mirror of
https://gitee.com/idea4good/GuiLite.git
synced 2026-01-02 04:17:19 +08:00
refactor c_rect
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
#define GUILITE_CORE_INCLUDE_API_H
|
||||
|
||||
#define REAL_TIME_TASK_CYCLE_MS 50
|
||||
#define MAX(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(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF)
|
||||
@@ -19,7 +21,7 @@
|
||||
#define ALIGN_HMASK 0x03000000L
|
||||
|
||||
#define ALIGN_VCENTER 0x00000000L
|
||||
#define ALIGN_TOP 0x00100000L
|
||||
#define ALIGN_TOP 0x00100000L
|
||||
#define ALIGN_BOTTOM 0x00200000L
|
||||
#define ALIGN_VMASK 0x00300000L
|
||||
|
||||
@@ -68,4 +70,37 @@ private:
|
||||
void* m_read_sem;
|
||||
void* m_write_mutex;
|
||||
};
|
||||
|
||||
class c_rect
|
||||
{
|
||||
public:
|
||||
c_rect(){ m_left = m_top = m_right = m_bottom = -1; }
|
||||
c_rect(int left, int top, int width, int height)
|
||||
{
|
||||
set_rect(left, top, width, height);
|
||||
}
|
||||
void set_rect(int left, int top, int width, int height)
|
||||
{
|
||||
ASSERT(width > 0 && height > 0);
|
||||
m_left = left;
|
||||
m_top = top;
|
||||
m_right = left + width - 1;
|
||||
m_bottom = top + height -1;
|
||||
}
|
||||
bool pt_in_rect(int x, int y) const
|
||||
{
|
||||
return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom;
|
||||
}
|
||||
int operator==(const c_rect& rect) const
|
||||
{
|
||||
return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom);
|
||||
}
|
||||
int width() const { return m_right - m_left + 1; }
|
||||
int height() const { return m_bottom - m_top + 1 ; }
|
||||
|
||||
int m_left;
|
||||
int m_top;
|
||||
int m_right;
|
||||
int m_bottom;
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
#include "../core_include/api.h"
|
||||
#include "../core_include/resource.h"
|
||||
#include "../core_include/rect.h"
|
||||
#include "../core_include/display.h"
|
||||
|
||||
#define DEFAULT_MASK_COLOR 0xFF080408
|
||||
@@ -23,7 +22,7 @@ public:
|
||||
lower_fb_16 = (unsigned short*)surface->m_layers[z_order - 1].fb;
|
||||
lower_fb_32 = (unsigned int*)surface->m_layers[z_order - 1].fb;
|
||||
lower_fb_rect = surface->m_layers[z_order - 1].rect;
|
||||
lower_fb_width = lower_fb_rect.Width();
|
||||
lower_fb_width = lower_fb_rect.width();
|
||||
}
|
||||
unsigned int mask_rgb_16 = GL_RGB_32_to_16(mask_rgb);
|
||||
int xsize = pBitmap->width;
|
||||
@@ -37,7 +36,7 @@ public:
|
||||
unsigned int rgb = *pData++;
|
||||
if (mask_rgb_16 == rgb)
|
||||
{
|
||||
if (lower_fb_rect.PtInRect(x_, y_))
|
||||
if (lower_fb_rect.pt_in_rect(x_, y_))
|
||||
{//show lower layer
|
||||
surface->draw_pixel(x_, y_, (color_bytes == 4) ? lower_fb_32[(y_ - lower_fb_rect.m_top) * lower_fb_width + (x_ - lower_fb_rect.m_left)] : GL_RGB_16_to_32(lower_fb_16[(y_ - lower_fb_rect.m_top) * lower_fb_width + (x_ - lower_fb_rect.m_left)]), z_order);
|
||||
}
|
||||
@@ -66,7 +65,7 @@ public:
|
||||
lower_fb_16 = (unsigned short*)surface->m_layers[z_order - 1].fb;
|
||||
lower_fb_32 = (unsigned int*)surface->m_layers[z_order - 1].fb;
|
||||
lower_fb_rect = surface->m_layers[z_order - 1].rect;
|
||||
lower_fb_width = lower_fb_rect.Width();
|
||||
lower_fb_width = lower_fb_rect.width();
|
||||
}
|
||||
unsigned int mask_rgb_16 = GL_RGB_32_to_16(mask_rgb);
|
||||
const unsigned short* pData = (const unsigned short*)pBitmap->pixel_color_array;
|
||||
@@ -79,7 +78,7 @@ public:
|
||||
unsigned int rgb = *p++;
|
||||
if (mask_rgb_16 == rgb)
|
||||
{
|
||||
if (lower_fb_rect.PtInRect(x + x_, y + y_))
|
||||
if (lower_fb_rect.pt_in_rect(x + x_, y + y_))
|
||||
{//show lower layer
|
||||
surface->draw_pixel(x + x_, y + y_, (color_bytes == 4) ? lower_fb_32[(y + y_ - lower_fb_rect.m_top) * lower_fb_width + x + x_ - lower_fb_rect.m_left] : GL_RGB_16_to_32(lower_fb_16[(y + y_ - lower_fb_rect.m_top) * lower_fb_width + x + x_ - lower_fb_rect.m_left]), z_order);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#define GUILITE_CORE_INCLUDE_DISPLAY_H
|
||||
|
||||
#include "../core_include/api.h"
|
||||
#include "../core_include/rect.h"
|
||||
#include "../core_include/cmd_target.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
@@ -30,7 +29,7 @@ class c_display {
|
||||
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);//single custom surface
|
||||
inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect(0, 0, -1, -1));//for multiple surfaces
|
||||
inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for multiple surfaces
|
||||
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_height() { return m_height; }
|
||||
@@ -108,9 +107,9 @@ public:
|
||||
class c_surface {
|
||||
friend class c_display; friend class c_bitmap;
|
||||
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(0, 0, -1, -1)) : 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_fb(0), m_phy_write_index(0), m_display(0)
|
||||
{
|
||||
(overlpa_rect == c_rect(0, 0, -1, -1)) ? 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; }
|
||||
@@ -160,16 +159,16 @@ public:
|
||||
m_top_zorder = (Z_ORDER_LEVEL)z_order;
|
||||
}
|
||||
|
||||
if (m_layers[z_order].rect.PtInRect(x, y))
|
||||
if (m_layers[z_order].rect.pt_in_rect(x, y))
|
||||
{
|
||||
c_rect layer_rect = m_layers[z_order].rect;
|
||||
if (m_color_bytes == 4)
|
||||
{
|
||||
((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.Width()] = rgb;
|
||||
((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb;
|
||||
}
|
||||
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 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,7 +180,7 @@ public:
|
||||
bool be_overlapped = false;
|
||||
for (unsigned int tmp_z_order = Z_ORDER_LEVEL_MAX - 1; tmp_z_order > z_order; tmp_z_order--)
|
||||
{
|
||||
if (m_layers[tmp_z_order].rect.PtInRect(x, y))
|
||||
if (m_layers[tmp_z_order].rect.pt_in_rect(x, y))
|
||||
{
|
||||
be_overlapped = true;
|
||||
break;
|
||||
@@ -215,15 +214,15 @@ public:
|
||||
{
|
||||
for (x = x0; x <= x1; x++)
|
||||
{
|
||||
if (layer_rect.PtInRect(x, y))
|
||||
if (layer_rect.pt_in_rect(x, y))
|
||||
{
|
||||
if (m_color_bytes == 4)
|
||||
{
|
||||
((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.Width() + (x - layer_rect.m_left)] = rgb;
|
||||
((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb;
|
||||
}
|
||||
else
|
||||
{
|
||||
((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.Width() + (x - layer_rect.m_left)] = rgb_16;
|
||||
((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -352,7 +351,7 @@ public:
|
||||
rect.m_top >= layer_rect.m_top && rect.m_bottom <= layer_rect.m_bottom);
|
||||
|
||||
void* fb = m_layers[z_order].fb;
|
||||
int width = layer_rect.Width();
|
||||
int width = layer_rect.width();
|
||||
for (int y = rect.m_top; y <= rect.m_bottom; y++)
|
||||
{
|
||||
for (int x = rect.m_left; x <= rect.m_right; x++)
|
||||
@@ -458,7 +457,7 @@ protected:
|
||||
|
||||
for (int i = Z_ORDER_LEVEL_0; i < m_max_zorder; i++)
|
||||
{//Top layber fb always be 0
|
||||
ASSERT(m_layers[i].fb = calloc(layer_rect.Width() * layer_rect.Height(), m_color_bytes));
|
||||
ASSERT(m_layers[i].fb = calloc(layer_rect.width() * layer_rect.height(), m_color_bytes));
|
||||
m_layers[i].rect = layer_rect;
|
||||
}
|
||||
}
|
||||
@@ -479,7 +478,7 @@ protected:
|
||||
class c_surface_no_fb : public c_surface {//No physical framebuffer
|
||||
friend class c_display;
|
||||
public:
|
||||
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(0, 0, -1, -1)) : c_surface(width, height, color_bytes, max_zorder, overlpa_rect), m_gfx_op(gfx_op) {}
|
||||
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) {}
|
||||
protected:
|
||||
virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb)
|
||||
{
|
||||
@@ -574,7 +573,7 @@ inline c_display::c_display(void* phy_fb, int display_width, int display_height,
|
||||
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);
|
||||
(layer_rect == c_rect(0, 0, -1, -1)) ? m_surface_group[m_surface_index]->set_surface(max_zorder, c_rect(0, 0, m_width - 1, m_height - 1)) : m_surface_group[m_surface_index]->set_surface(max_zorder, layer_rect);
|
||||
(layer_rect == c_rect()) ? m_surface_group[m_surface_index]->set_surface(max_zorder, c_rect(0, 0, m_width - 1, m_height - 1)) : m_surface_group[m_surface_index]->set_surface(max_zorder, layer_rect);
|
||||
return m_surface_group[m_surface_index++];
|
||||
}
|
||||
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
#ifndef GUILITE_CORE_INCLUDE_RECT_H
|
||||
#define GUILITE_CORE_INCLUDE_RECT_H
|
||||
|
||||
#define MAX(a,b) (((a)>(b))?(a):(b))
|
||||
#define MIN(a,b) (((a)<(b))?(a):(b))
|
||||
|
||||
class c_rect
|
||||
{
|
||||
public:
|
||||
c_rect(){Empty();}
|
||||
c_rect(int left, int top, int right, int bottom){m_left = left;m_top = top;m_right = right;m_bottom = bottom;};
|
||||
void SetRect(int Left, int Top, int Right, int Bottom)
|
||||
{
|
||||
m_left = MIN(Left, Right);
|
||||
m_top = MIN(Top, Bottom);
|
||||
m_right = MAX(Left, Right);
|
||||
m_bottom = MAX(Top, Bottom);
|
||||
}
|
||||
c_rect(const c_rect& rect)
|
||||
{
|
||||
SetRect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom);
|
||||
}
|
||||
void Empty()
|
||||
{
|
||||
m_left = m_top = m_right = m_bottom = -1;
|
||||
}
|
||||
int IsEmpty() const
|
||||
{
|
||||
return m_top == m_bottom || m_left == m_right;
|
||||
}
|
||||
bool PtInRect(int x, int y) const
|
||||
{
|
||||
return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom;
|
||||
}
|
||||
int operator==(const c_rect& rect) const
|
||||
{
|
||||
return (m_left == rect.m_left) && (m_top == rect.m_top) &&
|
||||
(m_right == rect.m_right) && (m_bottom == rect.m_bottom);
|
||||
}
|
||||
int Width() const {return m_right - m_left + 1;}
|
||||
int Height() const {return m_bottom - m_top + 1;}
|
||||
|
||||
int m_left;
|
||||
int m_top;
|
||||
int m_right;
|
||||
int m_bottom;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -2,7 +2,6 @@
|
||||
#define GUILITE_CORE_INCLUDE_THEME_H
|
||||
|
||||
#include "../core_include/api.h"
|
||||
#include "../core_include/rect.h"
|
||||
#include "../core_include/resource.h"
|
||||
|
||||
typedef struct struct_font_info FONT_INFO;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#define GUILITE_CORE_INCLUDE_WND_H
|
||||
|
||||
#include "../core_include/api.h"
|
||||
#include "../core_include/rect.h"
|
||||
#include "../core_include/cmd_target.h"
|
||||
#include "../core_include/resource.h"
|
||||
#include "../core_include/bitmap.h"
|
||||
@@ -196,8 +195,10 @@ public:
|
||||
void get_wnd_rect(c_rect &rect) const { rect = m_wnd_rect; }
|
||||
void get_screen_rect(c_rect &rect) const
|
||||
{
|
||||
rect.SetRect(0, 0, (m_wnd_rect.Width() - 1), (m_wnd_rect.Height() - 1));
|
||||
wnd2screen(rect);
|
||||
int l = 0;
|
||||
int t = 0;
|
||||
wnd2screen(l, t);
|
||||
rect.set_rect(l, t, m_wnd_rect.width(), m_wnd_rect.height());
|
||||
}
|
||||
|
||||
c_wnd* set_child_focus(c_wnd *focus_child)
|
||||
@@ -345,7 +346,7 @@ public:
|
||||
{
|
||||
c_rect rect;
|
||||
child->get_wnd_rect(rect);
|
||||
if (true == rect.PtInRect(x, y))
|
||||
if (true == rect.pt_in_rect(x, y))
|
||||
{
|
||||
return child->on_touch(x, y, action);
|
||||
}
|
||||
@@ -470,17 +471,6 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
void wnd2screen(c_rect &rect) const
|
||||
{
|
||||
int l = rect.m_left;
|
||||
int t = rect.m_top;
|
||||
wnd2screen(l, t);
|
||||
|
||||
int r = (l + rect.Width() - 1);
|
||||
int b = (t + rect.Height() - 1);
|
||||
rect.SetRect(l, t, r, b);
|
||||
}
|
||||
|
||||
int load_child_wnd(WND_TREE *p_child_tree)
|
||||
{
|
||||
if (0 == p_child_tree)
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#define GUILITE_CORE_INCLUDE_WORD_H
|
||||
|
||||
#include "../core_include/api.h"
|
||||
#include "../core_include/rect.h"
|
||||
#include "../core_include/resource.h"
|
||||
#include "../core_include/display.h"
|
||||
#include <string.h>
|
||||
|
||||
Reference in New Issue
Block a user