Skip to content

Commit ed5edbc

Browse files
committed
Fixed GUI use of libraries
Now GUI classes, that need fonts will be disabled, if not found
1 parent d96a688 commit ed5edbc

22 files changed

+134
-98
lines changed

src/GUI/animation.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@
33
* <nik.kazankov.05@mail.ru>
44
*/
55

6-
76
#include "baseGUI.hpp"
87

8+
#if (USE_SDL_IMAGE) && (PRELOAD_ANIMATIONS)
9+
910

10-
#if ANI_count
11-
// GIF animation class
12-
GUI::GIFAnimation::GIFAnimation(SDL_Rect _rect, ANI_names _type)
11+
GUI::Animation::Animation(SDL_Rect _rect, ANI_names _type)
1312
: dest(_dest), type(_type), frame(0), prevTick(0) {}
1413

15-
GUI::GIFAnimation::~GIFAnimation() {
14+
GUI::Animation::~Animation() {
1615
SDL_DestroyTexture(texture);
1716
}
1817

19-
void GUI::GIFAnimation::blit() {
18+
void GUI::Animation::blit() {
2019
if (SDL_GetTicks() > prevTick) {
2120
static unsigned frame = (frame + 1) % Animations[type]->count;
2221
window.destroy(texture);
2322
texture = window.createTexture(Animations[type]->frames[frame], false);
2423
prevTick = SDL_GetTicks() + Animations[type]->delays[frame] / 2;
2524
}
2625
}
27-
#endif
26+
27+
#endif // (USE_SDL_IMAGE) && (PRELOAD_ANIMATIONS)

src/GUI/baseGUI.hpp

Lines changed: 66 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -42,54 +42,6 @@ namespace GUI {
4242
};
4343

4444

45-
// Static text on screen
46-
class StaticText : public TextureTemplate {
47-
public:
48-
StaticText(const Window& window, float X, float Y, const LanguagedText texts,
49-
float height = Height::Main, Color color = WHITE, Aligment aligment = Aligment::Midle);
50-
~StaticText();
51-
};
52-
53-
54-
// Static text on screen
55-
class HighlightedStaticText : public TextureTemplate {
56-
public:
57-
HighlightedStaticText(const Window& window, float X, float Y, const LanguagedText texts, int frameThickness,
58-
float height = Height::Main, Color color = WHITE, Aligment aligment = Aligment::Midle);
59-
~HighlightedStaticText();
60-
};
61-
62-
63-
// Dynamicly updated text on screen
64-
class DynamicText : public TextureTemplate {
65-
private:
66-
const LanguagedText texts; // Text to create from
67-
const float posX; // Relative positions on screen
68-
const Aligment aligment; // Aligment type to improve displasment
69-
const Color color; // Base draw color
70-
const float height; // Height of text to draw
71-
72-
public:
73-
DynamicText(const Window& window, float X, float Y, const LanguagedText texts,
74-
float height = Height::Main, Color color = WHITE, Aligment aligment = Aligment::Midle);
75-
~DynamicText();
76-
template <typename ...Args>
77-
void setValues(Args&& ...args) {
78-
// Checking for all chars
79-
char buffer[100];
80-
std::snprintf(buffer, sizeof(buffer), texts.getString().c_str(), args...);
81-
82-
// Creating surface with text
83-
texture = window.createTexture(Fonts::Main, height, buffer, 0, color);
84-
85-
// Moving draw rect to new place
86-
rect.w = texture->w;
87-
rect.h = texture->h;
88-
rect.x = window.getWidth() * posX - (rect.w * (unsigned)aligment / 2);
89-
}
90-
};
91-
92-
9345
// Class of slider bar with point on it to control need parameter
9446
class Slider : public TextureTemplate {
9547
private:
@@ -107,13 +59,6 @@ namespace GUI {
10759
};
10860

10961

110-
// Class of buttons with image on it
111-
class ImageButton : public TextureTemplate {
112-
public:
113-
ImageButton(const Window& window, float X, float Y, float width, Textures name);
114-
};
115-
116-
11762
// Class of rounded backplate for better understability
11863
class RoundedBackplate : public TextureTemplate {
11964
public:
@@ -136,22 +81,82 @@ namespace GUI {
13681
};
13782

13883

139-
// GIF-animations
140-
#if ANI_count
141-
class GIFAnimation : public TextureTemplate {
84+
// Textures
85+
#if (USE_SDL_IMAGE) && (PRELOAD_TEXTURES)
86+
// Class of buttons with image on it
87+
class ImageButton : public TextureTemplate {
88+
public:
89+
ImageButton(const Window& window, float X, float Y, float width, Textures name);
90+
};
91+
#endif
92+
93+
94+
// Animations
95+
#if (USE_SDL_IMAGE) && (PRELOAD_ANIMATIONS)
96+
class Animation : public TextureTemplate {
14297
private:
14398
const Uint8 type;
14499
Uint64 prevTick;
145100
const SDL_FRect dest;
146101

147102
public:
148-
GIFAnimation(const Window& window, SDL_Rect destination, ANI_names type);
149-
~GIFAnimation();
103+
Animation(const Window& window, SDL_FRect destination, ANI_names type);
104+
~Animation();
150105
void blit() const;
151106
};
152107
#endif
153108

154109

110+
// Text part
111+
#if (USE_SDL_FONT) && (PRELOAD_FONTS)
112+
// Static text on screen
113+
class StaticText : public TextureTemplate {
114+
public:
115+
StaticText(const Window& window, float X, float Y, const LanguagedText texts,
116+
float height = Height::Main, Color color = WHITE, Aligment aligment = Aligment::Midle);
117+
~StaticText();
118+
};
119+
120+
121+
// Static text on screen
122+
class HighlightedStaticText : public TextureTemplate {
123+
public:
124+
HighlightedStaticText(const Window& window, float X, float Y, const LanguagedText texts, int frameThickness,
125+
float height = Height::Main, Color color = WHITE, Aligment aligment = Aligment::Midle);
126+
~HighlightedStaticText();
127+
};
128+
129+
130+
// Dynamicly updated text on screen
131+
class DynamicText : public TextureTemplate {
132+
private:
133+
const LanguagedText texts; // Text to create from
134+
const float posX; // Relative positions on screen
135+
const Aligment aligment; // Aligment type to improve displasment
136+
const Color color; // Base draw color
137+
const float height; // Height of text to draw
138+
139+
public:
140+
DynamicText(const Window& window, float X, float Y, const LanguagedText texts,
141+
float height = Height::Main, Color color = WHITE, Aligment aligment = Aligment::Midle);
142+
~DynamicText();
143+
template <typename ...Args>
144+
void setValues(Args&& ...args) {
145+
// Checking for all chars
146+
char buffer[100];
147+
std::snprintf(buffer, sizeof(buffer), texts.getString().c_str(), args...);
148+
149+
// Creating surface with text
150+
texture = window.createTexture(Fonts::Main, height, buffer, 0, color);
151+
152+
// Moving draw rect to new place
153+
rect.w = texture->w;
154+
rect.h = texture->h;
155+
rect.x = window.getWidth() * posX - (rect.w * (unsigned)aligment / 2);
156+
}
157+
};
158+
159+
155160
// Class of field, where user can type text
156161
template <unsigned bufferSize = 16>
157162
class TypeField : public TextureTemplate {
@@ -237,5 +242,6 @@ namespace GUI {
237242
void update();
238243
void reset();
239244
};
245+
#endif // (USE_SDL_FONT) && (PRELOAD_FONTS)
240246

241247
} // namespace GUI

src/GUI/dynamicText.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
* <nik.kazankov.05@mail.ru>
44
*/
55

6-
#include <sstream>
76
#include "baseGUI.hpp"
87

8+
#if (USE_SDL_FONT) && (PRELOAD_FONTS)
9+
910

1011
GUI::DynamicText::DynamicText(const Window& _window, float _X, float _Y,
1112
const LanguagedText _texts, float _height, Color _color, Aligment _aligment)
@@ -28,3 +29,5 @@ height(_height) {
2829
GUI::DynamicText::~DynamicText() {
2930
SDL_DestroyTexture(texture);
3031
}
32+
33+
#endif // (USE_SDL_FONT) && (PRELOAD_FONTS)

src/GUI/highlightedStaticText.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include "baseGUI.hpp"
77

8+
#if (USE_SDL_FONT) && (PRELOAD_FONTS)
9+
810

911
GUI::HighlightedStaticText::HighlightedStaticText(const Window& _window, float _X, float _Y,
1012
const LanguagedText _texts, int frame, float _height, Color _color, Aligment _aligment)
@@ -40,3 +42,5 @@ GUI::HighlightedStaticText::HighlightedStaticText(const Window& _window, float _
4042
GUI::HighlightedStaticText::~HighlightedStaticText() {
4143
SDL_DestroyTexture(texture);
4244
}
45+
46+
#endif // (USE_SDL_FONT) && (PRELOAD_FONTS)

src/GUI/imageButton.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include "baseGUI.hpp"
77

8+
#if (USE_SDL_IMAGE) && (PRELOAD_TEXTURES)
9+
810

911
GUI::ImageButton::ImageButton(const Window& _window, float _X, float _Y, float _width, Textures _index)
1012
: TextureTemplate(_window) {
@@ -19,3 +21,5 @@ GUI::ImageButton::ImageButton(const Window& _window, float _X, float _Y, float _
1921
rect.x = window.getWidth() * _X - rect.w / 2;
2022
rect.y = window.getHeight() * _Y - rect.h / 2;
2123
}
24+
25+
#endif // (USE_SDL_IMAGE) && (PRELOAD_TEXTURES)

src/GUI/infoBox.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include "baseGUI.hpp"
77

8+
#if (USE_SDL_FONT) && (PRELOAD_FONTS)
9+
810

911
GUI::InfoBox::InfoBox(const Window& _window, float _X, float _Y, const LanguagedText texts,
1012
float _size, Color _color, Aligment _aligment)
@@ -24,3 +26,5 @@ void GUI::InfoBox::update() {
2426
void GUI::InfoBox::reset() {
2527
counter = maxCounter;
2628
}
29+
30+
#endif // (USE_SDL_FONT) && (PRELOAD_FONTS)

src/GUI/interface.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#pragma once
77

88
// File for correct including
9-
#include <string>
109
#include "baseGUI.hpp"
1110
#include "typeField.cpp"
1211
#include "typeBox.cpp"

src/GUI/staticText.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include "baseGUI.hpp"
77

8+
#if (USE_SDL_FONT) && (PRELOAD_FONTS)
9+
810

911
// Class of static text
1012
GUI::StaticText::StaticText(const Window& _window, float _X, float _Y,
@@ -22,3 +24,5 @@ const LanguagedText _texts, float _height, Color _color, Aligment _aligment)
2224
GUI::StaticText::~StaticText() {
2325
SDL_DestroyTexture(texture);
2426
}
27+
28+
#endif // (USE_SDL_FONT) && (PRELOAD_FONTS)

src/GUI/textButton.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55

66
#include "baseGUI.hpp"
77

8+
#if (USE_SDL_FONT) && (PRELOAD_FONTS)
9+
810

9-
// Button class
1011
GUI::TextButton::TextButton(const Window& _window, float _X, float _Y, const LanguagedText _texts, float _size,
1112
Color _color, Aligment _aligment)
1213
: HighlightedStaticText(_window, _X, _Y, _texts, 1, _size, _color, _aligment),
@@ -16,3 +17,5 @@ void GUI::TextButton::blit() const {
1617
backplate.blit();
1718
window.blit(texture, rect);
1819
}
20+
21+
#endif // (USE_SDL_FONT) && (PRELOAD_FONTS)

src/GUI/typeBox.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include "baseGUI.hpp"
77

8+
#if (USE_SDL_FONT) && (PRELOAD_FONTS)
9+
810

911
template <unsigned bufferSize>
1012
GUI::TypeBox<bufferSize>::TypeBox(const Window& _window, float _posX, float _posY, const char *_startText,
@@ -26,3 +28,5 @@ template <unsigned bufferSize>
2628
bool GUI::TypeBox<bufferSize>::in(const Mouse _mouse) const {
2729
return backplate.in(_mouse);
2830
}
31+
32+
#endif // (USE_SDL_FONT) && (PRELOAD_FONTS)

0 commit comments

Comments
 (0)