diff --git a/components/core.py b/components/core.py index 9fd9c95..87af3eb 100644 --- a/components/core.py +++ b/components/core.py @@ -213,6 +213,9 @@ def screen_size(self): # TODO Is this appropriate for a decorator? def _is_drawable_clicked(self, drawable, pos): + """ + Position is taken as a (width, height) offset. + """ width_limit = drawable.draw_offset[1] + drawable.max_size[0] height_limit = drawable.draw_offset[0] + drawable.max_size[1] in_width = drawable.draw_offset[1] <= pos[0] <= width_limit diff --git a/tests/components/core_tests.py b/tests/components/core_tests.py index edc9f51..a113c5b 100644 --- a/tests/components/core_tests.py +++ b/tests/components/core_tests.py @@ -1,4 +1,5 @@ from components.core import DebugQueue, GameConfig, GameModel, GameScreen, GameLoop, GameLoopEvents +from components.drawable import Drawable from components.subscriber_pattern import Subscriber from mock import patch from StringIO import StringIO @@ -137,6 +138,12 @@ def test_debug_provisions(self): screen_debug.screen_size ) + def test_is_drawable_clicked_happy(self): + sample_drawable = Drawable((0, 0), 100, 88) + cfg = GameConfig(window_size=(200, 160)) + screen = GameScreen(cfg, GameModel()) + self.assertTrue(screen._is_drawable_clicked(sample_drawable, (90, 44))) + class DebugQueueTest(unittest.TestCase): def test_log_q_growth(self):