ManaPlus
src
gui
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
30
#include "
enums/resources/imageposition.h
"
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
40
Skin::Skin
(
ImageRect
*
const
restrict
skin,
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
{
59
mCloseImageHighlighted
=
mCloseImage
;
60
if
(
mCloseImageHighlighted
!=
nullptr
)
61
mCloseImageHighlighted
->incRef();
62
}
63
}
64
65
Skin::~Skin
()
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
100
delete2
(
mOptions
)
101
delete2
(
mBorder
)
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() +
139
mBorder
->
grid
[
ImagePosition::UPPER_RIGHT
]->getWidth();
140
}
141
142
int
Skin::getMinHeight
()
const
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
}
ImageRect
Definition:
imagerect.h:32
ImageRect::grid
Image * grid[9]
Definition:
imagerect.h:42
Settings::guiAlpha
float guiAlpha
Definition:
settings.h:131
Skin::~Skin
~Skin()
Definition:
skin.cpp:65
Skin::mStickyImageUp
Image * mStickyImageUp
Definition:
skin.h:129
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:
skin.cpp:40
Skin::getMinWidth
int getMinWidth() const
Definition:
skin.cpp:129
Skin::mStickyImageDown
Image * mStickyImageDown
Definition:
skin.h:130
Skin::mOptions
StringIntMap * mOptions
Definition:
skin.h:133
Skin::updateAlpha
void updateAlpha(const float minimumOpacityAllowed)
Definition:
skin.cpp:104
Skin::mCloseImage
Image * mCloseImage
Definition:
skin.h:127
Skin::getMinHeight
int getMinHeight() const
Definition:
skin.cpp:142
Skin::mCloseImageHighlighted
Image * mCloseImageHighlighted
Definition:
skin.h:128
Skin::mBorder
ImageRect * mBorder
Definition:
skin.h:126
debug.h
delete2.h
delete2
#define delete2(var)
Definition:
delete2.h:25
image.h
imageposition.h
imagerect.h
restrict
#define restrict
Definition:
localconsts.h:165
nullptr
#define nullptr
Definition:
localconsts.h:45
ImagePosition::UPPER_RIGHT
@ UPPER_RIGHT
Definition:
imageposition.h:52
ImagePosition::LOWER_LEFT
@ LOWER_LEFT
Definition:
imageposition.h:56
ImagePosition::UPPER_LEFT
@ UPPER_LEFT
Definition:
imageposition.h:50
anonymous_namespace{itemoptiondb.cpp}::mOptions
ItemOptionDb::OptionInfos mOptions
Definition:
itemoptiondb.cpp:36
settings
Settings settings
Definition:
settings.cpp:32
settings.h
skin.h
StringIntMap
std::map< std::string, int > StringIntMap
Definition:
stringmap.h:28
Generated on Wed Mar 17 2021 19:19:06 for ManaPlus by
1.9.1