move dc operations as dc engine.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@756 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
bernard.xiong@gmail.com 2010-06-01 00:07:59 +00:00
parent a1ee019309
commit 3a13964efa
7 changed files with 87 additions and 184 deletions

View File

@ -27,7 +27,7 @@ void rtgui_dc_destory(struct rtgui_dc* dc)
{
if (dc == RT_NULL) return;
dc->fini(dc);
dc->engine->fini(dc);
rtgui_free(dc);
}
@ -77,7 +77,7 @@ void rtgui_dc_draw_line (struct rtgui_dc* dc, int x1, int y1, int x2, int y2)
px += sdx;
/* draw this point */
dc->draw_point(dc, px, py);
rtgui_dc_draw_point(dc, px, py);
}
}
else /* the line is more vertical than horizontal */
@ -93,7 +93,7 @@ void rtgui_dc_draw_line (struct rtgui_dc* dc, int x1, int y1, int x2, int y2)
py += sdy;
/* draw this point */
dc->draw_point(dc, px, py);
rtgui_dc_draw_point(dc, px, py);
}
}
}
@ -203,12 +203,37 @@ void rtgui_dc_draw_mono_bmp(struct rtgui_dc* dc, int x, int y, int w, int h, con
void rtgui_dc_draw_byte(struct rtgui_dc*dc, int x, int y, int h, const rt_uint8_t* data)
{
rtgui_dc_draw_mono_bmp(dc, x, y, 8, h, data);
int i, k;
/* draw byte */
for (i=0; i < h; i ++)
{
for (k=0; k < 8; k++)
{
if (((data[i] >> (7-k)) & 0x01) != 0)
{
rtgui_dc_draw_point(dc, x + k, y + i);
}
}
}
}
void rtgui_dc_draw_word(struct rtgui_dc*dc, int x, int y, int h, const rt_uint8_t* data)
{
rtgui_dc_draw_mono_bmp(dc, x, y, 16, h, data);
int i, j, k;
/* draw word */
for (i=0; i < h; i ++)
{
for (j=0; j < 2; j++)
for (k=0; k < 8; k++)
{
if (((data[i * 2 + j] >> (7-k)) & 0x01) != 0)
{
rtgui_dc_draw_point(dc, x + 8*j + k, y + i);
}
}
}
}
void rtgui_dc_draw_shaded_rect(struct rtgui_dc* dc, rtgui_rect_t* rect,
@ -320,94 +345,6 @@ void rtgui_dc_draw_vertical_line(struct rtgui_dc* dc, int x, int y1, int y2)
RTGUI_DC_FC(dc) = color;
}
void rtgui_dc_draw_arrow(struct rtgui_dc* dc, rtgui_rect_t* rect, int kind)
{
rt_int32_t i;
rt_int32_t x1, y1, x2, y2;
rtgui_rect_t r = {0, 0, 0, 0};
static const rt_uint8_t ARROW_WIDTH = 7;
static const rt_uint8_t ARROW_LENGTH = 4;
x1 = y1 = 0;
switch (kind)
{
case RTGUI_ARRAW_UP:
case RTGUI_ARRAW_DOWN:
r.x2 = ARROW_WIDTH;
r.y2 = ARROW_LENGTH;
break;
case RTGUI_ARRAW_LEFT:
case RTGUI_ARRAW_RIGHT:
r.x2 = ARROW_LENGTH;
r.y2 = ARROW_WIDTH;
break;
}
rtgui_rect_moveto_align(rect, &r, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
switch (kind)
{
case RTGUI_ARRAW_UP:
x1 = r.x1 + (ARROW_WIDTH - 1)/2;;
y1 = r.y1;
break;
case RTGUI_ARRAW_DOWN:
x1 = r.x1 + (ARROW_WIDTH - 1)/2;
y1 = r.y1 + ARROW_LENGTH - 1;
break;
case RTGUI_ARRAW_LEFT:
x1 = r.x1;
y1 = r.y1 + (ARROW_WIDTH - 1)/2;
break;
case RTGUI_ARRAW_RIGHT:
x1 = r.x1 + ARROW_LENGTH - 1;
y1 = r.y1 + (ARROW_WIDTH - 1)/2;
break;
default:
return;
}
x2 = x1;
y2 = y1;
for (i = 0; i < ARROW_LENGTH; i++)
{
rtgui_dc_draw_line(dc, x1, y1, x2, y2);
switch (kind)
{
case RTGUI_ARRAW_UP:
x1 --;
x2 ++;
y1 ++;
y2 ++;
break;
case RTGUI_ARRAW_DOWN:
x1 --;
x2 ++;
y1 --;
y2 --;
break;
case RTGUI_ARRAW_LEFT:
y1 --;
y2 ++;
x1 ++;
x2 ++;
break;
case RTGUI_ARRAW_RIGHT:
y1 --;
y2 ++;
x1 --;
x2 --;
break;
}
}
}
void rtgui_dc_draw_polygon(struct rtgui_dc* dc, const int *vx, const int *vy, int count)
{
int i;
@ -524,44 +461,6 @@ void rtgui_dc_fill_polygon(struct rtgui_dc* dc, const int* vx, const int* vy, in
}
}
#if 1
void rtgui_dc_draw_circle(struct rtgui_dc *dc,
int xCenter, int yCenter, int radius)
{
int x =0;
int y = radius;
int p = 1-radius;
rtgui_dc_draw_point(dc,xCenter+x,yCenter+y);
rtgui_dc_draw_point(dc,xCenter-x,yCenter+y);
rtgui_dc_draw_point(dc,xCenter+x,yCenter-y);
rtgui_dc_draw_point(dc,xCenter-x,yCenter-y);
rtgui_dc_draw_point(dc,xCenter+y,yCenter+x);
rtgui_dc_draw_point(dc,xCenter-y,yCenter+x);
rtgui_dc_draw_point(dc,xCenter+y,yCenter-x);
rtgui_dc_draw_point(dc,xCenter-y,yCenter-x);
while(x<y){
x++;
if(p<0)
p+=2*x+1;
else{
y--;
p+=2*(x-y)+1;
}
rtgui_dc_draw_point(dc,xCenter+x,yCenter+y);
rtgui_dc_draw_point(dc,xCenter-x,yCenter+y);
rtgui_dc_draw_point(dc,xCenter+x,yCenter-y);
rtgui_dc_draw_point(dc,xCenter-x,yCenter-y);
rtgui_dc_draw_point(dc,xCenter+y,yCenter+x);
rtgui_dc_draw_point(dc,xCenter-y,yCenter+x);
rtgui_dc_draw_point(dc,xCenter+y,yCenter-x);
rtgui_dc_draw_point(dc,xCenter-y,yCenter-x);
}
}
#else
void rtgui_dc_draw_circle(struct rtgui_dc* dc, int x, int y, int r)
{
rt_int16_t cx = 0;
@ -637,7 +536,6 @@ void rtgui_dc_draw_circle(struct rtgui_dc* dc, int x, int y, int r)
cx++;
}while (cx <= cy);
}
#endif
void rtgui_dc_fill_circle(struct rtgui_dc* dc, rt_int16_t x, rt_int16_t y, rt_int16_t r)
{

View File

@ -50,33 +50,31 @@ static rtgui_gc_t* rtgui_dc_buffer_get_gc(struct rtgui_dc* dc);
static rt_bool_t rtgui_dc_buffer_get_visible(struct rtgui_dc* dc);
static void rtgui_dc_buffer_get_rect(struct rtgui_dc* dc, rtgui_rect_t* rect);
static void rtgui_dc_buffer_init(struct rtgui_dc_buffer* dc)
const static struct rtgui_dc_engine dc_buffer_engine =
{
if (dc == RT_NULL) return;
rtgui_dc_buffer_draw_point,
rtgui_dc_buffer_draw_color_point,
rtgui_dc_buffer_draw_vline,
rtgui_dc_buffer_draw_hline,
rtgui_dc_buffer_fill_rect,
rtgui_dc_buffer_blit,
dc->parent.type = RTGUI_DC_BUFFER;
dc->parent.draw_point = rtgui_dc_buffer_draw_point;
dc->parent.draw_color_point = rtgui_dc_buffer_draw_color_point;
dc->parent.draw_hline = rtgui_dc_buffer_draw_hline;
dc->parent.draw_vline = rtgui_dc_buffer_draw_vline;
dc->parent.fill_rect = rtgui_dc_buffer_fill_rect;
dc->parent.blit = rtgui_dc_buffer_blit;
rtgui_dc_buffer_set_gc,
rtgui_dc_buffer_get_gc,
dc->parent.set_gc = rtgui_dc_buffer_set_gc;
dc->parent.get_gc = rtgui_dc_buffer_get_gc;
rtgui_dc_buffer_get_visible,
rtgui_dc_buffer_get_rect,
dc->parent.get_visible= rtgui_dc_buffer_get_visible;
dc->parent.get_rect = rtgui_dc_buffer_get_rect;
dc->parent.fini = rtgui_dc_buffer_fini;
}
rtgui_dc_buffer_fini,
};
struct rtgui_dc* rtgui_dc_buffer_create(int w, int h)
{
struct rtgui_dc_buffer* dc;
dc = (struct rtgui_dc_buffer*)rtgui_malloc(sizeof(struct rtgui_dc_buffer));
rtgui_dc_buffer_init(dc);
dc->parent.type = RTGUI_DC_BUFFER;
dc->parent.engine = &dc_buffer_engine;
dc->gc.foreground = default_foreground;
dc->gc.background = default_background;
dc->gc.font = rtgui_font_default();

View File

@ -45,26 +45,23 @@ void rtgui_dc_end_drawing(struct rtgui_dc* dc)
}
}
void rtgui_dc_hw_init(struct rtgui_dc_hw* dc)
const static struct rtgui_dc_engine dc_hw_engine =
{
if (dc == RT_NULL) return;
rtgui_dc_hw_draw_point,
rtgui_dc_hw_draw_color_point,
rtgui_dc_hw_draw_vline,
rtgui_dc_hw_draw_hline,
rtgui_dc_hw_fill_rect,
rtgui_dc_hw_blit,
dc->parent.type = RTGUI_DC_HW;
dc->parent.draw_point = rtgui_dc_hw_draw_point;
dc->parent.draw_color_point = rtgui_dc_hw_draw_color_point;
dc->parent.draw_hline = rtgui_dc_hw_draw_hline;
dc->parent.draw_vline = rtgui_dc_hw_draw_vline;
dc->parent.fill_rect = rtgui_dc_hw_fill_rect ;
dc->parent.blit = rtgui_dc_hw_blit;
rtgui_dc_hw_set_gc,
rtgui_dc_hw_get_gc,
dc->parent.set_gc = rtgui_dc_hw_set_gc;
dc->parent.get_gc = rtgui_dc_hw_get_gc;
rtgui_dc_hw_get_visible,
rtgui_dc_hw_get_rect,
dc->parent.get_visible= rtgui_dc_hw_get_visible;
dc->parent.get_rect = rtgui_dc_hw_get_rect;
dc->parent.fini = rtgui_dc_hw_fini;
}
rtgui_dc_hw_fini,
};
extern struct rt_mutex cursor_mutex;
#define dc_set_foreground(c) dc->owner->gc.foreground = c
@ -82,7 +79,8 @@ struct rtgui_dc* rtgui_dc_hw_create(rtgui_widget_t* owner)
/* malloc a dc object */
dc = (struct rtgui_dc_hw*) rtgui_malloc(sizeof(struct rtgui_dc_hw));
rtgui_dc_hw_init(dc);
dc->parent.type = RTGUI_DC_HW;
dc->parent.engine = &dc_hw_engine;
dc->owner = owner;
dc->visible = RT_TRUE;
dc->device = rtgui_graphic_driver_get_default();

View File

@ -150,7 +150,7 @@ static void rtgui_image_hdc_blit(struct rtgui_image* image, struct rtgui_dc* dc,
RT_ASSERT(image != RT_NULL || dc != RT_NULL || dst_rect != RT_NULL);
/* this dc is not visible */
if (dc->get_visible(dc) != RT_TRUE) return;
if (rtgui_dc_get_visible(dc) != RT_TRUE) return;
hdc = (struct rtgui_image_hdc*) image->data;
RT_ASSERT(hdc != RT_NULL);
@ -207,7 +207,7 @@ static void rtgui_image_hdcmm_blit(struct rtgui_image* image, struct rtgui_dc* d
RT_ASSERT(image != RT_NULL || dc != RT_NULL || dst_rect != RT_NULL);
/* this dc is not visible */
if ((dc->get_visible(dc) != RT_TRUE) || (dc->type != RTGUI_DC_HW)) return;
if (rtgui_dc_get_visible(dc) != RT_TRUE || (dc->type != RTGUI_DC_HW)) return;
hdc = (struct rtgui_image_hdcmm*) image;
RT_ASSERT(hdc != RT_NULL);

View File

@ -26,12 +26,8 @@ enum rtgui_dc_type
RTGUI_DC_IMLIB2,
};
/* the abstract device context */
struct rtgui_dc
struct rtgui_dc_engine
{
/* type of device context */
rt_uint32_t type;
/* interface */
void (*draw_point)(struct rtgui_dc* dc, int x, int y);
void (*draw_color_point)(struct rtgui_dc* dc, int x, int y, rtgui_color_t color);
@ -53,6 +49,16 @@ struct rtgui_dc
rt_bool_t (*fini )(struct rtgui_dc* dc);
};
/* the abstract device context */
struct rtgui_dc
{
/* type of device context */
rt_uint32_t type;
/* dc engine */
const struct rtgui_dc_engine* engine;
};
#define RTGUI_DC_FC(dc) (rtgui_dc_get_gc(dc)->foreground)
#define RTGUI_DC_BC(dc) (rtgui_dc_get_gc(dc)->background)
#define RTGUI_DC_FONT(dc) (rtgui_dc_get_gc(dc)->font)
@ -82,7 +88,6 @@ void rtgui_dc_draw_word(struct rtgui_dc*dc, int x, int y, int h, const rt_uint8_
void rtgui_dc_draw_border(struct rtgui_dc* dc, rtgui_rect_t* rect, int flag);
void rtgui_dc_draw_horizontal_line(struct rtgui_dc* dc, int x1, int x2, int y);
void rtgui_dc_draw_vertical_line(struct rtgui_dc* dc, int x, int y1, int y2);
void rtgui_dc_draw_arrow(struct rtgui_dc* dc, rtgui_rect_t* rect, int kind);
void rtgui_dc_draw_focus_rect(struct rtgui_dc* dc, rtgui_rect_t* rect);
void rtgui_dc_draw_polygon(struct rtgui_dc* dc, const int *vx, const int *vy, int count);
@ -107,7 +112,7 @@ void rtgui_dc_fill_ellipse(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_i
*/
rt_inline void rtgui_dc_draw_point(struct rtgui_dc* dc, int x, int y)
{
dc->draw_point(dc, x, y);
dc->engine->draw_point(dc, x, y);
}
/*
@ -115,7 +120,7 @@ rt_inline void rtgui_dc_draw_point(struct rtgui_dc* dc, int x, int y)
*/
rt_inline void rtgui_dc_draw_color_point(struct rtgui_dc* dc, int x, int y, rtgui_color_t color)
{
dc->draw_color_point(dc, x, y, color);
dc->engine->draw_color_point(dc, x, y, color);
}
/*
@ -123,7 +128,7 @@ rt_inline void rtgui_dc_draw_color_point(struct rtgui_dc* dc, int x, int y, rtgu
*/
rt_inline void rtgui_dc_draw_vline(struct rtgui_dc* dc, int x, int y1, int y2)
{
dc->draw_vline(dc, x, y1, y2);
dc->engine->draw_vline(dc, x, y1, y2);
}
/*
@ -131,7 +136,7 @@ rt_inline void rtgui_dc_draw_vline(struct rtgui_dc* dc, int x, int y1, int y2)
*/
rt_inline void rtgui_dc_draw_hline(struct rtgui_dc* dc, int x1, int x2, int y)
{
dc->draw_hline(dc, x1, x2, y);
dc->engine->draw_hline(dc, x1, x2, y);
}
/*
@ -139,7 +144,7 @@ rt_inline void rtgui_dc_draw_hline(struct rtgui_dc* dc, int x1, int x2, int y)
*/
rt_inline void rtgui_dc_fill_rect (struct rtgui_dc* dc, struct rtgui_rect* rect)
{
dc->fill_rect(dc, rect);
dc->engine->fill_rect(dc, rect);
}
/*
@ -149,7 +154,7 @@ rt_inline void rtgui_dc_blit(struct rtgui_dc* dc, struct rtgui_point* dc_point,
{
if (dest == RT_NULL || rect == RT_NULL) return;
dc->blit(dc, dc_point, dest, rect);
dc->engine->blit(dc, dc_point, dest, rect);
}
/*
@ -157,7 +162,7 @@ rt_inline void rtgui_dc_blit(struct rtgui_dc* dc, struct rtgui_point* dc_point,
*/
rt_inline void rtgui_dc_set_gc(struct rtgui_dc* dc, rtgui_gc_t* gc)
{
dc->set_gc(dc, gc);
dc->engine->set_gc(dc, gc);
}
/*
@ -165,7 +170,7 @@ rt_inline void rtgui_dc_set_gc(struct rtgui_dc* dc, rtgui_gc_t* gc)
*/
rt_inline rtgui_gc_t *rtgui_dc_get_gc(struct rtgui_dc* dc)
{
return dc->get_gc(dc);
return dc->engine->get_gc(dc);
}
/*
@ -173,7 +178,7 @@ rt_inline rtgui_gc_t *rtgui_dc_get_gc(struct rtgui_dc* dc)
*/
rt_inline rt_bool_t rtgui_dc_get_visible(struct rtgui_dc* dc)
{
return dc->get_visible(dc);
return dc->engine->get_visible(dc);
}
/*
@ -183,7 +188,7 @@ rt_inline void rtgui_dc_get_rect(struct rtgui_dc*dc, rtgui_rect_t* rect)
{
if (rect != RT_NULL)
{
dc->get_rect(dc, rect);
dc->engine->get_rect(dc, rect);
}
}

View File

@ -75,8 +75,10 @@ struct rtgui_widget
/* widget flag */
rt_int32_t flag;
#ifndef RTGUI_USING_SMALL_SIZE
/* widget align */
rt_int32_t align;
#endif
/* the graphic context of widget */
rtgui_gc_t gc;

View File

@ -30,7 +30,9 @@ static void _rtgui_widget_constructor(rtgui_widget_t *widget)
widget->gc.background = default_background;
widget->gc.font = rtgui_font_default();
widget->gc.textalign = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_TOP;
#ifndef RTGUI_USING_SMALL_SIZE
widget->align = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_TOP;
#endif
/* set parent and toplevel root */
widget->parent = RT_NULL;