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 53 of file theme.h.

Member Typedef Documentation

◆ ProgressColors

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

Definition at line 208 of file theme.h.

◆ SkinIterator

typedef Skins::iterator Theme::SkinIterator
private

Definition at line 190 of file theme.h.

◆ Skins

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

Definition at line 189 of file theme.h.

Constructor & Destructor Documentation

◆ Theme()

Theme::Theme ( )

Definition at line 78 of file theme.cpp.

78  :
79  Palette(CAST_S32(ThemeColorId::THEME_COLORS_END) * THEME_PALETTES),
80  mSkins(),
81  mMinimumOpacity(-1.0F),
84 {
86 
87  config.addListener("guialpha", this);
88 
89  mColors[CAST_SIZE(ThemeColorId::HIGHLIGHT)].ch = 'H';
92  mColors[CAST_SIZE(ThemeColorId::GLOBAL)].ch = 'g';
93  mColors[CAST_SIZE(ThemeColorId::PLAYER)].ch = 'Y';
94  mColors[CAST_SIZE(ThemeColorId::WHISPER_TAB)].ch = 'W';
95  mColors[CAST_SIZE(ThemeColorId::WHISPER_TAB_OFFLINE)].ch = 'w';
96  mColors[CAST_SIZE(ThemeColorId::IS)].ch = 'I';
97  mColors[CAST_SIZE(ThemeColorId::PARTY_CHAT_TAB)].ch = 'P';
98  mColors[CAST_SIZE(ThemeColorId::GUILD_CHAT_TAB)].ch = 'U';
99  mColors[CAST_SIZE(ThemeColorId::SERVER)].ch = 'S';
100  mColors[CAST_SIZE(ThemeColorId::LOGGER)].ch = 'L';
101  mColors[CAST_SIZE(ThemeColorId::HYPERLINK)].ch = '<';
102  mColors[CAST_SIZE(ThemeColorId::SELFNICK)].ch = 's';
103  mColors[CAST_SIZE(ThemeColorId::OLDCHAT)].ch = 'o';
104  mColors[CAST_SIZE(ThemeColorId::AWAYCHAT)].ch = 'a';
105  mCharColors['H'] = CAST_S32(ThemeColorId::HIGHLIGHT);
108  mCharColors['g'] = CAST_S32(ThemeColorId::GLOBAL);
109  mCharColors['Y'] = CAST_S32(ThemeColorId::PLAYER);
110  mCharColors['W'] = CAST_S32(ThemeColorId::WHISPER_TAB);
111  mCharColors['w'] = CAST_S32(ThemeColorId::WHISPER_TAB_OFFLINE);
112  mCharColors['I'] = CAST_S32(ThemeColorId::IS);
113  mCharColors['P'] = CAST_S32(ThemeColorId::PARTY_CHAT_TAB);
114  mCharColors['U'] = CAST_S32(ThemeColorId::GUILD_CHAT_TAB);
115  mCharColors['S'] = CAST_S32(ThemeColorId::SERVER);
116  mCharColors['L'] = CAST_S32(ThemeColorId::LOGGER);
117  mCharColors['<'] = CAST_S32(ThemeColorId::HYPERLINK);
118  mCharColors['s'] = CAST_S32(ThemeColorId::SELFNICK);
119  mCharColors['o'] = CAST_S32(ThemeColorId::OLDCHAT);
120  mCharColors['a'] = CAST_S32(ThemeColorId::AWAYCHAT);
121 
122  // here need use outlined colors
123  mCharColors['H' | 0x80]
124  = CAST_S32(ThemeColorId::HIGHLIGHT_OUTLINE);
125  mCharColors['C' | 0x80] = CAST_S32(ThemeColorId::CHAT_OUTLINE);
126  mCharColors['G' | 0x80] = CAST_S32(ThemeColorId::GM_OUTLINE);
127  mCharColors['g' | 0x80] = CAST_S32(ThemeColorId::GLOBAL_OUTLINE);
128  mCharColors['Y' | 0x80] = CAST_S32(ThemeColorId::PLAYER_OUTLINE);
129  mCharColors['W' | 0x80]
130  = CAST_S32(ThemeColorId::WHISPER_TAB_OUTLINE);
131  mCharColors['w' | 0x80]
132  = CAST_S32(ThemeColorId::WHISPER_TAB_OFFLINE_OUTLINE);
133  mCharColors['I' | 0x80] = CAST_S32(ThemeColorId::IS_OUTLINE);
134  mCharColors['P' | 0x80]
135  = CAST_S32(ThemeColorId::PARTY_CHAT_TAB_OUTLINE);
136  mCharColors['U' | 0x80]
137  = CAST_S32(ThemeColorId::GUILD_CHAT_TAB_OUTLINE);
138  mCharColors['S' | 0x80] = CAST_S32(ThemeColorId::SERVER_OUTLINE);
139  mCharColors['L' | 0x80] = CAST_S32(ThemeColorId::LOGGER_OUTLINE);
140  mCharColors['<' | 0x80]
141  = CAST_S32(ThemeColorId::HYPERLINK_OUTLINE);
142  mCharColors['s' | 0x80] = CAST_S32(ThemeColorId::SELFNICK_OUTLINE);
143  mCharColors['o' | 0x80] = CAST_S32(ThemeColorId::OLDCHAT_OUTLINE);
144  mCharColors['a' | 0x80] = CAST_S32(ThemeColorId::AWAYCHAT_OUTLINE);
145 }
#define CAST_S32
Definition: cast.h:30
#define CAST_SIZE
Definition: cast.h:34
void addListener(const std::string &key, ConfigListener *const listener)
Colors mColors
Definition: palette.h:154
Palette(const int size)
Definition: palette.cpp:52
CharColors mCharColors
Definition: palette.h:155
float mMinimumOpacity
Definition: theme.h:206
Skins mSkins
Definition: theme.h:192
std::vector< DyePalette * > ProgressColors
Definition: theme.h:208
ProgressColors mProgressColors
Definition: theme.h:209
Configuration config
const int THEME_PALETTES
Definition: theme.h:31
static void initDefaultThemePath()
Definition: theme.cpp:65

References Configuration::addListener(), CAST_S32, CAST_SIZE, BeingType::CHAT, config, BeingFlag::GM, initDefaultThemePath(), Palette::mCharColors, and Palette::mColors.

◆ ~Theme()

Theme::~Theme ( )

Definition at line 147 of file theme.cpp.

148 {
150  config.removeListener("guialpha", this);
153 }
void removeListener(const std::string &key, ConfigListener *const listener)
void delete_all(Container &c)
Definition: dtor.h:56
#define CHECKLISTENERS
Definition: localconsts.h:277

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

Member Function Documentation

◆ fillFontsList()

void Theme::fillFontsList ( StringVect list)
static

Definition at line 570 of file theme.cpp.

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

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

Referenced by FontsModel::FontsModel().

◆ fillSkinsList()

void Theme::fillSkinsList ( StringVect list)
static

Definition at line 564 of file theme.cpp.

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

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

Referenced by ThemesModel::ThemesModel().

◆ fillSoundsList()

void Theme::fillSoundsList ( StringVect list)
static

Definition at line 578 of file theme.cpp.

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

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

Referenced by SoundsModel::SoundsModel().

◆ 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 136 of file theme.h.

138  {
139  if (CAST_SIZE(type) >= mColors.size())
140  {
141  logger->log("incorrect color request type: %d from %u",
142  CAST_S32(type),
143  CAST_U32(mColors.size()));
144  Color *const col = &mColors[CAST_SIZE(
145  ThemeColorId::BROWSERBOX)].color;
146  col->a = alpha;
147  return *col;
148  }
149  else
150  {
151  Color *const col = &mColors[CAST_SIZE(type)].color;
152  col->a = alpha;
153  return *col;
154  }
155  }
#define CAST_U32
Definition: cast.h:31
Definition: color.h:76
unsigned int a
Definition: color.h:251
void log(const char *const log_text,...)
Definition: logger.cpp:269
Logger * logger
Definition: logger.cpp:89

References Color::a, CAST_S32, CAST_SIZE, CAST_U32, Logger::log(), logger, and Palette::mColors.

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

◆ getIdByChar()

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

Definition at line 1075 of file theme.cpp.

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

References anonymous_namespace{libxml.cpp}::valid.

Referenced by Widget2::getThemeCharColor().

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

928 {
929  if (theme == nullptr)
930  return nullptr;
931 
932  Skin *const skin = theme->load(name,
933  name2,
934  false,
936  if (skin != nullptr)
937  {
938  const ImageRect &rect = skin->getBorder();
939  if (rect.grid[0] != nullptr)
940  {
941  Image *const image = rect.grid[0];
942  image->incRef();
943  theme->unload(skin);
944  return image;
945  }
946  theme->unload(skin);
947  }
948  return nullptr;
949 }
Image * grid[9]
Definition: imagerect.h:42
Definition: skin.h:37
const ImageRect & getBorder() const
Definition: skin.h:68
void unload(Skin *const skin)
Definition: theme.cpp:250
static std::string getThemePath()
Definition: theme.h:67
Skin * load(const std::string &filename, const std::string &filename2, const bool full, const std::string &defaultPath)
Definition: theme.cpp:179
Theme * theme
Definition: theme.cpp:62

References Skin::getBorder(), getThemePath(), ImageRect::grid, load(), SkinParameter::name, theme, and unload().

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

◆ getImageSetFromTheme()

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

Definition at line 660 of file theme.cpp.

662 {
663  return Loader::getImageSet(resolveThemePath(path), w, h);
664 }
ImageSet * getImageSet(const std::string &imagePath, const int w, const int h)

References Loader::getImageSet().

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

◆ getImageSetFromThemeXml()

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

Definition at line 951 of file theme.cpp.

954 {
955  if (theme == nullptr)
956  return nullptr;
957 
958  Skin *const skin = theme->load(name,
959  name2,
960  false,
962  if (skin != nullptr)
963  {
964  const ImageRect &rect = skin->getBorder();
965  if (rect.grid[0] != nullptr)
966  {
967  Image *const image = rect.grid[0];
968  const SDL_Rect &rect2 = image->mBounds;
969  if ((rect2.w != 0U) && (rect2.h != 0U))
970  {
971  ImageSet *const imageSet = Loader::getSubImageSet(
972  image, w, h);
973  theme->unload(skin);
974  return imageSet;
975  }
976  }
977  theme->unload(skin);
978  }
979  return nullptr;
980 }
ImageSet * getSubImageSet(Image *const parent, const int width, const int height)

References Skin::getBorder(), Loader::getSubImageSet(), getThemePath(), ImageRect::grid, load(), SkinParameter::name, theme, and unload().

◆ getMinimumOpacity()

float Theme::getMinimumOpacity ( ) const
inline

◆ getProgressColor()

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

Definition at line 155 of file theme.cpp.

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

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

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

◆ getThemeName()

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

Definition at line 70 of file theme.h.

71  { return mThemeName; }
static std::string mThemeName
Definition: theme.h:195

References mThemeName.

Referenced by Setup_Theme::Setup_Theme().

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

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

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

Referenced by BrowserBox::BrowserBox(), CheckBox::CheckBox(), Desktop::Desktop(), DropDown::DropDown(), Client::gameInit(), getImageFromThemeXml(), getImageSetFromThemeXml(), Button::init(), Label::init(), Tab::init(), ScrollArea::init(), ListBox::ListBox(), TouchManager::loadButtons(), Pincode::Pincode(), Popup::Popup(), ProgressBar::ProgressBar(), RadioButton::RadioButton(), SkillRectangleListBox::SkillRectangleListBox(), StaticBrowserBox::StaticBrowserBox(), TestLauncher::testDraw(), TextPreview::TextPreview(), and Window::Window().

◆ loadColors()

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

Definition at line 791 of file theme.cpp.

792 {
793  if (file.empty())
794  file = "colors.xml";
795  else
796  file = pathJoin(file, "colors.xml");
797 
798  XML::Document *const doc = Loader::getXml(resolveThemePath(file),
801  if (doc == nullptr)
802  return;
803  XmlNodeConstPtrConst root = doc->rootNode();
804 
805  if ((root == nullptr) || !xmlNameEqual(root, "colors"))
806  {
807  logger->log("Error loading colors file: %s", file.c_str());
808  doc->decRef();
809  return;
810  }
811 
812  logger->log("Loading colors file: %s", file.c_str());
813 
814  for_each_xml_child_node(paletteNode, root)
815  {
816  if (xmlNameEqual(paletteNode, "progressbar"))
817  {
818  const int type = readProgressType(XML::getProperty(
819  paletteNode, "id", ""));
820  if (type < 0)
821  continue;
822 
824  paletteNode, "color", ""), 6);
825  }
826  else if (!xmlNameEqual(paletteNode, "palette"))
827  {
828  continue;
829  }
830 
831  const int paletteId = XML::getProperty(paletteNode, "id", 1);
832  if (paletteId < 0 || paletteId >= THEME_PALETTES)
833  continue;
834 
835  for_each_xml_child_node(node, paletteNode)
836  {
837  if (xmlNameEqual(node, "color"))
838  {
839  const std::string id = XML::getProperty(node, "id", "");
840  const int type = readColorType(id);
841  if (type < 0)
842  continue;
843 
844  const std::string temp = XML::getProperty(node, "color", "");
845  if (temp.empty())
846  continue;
847 
848  const Color color = readColor(temp);
849  const GradientTypeT grad = readColorGradient(
850  XML::getProperty(node, "effect", ""));
851  mColors[paletteId * CAST_SIZE(
852  ThemeColorId::THEME_COLORS_END) + type].set(
853  type, color, grad, 10);
854 
855  if (!findLast(id, "_OUTLINE"))
856  {
857  const int type2 = readColorType(id + "_OUTLINE");
858  if (type2 < 0)
859  continue;
860  const int idx = paletteId
861  * CAST_S32(ThemeColorId::THEME_COLORS_END);
862  mColors[idx + type2] = mColors[idx + type];
863  }
864  }
865  }
866  }
867  doc->decRef();
868 }
virtual void decRef()
Definition: resource.cpp:50
xmlNodePtr rootNode()
Definition: libxml.cpp:169
GradientType ::T GradientTypeT
Definition: gradienttype.h:38
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:161
XML::Document * getXml(const std::string &idPath, const UseVirtFs useResman, const SkipError skipError)
Definition: xmlloader.cpp:56
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition: libxml.cpp:174
const bool SkipError_false
Definition: skiperror.h:30
bool findLast(const std::string &str1, const std::string &str2)
std::string pathJoin(std::string str1, const std::string &str2)
static int readColorType(const std::string &type)
Definition: theme.cpp:670
static Color readColor(const std::string &description)
Definition: theme.cpp:697
static GradientTypeT readColorGradient(const std::string &grad)
Definition: theme.cpp:738
static int readProgressType(const std::string &type)
Definition: theme.cpp:760
const bool UseVirtFs_true
Definition: usevirtfs.h:30

References CAST_S32, CAST_SIZE, Resource::decRef(), findLast(), for_each_xml_child_node, XML::getProperty(), Loader::getXml(), Logger::log(), logger, anonymous_namespace{palettedb.cpp}::mColors, pathJoin(), readColor(), readColorGradient(), readColorType(), readProgressType(), XML::Document::rootNode(), SkipError_false, THEME_PALETTES, and UseVirtFs_true.

Referenced by prepareThemePath(), and tryThemePath().

◆ loadInfo()

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

Definition at line 1006 of file theme.cpp.

1007 {
1008  std::string path;
1009  if (themeName.empty())
1010  {
1011  path = "graphics/gui/info.xml";
1012  }
1013  else
1014  {
1015  path = pathJoin(defaultThemePath,
1016  themeName,
1017  "info.xml");
1018  }
1019  logger->log("loading: " + path);
1020  XML::Document *const doc = Loader::getXml(path,
1022  SkipError_false);
1023  if (doc == nullptr)
1024  return nullptr;
1025  XmlNodeConstPtrConst rootNode = doc->rootNode();
1026 
1027  if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "info"))
1028  {
1029  doc->decRef();
1030  return nullptr;
1031  }
1032 
1033  ThemeInfo *const info = new ThemeInfo;
1034 
1035  const std::string fontSize2("fontSize_" + mScreenDensity);
1036  const std::string npcfontSize2("npcfontSize_" + mScreenDensity);
1037  XmlChar *tmpData = nullptr;
1038  for_each_xml_child_node(infoNode, rootNode)
1039  {
1040  if (xmlNameEqual(infoNode, "name"))
1041  readValue(name)
1042  else if (xmlNameEqual(infoNode, "copyright"))
1043  readValue(copyright)
1044  else if (xmlNameEqual(infoNode, "font"))
1045  readValue(font)
1046  else if (xmlNameEqual(infoNode, "boldFont"))
1048  else if (xmlNameEqual(infoNode, "particleFont"))
1049  readValue(particleFont)
1050  else if (xmlNameEqual(infoNode, "helpFont"))
1051  readValue(helpFont)
1052  else if (xmlNameEqual(infoNode, "secureFont"))
1053  readValue(secureFont)
1054  else if (xmlNameEqual(infoNode, "npcFont"))
1055  readValue(npcFont)
1056  else if (xmlNameEqual(infoNode, "japanFont"))
1057  readValue(japanFont)
1058  else if (xmlNameEqual(infoNode, "chinaFont"))
1059  readValue(chinaFont)
1060  else if (xmlNameEqual(infoNode, "fontSize"))
1061  readIntValue(fontSize)
1062  else if (xmlNameEqual(infoNode, "npcfontSize"))
1063  readIntValue(npcfontSize)
1064  else if (xmlNameEqual(infoNode, "guialpha"))
1065  readFloatValue(guiAlpha)
1066  else if (xmlNameEqual(infoNode, fontSize2.c_str()))
1067  readIntValue(fontSize)
1068  else if (xmlNameEqual(infoNode, npcfontSize2.c_str()))
1069  readIntValue(npcfontSize)
1070  }
1071  doc->decRef();
1072  return info;
1073 }
Font * boldFont
Definition: gui.cpp:112
bool info(InputEvent &event)
Definition: commands.cpp:57
#define readIntValue(name)
Definition: theme.cpp:990
#define readValue(name)
Definition: theme.cpp:982
static std::string defaultThemePath
Definition: theme.cpp:56
#define readFloatValue(name)
Definition: theme.cpp:998

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

Referenced by Setup_Theme::updateInfo().

◆ loadRect()

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

Definition at line 883 of file theme.cpp.

888 {
889  Skin *const skin = load(name,
890  name2,
891  false,
893  if (skin != nullptr)
894  {
895  loadGrid()
896  unload(skin);
897  }
898 }
#define loadGrid()
Definition: theme.cpp:870

References getThemePath(), AvatarDB::load(), loadGrid, SkinParameter::name, and Net::unload().

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

◆ loadSkinRect()

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

Definition at line 900 of file theme.cpp.

905 {
906  Skin *const skin = load(name,
907  name2,
908  true,
910  if (skin != nullptr)
911  loadGrid()
912  return skin;
913 }

References getThemePath(), AvatarDB::load(), loadGrid, and SkinParameter::name.

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

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

292 {
293  updateAlpha();
294 }
void updateAlpha()
Definition: theme.cpp:281

References updateAlpha().

◆ prepareThemePath()

void Theme::prepareThemePath ( )
static

Definition at line 604 of file theme.cpp.

605 {
607 
608  mThemePath.clear();
609  mThemeName.clear();
610 
611  // Try theme from settings
612  if (tryThemePath(config.getStringValue("theme")))
613  return;
614 
615  // Try theme from branding
616  if (tryThemePath(branding.getStringValue("theme")))
617  return;
618 
619  if (mThemePath.empty())
620  mThemePath = "graphics/gui";
621 
623 
624  logger->log("Selected Theme: " + mThemePath);
625 }
void loadColors(std::string file)
Definition: theme.cpp:791
static bool tryThemePath(const std::string &themePath)
Definition: theme.cpp:546

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

◆ readSkin()

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

Definition at line 394 of file theme.cpp.

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

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

Referenced by load().

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

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

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

Referenced by ActorSprite::initTargetCursor().

◆ selectSkin()

void Theme::selectSkin ( )
static

Definition at line 598 of file theme.cpp.

599 {
602 }
std::string getDensityString() const
static void prepareThemePath()
Definition: theme.cpp:604
GraphicsManager graphicsManager

References GraphicsManager::getDensityString(), and graphicsManager.

Referenced by Client::gameInit().

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

273 {
274  if (minimumOpacity > 1.0F)
275  return;
276 
277  mMinimumOpacity = minimumOpacity;
278  updateAlpha();
279 }

References mMinimumOpacity, and updateAlpha().

◆ tryThemePath()

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

Definition at line 546 of file theme.cpp.

547 {
548  if (!themeName.empty())
549  {
550  const std::string path = defaultThemePath + themeName;
551  if (VirtFs::exists(path))
552  {
553  mThemePath = path;
554  mThemeName = themeName;
555  if (theme != nullptr)
556  theme->loadColors("");
557  return true;
558  }
559  }
560 
561  return false;
562 }

References defaultThemePath, VirtFs::exists(), loadColors(), and theme.

◆ unload()

void Theme::unload ( Skin *const  skin)

Definition at line 250 of file theme.cpp.

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

References Skin::instances, and mSkins.

Referenced by DropDown::DropDown(), getImageFromThemeXml(), getImageSetFromThemeXml(), ScrollArea::init(), TouchManager::loadButtons(), 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().

◆ unloadRect()

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

Definition at line 915 of file theme.cpp.

918 {
919  for (int f = start; f <= end; f ++)
920  {
921  if (rect.grid[f] != nullptr)
922  rect.grid[f]->decRef();
923  }
924 }

References ImageRect::grid, and anonymous_namespace{stringutils.cpp}::start.

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

◆ updateAlpha()

void Theme::updateAlpha ( )

Updates the alpha values of all of the skins.

Definition at line 281 of file theme.cpp.

282 {
283  FOR_EACH (SkinIterator, iter, mSkins)
284  {
285  Skin *const skin = iter->second;
286  if (skin != nullptr)
288  }
289 }

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

Referenced by optionChanged(), and setMinimumOpacity().

Field Documentation

◆ mMinimumOpacity

float Theme::mMinimumOpacity
private

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

Definition at line 206 of file theme.h.

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

◆ mProgressColors

ProgressColors Theme::mProgressColors
private

Definition at line 209 of file theme.h.

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

◆ mScreenDensity

std::string Theme::mScreenDensity
staticprivate

Definition at line 196 of file theme.h.

Referenced by load().

◆ mSkins

Skins Theme::mSkins
private

Definition at line 192 of file theme.h.

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

◆ mThemeName

std::string Theme::mThemeName
staticprivate

Definition at line 195 of file theme.h.

Referenced by getThemeName().

◆ mThemePath

std::string Theme::mThemePath
staticprivate

Definition at line 194 of file theme.h.

Referenced by getThemePath().


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