diff options
Diffstat (limited to 'apps/gui/quickscreen.c')
-rw-r--r-- | apps/gui/quickscreen.c | 179 |
1 files changed, 179 insertions, 0 deletions
diff --git a/apps/gui/quickscreen.c b/apps/gui/quickscreen.c new file mode 100644 index 0000000000..760c1bdb00 --- /dev/null +++ b/apps/gui/quickscreen.c | |||
@@ -0,0 +1,179 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2005 by Kevin Ferrare | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #include "quickscreen.h" | ||
21 | #ifdef HAS_QUICKSCREEN | ||
22 | |||
23 | #include "icons.h" | ||
24 | #include "textarea.h" | ||
25 | #include "font.h" | ||
26 | #include "kernel.h" | ||
27 | #include "misc.h" | ||
28 | #include "statusbar.h" | ||
29 | |||
30 | void gui_quickscreen_init(struct gui_quickscreen * qs, | ||
31 | struct option_select *left_option, | ||
32 | struct option_select *bottom_option, | ||
33 | struct option_select *right_option, | ||
34 | char * left_right_title, | ||
35 | quickscreen_callback callback) | ||
36 | { | ||
37 | qs->left_option=left_option; | ||
38 | qs->bottom_option=bottom_option; | ||
39 | qs->right_option=right_option; | ||
40 | qs->left_right_title=left_right_title; | ||
41 | qs->callback=callback; | ||
42 | } | ||
43 | |||
44 | void gui_quickscreen_draw(struct gui_quickscreen * qs, struct screen * display) | ||
45 | { | ||
46 | int w,h; | ||
47 | char buffer[30]; | ||
48 | const char * option; | ||
49 | const char * title; | ||
50 | #ifdef HAS_BUTTONBAR | ||
51 | display->has_buttonbar=false; | ||
52 | #endif | ||
53 | gui_textarea_clear(display); | ||
54 | display->getstringsize("M",&w,&h); | ||
55 | /* Displays the icons */ | ||
56 | display->mono_bitmap(bitmap_icons_7x8[Icon_FastBackward], | ||
57 | display->width/2 - 16, | ||
58 | display->height/2 - 4, 7, 8); | ||
59 | display->mono_bitmap(bitmap_icons_7x8[Icon_DownArrow], | ||
60 | display->width/2 - 3, | ||
61 | display->height - h*3, 7, 8); | ||
62 | display->mono_bitmap(bitmap_icons_7x8[Icon_FastForward], | ||
63 | display->width/2 + 8, | ||
64 | display->height/2 - 4, 7, 8); | ||
65 | display->setfont(FONT_SYSFIXED); | ||
66 | |||
67 | /* Displays the left's text */ | ||
68 | title=option_select_get_title(qs->left_option); | ||
69 | option=option_select_get_text(qs->left_option, buffer); | ||
70 | display->putsxy(0, display->height/2 - h*2, title); | ||
71 | display->putsxy(0, display->height/2 - h, qs->left_right_title); | ||
72 | display->putsxy(0, display->height/2, option); | ||
73 | |||
74 | /* Displays the bottom's text */ | ||
75 | title=option_select_get_title(qs->bottom_option); | ||
76 | option=option_select_get_text(qs->bottom_option, buffer); | ||
77 | display->getstringsize(title, &w, &h); | ||
78 | display->putsxy((display->width-w)/2, display->height - h*2, title); | ||
79 | display->getstringsize(option, &w, &h); | ||
80 | display->putsxy((display->width-w)/2, display->height - h, option); | ||
81 | |||
82 | /* Displays the right's text */ | ||
83 | title=option_select_get_title(qs->right_option); | ||
84 | option=option_select_get_text(qs->right_option, buffer); | ||
85 | display->getstringsize(title,&w,&h); | ||
86 | display->putsxy(display->width - w, display->height/2 - h*2, title); | ||
87 | display->getstringsize(qs->left_right_title,&w,&h); | ||
88 | display->putsxy(display->width - w, display->height/2 - h, qs->left_right_title); | ||
89 | display->getstringsize(option,&w,&h); | ||
90 | display->putsxy(display->width - w, display->height/2, option); | ||
91 | |||
92 | gui_textarea_update(display); | ||
93 | lcd_setfont(FONT_UI); | ||
94 | } | ||
95 | |||
96 | void gui_syncquickscreen_draw(struct gui_quickscreen * qs) | ||
97 | { | ||
98 | int i; | ||
99 | FOR_NB_SCREENS(i) | ||
100 | gui_quickscreen_draw(qs, &screens[i]); | ||
101 | } | ||
102 | |||
103 | bool gui_quickscreen_do_button(struct gui_quickscreen * qs, int button) | ||
104 | { | ||
105 | switch(button) | ||
106 | { | ||
107 | case QUICKSCREEN_LEFT : | ||
108 | case QUICKSCREEN_LEFT | BUTTON_REPEAT : | ||
109 | #ifdef QUICKSCREEN_RC_LEFT | ||
110 | case QUICKSCREEN_RC_LEFT : | ||
111 | case QUICKSCREEN_RC_LEFT | BUTTON_REPEAT : | ||
112 | #endif | ||
113 | option_select_next(qs->left_option); | ||
114 | return(true); | ||
115 | |||
116 | case QUICKSCREEN_BOTTOM : | ||
117 | case QUICKSCREEN_BOTTOM | BUTTON_REPEAT : | ||
118 | #ifdef QUICKSCREEN_RC_BOTTOM | ||
119 | case QUICKSCREEN_RC_BOTTOM : | ||
120 | case QUICKSCREEN_RC_BOTTOM | BUTTON_REPEAT : | ||
121 | #endif | ||
122 | option_select_next(qs->bottom_option); | ||
123 | return(true); | ||
124 | |||
125 | case QUICKSCREEN_RIGHT : | ||
126 | case QUICKSCREEN_RIGHT | BUTTON_REPEAT : | ||
127 | #ifdef QUICKSCREEN_RC_RIGHT | ||
128 | case QUICKSCREEN_RC_RIGHT : | ||
129 | case QUICKSCREEN_RC_RIGHT | BUTTON_REPEAT : | ||
130 | #endif | ||
131 | option_select_next(qs->right_option); | ||
132 | return(true); | ||
133 | |||
134 | case QUICKSCREEN_BOTTOM_INV : | ||
135 | case QUICKSCREEN_BOTTOM_INV | BUTTON_REPEAT : | ||
136 | #ifdef QUICKSCREEN_RC_BOTTOM_INV | ||
137 | case QUICKSCREEN_RC_BOTTOM_INV : | ||
138 | case QUICKSCREEN_RC_BOTTOM_INV | BUTTON_REPEAT : | ||
139 | #endif | ||
140 | option_select_prev(qs->bottom_option); | ||
141 | return(true); | ||
142 | } | ||
143 | return(false); | ||
144 | } | ||
145 | |||
146 | bool gui_syncquickscreen_run(struct gui_quickscreen * qs) | ||
147 | { | ||
148 | int key; | ||
149 | gui_syncquickscreen_draw(qs); | ||
150 | while (true) { | ||
151 | key = button_get(true); | ||
152 | if(default_event_handler(key) == SYS_USB_CONNECTED) | ||
153 | return(true); | ||
154 | if(gui_quickscreen_do_button(qs, key)) | ||
155 | { | ||
156 | if(qs->callback) | ||
157 | qs->callback(qs); | ||
158 | gui_syncquickscreen_draw(qs); | ||
159 | } | ||
160 | else if(key==QUICKSCREEN_QUIT | ||
161 | #ifdef QUICKSCREEN_QUIT | ||
162 | || key==QUICKSCREEN_QUIT | ||
163 | #endif | ||
164 | #ifdef QUICKSCREEN_QUIT2 | ||
165 | || key==QUICKSCREEN_QUIT2 | ||
166 | #endif | ||
167 | #if QUICKSCREEN_RC_QUIT | ||
168 | || key==QUICKSCREEN_RC_QUIT | ||
169 | #endif | ||
170 | ) | ||
171 | { | ||
172 | return(false); | ||
173 | } | ||
174 | gui_syncstatusbar_draw(&statusbars, false); | ||
175 | } | ||
176 | } | ||
177 | |||
178 | #endif /* HAS_QUICKSCREEN */ | ||
179 | |||