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);
220
221 void setDisabled(bool isDisabled);
222
223 void setEditMode(bool editMode);
224
226
227private:
228 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;
229
230 int boxw, boxh;
231 int cursorposx, cursorposy, cursorposchar, cursorposutf, cursorpreviousposutf;
232 std::string text;
233 int cursorshowcounter, cursorshowcounterlimit, cursorshowlimit;
234 bool editmode;
235 std::vector<short> letterlength;
236 std::vector<int> letterpos;
237 int keystate;
238 int keypresstime, keypresstimelimit1, keypresstimelimit2;
239 int initx;
240 int firstchar, firstutf, firstposx;
241 int lastutf;
242 void handleKeys();
243 void pressKey();
244 std::vector<int> clickTextbox(int x, int y);
245 std::vector<int> calculateClickPosition(int x, int y);
246 std::vector<int> calculateClickPositionMultiline(int x, int y);
247 std::vector<int> calculateCursorPositionMultiline(int x, int y);
248 void calculateLinePositionMultiline(int x, int y);
249 std::vector<int> calculateLetterPosition(int letterCharNo);
250 std::vector<int> calculateAllLetterPositions();
251 void calculateLines();
252 int calculateLastUtf();
253 int calculateCharNoFromUtf(int letterUtfNo);
254 int calculateCharNum(std::string str);
255 int findFirstSpace(int lineend);
256 void startSelection();
257 std::vector<short> readString(const std::string& str);
258 bool isLetter(char c);
259 bool isNumber(char c);
260 void findCursorPosition();
261 void findCursorPositionPassword();
262 void calculateLineCount();
263 bool selectionmode;
264 int selectionposchar1, selectionposchar2;
265 int selectionposx1, selectionposx2;
266 int selectionposutf1, selectionposutf2;
267 int selectionboxx1, selectionboxx2, selectionboxw;
268 bool shiftpressed, ctrlpressed, commandpressed;
269 bool ctrlcpressed, ctrlvpressed, ctrlxpressed, ctrlapressed, ctrlzpressed;
270 bool commandcpressed, commandvpressed, commandxpressed, commandapressed, commandzpressed;
271 bool isdragging;
272 long clicktime, previousclicktime, firstclicktime, clicktimediff;
273 bool isdoubleclicked, istripleclicked;
274 bool iseditable;
275 bool isselectedall;
276 int rowsnum;
277 int lineheight;
278 bool ismultiline;
279 bool rowsnumexceeded;
280 int currentline, linecount, lastdrawnline;
281 int linetopmargin;
282 int hdiff;
283 std::vector<std::string> lines;
284 std::vector<int> lineendchar;
285 int leftlimit, rightlimit, toplimit, bottomlimit;
286 bool isnumeric;
287 bool ispassword;
288 int dotradius;
289 bool isbackgroundenabled;
290 int totalh;
291 int firstx, firsty;
292 bool boxshrinked, boxexpanded;
293 bool arrowkeypressed;
294 gFont* textfont;
295 gGUIManager* manager;
296 int textalignment;
297 int textalignmentamount;
298 gColor* textcolor;
299 bool colorset;
300 bool isdisabled;
301
302 bool widthexceeded;
303 int widthAdjusmentDelay;
304
305 //undo stacks
306 std::stack<std::string> undostack;
307 std::stack<int> cursorposxstack, cursorposystack, cursorposcharstack, cursorposutfstack;
308 std::stack<int> firstutfstack, firstcharstack, firstposxstack;
309 std::stack<int> currentlinestack, lastdrawnlinestack,linecountstack;
310
311 void pushToStack();
312};
313
314#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
int getCursorPreviousPosUTF()
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)
int getCursorPosUTF()
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)
int getCursorPosChar()
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)