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],
 
  42         """Represents a rectangle by defining its bounds
 
  44         :param Union[~displayio.ColorConverter,~displayio.Palette] pixel_shader:
 
  45             The pixel shader that produces colors from values
 
  46         :param int width: The number of pixels wide
 
  47         :param int height: The number of pixels high
 
  48         :param int x: Initial x position of the top left corner.
 
  49         :param int y: Initial y position of the top left corner.
 
  50         :param int color_index: Initial color_index to use when selecting color from the palette.
 
  56         super().__init__(pixel_shader, x, y)
 
  61     def width(self) -> int:
 
  62         """The width of the rectangle in pixels"""
 
  66     def width(self, value: int) -> None:
 
  68             raise ValueError("width must be >= 1")
 
  70         self._width = abs(value)
 
  71         self._shape_set_dirty()
 
  74     def height(self) -> int:
 
  75         """The height of the rectangle in pixels"""
 
  79     def height(self, value: int) -> None:
 
  81             raise ValueError("height must be >= 1")
 
  82         self._height = abs(value)
 
  83         self._shape_set_dirty()
 
  86     def color_index(self) -> int:
 
  87         """The color_index of the rectangle as 0 based index of the palette."""
 
  88         return self._color_index - 1
 
  91     def color_index(self, value: int) -> None:
 
  92         self._color_index = abs(value + 1)
 
  93         self._shape_set_dirty()
 
  95     def _get_pixel(self, x: int, y: int) -> int:
 
  96         if 0 <= x < self._width and 0 <= y < self._height:
 
  97             return self._color_index
 
 100     def _get_area(self, out_area: Area) -> None:
 
 103         out_area.x2 = self._width
 
 104         out_area.y2 = self._height