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-2019 The ManaPlus Developers
8  * Copyright (C) 2019-2021 Andrei Karas
9  *
10  * This file is part of The ManaPlus Client.
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <http://www.gnu.org/licenses/>.
24  */
25 
26 #include "gui/skin.h"
27 
28 #include "settings.h"
29 
31 
32 #include "resources/imagerect.h"
33 
34 #include "resources/image/image.h"
35 
36 #include "utils/delete2.h"
37 
38 #include "debug.h"
39 
41  const ImageRect *const restrict images,
42  const std::string &filePath, const std::string &name,
43  const int padding, const int titlePadding,
44  StringIntMap *restrict const options) :
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 }
64 
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 }
103 
104 void Skin::updateAlpha(const float minimumOpacityAllowed)
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 }
128 
129 int Skin::getMinWidth() const
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 }
141 
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 }
Image * grid[9]
Definition: imagerect.h:42
float guiAlpha
Definition: settings.h:131
~Skin()
Definition: skin.cpp:65
Image * mStickyImageUp
Definition: skin.h:129
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:40
int getMinWidth() const
Definition: skin.cpp:129
Image * mStickyImageDown
Definition: skin.h:130
StringIntMap * mOptions
Definition: skin.h:133
void updateAlpha(const float minimumOpacityAllowed)
Definition: skin.cpp:104
Image * mCloseImage
Definition: skin.h:127
int getMinHeight() const
Definition: skin.cpp:142
Image * mCloseImageHighlighted
Definition: skin.h:128
ImageRect * mBorder
Definition: skin.h:126
#define delete2(var)
Definition: delete2.h:25
#define restrict
Definition: localconsts.h:165
#define nullptr
Definition: localconsts.h:45
ItemOptionDb::OptionInfos mOptions
Settings settings
Definition: settings.cpp:32
std::map< std::string, int > StringIntMap
Definition: stringmap.h:28