FS#10406 - split the statusbar setting into one for each display, and allow the bar...
[kugel-rb.git] / apps / gui / viewport.c
blob67f63e349b15698e618408f10496f4cc1e5b41a9
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2008 by 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 <stdlib.h>
23 #include "config.h"
24 #include "lcd.h"
25 #include "lcd-remote.h"
26 #include "font.h"
27 #include "sprintf.h"
28 #include "string.h"
29 #include "settings.h"
30 #include "kernel.h"
31 #include "system.h"
32 #include "misc.h"
33 #include "viewport.h"
34 #include "statusbar.h"
35 #include "screen_access.h"
36 #include "appevents.h"
38 static int statusbar_enabled = 0;
40 int viewport_get_nb_lines(struct viewport *vp)
42 #ifdef HAVE_LCD_BITMAP
43 return vp->height/font_get(vp->font)->height;
44 #else
45 (void)vp;
46 return 2;
47 #endif
50 static bool showing_bars(enum screen_type screen)
52 bool ignore = statusbar_enabled & VP_SB_IGNORE_SETTING(screen);
53 if (statusbar_enabled & VP_SB_ONSCREEN(screen))
55 #ifdef HAVE_LCD_BITMAP
56 #ifdef HAVE_REMOTE_LCD
57 if (screen == SCREEN_REMOTE)
58 return global_settings.remote_statusbar || ignore;
59 #endif
60 return global_settings.statusbar || ignore;
61 #else
62 return true;
63 #endif
65 return false;
68 void viewport_set_defaults(struct viewport *vp, enum screen_type screen)
70 bool bar_at_top = true;
71 vp->x = 0;
72 vp->width = screens[screen].lcdwidth;
74 #ifdef HAVE_LCD_BITMAP
75 vp->drawmode = DRMODE_SOLID;
76 vp->font = FONT_UI; /* default to UI to discourage SYSFONT use */
77 #ifdef HAVE_REMOTE_LCD
78 if (screen == SCREEN_REMOTE)
79 bar_at_top = global_settings.remote_statusbar != STATUSBAR_BOTTOM;
80 else
81 #endif
82 bar_at_top = global_settings.statusbar != STATUSBAR_BOTTOM;
84 vp->height = screens[screen].lcdheight;
85 if (bar_at_top && showing_bars(screen))
86 vp->y = STATUSBAR_HEIGHT;
87 else
88 vp->y = 0;
89 #else
90 vp->y = 0;
91 #endif
92 vp->height = screens[screen].lcdheight - (showing_bars(screen)?STATUSBAR_HEIGHT:0);
94 #ifdef HAVE_REMOTE_LCD
95 /* We only need this test if there is a remote LCD */
96 if (screen == SCREEN_MAIN)
97 #endif
99 #ifdef HAVE_LCD_COLOR
100 vp->fg_pattern = global_settings.fg_color;
101 vp->bg_pattern = global_settings.bg_color;
102 vp->lss_pattern = global_settings.lss_color;
103 vp->lse_pattern = global_settings.lse_color;
104 vp->lst_pattern = global_settings.lst_color;
105 #elif LCD_DEPTH > 1
106 vp->fg_pattern = LCD_DEFAULT_FG;
107 vp->bg_pattern = LCD_DEFAULT_BG;
108 #endif
111 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
112 if (screen == SCREEN_REMOTE)
114 vp->fg_pattern = LCD_REMOTE_DEFAULT_FG;
115 vp->bg_pattern = LCD_REMOTE_DEFAULT_BG;
117 #endif
121 int viewportmanager_set_statusbar(int enabled)
123 int old = statusbar_enabled;
124 statusbar_enabled = enabled;
125 if (enabled)
127 int i;
128 FOR_NB_SCREENS(i)
130 if (showing_bars(i))
131 gui_statusbar_draw(&statusbars.statusbars[i], true);
133 add_event(GUI_EVENT_ACTIONUPDATE, false, viewportmanager_draw_statusbars);
135 else
137 remove_event(GUI_EVENT_ACTIONUPDATE, viewportmanager_draw_statusbars);
139 return old;
142 void viewportmanager_draw_statusbars(void* data)
144 int i;
146 FOR_NB_SCREENS(i)
148 if (showing_bars(i))
149 gui_statusbar_draw(&statusbars.statusbars[i], (bool)data);
153 void viewportmanager_statusbar_changed(void* data)
155 (void)data;
156 statusbar_enabled = 0;
157 if (global_settings.statusbar != STATUSBAR_OFF)
158 statusbar_enabled = VP_SB_ONSCREEN(SCREEN_MAIN);
159 #ifdef HAVE_REMOTE_LCD
160 if (global_settings.remote_statusbar != STATUSBAR_OFF)
161 statusbar_enabled |= VP_SB_ONSCREEN(SCREEN_REMOTE);
162 #endif
163 viewportmanager_set_statusbar(statusbar_enabled);