|
| 1 | +# SPDX-FileCopyrightText: 2021 Kevin Matocha, Tim C, Jose David M |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: MIT |
| 4 | + |
| 5 | +""" |
| 6 | +`adafruit_displayio_layout.widgets` |
| 7 | +======================= |
| 8 | +""" |
| 9 | + |
| 10 | +import vectorio |
| 11 | + |
| 12 | +try: |
| 13 | + import bitmaptools |
| 14 | +except NameError: |
| 15 | + pass |
| 16 | + |
| 17 | + |
| 18 | +# pylint: disable=invalid-name, too-many-arguments |
| 19 | +def rectangle_helper( |
| 20 | + x0: int, |
| 21 | + y0: int, |
| 22 | + height: int, |
| 23 | + width: int, |
| 24 | + bitmap, |
| 25 | + color_index: int, |
| 26 | + palette, |
| 27 | + bitmaptool: bool = True, |
| 28 | +) -> None: |
| 29 | + """rectangle_helper function |
| 30 | + Draws a rectangle to the bitmap given using ``bitmapstools.bitmap`` or |
| 31 | + ``vectorio.rectangle`` functions |
| 32 | +
|
| 33 | + :param int x0: rectangle lower corner x position |
| 34 | + :param int y0: rectangle lower corner y position |
| 35 | +
|
| 36 | + :param int width: rectangle upper corner x position |
| 37 | + :param int height: rectangle upper corner y position |
| 38 | +
|
| 39 | + :param int color_index: palette color index to be used |
| 40 | + :param palette: palette object to be used to draw the rectangle |
| 41 | +
|
| 42 | + :param bitmap: bitmap for the rectangle to be drawn |
| 43 | + :param bool bitmaptool: uses :py:func:`~bitmaptools.draw_line` to draw the rectanlge. |
| 44 | + when `False` uses :py:func:`~vectorio.Rectangle` |
| 45 | +
|
| 46 | + :return: None |
| 47 | + :rtype: None |
| 48 | +
|
| 49 | + ┌───────────────────────┐ |
| 50 | + │ │ |
| 51 | + │ │ |
| 52 | + (x0,y0) └───────────────────────┘ |
| 53 | +
|
| 54 | + """ |
| 55 | + if bitmaptool: |
| 56 | + x1 = x0 + width |
| 57 | + y1 = y0 + height |
| 58 | + for row_pos in range(y0, y1, 1): |
| 59 | + bitmaptools.draw_line(bitmap, x0, row_pos, x1, row_pos, color_index) |
| 60 | + else: |
| 61 | + rect = vectorio.Rectangle(width, height) |
| 62 | + vectorio.VectorShape( |
| 63 | + shape=rect, |
| 64 | + pixel_shader=palette, |
| 65 | + x=x0, |
| 66 | + y=y0, |
| 67 | + ) |
0 commit comments