mirror of
https://github.com/jtgans/g13gui.git
synced 2025-06-20 08:23:50 -04:00
bitwidgets: Make rectangle render unfilled outlines
Something I've wanted for a while has been the ability to draw a rectangle anywhere on the screen without it being filled in. Hopefully this does the trick.
This commit is contained in:
parent
e51c7ca0fc
commit
fa7a84ca3f
@ -2,11 +2,20 @@ from g13gui.bitwidgets.widget import Widget
|
|||||||
|
|
||||||
|
|
||||||
class Rectangle(Widget):
|
class Rectangle(Widget):
|
||||||
def __init__(self, x, y, w, h, fill=True):
|
def __init__(self, x, y, w, h, fill=True, outline=0):
|
||||||
Widget.__init__(self)
|
Widget.__init__(self)
|
||||||
self.position = (x, y)
|
self.position = (x, y)
|
||||||
self.bounds = (w, h)
|
self.bounds = (w, h)
|
||||||
self.fill = fill
|
self.fill = fill
|
||||||
|
self._outline = outline
|
||||||
|
|
||||||
|
@property
|
||||||
|
def outline(self):
|
||||||
|
return self._outline
|
||||||
|
|
||||||
|
@outline.setter
|
||||||
|
def outline(self, value):
|
||||||
|
self.setAttribute('outline', value)
|
||||||
|
|
||||||
def draw(self, ctx):
|
def draw(self, ctx):
|
||||||
if self._visible:
|
if self._visible:
|
||||||
@ -14,4 +23,5 @@ class Rectangle(Widget):
|
|||||||
self._position[0] + self._bounds[0],
|
self._position[0] + self._bounds[0],
|
||||||
self._position[1] + self._bounds[1])
|
self._position[1] + self._bounds[1])
|
||||||
ctx.rectangle(points,
|
ctx.rectangle(points,
|
||||||
fill=self._fill)
|
fill=self._fill,
|
||||||
|
outline=self._outline)
|
||||||
|
@ -25,7 +25,16 @@ class RectangleTests(unittest.TestCase):
|
|||||||
def testRect(self):
|
def testRect(self):
|
||||||
self.dd.name = 'testRect'
|
self.dd.name = 'testRect'
|
||||||
ctx = self.display.getContext()
|
ctx = self.display.getContext()
|
||||||
rect = Rectangle(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT - 1, fill=True)
|
rect = Rectangle(0, 0, DISPLAY_WIDTH - 1, DISPLAY_HEIGHT - 1)
|
||||||
|
rect.show()
|
||||||
|
rect.draw(ctx)
|
||||||
|
|
||||||
|
self.display.commit()
|
||||||
|
|
||||||
|
def testRectUnfilled(self):
|
||||||
|
self.dd.name = 'testRectUnfilled'
|
||||||
|
ctx = self.display.getContext()
|
||||||
|
rect = Rectangle(0, 0, DISPLAY_WIDTH - 1, DISPLAY_HEIGHT - 1, fill=False, outline=1)
|
||||||
rect.show()
|
rect.show()
|
||||||
rect.draw(ctx)
|
rect.draw(ctx)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user