Start dealing with LINE elements... setup a flag which lets tags tell the renderer to not start a new line in the viewport (i.e %we/d/i %X/x/xd etc)

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26833 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Jonathan Gordon 2010-06-13 14:42:09 +00:00
parent a8c073216d
commit 17c3484325
4 changed files with 37 additions and 11 deletions

View file

@ -22,6 +22,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <ctype.h>
@ -78,8 +79,11 @@ struct tag_handler_table {
int flags;
tag_handler *func;
};
#define EAT_LINE_ENDING 0x01
struct tag_handler_table table[] = {
{ SKIN_TOKEN_ENABLE_THEME, EAT_LINE_ENDING, NULL },
{ SKIN_TOKEN_DISABLE_THEME, EAT_LINE_ENDING, NULL },
/* file tags */
{ SKIN_TOKEN_FILE_BITRATE , 0, handle_this_or_next_track },
{ SKIN_TOKEN_FILE_CODEC , 0, handle_this_or_next_track },
@ -108,31 +112,43 @@ struct tag_handler_table table[] = {
{ SKIN_TOKEN_TRANSLATEDSTRING, 0, handle_translate_string},
};
int handle_tree(struct skin *skin, struct skin_element* tree)
int handle_tree(struct skin *skin, struct skin_element* tree, struct line *line)
{
/* for later.. do this in two steps
* 1) count how much skin buffer is needed
* 2) do the actual tree->skin conversion
*/
struct skin_element* element = tree;
struct line *current_line = line;
int counter;
while (element)
{
if (element->type == SUBLINES)
if (element->type == LINE)
{
struct line *line = (struct line*)malloc(sizeof(struct line));
line->update_mode = 0;
line->eat_line_ending = false;
element->data = line;
current_line = line;
}
else 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)
else if (element->type == TAG)
{
int i;
int i;
for(i=0;i<sizeof(table)/sizeof(*table);i++)
{
if (table[i].type == element->tag->type)
{
table[i].func(skin, element, false);
if (table[i].func)
table[i].func(skin, element, false);
if (table[i].flags&EAT_LINE_ENDING)
line->eat_line_ending = true;
break;
}
}
@ -145,7 +161,7 @@ int handle_tree(struct skin *skin, struct skin_element* tree)
counter = 0;
while (counter < element->children_count)
{
int ret = handle_tree(skin, element->children[counter]);
int ret = handle_tree(skin, element->children[counter], current_line);
counter++;
}
element = element->next;

View file

@ -29,7 +29,7 @@
#include "tag_table.h"
#include "skin_structs.h"
int handle_tree(struct skin *skin, struct skin_element* tree);
int handle_tree(struct skin *skin, struct skin_element* tree, struct line* line);
void skin_render(struct skin_element* root);
int main(int argc, char* argv[])
@ -73,7 +73,7 @@ int main(int argc, char* argv[])
struct skin_element* tree = skin_parse(buffer);
struct skin skin;
handle_tree(&skin, tree);
handle_tree(&skin, tree, NULL);
skin_render(tree);
skin_free_tree(tree);

View file

@ -94,11 +94,12 @@ void skin_render_alternator(struct skin_element* alternator,
buf, buf_size, line_number);
}
void skin_render_viewport(struct skin_element* line, bool draw_tags)
void skin_render_viewport(struct skin_element* viewport, bool draw_tags)
{
int line_number = 0;
char linebuf[MAX_LINE];
skin_render_func func = skin_render_line;
struct skin_element* line = viewport;
while (line)
{
linebuf[0] = '\0';
@ -107,10 +108,14 @@ void skin_render_viewport(struct skin_element* line, bool draw_tags)
else if (line->type == LINE)
func = skin_render_line;
func (line, linebuf, sizeof(linebuf), line_number);
func(line, linebuf, sizeof(linebuf), line_number);
if (draw_tags)
{
printf("%s\n", linebuf);
printf("%s", linebuf);
if (!((struct line*)line->data)->eat_line_ending)
{
printf("\n");
}
}
line_number++;
line = line->next;

View file

@ -51,6 +51,11 @@ struct progressbar {
bool have_bitmap_pb;
};
struct line {
unsigned update_mode;
bool eat_line_ending;
};
struct subline {
int timeout;
int current_line;