提交 490196b1 编写于 作者: B Bernard Xiong

[GUI Engine] Add RTGUI as a GUI Engine

上级 55bbe729
# RT-Thread building script for component
from building import *
cwd = GetCurrentDir()
src = Split('''
src/asc12font.c
src/asc16font.c
src/blit.c
src/box.c
src/color.c
src/container.c
src/dc.c
src/dc_blend.c
src/dc_buffer.c
src/dc_client.c
src/dc_hw.c
src/dc_rotozoom.c
src/dc_trans.c
src/filerw.c
src/font.c
src/font_bmp.c
src/font_fnt.c
src/font_freetype.c
src/font_hz_bmp.c
src/font_hz_file.c
src/hz12font.c
src/hz16font.c
src/image.c
src/image_bmp.c
src/image_hdc.c
src/image_jpg.c
src/image_png.c
src/image_xpm.c
src/matrix.c
src/mouse.c
src/region.c
src/rtgui_app.c
src/rtgui_driver.c
src/rtgui_object.c
src/rtgui_system.c
src/server.c
src/title.c
src/topwin.c
src/widget.c
src/window.c
''')
CPPPATH = [cwd + '/include']
group = DefineGroup('GUIEngine', src, depend = ['RT_USING_GUIENGINE'], CPPPATH = CPPPATH)
Return('group')
/*
* File : blit.h
* This file is part of RT-Thread GUI
* COPYRIGHT (C) 2006 - 2013, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2013-10-04 Bernard porting SDL software render to RT-Thread GUI
*/
/*
Simple DirectMedia Layer
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef __RTGUI_BLIT_H__
#define __RTGUI_BLIT_H__
#include <rtgui/rtgui.h>
/* Assemble R-G-B values into a specified pixel format and store them */
#define RGB565_FROM_RGB(Pixel, r, g, b) \
{ \
Pixel = ((r>>3)<<11)|((g>>2)<<5)|(b>>3); \
}
#define BGR565_FROM_RGB(Pixel, r, g, b) \
{ \
Pixel = ((b>>3)<<11)|((g>>2)<<5)|(r>>3); \
}
#define RGB555_FROM_RGB(Pixel, r, g, b) \
{ \
Pixel = ((r>>3)<<10)|((g>>3)<<5)|(b>>3); \
}
#define RGB888_FROM_RGB(Pixel, r, g, b) \
{ \
Pixel = (r<<16)|(g<<8)|b; \
}
#define ARGB8888_FROM_RGBA(Pixel, r, g, b, a) \
{ \
Pixel = (a<<24)|(r<<16)|(g<<8)|b; \
}
#define RGBA8888_FROM_RGBA(Pixel, r, g, b, a) \
{ \
Pixel = (r<<24)|(g<<16)|(b<<8)|a; \
}
#define ABGR8888_FROM_RGBA(Pixel, r, g, b, a) \
{ \
Pixel = (a<<24)|(b<<16)|(g<<8)|r; \
}
#define BGRA8888_FROM_RGBA(Pixel, r, g, b, a) \
{ \
Pixel = (b<<24)|(g<<16)|(r<<8)|a; \
}
#define ARGB2101010_FROM_RGBA(Pixel, r, g, b, a) \
{ \
r = r ? ((r << 2) | 0x3) : 0; \
g = g ? ((g << 2) | 0x3) : 0; \
b = b ? ((b << 2) | 0x3) : 0; \
a = (a * 3) / 255; \
Pixel = (a<<30)|(r<<20)|(g<<10)|b; \
}
/* Load pixel of the specified format from a buffer and get its R-G-B values */
#define RGB_FROM_RGB565(Pixel, r, g, b) \
{ \
r = rtgui_blit_expand_byte[3][((Pixel&0xF800)>>11)]; \
g = rtgui_blit_expand_byte[2][((Pixel&0x07E0)>>5)]; \
b = rtgui_blit_expand_byte[3][(Pixel&0x001F)]; \
}
#define RGB_FROM_BGR565(Pixel, r, g, b) \
{ \
b = rtgui_blit_expand_byte[3][((Pixel&0xF800)>>11)]; \
g = rtgui_blit_expand_byte[2][((Pixel&0x07E0)>>5)]; \
r = rtgui_blit_expand_byte[3][(Pixel&0x001F)]; \
}
#define RGB_FROM_RGB555(Pixel, r, g, b) \
{ \
r = rtgui_blit_expand_byte[3][((Pixel&0x7C00)>>10)]; \
g = rtgui_blit_expand_byte[3][((Pixel&0x03E0)>>5)]; \
b = rtgui_blit_expand_byte[3][(Pixel&0x001F)]; \
}
#define RGB_FROM_RGB888(Pixel, r, g, b) \
{ \
r = ((Pixel&0xFF0000)>>16); \
g = ((Pixel&0xFF00)>>8); \
b = (Pixel&0xFF); \
}
#define RGBA_FROM_RGBA8888(Pixel, r, g, b, a) \
{ \
r = (Pixel>>24); \
g = ((Pixel>>16)&0xFF); \
b = ((Pixel>>8)&0xFF); \
a = (Pixel&0xFF); \
}
#define RGBA_FROM_ARGB8888(Pixel, r, g, b, a) \
{ \
r = ((Pixel>>16)&0xFF); \
g = ((Pixel>>8)&0xFF); \
b = (Pixel&0xFF); \
a = (Pixel>>24); \
}
#define RGBA_FROM_ABGR8888(Pixel, r, g, b, a) \
{ \
r = (Pixel&0xFF); \
g = ((Pixel>>8)&0xFF); \
b = ((Pixel>>16)&0xFF); \
a = (Pixel>>24); \
}
#define RGBA_FROM_BGRA8888(Pixel, r, g, b, a) \
{ \
r = ((Pixel>>8)&0xFF); \
g = ((Pixel>>16)&0xFF); \
b = (Pixel>>24); \
a = (Pixel&0xFF); \
}
#define RGBA_FROM_ARGB2101010(Pixel, r, g, b, a) \
{ \
r = ((Pixel>>22)&0xFF); \
g = ((Pixel>>12)&0xFF); \
b = ((Pixel>>2)&0xFF); \
a = rtgui_blit_expand_byte[6][(Pixel>>30)]; \
}
/* 4-times unrolled loop */
#define DUFFS_LOOP4(pixel_copy_increment, width) \
{ int n = (width+3)/4; \
switch (width & 3) { \
case 0: do { pixel_copy_increment; \
case 3: pixel_copy_increment; \
case 2: pixel_copy_increment; \
case 1: pixel_copy_increment; \
} while (--n > 0); \
} \
}
/* 8-times unrolled loop */
#define DUFFS_LOOP8(pixel_copy_increment, width) \
{ int n = (width+7)/8; \
switch (width & 7) { \
case 0: do { pixel_copy_increment; \
case 7: pixel_copy_increment; \
case 6: pixel_copy_increment; \
case 5: pixel_copy_increment; \
case 4: pixel_copy_increment; \
case 3: pixel_copy_increment; \
case 2: pixel_copy_increment; \
case 1: pixel_copy_increment; \
} while ( --n > 0 ); \
} \
}
/* Use the 8-times version of the loop by default */
#define DUFFS_LOOP(pixel_copy_increment, width) \
DUFFS_LOOP8(pixel_copy_increment, width)
struct rtgui_blit_info
{
rt_uint8_t *src;
int src_w, src_h;
int src_pitch;
int src_skip;
rt_uint8_t *dst;
int dst_w, dst_h;
int dst_pitch;
int dst_skip;
rt_uint8_t src_fmt;
rt_uint8_t dst_fmt;
rt_uint8_t r, g, b, a;
};
struct rtgui_blit_info_src
{
rt_uint8_t *src;
int src_w, src_h;
int src_skip;
rt_uint8_t src_fmt;
};
extern const rt_uint8_t* rtgui_blit_expand_byte[9];
typedef void (*rtgui_blit_line_func)(rt_uint8_t *dst, rt_uint8_t *src, int line);
rtgui_blit_line_func rtgui_blit_line_get(int dst_bpp, int src_bpp);
rtgui_blit_line_func rtgui_blit_line_get_inv(int dst_bpp, int src_bpp);
void rtgui_blit(struct rtgui_blit_info * info);
#endif
/*
* File : color.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2009-10-16 Bernard first version
* 2012-01-24 onelife add mono color support
*/
#ifndef __RTGUI_COLOR_H__
#define __RTGUI_COLOR_H__
#include <rtgui/rtgui.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* The color used in the GUI:
*
* bit bit
* RGB565 15 R,G,B 0
* BGR565 15 B,G,R 0
* RGB888 23 R,G,B 0
* ARGB888 31 A,R,G,B 0
* RGBA888 31 R,G,B,A 0
* ABGR888 31 A,B,G,R 0
*
* The rtgui_color is defined as ARGB888.
* bit31 A,R,G,B bit0
*/
#define RTGUI_ARGB(a, r, g, b) \
((rtgui_color_t)(((rt_uint8_t)(b)|\
(((unsigned long)(rt_uint8_t)(g))<<8))|\
(((unsigned long)(rt_uint8_t)(r))<<16)|\
(((unsigned long)(rt_uint8_t)(a))<<24)))
#define RTGUI_RGB(r, g, b) RTGUI_ARGB(255, (r), (g), (b))
#define RTGUI_RGB_B(c) ((c) & 0xff)
#define RTGUI_RGB_G(c) (((c) >> 8) & 0xff)
#define RTGUI_RGB_R(c) (((c) >> 16) & 0xff)
#define RTGUI_RGB_A(c) (((c) >> 24) & 0xff)
extern const rtgui_color_t default_foreground;
extern const rtgui_color_t default_background;
/* it's better use these color definitions */
#define RED RTGUI_RGB(0xff, 0x00, 0x00)
#define GREEN RTGUI_RGB(0x00, 0xff, 0x00)
#define BLUE RTGUI_RGB(0x00, 0x00, 0xff)
#define BLACK RTGUI_RGB(0x00, 0x00, 0x00)
#define WHITE RTGUI_RGB(0xff, 0xff, 0xff)
#define HIGH_LIGHT RTGUI_RGB(0xfc, 0xfc, 0xfc)
#define DARK_GREY RTGUI_RGB(0x7f, 0x7f, 0x7f)
#define LIGHT_GREY RTGUI_RGB(0xc0, 0xc0, 0xc0)
#define TRANSPARENT RTGUI_ARGB(0, 0, 0, 0)
extern const rtgui_color_t red;
extern const rtgui_color_t green;
extern const rtgui_color_t blue;
extern const rtgui_color_t black;
extern const rtgui_color_t white;
extern const rtgui_color_t high_light;
extern const rtgui_color_t dark_grey;
extern const rtgui_color_t light_grey;
/*
* RTGUI default color format: ARGB
* AAAA AAAA RRRR RRRR GGGG GGGG BBBB BBBB
* 31 0
*/
/* convert rtgui color to mono */
rt_inline rt_uint8_t rtgui_color_to_mono(rtgui_color_t c)
{
rt_uint8_t pixel;
pixel = (RTGUI_RGB_R(c) | RTGUI_RGB_G(c) | RTGUI_RGB_B(c)) ? 0x01 : 0x00;
return pixel;
}
rt_inline rtgui_color_t rtgui_color_from_mono(rt_uint8_t pixel)
{
rtgui_color_t color;
if (pixel)
{
color = white;
}
else
{
color = black;
}
return color;
}
/* convert rtgui color to RRRRRGGGGGGBBBBB */
rt_inline rt_uint16_t rtgui_color_to_565(rtgui_color_t c)
{
rt_uint16_t pixel;
pixel = (rt_uint16_t)(((RTGUI_RGB_R(c) >> 3) << 11) | ((RTGUI_RGB_G(c) >> 2) << 5) | (RTGUI_RGB_B(c) >> 3));
return pixel;
}
rt_inline rtgui_color_t rtgui_color_from_565(rt_uint16_t pixel)
{
rt_uint16_t r, g, b;
rtgui_color_t color;
r = (pixel >> 11) & 0x1f;
g = (pixel >> 5) & 0x3f;
b = pixel & 0x1f;
color = b * 255 / 31 + ((g * 255 / 63) << 8) + ((r * 255 / 31) << 16);
return color;
}
/* convert rtgui color to BBBBBGGGGGGRRRRR */
rt_inline rt_uint16_t rtgui_color_to_565p(rtgui_color_t c)
{
rt_uint16_t pixel;
pixel = (rt_uint16_t)(((RTGUI_RGB_B(c) >> 3) << 11) | ((RTGUI_RGB_G(c) >> 2) << 5) | (RTGUI_RGB_R(c) >> 3));
return pixel;
}
rt_inline rtgui_color_t rtgui_color_from_565p(rt_uint16_t pixel)
{
rt_uint8_t r, g, b;
rtgui_color_t color;
r = pixel & 0x1f;
g = (pixel >> 5) & 0x3f;
b = (pixel >> 11) & 0x1f;
color = b * 255 / 31 + ((g * 255 / 63) << 8) + ((r * 255 / 31) << 16);
return color;
}
/* convert rtgui color to RGB */
rt_inline rt_uint32_t rtgui_color_to_888(rtgui_color_t c)
{
rt_uint32_t pixel;
pixel = RTGUI_RGB_R(c) << 16 | RTGUI_RGB_G(c) << 8 | RTGUI_RGB_B(c);
return pixel;
}
rt_inline rtgui_color_t rtgui_color_from_888(rt_uint32_t pixel)
{
rtgui_color_t color;
color = RTGUI_RGB(((pixel >> 16) & 0xff), ((pixel >> 8) & 0xff), pixel & 0xff);
return color;
}
/* get the bits of specified pixle format */
rt_uint8_t rtgui_color_get_bits(rt_uint8_t pixel_format) RTGUI_PURE;
/* get the bytes of specified pixle format */
rt_uint8_t rtgui_color_get_bpp(rt_uint8_t pixel_format) RTGUI_PURE;
#ifdef __cplusplus
}
#endif
#endif
/*
* File : dc.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2009-10-16 Bernard first version
*/
#ifndef __RTGUI_DC_H__
#define __RTGUI_DC_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <rtgui/rtgui.h>
#include <rtgui/font.h>
#include <rtgui/driver.h>
#include <rtgui/widgets/widget.h>
#define RTGUI_DC(dc) ((struct rtgui_dc*)(dc))
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
enum rtgui_dc_type
{
RTGUI_DC_HW,
RTGUI_DC_CLIENT,
RTGUI_DC_BUFFER,
};
struct rtgui_dc_engine
{
/* 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);
void (*draw_vline)(struct rtgui_dc *dc, int x, int y1, int y2);
void (*draw_hline)(struct rtgui_dc *dc, int x1, int x2, int y);
void (*fill_rect)(struct rtgui_dc *dc, rtgui_rect_t *rect);
void (*blit_line)(struct rtgui_dc *dc, int x1, int x2, int y, rt_uint8_t *line_data);
void (*blit)(struct rtgui_dc *dc, struct rtgui_point *dc_point, struct rtgui_dc *dest, rtgui_rect_t *rect);
rt_bool_t (*fini)(struct rtgui_dc *dc);
};
/*
* The abstract device context
*
* Normally, a DC is a drawable canvas, user can draw point/line/cycle etc
* on the DC.
*
* There are several kinds of DC:
* - Hardware DC;
* - Client DC;
* - Buffer DC;
*/
struct rtgui_dc
{
/* type of device context */
rt_uint32_t type;
/* dc engine */
const struct rtgui_dc_engine *engine;
};
/*
* The hardware device context
*
* The hardware DC is a context based on hardware device, for examle the
* LCD device. The operations on the hardware DC are reflected to the real
* hardware.
*
*/
struct rtgui_dc_hw
{
struct rtgui_dc parent;
rtgui_widget_t *owner;
const struct rtgui_graphic_driver *hw_driver;
};
/**
* The buffer dc is a device context with memory buffer.
*
* All the operations on this device context is reflected to the memory buffer.
*/
struct rtgui_dc_buffer
{
struct rtgui_dc parent;
/* graphic context */
rtgui_gc_t gc;
/* pixel format */
rt_uint8_t pixel_format;
rt_uint8_t blend_mode; /* RTGUI_BLENDMODE: None/Blend/Add/Mod */
/* width and height */
rt_uint16_t width, height;
/* pitch */
rt_uint16_t pitch;
/* pixel data */
rt_uint8_t *pixel;
};
#define RTGUI_DC_FC(dc) (rtgui_dc_get_gc(RTGUI_DC(dc))->foreground)
#define RTGUI_DC_BC(dc) (rtgui_dc_get_gc(RTGUI_DC(dc))->background)
#define RTGUI_DC_FONT(dc) (rtgui_dc_get_gc(RTGUI_DC(dc))->font)
#define RTGUI_DC_TEXTALIGN(dc) (rtgui_dc_get_gc(RTGUI_DC(dc))->textalign)
/* create a buffer dc */
struct rtgui_dc *rtgui_dc_buffer_create(int width, int height);
struct rtgui_dc *rtgui_dc_buffer_create_pixformat(rt_uint8_t pixel_format, int w, int h);
struct rtgui_dc *rtgui_dc_buffer_create_from_dc(struct rtgui_dc* dc);
/* create a widget dc */
struct rtgui_dc *rtgui_dc_widget_create(struct rtgui_widget * owner);
/* begin and end a drawing */
struct rtgui_dc *rtgui_dc_begin_drawing(rtgui_widget_t *owner);
void rtgui_dc_end_drawing(struct rtgui_dc *dc);
/* destroy a dc */
void rtgui_dc_destory(struct rtgui_dc *dc);
rt_uint8_t *rtgui_dc_buffer_get_pixel(struct rtgui_dc *dc);
void rtgui_dc_draw_line(struct rtgui_dc *dc, int x1, int y1, int x2, int y2);
void rtgui_dc_draw_rect(struct rtgui_dc *dc, struct rtgui_rect *rect);
void rtgui_dc_fill_rect_forecolor(struct rtgui_dc *dc, struct rtgui_rect *rect);
void rtgui_dc_draw_round_rect(struct rtgui_dc *dc, struct rtgui_rect *rect, int r);
void rtgui_dc_fill_round_rect(struct rtgui_dc *dc, struct rtgui_rect *rect, int r);
/** Fill a vertical gradient rect from @c1 to @c2 */
void rtgui_dc_fill_gradient_rectv(struct rtgui_dc *dc, rtgui_rect_t *rect,
rtgui_color_t c1, rtgui_color_t c2);
void rtgui_dc_draw_annulus(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t r1, rt_int16_t r2, rt_int16_t start, rt_int16_t end);
void rtgui_dc_draw_pie(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t r, rt_int16_t start, rt_int16_t end);
void rtgui_dc_fill_pie(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t r, rt_int16_t start, rt_int16_t end);
void rtgui_dc_draw_text(struct rtgui_dc *dc, const char *text, struct rtgui_rect *rect);
void rtgui_dc_draw_text_stroke(struct rtgui_dc *dc, const char *text, struct rtgui_rect *rect,
rtgui_color_t color_stroke, rtgui_color_t color_core);
void rtgui_dc_draw_mono_bmp(struct rtgui_dc *dc, int x, int y, int w, int h, const rt_uint8_t *data);
void rtgui_dc_draw_byte(struct rtgui_dc *dc, int x, int y, int h, const rt_uint8_t *data);
void rtgui_dc_draw_word(struct rtgui_dc *dc, int x, int y, int h, const rt_uint8_t *data);
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_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);
void rtgui_dc_fill_polygon(struct rtgui_dc *dc, const int *vx, const int *vy, int count);
void rtgui_dc_draw_circle(struct rtgui_dc *dc, int x, int y, int r);
void rtgui_dc_fill_circle(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t r);
void rtgui_dc_draw_arc(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t r, rt_int16_t start, rt_int16_t end);
void rtgui_dc_draw_ellipse(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t rx, rt_int16_t ry);
void rtgui_dc_fill_ellipse(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t rx, rt_int16_t ry);
/* alpha blending functions */
void rtgui_dc_draw_aa_line(struct rtgui_dc * dst,int x1,int y1,int x2,int y2);
void rtgui_dc_draw_aa_lines(struct rtgui_dc * dst,const struct rtgui_point * points,int count);
void rtgui_dc_blend_point(struct rtgui_dc * dst,int x,int y,enum RTGUI_BLENDMODE blendMode,rt_uint8_t r,rt_uint8_t g,rt_uint8_t b,rt_uint8_t a);
void rtgui_dc_blend_points(struct rtgui_dc * dst,const rtgui_point_t * points,int count,enum RTGUI_BLENDMODE blendMode,rt_uint8_t r,rt_uint8_t g,rt_uint8_t b,rt_uint8_t a);
void rtgui_dc_blend_line(struct rtgui_dc * dst,int x1,int y1,int x2,int y2,enum RTGUI_BLENDMODE blendMode,rtgui_color_t color);
void rtgui_dc_blend_lines(struct rtgui_dc * dst,const rtgui_point_t * points,int count,enum RTGUI_BLENDMODE blendMode,rtgui_color_t color);
void rtgui_dc_blend_fill_rect(struct rtgui_dc * dst,const rtgui_rect_t * rect,enum RTGUI_BLENDMODE blendMode,rtgui_color_t color);
void rtgui_dc_blend_fill_rects(struct rtgui_dc * dst,const rtgui_rect_t * rects,int count,enum RTGUI_BLENDMODE blendMode,rtgui_color_t color);
void rtgui_dc_draw_aa_circle(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t r);
void rtgui_dc_draw_aa_ellipse(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t rx, rt_int16_t ry);
int rtgui_dc_draw_thick_line(struct rtgui_dc * dst, rt_int16_t x1, rt_int16_t y1, rt_int16_t x2, rt_int16_t y2, rt_uint8_t width);
/*
* dc inline function
*
* Note:
* In order to improve drawing speed, put most of common function of dc to inline
*/
/*
* draw a point on dc
*/
rt_inline void rtgui_dc_draw_point(struct rtgui_dc *dc, int x, int y)
{
dc->engine->draw_point(dc, x, y);
}
/*
* draw a color point on dc
*/
rt_inline void rtgui_dc_draw_color_point(struct rtgui_dc *dc, int x, int y, rtgui_color_t color)
{
dc->engine->draw_color_point(dc, x, y, color);
}
/*
* draw a vertical line on dc
*/
rt_inline void rtgui_dc_draw_vline(struct rtgui_dc *dc, int x, int y1, int y2)
{
dc->engine->draw_vline(dc, x, y1, y2);
}
/*
* draw a horizontal line on dc
*/
rt_inline void rtgui_dc_draw_hline(struct rtgui_dc *dc, int x1, int x2, int y)
{
dc->engine->draw_hline(dc, x1, x2, y);
}
/*
* fill a rect with background color
*/
rt_inline void rtgui_dc_fill_rect(struct rtgui_dc *dc, struct rtgui_rect *rect)
{
dc->engine->fill_rect(dc, rect);
}
/*
* blit a dc (x, y) on another dc(rect)
*/
rt_inline void rtgui_dc_blit(struct rtgui_dc *dc, struct rtgui_point *dc_point, struct rtgui_dc *dest, rtgui_rect_t *rect)
{
dc->engine->blit(dc, dc_point, dest, rect);
}
/* set gc of dc */
void rtgui_dc_set_gc(struct rtgui_dc *dc, rtgui_gc_t *gc);
/* get gc of dc */
rtgui_gc_t *rtgui_dc_get_gc(struct rtgui_dc *dc);
/* get visible status of dc */
rt_bool_t rtgui_dc_get_visible(struct rtgui_dc *dc);
/* get rect of dc */
void rtgui_dc_get_rect(struct rtgui_dc *dc, rtgui_rect_t *rect);
/* get pixel format */
rt_uint8_t rtgui_dc_get_pixel_format(struct rtgui_dc *dc);
/* coordinate conversion */
void rtgui_dc_logic_to_device(struct rtgui_dc* dc, struct rtgui_point *point);
void rtgui_dc_rect_to_device(struct rtgui_dc* dc, struct rtgui_rect* rect);
/* dc rotation and zoom operations */
struct rtgui_dc *rtgui_dc_shrink(struct rtgui_dc *dc, int factorx, int factory);
struct rtgui_dc *rtgui_dc_zoom(struct rtgui_dc *dc, double zoomx, double zoomy, int smooth);
struct rtgui_dc *rtgui_dc_rotozoom(struct rtgui_dc *dc, double angle, double zoomx, double zoomy, int smooth);
#ifdef __cplusplus
}
#endif
#endif
/*
* File : dc_buffer.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2010, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2010-04-10 Bernard first version
* 2010-06-14 Bernard embedded hardware dc to each widget
* 2010-08-09 Bernard rename hardware dc to client dc
*/
#ifndef __RTGUI_DC_CLIENT_H__
#define __RTGUI_DC_CLIENT_H__
#include <rtgui/dc.h>
/* create a hardware dc */
struct rtgui_dc *rtgui_dc_client_create(rtgui_widget_t *owner);
void rtgui_dc_client_init(rtgui_widget_t *owner);
#endif
/*
* File : dc_blend.c
* This file is part of RT-Thread GUI
* COPYRIGHT (C) 2006 - 2013, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2013-10-04 Bernard porting SDL software render to RT-Thread GUI
*/
/*
Simple DirectMedia Layer
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef __DC_DRAW_H__
#define __DC_DRAW_H__
#include <rtgui/blit.h>
/* This code assumes that r, g, b, a are the source color,
* and in the blend and add case, the RGB values are premultiplied by a.
*/
#define DRAW_MUL(_a, _b) (((unsigned)(_a)*(_b))/256)
#define DRAW_FASTSETPIXEL(type) \
*pixel = (type) color
#define DRAW_FASTSETPIXEL1 DRAW_FASTSETPIXEL(rt_uint8_t)
#define DRAW_FASTSETPIXEL2 DRAW_FASTSETPIXEL(rt_uint16_t)
#define DRAW_FASTSETPIXEL4 DRAW_FASTSETPIXEL(rt_uint32_t)
#define DRAW_FASTSETPIXELXY(x, y, type, bpp, color) \
*(type *)(_dc_get_pixel(dst, x, y))= (type) color
#define DRAW_FASTSETPIXELXY1(x, y) DRAW_FASTSETPIXELXY(x, y, rt_uint8_t, 1, color)
#define DRAW_FASTSETPIXELXY2(x, y) DRAW_FASTSETPIXELXY(x, y, rt_uint16_t, 2, color)
#define DRAW_FASTSETPIXELXY4(x, y) DRAW_FASTSETPIXELXY(x, y, rt_uint32_t, 4, color)
#define DRAW_SETPIXEL(setpixel) \
do { \
unsigned sr = r, sg = g, sb = b, sa = a; (void) sa; \
setpixel; \
} while (0)
#define DRAW_SETPIXEL_BLEND(getpixel, setpixel) \
do { \
unsigned sr, sg, sb, sa; (void) sa; \
getpixel; \
sr = DRAW_MUL(inva, sr) + r; \
sg = DRAW_MUL(inva, sg) + g; \
sb = DRAW_MUL(inva, sb) + b; \
setpixel; \
} while (0)
#define DRAW_SETPIXEL_ADD(getpixel, setpixel) \
do { \
unsigned sr, sg, sb, sa; (void) sa; \
getpixel; \
sr += r; if (sr > 0xff) sr = 0xff; \
sg += g; if (sg > 0xff) sg = 0xff; \
sb += b; if (sb > 0xff) sb = 0xff; \
setpixel; \
} while (0)
#define DRAW_SETPIXEL_MOD(getpixel, setpixel) \
do { \
unsigned sr, sg, sb, sa; (void) sa; \
getpixel; \
sr = DRAW_MUL(sr, r); \
sg = DRAW_MUL(sg, g); \
sb = DRAW_MUL(sb, b); \
setpixel; \
} while (0)
#define DRAW_SETPIXELXY(x, y, type, bpp, op) \
do { \
type *pixel = (type *)(_dc_get_pixel(dst, x, y));\
op; \
} while (0)
/*
* Define draw operators for RGB555
*/
#define DRAW_SETPIXEL_RGB555 \
DRAW_SETPIXEL(RGB555_FROM_RGB(*pixel, sr, sg, sb))
#define DRAW_SETPIXEL_BLEND_RGB555 \
DRAW_SETPIXEL_BLEND(RGB_FROM_RGB555(*pixel, sr, sg, sb), \
RGB555_FROM_RGB(*pixel, sr, sg, sb))
#define DRAW_SETPIXEL_ADD_RGB555 \
DRAW_SETPIXEL_ADD(RGB_FROM_RGB555(*pixel, sr, sg, sb), \
RGB555_FROM_RGB(*pixel, sr, sg, sb))
#define DRAW_SETPIXEL_MOD_RGB555 \
DRAW_SETPIXEL_MOD(RGB_FROM_RGB555(*pixel, sr, sg, sb), \
RGB555_FROM_RGB(*pixel, sr, sg, sb))
#define DRAW_SETPIXELXY_RGB555(x, y) \
DRAW_SETPIXELXY(x, y, rt_uint16_t, 2, DRAW_SETPIXEL_RGB555)
#define DRAW_SETPIXELXY_BLEND_RGB555(x, y) \
DRAW_SETPIXELXY(x, y, rt_uint16_t, 2, DRAW_SETPIXEL_BLEND_RGB555)
#define DRAW_SETPIXELXY_ADD_RGB555(x, y) \
DRAW_SETPIXELXY(x, y, rt_uint16_t, 2, DRAW_SETPIXEL_ADD_RGB555)
#define DRAW_SETPIXELXY_MOD_RGB555(x, y) \
DRAW_SETPIXELXY(x, y, rt_uint16_t, 2, DRAW_SETPIXEL_MOD_RGB555)
/*
* Define draw operators for RGB565
*/
#define DRAW_SETPIXEL_RGB565 \
DRAW_SETPIXEL(RGB565_FROM_RGB(*pixel, sr, sg, sb))
#define DRAW_SETPIXEL_BLEND_RGB565 \
DRAW_SETPIXEL_BLEND(RGB_FROM_RGB565(*pixel, sr, sg, sb), \
RGB565_FROM_RGB(*pixel, sr, sg, sb))
#define DRAW_SETPIXEL_ADD_RGB565 \
DRAW_SETPIXEL_ADD(RGB_FROM_RGB565(*pixel, sr, sg, sb), \
RGB565_FROM_RGB(*pixel, sr, sg, sb))
#define DRAW_SETPIXEL_MOD_RGB565 \
DRAW_SETPIXEL_MOD(RGB_FROM_RGB565(*pixel, sr, sg, sb), \
RGB565_FROM_RGB(*pixel, sr, sg, sb))
#define DRAW_SETPIXELXY_RGB565(x, y) \
DRAW_SETPIXELXY(x, y, rt_uint16_t, 2, DRAW_SETPIXEL_RGB565)
#define DRAW_SETPIXELXY_BLEND_RGB565(x, y) \
DRAW_SETPIXELXY(x, y, rt_uint16_t, 2, DRAW_SETPIXEL_BLEND_RGB565)
#define DRAW_SETPIXELXY_ADD_RGB565(x, y) \
DRAW_SETPIXELXY(x, y, rt_uint16_t, 2, DRAW_SETPIXEL_ADD_RGB565)
#define DRAW_SETPIXELXY_MOD_RGB565(x, y) \
DRAW_SETPIXELXY(x, y, rt_uint16_t, 2, DRAW_SETPIXEL_MOD_RGB565)
/*
* Define draw operators for BGR565
*/
#define DRAW_SETPIXEL_BGR565 \
DRAW_SETPIXEL(BGR565_FROM_RGB(*pixel, sr, sg, sb))
#define DRAW_SETPIXEL_BLEND_BGR565 \
DRAW_SETPIXEL_BLEND(RGB_FROM_BGR565(*pixel, sr, sg, sb), \
BGR565_FROM_RGB(*pixel, sr, sg, sb))
#define DRAW_SETPIXEL_ADD_BGR565 \
DRAW_SETPIXEL_ADD(RGB_FROM_BGR565(*pixel, sr, sg, sb), \
BGR565_FROM_RGB(*pixel, sr, sg, sb))
#define DRAW_SETPIXEL_MOD_BGR565 \
DRAW_SETPIXEL_MOD(RGB_FROM_BGR565(*pixel, sr, sg, sb), \
BGR565_FROM_RGB(*pixel, sr, sg, sb))
#define DRAW_SETPIXELXY_BGR565(x, y) \
DRAW_SETPIXELXY(x, y, rt_uint16_t, 2, DRAW_SETPIXEL_BGR565)
#define DRAW_SETPIXELXY_BLEND_BGR565(x, y) \
DRAW_SETPIXELXY(x, y, rt_uint16_t, 2, DRAW_SETPIXEL_BLEND_BGR565)
#define DRAW_SETPIXELXY_ADD_BGR565(x, y) \
DRAW_SETPIXELXY(x, y, rt_uint16_t, 2, DRAW_SETPIXEL_ADD_BGR565)
#define DRAW_SETPIXELXY_MOD_BGR565(x, y) \
DRAW_SETPIXELXY(x, y, rt_uint16_t, 2, DRAW_SETPIXEL_MOD_BGR565)
/*
* Define draw operators for RGB888
*/
#define DRAW_SETPIXEL_RGB888 \
DRAW_SETPIXEL(RGB888_FROM_RGB(*pixel, sr, sg, sb))
#define DRAW_SETPIXEL_BLEND_RGB888 \
DRAW_SETPIXEL_BLEND(RGB_FROM_RGB888(*pixel, sr, sg, sb), \
RGB888_FROM_RGB(*pixel, sr, sg, sb))
#define DRAW_SETPIXEL_ADD_RGB888 \
DRAW_SETPIXEL_ADD(RGB_FROM_RGB888(*pixel, sr, sg, sb), \
RGB888_FROM_RGB(*pixel, sr, sg, sb))
#define DRAW_SETPIXEL_MOD_RGB888 \
DRAW_SETPIXEL_MOD(RGB_FROM_RGB888(*pixel, sr, sg, sb), \
RGB888_FROM_RGB(*pixel, sr, sg, sb))
#define DRAW_SETPIXELXY_RGB888(x, y) \
DRAW_SETPIXELXY(x, y, rt_uint32_t, 4, DRAW_SETPIXEL_RGB888)
#define DRAW_SETPIXELXY_BLEND_RGB888(x, y) \
DRAW_SETPIXELXY(x, y, rt_uint32_t, 4, DRAW_SETPIXEL_BLEND_RGB888)
#define DRAW_SETPIXELXY_ADD_RGB888(x, y) \
DRAW_SETPIXELXY(x, y, rt_uint32_t, 4, DRAW_SETPIXEL_ADD_RGB888)
#define DRAW_SETPIXELXY_MOD_RGB888(x, y) \
DRAW_SETPIXELXY(x, y, rt_uint32_t, 4, DRAW_SETPIXEL_MOD_RGB888)
/*
* Define draw operators for ARGB8888
*/
#define DRAW_SETPIXEL_ARGB8888 \
DRAW_SETPIXEL(ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
#define DRAW_SETPIXEL_BLEND_ARGB8888 \
DRAW_SETPIXEL_BLEND(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \
ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
#define DRAW_SETPIXEL_ADD_ARGB8888 \
DRAW_SETPIXEL_ADD(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \
ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
#define DRAW_SETPIXEL_MOD_ARGB8888 \
DRAW_SETPIXEL_MOD(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \
ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
#define DRAW_SETPIXELXY_ARGB8888(x, y) \
DRAW_SETPIXELXY(x, y, rt_uint32_t, 4, DRAW_SETPIXEL_ARGB8888)
#define DRAW_SETPIXELXY_BLEND_ARGB8888(x, y) \
DRAW_SETPIXELXY(x, y, rt_uint32_t, 4, DRAW_SETPIXEL_BLEND_ARGB8888)
#define DRAW_SETPIXELXY_ADD_ARGB8888(x, y) \
DRAW_SETPIXELXY(x, y, rt_uint32_t, 4, DRAW_SETPIXEL_ADD_ARGB8888)
#define DRAW_SETPIXELXY_MOD_ARGB8888(x, y) \
DRAW_SETPIXELXY(x, y, rt_uint32_t, 4, DRAW_SETPIXEL_MOD_ARGB8888)
/*
* Define line drawing macro
*/
#define ABS(_x) ((_x) < 0 ? -(_x) : (_x))
/* Horizontal line */
#define HLINE(type, op, draw_end) \
{ \
int length; \
type *pixel; \
if (x1 <= x2) { \
pixel = (type *)_dc_get_pixel(dst, x1, y1); \
length = draw_end ? (x2-x1+1) : (x2-x1); \
} else { \
pixel = (type *)_dc_get_pixel(dst, x2, y1); \
if (!draw_end) { \
++pixel; \
} \
length = draw_end ? (x1-x2+1) : (x1-x2); \
} \
while (length--) { \
op; \
++pixel; \
} \
}
/* Vertical line */
#define VLINE(type, op, draw_end) \
{ \
int length; \
int pitch = _dc_get_pitch(dst)/(_UI_BITBYTES(_dc_get_bits_per_pixel(dst))); \
type *pixel; \
if (y1 <= y2) { \
pixel = (type *)_dc_get_pixel(dst, x1, y1); \
length = draw_end ? (y2-y1+1) : (y2-y1); \
} else { \
pixel = (type *)_dc_get_pixel(dst, x1, y2); \
if (!draw_end) { \
pixel += pitch; \
} \
length = draw_end ? (y1-y2+1) : (y1-y2); \
} \
while (length--) { \
op; \
pixel += pitch; \
} \
}
/* Diagonal line */
#define DLINE(type, op, draw_end) \
{ \
int length; \
int pitch = _dc_get_pitch(dst)/(_UI_BITBYTES(_dc_get_bits_per_pixel(dst))); \
type *pixel; \
if (y1 <= y2) { \
pixel = (type *)_dc_get_pixel(dst, x1, y1); \
if (x1 <= x2) { \
++pitch; \
} else { \
--pitch; \
} \
length = (y2-y1); \
} else { \
pixel = (type *)_dc_get_pixel(dst, x2, y2); \
if (x2 <= x1) { \
++pitch; \
} else { \
--pitch; \
} \
if (!draw_end) { \
pixel += pitch; \
} \
length = (y1-y2); \
} \
if (draw_end) { \
++length; \
} \
while (length--) { \
op; \
pixel += pitch; \
} \
}
/* Bresenham's line algorithm */
#define BLINE(x1, y1, x2, y2, op, draw_end) \
{ \
int i, deltax, deltay, numpixels; \
int d, dinc1, dinc2; \
int x, xinc1, xinc2; \
int y, yinc1, yinc2; \
\
deltax = ABS(x2 - x1); \
deltay = ABS(y2 - y1); \
\
if (deltax >= deltay) { \
numpixels = deltax + 1; \
d = (2 * deltay) - deltax; \
dinc1 = deltay * 2; \
dinc2 = (deltay - deltax) * 2; \
xinc1 = 1; \
xinc2 = 1; \
yinc1 = 0; \
yinc2 = 1; \
} else { \
numpixels = deltay + 1; \
d = (2 * deltax) - deltay; \
dinc1 = deltax * 2; \
dinc2 = (deltax - deltay) * 2; \
xinc1 = 0; \
xinc2 = 1; \
yinc1 = 1; \
yinc2 = 1; \
} \
\
if (x1 > x2) { \
xinc1 = -xinc1; \
xinc2 = -xinc2; \
} \
if (y1 > y2) { \
yinc1 = -yinc1; \
yinc2 = -yinc2; \
} \
\
x = x1; \
y = y1; \
\
if (!draw_end) { \
--numpixels; \
} \
for (i = 0; i < numpixels; ++i) { \
op(x, y); \
if (d < 0) { \
d += dinc1; \
x += xinc1; \
y += yinc1; \
} else { \
d += dinc2; \
x += xinc2; \
y += yinc2; \
} \
} \
}
/* Xiaolin Wu's line algorithm, based on Michael Abrash's implementation */
#define WULINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \
{ \
rt_uint16_t ErrorAdj, ErrorAcc; \
rt_uint16_t ErrorAccTemp, Weighting; \
int DeltaX, DeltaY, Temp, XDir; \
unsigned r, g, b, a, inva; \
\
/* remove compiling warning */ \
r = 0; g = 0; b = 0; a = 0; \
inva = 0; inva = inva; \
/* Draw the initial pixel, which is always exactly intersected by \
the line and so needs no weighting */ \
opaque_op(x1, y1); \
\
/* Draw the final pixel, which is always exactly intersected by the line \
and so needs no weighting */ \
if (draw_end) { \
opaque_op(x2, y2); \
} \
\
/* Make sure the line runs top to bottom */ \
if (y1 > y2) { \
Temp = y1; y1 = y2; y2 = Temp; \
Temp = x1; x1 = x2; x2 = Temp; \
} \
DeltaY = y2 - y1; \
\
if ((DeltaX = x2 - x1) >= 0) { \
XDir = 1; \
} else { \
XDir = -1; \
DeltaX = -DeltaX; /* make DeltaX positive */ \
} \
\
/* line is not horizontal, diagonal, or vertical */ \
ErrorAcc = 0; /* initialize the line error accumulator to 0 */ \
\
/* Is this an X-major or Y-major line? */ \
if (DeltaY > DeltaX) { \
/* Y-major line; calculate 16-bit fixed-point fractional part of a \
pixel that X advances each time Y advances 1 pixel, truncating the \
result so that we won't overrun the endpoint along the X axis */ \
ErrorAdj = ((unsigned long) DeltaX << 16) / (unsigned long) DeltaY; \
/* Draw all pixels other than the first and last */ \
while (--DeltaY) { \
ErrorAccTemp = ErrorAcc; /* remember current accumulated error */ \
ErrorAcc += ErrorAdj; /* calculate error for next pixel */ \
if (ErrorAcc <= ErrorAccTemp) { \
/* The error accumulator turned over, so advance the X coord */ \
x1 += XDir; \
} \
y1++; /* Y-major, so always advance Y */ \
/* The IntensityBits most significant bits of ErrorAcc give us the \
intensity weighting for this pixel, and the complement of the \
weighting for the paired pixel */ \
Weighting = ErrorAcc >> 8; \
{ \
a = DRAW_MUL(_a, (Weighting ^ 255)); \
r = DRAW_MUL(_r, a); \
g = DRAW_MUL(_g, a); \
b = DRAW_MUL(_b, a); \
inva = (a ^ 0xFF); \
blend_op(x1, y1); \
} \
{ \
a = DRAW_MUL(_a, Weighting); \
r = DRAW_MUL(_r, a); \
g = DRAW_MUL(_g, a); \
b = DRAW_MUL(_b, a); \
inva = (a ^ 0xFF); \
blend_op(x1 + XDir, y1); \
} \
} \
} else { \
/* X-major line; calculate 16-bit fixed-point fractional part of a \
pixel that Y advances each time X advances 1 pixel, truncating the \
result to avoid overrunning the endpoint along the X axis */ \
ErrorAdj = ((unsigned long) DeltaY << 16) / (unsigned long) DeltaX; \
/* Draw all pixels other than the first and last */ \
while (--DeltaX) { \
ErrorAccTemp = ErrorAcc; /* remember currrent accumulated error */ \
ErrorAcc += ErrorAdj; /* calculate error for next pixel */ \
if (ErrorAcc <= ErrorAccTemp) { \
/* The error accumulator turned over, so advance the Y coord */ \
y1++; \
} \
x1 += XDir; /* X-major, so always advance X */ \
/* The IntensityBits most significant bits of ErrorAcc give us the \
intensity weighting for this pixel, and the complement of the \
weighting for the paired pixel */ \
Weighting = ErrorAcc >> 8; \
{ \
a = DRAW_MUL(_a, (Weighting ^ 255)); \
r = DRAW_MUL(_r, a); \
g = DRAW_MUL(_g, a); \
b = DRAW_MUL(_b, a); \
inva = (a ^ 0xFF); \
blend_op(x1, y1); \
} \
{ \
a = DRAW_MUL(_a, Weighting); \
r = DRAW_MUL(_r, a); \
g = DRAW_MUL(_g, a); \
b = DRAW_MUL(_b, a); \
inva = (a ^ 0xFF); \
blend_op(x1, y1 + 1); \
} \
} \
} \
}
#define AALINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \
WULINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end)
/*
* Define fill rect macro
*/
#define FILLRECT(type, op) \
do { \
int width = rect->x2 - rect->x1; \
int height = rect->y2 - rect->y1; \
int pitch = _dc_get_pitch(dst)/(_UI_BITBYTES(_dc_get_bits_per_pixel(dst))); \
int skip = pitch - width; \
type *pixel = (type *)_dc_get_pixel(dst, rect->x1, rect->y1); \
while (height--) { \
{ int n = (width+3)/4; \
switch (width & 3) { \
case 0: do { op; pixel++; \
case 3: op; pixel++; \
case 2: op; pixel++; \
case 1: op; pixel++; \
} while ( --n > 0 ); \
} \
} \
pixel += skip; \
} \
} while (0)
#endif
/*
* File : dc_buffer.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2010, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2010-04-10 Bernard first version
* 2010-06-14 Bernard embedded hardware dc to each widget
*/
#ifndef __RTGUI_DC_HW_H__
#define __RTGUI_DC_HW_H__
#include <rtgui/dc.h>
/* create a hardware dc */
struct rtgui_dc *rtgui_dc_hw_create(rtgui_widget_t *owner);
#endif
#ifndef __RTGUI_DC_TRANS_H__
#define __RTGUI_DC_TRANS_H__
#include <rtgui/dc.h>
#include <rtgui/matrix.h>
struct rtgui_dc_trans;
/** Create a dc translator on the dc @owner
*
* @return RT_NULL is there is no memory.
*/
struct rtgui_dc_trans* rtgui_dc_trans_create(struct rtgui_dc *owner);
/** Rotate the dc clockwise.
*
* @param degree the degree to rotate.
*/
void rtgui_dc_trans_rotate(struct rtgui_dc_trans *dct, double degree);
void rtgui_dc_trans_set_aa(struct rtgui_dc_trans *dct, int use_aa);
void rtgui_dc_trans_scale(struct rtgui_dc_trans *dct, double sx, double sy);
/** Move the dc
*
* The unit of @dx and @dy is pixel.
*/
void rtgui_dc_trans_move(struct rtgui_dc_trans *dct, int dx, int dy);
void rtgui_dc_trans_get_new_wh(struct rtgui_dc_trans *dct, int *new_w, int *new_h);
void rtgui_dc_trans_blit(struct rtgui_dc_trans *dct,
struct rtgui_point *dc_point,
struct rtgui_dc *dest,
struct rtgui_rect *rect);
void rtgui_dc_trans_destroy(struct rtgui_dc_trans *dct);
#endif
/*
* File : driver.h
* This file is part of RTGUI in RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2009-10-04 Bernard first version
*/
#ifndef __RTGUI_DRIVER_H__
#define __RTGUI_DRIVER_H__
#include <rtgui/list.h>
#include <rtgui/color.h>
/* graphic driver operations */
struct rtgui_graphic_driver_ops
{
/* set and get pixel in (x, y) */
void (*set_pixel)(rtgui_color_t *c, int x, int y);
void (*get_pixel)(rtgui_color_t *c, int x, int y);
void (*draw_hline)(rtgui_color_t *c, int x1, int x2, int y);
void (*draw_vline)(rtgui_color_t *c, int x , int y1, int y2);
/* draw raw hline */
void (*draw_raw_hline)(rt_uint8_t *pixels, int x1, int x2, int y);
};
/* graphic extension operations */
struct rtgui_graphic_ext_ops
{
/* some 2D operations */
void (*draw_line)(rtgui_color_t *c, int x1, int y1, int x2, int y2);
void (*draw_rect)(rtgui_color_t *c, int x1, int y1, int x2, int y2);
void (*fill_rect)(rtgui_color_t *c, int x1, int y1, int x2, int y2);
void (*draw_circle)(rtgui_color_t *c, int x, int y, int r);
void (*fill_circle)(rtgui_color_t *c, int x, int y, int r);
void (*draw_ellipse)(rtgui_color_t *c, int x, int y, int rx, int ry);
void (*fill_ellipse)(rtgui_color_t *c, int x, int y, int rx, int ry);
};
struct rtgui_graphic_driver
{
/* pixel format and byte per pixel */
rt_uint8_t pixel_format;
rt_uint8_t bits_per_pixel;
rt_uint16_t pitch;
/* screen width and height */
rt_uint16_t width;
rt_uint16_t height;
/* framebuffer address and ops */
rt_uint8_t *framebuffer;
struct rt_device* device;
const struct rtgui_graphic_driver_ops *ops;
const struct rtgui_graphic_ext_ops *ext_ops;
};
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_screen_update(const struct rtgui_graphic_driver *driver, rtgui_rect_t *rect);
rt_uint8_t *rtgui_graphic_driver_get_framebuffer(const struct rtgui_graphic_driver *driver);
rt_err_t rtgui_graphic_set_device(rt_device_t device);
void rtgui_graphic_driver_set_framebuffer(void *fb);
rt_inline struct rtgui_graphic_driver *rtgui_graphic_get_device()
{
return rtgui_graphic_driver_get_default();
}
#ifdef RTGUI_USING_HW_CURSOR
/*
* hardware cursor
*/
enum rtgui_cursor_type
{
RTGUI_CURSOR_ARROW,
RTGUI_CURSOR_HAND,
};
void rtgui_cursor_set_device(const char* device_name);
void rtgui_cursor_set_position(rt_uint16_t x, rt_uint16_t y);
void rtgui_cursor_set_image(enum rtgui_cursor_type type);
#endif
#ifdef RTGUI_USING_VFRAMEBUFFER
void rtgui_graphic_driver_vmode_enter(void);
void rtgui_graphic_driver_vmode_exit(void);
struct rtgui_dc* rtgui_graphic_driver_get_rect_buffer(const struct rtgui_graphic_driver *driver, struct rtgui_rect *rect);
#endif
rt_bool_t rtgui_graphic_driver_is_vmode(void);
#endif
/*
* File : event.h
* This file is part of RTGUI in RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2009-10-04 Bernard first version
*/
#ifndef __RTGUI_EVENT_H__
#define __RTGUI_EVENT_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <rtdevice.h>
#include <rtgui/rtgui.h>
#include <rtgui/kbddef.h>
/* NOTE: if you create a new event type, remember to add it into the union
* rtgui_event_generic */
enum _rtgui_event_type
{
/* applications event */
RTGUI_EVENT_APP_CREATE, /* create an application */
RTGUI_EVENT_APP_DESTROY, /* destroy an application */
RTGUI_EVENT_APP_ACTIVATE, /* activate an application */
/* window event */
RTGUI_EVENT_WIN_CREATE, /* create a window */
RTGUI_EVENT_WIN_DESTROY, /* destroy a window */
RTGUI_EVENT_WIN_SHOW, /* show a window */
RTGUI_EVENT_WIN_HIDE, /* hide a window */
RTGUI_EVENT_WIN_ACTIVATE, /* activate a window */
RTGUI_EVENT_WIN_DEACTIVATE, /* deactivate a window */
RTGUI_EVENT_WIN_CLOSE, /* close a window */
RTGUI_EVENT_WIN_MOVE, /* move a window */
RTGUI_EVENT_WIN_RESIZE, /* resize a window */
RTGUI_EVENT_WIN_MODAL_ENTER, /* the window is entering modal mode.
This event should be sent after the
window got setup and before the
application got setup. */
/* WM event */
RTGUI_EVENT_SET_WM, /* set window manager */
RTGUI_EVENT_UPDATE_BEGIN, /* update a rect */
RTGUI_EVENT_UPDATE_END, /* update a rect */
RTGUI_EVENT_MONITOR_ADD, /* add a monitor rect */
RTGUI_EVENT_MONITOR_REMOVE, /* remove a monitor rect */
RTGUI_EVENT_SHOW, /* the widget is going to be shown */
RTGUI_EVENT_HIDE, /* the widget is going to be hidden */
RTGUI_EVENT_PAINT, /* paint on screen */
RTGUI_EVENT_TIMER, /* timer */
RTGUI_EVENT_UPDATE_TOPLVL, /* update the toplevel */
/* virtual paint event */
RTGUI_EVENT_VPAINT_REQ, /* virtual paint request (server -> client) */
/* clip rect information */
RTGUI_EVENT_CLIP_INFO, /* clip rect info */
/* mouse and keyboard event */
RTGUI_EVENT_MOUSE_MOTION, /* mouse motion */
RTGUI_EVENT_MOUSE_BUTTON, /* mouse button info */
RTGUI_EVENT_KBD, /* keyboard info */
RTGUI_EVENT_TOUCH, /* touch event to server */
RTGUI_EVENT_GESTURE, /* gesture event */
/* widget event */
RTGUI_EVENT_FOCUSED, /* widget focused */
RTGUI_EVENT_SCROLLED, /* scroll bar scrolled */
RTGUI_EVENT_RESIZE, /* widget resize */
RTGUI_EVENT_SELECTED, /* widget selected */
RTGUI_EVENT_UNSELECTED, /* widget un-selected */
RTGUI_EVENT_MV_MODEL, /* data of a model has been changed */
WBUS_NOTIFY_EVENT,
/* user command event. It should always be the last command type. */
RTGUI_EVENT_COMMAND = 0x0100, /* user command */
};
typedef enum _rtgui_event_type rtgui_event_type;
enum
{
RTGUI_STATUS_OK = 0, /* status ok */
RTGUI_STATUS_ERROR, /* generic error */
RTGUI_STATUS_NRC, /* no resource */
};
struct rtgui_event
{
/* the event type */
enum _rtgui_event_type type;
/* user field of event */
rt_uint16_t user;
/* the event sender */
struct rtgui_app *sender;
/* mailbox to acknowledge request */
rt_mailbox_t ack;
};
typedef struct rtgui_event rtgui_event_t;
#define RTGUI_EVENT(e) ((struct rtgui_event*)(e))
extern struct rtgui_app* rtgui_app_self(void);
#define RTGUI_EVENT_INIT(e, t) do \
{ \
(e)->type = (t); \
(e)->user = 0; \
(e)->sender = rtgui_app_self(); \
(e)->ack = RT_NULL; \
} while (0)
/*
* RTGUI Application Event
*/
struct rtgui_event_application
{
struct rtgui_event parent;
struct rtgui_app *app;
};
/* gui application init */
#define RTGUI_EVENT_APP_CREATE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_APP_CREATE)
#define RTGUI_EVENT_APP_DESTROY_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_APP_DESTROY)
#define RTGUI_EVENT_APP_ACTIVATE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_APP_ACTIVATE)
/*
* RTGUI Window Event
*/
#define _RTGUI_EVENT_WIN_ELEMENTS \
struct rtgui_event parent; \
struct rtgui_win *wid;
/*
* RTGUI Window Event
*/
struct rtgui_event_win
{
_RTGUI_EVENT_WIN_ELEMENTS
};
struct rtgui_event_win_create
{
_RTGUI_EVENT_WIN_ELEMENTS
struct rtgui_win *parent_window;
};
struct rtgui_event_win_move
{
_RTGUI_EVENT_WIN_ELEMENTS
rt_int16_t x, y;
};
struct rtgui_event_win_resize
{
_RTGUI_EVENT_WIN_ELEMENTS
rtgui_rect_t rect;
};
#define rtgui_event_win_destroy rtgui_event_win
#define rtgui_event_win_show rtgui_event_win
#define rtgui_event_win_hide rtgui_event_win
#define rtgui_event_win_activate rtgui_event_win
#define rtgui_event_win_deactivate rtgui_event_win
#define rtgui_event_win_close rtgui_event_win
#define rtgui_event_win_modal_enter rtgui_event_win
/* window event init */
#define RTGUI_EVENT_WIN_CREATE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_CREATE)
#define RTGUI_EVENT_WIN_DESTROY_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_DESTROY)
#define RTGUI_EVENT_WIN_SHOW_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_SHOW)
#define RTGUI_EVENT_WIN_HIDE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_HIDE)
#define RTGUI_EVENT_WIN_ACTIVATE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_ACTIVATE)
#define RTGUI_EVENT_WIN_DEACTIVATE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_DEACTIVATE)
#define RTGUI_EVENT_WIN_CLOSE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_CLOSE)
#define RTGUI_EVENT_WIN_MOVE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_MOVE)
#define RTGUI_EVENT_WIN_RESIZE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_RESIZE)
#define RTGUI_EVENT_WIN_MODAL_ENTER_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_MODAL_ENTER)
/*
* RTGUI set window manager
*/
struct rtgui_event_set_wm
{
struct rtgui_event parent;
struct rtgui_app *app;
};
#define RTGUI_EVENT_SET_WM_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_SET_WM);
/*
* RTGUI Other Event
*/
struct rtgui_event_update_begin
{
struct rtgui_event parent;
/* the update rect */
rtgui_rect_t rect;
};
struct rtgui_event_update_end
{
struct rtgui_event parent;
/* the update rect */
rtgui_rect_t rect;
};
struct rtgui_event_monitor
{
_RTGUI_EVENT_WIN_ELEMENTS
/* the monitor rect */
rtgui_rect_t rect;
};
struct rtgui_event_paint
{
_RTGUI_EVENT_WIN_ELEMENTS
rtgui_rect_t rect; /* rect to be updated */
};
struct rtgui_timer;
struct rtgui_event_timer
{
struct rtgui_event parent;
struct rtgui_timer *timer;
};
typedef struct rtgui_event_timer rtgui_event_timer_t;
struct rtgui_event_clip_info
{
_RTGUI_EVENT_WIN_ELEMENTS
/* the number of rects */
//rt_uint32_t num_rect;
/* rtgui_rect_t *rects */
};
#define RTGUI_EVENT_GET_RECT(e, i) &(((rtgui_rect_t*)(e + 1))[i])
#define RTGUI_EVENT_UPDATE_BEGIN_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_UPDATE_BEGIN)
#define RTGUI_EVENT_UPDATE_END_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_UPDATE_END)
#define RTGUI_EVENT_MONITOR_ADD_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MONITOR_ADD)
#define RTGUI_EVENT_MONITOR_REMOVE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MONITOR_REMOVE)
#define RTGUI_EVENT_CLIP_INFO_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_CLIP_INFO)
#define RTGUI_EVENT_PAINT_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_PAINT)
#define RTGUI_EVENT_TIMER_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_TIMER)
#define rtgui_event_show rtgui_event
#define rtgui_event_hide rtgui_event
#define RTGUI_EVENT_SHOW_INIT(e) RTGUI_EVENT_INIT((e), RTGUI_EVENT_SHOW)
#define RTGUI_EVENT_HIDE_INIT(e) RTGUI_EVENT_INIT((e), RTGUI_EVENT_HIDE)
struct rtgui_event_update_toplvl
{
struct rtgui_event parent;
struct rtgui_win *toplvl;
};
#define RTGUI_EVENT_UPDATE_TOPLVL_INIT(e) \
do { \
RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_UPDATE_TOPLVL); \
(e)->toplvl = RT_NULL; \
} while (0)
struct rtgui_event_vpaint_req
{
_RTGUI_EVENT_WIN_ELEMENTS
struct rtgui_event_vpaint_req *sender;
struct rt_completion *cmp;
struct rtgui_dc* buffer;
};
#define RTGUI_EVENT_VPAINT_REQ_INIT(e, win, cm) \
do { \
RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_VPAINT_REQ); \
(e)->wid = win; \
(e)->cmp = cm; \
(e)->sender = (e); \
(e)->buffer = RT_NULL; \
rt_completion_init((e)->cmp); \
} while (0)
/**
* RTGUI Gesture Event
*/
enum rtgui_gesture_type
{
RTGUI_GESTURE_NONE = 0x0000,
RTGUI_GESTURE_TAP = 0x0001,
/* Usually used to zoom in and out. */
RTGUI_GESTURE_PINCH = 0x0002,
RTGUI_GESTURE_DRAG = 0x0004,
RTGUI_GESTURE_LONGPRESS = 0x0008,
/* PINCH, DRAG finished. */
RTGUI_GESTURE_FINISH = 0x8000,
/* The corresponding gesture should be canceled. */
RTGUI_GESTURE_CANCEL = 0x4000,
RTGUI_GESTURE_TYPE_MASK = 0x0FFF,
};
struct rtgui_event_gesture
{
_RTGUI_EVENT_WIN_ELEMENTS
enum rtgui_gesture_type type;
};
/*
* RTGUI Mouse and Keyboard Event
*/
struct rtgui_event_mouse
{
_RTGUI_EVENT_WIN_ELEMENTS
rt_uint16_t x, y;
rt_uint16_t button;
/* Timestamp of this event sampled in driver. */
rt_tick_t ts;
/* id of touch session(from down to up). Different session should have
* different id. id should never be 0. */
rt_uint32_t id;
};
#define RTGUI_MOUSE_BUTTON_LEFT 0x01
#define RTGUI_MOUSE_BUTTON_RIGHT 0x02
#define RTGUI_MOUSE_BUTTON_MIDDLE 0x03
#define RTGUI_MOUSE_BUTTON_WHEELUP 0x04
#define RTGUI_MOUSE_BUTTON_WHEELDOWN 0x08
#define RTGUI_MOUSE_BUTTON_DOWN 0x10
#define RTGUI_MOUSE_BUTTON_UP 0x20
#define RTGUI_EVENT_GESTURE_INIT(e, gtype) \
do { \
RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_GESTURE); \
(e)->type = gtype; \
} while (0)
struct rtgui_event_kbd
{
_RTGUI_EVENT_WIN_ELEMENTS
rt_uint16_t type; /* key down or up */
rt_uint16_t key; /* current key */
rt_uint16_t mod; /* current key modifiers */
rt_uint16_t unicode; /* translated character */
};
#define RTGUI_KBD_IS_SET_CTRL(e) ((e)->mod & (RTGUI_KMOD_LCTRL | RTGUI_KMOD_RCTRL))
#define RTGUI_KBD_IS_SET_ALT(e) ((e)->mod & (RTGUI_KMOD_LALT | RTGUI_KMOD_RALT))
#define RTGUI_KBD_IS_SET_SHIFT(e) ((e)->mod & (RTGUI_KMOD_LSHIFT| RTGUI_KMOD_RSHIFT))
#define RTGUI_KBD_IS_UP(e) ((e)->type == RTGUI_KEYUP)
#define RTGUI_KBD_IS_DOWN(e) ((e)->type == RTGUI_KEYDOWN)
#define RTGUI_EVENT_MOUSE_MOTION_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MOUSE_MOTION)
#define RTGUI_EVENT_MOUSE_BUTTON_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MOUSE_BUTTON)
#define RTGUI_EVENT_KBD_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_KBD)
/**
* RTGUI Touch Event
* NOTE: There is not touch event to user applications, it's handled by server.
*/
struct rtgui_event_touch
{
struct rtgui_event parent;
rt_uint16_t x, y;
rt_uint16_t up_down;
rt_uint16_t resv;
};
#define RTGUI_TOUCH_UP 0x01
#define RTGUI_TOUCH_DOWN 0x02
#define RTGUI_TOUCH_MOTION 0x03
#define RTGUI_EVENT_TOUCH_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_TOUCH)
struct rtgui_event_command
{
_RTGUI_EVENT_WIN_ELEMENTS
/* command type */
rt_int32_t type;
/* command id */
rt_int32_t command_id;
/* command string */
char command_string[RTGUI_NAME_MAX];
};
#define RTGUI_EVENT_COMMAND_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_COMMAND)
#define RTGUI_CMD_UNKNOWN 0x00
#define RTGUI_CMD_WM_CLOSE 0x10
#define RTGUI_CMD_USER_INT 0x20
#define RTGUI_CMD_USER_STRING 0x21
/************************************************************************/
/* Widget Event */
/************************************************************************/
#define RTGUI_WIDGET_EVENT_INIT(e, t) do \
{ \
(e)->type = (t); \
(e)->sender = RT_NULL; \
(e)->ack = RT_NULL; \
} while (0)
/*
* RTGUI Scrollbar Event
*/
struct rtgui_event_scrollbar
{
struct rtgui_event parent;
rt_uint8_t event;
};
#define RTGUI_SCROLL_LINEUP 0x01
#define RTGUI_SCROLL_LINEDOWN 0x02
#define RTGUI_SCROLL_PAGEUP 0x03
#define RTGUI_SCROLL_PAGEDOWN 0x04
#define RTGUI_EVENT_SCROLLED_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_SCROLLED)
/*
* RTGUI Widget Focused Event
*/
struct rtgui_event_focused
{
struct rtgui_event parent;
struct rtgui_widget *widget;
};
#define RTGUI_EVENT_FOCUSED_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_FOCUSED)
/*
* RTGUI Widget Resize Event
*/
struct rtgui_event_resize
{
struct rtgui_event parent;
rt_int16_t x, y;
rt_int16_t w, h;
};
#define RTGUI_EVENT_RESIZE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_RESIZE)
/*
* RTGUI Model/View Event
*/
enum rtgui_event_model_mode
{
RTGUI_MV_DATA_ADDED,
RTGUI_MV_DATA_CHANGED,
RTGUI_MV_DATA_DELETED,
};
struct rtgui_event_mv_model
{
struct rtgui_event parent;
struct rtgui_mv_model *model;
struct rtgui_mv_view *view;
rt_size_t first_data_changed_idx;
rt_size_t last_data_changed_idx;
};
#define _RTGUI_EVENT_MV_INIT_TYPE(T) \
rt_inline void RTGUI_EVENT_MV_MODEL_##T##_INIT(struct rtgui_event_mv_model *e) \
{ \
RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MV_MODEL); \
(e)->parent.user = RTGUI_MV_DATA_##T; \
} \
/* useless struct to allow trailing semicolon */ \
struct dummy
_RTGUI_EVENT_MV_INIT_TYPE(ADDED);
_RTGUI_EVENT_MV_INIT_TYPE(CHANGED);
_RTGUI_EVENT_MV_INIT_TYPE(DELETED);
#undef _RTGUI_EVENT_MV_INIT_TYPE
#define _RTGUI_EVENT_MV_IS_TYPE(T) \
rt_inline rt_bool_t RTGUI_EVENT_MV_MODEL_IS_##T(struct rtgui_event_mv_model *e) \
{ \
return e->parent.user == RTGUI_MV_DATA_##T; \
} \
/* useless struct to allow trailing semicolon */ \
struct dummy
_RTGUI_EVENT_MV_IS_TYPE(ADDED);
_RTGUI_EVENT_MV_IS_TYPE(CHANGED);
_RTGUI_EVENT_MV_IS_TYPE(DELETED);
#undef _RTGUI_EVENT_MV_IS_TYPE
#undef _RTGUI_EVENT_WIN_ELEMENTS
union rtgui_event_generic
{
struct rtgui_event base;
struct rtgui_event_application app_create;
struct rtgui_event_application app_destroy;
struct rtgui_event_application app_activate;
struct rtgui_event_set_wm set_wm;
struct rtgui_event_win win_base;
struct rtgui_event_win_create win_create;
struct rtgui_event_win_move win_move;
struct rtgui_event_win_resize win_resize;
struct rtgui_event_win_destroy win_destroy;
struct rtgui_event_win_show win_show;
struct rtgui_event_win_hide win_hide;
struct rtgui_event_win_activate win_activate;
struct rtgui_event_win_deactivate win_deactivate;
struct rtgui_event_win_close win_close;
struct rtgui_event_win_modal_enter win_modal_enter;
struct rtgui_event_update_begin update_begin;
struct rtgui_event_update_end update_end;
struct rtgui_event_monitor monitor;
struct rtgui_event_paint paint;
struct rtgui_event_timer timer;
struct rtgui_event_update_toplvl update_toplvl;
struct rtgui_event_vpaint_req vpaint_req;
struct rtgui_event_clip_info clip_info;
struct rtgui_event_mouse mouse;
struct rtgui_event_kbd kbd;
struct rtgui_event_touch touch;
struct rtgui_event_gesture gesture;
struct rtgui_event_scrollbar scrollbar;
struct rtgui_event_focused focused;
struct rtgui_event_resize resize;
struct rtgui_event_mv_model model;
struct rtgui_event_command command;
};
#ifdef __cplusplus
}
#endif
#endif
/*
* File : filerw.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2009-10-16 Bernard first version
*/
#ifndef __RTGUI_FILERW_H__
#define __RTGUI_FILERW_H__
#ifdef __cplusplus
extern "C" {
#endif
#ifdef RTGUI_USING_DFS_FILERW
#ifdef _WIN32_NATIVE
#pragma warning(disable: 4996)
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <io.h>
#else
#include <dfs_posix.h>
#endif
#endif
#include <rtgui/rtgui.h>
#define RTGUI_FILE_SEEK_SET 0
#define RTGUI_FILE_SEEK_CUR 1
#define RTGUI_FILE_SEEK_END 2
struct rtgui_filerw
{
int (*seek)(struct rtgui_filerw *context, rt_off_t offset, int whence);
int (*read)(struct rtgui_filerw *context, void *buffer, rt_size_t size, rt_size_t count);
int (*write)(struct rtgui_filerw *context, const void *buffer, rt_size_t size, rt_size_t count);
int (*tell)(struct rtgui_filerw *context);
int (*eof)(struct rtgui_filerw *context);
int (*close)(struct rtgui_filerw *context);
};
typedef struct rtgui_filerw rtgui_filerw_t;
struct rtgui_filerw *rtgui_filerw_create_file(const char *filename, const char *mode);
struct rtgui_filerw *rtgui_filerw_create_mem(const rt_uint8_t *mem, rt_size_t size);
int rtgui_filerw_seek(struct rtgui_filerw *context, rt_off_t offset, int whence);
int rtgui_filerw_read(struct rtgui_filerw *context, void *buffer, rt_size_t size, rt_size_t count);
int rtgui_filerw_write(struct rtgui_filerw *context, const void *buffer, rt_size_t size, rt_size_t count);
int rtgui_filerw_tell(struct rtgui_filerw *context);
int rtgui_filerw_eof(struct rtgui_filerw *context);
int rtgui_filerw_close(struct rtgui_filerw *context);
int rtgui_filerw_unlink(const char *filename);
/* get memory data from filerw memory object */
const rt_uint8_t *rtgui_filerw_mem_getdata(struct rtgui_filerw *context);
#ifdef __cplusplus
}
#endif
#endif
/*
* File : font.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2009-10-16 Bernard first version
*/
#ifndef __RTGUI_FONT_H__
#define __RTGUI_FONT_H__
#include <rtgui/rtgui.h>
#include <rtgui/list.h>
#ifdef __cplusplus
extern "C" {
#endif
struct rtgui_font;
struct rtgui_dc;
struct rtgui_rect;
struct rtgui_font_engine
{
/* font engine function */
void (*font_init)(struct rtgui_font *font);
void (*font_load)(struct rtgui_font *font);
void (*font_draw_text)(struct rtgui_font *font, struct rtgui_dc *dc, const char *text,
rt_ubase_t len, struct rtgui_rect *rect);
void (*font_get_metrics)(struct rtgui_font *font, const char *text, struct rtgui_rect *rect);
};
/*
* bitmap font engine
*/
struct rtgui_font_bitmap
{
const rt_uint8_t *bmp; /* bitmap font data */
const rt_uint8_t *char_width; /* each character width, NULL for fixed font */
const rt_uint32_t *offset; /* offset for each character */
rt_uint16_t width; /* font width */
rt_uint16_t height; /* font height */
rt_uint8_t first_char;
rt_uint8_t last_char;
};
extern const struct rtgui_font_engine bmp_font_engine;
#include <rtgui/tree.h>
SPLAY_HEAD(cache_tree, hz_cache);
struct hz_cache
{
SPLAY_ENTRY(hz_cache) hz_node;
rt_uint16_t hz_id;
};
struct rtgui_hz_file_font
{
struct cache_tree cache_root;
rt_uint16_t cache_size;
/* font size */
rt_uint16_t font_size;
rt_uint16_t font_data_size;
/* file descriptor */
int fd;
/* font file name */
const char *font_fn;
};
extern const struct rtgui_font_engine rtgui_hz_file_font_engine;
struct rtgui_font
{
/* font name */
char *family;
/* font height */
rt_uint16_t height;
/* refer count */
rt_uint32_t refer_count;
/* font engine */
const struct rtgui_font_engine *engine;
/* font private data */
void *data;
/* the font list */
rtgui_list_t list;
};
typedef struct rtgui_font rtgui_font_t;
void rtgui_font_system_init(void);
void rtgui_font_system_add_font(struct rtgui_font *font);
void rtgui_font_system_remove_font(struct rtgui_font *font);
struct rtgui_font *rtgui_font_default(void);
void rtgui_font_set_defaut(struct rtgui_font *font);
struct rtgui_font *rtgui_font_refer(const char *family, rt_uint16_t height);
void rtgui_font_derefer(struct rtgui_font *font);
/* draw a text */
void rtgui_font_draw(struct rtgui_font *font, struct rtgui_dc *dc, const char *text, rt_ubase_t len, struct rtgui_rect *rect);
int rtgui_font_get_string_width(struct rtgui_font *font, const char *text);
void rtgui_font_get_metrics(struct rtgui_font *font, const char *text, struct rtgui_rect *rect);
/* used by stract font */
#define FONT_BMP_DATA_BEGIN
#define FONT_BMP_DATA_END
struct rtgui_char_position
{
/* Keep the size of this struct within 4 bytes so it can be passed by
* value. */
/* How long this char is. */
rt_uint16_t char_width;
/* How many bytes remaining from current pointer. At least, it will be 1. */
rt_uint16_t remain;
};
/*
* @len the length of @str.
* @offset the char offset on the string to check with.
*/
struct rtgui_char_position _string_char_width(char *str, rt_size_t len, rt_size_t offset);
#ifdef __cplusplus
}
#endif
#endif
#ifndef __FONT_FNT_H__
#define __FONT_FNT_H__
#include <rtgui/font.h>
#include <rtgui/dc.h>
/* fnt font header */
struct fnt_header
{
rt_uint8_t version[4];
rt_uint16_t max_width;
rt_uint16_t height;
rt_uint16_t ascent;
rt_uint16_t depth;
rt_uint32_t first_char;
rt_uint32_t default_char;
rt_uint32_t size;
rt_uint32_t nbits;
rt_uint32_t noffset;
rt_uint32_t nwidth;
};
typedef rt_uint8_t MWIMAGEBITS;
struct fnt_font
{
struct fnt_header header;
const MWIMAGEBITS *bits; /* nbits */
const rt_uint16_t *offset; /* noffset */
const rt_uint8_t *width; /* nwidth */
};
extern const struct rtgui_font_engine fnt_font_engine;
struct rtgui_font *fnt_font_create(const char* filename);
#endif
#ifndef __RTGUI_FONT_TTF_H__
#define __RTGUI_FONT_TTF_H__
#include <rtgui/dc.h>
#include <rtgui/font.h>
#ifdef __cplusplus
extern "C" {
#endif
rtgui_font_t *rtgui_freetype_font_create(const char *filename, int bold, int italic, rt_size_t size);
void rtgui_freetype_font_destroy(rtgui_font_t *font);
#ifdef __cplusplus
}
#endif
#endif
/*
* File : image.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2009-10-16 Bernard first version
*/
#ifndef __RTGUI_IMAGE_H__
#define __RTGUI_IMAGE_H__
#include <rtgui/dc.h>
#include <rtgui/filerw.h>
#include <rtgui/region.h>
#ifdef __cplusplus
extern "C" {
#endif
struct rtgui_image;
struct rtgui_image_engine
{
const char *name;
struct rtgui_list_node list;
/* image engine function */
rt_bool_t (*image_check)(struct rtgui_filerw *file);
rt_bool_t (*image_load)(struct rtgui_image *image, struct rtgui_filerw *file, rt_bool_t load);
void (*image_unload)(struct rtgui_image *image);
void (*image_blit)(struct rtgui_image *image, struct rtgui_dc *dc, struct rtgui_rect *rect);
};
struct rtgui_image_palette
{
rtgui_color_t *colors;
rt_uint32_t ncolors;
};
typedef struct rtgui_image_palette rtgui_image_palette_t;
struct rtgui_image
{
/* image metrics */
rt_uint16_t w, h;
/* image engine */
const struct rtgui_image_engine *engine;
/* image palette */
rtgui_image_palette_t *palette;
/* image private data */
void *data;
};
typedef struct rtgui_image rtgui_image_t;
/* init rtgui image system */
void rtgui_system_image_init(void);
#if defined(RTGUI_USING_DFS_FILERW)
struct rtgui_image_engine *rtgui_image_get_engine_by_filename(const char *fn);
struct rtgui_image *rtgui_image_create_from_file(const char *type, const char *filename, rt_bool_t load);
struct rtgui_image *rtgui_image_create(const char *filename, rt_bool_t load);
#endif
struct rtgui_image *rtgui_image_create_from_mem(const char *type, const rt_uint8_t *data, rt_size_t length, rt_bool_t load);
void rtgui_image_destroy(struct rtgui_image *image);
/* get image's rect */
void rtgui_image_get_rect(struct rtgui_image *image, struct rtgui_rect *rect);
/* register an image engine */
void rtgui_image_register_engine(struct rtgui_image_engine *engine);
/* blit an image on DC */
void rtgui_image_blit(struct rtgui_image *image, struct rtgui_dc *dc, struct rtgui_rect *rect);
struct rtgui_image_palette *rtgui_image_palette_create(rt_uint32_t ncolors);
#ifdef __cplusplus
}
#endif
#endif
/*
* File : image_bmp.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2010-08-10 Bernard first version
*/
#ifndef __RTGUI_IMAGE_BMP_H__
#define __RTGUI_IMAGE_BMP_H__
#pragma pack(push)
#pragma pack(2)
struct rtgui_image_bmp_header
{
/* The Win32 BMP file header (14 bytes) */
rt_uint16_t bfType;
rt_uint32_t bfSize;
rt_uint16_t bfReserved1;
rt_uint16_t bfReserved2;
rt_uint32_t bfOffBits;
/* The Win32 BITMAPINFOHEADER struct (40 bytes) */
rt_uint32_t biSize;
rt_int32_t biWidth;
rt_int32_t biHeight;
rt_uint16_t biPlanes;
rt_uint16_t biBitCount;
rt_uint32_t biCompression;
rt_uint32_t biSizeImage;
rt_int32_t biXPelsPerMeter;
rt_int32_t biYPelsPerMeter;
rt_uint32_t biClrUsed;
rt_uint32_t biClrImportant;
};
#pragma pack(pop)
void rtgui_image_bmp_init(void);
#endif
/*
* File : image_xpm.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2009-10-16 Bernard first version
*/
#ifndef __RTGUI_IMAGE_HDC_H__
#define __RTGUI_IMAGE_HDC_H__
#include <rtgui/image.h>
struct rtgui_image_hdcmm
{
struct rtgui_image parent;
/* hdc image information */
rt_uint16_t byte_per_pixel;
rt_uint16_t pitch;
rt_uint8_t *pixels;
};
void rtgui_image_hdc_init(void);
extern const struct rtgui_image_engine rtgui_image_hdcmm_engine;
#define HDC_HEADER_SIZE (5 * 4)
#define RTGUI_IMAGE_HDC_DEF(bpp, w, h, pixels) \
{{w, h, &rtgui_image_hdcmm_engine, RT_NULL}, bpp, (bpp * w), ((rt_uint8_t*)pixels + HDC_HEADER_SIZE)}
#endif
#ifndef __RTGUI_IMAGE_JPEG_H__
#define __RTGUI_IMAGE_JPEG_H__
#include <rtgui/image.h>
void rtgui_image_jpeg_init(void);
#endif
/*
* File : image_png.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2009-10-16 Bernard first version
*/
#ifndef __RTGUI_IMAGE_PNG_H__
#define __RTGUI_IMAGE_PNG_H__
#include <rtgui/image.h>
void rtgui_image_png_init(void);
#endif
/*
* File : image_xpm.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2009-10-16 Bernard first version
*/
#ifndef __RTGUI_IMAGE_XPM_H__
#define __RTGUI_IMAGE_XPM_H__
#include <rtgui/image.h>
void rtgui_image_xpm_init(void);
#endif
/*
* File : kbddef.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2009-10-16 Bernard first version
*/
#ifndef __KBD_DEF_H__
#define __KBD_DEF_H__
/* The keyboard key have been cleverly chosen to map to ASCII */
typedef enum
{
RTGUIK_UNKNOWN = 0,
RTGUIK_FIRST = 0,
RTGUIK_BACKSPACE = 8,
RTGUIK_TAB = 9,
RTGUIK_CLEAR = 12,
RTGUIK_RETURN = 13,
RTGUIK_PAUSE = 19,
RTGUIK_ESCAPE = 27,
RTGUIK_SPACE = 32,
RTGUIK_EXCLAIM = 33,
RTGUIK_QUOTEDBL = 34,
RTGUIK_HASH = 35,
RTGUIK_DOLLAR = 36,
RTGUIK_AMPERSAND = 38,
RTGUIK_QUOTE = 39,
RTGUIK_LEFTPAREN = 40,
RTGUIK_RIGHTPAREN = 41,
RTGUIK_ASTERISK = 42,
RTGUIK_PLUS = 43,
RTGUIK_COMMA = 44,
RTGUIK_MINUS = 45,
RTGUIK_PERIOD = 46,
RTGUIK_SLASH = 47,
RTGUIK_0 = 48,
RTGUIK_1 = 49,
RTGUIK_2 = 50,
RTGUIK_3 = 51,
RTGUIK_4 = 52,
RTGUIK_5 = 53,
RTGUIK_6 = 54,
RTGUIK_7 = 55,
RTGUIK_8 = 56,
RTGUIK_9 = 57,
RTGUIK_COLON = 58,
RTGUIK_SEMICOLON = 59,
RTGUIK_LESS = 60,
RTGUIK_EQUALS = 61,
RTGUIK_GREATER = 62,
RTGUIK_QUESTION = 63,
RTGUIK_AT = 64,
/*
Skip uppercase letters
*/
RTGUIK_LEFTBRACKET = 91,
RTGUIK_BACKSLASH = 92,
RTGUIK_RIGHTBRACKET = 93,
RTGUIK_CARET = 94,
RTGUIK_UNDERSCORE = 95,
RTGUIK_BACKQUOTE = 96,
RTGUIK_a = 97,
RTGUIK_b = 98,
RTGUIK_c = 99,
RTGUIK_d = 100,
RTGUIK_e = 101,
RTGUIK_f = 102,
RTGUIK_g = 103,
RTGUIK_h = 104,
RTGUIK_i = 105,
RTGUIK_j = 106,
RTGUIK_k = 107,
RTGUIK_l = 108,
RTGUIK_m = 109,
RTGUIK_n = 110,
RTGUIK_o = 111,
RTGUIK_p = 112,
RTGUIK_q = 113,
RTGUIK_r = 114,
RTGUIK_s = 115,
RTGUIK_t = 116,
RTGUIK_u = 117,
RTGUIK_v = 118,
RTGUIK_w = 119,
RTGUIK_x = 120,
RTGUIK_y = 121,
RTGUIK_z = 122,
RTGUIK_DELETE = 127,
/* International keyboard */
RTGUIK_WORLD_0 = 160, /* 0xA0 */
RTGUIK_WORLD_1 = 161,
RTGUIK_WORLD_2 = 162,
RTGUIK_WORLD_3 = 163,
RTGUIK_WORLD_4 = 164,
RTGUIK_WORLD_5 = 165,
RTGUIK_WORLD_6 = 166,
RTGUIK_WORLD_7 = 167,
RTGUIK_WORLD_8 = 168,
RTGUIK_WORLD_9 = 169,
RTGUIK_WORLD_10 = 170,
RTGUIK_WORLD_11 = 171,
RTGUIK_WORLD_12 = 172,
RTGUIK_WORLD_13 = 173,
RTGUIK_WORLD_14 = 174,
RTGUIK_WORLD_15 = 175,
RTGUIK_WORLD_16 = 176,
RTGUIK_WORLD_17 = 177,
RTGUIK_WORLD_18 = 178,
RTGUIK_WORLD_19 = 179,
RTGUIK_WORLD_20 = 180,
RTGUIK_WORLD_21 = 181,
RTGUIK_WORLD_22 = 182,
RTGUIK_WORLD_23 = 183,
RTGUIK_WORLD_24 = 184,
RTGUIK_WORLD_25 = 185,
RTGUIK_WORLD_26 = 186,
RTGUIK_WORLD_27 = 187,
RTGUIK_WORLD_28 = 188,
RTGUIK_WORLD_29 = 189,
RTGUIK_WORLD_30 = 190,
RTGUIK_WORLD_31 = 191,
RTGUIK_WORLD_32 = 192,
RTGUIK_WORLD_33 = 193,
RTGUIK_WORLD_34 = 194,
RTGUIK_WORLD_35 = 195,
RTGUIK_WORLD_36 = 196,
RTGUIK_WORLD_37 = 197,
RTGUIK_WORLD_38 = 198,
RTGUIK_WORLD_39 = 199,
RTGUIK_WORLD_40 = 200,
RTGUIK_WORLD_41 = 201,
RTGUIK_WORLD_42 = 202,
RTGUIK_WORLD_43 = 203,
RTGUIK_WORLD_44 = 204,
RTGUIK_WORLD_45 = 205,
RTGUIK_WORLD_46 = 206,
RTGUIK_WORLD_47 = 207,
RTGUIK_WORLD_48 = 208,
RTGUIK_WORLD_49 = 209,
RTGUIK_WORLD_50 = 210,
RTGUIK_WORLD_51 = 211,
RTGUIK_WORLD_52 = 212,
RTGUIK_WORLD_53 = 213,
RTGUIK_WORLD_54 = 214,
RTGUIK_WORLD_55 = 215,
RTGUIK_WORLD_56 = 216,
RTGUIK_WORLD_57 = 217,
RTGUIK_WORLD_58 = 218,
RTGUIK_WORLD_59 = 219,
RTGUIK_WORLD_60 = 220,
RTGUIK_WORLD_61 = 221,
RTGUIK_WORLD_62 = 222,
RTGUIK_WORLD_63 = 223,
RTGUIK_WORLD_64 = 224,
RTGUIK_WORLD_65 = 225,
RTGUIK_WORLD_66 = 226,
RTGUIK_WORLD_67 = 227,
RTGUIK_WORLD_68 = 228,
RTGUIK_WORLD_69 = 229,
RTGUIK_WORLD_70 = 230,
RTGUIK_WORLD_71 = 231,
RTGUIK_WORLD_72 = 232,
RTGUIK_WORLD_73 = 233,
RTGUIK_WORLD_74 = 234,
RTGUIK_WORLD_75 = 235,
RTGUIK_WORLD_76 = 236,
RTGUIK_WORLD_77 = 237,
RTGUIK_WORLD_78 = 238,
RTGUIK_WORLD_79 = 239,
RTGUIK_WORLD_80 = 240,
RTGUIK_WORLD_81 = 241,
RTGUIK_WORLD_82 = 242,
RTGUIK_WORLD_83 = 243,
RTGUIK_WORLD_84 = 244,
RTGUIK_WORLD_85 = 245,
RTGUIK_WORLD_86 = 246,
RTGUIK_WORLD_87 = 247,
RTGUIK_WORLD_88 = 248,
RTGUIK_WORLD_89 = 249,
RTGUIK_WORLD_90 = 250,
RTGUIK_WORLD_91 = 251,
RTGUIK_WORLD_92 = 252,
RTGUIK_WORLD_93 = 253,
RTGUIK_WORLD_94 = 254,
RTGUIK_WORLD_95 = 255, /* 0xFF */
/* Numeric keypad */
RTGUIK_KP0 = 256,
RTGUIK_KP1 = 257,
RTGUIK_KP2 = 258,
RTGUIK_KP3 = 259,
RTGUIK_KP4 = 260,
RTGUIK_KP5 = 261,
RTGUIK_KP6 = 262,
RTGUIK_KP7 = 263,
RTGUIK_KP8 = 264,
RTGUIK_KP9 = 265,
RTGUIK_KP_PERIOD = 266,
RTGUIK_KP_DIVIDE = 267,
RTGUIK_KP_MULTIPLY = 268,
RTGUIK_KP_MINUS = 269,
RTGUIK_KP_PLUS = 270,
RTGUIK_KP_ENTER = 271,
RTGUIK_KP_EQUALS = 272,
/* Arrows + Home/End pad */
RTGUIK_UP = 273,
RTGUIK_DOWN = 274,
RTGUIK_RIGHT = 275,
RTGUIK_LEFT = 276,
RTGUIK_INSERT = 277,
RTGUIK_HOME = 278,
RTGUIK_END = 279,
RTGUIK_PAGEUP = 280,
RTGUIK_PAGEDOWN = 281,
/* Function keys */
RTGUIK_F1 = 282,
RTGUIK_F2 = 283,
RTGUIK_F3 = 284,
RTGUIK_F4 = 285,
RTGUIK_F5 = 286,
RTGUIK_F6 = 287,
RTGUIK_F7 = 288,
RTGUIK_F8 = 289,
RTGUIK_F9 = 290,
RTGUIK_F10 = 291,
RTGUIK_F11 = 292,
RTGUIK_F12 = 293,
RTGUIK_F13 = 294,
RTGUIK_F14 = 295,
RTGUIK_F15 = 296,
/* Key state modifier keys */
RTGUIK_NUMLOCK = 300,
RTGUIK_CAPSLOCK = 301,
RTGUIK_SCROLLOCK = 302,
RTGUIK_RSHIFT = 303,
RTGUIK_LSHIFT = 304,
RTGUIK_RCTRL = 305,
RTGUIK_LCTRL = 306,
RTGUIK_RALT = 307,
RTGUIK_LALT = 308,
RTGUIK_RMETA = 309,
RTGUIK_LMETA = 310,
RTGUIK_LSUPER = 311, /* Left "Windows" key */
RTGUIK_RSUPER = 312, /* Right "Windows" key */
RTGUIK_MODE = 313, /* "Alt Gr" key */
RTGUIK_COMPOSE = 314, /* Multi-key compose key */
/* Miscellaneous function keys */
RTGUIK_HELP = 315,
RTGUIK_PRINT = 316,
RTGUIK_SYSREQ = 317,
RTGUIK_BREAK = 318,
RTGUIK_MENU = 319,
RTGUIK_POWER = 320, /* Power key */
RTGUIK_LAST
} RTGUI_KBD_KEY;
/* Enumeration of valid key mods (possibly OR'd together) */
typedef enum
{
RTGUI_KMOD_NONE = 0x0000,
RTGUI_KMOD_LSHIFT = 0x0001,
RTGUI_KMOD_RSHIFT = 0x0002,
RTGUI_KMOD_LCTRL = 0x0040,
RTGUI_KMOD_RCTRL = 0x0080,
RTGUI_KMOD_LALT = 0x0100,
RTGUI_KMOD_RALT = 0x0200,
RTGUI_KMOD_LMETA = 0x0400,
RTGUI_KMOD_RMETA = 0x0800,
RTGUI_KMOD_NUM = 0x1000,
RTGUI_KMOD_CAPS = 0x2000,
RTGUI_KMOD_MODE = 0x4000,
RTGUI_KMOD_RESERVED = 0x8000
} RTGUI_KBD_MOD;
typedef enum
{
RTGUI_KEYDOWN, /* Keys pressed */
RTGUI_KEYUP, /* Keys released */
} RTGUI_KBD_TYPE;
#endif
/*
* File : list.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2009-10-16 Bernard first version
*/
#ifndef __RTGUI_LIST_H__
#define __RTGUI_LIST_H__
#include <rtgui/rtgui.h>
struct rtgui_list_node
{
struct rtgui_list_node *next;
};
typedef struct rtgui_list_node rtgui_list_t;
rt_inline void rtgui_list_init(rtgui_list_t *l)
{
l->next = (struct rtgui_list_node *)0;
}
rt_inline void rtgui_list_append(rtgui_list_t *l, rtgui_list_t *n)
{
struct rtgui_list_node *node;
node = l;
while (node->next) node = node->next;
/* append the node to the tail */
node->next = n;
n->next = (struct rtgui_list_node *) 0;
}
rt_inline void rtgui_list_insert(rtgui_list_t *l, rtgui_list_t *n)
{
n->next = l->next;
l->next = n;
}
rt_inline rtgui_list_t *rtgui_list_remove(rtgui_list_t *l, rtgui_list_t *n)
{
/* remove slist head */
struct rtgui_list_node *node = l;
while (node->next && node->next != n) node = node->next;
/* remove node */
if (node->next != (rtgui_list_t *)0) node->next = node->next->next;
return l;
}
#define rtgui_list_entry(node, type, member) \
((type *)((char*)(node)-(unsigned long)(&((type *)0)->member)))
#define rtgui_list_foreach(node, list) \
for ((node) = (list)->next; (node) != RT_NULL; (node) = (node)->next)
#endif
#ifndef __MATRIX_H__
#define __MATRIX_H__
/* Port from ejoy2d: https://github.com/cloudwu/ejoy2d/blob/master/LICENSE
* Original License:
*
* The MIT License (MIT)
*
* Copyright (c) 2013 Ejoy.com Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/* Port to RTGUI and modified by Grissiom */
#ifdef _MSC_VER
typedef __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
#else
#include <stdint.h>
#endif
#define RTGUI_MATRIX_FRAC_BITS 11
#define RTGUI_MATRIX_FRAC (1 << RTGUI_MATRIX_FRAC_BITS)
struct rtgui_matrix
{
/* The matrix format is :
*
* | m[0] m[1] 0 |
* | m[2] m[3] 0 |
* | m[4] m[5] 1 |
*
* The format of the coordinate of a point is:
*
* | x y 1 |
*
* So, if you want to transform a point p with a matrix m, do:
*
* p * m
*
* Note: m[0-3] is in fix presentation that has 10 bits decimal
* fraction(m/RTGUI_MATRIX_FRAC). While the unit of m[4-5] is pixel.
*
*/
int m[6];
};
rt_inline int32_t _rtgui_matrix_round_div32(int32_t n, int32_t d)
{
if (n == 0)
return 0;
if (d < 0)
{
d = -d;
n = -n;
}
if (n > 0)
return (n + d / 2) / d;
else
return (n - d / 2) / d;
}
rt_inline int32_t _rtgui_matrix_round_div6432(int64_t n, int32_t d)
{
if (n == 0)
return 0;
if (d < 0)
{
d = -d;
n = -n;
}
if (n > 0)
return (n + d / 2) / d;
else
return (n - d / 2) / d;
}
/* mm = mm1 * mm2 */
rt_inline void rtgui_matrix_mul(struct rtgui_matrix *mm,
const struct rtgui_matrix *mm1,
const struct rtgui_matrix *mm2)
{
int *m = mm->m;
const int *m1 = mm1->m;
const int *m2 = mm2->m;
m[0] = _rtgui_matrix_round_div32(m1[0] * m2[0] + m1[1] * m2[2], RTGUI_MATRIX_FRAC);
m[1] = _rtgui_matrix_round_div32(m1[0] * m2[1] + m1[1] * m2[3], RTGUI_MATRIX_FRAC);
m[2] = _rtgui_matrix_round_div32(m1[2] * m2[0] + m1[3] * m2[2], RTGUI_MATRIX_FRAC);
m[3] = _rtgui_matrix_round_div32(m1[2] * m2[1] + m1[3] * m2[3], RTGUI_MATRIX_FRAC);
m[4] = _rtgui_matrix_round_div32(m1[4] * m2[0] + m1[5] * m2[2], RTGUI_MATRIX_FRAC) + m2[4];
m[5] = _rtgui_matrix_round_div32(m1[4] * m2[1] + m1[5] * m2[3], RTGUI_MATRIX_FRAC) + m2[5];
}
/* Matrix multiply point[(p) = (x, y) * m], ignore the movement components. */
rt_inline void rtgui_matrix_mul_point_nomove(struct rtgui_point *p,
int x, int y,
struct rtgui_matrix *m)
{
int *mm = m->m;
p->x = _rtgui_matrix_round_div32(x * mm[0] + y * mm[2], RTGUI_MATRIX_FRAC);
p->y = _rtgui_matrix_round_div32(x * mm[1] + y * mm[3], RTGUI_MATRIX_FRAC);
}
/* Matrix multiply point[(p) = (x, y) * m]. */
rt_inline void rtgui_matrix_mul_point(struct rtgui_point *p,
int x, int y,
struct rtgui_matrix *m)
{
int *mm = m->m;
p->x = _rtgui_matrix_round_div32(x * mm[0] + y * mm[2], RTGUI_MATRIX_FRAC) + mm[4];
p->y = _rtgui_matrix_round_div32(x * mm[1] + y * mm[3], RTGUI_MATRIX_FRAC) + mm[5];
}
/** Set @mm to an identity matrix. */
rt_inline void rtgu_matrix_identity(struct rtgui_matrix *mm)
{
int *mat = mm->m;
mat[0] = RTGUI_MATRIX_FRAC;
mat[1] = 0;
mat[2] = 0;
mat[3] = RTGUI_MATRIX_FRAC;
mat[4] = 0;
mat[5] = 0;
}
/** Save the inversed matrix of @mm to @mo.
*
* @return If the matrix is not inversale, return 1. Otherwise, return 0. */
int rtgui_matrix_inverse(const struct rtgui_matrix *mm, struct rtgui_matrix *mo);
/** @degree range from 0 ~ 512. */
void rtgui_matrix_rotate(struct rtgui_matrix *m, int degree);
/** The unit is fixed point number. RTGUI_MATRIX_FRAC means 1.0. */
void rtgui_matrix_scale(struct rtgui_matrix *m, int sx, int sy);
/** The unit is pixel. Not the fixed point number. */
void rtgui_matrix_move(struct rtgui_matrix *m, int dx, int dy);
#endif /* end of include guard: __MATRIX_H__ */
/*
* File : region.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2009-10-16 Bernard first version
*/
#ifndef __RTGUI_REGION_H__
#define __RTGUI_REGION_H__
#include <rtgui/rtgui.h>
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif
typedef struct rtgui_region_data rtgui_region_data_t;
struct rtgui_dc;
struct rtgui_region_data
{
rt_uint32_t size;
rt_uint32_t numRects;
/* XXX: And why, exactly, do we have this bogus struct definition? */
/* rtgui_rect_t rects[size]; in memory but not explicitly declared */
};
typedef struct rtgui_region
{
rtgui_rect_t extents;
rtgui_region_data_t *data;
} rtgui_region_t;
typedef enum
{
RTGUI_REGION_STATUS_FAILURE,
RTGUI_REGION_STATUS_SUCCESS
} rtgui_region_status_t;
/* creation/destruction */
void rtgui_region_init(rtgui_region_t *region);
void rtgui_region_init_rect(rtgui_region_t *region,
int x, int y, unsigned int width, unsigned int height);
void rtgui_region_init_with_extents(rtgui_region_t *region, const rtgui_rect_t *extents);
void rtgui_region_fini(rtgui_region_t *region);
void rtgui_region_translate(rtgui_region_t *region, int x, int y);
rtgui_region_status_t rtgui_region_copy(rtgui_region_t *dest, rtgui_region_t *source);
rtgui_region_status_t rtgui_region_intersect(rtgui_region_t *newReg, rtgui_region_t *reg1, rtgui_region_t *reg2);
rtgui_region_status_t rtgui_region_intersect_rect(rtgui_region_t *newReg, rtgui_region_t *reg1, rtgui_rect_t *rect);
rtgui_region_status_t rtgui_region_union(rtgui_region_t *newReg, rtgui_region_t *reg1, rtgui_region_t *reg2);
rtgui_region_status_t rtgui_region_union_rect(rtgui_region_t *dest, rtgui_region_t *source, rtgui_rect_t *rect);
rtgui_region_status_t rtgui_region_subtract(rtgui_region_t *regD, rtgui_region_t *regM, rtgui_region_t *regS);
rtgui_region_status_t rtgui_region_subtract_rect(rtgui_region_t *regD, rtgui_region_t *regM, rtgui_rect_t *rect);
rtgui_region_status_t rtgui_region_inverse(rtgui_region_t *newReg, rtgui_region_t *reg1, rtgui_rect_t *invRect);
int rtgui_region_num_rects(rtgui_region_t *region);
rtgui_rect_t *rtgui_region_rects(rtgui_region_t *region);
#define RTGUI_REGION_OUT 0
#define RTGUI_REGION_IN 1
#define RTGUI_REGION_PART 2
int rtgui_region_contains_point(rtgui_region_t *region, int x, int y, rtgui_rect_t *box);
int rtgui_region_contains_rectangle(rtgui_region_t *rtgui_region_t, rtgui_rect_t *prect);
int rtgui_region_not_empty(rtgui_region_t *region);
rtgui_rect_t *rtgui_region_extents(rtgui_region_t *region);
rtgui_region_status_t rtgui_region_append(rtgui_region_t *dest, rtgui_region_t *region);
rtgui_region_status_t rtgui_region_validate(rtgui_region_t *badreg, int *pOverlap);
void rtgui_region_reset(rtgui_region_t *region, rtgui_rect_t *rect);
void rtgui_region_empty(rtgui_region_t *region);
void rtgui_region_dump(rtgui_region_t *region);
void rtgui_region_draw_clip(rtgui_region_t *region, struct rtgui_dc *dc);
int rtgui_region_is_flat(rtgui_region_t *region);
/* rect functions */
extern rtgui_rect_t rtgui_empty_rect;
void rtgui_rect_moveto(rtgui_rect_t *rect, int x, int y);
void rtgui_rect_moveto_align(const rtgui_rect_t *rect, rtgui_rect_t *to, int align);
void rtgui_rect_inflate(rtgui_rect_t *rect, int d);
void rtgui_rect_intersect(rtgui_rect_t *src, rtgui_rect_t *dest);
int rtgui_rect_contains_point(const rtgui_rect_t *rect, int x, int y);
int rtgui_rect_is_intersect(const rtgui_rect_t *rect1, const rtgui_rect_t *rect2);
int rtgui_rect_is_equal(const rtgui_rect_t *rect1, const rtgui_rect_t *rect2);
rtgui_rect_t *rtgui_rect_set(rtgui_rect_t *rect, int x, int y, int w, int h);
rt_bool_t rtgui_rect_is_empty(const rtgui_rect_t *rect);
rt_inline void rtgui_rect_init(rtgui_rect_t* rect, int x, int y, int width, int height)
{
rect->x1 = x; rect->y1 = y;
rect->x2 = x + width; rect->y2 = y + height;
}
#define RTGUI_RECT(rect, x, y, w, h) \
do { \
rect.x1 = x; rect.y1 = y; \
rect.x2 = (x) + (w); rect.y2 = (y) + (h); \
} while (0)
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
#endif /* _PIXMAN_H_ */
/*
* File : rtgui.h
* This file is part of RT-Thread GUI
* COPYRIGHT (C) 2009 - 2013, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2009-10-04 Bernard first version
*/
#ifndef __RT_GUI_H__
#define __RT_GUI_H__
#include <rtthread.h>
#include <rtgui/rtgui_config.h>
#ifdef __cplusplus
extern "C" {
#endif
#define RTGUI_VERSION 0L /**< major version number */
#define RTGUI_SUBVERSION 8L /**< minor version number */
#define RTGUI_REVISION 1L /**< revise version number */
#define RTGUI_CODENAME "Newton" /**< code name */
#define RT_INT16_MAX 32767
#define RT_INT16_MIN (-RT_INT16_MAX-1)
#define RTGUI_NOT_FOUND (-1)
#define _UI_MIN(x, y) (((x)<(y))?(x):(y))
#define _UI_MAX(x, y) (((x)>(y))?(x):(y))
#define _UI_BITBYTES(bits) ((bits + 7)/8)
#define _UI_ABS(x) ((x)>=0? (x):-(x))
/* MDK, GCC and MSVC all support __restrict keyword. */
#define RTGUI_RESTRICT __restrict
#ifdef _MSC_VER
#define RTGUI_PURE
#else
/* GCC and MDK share the same attributes.
* TODO: IAR attributes. */
#define RTGUI_PURE __attribute__((pure))
#endif
struct rtgui_event;
struct rtgui_object;
struct rtgui_widget;
struct rtgui_win;
struct rtgui_font;
typedef struct rtgui_win rtgui_win_t;
typedef rt_bool_t (*rtgui_event_handler_ptr)(struct rtgui_object *object, struct rtgui_event *event);
typedef void (*rtgui_onbutton_func_t)(struct rtgui_object *object, struct rtgui_event *event);
/**
* Coordinate point
*/
struct rtgui_point
{
rt_int16_t x, y;
};
typedef struct rtgui_point rtgui_point_t;
extern rtgui_point_t rtgui_empty_point;
/**
* Rectangle structure
*/
struct rtgui_rect
{
rt_int16_t x1, y1, x2, y2;
};
typedef struct rtgui_rect rtgui_rect_t;
#define rtgui_rect_width(r) ((r).x2 - (r).x1)
#define rtgui_rect_height(r) ((r).y2 - (r).y1)
typedef unsigned long rtgui_color_t;
/**
* Graphic context
*/
struct rtgui_gc
{
/* foreground and background color */
rtgui_color_t foreground, background;
/* text style */
rt_uint16_t textstyle;
/* text align */
rt_uint16_t textalign;
/* font */
struct rtgui_font *font;
};
typedef struct rtgui_gc rtgui_gc_t;
enum RTGUI_MARGIN_STYLE
{
RTGUI_MARGIN_LEFT = 0x01,
RTGUI_MARGIN_RIGHT = 0x02,
RTGUI_MARGIN_TOP = 0x04,
RTGUI_MARGIN_BOTTOM = 0x08,
RTGUI_MARGIN_ALL = RTGUI_MARGIN_LEFT | RTGUI_MARGIN_RIGHT | RTGUI_MARGIN_TOP | RTGUI_MARGIN_BOTTOM
};
/**
* Border style
*/
enum RTGUI_BORDER_STYLE
{
RTGUI_BORDER_NONE = 0,
RTGUI_BORDER_SIMPLE,
RTGUI_BORDER_RAISE,
RTGUI_BORDER_SUNKEN,
RTGUI_BORDER_BOX,
RTGUI_BORDER_STATIC,
RTGUI_BORDER_EXTRA,
RTGUI_BORDER_UP,
RTGUI_BORDER_DOWN
};
#define RTGUI_BORDER_DEFAULT_WIDTH 2
#define RTGUI_WIDGET_DEFAULT_MARGIN 3
/**
* Blend mode
*/
enum RTGUI_BLENDMODE
{
RTGUI_BLENDMODE_NONE = 0x00,
RTGUI_BLENDMODE_BLEND,
RTGUI_BLENDMODE_ADD,
RTGUI_BLENDMODE_MOD,
};
/**
* Orientation
*/
enum RTGUI_ORIENTATION
{
RTGUI_HORIZONTAL = 0x01,
RTGUI_VERTICAL = 0x02,
RTGUI_ORIENTATION_BOTH = RTGUI_HORIZONTAL | RTGUI_VERTICAL
};
enum RTGUI_ALIGN
{
RTGUI_ALIGN_NOT = 0x00,
RTGUI_ALIGN_CENTER_HORIZONTAL = 0x01,
RTGUI_ALIGN_LEFT = RTGUI_ALIGN_NOT,
RTGUI_ALIGN_TOP = RTGUI_ALIGN_NOT,
RTGUI_ALIGN_RIGHT = 0x02,
RTGUI_ALIGN_BOTTOM = 0x04,
RTGUI_ALIGN_CENTER_VERTICAL = 0x08,
RTGUI_ALIGN_CENTER = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL,
RTGUI_ALIGN_EXPAND = 0x10,
RTGUI_ALIGN_STRETCH = 0x20,
};
enum RTGUI_TEXTSTYLE
{
RTGUI_TEXTSTYLE_NORMAL = 0x00,
RTGUI_TEXTSTYLE_DRAW_BACKGROUND = 0x01,
RTGUI_TEXTSTYLE_SHADOW = 0x02,
RTGUI_TEXTSTYLE_OUTLINE = 0x04,
};
enum RTGUI_MODAL_CODE
{
RTGUI_MODAL_OK,
RTGUI_MODAL_CANCEL
};
typedef enum RTGUI_MODAL_CODE rtgui_modal_code_t;
#include <rtgui/rtgui_object.h>
#ifdef __cplusplus
}
#endif
#endif
/*
* File : rtgui_app.h
* This file is part of RTGUI in RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2012-01-13 Grissiom first version
*/
#ifndef __RTGUI_APP_H__
#define __RTGUI_APP_H__
#include <rtthread.h>
#include <rtgui/rtgui.h>
#include <rtgui/event.h>
#include <rtgui/rtgui_system.h>
#ifdef __cplusplus
extern "C" {
#endif
DECLARE_CLASS_TYPE(application);
/** Gets the type of a application */
#define RTGUI_APP_TYPE (RTGUI_TYPE(application))
/** Casts the object to an rtgui_workbench */
#define RTGUI_APP(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_APP_TYPE, struct rtgui_app))
/** Checks if the object is an rtgui_workbench */
#define RTGUI_IS_APP(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_APP_TYPE))
enum rtgui_app_flag
{
RTGUI_APP_FLAG_EXITED = 0x04,
RTGUI_APP_FLAG_SHOWN = 0x08,
RTGUI_APP_FLAG_KEEP = 0x80,
};
typedef void (*rtgui_idle_func_t)(struct rtgui_object *obj, struct rtgui_event *event);
struct rtgui_app
{
struct rtgui_object parent;
/* application name */
unsigned char *name;
struct rtgui_image *icon;
enum rtgui_app_flag state_flag;
rt_uint16_t ref_count;
rt_uint16_t exit_code;
/* the thread id */
rt_thread_t tid;
/* the message queue of thread */
rt_mq_t mq;
/* event buffer */
rt_uint8_t event_buffer[sizeof(union rtgui_event_generic)];
/* if not RT_NULL, the main_object is the one will be activated when the
* app recieves activate event. By default, it is the first window shown in
* the app. */
struct rtgui_object *main_object;
/* on idle event handler */
rtgui_idle_func_t on_idle;
unsigned int window_cnt;
void *user_data;
};
/**
* create an application named @myname on current thread.
*
* @param name the name of the application
*
* @return a pointer to struct rtgui_app on success. RT_NULL on failure.
*/
struct rtgui_app *rtgui_app_create(const char *name);
void rtgui_app_destroy(struct rtgui_app *app);
rt_bool_t rtgui_app_event_handler(struct rtgui_object *obj, rtgui_event_t *event);
rt_base_t rtgui_app_run(struct rtgui_app *app);
void rtgui_app_exit(struct rtgui_app *app, rt_uint16_t code);
void rtgui_app_activate(struct rtgui_app *app);
void rtgui_app_close(struct rtgui_app *app);
void rtgui_app_sleep(struct rtgui_app *app, int millisecond);
void rtgui_app_set_onidle(struct rtgui_app *app, rtgui_idle_func_t onidle);
rtgui_idle_func_t rtgui_app_get_onidle(struct rtgui_app *app);
/**
* return the rtgui_app struct on current thread
*/
struct rtgui_app *rtgui_app_self(void);
rt_err_t rtgui_app_set_as_wm(struct rtgui_app *app);
void rtgui_app_set_main_win(struct rtgui_app *app, struct rtgui_win *win);
struct rtgui_win* rtgui_app_get_main_win(struct rtgui_app *app);
#ifdef __cplusplus
}
#endif
#endif /* end of include guard: __RTGUI_APP_H__ */
/*
* File : rtgui_config.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2009-10-16 Bernard first version
* 2010-02-08 Bernard move some RTGUI options to bsp
*/
#ifndef __RTGUI_CONFIG_H__
#define __RTGUI_CONFIG_H__
/* RTGUI options */
#ifndef RT_USING_DFS
#undef RTGUI_USING_DFS_FILERW
#undef RTGUI_USING_HZ_FILE
#endif
#ifdef RT_USING_DFS
/* if file system is used, the DFS_FILERW will be defined */
#ifndef RTGUI_USING_DFS_FILERW
#define RTGUI_USING_DFS_FILERW
#endif
#endif
#if RTGUI_DEFAULT_FONT_SIZE == 0
#define RTGUI_DEFAULT_FONT_SIZE 12
#endif
#define RTGUI_SVR_THREAD_PRIORITY 15
#define RTGUI_SVR_THREAD_TIMESLICE 5
#ifndef RTGUI_SVR_THREAD_STACK_SIZE
#ifdef RTGUI_USING_SMALL_SIZE
#define RTGUI_SVR_THREAD_STACK_SIZE 1024
#else
#define RTGUI_SVR_THREAD_STACK_SIZE 2048
#endif
#endif
#define RTGUI_APP_THREAD_PRIORITY 25
#define RTGUI_APP_THREAD_TIMESLICE 5
#ifdef RTGUI_USING_SMALL_SIZE
#define RTGUI_APP_THREAD_STACK_SIZE 1024
#else
#define RTGUI_APP_THREAD_STACK_SIZE 2048
#endif
// #define RTGUI_USING_CAST_CHECK
// #define RTGUI_USING_DESKTOP_WINDOW
// #undef RTGUI_USING_SMALL_SIZE
//#define RTGUI_USING_CALIBRATION
#define RTGUI_USING_VFRAMEBUFFER
#ifdef DEBUG_MEMLEAK
#define rtgui_malloc rt_malloc
#define rtgui_realloc rt_realloc
#define rtgui_free rt_free
#endif
#endif
/*
* File : rtgui_object.h
* This file is part of RTGUI in RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2009-10-04 Bernard first version
*/
#ifndef __RTGUI_OBJECT_H__
#define __RTGUI_OBJECT_H__
#include <rtthread.h>
#include <rtgui/rtgui.h>
#ifdef __cplusplus
extern "C" {
#endif
/* 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 */
#define RTGUI_CONSTRUCTOR(constructor) ((rtgui_constructor_t)(constructor))
/** Casts the function pointer to an rtgui_constructor */
#define RTGUI_DESTRUCTOR(destructor) ((rtgui_destructor_t)(destructor))
/* pre-definition */
struct rtgui_object;
struct rtgui_app;
typedef struct rtgui_object rtgui_object_t;
typedef void (*rtgui_constructor_t)(rtgui_object_t *object);
typedef void (*rtgui_destructor_t)(rtgui_object_t *object);
/* rtgui type structure */
struct rtgui_type
{
/* type name */
char *name;
/* parent type link */
const struct rtgui_type *parent;
/* constructor and destructor */
rtgui_constructor_t constructor;
rtgui_destructor_t destructor;
/* size of type */
int size;
};
typedef struct rtgui_type rtgui_type_t;
#define RTGUI_TYPE(type) (_rtgui_##type##_get_type())
#define RTGUI_PARENT_TYPE(type) (const struct rtgui_type*)(&_rtgui_##type)
#define DECLARE_CLASS_TYPE(type) \
const rtgui_type_t *_rtgui_##type##_get_type(void); \
extern const struct rtgui_type _rtgui_##type
#define DEFINE_CLASS_TYPE(type, name, parent, constructor, destructor, size) \
const struct rtgui_type _rtgui_##type = { \
name, \
parent, \
RTGUI_CONSTRUCTOR(constructor), \
RTGUI_DESTRUCTOR(destructor), \
size }; \
const rtgui_type_t *_rtgui_##type##_get_type(void) { return &_rtgui_##type; } \
RTM_EXPORT(_rtgui_##type##_get_type)
void rtgui_type_object_construct(const rtgui_type_t *type, rtgui_object_t *object);
void rtgui_type_destructors_call(const rtgui_type_t *type, rtgui_object_t *object);
rt_bool_t rtgui_type_inherits_from(const rtgui_type_t *type, const rtgui_type_t *parent);
const rtgui_type_t *rtgui_type_parent_type_get(const rtgui_type_t *type);
const char *rtgui_type_name_get(const rtgui_type_t *type);
const rtgui_type_t *rtgui_object_object_type_get(rtgui_object_t *object);
#ifdef RTGUI_USING_CAST_CHECK
#define RTGUI_OBJECT_CAST(obj, obj_type, c_type) \
((c_type *)rtgui_object_check_cast((rtgui_object_t *)(obj), (obj_type), __FUNCTION__, __LINE__))
#else
#define RTGUI_OBJECT_CAST(obj, obj_type, c_type) ((c_type *)(obj))
#endif
#define RTGUI_OBJECT_CHECK_TYPE(_obj, _type) \
(rtgui_type_inherits_from(((rtgui_object_t *)(_obj))->type, (_type)))
DECLARE_CLASS_TYPE(object);
/** Gets the type of an object */
#define RTGUI_OBJECT_TYPE RTGUI_TYPE(object)
/** Casts the object to an rtgui_object_t */
#define RTGUI_OBJECT(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_OBJECT_TYPE, struct rtgui_object))
/** Checks if the object is an rtgui_Object */
#define RTGUI_IS_OBJECT(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_OBJECT_TYPE))
enum rtgui_object_flag
{
RTGUI_OBJECT_FLAG_NONE = 0x0000,
RTGUI_OBJECT_FLAG_STATIC = 0x0001,
RTGUI_OBJECT_FLAG_DISABLED = 0x0002,
/* When an object is created, it's flag is set to valid. When an object is
* deleted, the valid bits will be cleared. */
RTGUI_OBJECT_FLAG_VALID = 0xAB00,
};
/* rtgui base object */
struct rtgui_object
{
/* object type */
const rtgui_type_t *type;
/* the event handler */
rtgui_event_handler_ptr event_handler;
enum rtgui_object_flag flag;
rt_uint32_t id;
};
rtgui_object_t *rtgui_object_create(const rtgui_type_t *object_type);
void rtgui_object_destroy(rtgui_object_t *object);
/* set the event handler of object */
void rtgui_object_set_event_handler(struct rtgui_object *object, rtgui_event_handler_ptr handler);
/* object default event handler */
rt_bool_t rtgui_object_event_handler(struct rtgui_object *object, struct rtgui_event *event);
/* helper micro. widget event handlers could use this. */
#define RTGUI_WIDGET_EVENT_HANDLER_PREPARE \
struct rtgui_widget *widget; \
RT_ASSERT(object != RT_NULL); \
RT_ASSERT(event != RT_NULL); \
widget = RTGUI_WIDGET(object); \
/* supress compiler warning */ \
widget = widget;
/** handle @param event on @param object's own event handler
*
* If the @param object does not have an event handler, which means the object
* does not interested in any event, it will return RT_FALSE. Otherwise, the
* return code of that handler is returned.
*/
rt_inline rt_bool_t rtgui_object_handle(struct rtgui_object *object, struct rtgui_event *event)
{
if (object->event_handler)
return object->event_handler(object, event);
return RT_FALSE;
}
rtgui_object_t *rtgui_object_check_cast(rtgui_object_t *object, const rtgui_type_t *type, const char *func, int line);
const rtgui_type_t *rtgui_object_object_type_get(rtgui_object_t *object);
void rtgui_object_set_id(struct rtgui_object *obj, rt_uint32_t id);
rt_uint32_t rtgui_object_get_id(struct rtgui_object *obj);
struct rtgui_object* rtgui_get_object(struct rtgui_app *app, rt_uint32_t id);
struct rtgui_object* rtgui_get_self_object(rt_uint32_t id);
#ifdef __cplusplus
}
#endif
#endif
/*
* File : rtgui_server.h
* This file is part of RTGUI in RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2009-10-04 Bernard first version
*/
#ifndef __RTGUI_SERVER_H__
#define __RTGUI_SERVER_H__
#include <rtservice.h>
#include <rtgui/list.h>
/* RTGUI server definitions */
/* top window definitions in server */
enum rtgui_topwin_flag
{
WINTITLE_INIT = 0x00,
WINTITLE_ACTIVATE = 0x01,
WINTITLE_NOFOCUS = 0x02,
/* window is hidden by default */
WINTITLE_SHOWN = 0x04,
/* window is modaled by other window */
WINTITLE_MODALED = 0x08,
/* window is modaling other window */
WINTITLE_MODALING = 0x100,
WINTITLE_ONTOP = 0x200,
WINTITLE_ONBTM = 0x400,
};
struct rtgui_topwin
{
/* the window flag */
enum rtgui_topwin_flag flag;
/* event mask */
rt_uint32_t mask;
struct rtgui_wintitle *title;
/* the window id */
struct rtgui_win *wid;
/* which app I belong */
struct rtgui_app *app;
/* the extent information */
rtgui_rect_t extent;
struct rtgui_topwin *parent;
/* we need to iterate the topwin list with usual order(get target window)
* or reversely(painting). So it's better to use a double linked list */
rt_list_t list;
rt_list_t child_list;
/* the monitor rect list */
rtgui_list_t monitor_list;
};
/* top win manager init */
void rtgui_topwin_init(void);
void rtgui_server_init(void);
void rtgui_server_install_show_win_hook(void (*hk)(void));
void rtgui_server_install_act_win_hook(void (*hk)(void));
/* post an event to server */
void rtgui_server_post_event(struct rtgui_event *event, rt_size_t size);
rt_err_t rtgui_server_post_event_sync(struct rtgui_event *event, rt_size_t size);
#endif
/*
* File : rtgui_system.h
* This file is part of RTGUI in RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2009-10-04 Bernard first version
*/
#ifndef __RTGUI_SYSTEM_H__
#define __RTGUI_SYSTEM_H__
#include <rtthread.h>
#include <rtgui/rtgui.h>
#ifdef __cplusplus
extern "C" {
#endif
struct rtgui_dc;
struct rtgui_event;
struct rtgui_widget;
struct rtgui_timer;
typedef void (*rtgui_timeout_func)(struct rtgui_timer *timer, void *parameter);
enum rtgui_timer_state
{
RTGUI_TIMER_ST_INIT,
RTGUI_TIMER_ST_RUNNING,
RTGUI_TIMER_ST_DESTROY_PENDING,
};
struct rtgui_timer
{
/* the rtgui application it runs on */
struct rtgui_app* app;
/* rt timer */
struct rt_timer timer;
/* How many events are pending on the queue. */
int pending_cnt;
enum rtgui_timer_state state;
/* timeout function and user data */
rtgui_timeout_func timeout;
void *user_data;
};
typedef struct rtgui_timer rtgui_timer_t;
rtgui_timer_t *rtgui_timer_create(rt_int32_t time, rt_base_t flag, rtgui_timeout_func timeout, void *parameter);
void rtgui_timer_destory(rtgui_timer_t *timer);
void rtgui_timer_set_timeout(rtgui_timer_t *timer, rt_int32_t time);
void rtgui_timer_start(rtgui_timer_t *timer);
void rtgui_timer_stop(rtgui_timer_t *timer);
/* rtgui system initialization function */
int rtgui_system_server_init(void);
void *rtgui_malloc(rt_size_t size);
void rtgui_free(void *ptr);
void *rtgui_realloc(void *ptr, rt_size_t size);
#ifdef _WIN32_NATIVE
#define rtgui_enter_critical()
#define rtgui_exit_critical()
#else
#define rtgui_enter_critical rt_enter_critical
#define rtgui_exit_critical rt_exit_critical
#endif
struct rtgui_app* rtgui_get_server(void);
void rtgui_set_mainwin_rect(struct rtgui_rect *rect);
void rtgui_get_mainwin_rect(struct rtgui_rect *rect);
void rtgui_get_screen_rect(struct rtgui_rect *rect);
void rtgui_screen_lock(rt_int32_t timeout);
void rtgui_screen_unlock(void);
int rtgui_screen_lock_freeze(void);
void rtgui_screen_lock_thaw(int value);
struct rtgui_event;
rt_err_t rtgui_send(struct rtgui_app* app, struct rtgui_event *event, rt_size_t event_size);
rt_err_t rtgui_send_urgent(struct rtgui_app* app, struct rtgui_event *event, rt_size_t event_size);
rt_err_t rtgui_send_sync(struct rtgui_app* app, struct rtgui_event *event, rt_size_t event_size);
rt_err_t rtgui_ack(struct rtgui_event *event, rt_int32_t status);
rt_err_t rtgui_recv(struct rtgui_event *event, rt_size_t event_size, rt_int32_t timeout);
rt_err_t rtgui_recv_filter(rt_uint32_t type, struct rtgui_event *event, rt_size_t event_size);
#ifdef __cplusplus
}
#endif
#endif
此差异已折叠。
/*
* File : box.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2009-10-16 Bernard first version
*/
#ifndef __RTGUI_BOX_H__
#define __RTGUI_BOX_H__
#include <rtgui/rtgui.h>
#include <rtgui/widgets/widget.h>
#include <rtgui/widgets/container.h>
#ifdef __cplusplus
extern "C" {
#endif
DECLARE_CLASS_TYPE(box);
/** Gets the type of a box */
#define RTGUI_BOX_TYPE (RTGUI_TYPE(box))
/** Casts the object to an rtgui_box */
#define RTGUI_BOX(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_BOX_TYPE, rtgui_box_t))
/** Checks if the object is an rtgui_box */
#define RTGUI_IS_BOX(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_BOX_TYPE))
struct rtgui_box
{
struct rtgui_object parent;
rt_uint16_t orient;
rt_uint16_t border_size;
struct rtgui_container *container;
};
typedef struct rtgui_box rtgui_box_t;
struct rtgui_box *rtgui_box_create(int orientation, int border_size);
void rtgui_box_destroy(struct rtgui_box *box);
void rtgui_box_layout(rtgui_box_t *box);
void rtgui_box_layout_rect(rtgui_box_t *box, struct rtgui_rect *rect);
#ifdef __cplusplus
}
#endif
#endif
/*
* File : container.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2009-10-16 Bernard first version
*/
#ifndef __RTGUI_CONTAINER_H__
#define __RTGUI_CONTAINER_H__
#include <rtgui/widgets/widget.h>
#include <rtgui/widgets/box.h>
#ifdef __cplusplus
extern "C" {
#endif
DECLARE_CLASS_TYPE(container);
/** Gets the type of a container */
#define RTGUI_CONTAINER_TYPE (RTGUI_TYPE(container))
/** Casts the object to an rtgui_container */
#define RTGUI_CONTAINER(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_CONTAINER_TYPE, rtgui_container_t))
/** Checks if the object is an rtgui_container */
#define RTGUI_IS_CONTAINER(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_CONTAINER_TYPE))
/*
* the container widget
*/
struct rtgui_container
{
struct rtgui_widget parent;
/* layout box */
struct rtgui_box *layout_box;
rtgui_list_t children;
};
typedef struct rtgui_container rtgui_container_t;
rtgui_container_t *rtgui_container_create(void);
void rtgui_container_destroy(rtgui_container_t *container);
rt_bool_t rtgui_container_event_handler(struct rtgui_object *widget, struct rtgui_event *event);
/* set layout box */
void rtgui_container_set_box(struct rtgui_container *container, struct rtgui_box *box);
void rtgui_container_layout(struct rtgui_container *container);
void rtgui_container_add_child(rtgui_container_t *container, rtgui_widget_t *child);
void rtgui_container_remove_child(rtgui_container_t *container, rtgui_widget_t *child);
void rtgui_container_destroy_children(rtgui_container_t *container);
rtgui_widget_t *rtgui_container_get_first_child(rtgui_container_t *container);
rt_bool_t rtgui_container_event_handler(struct rtgui_object *widget, rtgui_event_t *event);
rt_bool_t rtgui_container_dispatch_event(rtgui_container_t *container, rtgui_event_t *event);
rt_bool_t rtgui_container_dispatch_mouse_event(rtgui_container_t *container, struct rtgui_event_mouse *event);
struct rtgui_object* rtgui_container_get_object(struct rtgui_container *container, rt_uint32_t id);
#ifdef __cplusplus
}
#endif
#endif
/*
* File : title.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2009-10-16 Bernard first version
*/
#ifndef __RTGUI_TITLE__
#define __RTGUI_TITLE__
#include <rtgui/widgets/widget.h>
DECLARE_CLASS_TYPE(wintitle);
/** Gets the type of a title */
#define RTGUI_WINTITLE_TYPE (RTGUI_TYPE(wintitle))
/** Casts the object to an rtgui_wintitle */
#define RTGUI_WINTITLE(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_WINTITLE_TYPE, rtgui_wintitle_t))
/** Checks if the object is an rtgui_wintitle */
#define RTGUI_IS_WINTITLE(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_WINTITLE_TYPE))
struct rtgui_wintitle
{
struct rtgui_widget parent;
};
typedef struct rtgui_wintitle rtgui_wintitle_t;
rtgui_wintitle_t *rtgui_wintitle_create(struct rtgui_win *window);
void rtgui_wintitle_destroy(rtgui_wintitle_t *wintitle);
rt_bool_t rtgui_wintile_event_handler(struct rtgui_object *object, rtgui_event_t *event);
#endif
/*
* File : widget.h
* This file is part of RT-Thread GUI
* COPYRIGHT (C) 2006 - 2013, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2009-10-04 Bernard first version
*/
#ifndef __RTGUI_WIDGET_H__
#define __RTGUI_WIDGET_H__
#include <rtgui/rtgui.h>
#include <rtgui/list.h>
#include <rtgui/region.h>
#include <rtgui/event.h>
#include <rtgui/color.h>
#include <rtgui/font.h>
#ifdef __cplusplus
extern "C" {
#endif
#define RTGUI_WIDGET_FLAG_DEFAULT 0x0000
#define RTGUI_WIDGET_FLAG_SHOWN 0x0001
#define RTGUI_WIDGET_FLAG_DISABLE 0x0002
#define RTGUI_WIDGET_FLAG_FOCUS 0x0004
#define RTGUI_WIDGET_FLAG_TRANSPARENT 0x0008
#define RTGUI_WIDGET_FLAG_FOCUSABLE 0x0010
#define RTGUI_WIDGET_FLAG_DC_VISIBLE 0x0100
#define RTGUI_WIDGET_FLAG_IN_ANIM 0x0200
/* rtgui widget attribute */
#define RTGUI_WIDGET_FOREGROUND(w) (RTGUI_WIDGET(w)->gc.foreground)
#define RTGUI_WIDGET_BACKGROUND(w) (RTGUI_WIDGET(w)->gc.background)
#define RTGUI_WIDGET_TEXTALIGN(w) (RTGUI_WIDGET(w)->gc.textalign)
#define RTGUI_WIDGET_FONT(w) (RTGUI_WIDGET(w)->gc.font)
#define RTGUI_WIDGET_FLAG(w) (RTGUI_WIDGET(w)->flag)
#define RTGUI_WIDGET_ALIGN(w) (RTGUI_WIDGET(w)->align)
#define RTGUI_WIDGET_BORDER(w) (RTGUI_WIDGET(w)->border)
#define RTGUI_WIDGET_BORDER_STYLE(w) (RTGUI_WIDGET(w)->border_style)
#define RTGUI_WIDGET_UNHIDE(w) RTGUI_WIDGET_FLAG(w) |= RTGUI_WIDGET_FLAG_SHOWN
#define RTGUI_WIDGET_HIDE(w) RTGUI_WIDGET_FLAG(w) &= ~RTGUI_WIDGET_FLAG_SHOWN
#define RTGUI_WIDGET_IS_HIDE(w) (!(RTGUI_WIDGET_FLAG(w) & RTGUI_WIDGET_FLAG_SHOWN))
#define RTGUI_WIDGET_ENABLE(w) RTGUI_WIDGET_FLAG(w) &= ~RTGUI_WIDGET_FLAG_DISABLE
#define RTGUI_WIDGET_DISABLE(w) RTGUI_WIDGET_FLAG(w) |= RTGUI_WIDGET_FLAG_DISABLE
#define RTGUI_WIDGET_IS_ENABLE(w) (!((RTGUI_WIDGET_FLAG(w) & RTGUI_WIDGET_FLAG_DISABLE)))
#define RTGUI_WIDGET_UNFOCUS(w) RTGUI_WIDGET_FLAG(w) &= ~RTGUI_WIDGET_FLAG_FOCUS
#define RTGUI_WIDGET_FOCUS(w) RTGUI_WIDGET_FLAG(w) |= RTGUI_WIDGET_FLAG_FOCUS
#define RTGUI_WIDGET_IS_FOCUSED(w) (RTGUI_WIDGET_FLAG(w) & RTGUI_WIDGET_FLAG_FOCUS)
#define RTGUI_WIDGET_IS_FOCUSABLE(w) (RTGUI_WIDGET_FLAG(w) & RTGUI_WIDGET_FLAG_FOCUSABLE)
#define RTGUI_WIDGET_SET_UNFOCUSABLE(w) RTGUI_WIDGET_FLAG(w) &= ~RTGUI_WIDGET_FLAG_FOCUSABLE
#define RTGUI_WIDGET_IS_DC_VISIBLE(w) (RTGUI_WIDGET_FLAG(w) & RTGUI_WIDGET_FLAG_DC_VISIBLE)
#define RTGUI_WIDGET_DC_SET_VISIBLE(w) RTGUI_WIDGET_FLAG(w) |= RTGUI_WIDGET_FLAG_DC_VISIBLE
#define RTGUI_WIDGET_DC_SET_UNVISIBLE(w) RTGUI_WIDGET_FLAG(w) &= ~RTGUI_WIDGET_FLAG_DC_VISIBLE
#define RTGUI_WIDGET_DC(w) ((struct rtgui_dc*)&((w)->dc_type))
DECLARE_CLASS_TYPE(widget);
/** Gets the type of a widget */
#define RTGUI_WIDGET_TYPE (RTGUI_TYPE(widget))
/** Casts the object to a rtgui_widget */
#define RTGUI_WIDGET(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_WIDGET_TYPE, rtgui_widget_t))
/** Check if the object is a rtgui_widget */
#define RTGUI_IS_WIDGET(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_WIDGET_TYPE))
/*
* the base widget object
*/
struct rtgui_widget
{
/* inherit from rtgui_object */
struct rtgui_object object;
/* the widget that contains this widget */
struct rtgui_widget *parent;
/* the window that contains this widget */
struct rtgui_win *toplevel;
/* the widget children and sibling */
rtgui_list_t sibling;
/* widget flag */
rt_int32_t flag;
/* hardware device context */
rt_uint32_t dc_type;
const struct rtgui_dc_engine *dc_engine;
/* the graphic context of widget */
rtgui_gc_t gc;
/* the widget extent */
rtgui_rect_t extent;
/* minimal width and height of widget */
rt_int16_t min_width, min_height;
/* widget align */
rt_int32_t align;
rt_uint16_t border;
rt_uint16_t border_style;
/* the rect clip */
rtgui_region_t clip;
/* call back */
rt_bool_t (*on_focus_in)(struct rtgui_object *widget, struct rtgui_event *event);
rt_bool_t (*on_focus_out)(struct rtgui_object *widget, struct rtgui_event *event);
rt_bool_t (*on_paint)(struct rtgui_object *widget, struct rtgui_event *event);
/* user private data */
rt_uint32_t user_data;
};
typedef struct rtgui_widget rtgui_widget_t;
rtgui_widget_t *rtgui_widget_create(const rtgui_type_t *widget_type);
void rtgui_widget_destroy(rtgui_widget_t *widget);
rt_bool_t rtgui_widget_event_handler(struct rtgui_object *object, rtgui_event_t *event);
/* focus and unfocus */
void rtgui_widget_focus(rtgui_widget_t *widget);
void rtgui_widget_unfocus(rtgui_widget_t *widget);
/* event handler for each command */
void rtgui_widget_set_onfocus(rtgui_widget_t *widget, rtgui_event_handler_ptr handler);
void rtgui_widget_set_onunfocus(rtgui_widget_t *widget, rtgui_event_handler_ptr handler);
void rtgui_widget_set_onpaint(rtgui_widget_t *widget, rtgui_event_handler_ptr handler);
/* get and set rect of widget */
void rtgui_widget_get_rect(rtgui_widget_t *widget, rtgui_rect_t *rect);
void rtgui_widget_set_border(rtgui_widget_t *widget, rt_uint32_t style);
void rtgui_widget_set_rect(rtgui_widget_t *widget, const rtgui_rect_t *rect);
void rtgui_widget_set_rectangle(rtgui_widget_t *widget, int x, int y, int width, int height);
void rtgui_widget_get_extent(rtgui_widget_t *widget, rtgui_rect_t *rect);
void rtgui_widget_set_minsize(rtgui_widget_t *widget, int width, int height);
void rtgui_widget_set_minwidth(rtgui_widget_t *widget, int width);
void rtgui_widget_set_minheight(rtgui_widget_t *widget, int height);
void rtgui_widget_set_parent(rtgui_widget_t *widget, rtgui_widget_t *parent);
/* get the physical position of a logic point on widget */
void rtgui_widget_point_to_device(rtgui_widget_t *widget, rtgui_point_t *point);
/* get the physical position of a logic rect on widget */
void rtgui_widget_rect_to_device(rtgui_widget_t *widget, rtgui_rect_t *rect);
/* get the logic position of a physical point on widget */
void rtgui_widget_point_to_logic(rtgui_widget_t *widget, rtgui_point_t *point);
/* get the logic position of a physical rect on widget */
void rtgui_widget_rect_to_logic(rtgui_widget_t *widget, rtgui_rect_t *rect);
void rtgui_widget_clip_parent(rtgui_widget_t *widget);
void rtgui_widget_clip_return(rtgui_widget_t *widget);
/* move widget and its children to a logic point */
void rtgui_widget_move_to_logic(rtgui_widget_t *widget, int dx, int dy);
/* update the clip info of widget */
void rtgui_widget_update_clip(rtgui_widget_t *widget);
/* get the toplevel widget of widget */
struct rtgui_win *rtgui_widget_get_toplevel(rtgui_widget_t *widget);
rt_bool_t rtgui_widget_onupdate_toplvl(struct rtgui_object *object, struct rtgui_event *event);
void rtgui_widget_show(rtgui_widget_t *widget);
rt_bool_t rtgui_widget_onshow(struct rtgui_object *object, struct rtgui_event *event);
void rtgui_widget_hide(rtgui_widget_t *widget);
rt_bool_t rtgui_widget_onhide(struct rtgui_object *object, struct rtgui_event *event);
void rtgui_widget_update(rtgui_widget_t *widget);
rt_bool_t rtgui_widget_onpaint(struct rtgui_object *object, struct rtgui_event *event);
/* get parent color */
rtgui_color_t rtgui_widget_get_parent_foreground(rtgui_widget_t *widget);
rtgui_color_t rtgui_widget_get_parent_background(rtgui_widget_t *widget);
/* get the next sibling of widget */
rtgui_widget_t *rtgui_widget_get_next_sibling(rtgui_widget_t *widget);
/* get the prev sibling of widget */
rtgui_widget_t *rtgui_widget_get_prev_sibling(rtgui_widget_t *widget);
rt_bool_t rtgui_widget_is_in_animation(rtgui_widget_t *widget);
/* dump widget information */
void rtgui_widget_dump(rtgui_widget_t *widget);
#ifdef __cplusplus
}
#endif
#endif
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册