-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathcanvas.cpy
65 lines (50 loc) · 1.76 KB
/
canvas.cpy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "../build/rmkit.h"
class SimpleCanvas: public ui::Widget:
public:
int prevx = -1, prevy = -1
framebuffer::FileFB *vfb
bool full_redraw
SimpleCanvas(int x, y, w, h, string name="note.raw"): ui::Widget(x, y, w, h):
vfb = new framebuffer::FileFB(name.c_str(), w, h)
self.full_redraw = true
self.dirty = 1
vfb->dirty_area.x0 = 0
vfb->dirty_area.y0 = 0
vfb->dirty_area.x1 = self.w
vfb->dirty_area.y1 = self.h
void on_mouse_up(input::SynMotionEvent &ev):
prevx = prevy = -1
void on_mouse_leave(input::SynMotionEvent &ev):
prevx = prevy = -1
void on_mouse_enter(input::SynMotionEvent &ev):
prevx = prevy = -1
void on_mouse_move(input::SynMotionEvent &ev):
if input::is_touch_event(ev):
return
if not mouse_down:
return
nextx := ev.x - self.x
nexty := ev.y - self.y
if prevx != -1:
vfb->draw_line(prevx, prevy, nextx, nexty, 1, BLACK)
self.dirty = 1
prevx = nextx
prevy = nexty
void render():
dirty_rect := self.vfb->dirty_area
if dirty_rect.x1 < dirty_rect.x0 || dirty_rect.y1 < dirty_rect.y0:
return
for int i = dirty_rect.y0; i < dirty_rect.y1; i++:
memcpy(
&fb->fbmem[(y+i)*fb->width + dirty_rect.x0 + self.x],
&vfb->fbmem[i*vfb->width + dirty_rect.x0],
(dirty_rect.x1 - dirty_rect.x0) * sizeof(remarkable_color))
self.fb->update_dirty(self.fb->dirty_area,
vfb->dirty_area.x0 + self.x, vfb->dirty_area.y0 + self.y)
self.fb->update_dirty(self.fb->dirty_area,
vfb->dirty_area.x1 + self.x, vfb->dirty_area.y1 + self.y)
self.fb->dirty = 1
if self.full_redraw:
self.full_redraw = false
self.fb->draw_rect(self.x, self.y, self.w, self.h, BLACK, false)
vfb->reset_dirty(vfb->dirty_area)