Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the user to specify a scaling function (UIImage) #642

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading