Backport d8a3871 - Update French by Amaury Pouly
[maemo-rb.git] / apps / screen_access.c
blob152f96f7fac0535836e94953846bfc713bc5d901
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 by Kevin Ferrare
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 <stdio.h>
23 #include "config.h"
24 #include <lcd.h>
25 #ifdef HAVE_REMOTE_LCD
26 #include <lcd-remote.h>
27 #endif
28 #include <scroll_engine.h>
29 #include <font.h>
30 #include <button.h>
31 #include <settings.h>
32 #include <kernel.h>
33 #include <icons.h>
35 #include "backlight.h"
36 #include "screen_access.h"
37 #include "backdrop.h"
39 /* some helper functions to calculate metrics on the fly */
40 static int screen_helper_getcharwidth(void)
42 #ifdef HAVE_LCD_BITMAP
43 return font_get(lcd_getfont())->maxwidth;
44 #else
45 return 1;
46 #endif
49 static int screen_helper_getcharheight(void)
51 #ifdef HAVE_LCD_BITMAP
52 return font_get(lcd_getfont())->height;
53 #else
54 return 1;
55 #endif
58 static int screen_helper_getnblines(void)
60 int height=screens[0].lcdheight;
61 #ifdef HAVE_LCD_BITMAP
62 if(global_settings.statusbar != STATUSBAR_OFF)
63 height -= STATUSBAR_HEIGHT;
64 #ifdef HAVE_BUTTONBAR
65 if(global_settings.buttonbar && screens[0].has_buttonbar)
66 height -= BUTTONBAR_HEIGHT;
67 #endif
68 #endif
69 return height / screens[0].getcharheight();
72 void screen_helper_setfont(int font)
74 (void)font;
75 #ifdef HAVE_LCD_BITMAP
76 if (font == FONT_UI)
77 font = global_status.font_id[SCREEN_MAIN];
78 lcd_setfont(font);
79 #endif
82 #ifdef HAVE_LCD_BITMAP
83 static int screen_helper_getuifont(void)
85 return global_status.font_id[SCREEN_MAIN];
88 static void screen_helper_setuifont(int font)
90 global_status.font_id[SCREEN_MAIN] = font;
92 #endif
94 #if NB_SCREENS == 2
95 static int screen_helper_remote_getcharwidth(void)
97 #ifdef HAVE_LCD_BITMAP
98 return font_get(lcd_remote_getfont())->maxwidth;
99 #else
100 return 1;
101 #endif
104 static int screen_helper_remote_getcharheight(void)
106 #ifdef HAVE_LCD_BITMAP
107 return font_get(lcd_remote_getfont())->height;
108 #else
109 return 1;
110 #endif
113 static int screen_helper_remote_getnblines(void)
115 int height=screens[1].lcdheight;
116 #ifdef HAVE_LCD_BITMAP
117 if(global_settings.statusbar != STATUSBAR_OFF)
118 height -= STATUSBAR_HEIGHT;
119 #ifdef HAVE_BUTTONBAR
120 if(global_settings.buttonbar && screens[1].has_buttonbar)
121 height -= BUTTONBAR_HEIGHT;
122 #endif
123 #endif
124 return height / screens[1].getcharheight();
127 void screen_helper_remote_setfont(int font)
129 if (font == FONT_UI)
130 font = global_status.font_id[SCREEN_REMOTE];
131 lcd_remote_setfont(font);
134 static int screen_helper_remote_getuifont(void)
136 #ifdef HAVE_LCD_BITMAP
137 return global_status.font_id[SCREEN_REMOTE];
138 #else
139 return FONT_SYSFIXED;
140 #endif
143 static void screen_helper_remote_setuifont(int font)
145 #ifdef HAVE_LCD_BITMAP
146 global_status.font_id[SCREEN_REMOTE] = font;
147 #endif
150 #endif
152 struct screen screens[NB_SCREENS] =
155 .screen_type=SCREEN_MAIN,
156 .lcdwidth=LCD_WIDTH,
157 .lcdheight=LCD_HEIGHT,
158 .depth=LCD_DEPTH,
159 .getnblines=&screen_helper_getnblines,
160 #if defined(HAVE_LCD_COLOR)
161 .is_color=true,
162 #else
163 .is_color=false,
164 #endif
165 #ifdef HAVE_LCD_BITMAP
166 .pixel_format=LCD_PIXELFORMAT,
167 #endif
168 .getcharwidth=screen_helper_getcharwidth,
169 .getcharheight=screen_helper_getcharheight,
170 #if (CONFIG_LED == LED_VIRTUAL)
171 .has_disk_led=false,
172 #elif defined(HAVE_REMOTE_LCD)
173 .has_disk_led=true,
174 #endif
175 .set_viewport=&lcd_set_viewport,
176 .getwidth=&lcd_getwidth,
177 .getheight=&lcd_getheight,
178 .getstringsize=&lcd_getstringsize,
179 #ifdef HAVE_LCD_BITMAP
180 .setfont=screen_helper_setfont,
181 .getuifont=screen_helper_getuifont,
182 .setuifont=screen_helper_setuifont,
183 .mono_bitmap=&lcd_mono_bitmap,
184 .mono_bitmap_part=&lcd_mono_bitmap_part,
185 .set_drawmode=&lcd_set_drawmode,
186 .bitmap=(screen_bitmap_func*)&lcd_bitmap,
187 .bitmap_part=(screen_bitmap_part_func*)&lcd_bitmap_part,
188 #if LCD_DEPTH <= 2
189 /* No transparency yet for grayscale and mono lcd */
190 .transparent_bitmap=(screen_bitmap_func*)&lcd_bitmap,
191 .transparent_bitmap_part=(screen_bitmap_part_func*)&lcd_bitmap_part,
192 #else
193 .transparent_bitmap=(screen_bitmap_func*)&lcd_bitmap_transparent,
194 .transparent_bitmap_part=(screen_bitmap_part_func*)&lcd_bitmap_transparent_part,
195 #endif
196 .bmp = &lcd_bmp,
197 .bmp_part = &lcd_bmp_part,
198 .nine_segment_bmp = &lcd_nine_segment_bmp,
199 #if LCD_DEPTH > 1
200 #if defined(HAVE_LCD_COLOR) && defined(LCD_REMOTE_DEPTH) && LCD_REMOTE_DEPTH > 1
201 .color_to_native=&lcd_color_to_native,
202 #endif
203 .get_background=&lcd_get_background,
204 .get_foreground=&lcd_get_foreground,
205 .set_background=&lcd_set_background,
206 .set_foreground=&lcd_set_foreground,
207 #ifdef HAVE_LCD_COLOR
208 .set_selector_start=&lcd_set_selector_start,
209 .set_selector_end=&lcd_set_selector_end,
210 .set_selector_text=&lcd_set_selector_text,
211 #endif
212 #endif /* LCD_DEPTH > 1 */
213 .update_rect=&lcd_update_rect,
214 .update_viewport_rect=&lcd_update_viewport_rect,
215 .fillrect=&lcd_fillrect,
216 .drawrect=&lcd_drawrect,
217 .draw_border_viewport=&lcd_draw_border_viewport,
218 .fill_viewport=&lcd_fill_viewport,
219 .drawpixel=&lcd_drawpixel,
220 .drawline=&lcd_drawline,
221 .vline=&lcd_vline,
222 .hline=&lcd_hline,
223 .scroll_step=&lcd_scroll_step,
224 .puts_style_offset=&lcd_puts_style_offset,
225 .puts_style_xyoffset=&lcd_puts_style_xyoffset,
226 .puts_scroll_style=&lcd_puts_scroll_style,
227 .puts_scroll_style_offset=&lcd_puts_scroll_style_offset,
228 .puts_scroll_style_xyoffset=&lcd_puts_scroll_style_xyoffset,
229 #endif /* HAVE_LCD_BITMAP */
231 #ifdef HAVE_LCD_CHARCELLS
232 .double_height=&lcd_double_height,
233 .putchar=&lcd_putc,
234 .get_locked_pattern=&lcd_get_locked_pattern,
235 .define_pattern=&lcd_define_pattern,
236 .unlock_pattern=&lcd_unlock_pattern,
237 .icon=&lcd_icon,
238 #endif /* HAVE_LCD_CHARCELLS */
240 .putsxy=&lcd_putsxy,
241 .puts=&lcd_puts,
242 .putsf=&lcd_putsf,
243 .puts_offset=&lcd_puts_offset,
244 .puts_scroll=&lcd_puts_scroll,
245 .puts_scroll_offset=&lcd_puts_scroll_offset,
246 .scroll_speed=&lcd_scroll_speed,
247 .scroll_delay=&lcd_scroll_delay,
248 .stop_scroll=&lcd_stop_scroll,
249 .clear_display=&lcd_clear_display,
250 .clear_viewport=&lcd_clear_viewport,
251 .scroll_stop=&lcd_scroll_stop,
252 .scroll_stop_line=&lcd_scroll_stop_line,
253 .update=&lcd_update,
254 .update_viewport=&lcd_update_viewport,
255 .backlight_on=&backlight_on,
256 .backlight_off=&backlight_off,
257 .is_backlight_on=&is_backlight_on,
258 .backlight_set_timeout=&backlight_set_timeout,
259 #if LCD_DEPTH > 1
260 .backdrop_load=&backdrop_load,
261 .backdrop_show=&backdrop_show,
262 #endif
263 #ifdef HAVE_BUTTONBAR
264 .has_buttonbar=false,
265 #endif
266 #if defined(HAVE_LCD_BITMAP)
267 .set_framebuffer = (void*)lcd_set_framebuffer,
268 #if defined(HAVE_LCD_COLOR)
269 .gradient_fillrect = lcd_gradient_fillrect,
270 #endif
271 #endif
273 #if NB_SCREENS == 2
275 .screen_type=SCREEN_REMOTE,
276 .lcdwidth=LCD_REMOTE_WIDTH,
277 .lcdheight=LCD_REMOTE_HEIGHT,
278 .depth=LCD_REMOTE_DEPTH,
279 .getnblines=&screen_helper_remote_getnblines,
280 .is_color=false,/* No color remotes yet */
281 .pixel_format=LCD_REMOTE_PIXELFORMAT,
282 .getcharwidth=screen_helper_remote_getcharwidth,
283 .getcharheight=screen_helper_remote_getcharheight,
284 .has_disk_led=false,
285 .set_viewport=&lcd_remote_set_viewport,
286 .getwidth=&lcd_remote_getwidth,
287 .getheight=&lcd_remote_getheight,
288 .getstringsize=&lcd_remote_getstringsize,
289 #if 1 /* all remote LCDs are bitmapped so far */
290 .setfont=screen_helper_remote_setfont,
291 .getuifont=screen_helper_remote_getuifont,
292 .setuifont=screen_helper_remote_setuifont,
293 .mono_bitmap=&lcd_remote_mono_bitmap,
294 .mono_bitmap_part=&lcd_remote_mono_bitmap_part,
295 .bitmap=(screen_bitmap_func*)&lcd_remote_bitmap,
296 .bitmap_part=(screen_bitmap_part_func*)&lcd_remote_bitmap_part,
297 .set_drawmode=&lcd_remote_set_drawmode,
298 #if LCD_REMOTE_DEPTH <= 2
299 /* No transparency yet for grayscale and mono lcd */
300 .transparent_bitmap=(screen_bitmap_func*)&lcd_remote_bitmap,
301 .transparent_bitmap_part=(screen_bitmap_part_func*)&lcd_remote_bitmap_part,
302 /* No colour remotes yet */
303 #endif
304 .bmp = &lcd_remote_bmp,
305 .bmp_part = &lcd_remote_bmp_part,
306 .nine_segment_bmp = &lcd_remote_nine_segment_bmp,
307 #if LCD_REMOTE_DEPTH > 1
308 #if defined(HAVE_LCD_COLOR)
309 .color_to_native=&lcd_remote_color_to_native,
310 #endif
311 .get_background=&lcd_remote_get_background,
312 .get_foreground=&lcd_remote_get_foreground,
313 .set_background=&lcd_remote_set_background,
314 .set_foreground=&lcd_remote_set_foreground,
315 #endif /* LCD_REMOTE_DEPTH > 1 */
316 .update_rect=&lcd_remote_update_rect,
317 .update_viewport_rect=&lcd_remote_update_viewport_rect,
318 .fillrect=&lcd_remote_fillrect,
319 .drawrect=&lcd_remote_drawrect,
320 .draw_border_viewport=&lcd_remote_draw_border_viewport,
321 .fill_viewport=&lcd_remote_fill_viewport,
322 .drawpixel=&lcd_remote_drawpixel,
323 .drawline=&lcd_remote_drawline,
324 .vline=&lcd_remote_vline,
325 .hline=&lcd_remote_hline,
326 .scroll_step=&lcd_remote_scroll_step,
327 .puts_style_offset=&lcd_remote_puts_style_offset,
328 .puts_style_xyoffset=&lcd_remote_puts_style_xyoffset,
329 .puts_scroll_style=&lcd_remote_puts_scroll_style,
330 .puts_scroll_style_offset=&lcd_remote_puts_scroll_style_offset,
331 .puts_scroll_style_xyoffset=&lcd_remote_puts_scroll_style_xyoffset,
332 #endif /* 1 */
334 #if 0 /* no charcell remote LCDs so far */
335 .double_height=&lcd_remote_double_height,
336 .putc=&lcd_remote_putc,
337 .get_locked_pattern=&lcd_remote_get_locked_pattern,
338 .define_pattern=&lcd_remote_define_pattern,
339 .icon=&lcd_remote_icon,
340 #endif /* 0 */
341 .putsxy=&lcd_remote_putsxy,
342 .puts=&lcd_remote_puts,
343 .putsf=&lcd_remote_putsf,
344 .puts_offset=&lcd_remote_puts_offset,
345 .puts_scroll=&lcd_remote_puts_scroll,
346 .puts_scroll_offset=&lcd_remote_puts_scroll_offset,
347 .scroll_speed=&lcd_remote_scroll_speed,
348 .scroll_delay=&lcd_remote_scroll_delay,
349 .stop_scroll=&lcd_remote_stop_scroll,
350 .clear_display=&lcd_remote_clear_display,
351 .clear_viewport=&lcd_remote_clear_viewport,
352 .scroll_stop=&lcd_remote_scroll_stop,
353 .scroll_stop_line=&lcd_remote_scroll_stop_line,
354 .update=&lcd_remote_update,
355 .update_viewport=&lcd_remote_update_viewport,
356 .backlight_on=&remote_backlight_on,
357 .backlight_off=&remote_backlight_off,
358 .is_backlight_on=&is_remote_backlight_on,
359 .backlight_set_timeout=&remote_backlight_set_timeout,
361 #if LCD_DEPTH > 1
362 .backdrop_load=&remote_backdrop_load,
363 .backdrop_show=&remote_backdrop_show,
364 #endif
365 #ifdef HAVE_BUTTONBAR
366 .has_buttonbar=false,
367 #endif
368 #if defined(HAVE_LCD_BITMAP)
369 .set_framebuffer = (void*)lcd_remote_set_framebuffer,
370 #endif
372 #endif /* NB_SCREENS == 2 */
375 #ifdef HAVE_LCD_BITMAP
376 void screen_clear_area(struct screen * display, int xstart, int ystart,
377 int width, int height)
379 display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
380 display->fillrect(xstart, ystart, width, height);
381 display->set_drawmode(DRMODE_SOLID);
383 #endif