1 # SPDX-FileCopyrightText: 2020 Melissa LeBlanc-Williams for Adafruit Industries
3 # SPDX-License-Identifier: MIT
7 ================================================================================
9 vectorio Rectangle for Blinka
11 **Software and Dependencies:**
14 https://github.com/adafruit/Adafruit_Blinka/releases
16 * Author(s): Melissa LeBlanc-Williams
20 from typing import Union
21 from displayio._colorconverter import ColorConverter
22 from displayio._palette import Palette
23 from displayio._area import Area
24 from ._vectorshape import _VectorShape
26 __version__ = "0.0.0+auto.0"
27 __repo__ = "https://github.com/adafruit/Adafruit_Blinka_displayio.git"
30 class Rectangle(_VectorShape):
31 """Vectorio Rectangle"""
36 pixel_shader: Union[ColorConverter, Palette],
43 """Represents a rectangle by defining its bounds
45 :param Union[~displayio.ColorConverter,~displayio.Palette] pixel_shader:
46 The pixel shader that produces colors from values
47 :param int width: The number of pixels wide
48 :param int height: The number of pixels high
49 :param int x: Initial x position of the top left corner.
50 :param int y: Initial y position of the top left corner.
51 :param int color_index: Initial color_index to use when selecting color from the palette.
55 self._color_index = color_index
57 super().__init__(pixel_shader, x, y)
62 def width(self) -> int:
63 """The width of the rectangle in pixels"""
67 def width(self, value: int) -> None:
69 raise ValueError("width must be >= 1")
71 self._width = abs(value)
72 self._shape_set_dirty()
75 def height(self) -> int:
76 """The height of the rectangle in pixels"""
80 def height(self, value: int) -> None:
82 raise ValueError("height must be >= 1")
83 self._height = abs(value)
84 self._shape_set_dirty()
87 def color_index(self) -> int:
88 """The color_index of the rectangle as 0 based index of the palette."""
89 return self._color_index
92 def color_index(self, value: int) -> None:
93 self._color_index = abs(value)
94 self._shape_set_dirty()
96 def _get_pixel(self, x: int, y: int) -> int:
97 if 0 <= x < self._width and 0 <= y < self._height:
98 return self._color_index
101 def _get_area(self, out_area: Area) -> None:
104 out_area.x2 = self._width
105 out_area.y2 = self._height