1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2008 by Jonathan Gordon
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.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include "quickscreen.h"
22 #ifdef HAVE_QUICKSCREEN
31 #include "statusbar.h"
33 #include "settings_list.h"
35 #include "option_select.h"
37 static struct viewport vps
[NB_SCREENS
][QUICKSCREEN_ITEM_COUNT
];
39 static void quickscreen_fix_viewports(struct gui_quickscreen
*qs
,
40 struct screen
*display
,
41 struct viewport
*parent
)
43 int height
, i
, count
=0, top
;
44 int nb_lines
= parent
->height
/display
->char_height
;
45 bool single_line_bottom
= false;
47 for(i
=0; i
<QUICKSCREEN_ITEM_COUNT
; i
++)
51 vps
[display
->screen_type
][i
] = *parent
;
54 /* special handling when there is only enough room for 2 items.
55 discard the top and bottom items, so only show the 2 side ones */
58 qs
->items
[QUICKSCREEN_TOP
] = NULL
;
59 qs
->items
[QUICKSCREEN_BOTTOM
] = NULL
;
60 vps
[display
->screen_type
][QUICKSCREEN_RIGHT
].y
= parent
->y
;
61 vps
[display
->screen_type
][QUICKSCREEN_LEFT
].height
= parent
->height
/2;
62 vps
[display
->screen_type
][QUICKSCREEN_RIGHT
].y
= parent
->y
+parent
->height
/2;
63 vps
[display
->screen_type
][QUICKSCREEN_RIGHT
].height
= parent
->height
/2;
66 else if (nb_lines
< 5 && count
== 4) /* drop the top item */
68 qs
->items
[QUICKSCREEN_TOP
] = NULL
;
69 single_line_bottom
= true;
72 height
= display
->char_height
*2;
74 (nb_lines
> 5 && qs
->items
[QUICKSCREEN_TOP
] == NULL
))
75 height
+= display
->char_height
;
77 if (qs
->items
[QUICKSCREEN_TOP
])
79 vps
[display
->screen_type
][QUICKSCREEN_TOP
].y
= parent
->y
;
80 vps
[display
->screen_type
][QUICKSCREEN_TOP
].height
= height
;
84 vps
[display
->screen_type
][QUICKSCREEN_TOP
].height
= 0;
87 if (qs
->items
[QUICKSCREEN_BOTTOM
])
89 if (single_line_bottom
)
90 height
= display
->char_height
;
91 vps
[display
->screen_type
][QUICKSCREEN_BOTTOM
].y
= parent
->y
+parent
->height
- height
;
92 vps
[display
->screen_type
][QUICKSCREEN_BOTTOM
].height
= height
;
96 vps
[display
->screen_type
][QUICKSCREEN_BOTTOM
].height
= 0;
100 height
= parent
->height
-
101 vps
[display
->screen_type
][QUICKSCREEN_BOTTOM
].height
-
102 vps
[display
->screen_type
][QUICKSCREEN_TOP
].height
;
103 top
= parent
->y
+vps
[display
->screen_type
][QUICKSCREEN_TOP
].height
;
104 vps
[display
->screen_type
][QUICKSCREEN_LEFT
].y
= top
;
105 vps
[display
->screen_type
][QUICKSCREEN_RIGHT
].y
= top
;
106 vps
[display
->screen_type
][QUICKSCREEN_LEFT
].height
= height
;
107 vps
[display
->screen_type
][QUICKSCREEN_RIGHT
].height
= height
;
109 vps
[display
->screen_type
][QUICKSCREEN_RIGHT
].x
= parent
->x
+parent
->width
/2;
111 vps
[display
->screen_type
][QUICKSCREEN_LEFT
].width
= parent
->width
/2;
112 vps
[display
->screen_type
][QUICKSCREEN_RIGHT
].width
= parent
->width
/2;
115 static void quickscreen_draw_text(char *s
, int item
, bool title
,
116 struct screen
*display
, struct viewport
*vp
)
118 int nb_lines
= vp
->height
/display
->char_height
;
119 int w
, line
= 0, x
=0;
120 display
->getstringsize(s
, &w
, NULL
);
123 case QUICKSCREEN_TOP
:
128 display
->mono_bitmap(bitmap_icons_7x8
[Icon_UpArrow
],
129 (vp
->width
/2)-4, 0, 7, 8);
137 x
= (vp
->width
- w
)/2;
139 case QUICKSCREEN_BOTTOM
:
140 if (title
&& nb_lines
> 2 && item
== QUICKSCREEN_BOTTOM
)
142 display
->mono_bitmap(bitmap_icons_7x8
[Icon_DownArrow
],
143 (vp
->width
/2)-4, vp
->height
-8, 7, 8);
146 x
= (vp
->width
- w
)/2;
148 case QUICKSCREEN_LEFT
:
158 display
->mono_bitmap(bitmap_icons_7x8
[Icon_FastBackward
], 1,
159 line
*display
->char_height
+display
->char_height
/2, 7, 8);
162 case QUICKSCREEN_RIGHT
:
167 display
->mono_bitmap(bitmap_icons_7x8
[Icon_FastForward
],
169 line
*display
->char_height
+display
->char_height
/2, 7, 8);
170 x
= vp
->width
- w
- 12;
174 display
->puts_scroll(0,line
,s
);
176 display
->putsxy(x
, line
*display
->char_height
, s
);
179 static void gui_quickscreen_draw(struct gui_quickscreen
*qs
,
180 struct screen
*display
,
181 struct viewport
*parent
)
185 unsigned char *title
, *value
;
188 display
->set_viewport(parent
);
189 display
->clear_viewport();
190 for (i
=0; i
<QUICKSCREEN_ITEM_COUNT
; i
++)
195 display
->set_viewport(&vps
[display
->screen_type
][i
]);
196 display
->scroll_stop(&vps
[display
->screen_type
][i
]);
198 title
= P2STR(ID2P(qs
->items
[i
]->lang_id
));
199 setting
= qs
->items
[i
]->setting
;
200 if (qs
->items
[i
]->flags
&F_T_BOOL
)
201 temp
= *(bool*)setting
?1:0;
203 temp
= *(int*)setting
;
204 value
= option_get_valuestring((struct settings_list
*)qs
->items
[i
], buf
, MAX_PATH
, temp
);
206 if (vps
[display
->screen_type
][i
].height
< display
->char_height
*2)
209 snprintf(text
, MAX_PATH
, "%s: %s", title
, value
);
210 quickscreen_draw_text(text
, i
, true, display
, &vps
[display
->screen_type
][i
]);
214 quickscreen_draw_text(title
, i
, true, display
, &vps
[display
->screen_type
][i
]);
215 quickscreen_draw_text(value
, i
, false, display
, &vps
[display
->screen_type
][i
]);
217 display
->update_viewport();
219 display
->set_viewport(parent
);
220 display
->update_viewport();
221 display
->set_viewport(NULL
);
226 * Does the actions associated to the given button if any
227 * - qs : the quickscreen
228 * - button : the key we are going to analyse
229 * returns : true if the button corresponded to an action, false otherwise
231 static bool gui_quickscreen_do_button(struct gui_quickscreen
* qs
, int button
)
236 if (qs
->items
[QUICKSCREEN_LEFT
])
237 option_select_next_val((struct settings_list
*)qs
->items
[QUICKSCREEN_LEFT
]);
241 if (qs
->items
[QUICKSCREEN_BOTTOM
])
242 option_select_next_val((struct settings_list
*)qs
->items
[QUICKSCREEN_BOTTOM
]);
245 case ACTION_QS_RIGHT
:
246 if (qs
->items
[QUICKSCREEN_RIGHT
])
247 option_select_next_val((struct settings_list
*)qs
->items
[QUICKSCREEN_RIGHT
]);
250 case ACTION_QS_DOWNINV
:
251 if (qs
->items
[QUICKSCREEN_TOP
])
252 option_select_next_val((struct settings_list
*)qs
->items
[QUICKSCREEN_TOP
]);
258 bool gui_syncquickscreen_run(struct gui_quickscreen
* qs
, int button_enter
)
261 bool changed
= false;
262 struct viewport vp
[NB_SCREENS
];
263 /* To quit we need either :
264 * - a second press on the button that made us enter
265 * - an action taken while pressing the enter button,
266 * then release the enter button*/
268 gui_syncstatusbar_draw(&statusbars
, true);
272 vp
[i
].width
= screens
[i
].width
;
273 vp
[i
].y
= STATUSBAR_HEIGHT
;
274 vp
[i
].height
= screens
[i
].height
- STATUSBAR_HEIGHT
;
275 #ifdef HAVE_LCD_COLOR
276 if (screens
[i
].is_color
)
278 vp
[i
].fg_pattern
= screens
[i
].get_foreground();
279 vp
[i
].bg_pattern
= screens
[i
].get_background();
284 vp
[i
].font
= FONT_UI
;
285 vp
[i
].drawmode
= STYLE_DEFAULT
;
286 quickscreen_fix_viewports(qs
, &screens
[i
], &vp
[i
]);
287 gui_quickscreen_draw(qs
, &screens
[i
], &vp
[i
]);
290 button
= get_action(CONTEXT_QUICKSCREEN
,TIMEOUT_BLOCK
);
291 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
293 if(gui_quickscreen_do_button(qs
, button
))
297 if (button
== ACTION_QS_DOWNINV
&&
298 !qs
->items
[QUICKSCREEN_TOP
])
301 gui_quickscreen_draw(qs
, &screens
[i
], &vp
[i
]);
303 else if(button
==button_enter
)
306 if((button
== button_enter
) && can_quit
)
309 if(button
==ACTION_STD_CANCEL
)
312 gui_syncstatusbar_draw(&statusbars
, false);
319 bool quick_screen_quick(int button_enter
)
321 struct gui_quickscreen qs
;
322 qs
.items
[QUICKSCREEN_LEFT
] = find_setting_from_string(global_settings
.quickscreen_left
, NULL
);
323 qs
.items
[QUICKSCREEN_RIGHT
] = find_setting_from_string(global_settings
.quickscreen_right
,NULL
);
324 qs
.items
[QUICKSCREEN_BOTTOM
] = find_setting_from_string(global_settings
.quickscreen_bottom
, NULL
);
325 qs
.items
[QUICKSCREEN_TOP
] = find_setting_from_string(global_settings
.quickscreen_top
,NULL
);
327 gui_syncquickscreen_run(&qs
, button_enter
);
332 bool quick_screen_f3(int button_enter
)
334 struct gui_quickscreen qs
;
335 qs
.items
[QUICKSCREEN_LEFT
] = find_setting(&global_settings
.scrollbar
, NULL
);
336 qs
.items
[QUICKSCREEN_RIGHT
] = find_setting(&global_settings
.statusbar
, NULL
);
337 qs
.items
[QUICKSCREEN_BOTTOM
] = find_setting(&global_settings
.flip_display
, NULL
);
338 qs
.items
[QUICKSCREEN_TOP
] = NULL
;
340 gui_syncquickscreen_run(&qs
, button_enter
);
343 #endif /* BUTTON_F3 */
345 #endif /* HAVE_QUICKSCREEN */