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=0.0F)
 
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 35 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 39 of file skin.cpp.

References Resource::incRef(), mCloseImage, and mCloseImageHighlighted.

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

◆ ~Skin()

Skin::~Skin ( )

Definition at line 64 of file skin.cpp.

References Image::decRef(), delete2, ImageRect::grid, mBorder, mCloseImage, mCloseImageHighlighted, mOptions, mStickyImageDown, and mStickyImageUp.

65 {
66  for (int i = 0; i < 9; i++)
67  {
68  if ((mBorder != nullptr) && (mBorder->grid[i] != nullptr))
69  {
70  mBorder->grid[i]->decRef();
71  mBorder->grid[i] = nullptr;
72  }
73  }
74 
75  if (mCloseImage != nullptr)
76  {
78  mCloseImage = nullptr;
79  }
80 
81  if (mCloseImageHighlighted != nullptr)
82  {
84  mCloseImageHighlighted = nullptr;
85  }
86 
87  if (mStickyImageUp != nullptr)
88  {
90  mStickyImageUp = nullptr;
91  }
92 
93  if (mStickyImageDown != nullptr)
94  {
96  mStickyImageDown = nullptr;
97  }
98 
100  delete2(mBorder);
101 }
StringIntMap * mOptions
Definition: skin.h:132
Image * mCloseImageHighlighted
Definition: skin.h:127
Image * mStickyImageUp
Definition: skin.h:128
#define delete2(var)
Definition: delete2.h:24
Image * grid[9]
Definition: imagerect.h:41
ImageRect * mBorder
Definition: skin.h:125
Image * mCloseImage
Definition: skin.h:126
void decRef()
Definition: image.cpp:521
Image * mStickyImageDown
Definition: skin.h:129

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 73 of file skin.h.

References mCloseImage, and mCloseImageHighlighted.

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

75  { return state ? mCloseImageHighlighted : mCloseImage; }
Image * mCloseImageHighlighted
Definition: skin.h:127
Image * mCloseImage
Definition: skin.h:126

◆ getFilePath()

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

Returns the skin's xml file path.

Definition at line 61 of file skin.h.

References mFilePath.

62  { return mFilePath; }
std::string mFilePath
Definition: skin.h:123

◆ getMinHeight()

int Skin::getMinHeight ( ) const

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

Definition at line 141 of file skin.cpp.

References Image::getHeight(), ImageRect::grid, ImagePosition::LOWER_LEFT, mBorder, and ImagePosition::UPPER_LEFT.

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

142 {
143  if ((mBorder == nullptr) ||
144  (mBorder->grid[ImagePosition::UPPER_LEFT] == nullptr) ||
145  (mBorder->grid[ImagePosition::LOWER_LEFT] == nullptr))
146  {
147  return 1;
148  }
149 
152 }
Image * grid[9]
Definition: imagerect.h:41
ImageRect * mBorder
Definition: skin.h:125
int getHeight() const A_INLINE
Definition: image.h:122

◆ getMinWidth()

int Skin::getMinWidth ( ) const

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

Definition at line 128 of file skin.cpp.

References Image::getWidth(), ImageRect::grid, mBorder, ImagePosition::UPPER_LEFT, and ImagePosition::UPPER_RIGHT.

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

129 {
130  if ((mBorder == nullptr) ||
131  (mBorder->grid[ImagePosition::UPPER_LEFT] == nullptr) ||
132  (mBorder->grid[ImagePosition::UPPER_RIGHT] == nullptr))
133  {
134  return 1;
135  }
136 
139 }
Image * grid[9]
Definition: imagerect.h:41
ImageRect * mBorder
Definition: skin.h:125
int getWidth() const A_INLINE
Definition: image.h:116

◆ 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 55 of file skin.h.

References mName.

56  { return mName; }
std::string mName
Definition: skin.h:124

◆ 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 112 of file skin.h.

References mOptions.

114  {
115  if (mOptions->find(name) != mOptions->end())
116  return (*mOptions)[name];
117  return def;
118  }
StringIntMap * mOptions
Definition: skin.h:132

◆ 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 80 of file skin.h.

References A_WARN_UNUSED, getMinHeight(), getMinWidth(), mStickyImageDown, mStickyImageUp, and updateAlpha().

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

82  { return state ? mStickyImageDown : mStickyImageUp; }
Image * mStickyImageUp
Definition: skin.h:128
Image * mStickyImageDown
Definition: skin.h:129

◆ getTitlePadding()

int Skin::getTitlePadding ( ) const
inline

Definition at line 102 of file skin.h.

References mTitlePadding.

Referenced by Window::Window().

103  { return mTitlePadding; }
int mTitlePadding
Definition: skin.h:131

◆ updateAlpha()

void Skin::updateAlpha ( const float  minimumOpacityAllowed = 0.0F)

Updates the alpha value of the skin

Definition at line 103 of file skin.cpp.

References ImageRect::grid, Settings::guiAlpha, mBorder, mCloseImage, mCloseImageHighlighted, mStickyImageDown, mStickyImageUp, Image::setAlpha(), and settings.

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

104 {
105  const float alpha = static_cast<float>(
106  std::max(static_cast<double>(minimumOpacityAllowed),
107  static_cast<double>(settings.guiAlpha)));
108 
109  if (mBorder != nullptr)
110  {
111  for (int i = 0; i < 9; i++)
112  {
113  if (mBorder->grid[i] != nullptr)
114  mBorder->grid[i]->setAlpha(alpha);
115  }
116  }
117 
118  if (mCloseImage != nullptr)
119  mCloseImage->setAlpha(alpha);
120  if (mCloseImageHighlighted != nullptr)
122  if (mStickyImageUp != nullptr)
123  mStickyImageUp->setAlpha(alpha);
124  if (mStickyImageDown != nullptr)
125  mStickyImageDown->setAlpha(alpha);
126 }
Image * mCloseImageHighlighted
Definition: skin.h:127
Image * mStickyImageUp
Definition: skin.h:128
Settings settings
Definition: settings.cpp:31
virtual void setAlpha(const float alpha)
Definition: image.cpp:285
Image * grid[9]
Definition: imagerect.h:41
ImageRect * mBorder
Definition: skin.h:125
Image * mCloseImage
Definition: skin.h:126
float guiAlpha
Definition: settings.h:129
Image * mStickyImageDown
Definition: skin.h:129

Field Documentation

◆ instances

int Skin::instances

Definition at line 120 of file skin.h.

Referenced by Theme::unload().

◆ mBorder

ImageRect* Skin::mBorder
private

The window border and background

Definition at line 125 of file skin.h.

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

◆ mCloseImage

Image* Skin::mCloseImage
private

Close Button Image

Definition at line 126 of file skin.h.

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

◆ mCloseImageHighlighted

Image* Skin::mCloseImageHighlighted
private

Highlighted close Button Image

Definition at line 127 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 123 of file skin.h.

Referenced by getFilePath().

◆ mName

std::string Skin::mName
private

Name of the skin to use

Definition at line 124 of file skin.h.

Referenced by getName().

◆ mOptions

StringIntMap* Skin::mOptions
private

Definition at line 132 of file skin.h.

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

◆ mPadding

int Skin::mPadding
private

Definition at line 130 of file skin.h.

Referenced by getPadding().

◆ mStickyImageDown

Image* Skin::mStickyImageDown
private

Sticky Button Image

Definition at line 129 of file skin.h.

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

◆ mStickyImageUp

Image* Skin::mStickyImageUp
private

Sticky Button Image

Definition at line 128 of file skin.h.

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

◆ mTitlePadding

int Skin::mTitlePadding
private

Definition at line 131 of file skin.h.

Referenced by getTitlePadding().


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