PolyUITextInput.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. Copyright (C) 2012 by Ivan Safrin
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #pragma once
  20. #include "PolyGlobals.h"
  21. #include "PolyScreenLabel.h"
  22. #include "PolyScreenShape.h"
  23. #include "PolyFontManager.h"
  24. #include "PolyFont.h"
  25. #include "PolyScreenEntity.h"
  26. #include "PolyUIEvent.h"
  27. #include "PolyUIBox.h"
  28. #include "PolyTimer.h"
  29. #include "PolyCoreInput.h"
  30. #include "PolyCore.h"
  31. #include <vector>
  32. using namespace std;
  33. namespace Polycode {
  34. class _PolyExport UITextInput : public ScreenEntity {
  35. public:
  36. UITextInput(bool multiLine, Number width, Number height);
  37. ~UITextInput();
  38. void handleEvent(Event *event);
  39. void Update();
  40. void setText(String text);
  41. String getText();
  42. void onLoseFocus();
  43. int insertLine(bool after);
  44. void onKeyDown(PolyKEY key, wchar_t charCode);
  45. void clearSelection();
  46. void setSelection(int lineStart, int lineEnd, int colStart, int colEnd);
  47. void deleteSelection();
  48. void selectAll();
  49. void Resize(int x, int y);
  50. void setNumberOnly(bool val);
  51. String getSelectionText();
  52. void insertText(String text);
  53. protected:
  54. bool isNumberOnly;
  55. int caretSkipWordBack(int caretLine, int caretPosition);
  56. int caretSkipWordForward(int caretLine, int caretPosition);
  57. void selectLineFromOffset();
  58. void updateCaretPosition();
  59. void setCaretToMouse(Number x, Number y);
  60. void dragSelectionTo(Number x, Number y);
  61. void selectWordAtCaret();
  62. void restructLines();
  63. void removeLine(ScreenLabel *line);
  64. ScreenShape *selectorRectTop;
  65. ScreenShape *selectorRectMiddle;
  66. ScreenShape *selectorRectBottom;
  67. int numLines;
  68. Number padding;
  69. Number lineSpacing;
  70. int selectionTop;
  71. int selectionBottom;
  72. int selectionL;
  73. int selectionR;
  74. int selectionCaretPosition;
  75. int selectionLine;
  76. bool draggingSelection;
  77. bool hasSelection;
  78. Number caretX,caretY;
  79. int caretPosition;
  80. bool doSelectToCaret;
  81. bool multiLine;
  82. Timer *blinkTimer;
  83. UIBox *inputRect;
  84. ScreenShape *blinkerRect;
  85. Number caretImagePosition;
  86. String fontName;
  87. Number fontSize;
  88. Number lineHeight;
  89. int lineOffset;
  90. ScreenLabel *currentLine;
  91. vector<ScreenLabel*> lines;
  92. };
  93. }