ManaPlus
Data Structures | Macros | Functions | Variables
theme.cpp File Reference

(986a3bf)

#include "gui/theme.h"
#include "configuration.h"
#include "graphicsmanager.h"
#include "const/gui/theme.h"
#include "fs/virtfs/fs.h"
#include "fs/virtfs/list.h"
#include "gui/skin.h"
#include "gui/themeinfo.h"
#include "resources/imagerect.h"
#include "resources/dye/dyepalette.h"
#include "resources/image/image.h"
#include "resources/loaders/imageloader.h"
#include "resources/loaders/imagesetloader.h"
#include "resources/loaders/subimageloader.h"
#include "resources/loaders/subimagesetloader.h"
#include "resources/loaders/xmlloader.h"
#include "utils/dtor.h"
#include "utils/foreach.h"
#include "debug.h"
#include "gui/themecolortype.inc"

Go to the source code of this file.

Data Structures

struct  SkinParameter
 
struct  SkinHelper
 

Macros

#define themeEnumStart(name)   #name,
 
#define themeEnum(name)   #name,
 
#define themeEnumEnd(name)
 
#define loadGrid()
 
#define readValue(name)
 
#define readIntValue(name)
 
#define readFloatValue(name)
 

Functions

static void initDefaultThemePath ()
 
static int readColorType (const std::string &type)
 
static Color readColor (const std::string &description)
 
static GradientTypeT readColorGradient (const std::string &grad)
 
static int readProgressType (const std::string &type)
 

Variables

static std::string defaultThemePath
 
Themetheme = 0
 
static const SkinParameter skinParam []
 
static const SkinParameter imageParam []
 

Macro Definition Documentation

◆ loadGrid

#define loadGrid ( )
Value:
{ \
const ImageRect &rect = skin->getBorder(); \
for (int f = start; f <= end; f ++) \
{ \
if (rect.grid[f]) \
{ \
image.grid[f] = rect.grid[f]; \
image.grid[f]->incRef(); \
} \
} \
}
Image * grid[9]
Definition: imagerect.h:42

Definition at line 870 of file theme.cpp.

◆ readFloatValue

#define readFloatValue (   name)
Value:
{ \
tmpData = reinterpret_cast<XmlChar*>( \
XmlNodeGetContent(infoNode)); \
info->name = static_cast<float>(atof(tmpData)); \
XmlFree(tmpData); \
}

Definition at line 998 of file theme.cpp.

◆ readIntValue

#define readIntValue (   name)
Value:
{ \
tmpData = reinterpret_cast<XmlChar*>( \
XmlNodeGetContent(infoNode)); \
info->name = atoi(tmpData); \
XmlFree(tmpData); \
}

Definition at line 990 of file theme.cpp.

◆ readValue

#define readValue (   name)
Value:
{ \
tmpData = reinterpret_cast<XmlChar*>( \
XmlNodeGetContent(infoNode)); \
info->name = tmpData; \
XmlFree(tmpData); \
}

Definition at line 982 of file theme.cpp.

◆ themeEnum

#define themeEnum (   name)    #name,

Definition at line 667 of file theme.cpp.

◆ themeEnumEnd

#define themeEnumEnd (   name)

Definition at line 668 of file theme.cpp.

◆ themeEnumStart

#define themeEnumStart (   name)    #name,

Definition at line 666 of file theme.cpp.

Function Documentation

◆ initDefaultThemePath()

static void initDefaultThemePath ( )
static

Definition at line 65 of file theme.cpp.

66 {
67  defaultThemePath = branding.getStringValue("guiThemePath");
68 
69  logger->log("defaultThemePath: " + defaultThemePath);
70  if (!defaultThemePath.empty() &&
72  {
73  return;
74  }
75  defaultThemePath = "themes/";
76 }
std::string getStringValue(const std::string &key) const
void log(const char *const log_text,...)
Definition: logger.cpp:269
Configuration branding
Logger * logger
Definition: logger.cpp:89
bool isDirectory(std::string name)
Definition: fs.cpp:239
static std::string defaultThemePath
Definition: theme.cpp:56

References branding, defaultThemePath, Configuration::getStringValue(), VirtFs::isDirectory(), Logger::log(), and logger.

Referenced by Theme::prepareThemePath(), and Theme::Theme().

◆ readColor()

static Color readColor ( const std::string &  description)
static

Definition at line 697 of file theme.cpp.

698 {
699  const int size = static_cast<int>(description.length());
700  if (size < 7 || description[0] != '#')
701  {
702  logger->log("Error, invalid theme color palette: %s",
703  description.c_str());
704  return Palette::BLACK;
705  }
706 
707  unsigned int v = 0;
708  for (int i = 1; i < 7; ++i)
709  {
710  signed const char c = description[i];
711  int n;
712 
713  if ('0' <= c && c <= '9')
714  {
715  n = c - '0';
716  }
717  else if ('A' <= c && c <= 'F')
718  {
719  n = c - 'A' + 10;
720  }
721  else if ('a' <= c && c <= 'f')
722  {
723  n = c - 'a' + 10;
724  }
725  else
726  {
727  logger->log("Error, invalid theme color palette: %s",
728  description.c_str());
729  return Palette::BLACK;
730  }
731 
732  v = (v << 4) | n;
733  }
734 
735  return Color(v);
736 }
Definition: color.h:76
static const Color BLACK
Definition: palette.h:48
int size()
Definition: emotedb.cpp:306

References Palette::BLACK, Logger::log(), logger, and EmoteDB::size().

Referenced by BrowserBox::BrowserBox(), Theme::loadColors(), and StaticBrowserBox::StaticBrowserBox().

◆ readColorGradient()

static GradientTypeT readColorGradient ( const std::string &  grad)
static

Definition at line 738 of file theme.cpp.

739 {
740  static const std::string grads[] =
741  {
742  "STATIC",
743  "PULSE",
744  "SPECTRUM",
745  "RAINBOW"
746  };
747 
748  if (grad.empty())
749  return GradientType::STATIC;
750 
751  for (int i = 0; i < 4; i++)
752  {
753  if (compareStrI(grad, grads[i]) != 0)
754  return static_cast<GradientTypeT>(i);
755  }
756 
757  return GradientType::STATIC;
758 }
GradientType ::T GradientTypeT
Definition: gradienttype.h:38
int compareStrI(const std::string &a, const std::string &b)

References compareStrI(), and GradientType::STATIC.

Referenced by Theme::loadColors().

◆ readColorType()

static int readColorType ( const std::string &  type)
static

Definition at line 670 of file theme.cpp.

671 {
672  static const std::string colors[CAST_SIZE(
673  ThemeColorId::THEME_COLORS_END)] =
674  {
675 #include "gui/themecolortype.inc"
676  };
677 
678  if (type.empty())
679  return -1;
680 
681  for (int i = 0; i < CAST_S32(ThemeColorId::THEME_COLORS_END); i++)
682  {
683  if (compareStrI(type, colors[i]) == 0)
684  return i;
685  }
686 
687  return -1;
688 }
#define CAST_S32
Definition: cast.h:30
#define CAST_SIZE
Definition: cast.h:34

References CAST_S32, CAST_SIZE, and compareStrI().

Referenced by Theme::loadColors().

◆ readProgressType()

static int readProgressType ( const std::string &  type)
static

Definition at line 760 of file theme.cpp.

761 {
762  static const std::string colors[CAST_SIZE(
764  {
765  "HP",
766  "HP_POISON",
767  "MP",
768  "NO_MP",
769  "EXP",
770  "INVY_SLOTS",
771  "WEIGHT",
772  "JOB",
773  "UPDATE",
774  "MONEY",
775  "ARROWS",
776  "STATUS"
777  };
778 
779  if (type.empty())
780  return -1;
781 
782  for (int i = 0; i < CAST_S32(ProgressColorId::THEME_PROG_END); i++)
783  {
784  if (compareStrI(type, colors[i]) == 0)
785  return i;
786  }
787 
788  return -1;
789 }

References CAST_S32, CAST_SIZE, compareStrI(), and ProgressColorId::THEME_PROG_END.

Referenced by Theme::loadColors().

Variable Documentation

◆ defaultThemePath

std::string defaultThemePath
static

Definition at line 56 of file theme.cpp.

Referenced by initDefaultThemePath(), Theme::loadInfo(), and Theme::tryThemePath().

◆ imageParam

const SkinParameter imageParam[]
static
Initial value:
=
{
{0, "closeImage"},
{1, "closeImageHighlighted"},
{2, "stickyImageUp"},
{3, "stickyImageDown"},
}

Definition at line 342 of file theme.cpp.

Referenced by Theme::readSkin().

◆ skinParam

const SkinParameter skinParam[]
static

Definition at line 303 of file theme.cpp.

Referenced by Theme::readSkin().

◆ theme

Theme* theme = 0

Definition at line 62 of file theme.cpp.

Referenced by Game::addWatermark(), BrowserBox::BrowserBox(), CheckBox::CheckBox(), Desktop::Desktop(), TextParticle::draw(), Being::drawSpeech(), TouchManager::drawText(), DropDown::DropDown(), Client::gameInit(), Theme::getImageFromThemeXml(), Theme::getImageSetFromThemeXml(), Theme::getProgressColor(), Widget2::getThemeCharColor(), Widget2::getThemeColor(), Button::init(), Label::init(), Slider::init(), Tab::init(), PlayerBox::init(), ScrollArea::init(), ListBox::ListBox(), TouchManager::loadButtons(), TouchManager::loadTouchItem(), LocalPlayer::LocalPlayer(), Pincode::Pincode(), Popup::Popup(), EquipmentWindow::postInit(), Theme::prepareThemePath(), ProgressBar::ProgressBar(), RadioButton::RadioButton(), Being::setSpeech(), SkillRectangleListBox::SkillRectangleListBox(), StaticBrowserBox::StaticBrowserBox(), TestLauncher::testDraw(), Text::Text(), TextField::TextField(), TextPreview::TextPreview(), Theme::tryThemePath(), Button::updateAlpha(), CheckBox::updateAlpha(), DropDown::updateAlpha(), ListBox::updateAlpha(), ProgressBar::updateAlpha(), RadioButton::updateAlpha(), ScrollArea::updateAlpha(), SkillRectangleListBox::updateAlpha(), Slider::updateAlpha(), Tab::updateAlpha(), TextField::updateAlpha(), Being::updateColors(), Window::Window(), BrowserBox::~BrowserBox(), Button::~Button(), CheckBox::~CheckBox(), Desktop::~Desktop(), DropDown::~DropDown(), Gui::~Gui(), 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().