Skip to content

Commit 73f2f91

Browse files
authored
Merge pull request #16 from makermelissa/master
Fixed some incorrect calculations for width/height
2 parents f911008 + a4f7a6d commit 73f2f91

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

adafruit_ra8875/ra8875.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ def rect(self, x, y, width, height, color):
573573
:param int height: The height of the rectangle
574574
:param int color: The color of the rectangle
575575
"""
576-
self._rect_helper(x, y, width, height, color, False)
576+
self._rect_helper(x, y, x + width - 1, y + height - 1, color, False)
577577

578578
def fill_rect(self, x, y, width, height, color):
579579
"""
@@ -585,15 +585,15 @@ def fill_rect(self, x, y, width, height, color):
585585
:param int height: The height of the rectangle
586586
:param int color: The color of the rectangle
587587
"""
588-
self._rect_helper(x, y, width, height, color, True)
588+
self._rect_helper(x, y, x + width - 1, y + height - 1, color, True)
589589

590590
def fill(self, color):
591591
"""
592592
Fill the Entire Screen (HW Accelerated)
593593
594594
:param int color: The color to Fill the screen
595595
"""
596-
self._rect_helper(0, 0, self.width, self.height, color, True)
596+
self._rect_helper(0, 0, self.width - 1, self.height - 1, color, True)
597597

598598
def circle(self, x_center, y_center, radius, color):
599599
"""
@@ -706,7 +706,7 @@ def hline(self, x, y, width, color):
706706
:param int width: The width of the line
707707
:param int color: The color of the line
708708
"""
709-
self.line(x, y, x + width, y, color)
709+
self.line(x, y, x + width - 1, y, color)
710710

711711
def vline(self, x, y, height, color):
712712
"""
@@ -717,7 +717,7 @@ def vline(self, x, y, height, color):
717717
:param int height: The height of the line
718718
:param int color: The color of the line
719719
"""
720-
self.line(x, y, x, y + height, color)
720+
self.line(x, y, x, y + height - 1, color)
721721

722722
def line(self, x1, y1, x2, y2, color):
723723
"""
@@ -758,13 +758,14 @@ def round_rect(self, x, y, width, height, radius, color):
758758
"""
759759
self._gfx_mode()
760760
self._curve_helper(x + radius, y + radius, radius, radius, 1, color, False)
761-
self._curve_helper(x + width - radius, y + radius, radius, radius, 2, color, False)
761+
self._curve_helper(x + width - radius - 1, y + radius, radius, radius, 2, color, False)
762762
self._curve_helper(x + radius, y + height - radius, radius, radius, 0, color, False)
763-
self._curve_helper(x + width - radius, y + height - radius, radius, radius, 3, color, False)
764-
self.hline(x + radius, y, width - (radius * 2), color)
765-
self.hline(x + radius, y + height, width - (radius * 2), color)
763+
self._curve_helper(x + width - radius - 1, y + height - radius, radius, radius, 3, color,
764+
False)
765+
self.hline(x + radius, y, width - (radius * 2) - 1, color)
766+
self.hline(x + radius, y + height, width - (radius * 2) - 1, color)
766767
self.vline(x, y + radius, height - (radius * 2), color)
767-
self.vline(x + width, y + radius, height - (radius * 2), color)
768+
self.vline(x + width - 1, y + radius, height - (radius * 2), color)
768769

769770
def fill_round_rect(self, x, y, width, height, radius, color):
770771
"""
@@ -779,11 +780,12 @@ def fill_round_rect(self, x, y, width, height, radius, color):
779780
"""
780781
self._gfx_mode()
781782
self._curve_helper(x + radius, y + radius, radius, radius, 1, color, True)
782-
self._curve_helper(x + width - radius, y + radius, radius, radius, 2, color, True)
783+
self._curve_helper(x + width - radius - 1, y + radius, radius, radius, 2, color, True)
783784
self._curve_helper(x + radius, y + height - radius, radius, radius, 0, color, True)
784-
self._curve_helper(x + width - radius, y + height - radius, radius, radius, 3, color, True)
785-
self._rect_helper(x + radius, y, x + width - radius, y + height, color, True)
786-
self._rect_helper(x, y + radius, x + width, y + height - radius, color, True)
785+
self._curve_helper(x + width - radius - 1, y + height - radius, radius, radius, 3, color,
786+
True)
787+
self._rect_helper(x + radius, y, x + width - radius - 1, y + height - 1, color, True)
788+
self._rect_helper(x, y + radius, x + width - 1, y + height - radius - 1, color, True)
787789

788790
def _circle_helper(self, x, y, radius, color, filled):
789791
"""General Circle Drawing Helper"""
@@ -800,17 +802,17 @@ def _circle_helper(self, x, y, radius, color, filled):
800802
self._write_reg(reg.DCR, reg.DCR_CIRC_START | (reg.DCR_FILL if filled else reg.DCR_NOFILL))
801803
self._wait_poll(reg.DCR, reg.DCR_CIRC_STATUS)
802804

803-
def _rect_helper(self, x, y, width, height, color, filled):
805+
def _rect_helper(self, x1, y1, x2, y2, color, filled):
804806
"""General Rectangle Drawing Helper"""
805807
self._gfx_mode()
806808

807809
# Set X and Y
808-
self._write_reg16(0x91, x)
809-
self._write_reg16(0x93, y + self.vert_offset)
810+
self._write_reg16(0x91, x1)
811+
self._write_reg16(0x93, y1 + self.vert_offset)
810812

811813
# Set Width and Height
812-
self._write_reg16(0x95, width)
813-
self._write_reg16(0x97, height + self.vert_offset)
814+
self._write_reg16(0x95, x2)
815+
self._write_reg16(0x97, y2 + self.vert_offset)
814816

815817
self.set_color(color)
816818

examples/ra8875_simpletest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,17 @@
4545
display.circle(100, 100, 50, BLACK)
4646
display.fill_circle(100, 100, 49, BLUE)
4747

48-
display.fill_rect(11, 11, 398, 198, GREEN)
48+
display.fill_rect(10, 10, 400, 200, GREEN)
4949
display.rect(10, 10, 400, 200, BLUE)
5050
display.fill_round_rect(200, 10, 200, 100, 10, RED)
51-
display.round_rect(199, 9, 202, 102, 12, BLUE)
51+
display.round_rect(200, 10, 200, 100, 10, BLUE)
5252
display.pixel(10, 10, BLACK)
5353
display.pixel(11, 11, BLACK)
5454
display.line(10, 10, 200, 100, RED)
55+
display.fill_triangle(200, 15, 250, 100, 150, 125, YELLOW)
5556
display.triangle(200, 15, 250, 100, 150, 125, BLACK)
56-
display.fill_triangle(200, 16, 249, 99, 151, 124, YELLOW)
57+
display.fill_ellipse(300, 100, 100, 40, BLUE)
5758
display.ellipse(300, 100, 100, 40, RED)
58-
display.fill_ellipse(300, 100, 98, 38, BLUE)
5959
display.curve(50, 100, 80, 40, 2, BLACK)
6060
display.fill_curve(50, 100, 78, 38, 2, WHITE)
6161

0 commit comments

Comments
 (0)