1
0

gammamgr.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #include <precomp.h>
  2. #include <api.h>
  3. #include "gammamgr.h"
  4. #include <api/service/servicei.h>
  5. #include <api/skin/skinelem.h>
  6. #include <api/syscb/callbacks/skincb.h>
  7. void GammaMgr::init()
  8. {
  9. skinXML.registerCallback(L"WinampAbstractionLayer\fgammaset", &xmlreader); //back compat
  10. skinXML.registerCallback(L"WinampAbstractionLayer\fgammaset\fgammagroup", &xmlreader); //back compat
  11. skinXML.registerCallback(L"WasabiXML\fgammaset", &xmlreader);
  12. skinXML.registerCallback(L"WasabiXML\fgammaset\fgammagroup", &xmlreader);
  13. curset = -1;
  14. }
  15. void GammaMgr::deinit()
  16. {
  17. WASABI_API_COLORTHEMES->deleteAllGammaSets();
  18. skinXML.unregisterCallback(&xmlreader);
  19. }
  20. void GammaMgr::onBeforeLoadingGammaGroups()
  21. {
  22. WASABI_API_COLORTHEMES->deleteAllGammaSets();
  23. curset = -1;
  24. }
  25. void GammaMgr::onAfterLoadingGammaGroups()
  26. {}
  27. void GammaMgr::loadDefault()
  28. {
  29. WASABI_API_COLORTHEMES->StartTransaction();
  30. #ifdef ON_LOAD_EXTRA_COLORTHEMES
  31. ON_LOAD_EXTRA_COLORTHEMES();
  32. #endif
  33. WASABI_API_COLORTHEMES->EndTransaction();
  34. if (WASABI_API_COLORTHEMES->getGammaSet() == NULL)
  35. {
  36. wchar_t txt[256] = {0};
  37. WASABI_API_CONFIG->getStringPrivate(StringPrintfW(L"Color Themes/%s", WASABI_API_SKIN->getSkinName()), txt, 256, L"Default");
  38. WASABI_API_COLORTHEMES->setGammaSet(txt);
  39. }
  40. }
  41. int GammaMgr::gammaEqual(const wchar_t *id1, const wchar_t *id2)
  42. {
  43. const wchar_t *a = WASABI_API_PALETTE->getGammaGroupFromId(id1);
  44. const wchar_t *b = WASABI_API_PALETTE->getGammaGroupFromId(id2);
  45. if (!a || !b) return 1;
  46. return !WCSICMP(a, b);
  47. }
  48. void GammaMgrXmlReader::xmlReaderOnStartElementCallback(const wchar_t *xmltag, skin_xmlreaderparams *params)
  49. {
  50. GammaMgr::xmlReaderOnStartElementCallback(xmltag, params);
  51. }
  52. void GammaMgr::xmlReaderOnStartElementCallback(const wchar_t *xmltag, skin_xmlreaderparams *params)
  53. {
  54. if (!WCSICMP(xmltag, L"gammaset"))
  55. {
  56. const wchar_t *id = params->getItemValue(L"id");
  57. WASABI_API_COLORTHEMES->resetGammaSet(id);
  58. curset = WASABI_API_COLORTHEMES->newGammaSet(id);
  59. }
  60. else if (!WCSICMP(xmltag, L"gammagroup"))
  61. {
  62. const wchar_t *id = params->getItemValue(L"id");
  63. if (!id) // TODO: should we pop up a skin error msgbox?
  64. return;
  65. StringW value = params->getItemValue(L"value");
  66. int r = 0, g = 0, b = 0;
  67. wchar_t *p = value.getNonConstVal();
  68. if (!p) // TODO: should we pop up a skin error msgbox?
  69. return;
  70. wchar_t *q = p;
  71. while (q && *q && *q != ',') q++;
  72. if (q && *q == ',') *q++ = 0;
  73. r = WTOI(p);
  74. if (*q)
  75. {
  76. p = q;
  77. while (*q && *q != ',') q++;
  78. if (*q == ',') *q++ = 0;
  79. g = WTOI(p);
  80. if (*q) b = WTOI(q);
  81. }
  82. int makegray = params->getItemValueInt(L"gray");
  83. int boost = params->getItemValueInt(L"boost");
  84. if (!WCSICMP(id, L"General") && curset>=0)
  85. {
  86. ColorThemeGroup *generalgroup = WASABI_API_COLORTHEMES->enumColorThemeGroup(curset, -1);
  87. if (generalgroup)
  88. {
  89. generalgroup->setRed(r);
  90. generalgroup->setGreen(g);
  91. generalgroup->setBlue(b);
  92. generalgroup->setGray(makegray);
  93. generalgroup->setBoost(boost);
  94. }
  95. }
  96. else if (curset != -1)
  97. {
  98. ColorThemeGroupI new_group(id, r, g, b, makegray, boost);
  99. WASABI_API_COLORTHEMES->addGammaGroup(curset, &new_group);
  100. }
  101. }
  102. }
  103. GammaMgrXmlReader GammaMgr::xmlreader;
  104. int GammaMgr::curset;
  105. #define CBCLASS ColorThemeGroupI
  106. START_DISPATCH;
  107. CB(COLORTHEMEGROUPGETNAME, getName);
  108. CB(COLORTHEMEGROUPGETRED, getRed);
  109. CB(COLORTHEMEGROUPGETGREEN, getGreen);
  110. CB(COLORTHEMEGROUPGETBLUE, getBlue);
  111. CB(COLORTHEMEGROUPGETGRAY, getGray);
  112. CB(COLORTHEMEGROUPGETBOOST, getBoost);
  113. VCB(COLORTHEMEGROUPSETNAME, setName);
  114. VCB(COLORTHEMEGROUPSETRED, setRed);
  115. VCB(COLORTHEMEGROUPSETGREEN, setGreen);
  116. VCB(COLORTHEMEGROUPSETBLUE, setBlue);
  117. VCB(COLORTHEMEGROUPSETGRAY, setGray);
  118. VCB(COLORTHEMEGROUPSETBOOST, setBoost);
  119. END_DISPATCH;