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 (const 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 207 of file theme.h.

◆ SkinIterator

typedef Skins::iterator Theme::SkinIterator
private

Definition at line 189 of file theme.h.

◆ Skins

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

Definition at line 188 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:191
Configuration config
ProgressColors mProgressColors
Definition: theme.h:208
void addListener(const std::string &key, ConfigListener *const listener)
float mMinimumOpacity
Definition: theme.h:205
std::vector< DyePalette * > ProgressColors
Definition: theme.h:207
#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:191
Configuration config
ProgressColors mProgressColors
Definition: theme.h:208
void delete_all(Container &c)
Definition: dtor.h:55
#define CHECKLISTENERS
Definition: localconsts.h:268
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 ( const 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()));
143  Color *const col = &mColors[CAST_SIZE(
144  ThemeColorId::BROWSERBOX)].color;
145  col->a = alpha;
146  return *col;
147  }
148  else
149  {
150  Color *const col = &mColors[CAST_SIZE(type)].color;
151  col->a = alpha;
152  return *col;
153  }
154  }
#define CAST_U32
Definition: cast.h:30
unsigned int a
Definition: color.h:250
Logger * logger
Definition: logger.cpp:88
#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:264

◆ getIdByChar()

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

Definition at line 1074 of file theme.cpp.

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

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

1075 {
1076  const CharColors::const_iterator it = mCharColors.find(c);
1077  if (it != mCharColors.end())
1078  {
1079  valid = true;
1080  return static_cast<ThemeColorIdT>((*it).second);
1081  }
1082 
1083  valid = false;
1084  return ThemeColorId::BROWSERBOX;
1085 }
ThemeColorId ::T ThemeColorIdT
Definition: themecolorid.h:34
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 925 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().

927 {
928  if (theme == nullptr)
929  return nullptr;
930 
931  Skin *const skin = theme->load(name,
932  name2,
933  false,
935  if (skin != nullptr)
936  {
937  const ImageRect &rect = skin->getBorder();
938  if (rect.grid[0] != nullptr)
939  {
940  Image *const image = rect.grid[0];
941  image->incRef();
942  theme->unload(skin);
943  return image;
944  }
945  theme->unload(skin);
946  }
947  return nullptr;
948 }
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(), Gui::setUseCustomCursor(), and WindowMenu::WindowMenu().

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 950 of file theme.cpp.

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

Referenced by getThemeName().

953 {
954  if (theme == nullptr)
955  return nullptr;
956 
957  Skin *const skin = theme->load(name,
958  name2,
959  false,
961  if (skin != nullptr)
962  {
963  const ImageRect &rect = skin->getBorder();
964  if (rect.grid[0] != nullptr)
965  {
966  Image *const image = rect.grid[0];
967  const SDL_Rect &rect2 = image->mBounds;
968  if ((rect2.w != 0u) && (rect2.h != 0u))
969  {
970  ImageSet *const imageSet = Loader::getSubImageSet(
971  image, w, h);
972  theme->unload(skin);
973  return imageSet;
974  }
975  }
976  theme->unload(skin);
977  }
978  return nullptr;
979 }
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:208
Logger * logger
Definition: logger.cpp:88
#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:264

◆ 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(), Pincode::Pincode(), 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:191
Skins::iterator SkinIterator
Definition: theme.h:189
Logger * logger
Definition: logger.cpp:88
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:195
Skin * readSkin(const std::string &filename0, const bool full)
Definition: theme.cpp:393
void log(const char *const log_text,...)
Definition: logger.cpp:264

◆ loadColors()

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

Definition at line 790 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().

791 {
792  if (file.empty())
793  file = "colors.xml";
794  else
795  file = pathJoin(file, "colors.xml");
796 
797  XML::Document *const doc = Loader::getXml(resolveThemePath(file),
800  if (doc == nullptr)
801  return;
802  XmlNodeConstPtrConst root = doc->rootNode();
803 
804  if ((root == nullptr) || !xmlNameEqual(root, "colors"))
805  {
806  logger->log("Error loading colors file: %s", file.c_str());
807  doc->decRef();
808  return;
809  }
810 
811  logger->log("Loading colors file: %s", file.c_str());
812 
813  for_each_xml_child_node(paletteNode, root)
814  {
815  if (xmlNameEqual(paletteNode, "progressbar"))
816  {
817  const int type = readProgressType(XML::getProperty(
818  paletteNode, "id", ""));
819  if (type < 0)
820  continue;
821 
823  paletteNode, "color", ""), 6);
824  }
825  else if (!xmlNameEqual(paletteNode, "palette"))
826  {
827  continue;
828  }
829 
830  const int paletteId = XML::getProperty(paletteNode, "id", 1);
831  if (paletteId < 0 || paletteId >= THEME_PALETTES)
832  continue;
833 
834  for_each_xml_child_node(node, paletteNode)
835  {
836  if (xmlNameEqual(node, "color"))
837  {
838  const std::string id = XML::getProperty(node, "id", "");
839  const int type = readColorType(id);
840  if (type < 0)
841  continue;
842 
843  const std::string temp = XML::getProperty(node, "color", "");
844  if (temp.empty())
845  continue;
846 
847  const Color color = readColor(temp);
848  const GradientTypeT grad = readColorGradient(
849  XML::getProperty(node, "effect", ""));
850  mColors[paletteId * CAST_SIZE(
851  ThemeColorId::THEME_COLORS_END) + type].set(
852  type, color, grad, 10);
853 
854  if (!findLast(id, "_OUTLINE"))
855  {
856  const int type2 = readColorType(id + "_OUTLINE");
857  if (type2 < 0)
858  continue;
859  const int idx = paletteId
861  mColors[idx + type2] = mColors[idx + type];
862  }
863  }
864  }
865  }
866  doc->decRef();
867 }
const bool SkipError_false
Definition: skiperror.h:29
static int readProgressType(const std::string &type)
Definition: theme.cpp:759
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:173
static GradientTypeT readColorGradient(const std::string &grad)
Definition: theme.cpp:737
ProgressColors mProgressColors
Definition: theme.h:208
Logger * logger
Definition: logger.cpp:88
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:696
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:168
static int readColorType(const std::string &type)
Definition: theme.cpp:669
#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:264
static std::string resolveThemePath(const std::string &path)
Definition: theme.cpp:626

◆ loadInfo()

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

Definition at line 1005 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().

1006 {
1007  std::string path;
1008  if (themeName.empty())
1009  {
1010  path = "graphics/gui/info.xml";
1011  }
1012  else
1013  {
1014  path = pathJoin(defaultThemePath,
1015  themeName,
1016  "info.xml");
1017  }
1018  logger->log("loading: " + path);
1019  XML::Document *const doc = Loader::getXml(path,
1021  SkipError_false);
1022  if (doc == nullptr)
1023  return nullptr;
1024  XmlNodeConstPtrConst rootNode = doc->rootNode();
1025 
1026  if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "info"))
1027  {
1028  doc->decRef();
1029  return nullptr;
1030  }
1031 
1032  ThemeInfo *const info = new ThemeInfo;
1033 
1034  const std::string fontSize2("fontSize_" + mScreenDensity);
1035  const std::string npcfontSize2("npcfontSize_" + mScreenDensity);
1036  XmlChar *tmpData = nullptr;
1037  for_each_xml_child_node(infoNode, rootNode)
1038  {
1039  if (xmlNameEqual(infoNode, "name"))
1040  readValue(name)
1041  else if (xmlNameEqual(infoNode, "copyright"))
1042  readValue(copyright)
1043  else if (xmlNameEqual(infoNode, "font"))
1044  readValue(font)
1045  else if (xmlNameEqual(infoNode, "boldFont"))
1047  else if (xmlNameEqual(infoNode, "particleFont"))
1048  readValue(particleFont)
1049  else if (xmlNameEqual(infoNode, "helpFont"))
1050  readValue(helpFont)
1051  else if (xmlNameEqual(infoNode, "secureFont"))
1052  readValue(secureFont)
1053  else if (xmlNameEqual(infoNode, "npcFont"))
1054  readValue(npcFont)
1055  else if (xmlNameEqual(infoNode, "japanFont"))
1056  readValue(japanFont)
1057  else if (xmlNameEqual(infoNode, "chinaFont"))
1058  readValue(chinaFont)
1059  else if (xmlNameEqual(infoNode, "fontSize"))
1060  readIntValue(fontSize)
1061  else if (xmlNameEqual(infoNode, "npcfontSize"))
1062  readIntValue(npcfontSize)
1063  else if (xmlNameEqual(infoNode, "guialpha"))
1064  readFloatValue(guiAlpha)
1065  else if (xmlNameEqual(infoNode, fontSize2.c_str()))
1066  readIntValue(fontSize)
1067  else if (xmlNameEqual(infoNode, npcfontSize2.c_str()))
1068  readIntValue(npcfontSize)
1069  }
1070  doc->decRef();
1071  return info;
1072 }
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:997
Logger * logger
Definition: logger.cpp:88
const bool UseVirtFs_true
Definition: usevirtfs.h:29
#define readIntValue(name)
Definition: theme.cpp:989
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:168
static std::string mScreenDensity
Definition: theme.h:195
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:981
void log(const char *const log_text,...)
Definition: logger.cpp:264

◆ loadRect()

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

Definition at line 882 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().

887 {
888  Skin *const skin = load(name,
889  name2,
890  false,
892  if (skin != nullptr)
893  {
894  loadGrid();
895  unload(skin);
896  }
897 }
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:869

◆ loadSkinRect()

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

Definition at line 899 of file theme.cpp.

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

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

904 {
905  Skin *const skin = load(name,
906  name2,
907  true,
909  if (skin != nullptr)
910  loadGrid();
911  return skin;
912 }
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:869

◆ 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:193
Logger * logger
Definition: logger.cpp:88
static bool tryThemePath(const std::string &themePath)
Definition: theme.cpp:545
Theme * theme
Definition: theme.cpp:61
static std::string mThemeName
Definition: theme.h:194
static void initDefaultThemePath()
Definition: theme.cpp:64
void log(const char *const log_text,...)
Definition: logger.cpp:264
void loadColors(std::string file)
Definition: theme.cpp:790

◆ 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:233
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:173
ImageRect * rect
Definition: theme.cpp:370
Logger * logger
Definition: logger.cpp:88
int xPos
Definition: theme.cpp:366
float mMinimumOpacity
Definition: theme.h:205
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:168
#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:264
const bool SkipError_true
Definition: skiperror.h:29
void decRef()
Definition: image.cpp:522
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:195
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:205
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:193
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:194
void loadColors(std::string file)
Definition: theme.cpp:790

◆ 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(), Pincode::~Pincode(), 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:191
Skins::iterator SkinIterator
Definition: theme.h:189
int instances
Definition: skin.h:120

◆ unloadRect()

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

Definition at line 914 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().

917 {
918  for (int f = start; f <= end; f ++)
919  {
920  if (rect.grid[f] != nullptr)
921  rect.grid[f]->decRef();
922  }
923 }
Image * grid[9]
Definition: imagerect.h:41
void decRef()
Definition: image.cpp:522

◆ 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:191
Skins::iterator SkinIterator
Definition: theme.h:189
float mMinimumOpacity
Definition: theme.h:205
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 205 of file theme.h.

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

◆ mProgressColors

ProgressColors Theme::mProgressColors
private

Definition at line 208 of file theme.h.

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

◆ mScreenDensity

std::string Theme::mScreenDensity
staticprivate

Definition at line 195 of file theme.h.

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

◆ mSkins

Skins Theme::mSkins
private

Definition at line 191 of file theme.h.

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

◆ mThemeName

std::string Theme::mThemeName
staticprivate

Definition at line 194 of file theme.h.

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

◆ mThemePath

std::string Theme::mThemePath
staticprivate

Definition at line 193 of file theme.h.

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


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