e2D 1.4.19__py3-none-any.whl → 1.4.21__py3-none-any.whl
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.
- e2D/__init__.py +58 -7
- e2D/__init__.pyi +294 -5
- e2D/colors.py +53 -23
- e2D/envs.py +71 -23
- e2D/utils.py +437 -51
- {e2d-1.4.19.dist-info → e2d-1.4.21.dist-info}/METADATA +3 -2
- e2d-1.4.21.dist-info/RECORD +13 -0
- {e2d-1.4.19.dist-info → e2d-1.4.21.dist-info}/WHEEL +1 -1
- {e2d-1.4.19.dist-info → e2d-1.4.21.dist-info/licenses}/LICENSE +21 -21
- e2d-1.4.19.dist-info/RECORD +0 -13
- {e2d-1.4.19.dist-info → e2d-1.4.21.dist-info}/top_level.txt +0 -0
e2D/utils.py
CHANGED
|
@@ -33,32 +33,51 @@ __PIVOT_POSITIONS_MULTIPLIER__ = dict(zip(("top_left", "top_center", "top_right"
|
|
|
33
33
|
class Mouse:
|
|
34
34
|
def __init__(self, parent) -> None:
|
|
35
35
|
self.parent = parent
|
|
36
|
-
self.
|
|
37
|
-
self.__last_frame_position__ = Vector2D.new_zero()
|
|
38
|
-
self.
|
|
39
|
-
self.__last_frame_movement__ = Vector2D.new_zero()
|
|
40
|
-
|
|
36
|
+
self.__last_frame_position_number__ :int= 0
|
|
37
|
+
self.__last_frame_position__ :Vector2D= Vector2D.new_zero()
|
|
38
|
+
self.__last_frame_movement_number__ :int= 0
|
|
39
|
+
self.__last_frame_movement__ :Vector2D= Vector2D.new_zero()
|
|
40
|
+
self.__last_frame_wheel_number__ :int= 0
|
|
41
|
+
self.__last_frame_wheel_delta__ :int= 0
|
|
42
|
+
|
|
41
43
|
self.__pressed__ : tuple[bool, bool, bool] = (False, False, False)
|
|
42
|
-
self.update()
|
|
44
|
+
self.update()
|
|
45
|
+
|
|
46
|
+
@property
|
|
47
|
+
def wheel_delta(self) -> int:
|
|
48
|
+
for event in self.parent.events:
|
|
49
|
+
if event.type == pg.MOUSEWHEEL:
|
|
50
|
+
if self.__last_frame_wheel_number__ != self.parent.current_frame:
|
|
51
|
+
self.__last_frame_wheel_delta__ = event.y
|
|
52
|
+
self.__last_frame_wheel_number__ = self.parent.current_frame
|
|
53
|
+
return self.__last_frame_wheel_delta__
|
|
54
|
+
|
|
55
|
+
self.__last_frame_wheel_delta__ = 0
|
|
56
|
+
self.__last_frame_wheel_number__ = self.parent.current_frame
|
|
57
|
+
return self.__last_frame_wheel_delta__
|
|
43
58
|
|
|
44
59
|
@property
|
|
45
60
|
def position(self) -> Vector2D:
|
|
46
|
-
if self.
|
|
61
|
+
if self.__last_frame_position_number__ != self.parent.current_frame:
|
|
47
62
|
self.__last_frame_position__ = Vector2D(*pg.mouse.get_pos())
|
|
48
|
-
self.
|
|
63
|
+
self.__last_frame_position_number__ = self.parent.current_frame
|
|
49
64
|
return self.__last_frame_position__
|
|
50
65
|
@position.setter
|
|
51
66
|
def position(self, new_position:Vector2D) -> None:
|
|
52
|
-
self.
|
|
67
|
+
self.__last_frame_position_number__ = self.parent.current_frame
|
|
53
68
|
self.__last_frame_position__ = new_position
|
|
54
69
|
pg.mouse.set_pos(self.__last_frame_position__())
|
|
55
70
|
|
|
56
71
|
@property
|
|
57
72
|
def last_frame_movement(self) -> Vector2D:
|
|
58
|
-
if self.
|
|
73
|
+
if self.__last_frame_movement_number__ != self.parent.current_frame:
|
|
59
74
|
self.__last_frame_movement__ = Vector2D(*pg.mouse.get_rel())
|
|
60
|
-
self.
|
|
75
|
+
self.__last_frame_movement_number__ = self.parent.current_frame
|
|
61
76
|
return self.__last_frame_movement__
|
|
77
|
+
@last_frame_movement.setter
|
|
78
|
+
def last_frame_movement(self, new_movement:Vector2D) -> None:
|
|
79
|
+
self.__last_frame_movement_number__ = self.parent.current_frame
|
|
80
|
+
self.__last_frame_movement__ = new_movement
|
|
62
81
|
|
|
63
82
|
def update(self) -> None:
|
|
64
83
|
self.__last_pressed__ = self.__pressed__
|
|
@@ -95,79 +114,115 @@ class Keyboard:
|
|
|
95
114
|
|
|
96
115
|
class Util:
|
|
97
116
|
def __init__(self) -> None:
|
|
98
|
-
self.rootEnv
|
|
99
|
-
self.surface : pg.Surface
|
|
117
|
+
self.rootEnv : Any
|
|
118
|
+
self.surface : pg.Surface= None # type: ignore
|
|
100
119
|
self.id : int|str
|
|
101
120
|
self.is_hovered :bool= False
|
|
102
|
-
|
|
103
|
-
def
|
|
121
|
+
self.hidden :bool= False
|
|
122
|
+
def hide(self) -> None:
|
|
123
|
+
self.hidden = True
|
|
124
|
+
def show(self) -> None:
|
|
125
|
+
self.hidden = False
|
|
126
|
+
def __render__(self) -> None: pass
|
|
127
|
+
def __draw__(self) -> None: pass
|
|
128
|
+
def __update__(self) -> None: pass
|
|
104
129
|
|
|
105
130
|
class InputCell(Util):
|
|
106
131
|
def __init__(self,
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
check_when_adding : Callable[[str], str] = lambda new_text: new_text
|
|
132
|
+
initial_value : str,
|
|
133
|
+
position : Vector2D,
|
|
134
|
+
size : Vector2D,
|
|
135
|
+
prefix : str|None = None,
|
|
136
|
+
text_color : Color|pg.Color = Color.white(),
|
|
137
|
+
bg_color : None|Color|pg.Color = None,
|
|
138
|
+
border_color : Color|pg.Color = Color.white(),
|
|
139
|
+
border_width : float = 0,
|
|
140
|
+
border_radius : int|list[int]|tuple[int,int,int,int] = -1,
|
|
141
|
+
margin : Vector2D = Vector2D.zero(),
|
|
142
|
+
pivot_position : __LITERAL_PIVOT_POSITIONS__ = "center_center",
|
|
143
|
+
font : pg.font.Font = FONT_ARIAL_32,
|
|
144
|
+
personalized_surface : pg.Surface|None = None,
|
|
145
|
+
on_enter_pressed : Callable[[str], Any] = lambda full_text: ...,
|
|
146
|
+
check_when_adding : Callable[[str], str] = lambda new_text: new_text,
|
|
123
147
|
) -> None:
|
|
124
148
|
super().__init__()
|
|
149
|
+
|
|
150
|
+
self.value = initial_value
|
|
125
151
|
|
|
126
|
-
self.id = id
|
|
127
|
-
self.on_enter_pressed = on_enter_pressed
|
|
128
|
-
self.check_when_adding = check_when_adding
|
|
129
|
-
self.prefix = prefix if prefix != None else ""
|
|
130
|
-
|
|
131
|
-
self.text_color = text_color
|
|
132
|
-
self.font = font
|
|
133
|
-
self.surface = personalized_surface
|
|
134
|
-
self.bg_color = bg_color
|
|
135
152
|
# size = Vector2D(*self.text_box.get_size()) + self.margin * 2
|
|
136
153
|
self.size = size
|
|
137
154
|
self.position = (position - size * __PIVOT_POSITIONS_MULTIPLIER__[pivot_position] + margin)
|
|
155
|
+
|
|
156
|
+
self.prefix = prefix if prefix != None else ""
|
|
157
|
+
|
|
158
|
+
self.font = font
|
|
159
|
+
|
|
138
160
|
self.bg_rect = [0, 0] + size()
|
|
139
|
-
|
|
140
|
-
self.border_color = border_color
|
|
161
|
+
|
|
141
162
|
self.border_radius = [border_radius]*4 if not any(isinstance(border_radius, cls) for cls in {tuple, list}) else border_radius
|
|
142
163
|
self.border_width = border_width
|
|
164
|
+
|
|
165
|
+
self.margin_rect = (margin * -1)() + size()
|
|
143
166
|
|
|
144
|
-
self.
|
|
167
|
+
self.on_enter_pressed = on_enter_pressed
|
|
168
|
+
self.check_when_adding = check_when_adding
|
|
169
|
+
|
|
145
170
|
self.update_text()
|
|
146
171
|
|
|
172
|
+
self.surface = personalized_surface
|
|
147
173
|
self.text_surface = pg.Surface(self.size(), pg.SRCALPHA, 32).convert_alpha()
|
|
174
|
+
|
|
175
|
+
self.text_color = text_color
|
|
176
|
+
self.bg_color = bg_color
|
|
177
|
+
self.border_color = border_color
|
|
148
178
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
179
|
+
@property
|
|
180
|
+
def text_color(self) -> Color:
|
|
181
|
+
return unpygamize_color(self.__text_color__)
|
|
182
|
+
@text_color.setter
|
|
183
|
+
def text_color(self, new_color:Color|pg.Color) -> None:
|
|
184
|
+
self.__text_color__ = pygamize_color(new_color)
|
|
185
|
+
@property
|
|
186
|
+
def bg_color(self) -> Color|None:
|
|
187
|
+
return unpygamize_color(self.__bg_color__) if self.__bg_color__ else None
|
|
188
|
+
@bg_color.setter
|
|
189
|
+
def bg_color(self, new_color:Color|pg.Color|None) -> None:
|
|
190
|
+
self.__bg_color__ = pygamize_color(new_color) if new_color else None
|
|
191
|
+
@property
|
|
192
|
+
def border_color(self) -> Color:
|
|
193
|
+
return unpygamize_color(self.__border_color__)
|
|
194
|
+
@border_color.setter
|
|
195
|
+
def border_color(self, new_color:Color|pg.Color) -> None:
|
|
196
|
+
self.__border_color__ = pygamize_color(new_color)
|
|
197
|
+
|
|
198
|
+
def __draw__(self) -> None:
|
|
199
|
+
if self.hidden: return
|
|
200
|
+
self.text_surface.fill(TRANSPARENT_COLOR_PYG)
|
|
201
|
+
|
|
202
|
+
if self.__bg_color__ is not None:
|
|
203
|
+
pg.draw.rect(self.text_surface, self.__bg_color__(), self.bg_rect, 0, -1, *self.border_radius)
|
|
153
204
|
|
|
154
205
|
self.text_surface.blit(self.text_box, self.text_position())
|
|
155
206
|
|
|
156
207
|
if self.rootEnv.selected_util != self:
|
|
157
208
|
if self.border_width:
|
|
158
|
-
pg.draw.rect(self.text_surface, self.
|
|
209
|
+
pg.draw.rect(self.text_surface, self.__border_color__(), self.margin_rect, self.border_width, -1, *self.border_radius)
|
|
159
210
|
else:
|
|
160
|
-
|
|
211
|
+
k = 127.5 + 127.5 * _mt.sin(self.rootEnv.runtime_seconds * 10)
|
|
212
|
+
pg.draw.rect(self.text_surface, pg.Color(k, k, k), self.margin_rect, self.border_width if self.border_width else 10, -1, *self.border_radius)
|
|
161
213
|
|
|
162
214
|
self.surface.blit(self.text_surface, self.position())
|
|
163
215
|
|
|
164
|
-
def
|
|
216
|
+
def __update__(self) -> None:
|
|
217
|
+
if self.hidden: return
|
|
165
218
|
self.is_hovered = self.position.x < self.rootEnv.mouse.position.x < self.position.x + self.size.x and\
|
|
166
219
|
self.position.y < self.rootEnv.mouse.position.y < self.position.y + self.size.y
|
|
220
|
+
|
|
167
221
|
if self.rootEnv.mouse.get_key(0, "just_pressed"):
|
|
168
222
|
if self.is_hovered:
|
|
169
223
|
self.rootEnv.selected_util = self if self.rootEnv.selected_util != self else None
|
|
170
224
|
self.update_text()
|
|
225
|
+
|
|
171
226
|
if self.rootEnv.selected_util == self:
|
|
172
227
|
for event in self.rootEnv.events:
|
|
173
228
|
if event.type == pg.TEXTINPUT:
|
|
@@ -183,9 +238,340 @@ class InputCell(Util):
|
|
|
183
238
|
self.update_text()
|
|
184
239
|
|
|
185
240
|
def update_text(self) -> None:
|
|
186
|
-
self.text_box = self.font.render(self.prefix + self.value, True, self.
|
|
241
|
+
self.text_box = self.font.render(self.prefix + self.value, True, self.__text_color__())
|
|
187
242
|
if self.rootEnv != None and self.rootEnv.selected_util == self:
|
|
188
243
|
# self.text_position = self.position + self.size * Vector2D(.85, .5) - Vector2D(*self.text_box.get_size()) * Vector2D(1, .5) - self.position
|
|
189
244
|
self.text_position = self.position + self.size * .5 - Vector2D(*self.text_box.get_size()) * Vector2D(.5, .5) - self.position
|
|
190
245
|
else:
|
|
191
246
|
self.text_position = self.position + self.size * .5 - Vector2D(*self.text_box.get_size()) * Vector2D(.5, .5) - self.position
|
|
247
|
+
|
|
248
|
+
class Slider(Util):
|
|
249
|
+
def __init__(self,
|
|
250
|
+
text : str,
|
|
251
|
+
position : Vector2D,
|
|
252
|
+
size : Vector2D,
|
|
253
|
+
min_value : float = 0,
|
|
254
|
+
max_value : float = 100,
|
|
255
|
+
step : float = 1,
|
|
256
|
+
color : Color|pg.Color = Color(200, 200, 200),
|
|
257
|
+
handleColour : Color|pg.Color = Color.white(),
|
|
258
|
+
initial_value : float = 0,
|
|
259
|
+
rounded : bool = True,
|
|
260
|
+
handleRadius : float = 10,
|
|
261
|
+
text_offset : V2 = V2(1.1, .5),
|
|
262
|
+
text_pivot : __LITERAL_PIVOT_POSITIONS__ = "center_center",
|
|
263
|
+
personalized_surface : pg.Surface|None = None,
|
|
264
|
+
) -> None:
|
|
265
|
+
super().__init__()
|
|
266
|
+
|
|
267
|
+
self.text = text
|
|
268
|
+
self.selected = False
|
|
269
|
+
self.min = min_value
|
|
270
|
+
self.max = max_value
|
|
271
|
+
self.step = step
|
|
272
|
+
|
|
273
|
+
self.position = position
|
|
274
|
+
self.size = size
|
|
275
|
+
|
|
276
|
+
self.value = clamp(initial_value, self.min, self.max)
|
|
277
|
+
|
|
278
|
+
self.radius = self.size.y // 2 if rounded else 0
|
|
279
|
+
self.text_offset = text_offset
|
|
280
|
+
self.text_pivot = text_pivot
|
|
281
|
+
|
|
282
|
+
self.handleRadius = handleRadius
|
|
283
|
+
self.surface = personalized_surface # type: ignore
|
|
284
|
+
|
|
285
|
+
self.hidden = False
|
|
286
|
+
|
|
287
|
+
self.color = color
|
|
288
|
+
self.handleColour = handleColour
|
|
289
|
+
|
|
290
|
+
@property
|
|
291
|
+
def color(self) -> Color:
|
|
292
|
+
return unpygamize_color(self.__color__)
|
|
293
|
+
@color.setter
|
|
294
|
+
def color(self, new_color:Color|pg.Color) -> None:
|
|
295
|
+
self.__color__ = pygamize_color(new_color)
|
|
296
|
+
@property
|
|
297
|
+
def handleColour(self) -> Color:
|
|
298
|
+
return unpygamize_color(self.__handleColour__)
|
|
299
|
+
@handleColour.setter
|
|
300
|
+
def handleColour(self, new_color:Color|pg.Color) -> None:
|
|
301
|
+
self.__handleColour__ = pygamize_color(new_color)
|
|
302
|
+
|
|
303
|
+
def __draw__(self) -> None:
|
|
304
|
+
if self.hidden: return
|
|
305
|
+
pg.draw.rect(self.surface, self.__color__, self.position() + self.size())
|
|
306
|
+
|
|
307
|
+
if self.radius:
|
|
308
|
+
pg.draw.circle(self.surface, self.__color__, (self.position.x, self.position.y + self.size.y // 2), self.radius)
|
|
309
|
+
pg.draw.circle(self.surface, self.__color__, (self.position.x + self.size.x, self.position.y + self.size.y // 2), self.radius)
|
|
310
|
+
|
|
311
|
+
circle = V2(int(self.position.x + (self.value - self.min) / (self.max - self.min) * self.size.x), self.position.y + self.size.y // 2)
|
|
312
|
+
|
|
313
|
+
pg.draw.circle(self.surface, self.__color__, circle(), self.handleRadius * 1.25)
|
|
314
|
+
pg.draw.circle(self.surface, self.__handleColour__, circle(), self.handleRadius)
|
|
315
|
+
self.rootEnv.print(self.text.format(round(self.value, 2)), self.position + self.size * self.text_offset, pivot_position=self.text_pivot)
|
|
316
|
+
|
|
317
|
+
def __update__(self) -> None:
|
|
318
|
+
if self.hidden: return
|
|
319
|
+
x,y = self.rootEnv.mouse.position
|
|
320
|
+
|
|
321
|
+
if self.rootEnv.mouse.get_key(0, "just_pressed") and self.__contains__(x, y):
|
|
322
|
+
self.rootEnv.selected_util = self
|
|
323
|
+
elif self.rootEnv.mouse.get_key(0, "just_released"):
|
|
324
|
+
self.rootEnv.selected_util = None
|
|
325
|
+
|
|
326
|
+
if self.rootEnv.selected_util == self:
|
|
327
|
+
new_value = (x - self.position.x) / self.size.x * self.max + self.min
|
|
328
|
+
self.value = clamp(new_value, self.min, self.max)
|
|
329
|
+
|
|
330
|
+
def __contains__(self, x, y) -> bool:
|
|
331
|
+
handleX = self.position.x + (self.value - self.min) / (self.max - self.min) * self.size.x
|
|
332
|
+
handleY = self.position.y + self.size.y // 2
|
|
333
|
+
return (handleX - x) ** 2 + (handleY - y) ** 2 <= self.handleRadius ** 2
|
|
334
|
+
|
|
335
|
+
def setValue(self, value) -> None:
|
|
336
|
+
self.value = clamp(value, self.min, self.max)
|
|
337
|
+
|
|
338
|
+
def getValue(self) -> float:
|
|
339
|
+
return self.value
|
|
340
|
+
|
|
341
|
+
class Button(Util):
|
|
342
|
+
def __init__(self,
|
|
343
|
+
text : str,
|
|
344
|
+
position : V2|Vector2D,
|
|
345
|
+
size : V2|Vector2D,
|
|
346
|
+
callback : Callable[[], None]|Callable[[], None] = lambda: None,
|
|
347
|
+
default_bg_color : Color|pg.Color = BLUE_COLOR_PYG,
|
|
348
|
+
hovered_bg_color : Color|pg.Color = CYAN_COLOR_PYG,
|
|
349
|
+
border_color : Color|pg.Color = WHITE_COLOR_PYG,
|
|
350
|
+
text_color : Color|pg.Color = WHITE_COLOR_PYG,
|
|
351
|
+
font : pg.font.Font = FONT_ARIAL_32,
|
|
352
|
+
border_radius : float = 10,
|
|
353
|
+
border_width : float = 10,
|
|
354
|
+
starting_hidden : bool = False,
|
|
355
|
+
args : list = [],
|
|
356
|
+
activation_mode : __LITERAL_KEY_MODE_TYPES__ = "just_pressed",
|
|
357
|
+
pivot_position : __LITERAL_PIVOT_POSITIONS__ = "top_left",
|
|
358
|
+
personalized_surface : pg.Surface|None = None,
|
|
359
|
+
) -> None:
|
|
360
|
+
super().__init__()
|
|
361
|
+
|
|
362
|
+
self.text = text
|
|
363
|
+
self.font = font
|
|
364
|
+
|
|
365
|
+
self.callback = callback
|
|
366
|
+
|
|
367
|
+
self.border_radius = border_radius
|
|
368
|
+
self.__size__ = size
|
|
369
|
+
self.__border_width__ = border_width
|
|
370
|
+
|
|
371
|
+
self.pivot_position :__LITERAL_PIVOT_POSITIONS__= pivot_position
|
|
372
|
+
self.update_position(position)
|
|
373
|
+
|
|
374
|
+
self.hidden = starting_hidden
|
|
375
|
+
self.args = args
|
|
376
|
+
|
|
377
|
+
self.activation_mode = activation_mode
|
|
378
|
+
|
|
379
|
+
self.hovered = False
|
|
380
|
+
|
|
381
|
+
self.text_color = text_color
|
|
382
|
+
self.default_bg_color = default_bg_color
|
|
383
|
+
self.border_color = border_color
|
|
384
|
+
self.hovered_bg_color = hovered_bg_color
|
|
385
|
+
|
|
386
|
+
self.surface = personalized_surface #type: ignore
|
|
387
|
+
self.update_surface()
|
|
388
|
+
|
|
389
|
+
def update_position(self, new_position:V2) -> None:
|
|
390
|
+
self.position = new_position - self.__size__ * __PIVOT_POSITIONS_MULTIPLIER__[self.pivot_position]
|
|
391
|
+
|
|
392
|
+
def update_pivoting(self, new_pivot_position:__LITERAL_PIVOT_POSITIONS__) -> None:
|
|
393
|
+
self.pivot_position = new_pivot_position
|
|
394
|
+
self.update_position(self.position)
|
|
395
|
+
|
|
396
|
+
def update_surface(self, render=False) -> None:
|
|
397
|
+
self.buffer_surface = pg.Surface((self.__size__ + self.__border_width__ * 2)(), pg.SRCALPHA, 32).convert_alpha()
|
|
398
|
+
if render: self.__render__()
|
|
399
|
+
|
|
400
|
+
@property
|
|
401
|
+
def size(self) -> V2:
|
|
402
|
+
return self.__size__
|
|
403
|
+
@size.setter
|
|
404
|
+
def size(self, new_size:V2|Vector2D) -> None:
|
|
405
|
+
self.__size__ = new_size
|
|
406
|
+
self.update_surface(render=True)
|
|
407
|
+
|
|
408
|
+
@property
|
|
409
|
+
def border_width(self) -> float:
|
|
410
|
+
return self.__border_width__
|
|
411
|
+
@border_width.setter
|
|
412
|
+
def border_width(self, new_width:float) -> None:
|
|
413
|
+
# self.position -= (self.__border_width__ - new_width) * .5
|
|
414
|
+
self.__border_width__ = new_width
|
|
415
|
+
self.update_surface(render=True)
|
|
416
|
+
|
|
417
|
+
@property
|
|
418
|
+
def text_color(self) -> Color:
|
|
419
|
+
return unpygamize_color(self.__text_color__)
|
|
420
|
+
@text_color.setter
|
|
421
|
+
def text_color(self, new_color:Color|pg.Color) -> None:
|
|
422
|
+
self.__text_color__ = pygamize_color(new_color)
|
|
423
|
+
@property
|
|
424
|
+
def default_bg_color(self) -> Color:
|
|
425
|
+
return unpygamize_color(self.__default_bg_color__)
|
|
426
|
+
@default_bg_color.setter
|
|
427
|
+
def default_bg_color(self, new_color:Color|pg.Color) -> None:
|
|
428
|
+
self.__default_bg_color__ = pygamize_color(new_color)
|
|
429
|
+
@property
|
|
430
|
+
def border_color(self) -> Color:
|
|
431
|
+
return unpygamize_color(self.__border_color__)
|
|
432
|
+
@border_color.setter
|
|
433
|
+
def border_color(self, new_color:Color|pg.Color) -> None:
|
|
434
|
+
self.__border_color__ = pygamize_color(new_color)
|
|
435
|
+
@property
|
|
436
|
+
def hovered_bg_color(self) -> Color:
|
|
437
|
+
return unpygamize_color(self.__hovered_bg_color__)
|
|
438
|
+
@hovered_bg_color.setter
|
|
439
|
+
def hovered_bg_color(self, new_color:Color|pg.Color) -> None:
|
|
440
|
+
self.__hovered_bg_color__ = pygamize_color(new_color)
|
|
441
|
+
|
|
442
|
+
def __render__(self) -> None:
|
|
443
|
+
self.buffer_surface.fill(TRANSPARENT_COLOR_PYG)
|
|
444
|
+
|
|
445
|
+
color = self.__hovered_bg_color__ if self.hovered else self.__default_bg_color__
|
|
446
|
+
pg.draw.rect(self.buffer_surface, self.__border_color__, V2.zero()() + (self.size + self.border_width * 2)(), border_radius=self.border_radius)
|
|
447
|
+
pg.draw.rect(self.buffer_surface, color, (V2.zero() + self.border_width)() + self.size(), border_radius=self.border_radius)
|
|
448
|
+
|
|
449
|
+
# TODO:
|
|
450
|
+
# not only size * .5 but also internal pivoting on the corners and sides
|
|
451
|
+
self.rootEnv.print(self.text, self.border_width + self.size * .5, color=self.__text_color__, font=self.font, pivot_position="center_center", personalized_surface=self.buffer_surface)
|
|
452
|
+
|
|
453
|
+
def __draw__(self) -> None:
|
|
454
|
+
if self.hidden: return
|
|
455
|
+
self.surface.blit(self.buffer_surface, (self.position)())
|
|
456
|
+
|
|
457
|
+
def __update__(self) -> None:
|
|
458
|
+
if self.hidden: return
|
|
459
|
+
|
|
460
|
+
old_overed = self.hovered
|
|
461
|
+
self.hovered = \
|
|
462
|
+
self.position.x < self.rootEnv.mouse.position.x < self.position.x + self.size.x and \
|
|
463
|
+
self.position.y < self.rootEnv.mouse.position.y < self.position.y + self.size.y
|
|
464
|
+
if self.hovered != old_overed:
|
|
465
|
+
self.__render__()
|
|
466
|
+
|
|
467
|
+
if self.hovered and self.rootEnv.mouse.get_key(0, self.activation_mode):
|
|
468
|
+
self.callback(*self.args)
|
|
469
|
+
self.rootEnv.selected_util = self
|
|
470
|
+
self.__render__()
|
|
471
|
+
elif self.rootEnv.selected_util == self:
|
|
472
|
+
self.rootEnv.selected_util = None
|
|
473
|
+
self.__render__()
|
|
474
|
+
|
|
475
|
+
class Label(Util):
|
|
476
|
+
def __init__(self,
|
|
477
|
+
text : str,
|
|
478
|
+
position : V2|Vector2D,
|
|
479
|
+
size : V2|Vector2D,
|
|
480
|
+
default_color : Color|pg.Color = TRANSPARENT_COLOR_PYG,
|
|
481
|
+
border_color : Color|pg.Color = WHITE_COLOR_PYG,
|
|
482
|
+
text_color : Color|pg.Color = WHITE_COLOR_PYG,
|
|
483
|
+
font : pg.font.Font = FONT_ARIAL_32,
|
|
484
|
+
border_radius : float = 10,
|
|
485
|
+
border_width : float = 10,
|
|
486
|
+
starting_hidden : bool = False,
|
|
487
|
+
personalized_surface : pg.Surface|None = None,
|
|
488
|
+
pivot_position : __LITERAL_PIVOT_POSITIONS__ = "top_left",
|
|
489
|
+
) -> None:
|
|
490
|
+
super().__init__()
|
|
491
|
+
|
|
492
|
+
self.__text__ = text
|
|
493
|
+
self.font = font
|
|
494
|
+
|
|
495
|
+
self.border_radius = border_radius
|
|
496
|
+
self.__size__ = size
|
|
497
|
+
self.__border_width__ = border_width
|
|
498
|
+
|
|
499
|
+
self.pivot_position :__LITERAL_PIVOT_POSITIONS__= pivot_position
|
|
500
|
+
self.update_position(position)
|
|
501
|
+
|
|
502
|
+
self.hidden = starting_hidden
|
|
503
|
+
|
|
504
|
+
self.text_color = text_color
|
|
505
|
+
self.default_color = default_color
|
|
506
|
+
self.border_color = border_color
|
|
507
|
+
|
|
508
|
+
self.surface = personalized_surface # type: ignore
|
|
509
|
+
self.update_surface()
|
|
510
|
+
|
|
511
|
+
def update_position(self, new_position:V2) -> None:
|
|
512
|
+
self.position = new_position - (self.__size__ + self.border_width * 2) * __PIVOT_POSITIONS_MULTIPLIER__[self.pivot_position]
|
|
513
|
+
|
|
514
|
+
def update_pivoting(self, new_pivot_position:__LITERAL_PIVOT_POSITIONS__="top_left") -> None:
|
|
515
|
+
self.pivot_position = new_pivot_position
|
|
516
|
+
self.update_position(self.position)
|
|
517
|
+
|
|
518
|
+
def update_surface(self, render=False) -> None:
|
|
519
|
+
self.buffer_surface = pg.Surface((self.__size__ + self.__border_width__ * 2)(), pg.SRCALPHA, 32).convert_alpha()
|
|
520
|
+
if render: self.__render__()
|
|
521
|
+
|
|
522
|
+
@property
|
|
523
|
+
def text(self) -> str:
|
|
524
|
+
return self.__text__
|
|
525
|
+
@text.setter
|
|
526
|
+
def text(self, new_text:str) -> None:
|
|
527
|
+
self.__text__ = new_text
|
|
528
|
+
self.__render__()
|
|
529
|
+
|
|
530
|
+
@property
|
|
531
|
+
def size(self) -> V2:
|
|
532
|
+
return self.__size__
|
|
533
|
+
@size.setter
|
|
534
|
+
def size(self, new_size:V2|Vector2D) -> None:
|
|
535
|
+
self.__size__ = new_size
|
|
536
|
+
self.update_surface(render=True)
|
|
537
|
+
|
|
538
|
+
@property
|
|
539
|
+
def border_width(self) -> float:
|
|
540
|
+
return self.__border_width__
|
|
541
|
+
@border_width.setter
|
|
542
|
+
def border_width(self, new_width:float) -> None:
|
|
543
|
+
self.__border_width__ = new_width
|
|
544
|
+
self.update_surface(render=True)
|
|
545
|
+
|
|
546
|
+
@property
|
|
547
|
+
def text_color(self) -> Color:
|
|
548
|
+
return unpygamize_color(self.__text_color__)
|
|
549
|
+
@text_color.setter
|
|
550
|
+
def text_color(self, new_color:Color|pg.Color) -> None:
|
|
551
|
+
self.__text_color__ = pygamize_color(new_color)
|
|
552
|
+
@property
|
|
553
|
+
def default_color(self) -> Color:
|
|
554
|
+
return unpygamize_color(self.__default_color__)
|
|
555
|
+
@default_color.setter
|
|
556
|
+
def default_color(self, new_color:Color|pg.Color) -> None:
|
|
557
|
+
self.__default_color__ = pygamize_color(new_color)
|
|
558
|
+
@property
|
|
559
|
+
def border_color(self) -> Color:
|
|
560
|
+
return unpygamize_color(self.__border_color__)
|
|
561
|
+
@border_color.setter
|
|
562
|
+
def border_color(self, new_color:Color|pg.Color) -> None:
|
|
563
|
+
self.__border_color__ = pygamize_color(new_color)
|
|
564
|
+
|
|
565
|
+
def __render__(self) -> None:
|
|
566
|
+
self.buffer_surface.fill(TRANSPARENT_COLOR_PYG)
|
|
567
|
+
|
|
568
|
+
pg.draw.rect(self.buffer_surface, self.__border_color__, V2.zero()() + (self.size + self.border_width * 2)(), border_radius=self.border_radius)
|
|
569
|
+
pg.draw.rect(self.buffer_surface, self.__default_color__, (V2.zero() + self.border_width)() + self.size(), border_radius=self.border_radius)
|
|
570
|
+
|
|
571
|
+
# TODO:
|
|
572
|
+
# not only size * .5 but also internal pivoting on the corners and sides
|
|
573
|
+
self.rootEnv.print(self.text, self.border_width + self.size * .5, color=self.__text_color__, font=self.font, pivot_position="center_center", personalized_surface=self.buffer_surface)
|
|
574
|
+
|
|
575
|
+
def __draw__(self) -> None:
|
|
576
|
+
if self.hidden: return
|
|
577
|
+
self.surface.blit(self.buffer_surface, (self.position)())
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: e2D
|
|
3
|
-
Version: 1.4.
|
|
3
|
+
Version: 1.4.21
|
|
4
4
|
Summary: Python library for 2D games. Streamlines dev with keyboard/mouse input, vector calculations, color manipulation, and collision detection. Simplify game creation and unleash creativity!
|
|
5
5
|
Home-page: https://github.com/marick-py/e2D
|
|
6
6
|
Author: Riccardo Mariani
|
|
@@ -13,6 +13,7 @@ Description-Content-Type: text/markdown
|
|
|
13
13
|
License-File: LICENSE
|
|
14
14
|
Requires-Dist: numpy
|
|
15
15
|
Requires-Dist: pygame
|
|
16
|
+
Dynamic: license-file
|
|
16
17
|
|
|
17
18
|
# e2D
|
|
18
19
|
## A Python Game Development Library
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
e2D/__init__.py,sha256=4I3D04BVJJB8ol9t4fmCLbegF1E_FIdhdf6-87ohdmw,23827
|
|
2
|
+
e2D/__init__.pyi,sha256=thZB-EMOTXyrnuLOxTlQXoYUeUVG-177ZbE7MVwKXCE,53993
|
|
3
|
+
e2D/colors.py,sha256=LGPiWQVkWOZWghfljiuxZ3r8PCxkR2nY8YjTwNqGHA8,19069
|
|
4
|
+
e2D/def_colors.py,sha256=3sJq2L6qFZ3svn2qEWIx0SinNXjb9huNaFigDeJipm8,43805
|
|
5
|
+
e2D/envs.py,sha256=XgORP4XDXwju7SbWvXVwVyAO-RqODZ6SUHHUJLhcq-4,8592
|
|
6
|
+
e2D/plots.py,sha256=_d72ZJo-GIhcJ44XCphFH288cf_ZSwWcbLh_olgGjBc,35880
|
|
7
|
+
e2D/utils.py,sha256=ozdTed195gWIJwmfZYdMr1Lv0_8MqM1kztjfWS-afGQ,29488
|
|
8
|
+
e2D/winrec.py,sha256=EFFfWYbk27NhS-rWD-BLChXvLjFW1uYZ5LkRGMj_Xo0,1116
|
|
9
|
+
e2d-1.4.21.dist-info/licenses/LICENSE,sha256=hbjljn38VVW9en51B0qzRK-v2FBDijqRWbZIVTk7ipU,1094
|
|
10
|
+
e2d-1.4.21.dist-info/METADATA,sha256=EZ9QJvoEXiuy8qdnFNU5MmLFbLwCVjQEEU8KAQd8XYA,9634
|
|
11
|
+
e2d-1.4.21.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
12
|
+
e2d-1.4.21.dist-info/top_level.txt,sha256=3vKZ-CGzNlTCpzVMmM0Ht76krCofKw7hZ0wBf-dnKdM,4
|
|
13
|
+
e2d-1.4.21.dist-info/RECORD,,
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Riccardo Mariani
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Riccardo Mariani
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
e2d-1.4.19.dist-info/RECORD
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
e2D/__init__.py,sha256=Ex3kVbhzHPqoeGhVJr83TAlwRfA65iaoaA_wuKaq1bs,22080
|
|
2
|
-
e2D/__init__.pyi,sha256=SgTFu2fx0qOAp8BbiCT8kd6ySzKwjpZqhfcPlE_pTEE,43472
|
|
3
|
-
e2D/colors.py,sha256=DgkgUdaQY41nA0VlJaMaT6VZwypG--Cw3Pwakf4OVHM,17412
|
|
4
|
-
e2D/def_colors.py,sha256=3sJq2L6qFZ3svn2qEWIx0SinNXjb9huNaFigDeJipm8,43805
|
|
5
|
-
e2D/envs.py,sha256=VmXKHcMBPHArx9u15mZtbAb7eXWdmhSC2nz4y_sRvro,6349
|
|
6
|
-
e2D/plots.py,sha256=_d72ZJo-GIhcJ44XCphFH288cf_ZSwWcbLh_olgGjBc,35880
|
|
7
|
-
e2D/utils.py,sha256=cJarYc6OTIdud7AJZHxwOhxMcEJLlgfKu60kkBu4hB8,14116
|
|
8
|
-
e2D/winrec.py,sha256=EFFfWYbk27NhS-rWD-BLChXvLjFW1uYZ5LkRGMj_Xo0,1116
|
|
9
|
-
e2d-1.4.19.dist-info/LICENSE,sha256=VP36drkzlpF7Kc7qhWiQ-Foke1Ru3WO0e5JgASurHNM,1073
|
|
10
|
-
e2d-1.4.19.dist-info/METADATA,sha256=4Rg4PBPfe_WOlzDT0CPT5450sjo5MX8oIECWWcNy4TQ,9611
|
|
11
|
-
e2d-1.4.19.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
|
|
12
|
-
e2d-1.4.19.dist-info/top_level.txt,sha256=3vKZ-CGzNlTCpzVMmM0Ht76krCofKw7hZ0wBf-dnKdM,4
|
|
13
|
-
e2d-1.4.19.dist-info/RECORD,,
|
|
File without changes
|