aboutsummaryrefslogtreecommitdiff
path: root/Src/Wasabi/api/skin/skinapi.cpp
blob: f68a0614e189fff969a54a818a954e3a0c867d23 (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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
#include <precomp.h>
#include <api.h>
#include "skinapi.h"
#include <api/skin/skin.h>
#include <api/wndmgr/skinembed.h>
#include <api/skin/skinelem.h>
#include <api/imgldr/imgldr.h>
#include <api/skin/gammamgr.h>
#include <api/skin/groupmgr.h>
#include <api/skin/cursormgr.h>
#include <api/skin/guitree.h>
#include <api/skin/groupwndcreate.h>
#include <api/wndmgr/autopopup.h>
#include <tataki/canvas/bltcanvas.h>

api_skin *skinApi;
static waServiceTSingle<svc_windowCreate, GroupWndCreateSvc> groupWndCreate;

SkinApi::SkinApi()
{
	lockui = 0;
	tha = new Skin();
	SkinParser::initialize();

	WASABI_API_SVC->service_register(&groupWndCreate);

	SkinElementsMgr::init();
	GammaMgr::init();

	// fixed this for 5.58+ so it'll use the correct skins directory
	// and not the winamp.exe folder + "skins" - fixes @SKINSPATH@
	// when the skins directory has been altered - from Bento notifier.xml
	skinspath = WASABI_API_APP->path_getSkinSettingsPath();
}

SkinApi::~SkinApi()
{
	delete tha; tha = NULL;
#ifdef WASABI_COMPILE_WNDMGR
	AutoPopup::reset();
#endif
	SkinElementsMgr::deinit();
	GammaMgr::deinit();
	WASABI_API_SVC->service_deregister(&groupWndCreate);
	SkinParser::shutdown();
}

void SkinApi::preShutdown()
{
	Skin::unloadSkin();
	SkinElementsMgr::resetSkinElements();
}

ARGB32 SkinApi::skin_getColorElement(const wchar_t *type, const wchar_t **color_group)
{
	return WASABI_API_PALETTE->getColorElement(type, color_group);
}

const ARGB32 *SkinApi::skin_getColorElementRef(const wchar_t *type, const wchar_t **color_group)
{
	return WASABI_API_PALETTE->getColorElementRef(type, color_group);
}

const int *SkinApi::skin_getIterator()
{
	return WASABI_API_PALETTE->getSkinPartIteratorPtr();
}

void SkinApi::skin_switchSkin(const wchar_t *skin_name, const wchar_t *skin_path)
{
	if (skin_name && *skin_name) Skin::toggleSkin(skin_name, skin_path, 1);
}

void SkinApi::skin_unloadSkin()
{
	Skin::unloadSkin();
}

const wchar_t *SkinApi::getSkinName()
{
	return Skin::getSkinName();
}

const wchar_t *SkinApi::getSkinPath()
{
	return Skin::getSkinPath();
}

const wchar_t *SkinApi::getSkinsPath()
{
	return skinspath;
}

const wchar_t *SkinApi::getDefaultSkinPath()
{
	return Skin::getDefaultSkinPath();
}

ARGB32 *SkinApi::imgldr_requestSkinBitmap(const wchar_t *file, int *has_alpha, int *x, int *y, int *subw, int *subh, int *w, int *h, int cached)
{
	if (file == NULL)
	{
		DebugStringW(L"illegal param : file == NULL\n");
		return NULL;
	}
	return imageLoader::requestSkinBitmap(file, has_alpha, x, y, subw, subh, w, h, cached);
}

void SkinApi::imgldr_releaseSkinBitmap(ARGB32 *bmpbits)
{
	if (bmpbits == NULL)
	{
		DebugStringW(L"illegal param : bmpbits == NULL\n");
		return ;
	}
	imageLoader::releaseSkinBitmap(bmpbits);
}

ARGB32 SkinApi::filterSkinColor(ARGB32 color, const wchar_t *elementid, const wchar_t *groupname)
{
	return imageLoader::filterSkinColor(color, elementid, groupname);
}

void SkinApi::reapplySkinFilters()
{
	imageLoader::applySkinFilters();
}

/* ---------------------------------------- */
int SkinApi::colortheme_getNumColorSets()
{
	return WASABI_API_COLORTHEMES->getNumGammaSets();
}

const wchar_t *SkinApi::colortheme_enumColorSet(int n)
{
	return WASABI_API_COLORTHEMES->enumGammaSet(n);
}

int SkinApi::colortheme_getNumColorGroups(const wchar_t *colorset)
{
	return WASABI_API_COLORTHEMES->getNumGammaGroups(colorset);
}

const wchar_t *SkinApi::colortheme_enumColorGroupName(const wchar_t *colorset, int n)
{
	return WASABI_API_COLORTHEMES->enumGammaGroup(colorset, n);
}

ColorThemeGroup *SkinApi::colortheme_enumColorGroup(int colorset, int colorgroup)
{
	return WASABI_API_COLORTHEMES->enumColorThemeGroup(colorset, colorgroup);
}

ColorThemeGroup *SkinApi::colortheme_getColorGroup(const wchar_t *colorset, const wchar_t *colorgroup)
{
	return WASABI_API_COLORTHEMES->getColorThemeGroup(colorset, colorgroup);
}

void SkinApi::colortheme_setColorSet(const wchar_t *colorset)
{
	WASABI_API_COLORTHEMES->setGammaSet(colorset);
	// TODO: benski> move this to a syscallback: SysCallback::SKINCB, SkinCallback::COLORTHEMECHANGED
	WASABI_API_CONFIG->setStringPrivate(StringPrintfW(L"Color Themes/%s", getSkinName()), colorset);
}

const wchar_t *SkinApi::colortheme_getColorSet()
{
	return WASABI_API_COLORTHEMES->getGammaSet();
}

void SkinApi::colortheme_newColorSet(const wchar_t *set)
{
	WASABI_API_COLORTHEMES->newGammaSet(set);
}

void SkinApi::colortheme_updateColorSet(const wchar_t *set)
{
	WASABI_API_COLORTHEMES->updateGammaSet(set);
}

void SkinApi::colortheme_renameColorSet(const wchar_t *set, const wchar_t *newname)
{
	WASABI_API_COLORTHEMES->renameGammaSet(set, newname);
}

void SkinApi::colortheme_deleteColorSet(const wchar_t *set)
{
	WASABI_API_COLORTHEMES->deleteGammaSet(set);
}

 /* -------------------------------------------- */

int SkinApi::loadSkinFile(const wchar_t *xmlfile)
{
	return Skin::loadSkinPart(xmlfile);
}

void SkinApi::unloadSkinPart(int skinpartid)
{
	Skin::unloadSkinPart(skinpartid);
}

ifc_window *SkinApi::group_create(const wchar_t *groupid, int scripts_enabled)
{
	return GroupMgr::instantiate(groupid, GROUP_GROUP, NULL, scripts_enabled);
}

int SkinApi::group_destroy(ifc_window *group)
{
	return GroupMgr::destroy(static_cast<Group*>(group));
}

int SkinApi::group_exists(const wchar_t *groupid)
{
	return GroupMgr::exists(groupid);
}

#ifdef WASABI_COMPILE_CONFIG
ifc_window *SkinApi::group_create_cfg(const wchar_t *groupid, CfgItem *cfgitem, const wchar_t *attributename, int scripts_enabled)
{
	return GroupMgr::instantiate(groupid, cfgitem, attributename, scripts_enabled);
}
#endif // WASABI_COMPILE_CONFIG

#ifdef WASABI_COMPILE_WNDMGR
ifc_window *SkinApi::group_create_layout(const wchar_t *groupid, int scripts_enabled)
{
	return GroupMgr::instantiate(groupid, GROUP_LAYOUTGROUP, NULL, scripts_enabled);
}
#endif //WASABI_COMPILE_WNDMGR

OSCURSOR SkinApi::cursor_request(const wchar_t *id)
{
	return CursorMgr::requestCursor(id);
}

int SkinApi::parse(const wchar_t *str, const wchar_t *how)
{
	return SkinParser::parse(str, how);
}

GuiObject *SkinApi::xui_new(const wchar_t *classname)
{
	return SkinParser::xui_new(classname);
}

void SkinApi::xui_delete(GuiObject *o)
{
	SkinParser::xui_delete(o);
}

int SkinApi::getNumGroupDefs()
{
	return guiTree->getNumGroupDefs();
}

SkinItem *SkinApi::enumGroupDef(int n)
{
	return guiTree->enumGroupDef(n);
}

ifc_window *SkinApi::group_createBySkinItem(SkinItem *item, int scripts_enabled)
{
	return GroupMgr::instantiate(NULL, GROUP_GROUP, item, scripts_enabled);
}

SkinItem *SkinApi::getGroupDefAncestor(SkinItem *item)
{
	return guiTree->getGroupDefAncestor(item);
}

int SkinApi::groupdef_getNumObjects(SkinItem *_item)
{
	GuiTreeItem *item = static_cast<GuiTreeItem *>(_item);
	int idx = item->getIdx();
	idx++;
	int n = 0;
	while (1)
	{
		GuiTreeItem *it = guiTree->getList()->enumItem(idx);
		if (it->getType() == XML_TAG_GROUPDEF && it->getParams() == NULL) break;
		idx++; n++;
	}
	return n;
}

SkinItem *SkinApi::groupdef_enumObject(SkinItem *_item, int n)
{
	GuiTreeItem *item = static_cast<GuiTreeItem *>(_item);
	int idx = item->getIdx();
	idx++;
	int _n = 0;
	GuiTreeItem *it = NULL;
	while (1)
	{
		it = guiTree->getList()->enumItem(idx);
		if (it->getType() == XML_TAG_GROUPDEF && it->getParams() == NULL) break;
		if (n == _n) break;
		idx++; _n++;
	}
	return it;
}

int SkinApi::loadGroupDefData(const wchar_t *groupdef, SkinItem **lastgroupdef)
{
	StringW s;
	s = L"buf:";
  
	s += L"<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"yes\"?>"
	     L"<WinampAbstractionLayer version=\"0.8\">";

	s += groupdef;

	s += L"</WinampAbstractionLayer>";

	int r = Skin::loadSkinPart(s);
	if (lastgroupdef != NULL)
		*lastgroupdef = guiTree->getLastDefinedGroup();
	return r;
}

double SkinApi::skin_getVersion()
{
	return SkinParser::getSkinVersion();
}
#ifdef WASABI_COMPILE_IMGLDR
ARGB32 SkinApi::skin_getBitmapColor(const wchar_t *id)
{
	SkinBitmap bitmap(id);
	BltCanvas c(bitmap.getWidth() + 1, bitmap.getHeight() + 1, 0); // TODO: this won't work on the mac i don't think
	bitmap.blit(&c, 0, 0);
	int x = bitmap.getWidth() / 2;
	int y = bitmap.getHeight() / 2;
	int *bits = (int *)c.getBits();
	if (bits != NULL)
	{
		return bits[x + y*bitmap.getWidth() + 1];
	}
	return 0xFFFF00FF;
}
#endif

bool SkinApi::skin_isLoaded()
{
	return Skin::isLoaded();
}