udelay between command and data write seems to get rid of the display glitches on...
[kugel-rb.git] / utils / newparser / skin_render.c
blobd8facb03f686458da4533ac778809c133c3dd944
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: skin_parser.c 26752 2010-06-10 21:22:16Z bieber $
10 * Copyright (C) 2010 Jonathan Gordon
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 #include <stdlib.h>
23 #include <stdio.h>
24 #include <string.h>
25 #include <stdbool.h>
26 #include <ctype.h>
27 #include <string.h>
29 #include "skin_parser.h"
30 #include "skin_debug.h"
31 #include "tag_table.h"
32 #include "symbols.h"
33 #include "skin_scan.h"
34 #include "skin_structs.h"
36 #define MAX_LINE 1024
38 typedef void (*skin_render_func)(struct skin_element* alternator,
39 char* buf, size_t buf_size, int line_number);
40 void skin_render_alternator(struct skin_element* alternator,
41 char* buf, size_t buf_size, int line_number);
43 static void do_tags_in_hidden_conditional(struct skin_element* branch)
45 /* Tags here are ones which need to be "turned off" or cleared
46 * if they are in a conditional branch which isnt being used */
47 if (branch->type == SUBLINES)
49 int i;
50 for (i=0; i<branch->children_count; i++)
52 do_tags_in_hidden_conditional(branch->children[i]);
55 else if (branch->type == LINE)
57 struct skin_element *child = branch->children[0];
58 while (child)
60 if (child->type != TAG)
62 child = child->next;
63 continue;
65 switch (child->tag->type)
67 case SKIN_TOKEN_PEAKMETER:
68 /* stop the peak meter */
69 break;
70 case SKIN_TOKEN_ALBUMART_DISPLAY:
71 /* clear the AA image */
72 break;
73 case SKIN_TOKEN_IMAGE_DISPLAY:
74 case SKIN_TOKEN_IMAGE_PRELOAD_DISPLAY:
75 printf("disable image\n");
76 /* clear images */
77 break;
78 default:
79 break;
81 child = child->next;
87 /* Draw a LINE element onto the display */
88 void skin_render_line(struct skin_element* line,
89 char* buf, size_t buf_size, int line_number)
91 int last_value, value;
92 if (line->children_count == 0)
93 return; /* empty line, do nothing */
94 struct skin_element *child = line->children[0];
95 skin_render_func func = skin_render_line;
96 char tempbuf[128];
97 while (child)
99 tempbuf[0] = '\0';
100 switch (child->type)
102 case CONDITIONAL:
103 last_value = ((struct conditional*)(child->data))->last_value;
104 value = 0; /* actually get it from the token :p */
105 if (value >= child->children_count)
106 value = child->children_count-1;
108 /* some tags need handling if they are being disabled */
109 if (value != last_value && last_value < child->children_count)
110 do_tags_in_hidden_conditional(child->children[last_value]);
111 last_value = value;
113 if (child->children[value]->type == SUBLINES)
114 func = skin_render_alternator;
115 else if (child->children[value]->type == LINE)
116 func = skin_render_line;
117 func(child->children[value], buf, buf_size, line_number);
118 break;
119 case TAG:
120 snprintf(tempbuf, sizeof(tempbuf), "%%%s", child->tag->name);
121 break;
122 case TEXT:
123 snprintf(tempbuf, sizeof(tempbuf), "%s", (char*)(child->data));
124 break;
125 case COMMENT:
126 default:
127 break;
129 strcat(buf, tempbuf);
130 child = child->next;
133 #define TIME_AFTER(a,b) 1
134 void skin_render_alternator(struct skin_element* alternator,
135 char* buf, size_t buf_size, int line_number)
137 struct subline *subline = (struct subline*)alternator->data;
138 if (TIME_AFTER(subline->last_change_tick + subline->timeout, 0/*FIXME*/))
140 subline->current_line++;
141 if (subline->current_line >= alternator->children_count)
142 subline->current_line = 0;
144 skin_render_line(alternator->children[subline->current_line],
145 buf, buf_size, line_number);
148 void skin_render_viewport(struct skin_element* viewport, bool draw_tags)
150 int line_number = 0;
151 char linebuf[MAX_LINE];
152 skin_render_func func = skin_render_line;
153 struct skin_element* line = viewport;
154 while (line)
156 linebuf[0] = '\0';
157 if (line->type == SUBLINES)
158 func = skin_render_alternator;
159 else if (line->type == LINE)
160 func = skin_render_line;
162 func(line, linebuf, sizeof(linebuf), line_number);
163 if (draw_tags)
165 printf("[%d]%s", line_number, linebuf);
166 if (!((struct line*)line->data)->eat_line_ending)
168 printf("\n");
171 if (!((struct line*)line->data)->eat_line_ending)
172 line_number++;
173 line = line->next;
177 void skin_render(struct skin_element* root)
179 struct skin_element* viewport = root;
180 bool draw_tags = viewport->next ? false : true;
181 while (viewport)
183 skin_render_viewport(viewport->children[0], draw_tags);
184 draw_tags = true;
185 viewport = viewport->next;