Mercurial > mplayer.hg
annotate gui/ui/render.c @ 37014:01b3cd8a1e76
Simplify string termination.
author | ib |
---|---|
date | Sat, 29 Mar 2014 14:21:45 +0000 |
parents | 11d2d0444f42 |
children | 68066d733c76 |
rev | line source |
---|---|
26458 | 1 /* |
2 * This file is part of MPlayer. | |
3 * | |
4 * MPlayer is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; either version 2 of the License, or | |
7 * (at your option) any later version. | |
8 * | |
9 * MPlayer is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU General Public License along | |
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
17 */ | |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
18 |
33123
9566100d88a1
Replace inttypes.h by stdint.h and remove inttypes.h where unneeded.
ib
parents:
32982
diff
changeset
|
19 #include <stdint.h> |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
20 #include <stdio.h> |
32963 | 21 #include <stdlib.h> |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
22 #include <string.h> |
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
23 |
33556 | 24 #include "render.h" |
32952 | 25 #include "gui/interface.h" |
37007 | 26 #include "gui/app/gui.h" |
26365
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
25603
diff
changeset
|
27 #include "gui/skin/font.h" |
34175 | 28 #include "gui/util/string.h" |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
29 |
36984
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
30 #include "access_mpcontext.h" |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
31 #include "help_mp.h" |
32963 | 32 #include "libavutil/avstring.h" |
32954 | 33 #include "osdep/timer.h" |
32963 | 34 #include "stream/stream.h" |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
35 |
33269 | 36 #define DLABEL_DELAY 2500 // in milliseconds |
37 | |
36980 | 38 /** |
36984
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
39 * @brief Convert #guiInfo member Filename. |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
40 * |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
41 * @param how 0 (cut file path and extension), |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
42 * 1 (additionally, convert lower case) or |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
43 * 2 (additionally, convert upper case) |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
44 * @param fname pointer to a buffer to receive the converted Filename |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
45 * @param maxlen size of @a fname buffer |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
46 * |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
47 * @return pointer to @a fname buffer |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
48 */ |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
49 static char *TranslateFilename(int how, char *fname, size_t maxlen) |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
50 { |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
51 char *p; |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
52 size_t len; |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
53 stream_t *stream; |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
54 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
55 switch (guiInfo.StreamType) { |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
56 case STREAMTYPE_FILE: |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
57 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
58 if (guiInfo.Filename && *guiInfo.Filename) { |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
59 p = strrchr(guiInfo.Filename, '/'); |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
60 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
61 if (p) |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
62 av_strlcpy(fname, p + 1, maxlen); |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
63 else |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
64 av_strlcpy(fname, guiInfo.Filename, maxlen); |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
65 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
66 len = strlen(fname); |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
67 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
68 if (len > 3 && fname[len - 3] == '.') |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
69 fname[len - 3] = 0; |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
70 else if (len > 4 && fname[len - 4] == '.') |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
71 fname[len - 4] = 0; |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
72 else if (len > 5 && fname[len - 5] == '.') |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
73 fname[len - 5] = 0; |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
74 } else |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
75 av_strlcpy(fname, MSGTR_GUI_MSG_NoFileLoaded, maxlen); |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
76 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
77 break; |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
78 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
79 case STREAMTYPE_STREAM: |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
80 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
81 av_strlcpy(fname, guiInfo.Filename, maxlen); |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
82 break; |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
83 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
84 case STREAMTYPE_CDDA: |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
85 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
86 snprintf(fname, maxlen, MSGTR_GUI_TitleN, guiInfo.Track); |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
87 break; |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
88 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
89 case STREAMTYPE_VCD: |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
90 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
91 snprintf(fname, maxlen, MSGTR_GUI_TitleN, guiInfo.Track - 1); |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
92 break; |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
93 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
94 case STREAMTYPE_DVD: |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
95 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
96 if (guiInfo.Chapter) |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
97 snprintf(fname, maxlen, MSGTR_GUI_ChapterN, guiInfo.Chapter); |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
98 else |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
99 av_strlcpy(fname, MSGTR_GUI_NoChapter, maxlen); |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
100 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
101 break; |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
102 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
103 case STREAMTYPE_TV: |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
104 case STREAMTYPE_DVB: |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
105 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
106 p = MSGTR_GUI_NoChannelName; |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
107 stream = mpctx_get_stream(guiInfo.mpcontext); |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
108 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
109 if (stream) |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
110 stream_control(stream, STREAM_CTRL_GET_CURRENT_CHANNEL, &p); |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
111 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
112 av_strlcpy(fname, p, maxlen); |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
113 break; |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
114 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
115 default: |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
116 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
117 av_strlcpy(fname, MSGTR_GUI_MSG_NoMediaOpened, maxlen); |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
118 break; |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
119 } |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
120 |
36988 | 121 if (how == 1) |
122 strlower(fname); | |
123 if (how == 2) | |
124 strupper(fname); | |
36984
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
125 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
126 return fname; |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
127 } |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
128 |
3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
ib
parents:
36980
diff
changeset
|
129 /** |
36980 | 130 * @brief Translate all variables in the @a text. |
131 * | |
132 * @param text text containing variables | |
133 * | |
134 * @return new text with all variables translated | |
135 */ | |
36974 | 136 static char *TranslateVariables(const char *text) |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
137 { |
36974 | 138 static char translation[512]; |
139 char trans[512]; | |
32972 | 140 unsigned int i, c; |
32963 | 141 int t; |
142 | |
36974 | 143 *translation = 0; |
32963 | 144 |
36974 | 145 for (c = 0, i = 0; i < strlen(text); i++) { |
146 if (text[i] != '$') { | |
147 if (c + 1 < sizeof(translation)) { | |
148 translation[c++] = text[i]; | |
149 translation[c] = 0; | |
32972 | 150 } |
32963 | 151 } else { |
36974 | 152 switch (text[++i]) { |
32963 | 153 case '1': |
33897 | 154 t = guiInfo.ElapsedTime; |
36979 | 155 HH_MM_SS: snprintf(trans, sizeof(trans), "%02d:%02d:%02d", t / 3600, t / 60 % 60, t % 60); |
36974 | 156 av_strlcat(translation, trans, sizeof(translation)); |
32963 | 157 break; |
158 | |
159 case '2': | |
33897 | 160 t = guiInfo.ElapsedTime; |
36979 | 161 MMMM_SS: snprintf(trans, sizeof(trans), "%04d:%02d", t / 60, t % 60); |
36974 | 162 av_strlcat(translation, trans, sizeof(translation)); |
32963 | 163 break; |
164 | |
165 case '3': | |
36974 | 166 snprintf(trans, sizeof(trans), "%02d", guiInfo.ElapsedTime / 3600); |
167 av_strlcat(translation, trans, sizeof(translation)); | |
32963 | 168 break; |
169 | |
170 case '4': | |
36978 | 171 snprintf(trans, sizeof(trans), "%02d", guiInfo.ElapsedTime / 60 % 60); |
36974 | 172 av_strlcat(translation, trans, sizeof(translation)); |
32963 | 173 break; |
174 | |
175 case '5': | |
36974 | 176 snprintf(trans, sizeof(trans), "%02d", guiInfo.ElapsedTime % 60); |
177 av_strlcat(translation, trans, sizeof(translation)); | |
32963 | 178 break; |
179 | |
36977 | 180 case '6': |
181 t = guiInfo.RunningTime; | |
36979 | 182 goto HH_MM_SS; |
36977 | 183 |
184 case '7': | |
185 t = guiInfo.RunningTime; | |
36979 | 186 goto MMMM_SS; |
36977 | 187 |
32963 | 188 case '8': |
36974 | 189 snprintf(trans, sizeof(trans), "%01d:%02d:%02d", guiInfo.ElapsedTime / 3600, (guiInfo.ElapsedTime / 60) % 60, guiInfo.ElapsedTime % 60); |
190 av_strlcat(translation, trans, sizeof(translation)); | |
32963 | 191 break; |
192 | |
193 case 'a': | |
33646 | 194 switch (guiInfo.AudioChannels) { |
32963 | 195 case 0: |
36974 | 196 av_strlcat(translation, "n", sizeof(translation)); |
32963 | 197 break; |
198 | |
199 case 1: | |
36974 | 200 av_strlcat(translation, "m", sizeof(translation)); |
32963 | 201 break; |
202 | |
203 case 2: | |
36978 | 204 av_strlcat(translation, guiInfo.AudioPassthrough ? "r" : "t", sizeof(translation)); |
32963 | 205 break; |
36910
11932adad7a2
Add symbol character 'r' for dynamic label variable $a.
ib
parents:
36909
diff
changeset
|
206 |
11932adad7a2
Add symbol character 'r' for dynamic label variable $a.
ib
parents:
36909
diff
changeset
|
207 default: |
36974 | 208 av_strlcat(translation, "r", sizeof(translation)); |
36910
11932adad7a2
Add symbol character 'r' for dynamic label variable $a.
ib
parents:
36909
diff
changeset
|
209 break; |
32963 | 210 } |
211 break; | |
212 | |
36977 | 213 case 'b': |
214 snprintf(trans, sizeof(trans), "%3.2f%%", guiInfo.Balance); | |
215 av_strlcat(translation, trans, sizeof(translation)); | |
216 break; | |
217 | |
218 case 'B': | |
219 snprintf(trans, sizeof(trans), "%3.1f", guiInfo.Balance); | |
220 av_strlcat(translation, trans, sizeof(translation)); | |
221 break; | |
222 | |
223 case 'C': | |
224 snprintf(trans, sizeof(trans), "%s", guiInfo.CodecName ? guiInfo.CodecName : ""); | |
225 av_strlcat(translation, trans, sizeof(translation)); | |
226 break; | |
227 | |
228 case 'D': | |
229 snprintf(trans, sizeof(trans), "%3.0f", guiInfo.Balance); | |
230 av_strlcat(translation, trans, sizeof(translation)); | |
231 break; | |
232 | |
233 case 'e': | |
234 if (guiInfo.Playing == GUI_PAUSE) | |
235 av_strlcat(translation, "e", sizeof(translation)); | |
236 break; | |
237 | |
238 case 'f': | |
239 TranslateFilename(1, trans, sizeof(trans)); | |
240 av_strlcat(translation, trans, sizeof(translation)); | |
241 break; | |
242 | |
243 case 'F': | |
244 TranslateFilename(2, trans, sizeof(trans)); | |
245 av_strlcat(translation, trans, sizeof(translation)); | |
246 break; | |
247 | |
248 case 'o': | |
249 TranslateFilename(0, trans, sizeof(trans)); | |
250 av_strlcat(translation, trans, sizeof(translation)); | |
251 break; | |
252 | |
253 case 'l': // legacy | |
254 case 'p': | |
255 if (guiInfo.Playing == GUI_PLAY) | |
256 av_strlcat(translation, "p", sizeof(translation)); | |
257 break; | |
258 | |
259 case 'P': | |
260 switch (guiInfo.Playing) { | |
261 case GUI_STOP: | |
262 av_strlcat(translation, "s", sizeof(translation)); | |
263 break; | |
264 | |
265 case GUI_PLAY: | |
266 av_strlcat(translation, "p", sizeof(translation)); | |
267 break; | |
268 | |
269 case GUI_PAUSE: | |
270 av_strlcat(translation, "e", sizeof(translation)); | |
271 break; | |
272 } | |
273 break; | |
274 | |
275 case 's': | |
276 if (guiInfo.Playing == GUI_STOP) | |
277 av_strlcat(translation, "s", sizeof(translation)); | |
278 break; | |
279 | |
280 case 't': | |
281 snprintf(trans, sizeof(trans), "%02d", guiInfo.Track); | |
282 av_strlcat(translation, trans, sizeof(translation)); | |
283 break; | |
284 | |
32963 | 285 case 'T': |
33555 | 286 switch (guiInfo.StreamType) { |
32963 | 287 case STREAMTYPE_FILE: |
36974 | 288 av_strlcat(translation, "f", sizeof(translation)); |
32963 | 289 break; |
290 | |
34077 | 291 case STREAMTYPE_STREAM: |
36974 | 292 av_strlcat(translation, "u", sizeof(translation)); |
34077 | 293 break; |
294 | |
34387 | 295 case STREAMTYPE_CDDA: |
36974 | 296 av_strlcat(translation, "a", sizeof(translation)); |
34387 | 297 break; |
298 | |
32963 | 299 case STREAMTYPE_VCD: |
36974 | 300 av_strlcat(translation, "v", sizeof(translation)); |
32963 | 301 break; |
302 | |
303 case STREAMTYPE_DVD: | |
36974 | 304 av_strlcat(translation, "d", sizeof(translation)); |
32963 | 305 break; |
306 | |
36429 | 307 case STREAMTYPE_TV: |
308 case STREAMTYPE_DVB: | |
36974 | 309 av_strlcat(translation, "b", sizeof(translation)); |
36429 | 310 break; |
311 | |
32963 | 312 default: |
36974 | 313 av_strlcat(translation, " ", sizeof(translation)); |
32963 | 314 break; |
315 } | |
316 break; | |
317 | |
36977 | 318 case 'U': |
319 snprintf(trans, sizeof(trans), "%3.0f", guiInfo.Volume); | |
320 av_strlcat(translation, trans, sizeof(translation)); | |
321 break; | |
322 | |
323 case 'v': | |
324 snprintf(trans, sizeof(trans), "%3.2f%%", guiInfo.Volume); | |
325 av_strlcat(translation, trans, sizeof(translation)); | |
326 break; | |
327 | |
328 case 'V': | |
329 snprintf(trans, sizeof(trans), "%3.1f", guiInfo.Volume); | |
330 av_strlcat(translation, trans, sizeof(translation)); | |
331 break; | |
332 | |
333 case 'x': | |
334 snprintf(trans, sizeof(trans), "%d", guiInfo.VideoWidth); | |
335 av_strlcat(translation, trans, sizeof(translation)); | |
336 break; | |
337 | |
338 case 'y': | |
339 snprintf(trans, sizeof(trans), "%d", guiInfo.VideoHeight); | |
340 av_strlcat(translation, trans, sizeof(translation)); | |
341 break; | |
342 | |
32963 | 343 case '$': |
36974 | 344 av_strlcat(translation, "$", sizeof(translation)); |
32963 | 345 break; |
346 | |
347 default: | |
348 continue; | |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
349 } |
32963 | 350 |
36974 | 351 c = strlen(translation); |
32963 | 352 } |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
353 } |
32963 | 354 |
36974 | 355 return translation; |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
356 } |
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
357 |
37007 | 358 static void PutImage(int x, int y, uint32_t *drawbuf, int drawbuf_width, guiImage *img, int parts, int index, int below) |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
359 { |
37009 | 360 register int i, ic, yc; |
37007 | 361 register uint32_t pixel; |
362 int xlimit, ylimit, ix, iy; | |
37005 | 363 uint32_t *pixels; |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
364 |
37010 | 365 if (!img || !img->Image) |
32963 | 366 return; |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
367 |
37007 | 368 if (below) { |
369 i = img->Width * (img->Height / parts) * index; | |
370 xlimit = x + img->Width; | |
371 ylimit = y + img->Height / parts; | |
372 } else { | |
373 i = (img->Width / parts) * index; | |
374 xlimit = x + img->Width / parts; | |
375 ylimit = y + img->Height; | |
376 } | |
377 | |
37006 | 378 pixels = (uint32_t *)img->Image; |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
379 |
36993 | 380 yc = y * drawbuf_width; |
32963 | 381 |
37007 | 382 for (iy = y; iy < ylimit; iy++) { |
383 ic = i; | |
384 | |
385 for (ix = x; ix < xlimit; ix++) { | |
36993 | 386 pixel = pixels[i++]; |
32963 | 387 |
36993 | 388 if (!IS_TRANSPARENT(pixel)) |
389 drawbuf[yc + ix] = pixel; | |
32963 | 390 } |
391 | |
37007 | 392 if (!below) |
37009 | 393 i = ic + img->Width; |
37007 | 394 |
36993 | 395 yc += drawbuf_width; |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
396 } |
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
397 } |
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
398 |
37011 | 399 void RenderAll(wsWindow *window, guiItem *items, int till, char *drawbuf) |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
400 { |
37005 | 401 uint32_t *db; |
35688 | 402 guiItem *item; |
33555 | 403 guiImage *image = NULL; |
37012 | 404 int dw, i, index, x; |
405 char *t; | |
406 unsigned int d; | |
32963 | 407 |
37005 | 408 db = (uint32_t *)drawbuf; |
409 dw = window->Width; | |
32963 | 410 |
37011 | 411 for (i = 0; i <= till; i++) { |
36994 | 412 item = &items[i]; |
32966
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
413 |
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
414 switch (item->pressed) { |
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
415 case btnPressed: |
36994 | 416 index = 0; |
32966
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
417 break; |
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
418 |
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
419 case btnReleased: |
36994 | 420 index = 1; |
32966
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
421 break; |
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
422 |
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
423 default: |
36994 | 424 index = 2; |
32966
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
425 break; |
1f51f39916e1
Replace ternary operator by more intelligible switch statement.
ib
parents:
32965
diff
changeset
|
426 } |
32963 | 427 |
428 switch (item->type) { | |
429 case itButton: | |
35541 | 430 |
37007 | 431 PutImage(item->x, item->y, db, dw, &item->Bitmap, 3, index, True); |
32963 | 432 break; |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
433 |
36920 | 434 case itPimage: |
35541 | 435 |
37008 | 436 PutImage(item->x, item->y, db, dw, &item->Bitmap, item->numphases, (item->numphases - 1) * item->value / 100.0, True); |
32963 | 437 break; |
438 | |
439 case itHPotmeter: | |
35541 | 440 |
37008 | 441 PutImage(item->x, item->y, db, dw, &item->Bitmap, item->numphases, (item->numphases - 1) * item->value / 100.0, True); |
442 PutImage(item->x + (item->width - item->pwidth) * item->value / 100.0, item->y, db, dw, &item->Mask, 3, index, True); | |
32963 | 443 break; |
444 | |
445 case itVPotmeter: | |
35541 | 446 |
37008 | 447 PutImage(item->x, item->y, db, dw, &item->Bitmap, item->numphases, (item->numphases - 1) * item->value / 100.0, False); |
37007 | 448 PutImage(item->x, item->y + (item->height - item->pheight) * (1.0 - item->value / 100.0), db, dw, &item->Mask, 3, index, True); |
32963 | 449 break; |
450 | |
451 case itSLabel: | |
35541 | 452 |
32969 | 453 if (item->width == -1) |
454 item->width = fntTextWidth(item->fontid, item->label); | |
35541 | 455 |
33971 | 456 image = fntTextRender(item, 0, item->label); |
35541 | 457 |
32963 | 458 if (image) |
37007 | 459 PutImage(item->x, item->y, db, dw, image, 1, 0, True); |
35541 | 460 |
32969 | 461 break; |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
462 |
32963 | 463 case itDLabel: |
37013 | 464 |
37012 | 465 t = TranslateVariables(item->label); |
32963 | 466 |
467 if (!item->text || (strcmp(item->text, t) != 0)) { | |
468 free(item->text); | |
469 item->text = strdup(t); | |
470 item->textwidth = fntTextWidth(item->fontid, t); | |
471 item->starttime = GetTimerMS(); | |
472 item->last_x = 0; | |
32761
3ceeb62a1125
Improve the readability of dynamic labels which scroll.
ib
parents:
32759
diff
changeset
|
473 } |
32963 | 474 |
475 d = GetTimerMS() - item->starttime; | |
476 | |
32964 | 477 if (d < DLABEL_DELAY) |
37013 | 478 x = item->last_x; // don't scroll yet |
32963 | 479 else { |
480 int l; | |
481 char c[2]; | |
482 | |
483 l = (item->textwidth ? item->textwidth : item->width); | |
35362 | 484 x = (l ? l - ((d - DLABEL_DELAY) / 20) % l - 1 : 0); |
32963 | 485 c[0] = *item->text; |
37014 | 486 c[1] = 0; |
32963 | 487 |
488 if (x < (fntTextWidth(item->fontid, c) + 1) >> 1) { | |
37013 | 489 item->starttime = GetTimerMS(); // stop again |
490 item->last_x = x; // at current x pos | |
32963 | 491 } |
32761
3ceeb62a1125
Improve the readability of dynamic labels which scroll.
ib
parents:
32759
diff
changeset
|
492 } |
32963 | 493 |
33971 | 494 image = fntTextRender(item, x, t); |
32963 | 495 |
496 if (image) | |
37007 | 497 PutImage(item->x, item->y, db, dw, image, 1, 0, True); |
32963 | 498 |
499 break; | |
500 } | |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
501 } |
32963 | 502 |
36994 | 503 wsImageRender(window, drawbuf); |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
diff
changeset
|
504 } |