annotate Gui/win32/widgetrender.c @ 21500:e7e7f397f991

Fix memleaks caused by missing vorbis/theora_info/comment_clear calls. Code still seems wrong to me for multiple audio tracks, since there is only one vorbis comment/info entry for the demuxer, not one per track?
author reimar
date Wed, 06 Dec 2006 10:46:50 +0000
parents e701a6eed5cb
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18914
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
1 /*
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
2 MPlayer Gui for win32
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
3 Copyright (c) 2003 Sascha Sommer <saschasommer@freenet.de>
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
4 Copyright (c) 2006 Erik Augustson <erik_27can@yahoo.com>
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
5 Copyright (c) 2006 Gianluigi Tiesi <sherpya@netfarm.it>
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
6
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
7 This program is free software; you can redistribute it and/or modify
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
8 it under the terms of the GNU General Public License as published by
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
9 the Free Software Foundation; either version 2 of the License, or
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
10 (at your option) any later version.
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
11
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
12 This program is distributed in the hope that it will be useful,
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
15 GNU General Public License for more details.
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
16
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
18 along with this program; if not, write to the Free Software
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
20 */
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
21
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
22 #include <stdio.h>
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
23 #include <ctype.h>
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
24 #include <windows.h>
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
25 #include <interface.h>
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
26 #include "gui.h"
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
27
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
28 extern char *codecname;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
29 #define MAX_LABELSIZE 250
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
30
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
31 static void render(int bitsperpixel, image *dst, image *src, int x, int y, int sx, int sy, int sw, int sh, int transparent)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
32 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
33 int i;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
34 int bpp = bitsperpixel / 8;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
35 int offset = (dst->width * bpp * y) + (x * bpp);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
36 int soffset = (src->width * bpp * sy) + (sx * bpp);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
37
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
38 for(i=0; i<sh; i++)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
39 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
40 int c;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
41 for(c=0; c < (sw * bpp); c += bpp)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
42 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
43 if(bpp == 2)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
44 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
45 if(!transparent || (((src->data + soffset + (i * src->width * bpp) + c)[0] != 0x1f)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
46 && ((src->data + soffset + (i * src->width * bpp) + c)[1] != 0x7c)))
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
47 memcpy(dst->data + offset + c, src->data + soffset + (i * src->width * bpp) + c, bpp);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
48 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
49 else if(bpp > 2)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
50 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
51 if(!transparent || *((unsigned int *) (src->data + soffset + (i * src->width * bpp) + c)) != 0x00ff00ff)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
52 memcpy(dst->data + offset + c, src->data + soffset + (i * src->width * bpp) + c, bpp);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
53 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
54 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
55 offset += (dst->width * bpp);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
56 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
57 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
58
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
59 static image *find_background(skin_t *skin, widget *item)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
60 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
61 unsigned int i;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
62 for (i=0; i < skin->windowcount; i++)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
63 if(skin->windows[i]->type == item->window)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
64 return skin->windows[i]->base->bitmap[0];
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
65 return NULL;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
66 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
67
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
68 /******************************************************************/
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
69 /* FONT related functions */
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
70 /******************************************************************/
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
71
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
72 /* returns the pos of s2 inside s1 or -1 if s1 doesn't contain s2 */
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
73 static int strpos(char *s1, const char* s2)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
74 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
75 unsigned int i, x;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
76 for (i=0; i < strlen(s1); i++)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
77 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
78 if(s1[i] == s2[0])
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
79 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
80 if(strlen(s1 + i) >= strlen(s2))
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
81 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
82 for (x=0; x <strlen(s2); x++)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
83 if(s1[i + x] != s2[x]) break;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
84 if(x == strlen(s2)) return i;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
85 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
86 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
87 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
88 return -1;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
89 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
90
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
91 /* replaces all occurences of what in dest with format */
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
92 static void stringreplace(char *dest, const char *what, const char *format, ... )
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
93 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
94 char tmp[MAX_LABELSIZE];
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
95 int offset=0;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
96 va_list va;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
97 va_start(va, format);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
98 vsnprintf(tmp, MAX_LABELSIZE, format, va);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
99 va_end(va);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
100 /* no search string == replace the entire string */
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
101 if(!what)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
102 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
103 memcpy(dest, tmp, strlen(tmp));
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
104 dest[strlen(tmp)] = 0;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
105 return;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
106 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
107 while((offset = strpos(dest, what)) != -1)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
108 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
109 memmove(dest + offset + strlen(tmp), dest + offset + strlen(what), strlen(dest + offset + strlen(what)) + 1);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
110 memcpy(dest + offset, tmp, strlen(tmp));
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
111 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
112 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
113
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
114 /* replaces the chars with special meaning with the associated data from the player info struct */
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
115 static char *generatetextfromlabel(widget *item)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
116 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
117 char *text = malloc(MAX_LABELSIZE);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
118 char tmp[MAX_LABELSIZE];
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
119 unsigned int i;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
120 if(!item)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
121 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
122 free(text);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
123 return NULL;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
124 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
125 strcpy(text, item->label);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
126 if(item->type == tySlabel) return text;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
127 stringreplace(text, "$1", "%.2i:%.2i:%.2i", guiIntfStruct.TimeSec / 3600,
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
128 (guiIntfStruct.TimeSec / 60) % 60, guiIntfStruct.TimeSec % 60);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
129 stringreplace(text, "$2", "%.4i:%.2i", guiIntfStruct.TimeSec / 60, guiIntfStruct.TimeSec % 60);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
130 stringreplace(text, "$3", "%.2i", guiIntfStruct.TimeSec / 3600);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
131 stringreplace(text, "$4", "%.2i", (guiIntfStruct.TimeSec / 60) % 60);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
132 stringreplace(text, "$5", "%.2i", guiIntfStruct.TimeSec % 60);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
133 stringreplace(text, "$6", "%.2i:%.2i:%.2i", guiIntfStruct.LengthInSec / 3600,
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
134 (guiIntfStruct.LengthInSec / 60) % 60, guiIntfStruct.LengthInSec % 60);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
135 stringreplace(text, "$7", "%.4i:%.2i", guiIntfStruct.LengthInSec / 60, guiIntfStruct.LengthInSec % 60);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
136 stringreplace(text, "$8", "%i:%.2i:%.2i", guiIntfStruct.TimeSec / 3600,
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
137 (guiIntfStruct.TimeSec / 60) % 60, guiIntfStruct.TimeSec % 60);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
138 stringreplace(text, "$v", "%3.2f", guiIntfStruct.Volume);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
139 stringreplace(text, "$V", "%3.1f", guiIntfStruct.Volume);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
140 stringreplace(text, "$b", "%3.2f", guiIntfStruct.Balance);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
141 stringreplace(text, "$B", "%3.1f", guiIntfStruct.Balance);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
142 stringreplace(text, "$t", "%.2i", guiIntfStruct.Track);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
143 stringreplace(text, "$o", "%s", guiIntfStruct.Filename);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
144 stringreplace(text, "$x", "%i", guiIntfStruct.MovieWidth);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
145 stringreplace(text, "$y", "%i", guiIntfStruct.MovieHeight);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
146 stringreplace(text, "$C", "%s", guiIntfStruct.sh_video ? codecname : "");
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
147 stringreplace(text, "$$", "$");
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
148
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
149 if(!strcmp(text, "$p") || !strcmp(text, "$s") || !strcmp(text, "$e"))
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
150 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
151 if(guiIntfStruct.Playing == 0) stringreplace(text, NULL, "s");
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
152 else if(guiIntfStruct.Playing == 1) stringreplace(text, NULL, "p");
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
153 else if(guiIntfStruct.Playing == 2) stringreplace(text, NULL, "e");
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
154 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
155
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
156 if(guiIntfStruct.AudioType == 0) stringreplace(text, "$a", "n");
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
157 else if(guiIntfStruct.AudioType == 1) stringreplace(text, "$a", "m");
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
158 else stringreplace(text, "$a", "t");
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
159
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
160 if(guiIntfStruct.StreamType == 0)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
161 stringreplace(text, "$T", "f");
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
162 #ifdef USE_DVDREAD
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
163 else if(guiIntfStruct.StreamType == STREAMTYPE_DVD || guiIntfStruct.StreamType == STREAMTYPE_DVDNAV)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
164 stringreplace(text, "$T", "d");
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
165 #endif
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
166 else stringreplace(text, "$T", "u");
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
167
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
168 if(guiIntfStruct.Filename)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
169 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
170 for (i=0; i<strlen(guiIntfStruct.Filename); i++)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
171 tmp[i] = tolower(guiIntfStruct.Filename[i]);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
172 stringreplace(text, "$f", tmp);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
173
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
174 for (i=0; i<strlen(guiIntfStruct.Filename); i++)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
175 tmp[i] = toupper(guiIntfStruct.Filename[i]);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
176 stringreplace(text, "$F", tmp);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
177 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
178
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
179 return text;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
180 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
181
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
182 /* cuts text to buflen scrolling from right to left */
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
183 static void scrolltext(char *text, unsigned int buflen, float *value)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
184 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
185 char *buffer = (char *) malloc(buflen + 1);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
186 unsigned int x,i;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
187 if(*value < buflen) x = 0;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
188 else x = *value - buflen;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
189 memset(buffer, ' ', buflen);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
190 for (i = (*value>=buflen) ? 0 : buflen - *value; i<buflen; i++)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
191 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
192 if(x < strlen(text))
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
193 buffer[i] = text[x];
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
194 x++;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
195 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
196 buffer[buflen] = 0;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
197 *value += 1.0f;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
198 if(*value >= strlen(text) + buflen) *value = 0.0f;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
199 strcpy(text, buffer);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
200 free(buffer);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
201 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
202
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
203 /* updates all dlabels and slabels */
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
204 void renderinfobox(skin_t *skin, window_priv_t *priv)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
205 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
206 unsigned int i;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
207 if (!priv) return;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
208
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
209 /* repaint the area behind the text*/
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
210 /* we have to do this for all labels here, because they may overlap in buggy skins ;( */
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
211
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
212 for (i=0; i<skin->widgetcount; i++)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
213 if((skin->widgets[i]->type == tyDlabel) || (skin->widgets[i]->type == tySlabel))
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
214 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
215 if(skin->widgets[i]->window == priv->type)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
216 render(skin->desktopbpp,
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
217 &priv->img,
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
218 find_background(skin, skin->widgets[i]),
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
219 skin->widgets[i]->x,
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
220 skin->widgets[i]->y,
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
221 skin->widgets[i]->x,
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
222 skin->widgets[i]->y,
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
223 skin->widgets[i]->length,
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
224 skin->widgets[i]->font->chars[0]->height,
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
225 1);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
226 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
227
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
228 /* load all slabels and dlabels */
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
229 for (i=0; i<skin->widgetcount; i++)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
230 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
231 widget *item = skin->widgets[i];
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
232 if(item->window != priv->type) continue;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
233 if((i == skin->widgetcount) || (item->type == tyDlabel) || (item->type == tySlabel))
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
234 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
235 char *text = generatetextfromlabel(item);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
236 unsigned int current, c;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
237 int offset = 0;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
238 unsigned int textlen;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
239 if(!text) continue;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
240 textlen = strlen(text);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
241
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
242 /* render(win, win->background, gui->skin->widgets[i]->x, gui->skin->widgets[i]->y,
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
243 gui->skin->widgets[i]->x, gui->skin->widgets[i]->y,
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
244 gui->skin->widgets[i]->length, gui->skin->widgets[i]->font->chars[0]->height,1); */
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
245
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
246 /* calculate text size */
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
247 for (current=0; current<textlen; current++)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
248 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
249 for (c=0; c<item->font->charcount; c++)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
250 if(item->font->chars[c]->c == text[current])
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
251 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
252 offset += item->font->chars[c]->width;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
253 break;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
254 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
255 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
256
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
257 /* labels can be scrolled if they are to big */
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
258 if((item->type == tyDlabel) && (item->length < offset))
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
259 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
260 int tomuch = (offset - item->length) / (offset /textlen);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
261 scrolltext(text, textlen - tomuch - 1, &skin->widgets[i]->value);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
262 textlen = strlen(text);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
263 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
264
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
265 /* align the text */
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
266 if(item->align == 1)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
267 offset = (item->length-offset) / 2;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
268 else if(item->align == 2)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
269 offset = item->length-offset;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
270 else
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
271 offset = 0;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
272
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
273 if(offset < 0) offset = 0;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
274
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
275 /* render the text */
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
276 for (current=0; current<textlen; current++)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
277 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
278 for (c=0; c<item->font->charcount; c++)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
279 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
280 char_t *cchar = item->font->chars[c];
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
281 if(cchar->c == *(text + current))
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
282 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
283 render(skin->desktopbpp,
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
284 &priv->img,
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
285 item->font->image,
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
286 item->x + offset,
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
287 item->y,
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
288 cchar->x,
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
289 cchar->y,
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
290 (cchar->width + offset > item->length) ? item->length - offset : cchar->width,
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
291 cchar->height,
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
292 1);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
293 offset += cchar->width;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
294 break;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
295 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
296 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
297 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
298 free(text);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
299 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
300 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
301 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
302
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
303 /******************************************************************/
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
304 /* WIDGET related functions */
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
305 /******************************************************************/
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
306
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
307 void renderwidget(skin_t *skin, image *dest, widget *item, int state)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
308 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
309 image *img = NULL;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
310 int height;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
311 int y;
19718
e701a6eed5cb ISO C90 warnings fixes
vayne
parents: 18914
diff changeset
312
e701a6eed5cb ISO C90 warnings fixes
vayne
parents: 18914
diff changeset
313 if(!dest) return;
18914
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
314 if((item->type == tyButton) || (item->type == tyHpotmeter) || (item->type == tyPotmeter))
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
315 img = item->bitmap[0];
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
316
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
317 if(!img) return;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
318
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
319 y = item->y;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
320 if(item->type == tyPotmeter)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
321 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
322 height = img->height / item->phases;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
323 y = height * (int)(item->value * item->phases / 100);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
324 if(y > img->height-height)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
325 y = img->height - height;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
326 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
327 else
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
328 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
329 height = img->height / 3;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
330 y = state * height;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
331 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
332
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
333 /* redraw background */
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
334 if(item->type == tyButton)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
335 render(skin->desktopbpp, dest, find_background(skin,item), item->x, item->y, item->x, item->y, img->width, height, 1);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
336
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
337 if((item->type == tyHpotmeter) || (item->type == tyPotmeter))
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
338 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
339 /* repaint the area behind the slider */
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
340 render(skin->desktopbpp, dest, find_background(skin, item), item->wx, item->wy, item->wx, item->wy, item->wwidth, item->height, 1);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
341 item->x = item->value * (item->wwidth-item->width) / 100 + item->wx;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
342 if((item->x + item->width) > (item->wx + item->wwidth))
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
343 item->x = item->wx + item->wwidth - item->width;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
344 if(item->x < item->wx)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
345 item->x = item->wx;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
346 /* workaround for blue */
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
347 if(item->type == tyHpotmeter)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
348 height = (item->height < img->height / 3) ? item->height : img->height / 3;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
349 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
350 render(skin->desktopbpp, dest, img, item->x, item->y, 0, y, img->width, height, 1);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
351 }