Mercurial > mplayer.hg
annotate gui/win32/widgetrender.c @ 37104:91b00a4407cd
demux_real: Improve buffer allocation for interleaved audio handling.
Allocate buffers where they are needed.
This avoids code duplication, allocating them when they are not
needed, and might avoid a crash if an audio stream is specified
via -aid that does not exist in the headers but does exist in the
file since then we might run the deinterleaving without having
the buffers allocated first (note: I have not tested this can
actually happen).
author | reimar |
---|---|
date | Tue, 13 May 2014 21:06:38 +0000 |
parents | b28b632efeef |
children |
rev | line source |
---|---|
23077 | 1 /* |
23079 | 2 * MPlayer GUI for Win32 |
3 * Copyright (C) 2003 Sascha Sommer <saschasommer@freenet.de> | |
4 * Copyright (C) 2006 Erik Augustson <erik_27can@yahoo.com> | |
5 * Copyright (C) 2006 Gianluigi Tiesi <sherpya@netfarm.it> | |
6 * | |
7 * This file is part of MPlayer. | |
8 * | |
9 * MPlayer is free software; you can redistribute it and/or modify | |
10 * it under the terms of the GNU General Public License as published by | |
11 * the Free Software Foundation; either version 2 of the License, or | |
12 * (at your option) any later version. | |
13 * | |
14 * MPlayer is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
26457 | 19 * You should have received a copy of the GNU General Public License along |
20 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
23079 | 22 */ |
23077 | 23 |
24 #include <stdio.h> | |
36984
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
25 #include <string.h> |
23077 | 26 #include <ctype.h> |
37053 | 27 #include <math.h> |
23077 | 28 #include <windows.h> |
23091
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
29 |
33564 | 30 #include "gui/util/bitmap.h" |
34175 | 31 #include "gui/util/string.h" |
26372
76413880bfad
Update include paths to account for build system changes.
diego
parents:
23091
diff
changeset
|
32 #include "gui/interface.h" |
23077 | 33 #include "gui.h" |
34 | |
36984
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
35 #include "access_mpcontext.h" |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
36 #include "help_mp.h" |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
37 #include "libavutil/avstring.h" |
37053 | 38 #include "libavutil/common.h" |
37018 | 39 #include "stream/stream.h" |
36984
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
40 |
23077 | 41 #define MAX_LABELSIZE 250 |
42 | |
43 static void render(int bitsperpixel, image *dst, image *src, int x, int y, int sx, int sy, int sw, int sh, int transparent) | |
44 { | |
45 int i; | |
46 int bpp = bitsperpixel / 8; | |
47 int offset = (dst->width * bpp * y) + (x * bpp); | |
48 int soffset = (src->width * bpp * sy) + (sx * bpp); | |
49 | |
50 for(i=0; i<sh; i++) | |
51 { | |
52 int c; | |
53 for(c=0; c < (sw * bpp); c += bpp) | |
54 { | |
55 if(bpp == 2) | |
56 { | |
57 if(!transparent || (((src->data + soffset + (i * src->width * bpp) + c)[0] != 0x1f) | |
58 && ((src->data + soffset + (i * src->width * bpp) + c)[1] != 0x7c))) | |
59 memcpy(dst->data + offset + c, src->data + soffset + (i * src->width * bpp) + c, bpp); | |
60 } | |
61 else if(bpp > 2) | |
62 { | |
33534 | 63 if(!transparent || !IS_TRANSPARENT(*((unsigned int *) (src->data + soffset + (i * src->width * bpp) + c)))) |
23077 | 64 memcpy(dst->data + offset + c, src->data + soffset + (i * src->width * bpp) + c, bpp); |
65 } | |
66 } | |
67 offset += (dst->width * bpp); | |
68 } | |
69 } | |
70 | |
71 static image *find_background(skin_t *skin, widget *item) | |
72 { | |
73 unsigned int i; | |
74 for (i=0; i < skin->windowcount; i++) | |
75 if(skin->windows[i]->type == item->window) | |
76 return skin->windows[i]->base->bitmap[0]; | |
77 return NULL; | |
78 } | |
79 | |
80 /******************************************************************/ | |
81 /* FONT related functions */ | |
82 /******************************************************************/ | |
83 | |
84 /* returns the pos of s2 inside s1 or -1 if s1 doesn't contain s2 */ | |
85 static int strpos(char *s1, const char* s2) | |
86 { | |
87 unsigned int i, x; | |
88 for (i=0; i < strlen(s1); i++) | |
89 { | |
90 if(s1[i] == s2[0]) | |
91 { | |
92 if(strlen(s1 + i) >= strlen(s2)) | |
93 { | |
94 for (x=0; x <strlen(s2); x++) | |
95 if(s1[i + x] != s2[x]) break; | |
96 if(x == strlen(s2)) return i; | |
97 } | |
98 } | |
99 } | |
100 return -1; | |
101 } | |
102 | |
103 /* replaces all occurences of what in dest with format */ | |
104 static void stringreplace(char *dest, const char *what, const char *format, ... ) | |
105 { | |
106 char tmp[MAX_LABELSIZE]; | |
107 int offset=0; | |
108 va_list va; | |
109 va_start(va, format); | |
110 vsnprintf(tmp, MAX_LABELSIZE, format, va); | |
111 va_end(va); | |
112 /* no search string == replace the entire string */ | |
113 if(!what) | |
114 { | |
115 memcpy(dest, tmp, strlen(tmp)); | |
116 dest[strlen(tmp)] = 0; | |
117 return; | |
118 } | |
119 while((offset = strpos(dest, what)) != -1) | |
120 { | |
121 memmove(dest + offset + strlen(tmp), dest + offset + strlen(what), strlen(dest + offset + strlen(what)) + 1); | |
122 memcpy(dest + offset, tmp, strlen(tmp)); | |
123 } | |
124 } | |
125 | |
36984
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
126 /** |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
127 * @brief Convert #guiInfo member Filename. |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
128 * |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
129 * @param how 0 (cut file path and extension), |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
130 * 1 (additionally, convert lower case) or |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
131 * 2 (additionally, convert upper case) |
37065 | 132 * @param fname memory location of a buffer to receive the converted Filename |
133 * @param maxlen size of the @a fname buffer | |
36984
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
134 * |
37065 | 135 * @return pointer to the @a fname buffer |
36984
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
136 */ |
37019 | 137 static char *TranslateFilename (int how, char *fname, size_t maxlen) |
36984
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
138 { |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
139 char *p; |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
140 size_t len; |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
141 stream_t *stream; |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
142 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
143 switch (guiInfo.StreamType) |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
144 { |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
145 case STREAMTYPE_FILE: |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
146 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
147 if (guiInfo.Filename && *guiInfo.Filename) |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
148 { |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
149 p = strrchr(guiInfo.Filename, '\\'); |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
150 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
151 if (p) av_strlcpy(fname, p + 1, maxlen); |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
152 else av_strlcpy(fname, guiInfo.Filename, maxlen); |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
153 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
154 len = strlen(fname); |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
155 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
156 if (len > 3 && fname[len - 3] == '.') fname[len - 3] = 0; |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
157 else if (len > 4 && fname[len - 4] == '.') fname[len - 4] = 0; |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
158 else if (len > 5 && fname[len - 5] == '.') fname[len - 5] = 0; |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
159 } |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
160 else av_strlcpy(fname, MSGTR_GUI_MSG_NoFileLoaded, maxlen); |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
161 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
162 break; |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
163 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
164 case STREAMTYPE_STREAM: |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
165 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
166 av_strlcpy(fname, guiInfo.Filename, maxlen); |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
167 break; |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
168 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
169 case STREAMTYPE_CDDA: |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
170 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
171 snprintf(fname, maxlen, MSGTR_GUI_TitleN, guiInfo.Track); |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
172 break; |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
173 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
174 case STREAMTYPE_VCD: |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
175 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
176 snprintf(fname, maxlen, MSGTR_GUI_TitleN, guiInfo.Track - 1); |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
177 break; |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
178 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
179 case STREAMTYPE_DVD: |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
180 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
181 if (guiInfo.Chapter) snprintf(fname, maxlen, MSGTR_GUI_ChapterN, guiInfo.Chapter); |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
182 else av_strlcpy(fname, MSGTR_GUI_NoChapter, maxlen); |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
183 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
184 break; |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
185 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
186 case STREAMTYPE_TV: |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
187 case STREAMTYPE_DVB: |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
188 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
189 p = MSGTR_GUI_NoChannelName; |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
190 stream = mpctx_get_stream(guiInfo.mpcontext); |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
191 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
192 if (stream) stream_control(stream, STREAM_CTRL_GET_CURRENT_CHANNEL, &p); |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
193 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
194 av_strlcpy(fname, p, maxlen); |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
195 break; |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
196 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
197 default: |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
198 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
199 av_strlcpy(fname, MSGTR_GUI_MSG_NoMediaOpened, maxlen); |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
200 break; |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
201 } |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
202 |
36988 | 203 if (how == 1) strlower(fname); |
204 if (how == 2) strupper(fname); | |
36984
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
205 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
206 return fname; |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
207 } |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36970
diff
changeset
|
208 |
23077 | 209 /* replaces the chars with special meaning with the associated data from the player info struct */ |
210 static char *generatetextfromlabel(widget *item) | |
211 { | |
212 char *text = malloc(MAX_LABELSIZE); | |
213 char tmp[MAX_LABELSIZE]; | |
214 if(!item) | |
215 { | |
216 free(text); | |
217 return NULL; | |
218 } | |
219 strcpy(text, item->label); | |
220 if(item->type == tySlabel) return text; | |
33897 | 221 stringreplace(text, "$1", "%.2i:%.2i:%.2i", guiInfo.ElapsedTime / 3600, |
222 (guiInfo.ElapsedTime / 60) % 60, guiInfo.ElapsedTime % 60); | |
223 stringreplace(text, "$2", "%.4i:%.2i", guiInfo.ElapsedTime / 60, guiInfo.ElapsedTime % 60); | |
224 stringreplace(text, "$3", "%.2i", guiInfo.ElapsedTime / 3600); | |
225 stringreplace(text, "$4", "%.2i", (guiInfo.ElapsedTime / 60) % 60); | |
226 stringreplace(text, "$5", "%.2i", guiInfo.ElapsedTime % 60); | |
227 stringreplace(text, "$6", "%.2i:%.2i:%.2i", guiInfo.RunningTime / 3600, | |
228 (guiInfo.RunningTime / 60) % 60, guiInfo.RunningTime % 60); | |
229 stringreplace(text, "$7", "%.4i:%.2i", guiInfo.RunningTime / 60, guiInfo.RunningTime % 60); | |
230 stringreplace(text, "$8", "%i:%.2i:%.2i", guiInfo.ElapsedTime / 3600, | |
231 (guiInfo.ElapsedTime / 60) % 60, guiInfo.ElapsedTime % 60); | |
36904
7c5b6a58fac6
Fix dynamic label variables $v and $b in the Win32 GUI.
ib
parents:
36899
diff
changeset
|
232 stringreplace(text, "$v", "%3.2f%%", guiInfo.Volume); |
33555 | 233 stringreplace(text, "$V", "%3.1f", guiInfo.Volume); |
36916 | 234 stringreplace(text, "$U", "%3.0f", guiInfo.Volume); |
36904
7c5b6a58fac6
Fix dynamic label variables $v and $b in the Win32 GUI.
ib
parents:
36899
diff
changeset
|
235 stringreplace(text, "$b", "%3.2f%%", guiInfo.Balance); |
33555 | 236 stringreplace(text, "$B", "%3.1f", guiInfo.Balance); |
36914 | 237 stringreplace(text, "$D", "%3.0f", guiInfo.Balance); |
33555 | 238 stringreplace(text, "$t", "%.2i", guiInfo.Track); |
34163 | 239 stringreplace(text, "$o", "%s", acp(TranslateFilename(0, tmp, sizeof(tmp)))); |
33901 | 240 stringreplace(text, "$x", "%i", guiInfo.VideoWidth); |
241 stringreplace(text, "$y", "%i", guiInfo.VideoHeight); | |
33555 | 242 stringreplace(text, "$C", "%s", guiInfo.sh_video ? codecname : ""); |
23077 | 243 stringreplace(text, "$$", "$"); |
244 | |
36918 | 245 if(guiInfo.Playing == GUI_STOP) |
246 { | |
247 stringreplace(text, "$P", "s"); | |
248 stringreplace(text, "$s", "s"); | |
249 } | |
250 else if(guiInfo.Playing == GUI_PLAY) | |
251 { | |
252 stringreplace(text, "$P", "p"); | |
253 stringreplace(text, "$p", "p"); | |
254 } | |
255 else if(guiInfo.Playing == GUI_PAUSE) | |
256 { | |
257 stringreplace(text, "$P", "e"); | |
258 stringreplace(text, "$e", "e"); | |
259 } | |
23077 | 260 |
33646 | 261 if(guiInfo.AudioChannels == 0) stringreplace(text, "$a", "n"); |
262 else if(guiInfo.AudioChannels == 1) stringreplace(text, "$a", "m"); | |
37018 | 263 else if(guiInfo.AudioChannels == 2) stringreplace(text, "$a", (guiInfo.AudioPassthrough ? "r" : "t")); |
36910
11932adad7a2
Add symbol character 'r' for dynamic label variable $a.
ib
parents:
36904
diff
changeset
|
264 else stringreplace(text, "$a", "r"); |
23077 | 265 |
36912
c20f0c6d19f1
Fix symbol character for dynamic label variable $T in Win32 GUI.
ib
parents:
36910
diff
changeset
|
266 if(guiInfo.StreamType == STREAMTYPE_FILE) |
23077 | 267 stringreplace(text, "$T", "f"); |
33555 | 268 else if(guiInfo.StreamType == STREAMTYPE_DVD || guiInfo.StreamType == STREAMTYPE_DVDNAV) |
23077 | 269 stringreplace(text, "$T", "d"); |
36912
c20f0c6d19f1
Fix symbol character for dynamic label variable $T in Win32 GUI.
ib
parents:
36910
diff
changeset
|
270 else if(guiInfo.StreamType == STREAMTYPE_STREAM) |
c20f0c6d19f1
Fix symbol character for dynamic label variable $T in Win32 GUI.
ib
parents:
36910
diff
changeset
|
271 stringreplace(text, "$T", "u"); |
c20f0c6d19f1
Fix symbol character for dynamic label variable $T in Win32 GUI.
ib
parents:
36910
diff
changeset
|
272 else stringreplace(text, "$T", " "); |
23077 | 273 |
34163 | 274 stringreplace(text, "$f", acp(TranslateFilename(1, tmp, sizeof(tmp)))); |
275 stringreplace(text, "$F", acp(TranslateFilename(2, tmp, sizeof(tmp)))); | |
23077 | 276 |
277 return text; | |
278 } | |
279 | |
280 /* cuts text to buflen scrolling from right to left */ | |
281 static void scrolltext(char *text, unsigned int buflen, float *value) | |
282 { | |
30702 | 283 char *buffer = malloc(buflen + 1); |
23077 | 284 unsigned int x,i; |
285 if(*value < buflen) x = 0; | |
286 else x = *value - buflen; | |
287 memset(buffer, ' ', buflen); | |
288 for (i = (*value>=buflen) ? 0 : buflen - *value; i<buflen; i++) | |
289 { | |
290 if(x < strlen(text)) | |
291 buffer[i] = text[x]; | |
292 x++; | |
293 } | |
294 buffer[buflen] = 0; | |
295 *value += 1.0f; | |
296 if(*value >= strlen(text) + buflen) *value = 0.0f; | |
297 strcpy(text, buffer); | |
298 free(buffer); | |
299 } | |
300 | |
301 /* updates all dlabels and slabels */ | |
302 void renderinfobox(skin_t *skin, window_priv_t *priv) | |
303 { | |
304 unsigned int i; | |
305 if (!priv) return; | |
306 | |
307 /* repaint the area behind the text*/ | |
308 /* we have to do this for all labels here, because they may overlap in buggy skins ;( */ | |
309 | |
310 for (i=0; i<skin->widgetcount; i++) | |
311 if((skin->widgets[i]->type == tyDlabel) || (skin->widgets[i]->type == tySlabel)) | |
312 { | |
313 if(skin->widgets[i]->window == priv->type) | |
314 render(skin->desktopbpp, | |
315 &priv->img, | |
316 find_background(skin, skin->widgets[i]), | |
317 skin->widgets[i]->x, | |
318 skin->widgets[i]->y, | |
319 skin->widgets[i]->x, | |
320 skin->widgets[i]->y, | |
321 skin->widgets[i]->length, | |
322 skin->widgets[i]->font->chars[0]->height, | |
323 1); | |
324 } | |
325 | |
326 /* load all slabels and dlabels */ | |
327 for (i=0; i<skin->widgetcount; i++) | |
328 { | |
329 widget *item = skin->widgets[i]; | |
330 if(item->window != priv->type) continue; | |
331 if((i == skin->widgetcount) || (item->type == tyDlabel) || (item->type == tySlabel)) | |
332 { | |
333 char *text = generatetextfromlabel(item); | |
334 unsigned int current, c; | |
335 int offset = 0; | |
336 unsigned int textlen; | |
337 if(!text) continue; | |
338 textlen = strlen(text); | |
339 | |
340 /* render(win, win->background, gui->skin->widgets[i]->x, gui->skin->widgets[i]->y, | |
341 gui->skin->widgets[i]->x, gui->skin->widgets[i]->y, | |
342 gui->skin->widgets[i]->length, gui->skin->widgets[i]->font->chars[0]->height,1); */ | |
343 | |
344 /* calculate text size */ | |
345 for (current=0; current<textlen; current++) | |
346 { | |
347 for (c=0; c<item->font->charcount; c++) | |
348 if(item->font->chars[c]->c == text[current]) | |
349 { | |
350 offset += item->font->chars[c]->width; | |
351 break; | |
352 } | |
353 } | |
354 | |
355 /* labels can be scrolled if they are to big */ | |
356 if((item->type == tyDlabel) && (item->length < offset)) | |
357 { | |
358 int tomuch = (offset - item->length) / (offset /textlen); | |
359 scrolltext(text, textlen - tomuch - 1, &skin->widgets[i]->value); | |
360 textlen = strlen(text); | |
361 } | |
362 | |
363 /* align the text */ | |
364 if(item->align == 1) | |
365 offset = (item->length-offset) / 2; | |
366 else if(item->align == 2) | |
367 offset = item->length-offset; | |
368 else | |
369 offset = 0; | |
370 | |
371 if(offset < 0) offset = 0; | |
372 | |
373 /* render the text */ | |
374 for (current=0; current<textlen; current++) | |
375 { | |
376 for (c=0; c<item->font->charcount; c++) | |
377 { | |
378 char_t *cchar = item->font->chars[c]; | |
379 if(cchar->c == *(text + current)) | |
380 { | |
381 render(skin->desktopbpp, | |
382 &priv->img, | |
383 item->font->image, | |
384 item->x + offset, | |
385 item->y, | |
386 cchar->x, | |
387 cchar->y, | |
388 (cchar->width + offset > item->length) ? item->length - offset : cchar->width, | |
389 cchar->height, | |
390 1); | |
391 offset += cchar->width; | |
392 break; | |
393 } | |
394 } | |
395 } | |
396 free(text); | |
397 } | |
398 } | |
399 } | |
400 | |
401 /******************************************************************/ | |
402 /* WIDGET related functions */ | |
403 /******************************************************************/ | |
404 | |
405 void renderwidget(skin_t *skin, image *dest, widget *item, int state) | |
406 { | |
407 image *img = NULL; | |
408 int height; | |
409 int y; | |
410 | |
411 if(!dest) return; | |
36920 | 412 if((item->type == tyButton) || (item->type == tyHpotmeter) || (item->type == tyVpotmeter) || (item->type == tyPimage)) |
23077 | 413 img = item->bitmap[0]; |
37053 | 414 if(item->type == tyRpotmeter) |
415 img = item->bitmap[1]; | |
23077 | 416 |
417 if(!img) return; | |
418 | |
419 y = item->y; | |
37053 | 420 if(item->type == tyPimage || /* legacy (potmeter) */ (item->type == tyHpotmeter && item->width == item->wwidth) || item->type == tyRpotmeter) |
23077 | 421 { |
422 height = img->height / item->phases; | |
423 y = height * (int)(item->value * item->phases / 100); | |
424 if(y > img->height-height) | |
425 y = img->height - height; | |
426 } | |
427 else | |
428 { | |
429 height = img->height / 3; | |
430 y = state * height; | |
431 } | |
432 | |
433 /* redraw background */ | |
434 if(item->type == tyButton) | |
435 render(skin->desktopbpp, dest, find_background(skin,item), item->x, item->y, item->x, item->y, img->width, height, 1); | |
436 | |
37053 | 437 if((item->type == tyHpotmeter) || (item->type == tyVpotmeter) || (item->type == tyRpotmeter) || (item->type == tyPimage)) |
23077 | 438 { |
36898 | 439 if(item->type == tyVpotmeter) |
440 { | |
441 /* repaint the area behind the slider */ | |
442 render(skin->desktopbpp, dest, find_background(skin, item), item->wx, item->wy, item->wx, item->wy, item->width, item->wheight, 1); | |
443 item->y = (100 - item->value) * (item->wheight-item->height) / 100 + item->wy; | |
444 } | |
37053 | 445 else if(item->type == tyRpotmeter) |
446 { | |
447 /* repaint the area behind the rpotmeter */ | |
448 render(skin->desktopbpp, dest, find_background(skin, item), item->wx, item->wy, item->wx, item->wy, item->wwidth, item->wheight, 1); | |
449 item->x = item->wx; | |
450 item->y = item->wy; | |
451 } | |
36898 | 452 else |
453 { | |
36899 | 454 /* repaint the area behind the slider */ |
455 render(skin->desktopbpp, dest, find_background(skin, item), item->wx, item->wy, item->wx, item->wy, item->wwidth, item->height, 1); | |
456 item->x = item->value * (item->wwidth-item->width) / 100 + item->wx; | |
36898 | 457 } |
23077 | 458 } |
459 render(skin->desktopbpp, dest, img, item->x, item->y, 0, y, img->width, height, 1); | |
37053 | 460 |
461 /* rpotmeter button */ | |
462 if(item->type == tyRpotmeter && item->bitmap[0] != item->bitmap[1]) | |
463 { | |
464 img = item->bitmap[0]; | |
465 | |
466 if(img) | |
467 { | |
468 double radius, radian; | |
469 int ix, iy; | |
470 | |
471 // keep the button inside the potmeter outline | |
472 radius = (FFMIN(item->wwidth, item->wheight) - item->maxwh) / 2.0; | |
473 | |
474 radian = item->value / 100.0 * item->arclength + item->zeropoint; | |
475 | |
476 // coordinates plus a correction for a non-square item | |
477 // (remember: both axes are mirrored, we have a clockwise radian) | |
478 ix = item->wx + radius * (1 + cos(radian)) + FFMAX(0, (item->wwidth - item->wheight) / 2.0) + 0.5; | |
479 iy = item->wy + radius * (1 + sin(radian)) + FFMAX(0, (item->wheight - item->wwidth) / 2.0) + 0.5; | |
480 | |
481 height = img->height / 3; | |
482 y = state * height; | |
483 | |
484 render(skin->desktopbpp, dest, img, ix, iy, 0, y, img->width, height, 1); | |
485 } | |
486 } | |
23077 | 487 } |