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

(7c6d372)

#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"

Go to the source code of this file.

Data Structures

struct  SkinParameter
 
struct  SkinHelper
 

Macros

#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 1079 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 1207 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 1199 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 1191 of file theme.cpp.

Referenced by Theme::loadInfo().

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:95
static std::string defaultThemePath
Definition: theme.cpp:55
void log(const char *const log_text,...)
Definition: logger.cpp:243

◆ readColor()

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

Definition at line 906 of file theme.cpp.

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

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

907 {
908  const int size = static_cast<int>(description.length());
909  if (size < 7 || description[0] != '#')
910  {
911  logger->log("Error, invalid theme color palette: %s",
912  description.c_str());
913  return Palette::BLACK;
914  }
915 
916  unsigned int v = 0;
917  for (int i = 1; i < 7; ++i)
918  {
919  signed const char c = description[i];
920  int n;
921 
922  if ('0' <= c && c <= '9')
923  {
924  n = c - '0';
925  }
926  else if ('A' <= c && c <= 'F')
927  {
928  n = c - 'A' + 10;
929  }
930  else if ('a' <= c && c <= 'f')
931  {
932  n = c - 'a' + 10;
933  }
934  else
935  {
936  logger->log("Error, invalid theme color palette: %s",
937  description.c_str());
938  return Palette::BLACK;
939  }
940 
941  v = (v << 4) | n;
942  }
943 
944  return Color(v);
945 }
static const Color BLACK
Definition: palette.h:47
Logger * logger
Definition: logger.cpp:95
Definition: color.h:74
void log(const char *const log_text,...)
Definition: logger.cpp:243

◆ readColorGradient()

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

Definition at line 947 of file theme.cpp.

References compareStrI(), and GradientType::STATIC.

Referenced by Theme::loadColors().

948 {
949  static const std::string grads[] =
950  {
951  "STATIC",
952  "PULSE",
953  "SPECTRUM",
954  "RAINBOW"
955  };
956 
957  if (grad.empty())
958  return GradientType::STATIC;
959 
960  for (int i = 0; i < 4; i++)
961  {
962  if (compareStrI(grad, grads[i]) != 0)
963  return static_cast<GradientTypeT>(i);
964  }
965 
966  return GradientType::STATIC;
967 }
int compareStrI(const std::string &a, const std::string &b)

◆ readColorType()

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

Definition at line 665 of file theme.cpp.

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

Referenced by Theme::loadColors().

666 {
667  static const std::string colors[CAST_SIZE(
669  {
670  "BROWSERBOX",
671  "BROWSERBOX_OUTLINE",
672  "SELFNICK",
673  "SELFNICK_OUTLINE",
674  "TEXT",
675  "TEXT_OUTLINE",
676  "CARET",
677  "SHADOW",
678  "OUTLINE",
679  "BORDER",
680  "PROGRESS_BAR",
681  "PROGRESS_BAR_OUTLINE",
682  "BUTTON",
683  "BUTTON_OUTLINE",
684  "BUTTON_DISABLED",
685  "BUTTON_DISABLED_OUTLINE",
686  "BUTTON_HIGHLIGHTED",
687  "BUTTON_HIGHLIGHTED_OUTLINE",
688  "BUTTON_PRESSED",
689  "BUTTON_PRESSED_OUTLINE",
690  "CHECKBOX",
691  "CHECKBOX_OUTLINE",
692  "DROPDOWN",
693  "DROPDOWN_OUTLINE",
694  "LABEL",
695  "LABEL_OUTLINE",
696  "LISTBOX",
697  "LISTBOX_OUTLINE",
698  "LISTBOX_SELECTED",
699  "LISTBOX_SELECTED_OUTLINE",
700  "RADIOBUTTON",
701  "RADIOBUTTON_OUTLINE",
702  "POPUP",
703  "POPUP_OUTLINE",
704  "TAB",
705  "TAB_OUTLINE",
706  "TAB_HIGHLIGHTED",
707  "TAB_HIGHLIGHTED_OUTLINE",
708  "TAB_SELECTED",
709  "TAB_SELECTED_OUTLINE",
710  "TEXTBOX",
711  "TEXTFIELD",
712  "TEXTFIELD_OUTLINE",
713  "WINDOW",
714  "WINDOW_OUTLINE",
715  "BATTLE_CHAT_TAB",
716  "BATTLE_CHAT_TAB_OUTLINE",
717  "CHANNEL_CHAT_TAB",
718  "CHANNEL_CHAT_TAB_OUTLINE",
719  "PARTY_CHAT_TAB",
720  "PARTY_CHAT_TAB_OUTLINE",
721  "PARTY_SOCIAL_TAB",
722  "PARTY_SOCIAL_TAB_OUTLINE",
723  "GUILD_CHAT_TAB",
724  "GUILD_CHAT_TAB_OUTLINE",
725  "GUILD_SOCIAL_TAB",
726  "GUILD_SOCIAL_TAB_OUTLINE",
727  "GM_CHAT_TAB",
728  "GM_CHAT_TAB_OUTLINE",
729  "BATTLE_CHAT_TAB_HIGHLIGHTED",
730  "BATTLE_CHAT_TAB_HIGHLIGHTED_OUTLINE",
731  "CHANNEL_CHAT_TAB_HIGHLIGHTED",
732  "CHANNEL_CHAT_TAB_HIGHLIGHTED_OUTLINE",
733  "PARTY_CHAT_TAB_HIGHLIGHTED",
734  "PARTY_CHAT_TAB_HIGHLIGHTED_OUTLINE",
735  "PARTY_SOCIAL_TAB_HIGHLIGHTED",
736  "PARTY_SOCIAL_TAB_HIGHLIGHTED_OUTLINE",
737  "GUILD_CHAT_TAB_HIGHLIGHTED",
738  "GUILD_CHAT_TAB_HIGHLIGHTED_OUTLINE",
739  "GUILD_SOCIAL_TAB_HIGHLIGHTED",
740  "GUILD_SOCIAL_TAB_HIGHLIGHTED_OUTLINE",
741  "GM_CHAT_TAB_HIGHLIGHTED",
742  "GM_CHAT_TAB_HIGHLIGHTED_OUTLINE",
743  "BATTLE_CHAT_TAB_SELECTED",
744  "BATTLE_CHAT_TAB_SELECTED_OUTLINE",
745  "CHANNEL_CHAT_TAB_SELECTED",
746  "CHANNEL_CHAT_TAB_SELECTED_OUTLINE",
747  "PARTY_CHAT_TAB_SELECTED",
748  "PARTY_CHAT_TAB_SELECTED_OUTLINE",
749  "PARTY_SOCIAL_TAB_SELECTED",
750  "PARTY_SOCIAL_TAB_SELECTED_OUTLINE",
751  "GUILD_CHAT_TAB_SELECTED",
752  "GUILD_CHAT_TAB_SELECTED_OUTLINE",
753  "GUILD_SOCIAL_TAB_SELECTED",
754  "GUILD_SOCIAL_TAB_SELECTED_OUTLINE",
755  "GM_CHAT_TAB_SELECTED",
756  "GM_CHAT_TAB_SELECTED_OUTLINE",
757  "BACKGROUND",
758  "BACKGROUND_GRAY",
759  "SCROLLBAR_GRAY",
760  "DROPDOWN_SHADOW",
761  "HIGHLIGHT",
762  "HIGHLIGHT_OUTLINE",
763  "TAB_FLASH",
764  "TAB_FLASH_OUTLINE",
765  "TAB_PLAYER_FLASH",
766  "TAB_PLAYER_FLASH_OUTLINE",
767  "SHOP_WARNING",
768  "ITEM_EQUIPPED",
769  "ITEM_EQUIPPED_OUTLINE",
770  "ITEM_NOT_EQUIPPED",
771  "ITEM_NOT_EQUIPPED_OUTLINE",
772  "CHAT",
773  "CHAT_OUTLINE",
774  "GM",
775  "GM_OUTLINE",
776  "GLOBAL",
777  "GLOBAL_OUTLINE",
778  "PLAYER",
779  "PLAYER_OUTLINE",
780  "WHISPER_TAB",
781  "WHISPER_TAB_OUTLINE",
782  "WHISPER_TAB_OFFLINE",
783  "WHISPER_TAB_OFFLINE_OUTLINE",
784  "WHISPER_TAB_HIGHLIGHTED",
785  "WHISPER_TAB_HIGHLIGHTED_OUTLINE",
786  "WHISPER_TAB_OFFLINE_HIGHLIGHTED",
787  "WHISPER_TAB_OFFLINE_HIGHLIGHTED_OUTLINE",
788  "WHISPER_TAB_SELECTED",
789  "WHISPER_TAB_SELECTED_OUTLINE",
790  "WHISPER_TAB_OFFLINE_SELECTED",
791  "WHISPER_TAB_OFFLINE_SELECTED_OUTLINE",
792  "IS",
793  "IS_OUTLINE",
794  "SERVER",
795  "SERVER_OUTLINE",
796  "LOGGER",
797  "LOGGER_OUTLINE",
798  "HYPERLINK",
799  "HYPERLINK_OUTLINE",
800  "UNKNOWN_ITEM",
801  "UNKNOWN_ITEM_OUTLINE",
802  "GENERIC",
803  "GENERIC_OUTLINE",
804  "HEAD",
805  "HEAD_OUTLINE",
806  "USABLE",
807  "USABLE_OUTLINE",
808  "TORSO",
809  "TORSO_OUTLINE",
810  "ONEHAND",
811  "ONEHAND_OUTLINE",
812  "LEGS",
813  "LEGS_OUTLINE",
814  "FEET",
815  "FEET_OUTLINE",
816  "TWOHAND",
817  "TWOHAND_OUTLINE",
818  "SHIELD",
819  "SHIELD_OUTLINE",
820  "RING",
821  "RING_OUTLINE",
822  "NECKLACE",
823  "NECKLACE_OUTLINE",
824  "ARMS",
825  "ARMS_OUTLINE",
826  "AMMO",
827  "AMMO_OUTLINE",
828  "SERVER_VERSION_NOT_SUPPORTED",
829  "SERVER_VERSION_NOT_SUPPORTED_OUTLINE",
830  "WARNING",
831  "WARNING_OUTLINE",
832  "CHARM",
833  "CHARM_OUTLINE",
834  "CARD",
835  "CARD_OUTLINE",
836  "PLAYER_ADVANCED",
837  "PLAYER_ADVANCED_OUTLINE",
838  "BUBBLE_NAME",
839  "BUBBLE_NAME_OUTLINE",
840  "BUBBLE_TEXT",
841  "BUBBLE_TEXT_OUTLINE",
842  "BLACK",
843  "BLACK_OUTLINE",
844  "RED",
845  "RED_OUTLINE",
846  "GREEN",
847  "GREEN_OUTLINE",
848  "BLUE",
849  "BLUE_OUTLINE",
850  "ORANGE",
851  "ORANGE_OUTLINE",
852  "YELLOW",
853  "YELLOW_OUTLINE",
854  "PINK",
855  "PINK_OUTLINE",
856  "PURPLE",
857  "PURPLE_OUTLINE",
858  "GRAY",
859  "GRAY_OUTLINE",
860  "BROWN",
861  "BROWN_OUTLINE",
862  "STATUSBAR_ON",
863  "STATUSBAR_OFF",
864  "TABLE_BACKGROUND",
865  "SLOTS_BAR",
866  "SLOTS_BAR_OUTLINE",
867  "HP_BAR",
868  "HP_BAR_OUTLINE",
869  "MP_BAR",
870  "MP_BAR_OUTLINE",
871  "NO_MP_BAR",
872  "NO_MP_BAR_OUTLINE",
873  "XP_BAR",
874  "XP_BAR_OUTLINE",
875  "WEIGHT_BAR",
876  "WEIGHT_BAR_OUTLINE",
877  "MONEY_BAR",
878  "MONEY_BAR_OUTLINE",
879  "ARROWS_BAR",
880  "ARROWS_BAR_OUTLINE",
881  "STATUS_BAR",
882  "STATUS_BAR_OUTLINE",
883  "JOB_BAR",
884  "JOB_BAR_OUTLINE",
885  "OLDCHAT",
886  "OLDCHAT_OUTLINE",
887  "AWAYCHAT",
888  "AWAYCHAT_OUTLINE",
889  "SKILL_COOLDOWN",
890  "TEXT_DISABLED",
891  "TEXT_DISABLED_OUTLINE"
892  };
893 
894  if (type.empty())
895  return -1;
896 
897  for (int i = 0; i < CAST_S32(ThemeColorId::THEME_COLORS_END); i++)
898  {
899  if (compareStrI(type, colors[i]) == 0)
900  return i;
901  }
902 
903  return -1;
904 }
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 969 of file theme.cpp.

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

Referenced by Theme::loadColors().

970 {
971  static const std::string colors[CAST_SIZE(
973  {
974  "HP",
975  "HP_POISON",
976  "MP",
977  "NO_MP",
978  "EXP",
979  "INVY_SLOTS",
980  "WEIGHT",
981  "JOB",
982  "UPDATE",
983  "MONEY",
984  "ARROWS",
985  "STATUS"
986  };
987 
988  if (type.empty())
989  return -1;
990 
991  for (int i = 0; i < CAST_S32(ProgressColorId::THEME_PROG_END); i++)
992  {
993  if (compareStrI(type, colors[i]) == 0)
994  return i;
995  }
996 
997  return -1;
998 }
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(), 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(), Popup::~Popup(), ProgressBar::~ProgressBar(), RadioButton::~RadioButton(), StaticBrowserBox::~StaticBrowserBox(), Tab::~Tab(), TextField::~TextField(), TextPreview::~TextPreview(), Window::~Window(), and WindowMenu::~WindowMenu().