Skip to content

Commit e74a40e

Browse files
committed
Removing Vectorshape Usage
1 parent c7f30ee commit e74a40e

File tree

2 files changed

+33
-105
lines changed

2 files changed

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

adafruit_displayio_layout/widgets/cartesian.py

+33-41
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
from adafruit_display_text import bitmap_label
3030
import vectorio
3131
from adafruit_displayio_layout.widgets.widget import Widget
32-
from adafruit_displayio_layout.widgets import rectangle_helper
32+
33+
# from adafruit_displayio_layout.widgets import rectangle_helper
3334

3435
try:
3536
import bitmaptools
@@ -138,7 +139,7 @@ class Cartesian(Widget):
138139
139140
- **range**: ``xrange`` and ``yrange`` This is the range in absolute units.
140141
For example, when using (20-90), the X axis will start at 20 finishing at 90.
141-
However the height of the graph is given by the height parameter. The scale
142+
However, the height of the graph is given by the height parameter. The scale
142143
is handled internal to provide a 1:1 experience when you update the graph.
143144
144145
@@ -269,14 +270,14 @@ def __init__(
269270
self._screen_palette[5] = self._background_color
270271

271272
self._corner_bitmap = displayio.Bitmap(10, 10, 5)
272-
rectangle_helper(
273+
274+
bitmaptools.fill_region(
275+
self._corner_bitmap,
273276
0,
274277
0,
275278
self._axes_line_thickness,
276279
self._axes_line_thickness,
277-
self._corner_bitmap,
278280
2,
279-
self._screen_palette,
280281
)
281282

282283
self._corner_tilegrid = displayio.TileGrid(
@@ -336,28 +337,23 @@ def _get_font_height(font, scale: int) -> Tuple[int, int]:
336337
return font_width, font_height
337338

338339
def _draw_axes(self) -> None:
339-
# Draw x axes line
340-
rectangle_helper(
340+
341+
bitmaptools.fill_region(
342+
self._axesx_bitmap,
341343
0,
342344
0,
343-
self._axes_line_thickness,
344345
self.width,
345-
self._axesx_bitmap,
346+
self._axes_line_thickness,
346347
2,
347-
self._screen_palette,
348-
True,
349348
)
350349

351-
# Draw y axes line
352-
rectangle_helper(
350+
bitmaptools.fill_region(
351+
self._axesy_bitmap,
353352
self._axesy_width - self._axes_line_thickness,
354353
0,
354+
self._axesy_width,
355355
self.height,
356-
self._axes_line_thickness,
357-
self._axesy_bitmap,
358356
2,
359-
self._screen_palette,
360-
True,
361357
)
362358

363359
def _draw_ticks(self) -> None:
@@ -382,30 +378,28 @@ def _draw_ticks(self) -> None:
382378
+ 1,
383379
)
384380
self.append(tick_text)
385-
rectangle_helper(
381+
382+
bitmaptools.fill_region(
383+
self._axesx_bitmap,
386384
text_dist,
387385
self._axes_line_thickness,
388-
self._tick_line_height,
389-
self._tick_line_thickness,
390-
self._axesx_bitmap,
386+
text_dist + self._tick_line_thickness,
387+
self._axes_line_thickness + self._tick_line_height,
391388
1,
392-
self._screen_palette,
393-
True,
394389
)
395390

396391
if self._subticks:
397392
if i in subticks:
398393
# calc subtick_line_height; force min lineheigt to 1.
399394
subtick_line_height = max(1, self._tick_line_height // 2)
400-
rectangle_helper(
395+
396+
bitmaptools.fill_region(
397+
self._axesx_bitmap,
401398
text_dist,
402399
self._axes_line_thickness,
403-
subtick_line_height,
400+
text_dist + 1,
401+
self._axes_line_thickness + subtick_line_height,
404402
1,
405-
self._axesx_bitmap,
406-
1,
407-
self._screen_palette,
408-
True,
409403
)
410404

411405
# Y axes ticks
@@ -425,34 +419,32 @@ def _draw_ticks(self) -> None:
425419
y=0 + self.height - text_dist,
426420
)
427421
self.append(tick_text)
428-
rectangle_helper(
422+
423+
bitmaptools.fill_region(
424+
self._axesy_bitmap,
429425
self._axesy_width
430426
- self._axes_line_thickness
431427
- self._tick_line_height
432428
- 1,
433429
text_dist,
434-
self._tick_line_thickness,
435-
self._tick_line_height,
436-
self._axesy_bitmap,
430+
self._axesy_width - self._axes_line_thickness - 1,
431+
text_dist + self._tick_line_thickness,
437432
1,
438-
self._screen_palette,
439-
True,
440433
)
441434

442435
if self._subticks:
443436
if i in subticks:
444-
rectangle_helper(
437+
438+
bitmaptools.fill_region(
439+
self._axesy_bitmap,
445440
self._axesy_width
446441
- self._axes_line_thickness
447442
- self._tick_line_height // 2
448443
- 1,
449444
text_dist,
445+
self._axesy_width - self._axes_line_thickness - 1,
446+
text_dist + 1,
450447
1,
451-
self._tick_line_height // 2,
452-
self._axesy_bitmap,
453-
1,
454-
self._screen_palette,
455-
True,
456448
)
457449

458450
def _draw_pointers(self, x: int, y: int) -> None:

0 commit comments

Comments
 (0)