Harmonic Flow Framework (libhffwk)
Cross platform C++ 2D Game Engine Framework
EditWidget.cpp
1 /*
2  Harmonic Flow Framework
3  Copyright (C) 2011-2018 Andreas Widen <andreas@harmonicflow.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 #include "EditWidget.h"
22 #include "WidgetManager.h"
23 #include "EditListener.h"
24 #include "platform/Environment.h"
25 #include <cstdlib>
26 
27 using namespace HFCore;
28 
29 #include "debug/CrtDbgNew.h"
30 
31 static int32_hf gEditWidgetColors[][3] =
32 {
33  {255, 255, 255},
34  {0, 0, 0},
35  {223, 162, 156},
36  {0, 0, 0},
37  {255, 255, 255}
38 };
39 
41 {
42  mId = id;
43  mEditListener = editListener;
44  mFont = font;
45 
46  mAllowExtendedChars = true;
47  mHadDoubleClick = false;
48  mHilitePos = -1;
49  mLastModifyIdx = -1;
50  mLeftPos = 0;
51  mUndoCursor = 0;
52  mUndoHilitePos = 0;
53  mLastModifyIdx = 0;
54  mBlinkAcc = 0;
55  mCursorPos = 0;
56  mShowingCursor = false;
57  mDrawSelOverride = false;
58  mMaxChars = -1;
59  mMaxPixels = -1;
60  mPasswordChar = 0;
61  mBlinkDelay = 40;
62 
63  // initiate string
64  mString.clear();
65  mPasswordDisplayString.clear();
66  mUndoString.clear();
67 
68  setColors(gEditWidgetColors, NUM_COLORS);
69 }
70 
72 {
74 }
75 
77 {
78  bool shiftDown = false;
79  bool controlDown = false;
80 
81  if (mods & Keyboard::KEYMOD_SHIFT)
82  {
83  shiftDown = true;
84  }
85  if (mods & Keyboard::KEYMOD_CTRL)
86  {
87  controlDown = true;
88  }
89 
90  bool bigChange = false;
91  bool removeHilite = !shiftDown;
92 
93  if (shiftDown && (mHilitePos == -1))
94  {
96  }
97 
98  std::wstring oldString = mString;
99  int32_hf oldCursorPos = mCursorPos;
100  int32_hf oldHilitePos = mHilitePos;
101 
102  if (key == Keyboard::KEY_LEFT)
103  {
104  if (controlDown)
105  {
106  // Get to a word
107  while ((mCursorPos > 0) && (!isPartOfWord(mString[mCursorPos - 1])))
108  {
109  mCursorPos--;
110  }
111 
112  // Go beyond the word
113  while ((mCursorPos > 0) && (isPartOfWord(mString[mCursorPos - 1])))
114  {
115  mCursorPos--;
116  }
117  }
118  else if (shiftDown || (mHilitePos == -1))
119  {
120  mCursorPos--;
121  }
122  else
123  {
125  }
126  }
127  else if (key == Keyboard::KEY_RIGHT)
128  {
129  if (controlDown)
130  {
131  // Get to whitespace
132  while ((mCursorPos < (int32_hf) mString.length() - 1) &&
134  {
135  mCursorPos++;
136  }
137 
138  // Go beyond the whitespace
139  while ((mCursorPos < (int32_hf) mString.length() - 1) &&
141  {
142  mCursorPos++;
143  }
144  }
145  if (shiftDown || (mHilitePos == -1))
146  {
147  mCursorPos++;
148  }
149  else
150  {
152  }
153  }
154  else if (key == Keyboard::KEY_BACKSPACE)
155  {
156  if (mString.length() > 0)
157  {
158  if ((mHilitePos != -1) && (mHilitePos != mCursorPos))
159  {
160  // Delete selection
161  mString = mString.substr(0, hf_min(mCursorPos, mHilitePos)) +
163  mString.length());
164 
166  mHilitePos = -1;
167 
168  bigChange = true;
169  }
170  else
171  {
172  // Delete char behind cursor
173  if (mCursorPos > 0)
174  {
175  mString = mString.substr(0, mCursorPos - 1) +
176  mString.substr(mCursorPos, mString.length());
177  }
178  else
179  {
180  mString = mString.substr(mCursorPos, mString.length());
181  }
182  mCursorPos--;
183  mHilitePos = -1;
184 
185  if (mCursorPos != mLastModifyIdx)
186  {
187  bigChange = true;
188  }
190  }
191  }
192  }
193  else if (key == Keyboard::KEY_DELETE)
194  {
195  if (mString.length() > 0)
196  {
197  if ((mHilitePos != -1) && (mHilitePos != mCursorPos))
198  {
199  // Delete selection
200  mString = mString.substr(0, hf_min(mCursorPos, mHilitePos)) +
202  mString.length());
203 
205  mHilitePos = -1;
206 
207  bigChange = true;
208  }
209  else
210  {
211  // Delete char in front of cursor
212  if (mCursorPos < (int32_hf) mString.length())
213  {
214  mString = mString.substr(0, mCursorPos) +
215  mString.substr(mCursorPos + 1, mString.length());
216  }
217 
218  if (mCursorPos != mLastModifyIdx)
219  {
220  bigChange = true;
221  }
223  }
224  }
225  }
226  else if (key == Keyboard::KEY_HOME)
227  {
228  mCursorPos = 0;
229  }
230  else if (key == Keyboard::KEY_END)
231  {
232  mCursorPos = mString.length();
233  }
234  else if (key == Keyboard::KEY_RETURN)
235  {
237  return;
238  }
239  else if (key == Keyboard::KEY_ESCAPE)
240  {
242  return;
243  }
244  else
245  {
246  std::wstring unicodeChar;
247  unicodeChar.resize(1);
248  unicodeChar[0] = unicode;
249 
250  uint32_hf ch = (uint32_hf)unicode;
251  uint32_hf range = 127;
252 
254  {
255  range = 255;
256  }
257 
258  if ((ch >= 32) && (ch <= range) &&
259  (mFont->getStringWidth(unicodeChar.c_str()) > 0)
260  && mEditListener->allowChar(mId, unicode))
261  {
262  if ((mHilitePos != -1) && (mHilitePos != mCursorPos))
263  {
264  // Replace selection with new character
265  if (mString.length() == 0)
266  {
267  mString = unicodeChar;
268  }
269  else
270  {
271  mString = mString.substr(0, hf_min(mCursorPos, mHilitePos)) + unicodeChar +
272  mString.substr(hf_max(mCursorPos, mHilitePos), mString.length());
273  }
274 
276  mHilitePos = -1;
277 
278  bigChange = true;
279  }
280  else
281  {
282  // Insert character where cursor is
283  if (mString.length() == 0)
284  {
285  mString = unicodeChar;
286  }
287  else
288  {
289  mString = mString.substr(0, mCursorPos) + unicodeChar +
290  mString.substr(mCursorPos, mString.length());
291  }
292 
293  if (mCursorPos != mLastModifyIdx + 1)
294  {
295  bigChange = true;
296  }
298  mHilitePos = -1;
299  }
300  mCursorPos++;
301  focusCursor(false);
302  }
303  else
304  {
305  removeHilite = false;
306  }
307  }
308 
309  if ((mMaxChars != -1) && ((int32_hf)mString.length() > mMaxChars))
310  {
311  mString = mString.substr(0, mMaxChars);
312  }
313 
315 
316  if (mCursorPos < 0)
317  {
318  mCursorPos = 0;
319  }
320  else if (mCursorPos > (int32_hf)mString.length())
321  {
322  mCursorPos = mString.length();
323  }
324 
325  if (oldCursorPos != mCursorPos)
326  {
327  mBlinkAcc = 0;
328  mShowingCursor = true;
329  }
330 
331  focusCursor(true);
332 
333  if (removeHilite || mHilitePos == mCursorPos)
334  {
335  mHilitePos = -1;
336  }
337 
338  if (!mEditListener->allowText(mId, mString.c_str()))
339  {
340  mString = oldString;
341  mCursorPos = oldCursorPos;
342  mHilitePos = oldHilitePos;
343  }
344  else if (bigChange)
345  {
346  mUndoString = oldString;
347  mUndoCursor = oldCursorPos;
348  mUndoHilitePos = oldHilitePos;
349  }
350 }
351 
353 {
354  if (mPasswordChar == 0)
355  {
356  return mString;
357  }
358 
359  if (mPasswordDisplayString.size() != mString.size())
360  {
362  mPasswordDisplayString.resize(mString.size());
363  for (int32_hf i = 0; i < (int32_hf)mString.length(); i++)
364  {
366  }
367  }
368 
369  return mPasswordDisplayString;
370 }
371 
373 {
374  std::wstring &string = getDisplayString();
375 
376  if (mCursorPos < (int32_hf)string.length())
377  {
378  // Find first space before word
380  while ((mHilitePos > 0) && (isPartOfWord(string[mHilitePos - 1])))
381  {
382  mHilitePos--;
383  }
384 
385  // Find first space after word
386  while ((mCursorPos < (int32_hf)string.length() - 1) &&
387  (isPartOfWord(string[mCursorPos + 1])))
388  {
389  mCursorPos++;
390  }
391  if (mCursorPos < (int32_hf)string.length())
392  {
393  mCursorPos++;
394  }
395  }
396 }
397 
398 void EditWidget::setFont(Font *font, Font *widthCheckFont)
399 {
400  mFont = font;
401 
403  if (widthCheckFont != NULL)
404  {
405  addWidthCheckFont(widthCheckFont);
406  }
407 }
408 
409 void EditWidget::setText(const std::wstring &text, bool leftPosToZero)
410 {
411  mString = text;
412  mCursorPos = mString.length();
413  mHilitePos = 0;
414  if (leftPosToZero)
415  {
416  mLeftPos = 0;
417  }
418  else
419  {
420  focusCursor(true);
421  }
422 }
423 
424 bool EditWidget::isPartOfWord(wchar_t unicode)
425 {
426  if ((unicode >= 32 && unicode <= 47) || (unicode >= 58 && unicode <= 64) ||
427  (unicode >= 91 && unicode <= 96) || (unicode >= 123 && unicode <= 126) ||
428  (unicode >= 128 && unicode <= 191) || (unicode == 95)
429  )
430  {
431  return false;
432  }
433 
434  return true;
435 }
436 
438 {
439  int32_hf pos = 0;
440 
441  std::wstring &string = getDisplayString();
442 
443  for (int32_hf i = mLeftPos; i < (int32_hf)string.length(); i++)
444  {
445  std::wstring loSubStr = string.substr(mLeftPos, i - mLeftPos);
446  std::wstring hiSubStr = string.substr(mLeftPos, i - mLeftPos + 1);
447 
448  int32_hf loLen = mFont->getStringWidth(loSubStr.c_str());
449  int32_hf hiLen = mFont->getStringWidth(hiSubStr.c_str());
450  if (x >= (loLen + hiLen) / 2 + 5)
451  {
452  pos = i + 1;
453  }
454  }
455 
456  return pos;
457 }
458 
460 {
461  Widget::resize(x, y, w, h);
462 
463  focusCursor(false);
464 }
465 
467 {
468  // actual UI part:
469  mRenderHelper.drawRect(g, mX, mY, mWidth, mHeight, mColors[COLOR_OUTLINE]);
470  mRenderHelper.drawRect(g, mX + 1, mY + 1, mWidth - 2, mHeight - 2, mColors[COLOR_BKG]);
471 
472  // draw actual text:
473  drawText(g);
474 }
475 
476 void EditWidget::drawText(Graphics *g)
477 {
478  std::wstring &string = getDisplayString();
479  Rect rect;
480  static int32_hf fontX = 0;
481 
482  for (int32_hf i = 0; i < 2; i++)
483  {
484  if (i == 1)
485  {
486  int32_hf cursorX = mFont->getStringWidth(string.substr(0, mCursorPos).c_str()) -
487  mFont->getStringWidth(string.substr(0, mLeftPos).c_str());
488  int32_hf hiliteX = cursorX + 2;
489  if ((mHilitePos != -1) && (mCursorPos != mHilitePos))
490  {
491  hiliteX = mFont->getStringWidth(string.substr(0, mHilitePos).c_str()) -
492  mFont->getStringWidth(string.substr(0, mLeftPos).c_str());
493  }
494 
495  cursorX = hf_min(hf_max(0, cursorX), (int32_hf)mWidth - 8);
496  hiliteX = hf_min(hf_max(0, hiliteX), (int32_hf)mWidth - 8);
497 
498  fontX = 4 + hf_min(cursorX, hiliteX) + (int32_hf)mX;
499 
500  if (!mShowingCursor)
501  {
502  cursorX += 2;
503  }
504 
505  rect.set((fp32_hf)(4 + hf_min(cursorX, hiliteX) + mX),
506  (fp32_hf)((mHeight - mFont->getHeight()) / 2 + mY),
507  (fp32_hf)(abs(hiliteX - cursorX)),
508  (fp32_hf)mFont->getHeight());
509  }
510  else
511  {
512  rect.set(mX + 4, mY, mWidth - 8, mHeight);
513  }
514 
515  bool hasfocus = mHasFocus || mDrawSelOverride;
516  if (i == 1 && hasfocus)
517  {
518  mRenderHelper.drawRect(g, rect.getX(), rect.getY(),
519  rect.getWidth(), rect.getHeight(),
521  }
522 
523  if (i == 0 || !hasfocus)
524  {
525  mRenderHelper.beginBatch(g, Graphics::BATCHMODE_STATIC);
526  mRenderHelper.drawString(g, mFont, mColors[COLOR_TEXT],
527  string.substr(mLeftPos, string.length()).c_str(),
528  (int32_hf)(4 + mX), (int32_hf)(mY + (mFont->getHeight() / 2) + 2));
529  mRenderHelper.endBatch(g, true);
530  }
531  else
532  {
533  if (mHilitePos >= 0)
534  {
537 
538  mRenderHelper.beginBatch(g, Graphics::BATCHMODE_STATIC);
539  mRenderHelper.drawString(g, mFont, mColors[COLOR_HILITE_TEXT],
540  string.substr(from, to - from).c_str(),
541  fontX + 1, (int32_hf)(mY + (mFont->getHeight() / 2) + 2));
542  mRenderHelper.endBatch(g, true);
543  }
544  }
545  }
546 }
547 
549 {
550  Widget::update(dt);
551 
552  if (mHasFocus)
553  {
554  if (++mBlinkAcc > mBlinkDelay)
555  {
556  mBlinkAcc = 0;
558  }
559  }
560 }
561 
563 {
564  return true;
565 }
566 
568 {
570 
571  mShowingCursor = true;
572  mBlinkAcc = 0;
573 }
574 
576 {
578 
579  mShowingCursor = false;
580 }
581 
582 void EditWidget::focusCursor(bool bigJump)
583 {
584  while (mCursorPos < mLeftPos)
585  {
586  if (bigJump)
587  {
588  mLeftPos = hf_max(0, mLeftPos - 10);
589  }
590  else
591  {
592  mLeftPos = hf_max(0, mLeftPos - 1);
593  }
594  }
595 
596  if (mFont != NULL)
597  {
598  std::wstring &string = getDisplayString();
599  while ((mWidth - 8 > 0) && (mFont->getStringWidth(string.substr(0, mCursorPos).c_str()) -
600  mFont->getStringWidth(string.substr(0, mLeftPos).c_str()) >= mWidth - 8))
601  {
602  if (bigJump)
603  {
604  mLeftPos = hf_min(mLeftPos + 10, (int32_hf)mString.length() - 1);
605  }
606  else
607  {
608  mLeftPos = hf_min(mLeftPos + 1, (int32_hf)mString.length() - 1);
609  }
610  }
611  }
612 }
613 
615 {
617  {
619  processKey(kb.unicode, kb.key, kb.mods);
620  }
621 
622  Widget::keyDown(kb);
623 }
624 
626 {
627 }
628 
630 {
631  /* if (!iOS_KeyboardIsShown())
632  {
633  iOS_KeyboardShow();
634  }*/
635 }
636 
638 {
639 }
640 
642 {
643  Widget::mouseMove(mouse);
644 
645  if (mIsDown)
646  {
647  if (mHilitePos == -1)
648  {
650  }
651 
652  mCursorPos = getCharAt((int32_hf)(mouse.x - mX),
653  (int32_hf)(mouse.y - mY));
654  focusCursor(false);
655  }
656 }
657 
659 {
661 
662  mHilitePos = -1;
663  mCursorPos = getCharAt((int32_hf)(mouse.x - mX),
664  (int32_hf)(mouse.y - mY));
665 
666  if (mouse.clickCount > 1)
667  {
668  mHadDoubleClick = true;
669  hiliteWord();
670  }
671 
672  focusCursor(false);
674 }
675 
677 {
678  Widget::mouseButtonUp(mouse);
679 
680  if (mHilitePos == mCursorPos)
681  {
682  mHilitePos = -1;
683  }
684 
685  if (mHadDoubleClick)
686  {
687  mHilitePos = -1;
688  mCursorPos = getCharAt((int32_hf)(mouse.x - mX),
689  (int32_hf)(mouse.y - mY));
690 
691  mHadDoubleClick = false;
692  hiliteWord();
694  }
695 }
696 
698 {
699  Widget::mouseEnter(mouse);
700 
701 }
702 
704 {
705  Widget::mouseLeave(mouse);
706 
707 }
708 
710 {
711  mWidthCheckList.clear();
712 }
713 
715 {
716  mWidthCheckList.push_back(WidthCheck());
717  WidthCheck &check = mWidthCheckList.back();
718  check.mWidth = maxPixels;
719  check.mFont = font;
720 }
721 
723 {
724  if (mMaxPixels <= 0 && mWidthCheckList.empty()) // no width checking in effect
725  {
726  return;
727  }
728 
729  if (mWidthCheckList.empty())
730  {
731  while (mFont->getStringWidth(mString.c_str()) > mMaxPixels)
732  {
733  mString = mString.substr(0, mString.length() - 1);
734  }
735 
736  return;
737  }
738 
739  for (WidthCheckList::iterator itr = mWidthCheckList.begin();
740  itr != mWidthCheckList.end(); ++itr)
741  {
742  int32_hf width = itr->mWidth;
743  if (width <= 0)
744  {
745  width = mMaxPixels;
746  if (width <= 0)
747  {
748  continue;
749  }
750  }
751 
752  while (itr->mFont->getStringWidth(mString.c_str()) > width)
753  {
754  mString = mString.substr(0, mString.length() - 1);
755  }
756  }
757 }
Key
Common Key&#39;s enum.
Definition: Keyboard.h:47
bool mShowingCursor
Flag indicating if showing cursor or not.
Definition: EditWidget.h:321
unsigned int uint32_hf
A type definition for unsigned int.
Definition: HFDataTypes.h:354
void endBatch(Graphics *g, bool render)
End current Batch.
virtual int32_hf getStringWidth(const UString &str, fp32_hf scale=1.0f)=0
Get the width of str.
virtual void keyDown(Keyboard::KeyboardInfo kb)
Called automatically when Keyboard keyDown event occurs.
Definition: EditWidget.cpp:614
fp32_hf drawString(Graphics *g, Font *font, Color color, const UString &string, int32_hf x, int32_hf y, fp32_hf scale=1.0f)
Draw a string.
int32_hf mCursorPos
Holds current cursor position.
Definition: EditWidget.h:340
virtual void keyDown(Keyboard::KeyboardInfo kb)
Called automatically when Keyboard keyDown event occurs.
Definition: Widget.cpp:243
virtual void setBatchUIUpdateNeeded(bool update)
Set BatchUI update needed flag.
Definition: Widget.cpp:503
fp32_hf y
Y coordinate, relative to window.
Definition: Mouse.h:69
Interface for UI EditWidget.
fp32_hf getWidth() const
Get Rect Width (or maxX).
Definition: Rect.h:168
int32_hf mWidth
Holds width.
Definition: EditWidget.h:166
virtual void update(fp32_hf dt)
Called by the framework once for every iteration of the game loop, immediately before rendering takes...
Definition: EditWidget.cpp:548
Font * mFont
Holds pointer to Font.
Definition: EditWidget.h:305
bool mDrawSelOverride
Flag indicating if to draw selected text even when not in focus.
Definition: EditWidget.h:327
int int32_hf
A type definition for int.
Definition: HFDataTypes.h:349
Key modifier Shift.
Definition: Keyboard.h:91
virtual ~EditWidget()
Destructor.
Definition: EditWidget.cpp:71
virtual void mouseLeave(Mouse::MouseInfo mouse)
Called automatically when Mouse leave event occurs.
Definition: Widget.cpp:292
virtual void touchUp(Touch::TouchInfo touch)
Called automatically when Touch up event occurs.
Definition: EditWidget.cpp:629
void drawRect(Graphics *g, fp32_hf x0, fp32_hf y0, fp32_hf w, fp32_hf h, Color color, Graphics::DrawMode drawMode=Graphics::DRAWMODE_NORMAL)
Draw a Rect.
virtual bool allowKey(int32_hf id, HFCore::Keyboard::Key key)
Called automatically and is a good method to implement if you want to allow certain HFCore::Keyboard:...
Definition: EditListener.h:92
std::wstring mUndoString
Holds undo string.
Definition: EditWidget.h:376
bool mHasFocus
Flag indicating if Widget has focus or not.
Definition: Widget.h:1060
Font * mFont
Holds pointer to Font.
Definition: EditWidget.h:165
virtual void resize(fp32_hf x, fp32_hf y, int32_hf w, int32_hf h)
Resize Widget.
Definition: EditWidget.cpp:459
fp32_hf mX
Holds Widget X position.
virtual bool wantsFocus()
Determine whether Widget wants focus.
Definition: EditWidget.cpp:562
EditWidget(int32_hf id, EditListener *editListener, Font *font)
Constructor.
Definition: EditWidget.cpp:40
std::wstring & getDisplayString()
Get display string.
Definition: EditWidget.cpp:352
std::wstring mString
Holds string.
Definition: EditWidget.h:287
virtual bool allowText(int32_hf id, const HFCore::UString &text)
Called automatically and is a good method to implement if you want to allow certain text only...
Definition: EditListener.h:118
fp32_hf x
X coordinate, relative to window.
Definition: Mouse.h:68
Interface for EditWidget listener callback methods.
Definition: EditListener.h:66
int32_hf mMaxPixels
Holds max pixels.
Definition: EditWidget.h:371
int32_hf mBlinkAcc
Holds blinking cursor value. (TODO: Fix this in a better way!)
Definition: EditWidget.h:351
virtual void focusCursor(bool bigJump)
Focus cursor.
Definition: EditWidget.cpp:582
A structure that contains Touch event information.
Definition: Touch.h:50
fp32_hf width()
Get Widget width.
Definition: Widget.h:994
virtual void mouseMove(Mouse::MouseInfo mouse)
Called automatically when Mouse motion event occurs.
Definition: Widget.cpp:272
int32_hf mLastModifyIdx
Holds last modify index.
Definition: EditWidget.h:391
fp32_hf getY() const
Get Rect Y (or minY).
Definition: Rect.h:159
int32_hf mLeftPos
Holds current left position.
Definition: EditWidget.h:361
virtual int32_hf getHeight()=0
Get Font height.
bool mHadDoubleClick
Flag indicating if we had double click or not. Used to fix a bug with double clicking to hilite a wor...
Definition: EditWidget.h:335
#define NULL
Convenient define for 0.
Definition: HFDataTypes.h:42
int32_hf mUndoHilitePos
Holds undo hilite position.
Definition: EditWidget.h:386
Useful for static content.
Definition: Graphics.h:199
EditListener * mEditListener
Holds pointer to EditListener class.
Definition: EditWidget.h:282
virtual void mouseEnter(Mouse::MouseInfo mouse)
Called automatically when Mouse enter event occurs.
Definition: Widget.cpp:288
virtual bool isPartOfWord(wchar_t unicode)
Determine whether unicode character is part of a word.
Definition: EditWidget.cpp:424
virtual void resize(fp32_hf x, fp32_hf y, int32_hf w, int32_hf h)
Resize Widget.
Definition: Widget.cpp:181
A structure that contains Mouse event information.
Definition: Mouse.h:63
wchar_t unicode
Unicode character if any.
Definition: Keyboard.h:108
int32_hf mUndoCursor
Holds undo cursor position.
Definition: EditWidget.h:381
bool mAllowExtendedChars
Flag indicating if extended character range is allowed or not. Extended range is 255 and normal range...
Definition: EditWidget.h:316
A structure that contains Keyboard event information.
Definition: Keyboard.h:103
virtual void mouseEnter(Mouse::MouseInfo mouse)
Called automatically when Mouse enter event occurs.
Definition: EditWidget.cpp:697
Key key
Key enum value if any.
Definition: Keyboard.h:109
Key modifier Ctrl.
Definition: Keyboard.h:92
Interface for EditWidget listener callback methods.
wchar_t mPasswordChar
Holds character to use as password char. See also mPasswordDisplayString.
Definition: EditWidget.h:300
fp32_hf getX() const
Get Rect X (or minX).
Definition: Rect.h:150
void addWidthCheckFont(Font *font, int32_hf maxPixels=-1)
Add font and maxPixels to internal WidthCheck list.
Definition: EditWidget.cpp:714
#define hf_min(a, b)
Returns the smallest of a and b.
Definition: HFDataTypes.h:123
void clearWidthCheckFonts()
Clear internal WidthCheck list.
Definition: EditWidget.cpp:709
virtual void mouseButtonUp(Mouse::MouseInfo mouse)
Called automatically when Mouse button up event occurs.
Definition: EditWidget.cpp:676
virtual void gotFocus()
Called when the Widget gains focus.
Definition: Widget.cpp:229
virtual void mouseButtonUp(Mouse::MouseInfo mouse)
Called automatically when Mouse button up event occurs.
Definition: Widget.cpp:280
virtual int32_hf getCharAt(int32_hf x, int32_hf y)
Get character at x and y position.
Definition: EditWidget.cpp:437
virtual void lostFocus()
Called when the Widget loses focus.
Definition: Widget.cpp:234
Modifiers
Key modifier enum.
Definition: Keyboard.h:87
int32_hf mBlinkDelay
Holds blink delay. (TODO: Fix this in a better way!)
Definition: EditWidget.h:356
virtual void draw(Graphics *g)
Called by the framework once for every iteration of the main loop.
Definition: EditWidget.cpp:466
fp32_hf mY
Holds Widget Y position.
virtual void mouseLeave(Mouse::MouseInfo mouse)
Called automatically when Mouse leave event occurs.
Definition: EditWidget.cpp:703
int32_hf mId
Holds EditWidget ID.
Definition: EditWidget.h:277
Definition: Actor.h:34
WidthCheckList mWidthCheckList
Holds list of WidthCheck.
Definition: EditWidget.h:310
virtual void editWidgetEscapeKeyPressed()
Called automatically when user hits ESCAPE key.
Definition: EditListener.h:123
std::wstring mPasswordDisplayString
Holds password display string. Useful when not wanting show actual text. See mPasswordChar for char u...
Definition: EditWidget.h:294
Interface for Resource type Font.
Definition: Font.h:84
Struct holding Font and width used for widthcheck.
Definition: EditWidget.h:163
virtual void lostFocus()
Called when the Widget loses focus.
Definition: EditWidget.cpp:575
Singleton interface for platform specific things.
virtual void update(fp32_hf dt)
Called by the framework once for every iteration of the game loop, immediately before rendering takes...
Definition: Widget.cpp:225
Specialized Boundary representing a Rect.
Definition: Rect.h:34
Interface for all rendering related things.
Definition: Graphics.h:120
virtual void mouseButtonDown(Mouse::MouseInfo mouse)
Called automatically when Mouse button down event occurs.
Definition: Widget.cpp:276
WidgetManager manages Widget&#39;s and interacts with Game interface.
virtual void hiliteWord()
Hilite word at cursor position.
Definition: EditWidget.cpp:372
virtual bool allowChar(int32_hf id, wchar_t unicode)
Called automatically and is a good method to implement if you want to allow certain unicode character...
Definition: EditListener.h:105
void beginBatch(Graphics *g, Graphics::BatchMode mode, Rect clipRect=Rect::ZERO())
Begin Batch using specified Graphics::BatchMode and optional clipping Rect.
bool mIsDown
Flag indicating if down or not.
Definition: Widget.h:1065
virtual void setColors(int32_hf colors[][3], int32_hf numColors)
Set RGB colors.
Definition: Widget.cpp:107
virtual void touchMove(Touch::TouchInfo touch)
Called automatically when Touch move/drag event occurs.
Definition: EditWidget.cpp:637
int32_hf mHilitePos
Holds current hilite position.
Definition: EditWidget.h:345
fp32_hf getHeight() const
Get Rect Height (or maxY).
Definition: Rect.h:177
ColorVector mColors
Vector holding Color&#39;s set by setColor() and setColors().
Definition: Widget.h:1081
virtual void processKey(wchar_t unicode, Keyboard::Key key, Keyboard::Modifiers mods)
Process key.
Definition: EditWidget.cpp:76
int32_hf mMaxChars
Holds max characters.
Definition: EditWidget.h:366
#define hf_max(a, b)
Returns the largest of a and b.
Definition: HFDataTypes.h:116
Modifiers mods
Key Modifier/s if any.
Definition: Keyboard.h:110
virtual void mouseMove(Mouse::MouseInfo mouse)
Called automatically when Mouse motion event occurs.
Definition: EditWidget.cpp:641
void set(fp32_hf x, fp32_hf y, fp32_hf width, fp32_hf height, bool isCentered=false)
Initializes the Rect.
Definition: Rect.cpp:36
int32_hf clickCount
Mouse click count.
Definition: Mouse.h:73
Color for background.
Definition: EditWidget.h:152
virtual void gotFocus()
Called when the Widget gains focus.
Definition: EditWidget.cpp:567
fp32_hf mWidth
Holds Widget width.
float fp32_hf
A type definition for float.
Definition: HFDataTypes.h:359
void enforceMaxPixels()
Enforce max pixels based on internal WidthCheck list.
Definition: EditWidget.cpp:722
virtual void touchDown(Touch::TouchInfo touch)
Called automatically when Touch down event occurs.
Definition: EditWidget.cpp:625
virtual void setFont(Font *font, Font *widthCheckFont=NULL)
Set Font to use.
Definition: EditWidget.cpp:398
virtual void mouseButtonDown(Mouse::MouseInfo mouse)
Called automatically when Mouse button down event occurs.
Definition: EditWidget.cpp:658
virtual void editWidgetText(int32_hf id, const HFCore::UString &string)
Called automatically when user finished typing text.
Definition: EditListener.h:79
fp32_hf mHeight
Holds Widget height.
virtual void setText(const std::wstring &text, bool leftPosToZero=true)
Set text.
Definition: EditWidget.cpp:409