Fix the statusbar to redraw after changing colors in the color picker screen.
[kugel-rb.git] / apps / menus / theme_menu.c
blob3459e1d0858125919be2e7feace2bfccb0af6859
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 Jonathan Gordon
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include <stdbool.h>
23 #include <stddef.h>
24 #include <limits.h>
25 #include "config.h"
26 #include "lang.h"
27 #include "action.h"
28 #include "settings.h"
29 #include "menu.h"
30 #include "tree.h"
31 #include "list.h"
32 #ifdef HAVE_LCD_BITMAP
33 #include "peakmeter.h"
34 #endif
35 #include "color_picker.h"
36 #include "lcd.h"
37 #include "lcd-remote.h"
38 #include "backdrop.h"
39 #include "exported_menus.h"
40 #include "appevents.h"
41 #include "viewport.h"
43 #if LCD_DEPTH > 1
44 /**
45 * Menu to clear the backdrop image
47 static int clear_main_backdrop(void)
49 global_settings.backdrop_file[0]=0;
50 backdrop_unload(BACKDROP_MAIN);
51 backdrop_show(BACKDROP_MAIN);
52 send_event(GUI_EVENT_REFRESH, NULL);
53 settings_save();
54 return 0;
56 MENUITEM_FUNCTION(clear_main_bd, 0, ID2P(LANG_CLEAR_BACKDROP),
57 clear_main_backdrop, NULL, NULL, Icon_NOICON);
58 #endif
59 #ifdef HAVE_LCD_COLOR
61 enum Colors {
62 COLOR_FG = 0,
63 COLOR_BG,
64 COLOR_LSS,
65 COLOR_LSE,
66 COLOR_LST,
67 COLOR_COUNT
69 static struct colour_info
71 int *setting;
72 int lang_id;
73 } colors[COLOR_COUNT] = {
74 [COLOR_FG] = {&global_settings.fg_color, LANG_FOREGROUND_COLOR},
75 [COLOR_BG] = {&global_settings.bg_color, LANG_BACKGROUND_COLOR},
76 [COLOR_LSS] = {&global_settings.lss_color, LANG_SELECTOR_START_COLOR},
77 [COLOR_LSE] = {&global_settings.lse_color, LANG_SELECTOR_END_COLOR},
78 [COLOR_LST] = {&global_settings.lst_color, LANG_SELECTOR_TEXT_COLOR},
81 /**
82 * Menu for fore/back/selection colors
84 static int set_color_func(void* color)
86 int res, c = (intptr_t)color, banned_color=-1;
88 /* Don't let foreground be set the same as background and vice-versa */
89 if (c == COLOR_BG)
90 banned_color = *colors[COLOR_FG].setting;
91 else if (c == COLOR_FG)
92 banned_color = *colors[COLOR_BG].setting;
94 res = (int)set_color(&screens[SCREEN_MAIN],str(colors[c].lang_id),
95 colors[c].setting, banned_color);
96 settings_save();
97 settings_apply(false);
98 send_event(GUI_EVENT_ACTIONUPDATE, (void*)true);
99 return res;
102 static int reset_color(void)
104 global_settings.fg_color = LCD_DEFAULT_FG;
105 global_settings.bg_color = LCD_DEFAULT_BG;
106 global_settings.lss_color = LCD_DEFAULT_LS;
107 global_settings.lse_color = LCD_DEFAULT_BG;
108 global_settings.lst_color = LCD_DEFAULT_FG;
110 settings_save();
111 settings_apply(false);
112 return 0;
114 MENUITEM_FUNCTION(set_bg_col, MENU_FUNC_USEPARAM, ID2P(LANG_BACKGROUND_COLOR),
115 set_color_func, (void*)COLOR_BG, NULL, Icon_NOICON);
116 MENUITEM_FUNCTION(set_fg_col, MENU_FUNC_USEPARAM, ID2P(LANG_FOREGROUND_COLOR),
117 set_color_func, (void*)COLOR_FG, NULL, Icon_NOICON);
118 MENUITEM_FUNCTION(set_lss_col, MENU_FUNC_USEPARAM, ID2P(LANG_SELECTOR_START_COLOR),
119 set_color_func, (void*)COLOR_LSS, NULL, Icon_NOICON);
120 MENUITEM_FUNCTION(set_lse_col, MENU_FUNC_USEPARAM, ID2P(LANG_SELECTOR_END_COLOR),
121 set_color_func, (void*)COLOR_LSE, NULL, Icon_NOICON);
122 MENUITEM_FUNCTION(set_lst_col, MENU_FUNC_USEPARAM, ID2P(LANG_SELECTOR_TEXT_COLOR),
123 set_color_func, (void*)COLOR_LST, NULL, Icon_NOICON);
124 MENUITEM_FUNCTION(reset_colors, 0, ID2P(LANG_RESET_COLORS),
125 reset_color, NULL, NULL, Icon_NOICON);
127 MAKE_MENU(lss_settings, ID2P(LANG_SELECTOR_COLOR_MENU),
128 NULL, Icon_NOICON,
129 &set_lss_col, &set_lse_col, &set_lst_col
132 /* now the actual menu */
133 MAKE_MENU(colors_settings, ID2P(LANG_COLORS_MENU),
134 NULL, Icon_Display_menu,
135 &lss_settings,
136 &set_bg_col, &set_fg_col, &reset_colors
139 #endif /* HAVE_LCD_COLOR */
140 /* LCD MENU */
141 /***********************************/
144 /************************************/
145 /* BARS MENU */
146 /* */
149 #ifdef HAVE_LCD_BITMAP
150 static int statusbar_callback_ex(int action,const struct menu_item_ex *this_item,
151 enum screen_type screen)
153 (void)this_item;
154 /* we save the old statusbar value here, so the old statusbars can get
155 * removed and cleared from the display properly on exiting
156 * (in gui_statusbar_changed() ) */
157 static enum statusbar_values old_bar[NB_SCREENS];
158 switch (action)
160 case ACTION_ENTER_MENUITEM:
161 old_bar[screen] = statusbar_position(screen);
162 break;
163 case ACTION_EXIT_MENUITEM:
164 gui_statusbar_changed(screen, old_bar[screen]);
165 send_event(GUI_EVENT_STATUSBAR_TOGGLE, NULL);
166 send_event(GUI_EVENT_ACTIONUPDATE, (void*)true);
167 break;
169 return action;
172 #ifdef HAVE_REMOTE_LCD
173 static int statusbar_callback_remote(int action,const struct menu_item_ex *this_item)
175 return statusbar_callback_ex(action, this_item, SCREEN_REMOTE);
177 #endif
178 static int statusbar_callback(int action,const struct menu_item_ex *this_item)
180 return statusbar_callback_ex(action, this_item, SCREEN_MAIN);
183 #ifdef HAVE_BUTTONBAR
184 static int buttonbar_callback(int action, const struct menu_item_ex *this_item)
186 (void)this_item;
187 switch (action)
189 case ACTION_EXIT_MENUITEM:
190 viewportmanager_theme_changed(THEME_BUTTONBAR);
191 break;
193 return ACTION_REDRAW;
195 #endif
196 MENUITEM_SETTING(scrollbar_item, &global_settings.scrollbar, NULL);
197 MENUITEM_SETTING(scrollbar_width, &global_settings.scrollbar_width, NULL);
198 MENUITEM_SETTING(statusbar, &global_settings.statusbar,
199 statusbar_callback);
200 #ifdef HAVE_REMOTE_LCD
201 MENUITEM_SETTING(remote_statusbar, &global_settings.remote_statusbar,
202 statusbar_callback_remote);
203 #endif
204 #ifdef HAVE_BUTTONBAR
205 MENUITEM_SETTING(buttonbar, &global_settings.buttonbar, buttonbar_callback);
206 #endif
207 MENUITEM_SETTING(volume_type, &global_settings.volume_type, NULL);
208 MENUITEM_SETTING(battery_display, &global_settings.battery_display, NULL);
209 MAKE_MENU(bars_menu, ID2P(LANG_BARS_MENU), 0, Icon_NOICON,
210 &scrollbar_item, &scrollbar_width, &statusbar,
211 #ifdef HAVE_REMOTE_LCD
212 &remote_statusbar,
213 #endif
214 #if CONFIG_KEYPAD == RECORDER_PAD
215 &buttonbar,
216 #endif
217 &volume_type, &battery_display);
218 #endif /* HAVE_LCD_BITMAP */
220 /* */
221 /* BARS MENU */
222 /************************************/
224 #ifdef HAVE_LCD_BITMAP
225 static struct browse_folder_info fonts = {FONT_DIR, SHOW_FONT};
226 #endif
227 static struct browse_folder_info wps = {WPS_DIR, SHOW_WPS};
228 #ifdef HAVE_REMOTE_LCD
229 static struct browse_folder_info rwps = {WPS_DIR, SHOW_RWPS};
230 #endif
231 static struct browse_folder_info themes = {THEME_DIR, SHOW_CFG};
233 int browse_folder(void *param)
235 const struct browse_folder_info *info =
236 (const struct browse_folder_info*)param;
237 return rockbox_browse(info->dir, info->show_options);
240 #ifdef HAVE_LCD_BITMAP
241 MENUITEM_FUNCTION(browse_fonts, MENU_FUNC_USEPARAM,
242 ID2P(LANG_CUSTOM_FONT),
243 browse_folder, (void*)&fonts, NULL, Icon_Font);
244 #endif
245 MENUITEM_FUNCTION(browse_wps, MENU_FUNC_USEPARAM,
246 ID2P(LANG_WHILE_PLAYING),
247 browse_folder, (void*)&wps, NULL, Icon_Wps);
248 #ifdef HAVE_REMOTE_LCD
249 MENUITEM_FUNCTION(browse_rwps, MENU_FUNC_USEPARAM,
250 ID2P(LANG_REMOTE_WHILE_PLAYING),
251 browse_folder, (void*)&rwps, NULL, Icon_Wps);
252 #endif
254 MENUITEM_SETTING(show_icons, &global_settings.show_icons, NULL);
255 MENUITEM_FUNCTION(browse_themes, MENU_FUNC_USEPARAM,
256 ID2P(LANG_CUSTOM_THEME),
257 browse_folder, (void*)&themes, NULL, Icon_Config);
258 #ifdef HAVE_LCD_BITMAP
259 MENUITEM_SETTING(cursor_style, &global_settings.cursor_style, NULL);
260 #endif
262 MAKE_MENU(theme_menu, ID2P(LANG_THEME_MENU),
263 NULL, Icon_Wps,
264 &browse_themes,
265 #ifdef HAVE_LCD_BITMAP
266 &browse_fonts,
267 #endif
268 &browse_wps,
269 #ifdef HAVE_REMOTE_LCD
270 &browse_rwps,
271 #endif
272 &show_icons,
273 #if LCD_DEPTH > 1
274 &clear_main_bd,
275 #endif
276 #ifdef HAVE_LCD_BITMAP
277 &bars_menu,
278 &cursor_style,
279 #endif
280 #ifdef HAVE_LCD_COLOR
281 &colors_settings,
282 #endif