mirror of
https://gitee.com/idea4good/GuiLite.git
synced 2025-01-15 17:02:52 +08:00
refactor assert, logout and bitmap
This commit is contained in:
parent
532a8a8069
commit
c49894a493
@ -5,10 +5,14 @@
|
|||||||
|
|
||||||
相比QT、MFC,GuiLite不预设开发者的使用场景,不在具体功能上,大包大揽;用框架的简洁,换取开发的自由;GuiLite在图形绘制上面,力图一步到位,运行效率感人。
|
相比QT、MFC,GuiLite不预设开发者的使用场景,不在具体功能上,大包大揽;用框架的简洁,换取开发的自由;GuiLite在图形绘制上面,力图一步到位,运行效率感人。
|
||||||
|
|
||||||
## 新功能:支持多种文字:Unicode
|
## 新功能:万国语和墙纸
|
||||||
|
墙纸:
|
||||||
|
![unicode](doc/wallpaper.jpg)
|
||||||
|
|
||||||
|
万国语(unicode):
|
||||||
![unicode](doc/unicode.jpg)
|
![unicode](doc/unicode.jpg)
|
||||||
|
|
||||||
[如何制作多种文字资源?](https://github.com/idea4good/GuiLiteToolkit)
|
[如何制作多种文字/位图资源?](https://github.com/idea4good/GuiLiteToolkit)
|
||||||
|
|
||||||
## 卓越的跨平台能力
|
## 卓越的跨平台能力
|
||||||
在Mac, iOS下的运行效果:
|
在Mac, iOS下的运行效果:
|
||||||
|
@ -7,12 +7,12 @@
|
|||||||
#define TRUE 1
|
#define TRUE 1
|
||||||
#define FALSE 0
|
#define FALSE 0
|
||||||
|
|
||||||
void do_assert(const char* file, int line);
|
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);
|
||||||
#define ASSERT(condition) \
|
#define ASSERT(condition) \
|
||||||
do{ \
|
do{ \
|
||||||
if(!(condition))do_assert(__FILE__, __LINE__);\
|
if(!(condition))_assert(__FILE__, __LINE__);\
|
||||||
}while(0)
|
}while(0)
|
||||||
|
|
||||||
void log_out(const char* log);
|
void log_out(const char* log);
|
||||||
|
|
||||||
#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)))
|
||||||
|
@ -10,7 +10,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
static void draw_bitmap_565(c_surface* surface, int z_order, int x, int y, int xsize, int ysize, const unsigned char* pPixel);
|
static void draw_bitmap_565(c_surface* surface, int z_order, int x, int y, int xsize, int ysize, const unsigned char* pPixel);
|
||||||
static void get_bitmap_pos(const BITMAP_INFO *pBitmap, c_rect rect, unsigned int align_type, int &x, int &y);
|
static void get_bitmap_pos(const BITMAP_INFO *pBitmap, c_rect rect, unsigned int align_type, int &x, int &y);
|
||||||
static void draw_bitmap_565_inrect(c_surface* surface, int z_order, int x, int y, int width, int height, int xsize, int ysize, const unsigned char* pPixel);
|
static void draw_bitmap_565_in_rect(c_surface* surface, int z_order, int x, int y, int width, int height, int xsize, int ysize, const unsigned char* pPixel);
|
||||||
|
|
||||||
c_bitmap(){}
|
c_bitmap(){}
|
||||||
c_bitmap(const c_bitmap&);
|
c_bitmap(const c_bitmap&);
|
||||||
|
@ -6,7 +6,6 @@ typedef struct struct_bitmap_info
|
|||||||
{
|
{
|
||||||
unsigned short XSize;
|
unsigned short XSize;
|
||||||
unsigned short YSize;
|
unsigned short YSize;
|
||||||
unsigned short BytesPerLine;
|
|
||||||
unsigned short BitsPerPixel;
|
unsigned short BitsPerPixel;
|
||||||
const unsigned char* pData; /* Pointer to picture data (indices) */
|
const unsigned char* pData; /* Pointer to picture data (indices) */
|
||||||
} BITMAP_INFO;
|
} BITMAP_INFO;
|
||||||
|
@ -59,7 +59,6 @@ public:
|
|||||||
virtual void modify_style(unsigned int add_style = 0, unsigned int remove_style = 0);
|
virtual void modify_style(unsigned int add_style = 0, unsigned int remove_style = 0);
|
||||||
|
|
||||||
void set_str(char* str) { m_str = str; }
|
void set_str(char* str) { m_str = str; }
|
||||||
char* get_str_id() const { return m_str; }
|
|
||||||
|
|
||||||
bool is_visible() const { return m_is_visible_now; }
|
bool is_visible() const { return m_is_visible_now; }
|
||||||
bool is_foreground();
|
bool is_foreground();
|
||||||
|
@ -18,6 +18,39 @@
|
|||||||
#define MAX_TIMER_CNT 10
|
#define MAX_TIMER_CNT 10
|
||||||
#define TIMER_UNIT 50//ms
|
#define TIMER_UNIT 50//ms
|
||||||
|
|
||||||
|
static void(*do_assert)(const char* file, int line);
|
||||||
|
static void(*do_log_out)(const char* log);
|
||||||
|
void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log))
|
||||||
|
{
|
||||||
|
do_assert = my_assert;
|
||||||
|
do_log_out = my_log_out;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _assert(const char* file, int line)
|
||||||
|
{
|
||||||
|
if(do_assert)
|
||||||
|
{
|
||||||
|
do_assert(file, line);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("assert@ file:%s, line:%d, error no: %d\n", file, line, errno);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void log_out(const char* log)
|
||||||
|
{
|
||||||
|
if (do_log_out)
|
||||||
|
{
|
||||||
|
do_log_out(log);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf(log);
|
||||||
|
fflush(stdout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
typedef struct _timer_manage
|
typedef struct _timer_manage
|
||||||
{
|
{
|
||||||
struct _timer_info
|
struct _timer_info
|
||||||
|
@ -5,10 +5,38 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <conio.h>
|
#include <conio.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
#define MAX_TIMER_CNT 10
|
#define MAX_TIMER_CNT 10
|
||||||
#define TIMER_UNIT 50//ms
|
#define TIMER_UNIT 50//ms
|
||||||
|
|
||||||
|
static void(*do_assert)(const char* file, int line);
|
||||||
|
static void(*do_log_out)(const char* log);
|
||||||
|
void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log))
|
||||||
|
{
|
||||||
|
do_assert = my_assert;
|
||||||
|
do_log_out = my_log_out;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _assert(const char* file, int line)
|
||||||
|
{
|
||||||
|
(do_assert) ? do_assert(file, line) : assert(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void log_out(const char* log)
|
||||||
|
{
|
||||||
|
if (do_log_out)
|
||||||
|
{
|
||||||
|
do_log_out(log);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf(log);
|
||||||
|
fflush(stdout);
|
||||||
|
OutputDebugStringA(log);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
typedef struct _timer_manage
|
typedef struct _timer_manage
|
||||||
{
|
{
|
||||||
struct _timer_info
|
struct _timer_info
|
||||||
|
@ -23,7 +23,7 @@ void c_bitmap::draw_bitmap_in_rect(c_surface* surface, int z_order, const BITMAP
|
|||||||
}
|
}
|
||||||
int x, y;
|
int x, y;
|
||||||
get_bitmap_pos(pBitmap, rect, align_type, x, y);
|
get_bitmap_pos(pBitmap, rect, align_type, x, y);
|
||||||
draw_bitmap_565_inrect(surface, z_order, rect.m_left + x, rect.m_top + y,
|
draw_bitmap_565_in_rect(surface, z_order, rect.m_left + x, rect.m_top + y,
|
||||||
(rect.m_right - rect.m_left + 1), (rect.m_bottom - rect.m_top + 1),
|
(rect.m_right - rect.m_left + 1), (rect.m_bottom - rect.m_top + 1),
|
||||||
pBitmap->XSize, pBitmap->YSize, (unsigned char const *)pBitmap->pData);
|
pBitmap->XSize, pBitmap->YSize, (unsigned char const *)pBitmap->pData);
|
||||||
}
|
}
|
||||||
@ -55,7 +55,6 @@ void c_bitmap::get_bitmap_pos(const BITMAP_INFO *pBitmap, c_rect rect, unsigned
|
|||||||
x = width - x_size;
|
x = width - x_size;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
break;
|
break;
|
||||||
@ -86,10 +85,7 @@ void c_bitmap::get_bitmap_pos(const BITMAP_INFO *pBitmap, c_rect rect, unsigned
|
|||||||
|
|
||||||
void c_bitmap::draw_bitmap_565(c_surface* surface, int z_order, int x, int y, int xsize, int ysize, const unsigned char* pPixel)
|
void c_bitmap::draw_bitmap_565(c_surface* surface, int z_order, int x, int y, int xsize, int ysize, const unsigned char* pPixel)
|
||||||
{
|
{
|
||||||
const unsigned short* pData;
|
const unsigned short* pData = (const unsigned short*)pPixel;
|
||||||
pData = (const unsigned short*)pPixel;
|
|
||||||
int BytesPerLine;
|
|
||||||
BytesPerLine = xsize;
|
|
||||||
for (int j = 0; j < ysize; j++)
|
for (int j = 0; j < ysize; j++)
|
||||||
{
|
{
|
||||||
const unsigned short * p = pData;
|
const unsigned short * p = pData;
|
||||||
@ -98,16 +94,13 @@ void c_bitmap::draw_bitmap_565(c_surface* surface, int z_order, int x, int y, in
|
|||||||
unsigned int rgb = *p++;
|
unsigned int rgb = *p++;
|
||||||
surface->draw_pixel(x + i, y + j, GL_RGB_16_to_32(rgb), z_order);
|
surface->draw_pixel(x + i, y + j, GL_RGB_16_to_32(rgb), z_order);
|
||||||
}
|
}
|
||||||
pData += BytesPerLine;
|
pData += xsize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void c_bitmap::draw_bitmap_565_inrect(c_surface* surface, int z_order, int x, int y, int width, int height, int xsize, int ysize, const unsigned char* pPixel)
|
void c_bitmap::draw_bitmap_565_in_rect(c_surface* surface, int z_order, int x, int y, int width, int height, int xsize, int ysize, const unsigned char* pPixel)
|
||||||
{
|
{
|
||||||
const unsigned short* pData;
|
const unsigned short* pData = (const unsigned short*)pPixel;
|
||||||
pData = (const unsigned short*)pPixel;
|
|
||||||
int BytesPerLine;
|
|
||||||
BytesPerLine = xsize;
|
|
||||||
for (int j = 0; j < ysize; j++)
|
for (int j = 0; j < ysize; j++)
|
||||||
{
|
{
|
||||||
if(j >= height)break;
|
if(j >= height)break;
|
||||||
@ -122,6 +115,6 @@ void c_bitmap::draw_bitmap_565_inrect(c_surface* surface, int z_order, int x, in
|
|||||||
unsigned int rgb = *p++;
|
unsigned int rgb = *p++;
|
||||||
surface->draw_pixel(x + i, y + j, GL_RGB_16_to_32(rgb), z_order);
|
surface->draw_pixel(x + i, y + j, GL_RGB_16_to_32(rgb), z_order);
|
||||||
}
|
}
|
||||||
pData += BytesPerLine;
|
pData += xsize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,6 @@ void c_wave_ctrl::set_max_min_base(short max_data, short min_data, short data_ba
|
|||||||
void c_wave_ctrl::set_wave_gain(E_WAVE_GAIN gain)
|
void c_wave_ctrl::set_wave_gain(E_WAVE_GAIN gain)
|
||||||
{
|
{
|
||||||
m_gain = gain;
|
m_gain = gain;
|
||||||
on_paint();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void c_wave_ctrl::set_wave_sample_rate(unsigned int rate)
|
void c_wave_ctrl::set_wave_sample_rate(unsigned int rate)
|
||||||
@ -192,7 +191,7 @@ void c_wave_ctrl::draw_smooth_vline(int y_min, int y_max, int mid, unsigned int
|
|||||||
short r = GL_RGB_R(rgb);
|
short r = GL_RGB_R(rgb);
|
||||||
short g = GL_RGB_G(rgb);
|
short g = GL_RGB_G(rgb);
|
||||||
short b = GL_RGB_B(rgb);
|
short b = GL_RGB_B(rgb);
|
||||||
int index = dy / 2 + 2;
|
int index = (dy >> 1) + 2;
|
||||||
int y;
|
int y;
|
||||||
|
|
||||||
draw_pixel(m_wave_cursor, mid, rgb);
|
draw_pixel(m_wave_cursor, mid, rgb);
|
||||||
@ -204,7 +203,7 @@ void c_wave_ctrl::draw_smooth_vline(int y_min, int y_max, int mid, unsigned int
|
|||||||
|
|
||||||
unsigned char cur_r,cur_g,cur_b;
|
unsigned char cur_r,cur_g,cur_b;
|
||||||
unsigned int cur_rgb;
|
unsigned int cur_rgb;
|
||||||
for (int i = 1; i <= dy/2 + 1; ++i )
|
for (int i = 1; i <= (dy >> 1) + 1; ++i )
|
||||||
{
|
{
|
||||||
if ( (mid + i) <= y_max )
|
if ( (mid + i) <= y_max )
|
||||||
{
|
{
|
||||||
|
@ -32,6 +32,10 @@ enum BITMAP_TYPE
|
|||||||
BITMAP_DOWN_BT_NORMAL,
|
BITMAP_DOWN_BT_NORMAL,
|
||||||
BITMAP_DOWN_BT_FOCUS,
|
BITMAP_DOWN_BT_FOCUS,
|
||||||
|
|
||||||
|
BITMAP_CUSTOM1,
|
||||||
|
BITMAP_CUSTOM2,
|
||||||
|
BITMAP_CUSTOM3,
|
||||||
|
|
||||||
BITMAP_MAX
|
BITMAP_MAX
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#include "core_include/api.h"
|
||||||
#include "core_include/rect.h"
|
#include "core_include/rect.h"
|
||||||
#include "core_include/resource.h"
|
#include "core_include/resource.h"
|
||||||
#include "../gui_include/my_resource.h"
|
#include "../gui_include/my_resource.h"
|
||||||
@ -9,44 +10,84 @@ static unsigned int s_color_map[COLOR_MAX];
|
|||||||
|
|
||||||
int c_my_resource::add_font(FONT_TYPE index, const FONT_INFO* font)
|
int c_my_resource::add_font(FONT_TYPE index, const FONT_INFO* font)
|
||||||
{
|
{
|
||||||
|
if (index >= FONT_MAX)
|
||||||
|
{
|
||||||
|
ASSERT(FALSE);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
s_font_map[index] = font;
|
s_font_map[index] = font;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const FONT_INFO* c_my_resource::get_font(FONT_TYPE index)
|
const FONT_INFO* c_my_resource::get_font(FONT_TYPE index)
|
||||||
{
|
{
|
||||||
|
if (index >= FONT_MAX)
|
||||||
|
{
|
||||||
|
ASSERT(FALSE);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
return s_font_map[index];
|
return s_font_map[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
int c_my_resource::add_bitmap(BITMAP_TYPE index, const BITMAP_INFO* bmp)
|
int c_my_resource::add_bitmap(BITMAP_TYPE index, const BITMAP_INFO* bmp)
|
||||||
{
|
{
|
||||||
|
if (index >= BITMAP_MAX)
|
||||||
|
{
|
||||||
|
ASSERT(FALSE);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
s_bmp_map[index] = bmp;
|
s_bmp_map[index] = bmp;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const BITMAP_INFO* c_my_resource::get_bmp(BITMAP_TYPE index)
|
const BITMAP_INFO* c_my_resource::get_bmp(BITMAP_TYPE index)
|
||||||
{
|
{
|
||||||
|
if (index >= BITMAP_MAX)
|
||||||
|
{
|
||||||
|
ASSERT(FALSE);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
return s_bmp_map[index];
|
return s_bmp_map[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
int c_my_resource::add_shape(SHAPE_TYPE index, const COLOR_RECT* shape)
|
int c_my_resource::add_shape(SHAPE_TYPE index, const COLOR_RECT* shape)
|
||||||
{
|
{
|
||||||
|
if (index >= SHAPE_MAX)
|
||||||
|
{
|
||||||
|
ASSERT(FALSE);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
s_shape_map[index] = shape;
|
s_shape_map[index] = shape;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const COLOR_RECT* c_my_resource::get_shape(SHAPE_TYPE index)
|
const COLOR_RECT* c_my_resource::get_shape(SHAPE_TYPE index)
|
||||||
{
|
{
|
||||||
|
if (index >= SHAPE_MAX)
|
||||||
|
{
|
||||||
|
ASSERT(FALSE);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
return s_shape_map[index];
|
return s_shape_map[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
int c_my_resource::add_color(COLOR_TYPE index, const unsigned int color)
|
int c_my_resource::add_color(COLOR_TYPE index, const unsigned int color)
|
||||||
{
|
{
|
||||||
|
if (index >= COLOR_MAX)
|
||||||
|
{
|
||||||
|
ASSERT(FALSE);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
s_color_map[index] = color;
|
s_color_map[index] = color;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const unsigned int c_my_resource::get_color(COLOR_TYPE index)
|
const unsigned int c_my_resource::get_color(COLOR_TYPE index)
|
||||||
{
|
{
|
||||||
|
if (index >= COLOR_MAX)
|
||||||
|
{
|
||||||
|
ASSERT(FALSE);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
return s_color_map[index];
|
return s_color_map[index];
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user