Skip to content

Commit

Permalink
updated (#2469) (#2470)
Browse files Browse the repository at this point in the history
* updated (#2469)
* update doc string to reference view instead of window
* Make the default clear color BLACK not TRANSPARENT_BLACK
  • Loading branch information
DragonMoffon authored Dec 22, 2024
1 parent 1b2b45c commit d4e124d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
39 changes: 35 additions & 4 deletions arcade/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import arcade
from arcade.clock import GLOBAL_CLOCK, GLOBAL_FIXED_CLOCK, _setup_clock, _setup_fixed_clock
from arcade.color import TRANSPARENT_BLACK
from arcade.color import BLACK
from arcade.context import ArcadeContext
from arcade.types import LBWH, Color, Rect, RGBANormalized, RGBOrA255
from arcade.utils import is_raspberry_pi
Expand Down Expand Up @@ -268,7 +268,7 @@ def __init__(
self.push_handlers(on_resize=self._on_resize)

self._ctx: ArcadeContext = ArcadeContext(self, gc_mode=gc_mode, gl_api=gl_api)
self._background_color: Color = TRANSPARENT_BLACK
self._background_color: Color = BLACK

self._current_view: View | None = None

Expand Down Expand Up @@ -1240,7 +1240,9 @@ def __init__(
self, window: Window | None = None, background_color: RGBOrA255 | None = None
) -> None:
self.window = arcade.get_window() if window is None else window
self.background_color: RGBOrA255 | None = background_color
self._background_color: Color | None = background_color and Color.from_iterable(
background_color
)

def clear(
self,
Expand All @@ -1250,7 +1252,7 @@ def clear(
) -> None:
"""
Clears the window with the configured background color
set through :py:attr:`arcade.Window.background_color`.
set through :py:attr:`arcade.View.background_color`.
Args:
color(optional):
Expand Down Expand Up @@ -1570,3 +1572,32 @@ def center_y(self) -> float:
An alias for `arcade.Window.center_y`
"""
return self.window.center_y

@property
def background_color(self) -> Color | None:
"""
Get or set the background color for this view.
This affects what color the window will contain when
:py:meth:`~arcade.View.clear` is called.
Examples::
# Use Arcade's built in Color values
view.background_color = arcade.color.AMAZON
# Set the background color with a custom Color instance
MY_RED = arcade.types.Color(255, 0, 0)
view.background_color = MY_RED
# Set the background color directly from an RGBA tuple
view.background_color = 255, 0, 0, 255
# Set the background color directly from an RGB tuple
# RGB tuples will assume 255 as the opacity / alpha value
view.background_color = 255, 0, 0
"""
return self._background_color

@background_color.setter
def background_color(self, value: RGBOrA255) -> None:
self._background_color = Color.from_iterable(value)
10 changes: 9 additions & 1 deletion tests/unit/window/test_view.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from unittest.mock import Mock

from arcade import Window, View
from arcade import Window, View, color, get_image


def test_on_show_view_called(window):
Expand All @@ -24,3 +24,11 @@ def test_on_hide_view_called(window):
window.show_view(view2)

hide_mock.assert_called_once()

def test_view_background_color(window):
view = View(window, color.ARCADE_GREEN)
assert view.background_color == color.ARCADE_GREEN
window.clear()
# assert get_image(0, 0, 1, 1).getpixel((0, 0)) == color.BLACK
view.clear()
# assert get_image(0, 0, 1, 1).getpixel((0, 0)) == color.ARCADE_GREEN

0 comments on commit d4e124d

Please sign in to comment.