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

(1c30ebb)

#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:41
virtual void incRef()
Definition: resource.cpp:37

Definition at line 869 of file theme.cpp.

Referenced by Theme::loadRect(), and Theme::loadSkinRect().

◆ readFloatValue

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

Definition at line 997 of file theme.cpp.

Referenced by Theme::loadInfo().

◆ readIntValue

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

Definition at line 989 of file theme.cpp.

Referenced by Theme::loadInfo().

◆ readValue

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

Definition at line 981 of file theme.cpp.

Referenced by Theme::loadInfo().

◆ themeEnum

#define themeEnum (   name)    #name,

Definition at line 666 of file theme.cpp.

◆ themeEnumEnd

#define themeEnumEnd (   name)

Definition at line 667 of file theme.cpp.

◆ themeEnumStart

#define themeEnumStart (   name)    #name,

Definition at line 665 of file theme.cpp.

Function Documentation

◆ initDefaultThemePath()

static void initDefaultThemePath ( )
static

Definition at line 64 of file theme.cpp.

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

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

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

◆ readColor()

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

Definition at line 696 of file theme.cpp.

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

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

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

◆ readColorGradient()

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

Definition at line 737 of file theme.cpp.

References compareStrI(), and GradientType::STATIC.

Referenced by Theme::loadColors().

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

◆ readColorType()

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

Definition at line 669 of file theme.cpp.

References CAST_S32, CAST_SIZE, compareStrI(), ThemeColorId::THEME_COLORS_END, and THEMECOLORTYPE_VOID.

Referenced by Theme::loadColors().

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

◆ readProgressType()

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

Definition at line 759 of file theme.cpp.

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

Referenced by Theme::loadColors().

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

Variable Documentation

◆ defaultThemePath

std::string defaultThemePath
static

Definition at line 55 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 341 of file theme.cpp.

◆ skinParam

const SkinParameter skinParam[]
static

Definition at line 302 of file theme.cpp.

Referenced by Theme::readSkin().

◆ theme

Theme* theme = 0

Definition at line 61 of file theme.cpp.

Referenced by anonymous_namespace{client.cpp}::LoginListener::action(), Game::addWatermark(), BrowserBox::BrowserBox(), CheckBox::CheckBox(), Desktop::Desktop(), TextParticle::draw(), Being::drawSpeech(), TouchManager::drawText(), DropDown::DropDown(), Client::gameInit(), Widget2::getThemeCharColor(), Widget2::getThemeColor(), PlayerBox::init(), Label::init(), Tab::init(), Slider::init(), Button::init(), ScrollArea::init(), ListBox::ListBox(), TouchManager::loadButtons(), TouchManager::loadTouchItem(), LocalPlayer::LocalPlayer(), Pincode::Pincode(), Popup::Popup(), EquipmentWindow::postInit(), ProgressBar::ProgressBar(), RadioButton::RadioButton(), Being::setSpeech(), SkillRectangleListBox::SkillRectangleListBox(), Client::stateSwitchLogin1(), StaticBrowserBox::StaticBrowserBox(), TestLauncher::testDraw(), Text::Text(), TextField::TextField(), TextPreview::TextPreview(), ProgressBar::updateAlpha(), DropDown::updateAlpha(), Tab::updateAlpha(), Slider::updateAlpha(), TextField::updateAlpha(), ListBox::updateAlpha(), CheckBox::updateAlpha(), RadioButton::updateAlpha(), ScrollArea::updateAlpha(), Button::updateAlpha(), SkillRectangleListBox::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().