skinclr.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #include "skinclr.h"
  2. #include <bfc/assert.h>
  3. #include <tataki/api__tataki.h>
  4. static const int *skin_iterator = 0;
  5. SkinColor::SkinColor(const wchar_t *_name, const wchar_t *colorgroup)
  6. : FilteredColor(0, (colorgroup == NULL || !*colorgroup) ? L"Text" : colorgroup)
  7. {
  8. name = 0;
  9. latest_iteration = -1;
  10. //CUT skin_iterator = NULL;
  11. setElementName(_name);
  12. ovr_grp = colorgroup;
  13. dooverride = 0;
  14. color_override = 0;
  15. }
  16. SkinColor::~SkinColor()
  17. {
  18. if (name) free(name);
  19. }
  20. ARGB32 SkinColor::v(ARGB32 defaultColor)
  21. {
  22. if (!name || !*name) return defaultColor;
  23. if (!iteratorValid())
  24. {
  25. val = NULL; // pointer now invalid, must re-get
  26. latest_iteration = *skin_iterator; // and then we'll be current
  27. // new pointer please
  28. const wchar_t *grp = NULL;
  29. ARGB32 r;
  30. if (dooverride)
  31. r = color_override;
  32. else
  33. r = WASABI_API_PALETTE->getColorElement(name, &grp);
  34. if (ovr_grp == NULL && grp != NULL)
  35. setColorGroup(grp);
  36. FilteredColor::setColor(r);
  37. val = getColorRef();
  38. }
  39. if (val == NULL) return defaultColor;
  40. return *val;
  41. }
  42. void SkinColor::setElementName(const wchar_t *_name)
  43. {
  44. if (name) free(name);
  45. if (_name)
  46. name = _wcsdup(_name);
  47. else
  48. name = 0;
  49. val = NULL;
  50. latest_iteration = 0;
  51. }
  52. void SkinColor::setColor(ARGB32 c)
  53. {
  54. dooverride = 1;
  55. color_override = c;
  56. FilteredColor::setColor(color_override);
  57. }
  58. int SkinColor::iteratorValid()
  59. {
  60. // fetch iterator pointer if necessary
  61. if (skin_iterator == NULL)
  62. {
  63. skin_iterator = WASABI_API_PALETTE->getSkinPartIteratorPtr();
  64. ASSERT(skin_iterator != NULL);
  65. }
  66. // see if we're current
  67. return (*skin_iterator == latest_iteration);
  68. }
  69. const wchar_t *SkinColor::operator =(const wchar_t *name) { setElementName(name); return name;}
  70. const wchar_t *SkinColor::getColorName() { return name; }
  71. ARGB32 SkinColor::GetColor(const wchar_t *name, const wchar_t *group, ARGB32 defaultColor)
  72. {
  73. const wchar_t *colorGroup = NULL;
  74. const ARGB32 *color = WASABI_API_PALETTE->getColorElementRef(name, &colorGroup);
  75. if (!color)
  76. return defaultColor;
  77. /* TODO: benski> if we ever add color themes to Classic, we'll need to change this */
  78. if (WASABI_API_SKIN)
  79. {
  80. if (group)
  81. colorGroup = group;
  82. if (!colorGroup)
  83. colorGroup = L"Text";
  84. return WASABI_API_SKIN->filterSkinColor(*color, name, colorGroup);
  85. }
  86. else
  87. {
  88. return *color;
  89. }
  90. }
  91. bool SkinColor::TryGetColor(ARGB32 *returned_color, const wchar_t *name, const wchar_t *group)
  92. {
  93. const wchar_t *colorGroup = NULL;
  94. const ARGB32 *color = WASABI_API_PALETTE->getColorElementRef(name, &colorGroup);
  95. if (!color)
  96. return false;
  97. /* TODO: benski> if we ever add color themes to Classic, we'll need to change this */
  98. if (WASABI_API_SKIN)
  99. {
  100. if (group)
  101. colorGroup = group;
  102. if (!colorGroup)
  103. colorGroup = L"Text";
  104. *returned_color = WASABI_API_SKIN->filterSkinColor(*color, name, colorGroup);
  105. }
  106. else
  107. {
  108. *returned_color = *color;
  109. }
  110. return true;
  111. }