summaryrefslogtreecommitdiff
path: root/apps/plugins/test_viewports.c
blob: 1f1e99a0fff54c382099c23030646dec1d64fc0c (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
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id: helloworld.c 12807 2007-03-16 21:56:08Z amiconn $
 *
 * Copyright (C) 2007 Dave Chapman
 *
 * All files in this archive are subject to the GNU General Public License.
 * See the file COPYING in the source tree root for full license agreement.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/

#include "plugin.h"

PLUGIN_HEADER

static struct plugin_api* rb;

#ifdef HAVE_LCD_BITMAP

#ifdef HAVE_LCD_COLOR
#define BGCOLOR_1 LCD_RGBPACK(255,255,0)
#define BGCOLOR_2 LCD_RGBPACK(0,255,0)
#define FGCOLOR_1 LCD_RGBPACK(0,0,255)
#elif LCD_DEPTH > 1
#define BGCOLOR_1 LCD_DARKGRAY
#define BGCOLOR_2 LCD_LIGHTGRAY
#define FGCOLOR_1 LCD_WHITE
#endif

static struct viewport vp0 =
{
    .x        = 0,
    .y        = 0,
    .width    = LCD_WIDTH,
    .height   = 20,
    .font     = FONT_UI,
    .drawmode = DRMODE_SOLID,
    .xmargin  = 0,
    .ymargin  = 0,
#if LCD_DEPTH > 1
    .fg_pattern = LCD_DEFAULT_FG,
    .bg_pattern = BGCOLOR_1,
#endif
#ifdef HAVE_LCD_COLOR
    .lss_pattern = LCD_DEFAULT_BG,
    .lse_pattern = LCD_DEFAULT_BG,
    .lst_pattern = LCD_DEFAULT_BG,
#endif
};

static struct viewport vp1 =
{
    .x        = LCD_WIDTH / 10,
    .y        = 20,
    .width    = LCD_WIDTH / 3,
    .height   = LCD_HEIGHT / 2,
    .font     = FONT_SYSFIXED,
    .drawmode = DRMODE_SOLID,
    .xmargin  = 0,
    .ymargin  = 0,
#if LCD_DEPTH > 1
    .fg_pattern = LCD_DEFAULT_FG,
    .bg_pattern = LCD_DEFAULT_BG,
#ifdef HAVE_LCD_COLOR
    .lss_pattern = LCD_DEFAULT_BG,
    .lse_pattern = LCD_DEFAULT_BG,
    .lst_pattern = LCD_DEFAULT_BG,
#endif
#endif
};

static struct viewport vp2 =
{
    .x        = LCD_WIDTH / 2,
    .y        = 40,
    .width    = LCD_WIDTH / 3,
    .height   = (LCD_HEIGHT / 2),
    .font     = FONT_UI,
    .drawmode = DRMODE_SOLID,
    .xmargin  = 0,
    .ymargin  = 0,
#if LCD_DEPTH > 1
    .fg_pattern = FGCOLOR_1,
    .bg_pattern = BGCOLOR_2,
#ifdef HAVE_LCD_COLOR
    .lss_pattern = LCD_DEFAULT_BG,
    .lse_pattern = LCD_DEFAULT_BG,
    .lst_pattern = LCD_DEFAULT_BG,
#endif
#endif
};


static struct viewport vp3 =
{
    .x        = LCD_WIDTH / 4,
    .y        = (5 * LCD_HEIGHT) / 8,
    .width    = LCD_WIDTH / 2,
    .height   = (LCD_HEIGHT / 4),
    .font     = FONT_SYSFIXED,
    .drawmode = DRMODE_SOLID,
    .xmargin  = 0,
    .ymargin  = 0,
#if LCD_DEPTH > 1
    .fg_pattern = LCD_BLACK,
    .bg_pattern = LCD_WHITE,
#ifdef HAVE_LCD_COLOR
    .lss_pattern = LCD_DEFAULT_BG,
    .lse_pattern = LCD_DEFAULT_BG,
    .lst_pattern = LCD_DEFAULT_BG,
#endif
#endif
};


#ifdef HAVE_REMOTE_LCD
static struct viewport rvp0 =
{
    .x        = 0,
    .y        = 10,
    .width    = LCD_REMOTE_WIDTH / 3,
    .height   = LCD_REMOTE_HEIGHT - 10,
    .font     = FONT_SYSFIXED,
    .drawmode = DRMODE_SOLID,
    .xmargin  = 0,
    .ymargin  = 0,
#if LCD_REMOTE_DEPTH > 1
    .fg_pattern = LCD_REMOTE_BLACK,
    .bg_pattern = LCD_REMOTE_LIGHTGRAY,
#endif
};

static struct viewport rvp1 =
{
    .x        = LCD_REMOTE_WIDTH / 2,
    .y        = 0,
    .width    = LCD_REMOTE_WIDTH / 3,
    .height   = LCD_REMOTE_HEIGHT - 10,
    .font     = FONT_SYSFIXED,
    .drawmode = DRMODE_SOLID,
    .xmargin  = 0,
    .ymargin  = 0,
#if LCD_REMOTE_DEPTH > 1
    .fg_pattern = LCD_REMOTE_DEFAULT_FG,
    .bg_pattern = LCD_REMOTE_DEFAULT_BG
#endif
};

#endif


enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
{
    (void)parameter;
    char buf[80];
    int i,y;

    rb = api;

    rb->screens[SCREEN_MAIN]->set_viewport(&vp0);
    rb->screens[SCREEN_MAIN]->clear_viewport();
    rb->screens[SCREEN_MAIN]->puts_scroll(0,0,"Viewport testing plugin - this is a scrolling title");

    rb->screens[SCREEN_MAIN]->set_viewport(&vp1);
    rb->screens[SCREEN_MAIN]->clear_viewport();

    for (i = 0 ; i < 3; i++)
    {
        rb->snprintf(buf,sizeof(buf),"Left text, scrolling_line %d",i);
        rb->screens[SCREEN_MAIN]->puts_scroll(0,i,buf);
    }

    rb->screens[SCREEN_MAIN]->set_viewport(&vp2);
    rb->screens[SCREEN_MAIN]->clear_viewport();
    for (i = 1 ; i < 3; i++)
    {
        rb->snprintf(buf,sizeof(buf),"Right text, scrolling line %d",i);
        rb->screens[SCREEN_MAIN]->puts_scroll(1,i,buf);
    }

    y = -10;
    for (i = -10; i < vp2.width + 10; i += 5)
    {
        rb->screens[SCREEN_MAIN]->drawline(i, y, i, vp2.height - y);
    }

    rb->screens[SCREEN_MAIN]->set_viewport(&vp3);
    rb->screens[SCREEN_MAIN]->clear_viewport();
    for (i = 1 ; i < 2; i++)
    {
        rb->snprintf(buf,sizeof(buf),"Bottom text, a scrolling line %d",i);
        rb->screens[SCREEN_MAIN]->puts_scroll(2,i,buf);
    }
    rb->screens[SCREEN_MAIN]->puts_scroll(4,i,"Short line");
    rb->screens[SCREEN_MAIN]->update();


#ifdef HAVE_REMOTE_LCD
    rb->screens[SCREEN_REMOTE]->set_viewport(&rvp0);
    rb->screens[SCREEN_REMOTE]->clear_viewport();

    for (i = 0 ; i < 5; i++)
    {
        rb->snprintf(buf,sizeof(buf),"Left text, scrolling_line %d",i);
        rb->screens[SCREEN_REMOTE]->puts_scroll(0,i,buf);
    }
    rb->screens[SCREEN_REMOTE]->puts(1,i,"Static");

    rb->screens[SCREEN_REMOTE]->set_viewport(&rvp1);
    rb->screens[SCREEN_REMOTE]->clear_viewport();
    for (i = 1 ; i < 3; i++)
    {
        rb->snprintf(buf,sizeof(buf),"Right text, scrolling line %d",i);
        rb->screens[SCREEN_REMOTE]->puts_scroll(1,i,buf);
    }

    y = -10;
    for (i = -10; i < rvp1.width + 10; i += 5)
    {
        rb->screens[SCREEN_REMOTE]->drawline(i, y, i, rvp1.height - y);
    }

    rb->screens[SCREEN_REMOTE]->update();
#endif

    rb->button_get(true);

    /* Restore the default viewport */
    rb->screens[SCREEN_MAIN]->set_viewport(NULL);
#ifdef HAVE_REMOTE_LCD
    rb->screens[SCREEN_REMOTE]->set_viewport(NULL);
#endif

    return PLUGIN_OK;
}


#else

/* Charcell version of plugin */

static struct viewport vp0 =
{
    .x        = 0,
    .y        = 0,
    .width    = 5,
    .height   = 1,
    .xmargin  = 0,
    .ymargin  = 0,
};

static struct viewport vp1 =
{
    .x        = 6,
    .y        = 0,
    .width    = 5,
    .height   = 1,
    .xmargin  = 0,
    .ymargin  = 0,
};

static struct viewport vp2 =
{
    .x        = 0,
    .y        = 1,
    .width    = LCD_WIDTH,
    .height   = 1,
    .xmargin  = 0,
    .ymargin  = 0,
};


enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
{
    (void)parameter;

    rb = api;

    rb->screens[SCREEN_MAIN]->set_viewport(&vp0);
    rb->screens[SCREEN_MAIN]->clear_viewport();
    rb->screens[SCREEN_MAIN]->puts_scroll(0,0,"Rockbox");

    rb->screens[SCREEN_MAIN]->set_viewport(&vp1);
    rb->screens[SCREEN_MAIN]->clear_viewport();
    rb->screens[SCREEN_MAIN]->puts_scroll(0,0,"Viewports");

    rb->screens[SCREEN_MAIN]->set_viewport(&vp2);
    rb->screens[SCREEN_MAIN]->clear_viewport();
    rb->screens[SCREEN_MAIN]->puts_scroll(0,0,"Demonstration");

    rb->screens[SCREEN_MAIN]->update();

    rb->button_get(true);

    /* Restore the default viewport */
    rb->screens[SCREEN_MAIN]->set_viewport(NULL);

    return PLUGIN_OK;
}

#endif /* !HAVE_LCD_BITMAP */