@@ -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 ();
0 commit comments