Skip to content

Commit

Permalink
Add test 'border_overlap' theming to somewhat control overlapping of …
Browse files Browse the repository at this point in the history
…curved shapes and their borders.
  • Loading branch information
MyreMylar committed Dec 29, 2024
1 parent 4caccad commit 9db2a81
Show file tree
Hide file tree
Showing 17 changed files with 65 additions and 23 deletions.
11 changes: 7 additions & 4 deletions pygame_gui/core/drawable_shapes/ellipse_drawable_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ def redraw_state(self, state_str: str, add_text: bool = True):
text_colour_state_str = state_str + '_text'
text_shadow_colour_state_str = state_str + '_text_shadow'
image_state_str = state_str + '_image'
border_overlap = 0
if 'border_overlap' in self.theming:
border_overlap = self.theming['border_overlap']

found_shape = None
shape_id = None
Expand Down Expand Up @@ -214,25 +217,25 @@ def redraw_state(self, state_str: str, add_text: bool = True):
if isinstance(self.theming[border_colour_state_str], ColourGradient):
shape_surface = self.clear_and_create_shape_surface(bab_surface,
self.border_rect,
0, aa_amount=aa_amount,
border_overlap, aa_amount=aa_amount,
clear=False)
self.theming[border_colour_state_str].apply_gradient_to_surface(shape_surface)
else:
shape_surface = self.clear_and_create_shape_surface(bab_surface,
self.border_rect,
0, aa_amount=aa_amount,
border_overlap, aa_amount=aa_amount,
clear=False)
apply_colour_to_surface(self.theming[border_colour_state_str],
shape_surface)
basic_blit(bab_surface, shape_surface, self.border_rect)
if isinstance(self.theming[bg_colour_state_str], ColourGradient):
shape_surface = self.clear_and_create_shape_surface(bab_surface,
self.background_rect, 1,
self.background_rect, border_overlap,
aa_amount=aa_amount)
self.theming[bg_colour_state_str].apply_gradient_to_surface(shape_surface)
else:
shape_surface = self.clear_and_create_shape_surface(bab_surface,
self.background_rect, 1,
self.background_rect, border_overlap,
aa_amount=aa_amount)
apply_colour_to_surface(self.theming[bg_colour_state_str], shape_surface)

Expand Down
10 changes: 7 additions & 3 deletions pygame_gui/core/drawable_shapes/rounded_rect_drawable_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ def redraw_state(self, state_str: str, add_text: bool = True):
text_shadow_colour_state_str = state_str + '_text_shadow'
bg_col = self.theming[state_str + '_bg']
border_col = self.theming[state_str + '_border']
border_overlap = 0
if 'border_overlap' in self.theming:
border_overlap = self.theming['border_overlap']

found_shape = None
shape_id = None
Expand Down Expand Up @@ -378,7 +381,7 @@ def redraw_state(self, state_str: str, add_text: bool = True):
if self.border_width > 0:
shape_surface = self.clear_and_create_shape_surface(bab_surface,
self.border_rect,
0,
border_overlap,
self.shape_corner_radius,
aa_amount=aa_amount,
clear=False)
Expand All @@ -391,7 +394,7 @@ def redraw_state(self, state_str: str, add_text: bool = True):

shape_surface = self.clear_and_create_shape_surface(bab_surface,
self.background_rect,
0,
border_overlap,
bg_corner_radii,
aa_amount=aa_amount)

Expand Down Expand Up @@ -545,7 +548,8 @@ def create_subtract_surface(self,
self.temp_subtractive_shape = pygame.surface.Surface(subtract_size,
flags=pygame.SRCALPHA,
depth=32)
self.temp_subtractive_shape.fill(pygame.Color('#00000000'))
clear_colour = '#00000000'
self.temp_subtractive_shape.fill(pygame.Color(clear_colour))
RoundedRectangleShape.draw_colourless_rounded_rectangle(corner_radii,
self.temp_subtractive_shape,
int(aa_amount / 2))
Expand Down
5 changes: 5 additions & 0 deletions pygame_gui/core/ui_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def __init__(self, relative_rect: RectLike,
# Themed parameters
self.shadow_width = None # type: Union[None, int]
self.border_width = None # type: Union[None, int]
self.border_overlap = None # type: Union[None, int]
self.shape_corner_radius: Optional[List[int]] = None

self.tool_tip_text = None
Expand Down Expand Up @@ -113,6 +114,7 @@ def __init__(self, relative_rect: RectLike,
# need to expand our rect by the shadow size and adjust position by it as well.
self._check_shape_theming_changed(defaults={'border_width': 1,
'shadow_width': 2,
'border_overlap': 1,
'shape_corner_radius': [2, 2, 2, 2]})
self.relative_rect.width += self.shadow_width * 2
self.relative_rect.height += self.shadow_width * 2
Expand Down Expand Up @@ -1308,6 +1310,9 @@ def _check_shape_theming_changed(self, defaults: Dict[str, Any]) -> bool:
if self._check_misc_theme_data_changed('shadow_width', defaults['shadow_width'], int):
has_any_changed = True

if self._check_misc_theme_data_changed('border_overlap', defaults['border_overlap'], int):
has_any_changed = True

# corner radius
temp_corner_radius = [0, 0, 0, 0]
try:
Expand Down
4 changes: 3 additions & 1 deletion pygame_gui/elements/ui_2d_slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ def rebuild(self):
"disabled_border": self.disabled_border_colour,
"border_width": self.border_width,
"shadow_width": self.shadow_width,
"shape_corner_radius": self.shape_corner_radius}
"shape_corner_radius": self.shape_corner_radius,
'border_overlap': self.border_overlap}

if self.shape == "rectangle":
self.drawable_shape = RectDrawableShape(self.rect, theming_parameters,
Expand Down Expand Up @@ -355,6 +356,7 @@ def rebuild_from_changed_theme_data(self) -> None:

if self._check_shape_theming_changed(defaults={"border_width": 1,
"shadow_width": 2,
"border_overlap": 1,
"shape_corner_radius": [2, 2, 2, 2]}):
has_any_changed = True

Expand Down
4 changes: 3 additions & 1 deletion pygame_gui/elements/ui_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ def rebuild_from_changed_theme_data(self):

if self._check_shape_theming_changed(defaults={'border_width': 1,
'shadow_width': 2,
'border_overlap': 1,
'shape_corner_radius': [2, 2, 2, 2]}):
has_any_changed = True

Expand Down Expand Up @@ -747,7 +748,8 @@ def rebuild(self):
'text_horiz_alignment_method': self.text_horiz_alignment_method,
'text_vert_alignment_padding': self.text_vert_alignment_padding,
'shape_corner_radius': self.shape_corner_radius,
'transitions': self.state_transitions}
'transitions': self.state_transitions,
'border_overlap': self.border_overlap}

drawable_shape_rect = self.rect.copy()
if self.dynamic_width:
Expand Down
7 changes: 5 additions & 2 deletions pygame_gui/elements/ui_drop_down_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ def rebuild(self):
'normal_border': self.drop_down_menu_ui.border_colour,
'border_width': self.drop_down_menu_ui.border_width,
'shadow_width': self.drop_down_menu_ui.shadow_width,
'shape_corner_radius': self.drop_down_menu_ui.shape_corner_radius}
'shape_corner_radius': self.drop_down_menu_ui.shape_corner_radius,
'border_overlap': self.drop_down_menu_ui.border_overlap}

shape_rect = self.drop_down_menu_ui.relative_rect
if self.drop_down_menu_ui.shape == 'rectangle':
Expand Down Expand Up @@ -457,7 +458,8 @@ def rebuild(self):
'disabled_border': self.drop_down_menu_ui.disabled_border_colour,
'border_width': self.drop_down_menu_ui.border_width,
'shadow_width': self.drop_down_menu_ui.shadow_width,
'shape_corner_radius': self.drop_down_menu_ui.shape_corner_radius}
'shape_corner_radius': self.drop_down_menu_ui.shape_corner_radius,
'border_overlap': self.drop_down_menu_ui.border_overlap}

if self.drop_down_menu_ui.shape == 'rectangle':
self.drop_down_menu_ui.drawable_shape = RectDrawableShape(self.drop_down_menu_ui.rect,
Expand Down Expand Up @@ -888,6 +890,7 @@ def rebuild_from_changed_theme_data(self):

if self._check_shape_theming_changed(defaults={'border_width': 1,
'shadow_width': 2,
'border_overlap': 1,
'shape_corner_radius': [2, 2, 2, 2]}):
has_any_changed = True

Expand Down
8 changes: 6 additions & 2 deletions pygame_gui/elements/ui_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ def rebuild_from_changed_theme_data(self) -> None:

if self._check_shape_theming_changed(defaults={"border_width": 1,
"shadow_width": 2,
'border_overlap': 1,
"shape_corner_radius": 2}):
has_any_changed = True

Expand Down Expand Up @@ -301,7 +302,8 @@ def rebuild(self) -> None:
"normal_image": self.background_image,
"border_width": self.border_width,
"shadow_width": self.shadow_width,
"shape_corner_radius": self.shape_corner_radius}
"shape_corner_radius": self.shape_corner_radius,
'border_overlap': self.border_overlap}

if self.shape == "rectangle":
self.drawable_shape = RectDrawableShape(self.rect, theming_parameters,
Expand Down Expand Up @@ -784,6 +786,7 @@ def rebuild_from_changed_theme_data(self) -> None:

if self._check_shape_theming_changed(defaults={"border_width": 1,
"shadow_width": 2,
'border_overlap': 1,
"shape_corner_radius": 2}):
has_any_changed = True

Expand Down Expand Up @@ -1025,7 +1028,8 @@ def rebuild(self) -> None:
"normal_image": self.background_image,
"border_width": self.border_width,
"shadow_width": self.shadow_width,
"shape_corner_radius": self.shape_corner_radius}
"shape_corner_radius": self.shape_corner_radius,
'border_overlap': self.border_overlap}

if self.shape == "rectangle":
self.drawable_shape = RectDrawableShape(self.rect, theming_parameters,
Expand Down
4 changes: 3 additions & 1 deletion pygame_gui/elements/ui_horizontal_scroll_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ def rebuild(self):
'disabled_border': self.disabled_border_colour,
'border_width': self.border_width,
'shadow_width': self.shadow_width,
'shape_corner_radius': self.shape_corner_radius}
'shape_corner_radius': self.shape_corner_radius,
'border_overlap': self.border_overlap}

if self.shape == 'rectangle':
self.drawable_shape = RectDrawableShape(self.rect, theming_parameters,
Expand Down Expand Up @@ -472,6 +473,7 @@ def rebuild_from_changed_theme_data(self):

if self._check_shape_theming_changed(defaults={'border_width': 1,
'shadow_width': 2,
'border_overlap': 1,
'shape_corner_radius': [2, 2, 2, 2]}):
has_any_changed = True

Expand Down
4 changes: 3 additions & 1 deletion pygame_gui/elements/ui_horizontal_slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ def rebuild(self):
'disabled_border': self.disabled_border_colour,
'border_width': self.border_width,
'shadow_width': self.shadow_width,
'shape_corner_radius': self.shape_corner_radius}
'shape_corner_radius': self.shape_corner_radius,
'border_overlap': self.border_overlap}

if self.shape == 'rectangle':
self.drawable_shape = RectDrawableShape(self.rect, theming_parameters,
Expand Down Expand Up @@ -414,6 +415,7 @@ def rebuild_from_changed_theme_data(self):

if self._check_shape_theming_changed(defaults={'border_width': 1,
'shadow_width': 2,
'border_overlap': 1,
'shape_corner_radius': [2, 2, 2, 2]}):
has_any_changed = True

Expand Down
3 changes: 2 additions & 1 deletion pygame_gui/elements/ui_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ def rebuild(self):
'text_horiz_alignment': self.text_horiz_alignment,
'text_vert_alignment': self.text_vert_alignment,
'text_horiz_alignment_padding': self.text_horiz_alignment_padding,
'text_vert_alignment_padding': self.text_vert_alignment_padding}
'text_vert_alignment_padding': self.text_vert_alignment_padding,
'border_overlap': self.border_overlap}

drawable_shape_rect = self.rect.copy()
if self.dynamic_width:
Expand Down
4 changes: 3 additions & 1 deletion pygame_gui/elements/ui_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ def rebuild_from_changed_theme_data(self):

if self._check_shape_theming_changed(defaults={'border_width': 1,
'shadow_width': 2,
'border_overlap': 1,
'shape_corner_radius': [2, 2, 2, 2]}):
has_any_changed = True

Expand All @@ -258,7 +259,8 @@ def rebuild(self):
'normal_image': self.background_image,
'border_width': self.border_width,
'shadow_width': self.shadow_width,
'shape_corner_radius': self.shape_corner_radius}
'shape_corner_radius': self.shape_corner_radius,
'border_overlap': self.border_overlap}

if self.shape == 'rectangle':
self.drawable_shape = RectDrawableShape(self.rect, theming_parameters,
Expand Down
4 changes: 3 additions & 1 deletion pygame_gui/elements/ui_selection_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ def rebuild_from_changed_theme_data(self):

if self._check_shape_theming_changed(defaults={'border_width': 1,
'shadow_width': 2,
'border_overlap': 1,
'shape_corner_radius': [2, 2, 2, 2]}):
has_any_changed = True

Expand All @@ -641,7 +642,8 @@ def rebuild(self):
'normal_image': self.background_image,
'border_width': self.border_width,
'shadow_width': self.shadow_width,
'shape_corner_radius': self.shape_corner_radius}
'shape_corner_radius': self.shape_corner_radius,
'border_overlap': self.border_overlap}

if self.shape == 'rectangle':
self.drawable_shape = RectDrawableShape(self.rect, theming_parameters,
Expand Down
4 changes: 3 additions & 1 deletion pygame_gui/elements/ui_status_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ def redraw(self):
'shape_corner_radius': self.shape_corner_radius,
'filled_bar': self.bar_filled_colour,
'filled_bar_width_percentage': self.percent_full,
'follow_sprite_offset': self.follow_sprite_offset}
'follow_sprite_offset': self.follow_sprite_offset,
'border_overlap': self.border_overlap}

text = self.status_text()
if text:
Expand Down Expand Up @@ -232,6 +233,7 @@ def rebuild_from_changed_theme_data(self):

if self._check_shape_theming_changed(defaults={'border_width': 1,
'shadow_width': 2,
'border_overlap': 1,
'shape_corner_radius': [2, 2, 2, 2]}):
has_any_changed = True

Expand Down
4 changes: 3 additions & 1 deletion pygame_gui/elements/ui_text_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@ def rebuild(self):
'border_width': self.border_width,
'shadow_width': self.shadow_width,
'shape_corner_radius': self.shape_corner_radius,
'text_cursor_colour': self.text_cursor_colour}
'text_cursor_colour': self.text_cursor_colour,
'border_overlap': self.border_overlap}

if self.shape == 'rectangle':
self.drawable_shape = RectDrawableShape(self.rect, theming_parameters,
Expand Down Expand Up @@ -1055,6 +1056,7 @@ def rebuild_from_changed_theme_data(self):

if self._check_shape_theming_changed(defaults={'border_width': 1,
'shadow_width': 2,
'border_overlap': 1,
'shape_corner_radius': [2, 2, 2, 2]}):
has_any_changed = True

Expand Down
Loading

0 comments on commit 9db2a81

Please sign in to comment.