ManaPlus
skin.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2008 The Legend of Mazzeroth Development Team
4  * Copyright (C) 2009 Aethyra Development Team
5  * Copyright (C) 2009 The Mana World Development Team
6  * Copyright (C) 2009-2010 The Mana Developers
7  * Copyright (C) 2011-2017 The ManaPlus Developers
8  *
9  * This file is part of The ManaPlus Client.
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <http://www.gnu.org/licenses/>.
23  */
24 
25 #include "gui/skin.h"
26 
27 #include "settings.h"
28 
30 
31 #include "resources/imagerect.h"
32 
33 #include "resources/image/image.h"
34 
35 #include "utils/delete2.h"
36 
37 #include "debug.h"
38 
40  const ImageRect *const restrict images,
41  const std::string &filePath, const std::string &name,
42  const int padding, const int titlePadding,
43  StringIntMap *restrict const options) :
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 }
63 
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 }
102 
103 void Skin::updateAlpha(const float minimumOpacityAllowed)
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 }
127 
128 int Skin::getMinWidth() const
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 }
140 
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 }
ItemOptionDb::OptionInfos mOptions
StringIntMap * mOptions
Definition: skin.h:132
int getMinHeight() const
Definition: skin.cpp:141
std::map< std::string, int > StringIntMap
Definition: stringmap.h:27
Image * mCloseImageHighlighted
Definition: skin.h:127
Image * mStickyImageUp
Definition: skin.h:128
#define delete2(var)
Definition: delete2.h:24
Settings settings
Definition: settings.cpp:31
virtual void setAlpha(const float alpha)
Definition: image.cpp:285
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: skin.cpp:39
Image * grid[9]
Definition: imagerect.h:41
ImageRect * mBorder
Definition: skin.h:125
#define nullptr
Definition: localconsts.h:44
~Skin()
Definition: skin.cpp:64
Image * mCloseImage
Definition: skin.h:126
virtual void incRef()
Definition: resource.cpp:37
int getWidth() const A_INLINE
Definition: image.h:116
#define restrict
Definition: localconsts.h:176
void updateAlpha(const float minimumOpacityAllowed=0.0F)
Definition: skin.cpp:103
float guiAlpha
Definition: settings.h:129
void decRef()
Definition: image.cpp:521
Image * mStickyImageDown
Definition: skin.h:129
int getHeight() const A_INLINE
Definition: image.h:122
int getMinWidth() const
Definition: skin.cpp:128