Skip to content

Commit

Permalink
Merge pull request #642 from joereynolds/feature/specify-scaling-func…
Browse files Browse the repository at this point in the history
…tion

Allow the user to specify a scaling function (UIImage)
  • Loading branch information
MyreMylar authored Nov 3, 2024
2 parents cc1c41d + e95ef56 commit 1b4bcdc
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pygame_gui/elements/ui_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def __init__(self,
anchors: Optional[Dict[str, Union[str, UIElement]]] = None,
visible: int = 1,
*,
starting_height: int = 1,):
starting_height: int = 1,
scale_func=pygame.transform.smoothscale):

super().__init__(relative_rect, manager, container,
starting_height=starting_height,
Expand All @@ -50,7 +51,7 @@ def __init__(self,

self.original_image = None

self.set_image(image_surface, image_is_alpha_premultiplied)
self.set_image(image_surface, image_is_alpha_premultiplied, scale_func)
self.rebuild_from_changed_theme_data()

def rebuild_from_changed_theme_data(self):
Expand Down Expand Up @@ -79,7 +80,8 @@ def set_dimensions(self, dimensions: Coordinate, clamp_to_container: bool = Fals

def set_image(self,
new_image: Union[pygame.surface.Surface, None],
image_is_alpha_premultiplied: bool = False) -> None:
image_is_alpha_premultiplied: bool = False,
scale_func = pygame.transform.smoothscale) -> None:
"""
Allows users to change the image displayed on a UIImage element during run time, without recreating
the element.
Expand All @@ -97,6 +99,6 @@ def set_image(self,
if (image_surface.get_width() != self.rect.width or
image_surface.get_height() != self.rect.height):
self.original_image = image_surface
self._set_image(pygame.transform.smoothscale(self.original_image, self.rect.size))
self._set_image(scale_func(self.original_image, self.rect.size))
else:
self._set_image(image_surface)

0 comments on commit 1b4bcdc

Please sign in to comment.