提交 92a50c83 编写于 作者: C chaos.proton@gmail.com

sync with RTGUI c074ff2898b9e

Full log is in GitHub.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2222 bbd45198-f89e-11dd-88c7-29a3b14d5316
上级 c2868be9
......@@ -9,6 +9,7 @@ common/rtgui_object.c
common/rtgui_system.c
common/rtgui_theme.c
common/rtgui_xml.c
common/rtgui_app.c
common/dc.c
common/dc_hw.c
common/dc_buffer.c
......@@ -34,7 +35,6 @@ common/pixel_driver.c
""")
server_src = Split("""
server/rtgui_application.c
server/driver.c
server/mouse.c
server/server.c
......@@ -63,10 +63,10 @@ widgets/toplevel.c
widgets/notebook.c
widgets/container.c
widgets/list_view.c
widgets/about_view.c
widgets/filelist_view.c
widgets/widget.c
widgets/window.c
widgets/panel.c
""")
# The set of source files associated with this SConscript file.
......
/*
* Change Logs:
* Date Author Notes
* 2012-01-24 onelife add one more blit table which exchanges the
* positions of R and B color components in output
*/
#include <rtgui/rtgui.h>
#include <rtgui/blit.h>
......@@ -305,3 +311,63 @@ rtgui_blit_line_func rtgui_blit_line_get(int dst_bpp, int src_bpp)
return _blit_table[dst_bpp][src_bpp];
}
static void rtgui_blit_line_3_2_inv(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int line)
{
rt_uint16_t* dst;
dst = (rt_uint16_t*)dst_ptr;
line = line / 3;
while (line)
{
*dst = (((*src_ptr << 8) & 0x0000F800) |
((*(src_ptr + 1) << 3) & 0x000007E0) |
((*(src_ptr + 2) >> 3) & 0x0000001F));
src_ptr += 3;
dst ++;
line --;
}
return;
}
void rtgui_blit_line_2_2_inv(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int line)
{
rt_uint16_t *dst, *src;
dst = (rt_uint16_t *)dst_ptr;
src = (rt_uint16_t *)src_ptr;
line = line / 2;
while (line)
{
*dst = ((*src << 11) & 0xF800) | (*src & 0x07E0) | ((*src >> 11) & 0x001F);
src ++;
dst ++;
line --;
}
}
static const rtgui_blit_line_func _blit_table_inv[5][5] =
{
/* 0_0, 1_0, 2_0, 3_0, 4_0 */
{RT_NULL, RT_NULL, RT_NULL, RT_NULL, RT_NULL },
/* 0_1, 1_1, 2_1, 3_1, 4_1 */
{RT_NULL, rtgui_blit_line_direct, rtgui_blit_line_2_1, rtgui_blit_line_3_1, rtgui_blit_line_4_1 },
/* 0_2, 1_2, 2_2, 3_2, 4_2 */
{RT_NULL, rtgui_blit_line_1_2, rtgui_blit_line_2_2_inv, rtgui_blit_line_3_2_inv, rtgui_blit_line_4_2 },
/* 0_3, 1_3, 2_3, 3_3, 4_3 */
{RT_NULL, rtgui_blit_line_1_3, rtgui_blit_line_2_3, rtgui_blit_line_direct, rtgui_blit_line_4_3 },
/* 0_4, 1_4, 2_4, 3_4, 4_4 */
{RT_NULL, rtgui_blit_line_1_4, rtgui_blit_line_2_4, rtgui_blit_line_3_4, rtgui_blit_line_direct },
};
rtgui_blit_line_func rtgui_blit_line_get_inv(int dst_bpp, int src_bpp)
{
RT_ASSERT(dst_bpp>0 && dst_bpp < 5);
RT_ASSERT(src_bpp>0 && src_bpp < 5);
return _blit_table_inv[dst_bpp][src_bpp];
}
......@@ -138,12 +138,12 @@ void rtgui_dc_draw_vertical_line(struct rtgui_dc* dc, int x, int y1, int y2)
color = RTGUI_DC_FC(dc);
RTGUI_DC_FC(dc) = dark_grey;
rtgui_dc_draw_hline(dc, x, y1, y2);
rtgui_dc_draw_vline(dc, x, y1, y2);
x ++;
RTGUI_DC_FC(dc) = high_light;
rtgui_dc_draw_hline(dc, x, y1, y2);
rtgui_dc_draw_vline(dc, x, y1, y2);
/* restore color */
RTGUI_DC_FC(dc) = color;
......
......@@ -21,7 +21,7 @@
#include <rtgui/driver.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/rtgui_application.h>
#include <rtgui/rtgui_app.h>
#include <rtgui/rtgui_server.h>
#include <rtgui/widgets/container.h>
#include <rtgui/widgets/window.h>
......@@ -139,7 +139,7 @@ struct rtgui_dc* rtgui_dc_client_create(rtgui_widget_t* owner)
#endif
}
}
else if (RTGUI_IS_APPLICATION(owner->toplevel))
else if (RTGUI_IS_APP(owner->toplevel))
{
RT_ASSERT(0);
}
......@@ -207,7 +207,7 @@ static rt_bool_t rtgui_dc_client_fini(struct rtgui_dc* dc)
#endif
}
}
else if (RTGUI_IS_APPLICATION(owner->toplevel) ||
else if (RTGUI_IS_APP(owner->toplevel) ||
RTGUI_IS_WIN(owner->toplevel))
{
rtgui_toplevel_t* top = RTGUI_TOPLEVEL(owner->toplevel);
......
......@@ -15,7 +15,7 @@
#include <rtgui/dc_hw.h>
#include <rtgui/driver.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/rtgui_application.h>
#include <rtgui/rtgui_app.h>
#include <rtgui/rtgui_server.h>
#include <rtgui/widgets/container.h>
......@@ -117,7 +117,7 @@ struct rtgui_dc* rtgui_dc_hw_create(rtgui_widget_t* owner)
#endif
}
}
else if (RTGUI_IS_APPLICATION(owner->toplevel) ||
else if (RTGUI_IS_APP(owner->toplevel) ||
RTGUI_IS_WIN(owner->toplevel))
{
rtgui_toplevel_t* top = RTGUI_TOPLEVEL(owner->toplevel);
......@@ -184,7 +184,7 @@ static rt_bool_t rtgui_dc_hw_fini(struct rtgui_dc* dc)
#endif
}
}
else if (RTGUI_IS_APPLICATION(owner->toplevel) ||
else if (RTGUI_IS_APP(owner->toplevel) ||
RTGUI_IS_WIN(owner->toplevel))
{
rtgui_toplevel_t* top = RTGUI_TOPLEVEL(owner->toplevel);
......
/*
* Change Logs:
* Date Author Notes
* 2012-01-24 onelife fix a bug in framebuffer_draw_raw_hline
*/
#include <rtgui/rtgui_system.h>
#include <rtgui/driver.h>
......@@ -108,7 +113,7 @@ static void framebuffer_draw_raw_hline(rt_uint8_t *pixels, int x1, int x2, int y
rt_uint8_t *dst;
dst = GET_PIXEL(rtgui_graphic_get_device(), x1, y, rt_uint8_t);
rt_memcpy(dst, pixels, (x2 - x1) * (rtgui_graphic_get_device()->bits_per_pixel/8));
rt_memcpy(dst, pixels, (x2 - x1 + 1) * (rtgui_graphic_get_device()->bits_per_pixel/8));
}
const struct rtgui_graphic_driver_ops _framebuffer_rgb565_ops =
......
......@@ -10,6 +10,7 @@
* Change Logs:
* Date Author Notes
* 2009-10-16 Bernard first version
* 2012-01-24 onelife add TJpgDec (Tiny JPEG Decompressor) support
*/
#include <rtthread.h>
#include <rtgui/image.h>
......@@ -27,7 +28,7 @@
#ifdef RTGUI_IMAGE_BMP
#include <rtgui/image_bmp.h>
#endif
#ifdef RTGUI_IMAGE_JPEG
#if (defined(RTGUI_IMAGE_JPEG) || defined(RTGUI_IMAGE_TJPGD))
#include <rtgui/image_jpeg.h>
#endif
#ifdef RTGUI_IMAGE_PNG
......@@ -50,7 +51,7 @@ void rtgui_system_image_init(void)
rtgui_image_bmp_init();
#endif
#ifdef RTGUI_IMAGE_JPEG
#if (defined(RTGUI_IMAGE_JPEG) || defined(RTGUI_IMAGE_TJPGD))
rtgui_image_jpeg_init();
#endif
......
此差异已折叠。
/*
* Change Logs:
* Date Author Notes
* 2012-01-24 onelife add TJpgDec (Tiny JPEG Decompressor) support
*/
#include <rtthread.h>
#include <rtgui/rtgui.h>
......@@ -494,3 +499,477 @@ static rt_bool_t rtgui_image_jpeg_check(struct rtgui_filerw* file)
}
#endif
#if defined(RTGUI_IMAGE_TJPGD)
/***************************************************************************//**
* @file image_jpg.c
* @brief JPEG decoder using TJpgDec module (elm-chan.org)
* COPYRIGHT (C) 2012, RT-Thread Development Team
* @author onelife
* @version 1.0
*******************************************************************************
* @section License
* 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
*******************************************************************************
* @section Change Logs
* Date Author Notes
* 2012-01-24 onelife Initial creation for limited memory devices
******************************************************************************/
/***************************************************************************//**
* @addtogroup TJpgDec
* @{
******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "tjpgd.h"
#include <rtgui/rtgui_system.h>
#include <rtgui/filerw.h>
#include <rtgui/blit.h>
#include <rtgui/image_jpeg.h>
#ifdef RTGUI_USING_DFS_FILERW
#include <dfs_posix.h>
#endif
/* Private typedef -----------------------------------------------------------*/
struct rtgui_image_jpeg
{
struct rtgui_filerw* filerw;
struct rtgui_dc *dc;
rt_uint16_t dst_x, dst_y;
rt_uint16_t dst_w, dst_h;
rt_bool_t is_loaded;
rt_bool_t to_buffer;
rt_uint8_t scale;
rt_uint8_t byte_per_pixel;
JDEC tjpgd; /* jpeg structure */
void *pool;
rt_uint8_t *pixels;
};
/* Private define ------------------------------------------------------------*/
#define TJPGD_WORKING_BUFFER_SIZE (3100)
#define TJPGD_MAX_MCU_WIDTH_ON_DISP (2 * 8 * 4) /* Y component: 2x2; Display: 4-byte per pixel */
#define TJPGD_MAX_SCALING_FACTOR (3)
#define hw_driver (rtgui_graphic_driver_get_default())
/* Private macro -------------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* static rt_bool_t rtgui_image_jpeg_check(struct rtgui_filerw* file,
rt_uint16_t *width, rt_uint16_t *height);
static rt_bool_t rtgui_image_jpeg_load(struct rtgui_image* image,
struct rtgui_filerw* file, rt_uint8_t scale, rt_bool_t load); */
static rt_bool_t rtgui_image_jpeg_check(struct rtgui_filerw* file);
static rt_bool_t rtgui_image_jpeg_load(struct rtgui_image* image, struct rtgui_filerw* file, rt_bool_t load);
static void rtgui_image_jpeg_unload(struct rtgui_image* image);
static void rtgui_image_jpeg_blit(struct rtgui_image* image,
struct rtgui_dc* dc, struct rtgui_rect* dst_rect);
/* Private variables ---------------------------------------------------------*/
struct rtgui_image_engine rtgui_image_jpeg_engine =
{
"jpeg",
{RT_NULL},
rtgui_image_jpeg_check,
rtgui_image_jpeg_load,
rtgui_image_jpeg_unload,
rtgui_image_jpeg_blit
};
struct rtgui_image_engine rtgui_image_jpg_engine =
{
"jpg",
{RT_NULL},
rtgui_image_jpeg_check,
rtgui_image_jpeg_load,
rtgui_image_jpeg_unload,
rtgui_image_jpeg_blit
};
/* Private functions ---------------------------------------------------------*/
void rtgui_image_jpeg_init()
{
/* register jpeg on image system */
rtgui_image_register_engine(&rtgui_image_jpeg_engine);
/* register jpg on image system */
rtgui_image_register_engine(&rtgui_image_jpg_engine);
}
static UINT tjpgd_in_func(JDEC *jdec, BYTE *buff, UINT ndata)
{
struct rtgui_filerw *file = *(struct rtgui_filerw **)jdec->device;
if (buff == RT_NULL)
{
return rtgui_filerw_seek(file, ndata, RTGUI_FILE_SEEK_CUR);
}
return rtgui_filerw_read(file, (void *)buff, 1, ndata);
}
static UINT tjpgd_out_func(JDEC *jdec, void *bitmap, JRECT *rect)
{
struct rtgui_image_jpeg *jpeg = (struct rtgui_image_jpeg *)jdec->device;
rt_uint16_t w, h, y;
rt_uint16_t rectWidth; /* Width of source rectangular (bytes) */
rt_uint8_t *src, *dst;
/* Put progress indicator */
if (rect->left == 0)
{
rt_kprintf("\r%lu%%", (rect->top << jpeg->scale) * 100UL / jdec->height);
}
/* Copy the decompressed RGB rectanglar to the frame buffer */
rectWidth = (rect->right - rect->left + 1) * jpeg->byte_per_pixel;
src = (rt_uint8_t *)bitmap;
if (jpeg->to_buffer)
{
rt_uint16_t imageWidth; /* Width of image (bytes) */
imageWidth = (jdec->width >> jdec->scale) * jpeg->byte_per_pixel;
dst = jpeg->pixels + rect->top * imageWidth + rect->left * jpeg->byte_per_pixel;
/* Left-top of destination rectangular */
for (h = rect->top; h <= rect->bottom; h++)
{
rt_memcpy(dst, src, rectWidth);
src += rectWidth;
dst += imageWidth; /* Next line */
}
}
else
{
rtgui_blit_line_func blit_line = RT_NULL;
w = rect->right < jpeg->dst_w ? rect->right : jpeg->dst_w;
w = w - rect->left + 1;
h = rect->bottom < jpeg->dst_h ? rect->bottom : jpeg->dst_h;
h = h - rect->top + 1;
if (jpeg->byte_per_pixel == hw_driver->bits_per_pixel / 8)
{
if (hw_driver->pixel_format == RTGRAPHIC_PIXEL_FORMAT_RGB565)
{
blit_line = rtgui_blit_line_get_inv(hw_driver->bits_per_pixel / 8, jpeg->byte_per_pixel);
}
}
else
{
blit_line = rtgui_blit_line_get(hw_driver->bits_per_pixel / 8, jpeg->byte_per_pixel);
}
if (blit_line)
{
rt_uint8_t line_buf[TJPGD_MAX_MCU_WIDTH_ON_DISP];
for (y = 0; y < h; y++)
{
blit_line(line_buf, src, w * jpeg->byte_per_pixel);
jpeg->dc->engine->blit_line(jpeg->dc,
jpeg->dst_x + rect->left, jpeg->dst_x + rect->left + w - 1,
jpeg->dst_y + rect->top + y,
line_buf);
src += rectWidth;
}
}
else
{
for (y = 0; y < h; y++)
{
jpeg->dc->engine->blit_line(jpeg->dc,
jpeg->dst_x + rect->left, jpeg->dst_x + rect->left + w - 1,
jpeg->dst_y + rect->top + y,
src);
src += rectWidth;
}
}
}
return 1; /* Continue to decompress */
}
static rt_bool_t rtgui_image_jpeg_check(struct rtgui_filerw* file)
//static rt_bool_t rtgui_image_jpeg_check(struct rtgui_filerw* file,
// rt_uint32_t *width, rt_uint32_t *height)
{
rt_bool_t is_JPG;
JDEC tjpgd;
void *pool;
is_JPG = RT_FALSE;
do
{
if (!file )
{
break;
}
pool = rt_malloc(TJPGD_WORKING_BUFFER_SIZE);
if (pool == RT_NULL)
{
rt_kprintf("TJPGD err: no mem\n");
break;
}
if (rtgui_filerw_seek(file, 0, SEEK_SET) == -1)
{
break;
}
if (jd_prepare(&tjpgd, tjpgd_in_func, pool,
TJPGD_WORKING_BUFFER_SIZE, (void *)&file) == JDR_OK)
{
// *width = (rt_uint32_t)tjpgd.width;
// *height = (rt_uint32_t)tjpgd.height;
is_JPG = RT_TRUE;
}
rt_kprintf("TJPGD: check OK\n");
} while(0);
rt_free(pool);
return is_JPG;
}
static rt_bool_t rtgui_image_jpeg_load(struct rtgui_image* image, struct rtgui_filerw* file, rt_bool_t load)
//static rt_bool_t rtgui_image_jpeg_load(struct rtgui_image* image,
// struct rtgui_filerw* file, rt_uint8_t scale, rt_bool_t load)
{
rt_uint8_t scale = 2;
rt_bool_t res = RT_FALSE;
struct rtgui_image_jpeg *jpeg;
JRESULT ret;
if (scale > TJPGD_MAX_SCALING_FACTOR)
{
return RT_FALSE;
}
do
{
jpeg = (struct rtgui_image_jpeg *)rt_malloc(sizeof(struct rtgui_image_jpeg));
if (jpeg == RT_NULL)
{
break;
}
jpeg->filerw = file;
jpeg->is_loaded = RT_FALSE;
jpeg->to_buffer = load;
jpeg->scale = scale;
#if (JD_FORMAT == 0)
jpeg->byte_per_pixel = 3;
#elif (JD_FORMAT == 1)
jpeg->byte_per_pixel = 2;
#endif
jpeg->pool = RT_NULL;
jpeg->pixels = RT_NULL;
jpeg->pool = rt_malloc(TJPGD_WORKING_BUFFER_SIZE);
if (jpeg->pool == RT_NULL)
{
rt_kprintf("TJPGD err: no mem (%d)\n", TJPGD_WORKING_BUFFER_SIZE);
break;
}
if (rtgui_filerw_seek(jpeg->filerw, 0, SEEK_SET) == -1)
{
break;
}
ret = jd_prepare(&jpeg->tjpgd, tjpgd_in_func, jpeg->pool,
TJPGD_WORKING_BUFFER_SIZE, (void *)jpeg);
if (ret != JDR_OK)
{
if (ret == JDR_FMT3)
{
rt_kprintf("TJPGD: not supported format\n");
}
break;
}
rt_kprintf("TJPGD: prepare OK\n");
image->w = (rt_uint16_t)jpeg->tjpgd.width >> jpeg->scale;
image->h = (rt_uint16_t)jpeg->tjpgd.height >> jpeg->scale;
/* set image private data and engine */
image->data = jpeg;
image->engine = &rtgui_image_jpeg_engine;
if (jpeg->to_buffer == RT_TRUE)
{
jpeg->pixels = (rt_uint8_t *)rtgui_malloc(
jpeg->byte_per_pixel * image->w * image->h);
if (jpeg->pixels == RT_NULL)
{
rt_kprintf("TJPGD err: no mem to load (%d)\n",
jpeg->byte_per_pixel * image->w * image->h);
break;
}
ret = jd_decomp(&jpeg->tjpgd, tjpgd_out_func, jpeg->scale);
if (ret != JDR_OK)
{
break;
}
rtgui_filerw_close(jpeg->filerw);
jpeg->is_loaded = RT_TRUE;
rt_kprintf("TJPGD: load to RAM\n");
}
res = RT_TRUE;
} while(0);
if (!res || jpeg->is_loaded)
{
rt_free(jpeg->pool);
}
if (!res)
{
rtgui_free(jpeg->pixels);
rt_free(jpeg);
}
/* create jpeg image successful */
return res;
}
static void rtgui_image_jpeg_unload(struct rtgui_image* image)
{
if (image != RT_NULL)
{
struct rtgui_image_jpeg* jpeg;
jpeg = (struct rtgui_image_jpeg*) image->data;
RT_ASSERT(jpeg != RT_NULL);
if (jpeg->to_buffer == RT_TRUE)
{
if (jpeg->is_loaded == RT_TRUE)
{
rtgui_free(jpeg->pixels);
}
if (jpeg->is_loaded != RT_TRUE)
{
rtgui_filerw_close(jpeg->filerw);
}
}
else
{
rt_free(jpeg->pool);
rtgui_filerw_close(jpeg->filerw);
}
rt_free(jpeg);
}
rt_kprintf("TJPGD: unload\n");
}
static void rtgui_image_jpeg_blit(struct rtgui_image* image,
struct rtgui_dc* dc, struct rtgui_rect* dst_rect)
{
rt_uint16_t w, h, y;
struct rtgui_image_jpeg *jpeg;
jpeg = (struct rtgui_image_jpeg *) image->data;
RT_ASSERT(image != RT_NULL || dc != RT_NULL || dst_rect != RT_NULL || jpeg != RT_NULL);
do
{
/* this dc is not visible */
if (rtgui_dc_get_visible(dc) != RT_TRUE)
{
break;
}
jpeg->dc= dc;
/* the minimum rect */
if (image->w < rtgui_rect_width(*dst_rect))
{
w = image->w;
}
else
{
w = rtgui_rect_width(*dst_rect);
}
if (image->h < rtgui_rect_height(*dst_rect))
{
h = image->h;
}
else
{
h = rtgui_rect_height(*dst_rect);
}
if (!jpeg->is_loaded)
{
JRESULT ret;
jpeg->dst_x = dst_rect->x1;
jpeg->dst_y = dst_rect->y1;
jpeg->dst_w = w;
jpeg->dst_h = h;
ret = jd_decomp(&jpeg->tjpgd, tjpgd_out_func, jpeg->scale);
if (ret != JDR_OK)
{
break;
}
rt_kprintf("TJPGD: load to display\n");
}
else
{
rt_uint8_t* src = jpeg->pixels;
rt_uint16_t imageWidth = image->w * jpeg->byte_per_pixel;
rtgui_blit_line_func blit_line = RT_NULL;
if (jpeg->byte_per_pixel == hw_driver->bits_per_pixel / 8)
{
if (hw_driver->pixel_format == RTGRAPHIC_PIXEL_FORMAT_RGB565)
{
blit_line = rtgui_blit_line_get_inv(hw_driver->bits_per_pixel / 8, jpeg->byte_per_pixel);
}
}
else
{
blit_line = rtgui_blit_line_get(hw_driver->bits_per_pixel / 8, jpeg->byte_per_pixel);
}
if (blit_line)
{
rt_uint16_t x;
rt_uint8_t temp[4];
for (y = 0; y < h; y++)
{
for (x = 0; x < w; x++)
{
blit_line(temp, src, jpeg->byte_per_pixel);
src += jpeg->byte_per_pixel;
dc->engine->blit_line(dc,
dst_rect->x1 + x, dst_rect->x1 + x,
dst_rect->y1 + y,
temp);
}
}
}
else
{
for (y = 0; y < h; y++)
{
dc->engine->blit_line(dc,
dst_rect->x1, dst_rect->x1 + w - 1,
dst_rect->y1 + y,
src);
src += imageWidth;
}
}
}
} while(0);
}
#endif /* defined(RTGUI_IMAGE_TJPGD) */
/***************************************************************************//**
* @}
******************************************************************************/
......@@ -242,9 +242,16 @@ static void rtgui_image_png_unload(struct rtgui_image* image)
static void rtgui_image_png_blit(struct rtgui_image* image, struct rtgui_dc* dc, struct rtgui_rect* rect)
{
struct rtgui_graphic_driver* hwdev = rtgui_graphic_get_device();
rt_uint16_t x, y, w, h;
rtgui_color_t* ptr;
struct rtgui_image_png* png;
int fg_maxsample;
int ialpha;
float alpha;
rtgui_color_t color;
rtgui_color_t c, bgcolor;
int fc[3], bc[3];
RT_ASSERT(image != RT_NULL && dc != RT_NULL && rect != RT_NULL);
RT_ASSERT(image->data != RT_NULL);
......@@ -255,21 +262,56 @@ static void rtgui_image_png_blit(struct rtgui_image* image, struct rtgui_dc* dc,
else w = rtgui_rect_width(*rect);
if (image->h < rtgui_rect_height(*rect)) h = image->h;
else h = rtgui_rect_height(*rect);
fg_maxsample = (1 << png->info_ptr->bit_depth) - 1;
if (png->pixels != RT_NULL)
{
ptr = (rtgui_color_t*)png->pixels;
/* draw each point within dc */
bgcolor = rtgui_color_from_565(RTGUI_DC_BC(dc));
bc[0] = RTGUI_RGB_R(bgcolor);
bc[1] = RTGUI_RGB_G(bgcolor);
bc[2] = RTGUI_RGB_B(bgcolor);
/* draw each point within dc */
for (y = 0; y < h; y ++)
{
for (x = 0; x < w; x++)
{
/* not alpha */
if ((*ptr >> 24) != 255)
{
rtgui_dc_draw_color_point(dc, x + rect->x1, y + rect->y1, *ptr);
}
c = *ptr;
ialpha = RTGUI_RGB_A(c);
if(ialpha == 0)
{
/*
* Foreground image is transparent hear.
* If the background image is already in the frame
* buffer, there is nothing to do.
*/
}
else if (ialpha == fg_maxsample)
{
/*
* Copy foreground pixel to frame buffer.
*/
rtgui_dc_draw_color_point(dc, x + rect->x1, y + rect->y1, c);
}
else
{ /* output = alpha * foreground + (1-alpha) * background */
/*
* Compositing is necessary.
* Get floating-point alpha and its complement.
* Note: alpha is always linear: gamma does not
* affect it.
*/
fc[0] = RTGUI_RGB_R(c);
fc[1] = RTGUI_RGB_G(c);
fc[2] = RTGUI_RGB_B(c);
alpha = (float) ialpha / fg_maxsample;
color = RTGUI_RGB( (rt_uint8_t)(fc[0]*alpha + bc[0]*(1-alpha)),
(rt_uint8_t)(fc[1]*alpha + bc[1]*(1-alpha)),
(rt_uint8_t)(fc[2]*alpha + bc[2]*(1-alpha)));
rtgui_dc_draw_color_point(dc, x + rect->x1, y + rect->y1, color);
}
/* move to next color buffer */
ptr ++;
}
......
/*
* Change Logs:
* Date Author Notes
* 2012-01-24 onelife add mono color support
* 2012-01-24 onelife fix a bug in _pixel_draw_raw_hline
*/
#include <rtgui/rtgui_system.h>
#include <rtgui/driver.h>
#define gfx_device (rtgui_graphic_get_device()->device)
#define gfx_device_ops rt_graphix_ops(gfx_device)
static void _pixel_mono_set_pixel(rtgui_color_t *c, int x, int y)
{
rt_uint8_t pixel;
pixel = rtgui_color_to_mono(*c);
gfx_device_ops->set_pixel((char*)&pixel, x, y);
}
static void _pixel_rgb565p_set_pixel(rtgui_color_t *c, int x, int y)
{
rt_uint16_t pixel;
......@@ -28,6 +42,14 @@ static void _pixel_rgb888_set_pixel(rtgui_color_t *c, int x, int y)
gfx_device_ops->set_pixel((char*)&pixel, x, y);
}
static void _pixel_mono_get_pixel(rtgui_color_t *c, int x, int y)
{
rt_uint8_t pixel;
gfx_device_ops->get_pixel((char*)&pixel, x, y);
*c = rtgui_color_from_mono(pixel);
}
static void _pixel_rgb565p_get_pixel(rtgui_color_t *c, int x, int y)
{
rt_uint16_t pixel;
......@@ -52,6 +74,14 @@ static void _pixel_rgb888_get_pixel(rtgui_color_t *c, int x, int y)
*c = rtgui_color_from_888(pixel);
}
static void _pixel_mono_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
{
rt_uint8_t pixel;
pixel = rtgui_color_to_mono(*c);
gfx_device_ops->draw_hline((char*)&pixel, x1, x2, y);
}
static void _pixel_rgb565p_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
{
rt_uint16_t pixel;
......@@ -76,6 +106,14 @@ static void _pixel_rgb888_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
gfx_device_ops->draw_hline((char*)&pixel, x1, x2, y);
}
static void _pixel_mono_draw_vline(rtgui_color_t *c, int x, int y1, int y2)
{
rt_uint8_t pixel;
pixel = rtgui_color_to_mono(*c);
gfx_device_ops->draw_vline((char*)&pixel, x, y1, y2);
}
static void _pixel_rgb565p_draw_vline(rtgui_color_t *c, int x, int y1, int y2)
{
rt_uint16_t pixel;
......@@ -102,13 +140,19 @@ static void _pixel_rgb888_draw_vline(rtgui_color_t *c, int x, int y1, int y2)
static void _pixel_draw_raw_hline(rt_uint8_t *pixels, int x1, int x2, int y)
{
if (x2 > x1)
gfx_device_ops->blit_line((char*)pixels, x1, y, (x2 - x1));
else
gfx_device_ops->blit_line((char*)pixels, x2, y, (x1 - x2));
gfx_device_ops->blit_line((char*)pixels, x1, x2, y);
}
/* pixel device */
const struct rtgui_graphic_driver_ops _pixel_mono_ops =
{
_pixel_mono_set_pixel,
_pixel_mono_get_pixel,
_pixel_mono_draw_hline,
_pixel_mono_draw_vline,
_pixel_draw_raw_hline,
};
const struct rtgui_graphic_driver_ops _pixel_rgb565p_ops =
{
_pixel_rgb565p_set_pixel,
......@@ -140,6 +184,9 @@ const struct rtgui_graphic_driver_ops *rtgui_pixel_device_get_ops(int pixel_form
{
switch (pixel_format)
{
case RTGRAPHIC_PIXEL_FORMAT_MONO:
return &_pixel_mono_ops;
case RTGRAPHIC_PIXEL_FORMAT_RGB565:
return &_pixel_rgb565_ops;
......
/*
* File : rtgui_application.c
* This file is part of RTGUI in RT-Thread RTOS
* COPYRIGHT (C) 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(just a prototype of application API)
* 2012-07-07 Bernard move the send/recv message to the rtgui_system.c
*/
#include <rtgui/rtgui_system.h>
#include <rtgui/rtgui_app.h>
#include <rtgui/widgets/window.h>
static void _rtgui_app_constructor(struct rtgui_app *app)
{
/* set event handler */
rtgui_object_set_event_handler(RTGUI_OBJECT(app),
rtgui_app_event_handler);
app->name = RT_NULL;
/* set EXITED so we can destroy an application that just created */
app->state_flag = RTGUI_APP_FLAG_EXITED;
app->ref_count = 0;
app->exit_code = 0;
app->tid = RT_NULL;
app->server = RT_NULL;
app->mq = RT_NULL;
app->modal_object = RT_NULL;
app->main_object = RT_NULL;
app->on_idle = RT_NULL;
}
static void _rtgui_app_destructor(struct rtgui_app *app)
{
RT_ASSERT(app != RT_NULL);
rt_free(app->name);
app->name = RT_NULL;
}
DEFINE_CLASS_TYPE(application, "application",
RTGUI_OBJECT_TYPE,
_rtgui_app_constructor,
_rtgui_app_destructor,
sizeof(struct rtgui_app));
struct rtgui_app* rtgui_app_create(
rt_thread_t tid,
const char *title)
{
rt_thread_t srv_tid;
struct rtgui_app *app;
struct rtgui_event_application event;
RT_ASSERT(tid != RT_NULL);
RT_ASSERT(title != RT_NULL);
/* create application */
app = RTGUI_APP(rtgui_object_create(RTGUI_APP_TYPE));
if (app == RT_NULL)
return RT_NULL;
/* one thread only can create one rtgui application */
RT_ASSERT(tid->user_data == 0);
app->tid = tid;
/* set user thread */
tid->user_data = (rt_uint32_t)app;
app->mq = rt_mq_create("rtgui", sizeof(union rtgui_event_generic), 32, RT_IPC_FLAG_FIFO);
if (app->mq == RT_NULL)
{
rt_kprintf("create msgq failed.\n");
goto __mq_err;
}
/* set application title */
app->name = (unsigned char*)rt_strdup((char*)title);
if (app->name == RT_NULL)
goto __err;
/* send a message to notify rtgui server */
srv_tid = rtgui_get_server();
if (srv_tid == RT_NULL)
{
rt_kprintf("gui server is not running.\n");
goto __err;
}
/* create the rtgui server application */
if (srv_tid == rt_thread_self())
return app;
RTGUI_EVENT_APP_CREATE_INIT(&event);
event.app = app;
/* notify rtgui server to one application has been created */
if (rtgui_send_sync(srv_tid, RTGUI_EVENT(&event), sizeof(event)) == RT_EOK)
{
return app;
}
__err:
__mq_err:
rtgui_object_destroy(RTGUI_OBJECT(app));
tid->user_data = 0;
return RT_NULL;
}
#define _rtgui_application_check(app) \
do { \
RT_ASSERT(app != RT_NULL); \
RT_ASSERT(app->tid != RT_NULL); \
RT_ASSERT(app->tid->user_data != 0); \
RT_ASSERT(app->mq != RT_NULL); \
} while (0)
void rtgui_app_destroy(struct rtgui_app *app)
{
rt_thread_t srv_tid;
_rtgui_application_check(app);
if (!(app->state_flag & RTGUI_APP_FLAG_EXITED))
{
rt_kprintf("cannot destroy a running application: %s.\n",
app->name);
return;
}
/* send a message to notify rtgui server */
srv_tid = rtgui_get_server();
if (srv_tid != rt_thread_self()) /* must not the server thread */
{
struct rtgui_event_application event;
RTGUI_EVENT_APP_DESTROY_INIT(&event);
event.app = app;
if (rtgui_send_sync(srv_tid, RTGUI_EVENT(&event), sizeof(event)) != RT_EOK)
{
rt_kprintf("destroy an application in server failed\n");
return ;
}
}
app->tid->user_data = 0;
rt_mq_delete(app->mq);
rtgui_object_destroy(RTGUI_OBJECT(app));
}
struct rtgui_app* rtgui_app_self(void)
{
struct rtgui_app *app;
rt_thread_t self;
/* get current thread */
self = rt_thread_self();
app = (struct rtgui_app*)(self->user_data);
return app;
}
void rtgui_app_set_onidle(rtgui_idle_func_t onidle)
{
struct rtgui_app *app;
app = rtgui_app_self();
if (app != RT_NULL)
app->on_idle = onidle;
}
rtgui_idle_func_t rtgui_app_get_onidle(void)
{
struct rtgui_app *app;
app = rtgui_app_self();
if (app != RT_NULL)
return app->on_idle;
else
return RT_NULL;
}
rt_inline rt_bool_t _rtgui_application_dest_handle(
struct rtgui_app *app,
struct rtgui_event *event)
{
struct rtgui_event_win* wevent = (struct rtgui_event_win*)event;
struct rtgui_object* dest_object = RTGUI_OBJECT(wevent->wid);
if (dest_object != RT_NULL)
{
if (dest_object->event_handler != RT_NULL)
return dest_object->event_handler(RTGUI_OBJECT(dest_object), event);
else
return RT_FALSE;
}
else
{
rt_kprintf("RTGUI ERROR:server sent a event(%d) without wid\n", event->type);
return RT_FALSE;
}
}
rt_bool_t rtgui_app_event_handler(struct rtgui_object* object, rtgui_event_t* event)
{
struct rtgui_app* app;
RT_ASSERT(object != RT_NULL);
RT_ASSERT(event != RT_NULL);
app = RTGUI_APP(object);
switch (event->type)
{
case RTGUI_EVENT_PAINT:
case RTGUI_EVENT_CLIP_INFO:
case RTGUI_EVENT_WIN_ACTIVATE:
case RTGUI_EVENT_WIN_DEACTIVATE:
case RTGUI_EVENT_WIN_CLOSE:
case RTGUI_EVENT_WIN_MOVE:
case RTGUI_EVENT_KBD:
_rtgui_application_dest_handle(app, event);
break;
case RTGUI_EVENT_APP_ACTIVATE:
if (app->main_object != RT_NULL)
{
rtgui_win_activate(RTGUI_WIN(app->main_object));
if (app->modal_object != RT_NULL)
rtgui_win_activate(RTGUI_WIN(app->modal_object));
}
else if (app->modal_object != RT_NULL)
{
rtgui_win_activate(RTGUI_WIN(app->modal_object));
}
break;
case RTGUI_EVENT_MOUSE_BUTTON:
case RTGUI_EVENT_MOUSE_MOTION:
{
struct rtgui_event_win* wevent = (struct rtgui_event_win*)event;
struct rtgui_object* dest_object = RTGUI_OBJECT(wevent->wid);
// FIXME: let application determine the dest_wiget but not in sever
// so we can combine this handler with above one
if (app->modal_object != RT_NULL &&
dest_object != app->modal_object)
{
// rt_kprintf("discard event %s that is not sent to modal object\n",
// event_string[event->type]);
}
else
{
_rtgui_application_dest_handle(app, event);
}
}
break;
case RTGUI_EVENT_TIMER:
{
struct rtgui_timer* timer;
struct rtgui_event_timer* etimer = (struct rtgui_event_timer*) event;
timer = etimer->timer;
if (timer->timeout != RT_NULL)
{
/* call timeout function */
timer->timeout(timer, timer->user_data);
}
}
break;
case RTGUI_EVENT_COMMAND:
{
struct rtgui_event_command *ecmd = (struct rtgui_event_command*)event;
if (ecmd->wid != RT_NULL)
return _rtgui_application_dest_handle(app, event);
}
default:
return rtgui_object_event_handler(object, event);
}
return RT_TRUE;
}
rt_inline void _rtgui_application_event_loop(struct rtgui_app *app)
{
rt_err_t result;
rt_uint16_t current_ref;
struct rtgui_event *event;
_rtgui_application_check(app);
/* point to event buffer */
event = (struct rtgui_event*)app->event_buffer;
current_ref = ++app->ref_count;
while (current_ref <= app->ref_count)
{
RT_ASSERT(current_ref == app->ref_count);
if (app->on_idle != RT_NULL)
{
result = rtgui_recv_nosuspend(event, sizeof(union rtgui_event_generic));
if (result == RT_EOK)
RTGUI_OBJECT(app)->event_handler(RTGUI_OBJECT(app), event);
else if (result == -RT_ETIMEOUT)
app->on_idle(RTGUI_OBJECT(app), RT_NULL);
}
else
{
result = rtgui_recv(event, sizeof(union rtgui_event_generic));
if (result == RT_EOK)
RTGUI_OBJECT(app)->event_handler(RTGUI_OBJECT(app), event);
}
}
}
rt_base_t rtgui_app_run(struct rtgui_app *app)
{
_rtgui_application_check(app);
app->state_flag &= ~RTGUI_APP_FLAG_EXITED;
_rtgui_application_event_loop(app);
if (app->ref_count == 0)
app->state_flag |= RTGUI_APP_FLAG_EXITED;
return app->exit_code;
}
void rtgui_app_exit(struct rtgui_app* app, rt_uint16_t code)
{
--app->ref_count;
app->exit_code = code;
}
/**
* set this application as window manager
*/
rt_err_t rtgui_app_set_as_wm(void)
{
rt_thread_t srv_tid;
struct rtgui_event_set_wm event;
struct rtgui_app* app;
srv_tid = rtgui_get_server();
app = rtgui_app_self();
if (app != RT_NULL && srv_tid != RT_NULL)
{
/* notify rtgui server, this is a window manager */
RTGUI_EVENT_SET_WM_INIT(&event);
event.app = app;
rtgui_send_sync(srv_tid, RTGUI_EVENT(&event), sizeof(event));
return RT_EOK;
}
return RT_ERROR;
}
void rtgui_app_set_main_win(struct rtgui_win* win)
{
struct rtgui_app *app;
app = rtgui_app_self();
if (app != RT_NULL)
{
app->main_object = RTGUI_OBJECT(win);
}
}
......@@ -16,7 +16,7 @@
#include <rtgui/image.h>
#include <rtgui/font.h>
#include <rtgui/event.h>
#include <rtgui/rtgui_application.h>
#include <rtgui/rtgui_app.h>
#include <rtgui/rtgui_server.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/window.h>
......@@ -26,7 +26,7 @@
#define RTGUI_MEM_TRACE
#endif
void rtgui_system_server_init(void)
void rtgui_system_server_init()
{
/* init image */
rtgui_system_image_init();
......@@ -59,7 +59,7 @@ static void rtgui_time_out(void* parameter)
event.timer = timer;
rtgui_application_send(timer->tid, &(event.parent), sizeof(rtgui_event_timer_t));
rtgui_send(timer->tid, &(event.parent), sizeof(rtgui_event_timer_t));
}
rtgui_timer_t* rtgui_timer_create(rt_int32_t time, rt_int32_t flag, rtgui_timeout_func timeout, void* parameter)
......@@ -285,3 +285,416 @@ void rtgui_free(void* ptr)
rt_free(ptr);
}
#if defined(RTGUI_MEM_TRACE) && defined(RT_USING_FINSH)
#include <finsh.h>
void list_mem(void)
{
rt_kprintf("Current Used: %d, Maximal Used: %d\n", mem_info.allocated_size, mem_info.max_allocated);
}
FINSH_FUNCTION_EXPORT(list_mem, display memory information);
#endif
/************************************************************************/
/* RTGUI Event Dump */
/************************************************************************/
#ifdef _WIN32
#define RTGUI_EVENT_DEBUG
#endif
#ifdef RTGUI_EVENT_DEBUG
const char *event_string[] =
{
/* application event */
"APP_CREATE", /* create an application */
"APP_DESTROY", /* destroy an application */
"APP_ACTIVATE", /* activate an application */
/* window event */
"WIN_CREATE", /* create a window */
"WIN_DESTROY", /* destroy a window */
"WIN_SHOW", /* show a window */
"WIN_HIDE", /* hide a window */
"WIN_ACTIVATE", /* activate a window */
"WIN_DEACTIVATE", /* deactivate a window */
"WIN_CLOSE", /* close a window */
"WIN_MOVE", /* move a window */
"WIN_RESIZE", /* resize a window */
"WIN_MODAL_ENTER", /* a window modals */
"SET_WM", /* set window manager */
"UPDATE_BEGIN", /* begin of update rect */
"UPDATE_END", /* end of update rect */
"MONITOR_ADD", /* add a monitor rect */
"MONITOR_REMOVE", /* remove a monitor rect*/
"SHOW", /* the widget is going to be shown */
"HIDE", /* the widget is going to be hidden */
"PAINT", /* paint on screen */
"TIMER", /* timer */
/* clip rect information */
"CLIP_INFO", /* clip rect info */
/* mouse and keyboard event */
"MOUSE_MOTION", /* mouse motion */
"MOUSE_BUTTON", /* mouse button info */
"KBD", /* keyboard info */
/* user command event */
"COMMAND", /* user command */
/* request's status event */
"STATUS", /* request result */
"SCROLLED", /* scroll bar scrolled */
"RESIZE", /* widget resize */
};
#define DBG_MSG(x) rt_kprintf x
static void rtgui_event_dump(rt_thread_t tid, rtgui_event_t* event)
{
char* sender = "(unknown)";
if ((event->type == RTGUI_EVENT_TIMER) ||
(event->type == RTGUI_EVENT_UPDATE_BEGIN) ||
(event->type == RTGUI_EVENT_MOUSE_MOTION) ||
(event->type == RTGUI_EVENT_UPDATE_END))
{
/* don't dump timer event */
return ;
}
if (event->sender != RT_NULL)
sender = event->sender->name;
rt_kprintf("%s -- %s --> %s ", sender, event_string[event->type], tid->name);
switch (event->type)
{
case RTGUI_EVENT_APP_CREATE:
case RTGUI_EVENT_APP_DESTROY:
case RTGUI_EVENT_APP_ACTIVATE:
{
struct rtgui_event_application *eapp = (struct rtgui_event_application *)event;
rt_kprintf("app: %s", eapp->app->name);
}
break;
case RTGUI_EVENT_PAINT:
{
struct rtgui_event_paint *paint = (struct rtgui_event_paint *)event;
if(paint->wid != RT_NULL)
rt_kprintf("win: %s", paint->wid->title);
}
break;
case RTGUI_EVENT_KBD:
{
struct rtgui_event_kbd *ekbd = (struct rtgui_event_kbd*) event;
if (ekbd->wid != RT_NULL)
rt_kprintf("win: %s", ekbd->wid->title);
if (RTGUI_KBD_IS_UP(ekbd)) rt_kprintf(", up");
else rt_kprintf(", down");
}
break;
case RTGUI_EVENT_CLIP_INFO:
{
struct rtgui_event_clip_info *info = (struct rtgui_event_clip_info *)event;
if(info->wid != RT_NULL)
rt_kprintf("win: %s", info->wid->title);
}
break;
case RTGUI_EVENT_WIN_CREATE:
{
struct rtgui_event_win_create *create = (struct rtgui_event_win_create*)event;
rt_kprintf(" win: %s at (x1:%d, y1:%d, x2:%d, y2:%d), addr: %p",
#ifdef RTGUI_USING_SMALL_SIZE
create->wid->title,
RTGUI_WIDGET(create->wid)->extent.x1,
RTGUI_WIDGET(create->wid)->extent.y1,
RTGUI_WIDGET(create->wid)->extent.x2,
RTGUI_WIDGET(create->wid)->extent.y2,
#else
create->title,
create->extent.x1,
create->extent.y1,
create->extent.x2,
create->extent.y2,
#endif
create->wid
);
}
break;
case RTGUI_EVENT_UPDATE_END:
{
struct rtgui_event_update_end* update_end = (struct rtgui_event_update_end*)event;
rt_kprintf("(x:%d, y1:%d, x2:%d, y2:%d)", update_end->rect.x1,
update_end->rect.y1,
update_end->rect.x2,
update_end->rect.y2);
}
break;
case RTGUI_EVENT_WIN_ACTIVATE:
case RTGUI_EVENT_WIN_DEACTIVATE:
case RTGUI_EVENT_WIN_SHOW:
case RTGUI_EVENT_WIN_MODAL_ENTER:
{
struct rtgui_event_win *win = (struct rtgui_event_win *)event;
if(win->wid != RT_NULL)
rt_kprintf("win: %s", win->wid->title);
}
break;
case RTGUI_EVENT_WIN_MOVE:
{
struct rtgui_event_win_move *win = (struct rtgui_event_win_move *)event;
if(win->wid != RT_NULL)
{
rt_kprintf("win: %s", win->wid->title);
rt_kprintf(" to (x:%d, y:%d)", win->x, win->y);
}
}
break;
case RTGUI_EVENT_WIN_RESIZE:
{
struct rtgui_event_win_resize* win = (struct rtgui_event_win_resize *)event;
if (win->wid != RT_NULL)
{
rt_kprintf("win: %s, rect(x1:%d, y1:%d, x2:%d, y2:%d)", win->wid->title,
RTGUI_WIDGET(win->wid)->extent.x1,
RTGUI_WIDGET(win->wid)->extent.y1,
RTGUI_WIDGET(win->wid)->extent.x2,
RTGUI_WIDGET(win->wid)->extent.y2);
}
}
break;
case RTGUI_EVENT_MOUSE_BUTTON:
case RTGUI_EVENT_MOUSE_MOTION:
{
struct rtgui_event_mouse *mouse = (struct rtgui_event_mouse*)event;
if (mouse->button & RTGUI_MOUSE_BUTTON_LEFT) rt_kprintf("left ");
else rt_kprintf("right ");
if (mouse->button & RTGUI_MOUSE_BUTTON_DOWN) rt_kprintf("down ");
else rt_kprintf("up ");
if (mouse->wid != RT_NULL)
rt_kprintf("win: %s at (%d, %d)", mouse->wid->title,
mouse->x, mouse->y);
else
rt_kprintf("(%d, %d)", mouse->x, mouse->y);
}
break;
case RTGUI_EVENT_MONITOR_ADD:
{
struct rtgui_event_monitor *monitor = (struct rtgui_event_monitor*)event;
if (monitor->wid != RT_NULL)
{
rt_kprintf("win: %s, the rect is:(%d, %d) - (%d, %d)", monitor->wid->title,
monitor->rect.x1, monitor->rect.y1,
monitor->rect.x2, monitor->rect.y2);
}
}
break;
}
rt_kprintf("\n");
}
#else
#define DBG_MSG(x)
#define rtgui_event_dump(tid, event)
#endif
/************************************************************************/
/* RTGUI IPC APIs */
/************************************************************************/
rt_err_t rtgui_send(rt_thread_t tid, rtgui_event_t* event, rt_size_t event_size)
{
rt_err_t result;
struct rtgui_app *app;
RT_ASSERT(tid != RT_NULL);
RT_ASSERT(event != RT_NULL);
RT_ASSERT(event_size != 0);
rtgui_event_dump(tid, event);
/* find struct rtgui_application */
app = (struct rtgui_app*) (tid->user_data);
if (app == RT_NULL)
return -RT_ERROR;
result = rt_mq_send(app->mq, event, event_size);
if (result != RT_EOK)
{
if (event->type != RTGUI_EVENT_TIMER)
rt_kprintf("send event to %s failed\n", app->tid->name);
}
return result;
}
rt_err_t rtgui_send_urgent(rt_thread_t tid, rtgui_event_t* event, rt_size_t event_size)
{
rt_err_t result;
struct rtgui_app *app;
RT_ASSERT(tid != RT_NULL);
RT_ASSERT(event != RT_NULL);
RT_ASSERT(event_size != 0);
rtgui_event_dump(tid, event);
/* find rtgui_application */
app = (struct rtgui_app*) (tid->user_data);
if (app == RT_NULL)
return -RT_ERROR;
result = rt_mq_urgent(app->mq, event, event_size);
if (result != RT_EOK)
rt_kprintf("send ergent event failed\n");
return result;
}
rt_err_t rtgui_send_sync(rt_thread_t tid, rtgui_event_t* event, rt_size_t event_size)
{
rt_err_t r;
struct rtgui_app *app;
rt_int32_t ack_buffer, ack_status;
struct rt_mailbox ack_mb;
RT_ASSERT(tid != RT_NULL);
RT_ASSERT(event != RT_NULL);
RT_ASSERT(event_size != 0);
rtgui_event_dump(tid, event);
/* init ack mailbox */
r = rt_mb_init(&ack_mb, "ack", &ack_buffer, 1, 0);
if (r!= RT_EOK)
goto __return;
app = (struct rtgui_app*) (tid->user_data);
if (app == RT_NULL)
{
r = -RT_ERROR;
goto __return;
}
event->ack = &ack_mb;
r = rt_mq_send(app->mq, event, event_size);
if (r != RT_EOK)
{
rt_kprintf("send sync event failed\n");
goto __return;
}
r = rt_mb_recv(&ack_mb, (rt_uint32_t*)&ack_status, RT_WAITING_FOREVER);
if (r!= RT_EOK)
goto __return;
if (ack_status != RTGUI_STATUS_OK)
r = -RT_ERROR;
else
r = RT_EOK;
__return:
/* fini ack mailbox */
rt_mb_detach(&ack_mb);
return r;
}
rt_err_t rtgui_ack(rtgui_event_t* event, rt_int32_t status)
{
RT_ASSERT(event != RT_NULL);
RT_ASSERT(event->ack != RT_NULL);
rt_mb_send(event->ack, status);
return RT_EOK;
}
rt_err_t rtgui_recv(rtgui_event_t* event, rt_size_t event_size)
{
struct rtgui_app* app;
rt_err_t r;
RT_ASSERT(event != RT_NULL);
RT_ASSERT(event_size != 0);
app = (struct rtgui_app*) (rt_thread_self()->user_data);
if (app == RT_NULL)
return -RT_ERROR;
r = rt_mq_recv(app->mq, event, event_size, RT_WAITING_FOREVER);
return r;
}
rt_err_t rtgui_recv_nosuspend(rtgui_event_t* event, rt_size_t event_size)
{
struct rtgui_app *app;
rt_err_t r;
RT_ASSERT(event != RT_NULL);
RT_ASSERT(event != 0);
app = (struct rtgui_app*) (rt_thread_self()->user_data);
if (app == RT_NULL)
return -RT_ERROR;
r = rt_mq_recv(app->mq, event, event_size, 0);
return r;
}
rt_err_t rtgui_recv_filter(rt_uint32_t type, rtgui_event_t* event, rt_size_t event_size)
{
struct rtgui_app *app;
RT_ASSERT(event != RT_NULL);
RT_ASSERT(event_size != 0);
app = (struct rtgui_app*) (rt_thread_self()->user_data);
if (app == RT_NULL)
return -RT_ERROR;
while (rt_mq_recv(app->mq, event, event_size, RT_WAITING_FOREVER) == RT_EOK)
{
if (event->type == type)
{
return RT_EOK;
}
else
{
if (RTGUI_OBJECT(app)->event_handler != RT_NULL)
{
RTGUI_OBJECT(app)->event_handler(RTGUI_OBJECT(app), event);
}
}
}
return -RT_ERROR;
}
rt_thread_t rtgui_get_server(void)
{
return rt_thread_find("rtgui");
}
......@@ -14,3 +14,5 @@ slider 处理上下键,上面的值小,下面的值大。
6, view 不再提供 show 方法。如果想单独显示控件,请用 window 包含之。
7, 若窗口在销毁(destroy)时没有关闭,则 RTGUI 会先关闭之。也会调用 on_close 函数
但是此函数的返回值会被忽略。
......@@ -46,9 +46,9 @@ mq 的模式。rtgui_application 记录当前依附的 panel,和 panel 的 ext
10, 在 widget 中添加 on_show 和 on_hide 事件回调函数。(Done)
11, 添加 EVENT_WIN_MODAL_ENTER 和 EVENT_WIN_MODAL_EXIT 事件,用来通知窗口管理器
(topwin)一个窗口进入模态。窗口管理器根据这个进行相应的设置。
(topwin)一个窗口进入模态。窗口管理器根据这个进行相应的设置。(Done)
12, rtgui_filelist_view 不必继承自 container。
12, rtgui_filelist_view 不必继承自 container。(Deprecated)
13, 添加 desktop window 支持。(Done)
概念与名词:
......
......@@ -5,5 +5,6 @@
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);
#endif
......@@ -10,6 +10,7 @@
* 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__
......@@ -45,6 +46,30 @@ extern const rtgui_color_t light_grey;
* BBBB BBBB GGGG GGGG RRRR RRRR
*/
/* 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 BBBBBGGGGGGRRRRR */
rt_inline rt_uint16_t rtgui_color_to_565(rtgui_color_t c)
{
......
......@@ -54,6 +54,7 @@ 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_uint8_t* rtgui_graphic_driver_get_default_framebuffer(void);
rt_err_t rtgui_graphic_set_device(rt_device_t device);
......
......@@ -21,6 +21,11 @@
* 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 */
......@@ -43,6 +48,8 @@ enum _rtgui_event_type
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 */
......@@ -94,6 +101,24 @@ typedef struct rtgui_event rtgui_event_t;
(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;
......@@ -151,6 +176,16 @@ struct rtgui_event_win_resize
#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
*/
......@@ -214,6 +249,12 @@ struct 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)
/*
* RTGUI Mouse and Keyboard Event
*/
......@@ -325,6 +366,12 @@ struct rtgui_event_resize
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;
......
......@@ -30,7 +30,7 @@ struct rtgui_font;
typedef struct rtgui_win rtgui_win_t;
typedef struct rtgui_workbench rtgui_workbench_t;
typedef rt_bool_t (*rtgui_event_handler_ptr)(struct rtgui_object* widget, struct rtgui_event* event);
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);
struct rtgui_point
......
......@@ -22,34 +22,36 @@
DECLARE_CLASS_TYPE(application);
/** Gets the type of a application */
#define RTGUI_APPLICATION_TYPE (RTGUI_TYPE(application))
#define RTGUI_APP_TYPE (RTGUI_TYPE(application))
/** Casts the object to an rtgui_workbench */
#define RTGUI_APPLICATION(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_APPLICATION_TYPE, struct rtgui_application))
#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_APPLICATION(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_APPLICATION_TYPE))
#define RTGUI_IS_APP(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_APP_TYPE))
enum rtgui_application_flag
enum rtgui_app_flag
{
RTGUI_APPLICATION_FLAG_EXITED = 0x04,
RTGUI_APPLICATION_FLAG_SHOWN = 0x08
RTGUI_APP_FLAG_EXITED = 0x04,
RTGUI_APP_FLAG_SHOWN = 0x08
};
typedef void (*rtgui_idle_func)(struct rtgui_object* obj, struct rtgui_event *event);
typedef void (*rtgui_idle_func_t)(struct rtgui_object* obj, struct rtgui_event *event);
struct rtgui_application
struct rtgui_app
{
struct rtgui_object parent;
/* application name */
unsigned char *name;
struct rtgui_image* icon;
enum rtgui_application_flag state_flag;
enum rtgui_app_flag state_flag;
rt_uint16_t ref_count;
rt_uint16_t exit_code;
/* the thread id */
rt_thread_t tid;
/* the RTGUI server id */
rt_thread_t server;
/* the message queue of thread */
......@@ -57,43 +59,30 @@ struct rtgui_application
/* event buffer */
rt_uint8_t event_buffer[sizeof(union rtgui_event_generic)];
/* if not RT_NULL, the application is modaled by modal_object. If is
* RT_NULL, nothing modals. */
/* if not RT_NULL, the application is in modal state by modal_object. If is
* RT_NULL, nothing modal windows. */
struct rtgui_object *modal_object;
struct rtgui_object *main_object;
/* on idle event handler */
rtgui_idle_func on_idle;
rtgui_idle_func_t on_idle;
};
/**
* create an application named @myname on thread @param tid
*/
struct rtgui_application* rtgui_application_create(
rt_thread_t tid,
const char *myname);
void rtgui_application_destroy(struct rtgui_application *app);
rt_err_t rtgui_application_show(struct rtgui_application *app);
rt_err_t rtgui_application_hide(struct rtgui_application *app);
rt_base_t rtgui_application_run(struct rtgui_application *app);
void rtgui_application_exit(struct rtgui_application *app, rt_uint16_t code);
void rtgui_application_set_onidle(rtgui_idle_func onidle);
rtgui_idle_func rtgui_application_get_onidle(void);
struct rtgui_application* rtgui_application_self(void);
rt_thread_t rtgui_application_get_server(void);
void rtgui_application_set_root_object(struct rtgui_object* object);
struct rtgui_object* rtgui_application_get_root_object(void);
struct rtgui_event;
rt_err_t rtgui_application_send(rt_thread_t tid, struct rtgui_event* event, rt_size_t event_size);
rt_err_t rtgui_application_send_urgent(rt_thread_t tid, struct rtgui_event* event, rt_size_t event_size);
rt_err_t rtgui_application_send_sync(rt_thread_t tid, struct rtgui_event* event, rt_size_t event_size);
rt_err_t rtgui_application_ack(struct rtgui_event* event, rt_int32_t status);
rt_err_t rtgui_application_recv(struct rtgui_event* event, rt_size_t event_size);
rt_err_t rtgui_application_recv_nosuspend(struct rtgui_event* event, rt_size_t event_size);
rt_err_t rtgui_application_recv_filter(rt_uint32_t type, struct rtgui_event* event, rt_size_t event_size);
struct rtgui_app* rtgui_app_create(rt_thread_t tid, const char *title);
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_set_onidle(rtgui_idle_func_t onidle);
rtgui_idle_func_t rtgui_app_get_onidle(void);
struct rtgui_app* rtgui_app_self(void);
rt_err_t rtgui_app_set_as_wm(void);
void rtgui_app_set_main_win(struct rtgui_win* win);
#endif /* end of include guard: RTGUI_APPLICATION_H */
......@@ -77,5 +77,6 @@
//#define RTGUI_USING_DESKTOP_WINDOW
#define RTGUI_EVENT_DEBUG
#undef RTGUI_USING_SMALL_SIZE
// #undef RTGUI_USING_SMALL_SIZE
#endif
......@@ -31,7 +31,7 @@ extern "C" {
/** Casts the function pointer to an rtgui_constructor */
#define RTGUI_DESTRUCTOR(destructor) ((rtgui_destructor_t)(destructor))
/* pre-definetion */
/* pre-definition */
struct rtgui_object;
typedef struct rtgui_object rtgui_object_t;
typedef void (*rtgui_constructor_t)(rtgui_object_t *object);
......@@ -125,9 +125,6 @@ rt_bool_t rtgui_object_event_handler(struct rtgui_object *object, struct rtgui_e
/* supress compiler warning */ \
widget = widget;
void rtgui_object_name_set(rtgui_object_t *object, const char *name);
const char *rtgui_object_name_get(rtgui_object_t *object);
rtgui_object_t *rtgui_object_check_cast(rtgui_object_t *object, rtgui_type_t *type, const char* func, int line);
rtgui_type_t *rtk_object_object_type_get(rtgui_object_t *object);
......
......@@ -20,7 +20,7 @@
/* RTGUI server definitions */
/* top window definitions in server */
enum
enum rtgui_topwin_flag
{
WINTITLE_NO = 0x01,
WINTITLE_BORDER = 0x02,
......@@ -34,7 +34,9 @@ enum
/* window is modaled by other window */
WINTITLE_MODALED = 0x80,
/* window is modaling other window */
WINTITLE_MODALING = 0x100
WINTITLE_MODALING = 0x100,
WINTITLE_ONTOP = 0x200,
WINTITLE_ONBTM = 0x400,
};
#define WINTITLE_HEIGHT 20
......@@ -45,7 +47,7 @@ enum
struct rtgui_topwin
{
/* the window flag */
rt_uint32_t flag;
enum rtgui_topwin_flag flag;
/* event mask */
rt_uint32_t mask;
......
......@@ -53,5 +53,16 @@ void* rtgui_realloc(void* ptr, rt_size_t size);
#define rtgui_enter_critical rt_enter_critical
#define rtgui_exit_critical rt_exit_critical
rt_thread_t rtgui_get_server(void);
struct rtgui_event;
rt_err_t rtgui_send(rt_thread_t tid, struct rtgui_event* event, rt_size_t event_size);
rt_err_t rtgui_send_urgent(rt_thread_t tid, struct rtgui_event* event, rt_size_t event_size);
rt_err_t rtgui_send_sync(rt_thread_t tid, 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_err_t rtgui_recv_nosuspend(struct rtgui_event* event, rt_size_t event_size);
rt_err_t rtgui_recv_filter(rt_uint32_t type, struct rtgui_event* event, rt_size_t event_size);
#endif
/*
* File : list_view.h
* This file is part of RTGUI in RT-Thread RTOS
* COPYRIGHT (C) 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-01-06 Bernard first version
*/
#ifndef __RTGUI_ABOUT_VIEW_H__
#define __RTGUI_ABOUT_VIEW_H__
#include <rtgui/rtgui.h>
#include <rtgui/image.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/container.h>
DECLARE_CLASS_TYPE(aboutview);
/** Gets the type of a about view */
#define RTGUI_ABOUT_VIEW_TYPE (RTGUI_TYPE(aboutview))
/** Casts the object to a about view */
#define RTGUI_ABOUT_VIEW(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_ABOUT_VIEW_TYPE, rtgui_about_view_t))
/** Checks if the object is a about view */
#define RTGUI_IS_ABOUT_VIEW(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_ABOUT_VIEW_TYPE))
struct rtgui_about_view
{
struct rtgui_container parent;
/* widget private data */
rtgui_image_t* logo;
const char* description;
};
typedef struct rtgui_about_view rtgui_about_view_t;
rtgui_about_view_t* rtgui_about_view_create(rtgui_image_t *logo, const char* description);
rt_bool_t rtgui_about_view_event_handler(struct rtgui_object* widget, struct rtgui_event* event);
#endif
......@@ -33,26 +33,23 @@ DECLARE_CLASS_TYPE(box);
struct rtgui_box
{
struct rtgui_container parent;
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, rtgui_rect_t* rect);
struct rtgui_box* rtgui_box_create(int orientation, int border_size);
void rtgui_box_destroy(struct rtgui_box* box);
rt_bool_t rtgui_box_event_handler(struct rtgui_object* object, rtgui_event_t* event);
void rtgui_box_append(rtgui_box_t* box, rtgui_widget_t* widget);
void rtgui_box_layout(rtgui_box_t* box);
rt_uint32_t rtgui_box_get_width(rtgui_box_t* box);
rt_uint32_t rtgui_box_get_height(rtgui_box_t* box);
#ifdef __cplusplus
}
#endif
#endif
......@@ -15,6 +15,7 @@
#define __RTGUI_CONTAINER_H__
#include <rtgui/widgets/widget.h>
#include <rtgui/widgets/box.h>
#ifdef __cplusplus
extern "C" {
......@@ -35,6 +36,9 @@ 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;
......@@ -44,12 +48,9 @@ void rtgui_container_destroy(rtgui_container_t* container);
rt_bool_t rtgui_container_event_handler(struct rtgui_object* widget, struct rtgui_event* event);
#ifndef RTGUI_USING_SMALL_SIZE
struct rtgui_box;
/* set layout box */
void rtgui_container_set_box(struct rtgui_container* container, struct rtgui_box* box);
#endif
void rtgui_container_hide(rtgui_container_t* container);
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);
......
......@@ -49,7 +49,7 @@ rtgui_filelist_view_t* rtgui_filelist_view_create(const char* directory,
const rtgui_rect_t* rect);
void rtgui_filelist_view_destroy(rtgui_filelist_view_t* view);
rt_bool_t rtgui_filelist_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event);
rt_bool_t rtgui_filelist_view_event_handler(struct rtgui_object* object, struct rtgui_event* event);
void rtgui_filelist_view_set_directory(rtgui_filelist_view_t* view, const char* directory);
void rtgui_filelist_view_get_fullpath(rtgui_filelist_view_t* view, char* path, rt_size_t len);
......
......@@ -29,7 +29,7 @@ struct rtgui_menu_item
rt_uint16_t submenu_count;
/* menu action */
rt_bool_t (*on_menuaction)(rtgui_widget_t* widget, rtgui_event_t* event);
rt_bool_t (*on_menuaction)(struct rtgui_object* object, struct rtgui_event* event);
};
typedef struct rtgui_menu_item rtgui_menu_item_t;
......
/*
* File : panel.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_PANEL_H__
#define __RTGUI_PANEL_H__
#include <rtgui/rtgui.h>
#include <rtgui/widgets/container.h>
DECLARE_CLASS_TYPE(panel);
/** Gets the type of a panel */
#define RTGUI_PANEL_TYPE (RTGUI_TYPE(panel))
/** Casts the object to an panel */
#define RTGUI_PANEL(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_PANEL_TYPE, rtgui_panel_t))
/** Checks if the object is an rtgui_button */
#define RTGUI_IS_PANEL(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_PANEL_TYPE))
/*
* the panel widget
*/
struct rtgui_panel
{
struct rtgui_container parent;
int border_style;
};
typedef struct rtgui_panel rtgui_panel_t;
rtgui_panel_t* rtgui_panel_create(int border_style);
void rtgui_panel_destroy(rtgui_panel_t* panel);
rt_bool_t rtgui_panel_event_handler(struct rtgui_object* object, struct rtgui_event* event);
#endif
......@@ -14,32 +14,34 @@
#ifndef __RTGUI_TEXTBOX_H__
#define __RTGUI_TEXTBOX_H__
#include <rtgui/rtgui.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/widget.h>
#include <rtgui/widgets/container.h>
#ifdef __cplusplus
extern "C" {
#endif
DECLARE_CLASS_TYPE(textbox);
/** Gets the type of a textbox */
#define RTGUI_TEXTBOX_TYPE (RTGUI_TYPE(textbox))
/** Casts the object to a rtgui_textbox */
/** Casts the object to a rtgui_textbox_t */
#define RTGUI_TEXTBOX(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_TEXTBOX_TYPE, rtgui_textbox_t))
/** Checks if the object is a rtgui_textbox */
/** Checks if the object is a rtgui_textbox_t */
#define RTGUI_IS_TEXTBOX(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_TEXTBOX_TYPE))
#define RTGUI_TEXTBOX_DEFAULT_WIDTH 80
#define RTGUI_TEXTBOX_DEFAULT_HEIGHT 20
#define RTGUI_TEXTBOX_DEFAULT_HEIGHT 20
#define RTGUI_TEXTBOX_SINGLE 0x00
#define RTGUI_TEXTBOX_MULTI 0x01
#define RTGUI_TEXTBOX_MASK 0x02
#define RTGUI_TEXTBOX_CARET_SHOW 0x10
#define RTGUI_TEXTBOX_CARET_HIDE 0x00
struct rtgui_textbox_line
{
char* line_text;
#define RTGUI_TEXTBOX_SINGLE 0x00
#define RTGUI_TEXTBOX_MULTI 0x01 /* multiline */
#define RTGUI_TEXTBOX_MASK 0x02 /* ciphertext */
#define RTGUI_TEXTBOX_DIGIT 0x04 /* digit */
#define RTGUI_TEXTBOX_CARET_SHOW 0x10
#define RTGUI_TEXTBOX_CARET_STAT 0x20 /* unused */
struct rtgui_textbox_line *prev, *next;
};
#define RTGUI_TEXTBOX_LINE_MAX 128 /* text line cache */
struct rtgui_textbox
{
......@@ -47,22 +49,24 @@ struct rtgui_textbox
struct rtgui_widget parent;
/* text box flag */
rt_uint8_t flag;
rt_uint32_t flag;
/* current line and position */
rt_uint16_t line, line_begin, position, line_length;
rt_uint16_t dis_length; /*may be display length.*/
char* text;
rt_size_t font_width;
struct rtgui_timer* caret_timer;
rtgui_timer_t *caret_timer;
rtgui_color_t *caret;
rtgui_rect_t caret_rect;
/* widget private data */
rt_bool_t (*on_enter) (struct rtgui_widget* widget, struct rtgui_event* event);
/* textbox private data */
rt_bool_t (*on_enter) (struct rtgui_textbox *box, rtgui_event_t* event);
};
typedef struct rtgui_textbox rtgui_textbox_t;
struct rtgui_textbox* rtgui_textbox_create(const char* text, rt_uint8_t flag);
struct rtgui_textbox* rtgui_textbox_create(const char* text, rt_uint32_t flag);
void rtgui_textbox_destroy(struct rtgui_textbox* box);
rt_bool_t rtgui_textbox_event_handler(struct rtgui_object* object, struct rtgui_event* event);
......@@ -72,4 +76,11 @@ const char* rtgui_textbox_get_value(struct rtgui_textbox* box);
void rtgui_textbox_set_line_length(struct rtgui_textbox* box, rt_size_t length);
void rtgui_textbox_get_edit_rect(struct rtgui_textbox *box,rtgui_rect_t *rect);
void rtgui_textbox_ondraw(rtgui_textbox_t* box);
#ifdef __cplusplus
}
#endif
#endif
......@@ -26,16 +26,16 @@ extern "C" {
#endif
#define RTGUI_WIDGET_FLAG_DEFAULT 0x0000
#define RTGUI_WIDGET_FLAG_HIDE 0x0001
#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_UNHIDE(w) (w)->flag &= ~RTGUI_WIDGET_FLAG_HIDE
#define RTGUI_WIDGET_HIDE(w) (w)->flag |= RTGUI_WIDGET_FLAG_HIDE
#define RTGUI_WIDGET_IS_HIDE(w) ((w)->flag & RTGUI_WIDGET_FLAG_HIDE)
#define RTGUI_WIDGET_UNHIDE(w) (w)->flag |= RTGUI_WIDGET_FLAG_SHOWN
#define RTGUI_WIDGET_HIDE(w) (w)->flag &= ~RTGUI_WIDGET_FLAG_SHOWN
#define RTGUI_WIDGET_IS_HIDE(w) (!((w)->flag & RTGUI_WIDGET_FLAG_SHOWN))
#define RTGUI_WIDGET_ENABLE(w) (w)->flag &= ~RTGUI_WIDGET_FLAG_DISABLE
#define RTGUI_WIDGET_DISABLE(w) (w)->flag |= RTGUI_WIDGET_FLAG_DISABLE
......@@ -52,12 +52,13 @@ extern "C" {
#define RTGUI_WIDGET_DC_SET_UNVISIBLE(w) (w)->flag &= ~RTGUI_WIDGET_FLAG_DC_VISIBLE
#define RTGUI_WIDGET_DC(w) ((struct rtgui_dc*)&((w)->dc_type))
/* get rtgui widget object */
#define RTGUI_WIDGET_FOREGROUND(w) ((w)->gc.foreground)
#define RTGUI_WIDGET_BACKGROUND(w) ((w)->gc.background)
#define RTGUI_WIDGET_TEXTALIGN(w) ((w)->gc.textalign)
#define RTGUI_WIDGET_FONT(w) ((w)->gc.font)
#define RTGUI_WIDGET_FLAG(w) ((w)->flag)
/* 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)
DECLARE_CLASS_TYPE(widget);
......@@ -96,14 +97,10 @@ struct rtgui_widget
/* the widget extent */
rtgui_rect_t extent;
#ifndef RTGUI_USING_SMALL_SIZE
/* minimal width and height of widget */
rt_int16_t mini_width, mini_height;
rt_int16_t margin, margin_style;
/* widget align */
rt_int32_t align;
#endif
/* the rect clip */
rtgui_region_t clip;
......@@ -189,7 +186,9 @@ void rtgui_widget_update_clip(rtgui_widget_t* widget);
struct rtgui_win* rtgui_widget_get_toplevel(rtgui_widget_t* widget);
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);
/* get parent color */
......
......@@ -37,16 +37,8 @@ DECLARE_CLASS_TYPE(win);
#define RTGUI_WIN_STYLE_MINIBOX 0x010 /* window has the mini button */
#define RTGUI_WIN_STYLE_DESTROY_ON_CLOSE 0x020 /* window is destroyed when closed */
#ifdef RTGUI_USING_DESKTOP_WINDOW
/* A desktop window is a full screen window which will beneath all other windows.
* There will be only one desktop window in a system. And this window should be
* created _before_ any other windows.
*/
#define RTGUI_WIN_STYLE_DESKTOP 0x8000
#define RTGUI_WIN_STYLE_DESKTOP_DEFAULT RTGUI_WIN_STYLE_DESKTOP |\
RTGUI_WIN_STYLE_NO_BORDER |\
RTGUI_WIN_STYLE_NO_TITLE
#endif
#define RTGUI_WIN_STYLE_ONTOP 0x040 /* window is in the top layer */
#define RTGUI_WIN_STYLE_ONBTM 0x080 /* window is in the bottom layer */
#define RTGUI_WIN_STYLE_DEFAULT (RTGUI_WIN_STYLE_CLOSEBOX | RTGUI_WIN_STYLE_MINIBOX)
......@@ -84,7 +76,7 @@ struct rtgui_win
/* the widget that will grab the focus in current window */
struct rtgui_widget *focused_widget;
/* top window style */
/* window style */
rt_uint16_t style;
/* window state flag */
......@@ -133,7 +125,7 @@ rt_bool_t rtgui_win_close(struct rtgui_win* win);
rt_base_t rtgui_win_show(struct rtgui_win *win, rt_bool_t is_modal);
void rtgui_win_hiden(rtgui_win_t* win);
void rtgui_win_end_modal(rtgui_win_t* win, rtgui_modal_code_t modal_code);
rt_err_t rtgui_win_activate(struct rtgui_win *win);
rt_bool_t rtgui_win_is_activated(struct rtgui_win* win);
void rtgui_win_move(struct rtgui_win* win, int x, int y);
......
......@@ -88,3 +88,7 @@ rt_uint8_t* rtgui_graphic_driver_get_framebuffer(const struct rtgui_graphic_driv
return (rt_uint8_t*)driver->framebuffer;
}
rt_uint8_t* rtgui_graphic_driver_get_default_framebuffer(void)
{
return rtgui_graphic_driver_get_framebuffer(&_driver);
}
......@@ -52,9 +52,6 @@ struct rtgui_cursor
rt_uint8_t *win_top, *win_bottom;
rt_bool_t win_rect_show, win_rect_has_saved;
#endif
/* screen framebuffer */
rt_uint8_t* framebuffer;
};
struct rtgui_cursor* _rtgui_cursor;
......@@ -140,7 +137,6 @@ void rtgui_mouse_init()
/* init cursor */
_rtgui_cursor->bpp = gd->bits_per_pixel/8;
_rtgui_cursor->framebuffer = rtgui_graphic_driver_get_framebuffer(gd);
_rtgui_cursor->screen_pitch = _rtgui_cursor->bpp * gd->width;
#ifdef RTGUI_USING_MOUSE_CURSOR
......@@ -300,7 +296,7 @@ static void rtgui_cursor_restore()
rt_base_t idx, height, cursor_pitch;
rt_uint8_t *cursor_ptr, *fb_ptr;
fb_ptr = _rtgui_cursor->framebuffer + _rtgui_cursor->cy * _rtgui_cursor->screen_pitch
fb_ptr = rtgui_graphic_driver_get_default_framebuffer() + _rtgui_cursor->cy * _rtgui_cursor->screen_pitch
+ _rtgui_cursor->cx * _rtgui_cursor->bpp;
cursor_ptr = _rtgui_cursor->cursor_saved;
......@@ -327,7 +323,7 @@ static void rtgui_cursor_save()
rt_base_t idx, height, cursor_pitch;
rt_uint8_t *cursor_ptr, *fb_ptr;
fb_ptr = _rtgui_cursor->framebuffer + _rtgui_cursor->cy * _rtgui_cursor->screen_pitch +
fb_ptr = _driver_get_default_framebuffer() + _rtgui_cursor->cy * _rtgui_cursor->screen_pitch +
_rtgui_cursor->cx * _rtgui_cursor->bpp;
cursor_ptr = _rtgui_cursor->cursor_saved;
......@@ -488,10 +484,11 @@ static void rtgui_winrect_show()
static void rtgui_winrect_restore()
{
rt_uint8_t *winrect_ptr, *fb_ptr;
rt_uint8_t *winrect_ptr, *fb_ptr, *driver_fb;
int winrect_pitch, idx;
rtgui_rect_t screen_rect, win_rect;
driver_fb = rtgui_graphic_driver_get_default_framebuffer();
win_rect = _rtgui_cursor->win_rect;
rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(),
......@@ -499,7 +496,7 @@ static void rtgui_winrect_restore()
rtgui_rect_intersect(&screen_rect, &win_rect);
/* restore winrect left */
fb_ptr = _rtgui_cursor->framebuffer + win_rect.y1 * _rtgui_cursor->screen_pitch +
fb_ptr = driver_fb + win_rect.y1 * _rtgui_cursor->screen_pitch +
win_rect.x1 * _rtgui_cursor->bpp;
winrect_ptr = _rtgui_cursor->win_left;
winrect_pitch = WIN_MOVE_BORDER * _rtgui_cursor->bpp;
......@@ -507,7 +504,7 @@ static void rtgui_winrect_restore()
(win_rect.y2 - win_rect.y1), winrect_pitch);
/* restore winrect right */
fb_ptr = _rtgui_cursor->framebuffer + win_rect.y1 * _rtgui_cursor->screen_pitch +
fb_ptr = driver_fb + win_rect.y1 * _rtgui_cursor->screen_pitch +
(win_rect.x2 - WIN_MOVE_BORDER) * _rtgui_cursor->bpp;
winrect_ptr = _rtgui_cursor->win_right;
winrect_pitch = WIN_MOVE_BORDER * _rtgui_cursor->bpp;
......@@ -515,7 +512,7 @@ static void rtgui_winrect_restore()
(win_rect.y2 - win_rect.y1), winrect_pitch);
/* restore winrect top */
fb_ptr = _rtgui_cursor->framebuffer + win_rect.y1 * _rtgui_cursor->screen_pitch +
fb_ptr = driver_fb + win_rect.y1 * _rtgui_cursor->screen_pitch +
(win_rect.x1 + WIN_MOVE_BORDER)* _rtgui_cursor->bpp;
winrect_ptr = _rtgui_cursor->win_top;
winrect_pitch = (win_rect.x2 - win_rect.x1 - 2 * WIN_MOVE_BORDER) * _rtgui_cursor->bpp;
......@@ -523,7 +520,7 @@ static void rtgui_winrect_restore()
WIN_MOVE_BORDER, winrect_pitch);
/* restore winrect bottom */
fb_ptr = _rtgui_cursor->framebuffer + (win_rect.y2 - WIN_MOVE_BORDER) * _rtgui_cursor->screen_pitch +
fb_ptr = driver_fb + (win_rect.y2 - WIN_MOVE_BORDER) * _rtgui_cursor->screen_pitch +
(win_rect.x1 + WIN_MOVE_BORDER) * _rtgui_cursor->bpp;
winrect_ptr = _rtgui_cursor->win_bottom;
display_direct_memcpy(winrect_ptr, fb_ptr, winrect_pitch, _rtgui_cursor->screen_pitch,
......@@ -532,10 +529,11 @@ static void rtgui_winrect_restore()
static void rtgui_winrect_save()
{
rt_uint8_t *winrect_ptr, *fb_ptr;
rt_uint8_t *winrect_ptr, *fb_ptr, *driver_fb;
int winrect_pitch, idx;
rtgui_rect_t screen_rect, win_rect;
driver_fb = rtgui_graphic_driver_get_default_framebuffer();
win_rect = _rtgui_cursor->win_rect;
rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(),
......@@ -546,7 +544,7 @@ static void rtgui_winrect_save()
_rtgui_cursor->win_rect_has_saved = RT_TRUE;
/* save winrect left */
fb_ptr = _rtgui_cursor->framebuffer + win_rect.y1 * _rtgui_cursor->screen_pitch +
fb_ptr = driver_fb + win_rect.y1 * _rtgui_cursor->screen_pitch +
win_rect.x1 * _rtgui_cursor->bpp;
winrect_ptr = _rtgui_cursor->win_left;
winrect_pitch = WIN_MOVE_BORDER * _rtgui_cursor->bpp;
......@@ -554,7 +552,7 @@ static void rtgui_winrect_save()
(win_rect.y2 - win_rect.y1), winrect_pitch);
/* save winrect right */
fb_ptr = _rtgui_cursor->framebuffer + win_rect.y1 * _rtgui_cursor->screen_pitch +
fb_ptr = driver_fb + win_rect.y1 * _rtgui_cursor->screen_pitch +
(win_rect.x2 - WIN_MOVE_BORDER) * _rtgui_cursor->bpp;
winrect_ptr = _rtgui_cursor->win_right;
winrect_pitch = WIN_MOVE_BORDER * _rtgui_cursor->bpp;
......@@ -562,7 +560,7 @@ static void rtgui_winrect_save()
(win_rect.y2 - win_rect.y1), winrect_pitch);
/* save winrect top */
fb_ptr = _rtgui_cursor->framebuffer + win_rect.y1 * _rtgui_cursor->screen_pitch +
fb_ptr = driver_fb + win_rect.y1 * _rtgui_cursor->screen_pitch +
(win_rect.x1 + WIN_MOVE_BORDER)* _rtgui_cursor->bpp;
winrect_ptr = _rtgui_cursor->win_top;
winrect_pitch = (win_rect.x2 - win_rect.x1 - 2 * WIN_MOVE_BORDER) * _rtgui_cursor->bpp;
......@@ -570,7 +568,7 @@ static void rtgui_winrect_save()
WIN_MOVE_BORDER, winrect_pitch);
/* save winrect bottom */
fb_ptr = _rtgui_cursor->framebuffer + (win_rect.y2 - WIN_MOVE_BORDER) * _rtgui_cursor->screen_pitch +
fb_ptr = driver_fb + (win_rect.y2 - WIN_MOVE_BORDER) * _rtgui_cursor->screen_pitch +
(win_rect.x1 + WIN_MOVE_BORDER) * _rtgui_cursor->bpp;
winrect_ptr = _rtgui_cursor->win_bottom;
display_direct_memcpy(fb_ptr, winrect_ptr, _rtgui_cursor->screen_pitch, winrect_pitch,
......
/*
* File : rtgui_application.c
* This file is part of RTGUI in RT-Thread RTOS
* COPYRIGHT (C) 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(just a prototype of application API)
*/
#include <rtgui/rtgui_system.h>
#include <rtgui/rtgui_application.h>
#include <rtgui/widgets/window.h>
#ifdef _WIN32
#define RTGUI_EVENT_DEBUG
#endif
#ifdef RTGUI_EVENT_DEBUG
const char *event_string[] =
{
/* window event */
"WIN_CREATE", /* create a window */
"WIN_DESTROY", /* destroy a window */
"WIN_SHOW", /* show a window */
"WIN_HIDE", /* hide a window */
"WIN_ACTIVATE", /* activate a window */
"WIN_DEACTIVATE", /* deactivate a window */
"WIN_CLOSE", /* close a window */
"WIN_MOVE", /* move a window */
"WIN_RESIZE", /* resize a window */
"WIN_MODAL_ENTER", /* a window modals */
"SET_WM", /* set window manager */
"UPDATE_BEGIN", /* begin of update rect */
"UPDATE_END", /* end of update rect */
"MONITOR_ADD", /* add a monitor rect */
"MONITOR_REMOVE", /* remove a monitor rect*/
"PAINT", /* paint on screen */
"TIMER", /* timer */
/* clip rect information */
"CLIP_INFO", /* clip rect info */
/* mouse and keyboard event */
"MOUSE_MOTION", /* mouse motion */
"MOUSE_BUTTON", /* mouse button info */
"KBD", /* keyboard info */
/* user command event */
"COMMAND", /* user command */
/* request's status event */
"STATUS", /* request result */
"SCROLLED", /* scroll bar scrolled */
"RESIZE", /* widget resize */
};
#define DBG_MSG(x) rt_kprintf x
static void rtgui_event_dump(rt_thread_t tid, rtgui_event_t* event)
{
char* sender = "(unknown)";
if ((event->type == RTGUI_EVENT_TIMER) ||
(event->type == RTGUI_EVENT_UPDATE_BEGIN) ||
(event->type == RTGUI_EVENT_MOUSE_MOTION) ||
(event->type == RTGUI_EVENT_UPDATE_END))
{
/* don't dump timer event */
return ;
}
if (event->sender != RT_NULL)
sender = event->sender->name;
rt_kprintf("%s -- %s --> %s ", sender, event_string[event->type], tid->name);
switch (event->type)
{
case RTGUI_EVENT_PAINT:
{
struct rtgui_event_paint *paint = (struct rtgui_event_paint *)event;
if(paint->wid != RT_NULL)
rt_kprintf("win: %s", paint->wid->title);
}
break;
case RTGUI_EVENT_KBD:
{
struct rtgui_event_kbd *ekbd = (struct rtgui_event_kbd*) event;
if (ekbd->wid != RT_NULL)
rt_kprintf("win: %s", ekbd->wid->title);
if (RTGUI_KBD_IS_UP(ekbd)) rt_kprintf(", up");
else rt_kprintf(", down");
}
break;
case RTGUI_EVENT_CLIP_INFO:
{
struct rtgui_event_clip_info *info = (struct rtgui_event_clip_info *)event;
if(info->wid != RT_NULL)
rt_kprintf("win: %s", info->wid->title);
}
break;
case RTGUI_EVENT_WIN_CREATE:
{
struct rtgui_event_win_create *create = (struct rtgui_event_win_create*)event;
rt_kprintf(" win: %s at (x1:%d, y1:%d, x2:%d, y2:%d), addr: %p",
#ifdef RTGUI_USING_SMALL_SIZE
create->wid->title,
RTGUI_WIDGET(create->wid)->extent.x1,
RTGUI_WIDGET(create->wid)->extent.y1,
RTGUI_WIDGET(create->wid)->extent.x2,
RTGUI_WIDGET(create->wid)->extent.y2,
#else
create->title,
create->extent.x1,
create->extent.y1,
create->extent.x2,
create->extent.y2,
#endif
create->wid
);
}
break;
case RTGUI_EVENT_UPDATE_END:
{
struct rtgui_event_update_end* update_end = (struct rtgui_event_update_end*)event;
rt_kprintf("(x:%d, y1:%d, x2:%d, y2:%d)", update_end->rect.x1,
update_end->rect.y1,
update_end->rect.x2,
update_end->rect.y2);
}
break;
case RTGUI_EVENT_WIN_ACTIVATE:
case RTGUI_EVENT_WIN_DEACTIVATE:
case RTGUI_EVENT_WIN_SHOW:
case RTGUI_EVENT_WIN_MODAL_ENTER:
case RTGUI_EVENT_WIN_HIDE:
{
struct rtgui_event_win *win = (struct rtgui_event_win *)event;
if(win->wid != RT_NULL)
rt_kprintf("win: %s", win->wid->title);
}
break;
case RTGUI_EVENT_WIN_MOVE:
{
struct rtgui_event_win_move *win = (struct rtgui_event_win_move *)event;
if(win->wid != RT_NULL)
{
rt_kprintf("win: %s", win->wid->title);
rt_kprintf(" to (x:%d, y:%d)", win->x, win->y);
}
}
break;
case RTGUI_EVENT_WIN_RESIZE:
{
struct rtgui_event_win_resize* win = (struct rtgui_event_win_resize *)event;
if (win->wid != RT_NULL)
{
rt_kprintf("win: %s, rect(x1:%d, y1:%d, x2:%d, y2:%d)", win->wid->title,
RTGUI_WIDGET(win->wid)->extent.x1,
RTGUI_WIDGET(win->wid)->extent.y1,
RTGUI_WIDGET(win->wid)->extent.x2,
RTGUI_WIDGET(win->wid)->extent.y2);
}
}
break;
case RTGUI_EVENT_MOUSE_BUTTON:
case RTGUI_EVENT_MOUSE_MOTION:
{
struct rtgui_event_mouse *mouse = (struct rtgui_event_mouse*)event;
if (mouse->button & RTGUI_MOUSE_BUTTON_LEFT) rt_kprintf("left ");
else rt_kprintf("right ");
if (mouse->button & RTGUI_MOUSE_BUTTON_DOWN) rt_kprintf("down ");
else rt_kprintf("up ");
if (mouse->wid != RT_NULL)
rt_kprintf("win: %s at (%d, %d)", mouse->wid->title,
mouse->x, mouse->y);
else
rt_kprintf("(%d, %d)", mouse->x, mouse->y);
}
break;
case RTGUI_EVENT_MONITOR_ADD:
{
struct rtgui_event_monitor *monitor = (struct rtgui_event_monitor*)event;
if (monitor->wid != RT_NULL)
{
rt_kprintf("win: %s, the rect is:(%d, %d) - (%d, %d)", monitor->wid->title,
monitor->rect.x1, monitor->rect.y1,
monitor->rect.x2, monitor->rect.y2);
}
}
break;
default:
break;
}
rt_kprintf("\n");
}
#else
#define DBG_MSG(x)
#define rtgui_event_dump(tid, event)
#endif
rt_bool_t rtgui_application_event_handler(struct rtgui_object* obj, rtgui_event_t* event);
static void _rtgui_application_constructor(struct rtgui_application *app)
{
/* set event handler */
rtgui_object_set_event_handler(RTGUI_OBJECT(app),
rtgui_application_event_handler);
app->name = RT_NULL;
/* set EXITED so we can destroy an application that just created */
app->state_flag = RTGUI_APPLICATION_FLAG_EXITED;
app->ref_count = 0;
app->exit_code = 0;
app->tid = RT_NULL;
app->server = RT_NULL;
app->mq = RT_NULL;
app->modal_object = RT_NULL;
app->on_idle = RT_NULL;
}
static void _rtgui_application_destructor(struct rtgui_application *app)
{
RT_ASSERT(app != RT_NULL);
rt_free(app->name);
app->name = RT_NULL;
}
DEFINE_CLASS_TYPE(application, "application",
RTGUI_OBJECT_TYPE,
_rtgui_application_constructor,
_rtgui_application_destructor,
sizeof(struct rtgui_application));
struct rtgui_application* rtgui_application_create(
rt_thread_t tid,
const char *myname)
{
struct rtgui_application *app;
RT_ASSERT(tid != RT_NULL);
RT_ASSERT(myname != RT_NULL);
/* create application */
app = RTGUI_APPLICATION(rtgui_object_create(RTGUI_APPLICATION_TYPE));
if (app == RT_NULL)
return RT_NULL;
DBG_MSG(("register a rtgui application(%s) on thread %s\n", myname, tid->name));
app->tid = tid;
/* set user thread */
tid->user_data = (rt_uint32_t)app;
app->mq = rt_mq_create("rtgui", sizeof(union rtgui_event_generic), 32, RT_IPC_FLAG_FIFO);
if (app->mq == RT_NULL)
{
rt_kprintf("mq err\n");
goto __mq_err;
}
/* set application title */
app->name = (unsigned char*)rt_strdup((char*)myname);
if (app->name != RT_NULL)
return app;
__mq_err:
rtgui_object_destroy(RTGUI_OBJECT(app));
tid->user_data = 0;
return RT_NULL;
}
#define _rtgui_application_check(app) \
do { \
RT_ASSERT(app != RT_NULL); \
RT_ASSERT(app->tid != RT_NULL); \
RT_ASSERT(app->tid->user_data != 0); \
RT_ASSERT(app->mq != RT_NULL); \
} while (0)
void rtgui_application_destroy(struct rtgui_application *app)
{
_rtgui_application_check(app);
if (!(app->state_flag & RTGUI_APPLICATION_FLAG_EXITED))
{
rt_kprintf("cannot destroy a running application: %s.\n",
app->name);
return;
}
app->tid->user_data = 0;
rt_mq_delete(app->mq);
rtgui_object_destroy(RTGUI_OBJECT(app));
}
struct rtgui_application* rtgui_application_self(void)
{
struct rtgui_application *app;
rt_thread_t self;
/* get current thread */
self = rt_thread_self();
app = (struct rtgui_application*)(self->user_data);
return app;
}
void rtgui_application_set_onidle(rtgui_idle_func onidle)
{
struct rtgui_application *app;
app = rtgui_application_self();
if (app != RT_NULL)
app->on_idle = onidle;
}
rtgui_idle_func rtgui_application_get_onidle(void)
{
struct rtgui_application *app;
app = rtgui_application_self();
if (app != RT_NULL)
return app->on_idle;
else
return RT_NULL;
}
extern rt_thread_t rt_thread_find(char* name);
rt_thread_t rtgui_application_get_server(void)
{
return rt_thread_find("rtgui");
}
rt_err_t rtgui_application_send(rt_thread_t tid, rtgui_event_t* event, rt_size_t event_size)
{
rt_err_t result;
struct rtgui_application *app;
RT_ASSERT(tid != RT_NULL);
RT_ASSERT(event != RT_NULL);
RT_ASSERT(event_size != 0);
rtgui_event_dump(tid, event);
/* find struct rtgui_application */
app = (struct rtgui_application*) (tid->user_data);
if (app == RT_NULL)
return -RT_ERROR;
result = rt_mq_send(app->mq, event, event_size);
if (result != RT_EOK)
{
if (event->type != RTGUI_EVENT_TIMER)
rt_kprintf("send event to %s failed\n", app->tid->name);
}
return result;
}
rt_err_t rtgui_application_send_urgent(rt_thread_t tid, rtgui_event_t* event, rt_size_t event_size)
{
rt_err_t result;
struct rtgui_application *app;
RT_ASSERT(tid != RT_NULL);
RT_ASSERT(event != RT_NULL);
RT_ASSERT(event_size != 0);
rtgui_event_dump(tid, event);
/* find rtgui_application */
app = (struct rtgui_application*) (tid->user_data);
if (app == RT_NULL)
return -RT_ERROR;
result = rt_mq_urgent(app->mq, event, event_size);
if (result != RT_EOK)
rt_kprintf("send ergent event failed\n");
return result;
}
rt_err_t rtgui_application_send_sync(rt_thread_t tid, rtgui_event_t* event, rt_size_t event_size)
{
rt_err_t r;
struct rtgui_application *app;
rt_int32_t ack_buffer, ack_status;
struct rt_mailbox ack_mb;
RT_ASSERT(tid != RT_NULL);
RT_ASSERT(event != RT_NULL);
RT_ASSERT(event_size != 0);
rtgui_event_dump(tid, event);
/* init ack mailbox */
r = rt_mb_init(&ack_mb, "ack", &ack_buffer, 1, 0);
if (r!= RT_EOK)
goto __return;
app = (struct rtgui_application*) (tid->user_data);
if (app == RT_NULL)
{
r = -RT_ERROR;
goto __return;
}
event->ack = &ack_mb;
r = rt_mq_send(app->mq, event, event_size);
if (r != RT_EOK)
{
rt_kprintf("send sync event failed\n");
goto __return;
}
r = rt_mb_recv(&ack_mb, (rt_uint32_t*)&ack_status, RT_WAITING_FOREVER);
if (r!= RT_EOK)
goto __return;
if (ack_status != RTGUI_STATUS_OK)
r = -RT_ERROR;
else
r = RT_EOK;
__return:
/* fini ack mailbox */
rt_mb_detach(&ack_mb);
return r;
}
rt_err_t rtgui_application_ack(rtgui_event_t* event, rt_int32_t status)
{
RT_ASSERT(event != RT_NULL);
RT_ASSERT(event->ack != RT_NULL);
rt_mb_send(event->ack, status);
return RT_EOK;
}
rt_err_t rtgui_application_recv(rtgui_event_t* event, rt_size_t event_size)
{
struct rtgui_application* app;
rt_err_t r;
RT_ASSERT(event != RT_NULL);
RT_ASSERT(event_size != 0);
app = (struct rtgui_application*) (rt_thread_self()->user_data);
if (app == RT_NULL)
return -RT_ERROR;
r = rt_mq_recv(app->mq, event, event_size, RT_WAITING_FOREVER);
return r;
}
rt_err_t rtgui_application_recv_nosuspend(rtgui_event_t* event, rt_size_t event_size)
{
struct rtgui_application *app;
rt_err_t r;
RT_ASSERT(event != RT_NULL);
RT_ASSERT(event != 0);
app = (struct rtgui_application*) (rt_thread_self()->user_data);
if (app == RT_NULL)
return -RT_ERROR;
r = rt_mq_recv(app->mq, event, event_size, 0);
return r;
}
rt_err_t rtgui_application_recv_filter(rt_uint32_t type, rtgui_event_t* event, rt_size_t event_size)
{
struct rtgui_application *app;
RT_ASSERT(event != RT_NULL);
RT_ASSERT(event_size != 0);
app = (struct rtgui_application*) (rt_thread_self()->user_data);
if (app == RT_NULL)
return -RT_ERROR;
while (rt_mq_recv(app->mq, event, event_size, RT_WAITING_FOREVER) == RT_EOK)
{
if (event->type == type)
{
return RT_EOK;
}
else
{
if (RTGUI_OBJECT(app)->event_handler != RT_NULL)
{
RTGUI_OBJECT(app)->event_handler(RTGUI_OBJECT(app), event);
}
}
}
return -RT_ERROR;
}
rt_inline rt_bool_t _rtgui_application_dest_handle(
struct rtgui_application *app,
struct rtgui_event *event)
{
struct rtgui_event_win* wevent = (struct rtgui_event_win*)event;
struct rtgui_object* dest_object = RTGUI_OBJECT(wevent->wid);
if (dest_object != RT_NULL)
{
if (dest_object->event_handler != RT_NULL)
return dest_object->event_handler(RTGUI_OBJECT(dest_object), event);
else
return RT_FALSE;
}
else
{
rt_kprintf("RTGUI ERROR:server sent a event(%d) without wid\n", event->type);
return RT_FALSE;
}
}
rt_bool_t rtgui_application_event_handler(struct rtgui_object* object, rtgui_event_t* event)
{
struct rtgui_application* app;
RT_ASSERT(object != RT_NULL);
RT_ASSERT(event != RT_NULL);
app = RTGUI_APPLICATION(object);
switch (event->type)
{
case RTGUI_EVENT_PAINT:
case RTGUI_EVENT_CLIP_INFO:
case RTGUI_EVENT_WIN_ACTIVATE:
case RTGUI_EVENT_WIN_DEACTIVATE:
case RTGUI_EVENT_WIN_CLOSE:
case RTGUI_EVENT_WIN_MOVE:
case RTGUI_EVENT_KBD:
_rtgui_application_dest_handle(app, event);
break;
case RTGUI_EVENT_MOUSE_BUTTON:
case RTGUI_EVENT_MOUSE_MOTION:
{
struct rtgui_event_win* wevent = (struct rtgui_event_win*)event;
struct rtgui_object* dest_object = RTGUI_OBJECT(wevent->wid);
// FIXME: let application determine the dest_wiget but not in sever
// so we can combine this handler with above one
if (app->modal_object != RT_NULL &&
dest_object != app->modal_object)
{
// rt_kprintf("discard event %s that is not sent to modal object\n",
// event_string[event->type]);
}
else
{
_rtgui_application_dest_handle(app, event);
}
}
break;
case RTGUI_EVENT_TIMER:
{
struct rtgui_timer* timer;
struct rtgui_event_timer* etimer = (struct rtgui_event_timer*) event;
timer = etimer->timer;
if (timer->timeout != RT_NULL)
{
/* call timeout function */
timer->timeout(timer, timer->user_data);
}
}
break;
case RTGUI_EVENT_COMMAND:
{
struct rtgui_event_command *ecmd = (struct rtgui_event_command *)event;
if (ecmd->wid != RT_NULL)
return _rtgui_application_dest_handle(app, event);
}
default:
return rtgui_object_event_handler(object, event);
}
return RT_TRUE;
}
rt_inline void _rtgui_application_event_loop(struct rtgui_application *app)
{
rt_err_t result;
rt_uint16_t current_ref;
struct rtgui_event *event;
_rtgui_application_check(app);
/* point to event buffer */
event = (struct rtgui_event*)app->event_buffer;
current_ref = ++app->ref_count;
while (current_ref <= app->ref_count)
{
RT_ASSERT(current_ref == app->ref_count);
if (app->on_idle != RT_NULL)
{
result = rtgui_application_recv_nosuspend(event, sizeof(union rtgui_event_generic));
if (result == RT_EOK)
RTGUI_OBJECT(app)->event_handler(RTGUI_OBJECT(app), event);
else if (result == -RT_ETIMEOUT)
app->on_idle(RTGUI_OBJECT(app), RT_NULL);
}
else
{
result = rtgui_application_recv(event, sizeof(union rtgui_event_generic));
if (result == RT_EOK)
RTGUI_OBJECT(app)->event_handler(RTGUI_OBJECT(app), event);
}
}
}
rt_base_t rtgui_application_run(struct rtgui_application *app)
{
_rtgui_application_check(app);
app->state_flag &= ~RTGUI_APPLICATION_FLAG_EXITED;
_rtgui_application_event_loop(app);
if (app->ref_count == 0)
app->state_flag |= RTGUI_APPLICATION_FLAG_EXITED;
return app->exit_code;
}
void rtgui_application_exit(struct rtgui_application* app, rt_uint16_t code)
{
--app->ref_count;
app->exit_code = code;
}
......@@ -16,14 +16,16 @@
#include <rtgui/event.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/rtgui_object.h>
#include <rtgui/rtgui_application.h>
#include <rtgui/rtgui_app.h>
#include <rtgui/driver.h>
#include "mouse.h"
#include "topwin.h"
static struct rt_thread *rtgui_server_tid;
static struct rtgui_application *rtgui_server_application;
static struct rtgui_app *rtgui_server_application = RT_NULL;
static struct rtgui_app *rtgui_wm_application = RT_NULL;
void rtgui_server_handle_update(struct rtgui_event_update_end* event)
{
......@@ -85,7 +87,7 @@ void rtgui_server_handle_mouse_btn(struct rtgui_event_mouse* event)
}
/* send to client thread */
rtgui_application_send(topwin->tid, &(ewin.parent), sizeof(ewin));
rtgui_send(topwin->tid, &(ewin.parent), sizeof(ewin));
return;
}
......@@ -101,7 +103,7 @@ void rtgui_server_handle_mouse_btn(struct rtgui_event_mouse* event)
if (rtgui_topwin_get_focus() != wnd)
{
/* raise this window */
rtgui_topwin_activate_win(wnd);
rtgui_topwin_activate_topwin(wnd);
}
if (wnd->title != RT_NULL &&
......@@ -112,7 +114,7 @@ void rtgui_server_handle_mouse_btn(struct rtgui_event_mouse* event)
else
{
/* send mouse event to thread */
rtgui_application_send(wnd->tid, (struct rtgui_event*)event, sizeof(struct rtgui_event_mouse));
rtgui_send(wnd->tid, (struct rtgui_event*)event, sizeof(struct rtgui_event_mouse));
}
return ;
}
......@@ -144,7 +146,7 @@ void rtgui_server_handle_mouse_motion(struct rtgui_event_mouse* event)
{
event->wid = last_monitor_topwin->wid;
/* send mouse motion event */
rtgui_application_send(last_monitor_topwin->tid, &(event->parent), sizeof(struct rtgui_event_mouse));
rtgui_send(last_monitor_topwin->tid, &(event->parent), sizeof(struct rtgui_event_mouse));
}
if (last_monitor_topwin != win)
......@@ -155,7 +157,7 @@ void rtgui_server_handle_mouse_motion(struct rtgui_event_mouse* event)
event->wid = last_monitor_topwin->wid;
/* send mouse motion event */
rtgui_application_send(last_monitor_topwin->tid, &(event->parent), sizeof(struct rtgui_event_mouse));
rtgui_send(last_monitor_topwin->tid, &(event->parent), sizeof(struct rtgui_event_mouse));
}
}
......@@ -181,7 +183,7 @@ void rtgui_server_handle_kbd(struct rtgui_event_kbd* event)
event->wid = wnd->wid;
/* send keyboard event to thread */
rtgui_application_send(wnd->tid, (struct rtgui_event*)event, sizeof(struct rtgui_event_kbd));
rtgui_send(wnd->tid, (struct rtgui_event*)event, sizeof(struct rtgui_event_kbd));
return;
}
......@@ -200,58 +202,113 @@ static rt_bool_t rtgui_server_event_handler(struct rtgui_object *object,
/* dispatch event */
switch (event->type)
{
case RTGUI_EVENT_APP_CREATE:
case RTGUI_EVENT_APP_DESTROY:
if (rtgui_wm_application != RT_NULL)
{
/* forward event to wm application */
rtgui_send(rtgui_wm_application->tid, event, sizeof(struct rtgui_event_application));
}
else
{
/* always ack with OK */
rtgui_ack(event, RTGUI_STATUS_OK);
}
break;
/* mouse and keyboard event */
case RTGUI_EVENT_MOUSE_MOTION:
/* handle mouse motion event */
rtgui_server_handle_mouse_motion((struct rtgui_event_mouse*)event);
break;
case RTGUI_EVENT_MOUSE_BUTTON:
/* handle mouse button */
rtgui_server_handle_mouse_btn((struct rtgui_event_mouse*)event);
break;
case RTGUI_EVENT_KBD:
/* handle keyboard event */
rtgui_server_handle_kbd((struct rtgui_event_kbd*)event);
break;
/* window event */
case RTGUI_EVENT_WIN_CREATE:
if (rtgui_topwin_add((struct rtgui_event_win_create*)event) == RT_EOK)
rtgui_application_ack(event, RTGUI_STATUS_OK);
rtgui_ack(event, RTGUI_STATUS_OK);
else
rtgui_application_ack(event, RTGUI_STATUS_ERROR);
break;
case RTGUI_EVENT_WIN_DESTROY:
if (last_monitor_topwin != RT_NULL &&
last_monitor_topwin->wid == ((struct rtgui_event_win*)event)->wid)
last_monitor_topwin = RT_NULL;
if (rtgui_topwin_remove(((struct rtgui_event_win*)event)->wid) == RT_EOK)
rtgui_application_ack(event, RTGUI_STATUS_OK);
else
rtgui_application_ack(event, RTGUI_STATUS_ERROR);
rtgui_ack(event, RTGUI_STATUS_ERROR);
break;
case RTGUI_EVENT_WIN_SHOW:
if (rtgui_topwin_show((struct rtgui_event_win*)event) == RT_EOK)
rtgui_application_ack(event, RTGUI_STATUS_OK);
rtgui_ack(event, RTGUI_STATUS_OK);
else
rtgui_application_ack(event, RTGUI_STATUS_ERROR);
rtgui_ack(event, RTGUI_STATUS_ERROR);
break;
case RTGUI_EVENT_WIN_HIDE:
if (rtgui_topwin_hide((struct rtgui_event_win*)event) == RT_EOK)
rtgui_application_ack(event, RTGUI_STATUS_OK);
rtgui_ack(event, RTGUI_STATUS_OK);
else
rtgui_application_ack(event, RTGUI_STATUS_ERROR);
rtgui_ack(event, RTGUI_STATUS_ERROR);
break;
case RTGUI_EVENT_WIN_MOVE:
if (rtgui_topwin_move((struct rtgui_event_win_move*)event) == RT_EOK)
rtgui_application_ack(event, RTGUI_STATUS_OK);
rtgui_ack(event, RTGUI_STATUS_OK);
else
rtgui_application_ack(event, RTGUI_STATUS_ERROR);
rtgui_ack(event, RTGUI_STATUS_ERROR);
break;
case RTGUI_EVENT_WIN_MODAL_ENTER:
if (rtgui_topwin_modal_enter((struct rtgui_event_win_modal_enter*)event) == RT_EOK)
rtgui_application_ack(event, RTGUI_STATUS_OK);
rtgui_ack(event, RTGUI_STATUS_OK);
else
rtgui_application_ack(event, RTGUI_STATUS_ERROR);
rtgui_ack(event, RTGUI_STATUS_ERROR);
break;
case RTGUI_EVENT_WIN_ACTIVATE:
if (rtgui_topwin_activate((struct rtgui_event_win_activate*)event) == RT_EOK)
rtgui_ack(event, RTGUI_STATUS_OK);
else
rtgui_ack(event, RTGUI_STATUS_ERROR);
break;
case RTGUI_EVENT_WIN_DESTROY:
if (last_monitor_topwin != RT_NULL &&
last_monitor_topwin->wid == ((struct rtgui_event_win*)event)->wid)
last_monitor_topwin = RT_NULL;
if (rtgui_topwin_remove(((struct rtgui_event_win*)event)->wid) == RT_EOK)
rtgui_ack(event, RTGUI_STATUS_OK);
else
rtgui_ack(event, RTGUI_STATUS_ERROR);
break;
case RTGUI_EVENT_WIN_RESIZE:
rtgui_topwin_resize(((struct rtgui_event_win_resize*)event)->wid,
&(((struct rtgui_event_win_resize*)event)->rect));
break;
case RTGUI_EVENT_SET_WM:
if (rtgui_wm_application != RT_NULL)
{
rtgui_ack(event, RTGUI_STATUS_ERROR);
}
else
{
struct rtgui_event_set_wm *set_wm;
set_wm = (struct rtgui_event_set_wm*) event;
rtgui_wm_application = set_wm->app;
rtgui_ack(event, RTGUI_STATUS_OK);
}
break;
/* other event */
case RTGUI_EVENT_COMMAND:
break;
case RTGUI_EVENT_UPDATE_BEGIN:
#ifdef RTGUI_USING_MOUSE_CURSOR
/* hide cursor */
......@@ -272,25 +329,6 @@ static rt_bool_t rtgui_server_event_handler(struct rtgui_object *object,
/* handle mouse monitor */
rtgui_server_handle_monitor_add((struct rtgui_event_monitor*)event);
break;
/* mouse and keyboard event */
case RTGUI_EVENT_MOUSE_MOTION:
/* handle mouse motion event */
rtgui_server_handle_mouse_motion((struct rtgui_event_mouse*)event);
break;
case RTGUI_EVENT_MOUSE_BUTTON:
/* handle mouse button */
rtgui_server_handle_mouse_btn((struct rtgui_event_mouse*)event);
break;
case RTGUI_EVENT_KBD:
/* handle keyboard event */
rtgui_server_handle_kbd((struct rtgui_event_kbd*)event);
break;
case RTGUI_EVENT_COMMAND:
break;
}
return RT_TRUE;
......@@ -307,8 +345,8 @@ static void rtgui_server_entry(void* parameter)
SetThreadPriority(hCurrentThread, THREAD_PRIORITY_HIGHEST);
#endif
/* register rtgui server thread */
rtgui_server_application = rtgui_application_create(rtgui_server_tid,
/* create rtgui server application */
rtgui_server_application = rtgui_app_create(rtgui_server_tid,
"rtgui");
if (rtgui_server_application == RT_NULL)
return;
......@@ -321,16 +359,16 @@ static void rtgui_server_entry(void* parameter)
rtgui_mouse_show_cursor();
#endif
rtgui_application_run(rtgui_server_application);
rtgui_app_run(rtgui_server_application);
rtgui_application_destroy(rtgui_server_application);
rtgui_app_destroy(rtgui_server_application);
rtgui_server_application = RT_NULL;
}
void rtgui_server_post_event(struct rtgui_event* event, rt_size_t size)
{
if (rtgui_server_tid != RT_NULL)
rtgui_application_send(rtgui_server_tid, event, size);
rtgui_send(rtgui_server_tid, event, size);
else
rt_kprintf("post when server is not running\n");
}
......@@ -338,7 +376,7 @@ 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)
{
if (rtgui_server_tid != RT_NULL)
return rtgui_application_send_sync(rtgui_server_tid, event, size);
return rtgui_send_sync(rtgui_server_tid, event, size);
else
{
rt_kprintf("post when server is not running\n");
......
此差异已折叠。
......@@ -23,8 +23,8 @@
/* add or remove a top win */
rt_err_t rtgui_topwin_add(struct rtgui_event_win_create* event);
rt_err_t rtgui_topwin_remove(struct rtgui_win* wid);
void rtgui_topwin_activate_win(struct rtgui_topwin* win);
rt_err_t rtgui_topwin_activate(struct rtgui_event_win_activate* event);
rt_err_t rtgui_topwin_activate_topwin(struct rtgui_topwin* win);
/* show a window */
rt_err_t rtgui_topwin_show(struct rtgui_event_win* event);
......
/*
* File : about_view.c
* This file is part of RTGUI in RT-Thread RTOS
* COPYRIGHT (C) 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-01-06 Bernard first version
*/
#include <rtgui/rtgui_theme.h>
#include <rtgui/widgets/about_view.h>
static void _rtgui_about_view_constructor(struct rtgui_about_view *view)
{
/* default rect */
struct rtgui_rect rect = {0, 0, 200, 200};
/* set default widget rect and set event handler */
rtgui_object_set_event_handler(RTGUI_OBJECT(view),rtgui_about_view_event_handler);
rtgui_widget_set_rect(RTGUI_WIDGET(view), &rect);
RTGUI_WIDGET(view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
view->logo = RT_NULL;
view->description = RT_NULL;
RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(view)) = RTGUI_ALIGN_CENTER_VERTICAL;
}
DEFINE_CLASS_TYPE(aboutview, "aboutview",
RTGUI_CONTAINER_TYPE,
_rtgui_about_view_constructor,
RT_NULL,
sizeof(struct rtgui_about_view));
void rtgui_about_view_ondraw(struct rtgui_about_view* view)
{
struct rtgui_rect rect;
struct rtgui_dc* dc;
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view));
if (dc == RT_NULL) return;
rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
rtgui_dc_fill_rect(dc, &rect);
if (view->logo != RT_NULL)
rtgui_image_blit(view->logo, dc, &rect);
rect.y1 += view->logo->h + 5;
if (view->description != RT_NULL)
rtgui_dc_draw_text(dc, view->description, &rect);
rect.y1 += rtgui_dc_get_gc(dc)->font->height;
rtgui_dc_draw_hline(dc, rect.x1 + 3, rect.x2 - 3, rect.y1);
RTGUI_DC_FC(dc) = white;
rtgui_dc_draw_hline(dc, rect.x1 + 4, rect.x2 - 2, rect.y1 + 1);
rtgui_dc_end_drawing(dc);
}
rt_bool_t rtgui_about_view_event_handler(struct rtgui_object* widget, struct rtgui_event* event)
{
struct rtgui_about_view* view = RT_NULL;
view = RTGUI_ABOUT_VIEW(widget);
switch (event->type)
{
case RTGUI_EVENT_PAINT:
rtgui_about_view_ondraw(view);
return RT_FALSE;
}
/* use view event handler */
return rtgui_container_event_handler(widget, event);
}
rtgui_about_view_t* rtgui_about_view_create(rtgui_image_t *logo, const char* description)
{
struct rtgui_about_view* view = RT_NULL;
view = (struct rtgui_about_view*) rtgui_widget_create(RTGUI_ABOUT_VIEW_TYPE);
if (view != RT_NULL)
{
view->logo = logo;
view->description = description;
}
return view;
}
void rtgui_about_view_destroy(rtgui_about_view_t* view)
{
/* destroy view */
rtgui_widget_destroy(RTGUI_WIDGET(view));
}
此差异已折叠。
......@@ -62,7 +62,7 @@ rt_bool_t rtgui_button_event_handler(struct rtgui_object* object, struct rtgui_e
struct rtgui_widget *widget;
struct rtgui_button *btn;
RT_ASSERT(widget != RT_NULL);
RT_ASSERT(object != RT_NULL);
RT_ASSERT(event != RT_NULL);
widget = RTGUI_WIDGET(object);
......@@ -189,6 +189,8 @@ rt_bool_t rtgui_button_event_handler(struct rtgui_object* object, struct rtgui_e
return RT_TRUE;
}
default:
return rtgui_widget_event_handler(object, event);
}
return RT_FALSE;
......
......@@ -92,6 +92,8 @@ rt_bool_t rtgui_checkbox_event_handler(struct rtgui_object* object, struct rtgui
return RT_TRUE;
}
default:
return rtgui_widget_event_handler(object, event);
}
return RT_FALSE;
......
......@@ -38,7 +38,6 @@ rt_bool_t rtgui_combobox_pdwin_onitem(struct rtgui_object* object, struct rtgui_
rtgui_listbox_t* list;
RT_ASSERT(object != RT_NULL);
RT_ASSERT(event != RT_NULL);
widget = RTGUI_WIDGET(object);
list = RTGUI_LISTBOX(widget);
......@@ -228,6 +227,8 @@ rt_bool_t rtgui_combobox_event_handler(struct rtgui_object* object, struct rtgui
}
}
break;
default:
return rtgui_widget_event_handler(object, event);
}
return RT_FALSE;
......
......@@ -66,6 +66,8 @@ rt_bool_t rtgui_iconbox_event_handler(struct rtgui_object* object, struct rtgui_
}
break;
default:
return rtgui_widget_event_handler(object, event);
}
return RT_FALSE;
......
......@@ -49,6 +49,8 @@ rt_bool_t rtgui_label_event_handler(struct rtgui_object *object, struct rtgui_ev
case RTGUI_EVENT_PAINT:
rtgui_theme_draw_label(label);
break;
default:
return rtgui_widget_event_handler(object, event);
}
return RT_FALSE;
......
此差异已折叠。
......@@ -316,13 +316,13 @@ rt_bool_t rtgui_listctrl_event_handler(struct rtgui_object* object, struct rtgui
if (ctrl->current_item - ctrl->page_items >= 0)
ctrl->current_item -= ctrl->page_items;
rtgui_listctrl_update_current(ctrl, old_item);
return RT_FALSE;
return RT_TRUE;
case RTGUIK_UP:
if (ctrl->current_item > 0)
ctrl->current_item --;
rtgui_listctrl_update_current(ctrl, old_item);
return RT_FALSE;
return RT_TRUE;
case RTGUIK_RIGHT:
if (ctrl->current_item + ctrl->page_items < ctrl->items_count - 1)
......@@ -333,18 +333,18 @@ rt_bool_t rtgui_listctrl_event_handler(struct rtgui_object* object, struct rtgui
ctrl->current_item = ((ctrl->current_item / ctrl->page_items) + 1) * ctrl->page_items;
}
rtgui_listctrl_update_current(ctrl, old_item);
return RT_FALSE;
return RT_TRUE;
case RTGUIK_DOWN:
if (ctrl->current_item < ctrl->items_count - 1)
ctrl->current_item ++;
rtgui_listctrl_update_current(ctrl, old_item);
return RT_FALSE;
return RT_TRUE;
case RTGUIK_RETURN:
if (ctrl->on_item != RT_NULL)
{
ctrl->on_item(RTGUI_OBJECT(ctrl), RT_NULL);
return ctrl->on_item(RTGUI_OBJECT(ctrl), RT_NULL);
}
return RT_FALSE;
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -38,6 +38,8 @@ rt_bool_t rtgui_progressbar_event_handler(struct rtgui_object* object,
case RTGUI_EVENT_PAINT:
rtgui_theme_draw_progressbar(bar);
break;
default:
return rtgui_widget_event_handler(object, event);
}
return RT_FALSE;
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册