Skip to content

Commit f65241a

Browse files
draw: pink circles
1 parent b0cd941 commit f65241a

File tree

1 file changed

+138
-47
lines changed
  • internal_filesystem/apps/com.example.draw/assets

1 file changed

+138
-47
lines changed

internal_filesystem/apps/com.example.draw/assets/draw.py

Lines changed: 138 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,150 @@
22

33
import lvgl as lv
44

5+
indev_error_x = 160
6+
indev_error_y = 120
7+
58
DARKPINK = lv.color_hex(0xEC048C)
69

10+
EVENT_MAP = {
11+
lv.EVENT.ALL: "ALL",
12+
lv.EVENT.CANCEL: "CANCEL",
13+
lv.EVENT.CHILD_CHANGED: "CHILD_CHANGED",
14+
lv.EVENT.CHILD_CREATED: "CHILD_CREATED",
15+
lv.EVENT.CHILD_DELETED: "CHILD_DELETED",
16+
lv.EVENT.CLICKED: "CLICKED",
17+
lv.EVENT.COLOR_FORMAT_CHANGED: "COLOR_FORMAT_CHANGED",
18+
lv.EVENT.COVER_CHECK: "COVER_CHECK",
19+
lv.EVENT.CREATE: "CREATE",
20+
lv.EVENT.DEFOCUSED: "DEFOCUSED",
21+
lv.EVENT.DELETE: "DELETE",
22+
lv.EVENT.DRAW_MAIN: "DRAW_MAIN",
23+
lv.EVENT.DRAW_MAIN_BEGIN: "DRAW_MAIN_BEGIN",
24+
lv.EVENT.DRAW_MAIN_END: "DRAW_MAIN_END",
25+
lv.EVENT.DRAW_POST: "DRAW_POST",
26+
lv.EVENT.DRAW_POST_BEGIN: "DRAW_POST_BEGIN",
27+
lv.EVENT.DRAW_POST_END: "DRAW_POST_END",
28+
lv.EVENT.DRAW_TASK_ADDED: "DRAW_TASK_ADDED",
29+
lv.EVENT.FLUSH_FINISH: "FLUSH_FINISH",
30+
lv.EVENT.FLUSH_START: "FLUSH_START",
31+
lv.EVENT.FLUSH_WAIT_FINISH: "FLUSH_WAIT_FINISH",
32+
lv.EVENT.FLUSH_WAIT_START: "FLUSH_WAIT_START",
33+
lv.EVENT.FOCUSED: "FOCUSED",
34+
lv.EVENT.GESTURE: "GESTURE",
35+
lv.EVENT.GET_SELF_SIZE: "GET_SELF_SIZE",
36+
lv.EVENT.HIT_TEST: "HIT_TEST",
37+
lv.EVENT.HOVER_LEAVE: "HOVER_LEAVE",
38+
lv.EVENT.HOVER_OVER: "HOVER_OVER",
39+
lv.EVENT.INDEV_RESET: "INDEV_RESET",
40+
lv.EVENT.INSERT: "INSERT",
41+
lv.EVENT.INVALIDATE_AREA: "INVALIDATE_AREA",
42+
lv.EVENT.KEY: "KEY",
43+
lv.EVENT.LAST: "LAST",
44+
lv.EVENT.LAYOUT_CHANGED: "LAYOUT_CHANGED",
45+
lv.EVENT.LEAVE: "LEAVE",
46+
lv.EVENT.LONG_PRESSED: "LONG_PRESSED",
47+
lv.EVENT.LONG_PRESSED_REPEAT: "LONG_PRESSED_REPEAT",
48+
lv.EVENT.PREPROCESS: "PREPROCESS",
49+
lv.EVENT.PRESSED: "PRESSED",
50+
lv.EVENT.PRESSING: "PRESSING",
51+
lv.EVENT.PRESS_LOST: "PRESS_LOST",
52+
lv.EVENT.READY: "READY",
53+
lv.EVENT.REFRESH: "REFRESH",
54+
lv.EVENT.REFR_EXT_DRAW_SIZE: "REFR_EXT_DRAW_SIZE",
55+
lv.EVENT.REFR_READY: "REFR_READY",
56+
lv.EVENT.REFR_REQUEST: "REFR_REQUEST",
57+
lv.EVENT.REFR_START: "REFR_START",
58+
lv.EVENT.RELEASED: "RELEASED",
59+
lv.EVENT.RENDER_READY: "RENDER_READY",
60+
lv.EVENT.RENDER_START: "RENDER_START",
61+
lv.EVENT.RESOLUTION_CHANGED: "RESOLUTION_CHANGED",
62+
lv.EVENT.ROTARY: "ROTARY",
63+
lv.EVENT.SCREEN_LOADED: "SCREEN_LOADED",
64+
lv.EVENT.SCREEN_LOAD_START: "SCREEN_LOAD_START",
65+
lv.EVENT.SCREEN_UNLOADED: "SCREEN_UNLOADED",
66+
lv.EVENT.SCREEN_UNLOAD_START: "SCREEN_UNLOAD_START",
67+
lv.EVENT.SCROLL: "SCROLL",
68+
lv.EVENT.SCROLL_BEGIN: "SCROLL_BEGIN",
69+
lv.EVENT.SCROLL_END: "SCROLL_END",
70+
lv.EVENT.SCROLL_THROW_BEGIN: "SCROLL_THROW_BEGIN",
71+
lv.EVENT.SHORT_CLICKED: "SHORT_CLICKED",
72+
lv.EVENT.SIZE_CHANGED: "SIZE_CHANGED",
73+
lv.EVENT.STYLE_CHANGED: "STYLE_CHANGED",
74+
lv.EVENT.VALUE_CHANGED: "VALUE_CHANGED",
75+
lv.EVENT.VSYNC: "VSYNC"
76+
}
77+
78+
# Function to translate event code to name
79+
def get_event_name(event_code):
80+
return EVENT_MAP.get(event_code, f"Unknown event {event_code}")
81+
82+
def get_xy():
83+
indev = lv.indev_active()
84+
if indev:
85+
point = lv.point_t()
86+
indev.get_point(point)
87+
return point.x, point.y
88+
else:
89+
return indev_error_x,indev_error_y # make it visible that this occurred
90+
91+
def draw_line(x, y):
92+
global canvas
93+
# Line drawing like this doesn't work:
94+
layer = lv.layer_t()
95+
canvas.init_layer(layer)
96+
dsc = lv.draw_line_dsc_t()
97+
dsc.color = DARKPINK
98+
dsc.width = 4
99+
dsc.round_end = 1
100+
dsc.round_start = 1
101+
dsc.p1 = lv.point_precise_t()
102+
dsc.p1.x = x
103+
dsc.p1.y = y
104+
dsc.p2 = lv.point_precise_t()
105+
dsc.p2.x = 100
106+
dsc.p2.y = 200
107+
#layer.draw_line(dsc) doesnt exist!
108+
lv.draw_line(layer,dsc) # doesnt do anything!
109+
canvas.finish_layer(layer)
110+
111+
7112
def touch_cb(event):
8113
global canvas
9114
event_code=event.get_code()
115+
# Ignore:
116+
# =======
117+
# COVER_CHECK
118+
# DRAW_MAIN
119+
# DRAW_MAIN_BEGIN
120+
# DRAW_MAIN_END
121+
# DRAW_POST
122+
# DRAW_POST_BEGIN
123+
# DRAW_POST_END
124+
# GET_SELF_SIZE
10125
if event_code not in [23,25,26,27,28,29,30,49]:
11-
#print(f"got event: {event}")
12-
#print(f"lv_event_t: code={event_code}, target={event.get_target()}, user_data={event.get_user_data()}, param={event.get_param()}")
13-
if event_code == lv.EVENT.PRESSING:
14-
#print("lv.EVENT.PRESSING")
15-
indev = lv.indev_active()
16-
if indev:
17-
point = lv.point_t()
18-
indev.get_point(point)
19-
x, y = point.x, point.y
20-
#
21-
# drawing a point works:
22-
#canvas.set_px(x,y,lv.color_black(),lv.OPA.COVER)
23-
#
24-
# drawing a square like this works:
25-
#for dx in range(-5,5):
26-
# for dy in range(-5,5):
27-
# canvas.set_px(x+dx,y+dy,DARKPINK,lv.OPA.COVER)
28-
#
29-
# drawing a circle works:
30-
radius = 7 # Set desired radius
31-
for dx in range(-radius, radius):
32-
for dy in range(-radius, radius):
33-
if dx * dx + dy * dy <= radius * radius:
34-
canvas.set_px(x + dx, y + dy, DARKPINK, lv.OPA.COVER)
35-
# Line drawing like this doesn't work:
36-
layer = lv.layer_t()
37-
canvas.init_layer(layer)
38-
dsc = lv.draw_line_dsc_t()
39-
dsc.color = DARKPINK
40-
dsc.width = 4
41-
dsc.round_end = 1
42-
dsc.round_start = 1
43-
dsc.p1 = lv.point_precise_t()
44-
dsc.p1.x = x
45-
dsc.p1.y = y
46-
dsc.p2 = lv.point_precise_t()
47-
dsc.p2.x = 100
48-
dsc.p2.y = 200
49-
#layer.draw_line(dsc) doesnt exist!
50-
lv.draw_line(layer,dsc) # doesnt do anything!
51-
canvas.finish_layer(layer)
52-
else:
53-
print("no indev!")
126+
name = get_event_name(event_code)
127+
#x, y = get_xy()
128+
#print(f"lv_event_t: code={event_code}, name={name}, x={x}, y={y}")
129+
if event_code == lv.EVENT.PRESSING: # this is probably enough
130+
#if event_code in [lv.EVENT.PRESSED, lv.EVENT.PRESSING, lv.EVENT.LONG_PRESSED, lv.EVENT.LONG_PRESSED_REPEAT]:
131+
x, y = get_xy()
132+
# drawing a point works:
133+
#canvas.set_px(x,y,lv.color_black(),lv.OPA.COVER)
134+
#
135+
# drawing a square like this works:
136+
#for dx in range(-5,5):
137+
# for dy in range(-5,5):
138+
# canvas.set_px(x+dx,y+dy,DARKPINK,lv.OPA.COVER)
139+
#
140+
# drawing a circle works:
141+
radius = 7 # Set desired radius
142+
if x == indev_error_x and y == indev_error_y:
143+
radius = 25 # in case of indev error
144+
square = radius * radius
145+
for dx in range(-radius, radius):
146+
for dy in range(-radius, radius):
147+
if dx * dx + dy * dy <= square:
148+
canvas.set_px(x + dx, y + dy, DARKPINK, lv.OPA.COVER)
54149

55150

56151
canvas = lv.canvas(appscreen)
@@ -69,7 +164,3 @@ def touch_cb(event):
69164
canvas.add_flag(lv.obj.FLAG.CLICKABLE)
70165
canvas.add_event_cb(touch_cb, lv.EVENT.ALL, None)
71166

72-
73-
# Wait until the user closes the app
74-
#while appscreen == lv.screen_active():
75-
# time.sleep_ms(1000)

0 commit comments

Comments
 (0)