guiTextCtrl.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 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 "gfx/gFont.h"
  26. #endif
  27. #ifndef _GUITYPES_H_
  28. #include "gui/core/guiTypes.h"
  29. #endif
  30. #ifndef _GUICONTAINER_H_
  31. #include "gui/containers/guiContainer.h"
  32. #endif
  33. class GuiTextCtrl : public GuiContainer
  34. {
  35. private:
  36. typedef GuiContainer Parent;
  37. public:
  38. enum Constants { MAX_STRING_LENGTH = 1024 };
  39. protected:
  40. StringTableEntry mInitialText;
  41. StringTableEntry mInitialTextID;
  42. UTF8 mText[MAX_STRING_LENGTH + 1];
  43. S32 mMaxStrLen; // max string len, must be less then or equal to 255
  44. public:
  45. //creation methods
  46. DECLARE_CONOBJECT(GuiTextCtrl);
  47. DECLARE_CATEGORY( "Gui Text" );
  48. DECLARE_DESCRIPTION( "A control that displays a single line of text." );
  49. GuiTextCtrl();
  50. static void initPersistFields();
  51. //Parental methods
  52. bool onAdd();
  53. virtual bool onWake();
  54. //text methods
  55. virtual void setText(const char *txt = NULL);
  56. virtual void setTextID(S32 id);
  57. virtual void setTextID(const char *id);
  58. const char *getText() { return (const char*)mText; }
  59. // Text Property Accessors
  60. static bool setText(void *object, const char *index, const char *data)
  61. { static_cast<GuiTextCtrl*>(object)->setText(data); return true; }
  62. static const char* getTextProperty(void* obj, const char* data)
  63. { return static_cast<GuiTextCtrl*>(obj)->getText(); }
  64. void inspectPostApply();
  65. //rendering methods
  66. void onPreRender();
  67. void onRender(Point2I offset, const RectI &updateRect);
  68. void displayText( S32 xOffset, S32 yOffset );
  69. // resizing
  70. void autoResize();
  71. //Console methods
  72. const char *getScriptValue();
  73. void setScriptValue(const char *value);
  74. };
  75. #endif //_GUI_TEXT_CONTROL_H_