mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-10-07 00:59:00 +08:00
sync with rtgui-0.6
This commit is contained in:
Vendored
+124
-124
File diff suppressed because it is too large
Load Diff
Vendored
+1
-6
@@ -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 )
|
||||
|
||||
+5
-3
@@ -1,11 +1,13 @@
|
||||
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')
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
common/font_cmp_hz*.c
|
||||
doc/doxygened/
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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'):
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -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)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
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 的
|
||||
价值。
|
||||
@@ -0,0 +1,81 @@
|
||||
/** @~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,11 +60,11 @@ struct rtgui_graphic_driver
|
||||
|
||||
/* framebuffer address and ops */
|
||||
volatile rt_uint8_t *framebuffer;
|
||||
rt_device_t device;
|
||||
const struct rtgui_graphic_driver_ops *ops;
|
||||
};
|
||||
struct rt_device* device;
|
||||
|
||||
void rtgui_graphic_driver_add(const struct rtgui_graphic_driver *driver);
|
||||
const struct rtgui_graphic_driver_ops *ops;
|
||||
const struct rtgui_graphic_ext_ops *ext_ops;
|
||||
};
|
||||
|
||||
struct rtgui_graphic_driver *rtgui_graphic_driver_get_default(void);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
#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
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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
|
||||
@@ -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);
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
|
||||
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.
|
||||
@@ -0,0 +1,7 @@
|
||||
# 'animals.txt'
|
||||
Elephant
|
||||
Horse
|
||||
Camel
|
||||
Python
|
||||
Dog
|
||||
Cat
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,136 @@
|
||||
|
||||
|
||||
<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">"Optimal algorithms for minimal perfect hashing"</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 = ["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
|
||||
</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>
|
||||
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
|
||||
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
|
||||
@@ -0,0 +1,141 @@
|
||||
|
||||
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
|
||||
@@ -0,0 +1,22 @@
|
||||
#!/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>'
|
||||
@@ -0,0 +1,11 @@
|
||||
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)
|
||||
@@ -0,0 +1,31 @@
|
||||
|
||||
CXX = g++ -Wall
|
||||
|
||||
|
||||
lookup: main.o states-code.o
|
||||
$(CXX) -o $@ $^
|
||||
|
||||
|
||||
main.o: main.cc states-code.hh
|
||||
$(CXX) -c $<
|
||||
|
||||
|
||||
states-code.o: states-code.cc states-code.hh states.dat.h
|
||||
$(CXX) -c $<
|
||||
|
||||
|
||||
states-code.cc: states.dat states-tmpl.cc states-code.hh
|
||||
../perfect_hash.py --splitby '|' --keycol 2 states.dat states-tmpl.cc
|
||||
|
||||
|
||||
states.dat.h: states.dat
|
||||
./mk_header.py >$@
|
||||
|
||||
|
||||
clean:
|
||||
rm lookup *.o states.dat.h states-code.cc
|
||||
|
||||
|
||||
test:
|
||||
./lookup 'NY'
|
||||
./lookup 'QW'
|
||||
@@ -0,0 +1,24 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
#include "states-code.hh"
|
||||
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
if (argc != 2) {
|
||||
printf ("Usage: %s <abbreviation>\n", argv[0]);
|
||||
return 2;
|
||||
}
|
||||
|
||||
string abbr = argv[1];
|
||||
|
||||
State s(abbr);
|
||||
|
||||
cout << "The state of " << s.name ()
|
||||
<< " has a population of " << 1e-6 * s.population () << " million.\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#!/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
|
||||
@@ -0,0 +1,19 @@
|
||||
|
||||
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
|
||||
class State
|
||||
{
|
||||
public:
|
||||
State (const string abbr);
|
||||
|
||||
string name () const { return nam; };
|
||||
int population () const { return pop; };
|
||||
|
||||
private:
|
||||
string nam;
|
||||
int pop;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "states-code.hh"
|
||||
|
||||
static struct {
|
||||
char *name;
|
||||
char *abbr;
|
||||
int pop;
|
||||
} states[$NK] = {
|
||||
#include "states.dat.h"
|
||||
};
|
||||
|
||||
static int T1[] = { $S1 };
|
||||
|
||||
static int T2[] = { $S2 };
|
||||
|
||||
static int G[] = { $G };
|
||||
|
||||
static int hash_g (const char *key, const int *T)
|
||||
{
|
||||
int i, sum = 0;
|
||||
|
||||
for (i = 0; key[i] != '\0'; i++) {
|
||||
sum += T[i] * key[i];
|
||||
sum %= $NG;
|
||||
}
|
||||
return G[sum];
|
||||
}
|
||||
|
||||
static int perfect_hash (const char *key)
|
||||
{
|
||||
if (strlen (key) > $NS)
|
||||
return 0;
|
||||
|
||||
return (hash_g (key, T1) + hash_g (key, T2)) % $NG;
|
||||
}
|
||||
|
||||
State::State (const string abbr)
|
||||
{
|
||||
int hash_value = perfect_hash (abbr.c_str ());
|
||||
|
||||
if (hash_value < $NK &&
|
||||
strcmp(abbr.c_str (), states[hash_value].abbr) == 0)
|
||||
{
|
||||
nam = states[hash_value].name;
|
||||
pop = states[hash_value].pop;
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << "'" << abbr << "' is not an abbreviation for a state\n";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
# Name | Abr | Population
|
||||
#--------------+------+---------
|
||||
Alabama | AL | 4335400
|
||||
Alaska | AK | 611500
|
||||
Arizona | AZ | 4664600
|
||||
Arkansas | AR | 2531000
|
||||
California | CA | 33198100
|
||||
Colorado | CO | 3930700
|
||||
Connecticut | CT | 3271100
|
||||
Delaware | DE | 736900
|
||||
Florida | FL | 15012200
|
||||
Georgia | GA | 7562200
|
||||
Hawaii | HI | 1188400
|
||||
Idaho | ID | 1221500
|
||||
Illinois | IL | 11981700
|
||||
Indiana | IN | 5882500
|
||||
Iowa | IA | 2854700
|
||||
Kansas | KS | 2603200
|
||||
Kentucky | KY | 3921000
|
||||
Louisiana | LA | 4361200
|
||||
Maine | ME | 1243700
|
||||
Maryland | MD | 5122400
|
||||
Massachusetts | MA | 6133500
|
||||
Michigan | MI | 9825100
|
||||
Minnesota | MN | 4704200
|
||||
Mississippi | MS | 2739700
|
||||
Missouri | MO | 5421400
|
||||
Montana | MT | 886400
|
||||
Nebraska | NE | 1661400
|
||||
Nevada | NV | 1828700
|
||||
New Hampshire | NH | 1179100
|
||||
New Jersey | NJ | 8078300
|
||||
New Mexico | NM | 1738700
|
||||
New York | NY | 18197800
|
||||
North Carolina | NC | 7483100
|
||||
North Dakota | ND | 640000
|
||||
Ohio | OH | 11197900
|
||||
Oklahoma | OK | 3328100
|
||||
Oregon | OR | 3266800
|
||||
Pennsylvania | PA | 12044200
|
||||
Rhode Island | RI | 987000
|
||||
South Carolina | SC | 3781800
|
||||
South Dakota | SD | 738500
|
||||
Tennessee | TN | 5398200
|
||||
Texas | TX | 19274300
|
||||
Utah | UT | 2071500
|
||||
Vermont | VT | 590400
|
||||
Virginia | VA | 6768400
|
||||
Washington | WA | 5674900
|
||||
West Virginia | WV | 1813200
|
||||
Wisconsin | WI | 5224500
|
||||
Wyoming | WY | 479500
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
|
||||
CC = gcc -Wall
|
||||
|
||||
|
||||
stations.so: stationsmodule.c stations.dat.h stations-code.h
|
||||
$(CC) -shared -fPIC -I/usr/local/include/python2.5 \
|
||||
-o stations.so stationsmodule.c
|
||||
|
||||
|
||||
stations.dat.h: stations.dat
|
||||
sed <$< >$@ -e 's:\([^,]*\),\([^,]*\): { "\1", "\2" },:'
|
||||
|
||||
|
||||
stations-code.h: stations.dat stations-tmpl.h
|
||||
../perfect_hash.py --trails 2 $^
|
||||
|
||||
|
||||
clean:
|
||||
rm stations-code.h stations.dat.h stations.so
|
||||
|
||||
|
||||
test:
|
||||
python -c "import stations; print stations.locator('DL5BAC')"
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
|
||||
#define NK $NK /* number of keys */
|
||||
#define NG $NG /* number of vertices */
|
||||
#define NS $NS /* elements in T */
|
||||
|
||||
|
||||
int G[] = { $G };
|
||||
|
||||
int T1[] = { $S1 };
|
||||
|
||||
int T2[] = { $S2 };
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,69 @@
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include "stations-code.h"
|
||||
|
||||
static struct {
|
||||
char *callsign;
|
||||
char *locator;
|
||||
} station_list[] = {
|
||||
#include "stations.dat.h"
|
||||
};
|
||||
|
||||
static int hash_f (const char *s, const int *T)
|
||||
{
|
||||
register int i, sum = 0;
|
||||
|
||||
for (i = 0; s[i] != '\0'; i++) {
|
||||
sum += T[i] * s[i];
|
||||
sum %= NG;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
static int perf_hash (const char *k)
|
||||
{
|
||||
if (strlen (k) > NS)
|
||||
return 0;
|
||||
|
||||
return (G[ hash_f(k, T1) ] + G[ hash_f(k, T2)] ) % NG;
|
||||
}
|
||||
|
||||
static int getlocator (char *locator, const char *callsign)
|
||||
{
|
||||
int hashval = perf_hash (callsign);
|
||||
|
||||
if (hashval < NK && strcmp(callsign, station_list[hashval].callsign) == 0) {
|
||||
strcpy (locator, station_list[hashval].locator);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
stations_locator(PyObject *self, PyObject *args)
|
||||
{
|
||||
const char *callsign;
|
||||
char locator[6];
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s", &callsign))
|
||||
return NULL;
|
||||
|
||||
return Py_BuildValue("s", (getlocator (locator, callsign) == 1) ?
|
||||
locator : NULL);
|
||||
}
|
||||
|
||||
static PyMethodDef StationsMethods[] = {
|
||||
|
||||
{"locator", stations_locator, METH_VARARGS,
|
||||
"Get locator from callsign."},
|
||||
|
||||
{NULL, NULL, 0, NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
PyMODINIT_FUNC
|
||||
initstations(void)
|
||||
{
|
||||
(void) Py_InitModule("stations", StationsMethods);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env python
|
||||
import sys
|
||||
from timeit import Timer
|
||||
from stations import locator
|
||||
|
||||
call = sys.argv[1]
|
||||
print repr(call)
|
||||
D = {}
|
||||
|
||||
for line in file('stations.dat'):
|
||||
c, l = [x.strip() for x in line.split(',')]
|
||||
D[c] = l
|
||||
|
||||
def test1(c):
|
||||
return D[c]
|
||||
|
||||
print repr(test1(call))
|
||||
t = Timer("test1(%r)" % call, "from __main__ import test1")
|
||||
print t.timeit()
|
||||
|
||||
# -----
|
||||
|
||||
def test2(c):
|
||||
return locator(c)
|
||||
|
||||
print repr(test2(call))
|
||||
t = Timer("test2(%r)" % call, "from __main__ import test2")
|
||||
print t.timeit()
|
||||
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
This example shows how to use the class Graph.
|
||||
|
||||
The class implements a graph with 'N' vertices. First, you connect the
|
||||
graph with edges, which have a desired value associated. Then the vertex
|
||||
values are assigned, which will fail if the graph is cyclic. The vertex
|
||||
values are assigned such that the two values corresponding to an edge add
|
||||
up to the desired edge value (mod N).
|
||||
"""
|
||||
import sys
|
||||
|
||||
sys.path.append('..')
|
||||
from perfect_hash import Graph
|
||||
|
||||
G = Graph(3)
|
||||
assert G.assign_vertex_values() == True
|
||||
|
||||
# Now we make an edge between vertex 0 and 1 with desired edge value 2:
|
||||
G.connect(0, 1, 2)
|
||||
|
||||
# Make another edge 1:2 with desired edge value 1:
|
||||
G.connect(1, 2, 1)
|
||||
|
||||
# The graph is still acyclic, and assigning values works:
|
||||
assert G.assign_vertex_values() == True
|
||||
assert G.vertex_values == [0, 2, 2]
|
||||
|
||||
# What do these values mean?
|
||||
# When you add the values for edge 0:1 you get 0 + 2 = 2, as desired.
|
||||
# For edge 1:2 you add 2 + 2 = 4 = 1 (mod 3), as desired.
|
||||
|
||||
# Adding edge 0:2 produces a loop, so the graph is no longer acyclic.
|
||||
# Assigning values fails.
|
||||
G.connect(0, 2, 0)
|
||||
|
||||
assert G.assign_vertex_values() == False
|
||||
|
||||
|
||||
print 'OK'
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
|
||||
all:
|
||||
true
|
||||
|
||||
|
||||
clean:
|
||||
true
|
||||
|
||||
|
||||
test:
|
||||
./generate_hash.py
|
||||
./PerfHash.py
|
||||
./Graph.py
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
This example shows how to use the class PerfHash.
|
||||
|
||||
This class is designed for creating perfect hash tables at run time,
|
||||
which should be avoided, in particulat inserting new keys is
|
||||
prohibitively expensive since a new perfect hash table needs to be
|
||||
constructed. However, this class can be usefull for testing.
|
||||
|
||||
For practical programming purposes in Python the class PerfHash
|
||||
should never be used because Python's built-in dictionary is very
|
||||
efficient and always faster than PerfHash.
|
||||
"""
|
||||
|
||||
import sys
|
||||
|
||||
sys.path.append('..')
|
||||
from perfect_hash import PerfHash
|
||||
|
||||
|
||||
month = dict(zip('jan feb mar apr may jun jul aug sep oct mov dec'.split(),
|
||||
range(1, 13)))
|
||||
|
||||
d = PerfHash(month)
|
||||
|
||||
|
||||
for m in month:
|
||||
assert month[m] == d[m]
|
||||
|
||||
d[True] = False
|
||||
|
||||
assert d[True] == False
|
||||
|
||||
for i in xrange(10): # very expensive
|
||||
d[i] = 2*i*i + 3*i -7
|
||||
|
||||
assert d[4] == 37
|
||||
|
||||
|
||||
print 'OK'
|
||||
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
This example shows how to use the function generate_hash.
|
||||
|
||||
generate_hash(kdic, Hash)
|
||||
|
||||
returns hash functions f1 and f2, and G for a perfect minimal hash.
|
||||
Input is dictionary 'kdic' with the keys and desired hash values.
|
||||
'Hash' is a random hash function generator, that means Hash(N) returns a
|
||||
returns a random hash function which returns hash values from 0..N-1.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import random, string
|
||||
|
||||
sys.path.append('..')
|
||||
from perfect_hash import generate_hash
|
||||
|
||||
|
||||
|
||||
month = dict(zip('jan feb mar apr may jun jul aug sep oct mov dec'.split(),
|
||||
range(1, 13)))
|
||||
|
||||
def mkRandHash(N):
|
||||
"""
|
||||
Return a random hash function which returns hash values from 0..N-1.
|
||||
"""
|
||||
junk = "".join(random.choice(string.letters + string.digits)
|
||||
for i in xrange(10))
|
||||
return lambda key: hash(junk + str(key)) % N
|
||||
|
||||
|
||||
f1, f2, G = generate_hash(month, mkRandHash)
|
||||
|
||||
for k, h in month.items():
|
||||
assert h == ( G[f1(k)] + G[f2(k)] ) % len(G)
|
||||
|
||||
print 'OK'
|
||||
@@ -0,0 +1,31 @@
|
||||
|
||||
CC = gcc -Wall
|
||||
|
||||
|
||||
lookup: main.o states-code.o
|
||||
$(CC) -o $@ $^
|
||||
|
||||
|
||||
main.o: main.c states-code.h states.dat.h
|
||||
$(CC) -c $<
|
||||
|
||||
|
||||
states-code.o: states-code.c states-code.h
|
||||
$(CC) -c $<
|
||||
|
||||
|
||||
states-code.c: states.dat states-tmpl.c
|
||||
../perfect_hash.py -vvvv --splitby '|' --keycol 2 $^
|
||||
|
||||
|
||||
states.dat.h: states.dat
|
||||
./mk_header.py >$@
|
||||
|
||||
|
||||
clean:
|
||||
rm lookup *.o states.dat.h states-code.c
|
||||
|
||||
|
||||
test:
|
||||
./lookup 'NY'
|
||||
./lookup 'QW'
|
||||
@@ -0,0 +1,33 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "states-code.h"
|
||||
|
||||
struct {
|
||||
char *name;
|
||||
char *abbr;
|
||||
int pop;
|
||||
} states[] = {
|
||||
#include "states.dat.h"
|
||||
};
|
||||
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
if (argc != 2) {
|
||||
printf ("Usage: %s <abbreviation>\n", argv[0]);
|
||||
return 2;
|
||||
}
|
||||
|
||||
char *abbr = argv[1];
|
||||
int hashval;
|
||||
|
||||
if ((hashval = has_key(abbr)) == -1)
|
||||
printf ("'%s' is not an abbreviation for a state.\n", abbr);
|
||||
else
|
||||
printf ("The state of %s has a population of %g million.\n",
|
||||
states[hashval].name,
|
||||
1e-6 * states[hashval].pop);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#!/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
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
|
||||
/* Return hash value of abbreviation 'abbr' if found, -1 otherwise */
|
||||
int has_key (const char *abbr);
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "states-code.h"
|
||||
|
||||
|
||||
static int T1[] = { $S1 };
|
||||
|
||||
static int T2[] = { $S2 };
|
||||
|
||||
static int G[] = { $G };
|
||||
|
||||
static char *K[] = { $K };
|
||||
|
||||
static int hash_g (const char *key, const int *T)
|
||||
{
|
||||
int i, sum = 0;
|
||||
|
||||
for (i = 0; key[i] != '\0'; i++) {
|
||||
sum += T[i] * key[i];
|
||||
sum %= $NG;
|
||||
}
|
||||
return G[sum];
|
||||
}
|
||||
|
||||
static int perfect_hash (const char *key)
|
||||
{
|
||||
if (strlen (key) > $NS)
|
||||
return 0;
|
||||
|
||||
return (hash_g (key, T1) + hash_g (key, T2)) % $NG;
|
||||
}
|
||||
|
||||
int has_key (const char *abbr)
|
||||
{
|
||||
int hash_value = perfect_hash (abbr);
|
||||
|
||||
if (hash_value < $NK && strcmp(abbr, K[hash_value]) == 0)
|
||||
return hash_value;
|
||||
|
||||
return -1;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
# Name | Abr | Population
|
||||
#--------------+------+---------
|
||||
Alabama | AL | 4335400
|
||||
Alaska | AK | 611500
|
||||
Arizona | AZ | 4664600
|
||||
Arkansas | AR | 2531000
|
||||
California | CA | 33198100
|
||||
Colorado | CO | 3930700
|
||||
Connecticut | CT | 3271100
|
||||
Delaware | DE | 736900
|
||||
Florida | FL | 15012200
|
||||
Georgia | GA | 7562200
|
||||
Hawaii | HI | 1188400
|
||||
Idaho | ID | 1221500
|
||||
Illinois | IL | 11981700
|
||||
Indiana | IN | 5882500
|
||||
Iowa | IA | 2854700
|
||||
Kansas | KS | 2603200
|
||||
Kentucky | KY | 3921000
|
||||
Louisiana | LA | 4361200
|
||||
Maine | ME | 1243700
|
||||
Maryland | MD | 5122400
|
||||
Massachusetts | MA | 6133500
|
||||
Michigan | MI | 9825100
|
||||
Minnesota | MN | 4704200
|
||||
Mississippi | MS | 2739700
|
||||
Missouri | MO | 5421400
|
||||
Montana | MT | 886400
|
||||
Nebraska | NE | 1661400
|
||||
Nevada | NV | 1828700
|
||||
New Hampshire | NH | 1179100
|
||||
New Jersey | NJ | 8078300
|
||||
New Mexico | NM | 1738700
|
||||
New York | NY | 18197800
|
||||
North Carolina | NC | 7483100
|
||||
North Dakota | ND | 640000
|
||||
Ohio | OH | 11197900
|
||||
Oklahoma | OK | 3328100
|
||||
Oregon | OR | 3266800
|
||||
Pennsylvania | PA | 12044200
|
||||
Rhode Island | RI | 987000
|
||||
South Carolina | SC | 3781800
|
||||
South Dakota | SD | 738500
|
||||
Tennessee | TN | 5398200
|
||||
Texas | TX | 19274300
|
||||
Utah | UT | 2071500
|
||||
Vermont | VT | 590400
|
||||
Virginia | VA | 6768400
|
||||
Washington | WA | 5674900
|
||||
West Virginia | WV | 1813200
|
||||
Wisconsin | WI | 5224500
|
||||
Wyoming | WY | 479500
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
CC = gcc -Wall
|
||||
|
||||
a.out: main.c keys.code.h
|
||||
$(CC) $<
|
||||
|
||||
|
||||
keys.code.h: keys.dat keys.tmpl.h
|
||||
../perfect_hash.py $^
|
||||
|
||||
|
||||
keys.dat:
|
||||
./mk_rnd_keys.py 100 >keys.dat
|
||||
|
||||
|
||||
clean:
|
||||
rm keys.dat keys.code.h a.out
|
||||
|
||||
|
||||
test:
|
||||
./a.out
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
|
||||
#define NK $NK /* number of keys */
|
||||
#define NG $NG /* number of vertices */
|
||||
#define NS $NS /* length of array T1 and T2 */
|
||||
|
||||
int T1[] = { $S1 };
|
||||
|
||||
int T2[] = { $S2 };
|
||||
|
||||
int G[] = { $G };
|
||||
|
||||
char *K[] = { $K };
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "keys.code.h"
|
||||
|
||||
int hash_g (char *s, int *T)
|
||||
{
|
||||
int i, f = 0;
|
||||
|
||||
for (i = 0; s[i] != '\0'; i++) {
|
||||
f += T[i] * s[i];
|
||||
f %= NG;
|
||||
}
|
||||
return G[f];
|
||||
}
|
||||
|
||||
int hash (char *k)
|
||||
{
|
||||
if (strlen (k) > NS)
|
||||
return 0;
|
||||
|
||||
return (hash_g (k, T1) + hash_g (k, T2)) % NG;
|
||||
}
|
||||
|
||||
bool has_key (char *k)
|
||||
{
|
||||
int h = hash (k);
|
||||
|
||||
return h < NK && strcmp(k, K[h]) == 0;
|
||||
}
|
||||
|
||||
int main ()
|
||||
{
|
||||
int i;
|
||||
|
||||
char *junk = "acnhuvn5yushvghnw7og5siuhgsiuhnglsh45vgghwn";
|
||||
|
||||
assert (has_key(junk) == 0);
|
||||
assert (hash(junk) == 0);
|
||||
|
||||
for (i = 0; i < NK; i++) {
|
||||
assert (has_key(K[i]) == true);
|
||||
assert (hash(K[i]) == i);
|
||||
}
|
||||
puts ("OK");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# ./mk_rnd_keys.py 10000 | sort | uniq | shuf >keywords.txt
|
||||
|
||||
import sys
|
||||
from random import choice, randint
|
||||
from string import digits, uppercase, lowercase
|
||||
|
||||
def key():
|
||||
return ''.join(choice(uppercase + lowercase + digits)
|
||||
for i in xrange(randint(6, 20)))
|
||||
|
||||
N = int(sys.argv[1])
|
||||
|
||||
|
||||
for n in xrange(N):
|
||||
print key()
|
||||
@@ -0,0 +1,23 @@
|
||||
|
||||
|
||||
|
||||
animals.ps: animals.dot
|
||||
neato -Tps $< -Gstart=100 -o $@
|
||||
|
||||
|
||||
animals.dot: animals.py
|
||||
./py2dot -l $< -o $@
|
||||
|
||||
|
||||
animals.py: ../animals.txt
|
||||
../perfect_hash.py $< >$@
|
||||
|
||||
|
||||
clean:
|
||||
rm animals.py animals.dot animals.ps
|
||||
|
||||
|
||||
test:
|
||||
true
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
../perfect_hash.py ../animals.txt | ./py2dot | neato -Tps -Gstart=100 -o out.ps
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
|
||||
function showpwd ()
|
||||
{
|
||||
echo '=============' `pwd`
|
||||
}
|
||||
|
||||
# perform programs self test
|
||||
showpwd
|
||||
./perfect_hash.py --test || exit 1
|
||||
|
||||
# update documentation
|
||||
for folder in doc
|
||||
do
|
||||
cd $folder
|
||||
showpwd
|
||||
make
|
||||
cd ..
|
||||
done
|
||||
|
||||
# run examples
|
||||
for folder in example* graph
|
||||
do
|
||||
cd $folder
|
||||
showpwd
|
||||
make || exit 1
|
||||
make test || exit 1
|
||||
make clean
|
||||
cd ..
|
||||
done
|
||||
|
||||
rm perfect_hash.pyc
|
||||
@@ -0,0 +1,163 @@
|
||||
#encoding: utf-8
|
||||
from perfect_hash import perfect_hash
|
||||
|
||||
import re, string, os, random
|
||||
|
||||
cur_dir = os.path.abspath(os.path.dirname(__file__))
|
||||
|
||||
unicode_chinese_re = u'[\u2E80-\u2EFF\u2F00-\u2FDF\u3000-\u303F\u31C0-\u31EF\u3200-\u32FF\u3300-\u33FF\u3400-\u4DBF\u4DC0-\u4DFF\u4E00-\u9FBF\uF900-\uFAFF\uFE30-\uFE4F\uFF00-\uFFEF]'
|
||||
match_re = re.compile(unicode_chinese_re)
|
||||
|
||||
def _get_font_lib(f):
|
||||
reading_data = False
|
||||
data = []
|
||||
for i in f.readlines():
|
||||
if i.strip() == 'FONT_BMP_DATA_BEGIN':
|
||||
reading_data = True
|
||||
continue
|
||||
if i.strip() == 'FONT_BMP_DATA_END':
|
||||
break
|
||||
if reading_data:
|
||||
line = [k for k in i.strip().split(',') if k]
|
||||
data.extend([int(k, 16) for k in line])
|
||||
return data
|
||||
|
||||
class font_lib(object):
|
||||
def __init__(self, f, width, height, encoding):
|
||||
self.width = width
|
||||
self.height = height
|
||||
self._lib = _get_font_lib(f)
|
||||
# byte per charactor
|
||||
self._bpc = (width+7)//8*height
|
||||
self.encoding = encoding
|
||||
self._finished_push = False
|
||||
|
||||
self.char_dict = {}
|
||||
|
||||
def get_char_data(self, char):
|
||||
#char_gb = char.encode(self.encoding)
|
||||
|
||||
# copied from font_hz_bmp.c
|
||||
sec, idx = [ord(i) - 0xA0 for i in char]
|
||||
#print 'sec %d, idx %d for' % (sec, idx), char
|
||||
start = (94 * (sec-1) + (idx-1)) * self._bpc
|
||||
return self._lib[start:start+self._bpc]
|
||||
|
||||
def push_char(self, c):
|
||||
self.char_dict[c] = self.char_dict.get(c, 0) + 1
|
||||
|
||||
def push_file(self, f):
|
||||
try:
|
||||
for i in f:
|
||||
t = re.findall(match_re, unicode(i.decode(self.encoding)))
|
||||
if t:
|
||||
for c in t:
|
||||
self.push_char(c.encode(self.encoding))
|
||||
except UnicodeDecodeError as e:
|
||||
try:
|
||||
print 'error in decoding %s' % f.name
|
||||
except:
|
||||
print 'error in decoding string %s' % f
|
||||
# re-raise the exception and terminate the building process
|
||||
raise
|
||||
|
||||
def _finish_push(self):
|
||||
if self._finished_push:
|
||||
return
|
||||
|
||||
self._char_li = zip(self.char_dict.keys(), self.char_dict.values())
|
||||
self._char_li.sort(key=lambda x:x[1], reverse=True)
|
||||
self._finished_push = True
|
||||
|
||||
#for i in self._char_li:
|
||||
#print i[0], i[1]
|
||||
|
||||
def get_hash_map(self):
|
||||
self._finish_push()
|
||||
li = []
|
||||
for i, k in enumerate(self._char_li):
|
||||
li.append((k[0], i))
|
||||
return li
|
||||
|
||||
def get_new_font_lib(self):
|
||||
self._finish_push()
|
||||
dat = []
|
||||
for c, f in self._char_li:
|
||||
dat.extend(self.get_char_data(c))
|
||||
return dat
|
||||
|
||||
def finish(self):
|
||||
return self.get_hash_map(), self.get_new_font_lib()
|
||||
|
||||
class mph_options(object):
|
||||
'mock object for options'
|
||||
def __init__(self, verbose=4, delimiter=', ', indent=4, width=80):
|
||||
self.verbose = verbose
|
||||
self.delimiter = delimiter
|
||||
self.indent = indent
|
||||
self.width = width
|
||||
|
||||
def gen_char_mph(font_lib):
|
||||
template = open(os.path.join(cur_dir, '..', 'common', 'font_mph-tmpl.c'), 'r').read()
|
||||
opt = mph_options()
|
||||
hmap, flib = font_lib.finish()
|
||||
#print 'compact font lib: %d chars included.' % len(hmap)
|
||||
#for i in hmap:
|
||||
#print i[0], repr(i[0]), i[1]
|
||||
code = perfect_hash.generate_code(hmap, template, perfect_hash.Hash2, opt,
|
||||
extra_subs={
|
||||
'width':str(font_lib.width),
|
||||
'height':str(font_lib.height),
|
||||
'font_data':', '.join([hex(i) for i in flib])})
|
||||
|
||||
return code
|
||||
|
||||
# {name:[file_name, height, width, encoding, instance]}
|
||||
_font_map = {'hz16':{'fname':'common/hz16font.c',
|
||||
'height':16,
|
||||
'width':16,
|
||||
'encoding':'GB2312',
|
||||
'flib':None},
|
||||
'hz12':{'fname':'common/hz12font.c',
|
||||
'height':12,
|
||||
'width':12,
|
||||
'encoding':'GB2312',
|
||||
'flib':None}
|
||||
}
|
||||
|
||||
def get_font_lib(name):
|
||||
if name not in _font_map.keys():
|
||||
return None
|
||||
|
||||
if _font_map[name]['flib'] is None:
|
||||
_font_map[name]['flib'] = font_lib(open(
|
||||
os.path.join(cur_dir, '..', _font_map[name]['fname']), 'r'),
|
||||
_font_map[name]['height'],
|
||||
_font_map[name]['width'],
|
||||
_font_map[name]['encoding'])
|
||||
return _font_map[name]['flib']
|
||||
|
||||
def gen_cmp_font_file():
|
||||
for i in _font_map:
|
||||
fl = _font_map[i]['flib']
|
||||
if fl is not None:
|
||||
code = gen_char_mph(fl)
|
||||
with open(os.path.join(cur_dir, '..', 'common', 'font_cmp_%s.c' % i), 'w') as f:
|
||||
f.write(code)
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
|
||||
lib = get_font_lib('hz16')
|
||||
libn = get_font_lib('hz16')
|
||||
assert(lib is libn)
|
||||
|
||||
lib.push_file(open(sys.argv[1], 'rb'))
|
||||
|
||||
hmap, flib = lib.finish()
|
||||
for i in hmap:
|
||||
print i[0], i[1]
|
||||
|
||||
assert(len(flib) == 32 * len(hmap))
|
||||
|
||||
print gen_char_mph(lib)
|
||||
@@ -73,7 +73,7 @@ static void rtgui_box_layout_vertical(struct rtgui_box *box, struct rtgui_rect *
|
||||
{
|
||||
rtgui_widget_t *widget = rtgui_list_entry(node, struct rtgui_widget, sibling);
|
||||
if (widget->align & RTGUI_ALIGN_STRETCH) space_count ++;
|
||||
else total_height += widget->mini_height;
|
||||
else total_height += widget->min_height;
|
||||
}
|
||||
|
||||
/* calculate the height for each spaces */
|
||||
@@ -98,8 +98,8 @@ static void rtgui_box_layout_vertical(struct rtgui_box *box, struct rtgui_rect *
|
||||
|
||||
/* reset rect */
|
||||
rtgui_rect_moveto(rect, -rect->x1, -rect->y1);
|
||||
rect->x2 = widget->mini_width;
|
||||
rect->y2 = widget->mini_height;
|
||||
rect->x2 = widget->min_width;
|
||||
rect->y2 = widget->min_height;
|
||||
|
||||
/* left in default */
|
||||
rtgui_rect_moveto(rect, next_x, next_y);
|
||||
@@ -166,7 +166,7 @@ static void rtgui_box_layout_horizontal(struct rtgui_box *box, struct rtgui_rect
|
||||
{
|
||||
rtgui_widget_t *widget = rtgui_list_entry(node, struct rtgui_widget, sibling);
|
||||
if (widget->align & RTGUI_ALIGN_STRETCH) space_count ++;
|
||||
else total_width += widget->mini_width;
|
||||
else total_width += widget->min_width;
|
||||
}
|
||||
|
||||
if (space_count != 0)
|
||||
@@ -191,8 +191,8 @@ static void rtgui_box_layout_horizontal(struct rtgui_box *box, struct rtgui_rect
|
||||
|
||||
/* reset rect */
|
||||
rtgui_rect_moveto(rect, -rect->x1, -rect->y1);
|
||||
rect->x2 = widget->mini_width;
|
||||
rect->y2 = widget->mini_height;
|
||||
rect->x2 = widget->min_width;
|
||||
rect->y2 = widget->min_height;
|
||||
|
||||
/* top in default */
|
||||
rtgui_rect_moveto(rect, next_x, next_y);
|
||||
|
||||
@@ -104,7 +104,8 @@ rt_bool_t rtgui_button_event_handler(struct rtgui_object *object, struct rtgui_e
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_MOUSE_BUTTON:
|
||||
if (RTGUI_WIDGET_IS_HIDE(widget)) return RT_FALSE;
|
||||
if (RTGUI_WIDGET_IS_HIDE(widget))
|
||||
return RT_FALSE;
|
||||
{
|
||||
struct rtgui_event_mouse *emouse = (struct rtgui_event_mouse *)event;
|
||||
|
||||
@@ -159,9 +160,6 @@ rt_bool_t rtgui_button_event_handler(struct rtgui_object *object, struct rtgui_e
|
||||
/* need callback */
|
||||
rt_bool_t need_cb = RT_FALSE;
|
||||
|
||||
win = RTGUI_WIN(RTGUI_WIDGET(btn)->toplevel);
|
||||
win->last_mevent_widget = RTGUI_WIDGET(btn);
|
||||
|
||||
/* we need to decide whether the callback will be invoked
|
||||
* before the flag has changed. Moreover, we cannot invoke
|
||||
* it directly here, because the button might be destroyed
|
||||
@@ -174,14 +172,20 @@ rt_bool_t rtgui_button_event_handler(struct rtgui_object *object, struct rtgui_e
|
||||
need_cb = RT_TRUE;
|
||||
}
|
||||
|
||||
/* it's a normal button */
|
||||
/* if the button will handle the mouse up event here, it
|
||||
* should not be the last_mevent_widget. Take care that
|
||||
* don't overwrite other widgets. */
|
||||
win = RTGUI_WIN(RTGUI_WIDGET(btn)->toplevel);
|
||||
if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
|
||||
{
|
||||
btn->flag |= RTGUI_BUTTON_FLAG_PRESS;
|
||||
win->last_mevent_widget = RTGUI_WIDGET(btn);
|
||||
}
|
||||
else
|
||||
{
|
||||
btn->flag &= ~RTGUI_BUTTON_FLAG_PRESS;
|
||||
if (win->last_mevent_widget == RTGUI_WIDGET(btn))
|
||||
win->last_mevent_widget = RT_NULL;
|
||||
}
|
||||
|
||||
/* draw button */
|
||||
|
||||
@@ -48,7 +48,7 @@ rt_bool_t rtgui_combobox_pdwin_onitem(struct rtgui_object *object, struct rtgui_
|
||||
if (combo->on_selected != RT_NULL)
|
||||
combo->on_selected(RTGUI_OBJECT(combo), RT_NULL);
|
||||
|
||||
rtgui_win_hiden(pd_win);
|
||||
rtgui_win_hide(pd_win);
|
||||
rtgui_widget_update(RTGUI_WIDGET(combo));
|
||||
|
||||
return RT_FALSE;
|
||||
@@ -56,7 +56,7 @@ rt_bool_t rtgui_combobox_pdwin_onitem(struct rtgui_object *object, struct rtgui_
|
||||
|
||||
rt_bool_t rtgui_combobox_pdwin_ondeactive(struct rtgui_object *object, struct rtgui_event *event)
|
||||
{
|
||||
rtgui_win_hiden(RTGUI_WIN(object));
|
||||
rtgui_win_hide(RTGUI_WIN(object));
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ rt_bool_t rtgui_combobox_event_handler(struct rtgui_object *object, struct rtgui
|
||||
if (focused->widget != RT_NULL)
|
||||
{
|
||||
/* hide pull down window */
|
||||
rtgui_win_hiden(RTGUI_WIN(box->pd_win));
|
||||
rtgui_win_hide(RTGUI_WIN(box->pd_win));
|
||||
rtgui_combobox_ondraw(box);
|
||||
}
|
||||
}
|
||||
@@ -255,7 +255,7 @@ static rt_bool_t rtgui_combobox_pulldown_hide(struct rtgui_object *object, struc
|
||||
if (box == RT_NULL) return RT_TRUE;
|
||||
|
||||
/* hide pull down window */
|
||||
rtgui_win_hiden(RTGUI_WIN(box->pd_win));
|
||||
rtgui_win_hide(RTGUI_WIN(box->pd_win));
|
||||
|
||||
/* clear pull down button state */
|
||||
box->pd_pressed = RT_FALSE;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#include <rtgui/dc.h>
|
||||
#include <rtgui/widgets/digtube.h>
|
||||
|
||||
static void _rtgui_digtube_constructor(struct rtgui_digtube * digtube)
|
||||
{
|
||||
RTGUI_WIDGET_TEXTALIGN(digtube) = RTGUI_ALIGN_CENTER;
|
||||
|
||||
/* init widget and set event handler */
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(digtube), rtgui_digtube_event_handler);
|
||||
}
|
||||
|
||||
static void _rtgui_digtube_destructor(struct rtgui_digtube *digtube)
|
||||
{
|
||||
#ifndef RTGUI_DIGTUBE_USE_CONST_FONT
|
||||
/* release font memory */
|
||||
rt_free(digtube->digitfont.data);
|
||||
digtube->digitfont.data = RT_NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
DEFINE_CLASS_TYPE(digtube, "digtube",
|
||||
RTGUI_WIDGET_TYPE,
|
||||
_rtgui_digtube_constructor,
|
||||
_rtgui_digtube_destructor,
|
||||
sizeof(struct rtgui_digtube));
|
||||
|
||||
rt_bool_t rtgui_digtube_event_handler(struct rtgui_object *object, struct rtgui_event *event)
|
||||
{
|
||||
struct rtgui_digtube *digtube;
|
||||
struct rtgui_dc *dc;
|
||||
rtgui_rect_t rect;
|
||||
rtgui_rect_t text_rect;
|
||||
rtgui_color_t color;
|
||||
char * disbuf;
|
||||
char tempbuf[8];
|
||||
int i;
|
||||
|
||||
RTGUI_WIDGET_EVENT_HANDLER_PREPARE
|
||||
|
||||
digtube = RTGUI_DIGTUBE(object);
|
||||
switch (event->type)
|
||||
{
|
||||
case RTGUI_EVENT_PAINT:
|
||||
|
||||
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(object));
|
||||
if (dc == RT_NULL)
|
||||
break;
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(object), &rect);
|
||||
rtgui_dc_fill_rect(dc, &rect);
|
||||
|
||||
if (! (digtube->tube_style & RTGUI_DIGTUBE_STYLE_NOBACKFONT))
|
||||
{
|
||||
color = RTGUI_DC_BC(dc);
|
||||
RTGUI_DC_BC(dc) = digtube->digit_bc;
|
||||
}
|
||||
|
||||
if (digtube->tube_style & RTGUI_DIGTUBE_STYLE_DISCODES)
|
||||
disbuf = (char *) (digtube->value);
|
||||
else
|
||||
{
|
||||
const char * format =
|
||||
digtube->tube_style & RTGUI_DIGTUBE_STYLE_DISHEXNUM ?
|
||||
"%7x" : "%7d";
|
||||
|
||||
disbuf = &tempbuf[0];
|
||||
rt_snprintf(disbuf, 8, format, digtube->value);
|
||||
|
||||
/* */
|
||||
for (i=0; i<7; i++)
|
||||
{
|
||||
if (disbuf[i] == ' ')
|
||||
disbuf[i] = 0;
|
||||
else
|
||||
{
|
||||
disbuf[i] = (disbuf[i] >= '0' && disbuf[i] <= '9') ? disbuf[i] - '0':
|
||||
disbuf[i] - 'a' + 10;
|
||||
|
||||
disbuf[i] = digtube_code_table[disbuf[i]];
|
||||
}
|
||||
}
|
||||
|
||||
disbuf = tempbuf + 7 - digtube->tube_count;
|
||||
}
|
||||
|
||||
text_rect.x1 = 0;
|
||||
text_rect.y1 = 0;
|
||||
text_rect.x2 = (digtube->digit_width + digtube->digit_space) * digtube->tube_count
|
||||
-digtube->digit_space;
|
||||
text_rect.y2 = digtube->digit_hight;
|
||||
|
||||
rtgui_rect_moveto_align(&rect, &text_rect, RTGUI_DC_TEXTALIGN(dc));
|
||||
for (i=0; i<digtube->tube_count; i++)
|
||||
{
|
||||
rtgui_dc_draw_digitfont_code(dc, &digtube->digitfont, &text_rect, disbuf[i]);
|
||||
text_rect.x1 += digtube->digit_width + digtube->digit_space;
|
||||
}
|
||||
|
||||
if (! (digtube->tube_style & RTGUI_DIGTUBE_STYLE_NOBACKFONT))
|
||||
RTGUI_DC_BC(dc) = color;
|
||||
rtgui_dc_end_drawing(dc);
|
||||
break;
|
||||
default:
|
||||
return rtgui_widget_event_handler(object, event);
|
||||
}
|
||||
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
rtgui_digtube_t *rtgui_digtube_create(
|
||||
struct rtgui_digitfont * digitfont,
|
||||
int count,
|
||||
void * value,
|
||||
int style)
|
||||
{
|
||||
struct rtgui_digtube *digtube;
|
||||
rtgui_rect_t rect;
|
||||
|
||||
RT_ASSERT(count <= 7 && count > 0)
|
||||
|
||||
digtube = (struct rtgui_digtube *) rtgui_widget_create(RTGUI_DIGTUBE_TYPE);
|
||||
if (digtube == RT_NULL)
|
||||
return RT_NULL;
|
||||
|
||||
/* set field */
|
||||
if (digitfont == RT_NULL)
|
||||
digitfont = &digitfont_40;
|
||||
|
||||
rt_memcpy(& digtube->digitfont, digitfont, sizeof(struct rtgui_digitfont));
|
||||
|
||||
#ifndef RTGUI_DIGTUBE_USE_CONST_FONT
|
||||
if (digtube->digitfont.data == RT_NULL)
|
||||
rtgui_digitfont_create(& digtube->digitfont);
|
||||
#endif
|
||||
|
||||
/* set default rect */
|
||||
rtgui_get_digfont_metrics(&digtube->digitfont, &rect);
|
||||
digtube->digit_width = rect.x2;
|
||||
digtube->digit_hight = rect.y2;
|
||||
digtube->tube_count = count;
|
||||
digtube->digit_space = RTGUI_DIGTUBE_DEFAULT_SPACE;
|
||||
|
||||
rect.x2 = (rect.x2 + digtube->digit_space) * count - digtube->digit_space;
|
||||
rect.y2 = rect.y2;
|
||||
|
||||
RTGUI_WIDGET_BACKGROUND(digtube) = rtgui_theme_default_bc();
|
||||
RTGUI_WIDGET_FOREGROUND(digtube) = RTGUI_DIGTUBE_DEFAULT_FC;
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(digtube), &rect);
|
||||
|
||||
/* set display value */
|
||||
digtube->digit_bc = RTGUI_DIGTUBE_DEFAULT_DIGIT_BC;
|
||||
digtube->value = value;
|
||||
digtube->tube_style = style;
|
||||
|
||||
return digtube;
|
||||
}
|
||||
|
||||
void rtgui_digtube_destroy(rtgui_digtube_t *digtube)
|
||||
{
|
||||
rtgui_widget_destroy(RTGUI_WIDGET(digtube));
|
||||
}
|
||||
@@ -250,7 +250,7 @@ static rt_bool_t rtgui_filelist_view_on_folder_item(rtgui_object_t *object, stru
|
||||
view = RTGUI_FILELIST_VIEW(menu->user_data);
|
||||
|
||||
/* hide window */
|
||||
rtgui_win_hiden(menu);
|
||||
rtgui_win_hide(menu);
|
||||
|
||||
switch (listbox->current_item)
|
||||
{
|
||||
|
||||
@@ -61,7 +61,7 @@ static rt_bool_t _rtgui_menu_onitem(struct rtgui_object *object, struct rtgui_ev
|
||||
if (!RTGUI_WIDGET_IS_HIDE(menu->sub_menu))
|
||||
{
|
||||
/* hide this sub menu */
|
||||
rtgui_win_hiden(RTGUI_WIN(menu->sub_menu));
|
||||
rtgui_win_hide(RTGUI_WIN(menu->sub_menu));
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
@@ -91,9 +91,9 @@ static rt_bool_t _rtgui_menu_onitem(struct rtgui_object *object, struct rtgui_ev
|
||||
/* hide sub-menu */
|
||||
if (menu->sub_menu != RT_NULL)
|
||||
{
|
||||
rtgui_menu_hiden(menu->sub_menu);
|
||||
rtgui_menu_hide(menu->sub_menu);
|
||||
}
|
||||
rtgui_menu_hiden(menu);
|
||||
rtgui_menu_hide(menu);
|
||||
}
|
||||
return RT_FALSE;
|
||||
}
|
||||
@@ -183,7 +183,7 @@ static rt_bool_t rtgui_menu_on_deactivate(struct rtgui_object *object, rtgui_eve
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
rtgui_win_hiden(RTGUI_WIN(menu));
|
||||
rtgui_win_hide(RTGUI_WIN(menu));
|
||||
if (menu->on_menuhide != RT_NULL)
|
||||
{
|
||||
menu->on_menuhide(RTGUI_OBJECT(menu), RT_NULL);
|
||||
@@ -282,13 +282,13 @@ void rtgui_menu_pop(struct rtgui_menu *menu, int x, int y)
|
||||
rtgui_win_show(RTGUI_WIN(menu), RT_FALSE);
|
||||
}
|
||||
|
||||
void rtgui_menu_hiden(struct rtgui_menu *menu)
|
||||
void rtgui_menu_hide(struct rtgui_menu *menu)
|
||||
{
|
||||
rtgui_win_hiden(RTGUI_WIN(menu));
|
||||
rtgui_win_hide(RTGUI_WIN(menu));
|
||||
/* un-select item */
|
||||
menu->items_list->current_item = -1;
|
||||
|
||||
if (menu->parent_menu != RT_NULL)
|
||||
rtgui_menu_hiden(menu->parent_menu);
|
||||
rtgui_menu_hide(menu->parent_menu);
|
||||
}
|
||||
|
||||
|
||||
@@ -539,7 +539,8 @@ void rtgui_notebook_set_current_by_index(struct rtgui_notebook *notebook, rt_uin
|
||||
widget = notebook->childs[notebook->current].widget;
|
||||
rtgui_widget_show(widget);
|
||||
rtgui_widget_update_clip(widget);
|
||||
rtgui_widget_update(widget);
|
||||
/* the whole notebook need an update */
|
||||
rtgui_widget_update(RTGUI_WIDGET(notebook));
|
||||
rtgui_widget_focus(widget);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,14 +228,14 @@ void rtgui_radiobox_set_orientation(struct rtgui_radiobox *radiobox, int orienta
|
||||
if (radiobox->orient == RTGUI_HORIZONTAL)
|
||||
{
|
||||
/* HORIZONTAL */
|
||||
rtgui_widget_set_miniheight(RTGUI_WIDGET(radiobox), RTGUI_RADIOBOX_DEFAULT_HEIGHT);
|
||||
rtgui_widget_set_miniwidth(RTGUI_WIDGET(radiobox), RTGUI_RADIOBOX_DEFAULT_WIDTH);
|
||||
rtgui_widget_set_minheight(RTGUI_WIDGET(radiobox), RTGUI_RADIOBOX_DEFAULT_HEIGHT);
|
||||
rtgui_widget_set_minwidth(RTGUI_WIDGET(radiobox), RTGUI_RADIOBOX_DEFAULT_WIDTH);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* VERTICAL */
|
||||
rtgui_widget_set_miniwidth(RTGUI_WIDGET(radiobox), RTGUI_RADIOBOX_DEFAULT_HEIGHT);
|
||||
rtgui_widget_set_miniheight(RTGUI_WIDGET(radiobox), RTGUI_RADIOBOX_DEFAULT_WIDTH);
|
||||
rtgui_widget_set_minwidth(RTGUI_WIDGET(radiobox), RTGUI_RADIOBOX_DEFAULT_HEIGHT);
|
||||
rtgui_widget_set_minheight(RTGUI_WIDGET(radiobox), RTGUI_RADIOBOX_DEFAULT_WIDTH);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -255,14 +255,14 @@ void rtgui_slider_set_orientation(struct rtgui_slider *slider, int orientation)
|
||||
if (slider->orient == RTGUI_HORIZONTAL)
|
||||
{
|
||||
/* HORIZONTAL */
|
||||
rtgui_widget_set_miniheight(RTGUI_WIDGET(slider), RTGUI_SLIDER_DEFAULT_HEIGHT);
|
||||
rtgui_widget_set_miniwidth(RTGUI_WIDGET(slider), RTGUI_SLIDER_DEFAULT_WIDTH);
|
||||
rtgui_widget_set_minheight(RTGUI_WIDGET(slider), RTGUI_SLIDER_DEFAULT_HEIGHT);
|
||||
rtgui_widget_set_minwidth(RTGUI_WIDGET(slider), RTGUI_SLIDER_DEFAULT_WIDTH);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* VERTICAL */
|
||||
rtgui_widget_set_miniwidth(RTGUI_WIDGET(slider), RTGUI_SLIDER_DEFAULT_HEIGHT);
|
||||
rtgui_widget_set_miniheight(RTGUI_WIDGET(slider), RTGUI_SLIDER_DEFAULT_WIDTH);
|
||||
rtgui_widget_set_minwidth(RTGUI_WIDGET(slider), RTGUI_SLIDER_DEFAULT_HEIGHT);
|
||||
rtgui_widget_set_minheight(RTGUI_WIDGET(slider), RTGUI_SLIDER_DEFAULT_WIDTH);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -73,14 +73,14 @@ void rtgui_staticline_set_orientation(rtgui_staticline_t *staticline, int orient
|
||||
if (orientation == RTGUI_HORIZONTAL)
|
||||
{
|
||||
/* HORIZONTAL */
|
||||
rtgui_widget_set_miniheight(RTGUI_WIDGET(staticline), 2);
|
||||
rtgui_widget_set_miniwidth(RTGUI_WIDGET(staticline), 100);
|
||||
rtgui_widget_set_minheight(RTGUI_WIDGET(staticline), 2);
|
||||
rtgui_widget_set_minwidth(RTGUI_WIDGET(staticline), 100);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* VERTICAL */
|
||||
rtgui_widget_set_miniwidth(RTGUI_WIDGET(staticline), 2);
|
||||
rtgui_widget_set_miniheight(RTGUI_WIDGET(staticline), 100);
|
||||
rtgui_widget_set_minwidth(RTGUI_WIDGET(staticline), 2);
|
||||
rtgui_widget_set_minheight(RTGUI_WIDGET(staticline), 100);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -54,6 +54,14 @@ static void _rtgui_textbox_constructor(rtgui_textbox_t *box)
|
||||
rtgui_textbox_set_mask_char(box, '*');
|
||||
|
||||
rtgui_font_get_metrics(RTGUI_WIDGET_FONT(box), "H", &rect);
|
||||
rtgui_widget_set_minheight(RTGUI_WIDGET(box),
|
||||
rtgui_rect_height(rect) + RTGUI_TEXTBOX_BORDER_WIDTH * 2);
|
||||
/* at least, we want to display one char. */
|
||||
rtgui_widget_set_minwidth(RTGUI_WIDGET(box),
|
||||
rtgui_rect_width(rect) + RTGUI_TEXTBOX_BORDER_WIDTH * 2 \
|
||||
+ RTGUI_WIDGET_DEFAULT_MARGIN /* there is a margin in the beginning
|
||||
of the text. */
|
||||
);
|
||||
box->font_width = rtgui_rect_width(rect);
|
||||
box->on_enter = RT_NULL;
|
||||
box->dis_length = 0;
|
||||
@@ -531,13 +539,13 @@ void rtgui_textbox_ondraw(rtgui_textbox_t *box)
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect);
|
||||
fc = RTGUI_WIDGET_FOREGROUND(box);
|
||||
|
||||
rtgui_rect_inflate(&rect, -1);
|
||||
rtgui_rect_inflate(&rect, -RTGUI_TEXTBOX_BORDER_WIDTH);
|
||||
|
||||
/* fill widget rect with white color */
|
||||
RTGUI_WIDGET_BACKGROUND(box) = white;
|
||||
rtgui_dc_fill_rect(dc, &rect);
|
||||
|
||||
rtgui_rect_inflate(&rect, 1);
|
||||
rtgui_rect_inflate(&rect, RTGUI_TEXTBOX_BORDER_WIDTH);
|
||||
/* draw border */
|
||||
RTGUI_WIDGET_FOREGROUND(box) = RTGUI_RGB(123, 158, 189);
|
||||
rtgui_dc_draw_rect(dc, &rect);
|
||||
@@ -610,29 +618,27 @@ char rtgui_textbox_get_mask_char(rtgui_textbox_t *box)
|
||||
return box->mask_char;
|
||||
}
|
||||
|
||||
void rtgui_textbox_set_line_length(rtgui_textbox_t *box, rt_size_t length)
|
||||
rt_err_t rtgui_textbox_set_line_length(rtgui_textbox_t *box, rt_size_t length)
|
||||
{
|
||||
rt_uint8_t *new_line;
|
||||
char *new_line;
|
||||
|
||||
RT_ASSERT(box != RT_NULL);
|
||||
RT_ASSERT(box != RT_NULL);
|
||||
|
||||
/* invalid length */
|
||||
if (length <= 0)
|
||||
return;
|
||||
/* invalid length */
|
||||
if (length <= 0)
|
||||
return -RT_ERROR;
|
||||
|
||||
new_line = rtgui_malloc(length);
|
||||
if (length < box->line_length)
|
||||
{
|
||||
rt_memcpy(new_line, box->text, length - 1);
|
||||
new_line[length] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_memcpy(new_line, (const char *)box->text, rt_strlen((const char *)box->text));
|
||||
}
|
||||
new_line = rtgui_realloc(box->text, length+1);
|
||||
if (new_line == RT_NULL)
|
||||
return -RT_ENOMEM;
|
||||
|
||||
/* set line length */
|
||||
box->line_length = length;
|
||||
if (length < box->line_length)
|
||||
new_line[length] = '\0';
|
||||
|
||||
box->line_length = length;
|
||||
box->text = new_line;
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
/* get textbox text area */
|
||||
|
||||
@@ -135,9 +135,9 @@ void rtgui_widget_set_rect(rtgui_widget_t *widget, const rtgui_rect_t *rect)
|
||||
rtgui_container_layout(RTGUI_CONTAINER(widget));
|
||||
}
|
||||
|
||||
/* reset mini width and height */
|
||||
widget->mini_width = rtgui_rect_width(widget->extent);
|
||||
widget->mini_height = rtgui_rect_height(widget->extent);
|
||||
/* reset min width and height */
|
||||
widget->min_width = rtgui_rect_width(widget->extent);
|
||||
widget->min_height = rtgui_rect_height(widget->extent);
|
||||
|
||||
/* it's not empty, fini it */
|
||||
if (rtgui_region_not_empty(&(widget->clip)))
|
||||
@@ -184,21 +184,29 @@ void rtgui_widget_get_extent(rtgui_widget_t *widget, rtgui_rect_t *rect)
|
||||
}
|
||||
RTM_EXPORT(rtgui_widget_get_extent);
|
||||
|
||||
void rtgui_widget_set_miniwidth(rtgui_widget_t *widget, int width)
|
||||
void rtgui_widget_set_minsize(rtgui_widget_t *widget, int width, int height)
|
||||
{
|
||||
RT_ASSERT(widget != RT_NULL);
|
||||
widget->min_width = width;
|
||||
widget->min_height = height;
|
||||
}
|
||||
RTM_EXPORT(rtgui_widget_set_minsize);
|
||||
|
||||
void rtgui_widget_set_minwidth(rtgui_widget_t *widget, int width)
|
||||
{
|
||||
RT_ASSERT(widget != RT_NULL);
|
||||
|
||||
widget->mini_width = width;
|
||||
widget->min_width = width;
|
||||
}
|
||||
RTM_EXPORT(rtgui_widget_set_miniwidth);
|
||||
RTM_EXPORT(rtgui_widget_set_minwidth);
|
||||
|
||||
void rtgui_widget_set_miniheight(rtgui_widget_t *widget, int height)
|
||||
void rtgui_widget_set_minheight(rtgui_widget_t *widget, int height)
|
||||
{
|
||||
RT_ASSERT(widget != RT_NULL);
|
||||
|
||||
widget->mini_height = height;
|
||||
widget->min_height = height;
|
||||
}
|
||||
RTM_EXPORT(rtgui_widget_set_miniheight);
|
||||
RTM_EXPORT(rtgui_widget_set_minheight);
|
||||
|
||||
/*
|
||||
* This function moves widget and its children to a logic point
|
||||
|
||||
@@ -178,7 +178,7 @@ static rt_bool_t _rtgui_win_deal_close(struct rtgui_win *win,
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
rtgui_win_hiden(win);
|
||||
rtgui_win_hide(win);
|
||||
|
||||
win->flag |= RTGUI_WIN_FLAG_CLOSED;
|
||||
|
||||
@@ -280,7 +280,7 @@ rt_base_t rtgui_win_show(struct rtgui_win *win, rt_bool_t is_modal)
|
||||
|
||||
/* set main window */
|
||||
if (app->main_object == RT_NULL)
|
||||
rtgui_app_set_main_win(win);
|
||||
rtgui_app_set_main_win(app, win);
|
||||
|
||||
if (is_modal == RT_TRUE)
|
||||
{
|
||||
@@ -328,7 +328,7 @@ void rtgui_win_end_modal(struct rtgui_win *win, rtgui_modal_code_t modal_code)
|
||||
}
|
||||
RTM_EXPORT(rtgui_win_end_modal);
|
||||
|
||||
void rtgui_win_hiden(struct rtgui_win *win)
|
||||
void rtgui_win_hide(struct rtgui_win *win)
|
||||
{
|
||||
RT_ASSERT(win != RT_NULL);
|
||||
|
||||
@@ -351,7 +351,7 @@ void rtgui_win_hiden(struct rtgui_win *win)
|
||||
win->flag &= ~RTGUI_WIN_FLAG_ACTIVATE;
|
||||
}
|
||||
}
|
||||
RTM_EXPORT(rtgui_win_hiden);
|
||||
RTM_EXPORT(rtgui_win_hide);
|
||||
|
||||
rt_err_t rtgui_win_activate(struct rtgui_win *win)
|
||||
{
|
||||
@@ -469,7 +469,7 @@ rt_bool_t rtgui_win_event_handler(struct rtgui_object *object, struct rtgui_even
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_WIN_HIDE:
|
||||
rtgui_win_hiden(win);
|
||||
rtgui_win_hide(win);
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_WIN_CLOSE:
|
||||
@@ -538,27 +538,37 @@ rt_bool_t rtgui_win_event_handler(struct rtgui_object *object, struct rtgui_even
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_MOUSE_BUTTON:
|
||||
/* check whether has widget which handled mouse event before */
|
||||
if (win->last_mevent_widget != RT_NULL)
|
||||
{
|
||||
RTGUI_OBJECT(win->last_mevent_widget)->event_handler(
|
||||
RTGUI_OBJECT(win->last_mevent_widget),
|
||||
event);
|
||||
|
||||
/* clean last mouse event handled widget */
|
||||
win->last_mevent_widget = RT_NULL;
|
||||
}
|
||||
else if (rtgui_container_dispatch_mouse_event(RTGUI_CONTAINER(win),
|
||||
(struct rtgui_event_mouse *)event) == RT_FALSE)
|
||||
{
|
||||
rt_bool_t res = rtgui_container_dispatch_mouse_event(RTGUI_CONTAINER(win),
|
||||
(struct rtgui_event_mouse *)event);
|
||||
#ifndef RTGUI_USING_SMALL_SIZE
|
||||
if (RTGUI_WIDGET(object)->on_mouseclick != RT_NULL)
|
||||
{
|
||||
return RTGUI_WIDGET(object)->on_mouseclick(object, event);
|
||||
RTGUI_WIDGET(object)->on_mouseclick(object, event);
|
||||
}
|
||||
#endif
|
||||
/* check whether has widget which handled mouse event before.
|
||||
*
|
||||
* Note #1: that the widget should have already received mouse down
|
||||
* event and we should only feed the mouse up event to it here.
|
||||
*
|
||||
* Note #2: the widget is responsible to clean up
|
||||
* last_mevent_widget on mouse up event(but not overwrite other
|
||||
* widgets). If not, it will receive two mouse up events.
|
||||
*/
|
||||
if (((struct rtgui_event_mouse *)event)->button & RTGUI_MOUSE_BUTTON_UP
|
||||
&& win->last_mevent_widget != RT_NULL)
|
||||
{
|
||||
RTGUI_OBJECT(win->last_mevent_widget)->event_handler(
|
||||
RTGUI_OBJECT(win->last_mevent_widget),
|
||||
event);
|
||||
|
||||
/* clean last mouse event handled widget */
|
||||
win->last_mevent_widget = RT_NULL;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_MOUSE_MOTION:
|
||||
#if 0
|
||||
@@ -623,7 +633,7 @@ rt_bool_t rtgui_win_event_handler(struct rtgui_object *object, struct rtgui_even
|
||||
return RT_TRUE;
|
||||
break;
|
||||
|
||||
default :
|
||||
default:
|
||||
return rtgui_container_event_handler(object, event);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ demo_view_edit.c
|
||||
demo_view_bmp.c
|
||||
demo_plot.c
|
||||
mywidget.c
|
||||
demo_view_digtube.c
|
||||
""")
|
||||
|
||||
if GetDepend('RTGUI_USING_FONT_COMPACT'):
|
||||
|
||||
@@ -33,7 +33,7 @@ static void application_entry(void *parameter)
|
||||
struct rtgui_app *app;
|
||||
struct rtgui_rect rect;
|
||||
|
||||
app = rtgui_app_create(rt_thread_self(), "gui_demo");
|
||||
app = rtgui_app_create("gui_demo");
|
||||
if (app == RT_NULL)
|
||||
return;
|
||||
|
||||
@@ -95,6 +95,7 @@ static void application_entry(void *parameter)
|
||||
demo_view_notebook();
|
||||
demo_view_mywidget();
|
||||
demo_plot();
|
||||
demo_view_digtube();
|
||||
|
||||
#if defined(RTGUI_USING_DFS_FILERW)
|
||||
demo_view_edit();
|
||||
|
||||
@@ -42,7 +42,7 @@ struct rtgui_container* demo_plot(void)
|
||||
curve1->min_x = 0;
|
||||
curve1->max_x = sizeof(sin_ydata)/sizeof(sin_ydata[0]);
|
||||
curve1->min_y = -100;
|
||||
curve1->min_y = 100;
|
||||
curve1->max_y = 100;
|
||||
curve1->color = red;
|
||||
rtgui_mv_model_add_view(RTGUI_MV_MODEL(curve1), RTGUI_MV_VIEW(plot));
|
||||
|
||||
@@ -51,22 +51,25 @@ struct rtgui_container* demo_plot(void)
|
||||
RTGUI_MV_MODEL(curve2)->length = sizeof(cos_ydata)/sizeof(cos_ydata[0]);
|
||||
curve2->min_x = 0;
|
||||
curve2->max_x = sizeof(cos_ydata)/sizeof(cos_ydata[0]);
|
||||
curve1->min_y = -50;
|
||||
curve1->min_y = 50;
|
||||
curve2->min_y = -50;
|
||||
curve2->max_y = 50;
|
||||
curve2->color = blue;
|
||||
rtgui_mv_model_add_view(RTGUI_MV_MODEL(curve2), RTGUI_MV_VIEW(plot));
|
||||
|
||||
curve3 = rtgui_plot_curve_create();
|
||||
rtgui_plot_curve_set_x(curve3, cos_ydata);
|
||||
rtgui_plot_curve_set_y(curve3, sin_ydata);
|
||||
curve3->min_x = -50;
|
||||
curve3->max_x = 50;
|
||||
curve3->min_y = -100;
|
||||
curve3->max_y = 100;
|
||||
RTGUI_MV_MODEL(curve3)->length = sizeof(sin_ydata)/sizeof(sin_ydata[0]);
|
||||
curve3->color = black;
|
||||
rtgui_mv_model_add_view(RTGUI_MV_MODEL(curve3), RTGUI_MV_VIEW(plot));
|
||||
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(cnt), &rect);
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(plot), &rect);
|
||||
rtgui_plot_set_base(plot,
|
||||
-rtgui_rect_width(rect)/3, rtgui_rect_height(rect)/2);
|
||||
rtgui_plot_set_base(plot, -100, -300);
|
||||
|
||||
rtgui_container_add_child(cnt, RTGUI_WIDGET(plot));
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ rt_bool_t benchmark_event_handler(struct rtgui_object *object, rtgui_event_t *ev
|
||||
if (running)
|
||||
{
|
||||
/* stop */
|
||||
rtgui_app_set_onidle(RT_NULL);
|
||||
rtgui_app_set_onidle(rtgui_app_self(), RT_NULL);
|
||||
_draw_default(object, event);
|
||||
}
|
||||
else
|
||||
@@ -118,7 +118,7 @@ rt_bool_t benchmark_event_handler(struct rtgui_object *object, rtgui_event_t *ev
|
||||
/* run */
|
||||
ticks = rt_tick_get();
|
||||
area = 0;
|
||||
rtgui_app_set_onidle(_onidle);
|
||||
rtgui_app_set_onidle(rtgui_app_self(), _onidle);
|
||||
}
|
||||
|
||||
running = !running;
|
||||
|
||||
@@ -34,7 +34,7 @@ rtgui_container_t *demo_view_box(void)
|
||||
|
||||
button = rtgui_button_create("button 2");
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(panel), RTGUI_WIDGET(button));
|
||||
rtgui_widget_set_miniheight(RTGUI_WIDGET(button), 25);
|
||||
rtgui_widget_set_minheight(RTGUI_WIDGET(button), 25);
|
||||
RTGUI_WIDGET_ALIGN(button) = RTGUI_ALIGN_EXPAND;
|
||||
|
||||
rtgui_container_layout(RTGUI_CONTAINER(panel));
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/*
|
||||
* 程序清单:button控件演示
|
||||
* 程序清单:button控件演示
|
||||
*
|
||||
* 这个例子会在创建出的container上添加几个不同类型的button控件
|
||||
* 这个例子会在创建出的container上添加几个不同类型的button控件
|
||||
*/
|
||||
|
||||
#include "demo_view.h"
|
||||
#include <rtgui/widgets/button.h>
|
||||
|
||||
/* 创建用于演示button控件的视图 */
|
||||
/* 创建用于演示button控件的视图 */
|
||||
rtgui_container_t *demo_view_button(void)
|
||||
{
|
||||
rtgui_rect_t rect;
|
||||
@@ -15,64 +15,64 @@ rtgui_container_t *demo_view_button(void)
|
||||
rtgui_button_t *button;
|
||||
rtgui_font_t *font;
|
||||
|
||||
/* 先创建一个演示用的视图 */
|
||||
/* 先创建一个演示用的视图 */
|
||||
container = demo_view("Button View");
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(container, &rect);
|
||||
rect.x1 += 5;
|
||||
rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
/* 创建一个button控件 */
|
||||
/* 创建一个button控件 */
|
||||
button = rtgui_button_create("Red");
|
||||
/* 设置label控件的前景色为红色 */
|
||||
/* 设置label控件的前景色为红色 */
|
||||
RTGUI_WIDGET_FOREGROUND(button) = red;
|
||||
/* 设置button的位置 */
|
||||
/* 设置button的位置 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
|
||||
rtgui_container_add_child(container, RTGUI_WIDGET(button));
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(container, &rect);
|
||||
rect.x1 += 5;
|
||||
rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5 + 25;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
/* 创建一个button控件 */
|
||||
/* 创建一个button控件 */
|
||||
button = rtgui_button_create("Blue");
|
||||
/* 设置label控件的前景色为蓝色 */
|
||||
/* 设置label控件的前景色为蓝色 */
|
||||
RTGUI_WIDGET_FOREGROUND(button) = blue;
|
||||
/* 设置button的位置 */
|
||||
/* 设置button的位置 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
|
||||
rtgui_container_add_child(container, RTGUI_WIDGET(button));
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(container, &rect);
|
||||
rect.x1 += 5;
|
||||
rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5 + 25 + 25;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
/* 创建一个button控件 */
|
||||
/* 创建一个button控件 */
|
||||
button = rtgui_button_create("12 font");
|
||||
/* 设置字体为12点阵的asc字体 */
|
||||
/* 设置字体为12点阵的asc字体 */
|
||||
font = rtgui_font_refer("asc", 12);
|
||||
RTGUI_WIDGET_FONT(button) = font;
|
||||
/* 设置button的位置 */
|
||||
/* 设置button的位置 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
|
||||
rtgui_container_add_child(container, RTGUI_WIDGET(button));
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(container, &rect);
|
||||
rect.x1 += 5;
|
||||
rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5 + 25 + 25 + 25;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
/* 创建一个button控件 */
|
||||
/* 创建一个button控件 */
|
||||
button = rtgui_button_create("16 font");
|
||||
/* 设置字体为16点阵的asc字体 */
|
||||
/* 设置字体为16点阵的asc字体 */
|
||||
font = rtgui_font_refer("asc", 16);
|
||||
RTGUI_WIDGET_FONT(button) = font;
|
||||
/* 设置button的位置 */
|
||||
/* 设置button的位置 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
|
||||
rtgui_container_add_child(container, RTGUI_WIDGET(button));
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/*
|
||||
* 程序清单:checkbox控件演示
|
||||
* 程序清单:checkbox控件演示
|
||||
*
|
||||
* 这个例子会在创建出的container上添加几个checkbox控件
|
||||
* 这个例子会在创建出的container上添加几个checkbox控件
|
||||
*/
|
||||
|
||||
#include "demo_view.h"
|
||||
#include <rtgui/widgets/checkbox.h>
|
||||
|
||||
/* 创建用于演示checkbox控件的视图 */
|
||||
/* 创建用于演示checkbox控件的视图 */
|
||||
rtgui_container_t *demo_view_checkbox(void)
|
||||
{
|
||||
rtgui_rect_t rect;
|
||||
@@ -15,64 +15,64 @@ rtgui_container_t *demo_view_checkbox(void)
|
||||
rtgui_checkbox_t *checkbox;
|
||||
rtgui_font_t *font;
|
||||
|
||||
/* 先创建一个演示用的视图 */
|
||||
/* 先创建一个演示用的视图 */
|
||||
container = demo_view("CheckBox View");
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(container, &rect);
|
||||
rect.x1 += 5;
|
||||
rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
/* 创建一个checkbox控件 */
|
||||
/* 创建一个checkbox控件 */
|
||||
checkbox = rtgui_checkbox_create("Red", RT_TRUE);
|
||||
/* 设置前景色为红色 */
|
||||
/* 设置前景色为红色 */
|
||||
RTGUI_WIDGET_FOREGROUND(checkbox) = red;
|
||||
/* 设置checkbox的位置 */
|
||||
/* 设置checkbox的位置 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect);
|
||||
rtgui_container_add_child(container, RTGUI_WIDGET(checkbox));
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(container, &rect);
|
||||
rect.x1 += 5;
|
||||
rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5 + 25;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
/* 创建一个checkbox控件 */
|
||||
/* 创建一个checkbox控件 */
|
||||
checkbox = rtgui_checkbox_create("Blue", RT_TRUE);
|
||||
/* 设置前景色为蓝色 */
|
||||
/* 设置前景色为蓝色 */
|
||||
RTGUI_WIDGET_FOREGROUND(checkbox) = blue;
|
||||
/* 设置checkbox的位置 */
|
||||
/* 设置checkbox的位置 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect);
|
||||
rtgui_container_add_child(container, RTGUI_WIDGET(checkbox));
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(container, &rect);
|
||||
rect.x1 += 5;
|
||||
rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5 + 25 + 25;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
/* 创建一个checkbox控件 */
|
||||
/* 创建一个checkbox控件 */
|
||||
checkbox = rtgui_checkbox_create("12 font", RT_TRUE);
|
||||
/* 设置字体为12点阵 */
|
||||
/* 设置字体为12点阵 */
|
||||
font = rtgui_font_refer("asc", 12);
|
||||
RTGUI_WIDGET_FONT(checkbox) = font;
|
||||
/* 设置checkbox的位置 */
|
||||
/* 设置checkbox的位置 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect);
|
||||
rtgui_container_add_child(container, RTGUI_WIDGET(checkbox));
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(container, &rect);
|
||||
rect.x1 += 5;
|
||||
rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5 + 25 + 25 + 25;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
/* 创建一个checkbox控件 */
|
||||
/* 创建一个checkbox控件 */
|
||||
checkbox = rtgui_checkbox_create("16 font", RT_TRUE);
|
||||
/* 设置字体为16点阵 */
|
||||
/* 设置字体为16点阵 */
|
||||
font = rtgui_font_refer("asc", 16);
|
||||
RTGUI_WIDGET_FONT(checkbox) = font;
|
||||
/* 设置checkbox的位置 */
|
||||
/* 设置checkbox的位置 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect);
|
||||
rtgui_container_add_child(container, RTGUI_WIDGET(checkbox));
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user