rockbox/apps/gui/skin_engine/wps_internals.h

440 lines
12 KiB
C
Raw Normal View History

/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2007 Nicolas Pennequin
*
* 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.
*
****************************************************************************/
/* This stuff is for the wps engine only.. anyone caught using this outside
* of apps/gui/wps_engine will be shot on site! */
#ifndef _WPS_ENGINE_INTERNALS_
#define _WPS_ENGINE_INTERNALS_
/* Timeout unit expressed in HZ. In WPS, all timeouts are given in seconds
(possibly with a decimal fraction) but stored as integer values.
E.g. 2.5 is stored as 25. This means 25 tenth of a second, i.e. 25 units.
*/
#define TIMEOUT_UNIT (HZ/10) /* I.e. 0.1 sec */
#define DEFAULT_SUBLINE_TIME_MULTIPLIER 20 /* In TIMEOUT_UNIT's */
#include "skin_tokens.h"
#include "tag_table.h"
#include "skin_parser.h"
/* TODO: sort this mess out */
#include "screen_access.h"
#include "statusbar.h"
#include "metadata.h"
/* alignments */
#define WPS_ALIGN_RIGHT 32
#define WPS_ALIGN_CENTER 64
#define WPS_ALIGN_LEFT 128
#define TOKEN_VALUE_ONLY 0x0DEADC0D
#ifdef HAVE_ALBUMART
/* albumart definitions */
#define WPS_ALBUMART_NONE 0 /* WPS does not contain AA tag */
#define WPS_ALBUMART_CHECK 1 /* WPS contains AA conditional tag */
#define WPS_ALBUMART_LOAD 2 /* WPS contains AA tag */
#define WPS_ALBUMART_ALIGN_RIGHT 1 /* x align: right */
#define WPS_ALBUMART_ALIGN_CENTER 2 /* x/y align: center */
#define WPS_ALBUMART_ALIGN_LEFT 4 /* x align: left */
#define WPS_ALBUMART_ALIGN_TOP 1 /* y align: top */
#define WPS_ALBUMART_ALIGN_BOTTOM 4 /* y align: bottom */
#endif /* HAVE_ALBUMART */
/* wps_data*/
#ifdef HAVE_LCD_BITMAP
struct gui_img {
struct viewport* vp; /* The viewport to display this image in */
short int x; /* x-pos */
short int y; /* y-pos */
short int num_subimages; /* number of sub-images */
short int subimage_height; /* height of each sub-image */
struct bitmap bm;
int buflib_handle;
const char *label;
bool loaded; /* load state */
bool always_display; /* not using the preload/display mechanism */
int display;
bool using_preloaded_icons; /* using the icon system instead of a bmp */
};
struct image_display {
const char *label;
int subimage;
struct wps_token *token; /* the token to get the subimage number from */
int offset; /* offset into the bitmap strip to start */
};
struct progressbar {
enum skin_token_type type;
struct viewport *vp;
/* regular pb */
short x;
/* >=0: explicitly set in the tag -> y-coord within the viewport
<0 : not set in the tag -> negated 1-based line number within
the viewport. y-coord will be computed based on the font height */
short y;
short width;
short height;
bool follow_lang_direction;
struct gui_img *image;
bool invert_fill_direction;
bool nofill;
bool nobar;
struct gui_img *slider;
bool horizontal;
struct gui_img *backdrop;
};
#endif
struct align_pos {
char* left;
char* center;
char* right;
};
#ifdef HAVE_LCD_BITMAP
#define MAX_IMAGES (26*2) /* a-z and A-Z */
#define MAX_PROGRESSBARS 3
/* The image buffer is big enough to store one full-screen native bitmap,
plus two full-screen mono bitmaps. */
#define WPS_MAX_VIEWPORTS 24
#define WPS_MAX_LINES ((LCD_HEIGHT/5+1) * 2)
#define WPS_MAX_SUBLINES (WPS_MAX_LINES*3)
#define WPS_MAX_TOKENS 1150
#define WPS_MAX_STRINGS 128
#define STRING_BUFFER_SIZE 1024
#define WPS_MAX_COND_LEVEL 10
#else
#define WPS_MAX_VIEWPORTS 2
#define WPS_MAX_LINES 2
#define WPS_MAX_SUBLINES 12
#define WPS_MAX_TOKENS 64
#define WPS_MAX_STRINGS 32
#define STRING_BUFFER_SIZE 64
#define WPS_MAX_COND_LEVEL 5
#endif
#define SUBLINE_RESET -1
enum wps_parse_error {
PARSE_OK,
PARSE_FAIL_UNCLOSED_COND,
PARSE_FAIL_INVALID_CHAR,
PARSE_FAIL_COND_SYNTAX_ERROR,
PARSE_FAIL_COND_INVALID_PARAM,
PARSE_FAIL_LIMITS_EXCEEDED,
};
#ifdef HAVE_LCD_COLOR
struct gradient_config {
unsigned start;
unsigned end;
unsigned text;
int lines_count;
};
#endif
Initial custom statusbar commit. The custom statusbar can be used as a WPS for the main UI, using .(r)sbs files. It's using the skin engine and knows all tags the WPS also knows. The default folder for .sbs is the wps folder to reuse images used in the WPS. As it can be shown in the WPS also, it's useful to move shared parts to the custom statusbar in order to save skin buffer space. There are a few restrictions/TODOs: *) Peak meter doesn't redraw nicely(not frequent enough), as very frequent updates would slow the UI down as hell (some targets fight with it in the WPS already: FS#10686) *) No touchregion support as the statusbar doesn't have any action handling (it won't fail to parse though). *) Drawing stuff into the default VP is forbidden (loading images in it is not). You *need* to use viewports for the displaying stuff (parsing fails if no viewport is used). *) Themes that don't use a custom ui viewport can be fixed up using the new %Vi tag to avoid nasty redraw effectts (you must not draw into it as well, it's used to fix up the ui viewport). %Vi describes the viewport that the lists can use without getting in the way of the statusbar. Otherwise, it behaves like the classic statusbar, it can be configured in the theme settings, and can be turned off in the wps using %wd. Note to translaters: When translating LANG_STATUSBAR_CUSTOM, please consider using the same translation as for LANG_CHANNEL_CUSTOM if it's compatible. They could be combined later then. Flyspray: FS#10566 Author: myself git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23258 a1c6a512-1295-4272-9138-f99709370657
2009-10-19 15:28:15 +00:00
#define VP_DRAW_HIDEABLE 0x1
#define VP_DRAW_HIDDEN 0x2
#define VP_DRAW_WASHIDDEN 0x4
/* these are never drawn, nor cleared, i.e. just ignored */
#define VP_NEVER_VISIBLE 0x8
#define VP_DEFAULT_LABEL "|"
struct skin_viewport {
struct viewport vp; /* The LCD viewport struct */
char hidden_flags;
bool is_infovp;
char* label;
int parsed_fontid;
#if LCD_DEPTH > 1
unsigned start_fgcolour;
unsigned start_bgcolour;
#ifdef HAVE_LCD_COLOR
struct gradient_config start_gradient;
#endif
#endif
};
struct viewport_colour {
struct viewport *vp;
unsigned colour;
};
Lists can now be completly draw using the skin engine! due to lack of user feedback the actual tags may change, hopefully not though. The way it works is the skin specifies a rectangle and a viewport label. For each item in the list that is being displayed all viewports with the specified label are drawn. However, instead of the viewport x/y position being offset from the top left corner like normal they are offset from the rectangle position in the list (so think of them as child-viewports of the rectangle which moves). Normally the rectangle will move down the screen to show a normal list, this can be changed to move across the screen in a grid pattern. The UI viewport is used to bound the items (i.e %Vi() ) Scrolling is completly disabled in all items except the currently selected item. This works well in combination with the %cs tag to show differently styled lists based on the current screen :) New tags: %LT - Get the current items text %LI - Get the current items icon number %Lc - Use as a conditional to determine if the current item is the selected item %LB - BAR TAG to show the scroll bar, params/options like other bar types. It still needs a bit of work though. Use as a conditional to find out if the bar is actually needed %Lb(viewport, width, height [,tile]) - specify the viewport label to draw for each item and the size of each item. if the last param is 'tile' it will form a grid instead of a list example.sbs: %?cs<%Lb(a,100,20)|> %V(0,0,10,-,1)%Vf(aabbcc) %?LB<%LB(0,0,10,185, invert)> %Vi(-,10,0,-,-35,1) %Vl(a,5,5,160,12,1) %s%?Lc<%Vg(00ffaa, ff0000, 000000)%Vs(gradient)%>%>%>%ac>zzzzzzz %LT zzzzz%s%?Lc<%ar%<%<%<> %V(0,185,-,-,1) %s%LT git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30461 a1c6a512-1295-4272-9138-f99709370657
2011-09-06 13:49:41 +00:00
#ifdef HAVE_TOUCHSCREEN
struct touchregion {
char* label; /* label to identify this region */
struct skin_viewport* wvp;/* The viewport this region is in */
short int x; /* x-pos */
short int y; /* y-pos */
short int width; /* width */
short int height; /* height */
bool reverse_bar; /* if true 0% is the left or top */
bool allow_while_locked;
enum {
PRESS, /* quick press only */
LONG_PRESS, /* Long press without repeat */
REPEAT, /* long press allowing repeats */
} press_length;
int action; /* action this button will return */
bool armed; /* A region is armed on press. Only armed regions are triggered
on repeat or release. */
union { /* Extra data, action dependant */
struct touchsetting {
const struct settings_list *setting; /* setting being controlled */
union { /* Value to set the setting to for ACTION_SETTING_SET */
int number;
char* text;
} value;
} setting_data;
int value;
};
long last_press; /* last tick this was pressed */
};
struct touchregion_lastpress {
struct touchregion *region;
long timeout;
};
#endif
struct playlistviewer {
struct viewport *vp;
bool show_icons;
int start_offset;
struct skin_element *line;
};
#ifdef HAVE_ALBUMART
struct skin_albumart {
/* Album art support */
int x;
int y;
int width;
int height;
unsigned char xalign; /* WPS_ALBUMART_ALIGN_LEFT, _CENTER, _RIGHT */
unsigned char yalign; /* WPS_ALBUMART_ALIGN_TOP, _CENTER, _BOTTOM */
unsigned char state; /* WPS_ALBUMART_NONE, _CHECK, _LOAD */
struct viewport *vp;
int draw_handle;
};
#endif
struct line {
unsigned update_mode;
};
struct line_alternator {
int current_line;
unsigned long next_change_tick;
};
struct conditional {
int last_value;
struct wps_token *token;
};
struct logical_if {
struct wps_token *token;
enum {
IF_EQUALS, /* == */
IF_NOTEQUALS, /* != */
IF_LESSTHAN, /* < */
IF_LESSTHAN_EQ, /* <= */
IF_GREATERTHAN, /* > */
IF_GREATERTHAN_EQ /* >= */
} op;
struct skin_tag_parameter operand;
int num_options;
};
struct substring {
int start;
int length;
struct wps_token *token;
};
struct listitem {
bool wrap;
short offset;
};
#ifdef HAVE_SKIN_VARIABLES
struct skin_var {
const char *label;
int value;
long last_changed;
};
struct skin_var_lastchange {
struct skin_var *var;
long timeout;
};
struct skin_var_changer {
struct skin_var *var;
int newval;
bool direct; /* true to make val=newval, false for val += newval */
int max;
};
#endif
/* wps_data
this struct holds all necessary data which describes the
viewable content of a wps */
struct wps_data
{
struct skin_element *tree;
#ifdef HAVE_LCD_BITMAP
struct skin_token_list *images;
int *font_ids;
int font_count;
#endif
#if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
struct {
char *backdrop;
int backdrop_id;
};
#endif
#ifdef HAVE_TOUCHSCREEN
struct skin_token_list *touchregions;
bool touchscreen_locked;
#endif
#ifdef HAVE_ALBUMART
struct skin_albumart *albumart;
int playback_aa_slot;
#endif
#ifdef HAVE_SKIN_VARIABLES
struct skin_token_list *skinvars;
#endif
#ifdef HAVE_LCD_BITMAP
bool peak_meter_enabled;
bool wps_sb_tag;
bool show_sb_on_wps;
#else /*HAVE_LCD_CHARCELLS */
unsigned short wps_progress_pat[8];
bool full_line_progressbar;
#endif
bool wps_loaded;
};
/* wps_data end */
/* wps_state
holds the data which belongs to the current played track,
the track which will be played afterwards, current path to the track
and some status infos */
struct wps_state
{
struct mp3entry* id3;
struct mp3entry* nid3;
int ff_rewind_count;
bool ff_rewind;
bool paused;
bool is_fading;
};
/* change the ff/rew-status
if ff_rew = true then we are in skipping mode
else we are in normal mode */
/* void wps_state_update_ff_rew(bool ff_rew); Currently unused */
/* change the tag-information of the current played track
and the following track */
/* void wps_state_update_id3_nid3(struct mp3entry *id3, struct mp3entry *nid3); Currently unused */
/* wps_state end*/
/* gui_wps
defines a wps with its data, state,
and the screen on which the wps-content should be drawn */
struct gui_wps
{
struct screen *display;
struct wps_data *data;
};
/* gui_wps end */
char *get_image_filename(const char *start, const char* bmpdir,
char *buf, int buf_size);
/***** wps_tokens.c ******/
const char *get_token_value(struct gui_wps *gwps,
struct wps_token *token, int offset,
char *buf, int buf_size,
int *intval);
/* Get the id3 fields from the cuesheet */
const char *get_cuesheetid3_token(struct wps_token *token, struct mp3entry *id3,
int offset_tracks, char *buf, int buf_size);
const char *get_id3_token(struct wps_token *token, struct mp3entry *id3,
char *filename, char *buf, int buf_size, int limit, int *intval);
#if CONFIG_TUNER
const char *get_radio_token(struct wps_token *token, int preset_offset,
char *buf, int buf_size, int limit, int *intval);
#endif
enum skin_find_what {
SKIN_FIND_VP = 0,
SKIN_FIND_UIVP,
#ifdef HAVE_LCD_BITMAP
SKIN_FIND_IMAGE,
#endif
#ifdef HAVE_TOUCHSCREEN
SKIN_FIND_TOUCHREGION,
#endif
#ifdef HAVE_SKIN_VARIABLES
SKIN_VARIABLE,
#endif
};
void *skin_find_item(const char *label, enum skin_find_what what,
struct wps_data *data);
#ifdef SIMULATOR
#define DEBUG_SKIN_ENGINE
extern bool debug_wps;
#endif
#endif