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 == ONDAVX777_PAD )
163 #define ROCKPAINT_QUIT BUTTON_POWER
165 #elif CONFIG_KEYPAD == MROBE500_PAD
166 #define ROCKPAINT_QUIT BUTTON_POWER
168 #elif ( CONFIG_KEYPAD == SAMSUNG_YH_PAD )
169 #define ROCKPAINT_QUIT BUTTON_REC
170 #define ROCKPAINT_DRAW BUTTON_PLAY
171 #define ROCKPAINT_MENU BUTTON_FFWD
172 #define ROCKPAINT_TOOLBAR BUTTON_REW
173 #define ROCKPAINT_TOOLBAR2 ( BUTTON_REW | BUTTON_LEFT )
174 #define ROCKPAINT_UP BUTTON_UP
175 #define ROCKPAINT_DOWN BUTTON_DOWN
176 #define ROCKPAINT_LEFT BUTTON_LEFT
177 #define ROCKPAINT_RIGHT BUTTON_RIGHT
180 #error "Please define keys for this keypad"
183 #ifdef HAVE_TOUCHSCREEN
184 #ifndef ROCKPAINT_QUIT
185 #define ROCKPAINT_QUIT BUTTON_TOPLEFT
187 #ifndef ROCKPAINT_DRAW
188 #define ROCKPAINT_DRAW BUTTON_CENTER
190 #ifndef ROCKPAINT_MENU
191 #define ROCKPAINT_MENU BUTTON_TOPRIGHT
193 #ifndef ROCKPAINT_TOOLBAR
194 #define ROCKPAINT_TOOLBAR BUTTON_BOTTOMLEFT
196 #ifndef ROCKPAINT_TOOLBAR2
197 #define ROCKPAINT_TOOLBAR2 BUTTON_BOTTOMRIGHT
200 #define ROCKPAINT_UP BUTTON_TOPMIDDLE
202 #ifndef ROCKPAINT_DOWN
203 #define ROCKPAINT_DOWN BUTTON_BOTTOMMIDDLE
205 #ifndef ROCKPAINT_LEFT
206 #define ROCKPAINT_LEFT BUTTON_MIDLEFT
208 #ifndef ROCKPAINT_RIGHT
209 #define ROCKPAINT_RIGHT BUTTON_MIDRIGHT
213 /***********************************************************************
214 * Palette Default Colors
215 ***********************************************************************/
216 #define COLOR_BLACK LCD_RGBPACK(0,0,0)
217 #define COLOR_WHITE LCD_RGBPACK(255,255,255)
218 #define COLOR_DARKGRAY LCD_RGBPACK(128,128,128)
219 #define COLOR_LIGHTGRAY LCD_RGBPACK(192,192,192)
220 #define COLOR_RED LCD_RGBPACK(128,0,0)
221 #define COLOR_LIGHTRED LCD_RGBPACK(255,0,0)
222 #define COLOR_DARKYELLOW LCD_RGBPACK(128,128,0)
223 #define COLOR_YELLOW LCD_RGBPACK(255,255,0)
224 #define COLOR_GREEN LCD_RGBPACK(0,128,0)
225 #define COLOR_LIGHTGREN LCD_RGBPACK(0,255,0)
226 #define COLOR_CYAN LCD_RGBPACK(0,128,128)
227 #define COLOR_LIGHTCYAN LCD_RGBPACK(0,255,255)
228 #define COLOR_BLUE LCD_RGBPACK(0,0,128)
229 #define COLOR_LIGHTBLUE LCD_RGBPACK(0,0,255)
230 #define COLOR_PURPLE LCD_RGBPACK(128,0,128)
231 #define COLOR_PINK LCD_RGBPACK(255,0,255)
232 #define COLOR_BROWN LCD_RGBPACK(128,64,0)
233 #define COLOR_LIGHTBROWN LCD_RGBPACK(255,128,64)
235 #define SPLASH_SCREEN PLUGIN_APPS_DIR "/rockpaint/splash.bmp"
236 #define ROCKPAINT_TITLE_FONT 2
238 /***********************************************************************
240 ***********************************************************************/
241 #define ROCKPAINT_PALETTE LCD_RGBPACK(0,64,128)
242 #define ROCKPAINT_SELECTED LCD_RGBPACK(128,192,255)
244 #define ROWS LCD_HEIGHT
245 #define COLS LCD_WIDTH
248 * Toolbar positioning stuff ... don't read this unless you really need to
257 /* Separator sizes */
258 #define TB_SP_MARGIN 3
259 #define TB_SP_WIDTH (2+2*TB_SP_MARGIN)
261 /* Selected color sizes */
262 #define TB_SC_SIZE 12
265 #define TB_PL_COLOR_SIZE 7
266 #define TB_PL_COLOR_SPACING 2
267 #define TB_PL_WIDTH ( 9 * TB_PL_COLOR_SIZE + 8 * TB_PL_COLOR_SPACING )
268 #define TB_PL_HEIGHT ( TB_PL_COLOR_SIZE * 2 + TB_PL_COLOR_SPACING )
272 #define TB_TL_SPACING 2
273 #define TB_TL_WIDTH ( 7 * ( TB_TL_SIZE + TB_TL_SPACING ) - TB_TL_SPACING )
274 #define TB_TL_HEIGHT ( 2 * TB_TL_SIZE + TB_TL_SPACING )
276 /* Menu button size ... gruik */
277 #define TB_MENU_MIN_WIDTH 30
279 /* Selected colors position */
280 #define TB_SC_FG_TOP 2
281 #define TB_SC_FG_LEFT 2
282 #define TB_SC_BG_TOP (TB_SC_FG_TOP+TB_PL_COLOR_SIZE*2+TB_PL_COLOR_SPACING-TB_SC_SIZE)
283 #define TB_SC_BG_LEFT (TB_SC_FG_LEFT+TB_PL_COLOR_SIZE*2+TB_PL_COLOR_SPACING-TB_SC_SIZE)
285 /* Palette position */
286 #define TB_PL_TOP TB_SC_FG_TOP
287 #define TB_PL_LEFT (TB_SC_BG_LEFT + TB_SC_SIZE + TB_PL_COLOR_SPACING)
290 #define TB_TL_TOP TB_SC_FG_TOP
291 #define TB_TL_LEFT ( TB_PL_LEFT + TB_PL_WIDTH-1 + TB_SP_WIDTH )
293 #if TB_TL_LEFT + TB_TL_WIDTH + TB_MENU_MIN_WIDTH >= LCD_WIDTH
296 #define TB_TL_TOP ( TB_PL_TOP + TB_PL_HEIGHT + 4 )
297 #define TB_TL_LEFT TB_SC_FG_LEFT
300 /* Menu button position */
301 #define TB_MENU_TOP ( TB_TL_TOP + (TB_TL_HEIGHT-8)/2 )
302 #define TB_MENU_LEFT ( TB_TL_LEFT + TB_TL_WIDTH-1 + TB_SP_WIDTH )
304 #define TB_HEIGHT ( TB_TL_TOP + TB_TL_HEIGHT + 1 )
307 static void draw_pixel(int x
,int y
);
308 static void draw_line( int x1
, int y1
, int x2
, int y2
);
309 static void draw_rect( int x1
, int y1
, int x2
, int y2
);
310 static void draw_toolbars(bool update
);
311 static void inv_cursor(bool update
);
312 static void restore_screen(void);
313 static void clear_drawing(void);
314 static void goto_menu(void);
315 static int load_bitmap( const char *filename
);
316 static int save_bitmap( char *filename
);
317 static void draw_rect_full( int x1
, int y1
, int x2
, int y2
);
319 /***********************************************************************
321 ***********************************************************************/
323 static int drawcolor
=0; /* Current color (in palette) */
324 static int bgdrawcolor
=9; /* Current background color (in palette) */
325 static int img_height
= ROWS
;
326 static int img_width
= COLS
;
327 bool isbg
= false; /* gruik ugly hack alert */
329 static int preview
=false; /* Is preview mode on ? */
331 /* TODO: clean this up */
332 static int x
=0, y
=0; /* cursor position */
333 static int prev_x
=-1, prev_y
=-1; /* previous saved cursor position */
334 static int prev_x2
=-1, prev_y2
=-1;
335 static int prev_x3
=-1, prev_y3
=-1;
336 static int tool_mode
=-1;
339 static int bsize
=1; /* brush size */
340 static int bspeed
=1; /* brush speed */
342 enum Tools
{ Brush
= 0, /* Regular brush */
343 Fill
= 1, /* Fill a shape with current color */
345 ColorPicker
= 3, /* Pick a color */
346 Line
= 4, /* Draw a line between two points */
347 Unused
= 5, /* THIS IS UNUSED ... */
350 Rectangle
= 8, /* Draw a rectangle */
352 Oval
= 10, /* Draw an oval */
358 enum Tools tool
= Brush
;
360 static bool quit
=false;
361 static int gridsize
=0;
363 static fb_data rp_colors
[18] =
365 COLOR_BLACK
, COLOR_DARKGRAY
, COLOR_RED
, COLOR_DARKYELLOW
,
366 COLOR_GREEN
, COLOR_CYAN
, COLOR_BLUE
, COLOR_PURPLE
, COLOR_BROWN
,
367 COLOR_WHITE
, COLOR_LIGHTGRAY
, COLOR_LIGHTRED
, COLOR_YELLOW
,
368 COLOR_LIGHTGREN
, COLOR_LIGHTCYAN
, COLOR_LIGHTBLUE
, COLOR_PINK
,
372 static fb_data save_buffer
[ ROWS
*COLS
];
374 extern fb_data rockpaint
[];
375 extern fb_data rockpaint_hsvrgb
[];
377 /* Maximum string size allowed for the text tool */
382 /* Used by fill and gradient algorithms */
387 } coord
[ ROWS
*COLS
];
389 /* Used by bezier curve algorithms */
397 } bezier
[ (ROWS
*COLS
)/5 ]; /* We have 4.5 times more data per struct
398 * than coord ... so we divide to take
401 /* Used to cut/copy/paste data */
402 fb_data clipboard
[ ROWS
*COLS
];
404 /* Used for text mode */
409 char old_font
[MAX_PATH
];
412 char fontname_buf
[30][MAX_PATH
];
416 /* Current filename */
417 static char filename
[MAX_PATH
];
419 /* Font preview buffer */
420 //#define FONT_PREVIEW_WIDTH ((LCD_WIDTH-30)/8)
421 //#define FONT_PREVIEW_HEIGHT 1000
422 //static unsigned char fontpreview[FONT_PREVIEW_WIDTH*FONT_PREVIEW_HEIGHT];
424 /***********************************************************************
425 * Offscreen buffer/Text/Fonts handling
427 * Parts of code taken from firmware/drivers/lcd-16bit.c
428 ***********************************************************************/
429 static void buffer_mono_bitmap_part(
430 fb_data
*buf
, int buf_width
, int buf_height
,
431 const unsigned char *src
, int src_x
, int src_y
,
432 int stride
, int x
, int y
, int width
, int height
)
433 /* this function only draws the foreground part of the bitmap */
435 const unsigned char *src_end
;
436 fb_data
*dst
, *dst_end
;
437 unsigned fgcolor
= rb
->lcd_get_foreground();
439 /* nothing to draw? */
440 if( ( width
<= 0 ) || ( height
<= 0 ) || ( x
>= buf_width
)
441 || ( y
>= buf_height
) || ( x
+ width
<= 0 ) || ( y
+ height
<= 0 ) )
457 if( x
+ width
> buf_width
)
458 width
= buf_width
- x
;
459 if( y
+ height
> buf_height
)
460 height
= buf_height
- y
;
462 src
+= stride
* (src_y
>> 3) + src_x
; /* move starting point */
464 src_end
= src
+ width
;
466 dst
= buf
+ y
*buf_width
+ x
;
470 const unsigned char *src_col
= src
++;
471 unsigned data
= *src_col
>> src_y
;
472 fb_data
*dst_col
= dst
++;
473 int numbits
= 8 - src_y
;
475 dst_end
= dst_col
+ height
* buf_width
;
479 *dst_col
= fgcolor
; /* FIXME ? */
481 dst_col
+= buf_width
;
490 } while( dst_col
< dst_end
);
491 } while( src
< src_end
);
494 static void buffer_putsxyofs( fb_data
*buf
, int buf_width
, int buf_height
,
495 int x
, int y
, int ofs
, const unsigned char *str
)
500 struct font
*pf
= rb
->font_get( FONT_UI
);
501 if( !pf
) pf
= rb
->font_get( FONT_SYSFIXED
);
503 ucs
= rb
->bidi_l2v( str
, 1 );
505 while( (ch
= *ucs
++) != 0 && x
< buf_width
)
508 const unsigned char *bits
;
510 /* get proportional width and glyph bits */
511 width
= rb
->font_get_width( pf
, ch
);
519 bits
= rb
->font_get_bits( pf
, ch
);
521 buffer_mono_bitmap_part( buf
, buf_width
, buf_height
, bits
, ofs
, 0,
522 width
, x
, y
, width
- ofs
, pf
->height
);
529 /***********************************************************************
531 ***********************************************************************/
535 MAIN_MENU_NEW
, MAIN_MENU_LOAD
, MAIN_MENU_SAVE
,
536 MAIN_MENU_SET_WIDTH
, MAIN_MENU_SET_HEIGHT
,
537 MAIN_MENU_BRUSH_SIZE
, MAIN_MENU_BRUSH_SPEED
, MAIN_MENU_COLOR
,
539 MAIN_MENU_PLAYBACK_CONTROL
,
543 /* Select action menu */
544 SELECT_MENU_CUT
, SELECT_MENU_COPY
,
545 SELECT_MENU_INVERT
, SELECT_MENU_HFLIP
, SELECT_MENU_VFLIP
,
546 SELECT_MENU_ROTATE90
, SELECT_MENU_ROTATE180
, SELECT_MENU_ROTATE270
,
551 TEXT_MENU_TEXT
, TEXT_MENU_FONT
,
552 TEXT_MENU_PREVIEW
, TEXT_MENU_APPLY
, TEXT_MENU_CANCEL
,
555 MENUITEM_STRINGLIST(main_menu
, "RockPaint", NULL
,
556 "Resume", "New", "Load", "Save",
557 "Set Width", "Set Height",
558 "Brush Size", "Brush Speed",
559 "Choose Color", "Grid Size",
560 "Playback Control", "Exit");
561 MENUITEM_STRINGLIST(select_menu
, "Select...", NULL
,
563 "Invert", "Horizontal Flip", "Vertical Flip",
564 "Rotate 90°", "Rotate 180°", "Rotate 270°",
566 MENUITEM_STRINGLIST(text_menu
, "Text", NULL
,
567 "Set Text", "Change Font",
568 "Preview", "Apply", "Cancel");
569 static const int times_list
[] = { 1, 2, 4, 8 };
570 static const int gridsize_list
[] = { 0, 5, 10, 20 };
571 static const struct opt_items times_options
[] = {
572 { "1x", -1 }, { "2x", -1 }, { "4x", -1 }, { "8x", -1 }
574 static const struct opt_items gridsize_options
[] = {
575 { "No grid", -1 }, { "5px", -1 }, { "10px", -1 }, { "20px", -1 }
578 static int draw_window( int height
, int width
,
583 rb
->lcd_getstringsize( title
, NULL
, &fh
);
586 const int _top
= ( LCD_HEIGHT
- height
) / 2;
587 const int _left
= ( LCD_WIDTH
- width
) / 2;
588 if( top
) *top
= _top
;
589 if( left
) *left
= _left
;
590 rb
->lcd_set_background(COLOR_BLUE
);
591 rb
->lcd_set_foreground(COLOR_LIGHTGRAY
);
592 rb
->lcd_fillrect( _left
, _top
, width
, height
);
593 rb
->lcd_set_foreground(COLOR_BLUE
);
594 rb
->lcd_fillrect( _left
, _top
, width
, fh
+4 );
595 rb
->lcd_set_foreground(COLOR_WHITE
);
596 rb
->lcd_putsxy( _left
+2, _top
+2, title
);
597 rb
->lcd_set_foreground(COLOR_BLACK
);
598 rb
->lcd_drawrect( _left
, _top
, width
, height
);
602 /***********************************************************************
604 ***********************************************************************/
606 char bbuf
[MAX_PATH
]; /* used by file and font browsers */
607 char bbuf_s
[MAX_PATH
]; /* used by file and font browsers */
608 struct tree_context
*tree
= NULL
;
610 static bool check_extention(const char *filename
, const char *ext
)
612 const char *p
= rb
->strrchr( filename
, '.' );
613 return ( p
!= NULL
&& !rb
->strcasecmp( p
, ext
) );
616 static const char* browse_get_name_cb(int selected_item
, void *data
,
617 char *buffer
, size_t buffer_len
)
619 int *indexes
= (int *) data
;
620 struct entry
* dc
= tree
->dircache
;
621 struct entry
* e
= &dc
[indexes
[selected_item
]];
628 static bool browse( char *dst
, int dst_size
, const char *start
)
630 struct gui_synclist browse_list
;
631 int item_count
= 0, selected
, button
;
632 struct tree_context backup
;
635 int dirfilter
= SHOW_ALL
;
636 int *indexes
= (int *) buffer
.clipboard
;
640 rb
->strcpy( bbuf
, start
);
641 a
= bbuf
+rb
->strlen(bbuf
)-1;
649 rb
->gui_synclist_init(&browse_list
, browse_get_name_cb
,
650 (void*) indexes
, false, 1, NULL
);
652 tree
= rb
->tree_get_context();
655 a
= backup
.currdir
+rb
->strlen(backup
.currdir
)-1;
661 rb
->strcpy( a
, dc
[tree
->selected_item
].name
);
662 tree
->dirfilter
= &dirfilter
;
668 rb
->set_current_file(bbuf
);
671 for( i
= 0; i
< tree
->filesindir
; i
++)
673 /* only displayes directories and .bmp files */
674 if( ((dc
[i
].attr
& ATTR_DIRECTORY
) &&
675 rb
->strcmp( dc
[i
].name
, "." ) &&
676 rb
->strcmp( dc
[i
].name
, ".." )) ||
677 ( !(dc
[i
].attr
& ATTR_DIRECTORY
) &&
678 check_extention( dc
[i
].name
, ".bmp" ) ) )
680 if( !rb
->strcmp( dc
[i
].name
, bbuf_s
) )
681 selected
= item_count
;
682 indexes
[item_count
++] = i
;
686 rb
->gui_synclist_set_nb_items(&browse_list
,item_count
);
687 rb
->gui_synclist_select_item(&browse_list
, selected
);
688 rb
->gui_synclist_set_title(&browse_list
, bbuf
, NOICON
);
689 rb
->gui_synclist_draw(&browse_list
);
692 button
= rb
->get_action(CONTEXT_LIST
,TIMEOUT_BLOCK
);
693 if (rb
->gui_synclist_do_button(&browse_list
,&button
,LIST_WRAP_UNLESS_HELD
))
697 case ACTION_STD_CANCEL
:
698 if( !rb
->strcmp( bbuf
, "/" ) )
701 rb
->set_current_file( backup
.currdir
);
704 rb
->strcpy( bbuf_s
, ".." );
706 if( button
== ACTION_STD_OK
)
708 selected
= rb
->gui_synclist_get_sel_pos( &browse_list
);
709 if( selected
< 0 || selected
>= item_count
)
711 struct entry
* e
= &dc
[indexes
[selected
]];
712 rb
->strlcpy( bbuf_s
, e
->name
, sizeof( bbuf_s
) );
713 if( !( e
->attr
& ATTR_DIRECTORY
) )
716 rb
->set_current_file( backup
.currdir
);
717 rb
->snprintf( dst
, dst_size
, "%s%s", bbuf
, bbuf_s
);
721 if( !rb
->strcmp( bbuf_s
, "." ) ) break;
722 a
= bbuf
+rb
->strlen(bbuf
);
723 if( !rb
->strcmp( bbuf_s
, ".." ) )
726 if( a
== bbuf
) break;
728 while( *a
!= '/' ) a
--;
729 rb
->strcpy( bbuf_s
, ++a
);
730 /* select parent directory */
731 bbuf_s
[rb
->strlen(bbuf_s
)-1] = '\0';
736 rb
->snprintf( a
, bbuf
+sizeof(bbuf
)-a
, "%s/", bbuf_s
);
740 case ACTION_STD_MENU
:
742 rb
->set_current_file( backup
.currdir
);
748 /***********************************************************************
751 * FIXME: This still needs some work ... it currently only works fine
752 * on the simulators, disk spins too much on real targets -> rendered
753 * font buffer needed.
754 ***********************************************************************/
755 static bool browse_fonts( char *dst
, int dst_size
)
757 #define WIDTH ( LCD_WIDTH - 20 )
758 #define HEIGHT ( LCD_HEIGHT - 20 )
760 int top
, top_inside
= 0, left
;
764 int fvi
= 0; /* first visible item */
765 int lvi
= 0; /* last visible item */
766 int si
= 0; /* selected item */
767 int osi
= 0; /* old selected item */
768 int li
= 0; /* last item */
769 int nvih
= 0; /* next visible item height */
771 int b_need_redraw
= 1; /* Do we need to redraw ? */
773 int cp
= 0; /* current position */
774 int fh
; /* font height */
776 #define fh_buf buffer.text.fh_buf /* 30 might not be enough ... */
777 #define fw_buf buffer.text.fw_buf
779 #define fontname_buf buffer.text.fontname_buf
781 rb
->snprintf( buffer
.text
.old_font
, MAX_PATH
,
783 rb
->global_settings
->font_file
);
789 /* we don't need to redraw ... but we need to unselect
790 * the previously selected item */
791 cp
= top_inside
+ LINE_SPACE
;
792 for( i
= 0; i
+fvi
< osi
; i
++ )
794 cp
+= fh_buf
[i
] + LINE_SPACE
;
796 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
797 rb
->lcd_fillrect( left
+10, cp
, fw_buf
[i
], fh_buf
[i
] );
798 rb
->lcd_set_drawmode(DRMODE_SOLID
);
805 d
= rb
->opendir( FONT_DIR
"/" );
810 top_inside
= draw_window( HEIGHT
, WIDTH
, &top
, &left
, "Fonts" );
818 cp
= top_inside
+LINE_SPACE
;
820 rb
->lcd_set_foreground(COLOR_BLACK
);
821 rb
->lcd_set_background(COLOR_LIGHTGRAY
);
823 while( cp
< top
+HEIGHT
)
825 de
= rb
->readdir( d
);
831 if( !check_extention( de
->d_name
, ".fnt" ) )
833 rb
->snprintf( bbuf
, MAX_PATH
, FONT_DIR
"/%s",
835 rb
->font_load( bbuf
);
836 rb
->font_getstringsize( de
->d_name
, &fw
, &fh
, FONT_UI
);
841 if( nvih
< 0 ) nvih
= 0;
845 if( cp
+ fh
>= top
+HEIGHT
)
850 rb
->lcd_putsxy( left
+10, cp
, de
->d_name
);
853 cp
+= fh
+ LINE_SPACE
;
854 rb
->strcpy( fontname_buf
[i
-fvi
], bbuf
);
860 if( !(de
= rb
->readdir( d
) ) )
864 else if( !nvih
&& check_extention( de
->d_name
, ".fnt" ) )
866 rb
->snprintf( bbuf
, MAX_PATH
, FONT_DIR
"/%s",
868 rb
->font_load( bbuf
);
869 rb
->font_getstringsize( de
->d_name
, NULL
, &fh
, FONT_UI
);
873 rb
->font_load( buffer
.text
.old_font
);
877 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
878 cp
= top_inside
+ LINE_SPACE
;
879 for( i
= 0; i
+fvi
< si
; i
++ )
881 cp
+= fh_buf
[i
] + LINE_SPACE
;
883 rb
->lcd_fillrect( left
+10, cp
, fw_buf
[i
], fh_buf
[i
] );
884 rb
->lcd_set_drawmode(DRMODE_SOLID
);
886 rb
->lcd_update_rect( left
, top
, WIDTH
, HEIGHT
);
890 switch( rb
->button_get(true) )
893 case ROCKPAINT_UP
|BUTTON_REPEAT
:
905 case ROCKPAINT_DOWN
|BUTTON_REPEAT
:
906 if( li
== -1 || si
< li
)
915 case ROCKPAINT_RIGHT
:
917 rb
->snprintf( dst
, dst_size
, "%s", fontname_buf
[si
-fvi
] );
921 if( i
!= fvi
|| si
> lvi
)
939 /***********************************************************************
940 * HSVRGB Color chooser
941 ***********************************************************************/
942 static unsigned int color_chooser( unsigned int color
)
944 int red
= RGB_UNPACK_RED( color
);
945 int green
= RGB_UNPACK_GREEN( color
);
946 int blue
= RGB_UNPACK_BLUE( color
);
947 int hue
, saturation
, value
;
948 int r
, g
, b
; /* temp variables */
951 enum BaseColor
{ Hue
= 0, Saturation
= 1, Value
= 2,
952 Red
= 3, Green
= 4, Blue
= 5 };
953 enum BaseColor current
= Red
;
960 rgb2hsv( red
, green
, blue
, &hue
, &saturation
, &value
);
965 color
= LCD_RGBPACK( red
, green
, blue
);
967 #define HEIGHT ( 100 )
968 #define WIDTH ( 150 )
970 top
= draw_window( HEIGHT
, WIDTH
, NULL
, &left
, "Color chooser" );
973 for( i
=0; i
<100; i
++ )
975 hsv2rgb( i
*36, saturation
, value
, &r
, &g
, &b
);
976 rb
->lcd_set_foreground( LCD_RGBPACK( r
, g
, b
) );
977 rb
->lcd_vline( left
+15+i
, top
+20, top
+27 );
978 hsv2rgb( hue
, i
*255/100, value
, &r
, &g
, &b
);
979 rb
->lcd_set_foreground( LCD_RGBPACK( r
, g
, b
) );
980 rb
->lcd_vline( left
+15+i
, top
+30, top
+37 );
981 hsv2rgb( hue
, saturation
, i
*255/100, &r
, &g
, &b
);
982 rb
->lcd_set_foreground( LCD_RGBPACK( r
, g
, b
) );
983 rb
->lcd_vline( left
+15+i
, top
+40, top
+47 );
984 rb
->lcd_set_foreground( LCD_RGBPACK( i
*255/100, green
, blue
) );
985 rb
->lcd_vline( left
+15+i
, top
+50, top
+57 );
986 rb
->lcd_set_foreground( LCD_RGBPACK( red
, i
*255/100, blue
) );
987 rb
->lcd_vline( left
+15+i
, top
+60, top
+67 );
988 rb
->lcd_set_foreground( LCD_RGBPACK( red
, green
, i
*255/100 ) );
989 rb
->lcd_vline( left
+15+i
, top
+70, top
+77 );
992 rb
->lcd_set_foreground(COLOR_BLACK
);
993 #define POSITION( a, i ) \
994 rb->lcd_drawpixel( left+14+i, top + 19 + a ); \
995 rb->lcd_drawpixel( left+16+i, top + 19 + a ); \
996 rb->lcd_drawpixel( left+14+i, top + 28 + a ); \
997 rb->lcd_drawpixel( left+16+i, top + 28 + a );
998 POSITION( 0, hue
/36 );
999 POSITION( 10, saturation
*99/255 );
1000 POSITION( 20, value
*99/255 );
1001 POSITION( 30, red
*99/255 );
1002 POSITION( 40, green
*99/255 );
1003 POSITION( 50, blue
*99/255 );
1005 rb
->lcd_set_background(COLOR_LIGHTGRAY
);
1006 rb
->lcd_setfont( FONT_SYSFIXED
);
1007 rb
->snprintf( str
, 6, "%d", hue
/10 );
1008 rb
->lcd_putsxy( left
+ 117, top
+ 20, str
);
1009 rb
->snprintf( str
, 6, "%d.%d", saturation
/255, ((saturation
*100)/255)%100 );
1010 rb
->lcd_putsxy( left
+ 117, top
+ 30, str
);
1011 rb
->snprintf( str
, 6, "%d.%d", value
/255, ((value
*100)/255)%100 );
1012 rb
->lcd_putsxy( left
+ 117, top
+ 40, str
);
1013 rb
->snprintf( str
, 6, "%d", red
);
1014 rb
->lcd_putsxy( left
+ 117, top
+ 50, str
);
1015 rb
->snprintf( str
, 6, "%d", green
);
1016 rb
->lcd_putsxy( left
+ 117, top
+ 60, str
);
1017 rb
->snprintf( str
, 6, "%d", blue
);
1018 rb
->lcd_putsxy( left
+ 117, top
+ 70, str
);
1019 rb
->lcd_setfont( FONT_UI
);
1021 #define CURSOR( l ) \
1022 rb->lcd_bitmap_transparent_part( rockpaint_hsvrgb, 1, 1, 16, left+l+1, top+20, 6, 58 ); \
1023 rb->lcd_bitmap_transparent_part( rockpaint_hsvrgb, 8, 10*current, 16, left+l, top+19+10*current, 8, 10 );
1027 rb
->lcd_set_foreground( color
);
1028 rb
->lcd_fillrect( left
+15, top
+85, 100, 8 );
1032 switch( rb
->button_get(true) )
1035 current
= ( current
+ 5 )%6;
1038 case ROCKPAINT_DOWN
:
1039 current
= (current
+ 1 )%6;
1042 case ROCKPAINT_LEFT
:
1047 hue
= ( hue
+ 3600 - 10 )%3600;
1050 if( saturation
) saturation
--;
1053 if( value
) value
--;
1059 if( green
) green
--;
1067 case ROCKPAINT_LEFT
|BUTTON_REPEAT
:
1072 hue
= ( hue
+ 3600 - 100 )%3600;
1075 if( saturation
>= 8 ) saturation
-=8;
1076 else saturation
= 0;
1079 if( value
>= 8 ) value
-=8;
1083 if( red
>= 8 ) red
-=8;
1087 if( green
>= 8 ) green
-=8;
1091 if( blue
>= 8 ) blue
-=8;
1097 case ROCKPAINT_RIGHT
:
1102 hue
= ( hue
+ 10 )%3600;
1105 if( saturation
< 0xff ) saturation
++;
1108 if( value
< 0xff ) value
++;
1111 if( red
< 0xff ) red
++;
1114 if( green
< 0xff ) green
++;
1117 if( blue
< 0xff ) blue
++;
1122 case ROCKPAINT_RIGHT
|BUTTON_REPEAT
:
1127 hue
= ( hue
+ 100 )%3600;
1130 if( saturation
< 0xff - 8 ) saturation
+=8;
1131 else saturation
= 0xff;
1134 if( value
< 0xff - 8 ) value
+=8;
1138 if( red
< 0xff - 8 ) red
+=8;
1142 if( green
< 0xff - 8 ) green
+=8;
1146 if( blue
< 0xff - 8 ) blue
+=8;
1152 case ROCKPAINT_DRAW
:
1162 hsv2rgb( hue
, saturation
, value
, &red
, &green
, &blue
);
1168 rgb2hsv( red
, green
, blue
, &hue
, &saturation
, &value
);
1177 /***********************************************************************
1179 ***********************************************************************/
1180 static void init_buffer(void)
1183 fb_data color
= rp_colors
[ bgdrawcolor
];
1184 for( i
= 0; i
< ROWS
*COLS
; i
++ )
1186 save_buffer
[i
] = color
;
1190 static void draw_pixel(int x
,int y
)
1194 if( x
< 0 || x
>= COLS
|| y
< 0 || y
>= ROWS
) return;
1197 save_buffer
[ x
+y
*COLS
] = rp_colors
[bgdrawcolor
];
1201 save_buffer
[ x
+y
*COLS
] = rp_colors
[drawcolor
];
1204 rb
->lcd_drawpixel(x
,y
);
1207 static void color_picker( int x
, int y
)
1211 rb
->lcd_set_foreground( save_buffer
[ x
+y
*COLS
] );
1213 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1214 if( x
>= COLS
- PSIZE
) x
-= PSIZE
+ 2;
1215 if( y
>= ROWS
- PSIZE
) y
-= PSIZE
+ 2;
1216 rb
->lcd_drawrect( x
+ 2, y
+ 2, PSIZE
- 2, PSIZE
- 2 );
1217 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1218 rb
->lcd_drawrect( x
+ 3, y
+ 3, PSIZE
- 4, PSIZE
- 4 );
1220 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
1224 rp_colors
[ drawcolor
] = save_buffer
[ x
+y
*COLS
];
1228 static void draw_select_rectangle( int x1
, int y1
, int x2
, int y2
)
1229 /* This is a preview mode only function */
1244 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1246 for( a
= x1
; a
< x2
; a
++, i
++ )
1248 rb
->lcd_drawpixel( a
, y1
);
1249 for( a
= y1
; a
< y2
; a
++, i
++ )
1251 rb
->lcd_drawpixel( x2
, a
);
1253 for( a
= x2
; a
> x1
; a
--, i
++ )
1255 rb
->lcd_drawpixel( a
, y2
);
1257 for( a
= y2
; a
> y1
; a
--, i
++ )
1259 rb
->lcd_drawpixel( x1
, a
);
1260 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1263 static void copy_to_clipboard( void )
1265 /* This needs to be optimised ... but i'm lazy ATM */
1266 rb
->memcpy( buffer
.clipboard
, save_buffer
, COLS
*ROWS
*sizeof( fb_data
) );
1269 /* no preview mode handling atm ... do we need it ? (one if) */
1270 static void draw_invert( int x1
, int y1
, int x2
, int y2
)
1286 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1287 rb
->lcd_fillrect( x1
, y1
, x2
-x1
+1, y2
-y1
+1 );
1288 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1290 for( ; y1
<=y2
; y1
++ )
1292 for( i
= x1
; i
<=x2
; i
++ )
1294 save_buffer
[ y1
*COLS
+ i
] = ~save_buffer
[ y1
*COLS
+ i
];
1297 /*if( update )*/ rb
->lcd_update();
1300 static void draw_hflip( int x1
, int y1
, int x2
, int y2
)
1316 copy_to_clipboard();
1318 for( i
= 0; i
<= y2
- y1
; i
++ )
1320 rb
->memcpy( save_buffer
+(y1
+i
)*COLS
+x1
,
1321 buffer
.clipboard
+(y2
-i
)*COLS
+x1
,
1322 (x2
-x1
+1)*sizeof( fb_data
) );
1328 static void draw_vflip( int x1
, int y1
, int x2
, int y2
)
1344 copy_to_clipboard();
1346 for( ; y1
<= y2
; y1
++ )
1348 for( i
= 0; i
<= x2
- x1
; i
++ )
1350 save_buffer
[y1
*COLS
+x1
+i
] = buffer
.clipboard
[y1
*COLS
+x2
-i
];
1357 /* direction: -1 = left, 1 = right */
1358 static void draw_rot_90_deg( int x1
, int y1
, int x2
, int y2
, int direction
)
1374 copy_to_clipboard();
1376 fb_data color
= rp_colors
[ bgdrawcolor
];
1377 const int width
= x2
- x1
, height
= y2
- y1
;
1378 const int sub_half
= width
/2-height
/2, add_half
= (width
+height
)/2;
1379 if( width
> height
)
1381 for( i
= 0; i
<= height
; i
++ )
1383 for( j
= 0; j
< sub_half
; j
++ )
1384 save_buffer
[(y1
+i
)*COLS
+x1
+j
] = color
;
1385 for( j
= add_half
+1; j
<= width
; j
++ )
1386 save_buffer
[(y1
+i
)*COLS
+x1
+j
] = color
;
1389 else if( width
< height
)
1391 for( j
= 0; j
<= width
; j
++ )
1393 for( i
= 0; i
< -sub_half
; i
++ )
1394 save_buffer
[(y1
+i
)*COLS
+x1
+j
] = color
;
1395 for( i
= add_half
+1; i
<= height
; i
++ )
1396 save_buffer
[(y1
+i
)*COLS
+x1
+j
] = color
;
1399 int x3
= x1
+ sub_half
, y3
= y1
- sub_half
;
1400 int is
= x3
<0?-x3
:0, ie
= COLS
-x3
-1, js
= y3
<0?-y3
:0, je
= ROWS
-y3
-1;
1401 if( ie
> height
) ie
= height
;
1402 if( je
> width
) je
= width
;
1403 for( i
= is
; i
<= ie
; i
++ )
1405 for( j
= js
; j
<= je
; j
++ )
1418 save_buffer
[(y3
+j
)*COLS
+x3
+i
] = buffer
.clipboard
[y
*COLS
+x
];
1425 static void draw_paste_rectangle( int src_x1
, int src_y1
, int src_x2
,
1426 int src_y2
, int x1
, int y1
, int mode
)
1428 int i
, width
, height
;
1429 if( mode
== SELECT_MENU_CUT
)
1432 drawcolor
= bgdrawcolor
;
1433 draw_rect_full( src_x1
, src_y1
, src_x2
, src_y2
);
1436 if( src_x1
> src_x2
)
1442 if( src_y1
> src_y2
)
1448 width
= src_x2
- src_x1
+ 1;
1449 height
= src_y2
- src_y1
+ 1;
1451 if( x1
+ width
> COLS
)
1453 if( y1
+ height
> ROWS
)
1456 rb
->lcd_bitmap_part( buffer
.clipboard
, src_x1
, src_y1
, COLS
,
1457 x1
, y1
, width
, height
);
1460 for( i
= 0; i
< height
; i
++ )
1462 rb
->memcpy( save_buffer
+(y1
+i
)*COLS
+x1
,
1463 buffer
.clipboard
+(src_y1
+i
)*COLS
+src_x1
,
1464 width
*sizeof( fb_data
) );
1469 static void show_grid( bool update
)
1474 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1475 for( i
= gridsize
; i
< img_width
; i
+= gridsize
)
1477 rb
->lcd_vline( i
, 0, img_height
-1 );
1479 for( i
= gridsize
; i
< img_height
; i
+= gridsize
)
1481 rb
->lcd_hline( 0, img_width
-1, i
);
1483 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1484 if( update
) rb
->lcd_update();
1488 static void draw_text( int x
, int y
)
1491 buffer
.text
.text
[0] = '\0';
1492 rb
->snprintf( buffer
.text
.old_font
, MAX_PATH
,
1494 rb
->global_settings
->font_file
);
1497 switch( rb
->do_menu( &text_menu
, &selected
, NULL
, NULL
) )
1499 case TEXT_MENU_TEXT
:
1500 rb
->lcd_set_foreground(COLOR_BLACK
);
1501 rb
->kbd_input( buffer
.text
.text
, MAX_TEXT
);
1504 case TEXT_MENU_FONT
:
1505 if( browse_fonts( buffer
.text
.font
, MAX_PATH
) )
1507 rb
->font_load( buffer
.text
.font
);
1511 case TEXT_MENU_PREVIEW
:
1512 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
1517 rb
->lcd_putsxy( x
, y
, buffer
.text
.text
);
1519 switch( button
= rb
->button_get( true ) )
1521 case ROCKPAINT_LEFT
:
1522 case ROCKPAINT_LEFT
| BUTTON_REPEAT
:
1523 x
-=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
1527 case ROCKPAINT_RIGHT
:
1528 case ROCKPAINT_RIGHT
| BUTTON_REPEAT
:
1529 x
+=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
1534 case ROCKPAINT_UP
| BUTTON_REPEAT
:
1535 y
-=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
1539 case ROCKPAINT_DOWN
:
1540 case ROCKPAINT_DOWN
| BUTTON_REPEAT
:
1541 y
+=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
1545 case ROCKPAINT_DRAW
:
1548 if(rb
->default_event_handler(button
)
1549 == SYS_USB_CONNECTED
)
1550 button
= ROCKPAINT_DRAW
;
1553 if( button
== ROCKPAINT_DRAW
) break;
1557 case TEXT_MENU_APPLY
:
1558 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
1559 buffer_putsxyofs( save_buffer
, COLS
, ROWS
, x
, y
, 0,
1561 case TEXT_MENU_CANCEL
:
1564 rb
->font_load( buffer
.text
.old_font
);
1570 static void draw_brush( int x
, int y
)
1573 for( i
=-bsize
/2+(bsize
+1)%2; i
<=bsize
/2; i
++ )
1575 for( j
=-bsize
/2+(bsize
+1)%2; j
<=bsize
/2; j
++ )
1577 draw_pixel( x
+i
, y
+j
);
1582 /* This is an implementation of Bresenham's line algorithm.
1583 * See http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm.
1585 static void draw_line( int x1
, int y1
, int x2
, int y2
)
1589 int deltax
= x2
- x1
;
1590 int deltay
= y2
- y1
;
1593 int xerr
= abs(deltax
);
1594 int yerr
= abs(deltay
);
1595 int xstep
= deltax
> 0 ? 1 : -1;
1596 int ystep
= deltay
> 0 ? 1 : -1;
1606 /* to leave off the last pixel of the line, leave off the "+ 1" */
1607 for (i
= abs(deltay
) + 1; i
; --i
)
1620 /* more horizontal */
1625 for (i
= abs(deltax
) + 1; i
; --i
)
1638 static void draw_curve( int x1
, int y1
, int x2
, int y2
,
1639 int xa
, int ya
, int xb
, int yb
)
1653 if( x1
== x2
&& y1
== y2
)
1655 draw_pixel( x1
, y1
);
1661 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1662 if( xa
== -1 || ya
== -1 )
1664 rb
->lcd_drawline( x1
, y1
, xb
, yb
);
1665 rb
->lcd_drawline( x2
, y2
, xb
, yb
);
1669 rb
->lcd_drawline( x1
, y1
, xa
, ya
);
1670 rb
->lcd_drawline( x2
, y2
, xb
, yb
);
1672 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1675 if( xa
== -1 || ya
== -1 )
1676 /* We only have 3 of the points
1677 * This will currently only be used in preview mode */
1679 #define PUSH( a1, b1, a2, b2, a3, b3, d ) \
1680 buffer.bezier[i].x1 = a1; \
1681 buffer.bezier[i].y1 = b1; \
1682 buffer.bezier[i].x2 = a2; \
1683 buffer.bezier[i].y2 = b2; \
1684 buffer.bezier[i].x3 = a3; \
1685 buffer.bezier[i].y3 = b3; \
1686 buffer.bezier[i].depth = d; \
1688 #define POP( a1, b1, a2, b2, a3, b3, d ) \
1690 a1 = buffer.bezier[i].x1; \
1691 b1 = buffer.bezier[i].y1; \
1692 a2 = buffer.bezier[i].x2; \
1693 b2 = buffer.bezier[i].y2; \
1694 a3 = buffer.bezier[i].x3; \
1695 b3 = buffer.bezier[i].y3; \
1696 d = buffer.bezier[i].depth;
1697 PUSH( x1
<<4, y1
<<4, xb
<<4, yb
<<4, x2
<<4, y2
<<4, 0 );
1700 /* de Casteljau's algorithm (see wikipedia) */
1701 POP( xl1
, yl1
, xb
, yb
, xr3
, yr3
, depth
);
1702 if( depth
< 10 ) /* check that the stack's 'i' doesn't overflow */
1704 xl2
= ( xl1
+ xb
)>>1;
1705 yl2
= ( yl1
+ yb
)>>1;
1706 xr2
= ( xb
+ xr3
)>>1;
1707 yr2
= ( yb
+ yr3
)>>1;
1708 xr1
= ( xl2
+ xr2
)>>1;
1709 yr1
= ( yl2
+ yr2
)>>1;
1712 PUSH( xl1
, yl1
, xl2
, yl2
, xl3
, yl3
, depth
+1 );
1713 PUSH( xr1
, yr1
, xr2
, yr2
, xr3
, yr3
, depth
+1 );
1717 draw_line( ((xl1
>>3)+1)>>1, ((yl1
>>3)+1)>>1,
1718 ((xr3
>>3)+1)>>1, ((yr3
>>3)+1)>>1 );
1724 else /* We have the 4 points */
1726 #define PUSH( a1, b1, a2, b2, a3, b3, a4, b4, d ) \
1727 buffer.bezier[i].x1 = a1; \
1728 buffer.bezier[i].y1 = b1; \
1729 buffer.bezier[i].x2 = a2; \
1730 buffer.bezier[i].y2 = b2; \
1731 buffer.bezier[i].x3 = a3; \
1732 buffer.bezier[i].y3 = b3; \
1733 buffer.bezier[i].x4 = a4; \
1734 buffer.bezier[i].y4 = b4; \
1735 buffer.bezier[i].depth = d; \
1737 #define POP( a1, b1, a2, b2, a3, b3, a4, b4, d ) \
1739 a1 = buffer.bezier[i].x1; \
1740 b1 = buffer.bezier[i].y1; \
1741 a2 = buffer.bezier[i].x2; \
1742 b2 = buffer.bezier[i].y2; \
1743 a3 = buffer.bezier[i].x3; \
1744 b3 = buffer.bezier[i].y3; \
1745 a4 = buffer.bezier[i].x4; \
1746 b4 = buffer.bezier[i].y4; \
1747 d = buffer.bezier[i].depth;
1749 PUSH( x1
<<4, y1
<<4, xa
<<4, ya
<<4, xb
<<4, yb
<<4, x2
<<4, y2
<<4, 0 );
1752 /* de Casteljau's algorithm (see wikipedia) */
1753 POP( xl1
, yl1
, xa
, ya
, xb
, yb
, xr4
, yr4
, depth
);
1754 if( depth
< 10 ) /* check that the stack's 'i' doesn't overflow */
1756 xl2
= ( xl1
+ xa
)>>1;
1757 yl2
= ( yl1
+ ya
)>>1;
1758 xh
= ( xa
+ xb
)>>1;
1759 yh
= ( ya
+ yb
)>>1;
1760 xr3
= ( xb
+ xr4
)>>1;
1761 yr3
= ( yb
+ yr4
)>>1;
1762 xl3
= ( xl2
+ xh
)>>1;
1763 yl3
= ( yl2
+ yh
)>>1;
1764 xr2
= ( xr3
+ xh
)>>1;
1765 yr2
= ( yr3
+ yh
)>>1;
1766 xl4
= ( xl3
+ xr2
)>>1;
1767 yl4
= ( yl3
+ yr2
)>>1;
1770 PUSH( xl1
, yl1
, xl2
, yl2
, xl3
, yl3
, xl4
, yl4
, depth
+1 );
1771 PUSH( xr1
, yr1
, xr2
, yr2
, xr3
, yr3
, xr4
, yr4
, depth
+1 );
1775 draw_line( ((xl1
>>3)+1)>>1, ((yl1
>>3)+1)>>1,
1776 ((xr4
>>3)+1)>>1, ((yr4
>>3)+1)>>1 );
1784 static void draw_rect( int x1
, int y1
, int x2
, int y2
)
1786 draw_line( x1
, y1
, x1
, y2
);
1787 draw_line( x1
, y1
, x2
, y1
);
1788 draw_line( x1
, y2
, x2
, y2
);
1789 draw_line( x2
, y1
, x2
, y2
);
1792 static void togglebg( void )
1796 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
1800 rb
->lcd_set_foreground( rp_colors
[ bgdrawcolor
] );
1805 static void draw_rect_full( int x1
, int y1
, int x2
, int y2
)
1818 draw_line( x
, y1
, x
, y2
);
1819 } while( ++x
<= x2
);
1821 draw_rect( x1
, y1
, x2
, y2
);
1824 static void draw_oval( int x1
, int y1
, int x2
, int y2
, bool full
)
1826 /* TODO: simplify :) */
1827 int cx
= (x1
+x2
)>>1;
1828 int cy
= (y1
+y2
)>>1;
1830 int rx
= (x1
-x2
)>>1;
1831 int ry
= (y1
-y2
)>>1;
1832 if( rx
< 0 ) rx
*= -1;
1833 if( ry
< 0 ) ry
*= -1;
1835 if( rx
== 0 || ry
== 0 )
1837 draw_line( x1
, y1
, x2
, y2
);
1844 for( x
= 0; x
< rx
; x
++ )
1850 dst
= ry
* ry
* x
* x
+ rx
* rx
* y
* y
- rx
* rx
* ry
* ry
;
1853 if( -old_dst
< dst
) y
--;
1856 draw_line( cx
+x
, cy
, cx
+x
, cy
+y
);
1857 draw_line( cx
+x
, cy
, cx
+x
, cy
-y
);
1858 draw_line( cx
-x
, cy
, cx
-x
, cy
+y
);
1859 draw_line( cx
-x
, cy
, cx
-x
, cy
-y
);
1863 draw_pixel( cx
+x
, cy
+y
);
1864 draw_pixel( cx
+x
, cy
-y
);
1865 draw_pixel( cx
-x
, cy
+y
);
1866 draw_pixel( cx
-x
, cy
-y
);
1869 for( y
= 0; y
< ry
; y
++ )
1875 dst
= ry
* ry
* x
* x
+ rx
* rx
* y
* y
- rx
* rx
* ry
* ry
;
1878 if( -old_dst
< dst
) x
--;
1881 draw_line( cx
+x
, cy
, cx
+x
, cy
+y
);
1882 draw_line( cx
+x
, cy
, cx
+x
, cy
-y
);
1883 draw_line( cx
-x
, cy
, cx
-x
, cy
+y
);
1884 draw_line( cx
-x
, cy
, cx
-x
, cy
-y
);
1888 draw_pixel( cx
+x
, cy
+y
);
1889 draw_pixel( cx
+x
, cy
-y
);
1890 draw_pixel( cx
-x
, cy
+y
);
1891 draw_pixel( cx
-x
, cy
-y
);
1896 static void draw_oval_empty( int x1
, int y1
, int x2
, int y2
)
1898 draw_oval( x1
, y1
, x2
, y2
, false );
1901 static void draw_oval_full( int x1
, int y1
, int x2
, int y2
)
1904 draw_oval( x1
, y1
, x2
, y2
, true );
1906 draw_oval( x1
, y1
, x2
, y2
, false );
1909 static void draw_fill( int x0
, int y0
)
1911 #define PUSH( a, b ) \
1912 draw_pixel( (int)a, (int)b ); \
1913 buffer.coord[i].x = a; \
1914 buffer.coord[i].y = b; \
1916 #define POP( a, b ) \
1918 a = buffer.coord[i].x; \
1919 b = buffer.coord[i].y;
1924 unsigned int prev_color
= save_buffer
[ x0
+y0
*COLS
];
1926 if( prev_color
== rp_colors
[ drawcolor
] ) return;
1933 if( x
> 0 && save_buffer
[x
-1+y
*COLS
] == prev_color
)
1937 if( x
< COLS
-1 && save_buffer
[x
+1+y
*COLS
] == prev_color
)
1941 if( y
> 0 && save_buffer
[x
+(y
-1)*COLS
] == prev_color
)
1945 if( y
< ROWS
- 1 && save_buffer
[x
+(y
+1)*COLS
] == prev_color
)
1955 /* For preview purposes only */
1956 static void line_gradient( int x1
, int y1
, int x2
, int y2
)
1960 int h1
, s1
, v1
, h2
, s2
, v2
, r
, g
, b
;
1973 if( w
== 0 && h
== 0 )
1975 draw_pixel( x1
>>1, y1
>>1 );
1979 r1
= RGB_UNPACK_RED( rp_colors
[ bgdrawcolor
] );
1980 g1
= RGB_UNPACK_GREEN( rp_colors
[ bgdrawcolor
] );
1981 b1
= RGB_UNPACK_BLUE( rp_colors
[ bgdrawcolor
] );
1982 r2
= RGB_UNPACK_RED( rp_colors
[ drawcolor
] );
1983 g2
= RGB_UNPACK_GREEN( rp_colors
[ drawcolor
] );
1984 b2
= RGB_UNPACK_BLUE( rp_colors
[ drawcolor
] );
2009 rgb2hsv( r1
, g1
, b1
, &h1
, &s1
, &v1
);
2010 rgb2hsv( r2
, g2
, b2
, &h2
, &s2
, &v2
);
2027 hsv2rgb( h1
+((h2
-h1
)*(x1
-x2
))/w
,
2028 s1
+((s2
-s1
)*(x1
-x2
))/w
,
2029 v1
+((v2
-v1
)*(x1
-x2
))/w
,
2031 rp_colors
[ drawcolor
] = LCD_RGBPACK( r
, g
, b
);
2032 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
2033 draw_pixel( (x1
+1)>>1, (y1
+1)>>1 );
2035 y1
= y2
- ( x2
- x1
) * h
/ w
;
2053 hsv2rgb( h1
+((h2
-h1
)*(y1
-y2
))/h
,
2054 s1
+((s2
-s1
)*(y1
-y2
))/h
,
2055 v1
+((v2
-v1
)*(y1
-y2
))/h
,
2057 rp_colors
[ drawcolor
] = LCD_RGBPACK( r
, g
, b
);
2058 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
2059 draw_pixel( (x1
+1)>>1, (y1
+1)>>1 );
2061 x1
= x2
- ( y2
- y1
) * w
/ h
;
2066 rp_colors
[ drawcolor
] = LCD_RGBPACK( r1
, g1
, b1
);
2070 rp_colors
[ drawcolor
] = LCD_RGBPACK( r2
, g2
, b2
);
2074 static void linear_gradient( int x1
, int y1
, int x2
, int y2
)
2076 int r1
= RGB_UNPACK_RED( rp_colors
[ bgdrawcolor
] );
2077 int g1
= RGB_UNPACK_GREEN( rp_colors
[ bgdrawcolor
] );
2078 int b1
= RGB_UNPACK_BLUE( rp_colors
[ bgdrawcolor
] );
2079 int r2
= RGB_UNPACK_RED( rp_colors
[ drawcolor
] );
2080 int g2
= RGB_UNPACK_GREEN( rp_colors
[ drawcolor
] );
2081 int b2
= RGB_UNPACK_BLUE( rp_colors
[ drawcolor
] );
2083 int h1
, s1
, v1
, h2
, s2
, v2
, r
, g
, b
;
2086 int radius2
= ( x1
- x2
) * ( x1
- x2
) + ( y1
- y2
) * ( y1
- y2
);
2089 /* We only propagate the gradient to neighboring pixels with the same
2090 * color as ( x1, y1 ) */
2091 unsigned int prev_color
= save_buffer
[ x1
+y1
*COLS
];
2096 if( radius2
== 0 ) return;
2099 line_gradient( x1
, y1
, x2
, y2
);
2102 rgb2hsv( r1
, g1
, b1
, &h1
, &s1
, &v1
);
2103 rgb2hsv( r2
, g2
, b2
, &h2
, &s2
, &v2
);
2105 #define PUSH( x0, y0 ) \
2106 buffer.coord[i].x = (short)(x0); \
2107 buffer.coord[i].y = (short)(y0); \
2109 #define POP( a, b ) \
2111 a = (int)buffer.coord[i].x; \
2112 b = (int)buffer.coord[i].y;
2120 dist2
= ( x2
- x1
) * ( x
- x1
) + ( y2
- y1
) * ( y
- y1
);
2123 rp_colors
[ drawcolor
] = rp_colors
[ bgdrawcolor
];
2125 else if( dist2
< radius2
)
2127 hsv2rgb( h1
+((h2
-h1
)*dist2
)/radius2
,
2128 s1
+((s2
-s1
)*dist2
)/radius2
,
2129 v1
+((v2
-v1
)*dist2
)/radius2
,
2131 rp_colors
[ drawcolor
] = LCD_RGBPACK( r
, g
, b
);
2135 rp_colors
[ drawcolor
] = LCD_RGBPACK( r2
, g2
, b2
);
2137 if( rp_colors
[ drawcolor
] == prev_color
)
2139 if( rp_colors
[ drawcolor
])
2140 rp_colors
[ drawcolor
]--; /* GRUIK */
2142 rp_colors
[ drawcolor
]++; /* GRUIK */
2144 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
2147 if( x
> 0 && save_buffer
[x
-1+y
*COLS
] == prev_color
)
2151 if( x
< COLS
-1 && save_buffer
[x
+1+y
*COLS
] == prev_color
)
2155 if( y
> 0 && save_buffer
[x
+(y
-1)*COLS
] == prev_color
)
2159 if( y
< ROWS
- 1 && save_buffer
[x
+(y
+1)*COLS
] == prev_color
)
2167 rp_colors
[ drawcolor
] = LCD_RGBPACK( r2
, g2
, b2
);
2170 static void radial_gradient( int x1
, int y1
, int x2
, int y2
)
2172 int r1
= RGB_UNPACK_RED( rp_colors
[ bgdrawcolor
] );
2173 int g1
= RGB_UNPACK_GREEN( rp_colors
[ bgdrawcolor
] );
2174 int b1
= RGB_UNPACK_BLUE( rp_colors
[ bgdrawcolor
] );
2175 int r2
= RGB_UNPACK_RED( rp_colors
[ drawcolor
] );
2176 int g2
= RGB_UNPACK_GREEN( rp_colors
[ drawcolor
] );
2177 int b2
= RGB_UNPACK_BLUE( rp_colors
[ drawcolor
] );
2179 int h1
, s1
, v1
, h2
, s2
, v2
, r
, g
, b
;
2182 int radius2
= ( x1
- x2
) * ( x1
- x2
) + ( y1
- y2
) * ( y1
- y2
);
2185 /* We only propagate the gradient to neighboring pixels with the same
2186 * color as ( x1, y1 ) */
2187 unsigned int prev_color
= save_buffer
[ x1
+y1
*COLS
];
2192 if( radius2
== 0 ) return;
2195 line_gradient( x1
, y1
, x2
, y2
);
2198 rgb2hsv( r1
, g1
, b1
, &h1
, &s1
, &v1
);
2199 rgb2hsv( r2
, g2
, b2
, &h2
, &s2
, &v2
);
2201 #define PUSH( x0, y0 ) \
2202 buffer.coord[i].x = (short)(x0); \
2203 buffer.coord[i].y = (short)(y0); \
2205 #define POP( a, b ) \
2207 a = (int)buffer.coord[i].x; \
2208 b = (int)buffer.coord[i].y;
2216 if( ( dist2
= (x1
-(x
))*(x1
-(x
))+(y1
-(y
))*(y1
-(y
)) ) < radius2
)
2218 hsv2rgb( h1
+((h2
-h1
)*dist2
)/radius2
,
2219 s1
+((s2
-s1
)*dist2
)/radius2
,
2220 v1
+((v2
-v1
)*dist2
)/radius2
,
2222 rp_colors
[ drawcolor
] = LCD_RGBPACK( r
, g
, b
);
2226 rp_colors
[ drawcolor
] = LCD_RGBPACK( r2
, g2
, b2
);
2228 if( rp_colors
[ drawcolor
] == prev_color
)
2230 if( rp_colors
[ drawcolor
])
2231 rp_colors
[ drawcolor
]--; /* GRUIK */
2233 rp_colors
[ drawcolor
]++; /* GRUIK */
2235 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
2238 if( x
> 0 && save_buffer
[x
-1+y
*COLS
] == prev_color
)
2242 if( x
< COLS
-1 && save_buffer
[x
+1+y
*COLS
] == prev_color
)
2246 if( y
> 0 && save_buffer
[x
+(y
-1)*COLS
] == prev_color
)
2250 if( y
< ROWS
- 1 && save_buffer
[x
+(y
+1)*COLS
] == prev_color
)
2258 rp_colors
[ drawcolor
] = LCD_RGBPACK( r2
, g2
, b2
);
2261 static void draw_toolbars(bool update
)
2264 #define TOP (LCD_HEIGHT-TB_HEIGHT)
2265 rb
->lcd_set_background( COLOR_LIGHTGRAY
);
2266 rb
->lcd_set_foreground( COLOR_LIGHTGRAY
);
2267 rb
->lcd_fillrect( 0, TOP
, LCD_WIDTH
, TB_HEIGHT
);
2268 rb
->lcd_set_foreground( COLOR_BLACK
);
2269 rb
->lcd_drawrect( 0, TOP
, LCD_WIDTH
, TB_HEIGHT
);
2271 rb
->lcd_set_foreground( rp_colors
[ bgdrawcolor
] );
2272 rb
->lcd_fillrect( TB_SC_BG_LEFT
, TOP
+TB_SC_BG_TOP
,
2273 TB_SC_SIZE
, TB_SC_SIZE
);
2274 rb
->lcd_set_foreground(ROCKPAINT_PALETTE
);
2275 rb
->lcd_drawrect( TB_SC_BG_LEFT
, TOP
+TB_SC_BG_TOP
,
2276 TB_SC_SIZE
, TB_SC_SIZE
);
2277 rb
->lcd_set_foreground( rp_colors
[ drawcolor
] );
2278 rb
->lcd_fillrect( TB_SC_FG_LEFT
, TOP
+TB_SC_FG_TOP
,
2279 TB_SC_SIZE
, TB_SC_SIZE
);
2280 rb
->lcd_set_foreground(ROCKPAINT_PALETTE
);
2281 rb
->lcd_drawrect( TB_SC_FG_LEFT
, TOP
+TB_SC_FG_TOP
,
2282 TB_SC_SIZE
, TB_SC_SIZE
);
2284 for( i
=0; i
<18; i
++ )
2286 rb
->lcd_set_foreground( rp_colors
[i
] );
2288 TB_PL_LEFT
+(i
%9)*( TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
),
2289 TOP
+TB_PL_TOP
+(i
/9)*( TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
),
2290 TB_PL_COLOR_SIZE
, TB_PL_COLOR_SIZE
);
2291 rb
->lcd_set_foreground( ROCKPAINT_PALETTE
);
2293 TB_PL_LEFT
+(i
%9)*( TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
),
2294 TOP
+TB_PL_TOP
+(i
/9)*( TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
),
2295 TB_PL_COLOR_SIZE
, TB_PL_COLOR_SIZE
);
2298 #define SEPARATOR( x, y ) \
2299 rb->lcd_set_foreground( COLOR_WHITE ); \
2300 rb->lcd_vline( x, TOP+y, TOP+y+TB_PL_HEIGHT-1 ); \
2301 rb->lcd_set_foreground( COLOR_DARKGRAY ); \
2302 rb->lcd_vline( x+1, TOP+y, TOP+y+TB_PL_HEIGHT-1 );
2303 SEPARATOR( TB_PL_LEFT
+ TB_PL_WIDTH
- 1 + TB_SP_MARGIN
, TB_PL_TOP
);
2305 rb
->lcd_bitmap_transparent( rockpaint
, TB_TL_LEFT
, TOP
+TB_TL_TOP
,
2306 TB_TL_WIDTH
, TB_TL_HEIGHT
);
2307 rb
->lcd_set_foreground(ROCKPAINT_PALETTE
);
2308 rb
->lcd_drawrect( TB_TL_LEFT
+(TB_TL_SIZE
+TB_TL_SPACING
)*(tool
/2),
2309 TOP
+TB_TL_TOP
+(TB_TL_SIZE
+TB_TL_SPACING
)*(tool
%2),
2310 TB_TL_SIZE
, TB_TL_SIZE
);
2312 SEPARATOR( TB_TL_LEFT
+ TB_TL_WIDTH
- 1 + TB_SP_MARGIN
, TB_TL_TOP
);
2314 rb
->lcd_setfont( FONT_SYSFIXED
);
2315 rb
->lcd_putsxy( TB_MENU_LEFT
, TOP
+TB_MENU_TOP
, "Menu" );
2316 rb
->lcd_setfont( FONT_UI
);
2319 if( update
) rb
->lcd_update();
2322 static void toolbar( void )
2326 draw_toolbars( false );
2327 y
= LCD_HEIGHT
-TB_HEIGHT
/2;
2331 switch( button
= rb
->button_get( true ) )
2333 case ROCKPAINT_DRAW
:
2334 #define TOP ( LCD_HEIGHT - TB_HEIGHT )
2335 if( y
>= TOP
+ TB_SC_FG_TOP
2336 && y
< TOP
+ TB_SC_FG_TOP
+ TB_SC_SIZE
2337 && x
>= TB_SC_FG_LEFT
2338 && x
< TB_SC_FG_LEFT
+ TB_SC_SIZE
)
2340 /* click on the foreground color */
2341 rp_colors
[drawcolor
] = color_chooser( rp_colors
[drawcolor
] );
2343 else if( y
>= TOP
+ TB_SC_BG_TOP
2344 && y
< TOP
+ TB_SC_BG_TOP
+ TB_SC_SIZE
2345 && x
>= TB_SC_BG_LEFT
2346 && x
< TB_SC_BG_LEFT
+ TB_SC_SIZE
)
2348 /* click on the background color */
2350 drawcolor
= bgdrawcolor
;
2353 else if( y
>= TOP
+ TB_PL_TOP
2354 && y
< TOP
+ TB_PL_TOP
+ TB_PL_HEIGHT
2356 && x
< TB_PL_LEFT
+ TB_PL_WIDTH
)
2358 /* click on the palette */
2359 i
= (x
- TB_PL_LEFT
)%(TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
);
2360 j
= (y
- (TOP
+TB_PL_TOP
) )%(TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
);
2361 if( i
>= TB_PL_COLOR_SIZE
|| j
>= TB_PL_COLOR_SIZE
)
2363 i
= ( x
- TB_PL_LEFT
)/(TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
);
2364 j
= ( y
- (TOP
+TB_PL_TOP
) )/(TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
);
2365 drawcolor
= j
*(TB_PL_COLOR_SIZE
+TB_PL_COLOR_SPACING
)+i
;
2367 else if( y
>= TOP
+TB_TL_TOP
2368 && y
< TOP
+ TB_TL_TOP
+ TB_TL_HEIGHT
2370 && x
<= TB_TL_LEFT
+ TB_TL_WIDTH
)
2372 /* click on the tools */
2373 i
= (x
- TB_TL_LEFT
) % (TB_TL_SIZE
+TB_TL_SPACING
);
2374 j
= (y
- (TOP
+TB_TL_TOP
) ) %(TB_TL_SIZE
+TB_TL_SPACING
);
2375 if( i
>= TB_TL_SIZE
|| j
>= TB_TL_SIZE
) break;
2376 i
= ( x
- TB_TL_LEFT
)/(TB_TL_SIZE
+TB_TL_SPACING
);
2377 j
= ( y
- (TOP
+TB_TL_TOP
) )/(TB_TL_SIZE
+TB_TL_SPACING
);
2387 else if( x
>= TB_MENU_LEFT
&& y
>= TOP
+TB_MENU_TOP
-2)
2394 draw_toolbars( false );
2398 case ROCKPAINT_LEFT
:
2399 case ROCKPAINT_LEFT
| BUTTON_REPEAT
:
2401 x
-=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
2406 case ROCKPAINT_RIGHT
:
2407 case ROCKPAINT_RIGHT
| BUTTON_REPEAT
:
2409 x
+=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
2415 case ROCKPAINT_UP
| BUTTON_REPEAT
:
2417 y
-=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
2418 if (y
<LCD_HEIGHT
-TB_HEIGHT
)
2425 case ROCKPAINT_DOWN
:
2426 case ROCKPAINT_DOWN
| BUTTON_REPEAT
:
2428 y
+=bspeed
* ( button
& BUTTON_REPEAT
? 4 : 1 );
2437 case ROCKPAINT_TOOLBAR
:
2438 case ROCKPAINT_TOOLBAR2
:
2445 static void inv_cursor(bool update
)
2447 rb
->lcd_set_foreground(COLOR_BLACK
);
2448 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
2449 /* cross painting */
2450 rb
->lcd_hline(x
-4,x
+4,y
);
2451 rb
->lcd_vline(x
,y
-4,y
+4);
2452 rb
->lcd_set_foreground(rp_colors
[drawcolor
]);
2453 rb
->lcd_set_drawmode(DRMODE_SOLID
);
2455 if( update
) rb
->lcd_update();
2458 static void restore_screen(void)
2460 rb
->lcd_bitmap( save_buffer
, 0, 0, COLS
, ROWS
);
2461 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
2462 rb
->lcd_vline( img_width
, 0, ROWS
);
2463 rb
->lcd_hline( 0, COLS
, img_height
);
2464 rb
->lcd_drawpixel( img_width
, img_height
);
2465 rb
->lcd_set_drawmode(DRMODE_SOLID
);
2468 static void clear_drawing(void)
2473 rb
->lcd_set_foreground( rp_colors
[ bgdrawcolor
] );
2474 rb
->lcd_fillrect( 0, 0, COLS
, ROWS
);
2478 static void goto_menu(void)
2485 switch( rb
->do_menu( &main_menu
, &selected
, NULL
, false ) )
2491 case MAIN_MENU_LOAD
:
2492 if( browse( filename
, MAX_PATH
, "/" ) )
2494 if( load_bitmap( filename
) <= 0 )
2496 rb
->splashf( 1*HZ
, "Error while loading %s",
2502 rb
->splashf( 1*HZ
, "Image loaded (%s)", filename
);
2510 case MAIN_MENU_SAVE
:
2511 rb
->lcd_set_foreground(COLOR_BLACK
);
2513 rb
->strcpy(filename
,"/");
2514 if( !rb
->kbd_input( filename
, MAX_PATH
) )
2516 if( !check_extention( filename
, ".bmp" ) )
2517 rb
->strcat(filename
, ".bmp");
2518 save_bitmap( filename
);
2519 rb
->splashf( 1*HZ
, "File saved (%s)", filename
);
2523 case MAIN_MENU_SET_WIDTH
:
2524 rb
->set_int( "Set Width", "px", UNIT_INT
, &img_width
,
2525 NULL
, 1, 1, COLS
, NULL
);
2527 case MAIN_MENU_SET_HEIGHT
:
2528 rb
->set_int( "Set Height", "px", UNIT_INT
, &img_height
,
2529 NULL
, 1, 1, ROWS
, NULL
);
2531 case MAIN_MENU_BRUSH_SIZE
:
2532 for(multi
= 0; multi
<4; multi
++)
2533 if(bsize
== times_list
[multi
]) break;
2534 rb
->set_option( "Brush Size", &multi
, INT
, times_options
, 4, NULL
);
2536 bsize
= times_list
[multi
];
2539 case MAIN_MENU_BRUSH_SPEED
:
2540 for(multi
= 0; multi
<3; multi
++)
2541 if(bspeed
== times_list
[multi
]) break;
2542 rb
->set_option( "Brush Speed", &multi
, INT
, times_options
, 3, NULL
);
2544 bspeed
= times_list
[multi
];
2547 case MAIN_MENU_COLOR
:
2548 rp_colors
[drawcolor
] = color_chooser( rp_colors
[drawcolor
] );
2551 case MAIN_MENU_GRID_SIZE
:
2552 for(multi
= 0; multi
<4; multi
++)
2553 if(gridsize
== gridsize_list
[multi
]) break;
2554 rb
->set_option( "Grid Size", &multi
, INT
, gridsize_options
, 4, NULL
);
2556 gridsize
= gridsize_list
[multi
];
2559 case MAIN_MENU_PLAYBACK_CONTROL
:
2560 playback_control( NULL
);
2563 case MAIN_MENU_EXIT
:
2568 case MAIN_MENU_RESUME
:
2576 static void reset_tool( void )
2588 static bool rockpaint_loop( void )
2600 button
= rb
->button_get(true);
2602 if( tool
== Brush
&& prev_x
!= -1 )
2606 else if( button
& BUTTON_REPEAT
)
2617 case ROCKPAINT_QUIT
:
2618 rb
->lcd_set_drawmode(DRMODE_SOLID
);
2621 case ROCKPAINT_MENU
:
2628 case ROCKPAINT_DRAW
:
2633 if( prev_x
== -1 ) prev_x
= 1;
2637 case SelectRectangle
:
2644 case LinearGradient
:
2645 case RadialGradient
:
2646 /* Curve uses 4 points, others use 2 */
2647 if( prev_x
== -1 || prev_y
== -1 )
2653 else if( tool
== Curve
2654 && ( prev_x2
== -1 || prev_y2
== -1 ) )
2659 else if( tool
== SelectRectangle
2660 && ( prev_x2
== -1 || prev_y2
== -1 ) )
2662 tool_mode
= rb
->do_menu( &select_menu
,
2663 NULL
, NULL
, false );
2666 case SELECT_MENU_CUT
:
2667 case SELECT_MENU_COPY
:
2670 copy_to_clipboard();
2671 if( prev_x
< x
) x
= prev_x
;
2672 if( prev_y
< y
) y
= prev_y
;
2675 case SELECT_MENU_INVERT
:
2676 draw_invert( prev_x
, prev_y
, x
, y
);
2680 case SELECT_MENU_HFLIP
:
2681 draw_hflip( prev_x
, prev_y
, x
, y
);
2685 case SELECT_MENU_VFLIP
:
2686 draw_vflip( prev_x
, prev_y
, x
, y
);
2690 case SELECT_MENU_ROTATE90
:
2691 draw_rot_90_deg( prev_x
, prev_y
, x
, y
, 1 );
2695 case SELECT_MENU_ROTATE180
:
2696 draw_hflip( prev_x
, prev_y
, x
, y
);
2697 draw_vflip( prev_x
, prev_y
, x
, y
);
2701 case SELECT_MENU_ROTATE270
:
2702 draw_rot_90_deg( prev_x
, prev_y
, x
, y
, -1 );
2706 case SELECT_MENU_CANCEL
:
2715 else if( tool
== Curve
2716 && ( prev_x3
== -1 || prev_y3
== -1 ) )
2726 case SelectRectangle
:
2727 draw_paste_rectangle( prev_x
, prev_y
,
2732 draw_line( prev_x
, prev_y
, x
, y
);
2735 draw_curve( prev_x
, prev_y
,
2741 draw_rect( prev_x
, prev_y
, x
, y
);
2744 draw_rect_full( prev_x
, prev_y
, x
, y
);
2747 draw_oval_empty( prev_x
, prev_y
, x
, y
);
2750 draw_oval_full( prev_x
, prev_y
, x
, y
);
2752 case LinearGradient
:
2753 linear_gradient( prev_x
, prev_y
, x
, y
);
2755 case RadialGradient
:
2756 radial_gradient( prev_x
, prev_y
, x
, y
);
2772 color_picker( x
, y
);
2785 case ROCKPAINT_DRAW
|BUTTON_REPEAT
:
2788 /* 3 point bezier curve */
2790 draw_curve( prev_x
, prev_y
,
2800 case ROCKPAINT_TOOLBAR
:
2809 case ROCKPAINT_TOOLBAR2
:
2818 case ROCKPAINT_LEFT
:
2819 case ROCKPAINT_LEFT
| BUTTON_REPEAT
:
2821 x
-=bspeed
* accelaration
;
2826 case ROCKPAINT_RIGHT
:
2827 case ROCKPAINT_RIGHT
| BUTTON_REPEAT
:
2829 x
+=bspeed
* accelaration
;
2835 case ROCKPAINT_UP
| BUTTON_REPEAT
:
2837 y
-=bspeed
* accelaration
;
2842 case ROCKPAINT_DOWN
:
2843 case ROCKPAINT_DOWN
| BUTTON_REPEAT
:
2845 y
+=bspeed
* accelaration
;
2855 if (rb
->default_event_handler(button
) == SYS_USB_CONNECTED
)
2856 return PLUGIN_USB_CONNECTED
;
2859 if( tool
== Brush
&& prev_x
== 1 )
2865 if( preview
|| tool
== ColorPicker
)
2866 /* always preview color picker */
2871 case SelectRectangle
:
2872 if( prev_x2
== -1 || prev_y2
== -1 )
2874 /* we are defining the selection */
2875 draw_select_rectangle( prev_x
, prev_y
, x
, y
);
2879 /* we are pasting the selected data */
2880 draw_paste_rectangle( prev_x
, prev_y
, prev_x2
,
2881 prev_y2
, x
, y
, tool_mode
);
2882 prev_x3
= prev_x2
-prev_x
;
2883 if( prev_x3
< 0 ) prev_x3
*= -1;
2884 prev_y3
= prev_y2
-prev_y
;
2885 if( prev_y3
< 0 ) prev_y3
*= -1;
2886 draw_select_rectangle( x
, y
, x
+prev_x3
, y
+prev_y3
);
2896 draw_line( prev_x
, prev_y
, x
, y
);
2900 if( prev_x2
== -1 || prev_y2
== -1 )
2902 draw_line( prev_x
, prev_y
, x
, y
);
2906 draw_curve( prev_x
, prev_y
,
2914 draw_rect( prev_x
, prev_y
, x
, y
);
2918 draw_rect_full( prev_x
, prev_y
, x
, y
);
2922 draw_oval_empty( prev_x
, prev_y
, x
, y
);
2926 draw_oval_full( prev_x
, prev_y
, x
, y
);
2934 color_picker( x
, y
);
2938 case LinearGradient
:
2939 line_gradient( prev_x
, prev_y
, x
, y
);
2942 case RadialGradient
:
2943 line_gradient( prev_x
, prev_y
, x
, y
);
2962 static int load_bitmap( const char *file
)
2967 fb_data color
= rp_colors
[ bgdrawcolor
];
2969 bm
.data
= (char*)save_buffer
;
2970 ret
= rb
->read_bmp_file( file
, &bm
, ROWS
*COLS
*sizeof( fb_data
),
2971 FORMAT_NATIVE
, NULL
);
2973 if((bm
.width
> COLS
) || ( bm
.height
> ROWS
))
2976 img_width
= bm
.width
;
2977 img_height
= bm
.height
;
2978 for( i
= bm
.height
-1; i
>= 0; i
-- )
2980 rb
->memmove( save_buffer
+i
*COLS
, save_buffer
+i
*bm
.width
,
2981 sizeof( fb_data
)*bm
.width
);
2982 for( j
= bm
.width
; j
< COLS
; j
++ )
2983 save_buffer
[j
+i
*COLS
] = color
;
2985 for( i
= bm
.height
*COLS
; i
< ROWS
*COLS
; i
++ )
2986 save_buffer
[i
] = color
;
2991 static int save_bitmap( char *file
)
2995 for(i
= 0; i
< img_height
; i
++)
2997 rb
->memcpy( buffer
.clipboard
+i
*img_width
, save_buffer
+i
*COLS
,
2998 sizeof( fb_data
)*img_width
);
3000 bm
.data
= (char*)buffer
.clipboard
;
3001 bm
.height
= img_height
;
3002 bm
.width
= img_width
;
3003 bm
.format
= FORMAT_NATIVE
;
3004 return save_bmp_file( file
, &bm
);
3007 enum plugin_status
plugin_start(const void* parameter
)
3009 rb
->lcd_set_foreground(COLOR_WHITE
);
3010 rb
->lcd_set_backdrop(NULL
);
3011 rb
->lcd_fillrect(0,0,LCD_WIDTH
,LCD_HEIGHT
);
3012 rb
->splash( HZ
/2, "Rock Paint");
3014 rb
->lcd_clear_display();
3020 if( load_bitmap( parameter
) <= 0 )
3022 rb
->splash( 1*HZ
, "File Open Error");
3027 rb
->splashf( 1*HZ
, "Image loaded (%s)", (char *)parameter
);
3029 rb
->strcpy( filename
, parameter
);
3038 return rockpaint_loop();