提交 f06c70fe 编写于 作者: G Grissiom

sync with rtgui-0.6

上级 4f02e67b
============================================================================
miniLZO -- mini subset of the LZO real-time data compression library
============================================================================
Author : Markus Franz Xaver Johannes Oberhumer
<markus@oberhumer.com>
http://www.oberhumer.com/opensource/lzo/
Version : 2.06
Date : 12 Aug 2011
I've created miniLZO for projects where it is inconvenient to
include (or require) the full LZO source code just because you
want to add a little bit of data compression to your application.
miniLZO implements the LZO1X-1 compressor and both the standard and
safe LZO1X decompressor. Apart from fast compression it also useful
for situations where you want to use pre-compressed data files (which
must have been compressed with LZO1X-999).
miniLZO consists of one C source file and three header files:
minilzo.c
minilzo.h, lzoconf.h, lzodefs.h
To use miniLZO just copy these files into your source directory, add
minilzo.c to your Makefile and #include minilzo.h from your program.
Note: you also must distribute this file ('README.LZO') with your project.
minilzo.o compiles to about 6 KiB (using gcc or Visual C on an i386), and
the sources are about 30 KiB when packed with zip - so there's no more
excuse that your application doesn't support data compression :-)
For more information, documentation, example programs and other support
files (like Makefiles and build scripts) please download the full LZO
package from
http://www.oberhumer.com/opensource/lzo/
Have fun,
Markus
P.S. minilzo.c is generated automatically from the LZO sources and
therefore functionality is completely identical
Appendix A: building miniLZO
----------------------------
miniLZO is written such a way that it should compile and run
out-of-the-box on most machines.
If you are running on a very unusual architecture and lzo_init() fails then
you should first recompile with '-DLZO_DEBUG' to see what causes the failure.
The most probable case is something like 'sizeof(void *) != sizeof(size_t)'.
After identifying the problem you can compile by adding some defines
like '-DSIZEOF_VOID_P=8' to your Makefile.
The best solution is (of course) using Autoconf - if your project uses
Autoconf anyway just add '-DMINILZO_HAVE_CONFIG_H' to your compiler
flags when compiling minilzo.c. See the LZO distribution for an example
how to set up configure.ac.
Appendix B: list of public functions available in miniLZO
---------------------------------------------------------
Library initialization
lzo_init()
Compression
lzo1x_1_compress()
Decompression
lzo1x_decompress()
lzo1x_decompress_safe()
Checksum functions
lzo_adler32()
Version functions
lzo_version()
lzo_version_string()
lzo_version_date()
Portable (but slow) string functions
lzo_memcmp()
lzo_memcpy()
lzo_memmove()
lzo_memset()
Appendix C: suggested macros for 'configure.ac' when using Autoconf
-------------------------------------------------------------------
Checks for typedefs and structures
AC_CHECK_TYPE(ptrdiff_t,long)
AC_TYPE_SIZE_T
AC_CHECK_SIZEOF(short)
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(long)
AC_CHECK_SIZEOF(long long)
AC_CHECK_SIZEOF(__int64)
AC_CHECK_SIZEOF(void *)
AC_CHECK_SIZEOF(size_t)
AC_CHECK_SIZEOF(ptrdiff_t)
Checks for compiler characteristics
AC_C_CONST
Checks for library functions
AC_CHECK_FUNCS(memcmp memcpy memmove memset)
Appendix D: Copyright
---------------------
LZO and miniLZO are Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001,
2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
Markus Franz Xaver Oberhumer <markus@oberhumer.com>.
LZO and miniLZO are distributed under the terms of the GNU General
Public License (GPL). See the file COPYING.
Special licenses for commercial and other applications which
are not willing to accept the GNU General Public License
are available by contacting the author.
============================================================================
miniLZO -- mini subset of the LZO real-time data compression library
============================================================================
Author : Markus Franz Xaver Johannes Oberhumer
<markus@oberhumer.com>
http://www.oberhumer.com/opensource/lzo/
Version : 2.06
Date : 12 Aug 2011
I've created miniLZO for projects where it is inconvenient to
include (or require) the full LZO source code just because you
want to add a little bit of data compression to your application.
miniLZO implements the LZO1X-1 compressor and both the standard and
safe LZO1X decompressor. Apart from fast compression it also useful
for situations where you want to use pre-compressed data files (which
must have been compressed with LZO1X-999).
miniLZO consists of one C source file and three header files:
minilzo.c
minilzo.h, lzoconf.h, lzodefs.h
To use miniLZO just copy these files into your source directory, add
minilzo.c to your Makefile and #include minilzo.h from your program.
Note: you also must distribute this file ('README.LZO') with your project.
minilzo.o compiles to about 6 KiB (using gcc or Visual C on an i386), and
the sources are about 30 KiB when packed with zip - so there's no more
excuse that your application doesn't support data compression :-)
For more information, documentation, example programs and other support
files (like Makefiles and build scripts) please download the full LZO
package from
http://www.oberhumer.com/opensource/lzo/
Have fun,
Markus
P.S. minilzo.c is generated automatically from the LZO sources and
therefore functionality is completely identical
Appendix A: building miniLZO
----------------------------
miniLZO is written such a way that it should compile and run
out-of-the-box on most machines.
If you are running on a very unusual architecture and lzo_init() fails then
you should first recompile with '-DLZO_DEBUG' to see what causes the failure.
The most probable case is something like 'sizeof(void *) != sizeof(size_t)'.
After identifying the problem you can compile by adding some defines
like '-DSIZEOF_VOID_P=8' to your Makefile.
The best solution is (of course) using Autoconf - if your project uses
Autoconf anyway just add '-DMINILZO_HAVE_CONFIG_H' to your compiler
flags when compiling minilzo.c. See the LZO distribution for an example
how to set up configure.ac.
Appendix B: list of public functions available in miniLZO
---------------------------------------------------------
Library initialization
lzo_init()
Compression
lzo1x_1_compress()
Decompression
lzo1x_decompress()
lzo1x_decompress_safe()
Checksum functions
lzo_adler32()
Version functions
lzo_version()
lzo_version_string()
lzo_version_date()
Portable (but slow) string functions
lzo_memcmp()
lzo_memcpy()
lzo_memmove()
lzo_memset()
Appendix C: suggested macros for 'configure.ac' when using Autoconf
-------------------------------------------------------------------
Checks for typedefs and structures
AC_CHECK_TYPE(ptrdiff_t,long)
AC_TYPE_SIZE_T
AC_CHECK_SIZEOF(short)
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(long)
AC_CHECK_SIZEOF(long long)
AC_CHECK_SIZEOF(__int64)
AC_CHECK_SIZEOF(void *)
AC_CHECK_SIZEOF(size_t)
AC_CHECK_SIZEOF(ptrdiff_t)
Checks for compiler characteristics
AC_C_CONST
Checks for library functions
AC_CHECK_FUNCS(memcmp memcpy memmove memset)
Appendix D: Copyright
---------------------
LZO and miniLZO are Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001,
2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
Markus Franz Xaver Oberhumer <markus@oberhumer.com>.
LZO and miniLZO are distributed under the terms of the GNU General
Public License (GPL). See the file COPYING.
Special licenses for commercial and other applications which
are not willing to accept the GNU General Public License
are available by contacting the author.
......@@ -19,13 +19,8 @@
#ifdef _WIN32
#pragma warning(disable: 4996)
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <io.h>
#else
#include <dfs_posix.h>
#endif
#include <dfs_posix.h>
/* the worst of allocation */
#define LZO1X_WORST(x) ( (x) + ((x)/16) + 64 + 3 )
......
Import('RTT_ROOT')
Import('rtconfig')
from building import *
cwd = GetCurrentDir()
CPPPATH = [cwd]
src = Split('''
src = Split('''
tjpgd.c
''')
CPPPATH = [RTT_ROOT + '/components/external/tjpgd1a']
group = DefineGroup('tjpgd', src, depend = ['RTGUI_IMAGE_TJPGD'], CPPPATH = CPPPATH)
Return('group')
......
common/font_cmp_hz*.c
doc/doxygened/
此差异已折叠。
......@@ -72,6 +72,8 @@ widgets/edit.c
widgets/mv_view.c
widgets/plot.c
widgets/plot_curve.c
widgets/digtube.c
widgets/digfont.c
""")
if GetDepend('RTGUI_USING_FONT_COMPACT'):
......
此差异已折叠。
此差异已折叠。
......@@ -37,13 +37,6 @@ static rt_bool_t rtgui_dc_hw_fini(struct rtgui_dc *dc);
static rt_bool_t rtgui_dc_hw_get_visible(struct rtgui_dc *dc);
static void rtgui_dc_hw_get_rect(struct rtgui_dc *dc, rtgui_rect_t *rect);
struct rtgui_dc_hw
{
struct rtgui_dc parent;
rtgui_widget_t *owner;
const struct rtgui_graphic_driver *hw_driver;
};
const struct rtgui_dc_engine dc_hw_engine =
{
rtgui_dc_hw_draw_point,
......
......@@ -59,11 +59,12 @@ void rtgui_bitmap_font_draw_char(struct rtgui_font_bitmap *font, struct rtgui_dc
for (i = 0; i < h; i++)
{
rt_uint8_t chr;
rt_uint8_t chr = 0;
const rt_uint8_t *ptr = font_ptr + i * word_bytes;
for (j = 0; j < w; j++)
{
if (j % 8 == 0)chr = *ptr++;
if (j % 8 == 0)
chr = *ptr++;
if (chr & 0x80)
rtgui_dc_draw_point(dc, j + x, i + y);
else if (style & RTGUI_TEXTSTYLE_DRAW_BACKGROUND)
......
......@@ -351,6 +351,7 @@ static rt_bool_t rtgui_image_jpeg_load(struct rtgui_image *image, struct rtgui_f
{
/* no memory */
jpeg_finish_decompress(&jpeg->cinfo);
jpeg_destroy_decompress(&jpeg->cinfo);
rt_free(jpeg);
return RT_FALSE;
......@@ -381,6 +382,7 @@ static void rtgui_image_jpeg_unload(struct rtgui_image *image)
rtgui_filerw_close(jpeg->filerw);
jpeg_finish_decompress(&jpeg->cinfo);
}
jpeg_destroy_decompress(&jpeg->cinfo);
rt_free(jpeg);
}
}
......
......@@ -2274,3 +2274,13 @@ rt_bool_t rtgui_rect_is_empty(const rtgui_rect_t *rect)
return RT_FALSE;
}
rtgui_rect_t *rtgui_rect_set(rtgui_rect_t *rect, int x, int y, int w, int h)
{
RT_ASSERT(rect != RT_NULL);
rect->x1 = x; rect->y1 = y;
rect->x2 = x + w; rect->y2 = y + h;
return rect;
}
......@@ -30,7 +30,6 @@ static void _rtgui_app_constructor(struct rtgui_app *app)
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;
......@@ -51,13 +50,13 @@ DEFINE_CLASS_TYPE(application, "application",
_rtgui_app_destructor,
sizeof(struct rtgui_app));
struct rtgui_app *rtgui_app_create(
rt_thread_t tid,
const char *title)
struct rtgui_app *rtgui_app_create(const char *title)
{
rt_thread_t srv_tid;
rt_thread_t tid = rt_thread_self();
struct rtgui_app *app;
struct rtgui_app *srv_app;
struct rtgui_event_application event;
char mq_name[RT_NAME_MAX];
RT_ASSERT(tid != RT_NULL);
RT_ASSERT(title != RT_NULL);
......@@ -70,10 +69,9 @@ struct rtgui_app *rtgui_app_create(
/* 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);
rt_snprintf(mq_name, RT_NAME_MAX, "g%s", title);
app->mq = rt_mq_create(mq_name, sizeof(union rtgui_event_generic), 32, RT_IPC_FLAG_FIFO);
if (app->mq == RT_NULL)
{
rt_kprintf("create msgq failed.\n");
......@@ -85,31 +83,30 @@ struct rtgui_app *rtgui_app_create(
if (app->name == RT_NULL)
goto __err;
/* send a message to notify rtgui server */
srv_tid = rtgui_get_server();
if (srv_tid == RT_NULL)
/* the first app should be the server */
srv_app = rtgui_get_server();
if (srv_app == RT_NULL)
{
rt_kprintf("gui server is not running.\n");
goto __err;
}
/* create the rtgui server application */
if (srv_tid == rt_thread_self())
/* set user thread */
tid->user_data = (rt_uint32_t)app;
rt_kprintf("RTGUI: creating the server app %p.\n", app);
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)
if (rtgui_send_sync(srv_app, RTGUI_EVENT(&event), sizeof(event)) == RT_EOK)
{
/* set user thread */
tid->user_data = (rt_uint32_t)app;
return app;
}
__err:
__mq_err:
rtgui_object_destroy(RTGUI_OBJECT(app));
tid->user_data = 0;
return RT_NULL;
}
RTM_EXPORT(rtgui_app_create);
......@@ -124,7 +121,7 @@ RTM_EXPORT(rtgui_app_create);
void rtgui_app_destroy(struct rtgui_app *app)
{
rt_thread_t srv_tid;
struct rtgui_app *srv_app;
_rtgui_application_check(app);
if (!(app->state_flag & RTGUI_APP_FLAG_EXITED))
......@@ -135,14 +132,14 @@ void rtgui_app_destroy(struct rtgui_app *app)
}
/* send a message to notify rtgui server */
srv_tid = rtgui_get_server();
if (srv_tid != rt_thread_self()) /* must not the server thread */
srv_app = rtgui_get_server();
if (srv_app != rtgui_app_self())
{
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)
if (rtgui_send_sync(srv_app, RTGUI_EVENT(&event), sizeof(event)) != RT_EOK)
{
rt_kprintf("destroy an application in server failed\n");
return ;
......@@ -168,25 +165,18 @@ struct rtgui_app *rtgui_app_self(void)
}
RTM_EXPORT(rtgui_app_self);
void rtgui_app_set_onidle(rtgui_idle_func_t onidle)
void rtgui_app_set_onidle(struct rtgui_app *app, rtgui_idle_func_t onidle)
{
struct rtgui_app *app;
app = rtgui_app_self();
if (app != RT_NULL)
app->on_idle = onidle;
_rtgui_application_check(app);
app->on_idle = onidle;
}
RTM_EXPORT(rtgui_app_set_onidle);
rtgui_idle_func_t rtgui_app_get_onidle(void)
rtgui_idle_func_t rtgui_app_get_onidle(struct rtgui_app *app)
{
struct rtgui_app *app;
app = rtgui_app_self();
if (app != RT_NULL)
return app->on_idle;
else
return RT_NULL;
_rtgui_application_check(app);
return app->on_idle;
}
RTM_EXPORT(rtgui_app_get_onidle);
......@@ -369,7 +359,7 @@ void rtgui_app_activate(struct rtgui_app *app)
RTGUI_EVENT_APP_ACTIVATE_INIT(&event);
event.app = app;
rtgui_send(app->tid, RTGUI_EVENT(&event), sizeof(struct rtgui_event_application));
rtgui_send(app, RTGUI_EVENT(&event), sizeof(struct rtgui_event_application));
}
RTM_EXPORT(rtgui_app_activate);
......@@ -380,28 +370,28 @@ void rtgui_app_close(struct rtgui_app *app)
RTGUI_EVENT_APP_DESTROY_INIT(&event);
event.app = app;
rtgui_send(app->tid, RTGUI_EVENT(&event), sizeof(struct rtgui_event_application));
rtgui_send(app, RTGUI_EVENT(&event), sizeof(struct rtgui_event_application));
}
RTM_EXPORT(rtgui_app_close);
/**
* set this application as window manager
*/
rt_err_t rtgui_app_set_as_wm(void)
rt_err_t rtgui_app_set_as_wm(struct rtgui_app *app)
{
rt_thread_t srv_tid;
struct rtgui_app *srv_app;
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)
_rtgui_application_check(app);
srv_app = rtgui_get_server();
if (srv_app != 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));
rtgui_send_sync(srv_app, RTGUI_EVENT(&event), sizeof(event));
return RT_EOK;
}
......@@ -409,15 +399,11 @@ rt_err_t rtgui_app_set_as_wm(void)
}
RTM_EXPORT(rtgui_app_set_as_wm);
void rtgui_app_set_main_win(struct rtgui_win *win)
void rtgui_app_set_main_win(struct rtgui_app *app, struct rtgui_win *win)
{
struct rtgui_app *app;
app = rtgui_app_self();
if (app != RT_NULL)
{
app->main_object = RTGUI_OBJECT(win);
}
_rtgui_application_check(app);
app->main_object = RTGUI_OBJECT(win);
}
RTM_EXPORT(rtgui_app_set_main_win);
......@@ -422,7 +422,7 @@ static rt_bool_t _rtgui_mv_model_notify_view(struct rtgui_mv_model *model,
struct rtgui_mv_view *view,
struct rtgui_event_mv_model *emodel)
{
rt_thread_t target = RTGUI_WIDGET(view)->toplevel->app->tid;
struct rtgui_app *target = RTGUI_WIDGET(view)->toplevel->app;
emodel->model = model;
emodel->view = view;
return rtgui_send(target, (struct rtgui_event *)emodel, sizeof(*emodel));
......
......@@ -70,7 +70,7 @@ static void rtgui_time_out(void *parameter)
event.timer = timer;
rtgui_send(timer->tid, &(event.parent), sizeof(rtgui_event_timer_t));
rtgui_send(timer->app, &(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)
......@@ -78,7 +78,7 @@ rtgui_timer_t *rtgui_timer_create(rt_int32_t time, rt_int32_t flag, rtgui_timeou
rtgui_timer_t *timer;
timer = (rtgui_timer_t *) rtgui_malloc(sizeof(rtgui_timer_t));
timer->tid = rt_thread_self();
timer->app = rtgui_app_self();
timer->timeout = timeout;
timer->user_data = parameter;
......@@ -371,7 +371,7 @@ const char *event_string[] =
#define DBG_MSG(x) rt_kprintf x
static void rtgui_event_dump(rt_thread_t tid, rtgui_event_t *event)
static void rtgui_event_dump(struct rtgui_app* app, rtgui_event_t *event)
{
char *sender = "(unknown)";
......@@ -389,12 +389,12 @@ static void rtgui_event_dump(rt_thread_t tid, rtgui_event_t *event)
if (event->type >= RTGUI_EVENT_COMMAND)
{
rt_kprintf("%s -- USER EVENT --> %s \n", sender, tid->name);
rt_kprintf("%s -- USER EVENT --> %s \n", sender, app->name);
return ;
}
else
{
rt_kprintf("%s -- %s --> %s ", sender, event_string[event->type], tid->name);
rt_kprintf("%s -- %s --> %s ", sender, event_string[event->type], app->name);
}
switch (event->type)
......@@ -545,88 +545,68 @@ static void rtgui_event_dump(rt_thread_t tid, rtgui_event_t *event)
}
#else
#define DBG_MSG(x)
#define rtgui_event_dump(tid, event)
#define rtgui_event_dump(app, 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 rtgui_send(struct rtgui_app* app, rtgui_event_t *event, rt_size_t event_size)
{
rt_err_t result;
struct rtgui_app *app;
RT_ASSERT(tid != RT_NULL);
RT_ASSERT(app != 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;
rtgui_event_dump(app, event);
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);
rt_kprintf("send event to %s failed\n", app->name);
}
return result;
}
RTM_EXPORT(rtgui_send);
rt_err_t rtgui_send_urgent(rt_thread_t tid, rtgui_event_t *event, rt_size_t event_size)
rt_err_t rtgui_send_urgent(struct rtgui_app* app, rtgui_event_t *event, rt_size_t event_size)
{
rt_err_t result;
struct rtgui_app *app;
RT_ASSERT(tid != RT_NULL);
RT_ASSERT(app != 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;
rtgui_event_dump(app, event);
result = rt_mq_urgent(app->mq, event, event_size);
if (result != RT_EOK)
rt_kprintf("send ergent event failed\n");
rt_kprintf("send ergent event to %s failed\n", app->name);
return result;
}
RTM_EXPORT(rtgui_send_urgent);
rt_err_t rtgui_send_sync(rt_thread_t tid, rtgui_event_t *event, rt_size_t event_size)
rt_err_t rtgui_send_sync(struct rtgui_app* app, 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(app != RT_NULL);
RT_ASSERT(event != RT_NULL);
RT_ASSERT(event_size != 0);
rtgui_event_dump(tid, event);
rtgui_event_dump(app, 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)
......@@ -728,12 +708,6 @@ rt_err_t rtgui_recv_filter(rt_uint32_t type, rtgui_event_t *event, rt_size_t eve
}
RTM_EXPORT(rtgui_recv_filter);
rt_thread_t rtgui_get_server(void)
{
return rt_thread_find("rtgui");
}
RTM_EXPORT(rtgui_get_server);
void rtgui_set_mainwin_rect(struct rtgui_rect *rect)
{
_mainwin_rect = *rect;
......
......@@ -96,31 +96,34 @@ void rtgui_theme_draw_win(struct rtgui_topwin *win)
if (!(win->flag & WINTITLE_NO))
{
rt_uint32_t index;
float r, g, b, delta;
rt_uint16_t r, g, b, delta;
#define RGB_FACTOR 4
if (win->flag & WINTITLE_ACTIVATE)
{
r = 10;
g = 36;
b = 106;
delta = 150 / (float)(rect.x2 - rect.x1);
r = 10 << RGB_FACTOR;
g = 36 << RGB_FACTOR;
b = 106 << RGB_FACTOR;
delta = (150 << RGB_FACTOR) / (rect.x2 - rect.x1);
}
else
{
r = 128;
g = 128;
b = 128;
delta = 64 / (float)(rect.x2 - rect.x1);
r = 128 << RGB_FACTOR;
g = 128 << RGB_FACTOR;
b = 128 << RGB_FACTOR;
delta = (64 << RGB_FACTOR) / (rect.x2 - rect.x1);
}
RTGUI_WIDGET_FOREGROUND(win->title) = RTGUI_RGB(r, g, b);
for (index = rect.x1; index < rect.x2 + 1; index ++)
{
RTGUI_WIDGET_FOREGROUND(win->title) = RTGUI_RGB((r>>RGB_FACTOR), \
(g>>RGB_FACTOR), (b>>RGB_FACTOR));
rtgui_dc_draw_vline(dc, index, rect.y1, rect.y2);
r += delta;
g += delta;
b += delta;
}
#undef RGB_FACTOR
if (win->flag & WINTITLE_ACTIVATE)
{
......
RTGUI 0.6版发布纪要
# 为什么是 0.6?
RTGUI 是作为 RT-Thread 的一个组件存在的。这次新发布的版本是在原 RTGUI 基础上重
构而来的。原 RTGUI 没有独立的版本号。暂设其为 0.5。所以本版本号取 0.6,为在原有
基础上改进之意。以后我们会每个月发布一个新版本。下一个版本号会是 0.6.1。
# 运行环境
理论上原来可以运行 RTGUI 的设备上都可以运行新的 RTGUI。本版本自带一个 Windows
模拟器,用来方便地评估运行效果。默认的运行环境是 realtouch。RT-Thread 中的模拟
器也是可以运作的。
# 新版本有什么特点?
0. 新版本的 GUI 摒弃了原有的 workbench/view/window 的工作方式。转换成全面向
window的工作方式。原有的 workbench/view 可以用 notebook 来实现。
0.`rtgui_app` 对线程进行了抽象。
0. 事件驱动更彻底:
0. 将事件处理机制集成进 `rtgui_object`
0. 添加了`RTGUI_EVENT_SHOW``RTGUI_EVENT_HIDE` 来通知控件将要被显示/隐藏。
0. 底层代码中对事件的应用更加彻底。
0. 重构了自动布局方式。使得控件的摆放更加方便。
# 增强
- 添加了 TJPGD 引擎。使得小内存系统解码 jpeg 图片成为可能。(onelife)
- 添加了对单色屏的支持(onelife)
- bmp 图像引擎的重构(onelife)
- bmp 图像的旋转/缩放,以及功能性增强(amsl)
- 增加屏幕快照功能(amsl)
- PNG 引擎增加 Alpha 通道支持(amsl)
- 新增 edit 多行文本编辑控件。(amsl)
- 增加了 Model/View 的编程框架。(Grissiom)
- 添加了缩减字库的特性,开启后可以自动添加用到的汉字,不用的汉字字形不会加入到
字库当中。使得 GUI 能够在小 ROM 系统上得以应用。(Grissiom)
- 新增 digtube 七段码显示控件(prife)
- demo/benchmark 新增了 FPS 输出(amsl)
- 新增 box/panel/groupbox,支持自动布局(Bernard)
# API 变化
除了 workbench/view 的消失以外,还有如下的 API 变化:
- c05a301, 68e3e30: `rtgui_{menu,win}_hiden` 被重命名为 `rtgui_{menu,win}_hide`
- 05e4894: 将 `struct rtgui_widget` 中的 `mini_{height,width}` 重命名为 `min_{height,width}`
- 等等……
今后很长时间内,新版本的 RTGUI 会与此版本的 API 尽量只增不减,保持兼容。
# Bug fixes
- 00a6690: 解决了 `rtgui_notebook_set_current_by_index` 中重绘标签页的 bug。感
谢 prife 提交 bug 信息和补丁。
- 6850ff2: 解决了 `last_mevent_widget` 引起的事件传送失败。感谢 heryon 提交bug
报告。
- 9143e11: 解决了 jpeg 引擎中的内存泄漏。感谢 Young 提供 bug 信息。
- fbd567c: 解决了 `rtgui_textbox_set_line_length` 的 bug。
- 9b67b66: 修复了窗口标题栏渐变效果的绘制。
- fc3abbf: 修复了 `rtgui_label_set_text`。感谢 tanghong668 提供 bug 信息。
- d41586c: 修复了窗口激活时重复刷新的问题。感谢 onelife 提供 bug 信息。
- ab08de6: 修复了字库缓存的 bug。感谢 rtt\_fans 提供 bug 信息。
- 等等……
除了上面提到的,luoyuncong2012, lgnq, shaolin 也有贡献。上面的列表也必然是不完
整的。感谢编写了第一版 RTGUI 的 Bernard 和其他大侠们,没有他们的辛勤劳动,也不
会有今天的版本。感谢各位使用和支持RTGUI的开发人员,是你们 RTGUI 体现了 RTGUI 的
价值。
/** @~english
@page pg-mv-model Model-View framework
@brief A overview of the Model-View framework
@section Glossary
@li view: widget dedicated to show the data. It could be a graph, list etc.
@li model: abstraction and combination of data.
@li data: things that needed to be delivered or shown. It could be a array of
votage values which is sampled from a AD in an interval. Or it could be the
attributes of all the files in a folder.
@section Design considerations and implementations
@li one model can respond to more than one views. one view can connect to
more than one models.
@li It is guaranteed that the change events of a model will be sent to all
the registered views.
@li Because there are so many formats of data, Model-View neither specify the
format data is stored nor try to abstract them. The only thing stored in
model is a pointer to the underlaying data. It is the responsibility of
inherited classed to implement the boxing/un-boxing operations.
@li Data can be multi-dimensional. The "dimension" does not only means
dimension geometry. It can also means attributes. For example, a folder could
have two attributes which are name and icon. So it's two-dimensional. If take
the size into consideration, it will be three-dimensional. The size of
dimension is saved in model. Each dimension is correspond to a pointer to some
sort of data. Model can save many of them. As above, model does not make
assumptions on the underlaying data structure. It only provide mechanism, not
policy and leave that to the inherited classes.
@section Events
@li model has a record of registered views. When data changes, model notify
views the change by sending events. The event contains the id of the model,
the id of target view, the scope of changed data.
@li views can handle the event by retrieve data from model, and update
themselves according to the scope that data has changed. The connected model
views should have the same presentation of data structure. Views should also
restore all the models it interested. In the case of repainting, it should
re-retrieve data from those models.
@li model send events by rtgui_send. So it's suitable for the synchronization
between threads and even could be used in ISR.
*/
/** @~chinese
@page pg-mv-model Model-View 框架
@brief 对于 Model-View 框架的简介
@section 名词解释
@li view:用于显示数据的控件。可以是诸如图表控件、列表控件的控件。
@li model:对于数据的组合和抽象。
@li 数据:需要显示或传递的数据。它可以是每隔一段时间就从AD读取的电压值,也可
以是一个目录下所有文件的属性列表。
@section 设计原则和实现
@li 一个 model 可以对应多个view。一个view可以对应多个 model
@li 保证 model 的更新事件会同时发送到所有注册的 view 上。
@li 因为数据的形式与内容千差万别,所以 Model-View 不规定数据的存储形式,也不对其进
行抽象。只在 model 中保留指向第一个数据的指针。打包/解包由从m odel/view 派生出
的子类实现。
@li 数据源可以是多维的。这里的维度指的不只是几何的维度,而且可以是属性。比如
一个目录,它可以有名称、图标两个属性,那么它就是两维的。如果加入大小这个属性
,就是三维的。 model 内部存储数据的维度大小。一个维度对应一个数据首地址的指针
model 中可以存储多个数据首地址。model 对底层数据结构不作假设。只提供机制,不
提供策略。只保证能够多维,但把具体的实现方式留给子类实现。
@subsection 事件
@li model 内部记录对自己感兴趣的 view。在数据变化时,用事件通知所有相关 view。事
件内容包含:自己的 id;目标 view id;所变化数据的 index 范围。
@li view 收到事件之后通过 model id 拿到数据并根据事件中的变化范围更新自己。对于
指针的数据类型转换需要自己实现并保证和 model 一致。view 内部保存与自己相关的
model id,在需要重绘的时候要从所有相关 model 提取数据。
@li model 通过 rtgui_send view 发送事件。使得这个模型适用于线程间同步,也
可以在中断上下文里通知事件的发生。
*/
......@@ -60,6 +60,14 @@ struct rtgui_dc
const struct rtgui_dc_engine *engine;
};
/* hardware device context */
struct rtgui_dc_hw
{
struct rtgui_dc parent;
rtgui_widget_t *owner;
const struct rtgui_graphic_driver *hw_driver;
};
#define RTGUI_DC_FC(dc) (rtgui_dc_get_gc(dc)->foreground)
#define RTGUI_DC_BC(dc) (rtgui_dc_get_gc(dc)->background)
#define RTGUI_DC_FONT(dc) (rtgui_dc_get_gc(dc)->font)
......
......@@ -17,6 +17,7 @@
#include <rtgui/list.h>
#include <rtgui/color.h>
/* graphic driver operations */
struct rtgui_graphic_driver_ops
{
/* set and get pixel in (x, y) */
......@@ -30,6 +31,22 @@ struct rtgui_graphic_driver_ops
void (*draw_raw_hline)(rt_uint8_t *pixels, int x1, int x2, int y);
};
/* graphic extension operations */
struct rtgui_graphic_ext_ops
{
/* some 2D operations */
void (*draw_line)(rtgui_color_t *c, int x1, int y1, int x2, int y2);
void (*draw_rect)(rtgui_color_t *c, int x1, int y1, int x2, int y2);
void (*fill_rect)(rtgui_color_t *c, int x1, int y1, int x2, int y2);
void (*draw_circle)(rtgui_color_t *c, int x, int y, int r);
void (*fill_circle)(rtgui_color_t *c, int x, int y, int r);
void (*draw_ellipse)(rtgui_color_t *c, int x, int y, int rx, int ry);
void (*fill_ellipse)(rtgui_color_t *c, int x, int y, int rx, int ry);
};
struct rtgui_graphic_driver
{
/* pixel format and byte per pixel */
......@@ -43,12 +60,12 @@ struct rtgui_graphic_driver
/* framebuffer address and ops */
volatile rt_uint8_t *framebuffer;
rt_device_t device;
struct rt_device* device;
const struct rtgui_graphic_driver_ops *ops;
const struct rtgui_graphic_ext_ops *ext_ops;
};
void rtgui_graphic_driver_add(const struct rtgui_graphic_driver *driver);
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);
......@@ -64,5 +81,19 @@ rt_inline struct rtgui_graphic_driver *rtgui_graphic_get_device()
return &_driver;
}
#ifdef RTGUI_USING_HW_CURSOR
/*
* hardware cursor
*/
enum rtgui_cursor_type
{
RTGUI_CURSOR_ARROW,
RTGUI_CURSOR_HAND,
};
void rtgui_cursor_set_device(const char* device_name);
void rtgui_cursor_set_position(rt_uint16_t x, rt_uint16_t y);
void rtgui_cursor_set_image(enum rtgui_cursor_type type);
#endif
#endif
......@@ -90,7 +90,7 @@ struct rtgui_event
rt_uint16_t user;
/* the event sender */
rt_thread_t sender;
struct rtgui_app *sender;
/* mailbox to acknowledge request */
rt_mailbox_t ack;
......@@ -98,11 +98,13 @@ struct rtgui_event
typedef struct rtgui_event rtgui_event_t;
#define RTGUI_EVENT(e) ((struct rtgui_event*)(e))
extern struct rtgui_app* rtgui_app_self(void);
#define RTGUI_EVENT_INIT(e, t) do \
{ \
(e)->type = (t); \
(e)->user = 0; \
(e)->sender = rt_thread_self(); \
(e)->sender = rtgui_app_self(); \
(e)->ack = RT_NULL; \
} while (0)
......
......@@ -20,81 +20,82 @@
extern "C" {
#endif
typedef struct rtgui_region_data rtgui_region_data_t;
typedef struct rtgui_region_data rtgui_region_data_t;
struct rtgui_region_data
{
rt_uint32_t size;
rt_uint32_t numRects;
/* XXX: And why, exactly, do we have this bogus struct definition? */
/* rtgui_rect_t rects[size]; in memory but not explicitly declared */
};
struct rtgui_region_data
{
rt_uint32_t size;
rt_uint32_t numRects;
/* XXX: And why, exactly, do we have this bogus struct definition? */
/* rtgui_rect_t rects[size]; in memory but not explicitly declared */
};
typedef struct rtgui_region
{
rtgui_rect_t extents;
rtgui_region_data_t *data;
} rtgui_region_t;
typedef struct rtgui_region
{
rtgui_rect_t extents;
rtgui_region_data_t *data;
} rtgui_region_t;
typedef enum
{
RTGUI_REGION_STATUS_FAILURE,
RTGUI_REGION_STATUS_SUCCESS
} rtgui_region_status_t;
typedef enum
{
RTGUI_REGION_STATUS_FAILURE,
RTGUI_REGION_STATUS_SUCCESS
} rtgui_region_status_t;
/* creation/destruction */
/* creation/destruction */
void rtgui_region_init(rtgui_region_t *region);
void rtgui_region_init_rect(rtgui_region_t *region,
int x, int y, unsigned int width, unsigned int height);
void rtgui_region_init_with_extents(rtgui_region_t *region, const rtgui_rect_t *extents);
void rtgui_region_fini(rtgui_region_t *region);
void rtgui_region_init(rtgui_region_t *region);
void rtgui_region_init_rect(rtgui_region_t *region,
int x, int y, unsigned int width, unsigned int height);
void rtgui_region_init_with_extents(rtgui_region_t *region, const rtgui_rect_t *extents);
void rtgui_region_fini(rtgui_region_t *region);
void rtgui_region_translate(rtgui_region_t *region, int x, int y);
void rtgui_region_translate(rtgui_region_t *region, int x, int y);
rtgui_region_status_t rtgui_region_copy(rtgui_region_t *dest, rtgui_region_t *source);
rtgui_region_status_t rtgui_region_copy(rtgui_region_t *dest, rtgui_region_t *source);
rtgui_region_status_t rtgui_region_intersect(rtgui_region_t *newReg, rtgui_region_t *reg1, rtgui_region_t *reg2);
rtgui_region_status_t rtgui_region_intersect_rect(rtgui_region_t *newReg, rtgui_region_t *reg1, rtgui_rect_t *rect);
rtgui_region_status_t rtgui_region_union(rtgui_region_t *newReg, rtgui_region_t *reg1, rtgui_region_t *reg2);
rtgui_region_status_t rtgui_region_union_rect(rtgui_region_t *dest, rtgui_region_t *source, rtgui_rect_t *rect);
rtgui_region_status_t rtgui_region_subtract(rtgui_region_t *regD, rtgui_region_t *regM, rtgui_region_t *regS);
rtgui_region_status_t rtgui_region_subtract_rect(rtgui_region_t *regD, rtgui_region_t *regM, rtgui_rect_t *rect);
rtgui_region_status_t rtgui_region_inverse(rtgui_region_t *newReg, rtgui_region_t *reg1, rtgui_rect_t *invRect);
rtgui_region_status_t rtgui_region_intersect(rtgui_region_t *newReg, rtgui_region_t *reg1, rtgui_region_t *reg2);
rtgui_region_status_t rtgui_region_intersect_rect(rtgui_region_t *newReg, rtgui_region_t *reg1, rtgui_rect_t *rect);
rtgui_region_status_t rtgui_region_union(rtgui_region_t *newReg, rtgui_region_t *reg1, rtgui_region_t *reg2);
rtgui_region_status_t rtgui_region_union_rect(rtgui_region_t *dest, rtgui_region_t *source, rtgui_rect_t *rect);
rtgui_region_status_t rtgui_region_subtract(rtgui_region_t *regD, rtgui_region_t *regM, rtgui_region_t *regS);
rtgui_region_status_t rtgui_region_subtract_rect(rtgui_region_t *regD, rtgui_region_t *regM, rtgui_rect_t *rect);
rtgui_region_status_t rtgui_region_inverse(rtgui_region_t *newReg, rtgui_region_t *reg1, rtgui_rect_t *invRect);
int rtgui_region_num_rects(rtgui_region_t *region);
int rtgui_region_num_rects(rtgui_region_t *region);
rtgui_rect_t *rtgui_region_rects(rtgui_region_t *region);
rtgui_rect_t *rtgui_region_rects(rtgui_region_t *region);
#define RTGUI_REGION_OUT 0
#define RTGUI_REGION_IN 1
#define RTGUI_REGION_PART 2
int rtgui_region_contains_point(rtgui_region_t *region, int x, int y, rtgui_rect_t *box);
int rtgui_region_contains_rectangle(rtgui_region_t *rtgui_region_t, rtgui_rect_t *prect);
int rtgui_region_contains_point(rtgui_region_t *region, int x, int y, rtgui_rect_t *box);
int rtgui_region_contains_rectangle(rtgui_region_t *rtgui_region_t, rtgui_rect_t *prect);
int rtgui_region_not_empty(rtgui_region_t *region);
rtgui_rect_t *rtgui_region_extents(rtgui_region_t *region);
int rtgui_region_not_empty(rtgui_region_t *region);
rtgui_rect_t *rtgui_region_extents(rtgui_region_t *region);
rtgui_region_status_t rtgui_region_append(rtgui_region_t *dest, rtgui_region_t *region);
rtgui_region_status_t rtgui_region_validate(rtgui_region_t *badreg, int *pOverlap);
rtgui_region_status_t rtgui_region_append(rtgui_region_t *dest, rtgui_region_t *region);
rtgui_region_status_t rtgui_region_validate(rtgui_region_t *badreg, int *pOverlap);
void rtgui_region_reset(rtgui_region_t *region, rtgui_rect_t *rect);
void rtgui_region_empty(rtgui_region_t *region);
void rtgui_region_dump(rtgui_region_t *region);
int rtgui_region_is_flat(rtgui_region_t *region);
void rtgui_region_reset(rtgui_region_t *region, rtgui_rect_t *rect);
void rtgui_region_empty(rtgui_region_t *region);
void rtgui_region_dump(rtgui_region_t *region);
int rtgui_region_is_flat(rtgui_region_t *region);
/* rect functions */
extern rtgui_rect_t rtgui_empty_rect;
/* rect functions */
extern rtgui_rect_t rtgui_empty_rect;
void rtgui_rect_moveto(rtgui_rect_t *rect, int x, int y);
void rtgui_rect_moveto_align(rtgui_rect_t *rect, rtgui_rect_t *to, int align);
void rtgui_rect_inflate(rtgui_rect_t *rect, int d);
void rtgui_rect_intersect(rtgui_rect_t *src, rtgui_rect_t *dest);
int rtgui_rect_contains_point(const rtgui_rect_t *rect, int x, int y);
int rtgui_rect_is_intersect(const rtgui_rect_t *rect1, const rtgui_rect_t *rect2);
int rtgui_rect_is_equal(const rtgui_rect_t *rect1, const rtgui_rect_t *rect2);
rt_bool_t rtgui_rect_is_empty(const rtgui_rect_t *rect);
void rtgui_rect_moveto(rtgui_rect_t *rect, int x, int y);
void rtgui_rect_moveto_align(rtgui_rect_t *rect, rtgui_rect_t *to, int align);
void rtgui_rect_inflate(rtgui_rect_t *rect, int d);
void rtgui_rect_intersect(rtgui_rect_t *src, rtgui_rect_t *dest);
int rtgui_rect_contains_point(const rtgui_rect_t *rect, int x, int y);
int rtgui_rect_is_intersect(const rtgui_rect_t *rect1, const rtgui_rect_t *rect2);
int rtgui_rect_is_equal(const rtgui_rect_t *rect1, const rtgui_rect_t *rect2);
rtgui_rect_t *rtgui_rect_set(rtgui_rect_t *rect, int x, int y, int w, int h);
rt_bool_t rtgui_rect_is_empty(const rtgui_rect_t *rect);
#if defined(__cplusplus) || defined(c_plusplus)
}
......
......@@ -17,6 +17,11 @@
#include <rtthread.h>
#include <rtgui/rtgui_config.h>
#define RTGUI_VERSION 0L /**< major version number */
#define RTGUI_SUBVERSION 6L /**< minor version number */
#define RTGUI_REVISION 0L /**< revise version number */
#define RTGUI_CODENAME "Newton" /**< code name */
#define RT_INT16_MAX 32767
#define RT_INT16_MIN (-RT_INT16_MAX-1)
#define RTGUI_NOT_FOUND (-1)
......
......@@ -52,9 +52,6 @@ struct rtgui_app
/* the thread id */
rt_thread_t tid;
/* the RTGUI server id */
rt_thread_t server;
/* the message queue of thread */
rt_mq_t mq;
/* event buffer */
......@@ -70,9 +67,13 @@ struct rtgui_app
};
/**
* create an application named @myname on thread @param tid
* create an application named @myname on current thread.
*
* @param name the name of the application
*
* @return a pointer to struct rtgui_app on success. RT_NULL on failure.
*/
struct rtgui_app *rtgui_app_create(rt_thread_t tid, const char *title);
struct rtgui_app *rtgui_app_create(const char *name);
void rtgui_app_destroy(struct rtgui_app *app);
rt_bool_t rtgui_app_event_handler(struct rtgui_object *obj, rtgui_event_t *event);
......@@ -81,11 +82,15 @@ void rtgui_app_exit(struct rtgui_app *app, rt_uint16_t code);
void rtgui_app_activate(struct rtgui_app *app);
void rtgui_app_close(struct rtgui_app *app);
void rtgui_app_set_onidle(rtgui_idle_func_t onidle);
rtgui_idle_func_t rtgui_app_get_onidle(void);
void rtgui_app_set_onidle(struct rtgui_app *app, rtgui_idle_func_t onidle);
rtgui_idle_func_t rtgui_app_get_onidle(struct rtgui_app *app);
/**
* return the rtgui_app struct on current thread
*/
struct rtgui_app *rtgui_app_self(void);
rt_err_t rtgui_app_set_as_wm(void);
void rtgui_app_set_main_win(struct rtgui_win *win);
rt_err_t rtgui_app_set_as_wm(struct rtgui_app *app);
void rtgui_app_set_main_win(struct rtgui_app *app, struct rtgui_win *win);
#endif /* end of include guard: __RTGUI_APP_H__ */
......@@ -56,8 +56,8 @@ struct rtgui_topwin
/* the window id */
struct rtgui_win *wid;
/* the thread id */
rt_thread_t tid;
/* which app I belong */
struct rtgui_app *app;
/* the extent information */
rtgui_rect_t extent;
......
......@@ -26,8 +26,8 @@ typedef void (*rtgui_timeout_func)(struct rtgui_timer *timer, void *parameter);
struct rtgui_timer
{
/* context thread id */
rt_thread_t tid;
/* the rtgui application it runs on */
struct rtgui_app* app;
/* rt timer */
struct rt_timer timer;
......@@ -58,7 +58,7 @@ void *rtgui_realloc(void *ptr, rt_size_t size);
#define rtgui_exit_critical rt_exit_critical
#endif
rt_thread_t rtgui_get_server(void);
struct rtgui_app* rtgui_get_server(void);
void rtgui_set_mainwin_rect(struct rtgui_rect *rect);
void rtgui_get_mainwin_rect(struct rtgui_rect *rect);
void rtgui_get_screen_rect(struct rtgui_rect *rect);
......@@ -67,9 +67,9 @@ void rtgui_screen_lock(rt_int32_t timeout);
void rtgui_screen_unlock(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_send(struct rtgui_app* app, struct rtgui_event *event, rt_size_t event_size);
rt_err_t rtgui_send_urgent(struct rtgui_app* app, struct rtgui_event *event, rt_size_t event_size);
rt_err_t rtgui_send_sync(struct rtgui_app* app, struct rtgui_event *event, rt_size_t event_size);
rt_err_t rtgui_ack(struct rtgui_event *event, rt_int32_t status);
rt_err_t rtgui_recv(struct rtgui_event *event, rt_size_t event_size);
rt_err_t rtgui_recv_nosuspend(struct rtgui_event *event, rt_size_t event_size);
......
#ifndef DIG_FONT_H
#define DIG_FONT_H
struct rtgui_digitfont_data
{
rt_uint16_t x;
rt_uint16_t y;
rt_uint16_t len;
rt_uint16_t type; //ˮƽʹֱ
};
struct rtgui_digitfont
{
int seg1_len;
int seg1_hspace;
int seg1_vspace;
int seg1_nr; //9
int seg2_len;
int seg3_len;
struct rtgui_digitfont_data *data;
};
typedef struct rtgui_digitfont rtgui_digitfont_t;
extern struct rtgui_digitfont digitfont_40;
extern const char digtube_code_table[];
int rtgui_digitfont_create(struct rtgui_digitfont *font);
int rtgui_dc_draw_digitfont(struct rtgui_dc *dc, struct rtgui_digitfont *font, rtgui_rect_t *rect);
int rtgui_get_digfont_metrics(struct rtgui_digitfont * font, rtgui_rect_t * rect);
int rtgui_dc_draw_digitfont_code(struct rtgui_dc *dc, struct rtgui_digitfont * font, rtgui_rect_t * rect, char code);
#endif
\ No newline at end of file
/*
* File : digfont.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2012-12-21 pife first version
*/
#ifndef __RTGUI_DIGTUBE_H__
#define __RTGUI_DIGTUBE_H__
#include <rtgui/rtgui.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/widget.h>
#include <rtgui/widgets/digfont.h>
DECLARE_CLASS_TYPE(digtube);
/** Gets the type of a digit tubes */
#define RTGUI_DIGTUBE_TYPE (RTGUI_TYPE(digtube))
/** Casts the object to an rtgui_digtube */
#define RTGUI_DIGTUBE(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_DIGTUBE_TYPE, rtgui_digtube_t))
/** Checks if the object is an rtgui_digtube */
#define RTGUI_IS_DIGTUBE(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_DIGTUBE_TYPE))
/*
* the digit tube widget
*/
struct rtgui_digtube
{
struct rtgui_widget parent;
struct rtgui_digitfont digitfont;
/* number of tubes */
rt_uint8_t tube_count;
rt_uint8_t tube_style;
rt_uint8_t digit_hight;
rt_uint8_t digit_width;
rt_uint8_t digit_space;
rtgui_color_t digit_bc;
void * value;
};
typedef struct rtgui_digtube rtgui_digtube_t;
rtgui_digtube_t *rtgui_digtube_create( struct rtgui_digitfont * digitfont, int count, void * value, int style);
void rtgui_digtube_destroy(rtgui_digtube_t *digtube);
rt_bool_t rtgui_digtube_event_handler(struct rtgui_object *object, struct rtgui_event *event);
#define RTGUI_DIGTUBE_DEFAULT_BC RTGUI_RGB(0, 0, 0)
#define RTGUI_DIGTUBE_DEFAULT_FC RTGUI_RGB(0xFF, 0, 0)
#define RTGUI_DIGTUBE_DEFAULT_DIGIT_BC RTGUI_RGB(100, 100, 100)
#define RTGUI_DIGTUBE_DEFAULT_SPACE 10
#define RTGUI_DIGTUBE_STYLE_NOBACKFONT 0x01
#define RTGUI_DIGTUBE_STYLE_DISHEXNUM 0x02
#define RTGUI_DIGTUBE_STYLE_DISCODES 0x04
//void rtgui_digtube_set_text(rtgui_digtube_t *digtube, const char *text);
//char *rtgui_digtube_get_text(rtgui_digtube_t *digtube);
#endif
\ No newline at end of file
......@@ -72,7 +72,7 @@ void rtgui_menu_set_onmenupop(struct rtgui_menu *menu, rtgui_event_handler_ptr h
void rtgui_menu_set_onmenuhide(struct rtgui_menu *menu, rtgui_event_handler_ptr handler);
void rtgui_menu_pop(struct rtgui_menu *menu, int x, int y);
void rtgui_menu_hiden(struct rtgui_menu *menu);
void rtgui_menu_hide(struct rtgui_menu *menu);
#endif
......@@ -34,6 +34,8 @@ DECLARE_CLASS_TYPE(textbox);
#define RTGUI_TEXTBOX_DEFAULT_WIDTH 80
#define RTGUI_TEXTBOX_DEFAULT_HEIGHT 20
#define RTGUI_TEXTBOX_BORDER_WIDTH 1
#define RTGUI_TEXTBOX_SINGLE 0x00
#define RTGUI_TEXTBOX_MULTI 0x01 /* multiline */
#define RTGUI_TEXTBOX_MASK 0x02 /* ciphertext */
......@@ -52,10 +54,13 @@ struct rtgui_textbox
rt_uint32_t flag;
/* current line and position */
rt_uint16_t line, line_begin, position, line_length;
rt_uint16_t line, line_begin, position;
/** maximum chars a line could hold excluding the NULL byte */
rt_uint16_t line_length;
rt_uint16_t dis_length; /*may be display length.*/
rt_uint16_t first_pos;
char mask_char;
/** a NULL terminated string that the textbox is holding */
char *text;
rt_size_t font_width;
......@@ -77,7 +82,20 @@ void rtgui_textbox_set_value(struct rtgui_textbox *box, const char *text);
const char *rtgui_textbox_get_value(struct rtgui_textbox *box);
void rtgui_textbox_set_mask_char(rtgui_textbox_t *box, const char ch);
char rtgui_textbox_get_mask_char(rtgui_textbox_t *box);
void rtgui_textbox_set_line_length(struct rtgui_textbox *box, rt_size_t length);
/** set the maximum chars a line could hold excluding the NULL byte
*
* It will truncate the current line if the length is smaller than the chars
* the box is currently holding. But the box->text is guaranteed to be NULL
* terminated anyway.
*
* @param box the text box it operate on
* @param length the new line length. It should be greater than 0.
*
* @return -RT_ERROR on invalid length; -RT_ENOMEM if there is no enough memory
* to allocate the new buffer. On returning -RT_ENOMEM, the original text would
* remain unchanged.
*/
rt_err_t 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);
......
......@@ -62,139 +62,138 @@ extern "C" {
#define RTGUI_WIDGET_DC_SET_UNVISIBLE(w) RTGUI_WIDGET_FLAG(w) &= ~RTGUI_WIDGET_FLAG_DC_VISIBLE
#define RTGUI_WIDGET_DC(w) ((struct rtgui_dc*)&((w)->dc_type))
DECLARE_CLASS_TYPE(widget);
DECLARE_CLASS_TYPE(widget);
/** Gets the type of a widget */
/** Gets the type of a widget */
#define RTGUI_WIDGET_TYPE (RTGUI_TYPE(widget))
/** Casts the object to a rtgui_widget */
/** Casts the object to a rtgui_widget */
#define RTGUI_WIDGET(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_WIDGET_TYPE, rtgui_widget_t))
/** Check if the object is a rtgui_widget */
/** Check if the object is a rtgui_widget */
#define RTGUI_IS_WIDGET(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_WIDGET_TYPE))
/*
* the base widget object
*/
struct rtgui_widget
{
/* inherit from rtgui_object */
struct rtgui_object object;
/* the widget that contains this widget */
struct rtgui_widget *parent;
/* the window that contains this widget */
struct rtgui_win *toplevel;
/* the widget children and sibling */
rtgui_list_t sibling;
/* widget flag */
rt_int32_t flag;
/* hardware device context */
rt_uint32_t dc_type;
const struct rtgui_dc_engine *dc_engine;
/* the graphic context of widget */
rtgui_gc_t gc;
/* the widget extent */
rtgui_rect_t extent;
/* minimal width and height of widget */
rt_int16_t mini_width, mini_height;
/* widget align */
rt_int32_t align;
rt_uint16_t border;
rt_uint16_t border_style;
/* the rect clip */
rtgui_region_t clip;
/* call back */
rt_bool_t (*on_focus_in)(struct rtgui_object *widget, struct rtgui_event *event);
rt_bool_t (*on_focus_out)(struct rtgui_object *widget, struct rtgui_event *event);
/*
* the base widget object
*/
struct rtgui_widget
{
/* inherit from rtgui_object */
struct rtgui_object object;
/* the widget that contains this widget */
struct rtgui_widget *parent;
/* the window that contains this widget */
struct rtgui_win *toplevel;
/* the widget children and sibling */
rtgui_list_t sibling;
/* widget flag */
rt_int32_t flag;
/* hardware device context */
rt_uint32_t dc_type;
const struct rtgui_dc_engine *dc_engine;
/* the graphic context of widget */
rtgui_gc_t gc;
/* the widget extent */
rtgui_rect_t extent;
/* minimal width and height of widget */
rt_int16_t min_width, min_height;
/* widget align */
rt_int32_t align;
rt_uint16_t border;
rt_uint16_t border_style;
/* the rect clip */
rtgui_region_t clip;
/* call back */
rt_bool_t (*on_focus_in)(struct rtgui_object *widget, struct rtgui_event *event);
rt_bool_t (*on_focus_out)(struct rtgui_object *widget, struct rtgui_event *event);
#ifndef RTGUI_USING_SMALL_SIZE
rt_bool_t (*on_draw)(struct rtgui_object *widget, struct rtgui_event *event);
rt_bool_t (*on_mouseclick)(struct rtgui_object *widget, struct rtgui_event *event);
rt_bool_t (*on_key)(struct rtgui_object *widget, struct rtgui_event *event);
rt_bool_t (*on_size)(struct rtgui_object *widget, struct rtgui_event *event);
rt_bool_t (*on_command)(struct rtgui_object *widget, struct rtgui_event *event);
rt_bool_t (*on_draw)(struct rtgui_object *widget, struct rtgui_event *event);
rt_bool_t (*on_mouseclick)(struct rtgui_object *widget, struct rtgui_event *event);
rt_bool_t (*on_key)(struct rtgui_object *widget, struct rtgui_event *event);
rt_bool_t (*on_size)(struct rtgui_object *widget, struct rtgui_event *event);
rt_bool_t (*on_command)(struct rtgui_object *widget, struct rtgui_event *event);
#endif
/* user private data */
rt_uint32_t user_data;
};
typedef struct rtgui_widget rtgui_widget_t;
/* user private data */
rt_uint32_t user_data;
};
typedef struct rtgui_widget rtgui_widget_t;
rtgui_widget_t *rtgui_widget_create(rtgui_type_t *widget_type);
void rtgui_widget_destroy(rtgui_widget_t *widget);
rtgui_widget_t *rtgui_widget_create(rtgui_type_t *widget_type);
void rtgui_widget_destroy(rtgui_widget_t *widget);
rt_bool_t rtgui_widget_event_handler(struct rtgui_object *object, rtgui_event_t *event);
rt_bool_t rtgui_widget_event_handler(struct rtgui_object *object, rtgui_event_t *event);
/* focus and unfocus */
void rtgui_widget_focus(rtgui_widget_t *widget);
void rtgui_widget_unfocus(rtgui_widget_t *widget);
/* focus and unfocus */
void rtgui_widget_focus(rtgui_widget_t *widget);
void rtgui_widget_unfocus(rtgui_widget_t *widget);
/* event handler for each command */
void rtgui_widget_set_onfocus(rtgui_widget_t *widget, rtgui_event_handler_ptr handler);
void rtgui_widget_set_onunfocus(rtgui_widget_t *widget, rtgui_event_handler_ptr handler);
/* event handler for each command */
void rtgui_widget_set_onfocus(rtgui_widget_t *widget, rtgui_event_handler_ptr handler);
void rtgui_widget_set_onunfocus(rtgui_widget_t *widget, rtgui_event_handler_ptr handler);
#ifndef RTGUI_USING_SMALL_SIZE
void rtgui_widget_set_ondraw(rtgui_widget_t *widget, rtgui_event_handler_ptr handler);
void rtgui_widget_set_onmouseclick(rtgui_widget_t *widget, rtgui_event_handler_ptr handler);
void rtgui_widget_set_onkey(rtgui_widget_t *widget, rtgui_event_handler_ptr handler);
void rtgui_widget_set_onsize(rtgui_widget_t *widget, rtgui_event_handler_ptr handler);
void rtgui_widget_set_oncommand(rtgui_widget_t *widget, rtgui_event_handler_ptr handler);
void rtgui_widget_set_ondraw(rtgui_widget_t *widget, rtgui_event_handler_ptr handler);
void rtgui_widget_set_onmouseclick(rtgui_widget_t *widget, rtgui_event_handler_ptr handler);
void rtgui_widget_set_onkey(rtgui_widget_t *widget, rtgui_event_handler_ptr handler);
void rtgui_widget_set_onsize(rtgui_widget_t *widget, rtgui_event_handler_ptr handler);
void rtgui_widget_set_oncommand(rtgui_widget_t *widget, rtgui_event_handler_ptr handler);
#endif
/* get and set rect of widget */
void rtgui_widget_get_rect(rtgui_widget_t *widget, rtgui_rect_t *rect);
void rtgui_widget_set_border(rtgui_widget_t *widget, rt_uint32_t style);
void rtgui_widget_set_rect(rtgui_widget_t *widget, const rtgui_rect_t *rect);
void rtgui_widget_set_rectangle(rtgui_widget_t *widget, int x, int y, int width, int height);
void rtgui_widget_get_extent(rtgui_widget_t *widget, rtgui_rect_t *rect);
/* get and set rect of widget */
void rtgui_widget_get_rect(rtgui_widget_t *widget, rtgui_rect_t *rect);
void rtgui_widget_set_border(rtgui_widget_t *widget, rt_uint32_t style);
void rtgui_widget_set_rect(rtgui_widget_t *widget, const rtgui_rect_t *rect);
void rtgui_widget_set_rectangle(rtgui_widget_t *widget, int x, int y, int width, int height);
void rtgui_widget_get_extent(rtgui_widget_t *widget, rtgui_rect_t *rect);
#ifndef RTGUI_USING_SMALL_SIZE
void rtgui_widget_set_miniwidth(rtgui_widget_t *widget, int width);
void rtgui_widget_set_miniheight(rtgui_widget_t *widget, int height);
#endif
void rtgui_widget_set_minsize(rtgui_widget_t *widget, int width, int height);
void rtgui_widget_set_minwidth(rtgui_widget_t *widget, int width);
void rtgui_widget_set_minheight(rtgui_widget_t *widget, int height);
void rtgui_widget_set_parent(rtgui_widget_t *widget, rtgui_widget_t *parent);
void rtgui_widget_set_parent(rtgui_widget_t *widget, rtgui_widget_t *parent);
/* get the physical position of a logic point on widget */
void rtgui_widget_point_to_device(rtgui_widget_t *widget, rtgui_point_t *point);
/* get the physical position of a logic rect on widget */
void rtgui_widget_rect_to_device(rtgui_widget_t *widget, rtgui_rect_t *rect);
/* get the physical position of a logic point on widget */
void rtgui_widget_point_to_device(rtgui_widget_t *widget, rtgui_point_t *point);
/* get the physical position of a logic rect on widget */
void rtgui_widget_rect_to_device(rtgui_widget_t *widget, rtgui_rect_t *rect);
/* get the logic position of a physical point on widget */
void rtgui_widget_point_to_logic(rtgui_widget_t *widget, rtgui_point_t *point);
/* get the logic position of a physical rect on widget */
void rtgui_widget_rect_to_logic(rtgui_widget_t *widget, rtgui_rect_t *rect);
/* get the logic position of a physical point on widget */
void rtgui_widget_point_to_logic(rtgui_widget_t *widget, rtgui_point_t *point);
/* get the logic position of a physical rect on widget */
void rtgui_widget_rect_to_logic(rtgui_widget_t *widget, rtgui_rect_t *rect);
/* move widget and its children to a logic point */
void rtgui_widget_move_to_logic(rtgui_widget_t *widget, int dx, int dy);
/* move widget and its children to a logic point */
void rtgui_widget_move_to_logic(rtgui_widget_t *widget, int dx, int dy);
/* update the clip info of widget */
void rtgui_widget_update_clip(rtgui_widget_t *widget);
/* update the clip info of widget */
void rtgui_widget_update_clip(rtgui_widget_t *widget);
/* get the toplevel widget of widget */
struct rtgui_win *rtgui_widget_get_toplevel(rtgui_widget_t *widget);
rt_bool_t rtgui_widget_onupdate_toplvl(struct rtgui_object *object, struct rtgui_event *event);
/* get the toplevel widget of widget */
struct rtgui_win *rtgui_widget_get_toplevel(rtgui_widget_t *widget);
rt_bool_t rtgui_widget_onupdate_toplvl(struct rtgui_object *object, struct rtgui_event *event);
void rtgui_widget_show(rtgui_widget_t *widget);
rt_bool_t rtgui_widget_onshow(struct rtgui_object *object, struct rtgui_event *event);
void rtgui_widget_hide(rtgui_widget_t *widget);
rt_bool_t rtgui_widget_onhide(struct rtgui_object *object, struct rtgui_event *event);
void rtgui_widget_update(rtgui_widget_t *widget);
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 */
rtgui_color_t rtgui_widget_get_parent_foreground(rtgui_widget_t *widget);
rtgui_color_t rtgui_widget_get_parent_background(rtgui_widget_t *widget);
/* get parent color */
rtgui_color_t rtgui_widget_get_parent_foreground(rtgui_widget_t *widget);
rtgui_color_t rtgui_widget_get_parent_background(rtgui_widget_t *widget);
/* get the next sibling of widget */
rtgui_widget_t *rtgui_widget_get_next_sibling(rtgui_widget_t *widget);
/* get the prev sibling of widget */
rtgui_widget_t *rtgui_widget_get_prev_sibling(rtgui_widget_t *widget);
/* get the next sibling of widget */
rtgui_widget_t *rtgui_widget_get_next_sibling(rtgui_widget_t *widget);
/* get the prev sibling of widget */
rtgui_widget_t *rtgui_widget_get_prev_sibling(rtgui_widget_t *widget);
/* dump widget information */
void rtgui_widget_dump(rtgui_widget_t *widget);
/* dump widget information */
void rtgui_widget_dump(rtgui_widget_t *widget);
#ifdef __cplusplus
}
......
......@@ -130,7 +130,7 @@ void rtgui_win_destroy(rtgui_win_t *win);
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_hide(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);
......
......@@ -41,6 +41,7 @@ rt_err_t rtgui_graphic_set_device(rt_device_t device)
{
rt_err_t result;
struct rt_device_graphic_info info;
struct rtgui_graphic_ext_ops *ext_ops;
/* get framebuffer address */
result = rt_device_control(device, RTGRAPHIC_CTRL_GET_INFO, &info);
......@@ -59,6 +60,13 @@ rt_err_t rtgui_graphic_set_device(rt_device_t device)
_driver.pitch = _driver.width * _driver.bits_per_pixel / 8;
_driver.framebuffer = info.framebuffer;
/* get graphic extension operations */
result = rt_device_control(device, RTGRAPHIC_CTRL_GET_EXT, &ext_ops);
if (result == RT_EOK)
{
_driver.ext_ops = ext_ops;
}
if (info.framebuffer != RT_NULL)
{
/* is a frame buffer device */
......@@ -70,6 +78,11 @@ rt_err_t rtgui_graphic_set_device(rt_device_t device)
_driver.ops = rtgui_pixel_device_get_ops(_driver.pixel_format);
}
#ifdef RTGUI_USING_HW_CURSOR
/* set default cursor image */
rtgui_cursor_set_image(RTGUI_CURSOR_ARROW);
#endif
return RT_EOK;
}
RTM_EXPORT(rtgui_graphic_set_device);
......@@ -100,3 +113,27 @@ rt_uint8_t *rtgui_graphic_driver_get_default_framebuffer(void)
}
RTM_EXPORT(rtgui_graphic_driver_get_default_framebuffer);
#ifdef RTGUI_USING_HW_CURSOR
void rtgui_cursor_set_position(rt_uint16_t x, rt_uint16_t y)
{
rt_uint32_t value;
if (_driver.device != RT_NULL)
{
value = (x << 16 | y);
rt_device_control(_driver.device, RT_DEVICE_CTRL_CURSOR_SET_POSITION, &value);
}
}
void rtgui_cursor_set_image(enum rtgui_cursor_type type)
{
rt_uint32_t value;
if (_driver.device != RT_NULL)
{
value = type;
rt_device_control(_driver.device, RT_DEVICE_CTRL_CURSOR_SET_TYPE, &value);
}
};
#endif
......@@ -255,6 +255,10 @@ void rtgui_mouse_moveto(int x, int y)
rtgui_mouse_show_cursor();
#endif
}
#ifdef RTGUI_USING_HW_CURSOR
rtgui_cursor_set_position(_rtgui_cursor->cx, _rtgui_cursor->cy);
#endif
}
#ifdef RTGUI_USING_MOUSE_CURSOR
......@@ -262,6 +266,17 @@ void rtgui_mouse_moveto(int x, int y)
#endif
}
void rtgui_mouse_set_position(int x, int y)
{
/* move current cursor */
_rtgui_cursor->cx = x;
_rtgui_cursor->cy = y;
#ifdef RTGUI_USING_HW_CURSOR
rtgui_cursor_set_position(_rtgui_cursor->cx, _rtgui_cursor->cy);
#endif
}
#ifdef RTGUI_USING_MOUSE_CURSOR
void rtgui_mouse_set_cursor_enable(rt_bool_t enable)
{
......
......@@ -31,6 +31,8 @@ typedef struct rtgui_mouse_monitor rtgui_mouse_monitor_t;
void rtgui_mouse_init(void);
void rtgui_mouse_fini(void);
void rtgui_mouse_moveto(int x, int y);
/* set cursor position */
void rtgui_mouse_set_position(int x, int y);
void rtgui_mouse_set_cursor_enable(rt_bool_t enable);
void rtgui_mouse_set_cursor(rtgui_image_t *cursor);
......
......@@ -22,9 +22,7 @@
#include "mouse.h"
#include "topwin.h"
static struct rt_thread *rtgui_server_tid;
static struct rtgui_app *rtgui_server_application = RT_NULL;
static struct rtgui_app *rtgui_server_app = RT_NULL;
static struct rtgui_app *rtgui_wm_application = RT_NULL;
void rtgui_server_handle_update(struct rtgui_event_update_end *event)
......@@ -57,6 +55,9 @@ void rtgui_server_handle_mouse_btn(struct rtgui_event_mouse *event)
/* re-init to server thread */
RTGUI_EVENT_MOUSE_BUTTON_INIT(event);
/* set cursor position */
rtgui_mouse_set_position(event->x, event->y);
#ifdef RTGUI_USING_WINMOVE
if (rtgui_winrect_is_moved() &&
event->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_UP))
......@@ -87,7 +88,7 @@ void rtgui_server_handle_mouse_btn(struct rtgui_event_mouse *event)
}
/* send to client thread */
rtgui_send(topwin->tid, &(ewin.parent), sizeof(ewin));
rtgui_send(topwin->app, &(ewin.parent), sizeof(ewin));
return;
}
......@@ -100,9 +101,10 @@ void rtgui_server_handle_mouse_btn(struct rtgui_event_mouse *event)
{
event->wid = wnd->wid;
if (rtgui_topwin_get_focus() != wnd)
/* only raise window if the button is pressed down */
if (event->button & RTGUI_MOUSE_BUTTON_DOWN
&& rtgui_topwin_get_focus() != wnd)
{
/* raise this window */
rtgui_topwin_activate_topwin(wnd);
}
......@@ -114,7 +116,7 @@ void rtgui_server_handle_mouse_btn(struct rtgui_event_mouse *event)
else
{
/* send mouse event to thread */
rtgui_send(wnd->tid, (struct rtgui_event *)event, sizeof(struct rtgui_event_mouse));
rtgui_send(wnd->app, (struct rtgui_event *)event, sizeof(struct rtgui_event_mouse));
}
return ;
}
......@@ -146,7 +148,7 @@ void rtgui_server_handle_mouse_motion(struct rtgui_event_mouse *event)
{
event->wid = last_monitor_topwin->wid;
/* send mouse motion event */
rtgui_send(last_monitor_topwin->tid, &(event->parent), sizeof(struct rtgui_event_mouse));
rtgui_send(last_monitor_topwin->app, &(event->parent), sizeof(struct rtgui_event_mouse));
}
if (last_monitor_topwin != win)
......@@ -157,7 +159,7 @@ void rtgui_server_handle_mouse_motion(struct rtgui_event_mouse *event)
event->wid = last_monitor_topwin->wid;
/* send mouse motion event */
rtgui_send(last_monitor_topwin->tid, &(event->parent), sizeof(struct rtgui_event_mouse));
rtgui_send(last_monitor_topwin->app, &(event->parent), sizeof(struct rtgui_event_mouse));
}
}
......@@ -183,7 +185,7 @@ void rtgui_server_handle_kbd(struct rtgui_event_kbd *event)
event->wid = wnd->wid;
/* send keyboard event to thread */
rtgui_send(wnd->tid, (struct rtgui_event *)event, sizeof(struct rtgui_event_kbd));
rtgui_send(wnd->app, (struct rtgui_event *)event, sizeof(struct rtgui_event_kbd));
return;
}
......@@ -207,7 +209,7 @@ static rt_bool_t rtgui_server_event_handler(struct rtgui_object *object,
if (rtgui_wm_application != RT_NULL)
{
/* forward event to wm application */
rtgui_send(rtgui_wm_application->tid, event, sizeof(struct rtgui_event_application));
rtgui_send(rtgui_wm_application, event, sizeof(struct rtgui_event_application));
}
else
{
......@@ -349,12 +351,12 @@ static void rtgui_server_entry(void *parameter)
#endif
/* create rtgui server application */
rtgui_server_application = rtgui_app_create(rtgui_server_tid,
"rtgui");
if (rtgui_server_application == RT_NULL)
rtgui_server_app = rtgui_app_create("rtgui");
rt_kprintf("RTGUI: create server: %p", rtgui_server_app);
if (rtgui_server_app == RT_NULL)
return;
rtgui_object_set_event_handler(RTGUI_OBJECT(rtgui_server_application),
rtgui_object_set_event_handler(RTGUI_OBJECT(rtgui_server_app),
rtgui_server_event_handler);
/* init mouse and show */
rtgui_mouse_init();
......@@ -362,24 +364,24 @@ static void rtgui_server_entry(void *parameter)
rtgui_mouse_show_cursor();
#endif
rtgui_app_run(rtgui_server_application);
rtgui_app_run(rtgui_server_app);
rtgui_app_destroy(rtgui_server_application);
rtgui_server_application = RT_NULL;
rtgui_app_destroy(rtgui_server_app);
rtgui_server_app = RT_NULL;
}
void rtgui_server_post_event(struct rtgui_event *event, rt_size_t size)
{
if (rtgui_server_tid != RT_NULL)
rtgui_send(rtgui_server_tid, event, size);
if (rtgui_server_app != RT_NULL)
rtgui_send(rtgui_server_app, event, size);
else
rt_kprintf("post when server is not running\n");
}
rt_err_t rtgui_server_post_event_sync(struct rtgui_event *event, rt_size_t size)
{
if (rtgui_server_tid != RT_NULL)
return rtgui_send_sync(rtgui_server_tid, event, size);
if (rtgui_server_app != RT_NULL)
return rtgui_send_sync(rtgui_server_app, event, size);
else
{
rt_kprintf("post when server is not running\n");
......@@ -387,18 +389,27 @@ rt_err_t rtgui_server_post_event_sync(struct rtgui_event *event, rt_size_t size)
}
}
struct rtgui_app* rtgui_get_server(void)
{
rt_thread_t tid = rt_thread_find("rtgui");
if (tid == RT_NULL)
return RT_NULL;
return (struct rtgui_app*)tid->user_data;
}
RTM_EXPORT(rtgui_get_server);
void rtgui_server_init(void)
{
if (rtgui_server_tid != RT_NULL)
return;
rt_thread_t tid;
rtgui_server_tid = rt_thread_create("rtgui",
rtgui_server_entry, RT_NULL,
RTGUI_SVR_THREAD_STACK_SIZE,
RTGUI_SVR_THREAD_PRIORITY,
RTGUI_SVR_THREAD_TIMESLICE);
tid = rt_thread_create("rtgui",
rtgui_server_entry, RT_NULL,
RTGUI_SVR_THREAD_STACK_SIZE,
RTGUI_SVR_THREAD_PRIORITY,
RTGUI_SVR_THREAD_TIMESLICE);
/* start rtgui server thread */
if (rtgui_server_tid != RT_NULL)
rt_thread_startup(rtgui_server_tid);
if (tid != RT_NULL)
rt_thread_startup(tid);
}
......@@ -102,7 +102,7 @@ rt_err_t rtgui_topwin_add(struct rtgui_event_win_create *event)
#else
topwin->extent = event->extent;
#endif
topwin->tid = event->parent.sender;
topwin->app = event->parent.sender;
if (event->parent_window == RT_NULL)
{
......@@ -337,7 +337,7 @@ static void _rtgui_topwin_only_activate(struct rtgui_topwin *topwin)
topwin->flag |= WINTITLE_ACTIVATE;
event.wid = topwin->wid;
rtgui_send(topwin->tid, &(event.parent), sizeof(struct rtgui_event_win));
rtgui_send(topwin->app, &(event.parent), sizeof(struct rtgui_event_win));
/* redraw title */
if (topwin->title != RT_NULL)
......@@ -366,11 +366,11 @@ static void _rtgui_topwin_deactivate(struct rtgui_topwin *topwin)
struct rtgui_event_win event;
RT_ASSERT(topwin != RT_NULL);
RT_ASSERT(topwin->tid != RT_NULL);
RT_ASSERT(topwin->app != RT_NULL);
RTGUI_EVENT_WIN_DEACTIVATE_INIT(&event);
event.wid = topwin->wid;
rtgui_send(topwin->tid,
rtgui_send(topwin->app,
&event.parent, sizeof(struct rtgui_event_win));
topwin->flag &= ~WINTITLE_ACTIVATE;
......@@ -495,7 +495,7 @@ static void _rtgui_topwin_draw_tree(struct rtgui_topwin *topwin, struct rtgui_ev
}
epaint->wid = topwin->wid;
rtgui_send(topwin->tid, &(epaint->parent), sizeof(struct rtgui_event_paint));
rtgui_send(topwin->app, &(epaint->parent), sizeof(struct rtgui_event_paint));
rtgui_dlist_foreach(node, &topwin->child_list, prev)
{
......@@ -748,7 +748,7 @@ rt_err_t rtgui_topwin_move(struct rtgui_event_win_move *event)
struct rtgui_event_paint epaint;
RTGUI_EVENT_PAINT_INIT(&epaint);
epaint.wid = topwin->wid;
rtgui_send(topwin->tid, &(epaint.parent), sizeof(epaint));
rtgui_send(topwin->app, &(epaint.parent), sizeof(epaint));
}
return RT_EOK;
......@@ -945,7 +945,7 @@ static void rtgui_topwin_update_clip(void)
/* send clip event to destination window */
eclip.wid = top->wid;
rtgui_send(top->tid, &(eclip.parent), sizeof(struct rtgui_event_clip_info));
rtgui_send(top->app, &(eclip.parent), sizeof(struct rtgui_event_clip_info));
/* move to next sibling tree */
if (top->parent == RT_NULL)
......@@ -991,7 +991,7 @@ static void _rtgui_topwin_redraw_tree(struct rtgui_dlist_node *list,
if (rtgui_rect_is_intersect(rect, &(topwin->extent)) == RT_EOK)
{
epaint->wid = topwin->wid;
rtgui_send(topwin->tid, &(epaint->parent), sizeof(*epaint));
rtgui_send(topwin->app, &(epaint->parent), sizeof(*epaint));
/* draw title */
if (topwin->title != RT_NULL)
......@@ -1059,7 +1059,7 @@ void rtgui_topwin_title_onmouse(struct rtgui_topwin *win, struct rtgui_event_mou
if (rtgui_rect_contains_point(&win->extent, event->x, event->y) == RT_EOK)
{
/* send mouse event to thread */
rtgui_send(win->tid, &(event->parent), sizeof(struct rtgui_event_mouse));
rtgui_send(win->app, &(event->parent), sizeof(struct rtgui_event_mouse));
return;
}
......@@ -1098,7 +1098,7 @@ void rtgui_topwin_title_onmouse(struct rtgui_topwin *win, struct rtgui_event_mou
/* send close event to window */
RTGUI_EVENT_WIN_CLOSE_INIT(&event);
event.wid = win->wid;
rtgui_send(win->tid, &(event.parent), sizeof(struct rtgui_event_win));
rtgui_send(win->app, &(event.parent), sizeof(struct rtgui_event_win));
}
}
}
......
perfect_hash.py
Ilan Schnell <ilanschnell@gmail.com>, 2008
Generate a minimal perfect hash function for the keys in a file,
desired hash values may be specified within this file as well.
A given code template is filled with parameters, such that the
output is code which implements the hash function.
Templates can easily be constructed for any programming language.
The code is based on an a program A.M. Kuchling wrote:
http://www.amk.ca/python/code/perfect-hash
The algorithm the program uses is described in the paper
'Optimal algorithms for minimal perfect hashing',
Z. J. Czech, G. Havas and B.S. Majewski.
http://citeseer.ist.psu.edu/122364.html
Content:
perfect_hash.py The actual program, try $ ./perfect_hash.py animals.txt
doc HTML and plain text documentation
example1-C An example which shows how to generate a C program
which implements a perfect hash table.
example2-C Another example in C.
example-C++ In this C++ example, a class is used to define the
interface to a static lookup table.
example-PyModule A lookup table in implemented as a C extension module
for Python.
example-Python Some small Python programs which show how to access
some functions and classes in perfect_hash.py directly,
i.e. using perfect_hash has a Python module, rather
than a standalone program.
graph A small program `py2dot' which converts the default python
output code from perfect_hash.py into a .dot-file which
can be used by Graphviz (see http://www.graphviz.org/) to
create a picture of the graph.
run Runs some tests.
# 'animals.txt'
Elephant
Horse
Camel
Python
Dog
Cat
all: doc.html doc.txt
doc.html: doc.in parameters.txt mktable.py
./mktable.py >table.html
markdown doc.in | \
sed -e "s,<h6>table</h6>,m4_include(\`table.html')," | \
m4 -P >doc.html
rm table.html
doc.txt: doc.in parameters.txt
sed <doc.in -e "s,###### table,m4_include(\`parameters.txt')," \
-e "s,\`\([^\`]*\)\`,'\1',g" | m4 -P >doc.txt
clean:
rm doc.html doc.txt
<h2>Generic Perfect Hash Generator</h2>
<p><em>Ilan Schnell, 2008</em>
</p>
<p>perfect_hash.py provides a perfect hash generator which is not language
specific. That is, the generator can output a perfect hash function for
a given set of keys in any programming language, this is achieved by
filling a given code template.
</p>
<h3>Acknowledgments:</h3>
<p>This code is derived from A. M. Kuchling's
<a href="http://www.amk.ca/python/code/perfect-hash">Perfect Minimal Hash Generator</a>.
</p>
<h3>Introduction:</h3>
<p>A perfect hash function of a certain set S of keys is a hash function
which maps all keys in S to different numbers.
That means that for the set S,
the hash function is collision-free, or perfect.
Further, a perfect hash function is called minimal when it maps n keys
to n <em>consecutive</em> integers, usually in the range from 0 to n-1.
</p>
<p>After coming across A. M. Kuchling's Perfect Minimal Hash Generator,
I decided to write a general tool for generating perfect hashes.
It is general in the sense that it can produce perfect hash functions
for almost any programming language.
A given code template is filled with parameters,
such that the output is code which implements the hash function.
</p>
<p>The algorithm the program uses is described in the paper
<a href="http://citeseer.ist.psu.edu/122364.html">&quot;Optimal algorithms for minimal perfect hashing&quot;</a>,
Z. J. Czech, G. Havas and B.S. Majewski.
</p>
<p>I tried to illustrate the algorithm and explain how it works on
<a href="http://ilan.schnell-web.net/prog/perfect-hash/algo.html">this page</a>.
</p>
<h3>Usage:</h3>
<p>Given a set of keys which are ordinary character string,
the program returns a minimal perfect hash function.
This hash function is returned in the form of Python code by default.
Suppose we have a file with keys:
</p>
<pre><code># 'animals.txt'
Elephant
Horse
Camel
Python
Dog
Cat
</code></pre><p>The exact way this file is parsed can be specified using command line
options, for example it is possible to only read one column from a file
which contains different items in each row.
The program is invoked like this:
</p>
<pre><code># =======================================================================
# ================= Python code for perfect hash function ===============
# =======================================================================
G = [0, 0, 4, 1, 0, 3, 8, 1, 6]
S1 = [5, 0, 0, 6, 1, 0, 4, 7]
S2 = [7, 3, 6, 7, 8, 5, 7, 6]
def hash_f(key, T):
return sum(T[i % 8] * ord(c) for i, c in enumerate(str(key))) % 9
def perfect_hash(key):
return (G[hash_f(key, S1)] + G[hash_f(key, S2)]) % 9
# ============================ Sanity check =============================
K = [&quot;Elephant&quot;, &quot;Horse&quot;, &quot;Camel&quot;, &quot;Python&quot;, &quot;Dog&quot;, &quot;Cat&quot;]
H = [0, 1, 2, 3, 4, 5]
assert len(K) == len(H) == 6
for k, h in zip(K, H):
assert perfect_hash(k) == h
</code></pre><p>The way the program works is by filling a code template with the calculated
parameters. The program can take such a template in form of a file and
fill in the calculated parameters, this allows the generation of perfect
hash function in any programming language. The hash function is kept quite
simple and does not require machine or language specific byte level operations
which might be hard to implement in the target language.
The following parameters are available in the template, and will expand to:
</p>
<table>
<tr><th>string</th><th>expands to</th></tr>
<tr><td><code>$NS</code></td><td>the length of S1 and S2</td></tr>
<tr><td><code>$S1</code></td><td>array of integers S1</td></tr>
<tr><td><code>$S2</code></td><td>array of integers S2</td></tr>
<tr><td><code>$NG</code></td><td>length of array G</td></tr>
<tr><td><code>$G</code></td><td>array of integers G</td></tr>
<tr><td><code>$NK</code></td><td>the number of keys, i.e. length of array K and H</td></tr>
<tr><td><code>$K</code></td><td>array with the quoted keys</td></tr>
<tr><td><code>$H</code></td><td>array of integer hash values</td></tr>
<tr><td><code>$$</code></td><td><code>$</code> (a literal dollar sign)</td></tr>
</table>
<p>A literal <code>$</code> is escaped as <code>$$</code>. Since the syntax for arrays is not the
same in all programming languages, some specifics can be adjusted using
command line options.
The section of the built-in template which creates the actual hash function
is:
</p>
<pre><code>G = [$G]
S1 = [$S1]
S2 = [$S2]
def hash_f(key, T):
return sum(T[i % $NS] * ord(c) for i, c in enumerate(str(key))) % $NG
def perfect_hash(key):
return (G[hash_f(key, S1)] + G[hash_f(key, S2)]) % $NG
</code></pre><p>Using code templates, makes this program very flexible. The package comes
with several complete examples for C and C++. There are many choices one
faces when implementing a static hash table: do the parameter lists go into
a separate header file, should the API for the table only contain the hash
values, but not the objects being mapped, and so on.
All these various choices are possible because of the template is simply
filled with the parameters, no matter what else is inside the template.
</p>
<p>Another possible use the program is as a python module. The functions and
classes in <code>perfect_hash.py</code> are documented and have clean interfaces.
The folder <code>example-Python</code> has examples which shows how the module
can be used directly in this way.
</p>
<h3>Requirement:</h3>
<p>Python 2.5
</p>
Generic Perfect Hash Generator
------------------------------
*Ilan Schnell, 2008*
perfect_hash.py provides a perfect hash generator which is not language
specific. That is, the generator can output a perfect hash function for
a given set of keys in any programming language, this is achieved by
filling a given code template.
### Acknowledgments:
This code is derived from A. M. Kuchling's
[Perfect Minimal Hash Generator](http://www.amk.ca/python/code/perfect-hash).
### Introduction:
A perfect hash function of a certain set S of keys is a hash function
which maps all keys in S to different numbers.
That means that for the set S,
the hash function is collision-free, or perfect.
Further, a perfect hash function is called minimal when it maps n keys
to n *consecutive* integers, usually in the range from 0 to n-1.
After coming across A. M. Kuchling's Perfect Minimal Hash Generator,
I decided to write a general tool for generating perfect hashes.
It is general in the sense that it can produce perfect hash functions
for almost any programming language.
A given code template is filled with parameters,
such that the output is code which implements the hash function.
The algorithm the program uses is described in the paper
["Optimal algorithms for minimal perfect hashing"]
(http://citeseer.ist.psu.edu/122364.html),
Z. J. Czech, G. Havas and B.S. Majewski.
I tried to illustrate the algorithm and explain how it works on
[this page](http://ilan.schnell-web.net/prog/perfect-hash/algo.html).
### Usage:
Given a set of keys which are ordinary character string,
the program returns a minimal perfect hash function.
This hash function is returned in the form of Python code by default.
Suppose we have a file with keys:
# 'animals.txt'
Elephant
Horse
Camel
Python
Dog
Cat
The exact way this file is parsed can be specified using command line
options, for example it is possible to only read one column from a file
which contains different items in each row.
The program is invoked like this:
# =======================================================================
# ================= Python code for perfect hash function ===============
# =======================================================================
G = [0, 0, 4, 1, 0, 3, 8, 1, 6]
S1 = [5, 0, 0, 6, 1, 0, 4, 7]
S2 = [7, 3, 6, 7, 8, 5, 7, 6]
def hash_f(key, T):
return sum(T[i % 8] * ord(c) for i, c in enumerate(str(key))) % 9
def perfect_hash(key):
return (G[hash_f(key, S1)] + G[hash_f(key, S2)]) % 9
# ============================ Sanity check =============================
K = ["Elephant", "Horse", "Camel", "Python", "Dog", "Cat"]
H = [0, 1, 2, 3, 4, 5]
assert len(K) == len(H) == 6
for k, h in zip(K, H):
assert perfect_hash(k) == h
The way the program works is by filling a code template with the calculated
parameters. The program can take such a template in form of a file and
fill in the calculated parameters, this allows the generation of perfect
hash function in any programming language. The hash function is kept quite
simple and does not require machine or language specific byte level operations
which might be hard to implement in the target language.
The following parameters are available in the template, and will expand to:
###### table
A literal `$` is escaped as `$$`. Since the syntax for arrays is not the
same in all programming languages, some specifics can be adjusted using
command line options.
The section of the built-in template which creates the actual hash function
is:
G = [$G]
S1 = [$S1]
S2 = [$S2]
def hash_f(key, T):
return sum(T[i % $NS] * ord(c) for i, c in enumerate(str(key))) % $NG
def perfect_hash(key):
return (G[hash_f(key, S1)] + G[hash_f(key, S2)]) % $NG
Using code templates, makes this program very flexible. The package comes
with several complete examples for C and C++. There are many choices one
faces when implementing a static hash table: do the parameter lists go into
a separate header file, should the API for the table only contain the hash
values, but not the objects being mapped, and so on.
All these various choices are possible because of the template is simply
filled with the parameters, no matter what else is inside the template.
Another possible use the program is as a python module. The functions and
classes in `perfect_hash.py` are documented and have clean interfaces.
The folder `example-Python` has examples which shows how the module
can be used directly in this way.
### Requirement:
Python 2.5
Generic Perfect Hash Generator
------------------------------
*Ilan Schnell, 2008*
perfect_hash.py provides a perfect hash generator which is not language
specific. That is, the generator can output a perfect hash function for
a given set of keys in any programming language, this is achieved by
filling a given code template.
### Acknowledgments:
This code is derived from A. M. Kuchling's
[Perfect Minimal Hash Generator](http://www.amk.ca/python/code/perfect-hash).
### Introduction:
A perfect hash function of a certain set S of keys is a hash function
which maps all keys in S to different numbers.
That means that for the set S,
the hash function is collision-free, or perfect.
Further, a perfect hash function is called minimal when it maps n keys
to n *consecutive* integers, usually in the range from 0 to n-1.
After coming across A. M. Kuchling's Perfect Minimal Hash Generator,
I decided to write a general tool for generating perfect hashes.
It is general in the sense that it can produce perfect hash functions
for almost any programming language.
A given code template is filled with parameters,
such that the output is code which implements the hash function.
The algorithm the program uses is described in the paper
["Optimal algorithms for minimal perfect hashing"]
(http://citeseer.ist.psu.edu/122364.html),
Z. J. Czech, G. Havas and B.S. Majewski.
I tried to illustrate the algorithm and explain how it works on
[this page](http://ilan.schnell-web.net/prog/perfect-hash/algo.html).
### Usage:
Given a set of keys which are ordinary character string,
the program returns a minimal perfect hash function.
This hash function is returned in the form of Python code by default.
Suppose we have a file with keys:
# 'animals.txt'
Elephant
Horse
Camel
Python
Dog
Cat
The exact way this file is parsed can be specified using command line
options, for example it is possible to only read one column from a file
which contains different items in each row.
The program is invoked like this:
# =======================================================================
# ================= Python code for perfect hash function ===============
# =======================================================================
G = [0, 0, 4, 1, 0, 3, 8, 1, 6]
S1 = [5, 0, 0, 6, 1, 0, 4, 7]
S2 = [7, 3, 6, 7, 8, 5, 7, 6]
def hash_f(key, T):
return sum(T[i % 8] * ord(c) for i, c in enumerate(str(key))) % 9
def perfect_hash(key):
return (G[hash_f(key, S1)] + G[hash_f(key, S2)]) % 9
# ============================ Sanity check =============================
K = ["Elephant", "Horse", "Camel", "Python", "Dog", "Cat"]
H = [0, 1, 2, 3, 4, 5]
assert len(K) == len(H) == 6
for k, h in zip(K, H):
assert perfect_hash(k) == h
The way the program works is by filling a code template with the calculated
parameters. The program can take such a template in form of a file and
fill in the calculated parameters, this allows the generation of perfect
hash function in any programming language. The hash function is kept quite
simple and does not require machine or language specific byte level operations
which might be hard to implement in the target language.
The following parameters are available in the template, and will expand to:
string | expands to
--------+--------------------------------
$NS | the length of S1 and S2
$S1 | array of integers S1
$S2 | array of integers S2
$NG | length of array G
$G | array of integers G
$NK | the number of keys, i.e. length of array K and H
$K | array with the quoted keys
$H | array of integer hash values
$$ | $ (a literal dollar sign)
A literal '$' is escaped as '$$'. Since the syntax for arrays is not the
same in all programming languages, some specifics can be adjusted using
command line options.
The section of the built-in template which creates the actual hash function
is:
G = [$G]
S1 = [$S1]
S2 = [$S2]
def hash_f(key, T):
return sum(T[i % $NS] * ord(c) for i, c in enumerate(str(key))) % $NG
def perfect_hash(key):
return (G[hash_f(key, S1)] + G[hash_f(key, S2)]) % $NG
Using code templates, makes this program very flexible. The package comes
with several complete examples for C and C++. There are many choices one
faces when implementing a static hash table: do the parameter lists go into
a separate header file, should the API for the table only contain the hash
values, but not the objects being mapped, and so on.
All these various choices are possible because of the template is simply
filled with the parameters, no matter what else is inside the template.
Another possible use the program is as a python module. The functions and
classes in 'perfect_hash.py' are documented and have clean interfaces.
The folder 'example-Python' has examples which shows how the module
can be used directly in this way.
### Requirement:
Python 2.5
#!/usr/bin/env python
import re
def convert(line, head = False):
pat = re.compile(r'([$]\S*)')
line = pat.sub(r'<code>\1</code>', line)
row = [x.strip() for x in line.split('|')]
fmt = ' <tr><td>%s</td><td>%s</td></tr>'
if head:
fmt = fmt.replace('td', 'th')
print fmt % tuple(row)
f = file('parameters.txt')
print '<table>'
convert(f.readline(), head = True)
f.readline()
for line in f:
convert(line)
print '</table>'
string | expands to
--------+--------------------------------
$NS | the length of S1 and S2
$S1 | array of integers S1
$S2 | array of integers S2
$NG | length of array G
$G | array of integers G
$NK | the number of keys, i.e. length of array K and H
$K | array with the quoted keys
$H | array of integer hash values
$$ | $ (a literal dollar sign)
此差异已折叠。
#!/usr/bin/env python
for line in file('states.dat'):
line = line.strip()
if line.startswith('#'):
continue
row = tuple(entry.strip() for entry in line.split('|'))
print ' { "%s", "%s", %s },' % row
此差异已折叠。
此差异已折叠。
/* Return hash value of abbreviation 'abbr' if found, -1 otherwise */
int has_key (const char *abbr);
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册