batframework 1.0.9a10__py3-none-any.whl → 1.0.10__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.
- batFramework/__init__.py +53 -76
- batFramework/action.py +99 -126
- batFramework/actionContainer.py +9 -53
- batFramework/animatedSprite.py +114 -56
- batFramework/audioManager.py +36 -82
- batFramework/camera.py +69 -263
- batFramework/constants.py +53 -29
- batFramework/cutscene.py +109 -243
- batFramework/cutsceneBlocks.py +176 -0
- batFramework/debugger.py +48 -0
- batFramework/dynamicEntity.py +9 -16
- batFramework/easing.py +71 -0
- batFramework/entity.py +85 -92
- batFramework/gui/__init__.py +3 -14
- batFramework/gui/button.py +78 -12
- batFramework/gui/constraints.py +204 -0
- batFramework/gui/container.py +31 -183
- batFramework/gui/debugger.py +43 -126
- batFramework/gui/frame.py +19 -0
- batFramework/gui/image.py +20 -55
- batFramework/gui/indicator.py +22 -95
- batFramework/gui/interactiveWidget.py +12 -229
- batFramework/gui/label.py +77 -311
- batFramework/gui/layout.py +66 -411
- batFramework/gui/root.py +35 -203
- batFramework/gui/shape.py +57 -247
- batFramework/gui/toggle.py +48 -114
- batFramework/gui/widget.py +243 -457
- batFramework/manager.py +29 -113
- batFramework/particles.py +77 -0
- batFramework/scene.py +217 -22
- batFramework/sceneManager.py +129 -161
- batFramework/stateMachine.py +8 -11
- batFramework/time.py +75 -0
- batFramework/transition.py +124 -129
- batFramework/transitionManager.py +0 -0
- batFramework/triggerZone.py +4 -4
- batFramework/utils.py +144 -266
- {batframework-1.0.9a10.dist-info → batframework-1.0.10.dist-info}/METADATA +24 -17
- batframework-1.0.10.dist-info/RECORD +43 -0
- batFramework/animation.py +0 -77
- batFramework/baseScene.py +0 -240
- batFramework/cutsceneManager.py +0 -34
- batFramework/drawable.py +0 -77
- batFramework/easingController.py +0 -58
- batFramework/enums.py +0 -135
- batFramework/fontManager.py +0 -65
- batFramework/gui/animatedLabel.py +0 -89
- batFramework/gui/clickableWidget.py +0 -245
- batFramework/gui/constraints/__init__.py +0 -1
- batFramework/gui/constraints/constraints.py +0 -980
- batFramework/gui/draggableWidget.py +0 -44
- batFramework/gui/meter.py +0 -96
- batFramework/gui/radioButton.py +0 -35
- batFramework/gui/selector.py +0 -250
- batFramework/gui/slider.py +0 -397
- batFramework/gui/style.py +0 -10
- batFramework/gui/styleManager.py +0 -54
- batFramework/gui/syncedVar.py +0 -49
- batFramework/gui/textInput.py +0 -306
- batFramework/gui/tooltip.py +0 -30
- batFramework/particle.py +0 -118
- batFramework/propertyEaser.py +0 -79
- batFramework/renderGroup.py +0 -34
- batFramework/resourceManager.py +0 -130
- batFramework/sceneLayer.py +0 -138
- batFramework/scrollingSprite.py +0 -115
- batFramework/sprite.py +0 -51
- batFramework/templates/__init__.py +0 -1
- batFramework/templates/controller.py +0 -97
- batFramework/tileset.py +0 -46
- batFramework/timeManager.py +0 -213
- batframework-1.0.9a10.dist-info/RECORD +0 -67
- {batframework-1.0.9a10.dist-info → batframework-1.0.10.dist-info}/LICENSE +0 -0
- {batframework-1.0.9a10.dist-info → batframework-1.0.10.dist-info}/WHEEL +0 -0
- {batframework-1.0.9a10.dist-info → batframework-1.0.10.dist-info}/top_level.txt +0 -0
batFramework/gui/root.py
CHANGED
@@ -2,227 +2,59 @@ import batFramework as bf
|
|
2
2
|
from .interactiveWidget import InteractiveWidget
|
3
3
|
from .widget import Widget
|
4
4
|
import pygame
|
5
|
-
from typing import Self
|
6
|
-
import sys
|
7
|
-
|
8
5
|
|
9
6
|
class Root(InteractiveWidget):
|
10
|
-
def __init__(self
|
7
|
+
def __init__(self):
|
11
8
|
super().__init__()
|
12
|
-
self.
|
13
|
-
self.
|
14
|
-
self.visible = False
|
9
|
+
self.surface = None
|
10
|
+
self.set_root()
|
15
11
|
self.rect.size = pygame.display.get_surface().get_size()
|
16
|
-
self.focused: InteractiveWidget
|
17
|
-
self.hovered: Widget
|
18
|
-
self.
|
19
|
-
self.set_debug_color("yellow")
|
20
|
-
|
21
|
-
self.show_tooltip : bool = True
|
22
|
-
self.tooltip = bf.gui.ToolTip("").set_visible(False)
|
23
|
-
self.add(self.tooltip)
|
24
|
-
|
25
|
-
def toggle_tooltip(self,value:bool)->Self:
|
26
|
-
self.show_tooltip = value
|
27
|
-
return self
|
28
|
-
|
29
|
-
def __str__(self) -> str:
|
30
|
-
return "Root"
|
31
|
-
|
32
|
-
def to_ascii_tree(self) -> str:
|
33
|
-
def f(w, depth):
|
34
|
-
prefix = " " * (depth * 4) + ("└── " if depth > 0 else "")
|
35
|
-
children = "\n".join(f(c, depth + 1) for c in w.children) if w.children else ""
|
36
|
-
return f"{prefix}{str(w)}\n{children}"
|
37
|
-
return f(self, 0)
|
12
|
+
self.focused : InteractiveWidget = self
|
13
|
+
self.hovered : Widget|None = self
|
14
|
+
self.set_debug_color("purple")
|
38
15
|
|
39
|
-
def
|
40
|
-
|
16
|
+
def to_string(self)->str:
|
17
|
+
return "ROOT"
|
41
18
|
|
42
|
-
def get_focused(self)
|
19
|
+
def get_focused(self)->Widget|None:
|
43
20
|
return self.focused
|
44
21
|
|
45
|
-
def get_hovered(self)
|
22
|
+
def get_hovered(self)->Widget|None:
|
46
23
|
return self.hovered
|
24
|
+
|
25
|
+
def to_string_id(self)->str:
|
26
|
+
return "ROOT"
|
47
27
|
|
48
|
-
def
|
49
|
-
self.
|
50
|
-
|
51
|
-
def clear_hovered(self) -> None:
|
52
|
-
if isinstance(self.hovered, InteractiveWidget):
|
53
|
-
self.hovered.on_exit()
|
54
|
-
self.hovered = None
|
55
|
-
|
56
|
-
def get_debug_outlines(self):
|
57
|
-
yield (self.rect, self.debug_color)
|
58
|
-
for child in self.children:
|
59
|
-
yield from child.get_debug_outlines()
|
60
|
-
|
61
|
-
def focus_on(self, widget: InteractiveWidget | None) -> None:
|
62
|
-
if widget == self.focused:
|
63
|
-
return
|
64
|
-
if widget and not widget.allow_focus_to_self():
|
65
|
-
return
|
66
|
-
if self.focused is not None:
|
28
|
+
def focus_on(self,widget:InteractiveWidget)->None:
|
29
|
+
if self.focused is not None:
|
67
30
|
self.focused.on_lose_focus()
|
68
|
-
if widget is None:
|
31
|
+
if widget is None :
|
69
32
|
self.focused = self
|
70
33
|
return
|
71
|
-
self.focused
|
34
|
+
self.focused= widget
|
72
35
|
self.focused.on_get_focus()
|
73
36
|
|
74
|
-
def
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
nonlocal res
|
79
|
-
if any(t in w.tags for t in tags):
|
80
|
-
res.append(w)
|
81
|
-
|
82
|
-
self.visit(getter)
|
83
|
-
return res
|
84
|
-
|
85
|
-
def focus_next_tab(self, widget):
|
86
|
-
return
|
87
|
-
|
88
|
-
def focus_prev_tab(self, widget):
|
89
|
-
return
|
90
|
-
|
91
|
-
def get_by_uid(self, uid: int) -> "Widget":
|
92
|
-
def helper(w: "Widget", uid: int) -> "Widget":
|
93
|
-
if w.uid == uid:
|
94
|
-
return w
|
95
|
-
for child in w.children:
|
96
|
-
res = helper(child, uid)
|
97
|
-
if res is not None:
|
98
|
-
return res
|
99
|
-
return None
|
100
|
-
|
101
|
-
return helper(self, uid)
|
102
|
-
|
103
|
-
def set_size(self, size: tuple[float, float], force: bool = False) -> "Root":
|
104
|
-
if not force:
|
105
|
-
return self
|
106
|
-
self.rect.size = size
|
107
|
-
self.dirty_shape = True
|
108
|
-
self.dirty_size_constraints = True
|
37
|
+
def set_size(self,width:float,height:float,force:bool=False)->"Root":
|
38
|
+
if not force : return self
|
39
|
+
self.rect.size = width,height
|
40
|
+
self.build(apply_constraints=True)
|
109
41
|
return self
|
110
|
-
|
111
|
-
def process_event(self,event):
|
112
|
-
if not event.consumed : self.do_handle_event_early(event)
|
113
|
-
if not event.consumed : super().process_event(event)
|
114
42
|
|
115
|
-
def
|
116
|
-
if
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
if not self.hovered or (not isinstance(self.hovered, InteractiveWidget)):
|
127
|
-
event.consumed = True
|
128
|
-
return
|
129
|
-
|
130
|
-
if event.type == pygame.MOUSEBUTTONDOWN:
|
131
|
-
event.consumed = self.hovered.on_click_down(event.button)
|
132
|
-
|
133
|
-
elif event.type == pygame.MOUSEBUTTONUP:
|
134
|
-
event.consumed = self.hovered.on_click_up(event.button)
|
135
|
-
|
136
|
-
def do_on_click_down(self, button: int) -> None:
|
137
|
-
if button == 1:
|
138
|
-
self.clear_focused()
|
139
|
-
|
140
|
-
def top_at(self, x: float | int, y: float | int) -> "None|Widget":
|
141
|
-
if self.children:
|
142
|
-
for child in reversed(self.children):
|
143
|
-
r = child.top_at(x, y)
|
144
|
-
if r is not None:
|
145
|
-
return r
|
146
|
-
return self if self.rect.collidepoint(x, y) else None
|
43
|
+
def build(self,apply_constraints:bool=False)->None:
|
44
|
+
if apply_constraints : self.apply_all_constraints()
|
45
|
+
for child in self.children :
|
46
|
+
child.build()
|
47
|
+
|
48
|
+
def do_handle_event(self,event):
|
49
|
+
if event.type == pygame.VIDEORESIZE:
|
50
|
+
self.set_size(event.w,event.h,force=True)
|
51
|
+
return True
|
52
|
+
return False
|
147
53
|
|
148
|
-
def update(self,
|
54
|
+
def update(self,dt:float)->None:
|
149
55
|
super().update(dt)
|
150
|
-
self.
|
151
|
-
|
152
|
-
mouse_screen = pygame.mouse.get_pos()
|
153
|
-
mouse_world = self.drawing_camera.screen_to_world(mouse_screen)
|
154
|
-
prev_hovered = self.hovered
|
155
|
-
self.hovered = self.top_at(*mouse_world) or None
|
156
|
-
|
157
|
-
# Tooltip logic
|
158
|
-
if self.hovered and self.hovered.tooltip_text:
|
159
|
-
self.tooltip.set_text(self.hovered.tooltip_text)
|
160
|
-
|
161
|
-
tooltip_size = self.tooltip.get_min_required_size()
|
162
|
-
screen_w, screen_h = self.drawing_camera.rect.size
|
163
|
-
tooltip_x, tooltip_y = self.drawing_camera.world_to_screen_point(mouse_world)
|
164
|
-
|
165
|
-
tooltip_x = min(tooltip_x, screen_w - tooltip_size[0])
|
166
|
-
tooltip_y = min(tooltip_y, screen_h - tooltip_size[1])
|
167
|
-
tooltip_x = max(0, tooltip_x)
|
168
|
-
tooltip_y = max(0, tooltip_y)
|
169
|
-
|
170
|
-
self.tooltip.set_position(tooltip_x, tooltip_y)
|
171
|
-
self.tooltip.fade_in()
|
172
|
-
else:
|
173
|
-
self.tooltip.fade_out()
|
174
|
-
|
175
|
-
if self.hovered == prev_hovered:
|
176
|
-
if isinstance(self.hovered, InteractiveWidget):
|
177
|
-
self.hovered.on_mouse_motion(*mouse_world)
|
178
|
-
return
|
179
|
-
|
180
|
-
if isinstance(prev_hovered, InteractiveWidget):
|
181
|
-
prev_hovered.on_exit()
|
182
|
-
if isinstance(self.hovered, InteractiveWidget):
|
183
|
-
self.hovered.on_enter()
|
184
|
-
|
185
|
-
|
186
|
-
def _handle_alt_tab(self,key):
|
187
|
-
if self.focused is None:
|
188
|
-
return False
|
189
|
-
if key != pygame.K_TAB:
|
190
|
-
return False
|
191
|
-
keys = pygame.key.get_pressed()
|
192
|
-
if keys[pygame.K_LSHIFT] or keys[pygame.K_RSHIFT]:
|
193
|
-
self.focused.focus_prev_tab(self.focused)
|
194
|
-
else:
|
195
|
-
self.focused.focus_next_tab(self.focused)
|
196
|
-
return True
|
197
|
-
|
198
|
-
def update_tree(self):
|
199
|
-
# print("START updating tree")
|
200
|
-
self.apply_updates("pre")
|
201
|
-
self.apply_updates("post")
|
202
|
-
|
203
|
-
self.apply_updates("pre")
|
204
|
-
self.apply_updates("post")
|
205
|
-
|
206
|
-
# print("END updating tree")
|
207
|
-
|
208
|
-
def apply_pre_updates(self):
|
209
|
-
return
|
56
|
+
self.hovered = self.top_at(*pygame.mouse.get_pos()) if self.top_at(*pygame.mouse.get_pos()) else None
|
57
|
+
|
210
58
|
|
211
|
-
def apply_post_updates(self, skip_draw = False):
|
212
|
-
return
|
213
59
|
|
214
|
-
|
215
|
-
super().draw(camera)
|
216
|
-
if (
|
217
|
-
self.parent_scene
|
218
|
-
and self.parent_scene.active
|
219
|
-
and self.focused
|
220
|
-
and self.focused != self
|
221
|
-
):
|
222
|
-
clip:bool =self.focused.parent and self.focused.parent.clip_children
|
223
|
-
if clip:
|
224
|
-
old_clip = camera.surface.get_clip()
|
225
|
-
camera.surface.set_clip(camera.world_to_screen(self.focused.parent.rect))
|
226
|
-
if clip:
|
227
|
-
camera.surface.set_clip(old_clip)
|
228
|
-
self.focused.draw_focused(camera)
|
60
|
+
|
batFramework/gui/shape.py
CHANGED
@@ -1,276 +1,86 @@
|
|
1
1
|
import batFramework as bf
|
2
2
|
from .widget import Widget
|
3
3
|
import pygame
|
4
|
-
from typing import Self, Iterable
|
5
|
-
from math import ceil
|
6
4
|
|
7
5
|
|
8
6
|
class Shape(Widget):
|
9
|
-
def __init__(self,
|
10
|
-
|
11
|
-
self.
|
12
|
-
self.
|
13
|
-
self.
|
14
|
-
|
15
|
-
self.
|
16
|
-
self.texture_subsize = (0, 0)
|
17
|
-
self.relief = 0
|
18
|
-
self.shadow_color: tuple[int, int, int] | str = (0, 0, 0, 255)
|
19
|
-
self.draw_mode = bf.drawMode.SOLID
|
7
|
+
def __init__(self,width:float,height:float):
|
8
|
+
self._color = (0,0,0,0)
|
9
|
+
self._border_radius:list[int] = [0]
|
10
|
+
self._outline : int = 0
|
11
|
+
self._outline_color : tuple[int,int,int] | str = (0,0,0,0)
|
12
|
+
super().__init__(convert_alpha = True)
|
13
|
+
self.set_size(width,height)
|
20
14
|
|
21
|
-
def get_inner_bottom(self) -> float:
|
22
|
-
return self.rect.bottom - self.padding[3] - self.relief
|
23
15
|
|
24
|
-
def
|
25
|
-
return self.rect.h - self.padding[1] - self.padding[3] - self.relief
|
26
|
-
|
27
|
-
def get_inner_top(self) -> float:
|
28
|
-
return self.rect.y + self.padding[1]
|
29
|
-
|
30
|
-
def get_local_inner_rect(self)->pygame.FRect:
|
31
|
-
return pygame.FRect(
|
32
|
-
self.padding[0],
|
33
|
-
self.padding[1],
|
34
|
-
self.rect.w - self.padding[2] - self.padding[0],
|
35
|
-
self.rect.h - self.padding[1] - self.padding[3] - self.relief,
|
36
|
-
)
|
37
|
-
|
38
|
-
def get_inner_rect(self) -> pygame.FRect:
|
39
|
-
return pygame.FRect(
|
40
|
-
self.rect.x + self.padding[0],
|
41
|
-
self.rect.y + self.padding[1],
|
42
|
-
self.rect.w - self.padding[2] - self.padding[0],
|
43
|
-
self.rect.h - self.padding[1] - self.padding[3] - self.relief,
|
44
|
-
)
|
45
|
-
|
46
|
-
def set_shadow_color(self, color: tuple[int, int, int] | str) -> Self:
|
47
|
-
self.shadow_color = color
|
48
|
-
self.dirty_surface = True
|
49
|
-
return self
|
50
|
-
|
51
|
-
def set_relief(self, relief: int) -> Self:
|
52
|
-
if relief < 0:
|
53
|
-
return self
|
54
|
-
self.dirty_shape = self.relief != relief
|
55
|
-
self.relief = relief
|
56
|
-
return self
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
def set_texture(
|
61
|
-
self, surface: pygame.SurfaceType, subsize: tuple[int, int] | None = None
|
62
|
-
) -> Self:
|
63
|
-
self.texture_surface = surface
|
64
|
-
if subsize is None:
|
65
|
-
subsize = (ceil(surface.get_width() / 3), ceil(surface.get_height() / 3))
|
66
|
-
self.texture_subsize = subsize
|
67
|
-
self.dirty_surface = True
|
68
|
-
return self
|
69
|
-
|
70
|
-
def set_draw_mode(self, mode: bf.drawMode) -> Self:
|
71
|
-
self.draw_mode = mode
|
72
|
-
self.dirty_surface = True
|
73
|
-
return self
|
74
|
-
|
75
|
-
def get_draw_mode(self) -> bf.drawMode:
|
76
|
-
return self.draw_mode
|
77
|
-
|
78
|
-
def has_alpha_color(self) -> bool:
|
79
|
-
return (pygame.Color(self.color).a != 255) or (
|
80
|
-
pygame.Color(self.outline_color).a != 255
|
81
|
-
)
|
82
|
-
|
83
|
-
def __str__(self) -> str:
|
16
|
+
def to_string_id(self)->str:
|
84
17
|
return "Shape"
|
85
18
|
|
86
|
-
def set_color(self,
|
87
|
-
self.
|
88
|
-
self.
|
19
|
+
def set_color(self,color:tuple[int,int,int]|str) -> "Frame":
|
20
|
+
self._color = color
|
21
|
+
self.build()
|
89
22
|
return self
|
90
23
|
|
91
|
-
def set_outline_color(self,
|
92
|
-
self.
|
93
|
-
self.
|
24
|
+
def set_outline_color(self,color:tuple[int,int,int]|str) -> "Frame":
|
25
|
+
self._outline_color = color
|
26
|
+
self.build()
|
94
27
|
return self
|
95
28
|
|
96
|
-
def set_border_radius(self,
|
97
|
-
if isinstance(value,
|
98
|
-
self.
|
29
|
+
def set_border_radius(self,value:int|list[int]) -> "Frame":
|
30
|
+
if isinstance(value,int):
|
31
|
+
self._border_radius = [value]
|
99
32
|
else:
|
100
|
-
self.
|
101
|
-
self.
|
33
|
+
self._border_radius = value
|
34
|
+
self.build()
|
102
35
|
return self
|
103
|
-
|
104
|
-
def set_outline_width(self,
|
105
|
-
self.
|
106
|
-
self.
|
36
|
+
|
37
|
+
def set_outline_width(self,value:int) -> "Frame":
|
38
|
+
self._outline = value
|
39
|
+
self.build()
|
107
40
|
return self
|
108
|
-
|
109
|
-
def
|
110
|
-
if self.
|
111
|
-
self.
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
if self.
|
116
|
-
self.
|
41
|
+
|
42
|
+
def build(self)->None:
|
43
|
+
if self.surface.get_size() != self.get_size_int():
|
44
|
+
self.surface = pygame.Surface(self.get_size_int())
|
45
|
+
if self.convert_alpha :
|
46
|
+
self.surface = self.surface.convert_alpha()
|
47
|
+
self.surface.fill((0,0,0,0))
|
48
|
+
if self.parent :
|
49
|
+
self.parent.children_modified()
|
50
|
+
if self._border_radius == [0]:
|
51
|
+
self._build_shape()
|
52
|
+
if self._outline : self._build_outline()
|
117
53
|
else:
|
118
|
-
self.
|
119
|
-
if self.
|
120
|
-
self._paint_rounded_outline()
|
54
|
+
self._build_rounded_shape()
|
55
|
+
if self._outline : self._build_rounded_outline()
|
121
56
|
|
122
|
-
def _paint_textured(self) -> None:
|
123
|
-
self.surface.fill((0, 0, 0, 0))
|
124
|
-
if self.texture_surface is None:
|
125
|
-
return
|
126
|
-
w, h = self.surface.get_size()
|
127
|
-
sw, sh = self.texture_surface.get_size()
|
128
|
-
sub = self.texture_subsize
|
129
57
|
|
130
|
-
|
131
|
-
|
132
|
-
top_surface = self.texture_surface.subsurface((sub[0], 0, *sub))
|
133
|
-
bottom_surface = self.texture_surface.subsurface((sub[0], sh - sub[1], *sub))
|
134
|
-
left_surface = self.texture_surface.subsurface((0, sub[1], *sub))
|
135
|
-
right_surface = self.texture_surface.subsurface((sw - sub[0], sub[1], *sub))
|
58
|
+
def _build_shape(self)->None:
|
59
|
+
self.surface.fill(self._color)
|
136
60
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
fix_y = ((h // sub[1]) - 1) * sub[1]
|
146
|
-
|
147
|
-
if (w > sub[0]) and (w_remainder > 0):
|
148
|
-
# Center : Fix gaps on the x axis
|
149
|
-
h_portion = center_surface.subsurface(0, 0, w_remainder, sub[1])
|
150
|
-
for y in range(sub[1], h - sub[1] * 2, sub[1]):
|
151
|
-
lst.append((h_portion, (fix_x, y)))
|
152
|
-
|
153
|
-
# Fix partial gaps on the top
|
154
|
-
|
155
|
-
t_portion = top_surface.subsurface(0, 0, w_remainder, sub[1])
|
156
|
-
lst.append((t_portion, (fix_x, 0)))
|
157
|
-
|
158
|
-
# Fix partial gaps on the bottom
|
159
|
-
b_portion = bottom_surface.subsurface(0, 0, w_remainder, sub[1])
|
160
|
-
lst.append((b_portion, (fix_x, h - sub[1] - 1)))
|
161
|
-
|
162
|
-
if (h > sub[1]) and (h_remainder > 0):
|
163
|
-
# Center : Fix gaps on the y axis
|
164
|
-
v_portion = center_surface.subsurface(0, 0, sub[0], h_remainder)
|
165
|
-
for x in range(sub[0], w - sub[0] * 2, sub[0]):
|
166
|
-
lst.append((v_portion, (x, fix_y)))
|
167
|
-
|
168
|
-
# Fix partial gaps on the left
|
169
|
-
l_portion = left_surface.subsurface(0, 0, sub[0], h_remainder)
|
170
|
-
lst.append((l_portion, (0, fix_y)))
|
171
|
-
|
172
|
-
# Fix partial gaps on the right
|
173
|
-
r_portion = right_surface.subsurface(0, 0, sub[0], h_remainder)
|
174
|
-
lst.append((r_portion, (w - sub[0] - 1, fix_y)))
|
175
|
-
|
176
|
-
# fix corner gap
|
177
|
-
if h > sub[1] or w > sub[0]:
|
178
|
-
corner_portion = center_surface.subsurface(
|
179
|
-
0,
|
180
|
-
0,
|
181
|
-
w_remainder if w_remainder else sub[0],
|
182
|
-
h_remainder if h_remainder else sub[1],
|
183
|
-
)
|
184
|
-
if w_remainder == 0:
|
185
|
-
fix_x -= sub[0]
|
186
|
-
if h_remainder == 0:
|
187
|
-
fix_y -= sub[1]
|
188
|
-
lst.append((corner_portion, (fix_x - 1, fix_y - 1)))
|
189
|
-
|
190
|
-
# borders
|
191
|
-
lst.extend(
|
192
|
-
[(top_surface, (x, 0)) for x in range(sub[0], w + 1 - sub[0] * 2, sub[0])]
|
193
|
-
+ [
|
194
|
-
(bottom_surface, (x, h - sub[1] - 1))
|
195
|
-
for x in range(sub[0], w + 1 - sub[0] * 2, sub[0])
|
196
|
-
]
|
197
|
-
+ [
|
198
|
-
(left_surface, (0, y))
|
199
|
-
for y in range(sub[1], h + 1 - sub[1] * 2, sub[1])
|
200
|
-
]
|
201
|
-
+ [
|
202
|
-
(right_surface, (w - sub[0] - 1, y))
|
203
|
-
for y in range(sub[1], h + 1 - sub[1] * 2, sub[1])
|
204
|
-
]
|
205
|
-
+ [
|
206
|
-
(self.texture_surface.subsurface((0, 0, *sub)), (0, 0)),
|
207
|
-
(
|
208
|
-
self.texture_surface.subsurface((sw - sub[0], 0, *sub)),
|
209
|
-
(w - sub[0] - 1, 0),
|
210
|
-
),
|
211
|
-
(
|
212
|
-
self.texture_surface.subsurface((0, sh - sub[1], *sub)),
|
213
|
-
(0, h - sub[1] - 1),
|
214
|
-
),
|
215
|
-
(
|
216
|
-
self.texture_surface.subsurface((sw - sub[0], sh - sub[1], *sub)),
|
217
|
-
(w - sub[0] - 1, h - sub[1] - 1),
|
218
|
-
),
|
219
|
-
]
|
61
|
+
def _build_rounded_shape(self)->None:
|
62
|
+
self.surface.fill((0,0,0,0))
|
63
|
+
pygame.draw.rect(
|
64
|
+
self.surface,
|
65
|
+
self._color,
|
66
|
+
(0,0,*self.rect.size),
|
67
|
+
0,
|
68
|
+
*self._border_radius
|
220
69
|
)
|
221
70
|
|
222
|
-
|
223
|
-
|
224
|
-
def _get_elevated_rect(self) -> pygame.FRect:
|
225
|
-
return pygame.FRect(0, 0, self.rect.w, self.rect.h - self.relief)
|
226
|
-
|
227
|
-
def _get_base_rect(self) -> pygame.FRect:
|
228
|
-
return pygame.FRect(0, self.rect.h - self.relief, self.rect.w, self.relief)
|
229
|
-
|
230
|
-
def _paint_shape(self) -> None:
|
231
|
-
self.surface.fill((0, 0, 0, 0))
|
232
|
-
if self.relief!=0:
|
233
|
-
self.surface.fill(self.shadow_color, self._get_base_rect())
|
234
|
-
self.surface.fill(self.color, self._get_elevated_rect())
|
235
|
-
else:
|
236
|
-
self.surface.fill(self.color, self._get_elevated_rect())
|
237
|
-
|
238
|
-
def _paint_rounded_shape(self) -> None:
|
239
|
-
self.surface.fill((0, 0, 0, 0))
|
240
|
-
e = self._get_elevated_rect()
|
241
|
-
if self.relief != 0:
|
242
|
-
b = e.copy()
|
243
|
-
b.bottom = self.rect.h
|
244
|
-
pygame.draw.rect(self.surface, self.shadow_color, b, 0, *self.border_radius)
|
245
|
-
pygame.draw.rect(self.surface, self.color, e, 0, *self.border_radius)
|
246
|
-
else:
|
247
|
-
pygame.draw.rect(self.surface, self.color, e, 0, *self.border_radius)
|
248
|
-
|
249
|
-
def _paint_outline(self) -> None:
|
71
|
+
def _build_outline(self)->None:
|
250
72
|
pygame.draw.rect(
|
251
73
|
self.surface,
|
252
|
-
self.
|
253
|
-
self.
|
254
|
-
self.
|
74
|
+
self._outline_color,
|
75
|
+
(0,0,*self.rect.size),
|
76
|
+
self._outline
|
255
77
|
)
|
256
|
-
|
257
|
-
def
|
258
|
-
e = self._get_elevated_rect()
|
259
|
-
b = e.copy()
|
260
|
-
b.h += e.bottom - b.bottom
|
261
|
-
|
78
|
+
|
79
|
+
def _build_rounded_outline(self)->None:
|
262
80
|
pygame.draw.rect(
|
263
81
|
self.surface,
|
264
|
-
self.
|
265
|
-
|
266
|
-
self.
|
267
|
-
*self.
|
82
|
+
self._outline_color,
|
83
|
+
(0,0,*self.rect.size),
|
84
|
+
self._outline,
|
85
|
+
*self._border_radius
|
268
86
|
)
|
269
|
-
if self.relief:
|
270
|
-
pygame.draw.rect(
|
271
|
-
self.surface,
|
272
|
-
self.outline_color,
|
273
|
-
b,
|
274
|
-
self.outline_width,
|
275
|
-
*self.border_radius,
|
276
|
-
)
|