Skip to content

Commit

Permalink
Fix Surface.draw_texture (#1705) (#1769)
Browse files Browse the repository at this point in the history
* Correct logic & typing of Surface.draw_texture
* Remove exception on position != 0, 0 per review
* Correct alpha value
* Add simple test for NotImplementedErrors on unsupported arguments
* Fix grammar & include value in exception strings
  • Loading branch information
pushfoo committed May 12, 2023
1 parent b6d1e75 commit 246abe1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
13 changes: 5 additions & 8 deletions arcade/gui/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,15 @@ def draw_texture(
width: float,
height: float,
tex: Union[Texture, NinePatchTexture],
angle=0,
angle: float = 0.0,
alpha: int = 255,
):
if isinstance(tex, NinePatchTexture):
if x != 0 or y != 0:
raise ValueError("Ninepatch does not support a position != (0,0) yet")
if angle != 0.0:
raise NotImplementedError(f"Ninepatch does not support an angle != 0 yet, but got {angle}")

if x != 0 or y != 0:
raise ValueError("Ninepatch does not support a angle != 0 yet")

if x != 0 or y != 0:
raise ValueError("Ninepatch does not support a alpha != 255 yet")
if alpha != 255:
raise NotImplementedError(f"Ninepatch does not support an alpha != 255 yet, but got {alpha}")

tex.draw_sized(size=(width, height))
else:
Expand Down
33 changes: 33 additions & 0 deletions tests/unit/gui/test_surface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import pytest

from arcade import load_texture
from arcade.gui import Surface, NinePatchTexture


def test_surface_draw_texture_raises_not_implemented_error_on_unsupported_values(window):
ninepatch_tx = NinePatchTexture(
left=5,
right=5,
top=5,
bottom=5,
texture=load_texture(
":resources:gui_basic_assets/window/dark_blue_gray_panel.png"
))
surface = Surface(size=(100, 100))

def keywords_only(**kwargs):
surface.draw_texture(0, 0, 20, 20, ninepatch_tx, **kwargs)

with pytest.raises(NotImplementedError):
keywords_only(alpha=128)

with pytest.raises(NotImplementedError):
keywords_only(angle=30.0)

with pytest.raises(NotImplementedError):
keywords_only(alpha=10, angle=30.0)





0 comments on commit 246abe1

Please sign in to comment.