~ubuntu-branches/ubuntu/precise/ultrastar-ng/precise

« back to all changes in this revision

Viewing changes to src/theme.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Miriam Ruiz, Miriam Ruiz, Mario Bonino, Jon Dowland, Ansgar Burchardt
  • Date: 2008-06-07 16:43:18 UTC
  • mfrom: (4.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080607164318-4cnzizck1tp8mrwp
Tags: 0.2.1-1
[ Miriam Ruiz ]
* New Upstream Release (Closes: #453132)
* Removed unneeded patches
* Added packages to build deps:
  + libtool
  + portaudio19-dev | portaudio-dev
  + libboost-dev, libboost-thread-dev, libboost-serialization-dev
  + libboost-program-options-dev, libboost-regex-dev
* Moved shared objects to private directory: /usr/lib/ultraster-ng
* Added rpath to binaries to search for shared objects in the private dir
* Uses ultrastar-ng-gstreamer as default, instead of ultrastar-ng-xine,
  since there are significantly less issues with GStreamer.
* Added patch to fix upstream desktop file
* Added -Wl,-as-needed to LDFLAGS
* Replaced fftw3-dev by libfftw3-dev in build dependencies.
* Standards-Version upgraded to 3.7.3

[ Mario Bonino ]
* Fixed data/Makefile.am to install .desktop file and icon

[ Jon Dowland ]
* add Homepage: control field to source stanza
* fix a bashism in debian/rules (Closes: #478634)

[ Ansgar Burchardt ]
* debian/control: Change XS-Vcs-* to Vcs-*
* Remove Homepage semi-field from description

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include <theme.h>
2
2
#include <screen.h>
3
3
 
4
 
CTheme::CTheme(int _width, int _height) 
5
 
        :width(_width),
6
 
        height(_height),
7
 
        surface(NULL),
8
 
        dc(NULL) {
9
 
        clear();
 
4
CTheme::CTheme(int _width, int _height):
 
5
  width(_width),
 
6
  height(_height),
 
7
  surface(NULL),
 
8
  dc(NULL)
 
9
{
 
10
        clear();
10
11
}
 
12
 
11
13
void CTheme::clear() {
12
 
        if(this->dc) {
13
 
            cairo_destroy(dc);
14
 
        }
15
 
        if(this->surface) {
16
 
            cairo_surface_destroy(surface);
17
 
        }
18
 
        surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
19
 
        dc = cairo_create(surface);
 
14
        if (dc) cairo_destroy(dc);
 
15
        if (surface) cairo_surface_destroy(surface);
 
16
        surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
 
17
        dc = cairo_create(surface);
20
18
}
 
19
 
21
20
cairo_surface_t *CTheme::PrintText(TThemeTxt *text) {
22
 
        cairo_save(dc);
23
 
        cairo_scale(dc, width/text->svg_width, height/text->svg_height);
24
 
        cairo_select_font_face(dc, text->fontfamily, text->fontstyle, text->fontweight);
25
 
        cairo_set_font_size(dc, text->fontsize);
26
 
        cairo_move_to(dc, text->x, text->y);
27
 
        cairo_text_extents(dc, text->text, &(text->extents));
28
 
        cairo_move_to(dc, text->x - (text->extents.width - text->extents.width/text->scale)/2, text->y - (text->extents.height - text->extents.height/text->scale)/2);
29
 
        cairo_set_font_size(dc, text->fontsize * text->scale);
30
 
        cairo_text_path(dc, text->text);
31
 
        if (text->fill_col.r != -1 && text->fill_col.g != -1 && text->fill_col.b != -1) {
32
 
            cairo_set_source_rgba(dc, text->fill_col.r, text->fill_col.g, text->fill_col.b, text->fill_col.a);
33
 
            if (text->stroke_col.r != -1 && text->stroke_col.g != -1 && text->stroke_col.b != -1)
34
 
                cairo_fill_preserve(dc);
35
 
            else
36
 
                cairo_fill(dc);
37
 
        }
38
 
        if (text->stroke_col.r != -1 && text->stroke_col.g != -1 && text->stroke_col.b != -1) {
39
 
            cairo_set_line_width(dc, text->stroke_width);
40
 
            cairo_set_source_rgba(dc, text->stroke_col.r, text->stroke_col.b, text->stroke_col.g, text->stroke_col.a);
41
 
            cairo_stroke(dc);
42
 
        }
43
 
        cairo_restore(dc);
44
 
        return surface;
 
21
        PangoFontDescription *desc = pango_font_description_new();
 
22
        PangoLayout *layout = pango_cairo_create_layout(dc);
 
23
        pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER );
 
24
        PangoRectangle rec;
 
25
 
 
26
        cairo_save(dc);
 
27
 
 
28
        pango_font_description_set_family(desc, text->fontfamily.c_str());
 
29
        pango_font_description_set_style (desc,PANGO_STYLE_NORMAL);
 
30
        pango_font_description_set_absolute_size (desc,text->fontsize * PANGO_SCALE);
 
31
        pango_layout_set_font_description (layout, desc);
 
32
        pango_layout_set_text (layout, text->text.c_str(), -1);
 
33
        pango_layout_get_pixel_extents (layout,NULL,&rec);
 
34
        text->extents.width = rec.width;
 
35
        text->extents.height = rec.height;
 
36
        text->extents.x_advance = rec.width+rec.x;
 
37
        text->extents.y_advance = rec.height+rec.y;
 
38
        pango_font_description_set_absolute_size (desc,text->fontsize * text->scale * PANGO_SCALE);
 
39
        pango_layout_set_font_description (layout, desc);
 
40
        pango_cairo_update_layout (dc, layout);
 
41
        cairo_scale(dc, width/text->svg_width, height/text->svg_height);
 
42
        cairo_move_to(dc,text->x - (rec.width-rec.width/text->scale)/2,text->y-text->fontsize * text->scale);
 
43
        pango_cairo_show_layout (dc, layout);
 
44
        pango_cairo_layout_path(dc,layout);
 
45
        if (text->fill_col.r != -1 && text->fill_col.g != -1 && text->fill_col.b != -1) {
 
46
                cairo_set_source_rgba(dc, text->fill_col.r, text->fill_col.g, text->fill_col.b, text->fill_col.a);
 
47
                if (text->stroke_col.r != -1 && text->stroke_col.g != -1 && text->stroke_col.b != -1) cairo_fill_preserve(dc);
 
48
                else cairo_fill(dc);
 
49
        }
 
50
        if (text->stroke_col.r != -1 && text->stroke_col.g != -1 && text->stroke_col.b != -1) {
 
51
                cairo_set_line_width(dc, text->stroke_width);
 
52
                cairo_set_source_rgba(dc, text->stroke_col.r, text->stroke_col.g, text->stroke_col.b, text->stroke_col.a);
 
53
                cairo_stroke(dc);
 
54
        }
 
55
        cairo_restore(dc);
 
56
 
 
57
        g_object_unref(layout);
 
58
        pango_font_description_free(desc);
 
59
        return surface;
45
60
}
 
61
 
46
62
cairo_surface_t *CTheme::DrawRect(TThemeRect rect) {
47
 
        cairo_save(dc);
48
 
        cairo_scale(dc, width/rect.svg_width, height/rect.svg_height);
49
 
        cairo_rectangle(dc, rect.x, rect.y, rect.width, rect.height);
50
 
        if (rect.fill_col.r != -1 && rect.fill_col.g != -1 && rect.fill_col.b != -1) {
51
 
            cairo_set_source_rgba(dc, rect.fill_col.r, rect.fill_col.g, rect.fill_col.b, rect.fill_col.a);
52
 
            if (rect.stroke_col.r != -1 && rect.stroke_col.g != -1 && rect.stroke_col.b != -1)
53
 
                cairo_fill_preserve(dc);
54
 
            else
55
 
                cairo_fill(dc);
56
 
        }
57
 
        if (rect.stroke_col.r != -1 && rect.stroke_col.g != -1 && rect.stroke_col.b != -1) {
58
 
            cairo_set_line_width(dc, rect.stroke_width);
59
 
            cairo_set_source_rgba(dc, rect.stroke_col.r, rect.stroke_col.b, rect.stroke_col.g, rect.stroke_col.a);
60
 
            cairo_stroke(dc);
61
 
        }
62
 
        cairo_restore(dc);
63
 
        return surface;
 
63
        cairo_save(dc);
 
64
        cairo_scale(dc, width/rect.svg_width, height/rect.svg_height);
 
65
        cairo_rectangle(dc, rect.x, rect.y, rect.width, rect.height);
 
66
        if (rect.fill_col.r != -1 && rect.fill_col.g != -1 && rect.fill_col.b != -1) {
 
67
                cairo_set_source_rgba(dc, rect.fill_col.r, rect.fill_col.g, rect.fill_col.b, rect.fill_col.a);
 
68
                if (rect.stroke_col.r != -1 && rect.stroke_col.g != -1 && rect.stroke_col.b != -1) cairo_fill_preserve(dc);
 
69
                else cairo_fill(dc);
 
70
        }
 
71
        if (rect.stroke_col.r != -1 && rect.stroke_col.g != -1 && rect.stroke_col.b != -1) {
 
72
                cairo_set_line_width(dc, rect.stroke_width);
 
73
                cairo_set_source_rgba(dc, rect.stroke_col.r, rect.stroke_col.g, rect.stroke_col.b, rect.stroke_col.a);
 
74
                cairo_stroke(dc);
 
75
        }
 
76
        cairo_restore(dc);
 
77
        return surface;
64
78
}
 
79
 
65
80
cairo_text_extents_t CTheme::GetTextExtents(TThemeTxt text) {
66
 
        cairo_text_extents_t extents;
67
 
        cairo_select_font_face(dc, text.fontfamily, text.fontstyle, text.fontweight);
68
 
        cairo_set_font_size(dc, text.fontsize);
69
 
        cairo_move_to(dc, text.x, text.y);
70
 
        cairo_text_extents(dc, text.text, &extents);
71
 
        return extents;
72
 
}
73
 
void CTheme::ParseSVGForText(char *filename, TThemeTxt *text) {
74
 
        xmlDoc *doc = NULL;
75
 
        xmlNode *root_element = NULL;
76
 
        doc = xmlReadFile(filename, NULL, 0);
77
 
        root_element = xmlDocGetRootElement(doc);
78
 
        
79
 
        /* set some defaults */
80
 
        text->scale = 1.0;
81
 
        text->fontfamily[0]  ='\0';
82
 
        strncat(text->fontfamily,"Sans",4);
83
 
        text->fontstyle = CAIRO_FONT_SLANT_NORMAL;
84
 
        text->fontweight = CAIRO_FONT_WEIGHT_NORMAL;
85
 
        text->stroke_width = 0;
86
 
 
87
 
        walk_tree(root_element, text);
88
 
        xmlFreeDoc(doc);
89
 
        xmlCleanupParser();
90
 
}
91
 
void CTheme::ParseSVGForRect(char *filename, TThemeRect *rect) {
92
 
        xmlDoc *doc = NULL;
93
 
        xmlNode *root_element = NULL;
94
 
        doc = xmlReadFile(filename, NULL, 0);
95
 
        root_element = xmlDocGetRootElement(doc);
96
 
        /* set some defaults */
97
 
        rect->stroke_width = 0;
98
 
        
99
 
        walk_tree(root_element, rect);
100
 
        xmlFreeDoc(doc);
101
 
        xmlCleanupParser();
102
 
}
103
 
void CTheme::walk_tree(xmlNode * a_node, TThemeTxt *text)
104
 
{
105
 
    xmlNode *cur_node = NULL;
106
 
    xmlAttr *attr = NULL;
107
 
    char *string;
108
 
    for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
109
 
       if (cur_node->type == XML_ELEMENT_NODE) { 
110
 
            if (cur_node->properties != NULL) {
111
 
                attr = cur_node->properties;
112
 
                while (attr != NULL) {
113
 
                   if (!strcasecmp((char *) cur_node->name, "text")) {
114
 
                        if (!strcasecmp((char *) attr->name, "x")) {
115
 
                            string = (char *) xmlGetProp(cur_node, attr->name);
116
 
                            sscanf(string,"%lf",&(text->x));
117
 
                            xmlFree(string);
118
 
                        } else if (!strcasecmp((char *) attr->name, "y")) {
119
 
                            string = (char *) xmlGetProp(cur_node, attr->name);
120
 
                            sscanf(string,"%lf",&(text->y));
121
 
                            xmlFree(string);
122
 
                        } else if (!strcasecmp((char *) attr->name, "transform")) {
123
 
                            double x_trans, y_trans;
124
 
                            char tmp_string[10], *p; 
125
 
                            tmp_string[0] = '\0';
126
 
                            string = (char *) xmlGetProp(cur_node, attr->name);
127
 
                            if(!strncasecmp(string, "translate(", 10)) {
128
 
                                string += 10;
129
 
                                p = strchr(string, ',');
130
 
                                strncat(tmp_string, string, p - string);
131
 
                                sscanf(tmp_string, "%lf", &x_trans);
132
 
                                string = p + 1;
133
 
                                p = strchr(string, ')');
134
 
                                tmp_string[0] = '\0';
135
 
                                strncat(tmp_string, string, p - string);
136
 
                                sscanf(tmp_string, "%lf", &y_trans);
137
 
                                text->x += x_trans;
138
 
                                text->y += y_trans;
139
 
                            }
140
 
                            xmlFree(string);
141
 
                        } else if (!strcasecmp((char *) attr->name, "style")) {
142
 
                           string = strtok((char *) xmlGetProp(cur_node, attr->name), ";");
143
 
                           while (string != NULL) {
144
 
                                if (!strncasecmp(string, "font-size:", 10)) {
145
 
                                    sscanf((string + 10),"%lf", &(text->fontsize));
146
 
                                } else if (!strncasecmp(string, "font-family:", 12)) {
147
 
                                    text->fontfamily[0]  ='\0';
148
 
                                    strncat((*text).fontfamily, (string + 12), 31);     /* copy no more than 31 bytes to not caue buffer overrun */
149
 
                                } else if (!strncasecmp(string, "font-style:", 11)) {
150
 
                                    if(!strncasecmp((string + 11), "normal", 6)) {
151
 
                                        text->fontstyle = CAIRO_FONT_SLANT_NORMAL;
152
 
                                    } else if(!strncasecmp((string + 11), "italic", 6)) {
153
 
                                        text->fontstyle = CAIRO_FONT_SLANT_ITALIC;
154
 
                                    } else if(!strncasecmp((string + 11), "oblique", 7)) {
155
 
                                        text->fontstyle = CAIRO_FONT_SLANT_OBLIQUE;
156
 
                                    }
157
 
                                } else if (!strncasecmp(string, "font-weight:", 12)) {
158
 
                                    if(!strncasecmp((string + 12), "normal", 6)) {
159
 
                                        text->fontweight = CAIRO_FONT_WEIGHT_NORMAL;
160
 
                                    } else if(!strncasecmp((string + 12), "bold", 4)) {
161
 
                                        text->fontweight = CAIRO_FONT_WEIGHT_BOLD;
162
 
                                    }
163
 
                                } else if (!strncasecmp(string, "fill:", 5)) {
164
 
                                    getcolor((string + 5), &(text->fill_col));
165
 
                                } else if (!strncasecmp(string, "fill-opacity:", 13)) {
166
 
                                    sscanf((string + 13), "%lf", &(text->fill_col.a));
167
 
                                } else if (!strncasecmp(string, "stroke:", 7)) {
168
 
                                    getcolor((string + 7), &(text->stroke_col));
169
 
                                } else if (!strncasecmp(string, "stroke-opacity:", 15)) {
170
 
                                    sscanf((string + 15), "%lf", &(text->stroke_col.a));
171
 
                                } else if (!strncasecmp(string, "stroke-width:", 13)) {
172
 
                                    sscanf((string + 13),"%lf", &(text->stroke_width));
173
 
                                }
174
 
                                string = strtok(NULL, ";");
175
 
                           }
176
 
                           xmlFree(string);
177
 
 
178
 
                        }
179
 
 
180
 
                    } else if (!strcasecmp((char *) cur_node->name, "svg")) {
181
 
                         if (!strcasecmp((char *) attr->name, "width")) {
182
 
                            string = (char *) xmlGetProp(cur_node, attr->name);
183
 
                            sscanf(string,"%lf",&(text->svg_width));
184
 
                            xmlFree(string);
185
 
                        } else if (!strcasecmp((char *) attr->name, "height")) {
186
 
                            string = (char *) xmlGetProp(cur_node, attr->name);
187
 
                            sscanf(string,"%lf",&(text->svg_height));
188
 
                            xmlFree(string);
189
 
                        } 
190
 
                    }
191
 
                    attr = attr->next;
192
 
                }
193
 
            }
194
 
        }
195
 
        walk_tree(cur_node->children, text);
196
 
    }
197
 
}
198
 
void CTheme::walk_tree(xmlNode * a_node, TThemeRect *rect)
199
 
{
200
 
    xmlNode *cur_node = NULL;
201
 
    xmlAttr *attr = NULL;
202
 
    char *string;
203
 
    for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
204
 
       if (cur_node->type == XML_ELEMENT_NODE) { 
205
 
            if (cur_node->properties != NULL) {
206
 
                attr = cur_node->properties;
207
 
                while (attr != NULL) {
208
 
                    if (!strcasecmp((char *) cur_node->name, "rect")) {
209
 
                        if (!strcasecmp((char *) attr->name, "x")) {
210
 
                            string = (char *) xmlGetProp(cur_node, attr->name);
211
 
                            sscanf(string,"%lf",&(rect->x));
212
 
                            xmlFree(string);
213
 
                        } else if (!strcasecmp((char *) attr->name, "y")) {
214
 
                            string = (char *) xmlGetProp(cur_node, attr->name);
215
 
                            sscanf(string,"%lf",&(rect->y));
216
 
                            xmlFree(string);
217
 
                        } else if (!strcasecmp((char *) attr->name, "width")) {
218
 
                            string = (char *) xmlGetProp(cur_node, attr->name);
219
 
                            sscanf(string,"%lf",&(rect->final_width));
220
 
                            xmlFree(string);
221
 
                            rect->width = rect->final_width;
222
 
                        } else if (!strcasecmp((char *) attr->name, "height")) {
223
 
                            string = (char *) xmlGetProp(cur_node, attr->name);
224
 
                            sscanf(string,"%lf",&(rect->final_height));
225
 
                            xmlFree(string);
226
 
                            rect->height = rect->final_height;
227
 
                        } else if (!strcasecmp((char *) attr->name, "style")) {
228
 
                           string = (char *) xmlGetProp(cur_node, attr->name);
229
 
                           char * string_tmp = strtok(string, ";");
230
 
                           while (string_tmp != NULL) {
231
 
                                if (!strncasecmp(string_tmp, "fill:", 5)) {
232
 
                                    getcolor((string_tmp + 5), &(rect->fill_col));
233
 
                                } else if (!strncasecmp(string_tmp, "fill-opacity:", 13)) {
234
 
                                    sscanf((string_tmp + 13), "%lf", &(rect->fill_col.a));
235
 
                                } else if (!strncasecmp(string_tmp, "stroke:", 7)) {
236
 
                                    getcolor((string_tmp + 7), &(rect->stroke_col));
237
 
                                } else if (!strncasecmp(string_tmp, "stroke-opacity:", 15)) {
238
 
                                    sscanf((string_tmp + 15), "%lf", &(rect->stroke_col.a));
239
 
                                } else if (!strncasecmp(string_tmp, "stroke-width:", 13)) {
240
 
                                    sscanf((string_tmp + 13),"%lf", &(rect->stroke_width));
241
 
                                }
242
 
                                string_tmp = strtok(NULL, ";");
243
 
                           }
244
 
                           xmlFree(string);
245
 
 
246
 
                        }
247
 
 
248
 
                    } else if (!strcasecmp((char *) cur_node->name, "svg")) {
249
 
                        if (!strcasecmp((char *) attr->name, "width")) {
250
 
                            string = (char *) xmlGetProp(cur_node, attr->name);
251
 
                            sscanf(string,"%lf",&(rect->svg_width));
252
 
                            xmlFree(string);
253
 
                        } else if (!strcasecmp((char *) attr->name, "height")) {
254
 
                            string = (char *) xmlGetProp(cur_node, attr->name);
255
 
                            sscanf(string,"%lf",&(rect->svg_height));
256
 
                            xmlFree(string);
257
 
                        } 
258
 
                    }
259
 
                    attr = attr->next;
260
 
                }
261
 
            }
262
 
        }
263
 
        walk_tree(cur_node->children, rect);
264
 
    }
265
 
}
 
81
        cairo_text_extents_t extents;
 
82
 
 
83
        PangoContext* ctx=NULL;
 
84
        ctx = pango_cairo_font_map_create_context ((PangoCairoFontMap*)pango_cairo_font_map_get_default());
 
85
        PangoFontDescription *desc = pango_font_description_new();
 
86
        PangoLayout *layout = pango_layout_new(ctx);
 
87
        pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER );
 
88
        PangoRectangle rec;
 
89
 
 
90
        pango_font_description_set_family(desc, text.fontfamily.c_str());
 
91
        pango_font_description_set_style (desc,PANGO_STYLE_NORMAL);
 
92
        pango_font_description_set_absolute_size (desc,text.fontsize * PANGO_SCALE);
 
93
        pango_layout_set_font_description (layout, desc);
 
94
        pango_layout_set_text (layout, text.text.c_str(), -1);
 
95
        pango_layout_get_pixel_extents (layout,NULL,&rec);
 
96
        extents.width = rec.width;
 
97
        extents.height = rec.height;
 
98
        extents.x_advance = rec.width+rec.x;
 
99
        extents.y_advance = rec.height+rec.y;
 
100
 
 
101
        g_object_unref (layout);
 
102
        pango_font_description_free (desc);
 
103
        g_object_unref (ctx);
 
104
 
 
105
        return extents;
 
106
}
 
107
 
 
108
void CTheme::ParseSVGForText(std::string const& filename, TThemeTxt *text) {
 
109
        xmlDoc *doc = NULL;
 
110
        xmlNode *root_element = NULL;
 
111
        doc = xmlReadFile(filename.c_str(), NULL, 0);
 
112
        root_element = xmlDocGetRootElement(doc);
 
113
 
 
114
        /* set some defaults */
 
115
        text->scale = 1.0;
 
116
        text->fontfamily = "Sans";
 
117
        text->fontstyle = CAIRO_FONT_SLANT_NORMAL;
 
118
        text->fontweight = CAIRO_FONT_WEIGHT_NORMAL;
 
119
        text->stroke_width = 0;
 
120
 
 
121
        walk_tree(root_element, text);
 
122
        xmlFreeDoc(doc);
 
123
        xmlCleanupParser();
 
124
}
 
125
 
 
126
void CTheme::ParseSVGForRect(std::string const& filename, TThemeRect *rect) {
 
127
        xmlDoc *doc = NULL;
 
128
        xmlNode *root_element = NULL;
 
129
        doc = xmlReadFile(filename.c_str(), NULL, 0);
 
130
        root_element = xmlDocGetRootElement(doc);
 
131
        /* set some defaults */
 
132
        rect->stroke_width = 0;
 
133
 
 
134
        walk_tree(root_element, rect);
 
135
        xmlFreeDoc(doc);
 
136
        xmlCleanupParser();
 
137
}
 
138
 
 
139
void CTheme::walk_tree(xmlNode * a_node, TThemeTxt *text) {
 
140
        xmlNode *cur_node = NULL;
 
141
        xmlAttr *attr = NULL;
 
142
        char *string;
 
143
        for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
 
144
           if (cur_node->type == XML_ELEMENT_NODE) { 
 
145
                        if (cur_node->properties != NULL) {
 
146
                                attr = cur_node->properties;
 
147
                                while (attr != NULL) {
 
148
                                   if (!strcasecmp((char *) cur_node->name, "text")) {
 
149
                                                if (!strcasecmp((char *) attr->name, "x")) {
 
150
                                                        string = (char *) xmlGetProp(cur_node, attr->name);
 
151
                                                        sscanf(string,"%lf",&(text->x));
 
152
                                                        xmlFree(string);
 
153
                                                } else if (!strcasecmp((char *) attr->name, "y")) {
 
154
                                                        string = (char *) xmlGetProp(cur_node, attr->name);
 
155
                                                        sscanf(string,"%lf",&(text->y));
 
156
                                                        xmlFree(string);
 
157
                                                } else if (!strcasecmp((char *) attr->name, "transform")) {
 
158
                                                        double x_trans, y_trans;
 
159
                                                        char tmp_string[10], *p; 
 
160
                                                        tmp_string[0] = '\0';
 
161
                                                        string = (char *) xmlGetProp(cur_node, attr->name);
 
162
                                                        if (!strncasecmp(string, "translate(", 10)) {
 
163
                                                                string += 10;
 
164
                                                                p = strchr(string, ',');
 
165
                                                                strncat(tmp_string, string, p - string);
 
166
                                                                sscanf(tmp_string, "%lf", &x_trans);
 
167
                                                                string = p + 1;
 
168
                                                                p = strchr(string, ')');
 
169
                                                                tmp_string[0] = '\0';
 
170
                                                                strncat(tmp_string, string, p - string);
 
171
                                                                sscanf(tmp_string, "%lf", &y_trans);
 
172
                                                                text->x += x_trans;
 
173
                                                                text->y += y_trans;
 
174
                                                        }
 
175
                                                        xmlFree(string);
 
176
                                                } else if (!strcasecmp((char *) attr->name, "style")) {
 
177
                                                   char * orig = (char *) xmlGetProp(cur_node, attr->name);
 
178
                                                   string = strtok(orig, ";");
 
179
                                                   while (string != NULL) {
 
180
                                                                if (!strncasecmp(string, "font-size:", 10)) {
 
181
                                                                        sscanf((string + 10),"%lf", &(text->fontsize));
 
182
                                                                } else if (!strncasecmp(string, "font-family:", 12)) {
 
183
                                                                        text->fontfamily = string + 12;
 
184
                                                                } else if (!strncasecmp(string, "font-style:", 11)) {
 
185
                                                                        if (!strncasecmp((string + 11), "normal", 6)) {
 
186
                                                                                text->fontstyle = CAIRO_FONT_SLANT_NORMAL;
 
187
                                                                        } else if (!strncasecmp((string + 11), "italic", 6)) {
 
188
                                                                                text->fontstyle = CAIRO_FONT_SLANT_ITALIC;
 
189
                                                                        } else if (!strncasecmp((string + 11), "oblique", 7)) {
 
190
                                                                                text->fontstyle = CAIRO_FONT_SLANT_OBLIQUE;
 
191
                                                                        }
 
192
                                                                } else if (!strncasecmp(string, "font-weight:", 12)) {
 
193
                                                                        if (!strncasecmp((string + 12), "normal", 6)) {
 
194
                                                                                text->fontweight = CAIRO_FONT_WEIGHT_NORMAL;
 
195
                                                                        } else if (!strncasecmp((string + 12), "bold", 4)) {
 
196
                                                                                text->fontweight = CAIRO_FONT_WEIGHT_BOLD;
 
197
                                                                        }
 
198
                                                                } else if (!strncasecmp(string, "fill:", 5)) {
 
199
                                                                        getcolor((string + 5), &(text->fill_col));
 
200
                                                                } else if (!strncasecmp(string, "fill-opacity:", 13)) {
 
201
                                                                        sscanf((string + 13), "%lf", &(text->fill_col.a));
 
202
                                                                } else if (!strncasecmp(string, "stroke:", 7)) {
 
203
                                                                        getcolor((string + 7), &(text->stroke_col));
 
204
                                                                } else if (!strncasecmp(string, "stroke-opacity:", 15)) {
 
205
                                                                        sscanf((string + 15), "%lf", &(text->stroke_col.a));
 
206
                                                                } else if (!strncasecmp(string, "stroke-width:", 13)) {
 
207
                                                                        sscanf((string + 13),"%lf", &(text->stroke_width));
 
208
                                                                }
 
209
                                                                string = strtok(NULL, ";");
 
210
                                                   }
 
211
                                                   xmlFree(orig);
 
212
 
 
213
                                                }
 
214
 
 
215
                                        } else if (!strcasecmp((char *) cur_node->name, "svg")) {
 
216
                                                if (!strcasecmp((char *) attr->name, "width")) {
 
217
                                                        string = (char *) xmlGetProp(cur_node, attr->name);
 
218
                                                        sscanf(string,"%lf",&(text->svg_width));
 
219
                                                        xmlFree(string);
 
220
                                                } else if (!strcasecmp((char *) attr->name, "height")) {
 
221
                                                        string = (char *) xmlGetProp(cur_node, attr->name);
 
222
                                                        sscanf(string,"%lf",&(text->svg_height));
 
223
                                                        xmlFree(string);
 
224
                                                } 
 
225
                                        }
 
226
                                        attr = attr->next;
 
227
                                }
 
228
                        }
 
229
                }
 
230
                walk_tree(cur_node->children, text);
 
231
        }
 
232
}
 
233
 
 
234
void CTheme::walk_tree(xmlNode * a_node, TThemeRect *rect) {
 
235
        xmlNode *cur_node = NULL;
 
236
        xmlAttr *attr = NULL;
 
237
        char *string;
 
238
        for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
 
239
           if (cur_node->type == XML_ELEMENT_NODE) { 
 
240
                        if (cur_node->properties != NULL) {
 
241
                                attr = cur_node->properties;
 
242
                                while (attr != NULL) {
 
243
                                        if (!strcasecmp((char *) cur_node->name, "rect")) {
 
244
                                                if (!strcasecmp((char *) attr->name, "x")) {
 
245
                                                        string = (char *) xmlGetProp(cur_node, attr->name);
 
246
                                                        sscanf(string,"%lf",&(rect->x));
 
247
                                                        xmlFree(string);
 
248
                                                } else if (!strcasecmp((char *) attr->name, "y")) {
 
249
                                                        string = (char *) xmlGetProp(cur_node, attr->name);
 
250
                                                        sscanf(string,"%lf",&(rect->y));
 
251
                                                        xmlFree(string);
 
252
                                                } else if (!strcasecmp((char *) attr->name, "width")) {
 
253
                                                        string = (char *) xmlGetProp(cur_node, attr->name);
 
254
                                                        sscanf(string,"%lf",&(rect->final_width));
 
255
                                                        xmlFree(string);
 
256
                                                        rect->width = rect->final_width;
 
257
                                                } else if (!strcasecmp((char *) attr->name, "height")) {
 
258
                                                        string = (char *) xmlGetProp(cur_node, attr->name);
 
259
                                                        sscanf(string,"%lf",&(rect->final_height));
 
260
                                                        xmlFree(string);
 
261
                                                        rect->height = rect->final_height;
 
262
                                                } else if (!strcasecmp((char *) attr->name, "style")) {
 
263
                                                   string = (char *) xmlGetProp(cur_node, attr->name);
 
264
                                                   char * string_tmp = strtok(string, ";");
 
265
                                                   while (string_tmp != NULL) {
 
266
                                                                if (!strncasecmp(string_tmp, "fill:", 5)) {
 
267
                                                                        getcolor((string_tmp + 5), &(rect->fill_col));
 
268
                                                                } else if (!strncasecmp(string_tmp, "fill-opacity:", 13)) {
 
269
                                                                        sscanf((string_tmp + 13), "%lf", &(rect->fill_col.a));
 
270
                                                                } else if (!strncasecmp(string_tmp, "stroke:", 7)) {
 
271
                                                                        getcolor((string_tmp + 7), &(rect->stroke_col));
 
272
                                                                } else if (!strncasecmp(string_tmp, "stroke-opacity:", 15)) {
 
273
                                                                        sscanf((string_tmp + 15), "%lf", &(rect->stroke_col.a));
 
274
                                                                } else if (!strncasecmp(string_tmp, "stroke-width:", 13)) {
 
275
                                                                        sscanf((string_tmp + 13),"%lf", &(rect->stroke_width));
 
276
                                                                }
 
277
                                                                string_tmp = strtok(NULL, ";");
 
278
                                                   }
 
279
                                                   xmlFree(string);
 
280
 
 
281
                                                }
 
282
 
 
283
                                        } else if (!strcasecmp((char *) cur_node->name, "svg")) {
 
284
                                                if (!strcasecmp((char *) attr->name, "width")) {
 
285
                                                        string = (char *) xmlGetProp(cur_node, attr->name);
 
286
                                                        sscanf(string,"%lf",&(rect->svg_width));
 
287
                                                        xmlFree(string);
 
288
                                                } else if (!strcasecmp((char *) attr->name, "height")) {
 
289
                                                        string = (char *) xmlGetProp(cur_node, attr->name);
 
290
                                                        sscanf(string,"%lf",&(rect->svg_height));
 
291
                                                        xmlFree(string);
 
292
                                                } 
 
293
                                        }
 
294
                                        attr = attr->next;
 
295
                                }
 
296
                        }
 
297
                }
 
298
                walk_tree(cur_node->children, rect);
 
299
        }
 
300
}
 
301
 
266
302
void CTheme::getcolor(char *string, TRGBA *col) {
267
 
        unsigned int r,g,b;
268
 
        if (string[0] == '#') {
269
 
            if(strlen(string) == 7) {
270
 
                sscanf((string+1), "%02x %02x %02x", &r, &g, &b);
271
 
                col->r = (double) r / 255;
272
 
                col->g = (double) g / 255;
273
 
                col->b = (double) b / 255;
274
 
            }
275
 
        } else if(!strcasecmp(string, "red")) {
276
 
            col->r = 1;
277
 
            col->g = col->b = 0;
278
 
        } else if(!strcasecmp(string, "lime")) {
279
 
            col->g = 1;
280
 
            col->r = col->b = 0;
281
 
        } else if(!strcasecmp(string, "blue")) {
282
 
            col->b = 1;
283
 
            col->r = col->g = 0;
284
 
        } else if(!strcasecmp(string, "black")) {
285
 
            col->r = col->g = col->b = 0;
286
 
        } else if(!strcasecmp(string, "silver")) {
287
 
            col->r = col->g = col->b = 0.75;
288
 
        } else if(!strcasecmp(string, "gray")) {
289
 
            col->r = col->g = col->b = 0.5;
290
 
        } else if(!strcasecmp(string, "white")) {
291
 
            col->r = col->g = col->b = 1;
292
 
        } else if(!strcasecmp(string, "maroon")) {
293
 
            col->r = 0.5;
294
 
            col->g = col->b = 0;
295
 
        } else if(!strcasecmp(string, "purple")) {
296
 
            col->g = 0.5;
297
 
            col->r = col->b = 0.5;
298
 
        } else if(!strcasecmp(string, "fuchsia")) {
299
 
            col->g = 0.5;
300
 
            col->r = col->b = 1;
301
 
        } else if(!strcasecmp(string, "green")) {
302
 
            col->g = 0.5;
303
 
            col->r = col->b = 0;
304
 
        } else if(!strcasecmp(string, "olive")) {
305
 
            col->b = 0;
306
 
            col->r = col->g = 0.5;
307
 
        } else if(!strcasecmp(string, "yellow")) {
308
 
            col->b = 0;
309
 
            col->r = col->g = 1;
310
 
        } else if(!strcasecmp(string, "navy")) {
311
 
            col->b = 0.5;
312
 
            col->r = col->g = 0;
313
 
        } else if(!strcasecmp(string, "teal")) {
314
 
            col->r = 0;
315
 
            col->g = col->b = 0.5;
316
 
        } else if(!strcasecmp(string, "aqua")) {
317
 
            col->r = 0;
318
 
            col->g = col->b = 1;
319
 
        } else if(!strcasecmp((string), "none")) {
320
 
            col->r = col->g = col->b = -1;
321
 
        }
322
 
    
 
303
                unsigned int r,g,b;
 
304
                if (string[0] == '#') {
 
305
                        if (strlen(string) == 7) {
 
306
                                sscanf((string+1), "%02x %02x %02x", &r, &g, &b);
 
307
                                col->r = (double) r / 255;
 
308
                                col->g = (double) g / 255;
 
309
                                col->b = (double) b / 255;
 
310
                        }
 
311
                } else if (!strcasecmp(string, "red")) {
 
312
                        col->r = 1;
 
313
                        col->g = col->b = 0;
 
314
                } else if (!strcasecmp(string, "lime")) {
 
315
                        col->g = 1;
 
316
                        col->r = col->b = 0;
 
317
                } else if (!strcasecmp(string, "blue")) {
 
318
                        col->b = 1;
 
319
                        col->r = col->g = 0;
 
320
                } else if (!strcasecmp(string, "black")) {
 
321
                        col->r = col->g = col->b = 0;
 
322
                } else if (!strcasecmp(string, "silver")) {
 
323
                        col->r = col->g = col->b = 0.75;
 
324
                } else if (!strcasecmp(string, "gray")) {
 
325
                        col->r = col->g = col->b = 0.5;
 
326
                } else if (!strcasecmp(string, "white")) {
 
327
                        col->r = col->g = col->b = 1;
 
328
                } else if (!strcasecmp(string, "maroon")) {
 
329
                        col->r = 0.5;
 
330
                        col->g = col->b = 0;
 
331
                } else if (!strcasecmp(string, "purple")) {
 
332
                        col->g = 0.5;
 
333
                        col->r = col->b = 0.5;
 
334
                } else if (!strcasecmp(string, "fuchsia")) {
 
335
                        col->g = 0.5;
 
336
                        col->r = col->b = 1;
 
337
                } else if (!strcasecmp(string, "green")) {
 
338
                        col->g = 0.5;
 
339
                        col->r = col->b = 0;
 
340
                } else if (!strcasecmp(string, "olive")) {
 
341
                        col->b = 0;
 
342
                        col->r = col->g = 0.5;
 
343
                } else if (!strcasecmp(string, "yellow")) {
 
344
                        col->b = 0;
 
345
                        col->r = col->g = 1;
 
346
                } else if (!strcasecmp(string, "navy")) {
 
347
                        col->b = 0.5;
 
348
                        col->r = col->g = 0;
 
349
                } else if (!strcasecmp(string, "teal")) {
 
350
                        col->r = 0;
 
351
                        col->g = col->b = 0.5;
 
352
                } else if (!strcasecmp(string, "aqua")) {
 
353
                        col->r = 0;
 
354
                        col->g = col->b = 1;
 
355
                } else if (!strcasecmp((string), "none")) {
 
356
                        col->r = col->g = col->b = -1;
 
357
                }
 
358
        
323
359
}
 
360
 
324
361
CTheme::~CTheme() {
325
 
        if(this->dc) {
326
 
            cairo_destroy(dc);
327
 
        }
328
 
        if(this->surface) {
329
 
            cairo_surface_destroy(surface);
330
 
        }
331
 
}
332
 
CThemeSongs::CThemeSongs() {
333
 
        char * theme_path = new char[1024];
334
 
        CScreenManager * sm = CScreenManager::getSingletonPtr();
335
 
 
336
 
        sm->getThemePathFile(theme_path,"songs_bg.svg");
337
 
        bg = new CairoSVG(theme_path, sm->getWidth(), sm->getHeight());
338
 
 
339
 
        theme = new CTheme(sm->getWidth(), sm->getHeight());
340
 
        sm->getThemePathFile(theme_path,"songs_song.svg");
341
 
        theme->ParseSVGForText(theme_path, &song);
342
 
        sm->getThemePathFile(theme_path,"songs_order.svg");
343
 
        theme->ParseSVGForText(theme_path, &order);
344
 
        
345
 
        delete[] theme_path;
346
 
}
 
362
        if (dc) cairo_destroy(dc);
 
363
        if (surface) cairo_surface_destroy(surface);
 
364
}
 
365
 
 
366
CThemeSongs::CThemeSongs(unsigned int width, unsigned int height) {
 
367
        CScreenManager* sm = CScreenManager::getSingletonPtr();
 
368
        bg = new CairoSVG(sm->getThemePathFile("songs_bg.svg"), width, height);
 
369
        theme = new CTheme(width, height);
 
370
        theme->ParseSVGForText(sm->getThemePathFile("songs_song.svg"), &song);
 
371
        theme->ParseSVGForText(sm->getThemePathFile("songs_order.svg"), &order);
 
372
}
 
373
 
347
374
CThemeSongs::~CThemeSongs() {
348
375
        delete bg;
349
376
        delete theme;
350
377
}
351
 
CThemePractice::CThemePractice() {
352
 
        char * theme_path = new char[1024];
 
378
 
 
379
CThemePractice::CThemePractice(unsigned int width, unsigned int height) {
353
380
        CScreenManager * sm = CScreenManager::getSingletonPtr();
354
 
 
355
 
        sm->getThemePathFile(theme_path,"practice_bg.svg");
356
 
        bg = new CairoSVG(theme_path, sm->getWidth(), sm->getHeight());
357
 
 
358
 
        theme = new CTheme(sm->getWidth(), sm->getHeight());
359
 
        sm->getThemePathFile(theme_path,"practice_txt.svg");
360
 
        theme->ParseSVGForText(theme_path, &notetxt);
361
 
        
362
 
        delete[] theme_path;
 
381
        bg = new CairoSVG(sm->getThemePathFile("practice_bg.svg"), width, height);
 
382
        theme = new CTheme(width, height);
 
383
        theme->ParseSVGForText(sm->getThemePathFile("practice_txt.svg"), &notetxt);
 
384
        theme->ParseSVGForRect(sm->getThemePathFile("practice_peak.svg"), &peak);
363
385
}
 
386
 
364
387
CThemePractice::~CThemePractice() {
365
388
        delete bg;
366
389
        delete theme;
367
390
}
368
 
CThemeSing::CThemeSing() {
369
 
        char * theme_path = new char[1024];
 
391
 
 
392
CThemeSing::CThemeSing(unsigned int width, unsigned int height) {
370
393
        CScreenManager * sm = CScreenManager::getSingletonPtr();
371
 
 
372
 
        sm->getThemePathFile(theme_path,"sing_bg.svg");
373
 
        bg = new CairoSVG(theme_path, sm->getWidth(), sm->getHeight());
374
 
        sm->getThemePathFile(theme_path,"sing_p1box.svg");
375
 
        p1box = new CairoSVG(theme_path, sm->getWidth(), sm->getHeight());
376
 
        theme = new CTheme(sm->getWidth(), sm->getHeight());
377
 
        sm->getThemePathFile(theme_path,"sing_timetxt.svg");
378
 
        theme->ParseSVGForText(theme_path, &timertxt);
379
 
        sm->getThemePathFile(theme_path,"sing_p1score.svg");
380
 
        theme->ParseSVGForText(theme_path, &p1score);
381
 
        sm->getThemePathFile(theme_path,"sing_lyricscurrent.svg");
382
 
        theme->ParseSVGForText(theme_path, &lyricspast);
383
 
        sm->getThemePathFile(theme_path,"sing_lyricscurrent.svg");
384
 
        theme->ParseSVGForText(theme_path, &lyricsfuture);
385
 
        sm->getThemePathFile(theme_path,"sing_lyricshighlight.svg");
386
 
        theme->ParseSVGForText(theme_path, &lyricshighlight);
387
 
        sm->getThemePathFile(theme_path,"sing_lyricsnext.svg");
388
 
        theme->ParseSVGForText(theme_path, &lyricsnextsentence);
389
 
        sm->getThemePathFile(theme_path,"sing_progressfg.svg");
390
 
        theme->ParseSVGForRect(theme_path, &progressfg);
391
 
        sm->getThemePathFile(theme_path,"sing_tostartfg.svg");
392
 
        theme->ParseSVGForRect(theme_path, &tostartfg);
393
 
 
394
 
        delete[] theme_path;
 
394
        bg = new CairoSVG(sm->getThemePathFile("sing_bg.svg"), width, height);  
 
395
        p1box = new CairoSVG(sm->getThemePathFile("sing_p1box.svg"), width, height);
 
396
        theme = new CTheme(width, height);
 
397
        theme->ParseSVGForText(sm->getThemePathFile("sing_timetxt.svg"), &timertxt);
 
398
        theme->ParseSVGForText(sm->getThemePathFile("sing_p1score.svg"), &p1score);
 
399
        theme->ParseSVGForText(sm->getThemePathFile("sing_lyricscurrent.svg"), &lyricspast);
 
400
        theme->ParseSVGForText(sm->getThemePathFile("sing_lyricscurrent.svg"), &lyricsfuture);
 
401
        theme->ParseSVGForText(sm->getThemePathFile("sing_lyricshighlight.svg"), &lyricshighlight);
 
402
        theme->ParseSVGForText(sm->getThemePathFile("sing_lyricsnext.svg"), &lyricsnextsentence);
 
403
        theme->ParseSVGForRect(sm->getThemePathFile("sing_progressfg.svg"), &progressfg);
 
404
        theme->ParseSVGForRect(sm->getThemePathFile("sing_tostartfg.svg"), &tostartfg);
395
405
}
 
406
 
396
407
CThemeSing::~CThemeSing() {
397
 
        delete bg;
398
 
        delete p1box;
399
 
        delete theme;
400
 
}
 
408
        delete bg;
 
409
        delete p1box;
 
410
        delete theme;
 
411
}
 
412
 
 
413
CThemeScore::CThemeScore(unsigned int width, unsigned int height) {
 
414
        CScreenManager * sm = CScreenManager::getSingletonPtr();
 
415
        bg = new CairoSVG(sm->getThemePathFile("score_bg.svg"), width, height);
 
416
        theme = new CTheme(width, height);
 
417
        theme->ParseSVGForText(sm->getThemePathFile("score_txt.svg"), &normal_score);
 
418
        theme->ParseSVGForText(sm->getThemePathFile("score_rank.svg"), &rank);
 
419
        theme->ParseSVGForRect(sm->getThemePathFile("score_level.svg"), &level);
 
420
}
 
421
 
 
422
CThemeScore::~CThemeScore() {
 
423
        delete bg;
 
424
        delete theme;
 
425
}
 
426
 
 
427
CThemeConfiguration::CThemeConfiguration(unsigned int width, unsigned int height) {
 
428
        CScreenManager * sm = CScreenManager::getSingletonPtr();
 
429
        bg = new CairoSVG(sm->getThemePathFile("configuration_bg.svg"), width, height);
 
430
        theme = new CTheme(width, height);
 
431
        theme->ParseSVGForText(sm->getThemePathFile("configuration_item.svg"), &item);
 
432
        theme->ParseSVGForText(sm->getThemePathFile("configuration_value.svg"), &value);
 
433
}
 
434
 
 
435
CThemeConfiguration::~CThemeConfiguration() {
 
436
        delete bg;
 
437
        delete theme;
 
438
}
 
439