1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
|
#include "Button.hpp"
//Constructor
//
CButton::CButton()
{
m_ActiveScale = 1.0f;
m_PressedScale = 1.0f;
m_MainColor.White;
m_ActiveColor.White;
m_MainText.setString("Button");
m_MainText.setColor(sf::Color::Black);
m_MainTextColor.Black;
m_ActiveTextColor.Black;
m_ActiveText = m_MainText;
m_Rectangle.setOutlineColor(sf::Color::Black);
m_Rectangle.setFillColor(sf::Color::White);
m_Rectangle.setOutlineThickness(1.0f);
m_Active = false;
m_Pressed = false;
}
/*
//Constructor
//
CButton::CButton(int xPos, int yPos, int Width, int Height, const std::string &MainText, const sf::Font &Font)
{
m_MainText.setString(MainText);
m_Rectangle.setSize(sf::Vector2f(Width, Height));
m_Rectangle.setPosition(static_cast<int> (xPos), static_cast<int> (yPos));
m_ActiveScale = 1.0f;
m_PressedScale = 1.0f;
m_MainColor.White;
m_ActiveColor.White;
m_MainTextColor.Black;
m_ActiveTextColor.Black;
m_ActiveText = m_MainText;
m_MainText.setFont(Font);
m_MainText.setPosition(Height, Width);
m_ActiveText.setPosition(Height, Width);
m_Rectangle.setOutlineColor(sf::Color::Black);
m_Rectangle.setFillColor(sf::Color::White);
m_Rectangle.setOutlineThickness(1.0f);
m_Active = false;
m_Pressed = false;
}//Constructor
//Constructor
//
//sets also the main Color
//
CButton::CButton(int xPos, int yPos, int Width, int Height, const std::string& MainText, const sf::Font& Font, const sf::Color &MainColor)
{
m_MainText.setString(MainText);
m_Rectangle.setSize(sf::Vector2f(Width, Height));
m_Rectangle.setPosition(static_cast<int> (xPos), static_cast<int> (yPos));
m_ActiveScale = 1.0f;
m_PressedScale = 1.0f;
m_MainColor.Black;
m_ActiveColor.Black;
m_MainTextColor.White;
m_ActiveTextColor.White;
m_ActiveText = m_MainText;
m_MainText.setFont(Font);
m_MainText.setPosition(Height, Width);
m_ActiveText.setPosition(Height, Width);
m_Rectangle.setOutlineColor(sf::Color::Black);
m_Rectangle.setFillColor(MainColor);
m_Rectangle.setOutlineThickness(1.0f);
m_Active = false;
m_Pressed = false;
}//Constructor
*/
//Destructor
//
CButton::~CButton()
{
std::cerr << "Destructor of an instance of CButton\n";
}//Destructor
//setPosition
//
//setsPosition of the Button
//
void CButton::setPosition(int xPos, int yPos)
{
m_Rectangle.setPosition(static_cast<int>(xPos), static_cast<int>(yPos));
m_MainText.setPosition(static_cast<int>(xPos), static_cast<int>(yPos));
m_ActiveText.setPosition(static_cast<int>(xPos), static_cast<int>(yPos));
}//setPosition
//setSize
//
//sets the size (Width and Height) of the Button
//
void CButton::setSize(int Width, int Height)
{
m_Rectangle.setSize(sf::Vector2f(Width, Height));
}//setSize
//setActiveScale
//
//sets the amount the Buttons size changes when the mousepointer is over it
//
void CButton::setActiveScale(float Scale)
{
m_ActiveScale = Scale;
}//setActiveScale
//setPressedScale
//
//sets the amount the Buttons size changes when it's pressed(broken)
//
void CButton::setPressedScale(float Scale)
{
m_PressedScale = Scale;
}//setPressedScale
//setMainColor
//
//sets the Color shown when the Button is inactive
//
void CButton::setMainColor(const sf::Color &Color)
{
m_MainColor = Color;
}//setMainColor
//setOutlineColor
//
//sets the Color of the Outline
//
void CButton::setOutlineColor(const sf::Color &Color)
{
m_OutlineColor = Color;
}//setOutlineColor
//setMainString
//
//sets the text shown when the Button is inactive
//
void CButton::setMainString(const std::string &String)
{
m_MainText.setString(String);
}//setMainString
//setMainStringColor
//
//sets the Color of the text
//
void CButton::setMainStringColor(const sf::Color& Color)
{
m_MainText.setColor(Color);
}//setMainStringColor
//setActiveString
//
//sets the text shown when the mousepointer is over the Button
//
void CButton::setActiveString(const std::string &String)
{
m_ActiveText.setString(String);
}//setActiveString
//setActiveStringColor
//
//sets the Color of the text
//
void CButton::setActiveStringColor(const sf::Color &Color)
{
m_ActiveText.setColor(Color);
}//setActiveColor
//setOutlineThicknes
//
//sets the Thickness of the outline
//
void CButton::setOutlineThickness(float OutlineThickness)
{
m_Rectangle.setOutlineThickness(OutlineThickness);
}//setOutlineThickness
//setFont
//
//sets the Font of the text shown on the Button
//
void CButton::setFont(const sf::Font &Font)
{
m_MainText.setFont(Font);
m_ActiveText.setFont(Font);
}//setFont
//getXPos
//
//returns the X-Position of the Button
//
int CButton::getXPos()
{
sf::Vector2f Pos = m_Rectangle.getPosition();
int xPos = static_cast<int>(Pos.x);
return xPos;
}//getXPos
//getYPos
//
//returns the Y-Position of the Button
//
int CButton::getYPos()
{
sf::Vector2f Pos = m_Rectangle.getPosition();
int yPos = static_cast<int>(Pos.y);
return yPos;
}//getYPos
//getWidth
//
//returns the Width of the Button
//
int CButton::getWidth()
{
int Width = static_cast<int> (m_Rectangle.getSize().x);
return Width;
}//getWidth
//getHeight
//
//returns the Height of the Button
//
int CButton::getHeight()
{
int Height = static_cast<int> (m_Rectangle.getSize().y);
return Height;
}//getHeight
//getMainColor
//
//return the MainColor of the Button
//
sf::Color CButton::getMainColor()
{
return m_MainColor;
}//getMainColor
//getOutlineColor
//
//returns the OutlineColor of the Button
//
sf::Color CButton::getOutlineColor()
{
return m_OutlineColor;
}//getOutlineColor
//getActiveScale
//
//returns the amount the Buttons size increases when the mousepointer is over it
//
float CButton::getActiveScale()
{
return m_ActiveScale;
}//getActiveScale
//getMainText
//
//returns the string, which is displayed when the Button is inactive
//
std::string CButton::getMainText()
{
return m_MainText.getString();
}//getMainText
//getActiveText
//
//returns the string, which is displayed when the Button is active
//
std::string CButton::getActiveText()
{
return m_ActiveText.getString();
}//getActiveText
//getOutlineThickness
//
//returns the Thickness of the Outline
//
float CButton::getOutlineThickness()
{
return m_Rectangle.getOutlineThickness();
}//getOutlineThickness
//isActive
//
//returns true when the Button is active
//
bool CButton::isActive(float MouseXPos, float MouseYPos)
{
sf::Vector2f MousePos;
MousePos.x = MouseXPos;
MousePos.y = MouseYPos;
if(MousePos.x >= m_Rectangle.getPosition().x && MousePos.y >= m_Rectangle.getPosition().y)
{
if(MousePos.x <= ((m_Rectangle.getPosition().x) + (m_Rectangle.getSize().x)) && MousePos.y <= ((m_Rectangle.getPosition().y) + (m_Rectangle.getSize().y)))
{
m_Active = true;
}
else
{
m_Active = false;
}
}
else
{
m_Active = false;
}
return m_Active;
}//isActive
//isPressed
//
//returns true when the Button is Pressed (Suprise)
//
bool CButton::isPressed()
{
if(m_Active == true && sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
m_Pressed = true;
}
else
{
m_Pressed = false;
}
return m_Pressed;
}//isPressed
//move
//
//moves the Button by a specific amount pixel
//
void CButton::move(int x, int y)
{
m_Rectangle.move(static_cast<float>(x), static_cast<float>(y));
}//move
//draw(broken)
//
//makes the Button drawable
//
void CButton::draw(sf::RenderTarget &target, sf::RenderStates states)const
{
target.draw(m_Rectangle, states); //Draw Rect here
if(m_Active)
target.draw(m_ActiveText, states);
else
target.draw(m_MainText, states);
}//draw
|