-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathmain.cpy
138 lines (107 loc) · 3.8 KB
/
main.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include "../build/rmkit.h"
#include "../shared/proc.h"
#include "app/ui.h"
#include "app/canvas.h"
#include "app/state.h"
using namespace std
using app_ui::STATE
class ToolBar : public ui::HorizontalLayout:
public:
class Background: public ui::Widget:
public:
Background(int x, y, w, h): ui::Widget(x, y, w, h):
pass
void render():
self.fb->draw_rect(x, y, w, h, WHITE, true /* fill */)
;
Background *bg
ToolBar(int x, y, w, h, ui::Scene s): ui::HorizontalLayout(x, y, w, h, s):
bg = new Background(x, y, w, h)
s->add(bg)
void set_bg():
bg->x = self.x
bg->y = self.y
bg->w = self.w
bg->h = self.h
;
class App:
public:
shared_ptr<framebuffer::FB> fb
ui::Scene notebook
app_ui::ManageButton *manage_button
app_ui::Canvas *canvas
// do we accept finger touch events
App():
fb = framebuffer::get()
fb->make_save_dir()
fb->clear_screen()
fb->redraw_screen()
w, h = fb->get_display_size()
notebook = ui::make_scene()
ui::MainLoop::set_scene(notebook)
canvas = new app_ui::Canvas(0, 0, fb->width, fb->height)
notebook->add(canvas)
toolbar_area := new ui::VerticalLayout(0, 0, w, h, notebook)
toolbar := new ToolBar(0, 0, w, TOOLBAR_HEIGHT, notebook)
// aligns the toolbar to the bottom of the screen using pack_end
// NOTE: this is an example of nesting layouts
toolbar_area->pack_end(toolbar)
toolbar->set_bg()
// we always have to pack layouts in order
tool_button := new app_ui::ToolButton(0, 0, ICON_WIDTH*2, TOOLBAR_HEIGHT)
tool_button->set_option_size(250, TOOLBAR_HEIGHT)
tool_button->set_option_offset(0, -TOOLBAR_HEIGHT)
toolbar->pack_start(tool_button)
brush_config_button := new app_ui::BrushConfigButton(0, 0, ICON_WIDTH*2, TOOLBAR_HEIGHT)
brush_config_button->set_option_size(200, TOOLBAR_HEIGHT)
brush_config_button->set_option_offset(0, -TOOLBAR_HEIGHT)
toolbar->pack_start(brush_config_button)
toolbar->pack_start(new app_ui::LayerButton(0, 0, 150, TOOLBAR_HEIGHT, canvas), 10)
toolbar->pack_center(new app_ui::LiftBrushButton(0, 0, 114, 100, canvas))
// because we pack end, we go in reverse order
toolbar->pack_end(manage_button = new app_ui::ManageButton(0, 0, 100, TOOLBAR_HEIGHT, canvas))
toolbar->pack_end(new app_ui::RedoButton(0, 0, ICON_WIDTH, TOOLBAR_HEIGHT, canvas))
toolbar->pack_end(new app_ui::UndoButton(0, 0, ICON_WIDTH, TOOLBAR_HEIGHT, canvas))
toolbar->pack_end(new app_ui::HistoryButton(0, 0, 100, TOOLBAR_HEIGHT, canvas))
#ifndef KOBO
toolbar->pack_end(new app_ui::PalmButton(0, 0, ICON_WIDTH, TOOLBAR_HEIGHT))
#endif
canvas->mouse.up += PLS_LAMBDA(auto):
toolbar->refresh()
;
def handle_key_event(input::SynKeyEvent &key_ev):
if key_ev.is_pressed:
switch key_ev.key:
case KEY_POWER:
manage_button->select_exit()
break
case KEY_HOME:
fb->clear_screen()
ui::MainLoop::refresh()
break
default:
ui::MainLoop::handle_key_event(key_ev)
return
key_ev.stop_propagation()
def handle_motion_event(input::SynMotionEvent &syn_ev):
#ifdef DEBUG_INPUT
if (auto m_ev = input::is_mouse_event(syn_ev)):
debug "MOUSE EVENT"
else if (auto t_ev = input::is_touch_event(syn_ev)):
debug "TOUVCH EVENT"
else if (auto w_ev = input::is_wacom_event(syn_ev)):
debug "WACOM EVENT"
#endif
if STATE.reject_touch && input::is_touch_event(syn_ev):
syn_ev.stop_propagation()
return
def run():
ui::MainLoop::key_event += PLS_DELEGATE(self.handle_key_event)
ui::MainLoop::motion_event += PLS_DELEGATE(self.handle_motion_event)
while true:
ui::MainLoop::main()
ui::MainLoop::redraw()
ui::MainLoop::read_input()
App app
def main():
app.run()