1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
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)
32 #include "lib/rgb_hsv.h"
36 /***********************************************************************
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
107 #error "Please define keys for this keypad"
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 /***********************************************************************
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
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
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 )
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)
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
193 #define TB_TL_TOP ( TB_PL_TOP + TB_PL_HEIGHT + 4 )
194 #define TB_TL_LEFT TB_SC_FG_LEFT
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
);
217 /***********************************************************************
219 ***********************************************************************/
221 #if !defined(SIMULATOR) || defined(__MINGW32__) || defined(__CYGWIN__)
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 */
247 ColorPicker
= 3, /* Pick a color */
248 Line
= 4, /* Draw a line between two points */
249 Unused
= 5, /* THIS IS UNUSED ... */
252 Rectangle
= 8, /* Draw a rectangle */
254 Oval
= 10, /* Draw an oval */
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
,
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 */
284 /* Used by fill and gradient algorithms */
289 } coord
[ ROWS
*COLS
];
291 /* Used by bezier curve algorithms */
299 } bezier
[ (ROWS
*COLS
)/5 ]; /* We have 4.5 times more data per struct
300 * than coord ... so we divide to take
303 /* Used to cut/copy/paste data */
304 fb_data clipboard
[ ROWS
*COLS
];
306 /* Used for text mode */
309 char text
[MAX_TEXT
+1];
310 char font
[MAX_PATH
+1];
311 char old_font
[MAX_PATH
+1];
314 char fontname_buf
[30][MAX_PATH
];
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 ) )
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 */
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
;
381 *dst_col
= fgcolor
; /* FIXME ? */
383 dst_col
+= buf_width
;
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
)
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
)
410 const unsigned char *bits
;
412 /* get proportional width and glyph bits */
413 width
= rb
->font_get_width( pf
, ch
);
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
);
430 /***********************************************************************
432 ***********************************************************************/
436 char label
[16]; /* GRUIK ? */
439 #define MENU_ESC -1242
441 /* Generic menu items */
442 MENU_END
= -42, MENU_TITLE
= -12,
445 MAIN_MENU_NEW
, MAIN_MENU_LOAD
, MAIN_MENU_SAVE
,
446 MAIN_MENU_BRUSH_SIZE
, MAIN_MENU_BRUSH_SPEED
, MAIN_MENU_COLOR
,
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
,
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" },
472 static struct menu_items size_menu
[] =
473 { { MENU_TITLE
, "Choose Size" },
480 static struct menu_items speed_menu
[] =
481 { { MENU_TITLE
, "Choose Speed" },
487 static struct menu_items gridsize_menu
[] =
488 { { MENU_TITLE
, "Grid Size" },
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" },
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" },
517 static int draw_window( int height
, int width
,
522 rb
->lcd_getstringsize( title
, NULL
, &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
);
541 static int menu_display( struct menu_items menu
[], int prev_value
)
544 fh
, /* font height */
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
)
559 rb
->lcd_getstringsize( menu
[i
].label
, &a
, &b
);
560 if( a
> width
) width
= a
;
567 height
= menu_length
* fh
+ 4 + 2 + 2;
568 if( height
>= LCD_HEIGHT
)
571 onscreen
= ( LCD_HEIGHT
- 4 - 2 - 2 )/fh
;
572 height
= onscreen
* fh
+ 4 + 2 + 2;
577 onscreen
= menu_length
;
580 draw_window( height
, width
, &top
, &left
, menu
[0].label
);
584 for( i
= (scroll
== 0 ? 1 : scroll
);
585 i
< (scroll
? scroll
+ onscreen
- 1:onscreen
);
590 rb
->lcd_set_foreground( COLOR_WHITE
);
591 rb
->lcd_set_background( COLOR_BLUE
);
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 )),
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
),
613 switch( rb
->button_get(true) )
616 case ROCKPAINT_UP
|BUTTON_REPEAT
:
617 selection
= (selection
+ menu_length
-1)%menu_length
;
618 if( !selection
) selection
= menu_length
-1;
622 case ROCKPAINT_DOWN
|BUTTON_REPEAT
:
623 selection
= (selection
+ 1)%menu_length
;
624 if( !selection
) selection
++;
631 case ROCKPAINT_RIGHT
:
634 return menu
[selection
].value
;
638 if( selection
< scroll
)
641 draw_window( height
, width
, NULL
, NULL
, menu
[0].label
);
643 if( selection
>= scroll
+ onscreen
- 1 )
646 draw_window( height
, width
, NULL
, NULL
, menu
[0].label
);
652 /***********************************************************************
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 )
664 int top
, top_inside
, left
;
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 */
677 rb
->lcd_getstringsize( "Ap", NULL
, &fh
);
679 rb
->strcpy( bbuf
, start
);
680 a
= bbuf
+rb
->strlen(bbuf
)-1;
689 d
= rb
->PREFIX(opendir
)( bbuf
);
693 if( errno == ENOTDIR )
696 bbuf
[rb
->strlen(bbuf
)-1] = '\0';
697 rb
->strncpy( dst
, bbuf
, dst_size
);
700 else if( errno == EACCES || errno == ENOENT )
702 bbuf[0] = '/'; bbuf[1] = '\0';
703 d = rb->PREFIX(opendir)( "/" );
710 top_inside
= draw_window( HEIGHT
, WIDTH
, &top
, &left
, bbuf
);
715 rb
->PREFIX(readdir
)( d
);
718 while( top_inside
+(i
-fvi
)*(fh
+LINE_SPACE
) < HEIGHT
)
720 de
= rb
->PREFIX(readdir
)( d
);
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
),
732 rb
->strcpy( bbuf_s
, de
->d_name
);
738 if( !rb
->PREFIX(readdir
)( d
) )
743 rb
->PREFIX(closedir
)( d
);
747 switch( rb
->button_get(true) )
750 case ROCKPAINT_UP
|BUTTON_REPEAT
:
762 case ROCKPAINT_DOWN
|BUTTON_REPEAT
:
763 if( li
== -1 || si
< li
)
774 if( bbuf
[0] == '/' && !bbuf
[1] ) return false;
778 case ROCKPAINT_RIGHT
:
780 if( *bbuf_s
== '.' && !bbuf_s
[1] ) break;
783 if( *bbuf_s
== '.' && bbuf_s
[1] == '.' && !bbuf_s
[2] )
786 if( a
== bbuf
) break;
788 while( *a
!= '/' ) a
--;
792 rb
->strcpy( a
, bbuf_s
);
806 /***********************************************************************
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 )
819 int top
, top_inside
= 0, left
;
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 */
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
838 #define fontname_buf buffer.text.fontname_buf
840 rb
->snprintf( old_font
, MAX_PATH
,
842 rb
->global_settings
->font_file
);
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
);
864 d
= rb
->PREFIX(opendir
)( FONT_DIR
"/" );
869 top_inside
= draw_window( HEIGHT
, WIDTH
, &top
, &left
, "Fonts" );
874 rb
->PREFIX(readdir
)( d
);
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
);
890 if( rb
->strlen( de
->d_name
) < 4
891 || rb
->strcmp( de
->d_name
+ rb
->strlen( de
->d_name
) - 4,
894 rb
->snprintf( bbuf
, MAX_PATH
, FONT_DIR
"/%s",
896 rb
->font_load( bbuf
);
897 rb
->font_getstringsize( de
->d_name
, &fw
, &fh
, FONT_UI
);
902 if( nvih
< 0 ) nvih
= 0;
906 if( cp
+ fh
>= top
+HEIGHT
)
911 rb
->lcd_putsxy( left
+10, cp
, de
->d_name
);
914 cp
+= fh
+ LINE_SPACE
;
915 rb
->strcpy( fontname_buf
[i
-fvi
], bbuf
);
921 if( !(de
= rb
->PREFIX(readdir
)( d
) ) )
925 else if( !nvih
&& !rb
->strlen( de
->d_name
) < 4
926 && !rb
->strcmp( de
->d_name
+ rb
->strlen( de
->d_name
) - 4,
929 rb
->snprintf( bbuf
, MAX_PATH
, FONT_DIR
"/%s",
931 rb
->font_load( bbuf
);
932 rb
->font_getstringsize( de
->d_name
, NULL
, &fh
, FONT_UI
);
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
);
953 switch( rb
->button_get(true) )
956 case ROCKPAINT_UP
|BUTTON_REPEAT
:
968 case ROCKPAINT_DOWN
|BUTTON_REPEAT
:
969 if( li
== -1 || si
< li
)
978 case ROCKPAINT_RIGHT
:
980 rb
->snprintf( dst
, dst_size
, "%s", fontname_buf
[si
-fvi
] );
984 if( i
!= fvi
|| si
> lvi
)
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 */
1014 enum BaseColor
{ Hue
= 0, Saturation
= 1, Value
= 2,
1015 Red
= 3, Green
= 4, Blue
= 5 };
1016 enum BaseColor current
= Red
;
1023 rgb2hsv( red
, green
, blue
, &hue
, &saturation
, &value
);
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" );
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 );
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 );
1090 rb
->lcd_set_foreground( color
);
1091 rb
->lcd_fillrect( left
+15, top
+85, 100, 8 );
1095 switch( rb
->button_get(true) )
1098 current
= ( current
+ 5 )%6;
1101 case ROCKPAINT_DOWN
:
1102 current
= (current
+ 1 )%6;
1105 case ROCKPAINT_LEFT
:
1110 hue
= ( hue
+ 3600 - 10 )%3600;
1113 if( saturation
) saturation
--;
1116 if( value
) value
--;
1122 if( green
) green
--;
1130 case ROCKPAINT_LEFT
|BUTTON_REPEAT
:
1135 hue
= ( hue
+ 3600 - 100 )%3600;
1138 if( saturation
>= 8 ) saturation
-=8;
1139 else saturation
= 0;
1142 if( value
>= 8 ) value
-=8;
1146 if( red
>= 8 ) red
-=8;
1150 if( green
>= 8 ) green
-=8;
1154 if( blue
>= 8 ) blue
-=8;
1160 case ROCKPAINT_RIGHT
:
1165 hue
= ( hue
+ 10 )%3600;
1168 if( saturation
< 0xff ) saturation
++;
1171 if( value
< 0xff ) value
++;
1174 if( red
< 0xff ) red
++;
1177 if( green
< 0xff ) green
++;
1180 if( blue
< 0xff ) blue
++;
1185 case ROCKPAINT_RIGHT
|BUTTON_REPEAT
:
1190 hue
= ( hue
+ 100 )%3600;
1193 if( saturation
< 0xff - 8 ) saturation
+=8;
1194 else saturation
= 0xff;
1197 if( value
< 0xff - 8 ) value
+=8;
1201 if( red
< 0xff - 8 ) red
+=8;
1205 if( green
< 0xff - 8 ) green
+=8;
1209 if( blue
< 0xff - 8 ) blue
+=8;
1215 case ROCKPAINT_DRAW
:
1225 hsv2rgb( hue
, saturation
, value
, &red
, &green
, &blue
);
1231 rgb2hsv( red
, green
, blue
, &hue
, &saturation
, &value
);
1240 /***********************************************************************
1242 ***********************************************************************/
1243 static void init_buffer(void)
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
)
1257 if( x
< 0 || x
>= COLS
|| y
< 0 || y
>= ROWS
) return;
1260 save_buffer
[ x
+y
*COLS
] = rp_colors
[bgdrawcolor
];
1264 save_buffer
[ x
+y
*COLS
] = rp_colors
[drawcolor
];
1267 rb
->lcd_drawpixel(x
,y
);
1270 static void color_picker( int x
, int y
)
1274 rb
->lcd_set_foreground( save_buffer
[ x
+y
*COLS
] );
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 );
1281 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
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 */
1305 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1307 for( a
= x1
; a
< x2
; a
++, i
++ )
1309 rb
->lcd_drawpixel( a
, y1
);
1310 for( a
= y1
; a
< y2
; a
++, i
++ )
1312 rb
->lcd_drawpixel( x2
, a
);
1314 for( a
= x2
; a
> x1
; a
--, i
++ )
1316 rb
->lcd_drawpixel( a
, y2
);
1318 for( a
= y2
; a
> y1
; a
--, i
++ )
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
)
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
)
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
) );
1389 static void draw_vflip( int x1
, int y1
, int x2
, int y2
)
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
];
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
)
1422 if( mode
== SELECT_MENU_CUT
)
1425 drawcolor
= bgdrawcolor
;
1426 draw_rect_full( src_x1
, src_y1
, src_x2
, src_y2
);
1429 if( src_x1
> src_x2
)
1435 if( src_y1
> src_y2
)
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 );
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
)
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
,
1478 rb
->global_settings
->font_file
);
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
);
1489 case TEXT_MENU_FONT
:
1490 if( browse_fonts( buffer
.text
.font
, MAX_PATH
) )
1492 rb
->font_load( buffer
.text
.font
);
1496 case TEXT_MENU_PREVIEW
:
1497 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
1500 unsigned int button
;
1502 rb
->lcd_putsxy( x
, y
, buffer
.text
.text
);
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 );
1512 case ROCKPAINT_RIGHT
:
1513 case ROCKPAINT_RIGHT
| BUTTON_REPEAT
:
1514 x
+=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
1519 case ROCKPAINT_UP
| BUTTON_REPEAT
:
1520 y
-=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
1524 case ROCKPAINT_DOWN
:
1525 case ROCKPAINT_DOWN
| BUTTON_REPEAT
:
1526 y
+=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
1530 case ROCKPAINT_DRAW
:
1534 if( button
== 1242 ) break;
1538 case TEXT_MENU_APPLY
:
1539 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
1540 buffer_putsxyofs( save_buffer
, COLS
, ROWS
, x
, y
, 0,
1542 case TEXT_MENU_CANCEL
:
1544 rb
->font_load( buffer
.text
.old_font
);
1550 static void draw_brush( int x
, int y
)
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
)
1573 if( w
== 0 && h
== 0 )
1575 draw_pixel( x1
>>1, y1
>>1 );
1579 if( w
< 0 ) w
*= -1;
1580 if( h
< 0 ) h
*= -1;
1597 draw_pixel( (x1
+1)>>1, (y1
+1)>>1 );
1599 y1
= y2
- ( x2
- x1
) * h
/ w
;
1617 draw_pixel( (x1
+1)>>1, (y1
+1)>>1 );
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
)
1639 if( x1
== x2
&& y1
== y2
)
1641 draw_pixel( x1
, y1
);
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
);
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; \
1674 #define POP( a1, b1, a2, b2, a3, b3, d ) \
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 );
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;
1698 PUSH( xl1
, yl1
, xl2
, yl2
, xl3
, yl3
, depth
+1 );
1699 PUSH( xr1
, yr1
, xr2
, yr2
, xr3
, yr3
, depth
+1 );
1703 draw_line( ((xl1
>>3)+1)>>1, ((yl1
>>3)+1)>>1,
1704 ((xr3
>>3)+1)>>1, ((yr3
>>3)+1)>>1 );
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; \
1723 #define POP( a1, b1, a2, b2, a3, b3, a4, b4, d ) \
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 );
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;
1756 PUSH( xl1
, yl1
, xl2
, yl2
, xl3
, yl3
, xl4
, yl4
, depth
+1 );
1757 PUSH( xr1
, yr1
, xr2
, yr2
, xr3
, yr3
, xr4
, yr4
, depth
+1 );
1761 draw_line( ((xl1
>>3)+1)>>1, ((yl1
>>3)+1)>>1,
1762 ((xr4
>>3)+1)>>1, ((yr4
>>3)+1)>>1 );
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 )
1782 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
1786 rb
->lcd_set_foreground( rp_colors
[ bgdrawcolor
] );
1791 static void draw_rect_full( int x1
, int y1
, int x2
, int y2
)
1799 draw_line( x
, y1
, x
, y2
);
1800 } while( ++x
<= x2
);
1805 draw_line( x
, y1
, x
, y2
);
1806 } while( --x
>= x2
);
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
);
1832 for( x
= 0; x
< rx
; x
++ )
1838 dst
= ry
* ry
* x
* x
+ rx
* rx
* y
* y
- rx
* rx
* ry
* ry
;
1841 if( -old_dst
< dst
) y
--;
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
);
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
++ )
1863 dst
= ry
* ry
* x
* x
+ rx
* rx
* y
* y
- rx
* rx
* ry
* ry
;
1866 if( -old_dst
< dst
) x
--;
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
);
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
)
1892 draw_oval( x1
, y1
, x2
, y2
, true );
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; \
1904 #define POP( a, b ) \
1906 a = buffer.coord[i].x; \
1907 b = buffer.coord[i].y;
1912 unsigned int prev_color
= save_buffer
[ x0
+y0
*COLS
];
1914 if( prev_color
== rp_colors
[ drawcolor
] ) return;
1921 if( x
> 0 && save_buffer
[x
-1+y
*COLS
] == prev_color
)
1925 if( x
< COLS
-1 && save_buffer
[x
+1+y
*COLS
] == prev_color
)
1929 if( y
> 0 && save_buffer
[x
+(y
-1)*COLS
] == prev_color
)
1933 if( y
< ROWS
- 1 && save_buffer
[x
+(y
+1)*COLS
] == prev_color
)
1943 /* For preview purposes only */
1944 static void line_gradient( int x1
, int y1
, int x2
, int y2
)
1948 int h1
, s1
, v1
, h2
, s2
, v2
, r
, g
, b
;
1961 if( w
== 0 && h
== 0 )
1963 draw_pixel( x1
>>1, y1
>>1 );
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
] );
1997 rgb2hsv( r1
, g1
, b1
, &h1
, &s1
, &v1
);
1998 rgb2hsv( r2
, g2
, b2
, &h2
, &s2
, &v2
);
2015 hsv2rgb( h1
+((h2
-h1
)*(x1
-x2
))/w
,
2016 s1
+((s2
-s1
)*(x1
-x2
))/w
,
2017 v1
+((v2
-v1
)*(x1
-x2
))/w
,
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 );
2023 y1
= y2
- ( x2
- x1
) * h
/ w
;
2041 hsv2rgb( h1
+((h2
-h1
)*(y1
-y2
))/h
,
2042 s1
+((s2
-s1
)*(y1
-y2
))/h
,
2043 v1
+((v2
-v1
)*(y1
-y2
))/h
,
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 );
2049 x1
= x2
- ( y2
- y1
) * w
/ h
;
2054 rp_colors
[ drawcolor
] = LCD_RGBPACK( r1
, g1
, b1
);
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
;
2074 int radius2
= ( x1
- x2
) * ( x1
- x2
) + ( y1
- y2
) * ( y1
- y2
);
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
];
2084 if( radius2
== 0 ) return;
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); \
2097 #define POP( a, b ) \
2099 a = (int)buffer.coord[i].x; \
2100 b = (int)buffer.coord[i].y;
2108 dist2
= ( x2
- x1
) * ( x
- x1
) + ( y2
- y1
) * ( y
- y1
);
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
,
2119 rp_colors
[ drawcolor
] = LCD_RGBPACK( r
, g
, b
);
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 */
2130 rp_colors
[ drawcolor
]++; /* GRUIK */
2132 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
2135 if( x
> 0 && save_buffer
[x
-1+y
*COLS
] == prev_color
)
2139 if( x
< COLS
-1 && save_buffer
[x
+1+y
*COLS
] == prev_color
)
2143 if( y
> 0 && save_buffer
[x
+(y
-1)*COLS
] == prev_color
)
2147 if( y
< ROWS
- 1 && save_buffer
[x
+(y
+1)*COLS
] == prev_color
)
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
;
2170 int radius2
= ( x1
- x2
) * ( x1
- x2
) + ( y1
- y2
) * ( y1
- y2
);
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
];
2180 if( radius2
== 0 ) return;
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); \
2193 #define POP( a, b ) \
2195 a = (int)buffer.coord[i].x; \
2196 b = (int)buffer.coord[i].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
,
2210 rp_colors
[ drawcolor
] = LCD_RGBPACK( r
, g
, b
);
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 */
2221 rp_colors
[ drawcolor
]++; /* GRUIK */
2223 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
2226 if( x
> 0 && save_buffer
[x
-1+y
*COLS
] == prev_color
)
2230 if( x
< COLS
-1 && save_buffer
[x
+1+y
*COLS
] == prev_color
)
2234 if( y
> 0 && save_buffer
[x
+(y
-1)*COLS
] == prev_color
)
2238 if( y
< ROWS
- 1 && save_buffer
[x
+(y
+1)*COLS
] == prev_color
)
2246 rp_colors
[ drawcolor
] = LCD_RGBPACK( r2
, g2
, b2
);
2249 static void draw_toolbars(bool update
)
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
] );
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
);
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
);
2307 if( update
) rb
->lcd_update();
2310 static void toolbar( void )
2314 draw_toolbars( false );
2315 y
= LCD_HEIGHT
-TB_HEIGHT
/2;
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 */
2338 drawcolor
= bgdrawcolor
;
2341 else if( y
>= TOP
+ TB_PL_TOP
2342 && y
< TOP
+ TB_PL_TOP
+ TB_PL_HEIGHT
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
)
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
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
);
2375 else if( x
>= TB_MENU_LEFT
&& y
>= TOP
+TB_MENU_TOP
-2)
2382 draw_toolbars( false );
2386 case ROCKPAINT_LEFT
:
2387 case ROCKPAINT_LEFT
| BUTTON_REPEAT
:
2389 x
-=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
2394 case ROCKPAINT_RIGHT
:
2395 case ROCKPAINT_RIGHT
| BUTTON_REPEAT
:
2397 x
+=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
2403 case ROCKPAINT_UP
| BUTTON_REPEAT
:
2405 y
-=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
2406 if (y
<LCD_HEIGHT
-TB_HEIGHT
)
2413 case ROCKPAINT_DOWN
:
2414 case ROCKPAINT_DOWN
| BUTTON_REPEAT
:
2416 y
+=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
2425 case ROCKPAINT_TOOLBAR
:
2426 case ROCKPAINT_TOOLBAR2
:
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)
2456 rb
->lcd_set_foreground( rp_colors
[ bgdrawcolor
] );
2457 rb
->lcd_fillrect( 0, 0, COLS
, ROWS
);
2461 static void goto_menu(void)
2467 switch( menu_display( main_menu
, 1 ) )
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",
2483 rb
->splash( 1*HZ
, "Image loaded (%s)", filename
);
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
);
2499 case MAIN_MENU_BRUSH_SIZE
:
2500 multi
= menu_display( size_menu
, bsize
);
2505 case MAIN_MENU_BRUSH_SPEED
:
2506 multi
= menu_display( speed_menu
, bspeed
);
2511 case MAIN_MENU_COLOR
:
2512 rp_colors
[drawcolor
] = color_chooser( rp_colors
[drawcolor
] );
2515 case MAIN_MENU_GRID_SIZE
:
2516 multi
= menu_display( gridsize_menu
, gridsize
);
2521 case MAIN_MENU_EXIT
:
2525 case MAIN_MENU_RESUME
:
2532 static void reset_tool( void )
2544 static bool rockpaint_loop( void )
2550 button
= rb
->button_get(true);
2552 if( tool
== Brush
&& prev_x
!= -1 )
2556 else if( button
& BUTTON_REPEAT
)
2567 case ROCKPAINT_QUIT
:
2568 rb
->lcd_set_drawmode(DRMODE_SOLID
);
2571 case ROCKPAINT_MENU
:
2577 case ROCKPAINT_DRAW
:
2582 if( prev_x
== -1 ) prev_x
= 1;
2586 case SelectRectangle
:
2593 case LinearGradient
:
2594 case RadialGradient
:
2595 /* Curve uses 4 points, others use 2 */
2596 if( prev_x
== -1 || prev_y
== -1 )
2602 else if( tool
== Curve
2603 && ( prev_x2
== -1 || prev_y2
== -1 ) )
2608 else if( tool
== SelectRectangle
2609 && ( prev_x2
== -1 || prev_y2
== -1 ) )
2611 tool_mode
= menu_display( select_menu
,
2615 case SELECT_MENU_CUT
:
2616 case SELECT_MENU_COPY
:
2619 copy_to_clipboard();
2620 if( prev_x
< x
) x
= prev_x
;
2621 if( prev_y
< y
) y
= prev_y
;
2624 case SELECT_MENU_INVERT
:
2625 draw_invert( prev_x
, prev_y
, x
, y
);
2629 case SELECT_MENU_HFLIP
:
2630 draw_hflip( prev_x
, prev_y
, x
, y
);
2634 case SELECT_MENU_VFLIP
:
2635 draw_vflip( prev_x
, prev_y
, x
, y
);
2639 case SELECT_MENU_ROTATE90
:
2641 case SELECT_MENU_ROTATE180
:
2642 draw_hflip( prev_x
, prev_y
, x
, y
);
2643 draw_vflip( prev_x
, prev_y
, x
, y
);
2646 case SELECT_MENU_ROTATE270
:
2649 case SELECT_MENU_CANCEL
:
2657 else if( tool
== Curve
2658 && ( prev_x3
== -1 || prev_y3
== -1 ) )
2668 case SelectRectangle
:
2669 draw_paste_rectangle( prev_x
, prev_y
,
2674 draw_line( prev_x
, prev_y
, x
, y
);
2677 draw_curve( prev_x
, prev_y
,
2683 draw_rect( prev_x
, prev_y
, x
, y
);
2686 draw_rect_full( prev_x
, prev_y
, x
, y
);
2689 draw_oval_empty( prev_x
, prev_y
, x
, y
);
2692 draw_oval_full( prev_x
, prev_y
, x
, y
);
2694 case LinearGradient
:
2695 linear_gradient( prev_x
, prev_y
, x
, y
);
2697 case RadialGradient
:
2698 radial_gradient( prev_x
, prev_y
, x
, y
);
2712 color_picker( x
, y
);
2725 case ROCKPAINT_DRAW
|BUTTON_REPEAT
:
2728 /* 3 point bezier curve */
2730 draw_curve( prev_x
, prev_y
,
2740 case ROCKPAINT_TOOLBAR
:
2749 case ROCKPAINT_TOOLBAR2
:
2758 case ROCKPAINT_LEFT
:
2759 case ROCKPAINT_LEFT
| BUTTON_REPEAT
:
2761 x
-=bspeed
* accelaration
;
2766 case ROCKPAINT_RIGHT
:
2767 case ROCKPAINT_RIGHT
| BUTTON_REPEAT
:
2769 x
+=bspeed
* accelaration
;
2775 case ROCKPAINT_UP
| BUTTON_REPEAT
:
2777 y
-=bspeed
* accelaration
;
2782 case ROCKPAINT_DOWN
:
2783 case ROCKPAINT_DOWN
| BUTTON_REPEAT
:
2785 y
+=bspeed
* accelaration
;
2795 if (rb
->default_event_handler(button
) == SYS_USB_CONNECTED
)
2796 return PLUGIN_USB_CONNECTED
;
2799 if( tool
== Brush
&& prev_x
== 1 )
2805 if( preview
|| tool
== ColorPicker
)
2806 /* always preview color picker */
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
);
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
);
2836 draw_line( prev_x
, prev_y
, x
, y
);
2840 if( prev_x2
== -1 || prev_y2
== -1 )
2842 draw_line( prev_x
, prev_y
, x
, y
);
2846 draw_curve( prev_x
, prev_y
,
2854 draw_rect( prev_x
, prev_y
, x
, y
);
2858 draw_rect_full( prev_x
, prev_y
, x
, y
);
2862 draw_oval_empty( prev_x
, prev_y
, x
, y
);
2866 draw_oval_full( prev_x
, prev_y
, x
, y
);
2874 color_picker( x
, y
);
2878 case LinearGradient
:
2879 line_gradient( prev_x
, prev_y
, x
, y
);
2882 case RadialGradient
:
2883 line_gradient( prev_x
, prev_y
, x
, y
);
2902 static int load_bitmap( char *file
)
2908 bm
.data
= (char*)save_buffer
;
2909 ret
= rb
->read_bmp_file( file
, &bm
, ROWS
*COLS
*sizeof( fb_data
),
2912 if((bm
.width
> COLS
) || ( bm
.height
> ROWS
))
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
) );
2931 static int save_bitmap( char *file
)
2934 bm
.data
= (char*)save_buffer
;
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 **/
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();
2957 if( load_bitmap( parameter
) <= 0 )
2959 rb
->splash( 1*HZ
, "File Open Error");
2964 rb
->splash( 1*HZ
, "Image loaded (%s)", (char *)parameter
);
2966 rb
->strcpy( filename
, parameter
);
2975 return rockpaint_loop();