2
0

guiTextCtrl.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _GUITEXTCTRL_H_
  23. #define _GUITEXTCTRL_H_
  24. #ifndef _GFONT_H_
  25. #include "graphics/gFont.h"
  26. #endif
  27. #ifndef _GUITYPES_H_
  28. #include "gui/guiTypes.h"
  29. #endif
  30. #ifndef _GUICONTROL_H_
  31. #include "gui/guiControl.h"
  32. #endif
  33. #ifndef _STRINGBUFFER_H_
  34. #include "string/stringBuffer.h"
  35. #endif
  36. class GuiTextCtrl : public GuiControl
  37. {
  38. private:
  39. typedef GuiControl Parent;
  40. public:
  41. enum Constants { MAX_STRING_LENGTH = 1024 };
  42. protected:
  43. StringTableEntry mInitialText;
  44. StringTableEntry mInitialTextID;
  45. UTF8 mText[MAX_STRING_LENGTH + 1];
  46. S32 mMaxStrLen; // max string len, must be less then or equal to 255
  47. Resource<GFont> mFont;
  48. bool mTruncateWhenUnfocused;
  49. S32 textBufferWidth(StringBuffer buffer);
  50. StringBuffer truncate(StringBuffer buffer, StringBuffer terminationString, S32 width);
  51. public:
  52. //creation methods
  53. DECLARE_CONOBJECT(GuiTextCtrl);
  54. GuiTextCtrl();
  55. static void initPersistFields();
  56. //Parental methods
  57. bool onAdd();
  58. virtual bool onWake();
  59. virtual void onSleep();
  60. //text methods
  61. virtual void setText(const char *txt = NULL);
  62. virtual void setTextID(S32 id);
  63. virtual void setTextID(const char *id);
  64. const char *getText() { return (const char*)mText; }
  65. // Text Property Accessors
  66. static bool setText(void* obj, const char* data) { static_cast<GuiTextCtrl*>(obj)->setText(data); return true; }
  67. static const char* getTextProperty(void* obj, const char* data) { return static_cast<GuiTextCtrl*>(obj)->getText(); }
  68. void inspectPostApply();
  69. //rendering methods
  70. void onPreRender();
  71. void onRender(Point2I offset, const RectI &updateRect);
  72. void displayText( S32 xOffset, S32 yOffset );
  73. //Console methods
  74. const char *getScriptValue();
  75. void setScriptValue(const char *value);
  76. };
  77. #endif //_GUI_TEXT_CONTROL_H_