1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2004 Matthias Wientapper
11 * Heavily extended 2005 Jens Arnold
12 * Extended 2009 Tomer Shalev
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
23 ****************************************************************************/
26 #ifdef HAVE_LCD_BITMAP
29 #include "fractal_rect.h"
30 #include "fractal_sets.h"
31 #include "mandelbrot_set.h"
35 static unsigned char *gbuf
;
36 static size_t gbuf_size
= 0;
40 #define REDRAW_PARTIAL 1
42 #define REDRAW_FULL_OVERLAY 3
46 /* returns 1 if a button has been pressed, 0 otherwise */
47 static int button_yield(void *ctx
)
49 long *button
= (long *)ctx
;
51 *button
= rb
->button_get(false);
60 case FRACTAL_ZOOM_OUT
:
61 case FRACTAL_PRECISION_INC
:
62 case FRACTAL_PRECISION_DEC
:
64 #ifdef FRACTAL_ZOOM_IN2
65 case FRACTAL_ZOOM_IN2
:
67 #ifdef FRACTAL_ZOOM_IN_PRE
68 case FRACTAL_ZOOM_IN_PRE
:
70 #if defined(FRACTAL_ZOOM_OUT_PRE) && \
71 (FRACTAL_ZOOM_OUT_PRE != FRACTAL_ZOOM_IN_PRE)
72 case FRACTAL_ZOOM_OUT_PRE
:
74 #ifdef FRACTAL_PRECISION_INC_PRE
75 case FRACTAL_PRECISION_INC_PRE
:
77 #if defined(FRACTAL_PRECISION_DEC_PRE) && \
78 (FRACTAL_PRECISION_DEC_PRE != FRACTAL_PRECISION_INC_PRE)
79 case FRACTAL_PRECISION_DEC_PRE
:
83 *button
= BUTTON_NONE
;
88 static void cleanup(void *parameter
)
96 enum plugin_status
plugin_start(const void* parameter
)
98 long lastbutton
= BUTTON_NONE
;
99 int redraw
= REDRAW_FULL
;
100 struct fractal_ops
*ops
= &mandelbrot_ops
;
105 /* get the remainder of the plugin buffer */
106 gbuf
= (unsigned char *)rb
->plugin_get_buffer(&gbuf_size
);
108 /* initialize the greyscale buffer.*/
109 if (!grey_init(gbuf
, gbuf_size
, GREY_ON_COP
, LCD_WIDTH
, LCD_HEIGHT
, NULL
))
111 rb
->splash(HZ
, "Couldn't init greyscale display");
114 grey_show(true); /* switch on greyscale overlay */
118 rb
->lcd_set_backdrop(NULL
);
126 long button
= BUTTON_NONE
;
128 if (redraw
!= REDRAW_NONE
)
130 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
136 mylcd_ub_clear_display();
139 case REDRAW_FULL_OVERLAY
:
146 /* paint all rects */
147 rects_calc_all(ops
->calc
, button_yield
, (void *)&button
);
148 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
149 rb
->cpu_boost(false);
151 /* not interrupted by button press - screen is fully drawn */
152 redraw
= (button
== BUTTON_NONE
) ? REDRAW_NONE
: REDRAW_PARTIAL
;
155 if (button
== BUTTON_NONE
)
156 button
= rb
->button_get(true);
160 #ifdef FRACTAL_RC_QUIT
161 case FRACTAL_RC_QUIT
:
169 case FRACTAL_ZOOM_OUT
:
170 #ifdef FRACTAL_ZOOM_OUT_PRE
171 if (lastbutton
!= FRACTAL_ZOOM_OUT_PRE
)
175 redraw
= REDRAW_FULL
;
179 case FRACTAL_ZOOM_IN
:
180 #ifdef FRACTAL_ZOOM_IN_PRE
181 if (lastbutton
!= FRACTAL_ZOOM_IN_PRE
)
184 #ifdef FRACTAL_ZOOM_IN2
185 case FRACTAL_ZOOM_IN2
:
188 redraw
= REDRAW_FULL
;
193 mylcd_ub_scroll_down(LCD_SHIFT_Y
);
195 if (redraw
!= REDRAW_FULL
)
196 redraw
= rects_move_down() ? REDRAW_FULL
: REDRAW_PARTIAL
;
201 mylcd_ub_scroll_up(LCD_SHIFT_Y
);
203 if (redraw
!= REDRAW_FULL
)
204 redraw
= rects_move_up() ? REDRAW_FULL
: REDRAW_PARTIAL
;
209 mylcd_ub_scroll_right(LCD_SHIFT_X
);
211 if (redraw
!= REDRAW_FULL
)
212 redraw
= rects_move_right() ? REDRAW_FULL
: REDRAW_PARTIAL
;
217 mylcd_ub_scroll_left(LCD_SHIFT_X
);
219 if (redraw
!= REDRAW_FULL
)
220 redraw
= rects_move_left() ? REDRAW_FULL
: REDRAW_PARTIAL
;
223 case FRACTAL_PRECISION_DEC
:
224 #ifdef FRACTAL_PRECISION_DEC_PRE
225 if (lastbutton
!= FRACTAL_PRECISION_DEC_PRE
)
228 if (ops
->precision(-1))
229 redraw
= REDRAW_FULL_OVERLAY
;
233 case FRACTAL_PRECISION_INC
:
234 #ifdef FRACTAL_PRECISION_INC_PRE
235 if (lastbutton
!= FRACTAL_PRECISION_INC_PRE
)
238 if (ops
->precision(+1))
239 redraw
= REDRAW_FULL_OVERLAY
;
245 redraw
= REDRAW_FULL
;
249 if (rb
->default_event_handler_ex(button
, cleanup
, NULL
)
250 == SYS_USB_CONNECTED
)
251 return PLUGIN_USB_CONNECTED
;
255 if (button
!= BUTTON_NONE
)