GlistEngine
Loading...
Searching...
No Matches
gGUITextbox.h
Go to the documentation of this file.
1/****************************************************************************
2 * Copyright (c) 2014 Nitra Games Ltd., Istanbul, Turkey *
3 * *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
11 * *
12 * The above copyright notice and this permission notice should not be *
13 * deleted from the source form of the Software. *
14 * *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
22 * *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
26 * authorization. *
27 ****************************************************************************/
28
29/****************************************************************************
30 * Author: Noyan Culum, 2021-09-02, Utku Sarialan, 2022-on *
31 ****************************************************************************//*
32 * gTextbox.h
33 *
34 * Created on: Sep 2, 2021
35 * Author: noyan
36 */
37
38#ifndef UI_GGUITEXTBOX_H_
39#define UI_GGUITEXTBOX_H_
40
41#include "gGUIControl.h"
42#include <stack>
43class gGUIManager;
44
45
46class gGUITextbox: public gGUIControl {
47public:
48
50 virtual ~gGUITextbox();
51
52 virtual void set(gBaseApp* root, gBaseGUIObject* topParentGUIObject, gBaseGUIObject* parentGUIObject, int parentSlotLineNo, int parentSlotColumnNo, int x, int y, int w, int h);
53
59 void setText(const std::string& text);
60
66 std::string getText();
67
76
82 bool isEditable();
83
94 void setLineCount(int linecount);
95
102
106 int getCursor(int x, int y);
107
116 void setSize(int width, int height);
117
126
133 bool isNumeric();
134
144
153 void addTopMargin(int top);
154
160 void setLineTopMargin(int linetopmargin);
161
170
177
184 /*
185 * Enables/disables the vertical margin between textbox and its background
186 *
187 */
188 void enableVerticalMargin(bool isAligned);
190
191 void update();
192 void draw();
193
194 void keyPressed(int key);
195 void keyReleased(int key);
196 void charPressed(unsigned int codepoint);
197 void mousePressed(int x, int y, int button);
198 void mouseReleased(int x, int y, int button);
199 void mouseDragged(int x, int y, int button);
200
202 void cleanText();
203
204 void setFirstX(int firstx);
205 void setFirstY(int firsty);
206
207 int getInitX();
208
209 void setTextFont(gFont* textFont);
210
211 void setTextAlignment(int textAlignment, float cellW, int initX);
212
213 void setTextColor(gColor* textColor);
214
216 void setCursorPosX(int cursorPosX, int length);
217
218 void setDisabled(bool isDisabled);
219
220 void setEditMode(bool editMode);
221
223
224private:
225 static const int KEY_NONE = 0, KEY_BACKSPACE = 1, KEY_LEFT = 2, KEY_RIGHT = 4, KEY_DELETE = 8, KEY_ENTER = 16, KEY_UP = 32, KEY_DOWN = 64;
226
227 int boxw, boxh;
228 int cursorposx, cursorposy, cursorposchar, cursorposutf;
229 std::string text;
230 int cursorshowcounter, cursorshowcounterlimit, cursorshowlimit;
231 bool editmode;
232 std::vector<short> letterlength;
233 std::vector<int> letterpos;
234 int keystate;
235 int keypresstime, keypresstimelimit1, keypresstimelimit2;
236 int initx;
237 int firstchar, firstutf, firstposx;
238 int lastutf;
239 void handleKeys();
240 void pressKey();
241 std::vector<int> clickTextbox(int x, int y);
242 std::vector<int> calculateClickPosition(int x, int y);
243 std::vector<int> calculateClickPositionMultiline(int x, int y);
244 std::vector<int> calculateCursorPositionMultiline(int x, int y);
245 void calculateLinePositionMultiline(int x, int y);
246 std::vector<int> calculateLetterPosition(int letterCharNo);
247 std::vector<int> calculateAllLetterPositions();
248 void calculateLines();
249 int calculateLastUtf();
250 int calculateCharNoFromUtf(int letterUtfNo);
251 int calculateCharNum(std::string str);
252 int findFirstSpace(int lineend);
253 void startSelection();
254 std::vector<short> readString(const std::string& str);
255 bool isLetter(char c);
256 bool isNumber(char c);
257 void findCursorPosition();
258 void findCursorPositionPassword();
259 void calculateLineCount();
260 bool selectionmode;
261 int selectionposchar1, selectionposchar2;
262 int selectionposx1, selectionposx2;
263 int selectionposutf1, selectionposutf2;
264 int selectionboxx1, selectionboxx2, selectionboxw;
265 bool shiftpressed, ctrlpressed, commandpressed;
266 bool ctrlcpressed, ctrlvpressed, ctrlxpressed, ctrlapressed, ctrlzpressed;
267 bool commandcpressed, commandvpressed, commandxpressed, commandapressed, commandzpressed;
268 bool isdragging;
269 long clicktime, previousclicktime, firstclicktime, clicktimediff;
270 bool isdoubleclicked, istripleclicked;
271 bool iseditable;
272 bool isselectedall;
273 int rowsnum;
274 int lineheight;
275 bool ismultiline;
276 bool rowsnumexceeded;
277 int currentline, linecount, lastdrawnline;
278 int linetopmargin;
279 int hdiff;
280 std::vector<std::string> lines;
281 std::vector<int> lineendchar;
282 int leftlimit, rightlimit, toplimit, bottomlimit;
283 bool isnumeric;
284 bool ispassword;
285 int dotradius;
286 bool isbackgroundenabled;
287 int totalh;
288 int firstx, firsty;
289 bool boxshrinked, boxexpanded;
290 bool arrowkeypressed;
291 gFont* textfont;
292 gGUIManager* manager;
293 int textalignment;
294 int textalignmentamount;
295 gColor* textcolor;
296 bool colorset;
297 bool isdisabled;
298
299 bool widthexceeded;
300 int widthAdjusmentDelay;
301
302 //undo stacks
303 std::stack<std::string> undostack;
304 std::stack<int> cursorposxstack, cursorposystack, cursorposcharstack, cursorposutfstack;
305 std::stack<int> firstutfstack, firstcharstack, firstposxstack;
306 std::stack<int> currentlinestack, lastdrawnlinestack,linecountstack;
307
308 void pushToStack();
309};
310
311#endif /* UI_GGUITEXTBOX_H_ */
Definition gBaseApp.h:16
Definition gBaseGUIObject.h:18
int top
Definition gBaseGUIObject.h:120
gBaseApp * root
Definition gBaseGUIObject.h:147
int width
Definition gBaseGUIObject.h:120
int height
Definition gBaseGUIObject.h:120
int left
Definition gBaseGUIObject.h:120
Definition gColor.h:17
Definition gFont.h:47
Definition gGUIControl.h:29
Definition gGUIManager.h:37
Definition gGUITextbox.h:46
void setSize(int width, int height)
bool isNumeric()
int getCursorPosX()
int getCursor(int x, int y)
std::string getText()
void setLineCount(int linecount)
virtual void set(gBaseApp *root, gBaseGUIObject *topParentGUIObject, gBaseGUIObject *parentGUIObject, int parentSlotLineNo, int parentSlotColumnNo, int x, int y, int w, int h)
void setEditMode(bool editMode)
void setDisabled(bool isDisabled)
bool isBackgroundEnabled()
void mouseReleased(int x, int y, int button)
bool isEditable()
void mouseDragged(int x, int y, int button)
void setLineTopMargin(int linetopmargin)
int getLineCount()
int calculateContentHeight()
void keyReleased(int key)
void setPassword(bool isPassword)
bool isPassword()
void setText(const std::string &text)
void mousePressed(int x, int y, int button)
void setNumeric(bool isNumeric)
void cleanText()
void setEditable(bool isEditable)
int getInitX()
virtual ~gGUITextbox()
void setTextFont(gFont *textFont)
void setTextAlignment(int textAlignment, float cellW, int initX)
void enableBackground(bool isEnabled)
void addLeftMargin(int left)
void keyPressed(int key)
void update()
void setTextColor(gColor *textColor)
void charPressed(unsigned int codepoint)
int getTextboxh()
void enableVerticalMargin(bool isAligned)
void setFirstY(int firsty)
void setFirstX(int firstx)
void addTopMargin(int top)
void setCursorPosX(int cursorPosX, int length)