ManaPlus
Public Member Functions | Data Fields | Private Attributes
Skin Class Reference

#include <skin.h>

Public Member Functions

 Skin (ImageRect *const skin, const ImageRect *const images, const std::string &filePath, const std::string &name, const int padding, const int titlePadding, StringIntMap *const options)
 
 ~Skin ()
 
const std::string & getName () const
 
const std::string & getFilePath () const
 
const ImageRectgetBorder () const
 
const ImagegetCloseImage (const bool state) const
 
const ImagegetStickyImage (const bool state) const
 
int getMinWidth () const
 
int getMinHeight () const
 
void updateAlpha (const float minimumOpacityAllowed)
 
int getPadding () const
 
int getTitlePadding () const
 
int getOption (const std::string &name) const
 
int getOption (const std::string &name, const int def) const
 

Data Fields

int instances
 

Private Attributes

std::string mFilePath
 
std::string mName
 
ImageRectmBorder
 
ImagemCloseImage
 
ImagemCloseImageHighlighted
 
ImagemStickyImageUp
 
ImagemStickyImageDown
 
int mPadding
 
int mTitlePadding
 
StringIntMapmOptions
 

Detailed Description

Definition at line 36 of file skin.h.

Constructor & Destructor Documentation

◆ Skin()

Skin::Skin ( ImageRect *const  skin,
const ImageRect *const  images,
const std::string &  filePath,
const std::string &  name,
const int  padding,
const int  titlePadding,
StringIntMap *const  options 
)

Definition at line 40 of file skin.cpp.

44  :
45  instances(1),
46  mFilePath(filePath),
47  mName(name),
48  mBorder(skin),
49  mCloseImage(images != nullptr ? images->grid[0] : nullptr),
50  mCloseImageHighlighted(images != nullptr ? images->grid[1] : nullptr),
51  mStickyImageUp(images != nullptr ? images->grid[2] : nullptr),
52  mStickyImageDown(images != nullptr ? images->grid[3] : nullptr),
53  mPadding(padding),
54  mTitlePadding(titlePadding),
55  mOptions(options)
56 {
57  if (mCloseImageHighlighted == nullptr)
58  {
60  if (mCloseImageHighlighted != nullptr)
61  mCloseImageHighlighted->incRef();
62  }
63 }
Image * grid[9]
Definition: imagerect.h:42
int mTitlePadding
Definition: skin.h:132
int mPadding
Definition: skin.h:131
std::string mFilePath
Definition: skin.h:124
Image * mStickyImageUp
Definition: skin.h:129
int instances
Definition: skin.h:121
Image * mStickyImageDown
Definition: skin.h:130
StringIntMap * mOptions
Definition: skin.h:133
Image * mCloseImage
Definition: skin.h:127
Image * mCloseImageHighlighted
Definition: skin.h:128
std::string mName
Definition: skin.h:125
ImageRect * mBorder
Definition: skin.h:126

References mCloseImage, and mCloseImageHighlighted.

◆ ~Skin()

Skin::~Skin ( )

Definition at line 65 of file skin.cpp.

66 {
67  for (int i = 0; i < 9; i++)
68  {
69  if ((mBorder != nullptr) && (mBorder->grid[i] != nullptr))
70  {
71  mBorder->grid[i]->decRef();
72  mBorder->grid[i] = nullptr;
73  }
74  }
75 
76  if (mCloseImage != nullptr)
77  {
78  mCloseImage->decRef();
79  mCloseImage = nullptr;
80  }
81 
82  if (mCloseImageHighlighted != nullptr)
83  {
84  mCloseImageHighlighted->decRef();
85  mCloseImageHighlighted = nullptr;
86  }
87 
88  if (mStickyImageUp != nullptr)
89  {
90  mStickyImageUp->decRef();
91  mStickyImageUp = nullptr;
92  }
93 
94  if (mStickyImageDown != nullptr)
95  {
96  mStickyImageDown->decRef();
97  mStickyImageDown = nullptr;
98  }
99 
102 }
#define delete2(var)
Definition: delete2.h:25

References delete2, ImageRect::grid, mBorder, mCloseImage, mCloseImageHighlighted, mOptions, mStickyImageDown, and mStickyImageUp.

Member Function Documentation

◆ getBorder()

const ImageRect& Skin::getBorder ( ) const
inline

◆ getCloseImage()

const Image* Skin::getCloseImage ( const bool  state) const
inline

Returns the image used by a close button for this skin.

Definition at line 74 of file skin.h.

76  { return state ? mCloseImageHighlighted : mCloseImage; }

References mCloseImage, and mCloseImageHighlighted.

Referenced by Window::draw(), Window::safeDraw(), and Window::widgetResized().

◆ getFilePath()

const std::string& Skin::getFilePath ( ) const
inline

Returns the skin's xml file path.

Definition at line 62 of file skin.h.

63  { return mFilePath; }

References mFilePath.

◆ getMinHeight()

int Skin::getMinHeight ( ) const

Returns the minimum height which can be used with this skin.

Definition at line 142 of file skin.cpp.

143 {
144  if ((mBorder == nullptr) ||
145  (mBorder->grid[ImagePosition::UPPER_LEFT] == nullptr) ||
146  (mBorder->grid[ImagePosition::LOWER_LEFT] == nullptr))
147  {
148  return 1;
149  }
150 
151  return mBorder->grid[ImagePosition::UPPER_LEFT]->getHeight() +
152  mBorder->grid[ImagePosition::LOWER_LEFT]->getHeight();
153 }

References ImageRect::grid, ImagePosition::LOWER_LEFT, mBorder, and ImagePosition::UPPER_LEFT.

Referenced by Popup::setMinHeight(), and Window::setMinHeight().

◆ getMinWidth()

int Skin::getMinWidth ( ) const

Returns the minimum width which can be used with this skin.

Definition at line 129 of file skin.cpp.

130 {
131  if ((mBorder == nullptr) ||
132  (mBorder->grid[ImagePosition::UPPER_LEFT] == nullptr) ||
133  (mBorder->grid[ImagePosition::UPPER_RIGHT] == nullptr))
134  {
135  return 1;
136  }
137 
138  return mBorder->grid[ImagePosition::UPPER_LEFT]->getWidth() +
140 }

References ImageRect::grid, mBorder, ImagePosition::UPPER_LEFT, and ImagePosition::UPPER_RIGHT.

Referenced by Popup::setMinWidth(), and Window::setMinWidth().

◆ getName()

const std::string& Skin::getName ( ) const
inline

Returns the skin's name. Useful for giving a human friendly skin name if a dialog for skin selection for a specific window type is done.

Definition at line 56 of file skin.h.

57  { return mName; }

References mName.

◆ getOption() [1/2]

int Skin::getOption ( const std::string &  name) const
inline

◆ getOption() [2/2]

int Skin::getOption ( const std::string &  name,
const int  def 
) const
inline

Definition at line 113 of file skin.h.

115  {
116  if (mOptions->find(name) != mOptions->end())
117  return (*mOptions)[name];
118  return def;
119  }

References mOptions.

◆ getPadding()

int Skin::getPadding ( ) const
inline

◆ getStickyImage()

const Image* Skin::getStickyImage ( const bool  state) const
inline

Returns the image used by a sticky button for this skin.

Definition at line 81 of file skin.h.

83  { return state ? mStickyImageDown : mStickyImageUp; }

References mStickyImageDown, and mStickyImageUp.

Referenced by Window::draw(), Window::safeDraw(), and Window::widgetResized().

◆ getTitlePadding()

int Skin::getTitlePadding ( ) const
inline

Definition at line 103 of file skin.h.

104  { return mTitlePadding; }

References mTitlePadding.

Referenced by Window::Window().

◆ updateAlpha()

void Skin::updateAlpha ( const float  minimumOpacityAllowed)

Updates the alpha value of the skin

Definition at line 104 of file skin.cpp.

105 {
106  const float alpha = static_cast<float>(
107  std::max(static_cast<double>(minimumOpacityAllowed),
108  static_cast<double>(settings.guiAlpha)));
109 
110  if (mBorder != nullptr)
111  {
112  for (int i = 0; i < 9; i++)
113  {
114  if (mBorder->grid[i] != nullptr)
115  mBorder->grid[i]->setAlpha(alpha);
116  }
117  }
118 
119  if (mCloseImage != nullptr)
120  mCloseImage->setAlpha(alpha);
121  if (mCloseImageHighlighted != nullptr)
122  mCloseImageHighlighted->setAlpha(alpha);
123  if (mStickyImageUp != nullptr)
124  mStickyImageUp->setAlpha(alpha);
125  if (mStickyImageDown != nullptr)
126  mStickyImageDown->setAlpha(alpha);
127 }
float guiAlpha
Definition: settings.h:131
Settings settings
Definition: settings.cpp:32

References ImageRect::grid, Settings::guiAlpha, mBorder, mCloseImage, mCloseImageHighlighted, mStickyImageDown, mStickyImageUp, and settings.

Referenced by Theme::readSkin(), and Theme::updateAlpha().

Field Documentation

◆ instances

int Skin::instances

Definition at line 121 of file skin.h.

Referenced by Theme::unload().

◆ mBorder

ImageRect* Skin::mBorder
private

The window border and background

Definition at line 126 of file skin.h.

Referenced by getBorder(), getMinHeight(), getMinWidth(), updateAlpha(), and ~Skin().

◆ mCloseImage

Image* Skin::mCloseImage
private

Close Button Image

Definition at line 127 of file skin.h.

Referenced by getCloseImage(), Skin(), updateAlpha(), and ~Skin().

◆ mCloseImageHighlighted

Image* Skin::mCloseImageHighlighted
private

Highlighted close Button Image

Definition at line 128 of file skin.h.

Referenced by getCloseImage(), Skin(), updateAlpha(), and ~Skin().

◆ mFilePath

std::string Skin::mFilePath
private

File name path for the skin

Definition at line 124 of file skin.h.

Referenced by getFilePath().

◆ mName

std::string Skin::mName
private

Name of the skin to use

Definition at line 125 of file skin.h.

Referenced by getName().

◆ mOptions

StringIntMap* Skin::mOptions
private

Definition at line 133 of file skin.h.

Referenced by getOption(), and ~Skin().

◆ mPadding

int Skin::mPadding
private

Definition at line 131 of file skin.h.

Referenced by getPadding().

◆ mStickyImageDown

Image* Skin::mStickyImageDown
private

Sticky Button Image

Definition at line 130 of file skin.h.

Referenced by getStickyImage(), updateAlpha(), and ~Skin().

◆ mStickyImageUp

Image* Skin::mStickyImageUp
private

Sticky Button Image

Definition at line 129 of file skin.h.

Referenced by getStickyImage(), updateAlpha(), and ~Skin().

◆ mTitlePadding

int Skin::mTitlePadding
private

Definition at line 132 of file skin.h.

Referenced by getTitlePadding().


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