forked from len0rd/rockbox
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
This commit is contained in:
parent
2a4c4de857
commit
32ad9a5966
1 changed files with 51 additions and 44 deletions
|
@ -370,7 +370,7 @@ extern fb_data rockpaint[];
|
||||||
extern fb_data rockpaint_hsvrgb[];
|
extern fb_data rockpaint_hsvrgb[];
|
||||||
|
|
||||||
/* Maximum string size allowed for the text tool */
|
/* Maximum string size allowed for the text tool */
|
||||||
#define MAX_TEXT 255
|
#define MAX_TEXT 256
|
||||||
|
|
||||||
static union
|
static union
|
||||||
{
|
{
|
||||||
|
@ -399,9 +399,9 @@ static union
|
||||||
/* Used for text mode */
|
/* Used for text mode */
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
char text[MAX_TEXT+1];
|
char text[MAX_TEXT];
|
||||||
char font[MAX_PATH+1];
|
char font[MAX_PATH];
|
||||||
char old_font[MAX_PATH+1];
|
char old_font[MAX_PATH];
|
||||||
int fh_buf[30];
|
int fh_buf[30];
|
||||||
int fw_buf[30];
|
int fw_buf[30];
|
||||||
char fontname_buf[30][MAX_PATH];
|
char fontname_buf[30][MAX_PATH];
|
||||||
|
@ -409,7 +409,7 @@ static union
|
||||||
} buffer;
|
} buffer;
|
||||||
|
|
||||||
/* Current filename */
|
/* Current filename */
|
||||||
static char filename[MAX_PATH+1];
|
static char filename[MAX_PATH];
|
||||||
|
|
||||||
/* Font preview buffer */
|
/* Font preview buffer */
|
||||||
//#define FONT_PREVIEW_WIDTH ((LCD_WIDTH-30)/8)
|
//#define FONT_PREVIEW_WIDTH ((LCD_WIDTH-30)/8)
|
||||||
|
@ -596,10 +596,16 @@ static int draw_window( int height, int width,
|
||||||
* File browser
|
* File browser
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
|
|
||||||
char bbuf[MAX_PATH+1]; /* used by file and font browsers */
|
char bbuf[MAX_PATH]; /* used by file and font browsers */
|
||||||
char bbuf_s[MAX_PATH+1]; /* used by file and font browsers */
|
char bbuf_s[MAX_PATH]; /* used by file and font browsers */
|
||||||
struct tree_context *tree = NULL;
|
struct tree_context *tree = NULL;
|
||||||
|
|
||||||
|
static bool check_extention(const char *filename, const char *ext)
|
||||||
|
{
|
||||||
|
const char *p = rb->strrchr( filename, '.' );
|
||||||
|
return ( p != NULL && !rb->strcasecmp( p, ext ) );
|
||||||
|
}
|
||||||
|
|
||||||
static const char* browse_get_name_cb(int selected_item, void *data,
|
static const char* browse_get_name_cb(int selected_item, void *data,
|
||||||
char *buffer, size_t buffer_len)
|
char *buffer, size_t buffer_len)
|
||||||
{
|
{
|
||||||
|
@ -662,8 +668,7 @@ static bool browse( char *dst, int dst_size, const char *start )
|
||||||
rb->strcmp( dc[i].name, "." ) &&
|
rb->strcmp( dc[i].name, "." ) &&
|
||||||
rb->strcmp( dc[i].name, ".." )) ||
|
rb->strcmp( dc[i].name, ".." )) ||
|
||||||
( !(dc[i].attr & ATTR_DIRECTORY) &&
|
( !(dc[i].attr & ATTR_DIRECTORY) &&
|
||||||
(a = rb->strrchr( dc[i].name,'.' )) &&
|
check_extention( dc[i].name, ".bmp" ) ) )
|
||||||
!rb->strcmp( a, ".bmp" ) ))
|
|
||||||
{
|
{
|
||||||
if( !rb->strcmp( dc[i].name, bbuf_s ) )
|
if( !rb->strcmp( dc[i].name, bbuf_s ) )
|
||||||
selected = item_count;
|
selected = item_count;
|
||||||
|
@ -816,9 +821,7 @@ static bool browse_fonts( char *dst, int dst_size )
|
||||||
li = i-1;
|
li = i-1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if( rb->strlen( de->d_name ) < 4
|
if( !check_extention( de->d_name, ".fnt" ) )
|
||||||
|| rb->strcmp( de->d_name + rb->strlen( de->d_name ) - 4,
|
|
||||||
".fnt" ) )
|
|
||||||
continue;
|
continue;
|
||||||
rb->snprintf( bbuf, MAX_PATH, FONT_DIR "/%s",
|
rb->snprintf( bbuf, MAX_PATH, FONT_DIR "/%s",
|
||||||
de->d_name );
|
de->d_name );
|
||||||
|
@ -851,9 +854,7 @@ static bool browse_fonts( char *dst, int dst_size )
|
||||||
{
|
{
|
||||||
li = lvi;
|
li = lvi;
|
||||||
}
|
}
|
||||||
else if( !nvih && !rb->strlen( de->d_name ) < 4
|
else if( !nvih && check_extention( de->d_name, ".fnt" ) )
|
||||||
&& !rb->strcmp( de->d_name + rb->strlen( de->d_name ) - 4,
|
|
||||||
".fnt" ) )
|
|
||||||
{
|
{
|
||||||
rb->snprintf( bbuf, MAX_PATH, FONT_DIR "/%s",
|
rb->snprintf( bbuf, MAX_PATH, FONT_DIR "/%s",
|
||||||
de->d_name );
|
de->d_name );
|
||||||
|
@ -1203,9 +1204,11 @@ static void color_picker( int x, int y )
|
||||||
rb->lcd_set_foreground( save_buffer[ x+y*COLS ] );
|
rb->lcd_set_foreground( save_buffer[ x+y*COLS ] );
|
||||||
#define PSIZE 12
|
#define PSIZE 12
|
||||||
rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
|
rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
|
||||||
rb->lcd_drawrect( x<COLS-PSIZE ? x + 2 : x - PSIZE, y<ROWS-PSIZE ? y + 2: y - PSIZE, PSIZE - 2, PSIZE - 2 );
|
if( x >= COLS - PSIZE ) x -= PSIZE + 2;
|
||||||
|
if( y >= ROWS - PSIZE ) y -= PSIZE + 2;
|
||||||
|
rb->lcd_drawrect( x + 2, y + 2, PSIZE - 2, PSIZE - 2 );
|
||||||
rb->lcd_set_drawmode(DRMODE_SOLID);
|
rb->lcd_set_drawmode(DRMODE_SOLID);
|
||||||
rb->lcd_fillrect( x<COLS-PSIZE ? x+3 : x - PSIZE+1, y<ROWS-PSIZE ? y +3: y - PSIZE+1, PSIZE-4, PSIZE-4 );
|
rb->lcd_drawrect( x + 3, y + 3, PSIZE - 4, PSIZE - 4 );
|
||||||
#undef PSIZE
|
#undef PSIZE
|
||||||
rb->lcd_set_foreground( rp_colors[ drawcolor ] );
|
rb->lcd_set_foreground( rp_colors[ drawcolor ] );
|
||||||
}
|
}
|
||||||
|
@ -1415,7 +1418,7 @@ static void draw_rot_90_deg( int x1, int y1, int x2, int y2, int direction )
|
||||||
static void draw_paste_rectangle( int src_x1, int src_y1, int src_x2,
|
static void draw_paste_rectangle( int src_x1, int src_y1, int src_x2,
|
||||||
int src_y2, int x1, int y1, int mode )
|
int src_y2, int x1, int y1, int mode )
|
||||||
{
|
{
|
||||||
int i;
|
int i, width, height;
|
||||||
if( mode == SELECT_MENU_CUT )
|
if( mode == SELECT_MENU_CUT )
|
||||||
{
|
{
|
||||||
i = drawcolor;
|
i = drawcolor;
|
||||||
|
@ -1435,15 +1438,23 @@ static void draw_paste_rectangle( int src_x1, int src_y1, int src_x2,
|
||||||
src_y1 = src_y2;
|
src_y1 = src_y2;
|
||||||
src_y2 = i;
|
src_y2 = i;
|
||||||
}
|
}
|
||||||
|
width = src_x2 - src_x1 + 1;
|
||||||
|
height = src_y2 - src_y1 + 1;
|
||||||
|
/* clipping */
|
||||||
|
if( x1 + width > COLS )
|
||||||
|
width = COLS - x1;
|
||||||
|
if( y1 + height > ROWS )
|
||||||
|
height = ROWS - y1;
|
||||||
|
|
||||||
rb->lcd_bitmap_part( buffer.clipboard, src_x1, src_y1, COLS,
|
rb->lcd_bitmap_part( buffer.clipboard, src_x1, src_y1, COLS,
|
||||||
x1, y1, src_x2-src_x1+1, src_y2-src_y1+1 );
|
x1, y1, width, height );
|
||||||
if( !preview )
|
if( !preview )
|
||||||
{
|
{
|
||||||
for( i = 0; i <= src_y2 - src_y1; i++ )
|
for( i = 0; i < height; i++ )
|
||||||
{
|
{
|
||||||
rb->memcpy( save_buffer+(y1+i)*COLS+x1,
|
rb->memcpy( save_buffer+(y1+i)*COLS+x1,
|
||||||
buffer.clipboard+(src_y1+i)*COLS+src_x1,
|
buffer.clipboard+(src_y1+i)*COLS+src_x1,
|
||||||
(src_x2 - src_x1 + 1)*sizeof( fb_data ) );
|
width*sizeof( fb_data ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1787,20 +1798,18 @@ static void togglebg( void )
|
||||||
static void draw_rect_full( int x1, int y1, int x2, int y2 )
|
static void draw_rect_full( int x1, int y1, int x2, int y2 )
|
||||||
{
|
{
|
||||||
/* GRUIK */
|
/* GRUIK */
|
||||||
int x = x1;
|
int x;
|
||||||
togglebg();
|
togglebg();
|
||||||
if( x < x2 )
|
if( x1 > x2 )
|
||||||
{
|
{
|
||||||
do {
|
x = x1;
|
||||||
draw_line( x, y1, x, y2 );
|
x1 = x2;
|
||||||
} while( ++x <= x2 );
|
x2 = x;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
do {
|
|
||||||
draw_line( x, y1, x, y2 );
|
|
||||||
} while( --x >= x2 );
|
|
||||||
}
|
}
|
||||||
|
x = x1;
|
||||||
|
do {
|
||||||
|
draw_line( x, y1, x, y2 );
|
||||||
|
} while( ++x <= x2 );
|
||||||
togglebg();
|
togglebg();
|
||||||
draw_rect( x1, y1, x2, y2 );
|
draw_rect( x1, y1, x2, y2 );
|
||||||
}
|
}
|
||||||
|
@ -2474,6 +2483,7 @@ static void goto_menu(void)
|
||||||
{
|
{
|
||||||
rb->splashf( 1*HZ, "Error while loading %s",
|
rb->splashf( 1*HZ, "Error while loading %s",
|
||||||
filename );
|
filename );
|
||||||
|
clear_drawing();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -2491,8 +2501,7 @@ static void goto_menu(void)
|
||||||
rb->strcpy(filename,"/");
|
rb->strcpy(filename,"/");
|
||||||
if( !rb->kbd_input( filename, MAX_PATH ) )
|
if( !rb->kbd_input( filename, MAX_PATH ) )
|
||||||
{
|
{
|
||||||
if(rb->strlen(filename) <= 4 ||
|
if( !check_extention( filename, ".bmp" ) )
|
||||||
rb->strcasecmp(&filename[rb->strlen(filename)-4], ".bmp"))
|
|
||||||
rb->strcat(filename, ".bmp");
|
rb->strcat(filename, ".bmp");
|
||||||
save_bitmap( filename );
|
save_bitmap( filename );
|
||||||
rb->splashf( 1*HZ, "File saved (%s)", filename );
|
rb->splashf( 1*HZ, "File saved (%s)", filename );
|
||||||
|
@ -2932,7 +2941,8 @@ static int load_bitmap( const char *file )
|
||||||
{
|
{
|
||||||
struct bitmap bm;
|
struct bitmap bm;
|
||||||
bool ret;
|
bool ret;
|
||||||
int l;
|
int i, j;
|
||||||
|
fb_data color = rp_colors[ bgdrawcolor ];
|
||||||
|
|
||||||
bm.data = (char*)save_buffer;
|
bm.data = (char*)save_buffer;
|
||||||
ret = rb->read_bmp_file( file, &bm, ROWS*COLS*sizeof( fb_data ),
|
ret = rb->read_bmp_file( file, &bm, ROWS*COLS*sizeof( fb_data ),
|
||||||
|
@ -2941,18 +2951,15 @@ static int load_bitmap( const char *file )
|
||||||
if((bm.width > COLS ) || ( bm.height > ROWS ))
|
if((bm.width > COLS ) || ( bm.height > ROWS ))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for( l = bm.height-1; l > 0; l-- )
|
for( i = bm.height-1; i >= 0; i-- )
|
||||||
{
|
{
|
||||||
rb->memmove( save_buffer+l*COLS, save_buffer+l*bm.width,
|
rb->memmove( save_buffer+i*COLS, save_buffer+i*bm.width,
|
||||||
sizeof( fb_data )*bm.width );
|
sizeof( fb_data )*bm.width );
|
||||||
|
for( j = bm.width; j < COLS; j++ )
|
||||||
|
save_buffer[j+i*COLS] = color;
|
||||||
}
|
}
|
||||||
for( l = 0; l < bm.height; l++ )
|
for( i = bm.height*COLS; i < ROWS*COLS; i++ )
|
||||||
{
|
save_buffer[i] = color;
|
||||||
rb->memset( save_buffer+l*COLS+bm.width, rp_colors[ bgdrawcolor ],
|
|
||||||
sizeof( fb_data )*(COLS-bm.width) );
|
|
||||||
}
|
|
||||||
rb->memset( save_buffer+COLS*bm.height, rp_colors[ bgdrawcolor ],
|
|
||||||
sizeof( fb_data )*COLS*(ROWS-bm.height) );
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue