@@ -103,3 +103,55 @@ def data(self, dat):
103
103
self .spi_device .write (dat )
104
104
self ._cs .value = True
105
105
self .spi_device .unlock ()
106
+
107
+ def draw_pixel (self , x , y , color ):
108
+ """This should be overridden in the subclass"""
109
+ pass
110
+
111
+ #framebuf methods
112
+ def fill (self , color ):
113
+ """fill the screen with the passed color"""
114
+ self .fill_rect (0 , 0 , self .width , self .height , color )
115
+
116
+ # pylint: disable=too-many-arguments
117
+ def fill_rect (self , x , y , width , height , color ):
118
+ """fill a rectangle with the passed color"""
119
+ if width < 1 or height < 1 or (x + width ) <= 0 :
120
+ return
121
+ if (y + height ) <= 0 or y >= self .height or x >= self .width :
122
+ return
123
+ xend = min (self .width , x + width )
124
+ yend = min (self .height , y + height )
125
+ x = max (x , 0 )
126
+ y = max (y , 0 )
127
+ for _x in range (xend - x ):
128
+ for _y in range (yend - y ):
129
+ self .draw_pixel (x + _x , y + _y , color )
130
+ return
131
+
132
+ def pixel (self , x , y , color = None ):
133
+ """draw a pixel"""
134
+ if x < 0 or x >= self .width or y < 0 or y >= self .height :
135
+ return None
136
+ #TODO: figure this out when we know what framebuffer we
137
+ # will actually use
138
+ #if color is None:
139
+ # return self.get_pixel(self, x, y)
140
+
141
+ self .draw_pixel (x , y , color )
142
+ return None
143
+
144
+ def hline (self , x , y , width , color ):
145
+ """draw a horizontal line"""
146
+ self .fill_rect (x , y , width , 1 , color )
147
+
148
+ def vline (self , x , y , height , color ):
149
+ """draw a vertical line"""
150
+ self .fill_rect (x , y , 1 , height , color )
151
+
152
+ def rect (self , x , y , width , height , color ):
153
+ """draw a rectangle"""
154
+ self .fill_rect (x , y , width , 1 , color )
155
+ self .fill_rect (x , y + height , width , 1 , color )
156
+ self .fill_rect (x , y , 1 , height , color )
157
+ self .fill_rect (x + width , y , 1 , height , color )
0 commit comments