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 ****************************************************************************/
27 #include "fractal_rect.h"
28 #include "fractal_sets.h"
29 #include "mandelbrot_set.h"
30 #include "lib/pluginlib_exit.h"
34 static unsigned char *gbuf
;
35 static size_t gbuf_size
= 0;
39 #define REDRAW_PARTIAL 1
41 #define REDRAW_FULL_OVERLAY 3
45 /* returns 1 if a button has been pressed, 0 otherwise */
46 static int button_yield(void *ctx
)
48 long *button
= (long *)ctx
;
50 *button
= rb
->button_get(false);
59 case FRACTAL_ZOOM_OUT
:
60 case FRACTAL_PRECISION_INC
:
61 case FRACTAL_PRECISION_DEC
:
63 #ifdef FRACTAL_ZOOM_IN2
64 case FRACTAL_ZOOM_IN2
:
66 #ifdef FRACTAL_ZOOM_IN_PRE
67 case FRACTAL_ZOOM_IN_PRE
:
69 #if defined(FRACTAL_ZOOM_OUT_PRE) && \
70 (FRACTAL_ZOOM_OUT_PRE != FRACTAL_ZOOM_IN_PRE)
71 case FRACTAL_ZOOM_OUT_PRE
:
73 #ifdef FRACTAL_PRECISION_INC_PRE
74 case FRACTAL_PRECISION_INC_PRE
:
76 #if defined(FRACTAL_PRECISION_DEC_PRE) && \
77 (FRACTAL_PRECISION_DEC_PRE != FRACTAL_PRECISION_INC_PRE)
78 case FRACTAL_PRECISION_DEC_PRE
:
82 *button
= BUTTON_NONE
;
87 static void cleanup(void)
94 enum plugin_status
plugin_start(const void* parameter
)
96 #if defined(FRACTAL_ZOOM_OUT_PRE) || \
97 defined(FRACTAL_ZOOM_IN_PRE) || \
98 defined(FRACTAL_PRECISION_DEC_PRE) || \
99 defined(FRACTAL_PRECISION_INC_PRE)
100 long lastbutton
= BUTTON_NONE
;
102 int redraw
= REDRAW_FULL
;
103 struct fractal_ops
*ops
= &mandelbrot_ops
;
108 /* get the remainder of the plugin buffer */
109 gbuf
= (unsigned char *)rb
->plugin_get_buffer(&gbuf_size
);
111 /* initialize the greyscale buffer.*/
112 if (!grey_init(gbuf
, gbuf_size
, GREY_ON_COP
, LCD_WIDTH
, LCD_HEIGHT
, NULL
))
114 rb
->splash(HZ
, "Couldn't init greyscale display");
117 grey_show(true); /* switch on greyscale overlay */
120 /* release greylib on exit */
123 rb
->lcd_set_backdrop(NULL
);
131 long button
= BUTTON_NONE
;
133 if (redraw
!= REDRAW_NONE
)
135 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
141 mylcd_ub_clear_display();
144 case REDRAW_FULL_OVERLAY
:
151 /* paint all rects */
152 rects_calc_all(ops
->calc
, button_yield
, (void *)&button
);
153 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
154 rb
->cpu_boost(false);
156 /* not interrupted by button press - screen is fully drawn */
157 redraw
= (button
== BUTTON_NONE
) ? REDRAW_NONE
: REDRAW_PARTIAL
;
160 if (button
== BUTTON_NONE
)
161 button
= rb
->button_get(true);
165 #ifdef FRACTAL_RC_QUIT
166 case FRACTAL_RC_QUIT
:
171 case FRACTAL_ZOOM_OUT
:
172 #ifdef FRACTAL_ZOOM_OUT_PRE
173 if (lastbutton
!= FRACTAL_ZOOM_OUT_PRE
)
177 redraw
= REDRAW_FULL
;
181 case FRACTAL_ZOOM_IN
:
182 #ifdef FRACTAL_ZOOM_IN_PRE
183 if (lastbutton
!= FRACTAL_ZOOM_IN_PRE
)
186 #ifdef FRACTAL_ZOOM_IN2
187 case FRACTAL_ZOOM_IN2
:
190 redraw
= REDRAW_FULL
;
195 mylcd_ub_scroll_down(LCD_SHIFT_Y
);
197 if (redraw
!= REDRAW_FULL
)
198 redraw
= rects_move_down() ? REDRAW_FULL
: REDRAW_PARTIAL
;
203 mylcd_ub_scroll_up(LCD_SHIFT_Y
);
205 if (redraw
!= REDRAW_FULL
)
206 redraw
= rects_move_up() ? REDRAW_FULL
: REDRAW_PARTIAL
;
211 mylcd_ub_scroll_right(LCD_SHIFT_X
);
213 if (redraw
!= REDRAW_FULL
)
214 redraw
= rects_move_right() ? REDRAW_FULL
: REDRAW_PARTIAL
;
219 mylcd_ub_scroll_left(LCD_SHIFT_X
);
221 if (redraw
!= REDRAW_FULL
)
222 redraw
= rects_move_left() ? REDRAW_FULL
: REDRAW_PARTIAL
;
225 case FRACTAL_PRECISION_DEC
:
226 #ifdef FRACTAL_PRECISION_DEC_PRE
227 if (lastbutton
!= FRACTAL_PRECISION_DEC_PRE
)
230 if (ops
->precision(-1))
231 redraw
= REDRAW_FULL_OVERLAY
;
235 case FRACTAL_PRECISION_INC
:
236 #ifdef FRACTAL_PRECISION_INC_PRE
237 if (lastbutton
!= FRACTAL_PRECISION_INC_PRE
)
240 if (ops
->precision(+1))
241 redraw
= REDRAW_FULL_OVERLAY
;
247 redraw
= REDRAW_FULL
;
254 #if defined(FRACTAL_ZOOM_OUT_PRE) || \
255 defined(FRACTAL_ZOOM_IN_PRE) || \
256 defined(FRACTAL_PRECISION_DEC_PRE) || \
257 defined(FRACTAL_PRECISION_INC_PRE)
258 if (button
!= BUTTON_NONE
)