Skip to content

Commit 3d58f51

Browse files
committed
Added warning on readme about additional function
also, kept NPatchInfo ctypes structure from being defined.
1 parent 7ece38c commit 3d58f51

File tree

2 files changed

+64
-38
lines changed

2 files changed

+64
-38
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,28 @@ vec['y'] = 20
216216
# vec[2:] = zw # <--- not supported; will raise TypeError
217217
```
218218

219+
## Additional (feature) draw function: `draw_texture_npatch`
220+
221+
The custom DLL installed by _raylib-py_ includes an not yet official drawing function and
222+
corresponding `NPatchInfo` helper structure:
223+
224+
```python
225+
# draws an 3-patch (vertical, or horizontal) or 9-patch textured that stretches and
226+
# shrinks nicely.
227+
# Seq means any sequence type
228+
def draw_texture_npatch(texture: Texture2D, npatch_info: NPatchInfo,
229+
dest_rec: Union[Rectangle, Seq], origin: Union[Vector2, Seq],
230+
rotation: float, tint: Union[Color, Seq]) -> None:
231+
```
232+
233+
At the moment (after _raylib_ v2.0.0), only the x86 custom DLL contains this function
234+
and, to enabled it, an specific `os.environ` key must be set:
235+
236+
```python
237+
# set this before importing raylibpy (the value does not matter as long is a str type)
238+
os.environ['ENABLE_V2_0_0_FEATURE_DRAWTEXTURENPATCH'] = '1'
239+
```
240+
219241
## Building _raylib_ from source
220242

221243
_raylib_ wiki pages contains information on how to build it on [Windows](https://github.com/raysan5/raylib/wiki/Working-on-Windows), [Mac](https://github.com/raysan5/raylib/wiki/Working-on-macOS), [Linux](https://github.com/raysan5/raylib/wiki/Working-on-GNU-Linux) and other platforms.

raylibpy/__init__.py

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2081,47 +2081,50 @@ def __str__(self) -> str:
20812081
return "(RENDERTEXTURE: {}w, {}h, texture: {}, depth: {})".format(self.width, self.height, self.texture, self.depth)
20822082

20832083

2084-
class _NPatchInfo(Structure):
2085-
_fields_ = [
2086-
('sourceRec', Rectangle),
2087-
('left', c_int),
2088-
('top', c_int),
2089-
('right', c_int),
2090-
('bottom', c_int),
2091-
('type', c_int),
2092-
]
2093-
2094-
2095-
class NPatchInfo(_NPatchInfo):
2096-
2097-
def __init__(self, source_rec: 'Rectangle', left: int=1, top:int=1, right: int=1, bottom: int=1, npatch_type: Union[int, 'NPatchType']=0) -> None:
2098-
if npatch_type not in NPatchType:
2099-
npatch_type = {
2084+
if ENABLE_V2_0_0_FEATURE_DRAWTEXTURENPATCH:
2085+
class _NPatchInfo(Structure):
2086+
_fields_ = [
2087+
('sourceRec', Rectangle),
2088+
('left', c_int),
2089+
('top', c_int),
2090+
('right', c_int),
2091+
('bottom', c_int),
2092+
('type', c_int),
2093+
]
2094+
2095+
class NPatchInfo(_NPatchInfo):
2096+
2097+
def __init__(self, source_rec: 'Rectangle', left: int=1, top:int=1, right: int=1, bottom: int=1, npatch_type: Union[int, 'NPatchType']=0) -> None:
2098+
if npatch_type not in NPatchType:
2099+
npatch_type = {
2100+
0: NPT_9PATCH,
2101+
1: NPT_3PATCH_VERTICAL,
2102+
2: NPT_3PATCH_VERTICAL
2103+
}.get(npatch_type, NPT_9PATCH)
2104+
2105+
super(NPatchInfo, self).__init__(source_rec, left, top, right, bottom, npatch_type)
2106+
2107+
def __str__(self) -> str:
2108+
"""Textual representation."""
2109+
npt = {
21002110
0: NPT_9PATCH,
21012111
1: NPT_3PATCH_VERTICAL,
21022112
2: NPT_3PATCH_VERTICAL
2103-
}.get(npatch_type, NPT_9PATCH)
2104-
2105-
super(NPatchInfo, self).__init__(source_rec, left, top, right, bottom, npatch_type)
2106-
2107-
def __str__(self) -> str:
2108-
"""Textual representation."""
2109-
npt = {
2110-
0: NPT_9PATCH,
2111-
1: NPT_3PATCH_VERTICAL,
2112-
2: NPT_3PATCH_VERTICAL
2113-
}.get(self.type, NPT_9PATCH).name
2114-
return "(NPATCHINFO: rec: {0.sourceRec}, ltrb: [{0.left}, {0.top}, {0.right}, {0.bottom}], type: {1})".format(self, npt)
2115-
2116-
def __repr__(self) -> str:
2117-
rc = repr(self.sourceRec)
2118-
npt = {
2119-
0: NPT_9PATCH,
2120-
1: NPT_3PATCH_VERTICAL,
2121-
2: NPT_3PATCH_VERTICAL
2122-
}.get(self.type, NPT_9PATCH).name
2123-
return "{0.__class__.__qualname__}({1}, {0.left}, {0.top}, {0.right}, {0.bottom}, {2})".format(self, rc, npt)
2113+
}.get(self.type, NPT_9PATCH).name
2114+
return "(NPATCHINFO: rec: {0.sourceRec}, ltrb: [{0.left}, {0.top}, {0.right}, {0.bottom}], type: {1})".format(self, npt)
21242115

2116+
def __repr__(self) -> str:
2117+
rc = repr(self.sourceRec)
2118+
npt = {
2119+
0: NPT_9PATCH,
2120+
1: NPT_3PATCH_VERTICAL,
2121+
2: NPT_3PATCH_VERTICAL
2122+
}.get(self.type, NPT_9PATCH).name
2123+
return "{0.__class__.__qualname__}({1}, {0.left}, {0.top}, {0.right}, {0.bottom}, {2})".format(self, rc, npt)
2124+
else:
2125+
class NPatchInfo:
2126+
__slots__ = 'source_rec', 'left', 'top', 'right', 'bottom', 'type'
2127+
pass
21252128

21262129
class CharInfo(Structure):
21272130
_fields_ = [
@@ -4089,10 +4092,11 @@ def draw_texture_pro(texture: Texture2D, source_rec: Union[Rectangle, Seq], dest
40894092
_rl.DrawTextureNPatch.argtypes = [Texture2D, NPatchInfo, Rectangle, Vector2, Float, Color]
40904093
_rl.DrawTextureNPatch.restype = None
40914094
def draw_texture_npatch(texture: Texture2D, npatch_info: NPatchInfo, dest_rec: Union[Rectangle, Seq], origin: Union[Vector2, Seq], rotation: float, tint: Union[Color, Seq]) -> None:
4092-
"""Draw a part of a texture defined by a rectangle with 'pro' parameters"""
4095+
"""Draws a textures that stretches and shrinks nicely."""
40934096
return _rl.DrawNPatch(texture, npatch_info, _rect(dest_rec), _vec2(origin), _float(rotation), _color(tint))
40944097
else:
40954098
def draw_texture_npatch(*args, **kwargs) -> None:
4099+
"""WARNING: THIS FUNCTION HAS NO EFFECT!"""
40964100
pass
40974101

40984102
# -----------------------------------------------------------------------------------

0 commit comments

Comments
 (0)