-
Notifications
You must be signed in to change notification settings - Fork 1
/
TextBox.hpp
194 lines (169 loc) · 4.75 KB
/
TextBox.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#ifndef TEXTBOX_HPP
#define TEXTBOX_HPP
//a really bad gui for a singular purpose to fit the look of the game
//developed enough to just work for what i need
#include <SFML/Graphics.hpp>
#include <functional>
#include "Grid.hpp"
#include "Colors.hpp"
#include "GameState.hpp"
//#include "Level.hpp"
namespace PGUI
{
void setCellSize(float sz);
//dialog input basic shit
enum class MSG : unsigned int
{
CLOSED = 0,
YES,//confirmation
NO,//confirmation
TEXT_CHANGED,//text box
DELETE,//delete an entry
MOVE,//move level to another folder
LIST_ITEM_CHOSE//list box entry chosen
};
const std::string MSGStrings[7] =
{
"Closed",
"Yes",
"No",
"Text Changed",
"Delete",
"Move",
"List Item Chose"
};
//not really a gui button but convenience functions
struct Button
{
unsigned int min_x, max_x, min_y, max_y;
sf::Color color;
void set(unsigned int minx, unsigned int maxx, unsigned int miny, unsigned int maxy);
void setColor(Grid &grid);
void brighten(Grid &grid);
bool isHovered(Coord C);
};
//try and make it not a window???
//is that possible?
//just a grid...
//use the gamestate render then own render pos...
class DialogBox
{
public:
DialogBox(uint width, uint height, GameState &_parent, sf::RenderWindow &_window, sf::Font &_font, const std::wstring & title);//just draw a 3x3 box right now
virtual ~DialogBox(){}
GameState &state;
sf::RenderWindow &window;
sf::Font &font;
Grid m_grid;
sf::Text m_titleText;
sf::Transform m_transform;//for drawing all child objects. just linear scaling
Button TitleBar;
Button Close;
MSG run();
virtual void render(){}
virtual void handleEvent(sf::Event &event){}
virtual void cleanUp(){}
virtual void update(){}
MSG msg;
bool isRunning;
ViewRect m_viewRect;
};
class TextBoxDB : public DialogBox //public Dialog box...
{
public:
TextBoxDB(GameState &_state, sf::RenderWindow &_parent, const std::wstring & title, const std::string &string, sf::Font &font);
void render() override;
void handleEvent(sf::Event &event) override;
void cleanUp() override;
void update() override;
std::string getString();
~TextBoxDB(){}
private:
bool cursorIsShowing;
std::string m_string, m_string2;
sf::Text m_text, m_text2;
sf::Text m_cursor;
sf::RectangleShape m_textBgShape;
Coord mouseCoord;
Button *hoveredButton = nullptr;
Button *lastHovered = nullptr;
float ticker;
sf::Clock clock;
//buttons
Button OK, Cancel, Delete, Move;
sf::Text m_OKtext;
sf::Text m_Canceltext;
sf::Text m_Deletetext;
sf::Text m_Movetext;
sf::Text m_instructionText;
};
class ListBoxDB : public DialogBox
{
public:
ListBoxDB(GameState &_state, sf::RenderWindow &_parent, const std::wstring &title, sf::Font &font, std::vector<std::string> &names);
std::vector<sf::Text> m_texts;
unsigned int getChosenId(){return activeId;}
void render() override;
void handleEvent(sf::Event &event) override;
private:
std::vector<std::string> &names;
Coord activeCoord;
Coord lastCoord;
unsigned int numEntriesShown;
unsigned int offset;
unsigned int activeId;
void scroll(int amt);
void updateId(unsigned int id);
};
/*****
class TextBox//public Dialog box...
{
public:
TextBox(sf::Window &_parent, const std::wstring & title, const std::string &string, sf::Font &font);//, std::function<void()> fn);
MSG run();
std::string getString();
~TextBox(){}
private:
sf::Window &parent;
sf::RenderWindow m_window;
// std::function<void()> m_function;
Grid m_grid;
std::string m_string;
sf::Text m_text, m_text2;
sf::Text m_cursor;
sf::RectangleShape m_textBgShape;
//buttons
Button OK, Cancel, Delete, Move;
sf::Text m_OKtext;
sf::Text m_Canceltext;
sf::Text m_Deletetext;
sf::Text m_Movetext;
sf::Text m_instructionText;
void parentMSGLoop();
};
class ListBox //public Dialog...
{
public:
ListBox(sf::Window &_parent, const std::string &title, sf::Font &font, std::vector<std::string> &names);//, const std::string &title);//some function???
std::vector<sf::Text> m_texts;
// std::vector<sf::RectangleShape> m_shapes;
unsigned int getChosenId(){return activeId;}
MSG run();
private:
//INHERIT THIS FROM BASE DIALOG CONTROL???
//Dialog in a dialog,,, change the parentMSGLoop -> default loop... if(parent) -> parent->basicMessage()
//void basicMSGLoop();
sf::Window &parent;
sf::RenderWindow m_window;
Grid m_grid;//....
void parentMSGLoop();
std::vector<std::string> &names;
Coord activeCoord;
Coord lastCoord;
unsigned int numEntriesShown;
unsigned int offset;
unsigned int activeId;
};
*/
}//namespace PGUI
#endif //TEXTBOX_HPP