source: titan/titan/style.h @ 40399

Last change on this file since 40399 was 23286, checked in by nit, 11 years ago

[titan] cleanup

File size: 10.4 KB
Line 
1#ifndef STYLE_H
2#define STYLE_H
3
4struct style* addstyle(char* line, struct style* last)
5{
6        char *ret = NULL;
7        struct style *newnode = NULL, *prev = NULL, *node = NULL;
8        int memfd = -1, length;
9        int fontsizeadjust = getskinconfigint("fontsizeadjust", NULL);
10
11        newnode = (struct style*)calloc(1, sizeof(struct style));
12        if(newnode == NULL)
13        {
14                err("no memory");
15                return NULL;
16        }
17
18        newnode->bgcol = -1;
19        newnode->titlebgcol = -1;
20        newnode->deaktivcol = -1;
21
22        if(line != NULL)
23        {
24                ret = getxmlentry(line, " name=");
25                if(ret != NULL)
26                        newnode->name = ret;
27                else
28                        newnode->name = ostrcat("unknown", NULL, 0, 0);
29                ret = getxmlentry(line, " posx=");
30                if(ret != NULL)
31                {
32                        newnode->posx = convertxmlentry(ret, &newnode->prozposx);
33                        free(ret);
34                }
35                ret = getxmlentry(line, " posy=");
36                if(ret != NULL)
37                {
38                        newnode->posy = convertxmlentry(ret, &newnode->prozposy);
39                        free(ret);
40                }
41                ret = getxmlentry(line, " width=");
42                if(ret != NULL)
43                {
44                        newnode->width = convertxmlentry(ret, &newnode->prozwidth);
45                        free(ret);
46                }
47                ret = getxmlentry(line, " height=");
48                if(ret != NULL)
49                {
50                        newnode->height = convertxmlentry(ret, &newnode->prozheight);
51                        free(ret);
52                }
53                ret = getxmlentry(line, " picwidth=");
54                if(ret != NULL)
55                {
56                        newnode->picwidth = convertxmlentry(ret, &newnode->picprozwidth);
57                        free(ret);
58                }
59                ret = getxmlentry(line, " picheight=");
60                if(ret != NULL)
61                {
62                        newnode->picheight = convertxmlentry(ret, &newnode->picprozheight);
63                        free(ret);
64                }
65                ret = getxmlentry(line, " picquality=");
66                if(ret != NULL)
67                {
68                        newnode->picquality = atoi(ret);
69                        free(ret);
70                }
71                ret = getxmlentry(line, " textposx=");
72                if(ret != NULL)
73                {
74                        newnode->textposx = atoi(ret);
75                        free(ret);
76                }
77                ret = getxmlentry(line, " textposx2=");
78                if(ret != NULL)
79                {
80                        newnode->textposx2 = atoi(ret);
81                        free(ret);
82                }
83                ret = getxmlentry(line, " halign=");
84                if(ret != NULL)
85                {
86                        newnode->halign = convertxmlentry(ret, NULL);
87                        free(ret);
88                }
89                ret = getxmlentry(line, " valign=");
90                if(ret != NULL)
91                {
92                        newnode->valign = convertxmlentry(ret, NULL);
93                        free(ret);
94                }
95                ret = getxmlentry(line, " hidden=");
96                if(ret != NULL)
97                {
98                        newnode->hidden = convertxmlentry(ret, NULL);
99                        free(ret);
100                }
101                ret = getxmlentry(line, " wrap=");
102                if(ret != NULL)
103                {
104                        newnode->wrap = convertxmlentry(ret, NULL);
105                        free(ret);
106                }
107                ret = getxmlentry(line, " hspace=");
108                if(ret != NULL)
109                {
110                        newnode->hspace = abs(atoi(ret));
111                        free(ret);
112                }
113                ret = getxmlentry(line, " vspace=");
114                if(ret != NULL)
115                {
116                        newnode->vspace = abs(atoi(ret));
117                        free(ret);
118                }
119                ret = getxmlentry(line, " bgspace=");
120                if(ret != NULL)
121                {
122                        newnode->bgspace = atoi(ret);
123                        free(ret);
124                }
125                ret = getxmlentry(line, " zorder=");
126                if(ret != NULL)
127                {
128                        newnode->zorder = atoi(ret);
129                        free(ret);
130                }
131                ret = getxmlentry(line, " scrollbar=");
132                if(ret != NULL)
133                {
134                        newnode->scrollbar = convertxmlentry(ret, NULL);
135                        free(ret);
136                }
137                ret = getxmlentry(line, " bordersize=");
138                if(ret != NULL)
139                {
140                        newnode->bordersize = atoi(ret);
141                        free(ret);
142                }
143                ret = getxmlentry(line, " bordertype=");
144                if(ret != NULL)
145                {
146                        newnode->bordertype = atoi(ret);
147                        free(ret);
148                }
149                ret = getxmlentry(line, " bordercol=");
150                if(ret != NULL)
151                {
152                        newnode->bordercol = convertcol(ret);
153                        free(ret);
154                }
155                ret = getxmlentry(line, " deaktivcol=");
156                if(ret != NULL)
157                {
158                        newnode->deaktivcol = convertcol(ret);
159                        free(ret);
160                }
161                ret = getxmlentry(line, " progresscol=");
162                if(ret != NULL)
163                {
164                        newnode->progresscol = convertcol(ret);
165                        free(ret);
166                }
167                ret = getxmlentry(line, " shadowsize=");
168                if(ret != NULL)
169                {
170                        newnode->shadowsize = atoi(ret);
171                        free(ret);
172                }
173                ret = getxmlentry(line, " shadowcol=");
174                if(ret != NULL)
175                {
176                        newnode->shadowcol = convertcol(ret);
177                        free(ret);
178                }
179                ret = getxmlentry(line, " shadowpos=");
180                if(ret != NULL)
181                {
182                        newnode->shadowpos = convertxmlentry(ret, NULL);
183                        free(ret);
184                }
185                ret = getxmlentry(line, " fontsize=");
186                if(ret != NULL)
187                {
188                        newnode->fontsize = atoi(ret);
189                        if(newnode->fontsize + fontsizeadjust >= 10)
190                                newnode->fontsize += fontsizeadjust;
191                        else if(newnode->fontsize >= 10)
192                                newnode->fontsize = 10;
193                        free(ret);
194                }
195                ret = getxmlentry(line, " fontsize2=");
196                if(ret != NULL)
197                {
198                        newnode->fontsize2 = atoi(ret);
199                        if(newnode->fontsize2 + fontsizeadjust >= 10)
200                                newnode->fontsize2 += fontsizeadjust;
201                        else if(newnode->fontsize2 >= 10)
202                                newnode->fontsize2 = 10;
203                        free(ret);
204                }
205                ret = getxmlentry(line, " fontcol=");
206                if(ret != NULL)
207                {
208                        newnode->fontcol = convertcol(ret);
209                        free(ret);
210                }
211                ret = getxmlentry(line, " fontcol2=");
212                if(ret != NULL)
213                {
214                        newnode->fontcol2 = convertcol(ret);
215                        free(ret);
216                }
217                ret = getxmlentry(line, " charspace=");
218                if(ret != NULL)
219                {
220                        newnode->charspace = atoi(ret);
221                        free(ret);
222                }
223                ret = getxmlentry(line, " borderradius=");
224                if(ret != NULL)
225                {
226                        newnode->borderradius = atoi(ret);
227                        free(ret);
228                }
229                ret = getxmlentry(line, " transparent=");
230                if(ret != NULL)
231                {
232                        newnode->transparent = atoi(ret);
233                        free(ret);
234                }
235                ret = getxmlentry(line, " font=");
236                if(ret != NULL)
237                        newnode->font = ret;
238                ret = getxmlentry(line, " titlealign=");
239                if(ret != NULL)
240                {
241                        newnode->titlealign = convertxmlentry(ret, NULL);
242                        free(ret);
243                }
244                ret = getxmlentry(line, " titlebgcol=");
245                if(ret != NULL)
246                {
247                        newnode->titlebgcol = convertcol(ret);
248                        free(ret);
249                }
250                ret = getxmlentry(line, " titlebgcol2=");
251                if(ret != NULL)
252                {
253                        newnode->titlebgcol2 = convertcol(ret);
254                        free(ret);
255                }
256                ret = getxmlentry(line, " bgcol=");
257                if(ret != NULL)
258                {
259                        newnode->bgcol = convertcol(ret);
260                        free(ret);
261                }
262                ret = getxmlentry(line, " bgcol2=");
263                if(ret != NULL)
264                {
265                        newnode->bgcol2 = convertcol(ret);
266                        free(ret);
267                }
268                ret = getxmlentry(line, " gradient=");
269                if(ret != NULL)
270                {
271                        newnode->gradient = convertxmlentry(ret, NULL);
272                        free(ret);
273                }
274                ret = getxmlentry(line, " titlegradient=");
275                if(ret != NULL)
276                {
277                        newnode->titlegradient = convertxmlentry(ret, NULL);
278                        free(ret);
279                }
280                ret = getxmlentry(line, " picmem=");
281                if(ret != NULL)
282                {
283                        unsigned long width = 0, height = 0, rowbytes = 0;
284                        int channels = 0;
285                        unsigned char* buf = NULL;
286
287                        newnode->picmem = 1;
288                        newnode->pic = changepicpath(ret);
289                        free(ret);
290
291                        if(getpic(newnode->pic) == NULL)
292                        {
293                                length = strlen(newnode->pic);
294                                if(newnode->pic[length - 1] == 'g' && newnode->pic[length - 2] == 'n' && newnode->pic[length - 3] == 'p')
295                                        buf = readpng(newnode->pic, &width, &height, &rowbytes, &channels, 0, 0, 0, 0, 0, 0);
296                                else if(getconfigint("pichwdecode", NULL) == 1)
297                                        readjpg(newnode->pic, &width, &height, &rowbytes, &channels, &buf, &memfd);
298                                else
299                                        buf = loadjpg(newnode->pic, &width, &height, &rowbytes, &channels, 1);
300                                addpic(newnode->pic, buf, memfd, width, height, rowbytes, channels, 0, 0, NULL);
301                        }
302                }
303                ret = getxmlentry(line, " pic=");
304                if(ret != NULL)
305                {
306                        newnode->pic = changepicpath(ret);
307                        free(ret);
308                }
309                ret = getxmlentry(line, " func=");
310                if(ret != NULL)
311                {
312                        newnode->skinfunc = convertfunc(ret, &newnode->funcrettype);
313                        free(ret);
314                }
315                ret = getxmlentry(line, " param1=");
316                if(ret != NULL)
317                        newnode->param1 = ret;
318                ret = getxmlentry(line, " param2=");
319                if(ret != NULL)
320                        newnode->param2 = ret;
321                ret = getxmlentry(line, " input=");
322                if(ret != NULL)
323                        newnode->input = ret;
324                ret = getxmlentry(line, " mask=");
325                if(ret != NULL)
326                        newnode->mask = ret;
327        }
328        else
329                newnode->name = ostrcat("unknown", NULL, 0, 0);
330               
331        if(last == NULL)
332        {
333                while(node != NULL)
334                {
335                        prev = node;
336                        node = node->next;
337                }
338        }
339        else
340        {
341                prev = last;
342                node = last->next;
343        }
344
345        if(prev == NULL)
346                style = newnode;
347        else
348                prev->next = newnode;
349        newnode->next = node;
350
351        return newnode;
352}
353
354void addstyletoscreennode(struct skin* node, struct style* snode)
355{
356        if(node == NULL || snode == NULL) return;
357
358        node->posx = snode->posx;
359        node->posy = snode->posy;
360        node->width = snode->width;
361        node->height = snode->height;
362        node->picwidth = snode->picwidth;
363        node->picheight = snode->picheight;
364        node->picquality = snode->picquality;
365        node->textposx = snode->textposx;
366        node->textposx2 = snode->textposx2;
367        node->halign = snode->halign;
368        node->valign = snode->valign;
369        node->hidden = snode->hidden;
370        node->wrap = snode->wrap;
371        node->hspace = snode->hspace;
372        node->vspace = snode->vspace;
373        node->bgspace = snode->bgspace;
374        node->zorder = snode->zorder;
375        node->scrollbar = snode->scrollbar;
376        node->bordersize = snode->bordersize;
377        node->bordertype = snode->bordertype;
378        node->bordercol = snode->bordercol;
379        node->deaktivcol = snode->deaktivcol;
380        node->progresscol = snode->progresscol;
381        node->shadowsize = snode->shadowsize;
382        node->shadowcol = snode->shadowcol;
383        node->shadowpos = snode->shadowpos;
384        node->fontsize = snode->fontsize;
385        node->fontsize2 = snode->fontsize2;
386        node->fontcol = snode->fontcol;
387        node->fontcol2 = snode->fontcol2;
388        node->charspace = snode->charspace;
389        node->borderradius = snode->borderradius;
390        node->transparent = snode->transparent;
391        node->titlealign = snode->titlealign;
392        node->titlebgcol = snode->titlebgcol;
393        node->titlebgcol2 = snode->titlebgcol2;
394        node->bgcol = snode->bgcol;
395        node->bgcol2 = snode->bgcol2;
396        node->gradient = snode->gradient;
397        node->titlegradient = snode->titlegradient;
398        node->skinfunc = snode->skinfunc;
399        node->prozposx = snode->prozposx;
400        node->prozposy = snode->prozposy;
401        node->prozwidth = snode->prozwidth;
402        node->prozheight = snode->prozheight;
403        node->picprozwidth = snode->picprozwidth;
404        node->picprozheight = snode->picprozheight;
405        node->funcrettype = snode->funcrettype;
406        node->picmem = snode->picmem;
407
408        changemask(node, snode->mask);
409
410        node->param1 = ostrcat(snode->param1, NULL, 0, 0);
411        node->param2 = ostrcat(snode->param2, NULL, 0, 0);
412        node->input = ostrcat(snode->input, NULL, 0, 0);
413        node->pic = ostrcat(snode->pic, NULL, 0, 0);
414        node->font = ostrcat(snode->font, NULL, 0, 0);
415}
416
417struct style* getstyle(char* name)
418{
419        struct style *node = style;
420
421        while(node != NULL)
422        {
423                if(ostrcmp(node->name, name) == 0)
424                        break;
425                node = node->next;
426        }
427       
428        return node;
429}
430
431void delstyle(struct style* snode)
432{
433        struct style *node = style, *prev = style;
434
435        while(node != NULL)
436        {
437                if(node == snode)
438                {
439                        if(node == style)
440                                style = node->next;
441                        else
442                                prev->next = node->next;
443
444                        free(node);
445                        node = NULL;
446                        break;
447                }
448
449                prev = node;
450                node = node->next;
451        }
452}
453
454void freestyle()
455{
456        struct style *node = style, *prev = style;
457
458        while(node != NULL)
459        {
460                prev = node;
461                node = node->next;
462                if(prev != NULL)
463                        delstyle(prev);
464        }
465}
466
467/*
468add code to skin.h
469add read to titan.c
470add free to titan.c
471*/
472
473#endif
Note: See TracBrowser for help on using the repository browser.