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)
32 #include "lib/pluginlib_bmp.h"
33 #include "lib/rgb_hsv.h"
34 #include "lib/playback_control.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 == SANSA_FUZE_PAD)
100 #define ROCKPAINT_QUIT (BUTTON_HOME|BUTTON_REPEAT)
101 #define ROCKPAINT_DRAW BUTTON_SELECT
102 #define ROCKPAINT_MENU ( BUTTON_SELECT | BUTTON_DOWN )
103 #define ROCKPAINT_TOOLBAR ( BUTTON_SELECT | BUTTON_LEFT )
104 #define ROCKPAINT_TOOLBAR2 ( BUTTON_SELECT | BUTTON_RIGHT )
105 #define ROCKPAINT_UP BUTTON_UP
106 #define ROCKPAINT_DOWN BUTTON_DOWN
107 #define ROCKPAINT_LEFT BUTTON_LEFT
108 #define ROCKPAINT_RIGHT BUTTON_RIGHT
110 #elif ( CONFIG_KEYPAD == IRIVER_H10_PAD )
111 #define ROCKPAINT_QUIT BUTTON_POWER
112 #define ROCKPAINT_DRAW BUTTON_FF
113 #define ROCKPAINT_MENU BUTTON_PLAY
114 #define ROCKPAINT_TOOLBAR BUTTON_REW
115 #define ROCKPAINT_TOOLBAR2 ( BUTTON_REW | BUTTON_LEFT )
116 #define ROCKPAINT_UP BUTTON_SCROLL_UP
117 #define ROCKPAINT_DOWN BUTTON_SCROLL_DOWN
118 #define ROCKPAINT_LEFT BUTTON_LEFT
119 #define ROCKPAINT_RIGHT BUTTON_RIGHT
121 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
122 #define ROCKPAINT_QUIT BUTTON_BACK
123 #define ROCKPAINT_DRAW BUTTON_SELECT
124 #define ROCKPAINT_MENU BUTTON_MENU
125 #define ROCKPAINT_TOOLBAR BUTTON_PLAY
126 #define ROCKPAINT_TOOLBAR2 ( BUTTON_PLAY | BUTTON_LEFT )
127 #define ROCKPAINT_UP BUTTON_UP
128 #define ROCKPAINT_DOWN BUTTON_DOWN
129 #define ROCKPAINT_LEFT BUTTON_LEFT
130 #define ROCKPAINT_RIGHT BUTTON_RIGHT
132 #elif ( CONFIG_KEYPAD == COWON_D2_PAD )
133 #define ROCKPAINT_QUIT BUTTON_POWER
134 #define ROCKPAINT_MENU BUTTON_MENU
136 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
137 #define ROCKPAINT_QUIT BUTTON_BACK
138 #define ROCKPAINT_DRAW BUTTON_SELECT
139 #define ROCKPAINT_MENU BUTTON_MENU
140 #define ROCKPAINT_TOOLBAR BUTTON_PLAY
141 #define ROCKPAINT_TOOLBAR2 ( BUTTON_PLAY | BUTTON_LEFT )
142 #define ROCKPAINT_UP BUTTON_UP
143 #define ROCKPAINT_DOWN BUTTON_DOWN
144 #define ROCKPAINT_LEFT BUTTON_LEFT
145 #define ROCKPAINT_RIGHT BUTTON_RIGHT
147 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
148 #define ROCKPAINT_QUIT BUTTON_POWER
149 #define ROCKPAINT_DRAW BUTTON_SELECT
150 #define ROCKPAINT_MENU BUTTON_MENU
151 #define ROCKPAINT_TOOLBAR BUTTON_VIEW
152 #define ROCKPAINT_TOOLBAR2 BUTTON_PLAYLIST
153 #define ROCKPAINT_UP BUTTON_UP
154 #define ROCKPAINT_DOWN BUTTON_DOWN
155 #define ROCKPAINT_LEFT BUTTON_LEFT
156 #define ROCKPAINT_RIGHT BUTTON_RIGHT
158 #elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
159 #define ROCKPAINT_QUIT BUTTON_POWER
160 #define ROCKPAINT_DRAW BUTTON_PLAY
161 #define ROCKPAINT_MENU BUTTON_MENU
162 #define ROCKPAINT_TOOLBAR BUTTON_RIGHT
163 #define ROCKPAINT_TOOLBAR2 BUTTON_LEFT
164 #define ROCKPAINT_UP BUTTON_UP
165 #define ROCKPAINT_DOWN BUTTON_DOWN
166 #define ROCKPAINT_LEFT BUTTON_PREV
167 #define ROCKPAINT_RIGHT BUTTON_NEXT
169 #elif ( CONFIG_KEYPAD == ONDAVX747_PAD )
170 #define ROCKPAINT_QUIT BUTTON_POWER
171 #define ROCKPAINT_MENU BUTTON_MENU
173 #elif ( CONFIG_KEYPAD == ONDAVX777_PAD )
174 #define ROCKPAINT_QUIT BUTTON_POWER
176 #elif CONFIG_KEYPAD == MROBE500_PAD
177 #define ROCKPAINT_QUIT BUTTON_POWER
179 #elif ( CONFIG_KEYPAD == SAMSUNG_YH_PAD )
180 #define ROCKPAINT_QUIT BUTTON_REC
181 #define ROCKPAINT_DRAW BUTTON_PLAY
182 #define ROCKPAINT_MENU BUTTON_FFWD
183 #define ROCKPAINT_TOOLBAR BUTTON_REW
184 #define ROCKPAINT_TOOLBAR2 ( BUTTON_REW | BUTTON_LEFT )
185 #define ROCKPAINT_UP BUTTON_UP
186 #define ROCKPAINT_DOWN BUTTON_DOWN
187 #define ROCKPAINT_LEFT BUTTON_LEFT
188 #define ROCKPAINT_RIGHT BUTTON_RIGHT
190 #elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
191 #define ROCKPAINT_QUIT BUTTON_REC
192 #define ROCKPAINT_DRAW BUTTON_PLAY
193 #define ROCKPAINT_MENU BUTTON_MENU
194 #define ROCKPAINT_TOOLBAR BUTTON_OK
195 #define ROCKPAINT_TOOLBAR2 BUTTON_CANCEL
196 #define ROCKPAINT_UP BUTTON_UP
197 #define ROCKPAINT_DOWN BUTTON_DOWN
198 #define ROCKPAINT_LEFT BUTTON_PREV
199 #define ROCKPAINT_RIGHT BUTTON_NEXT
202 #error "Please define keys for this keypad"
205 #ifdef HAVE_TOUCHSCREEN
206 #ifndef ROCKPAINT_QUIT
207 #define ROCKPAINT_QUIT BUTTON_TOPLEFT
209 #ifndef ROCKPAINT_DRAW
210 #define ROCKPAINT_DRAW BUTTON_CENTER
212 #ifndef ROCKPAINT_MENU
213 #define ROCKPAINT_MENU BUTTON_TOPRIGHT
215 #ifndef ROCKPAINT_TOOLBAR
216 #define ROCKPAINT_TOOLBAR BUTTON_BOTTOMLEFT
218 #ifndef ROCKPAINT_TOOLBAR2
219 #define ROCKPAINT_TOOLBAR2 BUTTON_BOTTOMRIGHT
222 #define ROCKPAINT_UP BUTTON_TOPMIDDLE
224 #ifndef ROCKPAINT_DOWN
225 #define ROCKPAINT_DOWN BUTTON_BOTTOMMIDDLE
227 #ifndef ROCKPAINT_LEFT
228 #define ROCKPAINT_LEFT BUTTON_MIDLEFT
230 #ifndef ROCKPAINT_RIGHT
231 #define ROCKPAINT_RIGHT BUTTON_MIDRIGHT
235 /***********************************************************************
236 * Palette Default Colors
237 ***********************************************************************/
238 #define COLOR_BLACK LCD_RGBPACK(0,0,0)
239 #define COLOR_WHITE LCD_RGBPACK(255,255,255)
240 #define COLOR_DARKGRAY LCD_RGBPACK(128,128,128)
241 #define COLOR_LIGHTGRAY LCD_RGBPACK(192,192,192)
242 #define COLOR_RED LCD_RGBPACK(128,0,0)
243 #define COLOR_LIGHTRED LCD_RGBPACK(255,0,0)
244 #define COLOR_DARKYELLOW LCD_RGBPACK(128,128,0)
245 #define COLOR_YELLOW LCD_RGBPACK(255,255,0)
246 #define COLOR_GREEN LCD_RGBPACK(0,128,0)
247 #define COLOR_LIGHTGREN LCD_RGBPACK(0,255,0)
248 #define COLOR_CYAN LCD_RGBPACK(0,128,128)
249 #define COLOR_LIGHTCYAN LCD_RGBPACK(0,255,255)
250 #define COLOR_BLUE LCD_RGBPACK(0,0,128)
251 #define COLOR_LIGHTBLUE LCD_RGBPACK(0,0,255)
252 #define COLOR_PURPLE LCD_RGBPACK(128,0,128)
253 #define COLOR_PINK LCD_RGBPACK(255,0,255)
254 #define COLOR_BROWN LCD_RGBPACK(128,64,0)
255 #define COLOR_LIGHTBROWN LCD_RGBPACK(255,128,64)
257 #define SPLASH_SCREEN PLUGIN_APPS_DIR "/rockpaint/splash.bmp"
258 #define ROCKPAINT_TITLE_FONT 2
260 /***********************************************************************
262 ***********************************************************************/
263 #define ROCKPAINT_PALETTE LCD_RGBPACK(0,64,128)
264 #define ROCKPAINT_SELECTED LCD_RGBPACK(128,192,255)
266 #define ROWS LCD_HEIGHT
267 #define COLS LCD_WIDTH
270 * Toolbar positioning stuff ... don't read this unless you really need to
279 /* Separator sizes */
280 #define TB_SP_MARGIN 3
281 #define TB_SP_WIDTH (2+2*TB_SP_MARGIN)
283 /* Selected color sizes */
284 #define TB_SC_SIZE 12
287 #define TB_PL_COLOR_SIZE 7
288 #define TB_PL_COLOR_SPACING 2
289 #define TB_PL_WIDTH ( 9 * TB_PL_COLOR_SIZE + 8 * TB_PL_COLOR_SPACING )
290 #define TB_PL_HEIGHT ( TB_PL_COLOR_SIZE * 2 + TB_PL_COLOR_SPACING )
294 #define TB_TL_SPACING 2
295 #define TB_TL_WIDTH ( 7 * ( TB_TL_SIZE + TB_TL_SPACING ) - TB_TL_SPACING )
296 #define TB_TL_HEIGHT ( 2 * TB_TL_SIZE + TB_TL_SPACING )
298 /* Menu button size ... gruik */
299 #define TB_MENU_MIN_WIDTH 30
301 /* Selected colors position */
302 #define TB_SC_FG_TOP 2
303 #define TB_SC_FG_LEFT 2
304 #define TB_SC_BG_TOP (TB_SC_FG_TOP+TB_PL_COLOR_SIZE*2+TB_PL_COLOR_SPACING-TB_SC_SIZE)
305 #define TB_SC_BG_LEFT (TB_SC_FG_LEFT+TB_PL_COLOR_SIZE*2+TB_PL_COLOR_SPACING-TB_SC_SIZE)
307 /* Palette position */
308 #define TB_PL_TOP TB_SC_FG_TOP
309 #define TB_PL_LEFT (TB_SC_BG_LEFT + TB_SC_SIZE + TB_PL_COLOR_SPACING)
312 #define TB_TL_TOP TB_SC_FG_TOP
313 #define TB_TL_LEFT ( TB_PL_LEFT + TB_PL_WIDTH-1 + TB_SP_WIDTH )
315 #if TB_TL_LEFT + TB_TL_WIDTH + TB_MENU_MIN_WIDTH >= LCD_WIDTH
318 #define TB_TL_TOP ( TB_PL_TOP + TB_PL_HEIGHT + 4 )
319 #define TB_TL_LEFT TB_SC_FG_LEFT
322 /* Menu button position */
323 #define TB_MENU_TOP ( TB_TL_TOP + (TB_TL_HEIGHT-8)/2 )
324 #define TB_MENU_LEFT ( TB_TL_LEFT + TB_TL_WIDTH-1 + TB_SP_WIDTH )
326 #define TB_HEIGHT ( TB_TL_TOP + TB_TL_HEIGHT + 1 )
329 static void draw_pixel(int x
,int y
);
330 static void draw_line( int x1
, int y1
, int x2
, int y2
);
331 static void draw_rect( int x1
, int y1
, int x2
, int y2
);
332 static void draw_toolbars(bool update
);
333 static void inv_cursor(bool update
);
334 static void restore_screen(void);
335 static void clear_drawing(void);
336 static void goto_menu(void);
337 static int load_bitmap( const char *filename
);
338 static int save_bitmap( char *filename
);
339 static void draw_rect_full( int x1
, int y1
, int x2
, int y2
);
341 /***********************************************************************
343 ***********************************************************************/
345 static int drawcolor
=0; /* Current color (in palette) */
346 static int bgdrawcolor
=9; /* Current background color (in palette) */
347 static int img_height
= ROWS
;
348 static int img_width
= COLS
;
349 bool isbg
= false; /* gruik ugly hack alert */
351 static int preview
=false; /* Is preview mode on ? */
353 /* TODO: clean this up */
354 static int x
=0, y
=0; /* cursor position */
355 static int prev_x
=-1, prev_y
=-1; /* previous saved cursor position */
356 static int prev_x2
=-1, prev_y2
=-1;
357 static int prev_x3
=-1, prev_y3
=-1;
358 static int tool_mode
=-1;
361 static int bsize
=1; /* brush size */
362 static int bspeed
=1; /* brush speed */
364 enum Tools
{ Brush
= 0, /* Regular brush */
365 Fill
= 1, /* Fill a shape with current color */
367 ColorPicker
= 3, /* Pick a color */
368 Line
= 4, /* Draw a line between two points */
369 Unused
= 5, /* THIS IS UNUSED ... */
372 Rectangle
= 8, /* Draw a rectangle */
374 Oval
= 10, /* Draw an oval */
380 enum Tools tool
= Brush
;
382 static bool quit
=false;
383 static int gridsize
=0;
385 static fb_data rp_colors
[18] =
387 COLOR_BLACK
, COLOR_DARKGRAY
, COLOR_RED
, COLOR_DARKYELLOW
,
388 COLOR_GREEN
, COLOR_CYAN
, COLOR_BLUE
, COLOR_PURPLE
, COLOR_BROWN
,
389 COLOR_WHITE
, COLOR_LIGHTGRAY
, COLOR_LIGHTRED
, COLOR_YELLOW
,
390 COLOR_LIGHTGREN
, COLOR_LIGHTCYAN
, COLOR_LIGHTBLUE
, COLOR_PINK
,
394 static fb_data save_buffer
[ ROWS
*COLS
];
396 extern fb_data rockpaint
[];
397 extern fb_data rockpaint_hsvrgb
[];
399 /* Maximum string size allowed for the text tool */
404 /* Used by fill and gradient algorithms */
409 } coord
[ ROWS
*COLS
];
411 /* Used by bezier curve algorithms */
419 } bezier
[ (ROWS
*COLS
)/5 ]; /* We have 4.5 times more data per struct
420 * than coord ... so we divide to take
423 /* Used to cut/copy/paste data */
424 fb_data clipboard
[ ROWS
*COLS
];
426 /* Used for text mode */
431 char old_font
[MAX_PATH
];
434 char fontname_buf
[30][MAX_PATH
];
438 /* Current filename */
439 static char filename
[MAX_PATH
];
441 /* Font preview buffer */
442 //#define FONT_PREVIEW_WIDTH ((LCD_WIDTH-30)/8)
443 //#define FONT_PREVIEW_HEIGHT 1000
444 //static unsigned char fontpreview[FONT_PREVIEW_WIDTH*FONT_PREVIEW_HEIGHT];
446 /***********************************************************************
447 * Offscreen buffer/Text/Fonts handling
449 * Parts of code taken from firmware/drivers/lcd-16bit.c
450 ***********************************************************************/
451 static void buffer_mono_bitmap_part(
452 fb_data
*buf
, int buf_width
, int buf_height
,
453 const unsigned char *src
, int src_x
, int src_y
,
454 int stride
, int x
, int y
, int width
, int height
)
455 /* this function only draws the foreground part of the bitmap */
457 const unsigned char *src_end
;
458 fb_data
*dst
, *dst_end
;
459 unsigned fgcolor
= rb
->lcd_get_foreground();
461 /* nothing to draw? */
462 if( ( width
<= 0 ) || ( height
<= 0 ) || ( x
>= buf_width
)
463 || ( y
>= buf_height
) || ( x
+ width
<= 0 ) || ( y
+ height
<= 0 ) )
479 if( x
+ width
> buf_width
)
480 width
= buf_width
- x
;
481 if( y
+ height
> buf_height
)
482 height
= buf_height
- y
;
484 src
+= stride
* (src_y
>> 3) + src_x
; /* move starting point */
486 src_end
= src
+ width
;
488 dst
= buf
+ y
*buf_width
+ x
;
492 const unsigned char *src_col
= src
++;
493 unsigned data
= *src_col
>> src_y
;
494 fb_data
*dst_col
= dst
++;
495 int numbits
= 8 - src_y
;
497 dst_end
= dst_col
+ height
* buf_width
;
501 *dst_col
= fgcolor
; /* FIXME ? */
503 dst_col
+= buf_width
;
512 } while( dst_col
< dst_end
);
513 } while( src
< src_end
);
516 static void buffer_putsxyofs( fb_data
*buf
, int buf_width
, int buf_height
,
517 int x
, int y
, int ofs
, const unsigned char *str
)
522 struct font
*pf
= rb
->font_get( FONT_UI
);
523 if( !pf
) pf
= rb
->font_get( FONT_SYSFIXED
);
525 ucs
= rb
->bidi_l2v( str
, 1 );
527 while( (ch
= *ucs
++) != 0 && x
< buf_width
)
530 const unsigned char *bits
;
532 /* get proportional width and glyph bits */
533 width
= rb
->font_get_width( pf
, ch
);
541 bits
= rb
->font_get_bits( pf
, ch
);
543 buffer_mono_bitmap_part( buf
, buf_width
, buf_height
, bits
, ofs
, 0,
544 width
, x
, y
, width
- ofs
, pf
->height
);
551 /***********************************************************************
553 ***********************************************************************/
557 MAIN_MENU_NEW
, MAIN_MENU_LOAD
, MAIN_MENU_SAVE
,
558 MAIN_MENU_SET_WIDTH
, MAIN_MENU_SET_HEIGHT
,
559 MAIN_MENU_BRUSH_SIZE
, MAIN_MENU_BRUSH_SPEED
, MAIN_MENU_COLOR
,
561 MAIN_MENU_PLAYBACK_CONTROL
,
565 /* Select action menu */
566 SELECT_MENU_CUT
, SELECT_MENU_COPY
,
567 SELECT_MENU_INVERT
, SELECT_MENU_HFLIP
, SELECT_MENU_VFLIP
,
568 SELECT_MENU_ROTATE90
, SELECT_MENU_ROTATE180
, SELECT_MENU_ROTATE270
,
573 TEXT_MENU_TEXT
, TEXT_MENU_FONT
,
574 TEXT_MENU_PREVIEW
, TEXT_MENU_APPLY
, TEXT_MENU_CANCEL
,
577 MENUITEM_STRINGLIST(main_menu
, "RockPaint", NULL
,
578 "Resume", "New", "Load", "Save",
579 "Set Width", "Set Height",
580 "Brush Size", "Brush Speed",
581 "Choose Color", "Grid Size",
582 "Playback Control", "Exit");
583 MENUITEM_STRINGLIST(select_menu
, "Select...", NULL
,
585 "Invert", "Horizontal Flip", "Vertical Flip",
586 "Rotate 90°", "Rotate 180°", "Rotate 270°",
588 MENUITEM_STRINGLIST(text_menu
, "Text", NULL
,
589 "Set Text", "Change Font",
590 "Preview", "Apply", "Cancel");
591 static const int times_list
[] = { 1, 2, 4, 8 };
592 static const int gridsize_list
[] = { 0, 5, 10, 20 };
593 static const struct opt_items times_options
[] = {
594 { "1x", -1 }, { "2x", -1 }, { "4x", -1 }, { "8x", -1 }
596 static const struct opt_items gridsize_options
[] = {
597 { "No grid", -1 }, { "5px", -1 }, { "10px", -1 }, { "20px", -1 }
600 static int draw_window( int height
, int width
,
605 rb
->lcd_getstringsize( title
, NULL
, &fh
);
608 const int _top
= ( LCD_HEIGHT
- height
) / 2;
609 const int _left
= ( LCD_WIDTH
- width
) / 2;
610 if( top
) *top
= _top
;
611 if( left
) *left
= _left
;
612 rb
->lcd_set_background(COLOR_BLUE
);
613 rb
->lcd_set_foreground(COLOR_LIGHTGRAY
);
614 rb
->lcd_fillrect( _left
, _top
, width
, height
);
615 rb
->lcd_set_foreground(COLOR_BLUE
);
616 rb
->lcd_fillrect( _left
, _top
, width
, fh
+4 );
617 rb
->lcd_set_foreground(COLOR_WHITE
);
618 rb
->lcd_putsxy( _left
+2, _top
+2, title
);
619 rb
->lcd_set_foreground(COLOR_BLACK
);
620 rb
->lcd_drawrect( _left
, _top
, width
, height
);
624 /***********************************************************************
626 ***********************************************************************/
628 char bbuf
[MAX_PATH
]; /* used by file and font browsers */
629 char bbuf_s
[MAX_PATH
]; /* used by file and font browsers */
630 struct tree_context
*tree
= NULL
;
632 static bool check_extention(const char *filename
, const char *ext
)
634 const char *p
= rb
->strrchr( filename
, '.' );
635 return ( p
!= NULL
&& !rb
->strcasecmp( p
, ext
) );
638 static const char* browse_get_name_cb(int selected_item
, void *data
,
639 char *buffer
, size_t buffer_len
)
641 int *indexes
= (int *) data
;
642 struct entry
* dc
= tree
->dircache
;
643 struct entry
* e
= &dc
[indexes
[selected_item
]];
650 static bool browse( char *dst
, int dst_size
, const char *start
)
652 struct gui_synclist browse_list
;
653 int item_count
= 0, selected
, button
;
654 struct tree_context backup
;
657 int dirfilter
= SHOW_ALL
;
658 int *indexes
= (int *) buffer
.clipboard
;
662 rb
->strcpy( bbuf
, start
);
663 a
= bbuf
+rb
->strlen(bbuf
)-1;
671 rb
->gui_synclist_init(&browse_list
, browse_get_name_cb
,
672 (void*) indexes
, false, 1, NULL
);
674 tree
= rb
->tree_get_context();
677 a
= backup
.currdir
+rb
->strlen(backup
.currdir
)-1;
683 rb
->strcpy( a
, dc
[tree
->selected_item
].name
);
684 tree
->dirfilter
= &dirfilter
;
690 rb
->set_current_file(bbuf
);
693 for( i
= 0; i
< tree
->filesindir
; i
++)
695 /* only displayes directories and .bmp files */
696 if( ((dc
[i
].attr
& ATTR_DIRECTORY
) &&
697 rb
->strcmp( dc
[i
].name
, "." ) &&
698 rb
->strcmp( dc
[i
].name
, ".." )) ||
699 ( !(dc
[i
].attr
& ATTR_DIRECTORY
) &&
700 check_extention( dc
[i
].name
, ".bmp" ) ) )
702 if( !rb
->strcmp( dc
[i
].name
, bbuf_s
) )
703 selected
= item_count
;
704 indexes
[item_count
++] = i
;
708 rb
->gui_synclist_set_nb_items(&browse_list
,item_count
);
709 rb
->gui_synclist_select_item(&browse_list
, selected
);
710 rb
->gui_synclist_set_title(&browse_list
, bbuf
, NOICON
);
711 rb
->gui_synclist_draw(&browse_list
);
714 button
= rb
->get_action(CONTEXT_LIST
,TIMEOUT_BLOCK
);
715 if (rb
->gui_synclist_do_button(&browse_list
,&button
,LIST_WRAP_UNLESS_HELD
))
719 case ACTION_STD_CANCEL
:
720 if( !rb
->strcmp( bbuf
, "/" ) )
723 rb
->set_current_file( backup
.currdir
);
726 rb
->strcpy( bbuf_s
, ".." );
728 if( button
== ACTION_STD_OK
)
730 selected
= rb
->gui_synclist_get_sel_pos( &browse_list
);
731 if( selected
< 0 || selected
>= item_count
)
733 struct entry
* e
= &dc
[indexes
[selected
]];
734 rb
->strlcpy( bbuf_s
, e
->name
, sizeof( bbuf_s
) );
735 if( !( e
->attr
& ATTR_DIRECTORY
) )
738 rb
->set_current_file( backup
.currdir
);
739 rb
->snprintf( dst
, dst_size
, "%s%s", bbuf
, bbuf_s
);
743 if( !rb
->strcmp( bbuf_s
, "." ) ) break;
744 a
= bbuf
+rb
->strlen(bbuf
);
745 if( !rb
->strcmp( bbuf_s
, ".." ) )
748 if( a
== bbuf
) break;
750 while( *a
!= '/' ) a
--;
751 rb
->strcpy( bbuf_s
, ++a
);
752 /* select parent directory */
753 bbuf_s
[rb
->strlen(bbuf_s
)-1] = '\0';
758 rb
->snprintf( a
, bbuf
+sizeof(bbuf
)-a
, "%s/", bbuf_s
);
762 case ACTION_STD_MENU
:
764 rb
->set_current_file( backup
.currdir
);
770 /***********************************************************************
773 * FIXME: This still needs some work ... it currently only works fine
774 * on the simulators, disk spins too much on real targets -> rendered
775 * font buffer needed.
776 ***********************************************************************/
777 static bool browse_fonts( char *dst
, int dst_size
)
779 #define WIDTH ( LCD_WIDTH - 20 )
780 #define HEIGHT ( LCD_HEIGHT - 20 )
782 int top
, top_inside
= 0, left
;
786 int fvi
= 0; /* first visible item */
787 int lvi
= 0; /* last visible item */
788 int si
= 0; /* selected item */
789 int osi
= 0; /* old selected item */
790 int li
= 0; /* last item */
791 int nvih
= 0; /* next visible item height */
793 int b_need_redraw
= 1; /* Do we need to redraw ? */
795 int cp
= 0; /* current position */
796 int fh
; /* font height */
798 #define fh_buf buffer.text.fh_buf /* 30 might not be enough ... */
799 #define fw_buf buffer.text.fw_buf
801 #define fontname_buf buffer.text.fontname_buf
803 rb
->snprintf( buffer
.text
.old_font
, MAX_PATH
,
805 rb
->global_settings
->font_file
);
811 /* we don't need to redraw ... but we need to unselect
812 * the previously selected item */
813 cp
= top_inside
+ LINE_SPACE
;
814 for( i
= 0; i
+fvi
< osi
; i
++ )
816 cp
+= fh_buf
[i
] + LINE_SPACE
;
818 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
819 rb
->lcd_fillrect( left
+10, cp
, fw_buf
[i
], fh_buf
[i
] );
820 rb
->lcd_set_drawmode(DRMODE_SOLID
);
827 d
= rb
->opendir( FONT_DIR
"/" );
832 top_inside
= draw_window( HEIGHT
, WIDTH
, &top
, &left
, "Fonts" );
840 cp
= top_inside
+LINE_SPACE
;
842 rb
->lcd_set_foreground(COLOR_BLACK
);
843 rb
->lcd_set_background(COLOR_LIGHTGRAY
);
845 while( cp
< top
+HEIGHT
)
847 de
= rb
->readdir( d
);
853 if( !check_extention( de
->d_name
, ".fnt" ) )
855 rb
->snprintf( bbuf
, MAX_PATH
, FONT_DIR
"/%s",
857 rb
->font_load(NULL
, bbuf
);
858 rb
->font_getstringsize( de
->d_name
, &fw
, &fh
, FONT_UI
);
863 if( nvih
< 0 ) nvih
= 0;
867 if( cp
+ fh
>= top
+HEIGHT
)
872 rb
->lcd_putsxy( left
+10, cp
, de
->d_name
);
875 cp
+= fh
+ LINE_SPACE
;
876 rb
->strcpy( fontname_buf
[i
-fvi
], bbuf
);
882 if( !(de
= rb
->readdir( d
) ) )
886 else if( !nvih
&& check_extention( de
->d_name
, ".fnt" ) )
888 rb
->snprintf( bbuf
, MAX_PATH
, FONT_DIR
"/%s",
890 rb
->font_load(NULL
, bbuf
);
891 rb
->font_getstringsize( de
->d_name
, NULL
, &fh
, FONT_UI
);
895 rb
->font_load(NULL
, buffer
.text
.old_font
);
899 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
900 cp
= top_inside
+ LINE_SPACE
;
901 for( i
= 0; i
+fvi
< si
; i
++ )
903 cp
+= fh_buf
[i
] + LINE_SPACE
;
905 rb
->lcd_fillrect( left
+10, cp
, fw_buf
[i
], fh_buf
[i
] );
906 rb
->lcd_set_drawmode(DRMODE_SOLID
);
908 rb
->lcd_update_rect( left
, top
, WIDTH
, HEIGHT
);
912 switch( rb
->button_get(true) )
915 case ROCKPAINT_UP
|BUTTON_REPEAT
:
927 case ROCKPAINT_DOWN
|BUTTON_REPEAT
:
928 if( li
== -1 || si
< li
)
937 case ROCKPAINT_RIGHT
:
939 rb
->snprintf( dst
, dst_size
, "%s", fontname_buf
[si
-fvi
] );
943 if( i
!= fvi
|| si
> lvi
)
961 /***********************************************************************
962 * HSVRGB Color chooser
963 ***********************************************************************/
964 static unsigned int color_chooser( unsigned int color
)
966 int red
= RGB_UNPACK_RED( color
);
967 int green
= RGB_UNPACK_GREEN( color
);
968 int blue
= RGB_UNPACK_BLUE( color
);
969 int hue
, saturation
, value
;
970 int r
, g
, b
; /* temp variables */
973 enum BaseColor
{ Hue
= 0, Saturation
= 1, Value
= 2,
974 Red
= 3, Green
= 4, Blue
= 5 };
975 enum BaseColor current
= Red
;
982 rgb2hsv( red
, green
, blue
, &hue
, &saturation
, &value
);
987 color
= LCD_RGBPACK( red
, green
, blue
);
989 #define HEIGHT ( 100 )
990 #define WIDTH ( 150 )
992 top
= draw_window( HEIGHT
, WIDTH
, NULL
, &left
, "Color chooser" );
995 for( i
=0; i
<100; i
++ )
997 hsv2rgb( i
*36, saturation
, value
, &r
, &g
, &b
);
998 rb
->lcd_set_foreground( LCD_RGBPACK( r
, g
, b
) );
999 rb
->lcd_vline( left
+15+i
, top
+20, top
+27 );
1000 hsv2rgb( hue
, i
*255/100, value
, &r
, &g
, &b
);
1001 rb
->lcd_set_foreground( LCD_RGBPACK( r
, g
, b
) );
1002 rb
->lcd_vline( left
+15+i
, top
+30, top
+37 );
1003 hsv2rgb( hue
, saturation
, i
*255/100, &r
, &g
, &b
);
1004 rb
->lcd_set_foreground( LCD_RGBPACK( r
, g
, b
) );
1005 rb
->lcd_vline( left
+15+i
, top
+40, top
+47 );
1006 rb
->lcd_set_foreground( LCD_RGBPACK( i
*255/100, green
, blue
) );
1007 rb
->lcd_vline( left
+15+i
, top
+50, top
+57 );
1008 rb
->lcd_set_foreground( LCD_RGBPACK( red
, i
*255/100, blue
) );
1009 rb
->lcd_vline( left
+15+i
, top
+60, top
+67 );
1010 rb
->lcd_set_foreground( LCD_RGBPACK( red
, green
, i
*255/100 ) );
1011 rb
->lcd_vline( left
+15+i
, top
+70, top
+77 );
1014 rb
->lcd_set_foreground(COLOR_BLACK
);
1015 #define POSITION( a, i ) \
1016 rb->lcd_drawpixel( left+14+i, top + 19 + a ); \
1017 rb->lcd_drawpixel( left+16+i, top + 19 + a ); \
1018 rb->lcd_drawpixel( left+14+i, top + 28 + a ); \
1019 rb->lcd_drawpixel( left+16+i, top + 28 + a );
1020 POSITION( 0, hue
/36 );
1021 POSITION( 10, saturation
*99/255 );
1022 POSITION( 20, value
*99/255 );
1023 POSITION( 30, red
*99/255 );
1024 POSITION( 40, green
*99/255 );
1025 POSITION( 50, blue
*99/255 );
1027 rb
->lcd_set_background(COLOR_LIGHTGRAY
);
1028 rb
->lcd_setfont( FONT_SYSFIXED
);
1029 rb
->snprintf( str
, 6, "%d", hue
/10 );
1030 rb
->lcd_putsxy( left
+ 117, top
+ 20, str
);
1031 rb
->snprintf( str
, 6, "%d.%d", saturation
/255, ((saturation
*100)/255)%100 );
1032 rb
->lcd_putsxy( left
+ 117, top
+ 30, str
);
1033 rb
->snprintf( str
, 6, "%d.%d", value
/255, ((value
*100)/255)%100 );
1034 rb
->lcd_putsxy( left
+ 117, top
+ 40, str
);
1035 rb
->snprintf( str
, 6, "%d", red
);
1036 rb
->lcd_putsxy( left
+ 117, top
+ 50, str
);
1037 rb
->snprintf( str
, 6, "%d", green
);
1038 rb
->lcd_putsxy( left
+ 117, top
+ 60, str
);
1039 rb
->snprintf( str
, 6, "%d", blue
);
1040 rb
->lcd_putsxy( left
+ 117, top
+ 70, str
);
1041 rb
->lcd_setfont( FONT_UI
);
1043 #define CURSOR( l ) \
1044 rb->lcd_bitmap_transparent_part( rockpaint_hsvrgb, 1, 1, 16, left+l+1, top+20, 6, 58 ); \
1045 rb->lcd_bitmap_transparent_part( rockpaint_hsvrgb, 8, 10*current, 16, left+l, top+19+10*current, 8, 10 );
1049 rb
->lcd_set_foreground( color
);
1050 rb
->lcd_fillrect( left
+15, top
+85, 100, 8 );
1054 switch( rb
->button_get(true) )
1057 current
= ( current
+ 5 )%6;
1060 case ROCKPAINT_DOWN
:
1061 current
= (current
+ 1 )%6;
1064 case ROCKPAINT_LEFT
:
1069 hue
= ( hue
+ 3600 - 10 )%3600;
1072 if( saturation
) saturation
--;
1075 if( value
) value
--;
1081 if( green
) green
--;
1089 case ROCKPAINT_LEFT
|BUTTON_REPEAT
:
1094 hue
= ( hue
+ 3600 - 100 )%3600;
1097 if( saturation
>= 8 ) saturation
-=8;
1098 else saturation
= 0;
1101 if( value
>= 8 ) value
-=8;
1105 if( red
>= 8 ) red
-=8;
1109 if( green
>= 8 ) green
-=8;
1113 if( blue
>= 8 ) blue
-=8;
1119 case ROCKPAINT_RIGHT
:
1124 hue
= ( hue
+ 10 )%3600;
1127 if( saturation
< 0xff ) saturation
++;
1130 if( value
< 0xff ) value
++;
1133 if( red
< 0xff ) red
++;
1136 if( green
< 0xff ) green
++;
1139 if( blue
< 0xff ) blue
++;
1144 case ROCKPAINT_RIGHT
|BUTTON_REPEAT
:
1149 hue
= ( hue
+ 100 )%3600;
1152 if( saturation
< 0xff - 8 ) saturation
+=8;
1153 else saturation
= 0xff;
1156 if( value
< 0xff - 8 ) value
+=8;
1160 if( red
< 0xff - 8 ) red
+=8;
1164 if( green
< 0xff - 8 ) green
+=8;
1168 if( blue
< 0xff - 8 ) blue
+=8;
1174 case ROCKPAINT_DRAW
:
1184 hsv2rgb( hue
, saturation
, value
, &red
, &green
, &blue
);
1190 rgb2hsv( red
, green
, blue
, &hue
, &saturation
, &value
);
1199 /***********************************************************************
1201 ***********************************************************************/
1202 static void init_buffer(void)
1205 fb_data color
= rp_colors
[ bgdrawcolor
];
1206 for( i
= 0; i
< ROWS
*COLS
; i
++ )
1208 save_buffer
[i
] = color
;
1212 static void draw_pixel(int x
,int y
)
1216 if( x
< 0 || x
>= COLS
|| y
< 0 || y
>= ROWS
) return;
1219 save_buffer
[ x
+y
*COLS
] = rp_colors
[bgdrawcolor
];
1223 save_buffer
[ x
+y
*COLS
] = rp_colors
[drawcolor
];
1226 rb
->lcd_drawpixel(x
,y
);
1229 static void color_picker( int x
, int y
)
1233 rb
->lcd_set_foreground( save_buffer
[ x
+y
*COLS
] );
1235 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1236 if( x
>= COLS
- PSIZE
) x
-= PSIZE
+ 2;
1237 if( y
>= ROWS
- PSIZE
) y
-= PSIZE
+ 2;
1238 rb
->lcd_drawrect( x
+ 2, y
+ 2, PSIZE
- 2, PSIZE
- 2 );
1239 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1240 rb
->lcd_drawrect( x
+ 3, y
+ 3, PSIZE
- 4, PSIZE
- 4 );
1242 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
1246 rp_colors
[ drawcolor
] = save_buffer
[ x
+y
*COLS
];
1250 static void draw_select_rectangle( int x1
, int y1
, int x2
, int y2
)
1251 /* This is a preview mode only function */
1266 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1268 for( a
= x1
; a
< x2
; a
++, i
++ )
1270 rb
->lcd_drawpixel( a
, y1
);
1271 for( a
= y1
; a
< y2
; a
++, i
++ )
1273 rb
->lcd_drawpixel( x2
, a
);
1275 for( a
= x2
; a
> x1
; a
--, i
++ )
1277 rb
->lcd_drawpixel( a
, y2
);
1279 for( a
= y2
; a
> y1
; a
--, i
++ )
1281 rb
->lcd_drawpixel( x1
, a
);
1282 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1285 static void copy_to_clipboard( void )
1287 /* This needs to be optimised ... but i'm lazy ATM */
1288 rb
->memcpy( buffer
.clipboard
, save_buffer
, COLS
*ROWS
*sizeof( fb_data
) );
1291 /* no preview mode handling atm ... do we need it ? (one if) */
1292 static void draw_invert( int x1
, int y1
, int x2
, int y2
)
1308 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1309 rb
->lcd_fillrect( x1
, y1
, x2
-x1
+1, y2
-y1
+1 );
1310 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1312 for( ; y1
<=y2
; y1
++ )
1314 for( i
= x1
; i
<=x2
; i
++ )
1316 save_buffer
[ y1
*COLS
+ i
] = ~save_buffer
[ y1
*COLS
+ i
];
1319 /*if( update )*/ rb
->lcd_update();
1322 static void draw_hflip( int x1
, int y1
, int x2
, int y2
)
1338 copy_to_clipboard();
1340 for( i
= 0; i
<= y2
- y1
; i
++ )
1342 rb
->memcpy( save_buffer
+(y1
+i
)*COLS
+x1
,
1343 buffer
.clipboard
+(y2
-i
)*COLS
+x1
,
1344 (x2
-x1
+1)*sizeof( fb_data
) );
1350 static void draw_vflip( int x1
, int y1
, int x2
, int y2
)
1366 copy_to_clipboard();
1368 for( ; y1
<= y2
; y1
++ )
1370 for( i
= 0; i
<= x2
- x1
; i
++ )
1372 save_buffer
[y1
*COLS
+x1
+i
] = buffer
.clipboard
[y1
*COLS
+x2
-i
];
1379 /* direction: -1 = left, 1 = right */
1380 static void draw_rot_90_deg( int x1
, int y1
, int x2
, int y2
, int direction
)
1396 copy_to_clipboard();
1398 fb_data color
= rp_colors
[ bgdrawcolor
];
1399 const int width
= x2
- x1
, height
= y2
- y1
;
1400 const int sub_half
= width
/2-height
/2, add_half
= (width
+height
)/2;
1401 if( width
> height
)
1403 for( i
= 0; i
<= height
; i
++ )
1405 for( j
= 0; j
< sub_half
; j
++ )
1406 save_buffer
[(y1
+i
)*COLS
+x1
+j
] = color
;
1407 for( j
= add_half
+1; j
<= width
; j
++ )
1408 save_buffer
[(y1
+i
)*COLS
+x1
+j
] = color
;
1411 else if( width
< height
)
1413 for( j
= 0; j
<= width
; j
++ )
1415 for( i
= 0; i
< -sub_half
; i
++ )
1416 save_buffer
[(y1
+i
)*COLS
+x1
+j
] = color
;
1417 for( i
= add_half
+1; i
<= height
; i
++ )
1418 save_buffer
[(y1
+i
)*COLS
+x1
+j
] = color
;
1421 int x3
= x1
+ sub_half
, y3
= y1
- sub_half
;
1422 int is
= x3
<0?-x3
:0, ie
= COLS
-x3
-1, js
= y3
<0?-y3
:0, je
= ROWS
-y3
-1;
1423 if( ie
> height
) ie
= height
;
1424 if( je
> width
) je
= width
;
1425 for( i
= is
; i
<= ie
; i
++ )
1427 for( j
= js
; j
<= je
; j
++ )
1440 save_buffer
[(y3
+j
)*COLS
+x3
+i
] = buffer
.clipboard
[y
*COLS
+x
];
1447 static void draw_paste_rectangle( int src_x1
, int src_y1
, int src_x2
,
1448 int src_y2
, int x1
, int y1
, int mode
)
1450 int i
, width
, height
;
1451 if( mode
== SELECT_MENU_CUT
)
1454 drawcolor
= bgdrawcolor
;
1455 draw_rect_full( src_x1
, src_y1
, src_x2
, src_y2
);
1458 if( src_x1
> src_x2
)
1464 if( src_y1
> src_y2
)
1470 width
= src_x2
- src_x1
+ 1;
1471 height
= src_y2
- src_y1
+ 1;
1473 if( x1
+ width
> COLS
)
1475 if( y1
+ height
> ROWS
)
1478 rb
->lcd_bitmap_part( buffer
.clipboard
, src_x1
, src_y1
, COLS
,
1479 x1
, y1
, width
, height
);
1482 for( i
= 0; i
< height
; i
++ )
1484 rb
->memcpy( save_buffer
+(y1
+i
)*COLS
+x1
,
1485 buffer
.clipboard
+(src_y1
+i
)*COLS
+src_x1
,
1486 width
*sizeof( fb_data
) );
1491 static void show_grid( bool update
)
1496 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1497 for( i
= gridsize
; i
< img_width
; i
+= gridsize
)
1499 rb
->lcd_vline( i
, 0, img_height
-1 );
1501 for( i
= gridsize
; i
< img_height
; i
+= gridsize
)
1503 rb
->lcd_hline( 0, img_width
-1, i
);
1505 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1506 if( update
) rb
->lcd_update();
1510 static void draw_text( int x
, int y
)
1513 buffer
.text
.text
[0] = '\0';
1514 rb
->snprintf( buffer
.text
.old_font
, MAX_PATH
,
1516 rb
->global_settings
->font_file
);
1519 switch( rb
->do_menu( &text_menu
, &selected
, NULL
, NULL
) )
1521 case TEXT_MENU_TEXT
:
1522 rb
->lcd_set_foreground(COLOR_BLACK
);
1523 rb
->kbd_input( buffer
.text
.text
, MAX_TEXT
);
1526 case TEXT_MENU_FONT
:
1527 if( browse_fonts( buffer
.text
.font
, MAX_PATH
) )
1529 rb
->font_load(NULL
, buffer
.text
.font
);
1533 case TEXT_MENU_PREVIEW
:
1534 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
1539 rb
->lcd_putsxy( x
, y
, buffer
.text
.text
);
1541 switch( button
= rb
->button_get( true ) )
1543 case ROCKPAINT_LEFT
:
1544 case ROCKPAINT_LEFT
| BUTTON_REPEAT
:
1545 x
-=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
1549 case ROCKPAINT_RIGHT
:
1550 case ROCKPAINT_RIGHT
| BUTTON_REPEAT
:
1551 x
+=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
1556 case ROCKPAINT_UP
| BUTTON_REPEAT
:
1557 y
-=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
1561 case ROCKPAINT_DOWN
:
1562 case ROCKPAINT_DOWN
| BUTTON_REPEAT
:
1563 y
+=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
1567 case ROCKPAINT_DRAW
:
1570 if(rb
->default_event_handler(button
)
1571 == SYS_USB_CONNECTED
)
1572 button
= ROCKPAINT_DRAW
;
1575 if( button
== ROCKPAINT_DRAW
) break;
1579 case TEXT_MENU_APPLY
:
1580 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
1581 buffer_putsxyofs( save_buffer
, COLS
, ROWS
, x
, y
, 0,
1583 case TEXT_MENU_CANCEL
:
1586 rb
->font_load(NULL
, buffer
.text
.old_font
);
1592 static void draw_brush( int x
, int y
)
1595 for( i
=-bsize
/2+(bsize
+1)%2; i
<=bsize
/2; i
++ )
1597 for( j
=-bsize
/2+(bsize
+1)%2; j
<=bsize
/2; j
++ )
1599 draw_pixel( x
+i
, y
+j
);
1604 /* This is an implementation of Bresenham's line algorithm.
1605 * See http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm.
1607 static void draw_line( int x1
, int y1
, int x2
, int y2
)
1611 int deltax
= x2
- x1
;
1612 int deltay
= y2
- y1
;
1615 int xerr
= abs(deltax
);
1616 int yerr
= abs(deltay
);
1617 int xstep
= deltax
> 0 ? 1 : -1;
1618 int ystep
= deltay
> 0 ? 1 : -1;
1628 /* to leave off the last pixel of the line, leave off the "+ 1" */
1629 for (i
= abs(deltay
) + 1; i
; --i
)
1642 /* more horizontal */
1647 for (i
= abs(deltax
) + 1; i
; --i
)
1660 static void draw_curve( int x1
, int y1
, int x2
, int y2
,
1661 int xa
, int ya
, int xb
, int yb
)
1675 if( x1
== x2
&& y1
== y2
)
1677 draw_pixel( x1
, y1
);
1683 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1684 if( xa
== -1 || ya
== -1 )
1686 rb
->lcd_drawline( x1
, y1
, xb
, yb
);
1687 rb
->lcd_drawline( x2
, y2
, xb
, yb
);
1691 rb
->lcd_drawline( x1
, y1
, xa
, ya
);
1692 rb
->lcd_drawline( x2
, y2
, xb
, yb
);
1694 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1697 if( xa
== -1 || ya
== -1 )
1698 /* We only have 3 of the points
1699 * This will currently only be used in preview mode */
1701 #define PUSH( a1, b1, a2, b2, a3, b3, d ) \
1702 buffer.bezier[i].x1 = a1; \
1703 buffer.bezier[i].y1 = b1; \
1704 buffer.bezier[i].x2 = a2; \
1705 buffer.bezier[i].y2 = b2; \
1706 buffer.bezier[i].x3 = a3; \
1707 buffer.bezier[i].y3 = b3; \
1708 buffer.bezier[i].depth = d; \
1710 #define POP( a1, b1, a2, b2, a3, b3, d ) \
1712 a1 = buffer.bezier[i].x1; \
1713 b1 = buffer.bezier[i].y1; \
1714 a2 = buffer.bezier[i].x2; \
1715 b2 = buffer.bezier[i].y2; \
1716 a3 = buffer.bezier[i].x3; \
1717 b3 = buffer.bezier[i].y3; \
1718 d = buffer.bezier[i].depth;
1719 PUSH( x1
<<4, y1
<<4, xb
<<4, yb
<<4, x2
<<4, y2
<<4, 0 );
1722 /* de Casteljau's algorithm (see wikipedia) */
1723 POP( xl1
, yl1
, xb
, yb
, xr3
, yr3
, depth
);
1724 if( depth
< 10 ) /* check that the stack's 'i' doesn't overflow */
1726 xl2
= ( xl1
+ xb
)>>1;
1727 yl2
= ( yl1
+ yb
)>>1;
1728 xr2
= ( xb
+ xr3
)>>1;
1729 yr2
= ( yb
+ yr3
)>>1;
1730 xr1
= ( xl2
+ xr2
)>>1;
1731 yr1
= ( yl2
+ yr2
)>>1;
1734 PUSH( xl1
, yl1
, xl2
, yl2
, xl3
, yl3
, depth
+1 );
1735 PUSH( xr1
, yr1
, xr2
, yr2
, xr3
, yr3
, depth
+1 );
1739 draw_line( ((xl1
>>3)+1)>>1, ((yl1
>>3)+1)>>1,
1740 ((xr3
>>3)+1)>>1, ((yr3
>>3)+1)>>1 );
1746 else /* We have the 4 points */
1748 #define PUSH( a1, b1, a2, b2, a3, b3, a4, b4, d ) \
1749 buffer.bezier[i].x1 = a1; \
1750 buffer.bezier[i].y1 = b1; \
1751 buffer.bezier[i].x2 = a2; \
1752 buffer.bezier[i].y2 = b2; \
1753 buffer.bezier[i].x3 = a3; \
1754 buffer.bezier[i].y3 = b3; \
1755 buffer.bezier[i].x4 = a4; \
1756 buffer.bezier[i].y4 = b4; \
1757 buffer.bezier[i].depth = d; \
1759 #define POP( a1, b1, a2, b2, a3, b3, a4, b4, d ) \
1761 a1 = buffer.bezier[i].x1; \
1762 b1 = buffer.bezier[i].y1; \
1763 a2 = buffer.bezier[i].x2; \
1764 b2 = buffer.bezier[i].y2; \
1765 a3 = buffer.bezier[i].x3; \
1766 b3 = buffer.bezier[i].y3; \
1767 a4 = buffer.bezier[i].x4; \
1768 b4 = buffer.bezier[i].y4; \
1769 d = buffer.bezier[i].depth;
1771 PUSH( x1
<<4, y1
<<4, xa
<<4, ya
<<4, xb
<<4, yb
<<4, x2
<<4, y2
<<4, 0 );
1774 /* de Casteljau's algorithm (see wikipedia) */
1775 POP( xl1
, yl1
, xa
, ya
, xb
, yb
, xr4
, yr4
, depth
);
1776 if( depth
< 10 ) /* check that the stack's 'i' doesn't overflow */
1778 xl2
= ( xl1
+ xa
)>>1;
1779 yl2
= ( yl1
+ ya
)>>1;
1780 xh
= ( xa
+ xb
)>>1;
1781 yh
= ( ya
+ yb
)>>1;
1782 xr3
= ( xb
+ xr4
)>>1;
1783 yr3
= ( yb
+ yr4
)>>1;
1784 xl3
= ( xl2
+ xh
)>>1;
1785 yl3
= ( yl2
+ yh
)>>1;
1786 xr2
= ( xr3
+ xh
)>>1;
1787 yr2
= ( yr3
+ yh
)>>1;
1788 xl4
= ( xl3
+ xr2
)>>1;
1789 yl4
= ( yl3
+ yr2
)>>1;
1792 PUSH( xl1
, yl1
, xl2
, yl2
, xl3
, yl3
, xl4
, yl4
, depth
+1 );
1793 PUSH( xr1
, yr1
, xr2
, yr2
, xr3
, yr3
, xr4
, yr4
, depth
+1 );
1797 draw_line( ((xl1
>>3)+1)>>1, ((yl1
>>3)+1)>>1,
1798 ((xr4
>>3)+1)>>1, ((yr4
>>3)+1)>>1 );
1806 static void draw_rect( int x1
, int y1
, int x2
, int y2
)
1808 draw_line( x1
, y1
, x1
, y2
);
1809 draw_line( x1
, y1
, x2
, y1
);
1810 draw_line( x1
, y2
, x2
, y2
);
1811 draw_line( x2
, y1
, x2
, y2
);
1814 static void togglebg( void )
1818 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
1822 rb
->lcd_set_foreground( rp_colors
[ bgdrawcolor
] );
1827 static void draw_rect_full( int x1
, int y1
, int x2
, int y2
)
1840 draw_line( x
, y1
, x
, y2
);
1841 } while( ++x
<= x2
);
1843 draw_rect( x1
, y1
, x2
, y2
);
1846 static void draw_oval( int x1
, int y1
, int x2
, int y2
, bool full
)
1848 /* TODO: simplify :) */
1849 int cx
= (x1
+x2
)>>1;
1850 int cy
= (y1
+y2
)>>1;
1852 int rx
= (x1
-x2
)>>1;
1853 int ry
= (y1
-y2
)>>1;
1854 if( rx
< 0 ) rx
*= -1;
1855 if( ry
< 0 ) ry
*= -1;
1857 if( rx
== 0 || ry
== 0 )
1859 draw_line( x1
, y1
, x2
, y2
);
1866 for( x
= 0; x
< rx
; x
++ )
1872 dst
= ry
* ry
* x
* x
+ rx
* rx
* y
* y
- rx
* rx
* ry
* ry
;
1875 if( -old_dst
< dst
) y
--;
1878 draw_line( cx
+x
, cy
, cx
+x
, cy
+y
);
1879 draw_line( cx
+x
, cy
, cx
+x
, cy
-y
);
1880 draw_line( cx
-x
, cy
, cx
-x
, cy
+y
);
1881 draw_line( cx
-x
, cy
, cx
-x
, cy
-y
);
1885 draw_pixel( cx
+x
, cy
+y
);
1886 draw_pixel( cx
+x
, cy
-y
);
1887 draw_pixel( cx
-x
, cy
+y
);
1888 draw_pixel( cx
-x
, cy
-y
);
1891 for( y
= 0; y
< ry
; y
++ )
1897 dst
= ry
* ry
* x
* x
+ rx
* rx
* y
* y
- rx
* rx
* ry
* ry
;
1900 if( -old_dst
< dst
) x
--;
1903 draw_line( cx
+x
, cy
, cx
+x
, cy
+y
);
1904 draw_line( cx
+x
, cy
, cx
+x
, cy
-y
);
1905 draw_line( cx
-x
, cy
, cx
-x
, cy
+y
);
1906 draw_line( cx
-x
, cy
, cx
-x
, cy
-y
);
1910 draw_pixel( cx
+x
, cy
+y
);
1911 draw_pixel( cx
+x
, cy
-y
);
1912 draw_pixel( cx
-x
, cy
+y
);
1913 draw_pixel( cx
-x
, cy
-y
);
1918 static void draw_oval_empty( int x1
, int y1
, int x2
, int y2
)
1920 draw_oval( x1
, y1
, x2
, y2
, false );
1923 static void draw_oval_full( int x1
, int y1
, int x2
, int y2
)
1926 draw_oval( x1
, y1
, x2
, y2
, true );
1928 draw_oval( x1
, y1
, x2
, y2
, false );
1931 static void draw_fill( int x0
, int y0
)
1933 #define PUSH( a, b ) \
1934 draw_pixel( (int)a, (int)b ); \
1935 buffer.coord[i].x = a; \
1936 buffer.coord[i].y = b; \
1938 #define POP( a, b ) \
1940 a = buffer.coord[i].x; \
1941 b = buffer.coord[i].y;
1946 unsigned int prev_color
= save_buffer
[ x0
+y0
*COLS
];
1948 if( prev_color
== rp_colors
[ drawcolor
] ) return;
1955 if( x
> 0 && save_buffer
[x
-1+y
*COLS
] == prev_color
)
1959 if( x
< COLS
-1 && save_buffer
[x
+1+y
*COLS
] == prev_color
)
1963 if( y
> 0 && save_buffer
[x
+(y
-1)*COLS
] == prev_color
)
1967 if( y
< ROWS
- 1 && save_buffer
[x
+(y
+1)*COLS
] == prev_color
)
1977 /* For preview purposes only */
1978 static void line_gradient( int x1
, int y1
, int x2
, int y2
)
1982 int h1
, s1
, v1
, h2
, s2
, v2
, r
, g
, b
;
1995 if( w
== 0 && h
== 0 )
1997 draw_pixel( x1
>>1, y1
>>1 );
2001 r1
= RGB_UNPACK_RED( rp_colors
[ bgdrawcolor
] );
2002 g1
= RGB_UNPACK_GREEN( rp_colors
[ bgdrawcolor
] );
2003 b1
= RGB_UNPACK_BLUE( rp_colors
[ bgdrawcolor
] );
2004 r2
= RGB_UNPACK_RED( rp_colors
[ drawcolor
] );
2005 g2
= RGB_UNPACK_GREEN( rp_colors
[ drawcolor
] );
2006 b2
= RGB_UNPACK_BLUE( rp_colors
[ drawcolor
] );
2031 rgb2hsv( r1
, g1
, b1
, &h1
, &s1
, &v1
);
2032 rgb2hsv( r2
, g2
, b2
, &h2
, &s2
, &v2
);
2049 hsv2rgb( h1
+((h2
-h1
)*(x1
-x2
))/w
,
2050 s1
+((s2
-s1
)*(x1
-x2
))/w
,
2051 v1
+((v2
-v1
)*(x1
-x2
))/w
,
2053 rp_colors
[ drawcolor
] = LCD_RGBPACK( r
, g
, b
);
2054 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
2055 draw_pixel( (x1
+1)>>1, (y1
+1)>>1 );
2057 y1
= y2
- ( x2
- x1
) * h
/ w
;
2075 hsv2rgb( h1
+((h2
-h1
)*(y1
-y2
))/h
,
2076 s1
+((s2
-s1
)*(y1
-y2
))/h
,
2077 v1
+((v2
-v1
)*(y1
-y2
))/h
,
2079 rp_colors
[ drawcolor
] = LCD_RGBPACK( r
, g
, b
);
2080 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
2081 draw_pixel( (x1
+1)>>1, (y1
+1)>>1 );
2083 x1
= x2
- ( y2
- y1
) * w
/ h
;
2088 rp_colors
[ drawcolor
] = LCD_RGBPACK( r1
, g1
, b1
);
2092 rp_colors
[ drawcolor
] = LCD_RGBPACK( r2
, g2
, b2
);
2096 static void linear_gradient( int x1
, int y1
, int x2
, int y2
)
2098 int r1
= RGB_UNPACK_RED( rp_colors
[ bgdrawcolor
] );
2099 int g1
= RGB_UNPACK_GREEN( rp_colors
[ bgdrawcolor
] );
2100 int b1
= RGB_UNPACK_BLUE( rp_colors
[ bgdrawcolor
] );
2101 int r2
= RGB_UNPACK_RED( rp_colors
[ drawcolor
] );
2102 int g2
= RGB_UNPACK_GREEN( rp_colors
[ drawcolor
] );
2103 int b2
= RGB_UNPACK_BLUE( rp_colors
[ drawcolor
] );
2105 int h1
, s1
, v1
, h2
, s2
, v2
, r
, g
, b
;
2108 int radius2
= ( x1
- x2
) * ( x1
- x2
) + ( y1
- y2
) * ( y1
- y2
);
2111 /* We only propagate the gradient to neighboring pixels with the same
2112 * color as ( x1, y1 ) */
2113 unsigned int prev_color
= save_buffer
[ x1
+y1
*COLS
];
2118 if( radius2
== 0 ) return;
2121 line_gradient( x1
, y1
, x2
, y2
);
2124 rgb2hsv( r1
, g1
, b1
, &h1
, &s1
, &v1
);
2125 rgb2hsv( r2
, g2
, b2
, &h2
, &s2
, &v2
);
2127 #define PUSH( x0, y0 ) \
2128 buffer.coord[i].x = (short)(x0); \
2129 buffer.coord[i].y = (short)(y0); \
2131 #define POP( a, b ) \
2133 a = (int)buffer.coord[i].x; \
2134 b = (int)buffer.coord[i].y;
2142 dist2
= ( x2
- x1
) * ( x
- x1
) + ( y2
- y1
) * ( y
- y1
);
2145 rp_colors
[ drawcolor
] = rp_colors
[ bgdrawcolor
];
2147 else if( dist2
< radius2
)
2149 hsv2rgb( h1
+((h2
-h1
)*dist2
)/radius2
,
2150 s1
+((s2
-s1
)*dist2
)/radius2
,
2151 v1
+((v2
-v1
)*dist2
)/radius2
,
2153 rp_colors
[ drawcolor
] = LCD_RGBPACK( r
, g
, b
);
2157 rp_colors
[ drawcolor
] = LCD_RGBPACK( r2
, g2
, b2
);
2159 if( rp_colors
[ drawcolor
] == prev_color
)
2161 if( rp_colors
[ drawcolor
])
2162 rp_colors
[ drawcolor
]--; /* GRUIK */
2164 rp_colors
[ drawcolor
]++; /* GRUIK */
2166 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
2169 if( x
> 0 && save_buffer
[x
-1+y
*COLS
] == prev_color
)
2173 if( x
< COLS
-1 && save_buffer
[x
+1+y
*COLS
] == prev_color
)
2177 if( y
> 0 && save_buffer
[x
+(y
-1)*COLS
] == prev_color
)
2181 if( y
< ROWS
- 1 && save_buffer
[x
+(y
+1)*COLS
] == prev_color
)
2189 rp_colors
[ drawcolor
] = LCD_RGBPACK( r2
, g2
, b2
);
2192 static void radial_gradient( int x1
, int y1
, int x2
, int y2
)
2194 int r1
= RGB_UNPACK_RED( rp_colors
[ bgdrawcolor
] );
2195 int g1
= RGB_UNPACK_GREEN( rp_colors
[ bgdrawcolor
] );
2196 int b1
= RGB_UNPACK_BLUE( rp_colors
[ bgdrawcolor
] );
2197 int r2
= RGB_UNPACK_RED( rp_colors
[ drawcolor
] );
2198 int g2
= RGB_UNPACK_GREEN( rp_colors
[ drawcolor
] );
2199 int b2
= RGB_UNPACK_BLUE( rp_colors
[ drawcolor
] );
2201 int h1
, s1
, v1
, h2
, s2
, v2
, r
, g
, b
;
2204 int radius2
= ( x1
- x2
) * ( x1
- x2
) + ( y1
- y2
) * ( y1
- y2
);
2207 /* We only propagate the gradient to neighboring pixels with the same
2208 * color as ( x1, y1 ) */
2209 unsigned int prev_color
= save_buffer
[ x1
+y1
*COLS
];
2214 if( radius2
== 0 ) return;
2217 line_gradient( x1
, y1
, x2
, y2
);
2220 rgb2hsv( r1
, g1
, b1
, &h1
, &s1
, &v1
);
2221 rgb2hsv( r2
, g2
, b2
, &h2
, &s2
, &v2
);
2223 #define PUSH( x0, y0 ) \
2224 buffer.coord[i].x = (short)(x0); \
2225 buffer.coord[i].y = (short)(y0); \
2227 #define POP( a, b ) \
2229 a = (int)buffer.coord[i].x; \
2230 b = (int)buffer.coord[i].y;
2238 if( ( dist2
= (x1
-(x
))*(x1
-(x
))+(y1
-(y
))*(y1
-(y
)) ) < radius2
)
2240 hsv2rgb( h1
+((h2
-h1
)*dist2
)/radius2
,
2241 s1
+((s2
-s1
)*dist2
)/radius2
,
2242 v1
+((v2
-v1
)*dist2
)/radius2
,
2244 rp_colors
[ drawcolor
] = LCD_RGBPACK( r
, g
, b
);
2248 rp_colors
[ drawcolor
] = LCD_RGBPACK( r2
, g2
, b2
);
2250 if( rp_colors
[ drawcolor
] == prev_color
)
2252 if( rp_colors
[ drawcolor
])
2253 rp_colors
[ drawcolor
]--; /* GRUIK */
2255 rp_colors
[ drawcolor
]++; /* GRUIK */
2257 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
2260 if( x
> 0 && save_buffer
[x
-1+y
*COLS
] == prev_color
)
2264 if( x
< COLS
-1 && save_buffer
[x
+1+y
*COLS
] == prev_color
)
2268 if( y
> 0 && save_buffer
[x
+(y
-1)*COLS
] == prev_color
)
2272 if( y
< ROWS
- 1 && save_buffer
[x
+(y
+1)*COLS
] == prev_color
)
2280 rp_colors
[ drawcolor
] = LCD_RGBPACK( r2
, g2
, b2
);
2283 static void draw_toolbars(bool update
)
2286 #define TOP (LCD_HEIGHT-TB_HEIGHT)
2287 rb
->lcd_set_background( COLOR_LIGHTGRAY
);
2288 rb
->lcd_set_foreground( COLOR_LIGHTGRAY
);
2289 rb
->lcd_fillrect( 0, TOP
, LCD_WIDTH
, TB_HEIGHT
);
2290 rb
->lcd_set_foreground( COLOR_BLACK
);
2291 rb
->lcd_drawrect( 0, TOP
, LCD_WIDTH
, TB_HEIGHT
);
2293 rb
->lcd_set_foreground( rp_colors
[ bgdrawcolor
] );
2294 rb
->lcd_fillrect( TB_SC_BG_LEFT
, TOP
+TB_SC_BG_TOP
,
2295 TB_SC_SIZE
, TB_SC_SIZE
);
2296 rb
->lcd_set_foreground(ROCKPAINT_PALETTE
);
2297 rb
->lcd_drawrect( TB_SC_BG_LEFT
, TOP
+TB_SC_BG_TOP
,
2298 TB_SC_SIZE
, TB_SC_SIZE
);
2299 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
2300 rb
->lcd_fillrect( TB_SC_FG_LEFT
, TOP
+TB_SC_FG_TOP
,
2301 TB_SC_SIZE
, TB_SC_SIZE
);
2302 rb
->lcd_set_foreground(ROCKPAINT_PALETTE
);
2303 rb
->lcd_drawrect( TB_SC_FG_LEFT
, TOP
+TB_SC_FG_TOP
,
2304 TB_SC_SIZE
, TB_SC_SIZE
);
2306 for( i
=0; i
<18; i
++ )
2308 rb
->lcd_set_foreground( rp_colors
[i
] );
2310 TB_PL_LEFT
+(i
%9)*( TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
),
2311 TOP
+TB_PL_TOP
+(i
/9)*( TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
),
2312 TB_PL_COLOR_SIZE
, TB_PL_COLOR_SIZE
);
2313 rb
->lcd_set_foreground( ROCKPAINT_PALETTE
);
2315 TB_PL_LEFT
+(i
%9)*( TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
),
2316 TOP
+TB_PL_TOP
+(i
/9)*( TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
),
2317 TB_PL_COLOR_SIZE
, TB_PL_COLOR_SIZE
);
2320 #define SEPARATOR( x, y ) \
2321 rb->lcd_set_foreground( COLOR_WHITE ); \
2322 rb->lcd_vline( x, TOP+y, TOP+y+TB_PL_HEIGHT-1 ); \
2323 rb->lcd_set_foreground( COLOR_DARKGRAY ); \
2324 rb->lcd_vline( x+1, TOP+y, TOP+y+TB_PL_HEIGHT-1 );
2325 SEPARATOR( TB_PL_LEFT
+ TB_PL_WIDTH
- 1 + TB_SP_MARGIN
, TB_PL_TOP
);
2327 rb
->lcd_bitmap_transparent( rockpaint
, TB_TL_LEFT
, TOP
+TB_TL_TOP
,
2328 TB_TL_WIDTH
, TB_TL_HEIGHT
);
2329 rb
->lcd_set_foreground(ROCKPAINT_PALETTE
);
2330 rb
->lcd_drawrect( TB_TL_LEFT
+(TB_TL_SIZE
+TB_TL_SPACING
)*(tool
/2),
2331 TOP
+TB_TL_TOP
+(TB_TL_SIZE
+TB_TL_SPACING
)*(tool
%2),
2332 TB_TL_SIZE
, TB_TL_SIZE
);
2334 SEPARATOR( TB_TL_LEFT
+ TB_TL_WIDTH
- 1 + TB_SP_MARGIN
, TB_TL_TOP
);
2336 rb
->lcd_setfont( FONT_SYSFIXED
);
2337 rb
->lcd_putsxy( TB_MENU_LEFT
, TOP
+TB_MENU_TOP
, "Menu" );
2338 rb
->lcd_setfont( FONT_UI
);
2341 if( update
) rb
->lcd_update();
2344 static void toolbar( void )
2348 draw_toolbars( false );
2349 y
= LCD_HEIGHT
-TB_HEIGHT
/2;
2353 switch( button
= rb
->button_get( true ) )
2355 case ROCKPAINT_DRAW
:
2356 #define TOP ( LCD_HEIGHT - TB_HEIGHT )
2357 if( y
>= TOP
+ TB_SC_FG_TOP
2358 && y
< TOP
+ TB_SC_FG_TOP
+ TB_SC_SIZE
2359 && x
>= TB_SC_FG_LEFT
2360 && x
< TB_SC_FG_LEFT
+ TB_SC_SIZE
)
2362 /* click on the foreground color */
2363 rp_colors
[drawcolor
] = color_chooser( rp_colors
[drawcolor
] );
2365 else if( y
>= TOP
+ TB_SC_BG_TOP
2366 && y
< TOP
+ TB_SC_BG_TOP
+ TB_SC_SIZE
2367 && x
>= TB_SC_BG_LEFT
2368 && x
< TB_SC_BG_LEFT
+ TB_SC_SIZE
)
2370 /* click on the background color */
2372 drawcolor
= bgdrawcolor
;
2375 else if( y
>= TOP
+ TB_PL_TOP
2376 && y
< TOP
+ TB_PL_TOP
+ TB_PL_HEIGHT
2378 && x
< TB_PL_LEFT
+ TB_PL_WIDTH
)
2380 /* click on the palette */
2381 i
= (x
- TB_PL_LEFT
)%(TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
);
2382 j
= (y
- (TOP
+TB_PL_TOP
) )%(TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
);
2383 if( i
>= TB_PL_COLOR_SIZE
|| j
>= TB_PL_COLOR_SIZE
)
2385 i
= ( x
- TB_PL_LEFT
)/(TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
);
2386 j
= ( y
- (TOP
+TB_PL_TOP
) )/(TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
);
2387 drawcolor
= j
*(TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
)+i
;
2389 else if( y
>= TOP
+TB_TL_TOP
2390 && y
< TOP
+ TB_TL_TOP
+ TB_TL_HEIGHT
2392 && x
<= TB_TL_LEFT
+ TB_TL_WIDTH
)
2394 /* click on the tools */
2395 i
= (x
- TB_TL_LEFT
) % (TB_TL_SIZE
+TB_TL_SPACING
);
2396 j
= (y
- (TOP
+TB_TL_TOP
) ) %(TB_TL_SIZE
+TB_TL_SPACING
);
2397 if( i
>= TB_TL_SIZE
|| j
>= TB_TL_SIZE
) break;
2398 i
= ( x
- TB_TL_LEFT
)/(TB_TL_SIZE
+TB_TL_SPACING
);
2399 j
= ( y
- (TOP
+TB_TL_TOP
) )/(TB_TL_SIZE
+TB_TL_SPACING
);
2409 else if( x
>= TB_MENU_LEFT
&& y
>= TOP
+TB_MENU_TOP
-2)
2416 draw_toolbars( false );
2420 case ROCKPAINT_LEFT
:
2421 case ROCKPAINT_LEFT
| BUTTON_REPEAT
:
2423 x
-=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
2428 case ROCKPAINT_RIGHT
:
2429 case ROCKPAINT_RIGHT
| BUTTON_REPEAT
:
2431 x
+=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
2437 case ROCKPAINT_UP
| BUTTON_REPEAT
:
2439 y
-=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
2440 if (y
<LCD_HEIGHT
-TB_HEIGHT
)
2447 case ROCKPAINT_DOWN
:
2448 case ROCKPAINT_DOWN
| BUTTON_REPEAT
:
2450 y
+=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
2459 case ROCKPAINT_TOOLBAR
:
2460 case ROCKPAINT_TOOLBAR2
:
2467 static void inv_cursor(bool update
)
2469 rb
->lcd_set_foreground(COLOR_BLACK
);
2470 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
2471 /* cross painting */
2472 rb
->lcd_hline(x
-4,x
+4,y
);
2473 rb
->lcd_vline(x
,y
-4,y
+4);
2474 rb
->lcd_set_foreground(rp_colors
[drawcolor
]);
2475 rb
->lcd_set_drawmode(DRMODE_SOLID
);
2477 if( update
) rb
->lcd_update();
2480 static void restore_screen(void)
2482 rb
->lcd_bitmap( save_buffer
, 0, 0, COLS
, ROWS
);
2483 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
2484 rb
->lcd_vline( img_width
, 0, ROWS
);
2485 rb
->lcd_hline( 0, COLS
, img_height
);
2486 rb
->lcd_drawpixel( img_width
, img_height
);
2487 rb
->lcd_set_drawmode(DRMODE_SOLID
);
2490 static void clear_drawing(void)
2495 rb
->lcd_set_foreground( rp_colors
[ bgdrawcolor
] );
2496 rb
->lcd_fillrect( 0, 0, COLS
, ROWS
);
2500 static void goto_menu(void)
2507 switch( rb
->do_menu( &main_menu
, &selected
, NULL
, false ) )
2513 case MAIN_MENU_LOAD
:
2514 if( browse( filename
, MAX_PATH
, "/" ) )
2516 if( load_bitmap( filename
) <= 0 )
2518 rb
->splashf( 1*HZ
, "Error while loading %s",
2524 rb
->splashf( 1*HZ
, "Image loaded (%s)", filename
);
2532 case MAIN_MENU_SAVE
:
2533 rb
->lcd_set_foreground(COLOR_BLACK
);
2535 rb
->strcpy(filename
,"/");
2536 if( !rb
->kbd_input( filename
, MAX_PATH
) )
2538 if( !check_extention( filename
, ".bmp" ) )
2539 rb
->strcat(filename
, ".bmp");
2540 save_bitmap( filename
);
2541 rb
->splashf( 1*HZ
, "File saved (%s)", filename
);
2545 case MAIN_MENU_SET_WIDTH
:
2546 rb
->set_int( "Set Width", "px", UNIT_INT
, &img_width
,
2547 NULL
, 1, 1, COLS
, NULL
);
2549 case MAIN_MENU_SET_HEIGHT
:
2550 rb
->set_int( "Set Height", "px", UNIT_INT
, &img_height
,
2551 NULL
, 1, 1, ROWS
, NULL
);
2553 case MAIN_MENU_BRUSH_SIZE
:
2554 for(multi
= 0; multi
<4; multi
++)
2555 if(bsize
== times_list
[multi
]) break;
2556 rb
->set_option( "Brush Size", &multi
, INT
, times_options
, 4, NULL
);
2558 bsize
= times_list
[multi
];
2561 case MAIN_MENU_BRUSH_SPEED
:
2562 for(multi
= 0; multi
<3; multi
++)
2563 if(bspeed
== times_list
[multi
]) break;
2564 rb
->set_option( "Brush Speed", &multi
, INT
, times_options
, 3, NULL
);
2566 bspeed
= times_list
[multi
];
2569 case MAIN_MENU_COLOR
:
2570 rp_colors
[drawcolor
] = color_chooser( rp_colors
[drawcolor
] );
2573 case MAIN_MENU_GRID_SIZE
:
2574 for(multi
= 0; multi
<4; multi
++)
2575 if(gridsize
== gridsize_list
[multi
]) break;
2576 rb
->set_option( "Grid Size", &multi
, INT
, gridsize_options
, 4, NULL
);
2578 gridsize
= gridsize_list
[multi
];
2581 case MAIN_MENU_PLAYBACK_CONTROL
:
2582 playback_control( NULL
);
2585 case MAIN_MENU_EXIT
:
2590 case MAIN_MENU_RESUME
:
2598 static void reset_tool( void )
2610 static bool rockpaint_loop( void )
2622 button
= rb
->button_get(true);
2624 if( tool
== Brush
&& prev_x
!= -1 )
2628 else if( button
& BUTTON_REPEAT
)
2639 case ROCKPAINT_QUIT
:
2640 rb
->lcd_set_drawmode(DRMODE_SOLID
);
2643 case ROCKPAINT_MENU
:
2650 case ROCKPAINT_DRAW
:
2655 if( prev_x
== -1 ) prev_x
= 1;
2659 case SelectRectangle
:
2666 case LinearGradient
:
2667 case RadialGradient
:
2668 /* Curve uses 4 points, others use 2 */
2669 if( prev_x
== -1 || prev_y
== -1 )
2675 else if( tool
== Curve
2676 && ( prev_x2
== -1 || prev_y2
== -1 ) )
2681 else if( tool
== SelectRectangle
2682 && ( prev_x2
== -1 || prev_y2
== -1 ) )
2684 tool_mode
= rb
->do_menu( &select_menu
,
2685 NULL
, NULL
, false );
2688 case SELECT_MENU_CUT
:
2689 case SELECT_MENU_COPY
:
2692 copy_to_clipboard();
2693 if( prev_x
< x
) x
= prev_x
;
2694 if( prev_y
< y
) y
= prev_y
;
2697 case SELECT_MENU_INVERT
:
2698 draw_invert( prev_x
, prev_y
, x
, y
);
2702 case SELECT_MENU_HFLIP
:
2703 draw_hflip( prev_x
, prev_y
, x
, y
);
2707 case SELECT_MENU_VFLIP
:
2708 draw_vflip( prev_x
, prev_y
, x
, y
);
2712 case SELECT_MENU_ROTATE90
:
2713 draw_rot_90_deg( prev_x
, prev_y
, x
, y
, 1 );
2717 case SELECT_MENU_ROTATE180
:
2718 draw_hflip( prev_x
, prev_y
, x
, y
);
2719 draw_vflip( prev_x
, prev_y
, x
, y
);
2723 case SELECT_MENU_ROTATE270
:
2724 draw_rot_90_deg( prev_x
, prev_y
, x
, y
, -1 );
2728 case SELECT_MENU_CANCEL
:
2737 else if( tool
== Curve
2738 && ( prev_x3
== -1 || prev_y3
== -1 ) )
2748 case SelectRectangle
:
2749 draw_paste_rectangle( prev_x
, prev_y
,
2754 draw_line( prev_x
, prev_y
, x
, y
);
2757 draw_curve( prev_x
, prev_y
,
2763 draw_rect( prev_x
, prev_y
, x
, y
);
2766 draw_rect_full( prev_x
, prev_y
, x
, y
);
2769 draw_oval_empty( prev_x
, prev_y
, x
, y
);
2772 draw_oval_full( prev_x
, prev_y
, x
, y
);
2774 case LinearGradient
:
2775 linear_gradient( prev_x
, prev_y
, x
, y
);
2777 case RadialGradient
:
2778 radial_gradient( prev_x
, prev_y
, x
, y
);
2794 color_picker( x
, y
);
2807 case ROCKPAINT_DRAW
|BUTTON_REPEAT
:
2810 /* 3 point bezier curve */
2812 draw_curve( prev_x
, prev_y
,
2822 case ROCKPAINT_TOOLBAR
:
2831 case ROCKPAINT_TOOLBAR2
:
2840 case ROCKPAINT_LEFT
:
2841 case ROCKPAINT_LEFT
| BUTTON_REPEAT
:
2843 x
-=bspeed
* accelaration
;
2848 case ROCKPAINT_RIGHT
:
2849 case ROCKPAINT_RIGHT
| BUTTON_REPEAT
:
2851 x
+=bspeed
* accelaration
;
2857 case ROCKPAINT_UP
| BUTTON_REPEAT
:
2859 y
-=bspeed
* accelaration
;
2864 case ROCKPAINT_DOWN
:
2865 case ROCKPAINT_DOWN
| BUTTON_REPEAT
:
2867 y
+=bspeed
* accelaration
;
2877 if (rb
->default_event_handler(button
) == SYS_USB_CONNECTED
)
2878 return PLUGIN_USB_CONNECTED
;
2881 if( tool
== Brush
&& prev_x
== 1 )
2887 if( preview
|| tool
== ColorPicker
)
2888 /* always preview color picker */
2893 case SelectRectangle
:
2894 if( prev_x2
== -1 || prev_y2
== -1 )
2896 /* we are defining the selection */
2897 draw_select_rectangle( prev_x
, prev_y
, x
, y
);
2901 /* we are pasting the selected data */
2902 draw_paste_rectangle( prev_x
, prev_y
, prev_x2
,
2903 prev_y2
, x
, y
, tool_mode
);
2904 prev_x3
= prev_x2
-prev_x
;
2905 if( prev_x3
< 0 ) prev_x3
*= -1;
2906 prev_y3
= prev_y2
-prev_y
;
2907 if( prev_y3
< 0 ) prev_y3
*= -1;
2908 draw_select_rectangle( x
, y
, x
+prev_x3
, y
+prev_y3
);
2918 draw_line( prev_x
, prev_y
, x
, y
);
2922 if( prev_x2
== -1 || prev_y2
== -1 )
2924 draw_line( prev_x
, prev_y
, x
, y
);
2928 draw_curve( prev_x
, prev_y
,
2936 draw_rect( prev_x
, prev_y
, x
, y
);
2940 draw_rect_full( prev_x
, prev_y
, x
, y
);
2944 draw_oval_empty( prev_x
, prev_y
, x
, y
);
2948 draw_oval_full( prev_x
, prev_y
, x
, y
);
2956 color_picker( x
, y
);
2960 case LinearGradient
:
2961 line_gradient( prev_x
, prev_y
, x
, y
);
2964 case RadialGradient
:
2965 line_gradient( prev_x
, prev_y
, x
, y
);
2984 static int load_bitmap( const char *file
)
2989 fb_data color
= rp_colors
[ bgdrawcolor
];
2991 bm
.data
= (char*)save_buffer
;
2992 ret
= rb
->read_bmp_file( file
, &bm
, ROWS
*COLS
*sizeof( fb_data
),
2993 FORMAT_NATIVE
, NULL
);
2995 if((bm
.width
> COLS
) || ( bm
.height
> ROWS
))
2998 img_width
= bm
.width
;
2999 img_height
= bm
.height
;
3000 for( i
= bm
.height
-1; i
>= 0; i
-- )
3002 rb
->memmove( save_buffer
+i
*COLS
, save_buffer
+i
*bm
.width
,
3003 sizeof( fb_data
)*bm
.width
);
3004 for( j
= bm
.width
; j
< COLS
; j
++ )
3005 save_buffer
[j
+i
*COLS
] = color
;
3007 for( i
= bm
.height
*COLS
; i
< ROWS
*COLS
; i
++ )
3008 save_buffer
[i
] = color
;
3013 static int save_bitmap( char *file
)
3017 for(i
= 0; i
< img_height
; i
++)
3019 rb
->memcpy( buffer
.clipboard
+i
*img_width
, save_buffer
+i
*COLS
,
3020 sizeof( fb_data
)*img_width
);
3022 bm
.data
= (char*)buffer
.clipboard
;
3023 bm
.height
= img_height
;
3024 bm
.width
= img_width
;
3025 bm
.format
= FORMAT_NATIVE
;
3026 return save_bmp_file( file
, &bm
);
3029 enum plugin_status
plugin_start(const void* parameter
)
3031 rb
->lcd_set_foreground(COLOR_WHITE
);
3032 rb
->lcd_set_backdrop(NULL
);
3033 rb
->lcd_fillrect(0,0,LCD_WIDTH
,LCD_HEIGHT
);
3034 rb
->splash( HZ
/2, "Rock Paint");
3036 rb
->lcd_clear_display();
3042 if( load_bitmap( parameter
) <= 0 )
3044 rb
->splash( 1*HZ
, "File Open Error");
3049 rb
->splashf( 1*HZ
, "Image loaded (%s)", (char *)parameter
);
3051 rb
->strcpy( filename
, parameter
);
3060 return rockpaint_loop();