Change i2c config on e200. Seems to speed things up somewhat.
[kugel-rb.git] / apps / plugins / rockpaint.c
bloba15d7b11413e3725f4c876e75e9a1985586f8d83
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2006 Antoine Cellerier <dionoea -at- videolan -dot- org>
11 * Based on parts of rockpaint 0.45, Copyright (C) 2005 Eli Sherer
13 * All files in this archive are subject to the GNU General Public License.
14 * See the file COPYING in the source tree root for full license agreement.
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
19 ****************************************************************************/
21 /**
22 * TODO:
23 * - implement 2 layers with alpha colors
24 * - take brush width into account when drawing shapes
25 * - handle bigger than screen bitmaps
26 * - cache fonts when building the font preview (else it only works well on simulators because they have "fast" disk read)
29 #include "plugin.h"
30 #include "errno.h"
31 #include "lib/bmp.h"
32 #include "lib/rgb_hsv.h"
34 PLUGIN_HEADER
36 /***********************************************************************
37 * Buttons
38 ***********************************************************************/
40 #if CONFIG_KEYPAD == IRIVER_H300_PAD
41 #define ROCKPAINT_QUIT BUTTON_OFF
42 #define ROCKPAINT_DRAW BUTTON_SELECT
43 #define ROCKPAINT_MENU BUTTON_ON
44 #define ROCKPAINT_TOOLBAR BUTTON_REC
45 #define ROCKPAINT_TOOLBAR2 BUTTON_MODE
46 #define ROCKPAINT_UP BUTTON_UP
47 #define ROCKPAINT_DOWN BUTTON_DOWN
48 #define ROCKPAINT_LEFT BUTTON_LEFT
49 #define ROCKPAINT_RIGHT BUTTON_RIGHT
51 #elif ( CONFIG_KEYPAD == IPOD_4G_PAD ) || ( CONFIG_KEYPAD == IPOD_3G_PAD )
52 #define ROCKPAINT_QUIT ( ~BUTTON_MAIN )
53 #define ROCKPAINT_DRAW BUTTON_SELECT
54 #define ROCKPAINT_MENU ( BUTTON_SELECT | BUTTON_MENU )
55 #define ROCKPAINT_TOOLBAR ( BUTTON_MENU | BUTTON_LEFT )
56 #define ROCKPAINT_TOOLBAR2 ( BUTTON_MENU | BUTTON_RIGHT )
57 #define ROCKPAINT_UP BUTTON_MENU
58 #define ROCKPAINT_DOWN BUTTON_PLAY
59 #define ROCKPAINT_LEFT BUTTON_LEFT
60 #define ROCKPAINT_RIGHT BUTTON_RIGHT
62 #elif ( CONFIG_KEYPAD == IAUDIO_X5M5_PAD )
63 #define ROCKPAINT_QUIT BUTTON_POWER
64 #define ROCKPAINT_DRAW BUTTON_SELECT
65 #define ROCKPAINT_MENU BUTTON_PLAY
66 #define ROCKPAINT_TOOLBAR BUTTON_REC
67 #define ROCKPAINT_TOOLBAR2 ( BUTTON_REC | BUTTON_LEFT )
68 #define ROCKPAINT_UP BUTTON_UP
69 #define ROCKPAINT_DOWN BUTTON_DOWN
70 #define ROCKPAINT_LEFT BUTTON_LEFT
71 #define ROCKPAINT_RIGHT BUTTON_RIGHT
73 #elif CONFIG_KEYPAD == GIGABEAT_PAD
74 #define ROCKPAINT_QUIT BUTTON_A
75 #define ROCKPAINT_DRAW BUTTON_SELECT
76 #define ROCKPAINT_MENU BUTTON_MENU
77 #define ROCKPAINT_TOOLBAR BUTTON_POWER
78 #define ROCKPAINT_TOOLBAR2 ( BUTTON_POWER | BUTTON_LEFT )
79 #define ROCKPAINT_UP BUTTON_UP
80 #define ROCKPAINT_DOWN BUTTON_DOWN
81 #define ROCKPAINT_LEFT BUTTON_LEFT
82 #define ROCKPAINT_RIGHT BUTTON_RIGHT
84 #elif CONFIG_KEYPAD == SANSA_E200_PAD
85 #define ROCKPAINT_QUIT BUTTON_POWER
86 #define ROCKPAINT_DRAW BUTTON_SELECT
87 #define ROCKPAINT_MENU ( BUTTON_SELECT | BUTTON_POWER )
88 #define ROCKPAINT_TOOLBAR BUTTON_REC
89 #define ROCKPAINT_TOOLBAR2 ( BUTTON_REC | BUTTON_LEFT )
90 #define ROCKPAINT_UP BUTTON_UP
91 #define ROCKPAINT_DOWN BUTTON_DOWN
92 #define ROCKPAINT_LEFT BUTTON_LEFT
93 #define ROCKPAINT_RIGHT BUTTON_RIGHT
95 #elif ( CONFIG_KEYPAD == IRIVER_H10_PAD )
96 #define ROCKPAINT_QUIT BUTTON_POWER
97 #define ROCKPAINT_DRAW BUTTON_FF
98 #define ROCKPAINT_MENU BUTTON_PLAY
99 #define ROCKPAINT_TOOLBAR BUTTON_REW
100 #define ROCKPAINT_TOOLBAR2 ( BUTTON_REW | BUTTON_LEFT )
101 #define ROCKPAINT_UP BUTTON_SCROLL_UP
102 #define ROCKPAINT_DOWN BUTTON_SCROLL_DOWN
103 #define ROCKPAINT_LEFT BUTTON_LEFT
104 #define ROCKPAINT_RIGHT BUTTON_RIGHT
106 #else
107 #error "Please define keys for this keypad"
108 #endif
110 /***********************************************************************
111 * Palette Default Colors
112 ***********************************************************************/
113 #define COLOR_BLACK LCD_RGBPACK(0,0,0)
114 #define COLOR_WHITE LCD_RGBPACK(255,255,255)
115 #define COLOR_DARKGRAY LCD_RGBPACK(128,128,128)
116 #define COLOR_LIGHTGRAY LCD_RGBPACK(192,192,192)
117 #define COLOR_RED LCD_RGBPACK(128,0,0)
118 #define COLOR_LIGHTRED LCD_RGBPACK(255,0,0)
119 #define COLOR_DARKYELLOW LCD_RGBPACK(128,128,0)
120 #define COLOR_YELLOW LCD_RGBPACK(255,255,0)
121 #define COLOR_GREEN LCD_RGBPACK(0,128,0)
122 #define COLOR_LIGHTGREN LCD_RGBPACK(0,255,0)
123 #define COLOR_CYAN LCD_RGBPACK(0,128,128)
124 #define COLOR_LIGHTCYAN LCD_RGBPACK(0,255,255)
125 #define COLOR_BLUE LCD_RGBPACK(0,0,128)
126 #define COLOR_LIGHTBLUE LCD_RGBPACK(0,0,255)
127 #define COLOR_PURPLE LCD_RGBPACK(128,0,128)
128 #define COLOR_PINK LCD_RGBPACK(255,0,255)
129 #define COLOR_BROWN LCD_RGBPACK(128,64,0)
130 #define COLOR_LIGHTBROWN LCD_RGBPACK(255,128,64)
132 #define SPLASH_SCREEN PLUGIN_DIR "/rockpaint/splash.bmp"
133 #define ROCKPAINT_TITLE_FONT 2
135 /***********************************************************************
136 * Program Colors
137 ***********************************************************************/
138 #define ROCKPAINT_PALETTE LCD_RGBPACK(0,64,128)
139 #define ROCKPAINT_SELECTED LCD_RGBPACK(128,192,255)
141 #define ROWS LCD_HEIGHT
142 #define COLS LCD_WIDTH
145 * Toolbar positioning stuff ... don't read this unless you really need to
147 * TB Toolbar
148 * SP Separator
149 * SC Selected Color
150 * PL Palette
151 * TL Tools
154 /* Separator sizes */
155 #define TB_SP_MARGIN 3
156 #define TB_SP_WIDTH (2+2*TB_SP_MARGIN)
158 /* Selected color sizes */
159 #define TB_SC_SIZE 12
161 /* Palette sizes */
162 #define TB_PL_COLOR_SIZE 7
163 #define TB_PL_COLOR_SPACING 2
164 #define TB_PL_WIDTH ( 9 * TB_PL_COLOR_SIZE + 8 * TB_PL_COLOR_SPACING )
165 #define TB_PL_HEIGHT ( TB_PL_COLOR_SIZE * 2 + TB_PL_COLOR_SPACING )
167 /* Tools sizes */
168 #define TB_TL_SIZE 8
169 #define TB_TL_SPACING 2
170 #define TB_TL_WIDTH ( 7 * ( TB_TL_SIZE + TB_TL_SPACING ) - TB_TL_SPACING )
171 #define TB_TL_HEIGHT ( 2 * TB_TL_SIZE + TB_TL_SPACING )
173 /* Menu button size ... gruik */
174 #define TB_MENU_MIN_WIDTH 30
176 /* Selected colors position */
177 #define TB_SC_FG_TOP 2
178 #define TB_SC_FG_LEFT 2
179 #define TB_SC_BG_TOP (TB_SC_FG_TOP+TB_PL_COLOR_SIZE*2+TB_PL_COLOR_SPACING-TB_SC_SIZE)
180 #define TB_SC_BG_LEFT (TB_SC_FG_LEFT+TB_PL_COLOR_SIZE*2+TB_PL_COLOR_SPACING-TB_SC_SIZE)
182 /* Palette position */
183 #define TB_PL_TOP TB_SC_FG_TOP
184 #define TB_PL_LEFT (TB_SC_BG_LEFT + TB_SC_SIZE + TB_PL_COLOR_SPACING)
186 /* Tools position */
187 #define TB_TL_TOP TB_SC_FG_TOP
188 #define TB_TL_LEFT ( TB_PL_LEFT + TB_PL_WIDTH-1 + TB_SP_WIDTH )
190 #if TB_TL_LEFT + TB_TL_WIDTH + TB_MENU_MIN_WIDTH >= LCD_WIDTH
191 #undef TB_TL_TOP
192 #undef TB_TL_LEFT
193 #define TB_TL_TOP ( TB_PL_TOP + TB_PL_HEIGHT + 4 )
194 #define TB_TL_LEFT TB_SC_FG_LEFT
195 #endif
197 /* Menu button position */
198 #define TB_MENU_TOP ( TB_TL_TOP + (TB_TL_HEIGHT-8)/2 )
199 #define TB_MENU_LEFT ( TB_TL_LEFT + TB_TL_WIDTH-1 + TB_SP_WIDTH )
201 #define TB_HEIGHT ( TB_TL_TOP + TB_TL_HEIGHT + 1 )
204 static void draw_pixel(int x,int y);
205 static void draw_line( int x1, int y1, int x2, int y2 );
206 static void draw_rect( int x1, int y1, int x2, int y2 );
207 static void draw_toolbars(bool update);
208 static void inv_cursor(bool update);
209 static void restore_screen(void);
210 static void clear_drawing(void);
211 static void goto_menu(void);
212 static int load_bitmap( char *filename );
213 static int save_bitmap( char *filename );
214 static void draw_rect_full( int x1, int y1, int x2, int y2 );
215 extern int errno;
217 /***********************************************************************
218 * Global variables
219 ***********************************************************************/
221 #if !defined(SIMULATOR) || defined(__MINGW32__) || defined(__CYGWIN__)
222 int errno;
223 #endif
225 static struct plugin_api* rb;
227 static int drawcolor=0; /* Current color (in palette) */
228 static int bgdrawcolor=9; /* Current background color (in palette) */
229 bool isbg = false; /* gruik ugly hack alert */
231 static int preview=false; /* Is preview mode on ? */
233 /* TODO: clean this up */
234 static int x=0, y=0; /* cursor position */
235 static int prev_x=-1, prev_y=-1; /* previous saved cursor position */
236 static int prev_x2=-1, prev_y2=-1;
237 static int prev_x3=-1, prev_y3=-1;
238 static int tool_mode=-1;
241 static int bsize=1; /* brush size */
242 static int bspeed=1; /* brush speed */
244 enum Tools { Brush = 0, /* Regular brush */
245 Fill = 1, /* Fill a shape with current color */
246 SelectRectangle = 2,
247 ColorPicker = 3, /* Pick a color */
248 Line = 4, /* Draw a line between two points */
249 Unused = 5, /* THIS IS UNUSED ... */
250 Curve = 6,
251 Text = 7,
252 Rectangle = 8, /* Draw a rectangle */
253 RectangleFull = 9,
254 Oval = 10, /* Draw an oval */
255 OvalFull = 11,
256 LinearGradient = 12,
257 RadialGradient = 13
260 enum Tools tool = Brush;
262 static bool quit=false;
263 static int gridsize=0;
265 static fb_data rp_colors[18] =
267 COLOR_BLACK, COLOR_DARKGRAY, COLOR_RED, COLOR_DARKYELLOW,
268 COLOR_GREEN, COLOR_CYAN, COLOR_BLUE, COLOR_PURPLE, COLOR_BROWN,
269 COLOR_WHITE, COLOR_LIGHTGRAY, COLOR_LIGHTRED, COLOR_YELLOW,
270 COLOR_LIGHTGREN, COLOR_LIGHTCYAN, COLOR_LIGHTBLUE, COLOR_PINK,
271 COLOR_LIGHTBROWN
274 static fb_data save_buffer[ ROWS*COLS ];
276 extern fb_data rockpaint[];
277 extern fb_data rockpaint_hsvrgb[];
279 /* Maximum string size allowed for the text tool */
280 #define MAX_TEXT 255
282 static union
284 /* Used by fill and gradient algorithms */
285 struct
287 short x;
288 short y;
289 } coord[ ROWS*COLS ];
291 /* Used by bezier curve algorithms */
292 struct
294 short x1, y1;
295 short x2, y2;
296 short x3, y3;
297 short x4, y4;
298 short depth;
299 } bezier[ (ROWS*COLS)/5 ]; /* We have 4.5 times more data per struct
300 * than coord ... so we divide to take
301 * less memory. */
303 /* Used to cut/copy/paste data */
304 fb_data clipboard[ ROWS*COLS ];
306 /* Used for text mode */
307 struct
309 char text[MAX_TEXT+1];
310 char font[MAX_PATH+1];
311 char old_font[MAX_PATH+1];
312 int fh_buf[30];
313 int fw_buf[30];
314 char fontname_buf[30][MAX_PATH];
315 } text;
316 } buffer;
318 /* Current filename */
319 static char filename[MAX_PATH+1];
321 /* Font preview buffer */
322 //#define FONT_PREVIEW_WIDTH ((LCD_WIDTH-30)/8)
323 //#define FONT_PREVIEW_HEIGHT 1000
324 //static unsigned char fontpreview[FONT_PREVIEW_WIDTH*FONT_PREVIEW_HEIGHT];
326 /***********************************************************************
327 * Offscreen buffer/Text/Fonts handling
329 * Parts of code taken from firmware/drivers/lcd-16bit.c
330 ***********************************************************************/
331 static void buffer_mono_bitmap_part(
332 fb_data *buf, int buf_width, int buf_height,
333 const unsigned char *src, int src_x, int src_y,
334 int stride, int x, int y, int width, int height )
335 /* this function only draws the foreground part of the bitmap */
337 const unsigned char *src_end;
338 fb_data *dst, *dst_end;
339 unsigned fgcolor = rb->lcd_get_foreground();
341 /* nothing to draw? */
342 if( ( width <= 0 ) || ( height <= 0 ) || ( x >= buf_width )
343 || ( y >= buf_height ) || ( x + width <= 0 ) || ( y + height <= 0 ) )
344 return;
346 /* clipping */
347 if( x < 0 )
349 width += x;
350 src_x -= x;
351 x = 0;
353 if( y < 0 )
355 height += y;
356 src_y -= y;
357 y = 0;
359 if( x + width > buf_width )
360 width = buf_width - x;
361 if( y + height > buf_height )
362 height = buf_height - y;
364 src += stride * (src_y >> 3) + src_x; /* move starting point */
365 src_y &= 7;
366 src_end = src + width;
368 dst = buf + y*buf_width + x;
372 const unsigned char *src_col = src++;
373 unsigned data = *src_col >> src_y;
374 fb_data *dst_col = dst++;
375 int numbits = 8 - src_y;
377 dst_end = dst_col + height * buf_width;
380 if( data & 0x01 )
381 *dst_col = fgcolor; /* FIXME ? */
383 dst_col += buf_width;
385 data >>= 1;
386 if( --numbits == 0 )
388 src_col += stride;
389 data = *src_col;
390 numbits = 8;
392 } while( dst_col < dst_end );
393 } while( src < src_end );
396 static void buffer_putsxyofs( fb_data *buf, int buf_width, int buf_height,
397 int x, int y, int ofs, const unsigned char *str )
399 unsigned short ch;
400 unsigned short *ucs;
402 struct font *pf = rb->font_get( FONT_UI );
403 if( !pf ) pf = rb->font_get( FONT_SYSFIXED );
405 ucs = rb->bidi_l2v( str, 1 );
407 while( (ch = *ucs++) != 0 && x < buf_width )
409 int width;
410 const unsigned char *bits;
412 /* get proportional width and glyph bits */
413 width = rb->font_get_width( pf, ch );
415 if( ofs > width )
417 ofs -= width;
418 continue;
421 bits = rb->font_get_bits( pf, ch );
423 buffer_mono_bitmap_part( buf, buf_width, buf_height, bits, ofs, 0, width, x, y, width - ofs, pf->height);
425 x += width - ofs;
426 ofs = 0;
430 /***********************************************************************
431 * Menu handling
432 ***********************************************************************/
433 struct menu_items
435 int value;
436 char label[16]; /* GRUIK ? */
439 #define MENU_ESC -1242
440 enum {
441 /* Generic menu items */
442 MENU_END = -42, MENU_TITLE = -12,
443 /* Main menu */
444 MAIN_MENU_RESUME,
445 MAIN_MENU_NEW, MAIN_MENU_LOAD, MAIN_MENU_SAVE,
446 MAIN_MENU_BRUSH_SIZE, MAIN_MENU_BRUSH_SPEED, MAIN_MENU_COLOR,
447 MAIN_MENU_GRID_SIZE,
448 MAIN_MENU_EXIT,
449 /* Select action menu */
450 SELECT_MENU_CUT, SELECT_MENU_COPY, SELECT_MENU_INVERT,
451 SELECT_MENU_HFLIP, SELECT_MENU_VFLIP, SELECT_MENU_ROTATE90,
452 SELECT_MENU_ROTATE180, SELECT_MENU_ROTATE270,
453 SELECT_MENU_CANCEL,
454 /* Text menu */
455 TEXT_MENU_TEXT, TEXT_MENU_FONT,
456 TEXT_MENU_PREVIEW, TEXT_MENU_APPLY, TEXT_MENU_CANCEL,
459 static struct menu_items main_menu[]=
460 { { MENU_TITLE, "RockPaint" },
461 { MAIN_MENU_RESUME, "Resume" },
462 { MAIN_MENU_NEW, "New" },
463 { MAIN_MENU_LOAD, "Load" },
464 { MAIN_MENU_SAVE, "Save" },
465 { MAIN_MENU_BRUSH_SIZE, "Brush Size" },
466 { MAIN_MENU_BRUSH_SPEED, "Brush Speed" },
467 { MAIN_MENU_COLOR, "Choose Color" },
468 { MAIN_MENU_GRID_SIZE, "Grid Size" },
469 { MAIN_MENU_EXIT, "Exit" },
470 { MENU_END, "" } };
472 static struct menu_items size_menu[] =
473 { { MENU_TITLE, "Choose Size" },
474 { 1, "1x" },
475 { 2, "2x" },
476 { 4, "4x" },
477 { 8, "8x" },
478 { MENU_END, "" } };
480 static struct menu_items speed_menu[] =
481 { { MENU_TITLE, "Choose Speed" },
482 { 1, "1x" },
483 { 2, "2x" },
484 { 4, "4x" },
485 { MENU_END, "" } };
487 static struct menu_items gridsize_menu[] =
488 { { MENU_TITLE, "Grid Size" },
489 { 0, "No grid" },
490 { 5, "5px" },
491 { 10, "10px" },
492 { 20, "20px" },
493 { MENU_END, "" } };
495 static struct menu_items select_menu[] =
496 { { MENU_TITLE, "Select..." },
497 { SELECT_MENU_CUT, "Cut" },
498 { SELECT_MENU_COPY, "Copy" },
499 { SELECT_MENU_INVERT, "Invert" },
500 { SELECT_MENU_HFLIP, "Horizontal flip" },
501 { SELECT_MENU_VFLIP, "Vertical flip" },
502 // { SELECT_MENU_ROTATE90, "Rotate 90°" },
503 { SELECT_MENU_ROTATE180, "Rotate 180°" },
504 // { SELECT_MENU_ROTATE270, "Rotate 270°" },
505 { SELECT_MENU_CANCEL, "Cancel" },
506 { MENU_END, "" } };
508 static struct menu_items text_menu[] =
509 { { MENU_TITLE, "Text" },
510 { TEXT_MENU_TEXT, "Set text" },
511 { TEXT_MENU_FONT, "Change font" },
512 { TEXT_MENU_PREVIEW, "Preview" },
513 { TEXT_MENU_APPLY, "Apply" },
514 { TEXT_MENU_CANCEL, "Cancel" },
515 { MENU_END, "" } };
517 static int draw_window( int height, int width,
518 int *top, int *left,
519 const char *title )
521 int fh;
522 rb->lcd_getstringsize( title, NULL, &fh );
523 fh++;
525 const int _top = ( LCD_HEIGHT - height ) / 2;
526 const int _left = ( LCD_WIDTH - width ) / 2;
527 if( top ) *top = _top;
528 if( left ) *left = _left;
529 rb->lcd_set_background(COLOR_BLUE);
530 rb->lcd_set_foreground(COLOR_LIGHTGRAY);
531 rb->lcd_fillrect( _left, _top, width, height );
532 rb->lcd_set_foreground(COLOR_BLUE);
533 rb->lcd_fillrect( _left, _top, width, fh+4 );
534 rb->lcd_set_foreground(COLOR_WHITE);
535 rb->lcd_putsxy( _left+2, _top+2, title );
536 rb->lcd_set_foreground(COLOR_BLACK);
537 rb->lcd_drawrect( _left, _top, width, height );
538 return _top+fh+4;
541 static int menu_display( struct menu_items menu[], int prev_value )
543 int i,
544 fh, /* font height */
545 width, height,
546 a, b,
547 selection=1,
548 menu_length,
549 top, left;
550 int scroll = 0, onscreen = 0;
552 rb->lcd_getstringsize( menu[0].label, &width, &fh );
553 for( i=1; menu[i].value != MENU_END; i++ )
555 if( prev_value == menu[i].value )
557 selection = i;
559 rb->lcd_getstringsize( menu[i].label, &a, &b );
560 if( a > width ) width = a;
561 if( b > fh ) fh = b;
563 menu_length = i;
564 fh++;
565 width += 10;
567 height = menu_length * fh + 4 + 2 + 2;
568 if( height >= LCD_HEIGHT )
570 scroll = 1;
571 onscreen = ( LCD_HEIGHT - 4 - 2 - 2 )/fh;
572 height = onscreen * fh + 4 + 2 + 2;
573 width += 5;
575 else
577 onscreen = menu_length;
580 draw_window( height, width, &top, &left, menu[0].label );
582 while( 1 )
584 for( i = (scroll == 0 ? 1 : scroll);
585 i < (scroll ? scroll + onscreen - 1:onscreen);
586 i++ )
588 if( i == selection )
590 rb->lcd_set_foreground( COLOR_WHITE );
591 rb->lcd_set_background( COLOR_BLUE );
593 else
595 rb->lcd_set_foreground( COLOR_BLACK );
596 rb->lcd_set_background( COLOR_LIGHTGRAY );
598 rb->lcd_putsxy( left+2,
599 top+6+fh*(i-(scroll == 0 ? 0 : scroll-1 )),
600 menu[i].label );
602 if( scroll )
604 int scroll_height = ((height-fh-4-2)*onscreen)/menu_length;
605 rb->lcd_set_foreground( COLOR_BLACK );
606 rb->lcd_vline( left+width-5, top+fh+4, top+height-2 );
607 rb->lcd_fillrect( left+width-4,
608 top+fh+4+((height-4-2-fh-scroll_height)*(scroll-1))/(menu_length-onscreen),
609 3, scroll_height );
611 rb->lcd_update();
613 switch( rb->button_get(true) )
615 case ROCKPAINT_UP:
616 case ROCKPAINT_UP|BUTTON_REPEAT:
617 selection = (selection + menu_length-1)%menu_length;
618 if( !selection ) selection = menu_length-1;
619 break;
621 case ROCKPAINT_DOWN:
622 case ROCKPAINT_DOWN|BUTTON_REPEAT:
623 selection = (selection + 1)%menu_length;
624 if( !selection ) selection++;
625 break;
627 case ROCKPAINT_LEFT:
628 restore_screen();
629 return MENU_ESC;
631 case ROCKPAINT_RIGHT:
632 case ROCKPAINT_DRAW:
633 restore_screen();
634 return menu[selection].value;
636 if( scroll )
638 if( selection < scroll )
640 scroll = selection;
641 draw_window( height, width, NULL, NULL, menu[0].label );
643 if( selection >= scroll + onscreen - 1 )
645 scroll++;
646 draw_window( height, width, NULL, NULL, menu[0].label );
652 /***********************************************************************
653 * File browser
654 ***********************************************************************/
656 char bbuf[MAX_PATH+1]; /* used by file and font browsers */
657 char bbuf_s[MAX_PATH+1]; /* used by file and font browsers */
659 static bool browse( char *dst, int dst_size, const char *start )
661 #define WIDTH ( LCD_WIDTH - 20 )
662 #define HEIGHT ( LCD_HEIGHT - 20 )
663 #define LINE_SPACE 2
664 int top, top_inside, left;
666 DIR *d;
667 struct dirent *de;
668 int fvi = 0; /* first visible item */
669 int lvi = 0; /* last visible item */
670 int si = 0; /* selected item */
671 int li = 0; /* last item */
672 int i;
674 int fh;
675 char *a;
677 rb->lcd_getstringsize( "Ap", NULL, &fh );
679 rb->strcpy( bbuf, start );
680 a = bbuf+rb->strlen(bbuf)-1;
681 if( *a != '/' )
683 a[1] = '/';
684 a[2] = '\0';
687 while( 1 )
689 d = rb->PREFIX(opendir)( bbuf );
690 if( !d )
693 if( errno == ENOTDIR )
695 /* this is a file */
696 bbuf[rb->strlen(bbuf)-1] = '\0';
697 rb->strncpy( dst, bbuf, dst_size );
698 return true;
700 else if( errno == EACCES || errno == ENOENT )
702 bbuf[0] = '/'; bbuf[1] = '\0';
703 d = rb->PREFIX(opendir)( "/" );
705 else
707 return false;
710 top_inside = draw_window( HEIGHT, WIDTH, &top, &left, bbuf );
711 i = 0;
712 li = -1;
713 while( i < fvi )
715 rb->PREFIX(readdir)( d );
716 i++;
718 while( top_inside+(i-fvi)*(fh+LINE_SPACE) < HEIGHT )
720 de = rb->PREFIX(readdir)( d );
721 if( !de )
723 li = i-1;
724 break;
726 rb->lcd_set_foreground((si==i?COLOR_WHITE:COLOR_BLACK));
727 rb->lcd_set_background((si==i?COLOR_BLUE:COLOR_LIGHTGRAY));
728 rb->lcd_putsxy( left+10,
729 top_inside+(i-fvi)*(fh+LINE_SPACE),
730 de->d_name );
731 if( si == i )
732 rb->strcpy( bbuf_s, de->d_name );
733 i++;
735 lvi = i-1;
736 if( li == -1 )
738 if( !rb->PREFIX(readdir)( d ) )
740 li = lvi;
743 rb->PREFIX(closedir)( d );
745 rb->lcd_update();
747 switch( rb->button_get(true) )
749 case ROCKPAINT_UP:
750 case ROCKPAINT_UP|BUTTON_REPEAT:
751 if( si > 0 )
753 si--;
754 if( si<fvi )
756 fvi--;
759 break;
761 case ROCKPAINT_DOWN:
762 case ROCKPAINT_DOWN|BUTTON_REPEAT:
763 if( li == -1 || si < li )
765 si++;
766 if( si>lvi )
768 fvi++;
771 break;
773 case ROCKPAINT_LEFT:
774 if( bbuf[0] == '/' && !bbuf[1] ) return false;
775 bbuf_s[0] = '.';
776 bbuf_s[1] = '.';
777 bbuf_s[2] = '\0';
778 case ROCKPAINT_RIGHT:
779 case ROCKPAINT_DRAW:
780 if( *bbuf_s == '.' && !bbuf_s[1] ) break;
781 a = bbuf;
782 while( *a ) a++;
783 if( *bbuf_s == '.' && bbuf_s[1] == '.' && !bbuf_s[2] )
785 a--;
786 if( a == bbuf ) break;
787 if( *a == '/' ) a--;
788 while( *a != '/' ) a--;
789 *++a = '\0';
790 break;
792 rb->strcpy( a, bbuf_s );
793 while( *a ) a++;
794 *a++ = '/';
795 *a = '\0';
796 fvi = si = 0;
797 break;
801 #undef WIDTH
802 #undef HEIGHT
803 #undef LINE_SPACE
806 /***********************************************************************
807 * Font browser
809 * FIXME: This still needs some work ... it currently only works fine
810 * on the simulators, disk spins too much on real targets -> rendered
811 * font buffer needed.
812 ***********************************************************************/
813 static bool browse_fonts( char *dst, int dst_size )
815 char old_font[MAX_PATH];
816 #define WIDTH ( LCD_WIDTH - 20 )
817 #define HEIGHT ( LCD_HEIGHT - 20 )
818 #define LINE_SPACE 2
819 int top, top_inside = 0, left;
821 DIR *d;
822 struct dirent *de;
823 int fvi = 0; /* first visible item */
824 int lvi = 0; /* last visible item */
825 int si = 0; /* selected item */
826 int osi = 0; /* old selected item */
827 int li = 0; /* last item */
828 int nvih = 0; /* next visible item height */
829 int i;
830 int b_need_redraw = 1; /* Do we need to redraw ? */
832 int cp = 0; /* current position */
833 int fh; /* font height */
835 #define fh_buf buffer.text.fh_buf /* 30 might not be enough ... */
836 #define fw_buf buffer.text.fw_buf
837 int fw;
838 #define fontname_buf buffer.text.fontname_buf
840 rb->snprintf( old_font, MAX_PATH,
841 FONT_DIR "/%s.fnt",
842 rb->global_settings->font_file );
844 while( 1 )
846 if( !b_need_redraw )
848 /* we don't need to redraw ... but we need to unselect
849 * the previously selected item */
850 cp = top_inside + LINE_SPACE;
851 for( i = 0; i+fvi < osi; i++ )
853 cp += fh_buf[i] + LINE_SPACE;
855 rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
856 rb->lcd_fillrect( left+10, cp, fw_buf[i], fh_buf[i] );
857 rb->lcd_set_drawmode(DRMODE_SOLID);
860 if( b_need_redraw )
862 b_need_redraw = 0;
864 d = rb->PREFIX(opendir)( FONT_DIR "/" );
865 if( !d )
867 return false;
869 top_inside = draw_window( HEIGHT, WIDTH, &top, &left, "Fonts" );
870 i = 0;
871 li = -1;
872 while( i < fvi )
874 rb->PREFIX(readdir)( d );
875 i++;
877 cp = top_inside+LINE_SPACE;
879 rb->lcd_set_foreground(COLOR_BLACK);
880 rb->lcd_set_background(COLOR_LIGHTGRAY);
882 while( cp < top+HEIGHT )
884 de = rb->PREFIX(readdir)( d );
885 if( !de )
887 li = i-1;
888 break;
890 if( rb->strlen( de->d_name ) < 4
891 || rb->strcmp( de->d_name + rb->strlen( de->d_name ) - 4,
892 ".fnt" ) )
893 continue;
894 rb->snprintf( bbuf, MAX_PATH, FONT_DIR "/%s",
895 de->d_name );
896 rb->font_load( bbuf );
897 rb->font_getstringsize( de->d_name, &fw, &fh, FONT_UI );
898 if( nvih > 0 )
900 nvih -= fh;
901 fvi++;
902 if( nvih < 0 ) nvih = 0;
903 i++;
904 continue;
906 if( cp + fh >= top+HEIGHT )
908 nvih = fh;
909 break;
911 rb->lcd_putsxy( left+10, cp, de->d_name );
912 fh_buf[i-fvi] = fh;
913 fw_buf[i-fvi] = fw;
914 cp += fh + LINE_SPACE;
915 rb->strcpy( fontname_buf[i-fvi], bbuf );
916 i++;
918 lvi = i-1;
919 if( li == -1 )
921 if( !(de = rb->PREFIX(readdir)( d ) ) )
923 li = lvi;
925 else if( !nvih && !rb->strlen( de->d_name ) < 4
926 && !rb->strcmp( de->d_name + rb->strlen( de->d_name ) - 4,
927 ".fnt" ) )
929 rb->snprintf( bbuf, MAX_PATH, FONT_DIR "/%s",
930 de->d_name );
931 rb->font_load( bbuf );
932 rb->font_getstringsize( de->d_name, NULL, &fh, FONT_UI );
933 nvih = fh;
936 rb->font_load( old_font );
937 rb->PREFIX(closedir)( d );
940 rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
941 cp = top_inside + LINE_SPACE;
942 for( i = 0; i+fvi < si; i++ )
944 cp += fh_buf[i] + LINE_SPACE;
946 rb->lcd_fillrect( left+10, cp, fw_buf[i], fh_buf[i] );
947 rb->lcd_set_drawmode(DRMODE_SOLID);
949 rb->lcd_update_rect( left, top, WIDTH, HEIGHT );
951 osi = si;
952 i = fvi;
953 switch( rb->button_get(true) )
955 case ROCKPAINT_UP:
956 case ROCKPAINT_UP|BUTTON_REPEAT:
957 if( si > 0 )
959 si--;
960 if( si<fvi )
962 fvi = si;
965 break;
967 case ROCKPAINT_DOWN:
968 case ROCKPAINT_DOWN|BUTTON_REPEAT:
969 if( li == -1 || si < li )
971 si++;
973 break;
975 case ROCKPAINT_LEFT:
976 return false;
978 case ROCKPAINT_RIGHT:
979 case ROCKPAINT_DRAW:
980 rb->snprintf( dst, dst_size, "%s", fontname_buf[si-fvi] );
981 return true;
984 if( i != fvi || si > lvi )
986 b_need_redraw = 1;
989 if( si<=lvi )
991 nvih = 0;
994 #undef fh_buf
995 #undef fw_buf
996 #undef fontname_buf
997 #undef WIDTH
998 #undef HEIGHT
999 #undef LINE_SPACE
1002 /***********************************************************************
1003 * HSVRGB Color chooser
1004 ***********************************************************************/
1005 static unsigned int color_chooser( unsigned int color )
1007 int red = RGB_UNPACK_RED( color );
1008 int green = RGB_UNPACK_GREEN( color );
1009 int blue = RGB_UNPACK_BLUE( color );
1010 int hue, saturation, value;
1011 int r, g, b; /* temp variables */
1012 int i, top, left;
1014 enum BaseColor { Hue = 0, Saturation = 1, Value = 2,
1015 Red = 3, Green = 4, Blue = 5 };
1016 enum BaseColor current = Red;
1017 bool has_changed;
1019 char str[6] = "";
1021 restore_screen();
1023 rgb2hsv( red, green, blue, &hue, &saturation, &value );
1025 while( 1 )
1027 has_changed = false;
1028 color = LCD_RGBPACK( red, green, blue );
1030 #define HEIGHT ( 100 )
1031 #define WIDTH ( 150 )
1033 top = draw_window( HEIGHT, WIDTH, NULL, &left, "Color chooser" );
1034 top -= 15;
1036 for( i=0; i<100; i++ )
1038 hsv2rgb( i*36, saturation, value, &r, &g, &b );
1039 rb->lcd_set_foreground( LCD_RGBPACK( r, g, b ) );
1040 rb->lcd_vline( left+15+i, top+20, top+27 );
1041 hsv2rgb( hue, i*255/100, value, &r, &g, &b );
1042 rb->lcd_set_foreground( LCD_RGBPACK( r, g, b ) );
1043 rb->lcd_vline( left+15+i, top+30, top+37 );
1044 hsv2rgb( hue, saturation, i*255/100, &r, &g, &b );
1045 rb->lcd_set_foreground( LCD_RGBPACK( r, g, b ) );
1046 rb->lcd_vline( left+15+i, top+40, top+47 );
1047 rb->lcd_set_foreground( LCD_RGBPACK( i*255/100, green, blue ) );
1048 rb->lcd_vline( left+15+i, top+50, top+57 );
1049 rb->lcd_set_foreground( LCD_RGBPACK( red, i*255/100, blue ) );
1050 rb->lcd_vline( left+15+i, top+60, top+67 );
1051 rb->lcd_set_foreground( LCD_RGBPACK( red, green, i*255/100 ) );
1052 rb->lcd_vline( left+15+i, top+70, top+77 );
1055 rb->lcd_set_foreground(COLOR_BLACK);
1056 #define POSITION( a, i ) \
1057 rb->lcd_drawpixel( left+14+i, top + 19 + a ); \
1058 rb->lcd_drawpixel( left+16+i, top + 19 + a ); \
1059 rb->lcd_drawpixel( left+14+i, top + 28 + a ); \
1060 rb->lcd_drawpixel( left+16+i, top + 28 + a );
1061 POSITION( 0, hue/36 );
1062 POSITION( 10, saturation*99/255 );
1063 POSITION( 20, value*99/255 );
1064 POSITION( 30, red*99/255 );
1065 POSITION( 40, green*99/255 );
1066 POSITION( 50, blue*99/255 );
1067 #undef POSITION
1068 rb->lcd_set_background(COLOR_LIGHTGRAY);
1069 rb->lcd_setfont( FONT_SYSFIXED );
1070 rb->snprintf( str, 6, "%d", hue/10 );
1071 rb->lcd_putsxy( left + 117, top + 20, str );
1072 rb->snprintf( str, 6, "%d.%d", saturation/255, ((saturation*100)/255)%100 );
1073 rb->lcd_putsxy( left + 117, top + 30, str );
1074 rb->snprintf( str, 6, "%d.%d", value/255, ((value*100)/255)%100 );
1075 rb->lcd_putsxy( left + 117, top + 40, str );
1076 rb->snprintf( str, 6, "%d", red );
1077 rb->lcd_putsxy( left + 117, top + 50, str );
1078 rb->snprintf( str, 6, "%d", green );
1079 rb->lcd_putsxy( left + 117, top + 60, str );
1080 rb->snprintf( str, 6, "%d", blue );
1081 rb->lcd_putsxy( left + 117, top + 70, str );
1082 rb->lcd_setfont( FONT_UI );
1084 #define CURSOR( l ) \
1085 rb->lcd_bitmap_transparent_part( rockpaint_hsvrgb, 1, 1, 16, left+l+1, top+20, 6, 58 ); \
1086 rb->lcd_bitmap_transparent_part( rockpaint_hsvrgb, 8, 10*current, 16, left+l, top+19+10*current, 8, 10 );
1087 CURSOR( 5 );
1088 #undef CURSOR
1090 rb->lcd_set_foreground( color );
1091 rb->lcd_fillrect( left+15, top+85, 100, 8 );
1093 rb->lcd_update();
1095 switch( rb->button_get(true) )
1097 case ROCKPAINT_UP:
1098 current = ( current + 5 )%6;
1099 break;
1101 case ROCKPAINT_DOWN:
1102 current = (current + 1 )%6;
1103 break;
1105 case ROCKPAINT_LEFT:
1106 has_changed = true;
1107 switch( current )
1109 case Hue:
1110 hue = ( hue + 3600 - 10 )%3600;
1111 break;
1112 case Saturation:
1113 if( saturation ) saturation--;
1114 break;
1115 case Value:
1116 if( value ) value--;
1117 break;
1118 case Red:
1119 if( red ) red--;
1120 break;
1121 case Green:
1122 if( green ) green--;
1123 break;
1124 case Blue:
1125 if( blue ) blue--;
1126 break;
1128 break;
1130 case ROCKPAINT_LEFT|BUTTON_REPEAT:
1131 has_changed = true;
1132 switch( current )
1134 case Hue:
1135 hue = ( hue + 3600 - 100 )%3600;
1136 break;
1137 case Saturation:
1138 if( saturation >= 8 ) saturation-=8;
1139 else saturation = 0;
1140 break;
1141 case Value:
1142 if( value >= 8 ) value-=8;
1143 else value = 0;
1144 break;
1145 case Red:
1146 if( red >= 8 ) red-=8;
1147 else red = 0;
1148 break;
1149 case Green:
1150 if( green >= 8 ) green-=8;
1151 else green = 0;
1152 break;
1153 case Blue:
1154 if( blue >= 8 ) blue-=8;
1155 else blue = 0;
1156 break;
1158 break;
1160 case ROCKPAINT_RIGHT:
1161 has_changed = true;
1162 switch( current )
1164 case Hue:
1165 hue = ( hue + 10 )%3600;
1166 break;
1167 case Saturation:
1168 if( saturation < 0xff ) saturation++;
1169 break;
1170 case Value:
1171 if( value < 0xff ) value++;
1172 break;
1173 case Red:
1174 if( red < 0xff ) red++;
1175 break;
1176 case Green:
1177 if( green < 0xff ) green++;
1178 break;
1179 case Blue:
1180 if( blue < 0xff ) blue++;
1181 break;
1183 break;
1185 case ROCKPAINT_RIGHT|BUTTON_REPEAT:
1186 has_changed = true;
1187 switch( current )
1189 case Hue:
1190 hue = ( hue + 100 )%3600;
1191 break;
1192 case Saturation:
1193 if( saturation < 0xff - 8 ) saturation+=8;
1194 else saturation = 0xff;
1195 break;
1196 case Value:
1197 if( value < 0xff - 8 ) value+=8;
1198 else value = 0xff;
1199 break;
1200 case Red:
1201 if( red < 0xff - 8 ) red+=8;
1202 else red = 0xff;
1203 break;
1204 case Green:
1205 if( green < 0xff - 8 ) green+=8;
1206 else green = 0xff;
1207 break;
1208 case Blue:
1209 if( blue < 0xff - 8 ) blue+=8;
1210 else blue = 0xff;
1211 break;
1213 break;
1215 case ROCKPAINT_DRAW:
1216 return color;
1218 if( has_changed )
1220 switch( current )
1222 case Hue:
1223 case Saturation:
1224 case Value:
1225 hsv2rgb( hue, saturation, value, &red, &green, &blue );
1226 break;
1228 case Red:
1229 case Green:
1230 case Blue:
1231 rgb2hsv( red, green, blue, &hue, &saturation, &value );
1232 break;
1235 #undef HEIGHT
1236 #undef WIDTH
1240 /***********************************************************************
1241 * Misc routines
1242 ***********************************************************************/
1243 static void init_buffer(void)
1245 int i;
1246 fb_data color = rp_colors[ bgdrawcolor ];
1247 for( i = 0; i < ROWS*COLS; i++ )
1249 save_buffer[i] = color;
1253 static void draw_pixel(int x,int y)
1255 if( !preview )
1257 if( x < 0 || x >= COLS || y < 0 || y >= ROWS ) return;
1258 if( isbg )
1260 save_buffer[ x+y*COLS ] = rp_colors[bgdrawcolor];
1262 else
1264 save_buffer[ x+y*COLS ] = rp_colors[drawcolor];
1267 rb->lcd_drawpixel(x,y);
1270 static void color_picker( int x, int y )
1272 if( preview )
1274 rb->lcd_set_foreground( save_buffer[ x+y*COLS ] );
1275 #define PSIZE 12
1276 rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
1277 rb->lcd_drawrect( x<COLS-PSIZE ? x + 2 : x - PSIZE, y<ROWS-PSIZE ? y + 2: y - PSIZE, PSIZE - 2, PSIZE - 2 );
1278 rb->lcd_set_drawmode(DRMODE_SOLID);
1279 rb->lcd_fillrect( x<COLS-PSIZE ? x+3 : x - PSIZE+1, y<ROWS-PSIZE ? y +3: y - PSIZE+1, PSIZE-4, PSIZE-4 );
1280 #undef PSIZE
1281 rb->lcd_set_foreground( rp_colors[ drawcolor ] );
1283 else
1285 rp_colors[ drawcolor ] = save_buffer[ x+y*COLS ];
1289 static void draw_select_rectangle( int x1, int y1, int x2, int y2 )
1290 /* This is a preview mode only function */
1292 int i,a;
1293 if( x1 > x2 )
1295 i = x1;
1296 x1 = x2;
1297 x2 = i;
1299 if( y1 > y2 )
1301 i = y1;
1302 y1 = y2;
1303 y2 = i;
1305 rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
1306 i = 0;
1307 for( a = x1; a < x2; a++, i++ )
1308 if( i%2 )
1309 rb->lcd_drawpixel( a, y1 );
1310 for( a = y1; a < y2; a++, i++ )
1311 if( i%2 )
1312 rb->lcd_drawpixel( x2, a );
1313 if( y2 != y1 )
1314 for( a = x2; a > x1; a--, i++ )
1315 if( i%2 )
1316 rb->lcd_drawpixel( a, y2 );
1317 if( x2 != x1 )
1318 for( a = y2; a > y1; a--, i++ )
1319 if( i%2 )
1320 rb->lcd_drawpixel( x1, a );
1321 rb->lcd_set_drawmode(DRMODE_SOLID);
1324 static void copy_to_clipboard( void )
1326 /* This needs to be optimised ... but i'm lazy ATM */
1327 rb->memcpy( buffer.clipboard, save_buffer, COLS*ROWS*sizeof( fb_data ) );
1330 /* no preview mode handling atm ... do we need it ? (one if) */
1331 static void draw_invert( int x1, int y1, int x2, int y2 )
1333 int i;
1334 if( x1 > x2 )
1336 i = x1;
1337 x1 = x2;
1338 x2 = i;
1340 if( y1 > y2 )
1342 i = y1;
1343 y1 = y2;
1344 y2 = i;
1347 rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
1348 rb->lcd_fillrect( x1, y1, x2-x1+1, y2-y1+1 );
1349 rb->lcd_set_drawmode(DRMODE_SOLID);
1351 for( ; y1<=y2; y1++ )
1353 for( i = x1; i<=x2; i++ )
1355 save_buffer[ y1*COLS + i ] = ~save_buffer[ y1*COLS + i ];
1358 /*if( update )*/ rb->lcd_update();
1361 static void draw_hflip( int x1, int y1, int x2, int y2 )
1363 int i;
1364 if( x1 > x2 )
1366 i = x1;
1367 x1 = x2;
1368 x2 = i;
1370 if( y1 > y2 )
1372 i = y1;
1373 y1 = y2;
1374 y2 = i;
1377 copy_to_clipboard();
1379 for( i = 0; i <= y2 - y1; i++ )
1381 rb->memcpy( save_buffer+(y1+i)*COLS+x1,
1382 buffer.clipboard+(y2-i)*COLS+x1,
1383 (x2-x1+1)*sizeof( fb_data ) );
1385 restore_screen();
1386 rb->lcd_update();
1389 static void draw_vflip( int x1, int y1, int x2, int y2 )
1391 int i;
1392 if( x1 > x2 )
1394 i = x1;
1395 x1 = x2;
1396 x2 = i;
1398 if( y1 > y2 )
1400 i = y1;
1401 y1 = y2;
1402 y2 = i;
1405 copy_to_clipboard();
1407 for( ; y1 <= y2; y1++ )
1409 for( i = 0; i <= x2 - x1; i++ )
1411 save_buffer[y1*COLS+x1+i] = buffer.clipboard[y1*COLS+x2-i];
1414 restore_screen();
1415 rb->lcd_update();
1418 static void draw_paste_rectangle( int src_x1, int src_y1, int src_x2,
1419 int src_y2, int x1, int y1, int mode )
1421 int i;
1422 if( mode == SELECT_MENU_CUT )
1424 i = drawcolor;
1425 drawcolor = bgdrawcolor;
1426 draw_rect_full( src_x1, src_y1, src_x2, src_y2 );
1427 drawcolor = i;
1429 if( src_x1 > src_x2 )
1431 i = src_x1;
1432 src_x1 = src_x2;
1433 src_x2 = i;
1435 if( src_y1 > src_y2 )
1437 i = src_y1;
1438 src_y1 = src_y2;
1439 src_y2 = i;
1441 rb->lcd_bitmap_part( buffer.clipboard, src_x1, src_y1, COLS,
1442 x1, y1, src_x2-src_x1+1, src_y2-src_y1+1 );
1443 if( !preview )
1445 for( i = 0; i <= src_y2 - src_y1; i++ )
1447 rb->memcpy( save_buffer+(y1+i)*COLS+x1,
1448 buffer.clipboard+(src_y1+i)*COLS+src_x1,
1449 (src_x2 - src_x1 + 1)*sizeof( fb_data ) );
1454 static void show_grid( bool update )
1456 int i;
1457 if( gridsize > 0 )
1459 rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
1460 for( i = gridsize; i < COLS; i+= gridsize )
1462 rb->lcd_vline( i, 0, ROWS-1 );
1464 for( i = gridsize; i < ROWS; i+= gridsize )
1466 rb->lcd_hline( 0, COLS-1, i );
1468 rb->lcd_set_drawmode(DRMODE_SOLID);
1469 if( update ) rb->lcd_update();
1473 static void draw_text( int x, int y )
1475 buffer.text.text[0] = '\0';
1476 rb->snprintf( buffer.text.old_font, MAX_PATH,
1477 FONT_DIR "/%s.fnt",
1478 rb->global_settings->font_file );
1479 while( 1 )
1481 int m = TEXT_MENU_TEXT;
1482 switch( m = menu_display( text_menu, m ) )
1484 case TEXT_MENU_TEXT:
1485 rb->kbd_input( buffer.text.text, MAX_TEXT );
1486 restore_screen();
1487 break;
1489 case TEXT_MENU_FONT:
1490 if( browse_fonts( buffer.text.font, MAX_PATH ) )
1492 rb->font_load( buffer.text.font );
1494 break;
1496 case TEXT_MENU_PREVIEW:
1497 rb->lcd_set_foreground( rp_colors[ drawcolor ] );
1498 while( 1 )
1500 unsigned int button;
1501 restore_screen();
1502 rb->lcd_putsxy( x, y, buffer.text.text );
1503 rb->lcd_update();
1504 switch( button = rb->button_get( true ) )
1506 case ROCKPAINT_LEFT:
1507 case ROCKPAINT_LEFT | BUTTON_REPEAT:
1508 x-=bspeed * ( button & BUTTON_REPEAT ? 4 : 1 );
1509 if (x<0) x=COLS-1;
1510 break;
1512 case ROCKPAINT_RIGHT:
1513 case ROCKPAINT_RIGHT | BUTTON_REPEAT:
1514 x+=bspeed * ( button & BUTTON_REPEAT ? 4 : 1 );
1515 if (x>=COLS) x=0;
1516 break;
1518 case ROCKPAINT_UP:
1519 case ROCKPAINT_UP | BUTTON_REPEAT:
1520 y-=bspeed * ( button & BUTTON_REPEAT ? 4 : 1 );
1521 if (y<0) y=ROWS-1;
1522 break;
1524 case ROCKPAINT_DOWN:
1525 case ROCKPAINT_DOWN | BUTTON_REPEAT:
1526 y+=bspeed * ( button & BUTTON_REPEAT ? 4 : 1 );
1527 if (y>=ROWS-1) y=0;
1528 break;
1530 case ROCKPAINT_DRAW:
1531 button = 1242;
1532 break;
1534 if( button == 1242 ) break;
1536 break;
1538 case TEXT_MENU_APPLY:
1539 rb->lcd_set_foreground( rp_colors[ drawcolor ] );
1540 buffer_putsxyofs( save_buffer, COLS, ROWS, x, y, 0,
1541 buffer.text.text );
1542 case TEXT_MENU_CANCEL:
1543 restore_screen();
1544 rb->font_load( buffer.text.old_font );
1545 return;
1550 static void draw_brush( int x, int y )
1552 int i,j;
1553 for( i=-bsize/2+(bsize+1)%2; i<=bsize/2; i++ )
1555 for( j=-bsize/2+(bsize+1)%2; j<=bsize/2; j++ )
1557 draw_pixel( x+i, y+j );
1562 static void draw_line( int x1, int y1, int x2, int y2 )
1564 x1 = x1<<1;
1565 y1 = y1<<1;
1566 x2 = x2<<1;
1567 y2 = y2<<1;
1568 int w = x1 - x2;
1569 int h = y1 - y2;
1571 int x, y;
1573 if( w == 0 && h == 0 )
1575 draw_pixel( x1>>1, y1>>1 );
1576 return;
1579 if( w < 0 ) w *= -1;
1580 if( h < 0 ) h *= -1;
1582 if( w > h )
1584 if( x1 > x2 )
1586 x = x2;
1587 y = y2;
1588 x2 = x1;
1589 y2 = y1;
1590 x1 = x;
1591 y1 = y;
1593 w = x1 - x2;
1594 h = y1 - y2;
1595 while( x1 <= x2 )
1597 draw_pixel( (x1+1)>>1, (y1+1)>>1 );
1598 x1+=2;
1599 y1 = y2 - ( x2 - x1 ) * h / w;
1602 else /* h > w */
1604 if( y1 > y2 )
1606 x = x2;
1607 y = y2;
1608 x2 = x1;
1609 y2 = y1;
1610 x1 = x;
1611 y1 = y;
1613 w = x1 - x2;
1614 h = y1 - y2;
1615 while( y1 <= y2 )
1617 draw_pixel( (x1+1)>>1, (y1+1)>>1 );
1618 y1+=2;
1619 x1 = x2 - ( y2 - y1 ) * w / h;
1624 static void draw_curve( int x1, int y1, int x2, int y2,
1625 int xa, int ya, int xb, int yb )
1627 int i = 0;
1628 short xl1, yl1;
1629 short xl2, yl2;
1630 short xl3, yl3;
1631 short xl4, yl4;
1632 short xr1, yr1;
1633 short xr2, yr2;
1634 short xr3, yr3;
1635 short xr4, yr4;
1636 short depth;
1637 short xh, yh;
1639 if( x1 == x2 && y1 == y2 )
1641 draw_pixel( x1, y1 );
1642 return;
1645 // if( preview )
1647 rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
1648 if( xa == -1 || ya == -1 )
1650 rb->lcd_drawline( x1, y1, xb, yb );
1651 rb->lcd_drawline( x2, y2, xb, yb );
1653 else
1655 rb->lcd_drawline( x1, y1, xa, ya );
1656 rb->lcd_drawline( x2, y2, xb, yb );
1658 rb->lcd_set_drawmode(DRMODE_SOLID);
1661 if( xa == -1 || ya == -1 )
1662 /* We only have 3 of the points
1663 * This will currently only be used in preview mode */
1665 #define PUSH( a1, b1, a2, b2, a3, b3, d ) \
1666 buffer.bezier[i].x1 = a1; \
1667 buffer.bezier[i].y1 = b1; \
1668 buffer.bezier[i].x2 = a2; \
1669 buffer.bezier[i].y2 = b2; \
1670 buffer.bezier[i].x3 = a3; \
1671 buffer.bezier[i].y3 = b3; \
1672 buffer.bezier[i].depth = d; \
1673 i++;
1674 #define POP( a1, b1, a2, b2, a3, b3, d ) \
1675 i--; \
1676 a1 = buffer.bezier[i].x1; \
1677 b1 = buffer.bezier[i].y1; \
1678 a2 = buffer.bezier[i].x2; \
1679 b2 = buffer.bezier[i].y2; \
1680 a3 = buffer.bezier[i].x3; \
1681 b3 = buffer.bezier[i].y3; \
1682 d = buffer.bezier[i].depth;
1683 PUSH( x1<<4, y1<<4, xb<<4, yb<<4, x2<<4, y2<<4, 0 );
1684 while( i )
1686 /* de Casteljau's algorithm (see wikipedia) */
1687 POP( xl1, yl1, xb, yb, xr3, yr3, depth );
1688 if( depth < 10 ) /* check that the stack's 'i' doesn't overflow */
1690 xl2 = ( xl1 + xb )>>1;
1691 yl2 = ( yl1 + yb )>>1;
1692 xr2 = ( xb + xr3 )>>1;
1693 yr2 = ( yb + yr3 )>>1;
1694 xr1 = ( xl2 + xr2 )>>1;
1695 yr1 = ( yl2 + yr2 )>>1;
1696 xl3 = xr1;
1697 yl3 = yr1;
1698 PUSH( xl1, yl1, xl2, yl2, xl3, yl3, depth+1 );
1699 PUSH( xr1, yr1, xr2, yr2, xr3, yr3, depth+1 );
1701 else
1703 draw_line( ((xl1>>3)+1)>>1, ((yl1>>3)+1)>>1,
1704 ((xr3>>3)+1)>>1, ((yr3>>3)+1)>>1 );
1707 #undef PUSH
1708 #undef POP
1710 else /* We have the 4 points */
1712 #define PUSH( a1, b1, a2, b2, a3, b3, a4, b4, d ) \
1713 buffer.bezier[i].x1 = a1; \
1714 buffer.bezier[i].y1 = b1; \
1715 buffer.bezier[i].x2 = a2; \
1716 buffer.bezier[i].y2 = b2; \
1717 buffer.bezier[i].x3 = a3; \
1718 buffer.bezier[i].y3 = b3; \
1719 buffer.bezier[i].x4 = a4; \
1720 buffer.bezier[i].y4 = b4; \
1721 buffer.bezier[i].depth = d; \
1722 i++;
1723 #define POP( a1, b1, a2, b2, a3, b3, a4, b4, d ) \
1724 i--; \
1725 a1 = buffer.bezier[i].x1; \
1726 b1 = buffer.bezier[i].y1; \
1727 a2 = buffer.bezier[i].x2; \
1728 b2 = buffer.bezier[i].y2; \
1729 a3 = buffer.bezier[i].x3; \
1730 b3 = buffer.bezier[i].y3; \
1731 a4 = buffer.bezier[i].x4; \
1732 b4 = buffer.bezier[i].y4; \
1733 d = buffer.bezier[i].depth;
1735 PUSH( x1<<4, y1<<4, xa<<4, ya<<4, xb<<4, yb<<4, x2<<4, y2<<4, 0 );
1736 while( i )
1738 /* de Casteljau's algorithm (see wikipedia) */
1739 POP( xl1, yl1, xa, ya, xb, yb, xr4, yr4, depth );
1740 if( depth < 10 ) /* check that the stack's 'i' doesn't overflow */
1742 xl2 = ( xl1 + xa )>>1;
1743 yl2 = ( yl1 + ya )>>1;
1744 xh = ( xa + xb )>>1;
1745 yh = ( ya + yb )>>1;
1746 xr3 = ( xb + xr4 )>>1;
1747 yr3 = ( yb + yr4 )>>1;
1748 xl3 = ( xl2 + xh )>>1;
1749 yl3 = ( yl2 + yh )>>1;
1750 xr2 = ( xr3 + xh )>>1;
1751 yr2 = ( yr3 + yh )>>1;
1752 xl4 = ( xl3 + xr2 )>>1;
1753 yl4 = ( yl3 + yr2 )>>1;
1754 xr1 = xl4;
1755 yr1 = yl4;
1756 PUSH( xl1, yl1, xl2, yl2, xl3, yl3, xl4, yl4, depth+1 );
1757 PUSH( xr1, yr1, xr2, yr2, xr3, yr3, xr4, yr4, depth+1 );
1759 else
1761 draw_line( ((xl1>>3)+1)>>1, ((yl1>>3)+1)>>1,
1762 ((xr4>>3)+1)>>1, ((yr4>>3)+1)>>1 );
1765 #undef PUSH
1766 #undef POP
1770 static void draw_rect( int x1, int y1, int x2, int y2 )
1772 draw_line( x1, y1, x1, y2 );
1773 draw_line( x1, y1, x2, y1 );
1774 draw_line( x1, y2, x2, y2 );
1775 draw_line( x2, y1, x2, y2 );
1778 static void togglebg( void )
1780 if( isbg )
1782 rb->lcd_set_foreground( rp_colors[ drawcolor ] );
1784 else
1786 rb->lcd_set_foreground( rp_colors[ bgdrawcolor ] );
1788 isbg = !isbg;
1791 static void draw_rect_full( int x1, int y1, int x2, int y2 )
1793 /* GRUIK */
1794 int x = x1;
1795 togglebg();
1796 if( x < x2 )
1798 do {
1799 draw_line( x, y1, x, y2 );
1800 } while( ++x <= x2 );
1802 else
1804 do {
1805 draw_line( x, y1, x, y2 );
1806 } while( --x >= x2 );
1808 togglebg();
1809 draw_rect( x1, y1, x2, y2 );
1812 static void draw_oval( int x1, int y1, int x2, int y2, bool full )
1814 /* TODO: simplify :) */
1815 int cx = (x1+x2)>>1;
1816 int cy = (y1+y2)>>1;
1818 int rx = (x1-x2)>>1;
1819 int ry = (y1-y2)>>1;
1820 if( rx < 0 ) rx *= -1;
1821 if( ry < 0 ) ry *= -1;
1823 if( rx == 0 || ry == 0 )
1825 draw_line( x1, y1, x2, y2 );
1826 return;
1829 int x,y;
1830 int dst, old_dst;
1832 for( x = 0; x < rx; x++ )
1834 y = 0;
1835 dst = -0xfff;
1836 do {
1837 old_dst = dst;
1838 dst = ry * ry * x * x + rx * rx * y * y - rx * rx * ry * ry;
1839 y++;
1840 } while( dst < 0 );
1841 if( -old_dst < dst ) y--;
1842 if( full )
1844 draw_line( cx+x, cy, cx+x, cy+y );
1845 draw_line( cx+x, cy, cx+x, cy-y );
1846 draw_line( cx-x, cy, cx-x, cy+y );
1847 draw_line( cx-x, cy, cx-x, cy-y );
1849 else
1851 draw_pixel( cx+x, cy+y );
1852 draw_pixel( cx+x, cy-y );
1853 draw_pixel( cx-x, cy+y );
1854 draw_pixel( cx-x, cy-y );
1857 for( y = 0; y < ry; y++ )
1859 x = 0;
1860 dst = -0xfff;
1861 do {
1862 old_dst = dst;
1863 dst = ry * ry * x * x + rx * rx * y * y - rx * rx * ry * ry;
1864 x++;
1865 } while( dst < 0 );
1866 if( -old_dst < dst ) x--;
1867 if( full )
1869 draw_line( cx+x, cy, cx+x, cy+y );
1870 draw_line( cx+x, cy, cx+x, cy-y );
1871 draw_line( cx-x, cy, cx-x, cy+y );
1872 draw_line( cx-x, cy, cx-x, cy-y );
1874 else
1876 draw_pixel( cx+x, cy+y );
1877 draw_pixel( cx+x, cy-y );
1878 draw_pixel( cx-x, cy+y );
1879 draw_pixel( cx-x, cy-y );
1884 static void draw_oval_empty( int x1, int y1, int x2, int y2 )
1886 draw_oval( x1, y1, x2, y2, false );
1889 static void draw_oval_full( int x1, int y1, int x2, int y2 )
1891 togglebg();
1892 draw_oval( x1, y1, x2, y2, true );
1893 togglebg();
1894 draw_oval( x1, y1, x2, y2, false );
1897 static void draw_fill( int x0, int y0 )
1899 #define PUSH( a, b ) \
1900 draw_pixel( (int)a, (int)b ); \
1901 buffer.coord[i].x = a; \
1902 buffer.coord[i].y = b; \
1903 i++;
1904 #define POP( a, b ) \
1905 i--; \
1906 a = buffer.coord[i].x; \
1907 b = buffer.coord[i].y;
1909 unsigned int i=0;
1910 short x = x0;
1911 short y = y0;
1912 unsigned int prev_color = save_buffer[ x0+y0*COLS ];
1914 if( prev_color == rp_colors[ drawcolor ] ) return;
1916 PUSH( x, y );
1918 while( i != 0 )
1920 POP( x, y );
1921 if( x > 0 && save_buffer[x-1+y*COLS] == prev_color )
1923 PUSH( x-1, y );
1925 if( x < COLS-1 && save_buffer[x+1+y*COLS] == prev_color )
1927 PUSH( x+1, y );
1929 if( y > 0 && save_buffer[x+(y-1)*COLS] == prev_color )
1931 PUSH( x, y-1 );
1933 if( y < ROWS - 1 && save_buffer[x+(y+1)*COLS] == prev_color )
1935 PUSH( x, y+1 );
1938 #undef PUSH
1939 #undef POP
1943 /* For preview purposes only */
1944 static void line_gradient( int x1, int y1, int x2, int y2 )
1946 int r1, g1, b1;
1947 int r2, g2, b2;
1948 int h1, s1, v1, h2, s2, v2, r, g, b;
1949 int w, h, x, y;
1951 bool a = false;
1953 x1 <<= 1;
1954 y1 <<= 1;
1955 x2 <<= 1;
1956 y2 <<= 1;
1958 w = x1 - x2;
1959 h = y1 - y2;
1961 if( w == 0 && h == 0 )
1963 draw_pixel( x1>>1, y1>>1 );
1964 return;
1967 r1 = RGB_UNPACK_RED( rp_colors[ bgdrawcolor ] );
1968 g1 = RGB_UNPACK_GREEN( rp_colors[ bgdrawcolor ] );
1969 b1 = RGB_UNPACK_BLUE( rp_colors[ bgdrawcolor ] );
1970 r2 = RGB_UNPACK_RED( rp_colors[ drawcolor ] );
1971 g2 = RGB_UNPACK_GREEN( rp_colors[ drawcolor ] );
1972 b2 = RGB_UNPACK_BLUE( rp_colors[ drawcolor ] );
1974 if( w < 0 )
1976 w *= -1;
1977 a = true;
1979 if( h < 0 )
1981 h *= -1;
1982 a = !a;
1984 if( a )
1986 r = r1;
1987 r1 = r2;
1988 r2 = r;
1989 g = g1;
1990 g1 = g2;
1991 g2 = g;
1992 b = b1;
1993 b1 = b2;
1994 b2 = b;
1997 rgb2hsv( r1, g1, b1, &h1, &s1, &v1 );
1998 rgb2hsv( r2, g2, b2, &h2, &s2, &v2 );
2000 if( w > h )
2002 if( x1 > x2 )
2004 x = x2;
2005 y = y2;
2006 x2 = x1;
2007 y2 = y1;
2008 x1 = x;
2009 y1 = y;
2011 w = x1 - x2;
2012 h = y1 - y2;
2013 while( x1 <= x2 )
2015 hsv2rgb( h1+((h2-h1)*(x1-x2))/w,
2016 s1+((s2-s1)*(x1-x2))/w,
2017 v1+((v2-v1)*(x1-x2))/w,
2018 &r, &g, &b );
2019 rp_colors[ drawcolor ] = LCD_RGBPACK( r, g, b );
2020 rb->lcd_set_foreground( rp_colors[ drawcolor ] );
2021 draw_pixel( (x1+1)>>1, (y1+1)>>1 );
2022 x1+=2;
2023 y1 = y2 - ( x2 - x1 ) * h / w;
2026 else /* h > w */
2028 if( y1 > y2 )
2030 x = x2;
2031 y = y2;
2032 x2 = x1;
2033 y2 = y1;
2034 x1 = x;
2035 y1 = y;
2037 w = x1 - x2;
2038 h = y1 - y2;
2039 while( y1 <= y2 )
2041 hsv2rgb( h1+((h2-h1)*(y1-y2))/h,
2042 s1+((s2-s1)*(y1-y2))/h,
2043 v1+((v2-v1)*(y1-y2))/h,
2044 &r, &g, &b );
2045 rp_colors[ drawcolor ] = LCD_RGBPACK( r, g, b );
2046 rb->lcd_set_foreground( rp_colors[ drawcolor ] );
2047 draw_pixel( (x1+1)>>1, (y1+1)>>1 );
2048 y1+=2;
2049 x1 = x2 - ( y2 - y1 ) * w / h;
2052 if( a )
2054 rp_colors[ drawcolor ] = LCD_RGBPACK( r1, g1, b1 );
2056 else
2058 rp_colors[ drawcolor ] = LCD_RGBPACK( r2, g2, b2 );
2062 static void linear_gradient( int x1, int y1, int x2, int y2 )
2064 int r1 = RGB_UNPACK_RED( rp_colors[ bgdrawcolor ] );
2065 int g1 = RGB_UNPACK_GREEN( rp_colors[ bgdrawcolor ] );
2066 int b1 = RGB_UNPACK_BLUE( rp_colors[ bgdrawcolor ] );
2067 int r2 = RGB_UNPACK_RED( rp_colors[ drawcolor ] );
2068 int g2 = RGB_UNPACK_GREEN( rp_colors[ drawcolor ] );
2069 int b2 = RGB_UNPACK_BLUE( rp_colors[ drawcolor ] );
2071 int h1, s1, v1, h2, s2, v2, r, g, b;
2073 /* radius^2 */
2074 int radius2 = ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 );
2075 int dist2, i=0;
2077 /* We only propagate the gradient to neighboring pixels with the same
2078 * color as ( x1, y1 ) */
2079 unsigned int prev_color = save_buffer[ x1+y1*COLS ];
2081 int x = x1;
2082 int y = y1;
2084 if( radius2 == 0 ) return;
2085 if( preview )
2087 line_gradient( x1, y1, x2, y2 );
2090 rgb2hsv( r1, g1, b1, &h1, &s1, &v1 );
2091 rgb2hsv( r2, g2, b2, &h2, &s2, &v2 );
2093 #define PUSH( x0, y0 ) \
2094 buffer.coord[i].x = (short)(x0); \
2095 buffer.coord[i].y = (short)(y0); \
2096 i++;
2097 #define POP( a, b ) \
2098 i--; \
2099 a = (int)buffer.coord[i].x; \
2100 b = (int)buffer.coord[i].y;
2102 PUSH( x, y );
2104 while( i != 0 )
2106 POP( x, y );
2108 dist2 = ( x2 - x1 ) * ( x - x1 ) + ( y2 - y1 ) * ( y - y1 );
2109 if( dist2 <= 0 )
2111 rp_colors[ drawcolor ] = rp_colors[ bgdrawcolor ];
2113 else if( dist2 < radius2 )
2115 hsv2rgb( h1+((h2-h1)*dist2)/radius2,
2116 s1+((s2-s1)*dist2)/radius2,
2117 v1+((v2-v1)*dist2)/radius2,
2118 &r, &g, &b );
2119 rp_colors[ drawcolor ] = LCD_RGBPACK( r, g, b );
2121 else
2123 rp_colors[ drawcolor ] = LCD_RGBPACK( r2, g2, b2 );
2125 if( rp_colors[ drawcolor ] == prev_color )
2127 if( rp_colors[ drawcolor ])
2128 rp_colors[ drawcolor ]--; /* GRUIK */
2129 else
2130 rp_colors[ drawcolor ]++; /* GRUIK */
2132 rb->lcd_set_foreground( rp_colors[ drawcolor ] );
2133 draw_pixel( x, y );
2135 if( x > 0 && save_buffer[x-1+y*COLS] == prev_color )
2137 PUSH( x-1, y );
2139 if( x < COLS-1 && save_buffer[x+1+y*COLS] == prev_color )
2141 PUSH( x+1, y );
2143 if( y > 0 && save_buffer[x+(y-1)*COLS] == prev_color )
2145 PUSH( x, y-1 );
2147 if( y < ROWS - 1 && save_buffer[x+(y+1)*COLS] == prev_color )
2149 PUSH( x, y+1 );
2152 #undef PUSH
2153 #undef POP
2155 rp_colors[ drawcolor ] = LCD_RGBPACK( r2, g2, b2 );
2158 static void radial_gradient( int x1, int y1, int x2, int y2 )
2160 int r1 = RGB_UNPACK_RED( rp_colors[ bgdrawcolor ] );
2161 int g1 = RGB_UNPACK_GREEN( rp_colors[ bgdrawcolor ] );
2162 int b1 = RGB_UNPACK_BLUE( rp_colors[ bgdrawcolor ] );
2163 int r2 = RGB_UNPACK_RED( rp_colors[ drawcolor ] );
2164 int g2 = RGB_UNPACK_GREEN( rp_colors[ drawcolor ] );
2165 int b2 = RGB_UNPACK_BLUE( rp_colors[ drawcolor ] );
2167 int h1, s1, v1, h2, s2, v2, r, g, b;
2169 /* radius^2 */
2170 int radius2 = ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 );
2171 int dist2, i=0;
2173 /* We only propagate the gradient to neighboring pixels with the same
2174 * color as ( x1, y1 ) */
2175 unsigned int prev_color = save_buffer[ x1+y1*COLS ];
2177 int x = x1;
2178 int y = y1;
2180 if( radius2 == 0 ) return;
2181 if( preview )
2183 line_gradient( x1, y1, x2, y2 );
2186 rgb2hsv( r1, g1, b1, &h1, &s1, &v1 );
2187 rgb2hsv( r2, g2, b2, &h2, &s2, &v2 );
2189 #define PUSH( x0, y0 ) \
2190 buffer.coord[i].x = (short)(x0); \
2191 buffer.coord[i].y = (short)(y0); \
2192 i++;
2193 #define POP( a, b ) \
2194 i--; \
2195 a = (int)buffer.coord[i].x; \
2196 b = (int)buffer.coord[i].y;
2198 PUSH( x, y );
2200 while( i != 0 )
2202 POP( x, y );
2204 if( ( dist2 = (x1-(x))*(x1-(x))+(y1-(y))*(y1-(y)) ) < radius2 )
2206 hsv2rgb( h1+((h2-h1)*dist2)/radius2,
2207 s1+((s2-s1)*dist2)/radius2,
2208 v1+((v2-v1)*dist2)/radius2,
2209 &r, &g, &b );
2210 rp_colors[ drawcolor ] = LCD_RGBPACK( r, g, b );
2212 else
2214 rp_colors[ drawcolor ] = LCD_RGBPACK( r2, g2, b2 );
2216 if( rp_colors[ drawcolor ] == prev_color )
2218 if( rp_colors[ drawcolor ])
2219 rp_colors[ drawcolor ]--; /* GRUIK */
2220 else
2221 rp_colors[ drawcolor ]++; /* GRUIK */
2223 rb->lcd_set_foreground( rp_colors[ drawcolor ] );
2224 draw_pixel( x, y );
2226 if( x > 0 && save_buffer[x-1+y*COLS] == prev_color )
2228 PUSH( x-1, y );
2230 if( x < COLS-1 && save_buffer[x+1+y*COLS] == prev_color )
2232 PUSH( x+1, y );
2234 if( y > 0 && save_buffer[x+(y-1)*COLS] == prev_color )
2236 PUSH( x, y-1 );
2238 if( y < ROWS - 1 && save_buffer[x+(y+1)*COLS] == prev_color )
2240 PUSH( x, y+1 );
2243 #undef PUSH
2244 #undef POP
2246 rp_colors[ drawcolor ] = LCD_RGBPACK( r2, g2, b2 );
2249 static void draw_toolbars(bool update)
2251 int i;
2252 #define TOP (LCD_HEIGHT-TB_HEIGHT)
2253 rb->lcd_set_background( COLOR_LIGHTGRAY );
2254 rb->lcd_set_foreground( COLOR_LIGHTGRAY );
2255 rb->lcd_fillrect( 0, TOP, LCD_WIDTH, TB_HEIGHT );
2256 rb->lcd_set_foreground( COLOR_BLACK );
2257 rb->lcd_drawrect( 0, TOP, LCD_WIDTH, TB_HEIGHT );
2259 rb->lcd_set_foreground( rp_colors[ bgdrawcolor ] );
2260 rb->lcd_fillrect( TB_SC_BG_LEFT, TOP+TB_SC_BG_TOP,
2261 TB_SC_SIZE, TB_SC_SIZE );
2262 rb->lcd_set_foreground(ROCKPAINT_PALETTE);
2263 rb->lcd_drawrect( TB_SC_BG_LEFT, TOP+TB_SC_BG_TOP,
2264 TB_SC_SIZE, TB_SC_SIZE );
2265 rb->lcd_set_foreground( rp_colors[ drawcolor ] );
2266 rb->lcd_fillrect( TB_SC_FG_LEFT, TOP+TB_SC_FG_TOP,
2267 TB_SC_SIZE, TB_SC_SIZE );
2268 rb->lcd_set_foreground(ROCKPAINT_PALETTE);
2269 rb->lcd_drawrect( TB_SC_FG_LEFT, TOP+TB_SC_FG_TOP,
2270 TB_SC_SIZE, TB_SC_SIZE );
2272 for( i=0; i<18; i++ )
2274 rb->lcd_set_foreground( rp_colors[i] );
2275 rb->lcd_fillrect(
2276 TB_PL_LEFT+(i%9)*( TB_PL_COLOR_SIZE+TB_PL_COLOR_SPACING ),
2277 TOP+TB_PL_TOP+(i/9)*( TB_PL_COLOR_SIZE+TB_PL_COLOR_SPACING),
2278 TB_PL_COLOR_SIZE, TB_PL_COLOR_SIZE );
2279 rb->lcd_set_foreground( ROCKPAINT_PALETTE );
2280 rb->lcd_drawrect(
2281 TB_PL_LEFT+(i%9)*( TB_PL_COLOR_SIZE+TB_PL_COLOR_SPACING ),
2282 TOP+TB_PL_TOP+(i/9)*( TB_PL_COLOR_SIZE+TB_PL_COLOR_SPACING),
2283 TB_PL_COLOR_SIZE, TB_PL_COLOR_SIZE );
2286 #define SEPARATOR( x, y ) \
2287 rb->lcd_set_foreground( COLOR_WHITE ); \
2288 rb->lcd_vline( x, TOP+y, TOP+y+TB_PL_HEIGHT-1 ); \
2289 rb->lcd_set_foreground( COLOR_DARKGRAY ); \
2290 rb->lcd_vline( x+1, TOP+y, TOP+y+TB_PL_HEIGHT-1 );
2291 SEPARATOR( TB_PL_LEFT + TB_PL_WIDTH - 1 + TB_SP_MARGIN, TB_PL_TOP );
2293 rb->lcd_bitmap_transparent( rockpaint, TB_TL_LEFT, TOP+TB_TL_TOP,
2294 TB_TL_WIDTH, TB_TL_HEIGHT );
2295 rb->lcd_set_foreground(ROCKPAINT_PALETTE);
2296 rb->lcd_drawrect( TB_TL_LEFT+(TB_TL_SIZE+TB_TL_SPACING)*(tool/2),
2297 TOP+TB_TL_TOP+(TB_TL_SIZE+TB_TL_SPACING)*(tool%2),
2298 TB_TL_SIZE, TB_TL_SIZE );
2300 SEPARATOR( TB_TL_LEFT + TB_TL_WIDTH - 1 + TB_SP_MARGIN, TB_TL_TOP );
2302 rb->lcd_setfont( FONT_SYSFIXED );
2303 rb->lcd_putsxy( TB_MENU_LEFT, TOP+TB_MENU_TOP, "Menu" );
2304 rb->lcd_setfont( FONT_UI );
2305 #undef TOP
2307 if( update ) rb->lcd_update();
2310 static void toolbar( void )
2312 int button, i, j;
2313 restore_screen();
2314 draw_toolbars( false );
2315 y = LCD_HEIGHT-TB_HEIGHT/2;
2316 inv_cursor( true );
2317 while( 1 )
2319 switch( button = rb->button_get( true ) )
2321 case ROCKPAINT_DRAW:
2322 #define TOP ( LCD_HEIGHT - TB_HEIGHT )
2323 if( y >= TOP + TB_SC_FG_TOP
2324 && y < TOP + TB_SC_FG_TOP + TB_SC_SIZE
2325 && x >= TB_SC_FG_LEFT
2326 && x < TB_SC_FG_LEFT + TB_SC_SIZE )
2328 /* click on the foreground color */
2329 rp_colors[drawcolor] = color_chooser( rp_colors[drawcolor] );
2331 else if( y >= TOP + TB_SC_BG_TOP
2332 && y < TOP + TB_SC_BG_TOP + TB_SC_SIZE
2333 && x >= TB_SC_BG_LEFT
2334 && x < TB_SC_BG_LEFT + TB_SC_SIZE )
2336 /* click on the background color */
2337 i = drawcolor;
2338 drawcolor = bgdrawcolor;
2339 bgdrawcolor = i;
2341 else if( y >= TOP + TB_PL_TOP
2342 && y < TOP + TB_PL_TOP + TB_PL_HEIGHT
2343 && x >= TB_PL_LEFT
2344 && x < TB_PL_LEFT + TB_PL_WIDTH )
2346 /* click on the palette */
2347 i = (x - TB_PL_LEFT)%(TB_PL_COLOR_SIZE+TB_PL_COLOR_SPACING);
2348 j = (y - (TOP+TB_PL_TOP) )%(TB_PL_COLOR_SIZE+TB_PL_COLOR_SPACING);
2349 if( i >= TB_PL_COLOR_SIZE || j >= TB_PL_COLOR_SIZE )
2350 break;
2351 i = ( x - TB_PL_LEFT )/(TB_PL_COLOR_SIZE+TB_PL_COLOR_SPACING);
2352 j = ( y - (TOP+TB_PL_TOP) )/(TB_PL_COLOR_SIZE+TB_PL_COLOR_SPACING);
2353 drawcolor = j*(TB_PL_COLOR_SIZE+TB_PL_COLOR_SPACING)+i;
2355 else if( y >= TOP+TB_TL_TOP
2356 && y < TOP + TB_TL_TOP + TB_TL_HEIGHT
2357 && x >= TB_TL_LEFT
2358 && x <= TB_TL_LEFT + TB_TL_WIDTH )
2360 /* click on the tools */
2361 i = (x - TB_TL_LEFT ) % (TB_TL_SIZE+TB_TL_SPACING);
2362 j = (y - (TOP+TB_TL_TOP) ) %(TB_TL_SIZE+TB_TL_SPACING);
2363 if( i >= TB_TL_SIZE || j >= TB_TL_SIZE ) break;
2364 i = ( x - TB_TL_LEFT )/(TB_TL_SIZE+TB_TL_SPACING);
2365 j = ( y - (TOP+TB_TL_TOP) )/(TB_TL_SIZE+TB_TL_SPACING);
2366 tool = i*2+j;
2367 prev_x = -1;
2368 prev_y = -1;
2369 prev_x2 = -1;
2370 prev_y2 = -1;
2371 prev_x3 = -1;
2372 prev_y3 = -1;
2373 preview = false;
2375 else if( x >= TB_MENU_LEFT && y >= TOP+TB_MENU_TOP-2)
2377 /* menu button */
2378 goto_menu();
2380 #undef TOP
2381 restore_screen();
2382 draw_toolbars( false );
2383 inv_cursor( true );
2384 break;
2386 case ROCKPAINT_LEFT:
2387 case ROCKPAINT_LEFT | BUTTON_REPEAT:
2388 inv_cursor(false);
2389 x-=bspeed * ( button & BUTTON_REPEAT ? 4 : 1 );
2390 if (x<0) x=COLS-1;
2391 inv_cursor(true);
2392 break;
2394 case ROCKPAINT_RIGHT:
2395 case ROCKPAINT_RIGHT | BUTTON_REPEAT:
2396 inv_cursor(false);
2397 x+=bspeed * ( button & BUTTON_REPEAT ? 4 : 1 );
2398 if (x>=COLS) x=0;
2399 inv_cursor(true);
2400 break;
2402 case ROCKPAINT_UP:
2403 case ROCKPAINT_UP | BUTTON_REPEAT:
2404 inv_cursor(false);
2405 y-=bspeed * ( button & BUTTON_REPEAT ? 4 : 1 );
2406 if (y<LCD_HEIGHT-TB_HEIGHT)
2408 return;
2410 inv_cursor(true);
2411 break;
2413 case ROCKPAINT_DOWN:
2414 case ROCKPAINT_DOWN | BUTTON_REPEAT:
2415 inv_cursor(false);
2416 y+=bspeed * ( button & BUTTON_REPEAT ? 4 : 1 );
2417 if (y>=LCD_HEIGHT)
2419 y = 0;
2420 return;
2422 inv_cursor(true);
2423 break;
2425 case ROCKPAINT_TOOLBAR:
2426 case ROCKPAINT_TOOLBAR2:
2427 return;
2429 if( quit ) return;
2433 static void inv_cursor(bool update)
2435 rb->lcd_set_foreground(COLOR_BLACK);
2436 rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
2437 /* cross painting */
2438 rb->lcd_drawline(x-4,y,x-1,y);
2439 rb->lcd_drawline(x+1,y,x+4,y);
2440 rb->lcd_drawline(x,y-4,x,y-1);
2441 rb->lcd_drawline(x,y+1,x,y+4);
2442 rb->lcd_set_foreground(rp_colors[drawcolor]);
2443 rb->lcd_set_drawmode(DRMODE_SOLID);
2445 if( update ) rb->lcd_update();
2448 static void restore_screen(void)
2450 rb->lcd_bitmap( save_buffer, 0, 0, COLS, ROWS );
2453 static void clear_drawing(void)
2455 init_buffer();
2456 rb->lcd_set_foreground( rp_colors[ bgdrawcolor ] );
2457 rb->lcd_fillrect( 0, 0, COLS, ROWS );
2458 rb->lcd_update();
2461 static void goto_menu(void)
2463 int multi;
2465 while( 1 )
2467 switch( menu_display( main_menu, 1 ) )
2469 case MAIN_MENU_NEW:
2470 clear_drawing();
2471 return;
2473 case MAIN_MENU_LOAD:
2474 if( browse( filename, MAX_PATH, "/" ) )
2476 if( load_bitmap( filename ) <= 0 )
2478 rb->splash( 1*HZ, "Error while loading %s",
2479 filename );
2481 else
2483 rb->splash( 1*HZ, "Image loaded (%s)", filename );
2484 restore_screen();
2485 inv_cursor(true);
2486 return;
2489 break;
2491 case MAIN_MENU_SAVE:
2492 if( !rb->kbd_input( filename, MAX_PATH ) )
2494 save_bitmap( filename );
2495 rb->splash( 1*HZ, "File saved (%s)", filename );
2497 break;
2499 case MAIN_MENU_BRUSH_SIZE:
2500 multi = menu_display( size_menu, bsize );
2501 if( multi != - 1 )
2502 bsize = multi;
2503 break;
2505 case MAIN_MENU_BRUSH_SPEED:
2506 multi = menu_display( speed_menu, bspeed );
2507 if( multi != -1 )
2508 bspeed = multi;
2509 break;
2511 case MAIN_MENU_COLOR:
2512 rp_colors[drawcolor] = color_chooser( rp_colors[drawcolor] );
2513 break;
2515 case MAIN_MENU_GRID_SIZE:
2516 multi = menu_display( gridsize_menu, gridsize );
2517 if( multi != - 1 )
2518 gridsize = multi;
2519 break;
2521 case MAIN_MENU_EXIT:
2522 quit=true;
2523 return;
2525 case MAIN_MENU_RESUME:
2526 case MENU_ESC:
2527 return;
2528 }/* end switch */
2529 }/* end while */
2532 static void reset_tool( void )
2534 prev_x = -1;
2535 prev_y = -1;
2536 prev_x2 = -1;
2537 prev_y2 = -1;
2538 prev_x3 = -1;
2539 prev_y3 = -1;
2540 tool_mode = -1;
2541 preview = false;
2544 static bool rockpaint_loop( void )
2546 int button=0,i,j;
2547 int accelaration;
2549 while (!quit) {
2550 button = rb->button_get(true);
2552 if( tool == Brush && prev_x != -1 )
2554 accelaration = 1;
2556 else if( button & BUTTON_REPEAT )
2558 accelaration = 4;
2560 else
2562 accelaration = 1;
2565 switch(button)
2567 case ROCKPAINT_QUIT:
2568 rb->lcd_set_drawmode(DRMODE_SOLID);
2569 return PLUGIN_OK;
2571 case ROCKPAINT_MENU:
2572 inv_cursor(false);
2573 goto_menu();
2574 inv_cursor(true);
2575 break;
2577 case ROCKPAINT_DRAW:
2578 inv_cursor(false);
2579 switch( tool )
2581 case Brush:
2582 if( prev_x == -1 ) prev_x = 1;
2583 else prev_x = -1;
2584 break;
2586 case SelectRectangle:
2587 case Line:
2588 case Curve:
2589 case Rectangle:
2590 case RectangleFull:
2591 case Oval:
2592 case OvalFull:
2593 case LinearGradient:
2594 case RadialGradient:
2595 /* Curve uses 4 points, others use 2 */
2596 if( prev_x == -1 || prev_y == -1 )
2598 prev_x = x;
2599 prev_y = y;
2600 preview = true;
2602 else if( tool == Curve
2603 && ( prev_x2 == -1 || prev_y2 == -1 ) )
2605 prev_x2 = x;
2606 prev_y2 = y;
2608 else if( tool == SelectRectangle
2609 && ( prev_x2 == -1 || prev_y2 == -1 ) )
2611 tool_mode = menu_display( select_menu,
2612 SELECT_MENU_CUT );
2613 switch( tool_mode )
2615 case SELECT_MENU_CUT:
2616 case SELECT_MENU_COPY:
2617 prev_x2 = x;
2618 prev_y2 = y;
2619 copy_to_clipboard();
2620 if( prev_x < x ) x = prev_x;
2621 if( prev_y < y ) y = prev_y;
2622 break;
2624 case SELECT_MENU_INVERT:
2625 draw_invert( prev_x, prev_y, x, y );
2626 reset_tool();
2627 break;
2629 case SELECT_MENU_HFLIP:
2630 draw_hflip( prev_x, prev_y, x, y );
2631 reset_tool();
2632 break;
2634 case SELECT_MENU_VFLIP:
2635 draw_vflip( prev_x, prev_y, x, y );
2636 reset_tool();
2637 break;
2639 case SELECT_MENU_ROTATE90:
2640 break;
2641 case SELECT_MENU_ROTATE180:
2642 draw_hflip( prev_x, prev_y, x, y );
2643 draw_vflip( prev_x, prev_y, x, y );
2644 reset_tool();
2645 break;
2646 case SELECT_MENU_ROTATE270:
2647 break;
2649 case SELECT_MENU_CANCEL:
2650 reset_tool();
2651 break;
2653 case MENU_ESC:
2654 break;
2657 else if( tool == Curve
2658 && ( prev_x3 == -1 || prev_y3 == -1 ) )
2660 prev_x3 = x;
2661 prev_y3 = y;
2663 else
2665 preview = false;
2666 switch( tool )
2668 case SelectRectangle:
2669 draw_paste_rectangle( prev_x, prev_y,
2670 prev_x2, prev_y2,
2671 x, y, tool_mode );
2672 break;
2673 case Line:
2674 draw_line( prev_x, prev_y, x, y );
2675 break;
2676 case Curve:
2677 draw_curve( prev_x, prev_y,
2678 prev_x2, prev_y2,
2679 prev_x3, prev_y3,
2680 x, y );
2681 break;
2682 case Rectangle:
2683 draw_rect( prev_x, prev_y, x, y );
2684 break;
2685 case RectangleFull:
2686 draw_rect_full( prev_x, prev_y, x, y );
2687 break;
2688 case Oval:
2689 draw_oval_empty( prev_x, prev_y, x, y );
2690 break;
2691 case OvalFull:
2692 draw_oval_full( prev_x, prev_y, x, y );
2693 break;
2694 case LinearGradient:
2695 linear_gradient( prev_x, prev_y, x, y );
2696 break;
2697 case RadialGradient:
2698 radial_gradient( prev_x, prev_y, x, y );
2699 break;
2700 default:
2701 break;
2703 reset_tool();
2705 break;
2707 case Fill:
2708 draw_fill( x, y );
2709 break;
2711 case ColorPicker:
2712 color_picker( x, y );
2713 break;
2715 case Text:
2716 draw_text( x, y );
2717 break;
2719 default:
2720 break;
2722 inv_cursor(true);
2723 break;
2725 case ROCKPAINT_DRAW|BUTTON_REPEAT:
2726 if( tool == Curve )
2728 /* 3 point bezier curve */
2729 preview = false;
2730 draw_curve( prev_x, prev_y,
2731 prev_x2, prev_y2,
2732 -1, -1,
2733 x, y );
2734 reset_tool();
2735 restore_screen();
2736 inv_cursor( true );
2738 break;
2740 case ROCKPAINT_TOOLBAR:
2741 i = x; j = y;
2742 x = 10;
2743 toolbar();
2744 x = i; y = j;
2745 restore_screen();
2746 inv_cursor(true);
2747 break;
2749 case ROCKPAINT_TOOLBAR2:
2750 i = x; j = y;
2751 x = 110;
2752 toolbar();
2753 x = i; y = j;
2754 restore_screen();
2755 inv_cursor(true);
2756 break;
2758 case ROCKPAINT_LEFT:
2759 case ROCKPAINT_LEFT | BUTTON_REPEAT:
2760 inv_cursor(false);
2761 x-=bspeed * accelaration;
2762 if (x<0) x=COLS-1;
2763 inv_cursor(true);
2764 break;
2766 case ROCKPAINT_RIGHT:
2767 case ROCKPAINT_RIGHT | BUTTON_REPEAT:
2768 inv_cursor(false);
2769 x+=bspeed * accelaration;
2770 if (x>=COLS) x=0;
2771 inv_cursor(true);
2772 break;
2774 case ROCKPAINT_UP:
2775 case ROCKPAINT_UP | BUTTON_REPEAT:
2776 inv_cursor(false);
2777 y-=bspeed * accelaration;
2778 if (y<0) y=ROWS-1;
2779 inv_cursor(true);
2780 break;
2782 case ROCKPAINT_DOWN:
2783 case ROCKPAINT_DOWN | BUTTON_REPEAT:
2784 inv_cursor(false);
2785 y+=bspeed * accelaration;
2786 if (y>=ROWS)
2788 toolbar();
2789 restore_screen();
2791 inv_cursor(true);
2792 break;
2794 default:
2795 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
2796 return PLUGIN_USB_CONNECTED;
2797 break;
2799 if( tool == Brush && prev_x == 1 )
2801 inv_cursor(false);
2802 draw_brush( x, y );
2803 inv_cursor(true);
2805 if( preview || tool == ColorPicker )
2806 /* always preview color picker */
2808 restore_screen();
2809 switch( tool )
2811 case SelectRectangle:
2812 if( prev_x2 == -1 || prev_y2 == -1 )
2814 /* we are defining the selection */
2815 draw_select_rectangle( prev_x, prev_y, x, y );
2817 else
2819 /* we are pasting the selected data */
2820 draw_paste_rectangle( prev_x, prev_y, prev_x2,
2821 prev_y2, x, y, tool_mode );
2822 prev_x3 = prev_x2-prev_x;
2823 if( prev_x3 < 0 ) prev_x3 *= -1;
2824 prev_y3 = prev_y2-prev_y;
2825 if( prev_y3 < 0 ) prev_y3 *= -1;
2826 draw_select_rectangle( x, y, x+prev_x3, y+prev_y3 );
2827 prev_x3 = -1;
2828 prev_y3 = -1;
2830 break;
2832 case Brush:
2833 break;
2835 case Line:
2836 draw_line( prev_x, prev_y, x, y );
2837 break;
2839 case Curve:
2840 if( prev_x2 == -1 || prev_y2 == -1 )
2842 draw_line( prev_x, prev_y, x, y );
2844 else
2846 draw_curve( prev_x, prev_y,
2847 prev_x2, prev_y2,
2848 prev_x3, prev_y3,
2849 x, y );
2851 break;
2853 case Rectangle:
2854 draw_rect( prev_x, prev_y, x, y );
2855 break;
2857 case RectangleFull:
2858 draw_rect_full( prev_x, prev_y, x, y );
2859 break;
2861 case Oval:
2862 draw_oval_empty( prev_x, prev_y, x, y );
2863 break;
2865 case OvalFull:
2866 draw_oval_full( prev_x, prev_y, x, y );
2867 break;
2869 case Fill:
2870 break;
2872 case ColorPicker:
2873 preview = true;
2874 color_picker( x, y );
2875 preview = false;
2876 break;
2878 case LinearGradient:
2879 line_gradient( prev_x, prev_y, x, y );
2880 break;
2882 case RadialGradient:
2883 line_gradient( prev_x, prev_y, x, y );
2884 break;
2886 case Text:
2887 default:
2888 break;
2890 inv_cursor( true );
2892 if( gridsize > 0 )
2894 show_grid( true );
2895 show_grid( false );
2899 return PLUGIN_OK;
2902 static int load_bitmap( char *file )
2904 struct bitmap bm;
2905 bool ret;
2906 int l;
2908 bm.data = (char*)save_buffer;
2909 ret = rb->read_bmp_file( file, &bm, ROWS*COLS*sizeof( fb_data ),
2910 FORMAT_NATIVE );
2912 if((bm.width > COLS ) || ( bm.height > ROWS ))
2913 return -1;
2915 for( l = bm.height-1; l > 0; l-- )
2917 rb->memmove( save_buffer+l*COLS, save_buffer+l*bm.width,
2918 sizeof( fb_data )*bm.width );
2920 for( l = 0; l < bm.height; l++ )
2922 rb->memset( save_buffer+l*COLS+bm.width, rp_colors[ bgdrawcolor ],
2923 sizeof( fb_data )*(COLS-bm.width) );
2925 rb->memset( save_buffer+COLS*bm.height, rp_colors[ bgdrawcolor ],
2926 sizeof( fb_data )*COLS*(ROWS-bm.height) );
2928 return ret;
2931 static int save_bitmap( char *file )
2933 struct bitmap bm;
2934 bm.data = (char*)save_buffer;
2935 bm.height = ROWS;
2936 bm.width = COLS;
2937 bm.format = FORMAT_NATIVE;
2938 return save_bmp_file( file, &bm, rb );
2941 enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
2943 /** must have stuff **/
2944 rb = api;
2946 rb->lcd_set_foreground(COLOR_WHITE);
2947 rb->lcd_set_backdrop(NULL);
2948 rb->lcd_fillrect(0,0,LCD_WIDTH,LCD_HEIGHT);
2949 rb->splash( HZ/2, "Rock Paint");
2951 rb->lcd_clear_display();
2953 filename[0] = '\0';
2955 if( parameter )
2957 if( load_bitmap( parameter ) <= 0 )
2959 rb->splash( 1*HZ, "File Open Error");
2960 clear_drawing();
2962 else
2964 rb->splash( 1*HZ, "Image loaded (%s)", (char *)parameter );
2965 restore_screen();
2966 rb->strcpy( filename, parameter );
2969 else
2971 clear_drawing();
2973 inv_cursor(true);
2975 return rockpaint_loop();