Skip to content

Commit 3d7a55c

Browse files
committed
add face color change
1 parent 60e5e9c commit 3d7a55c

File tree

1 file changed

+39
-28
lines changed

1 file changed

+39
-28
lines changed

uiflow2/libs/Face.py

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ def __init__(self):
5656
self.pos_x=0
5757
self.pos_y=0
5858
self.shaking=False
59+
self._bg_color=DEFAULT_BG_COLOR
60+
self._color=DEFAULT_COLOR
5961
#
6062
#
6163
def set_center(self, x, y):
@@ -150,37 +152,37 @@ def drawEye(self, param0: int=0, r: int=8, pos: int=0,
150152

151153
if param0 == 1: # ^ ^
152154
for i in range(3):
153-
self.buffer.drawArc(xl, yl, r-1+i, r+i, 180+angle1, 360+angle1, DEFAULT_COLOR)
154-
self.buffer.drawArc(xr, yr, r-1+i, r+i, 180+angle1, 360+angle1, DEFAULT_COLOR)
155+
self.buffer.drawArc(xl, yl, r-1+i, r+i, 180+angle1, 360+angle1, self._color)
156+
self.buffer.drawArc(xr, yr, r-1+i, r+i, 180+angle1, 360+angle1, self._color)
155157

156158
elif param0 == 2: # o -
157-
self.buffer.fillRect(xl-(r+l)//2, yl-r//2, r+l, r, DEFAULT_COLOR)
158-
self.buffer.fillCircle(xr, yr, r, DEFAULT_COLOR)
159+
self.buffer.fillRect(xl-(r+l)//2, yl-r//2, r+l, r, self._color)
160+
self.buffer.fillCircle(xr, yr, r, self._color)
159161

160162
elif param0 == 3: # - o
161-
self.buffer.fillRect(xr-(r+l)//2, yr-r//2, r+l, r, DEFAULT_COLOR)
162-
self.buffer.fillCircle(xl, yl, r, DEFAULT_COLOR)
163+
self.buffer.fillRect(xr-(r+l)//2, yr-r//2, r+l, r, self._color)
164+
self.buffer.fillCircle(xl, yl, r, self._color)
163165

164166
elif param0 == 4: # - -
165-
self.buffer.fillRect(xl-(r+l)//2, yl-r//2, r+l, r, DEFAULT_COLOR)
166-
self.buffer.fillRect(xr-(r+l)//2, yr-r//2, r+l, r, DEFAULT_COLOR)
167+
self.buffer.fillRect(xl-(r+l)//2, yl-r//2, r+l, r, self._color)
168+
self.buffer.fillRect(xr-(r+l)//2, yr-r//2, r+l, r, self._color)
167169

168170
elif param0 == 5: # + +
169-
self.buffer.fillRect(xl-(r+l)//2, yl-r//2, r+l, r, DEFAULT_COLOR)
170-
self.buffer.fillRect(xl-r//2, yl-(r+l)//2, r, r+l, DEFAULT_COLOR)
171-
self.buffer.fillRect(xr-(r+l)//2, yr-r//2, r+l, r, DEFAULT_COLOR)
172-
self.buffer.fillRect(xr-r//2, yr-(r+l)//2, r, r+l, DEFAULT_COLOR)
171+
self.buffer.fillRect(xl-(r+l)//2, yl-r//2, r+l, r, self._color)
172+
self.buffer.fillRect(xl-r//2, yl-(r+l)//2, r, r+l, self._color)
173+
self.buffer.fillRect(xr-(r+l)//2, yr-r//2, r+l, r, self._color)
174+
self.buffer.fillRect(xr-r//2, yr-(r+l)//2, r, r+l, self._color)
173175

174176
elif param0 == 6: # / \ or \ /
175-
self.fillRectRot(xl-(r+l)//2, yl-r//2, r+l, r, -angle2, DEFAULT_COLOR)
176-
self.fillRectRot(xr-(r+l)//2, yr-r//2, r+l, r, angle2, DEFAULT_COLOR)
177+
self.fillRectRot(xl-(r+l)//2, yl-r//2, r+l, r, -angle2, self._color)
178+
self.fillRectRot(xr-(r+l)//2, yr-r//2, r+l, r, angle2, self._color)
177179

178180
else: # o o
179-
self.buffer.fillCircle(xl, yl, r, DEFAULT_COLOR)
180-
self.buffer.fillCircle(xr, yr, r, DEFAULT_COLOR)
181+
self.buffer.fillCircle(xl, yl, r, self._color)
182+
self.buffer.fillCircle(xr, yr, r, self._color)
181183
if self.is_blinking():
182-
self.buffer.fillCircle(xl, yl-self.blink, r, DEFAULT_BG_COLOR)
183-
self.buffer.fillCircle(xr, yr-self.blink, r, DEFAULT_BG_COLOR)
184+
self.buffer.fillCircle(xl, yl-self.blink, r, self._bg_color)
185+
self.buffer.fillCircle(xr, yr-self.blink, r, self._bg_color)
184186
self.update_blinking(r*2 + 2)
185187
#
186188
#
@@ -219,23 +221,23 @@ def drawMouse(self, oRatio=0, oRatio2=0, angle=0, pos=0,
219221
y=self.mouse_pos[1] - r -pos
220222
x, y = self.rot_pos([x, y], angle)
221223
for i in range(4):
222-
self.buffer.drawArc(x, y, r+i, r+i+1, 70+angle, 110+angle, DEFAULT_COLOR)
224+
self.buffer.drawArc(x, y, r+i, r+i+1, 70+angle, 110+angle, self._color)
223225

224226
elif mouse_flag == 2 or mouse_flag == '^': # ^
225227
r=80
226228
x=self.mouse_pos[0] +xpos
227229
y=self.mouse_pos[1] + r -pos
228230
x, y = self.rot_pos([x, y], angle)
229231
for i in range(4):
230-
self.buffer.drawArc(x, y, r+i, r+i+1, 250+angle, 290+angle, DEFAULT_COLOR)
232+
self.buffer.drawArc(x, y, r+i, r+i+1, 250+angle, 290+angle, self._color)
231233

232234
elif mouse_flag == 3 or mouse_flag == 'o': # ^
233235
x=self.mouse_pos[0] + xpos
234236
y=self.mouse_pos[1] -pos
235237
rx=10
236238
ry=20
237239
for i in range(4):
238-
self.buffer.drawEllipse(x, y, rx+i, ry+i, DEFAULT_COLOR)
240+
self.buffer.drawEllipse(x, y, rx+i, ry+i, self._color)
239241

240242
else: # -
241243
minWidth=50
@@ -248,12 +250,12 @@ def drawMouse(self, oRatio=0, oRatio2=0, angle=0, pos=0,
248250
x=self.mouse_pos[0] - w // 2 + xpos
249251
y=self.mouse_pos[1] - h // 2 - pos
250252
if angle == 0:
251-
self.buffer.fillRect(x, y, w, h, DEFAULT_COLOR)
253+
self.buffer.fillRect(x, y, w, h, self._color)
252254
else:
253255
for i in range(h):
254256
x1, y1 = self.rot_pos([x, y+i], angle)
255257
x2, y2 = self.rot_pos([x+w, y+i], angle)
256-
self.buffer.drawLine(x1, y1, x2, y2, DEFAULT_COLOR)
258+
self.buffer.drawLine(x1, y1, x2, y2, self._color)
257259
return
258260
#
259261
#
@@ -286,7 +288,7 @@ def setFaceType(self, n: int=0):
286288
#
287289
def drawFace(self, idx='x', angle=0, flush=True):
288290
if flush:
289-
self.buffer.clear()
291+
self.clear()
290292
self.drawEye(self.face_type, angle1=angle)
291293
self.drawMouse(*self.mouse_type[idx], angle=angle)
292294
if flush:
@@ -295,7 +297,7 @@ def drawFace(self, idx='x', angle=0, flush=True):
295297
#
296298
#
297299
def clear(self):
298-
self.buffer.clear()
300+
self.buffer.clear(self._bg_color)
299301
return True
300302
#
301303
#
@@ -306,7 +308,7 @@ def set_face_id(self, val):
306308
#
307309
#
308310
def draw(self, id: str='x', angle: int=0):
309-
self.buffer.clear()
311+
self.clear()
310312
if id == 'talk':
311313
try:
312314
idx=list(self.mouse_type.keys())[round(random.random() * len(self.mouse_type))]
@@ -368,6 +370,15 @@ def flush(self):
368370
return
369371
#
370372
#
373+
def set_color(self, color=None, bg_color=None):
374+
if color : self._color=color
375+
if bg_color: self._bg_color=bg_color
376+
377+
def reset_color(self):
378+
self._color=DEFAULT_COLOR
379+
self._bg_color=DEFAULT_BG_COLOR
380+
#
381+
#
371382
def print_message(self, msg='', color=0xffffff):
372383
self.message=msg
373384
if msg:
@@ -377,7 +388,7 @@ def print_message(self, msg='', color=0xffffff):
377388
self.top_buffer.print(msg)
378389
self.top_buffer.push(0,0)
379390
else:
380-
self.top_buffer.clear()
391+
self.top_buffer.clear(self._bg_color)
381392
self.top_buffer.push(0,0)
382393
return
383394
#
@@ -390,7 +401,7 @@ def print_info(self, msg='',color=0xffff00):
390401
self.bottom_buffer.setTextColor(0, color)
391402
self.bottom_buffer.print(msg)
392403
else:
393-
self.bottom_buffer.clear()
404+
self.bottom_buffer.clear(self._bg_color)
394405
self.bottom_buffer.push(0,214)
395406
return
396407
#

0 commit comments

Comments
 (0)