Initial community commit

This commit is contained in:
Jef
2024-09-24 14:54:57 +02:00
parent 537bcbc862
commit 20d28e80a5
16810 changed files with 4640254 additions and 2 deletions

View File

@ -0,0 +1,78 @@
#include "filteredcolor.h"
#include <tataki/api__tataki.h>
#include <bfc/bfc_assert.h>
static const int *skin_iterator=0;
FilteredColor::FilteredColor(ARGB32 _color, const wchar_t *colorgroupname)
{
group=0;
color = _color;
filteredcolor = _color;
if (colorgroupname)
group = _wcsdup(colorgroupname);
skin_iterator = NULL;
latest_iteration = -1;
need_filter = 1;
}
FilteredColor::~FilteredColor()
{
free(group);
}
void FilteredColor::setColor(ARGB32 _color)
{
color = _color;
filteredcolor = color;
}
void FilteredColor::setColorGroup(const wchar_t *_group)
{
free(group);
if (_group)
group = _wcsdup(_group);
else
group = 0;
need_filter = 1;
}
ARGB32 FilteredColor::getColor()
{
ensureFiltered();
return filteredcolor;
}
ARGB32 *FilteredColor::getColorRef()
{
if (!WASABI_API_SKIN)
return 0;
ensureFiltered();
return &filteredcolor;
}
void FilteredColor::ensureFiltered()
{
// fetch iterator pointer if necessary
if (skin_iterator == NULL)
{
skin_iterator = WASABI_API_PALETTE->getSkinPartIteratorPtr();
ASSERT(skin_iterator != NULL);
}
// see if we're current
if (*skin_iterator != latest_iteration)
{
need_filter = 1; // pointer now invalid, must re-get
latest_iteration = *skin_iterator; // and then we'll be current
}
if (need_filter && WASABI_API_SKIN)
{
filteredcolor = WASABI_API_SKIN->filterSkinColor(color, getColorName(), group);
need_filter = 0;
}
}

View File

@ -0,0 +1,29 @@
#ifndef TATAKI_FILTEREDCOLOR_H
#define TATAKI_FILTEREDCOLOR_H
#include <tataki/export.h>
class TATAKIAPI FilteredColor
{
public:
FilteredColor(ARGB32 _color=0, const wchar_t *colorgroupname=L"");
virtual ~FilteredColor();
virtual void setColor(ARGB32 _color);
virtual void setColorGroup(const wchar_t *group);
ARGB32 getColor();
ARGB32 *getColorRef();
virtual const wchar_t *getColorName() { return NULL; }
private:
void ensureFiltered();
ARGB32 color;
ARGB32 filteredcolor;
wchar_t *group;
int need_filter;
int latest_iteration;
};
#endif

View File

@ -0,0 +1,134 @@
#include "skinclr.h"
#include <bfc/assert.h>
#include <tataki/api__tataki.h>
static const int *skin_iterator = 0;
SkinColor::SkinColor(const wchar_t *_name, const wchar_t *colorgroup)
: FilteredColor(0, (colorgroup == NULL || !*colorgroup) ? L"Text" : colorgroup)
{
name = 0;
latest_iteration = -1;
//CUT skin_iterator = NULL;
setElementName(_name);
ovr_grp = colorgroup;
dooverride = 0;
color_override = 0;
}
SkinColor::~SkinColor()
{
if (name) free(name);
}
ARGB32 SkinColor::v(ARGB32 defaultColor)
{
if (!name || !*name) return defaultColor;
if (!iteratorValid())
{
val = NULL; // pointer now invalid, must re-get
latest_iteration = *skin_iterator; // and then we'll be current
// new pointer please
const wchar_t *grp = NULL;
ARGB32 r;
if (dooverride)
r = color_override;
else
r = WASABI_API_PALETTE->getColorElement(name, &grp);
if (ovr_grp == NULL && grp != NULL)
setColorGroup(grp);
FilteredColor::setColor(r);
val = getColorRef();
}
if (val == NULL) return defaultColor;
return *val;
}
void SkinColor::setElementName(const wchar_t *_name)
{
if (name) free(name);
if (_name)
name = _wcsdup(_name);
else
name = 0;
val = NULL;
latest_iteration = 0;
}
void SkinColor::setColor(ARGB32 c)
{
dooverride = 1;
color_override = c;
FilteredColor::setColor(color_override);
}
int SkinColor::iteratorValid()
{
// fetch iterator pointer if necessary
if (skin_iterator == NULL)
{
skin_iterator = WASABI_API_PALETTE->getSkinPartIteratorPtr();
ASSERT(skin_iterator != NULL);
}
// see if we're current
return (*skin_iterator == latest_iteration);
}
const wchar_t *SkinColor::operator =(const wchar_t *name) { setElementName(name); return name;}
const wchar_t *SkinColor::getColorName() { return name; }
ARGB32 SkinColor::GetColor(const wchar_t *name, const wchar_t *group, ARGB32 defaultColor)
{
const wchar_t *colorGroup = NULL;
const ARGB32 *color = WASABI_API_PALETTE->getColorElementRef(name, &colorGroup);
if (!color)
return defaultColor;
/* TODO: benski> if we ever add color themes to Classic, we'll need to change this */
if (WASABI_API_SKIN)
{
if (group)
colorGroup = group;
if (!colorGroup)
colorGroup = L"Text";
return WASABI_API_SKIN->filterSkinColor(*color, name, colorGroup);
}
else
{
return *color;
}
}
bool SkinColor::TryGetColor(ARGB32 *returned_color, const wchar_t *name, const wchar_t *group)
{
const wchar_t *colorGroup = NULL;
const ARGB32 *color = WASABI_API_PALETTE->getColorElementRef(name, &colorGroup);
if (!color)
return false;
/* TODO: benski> if we ever add color themes to Classic, we'll need to change this */
if (WASABI_API_SKIN)
{
if (group)
colorGroup = group;
if (!colorGroup)
colorGroup = L"Text";
*returned_color = WASABI_API_SKIN->filterSkinColor(*color, name, colorGroup);
}
else
{
*returned_color = *color;
}
return true;
}

View File

@ -0,0 +1,39 @@
#ifndef TATAKI_SKINCLR_H
#define TATAKI_SKINCLR_H
#include <tataki/export.h>
#include "filteredcolor.h"
// note: only pass in a const char *
class TATAKIAPI SkinColor : public FilteredColor
{
public:
explicit SkinColor(const wchar_t *name=NULL, const wchar_t *colorgroup=NULL);
~SkinColor();
virtual void setColor(ARGB32 c);
ARGB32 v(ARGB32 defaultColor=0xFFFF00FF);
operator int() { return v(); }
void setElementName(const wchar_t *name);
const wchar_t *operator =(const wchar_t *name);
virtual const wchar_t *getColorName();
int iteratorValid(); // if FALSE, color might have changed
// if you just need to do a one-off skin color query, use this function
// because SkinColor class does some malloc'ing
static ARGB32 GetColor(const wchar_t *name, const wchar_t *group = 0, ARGB32 defaultColor=0xFFFF00FF);
static bool TryGetColor(ARGB32 *color, const wchar_t *name, const wchar_t *group = 0);
private:
wchar_t *name;
ARGB32 *val;
int latest_iteration;
const wchar_t *ovr_grp;
int color_override;
int dooverride;
};
#endif