implement hardware DC in each widget.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@787 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
bernard.xiong@gmail.com 2010-07-04 23:58:35 +00:00
parent e76cd77c56
commit b25f307b9b
15 changed files with 244 additions and 144 deletions

View File

@ -250,7 +250,7 @@ rt_inline void rtgui_blit_line_4(rtgui_color_t* color, rt_uint8_t* dest, int lin
static void rtgui_dc_buffer_blit(struct rtgui_dc* self, struct rtgui_point* dc_point, struct rtgui_dc* dest, rtgui_rect_t* rect) static void rtgui_dc_buffer_blit(struct rtgui_dc* self, struct rtgui_point* dc_point, struct rtgui_dc* dest, rtgui_rect_t* rect)
{ {
struct rtgui_dc_buffer* dc = (struct rtgui_dc_buffer*)self; struct rtgui_dc_buffer* dc = (struct rtgui_dc_buffer*)self;
struct rtgui_dc_hw* hw = (struct rtgui_dc_hw*)dest; struct rtgui_dc* hw = dest;
if (dc_point == RT_NULL) dc_point = &rtgui_empty_point; if (dc_point == RT_NULL) dc_point = &rtgui_empty_point;
@ -273,7 +273,7 @@ static void rtgui_dc_buffer_blit(struct rtgui_dc* self, struct rtgui_point* dc_p
rect_height = rtgui_rect_height(*rect); rect_height = rtgui_rect_height(*rect);
/* get blit line function */ /* get blit line function */
switch (hw->device->byte_per_pixel) switch (rtgui_graphic_driver_get_default()->byte_per_pixel)
{ {
case 1: case 1:
blit_line = rtgui_blit_line_1; blit_line = rtgui_blit_line_1;
@ -292,7 +292,7 @@ static void rtgui_dc_buffer_blit(struct rtgui_dc* self, struct rtgui_point* dc_p
} }
/* create line buffer */ /* create line buffer */
line_ptr = (rt_uint8_t*) rtgui_malloc(rect_width * hw->device->byte_per_pixel); line_ptr = (rt_uint8_t*) rtgui_malloc(rect_width * rtgui_graphic_driver_get_default()->byte_per_pixel);
/* prepare pixel line */ /* prepare pixel line */
pixel = (rtgui_color_t*)(dc->pixel + dc_point->y * dc->pitch + dc_point->x * sizeof(rtgui_color_t)); pixel = (rtgui_color_t*)(dc->pixel + dc_point->y * dc->pitch + dc_point->x * sizeof(rtgui_color_t));

View File

@ -32,6 +32,10 @@ static rt_bool_t rtgui_dc_hw_fini(struct rtgui_dc* dc);
static rt_bool_t rtgui_dc_hw_get_visible(struct rtgui_dc* dc); static rt_bool_t rtgui_dc_hw_get_visible(struct rtgui_dc* dc);
static void rtgui_dc_hw_get_rect(struct rtgui_dc* dc, rtgui_rect_t* rect); static void rtgui_dc_hw_get_rect(struct rtgui_dc* dc, rtgui_rect_t* rect);
#define hw_driver (rtgui_graphic_driver_get_default())
#define dc_set_foreground(c) dc->gc.foreground = c
#define dc_set_background(c) dc->gc.background = c
struct rtgui_dc* rtgui_dc_begin_drawing(rtgui_widget_t* owner) struct rtgui_dc* rtgui_dc_begin_drawing(rtgui_widget_t* owner)
{ {
return rtgui_dc_hw_create(owner); return rtgui_dc_hw_create(owner);
@ -39,13 +43,10 @@ struct rtgui_dc* rtgui_dc_begin_drawing(rtgui_widget_t* owner)
void rtgui_dc_end_drawing(struct rtgui_dc* dc) void rtgui_dc_end_drawing(struct rtgui_dc* dc)
{ {
if (rtgui_dc_hw_fini(dc) == RT_TRUE) rtgui_dc_hw_fini(dc);
{
rtgui_free(dc);
}
} }
const static struct rtgui_dc_engine dc_hw_engine = const struct rtgui_dc_engine dc_hw_engine =
{ {
rtgui_dc_hw_draw_point, rtgui_dc_hw_draw_point,
rtgui_dc_hw_draw_color_point, rtgui_dc_hw_draw_color_point,
@ -63,44 +64,49 @@ const static struct rtgui_dc_engine dc_hw_engine =
rtgui_dc_hw_fini, rtgui_dc_hw_fini,
}; };
void rtgui_dc_hw_init(rtgui_widget_t* owner)
{
struct rtgui_dc* dc;
RT_ASSERT(owner != RT_NULL);
dc = RTGUI_WIDGET_DC(owner);
dc->type = RTGUI_DC_HW;
dc->engine = &dc_hw_engine;
}
extern struct rt_mutex cursor_mutex; extern struct rt_mutex cursor_mutex;
#define dc_set_foreground(c) dc->owner->gc.foreground = c
#define dc_set_background(c) dc->owner->gc.background = c
extern void rtgui_mouse_show_cursor(void); extern void rtgui_mouse_show_cursor(void);
extern void rtgui_mouse_hide_cursor(void); extern void rtgui_mouse_hide_cursor(void);
struct rtgui_dc* rtgui_dc_hw_create(rtgui_widget_t* owner) struct rtgui_dc* rtgui_dc_hw_create(rtgui_widget_t* owner)
{ {
struct rtgui_dc_hw* dc; struct rtgui_dc* dc;
rtgui_widget_t* widget; rtgui_widget_t* widget;
/* adjudge owner */ /* adjudge owner */
if (owner == RT_NULL || owner->toplevel == RT_NULL) return RT_NULL; if (owner == RT_NULL || owner->toplevel == RT_NULL) return RT_NULL;
if (!RTGUI_IS_TOPLEVEL(owner->toplevel)) return RT_NULL; if (!RTGUI_IS_TOPLEVEL(owner->toplevel)) return RT_NULL;
/* malloc a dc object */ dc = RTGUI_WIDGET_DC(owner);
dc = (struct rtgui_dc_hw*) rtgui_malloc(sizeof(struct rtgui_dc_hw)); /* set init visible as true */
dc->parent.type = RTGUI_DC_HW; RTGUI_WIDGET_DC_SET_VISIBLE(owner);
dc->parent.engine = &dc_hw_engine;
dc->owner = owner;
dc->visible = RT_TRUE;
dc->device = rtgui_graphic_driver_get_default();
/* set visible */ /* check widget visible */
widget = owner; widget = owner;
while (widget != RT_NULL) while (widget != RT_NULL)
{ {
if (RTGUI_WIDGET_IS_HIDE(widget)) if (RTGUI_WIDGET_IS_HIDE(widget))
{ {
dc->visible = RT_FALSE; RTGUI_WIDGET_DC_SET_UNVISIBLE(owner);
break; break;
} }
widget = widget->parent; widget = widget->parent;
} }
if (RTGUI_IS_WINTITLE(dc->owner->toplevel)) if (RTGUI_IS_WINTITLE(owner->toplevel))
{ {
rtgui_toplevel_t* top = RTGUI_TOPLEVEL(dc->owner->toplevel); rtgui_toplevel_t* top = RTGUI_TOPLEVEL(owner->toplevel);
top->drawing ++; top->drawing ++;
if (top->drawing == 1) if (top->drawing == 1)
@ -117,10 +123,10 @@ struct rtgui_dc* rtgui_dc_hw_create(rtgui_widget_t* owner)
#endif #endif
} }
} }
else if (RTGUI_IS_WORKBENCH(dc->owner->toplevel) || else if (RTGUI_IS_WORKBENCH(owner->toplevel) ||
RTGUI_IS_WIN(dc->owner->toplevel)) RTGUI_IS_WIN(owner->toplevel))
{ {
rtgui_toplevel_t* top = RTGUI_TOPLEVEL(dc->owner->toplevel); rtgui_toplevel_t* top = RTGUI_TOPLEVEL(owner->toplevel);
top->drawing ++; top->drawing ++;
if (top->drawing == 1) if (top->drawing == 1)
@ -142,21 +148,25 @@ struct rtgui_dc* rtgui_dc_hw_create(rtgui_widget_t* owner)
} }
} }
return &(dc->parent); return dc;
} }
static rt_bool_t rtgui_dc_hw_fini(struct rtgui_dc* dc) static rt_bool_t rtgui_dc_hw_fini(struct rtgui_dc* dc)
{ {
struct rtgui_dc_hw* hw = (struct rtgui_dc_hw*)dc; rtgui_widget_t* owner;
if (dc == RT_NULL || hw->parent.type != RTGUI_DC_HW) return RT_FALSE;
if (RTGUI_IS_WINTITLE(hw->owner->toplevel)) if (dc == RT_NULL || dc->type != RTGUI_DC_HW) return RT_FALSE;
/* get owner */
owner = RTGUI_CONTAINER_OF(dc, struct rtgui_widget, dc_type);
if (RTGUI_IS_WINTITLE(owner->toplevel))
{ {
/* update title extent */ /* update title extent */
rtgui_toplevel_t* top = RTGUI_TOPLEVEL(hw->owner->toplevel); rtgui_toplevel_t* top = RTGUI_TOPLEVEL(owner->toplevel);
top->drawing --; top->drawing --;
if ((top->drawing == 0) && (hw->visible == RT_TRUE)) if ((top->drawing == 0) && RTGUI_WIDGET_IS_DC_VISIBLE(owner))
{ {
#ifdef __WIN32__ #ifdef __WIN32__
#ifdef RTGUI_USING_MOUSE_CURSOR #ifdef RTGUI_USING_MOUSE_CURSOR
@ -166,7 +176,7 @@ static rt_bool_t rtgui_dc_hw_fini(struct rtgui_dc* dc)
rt_kprintf("show cursor\n"); rt_kprintf("show cursor\n");
#endif #endif
/* update screen */ /* update screen */
hw->device->screen_update(&(hw->owner->extent)); hw_driver->screen_update(&(owner->extent));
#else #else
#ifdef RTGUI_USING_MOUSE_CURSOR #ifdef RTGUI_USING_MOUSE_CURSOR
/* show cursor */ /* show cursor */
@ -174,17 +184,17 @@ static rt_bool_t rtgui_dc_hw_fini(struct rtgui_dc* dc)
#endif #endif
/* update screen */ /* update screen */
hw->device->screen_update(&(hw->owner->extent)); hw_driver->screen_update(&(owner->extent));
#endif #endif
} }
} }
else if (RTGUI_IS_WORKBENCH(hw->owner->toplevel) || else if (RTGUI_IS_WORKBENCH(owner->toplevel) ||
RTGUI_IS_WIN(hw->owner->toplevel)) RTGUI_IS_WIN(owner->toplevel))
{ {
rtgui_toplevel_t* top = RTGUI_TOPLEVEL(hw->owner->toplevel); rtgui_toplevel_t* top = RTGUI_TOPLEVEL(owner->toplevel);
top->drawing --; top->drawing --;
if ((top->drawing == 0) && (hw->visible == RT_TRUE)) if ((top->drawing == 0) && RTGUI_WIDGET_IS_DC_VISIBLE(owner))
{ {
#ifdef __WIN32__ #ifdef __WIN32__
#ifdef RTGUI_USING_MOUSE_CURSOR #ifdef RTGUI_USING_MOUSE_CURSOR
@ -194,12 +204,12 @@ static rt_bool_t rtgui_dc_hw_fini(struct rtgui_dc* dc)
rt_kprintf("show cursor\n"); rt_kprintf("show cursor\n");
#endif #endif
/* update screen */ /* update screen */
hw->device->screen_update(&(hw->owner->extent)); hw_driver->screen_update(&(owner->extent));
#else #else
/* send to server to end drawing */ /* send to server to end drawing */
struct rtgui_event_update_end eupdate; struct rtgui_event_update_end eupdate;
RTGUI_EVENT_UPDATE_END_INIT(&(eupdate)); RTGUI_EVENT_UPDATE_END_INIT(&(eupdate));
eupdate.rect = hw->owner->extent; eupdate.rect = owner->extent;
rtgui_thread_send(top->server, (struct rtgui_event*)&eupdate, sizeof(eupdate)); rtgui_thread_send(top->server, (struct rtgui_event*)&eupdate, sizeof(eupdate));
#endif #endif
@ -214,37 +224,44 @@ static rt_bool_t rtgui_dc_hw_fini(struct rtgui_dc* dc)
*/ */
static void rtgui_dc_hw_draw_point(struct rtgui_dc* self, int x, int y) static void rtgui_dc_hw_draw_point(struct rtgui_dc* self, int x, int y)
{ {
struct rtgui_dc_hw* dc;
rtgui_rect_t rect; rtgui_rect_t rect;
rtgui_widget_t *owner;
dc = (struct rtgui_dc_hw*)self; if (self == RT_NULL) return;
if (dc == RT_NULL || dc->visible != RT_TRUE) return;
x = x + dc->owner->extent.x1; /* get owner */
y = y + dc->owner->extent.y1; owner = RTGUI_CONTAINER_OF(self, struct rtgui_widget, dc_type);
if (!RTGUI_WIDGET_IS_DC_VISIBLE(owner)) return;
if (rtgui_region_contains_point(&(dc->owner->clip), x, y, &rect) == RT_EOK)
x = x + owner->extent.x1;
y = y + owner->extent.y1;
if (rtgui_region_contains_point(&(owner->clip), x, y, &rect) == RT_EOK)
{ {
/* draw this point */ /* draw this point */
dc->device->set_pixel(&(dc->owner->gc.foreground), x, y); hw_driver->set_pixel(&(owner->gc.foreground), x, y);
} }
} }
static void rtgui_dc_hw_draw_color_point(struct rtgui_dc* self, int x, int y, rtgui_color_t color) static void rtgui_dc_hw_draw_color_point(struct rtgui_dc* self, int x, int y, rtgui_color_t color)
{ {
struct rtgui_dc_hw* dc;
rtgui_rect_t rect; rtgui_rect_t rect;
rtgui_widget_t *owner;
dc = (struct rtgui_dc_hw*)self; if (self == RT_NULL) return;
if (dc == RT_NULL || dc->visible != RT_TRUE) return;
x = x + dc->owner->extent.x1; /* get owner */
y = y + dc->owner->extent.y1; owner = RTGUI_CONTAINER_OF(self, struct rtgui_widget, dc_type);
if (!RTGUI_WIDGET_IS_DC_VISIBLE(owner)) return;
if (rtgui_region_contains_point(&(dc->owner->clip), x, y, &rect) == RT_EOK) x = x + owner->extent.x1;
y = y + owner->extent.y1;
if (rtgui_region_contains_point(&(owner->clip), x, y, &rect) == RT_EOK)
{ {
/* draw this point */ /* draw this point */
dc->device->set_pixel(&color, x, y); hw_driver->set_pixel(&color, x, y);
} }
} }
@ -254,20 +271,23 @@ static void rtgui_dc_hw_draw_color_point(struct rtgui_dc* self, int x, int y, rt
static void rtgui_dc_hw_draw_vline(struct rtgui_dc* self, int x, int y1, int y2) static void rtgui_dc_hw_draw_vline(struct rtgui_dc* self, int x, int y1, int y2)
{ {
register rt_base_t index; register rt_base_t index;
struct rtgui_dc_hw* dc; rtgui_widget_t *owner;
dc = (struct rtgui_dc_hw*)self; if (self == RT_NULL) return;
if (dc == RT_NULL || dc->visible != RT_TRUE) return;
x = x + dc->owner->extent.x1; /* get owner */
y1 = y1 + dc->owner->extent.y1; owner = RTGUI_CONTAINER_OF(self, struct rtgui_widget, dc_type);
y2 = y2 + dc->owner->extent.y1; if (!RTGUI_WIDGET_IS_DC_VISIBLE(owner)) return;
if (dc->owner->clip.data == RT_NULL) x = x + owner->extent.x1;
y1 = y1 + owner->extent.y1;
y2 = y2 + owner->extent.y1;
if (owner->clip.data == RT_NULL)
{ {
rtgui_rect_t* prect; rtgui_rect_t* prect;
prect = &(dc->owner->clip.extents); prect = &(owner->clip.extents);
/* calculate vline intersect */ /* calculate vline intersect */
if (prect->x1 > x || prect->x2 <= x) return; if (prect->x1 > x || prect->x2 <= x) return;
@ -277,14 +297,14 @@ static void rtgui_dc_hw_draw_vline(struct rtgui_dc* self, int x, int y1, int y2)
if (prect->y2 < y2) y2 = prect->y2; if (prect->y2 < y2) y2 = prect->y2;
/* draw vline */ /* draw vline */
dc->device->draw_vline(&(dc->owner->gc.foreground), x, y1, y2); hw_driver->draw_vline(&(owner->gc.foreground), x, y1, y2);
} }
else for (index = 0; index < rtgui_region_num_rects(&(dc->owner->clip)); index ++) else for (index = 0; index < rtgui_region_num_rects(&(owner->clip)); index ++)
{ {
rtgui_rect_t* prect; rtgui_rect_t* prect;
register rt_base_t draw_y1, draw_y2; register rt_base_t draw_y1, draw_y2;
prect = ((rtgui_rect_t *)(dc->owner->clip.data + index + 1)); prect = ((rtgui_rect_t *)(owner->clip.data + index + 1));
draw_y1 = y1; draw_y1 = y1;
draw_y2 = y2; draw_y2 = y2;
@ -296,7 +316,7 @@ static void rtgui_dc_hw_draw_vline(struct rtgui_dc* self, int x, int y1, int y2)
if (prect->y2 < y2) draw_y2 = prect->y2; if (prect->y2 < y2) draw_y2 = prect->y2;
/* draw vline */ /* draw vline */
dc->device->draw_vline(&(dc->owner->gc.foreground), x, draw_y1, draw_y2); hw_driver->draw_vline(&(owner->gc.foreground), x, draw_y1, draw_y2);
} }
} }
@ -306,21 +326,24 @@ static void rtgui_dc_hw_draw_vline(struct rtgui_dc* self, int x, int y1, int y2)
static void rtgui_dc_hw_draw_hline(struct rtgui_dc* self, int x1, int x2, int y) static void rtgui_dc_hw_draw_hline(struct rtgui_dc* self, int x1, int x2, int y)
{ {
register rt_base_t index; register rt_base_t index;
struct rtgui_dc_hw* dc; rtgui_widget_t *owner;
dc = (struct rtgui_dc_hw*)self; if (self == RT_NULL) return;
if (dc == RT_NULL || dc->visible != RT_TRUE) return;
/* get owner */
owner = RTGUI_CONTAINER_OF(self, struct rtgui_widget, dc_type);
if (!RTGUI_WIDGET_IS_DC_VISIBLE(owner)) return;
/* convert logic to device */ /* convert logic to device */
x1 = x1 + dc->owner->extent.x1; x1 = x1 + owner->extent.x1;
x2 = x2 + dc->owner->extent.x1; x2 = x2 + owner->extent.x1;
y = y + dc->owner->extent.y1; y = y + owner->extent.y1;
if (dc->owner->clip.data == RT_NULL) if (owner->clip.data == RT_NULL)
{ {
rtgui_rect_t* prect; rtgui_rect_t* prect;
prect = &(dc->owner->clip.extents); prect = &(owner->clip.extents);
/* calculate vline intersect */ /* calculate vline intersect */
if (prect->y1 > y || prect->y2 <= y ) return; if (prect->y1 > y || prect->y2 <= y ) return;
@ -330,14 +353,14 @@ static void rtgui_dc_hw_draw_hline(struct rtgui_dc* self, int x1, int x2, int y)
if (prect->x2 < x2) x2 = prect->x2; if (prect->x2 < x2) x2 = prect->x2;
/* draw hline */ /* draw hline */
dc->device->draw_hline(&(dc->owner->gc.foreground), x1, x2, y); hw_driver->draw_hline(&(owner->gc.foreground), x1, x2, y);
} }
else for (index = 0; index < rtgui_region_num_rects(&(dc->owner->clip)); index ++) else for (index = 0; index < rtgui_region_num_rects(&(owner->clip)); index ++)
{ {
rtgui_rect_t* prect; rtgui_rect_t* prect;
register rt_base_t draw_x1, draw_x2; register rt_base_t draw_x1, draw_x2;
prect = ((rtgui_rect_t *)(dc->owner->clip.data + index + 1)); prect = ((rtgui_rect_t *)(owner->clip.data + index + 1));
draw_x1 = x1; draw_x1 = x1;
draw_x2 = x2; draw_x2 = x2;
@ -349,7 +372,7 @@ static void rtgui_dc_hw_draw_hline(struct rtgui_dc* self, int x1, int x2, int y)
if (prect->x2 < x2) draw_x2 = prect->x2; if (prect->x2 < x2) draw_x2 = prect->x2;
/* draw hline */ /* draw hline */
dc->device->draw_hline(&(dc->owner->gc.foreground), draw_x1, draw_x2, y); hw_driver->draw_hline(&(owner->gc.foreground), draw_x1, draw_x2, y);
} }
} }
@ -357,16 +380,19 @@ static void rtgui_dc_hw_fill_rect (struct rtgui_dc* self, struct rtgui_rect* rec
{ {
rtgui_color_t foreground; rtgui_color_t foreground;
register rt_base_t index; register rt_base_t index;
struct rtgui_dc_hw* dc; rtgui_widget_t *owner;
dc = (struct rtgui_dc_hw*)self; if (self == RT_NULL) return;
if (dc == RT_NULL || dc->visible != RT_TRUE) return;
/* get owner */
owner = RTGUI_CONTAINER_OF(self, struct rtgui_widget, dc_type);
if (!RTGUI_WIDGET_IS_DC_VISIBLE(owner)) return;
/* save foreground color */ /* save foreground color */
foreground = dc->owner->gc.foreground; foreground = owner->gc.foreground;
/* set background color as foreground color */ /* set background color as foreground color */
dc->owner->gc.foreground = dc->owner->gc.background; owner->gc.foreground = owner->gc.background;
/* fill rect */ /* fill rect */
for (index = rect->y1; index < rect->y2; index ++) for (index = rect->y1; index < rect->y2; index ++)
@ -375,7 +401,7 @@ static void rtgui_dc_hw_fill_rect (struct rtgui_dc* self, struct rtgui_rect* rec
} }
/* restore foreground color */ /* restore foreground color */
dc->owner->gc.foreground = foreground; owner->gc.foreground = foreground;
} }
static void rtgui_dc_hw_blit(struct rtgui_dc* dc, struct rtgui_point* dc_point, struct rtgui_dc* dest, rtgui_rect_t* rect) static void rtgui_dc_hw_blit(struct rtgui_dc* dc, struct rtgui_point* dc_point, struct rtgui_dc* dest, rtgui_rect_t* rect)
@ -386,51 +412,76 @@ static void rtgui_dc_hw_blit(struct rtgui_dc* dc, struct rtgui_point* dc_point,
static void rtgui_dc_hw_set_gc(struct rtgui_dc* self, rtgui_gc_t *gc) static void rtgui_dc_hw_set_gc(struct rtgui_dc* self, rtgui_gc_t *gc)
{ {
struct rtgui_dc_hw* dc = (struct rtgui_dc_hw*)self; rtgui_widget_t *owner;
if (self != RT_NULL) if (self == RT_NULL) return;
{
dc->owner->gc = *gc; /* get owner */
} owner = RTGUI_CONTAINER_OF(self, struct rtgui_widget, dc_type);
owner->gc = *gc;
} }
static rtgui_gc_t* rtgui_dc_hw_get_gc(struct rtgui_dc* self) static rtgui_gc_t* rtgui_dc_hw_get_gc(struct rtgui_dc* self)
{ {
struct rtgui_dc_hw* dc = (struct rtgui_dc_hw*)self; rtgui_widget_t *owner;
return self != RT_NULL? &(dc->owner->gc) : RT_NULL; if (self == RT_NULL)
{
rt_kprintf("why!!\n");
return RT_NULL;
}
/* get owner */
owner = RTGUI_CONTAINER_OF(self, struct rtgui_widget, dc_type);
return &(owner->gc);
} }
static rt_bool_t rtgui_dc_hw_get_visible(struct rtgui_dc* self) static rt_bool_t rtgui_dc_hw_get_visible(struct rtgui_dc* self)
{ {
struct rtgui_dc_hw* dc = (struct rtgui_dc_hw*)self; rtgui_widget_t *owner;
return dc->visible; if (self == RT_NULL) return RT_FALSE;
/* get owner */
owner = RTGUI_CONTAINER_OF(self, struct rtgui_widget, dc_type);
if (!RTGUI_WIDGET_IS_DC_VISIBLE(owner)) return RT_FALSE;
return RT_TRUE;
} }
static void rtgui_dc_hw_get_rect(struct rtgui_dc* self, rtgui_rect_t* rect) static void rtgui_dc_hw_get_rect(struct rtgui_dc* self, rtgui_rect_t* rect)
{ {
struct rtgui_dc_hw* dc = (struct rtgui_dc_hw*)self; rtgui_widget_t *owner;
rtgui_widget_get_rect(dc->owner, rect); if (self == RT_NULL) return;
/* get owner */
owner = RTGUI_CONTAINER_OF(self, struct rtgui_widget, dc_type);
rtgui_widget_get_rect(owner, rect);
} }
void rtgui_dc_hw_draw_raw_hline(struct rtgui_dc_hw* dc, rt_uint8_t* raw_ptr, int x1, int x2, int y) void rtgui_dc_hw_draw_raw_hline(struct rtgui_dc* self, rt_uint8_t* raw_ptr, int x1, int x2, int y)
{ {
register rt_base_t index; register rt_base_t index;
rtgui_widget_t *owner;
if (dc == RT_NULL || dc->visible != RT_TRUE) return; if (self == RT_NULL) return;
/* get owner */
owner = RTGUI_CONTAINER_OF(self, struct rtgui_widget, dc_type);
if (!RTGUI_WIDGET_IS_DC_VISIBLE(owner)) return;
/* convert logic to device */ /* convert logic to device */
x1 = x1 + dc->owner->extent.x1; x1 = x1 + owner->extent.x1;
x2 = x2 + dc->owner->extent.x1; x2 = x2 + owner->extent.x1;
y = y + dc->owner->extent.y1; y = y + owner->extent.y1;
if (dc->owner->clip.data == RT_NULL) if (owner->clip.data == RT_NULL)
{ {
rtgui_rect_t* prect; rtgui_rect_t* prect;
prect = &(dc->owner->clip.extents); prect = &(owner->clip.extents);
/* calculate hline intersect */ /* calculate hline intersect */
if (prect->y1 > y || prect->y2 <= y ) return; if (prect->y1 > y || prect->y2 <= y ) return;
@ -440,14 +491,14 @@ void rtgui_dc_hw_draw_raw_hline(struct rtgui_dc_hw* dc, rt_uint8_t* raw_ptr, int
if (prect->x2 < x2) x2 = prect->x2; if (prect->x2 < x2) x2 = prect->x2;
/* draw raw hline */ /* draw raw hline */
dc->device->draw_raw_hline(raw_ptr, x1, x2, y); hw_driver->draw_raw_hline(raw_ptr, x1, x2, y);
} }
else for (index = 0; index < rtgui_region_num_rects(&(dc->owner->clip)); index ++) else for (index = 0; index < rtgui_region_num_rects(&(owner->clip)); index ++)
{ {
rtgui_rect_t* prect; rtgui_rect_t* prect;
register rt_base_t draw_x1, draw_x2; register rt_base_t draw_x1, draw_x2;
prect = ((rtgui_rect_t *)(dc->owner->clip.data + index + 1)); prect = ((rtgui_rect_t *)(owner->clip.data + index + 1));
draw_x1 = x1; draw_x1 = x1;
draw_x2 = x2; draw_x2 = x2;
@ -459,6 +510,7 @@ void rtgui_dc_hw_draw_raw_hline(struct rtgui_dc_hw* dc, rt_uint8_t* raw_ptr, int
if (prect->x2 < x2) draw_x2 = prect->x2; if (prect->x2 < x2) draw_x2 = prect->x2;
/* draw raw hline */ /* draw raw hline */
dc->device->draw_raw_hline(raw_ptr + (draw_x1 - x1) * dc->device->byte_per_pixel, draw_x1, draw_x2, y); hw_driver->draw_raw_hline(raw_ptr + (draw_x1 - x1) * hw_driver->byte_per_pixel, draw_x1, draw_x2, y);
} }
} }

View File

@ -18,7 +18,7 @@ struct rtgui_image_hdc
rt_uint8_t *pixels; rt_uint8_t *pixels;
struct rtgui_filerw* filerw; struct rtgui_filerw* filerw;
struct rtgui_graphic_driver* hw_driver; const struct rtgui_graphic_driver* hw_driver;
}; };
static rt_bool_t rtgui_image_hdc_check(struct rtgui_filerw* file); static rt_bool_t rtgui_image_hdc_check(struct rtgui_filerw* file);
@ -172,7 +172,7 @@ static void rtgui_image_hdc_blit(struct rtgui_image* image, struct rtgui_dc* dc,
for (y = 0; y < h; y ++) for (y = 0; y < h; y ++)
{ {
rtgui_dc_hw_draw_raw_hline((struct rtgui_dc_hw*)dc, ptr, dst_rect->x1, dst_rect->x1 + w, dst_rect->y1 + y); rtgui_dc_hw_draw_raw_hline(dc, ptr, dst_rect->x1, dst_rect->x1 + w, dst_rect->y1 + y);
ptr += hdc->pitch; ptr += hdc->pitch;
} }
} }
@ -191,7 +191,7 @@ static void rtgui_image_hdc_blit(struct rtgui_image* image, struct rtgui_dc* dc,
if (rtgui_filerw_read(hdc->filerw, ptr, 1, hdc->pitch) != hdc->pitch) if (rtgui_filerw_read(hdc->filerw, ptr, 1, hdc->pitch) != hdc->pitch)
break; /* read data failed */ break; /* read data failed */
rtgui_dc_hw_draw_raw_hline((struct rtgui_dc_hw*)dc, ptr, dst_rect->x1, dst_rect->x1 + w, dst_rect->y1 + y); rtgui_dc_hw_draw_raw_hline(dc, ptr, dst_rect->x1, dst_rect->x1 + w, dst_rect->y1 + y);
} }
rtgui_free(ptr); rtgui_free(ptr);
@ -224,7 +224,7 @@ static void rtgui_image_hdcmm_blit(struct rtgui_image* image, struct rtgui_dc* d
for (y = 0; y < h; y ++) for (y = 0; y < h; y ++)
{ {
rtgui_dc_hw_draw_raw_hline((struct rtgui_dc_hw*)dc, ptr, dst_rect->x1, dst_rect->x1 + w, dst_rect->y1 + y); rtgui_dc_hw_draw_raw_hline(dc, ptr, dst_rect->x1, dst_rect->x1 + w, dst_rect->y1 + y);
ptr += hdc->pitch; ptr += hdc->pitch;
} }
} }

View File

@ -10,31 +10,19 @@
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
* 2010-04-10 Bernard first version * 2010-04-10 Bernard first version
* 2010-06-14 Bernard embedded hardware dc to each widget
*/ */
#ifndef __RTGUI_DC_HW_H__ #ifndef __RTGUI_DC_HW_H__
#define __RTGUI_DC_HW_H__ #define __RTGUI_DC_HW_H__
#include <rtgui/dc.h> #include <rtgui/dc.h>
/* hardware device context */
struct rtgui_dc_hw
{
struct rtgui_dc parent;
/* widget owner */
rtgui_widget_t* owner;
/* visible */
rt_bool_t visible;
/* display driver */
struct rtgui_graphic_driver* device;
};
/* create a hardware dc */ /* create a hardware dc */
struct rtgui_dc* rtgui_dc_hw_create(rtgui_widget_t* owner); struct rtgui_dc* rtgui_dc_hw_create(rtgui_widget_t* owner);
void rtgui_dc_hw_init(rtgui_widget_t* owner);
/* draw a hline with raw pixel data */ /* draw a hline with raw pixel data */
void rtgui_dc_hw_draw_raw_hline(struct rtgui_dc_hw* dc, rt_uint8_t* raw_ptr, int x1, int x2, int y); void rtgui_dc_hw_draw_raw_hline(struct rtgui_dc* dc, rt_uint8_t* raw_ptr, int x1, int x2, int y);
#endif #endif

View File

@ -49,13 +49,19 @@ struct rtgui_graphic_driver
rtgui_list_t list; rtgui_list_t list;
}; };
#ifdef RTGUI_USING_GRAPHIC_DRIVER_LIST
void rtgui_graphic_driver_add(struct rtgui_graphic_driver* driver); void rtgui_graphic_driver_add(struct rtgui_graphic_driver* driver);
void rtgui_graphic_driver_remove(struct rtgui_graphic_driver* driver); void rtgui_graphic_driver_remove(struct rtgui_graphic_driver* driver);
struct rtgui_graphic_driver* rtgui_graphic_driver_find(char* name); struct rtgui_graphic_driver* rtgui_graphic_driver_find(char* name);
struct rtgui_graphic_driver* rtgui_graphic_driver_get_default(void); #else
void rtgui_graphic_driver_add(const struct rtgui_graphic_driver* driver);
#endif
void rtgui_graphic_driver_get_rect(struct rtgui_graphic_driver *driver, rtgui_rect_t *rect); const struct rtgui_graphic_driver* rtgui_graphic_driver_get_default(void);
void rtgui_graphic_driver_get_rect(const struct rtgui_graphic_driver *driver, rtgui_rect_t *rect);
void rtgui_graphic_driver_get_default_rect(rtgui_rect_t *rect); void rtgui_graphic_driver_get_default_rect(rtgui_rect_t *rect);
#endif #endif

View File

@ -129,3 +129,4 @@ typedef enum RTGUI_MODAL_CODE rtgui_modal_code_t;
#include <rtgui/rtgui_object.h> #include <rtgui/rtgui_object.h>
#endif #endif

View File

@ -22,6 +22,8 @@ extern "C" {
#endif #endif
/* rtgui object type */ /* rtgui object type */
#define RTGUI_CONTAINER_OF(obj, type, member) \
((type *)((char *)(obj) - (unsigned long)(&((type *)0)->member)))
/** Casts the function pointer to an rtgui_constructor */ /** Casts the function pointer to an rtgui_constructor */
#define RTGUI_CONSTRUCTOR(constructor) ((rtgui_constructor_t)(constructor)) #define RTGUI_CONSTRUCTOR(constructor) ((rtgui_constructor_t)(constructor))

View File

@ -72,7 +72,9 @@ void rtgui_server_post_event(struct rtgui_event* event, rt_size_t size);
/* register or deregister panel in server */ /* register or deregister panel in server */
void rtgui_panel_register(char* name, rtgui_rect_t* extent); void rtgui_panel_register(char* name, rtgui_rect_t* extent);
void rtgui_panel_deregister(char* name); void rtgui_panel_deregister(char* name);
void rtgui_panel_set_default_focused(char* name); void rtgui_panel_set_default_focused(char* name);
void rtgui_panel_set_nofocused(char* name);
#endif #endif

View File

@ -25,12 +25,13 @@
extern "C" { extern "C" {
#endif #endif
#define RTGUI_WIDGET_FLAG_HIDE 0x01 #define RTGUI_WIDGET_FLAG_DEFAULT 0x0000
#define RTGUI_WIDGET_FLAG_DISABLE 0x02 #define RTGUI_WIDGET_FLAG_HIDE 0x0001
#define RTGUI_WIDGET_FLAG_FOCUS 0x04 #define RTGUI_WIDGET_FLAG_DISABLE 0x0002
#define RTGUI_WIDGET_FLAG_TRANSPARENT 0x08 #define RTGUI_WIDGET_FLAG_FOCUS 0x0004
#define RTGUI_WIDGET_FLAG_FOCUSABLE 0x10 #define RTGUI_WIDGET_FLAG_TRANSPARENT 0x0008
#define RTGUI_WIDGET_FLAG_DEFAULT 0x00 #define RTGUI_WIDGET_FLAG_FOCUSABLE 0x0010
#define RTGUI_WIDGET_FLAG_DC_VISIBLE 0x0100
#define RTGUI_WIDGET_UNHIDE(w) (w)->flag &= ~RTGUI_WIDGET_FLAG_HIDE #define RTGUI_WIDGET_UNHIDE(w) (w)->flag &= ~RTGUI_WIDGET_FLAG_HIDE
#define RTGUI_WIDGET_HIDE(w) (w)->flag |= RTGUI_WIDGET_FLAG_HIDE #define RTGUI_WIDGET_HIDE(w) (w)->flag |= RTGUI_WIDGET_FLAG_HIDE
@ -46,6 +47,11 @@ extern "C" {
#define RTGUI_WIDGET_IS_FOCUSABLE(w) ((w)->flag & RTGUI_WIDGET_FLAG_FOCUSABLE) #define RTGUI_WIDGET_IS_FOCUSABLE(w) ((w)->flag & RTGUI_WIDGET_FLAG_FOCUSABLE)
#define RTGUI_WIDGET_IS_DC_VISIBLE(w) ((w)->flag & RTGUI_WIDGET_FLAG_DC_VISIBLE)
#define RTGUI_WIDGET_DC_SET_VISIBLE(w) (w)->flag |= RTGUI_WIDGET_FLAG_DC_VISIBLE
#define RTGUI_WIDGET_DC_SET_UNVISIBLE(w) (w)->flag &= ~RTGUI_WIDGET_FLAG_DC_VISIBLE
#define RTGUI_WIDGET_DC(w) ((struct rtgui_dc*)&((w)->dc_type))
/* get rtgui widget object */ /* get rtgui widget object */
#define RTGUI_WIDGET_FOREGROUND(w) ((w)->gc.foreground) #define RTGUI_WIDGET_FOREGROUND(w) ((w)->gc.foreground)
#define RTGUI_WIDGET_BACKGROUND(w) ((w)->gc.background) #define RTGUI_WIDGET_BACKGROUND(w) ((w)->gc.background)
@ -75,19 +81,24 @@ struct rtgui_widget
/* widget flag */ /* widget flag */
rt_int32_t flag; rt_int32_t flag;
#ifndef RTGUI_USING_SMALL_SIZE
/* widget align */ /* hardware device context */
rt_int32_t align; rt_uint32_t dc_type;
#endif const struct rtgui_dc_engine* dc_engine;
/* the graphic context of widget */ /* the graphic context of widget */
rtgui_gc_t gc; rtgui_gc_t gc;
/* the widget extent */ /* the widget extent */
rtgui_rect_t extent; rtgui_rect_t extent;
#ifndef RTGUI_USING_SMALL_SIZE #ifndef RTGUI_USING_SMALL_SIZE
/* minimal width and height of widget */
rt_int16_t mini_width, mini_height; rt_int16_t mini_width, mini_height;
rt_int16_t margin, margin_style; rt_int16_t margin, margin_style;
/* widget align */
rt_int32_t align;
#endif #endif
/* the rect clip */ /* the rect clip */

View File

@ -13,6 +13,7 @@
*/ */
#include <rtgui/driver.h> #include <rtgui/driver.h>
#ifdef RTGUI_USING_GRAPHIC_DRIVER_LIST
struct rtgui_list_node _rtgui_graphic_driver_list = {RT_NULL}; struct rtgui_list_node _rtgui_graphic_driver_list = {RT_NULL};
void rtgui_graphic_driver_add(struct rtgui_graphic_driver* driver) void rtgui_graphic_driver_add(struct rtgui_graphic_driver* driver)
@ -50,10 +51,25 @@ struct rtgui_graphic_driver* rtgui_graphic_driver_get_default()
return rtgui_list_entry(_rtgui_graphic_driver_list.next, return rtgui_list_entry(_rtgui_graphic_driver_list.next,
struct rtgui_graphic_driver, list); struct rtgui_graphic_driver, list);
} }
#else
static const struct rtgui_graphic_driver* _default_graphic_driver = RT_NULL;
void rtgui_graphic_driver_get_rect(struct rtgui_graphic_driver *driver, rtgui_rect_t *rect) void rtgui_graphic_driver_add(const struct rtgui_graphic_driver* driver)
{ {
if (rect == RT_NULL || driver == RT_NULL) return; _default_graphic_driver = driver;
}
const struct rtgui_graphic_driver* rtgui_graphic_driver_get_default()
{
return _default_graphic_driver;
}
#endif
void rtgui_graphic_driver_get_rect(const struct rtgui_graphic_driver *driver, rtgui_rect_t *rect)
{
RT_ASSERT(rect != RT_NULL);
RT_ASSERT(driver != RT_NULL);
rect->x1 = rect->y1 = 0; rect->x1 = rect->y1 = 0;
rect->x2 = driver->width; rect->x2 = driver->width;
@ -65,3 +81,4 @@ void rtgui_graphic_driver_get_default_rect(rtgui_rect_t *rect)
/* return default the extent of default driver */ /* return default the extent of default driver */
rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), rect); rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), rect);
} }

View File

@ -129,7 +129,7 @@ static void rtgui_winrect_show (void);
#define WIN_MOVE_BORDER 4 #define WIN_MOVE_BORDER 4
void rtgui_mouse_init() void rtgui_mouse_init()
{ {
struct rtgui_graphic_driver* gd = rtgui_graphic_driver_get_default(); const struct rtgui_graphic_driver* gd = rtgui_graphic_driver_get_default();
_rtgui_cursor = (struct rtgui_cursor*) rtgui_malloc(sizeof(struct rtgui_cursor)); _rtgui_cursor = (struct rtgui_cursor*) rtgui_malloc(sizeof(struct rtgui_cursor));
rt_memset(_rtgui_cursor, 0, sizeof(struct rtgui_cursor)); rt_memset(_rtgui_cursor, 0, sizeof(struct rtgui_cursor));

View File

@ -54,6 +54,7 @@ void rtgui_panel_register(char* name, rtgui_rect_t* extent)
panel->extent = *extent; panel->extent = *extent;
panel->wm_thread = RT_NULL; panel->wm_thread = RT_NULL;
panel->is_focusable = RT_TRUE;
/* init list */ /* init list */
rtgui_list_init(&(panel->sibling)); rtgui_list_init(&(panel->sibling));
@ -90,6 +91,18 @@ void rtgui_panel_set_default_focused(char* name)
} }
} }
void rtgui_panel_set_nofocused(char* name)
{
extern struct rtgui_panel* rtgui_server_focus_panel;
struct rtgui_panel* panel;
panel = rtgui_panel_find(name);
if (panel != RT_NULL)
{
panel->is_focusable = RT_FALSE;
}
}
struct rtgui_panel* rtgui_panel_find(char* name) struct rtgui_panel* rtgui_panel_find(char* name)
{ {
struct rtgui_list_node* node; struct rtgui_list_node* node;
@ -304,3 +317,4 @@ void rtgui_panel_set_wm(rtgui_panel_t* panel, rt_thread_t wm)
panel->wm_thread = wm; panel->wm_thread = wm;
} }

View File

@ -47,6 +47,9 @@ struct rtgui_panel
/* the workbench manager thread */ /* the workbench manager thread */
rt_thread_t wm_thread; rt_thread_t wm_thread;
/* is focusable */
rt_bool_t is_focusable;
}; };
/* find panel by name */ /* find panel by name */
@ -66,3 +69,4 @@ void rtgui_panel_append_monitor_rect(rtgui_panel_t* panel, rt_thread_t tid, rtgu
void rtgui_panel_remove_monitor_rect(rtgui_panel_t* panel, rt_thread_t tid, rtgui_rect_t* rect); void rtgui_panel_remove_monitor_rect(rtgui_panel_t* panel, rt_thread_t tid, rtgui_rect_t* rect);
#endif #endif

View File

@ -182,7 +182,7 @@ void rtgui_server_handle_set_wm(struct rtgui_event_set_wm *event)
void rtgui_server_handle_update(struct rtgui_event_update_end* event) void rtgui_server_handle_update(struct rtgui_event_update_end* event)
{ {
struct rtgui_graphic_driver* driver = rtgui_graphic_driver_get_default(); const struct rtgui_graphic_driver* driver = rtgui_graphic_driver_get_default();
if (driver != RT_NULL) if (driver != RT_NULL)
{ {
driver->screen_update(&(event->rect)); driver->screen_update(&(event->rect));
@ -290,7 +290,7 @@ void rtgui_server_handle_mouse_btn(struct rtgui_event_mouse* event)
/* get the panel which contains the mouse */ /* get the panel which contains the mouse */
panel = rtgui_panel_get_contain(event->x, event->y); panel = rtgui_panel_get_contain(event->x, event->y);
if (panel != RT_NULL) if ((panel != RT_NULL) && (panel->is_focusable == RT_TRUE))
{ {
/* deactivate old window */ /* deactivate old window */
if (rtgui_server_focus_topwin != RT_NULL) if (rtgui_server_focus_topwin != RT_NULL)

View File

@ -60,6 +60,9 @@ static void _rtgui_widget_constructor(rtgui_widget_t *widget)
/* init clip information */ /* init clip information */
rtgui_region_init(&(widget->clip)); rtgui_region_init(&(widget->clip));
/* init hardware dc */
rtgui_dc_hw_init(widget);
} }
/* Destroys the widget */ /* Destroys the widget */