forked from idea4good/GuiLiteSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUIcode.cpp
116 lines (102 loc) · 3.06 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
#define GUILITE_ON //Do not define this macro once more!!!
#include "GuiLite.h"
#include <stdlib.h>
#include <string.h>
const int UI_WIDTH = 512;
const int UI_HEIGHT = 768;
//////////////////////// define widgets & map message ////////////////////////
enum WND_ID
{
ID_ROOT = 1,
ID_PAGE1,
ID_PAGE2,
ID_PAGE3,
ID_PAGE4,
ID_PAGE5
};
class c_page : public c_wnd
{
virtual void on_paint();
};
void c_page::on_paint()
{
c_rect rect;
get_screen_rect(rect);
const BITMAP_INFO* bmp = NULL;
switch (m_id)
{
case ID_PAGE1:
bmp = (const BITMAP_INFO*)c_theme::get_image(IMAGE_CUSTOM1);
break;
case ID_PAGE2:
bmp = (const BITMAP_INFO*)c_theme::get_image(IMAGE_CUSTOM2);
break;
case ID_PAGE3:
bmp = (const BITMAP_INFO*)c_theme::get_image(IMAGE_CUSTOM3);
break;
case ID_PAGE4:
bmp = (const BITMAP_INFO*)c_theme::get_image(IMAGE_CUSTOM4);
break;
case ID_PAGE5:
bmp = (const BITMAP_INFO*)c_theme::get_image(IMAGE_CUSTOM5);
break;
default:
break;
}
c_image::draw_image(m_surface, m_z_order, bmp, rect.m_left, rect.m_top);
}
//////////////////////// layout UI ////////////////////////
c_page s_page1, s_page2, s_page3, s_page4, s_page5;
static c_slide_group s_root;
static WND_TREE s_root_children[] =
{
{ NULL,0,0,0,0,0,0 }
};
//////////////////////// start UI ////////////////////////
extern const BITMAP_INFO ten_bmp, jack_bmp, queen_bmp, king_bmp, ace_bmp;
static c_display* s_display;
void load_resource()
{
c_theme::add_image(IMAGE_CUSTOM1, &ten_bmp);
c_theme::add_image(IMAGE_CUSTOM2, &jack_bmp);
c_theme::add_image(IMAGE_CUSTOM3, &queen_bmp);
c_theme::add_image(IMAGE_CUSTOM4, &king_bmp);
c_theme::add_image(IMAGE_CUSTOM5, &ace_bmp);
}
void create_ui(void* phy_fb, int screen_width, int screen_height, int color_bytes)
{
load_resource();
s_display = new c_display(phy_fb, screen_width, screen_height, UI_WIDTH, UI_HEIGHT, color_bytes, (1 + 5)/*1 root + 5 pages*/);
c_surface* surface = s_display->alloc_surface(Z_ORDER_LEVEL_1);
surface->set_active(true);
s_root.set_surface(surface);
s_root.connect(NULL, ID_ROOT, 0, 0, 0, UI_WIDTH, UI_HEIGHT, s_root_children);
s_root.add_slide(&s_page1, ID_PAGE1, 0, 0, UI_WIDTH, UI_HEIGHT, NULL);
s_root.add_slide(&s_page2, ID_PAGE2, 0, 0, UI_WIDTH, UI_HEIGHT, NULL);
s_root.add_slide(&s_page3, ID_PAGE3, 0, 0, UI_WIDTH, UI_HEIGHT, NULL);
s_root.add_slide(&s_page4, ID_PAGE4, 0, 0, UI_WIDTH, UI_HEIGHT, NULL);
s_root.add_slide(&s_page5, ID_PAGE5, 0, 0, UI_WIDTH, UI_HEIGHT, NULL);
s_root.set_active_slide(0);
s_root.show_window();
while(1)
{
thread_sleep(1000000);
}
}
//////////////////////// interface for all platform ////////////////////////
void startHelloSlide(void* phy_fb, int width, int height, int color_bytes)
{
create_ui(phy_fb, width, height, color_bytes);
}
void sendTouch2HelloSlide(int x, int y, bool is_down)
{
is_down ? s_root.on_touch(x, y, TOUCH_DOWN) : s_root.on_touch(x, y, TOUCH_UP);
}
void* getUiOfHelloSlide(int* width, int* height, bool force_update)
{
return s_display->get_updated_fb(width, height, force_update);
}
int captureUiOfHelloSlide()
{
return s_display->snap_shot("snap_short.bmp");
}