aboutsummaryrefslogtreecommitdiff
path: root/Src/Winamp/draw_embed.cpp
blob: 345ae7cede384e795528990d5ad27c5adec708ff (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
/** (c) Nullsoft, Inc.         C O N F I D E N T I A L
 ** Filename: 
 ** Project:
 ** Description:
 ** Author:
 ** Created:
 **/
#include "Main.h"
#include "draw.h"

HBITMAP embedBM;

int titlebar_font_widths[26] = {0};
int titlebar_font_offsets[26] = {0};
int titlebar_font_num_widths[12] = {0};
int titlebar_font_num_offsets[12] = {0};
int titlebar_font_unknown_width = 5;

static int calcTBFontTextWidth(char *text)
{
	int w=0;
	while (text && *text)
	{
		char c=*text++;
		if (c >= 'a' && c <= 'z') c+='A'-'a';

		if (c >= 'A' && c <= 'Z' && titlebar_font_widths[c-'A']) 
			w+=titlebar_font_widths[c-'A'];
		else if (c >= '0' && c <= '9' && titlebar_font_widths[c-'0'] && Skin_UseGenNums) 
			w+=titlebar_font_num_widths[c-'0'];
		else if (c == '-' && titlebar_font_widths[10] && Skin_UseGenNums) 
			w+=titlebar_font_num_widths[10];
		else if (c == ':' && titlebar_font_widths[11] && Skin_UseGenNums) 
			w+=titlebar_font_num_widths[11];
		else w+=titlebar_font_unknown_width;
	}
	return w;
}

static void drawTBText(HDC hdcout,int xp, int yp, char *buf, int maxw, int sel)
{
	while (buf && *buf)
	{
		char c=*buf++;
		int w=titlebar_font_unknown_width;
		if (c >= 'a' && c <= 'z') c+='A'-'a';

		if (c >= 'A' && c <= 'Z' && titlebar_font_widths[c-'A']) 
		{
			w=titlebar_font_widths[c-'A'];
			if (w > maxw) break;
			BitBlt(hdcout,xp,yp,w,7,bmDC,titlebar_font_offsets[c-'A'],88+(sel?8:0),SRCCOPY);
		}
		else if (c >= '0' && c <= '9' && titlebar_font_num_widths[c-'0'] && Skin_UseGenNums)
		{
			w=titlebar_font_num_widths[c-'0'];
			if (w > maxw) break;
			BitBlt(hdcout,xp,yp,w,7,bmDC,titlebar_font_num_offsets[c-'0'],72+(sel?8:0),SRCCOPY);
		}
		else if (c == '-' && titlebar_font_num_widths[10] && Skin_UseGenNums)
		{
			w=titlebar_font_num_widths[10];
			if (w > maxw) break;
			BitBlt(hdcout,xp,yp,w,7,bmDC,titlebar_font_num_offsets[10],72+(sel?8:0),SRCCOPY);
		}
		else if (c == ':' && titlebar_font_num_widths[11] && Skin_UseGenNums)
		{
			w=titlebar_font_num_widths[11];
			if (w > maxw) break;
			BitBlt(hdcout,xp,yp,w,7,bmDC,titlebar_font_num_offsets[11],72+(sel?8:0),SRCCOPY);
		}
		xp+=w;
		maxw-=w;
	}
}

void draw_embed_tbar(HWND hwnd, int state, int w)
{
	if (!disable_skin_borders)
	{
		HDC hdcout=GetWindowDC(hwnd);
		char buf[32] = {0};
		state = state?0:21;
		do_palmode(hdcout);
		setSrcBM(embedBM);
		GetWindowTextA(hwnd,buf,sizeof(buf)/sizeof(char)-1);
		buf[31]=0;
		{
			int textw_exact=calcTBFontTextWidth(buf);
			int nt;
			int xp=0;

			int textw=textw_exact + 24;
			textw -= textw % 25;

			if (textw > w-100) textw=w-100;

			BitBlt(hdcout,xp,0,25,20,bmDC,0,state,SRCCOPY);
			xp+=25;
			nt = (w - 100 - textw)/25;
			if (nt)
			{
				if (nt&1)
				{
					BitBlt(hdcout,xp,0,12,20,bmDC,104,state,SRCCOPY);
					xp+=12;
				}
				nt/=2;
				while (nt-->0)
				{
					BitBlt(hdcout,xp,0,25,20,bmDC,104,state,SRCCOPY);
					xp+=25;
				}
			}

			BitBlt(hdcout,xp,0,25,20,bmDC,26,state,SRCCOPY);
			xp+=25;

			nt = textw/25;
			if (nt)
			{
				int xstart=xp + (textw - textw_exact)/2;
				if (textw != textw_exact) xstart++;
				while (nt-->0)
				{
					BitBlt(hdcout,xp,0,25,20,bmDC,52,state,SRCCOPY);
					xp+=25;
				}
				drawTBText(hdcout,xstart,4,buf,textw,state);
			}

			BitBlt(hdcout,xp,0,25,20,bmDC,78,state,SRCCOPY);
			xp+=25;

			nt = (w - 100 - textw)/25;
			if (nt)
			{
				if (nt&1)
				{
					BitBlt(hdcout,xp,0,13,20,bmDC,104,state,SRCCOPY);
					xp+=13;
				}
				nt/=2;
				while (nt-->0)
				{
					BitBlt(hdcout,xp,0,25,20,bmDC,104,state,SRCCOPY);
					xp+=25;
				}
			}
			nt = (w - 100 - textw) % 25;
			if (nt>0)
			{
				StretchBlt(hdcout,xp,0,nt,20,bmDC,104,state,25,20,SRCCOPY);
				xp+=nt;
			}
			BitBlt(hdcout,xp,0,25,20,bmDC,130,state,SRCCOPY);
		}
		unsetSrcBM();
		ReleaseDC(hwnd,hdcout);
	}
}

void draw_embed(HWND hwnd, HDC hdcout, int w, int h, int flags)
{
	if (!disable_skin_borders)
	{
		do_palmode(hdcout);
		{ 
			// fg>this is here in case a child temporarily unparents itself from the embedwnd, like avs when it docks to its editor.
			// when the child is there, fillrect is clipped
			RECT r={11,20,w-8, h-14};
			FillRect(hdcout, &r, (HBRUSH)GetStockObject(BLACK_BRUSH));
		}
		draw_embed_tbar(hwnd,GetForegroundWindow()==hwnd?1:(config_hilite?0:1),w);
		setSrcBM(embedBM);
		{
			int y=(h-20-38)/29;
			int yp=20,x,xp;
			while (y-->0)
			{
				BitBlt(hdcout,0,yp,11,29,bmDC,127,42,SRCCOPY);
				BitBlt(hdcout,w-8,yp,8,29,bmDC,139,42,SRCCOPY);
				yp += 29;
			}
			y=(h-20-38)%29;
			if (y)
			{
				StretchBlt(hdcout,0,yp,11,y,bmDC,127,42,11,29,SRCCOPY);
				StretchBlt(hdcout,w-8,yp,8,y,bmDC,139,42,8,29,SRCCOPY);
				yp += y;
			}

			// 24 pixel lamity
			BitBlt(hdcout,0,yp,11,24,bmDC,158,42,SRCCOPY);
			BitBlt(hdcout,w-8,yp,8,24,bmDC,170,42,SRCCOPY);
			yp += 24;

			BitBlt(hdcout,0,yp,125,14,bmDC,0,42,SRCCOPY);
			x=(w-125-125)/25;
			xp=125;
			while (x-->0)
			{
				BitBlt(hdcout,xp,yp,25,14,bmDC,127,72,SRCCOPY);
				xp+=25;
			}
			x=(w-125-125)%25;
			if (x)
			{
				StretchBlt(hdcout,xp,yp,x,14,bmDC,127,72,25,14,SRCCOPY);
				xp+=x;
			}
			BitBlt(hdcout,xp,yp,125,14,bmDC,0,57,SRCCOPY);
			if (flags & EMBED_FLAGS_NORESIZE)
			{
				BitBlt(hdcout,xp+112,yp+2,7,7,bmDC,118,72,SRCCOPY);
			}
		}
		unsetSrcBM();
	}
}

void draw_paint_emb(HWND hwnd, int w, int h, int flags)
{
	PAINTSTRUCT ps;
	draw_embed(hwnd,BeginPaint(hwnd,&ps),w,h,flags);
	EndPaint(hwnd,&ps);
}

void draw_embed_tbutton(HWND hwnd, int b3, int w)
{
	if (!disable_skin_borders)
	{
		HDC hdcout=GetWindowDC(hwnd);
		do_palmode(hdcout);
		setSrcBM(embedBM);
		if (!b3)
			BitBlt(hdcout,w-11,3,9,9,bmDC,144,3,SRCCOPY);
		else
			BitBlt(hdcout,w-11,3,9,9,bmDC,148,42,SRCCOPY);
		unsetSrcBM();
		ReleaseDC(hwnd,hdcout);
	}
}