Skip to content

Commit 1b31bd5

Browse files
authored
Merge pull request #9 from kolyaka32/Dev-branch
Core project update
2 parents c09afef + 2eccadf commit 1b31bd5

Some content is hidden

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

71 files changed

+732
-288
lines changed

src/GUI/animation.cpp

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,35 @@
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)
13-
: dest(_dest), type(_type), frame(0), prevTick(0) {}
11+
GUI::Animation::Animation(const Window& _window, float _X, float _Y, float _W, float _H, Animations _type)
12+
: Animation(_window, {_X*window.getWidth(), _Y*window.getHeight(), _W*window.getWidth(), _H*window.getHeight()}, _type) {}
1413

15-
GUI::GIFAnimation::~GIFAnimation() {
14+
GUI::Animation::Animation(const Window& _window, const SDL_FRect& _dest, Animations _type)
15+
: TextureTemplate(_window),
16+
type(_type),
17+
prevTick(0),
18+
animation(window.getAnimation(_type)) {
19+
rect = _dest;
20+
texture = window.createTexture(animation->frames[0]);
21+
prevTick = getTime() + animation->delays[0];
22+
}
23+
24+
GUI::Animation::~Animation() {
1625
SDL_DestroyTexture(texture);
1726
}
1827

19-
void GUI::GIFAnimation::blit() {
28+
void GUI::Animation::update() {
2029
if (SDL_GetTicks() > prevTick) {
21-
static unsigned frame = (frame + 1) % Animations[type]->count;
22-
window.destroy(texture);
23-
texture = window.createTexture(Animations[type]->frames[frame], false);
24-
prevTick = SDL_GetTicks() + Animations[type]->delays[frame] / 2;
30+
frame = (frame + 1) % animation->count;
31+
SDL_DestroyTexture(texture);
32+
texture = window.createTexture(animation->frames[frame]);
33+
prevTick = getTime() + animation->delays[frame];
2534
}
2635
}
27-
#endif
36+
37+
#endif // (USE_SDL_IMAGE) && (PRELOAD_ANIMATIONS)

src/GUI/baseGUI.hpp

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

4444

45+
// Class of rounded backplate for better understability
46+
class RoundedBackplate : public TextureTemplate {
47+
public:
48+
RoundedBackplate(const Window& window, float centerX, float centerY, float width, float height,
49+
float radius, float border, Color frontColor = GREY, Color backColor = BLACK);
50+
RoundedBackplate(const Window& window, const SDL_FRect& rect, float radius, float border,
51+
Color frontColor = GREY, Color backColor = BLACK);
52+
~RoundedBackplate();
53+
};
54+
55+
56+
// Class with rectangular backplate for typeBox
57+
class RectBackplate : public TextureTemplate {
58+
public:
59+
RectBackplate(const Window& window, float centerX, float centerY, float width, float height,
60+
float border, Color frontColor = GREY, Color backColor = BLACK);
61+
RectBackplate(const Window& window, const SDL_FRect& rect,
62+
float border, Color frontColor = GREY, Color backColor = BLACK);
63+
~RectBackplate();
64+
};
65+
66+
67+
// Textures
68+
#if (USE_SDL_IMAGE) && (PRELOAD_TEXTURES)
69+
// Class of slider bar with point on it to control need parameter
70+
class Slider : public TextureTemplate {
71+
private:
72+
SDL_Texture *textureButton; // Texture of line (upper part of slider)
73+
SDL_FRect buttonRect; // Place for rendering upper part
74+
const unsigned maxValue; // Maximal value of state
75+
76+
public:
77+
// Create slide with need line and button images
78+
Slider(const Window& window, float X, float Y, float width, unsigned startValue,
79+
Textures lineImage = Textures::SliderLine, Textures buttonImage = Textures::SliderButton, unsigned max = 255);
80+
unsigned setValue(float mouseX); // Setting new state from mouse position
81+
unsigned scroll(float wheelY); // Checking mouse wheel action
82+
void blit() const override; // Drawing slider with need button position
83+
};
84+
85+
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 {
97+
private:
98+
const Animations type;
99+
const IMG_Animation* animation;
100+
unsigned frame = 0;
101+
timer prevTick;
102+
103+
public:
104+
Animation(const Window& window, float X, float Y, float width, float height, Animations type);
105+
Animation(const Window& window, const SDL_FRect& destination, Animations type);
106+
~Animation();
107+
void update();
108+
};
109+
#endif
110+
111+
112+
// Text part
113+
#if (USE_SDL_FONT) && (PRELOAD_FONTS)
45114
// Static text on screen
46115
class StaticText : public TextureTemplate {
47116
public:
@@ -90,68 +159,6 @@ namespace GUI {
90159
};
91160

92161

93-
// Class of slider bar with point on it to control need parameter
94-
class Slider : public TextureTemplate {
95-
private:
96-
SDL_Texture *textureButton; // Texture of line (upper part of slider)
97-
SDL_FRect buttonRect; // Place for rendering upper part
98-
const unsigned maxValue; // Maximal value of state
99-
100-
public:
101-
// Create slide with need line and button images
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);
104-
unsigned setValue(float mouseX); // Setting new state from mouse position
105-
unsigned scroll(float wheelY); // Checking mouse wheel action
106-
void blit() const override; // Drawing slider with need button position
107-
};
108-
109-
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-
117-
// Class of rounded backplate for better understability
118-
class RoundedBackplate : public TextureTemplate {
119-
public:
120-
RoundedBackplate(const Window& window, float centerX, float centerY, float width, float height,
121-
float radius, float border, Color frontColor = GREY, Color backColor = BLACK);
122-
RoundedBackplate(const Window& window, const SDL_FRect& rect, float radius, float border,
123-
Color frontColor = GREY, Color backColor = BLACK);
124-
~RoundedBackplate();
125-
};
126-
127-
128-
// Class with rectangular backplate for typeBox
129-
class RectBackplate : public TextureTemplate {
130-
public:
131-
RectBackplate(const Window& window, float centerX, float centerY, float width, float height,
132-
float border, Color frontColor = GREY, Color backColor = BLACK);
133-
RectBackplate(const Window& window, const SDL_FRect& rect,
134-
float border, Color frontColor = GREY, Color backColor = BLACK);
135-
~RectBackplate();
136-
};
137-
138-
139-
// GIF-animations
140-
#if ANI_count
141-
class GIFAnimation : public TextureTemplate {
142-
private:
143-
const Uint8 type;
144-
Uint64 prevTick;
145-
const SDL_FRect dest;
146-
147-
public:
148-
GIFAnimation(const Window& window, SDL_Rect destination, ANI_names type);
149-
~GIFAnimation();
150-
void blit() const;
151-
};
152-
#endif
153-
154-
155162
// Class of field, where user can type text
156163
template <unsigned bufferSize = 16>
157164
class TypeField : public TextureTemplate {
@@ -237,5 +244,6 @@ namespace GUI {
237244
void update();
238245
void reset();
239246
};
247+
#endif // (USE_SDL_FONT) && (PRELOAD_FONTS)
240248

241249
} // 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/slider.cpp

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

88

9+
#if (USE_SDL_IMAGE) && (PRELOAD_TEXTURES)
10+
911
GUI::Slider::Slider(const Window& _window, float _X, float _Y, float _width, unsigned _startValue,
1012
Textures _lineImage, Textures _buttonImage, unsigned _max)
1113
: TextureTemplate(_window),
@@ -52,3 +54,5 @@ unsigned GUI::Slider::scroll(float _wheelY) {
5254
}
5355
return 0;
5456
}
57+
58+
#endif // (USE_SDL_IMAGE) && (PRELOAD_TEXTURES)

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)

0 commit comments

Comments
 (0)