1
0
Fork 0
forked from len0rd/rockbox

get the renderer working more better! "handle" sublines correctly, dont "draw" in the first viewport if we are using viewports, get rid of the idea of a linear token array (i.e we are going to use the parse tree directly)

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26831 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Jonathan Gordon 2010-06-13 13:54:34 +00:00
parent 93460f50ba
commit 21cbdac55f
5 changed files with 70 additions and 49 deletions

View file

@ -1,3 +1,3 @@
all:
gcc -I../themeeditor -g -Wall -o newparser newparser.c skin_render.c handle_tags.c ../themeeditor/skin_parser.c ../themeeditor/skin_scan.c ../themeeditor/skin_debug.c ../themeeditor/tag_table.c
gcc -I. -I../themeeditor -g -Wall -o newparser newparser.c handle_tags.c skin_render.c ../themeeditor/skin_parser.c ../themeeditor/skin_scan.c ../themeeditor/skin_debug.c ../themeeditor/tag_table.c

View file

@ -25,6 +25,7 @@
#include <string.h>
#include <ctype.h>
#include "symbols.h"
#include "skin_parser.h"
#include "tag_table.h"
#include "skin_structs.h"
@ -35,32 +36,22 @@ typedef int (tag_handler)(struct skin *skin, struct skin_element* element, bool
int handle_translate_string(struct skin *skin, struct skin_element* element, bool size_only)
{
struct skin_token *token = &skin->tokens[skin->token_count++];
token->type = element->tag->type;
token->next = false;
token->value.i = 1; /* actually need to fix this */
return 0;
}
int handle_this_or_next_track(struct skin *skin, struct skin_element* element, bool size_only)
{
struct skin_token *token = &skin->tokens[skin->token_count++];
token->type = element->tag->type;
token->next = element->tag->name[0] == 'D'
|| element->tag->name[0] == 'I'
|| element->tag->name[0] == 'F';
if (element->tag->type == SKIN_TOKEN_FILE_DIRECTORY)
{
if (element->params_count != 1 || element->params[0].type_code != NUMERIC)
return -1;
token->value.i = element->params[0].data.numeric;
//token->value.i = element->params[0].data.numeric;
}
return 0;
}
int handle_bar(struct skin *skin, struct skin_element* element, bool size_only)
{
struct skin_token *token = &skin->tokens[skin->token_count++];
struct progressbar bar;
/* %bar with no params is different for each one so handle that! */
if (element->params_count == 0)
@ -79,7 +70,6 @@ int handle_bar(struct skin *skin, struct skin_element* element, bool size_only)
return sizeof(struct progressbar);
}
token->type = element->tag->type;
return 0;
}
@ -128,6 +118,13 @@ int handle_tree(struct skin *skin, struct skin_element* tree)
int counter;
while (element)
{
if (element->type == SUBLINES)
{
struct subline *subline = malloc(sizeof(struct subline));
subline->current_line = -1;
subline->last_change_tick = 0;
element->data = subline;
}
if (element->type == TAG)
{
int i;

View file

@ -73,8 +73,8 @@ int main(int argc, char* argv[])
struct skin_element* tree = skin_parse(buffer);
struct skin skin;
handle_tree(&skin, tree);
skin_render(tree);
//handle_tree(&skin, tree);
skin_free_tree(tree);
return 0;

View file

@ -22,25 +22,37 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>
#include <string.h>
#include "skin_parser.h"
#include "skin_debug.h"
#include "tag_table.h"
#include "symbols.h"
#include "skin_scan.h"
#include "skin_structs.h"
void skin_render_alternator(struct skin_element* alternator, int line_number);
#define MAX_LINE 1024
typedef void (*skin_render_func)(struct skin_element* alternator,
char* buf, size_t buf_size, int line_number);
void skin_render_alternator(struct skin_element* alternator,
char* buf, size_t buf_size, int line_number);
/* Draw a LINE element onto the display */
void skin_render_line(struct skin_element* line, int line_number)
void skin_render_line(struct skin_element* line,
char* buf, size_t buf_size, int line_number)
{
int i=0, value;
int value;
if (line->children_count == 0)
return; /* empty line, do nothing */
struct skin_element *child = line->children[0];
skin_render_func func = skin_render_line;
char tempbuf[128];
while (child)
{
tempbuf[0] = '\0';
switch (child->type)
{
case CONDITIONAL:
@ -48,41 +60,58 @@ void skin_render_line(struct skin_element* line, int line_number)
if (value >= child->children_count)
value = child->children_count-1;
if (child->children[value]->type == SUBLINES)
skin_render_alternator(child->children[value], line_number);
func = skin_render_alternator;
else if (child->children[value]->type == LINE)
skin_render_line(child->children[value], line_number);
func = skin_render_line;
func(child->children[value], buf, buf_size, line_number);
break;
case TAG:
printf("%%%s", child->tag->name);
snprintf(tempbuf, sizeof(tempbuf), "%%%s", child->tag->name);
break;
case TEXT:
printf("%s", (char*)(child->data));
snprintf(tempbuf, sizeof(tempbuf), "%s", (char*)(child->data));
break;
case COMMENT:
default:
break;
}
strcat(buf, tempbuf);
child = child->next;
}
}
void skin_render_alternator(struct skin_element* alternator, int line_number)
#define TIME_AFTER(a,b) 1
void skin_render_alternator(struct skin_element* alternator,
char* buf, size_t buf_size, int line_number)
{
/*TODO Choose which subline to draw */
skin_render_line(alternator->children[0], line_number);
struct subline *subline = (struct subline*)alternator->data;
if (TIME_AFTER(subline->last_change_tick + subline->timeout, 0/*FIXME*/))
{
subline->current_line++;
if (subline->current_line >= alternator->children_count)
subline->current_line = 0;
}
skin_render_line(alternator->children[subline->current_line],
buf, buf_size, line_number);
}
void skin_render_viewport(struct skin_element* viewport)
void skin_render_viewport(struct skin_element* line, bool draw_tags)
{
struct skin_element *line = viewport;
int line_number = 0;
char linebuf[MAX_LINE];
skin_render_func func = skin_render_line;
while (line)
{
printf("\n[%d]", line_number); /* might be incorrect */
linebuf[0] = '\0';
if (line->type == SUBLINES)
skin_render_alternator(line, line_number);
func = skin_render_alternator;
else if (line->type == LINE)
skin_render_line(line, line_number);
func = skin_render_line;
func (line, linebuf, sizeof(linebuf), line_number);
if (draw_tags)
{
printf("%s\n", linebuf);
}
line_number++;
line = line->next;
}
@ -91,9 +120,11 @@ void skin_render_viewport(struct skin_element* viewport)
void skin_render(struct skin_element* root)
{
struct skin_element* viewport = root;
bool draw_tags = viewport->next ? false : true;
while (viewport)
{
skin_render_viewport(viewport->children[0]);
skin_render_viewport(viewport->children[0], draw_tags);
draw_tags = true;
viewport = viewport->next;
}
}

View file

@ -27,26 +27,10 @@
#include "skin_parser.h"
#include "tag_table.h"
struct skin_token {
enum skin_token_type type; /* enough to store the token type */
/* Whether the tag (e.g. track name or the album) refers the
current or the next song (false=current, true=next) */
bool next;
union {
char c;
unsigned int i;
void* data;
} value;
};
#define MAX_TOKENS 10000
#ifndef SKIN_STRUCTS_H_
#define SKIN_STRUCTS_H_
struct skin
{
int token_count;
struct skin_token tokens[MAX_TOKENS];
};
@ -66,3 +50,12 @@ struct progressbar {
// struct bitmap bm;
bool have_bitmap_pb;
};
struct subline {
int timeout;
int current_line;
unsigned long last_change_tick;
};
#endif