skinapi.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. #include <precomp.h>
  2. #include <api.h>
  3. #include "skinapi.h"
  4. #include <api/skin/skin.h>
  5. #include <api/wndmgr/skinembed.h>
  6. #include <api/skin/skinelem.h>
  7. #include <api/imgldr/imgldr.h>
  8. #include <api/skin/gammamgr.h>
  9. #include <api/skin/groupmgr.h>
  10. #include <api/skin/cursormgr.h>
  11. #include <api/skin/guitree.h>
  12. #include <api/skin/groupwndcreate.h>
  13. #include <api/wndmgr/autopopup.h>
  14. #include <tataki/canvas/bltcanvas.h>
  15. api_skin *skinApi;
  16. static waServiceTSingle<svc_windowCreate, GroupWndCreateSvc> groupWndCreate;
  17. SkinApi::SkinApi()
  18. {
  19. lockui = 0;
  20. tha = new Skin();
  21. SkinParser::initialize();
  22. WASABI_API_SVC->service_register(&groupWndCreate);
  23. SkinElementsMgr::init();
  24. GammaMgr::init();
  25. // fixed this for 5.58+ so it'll use the correct skins directory
  26. // and not the winamp.exe folder + "skins" - fixes @SKINSPATH@
  27. // when the skins directory has been altered - from Bento notifier.xml
  28. skinspath = WASABI_API_APP->path_getSkinSettingsPath();
  29. }
  30. SkinApi::~SkinApi()
  31. {
  32. delete tha; tha = NULL;
  33. #ifdef WASABI_COMPILE_WNDMGR
  34. AutoPopup::reset();
  35. #endif
  36. SkinElementsMgr::deinit();
  37. GammaMgr::deinit();
  38. WASABI_API_SVC->service_deregister(&groupWndCreate);
  39. SkinParser::shutdown();
  40. }
  41. void SkinApi::preShutdown()
  42. {
  43. Skin::unloadSkin();
  44. SkinElementsMgr::resetSkinElements();
  45. }
  46. ARGB32 SkinApi::skin_getColorElement(const wchar_t *type, const wchar_t **color_group)
  47. {
  48. return WASABI_API_PALETTE->getColorElement(type, color_group);
  49. }
  50. const ARGB32 *SkinApi::skin_getColorElementRef(const wchar_t *type, const wchar_t **color_group)
  51. {
  52. return WASABI_API_PALETTE->getColorElementRef(type, color_group);
  53. }
  54. const int *SkinApi::skin_getIterator()
  55. {
  56. return WASABI_API_PALETTE->getSkinPartIteratorPtr();
  57. }
  58. void SkinApi::skin_switchSkin(const wchar_t *skin_name, const wchar_t *skin_path)
  59. {
  60. if (skin_name && *skin_name) Skin::toggleSkin(skin_name, skin_path, 1);
  61. }
  62. void SkinApi::skin_unloadSkin()
  63. {
  64. Skin::unloadSkin();
  65. }
  66. const wchar_t *SkinApi::getSkinName()
  67. {
  68. return Skin::getSkinName();
  69. }
  70. const wchar_t *SkinApi::getSkinPath()
  71. {
  72. return Skin::getSkinPath();
  73. }
  74. const wchar_t *SkinApi::getSkinsPath()
  75. {
  76. return skinspath;
  77. }
  78. const wchar_t *SkinApi::getDefaultSkinPath()
  79. {
  80. return Skin::getDefaultSkinPath();
  81. }
  82. 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)
  83. {
  84. if (file == NULL)
  85. {
  86. DebugStringW(L"illegal param : file == NULL\n");
  87. return NULL;
  88. }
  89. return imageLoader::requestSkinBitmap(file, has_alpha, x, y, subw, subh, w, h, cached);
  90. }
  91. void SkinApi::imgldr_releaseSkinBitmap(ARGB32 *bmpbits)
  92. {
  93. if (bmpbits == NULL)
  94. {
  95. DebugStringW(L"illegal param : bmpbits == NULL\n");
  96. return ;
  97. }
  98. imageLoader::releaseSkinBitmap(bmpbits);
  99. }
  100. ARGB32 SkinApi::filterSkinColor(ARGB32 color, const wchar_t *elementid, const wchar_t *groupname)
  101. {
  102. return imageLoader::filterSkinColor(color, elementid, groupname);
  103. }
  104. void SkinApi::reapplySkinFilters()
  105. {
  106. imageLoader::applySkinFilters();
  107. }
  108. /* ---------------------------------------- */
  109. int SkinApi::colortheme_getNumColorSets()
  110. {
  111. return WASABI_API_COLORTHEMES->getNumGammaSets();
  112. }
  113. const wchar_t *SkinApi::colortheme_enumColorSet(int n)
  114. {
  115. return WASABI_API_COLORTHEMES->enumGammaSet(n);
  116. }
  117. int SkinApi::colortheme_getNumColorGroups(const wchar_t *colorset)
  118. {
  119. return WASABI_API_COLORTHEMES->getNumGammaGroups(colorset);
  120. }
  121. const wchar_t *SkinApi::colortheme_enumColorGroupName(const wchar_t *colorset, int n)
  122. {
  123. return WASABI_API_COLORTHEMES->enumGammaGroup(colorset, n);
  124. }
  125. ColorThemeGroup *SkinApi::colortheme_enumColorGroup(int colorset, int colorgroup)
  126. {
  127. return WASABI_API_COLORTHEMES->enumColorThemeGroup(colorset, colorgroup);
  128. }
  129. ColorThemeGroup *SkinApi::colortheme_getColorGroup(const wchar_t *colorset, const wchar_t *colorgroup)
  130. {
  131. return WASABI_API_COLORTHEMES->getColorThemeGroup(colorset, colorgroup);
  132. }
  133. void SkinApi::colortheme_setColorSet(const wchar_t *colorset)
  134. {
  135. WASABI_API_COLORTHEMES->setGammaSet(colorset);
  136. // TODO: benski> move this to a syscallback: SysCallback::SKINCB, SkinCallback::COLORTHEMECHANGED
  137. WASABI_API_CONFIG->setStringPrivate(StringPrintfW(L"Color Themes/%s", getSkinName()), colorset);
  138. }
  139. const wchar_t *SkinApi::colortheme_getColorSet()
  140. {
  141. return WASABI_API_COLORTHEMES->getGammaSet();
  142. }
  143. void SkinApi::colortheme_newColorSet(const wchar_t *set)
  144. {
  145. WASABI_API_COLORTHEMES->newGammaSet(set);
  146. }
  147. void SkinApi::colortheme_updateColorSet(const wchar_t *set)
  148. {
  149. WASABI_API_COLORTHEMES->updateGammaSet(set);
  150. }
  151. void SkinApi::colortheme_renameColorSet(const wchar_t *set, const wchar_t *newname)
  152. {
  153. WASABI_API_COLORTHEMES->renameGammaSet(set, newname);
  154. }
  155. void SkinApi::colortheme_deleteColorSet(const wchar_t *set)
  156. {
  157. WASABI_API_COLORTHEMES->deleteGammaSet(set);
  158. }
  159. /* -------------------------------------------- */
  160. int SkinApi::loadSkinFile(const wchar_t *xmlfile)
  161. {
  162. return Skin::loadSkinPart(xmlfile);
  163. }
  164. void SkinApi::unloadSkinPart(int skinpartid)
  165. {
  166. Skin::unloadSkinPart(skinpartid);
  167. }
  168. ifc_window *SkinApi::group_create(const wchar_t *groupid, int scripts_enabled)
  169. {
  170. return GroupMgr::instantiate(groupid, GROUP_GROUP, NULL, scripts_enabled);
  171. }
  172. int SkinApi::group_destroy(ifc_window *group)
  173. {
  174. return GroupMgr::destroy(static_cast<Group*>(group));
  175. }
  176. int SkinApi::group_exists(const wchar_t *groupid)
  177. {
  178. return GroupMgr::exists(groupid);
  179. }
  180. #ifdef WASABI_COMPILE_CONFIG
  181. ifc_window *SkinApi::group_create_cfg(const wchar_t *groupid, CfgItem *cfgitem, const wchar_t *attributename, int scripts_enabled)
  182. {
  183. return GroupMgr::instantiate(groupid, cfgitem, attributename, scripts_enabled);
  184. }
  185. #endif // WASABI_COMPILE_CONFIG
  186. #ifdef WASABI_COMPILE_WNDMGR
  187. ifc_window *SkinApi::group_create_layout(const wchar_t *groupid, int scripts_enabled)
  188. {
  189. return GroupMgr::instantiate(groupid, GROUP_LAYOUTGROUP, NULL, scripts_enabled);
  190. }
  191. #endif //WASABI_COMPILE_WNDMGR
  192. OSCURSOR SkinApi::cursor_request(const wchar_t *id)
  193. {
  194. return CursorMgr::requestCursor(id);
  195. }
  196. int SkinApi::parse(const wchar_t *str, const wchar_t *how)
  197. {
  198. return SkinParser::parse(str, how);
  199. }
  200. GuiObject *SkinApi::xui_new(const wchar_t *classname)
  201. {
  202. return SkinParser::xui_new(classname);
  203. }
  204. void SkinApi::xui_delete(GuiObject *o)
  205. {
  206. SkinParser::xui_delete(o);
  207. }
  208. int SkinApi::getNumGroupDefs()
  209. {
  210. return guiTree->getNumGroupDefs();
  211. }
  212. SkinItem *SkinApi::enumGroupDef(int n)
  213. {
  214. return guiTree->enumGroupDef(n);
  215. }
  216. ifc_window *SkinApi::group_createBySkinItem(SkinItem *item, int scripts_enabled)
  217. {
  218. return GroupMgr::instantiate(NULL, GROUP_GROUP, item, scripts_enabled);
  219. }
  220. SkinItem *SkinApi::getGroupDefAncestor(SkinItem *item)
  221. {
  222. return guiTree->getGroupDefAncestor(item);
  223. }
  224. int SkinApi::groupdef_getNumObjects(SkinItem *_item)
  225. {
  226. GuiTreeItem *item = static_cast<GuiTreeItem *>(_item);
  227. int idx = item->getIdx();
  228. idx++;
  229. int n = 0;
  230. while (1)
  231. {
  232. GuiTreeItem *it = guiTree->getList()->enumItem(idx);
  233. if (it->getType() == XML_TAG_GROUPDEF && it->getParams() == NULL) break;
  234. idx++; n++;
  235. }
  236. return n;
  237. }
  238. SkinItem *SkinApi::groupdef_enumObject(SkinItem *_item, int n)
  239. {
  240. GuiTreeItem *item = static_cast<GuiTreeItem *>(_item);
  241. int idx = item->getIdx();
  242. idx++;
  243. int _n = 0;
  244. GuiTreeItem *it = NULL;
  245. while (1)
  246. {
  247. it = guiTree->getList()->enumItem(idx);
  248. if (it->getType() == XML_TAG_GROUPDEF && it->getParams() == NULL) break;
  249. if (n == _n) break;
  250. idx++; _n++;
  251. }
  252. return it;
  253. }
  254. int SkinApi::loadGroupDefData(const wchar_t *groupdef, SkinItem **lastgroupdef)
  255. {
  256. StringW s;
  257. s = L"buf:";
  258. s += L"<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"yes\"?>"
  259. L"<WinampAbstractionLayer version=\"0.8\">";
  260. s += groupdef;
  261. s += L"</WinampAbstractionLayer>";
  262. int r = Skin::loadSkinPart(s);
  263. if (lastgroupdef != NULL)
  264. *lastgroupdef = guiTree->getLastDefinedGroup();
  265. return r;
  266. }
  267. double SkinApi::skin_getVersion()
  268. {
  269. return SkinParser::getSkinVersion();
  270. }
  271. #ifdef WASABI_COMPILE_IMGLDR
  272. ARGB32 SkinApi::skin_getBitmapColor(const wchar_t *id)
  273. {
  274. SkinBitmap bitmap(id);
  275. BltCanvas c(bitmap.getWidth() + 1, bitmap.getHeight() + 1, 0); // TODO: this won't work on the mac i don't think
  276. bitmap.blit(&c, 0, 0);
  277. int x = bitmap.getWidth() / 2;
  278. int y = bitmap.getHeight() / 2;
  279. int *bits = (int *)c.getBits();
  280. if (bits != NULL)
  281. {
  282. return bits[x + y*bitmap.getWidth() + 1];
  283. }
  284. return 0xFFFF00FF;
  285. }
  286. #endif
  287. bool SkinApi::skin_isLoaded()
  288. {
  289. return Skin::isLoaded();
  290. }