|
|
|
@ -189,7 +189,8 @@ class GuiApplication: |
|
|
|
|
|
|
|
|
|
self._modal_overlay = ModalOverlay(overlay=overlay, callback=callback) |
|
|
|
|
|
|
|
|
|
def texture(self, asset_path: str, width: int, height: int, alpha_premultiply=False, keep_aspect_ratio=True): |
|
|
|
|
def texture(self, asset_path: str, width: int | None = None, height: int | None = None, |
|
|
|
|
alpha_premultiply=False, keep_aspect_ratio=True): |
|
|
|
|
cache_key = f"{asset_path}_{width}_{height}_{alpha_premultiply}{keep_aspect_ratio}" |
|
|
|
|
if cache_key in self._textures: |
|
|
|
|
return self._textures[cache_key] |
|
|
|
@ -199,29 +200,31 @@ class GuiApplication: |
|
|
|
|
self._textures[cache_key] = texture_obj |
|
|
|
|
return texture_obj |
|
|
|
|
|
|
|
|
|
def _load_texture_from_image(self, image_path: str, width: int, height: int, alpha_premultiply=False, keep_aspect_ratio=True): |
|
|
|
|
def _load_texture_from_image(self, image_path: str, width: int | None = None, height: int | None = None, |
|
|
|
|
alpha_premultiply=False, keep_aspect_ratio=True): |
|
|
|
|
"""Load and resize a texture, storing it for later automatic unloading.""" |
|
|
|
|
image = rl.load_image(image_path) |
|
|
|
|
|
|
|
|
|
if alpha_premultiply: |
|
|
|
|
rl.image_alpha_premultiply(image) |
|
|
|
|
|
|
|
|
|
# Resize with aspect ratio preservation if requested |
|
|
|
|
if keep_aspect_ratio: |
|
|
|
|
orig_width = image.width |
|
|
|
|
orig_height = image.height |
|
|
|
|
if width is not None and height is not None: |
|
|
|
|
# Resize with aspect ratio preservation if requested |
|
|
|
|
if keep_aspect_ratio: |
|
|
|
|
orig_width = image.width |
|
|
|
|
orig_height = image.height |
|
|
|
|
|
|
|
|
|
scale_width = width / orig_width |
|
|
|
|
scale_height = height / orig_height |
|
|
|
|
scale_width = width / orig_width |
|
|
|
|
scale_height = height / orig_height |
|
|
|
|
|
|
|
|
|
# Calculate new dimensions |
|
|
|
|
scale = min(scale_width, scale_height) |
|
|
|
|
new_width = int(orig_width * scale) |
|
|
|
|
new_height = int(orig_height * scale) |
|
|
|
|
# Calculate new dimensions |
|
|
|
|
scale = min(scale_width, scale_height) |
|
|
|
|
new_width = int(orig_width * scale) |
|
|
|
|
new_height = int(orig_height * scale) |
|
|
|
|
|
|
|
|
|
rl.image_resize(image, new_width, new_height) |
|
|
|
|
else: |
|
|
|
|
rl.image_resize(image, width, height) |
|
|
|
|
rl.image_resize(image, new_width, new_height) |
|
|
|
|
else: |
|
|
|
|
rl.image_resize(image, width, height) |
|
|
|
|
|
|
|
|
|
texture = rl.load_texture_from_image(image) |
|
|
|
|
# Set texture filtering to smooth the result |
|
|
|
|