pyforgeui 1.0.0__tar.gz → 1.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyforgeui-1.0.0/src/pyforgeui.egg-info → pyforgeui-1.1.0}/PKG-INFO +3 -2
- {pyforgeui-1.0.0 → pyforgeui-1.1.0}/README.md +2 -1
- {pyforgeui-1.0.0 → pyforgeui-1.1.0}/pyproject.toml +1 -1
- {pyforgeui-1.0.0 → pyforgeui-1.1.0}/src/pyforgeui/Behavior/Element_behavior.py +1 -1
- pyforgeui-1.1.0/src/pyforgeui/Behavior/Mouse_collision.py +218 -0
- {pyforgeui-1.0.0 → pyforgeui-1.1.0}/src/pyforgeui/Behavior/Pressed_button.py +25 -14
- {pyforgeui-1.0.0 → pyforgeui-1.1.0}/src/pyforgeui/Elements/Combo_box.py +223 -33
- pyforgeui-1.1.0/src/pyforgeui/Elements/Input_text.py +163 -0
- pyforgeui-1.1.0/src/pyforgeui/Elements/Polygon_button.py +83 -0
- {pyforgeui-1.0.0 → pyforgeui-1.1.0}/src/pyforgeui/Elements/Scroll_bar.py +84 -7
- pyforgeui-1.1.0/src/pyforgeui/Elements/Text.py +109 -0
- pyforgeui-1.1.0/src/pyforgeui/Elements/Text_button.py +115 -0
- {pyforgeui-1.0.0 → pyforgeui-1.1.0}/src/pyforgeui/Elements_Factory.py +16 -1
- pyforgeui-1.1.0/src/pyforgeui/VisualFX.py +798 -0
- {pyforgeui-1.0.0 → pyforgeui-1.1.0}/src/pyforgeui/__init__.py +4 -1
- {pyforgeui-1.0.0 → pyforgeui-1.1.0/src/pyforgeui.egg-info}/PKG-INFO +3 -2
- {pyforgeui-1.0.0 → pyforgeui-1.1.0}/src/pyforgeui.egg-info/SOURCES.txt +1 -0
- pyforgeui-1.1.0/tests/test_pyforgeui.py +242 -0
- pyforgeui-1.0.0/src/pyforgeui/Behavior/Mouse_collision.py +0 -108
- pyforgeui-1.0.0/src/pyforgeui/Elements/Input_text.py +0 -42
- pyforgeui-1.0.0/src/pyforgeui/Elements/Polygon_button.py +0 -18
- pyforgeui-1.0.0/src/pyforgeui/Elements/Text.py +0 -25
- pyforgeui-1.0.0/src/pyforgeui/Elements/Text_button.py +0 -13
- pyforgeui-1.0.0/tests/test_pyforgeui.py +0 -106
- {pyforgeui-1.0.0 → pyforgeui-1.1.0}/LICENSE +0 -0
- {pyforgeui-1.0.0 → pyforgeui-1.1.0}/LICENSE.md +0 -0
- {pyforgeui-1.0.0 → pyforgeui-1.1.0}/setup.cfg +0 -0
- {pyforgeui-1.0.0 → pyforgeui-1.1.0}/src/pyforgeui/Behavior/__init__.py +0 -0
- {pyforgeui-1.0.0 → pyforgeui-1.1.0}/src/pyforgeui/Containers/Layout.py +0 -0
- {pyforgeui-1.0.0 → pyforgeui-1.1.0}/src/pyforgeui/Containers/Modal.py +0 -0
- {pyforgeui-1.0.0 → pyforgeui-1.1.0}/src/pyforgeui/Containers/Panel.py +0 -0
- {pyforgeui-1.0.0 → pyforgeui-1.1.0}/src/pyforgeui/Containers/Tab_container.py +0 -0
- {pyforgeui-1.0.0 → pyforgeui-1.1.0}/src/pyforgeui/Containers/__init__.py +0 -0
- {pyforgeui-1.0.0 → pyforgeui-1.1.0}/src/pyforgeui/Elements/Check_box.py +0 -0
- {pyforgeui-1.0.0 → pyforgeui-1.1.0}/src/pyforgeui/Elements/Image_element.py +0 -0
- {pyforgeui-1.0.0 → pyforgeui-1.1.0}/src/pyforgeui/Elements/Keybind_button.py +0 -0
- {pyforgeui-1.0.0 → pyforgeui-1.1.0}/src/pyforgeui/Elements/Number_spinner.py +0 -0
- {pyforgeui-1.0.0 → pyforgeui-1.1.0}/src/pyforgeui/Elements/Progress_bar.py +0 -0
- {pyforgeui-1.0.0 → pyforgeui-1.1.0}/src/pyforgeui/Elements/Radio_button.py +0 -0
- {pyforgeui-1.0.0 → pyforgeui-1.1.0}/src/pyforgeui/Elements/Slider.py +0 -0
- {pyforgeui-1.0.0 → pyforgeui-1.1.0}/src/pyforgeui/Elements/Toggle_switch.py +0 -0
- {pyforgeui-1.0.0 → pyforgeui-1.1.0}/src/pyforgeui/Elements/Tooltip.py +0 -0
- {pyforgeui-1.0.0 → pyforgeui-1.1.0}/src/pyforgeui/Elements/__init__.py +0 -0
- {pyforgeui-1.0.0 → pyforgeui-1.1.0}/src/pyforgeui/UI_Manager.py +0 -0
- {pyforgeui-1.0.0 → pyforgeui-1.1.0}/src/pyforgeui.egg-info/dependency_links.txt +0 -0
- {pyforgeui-1.0.0 → pyforgeui-1.1.0}/src/pyforgeui.egg-info/requires.txt +0 -0
- {pyforgeui-1.0.0 → pyforgeui-1.1.0}/src/pyforgeui.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pyforgeui
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.1.0
|
|
4
4
|
Summary: A modular, zero-leak, game-ready GUI widget and container library built on top of Pygame.
|
|
5
5
|
Author: Drakonosinc
|
|
6
6
|
License: MIT
|
|
@@ -28,6 +28,7 @@ Dynamic: license-file
|
|
|
28
28
|
# PyForgeUI
|
|
29
29
|
|
|
30
30
|
[](https://deepwiki.com/Drakonosinc/PyForgeUI)
|
|
31
|
+
[](https://pypi.org/project/pyforgeui/)
|
|
31
32
|
[](https://www.python.org/)
|
|
32
33
|
[](LICENSE)
|
|
33
34
|
|
|
@@ -50,7 +51,7 @@ Dynamic: license-file
|
|
|
50
51
|
|
|
51
52
|
## Installation
|
|
52
53
|
|
|
53
|
-
### From PyPI
|
|
54
|
+
### From PyPI
|
|
54
55
|
```bash
|
|
55
56
|
pip install pyforgeui
|
|
56
57
|
```
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# PyForgeUI
|
|
2
2
|
|
|
3
3
|
[](https://deepwiki.com/Drakonosinc/PyForgeUI)
|
|
4
|
+
[](https://pypi.org/project/pyforgeui/)
|
|
4
5
|
[](https://www.python.org/)
|
|
5
6
|
[](LICENSE)
|
|
6
7
|
|
|
@@ -23,7 +24,7 @@
|
|
|
23
24
|
|
|
24
25
|
## Installation
|
|
25
26
|
|
|
26
|
-
### From PyPI
|
|
27
|
+
### From PyPI
|
|
27
28
|
```bash
|
|
28
29
|
pip install pyforgeui
|
|
29
30
|
```
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "pyforgeui"
|
|
7
|
-
version = "1.
|
|
7
|
+
version = "1.1.0"
|
|
8
8
|
description = "A modular, zero-leak, game-ready GUI widget and container library built on top of Pygame."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -19,7 +19,7 @@ class ElementBehavior(MouseCollision, PressedButton):
|
|
|
19
19
|
return False
|
|
20
20
|
|
|
21
21
|
def reactivate_pressed(self, event: pygame.event.Event) -> None:
|
|
22
|
-
if event.type == self.EVENT_NEW:
|
|
22
|
+
if event.type == self.EVENT_NEW and not self.states.get("active", False):
|
|
23
23
|
self.states["presses_touch"] = True
|
|
24
24
|
|
|
25
25
|
def new_events(self, time: int) -> None:
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import pygame
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class MouseCollision:
|
|
5
|
+
"""Mixin/Base providing hover detection, coordinate translation, and spatial geometry."""
|
|
6
|
+
|
|
7
|
+
_active_popup = None
|
|
8
|
+
_popup_block_until_release: bool = False
|
|
9
|
+
_popup_closed_tick: int = -1000
|
|
10
|
+
_popup_closed_rect: pygame.Rect | None = None
|
|
11
|
+
|
|
12
|
+
@classmethod
|
|
13
|
+
def set_active_popup(cls, popup) -> None:
|
|
14
|
+
if cls._active_popup is not None and cls._active_popup is not popup:
|
|
15
|
+
prev = cls._active_popup
|
|
16
|
+
cls._active_popup = None
|
|
17
|
+
if getattr(prev, "is_dropdown_open", False):
|
|
18
|
+
prev.close_dropdown(block_click=False)
|
|
19
|
+
cls._active_popup = popup
|
|
20
|
+
|
|
21
|
+
@classmethod
|
|
22
|
+
def clear_active_popup(cls, popup=None, block_click: bool = False) -> None:
|
|
23
|
+
target = popup if popup is not None else cls._active_popup
|
|
24
|
+
if target is not None and hasattr(target, "get_total_interactive_rect"):
|
|
25
|
+
try:
|
|
26
|
+
cls._popup_closed_rect = target.get_total_interactive_rect()
|
|
27
|
+
except Exception:
|
|
28
|
+
cls._popup_closed_rect = None
|
|
29
|
+
if popup is None or cls._active_popup is popup:
|
|
30
|
+
cls._active_popup = None
|
|
31
|
+
if block_click:
|
|
32
|
+
cls._popup_block_until_release = True
|
|
33
|
+
try:
|
|
34
|
+
cls._popup_closed_tick = pygame.time.get_ticks()
|
|
35
|
+
except Exception:
|
|
36
|
+
cls._popup_closed_tick = 0
|
|
37
|
+
|
|
38
|
+
@classmethod
|
|
39
|
+
def get_active_popup(cls):
|
|
40
|
+
popup = cls._active_popup
|
|
41
|
+
if popup is not None:
|
|
42
|
+
if not getattr(popup, "is_dropdown_open", False) or not getattr(popup, "visible", True):
|
|
43
|
+
cls._active_popup = None
|
|
44
|
+
return None
|
|
45
|
+
last_tick = getattr(popup, "_last_draw_tick", None)
|
|
46
|
+
if last_tick is not None:
|
|
47
|
+
try:
|
|
48
|
+
if (pygame.time.get_ticks() - last_tick) > 250:
|
|
49
|
+
popup._is_dropdown_open = False
|
|
50
|
+
cls._active_popup = None
|
|
51
|
+
return None
|
|
52
|
+
except Exception:
|
|
53
|
+
pass
|
|
54
|
+
return popup
|
|
55
|
+
|
|
56
|
+
def _is_visual_occluded_by_popup(self, check_rect: pygame.Rect | None = None) -> bool:
|
|
57
|
+
popup = MouseCollision.get_active_popup()
|
|
58
|
+
owner = getattr(self, "_owner_popup", None)
|
|
59
|
+
if popup is None or owner is popup or self is popup:
|
|
60
|
+
return False
|
|
61
|
+
if getattr(self, "screen", None) is not getattr(popup, "screen", None):
|
|
62
|
+
return False
|
|
63
|
+
overlay_rect = popup.get_dropdown_overlay_rect() if hasattr(popup, "get_dropdown_overlay_rect") else None
|
|
64
|
+
if not isinstance(overlay_rect, pygame.Rect):
|
|
65
|
+
return False
|
|
66
|
+
rect_to_check = check_rect if isinstance(check_rect, pygame.Rect) else self.get_bounding_rect()
|
|
67
|
+
if isinstance(rect_to_check, pygame.Rect) and rect_to_check.width > 0 and rect_to_check.height > 0:
|
|
68
|
+
return overlay_rect.colliderect(rect_to_check)
|
|
69
|
+
return False
|
|
70
|
+
|
|
71
|
+
def _is_occluded_by_popup(self, check_rect: pygame.Rect | None = None, mouse_pos: tuple[int, int] | None = None) -> bool:
|
|
72
|
+
try:
|
|
73
|
+
pressed = pygame.mouse.get_pressed()[0]
|
|
74
|
+
now = pygame.time.get_ticks()
|
|
75
|
+
except Exception:
|
|
76
|
+
pressed = False
|
|
77
|
+
now = 0
|
|
78
|
+
|
|
79
|
+
if not pressed and MouseCollision._popup_block_until_release and (now - MouseCollision._popup_closed_tick) > 45:
|
|
80
|
+
MouseCollision._popup_block_until_release = False
|
|
81
|
+
|
|
82
|
+
popup = MouseCollision.get_active_popup()
|
|
83
|
+
owner = getattr(self, "_owner_popup", None)
|
|
84
|
+
is_owned_by_active = (popup is not None) and (owner is popup or self is popup)
|
|
85
|
+
|
|
86
|
+
if not is_owned_by_active and isinstance(MouseCollision._popup_closed_rect, pygame.Rect):
|
|
87
|
+
if MouseCollision._popup_block_until_release or (now - MouseCollision._popup_closed_tick) <= 45:
|
|
88
|
+
if mouse_pos is not None and MouseCollision._popup_closed_rect.collidepoint(mouse_pos):
|
|
89
|
+
return True
|
|
90
|
+
rect_to_check = check_rect if isinstance(check_rect, pygame.Rect) else self.get_bounding_rect()
|
|
91
|
+
if isinstance(rect_to_check, pygame.Rect) and MouseCollision._popup_closed_rect.colliderect(rect_to_check):
|
|
92
|
+
return True
|
|
93
|
+
|
|
94
|
+
if popup is None or is_owned_by_active:
|
|
95
|
+
vp = getattr(self, "_scroll_viewport", None)
|
|
96
|
+
if isinstance(vp, pygame.Rect):
|
|
97
|
+
if mouse_pos is not None and not vp.collidepoint(mouse_pos):
|
|
98
|
+
return True
|
|
99
|
+
rect_to_check = check_rect if isinstance(check_rect, pygame.Rect) else self.get_bounding_rect()
|
|
100
|
+
if isinstance(rect_to_check, pygame.Rect) and (rect_to_check.top < vp.top or rect_to_check.bottom > vp.bottom):
|
|
101
|
+
return True
|
|
102
|
+
return False
|
|
103
|
+
if getattr(self, "screen", None) is not getattr(popup, "screen", None):
|
|
104
|
+
return False
|
|
105
|
+
|
|
106
|
+
overlay_rect = popup.get_dropdown_overlay_rect() if hasattr(popup, "get_dropdown_overlay_rect") else None
|
|
107
|
+
if isinstance(overlay_rect, pygame.Rect):
|
|
108
|
+
if mouse_pos is not None and overlay_rect.collidepoint(mouse_pos):
|
|
109
|
+
return True
|
|
110
|
+
rect_to_check = check_rect if isinstance(check_rect, pygame.Rect) else self.get_bounding_rect()
|
|
111
|
+
if isinstance(rect_to_check, pygame.Rect) and rect_to_check.width > 0 and rect_to_check.height > 0:
|
|
112
|
+
if overlay_rect.colliderect(rect_to_check):
|
|
113
|
+
return True
|
|
114
|
+
return False
|
|
115
|
+
|
|
116
|
+
def __init__(self, config: dict) -> None:
|
|
117
|
+
self.screen: pygame.Surface = config["screen"]
|
|
118
|
+
self.window = config.get("window", None)
|
|
119
|
+
pos = config.get("position", (0, 0))
|
|
120
|
+
self.position: tuple = tuple(pos) if isinstance(pos, (tuple, list)) else pos
|
|
121
|
+
self.sound_hover = config.get("sound_hover", None)
|
|
122
|
+
self.detect_mouse: bool = config.get("detect_mouse", True)
|
|
123
|
+
self.visible: bool = config.get("visible", True)
|
|
124
|
+
self.enabled: bool = config.get("enabled", True)
|
|
125
|
+
self.tooltip_text: str | None = config.get("tooltip", None)
|
|
126
|
+
if not hasattr(self, "states") or not isinstance(self.states, dict):
|
|
127
|
+
self.states = {}
|
|
128
|
+
self.states.update({"detect_hover": True, "is_hovered": False, **config.get("states", {})})
|
|
129
|
+
|
|
130
|
+
def get_mouse_pos(self) -> tuple[int, int]:
|
|
131
|
+
return self.window.get_mouse_pos() if self.window else pygame.mouse.get_pos()
|
|
132
|
+
|
|
133
|
+
def get_bounding_rect(self) -> pygame.Rect:
|
|
134
|
+
"""Returns a single bounding pygame.Rect for layout and container calculations."""
|
|
135
|
+
rect_attr = getattr(self, "rect", None)
|
|
136
|
+
if isinstance(rect_attr, pygame.Rect):
|
|
137
|
+
return rect_attr
|
|
138
|
+
if isinstance(rect_attr, dict):
|
|
139
|
+
rects = []
|
|
140
|
+
for v in rect_attr.values():
|
|
141
|
+
if isinstance(v, pygame.Rect):
|
|
142
|
+
rects.append(v)
|
|
143
|
+
elif hasattr(v, "get_bounding_rect"):
|
|
144
|
+
rects.append(v.get_bounding_rect())
|
|
145
|
+
elif hasattr(v, "rect") and isinstance(v.rect, pygame.Rect):
|
|
146
|
+
rects.append(v.rect)
|
|
147
|
+
if rects:
|
|
148
|
+
base = rects[0].copy()
|
|
149
|
+
for r in rects[1:]:
|
|
150
|
+
base.union_ip(r)
|
|
151
|
+
return base
|
|
152
|
+
if isinstance(self.position, (tuple, list)):
|
|
153
|
+
if len(self.position) >= 4 and isinstance(self.position[0], (int, float)):
|
|
154
|
+
return pygame.Rect(int(self.position[0]), int(self.position[1]), int(self.position[2]), int(self.position[3]))
|
|
155
|
+
if len(self.position) == 2 and isinstance(self.position[0], (int, float)):
|
|
156
|
+
return pygame.Rect(int(self.position[0]), int(self.position[1]), 0, 0)
|
|
157
|
+
return pygame.Rect(0, 0, 0, 0)
|
|
158
|
+
|
|
159
|
+
def move(self, dx: int, dy: int) -> None:
|
|
160
|
+
"""Translates this element and any nested rects/children by (dx, dy)."""
|
|
161
|
+
if dx == 0 and dy == 0:
|
|
162
|
+
return
|
|
163
|
+
if isinstance(self.position, (tuple, list)) and self.position:
|
|
164
|
+
if isinstance(self.position[0], (tuple, list)):
|
|
165
|
+
# Polygon points
|
|
166
|
+
self.position = [(p[0] + dx, p[1] + dy) for p in self.position]
|
|
167
|
+
if hasattr(self, "hover_position") and isinstance(self.hover_position, (tuple, list)):
|
|
168
|
+
self.hover_position = [(p[0] + dx, p[1] + dy) for p in self.hover_position]
|
|
169
|
+
elif len(self.position) == 2:
|
|
170
|
+
self.position = (self.position[0] + dx, self.position[1] + dy)
|
|
171
|
+
elif len(self.position) >= 4:
|
|
172
|
+
self.position = (self.position[0] + dx, self.position[1] + dy, *self.position[2:])
|
|
173
|
+
|
|
174
|
+
self._translate_rect_obj(getattr(self, "rect", None), dx, dy)
|
|
175
|
+
|
|
176
|
+
@classmethod
|
|
177
|
+
def _translate_rect_obj(cls, obj, dx: int, dy: int) -> None:
|
|
178
|
+
if isinstance(obj, pygame.Rect):
|
|
179
|
+
obj.x += dx
|
|
180
|
+
obj.y += dy
|
|
181
|
+
elif isinstance(obj, dict):
|
|
182
|
+
for v in obj.values():
|
|
183
|
+
if isinstance(v, (pygame.Rect, dict)):
|
|
184
|
+
cls._translate_rect_obj(v, dx, dy)
|
|
185
|
+
elif hasattr(v, "move"):
|
|
186
|
+
v.move(dx, dy)
|
|
187
|
+
|
|
188
|
+
def set_position(self, x: int, y: int) -> None:
|
|
189
|
+
"""Moves the element so its top-left corner is at (x, y)."""
|
|
190
|
+
if isinstance(self.position, (tuple, list)) and self.position and isinstance(self.position[0], (int, float)):
|
|
191
|
+
dx = int(x - self.position[0])
|
|
192
|
+
dy = int(y - self.position[1])
|
|
193
|
+
else:
|
|
194
|
+
bounds = self.get_bounding_rect()
|
|
195
|
+
dx = int(x - bounds.x)
|
|
196
|
+
dy = int(y - bounds.y)
|
|
197
|
+
self.move(dx, dy)
|
|
198
|
+
|
|
199
|
+
def mouse_collision(self, rect: pygame.Rect, mouse_pos: tuple[int, int], draw=None) -> bool:
|
|
200
|
+
if not self.visible or not self.enabled or self._is_occluded_by_popup(rect, mouse_pos):
|
|
201
|
+
self.states["is_hovered"] = False
|
|
202
|
+
self.states["detect_hover"] = True
|
|
203
|
+
return False
|
|
204
|
+
if rect.collidepoint(mouse_pos):
|
|
205
|
+
self.states["is_hovered"] = True
|
|
206
|
+
self.draw_hover_effect() if draw is None else draw()
|
|
207
|
+
if self.states["detect_hover"]:
|
|
208
|
+
if self.sound_hover:
|
|
209
|
+
self.sound_hover.play(loops=0)
|
|
210
|
+
self.states["detect_hover"] = False
|
|
211
|
+
return True
|
|
212
|
+
else:
|
|
213
|
+
self.states["is_hovered"] = False
|
|
214
|
+
self.states["detect_hover"] = True
|
|
215
|
+
return False
|
|
216
|
+
|
|
217
|
+
def draw_hover_effect(self):
|
|
218
|
+
raise NotImplementedError
|
|
@@ -25,6 +25,11 @@ class PressedButton:
|
|
|
25
25
|
def pressed_button(self, rect: pygame.Rect, pressed_mouse: tuple, mouse_pos: tuple[int, int], draw=None, repeat: bool | None = None) -> bool:
|
|
26
26
|
if not getattr(self, "visible", True) or not getattr(self, "enabled", True):
|
|
27
27
|
return False
|
|
28
|
+
if hasattr(self, "_is_occluded_by_popup") and self._is_occluded_by_popup(rect, mouse_pos):
|
|
29
|
+
self.states["active"] = False
|
|
30
|
+
self.states["presses_touch"] = True
|
|
31
|
+
self.states["click_time"] = None
|
|
32
|
+
return False
|
|
28
33
|
|
|
29
34
|
fired = False
|
|
30
35
|
|
|
@@ -42,26 +47,32 @@ class PressedButton:
|
|
|
42
47
|
repeat = self.repeat if repeat is None else repeat
|
|
43
48
|
current_time = pygame.time.get_ticks()
|
|
44
49
|
|
|
45
|
-
if
|
|
46
|
-
execute(False, True, False, current_time, False)
|
|
47
|
-
|
|
48
|
-
if not repeat and not pressed_mouse[0] and self.states["active"]:
|
|
49
|
-
if rect.collidepoint(mouse_pos):
|
|
50
|
-
execute(True)
|
|
51
|
-
else:
|
|
52
|
-
self.states["active"] = False
|
|
53
|
-
self.states["presses_touch"] = True
|
|
54
|
-
elif self.states["click_time"] is not None and repeat:
|
|
50
|
+
if repeat:
|
|
55
51
|
if pressed_mouse[0] and rect.collidepoint(mouse_pos):
|
|
56
|
-
if
|
|
52
|
+
if self.states["presses_touch"] and not self.states["active"]:
|
|
53
|
+
# Fire immediately on initial press so a single click always registers
|
|
57
54
|
execute(True, active=True, presses=False, time=current_time, command=True)
|
|
55
|
+
elif self.states["active"] and self.states["click_time"] is not None:
|
|
56
|
+
if current_time - self.states["click_time"] >= self.repeat_interval:
|
|
57
|
+
execute(True, active=True, presses=False, time=current_time, command=True)
|
|
58
58
|
else:
|
|
59
59
|
self.states["active"] = False
|
|
60
|
-
|
|
60
|
+
if not pressed_mouse[0]:
|
|
61
|
+
self.states["presses_touch"] = True
|
|
61
62
|
self.states["click_time"] = None
|
|
63
|
+
else:
|
|
64
|
+
if pressed_mouse[0] and rect.collidepoint(mouse_pos) and self.states["presses_touch"]:
|
|
65
|
+
execute(False, True, False, current_time, False)
|
|
66
|
+
|
|
67
|
+
if not pressed_mouse[0] and self.states["active"]:
|
|
68
|
+
if rect.collidepoint(mouse_pos):
|
|
69
|
+
execute(True)
|
|
70
|
+
else:
|
|
71
|
+
self.states["active"] = False
|
|
72
|
+
self.states["presses_touch"] = True
|
|
62
73
|
|
|
63
|
-
|
|
64
|
-
|
|
74
|
+
if pressed_mouse[0] and not rect.collidepoint(mouse_pos) and self.states["active"]:
|
|
75
|
+
self.states["active"], self.states["presses_touch"] = False, True
|
|
65
76
|
|
|
66
77
|
if self.states["active"]:
|
|
67
78
|
self.draw_pressed_effect() if draw is None else draw()
|