diff --git a/arcade/examples/gui/2_widgets.py b/arcade/examples/gui/2_widgets.py index bbb91790d..973963f23 100644 --- a/arcade/examples/gui/2_widgets.py +++ b/arcade/examples/gui/2_widgets.py @@ -13,27 +13,27 @@ import arcade from arcade.gui import ( + NinePatchTexture, UIAnchorLayout, + UIBoxLayout, UIButtonRow, + UIDropdown, + UIDummy, UIFlatButton, + UIImage, UIInputText, UILabel, - UISpace, + UIManager, + UIMessageBox, UIOnActionEvent, - UITextArea, UIOnChangeEvent, - UITextureButton, - UITextureToggle, UISlider, - UITextureSlider, - UIBoxLayout, - UIImage, - UIDummy, + UISpace, UISpriteWidget, - NinePatchTexture, - UIDropdown, - UIMessageBox, - UIManager, + UITextArea, + UITextureButton, + UITextureSlider, + UITextureToggle, UIView, ) @@ -612,6 +612,7 @@ def _show_other_widgets(self): text_area.with_padding(left=10, right=10) text_area.with_border(color=arcade.uicolor.GRAY_CONCRETE, width=2) + def main(): window = arcade.Window(title="GUI Example: Widget Gallery") window.show_view(GalleryView()) diff --git a/arcade/gui/surface.py b/arcade/gui/surface.py index ac499d0fc..5e7af4d86 100644 --- a/arcade/gui/surface.py +++ b/arcade/gui/surface.py @@ -38,6 +38,7 @@ def __init__( self._size = size self._pos = position self._pixel_ratio = pixel_ratio + self._pixelated = False self.texture = self.ctx.texture(self.size_scaled, components=4) self.fbo: Framebuffer = self.ctx.framebuffer(color_attachments=[self.texture]) @@ -142,7 +143,9 @@ def draw_texture( tex.draw_rect(rect=LBWH(0, 0, width, height)) else: - arcade.draw_texture_rect(tex, LBWH(x, y, width, height), angle=angle, alpha=alpha) + arcade.draw_texture_rect( + tex, LBWH(x, y, width, height), angle=angle, alpha=alpha, pixelated=self._pixelated + ) def draw_sprite(self, x: float, y: float, width: float, height: float, sprite: arcade.Sprite): """Draw a sprite to the surface @@ -157,7 +160,7 @@ def draw_sprite(self, x: float, y: float, width: float, height: float, sprite: a sprite.position = x + width // 2, y + height // 2 sprite.width = width sprite.height = height - arcade.draw_sprite(sprite) + arcade.draw_sprite(sprite, pixelated=self._pixelated) @contextmanager def activate(self) -> Generator[Self, None, None]: @@ -226,11 +229,18 @@ def draw( Args: area: Limit the area in the surface we're drawing (l, b, w, h) + pixelated: If True, the texture will be rendered pixelated """ # Set blend function blend_func = self.ctx.blend_func self.ctx.blend_func = self.blend_func_render + # Handle the pixelated shortcut if filter is not set + if self._pixelated: + self.texture.filter = self.ctx.NEAREST, self.ctx.NEAREST + else: + self.texture.filter = self.ctx.LINEAR, self.ctx.LINEAR + self.texture.use(0) self._program["pos"] = self._pos self._program["size"] = self._size diff --git a/arcade/gui/ui_manager.py b/arcade/gui/ui_manager.py index 4f36c6cce..d793a177d 100644 --- a/arcade/gui/ui_manager.py +++ b/arcade/gui/ui_manager.py @@ -87,6 +87,10 @@ def on_draw(): """ _enabled = False + _pixelated = False + """Experimental feature to pixelate the UI, all textures will be rendered pixelated, + which will mostly influence scaled background images. + This property has to be set right after the UIManager is created.""" DEFAULT_LAYER = 0 OVERLAY_LAYER = 10 @@ -198,6 +202,7 @@ def _get_surface(self, layer: int) -> Surface: size=self.window.get_size(), pixel_ratio=self.window.get_pixel_ratio(), ) + self._surfaces[layer]._pixelated = self._pixelated return self._surfaces[layer] @@ -316,7 +321,7 @@ def on_update(self, time_delta): """Dispatches an update event to all widgets in the UIManager.""" return self.dispatch_ui_event(UIOnUpdateEvent(self, time_delta)) - def draw(self) -> None: + def draw(self, pixelated=False) -> None: """Will draw all widgets to the window. UIManager caches all rendered widgets into a framebuffer (something like a diff --git a/arcade/gui/widgets/text.py b/arcade/gui/widgets/text.py index be72e8788..e79b19814 100644 --- a/arcade/gui/widgets/text.py +++ b/arcade/gui/widgets/text.py @@ -194,6 +194,33 @@ def text(self, value): else: self.trigger_full_render() + @property + def font_name(self) -> FontNameOrNames: + """Font name of the label. Use :py:meth:`~arcade.gui.UILabel.update_font` to change.""" + return self._label.font_name + + @property + def font_size(self) -> float: + """Font size of the label. Use :py:meth:`~arcade.gui.UILabel.update_font` to change.""" + return self._label.font_size + + @property + def font_color(self) -> Color: + """Font color of the label. Use :py:meth:`~arcade.gui.UILabel.update_font` to change.""" + return self._label.color + + @property + def bold(self) -> bool | str: + """Return if the label is in bold style. + Use :py:meth:`~arcade.gui.UILabel.update_font` to change.""" + return self._label.bold + + @property + def italic(self) -> bool | str: + """Return if the label is in italic style. + Use :py:meth:`~arcade.gui.UILabel.update_font` to change.""" + return self._label.italic + def _update_label(self): """Update the position and size of the label.