34 Star 206 Fork 82

idea4good / GuiLiteSamples

Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
Clone or download
UIcode.cpp 3.90 KB
Copy Edit Web IDE Raw Blame History
#define GUILITE_ON //Do not define this macro once more!!!
#include "GuiLite.h"
#include <stdlib.h>
#include <stdio.h>
const int UI_WIDTH = 240;
const int UI_HEIGHT = 320;
//////////////////////// define widgets & map message ////////////////////////
enum WND_ID
{
ID_ROOT = 1,
ID_LABEL1,
ID_LABEL2,
ID_LABEL3,
ID_BUTTON1,
ID_BUTTON2,
ID_BUTTON3
};
class c_myUI : public c_wnd
{
virtual void on_init_children()
{
((c_button*)get_wnd_ptr(ID_BUTTON1))->set_on_click((WND_CALLBACK)&c_myUI::on_clicked);
((c_button*)get_wnd_ptr(ID_BUTTON2))->set_on_click((WND_CALLBACK)&c_myUI::on_clicked);
((c_button*)get_wnd_ptr(ID_BUTTON3))->set_on_click((WND_CALLBACK)&c_myUI::on_clicked);
}
virtual void on_paint(void)
{
c_rect rect;
get_screen_rect(rect);
m_surface->fill_rect(rect, GL_RGB(0, 0, 0), m_z_order);
}
void on_clicked(int ctrl_id, int param) {
static int sum1, sum2, sum3;
static char str1[8], str2[8], str3[8];
c_button* button = (c_button*)get_wnd_ptr(ctrl_id);
switch (ctrl_id)
{
case ID_BUTTON1:
sprintf(str1, "%d", ++sum1);
button->set_str(str1);
break;
case ID_BUTTON2:
sprintf(str2, "%d", ++sum2);
button->set_str(str2);
break;
case ID_BUTTON3:
sprintf(str3, "%d", ++sum3);
button->set_str(str3);
break;
}
button->show_window();
}
};
//////////////////////// layout UI ////////////////////////
static c_myUI s_myUI;
static c_label s_label1, s_label2, s_label3;
static c_button s_button1, s_button2, s_button3;
static WND_TREE s_myUI_children[] =
{
{&s_label1, ID_LABEL1, "a: <<", 20, 20, 80, 40, NULL},
{&s_label2, ID_LABEL2, "d: >>", 20, 140, 80, 40, NULL},
{&s_label3, ID_LABEL3, "s: click", 20, 260, 80, 40, NULL},
{&s_button1, ID_BUTTON1, "0", 140, 20, 80, 40, NULL},
{&s_button2, ID_BUTTON2, "0", 140, 140, 80, 40, NULL},
{&s_button3, ID_BUTTON3, "0", 140, 260, 80, 40, NULL},
{ NULL,0,0,0,0,0,0 }
};
//////////////////////// start UI ////////////////////////
extern const LATTICE_FONT_INFO Consolas_28;
void load_resource()
{
c_theme::add_font(FONT_DEFAULT, &Consolas_28);
//for button
c_theme::add_color(COLOR_WND_FONT, GL_RGB(255, 255, 243));
c_theme::add_color(COLOR_WND_NORMAL, GL_RGB(59, 75, 94));
c_theme::add_color(COLOR_WND_PUSHED, GL_RGB(33, 42, 53));
c_theme::add_color(COLOR_WND_FOCUS, GL_RGB(78, 198, 76));
c_theme::add_color(COLOR_WND_BORDER, GL_RGB(46, 59, 73));
}
static c_display* s_display;
static c_surface* s_surface;
void create_ui(void* phy_fb, int screen_width, int screen_height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op)
{
load_resource();
if (phy_fb)
{
static c_surface surface(UI_WIDTH, UI_HEIGHT, color_bytes, Z_ORDER_LEVEL_0);
static c_display display(phy_fb, screen_width, screen_height, &surface);
s_surface = &surface;
s_display = &display;
}
else
{//for MCU without framebuffer
static c_surface_no_fb surface_no_fb(UI_WIDTH, UI_HEIGHT, color_bytes, gfx_op, Z_ORDER_LEVEL_0);
static c_display display(phy_fb, screen_width, screen_height, &surface_no_fb);
s_surface = &surface_no_fb;
s_display = &display;
}
s_myUI.set_surface(s_surface);
s_myUI.connect(NULL, ID_ROOT, 0, 0, 0, UI_WIDTH, UI_HEIGHT, s_myUI_children);
s_myUI.show_window();
}
//////////////////////// interface for all platform ////////////////////////
extern "C" void startHelloNoTouch(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op)
{
create_ui(phy_fb, width, height, color_bytes, gfx_op);
}
extern "C" void sendTouch2HelloNoTouch(int x, int y, bool is_down)
{
is_down ? s_myUI.on_touch(x, y, TOUCH_DOWN) : s_myUI.on_touch(x, y, TOUCH_UP);
}
extern "C" void sendKey2HelloNoTouch(unsigned int key)
{
s_myUI.on_navigate(NAVIGATION_KEY(key));
}
extern void* getUiOfHelloNoTouch(int* width, int* height, bool force_update = false)
{
if (s_display)
{
return s_display->get_updated_fb(width, height, force_update);
}
return NULL;
}
int captureUiOfHelloNoTouch()
{
return s_display->snap_shot("snap_short.bmp");
}

Comment ( 0 )

Sign in for post a comment

C++
1
https://gitee.com/idea4good/GuiLiteSamples.git
git@gitee.com:idea4good/GuiLiteSamples.git
idea4good
GuiLiteSamples
GuiLiteSamples
master

Search

101046 36f486cf 1899542 101055 4cb66026 1899542