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 == COWOND2_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 == ONDAVX747_PAD )
159 #define ROCKPAINT_QUIT BUTTON_POWER
160 #define ROCKPAINT_MENU BUTTON_MENU
162 #elif CONFIG_KEYPAD == MROBE500_PAD
163 #define ROCKPAINT_QUIT BUTTON_POWER
165 #elif ( CONFIG_KEYPAD == SAMSUNG_YH_PAD )
166 #define ROCKPAINT_QUIT BUTTON_REC
167 #define ROCKPAINT_DRAW BUTTON_PLAY
168 #define ROCKPAINT_MENU BUTTON_FFWD
169 #define ROCKPAINT_TOOLBAR BUTTON_REW
170 #define ROCKPAINT_TOOLBAR2 ( BUTTON_REW | BUTTON_LEFT )
171 #define ROCKPAINT_UP BUTTON_UP
172 #define ROCKPAINT_DOWN BUTTON_DOWN
173 #define ROCKPAINT_LEFT BUTTON_LEFT
174 #define ROCKPAINT_RIGHT BUTTON_RIGHT
177 #error "Please define keys for this keypad"
180 #ifdef HAVE_TOUCHSCREEN
181 #ifndef ROCKPAINT_QUIT
182 #define ROCKPAINT_QUIT BUTTON_TOPLEFT
184 #ifndef ROCKPAINT_DRAW
185 #define ROCKPAINT_DRAW BUTTON_CENTER
187 #ifndef ROCKPAINT_MENU
188 #define ROCKPAINT_MENU BUTTON_TOPRIGHT
190 #ifndef ROCKPAINT_TOOLBAR
191 #define ROCKPAINT_TOOLBAR BUTTON_BOTTOMLEFT
193 #ifndef ROCKPAINT_TOOLBAR2
194 #define ROCKPAINT_TOOLBAR2 BUTTON_BOTTOMRIGHT
197 #define ROCKPAINT_UP BUTTON_TOPMIDDLE
199 #ifndef ROCKPAINT_DOWN
200 #define ROCKPAINT_DOWN BUTTON_BOTTOMMIDDLE
202 #ifndef ROCKPAINT_LEFT
203 #define ROCKPAINT_LEFT BUTTON_MIDLEFT
205 #ifndef ROCKPAINT_RIGHT
206 #define ROCKPAINT_RIGHT BUTTON_MIDRIGHT
210 /***********************************************************************
211 * Palette Default Colors
212 ***********************************************************************/
213 #define COLOR_BLACK LCD_RGBPACK(0,0,0)
214 #define COLOR_WHITE LCD_RGBPACK(255,255,255)
215 #define COLOR_DARKGRAY LCD_RGBPACK(128,128,128)
216 #define COLOR_LIGHTGRAY LCD_RGBPACK(192,192,192)
217 #define COLOR_RED LCD_RGBPACK(128,0,0)
218 #define COLOR_LIGHTRED LCD_RGBPACK(255,0,0)
219 #define COLOR_DARKYELLOW LCD_RGBPACK(128,128,0)
220 #define COLOR_YELLOW LCD_RGBPACK(255,255,0)
221 #define COLOR_GREEN LCD_RGBPACK(0,128,0)
222 #define COLOR_LIGHTGREN LCD_RGBPACK(0,255,0)
223 #define COLOR_CYAN LCD_RGBPACK(0,128,128)
224 #define COLOR_LIGHTCYAN LCD_RGBPACK(0,255,255)
225 #define COLOR_BLUE LCD_RGBPACK(0,0,128)
226 #define COLOR_LIGHTBLUE LCD_RGBPACK(0,0,255)
227 #define COLOR_PURPLE LCD_RGBPACK(128,0,128)
228 #define COLOR_PINK LCD_RGBPACK(255,0,255)
229 #define COLOR_BROWN LCD_RGBPACK(128,64,0)
230 #define COLOR_LIGHTBROWN LCD_RGBPACK(255,128,64)
232 #define SPLASH_SCREEN PLUGIN_APPS_DIR "/rockpaint/splash.bmp"
233 #define ROCKPAINT_TITLE_FONT 2
235 /***********************************************************************
237 ***********************************************************************/
238 #define ROCKPAINT_PALETTE LCD_RGBPACK(0,64,128)
239 #define ROCKPAINT_SELECTED LCD_RGBPACK(128,192,255)
241 #define ROWS LCD_HEIGHT
242 #define COLS LCD_WIDTH
245 * Toolbar positioning stuff ... don't read this unless you really need to
254 /* Separator sizes */
255 #define TB_SP_MARGIN 3
256 #define TB_SP_WIDTH (2+2*TB_SP_MARGIN)
258 /* Selected color sizes */
259 #define TB_SC_SIZE 12
262 #define TB_PL_COLOR_SIZE 7
263 #define TB_PL_COLOR_SPACING 2
264 #define TB_PL_WIDTH ( 9 * TB_PL_COLOR_SIZE + 8 * TB_PL_COLOR_SPACING )
265 #define TB_PL_HEIGHT ( TB_PL_COLOR_SIZE * 2 + TB_PL_COLOR_SPACING )
269 #define TB_TL_SPACING 2
270 #define TB_TL_WIDTH ( 7 * ( TB_TL_SIZE + TB_TL_SPACING ) - TB_TL_SPACING )
271 #define TB_TL_HEIGHT ( 2 * TB_TL_SIZE + TB_TL_SPACING )
273 /* Menu button size ... gruik */
274 #define TB_MENU_MIN_WIDTH 30
276 /* Selected colors position */
277 #define TB_SC_FG_TOP 2
278 #define TB_SC_FG_LEFT 2
279 #define TB_SC_BG_TOP (TB_SC_FG_TOP+TB_PL_COLOR_SIZE*2+TB_PL_COLOR_SPACING-TB_SC_SIZE)
280 #define TB_SC_BG_LEFT (TB_SC_FG_LEFT+TB_PL_COLOR_SIZE*2+TB_PL_COLOR_SPACING-TB_SC_SIZE)
282 /* Palette position */
283 #define TB_PL_TOP TB_SC_FG_TOP
284 #define TB_PL_LEFT (TB_SC_BG_LEFT + TB_SC_SIZE + TB_PL_COLOR_SPACING)
287 #define TB_TL_TOP TB_SC_FG_TOP
288 #define TB_TL_LEFT ( TB_PL_LEFT + TB_PL_WIDTH-1 + TB_SP_WIDTH )
290 #if TB_TL_LEFT + TB_TL_WIDTH + TB_MENU_MIN_WIDTH >= LCD_WIDTH
293 #define TB_TL_TOP ( TB_PL_TOP + TB_PL_HEIGHT + 4 )
294 #define TB_TL_LEFT TB_SC_FG_LEFT
297 /* Menu button position */
298 #define TB_MENU_TOP ( TB_TL_TOP + (TB_TL_HEIGHT-8)/2 )
299 #define TB_MENU_LEFT ( TB_TL_LEFT + TB_TL_WIDTH-1 + TB_SP_WIDTH )
301 #define TB_HEIGHT ( TB_TL_TOP + TB_TL_HEIGHT + 1 )
304 static void draw_pixel(int x
,int y
);
305 static void draw_line( int x1
, int y1
, int x2
, int y2
);
306 static void draw_rect( int x1
, int y1
, int x2
, int y2
);
307 static void draw_toolbars(bool update
);
308 static void inv_cursor(bool update
);
309 static void restore_screen(void);
310 static void clear_drawing(void);
311 static void goto_menu(void);
312 static int load_bitmap( const char *filename
);
313 static int save_bitmap( char *filename
);
314 static void draw_rect_full( int x1
, int y1
, int x2
, int y2
);
316 /***********************************************************************
318 ***********************************************************************/
320 static int drawcolor
=0; /* Current color (in palette) */
321 static int bgdrawcolor
=9; /* Current background color (in palette) */
322 bool isbg
= false; /* gruik ugly hack alert */
324 static int preview
=false; /* Is preview mode on ? */
326 /* TODO: clean this up */
327 static int x
=0, y
=0; /* cursor position */
328 static int prev_x
=-1, prev_y
=-1; /* previous saved cursor position */
329 static int prev_x2
=-1, prev_y2
=-1;
330 static int prev_x3
=-1, prev_y3
=-1;
331 static int tool_mode
=-1;
334 static int bsize
=1; /* brush size */
335 static int bspeed
=1; /* brush speed */
337 enum Tools
{ Brush
= 0, /* Regular brush */
338 Fill
= 1, /* Fill a shape with current color */
340 ColorPicker
= 3, /* Pick a color */
341 Line
= 4, /* Draw a line between two points */
342 Unused
= 5, /* THIS IS UNUSED ... */
345 Rectangle
= 8, /* Draw a rectangle */
347 Oval
= 10, /* Draw an oval */
353 enum Tools tool
= Brush
;
355 static bool quit
=false;
356 static int gridsize
=0;
358 static fb_data rp_colors
[18] =
360 COLOR_BLACK
, COLOR_DARKGRAY
, COLOR_RED
, COLOR_DARKYELLOW
,
361 COLOR_GREEN
, COLOR_CYAN
, COLOR_BLUE
, COLOR_PURPLE
, COLOR_BROWN
,
362 COLOR_WHITE
, COLOR_LIGHTGRAY
, COLOR_LIGHTRED
, COLOR_YELLOW
,
363 COLOR_LIGHTGREN
, COLOR_LIGHTCYAN
, COLOR_LIGHTBLUE
, COLOR_PINK
,
367 static fb_data save_buffer
[ ROWS
*COLS
];
369 extern fb_data rockpaint
[];
370 extern fb_data rockpaint_hsvrgb
[];
372 /* Maximum string size allowed for the text tool */
377 /* Used by fill and gradient algorithms */
382 } coord
[ ROWS
*COLS
];
384 /* Used by bezier curve algorithms */
392 } bezier
[ (ROWS
*COLS
)/5 ]; /* We have 4.5 times more data per struct
393 * than coord ... so we divide to take
396 /* Used to cut/copy/paste data */
397 fb_data clipboard
[ ROWS
*COLS
];
399 /* Used for text mode */
402 char text
[MAX_TEXT
+1];
403 char font
[MAX_PATH
+1];
404 char old_font
[MAX_PATH
+1];
407 char fontname_buf
[30][MAX_PATH
];
411 /* Current filename */
412 static char filename
[MAX_PATH
+1];
414 /* Font preview buffer */
415 //#define FONT_PREVIEW_WIDTH ((LCD_WIDTH-30)/8)
416 //#define FONT_PREVIEW_HEIGHT 1000
417 //static unsigned char fontpreview[FONT_PREVIEW_WIDTH*FONT_PREVIEW_HEIGHT];
419 /***********************************************************************
420 * Offscreen buffer/Text/Fonts handling
422 * Parts of code taken from firmware/drivers/lcd-16bit.c
423 ***********************************************************************/
424 static void buffer_mono_bitmap_part(
425 fb_data
*buf
, int buf_width
, int buf_height
,
426 const unsigned char *src
, int src_x
, int src_y
,
427 int stride
, int x
, int y
, int width
, int height
)
428 /* this function only draws the foreground part of the bitmap */
430 const unsigned char *src_end
;
431 fb_data
*dst
, *dst_end
;
432 unsigned fgcolor
= rb
->lcd_get_foreground();
434 /* nothing to draw? */
435 if( ( width
<= 0 ) || ( height
<= 0 ) || ( x
>= buf_width
)
436 || ( y
>= buf_height
) || ( x
+ width
<= 0 ) || ( y
+ height
<= 0 ) )
452 if( x
+ width
> buf_width
)
453 width
= buf_width
- x
;
454 if( y
+ height
> buf_height
)
455 height
= buf_height
- y
;
457 src
+= stride
* (src_y
>> 3) + src_x
; /* move starting point */
459 src_end
= src
+ width
;
461 dst
= buf
+ y
*buf_width
+ x
;
465 const unsigned char *src_col
= src
++;
466 unsigned data
= *src_col
>> src_y
;
467 fb_data
*dst_col
= dst
++;
468 int numbits
= 8 - src_y
;
470 dst_end
= dst_col
+ height
* buf_width
;
474 *dst_col
= fgcolor
; /* FIXME ? */
476 dst_col
+= buf_width
;
485 } while( dst_col
< dst_end
);
486 } while( src
< src_end
);
489 static void buffer_putsxyofs( fb_data
*buf
, int buf_width
, int buf_height
,
490 int x
, int y
, int ofs
, const unsigned char *str
)
495 struct font
*pf
= rb
->font_get( FONT_UI
);
496 if( !pf
) pf
= rb
->font_get( FONT_SYSFIXED
);
498 ucs
= rb
->bidi_l2v( str
, 1 );
500 while( (ch
= *ucs
++) != 0 && x
< buf_width
)
503 const unsigned char *bits
;
505 /* get proportional width and glyph bits */
506 width
= rb
->font_get_width( pf
, ch
);
514 bits
= rb
->font_get_bits( pf
, ch
);
516 buffer_mono_bitmap_part( buf
, buf_width
, buf_height
, bits
, ofs
, 0,
517 width
, x
, y
, width
- ofs
, pf
->height
);
524 /***********************************************************************
526 ***********************************************************************/
530 MAIN_MENU_NEW
, MAIN_MENU_LOAD
, MAIN_MENU_SAVE
,
531 MAIN_MENU_BRUSH_SIZE
, MAIN_MENU_BRUSH_SPEED
, MAIN_MENU_COLOR
,
533 MAIN_MENU_PLAYBACK_CONTROL
,
537 /* Select action menu */
538 SELECT_MENU_CUT
, SELECT_MENU_COPY
,
539 SELECT_MENU_INVERT
, SELECT_MENU_HFLIP
, SELECT_MENU_VFLIP
,
540 SELECT_MENU_ROTATE90
, SELECT_MENU_ROTATE180
, SELECT_MENU_ROTATE270
,
545 TEXT_MENU_TEXT
, TEXT_MENU_FONT
,
546 TEXT_MENU_PREVIEW
, TEXT_MENU_APPLY
, TEXT_MENU_CANCEL
,
549 MENUITEM_STRINGLIST(main_menu
, "RockPaint", NULL
,
550 "Resume", "New", "Load", "Save",
551 "Brush Size", "Brush Speed",
552 "Choose Color", "Grid Size",
553 "Playback Control", "Exit");
554 MENUITEM_STRINGLIST(select_menu
, "Select...", NULL
,
556 "Invert", "Horizontal Flip", "Vertical Flip",
557 "Rotate 90°", "Rotate 180°", "Rotate 270°",
559 MENUITEM_STRINGLIST(text_menu
, "Text", NULL
,
560 "Set Text", "Change Font",
561 "Preview", "Apply", "Cancel");
562 static const int times_list
[] = { 1, 2, 4, 8 };
563 static const int gridsize_list
[] = { 0, 5, 10, 20 };
564 static const struct opt_items times_options
[] = {
565 { "1x", -1 }, { "2x", -1 }, { "4x", -1 }, { "8x", -1 }
567 static const struct opt_items gridsize_options
[] = {
568 { "No grid", -1 }, { "5px", -1 }, { "10px", -1 }, { "20px", -1 }
571 static int draw_window( int height
, int width
,
576 rb
->lcd_getstringsize( title
, NULL
, &fh
);
579 const int _top
= ( LCD_HEIGHT
- height
) / 2;
580 const int _left
= ( LCD_WIDTH
- width
) / 2;
581 if( top
) *top
= _top
;
582 if( left
) *left
= _left
;
583 rb
->lcd_set_background(COLOR_BLUE
);
584 rb
->lcd_set_foreground(COLOR_LIGHTGRAY
);
585 rb
->lcd_fillrect( _left
, _top
, width
, height
);
586 rb
->lcd_set_foreground(COLOR_BLUE
);
587 rb
->lcd_fillrect( _left
, _top
, width
, fh
+4 );
588 rb
->lcd_set_foreground(COLOR_WHITE
);
589 rb
->lcd_putsxy( _left
+2, _top
+2, title
);
590 rb
->lcd_set_foreground(COLOR_BLACK
);
591 rb
->lcd_drawrect( _left
, _top
, width
, height
);
595 /***********************************************************************
597 ***********************************************************************/
599 char bbuf
[MAX_PATH
+1]; /* used by file and font browsers */
600 char bbuf_s
[MAX_PATH
+1]; /* used by file and font browsers */
601 struct tree_context
*tree
= NULL
;
603 static char * browse_get_name_cb( int selected_item
, void *data
,
604 char *buffer
, size_t buffer_len
)
606 int *indexes
= (int *) data
;
607 struct entry
* dc
= tree
->dircache
;
608 struct entry
* e
= &dc
[indexes
[selected_item
]];
615 static bool browse( char *dst
, int dst_size
, const char *start
)
617 struct gui_synclist browse_list
;
618 int item_count
= 0, selected
, button
;
619 struct tree_context backup
;
622 int dirfilter
= SHOW_ALL
;
623 int *indexes
= (int *) buffer
.clipboard
;
627 rb
->strcpy( bbuf
, start
);
628 a
= bbuf
+rb
->strlen(bbuf
)-1;
636 rb
->gui_synclist_init( &browse_list
, browse_get_name_cb
,
637 (void*) indexes
, false, 1, NULL
);
639 tree
= rb
->tree_get_context();
642 a
= backup
.currdir
+rb
->strlen(backup
.currdir
)-1;
648 rb
->strcpy( a
, dc
[tree
->selected_item
].name
);
649 tree
->dirfilter
= &dirfilter
;
655 rb
->set_current_file(bbuf
);
658 for( i
= 0; i
< tree
->filesindir
; i
++)
660 /* only displayes directories and .bmp files */
661 if( ((dc
[i
].attr
& ATTR_DIRECTORY
) &&
662 rb
->strcmp( dc
[i
].name
, "." ) &&
663 rb
->strcmp( dc
[i
].name
, ".." )) ||
664 ( !(dc
[i
].attr
& ATTR_DIRECTORY
) &&
665 (a
= rb
->strrchr( dc
[i
].name
,'.' )) &&
666 !rb
->strcmp( a
, ".bmp" ) ))
668 if( !rb
->strcmp( dc
[i
].name
, bbuf_s
) )
669 selected
= item_count
;
670 indexes
[item_count
++] = i
;
674 rb
->gui_synclist_set_nb_items(&browse_list
,item_count
);
675 rb
->gui_synclist_select_item(&browse_list
, selected
);
676 rb
->gui_synclist_set_title(&browse_list
, bbuf
, NOICON
);
677 rb
->gui_synclist_draw(&browse_list
);
680 button
= rb
->get_action(CONTEXT_LIST
,TIMEOUT_BLOCK
);
681 if (rb
->gui_synclist_do_button(&browse_list
,&button
,LIST_WRAP_UNLESS_HELD
))
685 case ACTION_STD_CANCEL
:
686 if( !rb
->strcmp( bbuf
, "/" ) )
689 rb
->set_current_file( backup
.currdir
);
692 rb
->strcpy( bbuf_s
, ".." );
694 if( button
== ACTION_STD_OK
)
696 selected
= rb
->gui_synclist_get_sel_pos( &browse_list
);
697 if( selected
< 0 || selected
>= item_count
)
699 struct entry
* e
= &dc
[indexes
[selected
]];
700 rb
->strlcpy( bbuf_s
, e
->name
, sizeof( bbuf_s
) );
701 if( !( e
->attr
& ATTR_DIRECTORY
) )
704 rb
->set_current_file( backup
.currdir
);
705 rb
->snprintf( dst
, dst_size
, "%s%s", bbuf
, bbuf_s
);
709 if( !rb
->strcmp( bbuf_s
, "." ) ) break;
710 a
= bbuf
+rb
->strlen(bbuf
);
711 if( !rb
->strcmp( bbuf_s
, ".." ) )
714 if( a
== bbuf
) break;
716 while( *a
!= '/' ) a
--;
717 rb
->strcpy( bbuf_s
, ++a
);
718 /* select parent directory */
719 bbuf_s
[rb
->strlen(bbuf_s
)-1] = '\0';
724 rb
->snprintf( a
, bbuf
+sizeof(bbuf
)-a
, "%s/", bbuf_s
);
728 case ACTION_STD_MENU
:
730 rb
->set_current_file( backup
.currdir
);
736 /***********************************************************************
739 * FIXME: This still needs some work ... it currently only works fine
740 * on the simulators, disk spins too much on real targets -> rendered
741 * font buffer needed.
742 ***********************************************************************/
743 static bool browse_fonts( char *dst
, int dst_size
)
745 #define WIDTH ( LCD_WIDTH - 20 )
746 #define HEIGHT ( LCD_HEIGHT - 20 )
748 int top
, top_inside
= 0, left
;
752 int fvi
= 0; /* first visible item */
753 int lvi
= 0; /* last visible item */
754 int si
= 0; /* selected item */
755 int osi
= 0; /* old selected item */
756 int li
= 0; /* last item */
757 int nvih
= 0; /* next visible item height */
759 int b_need_redraw
= 1; /* Do we need to redraw ? */
761 int cp
= 0; /* current position */
762 int fh
; /* font height */
764 #define fh_buf buffer.text.fh_buf /* 30 might not be enough ... */
765 #define fw_buf buffer.text.fw_buf
767 #define fontname_buf buffer.text.fontname_buf
769 rb
->snprintf( buffer
.text
.old_font
, MAX_PATH
,
771 rb
->global_settings
->font_file
);
777 /* we don't need to redraw ... but we need to unselect
778 * the previously selected item */
779 cp
= top_inside
+ LINE_SPACE
;
780 for( i
= 0; i
+fvi
< osi
; i
++ )
782 cp
+= fh_buf
[i
] + LINE_SPACE
;
784 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
785 rb
->lcd_fillrect( left
+10, cp
, fw_buf
[i
], fh_buf
[i
] );
786 rb
->lcd_set_drawmode(DRMODE_SOLID
);
793 d
= rb
->opendir( FONT_DIR
"/" );
798 top_inside
= draw_window( HEIGHT
, WIDTH
, &top
, &left
, "Fonts" );
806 cp
= top_inside
+LINE_SPACE
;
808 rb
->lcd_set_foreground(COLOR_BLACK
);
809 rb
->lcd_set_background(COLOR_LIGHTGRAY
);
811 while( cp
< top
+HEIGHT
)
813 de
= rb
->readdir( d
);
819 if( rb
->strlen( de
->d_name
) < 4
820 || rb
->strcmp( de
->d_name
+ rb
->strlen( de
->d_name
) - 4,
823 rb
->snprintf( bbuf
, MAX_PATH
, FONT_DIR
"/%s",
825 rb
->font_load( bbuf
);
826 rb
->font_getstringsize( de
->d_name
, &fw
, &fh
, FONT_UI
);
831 if( nvih
< 0 ) nvih
= 0;
835 if( cp
+ fh
>= top
+HEIGHT
)
840 rb
->lcd_putsxy( left
+10, cp
, de
->d_name
);
843 cp
+= fh
+ LINE_SPACE
;
844 rb
->strcpy( fontname_buf
[i
-fvi
], bbuf
);
850 if( !(de
= rb
->readdir( d
) ) )
854 else if( !nvih
&& !rb
->strlen( de
->d_name
) < 4
855 && !rb
->strcmp( de
->d_name
+ rb
->strlen( de
->d_name
) - 4,
858 rb
->snprintf( bbuf
, MAX_PATH
, FONT_DIR
"/%s",
860 rb
->font_load( bbuf
);
861 rb
->font_getstringsize( de
->d_name
, NULL
, &fh
, FONT_UI
);
865 rb
->font_load( buffer
.text
.old_font
);
869 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
870 cp
= top_inside
+ LINE_SPACE
;
871 for( i
= 0; i
+fvi
< si
; i
++ )
873 cp
+= fh_buf
[i
] + LINE_SPACE
;
875 rb
->lcd_fillrect( left
+10, cp
, fw_buf
[i
], fh_buf
[i
] );
876 rb
->lcd_set_drawmode(DRMODE_SOLID
);
878 rb
->lcd_update_rect( left
, top
, WIDTH
, HEIGHT
);
882 switch( rb
->button_get(true) )
885 case ROCKPAINT_UP
|BUTTON_REPEAT
:
897 case ROCKPAINT_DOWN
|BUTTON_REPEAT
:
898 if( li
== -1 || si
< li
)
907 case ROCKPAINT_RIGHT
:
909 rb
->snprintf( dst
, dst_size
, "%s", fontname_buf
[si
-fvi
] );
913 if( i
!= fvi
|| si
> lvi
)
931 /***********************************************************************
932 * HSVRGB Color chooser
933 ***********************************************************************/
934 static unsigned int color_chooser( unsigned int color
)
936 int red
= RGB_UNPACK_RED( color
);
937 int green
= RGB_UNPACK_GREEN( color
);
938 int blue
= RGB_UNPACK_BLUE( color
);
939 int hue
, saturation
, value
;
940 int r
, g
, b
; /* temp variables */
943 enum BaseColor
{ Hue
= 0, Saturation
= 1, Value
= 2,
944 Red
= 3, Green
= 4, Blue
= 5 };
945 enum BaseColor current
= Red
;
952 rgb2hsv( red
, green
, blue
, &hue
, &saturation
, &value
);
957 color
= LCD_RGBPACK( red
, green
, blue
);
959 #define HEIGHT ( 100 )
960 #define WIDTH ( 150 )
962 top
= draw_window( HEIGHT
, WIDTH
, NULL
, &left
, "Color chooser" );
965 for( i
=0; i
<100; i
++ )
967 hsv2rgb( i
*36, saturation
, value
, &r
, &g
, &b
);
968 rb
->lcd_set_foreground( LCD_RGBPACK( r
, g
, b
) );
969 rb
->lcd_vline( left
+15+i
, top
+20, top
+27 );
970 hsv2rgb( hue
, i
*255/100, value
, &r
, &g
, &b
);
971 rb
->lcd_set_foreground( LCD_RGBPACK( r
, g
, b
) );
972 rb
->lcd_vline( left
+15+i
, top
+30, top
+37 );
973 hsv2rgb( hue
, saturation
, i
*255/100, &r
, &g
, &b
);
974 rb
->lcd_set_foreground( LCD_RGBPACK( r
, g
, b
) );
975 rb
->lcd_vline( left
+15+i
, top
+40, top
+47 );
976 rb
->lcd_set_foreground( LCD_RGBPACK( i
*255/100, green
, blue
) );
977 rb
->lcd_vline( left
+15+i
, top
+50, top
+57 );
978 rb
->lcd_set_foreground( LCD_RGBPACK( red
, i
*255/100, blue
) );
979 rb
->lcd_vline( left
+15+i
, top
+60, top
+67 );
980 rb
->lcd_set_foreground( LCD_RGBPACK( red
, green
, i
*255/100 ) );
981 rb
->lcd_vline( left
+15+i
, top
+70, top
+77 );
984 rb
->lcd_set_foreground(COLOR_BLACK
);
985 #define POSITION( a, i ) \
986 rb->lcd_drawpixel( left+14+i, top + 19 + a ); \
987 rb->lcd_drawpixel( left+16+i, top + 19 + a ); \
988 rb->lcd_drawpixel( left+14+i, top + 28 + a ); \
989 rb->lcd_drawpixel( left+16+i, top + 28 + a );
990 POSITION( 0, hue
/36 );
991 POSITION( 10, saturation
*99/255 );
992 POSITION( 20, value
*99/255 );
993 POSITION( 30, red
*99/255 );
994 POSITION( 40, green
*99/255 );
995 POSITION( 50, blue
*99/255 );
997 rb
->lcd_set_background(COLOR_LIGHTGRAY
);
998 rb
->lcd_setfont( FONT_SYSFIXED
);
999 rb
->snprintf( str
, 6, "%d", hue
/10 );
1000 rb
->lcd_putsxy( left
+ 117, top
+ 20, str
);
1001 rb
->snprintf( str
, 6, "%d.%d", saturation
/255, ((saturation
*100)/255)%100 );
1002 rb
->lcd_putsxy( left
+ 117, top
+ 30, str
);
1003 rb
->snprintf( str
, 6, "%d.%d", value
/255, ((value
*100)/255)%100 );
1004 rb
->lcd_putsxy( left
+ 117, top
+ 40, str
);
1005 rb
->snprintf( str
, 6, "%d", red
);
1006 rb
->lcd_putsxy( left
+ 117, top
+ 50, str
);
1007 rb
->snprintf( str
, 6, "%d", green
);
1008 rb
->lcd_putsxy( left
+ 117, top
+ 60, str
);
1009 rb
->snprintf( str
, 6, "%d", blue
);
1010 rb
->lcd_putsxy( left
+ 117, top
+ 70, str
);
1011 rb
->lcd_setfont( FONT_UI
);
1013 #define CURSOR( l ) \
1014 rb->lcd_bitmap_transparent_part( rockpaint_hsvrgb, 1, 1, 16, left+l+1, top+20, 6, 58 ); \
1015 rb->lcd_bitmap_transparent_part( rockpaint_hsvrgb, 8, 10*current, 16, left+l, top+19+10*current, 8, 10 );
1019 rb
->lcd_set_foreground( color
);
1020 rb
->lcd_fillrect( left
+15, top
+85, 100, 8 );
1024 switch( rb
->button_get(true) )
1027 current
= ( current
+ 5 )%6;
1030 case ROCKPAINT_DOWN
:
1031 current
= (current
+ 1 )%6;
1034 case ROCKPAINT_LEFT
:
1039 hue
= ( hue
+ 3600 - 10 )%3600;
1042 if( saturation
) saturation
--;
1045 if( value
) value
--;
1051 if( green
) green
--;
1059 case ROCKPAINT_LEFT
|BUTTON_REPEAT
:
1064 hue
= ( hue
+ 3600 - 100 )%3600;
1067 if( saturation
>= 8 ) saturation
-=8;
1068 else saturation
= 0;
1071 if( value
>= 8 ) value
-=8;
1075 if( red
>= 8 ) red
-=8;
1079 if( green
>= 8 ) green
-=8;
1083 if( blue
>= 8 ) blue
-=8;
1089 case ROCKPAINT_RIGHT
:
1094 hue
= ( hue
+ 10 )%3600;
1097 if( saturation
< 0xff ) saturation
++;
1100 if( value
< 0xff ) value
++;
1103 if( red
< 0xff ) red
++;
1106 if( green
< 0xff ) green
++;
1109 if( blue
< 0xff ) blue
++;
1114 case ROCKPAINT_RIGHT
|BUTTON_REPEAT
:
1119 hue
= ( hue
+ 100 )%3600;
1122 if( saturation
< 0xff - 8 ) saturation
+=8;
1123 else saturation
= 0xff;
1126 if( value
< 0xff - 8 ) value
+=8;
1130 if( red
< 0xff - 8 ) red
+=8;
1134 if( green
< 0xff - 8 ) green
+=8;
1138 if( blue
< 0xff - 8 ) blue
+=8;
1144 case ROCKPAINT_DRAW
:
1154 hsv2rgb( hue
, saturation
, value
, &red
, &green
, &blue
);
1160 rgb2hsv( red
, green
, blue
, &hue
, &saturation
, &value
);
1169 /***********************************************************************
1171 ***********************************************************************/
1172 static void init_buffer(void)
1175 fb_data color
= rp_colors
[ bgdrawcolor
];
1176 for( i
= 0; i
< ROWS
*COLS
; i
++ )
1178 save_buffer
[i
] = color
;
1182 static void draw_pixel(int x
,int y
)
1186 if( x
< 0 || x
>= COLS
|| y
< 0 || y
>= ROWS
) return;
1189 save_buffer
[ x
+y
*COLS
] = rp_colors
[bgdrawcolor
];
1193 save_buffer
[ x
+y
*COLS
] = rp_colors
[drawcolor
];
1196 rb
->lcd_drawpixel(x
,y
);
1199 static void color_picker( int x
, int y
)
1203 rb
->lcd_set_foreground( save_buffer
[ x
+y
*COLS
] );
1205 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1206 rb
->lcd_drawrect( x
<COLS
-PSIZE
? x
+ 2 : x
- PSIZE
, y
<ROWS
-PSIZE
? y
+ 2: y
- PSIZE
, PSIZE
- 2, PSIZE
- 2 );
1207 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1208 rb
->lcd_fillrect( x
<COLS
-PSIZE
? x
+3 : x
- PSIZE
+1, y
<ROWS
-PSIZE
? y
+3: y
- PSIZE
+1, PSIZE
-4, PSIZE
-4 );
1210 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
1214 rp_colors
[ drawcolor
] = save_buffer
[ x
+y
*COLS
];
1218 static void draw_select_rectangle( int x1
, int y1
, int x2
, int y2
)
1219 /* This is a preview mode only function */
1234 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1236 for( a
= x1
; a
< x2
; a
++, i
++ )
1238 rb
->lcd_drawpixel( a
, y1
);
1239 for( a
= y1
; a
< y2
; a
++, i
++ )
1241 rb
->lcd_drawpixel( x2
, a
);
1243 for( a
= x2
; a
> x1
; a
--, i
++ )
1245 rb
->lcd_drawpixel( a
, y2
);
1247 for( a
= y2
; a
> y1
; a
--, i
++ )
1249 rb
->lcd_drawpixel( x1
, a
);
1250 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1253 static void copy_to_clipboard( void )
1255 /* This needs to be optimised ... but i'm lazy ATM */
1256 rb
->memcpy( buffer
.clipboard
, save_buffer
, COLS
*ROWS
*sizeof( fb_data
) );
1259 /* no preview mode handling atm ... do we need it ? (one if) */
1260 static void draw_invert( int x1
, int y1
, int x2
, int y2
)
1276 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1277 rb
->lcd_fillrect( x1
, y1
, x2
-x1
+1, y2
-y1
+1 );
1278 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1280 for( ; y1
<=y2
; y1
++ )
1282 for( i
= x1
; i
<=x2
; i
++ )
1284 save_buffer
[ y1
*COLS
+ i
] = ~save_buffer
[ y1
*COLS
+ i
];
1287 /*if( update )*/ rb
->lcd_update();
1290 static void draw_hflip( int x1
, int y1
, int x2
, int y2
)
1306 copy_to_clipboard();
1308 for( i
= 0; i
<= y2
- y1
; i
++ )
1310 rb
->memcpy( save_buffer
+(y1
+i
)*COLS
+x1
,
1311 buffer
.clipboard
+(y2
-i
)*COLS
+x1
,
1312 (x2
-x1
+1)*sizeof( fb_data
) );
1318 static void draw_vflip( int x1
, int y1
, int x2
, int y2
)
1334 copy_to_clipboard();
1336 for( ; y1
<= y2
; y1
++ )
1338 for( i
= 0; i
<= x2
- x1
; i
++ )
1340 save_buffer
[y1
*COLS
+x1
+i
] = buffer
.clipboard
[y1
*COLS
+x2
-i
];
1347 /* direction: -1 = left, 1 = right */
1348 static void draw_rot_90_deg( int x1
, int y1
, int x2
, int y2
, int direction
)
1364 copy_to_clipboard();
1366 fb_data color
= rp_colors
[ bgdrawcolor
];
1367 const int width
= x2
- x1
, height
= y2
- y1
;
1368 const int sub_half
= width
/2-height
/2, add_half
= (width
+height
)/2;
1369 if( width
> height
)
1371 for( i
= 0; i
<= height
; i
++ )
1373 for( j
= 0; j
< sub_half
; j
++ )
1374 save_buffer
[(y1
+i
)*COLS
+x1
+j
] = color
;
1375 for( j
= add_half
+1; j
<= width
; j
++ )
1376 save_buffer
[(y1
+i
)*COLS
+x1
+j
] = color
;
1379 else if( width
< height
)
1381 for( j
= 0; j
<= width
; j
++ )
1383 for( i
= 0; i
< -sub_half
; i
++ )
1384 save_buffer
[(y1
+i
)*COLS
+x1
+j
] = color
;
1385 for( i
= add_half
+1; i
<= height
; i
++ )
1386 save_buffer
[(y1
+i
)*COLS
+x1
+j
] = color
;
1389 int x3
= x1
+ sub_half
, y3
= y1
- sub_half
;
1390 int is
= x3
<0?-x3
:0, ie
= COLS
-x3
-1, js
= y3
<0?-y3
:0, je
= ROWS
-y3
-1;
1391 if( ie
> height
) ie
= height
;
1392 if( je
> width
) je
= width
;
1393 for( i
= is
; i
<= ie
; i
++ )
1395 for( j
= js
; j
<= je
; j
++ )
1408 save_buffer
[(y3
+j
)*COLS
+x3
+i
] = buffer
.clipboard
[y
*COLS
+x
];
1415 static void draw_paste_rectangle( int src_x1
, int src_y1
, int src_x2
,
1416 int src_y2
, int x1
, int y1
, int mode
)
1419 if( mode
== SELECT_MENU_CUT
)
1422 drawcolor
= bgdrawcolor
;
1423 draw_rect_full( src_x1
, src_y1
, src_x2
, src_y2
);
1426 if( src_x1
> src_x2
)
1432 if( src_y1
> src_y2
)
1438 rb
->lcd_bitmap_part( buffer
.clipboard
, src_x1
, src_y1
, COLS
,
1439 x1
, y1
, src_x2
-src_x1
+1, src_y2
-src_y1
+1 );
1442 for( i
= 0; i
<= src_y2
- src_y1
; i
++ )
1444 rb
->memcpy( save_buffer
+(y1
+i
)*COLS
+x1
,
1445 buffer
.clipboard
+(src_y1
+i
)*COLS
+src_x1
,
1446 (src_x2
- src_x1
+ 1)*sizeof( fb_data
) );
1451 static void show_grid( bool update
)
1456 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1457 for( i
= gridsize
; i
< COLS
; i
+= gridsize
)
1459 rb
->lcd_vline( i
, 0, ROWS
-1 );
1461 for( i
= gridsize
; i
< ROWS
; i
+= gridsize
)
1463 rb
->lcd_hline( 0, COLS
-1, i
);
1465 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1466 if( update
) rb
->lcd_update();
1470 static void draw_text( int x
, int y
)
1473 buffer
.text
.text
[0] = '\0';
1474 rb
->snprintf( buffer
.text
.old_font
, MAX_PATH
,
1476 rb
->global_settings
->font_file
);
1479 switch( rb
->do_menu( &text_menu
, &selected
, NULL
, NULL
) )
1481 case TEXT_MENU_TEXT
:
1482 rb
->lcd_set_foreground(COLOR_BLACK
);
1483 rb
->kbd_input( buffer
.text
.text
, MAX_TEXT
);
1486 case TEXT_MENU_FONT
:
1487 if( browse_fonts( buffer
.text
.font
, MAX_PATH
) )
1489 rb
->font_load( buffer
.text
.font
);
1493 case TEXT_MENU_PREVIEW
:
1494 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
1499 rb
->lcd_putsxy( x
, y
, buffer
.text
.text
);
1501 switch( button
= rb
->button_get( true ) )
1503 case ROCKPAINT_LEFT
:
1504 case ROCKPAINT_LEFT
| BUTTON_REPEAT
:
1505 x
-=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
1509 case ROCKPAINT_RIGHT
:
1510 case ROCKPAINT_RIGHT
| BUTTON_REPEAT
:
1511 x
+=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
1516 case ROCKPAINT_UP
| BUTTON_REPEAT
:
1517 y
-=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
1521 case ROCKPAINT_DOWN
:
1522 case ROCKPAINT_DOWN
| BUTTON_REPEAT
:
1523 y
+=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
1527 case ROCKPAINT_DRAW
:
1530 if(rb
->default_event_handler(button
)
1531 == SYS_USB_CONNECTED
)
1532 button
= ROCKPAINT_DRAW
;
1535 if( button
== ROCKPAINT_DRAW
) break;
1539 case TEXT_MENU_APPLY
:
1540 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
1541 buffer_putsxyofs( save_buffer
, COLS
, ROWS
, x
, y
, 0,
1543 case TEXT_MENU_CANCEL
:
1546 rb
->font_load( buffer
.text
.old_font
);
1552 static void draw_brush( int x
, int y
)
1555 for( i
=-bsize
/2+(bsize
+1)%2; i
<=bsize
/2; i
++ )
1557 for( j
=-bsize
/2+(bsize
+1)%2; j
<=bsize
/2; j
++ )
1559 draw_pixel( x
+i
, y
+j
);
1564 /* This is an implementation of Bresenham's line algorithm.
1565 * See http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm.
1567 static void draw_line( int x1
, int y1
, int x2
, int y2
)
1571 int deltax
= x2
- x1
;
1572 int deltay
= y2
- y1
;
1575 int xerr
= abs(deltax
);
1576 int yerr
= abs(deltay
);
1577 int xstep
= deltax
> 0 ? 1 : -1;
1578 int ystep
= deltay
> 0 ? 1 : -1;
1588 /* to leave off the last pixel of the line, leave off the "+ 1" */
1589 for (i
= abs(deltay
) + 1; i
; --i
)
1602 /* more horizontal */
1607 for (i
= abs(deltax
) + 1; i
; --i
)
1620 static void draw_curve( int x1
, int y1
, int x2
, int y2
,
1621 int xa
, int ya
, int xb
, int yb
)
1635 if( x1
== x2
&& y1
== y2
)
1637 draw_pixel( x1
, y1
);
1643 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1644 if( xa
== -1 || ya
== -1 )
1646 rb
->lcd_drawline( x1
, y1
, xb
, yb
);
1647 rb
->lcd_drawline( x2
, y2
, xb
, yb
);
1651 rb
->lcd_drawline( x1
, y1
, xa
, ya
);
1652 rb
->lcd_drawline( x2
, y2
, xb
, yb
);
1654 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1657 if( xa
== -1 || ya
== -1 )
1658 /* We only have 3 of the points
1659 * This will currently only be used in preview mode */
1661 #define PUSH( a1, b1, a2, b2, a3, b3, d ) \
1662 buffer.bezier[i].x1 = a1; \
1663 buffer.bezier[i].y1 = b1; \
1664 buffer.bezier[i].x2 = a2; \
1665 buffer.bezier[i].y2 = b2; \
1666 buffer.bezier[i].x3 = a3; \
1667 buffer.bezier[i].y3 = b3; \
1668 buffer.bezier[i].depth = d; \
1670 #define POP( a1, b1, a2, b2, a3, b3, d ) \
1672 a1 = buffer.bezier[i].x1; \
1673 b1 = buffer.bezier[i].y1; \
1674 a2 = buffer.bezier[i].x2; \
1675 b2 = buffer.bezier[i].y2; \
1676 a3 = buffer.bezier[i].x3; \
1677 b3 = buffer.bezier[i].y3; \
1678 d = buffer.bezier[i].depth;
1679 PUSH( x1
<<4, y1
<<4, xb
<<4, yb
<<4, x2
<<4, y2
<<4, 0 );
1682 /* de Casteljau's algorithm (see wikipedia) */
1683 POP( xl1
, yl1
, xb
, yb
, xr3
, yr3
, depth
);
1684 if( depth
< 10 ) /* check that the stack's 'i' doesn't overflow */
1686 xl2
= ( xl1
+ xb
)>>1;
1687 yl2
= ( yl1
+ yb
)>>1;
1688 xr2
= ( xb
+ xr3
)>>1;
1689 yr2
= ( yb
+ yr3
)>>1;
1690 xr1
= ( xl2
+ xr2
)>>1;
1691 yr1
= ( yl2
+ yr2
)>>1;
1694 PUSH( xl1
, yl1
, xl2
, yl2
, xl3
, yl3
, depth
+1 );
1695 PUSH( xr1
, yr1
, xr2
, yr2
, xr3
, yr3
, depth
+1 );
1699 draw_line( ((xl1
>>3)+1)>>1, ((yl1
>>3)+1)>>1,
1700 ((xr3
>>3)+1)>>1, ((yr3
>>3)+1)>>1 );
1706 else /* We have the 4 points */
1708 #define PUSH( a1, b1, a2, b2, a3, b3, a4, b4, 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].x4 = a4; \
1716 buffer.bezier[i].y4 = b4; \
1717 buffer.bezier[i].depth = d; \
1719 #define POP( a1, b1, a2, b2, a3, b3, a4, b4, d ) \
1721 a1 = buffer.bezier[i].x1; \
1722 b1 = buffer.bezier[i].y1; \
1723 a2 = buffer.bezier[i].x2; \
1724 b2 = buffer.bezier[i].y2; \
1725 a3 = buffer.bezier[i].x3; \
1726 b3 = buffer.bezier[i].y3; \
1727 a4 = buffer.bezier[i].x4; \
1728 b4 = buffer.bezier[i].y4; \
1729 d = buffer.bezier[i].depth;
1731 PUSH( x1
<<4, y1
<<4, xa
<<4, ya
<<4, xb
<<4, yb
<<4, x2
<<4, y2
<<4, 0 );
1734 /* de Casteljau's algorithm (see wikipedia) */
1735 POP( xl1
, yl1
, xa
, ya
, xb
, yb
, xr4
, yr4
, depth
);
1736 if( depth
< 10 ) /* check that the stack's 'i' doesn't overflow */
1738 xl2
= ( xl1
+ xa
)>>1;
1739 yl2
= ( yl1
+ ya
)>>1;
1740 xh
= ( xa
+ xb
)>>1;
1741 yh
= ( ya
+ yb
)>>1;
1742 xr3
= ( xb
+ xr4
)>>1;
1743 yr3
= ( yb
+ yr4
)>>1;
1744 xl3
= ( xl2
+ xh
)>>1;
1745 yl3
= ( yl2
+ yh
)>>1;
1746 xr2
= ( xr3
+ xh
)>>1;
1747 yr2
= ( yr3
+ yh
)>>1;
1748 xl4
= ( xl3
+ xr2
)>>1;
1749 yl4
= ( yl3
+ yr2
)>>1;
1752 PUSH( xl1
, yl1
, xl2
, yl2
, xl3
, yl3
, xl4
, yl4
, depth
+1 );
1753 PUSH( xr1
, yr1
, xr2
, yr2
, xr3
, yr3
, xr4
, yr4
, depth
+1 );
1757 draw_line( ((xl1
>>3)+1)>>1, ((yl1
>>3)+1)>>1,
1758 ((xr4
>>3)+1)>>1, ((yr4
>>3)+1)>>1 );
1766 static void draw_rect( int x1
, int y1
, int x2
, int y2
)
1768 draw_line( x1
, y1
, x1
, y2
);
1769 draw_line( x1
, y1
, x2
, y1
);
1770 draw_line( x1
, y2
, x2
, y2
);
1771 draw_line( x2
, y1
, x2
, y2
);
1774 static void togglebg( void )
1778 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
1782 rb
->lcd_set_foreground( rp_colors
[ bgdrawcolor
] );
1787 static void draw_rect_full( int x1
, int y1
, int x2
, int y2
)
1795 draw_line( x
, y1
, x
, y2
);
1796 } while( ++x
<= x2
);
1801 draw_line( x
, y1
, x
, y2
);
1802 } while( --x
>= x2
);
1805 draw_rect( x1
, y1
, x2
, y2
);
1808 static void draw_oval( int x1
, int y1
, int x2
, int y2
, bool full
)
1810 /* TODO: simplify :) */
1811 int cx
= (x1
+x2
)>>1;
1812 int cy
= (y1
+y2
)>>1;
1814 int rx
= (x1
-x2
)>>1;
1815 int ry
= (y1
-y2
)>>1;
1816 if( rx
< 0 ) rx
*= -1;
1817 if( ry
< 0 ) ry
*= -1;
1819 if( rx
== 0 || ry
== 0 )
1821 draw_line( x1
, y1
, x2
, y2
);
1828 for( x
= 0; x
< rx
; x
++ )
1834 dst
= ry
* ry
* x
* x
+ rx
* rx
* y
* y
- rx
* rx
* ry
* ry
;
1837 if( -old_dst
< dst
) y
--;
1840 draw_line( cx
+x
, cy
, cx
+x
, cy
+y
);
1841 draw_line( cx
+x
, cy
, cx
+x
, cy
-y
);
1842 draw_line( cx
-x
, cy
, cx
-x
, cy
+y
);
1843 draw_line( cx
-x
, cy
, cx
-x
, cy
-y
);
1847 draw_pixel( cx
+x
, cy
+y
);
1848 draw_pixel( cx
+x
, cy
-y
);
1849 draw_pixel( cx
-x
, cy
+y
);
1850 draw_pixel( cx
-x
, cy
-y
);
1853 for( y
= 0; y
< ry
; y
++ )
1859 dst
= ry
* ry
* x
* x
+ rx
* rx
* y
* y
- rx
* rx
* ry
* ry
;
1862 if( -old_dst
< dst
) x
--;
1865 draw_line( cx
+x
, cy
, cx
+x
, cy
+y
);
1866 draw_line( cx
+x
, cy
, cx
+x
, cy
-y
);
1867 draw_line( cx
-x
, cy
, cx
-x
, cy
+y
);
1868 draw_line( cx
-x
, cy
, cx
-x
, cy
-y
);
1872 draw_pixel( cx
+x
, cy
+y
);
1873 draw_pixel( cx
+x
, cy
-y
);
1874 draw_pixel( cx
-x
, cy
+y
);
1875 draw_pixel( cx
-x
, cy
-y
);
1880 static void draw_oval_empty( int x1
, int y1
, int x2
, int y2
)
1882 draw_oval( x1
, y1
, x2
, y2
, false );
1885 static void draw_oval_full( int x1
, int y1
, int x2
, int y2
)
1888 draw_oval( x1
, y1
, x2
, y2
, true );
1890 draw_oval( x1
, y1
, x2
, y2
, false );
1893 static void draw_fill( int x0
, int y0
)
1895 #define PUSH( a, b ) \
1896 draw_pixel( (int)a, (int)b ); \
1897 buffer.coord[i].x = a; \
1898 buffer.coord[i].y = b; \
1900 #define POP( a, b ) \
1902 a = buffer.coord[i].x; \
1903 b = buffer.coord[i].y;
1908 unsigned int prev_color
= save_buffer
[ x0
+y0
*COLS
];
1910 if( prev_color
== rp_colors
[ drawcolor
] ) return;
1917 if( x
> 0 && save_buffer
[x
-1+y
*COLS
] == prev_color
)
1921 if( x
< COLS
-1 && save_buffer
[x
+1+y
*COLS
] == prev_color
)
1925 if( y
> 0 && save_buffer
[x
+(y
-1)*COLS
] == prev_color
)
1929 if( y
< ROWS
- 1 && save_buffer
[x
+(y
+1)*COLS
] == prev_color
)
1939 /* For preview purposes only */
1940 static void line_gradient( int x1
, int y1
, int x2
, int y2
)
1944 int h1
, s1
, v1
, h2
, s2
, v2
, r
, g
, b
;
1957 if( w
== 0 && h
== 0 )
1959 draw_pixel( x1
>>1, y1
>>1 );
1963 r1
= RGB_UNPACK_RED( rp_colors
[ bgdrawcolor
] );
1964 g1
= RGB_UNPACK_GREEN( rp_colors
[ bgdrawcolor
] );
1965 b1
= RGB_UNPACK_BLUE( rp_colors
[ bgdrawcolor
] );
1966 r2
= RGB_UNPACK_RED( rp_colors
[ drawcolor
] );
1967 g2
= RGB_UNPACK_GREEN( rp_colors
[ drawcolor
] );
1968 b2
= RGB_UNPACK_BLUE( rp_colors
[ drawcolor
] );
1993 rgb2hsv( r1
, g1
, b1
, &h1
, &s1
, &v1
);
1994 rgb2hsv( r2
, g2
, b2
, &h2
, &s2
, &v2
);
2011 hsv2rgb( h1
+((h2
-h1
)*(x1
-x2
))/w
,
2012 s1
+((s2
-s1
)*(x1
-x2
))/w
,
2013 v1
+((v2
-v1
)*(x1
-x2
))/w
,
2015 rp_colors
[ drawcolor
] = LCD_RGBPACK( r
, g
, b
);
2016 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
2017 draw_pixel( (x1
+1)>>1, (y1
+1)>>1 );
2019 y1
= y2
- ( x2
- x1
) * h
/ w
;
2037 hsv2rgb( h1
+((h2
-h1
)*(y1
-y2
))/h
,
2038 s1
+((s2
-s1
)*(y1
-y2
))/h
,
2039 v1
+((v2
-v1
)*(y1
-y2
))/h
,
2041 rp_colors
[ drawcolor
] = LCD_RGBPACK( r
, g
, b
);
2042 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
2043 draw_pixel( (x1
+1)>>1, (y1
+1)>>1 );
2045 x1
= x2
- ( y2
- y1
) * w
/ h
;
2050 rp_colors
[ drawcolor
] = LCD_RGBPACK( r1
, g1
, b1
);
2054 rp_colors
[ drawcolor
] = LCD_RGBPACK( r2
, g2
, b2
);
2058 static void linear_gradient( int x1
, int y1
, int x2
, int y2
)
2060 int r1
= RGB_UNPACK_RED( rp_colors
[ bgdrawcolor
] );
2061 int g1
= RGB_UNPACK_GREEN( rp_colors
[ bgdrawcolor
] );
2062 int b1
= RGB_UNPACK_BLUE( rp_colors
[ bgdrawcolor
] );
2063 int r2
= RGB_UNPACK_RED( rp_colors
[ drawcolor
] );
2064 int g2
= RGB_UNPACK_GREEN( rp_colors
[ drawcolor
] );
2065 int b2
= RGB_UNPACK_BLUE( rp_colors
[ drawcolor
] );
2067 int h1
, s1
, v1
, h2
, s2
, v2
, r
, g
, b
;
2070 int radius2
= ( x1
- x2
) * ( x1
- x2
) + ( y1
- y2
) * ( y1
- y2
);
2073 /* We only propagate the gradient to neighboring pixels with the same
2074 * color as ( x1, y1 ) */
2075 unsigned int prev_color
= save_buffer
[ x1
+y1
*COLS
];
2080 if( radius2
== 0 ) return;
2083 line_gradient( x1
, y1
, x2
, y2
);
2086 rgb2hsv( r1
, g1
, b1
, &h1
, &s1
, &v1
);
2087 rgb2hsv( r2
, g2
, b2
, &h2
, &s2
, &v2
);
2089 #define PUSH( x0, y0 ) \
2090 buffer.coord[i].x = (short)(x0); \
2091 buffer.coord[i].y = (short)(y0); \
2093 #define POP( a, b ) \
2095 a = (int)buffer.coord[i].x; \
2096 b = (int)buffer.coord[i].y;
2104 dist2
= ( x2
- x1
) * ( x
- x1
) + ( y2
- y1
) * ( y
- y1
);
2107 rp_colors
[ drawcolor
] = rp_colors
[ bgdrawcolor
];
2109 else if( dist2
< radius2
)
2111 hsv2rgb( h1
+((h2
-h1
)*dist2
)/radius2
,
2112 s1
+((s2
-s1
)*dist2
)/radius2
,
2113 v1
+((v2
-v1
)*dist2
)/radius2
,
2115 rp_colors
[ drawcolor
] = LCD_RGBPACK( r
, g
, b
);
2119 rp_colors
[ drawcolor
] = LCD_RGBPACK( r2
, g2
, b2
);
2121 if( rp_colors
[ drawcolor
] == prev_color
)
2123 if( rp_colors
[ drawcolor
])
2124 rp_colors
[ drawcolor
]--; /* GRUIK */
2126 rp_colors
[ drawcolor
]++; /* GRUIK */
2128 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
2131 if( x
> 0 && save_buffer
[x
-1+y
*COLS
] == prev_color
)
2135 if( x
< COLS
-1 && save_buffer
[x
+1+y
*COLS
] == prev_color
)
2139 if( y
> 0 && save_buffer
[x
+(y
-1)*COLS
] == prev_color
)
2143 if( y
< ROWS
- 1 && save_buffer
[x
+(y
+1)*COLS
] == prev_color
)
2151 rp_colors
[ drawcolor
] = LCD_RGBPACK( r2
, g2
, b2
);
2154 static void radial_gradient( int x1
, int y1
, int x2
, int y2
)
2156 int r1
= RGB_UNPACK_RED( rp_colors
[ bgdrawcolor
] );
2157 int g1
= RGB_UNPACK_GREEN( rp_colors
[ bgdrawcolor
] );
2158 int b1
= RGB_UNPACK_BLUE( rp_colors
[ bgdrawcolor
] );
2159 int r2
= RGB_UNPACK_RED( rp_colors
[ drawcolor
] );
2160 int g2
= RGB_UNPACK_GREEN( rp_colors
[ drawcolor
] );
2161 int b2
= RGB_UNPACK_BLUE( rp_colors
[ drawcolor
] );
2163 int h1
, s1
, v1
, h2
, s2
, v2
, r
, g
, b
;
2166 int radius2
= ( x1
- x2
) * ( x1
- x2
) + ( y1
- y2
) * ( y1
- y2
);
2169 /* We only propagate the gradient to neighboring pixels with the same
2170 * color as ( x1, y1 ) */
2171 unsigned int prev_color
= save_buffer
[ x1
+y1
*COLS
];
2176 if( radius2
== 0 ) return;
2179 line_gradient( x1
, y1
, x2
, y2
);
2182 rgb2hsv( r1
, g1
, b1
, &h1
, &s1
, &v1
);
2183 rgb2hsv( r2
, g2
, b2
, &h2
, &s2
, &v2
);
2185 #define PUSH( x0, y0 ) \
2186 buffer.coord[i].x = (short)(x0); \
2187 buffer.coord[i].y = (short)(y0); \
2189 #define POP( a, b ) \
2191 a = (int)buffer.coord[i].x; \
2192 b = (int)buffer.coord[i].y;
2200 if( ( dist2
= (x1
-(x
))*(x1
-(x
))+(y1
-(y
))*(y1
-(y
)) ) < radius2
)
2202 hsv2rgb( h1
+((h2
-h1
)*dist2
)/radius2
,
2203 s1
+((s2
-s1
)*dist2
)/radius2
,
2204 v1
+((v2
-v1
)*dist2
)/radius2
,
2206 rp_colors
[ drawcolor
] = LCD_RGBPACK( r
, g
, b
);
2210 rp_colors
[ drawcolor
] = LCD_RGBPACK( r2
, g2
, b2
);
2212 if( rp_colors
[ drawcolor
] == prev_color
)
2214 if( rp_colors
[ drawcolor
])
2215 rp_colors
[ drawcolor
]--; /* GRUIK */
2217 rp_colors
[ drawcolor
]++; /* GRUIK */
2219 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
2222 if( x
> 0 && save_buffer
[x
-1+y
*COLS
] == prev_color
)
2226 if( x
< COLS
-1 && save_buffer
[x
+1+y
*COLS
] == prev_color
)
2230 if( y
> 0 && save_buffer
[x
+(y
-1)*COLS
] == prev_color
)
2234 if( y
< ROWS
- 1 && save_buffer
[x
+(y
+1)*COLS
] == prev_color
)
2242 rp_colors
[ drawcolor
] = LCD_RGBPACK( r2
, g2
, b2
);
2245 static void draw_toolbars(bool update
)
2248 #define TOP (LCD_HEIGHT-TB_HEIGHT)
2249 rb
->lcd_set_background( COLOR_LIGHTGRAY
);
2250 rb
->lcd_set_foreground( COLOR_LIGHTGRAY
);
2251 rb
->lcd_fillrect( 0, TOP
, LCD_WIDTH
, TB_HEIGHT
);
2252 rb
->lcd_set_foreground( COLOR_BLACK
);
2253 rb
->lcd_drawrect( 0, TOP
, LCD_WIDTH
, TB_HEIGHT
);
2255 rb
->lcd_set_foreground( rp_colors
[ bgdrawcolor
] );
2256 rb
->lcd_fillrect( TB_SC_BG_LEFT
, TOP
+TB_SC_BG_TOP
,
2257 TB_SC_SIZE
, TB_SC_SIZE
);
2258 rb
->lcd_set_foreground(ROCKPAINT_PALETTE
);
2259 rb
->lcd_drawrect( TB_SC_BG_LEFT
, TOP
+TB_SC_BG_TOP
,
2260 TB_SC_SIZE
, TB_SC_SIZE
);
2261 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
2262 rb
->lcd_fillrect( TB_SC_FG_LEFT
, TOP
+TB_SC_FG_TOP
,
2263 TB_SC_SIZE
, TB_SC_SIZE
);
2264 rb
->lcd_set_foreground(ROCKPAINT_PALETTE
);
2265 rb
->lcd_drawrect( TB_SC_FG_LEFT
, TOP
+TB_SC_FG_TOP
,
2266 TB_SC_SIZE
, TB_SC_SIZE
);
2268 for( i
=0; i
<18; i
++ )
2270 rb
->lcd_set_foreground( rp_colors
[i
] );
2272 TB_PL_LEFT
+(i
%9)*( TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
),
2273 TOP
+TB_PL_TOP
+(i
/9)*( TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
),
2274 TB_PL_COLOR_SIZE
, TB_PL_COLOR_SIZE
);
2275 rb
->lcd_set_foreground( ROCKPAINT_PALETTE
);
2277 TB_PL_LEFT
+(i
%9)*( TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
),
2278 TOP
+TB_PL_TOP
+(i
/9)*( TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
),
2279 TB_PL_COLOR_SIZE
, TB_PL_COLOR_SIZE
);
2282 #define SEPARATOR( x, y ) \
2283 rb->lcd_set_foreground( COLOR_WHITE ); \
2284 rb->lcd_vline( x, TOP+y, TOP+y+TB_PL_HEIGHT-1 ); \
2285 rb->lcd_set_foreground( COLOR_DARKGRAY ); \
2286 rb->lcd_vline( x+1, TOP+y, TOP+y+TB_PL_HEIGHT-1 );
2287 SEPARATOR( TB_PL_LEFT
+ TB_PL_WIDTH
- 1 + TB_SP_MARGIN
, TB_PL_TOP
);
2289 rb
->lcd_bitmap_transparent( rockpaint
, TB_TL_LEFT
, TOP
+TB_TL_TOP
,
2290 TB_TL_WIDTH
, TB_TL_HEIGHT
);
2291 rb
->lcd_set_foreground(ROCKPAINT_PALETTE
);
2292 rb
->lcd_drawrect( TB_TL_LEFT
+(TB_TL_SIZE
+TB_TL_SPACING
)*(tool
/2),
2293 TOP
+TB_TL_TOP
+(TB_TL_SIZE
+TB_TL_SPACING
)*(tool
%2),
2294 TB_TL_SIZE
, TB_TL_SIZE
);
2296 SEPARATOR( TB_TL_LEFT
+ TB_TL_WIDTH
- 1 + TB_SP_MARGIN
, TB_TL_TOP
);
2298 rb
->lcd_setfont( FONT_SYSFIXED
);
2299 rb
->lcd_putsxy( TB_MENU_LEFT
, TOP
+TB_MENU_TOP
, "Menu" );
2300 rb
->lcd_setfont( FONT_UI
);
2303 if( update
) rb
->lcd_update();
2306 static void toolbar( void )
2310 draw_toolbars( false );
2311 y
= LCD_HEIGHT
-TB_HEIGHT
/2;
2315 switch( button
= rb
->button_get( true ) )
2317 case ROCKPAINT_DRAW
:
2318 #define TOP ( LCD_HEIGHT - TB_HEIGHT )
2319 if( y
>= TOP
+ TB_SC_FG_TOP
2320 && y
< TOP
+ TB_SC_FG_TOP
+ TB_SC_SIZE
2321 && x
>= TB_SC_FG_LEFT
2322 && x
< TB_SC_FG_LEFT
+ TB_SC_SIZE
)
2324 /* click on the foreground color */
2325 rp_colors
[drawcolor
] = color_chooser( rp_colors
[drawcolor
] );
2327 else if( y
>= TOP
+ TB_SC_BG_TOP
2328 && y
< TOP
+ TB_SC_BG_TOP
+ TB_SC_SIZE
2329 && x
>= TB_SC_BG_LEFT
2330 && x
< TB_SC_BG_LEFT
+ TB_SC_SIZE
)
2332 /* click on the background color */
2334 drawcolor
= bgdrawcolor
;
2337 else if( y
>= TOP
+ TB_PL_TOP
2338 && y
< TOP
+ TB_PL_TOP
+ TB_PL_HEIGHT
2340 && x
< TB_PL_LEFT
+ TB_PL_WIDTH
)
2342 /* click on the palette */
2343 i
= (x
- TB_PL_LEFT
)%(TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
);
2344 j
= (y
- (TOP
+TB_PL_TOP
) )%(TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
);
2345 if( i
>= TB_PL_COLOR_SIZE
|| j
>= TB_PL_COLOR_SIZE
)
2347 i
= ( x
- TB_PL_LEFT
)/(TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
);
2348 j
= ( y
- (TOP
+TB_PL_TOP
) )/(TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
);
2349 drawcolor
= j
*(TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
)+i
;
2351 else if( y
>= TOP
+TB_TL_TOP
2352 && y
< TOP
+ TB_TL_TOP
+ TB_TL_HEIGHT
2354 && x
<= TB_TL_LEFT
+ TB_TL_WIDTH
)
2356 /* click on the tools */
2357 i
= (x
- TB_TL_LEFT
) % (TB_TL_SIZE
+TB_TL_SPACING
);
2358 j
= (y
- (TOP
+TB_TL_TOP
) ) %(TB_TL_SIZE
+TB_TL_SPACING
);
2359 if( i
>= TB_TL_SIZE
|| j
>= TB_TL_SIZE
) break;
2360 i
= ( x
- TB_TL_LEFT
)/(TB_TL_SIZE
+TB_TL_SPACING
);
2361 j
= ( y
- (TOP
+TB_TL_TOP
) )/(TB_TL_SIZE
+TB_TL_SPACING
);
2371 else if( x
>= TB_MENU_LEFT
&& y
>= TOP
+TB_MENU_TOP
-2)
2378 draw_toolbars( false );
2382 case ROCKPAINT_LEFT
:
2383 case ROCKPAINT_LEFT
| BUTTON_REPEAT
:
2385 x
-=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
2390 case ROCKPAINT_RIGHT
:
2391 case ROCKPAINT_RIGHT
| BUTTON_REPEAT
:
2393 x
+=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
2399 case ROCKPAINT_UP
| BUTTON_REPEAT
:
2401 y
-=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
2402 if (y
<LCD_HEIGHT
-TB_HEIGHT
)
2409 case ROCKPAINT_DOWN
:
2410 case ROCKPAINT_DOWN
| BUTTON_REPEAT
:
2412 y
+=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
2421 case ROCKPAINT_TOOLBAR
:
2422 case ROCKPAINT_TOOLBAR2
:
2429 static void inv_cursor(bool update
)
2431 rb
->lcd_set_foreground(COLOR_BLACK
);
2432 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
2433 /* cross painting */
2434 rb
->lcd_hline(x
-4,x
-1,y
);
2435 rb
->lcd_hline(x
+1,x
+4,y
);
2436 rb
->lcd_vline(x
,y
-4,y
-1);
2437 rb
->lcd_vline(x
,y
+1,y
+4);
2438 rb
->lcd_set_foreground(rp_colors
[drawcolor
]);
2439 rb
->lcd_set_drawmode(DRMODE_SOLID
);
2441 if( update
) rb
->lcd_update();
2444 static void restore_screen(void)
2446 rb
->lcd_bitmap( save_buffer
, 0, 0, COLS
, ROWS
);
2449 static void clear_drawing(void)
2452 rb
->lcd_set_foreground( rp_colors
[ bgdrawcolor
] );
2453 rb
->lcd_fillrect( 0, 0, COLS
, ROWS
);
2457 static void goto_menu(void)
2464 switch( rb
->do_menu( &main_menu
, &selected
, NULL
, false ) )
2470 case MAIN_MENU_LOAD
:
2471 if( browse( filename
, MAX_PATH
, "/" ) )
2473 if( load_bitmap( filename
) <= 0 )
2475 rb
->splashf( 1*HZ
, "Error while loading %s",
2480 rb
->splashf( 1*HZ
, "Image loaded (%s)", filename
);
2488 case MAIN_MENU_SAVE
:
2489 rb
->lcd_set_foreground(COLOR_BLACK
);
2491 rb
->strcpy(filename
,"/");
2492 if( !rb
->kbd_input( filename
, MAX_PATH
) )
2494 if(rb
->strlen(filename
) <= 4 ||
2495 rb
->strcasecmp(&filename
[rb
->strlen(filename
)-4], ".bmp"))
2496 rb
->strcat(filename
, ".bmp");
2497 save_bitmap( filename
);
2498 rb
->splashf( 1*HZ
, "File saved (%s)", filename
);
2502 case MAIN_MENU_BRUSH_SIZE
:
2503 for(multi
= 0; multi
<4; multi
++)
2504 if(bsize
== times_list
[multi
]) break;
2505 rb
->set_option( "Brush Size", &multi
, INT
, times_options
, 4, NULL
);
2507 bsize
= times_list
[multi
];
2510 case MAIN_MENU_BRUSH_SPEED
:
2511 for(multi
= 0; multi
<3; multi
++)
2512 if(bspeed
== times_list
[multi
]) break;
2513 rb
->set_option( "Brush Speed", &multi
, INT
, times_options
, 3, NULL
);
2515 bspeed
= times_list
[multi
];
2518 case MAIN_MENU_COLOR
:
2519 rp_colors
[drawcolor
] = color_chooser( rp_colors
[drawcolor
] );
2522 case MAIN_MENU_GRID_SIZE
:
2523 for(multi
= 0; multi
<4; multi
++)
2524 if(gridsize
== gridsize_list
[multi
]) break;
2525 rb
->set_option( "Grid Size", &multi
, INT
, gridsize_options
, 4, NULL
);
2527 gridsize
= gridsize_list
[multi
];
2530 case MAIN_MENU_PLAYBACK_CONTROL
:
2531 playback_control( NULL
);
2534 case MAIN_MENU_EXIT
:
2539 case MAIN_MENU_RESUME
:
2547 static void reset_tool( void )
2559 static bool rockpaint_loop( void )
2571 button
= rb
->button_get(true);
2573 if( tool
== Brush
&& prev_x
!= -1 )
2577 else if( button
& BUTTON_REPEAT
)
2588 case ROCKPAINT_QUIT
:
2589 rb
->lcd_set_drawmode(DRMODE_SOLID
);
2592 case ROCKPAINT_MENU
:
2599 case ROCKPAINT_DRAW
:
2604 if( prev_x
== -1 ) prev_x
= 1;
2608 case SelectRectangle
:
2615 case LinearGradient
:
2616 case RadialGradient
:
2617 /* Curve uses 4 points, others use 2 */
2618 if( prev_x
== -1 || prev_y
== -1 )
2624 else if( tool
== Curve
2625 && ( prev_x2
== -1 || prev_y2
== -1 ) )
2630 else if( tool
== SelectRectangle
2631 && ( prev_x2
== -1 || prev_y2
== -1 ) )
2633 tool_mode
= rb
->do_menu( &select_menu
,
2634 NULL
, NULL
, false );
2637 case SELECT_MENU_CUT
:
2638 case SELECT_MENU_COPY
:
2641 copy_to_clipboard();
2642 if( prev_x
< x
) x
= prev_x
;
2643 if( prev_y
< y
) y
= prev_y
;
2646 case SELECT_MENU_INVERT
:
2647 draw_invert( prev_x
, prev_y
, x
, y
);
2651 case SELECT_MENU_HFLIP
:
2652 draw_hflip( prev_x
, prev_y
, x
, y
);
2656 case SELECT_MENU_VFLIP
:
2657 draw_vflip( prev_x
, prev_y
, x
, y
);
2661 case SELECT_MENU_ROTATE90
:
2662 draw_rot_90_deg( prev_x
, prev_y
, x
, y
, 1 );
2666 case SELECT_MENU_ROTATE180
:
2667 draw_hflip( prev_x
, prev_y
, x
, y
);
2668 draw_vflip( prev_x
, prev_y
, x
, y
);
2672 case SELECT_MENU_ROTATE270
:
2673 draw_rot_90_deg( prev_x
, prev_y
, x
, y
, -1 );
2677 case SELECT_MENU_CANCEL
:
2686 else if( tool
== Curve
2687 && ( prev_x3
== -1 || prev_y3
== -1 ) )
2697 case SelectRectangle
:
2698 draw_paste_rectangle( prev_x
, prev_y
,
2703 draw_line( prev_x
, prev_y
, x
, y
);
2706 draw_curve( prev_x
, prev_y
,
2712 draw_rect( prev_x
, prev_y
, x
, y
);
2715 draw_rect_full( prev_x
, prev_y
, x
, y
);
2718 draw_oval_empty( prev_x
, prev_y
, x
, y
);
2721 draw_oval_full( prev_x
, prev_y
, x
, y
);
2723 case LinearGradient
:
2724 linear_gradient( prev_x
, prev_y
, x
, y
);
2726 case RadialGradient
:
2727 radial_gradient( prev_x
, prev_y
, x
, y
);
2741 color_picker( x
, y
);
2754 case ROCKPAINT_DRAW
|BUTTON_REPEAT
:
2757 /* 3 point bezier curve */
2759 draw_curve( prev_x
, prev_y
,
2769 case ROCKPAINT_TOOLBAR
:
2778 case ROCKPAINT_TOOLBAR2
:
2787 case ROCKPAINT_LEFT
:
2788 case ROCKPAINT_LEFT
| BUTTON_REPEAT
:
2790 x
-=bspeed
* accelaration
;
2795 case ROCKPAINT_RIGHT
:
2796 case ROCKPAINT_RIGHT
| BUTTON_REPEAT
:
2798 x
+=bspeed
* accelaration
;
2804 case ROCKPAINT_UP
| BUTTON_REPEAT
:
2806 y
-=bspeed
* accelaration
;
2811 case ROCKPAINT_DOWN
:
2812 case ROCKPAINT_DOWN
| BUTTON_REPEAT
:
2814 y
+=bspeed
* accelaration
;
2824 if (rb
->default_event_handler(button
) == SYS_USB_CONNECTED
)
2825 return PLUGIN_USB_CONNECTED
;
2828 if( tool
== Brush
&& prev_x
== 1 )
2834 if( preview
|| tool
== ColorPicker
)
2835 /* always preview color picker */
2840 case SelectRectangle
:
2841 if( prev_x2
== -1 || prev_y2
== -1 )
2843 /* we are defining the selection */
2844 draw_select_rectangle( prev_x
, prev_y
, x
, y
);
2848 /* we are pasting the selected data */
2849 draw_paste_rectangle( prev_x
, prev_y
, prev_x2
,
2850 prev_y2
, x
, y
, tool_mode
);
2851 prev_x3
= prev_x2
-prev_x
;
2852 if( prev_x3
< 0 ) prev_x3
*= -1;
2853 prev_y3
= prev_y2
-prev_y
;
2854 if( prev_y3
< 0 ) prev_y3
*= -1;
2855 draw_select_rectangle( x
, y
, x
+prev_x3
, y
+prev_y3
);
2865 draw_line( prev_x
, prev_y
, x
, y
);
2869 if( prev_x2
== -1 || prev_y2
== -1 )
2871 draw_line( prev_x
, prev_y
, x
, y
);
2875 draw_curve( prev_x
, prev_y
,
2883 draw_rect( prev_x
, prev_y
, x
, y
);
2887 draw_rect_full( prev_x
, prev_y
, x
, y
);
2891 draw_oval_empty( prev_x
, prev_y
, x
, y
);
2895 draw_oval_full( prev_x
, prev_y
, x
, y
);
2903 color_picker( x
, y
);
2907 case LinearGradient
:
2908 line_gradient( prev_x
, prev_y
, x
, y
);
2911 case RadialGradient
:
2912 line_gradient( prev_x
, prev_y
, x
, y
);
2931 static int load_bitmap( const char *file
)
2937 bm
.data
= (char*)save_buffer
;
2938 ret
= rb
->read_bmp_file( file
, &bm
, ROWS
*COLS
*sizeof( fb_data
),
2939 FORMAT_NATIVE
, NULL
);
2941 if((bm
.width
> COLS
) || ( bm
.height
> ROWS
))
2944 for( l
= bm
.height
-1; l
> 0; l
-- )
2946 rb
->memmove( save_buffer
+l
*COLS
, save_buffer
+l
*bm
.width
,
2947 sizeof( fb_data
)*bm
.width
);
2949 for( l
= 0; l
< bm
.height
; l
++ )
2951 rb
->memset( save_buffer
+l
*COLS
+bm
.width
, rp_colors
[ bgdrawcolor
],
2952 sizeof( fb_data
)*(COLS
-bm
.width
) );
2954 rb
->memset( save_buffer
+COLS
*bm
.height
, rp_colors
[ bgdrawcolor
],
2955 sizeof( fb_data
)*COLS
*(ROWS
-bm
.height
) );
2960 static int save_bitmap( char *file
)
2963 bm
.data
= (char*)save_buffer
;
2966 bm
.format
= FORMAT_NATIVE
;
2967 return save_bmp_file( file
, &bm
);
2970 enum plugin_status
plugin_start(UNUSED_ATTR
const void* parameter
)
2972 rb
->lcd_set_foreground(COLOR_WHITE
);
2973 rb
->lcd_set_backdrop(NULL
);
2974 rb
->lcd_fillrect(0,0,LCD_WIDTH
,LCD_HEIGHT
);
2975 rb
->splash( HZ
/2, "Rock Paint");
2977 rb
->lcd_clear_display();
2983 if( load_bitmap( parameter
) <= 0 )
2985 rb
->splash( 1*HZ
, "File Open Error");
2990 rb
->splashf( 1*HZ
, "Image loaded (%s)", (char *)parameter
);
2992 rb
->strcpy( filename
, parameter
);
3001 return rockpaint_loop();