代码拉取完成,页面将自动刷新
同步操作将从 idea4good/GuiLiteSamples 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#define GUILITE_ON //Do not define this macro once more!!!
#include "GuiLite.h"
#include <stdlib.h>
const int UI_WIDTH = 1280;
const int UI_HEIGHT = 720;
//////////////////////// define widgets & map message ////////////////////////
enum WND_ID
{
ID_DESKTOP = 1,
ID_START_BUTTON,
ID_START_MENU
};
class c_start_button : public c_button
{
virtual void on_paint()
{
c_rect rect;
get_screen_rect(rect);
extern const BITMAP_INFO start_icon_bmp;
extern const BITMAP_INFO start_icon_click_bmp;
switch (m_status)
{
case STATUS_NORMAL:
c_bitmap::draw_bitmap(m_surface, m_z_order, &start_icon_bmp, rect.m_left, rect.m_top);
break;
case STATUS_FOCUSED:
c_bitmap::draw_bitmap(m_surface, m_z_order, &start_icon_bmp, rect.m_left, rect.m_top);
break;
case STATUS_PUSHED:
c_bitmap::draw_bitmap(m_surface, m_z_order, &start_icon_click_bmp, rect.m_left, rect.m_top);
break;
default:
ASSERT(false);
break;
}
}
};
class c_desktop : public c_wnd
{
virtual void on_paint(void);
void on_clicked(int ctrl_id, int param);
GL_DECLARE_MESSAGE_MAP()//delcare message
};
//map message
GL_BEGIN_MESSAGE_MAP(c_desktop)
ON_GL_BN_CLICKED(c_desktop::on_clicked)
GL_END_MESSAGE_MAP()
void c_desktop::on_clicked(int ctrl_id, int param)
{
static bool is_open = false;
(is_open) ? c_dialog::close_dialog(m_surface): c_dialog::open_dialog((c_dialog*)get_wnd_ptr(ID_START_MENU), false);
is_open = !is_open;
}
void c_desktop::on_paint()
{
c_rect rect;
get_screen_rect(rect);
extern const BITMAP_INFO desktop_bmp;
int block_width = 80;
int block_height = 60;
int block_rows = desktop_bmp.height / block_height;
int block_cols = desktop_bmp.width / block_width;
int block_sum = block_rows * block_cols;
bool* block_map = (bool*)calloc(block_sum, sizeof(bool));
if (!block_map) { return; }
int sum = 0;
while (sum < block_sum)
{
int x = rand() % block_cols;
int y = rand() % block_rows;
if (block_map[x + (y * block_cols)] == false)
{
c_bitmap::draw_bitmap(m_surface, m_z_order, &desktop_bmp, rect.m_left + x * block_width, rect.m_top + y * block_height, x * block_width, y * block_height, block_width, block_height);
block_map[x + (y * block_cols)] = true;
sum++;
thread_sleep(10);
}
}
free(block_map);
}
class c_start_menu : public c_dialog
{
virtual void on_paint(void);
};
void c_start_menu::on_paint(void)
{
c_rect rect;
get_screen_rect(rect);
extern const BITMAP_INFO start_menu_bmp;
int step = 10;
for (int i = 0; i < start_menu_bmp.height; i += step)
{
thread_sleep(10);
c_bitmap::draw_bitmap(m_surface, m_z_order, &start_menu_bmp, rect.m_left, rect.m_top + i, 0, i, start_menu_bmp.width, step, GL_RGB(0, 0, 0));
}
}
//////////////////////// layout UI ////////////////////////
static c_desktop s_desktop;
static c_start_button s_start_button;
static c_start_menu s_start_menu;
static WND_TREE s_desktop_children[] =
{
{(c_wnd*)&s_start_menu, ID_START_MENU, 0, 400, 50, 475, 633, NULL},
{(c_wnd*)&s_start_button, ID_START_BUTTON, 0, 0, 682, 47, 38, NULL},
{ NULL,0,0,0,0,0,0 }
};
//////////////////////// start UI ////////////////////////
static c_display* s_display;
void create_ui(void* phy_fb, int screen_width, int screen_height, int color_bytes)
{
c_surface surface = c_surface(UI_WIDTH, UI_HEIGHT, color_bytes, Z_ORDER_LEVEL_1);
s_display = new c_display(phy_fb, screen_width, screen_height, &surface);
s_desktop.set_surface(&surface);
s_desktop.connect(NULL, ID_DESKTOP, 0, 0, 0, UI_WIDTH, UI_HEIGHT, s_desktop_children);
s_desktop.show_window();
while(1)
{
thread_sleep(1000000);
}
}
//////////////////////// interface for all platform ////////////////////////
void start_helloGL(void* phy_fb, int width, int height, int color_bytes)
{
create_ui(phy_fb, width, height, color_bytes);
}
void sendTouch2helloGL(int x, int y, bool is_down)
{
is_down ? s_desktop.on_touch(x, y, TOUCH_DOWN) : s_desktop.on_touch(x, y, TOUCH_UP);
}
void* getUiOfhelloGL(int* width, int* height, bool force_update)
{
return s_display->get_updated_fb(width, height, force_update);
}
int captureUiOfhelloGL()
{
return s_display->snap_shot("snap_short.bmp");
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。