!34 refactor display.h

1. 刪除了 c_surface_no_fb, 重构了 c_display, c_surface 受影响文件: GuiLite.h, display.h
2. 重构了GuiLite/src下的目录结构,删除了 core_include, widgets_include 文件夹
3. 简化了:GuiLite.h 代码量(4338 -> 4286)
4. 受影响项目:GuiLiteSamples,请一并更新
This commit is contained in:
idea4good 2022-05-31 06:53:23 +00:00
parent cd2f8b2863
commit 4eba1d2b13
53 changed files with 822 additions and 1299 deletions

435
GuiLite.h
View File

@ -1,29 +1,23 @@
#pragma once #pragma once
#define REAL_TIME_TASK_CYCLE_MS 50 #define REAL_TIME_TASK_CYCLE_MS 50
#define MAX(a,b) (((a)>(b))?(a):(b)) #define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b)) #define MIN(a,b) (((a)<(b))?(a):(b))
#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) #define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b)))
#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) #define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF)
#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) #define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b)))
#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) #define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF)
#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) #define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF)
#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) #define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF)
#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) #define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8))
#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) #define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8))
#define ALIGN_HCENTER 0x00000000L #define ALIGN_HCENTER 0x00000000L
#define ALIGN_LEFT 0x01000000L #define ALIGN_LEFT 0x01000000L
#define ALIGN_RIGHT 0x02000000L #define ALIGN_RIGHT 0x02000000L
#define ALIGN_HMASK 0x03000000L #define ALIGN_HMASK 0x03000000L
#define ALIGN_VCENTER 0x00000000L #define ALIGN_VCENTER 0x00000000L
#define ALIGN_TOP 0x00100000L #define ALIGN_TOP 0x00100000L
#define ALIGN_BOTTOM 0x00200000L #define ALIGN_BOTTOM 0x00200000L
#define ALIGN_VMASK 0x00300000L #define ALIGN_VMASK 0x00300000L
typedef struct typedef struct
{ {
unsigned short year; unsigned short year;
@ -34,7 +28,6 @@ typedef struct
unsigned short minute; unsigned short minute;
unsigned short second; unsigned short second;
}T_TIME; }T_TIME;
void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log));
void _assert(const char* file, int line); void _assert(const char* file, int line);
#define ASSERT(condition) \ #define ASSERT(condition) \
@ -42,19 +35,15 @@ void _assert(const char* file, int line);
if(!(condition))_assert(__FILE__, __LINE__);\ if(!(condition))_assert(__FILE__, __LINE__);\
}while(0) }while(0)
void log_out(const char* log); void log_out(const char* log);
long get_time_in_second(); long get_time_in_second();
T_TIME second_to_day(long second); T_TIME second_to_day(long second);
T_TIME get_time(); T_TIME get_time();
void start_real_timer(void (*func)(void* arg)); void start_real_timer(void (*func)(void* arg));
void register_timer(int milli_second, void func(void* param), void* param); void register_timer(int milli_second, void func(void* param), void* param);
unsigned int get_cur_thread_id(); unsigned int get_cur_thread_id();
void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg);
void thread_sleep(unsigned int milli_seconds); void thread_sleep(unsigned int milli_seconds);
int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data);
#define FIFO_BUFFER_LEN 1024 #define FIFO_BUFFER_LEN 1024
class c_fifo class c_fifo
{ {
@ -69,7 +58,6 @@ private:
void* m_read_sem; void* m_read_sem;
void* m_write_mutex; void* m_write_mutex;
}; };
class c_rect class c_rect
{ {
public: public:
@ -96,7 +84,6 @@ public:
} }
int width() const { return m_right - m_left + 1; } int width() const { return m_right - m_left + 1; }
int height() const { return m_bottom - m_top + 1 ; } int height() const { return m_bottom - m_top + 1 ; }
int m_left; int m_left;
int m_top; int m_top;
int m_right; int m_right;
@ -238,7 +225,7 @@ typedef enum
Z_ORDER_LEVEL_2,//highest graphic level Z_ORDER_LEVEL_2,//highest graphic level
Z_ORDER_LEVEL_MAX Z_ORDER_LEVEL_MAX
}Z_ORDER_LEVEL; }Z_ORDER_LEVEL;
struct EXTERNAL_GFX_OP struct DISPLAY_DRIVER
{ {
void(*draw_pixel)(int x, int y, unsigned int rgb); void(*draw_pixel)(int x, int y, unsigned int rgb);
void(*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); void(*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb);
@ -247,18 +234,19 @@ class c_surface;
class c_display { class c_display {
friend class c_surface; friend class c_surface;
public: public:
inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface or surface_no_fb inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver = 0);//single custom surface
inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface);//single custom surface inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver = 0);//multiple surface
inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for multiple surfaces inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for slide group
inline int swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset); inline int swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset);
int get_width() { return m_width; } int get_width() { return m_width; }
int get_height() { return m_height; } int get_height() { return m_height; }
void* get_phy_fb() { return m_phy_fb; }
void* get_updated_fb(int* width, int* height, bool force_update = false) void* get_updated_fb(int* width, int* height, bool force_update = false)
{ {
if (width && height) if (width && height)
{ {
*width = get_width(); *width = m_width;
*height = get_height(); *height = m_height;
} }
if (force_update) if (force_update)
{ {
@ -277,35 +265,123 @@ public:
{ {
return -1; return -1;
} }
int width = get_width();
int height = get_height();
//16 bits framebuffer //16 bits framebuffer
if (m_color_bytes == 2) if (m_color_bytes == 2)
{ {
return build_bmp(file_name, width, height, (unsigned char*)m_phy_fb); return build_bmp(file_name, m_width, m_height, (unsigned char*)m_phy_fb);
} }
//32 bits framebuffer //32 bits framebuffer
unsigned short* p_bmp565_data = new unsigned short[width * height]; unsigned short* p_bmp565_data = new unsigned short[m_width * m_height];
unsigned int* p_raw_data = (unsigned int*)m_phy_fb; unsigned int* p_raw_data = (unsigned int*)m_phy_fb;
for (int i = 0; i < width * height; i++) for (int i = 0; i < m_width * m_height; i++)
{ {
unsigned int rgb = *p_raw_data++; unsigned int rgb = *p_raw_data++;
p_bmp565_data[i] = GL_RGB_32_to_16(rgb); p_bmp565_data[i] = GL_RGB_32_to_16(rgb);
} }
int ret = build_bmp(file_name, width, height, (unsigned char*)p_bmp565_data); int ret = build_bmp(file_name, m_width, m_height, (unsigned char*)p_bmp565_data);
delete[]p_bmp565_data; delete[]p_bmp565_data;
return ret; return ret;
} }
private: protected:
int m_width; //in pixels virtual void draw_pixel(int x, int y, unsigned int rgb)
int m_height; //in pixels {
int m_color_bytes; //16 bits, 32 bits only if ((x >= m_width) || (y >= m_height)) { return; }
void* m_phy_fb; //physical framebuffer if (m_driver && m_driver->draw_pixel)
{
return m_driver->draw_pixel(x, y, rgb);
}
if (m_color_bytes == 2)
{
((unsigned short*)m_phy_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb);
}
else
{
((unsigned int*)m_phy_fb)[y * m_width + x] = rgb;
}
}
virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb)
{
if (m_driver && m_driver->fill_rect)
{
return m_driver->fill_rect(x0, y0, x1, y1, rgb);
}
if (m_driver && m_driver->draw_pixel)
{
for (int y = y0; y <= y1; y++)
{
for (int x = x0; x <= x1; x++)
{
m_driver->draw_pixel(x, y, rgb);
}
}
return;
}
register int _width = m_width;
register int _height = m_height;
int x, y;
if (m_color_bytes == 2)
{
unsigned short* phy_fb;
unsigned int rgb_16 = GL_RGB_32_to_16(rgb);
for (y = y0; y <= y1; y++)
{
phy_fb = &((unsigned short*)m_phy_fb)[y * _width + x0];
for (x = x0; x <= x1; x++)
{
if ((x < _width) && (y < _height))
{
*phy_fb++ = rgb_16;
}
}
}
}
else
{
unsigned int* phy_fb;
for (y = y0; y <= y1; y++)
{
phy_fb = &((unsigned int*)m_phy_fb)[y * _width + x0];
for (x = x0; x <= x1; x++)
{
if ((x < _width) && (y < _height))
{
*phy_fb++ = rgb;
}
}
}
}
}
virtual int flush_screen(int left, int top, int right, int bottom, void* fb, int fb_width)
{
if ((0 == m_phy_fb) || (0 == fb))
{
return -1;
}
register int _width = m_width;
register int _height = m_height;
left = (left >= _width) ? (_width - 1) : left;
right = (right >= _width) ? (_width - 1) : right;
top = (top >= _height) ? (_height - 1) : top;
bottom = (bottom >= _height) ? (_height - 1) : bottom;
for (int y = top; y < bottom; y++)
{
void* s_addr = (char*)fb + ((y * fb_width + left) * m_color_bytes);
void* d_addr = (char*)m_phy_fb + ((y * _width + left) * m_color_bytes);
memcpy(d_addr, s_addr, (right - left) * m_color_bytes);
}
return 0;
}
int m_width; //in pixels
int m_height; //in pixels
int m_color_bytes; //16/32 bits for default
void* m_phy_fb; //physical framebuffer for default
struct DISPLAY_DRIVER* m_driver; //Rendering by external method without default physical framebuffer
int m_phy_read_index; int m_phy_read_index;
int m_phy_write_index; int m_phy_write_index;
c_surface* m_surface_group[SURFACE_CNT_MAX]; c_surface* m_surface_group[SURFACE_CNT_MAX];
int m_surface_cnt; //surface count int m_surface_cnt; //surface count
int m_surface_index; int m_surface_index;
}; };
class c_layer class c_layer
{ {
@ -317,12 +393,10 @@ public:
class c_surface { class c_surface {
friend class c_display; friend class c_bitmap_operator; friend class c_display; friend class c_bitmap_operator;
public: public:
c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_fb(0), m_phy_write_index(0), m_display(0) c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_write_index(0), m_display(0)
{ {
(overlpa_rect == c_rect()) ? set_surface(max_zorder, c_rect(0, 0, width - 1, height - 1)) : set_surface(max_zorder, overlpa_rect); (overlpa_rect == c_rect()) ? set_surface(max_zorder, c_rect(0, 0, width - 1, height - 1)) : set_surface(max_zorder, overlpa_rect);
} }
int get_width() { return m_width; }
int get_height() { return m_height; }
unsigned int get_pixel(int x, int y, unsigned int z_order) unsigned int get_pixel(int x, int y, unsigned int z_order)
{ {
if (x >= m_width || y >= m_height || x < 0 || y < 0 || z_order >= Z_ORDER_LEVEL_MAX) if (x >= m_width || y >= m_height || x < 0 || y < 0 || z_order >= Z_ORDER_LEVEL_MAX)
@ -332,15 +406,15 @@ public:
} }
if (m_layers[z_order].fb) if (m_layers[z_order].fb)
{ {
return (m_color_bytes == 4) ? ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]); return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]) : ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x];
} }
else if (m_fb) else if (m_fb)
{ {
return (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]); return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]) : ((unsigned int*)m_fb)[y * m_width + x];
} }
else if (m_phy_fb) else if (m_display->m_phy_fb)
{ {
return (m_color_bytes == 4) ? ((unsigned int*)m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_phy_fb)[y * m_width + x]); return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]) : ((unsigned int*)m_display->m_phy_fb)[y * m_width + x];
} }
return 0; return 0;
} }
@ -357,7 +431,7 @@ public:
} }
if (z_order == m_max_zorder) if (z_order == m_max_zorder)
{ {
return draw_pixel_on_fb(x, y, rgb); return draw_pixel_low_level(x, y, rgb);
} }
if (z_order > (unsigned int)m_top_zorder) if (z_order > (unsigned int)m_top_zorder)
@ -367,19 +441,19 @@ public:
if (m_layers[z_order].rect.pt_in_rect(x, y)) if (m_layers[z_order].rect.pt_in_rect(x, y))
{ {
c_rect layer_rect = m_layers[z_order].rect; c_rect layer_rect = m_layers[z_order].rect;
if (m_color_bytes == 4) if (m_color_bytes == 2)
{ {
((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb);
} }
else else
{ {
((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb;
} }
} }
if (z_order == m_top_zorder) if (z_order == m_top_zorder)
{ {
return draw_pixel_on_fb(x, y, rgb); return draw_pixel_low_level(x, y, rgb);
} }
bool be_overlapped = false; bool be_overlapped = false;
for (unsigned int tmp_z_order = Z_ORDER_LEVEL_MAX - 1; tmp_z_order > z_order; tmp_z_order--) for (unsigned int tmp_z_order = Z_ORDER_LEVEL_MAX - 1; tmp_z_order > z_order; tmp_z_order--)
@ -392,7 +466,7 @@ public:
} }
if (!be_overlapped) if (!be_overlapped)
{ {
draw_pixel_on_fb(x, y, rgb); draw_pixel_low_level(x, y, rgb);
} }
} }
virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order) virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order)
@ -403,7 +477,7 @@ public:
y1 = (y1 > (m_height - 1)) ? (m_height - 1) : y1; y1 = (y1 > (m_height - 1)) ? (m_height - 1) : y1;
if (z_order == m_max_zorder) if (z_order == m_max_zorder)
{ {
return fill_rect_on_fb(x0, y0, x1, y1, rgb); return fill_rect_low_level(x0, y0, x1, y1, rgb);
} }
if (z_order == m_top_zorder) if (z_order == m_top_zorder)
{ {
@ -416,18 +490,18 @@ public:
{ {
if (layer_rect.pt_in_rect(x, y)) if (layer_rect.pt_in_rect(x, y))
{ {
if (m_color_bytes == 4) if (m_color_bytes == 2)
{ {
((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16;
} }
else else
{ {
((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb;
} }
} }
} }
} }
return fill_rect_on_fb(x0, y0, x1, y1, rgb); return fill_rect_low_level(x0, y0, x1, y1, rgb);
} }
for (; y0 <= y1; y0++) for (; y0 <= y1; y0++)
{ {
@ -499,27 +573,16 @@ public:
} }
int flush_screen(int left, int top, int right, int bottom) int flush_screen(int left, int top, int right, int bottom)
{ {
if (!m_is_active)
{
return -1;
}
if (left < 0 || left >= m_width || right < 0 || right >= m_width || if (left < 0 || left >= m_width || right < 0 || right >= m_width ||
top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) top < 0 || top >= m_height || bottom < 0 || bottom >= m_height)
{ {
ASSERT(false); ASSERT(false);
} }
if (!m_is_active || (0 == m_phy_fb) || (0 == m_fb)) m_display->flush_screen(left, top, right, bottom, m_fb, m_width);
{
return -1;
}
int display_width = m_display->get_width();
int display_height = m_display->get_height();
left = (left >= display_width) ? (display_width - 1) : left;
right = (right >= display_width) ? (display_width - 1) : right;
top = (top >= display_height) ? (display_height - 1) : top;
bottom = (bottom >= display_height) ? (display_height - 1) : bottom;
for (int y = top; y < bottom; y++)
{
void* s_addr = (char*)m_fb + ((y * m_width + left) * m_color_bytes);
void* d_addr = (char*)m_phy_fb + ((y * display_width + left) * m_color_bytes);
memcpy(d_addr, s_addr, (right - left) * m_color_bytes);
}
*m_phy_write_index = *m_phy_write_index + 1; *m_phy_write_index = *m_phy_write_index + 1;
return 0; return 0;
} }
@ -537,90 +600,62 @@ public:
{ {
for (int x = rect.m_left; x <= rect.m_right; x++) for (int x = rect.m_left; x <= rect.m_right; x++)
{ {
unsigned int rgb = (m_color_bytes == 4) ? ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width] : GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]); unsigned int rgb = (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]) : ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width];
draw_pixel_on_fb(x, y, rgb); draw_pixel_low_level(x, y, rgb);
} }
} }
return 0; return 0;
} }
void set_active(bool flag) { m_is_active = flag; } void set_active(bool flag) { m_is_active = flag; }
protected: protected:
virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) virtual void fill_rect_low_level(int x0, int y0, int x1, int y1, unsigned int rgb)
{ {//fill rect on framebuffer of surface
int display_width = m_display->get_width(); int x, y;
int display_height = m_display->get_height(); if (m_color_bytes == 2)
if (m_color_bytes == 4)
{ {
int x; unsigned short* fb;
unsigned int* fb, * phy_fb; unsigned int rgb_16 = GL_RGB_32_to_16(rgb);
for (; y0 <= y1; y0++) for (y = y0; y <= y1; y++)
{ {
x = x0; fb = m_fb ? &((unsigned short*)m_fb)[y * m_width + x0] : 0;
fb = m_fb ? &((unsigned int*)m_fb)[y0 * m_width + x] : 0; if (!fb) { break; }
phy_fb = &((unsigned int*)m_phy_fb)[y0 * display_width + x]; for (x = x0; x <= x1; x++)
*m_phy_write_index = *m_phy_write_index + 1;
for (; x <= x1; x++)
{ {
if (fb) *fb++ = rgb_16;
{
*fb++ = rgb;
}
if (m_is_active && (x < display_width) && (y0 < display_height))
{
*phy_fb++ = rgb;
}
} }
} }
} }
else if (m_color_bytes == 2) else
{ {
int x; unsigned int* fb;
unsigned short* fb, * phy_fb; for (y = y0; y <= y1; y++)
rgb = GL_RGB_32_to_16(rgb);
for (; y0 <= y1; y0++)
{ {
x = x0; fb = m_fb ? &((unsigned int*)m_fb)[y * m_width + x0] : 0;
fb = m_fb ? &((unsigned short*)m_fb)[y0 * m_width + x] : 0; if (!fb) { break; }
phy_fb = &((unsigned short*)m_phy_fb)[y0 * display_width + x]; for (x = x0; x <= x1; x++)
*m_phy_write_index = *m_phy_write_index + 1;
for (; x <= x1; x++)
{ {
if (fb) *fb++ = rgb;
{
*fb++ = rgb;
}
if (m_is_active && (x < display_width) && (y0 < display_height))
{
*phy_fb++ = rgb;
}
} }
} }
} }
if (!m_is_active) { return; }
m_display->fill_rect(x0, y0, x1, y1, rgb);
*m_phy_write_index = *m_phy_write_index + 1;
} }
virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) virtual void draw_pixel_low_level(int x, int y, unsigned int rgb)
{ {
if (m_fb) if (m_fb)
{ {//draw pixel on framebuffer of surface
(m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] = rgb : ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); (m_color_bytes == 2) ? ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb): ((unsigned int*)m_fb)[y * m_width + x] = rgb;
}
if (m_is_active && (x < m_display->get_width()) && (y < m_display->get_height()))
{
if (m_color_bytes == 4)
{
((unsigned int*)m_phy_fb)[y * (m_display->get_width()) + x] = rgb;
}
else
{
((unsigned short*)m_phy_fb)[y * (m_display->get_width()) + x] = GL_RGB_32_to_16(rgb);
}
*m_phy_write_index = *m_phy_write_index + 1;
} }
if (!m_is_active) { return; }
m_display->draw_pixel(x, y, rgb);
*m_phy_write_index = *m_phy_write_index + 1;
} }
void attach_display(c_display* display) void attach_display(c_display* display)
{ {
ASSERT(display); ASSERT(display);
m_display = display; m_display = display;
m_phy_fb = display->m_phy_fb;
m_phy_write_index = &display->m_phy_write_index; m_phy_write_index = &display->m_phy_write_index;
} }
void set_surface(Z_ORDER_LEVEL max_z_order, c_rect layer_rect) void set_surface(Z_ORDER_LEVEL max_z_order, c_rect layer_rect)
@ -638,87 +673,22 @@ protected:
} }
int m_width; //in pixels int m_width; //in pixels
int m_height; //in pixels int m_height; //in pixels
int m_color_bytes; //16 bits, 32 bits only int m_color_bytes; //16 bits, 32 bits for default
void* m_fb; //frame buffer you could see void* m_fb; //frame buffer you could see
c_layer m_layers[Z_ORDER_LEVEL_MAX];//all graphic layers c_layer m_layers[Z_ORDER_LEVEL_MAX];//all graphic layers
bool m_is_active; //active flag bool m_is_active; //active flag
Z_ORDER_LEVEL m_max_zorder; //the highest graphic layer the surface will have Z_ORDER_LEVEL m_max_zorder; //the highest graphic layer the surface will have
Z_ORDER_LEVEL m_top_zorder; //the current highest graphic layer the surface have Z_ORDER_LEVEL m_top_zorder; //the current highest graphic layer the surface have
void* m_phy_fb; //physical framebufer
int* m_phy_write_index; int* m_phy_write_index;
c_display* m_display; c_display* m_display;
}; };
class c_surface_no_fb : public c_surface {//No physical framebuffer, render with external graphic interface inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_driver(driver), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0)
friend class c_display; {
public: m_color_bytes = surface->m_color_bytes;
c_surface_no_fb(unsigned int width, unsigned int height, unsigned int color_bytes, struct EXTERNAL_GFX_OP* gfx_op, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : c_surface(width, height, color_bytes, max_zorder, overlpa_rect), m_gfx_op(gfx_op) {} surface->m_is_active = true;
protected: (m_surface_group[0] = surface)->attach_display(this);
virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) }
{ inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_driver(driver), m_surface_index(0)
if (!m_gfx_op)
{
return;
}
if (m_gfx_op->fill_rect)
{
return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb);
}
if (m_gfx_op->draw_pixel && m_is_active)
{
for (int y = y0; y <= y1; y++)
{
for (int x = x0; x <= x1; x++)
{
m_gfx_op->draw_pixel(x, y, rgb);
}
}
}
if (!m_fb) { return; }
if (m_color_bytes == 4)
{
unsigned int* fb;
for (int y = y0; y <= y1; y++)
{
fb = &((unsigned int*)m_fb)[y0 * m_width + x0];
for (int x = x0; x <= x1; x++)
{
*fb++ = rgb;
}
}
}
else if (m_color_bytes == 2)
{
unsigned short* fb;
rgb = GL_RGB_32_to_16(rgb);
for (int y = y0; y <= y1; y++)
{
fb = &((unsigned short*)m_fb)[y0 * m_width + x0];
for (int x = x0; x <= x1; x++)
{
*fb++ = rgb;
}
}
}
}
virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb)
{
if (m_gfx_op && m_gfx_op->draw_pixel && m_is_active)
{
m_gfx_op->draw_pixel(x, y, rgb);
}
if (!m_fb) { return; }
if (m_color_bytes == 4)
{
((unsigned int*)m_fb)[y * m_width + x] = rgb;
}
else if (m_color_bytes == 2)
{
((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb);
}
}
struct EXTERNAL_GFX_OP* m_gfx_op;//Rendering by external method
};
inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op) : m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_surface_index(0)
{ {
ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(color_bytes == 2 || color_bytes == 4);
ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX);
@ -726,16 +696,10 @@ inline c_display::c_display(void* phy_fb, int display_width, int display_height,
for (int i = 0; i < m_surface_cnt; i++) for (int i = 0; i < m_surface_cnt; i++)
{ {
m_surface_group[i] = (phy_fb) ? new c_surface(surface_width, surface_height, color_bytes) : new c_surface_no_fb(surface_width, surface_height, color_bytes, gfx_op); m_surface_group[i] = new c_surface(surface_width, surface_height, color_bytes);
m_surface_group[i]->attach_display(this); m_surface_group[i]->attach_display(this);
} }
} }
inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface) : m_width(display_width), m_height(display_height), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0)
{
m_color_bytes = surface->m_color_bytes;
surface->m_is_active = true;
(m_surface_group[0] = surface)->attach_display(this);
}
inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect) inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect)
{ {
ASSERT(max_zorder < Z_ORDER_LEVEL_MAX && m_surface_index < m_surface_cnt); ASSERT(max_zorder < Z_ORDER_LEVEL_MAX && m_surface_index < m_surface_cnt);
@ -744,8 +708,8 @@ inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect laye
} }
inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset) inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset)
{ {
int surface_width = s0->get_width(); register int surface_width = s0->m_width;
int surface_height = s0->get_height(); register int surface_height = s0->m_height;
if (offset < 0 || offset > surface_width || y0 < 0 || y0 >= surface_height || if (offset < 0 || offset > surface_width || y0 < 0 || y0 >= surface_height ||
y1 < 0 || y1 >= surface_height || x0 < 0 || x0 >= surface_width || x1 < 0 || x1 >= surface_width) y1 < 0 || y1 >= surface_height || x0 < 0 || x0 >= surface_width || x1 < 0 || x1 >= surface_width)
{ {
@ -767,35 +731,18 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1
for (int y = y0; y <= y1; y++) for (int y = y0; y <= y1; y++)
{ {
//Left surface //Left surface
char* addr_s = ((char*)(s0->m_fb) + (y * (s0->get_width()) + x0 + offset) * m_color_bytes); char* addr_s = ((char*)(s0->m_fb) + (y * surface_width + x0 + offset) * m_color_bytes);
char* addr_d = ((char*)(m_phy_fb)+(y * m_width + x0) * m_color_bytes); char* addr_d = ((char*)(m_phy_fb)+(y * m_width + x0) * m_color_bytes);
memcpy(addr_d, addr_s, (width - offset) * m_color_bytes); memcpy(addr_d, addr_s, (width - offset) * m_color_bytes);
//Right surface //Right surface
addr_s = ((char*)(s1->m_fb) + (y * (s1->get_width()) + x0) * m_color_bytes); addr_s = ((char*)(s1->m_fb) + (y * surface_width + x0) * m_color_bytes);
addr_d = ((char*)(m_phy_fb)+(y * m_width + x0 + (width - offset)) * m_color_bytes); addr_d = ((char*)(m_phy_fb)+(y * m_width + x0 + (width - offset)) * m_color_bytes);
memcpy(addr_d, addr_s, offset * m_color_bytes); memcpy(addr_d, addr_s, offset * m_color_bytes);
} }
} }
else if (m_color_bytes == 4)
{
void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel;
for (int y = y0; y <= y1; y++)
{
//Left surface
for (int x = x0; x <= (x1 - offset); x++)
{
draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]);
}
//Right surface
for (int x = x1 - offset; x <= x1; x++)
{
draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]);
}
}
}
else if (m_color_bytes == 2) else if (m_color_bytes == 2)
{ {
void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel;
for (int y = y0; y <= y1; y++) for (int y = y0; y <= y1; y++)
{ {
//Left surface //Left surface
@ -810,6 +757,23 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1
} }
} }
} }
else //m_color_bytes == 3/4...
{
void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel;
for (int y = y0; y <= y1; y++)
{
//Left surface
for (int x = x0; x <= (x1 - offset); x++)
{
draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]);
}
//Right surface
for (int x = x1 - offset; x <= x1; x++)
{
draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]);
}
}
}
m_phy_write_index++; m_phy_write_index++;
return 0; return 0;
} }
@ -3407,21 +3371,11 @@ private:
#ifdef GUILITE_ON #ifdef GUILITE_ON
c_bitmap_operator the_bitmap_op = c_bitmap_operator(); c_bitmap_operator the_bitmap_op = c_bitmap_operator();
c_image_operator* c_image::image_operator = &the_bitmap_op; c_image_operator* c_image::image_operator = &the_bitmap_op;
#endif
#ifdef GUILITE_ON
const void* c_theme::s_font_map[FONT_MAX]; const void* c_theme::s_font_map[FONT_MAX];
const void* c_theme::s_image_map[IMAGE_MAX]; const void* c_theme::s_image_map[IMAGE_MAX];
unsigned int c_theme::s_color_map[COLOR_MAX]; unsigned int c_theme::s_color_map[COLOR_MAX];
#endif
#ifdef GUILITE_ON
c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); c_lattice_font_op the_lattice_font_op = c_lattice_font_op();
c_font_operator* c_word::fontOperator = &the_lattice_font_op; c_font_operator* c_word::fontOperator = &the_lattice_font_op;
#endif #endif
#ifdef GUILITE_ON #ifdef GUILITE_ON
#if (defined __linux__) || (defined __APPLE__) #if (defined __linux__) || (defined __APPLE__)
@ -4264,11 +4218,7 @@ int c_fifo::write(void* buf, int len)
#endif #endif
#ifdef GUILITE_ON #ifdef GUILITE_ON
DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX];
#endif
#ifdef GUILITE_ON
c_keyboard c_edit::s_keyboard; c_keyboard c_edit::s_keyboard;
#endif
#ifdef GUILITE_ON
static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9;
static c_keyboard_button s_key_A, s_key_B, s_key_C, s_key_D, s_key_E, s_key_F, s_key_G, s_key_H, s_key_I, s_key_J; static c_keyboard_button s_key_A, s_key_B, s_key_C, s_key_D, s_key_E, s_key_F, s_key_G, s_key_H, s_key_I, s_key_J;
static c_keyboard_button s_key_K, s_key_L, s_key_M, s_key_N, s_key_O, s_key_P, s_key_Q, s_key_R, s_key_S, s_key_T; static c_keyboard_button s_key_K, s_key_L, s_key_M, s_key_N, s_key_O, s_key_P, s_key_Q, s_key_R, s_key_S, s_key_T;
@ -4306,12 +4256,12 @@ WND_TREE g_key_board_children[] =
{&s_key_B, 'B', 0, ((KEY_WIDTH / 2) + POS_X(5)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_B, 'B', 0, ((KEY_WIDTH / 2) + POS_X(5)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT},
{&s_key_N, 'N', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_N, 'N', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT},
{&s_key_M, 'M', 0, ((KEY_WIDTH / 2) + POS_X(7)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_M, 'M', 0, ((KEY_WIDTH / 2) + POS_X(7)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT},
{&s_key_del, 0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, {&s_key_del,0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT},
//Row 4 //Row 4
{&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT},
{&s_key_num_switch, 0x90, 0, POS_X(2), POS_Y(3), SWITCH_WIDTH, KEY_HEIGHT}, {&s_key_num_switch, 0x90, 0, POS_X(2), POS_Y(3), SWITCH_WIDTH, KEY_HEIGHT},
{&s_key_space, ' ', 0, ((KEY_WIDTH / 2) + POS_X(3)), POS_Y(3), SPACE_WIDTH, KEY_HEIGHT}, {&s_key_space, ' ', 0, ((KEY_WIDTH / 2) + POS_X(3)), POS_Y(3), SPACE_WIDTH, KEY_HEIGHT},
{&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT},
{&s_key_enter, '\n', 0, POS_X(8), POS_Y(3), ENTER_WIDTH, KEY_HEIGHT}, {&s_key_enter, '\n', 0, POS_X(8), POS_Y(3), ENTER_WIDTH, KEY_HEIGHT},
{0,0,0,0,0,0,0} {0,0,0,0,0,0,0}
}; };
@ -4326,10 +4276,9 @@ WND_TREE g_number_board_children[] =
{&s_key_7, '7', 0, POS_X(0), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_7, '7', 0, POS_X(0), POS_Y(2), KEY_WIDTH, KEY_HEIGHT},
{&s_key_8, '8', 0, POS_X(1), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_8, '8', 0, POS_X(1), POS_Y(2), KEY_WIDTH, KEY_HEIGHT},
{&s_key_9, '9', 0, POS_X(2), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_9, '9', 0, POS_X(2), POS_Y(2), KEY_WIDTH, KEY_HEIGHT},
{&s_key_esc,0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT},
{&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT},
{&s_key_0, '0', 0, POS_X(1), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_0, '0', 0, POS_X(1), POS_Y(3), KEY_WIDTH, KEY_HEIGHT},
{&s_key_dot, '.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_dot,'.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT},
{&s_key_del, 0x7F, 0, POS_X(3), POS_Y(0), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {&s_key_del, 0x7F, 0, POS_X(3), POS_Y(0), KEY_WIDTH, KEY_HEIGHT * 2 + 2},
{&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2},
{0,0,0,0,0,0,0} {0,0,0,0,0,0,0}

View File

@ -12,8 +12,8 @@ ADD_DEFINITIONS(-DGUILITE_ON)
FILE(GLOB CORE_SRC core/*.cpp) FILE(GLOB CORE_SRC core/*.cpp)
FILE(GLOB CORE_ADAPTER core/adapter/api_linux.cpp FILE(GLOB CORE_ADAPTER core/adapter/api_linux.cpp
core/adapter/audio_linux.cpp) core/adapter/audio_linux.cpp)
# gui # widgets
FILE(GLOB WIDGETS_SRC widgets/*.cpp) FILE(GLOB WIDGETS_SRC widgets/*.cpp)
# build static library # build static library
ADD_LIBRARY(GuiLite STATIC ${CORE_SRC} ${CORE_ADAPTER} ${WIDGETS_SRC}) ADD_LIBRARY(GuiLite STATIC ${CORE_SRC} ${CORE_ADAPTER} ${WIDGETS_SRC})

View File

@ -1,42 +1,37 @@
echo "Build header-only library: GuiLite.h" echo "Build header-only library: GuiLite.h"
# build GuiLiteRaw.h # build GuiLiteRaw.h
cd core_include cd core
cat api.h resource.h theme.h display.h word.h image.h wnd.h > core.h cat api.h resource.h theme.h display.h word.h image.h wnd.h > core.h
mv core.h ../ mv core.h ../
cd ..
cd ../widgets_include cd widgets
cat button.h dialog.h keyboard.h edit.h label.h list_box.h slide_group.h spinbox.h table.h wave_buffer.h wave_ctrl.h > widgets.h cat button.h dialog.h keyboard.h edit.h label.h list_box.h slide_group.h spinbox.h table.h wave_buffer.h wave_ctrl.h > widgets.h
mv widgets.h ../ mv widgets.h ../
cd .. cd ..
cat core.h widgets.h > GuiLiteRaw.h cat core.h widgets.h > GuiLiteRaw.h
# build GuiLiteRaw.cpp # build GuiLiteRaw.cpp
cd core cp core/core.cpp ./
cat *.cpp > core.cpp cp widgets/widgets.cpp ./
mv core.cpp ../
cd adapter cd core/adapter
cat *.cpp > adapter.cpp cat *.cpp > adapter.cpp
mv adapter.cpp ../../ mv adapter.cpp ../../
cd ../..
cd ../../widgets
cat *.cpp > widgets.cpp
mv widgets.cpp ../
cd ..
cat core.cpp adapter.cpp widgets.cpp > GuiLiteRaw.cpp cat core.cpp adapter.cpp widgets.cpp > GuiLiteRaw.cpp
# remove include core widgets from GuiLiteRaw.h
# remove include core_include widgets_include from GuiLiteRaw.h sed -i '/^#include.*core\|widgets.*/d' GuiLiteRaw.h
sed -i '/^#include.*core_include\|widgets_include.*/d' GuiLiteRaw.h
# remove all #pragma once # remove all #pragma once
sed -i '/^#pragma once/d' GuiLiteRaw.h sed -i '/^#pragma once/d' GuiLiteRaw.h
# add #pragma once for 1st line # add #pragma once for 1st line
sed -i '1 s/^/#pragma once\n/' GuiLiteRaw.h sed -i '1 s/^/#pragma once\n/' GuiLiteRaw.h
# remove include core_include widgets_include from GuiLiteRaw.cpp # remove include core widgets from GuiLiteRaw.cpp
sed -i '/^#include.*core_include\|widgets_include.*/d' GuiLiteRaw.cpp sed -i '/^#include.*core\|widgets.*/d' GuiLiteRaw.cpp
# Delete empty lines or blank lines # Delete empty lines or blank lines
sed '/^$/d' GuiLiteRaw.h > GuiLite.h sed '/^$/d' GuiLiteRaw.h > GuiLite.h
@ -52,7 +47,7 @@ gcc -c -D GUILITE_ON test.cpp
mv GuiLite.h ../ mv GuiLite.h ../
echo "Done!" echo "Done!"
echo "You could find GuiLite.h in root folder" echo "You could find GuiLite.h in root folder"
./.sync.sh GuiLite-header
# clean # clean
rm *.h *.cpp *.o rm *.h *.cpp *.o
./.sync.sh GuiLite-header

View File

@ -1,6 +0,0 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# These are explicitly windows files and should use crlf
*.bat text eol=crlf

10
src/Gradle/.gitignore vendored
View File

@ -1,10 +0,0 @@
# Ignore Gradle project-specific cache directory
.gradle
# Ignore Gradle build output directory
build
# Ignore IDEA project-specific configuration directory
.idea
.DS_Store

View File

@ -1,24 +0,0 @@
## 使用Gradle编译Guilite ###
* ### Windows平台: ###
* 兼容VS各大版本自动选择最新版本。
* 兼容Cygwin或MinGW确保gcc在path中。目前不支持Clang。
* 按`win+R`输入`cmd`打开命令行运行:`g++ -v`,有打印出版本则正常。
* 编译Guilite
```powershell
cd $GUILITE\workspace\Gradle\
gradlew produce
```
* 输出位置:$GRADLE\build\lib\main\release\shared(static)\
* ### Linux和Mac平台: ###
* 将使用系统PATH发现GCC或Clang请确保已经安装GCC或Clang。
* 打开终端运行:`g++ -v`,有打印出版本则正常。
* 编译Guilite
```shell
cd $GUILITE/workspace/Gradle/
gradlew produce
```
* 输出位置:$GRADLE/build/lib/main/release/shared(static)/
对单片机系统不了解,未支持!

View File

@ -1,36 +0,0 @@
plugins {
id("org.gradle.cpp-library")
}
library {
/**
* Gradle stipulates that the source directory is: $project/src/main/cpp/,
* specifies the `.cpp` source file directory according to the project.
* */
source.from(
"../core",
"../widgets"
)
/**
* Gradle conventions the header file directory is: $project/src/main/headers/,
* specify the `.h` header file directory according to the project.
*/
privateHeaders.from(
"../core_include",
"../widgets_include"
)
/**
* Gradle only exports shared libraries(dynamic libraries) by default,
* adds support for static libraries.
* */
linkage.add(Linkage.STATIC)
}
/**
* Compile tasks for custom release type dynamic and static libraries
* */
tasks.register("produce") {
dependsOn(
"assembleReleaseShared",
"assembleReleaseStatic"
)
}

Binary file not shown.

View File

@ -1,6 +0,0 @@
#Thu Jan 23 20:09:34 CST 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

183
src/Gradle/gradlew vendored
View File

@ -1,183 +0,0 @@
#!/usr/bin/env sh
#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=`expr $i + 1`
done
case $i in
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=`save "$@"`
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
exec "$JAVACMD" "$@"

100
src/Gradle/gradlew.bat vendored
View File

@ -1,100 +0,0 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

View File

@ -1 +0,0 @@
rootProject.name = "GuiLite"

View File

@ -382,35 +382,15 @@
<Group> <Group>
<GroupName>core</GroupName> <GroupName>core</GroupName>
<Files> <Files>
<File>
<FileName>display.cpp</FileName>
<FileType>8</FileType>
<FilePath>.\core\display.cpp</FilePath>
</File>
<File>
<FileName>theme.cpp</FileName>
<FileType>8</FileType>
<FilePath>.\core\theme.cpp</FilePath>
</File>
<File>
<FileName>wnd.cpp</FileName>
<FileType>8</FileType>
<FilePath>.\core\wnd.cpp</FilePath>
</File>
<File>
<FileName>word.cpp</FileName>
<FileType>8</FileType>
<FilePath>.\core\word.cpp</FilePath>
</File>
<File> <File>
<FileName>api_unknow.cpp</FileName> <FileName>api_unknow.cpp</FileName>
<FileType>8</FileType> <FileType>8</FileType>
<FilePath>.\core\adapter\api_unknow.cpp</FilePath> <FilePath>.\core\adapter\api_unknow.cpp</FilePath>
</File> </File>
<File> <File>
<FileName>image.cpp</FileName> <FileName>core.cpp</FileName>
<FileType>8</FileType> <FileType>8</FileType>
<FilePath>.\core\image.cpp</FilePath> <FilePath>.\core\core.cpp</FilePath>
</File> </File>
</Files> </Files>
</Group> </Group>
@ -418,24 +398,9 @@
<GroupName>widgets</GroupName> <GroupName>widgets</GroupName>
<Files> <Files>
<File> <File>
<FileName>button.cpp</FileName> <FileName>widgets.cpp</FileName>
<FileType>8</FileType> <FileType>8</FileType>
<FilePath>.\widgets\button.cpp</FilePath> <FilePath>.\widgets\widgets.cpp</FilePath>
</File>
<File>
<FileName>label.cpp</FileName>
<FileType>8</FileType>
<FilePath>.\widgets\label.cpp</FilePath>
</File>
<File>
<FileName>wave_buffer.cpp</FileName>
<FileType>8</FileType>
<FilePath>.\widgets\wave_buffer.cpp</FilePath>
</File>
<File>
<FileName>wave_ctrl.cpp</FileName>
<FileType>8</FileType>
<FilePath>.\widgets\wave_ctrl.cpp</FilePath>
</File> </File>
</Files> </Files>
</Group> </Group>

View File

@ -182,7 +182,8 @@
<AdditionalOptions>%(AdditionalOptions) /machine:X64</AdditionalOptions> <AdditionalOptions>%(AdditionalOptions) /machine:X64</AdditionalOptions>
</Lib> </Lib>
<PostBuildEvent> <PostBuildEvent>
<Command>call "$(SolutionDir)sync_build.bat" "GuiLite"</Command> <Command>
</Command>
</PostBuildEvent> </PostBuildEvent>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@ -389,22 +390,28 @@
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="core\adapter\api_win.cpp" /> <ClCompile Include="core\adapter\api_win.cpp" />
<ClCompile Include="core\display.cpp" /> <ClCompile Include="core\core.cpp" />
<ClCompile Include="core\image.cpp" /> <ClCompile Include="widgets\widgets.cpp" />
<ClCompile Include="core\theme.cpp" /> </ItemGroup>
<ClCompile Include="core\wnd.cpp" /> <ItemGroup>
<ClCompile Include="core\word.cpp" /> <ClInclude Include="core\api.h" />
<ClCompile Include="widgets\button.cpp" /> <ClInclude Include="core\display.h" />
<ClCompile Include="widgets\dialog.cpp" /> <ClInclude Include="core\image.h" />
<ClCompile Include="widgets\edit.cpp" /> <ClInclude Include="core\resource.h" />
<ClCompile Include="widgets\keyboard.cpp" /> <ClInclude Include="core\theme.h" />
<ClCompile Include="widgets\label.cpp" /> <ClInclude Include="core\wnd.h" />
<ClCompile Include="widgets\list_box.cpp" /> <ClInclude Include="core\word.h" />
<ClCompile Include="widgets\slide_group.cpp" /> <ClInclude Include="widgets\button.h" />
<ClCompile Include="widgets\spinbox.cpp" /> <ClInclude Include="widgets\dialog.h" />
<ClCompile Include="widgets\table.cpp" /> <ClInclude Include="widgets\edit.h" />
<ClCompile Include="widgets\wave_buffer.cpp" /> <ClInclude Include="widgets\keyboard.h" />
<ClCompile Include="widgets\wave_ctrl.cpp" /> <ClInclude Include="widgets\label.h" />
<ClInclude Include="widgets\list_box.h" />
<ClInclude Include="widgets\slide_group.h" />
<ClInclude Include="widgets\spinbox.h" />
<ClInclude Include="widgets\table.h" />
<ClInclude Include="widgets\wave_buffer.h" />
<ClInclude Include="widgets\wave_ctrl.h" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">

View File

@ -1,55 +1,13 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup> <ItemGroup>
<ClCompile Include="widgets\button.cpp"> <ClCompile Include="widgets\widgets.cpp">
<Filter>widgets</Filter> <Filter>widgets</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="widgets\dialog.cpp">
<Filter>widgets</Filter>
</ClCompile>
<ClCompile Include="widgets\edit.cpp">
<Filter>widgets</Filter>
</ClCompile>
<ClCompile Include="widgets\keyboard.cpp">
<Filter>widgets</Filter>
</ClCompile>
<ClCompile Include="widgets\label.cpp">
<Filter>widgets</Filter>
</ClCompile>
<ClCompile Include="widgets\list_box.cpp">
<Filter>widgets</Filter>
</ClCompile>
<ClCompile Include="widgets\slide_group.cpp">
<Filter>widgets</Filter>
</ClCompile>
<ClCompile Include="widgets\spinbox.cpp">
<Filter>widgets</Filter>
</ClCompile>
<ClCompile Include="widgets\table.cpp">
<Filter>widgets</Filter>
</ClCompile>
<ClCompile Include="widgets\wave_buffer.cpp">
<Filter>widgets</Filter>
</ClCompile>
<ClCompile Include="widgets\wave_ctrl.cpp">
<Filter>widgets</Filter>
</ClCompile>
<ClCompile Include="core\display.cpp">
<Filter>core</Filter>
</ClCompile>
<ClCompile Include="core\theme.cpp">
<Filter>core</Filter>
</ClCompile>
<ClCompile Include="core\wnd.cpp">
<Filter>core</Filter>
</ClCompile>
<ClCompile Include="core\word.cpp">
<Filter>core</Filter>
</ClCompile>
<ClCompile Include="core\adapter\api_win.cpp"> <ClCompile Include="core\adapter\api_win.cpp">
<Filter>core\adapter</Filter> <Filter>core\adapter</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="core\image.cpp"> <ClCompile Include="core\core.cpp">
<Filter>core</Filter> <Filter>core</Filter>
</ClCompile> </ClCompile>
</ItemGroup> </ItemGroup>
@ -64,4 +22,60 @@
<UniqueIdentifier>{691801eb-7076-4af6-aa0c-5ce5b0fcb21c}</UniqueIdentifier> <UniqueIdentifier>{691801eb-7076-4af6-aa0c-5ce5b0fcb21c}</UniqueIdentifier>
</Filter> </Filter>
</ItemGroup> </ItemGroup>
<ItemGroup>
<ClInclude Include="core\api.h">
<Filter>core</Filter>
</ClInclude>
<ClInclude Include="core\display.h">
<Filter>core</Filter>
</ClInclude>
<ClInclude Include="core\image.h">
<Filter>core</Filter>
</ClInclude>
<ClInclude Include="core\resource.h">
<Filter>core</Filter>
</ClInclude>
<ClInclude Include="core\theme.h">
<Filter>core</Filter>
</ClInclude>
<ClInclude Include="core\wnd.h">
<Filter>core</Filter>
</ClInclude>
<ClInclude Include="core\word.h">
<Filter>core</Filter>
</ClInclude>
<ClInclude Include="widgets\button.h">
<Filter>widgets</Filter>
</ClInclude>
<ClInclude Include="widgets\dialog.h">
<Filter>widgets</Filter>
</ClInclude>
<ClInclude Include="widgets\edit.h">
<Filter>widgets</Filter>
</ClInclude>
<ClInclude Include="widgets\keyboard.h">
<Filter>widgets</Filter>
</ClInclude>
<ClInclude Include="widgets\label.h">
<Filter>widgets</Filter>
</ClInclude>
<ClInclude Include="widgets\list_box.h">
<Filter>widgets</Filter>
</ClInclude>
<ClInclude Include="widgets\slide_group.h">
<Filter>widgets</Filter>
</ClInclude>
<ClInclude Include="widgets\spinbox.h">
<Filter>widgets</Filter>
</ClInclude>
<ClInclude Include="widgets\table.h">
<Filter>widgets</Filter>
</ClInclude>
<ClInclude Include="widgets\wave_buffer.h">
<Filter>widgets</Filter>
</ClInclude>
<ClInclude Include="widgets\wave_ctrl.h">
<Filter>widgets</Filter>
</ClInclude>
</ItemGroup>
</Project> </Project>

View File

@ -1,7 +1,7 @@
#ifdef GUILITE_ON #ifdef GUILITE_ON
#if (defined __linux__) || (defined __APPLE__) #if (defined __linux__) || (defined __APPLE__)
#include "../../core_include/api.h" #include "../../core/api.h"
#include <unistd.h> #include <unistd.h>
#include <pthread.h> #include <pthread.h>
#include <string.h> #include <string.h>

View File

@ -1,7 +1,7 @@
#ifdef GUILITE_ON #ifdef GUILITE_ON
#if (!defined _WIN32) && (!defined WIN32) && (!defined _WIN64) && (!defined WIN64) && (!defined __linux__) && (!defined __APPLE__) #if (!defined _WIN32) && (!defined WIN32) && (!defined _WIN64) && (!defined WIN64) && (!defined __linux__) && (!defined __APPLE__)
#include "../../core_include/api.h" #include "../../core/api.h"
#include <stdio.h> #include <stdio.h>
static void(*do_assert)(const char* file, int line); static void(*do_assert)(const char* file, int line);

View File

@ -1,7 +1,7 @@
#ifdef GUILITE_ON #ifdef GUILITE_ON
#if (defined _WIN32) || (defined WIN32) || (defined _WIN64) || (defined WIN64) #if (defined _WIN32) || (defined WIN32) || (defined _WIN64) || (defined WIN64)
#include "../../core_include/api.h" #include "../../core/api.h"
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>

17
src/core/core.cpp Normal file
View File

@ -0,0 +1,17 @@
#include "../core/display.h"
#include "../core//image.h"
#include "../core/theme.h"
#include "../core/wnd.h"
#include "../core/word.h"
#ifdef GUILITE_ON
c_bitmap_operator the_bitmap_op = c_bitmap_operator();
c_image_operator* c_image::image_operator = &the_bitmap_op;
const void* c_theme::s_font_map[FONT_MAX];
const void* c_theme::s_image_map[IMAGE_MAX];
unsigned int c_theme::s_color_map[COLOR_MAX];
c_lattice_font_op the_lattice_font_op = c_lattice_font_op();
c_font_operator* c_word::fontOperator = &the_lattice_font_op;
#endif

View File

@ -1 +0,0 @@
#include "../core_include/display.h"

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "../core_include/api.h" #include "../core/api.h"
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -15,7 +15,7 @@ typedef enum
Z_ORDER_LEVEL_MAX Z_ORDER_LEVEL_MAX
}Z_ORDER_LEVEL; }Z_ORDER_LEVEL;
struct EXTERNAL_GFX_OP struct DISPLAY_DRIVER
{ {
void(*draw_pixel)(int x, int y, unsigned int rgb); void(*draw_pixel)(int x, int y, unsigned int rgb);
void(*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); void(*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb);
@ -25,19 +25,20 @@ class c_surface;
class c_display { class c_display {
friend class c_surface; friend class c_surface;
public: public:
inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface or surface_no_fb inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver = 0);//single custom surface
inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface);//single custom surface inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver = 0);//multiple surface
inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for multiple surfaces inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for slide group
inline int swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset); inline int swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset);
int get_width() { return m_width; } int get_width() { return m_width; }
int get_height() { return m_height; } int get_height() { return m_height; }
void* get_phy_fb() { return m_phy_fb; }
void* get_updated_fb(int* width, int* height, bool force_update = false) void* get_updated_fb(int* width, int* height, bool force_update = false)
{ {
if (width && height) if (width && height)
{ {
*width = get_width(); *width = m_width;
*height = get_height(); *height = m_height;
} }
if (force_update) if (force_update)
{ {
@ -58,40 +59,138 @@ public:
return -1; return -1;
} }
int width = get_width();
int height = get_height();
//16 bits framebuffer //16 bits framebuffer
if (m_color_bytes == 2) if (m_color_bytes == 2)
{ {
return build_bmp(file_name, width, height, (unsigned char*)m_phy_fb); return build_bmp(file_name, m_width, m_height, (unsigned char*)m_phy_fb);
} }
//32 bits framebuffer //32 bits framebuffer
unsigned short* p_bmp565_data = new unsigned short[width * height]; unsigned short* p_bmp565_data = new unsigned short[m_width * m_height];
unsigned int* p_raw_data = (unsigned int*)m_phy_fb; unsigned int* p_raw_data = (unsigned int*)m_phy_fb;
for (int i = 0; i < width * height; i++) for (int i = 0; i < m_width * m_height; i++)
{ {
unsigned int rgb = *p_raw_data++; unsigned int rgb = *p_raw_data++;
p_bmp565_data[i] = GL_RGB_32_to_16(rgb); p_bmp565_data[i] = GL_RGB_32_to_16(rgb);
} }
int ret = build_bmp(file_name, width, height, (unsigned char*)p_bmp565_data); int ret = build_bmp(file_name, m_width, m_height, (unsigned char*)p_bmp565_data);
delete[]p_bmp565_data; delete[]p_bmp565_data;
return ret; return ret;
} }
private: protected:
int m_width; //in pixels virtual void draw_pixel(int x, int y, unsigned int rgb)
int m_height; //in pixels {
int m_color_bytes; //16 bits, 32 bits only if ((x >= m_width) || (y >= m_height)) { return; }
void* m_phy_fb; //physical framebuffer
if (m_driver && m_driver->draw_pixel)
{
return m_driver->draw_pixel(x, y, rgb);
}
if (m_color_bytes == 2)
{
((unsigned short*)m_phy_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb);
}
else
{
((unsigned int*)m_phy_fb)[y * m_width + x] = rgb;
}
}
virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb)
{
if (m_driver && m_driver->fill_rect)
{
return m_driver->fill_rect(x0, y0, x1, y1, rgb);
}
if (m_driver && m_driver->draw_pixel)
{
for (int y = y0; y <= y1; y++)
{
for (int x = x0; x <= x1; x++)
{
m_driver->draw_pixel(x, y, rgb);
}
}
return;
}
register int _width = m_width;
register int _height = m_height;
int x, y;
if (m_color_bytes == 2)
{
unsigned short* phy_fb;
unsigned int rgb_16 = GL_RGB_32_to_16(rgb);
for (y = y0; y <= y1; y++)
{
phy_fb = &((unsigned short*)m_phy_fb)[y * _width + x0];
for (x = x0; x <= x1; x++)
{
if ((x < _width) && (y < _height))
{
*phy_fb++ = rgb_16;
}
}
}
}
else
{
unsigned int* phy_fb;
for (y = y0; y <= y1; y++)
{
phy_fb = &((unsigned int*)m_phy_fb)[y * _width + x0];
for (x = x0; x <= x1; x++)
{
if ((x < _width) && (y < _height))
{
*phy_fb++ = rgb;
}
}
}
}
}
virtual int flush_screen(int left, int top, int right, int bottom, void* fb, int fb_width)
{
if ((0 == m_phy_fb) || (0 == fb))
{
return -1;
}
register int _width = m_width;
register int _height = m_height;
left = (left >= _width) ? (_width - 1) : left;
right = (right >= _width) ? (_width - 1) : right;
top = (top >= _height) ? (_height - 1) : top;
bottom = (bottom >= _height) ? (_height - 1) : bottom;
for (int y = top; y < bottom; y++)
{
void* s_addr = (char*)fb + ((y * fb_width + left) * m_color_bytes);
void* d_addr = (char*)m_phy_fb + ((y * _width + left) * m_color_bytes);
memcpy(d_addr, s_addr, (right - left) * m_color_bytes);
}
return 0;
}
int m_width; //in pixels
int m_height; //in pixels
int m_color_bytes; //16/32 bits for default
void* m_phy_fb; //physical framebuffer for default
struct DISPLAY_DRIVER* m_driver; //Rendering by external method without default physical framebuffer
int m_phy_read_index; int m_phy_read_index;
int m_phy_write_index; int m_phy_write_index;
c_surface* m_surface_group[SURFACE_CNT_MAX]; c_surface* m_surface_group[SURFACE_CNT_MAX];
int m_surface_cnt; //surface count int m_surface_cnt; //surface count
int m_surface_index; int m_surface_index;
}; };
class c_layer class c_layer
@ -105,14 +204,11 @@ public:
class c_surface { class c_surface {
friend class c_display; friend class c_bitmap_operator; friend class c_display; friend class c_bitmap_operator;
public: public:
c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_fb(0), m_phy_write_index(0), m_display(0) c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_write_index(0), m_display(0)
{ {
(overlpa_rect == c_rect()) ? set_surface(max_zorder, c_rect(0, 0, width - 1, height - 1)) : set_surface(max_zorder, overlpa_rect); (overlpa_rect == c_rect()) ? set_surface(max_zorder, c_rect(0, 0, width - 1, height - 1)) : set_surface(max_zorder, overlpa_rect);
} }
int get_width() { return m_width; }
int get_height() { return m_height; }
unsigned int get_pixel(int x, int y, unsigned int z_order) unsigned int get_pixel(int x, int y, unsigned int z_order)
{ {
if (x >= m_width || y >= m_height || x < 0 || y < 0 || z_order >= Z_ORDER_LEVEL_MAX) if (x >= m_width || y >= m_height || x < 0 || y < 0 || z_order >= Z_ORDER_LEVEL_MAX)
@ -122,15 +218,15 @@ public:
} }
if (m_layers[z_order].fb) if (m_layers[z_order].fb)
{ {
return (m_color_bytes == 4) ? ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]); return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]) : ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x];
} }
else if (m_fb) else if (m_fb)
{ {
return (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]); return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]) : ((unsigned int*)m_fb)[y * m_width + x];
} }
else if (m_phy_fb) else if (m_display->m_phy_fb)
{ {
return (m_color_bytes == 4) ? ((unsigned int*)m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_phy_fb)[y * m_width + x]); return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]) : ((unsigned int*)m_display->m_phy_fb)[y * m_width + x];
} }
return 0; return 0;
} }
@ -149,7 +245,7 @@ public:
if (z_order == m_max_zorder) if (z_order == m_max_zorder)
{ {
return draw_pixel_on_fb(x, y, rgb); return draw_pixel_low_level(x, y, rgb);
} }
if (z_order > (unsigned int)m_top_zorder) if (z_order > (unsigned int)m_top_zorder)
@ -160,19 +256,19 @@ public:
if (m_layers[z_order].rect.pt_in_rect(x, y)) if (m_layers[z_order].rect.pt_in_rect(x, y))
{ {
c_rect layer_rect = m_layers[z_order].rect; c_rect layer_rect = m_layers[z_order].rect;
if (m_color_bytes == 4) if (m_color_bytes == 2)
{ {
((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb);
} }
else else
{ {
((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb;
} }
} }
if (z_order == m_top_zorder) if (z_order == m_top_zorder)
{ {
return draw_pixel_on_fb(x, y, rgb); return draw_pixel_low_level(x, y, rgb);
} }
bool be_overlapped = false; bool be_overlapped = false;
@ -187,7 +283,7 @@ public:
if (!be_overlapped) if (!be_overlapped)
{ {
draw_pixel_on_fb(x, y, rgb); draw_pixel_low_level(x, y, rgb);
} }
} }
@ -200,7 +296,7 @@ public:
if (z_order == m_max_zorder) if (z_order == m_max_zorder)
{ {
return fill_rect_on_fb(x0, y0, x1, y1, rgb); return fill_rect_low_level(x0, y0, x1, y1, rgb);
} }
if (z_order == m_top_zorder) if (z_order == m_top_zorder)
@ -214,18 +310,18 @@ public:
{ {
if (layer_rect.pt_in_rect(x, y)) if (layer_rect.pt_in_rect(x, y))
{ {
if (m_color_bytes == 4) if (m_color_bytes == 2)
{ {
((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16;
} }
else else
{ {
((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb;
} }
} }
} }
} }
return fill_rect_on_fb(x0, y0, x1, y1, rgb); return fill_rect_low_level(x0, y0, x1, y1, rgb);
} }
for (; y0 <= y1; y0++) for (; y0 <= y1; y0++)
@ -308,31 +404,18 @@ public:
int flush_screen(int left, int top, int right, int bottom) int flush_screen(int left, int top, int right, int bottom)
{ {
if (!m_is_active)
{
return -1;
}
if (left < 0 || left >= m_width || right < 0 || right >= m_width || if (left < 0 || left >= m_width || right < 0 || right >= m_width ||
top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) top < 0 || top >= m_height || bottom < 0 || bottom >= m_height)
{ {
ASSERT(false); ASSERT(false);
} }
if (!m_is_active || (0 == m_phy_fb) || (0 == m_fb)) m_display->flush_screen(left, top, right, bottom, m_fb, m_width);
{
return -1;
}
int display_width = m_display->get_width();
int display_height = m_display->get_height();
left = (left >= display_width) ? (display_width - 1) : left;
right = (right >= display_width) ? (display_width - 1) : right;
top = (top >= display_height) ? (display_height - 1) : top;
bottom = (bottom >= display_height) ? (display_height - 1) : bottom;
for (int y = top; y < bottom; y++)
{
void* s_addr = (char*)m_fb + ((y * m_width + left) * m_color_bytes);
void* d_addr = (char*)m_phy_fb + ((y * display_width + left) * m_color_bytes);
memcpy(d_addr, s_addr, (right - left) * m_color_bytes);
}
*m_phy_write_index = *m_phy_write_index + 1; *m_phy_write_index = *m_phy_write_index + 1;
return 0; return 0;
} }
@ -354,94 +437,65 @@ public:
{ {
for (int x = rect.m_left; x <= rect.m_right; x++) for (int x = rect.m_left; x <= rect.m_right; x++)
{ {
unsigned int rgb = (m_color_bytes == 4) ? ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width] : GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]); unsigned int rgb = (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]) : ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width];
draw_pixel_on_fb(x, y, rgb); draw_pixel_low_level(x, y, rgb);
} }
} }
return 0; return 0;
} }
void set_active(bool flag) { m_is_active = flag; } void set_active(bool flag) { m_is_active = flag; }
protected: protected:
virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) virtual void fill_rect_low_level(int x0, int y0, int x1, int y1, unsigned int rgb)
{ {//fill rect on framebuffer of surface
int display_width = m_display->get_width(); int x, y;
int display_height = m_display->get_height(); if (m_color_bytes == 2)
{
unsigned short* fb;
unsigned int rgb_16 = GL_RGB_32_to_16(rgb);
for (y = y0; y <= y1; y++)
{
fb = m_fb ? &((unsigned short*)m_fb)[y * m_width + x0] : 0;
if (!fb) { break; }
for (x = x0; x <= x1; x++)
{
*fb++ = rgb_16;
}
}
}
else
{
unsigned int* fb;
for (y = y0; y <= y1; y++)
{
fb = m_fb ? &((unsigned int*)m_fb)[y * m_width + x0] : 0;
if (!fb) { break; }
for (x = x0; x <= x1; x++)
{
*fb++ = rgb;
}
}
}
if (m_color_bytes == 4) if (!m_is_active) { return; }
{ m_display->fill_rect(x0, y0, x1, y1, rgb);
int x; *m_phy_write_index = *m_phy_write_index + 1;
unsigned int* fb, * phy_fb;
for (; y0 <= y1; y0++)
{
x = x0;
fb = m_fb ? &((unsigned int*)m_fb)[y0 * m_width + x] : 0;
phy_fb = &((unsigned int*)m_phy_fb)[y0 * display_width + x];
*m_phy_write_index = *m_phy_write_index + 1;
for (; x <= x1; x++)
{
if (fb)
{
*fb++ = rgb;
}
if (m_is_active && (x < display_width) && (y0 < display_height))
{
*phy_fb++ = rgb;
}
}
}
}
else if (m_color_bytes == 2)
{
int x;
unsigned short* fb, * phy_fb;
rgb = GL_RGB_32_to_16(rgb);
for (; y0 <= y1; y0++)
{
x = x0;
fb = m_fb ? &((unsigned short*)m_fb)[y0 * m_width + x] : 0;
phy_fb = &((unsigned short*)m_phy_fb)[y0 * display_width + x];
*m_phy_write_index = *m_phy_write_index + 1;
for (; x <= x1; x++)
{
if (fb)
{
*fb++ = rgb;
}
if (m_is_active && (x < display_width) && (y0 < display_height))
{
*phy_fb++ = rgb;
}
}
}
}
} }
virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) virtual void draw_pixel_low_level(int x, int y, unsigned int rgb)
{ {
if (m_fb) if (m_fb)
{ {//draw pixel on framebuffer of surface
(m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] = rgb : ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); (m_color_bytes == 2) ? ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb): ((unsigned int*)m_fb)[y * m_width + x] = rgb;
}
if (m_is_active && (x < m_display->get_width()) && (y < m_display->get_height()))
{
if (m_color_bytes == 4)
{
((unsigned int*)m_phy_fb)[y * (m_display->get_width()) + x] = rgb;
}
else
{
((unsigned short*)m_phy_fb)[y * (m_display->get_width()) + x] = GL_RGB_32_to_16(rgb);
}
*m_phy_write_index = *m_phy_write_index + 1;
} }
if (!m_is_active) { return; }
m_display->draw_pixel(x, y, rgb);
*m_phy_write_index = *m_phy_write_index + 1;
} }
void attach_display(c_display* display) void attach_display(c_display* display)
{ {
ASSERT(display); ASSERT(display);
m_display = display; m_display = display;
m_phy_fb = display->m_phy_fb;
m_phy_write_index = &display->m_phy_write_index; m_phy_write_index = &display->m_phy_write_index;
} }
@ -462,93 +516,24 @@ protected:
int m_width; //in pixels int m_width; //in pixels
int m_height; //in pixels int m_height; //in pixels
int m_color_bytes; //16 bits, 32 bits only int m_color_bytes; //16 bits, 32 bits for default
void* m_fb; //frame buffer you could see void* m_fb; //frame buffer you could see
c_layer m_layers[Z_ORDER_LEVEL_MAX];//all graphic layers c_layer m_layers[Z_ORDER_LEVEL_MAX];//all graphic layers
bool m_is_active; //active flag bool m_is_active; //active flag
Z_ORDER_LEVEL m_max_zorder; //the highest graphic layer the surface will have Z_ORDER_LEVEL m_max_zorder; //the highest graphic layer the surface will have
Z_ORDER_LEVEL m_top_zorder; //the current highest graphic layer the surface have Z_ORDER_LEVEL m_top_zorder; //the current highest graphic layer the surface have
void* m_phy_fb; //physical framebufer
int* m_phy_write_index; int* m_phy_write_index;
c_display* m_display; c_display* m_display;
}; };
class c_surface_no_fb : public c_surface {//No physical framebuffer, render with external graphic interface inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_driver(driver), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0)
friend class c_display; {
public: m_color_bytes = surface->m_color_bytes;
c_surface_no_fb(unsigned int width, unsigned int height, unsigned int color_bytes, struct EXTERNAL_GFX_OP* gfx_op, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : c_surface(width, height, color_bytes, max_zorder, overlpa_rect), m_gfx_op(gfx_op) {} surface->m_is_active = true;
protected: (m_surface_group[0] = surface)->attach_display(this);
virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) }
{
if (!m_gfx_op)
{
return;
}
if (m_gfx_op->fill_rect)
{
return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb);
}
if (m_gfx_op->draw_pixel && m_is_active) inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_driver(driver), m_surface_index(0)
{
for (int y = y0; y <= y1; y++)
{
for (int x = x0; x <= x1; x++)
{
m_gfx_op->draw_pixel(x, y, rgb);
}
}
}
if (!m_fb) { return; }
if (m_color_bytes == 4)
{
unsigned int* fb;
for (int y = y0; y <= y1; y++)
{
fb = &((unsigned int*)m_fb)[y0 * m_width + x0];
for (int x = x0; x <= x1; x++)
{
*fb++ = rgb;
}
}
}
else if (m_color_bytes == 2)
{
unsigned short* fb;
rgb = GL_RGB_32_to_16(rgb);
for (int y = y0; y <= y1; y++)
{
fb = &((unsigned short*)m_fb)[y0 * m_width + x0];
for (int x = x0; x <= x1; x++)
{
*fb++ = rgb;
}
}
}
}
virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb)
{
if (m_gfx_op && m_gfx_op->draw_pixel && m_is_active)
{
m_gfx_op->draw_pixel(x, y, rgb);
}
if (!m_fb) { return; }
if (m_color_bytes == 4)
{
((unsigned int*)m_fb)[y * m_width + x] = rgb;
}
else if (m_color_bytes == 2)
{
((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb);
}
}
struct EXTERNAL_GFX_OP* m_gfx_op;//Rendering by external method
};
inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op) : m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_surface_index(0)
{ {
ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(color_bytes == 2 || color_bytes == 4);
ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX);
@ -556,18 +541,11 @@ inline c_display::c_display(void* phy_fb, int display_width, int display_height,
for (int i = 0; i < m_surface_cnt; i++) for (int i = 0; i < m_surface_cnt; i++)
{ {
m_surface_group[i] = (phy_fb) ? new c_surface(surface_width, surface_height, color_bytes) : new c_surface_no_fb(surface_width, surface_height, color_bytes, gfx_op); m_surface_group[i] = new c_surface(surface_width, surface_height, color_bytes);
m_surface_group[i]->attach_display(this); m_surface_group[i]->attach_display(this);
} }
} }
inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface) : m_width(display_width), m_height(display_height), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0)
{
m_color_bytes = surface->m_color_bytes;
surface->m_is_active = true;
(m_surface_group[0] = surface)->attach_display(this);
}
inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect) inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect)
{ {
ASSERT(max_zorder < Z_ORDER_LEVEL_MAX && m_surface_index < m_surface_cnt); ASSERT(max_zorder < Z_ORDER_LEVEL_MAX && m_surface_index < m_surface_cnt);
@ -577,8 +555,8 @@ inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect laye
inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset) inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset)
{ {
int surface_width = s0->get_width(); register int surface_width = s0->m_width;
int surface_height = s0->get_height(); register int surface_height = s0->m_height;
if (offset < 0 || offset > surface_width || y0 < 0 || y0 >= surface_height || if (offset < 0 || offset > surface_width || y0 < 0 || y0 >= surface_height ||
y1 < 0 || y1 >= surface_height || x0 < 0 || x0 >= surface_width || x1 < 0 || x1 >= surface_width) y1 < 0 || y1 >= surface_height || x0 < 0 || x0 >= surface_width || x1 < 0 || x1 >= surface_width)
@ -604,35 +582,18 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1
for (int y = y0; y <= y1; y++) for (int y = y0; y <= y1; y++)
{ {
//Left surface //Left surface
char* addr_s = ((char*)(s0->m_fb) + (y * (s0->get_width()) + x0 + offset) * m_color_bytes); char* addr_s = ((char*)(s0->m_fb) + (y * surface_width + x0 + offset) * m_color_bytes);
char* addr_d = ((char*)(m_phy_fb)+(y * m_width + x0) * m_color_bytes); char* addr_d = ((char*)(m_phy_fb)+(y * m_width + x0) * m_color_bytes);
memcpy(addr_d, addr_s, (width - offset) * m_color_bytes); memcpy(addr_d, addr_s, (width - offset) * m_color_bytes);
//Right surface //Right surface
addr_s = ((char*)(s1->m_fb) + (y * (s1->get_width()) + x0) * m_color_bytes); addr_s = ((char*)(s1->m_fb) + (y * surface_width + x0) * m_color_bytes);
addr_d = ((char*)(m_phy_fb)+(y * m_width + x0 + (width - offset)) * m_color_bytes); addr_d = ((char*)(m_phy_fb)+(y * m_width + x0 + (width - offset)) * m_color_bytes);
memcpy(addr_d, addr_s, offset * m_color_bytes); memcpy(addr_d, addr_s, offset * m_color_bytes);
} }
} }
else if (m_color_bytes == 4)
{
void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel;
for (int y = y0; y <= y1; y++)
{
//Left surface
for (int x = x0; x <= (x1 - offset); x++)
{
draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]);
}
//Right surface
for (int x = x1 - offset; x <= x1; x++)
{
draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]);
}
}
}
else if (m_color_bytes == 2) else if (m_color_bytes == 2)
{ {
void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel;
for (int y = y0; y <= y1; y++) for (int y = y0; y <= y1; y++)
{ {
//Left surface //Left surface
@ -647,6 +608,23 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1
} }
} }
} }
else //m_color_bytes == 3/4...
{
void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel;
for (int y = y0; y <= y1; y++)
{
//Left surface
for (int x = x0; x <= (x1 - offset); x++)
{
draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]);
}
//Right surface
for (int x = x1 - offset; x <= x1; x++)
{
draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]);
}
}
}
m_phy_write_index++; m_phy_write_index++;
return 0; return 0;

View File

@ -1,8 +0,0 @@
#include "../core_include/image.h"
#ifdef GUILITE_ON
c_bitmap_operator the_bitmap_op = c_bitmap_operator();
c_image_operator* c_image::image_operator = &the_bitmap_op;
#endif

View File

@ -1,8 +1,8 @@
#pragma once #pragma once
#include "../core_include/api.h" #include "../core/api.h"
#include "../core_include/resource.h" #include "../core/resource.h"
#include "../core_include/display.h" #include "../core/display.h"
#define DEFAULT_MASK_COLOR 0xFF080408 #define DEFAULT_MASK_COLOR 0xFF080408
class c_surface; class c_surface;

View File

@ -1,9 +0,0 @@
#include "../core_include/theme.h"
#ifdef GUILITE_ON
const void* c_theme::s_font_map[FONT_MAX];
const void* c_theme::s_image_map[IMAGE_MAX];
unsigned int c_theme::s_color_map[COLOR_MAX];
#endif

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include "../core_include/api.h" #include "../core/api.h"
#include "../core_include/resource.h" #include "../core/resource.h"
//Rebuild gui library once you change this file //Rebuild gui library once you change this file
enum FONT_LIST enum FONT_LIST

View File

@ -1 +0,0 @@
#include "../core_include/wnd.h"

View File

@ -1,8 +1,8 @@
#pragma once #pragma once
#include "../core_include/api.h" #include "../core/api.h"
#include "../core_include/resource.h" #include "../core/resource.h"
#include "../core_include/display.h" #include "../core/display.h"
class c_wnd; class c_wnd;
class c_surface; class c_surface;

View File

@ -1,8 +0,0 @@
#include "../core_include/word.h"
#ifdef GUILITE_ON
c_lattice_font_op the_lattice_font_op = c_lattice_font_op();
c_font_operator* c_word::fontOperator = &the_lattice_font_op;
#endif

View File

@ -1,8 +1,8 @@
#pragma once #pragma once
#include "../core_include/api.h" #include "../core/api.h"
#include "../core_include/resource.h" #include "../core/resource.h"
#include "../core_include/display.h" #include "../core/display.h"
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>

View File

@ -1 +0,0 @@
#include "../widgets_include/button.h"

View File

@ -1,11 +1,11 @@
#pragma once #pragma once
#include "../core_include/api.h" #include "../core/api.h"
#include "../core_include/wnd.h" #include "../core/wnd.h"
#include "../core_include/resource.h" #include "../core/resource.h"
#include "../core_include/word.h" #include "../core/word.h"
#include "../core_include/display.h" #include "../core/display.h"
#include "../core_include/theme.h" #include "../core/theme.h"
class c_button : public c_wnd class c_button : public c_wnd
{ {

View File

@ -1,7 +0,0 @@
#include "../widgets_include/dialog.h"
#ifdef GUILITE_ON
DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX];
#endif

View File

@ -1,11 +1,11 @@
#pragma once #pragma once
#include "../core_include/api.h" #include "../core/api.h"
#include "../core_include/wnd.h" #include "../core/wnd.h"
#include "../core_include/display.h" #include "../core/display.h"
#include "../core_include/resource.h" #include "../core/resource.h"
#include "../core_include/word.h" #include "../core/word.h"
#include "../core_include/theme.h" #include "../core/theme.h"
class c_surface; class c_surface;
class c_dialog; class c_dialog;

View File

@ -1,7 +0,0 @@
#include "../widgets_include/edit.h"
#ifdef GUILITE_ON
c_keyboard c_edit::s_keyboard;
#endif

View File

@ -1,14 +1,14 @@
#pragma once #pragma once
#include "../core_include/api.h" #include "../core/api.h"
#include "../core_include/wnd.h" #include "../core/wnd.h"
#include "../core_include/resource.h" #include "../core/resource.h"
#include "../core_include/word.h" #include "../core/word.h"
#include "../core_include/display.h" #include "../core/display.h"
#include "../core_include/theme.h" #include "../core/theme.h"
#include "../widgets_include/button.h" #include "../widgets/button.h"
#include "../widgets_include/label.h" #include "../widgets/label.h"
#include "../widgets_include/keyboard.h" #include "../widgets/keyboard.h"
#include <string.h> #include <string.h>
#define MAX_EDIT_STRLEN 32 #define MAX_EDIT_STRLEN 32

View File

@ -1,12 +1,12 @@
#pragma once #pragma once
#include "../core_include/api.h" #include "../core/api.h"
#include "../core_include/resource.h" #include "../core/resource.h"
#include "../core_include/word.h" #include "../core/word.h"
#include "../core_include/wnd.h" #include "../core/wnd.h"
#include "../core_include/display.h" #include "../core/display.h"
#include "../core_include/theme.h" #include "../core/theme.h"
#include "../widgets_include/button.h" #include "../widgets/button.h"
#include <string.h> #include <string.h>
//Changing key width/height will change the width/height of keyboard //Changing key width/height will change the width/height of keyboard

View File

@ -1 +0,0 @@
#include "../widgets_include/label.h"

View File

@ -1,11 +1,11 @@
#pragma once #pragma once
#include "../core_include/api.h" #include "../core/api.h"
#include "../core_include/wnd.h" #include "../core/wnd.h"
#include "../core_include/display.h" #include "../core/display.h"
#include "../core_include/resource.h" #include "../core/resource.h"
#include "../core_include/theme.h" #include "../core/theme.h"
#include "../core_include/word.h" #include "../core/word.h"
class c_label : public c_wnd class c_label : public c_wnd
{ {

View File

@ -1 +0,0 @@
#include "../widgets_include/list_box.h"

View File

@ -1,12 +1,12 @@
#pragma once #pragma once
#include "../core_include/api.h" #include "../core/api.h"
#include "../core_include/resource.h" #include "../core/resource.h"
#include "../core_include/wnd.h" #include "../core/wnd.h"
#include "../core_include/display.h" #include "../core/display.h"
#include "../core_include/word.h" #include "../core/word.h"
#include "../core_include/theme.h" #include "../core/theme.h"
#include "../widgets_include/button.h" #include "../widgets/button.h"
#include <string.h> #include <string.h>
#define MAX_ITEM_NUM 4 #define MAX_ITEM_NUM 4

View File

@ -1 +0,0 @@
#include "../widgets_include/slide_group.h"

View File

@ -1,9 +1,9 @@
#pragma once #pragma once
#include "../core_include/api.h" #include "../core/api.h"
#include "../core_include/display.h" #include "../core/display.h"
#include "../core_include/wnd.h" #include "../core/wnd.h"
#include "../widgets_include/dialog.h" #include "../widgets/dialog.h"
#include <stdlib.h> #include <stdlib.h>
#define MAX_PAGES 5 #define MAX_PAGES 5

View File

@ -1 +0,0 @@
#include "../widgets_include/spinbox.h"

View File

@ -1,12 +1,12 @@
#pragma once #pragma once
#include "../core_include/api.h" #include "../core/api.h"
#include "../core_include/wnd.h" #include "../core/wnd.h"
#include "../core_include/resource.h" #include "../core/resource.h"
#include "../core_include/word.h" #include "../core/word.h"
#include "../core_include/display.h" #include "../core/display.h"
#include "../core_include/theme.h" #include "../core/theme.h"
#include "../widgets_include/button.h" #include "../widgets/button.h"
#define ID_BT_ARROW_UP 0x1111 #define ID_BT_ARROW_UP 0x1111
#define ID_BT_ARROW_DOWN 0x2222 #define ID_BT_ARROW_DOWN 0x2222

View File

@ -1 +0,0 @@
#include "../widgets_include/table.h"

View File

@ -1,11 +1,11 @@
#pragma once #pragma once
#include "../core_include/api.h" #include "../core/api.h"
#include "../core_include/resource.h" #include "../core/resource.h"
#include "../core_include/word.h" #include "../core/word.h"
#include "../core_include/display.h" #include "../core/display.h"
#include "../core_include/theme.h" #include "../core/theme.h"
#include "../core_include/wnd.h" #include "../core/wnd.h"
#define MAX_COL_NUM 30 #define MAX_COL_NUM 30
#define MAX_ROW_NUM 30 #define MAX_ROW_NUM 30

View File

@ -1 +0,0 @@
#include "../widgets_include/wave_buffer.h"

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "../core_include/api.h" #include "../core/api.h"
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>

View File

@ -1 +0,0 @@
#include "../widgets_include/wave_ctrl.h"

View File

@ -1,11 +1,11 @@
#pragma once #pragma once
#include "../core_include/api.h" #include "../core/api.h"
#include "../core_include/wnd.h" #include "../core/wnd.h"
#include "../core_include/display.h" #include "../core/display.h"
#include "../core_include/resource.h" #include "../core/resource.h"
#include "../core_include/word.h" #include "../core/word.h"
#include "../widgets_include/wave_buffer.h" #include "../widgets/wave_buffer.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>

View File

@ -1,6 +1,18 @@
#include "../widgets_include/keyboard.h" #include "../widgets/button.h"
#include "../widgets/dialog.h"
#include "../widgets/keyboard.h"
#include "../widgets/label.h"
#include "../widgets/list_box.h"
#include "../widgets/slide_group.h"
#include "../widgets/spinbox.h"
#include "../widgets/table.h"
#include "../widgets/wave_buffer.h"
#include "../widgets/wave_ctrl.h"
#include "../widgets/edit.h"
#ifdef GUILITE_ON #ifdef GUILITE_ON
DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX];
c_keyboard c_edit::s_keyboard;
static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9;
static c_keyboard_button s_key_A, s_key_B, s_key_C, s_key_D, s_key_E, s_key_F, s_key_G, s_key_H, s_key_I, s_key_J; static c_keyboard_button s_key_A, s_key_B, s_key_C, s_key_D, s_key_E, s_key_F, s_key_G, s_key_H, s_key_I, s_key_J;
@ -40,12 +52,12 @@ WND_TREE g_key_board_children[] =
{&s_key_B, 'B', 0, ((KEY_WIDTH / 2) + POS_X(5)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_B, 'B', 0, ((KEY_WIDTH / 2) + POS_X(5)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT},
{&s_key_N, 'N', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_N, 'N', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT},
{&s_key_M, 'M', 0, ((KEY_WIDTH / 2) + POS_X(7)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_M, 'M', 0, ((KEY_WIDTH / 2) + POS_X(7)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT},
{&s_key_del, 0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, {&s_key_del,0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT},
//Row 4 //Row 4
{&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT},
{&s_key_num_switch, 0x90, 0, POS_X(2), POS_Y(3), SWITCH_WIDTH, KEY_HEIGHT}, {&s_key_num_switch, 0x90, 0, POS_X(2), POS_Y(3), SWITCH_WIDTH, KEY_HEIGHT},
{&s_key_space, ' ', 0, ((KEY_WIDTH / 2) + POS_X(3)), POS_Y(3), SPACE_WIDTH, KEY_HEIGHT}, {&s_key_space, ' ', 0, ((KEY_WIDTH / 2) + POS_X(3)), POS_Y(3), SPACE_WIDTH, KEY_HEIGHT},
{&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT},
{&s_key_enter, '\n', 0, POS_X(8), POS_Y(3), ENTER_WIDTH, KEY_HEIGHT}, {&s_key_enter, '\n', 0, POS_X(8), POS_Y(3), ENTER_WIDTH, KEY_HEIGHT},
{0,0,0,0,0,0,0} {0,0,0,0,0,0,0}
}; };
@ -64,12 +76,13 @@ WND_TREE g_number_board_children[] =
{&s_key_8, '8', 0, POS_X(1), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_8, '8', 0, POS_X(1), POS_Y(2), KEY_WIDTH, KEY_HEIGHT},
{&s_key_9, '9', 0, POS_X(2), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_9, '9', 0, POS_X(2), POS_Y(2), KEY_WIDTH, KEY_HEIGHT},
{&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_esc,0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT},
{&s_key_0, '0', 0, POS_X(1), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_0, '0', 0, POS_X(1), POS_Y(3), KEY_WIDTH, KEY_HEIGHT},
{&s_key_dot, '.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_dot,'.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT},
{&s_key_del, 0x7F, 0, POS_X(3), POS_Y(0), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {&s_key_del, 0x7F, 0, POS_X(3), POS_Y(0), KEY_WIDTH, KEY_HEIGHT * 2 + 2},
{&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2},
{0,0,0,0,0,0,0} {0,0,0,0,0,0,0}
}; };
#endif #endif