summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
authorTeruaki Kawashima <teru@rockbox.org>2009-08-21 14:14:08 +0000
committerTeruaki Kawashima <teru@rockbox.org>2009-08-21 14:14:08 +0000
commit32ad9a596645d08be8e91c39fbe53629bec35d69 (patch)
tree3c62ef4200da7d8c7fd62c27da921270099feec0 /apps/plugins
parent2a4c4de8576a23d62158d7f67dbbb90dda09f073 (diff)
downloadrockbox-32ad9a596645d08be8e91c39fbe53629bec35d69.tar.gz
rockbox-32ad9a596645d08be8e91c39fbe53629bec35d69.zip
rockpaint: some fixes and optimization.
Clip image when pasting copied/cut rectangle. Don't use memset in load_bitmap when filling blank spaces with background color. Clear buffer when failed to load bitmap file. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22448 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/rockpaint.c95
1 files changed, 51 insertions, 44 deletions
diff --git a/apps/plugins/rockpaint.c b/apps/plugins/rockpaint.c
index 219f013ed8..12b30d484d 100644
--- a/apps/plugins/rockpaint.c
+++ b/apps/plugins/rockpaint.c
@@ -370,7 +370,7 @@ extern fb_data rockpaint[];
370extern fb_data rockpaint_hsvrgb[]; 370extern fb_data rockpaint_hsvrgb[];
371 371
372/* Maximum string size allowed for the text tool */ 372/* Maximum string size allowed for the text tool */
373#define MAX_TEXT 255 373#define MAX_TEXT 256
374 374
375static union 375static union
376{ 376{
@@ -399,9 +399,9 @@ static union
399 /* Used for text mode */ 399 /* Used for text mode */
400 struct 400 struct
401 { 401 {
402 char text[MAX_TEXT+1]; 402 char text[MAX_TEXT];
403 char font[MAX_PATH+1]; 403 char font[MAX_PATH];
404 char old_font[MAX_PATH+1]; 404 char old_font[MAX_PATH];
405 int fh_buf[30]; 405 int fh_buf[30];
406 int fw_buf[30]; 406 int fw_buf[30];
407 char fontname_buf[30][MAX_PATH]; 407 char fontname_buf[30][MAX_PATH];
@@ -409,7 +409,7 @@ static union
409} buffer; 409} buffer;
410 410
411/* Current filename */ 411/* Current filename */
412static char filename[MAX_PATH+1]; 412static char filename[MAX_PATH];
413 413
414/* Font preview buffer */ 414/* Font preview buffer */
415//#define FONT_PREVIEW_WIDTH ((LCD_WIDTH-30)/8) 415//#define FONT_PREVIEW_WIDTH ((LCD_WIDTH-30)/8)
@@ -596,10 +596,16 @@ static int draw_window( int height, int width,
596 * File browser 596 * File browser
597 ***********************************************************************/ 597 ***********************************************************************/
598 598
599char bbuf[MAX_PATH+1]; /* used by file and font browsers */ 599char bbuf[MAX_PATH]; /* used by file and font browsers */
600char bbuf_s[MAX_PATH+1]; /* used by file and font browsers */ 600char bbuf_s[MAX_PATH]; /* used by file and font browsers */
601struct tree_context *tree = NULL; 601struct tree_context *tree = NULL;
602 602
603static bool check_extention(const char *filename, const char *ext)
604{
605 const char *p = rb->strrchr( filename, '.' );
606 return ( p != NULL && !rb->strcasecmp( p, ext ) );
607}
608
603static const char* browse_get_name_cb(int selected_item, void *data, 609static const char* browse_get_name_cb(int selected_item, void *data,
604 char *buffer, size_t buffer_len) 610 char *buffer, size_t buffer_len)
605{ 611{
@@ -662,8 +668,7 @@ static bool browse( char *dst, int dst_size, const char *start )
662 rb->strcmp( dc[i].name, "." ) && 668 rb->strcmp( dc[i].name, "." ) &&
663 rb->strcmp( dc[i].name, ".." )) || 669 rb->strcmp( dc[i].name, ".." )) ||
664 ( !(dc[i].attr & ATTR_DIRECTORY) && 670 ( !(dc[i].attr & ATTR_DIRECTORY) &&
665 (a = rb->strrchr( dc[i].name,'.' )) && 671 check_extention( dc[i].name, ".bmp" ) ) )
666 !rb->strcmp( a, ".bmp" ) ))
667 { 672 {
668 if( !rb->strcmp( dc[i].name, bbuf_s ) ) 673 if( !rb->strcmp( dc[i].name, bbuf_s ) )
669 selected = item_count; 674 selected = item_count;
@@ -816,9 +821,7 @@ static bool browse_fonts( char *dst, int dst_size )
816 li = i-1; 821 li = i-1;
817 break; 822 break;
818 } 823 }
819 if( rb->strlen( de->d_name ) < 4 824 if( !check_extention( de->d_name, ".fnt" ) )
820 || rb->strcmp( de->d_name + rb->strlen( de->d_name ) - 4,
821 ".fnt" ) )
822 continue; 825 continue;
823 rb->snprintf( bbuf, MAX_PATH, FONT_DIR "/%s", 826 rb->snprintf( bbuf, MAX_PATH, FONT_DIR "/%s",
824 de->d_name ); 827 de->d_name );
@@ -851,9 +854,7 @@ static bool browse_fonts( char *dst, int dst_size )
851 { 854 {
852 li = lvi; 855 li = lvi;
853 } 856 }
854 else if( !nvih && !rb->strlen( de->d_name ) < 4 857 else if( !nvih && check_extention( de->d_name, ".fnt" ) )
855 && !rb->strcmp( de->d_name + rb->strlen( de->d_name ) - 4,
856 ".fnt" ) )
857 { 858 {
858 rb->snprintf( bbuf, MAX_PATH, FONT_DIR "/%s", 859 rb->snprintf( bbuf, MAX_PATH, FONT_DIR "/%s",
859 de->d_name ); 860 de->d_name );
@@ -1203,9 +1204,11 @@ static void color_picker( int x, int y )
1203 rb->lcd_set_foreground( save_buffer[ x+y*COLS ] ); 1204 rb->lcd_set_foreground( save_buffer[ x+y*COLS ] );
1204#define PSIZE 12 1205#define PSIZE 12
1205 rb->lcd_set_drawmode(DRMODE_COMPLEMENT); 1206 rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
1206 rb->lcd_drawrect( x<COLS-PSIZE ? x + 2 : x - PSIZE, y<ROWS-PSIZE ? y + 2: y - PSIZE, PSIZE - 2, PSIZE - 2 ); 1207 if( x >= COLS - PSIZE ) x -= PSIZE + 2;
1208 if( y >= ROWS - PSIZE ) y -= PSIZE + 2;
1209 rb->lcd_drawrect( x + 2, y + 2, PSIZE - 2, PSIZE - 2 );
1207 rb->lcd_set_drawmode(DRMODE_SOLID); 1210 rb->lcd_set_drawmode(DRMODE_SOLID);
1208 rb->lcd_fillrect( x<COLS-PSIZE ? x+3 : x - PSIZE+1, y<ROWS-PSIZE ? y +3: y - PSIZE+1, PSIZE-4, PSIZE-4 ); 1211 rb->lcd_drawrect( x + 3, y + 3, PSIZE - 4, PSIZE - 4 );
1209#undef PSIZE 1212#undef PSIZE
1210 rb->lcd_set_foreground( rp_colors[ drawcolor ] ); 1213 rb->lcd_set_foreground( rp_colors[ drawcolor ] );
1211 } 1214 }
@@ -1415,7 +1418,7 @@ static void draw_rot_90_deg( int x1, int y1, int x2, int y2, int direction )
1415static void draw_paste_rectangle( int src_x1, int src_y1, int src_x2, 1418static void draw_paste_rectangle( int src_x1, int src_y1, int src_x2,
1416 int src_y2, int x1, int y1, int mode ) 1419 int src_y2, int x1, int y1, int mode )
1417{ 1420{
1418 int i; 1421 int i, width, height;
1419 if( mode == SELECT_MENU_CUT ) 1422 if( mode == SELECT_MENU_CUT )
1420 { 1423 {
1421 i = drawcolor; 1424 i = drawcolor;
@@ -1435,15 +1438,23 @@ static void draw_paste_rectangle( int src_x1, int src_y1, int src_x2,
1435 src_y1 = src_y2; 1438 src_y1 = src_y2;
1436 src_y2 = i; 1439 src_y2 = i;
1437 } 1440 }
1441 width = src_x2 - src_x1 + 1;
1442 height = src_y2 - src_y1 + 1;
1443 /* clipping */
1444 if( x1 + width > COLS )
1445 width = COLS - x1;
1446 if( y1 + height > ROWS )
1447 height = ROWS - y1;
1448
1438 rb->lcd_bitmap_part( buffer.clipboard, src_x1, src_y1, COLS, 1449 rb->lcd_bitmap_part( buffer.clipboard, src_x1, src_y1, COLS,
1439 x1, y1, src_x2-src_x1+1, src_y2-src_y1+1 ); 1450 x1, y1, width, height );
1440 if( !preview ) 1451 if( !preview )
1441 { 1452 {
1442 for( i = 0; i <= src_y2 - src_y1; i++ ) 1453 for( i = 0; i < height; i++ )
1443 { 1454 {
1444 rb->memcpy( save_buffer+(y1+i)*COLS+x1, 1455 rb->memcpy( save_buffer+(y1+i)*COLS+x1,
1445 buffer.clipboard+(src_y1+i)*COLS+src_x1, 1456 buffer.clipboard+(src_y1+i)*COLS+src_x1,
1446 (src_x2 - src_x1 + 1)*sizeof( fb_data ) ); 1457 width*sizeof( fb_data ) );
1447 } 1458 }
1448 } 1459 }
1449} 1460}
@@ -1787,20 +1798,18 @@ static void togglebg( void )
1787static void draw_rect_full( int x1, int y1, int x2, int y2 ) 1798static void draw_rect_full( int x1, int y1, int x2, int y2 )
1788{ 1799{
1789 /* GRUIK */ 1800 /* GRUIK */
1790 int x = x1; 1801 int x;
1791 togglebg(); 1802 togglebg();
1792 if( x < x2 ) 1803 if( x1 > x2 )
1793 {
1794 do {
1795 draw_line( x, y1, x, y2 );
1796 } while( ++x <= x2 );
1797 }
1798 else
1799 { 1804 {
1800 do { 1805 x = x1;
1801 draw_line( x, y1, x, y2 ); 1806 x1 = x2;
1802 } while( --x >= x2 ); 1807 x2 = x;
1803 } 1808 }
1809 x = x1;
1810 do {
1811 draw_line( x, y1, x, y2 );
1812 } while( ++x <= x2 );
1804 togglebg(); 1813 togglebg();
1805 draw_rect( x1, y1, x2, y2 ); 1814 draw_rect( x1, y1, x2, y2 );
1806} 1815}
@@ -2474,6 +2483,7 @@ static void goto_menu(void)
2474 { 2483 {
2475 rb->splashf( 1*HZ, "Error while loading %s", 2484 rb->splashf( 1*HZ, "Error while loading %s",
2476 filename ); 2485 filename );
2486 clear_drawing();
2477 } 2487 }
2478 else 2488 else
2479 { 2489 {
@@ -2491,8 +2501,7 @@ static void goto_menu(void)
2491 rb->strcpy(filename,"/"); 2501 rb->strcpy(filename,"/");
2492 if( !rb->kbd_input( filename, MAX_PATH ) ) 2502 if( !rb->kbd_input( filename, MAX_PATH ) )
2493 { 2503 {
2494 if(rb->strlen(filename) <= 4 || 2504 if( !check_extention( filename, ".bmp" ) )
2495 rb->strcasecmp(&filename[rb->strlen(filename)-4], ".bmp"))
2496 rb->strcat(filename, ".bmp"); 2505 rb->strcat(filename, ".bmp");
2497 save_bitmap( filename ); 2506 save_bitmap( filename );
2498 rb->splashf( 1*HZ, "File saved (%s)", filename ); 2507 rb->splashf( 1*HZ, "File saved (%s)", filename );
@@ -2932,7 +2941,8 @@ static int load_bitmap( const char *file )
2932{ 2941{
2933 struct bitmap bm; 2942 struct bitmap bm;
2934 bool ret; 2943 bool ret;
2935 int l; 2944 int i, j;
2945 fb_data color = rp_colors[ bgdrawcolor ];
2936 2946
2937 bm.data = (char*)save_buffer; 2947 bm.data = (char*)save_buffer;
2938 ret = rb->read_bmp_file( file, &bm, ROWS*COLS*sizeof( fb_data ), 2948 ret = rb->read_bmp_file( file, &bm, ROWS*COLS*sizeof( fb_data ),
@@ -2941,18 +2951,15 @@ static int load_bitmap( const char *file )
2941 if((bm.width > COLS ) || ( bm.height > ROWS )) 2951 if((bm.width > COLS ) || ( bm.height > ROWS ))
2942 return -1; 2952 return -1;
2943 2953
2944 for( l = bm.height-1; l > 0; l-- ) 2954 for( i = bm.height-1; i >= 0; i-- )
2945 { 2955 {
2946 rb->memmove( save_buffer+l*COLS, save_buffer+l*bm.width, 2956 rb->memmove( save_buffer+i*COLS, save_buffer+i*bm.width,
2947 sizeof( fb_data )*bm.width ); 2957 sizeof( fb_data )*bm.width );
2958 for( j = bm.width; j < COLS; j++ )
2959 save_buffer[j+i*COLS] = color;
2948 } 2960 }
2949 for( l = 0; l < bm.height; l++ ) 2961 for( i = bm.height*COLS; i < ROWS*COLS; i++ )
2950 { 2962 save_buffer[i] = color;
2951 rb->memset( save_buffer+l*COLS+bm.width, rp_colors[ bgdrawcolor ],
2952 sizeof( fb_data )*(COLS-bm.width) );
2953 }
2954 rb->memset( save_buffer+COLS*bm.height, rp_colors[ bgdrawcolor ],
2955 sizeof( fb_data )*COLS*(ROWS-bm.height) );
2956 2963
2957 return ret; 2964 return ret;
2958} 2965}