-
-
Notifications
You must be signed in to change notification settings - Fork 202
/
Copy pathUIcode.cpp
170 lines (149 loc) · 5.82 KB
/
UIcode.cpp
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include <stdio.h>
#define GUILITE_ON //Do not define this macro once more!!!
#include "GuiLite.h"
#include "surface_transparent.h"
#define UI_WIDTH 522
#define UI_HEIGHT 657
static const unsigned char s_wave_data1[] =
{
0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D,
0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D,
0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 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= 1,
ID_WAVE,
ID_DIALOG,
ID_BUTTON
};
class c_wave : public c_wave_ctrl
{
virtual void on_paint()
{
c_rect rect;
get_screen_rect(rect);
c_image::draw_image(s_surface, Z_ORDER_LEVEL_0, c_theme::get_image(IMAGE_CUSTOM1), rect.m_left, rect.m_top);
save_background();
}
virtual void on_init_children()//should be pre_create
{
c_wave_ctrl::on_init_children();
c_rect rect;
get_screen_rect(rect);
m_wave_top = rect.m_top + 270;
m_wave_bottom = m_wave_top + 100;
}
};
class c_my_dialog : public c_dialog
{
virtual void on_init_children()
{
((c_button*)get_wnd_ptr(ID_BUTTON))->set_on_click((WND_CALLBACK)&c_my_dialog::on_clicked);
}
virtual void on_paint(void)
{
c_rect rect;
get_screen_rect(rect);
s_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, GL_ARGB(220, 0, 0, 0), m_z_order);
}
void on_clicked(int ctrl_id, int param)
{
c_dialog::close_dialog(m_surface);
((c_surface_transparent*)m_surface)->clear_layer(m_z_order);
}
};
class c_my_ui : public c_wnd
{
public:
void on_paint()
{
c_image::draw_image(s_surface, Z_ORDER_LEVEL_0, c_theme::get_image(IMAGE_CUSTOM1), 0, 0);
}
virtual void on_init_children(void)
{
c_wave_ctrl* p_wave = (c_wave_ctrl*)get_wnd_ptr(ID_WAVE);
p_wave->set_wave_speed(1);
p_wave->set_wave_color(GL_RGB(0, 255, 0));
p_wave->set_wave_in_out_rate(256, 17);
p_wave->set_wave(&m_wave_buffer);
p_wave->set_max_min(170, 110);
}
c_wave_buffer m_wave_buffer;
};
// Layout Widgets
static c_my_ui s_my_ui;
static c_my_dialog s_my_dialog;
static c_button s_button;
static c_wave s_wave;
WND_TREE s_dialog_widgets[] =
{
{(c_wnd*)&s_button, ID_BUTTON, "CLOSE", 90, 130, 200, 100, NULL},
{NULL, 0 , 0, 0, 0, 0, 0}
};
WND_TREE s_main_widgets[] =
{
{(c_wnd*)&s_wave, ID_WAVE, 0, 0, 0, UI_WIDTH, UI_HEIGHT},
{(c_wnd*)&s_my_dialog, ID_DIALOG, 0, 100, 240, 350, 360, s_dialog_widgets},
{NULL, 0 , 0, 0, 0, 0, 0}
};
// Create GUI
extern const LATTICE_FONT_INFO Consolas_24B;
extern const BITMAP_INFO background_bmp;
void load_resource()
{
c_theme::add_font(FONT_DEFAULT, &Consolas_24B);
c_theme::add_image(IMAGE_CUSTOM1, &background_bmp);
c_theme::add_color(COLOR_WND_FONT, GL_RGB(255, 255, 255));
c_theme::add_color(COLOR_WND_NORMAL, GL_RGB(0, 117, 107));
c_theme::add_color(COLOR_WND_FOCUS, GL_RGB(0, 117, 107));
c_theme::add_color(COLOR_WND_PUSHED, GL_RGB(0, 117, 107));
c_theme::add_color(COLOR_WND_BORDER, GL_RGB(0, 117, 107));
}
void create_ui(void* phy_fb, int screen_width, int screen_height, int color_bytes) {
load_resource();
s_surface = new c_surface_transparent(UI_WIDTH, UI_HEIGHT, color_bytes, Z_ORDER_LEVEL_1);
s_display = new c_display(phy_fb, screen_width, screen_height, s_surface);
s_surface->correct_color_after_display();
s_my_ui.set_surface(s_surface);
s_my_ui.connect(NULL, ID_ROOT, 0, 0, 0, UI_WIDTH, UI_HEIGHT, s_main_widgets);
s_my_ui.show_window();
unsigned int data_index1 = 0;
unsigned int wave_index = 0;
while (1)
{
if (wave_index % 200 == 0)
{
c_dialog::open_dialog(&s_my_dialog);
}
s_my_ui.m_wave_buffer.write_wave_data(s_wave_data1[data_index1++ % sizeof(s_wave_data1)]);
s_my_ui.m_wave_buffer.write_wave_data(s_wave_data1[data_index1++ % sizeof(s_wave_data1)]);
s_my_ui.m_wave_buffer.write_wave_data(s_wave_data1[data_index1++ % sizeof(s_wave_data1)]);
s_my_ui.m_wave_buffer.write_wave_data(s_wave_data1[data_index1++ % sizeof(s_wave_data1)]);
s_wave.refresh_wave(wave_index++);
thread_sleep(17);
}
}
//////////////////////// interface for all platform ////////////////////////
void startHelloTransparent(void* phy_fb, int width, int height, int color_bytes) {
create_ui(phy_fb, width, height, color_bytes);
}
void sendTouch2HelloTransparent(int x, int y, bool is_down)
{
is_down ? s_my_ui.on_touch(x, y, TOUCH_DOWN) : s_my_ui.on_touch(x, y, TOUCH_UP);
}
void sendKey2HelloTransparent(unsigned int key)
{
s_my_ui.on_navigate(NAVIGATION_KEY(key));
}
void* getUiOfHelloTransparent(int* width, int* height, bool force_update)
{
return s_display->get_updated_fb(width, height, force_update);
}