1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
29 #include "skin_parser.h"
30 #include "skin_debug.h"
31 #include "tag_table.h"
33 #include "skin_scan.h"
34 #include "skin_structs.h"
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
)
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];
60 if (child
->type
!= TAG
)
65 switch (child
->tag
->type
)
67 case SKIN_TOKEN_PEAKMETER
:
68 /* stop the peak meter */
70 case SKIN_TOKEN_ALBUMART_DISPLAY
:
71 /* clear the AA image */
73 case SKIN_TOKEN_IMAGE_DISPLAY
:
74 case SKIN_TOKEN_IMAGE_PRELOAD_DISPLAY
:
75 printf("disable image\n");
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
;
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
]);
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
);
120 snprintf(tempbuf
, sizeof(tempbuf
), "%%%s", child
->tag
->name
);
123 snprintf(tempbuf
, sizeof(tempbuf
), "%s", (char*)(child
->data
));
129 strcat(buf
, tempbuf
);
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
)
151 char linebuf
[MAX_LINE
];
152 skin_render_func func
= skin_render_line
;
153 struct skin_element
* line
= viewport
;
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
);
165 printf("[%d]%s", line_number
, linebuf
);
166 if (!((struct line
*)line
->data
)->eat_line_ending
)
171 if (!((struct line
*)line
->data
)->eat_line_ending
)
177 void skin_render(struct skin_element
* root
)
179 struct skin_element
* viewport
= root
;
180 bool draw_tags
= viewport
->next
? false : true;
183 skin_render_viewport(viewport
->children
[0], draw_tags
);
185 viewport
= viewport
->next
;