Skip to content

Commit

Permalink
Added warning on readme about additional function
Browse files Browse the repository at this point in the history
also, kept NPatchInfo ctypes structure from being defined.
  • Loading branch information
overdev committed Oct 26, 2018
1 parent 7ece38c commit 3d58f51
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 38 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,28 @@ vec['y'] = 20
# vec[2:] = zw # <--- not supported; will raise TypeError
```

## Additional (feature) draw function: `draw_texture_npatch`

The custom DLL installed by _raylib-py_ includes an not yet official drawing function and
corresponding `NPatchInfo` helper structure:

```python
# draws an 3-patch (vertical, or horizontal) or 9-patch textured that stretches and
# shrinks nicely.
# Seq means any sequence type
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:
```

At the moment (after _raylib_ v2.0.0), only the x86 custom DLL contains this function
and, to enabled it, an specific `os.environ` key must be set:

```python
# set this before importing raylibpy (the value does not matter as long is a str type)
os.environ['ENABLE_V2_0_0_FEATURE_DRAWTEXTURENPATCH'] = '1'
```

## Building _raylib_ from source

_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.
Expand Down
80 changes: 42 additions & 38 deletions raylibpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2081,47 +2081,50 @@ def __str__(self) -> str:
return "(RENDERTEXTURE: {}w, {}h, texture: {}, depth: {})".format(self.width, self.height, self.texture, self.depth)


class _NPatchInfo(Structure):
_fields_ = [
('sourceRec', Rectangle),
('left', c_int),
('top', c_int),
('right', c_int),
('bottom', c_int),
('type', c_int),
]


class NPatchInfo(_NPatchInfo):

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:
if npatch_type not in NPatchType:
npatch_type = {
if ENABLE_V2_0_0_FEATURE_DRAWTEXTURENPATCH:
class _NPatchInfo(Structure):
_fields_ = [
('sourceRec', Rectangle),
('left', c_int),
('top', c_int),
('right', c_int),
('bottom', c_int),
('type', c_int),
]

class NPatchInfo(_NPatchInfo):

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:
if npatch_type not in NPatchType:
npatch_type = {
0: NPT_9PATCH,
1: NPT_3PATCH_VERTICAL,
2: NPT_3PATCH_VERTICAL
}.get(npatch_type, NPT_9PATCH)

super(NPatchInfo, self).__init__(source_rec, left, top, right, bottom, npatch_type)

def __str__(self) -> str:
"""Textual representation."""
npt = {
0: NPT_9PATCH,
1: NPT_3PATCH_VERTICAL,
2: NPT_3PATCH_VERTICAL
}.get(npatch_type, NPT_9PATCH)

super(NPatchInfo, self).__init__(source_rec, left, top, right, bottom, npatch_type)

def __str__(self) -> str:
"""Textual representation."""
npt = {
0: NPT_9PATCH,
1: NPT_3PATCH_VERTICAL,
2: NPT_3PATCH_VERTICAL
}.get(self.type, NPT_9PATCH).name
return "(NPATCHINFO: rec: {0.sourceRec}, ltrb: [{0.left}, {0.top}, {0.right}, {0.bottom}], type: {1})".format(self, npt)

def __repr__(self) -> str:
rc = repr(self.sourceRec)
npt = {
0: NPT_9PATCH,
1: NPT_3PATCH_VERTICAL,
2: NPT_3PATCH_VERTICAL
}.get(self.type, NPT_9PATCH).name
return "{0.__class__.__qualname__}({1}, {0.left}, {0.top}, {0.right}, {0.bottom}, {2})".format(self, rc, npt)
}.get(self.type, NPT_9PATCH).name
return "(NPATCHINFO: rec: {0.sourceRec}, ltrb: [{0.left}, {0.top}, {0.right}, {0.bottom}], type: {1})".format(self, npt)

def __repr__(self) -> str:
rc = repr(self.sourceRec)
npt = {
0: NPT_9PATCH,
1: NPT_3PATCH_VERTICAL,
2: NPT_3PATCH_VERTICAL
}.get(self.type, NPT_9PATCH).name
return "{0.__class__.__qualname__}({1}, {0.left}, {0.top}, {0.right}, {0.bottom}, {2})".format(self, rc, npt)
else:
class NPatchInfo:
__slots__ = 'source_rec', 'left', 'top', 'right', 'bottom', 'type'
pass

class CharInfo(Structure):
_fields_ = [
Expand Down Expand Up @@ -4089,10 +4092,11 @@ def draw_texture_pro(texture: Texture2D, source_rec: Union[Rectangle, Seq], dest
_rl.DrawTextureNPatch.argtypes = [Texture2D, NPatchInfo, Rectangle, Vector2, Float, Color]
_rl.DrawTextureNPatch.restype = None
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:
"""Draw a part of a texture defined by a rectangle with 'pro' parameters"""
"""Draws a textures that stretches and shrinks nicely."""
return _rl.DrawNPatch(texture, npatch_info, _rect(dest_rec), _vec2(origin), _float(rotation), _color(tint))
else:
def draw_texture_npatch(*args, **kwargs) -> None:
"""WARNING: THIS FUNCTION HAS NO EFFECT!"""
pass

# -----------------------------------------------------------------------------------
Expand Down

0 comments on commit 3d58f51

Please sign in to comment.