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_HDD6330_PAD
159 #define ROCKPAINT_QUIT BUTTON_POWER
160 #define ROCKPAINT_DRAW BUTTON_PLAY
161 #define ROCKPAINT_MENU BUTTON_MENU
162 #define ROCKPAINT_TOOLBAR BUTTON_PREV
163 #define ROCKPAINT_TOOLBAR2 BUTTON_NEXT
164 #define ROCKPAINT_UP BUTTON_UP
165 #define ROCKPAINT_DOWN BUTTON_DOWN
166 #define ROCKPAINT_LEFT BUTTON_LEFT
167 #define ROCKPAINT_RIGHT BUTTON_RIGHT
169 #elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
170 #define ROCKPAINT_QUIT BUTTON_POWER
171 #define ROCKPAINT_DRAW BUTTON_PLAY
172 #define ROCKPAINT_MENU BUTTON_MENU
173 #define ROCKPAINT_TOOLBAR BUTTON_RIGHT
174 #define ROCKPAINT_TOOLBAR2 BUTTON_LEFT
175 #define ROCKPAINT_UP BUTTON_UP
176 #define ROCKPAINT_DOWN BUTTON_DOWN
177 #define ROCKPAINT_LEFT BUTTON_PREV
178 #define ROCKPAINT_RIGHT BUTTON_NEXT
180 #elif ( CONFIG_KEYPAD == ONDAVX747_PAD )
181 #define ROCKPAINT_QUIT BUTTON_POWER
182 #define ROCKPAINT_MENU BUTTON_MENU
184 #elif ( CONFIG_KEYPAD == ONDAVX777_PAD )
185 #define ROCKPAINT_QUIT BUTTON_POWER
187 #elif CONFIG_KEYPAD == MROBE500_PAD
188 #define ROCKPAINT_QUIT BUTTON_POWER
190 #elif ( CONFIG_KEYPAD == SAMSUNG_YH_PAD )
191 #define ROCKPAINT_QUIT BUTTON_REC
192 #define ROCKPAINT_DRAW BUTTON_PLAY
193 #define ROCKPAINT_MENU BUTTON_FFWD
194 #define ROCKPAINT_TOOLBAR BUTTON_REW
195 #define ROCKPAINT_TOOLBAR2 ( BUTTON_REW | BUTTON_LEFT )
196 #define ROCKPAINT_UP BUTTON_UP
197 #define ROCKPAINT_DOWN BUTTON_DOWN
198 #define ROCKPAINT_LEFT BUTTON_LEFT
199 #define ROCKPAINT_RIGHT BUTTON_RIGHT
201 #elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
202 #define ROCKPAINT_QUIT BUTTON_REC
203 #define ROCKPAINT_DRAW BUTTON_PLAY
204 #define ROCKPAINT_MENU BUTTON_MENU
205 #define ROCKPAINT_TOOLBAR BUTTON_OK
206 #define ROCKPAINT_TOOLBAR2 BUTTON_CANCEL
207 #define ROCKPAINT_UP BUTTON_UP
208 #define ROCKPAINT_DOWN BUTTON_DOWN
209 #define ROCKPAINT_LEFT BUTTON_PREV
210 #define ROCKPAINT_RIGHT BUTTON_NEXT
213 #error "Please define keys for this keypad"
216 #ifdef HAVE_TOUCHSCREEN
217 #ifndef ROCKPAINT_QUIT
218 #define ROCKPAINT_QUIT BUTTON_TOPLEFT
220 #ifndef ROCKPAINT_DRAW
221 #define ROCKPAINT_DRAW BUTTON_CENTER
223 #ifndef ROCKPAINT_MENU
224 #define ROCKPAINT_MENU BUTTON_TOPRIGHT
226 #ifndef ROCKPAINT_TOOLBAR
227 #define ROCKPAINT_TOOLBAR BUTTON_BOTTOMLEFT
229 #ifndef ROCKPAINT_TOOLBAR2
230 #define ROCKPAINT_TOOLBAR2 BUTTON_BOTTOMRIGHT
233 #define ROCKPAINT_UP BUTTON_TOPMIDDLE
235 #ifndef ROCKPAINT_DOWN
236 #define ROCKPAINT_DOWN BUTTON_BOTTOMMIDDLE
238 #ifndef ROCKPAINT_LEFT
239 #define ROCKPAINT_LEFT BUTTON_MIDLEFT
241 #ifndef ROCKPAINT_RIGHT
242 #define ROCKPAINT_RIGHT BUTTON_MIDRIGHT
246 /***********************************************************************
247 * Palette Default Colors
248 ***********************************************************************/
249 #define COLOR_BLACK LCD_RGBPACK(0,0,0)
250 #define COLOR_WHITE LCD_RGBPACK(255,255,255)
251 #define COLOR_DARKGRAY LCD_RGBPACK(128,128,128)
252 #define COLOR_LIGHTGRAY LCD_RGBPACK(192,192,192)
253 #define COLOR_RED LCD_RGBPACK(128,0,0)
254 #define COLOR_LIGHTRED LCD_RGBPACK(255,0,0)
255 #define COLOR_DARKYELLOW LCD_RGBPACK(128,128,0)
256 #define COLOR_YELLOW LCD_RGBPACK(255,255,0)
257 #define COLOR_GREEN LCD_RGBPACK(0,128,0)
258 #define COLOR_LIGHTGREN LCD_RGBPACK(0,255,0)
259 #define COLOR_CYAN LCD_RGBPACK(0,128,128)
260 #define COLOR_LIGHTCYAN LCD_RGBPACK(0,255,255)
261 #define COLOR_BLUE LCD_RGBPACK(0,0,128)
262 #define COLOR_LIGHTBLUE LCD_RGBPACK(0,0,255)
263 #define COLOR_PURPLE LCD_RGBPACK(128,0,128)
264 #define COLOR_PINK LCD_RGBPACK(255,0,255)
265 #define COLOR_BROWN LCD_RGBPACK(128,64,0)
266 #define COLOR_LIGHTBROWN LCD_RGBPACK(255,128,64)
268 #define SPLASH_SCREEN PLUGIN_APPS_DIR "/rockpaint/splash.bmp"
269 #define ROCKPAINT_TITLE_FONT 2
271 /***********************************************************************
273 ***********************************************************************/
274 #define ROCKPAINT_PALETTE LCD_RGBPACK(0,64,128)
275 #define ROCKPAINT_SELECTED LCD_RGBPACK(128,192,255)
277 #define ROWS LCD_HEIGHT
278 #define COLS LCD_WIDTH
281 * Toolbar positioning stuff ... don't read this unless you really need to
290 /* Separator sizes */
291 #define TB_SP_MARGIN 3
292 #define TB_SP_WIDTH (2+2*TB_SP_MARGIN)
294 /* Selected color sizes */
295 #define TB_SC_SIZE 12
298 #define TB_PL_COLOR_SIZE 7
299 #define TB_PL_COLOR_SPACING 2
300 #define TB_PL_WIDTH ( 9 * TB_PL_COLOR_SIZE + 8 * TB_PL_COLOR_SPACING )
301 #define TB_PL_HEIGHT ( TB_PL_COLOR_SIZE * 2 + TB_PL_COLOR_SPACING )
305 #define TB_TL_SPACING 2
306 #define TB_TL_WIDTH ( 7 * ( TB_TL_SIZE + TB_TL_SPACING ) - TB_TL_SPACING )
307 #define TB_TL_HEIGHT ( 2 * TB_TL_SIZE + TB_TL_SPACING )
309 /* Menu button size ... gruik */
310 #define TB_MENU_MIN_WIDTH 30
312 /* Selected colors position */
313 #define TB_SC_FG_TOP 2
314 #define TB_SC_FG_LEFT 2
315 #define TB_SC_BG_TOP (TB_SC_FG_TOP+TB_PL_COLOR_SIZE*2+TB_PL_COLOR_SPACING-TB_SC_SIZE)
316 #define TB_SC_BG_LEFT (TB_SC_FG_LEFT+TB_PL_COLOR_SIZE*2+TB_PL_COLOR_SPACING-TB_SC_SIZE)
318 /* Palette position */
319 #define TB_PL_TOP TB_SC_FG_TOP
320 #define TB_PL_LEFT (TB_SC_BG_LEFT + TB_SC_SIZE + TB_PL_COLOR_SPACING)
323 #define TB_TL_TOP TB_SC_FG_TOP
324 #define TB_TL_LEFT ( TB_PL_LEFT + TB_PL_WIDTH-1 + TB_SP_WIDTH )
326 #if TB_TL_LEFT + TB_TL_WIDTH + TB_MENU_MIN_WIDTH >= LCD_WIDTH
329 #define TB_TL_TOP ( TB_PL_TOP + TB_PL_HEIGHT + 4 )
330 #define TB_TL_LEFT TB_SC_FG_LEFT
333 /* Menu button position */
334 #define TB_MENU_TOP ( TB_TL_TOP + (TB_TL_HEIGHT-8)/2 )
335 #define TB_MENU_LEFT ( TB_TL_LEFT + TB_TL_WIDTH-1 + TB_SP_WIDTH )
337 #define TB_HEIGHT ( TB_TL_TOP + TB_TL_HEIGHT + 1 )
340 static void draw_pixel(int x
,int y
);
341 static void draw_line( int x1
, int y1
, int x2
, int y2
);
342 static void draw_rect( int x1
, int y1
, int x2
, int y2
);
343 static void draw_toolbars(bool update
);
344 static void inv_cursor(bool update
);
345 static void restore_screen(void);
346 static void clear_drawing(void);
347 static void goto_menu(void);
348 static int load_bitmap( const char *filename
);
349 static int save_bitmap( char *filename
);
350 static void draw_rect_full( int x1
, int y1
, int x2
, int y2
);
352 /***********************************************************************
354 ***********************************************************************/
356 static int drawcolor
=0; /* Current color (in palette) */
357 static int bgdrawcolor
=9; /* Current background color (in palette) */
358 static int img_height
= ROWS
;
359 static int img_width
= COLS
;
360 bool isbg
= false; /* gruik ugly hack alert */
362 static int preview
=false; /* Is preview mode on ? */
364 /* TODO: clean this up */
365 static int x
=0, y
=0; /* cursor position */
366 static int prev_x
=-1, prev_y
=-1; /* previous saved cursor position */
367 static int prev_x2
=-1, prev_y2
=-1;
368 static int prev_x3
=-1, prev_y3
=-1;
369 static int tool_mode
=-1;
372 static int bsize
=1; /* brush size */
373 static int bspeed
=1; /* brush speed */
375 enum Tools
{ Brush
= 0, /* Regular brush */
376 Fill
= 1, /* Fill a shape with current color */
378 ColorPicker
= 3, /* Pick a color */
379 Line
= 4, /* Draw a line between two points */
380 Unused
= 5, /* THIS IS UNUSED ... */
383 Rectangle
= 8, /* Draw a rectangle */
385 Oval
= 10, /* Draw an oval */
391 enum Tools tool
= Brush
;
393 static bool quit
=false;
394 static int gridsize
=0;
396 static fb_data rp_colors
[18] =
398 COLOR_BLACK
, COLOR_DARKGRAY
, COLOR_RED
, COLOR_DARKYELLOW
,
399 COLOR_GREEN
, COLOR_CYAN
, COLOR_BLUE
, COLOR_PURPLE
, COLOR_BROWN
,
400 COLOR_WHITE
, COLOR_LIGHTGRAY
, COLOR_LIGHTRED
, COLOR_YELLOW
,
401 COLOR_LIGHTGREN
, COLOR_LIGHTCYAN
, COLOR_LIGHTBLUE
, COLOR_PINK
,
405 static fb_data save_buffer
[ ROWS
*COLS
];
407 extern fb_data rockpaint
[];
408 extern fb_data rockpaint_hsvrgb
[];
410 /* Maximum string size allowed for the text tool */
415 /* Used by fill and gradient algorithms */
420 } coord
[ ROWS
*COLS
];
422 /* Used by bezier curve algorithms */
430 } bezier
[ (ROWS
*COLS
)/5 ]; /* We have 4.5 times more data per struct
431 * than coord ... so we divide to take
434 /* Used to cut/copy/paste data */
435 fb_data clipboard
[ ROWS
*COLS
];
437 /* Used for text mode */
442 char old_font
[MAX_PATH
];
445 char fontname_buf
[30][MAX_PATH
];
451 /* Current filename */
452 static char filename
[MAX_PATH
];
454 /* Font preview buffer */
455 //#define FONT_PREVIEW_WIDTH ((LCD_WIDTH-30)/8)
456 //#define FONT_PREVIEW_HEIGHT 1000
457 //static unsigned char fontpreview[FONT_PREVIEW_WIDTH*FONT_PREVIEW_HEIGHT];
459 /***********************************************************************
460 * Offscreen buffer/Text/Fonts handling
462 * Parts of code taken from firmware/drivers/lcd-16bit.c
463 ***********************************************************************/
464 static void buffer_mono_bitmap_part(
465 fb_data
*buf
, int buf_width
, int buf_height
,
466 const unsigned char *src
, int src_x
, int src_y
,
467 int stride
, int x
, int y
, int width
, int height
)
468 /* this function only draws the foreground part of the bitmap */
470 const unsigned char *src_end
;
471 fb_data
*dst
, *dst_end
;
472 unsigned fgcolor
= rb
->lcd_get_foreground();
474 /* nothing to draw? */
475 if( ( width
<= 0 ) || ( height
<= 0 ) || ( x
>= buf_width
)
476 || ( y
>= buf_height
) || ( x
+ width
<= 0 ) || ( y
+ height
<= 0 ) )
492 if( x
+ width
> buf_width
)
493 width
= buf_width
- x
;
494 if( y
+ height
> buf_height
)
495 height
= buf_height
- y
;
497 src
+= stride
* (src_y
>> 3) + src_x
; /* move starting point */
499 src_end
= src
+ width
;
501 dst
= buf
+ y
*buf_width
+ x
;
505 const unsigned char *src_col
= src
++;
506 unsigned data
= *src_col
>> src_y
;
507 fb_data
*dst_col
= dst
++;
508 int numbits
= 8 - src_y
;
510 dst_end
= dst_col
+ height
* buf_width
;
514 *dst_col
= fgcolor
; /* FIXME ? */
516 dst_col
+= buf_width
;
525 } while( dst_col
< dst_end
);
526 } while( src
< src_end
);
529 static void buffer_putsxyofs( fb_data
*buf
, int buf_width
, int buf_height
,
530 int x
, int y
, int ofs
, const unsigned char *str
)
535 struct font
*pf
= rb
->font_get( FONT_UI
);
536 if( !pf
) pf
= rb
->font_get( FONT_SYSFIXED
);
538 ucs
= rb
->bidi_l2v( str
, 1 );
540 while( (ch
= *ucs
++) != 0 && x
< buf_width
)
543 const unsigned char *bits
;
545 /* get proportional width and glyph bits */
546 width
= rb
->font_get_width( pf
, ch
);
554 bits
= rb
->font_get_bits( pf
, ch
);
556 buffer_mono_bitmap_part( buf
, buf_width
, buf_height
, bits
, ofs
, 0,
557 width
, x
, y
, width
- ofs
, pf
->height
);
564 /***********************************************************************
566 ***********************************************************************/
570 MAIN_MENU_NEW
, MAIN_MENU_LOAD
, MAIN_MENU_SAVE
,
571 MAIN_MENU_SET_WIDTH
, MAIN_MENU_SET_HEIGHT
,
572 MAIN_MENU_BRUSH_SIZE
, MAIN_MENU_BRUSH_SPEED
, MAIN_MENU_COLOR
,
574 MAIN_MENU_PLAYBACK_CONTROL
,
578 /* Select action menu */
579 SELECT_MENU_CUT
, SELECT_MENU_COPY
,
580 SELECT_MENU_INVERT
, SELECT_MENU_HFLIP
, SELECT_MENU_VFLIP
,
581 SELECT_MENU_ROTATE90
, SELECT_MENU_ROTATE180
, SELECT_MENU_ROTATE270
,
586 TEXT_MENU_TEXT
, TEXT_MENU_FONT
,
587 TEXT_MENU_PREVIEW
, TEXT_MENU_APPLY
, TEXT_MENU_CANCEL
,
590 MENUITEM_STRINGLIST(main_menu
, "RockPaint", NULL
,
591 "Resume", "New", "Load", "Save",
592 "Set Width", "Set Height",
593 "Brush Size", "Brush Speed",
594 "Choose Color", "Grid Size",
595 "Playback Control", "Exit");
596 MENUITEM_STRINGLIST(select_menu
, "Select...", NULL
,
598 "Invert", "Horizontal Flip", "Vertical Flip",
599 "Rotate 90°", "Rotate 180°", "Rotate 270°",
601 MENUITEM_STRINGLIST(text_menu
, "Text", NULL
,
602 "Set Text", "Change Font",
603 "Preview", "Apply", "Cancel");
604 static const int times_list
[] = { 1, 2, 4, 8 };
605 static const int gridsize_list
[] = { 0, 5, 10, 20 };
606 static const struct opt_items times_options
[] = {
607 { "1x", -1 }, { "2x", -1 }, { "4x", -1 }, { "8x", -1 }
609 static const struct opt_items gridsize_options
[] = {
610 { "No grid", -1 }, { "5px", -1 }, { "10px", -1 }, { "20px", -1 }
613 static int draw_window( int height
, int width
,
618 rb
->lcd_getstringsize( title
, NULL
, &fh
);
621 const int _top
= ( LCD_HEIGHT
- height
) / 2;
622 const int _left
= ( LCD_WIDTH
- width
) / 2;
623 if( top
) *top
= _top
;
624 if( left
) *left
= _left
;
625 rb
->lcd_set_background(COLOR_BLUE
);
626 rb
->lcd_set_foreground(COLOR_LIGHTGRAY
);
627 rb
->lcd_fillrect( _left
, _top
, width
, height
);
628 rb
->lcd_set_foreground(COLOR_BLUE
);
629 rb
->lcd_fillrect( _left
, _top
, width
, fh
+4 );
630 rb
->lcd_set_foreground(COLOR_WHITE
);
631 rb
->lcd_putsxy( _left
+2, _top
+2, title
);
632 rb
->lcd_set_foreground(COLOR_BLACK
);
633 rb
->lcd_drawrect( _left
, _top
, width
, height
);
637 /***********************************************************************
639 ***********************************************************************/
641 char bbuf
[MAX_PATH
]; /* used by file and font browsers */
642 char bbuf_s
[MAX_PATH
]; /* used by file and font browsers */
643 struct tree_context
*tree
= NULL
;
645 static bool check_extention(const char *filename
, const char *ext
)
647 const char *p
= rb
->strrchr( filename
, '.' );
648 return ( p
!= NULL
&& !rb
->strcasecmp( p
, ext
) );
651 static const char* browse_get_name_cb(int selected_item
, void *data
,
652 char *buffer
, size_t buffer_len
)
654 int *indexes
= (int *) data
;
655 struct entry
* dc
= tree
->dircache
;
656 struct entry
* e
= &dc
[indexes
[selected_item
]];
663 static bool browse( char *dst
, int dst_size
, const char *start
)
665 struct gui_synclist browse_list
;
666 int item_count
= 0, selected
, button
;
667 struct tree_context backup
;
670 int dirfilter
= SHOW_ALL
;
671 int *indexes
= (int *) buffer
->clipboard
;
675 rb
->strcpy( bbuf
, start
);
676 a
= bbuf
+rb
->strlen(bbuf
)-1;
684 rb
->gui_synclist_init(&browse_list
, browse_get_name_cb
,
685 (void*) indexes
, false, 1, NULL
);
687 tree
= rb
->tree_get_context();
690 a
= backup
.currdir
+rb
->strlen(backup
.currdir
)-1;
696 rb
->strcpy( a
, dc
[tree
->selected_item
].name
);
697 tree
->dirfilter
= &dirfilter
;
703 rb
->set_current_file(bbuf
);
706 for( i
= 0; i
< tree
->filesindir
; i
++)
708 /* only displayes directories and .bmp files */
709 if( ((dc
[i
].attr
& ATTR_DIRECTORY
) &&
710 rb
->strcmp( dc
[i
].name
, "." ) &&
711 rb
->strcmp( dc
[i
].name
, ".." )) ||
712 ( !(dc
[i
].attr
& ATTR_DIRECTORY
) &&
713 check_extention( dc
[i
].name
, ".bmp" ) ) )
715 if( !rb
->strcmp( dc
[i
].name
, bbuf_s
) )
716 selected
= item_count
;
717 indexes
[item_count
++] = i
;
721 rb
->gui_synclist_set_nb_items(&browse_list
,item_count
);
722 rb
->gui_synclist_select_item(&browse_list
, selected
);
723 rb
->gui_synclist_set_title(&browse_list
, bbuf
, NOICON
);
724 rb
->gui_synclist_draw(&browse_list
);
727 button
= rb
->get_action(CONTEXT_LIST
,TIMEOUT_BLOCK
);
728 if (rb
->gui_synclist_do_button(&browse_list
,&button
,LIST_WRAP_UNLESS_HELD
))
732 case ACTION_STD_CANCEL
:
733 if( !rb
->strcmp( bbuf
, "/" ) )
736 rb
->set_current_file( backup
.currdir
);
739 rb
->strcpy( bbuf_s
, ".." );
741 if( button
== ACTION_STD_OK
)
743 selected
= rb
->gui_synclist_get_sel_pos( &browse_list
);
744 if( selected
< 0 || selected
>= item_count
)
746 struct entry
* e
= &dc
[indexes
[selected
]];
747 rb
->strlcpy( bbuf_s
, e
->name
, sizeof( bbuf_s
) );
748 if( !( e
->attr
& ATTR_DIRECTORY
) )
751 rb
->set_current_file( backup
.currdir
);
752 rb
->snprintf( dst
, dst_size
, "%s%s", bbuf
, bbuf_s
);
756 if( !rb
->strcmp( bbuf_s
, "." ) ) break;
757 a
= bbuf
+rb
->strlen(bbuf
);
758 if( !rb
->strcmp( bbuf_s
, ".." ) )
761 if( a
== bbuf
) break;
763 while( *a
!= '/' ) a
--;
764 rb
->strcpy( bbuf_s
, ++a
);
765 /* select parent directory */
766 bbuf_s
[rb
->strlen(bbuf_s
)-1] = '\0';
771 rb
->snprintf( a
, bbuf
+sizeof(bbuf
)-a
, "%s/", bbuf_s
);
775 case ACTION_STD_MENU
:
777 rb
->set_current_file( backup
.currdir
);
783 /***********************************************************************
786 * FIXME: This still needs some work ... it currently only works fine
787 * on the simulators, disk spins too much on real targets -> rendered
788 * font buffer needed.
789 ***********************************************************************/
790 static bool browse_fonts( char *dst
, int dst_size
)
792 #define WIDTH ( LCD_WIDTH - 20 )
793 #define HEIGHT ( LCD_HEIGHT - 20 )
795 int top
, top_inside
= 0, left
;
799 int fvi
= 0; /* first visible item */
800 int lvi
= 0; /* last visible item */
801 int si
= 0; /* selected item */
802 int osi
= 0; /* old selected item */
803 int li
= 0; /* last item */
804 int nvih
= 0; /* next visible item height */
806 int b_need_redraw
= 1; /* Do we need to redraw ? */
808 int cp
= 0; /* current position */
809 int fh
; /* font height */
811 #define fh_buf buffer->text.fh_buf /* 30 might not be enough ... */
812 #define fw_buf buffer->text.fw_buf
814 #define fontname_buf buffer->text.fontname_buf
816 rb
->snprintf( buffer
->text
.old_font
, MAX_PATH
,
818 rb
->global_settings
->font_file
);
824 /* we don't need to redraw ... but we need to unselect
825 * the previously selected item */
826 cp
= top_inside
+ LINE_SPACE
;
827 for( i
= 0; i
+fvi
< osi
; i
++ )
829 cp
+= fh_buf
[i
] + LINE_SPACE
;
831 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
832 rb
->lcd_fillrect( left
+10, cp
, fw_buf
[i
], fh_buf
[i
] );
833 rb
->lcd_set_drawmode(DRMODE_SOLID
);
840 d
= rb
->opendir( FONT_DIR
"/" );
845 top_inside
= draw_window( HEIGHT
, WIDTH
, &top
, &left
, "Fonts" );
853 cp
= top_inside
+LINE_SPACE
;
855 rb
->lcd_set_foreground(COLOR_BLACK
);
856 rb
->lcd_set_background(COLOR_LIGHTGRAY
);
858 while( cp
< top
+HEIGHT
)
860 de
= rb
->readdir( d
);
866 if( !check_extention( de
->d_name
, ".fnt" ) )
868 rb
->snprintf( bbuf
, MAX_PATH
, FONT_DIR
"/%s",
870 rb
->font_load(NULL
, bbuf
);
871 rb
->font_getstringsize( de
->d_name
, &fw
, &fh
, FONT_UI
);
876 if( nvih
< 0 ) nvih
= 0;
880 if( cp
+ fh
>= top
+HEIGHT
)
885 rb
->lcd_putsxy( left
+10, cp
, de
->d_name
);
888 cp
+= fh
+ LINE_SPACE
;
889 rb
->strcpy( fontname_buf
[i
-fvi
], bbuf
);
895 if( !(de
= rb
->readdir( d
) ) )
899 else if( !nvih
&& check_extention( de
->d_name
, ".fnt" ) )
901 rb
->snprintf( bbuf
, MAX_PATH
, FONT_DIR
"/%s",
903 rb
->font_load(NULL
, bbuf
);
904 rb
->font_getstringsize( de
->d_name
, NULL
, &fh
, FONT_UI
);
908 rb
->font_load(NULL
, buffer
->text
.old_font
);
912 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
913 cp
= top_inside
+ LINE_SPACE
;
914 for( i
= 0; i
+fvi
< si
; i
++ )
916 cp
+= fh_buf
[i
] + LINE_SPACE
;
918 rb
->lcd_fillrect( left
+10, cp
, fw_buf
[i
], fh_buf
[i
] );
919 rb
->lcd_set_drawmode(DRMODE_SOLID
);
921 rb
->lcd_update_rect( left
, top
, WIDTH
, HEIGHT
);
925 switch( rb
->button_get(true) )
928 case ROCKPAINT_UP
|BUTTON_REPEAT
:
940 case ROCKPAINT_DOWN
|BUTTON_REPEAT
:
941 if( li
== -1 || si
< li
)
950 case ROCKPAINT_RIGHT
:
952 rb
->snprintf( dst
, dst_size
, "%s", fontname_buf
[si
-fvi
] );
956 if( i
!= fvi
|| si
> lvi
)
974 /***********************************************************************
975 * HSVRGB Color chooser
976 ***********************************************************************/
977 static unsigned int color_chooser( unsigned int color
)
979 int red
= RGB_UNPACK_RED( color
);
980 int green
= RGB_UNPACK_GREEN( color
);
981 int blue
= RGB_UNPACK_BLUE( color
);
982 int hue
, saturation
, value
;
983 int r
, g
, b
; /* temp variables */
986 enum BaseColor
{ Hue
= 0, Saturation
= 1, Value
= 2,
987 Red
= 3, Green
= 4, Blue
= 5 };
988 enum BaseColor current
= Red
;
993 rgb2hsv( red
, green
, blue
, &hue
, &saturation
, &value
);
998 color
= LCD_RGBPACK( red
, green
, blue
);
1000 #define HEIGHT ( 100 )
1001 #define WIDTH ( 150 )
1003 top
= draw_window( HEIGHT
, WIDTH
, NULL
, &left
, "Color chooser" );
1006 for( i
=0; i
<100; i
++ )
1008 hsv2rgb( i
*36, saturation
, value
, &r
, &g
, &b
);
1009 rb
->lcd_set_foreground( LCD_RGBPACK( r
, g
, b
) );
1010 rb
->lcd_vline( left
+15+i
, top
+20, top
+27 );
1011 hsv2rgb( hue
, i
*255/100, value
, &r
, &g
, &b
);
1012 rb
->lcd_set_foreground( LCD_RGBPACK( r
, g
, b
) );
1013 rb
->lcd_vline( left
+15+i
, top
+30, top
+37 );
1014 hsv2rgb( hue
, saturation
, i
*255/100, &r
, &g
, &b
);
1015 rb
->lcd_set_foreground( LCD_RGBPACK( r
, g
, b
) );
1016 rb
->lcd_vline( left
+15+i
, top
+40, top
+47 );
1017 rb
->lcd_set_foreground( LCD_RGBPACK( i
*255/100, green
, blue
) );
1018 rb
->lcd_vline( left
+15+i
, top
+50, top
+57 );
1019 rb
->lcd_set_foreground( LCD_RGBPACK( red
, i
*255/100, blue
) );
1020 rb
->lcd_vline( left
+15+i
, top
+60, top
+67 );
1021 rb
->lcd_set_foreground( LCD_RGBPACK( red
, green
, i
*255/100 ) );
1022 rb
->lcd_vline( left
+15+i
, top
+70, top
+77 );
1025 rb
->lcd_set_foreground(COLOR_BLACK
);
1026 #define POSITION( a, i ) \
1027 rb->lcd_drawpixel( left+14+i, top + 19 + a ); \
1028 rb->lcd_drawpixel( left+16+i, top + 19 + a ); \
1029 rb->lcd_drawpixel( left+14+i, top + 28 + a ); \
1030 rb->lcd_drawpixel( left+16+i, top + 28 + a );
1031 POSITION( 0, hue
/36 );
1032 POSITION( 10, saturation
*99/255 );
1033 POSITION( 20, value
*99/255 );
1034 POSITION( 30, red
*99/255 );
1035 POSITION( 40, green
*99/255 );
1036 POSITION( 50, blue
*99/255 );
1038 rb
->lcd_set_background(COLOR_LIGHTGRAY
);
1039 rb
->lcd_setfont( FONT_SYSFIXED
);
1040 rb
->lcd_putsxyf( left
+ 117, top
+ 20, "%d", hue
/10 );
1041 rb
->lcd_putsxyf( left
+ 117, top
+ 30, "%d.%d",
1042 saturation
/255, ((saturation
*100)/255)%100 );
1043 rb
->lcd_putsxyf( left
+ 117, top
+ 40, "%d.%d",
1044 value
/255, ((value
*100)/255)%100 );
1045 rb
->lcd_putsxyf( left
+ 117, top
+ 50, "%d", red
);
1046 rb
->lcd_putsxyf( left
+ 117, top
+ 60, "%d", green
);
1047 rb
->lcd_putsxyf( left
+ 117, top
+ 70, "%d", blue
);
1048 rb
->lcd_setfont( FONT_UI
);
1050 #define CURSOR( l ) \
1051 rb->lcd_bitmap_transparent_part( rockpaint_hsvrgb, 1, 1, 16, left+l+1, top+20, 6, 58 ); \
1052 rb->lcd_bitmap_transparent_part( rockpaint_hsvrgb, 8, 10*current, 16, left+l, top+19+10*current, 8, 10 );
1056 rb
->lcd_set_foreground( color
);
1057 rb
->lcd_fillrect( left
+15, top
+85, 100, 8 );
1061 switch( rb
->button_get(true) )
1064 current
= ( current
+ 5 )%6;
1067 case ROCKPAINT_DOWN
:
1068 current
= (current
+ 1 )%6;
1071 case ROCKPAINT_LEFT
:
1076 hue
= ( hue
+ 3600 - 10 )%3600;
1079 if( saturation
) saturation
--;
1082 if( value
) value
--;
1088 if( green
) green
--;
1096 case ROCKPAINT_LEFT
|BUTTON_REPEAT
:
1101 hue
= ( hue
+ 3600 - 100 )%3600;
1104 if( saturation
>= 8 ) saturation
-=8;
1105 else saturation
= 0;
1108 if( value
>= 8 ) value
-=8;
1112 if( red
>= 8 ) red
-=8;
1116 if( green
>= 8 ) green
-=8;
1120 if( blue
>= 8 ) blue
-=8;
1126 case ROCKPAINT_RIGHT
:
1131 hue
= ( hue
+ 10 )%3600;
1134 if( saturation
< 0xff ) saturation
++;
1137 if( value
< 0xff ) value
++;
1140 if( red
< 0xff ) red
++;
1143 if( green
< 0xff ) green
++;
1146 if( blue
< 0xff ) blue
++;
1151 case ROCKPAINT_RIGHT
|BUTTON_REPEAT
:
1156 hue
= ( hue
+ 100 )%3600;
1159 if( saturation
< 0xff - 8 ) saturation
+=8;
1160 else saturation
= 0xff;
1163 if( value
< 0xff - 8 ) value
+=8;
1167 if( red
< 0xff - 8 ) red
+=8;
1171 if( green
< 0xff - 8 ) green
+=8;
1175 if( blue
< 0xff - 8 ) blue
+=8;
1181 case ROCKPAINT_DRAW
:
1191 hsv2rgb( hue
, saturation
, value
, &red
, &green
, &blue
);
1197 rgb2hsv( red
, green
, blue
, &hue
, &saturation
, &value
);
1206 /***********************************************************************
1208 ***********************************************************************/
1209 static void init_buffer(void)
1212 fb_data color
= rp_colors
[ bgdrawcolor
];
1213 for( i
= 0; i
< ROWS
*COLS
; i
++ )
1215 save_buffer
[i
] = color
;
1219 static void draw_pixel(int x
,int y
)
1223 if( x
< 0 || x
>= COLS
|| y
< 0 || y
>= ROWS
) return;
1226 save_buffer
[ x
+y
*COLS
] = rp_colors
[bgdrawcolor
];
1230 save_buffer
[ x
+y
*COLS
] = rp_colors
[drawcolor
];
1233 rb
->lcd_drawpixel(x
,y
);
1236 static void color_picker( int x
, int y
)
1240 rb
->lcd_set_foreground( save_buffer
[ x
+y
*COLS
] );
1242 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1243 if( x
>= COLS
- PSIZE
) x
-= PSIZE
+ 2;
1244 if( y
>= ROWS
- PSIZE
) y
-= PSIZE
+ 2;
1245 rb
->lcd_drawrect( x
+ 2, y
+ 2, PSIZE
- 2, PSIZE
- 2 );
1246 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1247 rb
->lcd_drawrect( x
+ 3, y
+ 3, PSIZE
- 4, PSIZE
- 4 );
1249 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
1253 rp_colors
[ drawcolor
] = save_buffer
[ x
+y
*COLS
];
1257 static void draw_select_rectangle( int x1
, int y1
, int x2
, int y2
)
1258 /* This is a preview mode only function */
1273 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1275 for( a
= x1
; a
< x2
; a
++, i
++ )
1277 rb
->lcd_drawpixel( a
, y1
);
1278 for( a
= y1
; a
< y2
; a
++, i
++ )
1280 rb
->lcd_drawpixel( x2
, a
);
1282 for( a
= x2
; a
> x1
; a
--, i
++ )
1284 rb
->lcd_drawpixel( a
, y2
);
1286 for( a
= y2
; a
> y1
; a
--, i
++ )
1288 rb
->lcd_drawpixel( x1
, a
);
1289 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1292 static void copy_to_clipboard( void )
1294 /* This needs to be optimised ... but i'm lazy ATM */
1295 rb
->memcpy( buffer
->clipboard
, save_buffer
, COLS
*ROWS
*sizeof( fb_data
) );
1298 /* no preview mode handling atm ... do we need it ? (one if) */
1299 static void draw_invert( int x1
, int y1
, int x2
, int y2
)
1315 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1316 rb
->lcd_fillrect( x1
, y1
, x2
-x1
+1, y2
-y1
+1 );
1317 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1319 for( ; y1
<=y2
; y1
++ )
1321 for( i
= x1
; i
<=x2
; i
++ )
1323 save_buffer
[ y1
*COLS
+ i
] = ~save_buffer
[ y1
*COLS
+ i
];
1326 /*if( update )*/ rb
->lcd_update();
1329 static void draw_hflip( int x1
, int y1
, int x2
, int y2
)
1345 copy_to_clipboard();
1347 for( i
= 0; i
<= y2
- y1
; i
++ )
1349 rb
->memcpy( save_buffer
+(y1
+i
)*COLS
+x1
,
1350 buffer
->clipboard
+(y2
-i
)*COLS
+x1
,
1351 (x2
-x1
+1)*sizeof( fb_data
) );
1357 static void draw_vflip( int x1
, int y1
, int x2
, int y2
)
1373 copy_to_clipboard();
1375 for( ; y1
<= y2
; y1
++ )
1377 for( i
= 0; i
<= x2
- x1
; i
++ )
1379 save_buffer
[y1
*COLS
+x1
+i
] = buffer
->clipboard
[y1
*COLS
+x2
-i
];
1386 /* direction: -1 = left, 1 = right */
1387 static void draw_rot_90_deg( int x1
, int y1
, int x2
, int y2
, int direction
)
1403 copy_to_clipboard();
1405 fb_data color
= rp_colors
[ bgdrawcolor
];
1406 const int width
= x2
- x1
, height
= y2
- y1
;
1407 const int sub_half
= width
/2-height
/2, add_half
= (width
+height
)/2;
1408 if( width
> height
)
1410 for( i
= 0; i
<= height
; i
++ )
1412 for( j
= 0; j
< sub_half
; j
++ )
1413 save_buffer
[(y1
+i
)*COLS
+x1
+j
] = color
;
1414 for( j
= add_half
+1; j
<= width
; j
++ )
1415 save_buffer
[(y1
+i
)*COLS
+x1
+j
] = color
;
1418 else if( width
< height
)
1420 for( j
= 0; j
<= width
; j
++ )
1422 for( i
= 0; i
< -sub_half
; i
++ )
1423 save_buffer
[(y1
+i
)*COLS
+x1
+j
] = color
;
1424 for( i
= add_half
+1; i
<= height
; i
++ )
1425 save_buffer
[(y1
+i
)*COLS
+x1
+j
] = color
;
1428 int x3
= x1
+ sub_half
, y3
= y1
- sub_half
;
1429 int is
= x3
<0?-x3
:0, ie
= COLS
-x3
-1, js
= y3
<0?-y3
:0, je
= ROWS
-y3
-1;
1430 if( ie
> height
) ie
= height
;
1431 if( je
> width
) je
= width
;
1432 for( i
= is
; i
<= ie
; i
++ )
1434 for( j
= js
; j
<= je
; j
++ )
1447 save_buffer
[(y3
+j
)*COLS
+x3
+i
] = buffer
->clipboard
[y
*COLS
+x
];
1454 static void draw_paste_rectangle( int src_x1
, int src_y1
, int src_x2
,
1455 int src_y2
, int x1
, int y1
, int mode
)
1457 int i
, width
, height
;
1458 if( mode
== SELECT_MENU_CUT
)
1461 drawcolor
= bgdrawcolor
;
1462 draw_rect_full( src_x1
, src_y1
, src_x2
, src_y2
);
1465 if( src_x1
> src_x2
)
1471 if( src_y1
> src_y2
)
1477 width
= src_x2
- src_x1
+ 1;
1478 height
= src_y2
- src_y1
+ 1;
1480 if( x1
+ width
> COLS
)
1482 if( y1
+ height
> ROWS
)
1485 rb
->lcd_bitmap_part( buffer
->clipboard
, src_x1
, src_y1
, COLS
,
1486 x1
, y1
, width
, height
);
1489 for( i
= 0; i
< height
; i
++ )
1491 rb
->memcpy( save_buffer
+(y1
+i
)*COLS
+x1
,
1492 buffer
->clipboard
+(src_y1
+i
)*COLS
+src_x1
,
1493 width
*sizeof( fb_data
) );
1498 static void show_grid( bool update
)
1503 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1504 for( i
= gridsize
; i
< img_width
; i
+= gridsize
)
1506 rb
->lcd_vline( i
, 0, img_height
-1 );
1508 for( i
= gridsize
; i
< img_height
; i
+= gridsize
)
1510 rb
->lcd_hline( 0, img_width
-1, i
);
1512 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1513 if( update
) rb
->lcd_update();
1517 static void draw_text( int x
, int y
)
1520 buffer
->text
.text
[0] = '\0';
1521 rb
->snprintf( buffer
->text
.old_font
, MAX_PATH
,
1523 rb
->global_settings
->font_file
);
1526 switch( rb
->do_menu( &text_menu
, &selected
, NULL
, NULL
) )
1528 case TEXT_MENU_TEXT
:
1529 rb
->lcd_set_foreground(COLOR_BLACK
);
1530 rb
->kbd_input( buffer
->text
.text
, MAX_TEXT
);
1533 case TEXT_MENU_FONT
:
1534 if( browse_fonts( buffer
->text
.font
, MAX_PATH
) )
1536 rb
->font_load(NULL
, buffer
->text
.font
);
1540 case TEXT_MENU_PREVIEW
:
1541 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
1546 rb
->lcd_putsxy( x
, y
, buffer
->text
.text
);
1548 switch( button
= rb
->button_get( true ) )
1550 case ROCKPAINT_LEFT
:
1551 case ROCKPAINT_LEFT
| BUTTON_REPEAT
:
1552 x
-=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
1556 case ROCKPAINT_RIGHT
:
1557 case ROCKPAINT_RIGHT
| BUTTON_REPEAT
:
1558 x
+=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
1563 case ROCKPAINT_UP
| BUTTON_REPEAT
:
1564 y
-=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
1568 case ROCKPAINT_DOWN
:
1569 case ROCKPAINT_DOWN
| BUTTON_REPEAT
:
1570 y
+=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
1574 case ROCKPAINT_DRAW
:
1577 if(rb
->default_event_handler(button
)
1578 == SYS_USB_CONNECTED
)
1579 button
= ROCKPAINT_DRAW
;
1582 if( button
== ROCKPAINT_DRAW
) break;
1586 case TEXT_MENU_APPLY
:
1587 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
1588 buffer_putsxyofs( save_buffer
, COLS
, ROWS
, x
, y
, 0,
1589 buffer
->text
.text
);
1590 case TEXT_MENU_CANCEL
:
1593 rb
->font_load(NULL
, buffer
->text
.old_font
);
1599 static void draw_brush( int x
, int y
)
1602 for( i
=-bsize
/2+(bsize
+1)%2; i
<=bsize
/2; i
++ )
1604 for( j
=-bsize
/2+(bsize
+1)%2; j
<=bsize
/2; j
++ )
1606 draw_pixel( x
+i
, y
+j
);
1611 /* This is an implementation of Bresenham's line algorithm.
1612 * See http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm.
1614 static void draw_line( int x1
, int y1
, int x2
, int y2
)
1618 int deltax
= x2
- x1
;
1619 int deltay
= y2
- y1
;
1622 int xerr
= abs(deltax
);
1623 int yerr
= abs(deltay
);
1624 int xstep
= deltax
> 0 ? 1 : -1;
1625 int ystep
= deltay
> 0 ? 1 : -1;
1635 /* to leave off the last pixel of the line, leave off the "+ 1" */
1636 for (i
= abs(deltay
) + 1; i
; --i
)
1649 /* more horizontal */
1654 for (i
= abs(deltax
) + 1; i
; --i
)
1667 static void draw_curve( int x1
, int y1
, int x2
, int y2
,
1668 int xa
, int ya
, int xb
, int yb
)
1682 if( x1
== x2
&& y1
== y2
)
1684 draw_pixel( x1
, y1
);
1690 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1691 if( xa
== -1 || ya
== -1 )
1693 rb
->lcd_drawline( x1
, y1
, xb
, yb
);
1694 rb
->lcd_drawline( x2
, y2
, xb
, yb
);
1698 rb
->lcd_drawline( x1
, y1
, xa
, ya
);
1699 rb
->lcd_drawline( x2
, y2
, xb
, yb
);
1701 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1704 if( xa
== -1 || ya
== -1 )
1705 /* We only have 3 of the points
1706 * This will currently only be used in preview mode */
1708 #define PUSH( a1, b1, a2, b2, a3, b3, d ) \
1709 buffer->bezier[i].x1 = a1; \
1710 buffer->bezier[i].y1 = b1; \
1711 buffer->bezier[i].x2 = a2; \
1712 buffer->bezier[i].y2 = b2; \
1713 buffer->bezier[i].x3 = a3; \
1714 buffer->bezier[i].y3 = b3; \
1715 buffer->bezier[i].depth = d; \
1717 #define POP( a1, b1, a2, b2, a3, b3, d ) \
1719 a1 = buffer->bezier[i].x1; \
1720 b1 = buffer->bezier[i].y1; \
1721 a2 = buffer->bezier[i].x2; \
1722 b2 = buffer->bezier[i].y2; \
1723 a3 = buffer->bezier[i].x3; \
1724 b3 = buffer->bezier[i].y3; \
1725 d = buffer->bezier[i].depth;
1726 PUSH( x1
<<4, y1
<<4, xb
<<4, yb
<<4, x2
<<4, y2
<<4, 0 );
1729 /* de Casteljau's algorithm (see wikipedia) */
1730 POP( xl1
, yl1
, xb
, yb
, xr3
, yr3
, depth
);
1731 if( depth
< 10 ) /* check that the stack's 'i' doesn't overflow */
1733 xl2
= ( xl1
+ xb
)>>1;
1734 yl2
= ( yl1
+ yb
)>>1;
1735 xr2
= ( xb
+ xr3
)>>1;
1736 yr2
= ( yb
+ yr3
)>>1;
1737 xr1
= ( xl2
+ xr2
)>>1;
1738 yr1
= ( yl2
+ yr2
)>>1;
1741 PUSH( xl1
, yl1
, xl2
, yl2
, xl3
, yl3
, depth
+1 );
1742 PUSH( xr1
, yr1
, xr2
, yr2
, xr3
, yr3
, depth
+1 );
1746 draw_line( ((xl1
>>3)+1)>>1, ((yl1
>>3)+1)>>1,
1747 ((xr3
>>3)+1)>>1, ((yr3
>>3)+1)>>1 );
1753 else /* We have the 4 points */
1755 #define PUSH( a1, b1, a2, b2, a3, b3, a4, b4, d ) \
1756 buffer->bezier[i].x1 = a1; \
1757 buffer->bezier[i].y1 = b1; \
1758 buffer->bezier[i].x2 = a2; \
1759 buffer->bezier[i].y2 = b2; \
1760 buffer->bezier[i].x3 = a3; \
1761 buffer->bezier[i].y3 = b3; \
1762 buffer->bezier[i].x4 = a4; \
1763 buffer->bezier[i].y4 = b4; \
1764 buffer->bezier[i].depth = d; \
1766 #define POP( a1, b1, a2, b2, a3, b3, a4, b4, d ) \
1768 a1 = buffer->bezier[i].x1; \
1769 b1 = buffer->bezier[i].y1; \
1770 a2 = buffer->bezier[i].x2; \
1771 b2 = buffer->bezier[i].y2; \
1772 a3 = buffer->bezier[i].x3; \
1773 b3 = buffer->bezier[i].y3; \
1774 a4 = buffer->bezier[i].x4; \
1775 b4 = buffer->bezier[i].y4; \
1776 d = buffer->bezier[i].depth;
1778 PUSH( x1
<<4, y1
<<4, xa
<<4, ya
<<4, xb
<<4, yb
<<4, x2
<<4, y2
<<4, 0 );
1781 /* de Casteljau's algorithm (see wikipedia) */
1782 POP( xl1
, yl1
, xa
, ya
, xb
, yb
, xr4
, yr4
, depth
);
1783 if( depth
< 10 ) /* check that the stack's 'i' doesn't overflow */
1785 xl2
= ( xl1
+ xa
)>>1;
1786 yl2
= ( yl1
+ ya
)>>1;
1787 xh
= ( xa
+ xb
)>>1;
1788 yh
= ( ya
+ yb
)>>1;
1789 xr3
= ( xb
+ xr4
)>>1;
1790 yr3
= ( yb
+ yr4
)>>1;
1791 xl3
= ( xl2
+ xh
)>>1;
1792 yl3
= ( yl2
+ yh
)>>1;
1793 xr2
= ( xr3
+ xh
)>>1;
1794 yr2
= ( yr3
+ yh
)>>1;
1795 xl4
= ( xl3
+ xr2
)>>1;
1796 yl4
= ( yl3
+ yr2
)>>1;
1799 PUSH( xl1
, yl1
, xl2
, yl2
, xl3
, yl3
, xl4
, yl4
, depth
+1 );
1800 PUSH( xr1
, yr1
, xr2
, yr2
, xr3
, yr3
, xr4
, yr4
, depth
+1 );
1804 draw_line( ((xl1
>>3)+1)>>1, ((yl1
>>3)+1)>>1,
1805 ((xr4
>>3)+1)>>1, ((yr4
>>3)+1)>>1 );
1813 static void draw_rect( int x1
, int y1
, int x2
, int y2
)
1815 draw_line( x1
, y1
, x1
, y2
);
1816 draw_line( x1
, y1
, x2
, y1
);
1817 draw_line( x1
, y2
, x2
, y2
);
1818 draw_line( x2
, y1
, x2
, y2
);
1821 static void togglebg( void )
1825 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
1829 rb
->lcd_set_foreground( rp_colors
[ bgdrawcolor
] );
1834 static void draw_rect_full( int x1
, int y1
, int x2
, int y2
)
1847 draw_line( x
, y1
, x
, y2
);
1848 } while( ++x
<= x2
);
1850 draw_rect( x1
, y1
, x2
, y2
);
1853 static void draw_oval( int x1
, int y1
, int x2
, int y2
, bool full
)
1855 /* TODO: simplify :) */
1856 int cx
= (x1
+x2
)>>1;
1857 int cy
= (y1
+y2
)>>1;
1859 int rx
= (x1
-x2
)>>1;
1860 int ry
= (y1
-y2
)>>1;
1861 if( rx
< 0 ) rx
*= -1;
1862 if( ry
< 0 ) ry
*= -1;
1864 if( rx
== 0 || ry
== 0 )
1866 draw_line( x1
, y1
, x2
, y2
);
1873 for( x
= 0; x
< rx
; x
++ )
1879 dst
= ry
* ry
* x
* x
+ rx
* rx
* y
* y
- rx
* rx
* ry
* ry
;
1882 if( -old_dst
< dst
) y
--;
1885 draw_line( cx
+x
, cy
, cx
+x
, cy
+y
);
1886 draw_line( cx
+x
, cy
, cx
+x
, cy
-y
);
1887 draw_line( cx
-x
, cy
, cx
-x
, cy
+y
);
1888 draw_line( cx
-x
, cy
, cx
-x
, cy
-y
);
1892 draw_pixel( cx
+x
, cy
+y
);
1893 draw_pixel( cx
+x
, cy
-y
);
1894 draw_pixel( cx
-x
, cy
+y
);
1895 draw_pixel( cx
-x
, cy
-y
);
1898 for( y
= 0; y
< ry
; y
++ )
1904 dst
= ry
* ry
* x
* x
+ rx
* rx
* y
* y
- rx
* rx
* ry
* ry
;
1907 if( -old_dst
< dst
) x
--;
1910 draw_line( cx
+x
, cy
, cx
+x
, cy
+y
);
1911 draw_line( cx
+x
, cy
, cx
+x
, cy
-y
);
1912 draw_line( cx
-x
, cy
, cx
-x
, cy
+y
);
1913 draw_line( cx
-x
, cy
, cx
-x
, cy
-y
);
1917 draw_pixel( cx
+x
, cy
+y
);
1918 draw_pixel( cx
+x
, cy
-y
);
1919 draw_pixel( cx
-x
, cy
+y
);
1920 draw_pixel( cx
-x
, cy
-y
);
1925 static void draw_oval_empty( int x1
, int y1
, int x2
, int y2
)
1927 draw_oval( x1
, y1
, x2
, y2
, false );
1930 static void draw_oval_full( int x1
, int y1
, int x2
, int y2
)
1933 draw_oval( x1
, y1
, x2
, y2
, true );
1935 draw_oval( x1
, y1
, x2
, y2
, false );
1938 static void draw_fill( int x0
, int y0
)
1940 #define PUSH( a, b ) \
1941 draw_pixel( (int)a, (int)b ); \
1942 buffer->coord[i].x = a; \
1943 buffer->coord[i].y = b; \
1945 #define POP( a, b ) \
1947 a = buffer->coord[i].x; \
1948 b = buffer->coord[i].y;
1953 unsigned int prev_color
= save_buffer
[ x0
+y0
*COLS
];
1955 if( prev_color
== rp_colors
[ drawcolor
] ) return;
1962 if( x
> 0 && save_buffer
[x
-1+y
*COLS
] == prev_color
)
1966 if( x
< COLS
-1 && save_buffer
[x
+1+y
*COLS
] == prev_color
)
1970 if( y
> 0 && save_buffer
[x
+(y
-1)*COLS
] == prev_color
)
1974 if( y
< ROWS
- 1 && save_buffer
[x
+(y
+1)*COLS
] == prev_color
)
1984 /* For preview purposes only */
1985 static void line_gradient( int x1
, int y1
, int x2
, int y2
)
1989 int h1
, s1
, v1
, h2
, s2
, v2
, r
, g
, b
;
2002 if( w
== 0 && h
== 0 )
2004 draw_pixel( x1
>>1, y1
>>1 );
2008 r1
= RGB_UNPACK_RED( rp_colors
[ bgdrawcolor
] );
2009 g1
= RGB_UNPACK_GREEN( rp_colors
[ bgdrawcolor
] );
2010 b1
= RGB_UNPACK_BLUE( rp_colors
[ bgdrawcolor
] );
2011 r2
= RGB_UNPACK_RED( rp_colors
[ drawcolor
] );
2012 g2
= RGB_UNPACK_GREEN( rp_colors
[ drawcolor
] );
2013 b2
= RGB_UNPACK_BLUE( rp_colors
[ drawcolor
] );
2038 rgb2hsv( r1
, g1
, b1
, &h1
, &s1
, &v1
);
2039 rgb2hsv( r2
, g2
, b2
, &h2
, &s2
, &v2
);
2056 hsv2rgb( h1
+((h2
-h1
)*(x1
-x2
))/w
,
2057 s1
+((s2
-s1
)*(x1
-x2
))/w
,
2058 v1
+((v2
-v1
)*(x1
-x2
))/w
,
2060 rp_colors
[ drawcolor
] = LCD_RGBPACK( r
, g
, b
);
2061 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
2062 draw_pixel( (x1
+1)>>1, (y1
+1)>>1 );
2064 y1
= y2
- ( x2
- x1
) * h
/ w
;
2082 hsv2rgb( h1
+((h2
-h1
)*(y1
-y2
))/h
,
2083 s1
+((s2
-s1
)*(y1
-y2
))/h
,
2084 v1
+((v2
-v1
)*(y1
-y2
))/h
,
2086 rp_colors
[ drawcolor
] = LCD_RGBPACK( r
, g
, b
);
2087 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
2088 draw_pixel( (x1
+1)>>1, (y1
+1)>>1 );
2090 x1
= x2
- ( y2
- y1
) * w
/ h
;
2095 rp_colors
[ drawcolor
] = LCD_RGBPACK( r1
, g1
, b1
);
2099 rp_colors
[ drawcolor
] = LCD_RGBPACK( r2
, g2
, b2
);
2103 static void linear_gradient( int x1
, int y1
, int x2
, int y2
)
2105 int r1
= RGB_UNPACK_RED( rp_colors
[ bgdrawcolor
] );
2106 int g1
= RGB_UNPACK_GREEN( rp_colors
[ bgdrawcolor
] );
2107 int b1
= RGB_UNPACK_BLUE( rp_colors
[ bgdrawcolor
] );
2108 int r2
= RGB_UNPACK_RED( rp_colors
[ drawcolor
] );
2109 int g2
= RGB_UNPACK_GREEN( rp_colors
[ drawcolor
] );
2110 int b2
= RGB_UNPACK_BLUE( rp_colors
[ drawcolor
] );
2112 int h1
, s1
, v1
, h2
, s2
, v2
, r
, g
, b
;
2115 int radius2
= ( x1
- x2
) * ( x1
- x2
) + ( y1
- y2
) * ( y1
- y2
);
2118 /* We only propagate the gradient to neighboring pixels with the same
2119 * color as ( x1, y1 ) */
2120 unsigned int prev_color
= save_buffer
[ x1
+y1
*COLS
];
2125 if( radius2
== 0 ) return;
2128 line_gradient( x1
, y1
, x2
, y2
);
2131 rgb2hsv( r1
, g1
, b1
, &h1
, &s1
, &v1
);
2132 rgb2hsv( r2
, g2
, b2
, &h2
, &s2
, &v2
);
2134 #define PUSH( x0, y0 ) \
2135 buffer->coord[i].x = (short)(x0); \
2136 buffer->coord[i].y = (short)(y0); \
2138 #define POP( a, b ) \
2140 a = (int)buffer->coord[i].x; \
2141 b = (int)buffer->coord[i].y;
2149 dist2
= ( x2
- x1
) * ( x
- x1
) + ( y2
- y1
) * ( y
- y1
);
2152 rp_colors
[ drawcolor
] = rp_colors
[ bgdrawcolor
];
2154 else if( dist2
< radius2
)
2156 hsv2rgb( h1
+((h2
-h1
)*dist2
)/radius2
,
2157 s1
+((s2
-s1
)*dist2
)/radius2
,
2158 v1
+((v2
-v1
)*dist2
)/radius2
,
2160 rp_colors
[ drawcolor
] = LCD_RGBPACK( r
, g
, b
);
2164 rp_colors
[ drawcolor
] = LCD_RGBPACK( r2
, g2
, b2
);
2166 if( rp_colors
[ drawcolor
] == prev_color
)
2168 if( rp_colors
[ drawcolor
])
2169 rp_colors
[ drawcolor
]--; /* GRUIK */
2171 rp_colors
[ drawcolor
]++; /* GRUIK */
2173 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
2176 if( x
> 0 && save_buffer
[x
-1+y
*COLS
] == prev_color
)
2180 if( x
< COLS
-1 && save_buffer
[x
+1+y
*COLS
] == prev_color
)
2184 if( y
> 0 && save_buffer
[x
+(y
-1)*COLS
] == prev_color
)
2188 if( y
< ROWS
- 1 && save_buffer
[x
+(y
+1)*COLS
] == prev_color
)
2196 rp_colors
[ drawcolor
] = LCD_RGBPACK( r2
, g2
, b2
);
2199 static void radial_gradient( int x1
, int y1
, int x2
, int y2
)
2201 int r1
= RGB_UNPACK_RED( rp_colors
[ bgdrawcolor
] );
2202 int g1
= RGB_UNPACK_GREEN( rp_colors
[ bgdrawcolor
] );
2203 int b1
= RGB_UNPACK_BLUE( rp_colors
[ bgdrawcolor
] );
2204 int r2
= RGB_UNPACK_RED( rp_colors
[ drawcolor
] );
2205 int g2
= RGB_UNPACK_GREEN( rp_colors
[ drawcolor
] );
2206 int b2
= RGB_UNPACK_BLUE( rp_colors
[ drawcolor
] );
2208 int h1
, s1
, v1
, h2
, s2
, v2
, r
, g
, b
;
2211 int radius2
= ( x1
- x2
) * ( x1
- x2
) + ( y1
- y2
) * ( y1
- y2
);
2214 /* We only propagate the gradient to neighboring pixels with the same
2215 * color as ( x1, y1 ) */
2216 unsigned int prev_color
= save_buffer
[ x1
+y1
*COLS
];
2221 if( radius2
== 0 ) return;
2224 line_gradient( x1
, y1
, x2
, y2
);
2227 rgb2hsv( r1
, g1
, b1
, &h1
, &s1
, &v1
);
2228 rgb2hsv( r2
, g2
, b2
, &h2
, &s2
, &v2
);
2230 #define PUSH( x0, y0 ) \
2231 buffer->coord[i].x = (short)(x0); \
2232 buffer->coord[i].y = (short)(y0); \
2234 #define POP( a, b ) \
2236 a = (int)buffer->coord[i].x; \
2237 b = (int)buffer->coord[i].y;
2245 if( ( dist2
= (x1
-(x
))*(x1
-(x
))+(y1
-(y
))*(y1
-(y
)) ) < radius2
)
2247 hsv2rgb( h1
+((h2
-h1
)*dist2
)/radius2
,
2248 s1
+((s2
-s1
)*dist2
)/radius2
,
2249 v1
+((v2
-v1
)*dist2
)/radius2
,
2251 rp_colors
[ drawcolor
] = LCD_RGBPACK( r
, g
, b
);
2255 rp_colors
[ drawcolor
] = LCD_RGBPACK( r2
, g2
, b2
);
2257 if( rp_colors
[ drawcolor
] == prev_color
)
2259 if( rp_colors
[ drawcolor
])
2260 rp_colors
[ drawcolor
]--; /* GRUIK */
2262 rp_colors
[ drawcolor
]++; /* GRUIK */
2264 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
2267 if( x
> 0 && save_buffer
[x
-1+y
*COLS
] == prev_color
)
2271 if( x
< COLS
-1 && save_buffer
[x
+1+y
*COLS
] == prev_color
)
2275 if( y
> 0 && save_buffer
[x
+(y
-1)*COLS
] == prev_color
)
2279 if( y
< ROWS
- 1 && save_buffer
[x
+(y
+1)*COLS
] == prev_color
)
2287 rp_colors
[ drawcolor
] = LCD_RGBPACK( r2
, g2
, b2
);
2290 static void draw_toolbars(bool update
)
2293 #define TOP (LCD_HEIGHT-TB_HEIGHT)
2294 rb
->lcd_set_background( COLOR_LIGHTGRAY
);
2295 rb
->lcd_set_foreground( COLOR_LIGHTGRAY
);
2296 rb
->lcd_fillrect( 0, TOP
, LCD_WIDTH
, TB_HEIGHT
);
2297 rb
->lcd_set_foreground( COLOR_BLACK
);
2298 rb
->lcd_drawrect( 0, TOP
, LCD_WIDTH
, TB_HEIGHT
);
2300 rb
->lcd_set_foreground( rp_colors
[ bgdrawcolor
] );
2301 rb
->lcd_fillrect( TB_SC_BG_LEFT
, TOP
+TB_SC_BG_TOP
,
2302 TB_SC_SIZE
, TB_SC_SIZE
);
2303 rb
->lcd_set_foreground(ROCKPAINT_PALETTE
);
2304 rb
->lcd_drawrect( TB_SC_BG_LEFT
, TOP
+TB_SC_BG_TOP
,
2305 TB_SC_SIZE
, TB_SC_SIZE
);
2306 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
2307 rb
->lcd_fillrect( TB_SC_FG_LEFT
, TOP
+TB_SC_FG_TOP
,
2308 TB_SC_SIZE
, TB_SC_SIZE
);
2309 rb
->lcd_set_foreground(ROCKPAINT_PALETTE
);
2310 rb
->lcd_drawrect( TB_SC_FG_LEFT
, TOP
+TB_SC_FG_TOP
,
2311 TB_SC_SIZE
, TB_SC_SIZE
);
2313 for( i
=0; i
<18; i
++ )
2315 rb
->lcd_set_foreground( rp_colors
[i
] );
2317 TB_PL_LEFT
+(i
%9)*( TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
),
2318 TOP
+TB_PL_TOP
+(i
/9)*( TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
),
2319 TB_PL_COLOR_SIZE
, TB_PL_COLOR_SIZE
);
2320 rb
->lcd_set_foreground( ROCKPAINT_PALETTE
);
2322 TB_PL_LEFT
+(i
%9)*( TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
),
2323 TOP
+TB_PL_TOP
+(i
/9)*( TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
),
2324 TB_PL_COLOR_SIZE
, TB_PL_COLOR_SIZE
);
2327 #define SEPARATOR( x, y ) \
2328 rb->lcd_set_foreground( COLOR_WHITE ); \
2329 rb->lcd_vline( x, TOP+y, TOP+y+TB_PL_HEIGHT-1 ); \
2330 rb->lcd_set_foreground( COLOR_DARKGRAY ); \
2331 rb->lcd_vline( x+1, TOP+y, TOP+y+TB_PL_HEIGHT-1 );
2332 SEPARATOR( TB_PL_LEFT
+ TB_PL_WIDTH
- 1 + TB_SP_MARGIN
, TB_PL_TOP
);
2334 rb
->lcd_bitmap_transparent( rockpaint
, TB_TL_LEFT
, TOP
+TB_TL_TOP
,
2335 TB_TL_WIDTH
, TB_TL_HEIGHT
);
2336 rb
->lcd_set_foreground(ROCKPAINT_PALETTE
);
2337 rb
->lcd_drawrect( TB_TL_LEFT
+(TB_TL_SIZE
+TB_TL_SPACING
)*(tool
/2),
2338 TOP
+TB_TL_TOP
+(TB_TL_SIZE
+TB_TL_SPACING
)*(tool
%2),
2339 TB_TL_SIZE
, TB_TL_SIZE
);
2341 SEPARATOR( TB_TL_LEFT
+ TB_TL_WIDTH
- 1 + TB_SP_MARGIN
, TB_TL_TOP
);
2343 rb
->lcd_setfont( FONT_SYSFIXED
);
2344 rb
->lcd_putsxy( TB_MENU_LEFT
, TOP
+TB_MENU_TOP
, "Menu" );
2345 rb
->lcd_setfont( FONT_UI
);
2348 if( update
) rb
->lcd_update();
2351 static void toolbar( void )
2355 draw_toolbars( false );
2356 y
= LCD_HEIGHT
-TB_HEIGHT
/2;
2360 switch( button
= rb
->button_get( true ) )
2362 case ROCKPAINT_DRAW
:
2363 #define TOP ( LCD_HEIGHT - TB_HEIGHT )
2364 if( y
>= TOP
+ TB_SC_FG_TOP
2365 && y
< TOP
+ TB_SC_FG_TOP
+ TB_SC_SIZE
2366 && x
>= TB_SC_FG_LEFT
2367 && x
< TB_SC_FG_LEFT
+ TB_SC_SIZE
)
2369 /* click on the foreground color */
2370 rp_colors
[drawcolor
] = color_chooser( rp_colors
[drawcolor
] );
2372 else if( y
>= TOP
+ TB_SC_BG_TOP
2373 && y
< TOP
+ TB_SC_BG_TOP
+ TB_SC_SIZE
2374 && x
>= TB_SC_BG_LEFT
2375 && x
< TB_SC_BG_LEFT
+ TB_SC_SIZE
)
2377 /* click on the background color */
2379 drawcolor
= bgdrawcolor
;
2382 else if( y
>= TOP
+ TB_PL_TOP
2383 && y
< TOP
+ TB_PL_TOP
+ TB_PL_HEIGHT
2385 && x
< TB_PL_LEFT
+ TB_PL_WIDTH
)
2387 /* click on the palette */
2388 i
= (x
- TB_PL_LEFT
)%(TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
);
2389 j
= (y
- (TOP
+TB_PL_TOP
) )%(TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
);
2390 if( i
>= TB_PL_COLOR_SIZE
|| j
>= TB_PL_COLOR_SIZE
)
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 drawcolor
= j
*(TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
)+i
;
2396 else if( y
>= TOP
+TB_TL_TOP
2397 && y
< TOP
+ TB_TL_TOP
+ TB_TL_HEIGHT
2399 && x
<= TB_TL_LEFT
+ TB_TL_WIDTH
)
2401 /* click on the tools */
2402 i
= (x
- TB_TL_LEFT
) % (TB_TL_SIZE
+TB_TL_SPACING
);
2403 j
= (y
- (TOP
+TB_TL_TOP
) ) %(TB_TL_SIZE
+TB_TL_SPACING
);
2404 if( i
>= TB_TL_SIZE
|| j
>= TB_TL_SIZE
) break;
2405 i
= ( x
- TB_TL_LEFT
)/(TB_TL_SIZE
+TB_TL_SPACING
);
2406 j
= ( y
- (TOP
+TB_TL_TOP
) )/(TB_TL_SIZE
+TB_TL_SPACING
);
2416 else if( x
>= TB_MENU_LEFT
&& y
>= TOP
+TB_MENU_TOP
-2)
2423 draw_toolbars( false );
2427 case ROCKPAINT_LEFT
:
2428 case ROCKPAINT_LEFT
| BUTTON_REPEAT
:
2430 x
-=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
2435 case ROCKPAINT_RIGHT
:
2436 case ROCKPAINT_RIGHT
| BUTTON_REPEAT
:
2438 x
+=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
2444 case ROCKPAINT_UP
| BUTTON_REPEAT
:
2446 y
-=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
2447 if (y
<LCD_HEIGHT
-TB_HEIGHT
)
2454 case ROCKPAINT_DOWN
:
2455 case ROCKPAINT_DOWN
| BUTTON_REPEAT
:
2457 y
+=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
2466 case ROCKPAINT_TOOLBAR
:
2467 case ROCKPAINT_TOOLBAR2
:
2474 static void inv_cursor(bool update
)
2476 rb
->lcd_set_foreground(COLOR_BLACK
);
2477 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
2478 /* cross painting */
2479 rb
->lcd_hline(x
-4,x
+4,y
);
2480 rb
->lcd_vline(x
,y
-4,y
+4);
2481 rb
->lcd_set_foreground(rp_colors
[drawcolor
]);
2482 rb
->lcd_set_drawmode(DRMODE_SOLID
);
2484 if( update
) rb
->lcd_update();
2487 static void restore_screen(void)
2489 rb
->lcd_bitmap( save_buffer
, 0, 0, COLS
, ROWS
);
2490 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
2491 rb
->lcd_vline( img_width
, 0, ROWS
);
2492 rb
->lcd_hline( 0, COLS
, img_height
);
2493 rb
->lcd_drawpixel( img_width
, img_height
);
2494 rb
->lcd_set_drawmode(DRMODE_SOLID
);
2497 static void clear_drawing(void)
2502 rb
->lcd_set_foreground( rp_colors
[ bgdrawcolor
] );
2503 rb
->lcd_fillrect( 0, 0, COLS
, ROWS
);
2507 static void goto_menu(void)
2514 switch( rb
->do_menu( &main_menu
, &selected
, NULL
, false ) )
2520 case MAIN_MENU_LOAD
:
2521 if( browse( filename
, MAX_PATH
, "/" ) )
2523 if( load_bitmap( filename
) <= 0 )
2525 rb
->splashf( 1*HZ
, "Error while loading %s",
2531 rb
->splashf( 1*HZ
, "Image loaded (%s)", filename
);
2539 case MAIN_MENU_SAVE
:
2540 rb
->lcd_set_foreground(COLOR_BLACK
);
2542 rb
->strcpy(filename
,"/");
2543 if( !rb
->kbd_input( filename
, MAX_PATH
) )
2545 if( !check_extention( filename
, ".bmp" ) )
2546 rb
->strcat(filename
, ".bmp");
2547 save_bitmap( filename
);
2548 rb
->splashf( 1*HZ
, "File saved (%s)", filename
);
2552 case MAIN_MENU_SET_WIDTH
:
2553 rb
->set_int( "Set Width", "px", UNIT_INT
, &img_width
,
2554 NULL
, 1, 1, COLS
, NULL
);
2556 case MAIN_MENU_SET_HEIGHT
:
2557 rb
->set_int( "Set Height", "px", UNIT_INT
, &img_height
,
2558 NULL
, 1, 1, ROWS
, NULL
);
2560 case MAIN_MENU_BRUSH_SIZE
:
2561 for(multi
= 0; multi
<4; multi
++)
2562 if(bsize
== times_list
[multi
]) break;
2563 rb
->set_option( "Brush Size", &multi
, INT
, times_options
, 4, NULL
);
2565 bsize
= times_list
[multi
];
2568 case MAIN_MENU_BRUSH_SPEED
:
2569 for(multi
= 0; multi
<3; multi
++)
2570 if(bspeed
== times_list
[multi
]) break;
2571 rb
->set_option( "Brush Speed", &multi
, INT
, times_options
, 3, NULL
);
2573 bspeed
= times_list
[multi
];
2576 case MAIN_MENU_COLOR
:
2577 rp_colors
[drawcolor
] = color_chooser( rp_colors
[drawcolor
] );
2580 case MAIN_MENU_GRID_SIZE
:
2581 for(multi
= 0; multi
<4; multi
++)
2582 if(gridsize
== gridsize_list
[multi
]) break;
2583 rb
->set_option( "Grid Size", &multi
, INT
, gridsize_options
, 4, NULL
);
2585 gridsize
= gridsize_list
[multi
];
2588 case MAIN_MENU_PLAYBACK_CONTROL
:
2589 playback_control( NULL
);
2592 case MAIN_MENU_EXIT
:
2597 case MAIN_MENU_RESUME
:
2605 static void reset_tool( void )
2617 static bool rockpaint_loop( void )
2629 button
= rb
->button_get(true);
2631 if( tool
== Brush
&& prev_x
!= -1 )
2635 else if( button
& BUTTON_REPEAT
)
2646 case ROCKPAINT_QUIT
:
2647 rb
->lcd_set_drawmode(DRMODE_SOLID
);
2650 case ROCKPAINT_MENU
:
2657 case ROCKPAINT_DRAW
:
2662 if( prev_x
== -1 ) prev_x
= 1;
2666 case SelectRectangle
:
2673 case LinearGradient
:
2674 case RadialGradient
:
2675 /* Curve uses 4 points, others use 2 */
2676 if( prev_x
== -1 || prev_y
== -1 )
2682 else if( tool
== Curve
2683 && ( prev_x2
== -1 || prev_y2
== -1 ) )
2688 else if( tool
== SelectRectangle
2689 && ( prev_x2
== -1 || prev_y2
== -1 ) )
2691 tool_mode
= rb
->do_menu( &select_menu
,
2692 NULL
, NULL
, false );
2695 case SELECT_MENU_CUT
:
2696 case SELECT_MENU_COPY
:
2699 copy_to_clipboard();
2700 if( prev_x
< x
) x
= prev_x
;
2701 if( prev_y
< y
) y
= prev_y
;
2704 case SELECT_MENU_INVERT
:
2705 draw_invert( prev_x
, prev_y
, x
, y
);
2709 case SELECT_MENU_HFLIP
:
2710 draw_hflip( prev_x
, prev_y
, x
, y
);
2714 case SELECT_MENU_VFLIP
:
2715 draw_vflip( prev_x
, prev_y
, x
, y
);
2719 case SELECT_MENU_ROTATE90
:
2720 draw_rot_90_deg( prev_x
, prev_y
, x
, y
, 1 );
2724 case SELECT_MENU_ROTATE180
:
2725 draw_hflip( prev_x
, prev_y
, x
, y
);
2726 draw_vflip( prev_x
, prev_y
, x
, y
);
2730 case SELECT_MENU_ROTATE270
:
2731 draw_rot_90_deg( prev_x
, prev_y
, x
, y
, -1 );
2735 case SELECT_MENU_CANCEL
:
2744 else if( tool
== Curve
2745 && ( prev_x3
== -1 || prev_y3
== -1 ) )
2755 case SelectRectangle
:
2756 draw_paste_rectangle( prev_x
, prev_y
,
2761 draw_line( prev_x
, prev_y
, x
, y
);
2764 draw_curve( prev_x
, prev_y
,
2770 draw_rect( prev_x
, prev_y
, x
, y
);
2773 draw_rect_full( prev_x
, prev_y
, x
, y
);
2776 draw_oval_empty( prev_x
, prev_y
, x
, y
);
2779 draw_oval_full( prev_x
, prev_y
, x
, y
);
2781 case LinearGradient
:
2782 linear_gradient( prev_x
, prev_y
, x
, y
);
2784 case RadialGradient
:
2785 radial_gradient( prev_x
, prev_y
, x
, y
);
2801 color_picker( x
, y
);
2814 case ROCKPAINT_DRAW
|BUTTON_REPEAT
:
2817 /* 3 point bezier curve */
2819 draw_curve( prev_x
, prev_y
,
2829 case ROCKPAINT_TOOLBAR
:
2838 case ROCKPAINT_TOOLBAR2
:
2847 case ROCKPAINT_LEFT
:
2848 case ROCKPAINT_LEFT
| BUTTON_REPEAT
:
2850 x
-=bspeed
* accelaration
;
2855 case ROCKPAINT_RIGHT
:
2856 case ROCKPAINT_RIGHT
| BUTTON_REPEAT
:
2858 x
+=bspeed
* accelaration
;
2864 case ROCKPAINT_UP
| BUTTON_REPEAT
:
2866 y
-=bspeed
* accelaration
;
2871 case ROCKPAINT_DOWN
:
2872 case ROCKPAINT_DOWN
| BUTTON_REPEAT
:
2874 y
+=bspeed
* accelaration
;
2884 if (rb
->default_event_handler(button
) == SYS_USB_CONNECTED
)
2885 return PLUGIN_USB_CONNECTED
;
2888 if( tool
== Brush
&& prev_x
== 1 )
2894 if( preview
|| tool
== ColorPicker
)
2895 /* always preview color picker */
2900 case SelectRectangle
:
2901 if( prev_x2
== -1 || prev_y2
== -1 )
2903 /* we are defining the selection */
2904 draw_select_rectangle( prev_x
, prev_y
, x
, y
);
2908 /* we are pasting the selected data */
2909 draw_paste_rectangle( prev_x
, prev_y
, prev_x2
,
2910 prev_y2
, x
, y
, tool_mode
);
2911 prev_x3
= prev_x2
-prev_x
;
2912 if( prev_x3
< 0 ) prev_x3
*= -1;
2913 prev_y3
= prev_y2
-prev_y
;
2914 if( prev_y3
< 0 ) prev_y3
*= -1;
2915 draw_select_rectangle( x
, y
, x
+prev_x3
, y
+prev_y3
);
2925 draw_line( prev_x
, prev_y
, x
, y
);
2929 if( prev_x2
== -1 || prev_y2
== -1 )
2931 draw_line( prev_x
, prev_y
, x
, y
);
2935 draw_curve( prev_x
, prev_y
,
2943 draw_rect( prev_x
, prev_y
, x
, y
);
2947 draw_rect_full( prev_x
, prev_y
, x
, y
);
2951 draw_oval_empty( prev_x
, prev_y
, x
, y
);
2955 draw_oval_full( prev_x
, prev_y
, x
, y
);
2963 color_picker( x
, y
);
2967 case LinearGradient
:
2968 line_gradient( prev_x
, prev_y
, x
, y
);
2971 case RadialGradient
:
2972 line_gradient( prev_x
, prev_y
, x
, y
);
2991 static int load_bitmap( const char *file
)
2996 fb_data color
= rp_colors
[ bgdrawcolor
];
2998 bm
.data
= (char*)save_buffer
;
2999 ret
= rb
->read_bmp_file( file
, &bm
, ROWS
*COLS
*sizeof( fb_data
),
3000 FORMAT_NATIVE
, NULL
);
3002 if((bm
.width
> COLS
) || ( bm
.height
> ROWS
))
3005 img_width
= bm
.width
;
3006 img_height
= bm
.height
;
3007 for( i
= bm
.height
-1; i
>= 0; i
-- )
3009 rb
->memmove( save_buffer
+i
*COLS
, save_buffer
+i
*bm
.width
,
3010 sizeof( fb_data
)*bm
.width
);
3011 for( j
= bm
.width
; j
< COLS
; j
++ )
3012 save_buffer
[j
+i
*COLS
] = color
;
3014 for( i
= bm
.height
*COLS
; i
< ROWS
*COLS
; i
++ )
3015 save_buffer
[i
] = color
;
3020 static int save_bitmap( char *file
)
3024 for(i
= 0; i
< img_height
; i
++)
3026 rb
->memcpy( buffer
->clipboard
+i
*img_width
, save_buffer
+i
*COLS
,
3027 sizeof( fb_data
)*img_width
);
3029 bm
.data
= (char*)buffer
->clipboard
;
3030 bm
.height
= img_height
;
3031 bm
.width
= img_width
;
3032 bm
.format
= FORMAT_NATIVE
;
3033 return save_bmp_file( file
, &bm
);
3036 enum plugin_status
plugin_start(const void* parameter
)
3039 buffer
= (buf
*) (((uintptr_t)rb
->plugin_get_buffer(&buffer_size
) + 3) & ~3);
3040 if (buffer_size
< sizeof(*buffer
) + 3)
3042 /* steal from audiobuffer if plugin buffer is too small */
3044 (((uintptr_t)rb
->plugin_get_audio_buffer(&buffer_size
) + 3) & ~3);
3046 if (buffer_size
< sizeof(*buffer
) + 3)
3048 rb
->splash(HZ
, "Not enough memory");
3049 return PLUGIN_ERROR
;
3053 rb
->lcd_set_foreground(COLOR_WHITE
);
3054 rb
->lcd_set_backdrop(NULL
);
3055 rb
->lcd_fillrect(0,0,LCD_WIDTH
,LCD_HEIGHT
);
3056 rb
->splash( HZ
/2, "Rock Paint");
3058 rb
->lcd_clear_display();
3064 if( load_bitmap( parameter
) <= 0 )
3066 rb
->splash( 1*HZ
, "File Open Error");
3071 rb
->splashf( 1*HZ
, "Image loaded (%s)", (char *)parameter
);
3073 rb
->strcpy( filename
, parameter
);
3082 return rockpaint_loop();