Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2008 by Jonathan Gordon |
| 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame] | 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. |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
| 21 | |
Bertrik Sikken | 2843469 | 2008-04-28 16:18:04 +0000 | [diff] [blame] | 22 | #include <stdlib.h> |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 23 | #include "config.h" |
| 24 | #include "lcd.h" |
Dave Chapman | 2b7d48e | 2008-03-09 23:53:46 +0000 | [diff] [blame] | 25 | #include "lcd-remote.h" |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 26 | #include "font.h" |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 27 | #include "viewport.h" |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 28 | #include "screen_access.h" |
Thomas Martitz | c0f1c49 | 2009-09-13 13:40:58 +0000 | [diff] [blame] | 29 | #include "settings.h" |
| 30 | #include "misc.h" |
Thomas Martitz | 9bd7b23 | 2009-08-09 16:16:55 +0000 | [diff] [blame] | 31 | |
Thomas Martitz | e4bdc08 | 2009-08-12 13:04:12 +0000 | [diff] [blame] | 32 | /*some short cuts for fg/bg/line selector handling */ |
Thomas Martitz | 9f3fc27 | 2009-08-09 17:39:39 +0000 | [diff] [blame] | 33 | #ifdef HAVE_LCD_COLOR |
Thomas Martitz | 9f3fc27 | 2009-08-09 17:39:39 +0000 | [diff] [blame] | 34 | #define FG_FALLBACK global_settings.fg_color |
| 35 | #define BG_FALLBACK global_settings.bg_color |
| 36 | #else |
| 37 | #define FG_FALLBACK LCD_DEFAULT_FG |
Thomas Martitz | e4bdc08 | 2009-08-12 13:04:12 +0000 | [diff] [blame] | 38 | #define BG_FALLBACK LCD_DEFAULT_BG |
Thomas Martitz | 9f3fc27 | 2009-08-09 17:39:39 +0000 | [diff] [blame] | 39 | #endif |
Jonathan Gordon | 5c7be3e | 2010-05-25 04:02:09 +0000 | [diff] [blame] | 40 | #ifdef HAVE_REMOTE_LCD |
| 41 | #define REMOTE_FG_FALLBACK LCD_REMOTE_DEFAULT_FG |
| 42 | #define REMOTE_BG_FALLBACK LCD_REMOTE_DEFAULT_BG |
| 43 | #endif |
| 44 | |
Thomas Martitz | 9bd7b23 | 2009-08-09 16:16:55 +0000 | [diff] [blame] | 45 | |
Thomas Martitz | c0f1c49 | 2009-09-13 13:40:58 +0000 | [diff] [blame] | 46 | /* all below isn't needed for pc tools (i.e. checkwps/wps editor) |
| 47 | * only viewport_parse_viewport() is */ |
| 48 | #ifndef __PCTOOL__ |
Thomas Martitz | c0f1c49 | 2009-09-13 13:40:58 +0000 | [diff] [blame] | 49 | #include "string.h" |
| 50 | #include "kernel.h" |
| 51 | #include "system.h" |
| 52 | #include "statusbar.h" |
| 53 | #include "appevents.h" |
Jonathan Gordon | dd9fbbf | 2009-12-09 07:44:08 +0000 | [diff] [blame] | 54 | #include "panic.h" |
Tomer Shalev | 5da7507 | 2009-10-05 21:32:29 +0000 | [diff] [blame] | 55 | #ifdef HAVE_LCD_BITMAP |
Tomer Shalev | b0a9938 | 2009-10-05 21:13:55 +0000 | [diff] [blame] | 56 | #include "language.h" |
Tomer Shalev | 5da7507 | 2009-10-05 21:32:29 +0000 | [diff] [blame] | 57 | #endif |
Thomas Martitz | 1016ee4 | 2009-10-19 15:28:15 +0000 | [diff] [blame] | 58 | #include "statusbar-skinned.h" |
| 59 | #include "debug.h" |
| 60 | |
Jonathan Gordon | b2eb44c | 2009-12-09 07:25:46 +0000 | [diff] [blame] | 61 | #define VPSTACK_DEPTH 16 |
| 62 | struct viewport_stack_item |
| 63 | { |
| 64 | struct viewport* vp; |
| 65 | bool enabled; |
| 66 | }; |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 67 | |
Thomas Martitz | 4c48b59 | 2009-08-16 22:20:11 +0000 | [diff] [blame] | 68 | #ifdef HAVE_LCD_BITMAP |
Jonathan Gordon | b2eb44c | 2009-12-09 07:25:46 +0000 | [diff] [blame] | 69 | static void viewportmanager_redraw(void* data); |
Teruaki Kawashima | 38efc71 | 2010-02-28 14:12:41 +0000 | [diff] [blame] | 70 | |
Jonathan Gordon | b2eb44c | 2009-12-09 07:25:46 +0000 | [diff] [blame] | 71 | static int theme_stack_top[NB_SCREENS]; /* the last item added */ |
| 72 | static struct viewport_stack_item theme_stack[NB_SCREENS][VPSTACK_DEPTH]; |
| 73 | static bool is_theme_enabled(enum screen_type screen); |
Thomas Martitz | 4c48b59 | 2009-08-16 22:20:11 +0000 | [diff] [blame] | 74 | |
Thomas Martitz | feb3a26 | 2010-01-27 20:34:51 +0000 | [diff] [blame] | 75 | |
| 76 | static void toggle_events(bool enable) |
Jonathan Gordon | b2eb44c | 2009-12-09 07:25:46 +0000 | [diff] [blame] | 77 | { |
Thomas Martitz | feb3a26 | 2010-01-27 20:34:51 +0000 | [diff] [blame] | 78 | if (enable) |
Jonathan Gordon | b2eb44c | 2009-12-09 07:25:46 +0000 | [diff] [blame] | 79 | { |
| 80 | add_event(GUI_EVENT_ACTIONUPDATE, false, viewportmanager_redraw); |
| 81 | #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP) |
| 82 | add_event(LCD_EVENT_ACTIVATION, false, do_sbs_update_callback); |
| 83 | #endif |
| 84 | add_event(PLAYBACK_EVENT_TRACK_CHANGE, false, |
| 85 | do_sbs_update_callback); |
| 86 | add_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE, false, |
| 87 | do_sbs_update_callback); |
Thomas Martitz | feb3a26 | 2010-01-27 20:34:51 +0000 | [diff] [blame] | 88 | } |
| 89 | else |
| 90 | { |
| 91 | #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP) |
| 92 | remove_event(LCD_EVENT_ACTIVATION, do_sbs_update_callback); |
| 93 | #endif |
| 94 | remove_event(PLAYBACK_EVENT_TRACK_CHANGE, do_sbs_update_callback); |
| 95 | remove_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE, do_sbs_update_callback); |
| 96 | remove_event(GUI_EVENT_ACTIONUPDATE, viewportmanager_redraw); |
Teruaki Kawashima | 38efc71 | 2010-02-28 14:12:41 +0000 | [diff] [blame] | 97 | } |
Thomas Martitz | feb3a26 | 2010-01-27 20:34:51 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | |
| 101 | static void toggle_theme(enum screen_type screen, bool force) |
| 102 | { |
| 103 | bool enable_event = false; |
| 104 | static bool was_enabled[NB_SCREENS] = {false}; |
Thomas Martitz | 81ebf2b | 2010-02-27 21:19:34 +0000 | [diff] [blame] | 105 | static bool after_boot[NB_SCREENS] = {false}; |
Thomas Martitz | feb3a26 | 2010-01-27 20:34:51 +0000 | [diff] [blame] | 106 | int i; |
| 107 | |
| 108 | FOR_NB_SCREENS(i) |
| 109 | { |
| 110 | enable_event = enable_event || is_theme_enabled(i); |
Jonathan Gordon | 466e5d9 | 2010-02-26 03:45:41 +0000 | [diff] [blame] | 111 | sb_set_title_text(NULL, Icon_NOICON, i); |
Thomas Martitz | feb3a26 | 2010-01-27 20:34:51 +0000 | [diff] [blame] | 112 | } |
| 113 | toggle_events(enable_event); |
| 114 | |
| 115 | if (is_theme_enabled(screen)) |
| 116 | { |
Jonathan Gordon | 4c6b355 | 2010-02-26 08:01:41 +0000 | [diff] [blame] | 117 | bool first_boot = theme_stack_top[screen] == 0; |
Jonathan Gordon | b2eb44c | 2009-12-09 07:25:46 +0000 | [diff] [blame] | 118 | /* remove the left overs from the previous screen. |
| 119 | * could cause a tiny flicker. Redo your screen code if that happens */ |
Jonathan Gordon | 9955e9a | 2010-02-08 17:19:15 +0000 | [diff] [blame] | 120 | #if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1 |
Jonathan Gordon | fd2fdc2 | 2010-02-10 04:19:50 +0000 | [diff] [blame] | 121 | screens[screen].backdrop_show(sb_get_backdrop(screen)); |
Jonathan Gordon | 9955e9a | 2010-02-08 17:19:15 +0000 | [diff] [blame] | 122 | #endif |
Thomas Martitz | 81ebf2b | 2010-02-27 21:19:34 +0000 | [diff] [blame] | 123 | if (LIKELY(after_boot[screen]) && (!was_enabled[screen] || force)) |
Jonathan Gordon | b2eb44c | 2009-12-09 07:25:46 +0000 | [diff] [blame] | 124 | { |
Jonathan Gordon | 9d1832c | 2009-12-21 05:19:12 +0000 | [diff] [blame] | 125 | struct viewport deadspace, user; |
| 126 | viewport_set_defaults(&user, screen); |
| 127 | deadspace = user; /* get colours and everything */ |
| 128 | /* above */ |
| 129 | deadspace.x = 0; |
| 130 | deadspace.y = 0; |
| 131 | deadspace.width = screens[screen].lcdwidth; |
| 132 | deadspace.height = user.y; |
| 133 | if (deadspace.width && deadspace.height) |
Jonathan Gordon | b2eb44c | 2009-12-09 07:25:46 +0000 | [diff] [blame] | 134 | { |
Jonathan Gordon | 9d1832c | 2009-12-21 05:19:12 +0000 | [diff] [blame] | 135 | screens[screen].set_viewport(&deadspace); |
| 136 | screens[screen].clear_viewport(); |
| 137 | screens[screen].update_viewport(); |
| 138 | } |
| 139 | /* below */ |
| 140 | deadspace.y = user.y + user.height; |
| 141 | deadspace.height = screens[screen].lcdheight - deadspace.y; |
| 142 | if (deadspace.width && deadspace.height) |
| 143 | { |
| 144 | screens[screen].set_viewport(&deadspace); |
| 145 | screens[screen].clear_viewport(); |
| 146 | screens[screen].update_viewport(); |
| 147 | } |
| 148 | /* left */ |
| 149 | deadspace.x = 0; |
| 150 | deadspace.y = 0; |
| 151 | deadspace.width = user.x; |
| 152 | deadspace.height = screens[screen].lcdheight; |
| 153 | if (deadspace.width && deadspace.height) |
| 154 | { |
| 155 | screens[screen].set_viewport(&deadspace); |
| 156 | screens[screen].clear_viewport(); |
| 157 | screens[screen].update_viewport(); |
| 158 | } |
| 159 | /* below */ |
| 160 | deadspace.x = user.x + user.width; |
| 161 | deadspace.width = screens[screen].lcdwidth - deadspace.x; |
| 162 | if (deadspace.width && deadspace.height) |
| 163 | { |
| 164 | screens[screen].set_viewport(&deadspace); |
| 165 | screens[screen].clear_viewport(); |
| 166 | screens[screen].update_viewport(); |
Jonathan Gordon | b2eb44c | 2009-12-09 07:25:46 +0000 | [diff] [blame] | 167 | } |
Teruaki Kawashima | 38efc71 | 2010-02-28 14:12:41 +0000 | [diff] [blame] | 168 | screens[screen].set_viewport(NULL); |
Jonathan Gordon | b2eb44c | 2009-12-09 07:25:46 +0000 | [diff] [blame] | 169 | } |
Jonathan Gordon | 92f0aa8 | 2010-02-26 08:43:26 +0000 | [diff] [blame] | 170 | intptr_t force = first_boot?0:1; |
Jonathan Gordon | a398c28 | 2010-06-21 06:04:19 +0000 | [diff] [blame] | 171 | |
Jonathan Gordon | 92f0aa8 | 2010-02-26 08:43:26 +0000 | [diff] [blame] | 172 | send_event(GUI_EVENT_ACTIONUPDATE, (void*)force); |
Jonathan Gordon | b2eb44c | 2009-12-09 07:25:46 +0000 | [diff] [blame] | 173 | } |
| 174 | else |
| 175 | { |
Thomas Martitz | e18e806 | 2010-01-27 20:45:42 +0000 | [diff] [blame] | 176 | #if LCD_DEPTH > 1 || (defined(LCD_REMOTE_DEPTH) && LCD_REMOTE_DEPTH > 1) |
Jonathan Gordon | eee5423 | 2010-01-29 07:52:13 +0000 | [diff] [blame] | 177 | screens[screen].backdrop_show(NULL); |
Jonathan Gordon | 2565389 | 2010-01-27 06:47:56 +0000 | [diff] [blame] | 178 | #endif |
Thomas Martitz | feb3a26 | 2010-01-27 20:34:51 +0000 | [diff] [blame] | 179 | screens[screen].stop_scroll(); |
Jonathan Gordon | b2eb44c | 2009-12-09 07:25:46 +0000 | [diff] [blame] | 180 | } |
Jonathan Gordon | 0900b56 | 2009-12-18 06:51:36 +0000 | [diff] [blame] | 181 | /* let list initialize viewport in case viewport dimensions is changed. */ |
| 182 | send_event(GUI_EVENT_THEME_CHANGED, NULL); |
Jonathan Gordon | b2eb44c | 2009-12-09 07:25:46 +0000 | [diff] [blame] | 183 | FOR_NB_SCREENS(i) |
| 184 | was_enabled[i] = is_theme_enabled(i); |
Jonathan Gordon | a398c28 | 2010-06-21 06:04:19 +0000 | [diff] [blame] | 185 | #ifdef HAVE_TOUCHSCREEN |
| 186 | sb_bypass_touchregions(!is_theme_enabled(SCREEN_MAIN)); |
| 187 | #endif |
Thomas Martitz | 81ebf2b | 2010-02-27 21:19:34 +0000 | [diff] [blame] | 188 | after_boot[screen] = true; |
Jonathan Gordon | b2eb44c | 2009-12-09 07:25:46 +0000 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | void viewportmanager_theme_enable(enum screen_type screen, bool enable, |
| 192 | struct viewport *viewport) |
| 193 | { |
| 194 | int top = ++theme_stack_top[screen]; |
| 195 | if (top >= VPSTACK_DEPTH-1) |
| 196 | panicf("Stack overflow... viewportmanager"); |
| 197 | theme_stack[screen][top].enabled = enable; |
| 198 | theme_stack[screen][top].vp = viewport; |
Jonathan Gordon | 9d1832c | 2009-12-21 05:19:12 +0000 | [diff] [blame] | 199 | toggle_theme(screen, false); |
Jonathan Gordon | b2eb44c | 2009-12-09 07:25:46 +0000 | [diff] [blame] | 200 | /* then be nice and set the viewport up */ |
| 201 | if (viewport) |
| 202 | viewport_set_defaults(viewport, screen); |
| 203 | } |
| 204 | |
Jonathan Gordon | 9d1832c | 2009-12-21 05:19:12 +0000 | [diff] [blame] | 205 | void viewportmanager_theme_undo(enum screen_type screen, bool force_redraw) |
Jonathan Gordon | b2eb44c | 2009-12-09 07:25:46 +0000 | [diff] [blame] | 206 | { |
| 207 | int top = --theme_stack_top[screen]; |
| 208 | if (top < 0) |
| 209 | panicf("Stack underflow... viewportmanager"); |
| 210 | |
Jonathan Gordon | 9d1832c | 2009-12-21 05:19:12 +0000 | [diff] [blame] | 211 | toggle_theme(screen, force_redraw); |
Jonathan Gordon | b2eb44c | 2009-12-09 07:25:46 +0000 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | |
| 215 | static bool is_theme_enabled(enum screen_type screen) |
| 216 | { |
| 217 | int top = theme_stack_top[screen]; |
| 218 | return theme_stack[screen][top].enabled; |
| 219 | } |
Jonathan Gordon | b2eb44c | 2009-12-09 07:25:46 +0000 | [diff] [blame] | 220 | #endif /* HAVE_LCD_BITMAP */ |
Thomas Martitz | 4c48b59 | 2009-08-16 22:20:11 +0000 | [diff] [blame] | 221 | |
Nils Wallménius | 3c1e2c1 | 2009-10-10 08:29:13 +0000 | [diff] [blame] | 222 | int viewport_get_nb_lines(const struct viewport *vp) |
Jonathan Gordon | 0e5cec2 | 2008-03-05 09:58:30 +0000 | [diff] [blame] | 223 | { |
| 224 | #ifdef HAVE_LCD_BITMAP |
| 225 | return vp->height/font_get(vp->font)->height; |
| 226 | #else |
| 227 | (void)vp; |
| 228 | return 2; |
| 229 | #endif |
| 230 | } |
| 231 | |
Thomas Martitz | 4c48b59 | 2009-08-16 22:20:11 +0000 | [diff] [blame] | 232 | static void viewportmanager_redraw(void* data) |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 233 | { |
Jonathan Gordon | 80cb355 | 2009-02-01 11:34:16 +0000 | [diff] [blame] | 234 | int i; |
| 235 | FOR_NB_SCREENS(i) |
| 236 | { |
Jonathan Gordon | b2eb44c | 2009-12-09 07:25:46 +0000 | [diff] [blame] | 237 | #ifdef HAVE_LCD_BITMAP |
Jonathan Gordon | 1759a29 | 2010-03-13 22:26:03 +0000 | [diff] [blame] | 238 | if (is_theme_enabled(i)) |
| 239 | sb_skin_update(i, NULL != data); |
Jonathan Gordon | a9b5f4d | 2010-03-06 00:29:46 +0000 | [diff] [blame] | 240 | #else |
Jonathan Gordon | f1b209c | 2010-03-06 00:37:01 +0000 | [diff] [blame] | 241 | (void)data; |
Jonathan Gordon | a9b5f4d | 2010-03-06 00:29:46 +0000 | [diff] [blame] | 242 | gui_statusbar_draw(&statusbars.statusbars[i], NULL, NULL); |
Jonathan Gordon | b2eb44c | 2009-12-09 07:25:46 +0000 | [diff] [blame] | 243 | #endif |
Thomas Martitz | 4c48b59 | 2009-08-16 22:20:11 +0000 | [diff] [blame] | 244 | } |
| 245 | } |
Thomas Martitz | 4c48b59 | 2009-08-16 22:20:11 +0000 | [diff] [blame] | 246 | |
Jonathan Gordon | b2eb44c | 2009-12-09 07:25:46 +0000 | [diff] [blame] | 247 | void viewportmanager_init() |
Thomas Martitz | 4c48b59 | 2009-08-16 22:20:11 +0000 | [diff] [blame] | 248 | { |
Jonathan Gordon | b2eb44c | 2009-12-09 07:25:46 +0000 | [diff] [blame] | 249 | #ifdef HAVE_LCD_BITMAP |
| 250 | int i; |
| 251 | FOR_NB_SCREENS(i) |
| 252 | { |
| 253 | theme_stack_top[i] = -1; /* the next call fixes this to 0 */ |
| 254 | /* We always want the theme enabled by default... */ |
Teruaki Kawashima | 38efc71 | 2010-02-28 14:12:41 +0000 | [diff] [blame] | 255 | viewportmanager_theme_enable(i, true, NULL); |
Jonathan Gordon | b2eb44c | 2009-12-09 07:25:46 +0000 | [diff] [blame] | 256 | } |
| 257 | #else |
| 258 | add_event(GUI_EVENT_ACTIONUPDATE, false, viewportmanager_redraw); |
| 259 | #endif |
Thomas Martitz | 4c48b59 | 2009-08-16 22:20:11 +0000 | [diff] [blame] | 260 | } |
| 261 | |
Jonathan Gordon | b2eb44c | 2009-12-09 07:25:46 +0000 | [diff] [blame] | 262 | #ifdef HAVE_LCD_BITMAP |
Thomas Martitz | a27f2b8 | 2009-10-11 00:05:12 +0000 | [diff] [blame] | 263 | void viewportmanager_theme_changed(const int which) |
Thomas Martitz | 4c48b59 | 2009-08-16 22:20:11 +0000 | [diff] [blame] | 264 | { |
Thomas Martitz | 90a29dd | 2009-08-29 15:46:32 +0000 | [diff] [blame] | 265 | int i; |
Thomas Martitz | 2eb1cb6 | 2009-09-07 17:37:06 +0000 | [diff] [blame] | 266 | #ifdef HAVE_BUTTONBAR |
| 267 | if (which & THEME_BUTTONBAR) |
| 268 | { /* don't handle further, the custom ui viewport ignores the buttonbar, |
| 269 | * as does viewport_set_defaults(), since only lists use it*/ |
| 270 | screens[SCREEN_MAIN].has_buttonbar = global_settings.buttonbar; |
| 271 | } |
| 272 | #endif |
Thomas Martitz | 4c48b59 | 2009-08-16 22:20:11 +0000 | [diff] [blame] | 273 | if (which & THEME_UI_VIEWPORT) |
| 274 | { |
Thomas Martitz | 4c48b59 | 2009-08-16 22:20:11 +0000 | [diff] [blame] | 275 | } |
Jonathan Gordon | b2eb44c | 2009-12-09 07:25:46 +0000 | [diff] [blame] | 276 | if (which & THEME_LANGUAGE) |
Teruaki Kawashima | 38efc71 | 2010-02-28 14:12:41 +0000 | [diff] [blame] | 277 | { |
Thomas Martitz | 80003bc | 2009-10-09 18:39:34 +0000 | [diff] [blame] | 278 | } |
Thomas Martitz | 4c48b59 | 2009-08-16 22:20:11 +0000 | [diff] [blame] | 279 | if (which & THEME_STATUSBAR) |
| 280 | { |
Thomas Martitz | 94f7651 | 2009-10-16 20:34:04 +0000 | [diff] [blame] | 281 | FOR_NB_SCREENS(i) |
| 282 | { |
Jonathan Gordon | b2eb44c | 2009-12-09 07:25:46 +0000 | [diff] [blame] | 283 | /* This can probably be done better... |
| 284 | * disable the theme so it's forced to do a full redraw */ |
| 285 | viewportmanager_theme_enable(i, false, NULL); |
Jonathan Gordon | 9d1832c | 2009-12-21 05:19:12 +0000 | [diff] [blame] | 286 | viewportmanager_theme_undo(i, true); |
Thomas Martitz | 4c48b59 | 2009-08-16 22:20:11 +0000 | [diff] [blame] | 287 | } |
Jonathan Gordon | 80cb355 | 2009-02-01 11:34:16 +0000 | [diff] [blame] | 288 | } |
Thomas Martitz | 2eb1cb6 | 2009-09-07 17:37:06 +0000 | [diff] [blame] | 289 | send_event(GUI_EVENT_THEME_CHANGED, NULL); |
Jonathan Gordon | e385ee1 | 2008-12-31 05:59:26 +0000 | [diff] [blame] | 290 | } |
| 291 | |
Thomas Martitz | c0f1c49 | 2009-09-13 13:40:58 +0000 | [diff] [blame] | 292 | #ifdef HAVE_TOUCHSCREEN |
| 293 | /* check if a point (x and y coordinates) are within a viewport */ |
Thomas Martitz | a27f2b8 | 2009-10-11 00:05:12 +0000 | [diff] [blame] | 294 | bool viewport_point_within_vp(const struct viewport *vp, |
| 295 | const int x, const int y) |
Thomas Martitz | c0f1c49 | 2009-09-13 13:40:58 +0000 | [diff] [blame] | 296 | { |
| 297 | bool is_x = (x >= vp->x && x < (vp->x + vp->width)); |
| 298 | bool is_y = (y >= vp->y && y < (vp->y + vp->height)); |
| 299 | return (is_x && is_y); |
| 300 | } |
| 301 | #endif /* HAVE_TOUCHSCREEN */ |
Jonathan Gordon | b2eb44c | 2009-12-09 07:25:46 +0000 | [diff] [blame] | 302 | |
| 303 | static void set_default_align_flags(struct viewport *vp) |
| 304 | { |
| 305 | vp->flags &= ~VP_FLAG_ALIGNMENT_MASK; |
Jonathan Gordon | b2eb44c | 2009-12-09 07:25:46 +0000 | [diff] [blame] | 306 | if (UNLIKELY(lang_is_rtl())) |
| 307 | vp->flags |= VP_FLAG_ALIGN_RIGHT; |
Jonathan Gordon | b2eb44c | 2009-12-09 07:25:46 +0000 | [diff] [blame] | 308 | } |
| 309 | |
Thomas Martitz | c0f1c49 | 2009-09-13 13:40:58 +0000 | [diff] [blame] | 310 | #endif /* HAVE_LCD_BITMAP */ |
| 311 | #endif /* __PCTOOL__ */ |
| 312 | |
Thomas Martitz | a1b0e16 | 2009-08-09 18:44:49 +0000 | [diff] [blame] | 313 | #ifdef HAVE_LCD_COLOR |
Thomas Martitz | e4bdc08 | 2009-08-12 13:04:12 +0000 | [diff] [blame] | 314 | #define ARG_STRING(_depth) ((_depth) == 2 ? "dddddgg":"dddddcc") |
Thomas Martitz | a1b0e16 | 2009-08-09 18:44:49 +0000 | [diff] [blame] | 315 | #else |
Thomas Martitz | e4bdc08 | 2009-08-12 13:04:12 +0000 | [diff] [blame] | 316 | #define ARG_STRING(_depth) "dddddgg" |
Thomas Martitz | a1b0e16 | 2009-08-09 18:44:49 +0000 | [diff] [blame] | 317 | #endif |
| 318 | |
Thomas Martitz | 6750d65 | 2009-11-04 06:56:04 +0000 | [diff] [blame] | 319 | |
| 320 | void viewport_set_fullscreen(struct viewport *vp, |
| 321 | const enum screen_type screen) |
| 322 | { |
| 323 | vp->x = 0; |
| 324 | vp->y = 0; |
| 325 | vp->width = screens[screen].lcdwidth; |
| 326 | vp->height = screens[screen].lcdheight; |
| 327 | |
| 328 | #ifdef HAVE_LCD_BITMAP |
Jonathan Gordon | dd9fbbf | 2009-12-09 07:44:08 +0000 | [diff] [blame] | 329 | #ifndef __PCTOOL__ |
Thomas Martitz | 6750d65 | 2009-11-04 06:56:04 +0000 | [diff] [blame] | 330 | set_default_align_flags(vp); |
Jonathan Gordon | dd9fbbf | 2009-12-09 07:44:08 +0000 | [diff] [blame] | 331 | #endif |
Jonathan Gordon | 1c2aa35 | 2010-02-14 06:26:16 +0000 | [diff] [blame] | 332 | vp->font = FONT_UI + screen; /* default to UI to discourage SYSFONT use */ |
Thomas Martitz | 6750d65 | 2009-11-04 06:56:04 +0000 | [diff] [blame] | 333 | vp->drawmode = DRMODE_SOLID; |
| 334 | #if LCD_DEPTH > 1 |
| 335 | #ifdef HAVE_REMOTE_LCD |
| 336 | /* We only need this test if there is a remote LCD */ |
| 337 | if (screen == SCREEN_MAIN) |
| 338 | #endif |
| 339 | { |
| 340 | vp->fg_pattern = FG_FALLBACK; |
| 341 | vp->bg_pattern = BG_FALLBACK; |
| 342 | #ifdef HAVE_LCD_COLOR |
| 343 | vp->lss_pattern = global_settings.lss_color; |
| 344 | vp->lse_pattern = global_settings.lse_color; |
| 345 | vp->lst_pattern = global_settings.lst_color; |
| 346 | #endif |
| 347 | } |
| 348 | #endif |
| 349 | |
| 350 | #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1 |
| 351 | if (screen == SCREEN_REMOTE) |
| 352 | { |
| 353 | vp->fg_pattern = LCD_REMOTE_DEFAULT_FG; |
| 354 | vp->bg_pattern = LCD_REMOTE_DEFAULT_BG; |
| 355 | } |
| 356 | #endif |
| 357 | #endif |
| 358 | } |
| 359 | |
| 360 | void viewport_set_defaults(struct viewport *vp, |
| 361 | const enum screen_type screen) |
| 362 | { |
Thomas Martitz | 6750d65 | 2009-11-04 06:56:04 +0000 | [diff] [blame] | 363 | #if defined(HAVE_LCD_BITMAP) && !defined(__PCTOOL__) |
Jonathan Gordon | eee5423 | 2010-01-29 07:52:13 +0000 | [diff] [blame] | 364 | struct viewport *sbs_area = NULL; |
Jonathan Gordon | b2eb44c | 2009-12-09 07:25:46 +0000 | [diff] [blame] | 365 | if (!is_theme_enabled(screen)) |
Jonathan Gordon | eee5423 | 2010-01-29 07:52:13 +0000 | [diff] [blame] | 366 | { |
Teruaki Kawashima | 38efc71 | 2010-02-28 14:12:41 +0000 | [diff] [blame] | 367 | viewport_set_fullscreen(vp, screen); |
| 368 | return; |
Thomas Martitz | 6750d65 | 2009-11-04 06:56:04 +0000 | [diff] [blame] | 369 | } |
Jonathan Gordon | eee5423 | 2010-01-29 07:52:13 +0000 | [diff] [blame] | 370 | sbs_area = sb_skin_get_info_vp(screen); |
| 371 | |
Thomas Martitz | e9c900d | 2009-11-04 21:08:21 +0000 | [diff] [blame] | 372 | if (sbs_area) |
Thomas Martitz | 6750d65 | 2009-11-04 06:56:04 +0000 | [diff] [blame] | 373 | *vp = *sbs_area; |
Teruaki Kawashima | 38efc71 | 2010-02-28 14:12:41 +0000 | [diff] [blame] | 374 | else |
Thomas Martitz | 6750d65 | 2009-11-04 06:56:04 +0000 | [diff] [blame] | 375 | #endif /* HAVE_LCD_BITMAP */ |
Teruaki Kawashima | 38efc71 | 2010-02-28 14:12:41 +0000 | [diff] [blame] | 376 | viewport_set_fullscreen(vp, screen); |
Thomas Martitz | 6750d65 | 2009-11-04 06:56:04 +0000 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | |
Thomas Martitz | c0f1c49 | 2009-09-13 13:40:58 +0000 | [diff] [blame] | 380 | #ifdef HAVE_LCD_BITMAP |
Jonathan Gordon | 5b0521c | 2010-06-07 03:44:11 +0000 | [diff] [blame] | 381 | |
| 382 | int get_viewport_default_colour(enum screen_type screen, bool fgcolour) |
| 383 | { |
Jonathan Gordon | 4f3fb96 | 2010-06-07 04:11:49 +0000 | [diff] [blame] | 384 | (void)screen; (void)fgcolour; |
Jonathan Gordon | 5b0521c | 2010-06-07 03:44:11 +0000 | [diff] [blame] | 385 | #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) |
Jonathan Gordon | 4e0b47c | 2010-06-07 04:00:39 +0000 | [diff] [blame] | 386 | int colour; |
Jonathan Gordon | 5b0521c | 2010-06-07 03:44:11 +0000 | [diff] [blame] | 387 | if (fgcolour) |
| 388 | { |
| 389 | #if (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) |
| 390 | if (screen == SCREEN_REMOTE) |
| 391 | colour = REMOTE_FG_FALLBACK; |
| 392 | else |
| 393 | #endif |
Jonathan Gordon | 3245513 | 2010-06-07 03:55:40 +0000 | [diff] [blame] | 394 | #if defined(HAVE_LCD_COLOR) |
Jonathan Gordon | 5b0521c | 2010-06-07 03:44:11 +0000 | [diff] [blame] | 395 | colour = global_settings.fg_color; |
Jonathan Gordon | 3245513 | 2010-06-07 03:55:40 +0000 | [diff] [blame] | 396 | #else |
| 397 | colour = FG_FALLBACK; |
| 398 | #endif |
Jonathan Gordon | 5b0521c | 2010-06-07 03:44:11 +0000 | [diff] [blame] | 399 | } |
| 400 | else |
| 401 | { |
| 402 | #if (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) |
| 403 | if (screen == SCREEN_REMOTE) |
| 404 | colour = REMOTE_BG_FALLBACK; |
| 405 | else |
| 406 | #endif |
Jonathan Gordon | 3245513 | 2010-06-07 03:55:40 +0000 | [diff] [blame] | 407 | #if defined(HAVE_LCD_COLOR) |
Jonathan Gordon | 5b0521c | 2010-06-07 03:44:11 +0000 | [diff] [blame] | 408 | colour = global_settings.bg_color; |
Jonathan Gordon | 3245513 | 2010-06-07 03:55:40 +0000 | [diff] [blame] | 409 | #else |
| 410 | colour = BG_FALLBACK; |
| 411 | #endif |
Jonathan Gordon | 5b0521c | 2010-06-07 03:44:11 +0000 | [diff] [blame] | 412 | } |
Jonathan Gordon | 5b0521c | 2010-06-07 03:44:11 +0000 | [diff] [blame] | 413 | return colour; |
Jonathan Gordon | 4e0b47c | 2010-06-07 04:00:39 +0000 | [diff] [blame] | 414 | #else |
| 415 | return 0; |
| 416 | #endif /* LCD_DEPTH > 1 || LCD_REMOTE_DEPTH > 1 */ |
Jonathan Gordon | 5b0521c | 2010-06-07 03:44:11 +0000 | [diff] [blame] | 417 | } |
| 418 | |
Thomas Martitz | 9bd7b23 | 2009-08-09 16:16:55 +0000 | [diff] [blame] | 419 | const char* viewport_parse_viewport(struct viewport *vp, |
| 420 | enum screen_type screen, |
| 421 | const char *bufptr, |
| 422 | const char separator) |
| 423 | { |
| 424 | /* parse the list to the viewport struct */ |
| 425 | const char *ptr = bufptr; |
Thomas Martitz | 9bd7b23 | 2009-08-09 16:16:55 +0000 | [diff] [blame] | 426 | uint32_t set = 0; |
| 427 | |
| 428 | enum { |
| 429 | PL_X = 0, |
| 430 | PL_Y, |
| 431 | PL_WIDTH, |
| 432 | PL_HEIGHT, |
| 433 | PL_FONT, |
Thomas Martitz | 9bd7b23 | 2009-08-09 16:16:55 +0000 | [diff] [blame] | 434 | }; |
| 435 | |
Jonathan Gordon | 5b0521c | 2010-06-07 03:44:11 +0000 | [diff] [blame] | 436 | if (!(ptr = parse_list("ddddd", &set, separator, ptr, |
| 437 | &vp->x, &vp->y, &vp->width, &vp->height, &vp->font))) |
| 438 | return NULL; |
Thomas Martitz | 9bd7b23 | 2009-08-09 16:16:55 +0000 | [diff] [blame] | 439 | |
| 440 | /* X and Y *must* be set */ |
| 441 | if (!LIST_VALUE_PARSED(set, PL_X) || !LIST_VALUE_PARSED(set, PL_Y)) |
Alexander Levin | 3bfc0e7 | 2009-08-12 13:37:07 +0000 | [diff] [blame] | 442 | return NULL; |
Teruaki Kawashima | 38efc71 | 2010-02-28 14:12:41 +0000 | [diff] [blame] | 443 | /* check for negative values */ |
Jonathan Gordon | bee5900 | 2009-10-28 06:44:37 +0000 | [diff] [blame] | 444 | if (vp->x < 0) |
| 445 | vp->x += screens[screen].lcdwidth; |
| 446 | if (vp->y < 0) |
| 447 | vp->y += screens[screen].lcdheight; |
Jonathan Gordon | 0aa035d | 2009-10-29 03:27:13 +0000 | [diff] [blame] | 448 | |
| 449 | /* fix defaults, |
| 450 | * and negative width/height which means "extend to edge minus value */ |
Thomas Martitz | 9bd7b23 | 2009-08-09 16:16:55 +0000 | [diff] [blame] | 451 | if (!LIST_VALUE_PARSED(set, PL_WIDTH)) |
| 452 | vp->width = screens[screen].lcdwidth - vp->x; |
Jonathan Gordon | 0aa035d | 2009-10-29 03:27:13 +0000 | [diff] [blame] | 453 | else if (vp->width < 0) |
| 454 | vp->width = (vp->width + screens[screen].lcdwidth) - vp->x; |
Thomas Martitz | 9bd7b23 | 2009-08-09 16:16:55 +0000 | [diff] [blame] | 455 | if (!LIST_VALUE_PARSED(set, PL_HEIGHT)) |
| 456 | vp->height = screens[screen].lcdheight - vp->y; |
Jonathan Gordon | 0aa035d | 2009-10-29 03:27:13 +0000 | [diff] [blame] | 457 | else if (vp->height < 0) |
| 458 | vp->height = (vp->height + screens[screen].lcdheight) - vp->y; |
Thomas Martitz | 9bd7b23 | 2009-08-09 16:16:55 +0000 | [diff] [blame] | 459 | |
Thomas Martitz | f909428 | 2009-08-09 17:47:12 +0000 | [diff] [blame] | 460 | #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) |
Jonathan Gordon | 5b0521c | 2010-06-07 03:44:11 +0000 | [diff] [blame] | 461 | vp->fg_pattern = get_viewport_default_colour(screen, true); |
| 462 | vp->bg_pattern = get_viewport_default_colour(screen, false); |
Thomas Martitz | 9f3fc27 | 2009-08-09 17:39:39 +0000 | [diff] [blame] | 463 | #endif /* LCD_DEPTH > 1 || LCD_REMOTE_DEPTH > 1 */ |
| 464 | |
Jonathan Gordon | 0aa035d | 2009-10-29 03:27:13 +0000 | [diff] [blame] | 465 | #ifdef HAVE_LCD_COLOR |
| 466 | vp->lss_pattern = global_settings.lss_color; |
| 467 | vp->lse_pattern = global_settings.lse_color; |
| 468 | vp->lst_pattern = global_settings.lst_color; |
| 469 | #endif |
Thomas Martitz | 9f3fc27 | 2009-08-09 17:39:39 +0000 | [diff] [blame] | 470 | |
Thomas Martitz | 9bd7b23 | 2009-08-09 16:16:55 +0000 | [diff] [blame] | 471 | /* Validate the viewport dimensions - we know that the numbers are |
| 472 | non-negative integers, ignore bars and assume the viewport takes them |
| 473 | * into account */ |
| 474 | if ((vp->x >= screens[screen].lcdwidth) || |
| 475 | ((vp->x + vp->width) > screens[screen].lcdwidth) || |
| 476 | (vp->y >= screens[screen].lcdheight) || |
| 477 | ((vp->y + vp->height) > screens[screen].lcdheight)) |
| 478 | { |
Alexander Levin | 3bfc0e7 | 2009-08-12 13:37:07 +0000 | [diff] [blame] | 479 | return NULL; |
Thomas Martitz | 9bd7b23 | 2009-08-09 16:16:55 +0000 | [diff] [blame] | 480 | } |
| 481 | |
Jonathan Gordon | 1c2aa35 | 2010-02-14 06:26:16 +0000 | [diff] [blame] | 482 | /* Default to using the user font if the font was an invalid number or '-' |
| 483 | * font 1 is *always* the UI font for the current screen |
| 484 | * 2 is always the first extra font */ |
| 485 | if (!LIST_VALUE_PARSED(set, PL_FONT)) |
Jonathan Gordon | f85103e | 2010-02-21 19:10:09 +0000 | [diff] [blame] | 486 | vp->font = FONT_UI; |
Thomas Martitz | a1b0e16 | 2009-08-09 18:44:49 +0000 | [diff] [blame] | 487 | |
| 488 | /* Set the defaults for fields not user-specified */ |
Thomas Martitz | 9bd7b23 | 2009-08-09 16:16:55 +0000 | [diff] [blame] | 489 | vp->drawmode = DRMODE_SOLID; |
Jonathan Gordon | dd9fbbf | 2009-12-09 07:44:08 +0000 | [diff] [blame] | 490 | #ifndef __PCTOOL__ |
Thomas Martitz | a79dc87 | 2009-10-11 12:21:27 +0000 | [diff] [blame] | 491 | set_default_align_flags(vp); |
Jonathan Gordon | dd9fbbf | 2009-12-09 07:44:08 +0000 | [diff] [blame] | 492 | #endif |
Thomas Martitz | 9bd7b23 | 2009-08-09 16:16:55 +0000 | [diff] [blame] | 493 | |
| 494 | return ptr; |
| 495 | } |
Thomas Martitz | 4c48b59 | 2009-08-16 22:20:11 +0000 | [diff] [blame] | 496 | #endif |