PolyUITextInput.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * PolyUITextInput.h
  3. * Poly
  4. *
  5. * Created by Ivan Safrin on 7/30/08.
  6. * Copyright 2008 __MyCompanyName__. All rights reserved.
  7. *
  8. */
  9. // @package UI
  10. #pragma once
  11. #include "PolyGlobals.h"
  12. #include "PolyScreenLabel.h"
  13. #include "PolyScreenShape.h"
  14. #include "PolyFont.h"
  15. #include "PolyScreenEntity.h"
  16. #include "PolyUIEvent.h"
  17. #include "PolyUIBox.h"
  18. #include <vector>
  19. using namespace std;
  20. namespace Polycode {
  21. class _PolyExport UITextInput : public ScreenEntity {
  22. public:
  23. UITextInput(bool multiLine, float width, float height);
  24. ~UITextInput();
  25. void handleEvent(Event *event);
  26. void Update();
  27. void setText(String text);
  28. String getText();
  29. void onLoseFocus();
  30. int insertLine(bool after);
  31. void onKeyDown(TAUKey key, wchar_t charCode);
  32. void clearSelection();
  33. void setSelection(int lineStart, int lineEnd, int colStart, int colEnd);
  34. void deleteSelection();
  35. void selectAll();
  36. void Resize(int x, int y);
  37. String getSelectionText();
  38. void insertText(String text);
  39. protected:
  40. int caretSkipWordBack(int caretLine, int caretPosition);
  41. int caretSkipWordForward(int caretLine, int caretPosition);
  42. void selectLineFromOffset();
  43. void updateCaretPosition();
  44. void setCaretToMouse(float x, float y);
  45. void dragSelectionTo(float x, float y);
  46. void selectWordAtCaret();
  47. void restructLines();
  48. void removeLine(ScreenLabel *line);
  49. ScreenShape *selectorRectTop;
  50. ScreenShape *selectorRectMiddle;
  51. ScreenShape *selectorRectBottom;
  52. int numLines;
  53. float padding;
  54. float lineSpacing;
  55. int selectionTop;
  56. int selectionBottom;
  57. int selectionL;
  58. int selectionR;
  59. int selectionCaretPosition;
  60. int selectionLine;
  61. bool draggingSelection;
  62. bool hasSelection;
  63. float caretX,caretY;
  64. int caretPosition;
  65. bool doSelectToCaret;
  66. bool multiLine;
  67. Timer *blinkTimer;
  68. UIBox *inputRect;
  69. ScreenShape *blinkerRect;
  70. float caretImagePosition;
  71. String fontName;
  72. float fontSize;
  73. float lineHeight;
  74. int lineOffset;
  75. ScreenLabel *currentLine;
  76. vector<ScreenLabel*> lines;
  77. };
  78. }