sync RTGUI with github(https://github.com/RT-Thread/RTGUI) 9ae08379da5b698d6facc40bd0415de2e254ae9c

As always, full log is in GitHub.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2449 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
dzzxzz@gmail.com 2012-11-26 02:42:52 +00:00
parent 9789907ca1
commit 62447b2cd8
131 changed files with 50561 additions and 49024 deletions

View File

@ -32,6 +32,7 @@ common/hz12font.c
common/hz16font.c
common/framebuffer_driver.c
common/pixel_driver.c
common/rtgui_mv_model.c
""")
server_src = Split("""
@ -68,10 +69,17 @@ widgets/window.c
widgets/panel.c
widgets/groupbox.c
widgets/edit.c
widgets/mv_view.c
widgets/plot.c
widgets/plot_curve.c
""")
if GetDepend('RTGUI_USING_FONT_COMPACT'):
import stract_cjk
common_src.append('common/font_cmp_hz16.c')
common_src.append('common/font_cmp_hz12.c')
RegisterPreBuildingAction(stract_cjk.gen_cmp_font_file)
# The set of source files associated with this SConscript file.
src = common_src + server_src + widgets_src

View File

@ -13,7 +13,8 @@
*/
#include <rtgui/font.h>
const rt_uint8_t asc12_font[] = {
const rt_uint8_t asc12_font[] =
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x81, 0xa5, 0x81,
0x81, 0xbd, 0x99, 0x81, 0x81, 0x7e, 0x00, 0x00, 0x7e, 0xff, 0xdb, 0xff, 0xff, 0xc3, 0xe7, 0xff,
0xff, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x6c, 0xfe, 0xfe, 0xfe, 0xfe, 0x7c, 0x38, 0x10, 0x00, 0x00,

View File

@ -14,7 +14,8 @@
#include <rtgui/font.h>
#ifdef RTGUI_USING_FONT16
const unsigned char asc16_font[] = {
const unsigned char asc16_font[] =
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7e, 0x81, 0xa5, 0x81, 0x81, 0xbd, 0x99, 0x81, 0x81, 0x7e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7e, 0xff, 0xdb, 0xff, 0xff, 0xc3, 0xe7, 0xff, 0xff, 0x7e, 0x00, 0x00, 0x00, 0x00,

View File

@ -33,7 +33,10 @@ static void rtgui_blit_line_3_1(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int li
/* 4 bpp to 1 bpp */
static void rtgui_blit_line_4_1(rt_uint8_t *dst_ptr, rt_uint8_t *src_ptr, int line)
{
struct _color {rt_uint8_t r, g, b, a;} *c;
struct _color
{
rt_uint8_t r, g, b, a;
} *c;
c = (struct _color *)src_ptr;
while (line-- > 0)
@ -75,7 +78,10 @@ static void rtgui_blit_line_3_2(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int li
/* 4 bpp to 2 bpp */
static void rtgui_blit_line_4_2(rt_uint8_t *dst_ptr, rt_uint8_t *src_ptr, int line)
{
struct _color {rt_uint8_t r, g, b, a;} *c;
struct _color
{
rt_uint8_t r, g, b, a;
} *c;
rt_uint16_t *ptr;
c = (struct _color *)src_ptr;

View File

@ -172,7 +172,8 @@ void rtgui_dc_fill_rect_forecolor(struct rtgui_dc* dc, struct rtgui_rect* rect)
{
rtgui_dc_draw_hline(dc, rect->x1 + 1, rect->x2 - 1, rect->y1 + i);
i++;
}while(!(rect->y1+i == rect->y2));
}
while (!(rect->y1 + i == rect->y2));
}
RTM_EXPORT(rtgui_dc_fill_rect_forecolor);
@ -529,27 +530,37 @@ void rtgui_dc_fill_polygon(struct rtgui_dc* dc, const int* vx, const int* vy, in
/*
* Draw, scanning y
*/
for (y = miny; (y <= maxy); y++) {
for (y = miny; (y <= maxy); y++)
{
ints = 0;
for (i = 0; (i < count); i++) {
if (!i) {
for (i = 0; (i < count); i++)
{
if (!i)
{
ind1 = count - 1;
ind2 = 0;
} else {
}
else
{
ind1 = i - 1;
ind2 = i;
}
y1 = vy[ind1];
y2 = vy[ind2];
if (y1 < y2) {
if (y1 < y2)
{
x1 = vx[ind1];
x2 = vx[ind2];
} else if (y1 > y2) {
}
else if (y1 > y2)
{
y2 = vy[ind1];
y1 = vy[ind2];
x2 = vx[ind1];
x1 = vx[ind2];
} else {
}
else
{
continue;
}
@ -649,7 +660,8 @@ void rtgui_dc_draw_circle(struct rtgui_dc* dc, int x, int y, int r)
cy--;
}
cx++;
}while (cx <= cy);
}
while (cx <= cy);
}
RTM_EXPORT(rtgui_dc_draw_circle);
@ -682,30 +694,40 @@ void rtgui_dc_fill_circle(struct rtgui_dc* dc, rt_int16_t x, rt_int16_t y, rt_in
/*
* Draw
*/
do {
do
{
xpcx = x + cx;
xmcx = x - cx;
xpcy = x + cy;
xmcy = x - cy;
if (ocy != cy) {
if (cy > 0) {
if (ocy != cy)
{
if (cy > 0)
{
ypcy = y + cy;
ymcy = y - cy;
rtgui_dc_draw_hline(dc, xmcx, xpcx, ypcy);
rtgui_dc_draw_hline(dc, xmcx, xpcx, ymcy);
} else {
}
else
{
rtgui_dc_draw_hline(dc, xmcx, xpcx, y);
}
ocy = cy;
}
if (ocx != cx) {
if (cx != cy) {
if (cx > 0) {
if (ocx != cx)
{
if (cx != cy)
{
if (cx > 0)
{
ypcx = y + cx;
ymcx = y - cx;
rtgui_dc_draw_hline(dc, xmcy, xpcy, ymcx);
rtgui_dc_draw_hline(dc, xmcy, xpcy, ypcx);
} else {
}
else
{
rtgui_dc_draw_hline(dc, xmcy, xpcy, y);
}
}
@ -714,18 +736,22 @@ void rtgui_dc_fill_circle(struct rtgui_dc* dc, rt_int16_t x, rt_int16_t y, rt_in
/*
* Update
*/
if (df < 0) {
if (df < 0)
{
df += d_e;
d_e += 2;
d_se += 2;
} else {
}
else
{
df += d_se;
d_e += 2;
d_se += 4;
cy--;
}
cx++;
} while (cx <= cy);
}
while (cx <= cy);
}
RTM_EXPORT(rtgui_dc_fill_circle);
@ -790,7 +816,8 @@ void rtgui_dc_draw_arc(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16
oct = startoct - 1; // we increment as first step in loop
//stopval_start, stopval_end; // what values of cx to stop at.
do {
do
{
oct = (oct + 1) % 8;
if (oct == startoct)
@ -869,10 +896,13 @@ void rtgui_dc_draw_arc(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16
}
else if (oct % 2) drawoct &= 255 - (1 << oct);
else drawoct |= (1 << oct);
} else if (oct != startoct) { // already verified that it's != endoct
}
else if (oct != startoct) // already verified that it's != endoct
{
drawoct |= (1 << oct); // draw this entire segment
}
} while (oct != endoct);
}
while (oct != endoct);
// so now we have what octants to draw and when to draw them. all that's left is the actual raster code.
do
@ -945,7 +975,8 @@ void rtgui_dc_draw_arc(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16
}
cx++;
} while (cx <= cy);
}
while (cx <= cy);
}
RTM_EXPORT(rtgui_dc_draw_arc);
@ -1066,7 +1097,8 @@ void rtgui_dc_fill_sector(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_in
start ++;
rtgui_dc_draw_line(dc, x, y, start_x, start_y);
}while(!((start_x == end_x) && (start_y == end_y)));
}
while (!((start_x == end_x) && (start_y == end_y)));
}
RTM_EXPORT(rtgui_dc_fill_sector);
@ -1160,7 +1192,8 @@ void rtgui_dc_draw_ellipse(struct rtgui_dc* dc, rt_int16_t x, rt_int16_t y, rt_i
ix = ix + iy / rx;
iy = iy - ix / rx;
} while (i > h);
}
while (i > h);
}
else
{
@ -1214,7 +1247,8 @@ void rtgui_dc_draw_ellipse(struct rtgui_dc* dc, rt_int16_t x, rt_int16_t y, rt_i
ix = ix + iy / ry;
iy = iy - ix / ry;
} while (i > h);
}
while (i > h);
}
}
RTM_EXPORT(rtgui_dc_draw_ellipse);
@ -1239,7 +1273,8 @@ void rtgui_dc_fill_ellipse(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_i
}
/* special case for ry=0 - draw a hline */
if (ry == 0) {
if (ry == 0)
{
rtgui_dc_draw_hline(dc, x - rx, x + rx, y);
return;
}
@ -1252,34 +1287,44 @@ void rtgui_dc_fill_ellipse(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_i
/*
* Draw
*/
if (rx > ry) {
if (rx > ry)
{
ix = 0;
iy = rx * 64;
do {
do
{
h = (ix + 32) >> 6;
i = (iy + 32) >> 6;
j = (h * ry) / rx;
k = (i * ry) / rx;
if ((ok != k) && (oj != k)) {
if ((ok != k) && (oj != k))
{
xph = x + h;
xmh = x - h;
if (k > 0) {
if (k > 0)
{
rtgui_dc_draw_hline(dc, xmh, xph, y + k);
rtgui_dc_draw_hline(dc, xmh, xph, y - k);
} else {
}
else
{
rtgui_dc_draw_hline(dc, xmh, xph, y);
}
ok = k;
}
if ((oj != j) && (ok != j) && (k != j)) {
if ((oj != j) && (ok != j) && (k != j))
{
xmi = x - i;
xpi = x + i;
if (j > 0) {
if (j > 0)
{
rtgui_dc_draw_hline(dc, xmi, xpi, y + j);
rtgui_dc_draw_hline(dc, xmi, xpi, y - j);
} else {
}
else
{
rtgui_dc_draw_hline(dc, xmi, xpi, y);
}
oj = j;
@ -1288,42 +1333,55 @@ void rtgui_dc_fill_ellipse(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_i
ix = ix + iy / rx;
iy = iy - ix / rx;
} while (i > h);
} else {
}
while (i > h);
}
else
{
ix = 0;
iy = ry * 64;
do {
do
{
h = (ix + 32) >> 6;
i = (iy + 32) >> 6;
j = (h * rx) / ry;
k = (i * rx) / ry;
if ((oi != i) && (oh != i)) {
if ((oi != i) && (oh != i))
{
xmj = x - j;
xpj = x + j;
if (i > 0) {
if (i > 0)
{
rtgui_dc_draw_hline(dc, xmj, xpj, y + i);
rtgui_dc_draw_hline(dc, xmj, xpj, y - i);
} else {
}
else
{
rtgui_dc_draw_hline(dc, xmj, xpj, y);
}
oi = i;
}
if ((oh != h) && (oi != h) && (i != h)) {
if ((oh != h) && (oi != h) && (i != h))
{
xmk = x - k;
xpk = x + k;
if (h > 0) {
if (h > 0)
{
rtgui_dc_draw_hline(dc, xmk, xpk, y + h);
rtgui_dc_draw_hline(dc, xmk, xpk, y - h);
} else {
}
else
{
rtgui_dc_draw_hline(dc, xmk, xpk, y);
}
oh = h;
}
ix = ix + iy / ry;
iy = iy - ix / ry;
} while (i > h);
}
while (i > h);
}
}
RTM_EXPORT(rtgui_dc_fill_ellipse);

View File

@ -138,7 +138,7 @@ struct rtgui_dc* rtgui_dc_client_create(rtgui_widget_t* owner)
if (top->drawing == 1)
{
#ifdef RTGUI_USING_MOUSE_CURSOR
#ifdef _WIN32
#ifdef _WIN32_NATIVE
rt_mutex_take(&cursor_mutex, RT_WAITING_FOREVER);
rt_kprintf("hide cursor\n");
rtgui_mouse_hide_cursor();
@ -160,7 +160,7 @@ struct rtgui_dc* rtgui_dc_client_create(rtgui_widget_t* owner)
if (top->drawing == 1)
{
#ifdef _WIN32
#ifdef _WIN32_NATIVE
#ifdef RTGUI_USING_MOUSE_CURSOR
rt_mutex_take(&cursor_mutex, RT_WAITING_FOREVER);
rt_kprintf("hide cursor\n");
@ -197,7 +197,7 @@ static rt_bool_t rtgui_dc_client_fini(struct rtgui_dc* dc)
top->drawing --;
if ((top->drawing == 0) && RTGUI_WIDGET_IS_DC_VISIBLE(owner))
{
#ifdef _WIN32
#ifdef _WIN32_NATIVE
#ifdef RTGUI_USING_MOUSE_CURSOR
rt_mutex_release(&cursor_mutex);
/* show cursor */
@ -225,7 +225,7 @@ static rt_bool_t rtgui_dc_client_fini(struct rtgui_dc* dc)
if ((top->drawing == 0) && RTGUI_WIDGET_IS_DC_VISIBLE(owner))
{
#ifdef _WIN32
#ifdef _WIN32_NATIVE
#ifdef RTGUI_USING_MOUSE_CURSOR
rt_mutex_release(&cursor_mutex);
/* show cursor */

View File

@ -108,7 +108,7 @@ struct rtgui_dc* rtgui_dc_hw_create(rtgui_widget_t* owner)
if (top->drawing == 1)
{
#ifdef RTGUI_USING_MOUSE_CURSOR
#ifdef _WIN32
#ifdef _WIN32_NATIVE
rt_mutex_take(&cursor_mutex, RT_WAITING_FOREVER);
rt_kprintf("hide cursor\n");
rtgui_mouse_hide_cursor();
@ -127,7 +127,7 @@ struct rtgui_dc* rtgui_dc_hw_create(rtgui_widget_t* owner)
if (top->drawing == 1)
{
#ifdef _WIN32
#ifdef _WIN32_NATIVE
#ifdef RTGUI_USING_MOUSE_CURSOR
rt_mutex_take(&cursor_mutex, RT_WAITING_FOREVER);
rt_kprintf("hide cursor\n");
@ -166,7 +166,7 @@ static rt_bool_t rtgui_dc_hw_fini(struct rtgui_dc* dc)
top->drawing --;
if ((top->drawing == 0) && RTGUI_WIDGET_IS_DC_VISIBLE(owner))
{
#ifdef _WIN32
#ifdef _WIN32_NATIVE
#ifdef RTGUI_USING_MOUSE_CURSOR
rt_mutex_release(&cursor_mutex);
/* show cursor */
@ -194,7 +194,7 @@ static rt_bool_t rtgui_dc_hw_fini(struct rtgui_dc* dc)
if ((top->drawing == 0) && RTGUI_WIDGET_IS_DC_VISIBLE(owner))
{
#ifdef _WIN32
#ifdef _WIN32_NATIVE
#ifdef RTGUI_USING_MOUSE_CURSOR
rt_mutex_release(&cursor_mutex);
/* show cursor */
@ -231,13 +231,8 @@ static void rtgui_dc_hw_draw_point(struct rtgui_dc* self, int x, int y)
dc = (struct rtgui_dc_hw *) self;
x = x + dc->owner->extent.x1;
#if (0) /* Please yourself to decide whether to use it*/
if(x < dc->owner->extent.x1 || x >= dc->owner->extent.x2) return;
#endif
y = y + dc->owner->extent.y1;
#if (0)
if(y < dc->owner->extent.y1 || y >= dc->owner->extent.y2) return;
#endif
/* draw this point */
dc->hw_driver->ops->set_pixel(&(dc->owner->gc.foreground), x, y);
}

View File

@ -112,7 +112,8 @@ static int mem_seek(struct rtgui_filerw *context, rt_off_t offset, int whence)
RT_ASSERT(mem != RT_NULL);
switch (whence) {
switch (whence)
{
case RTGUI_FILE_SEEK_SET:
newpos = mem->mem_base + offset;
break;
@ -213,12 +214,23 @@ static int parse_mode(const char *mode)
{
switch (*mode)
{
case 0: return f;
case 'b': f|=O_BINARY;break;
case 'r': f=O_RDONLY; break;
case 'w': f=O_WRONLY|O_CREAT|O_TRUNC; break;
case 'a': f=O_WRONLY|O_CREAT|O_APPEND; break;
case '+': f=(f&(~O_WRONLY))|O_RDWR; break;
case 0:
return f;
case 'b':
f |= O_BINARY;
break;
case 'r':
f = O_RDONLY;
break;
case 'w':
f = O_WRONLY | O_CREAT | O_TRUNC;
break;
case 'a':
f = O_WRONLY | O_CREAT | O_APPEND;
break;
case '+':
f = (f & (~O_WRONLY)) | O_RDWR;
break;
}
++mode;
@ -233,7 +245,7 @@ struct rtgui_filerw* rtgui_filerw_create_file(const char* filename, const char*
RT_ASSERT(filename != RT_NULL);
rw = RT_NULL;
#ifdef _WIN32
#ifdef _WIN32_NATIVE
fd = _open(filename, parse_mode(mode), 0);
#else
fd = open(filename, parse_mode(mode), 0);
@ -261,11 +273,16 @@ struct rtgui_filerw* rtgui_filerw_create_file(const char* filename, const char*
int rtgui_filerw_unlink(const char *filename)
{
#ifdef _WIN32
#ifdef _WIN32_NATIVE
return _unlink(filename);
#else
#ifndef RT_USING_DFS
/* no unlink function */
return -1;
#else
return unlink(filename);
#endif
#endif
}
#endif

View File

@ -86,7 +86,7 @@ void rtgui_font_set_defaut(struct rtgui_font* font)
rtgui_default_font = font;
}
struct rtgui_font* rtgui_font_refer(const rt_uint8_t* family, rt_uint16_t height)
struct rtgui_font *rtgui_font_refer(const char *family, rt_uint16_t height)
{
/* search font */
struct rtgui_list_node *node;
@ -95,7 +95,7 @@ struct rtgui_font* rtgui_font_refer(const rt_uint8_t* family, rt_uint16_t height
rtgui_list_foreach(node, &_rtgui_font_list)
{
font = rtgui_list_entry(node, struct rtgui_font, list);
if ((rt_strncmp((const char*)font->family, (const char*)family, RTGUI_NAME_MAX) == 0) &&
if ((rt_strncmp(font->family, family, RTGUI_NAME_MAX) == 0) &&
font->height == height)
{
font->refer_count ++;

View File

@ -152,7 +152,8 @@ static void rtgui_bitmap_font_get_metrics(struct rtgui_font* font, const char* t
RT_ASSERT(bmp_font != RT_NULL);
/* set init metrics rect */
rect->x1 = rect->y1 = 0;rect->x2 = 0;
rect->x1 = rect->y1 = 0;
rect->x2 = 0;
rect->y2 = bmp_font->height;
while (*text)

View File

@ -143,8 +143,10 @@ static void rtgui_freetype_font_get_metrics(struct rtgui_font* font, const char*
text_ptr ++;
}
rect->x1 = 0; rect->y1 = 0;
rect->x2 = w; rect->y2 = h;
rect->x1 = 0;
rect->y1 = 0;
rect->x2 = w;
rect->y2 = h;
/* release unicode buffer */
rtgui_free(text_short);

View File

@ -14,11 +14,49 @@ const struct rtgui_font_engine hz_bmp_font_engine =
rtgui_hz_bitmap_font_get_metrics
};
#ifdef RTGUI_USING_FONT_COMPACT
extern rt_uint32_t rtgui_font_mph12(const rt_uint16_t key);
extern rt_uint32_t rtgui_font_mph16(const rt_uint16_t key);
rt_inline const rt_uint8_t *_rtgui_hz_bitmap_get_font_ptr(struct rtgui_font_bitmap *bmp_font,
rt_uint8_t *str,
rt_base_t font_bytes)
{
rt_uint16_t cha = *(rt_uint16_t *)str;
int idx;
if (bmp_font->height == 16)
idx = rtgui_font_mph16(cha);
else // asume the height is 12
idx = rtgui_font_mph12(cha);
/* don't access beyond the data */
if (idx < 0)
idx = 0;
/* get font pixel data */
return bmp_font->bmp + idx * font_bytes;
}
#else
rt_inline const rt_uint8_t *_rtgui_hz_bitmap_get_font_ptr(struct rtgui_font_bitmap *bmp_font,
rt_uint8_t *str,
rt_base_t font_bytes)
{
rt_ubase_t sect, index;
/* calculate section and index */
sect = *str - 0xA0;
index = *(str + 1) - 0xA0;
/* get font pixel data */
return bmp_font->bmp + (94 * (sect - 1) + (index - 1)) * font_bytes;
}
#endif
static void _rtgui_hz_bitmap_font_draw_text(struct rtgui_font_bitmap *bmp_font, struct rtgui_dc *dc, const char *text, rt_ubase_t len, struct rtgui_rect *rect)
{
rt_uint8_t* str;
rtgui_color_t bc;
rt_uint16_t style;
rt_uint8_t *str;
register rt_base_t h, word_bytes, font_bytes;
RT_ASSERT(bmp_font != RT_NULL);
@ -37,15 +75,10 @@ static void _rtgui_hz_bitmap_font_draw_text(struct rtgui_font_bitmap* bmp_font,
while (len > 0 && rect->x1 < rect->x2)
{
const rt_uint8_t *font_ptr;
rt_ubase_t sect, index;
register rt_base_t i, j, k;
/* calculate section and index */
sect = *str - 0xA0;
index = *(str+1) - 0xA0;
/* get font pixel data */
font_ptr = bmp_font->bmp + (94 * (sect - 1) + (index - 1)) * font_bytes;
font_ptr = _rtgui_hz_bitmap_get_font_ptr(bmp_font, str, font_bytes);
/* draw word */
for (i = 0; i < h; i ++)
{

View File

@ -7,7 +7,7 @@
#include <rtgui/rtgui_system.h>
#ifdef RTGUI_USING_HZ_FILE
#ifdef _WIN32
#ifdef _WIN32_NATIVE
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>

View File

@ -0,0 +1,35 @@
/* adapted from utils/perfect_hash/example1-C/states-tmpl.c */
#include <rtthread.h>
#include <string.h>
static const rt_uint32_t T1[] = { $S1 };
static const rt_uint32_t T2[] = { $S2 };
static const rt_uint16_t G[] = { $G };
static rt_uint32_t hash_g(const rt_uint16_t key, const rt_uint32_t *T)
{
rt_uint32_t sum = (T[0] * (key & 0xFF) + T[1] * (key >> 8)) % $NG;
return G[sum % $NG];
}
static rt_uint32_t perfect_hash(const rt_uint16_t key)
{
return (hash_g(key, T1) + hash_g(key, T2)) % $NG;
}
rt_uint32_t rtgui_font_mph${height}(const rt_uint16_t key)
{
rt_uint32_t hash_value = perfect_hash(key);
/*rt_kprintf("hash 0x7684 is %d", perfect_hash(0x7684));*/
/*RT_ASSERT(K[hash_value] == key);*/
/* NOTE: we trust you will not feed invalid data into me. So there is no
* more sanity check which will consume more flash and memory. */
if (hash_value < $NK)
return hash_value;
return -1;
}
const unsigned char hz${height}_font[] = { $font_data };

View File

@ -2,7 +2,12 @@
#ifdef RTGUI_USING_FONT12
#ifndef RTGUI_USING_HZ_FILE
const unsigned char hz12_font[] = {
#ifdef RTGUI_USING_FONT_COMPACT
extern const unsigned char hz12_font[];
#else
const unsigned char hz12_font[] =
{
FONT_BMP_DATA_BEGIN
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x70, 0x00, 0x30, 0x00, 0x00, 0x00,
@ -12270,7 +12275,9 @@ const unsigned char hz12_font[] = {
0x10, 0x00, 0x3d, 0xf0, 0x24, 0x40, 0x3c, 0x40, 0x24, 0x40, 0x7f, 0xf0, 0x52, 0x40, 0x7e, 0x40,
0x00, 0x40, 0xff, 0x40, 0x24, 0x40, 0xc4, 0x40, 0x20, 0x80, 0x7b, 0xf0, 0x49, 0xc0, 0x7a, 0xa0,
0x4c, 0x90, 0xfb, 0xe0, 0xaa, 0x20, 0xfb, 0xe0, 0x02, 0x20, 0xff, 0xe0, 0x48, 0x00, 0x8b, 0xf0,
FONT_BMP_DATA_END
};
#endif
const struct rtgui_font_bitmap hz12 =
{
@ -12292,7 +12299,6 @@ struct rtgui_font rtgui_font_hz12 =
&hz_bmp_font_engine,/* font engine */
(void *) &hz12, /* font private data */
};
/* size = 196272 bytes */
#else
struct rtgui_hz_file_font hz12 =

View File

@ -2,7 +2,12 @@
#ifdef RTGUI_USING_FONT16
#ifndef RTGUI_USING_HZ_FILE
const unsigned char hz16_font[] = {
#ifdef RTGUI_USING_FONT_COMPACT
extern const unsigned char hz16_font[];
#else
const unsigned char hz16_font[] =
{
FONT_BMP_DATA_BEGIN
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -16728,7 +16733,10 @@ const unsigned char hz16_font[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
FONT_BMP_DATA_END
};
#endif
const struct rtgui_font_bitmap hz16 =
{
@ -16750,7 +16758,6 @@ struct rtgui_font rtgui_font_hz16 =
&hz_bmp_font_engine,/* font engine */
(void *) &hz16, /* font private data */
};
/* size = 267616 bytes */
#else
struct rtgui_hz_file_font hz16 =

View File

@ -21,6 +21,9 @@
#include <rtgui/image_container.h>
#include <string.h>
#ifdef _WIN32
#define strncasecmp strnicmp
#endif
#ifdef RTGUI_IMAGE_XPM
#include <rtgui/image_xpm.h>
@ -92,7 +95,11 @@ struct rtgui_image_engine* rtgui_image_get_engine_by_filename(const char* fn)
ext = fn + rt_strlen(fn);
while (ext != fn)
{
if (*ext == '.') { ext ++; break; }
if (*ext == '.')
{
ext ++;
break;
}
ext --;
}
if (ext == fn) return RT_NULL; /* no ext */
@ -311,8 +318,10 @@ void rtgui_image_get_rect(struct rtgui_image* image, struct rtgui_rect* rect)
RT_ASSERT(image != RT_NULL);
RT_ASSERT(rect != RT_NULL);
rect->x1 = 0; rect->y1 = 0;
rect->x2 = image->w; rect->y2 = image->h;
rect->x1 = 0;
rect->y1 = 0;
rect->x2 = image->w;
rect->y2 = image->h;
}
RTM_EXPORT(rtgui_image_get_rect);

View File

@ -1112,7 +1112,8 @@ static struct rtgui_image* rtgui_image_bmp_zoom(struct rtgui_image* image,
int x = (int)(scalew * j);
float v = (float)(scalew * j - x);
if (bitcount == 16)
{ /* Each color component is calculated separately */
{
/* Each color component is calculated separately */
rt_uint32_t cc1, cc2, cc3, cc4;
unsigned char r, g, b;
cc1 = rtgui_color_from_565p(*(rt_uint16_t *)(src_buf +
@ -1141,7 +1142,8 @@ static struct rtgui_image* rtgui_image_bmp_zoom(struct rtgui_image* image,
{
int k;
for (k = 0; k < 3; k++)
{ /* 24 bits color is 3 bytes R:G:B */
{
/* 24 bits color is 3 bytes R:G:B */
c1 = (src_buf[src_line_size * y + nbytes * x + k]);
c2 = (src_buf[src_line_size * y + nbytes * (x + 1) + k]);
c3 = (src_buf[src_line_size * (y + 1) + nbytes * x + k]);
@ -1225,7 +1227,8 @@ static struct rtgui_image* rtgui_image_bmp_rotate(struct rtgui_image* image, flo
dw = (int)(sw *fabs(cosa) + sh *fabs(sina));
dh = (int)(sh *fabs(cosa) + sw *fabs(sina));
rect.x1 = rect.y1 = 0;
rect.x2 = sw; rect.y2 = sh;
rect.x2 = sw;
rect.y2 = sh;
d_img = rt_malloc(sizeof(struct rtgui_image));
if (d_img == RT_NULL)
@ -1278,7 +1281,8 @@ static struct rtgui_image* rtgui_image_bmp_rotate(struct rtgui_image* image, flo
{
for (j = 0; j < dw; j++)
{
p.x = j; p.y = i;
p.x = j;
p.y = i;
cp = _rotate_pos(o, p, sina, cosa);
cp.x -= (dw - sw) >> 1;
cp.y -= (dh - sh) >> 1;

View File

@ -89,12 +89,17 @@ static rt_bool_t rtgui_image_hdc_load(struct rtgui_image* image, struct rtgui_fi
if (hdc == RT_NULL) return RT_FALSE;
hdc->hw_driver = rtgui_graphic_driver_get_default();
if (hdc->hw_driver == RT_NULL) { rtgui_free(hdc); return RT_FALSE; }
if (hdc->hw_driver == RT_NULL)
{
rtgui_free(hdc);
return RT_FALSE;
}
rtgui_filerw_read(file, (char *)&header, 1, sizeof(header));
/* set image information */
image->w = (rt_uint16_t)header[1]; image->h = (rt_uint16_t)header[2];
image->w = (rt_uint16_t)header[1];
image->h = (rt_uint16_t)header[2];
image->engine = &rtgui_image_hdc_engine;
image->data = hdc;
hdc->filerw = file;

View File

@ -634,11 +634,13 @@ static UINT tjpgd_out_func(JDEC *jdec, void *bitmap, JRECT *rect)
rt_uint16_t rectWidth; /* Width of source rectangular (bytes) */
rt_uint8_t *src, *dst;
#ifdef RTGUI_DEBUG_TJPGD
/* Put progress indicator */
if (rect->left == 0)
{
rt_kprintf("\r%lu%%", (rect->top << jpeg->scale) * 100UL / jdec->height);
}
#endif
/* Copy the decompressed RGB rectanglar to the frame buffer */
rectWidth = (rect->right - rect->left + 1) * jpeg->byte_per_pixel;
@ -747,7 +749,9 @@ static rt_bool_t rtgui_image_jpeg_check(struct rtgui_filerw *file)
is_JPG = RT_TRUE;
}
#ifdef RTGUI_DEBUG_TJPGD
rt_kprintf("TJPGD: check OK\n");
#endif
}
while (0);
@ -809,7 +813,9 @@ static rt_bool_t rtgui_image_jpeg_load(struct rtgui_image *image, struct rtgui_f
}
break;
}
#ifdef RTGUI_DEBUG_TJPGD
rt_kprintf("TJPGD: prepare OK\n");
#endif
image->w = (rt_uint16_t)jpeg->tjpgd.width >> jpeg->scale;
image->h = (rt_uint16_t)jpeg->tjpgd.height >> jpeg->scale;
@ -838,7 +844,9 @@ static rt_bool_t rtgui_image_jpeg_load(struct rtgui_image *image, struct rtgui_f
rtgui_filerw_close(jpeg->filerw);
jpeg->is_loaded = RT_TRUE;
#ifdef RTGUI_DEBUG_TJPGD
rt_kprintf("TJPGD: load to RAM\n");
#endif
}
res = RT_TRUE;
}
@ -886,7 +894,9 @@ static void rtgui_image_jpeg_unload(struct rtgui_image *image)
}
rt_free(jpeg);
}
#ifdef RTGUI_DEBUG_TJPGD
rt_kprintf("TJPGD: unload\n");
#endif
}
static void rtgui_image_jpeg_blit(struct rtgui_image *image,
@ -938,7 +948,9 @@ static void rtgui_image_jpeg_blit(struct rtgui_image *image,
{
break;
}
#ifdef RTGUI_DEBUG_TJPGD
rt_kprintf("TJPGD: load to display\n");
#endif
}
else
{

View File

@ -170,7 +170,8 @@ static rt_bool_t rtgui_image_png_load(struct rtgui_image* image, struct rtgui_fi
&color_type, NULL, NULL, NULL);
/* set image information */
image->w = width; image->h = height;
image->w = width;
image->h = height;
image->engine = &rtgui_image_png_engine;
image->data = png;
@ -297,7 +298,8 @@ static void rtgui_image_png_blit(struct rtgui_image* image, struct rtgui_dc* dc,
rtgui_dc_draw_color_point(dc, x + rect->x1, y + rect->y1, c);
}
else
{ /* output = alpha * foreground + (1-alpha) * background */
{
/* output = alpha * foreground + (1-alpha) * background */
/*
* Compositing is necessary.
* Get floating-point alpha and its complement.

View File

@ -46,7 +46,8 @@ struct rgb_item
int b;
};
const struct rgb_item rgbRecord[234] = {
const struct rgb_item rgbRecord[234] =
{
{"AliceBlue", 240, 248, 255},
{"AntiqueWhite", 250, 235, 215},
{"Aquamarine", 50, 191, 193},
@ -390,10 +391,14 @@ int strcasecmp( const char* s1, const char* s2 )
register unsigned int x2;
register unsigned int x1;
while (1) {
x2 = *s2 - 'A'; if (x2 < 26u) x2 += 32;
x1 = *s1 - 'A'; if (x1 < 26u) x1 += 32;
s1++; s2++;
while (1)
{
x2 = *s2 - 'A';
if (x2 < 26u) x2 += 32;
x1 = *s1 - 'A';
if (x1 < 26u) x1 += 32;
s1++;
s2++;
if (x2 != x1)
break;
if (x1 == (unsigned int) - 'A')

View File

@ -2046,7 +2046,8 @@ static void QuickSortSpans(
yprev = spans[0].y;
i = 1;
do
{ /* while i != numSpans */
{
/* while i != numSpans */
y = spans[i].y;
if (yprev > y)
{

View File

@ -285,6 +285,13 @@ rt_bool_t rtgui_app_event_handler(struct rtgui_object* object, rtgui_event_t* ev
}
break;
case RTGUI_EVENT_MV_MODEL:
{
struct rtgui_event_mv_model *emodel = (struct rtgui_event_mv_model *)event;
RT_ASSERT(emodel->view);
return rtgui_object_handle(RTGUI_OBJECT(emodel->view), event);
}
case RTGUI_EVENT_COMMAND:
{
struct rtgui_event_command *ecmd = (struct rtgui_event_command *)event;
@ -292,9 +299,11 @@ rt_bool_t rtgui_app_event_handler(struct rtgui_object* object, rtgui_event_t* ev
if (ecmd->wid != RT_NULL)
return _rtgui_application_dest_handle(app, event);
}
default:
return rtgui_object_event_handler(object, event);
}
return rtgui_object_event_handler(object, event);
return RT_TRUE;
}
rt_inline void _rtgui_application_event_loop(struct rtgui_app *app)

View File

@ -0,0 +1,454 @@
/*
* File : rtgui_mv_model.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2012-09-15 Grissiom first version
*/
#include <rtgui/rtgui.h>
#include <rtgui/rtgui_app.h>
#include <rtgui/rtgui_object.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/rtgui_mv_model.h>
#include <rtgui/widgets/mv_view.h>
#include <rtgui/widgets/window.h>
static void _rtgui_mv_model_bare_remove(struct rtgui_mv_model *model, struct rtgui_mv_view *view);
static void _rtgui_mv_view_bare_remove(struct rtgui_mv_view *view, struct rtgui_mv_model *model);
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);
static void _rtgui_mv_model_constructor(struct rtgui_mv_model *model)
{
model->dimension = 0;
model->length = 0;
model->data = RT_NULL;
model->view_number = 0;
model->view = RT_NULL;
/* currently not interested in any event */
rtgui_object_set_event_handler(RTGUI_OBJECT(model), RT_NULL);
}
static void _rtgui_mv_model_destructor(struct rtgui_mv_model *model)
{
if (model->view_number == 1)
{
rtgui_mv_model_remove_view(model, model->view);
}
else if (model->view_number > 1)
{
int i;
struct rtgui_mv_view **view_arr = (struct rtgui_mv_view **)(model)->view;
for (i = 0; i < model->view_number; i++)
{
rtgui_mv_model_remove_view(model, view_arr[i]);
}
}
if (model->dimension > 1)
rtgui_free(model->data);
}
DEFINE_CLASS_TYPE(mv_model, "mv_model",
RTGUI_OBJECT_TYPE,
_rtgui_mv_model_constructor,
_rtgui_mv_model_destructor,
sizeof(struct rtgui_mv_model));
struct rtgui_mv_model *rtgui_mv_model_create(rt_uint16_t dimension)
{
struct rtgui_mv_model *model;
RT_ASSERT(dimension);
model = RTGUI_MV_MODEL(rtgui_object_create(RTGUI_MV_MODEL_TYPE));
if (model == RT_NULL)
return RT_NULL;
if (rtgui_mv_model_set_dimension(model, dimension) != RT_EOK)
{
rtgui_object_destroy(RTGUI_OBJECT(model));
return RT_NULL;
}
return model;
}
RTM_EXPORT(rtgui_mv_model_create);
rt_err_t rtgui_mv_model_set_dimension(struct rtgui_mv_model *model, rt_uint16_t dimension)
{
if (dimension == 1)
{
if (model->dimension > 1)
rtgui_free(model->data);
model->data = RT_NULL;
}
else
{
void *data;
if (model->dimension > 1)
rtgui_free(model->data);
data = rtgui_malloc(sizeof(void *)*dimension);
if (data == RT_NULL)
{
return -RT_ENOMEM;
}
rt_memset(data, 0, sizeof(void *)*dimension);
model->data = data;
}
model->dimension = dimension;
return RT_EOK;
}
RTM_EXPORT(rtgui_mv_model_set_dimension);
void rtgui_mv_model_destroy(struct rtgui_mv_model *model)
{
rtgui_object_destroy(RTGUI_OBJECT(model));
}
RTM_EXPORT(rtgui_mv_model_destroy);
rt_err_t rtgui_mv_model_add_view(struct rtgui_mv_model *model, struct rtgui_mv_view *view)
{
RT_ASSERT(model);
if (view == RT_NULL)
return RT_EOK;
/* add view to model */
if (model->view_number == 0)
{
model->view = view;
}
else if (model->view_number == 1)
{
/* create the array of view pointers */
struct rtgui_mv_view **new_view;
if (view == model->view)
return RT_EOK;
new_view = rtgui_malloc(2 * sizeof(struct rtgui_mv_view *));
if (new_view == RT_NULL)
return -RT_ENOMEM;
new_view[0] = model->view;
new_view[1] = view;
model->view = new_view;
}
else
{
int i;
struct rtgui_mv_view **new_view;
struct rtgui_mv_view **view_arr = (struct rtgui_mv_view **)(model)->view;
for (i = 0; i < model->view_number; i++)
{
if (view == view_arr[i])
return RT_EOK;
}
new_view = rtgui_realloc(model->view,
(model->view_number + 1) * sizeof(struct rtgui_mv_view *));
if (new_view == RT_NULL)
return -RT_ENOMEM;
new_view[model->view_number] = view;
model->view = new_view;
}
model->view_number++;
/* add model to view. Roll back previous action on fail. */
if (view->model_number == 0)
{
view->model = model;
}
else if (view->model_number == 1)
{
struct rtgui_mv_model **new_arr = rtgui_malloc(2 * sizeof(struct rtgui_mv_model *));
if (new_arr == RT_NULL)
{
_rtgui_mv_model_bare_remove(model, view);
return -RT_ENOMEM;
}
new_arr[0] = view->model;
new_arr[1] = model;
view->model = new_arr;
}
else
{
struct rtgui_mv_model **new_arr = rtgui_realloc(view->model,
(view->model_number + 1) * sizeof(struct rtgui_mv_model *));
if (new_arr == RT_NULL)
{
_rtgui_mv_model_bare_remove(model, view);
return -RT_ENOMEM;
}
new_arr[view->model_number] = model;
view->model = new_arr;
}
view->model_number++;
return RT_EOK;
}
RTM_EXPORT(rtgui_mv_model_add_view);
static void _rtgui_mv_model_bare_remove(struct rtgui_mv_model *model, struct rtgui_mv_view *view)
{
int i;
if (model->view_number == 1)
{
if (model->view == view)
{
model->view_number--;
model->view = RT_NULL;
}
return;
}
for (i = 0; i < model->view_number; i++)
{
struct rtgui_mv_view **view_arr = (struct rtgui_mv_view **)(model)->view;
if (view == view_arr[i])
break;
}
/* no match */
if (i == model->view_number)
{
return;
}
else if (model->view_number == 2)
{
struct rtgui_mv_view **view_arr = (struct rtgui_mv_view **)(model)->view;
struct rtgui_mv_view *the_view = view_arr[(i + 1) % 2];
rtgui_free(model->view);
model->view = the_view;
model->view_number--;
return;
}
else
{
struct rtgui_mv_view **view_arr = (struct rtgui_mv_view **)(model)->view;
void *new_view;
for (; i < model->view_number - 1; i++)
{
view_arr[i] = view_arr[i + 1];
}
new_view = rtgui_realloc(model->view,
(model->view_number - 1) * sizeof(struct rtgui_mv_view *));
/* no need to be panic on OOM error. The original array is still there
* and we can operate it safely. So just ignore the NULL value returned
* by realloc. */
if (new_view != RT_NULL)
model->view = new_view;
model->view_number--;
return;
}
}
static void _rtgui_mv_view_bare_remove(struct rtgui_mv_view *view, struct rtgui_mv_model *model)
{
int i;
struct rtgui_mv_model **model_arr = (struct rtgui_mv_model **)(view)->model;
if (view->model_number == 1)
{
if (view->model == model)
{
view->model_number--;
view->model = RT_NULL;
}
return;
}
for (i = 0; i < view->model_number; i++)
{
if (model == model_arr[i])
break;
}
/* no match */
if (i == view->model_number)
{
return;
}
else if (view->model_number == 2)
{
struct rtgui_mv_model **model_arr = (struct rtgui_mv_model **)(view)->model;
struct rtgui_mv_model *the_model = model_arr[(i + 1) % 2];
rtgui_free(view->model);
view->model = the_model;
view->model_number--;
return;
}
else
{
struct rtgui_mv_model **model_arr = (struct rtgui_mv_model **)(view)->model;
void *new_model;
for (; i < view->model_number - 1; i++)
{
model_arr[i] = model_arr[i + 1];
}
new_model = rtgui_realloc(view->model,
(view->model_number - 1) * sizeof(struct rtgui_mv_model *));
/* no need to be panic on OOM error. The original array is still there
* and we can operate it safely. So just ignore the NULL value returned
* by realloc. */
if (new_model != RT_NULL)
view->model = new_model;
view->model_number--;
return;
}
}
void rtgui_mv_model_remove_view(struct rtgui_mv_model *model, struct rtgui_mv_view *view)
{
RT_ASSERT(model);
if (view == RT_NULL)
return;
if (model->length > 0)
{
struct rtgui_event_mv_model emodel;
RTGUI_EVENT_MV_MODEL_DELETED_INIT(&emodel);
emodel.first_data_changed_idx = 0;
emodel.last_data_changed_idx = model->length;
/* rtgui_mv_model_remove_view is to be called in thread context.
* Besides, it is called by _rtgui_mv_view_destructor which means the
* view will be invalid in the future. So we should call the event
* handler immediately. */
RTGUI_OBJECT(view)->event_handler(RTGUI_OBJECT(view), (struct rtgui_event *)&emodel);
}
_rtgui_mv_model_bare_remove(model, view);
_rtgui_mv_view_bare_remove(view, model);
}
RTM_EXPORT(rtgui_mv_model_remove_view);
rt_bool_t rtgui_mv_model_has_view(struct rtgui_mv_model *model, struct rtgui_mv_view *view)
{
RT_ASSERT(model);
if (view == RT_NULL || model->view_number == 0)
return RT_FALSE;
if (model->view_number == 1)
{
return model->view == view;
}
else
{
int i;
struct rtgui_mv_view **view_arr = (struct rtgui_mv_view **)(model)->view;
for (i = 0; i < model->view_number; i++)
{
if (view == view_arr[i])
return RT_TRUE;
}
return RT_FALSE;
}
}
RTM_EXPORT(rtgui_mv_model_has_view);
void rtgui_mv_model_set_data(struct rtgui_mv_model *model, rt_uint16_t dim, void *p)
{
RT_ASSERT(model);
RT_ASSERT(dim < model->dimension);
if (model->dimension == 1)
{
model->data = p;
return;
}
else
{
void **d_arr = (void **)model->data;
d_arr[dim] = p;
}
}
RTM_EXPORT(rtgui_mv_model_set_data);
void *rtgui_mv_model_get_data(struct rtgui_mv_model *model, rt_uint16_t dim)
{
RT_ASSERT(model);
RT_ASSERT(dim < model->dimension);
if (model->dimension == 1)
{
return model->data;
}
else
{
void **d_arr = (void **)model->data;
return d_arr[dim];
}
}
RTM_EXPORT(rtgui_mv_model_get_data);
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;
emodel->model = model;
emodel->view = view;
return rtgui_send(target, (struct rtgui_event *)emodel, sizeof(*emodel));
}
void rtgui_mv_model_notify(struct rtgui_mv_model *model,
struct rtgui_event_mv_model *em)
{
/* model and view may not be in the same thread. Actually, model may not
* belong to any RTGUI thread. So we have to notify the views by sending
* events to the thread directly. */
if (model->view_number == 1)
{
struct rtgui_mv_view *view = (struct rtgui_mv_view *)model->view;
_rtgui_mv_model_notify_view(model, view, em);
}
else
{
int i;
struct rtgui_mv_view **view_arr = (struct rtgui_mv_view **)(model)->view;
for (i = 0; i < model->view_number; i++)
{
_rtgui_mv_model_notify_view(model, view_arr[i], em);
}
}
}
RTM_EXPORT(rtgui_mv_model_notify);

View File

@ -94,10 +94,12 @@ struct rtgui_object_information obj_info = {0, 0, 0};
#endif
/**
* @brief Creates a new object: it calls the corresponding constructors (from the constructor of the base class to the
* constructor of the more derived class) and then sets the values of the given properties
* @brief Creates a new object: it calls the corresponding constructors
* (from the constructor of the base class to the constructor of the more
* derived class) and then sets the values of the given properties
*
* @param object_type the type of object to create
* @return Returns the new Etk_Object of type @a object_type
* @return the created object
*/
rtgui_object_t *rtgui_object_create(rtgui_type_t *object_type)
{
@ -125,11 +127,11 @@ rtgui_object_t *rtgui_object_create(rtgui_type_t *object_type)
RTM_EXPORT(rtgui_object_create);
/**
* @brief Destroys the object: it first sets the weak-pointers to RT_NULL, emits the "destroyed" signal, and then
* queues the object in the list of objects to free. Thus, the destructors will only be called at the beginning of the
* next main loop iteration (from the destructor of the more derived class to the destructor of the ultimate base class).
* @brief Destroys the object.
*
* The object destructors will be called in inherited type order.
*
* @param object the object to destroy
* @warning You should not assume that this function will call directly the destructors of the object!
*/
void rtgui_object_destroy(rtgui_object_t *object)
{
@ -151,12 +153,14 @@ void rtgui_object_destroy(rtgui_object_t *object)
RTM_EXPORT(rtgui_object_destroy);
/**
* @brief Checks if @a object can be cast to @a type.
* If @a object doesn't inherit from @a type, a warning is displayed in the console but the object is returned anyway.
* @brief Checks if the object can be cast to the specified type.
*
* If the object doesn't inherit from the specified type, a warning
* is displayed in the console but the object is returned anyway.
*
* @param object the object to cast
* @param type the type to which we cast the object
* @return Returns the object
* @note You usually do not need to call this function, use specific macros instead (ETK_IS_WIDGET() for example)
*/
rtgui_object_t *rtgui_object_check_cast(rtgui_object_t *obj, rtgui_type_t *obj_type, const char *func, int line)
{
@ -164,7 +168,8 @@ rtgui_object_t *rtgui_object_check_cast(rtgui_object_t *obj, rtgui_type_t *obj_t
if (!rtgui_type_inherits_from(obj->type, obj_type))
{
rt_kprintf("%s[%d]: Invalid cast from \"%s\" to \"%s\"\n", func, line, rtgui_type_name_get(obj->type), rtgui_type_name_get(obj_type));
rt_kprintf("%s[%d]: Invalid cast from \"%s\" to \"%s\"\n", func, line,
rtgui_type_name_get(obj->type), rtgui_type_name_get(obj_type));
}
return obj;
@ -174,8 +179,9 @@ RTM_EXPORT(rtgui_object_check_cast);
/**
* @brief Gets the type of the object
*
* @param object an object
* @return Returns the type of @a object (RT_NULL on failure)
* @return the type of the object (RT_NULL on failure)
*/
const rtgui_type_t *rtgui_object_object_type_get(rtgui_object_t *object)
{

View File

@ -22,7 +22,7 @@
#include <rtgui/widgets/window.h>
#include <rtgui/rtgui_theme.h>
#ifdef _WIN32
#ifdef _WIN32_NATIVE
#define RTGUI_MEM_TRACE
#endif
@ -316,7 +316,7 @@ FINSH_FUNCTION_EXPORT(list_guimem, display memory information);
/* RTGUI Event Dump */
/************************************************************************/
#ifdef _WIN32
#ifdef _WIN32_NATIVE
#define RTGUI_EVENT_DEBUG
#endif
@ -387,7 +387,16 @@ static void rtgui_event_dump(rt_thread_t tid, rtgui_event_t* event)
if (event->sender != RT_NULL)
sender = event->sender->name;
if (event->type >= RTGUI_EVENT_COMMAND)
{
rt_kprintf("%s -- USER EVENT --> %s \n", sender, tid->name);
return ;
}
else
{
rt_kprintf("%s -- %s --> %s ", sender, event_string[event->type], tid->name);
}
switch (event->type)
{
case RTGUI_EVENT_APP_CREATE:

View File

@ -70,7 +70,8 @@ void rtgui_theme_draw_win(struct rtgui_topwin* win)
/* draw border */
if (win->flag & WINTITLE_BORDER)
{
rect.x2 -= 1; rect.y2 -= 1;
rect.x2 -= 1;
rect.y2 -= 1;
RTGUI_WIDGET_FOREGROUND(win->title) = RTGUI_RGB(212, 208, 200);
rtgui_dc_draw_hline(dc, rect.x1, rect.x2, rect.y1);
rtgui_dc_draw_vline(dc, rect.x1, rect.y1, rect.y2);
@ -99,12 +100,16 @@ void rtgui_theme_draw_win(struct rtgui_topwin* win)
if (win->flag & WINTITLE_ACTIVATE)
{
r = 10; g = 36; b = 106;
r = 10;
g = 36;
b = 106;
delta = 150 / (float)(rect.x2 - rect.x1);
}
else
{
r = 128; g = 128; b = 128;
r = 128;
g = 128;
b = 128;
delta = 64 / (float)(rect.x2 - rect.x1);
}
@ -112,7 +117,9 @@ void rtgui_theme_draw_win(struct rtgui_topwin* win)
for (index = rect.x1; index < rect.x2 + 1; index ++)
{
rtgui_dc_draw_vline(dc, index, rect.y1, rect.y2);
r += delta; g += delta; b += delta;
r += delta;
g += delta;
b += delta;
}
if (win->flag & WINTITLE_ACTIVATE)
@ -125,7 +132,8 @@ void rtgui_theme_draw_win(struct rtgui_topwin* win)
}
rect.x1 += 4;
rect.y1 += 2; rect.y2 = rect.y1 + WINTITLE_CB_HEIGHT;
rect.y1 += 2;
rect.y2 = rect.y1 + WINTITLE_CB_HEIGHT;
rtgui_dc_draw_text(dc, rtgui_wintitle_get_title(win->title), &rect);
if (win->flag & WINTITLE_CLOSEBOX)
@ -133,7 +141,8 @@ void rtgui_theme_draw_win(struct rtgui_topwin* win)
/* get close button rect */
rtgui_rect_t box_rect = {0, 0, WINTITLE_CB_WIDTH, WINTITLE_CB_HEIGHT};
rtgui_rect_moveto_align(&rect, &box_rect, RTGUI_ALIGN_CENTER_VERTICAL | RTGUI_ALIGN_RIGHT);
box_rect.x1 -= 3; box_rect.x2 -= 3;
box_rect.x1 -= 3;
box_rect.x2 -= 3;
rtgui_dc_fill_rect(dc, &box_rect);
/* draw close box */
@ -182,7 +191,8 @@ void rtgui_theme_draw_button(rtgui_button_t* btn)
if (btn->pressed_image != RT_NULL)
{
rtgui_rect_t image_rect;
image_rect.x1 = 0; image_rect.y1 = 0;
image_rect.x1 = 0;
image_rect.y1 = 0;
image_rect.x2 = btn->unpressed_image->w;
image_rect.y2 = btn->unpressed_image->h;
rtgui_rect_moveto_align(&rect, &image_rect, RTGUI_ALIGN_CENTER);
@ -202,7 +212,8 @@ void rtgui_theme_draw_button(rtgui_button_t* btn)
if (btn->unpressed_image != RT_NULL)
{
rtgui_rect_t image_rect;
image_rect.x1 = 0; image_rect.y1 = 0;
image_rect.x1 = 0;
image_rect.y1 = 0;
image_rect.x2 = btn->unpressed_image->w;
image_rect.y2 = btn->unpressed_image->h;
rtgui_rect_moveto_align(&rect, &image_rect, RTGUI_ALIGN_CENTER);
@ -404,7 +415,8 @@ void rtgui_theme_draw_checkbox(struct rtgui_checkbox* checkbox)
box_rect.x2 = CHECK_BOX_W;
box_rect.y2 = CHECK_BOX_H;
rtgui_rect_moveto_align(&rect, &box_rect, RTGUI_ALIGN_CENTER_VERTICAL);
box_rect.x1 += 2; box_rect.x2 += 2;
box_rect.x1 += 2;
box_rect.x2 += 2;
rtgui_dc_draw_border(dc, &box_rect, RTGUI_BORDER_BOX);
rtgui_rect_inflate(&box_rect, -1);
@ -486,9 +498,11 @@ void rtgui_theme_draw_radiobutton(struct rtgui_radiobox* radiobox, rt_uint16_t i
}
else
{
item_rect.x2 += 1; item_rect.y2 += 1;
item_rect.x2 += 1;
item_rect.y2 += 1;
rtgui_dc_fill_rect(dc, &item_rect);
item_rect.x2 -= 1; item_rect.y2 -= 1;
item_rect.x2 -= 1;
item_rect.y2 -= 1;
rtgui_dc_draw_word(dc, item_rect.x1, item_rect.y1 + (item_size - RADIO_BOX_H) / 2,
RADIO_BOX_H, radio_unchecked_byte);
}
@ -514,9 +528,11 @@ void rtgui_theme_draw_radiobutton(struct rtgui_radiobox* radiobox, rt_uint16_t i
}
else
{
item_rect.x2 += 1; item_rect.y2 += 1;
item_rect.x2 += 1;
item_rect.y2 += 1;
rtgui_dc_fill_rect(dc, &item_rect);
item_rect.x2 -= 1; item_rect.y2 -= 1;
item_rect.x2 -= 1;
item_rect.y2 -= 1;
rtgui_dc_draw_word(dc, item_rect.x1, item_rect.y1, RADIO_BOX_H, radio_unchecked_byte);
}
@ -559,11 +575,17 @@ void rtgui_theme_draw_radiobox(struct rtgui_radiobox* radiobox)
fc = RTGUI_WIDGET_FOREGROUND(radiobox);
RTGUI_WIDGET_FOREGROUND(radiobox) = white;
rect.x1 ++; rect.y1 ++; rect.x2 ++; rect.y2 ++;
rect.x1 ++;
rect.y1 ++;
rect.x2 ++;
rect.y2 ++;
rtgui_dc_draw_rect(dc, &rect);
RTGUI_WIDGET_FOREGROUND(radiobox) = RTGUI_RGB(128, 128, 128);
rect.x1 --; rect.y1 --; rect.x2 --; rect.y2 --;
rect.x1 --;
rect.y1 --;
rect.x2 --;
rect.y2 --;
rtgui_dc_draw_rect(dc, &rect);
RTGUI_WIDGET_FOREGROUND(radiobox) = fc;
@ -576,9 +598,11 @@ void rtgui_theme_draw_radiobox(struct rtgui_radiobox* radiobox)
/* draw group text */
rtgui_font_get_metrics(RTGUI_DC_FONT(dc), radiobox->text, &text_rect);
rtgui_rect_moveto(&text_rect, rect.x1 + bord_size + 5, rect.y1);
rect.x1 -= 5; rect.x2 += 5;
rect.x1 -= 5;
rect.x2 += 5;
rtgui_dc_fill_rect(dc, &text_rect);
rect.x1 += 5; rect.x2 -= 5;
rect.x1 += 5;
rect.x2 -= 5;
rtgui_dc_draw_text(dc, radiobox->text, &text_rect);
}
@ -749,127 +773,6 @@ void rtgui_theme_draw_slider(struct rtgui_slider* slider)
return;
}
const static rt_uint8_t _up_arrow[] = {0x10, 0x38, 0x7C, 0xFE};
const static rt_uint8_t _down_arrow[] = {0xFE,0x7C, 0x38, 0x10};
const static rt_uint8_t _left_arrow[] = {0x10, 0x30, 0x70, 0xF0, 0x70, 0x30, 0x10};
const static rt_uint8_t _right_arrow[] = {0x80, 0xC0, 0xE0, 0xF0, 0xE0, 0xC0, 0x80};
void rtgui_theme_draw_scrollbar(struct rtgui_scrollbar* bar)
{
/* draw scroll bar */
struct rtgui_dc* dc;
rtgui_rect_t rect, btn_rect, thum_rect, arrow_rect;
rtgui_color_t bc, fc;
/* begin drawing */
dc = rtgui_dc_begin_drawing(&(bar->parent));
if (dc == RT_NULL) return;
rtgui_widget_get_rect(RTGUI_WIDGET(bar), &rect);
/* draw background */
fc = RTGUI_WIDGET_FOREGROUND(bar);
if (!RTGUI_WIDGET_IS_ENABLE(bar))
RTGUI_WIDGET_FOREGROUND(bar) = RTGUI_RGB(128, 128, 128);
bc = RTGUI_WIDGET_BACKGROUND(bar);
RTGUI_WIDGET_BACKGROUND(bar) = white;
rtgui_dc_fill_rect(dc, &rect);
RTGUI_WIDGET_BACKGROUND(bar) = bc;
if (bar->orient == RTGUI_VERTICAL)
{
btn_rect = rect;
btn_rect.y2 = btn_rect.y1 + (rect.x2 - rect.x1);
/* draw up button */
rtgui_dc_fill_rect(dc, &btn_rect);
if (bar->status & SBS_UPARROW) rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
else rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);
/* draw arrow */
arrow_rect.x1 = 0; arrow_rect.y1 = 0;
arrow_rect.x2 = 7; arrow_rect.y2 = 4;
rtgui_rect_moveto_align(&btn_rect, &arrow_rect,
RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1,
rtgui_rect_height(arrow_rect), _up_arrow);
/* draw thumb */
if (RTGUI_WIDGET_IS_ENABLE(bar))
{
rtgui_scrollbar_get_thumb_rect(bar, &thum_rect);
rtgui_dc_fill_rect(dc, &thum_rect);
rtgui_dc_draw_border(dc, &thum_rect, RTGUI_BORDER_RAISE);
}
/* draw down button */
btn_rect.y1 = rect.y2 - (rect.x2 - rect.x1);
btn_rect.y2 = rect.y2;
rtgui_dc_fill_rect(dc, &btn_rect);
if (bar->status & SBS_DOWNARROW) rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
else rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);
arrow_rect.x1 = 0; arrow_rect.y1 = 0;
arrow_rect.x2 = 7; arrow_rect.y2 = 4;
rtgui_rect_moveto_align(&btn_rect, &arrow_rect,
RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1,
rtgui_rect_height(arrow_rect), _down_arrow);
}
else
{
btn_rect.x1 = rect.x1;
btn_rect.y1 = rect.y1;
btn_rect.x2 = rect.y2;
btn_rect.y2 = rect.y2;
/* draw left button */
rtgui_dc_fill_rect(dc, &btn_rect);
if (bar->status & SBS_LEFTARROW) rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
else rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);
arrow_rect.x1 = 0; arrow_rect.y1 = 0;
arrow_rect.x2 = 4; arrow_rect.y2 = 7;
rtgui_rect_moveto_align(&btn_rect, &arrow_rect,
RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1,
rtgui_rect_height(arrow_rect), _left_arrow);
/* draw thumb */
if (RTGUI_WIDGET_IS_ENABLE(bar))
{
rtgui_scrollbar_get_thumb_rect(bar, &thum_rect);
rtgui_dc_fill_rect(dc, &thum_rect);
rtgui_dc_draw_border(dc, &thum_rect, RTGUI_BORDER_RAISE);
}
btn_rect.x1 = rect.x2 - rect.y2;
btn_rect.x2 = rect.x2;
/* draw right button */
rtgui_dc_fill_rect(dc, &btn_rect);
if (bar->status & SBS_RIGHTARROW) rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
else rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);
arrow_rect.x1 = 0; arrow_rect.y1 = 0;
arrow_rect.x2 = 4; arrow_rect.y2 = 7;
rtgui_rect_moveto_align(&btn_rect, &arrow_rect,
RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1,
rtgui_rect_height(arrow_rect), _right_arrow);
}
/* end drawing */
rtgui_dc_end_drawing(dc);
RTGUI_WIDGET_FOREGROUND(bar) = fc;
return;
}
void rtgui_theme_draw_progressbar(struct rtgui_progressbar *bar)
{
/* draw progress bar */
@ -900,11 +803,13 @@ void rtgui_theme_draw_progressbar(struct rtgui_progressbar* bar)
return;
}
rect.x2 ++; rect.y2 ++;
rect.x2 ++;
rect.y2 ++;
left = max - pos;
rtgui_rect_inflate(&rect, -2);
RTGUI_WIDGET_BACKGROUND(bar) = RTGUI_RGB(0, 0, 255);
rect.y2 --; rect.x2 --;
rect.y2 --;
rect.x2 --;
if (bar->orient == RTGUI_VERTICAL)
{
@ -914,7 +819,8 @@ void rtgui_theme_draw_progressbar(struct rtgui_progressbar* bar)
rtgui_dc_fill_rect(dc, &rect);
RTGUI_DC_BC(dc) = bc;
rect.y1 -= dy; rect.y2 = dy;
rect.y1 -= dy;
rect.y2 = dy;
rtgui_dc_fill_rect(dc, &rect);
}
else
@ -925,7 +831,8 @@ void rtgui_theme_draw_progressbar(struct rtgui_progressbar* bar)
rtgui_dc_fill_rect(dc, &rect);
RTGUI_DC_BC(dc) = bc;
rect.x1 = rect.x2; rect.x2 += dx;
rect.x1 = rect.x2;
rect.x2 += dx;
rtgui_dc_fill_rect(dc, &rect);
}

View File

@ -2,7 +2,8 @@
#include <rtgui/rtgui_system.h>
/* Internal states that the parser can be in at any given time. */
enum {
enum
{
STAT_START = 0, /* starting base state, default state */
STAT_TEXT, /* text state */
STAT_START_TAG, /* start tag state */
@ -22,7 +23,8 @@ enum {
/* character classes that we will match against; This could be expanded if
need be, however, we are aiming for simple. */
enum {
enum
{
CLASS_TYPE_NONE = 0, /* matches nothing, a base state */
CLASS_TYPE_LEFT_ANGLE, /* matches start tag '<' */
CLASS_TYPE_SLASH, /* matches forward slash */
@ -45,7 +47,8 @@ struct rtgui_xml_state
};
/* Note: States must be grouped in match order AND grouped together! */
static const struct rtgui_xml_state RTGUI_XML_STATES [] = {
static const struct rtgui_xml_state RTGUI_XML_STATES [] =
{
/* [0-2] starting state, which also serves as the default state in case
of error */
{ STAT_START, CLASS_TYPE_SPACE, STAT_SPACE, EVENT_NONE },

View File

@ -62,19 +62,21 @@ enum _rtgui_event_type
RTGUI_EVENT_MOUSE_BUTTON, /* mouse button info */
RTGUI_EVENT_KBD, /* keyboard info */
/* user command event */
RTGUI_EVENT_COMMAND=0x0100, /* user command */
/* widget event */
RTGUI_EVENT_FOCUSED, /* widget focused */
RTGUI_EVENT_SCROLLED, /* scroll bar scrolled */
RTGUI_EVENT_RESIZE, /* widget resize */
RTGUI_EVENT_SELECTED, /* widget selected */
RTGUI_EVENT_UNSELECTED, /* widget un-selected */
RTGUI_EVENT_MV_MODEL, /* data of a model has been changed */
/* user command event. It should always be the last command type. */
RTGUI_EVENT_COMMAND = 0x0100, /* user command */
};
typedef enum _rtgui_event_type rtgui_event_type;
enum {
enum
{
RTGUI_STATUS_OK = 0, /* status ok */
RTGUI_STATUS_ERROR, /* generic error */
RTGUI_STATUS_NRC, /* no resource */
@ -83,7 +85,7 @@ enum {
struct rtgui_event
{
/* the event type */
rt_uint16_t type;
enum _rtgui_event_type type;
/* user field of event */
rt_uint16_t user;
@ -376,6 +378,52 @@ struct rtgui_event_resize
};
#define RTGUI_EVENT_RESIZE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_RESIZE)
/*
* RTGUI Model/View Event
*/
enum rtgui_event_model_mode
{
RTGUI_MV_DATA_ADDED,
RTGUI_MV_DATA_CHANGED,
RTGUI_MV_DATA_DELETED,
};
struct rtgui_event_mv_model
{
struct rtgui_event parent;
struct rtgui_mv_model *model;
struct rtgui_mv_view *view;
rt_size_t first_data_changed_idx;
rt_size_t last_data_changed_idx;
};
#define _RTGUI_EVENT_MV_INIT_TYPE(T) \
rt_inline void RTGUI_EVENT_MV_MODEL_##T##_INIT(struct rtgui_event_mv_model *e) \
{ \
RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MV_MODEL); \
(e)->parent.user = RTGUI_MV_DATA_##T; \
} \
/* useless struct to allow trailing semicolon */ \
struct dummy
_RTGUI_EVENT_MV_INIT_TYPE(ADDED);
_RTGUI_EVENT_MV_INIT_TYPE(CHANGED);
_RTGUI_EVENT_MV_INIT_TYPE(DELETED);
#undef _RTGUI_EVENT_MV_INIT_TYPE
#define _RTGUI_EVENT_MV_IS_TYPE(T) \
rt_inline rt_bool_t RTGUI_EVENT_MV_MODEL_IS_##T(struct rtgui_event_mv_model *e) \
{ \
return e->parent.user == RTGUI_MV_DATA_##T; \
} \
/* useless struct to allow trailing semicolon */ \
struct dummy
_RTGUI_EVENT_MV_IS_TYPE(ADDED);
_RTGUI_EVENT_MV_IS_TYPE(CHANGED);
_RTGUI_EVENT_MV_IS_TYPE(DELETED);
#undef _RTGUI_EVENT_MV_IS_TYPE
#undef _RTGUI_EVENT_WIN_ELEMENTS
union rtgui_event_generic
@ -407,9 +455,10 @@ union rtgui_event_generic
struct rtgui_event_clip_info clip_info;
struct rtgui_event_mouse mouse;
struct rtgui_event_kbd kbd;
struct rtgui_event_command command;
struct rtgui_event_scrollbar scrollbar;
struct rtgui_event_focused focused;
struct rtgui_event_resize resize;
struct rtgui_event_mv_model model;
struct rtgui_event_command command;
};
#endif

View File

@ -15,7 +15,7 @@
#define __RTGUI_FILERW_H__
#ifdef RTGUI_USING_DFS_FILERW
#ifdef _WIN32
#ifdef _WIN32_NATIVE
#pragma warning(disable: 4996)
#include <fcntl.h>
#include <sys/types.h>

View File

@ -103,7 +103,7 @@ void rtgui_font_system_remove_font(struct rtgui_font* font);
struct rtgui_font *rtgui_font_default(void);
void rtgui_font_set_defaut(struct rtgui_font *font);
struct rtgui_font* rtgui_font_refer(const rt_uint8_t* family, rt_uint16_t height);
struct rtgui_font *rtgui_font_refer(const char *family, rt_uint16_t height);
void rtgui_font_derefer(struct rtgui_font *font);
/* draw a text */
@ -111,4 +111,8 @@ void rtgui_font_draw(struct rtgui_font* font, struct rtgui_dc* dc, const char* t
int rtgui_font_get_string_width(struct rtgui_font *font, const char *text);
void rtgui_font_get_metrics(struct rtgui_font *font, const char *text, struct rtgui_rect *rect);
/* used by stract font */
#define FONT_BMP_DATA_BEGIN
#define FONT_BMP_DATA_END
#endif

View File

@ -38,7 +38,7 @@ struct rtgui_image_bmp_header
rt_uint32_t biClrUsed;
rt_uint32_t biClrImportant;
};
#ifdef _WIN32
#ifdef _WIN32_NATIVE
#pragma warning(disable : 4103)
#endif
void rtgui_image_bmp_init(void);

View File

@ -269,7 +269,8 @@ typedef enum
} RTGUI_KBD_KEY;
/* Enumeration of valid key mods (possibly OR'd together) */
typedef enum {
typedef enum
{
RTGUI_KMOD_NONE = 0x0000,
RTGUI_KMOD_LSHIFT = 0x0001,
RTGUI_KMOD_RSHIFT = 0x0002,
@ -285,7 +286,8 @@ typedef enum {
RTGUI_KMOD_RESERVED = 0x8000
} RTGUI_KBD_MOD;
typedef enum {
typedef enum
{
RTGUI_KEYDOWN, /* Keys pressed */
RTGUI_KEYUP, /* Keys released */
} RTGUI_KBD_TYPE;

View File

@ -18,43 +18,10 @@
/* RTGUI options */
#ifdef _WIN32
/* name length of RTGUI object */
#define RTGUI_NAME_MAX 12
/* support 16 weight font */
#define RTGUI_USING_FONT16
/* support Chinese font */
#define RTGUI_USING_FONTHZ
/* support FreeType TTF font */
//#define RTGUI_USING_TTF
/* use small size in RTGUI */
#define RTGUI_USING_SMALL_SIZE
/* use mouse cursor */
/* #define RTGUI_USING_MOUSE_CURSOR */
/* default font size in RTGUI */
#define RTGUI_DEFAULT_FONT_SIZE 12
#define RTGUI_USING_STDIO_FILERW
#define RTGUI_USING_DFS_FILERW
#define RTGUI_IMAGE_CONTAINER
#define RTGUI_IMAGE_XPM
#define RTGUI_IMAGE_BMP
#define RTGUI_IMAGE_PNG
// #define RTGUI_IMAGE_JPEG
// #define RTGUI_IMAGE_TJPGD
#define RTGUI_USING_FONT12
#define RTGUI_USING_HZ_BMP
#define RTGUI_MEM_TRACE
#define RTGUI_USING_WINMOVE
#define RTGUI_USING_NOTEBOOK_IMAGE
// #define RTGUI_USING_HZ_FILE
#else
/* native running under RT-Thread */
#ifndef RT_USING_DFS
#undef RTGUI_USING_DFS_FILERW
#undef RTGUI_USING_HZ_FILE
#endif
#endif
#if RTGUI_DEFAULT_FONT_SIZE == 0
#define RTGUI_DEFAULT_FONT_SIZE 12
@ -79,6 +46,6 @@
#define RTGUI_USING_CAST_CHECK
//#define RTGUI_USING_DESKTOP_WINDOW
#undef RTGUI_USING_SMALL_SIZE
//#undef RTGUI_USING_SMALL_SIZE
#endif

View File

@ -0,0 +1,58 @@
/*
* File : rtgui_mv_model.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2012-09-15 Grissiom first version
*/
#ifndef __RTGUI_MV_MODEL_H__
#define __RTGUI_MV_MODEL_H__
#include <rtgui/rtgui.h>
#include <rtgui/widgets/mv_view.h>
DECLARE_CLASS_TYPE(mv_model);
/** Gets the type of a mv_model */
#define RTGUI_MV_MODEL_TYPE (RTGUI_TYPE(mv_model))
/** Casts the object to an mv_model */
#define RTGUI_MV_MODEL(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_MV_MODEL_TYPE, struct rtgui_mv_model))
/** Checks if the object is an mv_model */
#define RTGUI_IS_MV_MODEL(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_MV_MODEL_TYPE))
struct rtgui_mv_model
{
struct rtgui_object parent;
rt_uint16_t dimension;
rt_uint16_t view_number;
/* the length of data */
rt_uint16_t length;
/* if the dimension is 1, the data is the pointer to the data. If the
* dimension is more than 1, data is a pointer to a array of pointers to
* data. */
void *data;
/* the content of view is like the content of data. If a model has more
* then one view, view is pointed to an array of pointers to views. */
void *view;
};
struct rtgui_mv_model *rtgui_mv_model_create(rt_uint16_t dimension);
void rtgui_mv_model_destroy(struct rtgui_mv_model *model);
rt_err_t rtgui_mv_model_set_dimension(struct rtgui_mv_model *model, rt_uint16_t dimension);
rt_err_t rtgui_mv_model_add_view(struct rtgui_mv_model *, struct rtgui_mv_view *);
void rtgui_mv_model_remove_view(struct rtgui_mv_model *, struct rtgui_mv_view *);
rt_bool_t rtgui_mv_model_has_view(struct rtgui_mv_model *model, struct rtgui_mv_view *view);
void rtgui_mv_model_set_data(struct rtgui_mv_model *model, rt_uint16_t dim, void *p);
void *rtgui_mv_model_get_data(struct rtgui_mv_model *model, rt_uint16_t dim);
void rtgui_mv_model_notify(struct rtgui_mv_model *model, struct rtgui_event_mv_model *em);
#endif /* end of include guard: __RTGUI_MV_MODEL_H__ */

View File

@ -50,7 +50,7 @@ void* rtgui_malloc(rt_size_t size);
void rtgui_free(void *ptr);
void *rtgui_realloc(void *ptr, rt_size_t size);
#ifdef _WIN32
#ifdef _WIN32_NATIVE
#define rtgui_enter_critical()
#define rtgui_exit_critical()
#else

View File

@ -50,7 +50,6 @@ void rtgui_theme_draw_radiobutton(struct rtgui_radiobox* radiobox, rt_uint16_t i
void rtgui_theme_draw_radiobox(struct rtgui_radiobox *radiobox);
void rtgui_theme_draw_slider(struct rtgui_slider *slider);
void rtgui_theme_draw_scrollbar(struct rtgui_scrollbar* bar);
void rtgui_theme_draw_progressbar(struct rtgui_progressbar *bar);
void rtgui_theme_draw_staticline(struct rtgui_staticline *staticline);

View File

@ -5,7 +5,8 @@
/* Types of events: start element, end element, text, attr name, attr
val and start/end document. Other events can be ignored! */
enum {
enum
{
EVENT_START = 0, /* Start tag */
EVENT_END, /* End tag */
EVENT_TEXT, /* Text */

View File

@ -34,7 +34,7 @@ struct rtgui_listctrl
/* widget private data */
/* listctrl items */
rt_uint32_t items;
void *items;
/* total number of items */
rt_uint16_t items_count;
@ -52,13 +52,14 @@ typedef struct rtgui_listctrl rtgui_listctrl_t;
typedef void (*rtgui_onitem_draw_t)(struct rtgui_listctrl *list, struct rtgui_dc *dc, rtgui_rect_t *rect, rt_uint16_t index);
rtgui_listctrl_t* rtgui_listctrl_create(rt_uint32_t items, rt_uint16_t count,
rtgui_listctrl_t *rtgui_listctrl_create(void *items, rt_uint16_t count,
rtgui_rect_t *rect, rtgui_onitem_draw_t ondraw);
void rtgui_listctrl_destroy(rtgui_listctrl_t *ctrl);
rt_bool_t rtgui_listctrl_event_handler(struct rtgui_object *object, struct rtgui_event *event);
void rtgui_listctrl_set_onitem(rtgui_listctrl_t *ctrl, rtgui_event_handler_ptr func);
void rtgui_listctrl_set_items(rtgui_listctrl_t* ctrl, rt_uint32_t items, rt_uint16_t count);
void rtgui_listctrl_set_items(rtgui_listctrl_t *ctrl, void *items, rt_uint16_t count);
void rtgui_listctrl_set_current_item(struct rtgui_listctrl *ctrl, rt_uint16_t index);
rt_bool_t rtgui_listctrl_get_item_rect(rtgui_listctrl_t *ctrl, rt_uint16_t item, rtgui_rect_t *item_rect);
void rtgui_listctrl_set_itemheight(struct rtgui_listctrl *ctrl, int height);

View File

@ -0,0 +1,44 @@
/*
* File : mv_view.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2012-09-15 Grissiom first version
*/
#ifndef __MV_VIEW_H__
#define __MV_VIEW_H__
#include <rtgui/rtgui.h>
#include <rtgui/widgets/widget.h>
DECLARE_CLASS_TYPE(mv_view);
/** Gets the type of a mv_view */
#define RTGUI_MV_VIEW_TYPE (RTGUI_TYPE(mv_view))
/** Casts the object to an mv_view */
#define RTGUI_MV_VIEW(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_MV_VIEW_TYPE, struct rtgui_mv_view))
/** Checks if the object is an mv_view */
#define RTGUI_IS_MV_VIEW(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_MV_VIEW_TYPE))
struct rtgui_mv_view
{
struct rtgui_widget parent;
rt_uint16_t model_number;
/* if the model_number is 1, the model is the pointer to the model. If the
* model_number is more than 1, model is a pointer to a array of pointers
* to model. */
void *model;
};
struct rtgui_mv_view *rtgui_mv_view_create(void);
void rtgui_mv_view_destroy(struct rtgui_mv_view *view);
struct rtgui_mv_model *rtgui_mv_view_foreach_in_model(struct rtgui_mv_view *view, rt_uint32_t *iter);
#endif /* end of include guard: __MV_VIEW_H__ */

View File

@ -16,6 +16,7 @@
#include <rtgui/rtgui.h>
#include <rtgui/widgets/widget.h>
#include <rtgui/widgets/mv_view.h>
#include <rtgui/widgets/plot_curve.h>
DECLARE_CLASS_TYPE(plot);
@ -27,17 +28,10 @@ DECLARE_CLASS_TYPE(plot);
/** Checks if the object is an rtgui_plot */
#define RTGUI_IS_PLOT(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_PLOT_TYPE))
struct rtgui_plot_curve_container
enum rtgui_plot_type
{
struct rtgui_plot_curve *curve;
struct rtgui_plot_curve_container *next;
};
enum rtgui_plot_flag
{
RTGUI_PLOT_INCREMENTAL,
RTGUI_PLOT_MOVING_WINDOW,
RTGUI_PLOT_SCAN,
RTGUI_PLOT_TYPE_SCAN,
RTGUI_PLOT_TYPE_INCREMENTAL,
};
/*
@ -45,20 +39,21 @@ enum rtgui_plot_flag
*/
struct rtgui_plot
{
struct rtgui_widget parent;
struct rtgui_mv_view parent;
enum rtgui_plot_flag pflag;
enum rtgui_plot_type ptype;
rt_uint16_t scale_x;
rt_uint16_t scale_y;
struct rtgui_point base_point;
struct rtgui_plot_curve_container curve_container;
rtgui_plot_curve_dtype base_x;
rtgui_plot_curve_dtype base_y;
};
struct rtgui_plot *rtgui_plot_create(struct rtgui_plot_curve*);
struct rtgui_plot *rtgui_plot_create(void);
void rtgui_plot_destroy(struct rtgui_plot *plot);
void rtgui_plot_set_base_point(struct rtgui_plot *plot, rt_uint16_t x, rt_uint16_t y);
void rtgui_plot_append_curve(struct rtgui_plot *plot, struct rtgui_plot_curve *curve);
void rtgui_plot_remove_curve(struct rtgui_plot *plot, struct rtgui_plot_curve *curve);
void rtgui_plot_set_base(struct rtgui_plot *plot,
rtgui_plot_curve_dtype x, rtgui_plot_curve_dtype y);
rt_bool_t rtgui_plot_event_handler(struct rtgui_object *object, struct rtgui_event *event);

View File

@ -15,6 +15,7 @@
#define __RTGUI_PLOT_CURVE_H__
#include <rtgui/rtgui.h>
#include <rtgui/rtgui_mv_model.h>
DECLARE_CLASS_TYPE(plot_curve);
@ -31,15 +32,20 @@ DECLARE_CLASS_TYPE(plot_curve);
struct rtgui_plot_curve
{
struct rtgui_object parent;
struct rtgui_mv_model parent;
rtgui_color_t color;
rt_size_t length;
rtgui_plot_curve_dtype *x_data;
rtgui_plot_curve_dtype *y_data;
rtgui_plot_curve_dtype min_x, max_x;
rtgui_plot_curve_dtype min_y, max_y;
};
struct rtgui_plot_curve *rtgui_plot_curve_create(void);
void rtgui_plot_curve_destroy(struct rtgui_plot_curve *curve);
void rtgui_plot_curve_set_x(struct rtgui_plot_curve *curve, void *p);
void *rtgui_plot_curve_get_x(struct rtgui_plot_curve *curve);
void rtgui_plot_curve_set_y(struct rtgui_plot_curve *curve, void *p);
void *rtgui_plot_curve_get_y(struct rtgui_plot_curve *curve);
#endif

View File

@ -14,14 +14,15 @@
#ifndef __RTGUI_SCROLLBAR_H__
#define __RTGUI_SCROLLBAR_H__
#include <rtgui/rtgui.h>
#include <rtgui/widgets/widget.h>
#include <rtgui/widgets/container.h>
#ifdef __cplusplus
extern "C" {
#endif
DECLARE_CLASS_TYPE(scrollbar);
/** Gets the type of a scrollbar */
#define RTGUI_SCROLLBAR_TYPE (RTGUI_TYPE(scrollbar))
/** Casts the object to an rtgui_scrollbar */
@ -29,58 +30,60 @@ DECLARE_CLASS_TYPE(scrollbar);
/** Checks if the object is an rtgui_scrollbar */
#define RTGUI_IS_SCROLLBAR(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_SCROLLBAR_TYPE))
#define RTGUI_DEFAULT_SB_WIDTH 100
#define RTGUI_DEFAULT_SB_HEIGHT 16
#define RTGUI_DEFAULT_SB_WIDTH 16
/* scrollbar status/positions*/
#define SBS_UNKNOWN 0x0000
#define SBS_LEFTARROW 0x0001
#define SBS_RIGHTARROW 0x0002
#define SBS_LEFTSPACE 0x0004
#define SBS_RIGHTSPACE 0x0008
#define SBS_HORZTHUMB 0x0010
#define SBS_LEFTSPACE 0x0004 /* Need mouse_motion event */
#define SBS_RIGHTSPACE 0x0008 /* Need mouse_motion event */
#define SBS_HORZTHUMB 0x0010 /* Need mouse_motion event */
#define SBS_UPARROW 0x0020
#define SBS_DOWNARROW 0x0040
#define SBS_UPSPACE 0x0080
#define SBS_DOWNSPACE 0x0100
#define SBS_VERTTHUMB 0x0200
#define SBS_UPSPACE 0x0080 /* Need mouse_motion event */
#define SBS_DOWNSPACE 0x0100 /* Need mouse_motion event */
#define SBS_VERTTHUMB 0x0200 /* Need mouse_motion event */
#define SBS_UPTHUMB 0x0400 /* Need mouse_motion event */
#define SBS_DOWNTHUMB 0x0800 /* Need mouse_motion event */
#define SBS_LEFTTHUMB 0x1000 /* Need mouse_motion event */
#define SBS_RIGHTTHUMB 0x2000 /* Need mouse_motion event */
struct rtgui_scrollbar
{
/* inherit from widget */
struct rtgui_widget parent;
rtgui_widget_t parent;
rt_uint8_t orient;
rt_uint8_t status;
rt_uint32_t status;
/* page_step = width of scrollbar */
/* thumb size = line_step * page_step / (page_step - (button width * 2)) */
/* page_step = display lines of scrollbar */
/* thumb_len = line_step * page_step / (page_step - (button width * 2)) */
rt_int16_t line_step, page_step;
rt_int16_t thumb_position, thumb_size;
rt_int16_t value, thumb_len,thumb_w;
/* position 1:1 width of scrollbar */
rt_int16_t min_position, max_position;
rt_int16_t count;
rtgui_event_handler_ptr on_scroll;
rtgui_widget_t *widget_link;/* be connected widget */
rt_bool_t (*on_scroll) (rtgui_object_t *obj, rtgui_event_t* event);
};
typedef struct rtgui_scrollbar rtgui_scrollbar_t;
struct rtgui_scrollbar* rtgui_scrollbar_create(int orient, rtgui_rect_t* r);
void rtgui_scrollbar_destroy(struct rtgui_scrollbar* bar);
rtgui_scrollbar_t* rtgui_scrollbar_create(rtgui_container_t *container,int left,int top,int w,int len,int orient);
void rtgui_scrollbar_destroy(rtgui_scrollbar_t* bar);
void rtgui_scrollbar_ondraw(rtgui_scrollbar_t* bar);
void rtgui_scrollbar_get_thumb_rect(rtgui_scrollbar_t *bar, rtgui_rect_t *erect);
void rtgui_scrollbar_get_thumb_rect(rtgui_scrollbar_t *bar, rtgui_rect_t *rect);
void rtgui_scrollbar_set_range(rtgui_scrollbar_t* bar, int count);
void rtgui_scrollbar_set_value(rtgui_scrollbar_t* bar, rt_int16_t value);
void rtgui_scrollbar_set_range(struct rtgui_scrollbar* bar, int min, int max);
rt_int16_t rtgui_scrollbar_get_value(struct rtgui_scrollbar* bar);
void rtgui_scrollbar_set_value(struct rtgui_scrollbar* bar, rt_int16_t position);
void rtgui_scrollbar_set_onscroll(rtgui_scrollbar_t* bar, rtgui_event_handler_ptr handler);
void rtgui_scrollbar_set_orientation(rtgui_scrollbar_t* bar, int orient);
void rtgui_scrollbar_set_page_step(rtgui_scrollbar_t* bar, int step);
void rtgui_scrollbar_set_line_step(rtgui_scrollbar_t* bar, int step);
void rtgui_scrollbar_set_onscroll(struct rtgui_scrollbar* bar, rtgui_event_handler_ptr handler);
void rtgui_scrollbar_set_orientation(struct rtgui_scrollbar* bar, int orientation);
void rtgui_scrollbar_set_page_step(struct rtgui_scrollbar* bar, int step);
void rtgui_scrollbar_set_line_step(struct rtgui_scrollbar* bar, int step);
rt_bool_t rtgui_scrollbar_event_handler(struct rtgui_object* object, struct rtgui_event* event);
rt_bool_t rtgui_scrollbar_event_handler(rtgui_object_t *obj, rtgui_event_t* event);
void rtgui_scrollbar_hide(rtgui_scrollbar_t* bar);
#ifdef __cplusplus
}

View File

@ -54,6 +54,8 @@ struct rtgui_textbox
/* current line and position */
rt_uint16_t line, line_begin, position, line_length;
rt_uint16_t dis_length; /*may be display length.*/
rt_uint16_t first_pos;
char mask_char;
char *text;
rt_size_t font_width;
@ -66,14 +68,15 @@ struct rtgui_textbox
};
typedef struct rtgui_textbox rtgui_textbox_t;
struct rtgui_textbox* rtgui_textbox_create(const char* text, rt_uint32_t flag);
rtgui_textbox_t *rtgui_textbox_create(const char *text, rt_uint32_t flag);
void rtgui_textbox_destroy(struct rtgui_textbox *box);
rt_bool_t rtgui_textbox_event_handler(struct rtgui_object *object, struct rtgui_event *event);
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);
const char rtgui_textbox_get_mask_char(rtgui_textbox_t *box);
void rtgui_textbox_set_line_length(struct rtgui_textbox *box, rt_size_t length);
void rtgui_textbox_get_edit_rect(struct rtgui_textbox *box, rtgui_rect_t *rect);

View File

@ -78,6 +78,9 @@ struct rtgui_win
/* the widget that will grab the focus in current window */
struct rtgui_widget *focused_widget;
/* which app I belong */
struct rtgui_app *app;
/* window style */
rt_uint16_t style;

View File

@ -79,7 +79,8 @@ void rtgui_graphic_driver_screen_update(const struct rtgui_graphic_driver* drive
{
struct rt_device_rect_info rect_info;
rect_info.x = rect->x1; rect_info.y = rect->y1;
rect_info.x = rect->x1;
rect_info.y = rect->y1;
rect_info.width = rect->x2 - rect->x1;
rect_info.height = rect->y2 - rect->y1;
rt_device_control(driver->device, RTGRAPHIC_CTRL_RECT_UPDATE, &rect_info);

View File

@ -58,7 +58,8 @@ struct rtgui_cursor* _rtgui_cursor;
#ifdef RTGUI_USING_MOUSE_CURSOR
struct rt_mutex cursor_mutex;
static const rt_uint8_t * cursor_xpm[] = {
static const rt_uint8_t *cursor_xpm[] =
{
"16 16 35 1",
" c None",
". c #A0B8D0",
@ -110,7 +111,8 @@ static const rt_uint8_t * cursor_xpm[] = {
" / )345 ",
" 6}${ ",
" 5{ ",
" "};
" "
};
static void rtgui_cursor_restore(void);
static void rtgui_cursor_save(void);

View File

@ -189,7 +189,7 @@ void rtgui_server_handle_kbd(struct rtgui_event_kbd* event)
}
}
#ifdef _WIN32
#ifdef _WIN32_NATIVE
#include <windows.h>
#endif
@ -329,6 +329,9 @@ static rt_bool_t rtgui_server_event_handler(struct rtgui_object *object,
/* handle mouse monitor */
rtgui_server_handle_monitor_add((struct rtgui_event_monitor *)event);
break;
default:
rt_kprintf("RTGUI: wrong event sent to server: %d", event->type);
return RT_FALSE;
}
return RT_TRUE;
@ -339,7 +342,7 @@ static rt_bool_t rtgui_server_event_handler(struct rtgui_object *object,
*/
static void rtgui_server_entry(void *parameter)
{
#ifdef _WIN32
#ifdef _WIN32_NATIVE
/* set the server thread to highest */
HANDLE hCurrentThread = GetCurrentThread();
SetThreadPriority(hCurrentThread, THREAD_PRIORITY_HIGHEST);

View File

@ -123,7 +123,10 @@ static void rtgui_combobox_ondraw(struct rtgui_combobox* box)
if (box->pd_pressed == RT_TRUE) rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SUNKEN);
else rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_RAISE);
r.x1 = 0; r.y1 = 0; r.x2 = 8; r.y2 = 4;
r.x1 = 0;
r.y1 = 0;
r.x2 = 8;
r.y2 = 4;
rtgui_rect_moveto_align(&rect, &r, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
rtgui_dc_draw_byte(dc, r.x1, r.y1, 4, down_arrow);
@ -164,7 +167,8 @@ static rt_bool_t rtgui_combobox_onmouse_button(struct rtgui_combobox* box, struc
/* create pull down window */
rect = RTGUI_WIDGET(box)->extent;
rect.y1 = rect.y2;
rect.y2 = rect.y1 + 5 * (2 + rtgui_theme_get_selected_height());
/* give it 5 pixels margin, or the last item won't get shown */
rect.y2 = rect.y1 + box->items_count * (2 + rtgui_theme_get_selected_height()) + 5;
box->pd_win = rtgui_win_create(RT_NULL, "combo", &rect, RTGUI_WIN_STYLE_NO_TITLE);
rtgui_win_set_ondeactivate(RTGUI_WIN(box->pd_win), rtgui_combobox_pulldown_hide);
/* set user data to parent combobox */

View File

@ -162,7 +162,6 @@ rt_bool_t rtgui_container_event_handler(struct rtgui_object* object, struct rtgu
rtgui_container_dispatch_event(container, event);
break;
case RTGUI_EVENT_COMMAND:
case RTGUI_EVENT_RESIZE:
rtgui_container_dispatch_event(container, event);
break;
@ -173,6 +172,11 @@ rt_bool_t rtgui_container_event_handler(struct rtgui_object* object, struct rtgu
rtgui_container_broadcast_event(container, event);
break;
case RTGUI_EVENT_RESIZE:
/* re-layout container */
rtgui_container_layout(container);
break;
default:
/* call parent widget event handler */
return rtgui_widget_event_handler(RTGUI_OBJECT(widget), event);

View File

@ -578,7 +578,8 @@ rt_uint32_t rtgui_edit_get_index_by_line(struct rtgui_edit *edit, struct edit_li
}
RTM_EXPORT(rtgui_edit_get_index_by_line);
enum {
enum
{
EDIT_IDENT_DIR_BOTH,
EDIT_IDENT_DIR_LEFT,
EDIT_IDENT_DIR_RIGHT
@ -733,25 +734,44 @@ rt_inline rt_uint16_t query_shift_code(rt_uint16_t key)
{
switch (key)
{
case '1': return '!';
case '2': return '@';
case '3': return '#';
case '4': return '$';
case '5': return '%';
case '6': return '^';
case '7': return '&';
case '8': return '*';
case '9': return '(';
case '0': return ')';
case '-': return '_';
case '=': return '+';
case '\\':return '|';
case ';': return ':';
case '\'':return '"';
case ',': return '<';
case '.': return '>';
case '/': return '?';
case '`': return '~';
case '1':
return '!';
case '2':
return '@';
case '3':
return '#';
case '4':
return '$';
case '5':
return '%';
case '6':
return '^';
case '7':
return '&';
case '8':
return '*';
case '9':
return '(';
case '0':
return ')';
case '-':
return '_';
case '=':
return '+';
case '\\':
return '|';
case ';':
return ':';
case '\'':
return '"';
case ',':
return '<';
case '.':
return '>';
case '/':
return '?';
case '`':
return '~';
}
}
return key;
@ -826,7 +846,8 @@ static rt_bool_t rtgui_edit_onkey(struct rtgui_object* object, rtgui_event_t* ev
RT_ASSERT(ekbd != RT_NULL);
if (RTGUI_KBD_IS_UP(ekbd))
{ /* reset function key */
{
/* reset function key */
if (ekbd->key == RTGUIK_RCTRL || ekbd->key == RTGUIK_LCTRL)
edit->flag &= ~RTGUI_EDIT_CTRL;
else if (ekbd->key == RTGUIK_RALT || ekbd->key == RTGUIK_LALT)
@ -846,17 +867,20 @@ static rt_bool_t rtgui_edit_onkey(struct rtgui_object* object, rtgui_event_t* ev
/* rt_kprintf("key=%04X ",ekbd->key); */
if (ekbd->key == RTGUIK_RCTRL || ekbd->key == RTGUIK_LCTRL)
{ /* use CTRL key */
{
/* use CTRL key */
edit->flag |= RTGUI_EDIT_CTRL;
return RT_FALSE;
}
else if (ekbd->key == RTGUIK_RALT || ekbd->key == RTGUIK_LALT)
{ /* use ALT key */
{
/* use ALT key */
edit->flag |= RTGUI_EDIT_ALT;
return RT_FALSE;
}
else if (ekbd->key == RTGUIK_RSHIFT || ekbd->key == RTGUIK_LSHIFT)
{ /* use SHIFT key */
{
/* use SHIFT key */
edit->flag |= RTGUI_EDIT_SHIFT;
return RT_FALSE;
}
@ -871,10 +895,12 @@ static rt_bool_t rtgui_edit_onkey(struct rtgui_object* object, rtgui_event_t* ev
return RT_FALSE;
}
else if (ekbd->key == RTGUIK_DELETE)
{ /* delete latter character */
{
/* delete latter character */
int ofs = edit->upleft.x + edit->visual.x;
if (ofs > line->len - 1 || (ofs == 0 && line->len == 0))
{ /* will the next line marges into the current line */
{
/* will the next line marges into the current line */
struct edit_line *next_line = line->next;
if (next_line != RT_NULL)
{
@ -929,7 +955,8 @@ static rt_bool_t rtgui_edit_onkey(struct rtgui_object* object, rtgui_event_t* ev
else if (ekbd->key == RTGUIK_BACKSPACE)
{
if (edit->visual.x == 0)
{ /* incorporated into prev line */
{
/* incorporated into prev line */
struct rtgui_event_kbd event_kbd;
struct edit_line *prev_line = line->prev;
if (prev_line != RT_NULL)
@ -973,7 +1000,8 @@ static rt_bool_t rtgui_edit_onkey(struct rtgui_object* object, rtgui_event_t* ev
edit->visual.x -= tmp_pos;
}
else if (edit->visual.x != 0)
{ /* remove current character */
{
/* remove current character */
char *c;
rt_int16_t tmp_pos = 1;
identify_double_byte(edit, line, EDIT_IDENT_DIR_LEFT, &tmp_pos);
@ -997,7 +1025,8 @@ static rt_bool_t rtgui_edit_onkey(struct rtgui_object* object, rtgui_event_t* ev
edit->update.end.y = edit->visual.y;
}
else if (ekbd->key == RTGUIK_UP)
{ /* move to prev line */
{
/* move to prev line */
struct edit_line *prev_line;
if (edit->visual.y > 0)
edit->visual.y --;
@ -1069,7 +1098,8 @@ static rt_bool_t rtgui_edit_onkey(struct rtgui_object* object, rtgui_event_t* ev
struct edit_line *tail_line, *next_line;
tail_line = rtgui_edit_get_line_by_index(edit, edit->upleft.y + edit->visual.y);
if (tail_line != RT_NULL)
{ /* it is tail line */
{
/* it is tail line */
if (tail_line == edit->tail) return RT_FALSE;
}
/* move to next line */
@ -1138,7 +1168,8 @@ static rt_bool_t rtgui_edit_onkey(struct rtgui_object* object, rtgui_event_t* ev
#endif
}
else if (ekbd->key == RTGUIK_LEFT)
{ /* move to prev char */
{
/* move to prev char */
if (edit->visual.x > 0)
{
rt_int16_t tmp_pos = 1;
@ -1166,7 +1197,8 @@ static rt_bool_t rtgui_edit_onkey(struct rtgui_object* object, rtgui_event_t* ev
struct edit_line *first_line;
first_line = rtgui_edit_get_line_by_index(edit, edit->upleft.y + edit->visual.y);
if (first_line != RT_NULL)
{ /* it is head line */
{
/* it is head line */
if (first_line == edit->head) return RT_FALSE;
}
/* move the caret to the prev line end */
@ -1178,7 +1210,8 @@ static rt_bool_t rtgui_edit_onkey(struct rtgui_object* object, rtgui_event_t* ev
}
}
else if (ekbd->key == RTGUIK_RIGHT)
{ /* move to next char */
{
/* move to next char */
if (line->len >= edit->col_per_page)
{
if (edit->upleft.x + edit->col_per_page <= line->len)
@ -1222,7 +1255,8 @@ static rt_bool_t rtgui_edit_onkey(struct rtgui_object* object, rtgui_event_t* ev
struct edit_line *tail_line;
tail_line = rtgui_edit_get_line_by_index(edit, edit->upleft.y + edit->visual.y);
if (tail_line != RT_NULL)
{ /* it is tail line */
{
/* it is tail line */
if (tail_line == edit->tail) return RT_FALSE;
}
/* move the caret to the next line head */
@ -1234,7 +1268,8 @@ static rt_bool_t rtgui_edit_onkey(struct rtgui_object* object, rtgui_event_t* ev
}
}
else if (ekbd->key == RTGUIK_HOME)
{ /* move cursor to line head */
{
/* move cursor to line head */
edit->visual.x = 0;
if (edit->upleft.x > 0)
{
@ -1243,7 +1278,8 @@ static rt_bool_t rtgui_edit_onkey(struct rtgui_object* object, rtgui_event_t* ev
}
}
else if (ekbd->key == RTGUIK_END)
{ /* move cursor to line tail */
{
/* move cursor to line tail */
if (line->len >= edit->col_per_page)
{
edit->visual.x = edit->col_per_page - 1;
@ -1312,7 +1348,8 @@ static rt_bool_t rtgui_edit_onkey(struct rtgui_object* object, rtgui_event_t* ev
else
{
if (isprint((unsigned char)ekbd->key))
{ /* it's may print character */
{
/* it's may print character */
update_type = EDIT_UPDATE;
edit->update.start = edit->visual;
@ -1347,7 +1384,8 @@ static rt_bool_t rtgui_edit_onkey(struct rtgui_object* object, rtgui_event_t* ev
edit->update.end.y = edit->visual.y;
}
else
{ /* adjust line buffer's zone size */
{
/* adjust line buffer's zone size */
line->zsize = rtgui_edit_alloc_len(edit->bzsize, line->len + 1);
line->text = rt_realloc(line->text, line->zsize);
rtgui_edit_onkey(object, event); /* reentry */
@ -1468,7 +1506,8 @@ void rtgui_edit_update(struct rtgui_edit *edit)
rtgui_rect_inflate(&rect, -(edit->margin + RTGUI_WIDGET_BORDER(edit)));
if (edit->update_buf == RT_NULL)
{ /* try again allocate */
{
/* try again allocate */
edit->update_buf = rtgui_malloc(edit->col_per_page + 1);
}
@ -1479,7 +1518,8 @@ void rtgui_edit_update(struct rtgui_edit *edit)
if (i > edit->upleft.y + edit->row_per_page) break;
if (line == RT_NULL)
{ /* when use "RTGUIK_BACKSPACE" backspace forward,
{
/* when use "RTGUIK_BACKSPACE" backspace forward,
* the last line is blank, that only fill background. */
r.x1 = rect.x1;
r.x2 = rect.x1 + prev_len * edit->font_width;
@ -1608,7 +1648,8 @@ void rtgui_edit_ondraw(struct rtgui_edit *edit)
identify_double_byte(edit, line, EDIT_IDENT_DIR_LEFT, &tmp_pos);
ofs = tmp_pos % 2;
if (ofs == 1)
{ /* use dc_buffer draw the left half of double byte */
{
/* use dc_buffer draw the left half of double byte */
char dbl_bmp[3];
rtgui_point_t pot = {0};
rtgui_rect_t r = {0};
@ -1690,12 +1731,14 @@ void rtgui_edit_set_text(struct rtgui_edit* edit, const char* text)
for (ptr = begin; *ptr != '\0'; ptr++)
{
if (*ptr == 0x0A)
{ /* unix style */
{
/* unix style */
rtgui_edit_append_line(edit, begin);
begin = ptr + 1;
}
else if (*ptr == 0x0D && *(ptr + 1) == 0x0A)
{ /* windows style */
{
/* windows style */
rtgui_edit_append_line(edit, begin);
begin = ptr + 2;
}
@ -1853,9 +1896,11 @@ rt_bool_t rtgui_edit_readin_file(struct rtgui_edit *edit, const char *filename)
text = rtgui_malloc(size);
if (text == RT_NULL) return RT_FALSE;
do {
do
{
if ((read_bytes = rtgui_filerw_read(filerw, &ch, 1, 1)) > 0)
{ /* rt_kprintf("ch=%02X ",ch); DEBUG */
{
/* rt_kprintf("ch=%02X ",ch); DEBUG */
if (num >= size - 1)
text = rt_realloc(text, rtgui_edit_alloc_len(size, num));
if (ch == 0x09) //Tab
@ -1874,11 +1919,13 @@ rt_bool_t rtgui_edit_readin_file(struct rtgui_edit *edit, const char *filename)
}
else if (num > 0)
{ /* last line does not exist the end operator */
{
/* last line does not exist the end operator */
*(text + num) = '\0';
rtgui_edit_append_line(edit, text);
}
} while(read_bytes);
}
while (read_bytes);
rtgui_filerw_close(filerw);
rtgui_free(text);

View File

@ -25,7 +25,7 @@
#include <rtgui/widgets/window.h>
#if defined(RTGUI_USING_DFS_FILERW)
#ifdef _WIN32
#ifdef _WIN32_NATIVE
#include <io.h>
#include <dirent.h>
#include <sys/stat.h>
@ -39,7 +39,8 @@
#define RTGUI_FILELIST_MARGIN 5
const static char * file_xpm[] = {
const static char *file_xpm[] =
{
"16 16 21 1",
" c None",
". c #999999",
@ -77,9 +78,11 @@ const static char * file_xpm[] = {
"+@&&,!!**{]]@+ ",
"+@@@@@@@@@@@@+ ",
"^++++++++++++^ ",
" "};
" "
};
const static char * folder_xpm[] = {
const static char *folder_xpm[] =
{
"16 16 121 2",
" c None",
". c #D9B434",
@ -217,7 +220,8 @@ const static char * folder_xpm[] = {
" ,.'.).!.~.{.].^./.(._.:.<.,. ",
" [.}.[.[.[.[.[.[.[.[.}.[.|. ",
" ",
" "};
" "
};
/* image for file and folder */
static rtgui_image_t *file_image, *folder_image;
@ -386,8 +390,10 @@ void rtgui_filelist_view_ondraw(struct rtgui_filelist_view* view)
item_rect.y2 = item_rect.y1 + (1 + rtgui_theme_get_selected_height());
/* get image base rect */
image_rect.x1 = RTGUI_FILELIST_MARGIN; image_rect.y1 = 0;
image_rect.x2 = RTGUI_FILELIST_MARGIN + file_image->w; image_rect.y2 = file_image->h;
image_rect.x1 = RTGUI_FILELIST_MARGIN;
image_rect.y1 = 0;
image_rect.x2 = RTGUI_FILELIST_MARGIN + file_image->w;
image_rect.y2 = file_image->h;
rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
/* get current page */
@ -455,8 +461,10 @@ void rtgui_filelist_view_update_current(struct rtgui_filelist_view* view, rt_uin
item_rect.y2 = item_rect.y1 + (1 + rtgui_theme_get_selected_height());
/* get image rect */
image_rect.x1 = RTGUI_FILELIST_MARGIN; image_rect.y1 = 0;
image_rect.x2 = RTGUI_FILELIST_MARGIN + file_image->w; image_rect.y2 = file_image->h;
image_rect.x1 = RTGUI_FILELIST_MARGIN;
image_rect.y1 = 0;
image_rect.x2 = RTGUI_FILELIST_MARGIN + file_image->w;
image_rect.y2 = file_image->h;
rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
/* draw old item */
@ -480,8 +488,10 @@ void rtgui_filelist_view_update_current(struct rtgui_filelist_view* view, rt_uin
rtgui_theme_draw_selected(dc, &item_rect);
/* get image base rect */
image_rect.x1 = RTGUI_FILELIST_MARGIN; image_rect.y1 = 0;
image_rect.x2 = RTGUI_FILELIST_MARGIN + file_image->w; image_rect.y2 = file_image->h;
image_rect.x1 = RTGUI_FILELIST_MARGIN;
image_rect.y1 = 0;
image_rect.x2 = RTGUI_FILELIST_MARGIN + file_image->w;
image_rect.y2 = file_image->h;
rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
item = &(view->items[view->current_item]);
@ -522,7 +532,7 @@ static void rtgui_filelist_view_onenturn(struct rtgui_filelist_view* view)
}
}
else if (view->current_item == 0 &&
#ifdef _WIN32
#ifdef _WIN32_NATIVE
(view->current_directory[1] == ':') && (view->current_directory[2] == '\\')
#else
(view->current_directory[0] == '/') && (view->current_directory[1] == '\0')
@ -750,7 +760,8 @@ void rtgui_filelist_view_set_directory(rtgui_filelist_view_t* view, const char*
if (strcmp(dirent->d_name, "..") == 0) continue;
view->items_count ++;
} while (dirent != RT_NULL);
}
while (dirent != RT_NULL);
closedir(dir);
view->items_count ++; /* root directory for [x] exit, others for .. */

View File

@ -79,11 +79,13 @@ static void rtgui_list_view_onicondraw(struct rtgui_list_view* view, struct rtgu
drawing_rect.x2 = image->w;
drawing_rect.y2 = image->h;
rtgui_rect_moveto_align(&item_rect, &drawing_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
drawing_rect.y1 += 5; drawing_rect.y2 += 5;
drawing_rect.y1 += 5;
drawing_rect.y2 += 5;
rtgui_image_blit(view->items[item_index].image, dc, &drawing_rect);
item_rect.y1 = drawing_rect.y2 + LIST_MARGIN;
item_rect.x1 += 3; item_rect.x2 -=3;
item_rect.x1 += 3;
item_rect.x2 -= 3;
rtgui_font_get_metrics(RTGUI_WIDGET_FONT(view), view->items[item_index].name,
&drawing_rect);
rtgui_rect_moveto_align(&item_rect, &drawing_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
@ -138,12 +140,14 @@ static void rtgui_list_view_update_icon(struct rtgui_list_view* view, rt_int16_t
drawing_rect.x2 = image->w;
drawing_rect.y2 = image->h;
rtgui_rect_moveto_align(&item_rect, &drawing_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
drawing_rect.y1 += 5; drawing_rect.y2 += 5;
drawing_rect.y1 += 5;
drawing_rect.y2 += 5;
rtgui_image_blit(view->items[old_item].image, dc, &drawing_rect);
/* draw text */
item_rect.y1 = drawing_rect.y2 + LIST_MARGIN;
item_rect.x1 += 3; item_rect.x2 -=3;
item_rect.x1 += 3;
item_rect.x2 -= 3;
rtgui_font_get_metrics(RTGUI_WIDGET_FONT(view), view->items[old_item].name,
&drawing_rect);
rtgui_rect_moveto_align(&item_rect, &drawing_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
@ -169,7 +173,8 @@ static void rtgui_list_view_update_icon(struct rtgui_list_view* view, rt_int16_t
/* draw text */
item_rect.y1 = drawing_rect.y2 + LIST_MARGIN;
item_rect.x1 += 3; item_rect.x2 -=3;
item_rect.x1 += 3;
item_rect.x2 -= 3;
rtgui_font_get_metrics(RTGUI_WIDGET_FONT(view),
view->items[view->current_item].name,
&drawing_rect);
@ -209,7 +214,8 @@ static void rtgui_list_view_onlistdraw(struct rtgui_list_view* view, struct rtgu
if (item->image != RT_NULL)
{
/* blit on center */
image_rect.x1 = 0; image_rect.y1 = 0;
image_rect.x1 = 0;
image_rect.y1 = 0;
image_rect.x2 = item->image->w;
image_rect.y2 = item->image->h;
@ -249,7 +255,8 @@ void rtgui_list_view_update_list(struct rtgui_list_view* view, rt_int16_t old_it
rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
/* get old item's rect and draw old item */
item_rect.x1 = rect.x1; item_rect.x2 = rect.x2;
item_rect.x1 = rect.x1;
item_rect.x2 = rect.x2;
item_rect.y1 = rect.y1 + 2;
item_rect.y1 += (old_item % view->page_items) * (2 + rtgui_theme_get_selected_height());
item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height());
@ -263,7 +270,8 @@ void rtgui_list_view_update_list(struct rtgui_list_view* view, rt_int16_t old_it
struct rtgui_rect image_rect;
/* blit on center */
image_rect.x1 = 0; image_rect.y1 = 0;
image_rect.x1 = 0;
image_rect.y1 = 0;
image_rect.x2 = item->image->w;
image_rect.y2 = item->image->h;
@ -291,7 +299,8 @@ void rtgui_list_view_update_list(struct rtgui_list_view* view, rt_int16_t old_it
struct rtgui_rect image_rect;
/* blit on center */
image_rect.x1 = 0; image_rect.y1 = 0;
image_rect.x1 = 0;
image_rect.y1 = 0;
image_rect.x2 = item->image->w;
image_rect.y2 = item->image->h;
@ -561,11 +570,15 @@ rt_bool_t rtgui_list_view_event_handler(struct rtgui_object* widget, struct rtgu
}
}
return RT_FALSE;
}
default:
/* use view event handler */
return rtgui_container_event_handler(widget, event);
}
return RT_FALSE;
}
RTM_EXPORT(rtgui_list_view_event_handler);
static void rtgui_list_view_calc(struct rtgui_list_view *view)

View File

@ -53,14 +53,16 @@ void rtgui_listbox_ondraw(struct rtgui_listbox* box)
rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect);
rtgui_dc_fill_rect(dc, &rect);
rect.x2 -= 1; rect.y2 -= 1;
rect.x2 -= 1;
rect.y2 -= 1;
/* draw focused border */
if (RTGUI_WIDGET_IS_FOCUSED(box))
rtgui_dc_draw_focus_rect(dc, &rect);
/* get item base rect */
item_rect = rect;
item_rect.x1 += 1; item_rect.x2 -= 1;
item_rect.x1 += 1;
item_rect.x2 -= 1;
item_rect.y1 += 2;
item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height());
@ -122,11 +124,13 @@ static void rtgui_listbox_update_current(struct rtgui_listbox* box, rt_int16_t o
if (dc == RT_NULL) return;
rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect);
rect.x2 -= 1; rect.y2 -= 1;
rect.x2 -= 1;
rect.y2 -= 1;
item_rect = rect;
/* get old item's rect */
item_rect.x1 += 1; item_rect.x2 -= 1;
item_rect.x1 += 1;
item_rect.x2 -= 1;
item_rect.y1 += 2;
item_rect.y1 += (old_item % box->page_items) * (2 + rtgui_theme_get_selected_height());
item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height());
@ -150,7 +154,8 @@ static void rtgui_listbox_update_current(struct rtgui_listbox* box, rt_int16_t o
/* draw current item */
item_rect = rect;
/* get current item's rect */
item_rect.x1 += 1; item_rect.x2 -= 1;
item_rect.x1 += 1;
item_rect.x2 -= 1;
item_rect.y1 += 2;
item_rect.y1 += (box->current_item % box->page_items) * (2 + rtgui_theme_get_selected_height());
item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height());
@ -227,7 +232,8 @@ rt_bool_t rtgui_listbox_event_handler(struct rtgui_object* object, struct rtgui_
/* get widget rect */
rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect);
/* update focus border */
rect.x2 -= 1; rect.y2 -= 1;
rect.x2 -= 1;
rect.y2 -= 1;
/* draw focused border */
if (RTGUI_WIDGET_IS_FOCUSED(box))
rtgui_dc_draw_focus_rect(dc, &rect);
@ -321,11 +327,13 @@ rt_bool_t rtgui_listbox_event_handler(struct rtgui_object* object, struct rtgui_
}
}
return RT_FALSE;
}
default:
/* use box event handler */
return rtgui_widget_event_handler(RTGUI_OBJECT(widget), event);
}
return RT_FALSE;
}
RTM_EXPORT(rtgui_listbox_event_handler);
rtgui_listbox_t *rtgui_listbox_create(const struct rtgui_listbox_item *items, rt_uint16_t count, rtgui_rect_t *rect)
@ -381,15 +389,19 @@ void rtgui_listbox_set_current_item(rtgui_listbox_t* box, int index)
{
RT_ASSERT(box != RT_NULL);
if (index >= box->items_count)
return;
if (index != box->current_item)
{
int old_item;
old_item = box->current_item;
box->current_item = index;
rtgui_listbox_update_current(box, old_item);
}
if (box->on_item)
box->on_item(RTGUI_OBJECT(box), RT_NULL);
}
RTM_EXPORT(rtgui_listbox_set_current_item);
@ -411,7 +423,8 @@ static rt_bool_t rtgui_listbox_onunfocus(struct rtgui_object* object, rtgui_even
{
/* only clear focus rect */
rtgui_color_t color;
rect.x2 -= 1; rect.y2 -= 1;
rect.x2 -= 1;
rect.y2 -= 1;
color = RTGUI_DC_FC(dc);
RTGUI_DC_FC(dc) = RTGUI_DC_BC(dc);
rtgui_dc_draw_focus_rect(dc, &rect);

View File

@ -79,7 +79,8 @@ static void _rtgui_listctrl_scrollbar_ondraw(struct rtgui_listctrl* ctrl, struct
height = height / ((ctrl->items_count + (ctrl->page_items - 1)) / ctrl->page_items);
y1 = (ctrl->current_item / ctrl->page_items) * height;
rect.y1 = rect.y1 + y1; rect.y2 = rect.y1 + height;
rect.y1 = rect.y1 + y1;
rect.y2 = rect.y1 + height;
rect.x1 -= 3;
rtgui_theme_draw_selected(dc, &rect);
}
@ -96,7 +97,8 @@ static void _rtgui_listctrl_scrollbar_onmouse(struct rtgui_listctrl* ctrl, struc
height = height / ((ctrl->items_count + (ctrl->page_items - 1)) / ctrl->page_items);
y1 = (ctrl->current_item / ctrl->page_items) * height;
rect.y1 = rect.y1 + y1; rect.y2 = rect.y1 + height;
rect.y1 = rect.y1 + y1;
rect.y2 = rect.y1 + height;
rtgui_widget_rect_to_device(RTGUI_WIDGET(ctrl), &rect);
old_item = ctrl->current_item;
@ -128,11 +130,13 @@ static void _rtgui_listctrl_ondraw(struct rtgui_listctrl* ctrl)
_rtgui_listctrl_get_rect(ctrl, &rect);
rtgui_dc_fill_rect(dc, &rect);
rect.x2 -= 1; rect.y2 -= 1;
rect.x2 -= 1;
rect.y2 -= 1;
/* get item base rect */
item_rect = rect;
item_rect.x1 += 1; item_rect.x2 -= 1;
item_rect.x1 += 1;
item_rect.x2 -= 1;
item_rect.y1 += 2;
item_rect.y2 = item_rect.y1 + (2 + ctrl->item_height);
@ -178,11 +182,13 @@ void rtgui_listctrl_update_current(struct rtgui_listctrl* ctrl, rt_uint16_t old_
if (dc == RT_NULL) return;
_rtgui_listctrl_get_rect(ctrl, &rect);
rect.x2 -= 1; rect.y2 -= 1;
rect.x2 -= 1;
rect.y2 -= 1;
item_rect = rect;
/* get old item's rect */
item_rect.x1 += 1; item_rect.x2 -= 1;
item_rect.x1 += 1;
item_rect.x2 -= 1;
item_rect.y1 += 2;
item_rect.y1 += (old_item % ctrl->page_items) * (2 + ctrl->item_height);
item_rect.y2 = item_rect.y1 + (2 + ctrl->item_height);
@ -195,7 +201,8 @@ void rtgui_listctrl_update_current(struct rtgui_listctrl* ctrl, rt_uint16_t old_
/* draw current item */
item_rect = rect;
/* get current item's rect */
item_rect.x1 += 1; item_rect.x2 -= 1;
item_rect.x1 += 1;
item_rect.x2 -= 1;
item_rect.y1 += 2;
item_rect.y1 += (ctrl->current_item % ctrl->page_items) * (2 + ctrl->item_height);
item_rect.y2 = item_rect.y1 + (2 + ctrl->item_height);
@ -272,7 +279,8 @@ rt_bool_t rtgui_listctrl_event_handler(struct rtgui_object* object, struct rtgui
/* get widget rect */
rtgui_widget_get_rect(RTGUI_WIDGET(ctrl), &rect);
/* update focus border */
rect.x2 -= 1; rect.y2 -= 1;
rect.x2 -= 1;
rect.y2 -= 1;
rtgui_dc_end_drawing(dc);
}
}
@ -357,14 +365,16 @@ rt_bool_t rtgui_listctrl_event_handler(struct rtgui_object* object, struct rtgui
}
}
return RT_FALSE;
}
default:
/* use ctrl event handler */
return rtgui_widget_event_handler(RTGUI_OBJECT(widget), event);
}
return RT_FALSE;
}
RTM_EXPORT(rtgui_listctrl_event_handler);
rtgui_listctrl_t* rtgui_listctrl_create(rt_uint32_t items, rt_uint16_t count, rtgui_rect_t *rect,
rtgui_listctrl_t *rtgui_listctrl_create(void *items, rt_uint16_t count, rtgui_rect_t *rect,
rtgui_onitem_draw_t ondraw)
{
struct rtgui_listctrl *ctrl = RT_NULL;
@ -399,7 +409,7 @@ void rtgui_listctrl_set_onitem(rtgui_listctrl_t* ctrl, rtgui_event_handler_ptr f
}
RTM_EXPORT(rtgui_listctrl_set_onitem);
void rtgui_listctrl_set_items(rtgui_listctrl_t* ctrl, rt_uint32_t items, rt_uint16_t count)
void rtgui_listctrl_set_items(rtgui_listctrl_t *ctrl, void *items, rt_uint16_t count)
{
rtgui_rect_t rect;
@ -414,6 +424,36 @@ void rtgui_listctrl_set_items(rtgui_listctrl_t* ctrl, rt_uint32_t items, rt_uint
}
RTM_EXPORT(rtgui_listctrl_set_items);
/**
* @brief set the selected(current) item of listctrl widget.
*
* If the index is greater than items_count, it will have no effect. Otherwise,
* the item on @param index will be selected and the on_item will be invoked if
* it has one.
*
* @fixme set current to the items which is not in current page won't update
* the scrollbar.
*/
void rtgui_listctrl_set_current_item(struct rtgui_listctrl *ctrl, rt_uint16_t index)
{
RT_ASSERT(ctrl);
if (index >= ctrl->items_count)
return;
if (index != ctrl->current_item)
{
rt_uint16_t old_item = ctrl->current_item;
ctrl->current_item = index;
rtgui_listctrl_update_current(ctrl, old_item);
}
if (ctrl->on_item != RT_NULL)
{
ctrl->on_item(RTGUI_OBJECT(ctrl), RT_NULL);
}
}
RTM_EXPORT(rtgui_listctrl_set_current_item);
rt_bool_t rtgui_listctrl_get_item_rect(rtgui_listctrl_t *ctrl, rt_uint16_t item, rtgui_rect_t *item_rect)
{
if (item < ctrl->items_count)

View File

@ -128,7 +128,8 @@ static void _rtgui_menu_item_ondraw(struct rtgui_listctrl *list,
{
rtgui_rect_t r = {0, 0, 8, 8};
rtgui_dc_draw_text(dc, item->label, &item_rect);
item_rect.x1 = item_rect.x2 - 16; item_rect.x2 -= 8;
item_rect.x1 = item_rect.x2 - 16;
item_rect.x2 -= 8;
rtgui_rect_moveto_align(&item_rect, &r, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
rtgui_dc_draw_byte(dc, r.x1, r.y1, 8, right_arrow);
}
@ -218,7 +219,7 @@ struct rtgui_menu* rtgui_menu_create(const char* title, struct rtgui_menu* paren
rtgui_widget_set_rect(RTGUI_WIDGET(menu), &rect);
rtgui_rect_inflate(&rect, -1);
/* create menu item list */
menu->items_list = rtgui_listctrl_create((rt_uint32_t)items, count, &rect, _rtgui_menu_item_ondraw);
menu->items_list = rtgui_listctrl_create((void*)items, count, &rect, _rtgui_menu_item_ondraw);
RTGUI_WIDGET_BACKGROUND(menu->items_list) = rtgui_theme_default_bc();
rtgui_container_add_child(RTGUI_CONTAINER(menu), RTGUI_WIDGET(menu->items_list));
rtgui_listctrl_set_onitem(menu->items_list, _rtgui_menu_onitem);
@ -255,16 +256,20 @@ void rtgui_menu_pop(struct rtgui_menu* menu, int x, int y)
return;
/* set window extent */
rect.x1 = 0; rect.y1 = 0;
rect.x2 = 100; rect.y2 = menu->items_count * (rtgui_theme_get_selected_height() + 2) + 5;
rect.x1 = 0;
rect.y1 = 0;
rect.x2 = 100;
rect.y2 = menu->items_count * (rtgui_theme_get_selected_height() + 2) + 5;
rtgui_rect_moveto(&rect, x, y);
rtgui_win_set_rect(RTGUI_WIN(menu), &rect);
rtgui_rect_inflate(&rect, -1);
rtgui_widget_set_rect(RTGUI_WIDGET(menu->items_list), &rect);
eresize.parent.type = RTGUI_EVENT_RESIZE;
eresize.x = rect.x1; eresize.y = rect.y1;
eresize.h = rect.y2 - rect.y1; eresize.w = rect.x2 - rect.x1;
eresize.x = rect.x1;
eresize.y = rect.y1;
eresize.h = rect.y2 - rect.y1;
eresize.w = rect.x2 - rect.x1;
rtgui_listctrl_event_handler(RTGUI_OBJECT(menu->items_list), &(eresize.parent));
/* on menu pop handler */

View File

@ -0,0 +1,81 @@
/*
* File : mv_view.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2012-09-17 Grissiom first version
*/
#include <rtgui/rtgui.h>
#include <rtgui/rtgui_mv_model.h>
#include <rtgui/widgets/mv_view.h>
static void _rtgui_mv_view_constructor(struct rtgui_mv_view *view)
{
view->model_number = 0;
view->model = RT_NULL;
}
static void _rtgui_mv_view_destructor(struct rtgui_mv_view *view)
{
if (view->model_number == 1)
{
rtgui_mv_model_remove_view(view->model, view);
}
else if (view->model_number > 1)
{
void **model_arr = *(void ** *)view->model;
int i;
for (i = 0; i < view->model_number; i++)
{
rtgui_mv_model_remove_view(model_arr[i], view);
}
}
}
DEFINE_CLASS_TYPE(mv_view, "mv_view",
RTGUI_WIDGET_TYPE,
_rtgui_mv_view_constructor,
_rtgui_mv_view_destructor,
sizeof(struct rtgui_mv_view));
struct rtgui_mv_view *rtgui_mv_view_create(void)
{
return RTGUI_MV_VIEW(rtgui_widget_create(RTGUI_MV_VIEW_TYPE));
}
void rtgui_mv_view_destroy(struct rtgui_mv_view *view)
{
rtgui_widget_destroy(RTGUI_WIDGET(view));
}
struct rtgui_mv_model *rtgui_mv_view_foreach_in_model(struct rtgui_mv_view *view, rt_uint32_t *iter)
{
struct rtgui_mv_model *model;
RT_ASSERT(view);
if (*iter >= view->model_number)
return RT_NULL;
if (view->model_number == 1)
{
model = view->model;
}
else
{
struct rtgui_mv_model **model_array = view->model;
model = model_array[*iter];
}
(*iter)++;
return model;
}

View File

@ -375,13 +375,13 @@ void rtgui_notebook_add(struct rtgui_notebook* notebook, const char* label, stru
/* set parent */
rtgui_widget_set_parent(child, RTGUI_WIDGET(notebook));
if (notebook->count - 1 != notebook->current)
rtgui_widget_hide(child);
_rtgui_notebook_get_page_rect(notebook, &rect);
rtgui_widget_rect_to_device(RTGUI_WIDGET(notebook), &rect);
rtgui_widget_set_rect(child, &rect);
if (notebook->count - 1 != notebook->current)
rtgui_widget_hide(child);
if (RTGUI_WIDGET(notebook)->toplevel != RT_NULL &&
RTGUI_IS_WIN(RTGUI_WIDGET(notebook)->toplevel))
{
@ -578,6 +578,8 @@ static void _rtgui_notebook_all_widget_handle(struct rtgui_notebook *notebook,
rt_bool_t rtgui_notebook_event_handler(struct rtgui_object *object, struct rtgui_event *event)
{
int page_index;
rtgui_rect_t rect;
struct rtgui_notebook *notebook;
RT_ASSERT(object != RT_NULL);
@ -611,6 +613,17 @@ rt_bool_t rtgui_notebook_event_handler(struct rtgui_object* object, struct rtgui
/* update all the widgets in myself */
_rtgui_notebook_all_widget_handle(notebook, event);
return RT_FALSE;
case RTGUI_EVENT_RESIZE:
/* re-size page widget */
_rtgui_notebook_get_page_rect(notebook, &rect);
rtgui_widget_rect_to_device(RTGUI_WIDGET(notebook), &rect);
for (page_index = 0; page_index < notebook->count; page_index ++)
{
rtgui_widget_set_rect(notebook->childs[page_index].widget, &rect);
}
break;
default:
/* use parent event handler */
return rtgui_widget_event_handler(object, event);

View File

@ -1,5 +1,5 @@
/*
* File : plot.h
* File : plot.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2012, RT-Thread Development Team
*
@ -15,42 +15,32 @@
#include <rtgui/rtgui_system.h>
#include <rtgui/dc.h>
#include <rtgui/widgets/plot.h>
#include <rtgui/widgets/plot_curve.h>
static void _rtgui_plot_constructor(struct rtgui_plot *plot)
{
plot->base_point.x = plot->base_point.y = 0;
plot->curve_container.curve = RT_NULL;
plot->curve_container.next = RT_NULL;
plot->base_x = plot->base_y = 0;
plot->ptype = RTGUI_PLOT_TYPE_SCAN;
plot->scale_x = plot->scale_y = 1;
/* init widget and set event handler */
rtgui_object_set_event_handler(RTGUI_OBJECT(plot), rtgui_plot_event_handler);
}
static void _free_curve_container_recursive(struct rtgui_plot_curve_container *cnt)
{
if (!cnt)
return;
_free_curve_container_recursive(cnt->next);
rtgui_free(cnt);
}
static void _rtgui_plot_destructor(struct rtgui_plot *plot)
{
_free_curve_container_recursive(plot->curve_container.next);
}
DEFINE_CLASS_TYPE(plot, "plot",
RTGUI_WIDGET_TYPE,
RTGUI_MV_VIEW_TYPE,
_rtgui_plot_constructor,
_rtgui_plot_destructor,
sizeof(struct rtgui_plot));
struct rtgui_plot *rtgui_plot_create(struct rtgui_plot_curve *curve)
struct rtgui_plot *rtgui_plot_create(void)
{
struct rtgui_plot *plot;
plot = (struct rtgui_plot *)rtgui_widget_create(RTGUI_PLOT_TYPE);
plot->curve_container.curve = curve;
plot = RTGUI_PLOT(rtgui_widget_create(RTGUI_PLOT_TYPE));
return plot;
}
@ -58,45 +48,40 @@ RTM_EXPORT(rtgui_plot_create);
void rtgui_plot_destroy(struct rtgui_plot *plot)
{
rtgui_widget_destroy(RTGUI_WIDGET(plot));
rtgui_mv_view_destroy(RTGUI_MV_VIEW(plot));
}
RTM_EXPORT(rtgui_plot_destroy);
void rtgui_plot_set_base_point(struct rtgui_plot *plot, rt_uint16_t x, rt_uint16_t y)
void rtgui_plot_set_base(struct rtgui_plot *plot,
rtgui_plot_curve_dtype x, rtgui_plot_curve_dtype y)
{
plot->base_point.x = x;
plot->base_point.y = y;
plot->base_x = x;
plot->base_y = y;
}
RTM_EXPORT(rtgui_plot_set_base_point);
RTM_EXPORT(rtgui_plot_set_base);
void rtgui_plot_append_curve(struct rtgui_plot *plot, struct rtgui_plot_curve *curve)
rt_inline int _rtgui_plot_curve_calc_x(struct rtgui_plot *plot, rtgui_plot_curve_dtype x)
{
struct rtgui_plot_curve_container *cur_cnt, *next_cnt;
return (x - plot->base_x) / plot->scale_x;
}
RT_ASSERT(plot);
next_cnt = rtgui_malloc(sizeof(*next_cnt));
next_cnt->curve = curve;
next_cnt->next = RT_NULL;
cur_cnt = &plot->curve_container;
while (cur_cnt->next)
rt_inline int _rtgui_plot_curve_calc_y(struct rtgui_plot *plot, rtgui_plot_curve_dtype y, rt_uint16_t height)
{
cur_cnt = cur_cnt->next;
return height - (y - plot->base_y) / plot->scale_y;
}
cur_cnt->next = next_cnt;
}
RTM_EXPORT(rtgui_plot_append_curve);
static void _rtgui_plot_curve_onpaint(
struct rtgui_dc *dc,
struct rtgui_plot *plot,
struct rtgui_plot_curve *curve,
struct rtgui_point base)
rt_uint16_t start_idx,
rt_uint16_t stop_idx)
{
struct rtgui_rect rect;
rt_uint16_t height;
int last_x, last_y;
rtgui_color_t old_color;
rtgui_plot_curve_dtype *x_data, *y_data;
rtgui_dc_get_rect(dc, &rect);
height = rtgui_rect_height(rect);
@ -104,16 +89,18 @@ static void _rtgui_plot_curve_onpaint(
old_color = RTGUI_DC_FC(dc);
RTGUI_DC_FC(dc) = curve->color;
if (curve->x_data)
x_data = rtgui_plot_curve_get_x(curve);
y_data = rtgui_plot_curve_get_y(curve);
if (x_data)
{
rt_size_t i;
last_x = curve->x_data[0] + base.x;
last_y = height - curve->y_data[0] - base.y;
for (i = 1; i < curve->length; i++)
last_x = _rtgui_plot_curve_calc_x(plot, x_data[start_idx]);
last_y = _rtgui_plot_curve_calc_y(plot, y_data[start_idx], height);
for (i = start_idx + 1; i < stop_idx; i++)
{
int cur_x = curve->x_data[i] + base.x;
int cur_y = height - curve->y_data[i] - base.y;
int cur_x = _rtgui_plot_curve_calc_x(plot, x_data[i]);
int cur_y = _rtgui_plot_curve_calc_y(plot, y_data[i], height);
rtgui_dc_draw_line(dc,
last_x, last_y,
cur_x, cur_y);
@ -125,12 +112,12 @@ static void _rtgui_plot_curve_onpaint(
{
rt_size_t i;
last_x = 0 + base.x;
last_y = height - curve->y_data[0] - base.y;
for (i = 1; i < curve->length; i++)
last_x = _rtgui_plot_curve_calc_x(plot, start_idx);
last_y = _rtgui_plot_curve_calc_y(plot, y_data[start_idx], height);
for (i = start_idx + 1; i < stop_idx; i++)
{
int cur_x = i + base.x;
int cur_y = height - curve->y_data[i] - base.y;
int cur_x = _rtgui_plot_curve_calc_x(plot, i);
int cur_y = _rtgui_plot_curve_calc_y(plot, y_data[i], height);
rtgui_dc_draw_line(dc,
last_x, last_y,
cur_x, cur_y);
@ -141,44 +128,160 @@ static void _rtgui_plot_curve_onpaint(
RTGUI_DC_FC(dc) = old_color;
}
static void _rtgui_plot_onpaint(struct rtgui_object *object, struct rtgui_event *event)
static void _rtgui_plot_draw_curve(struct rtgui_plot *plot, struct rtgui_event *event)
{
int i;
struct rtgui_dc *dc;
struct rtgui_rect rect;
struct rtgui_plot *plot = RTGUI_PLOT(object);
struct rtgui_plot_curve_container *cnt;
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(plot));
if (dc == RT_NULL)
return;
rtgui_widget_get_rect(RTGUI_WIDGET(object), &rect);
rtgui_dc_fill_rect(dc, &rect);
for (cnt = &plot->curve_container; cnt; cnt = cnt->next)
if (RTGUI_MV_VIEW(plot)->model_number == 1)
{
_rtgui_plot_curve_onpaint(dc, cnt->curve, plot->base_point);
_rtgui_plot_curve_onpaint(dc, plot,
RTGUI_PLOT_CURVE(RTGUI_MV_VIEW(plot)->model),
0, RTGUI_MV_MODEL(RTGUI_MV_VIEW(plot)->model)->length);
}
else
{
void **curve_array = (void **)RTGUI_MV_VIEW(plot)->model;
for (i = 0; i < RTGUI_MV_VIEW(plot)->model_number; i++)
{
_rtgui_plot_curve_onpaint(dc, plot,
RTGUI_PLOT_CURVE(curve_array[i]),
0, RTGUI_MV_MODEL(curve_array[i])->length);
}
}
rtgui_dc_end_drawing(dc);
}
rt_bool_t rtgui_plot_event_handler(struct rtgui_object *object, struct rtgui_event *event)
static void _rtgui_plot_update_scale(struct rtgui_plot *plot)
{
struct rtgui_plot *plot;
RTGUI_WIDGET_EVENT_HANDLER_PREPARE;
struct rtgui_plot_curve *curve;
struct rtgui_rect rect;
rtgui_plot_curve_dtype max_x = 0;
rtgui_plot_curve_dtype min_x = 0;
rtgui_plot_curve_dtype max_y = 0;
rtgui_plot_curve_dtype min_y = 0;
rt_uint32_t iter = 0;
plot = RTGUI_PLOT(object);
switch (event->type)
rtgui_widget_get_rect(RTGUI_WIDGET(plot), &rect);
curve = RTGUI_PLOT_CURVE(
rtgui_mv_view_foreach_in_model(RTGUI_MV_VIEW(plot), &iter));
max_x = curve->max_x;
min_x = curve->min_x;
max_y = curve->max_y;
min_y = curve->min_y;
while (curve)
{
case RTGUI_EVENT_PAINT:
_rtgui_plot_onpaint(object, event);
break;
default:
return rtgui_widget_event_handler(object, event);
if (curve->max_x > max_x)
max_x = curve->max_x;
if (curve->min_x < min_x)
min_x = curve->min_x;
if (curve->max_y > max_y)
max_y = curve->max_y;
if (curve->min_y < min_y)
min_y = curve->min_y;
curve = RTGUI_PLOT_CURVE(
rtgui_mv_view_foreach_in_model(RTGUI_MV_VIEW(plot), &iter));
}
plot->scale_x = (max_x - min_x + rtgui_rect_width(rect)) / rtgui_rect_width(rect);
plot->scale_y = (max_y - min_y + rtgui_rect_height(rect)) / rtgui_rect_height(rect);
}
rt_bool_t rtgui_plot_ondraw(struct rtgui_plot *plot, struct rtgui_event *event)
{
struct rtgui_dc *dc;
struct rtgui_rect rect;
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(plot));
if (dc == RT_NULL)
return RT_FALSE;
rtgui_widget_get_rect(RTGUI_WIDGET(plot), &rect);
rtgui_dc_fill_rect(dc, &rect);
_rtgui_plot_draw_curve(plot, event);
rtgui_dc_end_drawing(dc);
return RT_FALSE;
}
rt_bool_t rtgui_plot_onmvmodel(struct rtgui_plot *plot, struct rtgui_event *event)
{
struct rtgui_event_mv_model *emodel = (struct rtgui_event_mv_model *)event;
RT_ASSERT(plot);
RT_ASSERT(event);
switch (plot->ptype)
{
case RTGUI_PLOT_TYPE_SCAN:
_rtgui_plot_update_scale(plot);
rtgui_plot_ondraw(plot, event);
case RTGUI_PLOT_TYPE_INCREMENTAL:
{
rt_uint16_t old_sc_x = plot->scale_x;
rt_uint16_t old_sc_y = plot->scale_y;
_rtgui_plot_update_scale(plot);
if (old_sc_x != plot->scale_x || old_sc_y != plot->scale_y)
{
/* we need to repaint the whole widget as the scale changed. */
rtgui_plot_ondraw(plot, event);
}
else
{
/* get dc for _rtgui_plot_curve_onpaint */
struct rtgui_dc *dc;
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(plot));
if (dc == RT_NULL)
return RT_FALSE;
/* only draw the newly recieved data */
_rtgui_plot_curve_onpaint(dc, plot,
RTGUI_PLOT_CURVE(emodel->model),
emodel->first_data_changed_idx,
emodel->last_data_changed_idx + 1);
rtgui_dc_end_drawing(dc);
}
}
return RT_TRUE;
default:
RT_ASSERT(0);
}
return RT_TRUE;
}
rt_bool_t rtgui_plot_event_handler(struct rtgui_object *object, struct rtgui_event *event)
{
struct rtgui_plot *plot;
RTGUI_WIDGET_EVENT_HANDLER_PREPARE;
plot = RTGUI_PLOT(object);
switch (event->type)
{
case RTGUI_EVENT_PAINT:
_rtgui_plot_update_scale(RTGUI_PLOT(object));
return rtgui_plot_ondraw(plot, event);
case RTGUI_EVENT_MV_MODEL:
return rtgui_plot_onmvmodel(plot, event);
default:
return rtgui_widget_event_handler(object, event);
}
}
RTM_EXPORT(rtgui_plot_event_handler);

View File

@ -13,14 +13,14 @@
*/
#include <rtgui/color.h>
#include <rtgui/rtgui_mv_model.h>
#include <rtgui/widgets/widget.h>
#include <rtgui/widgets/plot_curve.h>
static void _rtgui_plot_curve_constructor(struct rtgui_plot_curve *curve)
{
curve->length = 0;
curve->x_data = curve->y_data = RT_NULL;
curve->color = red;
curve->max_x = curve->min_x = curve->max_y = curve->min_y = 0;
/* init widget and set event handler */
rtgui_object_set_event_handler(RTGUI_OBJECT(curve), RT_NULL);
@ -32,20 +32,56 @@ static void _rtgui_plot_curve_destructor(struct rtgui_plot_curve *curve)
}
DEFINE_CLASS_TYPE(plot_curve, "plot_curve",
RTGUI_OBJECT_TYPE,
RTGUI_MV_MODEL_TYPE,
_rtgui_plot_curve_constructor,
_rtgui_plot_curve_destructor,
sizeof(struct rtgui_plot_curve));
struct rtgui_plot_curve *rtgui_plot_curve_create(void)
{
return (struct rtgui_plot_curve*)rtgui_object_create(RTGUI_PLOT_CURVE_TYPE);
struct rtgui_plot_curve *curve;
curve = RTGUI_PLOT_CURVE(rtgui_object_create(RTGUI_PLOT_CURVE_TYPE));
if (curve == RT_NULL)
return RT_NULL;
if (rtgui_mv_model_set_dimension(RTGUI_MV_MODEL(curve), 2) != RT_EOK)
{
rtgui_object_destroy(RTGUI_OBJECT(curve));
return RT_NULL;
}
return curve;
}
RTM_EXPORT(rtgui_plot_curve_create);
void rtgui_plot_curve_destroy(struct rtgui_plot_curve *curve)
{
rtgui_object_destroy(RTGUI_OBJECT(curve));
rtgui_mv_model_destroy(RTGUI_MV_MODEL(curve));
}
RTM_EXPORT(rtgui_plot_curve_destroy);
void rtgui_plot_curve_set_x(struct rtgui_plot_curve *curve, void *p)
{
rtgui_mv_model_set_data(RTGUI_MV_MODEL(curve), 0, p);
}
RTM_EXPORT(rtgui_plot_curve_set_x);
void *rtgui_plot_curve_get_x(struct rtgui_plot_curve *curve)
{
return rtgui_mv_model_get_data(RTGUI_MV_MODEL(curve), 0);
}
RTM_EXPORT(rtgui_plot_curve_get_x);
void rtgui_plot_curve_set_y(struct rtgui_plot_curve *curve, void *p)
{
rtgui_mv_model_set_data(RTGUI_MV_MODEL(curve), 1, p);
}
RTM_EXPORT(rtgui_plot_curve_set_y);
void *rtgui_plot_curve_get_y(struct rtgui_plot_curve *curve)
{
return rtgui_mv_model_get_data(RTGUI_MV_MODEL(curve), 1);
}
RTM_EXPORT(rtgui_plot_curve_get_y);

View File

@ -9,120 +9,284 @@
*
* Change Logs:
* Date Author Notes
* 2010-08-09 Bernard first version
*
*/
#include <stdlib.h>
#include <rtgui/dc.h>
#include <rtgui/rtgui_theme.h>
#include <rtgui/widgets/scrollbar.h>
static void _rtgui_scrollbar_constructor(rtgui_scrollbar_t *bar)
{
struct rtgui_rect rect = {0, 0, RTGUI_DEFAULT_SB_WIDTH, RTGUI_DEFAULT_SB_HEIGHT};
/* set event handler */
rtgui_object_set_event_handler(RTGUI_OBJECT(bar), rtgui_scrollbar_event_handler);
rtgui_scrollbar_set_range(bar, 0, 100);
rtgui_scrollbar_set_page_step(bar, 20);
rtgui_scrollbar_set_line_step(bar, 10);
bar->status = 0;
bar->thumb_position = 0;
bar->thumb_size = 16;
bar->value = 0;
bar->thumb_w = 16;
bar->thumb_len = 16;
bar->widget_link = RT_NULL;
bar->on_scroll = RT_NULL;
bar->orient = RTGUI_HORIZONTAL;
rtgui_widget_set_rect(RTGUI_WIDGET(bar), &rect);
/* set gc */
RTGUI_WIDGET_TEXTALIGN(bar) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL;
RTGUI_WIDGET_TEXTALIGN(bar) = RTGUI_ALIGN_CENTER;
}
rt_inline rt_uint32_t _rtgui_scrollbar_get_length(rtgui_scrollbar_t *bar)
static void _rtgui_scrollbar_destructor(rtgui_scrollbar_t *bar)
{
struct rtgui_rect rect;
}
rt_uint32_t _rtgui_scrollbar_get_length(rtgui_scrollbar_t *bar)
{
rtgui_rect_t rect;
rt_uint32_t result;
rtgui_widget_get_rect(RTGUI_WIDGET(bar), &rect);
if(bar->orient & RTGUI_VERTICAL)
return rect.y2 - 2 * (rect.x2 - rect.x1);
result = rtgui_rect_height(rect) - 2*rtgui_rect_width(rect) - bar->thumb_len;
else
result = rtgui_rect_width(rect) - 2*rtgui_rect_height(rect) - bar->thumb_len;
return rect.x2 - 2 * (rect.y2 - rect.y1);
return result;
}
rt_inline rt_uint32_t _rtgui_scrollbar_get_thumb_position(rtgui_scrollbar_t* bar)
rt_uint32_t get_scrollbar_pos(rtgui_scrollbar_t* bar)
{
rt_uint32_t thumb_position;
double pos,ftmp;
rt_uint32_t result;
/* calculate thumb position */
thumb_position = (rtgui_scrollbar_get_value(bar) - bar->min_position) * _rtgui_scrollbar_get_length(bar) /
(bar->max_position - bar->min_position);
pos = bar->value;
ftmp = _rtgui_scrollbar_get_length(bar);
pos *= ftmp;
ftmp = bar->count;
pos /= ftmp;
return thumb_position;
}
void rtgui_scrollbar_get_thumb_rect(rtgui_scrollbar_t *bar, rtgui_rect_t *rect)
{
struct rtgui_rect scrollbar_rect;
rtgui_widget_get_rect(RTGUI_WIDGET(bar), &scrollbar_rect);
if (bar->orient & RTGUI_VERTICAL)
{
rt_uint32_t btn_width = scrollbar_rect.x2 - scrollbar_rect.x1;
/* vertical scroll bar */
rect->x1 = scrollbar_rect.x1;
rect->x2 = scrollbar_rect.x2;
rect->y1 = scrollbar_rect.y1 + btn_width + _rtgui_scrollbar_get_thumb_position(bar);
rect->y2 = rect->y1 + btn_width;
}
else
{
rt_uint32_t btn_height = scrollbar_rect.y2 - scrollbar_rect.y1;
/* horizontal scroll bar */
rect->x1 = scrollbar_rect.x1 + btn_height + _rtgui_scrollbar_get_thumb_position(bar);
rect->x2 = rect->x1 + btn_height;
rect->y1 = scrollbar_rect.y1;
rect->y2 = scrollbar_rect.y2;
}
result = pos;
return result;
}
DEFINE_CLASS_TYPE(scrollbar, "scrollbar",
RTGUI_WIDGET_TYPE,
_rtgui_scrollbar_constructor,
RT_NULL,
_rtgui_scrollbar_destructor,
sizeof(struct rtgui_scrollbar));
static void _rtgui_scrollbar_on_mouseclick(struct rtgui_widget * widget, struct rtgui_event * event)
rtgui_scrollbar_t* rtgui_scrollbar_create(rtgui_container_t *container,int left,int top,int w,int len,int orient)
{
rtgui_rect_t btn_rect, bar_rect;
rt_uint32_t thumb_size, thumb_position;
struct rtgui_scrollbar* bar = (struct rtgui_scrollbar*)widget;
struct rtgui_event_mouse* mouse = (struct rtgui_event_mouse*)event;
rtgui_scrollbar_t* bar;
/* get the thumb size and position */
thumb_size = bar->thumb_size * (bar->max_position - bar->min_position) / _rtgui_scrollbar_get_length(bar);
thumb_position = _rtgui_scrollbar_get_thumb_position(bar);
RT_ASSERT(container != RT_NULL);
bar = (rtgui_scrollbar_t *)rtgui_widget_create(RTGUI_SCROLLBAR_TYPE);
if(bar != RT_NULL)
{
rtgui_rect_t rect;
rtgui_widget_get_rect(RTGUI_WIDGET(container), &rect);
rtgui_widget_rect_to_device(RTGUI_WIDGET(container),&rect);
rect.x1 += left;
rect.y1 += top;
bar->thumb_w = w;
if(orient == RTGUI_VERTICAL)
{
rect.x2 = rect.x1+w;
rect.y2 = rect.y1+len;
}
else
{
rect.x2 = rect.x1+len;
rect.y2 = rect.y1+w;
}
rtgui_widget_set_rect(RTGUI_WIDGET(bar), &rect);
bar->orient = orient;
rtgui_container_add_child(container, RTGUI_WIDGET(bar));
}
return bar;
}
void rtgui_scrollbar_destroy(rtgui_scrollbar_t* bar)
{
rtgui_widget_destroy(RTGUI_WIDGET(bar));
}
const static rt_uint8_t _up_arrow[] = {0x10, 0x38, 0x7C, 0xFE};
const static rt_uint8_t _down_arrow[] = {0xFE,0x7C, 0x38, 0x10};
const static rt_uint8_t _left_arrow[] = {0x10, 0x30, 0x70, 0xF0, 0x70, 0x30, 0x10};
const static rt_uint8_t _right_arrow[] = {0x80, 0xC0, 0xE0, 0xF0, 0xE0, 0xC0, 0x80};
void rtgui_scrollbar_ondraw(rtgui_scrollbar_t* bar)
{
/* draw scroll bar */
rtgui_rect_t rect, btn_rect, thum_rect, arrow_rect;
struct rtgui_dc* dc;
rtgui_color_t bc;
RT_ASSERT(bar != RT_NULL);
/* begin drawing */
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(bar));
if(dc == RT_NULL)return;
bc = RTGUI_DC_BC(dc);
/* begin drawing */
rtgui_widget_get_rect(RTGUI_WIDGET(bar), &rect);
RTGUI_DC_BC(dc) = white;
rtgui_dc_fill_rect(dc,&rect);
RTGUI_DC_BC(dc) = bc;
if(bar->orient == RTGUI_VERTICAL)
{
btn_rect = rect;
btn_rect.y2 = btn_rect.y1 + (rect.x2 - rect.x1);
rtgui_dc_fill_rect(dc,&btn_rect);
/* draw up button */
if(bar->status & SBS_UPARROW)
rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
else
rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);
/* draw up arrow */
arrow_rect.x1 = 0; arrow_rect.y1 = 0;
arrow_rect.x2 = 7; arrow_rect.y2 = 4;
rtgui_rect_moveto_align(&btn_rect, &arrow_rect, RTGUI_ALIGN_CENTER);
rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1, rtgui_rect_height(arrow_rect), _up_arrow);
/* draw thumb */
rtgui_scrollbar_get_thumb_rect(bar, &thum_rect);
rtgui_dc_fill_rect(dc,&thum_rect);
rtgui_dc_draw_border(dc, &thum_rect, RTGUI_BORDER_RAISE);
/* draw down button */
btn_rect.y1 = rect.y2 - (rect.x2 - rect.x1);
btn_rect.y2 = rect.y2;
rtgui_dc_fill_rect(dc,&btn_rect);
if(bar->status & SBS_DOWNARROW)
rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
else
rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);
/* draw down arrow */
arrow_rect.x1 = 0;
arrow_rect.y1 = 0;
arrow_rect.x2 = 7;
arrow_rect.y2 = 4;
rtgui_rect_moveto_align(&btn_rect, &arrow_rect, RTGUI_ALIGN_CENTER);
rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1, rtgui_rect_height(arrow_rect), _down_arrow);
}
else
{
btn_rect = rect;
btn_rect.x2 = btn_rect.x1 + (rect.y2 - rect.y1);
rtgui_dc_fill_rect(dc,&btn_rect);
/* draw left button */
if(bar->status & SBS_LEFTARROW)
rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
else
rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);
arrow_rect.x1 = 0;
arrow_rect.y1 = 0;
arrow_rect.x2 = 4;
arrow_rect.y2 = 7;
rtgui_rect_moveto_align(&btn_rect, &arrow_rect, RTGUI_ALIGN_CENTER);
rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1, rtgui_rect_height(arrow_rect), _left_arrow);
/* draw thumb */
if(RTGUI_WIDGET_IS_ENABLE(bar))
{
rtgui_scrollbar_get_thumb_rect(bar, &thum_rect);
rtgui_dc_fill_rect(dc,&thum_rect);
rtgui_dc_draw_border(dc, &thum_rect, RTGUI_BORDER_RAISE);
}
btn_rect.x1 = rect.x2 - (rect.y2-rect.y1);
btn_rect.x2 = rect.x2;
rtgui_dc_fill_rect(dc,&btn_rect);
/* draw right button */
if(bar->status & SBS_RIGHTARROW)
rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
else
rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);
arrow_rect.x1 = 0;
arrow_rect.y1 = 0;
arrow_rect.x2 = 4;
arrow_rect.y2 = 7;
rtgui_rect_moveto_align(&btn_rect, &arrow_rect, RTGUI_ALIGN_CENTER);
rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1, rtgui_rect_height(arrow_rect), _right_arrow);
}
rtgui_dc_end_drawing(dc);
}
void rtgui_scrollbar_get_thumb_rect(rtgui_scrollbar_t *bar, rtgui_rect_t *erect)
{
rtgui_rect_t rect;
rtgui_widget_get_rect(RTGUI_WIDGET(bar), &rect);
if(bar->orient & RTGUI_VERTICAL)
{
/* vertical scroll bar */
erect->x1 = rect.x1;
erect->x2 = rect.x2;
erect->y1 = rect.y1 + rtgui_rect_width(rect) + get_scrollbar_pos(bar);
erect->y2 = erect->y1 + bar->thumb_len;
}
else
{
/* horizontal scroll bar */
erect->x1 = rect.x1 + rtgui_rect_height(rect) + get_scrollbar_pos(bar);
erect->x2 = erect->x1 + bar->thumb_len;
erect->y1 = rect.y1;
erect->y2 = rect.y2;
}
}
static rtgui_point_t sbar_mouse_move_size;
static void _rtgui_scrollbar_on_mouseclick(rtgui_scrollbar_t *bar, rtgui_event_t * event)
{
rtgui_rect_t btn_rect, bar_rect,rect;
rt_uint32_t pos;
struct rtgui_event_mouse *mouse = (struct rtgui_event_mouse*)event;
RT_ASSERT(bar != RT_NULL);
/* get value */
pos = get_scrollbar_pos(bar);
rtgui_widget_get_rect(RTGUI_WIDGET(bar), &rect);
rtgui_widget_rect_to_device(RTGUI_WIDGET(bar),&rect);
if(bar->orient == RTGUI_VERTICAL)
{
/* arrange vertical */
/* get up arrow button rect */
btn_rect.x1 = widget->extent.x1;
btn_rect.x2 = widget->extent.x2;
btn_rect.y1 = widget->extent.y1;
btn_rect.y2 = widget->extent.y1 + (widget->extent.x2 - widget->extent.x1);
btn_rect.x1 = rect.x1;
btn_rect.x2 = rect.x2;
btn_rect.y1 = rect.y1;
btn_rect.y2 = rect.y1 + rtgui_rect_width(rect);
if(rtgui_rect_contains_point(&btn_rect, mouse->x, mouse->y) == RT_EOK)
{
if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
(RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
{
bar->status |= SBS_UPARROW;
if(bar->value==0)
{
rtgui_scrollbar_ondraw(bar);
return;
}
/* line step */
bar->thumb_position -= bar->line_step;
if (bar->thumb_position < bar->min_position) bar->thumb_position = bar->min_position;
bar->value -= bar->line_step;
if(bar->value < 0) bar->value = 0;
}
else if(mouse->button & RTGUI_MOUSE_BUTTON_UP)
{
@ -130,176 +294,370 @@ static void _rtgui_scrollbar_on_mouseclick(struct rtgui_widget * widget, struct
}
goto __exit;
}
/* get bar rect */
bar_rect.x1 = widget->extent.x1;
bar_rect.x2 = widget->extent.x2;
bar_rect.y1 = widget->extent.y1 + (widget->extent.x2 - widget->extent.x1);
bar_rect.y2 = widget->extent.y2 - (widget->extent.x2 - widget->extent.x1);
/* click on the thumb chunk, be going to dragging */
rtgui_scrollbar_get_thumb_rect(bar, &bar_rect);
rtgui_widget_rect_to_device(RTGUI_WIDGET(bar),&bar_rect);
if(rtgui_rect_contains_point(&bar_rect, mouse->x, mouse->y) == RT_EOK)
{
if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
(RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
/* on thumb */
if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
{
/* changed status into drag */
bar->status |= SBS_VERTTHUMB;
sbar_mouse_move_size.x = mouse->x;
sbar_mouse_move_size.y = mouse->y;
}
else if(mouse->button & RTGUI_MOUSE_BUTTON_UP)
{
bar->status = 0;
}
goto __exit;
}
else
{
/* click on space without thumb */
/* get bar rect */
bar_rect.y1 = rect.y1 + rtgui_rect_width(rect);
bar_rect.y2 = rect.y2 - rtgui_rect_width(rect);
if(rtgui_rect_contains_point(&bar_rect, mouse->x, mouse->y) == RT_EOK)
{
if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
{
/* page step */
if (mouse->y < bar_rect.y1 + thumb_position)
if(mouse->y < bar_rect.y1 + pos)
{
bar->thumb_position -= bar->page_step;
if (bar->thumb_position < bar->min_position)
bar->thumb_position = bar->min_position;
bar->status |= SBS_UPSPACE;
bar->value -= bar->page_step;
if(bar->value < 0) bar->value = 0;
}
else if (mouse->y > thumb_position + bar->thumb_size)
else if(mouse->y > pos + bar->thumb_len)
{
bar->thumb_position += bar->page_step;
if (bar->thumb_position > bar->max_position - thumb_size)
bar->thumb_position = bar->max_position - thumb_size;
bar->status |= SBS_DOWNSPACE;
bar->value += bar->page_step;
if(bar->value > bar->count) bar->value = bar->count;
}
}
goto __exit;
}
}
/* likewise foregoing */
/* get down arrow button rect */
btn_rect.y1 = widget->extent.y2 - (widget->extent.x2 - widget->extent.x1);
btn_rect.y2 = widget->extent.y2;
bar_rect.y1 = widget->extent.y1 + ((widget->extent.y2 - widget->extent.y1)/2);
bar_rect.y2 = widget->extent.y2 - (widget->extent.x2 - widget->extent.x1);
bar_rect.x1 = rect.x1;
bar_rect.x2 = rect.x2;
btn_rect.y1 = rect.y2 - rtgui_rect_width(rect);
btn_rect.y2 = rect.y2;
if(rtgui_rect_contains_point(&btn_rect, mouse->x, mouse->y) == RT_EOK)
{
if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
(RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
{
bar->status |= SBS_DOWNARROW;
if(bar->value==bar->count)
{
rtgui_scrollbar_ondraw(bar);
return;
}
/* line step */
bar->thumb_position += bar->line_step;
if (bar->thumb_position > bar->max_position - thumb_size)
bar->thumb_position = bar->max_position - thumb_size;
bar->value += bar->line_step;
if(bar->value > bar->count) bar->value = bar->count;
}
else if(mouse->button & RTGUI_MOUSE_BUTTON_UP)
bar->status = 0;
goto __exit;
}
}
else
{
/* get left arrow button rect */
btn_rect.x1 = widget->extent.x1;
btn_rect.x2 = widget->extent.x1 + (widget->extent.y2 - widget->extent.y1);
btn_rect.y1 = widget->extent.y1;
btn_rect.y2 = widget->extent.y2;
btn_rect.x1 = rect.x1;
btn_rect.x2 = rect.x1 + rtgui_rect_height(rect);
btn_rect.y1 = rect.y1;
btn_rect.y2 = rect.y2;
if(rtgui_rect_contains_point(&btn_rect, mouse->x, mouse->y) == RT_EOK)
{
if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
(RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
{
bar->status |= SBS_LEFTARROW;
if(bar->value==0)
{
rtgui_scrollbar_ondraw(bar);
return;
}
/* line step */
bar->thumb_position -= bar->line_step;
if (bar->thumb_position < bar->min_position) bar->thumb_position = bar->min_position;
bar->value -= bar->line_step;
if(bar->value < 0) bar->value = 0;
}
else if(mouse->button & RTGUI_MOUSE_BUTTON_UP)
bar->status = 0;
goto __exit;
}
/* get bar rect */
bar_rect.x1 = widget->extent.x1 + (widget->extent.y2 - widget->extent.y1);
bar_rect.x2 = widget->extent.x2 - (widget->extent.y2 - widget->extent.y1);
bar_rect.y1 = widget->extent.y1;
bar_rect.y2 = widget->extent.y2;
rtgui_scrollbar_get_thumb_rect(bar, &bar_rect);
rtgui_widget_rect_to_device(RTGUI_WIDGET(bar),&bar_rect);
if(rtgui_rect_contains_point(&bar_rect, mouse->x, mouse->y) == RT_EOK)
{
if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
(RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
/* on the thumb */
if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
{
/* page step */
if (mouse->x < bar_rect.x1 + thumb_position)
{
bar->thumb_position -= bar->page_step;
if (bar->thumb_position < bar->min_position)
bar->thumb_position = bar->min_position;
bar->status |= SBS_HORZTHUMB;
sbar_mouse_move_size.x = mouse->x;
sbar_mouse_move_size.y = mouse->y;
}
else if (mouse->x > thumb_position + bar->thumb_size)
else if(mouse->button & RTGUI_MOUSE_BUTTON_UP)
{
bar->thumb_position += bar->page_step;
if (bar->thumb_position > bar->max_position - thumb_size)
bar->thumb_position = bar->max_position - thumb_size;
}
bar->status = 0;
}
goto __exit;
}
/* get right arrow button rect */
btn_rect.x1 = widget->extent.x2 - (widget->extent.y2 - widget->extent.y1);
btn_rect.x2 = widget->extent.x2;
bar_rect.x1 = widget->extent.x1 + ((widget->extent.x2 - widget->extent.x1)/2);
bar_rect.x2 = widget->extent.x2 - (widget->extent.y2 - widget->extent.y1);
if (rtgui_rect_contains_point(&btn_rect,
mouse->x, mouse->y) == RT_EOK)
else
{
if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
(RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
/* get bar rect */
bar_rect.x1 = rect.x1 + rtgui_rect_height(rect);
bar_rect.x2 = rect.x2 - rtgui_rect_height(rect);
bar_rect.y1 = rect.y1;
bar_rect.y2 = rect.y2;
if(rtgui_rect_contains_point(&bar_rect, mouse->x, mouse->y) == RT_EOK)
{
if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
{
/* page step */
if(mouse->x < bar_rect.x1 + pos)
{
bar->status |= SBS_LEFTSPACE;
bar->value -= bar->page_step;
if(bar->value < 0) bar->value = 0;
}
else if(mouse->x > pos + bar->thumb_len)
{
bar->status |= SBS_RIGHTSPACE;
bar->value += bar->page_step;
if(bar->value > bar->count) bar->value = bar->count;
}
}
else if(mouse->button & RTGUI_MOUSE_BUTTON_UP)
{
bar->status = 0;
}
goto __exit;
}
}
/* get right arrow button rect */
btn_rect.x1 = rect.x2 - rtgui_rect_height(rect);
btn_rect.x2 = rect.x2;
bar_rect.y1 = rect.y1;
bar_rect.y2 = rect.y2;
if(rtgui_rect_contains_point(&btn_rect, mouse->x, mouse->y) == RT_EOK)
{
if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
{
bar->status |= SBS_RIGHTARROW;
if(bar->value==bar->count)
{
rtgui_scrollbar_ondraw(bar);
return;
}
/* line step */
bar->thumb_position += bar->line_step;
if (bar->thumb_position > bar->max_position - bar->line_step)
bar->thumb_position = bar->max_position - bar->line_step;
bar->value += bar->line_step;
if(bar->value > bar->count) bar->value = bar->count;
}
else if(mouse->button & RTGUI_MOUSE_BUTTON_UP)
bar->status = 0;
goto __exit;
}
}
__exit:
rtgui_theme_draw_scrollbar(bar);
if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
(RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
rtgui_scrollbar_ondraw(bar);
if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
{
if (bar->on_scroll != RT_NULL)
bar->on_scroll(RTGUI_OBJECT(widget), RT_NULL);
if(bar->widget_link != RT_NULL && bar->on_scroll != RT_NULL)
{
rtgui_widget_focus(bar->widget_link);
bar->on_scroll(RTGUI_OBJECT(bar->widget_link), event);
}
}
}
rt_bool_t rtgui_scrollbar_event_handler(struct rtgui_object *object,
struct rtgui_event *event)
/* thumb chunk activity */
static void _rtgui_scrollbar_on_mousemotion(rtgui_scrollbar_t *bar, rtgui_event_t * event)
{
struct rtgui_scrollbar* bar;
RTGUI_WIDGET_EVENT_HANDLER_PREPARE
float tmppos;
rt_uint32_t pos;
struct rtgui_event_mouse *mouse = (struct rtgui_event_mouse*)event;
rt_kprintf("sbar mouse motion.\n");
tmppos = _rtgui_scrollbar_get_length(bar);
tmppos /= bar->count;
pos = (rt_uint32_t)tmppos;
bar = RTGUI_SCROLLBAR(object);
if(bar->orient == RTGUI_VERTICAL)
{
if(bar->status & SBS_VERTTHUMB)
{
/* from then on mouseclick */
if((mouse->y-sbar_mouse_move_size.y) > 3)
{
bar->status |= SBS_DOWNTHUMB;
}
else if((mouse->y-sbar_mouse_move_size.y) < -3)
{
bar->status |= SBS_UPTHUMB;
}
else bar->status &= ~(SBS_UPTHUMB|SBS_DOWNTHUMB);
if(abs(mouse->y-sbar_mouse_move_size.y) >= pos)
{
int step = abs(mouse->y-sbar_mouse_move_size.y)/pos;
sbar_mouse_move_size.y = mouse->y;
if(bar->status & SBS_UPTHUMB)
{
bar->value -= step;
if(bar->value < 0) bar->value = 0;
}
else if(bar->status & SBS_DOWNTHUMB)
{
bar->value += step;
if(bar->value > bar->count) bar->value = bar->count;
}
goto __exit;
}
}
else if(bar->status & SBS_UPARROW)
{
/* on-going push down uparrow button */
if(bar->value==0)return;
bar->value -= bar->line_step;
if(bar->value < 0) bar->value = 0;
goto __exit;
}
else if(bar->status & SBS_DOWNARROW)
{
/* on-going push down downarrow button */
if(bar->value==bar->count)return;
bar->value += bar->line_step;
if(bar->value > bar->count) bar->value = bar->count;
goto __exit;
}
/*else if(bar->status & SBS_UPSPACE)
{
bar->value -= bar->page_step;
if(bar->value < 0) bar->value = 0;
goto __exit;
}
else if(bar->status & SBS_DOWNSPACE)
{
bar->value += bar->page_step;
if(bar->value > bar->count) bar->value = bar->count;
goto __exit;
}*/
return;
}
else
{
if(bar->status & SBS_HORZTHUMB)
{rt_kprintf("HORZTHUMB, move event\n");
if((mouse->x-sbar_mouse_move_size.x) > 5)
{
bar->status |= SBS_RIGHTTHUMB;
}
else if((mouse->x-sbar_mouse_move_size.x) < -5)
{
bar->status |= SBS_LEFTTHUMB;
}
if(abs(mouse->x-sbar_mouse_move_size.x) > pos)
{
int step = abs(mouse->x-sbar_mouse_move_size.x)/pos;
sbar_mouse_move_size.x = mouse->x;
if(bar->status & SBS_LEFTTHUMB)
{
bar->value -= step;
if(bar->value < 0) bar->value = 0;
}
else if(bar->status & SBS_RIGHTTHUMB)
{
bar->value += step;
if(bar->value > bar->count) bar->value = bar->count;
}
goto __exit;
}
}
else if(bar->status & SBS_LEFTARROW)
{
if(bar->value==0)return;
bar->value -= bar->line_step;
if(bar->value < 0) bar->value = 0;
goto __exit;
}
else if(bar->status & SBS_RIGHTARROW)
{
if(bar->value==bar->count)return;
bar->value += bar->line_step;
if(bar->value > bar->count) bar->value = bar->count;
goto __exit;
}
/*else if(bar->status & SBS_LEFTSPACE)
{
bar->value -= bar->page_step;
if(bar->value < bar->min) bar->value = bar->min;
goto __exit;
}
else if(bar->status & SBS_RIGHTSPACE)
{
bar->value += bar->page_step;
if(bar->value > bar->count-1) bar->value = bar->count-1;
goto __exit;
}*/
return;
}
__exit:
rtgui_scrollbar_ondraw(bar);
if(bar->widget_link != RT_NULL && bar->on_scroll != RT_NULL)
{
rtgui_widget_focus(bar->widget_link);
bar->on_scroll(RTGUI_OBJECT(bar->widget_link), event);
}
}
rt_bool_t rtgui_scrollbar_event_handler(rtgui_object_t *object, rtgui_event_t *event)
{
rtgui_widget_t *widget = RTGUI_WIDGET(object);
rtgui_scrollbar_t* bar = RTGUI_SCROLLBAR(object);
switch(event->type)
{
case RTGUI_EVENT_PAINT:
#ifndef RTGUI_USING_SMALL_SIZE
if(widget->on_draw != RT_NULL)
widget->on_draw(RTGUI_OBJECT(widget), event);
widget->on_draw(object, event);
else
#endif
{
rtgui_theme_draw_scrollbar(bar);
if(!RTGUI_WIDGET_IS_HIDE(bar))
rtgui_scrollbar_ondraw(bar);
}
break;
case RTGUI_EVENT_MOUSE_BUTTON:
if (RTGUI_WIDGET_IS_ENABLE(widget) && !RTGUI_WIDGET_IS_HIDE(widget))
if(RTGUI_WIDGET_IS_ENABLE(widget))
{
#ifndef RTGUI_USING_SMALL_SIZE
if(widget->on_mouseclick != RT_NULL)
{
widget->on_mouseclick(RTGUI_OBJECT(widget), event);
widget->on_mouseclick(object, event);
}
else
#endif
{
_rtgui_scrollbar_on_mouseclick(widget, event);
_rtgui_scrollbar_on_mouseclick(bar, event);
}
}
break;
case RTGUI_EVENT_MOUSE_MOTION:
if(RTGUI_WIDGET_IS_ENABLE(widget))
{
_rtgui_scrollbar_on_mousemotion(bar, event);
}
default:
return rtgui_widget_event_handler(object, event);
@ -308,76 +666,71 @@ rt_bool_t rtgui_scrollbar_event_handler(struct rtgui_object *object,
return RT_FALSE;
}
struct rtgui_scrollbar* rtgui_scrollbar_create(int orient, rtgui_rect_t* r)
void rtgui_scrollbar_set_orientation(rtgui_scrollbar_t* bar, int orient)
{
struct rtgui_scrollbar* bar;
bar = (struct rtgui_scrollbar*) rtgui_widget_create (RTGUI_SCROLLBAR_TYPE);
if (bar != RT_NULL)
{
if (r != RT_NULL)
{
rtgui_widget_set_rect(RTGUI_WIDGET(bar), r);
if (orient == RTGUI_VERTICAL)
bar->thumb_size = (r->x2 - r->x1);
else
bar->thumb_size = (r->y2 - r->y1);
}
RT_ASSERT(bar != RT_NULL);
bar->orient = orient;
}
return bar;
}
void rtgui_scrollbar_destroy(struct rtgui_scrollbar* bar)
/* get active area length */
rt_uint32_t get_sbar_active_len(rtgui_scrollbar_t *bar)
{
rtgui_widget_destroy(RTGUI_WIDGET(bar));
}
rtgui_rect_t rect;
void rtgui_scrollbar_set_orientation(rtgui_scrollbar_t* bar, int orientation)
{
RT_ASSERT(bar != RT_NULL);
rtgui_widget_get_rect(RTGUI_WIDGET(bar), &rect);
bar->orient = orientation;
#ifndef RTGUI_USING_SMALL_SIZE
if (bar->orient == RTGUI_HORIZONTAL)
{
/* horizontal */
rtgui_widget_set_miniwidth(RTGUI_WIDGET(bar), RTGUI_DEFAULT_SB_WIDTH);
rtgui_widget_set_miniheight(RTGUI_WIDGET(bar), RTGUI_DEFAULT_SB_HEIGHT);
}
if(bar->orient & RTGUI_VERTICAL)
return rtgui_rect_height(rect) - 2*rtgui_rect_width(rect);
else
{
/* vertical */
rtgui_widget_set_miniwidth(RTGUI_WIDGET(bar), RTGUI_DEFAULT_SB_HEIGHT);
rtgui_widget_set_miniheight(RTGUI_WIDGET(bar), RTGUI_DEFAULT_SB_WIDTH);
}
#endif
return rtgui_rect_width(rect) - 2*rtgui_rect_height(rect);
}
void rtgui_scrollbar_set_range(struct rtgui_scrollbar* bar, int min, int max)
void rtgui_scrollbar_set_thumbbar_len(rtgui_scrollbar_t* bar)
{
double size=0;
rt_uint32_t len,w;
RT_ASSERT(bar != RT_NULL);
/* Make sure called rtgui_scrollbar_set_range(),before you use under code. */
size = bar->page_step;
size /= bar->count+bar->page_step;
size *= get_sbar_active_len(bar);
len = (rt_uint32_t)size ;
w = bar->thumb_w;
if(len < w/2) len = w/2;
bar->thumb_len = len;
}
/*
* please use them with below step:
* 1.SetLineStep();2.SetPageStep();3.SetRange();
*/
void rtgui_scrollbar_set_line_step(rtgui_scrollbar_t* bar, int step)
{
RT_ASSERT(bar != RT_NULL);
if (min >= max )
{
RTGUI_WIDGET_DISABLE(bar);
return;
bar->line_step = step;
}
bar->min_position = (rt_int16_t)min;
bar->max_position = (rt_int16_t)max;
}
void rtgui_scrollbar_set_page_step(struct rtgui_scrollbar* bar, int step)
void rtgui_scrollbar_set_page_step(rtgui_scrollbar_t* bar, int step)
{
RT_ASSERT(bar != RT_NULL);
bar->page_step = step;
}
void rtgui_scrollbar_set_range(rtgui_scrollbar_t* bar, int count)
{
RT_ASSERT(bar != RT_NULL);
/* disable or enable scrollbar */
if (bar->page_step > (bar->max_position - bar->min_position))
if(bar->page_step >= count)
{
/* disable bar */
RTGUI_WIDGET_DISABLE(bar);
@ -387,34 +740,51 @@ void rtgui_scrollbar_set_page_step(struct rtgui_scrollbar* bar, int step)
/* enable bar */
RTGUI_WIDGET_ENABLE(bar);
}
/* thumb step count = item_count-item_per_page */
bar->count = (rt_int16_t)(count-bar->page_step);
rtgui_scrollbar_set_thumbbar_len(bar);
}
void rtgui_scrollbar_set_line_step(struct rtgui_scrollbar* bar, int step)
/* use VALUE change be binding widget's frist item. */
void rtgui_scrollbar_set_value(rtgui_scrollbar_t* bar, rt_int16_t value)
{
RT_ASSERT(bar != RT_NULL);
bar->line_step = step;
}
bar->value = value;
rt_int16_t rtgui_scrollbar_get_value(struct rtgui_scrollbar* bar)
{
RT_ASSERT(bar != RT_NULL);
if(bar->value < 0) bar->value = 0;
return bar->thumb_position;
}
void rtgui_scrollbar_set_value(struct rtgui_scrollbar* bar, rt_int16_t position)
{
RT_ASSERT(bar != RT_NULL);
bar->thumb_position = position;
rtgui_widget_update(RTGUI_WIDGET(bar));
}
void rtgui_scrollbar_set_onscroll(struct rtgui_scrollbar* bar,
rtgui_event_handler_ptr handler)
void rtgui_scrollbar_set_onscroll(rtgui_scrollbar_t* bar, rtgui_event_handler_ptr handler)
{
if(bar == RT_NULL || handler == RT_NULL) return;
bar->on_scroll = handler;
}
void rtgui_scrollbar_hide(rtgui_scrollbar_t* bar)
{
rtgui_rect_t rect;
struct rtgui_dc* dc;
RT_ASSERT(bar != RT_NULL);
/* begin drawing */
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(bar));
if(dc == RT_NULL)return;
RTGUI_WIDGET_HIDE(bar);
/* begin drawing */
rtgui_widget_get_rect(RTGUI_WIDGET(bar), &rect);
if((RTGUI_WIDGET(bar))->parent != RT_NULL)
RTGUI_DC_BC(dc) = RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(bar)->parent);
else
RTGUI_DC_BC(dc) = RTGUI_RGB(225, 228, 220);
rtgui_dc_fill_rect(dc,&rect);
rtgui_dc_end_drawing(dc);
}

View File

@ -51,11 +51,13 @@ static void _rtgui_textbox_constructor(rtgui_textbox_t *box)
box->flag = RTGUI_TEXTBOX_SINGLE;
/* allocate default line buffer */
box->text = RT_NULL;
rtgui_textbox_set_mask_char(box, '*');
rtgui_font_get_metrics(RTGUI_WIDGET_FONT(box), "H", &rect);
box->font_width = rtgui_rect_width(rect);
box->on_enter = RT_NULL;
box->dis_length = 0;
box->first_pos = 0;
}
static void _rtgui_textbox_deconstructor(rtgui_textbox_t *textbox)
@ -201,9 +203,9 @@ static void rtgui_textbox_onmouse(rtgui_textbox_t* box, struct rtgui_event_mouse
{
box->position = 0;
}
else if(x > length * box->font_width)
else if (x > (length - box->first_pos) * box->font_width)
{
box->position = length;
box->position = length - box->first_pos;
}
else
{
@ -256,28 +258,44 @@ static rt_bool_t rtgui_textbox_onkey(struct rtgui_object* widget, rtgui_event_t*
length = rt_strlen(box->text);
if (ekbd->key == RTGUIK_DELETE)
{/* delete latter character */
if(box->position == length - 1)
{
box->text[box->position] = '\0';
/* delete latter character */
if (box->first_pos + box->position == length - 1)
{
box->text[box->first_pos + box->position] = '\0';
}
else
{
char *c;
/* remove character */
for(c = &box->text[box->position]; c[1] != '\0'; c++)
for (c = &box->text[box->first_pos + box->position]; c[1] != '\0'; c++)
*c = c[1];
*c = '\0';
}
}
else if (ekbd->key == RTGUIK_BACKSPACE)
{/* delete front character */
if(box->position == 0)
return RT_FALSE;
else if(box->position == length)
{
box->text[box->position-1] = '\0';
/* delete front character */
if (box->position == 0)
{
if(box->first_pos > 0)
{
if(box->first_pos > box->dis_length)
{
box->first_pos -= box->dis_length;
box->position = box->dis_length;
}
else
{
box->position = box->first_pos;
box->first_pos = 0;
}
}
}
else if (box->position == length-box->first_pos)
{
box->text[box->first_pos + box->position - 1] = '\0';
box->position --;
}
else if (box->position != 0)
@ -296,26 +314,48 @@ static rt_bool_t rtgui_textbox_onkey(struct rtgui_object* widget, rtgui_event_t*
}
}
else if (ekbd->key == RTGUIK_LEFT)
{/* move to prev */
{
/* move to prev */
if (box->position > 0)
{
box->position --;
}
else
{
if(box->first_pos > 0)
box->first_pos -= 1;//DEBUG
}
}
else if (ekbd->key == RTGUIK_RIGHT)
{/* move to next */
if(box->position < length)
{
/* move to next */
if (box->first_pos + box->position < length)
{
if(box->position < box->dis_length)
box->position ++;
else
box->first_pos += 1;//DEBUG
}
}
else if (ekbd->key == RTGUIK_HOME)
{/* move cursor to start */
{
/* move cursor to start */
box->position = 0;
box->first_pos = 0;
}
else if (ekbd->key == RTGUIK_END)
{/* move cursor to end */
{
/* move cursor to end */
if(length > box->dis_length)
{
box->position = box->dis_length;
box->first_pos = length - box->dis_length;
}
else
{
box->position = length;
box->first_pos = 0;
}
}
else if (ekbd->key == RTGUIK_RETURN)
{
@ -335,19 +375,21 @@ static rt_bool_t rtgui_textbox_onkey(struct rtgui_object* widget, rtgui_event_t*
else
{
if (isprint(ekbd->key))
{/* it's may print character */
{
/* it's may print character */
/* no buffer on this line */
if (box->flag & RTGUI_TEXTBOX_DIGIT)
{/* only input digit */
{
/* only input digit */
if (!isdigit(ekbd->key))
{/* exception: '.' and '-' */
{
/* exception: '.' and '-' */
if (ekbd->key != '.' && ekbd->key != '-')return RT_FALSE;
if (ekbd->key == '.' && strchr(box->text, '.'))return RT_FALSE;
if (ekbd->key == '-')
{
if (length + 1 > box->line_length) return RT_FALSE;
if(length+1 > box->dis_length) return RT_FALSE;
if (strchr(box->text, '-'))
{
@ -372,19 +414,21 @@ static rt_bool_t rtgui_textbox_onkey(struct rtgui_object* widget, rtgui_event_t*
}
}
if (length + 1 > box->line_length) return RT_FALSE;
if(length+1 > box->dis_length) return RT_FALSE;
if(box->position <= length-1)
if (box->first_pos + box->position <= length - 1)
{
char *c;
for(c = &box->text[length]; c != &box->text[box->position]; c--)
for (c = &box->text[length]; c != &box->text[box->first_pos + box->position]; c--)
*c = *(c - 1);
box->text[length + 1] = '\0';
}
box->text[box->position] = ekbd->key;
box->text[box->first_pos + box->position] = ekbd->key;
if(box->position < box->dis_length)
box->position ++;
else
box->first_pos ++;
}
}
@ -506,20 +550,20 @@ void rtgui_textbox_ondraw(rtgui_textbox_t* box)
/* draw single text */
if (box->flag & RTGUI_TEXTBOX_MASK)
{
/* draw '*' */
/* draw mask char */
rt_size_t len = rt_strlen(box->text);
if (len > 0)
{
char *text_mask = rtgui_malloc(len + 1);
rt_memset(text_mask, '*', len + 1);
rt_memset(text_mask, box->mask_char, len + 1);
text_mask[len] = 0;
rtgui_dc_draw_text(dc, text_mask, &rect);
rtgui_dc_draw_text(dc, text_mask+box->first_pos, &rect);
rtgui_free(text_mask);
}
}
else
{
rtgui_dc_draw_text(dc, box->text, &rect);
rtgui_dc_draw_text(dc, box->text+box->first_pos, &rect);
}
}
@ -530,7 +574,8 @@ void rtgui_textbox_ondraw(rtgui_textbox_t* box)
void rtgui_textbox_set_value(rtgui_textbox_t *box, const char *text)
{
if (box->text != RT_NULL)
{/* yet exist something */
{
/* yet exist something */
/* free the old text */
rtgui_free(box->text);
box->text = RT_NULL;
@ -540,8 +585,8 @@ void rtgui_textbox_set_value(rtgui_textbox_t* box, const char* text)
box->line_length = ((rt_strlen(text) + 1) / RTGUI_TEXTBOX_LINE_MAX + 1) * RTGUI_TEXTBOX_LINE_MAX;
/* allocate line buffer */
box->text = rtgui_malloc(box->line_length);
rt_memset(box->text, 0, box->line_length);
box->text = rtgui_malloc(box->line_length+1);
rt_memset(box->text, 0, box->line_length+1);
/* copy text */
rt_memcpy(box->text, text, rt_strlen(text) + 1);
@ -555,6 +600,16 @@ const char* rtgui_textbox_get_value(rtgui_textbox_t* box)
return (const char *)box->text;
}
void rtgui_textbox_set_mask_char(rtgui_textbox_t *box, const char ch)
{
box->mask_char = ch;
}
const 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_uint8_t *new_line;

View File

@ -41,7 +41,8 @@ static void _calc_line(rtgui_textview_t *textview, const char* text)
}
/* get line count */
line_index = 0; line_position = 0;
line_index = 0;
line_position = 0;
ptr = (const unsigned char *)text;
if (*ptr == 0) return;
@ -104,7 +105,8 @@ static void _calc_line(rtgui_textview_t *textview, const char* text)
rt_memset(textview->lines, 0, (textview->line_count * textview->line_width));
/* fill lines */
line_index = 0; line_position = 0;
line_index = 0;
line_position = 0;
ptr = (const unsigned char *)text;
line = _get_line_text(textview, line_index);
while (*ptr)

View File

@ -129,6 +129,11 @@ void rtgui_widget_set_rect(rtgui_widget_t* widget, const rtgui_rect_t* rect)
/* update extent rectangle */
widget->extent = *rect;
if (RTGUI_IS_CONTAINER(widget))
{
/* re-do layout */
rtgui_container_layout(RTGUI_CONTAINER(widget));
}
/* reset mini width and height */
widget->mini_width = rtgui_rect_width(widget->extent);
@ -154,8 +159,10 @@ void rtgui_widget_set_rectangle(rtgui_widget_t* widget, int x, int y, int width,
{
rtgui_rect_t rect;
rect.x1 = x; rect.y1 = y;
rect.x2 = x + width; rect.y2 = y + height;
rect.x1 = x;
rect.y1 = y;
rect.x2 = x + width;
rect.y2 = y + height;
rtgui_widget_set_rect(widget, &rect);
}
@ -517,9 +524,11 @@ rt_bool_t rtgui_widget_event_handler(struct rtgui_object* object, rtgui_event_t*
return widget->on_size(RTGUI_OBJECT(widget), event);
break;
#endif
default:
return rtgui_object_event_handler(object, event);
}
return rtgui_object_event_handler(object, event);
return RT_FALSE;
}
RTM_EXPORT(rtgui_widget_event_handler);
@ -556,7 +565,7 @@ void rtgui_widget_update_clip(rtgui_widget_t* widget)
if (parent != RT_NULL)
{
/* subtract widget clip in parent clip */
if (!(widget->flag & RTGUI_WIDGET_FLAG_TRANSPARENT))
if (!(widget->flag & RTGUI_WIDGET_FLAG_TRANSPARENT) && RTGUI_IS_CONTAINER(parent))
{
rtgui_region_subtract_rect(&(parent->clip), &(parent->clip),
&(widget->extent));
@ -736,7 +745,8 @@ rtgui_widget_t* rtgui_widget_get_prev_sibling(rtgui_widget_t* widget)
struct rtgui_list_node *node;
rtgui_widget_t *sibling, *parent;
node = RT_NULL; sibling = RT_NULL;
node = RT_NULL;
sibling = RT_NULL;
parent = widget->parent;
if (parent != RT_NULL)
{

View File

@ -34,6 +34,7 @@ static void _rtgui_win_constructor(rtgui_win_t *win)
RTGUI_WIDGET(win)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
win->parent_window = RT_NULL;
win->app = rtgui_app_self();
/* init window attribute */
win->on_activate = RT_NULL;
win->on_deactivate = RT_NULL;
@ -249,7 +250,7 @@ rt_base_t rtgui_win_show(struct rtgui_win* win, rt_bool_t is_modal)
struct rtgui_app *app;
struct rtgui_event_win_show eshow;
app = rtgui_app_self();
app = win->app;
RTGUI_EVENT_WIN_SHOW_INIT(&eshow);
eshow.wid = win;
@ -289,7 +290,7 @@ rt_base_t rtgui_win_show(struct rtgui_win* win, rt_bool_t is_modal)
RTGUI_EVENT_WIN_MODAL_ENTER_INIT(&emodal);
emodal.wid = win;
app = rtgui_app_self();
app = win->app;
RT_ASSERT(app != RT_NULL);
win->flag |= RTGUI_WIN_FLAG_MODAL;
@ -320,7 +321,7 @@ void rtgui_win_end_modal(struct rtgui_win* win, rtgui_modal_code_t modal_code)
if (win == RT_NULL || !(win->flag & RTGUI_WIN_FLAG_MODAL))
return;
rtgui_app_exit(rtgui_app_self(), modal_code);
rtgui_app_exit(win->app, modal_code);
/* remove modal mode */
win->flag &= ~RTGUI_WIN_FLAG_MODAL;

View File

@ -1,4 +1,5 @@
from building import *
import os
'''
demo_view_dc_buffer.c
@ -44,7 +45,14 @@ demo_plot.c
mywidget.c
""")
if GetDepend('RTGUI_USING_FONT_COMPACT'):
import stract_cjk as sf
fl1 = sf.get_font_lib('hz16')
fl2 = sf.get_font_lib('hz12')
cwd = GetCurrentDir()
for i in src:
fl1.push_file(open(os.path.join(cwd, i), 'r'))
fl2.push_file(open(os.path.join(cwd, i), 'r'))
group = DefineGroup('gui_examples', src, depend = ['RT_USING_RTGUI'])

View File

@ -1,5 +1,5 @@
#include <rtgui/widgets/plot.h>
#include <rtgui/widgets/plot_curve.h>
#include "demo_view.h"
@ -34,30 +34,39 @@ struct rtgui_container* demo_plot(void)
cnt = demo_view("ÇúĎßťćÍź");
curve1 = rtgui_plot_curve_create();
curve1->y_data = sin_ydata;
curve1->length = sizeof(sin_ydata)/sizeof(sin_ydata[0]);
curve1->color = red;
plot = rtgui_plot_create();
plot = rtgui_plot_create(curve1);
curve1 = rtgui_plot_curve_create();
rtgui_plot_curve_set_y(curve1, sin_ydata);
RTGUI_MV_MODEL(curve1)->length = sizeof(sin_ydata)/sizeof(sin_ydata[0]);
curve1->min_x = 0;
curve1->max_x = sizeof(sin_ydata)/sizeof(sin_ydata[0]);
curve1->min_y = -100;
curve1->min_y = 100;
curve1->color = red;
rtgui_mv_model_add_view(RTGUI_MV_MODEL(curve1), RTGUI_MV_VIEW(plot));
curve2 = rtgui_plot_curve_create();
curve2->y_data = cos_ydata;
curve2->length = sizeof(cos_ydata)/sizeof(cos_ydata[0]);
rtgui_plot_curve_set_y(curve2, cos_ydata);
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->color = blue;
rtgui_plot_append_curve(plot, curve2);
rtgui_mv_model_add_view(RTGUI_MV_MODEL(curve2), RTGUI_MV_VIEW(plot));
curve3 = rtgui_plot_curve_create();
curve3->x_data = cos_ydata;
curve3->y_data = sin_ydata;
curve3->length = sizeof(sin_ydata)/sizeof(sin_ydata[0]);
rtgui_plot_curve_set_x(curve3, cos_ydata);
rtgui_plot_curve_set_y(curve3, sin_ydata);
RTGUI_MV_MODEL(curve3)->length = sizeof(sin_ydata)/sizeof(sin_ydata[0]);
curve3->color = black;
rtgui_plot_append_curve(plot, curve3);
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_point(plot,
rtgui_rect_width(rect)/3, rtgui_rect_height(rect)/2);
rtgui_plot_set_base(plot,
-rtgui_rect_width(rect)/3, rtgui_rect_height(rect)/2);
rtgui_container_add_child(cnt, RTGUI_WIDGET(plot));

View File

@ -6,6 +6,7 @@
#include "demo_view.h"
#define RAND(x1, x2) ((rand() % (x2 - x1)) + x1)
#define _int_swap(x, y) do {x ^= y; y ^= x; x ^= y; } while(0)
static struct rtgui_container *container = RT_NULL;
static int running = 0;
@ -34,8 +35,12 @@ void _onidle(struct rtgui_object *object, rtgui_event_t *event)
demo_view_get_logic_rect(RTGUI_CONTAINER(container), &rect);
draw_rect.x1 = RAND(rect.x1, rect.x2);
draw_rect.y1 = RAND(rect.y1, rect.y2);
draw_rect.x2 = RAND(draw_rect.x1, rect.x2);
draw_rect.y2 = RAND(draw_rect.y1, rect.y2);
draw_rect.x2 = RAND(rect.x1, rect.x2);
draw_rect.y2 = RAND(rect.y1, rect.y2);
if(draw_rect.x1 > draw_rect.x2) _int_swap(draw_rect.x1, draw_rect.x2);
if(draw_rect.y1 > draw_rect.y2) _int_swap(draw_rect.y1, draw_rect.y2);
area += rtgui_rect_width(draw_rect) * rtgui_rect_height(draw_rect);
color = RTGUI_RGB(rand() % 255, rand() % 255, rand() % 255);
RTGUI_WIDGET_BACKGROUND(container) = color;

View File

@ -16,35 +16,33 @@ rtgui_container_t *demo_view_scrollbar(void)
/* get demo container rect */
demo_view_get_rect(container, &rect);
label = rtgui_label_create("horizontal bar:");
rtgui_container_add_child(container, RTGUI_WIDGET(label));
rect.x1 += 5;
rect.x2 -= 5;
rect.y1 += 5;
rect.y2 = rect.y1 + 18;
rect.y2 = rect.y1 + 20;
label = rtgui_label_create("horizontal bar:");
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
rect.y1 += 20;
rect.y2 = rect.y1 + 18;
hbar = rtgui_scrollbar_create(RTGUI_HORIZONTAL, &rect);
rtgui_container_add_child(container, RTGUI_WIDGET(hbar));
rtgui_container_add_child(container, RTGUI_WIDGET(label));
hbar = rtgui_scrollbar_create(container, 5, 70, 20, 200, RTGUI_HORIZONTAL);
rtgui_scrollbar_set_line_step(hbar, 1);
rtgui_scrollbar_set_page_step(hbar, 3);
rtgui_scrollbar_set_range(hbar, 20);
/* get demo container rect */
demo_view_get_rect(container, &rect);
label = rtgui_label_create("vertical bar:");
rtgui_container_add_child(container, RTGUI_WIDGET(label));
rect.x1 += 5;
rect.x2 -= 5;
rect.y1 += 45;
rect.y2 = rect.y1 + 18;
rect.y1 += 5+40;
rect.y2 = rect.y1 + 20;
label = rtgui_label_create("vertical bar:");
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
rect.x1 += 110;
rect.x2 = rect.x1 + 20;
rect.y1 += 18 + 5;
rect.y2 = rect.y1 + 150;
vbar = rtgui_scrollbar_create(RTGUI_VERTICAL, &rect);
rtgui_container_add_child(container, RTGUI_WIDGET(vbar));
rtgui_container_add_child(container, RTGUI_WIDGET(label));
vbar = rtgui_scrollbar_create(container, 10, 110, 20, 200, RTGUI_VERTICAL);
rtgui_scrollbar_set_line_step(vbar, 1);
// RTGUI_WIDGET_DISABLE(vbar);
rtgui_scrollbar_set_page_step(vbar, 5);
rtgui_scrollbar_set_range(vbar, 20);
return container;
}

View File

@ -1,94 +1,73 @@
#include <rtgui/dc.h>
#include "mywidget.h"
/* 控件绘图函数 */
static void rtgui_mywidget_ondraw(struct rtgui_mywidget *me)
{
struct rtgui_dc *dc;
struct rtgui_rect rect;
rt_uint16_t x, y;
/* èŽ·å¾—ç®æ ‡DC,开å§ç»˜å?*/
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(me));
if (dc == RT_NULL) return;
/* 获得窗å<E28094>£çš„å°ºå¯?*/
rtgui_widget_get_rect(RTGUI_WIDGET(me), &rect);
/* 绘制背景�*/
RTGUI_DC_BC(dc) = white;
rtgui_dc_fill_rect(dc, &rect);
/* 计算中心原点 */
x = (rect.x2 + rect.x1) / 2;
y = (rect.y2 + rect.y1) / 2;
/* 绘制å<C2B6><C3A5>å­—æž?*/
RTGUI_DC_FC(dc) = black;
rtgui_dc_draw_hline(dc, rect.x1, rect.x2, y);
rtgui_dc_draw_vline(dc, x, rect.y1, rect.y2);
/* æ ¹æ<C2B9>®çжæ€<C3A6>绘制圆åœ?*/
if (me->status == MYWIDGET_STATUS_ON)
RTGUI_DC_FC(dc) = green;
else
RTGUI_DC_FC(dc) = red;
rtgui_dc_fill_circle(dc, x, y, 5);
/* 结æ<E2809C>Ÿç»˜å¾ */
rtgui_dc_end_drawing(dc);
return;
}
/* é¼ æ ‡äºä»¶å¤„ç<E2809E>†å‡½æ•° */
static void rtgui_mywidget_onmouse(struct rtgui_mywidget *me, struct rtgui_event_mouse *mouse)
{
struct rtgui_rect rect;
rt_uint16_t x, y;
/* 仅对鼠标抬起动作è¿è¡Œå¤„ç<E2809E>† */
if (!(mouse->button & RTGUI_MOUSE_BUTTON_UP)) return;
/* 获得控件的ä½<C3A4>ç½?*/
rtgui_widget_get_rect(RTGUI_WIDGET(me), &rect);
/* get_rect函数获得是控件的ç¸å¯¹ä½<C3A4>置,而鼠标äºä»¶ç»™å‡ºçš„å<E2809E><C3A5>标是ç»<C3A7>对å<C2B9><C3A5>标,需è¦<C3A8>å<EFBFBD>šä¸€ä¸ªè½¬æ<C2AC>?*/
rtgui_widget_rect_to_device(RTGUI_WIDGET(me), &rect);
/* 计算中心原点 */
x = (rect.x2 + rect.x1) / 2;
y = (rect.y2 + rect.y1) / 2;
/* 比较鼠标å<E280A1><C3A5>标是å<C2AF>¦åœ¨åœˆå†?*/
if ((mouse->x < x + 5 && mouse->x > x - 5) &&
(mouse->y < y + 5 && mouse->y > y - 5))
{
/* 更改控件状�*/
if (me->status & MYWIDGET_STATUS_ON) me->status = MYWIDGET_STATUS_OFF;
else me->status = MYWIDGET_STATUS_ON;
/* 刷新(é‡<C3A9>æ°ç»˜åˆ¶)控件 */
rtgui_mywidget_ondraw(me);
}
}
/* mywidget控件的äºä»¶å¤„ç<E2809E>†å‡½æ•?*/
rt_bool_t rtgui_mywidget_event_handler(struct rtgui_object *object, struct rtgui_event *event)
{
/* 调用äºä»¶å¤„ç<E2809E>†å‡½æ•°æ—¶ï¼ŒwidgetæŒ‡éˆæŒ‡å<E280A1>控件本身,所以先获得ç¸åº”控件对象的指é?*/
struct rtgui_mywidget *me = RTGUI_MYWIDGET(object);
switch (event->type)
{
case RTGUI_EVENT_PAINT:
/* 绘制事件,调用绘图函数绘�*/
rtgui_mywidget_ondraw(me);
break;
case RTGUI_EVENT_MOUSE_BUTTON:
/* 鼠标事件 */
rtgui_mywidget_onmouse(RTGUI_MYWIDGET(me), (struct rtgui_event_mouse *) event);
break;
/* å…¶ä»äºä»¶è°ƒç”¨çˆ¶ç±»çš„äºä»¶å¤„ç<E2809E>†å‡½æ•?*/
default:
return rtgui_widget_event_handler(object, event);
}
@ -96,15 +75,11 @@ rt_bool_t rtgui_mywidget_event_handler(struct rtgui_object *object, struct rtgui
return RT_FALSE;
}
/* 自定义控件的构造函�*/
static void _rtgui_mywidget_constructor(rtgui_mywidget_t *mywidget)
{
/* 默认这个控件接收è<C2B6>šç„¦ */
RTGUI_WIDGET(mywidget)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
/* åˆ<C3A5>å§åŒæŽ§ä»¶å¹¶è®¾ç½®äºä»¶å¤„ç<E2809E>†å‡½æ•° */
rtgui_object_set_event_handler(RTGUI_OBJECT(mywidget), rtgui_mywidget_event_handler);
/* åˆ<C3A5>å§çжæ€<C3A6>æ—¶OFF */
mywidget->status = MYWIDGET_STATUS_OFF;
}
@ -114,12 +89,10 @@ DEFINE_CLASS_TYPE(mywidget, "mywidget",
RT_NULL,
sizeof(struct rtgui_mywidget));
/* 创建一个自定义控件 */
struct rtgui_mywidget *rtgui_mywidget_create(rtgui_rect_t *r)
{
struct rtgui_mywidget *me;
/* 让rtgui_widgetåˆå»ºå‡ºä¸€ä¸ªæŒ‡å®šç±»åžï¼šRTGUI_MYWIDGET_TYPEç±»åžçš„æŽ§ä»?*/
me = (struct rtgui_mywidget *) rtgui_widget_create(RTGUI_MYWIDGET_TYPE);
if (me != RT_NULL)
{
@ -129,7 +102,6 @@ struct rtgui_mywidget *rtgui_mywidget_create(rtgui_rect_t *r)
return me;
}
/* 删除一个自定义控件 */
void rtgui_mywidget_destroy(struct rtgui_mywidget *me)
{
rtgui_widget_destroy(RTGUI_WIDGET(me));