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 */
404 char old_font
[MAX_PATH
];
407 char fontname_buf
[30][MAX_PATH
];
411 /* Current filename */
412 static char filename
[MAX_PATH
];
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
]; /* used by file and font browsers */
600 char bbuf_s
[MAX_PATH
]; /* used by file and font browsers */
601 struct tree_context
*tree
= NULL
;
603 static bool check_extention(const char *filename
, const char *ext
)
605 const char *p
= rb
->strrchr( filename
, '.' );
606 return ( p
!= NULL
&& !rb
->strcasecmp( p
, ext
) );
609 static const char* browse_get_name_cb(int selected_item
, void *data
,
610 char *buffer
, size_t buffer_len
)
612 int *indexes
= (int *) data
;
613 struct entry
* dc
= tree
->dircache
;
614 struct entry
* e
= &dc
[indexes
[selected_item
]];
621 static bool browse( char *dst
, int dst_size
, const char *start
)
623 struct gui_synclist browse_list
;
624 int item_count
= 0, selected
, button
;
625 struct tree_context backup
;
628 int dirfilter
= SHOW_ALL
;
629 int *indexes
= (int *) buffer
.clipboard
;
633 rb
->strcpy( bbuf
, start
);
634 a
= bbuf
+rb
->strlen(bbuf
)-1;
642 rb
->gui_synclist_init(&browse_list
, browse_get_name_cb
,
643 (void*) indexes
, false, 1, NULL
);
645 tree
= rb
->tree_get_context();
648 a
= backup
.currdir
+rb
->strlen(backup
.currdir
)-1;
654 rb
->strcpy( a
, dc
[tree
->selected_item
].name
);
655 tree
->dirfilter
= &dirfilter
;
661 rb
->set_current_file(bbuf
);
664 for( i
= 0; i
< tree
->filesindir
; i
++)
666 /* only displayes directories and .bmp files */
667 if( ((dc
[i
].attr
& ATTR_DIRECTORY
) &&
668 rb
->strcmp( dc
[i
].name
, "." ) &&
669 rb
->strcmp( dc
[i
].name
, ".." )) ||
670 ( !(dc
[i
].attr
& ATTR_DIRECTORY
) &&
671 check_extention( dc
[i
].name
, ".bmp" ) ) )
673 if( !rb
->strcmp( dc
[i
].name
, bbuf_s
) )
674 selected
= item_count
;
675 indexes
[item_count
++] = i
;
679 rb
->gui_synclist_set_nb_items(&browse_list
,item_count
);
680 rb
->gui_synclist_select_item(&browse_list
, selected
);
681 rb
->gui_synclist_set_title(&browse_list
, bbuf
, NOICON
);
682 rb
->gui_synclist_draw(&browse_list
);
685 button
= rb
->get_action(CONTEXT_LIST
,TIMEOUT_BLOCK
);
686 if (rb
->gui_synclist_do_button(&browse_list
,&button
,LIST_WRAP_UNLESS_HELD
))
690 case ACTION_STD_CANCEL
:
691 if( !rb
->strcmp( bbuf
, "/" ) )
694 rb
->set_current_file( backup
.currdir
);
697 rb
->strcpy( bbuf_s
, ".." );
699 if( button
== ACTION_STD_OK
)
701 selected
= rb
->gui_synclist_get_sel_pos( &browse_list
);
702 if( selected
< 0 || selected
>= item_count
)
704 struct entry
* e
= &dc
[indexes
[selected
]];
705 rb
->strlcpy( bbuf_s
, e
->name
, sizeof( bbuf_s
) );
706 if( !( e
->attr
& ATTR_DIRECTORY
) )
709 rb
->set_current_file( backup
.currdir
);
710 rb
->snprintf( dst
, dst_size
, "%s%s", bbuf
, bbuf_s
);
714 if( !rb
->strcmp( bbuf_s
, "." ) ) break;
715 a
= bbuf
+rb
->strlen(bbuf
);
716 if( !rb
->strcmp( bbuf_s
, ".." ) )
719 if( a
== bbuf
) break;
721 while( *a
!= '/' ) a
--;
722 rb
->strcpy( bbuf_s
, ++a
);
723 /* select parent directory */
724 bbuf_s
[rb
->strlen(bbuf_s
)-1] = '\0';
729 rb
->snprintf( a
, bbuf
+sizeof(bbuf
)-a
, "%s/", bbuf_s
);
733 case ACTION_STD_MENU
:
735 rb
->set_current_file( backup
.currdir
);
741 /***********************************************************************
744 * FIXME: This still needs some work ... it currently only works fine
745 * on the simulators, disk spins too much on real targets -> rendered
746 * font buffer needed.
747 ***********************************************************************/
748 static bool browse_fonts( char *dst
, int dst_size
)
750 #define WIDTH ( LCD_WIDTH - 20 )
751 #define HEIGHT ( LCD_HEIGHT - 20 )
753 int top
, top_inside
= 0, left
;
757 int fvi
= 0; /* first visible item */
758 int lvi
= 0; /* last visible item */
759 int si
= 0; /* selected item */
760 int osi
= 0; /* old selected item */
761 int li
= 0; /* last item */
762 int nvih
= 0; /* next visible item height */
764 int b_need_redraw
= 1; /* Do we need to redraw ? */
766 int cp
= 0; /* current position */
767 int fh
; /* font height */
769 #define fh_buf buffer.text.fh_buf /* 30 might not be enough ... */
770 #define fw_buf buffer.text.fw_buf
772 #define fontname_buf buffer.text.fontname_buf
774 rb
->snprintf( buffer
.text
.old_font
, MAX_PATH
,
776 rb
->global_settings
->font_file
);
782 /* we don't need to redraw ... but we need to unselect
783 * the previously selected item */
784 cp
= top_inside
+ LINE_SPACE
;
785 for( i
= 0; i
+fvi
< osi
; i
++ )
787 cp
+= fh_buf
[i
] + LINE_SPACE
;
789 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
790 rb
->lcd_fillrect( left
+10, cp
, fw_buf
[i
], fh_buf
[i
] );
791 rb
->lcd_set_drawmode(DRMODE_SOLID
);
798 d
= rb
->opendir( FONT_DIR
"/" );
803 top_inside
= draw_window( HEIGHT
, WIDTH
, &top
, &left
, "Fonts" );
811 cp
= top_inside
+LINE_SPACE
;
813 rb
->lcd_set_foreground(COLOR_BLACK
);
814 rb
->lcd_set_background(COLOR_LIGHTGRAY
);
816 while( cp
< top
+HEIGHT
)
818 de
= rb
->readdir( d
);
824 if( !check_extention( de
->d_name
, ".fnt" ) )
826 rb
->snprintf( bbuf
, MAX_PATH
, FONT_DIR
"/%s",
828 rb
->font_load( bbuf
);
829 rb
->font_getstringsize( de
->d_name
, &fw
, &fh
, FONT_UI
);
834 if( nvih
< 0 ) nvih
= 0;
838 if( cp
+ fh
>= top
+HEIGHT
)
843 rb
->lcd_putsxy( left
+10, cp
, de
->d_name
);
846 cp
+= fh
+ LINE_SPACE
;
847 rb
->strcpy( fontname_buf
[i
-fvi
], bbuf
);
853 if( !(de
= rb
->readdir( d
) ) )
857 else if( !nvih
&& check_extention( de
->d_name
, ".fnt" ) )
859 rb
->snprintf( bbuf
, MAX_PATH
, FONT_DIR
"/%s",
861 rb
->font_load( bbuf
);
862 rb
->font_getstringsize( de
->d_name
, NULL
, &fh
, FONT_UI
);
866 rb
->font_load( buffer
.text
.old_font
);
870 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
871 cp
= top_inside
+ LINE_SPACE
;
872 for( i
= 0; i
+fvi
< si
; i
++ )
874 cp
+= fh_buf
[i
] + LINE_SPACE
;
876 rb
->lcd_fillrect( left
+10, cp
, fw_buf
[i
], fh_buf
[i
] );
877 rb
->lcd_set_drawmode(DRMODE_SOLID
);
879 rb
->lcd_update_rect( left
, top
, WIDTH
, HEIGHT
);
883 switch( rb
->button_get(true) )
886 case ROCKPAINT_UP
|BUTTON_REPEAT
:
898 case ROCKPAINT_DOWN
|BUTTON_REPEAT
:
899 if( li
== -1 || si
< li
)
908 case ROCKPAINT_RIGHT
:
910 rb
->snprintf( dst
, dst_size
, "%s", fontname_buf
[si
-fvi
] );
914 if( i
!= fvi
|| si
> lvi
)
932 /***********************************************************************
933 * HSVRGB Color chooser
934 ***********************************************************************/
935 static unsigned int color_chooser( unsigned int color
)
937 int red
= RGB_UNPACK_RED( color
);
938 int green
= RGB_UNPACK_GREEN( color
);
939 int blue
= RGB_UNPACK_BLUE( color
);
940 int hue
, saturation
, value
;
941 int r
, g
, b
; /* temp variables */
944 enum BaseColor
{ Hue
= 0, Saturation
= 1, Value
= 2,
945 Red
= 3, Green
= 4, Blue
= 5 };
946 enum BaseColor current
= Red
;
953 rgb2hsv( red
, green
, blue
, &hue
, &saturation
, &value
);
958 color
= LCD_RGBPACK( red
, green
, blue
);
960 #define HEIGHT ( 100 )
961 #define WIDTH ( 150 )
963 top
= draw_window( HEIGHT
, WIDTH
, NULL
, &left
, "Color chooser" );
966 for( i
=0; i
<100; i
++ )
968 hsv2rgb( i
*36, saturation
, value
, &r
, &g
, &b
);
969 rb
->lcd_set_foreground( LCD_RGBPACK( r
, g
, b
) );
970 rb
->lcd_vline( left
+15+i
, top
+20, top
+27 );
971 hsv2rgb( hue
, i
*255/100, value
, &r
, &g
, &b
);
972 rb
->lcd_set_foreground( LCD_RGBPACK( r
, g
, b
) );
973 rb
->lcd_vline( left
+15+i
, top
+30, top
+37 );
974 hsv2rgb( hue
, saturation
, i
*255/100, &r
, &g
, &b
);
975 rb
->lcd_set_foreground( LCD_RGBPACK( r
, g
, b
) );
976 rb
->lcd_vline( left
+15+i
, top
+40, top
+47 );
977 rb
->lcd_set_foreground( LCD_RGBPACK( i
*255/100, green
, blue
) );
978 rb
->lcd_vline( left
+15+i
, top
+50, top
+57 );
979 rb
->lcd_set_foreground( LCD_RGBPACK( red
, i
*255/100, blue
) );
980 rb
->lcd_vline( left
+15+i
, top
+60, top
+67 );
981 rb
->lcd_set_foreground( LCD_RGBPACK( red
, green
, i
*255/100 ) );
982 rb
->lcd_vline( left
+15+i
, top
+70, top
+77 );
985 rb
->lcd_set_foreground(COLOR_BLACK
);
986 #define POSITION( a, i ) \
987 rb->lcd_drawpixel( left+14+i, top + 19 + a ); \
988 rb->lcd_drawpixel( left+16+i, top + 19 + a ); \
989 rb->lcd_drawpixel( left+14+i, top + 28 + a ); \
990 rb->lcd_drawpixel( left+16+i, top + 28 + a );
991 POSITION( 0, hue
/36 );
992 POSITION( 10, saturation
*99/255 );
993 POSITION( 20, value
*99/255 );
994 POSITION( 30, red
*99/255 );
995 POSITION( 40, green
*99/255 );
996 POSITION( 50, blue
*99/255 );
998 rb
->lcd_set_background(COLOR_LIGHTGRAY
);
999 rb
->lcd_setfont( FONT_SYSFIXED
);
1000 rb
->snprintf( str
, 6, "%d", hue
/10 );
1001 rb
->lcd_putsxy( left
+ 117, top
+ 20, str
);
1002 rb
->snprintf( str
, 6, "%d.%d", saturation
/255, ((saturation
*100)/255)%100 );
1003 rb
->lcd_putsxy( left
+ 117, top
+ 30, str
);
1004 rb
->snprintf( str
, 6, "%d.%d", value
/255, ((value
*100)/255)%100 );
1005 rb
->lcd_putsxy( left
+ 117, top
+ 40, str
);
1006 rb
->snprintf( str
, 6, "%d", red
);
1007 rb
->lcd_putsxy( left
+ 117, top
+ 50, str
);
1008 rb
->snprintf( str
, 6, "%d", green
);
1009 rb
->lcd_putsxy( left
+ 117, top
+ 60, str
);
1010 rb
->snprintf( str
, 6, "%d", blue
);
1011 rb
->lcd_putsxy( left
+ 117, top
+ 70, str
);
1012 rb
->lcd_setfont( FONT_UI
);
1014 #define CURSOR( l ) \
1015 rb->lcd_bitmap_transparent_part( rockpaint_hsvrgb, 1, 1, 16, left+l+1, top+20, 6, 58 ); \
1016 rb->lcd_bitmap_transparent_part( rockpaint_hsvrgb, 8, 10*current, 16, left+l, top+19+10*current, 8, 10 );
1020 rb
->lcd_set_foreground( color
);
1021 rb
->lcd_fillrect( left
+15, top
+85, 100, 8 );
1025 switch( rb
->button_get(true) )
1028 current
= ( current
+ 5 )%6;
1031 case ROCKPAINT_DOWN
:
1032 current
= (current
+ 1 )%6;
1035 case ROCKPAINT_LEFT
:
1040 hue
= ( hue
+ 3600 - 10 )%3600;
1043 if( saturation
) saturation
--;
1046 if( value
) value
--;
1052 if( green
) green
--;
1060 case ROCKPAINT_LEFT
|BUTTON_REPEAT
:
1065 hue
= ( hue
+ 3600 - 100 )%3600;
1068 if( saturation
>= 8 ) saturation
-=8;
1069 else saturation
= 0;
1072 if( value
>= 8 ) value
-=8;
1076 if( red
>= 8 ) red
-=8;
1080 if( green
>= 8 ) green
-=8;
1084 if( blue
>= 8 ) blue
-=8;
1090 case ROCKPAINT_RIGHT
:
1095 hue
= ( hue
+ 10 )%3600;
1098 if( saturation
< 0xff ) saturation
++;
1101 if( value
< 0xff ) value
++;
1104 if( red
< 0xff ) red
++;
1107 if( green
< 0xff ) green
++;
1110 if( blue
< 0xff ) blue
++;
1115 case ROCKPAINT_RIGHT
|BUTTON_REPEAT
:
1120 hue
= ( hue
+ 100 )%3600;
1123 if( saturation
< 0xff - 8 ) saturation
+=8;
1124 else saturation
= 0xff;
1127 if( value
< 0xff - 8 ) value
+=8;
1131 if( red
< 0xff - 8 ) red
+=8;
1135 if( green
< 0xff - 8 ) green
+=8;
1139 if( blue
< 0xff - 8 ) blue
+=8;
1145 case ROCKPAINT_DRAW
:
1155 hsv2rgb( hue
, saturation
, value
, &red
, &green
, &blue
);
1161 rgb2hsv( red
, green
, blue
, &hue
, &saturation
, &value
);
1170 /***********************************************************************
1172 ***********************************************************************/
1173 static void init_buffer(void)
1176 fb_data color
= rp_colors
[ bgdrawcolor
];
1177 for( i
= 0; i
< ROWS
*COLS
; i
++ )
1179 save_buffer
[i
] = color
;
1183 static void draw_pixel(int x
,int y
)
1187 if( x
< 0 || x
>= COLS
|| y
< 0 || y
>= ROWS
) return;
1190 save_buffer
[ x
+y
*COLS
] = rp_colors
[bgdrawcolor
];
1194 save_buffer
[ x
+y
*COLS
] = rp_colors
[drawcolor
];
1197 rb
->lcd_drawpixel(x
,y
);
1200 static void color_picker( int x
, int y
)
1204 rb
->lcd_set_foreground( save_buffer
[ x
+y
*COLS
] );
1206 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1207 if( x
>= COLS
- PSIZE
) x
-= PSIZE
+ 2;
1208 if( y
>= ROWS
- PSIZE
) y
-= PSIZE
+ 2;
1209 rb
->lcd_drawrect( x
+ 2, y
+ 2, PSIZE
- 2, PSIZE
- 2 );
1210 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1211 rb
->lcd_drawrect( x
+ 3, y
+ 3, PSIZE
- 4, PSIZE
- 4 );
1213 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
1217 rp_colors
[ drawcolor
] = save_buffer
[ x
+y
*COLS
];
1221 static void draw_select_rectangle( int x1
, int y1
, int x2
, int y2
)
1222 /* This is a preview mode only function */
1237 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1239 for( a
= x1
; a
< x2
; a
++, i
++ )
1241 rb
->lcd_drawpixel( a
, y1
);
1242 for( a
= y1
; a
< y2
; a
++, i
++ )
1244 rb
->lcd_drawpixel( x2
, a
);
1246 for( a
= x2
; a
> x1
; a
--, i
++ )
1248 rb
->lcd_drawpixel( a
, y2
);
1250 for( a
= y2
; a
> y1
; a
--, i
++ )
1252 rb
->lcd_drawpixel( x1
, a
);
1253 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1256 static void copy_to_clipboard( void )
1258 /* This needs to be optimised ... but i'm lazy ATM */
1259 rb
->memcpy( buffer
.clipboard
, save_buffer
, COLS
*ROWS
*sizeof( fb_data
) );
1262 /* no preview mode handling atm ... do we need it ? (one if) */
1263 static void draw_invert( int x1
, int y1
, int x2
, int y2
)
1279 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1280 rb
->lcd_fillrect( x1
, y1
, x2
-x1
+1, y2
-y1
+1 );
1281 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1283 for( ; y1
<=y2
; y1
++ )
1285 for( i
= x1
; i
<=x2
; i
++ )
1287 save_buffer
[ y1
*COLS
+ i
] = ~save_buffer
[ y1
*COLS
+ i
];
1290 /*if( update )*/ rb
->lcd_update();
1293 static void draw_hflip( int x1
, int y1
, int x2
, int y2
)
1309 copy_to_clipboard();
1311 for( i
= 0; i
<= y2
- y1
; i
++ )
1313 rb
->memcpy( save_buffer
+(y1
+i
)*COLS
+x1
,
1314 buffer
.clipboard
+(y2
-i
)*COLS
+x1
,
1315 (x2
-x1
+1)*sizeof( fb_data
) );
1321 static void draw_vflip( int x1
, int y1
, int x2
, int y2
)
1337 copy_to_clipboard();
1339 for( ; y1
<= y2
; y1
++ )
1341 for( i
= 0; i
<= x2
- x1
; i
++ )
1343 save_buffer
[y1
*COLS
+x1
+i
] = buffer
.clipboard
[y1
*COLS
+x2
-i
];
1350 /* direction: -1 = left, 1 = right */
1351 static void draw_rot_90_deg( int x1
, int y1
, int x2
, int y2
, int direction
)
1367 copy_to_clipboard();
1369 fb_data color
= rp_colors
[ bgdrawcolor
];
1370 const int width
= x2
- x1
, height
= y2
- y1
;
1371 const int sub_half
= width
/2-height
/2, add_half
= (width
+height
)/2;
1372 if( width
> height
)
1374 for( i
= 0; i
<= height
; i
++ )
1376 for( j
= 0; j
< sub_half
; j
++ )
1377 save_buffer
[(y1
+i
)*COLS
+x1
+j
] = color
;
1378 for( j
= add_half
+1; j
<= width
; j
++ )
1379 save_buffer
[(y1
+i
)*COLS
+x1
+j
] = color
;
1382 else if( width
< height
)
1384 for( j
= 0; j
<= width
; j
++ )
1386 for( i
= 0; i
< -sub_half
; i
++ )
1387 save_buffer
[(y1
+i
)*COLS
+x1
+j
] = color
;
1388 for( i
= add_half
+1; i
<= height
; i
++ )
1389 save_buffer
[(y1
+i
)*COLS
+x1
+j
] = color
;
1392 int x3
= x1
+ sub_half
, y3
= y1
- sub_half
;
1393 int is
= x3
<0?-x3
:0, ie
= COLS
-x3
-1, js
= y3
<0?-y3
:0, je
= ROWS
-y3
-1;
1394 if( ie
> height
) ie
= height
;
1395 if( je
> width
) je
= width
;
1396 for( i
= is
; i
<= ie
; i
++ )
1398 for( j
= js
; j
<= je
; j
++ )
1411 save_buffer
[(y3
+j
)*COLS
+x3
+i
] = buffer
.clipboard
[y
*COLS
+x
];
1418 static void draw_paste_rectangle( int src_x1
, int src_y1
, int src_x2
,
1419 int src_y2
, int x1
, int y1
, int mode
)
1421 int i
, width
, height
;
1422 if( mode
== SELECT_MENU_CUT
)
1425 drawcolor
= bgdrawcolor
;
1426 draw_rect_full( src_x1
, src_y1
, src_x2
, src_y2
);
1429 if( src_x1
> src_x2
)
1435 if( src_y1
> src_y2
)
1441 width
= src_x2
- src_x1
+ 1;
1442 height
= src_y2
- src_y1
+ 1;
1444 if( x1
+ width
> COLS
)
1446 if( y1
+ height
> ROWS
)
1449 rb
->lcd_bitmap_part( buffer
.clipboard
, src_x1
, src_y1
, COLS
,
1450 x1
, y1
, width
, height
);
1453 for( i
= 0; i
< height
; i
++ )
1455 rb
->memcpy( save_buffer
+(y1
+i
)*COLS
+x1
,
1456 buffer
.clipboard
+(src_y1
+i
)*COLS
+src_x1
,
1457 width
*sizeof( fb_data
) );
1462 static void show_grid( bool update
)
1467 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1468 for( i
= gridsize
; i
< COLS
; i
+= gridsize
)
1470 rb
->lcd_vline( i
, 0, ROWS
-1 );
1472 for( i
= gridsize
; i
< ROWS
; i
+= gridsize
)
1474 rb
->lcd_hline( 0, COLS
-1, i
);
1476 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1477 if( update
) rb
->lcd_update();
1481 static void draw_text( int x
, int y
)
1484 buffer
.text
.text
[0] = '\0';
1485 rb
->snprintf( buffer
.text
.old_font
, MAX_PATH
,
1487 rb
->global_settings
->font_file
);
1490 switch( rb
->do_menu( &text_menu
, &selected
, NULL
, NULL
) )
1492 case TEXT_MENU_TEXT
:
1493 rb
->lcd_set_foreground(COLOR_BLACK
);
1494 rb
->kbd_input( buffer
.text
.text
, MAX_TEXT
);
1497 case TEXT_MENU_FONT
:
1498 if( browse_fonts( buffer
.text
.font
, MAX_PATH
) )
1500 rb
->font_load( buffer
.text
.font
);
1504 case TEXT_MENU_PREVIEW
:
1505 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
1510 rb
->lcd_putsxy( x
, y
, buffer
.text
.text
);
1512 switch( button
= rb
->button_get( true ) )
1514 case ROCKPAINT_LEFT
:
1515 case ROCKPAINT_LEFT
| BUTTON_REPEAT
:
1516 x
-=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
1520 case ROCKPAINT_RIGHT
:
1521 case ROCKPAINT_RIGHT
| BUTTON_REPEAT
:
1522 x
+=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
1527 case ROCKPAINT_UP
| BUTTON_REPEAT
:
1528 y
-=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
1532 case ROCKPAINT_DOWN
:
1533 case ROCKPAINT_DOWN
| BUTTON_REPEAT
:
1534 y
+=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
1538 case ROCKPAINT_DRAW
:
1541 if(rb
->default_event_handler(button
)
1542 == SYS_USB_CONNECTED
)
1543 button
= ROCKPAINT_DRAW
;
1546 if( button
== ROCKPAINT_DRAW
) break;
1550 case TEXT_MENU_APPLY
:
1551 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
1552 buffer_putsxyofs( save_buffer
, COLS
, ROWS
, x
, y
, 0,
1554 case TEXT_MENU_CANCEL
:
1557 rb
->font_load( buffer
.text
.old_font
);
1563 static void draw_brush( int x
, int y
)
1566 for( i
=-bsize
/2+(bsize
+1)%2; i
<=bsize
/2; i
++ )
1568 for( j
=-bsize
/2+(bsize
+1)%2; j
<=bsize
/2; j
++ )
1570 draw_pixel( x
+i
, y
+j
);
1575 /* This is an implementation of Bresenham's line algorithm.
1576 * See http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm.
1578 static void draw_line( int x1
, int y1
, int x2
, int y2
)
1582 int deltax
= x2
- x1
;
1583 int deltay
= y2
- y1
;
1586 int xerr
= abs(deltax
);
1587 int yerr
= abs(deltay
);
1588 int xstep
= deltax
> 0 ? 1 : -1;
1589 int ystep
= deltay
> 0 ? 1 : -1;
1599 /* to leave off the last pixel of the line, leave off the "+ 1" */
1600 for (i
= abs(deltay
) + 1; i
; --i
)
1613 /* more horizontal */
1618 for (i
= abs(deltax
) + 1; i
; --i
)
1631 static void draw_curve( int x1
, int y1
, int x2
, int y2
,
1632 int xa
, int ya
, int xb
, int yb
)
1646 if( x1
== x2
&& y1
== y2
)
1648 draw_pixel( x1
, y1
);
1654 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1655 if( xa
== -1 || ya
== -1 )
1657 rb
->lcd_drawline( x1
, y1
, xb
, yb
);
1658 rb
->lcd_drawline( x2
, y2
, xb
, yb
);
1662 rb
->lcd_drawline( x1
, y1
, xa
, ya
);
1663 rb
->lcd_drawline( x2
, y2
, xb
, yb
);
1665 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1668 if( xa
== -1 || ya
== -1 )
1669 /* We only have 3 of the points
1670 * This will currently only be used in preview mode */
1672 #define PUSH( a1, b1, a2, b2, a3, b3, d ) \
1673 buffer.bezier[i].x1 = a1; \
1674 buffer.bezier[i].y1 = b1; \
1675 buffer.bezier[i].x2 = a2; \
1676 buffer.bezier[i].y2 = b2; \
1677 buffer.bezier[i].x3 = a3; \
1678 buffer.bezier[i].y3 = b3; \
1679 buffer.bezier[i].depth = d; \
1681 #define POP( a1, b1, a2, b2, a3, b3, d ) \
1683 a1 = buffer.bezier[i].x1; \
1684 b1 = buffer.bezier[i].y1; \
1685 a2 = buffer.bezier[i].x2; \
1686 b2 = buffer.bezier[i].y2; \
1687 a3 = buffer.bezier[i].x3; \
1688 b3 = buffer.bezier[i].y3; \
1689 d = buffer.bezier[i].depth;
1690 PUSH( x1
<<4, y1
<<4, xb
<<4, yb
<<4, x2
<<4, y2
<<4, 0 );
1693 /* de Casteljau's algorithm (see wikipedia) */
1694 POP( xl1
, yl1
, xb
, yb
, xr3
, yr3
, depth
);
1695 if( depth
< 10 ) /* check that the stack's 'i' doesn't overflow */
1697 xl2
= ( xl1
+ xb
)>>1;
1698 yl2
= ( yl1
+ yb
)>>1;
1699 xr2
= ( xb
+ xr3
)>>1;
1700 yr2
= ( yb
+ yr3
)>>1;
1701 xr1
= ( xl2
+ xr2
)>>1;
1702 yr1
= ( yl2
+ yr2
)>>1;
1705 PUSH( xl1
, yl1
, xl2
, yl2
, xl3
, yl3
, depth
+1 );
1706 PUSH( xr1
, yr1
, xr2
, yr2
, xr3
, yr3
, depth
+1 );
1710 draw_line( ((xl1
>>3)+1)>>1, ((yl1
>>3)+1)>>1,
1711 ((xr3
>>3)+1)>>1, ((yr3
>>3)+1)>>1 );
1717 else /* We have the 4 points */
1719 #define PUSH( a1, b1, a2, b2, a3, b3, a4, b4, d ) \
1720 buffer.bezier[i].x1 = a1; \
1721 buffer.bezier[i].y1 = b1; \
1722 buffer.bezier[i].x2 = a2; \
1723 buffer.bezier[i].y2 = b2; \
1724 buffer.bezier[i].x3 = a3; \
1725 buffer.bezier[i].y3 = b3; \
1726 buffer.bezier[i].x4 = a4; \
1727 buffer.bezier[i].y4 = b4; \
1728 buffer.bezier[i].depth = d; \
1730 #define POP( a1, b1, a2, b2, a3, b3, a4, b4, d ) \
1732 a1 = buffer.bezier[i].x1; \
1733 b1 = buffer.bezier[i].y1; \
1734 a2 = buffer.bezier[i].x2; \
1735 b2 = buffer.bezier[i].y2; \
1736 a3 = buffer.bezier[i].x3; \
1737 b3 = buffer.bezier[i].y3; \
1738 a4 = buffer.bezier[i].x4; \
1739 b4 = buffer.bezier[i].y4; \
1740 d = buffer.bezier[i].depth;
1742 PUSH( x1
<<4, y1
<<4, xa
<<4, ya
<<4, xb
<<4, yb
<<4, x2
<<4, y2
<<4, 0 );
1745 /* de Casteljau's algorithm (see wikipedia) */
1746 POP( xl1
, yl1
, xa
, ya
, xb
, yb
, xr4
, yr4
, depth
);
1747 if( depth
< 10 ) /* check that the stack's 'i' doesn't overflow */
1749 xl2
= ( xl1
+ xa
)>>1;
1750 yl2
= ( yl1
+ ya
)>>1;
1751 xh
= ( xa
+ xb
)>>1;
1752 yh
= ( ya
+ yb
)>>1;
1753 xr3
= ( xb
+ xr4
)>>1;
1754 yr3
= ( yb
+ yr4
)>>1;
1755 xl3
= ( xl2
+ xh
)>>1;
1756 yl3
= ( yl2
+ yh
)>>1;
1757 xr2
= ( xr3
+ xh
)>>1;
1758 yr2
= ( yr3
+ yh
)>>1;
1759 xl4
= ( xl3
+ xr2
)>>1;
1760 yl4
= ( yl3
+ yr2
)>>1;
1763 PUSH( xl1
, yl1
, xl2
, yl2
, xl3
, yl3
, xl4
, yl4
, depth
+1 );
1764 PUSH( xr1
, yr1
, xr2
, yr2
, xr3
, yr3
, xr4
, yr4
, depth
+1 );
1768 draw_line( ((xl1
>>3)+1)>>1, ((yl1
>>3)+1)>>1,
1769 ((xr4
>>3)+1)>>1, ((yr4
>>3)+1)>>1 );
1777 static void draw_rect( int x1
, int y1
, int x2
, int y2
)
1779 draw_line( x1
, y1
, x1
, y2
);
1780 draw_line( x1
, y1
, x2
, y1
);
1781 draw_line( x1
, y2
, x2
, y2
);
1782 draw_line( x2
, y1
, x2
, y2
);
1785 static void togglebg( void )
1789 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
1793 rb
->lcd_set_foreground( rp_colors
[ bgdrawcolor
] );
1798 static void draw_rect_full( int x1
, int y1
, int x2
, int y2
)
1811 draw_line( x
, y1
, x
, y2
);
1812 } while( ++x
<= x2
);
1814 draw_rect( x1
, y1
, x2
, y2
);
1817 static void draw_oval( int x1
, int y1
, int x2
, int y2
, bool full
)
1819 /* TODO: simplify :) */
1820 int cx
= (x1
+x2
)>>1;
1821 int cy
= (y1
+y2
)>>1;
1823 int rx
= (x1
-x2
)>>1;
1824 int ry
= (y1
-y2
)>>1;
1825 if( rx
< 0 ) rx
*= -1;
1826 if( ry
< 0 ) ry
*= -1;
1828 if( rx
== 0 || ry
== 0 )
1830 draw_line( x1
, y1
, x2
, y2
);
1837 for( x
= 0; x
< rx
; x
++ )
1843 dst
= ry
* ry
* x
* x
+ rx
* rx
* y
* y
- rx
* rx
* ry
* ry
;
1846 if( -old_dst
< dst
) y
--;
1849 draw_line( cx
+x
, cy
, cx
+x
, cy
+y
);
1850 draw_line( cx
+x
, cy
, cx
+x
, cy
-y
);
1851 draw_line( cx
-x
, cy
, cx
-x
, cy
+y
);
1852 draw_line( cx
-x
, cy
, cx
-x
, cy
-y
);
1856 draw_pixel( cx
+x
, cy
+y
);
1857 draw_pixel( cx
+x
, cy
-y
);
1858 draw_pixel( cx
-x
, cy
+y
);
1859 draw_pixel( cx
-x
, cy
-y
);
1862 for( y
= 0; y
< ry
; y
++ )
1868 dst
= ry
* ry
* x
* x
+ rx
* rx
* y
* y
- rx
* rx
* ry
* ry
;
1871 if( -old_dst
< dst
) x
--;
1874 draw_line( cx
+x
, cy
, cx
+x
, cy
+y
);
1875 draw_line( cx
+x
, cy
, cx
+x
, cy
-y
);
1876 draw_line( cx
-x
, cy
, cx
-x
, cy
+y
);
1877 draw_line( cx
-x
, cy
, cx
-x
, cy
-y
);
1881 draw_pixel( cx
+x
, cy
+y
);
1882 draw_pixel( cx
+x
, cy
-y
);
1883 draw_pixel( cx
-x
, cy
+y
);
1884 draw_pixel( cx
-x
, cy
-y
);
1889 static void draw_oval_empty( int x1
, int y1
, int x2
, int y2
)
1891 draw_oval( x1
, y1
, x2
, y2
, false );
1894 static void draw_oval_full( int x1
, int y1
, int x2
, int y2
)
1897 draw_oval( x1
, y1
, x2
, y2
, true );
1899 draw_oval( x1
, y1
, x2
, y2
, false );
1902 static void draw_fill( int x0
, int y0
)
1904 #define PUSH( a, b ) \
1905 draw_pixel( (int)a, (int)b ); \
1906 buffer.coord[i].x = a; \
1907 buffer.coord[i].y = b; \
1909 #define POP( a, b ) \
1911 a = buffer.coord[i].x; \
1912 b = buffer.coord[i].y;
1917 unsigned int prev_color
= save_buffer
[ x0
+y0
*COLS
];
1919 if( prev_color
== rp_colors
[ drawcolor
] ) return;
1926 if( x
> 0 && save_buffer
[x
-1+y
*COLS
] == prev_color
)
1930 if( x
< COLS
-1 && save_buffer
[x
+1+y
*COLS
] == prev_color
)
1934 if( y
> 0 && save_buffer
[x
+(y
-1)*COLS
] == prev_color
)
1938 if( y
< ROWS
- 1 && save_buffer
[x
+(y
+1)*COLS
] == prev_color
)
1948 /* For preview purposes only */
1949 static void line_gradient( int x1
, int y1
, int x2
, int y2
)
1953 int h1
, s1
, v1
, h2
, s2
, v2
, r
, g
, b
;
1966 if( w
== 0 && h
== 0 )
1968 draw_pixel( x1
>>1, y1
>>1 );
1972 r1
= RGB_UNPACK_RED( rp_colors
[ bgdrawcolor
] );
1973 g1
= RGB_UNPACK_GREEN( rp_colors
[ bgdrawcolor
] );
1974 b1
= RGB_UNPACK_BLUE( rp_colors
[ bgdrawcolor
] );
1975 r2
= RGB_UNPACK_RED( rp_colors
[ drawcolor
] );
1976 g2
= RGB_UNPACK_GREEN( rp_colors
[ drawcolor
] );
1977 b2
= RGB_UNPACK_BLUE( rp_colors
[ drawcolor
] );
2002 rgb2hsv( r1
, g1
, b1
, &h1
, &s1
, &v1
);
2003 rgb2hsv( r2
, g2
, b2
, &h2
, &s2
, &v2
);
2020 hsv2rgb( h1
+((h2
-h1
)*(x1
-x2
))/w
,
2021 s1
+((s2
-s1
)*(x1
-x2
))/w
,
2022 v1
+((v2
-v1
)*(x1
-x2
))/w
,
2024 rp_colors
[ drawcolor
] = LCD_RGBPACK( r
, g
, b
);
2025 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
2026 draw_pixel( (x1
+1)>>1, (y1
+1)>>1 );
2028 y1
= y2
- ( x2
- x1
) * h
/ w
;
2046 hsv2rgb( h1
+((h2
-h1
)*(y1
-y2
))/h
,
2047 s1
+((s2
-s1
)*(y1
-y2
))/h
,
2048 v1
+((v2
-v1
)*(y1
-y2
))/h
,
2050 rp_colors
[ drawcolor
] = LCD_RGBPACK( r
, g
, b
);
2051 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
2052 draw_pixel( (x1
+1)>>1, (y1
+1)>>1 );
2054 x1
= x2
- ( y2
- y1
) * w
/ h
;
2059 rp_colors
[ drawcolor
] = LCD_RGBPACK( r1
, g1
, b1
);
2063 rp_colors
[ drawcolor
] = LCD_RGBPACK( r2
, g2
, b2
);
2067 static void linear_gradient( int x1
, int y1
, int x2
, int y2
)
2069 int r1
= RGB_UNPACK_RED( rp_colors
[ bgdrawcolor
] );
2070 int g1
= RGB_UNPACK_GREEN( rp_colors
[ bgdrawcolor
] );
2071 int b1
= RGB_UNPACK_BLUE( rp_colors
[ bgdrawcolor
] );
2072 int r2
= RGB_UNPACK_RED( rp_colors
[ drawcolor
] );
2073 int g2
= RGB_UNPACK_GREEN( rp_colors
[ drawcolor
] );
2074 int b2
= RGB_UNPACK_BLUE( rp_colors
[ drawcolor
] );
2076 int h1
, s1
, v1
, h2
, s2
, v2
, r
, g
, b
;
2079 int radius2
= ( x1
- x2
) * ( x1
- x2
) + ( y1
- y2
) * ( y1
- y2
);
2082 /* We only propagate the gradient to neighboring pixels with the same
2083 * color as ( x1, y1 ) */
2084 unsigned int prev_color
= save_buffer
[ x1
+y1
*COLS
];
2089 if( radius2
== 0 ) return;
2092 line_gradient( x1
, y1
, x2
, y2
);
2095 rgb2hsv( r1
, g1
, b1
, &h1
, &s1
, &v1
);
2096 rgb2hsv( r2
, g2
, b2
, &h2
, &s2
, &v2
);
2098 #define PUSH( x0, y0 ) \
2099 buffer.coord[i].x = (short)(x0); \
2100 buffer.coord[i].y = (short)(y0); \
2102 #define POP( a, b ) \
2104 a = (int)buffer.coord[i].x; \
2105 b = (int)buffer.coord[i].y;
2113 dist2
= ( x2
- x1
) * ( x
- x1
) + ( y2
- y1
) * ( y
- y1
);
2116 rp_colors
[ drawcolor
] = rp_colors
[ bgdrawcolor
];
2118 else if( dist2
< radius2
)
2120 hsv2rgb( h1
+((h2
-h1
)*dist2
)/radius2
,
2121 s1
+((s2
-s1
)*dist2
)/radius2
,
2122 v1
+((v2
-v1
)*dist2
)/radius2
,
2124 rp_colors
[ drawcolor
] = LCD_RGBPACK( r
, g
, b
);
2128 rp_colors
[ drawcolor
] = LCD_RGBPACK( r2
, g2
, b2
);
2130 if( rp_colors
[ drawcolor
] == prev_color
)
2132 if( rp_colors
[ drawcolor
])
2133 rp_colors
[ drawcolor
]--; /* GRUIK */
2135 rp_colors
[ drawcolor
]++; /* GRUIK */
2137 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
2140 if( x
> 0 && save_buffer
[x
-1+y
*COLS
] == prev_color
)
2144 if( x
< COLS
-1 && save_buffer
[x
+1+y
*COLS
] == prev_color
)
2148 if( y
> 0 && save_buffer
[x
+(y
-1)*COLS
] == prev_color
)
2152 if( y
< ROWS
- 1 && save_buffer
[x
+(y
+1)*COLS
] == prev_color
)
2160 rp_colors
[ drawcolor
] = LCD_RGBPACK( r2
, g2
, b2
);
2163 static void radial_gradient( int x1
, int y1
, int x2
, int y2
)
2165 int r1
= RGB_UNPACK_RED( rp_colors
[ bgdrawcolor
] );
2166 int g1
= RGB_UNPACK_GREEN( rp_colors
[ bgdrawcolor
] );
2167 int b1
= RGB_UNPACK_BLUE( rp_colors
[ bgdrawcolor
] );
2168 int r2
= RGB_UNPACK_RED( rp_colors
[ drawcolor
] );
2169 int g2
= RGB_UNPACK_GREEN( rp_colors
[ drawcolor
] );
2170 int b2
= RGB_UNPACK_BLUE( rp_colors
[ drawcolor
] );
2172 int h1
, s1
, v1
, h2
, s2
, v2
, r
, g
, b
;
2175 int radius2
= ( x1
- x2
) * ( x1
- x2
) + ( y1
- y2
) * ( y1
- y2
);
2178 /* We only propagate the gradient to neighboring pixels with the same
2179 * color as ( x1, y1 ) */
2180 unsigned int prev_color
= save_buffer
[ x1
+y1
*COLS
];
2185 if( radius2
== 0 ) return;
2188 line_gradient( x1
, y1
, x2
, y2
);
2191 rgb2hsv( r1
, g1
, b1
, &h1
, &s1
, &v1
);
2192 rgb2hsv( r2
, g2
, b2
, &h2
, &s2
, &v2
);
2194 #define PUSH( x0, y0 ) \
2195 buffer.coord[i].x = (short)(x0); \
2196 buffer.coord[i].y = (short)(y0); \
2198 #define POP( a, b ) \
2200 a = (int)buffer.coord[i].x; \
2201 b = (int)buffer.coord[i].y;
2209 if( ( dist2
= (x1
-(x
))*(x1
-(x
))+(y1
-(y
))*(y1
-(y
)) ) < radius2
)
2211 hsv2rgb( h1
+((h2
-h1
)*dist2
)/radius2
,
2212 s1
+((s2
-s1
)*dist2
)/radius2
,
2213 v1
+((v2
-v1
)*dist2
)/radius2
,
2215 rp_colors
[ drawcolor
] = LCD_RGBPACK( r
, g
, b
);
2219 rp_colors
[ drawcolor
] = LCD_RGBPACK( r2
, g2
, b2
);
2221 if( rp_colors
[ drawcolor
] == prev_color
)
2223 if( rp_colors
[ drawcolor
])
2224 rp_colors
[ drawcolor
]--; /* GRUIK */
2226 rp_colors
[ drawcolor
]++; /* GRUIK */
2228 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
2231 if( x
> 0 && save_buffer
[x
-1+y
*COLS
] == prev_color
)
2235 if( x
< COLS
-1 && save_buffer
[x
+1+y
*COLS
] == prev_color
)
2239 if( y
> 0 && save_buffer
[x
+(y
-1)*COLS
] == prev_color
)
2243 if( y
< ROWS
- 1 && save_buffer
[x
+(y
+1)*COLS
] == prev_color
)
2251 rp_colors
[ drawcolor
] = LCD_RGBPACK( r2
, g2
, b2
);
2254 static void draw_toolbars(bool update
)
2257 #define TOP (LCD_HEIGHT-TB_HEIGHT)
2258 rb
->lcd_set_background( COLOR_LIGHTGRAY
);
2259 rb
->lcd_set_foreground( COLOR_LIGHTGRAY
);
2260 rb
->lcd_fillrect( 0, TOP
, LCD_WIDTH
, TB_HEIGHT
);
2261 rb
->lcd_set_foreground( COLOR_BLACK
);
2262 rb
->lcd_drawrect( 0, TOP
, LCD_WIDTH
, TB_HEIGHT
);
2264 rb
->lcd_set_foreground( rp_colors
[ bgdrawcolor
] );
2265 rb
->lcd_fillrect( TB_SC_BG_LEFT
, TOP
+TB_SC_BG_TOP
,
2266 TB_SC_SIZE
, TB_SC_SIZE
);
2267 rb
->lcd_set_foreground(ROCKPAINT_PALETTE
);
2268 rb
->lcd_drawrect( TB_SC_BG_LEFT
, TOP
+TB_SC_BG_TOP
,
2269 TB_SC_SIZE
, TB_SC_SIZE
);
2270 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
2271 rb
->lcd_fillrect( TB_SC_FG_LEFT
, TOP
+TB_SC_FG_TOP
,
2272 TB_SC_SIZE
, TB_SC_SIZE
);
2273 rb
->lcd_set_foreground(ROCKPAINT_PALETTE
);
2274 rb
->lcd_drawrect( TB_SC_FG_LEFT
, TOP
+TB_SC_FG_TOP
,
2275 TB_SC_SIZE
, TB_SC_SIZE
);
2277 for( i
=0; i
<18; i
++ )
2279 rb
->lcd_set_foreground( rp_colors
[i
] );
2281 TB_PL_LEFT
+(i
%9)*( TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
),
2282 TOP
+TB_PL_TOP
+(i
/9)*( TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
),
2283 TB_PL_COLOR_SIZE
, TB_PL_COLOR_SIZE
);
2284 rb
->lcd_set_foreground( ROCKPAINT_PALETTE
);
2286 TB_PL_LEFT
+(i
%9)*( TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
),
2287 TOP
+TB_PL_TOP
+(i
/9)*( TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
),
2288 TB_PL_COLOR_SIZE
, TB_PL_COLOR_SIZE
);
2291 #define SEPARATOR( x, y ) \
2292 rb->lcd_set_foreground( COLOR_WHITE ); \
2293 rb->lcd_vline( x, TOP+y, TOP+y+TB_PL_HEIGHT-1 ); \
2294 rb->lcd_set_foreground( COLOR_DARKGRAY ); \
2295 rb->lcd_vline( x+1, TOP+y, TOP+y+TB_PL_HEIGHT-1 );
2296 SEPARATOR( TB_PL_LEFT
+ TB_PL_WIDTH
- 1 + TB_SP_MARGIN
, TB_PL_TOP
);
2298 rb
->lcd_bitmap_transparent( rockpaint
, TB_TL_LEFT
, TOP
+TB_TL_TOP
,
2299 TB_TL_WIDTH
, TB_TL_HEIGHT
);
2300 rb
->lcd_set_foreground(ROCKPAINT_PALETTE
);
2301 rb
->lcd_drawrect( TB_TL_LEFT
+(TB_TL_SIZE
+TB_TL_SPACING
)*(tool
/2),
2302 TOP
+TB_TL_TOP
+(TB_TL_SIZE
+TB_TL_SPACING
)*(tool
%2),
2303 TB_TL_SIZE
, TB_TL_SIZE
);
2305 SEPARATOR( TB_TL_LEFT
+ TB_TL_WIDTH
- 1 + TB_SP_MARGIN
, TB_TL_TOP
);
2307 rb
->lcd_setfont( FONT_SYSFIXED
);
2308 rb
->lcd_putsxy( TB_MENU_LEFT
, TOP
+TB_MENU_TOP
, "Menu" );
2309 rb
->lcd_setfont( FONT_UI
);
2312 if( update
) rb
->lcd_update();
2315 static void toolbar( void )
2319 draw_toolbars( false );
2320 y
= LCD_HEIGHT
-TB_HEIGHT
/2;
2324 switch( button
= rb
->button_get( true ) )
2326 case ROCKPAINT_DRAW
:
2327 #define TOP ( LCD_HEIGHT - TB_HEIGHT )
2328 if( y
>= TOP
+ TB_SC_FG_TOP
2329 && y
< TOP
+ TB_SC_FG_TOP
+ TB_SC_SIZE
2330 && x
>= TB_SC_FG_LEFT
2331 && x
< TB_SC_FG_LEFT
+ TB_SC_SIZE
)
2333 /* click on the foreground color */
2334 rp_colors
[drawcolor
] = color_chooser( rp_colors
[drawcolor
] );
2336 else if( y
>= TOP
+ TB_SC_BG_TOP
2337 && y
< TOP
+ TB_SC_BG_TOP
+ TB_SC_SIZE
2338 && x
>= TB_SC_BG_LEFT
2339 && x
< TB_SC_BG_LEFT
+ TB_SC_SIZE
)
2341 /* click on the background color */
2343 drawcolor
= bgdrawcolor
;
2346 else if( y
>= TOP
+ TB_PL_TOP
2347 && y
< TOP
+ TB_PL_TOP
+ TB_PL_HEIGHT
2349 && x
< TB_PL_LEFT
+ TB_PL_WIDTH
)
2351 /* click on the palette */
2352 i
= (x
- TB_PL_LEFT
)%(TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
);
2353 j
= (y
- (TOP
+TB_PL_TOP
) )%(TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
);
2354 if( i
>= TB_PL_COLOR_SIZE
|| j
>= TB_PL_COLOR_SIZE
)
2356 i
= ( x
- TB_PL_LEFT
)/(TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
);
2357 j
= ( y
- (TOP
+TB_PL_TOP
) )/(TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
);
2358 drawcolor
= j
*(TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
)+i
;
2360 else if( y
>= TOP
+TB_TL_TOP
2361 && y
< TOP
+ TB_TL_TOP
+ TB_TL_HEIGHT
2363 && x
<= TB_TL_LEFT
+ TB_TL_WIDTH
)
2365 /* click on the tools */
2366 i
= (x
- TB_TL_LEFT
) % (TB_TL_SIZE
+TB_TL_SPACING
);
2367 j
= (y
- (TOP
+TB_TL_TOP
) ) %(TB_TL_SIZE
+TB_TL_SPACING
);
2368 if( i
>= TB_TL_SIZE
|| j
>= TB_TL_SIZE
) break;
2369 i
= ( x
- TB_TL_LEFT
)/(TB_TL_SIZE
+TB_TL_SPACING
);
2370 j
= ( y
- (TOP
+TB_TL_TOP
) )/(TB_TL_SIZE
+TB_TL_SPACING
);
2380 else if( x
>= TB_MENU_LEFT
&& y
>= TOP
+TB_MENU_TOP
-2)
2387 draw_toolbars( false );
2391 case ROCKPAINT_LEFT
:
2392 case ROCKPAINT_LEFT
| BUTTON_REPEAT
:
2394 x
-=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
2399 case ROCKPAINT_RIGHT
:
2400 case ROCKPAINT_RIGHT
| BUTTON_REPEAT
:
2402 x
+=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
2408 case ROCKPAINT_UP
| BUTTON_REPEAT
:
2410 y
-=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
2411 if (y
<LCD_HEIGHT
-TB_HEIGHT
)
2418 case ROCKPAINT_DOWN
:
2419 case ROCKPAINT_DOWN
| BUTTON_REPEAT
:
2421 y
+=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
2430 case ROCKPAINT_TOOLBAR
:
2431 case ROCKPAINT_TOOLBAR2
:
2438 static void inv_cursor(bool update
)
2440 rb
->lcd_set_foreground(COLOR_BLACK
);
2441 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
2442 /* cross painting */
2443 rb
->lcd_hline(x
-4,x
-1,y
);
2444 rb
->lcd_hline(x
+1,x
+4,y
);
2445 rb
->lcd_vline(x
,y
-4,y
-1);
2446 rb
->lcd_vline(x
,y
+1,y
+4);
2447 rb
->lcd_set_foreground(rp_colors
[drawcolor
]);
2448 rb
->lcd_set_drawmode(DRMODE_SOLID
);
2450 if( update
) rb
->lcd_update();
2453 static void restore_screen(void)
2455 rb
->lcd_bitmap( save_buffer
, 0, 0, COLS
, ROWS
);
2458 static void clear_drawing(void)
2461 rb
->lcd_set_foreground( rp_colors
[ bgdrawcolor
] );
2462 rb
->lcd_fillrect( 0, 0, COLS
, ROWS
);
2466 static void goto_menu(void)
2473 switch( rb
->do_menu( &main_menu
, &selected
, NULL
, false ) )
2479 case MAIN_MENU_LOAD
:
2480 if( browse( filename
, MAX_PATH
, "/" ) )
2482 if( load_bitmap( filename
) <= 0 )
2484 rb
->splashf( 1*HZ
, "Error while loading %s",
2490 rb
->splashf( 1*HZ
, "Image loaded (%s)", filename
);
2498 case MAIN_MENU_SAVE
:
2499 rb
->lcd_set_foreground(COLOR_BLACK
);
2501 rb
->strcpy(filename
,"/");
2502 if( !rb
->kbd_input( filename
, MAX_PATH
) )
2504 if( !check_extention( filename
, ".bmp" ) )
2505 rb
->strcat(filename
, ".bmp");
2506 save_bitmap( filename
);
2507 rb
->splashf( 1*HZ
, "File saved (%s)", filename
);
2511 case MAIN_MENU_BRUSH_SIZE
:
2512 for(multi
= 0; multi
<4; multi
++)
2513 if(bsize
== times_list
[multi
]) break;
2514 rb
->set_option( "Brush Size", &multi
, INT
, times_options
, 4, NULL
);
2516 bsize
= times_list
[multi
];
2519 case MAIN_MENU_BRUSH_SPEED
:
2520 for(multi
= 0; multi
<3; multi
++)
2521 if(bspeed
== times_list
[multi
]) break;
2522 rb
->set_option( "Brush Speed", &multi
, INT
, times_options
, 3, NULL
);
2524 bspeed
= times_list
[multi
];
2527 case MAIN_MENU_COLOR
:
2528 rp_colors
[drawcolor
] = color_chooser( rp_colors
[drawcolor
] );
2531 case MAIN_MENU_GRID_SIZE
:
2532 for(multi
= 0; multi
<4; multi
++)
2533 if(gridsize
== gridsize_list
[multi
]) break;
2534 rb
->set_option( "Grid Size", &multi
, INT
, gridsize_options
, 4, NULL
);
2536 gridsize
= gridsize_list
[multi
];
2539 case MAIN_MENU_PLAYBACK_CONTROL
:
2540 playback_control( NULL
);
2543 case MAIN_MENU_EXIT
:
2548 case MAIN_MENU_RESUME
:
2556 static void reset_tool( void )
2568 static bool rockpaint_loop( void )
2580 button
= rb
->button_get(true);
2582 if( tool
== Brush
&& prev_x
!= -1 )
2586 else if( button
& BUTTON_REPEAT
)
2597 case ROCKPAINT_QUIT
:
2598 rb
->lcd_set_drawmode(DRMODE_SOLID
);
2601 case ROCKPAINT_MENU
:
2608 case ROCKPAINT_DRAW
:
2613 if( prev_x
== -1 ) prev_x
= 1;
2617 case SelectRectangle
:
2624 case LinearGradient
:
2625 case RadialGradient
:
2626 /* Curve uses 4 points, others use 2 */
2627 if( prev_x
== -1 || prev_y
== -1 )
2633 else if( tool
== Curve
2634 && ( prev_x2
== -1 || prev_y2
== -1 ) )
2639 else if( tool
== SelectRectangle
2640 && ( prev_x2
== -1 || prev_y2
== -1 ) )
2642 tool_mode
= rb
->do_menu( &select_menu
,
2643 NULL
, NULL
, false );
2646 case SELECT_MENU_CUT
:
2647 case SELECT_MENU_COPY
:
2650 copy_to_clipboard();
2651 if( prev_x
< x
) x
= prev_x
;
2652 if( prev_y
< y
) y
= prev_y
;
2655 case SELECT_MENU_INVERT
:
2656 draw_invert( prev_x
, prev_y
, x
, y
);
2660 case SELECT_MENU_HFLIP
:
2661 draw_hflip( prev_x
, prev_y
, x
, y
);
2665 case SELECT_MENU_VFLIP
:
2666 draw_vflip( prev_x
, prev_y
, x
, y
);
2670 case SELECT_MENU_ROTATE90
:
2671 draw_rot_90_deg( prev_x
, prev_y
, x
, y
, 1 );
2675 case SELECT_MENU_ROTATE180
:
2676 draw_hflip( prev_x
, prev_y
, x
, y
);
2677 draw_vflip( prev_x
, prev_y
, x
, y
);
2681 case SELECT_MENU_ROTATE270
:
2682 draw_rot_90_deg( prev_x
, prev_y
, x
, y
, -1 );
2686 case SELECT_MENU_CANCEL
:
2695 else if( tool
== Curve
2696 && ( prev_x3
== -1 || prev_y3
== -1 ) )
2706 case SelectRectangle
:
2707 draw_paste_rectangle( prev_x
, prev_y
,
2712 draw_line( prev_x
, prev_y
, x
, y
);
2715 draw_curve( prev_x
, prev_y
,
2721 draw_rect( prev_x
, prev_y
, x
, y
);
2724 draw_rect_full( prev_x
, prev_y
, x
, y
);
2727 draw_oval_empty( prev_x
, prev_y
, x
, y
);
2730 draw_oval_full( prev_x
, prev_y
, x
, y
);
2732 case LinearGradient
:
2733 linear_gradient( prev_x
, prev_y
, x
, y
);
2735 case RadialGradient
:
2736 radial_gradient( prev_x
, prev_y
, x
, y
);
2750 color_picker( x
, y
);
2763 case ROCKPAINT_DRAW
|BUTTON_REPEAT
:
2766 /* 3 point bezier curve */
2768 draw_curve( prev_x
, prev_y
,
2778 case ROCKPAINT_TOOLBAR
:
2787 case ROCKPAINT_TOOLBAR2
:
2796 case ROCKPAINT_LEFT
:
2797 case ROCKPAINT_LEFT
| BUTTON_REPEAT
:
2799 x
-=bspeed
* accelaration
;
2804 case ROCKPAINT_RIGHT
:
2805 case ROCKPAINT_RIGHT
| BUTTON_REPEAT
:
2807 x
+=bspeed
* accelaration
;
2813 case ROCKPAINT_UP
| BUTTON_REPEAT
:
2815 y
-=bspeed
* accelaration
;
2820 case ROCKPAINT_DOWN
:
2821 case ROCKPAINT_DOWN
| BUTTON_REPEAT
:
2823 y
+=bspeed
* accelaration
;
2833 if (rb
->default_event_handler(button
) == SYS_USB_CONNECTED
)
2834 return PLUGIN_USB_CONNECTED
;
2837 if( tool
== Brush
&& prev_x
== 1 )
2843 if( preview
|| tool
== ColorPicker
)
2844 /* always preview color picker */
2849 case SelectRectangle
:
2850 if( prev_x2
== -1 || prev_y2
== -1 )
2852 /* we are defining the selection */
2853 draw_select_rectangle( prev_x
, prev_y
, x
, y
);
2857 /* we are pasting the selected data */
2858 draw_paste_rectangle( prev_x
, prev_y
, prev_x2
,
2859 prev_y2
, x
, y
, tool_mode
);
2860 prev_x3
= prev_x2
-prev_x
;
2861 if( prev_x3
< 0 ) prev_x3
*= -1;
2862 prev_y3
= prev_y2
-prev_y
;
2863 if( prev_y3
< 0 ) prev_y3
*= -1;
2864 draw_select_rectangle( x
, y
, x
+prev_x3
, y
+prev_y3
);
2874 draw_line( prev_x
, prev_y
, x
, y
);
2878 if( prev_x2
== -1 || prev_y2
== -1 )
2880 draw_line( prev_x
, prev_y
, x
, y
);
2884 draw_curve( prev_x
, prev_y
,
2892 draw_rect( prev_x
, prev_y
, x
, y
);
2896 draw_rect_full( prev_x
, prev_y
, x
, y
);
2900 draw_oval_empty( prev_x
, prev_y
, x
, y
);
2904 draw_oval_full( prev_x
, prev_y
, x
, y
);
2912 color_picker( x
, y
);
2916 case LinearGradient
:
2917 line_gradient( prev_x
, prev_y
, x
, y
);
2920 case RadialGradient
:
2921 line_gradient( prev_x
, prev_y
, x
, y
);
2940 static int load_bitmap( const char *file
)
2945 fb_data color
= rp_colors
[ bgdrawcolor
];
2947 bm
.data
= (char*)save_buffer
;
2948 ret
= rb
->read_bmp_file( file
, &bm
, ROWS
*COLS
*sizeof( fb_data
),
2949 FORMAT_NATIVE
, NULL
);
2951 if((bm
.width
> COLS
) || ( bm
.height
> ROWS
))
2954 for( i
= bm
.height
-1; i
>= 0; i
-- )
2956 rb
->memmove( save_buffer
+i
*COLS
, save_buffer
+i
*bm
.width
,
2957 sizeof( fb_data
)*bm
.width
);
2958 for( j
= bm
.width
; j
< COLS
; j
++ )
2959 save_buffer
[j
+i
*COLS
] = color
;
2961 for( i
= bm
.height
*COLS
; i
< ROWS
*COLS
; i
++ )
2962 save_buffer
[i
] = color
;
2967 static int save_bitmap( char *file
)
2970 bm
.data
= (char*)save_buffer
;
2973 bm
.format
= FORMAT_NATIVE
;
2974 return save_bmp_file( file
, &bm
);
2977 enum plugin_status
plugin_start(const void* parameter
)
2979 rb
->lcd_set_foreground(COLOR_WHITE
);
2980 rb
->lcd_set_backdrop(NULL
);
2981 rb
->lcd_fillrect(0,0,LCD_WIDTH
,LCD_HEIGHT
);
2982 rb
->splash( HZ
/2, "Rock Paint");
2984 rb
->lcd_clear_display();
2990 if( load_bitmap( parameter
) <= 0 )
2992 rb
->splash( 1*HZ
, "File Open Error");
2997 rb
->splashf( 1*HZ
, "Image loaded (%s)", (char *)parameter
);
2999 rb
->strcpy( filename
, parameter
);
3008 return rockpaint_loop();