annotate gui/win32/widgetrender.c @ 34697:ac6b38cd0d45

Rename sub window video window. It was a bad idea to name the video window "sub window" at the time the GUI was written. The term "sub window" does make sense from the programmer's point of view, but it doesn't make any sense at all from the user's point of view, because the sub window simply is the window where the video will be displayed. Moreover, since the term "sub" is generally short for "subtitles", the renaming makes the code much easier to understand.
author ib
date Sat, 03 Mar 2012 16:45:15 +0000
parents 5a45efc630b8
children 5b01e1e9d9ef
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
1 /*
23079
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
2 * MPlayer GUI for Win32
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
3 * Copyright (C) 2003 Sascha Sommer <saschasommer@freenet.de>
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
4 * Copyright (C) 2006 Erik Augustson <erik_27can@yahoo.com>
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
5 * Copyright (C) 2006 Gianluigi Tiesi <sherpya@netfarm.it>
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
6 *
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
7 * This file is part of MPlayer.
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
8 *
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
9 * MPlayer is free software; you can redistribute it and/or modify
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
10 * it under the terms of the GNU General Public License as published by
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
12 * (at your option) any later version.
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
13 *
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
14 * MPlayer is distributed in the hope that it will be useful,
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
17 * GNU General Public License for more details.
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
18 *
26457
9ba6d4487292 Use standard GPL header.
diego
parents: 26372
diff changeset
19 * You should have received a copy of the GNU General Public License along
9ba6d4487292 Use standard GPL header.
diego
parents: 26372
diff changeset
20 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
9ba6d4487292 Use standard GPL header.
diego
parents: 26372
diff changeset
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23079
8e9b11648f40 Use proper GPL header.
diego
parents: 23078
diff changeset
22 */
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
23
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
24 #include <stdio.h>
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
25 #include <ctype.h>
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
26 #include <windows.h>
23091
52488bb09d90 Consistently use quotes instead of angled brackets in #include
diego
parents: 23079
diff changeset
27
33564
7dd27b046712 Fix compilation of w32 gui.
reimar
parents: 33555
diff changeset
28 #include "gui/util/bitmap.h"
34175
a345e7162d0a Move TranslateFilename() to util/string.c.
ib
parents: 34163
diff changeset
29 #include "gui/util/string.h"
26372
76413880bfad Update include paths to account for build system changes.
diego
parents: 23091
diff changeset
30 #include "gui/interface.h"
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
31 #include "gui.h"
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
32
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
33 #define MAX_LABELSIZE 250
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
34
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
35 static void render(int bitsperpixel, image *dst, image *src, int x, int y, int sx, int sy, int sw, int sh, int transparent)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
36 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
37 int i;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
38 int bpp = bitsperpixel / 8;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
39 int offset = (dst->width * bpp * y) + (x * bpp);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
40 int soffset = (src->width * bpp * sy) + (sx * bpp);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
41
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
42 for(i=0; i<sh; i++)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
43 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
44 int c;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
45 for(c=0; c < (sw * bpp); c += bpp)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
46 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
47 if(bpp == 2)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
48 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
49 if(!transparent || (((src->data + soffset + (i * src->width * bpp) + c)[0] != 0x1f)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
50 && ((src->data + soffset + (i * src->width * bpp) + c)[1] != 0x7c)))
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
51 memcpy(dst->data + offset + c, src->data + soffset + (i * src->width * bpp) + c, bpp);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
52 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
53 else if(bpp > 2)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
54 {
33534
22c3241467b3 Remove function Normalize().
ib
parents: 32067
diff changeset
55 if(!transparent || !IS_TRANSPARENT(*((unsigned int *) (src->data + soffset + (i * src->width * bpp) + c))))
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
56 memcpy(dst->data + offset + c, src->data + soffset + (i * src->width * bpp) + c, bpp);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
57 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
58 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
59 offset += (dst->width * bpp);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
60 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
61 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
62
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
63 static image *find_background(skin_t *skin, widget *item)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
64 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
65 unsigned int i;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
66 for (i=0; i < skin->windowcount; i++)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
67 if(skin->windows[i]->type == item->window)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
68 return skin->windows[i]->base->bitmap[0];
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
69 return NULL;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
70 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
71
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
72 /******************************************************************/
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
73 /* FONT related functions */
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
74 /******************************************************************/
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
75
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
76 /* returns the pos of s2 inside s1 or -1 if s1 doesn't contain s2 */
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
77 static int strpos(char *s1, const char* s2)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
78 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
79 unsigned int i, x;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
80 for (i=0; i < strlen(s1); i++)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
81 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
82 if(s1[i] == s2[0])
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
83 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
84 if(strlen(s1 + i) >= strlen(s2))
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
85 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
86 for (x=0; x <strlen(s2); x++)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
87 if(s1[i + x] != s2[x]) break;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
88 if(x == strlen(s2)) return i;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
89 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
90 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
91 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
92 return -1;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
93 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
94
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
95 /* replaces all occurences of what in dest with format */
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
96 static void stringreplace(char *dest, const char *what, const char *format, ... )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
97 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
98 char tmp[MAX_LABELSIZE];
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
99 int offset=0;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
100 va_list va;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
101 va_start(va, format);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
102 vsnprintf(tmp, MAX_LABELSIZE, format, va);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
103 va_end(va);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
104 /* no search string == replace the entire string */
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
105 if(!what)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
106 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
107 memcpy(dest, tmp, strlen(tmp));
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
108 dest[strlen(tmp)] = 0;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
109 return;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
110 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
111 while((offset = strpos(dest, what)) != -1)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
112 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
113 memmove(dest + offset + strlen(tmp), dest + offset + strlen(what), strlen(dest + offset + strlen(what)) + 1);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
114 memcpy(dest + offset, tmp, strlen(tmp));
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
115 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
116 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
117
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
118 /* replaces the chars with special meaning with the associated data from the player info struct */
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
119 static char *generatetextfromlabel(widget *item)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
120 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
121 char *text = malloc(MAX_LABELSIZE);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
122 char tmp[MAX_LABELSIZE];
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
123 unsigned int i;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
124 if(!item)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
125 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
126 free(text);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
127 return NULL;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
128 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
129 strcpy(text, item->label);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
130 if(item->type == tySlabel) return text;
33897
e0d211c62cf7 Cosmetic: Rename some guiInfo members.
ib
parents: 33646
diff changeset
131 stringreplace(text, "$1", "%.2i:%.2i:%.2i", guiInfo.ElapsedTime / 3600,
e0d211c62cf7 Cosmetic: Rename some guiInfo members.
ib
parents: 33646
diff changeset
132 (guiInfo.ElapsedTime / 60) % 60, guiInfo.ElapsedTime % 60);
e0d211c62cf7 Cosmetic: Rename some guiInfo members.
ib
parents: 33646
diff changeset
133 stringreplace(text, "$2", "%.4i:%.2i", guiInfo.ElapsedTime / 60, guiInfo.ElapsedTime % 60);
e0d211c62cf7 Cosmetic: Rename some guiInfo members.
ib
parents: 33646
diff changeset
134 stringreplace(text, "$3", "%.2i", guiInfo.ElapsedTime / 3600);
e0d211c62cf7 Cosmetic: Rename some guiInfo members.
ib
parents: 33646
diff changeset
135 stringreplace(text, "$4", "%.2i", (guiInfo.ElapsedTime / 60) % 60);
e0d211c62cf7 Cosmetic: Rename some guiInfo members.
ib
parents: 33646
diff changeset
136 stringreplace(text, "$5", "%.2i", guiInfo.ElapsedTime % 60);
e0d211c62cf7 Cosmetic: Rename some guiInfo members.
ib
parents: 33646
diff changeset
137 stringreplace(text, "$6", "%.2i:%.2i:%.2i", guiInfo.RunningTime / 3600,
e0d211c62cf7 Cosmetic: Rename some guiInfo members.
ib
parents: 33646
diff changeset
138 (guiInfo.RunningTime / 60) % 60, guiInfo.RunningTime % 60);
e0d211c62cf7 Cosmetic: Rename some guiInfo members.
ib
parents: 33646
diff changeset
139 stringreplace(text, "$7", "%.4i:%.2i", guiInfo.RunningTime / 60, guiInfo.RunningTime % 60);
e0d211c62cf7 Cosmetic: Rename some guiInfo members.
ib
parents: 33646
diff changeset
140 stringreplace(text, "$8", "%i:%.2i:%.2i", guiInfo.ElapsedTime / 3600,
e0d211c62cf7 Cosmetic: Rename some guiInfo members.
ib
parents: 33646
diff changeset
141 (guiInfo.ElapsedTime / 60) % 60, guiInfo.ElapsedTime % 60);
33555
c5a19bbeac2b Cosmetic: Rename some GUI variables and functions.
ib
parents: 33534
diff changeset
142 stringreplace(text, "$v", "%3.2f", guiInfo.Volume);
c5a19bbeac2b Cosmetic: Rename some GUI variables and functions.
ib
parents: 33534
diff changeset
143 stringreplace(text, "$V", "%3.1f", guiInfo.Volume);
c5a19bbeac2b Cosmetic: Rename some GUI variables and functions.
ib
parents: 33534
diff changeset
144 stringreplace(text, "$b", "%3.2f", guiInfo.Balance);
c5a19bbeac2b Cosmetic: Rename some GUI variables and functions.
ib
parents: 33534
diff changeset
145 stringreplace(text, "$B", "%3.1f", guiInfo.Balance);
c5a19bbeac2b Cosmetic: Rename some GUI variables and functions.
ib
parents: 33534
diff changeset
146 stringreplace(text, "$t", "%.2i", guiInfo.Track);
34163
95c396eb89ab Internationalize and localize the Win32 GUI.
ib
parents: 34135
diff changeset
147 stringreplace(text, "$o", "%s", acp(TranslateFilename(0, tmp, sizeof(tmp))));
33901
d4f80f889106 Cosmetic: Rename guiInfo members.
ib
parents: 33897
diff changeset
148 stringreplace(text, "$x", "%i", guiInfo.VideoWidth);
d4f80f889106 Cosmetic: Rename guiInfo members.
ib
parents: 33897
diff changeset
149 stringreplace(text, "$y", "%i", guiInfo.VideoHeight);
33555
c5a19bbeac2b Cosmetic: Rename some GUI variables and functions.
ib
parents: 33534
diff changeset
150 stringreplace(text, "$C", "%s", guiInfo.sh_video ? codecname : "");
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
151 stringreplace(text, "$$", "$");
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
152
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
153 if(!strcmp(text, "$p") || !strcmp(text, "$s") || !strcmp(text, "$e"))
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
154 {
33615
1f9a31d4f114 Replace all playback integer constants by their symbolic constants.
ib
parents: 33564
diff changeset
155 if(guiInfo.Playing == GUI_STOP) stringreplace(text, NULL, "s");
1f9a31d4f114 Replace all playback integer constants by their symbolic constants.
ib
parents: 33564
diff changeset
156 else if(guiInfo.Playing == GUI_PLAY) stringreplace(text, NULL, "p");
1f9a31d4f114 Replace all playback integer constants by their symbolic constants.
ib
parents: 33564
diff changeset
157 else if(guiInfo.Playing == GUI_PAUSE) stringreplace(text, NULL, "e");
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
158 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
159
33646
f3300b0c38a9 Rename guiInterface_t member AudioType AudioChannels.
ib
parents: 33615
diff changeset
160 if(guiInfo.AudioChannels == 0) stringreplace(text, "$a", "n");
f3300b0c38a9 Rename guiInterface_t member AudioType AudioChannels.
ib
parents: 33615
diff changeset
161 else if(guiInfo.AudioChannels == 1) stringreplace(text, "$a", "m");
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
162 else stringreplace(text, "$a", "t");
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
163
33555
c5a19bbeac2b Cosmetic: Rename some GUI variables and functions.
ib
parents: 33534
diff changeset
164 if(guiInfo.StreamType == 0)
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
165 stringreplace(text, "$T", "f");
33555
c5a19bbeac2b Cosmetic: Rename some GUI variables and functions.
ib
parents: 33534
diff changeset
166 else if(guiInfo.StreamType == STREAMTYPE_DVD || guiInfo.StreamType == STREAMTYPE_DVDNAV)
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
167 stringreplace(text, "$T", "d");
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
168 else stringreplace(text, "$T", "u");
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
169
34163
95c396eb89ab Internationalize and localize the Win32 GUI.
ib
parents: 34135
diff changeset
170 stringreplace(text, "$f", acp(TranslateFilename(1, tmp, sizeof(tmp))));
95c396eb89ab Internationalize and localize the Win32 GUI.
ib
parents: 34135
diff changeset
171 stringreplace(text, "$F", acp(TranslateFilename(2, tmp, sizeof(tmp))));
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
172
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
173 return text;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
174 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
175
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
176 /* cuts text to buflen scrolling from right to left */
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
177 static void scrolltext(char *text, unsigned int buflen, float *value)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
178 {
30702
9fc9d1e788aa Do not cast the results of malloc/calloc/realloc.
diego
parents: 27341
diff changeset
179 char *buffer = malloc(buflen + 1);
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
180 unsigned int x,i;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
181 if(*value < buflen) x = 0;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
182 else x = *value - buflen;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
183 memset(buffer, ' ', buflen);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
184 for (i = (*value>=buflen) ? 0 : buflen - *value; i<buflen; i++)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
185 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
186 if(x < strlen(text))
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
187 buffer[i] = text[x];
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
188 x++;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
189 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
190 buffer[buflen] = 0;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
191 *value += 1.0f;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
192 if(*value >= strlen(text) + buflen) *value = 0.0f;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
193 strcpy(text, buffer);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
194 free(buffer);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
195 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
196
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
197 /* updates all dlabels and slabels */
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
198 void renderinfobox(skin_t *skin, window_priv_t *priv)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
199 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
200 unsigned int i;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
201 if (!priv) return;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
202
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
203 /* repaint the area behind the text*/
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
204 /* we have to do this for all labels here, because they may overlap in buggy skins ;( */
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
205
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
206 for (i=0; i<skin->widgetcount; i++)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
207 if((skin->widgets[i]->type == tyDlabel) || (skin->widgets[i]->type == tySlabel))
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
208 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
209 if(skin->widgets[i]->window == priv->type)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
210 render(skin->desktopbpp,
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
211 &priv->img,
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
212 find_background(skin, skin->widgets[i]),
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
213 skin->widgets[i]->x,
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
214 skin->widgets[i]->y,
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
215 skin->widgets[i]->x,
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
216 skin->widgets[i]->y,
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
217 skin->widgets[i]->length,
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
218 skin->widgets[i]->font->chars[0]->height,
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
219 1);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
220 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
221
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
222 /* load all slabels and dlabels */
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
223 for (i=0; i<skin->widgetcount; i++)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
224 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
225 widget *item = skin->widgets[i];
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
226 if(item->window != priv->type) continue;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
227 if((i == skin->widgetcount) || (item->type == tyDlabel) || (item->type == tySlabel))
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
228 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
229 char *text = generatetextfromlabel(item);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
230 unsigned int current, c;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
231 int offset = 0;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
232 unsigned int textlen;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
233 if(!text) continue;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
234 textlen = strlen(text);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
235
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
236 /* render(win, win->background, gui->skin->widgets[i]->x, gui->skin->widgets[i]->y,
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
237 gui->skin->widgets[i]->x, gui->skin->widgets[i]->y,
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
238 gui->skin->widgets[i]->length, gui->skin->widgets[i]->font->chars[0]->height,1); */
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
239
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
240 /* calculate text size */
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
241 for (current=0; current<textlen; current++)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
242 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
243 for (c=0; c<item->font->charcount; c++)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
244 if(item->font->chars[c]->c == text[current])
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
245 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
246 offset += item->font->chars[c]->width;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
247 break;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
248 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
249 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
250
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
251 /* labels can be scrolled if they are to big */
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
252 if((item->type == tyDlabel) && (item->length < offset))
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
253 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
254 int tomuch = (offset - item->length) / (offset /textlen);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
255 scrolltext(text, textlen - tomuch - 1, &skin->widgets[i]->value);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
256 textlen = strlen(text);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
257 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
258
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
259 /* align the text */
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
260 if(item->align == 1)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
261 offset = (item->length-offset) / 2;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
262 else if(item->align == 2)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
263 offset = item->length-offset;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
264 else
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
265 offset = 0;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
266
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
267 if(offset < 0) offset = 0;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
268
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
269 /* render the text */
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
270 for (current=0; current<textlen; current++)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
271 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
272 for (c=0; c<item->font->charcount; c++)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
273 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
274 char_t *cchar = item->font->chars[c];
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
275 if(cchar->c == *(text + current))
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
276 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
277 render(skin->desktopbpp,
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
278 &priv->img,
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
279 item->font->image,
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
280 item->x + offset,
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
281 item->y,
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
282 cchar->x,
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
283 cchar->y,
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
284 (cchar->width + offset > item->length) ? item->length - offset : cchar->width,
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
285 cchar->height,
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
286 1);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
287 offset += cchar->width;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
288 break;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
289 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
290 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
291 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
292 free(text);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
293 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
294 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
295 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
296
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
297 /******************************************************************/
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
298 /* WIDGET related functions */
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
299 /******************************************************************/
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
300
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
301 void renderwidget(skin_t *skin, image *dest, widget *item, int state)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
302 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
303 image *img = NULL;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
304 int height;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
305 int y;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
306
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
307 if(!dest) return;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
308 if((item->type == tyButton) || (item->type == tyHpotmeter) || (item->type == tyPotmeter))
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
309 img = item->bitmap[0];
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
310
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
311 if(!img) return;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
312
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
313 y = item->y;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
314 if(item->type == tyPotmeter)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
315 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
316 height = img->height / item->phases;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
317 y = height * (int)(item->value * item->phases / 100);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
318 if(y > img->height-height)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
319 y = img->height - height;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
320 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
321 else
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
322 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
323 height = img->height / 3;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
324 y = state * height;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
325 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
326
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
327 /* redraw background */
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
328 if(item->type == tyButton)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
329 render(skin->desktopbpp, dest, find_background(skin,item), item->x, item->y, item->x, item->y, img->width, height, 1);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
330
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
331 if((item->type == tyHpotmeter) || (item->type == tyPotmeter))
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
332 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
333 /* repaint the area behind the slider */
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
334 render(skin->desktopbpp, dest, find_background(skin, item), item->wx, item->wy, item->wx, item->wy, item->wwidth, item->height, 1);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
335 item->x = item->value * (item->wwidth-item->width) / 100 + item->wx;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
336 if((item->x + item->width) > (item->wx + item->wwidth))
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
337 item->x = item->wx + item->wwidth - item->width;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
338 if(item->x < item->wx)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
339 item->x = item->wx;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
340 /* workaround for blue */
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
341 if(item->type == tyHpotmeter)
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
342 height = (item->height < img->height / 3) ? item->height : img->height / 3;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
343 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
344 render(skin->desktopbpp, dest, img, item->x, item->y, 0, y, img->width, height, 1);
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
345 }