skin_engine: Automatically create touch regions for skin bars
[maemo-rb.git] / apps / gui / skin_engine / wps_internals.h
blobab2bc3579ec98bc56f1d58caf2bfaddbab99c7d1
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 Nicolas Pennequin
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 /* This stuff is for the wps engine only.. anyone caught using this outside
23 * of apps/gui/wps_engine will be shot on site! */
25 #ifndef _WPS_ENGINE_INTERNALS_
26 #define _WPS_ENGINE_INTERNALS_
28 #include "tag_table.h"
29 #include "skin_parser.h"
30 #ifndef __PCTOOL__
31 #include "core_alloc.h"
32 #endif
34 /* Timeout unit expressed in HZ. In WPS, all timeouts are given in seconds
35 (possibly with a decimal fraction) but stored as integer values.
36 E.g. 2.5 is stored as 25. This means 25 tenth of a second, i.e. 25 units.
38 #define TIMEOUT_UNIT (HZ/10) /* I.e. 0.1 sec */
39 #define DEFAULT_SUBLINE_TIME_MULTIPLIER 20 /* In TIMEOUT_UNIT's */
41 /* TODO: sort this mess out */
43 #include "screen_access.h"
44 #include "statusbar.h"
45 #include "metadata.h"
47 #define TOKEN_VALUE_ONLY 0x0DEADC0D
49 /* wps_data*/
50 struct wps_token {
51 union {
52 char c;
53 unsigned short i;
54 long l;
55 OFFSETTYPE(void*) data;
56 } value;
58 enum skin_token_type type; /* enough to store the token type */
59 /* Whether the tag (e.g. track name or the album) refers the
60 current or the next song (false=current, true=next) */
61 bool next;
64 char* get_dir(char* buf, int buf_size, const char* path, int level);
67 struct skin_token_list {
68 OFFSETTYPE(struct wps_token *) token;
69 OFFSETTYPE(struct skin_token_list *) next;
72 #ifdef HAVE_LCD_BITMAP
73 struct gui_img {
74 OFFSETTYPE(struct viewport*) vp; /* The viewport to display this image in */
75 short int x; /* x-pos */
76 short int y; /* y-pos */
77 short int num_subimages; /* number of sub-images */
78 short int subimage_height; /* height of each sub-image */
79 struct bitmap bm;
80 int buflib_handle;
81 OFFSETTYPE(char*) label;
82 bool loaded; /* load state */
83 int display;
84 bool using_preloaded_icons; /* using the icon system instead of a bmp */
87 struct image_display {
88 OFFSETTYPE(char*) label;
89 int subimage;
90 OFFSETTYPE(struct wps_token*) token; /* the token to get the subimage number from */
91 int offset; /* offset into the bitmap strip to start */
94 struct progressbar {
95 enum skin_token_type type;
96 OFFSETTYPE(struct viewport *) vp;
97 /* regular pb */
98 short x;
99 /* >=0: explicitly set in the tag -> y-coord within the viewport
100 <0 : not set in the tag -> negated 1-based line number within
101 the viewport. y-coord will be computed based on the font height */
102 short y;
103 short width;
104 short height;
105 bool follow_lang_direction;
107 OFFSETTYPE(struct gui_img *) image;
109 bool invert_fill_direction;
110 bool nofill;
111 bool nobar;
112 OFFSETTYPE(struct gui_img *) slider;
113 bool horizontal;
114 OFFSETTYPE(struct gui_img *) backdrop;
117 struct draw_rectangle {
118 int x;
119 int y;
120 int width;
121 int height;
122 unsigned start_colour;
123 unsigned end_colour;
125 #endif
129 struct align_pos {
130 char* left;
131 char* center;
132 char* right;
135 #ifdef HAVE_LCD_BITMAP
136 #define WPS_MAX_TOKENS 1150
137 #else
138 #define WPS_MAX_TOKENS 64
139 #endif
141 enum wps_parse_error {
142 PARSE_OK,
143 PARSE_FAIL_UNCLOSED_COND,
144 PARSE_FAIL_INVALID_CHAR,
145 PARSE_FAIL_COND_SYNTAX_ERROR,
146 PARSE_FAIL_COND_INVALID_PARAM,
147 PARSE_FAIL_LIMITS_EXCEEDED,
149 #ifdef HAVE_LCD_COLOR
150 struct gradient_config {
151 unsigned start;
152 unsigned end;
153 unsigned text;
154 int lines_count;
156 #endif
158 #define VP_DRAW_HIDEABLE 0x1
159 #define VP_DRAW_HIDDEN 0x2
160 #define VP_DRAW_WASHIDDEN 0x4
161 /* these are never drawn, nor cleared, i.e. just ignored */
162 #define VP_NEVER_VISIBLE 0x8
163 #ifndef __PCTOOL__
164 #define VP_DEFAULT_LABEL -200
165 #else
166 #define VP_DEFAULT_LABEL NULL
167 #endif
168 #define VP_DEFAULT_LABEL_STRING "|"
169 struct skin_viewport {
170 struct viewport vp; /* The LCD viewport struct */
171 char hidden_flags;
172 bool is_infovp;
173 OFFSETTYPE(char*) label;
174 int parsed_fontid;
175 #if LCD_DEPTH > 1
176 bool output_to_backdrop_buffer;
177 unsigned start_fgcolour;
178 unsigned start_bgcolour;
179 #ifdef HAVE_LCD_COLOR
180 struct gradient_config start_gradient;
181 #endif
182 #endif
184 struct viewport_colour {
185 OFFSETTYPE(struct viewport *) vp;
186 unsigned colour;
189 #ifdef HAVE_TOUCHSCREEN
190 struct touchregion {
191 OFFSETTYPE(char*) label; /* label to identify this region */
192 OFFSETTYPE(struct skin_viewport*) wvp;/* The viewport this region is in */
193 short int x; /* x-pos */
194 short int y; /* y-pos */
195 short int width; /* width */
196 short int height; /* height */
197 bool reverse_bar; /* if true 0% is the left or top */
198 bool allow_while_locked;
199 enum {
200 PRESS, /* quick press only */
201 LONG_PRESS, /* Long press without repeat */
202 REPEAT, /* long press allowing repeats */
203 } press_length;
204 int action; /* action this button will return */
205 bool armed; /* A region is armed on press. Only armed regions are triggered
206 on repeat or release. */
207 union { /* Extra data, action dependant */
208 struct touchsetting {
209 const struct settings_list *setting; /* setting being controlled */
210 union { /* Value to set the setting to for ACTION_SETTING_SET */
211 int number;
212 OFFSETTYPE(char*) text;
213 } value;
214 } setting_data;
215 int value;
217 long last_press; /* last tick this was pressed */
218 OFFSETTYPE(struct progressbar*) bar;
223 struct touchregion_lastpress {
224 OFFSETTYPE(struct touchregion *) region;
225 long timeout;
227 #endif
229 struct playlistviewer {
230 OFFSETTYPE(struct viewport *) vp;
231 bool show_icons;
232 int start_offset;
233 OFFSETTYPE(struct skin_element *) line;
237 #ifdef HAVE_ALBUMART
239 /* albumart definitions */
240 #define WPS_ALBUMART_NONE 0 /* WPS does not contain AA tag */
241 #define WPS_ALBUMART_CHECK 1 /* WPS contains AA conditional tag */
242 #define WPS_ALBUMART_LOAD 2 /* WPS contains AA tag */
244 #define WPS_ALBUMART_ALIGN_RIGHT 1 /* x align: right */
245 #define WPS_ALBUMART_ALIGN_CENTER 2 /* x/y align: center */
246 #define WPS_ALBUMART_ALIGN_LEFT 4 /* x align: left */
247 #define WPS_ALBUMART_ALIGN_TOP 1 /* y align: top */
248 #define WPS_ALBUMART_ALIGN_BOTTOM 4 /* y align: bottom */
250 struct skin_albumart {
251 /* Album art support */
252 int x;
253 int y;
254 int width;
255 int height;
257 unsigned char xalign; /* WPS_ALBUMART_ALIGN_LEFT, _CENTER, _RIGHT */
258 unsigned char yalign; /* WPS_ALBUMART_ALIGN_TOP, _CENTER, _BOTTOM */
259 unsigned char state; /* WPS_ALBUMART_NONE, _CHECK, _LOAD */
261 OFFSETTYPE(struct viewport *) vp;
262 int draw_handle;
264 #endif
267 struct line {
268 unsigned update_mode;
271 struct line_alternator {
272 int current_line;
273 unsigned long next_change_tick;
276 struct conditional {
277 int last_value;
278 OFFSETTYPE(struct wps_token *) token;
281 struct logical_if {
282 OFFSETTYPE(struct wps_token *) token;
283 enum {
284 IF_EQUALS, /* == */
285 IF_NOTEQUALS, /* != */
286 IF_LESSTHAN, /* < */
287 IF_LESSTHAN_EQ, /* <= */
288 IF_GREATERTHAN, /* > */
289 IF_GREATERTHAN_EQ /* >= */
290 } op;
291 struct skin_tag_parameter operand;
292 int num_options;
295 struct substring {
296 int start;
297 int length;
298 bool expect_number;
299 OFFSETTYPE(struct wps_token *) token;
302 struct listitem {
303 bool wrap;
304 short offset;
307 #ifdef HAVE_SKIN_VARIABLES
308 struct skin_var {
309 OFFSETTYPE(const char *) label;
310 int value;
311 long last_changed;
313 struct skin_var_lastchange {
314 OFFSETTYPE(struct skin_var *) var;
315 long timeout;
317 struct skin_var_changer {
318 OFFSETTYPE(struct skin_var *) var;
319 int newval;
320 bool direct; /* true to make val=newval, false for val += newval */
321 int max;
323 #endif
325 /* wps_data
326 this struct holds all necessary data which describes the
327 viewable content of a wps */
328 struct wps_data
330 int buflib_handle;
332 OFFSETTYPE(struct skin_element *) tree;
333 #ifdef HAVE_LCD_BITMAP
334 OFFSETTYPE(struct skin_token_list *) images;
335 OFFSETTYPE(int *) font_ids;
336 int font_count;
337 #endif
338 #ifdef HAVE_BACKDROP_IMAGE
339 int backdrop_id;
340 bool use_extra_framebuffer;
341 #endif
343 #ifdef HAVE_TOUCHSCREEN
344 OFFSETTYPE(struct skin_token_list *) touchregions;
345 bool touchscreen_locked;
346 #endif
347 #ifdef HAVE_ALBUMART
348 OFFSETTYPE(struct skin_albumart *) albumart;
349 int playback_aa_slot;
350 #endif
352 #ifdef HAVE_SKIN_VARIABLES
353 OFFSETTYPE(struct skin_token_list *) skinvars;
354 #endif
356 #ifdef HAVE_LCD_BITMAP
357 bool peak_meter_enabled;
358 bool wps_sb_tag;
359 bool show_sb_on_wps;
360 #else /*HAVE_LCD_CHARCELLS */
361 unsigned short wps_progress_pat[8];
362 bool full_line_progressbar;
363 #endif
364 bool wps_loaded;
367 #ifndef __PCTOOL__
368 static inline char* get_skin_buffer(struct wps_data* data)
370 if (data->buflib_handle >= 0)
371 return core_get_data(data->buflib_handle);
372 return NULL;
374 #else
375 #define get_skin_buffer(d) skin_buffer
376 #endif
378 /* wps_data end */
380 /* wps_state
381 holds the data which belongs to the current played track,
382 the track which will be played afterwards, current path to the track
383 and some status infos */
384 struct wps_state
386 struct mp3entry* id3;
387 struct mp3entry* nid3;
388 int ff_rewind_count;
389 bool ff_rewind;
390 bool paused;
391 bool is_fading;
394 /* change the ff/rew-status
395 if ff_rew = true then we are in skipping mode
396 else we are in normal mode */
397 /* void wps_state_update_ff_rew(bool ff_rew); Currently unused */
399 /* change the tag-information of the current played track
400 and the following track */
401 /* void wps_state_update_id3_nid3(struct mp3entry *id3, struct mp3entry *nid3); Currently unused */
402 /* wps_state end*/
404 /* gui_wps
405 defines a wps with its data, state,
406 and the screen on which the wps-content should be drawn */
407 struct gui_wps
409 struct screen *display;
410 struct wps_data *data;
413 /* gui_wps end */
415 void get_image_filename(const char *start, const char* bmpdir,
416 char *buf, int buf_size);
417 /***** wps_tokens.c ******/
419 const char *get_token_value(struct gui_wps *gwps,
420 struct wps_token *token, int offset,
421 char *buf, int buf_size,
422 int *intval);
424 /* Get the id3 fields from the cuesheet */
425 const char *get_cuesheetid3_token(struct wps_token *token, struct mp3entry *id3,
426 int offset_tracks, char *buf, int buf_size);
427 const char *get_id3_token(struct wps_token *token, struct mp3entry *id3,
428 char *filename, char *buf, int buf_size, int limit, int *intval);
429 #if CONFIG_TUNER
430 const char *get_radio_token(struct wps_token *token, int preset_offset,
431 char *buf, int buf_size, int limit, int *intval);
432 #endif
434 enum skin_find_what {
435 SKIN_FIND_VP = 0,
436 SKIN_FIND_UIVP,
437 #ifdef HAVE_LCD_BITMAP
438 SKIN_FIND_IMAGE,
439 #endif
440 #ifdef HAVE_TOUCHSCREEN
441 SKIN_FIND_TOUCHREGION,
442 #endif
443 #ifdef HAVE_SKIN_VARIABLES
444 SKIN_VARIABLE,
445 #endif
447 void *skin_find_item(const char *label, enum skin_find_what what,
448 struct wps_data *data);
449 #ifdef SIMULATOR
450 #define DEBUG_SKIN_ENGINE
451 extern bool debug_wps;
452 #endif
454 #endif