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 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ****************************************************************************/
25 * - implement 2 layers with alpha colors
26 * - take brush width into account when drawing shapes
27 * - handle bigger than screen bitmaps
28 * - cache fonts when building the font preview (else it only works well on simulators because they have "fast" disk read)
34 #include "lib/rgb_hsv.h"
38 /***********************************************************************
40 ***********************************************************************/
42 #if CONFIG_KEYPAD == IRIVER_H300_PAD
43 #define ROCKPAINT_QUIT BUTTON_OFF
44 #define ROCKPAINT_DRAW BUTTON_SELECT
45 #define ROCKPAINT_MENU BUTTON_ON
46 #define ROCKPAINT_TOOLBAR BUTTON_REC
47 #define ROCKPAINT_TOOLBAR2 BUTTON_MODE
48 #define ROCKPAINT_UP BUTTON_UP
49 #define ROCKPAINT_DOWN BUTTON_DOWN
50 #define ROCKPAINT_LEFT BUTTON_LEFT
51 #define ROCKPAINT_RIGHT BUTTON_RIGHT
53 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
54 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
55 #define ROCKPAINT_QUIT ( ~BUTTON_MAIN )
56 #define ROCKPAINT_DRAW BUTTON_SELECT
57 #define ROCKPAINT_MENU ( BUTTON_SELECT | BUTTON_MENU )
58 #define ROCKPAINT_TOOLBAR ( BUTTON_MENU | BUTTON_LEFT )
59 #define ROCKPAINT_TOOLBAR2 ( BUTTON_MENU | BUTTON_RIGHT )
60 #define ROCKPAINT_UP BUTTON_MENU
61 #define ROCKPAINT_DOWN BUTTON_PLAY
62 #define ROCKPAINT_LEFT BUTTON_LEFT
63 #define ROCKPAINT_RIGHT BUTTON_RIGHT
65 #elif ( CONFIG_KEYPAD == IAUDIO_X5M5_PAD )
66 #define ROCKPAINT_QUIT BUTTON_POWER
67 #define ROCKPAINT_DRAW BUTTON_SELECT
68 #define ROCKPAINT_MENU BUTTON_PLAY
69 #define ROCKPAINT_TOOLBAR BUTTON_REC
70 #define ROCKPAINT_TOOLBAR2 ( BUTTON_REC | BUTTON_LEFT )
71 #define ROCKPAINT_UP BUTTON_UP
72 #define ROCKPAINT_DOWN BUTTON_DOWN
73 #define ROCKPAINT_LEFT BUTTON_LEFT
74 #define ROCKPAINT_RIGHT BUTTON_RIGHT
76 #elif CONFIG_KEYPAD == GIGABEAT_PAD
77 #define ROCKPAINT_QUIT BUTTON_POWER
78 #define ROCKPAINT_DRAW BUTTON_SELECT
79 #define ROCKPAINT_MENU BUTTON_MENU
80 #define ROCKPAINT_TOOLBAR BUTTON_A
81 #define ROCKPAINT_TOOLBAR2 ( BUTTON_A | BUTTON_LEFT )
82 #define ROCKPAINT_UP BUTTON_UP
83 #define ROCKPAINT_DOWN BUTTON_DOWN
84 #define ROCKPAINT_LEFT BUTTON_LEFT
85 #define ROCKPAINT_RIGHT BUTTON_RIGHT
87 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
88 (CONFIG_KEYPAD == SANSA_C200_PAD)
89 #define ROCKPAINT_QUIT BUTTON_POWER
90 #define ROCKPAINT_DRAW BUTTON_SELECT
91 #define ROCKPAINT_MENU ( BUTTON_SELECT | BUTTON_POWER )
92 #define ROCKPAINT_TOOLBAR BUTTON_REC
93 #define ROCKPAINT_TOOLBAR2 ( BUTTON_REC | BUTTON_LEFT )
94 #define ROCKPAINT_UP BUTTON_UP
95 #define ROCKPAINT_DOWN BUTTON_DOWN
96 #define ROCKPAINT_LEFT BUTTON_LEFT
97 #define ROCKPAINT_RIGHT BUTTON_RIGHT
99 #elif ( CONFIG_KEYPAD == IRIVER_H10_PAD )
100 #define ROCKPAINT_QUIT BUTTON_POWER
101 #define ROCKPAINT_DRAW BUTTON_FF
102 #define ROCKPAINT_MENU BUTTON_PLAY
103 #define ROCKPAINT_TOOLBAR BUTTON_REW
104 #define ROCKPAINT_TOOLBAR2 ( BUTTON_REW | BUTTON_LEFT )
105 #define ROCKPAINT_UP BUTTON_SCROLL_UP
106 #define ROCKPAINT_DOWN BUTTON_SCROLL_DOWN
107 #define ROCKPAINT_LEFT BUTTON_LEFT
108 #define ROCKPAINT_RIGHT BUTTON_RIGHT
110 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
111 #define ROCKPAINT_QUIT BUTTON_BACK
112 #define ROCKPAINT_DRAW BUTTON_SELECT
113 #define ROCKPAINT_MENU BUTTON_MENU
114 #define ROCKPAINT_TOOLBAR BUTTON_PLAY
115 #define ROCKPAINT_TOOLBAR2 ( BUTTON_PLAY | BUTTON_LEFT )
116 #define ROCKPAINT_UP BUTTON_UP
117 #define ROCKPAINT_DOWN BUTTON_DOWN
118 #define ROCKPAINT_LEFT BUTTON_LEFT
119 #define ROCKPAINT_RIGHT BUTTON_RIGHT
121 #elif ( CONFIG_KEYPAD == COWOND2_PAD )
122 #define ROCKPAINT_QUIT BUTTON_POWER
123 #define ROCKPAINT_MENU BUTTON_MENU
126 #error "Please define keys for this keypad"
130 #ifndef ROCKPAINT_QUIT
131 #define ROCKPAINT_QUIT BUTTON_TOPLEFT
133 #ifndef ROCKPAINT_DRAW
134 #define ROCKPAINT_DRAW BUTTON_CENTER
136 #ifndef ROCKPAINT_MENU
137 #define ROCKPAINT_MENU BUTTON_TOPRIGHT
139 #ifndef ROCKPAINT_TOOLBAR
140 #define ROCKPAINT_TOOLBAR BUTTON_BOTTOMLEFT
142 #ifndef ROCKPAINT_TOOLBAR2
143 #define ROCKPAINT_TOOLBAR2 BUTTON_BOTTOMRIGHT
146 #define ROCKPAINT_UP BUTTON_TOPMIDDLE
148 #ifndef ROCKPAINT_DOWN
149 #define ROCKPAINT_DOWN BUTTON_BOTTOMMIDDLE
151 #ifndef ROCKPAINT_LEFT
152 #define ROCKPAINT_LEFT BUTTON_MIDLEFT
154 #ifndef ROCKPAINT_RIGHT
155 #define ROCKPAINT_RIGHT BUTTON_MIDRIGHT
159 /***********************************************************************
160 * Palette Default Colors
161 ***********************************************************************/
162 #define COLOR_BLACK LCD_RGBPACK(0,0,0)
163 #define COLOR_WHITE LCD_RGBPACK(255,255,255)
164 #define COLOR_DARKGRAY LCD_RGBPACK(128,128,128)
165 #define COLOR_LIGHTGRAY LCD_RGBPACK(192,192,192)
166 #define COLOR_RED LCD_RGBPACK(128,0,0)
167 #define COLOR_LIGHTRED LCD_RGBPACK(255,0,0)
168 #define COLOR_DARKYELLOW LCD_RGBPACK(128,128,0)
169 #define COLOR_YELLOW LCD_RGBPACK(255,255,0)
170 #define COLOR_GREEN LCD_RGBPACK(0,128,0)
171 #define COLOR_LIGHTGREN LCD_RGBPACK(0,255,0)
172 #define COLOR_CYAN LCD_RGBPACK(0,128,128)
173 #define COLOR_LIGHTCYAN LCD_RGBPACK(0,255,255)
174 #define COLOR_BLUE LCD_RGBPACK(0,0,128)
175 #define COLOR_LIGHTBLUE LCD_RGBPACK(0,0,255)
176 #define COLOR_PURPLE LCD_RGBPACK(128,0,128)
177 #define COLOR_PINK LCD_RGBPACK(255,0,255)
178 #define COLOR_BROWN LCD_RGBPACK(128,64,0)
179 #define COLOR_LIGHTBROWN LCD_RGBPACK(255,128,64)
181 #define SPLASH_SCREEN PLUGIN_APPS_DIR "/rockpaint/splash.bmp"
182 #define ROCKPAINT_TITLE_FONT 2
184 /***********************************************************************
186 ***********************************************************************/
187 #define ROCKPAINT_PALETTE LCD_RGBPACK(0,64,128)
188 #define ROCKPAINT_SELECTED LCD_RGBPACK(128,192,255)
190 #define ROWS LCD_HEIGHT
191 #define COLS LCD_WIDTH
194 * Toolbar positioning stuff ... don't read this unless you really need to
203 /* Separator sizes */
204 #define TB_SP_MARGIN 3
205 #define TB_SP_WIDTH (2+2*TB_SP_MARGIN)
207 /* Selected color sizes */
208 #define TB_SC_SIZE 12
211 #define TB_PL_COLOR_SIZE 7
212 #define TB_PL_COLOR_SPACING 2
213 #define TB_PL_WIDTH ( 9 * TB_PL_COLOR_SIZE + 8 * TB_PL_COLOR_SPACING )
214 #define TB_PL_HEIGHT ( TB_PL_COLOR_SIZE * 2 + TB_PL_COLOR_SPACING )
218 #define TB_TL_SPACING 2
219 #define TB_TL_WIDTH ( 7 * ( TB_TL_SIZE + TB_TL_SPACING ) - TB_TL_SPACING )
220 #define TB_TL_HEIGHT ( 2 * TB_TL_SIZE + TB_TL_SPACING )
222 /* Menu button size ... gruik */
223 #define TB_MENU_MIN_WIDTH 30
225 /* Selected colors position */
226 #define TB_SC_FG_TOP 2
227 #define TB_SC_FG_LEFT 2
228 #define TB_SC_BG_TOP (TB_SC_FG_TOP+TB_PL_COLOR_SIZE*2+TB_PL_COLOR_SPACING-TB_SC_SIZE)
229 #define TB_SC_BG_LEFT (TB_SC_FG_LEFT+TB_PL_COLOR_SIZE*2+TB_PL_COLOR_SPACING-TB_SC_SIZE)
231 /* Palette position */
232 #define TB_PL_TOP TB_SC_FG_TOP
233 #define TB_PL_LEFT (TB_SC_BG_LEFT + TB_SC_SIZE + TB_PL_COLOR_SPACING)
236 #define TB_TL_TOP TB_SC_FG_TOP
237 #define TB_TL_LEFT ( TB_PL_LEFT + TB_PL_WIDTH-1 + TB_SP_WIDTH )
239 #if TB_TL_LEFT + TB_TL_WIDTH + TB_MENU_MIN_WIDTH >= LCD_WIDTH
242 #define TB_TL_TOP ( TB_PL_TOP + TB_PL_HEIGHT + 4 )
243 #define TB_TL_LEFT TB_SC_FG_LEFT
246 /* Menu button position */
247 #define TB_MENU_TOP ( TB_TL_TOP + (TB_TL_HEIGHT-8)/2 )
248 #define TB_MENU_LEFT ( TB_TL_LEFT + TB_TL_WIDTH-1 + TB_SP_WIDTH )
250 #define TB_HEIGHT ( TB_TL_TOP + TB_TL_HEIGHT + 1 )
253 static void draw_pixel(int x
,int y
);
254 static void draw_line( int x1
, int y1
, int x2
, int y2
);
255 static void draw_rect( int x1
, int y1
, int x2
, int y2
);
256 static void draw_toolbars(bool update
);
257 static void inv_cursor(bool update
);
258 static void restore_screen(void);
259 static void clear_drawing(void);
260 static void goto_menu(void);
261 static int load_bitmap( const char *filename
);
262 static int save_bitmap( char *filename
);
263 static void draw_rect_full( int x1
, int y1
, int x2
, int y2
);
266 /***********************************************************************
268 ***********************************************************************/
270 #if !defined(SIMULATOR) || defined(__MINGW32__) || defined(__CYGWIN__)
274 static const struct plugin_api
* rb
;
276 MEM_FUNCTION_WRAPPERS(rb
);
278 static int drawcolor
=0; /* Current color (in palette) */
279 static int bgdrawcolor
=9; /* Current background color (in palette) */
280 bool isbg
= false; /* gruik ugly hack alert */
282 static int preview
=false; /* Is preview mode on ? */
284 /* TODO: clean this up */
285 static int x
=0, y
=0; /* cursor position */
286 static int prev_x
=-1, prev_y
=-1; /* previous saved cursor position */
287 static int prev_x2
=-1, prev_y2
=-1;
288 static int prev_x3
=-1, prev_y3
=-1;
289 static int tool_mode
=-1;
292 static int bsize
=1; /* brush size */
293 static int bspeed
=1; /* brush speed */
295 enum Tools
{ Brush
= 0, /* Regular brush */
296 Fill
= 1, /* Fill a shape with current color */
298 ColorPicker
= 3, /* Pick a color */
299 Line
= 4, /* Draw a line between two points */
300 Unused
= 5, /* THIS IS UNUSED ... */
303 Rectangle
= 8, /* Draw a rectangle */
305 Oval
= 10, /* Draw an oval */
311 enum Tools tool
= Brush
;
313 static bool quit
=false;
314 static int gridsize
=0;
316 static fb_data rp_colors
[18] =
318 COLOR_BLACK
, COLOR_DARKGRAY
, COLOR_RED
, COLOR_DARKYELLOW
,
319 COLOR_GREEN
, COLOR_CYAN
, COLOR_BLUE
, COLOR_PURPLE
, COLOR_BROWN
,
320 COLOR_WHITE
, COLOR_LIGHTGRAY
, COLOR_LIGHTRED
, COLOR_YELLOW
,
321 COLOR_LIGHTGREN
, COLOR_LIGHTCYAN
, COLOR_LIGHTBLUE
, COLOR_PINK
,
325 static fb_data save_buffer
[ ROWS
*COLS
];
327 extern fb_data rockpaint
[];
328 extern fb_data rockpaint_hsvrgb
[];
330 /* Maximum string size allowed for the text tool */
335 /* Used by fill and gradient algorithms */
340 } coord
[ ROWS
*COLS
];
342 /* Used by bezier curve algorithms */
350 } bezier
[ (ROWS
*COLS
)/5 ]; /* We have 4.5 times more data per struct
351 * than coord ... so we divide to take
354 /* Used to cut/copy/paste data */
355 fb_data clipboard
[ ROWS
*COLS
];
357 /* Used for text mode */
360 char text
[MAX_TEXT
+1];
361 char font
[MAX_PATH
+1];
362 char old_font
[MAX_PATH
+1];
365 char fontname_buf
[30][MAX_PATH
];
369 /* Current filename */
370 static char filename
[MAX_PATH
+1];
372 /* Font preview buffer */
373 //#define FONT_PREVIEW_WIDTH ((LCD_WIDTH-30)/8)
374 //#define FONT_PREVIEW_HEIGHT 1000
375 //static unsigned char fontpreview[FONT_PREVIEW_WIDTH*FONT_PREVIEW_HEIGHT];
377 /***********************************************************************
378 * Offscreen buffer/Text/Fonts handling
380 * Parts of code taken from firmware/drivers/lcd-16bit.c
381 ***********************************************************************/
382 static void buffer_mono_bitmap_part(
383 fb_data
*buf
, int buf_width
, int buf_height
,
384 const unsigned char *src
, int src_x
, int src_y
,
385 int stride
, int x
, int y
, int width
, int height
)
386 /* this function only draws the foreground part of the bitmap */
388 const unsigned char *src_end
;
389 fb_data
*dst
, *dst_end
;
390 unsigned fgcolor
= rb
->lcd_get_foreground();
392 /* nothing to draw? */
393 if( ( width
<= 0 ) || ( height
<= 0 ) || ( x
>= buf_width
)
394 || ( y
>= buf_height
) || ( x
+ width
<= 0 ) || ( y
+ height
<= 0 ) )
410 if( x
+ width
> buf_width
)
411 width
= buf_width
- x
;
412 if( y
+ height
> buf_height
)
413 height
= buf_height
- y
;
415 src
+= stride
* (src_y
>> 3) + src_x
; /* move starting point */
417 src_end
= src
+ width
;
419 dst
= buf
+ y
*buf_width
+ x
;
423 const unsigned char *src_col
= src
++;
424 unsigned data
= *src_col
>> src_y
;
425 fb_data
*dst_col
= dst
++;
426 int numbits
= 8 - src_y
;
428 dst_end
= dst_col
+ height
* buf_width
;
432 *dst_col
= fgcolor
; /* FIXME ? */
434 dst_col
+= buf_width
;
443 } while( dst_col
< dst_end
);
444 } while( src
< src_end
);
447 static void buffer_putsxyofs( fb_data
*buf
, int buf_width
, int buf_height
,
448 int x
, int y
, int ofs
, const unsigned char *str
)
453 struct font
*pf
= rb
->font_get( FONT_UI
);
454 if( !pf
) pf
= rb
->font_get( FONT_SYSFIXED
);
456 ucs
= rb
->bidi_l2v( str
, 1 );
458 while( (ch
= *ucs
++) != 0 && x
< buf_width
)
461 const unsigned char *bits
;
463 /* get proportional width and glyph bits */
464 width
= rb
->font_get_width( pf
, ch
);
472 bits
= rb
->font_get_bits( pf
, ch
);
474 buffer_mono_bitmap_part( buf
, buf_width
, buf_height
, bits
, ofs
, 0, width
, x
, y
, width
- ofs
, pf
->height
);
481 /***********************************************************************
483 ***********************************************************************/
487 char label
[16]; /* GRUIK ? */
490 #define MENU_ESC -1242
492 /* Generic menu items */
493 MENU_END
= -42, MENU_TITLE
= -12,
496 MAIN_MENU_NEW
, MAIN_MENU_LOAD
, MAIN_MENU_SAVE
,
497 MAIN_MENU_BRUSH_SIZE
, MAIN_MENU_BRUSH_SPEED
, MAIN_MENU_COLOR
,
500 /* Select action menu */
501 SELECT_MENU_CUT
, SELECT_MENU_COPY
, SELECT_MENU_INVERT
,
502 SELECT_MENU_HFLIP
, SELECT_MENU_VFLIP
, SELECT_MENU_ROTATE90
,
503 SELECT_MENU_ROTATE180
, SELECT_MENU_ROTATE270
,
506 TEXT_MENU_TEXT
, TEXT_MENU_FONT
,
507 TEXT_MENU_PREVIEW
, TEXT_MENU_APPLY
, TEXT_MENU_CANCEL
,
510 static struct menu_items main_menu
[]=
511 { { MENU_TITLE
, "RockPaint" },
512 { MAIN_MENU_RESUME
, "Resume" },
513 { MAIN_MENU_NEW
, "New" },
514 { MAIN_MENU_LOAD
, "Load" },
515 { MAIN_MENU_SAVE
, "Save" },
516 { MAIN_MENU_BRUSH_SIZE
, "Brush Size" },
517 { MAIN_MENU_BRUSH_SPEED
, "Brush Speed" },
518 { MAIN_MENU_COLOR
, "Choose Color" },
519 { MAIN_MENU_GRID_SIZE
, "Grid Size" },
520 { MAIN_MENU_EXIT
, "Exit" },
523 static struct menu_items size_menu
[] =
524 { { MENU_TITLE
, "Choose Size" },
531 static struct menu_items speed_menu
[] =
532 { { MENU_TITLE
, "Choose Speed" },
538 static struct menu_items gridsize_menu
[] =
539 { { MENU_TITLE
, "Grid Size" },
546 static struct menu_items select_menu
[] =
547 { { MENU_TITLE
, "Select..." },
548 { SELECT_MENU_CUT
, "Cut" },
549 { SELECT_MENU_COPY
, "Copy" },
550 { SELECT_MENU_INVERT
, "Invert" },
551 { SELECT_MENU_HFLIP
, "Horizontal flip" },
552 { SELECT_MENU_VFLIP
, "Vertical flip" },
553 // { SELECT_MENU_ROTATE90, "Rotate 90°" },
554 { SELECT_MENU_ROTATE180
, "Rotate 180°" },
555 // { SELECT_MENU_ROTATE270, "Rotate 270°" },
556 { SELECT_MENU_CANCEL
, "Cancel" },
559 static struct menu_items text_menu
[] =
560 { { MENU_TITLE
, "Text" },
561 { TEXT_MENU_TEXT
, "Set text" },
562 { TEXT_MENU_FONT
, "Change font" },
563 { TEXT_MENU_PREVIEW
, "Preview" },
564 { TEXT_MENU_APPLY
, "Apply" },
565 { TEXT_MENU_CANCEL
, "Cancel" },
568 static int draw_window( int height
, int width
,
573 rb
->lcd_getstringsize( title
, NULL
, &fh
);
576 const int _top
= ( LCD_HEIGHT
- height
) / 2;
577 const int _left
= ( LCD_WIDTH
- width
) / 2;
578 if( top
) *top
= _top
;
579 if( left
) *left
= _left
;
580 rb
->lcd_set_background(COLOR_BLUE
);
581 rb
->lcd_set_foreground(COLOR_LIGHTGRAY
);
582 rb
->lcd_fillrect( _left
, _top
, width
, height
);
583 rb
->lcd_set_foreground(COLOR_BLUE
);
584 rb
->lcd_fillrect( _left
, _top
, width
, fh
+4 );
585 rb
->lcd_set_foreground(COLOR_WHITE
);
586 rb
->lcd_putsxy( _left
+2, _top
+2, title
);
587 rb
->lcd_set_foreground(COLOR_BLACK
);
588 rb
->lcd_drawrect( _left
, _top
, width
, height
);
592 static int menu_display( struct menu_items menu
[], int prev_value
)
595 fh
, /* font height */
601 int scroll
= 0, onscreen
= 0;
603 rb
->lcd_getstringsize( menu
[0].label
, &width
, &fh
);
604 for( i
=1; menu
[i
].value
!= MENU_END
; i
++ )
606 if( prev_value
== menu
[i
].value
)
610 rb
->lcd_getstringsize( menu
[i
].label
, &a
, &b
);
611 if( a
> width
) width
= a
;
618 height
= menu_length
* fh
+ 4 + 2 + 2;
619 if( height
>= LCD_HEIGHT
)
622 onscreen
= ( LCD_HEIGHT
- 4 - 2 - 2 )/fh
;
623 height
= onscreen
* fh
+ 4 + 2 + 2;
628 onscreen
= menu_length
;
631 draw_window( height
, width
, &top
, &left
, menu
[0].label
);
635 for( i
= (scroll
== 0 ? 1 : scroll
);
636 i
< (scroll
? scroll
+ onscreen
- 1:onscreen
);
641 rb
->lcd_set_foreground( COLOR_WHITE
);
642 rb
->lcd_set_background( COLOR_BLUE
);
646 rb
->lcd_set_foreground( COLOR_BLACK
);
647 rb
->lcd_set_background( COLOR_LIGHTGRAY
);
649 rb
->lcd_putsxy( left
+2,
650 top
+6+fh
*(i
-(scroll
== 0 ? 0 : scroll
-1 )),
655 int scroll_height
= ((height
-fh
-4-2)*onscreen
)/menu_length
;
656 rb
->lcd_set_foreground( COLOR_BLACK
);
657 rb
->lcd_vline( left
+width
-5, top
+fh
+4, top
+height
-2 );
658 rb
->lcd_fillrect( left
+width
-4,
659 top
+fh
+4+((height
-4-2-fh
-scroll_height
)*(scroll
-1))/(menu_length
-onscreen
),
664 switch( rb
->button_get(true) )
667 case ROCKPAINT_UP
|BUTTON_REPEAT
:
668 selection
= (selection
+ menu_length
-1)%menu_length
;
669 if( !selection
) selection
= menu_length
-1;
673 case ROCKPAINT_DOWN
|BUTTON_REPEAT
:
674 selection
= (selection
+ 1)%menu_length
;
675 if( !selection
) selection
++;
682 case ROCKPAINT_RIGHT
:
685 return menu
[selection
].value
;
689 if( selection
< scroll
)
692 draw_window( height
, width
, NULL
, NULL
, menu
[0].label
);
694 if( selection
>= scroll
+ onscreen
- 1 )
697 draw_window( height
, width
, NULL
, NULL
, menu
[0].label
);
703 /***********************************************************************
705 ***********************************************************************/
707 char bbuf
[MAX_PATH
+1]; /* used by file and font browsers */
708 char bbuf_s
[MAX_PATH
+1]; /* used by file and font browsers */
710 static bool browse( char *dst
, int dst_size
, const char *start
)
712 #define WIDTH ( LCD_WIDTH - 20 )
713 #define HEIGHT ( LCD_HEIGHT - 20 )
715 int top
, top_inside
, left
;
719 int fvi
= 0; /* first visible item */
720 int lvi
= 0; /* last visible item */
721 int si
= 0; /* selected item */
722 int li
= 0; /* last item */
728 rb
->lcd_getstringsize( "Ap", NULL
, &fh
);
730 rb
->strcpy( bbuf
, start
);
731 a
= bbuf
+rb
->strlen(bbuf
)-1;
740 d
= rb
->opendir( bbuf
);
744 if( errno == ENOTDIR )
747 bbuf
[rb
->strlen(bbuf
)-1] = '\0';
748 rb
->strncpy( dst
, bbuf
, dst_size
);
751 else if( errno == EACCES || errno == ENOENT )
753 bbuf[0] = '/'; bbuf[1] = '\0';
754 d = rb->opendir( "/" );
761 top_inside
= draw_window( HEIGHT
, WIDTH
, &top
, &left
, bbuf
);
769 while( top_inside
+(i
-fvi
)*(fh
+LINE_SPACE
) < HEIGHT
)
771 de
= rb
->readdir( d
);
777 rb
->lcd_set_foreground((si
==i
?COLOR_WHITE
:COLOR_BLACK
));
778 rb
->lcd_set_background((si
==i
?COLOR_BLUE
:COLOR_LIGHTGRAY
));
779 rb
->lcd_putsxy( left
+10,
780 top_inside
+(i
-fvi
)*(fh
+LINE_SPACE
),
783 rb
->strcpy( bbuf_s
, de
->d_name
);
789 if( !rb
->readdir( d
) )
798 switch( rb
->button_get(true) )
801 case ROCKPAINT_UP
|BUTTON_REPEAT
:
813 case ROCKPAINT_DOWN
|BUTTON_REPEAT
:
814 if( li
== -1 || si
< li
)
825 if( bbuf
[0] == '/' && !bbuf
[1] ) return false;
829 case ROCKPAINT_RIGHT
:
831 if( *bbuf_s
== '.' && !bbuf_s
[1] ) break;
834 if( *bbuf_s
== '.' && bbuf_s
[1] == '.' && !bbuf_s
[2] )
837 if( a
== bbuf
) break;
839 while( *a
!= '/' ) a
--;
843 rb
->strcpy( a
, bbuf_s
);
857 /***********************************************************************
860 * FIXME: This still needs some work ... it currently only works fine
861 * on the simulators, disk spins too much on real targets -> rendered
862 * font buffer needed.
863 ***********************************************************************/
864 static bool browse_fonts( char *dst
, int dst_size
)
866 char old_font
[MAX_PATH
];
867 #define WIDTH ( LCD_WIDTH - 20 )
868 #define HEIGHT ( LCD_HEIGHT - 20 )
870 int top
, top_inside
= 0, left
;
874 int fvi
= 0; /* first visible item */
875 int lvi
= 0; /* last visible item */
876 int si
= 0; /* selected item */
877 int osi
= 0; /* old selected item */
878 int li
= 0; /* last item */
879 int nvih
= 0; /* next visible item height */
881 int b_need_redraw
= 1; /* Do we need to redraw ? */
883 int cp
= 0; /* current position */
884 int fh
; /* font height */
886 #define fh_buf buffer.text.fh_buf /* 30 might not be enough ... */
887 #define fw_buf buffer.text.fw_buf
889 #define fontname_buf buffer.text.fontname_buf
891 rb
->snprintf( old_font
, MAX_PATH
,
893 rb
->global_settings
->font_file
);
899 /* we don't need to redraw ... but we need to unselect
900 * the previously selected item */
901 cp
= top_inside
+ LINE_SPACE
;
902 for( i
= 0; i
+fvi
< osi
; i
++ )
904 cp
+= fh_buf
[i
] + LINE_SPACE
;
906 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
907 rb
->lcd_fillrect( left
+10, cp
, fw_buf
[i
], fh_buf
[i
] );
908 rb
->lcd_set_drawmode(DRMODE_SOLID
);
915 d
= rb
->opendir( FONT_DIR
"/" );
920 top_inside
= draw_window( HEIGHT
, WIDTH
, &top
, &left
, "Fonts" );
928 cp
= top_inside
+LINE_SPACE
;
930 rb
->lcd_set_foreground(COLOR_BLACK
);
931 rb
->lcd_set_background(COLOR_LIGHTGRAY
);
933 while( cp
< top
+HEIGHT
)
935 de
= rb
->readdir( d
);
941 if( rb
->strlen( de
->d_name
) < 4
942 || rb
->strcmp( de
->d_name
+ rb
->strlen( de
->d_name
) - 4,
945 rb
->snprintf( bbuf
, MAX_PATH
, FONT_DIR
"/%s",
947 rb
->font_load( bbuf
);
948 rb
->font_getstringsize( de
->d_name
, &fw
, &fh
, FONT_UI
);
953 if( nvih
< 0 ) nvih
= 0;
957 if( cp
+ fh
>= top
+HEIGHT
)
962 rb
->lcd_putsxy( left
+10, cp
, de
->d_name
);
965 cp
+= fh
+ LINE_SPACE
;
966 rb
->strcpy( fontname_buf
[i
-fvi
], bbuf
);
972 if( !(de
= rb
->readdir( d
) ) )
976 else if( !nvih
&& !rb
->strlen( de
->d_name
) < 4
977 && !rb
->strcmp( de
->d_name
+ rb
->strlen( de
->d_name
) - 4,
980 rb
->snprintf( bbuf
, MAX_PATH
, FONT_DIR
"/%s",
982 rb
->font_load( bbuf
);
983 rb
->font_getstringsize( de
->d_name
, NULL
, &fh
, FONT_UI
);
987 rb
->font_load( old_font
);
991 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
992 cp
= top_inside
+ LINE_SPACE
;
993 for( i
= 0; i
+fvi
< si
; i
++ )
995 cp
+= fh_buf
[i
] + LINE_SPACE
;
997 rb
->lcd_fillrect( left
+10, cp
, fw_buf
[i
], fh_buf
[i
] );
998 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1000 rb
->lcd_update_rect( left
, top
, WIDTH
, HEIGHT
);
1004 switch( rb
->button_get(true) )
1007 case ROCKPAINT_UP
|BUTTON_REPEAT
:
1018 case ROCKPAINT_DOWN
:
1019 case ROCKPAINT_DOWN
|BUTTON_REPEAT
:
1020 if( li
== -1 || si
< li
)
1026 case ROCKPAINT_LEFT
:
1029 case ROCKPAINT_RIGHT
:
1030 case ROCKPAINT_DRAW
:
1031 rb
->snprintf( dst
, dst_size
, "%s", fontname_buf
[si
-fvi
] );
1035 if( i
!= fvi
|| si
> lvi
)
1053 /***********************************************************************
1054 * HSVRGB Color chooser
1055 ***********************************************************************/
1056 static unsigned int color_chooser( unsigned int color
)
1058 int red
= RGB_UNPACK_RED( color
);
1059 int green
= RGB_UNPACK_GREEN( color
);
1060 int blue
= RGB_UNPACK_BLUE( color
);
1061 int hue
, saturation
, value
;
1062 int r
, g
, b
; /* temp variables */
1065 enum BaseColor
{ Hue
= 0, Saturation
= 1, Value
= 2,
1066 Red
= 3, Green
= 4, Blue
= 5 };
1067 enum BaseColor current
= Red
;
1074 rgb2hsv( red
, green
, blue
, &hue
, &saturation
, &value
);
1078 has_changed
= false;
1079 color
= LCD_RGBPACK( red
, green
, blue
);
1081 #define HEIGHT ( 100 )
1082 #define WIDTH ( 150 )
1084 top
= draw_window( HEIGHT
, WIDTH
, NULL
, &left
, "Color chooser" );
1087 for( i
=0; i
<100; i
++ )
1089 hsv2rgb( i
*36, saturation
, value
, &r
, &g
, &b
);
1090 rb
->lcd_set_foreground( LCD_RGBPACK( r
, g
, b
) );
1091 rb
->lcd_vline( left
+15+i
, top
+20, top
+27 );
1092 hsv2rgb( hue
, i
*255/100, value
, &r
, &g
, &b
);
1093 rb
->lcd_set_foreground( LCD_RGBPACK( r
, g
, b
) );
1094 rb
->lcd_vline( left
+15+i
, top
+30, top
+37 );
1095 hsv2rgb( hue
, saturation
, i
*255/100, &r
, &g
, &b
);
1096 rb
->lcd_set_foreground( LCD_RGBPACK( r
, g
, b
) );
1097 rb
->lcd_vline( left
+15+i
, top
+40, top
+47 );
1098 rb
->lcd_set_foreground( LCD_RGBPACK( i
*255/100, green
, blue
) );
1099 rb
->lcd_vline( left
+15+i
, top
+50, top
+57 );
1100 rb
->lcd_set_foreground( LCD_RGBPACK( red
, i
*255/100, blue
) );
1101 rb
->lcd_vline( left
+15+i
, top
+60, top
+67 );
1102 rb
->lcd_set_foreground( LCD_RGBPACK( red
, green
, i
*255/100 ) );
1103 rb
->lcd_vline( left
+15+i
, top
+70, top
+77 );
1106 rb
->lcd_set_foreground(COLOR_BLACK
);
1107 #define POSITION( a, i ) \
1108 rb->lcd_drawpixel( left+14+i, top + 19 + a ); \
1109 rb->lcd_drawpixel( left+16+i, top + 19 + a ); \
1110 rb->lcd_drawpixel( left+14+i, top + 28 + a ); \
1111 rb->lcd_drawpixel( left+16+i, top + 28 + a );
1112 POSITION( 0, hue
/36 );
1113 POSITION( 10, saturation
*99/255 );
1114 POSITION( 20, value
*99/255 );
1115 POSITION( 30, red
*99/255 );
1116 POSITION( 40, green
*99/255 );
1117 POSITION( 50, blue
*99/255 );
1119 rb
->lcd_set_background(COLOR_LIGHTGRAY
);
1120 rb
->lcd_setfont( FONT_SYSFIXED
);
1121 rb
->snprintf( str
, 6, "%d", hue
/10 );
1122 rb
->lcd_putsxy( left
+ 117, top
+ 20, str
);
1123 rb
->snprintf( str
, 6, "%d.%d", saturation
/255, ((saturation
*100)/255)%100 );
1124 rb
->lcd_putsxy( left
+ 117, top
+ 30, str
);
1125 rb
->snprintf( str
, 6, "%d.%d", value
/255, ((value
*100)/255)%100 );
1126 rb
->lcd_putsxy( left
+ 117, top
+ 40, str
);
1127 rb
->snprintf( str
, 6, "%d", red
);
1128 rb
->lcd_putsxy( left
+ 117, top
+ 50, str
);
1129 rb
->snprintf( str
, 6, "%d", green
);
1130 rb
->lcd_putsxy( left
+ 117, top
+ 60, str
);
1131 rb
->snprintf( str
, 6, "%d", blue
);
1132 rb
->lcd_putsxy( left
+ 117, top
+ 70, str
);
1133 rb
->lcd_setfont( FONT_UI
);
1135 #define CURSOR( l ) \
1136 rb->lcd_bitmap_transparent_part( rockpaint_hsvrgb, 1, 1, 16, left+l+1, top+20, 6, 58 ); \
1137 rb->lcd_bitmap_transparent_part( rockpaint_hsvrgb, 8, 10*current, 16, left+l, top+19+10*current, 8, 10 );
1141 rb
->lcd_set_foreground( color
);
1142 rb
->lcd_fillrect( left
+15, top
+85, 100, 8 );
1146 switch( rb
->button_get(true) )
1149 current
= ( current
+ 5 )%6;
1152 case ROCKPAINT_DOWN
:
1153 current
= (current
+ 1 )%6;
1156 case ROCKPAINT_LEFT
:
1161 hue
= ( hue
+ 3600 - 10 )%3600;
1164 if( saturation
) saturation
--;
1167 if( value
) value
--;
1173 if( green
) green
--;
1181 case ROCKPAINT_LEFT
|BUTTON_REPEAT
:
1186 hue
= ( hue
+ 3600 - 100 )%3600;
1189 if( saturation
>= 8 ) saturation
-=8;
1190 else saturation
= 0;
1193 if( value
>= 8 ) value
-=8;
1197 if( red
>= 8 ) red
-=8;
1201 if( green
>= 8 ) green
-=8;
1205 if( blue
>= 8 ) blue
-=8;
1211 case ROCKPAINT_RIGHT
:
1216 hue
= ( hue
+ 10 )%3600;
1219 if( saturation
< 0xff ) saturation
++;
1222 if( value
< 0xff ) value
++;
1225 if( red
< 0xff ) red
++;
1228 if( green
< 0xff ) green
++;
1231 if( blue
< 0xff ) blue
++;
1236 case ROCKPAINT_RIGHT
|BUTTON_REPEAT
:
1241 hue
= ( hue
+ 100 )%3600;
1244 if( saturation
< 0xff - 8 ) saturation
+=8;
1245 else saturation
= 0xff;
1248 if( value
< 0xff - 8 ) value
+=8;
1252 if( red
< 0xff - 8 ) red
+=8;
1256 if( green
< 0xff - 8 ) green
+=8;
1260 if( blue
< 0xff - 8 ) blue
+=8;
1266 case ROCKPAINT_DRAW
:
1276 hsv2rgb( hue
, saturation
, value
, &red
, &green
, &blue
);
1282 rgb2hsv( red
, green
, blue
, &hue
, &saturation
, &value
);
1291 /***********************************************************************
1293 ***********************************************************************/
1294 static void init_buffer(void)
1297 fb_data color
= rp_colors
[ bgdrawcolor
];
1298 for( i
= 0; i
< ROWS
*COLS
; i
++ )
1300 save_buffer
[i
] = color
;
1304 static void draw_pixel(int x
,int y
)
1308 if( x
< 0 || x
>= COLS
|| y
< 0 || y
>= ROWS
) return;
1311 save_buffer
[ x
+y
*COLS
] = rp_colors
[bgdrawcolor
];
1315 save_buffer
[ x
+y
*COLS
] = rp_colors
[drawcolor
];
1318 rb
->lcd_drawpixel(x
,y
);
1321 static void color_picker( int x
, int y
)
1325 rb
->lcd_set_foreground( save_buffer
[ x
+y
*COLS
] );
1327 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1328 rb
->lcd_drawrect( x
<COLS
-PSIZE
? x
+ 2 : x
- PSIZE
, y
<ROWS
-PSIZE
? y
+ 2: y
- PSIZE
, PSIZE
- 2, PSIZE
- 2 );
1329 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1330 rb
->lcd_fillrect( x
<COLS
-PSIZE
? x
+3 : x
- PSIZE
+1, y
<ROWS
-PSIZE
? y
+3: y
- PSIZE
+1, PSIZE
-4, PSIZE
-4 );
1332 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
1336 rp_colors
[ drawcolor
] = save_buffer
[ x
+y
*COLS
];
1340 static void draw_select_rectangle( int x1
, int y1
, int x2
, int y2
)
1341 /* This is a preview mode only function */
1356 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1358 for( a
= x1
; a
< x2
; a
++, i
++ )
1360 rb
->lcd_drawpixel( a
, y1
);
1361 for( a
= y1
; a
< y2
; a
++, i
++ )
1363 rb
->lcd_drawpixel( x2
, a
);
1365 for( a
= x2
; a
> x1
; a
--, i
++ )
1367 rb
->lcd_drawpixel( a
, y2
);
1369 for( a
= y2
; a
> y1
; a
--, i
++ )
1371 rb
->lcd_drawpixel( x1
, a
);
1372 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1375 static void copy_to_clipboard( void )
1377 /* This needs to be optimised ... but i'm lazy ATM */
1378 rb
->memcpy( buffer
.clipboard
, save_buffer
, COLS
*ROWS
*sizeof( fb_data
) );
1381 /* no preview mode handling atm ... do we need it ? (one if) */
1382 static void draw_invert( int x1
, int y1
, int x2
, int y2
)
1398 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1399 rb
->lcd_fillrect( x1
, y1
, x2
-x1
+1, y2
-y1
+1 );
1400 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1402 for( ; y1
<=y2
; y1
++ )
1404 for( i
= x1
; i
<=x2
; i
++ )
1406 save_buffer
[ y1
*COLS
+ i
] = ~save_buffer
[ y1
*COLS
+ i
];
1409 /*if( update )*/ rb
->lcd_update();
1412 static void draw_hflip( int x1
, int y1
, int x2
, int y2
)
1428 copy_to_clipboard();
1430 for( i
= 0; i
<= y2
- y1
; i
++ )
1432 rb
->memcpy( save_buffer
+(y1
+i
)*COLS
+x1
,
1433 buffer
.clipboard
+(y2
-i
)*COLS
+x1
,
1434 (x2
-x1
+1)*sizeof( fb_data
) );
1440 static void draw_vflip( int x1
, int y1
, int x2
, int y2
)
1456 copy_to_clipboard();
1458 for( ; y1
<= y2
; y1
++ )
1460 for( i
= 0; i
<= x2
- x1
; i
++ )
1462 save_buffer
[y1
*COLS
+x1
+i
] = buffer
.clipboard
[y1
*COLS
+x2
-i
];
1469 static void draw_paste_rectangle( int src_x1
, int src_y1
, int src_x2
,
1470 int src_y2
, int x1
, int y1
, int mode
)
1473 if( mode
== SELECT_MENU_CUT
)
1476 drawcolor
= bgdrawcolor
;
1477 draw_rect_full( src_x1
, src_y1
, src_x2
, src_y2
);
1480 if( src_x1
> src_x2
)
1486 if( src_y1
> src_y2
)
1492 rb
->lcd_bitmap_part( buffer
.clipboard
, src_x1
, src_y1
, COLS
,
1493 x1
, y1
, src_x2
-src_x1
+1, src_y2
-src_y1
+1 );
1496 for( i
= 0; i
<= src_y2
- src_y1
; i
++ )
1498 rb
->memcpy( save_buffer
+(y1
+i
)*COLS
+x1
,
1499 buffer
.clipboard
+(src_y1
+i
)*COLS
+src_x1
,
1500 (src_x2
- src_x1
+ 1)*sizeof( fb_data
) );
1505 static void show_grid( bool update
)
1510 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1511 for( i
= gridsize
; i
< COLS
; i
+= gridsize
)
1513 rb
->lcd_vline( i
, 0, ROWS
-1 );
1515 for( i
= gridsize
; i
< ROWS
; i
+= gridsize
)
1517 rb
->lcd_hline( 0, COLS
-1, i
);
1519 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1520 if( update
) rb
->lcd_update();
1524 static void draw_text( int x
, int y
)
1526 buffer
.text
.text
[0] = '\0';
1527 rb
->snprintf( buffer
.text
.old_font
, MAX_PATH
,
1529 rb
->global_settings
->font_file
);
1532 int m
= TEXT_MENU_TEXT
;
1533 switch( m
= menu_display( text_menu
, m
) )
1535 case TEXT_MENU_TEXT
:
1536 rb
->kbd_input( buffer
.text
.text
, MAX_TEXT
);
1540 case TEXT_MENU_FONT
:
1541 if( browse_fonts( buffer
.text
.font
, MAX_PATH
) )
1543 rb
->font_load( buffer
.text
.font
);
1547 case TEXT_MENU_PREVIEW
:
1548 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
1551 unsigned int button
;
1553 rb
->lcd_putsxy( x
, y
, buffer
.text
.text
);
1555 switch( button
= rb
->button_get( true ) )
1557 case ROCKPAINT_LEFT
:
1558 case ROCKPAINT_LEFT
| BUTTON_REPEAT
:
1559 x
-=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
1563 case ROCKPAINT_RIGHT
:
1564 case ROCKPAINT_RIGHT
| BUTTON_REPEAT
:
1565 x
+=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
1570 case ROCKPAINT_UP
| BUTTON_REPEAT
:
1571 y
-=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
1575 case ROCKPAINT_DOWN
:
1576 case ROCKPAINT_DOWN
| BUTTON_REPEAT
:
1577 y
+=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
1581 case ROCKPAINT_DRAW
:
1585 if( button
== 1242 ) break;
1589 case TEXT_MENU_APPLY
:
1590 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
1591 buffer_putsxyofs( save_buffer
, COLS
, ROWS
, x
, y
, 0,
1593 case TEXT_MENU_CANCEL
:
1595 rb
->font_load( buffer
.text
.old_font
);
1601 static void draw_brush( int x
, int y
)
1604 for( i
=-bsize
/2+(bsize
+1)%2; i
<=bsize
/2; i
++ )
1606 for( j
=-bsize
/2+(bsize
+1)%2; j
<=bsize
/2; j
++ )
1608 draw_pixel( x
+i
, y
+j
);
1613 /* This is an implementation of Bresenham's line algorithm.
1614 * See http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm.
1616 static void draw_line( int x1
, int y1
, int x2
, int y2
)
1620 int deltax
= x2
- x1
;
1621 int deltay
= y2
- y1
;
1624 int xerr
= abs(deltax
);
1625 int yerr
= abs(deltay
);
1626 int xstep
= deltax
> 0 ? 1 : -1;
1627 int ystep
= deltay
> 0 ? 1 : -1;
1637 /* to leave off the last pixel of the line, leave off the "+ 1" */
1638 for (i
= abs(deltay
) + 1; i
; --i
)
1651 /* more horizontal */
1656 for (i
= abs(deltax
) + 1; i
; --i
)
1669 static void draw_curve( int x1
, int y1
, int x2
, int y2
,
1670 int xa
, int ya
, int xb
, int yb
)
1684 if( x1
== x2
&& y1
== y2
)
1686 draw_pixel( x1
, y1
);
1692 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1693 if( xa
== -1 || ya
== -1 )
1695 rb
->lcd_drawline( x1
, y1
, xb
, yb
);
1696 rb
->lcd_drawline( x2
, y2
, xb
, yb
);
1700 rb
->lcd_drawline( x1
, y1
, xa
, ya
);
1701 rb
->lcd_drawline( x2
, y2
, xb
, yb
);
1703 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1706 if( xa
== -1 || ya
== -1 )
1707 /* We only have 3 of the points
1708 * This will currently only be used in preview mode */
1710 #define PUSH( a1, b1, a2, b2, a3, b3, d ) \
1711 buffer.bezier[i].x1 = a1; \
1712 buffer.bezier[i].y1 = b1; \
1713 buffer.bezier[i].x2 = a2; \
1714 buffer.bezier[i].y2 = b2; \
1715 buffer.bezier[i].x3 = a3; \
1716 buffer.bezier[i].y3 = b3; \
1717 buffer.bezier[i].depth = d; \
1719 #define POP( a1, b1, a2, b2, a3, b3, d ) \
1721 a1 = buffer.bezier[i].x1; \
1722 b1 = buffer.bezier[i].y1; \
1723 a2 = buffer.bezier[i].x2; \
1724 b2 = buffer.bezier[i].y2; \
1725 a3 = buffer.bezier[i].x3; \
1726 b3 = buffer.bezier[i].y3; \
1727 d = buffer.bezier[i].depth;
1728 PUSH( x1
<<4, y1
<<4, xb
<<4, yb
<<4, x2
<<4, y2
<<4, 0 );
1731 /* de Casteljau's algorithm (see wikipedia) */
1732 POP( xl1
, yl1
, xb
, yb
, xr3
, yr3
, depth
);
1733 if( depth
< 10 ) /* check that the stack's 'i' doesn't overflow */
1735 xl2
= ( xl1
+ xb
)>>1;
1736 yl2
= ( yl1
+ yb
)>>1;
1737 xr2
= ( xb
+ xr3
)>>1;
1738 yr2
= ( yb
+ yr3
)>>1;
1739 xr1
= ( xl2
+ xr2
)>>1;
1740 yr1
= ( yl2
+ yr2
)>>1;
1743 PUSH( xl1
, yl1
, xl2
, yl2
, xl3
, yl3
, depth
+1 );
1744 PUSH( xr1
, yr1
, xr2
, yr2
, xr3
, yr3
, depth
+1 );
1748 draw_line( ((xl1
>>3)+1)>>1, ((yl1
>>3)+1)>>1,
1749 ((xr3
>>3)+1)>>1, ((yr3
>>3)+1)>>1 );
1755 else /* We have the 4 points */
1757 #define PUSH( a1, b1, a2, b2, a3, b3, a4, b4, d ) \
1758 buffer.bezier[i].x1 = a1; \
1759 buffer.bezier[i].y1 = b1; \
1760 buffer.bezier[i].x2 = a2; \
1761 buffer.bezier[i].y2 = b2; \
1762 buffer.bezier[i].x3 = a3; \
1763 buffer.bezier[i].y3 = b3; \
1764 buffer.bezier[i].x4 = a4; \
1765 buffer.bezier[i].y4 = b4; \
1766 buffer.bezier[i].depth = d; \
1768 #define POP( a1, b1, a2, b2, a3, b3, a4, b4, d ) \
1770 a1 = buffer.bezier[i].x1; \
1771 b1 = buffer.bezier[i].y1; \
1772 a2 = buffer.bezier[i].x2; \
1773 b2 = buffer.bezier[i].y2; \
1774 a3 = buffer.bezier[i].x3; \
1775 b3 = buffer.bezier[i].y3; \
1776 a4 = buffer.bezier[i].x4; \
1777 b4 = buffer.bezier[i].y4; \
1778 d = buffer.bezier[i].depth;
1780 PUSH( x1
<<4, y1
<<4, xa
<<4, ya
<<4, xb
<<4, yb
<<4, x2
<<4, y2
<<4, 0 );
1783 /* de Casteljau's algorithm (see wikipedia) */
1784 POP( xl1
, yl1
, xa
, ya
, xb
, yb
, xr4
, yr4
, depth
);
1785 if( depth
< 10 ) /* check that the stack's 'i' doesn't overflow */
1787 xl2
= ( xl1
+ xa
)>>1;
1788 yl2
= ( yl1
+ ya
)>>1;
1789 xh
= ( xa
+ xb
)>>1;
1790 yh
= ( ya
+ yb
)>>1;
1791 xr3
= ( xb
+ xr4
)>>1;
1792 yr3
= ( yb
+ yr4
)>>1;
1793 xl3
= ( xl2
+ xh
)>>1;
1794 yl3
= ( yl2
+ yh
)>>1;
1795 xr2
= ( xr3
+ xh
)>>1;
1796 yr2
= ( yr3
+ yh
)>>1;
1797 xl4
= ( xl3
+ xr2
)>>1;
1798 yl4
= ( yl3
+ yr2
)>>1;
1801 PUSH( xl1
, yl1
, xl2
, yl2
, xl3
, yl3
, xl4
, yl4
, depth
+1 );
1802 PUSH( xr1
, yr1
, xr2
, yr2
, xr3
, yr3
, xr4
, yr4
, depth
+1 );
1806 draw_line( ((xl1
>>3)+1)>>1, ((yl1
>>3)+1)>>1,
1807 ((xr4
>>3)+1)>>1, ((yr4
>>3)+1)>>1 );
1815 static void draw_rect( int x1
, int y1
, int x2
, int y2
)
1817 draw_line( x1
, y1
, x1
, y2
);
1818 draw_line( x1
, y1
, x2
, y1
);
1819 draw_line( x1
, y2
, x2
, y2
);
1820 draw_line( x2
, y1
, x2
, y2
);
1823 static void togglebg( void )
1827 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
1831 rb
->lcd_set_foreground( rp_colors
[ bgdrawcolor
] );
1836 static void draw_rect_full( int x1
, int y1
, int x2
, int y2
)
1844 draw_line( x
, y1
, x
, y2
);
1845 } while( ++x
<= x2
);
1850 draw_line( x
, y1
, x
, y2
);
1851 } while( --x
>= x2
);
1854 draw_rect( x1
, y1
, x2
, y2
);
1857 static void draw_oval( int x1
, int y1
, int x2
, int y2
, bool full
)
1859 /* TODO: simplify :) */
1860 int cx
= (x1
+x2
)>>1;
1861 int cy
= (y1
+y2
)>>1;
1863 int rx
= (x1
-x2
)>>1;
1864 int ry
= (y1
-y2
)>>1;
1865 if( rx
< 0 ) rx
*= -1;
1866 if( ry
< 0 ) ry
*= -1;
1868 if( rx
== 0 || ry
== 0 )
1870 draw_line( x1
, y1
, x2
, y2
);
1877 for( x
= 0; x
< rx
; x
++ )
1883 dst
= ry
* ry
* x
* x
+ rx
* rx
* y
* y
- rx
* rx
* ry
* ry
;
1886 if( -old_dst
< dst
) y
--;
1889 draw_line( cx
+x
, cy
, cx
+x
, cy
+y
);
1890 draw_line( cx
+x
, cy
, cx
+x
, cy
-y
);
1891 draw_line( cx
-x
, cy
, cx
-x
, cy
+y
);
1892 draw_line( cx
-x
, cy
, cx
-x
, cy
-y
);
1896 draw_pixel( cx
+x
, cy
+y
);
1897 draw_pixel( cx
+x
, cy
-y
);
1898 draw_pixel( cx
-x
, cy
+y
);
1899 draw_pixel( cx
-x
, cy
-y
);
1902 for( y
= 0; y
< ry
; y
++ )
1908 dst
= ry
* ry
* x
* x
+ rx
* rx
* y
* y
- rx
* rx
* ry
* ry
;
1911 if( -old_dst
< dst
) x
--;
1914 draw_line( cx
+x
, cy
, cx
+x
, cy
+y
);
1915 draw_line( cx
+x
, cy
, cx
+x
, cy
-y
);
1916 draw_line( cx
-x
, cy
, cx
-x
, cy
+y
);
1917 draw_line( cx
-x
, cy
, cx
-x
, cy
-y
);
1921 draw_pixel( cx
+x
, cy
+y
);
1922 draw_pixel( cx
+x
, cy
-y
);
1923 draw_pixel( cx
-x
, cy
+y
);
1924 draw_pixel( cx
-x
, cy
-y
);
1929 static void draw_oval_empty( int x1
, int y1
, int x2
, int y2
)
1931 draw_oval( x1
, y1
, x2
, y2
, false );
1934 static void draw_oval_full( int x1
, int y1
, int x2
, int y2
)
1937 draw_oval( x1
, y1
, x2
, y2
, true );
1939 draw_oval( x1
, y1
, x2
, y2
, false );
1942 static void draw_fill( int x0
, int y0
)
1944 #define PUSH( a, b ) \
1945 draw_pixel( (int)a, (int)b ); \
1946 buffer.coord[i].x = a; \
1947 buffer.coord[i].y = b; \
1949 #define POP( a, b ) \
1951 a = buffer.coord[i].x; \
1952 b = buffer.coord[i].y;
1957 unsigned int prev_color
= save_buffer
[ x0
+y0
*COLS
];
1959 if( prev_color
== rp_colors
[ drawcolor
] ) return;
1966 if( x
> 0 && save_buffer
[x
-1+y
*COLS
] == prev_color
)
1970 if( x
< COLS
-1 && save_buffer
[x
+1+y
*COLS
] == prev_color
)
1974 if( y
> 0 && save_buffer
[x
+(y
-1)*COLS
] == prev_color
)
1978 if( y
< ROWS
- 1 && save_buffer
[x
+(y
+1)*COLS
] == prev_color
)
1988 /* For preview purposes only */
1989 static void line_gradient( int x1
, int y1
, int x2
, int y2
)
1993 int h1
, s1
, v1
, h2
, s2
, v2
, r
, g
, b
;
2006 if( w
== 0 && h
== 0 )
2008 draw_pixel( x1
>>1, y1
>>1 );
2012 r1
= RGB_UNPACK_RED( rp_colors
[ bgdrawcolor
] );
2013 g1
= RGB_UNPACK_GREEN( rp_colors
[ bgdrawcolor
] );
2014 b1
= RGB_UNPACK_BLUE( rp_colors
[ bgdrawcolor
] );
2015 r2
= RGB_UNPACK_RED( rp_colors
[ drawcolor
] );
2016 g2
= RGB_UNPACK_GREEN( rp_colors
[ drawcolor
] );
2017 b2
= RGB_UNPACK_BLUE( rp_colors
[ drawcolor
] );
2042 rgb2hsv( r1
, g1
, b1
, &h1
, &s1
, &v1
);
2043 rgb2hsv( r2
, g2
, b2
, &h2
, &s2
, &v2
);
2060 hsv2rgb( h1
+((h2
-h1
)*(x1
-x2
))/w
,
2061 s1
+((s2
-s1
)*(x1
-x2
))/w
,
2062 v1
+((v2
-v1
)*(x1
-x2
))/w
,
2064 rp_colors
[ drawcolor
] = LCD_RGBPACK( r
, g
, b
);
2065 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
2066 draw_pixel( (x1
+1)>>1, (y1
+1)>>1 );
2068 y1
= y2
- ( x2
- x1
) * h
/ w
;
2086 hsv2rgb( h1
+((h2
-h1
)*(y1
-y2
))/h
,
2087 s1
+((s2
-s1
)*(y1
-y2
))/h
,
2088 v1
+((v2
-v1
)*(y1
-y2
))/h
,
2090 rp_colors
[ drawcolor
] = LCD_RGBPACK( r
, g
, b
);
2091 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
2092 draw_pixel( (x1
+1)>>1, (y1
+1)>>1 );
2094 x1
= x2
- ( y2
- y1
) * w
/ h
;
2099 rp_colors
[ drawcolor
] = LCD_RGBPACK( r1
, g1
, b1
);
2103 rp_colors
[ drawcolor
] = LCD_RGBPACK( r2
, g2
, b2
);
2107 static void linear_gradient( int x1
, int y1
, int x2
, int y2
)
2109 int r1
= RGB_UNPACK_RED( rp_colors
[ bgdrawcolor
] );
2110 int g1
= RGB_UNPACK_GREEN( rp_colors
[ bgdrawcolor
] );
2111 int b1
= RGB_UNPACK_BLUE( rp_colors
[ bgdrawcolor
] );
2112 int r2
= RGB_UNPACK_RED( rp_colors
[ drawcolor
] );
2113 int g2
= RGB_UNPACK_GREEN( rp_colors
[ drawcolor
] );
2114 int b2
= RGB_UNPACK_BLUE( rp_colors
[ drawcolor
] );
2116 int h1
, s1
, v1
, h2
, s2
, v2
, r
, g
, b
;
2119 int radius2
= ( x1
- x2
) * ( x1
- x2
) + ( y1
- y2
) * ( y1
- y2
);
2122 /* We only propagate the gradient to neighboring pixels with the same
2123 * color as ( x1, y1 ) */
2124 unsigned int prev_color
= save_buffer
[ x1
+y1
*COLS
];
2129 if( radius2
== 0 ) return;
2132 line_gradient( x1
, y1
, x2
, y2
);
2135 rgb2hsv( r1
, g1
, b1
, &h1
, &s1
, &v1
);
2136 rgb2hsv( r2
, g2
, b2
, &h2
, &s2
, &v2
);
2138 #define PUSH( x0, y0 ) \
2139 buffer.coord[i].x = (short)(x0); \
2140 buffer.coord[i].y = (short)(y0); \
2142 #define POP( a, b ) \
2144 a = (int)buffer.coord[i].x; \
2145 b = (int)buffer.coord[i].y;
2153 dist2
= ( x2
- x1
) * ( x
- x1
) + ( y2
- y1
) * ( y
- y1
);
2156 rp_colors
[ drawcolor
] = rp_colors
[ bgdrawcolor
];
2158 else if( dist2
< radius2
)
2160 hsv2rgb( h1
+((h2
-h1
)*dist2
)/radius2
,
2161 s1
+((s2
-s1
)*dist2
)/radius2
,
2162 v1
+((v2
-v1
)*dist2
)/radius2
,
2164 rp_colors
[ drawcolor
] = LCD_RGBPACK( r
, g
, b
);
2168 rp_colors
[ drawcolor
] = LCD_RGBPACK( r2
, g2
, b2
);
2170 if( rp_colors
[ drawcolor
] == prev_color
)
2172 if( rp_colors
[ drawcolor
])
2173 rp_colors
[ drawcolor
]--; /* GRUIK */
2175 rp_colors
[ drawcolor
]++; /* GRUIK */
2177 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
2180 if( x
> 0 && save_buffer
[x
-1+y
*COLS
] == prev_color
)
2184 if( x
< COLS
-1 && save_buffer
[x
+1+y
*COLS
] == prev_color
)
2188 if( y
> 0 && save_buffer
[x
+(y
-1)*COLS
] == prev_color
)
2192 if( y
< ROWS
- 1 && save_buffer
[x
+(y
+1)*COLS
] == prev_color
)
2200 rp_colors
[ drawcolor
] = LCD_RGBPACK( r2
, g2
, b2
);
2203 static void radial_gradient( int x1
, int y1
, int x2
, int y2
)
2205 int r1
= RGB_UNPACK_RED( rp_colors
[ bgdrawcolor
] );
2206 int g1
= RGB_UNPACK_GREEN( rp_colors
[ bgdrawcolor
] );
2207 int b1
= RGB_UNPACK_BLUE( rp_colors
[ bgdrawcolor
] );
2208 int r2
= RGB_UNPACK_RED( rp_colors
[ drawcolor
] );
2209 int g2
= RGB_UNPACK_GREEN( rp_colors
[ drawcolor
] );
2210 int b2
= RGB_UNPACK_BLUE( rp_colors
[ drawcolor
] );
2212 int h1
, s1
, v1
, h2
, s2
, v2
, r
, g
, b
;
2215 int radius2
= ( x1
- x2
) * ( x1
- x2
) + ( y1
- y2
) * ( y1
- y2
);
2218 /* We only propagate the gradient to neighboring pixels with the same
2219 * color as ( x1, y1 ) */
2220 unsigned int prev_color
= save_buffer
[ x1
+y1
*COLS
];
2225 if( radius2
== 0 ) return;
2228 line_gradient( x1
, y1
, x2
, y2
);
2231 rgb2hsv( r1
, g1
, b1
, &h1
, &s1
, &v1
);
2232 rgb2hsv( r2
, g2
, b2
, &h2
, &s2
, &v2
);
2234 #define PUSH( x0, y0 ) \
2235 buffer.coord[i].x = (short)(x0); \
2236 buffer.coord[i].y = (short)(y0); \
2238 #define POP( a, b ) \
2240 a = (int)buffer.coord[i].x; \
2241 b = (int)buffer.coord[i].y;
2249 if( ( dist2
= (x1
-(x
))*(x1
-(x
))+(y1
-(y
))*(y1
-(y
)) ) < radius2
)
2251 hsv2rgb( h1
+((h2
-h1
)*dist2
)/radius2
,
2252 s1
+((s2
-s1
)*dist2
)/radius2
,
2253 v1
+((v2
-v1
)*dist2
)/radius2
,
2255 rp_colors
[ drawcolor
] = LCD_RGBPACK( r
, g
, b
);
2259 rp_colors
[ drawcolor
] = LCD_RGBPACK( r2
, g2
, b2
);
2261 if( rp_colors
[ drawcolor
] == prev_color
)
2263 if( rp_colors
[ drawcolor
])
2264 rp_colors
[ drawcolor
]--; /* GRUIK */
2266 rp_colors
[ drawcolor
]++; /* GRUIK */
2268 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
2271 if( x
> 0 && save_buffer
[x
-1+y
*COLS
] == prev_color
)
2275 if( x
< COLS
-1 && save_buffer
[x
+1+y
*COLS
] == prev_color
)
2279 if( y
> 0 && save_buffer
[x
+(y
-1)*COLS
] == prev_color
)
2283 if( y
< ROWS
- 1 && save_buffer
[x
+(y
+1)*COLS
] == prev_color
)
2291 rp_colors
[ drawcolor
] = LCD_RGBPACK( r2
, g2
, b2
);
2294 static void draw_toolbars(bool update
)
2297 #define TOP (LCD_HEIGHT-TB_HEIGHT)
2298 rb
->lcd_set_background( COLOR_LIGHTGRAY
);
2299 rb
->lcd_set_foreground( COLOR_LIGHTGRAY
);
2300 rb
->lcd_fillrect( 0, TOP
, LCD_WIDTH
, TB_HEIGHT
);
2301 rb
->lcd_set_foreground( COLOR_BLACK
);
2302 rb
->lcd_drawrect( 0, TOP
, LCD_WIDTH
, TB_HEIGHT
);
2304 rb
->lcd_set_foreground( rp_colors
[ bgdrawcolor
] );
2305 rb
->lcd_fillrect( TB_SC_BG_LEFT
, TOP
+TB_SC_BG_TOP
,
2306 TB_SC_SIZE
, TB_SC_SIZE
);
2307 rb
->lcd_set_foreground(ROCKPAINT_PALETTE
);
2308 rb
->lcd_drawrect( TB_SC_BG_LEFT
, TOP
+TB_SC_BG_TOP
,
2309 TB_SC_SIZE
, TB_SC_SIZE
);
2310 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
2311 rb
->lcd_fillrect( TB_SC_FG_LEFT
, TOP
+TB_SC_FG_TOP
,
2312 TB_SC_SIZE
, TB_SC_SIZE
);
2313 rb
->lcd_set_foreground(ROCKPAINT_PALETTE
);
2314 rb
->lcd_drawrect( TB_SC_FG_LEFT
, TOP
+TB_SC_FG_TOP
,
2315 TB_SC_SIZE
, TB_SC_SIZE
);
2317 for( i
=0; i
<18; i
++ )
2319 rb
->lcd_set_foreground( rp_colors
[i
] );
2321 TB_PL_LEFT
+(i
%9)*( TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
),
2322 TOP
+TB_PL_TOP
+(i
/9)*( TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
),
2323 TB_PL_COLOR_SIZE
, TB_PL_COLOR_SIZE
);
2324 rb
->lcd_set_foreground( ROCKPAINT_PALETTE
);
2326 TB_PL_LEFT
+(i
%9)*( TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
),
2327 TOP
+TB_PL_TOP
+(i
/9)*( TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
),
2328 TB_PL_COLOR_SIZE
, TB_PL_COLOR_SIZE
);
2331 #define SEPARATOR( x, y ) \
2332 rb->lcd_set_foreground( COLOR_WHITE ); \
2333 rb->lcd_vline( x, TOP+y, TOP+y+TB_PL_HEIGHT-1 ); \
2334 rb->lcd_set_foreground( COLOR_DARKGRAY ); \
2335 rb->lcd_vline( x+1, TOP+y, TOP+y+TB_PL_HEIGHT-1 );
2336 SEPARATOR( TB_PL_LEFT
+ TB_PL_WIDTH
- 1 + TB_SP_MARGIN
, TB_PL_TOP
);
2338 rb
->lcd_bitmap_transparent( rockpaint
, TB_TL_LEFT
, TOP
+TB_TL_TOP
,
2339 TB_TL_WIDTH
, TB_TL_HEIGHT
);
2340 rb
->lcd_set_foreground(ROCKPAINT_PALETTE
);
2341 rb
->lcd_drawrect( TB_TL_LEFT
+(TB_TL_SIZE
+TB_TL_SPACING
)*(tool
/2),
2342 TOP
+TB_TL_TOP
+(TB_TL_SIZE
+TB_TL_SPACING
)*(tool
%2),
2343 TB_TL_SIZE
, TB_TL_SIZE
);
2345 SEPARATOR( TB_TL_LEFT
+ TB_TL_WIDTH
- 1 + TB_SP_MARGIN
, TB_TL_TOP
);
2347 rb
->lcd_setfont( FONT_SYSFIXED
);
2348 rb
->lcd_putsxy( TB_MENU_LEFT
, TOP
+TB_MENU_TOP
, "Menu" );
2349 rb
->lcd_setfont( FONT_UI
);
2352 if( update
) rb
->lcd_update();
2355 static void toolbar( void )
2359 draw_toolbars( false );
2360 y
= LCD_HEIGHT
-TB_HEIGHT
/2;
2364 switch( button
= rb
->button_get( true ) )
2366 case ROCKPAINT_DRAW
:
2367 #define TOP ( LCD_HEIGHT - TB_HEIGHT )
2368 if( y
>= TOP
+ TB_SC_FG_TOP
2369 && y
< TOP
+ TB_SC_FG_TOP
+ TB_SC_SIZE
2370 && x
>= TB_SC_FG_LEFT
2371 && x
< TB_SC_FG_LEFT
+ TB_SC_SIZE
)
2373 /* click on the foreground color */
2374 rp_colors
[drawcolor
] = color_chooser( rp_colors
[drawcolor
] );
2376 else if( y
>= TOP
+ TB_SC_BG_TOP
2377 && y
< TOP
+ TB_SC_BG_TOP
+ TB_SC_SIZE
2378 && x
>= TB_SC_BG_LEFT
2379 && x
< TB_SC_BG_LEFT
+ TB_SC_SIZE
)
2381 /* click on the background color */
2383 drawcolor
= bgdrawcolor
;
2386 else if( y
>= TOP
+ TB_PL_TOP
2387 && y
< TOP
+ TB_PL_TOP
+ TB_PL_HEIGHT
2389 && x
< TB_PL_LEFT
+ TB_PL_WIDTH
)
2391 /* click on the palette */
2392 i
= (x
- TB_PL_LEFT
)%(TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
);
2393 j
= (y
- (TOP
+TB_PL_TOP
) )%(TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
);
2394 if( i
>= TB_PL_COLOR_SIZE
|| j
>= TB_PL_COLOR_SIZE
)
2396 i
= ( x
- TB_PL_LEFT
)/(TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
);
2397 j
= ( y
- (TOP
+TB_PL_TOP
) )/(TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
);
2398 drawcolor
= j
*(TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
)+i
;
2400 else if( y
>= TOP
+TB_TL_TOP
2401 && y
< TOP
+ TB_TL_TOP
+ TB_TL_HEIGHT
2403 && x
<= TB_TL_LEFT
+ TB_TL_WIDTH
)
2405 /* click on the tools */
2406 i
= (x
- TB_TL_LEFT
) % (TB_TL_SIZE
+TB_TL_SPACING
);
2407 j
= (y
- (TOP
+TB_TL_TOP
) ) %(TB_TL_SIZE
+TB_TL_SPACING
);
2408 if( i
>= TB_TL_SIZE
|| j
>= TB_TL_SIZE
) break;
2409 i
= ( x
- TB_TL_LEFT
)/(TB_TL_SIZE
+TB_TL_SPACING
);
2410 j
= ( y
- (TOP
+TB_TL_TOP
) )/(TB_TL_SIZE
+TB_TL_SPACING
);
2420 else if( x
>= TB_MENU_LEFT
&& y
>= TOP
+TB_MENU_TOP
-2)
2427 draw_toolbars( false );
2431 case ROCKPAINT_LEFT
:
2432 case ROCKPAINT_LEFT
| BUTTON_REPEAT
:
2434 x
-=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
2439 case ROCKPAINT_RIGHT
:
2440 case ROCKPAINT_RIGHT
| BUTTON_REPEAT
:
2442 x
+=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
2448 case ROCKPAINT_UP
| BUTTON_REPEAT
:
2450 y
-=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
2451 if (y
<LCD_HEIGHT
-TB_HEIGHT
)
2458 case ROCKPAINT_DOWN
:
2459 case ROCKPAINT_DOWN
| BUTTON_REPEAT
:
2461 y
+=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
2470 case ROCKPAINT_TOOLBAR
:
2471 case ROCKPAINT_TOOLBAR2
:
2478 static void inv_cursor(bool update
)
2480 rb
->lcd_set_foreground(COLOR_BLACK
);
2481 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
2482 /* cross painting */
2483 rb
->lcd_hline(x
-4,x
-1,y
);
2484 rb
->lcd_hline(x
+1,x
+4,y
);
2485 rb
->lcd_vline(x
,y
-4,y
-1);
2486 rb
->lcd_vline(x
,y
+1,y
+4);
2487 rb
->lcd_set_foreground(rp_colors
[drawcolor
]);
2488 rb
->lcd_set_drawmode(DRMODE_SOLID
);
2490 if( update
) rb
->lcd_update();
2493 static void restore_screen(void)
2495 rb
->lcd_bitmap( save_buffer
, 0, 0, COLS
, ROWS
);
2498 static void clear_drawing(void)
2501 rb
->lcd_set_foreground( rp_colors
[ bgdrawcolor
] );
2502 rb
->lcd_fillrect( 0, 0, COLS
, ROWS
);
2506 static void goto_menu(void)
2512 switch( menu_display( main_menu
, 1 ) )
2518 case MAIN_MENU_LOAD
:
2519 if( browse( filename
, MAX_PATH
, "/" ) )
2521 if( load_bitmap( filename
) <= 0 )
2523 rb
->splashf( 1*HZ
, "Error while loading %s",
2528 rb
->splashf( 1*HZ
, "Image loaded (%s)", filename
);
2536 case MAIN_MENU_SAVE
:
2538 rb
->strcpy(filename
,"/");
2539 if( !rb
->kbd_input( filename
, MAX_PATH
) )
2541 if(rb
->strlen(filename
) <= 4 ||
2542 rb
->strcasecmp(&filename
[rb
->strlen(filename
)-4], ".bmp"))
2543 rb
->strcat(filename
, ".bmp");
2544 save_bitmap( filename
);
2545 rb
->splashf( 1*HZ
, "File saved (%s)", filename
);
2549 case MAIN_MENU_BRUSH_SIZE
:
2550 multi
= menu_display( size_menu
, bsize
);
2555 case MAIN_MENU_BRUSH_SPEED
:
2556 multi
= menu_display( speed_menu
, bspeed
);
2561 case MAIN_MENU_COLOR
:
2562 rp_colors
[drawcolor
] = color_chooser( rp_colors
[drawcolor
] );
2565 case MAIN_MENU_GRID_SIZE
:
2566 multi
= menu_display( gridsize_menu
, gridsize
);
2571 case MAIN_MENU_EXIT
:
2575 case MAIN_MENU_RESUME
:
2582 static void reset_tool( void )
2594 static bool rockpaint_loop( void )
2600 button
= rb
->button_get(true);
2602 if( tool
== Brush
&& prev_x
!= -1 )
2606 else if( button
& BUTTON_REPEAT
)
2617 case ROCKPAINT_QUIT
:
2618 rb
->lcd_set_drawmode(DRMODE_SOLID
);
2621 case ROCKPAINT_MENU
:
2627 case ROCKPAINT_DRAW
:
2632 if( prev_x
== -1 ) prev_x
= 1;
2636 case SelectRectangle
:
2643 case LinearGradient
:
2644 case RadialGradient
:
2645 /* Curve uses 4 points, others use 2 */
2646 if( prev_x
== -1 || prev_y
== -1 )
2652 else if( tool
== Curve
2653 && ( prev_x2
== -1 || prev_y2
== -1 ) )
2658 else if( tool
== SelectRectangle
2659 && ( prev_x2
== -1 || prev_y2
== -1 ) )
2661 tool_mode
= menu_display( select_menu
,
2665 case SELECT_MENU_CUT
:
2666 case SELECT_MENU_COPY
:
2669 copy_to_clipboard();
2670 if( prev_x
< x
) x
= prev_x
;
2671 if( prev_y
< y
) y
= prev_y
;
2674 case SELECT_MENU_INVERT
:
2675 draw_invert( prev_x
, prev_y
, x
, y
);
2679 case SELECT_MENU_HFLIP
:
2680 draw_hflip( prev_x
, prev_y
, x
, y
);
2684 case SELECT_MENU_VFLIP
:
2685 draw_vflip( prev_x
, prev_y
, x
, y
);
2689 case SELECT_MENU_ROTATE90
:
2691 case SELECT_MENU_ROTATE180
:
2692 draw_hflip( prev_x
, prev_y
, x
, y
);
2693 draw_vflip( prev_x
, prev_y
, x
, y
);
2696 case SELECT_MENU_ROTATE270
:
2699 case SELECT_MENU_CANCEL
:
2707 else if( tool
== Curve
2708 && ( prev_x3
== -1 || prev_y3
== -1 ) )
2718 case SelectRectangle
:
2719 draw_paste_rectangle( prev_x
, prev_y
,
2724 draw_line( prev_x
, prev_y
, x
, y
);
2727 draw_curve( prev_x
, prev_y
,
2733 draw_rect( prev_x
, prev_y
, x
, y
);
2736 draw_rect_full( prev_x
, prev_y
, x
, y
);
2739 draw_oval_empty( prev_x
, prev_y
, x
, y
);
2742 draw_oval_full( prev_x
, prev_y
, x
, y
);
2744 case LinearGradient
:
2745 linear_gradient( prev_x
, prev_y
, x
, y
);
2747 case RadialGradient
:
2748 radial_gradient( prev_x
, prev_y
, x
, y
);
2762 color_picker( x
, y
);
2775 case ROCKPAINT_DRAW
|BUTTON_REPEAT
:
2778 /* 3 point bezier curve */
2780 draw_curve( prev_x
, prev_y
,
2790 case ROCKPAINT_TOOLBAR
:
2799 case ROCKPAINT_TOOLBAR2
:
2808 case ROCKPAINT_LEFT
:
2809 case ROCKPAINT_LEFT
| BUTTON_REPEAT
:
2811 x
-=bspeed
* accelaration
;
2816 case ROCKPAINT_RIGHT
:
2817 case ROCKPAINT_RIGHT
| BUTTON_REPEAT
:
2819 x
+=bspeed
* accelaration
;
2825 case ROCKPAINT_UP
| BUTTON_REPEAT
:
2827 y
-=bspeed
* accelaration
;
2832 case ROCKPAINT_DOWN
:
2833 case ROCKPAINT_DOWN
| BUTTON_REPEAT
:
2835 y
+=bspeed
* accelaration
;
2845 if (rb
->default_event_handler(button
) == SYS_USB_CONNECTED
)
2846 return PLUGIN_USB_CONNECTED
;
2849 if( tool
== Brush
&& prev_x
== 1 )
2855 if( preview
|| tool
== ColorPicker
)
2856 /* always preview color picker */
2861 case SelectRectangle
:
2862 if( prev_x2
== -1 || prev_y2
== -1 )
2864 /* we are defining the selection */
2865 draw_select_rectangle( prev_x
, prev_y
, x
, y
);
2869 /* we are pasting the selected data */
2870 draw_paste_rectangle( prev_x
, prev_y
, prev_x2
,
2871 prev_y2
, x
, y
, tool_mode
);
2872 prev_x3
= prev_x2
-prev_x
;
2873 if( prev_x3
< 0 ) prev_x3
*= -1;
2874 prev_y3
= prev_y2
-prev_y
;
2875 if( prev_y3
< 0 ) prev_y3
*= -1;
2876 draw_select_rectangle( x
, y
, x
+prev_x3
, y
+prev_y3
);
2886 draw_line( prev_x
, prev_y
, x
, y
);
2890 if( prev_x2
== -1 || prev_y2
== -1 )
2892 draw_line( prev_x
, prev_y
, x
, y
);
2896 draw_curve( prev_x
, prev_y
,
2904 draw_rect( prev_x
, prev_y
, x
, y
);
2908 draw_rect_full( prev_x
, prev_y
, x
, y
);
2912 draw_oval_empty( prev_x
, prev_y
, x
, y
);
2916 draw_oval_full( prev_x
, prev_y
, x
, y
);
2924 color_picker( x
, y
);
2928 case LinearGradient
:
2929 line_gradient( prev_x
, prev_y
, x
, y
);
2932 case RadialGradient
:
2933 line_gradient( prev_x
, prev_y
, x
, y
);
2952 static int load_bitmap( const char *file
)
2958 bm
.data
= (char*)save_buffer
;
2959 ret
= rb
->read_bmp_file( file
, &bm
, ROWS
*COLS
*sizeof( fb_data
),
2962 if((bm
.width
> COLS
) || ( bm
.height
> ROWS
))
2965 for( l
= bm
.height
-1; l
> 0; l
-- )
2967 rb
->memmove( save_buffer
+l
*COLS
, save_buffer
+l
*bm
.width
,
2968 sizeof( fb_data
)*bm
.width
);
2970 for( l
= 0; l
< bm
.height
; l
++ )
2972 rb
->memset( save_buffer
+l
*COLS
+bm
.width
, rp_colors
[ bgdrawcolor
],
2973 sizeof( fb_data
)*(COLS
-bm
.width
) );
2975 rb
->memset( save_buffer
+COLS
*bm
.height
, rp_colors
[ bgdrawcolor
],
2976 sizeof( fb_data
)*COLS
*(ROWS
-bm
.height
) );
2981 static int save_bitmap( char *file
)
2984 bm
.data
= (char*)save_buffer
;
2987 bm
.format
= FORMAT_NATIVE
;
2988 return save_bmp_file( file
, &bm
, rb
);
2991 enum plugin_status
plugin_start(const struct plugin_api
* api
, const void* parameter
)
2993 /** must have stuff **/
2996 rb
->lcd_set_foreground(COLOR_WHITE
);
2997 rb
->lcd_set_backdrop(NULL
);
2998 rb
->lcd_fillrect(0,0,LCD_WIDTH
,LCD_HEIGHT
);
2999 rb
->splash( HZ
/2, "Rock Paint");
3001 rb
->lcd_clear_display();
3007 if( load_bitmap( parameter
) <= 0 )
3009 rb
->splash( 1*HZ
, "File Open Error");
3014 rb
->splashf( 1*HZ
, "Image loaded (%s)", (char *)parameter
);
3016 rb
->strcpy( filename
, parameter
);
3025 return rockpaint_loop();