From 3ae8ac3c7ab34d5c31d0ab4695c4aa499479f291 Mon Sep 17 00:00:00 2001 From: YoursFunny Date: Sun, 5 Jul 2026 23:52:42 +0800 Subject: [PATCH] feat: add `Button.is_offset_in()` --- module/base/button.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/module/base/button.py b/module/base/button.py index 1f69cda..e8b6b7e 100644 --- a/module/base/button.py +++ b/module/base/button.py @@ -34,6 +34,23 @@ class Button(Resource): def clear_offset(self): self._button_offset = (0, 0) + def is_offset_in(self, x=0, y=0): + """ + Args: + x: + y: + + Returns: + bool: If _button_offset is in (-x, -y, x, y) + """ + if x: + if self._button_offset[0] < -x or self._button_offset[0] > x: + return False + if y: + if self._button_offset[1] < -y or self._button_offset[1] > y: + return False + return True + @cached_property def image(self): return load_image(self.file, self.area) @@ -295,6 +312,17 @@ class ButtonWrapper(Resource): for b in self.iter_buttons(): b.clear_offset() + def is_offset_in(self, x=0, y=0): + """ + Args: + x: + y: + + Returns: + bool: If _button_offset is in (-x, -y, x, y) + """ + return self.matched_button.is_offset_in(x=x, y=y) + def load_search(self, area): """ Set `search` attribute.