Skip to content

Commit aa6e531

Browse files
committed
Updating window structure
Reworking global objects in project Clearing unused
1 parent 1572441 commit aa6e531

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+405
-288
lines changed

img/GUI/type_box.png

-161 Bytes
Binary file not shown.

src/GUI/baseGUI.hpp

Lines changed: 57 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,50 @@ namespace GUI {
1818
};
1919

2020

21-
// Graphic user interface template for other objects
21+
// Object, that will be drawn at screen
2222
class Template {
23+
protected:
24+
const Window& window;
25+
26+
public:
27+
Template(const Window& window);
28+
virtual void blit() const;
29+
};
30+
31+
32+
// Object with texture, that will be drawn
33+
class TextureTemplate : public Template {
2334
protected:
2435
SDL_Texture* texture;
2536
SDL_FRect rect;
2637

2738
public:
28-
Template();
29-
virtual void blit() const;
39+
TextureTemplate(const Window& window);
40+
void blit() const override;
3041
bool in(const Mouse mouse) const;
3142
};
3243

3344

3445
// Static text on screen
35-
class StaticText : public Template {
46+
class StaticText : public TextureTemplate {
3647
public:
37-
StaticText(float X, float Y, const LanguagedText texts,
48+
StaticText(const Window& window, float X, float Y, const LanguagedText texts,
3849
float size, Color color = WHITE, Aligment aligment = Aligment::Midle);
3950
~StaticText();
4051
};
4152

4253

4354
// Static text on screen
44-
class HighlightedStaticText : public Template {
55+
class HighlightedStaticText : public TextureTemplate {
4556
public:
46-
HighlightedStaticText(float X, float Y, const LanguagedText texts,
57+
HighlightedStaticText(const Window& window, float X, float Y, const LanguagedText texts,
4758
int frameThickness, float size, Color color = WHITE, Aligment aligment = Aligment::Midle);
4859
~HighlightedStaticText();
4960
};
5061

5162

5263
// Dynamicly updated text on screen
53-
class DynamicText : public Template {
64+
class DynamicText : public TextureTemplate {
5465
private:
5566
const LanguagedText texts; // Text to create from
5667
const float posX; // Relative positions on screen
@@ -59,7 +70,7 @@ namespace GUI {
5970
const float height; // Height of text to draw
6071

6172
public:
62-
DynamicText(float X, float Y, const LanguagedText texts,
73+
DynamicText(const Window& window, float X, float Y, const LanguagedText texts,
6374
float size = 20, Color color = WHITE, Aligment aligment = Aligment::Midle);
6475
~DynamicText();
6576
template <typename ...Args>
@@ -80,39 +91,50 @@ namespace GUI {
8091

8192

8293
// Class of slider bar with point on it to control need parameter
83-
class Slider : public Template {
94+
class Slider : public TextureTemplate {
8495
private:
8596
SDL_Texture *textureButton; // Texture of line (upper part of slider)
8697
SDL_FRect buttonRect; // Place for rendering upper part
8798
const unsigned maxValue; // Maximal value of state
8899

89100
public:
90101
// Create slide with need line and button images
91-
Slider(float X, float Y, float width, unsigned startValue, Textures lineImage = Textures::SliderLine,
92-
Textures buttonImage = Textures::SliderButton, unsigned max = 255);
102+
Slider(const Window& window, float X, float Y, float width, unsigned startValue,
103+
Textures lineImage = Textures::SliderLine, Textures buttonImage = Textures::SliderButton, unsigned max = 255);
93104
unsigned setValue(float mouseX); // Setting new state from mouse position
94105
unsigned scroll(float wheelY); // Checking mouse wheel action
95106
void blit() const override; // Drawing slider with need button position
96107
};
97108

98109

99110
// Class of buttons with image on it
100-
class ImageButton : public Template {
111+
class ImageButton : public TextureTemplate {
101112
public:
102-
ImageButton(float X, float Y, float width, Textures name);
113+
ImageButton(const Window& window, float X, float Y, float width, Textures name);
114+
};
115+
116+
117+
// Class of backplate for better understability
118+
class Backplate : public TextureTemplate {
119+
public:
120+
Backplate(const Window& window, float centerX, float centerY, float width, float height,
121+
float radius, float border, Color frontColor = GREY, Color backColor = BLACK);
122+
Backplate(const Window& window, const SDL_FRect& rect, float radius, float border,
123+
Color frontColor = GREY, Color backColor = BLACK);
124+
~Backplate();
103125
};
104126

105127

106128
// GIF-animations
107129
#if ANI_count
108-
class GIFAnimation : public Template {
130+
class GIFAnimation : public TextureTemplate {
109131
private:
110132
const Uint8 type;
111133
Uint64 prevTick;
112134
const SDL_FRect dest;
113135

114136
public:
115-
GIFAnimation(SDL_Rect destination, ANI_names type);
137+
GIFAnimation(const Window& window, SDL_Rect destination, ANI_names type);
116138
~GIFAnimation();
117139
void blit() const;
118140
};
@@ -121,14 +143,12 @@ namespace GUI {
121143

122144
// Class of field, where user can type text
123145
template <unsigned bufferSize = 16>
124-
class TypeField {
146+
class TypeField : public TextureTemplate {
125147
protected:
126148
// Class constants
127149
const int posX; // Relevant x position on screen
128150
const Aligment aligment; // Aligment type for correct placed position
129151
const Color textColor; // Color of typing text
130-
SDL_Texture* backTexture; // Texture of backplate
131-
const SDL_FRect backRect; // Rect of backplate
132152
TTF_Font* font; // Font for type text
133153

134154
// Variables
@@ -142,8 +162,6 @@ namespace GUI {
142162
char clipboardText[bufferSize+1]; // Copying string for clipboard use
143163
bool pressed = false; //
144164
bool selected = false; //
145-
SDL_Texture* textTexture; // Texture of text
146-
SDL_FRect textRect; // Rect of text
147165

148166
void select(float _mouseX); // Select last letter to create writing symbol
149167
void updateTexture(); // Creat new texture and update it position
@@ -152,8 +170,8 @@ namespace GUI {
152170
void copyToClipboard(); // Writing selected text to clipboard
153171

154172
public:
155-
TypeField(float posX, float posY, float height, const char *startText = "",
156-
Aligment aligment = Aligment::Midle, Color textColor = BLACK);
173+
TypeField(const Window& window, float posX, float posY, float height,
174+
const char *startText = "", Aligment aligment = Aligment::Midle, Color textColor = BLACK);
157175
~TypeField(); // Clearing font and texture
158176
void writeString(const char* str); // Function of writing any string to buffer at caret position
159177
void type(SDL_Keycode code); // Function of processing special keycodes
@@ -162,18 +180,24 @@ namespace GUI {
162180
void unclick(); // Function of resetting pressing
163181
const char* getString(); // Function of getting typed string
164182
void setString(const char* string); // Function for replace text with new string
165-
void blit() const; // Function for draw at screen
183+
void blit() const override; // Function for draw at screen
166184
bool in(const Mouse mouse) const; // Function of checking pressing
167185
};
168186

169-
// Class of backplate for
170-
class Backplate : public Template {
187+
188+
// Object for typying in text with backplate for visability
189+
template <unsigned bufferSize = 16>
190+
class TypeBox : public TypeField<bufferSize> {
191+
private:
192+
// Backplate part
193+
SDL_Texture* backTexture; // Texture of backplate
194+
const SDL_FRect backRect; // Rect of backplate
195+
171196
public:
172-
Backplate(float centerX, float centerY, float width, float height, float radius, float border,
173-
Color frontColor = GREY, Color backColor = BLACK);
174-
Backplate(const SDL_FRect& rect, float radius, float border, Color frontColor = GREY,
175-
Color backColor = BLACK);
176-
~Backplate();
197+
TypeBox(const Window& window, float posX, float posY, float height, const char *startText = "",
198+
Aligment aligment = Aligment::Midle, unsigned frameWidth = 2, Color textColor = BLACK);
199+
~TypeBox();
200+
void blit() const override; // Function for draw inputting text with backplate
177201
};
178202

179203

@@ -183,7 +207,7 @@ namespace GUI {
183207
const Backplate backplate;
184208

185209
public:
186-
TextButton(float X, float Y, const LanguagedText texts, float size,
210+
TextButton(const Window& window, float X, float Y, const LanguagedText texts, float size,
187211
Color color = WHITE, Aligment aligment = Aligment::Midle);
188212
void blit() const override;
189213
};
@@ -196,7 +220,7 @@ namespace GUI {
196220
static const unsigned maxCounter = 100;
197221

198222
public:
199-
InfoBox(float X, float Y, const LanguagedText texts,
223+
InfoBox(const Window& window, float X, float Y, const LanguagedText texts,
200224
float size, Color color = WHITE, Aligment aligment = Aligment::Midle);
201225
void update();
202226
void reset();

src/GUI/dynamicText.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
#include "baseGUI.hpp"
88

99

10-
GUI::DynamicText::DynamicText(float _X, float _Y,
10+
GUI::DynamicText::DynamicText(const Window& _window, float _X, float _Y,
1111
const LanguagedText _texts, float _height, Color _color, Aligment _aligment)
12-
: posX(_X),
12+
: TextureTemplate(_window),
13+
posX(_X),
1314
aligment(_aligment),
1415
color(_color),
1516
texts(_texts),

src/GUI/highlightedStaticText.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
#include "baseGUI.hpp"
77

88

9-
GUI::HighlightedStaticText::HighlightedStaticText(float _X, float _Y,
10-
const LanguagedText _texts, int frame, float _height, Color _color, Aligment _aligment) {
9+
GUI::HighlightedStaticText::HighlightedStaticText(const Window& _window, float _X, float _Y,
10+
const LanguagedText _texts, int frame, float _height, Color _color, Aligment _aligment)
11+
: TextureTemplate(_window) {
1112
// Creating texture of text
1213
TTF_Font* font = window.getFont(Fonts::Main);
1314
TTF_SetFontSize(font, _height);

src/GUI/imageButton.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
#include "baseGUI.hpp"
77

88

9-
GUI::ImageButton::ImageButton(float _X, float _Y, float _width, Textures _index) {
9+
GUI::ImageButton::ImageButton(const Window& _window, float _X, float _Y, float _width, Textures _index)
10+
: TextureTemplate(_window) {
1011
// Setting base texture
1112
texture = window.getTexture(_index);
1213

src/GUI/infoBox.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
#include "baseGUI.hpp"
77

88

9-
GUI::InfoBox::InfoBox(float _X, float _Y, const LanguagedText texts,
9+
GUI::InfoBox::InfoBox(const Window& _window, float _X, float _Y, const LanguagedText texts,
1010
float _size, Color _color, Aligment _aligment)
11-
: HighlightedStaticText(_X, _Y, texts, 2, _size, _color, _aligment) {
11+
: HighlightedStaticText(_window, _X, _Y, texts, 2, _size, _color, _aligment) {
1212
// Resetting transperance
1313
SDL_SetTextureAlphaMod(texture, 0);
1414
}

src/GUI/interface.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,4 @@
99
#include <string>
1010
#include "baseGUI.hpp"
1111
#include "typeField.cpp"
12-
13-
// Making sure, that important files included
14-
#include "../define.hpp"
15-
#include "../testing.hpp"
16-
#include "../data/macroses.hpp"
12+
#include "typeBox.cpp"

src/GUI/roundedBackplate.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77

88

99
// Class of backplates (smoothed rects)
10-
GUI::Backplate::Backplate(float _centerX, float _centerY, float _width, float _height,
10+
GUI::Backplate::Backplate(const Window& _window, float _centerX, float _centerY, float _width, float _height,
1111
float _rad, float _bor, Color _frontColor, Color _backColor)
12-
: Backplate({window.getWidth() * (_centerX - _width/2), window.getHeight() * (_centerY - _height/2),
13-
window.getWidth() * _width, window.getHeight() * _height}, _rad, _bor, _frontColor, _backColor) {}
12+
: Backplate(_window, {_window.getWidth() * (_centerX - _width/2), _window.getHeight() * (_centerY - _height/2),
13+
_window.getWidth() * _width, _window.getHeight() * _height}, _rad, _bor, _frontColor, _backColor) {}
1414

1515

16-
GUI::Backplate::Backplate(const SDL_FRect& _rect, float _rad, float _bor, Color _frontColor, Color _backColor) {
16+
GUI::Backplate::Backplate(const Window& _window, const SDL_FRect& _rect, float _rad, float _bor, Color _frontColor, Color _backColor)
17+
: TextureTemplate(_window) {
1718
// Creating new texture for drawing
1819
texture = window.createTexture(_rect.w, _rect.h);
1920
rect = _rect;

src/GUI/slider.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
#include "baseGUI.hpp"
77

88

9-
// Slider class
10-
GUI::Slider::Slider(float _X, float _Y, float _width, unsigned _startValue,
9+
GUI::Slider::Slider(const Window& _window, float _X, float _Y, float _width, unsigned _startValue,
1110
Textures _lineImage, Textures _buttonImage, unsigned _max)
12-
: maxValue(_max) {
11+
: TextureTemplate(_window),
12+
maxValue(_max) {
1313
// Getting need texture
1414
texture = window.getTexture(_lineImage);
1515
textureButton = window.getTexture(_buttonImage);

src/GUI/staticText.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88

99
// Class of static text
10-
GUI::StaticText::StaticText(float _X, float _Y, const LanguagedText _texts,
11-
float _height, Color _color, Aligment _aligment) {
10+
GUI::StaticText::StaticText(const Window& _window, float _X, float _Y,
11+
const LanguagedText _texts, float _height, Color _color, Aligment _aligment)
12+
: TextureTemplate(_window) {
1213
// Creating texture of text
1314
texture = window.createTexture(Fonts::Main, _height, _texts.getString().c_str(), 0, _color);
1415

0 commit comments

Comments
 (0)