ManaPlus
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes
Theme Class Reference

#include <theme.h>

Inheritance diagram for Theme:
Palette ConfigListener

Public Member Functions

 Theme ()
 
 ~Theme ()
 
Skinload (const std::string &filename, const std::string &filename2, const bool full, const std::string &defaultPath)
 
SkinloadSkinRect (ImageRect &image, const std::string &name, const std::string &name2, const int start, const int end)
 
void unload (Skin *const skin)
 
void updateAlpha ()
 
float getMinimumOpacity () const
 
const ColorgetColor (ThemeColorIdT type, const unsigned int alpha)
 
ThemeColorIdT getIdByChar (const signed char c, bool &valid) const
 
void setMinimumOpacity (const float minimumOpacity)
 
void optionChanged (const std::string &name)
 
void loadRect (ImageRect &image, const std::string &name, const std::string &name2, const int start, const int end)
 
- Public Member Functions inherited from Palette
const ColorgetCharColor (const signed char c, bool &valid) const
 
char getColorChar (const int type) const
 
- Public Member Functions inherited from ConfigListener
 ConfigListener ()
 
virtual ~ConfigListener ()
 

Static Public Member Functions

static void prepareThemePath ()
 
static void selectSkin ()
 
static std::string getThemePath ()
 
static std::string getThemeName ()
 
static void fillSkinsList (StringVect &list)
 
static void fillFontsList (StringVect &list)
 
static void fillSoundsList (StringVect &list)
 
static std::string resolveThemePath (const std::string &path)
 
static ImagegetImageFromTheme (const std::string &path)
 
static ImageSetgetImageSetFromTheme (const std::string &path, const int w, const int h)
 
static ImageSetgetImageSetFromThemeXml (const std::string &name, const std::string &name2, const int w, const int h)
 
static Color getProgressColor (const ProgressColorIdT type, const float progress)
 
static void unloadRect (const ImageRect &rect, const int start, const int end)
 
static ImagegetImageFromThemeXml (const std::string &name, const std::string &name2)
 
static ThemeInfoloadInfo (const std::string &themeName)
 
- Static Public Member Functions inherited from Palette
static void advanceGradients ()
 

Private Types

typedef std::map< std::string, Skin * > Skins
 
typedef Skins::iterator SkinIterator
 
typedef std::vector< DyePalette * > ProgressColors
 

Private Member Functions

SkinreadSkin (const std::string &filename0, const bool full)
 
void loadColors (std::string file)
 

Static Private Member Functions

static bool tryThemePath (const std::string &themePath)
 

Private Attributes

Skins mSkins
 
float mMinimumOpacity
 
ProgressColors mProgressColors
 

Static Private Attributes

static std::string mThemePath
 
static std::string mThemeName
 
static std::string mScreenDensity
 

Additional Inherited Members

- Static Public Attributes inherited from Palette
static const Color BLACK = Color(0, 0, 0, 255)
 
- Protected Types inherited from Palette
typedef std::set< Palette * > Palettes
 
typedef std::vector< ColorElemColors
 
typedef std::map< unsigned char, int > CharColors
 
- Protected Member Functions inherited from Palette
 Palette (const int size)
 
virtual ~Palette ()
 
void advanceGradient ()
 
- Protected Attributes inherited from Palette
int mRainbowTime
 
Colors mColors
 
CharColors mCharColors
 
std::vector< ColorElem * > mGradVector
 
- Static Protected Attributes inherited from Palette
static const Color RAINBOW_COLORS [7]
 
static const int RAINBOW_COLOR_COUNT = 7
 
static Palettes mInstances
 

Detailed Description

Definition at line 52 of file theme.h.

Member Typedef Documentation

◆ ProgressColors

typedef std::vector<DyePalette*> Theme::ProgressColors
private

Definition at line 201 of file theme.h.

◆ SkinIterator

typedef Skins::iterator Theme::SkinIterator
private

Definition at line 183 of file theme.h.

◆ Skins

typedef std::map<std::string, Skin*> Theme::Skins
private

Definition at line 182 of file theme.h.

Constructor & Destructor Documentation

◆ Theme()

Theme::Theme ( )

Definition at line 77 of file theme.cpp.

References Configuration::addListener(), ThemeColorId::AWAYCHAT, ThemeColorId::AWAYCHAT_OUTLINE, CAST_S32, CAST_SIZE, ThemeColorId::CHAT, ThemeColorId::CHAT_OUTLINE, config, ThemeColorId::GLOBAL, ThemeColorId::GLOBAL_OUTLINE, ThemeColorId::GM, ThemeColorId::GM_OUTLINE, ThemeColorId::GUILD_CHAT_TAB, ThemeColorId::GUILD_CHAT_TAB_OUTLINE, ThemeColorId::HIGHLIGHT, ThemeColorId::HIGHLIGHT_OUTLINE, ThemeColorId::HYPERLINK, ThemeColorId::HYPERLINK_OUTLINE, initDefaultThemePath(), ThemeColorId::IS, ThemeColorId::IS_OUTLINE, ThemeColorId::LOGGER, ThemeColorId::LOGGER_OUTLINE, Palette::mCharColors, Palette::mColors, ThemeColorId::OLDCHAT, ThemeColorId::OLDCHAT_OUTLINE, ThemeColorId::PARTY_CHAT_TAB, ThemeColorId::PARTY_CHAT_TAB_OUTLINE, ThemeColorId::PLAYER, ThemeColorId::PLAYER_OUTLINE, ThemeColorId::SELFNICK, ThemeColorId::SELFNICK_OUTLINE, ThemeColorId::SERVER, ThemeColorId::SERVER_OUTLINE, ThemeColorId::WHISPER_TAB, ThemeColorId::WHISPER_TAB_OFFLINE, ThemeColorId::WHISPER_TAB_OFFLINE_OUTLINE, and ThemeColorId::WHISPER_TAB_OUTLINE.

77  :
79  mSkins(),
80  mMinimumOpacity(-1.0F),
83 {
85 
86  config.addListener("guialpha", this);
87 
120 
121  // here need use outlined colors
122  mCharColors['H' | 0x80]
128  mCharColors['W' | 0x80]
130  mCharColors['w' | 0x80]
133  mCharColors['P' | 0x80]
135  mCharColors['U' | 0x80]
139  mCharColors['<' | 0x80]
144 }
Skins mSkins
Definition: theme.h:185
Configuration config
ProgressColors mProgressColors
Definition: theme.h:202
void addListener(const std::string &key, ConfigListener *const listener)
float mMinimumOpacity
Definition: theme.h:199
std::vector< DyePalette * > ProgressColors
Definition: theme.h:201
#define CAST_S32
Definition: cast.h:29
Colors mColors
Definition: palette.h:153
CharColors mCharColors
Definition: palette.h:154
static void initDefaultThemePath()
Definition: theme.cpp:64
const int THEME_PALETTES
Definition: theme.h:30
#define CAST_SIZE
Definition: cast.h:33
Palette(const int size)
Definition: palette.cpp:51

◆ ~Theme()

Theme::~Theme ( )

Definition at line 146 of file theme.cpp.

References CHECKLISTENERS, config, delete_all(), mProgressColors, mSkins, and Configuration::removeListener().

147 {
149  config.removeListener("guialpha", this);
152 }
Skins mSkins
Definition: theme.h:185
Configuration config
ProgressColors mProgressColors
Definition: theme.h:202
void delete_all(Container &c)
Definition: dtor.h:55
#define CHECKLISTENERS
Definition: localconsts.h:305
void removeListener(const std::string &key, ConfigListener *const listener)

Member Function Documentation

◆ fillFontsList()

void Theme::fillFontsList ( StringVect list)
static

Definition at line 569 of file theme.cpp.

References branding, VirtFs::getFiles(), Configuration::getStringValue(), and VirtFs::permitLinks().

Referenced by FontsModel::FontsModel(), and getThemeName().

570 {
571  VirtFs::permitLinks(true);
572  VirtFs::getFiles(branding.getStringValue("fontsPath"), list);
573  std::sort(list.begin(), list.end());
574  VirtFs::permitLinks(false);
575 }
Configuration branding
std::string getStringValue(const std::string &key) const
void permitLinks(const bool val)
Definition: fs.cpp:802
void getFiles(std::string dirName, StringVect &list)
Definition: fs.cpp:171

◆ fillSkinsList()

void Theme::fillSkinsList ( StringVect list)
static

Definition at line 563 of file theme.cpp.

References branding, VirtFs::getDirs(), and Configuration::getStringValue().

Referenced by getThemeName(), and ThemesModel::ThemesModel().

564 {
565  VirtFs::getDirs(branding.getStringValue("guiThemePath"), list);
566  std::sort(list.begin(), list.end());
567 }
Configuration branding
std::string getStringValue(const std::string &key) const
void getDirs(std::string dirName, StringVect &list)
Definition: fs.cpp:216

◆ fillSoundsList()

void Theme::fillSoundsList ( StringVect list)
static

Definition at line 577 of file theme.cpp.

References branding, VirtFs::enumerateFiles(), findCutLast(), FOR_EACH, VirtFs::freeList(), Configuration::getStringValue(), VirtFs::isDirectory(), VirtFs::List::names, and ServerCommandType::str.

Referenced by getThemeName(), and SoundsModel::SoundsModel().

578 {
579  VirtFs::List *const skins = VirtFs::enumerateFiles(
580  branding.getStringValue("systemsounds"));
581 
582  FOR_EACH (StringVectCIter, i, skins->names)
583  {
585  "systemsounds") + *i)))
586  {
587  std::string str = *i;
588  if (findCutLast(str, ".ogg"))
589  list.push_back(str);
590  }
591  }
592 
593  VirtFs::freeList(skins);
594  std::sort(list.begin(), list.end());
595 }
Configuration branding
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
std::string getStringValue(const std::string &key) const
StringVect::const_iterator StringVectCIter
Definition: stringvector.h:30
void freeList(List *const handle)
Definition: fs.cpp:268
bool isDirectory(std::string name)
Definition: fs.cpp:238
bool findCutLast(std::string &str1, const std::string &str2)
StringVect names
Definition: list.h:39
List * enumerateFiles(std::string dirName)
Definition: fs.cpp:146

◆ getColor()

const Color& Theme::getColor ( ThemeColorIdT  type,
const unsigned int  alpha 
)
inline

Gets the color associated with the type. Sets the alpha channel before returning.

Parameters
typethe color type requested
alphaalpha channel to use
Returns
the requested color

Definition at line 135 of file theme.h.

References Color::a, A_WARN_UNUSED, ThemeColorId::BROWSERBOX, CAST_S32, CAST_SIZE, CAST_U32, getIdByChar(), getImageFromThemeXml(), loadInfo(), loadRect(), Logger::log(), logger, Palette::mColors, optionChanged(), readSkin(), setMinimumOpacity(), unloadRect(), and anonymous_namespace{libxml.cpp}::valid.

Referenced by Game::addWatermark(), TextParticle::draw(), Being::drawSpeech(), TouchManager::drawText(), Widget2::getThemeCharColor(), Widget2::getThemeColor(), LocalPlayer::LocalPlayer(), Being::setSpeech(), and Being::updateColors().

137  {
138  if (CAST_SIZE(type) >= mColors.size())
139  {
140  logger->log("incorrect color request type: %d from %u",
141  CAST_S32(type),
142  CAST_U32(mColors.size()));
144  }
145  Color *const col = &mColors[CAST_SIZE(type)].color;
146  col->a = alpha;
147  return *col;
148  }
#define CAST_U32
Definition: cast.h:30
unsigned int a
Definition: color.h:250
Logger * logger
Definition: logger.cpp:95
#define CAST_S32
Definition: cast.h:29
Colors mColors
Definition: palette.h:153
Definition: color.h:74
#define CAST_SIZE
Definition: cast.h:33
void log(const char *const log_text,...)
Definition: logger.cpp:243

◆ getIdByChar()

ThemeColorIdT Theme::getIdByChar ( const signed char  c,
bool valid 
) const

Definition at line 1284 of file theme.cpp.

References ThemeColorId::BROWSERBOX, and Palette::mCharColors.

Referenced by getColor(), and Widget2::getThemeCharColor().

1285 {
1286  const CharColors::const_iterator it = mCharColors.find(c);
1287  if (it != mCharColors.end())
1288  {
1289  valid = true;
1290  return static_cast<ThemeColorIdT>((*it).second);
1291  }
1292 
1293  valid = false;
1294  return ThemeColorId::BROWSERBOX;
1295 }
ThemeColorId ::T ThemeColorIdT
Definition: themecolorid.h:256
CharColors mCharColors
Definition: palette.h:154

◆ getImageFromTheme()

Image * Theme::getImageFromTheme ( const std::string &  path)
static

◆ getImageFromThemeXml()

Image * Theme::getImageFromThemeXml ( const std::string &  name,
const std::string &  name2 
)
static

Definition at line 1135 of file theme.cpp.

References Skin::getBorder(), getThemePath(), ImageRect::grid, Resource::incRef(), load(), and unload().

Referenced by AvatarListBox::AvatarListBox(), getColor(), Button::loadImage(), TouchManager::loadTouchItem(), ItemContainer::setCellBackgroundImage(), Window::setResizable(), and ShortcutContainer::ShortcutContainer().

1137 {
1138  if (theme == nullptr)
1139  return nullptr;
1140 
1141  Skin *const skin = theme->load(name,
1142  name2,
1143  false,
1145  if (skin != nullptr)
1146  {
1147  const ImageRect &rect = skin->getBorder();
1148  if (rect.grid[0] != nullptr)
1149  {
1150  Image *const image = rect.grid[0];
1151  image->incRef();
1152  theme->unload(skin);
1153  return image;
1154  }
1155  theme->unload(skin);
1156  }
1157  return nullptr;
1158 }
Definition: skin.h:35
void unload(Skin *const skin)
Definition: theme.cpp:249
static std::string getThemePath()
Definition: theme.h:66
Skin * load(const std::string &filename, const std::string &filename2, const bool full, const std::string &defaultPath)
Definition: theme.cpp:178
const ImageRect & getBorder() const
Definition: skin.h:67
Image * grid[9]
Definition: imagerect.h:41
virtual void incRef()
Definition: resource.cpp:37
Theme * theme
Definition: theme.cpp:61
Definition: image.h:61

◆ getImageSetFromTheme()

ImageSet * Theme::getImageSetFromTheme ( const std::string &  path,
const int  w,
const int  h 
)
static

Definition at line 659 of file theme.cpp.

References Loader::getImageSet(), and resolveThemePath().

Referenced by EquipmentWindow::fillBoxes(), EquipmentWindow::fillDefault(), getThemeName(), Button::loadImageSet(), ProgressIndicator::ProgressIndicator(), and Gui::setUseCustomCursor().

661 {
662  return Loader::getImageSet(resolveThemePath(path), w, h);
663 }
ImageSet * getImageSet(const std::string &imagePath, const int w, const int h)
static std::string resolveThemePath(const std::string &path)
Definition: theme.cpp:626

◆ getImageSetFromThemeXml()

ImageSet * Theme::getImageSetFromThemeXml ( const std::string &  name,
const std::string &  name2,
const int  w,
const int  h 
)
static

Definition at line 1160 of file theme.cpp.

References Skin::getBorder(), Loader::getSubImageSet(), getThemePath(), ImageRect::grid, load(), Image::mBounds, and unload().

Referenced by getThemeName().

1163 {
1164  if (theme == nullptr)
1165  return nullptr;
1166 
1167  Skin *const skin = theme->load(name,
1168  name2,
1169  false,
1171  if (skin != nullptr)
1172  {
1173  const ImageRect &rect = skin->getBorder();
1174  if (rect.grid[0] != nullptr)
1175  {
1176  Image *const image = rect.grid[0];
1177  const SDL_Rect &rect2 = image->mBounds;
1178  if ((rect2.w != 0u) && (rect2.h != 0u))
1179  {
1180  ImageSet *const imageSet = Loader::getSubImageSet(
1181  image, w, h);
1182  theme->unload(skin);
1183  return imageSet;
1184  }
1185  }
1186  theme->unload(skin);
1187  }
1188  return nullptr;
1189 }
Definition: skin.h:35
void unload(Skin *const skin)
Definition: theme.cpp:249
static std::string getThemePath()
Definition: theme.h:66
Skin * load(const std::string &filename, const std::string &filename2, const bool full, const std::string &defaultPath)
Definition: theme.cpp:178
const ImageRect & getBorder() const
Definition: skin.h:67
Image * grid[9]
Definition: imagerect.h:41
ImageSet * getSubImageSet(Image *const parent, const int width, const int height)
Theme * theme
Definition: theme.cpp:61
Definition: image.h:61
SDL_Rect mBounds
Definition: image.h:210

◆ getMinimumOpacity()

float Theme::getMinimumOpacity ( ) const
inline

◆ getProgressColor()

Color Theme::getProgressColor ( const ProgressColorIdT  type,
const float  progress 
)
static

Definition at line 154 of file theme.cpp.

References CAST_S32, CAST_SIZE, ServerCommandType::dye, DyePalette::getColor(), Logger::log(), logger, mProgressColors, and Catch::toString().

Referenced by AvatarListBox::draw(), getThemeName(), ProgressBar::ProgressBar(), AvatarListBox::safeDraw(), ProgressBar::setProgress(), and ProgressBar::setProgressPalette().

156 {
157  int color[3] = {0, 0, 0};
158 
159  if (theme != nullptr)
160  {
161  const DyePalette *const dye
162  = theme->mProgressColors[CAST_SIZE(type)];
163 
164  if (dye != nullptr)
165  {
166  dye->getColor(progress, color);
167  }
168  else
169  {
170  logger->log("color not found: "
171  + toString(CAST_S32(type)));
172  }
173  }
174 
175  return Color(color[0], color[1], color[2], 255U);
176 }
ProgressColors mProgressColors
Definition: theme.h:202
Logger * logger
Definition: logger.cpp:95
#define CAST_S32
Definition: cast.h:29
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
Theme * theme
Definition: theme.cpp:61
void getColor(const unsigned int intensity, unsigned int(&color)[3]) const
Definition: dyepalette.cpp:151
Definition: color.h:74
#define CAST_SIZE
Definition: cast.h:33
void log(const char *const log_text,...)
Definition: logger.cpp:243

◆ getThemeName()

static std::string Theme::getThemeName ( )
inlinestatic

◆ getThemePath()

static std::string Theme::getThemePath ( )
inlinestatic

◆ load()

Skin * Theme::load ( const std::string &  filename,
const std::string &  filename2,
const bool  full,
const std::string &  defaultPath 
)

Loads a skin.

Definition at line 178 of file theme.cpp.

References findCutLast(), Logger::log(), logger, mScreenDensity, mSkins, readSkin(), and strprintf().

Referenced by anonymous_namespace{client.cpp}::LoginListener::action(), BrowserBox::BrowserBox(), CheckBox::CheckBox(), Desktop::Desktop(), DropDown::DropDown(), Client::gameInit(), getImageFromThemeXml(), getImageSetFromThemeXml(), getThemeName(), Label::init(), Tab::init(), Button::init(), ScrollArea::init(), ListBox::ListBox(), TouchManager::loadButtons(), loadRect(), loadSkinRect(), Popup::Popup(), ProgressBar::ProgressBar(), RadioButton::RadioButton(), SkillRectangleListBox::SkillRectangleListBox(), StaticBrowserBox::StaticBrowserBox(), TestLauncher::testDraw(), TextPreview::TextPreview(), and Window::Window().

182 {
183  // Check if this skin was already loaded
184 
185  const SkinIterator skinIterator = mSkins.find(filename);
186  if (mSkins.end() != skinIterator)
187  {
188  if (skinIterator->second != nullptr)
189  skinIterator->second->instances++;
190  return skinIterator->second;
191  }
192 
193  Skin *skin = nullptr;
194  if (mScreenDensity.empty())
195  { // if no density detected
196  skin = readSkin(filename, full);
197  if ((skin == nullptr) && !filename2.empty() && filename2 != filename)
198  skin = readSkin(filename2, full);
199  if ((skin == nullptr) && filename2 != "window.xml")
200  skin = readSkin("window.xml", full);
201  }
202  else
203  { // first use correct density images
204  const std::string endStr("_" + mScreenDensity + ".xml");
205  std::string name = filename;
206  if (findCutLast(name, ".xml"))
207  skin = readSkin(name + endStr, full);
208  if (skin == nullptr)
209  skin = readSkin(filename, full);
210  if ((skin == nullptr) && !filename2.empty() && filename2 != filename)
211  {
212  name = filename2;
213  if (findCutLast(name, ".xml"))
214  skin = readSkin(name + endStr, full);
215  if (skin == nullptr)
216  skin = readSkin(filename2, full);
217  }
218  if ((skin == nullptr) && filename2 != "window.xml")
219  {
220  skin = readSkin("window" + endStr, full);
221  if (skin == nullptr)
222  skin = readSkin("window.xml", full);
223  }
224  }
225 
226  if (skin == nullptr)
227  {
228  // Try falling back on the defaultPath if this makes sense
229  if (filename != defaultPath)
230  {
231  logger->log("Error loading skin '%s', falling back on default.",
232  filename.c_str());
233 
234  skin = readSkin(defaultPath, full);
235  }
236 
237  if (skin == nullptr)
238  {
239  logger->log(strprintf("Error: Loading default skin '%s' failed. "
240  "Make sure the skin file is valid.",
241  defaultPath.c_str()));
242  }
243  }
244 
245  mSkins[filename] = skin;
246  return skin;
247 }
Definition: skin.h:35
Skins mSkins
Definition: theme.h:185
Skins::iterator SkinIterator
Definition: theme.h:183
Logger * logger
Definition: logger.cpp:95
bool findCutLast(std::string &str1, const std::string &str2)
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
static std::string mScreenDensity
Definition: theme.h:189
Skin * readSkin(const std::string &filename0, const bool full)
Definition: theme.cpp:393
void log(const char *const log_text,...)
Definition: logger.cpp:243

◆ loadColors()

void Theme::loadColors ( std::string  file)
private

Definition at line 1000 of file theme.cpp.

References CAST_S32, CAST_SIZE, Resource::decRef(), findLast(), for_each_xml_child_node, XML::getProperty(), Loader::getXml(), Logger::log(), logger, Palette::mColors, mProgressColors, pathJoin(), readColor(), readColorGradient(), readColorType(), readProgressType(), resolveThemePath(), XML::Document::rootNode(), SkipError_false, ThemeColorId::THEME_COLORS_END, THEME_PALETTES, and UseVirtFs_true.

Referenced by prepareThemePath(), and tryThemePath().

1001 {
1002  if (file.empty())
1003  file = "colors.xml";
1004  else
1005  file = pathJoin(file, "colors.xml");
1006 
1007  XML::Document *const doc = Loader::getXml(resolveThemePath(file),
1009  SkipError_false);
1010  if (doc == nullptr)
1011  return;
1012  XmlNodeConstPtrConst root = doc->rootNode();
1013 
1014  if ((root == nullptr) || !xmlNameEqual(root, "colors"))
1015  {
1016  logger->log("Error loading colors file: %s", file.c_str());
1017  doc->decRef();
1018  return;
1019  }
1020 
1021  logger->log("Loading colors file: %s", file.c_str());
1022 
1023  for_each_xml_child_node(paletteNode, root)
1024  {
1025  if (xmlNameEqual(paletteNode, "progressbar"))
1026  {
1027  const int type = readProgressType(XML::getProperty(
1028  paletteNode, "id", ""));
1029  if (type < 0)
1030  continue;
1031 
1033  paletteNode, "color", ""), 6);
1034  }
1035  else if (!xmlNameEqual(paletteNode, "palette"))
1036  {
1037  continue;
1038  }
1039 
1040  const int paletteId = XML::getProperty(paletteNode, "id", 1);
1041  if (paletteId < 0 || paletteId >= THEME_PALETTES)
1042  continue;
1043 
1044  for_each_xml_child_node(node, paletteNode)
1045  {
1046  if (xmlNameEqual(node, "color"))
1047  {
1048  const std::string id = XML::getProperty(node, "id", "");
1049  const int type = readColorType(id);
1050  if (type < 0)
1051  continue;
1052 
1053  const std::string temp = XML::getProperty(node, "color", "");
1054  if (temp.empty())
1055  continue;
1056 
1057  const Color color = readColor(temp);
1058  const GradientTypeT grad = readColorGradient(
1059  XML::getProperty(node, "effect", ""));
1060  mColors[paletteId * CAST_SIZE(
1061  ThemeColorId::THEME_COLORS_END) + type].set(
1062  type, color, grad, 10);
1063 
1064  if (!findLast(id, "_OUTLINE"))
1065  {
1066  const int type2 = readColorType(id + "_OUTLINE");
1067  if (type2 < 0)
1068  continue;
1069  const int idx = paletteId
1071  mColors[idx + type2] = mColors[idx + type];
1072  }
1073  }
1074  }
1075  }
1076  doc->decRef();
1077 }
const bool SkipError_false
Definition: skiperror.h:29
static int readProgressType(const std::string &type)
Definition: theme.cpp:969
virtual void decRef()
Definition: resource.cpp:49
GradientType ::T GradientTypeT
Definition: gradienttype.h:37
std::string pathJoin(std::string str1, const std::string &str2)
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition: libxml.cpp:171
static GradientTypeT readColorGradient(const std::string &grad)
Definition: theme.cpp:947
ProgressColors mProgressColors
Definition: theme.h:202
Logger * logger
Definition: logger.cpp:95
bool findLast(const std::string &str1, const std::string &str2)
const bool UseVirtFs_true
Definition: usevirtfs.h:29
#define CAST_S32
Definition: cast.h:29
static Color readColor(const std::string &description)
Definition: theme.cpp:906
Colors mColors
Definition: palette.h:153
XML::Document * getXml(const std::string &idPath, const UseVirtFs useResman, const SkipError skipError)
Definition: xmlloader.cpp:55
xmlNodePtr rootNode()
Definition: libxml.cpp:166
static int readColorType(const std::string &type)
Definition: theme.cpp:665
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:160
Definition: color.h:74
const int THEME_PALETTES
Definition: theme.h:30
#define CAST_SIZE
Definition: cast.h:33
void log(const char *const log_text,...)
Definition: logger.cpp:243
static std::string resolveThemePath(const std::string &path)
Definition: theme.cpp:626

◆ loadInfo()

ThemeInfo * Theme::loadInfo ( const std::string &  themeName)
static

Definition at line 1215 of file theme.cpp.

References boldFont, Resource::decRef(), defaultThemePath, ServerCommandType::font, for_each_xml_child_node, Loader::getXml(), Actions::info(), Logger::log(), logger, mScreenDensity, pathJoin(), readFloatValue, readIntValue, readValue, XML::Document::rootNode(), SkipError_false, and UseVirtFs_true.

Referenced by getColor(), and Setup_Theme::updateInfo().

1216 {
1217  std::string path;
1218  if (themeName.empty())
1219  {
1220  path = "graphics/gui/info.xml";
1221  }
1222  else
1223  {
1224  path = pathJoin(defaultThemePath,
1225  themeName,
1226  "info.xml");
1227  }
1228  logger->log("loading: " + path);
1229  XML::Document *const doc = Loader::getXml(path,
1231  SkipError_false);
1232  if (doc == nullptr)
1233  return nullptr;
1234  XmlNodeConstPtrConst rootNode = doc->rootNode();
1235 
1236  if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "info"))
1237  {
1238  doc->decRef();
1239  return nullptr;
1240  }
1241 
1242  ThemeInfo *const info = new ThemeInfo;
1243 
1244  const std::string fontSize2("fontSize_" + mScreenDensity);
1245  const std::string npcfontSize2("npcfontSize_" + mScreenDensity);
1246  XmlChar *tmpData = nullptr;
1247  for_each_xml_child_node(infoNode, rootNode)
1248  {
1249  if (xmlNameEqual(infoNode, "name"))
1250  readValue(name)
1251  else if (xmlNameEqual(infoNode, "copyright"))
1252  readValue(copyright)
1253  else if (xmlNameEqual(infoNode, "font"))
1254  readValue(font)
1255  else if (xmlNameEqual(infoNode, "boldFont"))
1257  else if (xmlNameEqual(infoNode, "particleFont"))
1258  readValue(particleFont)
1259  else if (xmlNameEqual(infoNode, "helpFont"))
1260  readValue(helpFont)
1261  else if (xmlNameEqual(infoNode, "secureFont"))
1262  readValue(secureFont)
1263  else if (xmlNameEqual(infoNode, "npcFont"))
1264  readValue(npcFont)
1265  else if (xmlNameEqual(infoNode, "japanFont"))
1266  readValue(japanFont)
1267  else if (xmlNameEqual(infoNode, "chinaFont"))
1268  readValue(chinaFont)
1269  else if (xmlNameEqual(infoNode, "fontSize"))
1270  readIntValue(fontSize)
1271  else if (xmlNameEqual(infoNode, "npcfontSize"))
1272  readIntValue(npcfontSize)
1273  else if (xmlNameEqual(infoNode, "guialpha"))
1274  readFloatValue(guiAlpha)
1275  else if (xmlNameEqual(infoNode, fontSize2.c_str()))
1276  readIntValue(fontSize)
1277  else if (xmlNameEqual(infoNode, npcfontSize2.c_str()))
1278  readIntValue(npcfontSize)
1279  }
1280  doc->decRef();
1281  return info;
1282 }
const bool SkipError_false
Definition: skiperror.h:29
Font * boldFont
Definition: gui.cpp:111
virtual void decRef()
Definition: resource.cpp:49
std::string pathJoin(std::string str1, const std::string &str2)
#define readFloatValue(name)
Definition: theme.cpp:1207
Logger * logger
Definition: logger.cpp:95
const bool UseVirtFs_true
Definition: usevirtfs.h:29
#define readIntValue(name)
Definition: theme.cpp:1199
bool info(InputEvent &event)
Definition: commands.cpp:56
XML::Document * getXml(const std::string &idPath, const UseVirtFs useResman, const SkipError skipError)
Definition: xmlloader.cpp:55
xmlNodePtr rootNode()
Definition: libxml.cpp:166
static std::string mScreenDensity
Definition: theme.h:189
static std::string defaultThemePath
Definition: theme.cpp:55
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:160
#define readValue(name)
Definition: theme.cpp:1191
void log(const char *const log_text,...)
Definition: logger.cpp:243

◆ loadRect()

void Theme::loadRect ( ImageRect image,
const std::string &  name,
const std::string &  name2,
const int  start,
const int  end 
)

Definition at line 1092 of file theme.cpp.

References getThemePath(), load(), loadGrid, and unload().

Referenced by DropDown::DropDown(), getColor(), Slider::init(), ScrollArea::init(), EquipmentWindow::postInit(), ProgressBar::ProgressBar(), and Text::Text().

1097 {
1098  Skin *const skin = load(name,
1099  name2,
1100  false,
1102  if (skin != nullptr)
1103  {
1104  loadGrid();
1105  unload(skin);
1106  }
1107 }
Definition: skin.h:35
void unload(Skin *const skin)
Definition: theme.cpp:249
static std::string getThemePath()
Definition: theme.h:66
Skin * load(const std::string &filename, const std::string &filename2, const bool full, const std::string &defaultPath)
Definition: theme.cpp:178
#define loadGrid()
Definition: theme.cpp:1079

◆ loadSkinRect()

Skin * Theme::loadSkinRect ( ImageRect image,
const std::string &  name,
const std::string &  name2,
const int  start,
const int  end 
)

Definition at line 1109 of file theme.cpp.

References getThemePath(), load(), and loadGrid.

Referenced by getThemeName(), PlayerBox::init(), TouchManager::loadTouchItem(), and TextField::TextField().

1114 {
1115  Skin *const skin = load(name,
1116  name2,
1117  true,
1119  if (skin != nullptr)
1120  loadGrid();
1121  return skin;
1122 }
Definition: skin.h:35
static std::string getThemePath()
Definition: theme.h:66
Skin * load(const std::string &filename, const std::string &filename2, const bool full, const std::string &defaultPath)
Definition: theme.cpp:178
#define loadGrid()
Definition: theme.cpp:1079

◆ optionChanged()

void Theme::optionChanged ( const std::string &  name)
virtual

Called when an option changed. The config listener will have to be registered to the option name first.

Implements ConfigListener.

Definition at line 290 of file theme.cpp.

References updateAlpha().

Referenced by getColor().

291 {
292  updateAlpha();
293 }
void updateAlpha()
Definition: theme.cpp:280

◆ prepareThemePath()

void Theme::prepareThemePath ( )
static

Definition at line 603 of file theme.cpp.

References branding, config, Configuration::getStringValue(), initDefaultThemePath(), loadColors(), Logger::log(), logger, mThemeName, mThemePath, and tryThemePath().

Referenced by selectSkin().

604 {
606 
607  mThemePath.clear();
608  mThemeName.clear();
609 
610  // Try theme from settings
611  if (tryThemePath(config.getStringValue("theme")))
612  return;
613 
614  // Try theme from branding
615  if (tryThemePath(branding.getStringValue("theme")))
616  return;
617 
618  if (mThemePath.empty())
619  mThemePath = "graphics/gui";
620 
622 
623  logger->log("Selected Theme: " + mThemePath);
624 }
Configuration branding
std::string getStringValue(const std::string &key) const
Configuration config
static std::string mThemePath
Definition: theme.h:187
Logger * logger
Definition: logger.cpp:95
static bool tryThemePath(const std::string &themePath)
Definition: theme.cpp:545
Theme * theme
Definition: theme.cpp:61
static std::string mThemeName
Definition: theme.h:188
static void initDefaultThemePath()
Definition: theme.cpp:64
void log(const char *const log_text,...)
Definition: logger.cpp:243
void loadColors(std::string file)
Definition: theme.cpp:1000

◆ readSkin()

Skin * Theme::readSkin ( const std::string &  filename0,
const bool  full 
)
private

Definition at line 393 of file theme.cpp.

References Resource::decRef(), Image::decRef(), VirtFs::exists(), for_each_xml_child_node, getImageFromTheme(), XML::getProperty(), Loader::getXml(), SkinHelper::height, SkinHelper::image, SkinHelper::loadList(), Logger::log(), Logger::log1(), logger, mMinimumOpacity, anonymous_namespace{itemoptiondb.cpp}::mOptions, SkinHelper::partType, SkinHelper::rect, resolveThemePath(), XML::Document::rootNode(), skinParam, SkipError_true, Skin::updateAlpha(), UseVirtFs_true, SkinHelper::width, SkinHelper::xPos, and SkinHelper::yPos.

Referenced by getColor(), and load().

394 {
395  if (filename.empty())
396  return nullptr;
397 
398  const std::string path = resolveThemePath(filename);
399  if (!VirtFs::exists(path))
400  return nullptr;
401  XML::Document *const doc = Loader::getXml(path,
404  if (doc == nullptr)
405  return nullptr;
406  XmlNodeConstPtr rootNode = doc->rootNode();
407  if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "skinset"))
408  {
409  doc->decRef();
410  return nullptr;
411  }
412 
413  const std::string skinSetImage = XML::getProperty(rootNode, "image", "");
414 
415  if (skinSetImage.empty())
416  {
417  logger->log1("Theme::readSkin(): Skinset does not define an image!");
418  doc->decRef();
419  return nullptr;
420  }
421 
422  Image *const dBorders = Theme::getImageFromTheme(skinSetImage);
423  ImageRect *const border = new ImageRect;
424  ImageRect *const images = new ImageRect;
425  int padding = 3;
426  int titlePadding = 4;
427  int titlebarHeight = 0;
428  int titlebarHeightRelative = 0;
429  int closePadding = 3;
430  int stickySpacing = 3;
431  int stickyPadding = 3;
432  int resizePadding = 2;
433  StringIntMap *const mOptions = new StringIntMap;
434 
435  // iterate <widget>'s
436  for_each_xml_child_node(widgetNode, rootNode)
437  {
438  if (!xmlNameEqual(widgetNode, "widget"))
439  continue;
440 
441  const std::string widgetType =
442  XML::getProperty(widgetNode, "type", "unknown");
443  if (widgetType == "Window")
444  {
445  SkinHelper helper;
446  const int globalXPos = XML::getProperty(widgetNode, "xpos", 0);
447  const int globalYPos = XML::getProperty(widgetNode, "ypos", 0);
448  for_each_xml_child_node(partNode, widgetNode)
449  {
450  if (xmlNameEqual(partNode, "part"))
451  {
452  helper.partType = XML::getProperty(
453  partNode, "type", "unknown");
454  helper.xPos = XML::getProperty(
455  partNode, "xpos", 0) + globalXPos;
456  helper.yPos = XML::getProperty(
457  partNode, "ypos", 0) + globalYPos;
458  helper.width = XML::getProperty(partNode, "width", 0);
459  helper.height = XML::getProperty(partNode, "height", 0);
460  if ((helper.width == 0) || (helper.height == 0))
461  continue;
462  helper.image = dBorders;
463 
464  helper.rect = border;
465  if (!helper.loadList(skinParam,
466  sizeof(skinParam) / sizeof(SkinParameter)))
467  {
468  helper.rect = images;
469  helper.loadList(imageParam,
470  sizeof(imageParam) / sizeof(SkinParameter));
471  }
472  }
473  else if (full && xmlNameEqual(partNode, "option"))
474  {
475  const std::string name = XML::getProperty(
476  partNode, "name", "");
477  if (name == "padding")
478  {
479  padding = XML::getProperty(partNode, "value", 3);
480  }
481  else if (name == "titlePadding")
482  {
483  titlePadding = XML::getProperty(partNode, "value", 4);
484  }
485  else if (name == "closePadding")
486  {
487  closePadding = XML::getProperty(partNode, "value", 3);
488  }
489  else if (name == "stickySpacing")
490  {
491  stickySpacing = XML::getProperty(partNode, "value", 3);
492  }
493  else if (name == "stickyPadding")
494  {
495  stickyPadding = XML::getProperty(partNode, "value", 3);
496  }
497  else if (name == "titlebarHeight")
498  {
499  titlebarHeight = XML::getProperty(
500  partNode, "value", 0);
501  }
502  else if (name == "titlebarHeightRelative")
503  {
504  titlebarHeightRelative = XML::getProperty(
505  partNode, "value", 0);
506  }
507  else if (name == "resizePadding")
508  {
509  resizePadding = XML::getProperty(
510  partNode, "value", 2);
511  }
512  else
513  {
514  (*mOptions)[name] = XML::getProperty(
515  partNode, "value", 0);
516  }
517  }
518  }
519  }
520  else
521  {
522  logger->log("Theme::readSkin(): Unknown widget type '%s'",
523  widgetType.c_str());
524  }
525  }
526 
527  if (dBorders != nullptr)
528  dBorders->decRef();
529 
530  (*mOptions)["closePadding"] = closePadding;
531  (*mOptions)["stickyPadding"] = stickyPadding;
532  (*mOptions)["stickySpacing"] = stickySpacing;
533  (*mOptions)["titlebarHeight"] = titlebarHeight;
534  (*mOptions)["titlebarHeightRelative"] = titlebarHeightRelative;
535  (*mOptions)["resizePadding"] = resizePadding;
536 
537  Skin *const skin = new Skin(border, images, filename, "", padding,
538  titlePadding, mOptions);
539  delete images;
541  doc->decRef();
542  return skin;
543 }
ItemOptionDb::OptionInfos mOptions
void log1(const char *const log_text)
Definition: logger.cpp:222
std::map< std::string, int > StringIntMap
Definition: stringmap.h:27
Definition: skin.h:35
virtual void decRef()
Definition: resource.cpp:49
std::string partType
Definition: theme.cpp:365
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition: libxml.cpp:171
ImageRect * rect
Definition: theme.cpp:370
Logger * logger
Definition: logger.cpp:95
int xPos
Definition: theme.cpp:366
float mMinimumOpacity
Definition: theme.h:199
const bool UseVirtFs_true
Definition: usevirtfs.h:29
static Image * getImageFromTheme(const std::string &path)
Definition: theme.cpp:654
int height
Definition: theme.cpp:369
XML::Document * getXml(const std::string &idPath, const UseVirtFs useResman, const SkipError skipError)
Definition: xmlloader.cpp:55
xmlNodePtr rootNode()
Definition: libxml.cpp:166
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:160
bool exists(std::string name)
Definition: fs.cpp:123
Definition: image.h:61
int yPos
Definition: theme.cpp:367
bool loadList(const SkinParameter *const params, const size_t size)
Definition: theme.cpp:374
int width
Definition: theme.cpp:368
void log(const char *const log_text,...)
Definition: logger.cpp:243
const bool SkipError_true
Definition: skiperror.h:29
void decRef()
Definition: image.cpp:521
void updateAlpha(const float minimumOpacityAllowed)
Definition: skin.cpp:103
static const SkinParameter imageParam[]
Definition: theme.cpp:341
static std::string resolveThemePath(const std::string &path)
Definition: theme.cpp:626
Image * image
Definition: theme.cpp:372
static const SkinParameter skinParam[]
Definition: theme.cpp:302

◆ resolveThemePath()

std::string Theme::resolveThemePath ( const std::string &  path)
static

Returns the patch to the given gui resource relative to the theme or, if it isn't in the theme, relative to 'graphics/gui'.

Definition at line 626 of file theme.cpp.

References branding, CAST_S32, VirtFs::exists(), Configuration::getStringValue(), getThemePath(), and pathJoin().

Referenced by getImageFromTheme(), getImageSetFromTheme(), getThemeName(), ActorSprite::initTargetCursor(), loadColors(), and readSkin().

627 {
628  // Need to strip off any dye info for the existence tests
629  const int pos = CAST_S32(path.find('|'));
630  std::string file;
631  if (pos > 0)
632  file = path.substr(0, pos);
633  else
634  file = path;
635 
636  // File with path
637  if (file.find('/') != std::string::npos)
638  {
639  // Might be a valid path already
640  if (VirtFs::exists(file))
641  return path;
642  }
643 
644  // Try the theme
645  file = pathJoin(getThemePath(), file);
646 
647  if (VirtFs::exists(file))
648  return pathJoin(getThemePath(), path);
649 
650  // Backup
651  return pathJoin(branding.getStringValue("guiPath"), path);
652 }
Configuration branding
std::string getStringValue(const std::string &key) const
std::string pathJoin(std::string str1, const std::string &str2)
static std::string getThemePath()
Definition: theme.h:66
#define CAST_S32
Definition: cast.h:29
bool exists(std::string name)
Definition: fs.cpp:123

◆ selectSkin()

void Theme::selectSkin ( )
static

Definition at line 597 of file theme.cpp.

References GraphicsManager::getDensityString(), graphicsManager, mScreenDensity, and prepareThemePath().

Referenced by anonymous_namespace{client.cpp}::LoginListener::action(), and Client::gameInit().

598 {
601 }
static void prepareThemePath()
Definition: theme.cpp:603
static std::string mScreenDensity
Definition: theme.h:189
GraphicsManager graphicsManager
std::string getDensityString() const

◆ setMinimumOpacity()

void Theme::setMinimumOpacity ( const float  minimumOpacity)

Set the minimum opacity allowed to skins. Set a negative value to free the minimum allowed.

Definition at line 271 of file theme.cpp.

References mMinimumOpacity, and updateAlpha().

Referenced by getColor(), and Client::stateSwitchLogin1().

272 {
273  if (minimumOpacity > 1.0F)
274  return;
275 
276  mMinimumOpacity = minimumOpacity;
277  updateAlpha();
278 }
float mMinimumOpacity
Definition: theme.h:199
void updateAlpha()
Definition: theme.cpp:280

◆ tryThemePath()

bool Theme::tryThemePath ( const std::string &  themePath)
staticprivate

Definition at line 545 of file theme.cpp.

References defaultThemePath, VirtFs::exists(), loadColors(), mThemeName, and mThemePath.

Referenced by prepareThemePath().

546 {
547  if (!themeName.empty())
548  {
549  const std::string path = defaultThemePath + themeName;
550  if (VirtFs::exists(path))
551  {
552  mThemePath = path;
553  mThemeName = themeName;
554  if (theme != nullptr)
555  theme->loadColors("");
556  return true;
557  }
558  }
559 
560  return false;
561 }
static std::string mThemePath
Definition: theme.h:187
static std::string defaultThemePath
Definition: theme.cpp:55
Theme * theme
Definition: theme.cpp:61
bool exists(std::string name)
Definition: fs.cpp:123
static std::string mThemeName
Definition: theme.h:188
void loadColors(std::string file)
Definition: theme.cpp:1000

◆ unload()

void Theme::unload ( Skin *const  skin)

Definition at line 249 of file theme.cpp.

References Skin::instances, and mSkins.

Referenced by DropDown::DropDown(), getImageFromThemeXml(), getImageSetFromThemeXml(), getThemeName(), ScrollArea::init(), TouchManager::loadButtons(), loadRect(), TouchManager::loadTouchItem(), BrowserBox::~BrowserBox(), Button::~Button(), CheckBox::~CheckBox(), Desktop::~Desktop(), DropDown::~DropDown(), ItemContainer::~ItemContainer(), Label::~Label(), ListBox::~ListBox(), Popup::~Popup(), ProgressBar::~ProgressBar(), RadioButton::~RadioButton(), StaticBrowserBox::~StaticBrowserBox(), Tab::~Tab(), TextField::~TextField(), TextPreview::~TextPreview(), Window::~Window(), and WindowMenu::~WindowMenu().

250 {
251  if (skin == nullptr)
252  return;
253  skin->instances --;
254  if (skin->instances == 0)
255  {
256  SkinIterator it = mSkins.begin();
257  const SkinIterator it_end = mSkins.end();
258  while (it != it_end)
259  {
260  if (it->second == skin)
261  {
262  mSkins.erase(it);
263  break;
264  }
265  ++ it;
266  }
267  delete skin;
268  }
269 }
Skins mSkins
Definition: theme.h:185
Skins::iterator SkinIterator
Definition: theme.h:183
int instances
Definition: skin.h:120

◆ unloadRect()

void Theme::unloadRect ( const ImageRect rect,
const int  start,
const int  end 
)
static

Definition at line 1124 of file theme.cpp.

References Image::decRef(), and ImageRect::grid.

Referenced by getColor(), TouchManager::unload(), DropDown::~DropDown(), PlayerBox::~PlayerBox(), ProgressBar::~ProgressBar(), ScrollArea::~ScrollArea(), Slider::~Slider(), and TextField::~TextField().

1127 {
1128  for (int f = start; f <= end; f ++)
1129  {
1130  if (rect.grid[f] != nullptr)
1131  rect.grid[f]->decRef();
1132  }
1133 }
Image * grid[9]
Definition: imagerect.h:41
void decRef()
Definition: image.cpp:521

◆ updateAlpha()

void Theme::updateAlpha ( )

Updates the alpha values of all of the skins.

Definition at line 280 of file theme.cpp.

References FOR_EACH, mMinimumOpacity, mSkins, and Skin::updateAlpha().

Referenced by getThemeName(), optionChanged(), and setMinimumOpacity().

281 {
282  FOR_EACH (SkinIterator, iter, mSkins)
283  {
284  Skin *const skin = iter->second;
285  if (skin != nullptr)
287  }
288 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
Definition: skin.h:35
Skins mSkins
Definition: theme.h:185
Skins::iterator SkinIterator
Definition: theme.h:183
float mMinimumOpacity
Definition: theme.h:199
void updateAlpha(const float minimumOpacityAllowed)
Definition: skin.cpp:103

Field Documentation

◆ mMinimumOpacity

float Theme::mMinimumOpacity
private

Tells if the current skins opacity should not get less than the given value

Definition at line 199 of file theme.h.

Referenced by getMinimumOpacity(), readSkin(), setMinimumOpacity(), and updateAlpha().

◆ mProgressColors

ProgressColors Theme::mProgressColors
private

Definition at line 202 of file theme.h.

Referenced by getProgressColor(), loadColors(), and ~Theme().

◆ mScreenDensity

std::string Theme::mScreenDensity
staticprivate

Definition at line 189 of file theme.h.

Referenced by load(), loadInfo(), and selectSkin().

◆ mSkins

Skins Theme::mSkins
private

Definition at line 185 of file theme.h.

Referenced by load(), unload(), updateAlpha(), and ~Theme().

◆ mThemeName

std::string Theme::mThemeName
staticprivate

Definition at line 188 of file theme.h.

Referenced by getThemeName(), prepareThemePath(), and tryThemePath().

◆ mThemePath

std::string Theme::mThemePath
staticprivate

Definition at line 187 of file theme.h.

Referenced by getThemePath(), prepareThemePath(), and tryThemePath().


The documentation for this class was generated from the following files: