|
| 1 | +frommpos.appsimportActivity |
| 2 | +importmpos.ui |
| 3 | + |
| 4 | +indev_error_x=160 |
| 5 | +indev_error_y=120 |
| 6 | + |
| 7 | +DARKPINK=lv.color_hex(0xEC048C) |
| 8 | + |
| 9 | +# doesnt work: |
| 10 | +defdraw_line(x,y): |
| 11 | +globalcanvas |
| 12 | +# Line drawing like this doesn't work: |
| 13 | +layer=lv.layer_t() |
| 14 | +canvas.init_layer(layer) |
| 15 | +dsc=lv.draw_line_dsc_t() |
| 16 | +dsc.color=DARKPINK |
| 17 | +dsc.width=4 |
| 18 | +dsc.round_end=1 |
| 19 | +dsc.round_start=1 |
| 20 | +dsc.p1=lv.point_precise_t() |
| 21 | +dsc.p1.x=x |
| 22 | +dsc.p1.y=y |
| 23 | +dsc.p2=lv.point_precise_t() |
| 24 | +dsc.p2.x=100 |
| 25 | +dsc.p2.y=200 |
| 26 | +#layer.draw_line(dsc) doesnt exist! |
| 27 | +lv.draw_line(layer,dsc)# doesnt do anything! |
| 28 | +canvas.finish_layer(layer) |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | +classDraw(Activity): |
| 34 | + |
| 35 | +hor_res=0 |
| 36 | +ver_res=0 |
| 37 | + |
| 38 | +# Widgets: |
| 39 | +canvas=None |
| 40 | + |
| 41 | +defonCreate(self): |
| 42 | +screen=lv.obj() |
| 43 | +self.canvas=lv.canvas(screen) |
| 44 | +disp=lv.display_get_default() |
| 45 | +self.hor_res=disp.get_horizontal_resolution() |
| 46 | +self.ver_res=disp.get_vertical_resolution() |
| 47 | +self.canvas.set_size(self.hor_res,self.ver_res) |
| 48 | +self.canvas.set_style_bg_color(lv.color_white(),0) |
| 49 | +buffer=bytearray(self.hor_res*self.ver_res*4) |
| 50 | +self.canvas.set_buffer(buffer,self.hor_res,self.ver_res,lv.COLOR_FORMAT.NATIVE) |
| 51 | +self.canvas.fill_bg(lv.color_white(),lv.OPA.COVER) |
| 52 | +self.canvas.add_flag(lv.obj.FLAG.CLICKABLE) |
| 53 | +self.canvas.add_event_cb(self.touch_cb,lv.EVENT.ALL,None) |
| 54 | +self.setContentView(screen) |
| 55 | + |
| 56 | +deftouch_cb(self,event): |
| 57 | +event_code=event.get_code() |
| 58 | +# Ignore: |
| 59 | +# ======= |
| 60 | +# 19: HIT_TEST |
| 61 | +# COVER_CHECK |
| 62 | +# DRAW_MAIN |
| 63 | +# DRAW_MAIN_BEGIN |
| 64 | +# DRAW_MAIN_END |
| 65 | +# DRAW_POST |
| 66 | +# DRAW_POST_BEGIN |
| 67 | +# DRAW_POST_END |
| 68 | +# GET_SELF_SIZE |
| 69 | +ifevent_codenotin [19,23,25,26,27,28,29,30,49]: |
| 70 | +name=mpos.ui.get_event_name(event_code) |
| 71 | +#print(f"lv_event_t: code={event_code}, name={name}") # target={event.get_target()}, user_data={event.get_user_data()}, param={event.get_param()} |
| 72 | +ifevent_code==lv.EVENT.PRESSING:# this is probably enough |
| 73 | +#if event_code in [lv.EVENT.PRESSED, lv.EVENT.PRESSING, lv.EVENT.LONG_PRESSED, lv.EVENT.LONG_PRESSED_REPEAT]: |
| 74 | +x,y=mpos.ui.get_pointer_xy() |
| 75 | +# drawing a point works: |
| 76 | +#canvas.set_px(x,y,lv.color_black(),lv.OPA.COVER) |
| 77 | +# |
| 78 | +# drawing a square like this works: |
| 79 | +#for dx in range(-5,5): |
| 80 | +# for dy in range(-5,5): |
| 81 | +# canvas.set_px(x+dx,y+dy,DARKPINK,lv.OPA.COVER) |
| 82 | +# |
| 83 | +# drawing a circle works: |
| 84 | +radius=7# Set desired radius |
| 85 | +ifx==indev_error_xandy==indev_error_y: |
| 86 | +radius=25# in case of indev error |
| 87 | +square=radius*radius |
| 88 | +fordxinrange(-radius,radius): |
| 89 | +fordyinrange(-radius,radius): |
| 90 | +ifdx*dx+dy*dy<=square: |
| 91 | +newx,newy=x+dx,y+dy |
| 92 | +if0<=newx<=self.hor_resand0<=newy<=self.ver_res:# don't draw outside of canvas because that may crash |
| 93 | +self.canvas.set_px(x+dx,y+dy,DARKPINK,lv.OPA.COVER) |
| 94 | + |