raylib: image dimensions are optional (#36332)

* meas

* now no resizing

* clean up
master-fp
Shane Smiskol 1 week ago committed by GitHub
parent 41fa0cdf82
commit 8e3757ac87
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      selfdrive/ui/layouts/onboarding.py
  2. 7
      system/ui/lib/application.py

@ -46,7 +46,7 @@ class TrainingGuide(Widget):
paths = sorted(paths, key=lambda x: int(re.search(r'\d+', x).group())) paths = sorted(paths, key=lambda x: int(re.search(r'\d+', x).group()))
for fn in paths: for fn in paths:
path = os.path.join(BASEDIR, "selfdrive/assets/training", fn) path = os.path.join(BASEDIR, "selfdrive/assets/training", fn)
self._images.append(gui_app.texture(path, gui_app.width, gui_app.height)) self._images.append(gui_app.texture(path))
def _handle_mouse_release(self, mouse_pos): def _handle_mouse_release(self, mouse_pos):
if rl.check_collision_point_rec(mouse_pos, STEP_RECTS[self._step]): if rl.check_collision_point_rec(mouse_pos, STEP_RECTS[self._step]):

@ -189,7 +189,8 @@ class GuiApplication:
self._modal_overlay = ModalOverlay(overlay=overlay, callback=callback) 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}" cache_key = f"{asset_path}_{width}_{height}_{alpha_premultiply}{keep_aspect_ratio}"
if cache_key in self._textures: if cache_key in self._textures:
return self._textures[cache_key] return self._textures[cache_key]
@ -199,13 +200,15 @@ class GuiApplication:
self._textures[cache_key] = texture_obj self._textures[cache_key] = texture_obj
return 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.""" """Load and resize a texture, storing it for later automatic unloading."""
image = rl.load_image(image_path) image = rl.load_image(image_path)
if alpha_premultiply: if alpha_premultiply:
rl.image_alpha_premultiply(image) rl.image_alpha_premultiply(image)
if width is not None and height is not None:
# Resize with aspect ratio preservation if requested # Resize with aspect ratio preservation if requested
if keep_aspect_ratio: if keep_aspect_ratio:
orig_width = image.width orig_width = image.width

Loading…
Cancel
Save