sync with github bd3351e572

As always, full log is in GitHub.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2234 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
dzzxzz@gmail.com 2012-07-26 06:36:49 +00:00
parent f7fbd6bc6d
commit 08e05eb3b4
11 changed files with 599 additions and 578 deletions

View File

@ -1,4 +1,4 @@
Import('RTT_ROOT') import os
from building import * from building import *
common_src = Split(""" common_src = Split("""
@ -72,10 +72,10 @@ widgets/panel.c
# The set of source files associated with this SConscript file. # The set of source files associated with this SConscript file.
src = common_src + server_src + widgets_src src = common_src + server_src + widgets_src
path = [RTT_ROOT + '/components/rtgui/include', cwd = GetCurrentDir()
RTT_ROOT + '/components/rtgui/common', dirs = ['include', 'common', 'server', 'widgets']
RTT_ROOT + '/components/rtgui/server', path = [os.path.join(cwd, i) for i in dirs]
RTT_ROOT + '/components/rtgui/widgets']
group = DefineGroup('RTGUI', src, depend = ['RT_USING_RTGUI'], CPPPATH = path) group = DefineGroup('RTGUI', src, depend = ['RT_USING_RTGUI'], CPPPATH = path)
Return('group') Return('group')

View File

@ -251,21 +251,7 @@ static int mem_read(struct rtgui_filerw *context, void *ptr, rt_size_t size, rt_
static int mem_write(struct rtgui_filerw *context, const void *ptr, rt_size_t size, rt_size_t num) static int mem_write(struct rtgui_filerw *context, const void *ptr, rt_size_t size, rt_size_t num)
{ {
#if 0
struct rtgui_filerw_mem* mem = (struct rtgui_filerw_mem*)context;
if ((mem->mem_position + (num * size)) > mem->mem_end)
{
num = (mem->mem_end - mem->mem_position)/size;
}
rt_memcpy(mem->mem_position, ptr, num*size);
mem->mem_position += num*size;
return num;
#else
return 0; /* not support memory write */ return 0; /* not support memory write */
#endif
} }
static int mem_tell(struct rtgui_filerw* context) static int mem_tell(struct rtgui_filerw* context)

View File

@ -82,7 +82,7 @@ static struct rtgui_image_engine* rtgui_image_get_engine(const char* type)
} }
#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW) #if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
static struct rtgui_image_engine* rtgui_image_get_engine_by_filename(const char* fn) struct rtgui_image_engine* rtgui_image_get_engine_by_filename(const char* fn)
{ {
struct rtgui_list_node *node; struct rtgui_list_node *node;
struct rtgui_image_engine *engine; struct rtgui_image_engine *engine;

View File

@ -36,15 +36,12 @@ struct rtgui_image_bmp
struct rtgui_filerw *filerw; struct rtgui_filerw *filerw;
rt_uint32_t w, h; rt_uint32_t w, h;
rt_uint32_t pixel_offset; rt_uint32_t pixel_offset;
rt_uint32_t pitch; rt_uint8_t scale; rt_uint32_t pitch;
rt_uint8_t scale;
rt_uint8_t bit_per_pixel; rt_uint8_t bit_per_pixel;
rt_uint8_t pad; rt_uint8_t pad;
}; };
/* static rt_bool_t rtgui_image_bmp_check(struct rtgui_filerw* file,
rt_uint32_t *width, rt_uint32_t *height);
static rt_bool_t rtgui_image_bmp_load(struct rtgui_image* image,
struct rtgui_filerw* file, rt_uint8_t scale, rt_bool_t load); */
static rt_bool_t rtgui_image_bmp_check(struct rtgui_filerw *file); static rt_bool_t rtgui_image_bmp_check(struct rtgui_filerw *file);
static rt_bool_t rtgui_image_bmp_load(struct rtgui_image *image, struct rtgui_filerw *file, rt_bool_t load); static rt_bool_t rtgui_image_bmp_load(struct rtgui_image *image, struct rtgui_filerw *file, rt_bool_t load);
static void rtgui_image_bmp_unload(struct rtgui_image *image); static void rtgui_image_bmp_unload(struct rtgui_image *image);
@ -62,8 +59,6 @@ struct rtgui_image_engine rtgui_image_bmp_engine =
}; };
static rt_bool_t rtgui_image_bmp_check(struct rtgui_filerw *file) static rt_bool_t rtgui_image_bmp_check(struct rtgui_filerw *file)
//static rt_bool_t rtgui_image_bmp_check(struct rtgui_filerw* file,
// rt_uint32_t *width, rt_uint32_t *height)
{ {
rt_uint8_t buffer[18]; rt_uint8_t buffer[18];
rt_bool_t is_bmp = RT_FALSE; rt_bool_t is_bmp = RT_FALSE;
@ -92,28 +87,27 @@ static rt_bool_t rtgui_image_bmp_check(struct rtgui_filerw* file)
/* Read BMP header size */ /* Read BMP header size */
if (*(rt_uint32_t *)&buffer[14] == 12) if (*(rt_uint32_t *)&buffer[14] == 12)
{ /* Bitmap Header Version 2.x */ {
/* Bitmap Header Version 2.x */
if (rtgui_filerw_read(file, (void *)buffer, 8, 1) != 8) if (rtgui_filerw_read(file, (void *)buffer, 8, 1) != 8)
{ {
break; break;
} }
/* Read image size */ /* Read image size */
// *width = (rt_uint32_t)*(rt_uint16_t *)&buffer[0];
// *height = (rt_uint32_t)*(rt_uint16_t *)&buffer[2];
is_bmp = RT_TRUE; is_bmp = RT_TRUE;
} }
else else
{ /* Bitmap Header Version bigger than 2.x */ {
/* Bitmap Header Version bigger than 2.x */
if (rtgui_filerw_read(file, (void *)buffer, 8, 1) != 8) if (rtgui_filerw_read(file, (void *)buffer, 8, 1) != 8)
{ {
break; break;
} }
/* Read image size */ /* Read image size */
// *width = *(rt_uint32_t *)&buffer[0];
// *height = *(rt_uint32_t *)&buffer[4];
is_bmp = RT_TRUE; is_bmp = RT_TRUE;
} }
} while(0); }
while (0);
return is_bmp; return is_bmp;
} }
@ -164,10 +158,8 @@ static struct rtgui_image_palette* rtgui_image_bmp_load_palette(
} }
static rt_bool_t rtgui_image_bmp_load(struct rtgui_image *image, struct rtgui_filerw *file, rt_bool_t load) static rt_bool_t rtgui_image_bmp_load(struct rtgui_image *image, struct rtgui_filerw *file, rt_bool_t load)
//static rt_bool_t rtgui_image_bmp_load(struct rtgui_image* image,
// struct rtgui_filerw* file, rt_uint8_t scale, rt_bool_t load)
{ {
rt_uint8_t scale = 2; rt_uint8_t scale = 0;
rt_uint8_t *wrkBuffer; rt_uint8_t *wrkBuffer;
struct rtgui_image_bmp *bmp; struct rtgui_image_bmp *bmp;
rt_uint32_t bmpHeaderSize; rt_uint32_t bmpHeaderSize;
@ -216,7 +208,8 @@ static rt_bool_t rtgui_image_bmp_load(struct rtgui_image* image, struct rtgui_fi
// rt_kprintf("BMP: bmpHeaderSize %d\n", bmpHeaderSize); // rt_kprintf("BMP: bmpHeaderSize %d\n", bmpHeaderSize);
colorsUsed = 0; colorsUsed = 0;
if (bmpHeaderSize == 12) if (bmpHeaderSize == 12)
{ /* Bitmap Header Version 2.x */ {
/* Bitmap Header Version 2.x */
if (rtgui_filerw_read(file, (void *)wrkBuffer, 8, 1) != 8) if (rtgui_filerw_read(file, (void *)wrkBuffer, 8, 1) != 8)
{ {
break; break;
@ -228,7 +221,8 @@ static rt_bool_t rtgui_image_bmp_load(struct rtgui_image* image, struct rtgui_fi
bmp->bit_per_pixel = (rt_uint8_t) * (rt_uint16_t *)&wrkBuffer[6]; bmp->bit_per_pixel = (rt_uint8_t) * (rt_uint16_t *)&wrkBuffer[6];
} }
else else
{ /* Bitmap Header Version bigger than 2.x */ {
/* Bitmap Header Version bigger than 2.x */
rt_uint32_t compression; rt_uint32_t compression;
if (rtgui_filerw_read(file, (void *)wrkBuffer, 36, 1) != 36) if (rtgui_filerw_read(file, (void *)wrkBuffer, 36, 1) != 36)
@ -478,7 +472,8 @@ static rt_bool_t rtgui_image_bmp_load(struct rtgui_image* image, struct rtgui_fi
/* Release memory */ /* Release memory */
rt_free(wrkBuffer); rt_free(wrkBuffer);
return RT_TRUE; return RT_TRUE;
} while(0); }
while (0);
/* Release memory */ /* Release memory */
rt_free(wrkBuffer); rt_free(wrkBuffer);
@ -560,19 +555,25 @@ static void rtgui_image_bmp_blit(struct rtgui_image* image, struct rtgui_dc* dc,
rt_uint8_t skipLength; rt_uint8_t skipLength;
rt_uint16_t x, y; rt_uint16_t x, y;
rt_int8_t scale1, scale2; rt_int8_t scale1, scale2;
rt_uint16_t y_start = dst_rect->y1 + h - 1;
wrkBuffer = (rt_uint8_t *)rt_malloc(BMP_WORKING_BUFFER_SIZE);
if (wrkBuffer == RT_NULL)
{
rt_kprintf("BMP err: no mem (%d)\n", BMP_WORKING_BUFFER_SIZE);
break;
}
/* Read the pixels. Note that the bmp image is upside down */ /* Read the pixels. Note that the bmp image is upside down */
if (rtgui_filerw_seek(bmp->filerw, bmp->pixel_offset, RTGUI_FILE_SEEK_SET) < 0) if (rtgui_filerw_seek(bmp->filerw, bmp->pixel_offset, RTGUI_FILE_SEEK_SET) < 0)
{ {
break; break;
} }
/* the image is upside down. So we need to start from middle if the
* image is higher than the dst_rect. */
if (image->h > rtgui_rect_height(*dst_rect))
{
int hdelta = image->h - rtgui_rect_height(*dst_rect);
if (rtgui_filerw_seek(bmp->filerw, hdelta * (bmp->pitch + bmp->pad) * (1 << bmp->scale),
RTGUI_FILE_SEEK_CUR) < 0)
{
error = RT_TRUE;
break;
}
}
if (bmp->bit_per_pixel == 1) if (bmp->bit_per_pixel == 1)
{ {
@ -601,9 +602,18 @@ static void rtgui_image_bmp_blit(struct rtgui_image* image, struct rtgui_dc* dc,
} }
} }
wrkBuffer = (rt_uint8_t *)rt_malloc(
(BMP_WORKING_BUFFER_SIZE > bmp->pitch) ? \
bmp->pitch : BMP_WORKING_BUFFER_SIZE);
if (wrkBuffer == RT_NULL)
{
rt_kprintf("BMP err: no mem (%d)\n", BMP_WORKING_BUFFER_SIZE);
break;
}
/* Process whole image */ /* Process whole image */
y = 0; y = 0;
while (y < image->h) while (y < h)
{ {
x = 0; x = 0;
readIndex = 0; readIndex = 0;
@ -613,7 +623,7 @@ static void rtgui_image_bmp_blit(struct rtgui_image* image, struct rtgui_dc* dc,
while (readIndex < bmp->pitch) while (readIndex < bmp->pitch)
{ {
/* Put progress indicator */ /* Put progress indicator */
rt_kprintf("\r%lu%%", y * 100UL / image->h); rt_kprintf("\r%lu%%", y * 100UL / h);
/* Read data to buffer */ /* Read data to buffer */
readLength = (BMP_WORKING_BUFFER_SIZE > (bmp->pitch - readIndex)) ? \ readLength = (BMP_WORKING_BUFFER_SIZE > (bmp->pitch - readIndex)) ? \
@ -629,18 +639,19 @@ static void rtgui_image_bmp_blit(struct rtgui_image* image, struct rtgui_dc* dc,
/* Process read buffer */ /* Process read buffer */
if (bmp->bit_per_pixel == 1) if (bmp->bit_per_pixel == 1)
{ {
rt_uint8_t j;
rtgui_color_t color;
for (loadIndex = skipLength; loadIndex < readLength; loadIndex += 1 << scale1) for (loadIndex = skipLength; loadIndex < readLength; loadIndex += 1 << scale1)
{ {
rt_uint8_t j;
for (j = 0; j < 8; j += 1 << scale2) for (j = 0; j < 8; j += 1 << scale2)
{ {
rtgui_color_t color;
color = image->palette->colors[(wrkBuffer[loadIndex] & (1 << (7 - j))) >> (7 - j)]; color = image->palette->colors[(wrkBuffer[loadIndex] & (1 << (7 - j))) >> (7 - j)];
rtgui_dc_draw_color_point(dc, rtgui_dc_draw_color_point(dc,
dst_rect->x1 + x++, dst_rect->x1 + x++,
dst_rect->y1 + image->h - y, y_start - y,
color); color);
if (x >= w)
break;
} }
if (scale1 && (readLength % (1 << scale1))) if (scale1 && (readLength % (1 << scale1)))
{ {
@ -650,18 +661,19 @@ static void rtgui_image_bmp_blit(struct rtgui_image* image, struct rtgui_dc* dc,
} }
else if (bmp->bit_per_pixel == 4) else if (bmp->bit_per_pixel == 4)
{ {
rt_uint8_t j;
rtgui_color_t color;
for (loadIndex = skipLength; loadIndex < readLength; loadIndex += 1 << scale1) for (loadIndex = skipLength; loadIndex < readLength; loadIndex += 1 << scale1)
{ {
rt_uint8_t j;
for (j = 0; j < 8; j += 1 << (2 + scale2)) for (j = 0; j < 8; j += 1 << (2 + scale2))
{ {
rtgui_color_t color;
color = image->palette->colors[(wrkBuffer[loadIndex] & (0x0F << (4 - j))) >> (4 - j)]; color = image->palette->colors[(wrkBuffer[loadIndex] & (0x0F << (4 - j))) >> (4 - j)];
rtgui_dc_draw_color_point(dc, rtgui_dc_draw_color_point(dc,
dst_rect->x1 + x++, dst_rect->x1 + x++,
dst_rect->y1 + image->h - y, y_start - y,
color); color);
if (x >= w)
break;
} }
} }
if (scale1 && (readLength % (1 << scale1))) if (scale1 && (readLength % (1 << scale1)))
@ -671,15 +683,16 @@ static void rtgui_image_bmp_blit(struct rtgui_image* image, struct rtgui_dc* dc,
} }
else if (bmp->bit_per_pixel == 8) else if (bmp->bit_per_pixel == 8)
{ {
rtgui_color_t color;
for (loadIndex = skipLength; loadIndex < readLength; loadIndex += 1 << bmp->scale) for (loadIndex = skipLength; loadIndex < readLength; loadIndex += 1 << bmp->scale)
{ {
rtgui_color_t color;
color = image->palette->colors[wrkBuffer[loadIndex]]; color = image->palette->colors[wrkBuffer[loadIndex]];
rtgui_dc_draw_color_point(dc, rtgui_dc_draw_color_point(dc,
dst_rect->x1 + x++, dst_rect->x1 + x++,
dst_rect->y1 + image->h - y, y_start - y,
color); color);
if (x >= w)
break;
} }
if (readLength % (1 << bmp->scale)) if (readLength % (1 << bmp->scale))
{ {
@ -713,9 +726,11 @@ static void rtgui_image_bmp_blit(struct rtgui_image* image, struct rtgui_dc* dc,
blit_line(temp, &wrkBuffer[loadIndex], bytePerPixel); blit_line(temp, &wrkBuffer[loadIndex], bytePerPixel);
dc->engine->blit_line(dc, dc->engine->blit_line(dc,
dst_rect->x1 + x, dst_rect->x1 + x + 1, dst_rect->x1 + x, dst_rect->x1 + x + 1,
dst_rect->y1 + image->h - y, y_start - y,
temp); temp);
x++; x++;
if (x >= w)
break;
} }
if (readLength % (1 << bmp->scale)) if (readLength % (1 << bmp->scale))
{ {
@ -813,7 +828,8 @@ static void rtgui_image_bmp_blit(struct rtgui_image* image, struct rtgui_dc* dc,
} }
} }
// rt_kprintf("BMP: blit ok\n"); // rt_kprintf("BMP: blit ok\n");
} while(0); }
while (0);
} }
void rtgui_image_bmp_init() void rtgui_image_bmp_init()

View File

@ -64,7 +64,8 @@ struct rtgui_image_engine rtgui_image_jpg_engine =
}; };
#define INPUT_BUFFER_SIZE 4096 #define INPUT_BUFFER_SIZE 4096
typedef struct { typedef struct
{
struct jpeg_source_mgr pub; struct jpeg_source_mgr pub;
struct rtgui_filerw *ctx; struct rtgui_filerw *ctx;
@ -165,7 +166,8 @@ static void rtgui_jpeg_filerw_src_init(j_decompress_ptr cinfo, struct rtgui_file
* This makes it unsafe to use this manager and a different source * This makes it unsafe to use this manager and a different source
* manager serially with the same JPEG object. Caveat programmer. * manager serially with the same JPEG object. Caveat programmer.
*/ */
if (cinfo->src == NULL) { /* first time for this JPEG object? */ if (cinfo->src == NULL) /* first time for this JPEG object? */
{
cinfo->src = (struct jpeg_source_mgr *) cinfo->src = (struct jpeg_source_mgr *)
(*cinfo->mem->alloc_small)((j_common_ptr) cinfo, JPOOL_PERMANENT, (*cinfo->mem->alloc_small)((j_common_ptr) cinfo, JPOOL_PERMANENT,
sizeof(rtgui_jpeg_source_mgr)); sizeof(rtgui_jpeg_source_mgr));
@ -417,7 +419,7 @@ static void rtgui_image_jpeg_blit(struct rtgui_image* image, struct rtgui_dc* dc
else else
{ {
/* seek to the begin of file */ /* seek to the begin of file */
rtgui_filerw_seek(jpeg->filerw, 0, SEEK_SET); rtgui_filerw_seek(jpeg->filerw, 0, RTGUI_FILE_SEEK_SET);
/* decompress line and line */ /* decompress line and line */
for (y = 0; y < image->h; y ++) for (y = 0; y < image->h; y ++)
@ -452,39 +454,58 @@ static rt_bool_t rtgui_image_jpeg_check(struct rtgui_filerw* file)
in_scan = 0; in_scan = 0;
/* seek to the begining of file */ /* seek to the begining of file */
rtgui_filerw_seek(file, 0, SEEK_SET); rtgui_filerw_seek(file, 0, RTGUI_FILE_SEEK_SET);
if ( rtgui_filerw_read(file, magic, 2, 1) ) { if (rtgui_filerw_read(file, magic, 2, 1))
if ( (magic[0] == 0xFF) && (magic[1] == 0xD8) ) { {
if ((magic[0] == 0xFF) && (magic[1] == 0xD8))
{
is_JPG = RT_TRUE; is_JPG = RT_TRUE;
while (is_JPG == RT_TRUE) { while (is_JPG == RT_TRUE)
if(rtgui_filerw_read(file, magic, 1, 2) != 2) { {
if (rtgui_filerw_read(file, magic, 1, 2) != 2)
{
is_JPG = RT_FALSE; is_JPG = RT_FALSE;
} else if( (magic[0] != 0xFF) && (in_scan == 0) ) { }
else if ((magic[0] != 0xFF) && (in_scan == 0))
{
is_JPG = RT_FALSE; is_JPG = RT_FALSE;
} else if( (magic[0] != 0xFF) || (magic[1] == 0xFF) ) { }
else if ((magic[0] != 0xFF) || (magic[1] == 0xFF))
{
/* Extra padding in JPEG (legal) */ /* Extra padding in JPEG (legal) */
/* or this is data and we are scanning */ /* or this is data and we are scanning */
rtgui_filerw_seek(file, -1, SEEK_CUR); rtgui_filerw_seek(file, -1, RTGUI_FILE_SEEK_CUR);
} else if(magic[1] == 0xD9) { }
else if (magic[1] == 0xD9)
{
/* Got to end of good JPEG */ /* Got to end of good JPEG */
break; break;
} else if( (in_scan == 1) && (magic[1] == 0x00) ) { }
else if ((in_scan == 1) && (magic[1] == 0x00))
{
/* This is an encoded 0xFF within the data */ /* This is an encoded 0xFF within the data */
} else if( (magic[1] >= 0xD0) && (magic[1] < 0xD9) ) { }
else if ((magic[1] >= 0xD0) && (magic[1] < 0xD9))
{
/* These have nothing else */ /* These have nothing else */
} else if(rtgui_filerw_read(file, magic+2, 1, 2) != 2) { }
else if (rtgui_filerw_read(file, magic + 2, 1, 2) != 2)
{
is_JPG = RT_FALSE; is_JPG = RT_FALSE;
} else { }
else
{
/* Yes, it's big-endian */ /* Yes, it's big-endian */
rt_uint32_t start; rt_uint32_t start;
rt_uint32_t size; rt_uint32_t size;
rt_uint32_t end; rt_uint32_t end;
start = rtgui_filerw_tell(file); start = rtgui_filerw_tell(file);
size = (magic[2] << 8) + magic[3]; size = (magic[2] << 8) + magic[3];
end = rtgui_filerw_seek(file, size-2, SEEK_CUR); end = rtgui_filerw_seek(file, size - 2, RTGUI_FILE_SEEK_CUR);
if (end != start + size - 2) is_JPG = RT_FALSE; if (end != start + size - 2) is_JPG = RT_FALSE;
if ( magic[1] == 0xDA ) { if (magic[1] == 0xDA)
{
/* Now comes the actual JPEG meat */ /* Now comes the actual JPEG meat */
/* It is a JPEG. */ /* It is a JPEG. */
break; break;
@ -493,7 +514,7 @@ static rt_bool_t rtgui_image_jpeg_check(struct rtgui_filerw* file)
} }
} }
} }
rtgui_filerw_seek(file, start, SEEK_SET); rtgui_filerw_seek(file, start, RTGUI_FILE_SEEK_SET);
return is_JPG; return is_JPG;
} }
@ -558,10 +579,6 @@ struct rtgui_image_jpeg
/* Private macro -------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/
/* static rt_bool_t rtgui_image_jpeg_check(struct rtgui_filerw* file,
rt_uint16_t *width, rt_uint16_t *height);
static rt_bool_t rtgui_image_jpeg_load(struct rtgui_image* image,
struct rtgui_filerw* file, rt_uint8_t scale, rt_bool_t load); */
static rt_bool_t rtgui_image_jpeg_check(struct rtgui_filerw *file); static rt_bool_t rtgui_image_jpeg_check(struct rtgui_filerw *file);
static rt_bool_t rtgui_image_jpeg_load(struct rtgui_image *image, struct rtgui_filerw *file, rt_bool_t load); static rt_bool_t rtgui_image_jpeg_load(struct rtgui_image *image, struct rtgui_filerw *file, rt_bool_t load);
static void rtgui_image_jpeg_unload(struct rtgui_image *image); static void rtgui_image_jpeg_unload(struct rtgui_image *image);
@ -645,6 +662,14 @@ static UINT tjpgd_out_func(JDEC *jdec, void *bitmap, JRECT *rect)
{ {
rtgui_blit_line_func blit_line = RT_NULL; rtgui_blit_line_func blit_line = RT_NULL;
/* we decompress from top to bottom if the block is beyond the right
* boundary, just continue to next block. However, if the block is
* beyond the bottom boundary, we don't need to decompress the rest. */
if (rect->left > jpeg->dst_w)
return 1;
if (rect->top > jpeg->dst_h)
return 0;
w = rect->right < jpeg->dst_w ? rect->right : jpeg->dst_w; w = rect->right < jpeg->dst_w ? rect->right : jpeg->dst_w;
w = w - rect->left + 1; w = w - rect->left + 1;
h = rect->bottom < jpeg->dst_h ? rect->bottom : jpeg->dst_h; h = rect->bottom < jpeg->dst_h ? rect->bottom : jpeg->dst_h;
@ -669,7 +694,7 @@ static UINT tjpgd_out_func(JDEC *jdec, void *bitmap, JRECT *rect)
{ {
blit_line(line_buf, src, w * jpeg->byte_per_pixel); blit_line(line_buf, src, w * jpeg->byte_per_pixel);
jpeg->dc->engine->blit_line(jpeg->dc, jpeg->dc->engine->blit_line(jpeg->dc,
jpeg->dst_x + rect->left, jpeg->dst_x + rect->left + w - 1, jpeg->dst_x + rect->left, jpeg->dst_x + rect->left + w,
jpeg->dst_y + rect->top + y, jpeg->dst_y + rect->top + y,
line_buf); line_buf);
src += rectWidth; src += rectWidth;
@ -680,7 +705,7 @@ static UINT tjpgd_out_func(JDEC *jdec, void *bitmap, JRECT *rect)
for (y = 0; y < h; y++) for (y = 0; y < h; y++)
{ {
jpeg->dc->engine->blit_line(jpeg->dc, jpeg->dc->engine->blit_line(jpeg->dc,
jpeg->dst_x + rect->left, jpeg->dst_x + rect->left + w - 1, jpeg->dst_x + rect->left, jpeg->dst_x + rect->left + w,
jpeg->dst_y + rect->top + y, jpeg->dst_y + rect->top + y,
src); src);
src += rectWidth; src += rectWidth;
@ -691,21 +716,19 @@ static UINT tjpgd_out_func(JDEC *jdec, void *bitmap, JRECT *rect)
} }
static rt_bool_t rtgui_image_jpeg_check(struct rtgui_filerw *file) static rt_bool_t rtgui_image_jpeg_check(struct rtgui_filerw *file)
//static rt_bool_t rtgui_image_jpeg_check(struct rtgui_filerw* file,
// rt_uint32_t *width, rt_uint32_t *height)
{ {
rt_bool_t is_JPG; rt_bool_t is_JPG;
JDEC tjpgd; JDEC tjpgd;
void *pool; void *pool;
if (!file)
{
return RT_FALSE;
}
is_JPG = RT_FALSE; is_JPG = RT_FALSE;
do do
{ {
if (!file )
{
break;
}
pool = rt_malloc(TJPGD_WORKING_BUFFER_SIZE); pool = rt_malloc(TJPGD_WORKING_BUFFER_SIZE);
if (pool == RT_NULL) if (pool == RT_NULL)
{ {
@ -713,7 +736,7 @@ static rt_bool_t rtgui_image_jpeg_check(struct rtgui_filerw* file)
break; break;
} }
if (rtgui_filerw_seek(file, 0, SEEK_SET) == -1) if (rtgui_filerw_seek(file, 0, RTGUI_FILE_SEEK_SET) == -1)
{ {
break; break;
} }
@ -721,13 +744,12 @@ static rt_bool_t rtgui_image_jpeg_check(struct rtgui_filerw* file)
if (jd_prepare(&tjpgd, tjpgd_in_func, pool, if (jd_prepare(&tjpgd, tjpgd_in_func, pool,
TJPGD_WORKING_BUFFER_SIZE, (void *)&file) == JDR_OK) TJPGD_WORKING_BUFFER_SIZE, (void *)&file) == JDR_OK)
{ {
// *width = (rt_uint32_t)tjpgd.width;
// *height = (rt_uint32_t)tjpgd.height;
is_JPG = RT_TRUE; is_JPG = RT_TRUE;
} }
rt_kprintf("TJPGD: check OK\n"); rt_kprintf("TJPGD: check OK\n");
} while(0); }
while (0);
rt_free(pool); rt_free(pool);
@ -735,10 +757,8 @@ static rt_bool_t rtgui_image_jpeg_check(struct rtgui_filerw* file)
} }
static rt_bool_t rtgui_image_jpeg_load(struct rtgui_image *image, struct rtgui_filerw *file, rt_bool_t load) static rt_bool_t rtgui_image_jpeg_load(struct rtgui_image *image, struct rtgui_filerw *file, rt_bool_t load)
//static rt_bool_t rtgui_image_jpeg_load(struct rtgui_image* image,
// struct rtgui_filerw* file, rt_uint8_t scale, rt_bool_t load)
{ {
rt_uint8_t scale = 2; rt_uint8_t scale = 0;
rt_bool_t res = RT_FALSE; rt_bool_t res = RT_FALSE;
struct rtgui_image_jpeg *jpeg; struct rtgui_image_jpeg *jpeg;
JRESULT ret; JRESULT ret;
@ -774,7 +794,7 @@ static rt_bool_t rtgui_image_jpeg_load(struct rtgui_image* image, struct rtgui_f
break; break;
} }
if (rtgui_filerw_seek(jpeg->filerw, 0, SEEK_SET) == -1) if (rtgui_filerw_seek(jpeg->filerw, 0, RTGUI_FILE_SEEK_SET) == -1)
{ {
break; break;
} }
@ -821,7 +841,8 @@ static rt_bool_t rtgui_image_jpeg_load(struct rtgui_image* image, struct rtgui_f
rt_kprintf("TJPGD: load to RAM\n"); rt_kprintf("TJPGD: load to RAM\n");
} }
res = RT_TRUE; res = RT_TRUE;
} while(0); }
while (0);
if (!res || jpeg->is_loaded) if (!res || jpeg->is_loaded)
{ {
@ -960,14 +981,15 @@ static void rtgui_image_jpeg_blit(struct rtgui_image* image,
for (y = 0; y < h; y++) for (y = 0; y < h; y++)
{ {
dc->engine->blit_line(dc, dc->engine->blit_line(dc,
dst_rect->x1, dst_rect->x1 + w - 1, dst_rect->x1, dst_rect->x1 + w,
dst_rect->y1 + y, dst_rect->y1 + y,
src); src);
src += imageWidth; src += imageWidth;
} }
} }
} }
} while(0); }
while (0);
} }
#endif /* defined(RTGUI_IMAGE_TJPGD) */ #endif /* defined(RTGUI_IMAGE_TJPGD) */
/***************************************************************************//** /***************************************************************************//**

View File

@ -60,6 +60,7 @@ typedef struct rtgui_image rtgui_image_t;
void rtgui_system_image_init(void); void rtgui_system_image_init(void);
#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW) #if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
struct rtgui_image_engine* rtgui_image_get_engine_by_filename(const char* fn);
struct rtgui_image* rtgui_image_create_from_file(const char* type, const char* filename, rt_bool_t load); struct rtgui_image* rtgui_image_create_from_file(const char* type, const char* filename, rt_bool_t load);
struct rtgui_image* rtgui_image_create(const char* filename, rt_bool_t load); struct rtgui_image* rtgui_image_create(const char* filename, rt_bool_t load);
#endif #endif

View File

@ -34,6 +34,7 @@ struct rtgui_notebook* rtgui_notebook_create(const rtgui_rect_t* rect, rt_uint8_
void rtgui_notebook_destroy(struct rtgui_notebook* notebook); void rtgui_notebook_destroy(struct rtgui_notebook* notebook);
void rtgui_notebook_add(struct rtgui_notebook* notebook, const char* label, struct rtgui_widget* child); void rtgui_notebook_add(struct rtgui_notebook* notebook, const char* label, struct rtgui_widget* child);
void rtgui_notebook_remove(struct rtgui_notebook* notebook, rt_uint16_t index);
struct rtgui_widget* rtgui_notebook_get_current(struct rtgui_notebook* notebook); struct rtgui_widget* rtgui_notebook_get_current(struct rtgui_notebook* notebook);
rt_int16_t rtgui_notebook_get_current_index(struct rtgui_notebook* notebook); rt_int16_t rtgui_notebook_get_current_index(struct rtgui_notebook* notebook);

View File

@ -133,10 +133,6 @@ void rtgui_win_move(struct rtgui_win* win, int x, int y);
/* reset extent of window */ /* reset extent of window */
void rtgui_win_set_rect(rtgui_win_t* win, rtgui_rect_t* rect); void rtgui_win_set_rect(rtgui_win_t* win, rtgui_rect_t* rect);
#ifndef RTGUI_USING_SMALL_SIZE
void rtgui_win_set_box(rtgui_win_t* win, rtgui_box_t* box);
#endif
void rtgui_win_set_onactivate(rtgui_win_t* win, rtgui_event_handler_ptr handler); void rtgui_win_set_onactivate(rtgui_win_t* win, rtgui_event_handler_ptr handler);
void rtgui_win_set_ondeactivate(rtgui_win_t* win, rtgui_event_handler_ptr handler); void rtgui_win_set_ondeactivate(rtgui_win_t* win, rtgui_event_handler_ptr handler);
void rtgui_win_set_onclose(rtgui_win_t* win, rtgui_event_handler_ptr handler); void rtgui_win_set_onclose(rtgui_win_t* win, rtgui_event_handler_ptr handler);

View File

@ -231,6 +231,8 @@ void rtgui_notebook_add(struct rtgui_notebook* notebook, const char* label, stru
void rtgui_notebook_remove(struct rtgui_notebook* notebook, rt_uint16_t index) void rtgui_notebook_remove(struct rtgui_notebook* notebook, rt_uint16_t index)
{ {
struct rtgui_notebook_tab tab; struct rtgui_notebook_tab tab;
rt_bool_t need_update = RT_FALSE;
RT_ASSERT(notebook != RT_NULL); RT_ASSERT(notebook != RT_NULL);
if (index < notebook->count) if (index < notebook->count)
@ -244,6 +246,9 @@ void rtgui_notebook_remove(struct rtgui_notebook* notebook, rt_uint16_t index)
} }
else else
{ {
if (notebook->current == index)
need_update = RT_TRUE;
tab = notebook->childs[index]; tab = notebook->childs[index];
for (;index < notebook->count - 1; index++) for (;index < notebook->count - 1; index++)
{ {
@ -255,16 +260,17 @@ void rtgui_notebook_remove(struct rtgui_notebook* notebook, rt_uint16_t index)
sizeof(struct rtgui_notebook_tab) * notebook->count); sizeof(struct rtgui_notebook_tab) * notebook->count);
} }
// FIXME: do we really want to destroy it?
rtgui_widget_destroy(tab.widget);
rtgui_free(tab.title); rtgui_free(tab.title);
if (notebook->current == index) if (need_update)
{ {
/* update tab */
if (notebook->current > notebook->count - 1) if (notebook->current > notebook->count - 1)
notebook->current = notebook->count - 1; notebook->current = notebook->count - 1;
rtgui_widget_hide(tab.widget);
rtgui_widget_show(notebook->childs[notebook->current].widget);
rtgui_widget_update(RTGUI_WIDGET(notebook)); rtgui_widget_update(RTGUI_WIDGET(notebook));
rtgui_widget_set_parent(tab.widget, RT_NULL);
} }
} }
} }

View File

@ -74,7 +74,7 @@ static void _rtgui_widget_destructor(rtgui_widget_t *widget)
{ {
if (widget == RT_NULL) return; if (widget == RT_NULL) return;
if (widget->parent != RT_NULL) if (widget->parent != RT_NULL && RTGUI_IS_CONTAINER(widget->parent))
{ {
/* remove widget from parent's children list */ /* remove widget from parent's children list */
rtgui_list_remove(&(RTGUI_CONTAINER(widget->parent)->children), &(widget->sibling)); rtgui_list_remove(&(RTGUI_CONTAINER(widget->parent)->children), &(widget->sibling));
@ -413,8 +413,7 @@ rt_bool_t rtgui_widget_onupdate_toplvl(struct rtgui_object *object, struct rtgui
rt_bool_t rtgui_widget_event_handler(struct rtgui_object* object, rtgui_event_t* event) rt_bool_t rtgui_widget_event_handler(struct rtgui_object* object, rtgui_event_t* event)
{ {
RT_ASSERT(object != RT_NULL); RTGUI_WIDGET_EVENT_HANDLER_PREPARE;
RT_ASSERT(event != RT_NULL);
switch (event->type) switch (event->type)
{ {
@ -538,9 +537,10 @@ rt_bool_t rtgui_widget_onshow(struct rtgui_object *object, struct rtgui_event *e
{ {
struct rtgui_widget *widget = RTGUI_WIDGET(object); struct rtgui_widget *widget = RTGUI_WIDGET(object);
/* update the clip info of widget */ if (!RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(object)))
return RT_FALSE;
RTGUI_WIDGET_UNHIDE(widget); RTGUI_WIDGET_UNHIDE(widget);
rtgui_widget_update_clip(widget);
if (widget->on_show != RT_NULL) if (widget->on_show != RT_NULL)
widget->on_show(RTGUI_OBJECT(widget), RT_NULL); widget->on_show(RTGUI_OBJECT(widget), RT_NULL);
@ -552,6 +552,9 @@ rt_bool_t rtgui_widget_onhide(struct rtgui_object *object, struct rtgui_event *e
{ {
struct rtgui_widget *widget = RTGUI_WIDGET(object); struct rtgui_widget *widget = RTGUI_WIDGET(object);
if (RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(object)))
return RT_FALSE;
/* hide this widget */ /* hide this widget */
RTGUI_WIDGET_HIDE(widget); RTGUI_WIDGET_HIDE(widget);

View File

@ -594,16 +594,6 @@ void rtgui_win_set_rect(rtgui_win_t* win, rtgui_rect_t* rect)
} }
} }
#ifndef RTGUI_USING_SMALL_SIZE
void rtgui_win_set_box(rtgui_win_t* win, rtgui_box_t* box)
{
if (win == RT_NULL || box == RT_NULL) return;
rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(box));
rtgui_widget_set_rect(RTGUI_WIDGET(box), &(RTGUI_WIDGET(win)->extent));
}
#endif
void rtgui_win_set_onactivate(rtgui_win_t* win, rtgui_event_handler_ptr handler) void rtgui_win_set_onactivate(rtgui_win_t* win, rtgui_event_handler_ptr handler)
{ {
if (win != RT_NULL) if (win != RT_NULL)