Skip to content

Commit 2463db3

Browse files
committed
Updated typeField class to typeBox
Separated backplate of typeField in own class
1 parent 41f322c commit 2463db3

File tree

12 files changed

+72
-48
lines changed

12 files changed

+72
-48
lines changed

src/GUI/baseGUI.hpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace GUI {
3838
public:
3939
TextureTemplate(const Window& window);
4040
void blit() const override;
41-
bool in(const Mouse mouse) const;
41+
virtual bool in(const Mouse mouse) const;
4242
};
4343

4444

@@ -114,14 +114,25 @@ namespace GUI {
114114
};
115115

116116

117-
// Class of backplate for better understability
118-
class Backplate : public TextureTemplate {
117+
// Class of rounded backplate for better understability
118+
class RoundedBackplate : public TextureTemplate {
119119
public:
120-
Backplate(const Window& window, float centerX, float centerY, float width, float height,
120+
RoundedBackplate(const Window& window, float centerX, float centerY, float width, float height,
121121
float radius, float border, Color frontColor = GREY, Color backColor = BLACK);
122-
Backplate(const Window& window, const SDL_FRect& rect, float radius, float border,
122+
RoundedBackplate(const Window& window, const SDL_FRect& rect, float radius, float border,
123123
Color frontColor = GREY, Color backColor = BLACK);
124-
~Backplate();
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();
125136
};
126137

127138

@@ -181,30 +192,27 @@ namespace GUI {
181192
const char* getString(); // Function of getting typed string
182193
void setString(const char* string); // Function for replace text with new string
183194
void blit() const override; // Function for draw at screen
184-
bool in(const Mouse mouse) const; // Function of checking pressing
185195
};
186196

187197

188198
// Object for typying in text with backplate for visability
189199
template <unsigned bufferSize = 16>
190200
class TypeBox : public TypeField<bufferSize> {
191201
private:
192-
// Backplate part
193-
SDL_Texture* backTexture; // Texture of backplate
194-
const SDL_FRect backRect; // Rect of backplate
202+
RectBackplate backplate;
195203

196204
public:
197205
TypeBox(const Window& window, float posX, float posY, float height, const char *startText = "",
198206
Aligment aligment = Aligment::Midle, unsigned frameWidth = 2, Color textColor = BLACK);
199-
~TypeBox();
200207
void blit() const override; // Function for draw inputting text with backplate
208+
bool in(const Mouse mouse) const override;
201209
};
202210

203211

204212
// Class of buttons with text on it
205213
class TextButton : public HighlightedStaticText {
206214
private:
207-
const Backplate backplate;
215+
const RoundedBackplate backplate;
208216

209217
public:
210218
TextButton(const Window& window, float X, float Y, const LanguagedText texts, float size,

src/GUI/rectBackplate.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (C) 2024-2025, Kazankov Nikolay
3+
* <nik.kazankov.05@mail.ru>
4+
*/
5+
6+
#include "baseGUI.hpp"
7+
8+
9+
GUI::RectBackplate::RectBackplate(const Window& _window, float _centerX, float _centerY, float _width, float _height,
10+
float _border, Color _frontColor, Color _backColor)
11+
: RectBackplate(_window, {_window.getWidth() * (_centerX - _width/2), _window.getHeight() * (_centerY - _height/2),
12+
_window.getWidth() * _width, _window.getHeight() * _height}, _border, _frontColor, _backColor) {}
13+
14+
GUI::RectBackplate::RectBackplate(const Window& _window, const SDL_FRect& _rect, float _border,
15+
Color _frontColor, Color _backColor)
16+
: TextureTemplate(_window) {
17+
// Copying parameters
18+
rect = _rect;
19+
// Creating backplate
20+
texture = window.createTexture(rect.w, rect.h);
21+
window.setRenderTarget(texture);
22+
window.setDrawColor(GREY);
23+
window.clear();
24+
window.setDrawColor(WHITE);
25+
window.drawRect({_border, _border, rect.w-2*_border, rect.h-2*_border});
26+
window.resetRenderTarget();
27+
}
28+
29+
GUI::RectBackplate::~RectBackplate() {
30+
SDL_DestroyTexture(texture);
31+
}

src/GUI/roundedBackplate.cpp

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

88

9-
// Class of backplates (smoothed rects)
10-
GUI::Backplate::Backplate(const Window& _window, float _centerX, float _centerY, float _width, float _height,
9+
GUI::RoundedBackplate::RoundedBackplate(const Window& _window, float _centerX, float _centerY, float _width, float _height,
1110
float _rad, float _bor, Color _frontColor, Color _backColor)
12-
: Backplate(_window, {_window.getWidth() * (_centerX - _width/2), _window.getHeight() * (_centerY - _height/2),
11+
: RoundedBackplate(_window, {_window.getWidth() * (_centerX - _width/2), _window.getHeight() * (_centerY - _height/2),
1312
_window.getWidth() * _width, _window.getHeight() * _height}, _rad, _bor, _frontColor, _backColor) {}
1413

1514

16-
GUI::Backplate::Backplate(const Window& _window, const SDL_FRect& _rect, float _rad, float _bor, Color _frontColor, Color _backColor)
15+
GUI::RoundedBackplate::RoundedBackplate(const Window& _window, const SDL_FRect& _rect, float _rad, float _bor, Color _frontColor, Color _backColor)
1716
: TextureTemplate(_window) {
1817
// Creating new texture for drawing
1918
texture = window.createTexture(_rect.w, _rect.h);
@@ -63,6 +62,6 @@ GUI::Backplate::Backplate(const Window& _window, const SDL_FRect& _rect, float _
6362
window.resetRenderTarget();
6463
}
6564

66-
GUI::Backplate::~Backplate() {
65+
GUI::RoundedBackplate::~RoundedBackplate() {
6766
SDL_DestroyTexture(texture);
6867
}

src/GUI/typeBox.cpp

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,19 @@ template <unsigned bufferSize>
1010
GUI::TypeBox<bufferSize>::TypeBox(const Window& _window, float _posX, float _posY, float _height,
1111
const char *_startText, Aligment _aligment, unsigned _frameWidth, Color _textColor)
1212
: TypeField<bufferSize>(_window, _posX, _posY, _height, _startText, _aligment, _textColor),
13-
backRect({_posX*_window.getWidth() - (6.5f*bufferSize+2), _posY*_window.getHeight()-_height * 0.9f,
14-
13.0f * bufferSize+4, _height * 1.8f}) {
15-
// Creating backplate
16-
backTexture = Template::window.createTexture(backRect.w, backRect.h);
17-
Template::window.setRenderTarget(backTexture);
18-
Template::window.setDrawColor(GREY);
19-
Template::window.clear();
20-
Template::window.setDrawColor(WHITE);
21-
Template::window.drawRect({_frameWidth, _frameWidth, backRect.w-2*_frameWidth, backRect.h-2*_frameWidth});
22-
Template::window.resetRenderTarget();
23-
}
24-
25-
template <unsigned bufferSize>
26-
GUI::TypeBox<bufferSize>::~TypeBox() {
27-
SDL_DestroyTexture(backTexture);
28-
}
13+
backplate(_window, {_posX*_window.getWidth() - (6.5f*bufferSize+2), _posY*_window.getHeight()-_height * 0.9f,
14+
13.0f * bufferSize+4, _height * 1.9f}, 2) {}
2915

3016
template <unsigned bufferSize>
3117
void GUI::TypeBox<bufferSize>::blit() const {
3218
// Rendering background picture for better typing
33-
Template::window.blit(backTexture, backRect);
19+
backplate.blit();
3420

3521
// Rendering text
3622
TypeField<bufferSize>::blit();
3723
}
24+
25+
template <unsigned bufferSize>
26+
bool GUI::TypeBox<bufferSize>::in(const Mouse _mouse) const {
27+
return backplate.in(_mouse);
28+
}

src/GUI/typeField.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -418,11 +418,6 @@ void GUI::TypeField<bufferSize>::blit() const {
418418
}
419419
}
420420

421-
template <unsigned bufferSize>
422-
bool GUI::TypeField<bufferSize>::in(const Mouse mouse) const {
423-
return mouse.in(rect);
424-
}
425-
426421
template <unsigned bufferSize>
427422
const char* GUI::TypeField<bufferSize>::getString() {
428423
buffer[length] = '\0';

src/cycles/clientLobby.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ class ClientLobbyCycle : public BaseCycle {
2121

2222
// Input fields
2323
GUI::StaticText enterIPText;
24-
GUI::TypeField<12> enterIPField;
24+
GUI::TypeBox<12> enterIPField;
2525
GUI::StaticText enterPortText;
26-
GUI::TypeField<6> enterPortField;
26+
GUI::TypeBox<6> enterPortField;
2727
GUI::TextButton pasteButton;
2828
GUI::TextButton connectButton;
2929

src/cycles/gameCycle.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class GameCycle : public BaseCycle {
2121
GUI::StaticText playersTurnsTexts[2];
2222

2323
// Menu after game end
24-
GUI::Backplate menuBackplate;
24+
GUI::RoundedBackplate menuBackplate;
2525
GUI::TextButton menuRestartButton;
2626
GUI::TextButton menuExitButton;
2727
// Ending options

src/cycles/parametersCycle.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ class ParametersCycle : public BaseCycle {
1313
private:
1414
GUI::HighlightedStaticText titleText;
1515
GUI::HighlightedStaticText widthText;
16-
GUI::TypeField<1> widthTypeField;
16+
GUI::TypeBox<1> widthTypeField;
1717
GUI::HighlightedStaticText winWidthText;
18-
GUI::TypeField<1> winWidthTypeField;
18+
GUI::TypeBox<1> winWidthTypeField;
1919

2020
GUI::TextButton smallFieldButton;
2121
GUI::TextButton mediumFieldButton;

src/game/connectionLostBox.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ConnectionLostBox {
2121
// Button for return to menu
2222
const GUI::TextButton closeButton;
2323
// Background plate for better visability
24-
const GUI::Backplate background;
24+
const GUI::RoundedBackplate background;
2525

2626
public:
2727
ConnectionLostBox(const Window& window);

src/game/settingsMenu.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class SettingsMenu : GUI::Template {
1818
// Button for enter and quit settings menu
1919
const GUI::ImageButton settingButton;
2020
// Background plate
21-
const GUI::Backplate background;
21+
const GUI::RoundedBackplate background;
2222
// Title
2323
GUI::HighlightedStaticText titleText;
2424
// Flags for select language

0 commit comments

Comments
 (0)