summaryrefslogtreecommitdiffstats
path: root/apps/screen_access.c
blob: a966d07876e02171cca5f5546846078c5631f7c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Copyright (C) 2005 by Kevin Ferrare
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/

#include <stdio.h>
#include "config.h"
#include <lcd.h>
#ifdef HAVE_REMOTE_LCD
#include <lcd-remote.h>
#endif
#include "scroll_engine.h"
#include <font.h>
#include <button.h>
#include <settings.h>
#include <kernel.h>
#include <icons.h>

#include "backlight.h"
#include "screen_access.h"
#include "backdrop.h"

/* some helper functions to calculate metrics on the fly */
static int screen_helper_getcharwidth(void)
{
#ifdef HAVE_LCD_BITMAP
    return font_get(lcd_getfont())->maxwidth;
#else
    return 1;
#endif
}

static int screen_helper_getcharheight(void)
{
#ifdef HAVE_LCD_BITMAP
    return font_get(lcd_getfont())->height;
#else
    return 1;
#endif
}

static int screen_helper_getnblines(void)
{
    int height=screens[0].lcdheight;
#ifdef HAVE_LCD_BITMAP
    if(global_settings.statusbar != STATUSBAR_OFF)
        height -= STATUSBAR_HEIGHT;
#endif
    return height / screens[0].getcharheight();
}

void screen_helper_setfont(int font)
{
    (void)font;
#ifdef HAVE_LCD_BITMAP
    if (font == FONT_UI)
        font = global_status.font_id[SCREEN_MAIN];
    lcd_setfont(font);
#endif
}

#ifdef HAVE_LCD_BITMAP
static int screen_helper_getuifont(void)
{
    return global_status.font_id[SCREEN_MAIN];
}

static void screen_helper_setuifont(int font)
{
    global_status.font_id[SCREEN_MAIN] = font;
}
#endif

static void screen_helper_set_drawmode(int mode)
{
#ifdef HAVE_LCD_BITMAP
    lcd_set_drawmode(mode);
#else
    (void) mode;
#endif
}

static void screen_helper_put_line(int x, int y, struct line_desc *line,
                                   const char *fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);
    vput_line(&screens[SCREEN_MAIN], x, y, line, fmt, ap);
    va_end(ap);
}

#if NB_SCREENS == 2
static int screen_helper_remote_getcharwidth(void)
{
#ifdef HAVE_LCD_BITMAP
    return font_get(lcd_remote_getfont())->maxwidth;
#else
    return 1;
#endif
}

static int screen_helper_remote_getcharheight(void)
{
#ifdef HAVE_LCD_BITMAP
    return font_get(lcd_remote_getfont())->height;
#else
    return 1;
#endif
}

static int screen_helper_remote_getnblines(void)
{
    int height=screens[1].lcdheight;
#ifdef HAVE_LCD_BITMAP
    if(global_settings.statusbar != STATUSBAR_OFF)
        height -= STATUSBAR_HEIGHT;
#endif
    return height / screens[1].getcharheight();
}

void screen_helper_remote_setfont(int font)
{
    if (font == FONT_UI)
        font = global_status.font_id[SCREEN_REMOTE];
    lcd_remote_setfont(font);
}

static int screen_helper_remote_getuifont(void)
{
#ifdef HAVE_LCD_BITMAP
    return global_status.font_id[SCREEN_REMOTE];
#else
    return FONT_SYSFIXED;
#endif
}

static void screen_helper_remote_setuifont(int font)
{
#ifdef HAVE_LCD_BITMAP
    global_status.font_id[SCREEN_REMOTE] = font;
#endif
}

static void screen_helper_remote_put_line(int x, int y, struct line_desc *line,
                                          const char *fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);
    vput_line(&screens[SCREEN_REMOTE], x, y, line, fmt, ap);
    va_end(ap);
}

#endif

struct screen screens[NB_SCREENS] =
{
    {
        .screen_type=SCREEN_MAIN,
        .lcdwidth=LCD_WIDTH,
        .lcdheight=LCD_HEIGHT,
        .depth=LCD_DEPTH,
        .getnblines=&screen_helper_getnblines,
#if defined(HAVE_LCD_COLOR)
        .is_color=true,
#else
        .is_color=false,
#endif
#ifdef HAVE_LCD_BITMAP
        .pixel_format=LCD_PIXELFORMAT,
#endif
        .getcharwidth=screen_helper_getcharwidth,
        .getcharheight=screen_helper_getcharheight,
#if (CONFIG_LED == LED_VIRTUAL)
        .has_disk_led=false,
#elif defined(HAVE_REMOTE_LCD)
        .has_disk_led=true,
#endif
        .set_drawmode=&screen_helper_set_drawmode,
        .set_viewport=&lcd_set_viewport,
        .getwidth=&lcd_getwidth,
        .getheight=&lcd_getheight,
        .getstringsize=&lcd_getstringsize,
#ifdef HAVE_LCD_BITMAP
        .setfont=screen_helper_setfont,
        .getuifont=screen_helper_getuifont,
        .setuifont=screen_helper_setuifont,
        .mono_bitmap=&lcd_mono_bitmap,
        .mono_bitmap_part=&lcd_mono_bitmap_part,
        .bitmap=(screen_bitmap_func*)&lcd_bitmap,
        .bitmap_part=(screen_bitmap_part_func*)&lcd_bitmap_part,
#if LCD_DEPTH <= 2
        /* No transparency yet for grayscale and mono lcd */
        .transparent_bitmap=(screen_bitmap_func*)&lcd_bitmap,
        .transparent_bitmap_part=(screen_bitmap_part_func*)&lcd_bitmap_part,
#else
        .transparent_bitmap=(screen_bitmap_func*)&lcd_bitmap_transparent,
        .transparent_bitmap_part=(screen_bitmap_part_func*)&lcd_bitmap_transparent_part,
#endif
        .bmp = &lcd_bmp,
        .bmp_part = &lcd_bmp_part,
        .nine_segment_bmp = &lcd_nine_segment_bmp,
#if LCD_DEPTH > 1
#if defined(HAVE_LCD_COLOR) && defined(LCD_REMOTE_DEPTH) && LCD_REMOTE_DEPTH > 1
        .color_to_native=&lcd_color_to_native,
#endif
        .get_background=&lcd_get_background,
        .get_foreground=&lcd_get_foreground,
        .set_background=&lcd_set_background,
        .set_foreground=&lcd_set_foreground,
#endif /* LCD_DEPTH > 1 */
        .update_rect=&lcd_update_rect,
        .update_viewport_rect=&lcd_update_viewport_rect,
        .fillrect=&lcd_fillrect,
        .drawrect=&lcd_drawrect,
        .draw_border_viewport=&lcd_draw_border_viewport,
        .fill_viewport=&lcd_fill_viewport,
        .drawpixel=&lcd_drawpixel,
        .drawline=&lcd_drawline,
        .vline=&lcd_vline,
        .hline=&lcd_hline,
        .scroll_step=&lcd_scroll_step,
#endif /* HAVE_LCD_BITMAP */

#ifdef HAVE_LCD_CHARCELLS
        .double_height=&lcd_double_height,
        .putchar=&lcd_putc,
        .get_locked_pattern=&lcd_get_locked_pattern,
        .define_pattern=&lcd_define_pattern,
        .unlock_pattern=&lcd_unlock_pattern,
        .icon=&lcd_icon,
#endif /* HAVE_LCD_CHARCELLS */

        .putsxy=&lcd_putsxy,
        .puts=&lcd_puts,
        .putsf=&lcd_putsf,
        .puts_scroll=&lcd_puts_scroll,
        .putsxy_scroll_func=&lcd_putsxy_scroll_func,
        .scroll_speed=&lcd_scroll_speed,
        .scroll_delay=&lcd_scroll_delay,
        .clear_display=&lcd_clear_display,
        .clear_viewport=&lcd_clear_viewport,
        .scroll_stop_viewport_rect=&lcd_scroll_stop_viewport_rect,
        .scroll_stop=&lcd_scroll_stop,
        .scroll_stop_viewport=&lcd_scroll_stop_viewport,
        .update=&lcd_update,
        .update_viewport=&lcd_update_viewport,
        .backlight_on=&backlight_on,
        .backlight_off=&backlight_off,
        .is_backlight_on=&is_backlight_on,
        .backlight_set_timeout=&backlight_set_timeout,
#if LCD_DEPTH > 1
        .backdrop_load=&backdrop_load,
        .backdrop_show=&backdrop_show,
#endif
#if defined(HAVE_LCD_BITMAP)
        .set_framebuffer = (void*)lcd_set_framebuffer,
#if defined(HAVE_LCD_COLOR)    
        .gradient_fillrect = lcd_gradient_fillrect,
        .gradient_fillrect_part = lcd_gradient_fillrect_part,
#endif
#endif
        .put_line = screen_helper_put_line,
    },
#if NB_SCREENS == 2
    {
        .screen_type=SCREEN_REMOTE,
        .lcdwidth=LCD_REMOTE_WIDTH,
        .lcdheight=LCD_REMOTE_HEIGHT,
        .depth=LCD_REMOTE_DEPTH,
        .getnblines=&screen_helper_remote_getnblines,
        .is_color=false,/* No color remotes yet */
        .pixel_format=LCD_REMOTE_PIXELFORMAT,
        .getcharwidth=screen_helper_remote_getcharwidth,
        .getcharheight=screen_helper_remote_getcharheight,
        .has_disk_led=false,
        .set_drawmode=&lcd_remote_set_drawmode,
        .set_viewport=&lcd_remote_set_viewport,
        .getwidth=&lcd_remote_getwidth,
        .getheight=&lcd_remote_getheight,
        .getstringsize=&lcd_remote_getstringsize,
#if 1 /* all remote LCDs are bitmapped so far */
        .setfont=screen_helper_remote_setfont,
        .getuifont=screen_helper_remote_getuifont,
        .setuifont=screen_helper_remote_setuifont,
        .mono_bitmap=&lcd_remote_mono_bitmap,
        .mono_bitmap_part=&lcd_remote_mono_bitmap_part,
        .bitmap=(screen_bitmap_func*)&lcd_remote_bitmap,
        .bitmap_part=(screen_bitmap_part_func*)&lcd_remote_bitmap_part,
#if LCD_REMOTE_DEPTH <= 2
        /* No transparency yet for grayscale and mono lcd */
        .transparent_bitmap=(screen_bitmap_func*)&lcd_remote_bitmap,
        .transparent_bitmap_part=(screen_bitmap_part_func*)&lcd_remote_bitmap_part,
        /* No colour remotes yet */
#endif
        .bmp = &lcd_remote_bmp,
        .bmp_part = &lcd_remote_bmp_part,
        .nine_segment_bmp = &lcd_remote_nine_segment_bmp,
#if LCD_REMOTE_DEPTH > 1
#if defined(HAVE_LCD_COLOR)
        .color_to_native=&lcd_remote_color_to_native,
#endif
        .get_background=&lcd_remote_get_background,
        .get_foreground=&lcd_remote_get_foreground,
        .set_background=&lcd_remote_set_background,
        .set_foreground=&lcd_remote_set_foreground,
#endif /* LCD_REMOTE_DEPTH > 1 */
        .update_rect=&lcd_remote_update_rect,
        .update_viewport_rect=&lcd_remote_update_viewport_rect,
        .fillrect=&lcd_remote_fillrect,
        .drawrect=&lcd_remote_drawrect,
        .draw_border_viewport=&lcd_remote_draw_border_viewport,
        .fill_viewport=&lcd_remote_fill_viewport,
        .drawpixel=&lcd_remote_drawpixel,
        .drawline=&lcd_remote_drawline,
        .vline=&lcd_remote_vline,
        .hline=&lcd_remote_hline,
        .scroll_step=&lcd_remote_scroll_step,
#endif /* 1 */

#if 0 /* no charcell remote LCDs so far */
        .double_height=&lcd_remote_double_height,
        .putc=&lcd_remote_putc,
        .get_locked_pattern=&lcd_remote_get_locked_pattern,
        .define_pattern=&lcd_remote_define_pattern,
        .icon=&lcd_remote_icon,
#endif /* 0 */
        .putsxy=&lcd_remote_putsxy,
        .puts=&lcd_remote_puts,
        .putsf=&lcd_remote_putsf,
        .puts_scroll=&lcd_remote_puts_scroll,
        .putsxy_scroll_func=&lcd_remote_putsxy_scroll_func,
        .scroll_speed=&lcd_remote_scroll_speed,
        .scroll_delay=&lcd_remote_scroll_delay,
        .clear_display=&lcd_remote_clear_display,
        .clear_viewport=&lcd_remote_clear_viewport,
        .scroll_stop_viewport_rect=&lcd_remote_scroll_stop_viewport_rect,
        .scroll_stop=&lcd_remote_scroll_stop,
        .scroll_stop_viewport=&lcd_remote_scroll_stop_viewport,
        .update=&lcd_remote_update,
        .update_viewport=&lcd_remote_update_viewport,
        .backlight_on=&remote_backlight_on,
        .backlight_off=&remote_backlight_off,
        .is_backlight_on=&is_remote_backlight_on,
        .backlight_set_timeout=&remote_backlight_set_timeout,

#if LCD_DEPTH > 1
        .backdrop_load=&remote_backdrop_load,
        .backdrop_show=&remote_backdrop_show,
#endif
#if defined(HAVE_LCD_BITMAP)
        .set_framebuffer = (void*)lcd_remote_set_framebuffer,
#endif
        .put_line = screen_helper_remote_put_line,
    }
#endif /* NB_SCREENS == 2 */
};

#ifdef HAVE_LCD_BITMAP
void screen_clear_area(struct screen * display, int xstart, int ystart,
                       int width, int height)
{
    display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
    display->fillrect(xstart, ystart, width, height);
    display->set_drawmode(DRMODE_SOLID);
}
#endif