guiControl.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  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 _GUICONTROL_H_
  23. #define _GUICONTROL_H_
  24. #ifndef _PLATFORM_H_
  25. #include "platform/platform.h"
  26. #endif
  27. #ifndef _MPOINT_H_
  28. #include "math/mPoint.h"
  29. #endif
  30. #ifndef _MRECT_H_
  31. #include "math/mRect.h"
  32. #endif
  33. #ifndef _COLOR_H_
  34. #include "graphics/color.h"
  35. #endif
  36. #ifndef _SIMBASE_H_
  37. #include "sim/simBase.h"
  38. #endif
  39. #ifndef _GUITYPES_H_
  40. #include "gui/guiTypes.h"
  41. #endif
  42. #ifndef _EVENT_H_
  43. #include "platform/event.h"
  44. #endif
  45. #ifndef _STRINGBUFFER_H_
  46. #include "string/stringBuffer.h"
  47. #endif
  48. #ifndef _LANG_H_
  49. #include "gui/language/lang.h"
  50. #endif
  51. class GuiCanvas;
  52. class GuiEditCtrl;
  53. //-----------------------------------------------------------------------------
  54. /// @defgroup gui_group Gui System
  55. /// The GUI system in Torque provides a powerful way of creating
  56. /// WYSIWYG User Interfaces for your Game or Application written
  57. /// in Torque.
  58. ///
  59. /// The GUI Provides a range of different controls that you may use
  60. /// to arrange and layout your GUI's, including Buttons, Lists, Bitmaps
  61. /// Windows, Containers, and HUD elements.
  62. ///
  63. /// The Base Control Class GuiControl provides a basis upon which to
  64. /// write GuiControl's that may be specific to your particular type
  65. /// of game.
  66. /// @addtogroup gui_core_group Core
  67. /// @section GuiControl_Intro Introduction
  68. ///
  69. /// GuiControl is the base class for GUI controls in Torque. It provides these
  70. /// basic areas of functionality:
  71. /// - Inherits from SimGroup, so that controls can have children.
  72. /// - Interfacing with a GuiControlProfile.
  73. /// - An abstraction from the details of handling user input
  74. /// and so forth, providing friendly hooks like onMouseEnter(), onMouseMove(),
  75. /// and onMouseLeave(), onKeyDown(), and so forth.
  76. /// - An abstraction from the details of rendering and resizing.
  77. /// - Helper functions to manipulate the mouse (mouseLock and
  78. /// mouseUnlock), and convert coordinates (localToGlobalCoord() and
  79. /// globalToLocalCoord()).
  80. ///
  81. /// @ref GUI has an overview of the GUI system.
  82. ///
  83. ///
  84. /// @ingroup gui_group Gui System
  85. /// @{
  86. class GuiControl : public SimGroup
  87. {
  88. private:
  89. typedef SimGroup Parent;
  90. typedef GuiControl Children;
  91. public:
  92. /// @name Control State
  93. /// @{
  94. GuiControlProfile *mProfile;
  95. GuiControlProfile *mTooltipProfile;
  96. S32 mTipHoverTime;
  97. S32 mTooltipWidth;
  98. bool mVisible;
  99. bool mActive;
  100. bool mAwake;
  101. bool mSetFirstResponder;
  102. bool mCanSave;
  103. bool mIsContainer; ///< if true, then the GuiEditor can drag other controls into this one.
  104. S32 mLayer;
  105. static S32 smCursorChanged; ///< Has this control modified the cursor? -1 or type
  106. RectI mBounds;
  107. Point2I mMinExtent;
  108. Point2I mRenderInsetLT; ///Add this to the mBounds and parent offset to get the true render location of the control
  109. Point2I mRenderInsetRB; ///The actual rendered inset for the right and bottom sides.
  110. StringTableEntry mLangTableName;
  111. LangTable *mLangTable;
  112. static bool smDesignTime; ///< static GuiControl boolean that specifies if the GUI Editor is active
  113. /// @}
  114. /// @name Design Time Editor Access
  115. /// @{
  116. static GuiEditCtrl *smEditorHandle; ///< static GuiEditCtrl pointer that gives controls access to editor-NULL if editor is closed
  117. /// @}
  118. /// @name Keyboard Input
  119. /// @{
  120. SimObjectPtr<GuiControl> mFirstResponder;
  121. static GuiControl *smPrevResponder;
  122. static GuiControl *smCurResponder;
  123. /// @}
  124. enum horizSizingOptions
  125. {
  126. horizResizeRight = 0, ///< fixed on the left and width
  127. horizResizeWidth, ///< fixed on the left and right
  128. horizResizeLeft, ///< fixed on the right and width
  129. horizResizeCenter,
  130. horizResizeRelative ///< resize relative
  131. };
  132. enum vertSizingOptions
  133. {
  134. vertResizeBottom = 0, ///< fixed on the top and in height
  135. vertResizeHeight, ///< fixed on the top and bottom
  136. vertResizeTop, ///< fixed in height and on the bottom
  137. vertResizeCenter,
  138. vertResizeRelative ///< resize relative
  139. };
  140. enum TextRotationOptions
  141. {
  142. tRotateNone = 0,
  143. tRotateLeft,
  144. tRotateRight
  145. };
  146. protected:
  147. /// @name Control State
  148. /// @{
  149. S32 mHorizSizing; ///< Set from horizSizingOptions.
  150. S32 mVertSizing; ///< Set from vertSizingOptions.
  151. StringTableEntry mConsoleVariable;
  152. StringTableEntry mConsoleCommand;
  153. StringTableEntry mAltConsoleCommand;
  154. StringTableEntry mAcceleratorKey;
  155. StringTableEntry mTooltip;
  156. StringTableEntry mText;
  157. StringTableEntry mTextID;
  158. /// @}
  159. /// @name Console
  160. /// The console variable collection of functions allows a console variable to be bound to the GUI control.
  161. ///
  162. /// This allows, say, an edit field to be bound to '$foo'. The value of the console
  163. /// variable '$foo' would then be equal to the text inside the text field. Changing
  164. /// either changes the other.
  165. /// @{
  166. /// Sets the value of the console variable bound to this control
  167. /// @param value String value to assign to control's console variable
  168. void setVariable(const char *value);
  169. /// Sets the value of the console variable bound to this control
  170. /// @param value Integer value to assign to control's console variable
  171. void setIntVariable(S32 value);
  172. /// Sets the value of the console variable bound to this control
  173. /// @param value Float value to assign to control's console variable
  174. void setFloatVariable(F32 value);
  175. const char* getVariable(); ///< Returns value of control's bound variable as a string
  176. S32 getIntVariable(); ///< Returns value of control's bound variable as a integer
  177. F32 getFloatVariable(); ///< Returns value of control's bound variable as a float
  178. public:
  179. /// Set the name of the console variable which this GuiObject is bound to
  180. /// @param variable Variable name
  181. void setConsoleVariable(const char *variable);
  182. /// Set the name of the console function bound to, such as a script function
  183. /// a button calls when clicked.
  184. /// @param newCmd Console function to attach to this GuiControl
  185. void setConsoleCommand(const char *newCmd);
  186. const char * getConsoleCommand(); ///< Returns the name of the function bound to this GuiControl
  187. LangTable *getGUILangTable(void);
  188. const UTF8 *getGUIString(S32 id);
  189. /// @}
  190. protected:
  191. /// @name Callbacks
  192. /// @{
  193. /// Executes a console command, and returns the result.
  194. ///
  195. /// The global console variable $ThisControl is set to the id of the calling
  196. /// control. WARNING: because multiple controls may set $ThisControl, at any time,
  197. /// the value of $ThisControl should be stored in a local variable by the
  198. /// callback code. The use of the $ThisControl variable is not thread safe.
  199. /// Executes mConsoleCommand, and returns the result.
  200. const char* execConsoleCallback();
  201. /// Executes mAltConsoleCommand, and returns the result.
  202. const char* execAltConsoleCallback();
  203. /// @}
  204. public:
  205. /// @name Editor
  206. /// These functions are used by the GUI Editor
  207. /// @{
  208. /// Sets the size of the GuiControl
  209. /// @param horz Width of the control
  210. /// @param vert Height of the control
  211. void setSizing(S32 horz, S32 vert);
  212. /// Overrides Parent Serialization to allow specific controls to not be saved (Dynamic Controls, etc)
  213. void write(Stream &stream, U32 tabStop, U32 flags);
  214. /// Returns boolean specifying if a control can be serialized
  215. bool getCanSave();
  216. /// Set serialization flag
  217. void setCanSave(bool bCanSave);
  218. /// Returns boolean as to whether any parent of this control has the 'no serialization' flag set.
  219. bool getCanSaveParent();
  220. /// @}
  221. public:
  222. /// @name Initialization
  223. /// @{
  224. DECLARE_CONOBJECT(GuiControl);
  225. GuiControl();
  226. virtual ~GuiControl();
  227. static void initPersistFields();
  228. /// @}
  229. /// @name Accessors
  230. /// @{
  231. const Point2I& getPosition() { return mBounds.point; } ///< Returns position of the control
  232. const Point2I& getExtent() { return mBounds.extent; } ///< Returns extents of the control
  233. const RectI& getBounds() { return mBounds; } ///< Returns the bounds of the control
  234. const Point2I& getMinExtent() { return mMinExtent; } ///< Returns minimum size the control can be
  235. const S32 getLeft() { return mBounds.point.x; } ///< Returns the X position of the control
  236. const S32 getTop() { return mBounds.point.y; } ///< Returns the Y position of the control
  237. const S32 getWidth() { return mBounds.extent.x; } ///< Returns the width of the control
  238. const S32 getHeight() { return mBounds.extent.y; } ///< Returns the height of the control
  239. void setText(const char *text);
  240. void setTextID(S32 id);
  241. void setTextID(const char *id);
  242. const char* getText();
  243. /// @}
  244. /// @name Flags
  245. /// @{
  246. /// Sets the visibility of the control
  247. /// @param value True if object should be visible
  248. virtual void setVisible(bool value);
  249. inline bool isVisible() { return mVisible; } ///< Returns true if the object is visible
  250. /// Sets the status of this control as active and responding or inactive
  251. /// @param value True if this is active
  252. void setActive(bool value);
  253. bool isActive() { return mActive; } ///< Returns true if this control is active
  254. bool isAwake() { return mAwake; } ///< Returns true if this control is awake
  255. /// @}
  256. /// Get information about the size of a scroll line.
  257. ///
  258. /// @param rowHeight The height, in pixels, of a row
  259. /// @param columnWidth The width, in pixels, of a column
  260. virtual void getScrollLineSizes(U32 *rowHeight, U32 *columnWidth);
  261. /// Get information about the cursor.
  262. /// @param cursor Cursor information will be stored here
  263. /// @param showCursor Will be set to true if the cursor is visible
  264. /// @param lastGuiEvent GuiEvent containing cursor position and modifyer keys (ie ctrl, shift, alt etc)
  265. virtual void getCursor(GuiCursor *&cursor, bool &showCursor, const GuiEvent &lastGuiEvent);
  266. /// @name Children
  267. /// @{
  268. /// Adds an object as a child of this object.
  269. /// @param obj New child object of this control
  270. void addObject(SimObject *obj);
  271. /// Removes a child object from this control.
  272. /// @param obj Object to remove from this control
  273. void removeObject(SimObject *obj);
  274. GuiControl *getParent(); ///< Returns the control which owns this one.
  275. GuiCanvas *getRoot(); ///< Returns the root canvas of this control.
  276. /// @}
  277. /// @name Coordinates
  278. /// @{
  279. /// Translates local coordinates (wrt this object) into global coordinates
  280. ///
  281. /// @param src Local coordinates to translate
  282. Point2I localToGlobalCoord(const Point2I &src);
  283. /// Returns global coordinates translated into local space
  284. ///
  285. /// @param src Global coordinates to translate
  286. Point2I globalToLocalCoord(const Point2I &src);
  287. /// @}
  288. /// @name Resizing
  289. /// @{
  290. /// Changes the size and/or position of this control
  291. /// @param newPosition New position of this control
  292. /// @param newExtent New size of this control
  293. virtual void resize(const Point2I &newPosition, const Point2I &newExtent);
  294. /// Changes the position of this control
  295. /// @param newPosition New position of this control
  296. virtual void setPosition( const Point2I &newPosition );
  297. /// Changes the size of this control
  298. /// @param newExtent New size of this control
  299. virtual void setExtent( const Point2I &newExtent );
  300. /// Changes the bounds of this control
  301. /// @param newBounds New bounds of this control
  302. virtual void setBounds( const RectI &newBounds );
  303. /// Changes the X position of this control
  304. /// @param newXPosition New X Position of this control
  305. virtual void setLeft( S32 newLeft );
  306. /// Changes the Y position of this control
  307. /// @param newYPosition New Y Position of this control
  308. virtual void setTop( S32 newTop );
  309. /// Changes the width of this control
  310. /// @param newWidth New width of this control
  311. virtual void setWidth( S32 newWidth );
  312. /// Changes the height of this control
  313. /// @param newHeight New Height of this control
  314. virtual void setHeight( S32 newHeight );
  315. /// Called when a child control of the object is resized
  316. /// @param child Child object
  317. virtual void childResized(GuiControl *child);
  318. /// Called when this objects parent is resized
  319. /// @param oldParentExtent The old size of the parent object
  320. /// @param newParentExtent The new size of the parent object
  321. virtual void parentResized(const Point2I &oldParentExtent, const Point2I &newParentExtent);
  322. /// @}
  323. /// @name Rendering
  324. /// @{
  325. /// Called when this control is to render itself
  326. /// @param offset The location this control is to begin rendering
  327. /// @param updateRect The screen area this control has drawing access to
  328. virtual void onRender(Point2I offset, const RectI &updateRect);
  329. /// Render a tooltip at the specified cursor position for this control
  330. /// @param cursorPos position of cursor to display the tip near
  331. /// @param tipText optional alternate tip to be rendered
  332. virtual bool renderTooltip(Point2I cursorPos, const char* tipText = NULL );
  333. /// Called when this control should render its children
  334. /// @param offset The top left of the parent control
  335. /// @param contentOffset The top left of the parent's content
  336. /// @param updateRect The screen area this control has drawing access to
  337. virtual void renderChildControls(Point2I offset, RectI content, const RectI &updateRect);
  338. /// Sets the area (local coordinates) this control wants refreshed each frame
  339. /// @param pos UpperLeft point on rectangle of refresh area
  340. /// @param ext Extent of update rect
  341. void setUpdateRegion(Point2I pos, Point2I ext);
  342. /// Sets the update area of the control to encompass the whole control
  343. virtual void setUpdate();
  344. /// @}
  345. //child hierarchy calls
  346. void awaken(); ///< Called when this control and its children have been wired up.
  347. void sleep(); ///< Called when this control is no more.
  348. void preRender(); ///< Prerender this control and all its children.
  349. /// @name Events
  350. ///
  351. /// If you subclass these, make sure to call the Parent::'s versions.
  352. ///
  353. /// @{
  354. /// Called when this object is asked to wake up returns true if it's actually awake at the end
  355. virtual bool onWake();
  356. /// Called when this object is asked to sleep
  357. virtual void onSleep();
  358. /// Do special pre-render proecessing
  359. virtual void onPreRender();
  360. /// Called when this object is removed
  361. virtual void onRemove();
  362. /// Called when one of this objects children is removed
  363. virtual void onChildRemoved( GuiControl *child );
  364. /// Called when this object is added to the scene
  365. bool onAdd();
  366. /// Called when this object has a new child
  367. virtual void onChildAdded( GuiControl *child );
  368. /// @}
  369. /// @name Console
  370. /// @{
  371. /// Returns the value of the variable bound to this object
  372. virtual const char *getScriptValue();
  373. /// Sets the value of the variable bound to this object
  374. virtual void setScriptValue(const char *value);
  375. /// @}
  376. /// @name Input (Keyboard/Mouse)
  377. /// @{
  378. /// This function will return true if the provided coordinates (wrt parent object) are
  379. /// within the bounds of this control
  380. /// @param parentCoordPoint Coordinates to test
  381. virtual bool pointInControl(const Point2I& parentCoordPoint);
  382. /// Returns true if the global cursor is inside this control
  383. bool cursorInControl();
  384. /// Returns the control which the provided point is under, with layering
  385. /// @param pt Point to test
  386. /// @param initialLayer Layer of gui objects to begin the search
  387. virtual GuiControl* findHitControl(const Point2I &pt, S32 initialLayer = -1);
  388. /// Lock the mouse within the provided control
  389. /// @param lockingControl Control to lock the mouse within
  390. void mouseLock(GuiControl *lockingControl);
  391. /// Turn on mouse locking with last used lock control
  392. void mouseLock();
  393. /// Unlock the mouse
  394. void mouseUnlock();
  395. /// Returns true if the mouse is locked
  396. bool isMouseLocked();
  397. /// @}
  398. /// General input handler.
  399. virtual bool onInputEvent(const InputEvent &event);
  400. /// @name Touch/Mouse Events
  401. /// These functions are called when the input event which is
  402. /// in the name of the function occurs.
  403. /// @{
  404. virtual void onTouchUp(const GuiEvent &event);
  405. virtual void onTouchDown(const GuiEvent &event);
  406. virtual void onTouchMove(const GuiEvent &event);
  407. virtual void onTouchDragged(const GuiEvent &event);
  408. virtual void onTouchEnter(const GuiEvent &event);
  409. virtual void onTouchLeave(const GuiEvent &event);
  410. virtual bool onMouseWheelUp(const GuiEvent &event);
  411. virtual bool onMouseWheelDown(const GuiEvent &event);
  412. virtual void onRightMouseDown(const GuiEvent &event);
  413. virtual void onRightMouseUp(const GuiEvent &event);
  414. virtual void onRightMouseDragged(const GuiEvent &event);
  415. virtual void onMiddleMouseDown(const GuiEvent &event);
  416. virtual void onMiddleMouseUp(const GuiEvent &event);
  417. virtual void onMiddleMouseDragged(const GuiEvent &event);
  418. /// @}
  419. /// @name Editor Mouse Events
  420. ///
  421. /// These functions are called when the input event which is
  422. /// in the name of the function occurs. Conversly from normal
  423. /// mouse events, these have a boolean return value that, if
  424. /// they return true, the editor will NOT act on them or be able
  425. /// to respond to this particular event.
  426. ///
  427. /// This is particularly useful for when writing controls so that
  428. /// they may become aware of the editor and allow customization
  429. /// of their data or appearance as if they were actually in use.
  430. /// For example, the GuiTabBookCtrl catches on mouse down to select
  431. /// a tab and NOT let the editor do any instant group manipulation.
  432. ///
  433. /// @{
  434. /// Called when a mouseDown event occurs on a control and the GUI editor is active
  435. /// @param event the GuiEvent which caused the call to this function
  436. /// @param offset the offset which is representative of the units x and y that the editor takes up on screen
  437. virtual bool onMouseDownEditor(const GuiEvent &event, Point2I offset) { return false; };
  438. /// Called when a mouseUp event occurs on a control and the GUI editor is active
  439. /// @param event the GuiEvent which caused the call to this function
  440. /// @param offset the offset which is representative of the units x and y that the editor takes up on screen
  441. virtual bool onMouseUpEditor(const GuiEvent &event, Point2I offset) { return false; };
  442. /// Called when a rightMouseDown event occurs on a control and the GUI editor is active
  443. /// @param event the GuiEvent which caused the call to this function
  444. /// @param offset the offset which is representative of the units x and y that the editor takes up on screen
  445. virtual bool onRightMouseDownEditor(const GuiEvent &event, Point2I offset) { return false; };
  446. /// Called when a mouseDragged event occurs on a control and the GUI editor is active
  447. /// @param event the GuiEvent which caused the call to this function
  448. /// @param offset the offset which is representative of the units x and y that the editor takes up on screen
  449. virtual bool onMouseDraggedEditor(const GuiEvent &event, Point2I offset) { return false; };
  450. /// @}
  451. /// @name Tabs
  452. /// @{
  453. /// Find the first tab-accessable child of this control
  454. virtual GuiControl* findFirstTabable();
  455. /// Find the last tab-accessable child of this control
  456. /// @param firstCall Set to true to clear the global previous responder
  457. virtual GuiControl* findLastTabable(bool firstCall = true);
  458. /// Find previous tab-accessable control with respect to the provided one
  459. /// @param curResponder Current control
  460. /// @param firstCall Set to true to clear the global previous responder
  461. virtual GuiControl* findPrevTabable(GuiControl *curResponder, bool firstCall = true);
  462. /// Find next tab-accessable control with regards to the provided control.
  463. ///
  464. /// @param curResponder Current control
  465. /// @param firstCall Set to true to clear the global current responder
  466. virtual GuiControl* findNextTabable(GuiControl *curResponder, bool firstCall = true);
  467. /// @}
  468. /// Returns true if the provided control is a child (grandchild, or greatgrandchild) of this one.
  469. ///
  470. /// @param child Control to test
  471. virtual bool ControlIsChild(GuiControl *child);
  472. /// @name First Responder
  473. /// A first responder is the control which reacts first, in it's responder chain, to keyboard events
  474. /// The responder chain is set for each parent and so there is only one first responder amongst it's
  475. /// children.
  476. /// @{
  477. /// Sets the first responder for child controls
  478. /// @param firstResponder First responder for this chain
  479. virtual void setFirstResponder(GuiControl *firstResponder);
  480. /// Sets up this control to be the first in it's group to respond to an input event
  481. /// @param value True if this should be a first responder
  482. virtual void makeFirstResponder(bool value);
  483. /// Returns true if this control is a first responder
  484. bool isFirstResponder();
  485. /// Sets this object to be a first responder
  486. virtual void setFirstResponder();
  487. /// Clears the first responder for this chain
  488. void clearFirstResponder();
  489. /// Returns the first responder for this chain
  490. GuiControl *getFirstResponder() { return mFirstResponder; }
  491. /// Occurs when the first responder for this chain is lost
  492. virtual void onLoseFirstResponder();
  493. /// @}
  494. /// @name Keyboard Events
  495. /// @{
  496. /// Adds the accelerator key for this object to the canvas
  497. void addAcceleratorKey();
  498. /// Adds this control's accelerator key to the accelerator map, and
  499. /// recursively tells all children to do the same.
  500. virtual void buildAcceleratorMap();
  501. /// Occurs when the accelerator key for this control is pressed
  502. ///
  503. /// @param index Index in the acclerator map of the key
  504. virtual void acceleratorKeyPress(U32 index);
  505. /// Occurs when the accelerator key for this control is released
  506. ///
  507. /// @param index Index in the acclerator map of the key
  508. virtual void acceleratorKeyRelease(U32 index);
  509. /// Happens when a key is depressed
  510. /// @param event Event descriptor (which contains the key)
  511. virtual bool onKeyDown(const GuiEvent &event);
  512. /// Happens when a key is released
  513. /// @param event Event descriptor (which contains the key)
  514. virtual bool onKeyUp(const GuiEvent &event);
  515. /// Happens when a key is held down, resulting in repeated keystrokes.
  516. /// @param event Event descriptor (which contains the key)
  517. virtual bool onKeyRepeat(const GuiEvent &event);
  518. /// @}
  519. /// Sets the control profile for this control.
  520. ///
  521. /// @see GuiControlProfile
  522. /// @param prof Control profile to apply
  523. void setControlProfile(GuiControlProfile *prof);
  524. /// Occurs when this control performs its "action"
  525. virtual void onAction();
  526. /// @name Peer Messaging
  527. /// Used to send a message to other GUIControls which are children of the same parent.
  528. ///
  529. /// This is mostly used by radio controls.
  530. /// @{
  531. void messageSiblings(S32 message); ///< Send a message to all siblings
  532. virtual void onMessage(GuiControl *sender, S32 msg); ///< Receive a message from another control
  533. /// @}
  534. /// @name Canvas Events
  535. /// Functions called by the canvas
  536. /// @{
  537. /// Called if this object is a dialog, when it is added to the visible layers
  538. virtual void onDialogPush();
  539. /// Called if this object is a dialog, when it is removed from the visible layers
  540. virtual void onDialogPop();
  541. /// @}
  542. /// Renders justified text using the profile.
  543. ///
  544. /// @note This should move into the graphics library at some point
  545. void renderText(Point2I offset, Point2I extent, const char *text, GuiControlProfile *profile, TextRotationOptions rot = tRotateNone);
  546. /// Returns a new rect based on the margins.
  547. RectI applyMargins(Point2I offset, Point2I extent, GuiControlState currentState, GuiControlProfile *profile);
  548. /// Returns the bounds of the rect after considering the borders.
  549. RectI applyBorders(Point2I offset, Point2I extent, GuiControlState currentState, GuiControlProfile *profile);
  550. /// Returns the bounds of the rect this time with padding.
  551. RectI applyPadding(Point2I offset, Point2I extent, GuiControlState currentState, GuiControlProfile *profile);
  552. /// Returns the bounds of the rect with margin, borders, and padding applied.
  553. RectI getInnerRect(Point2I offset, Point2I extent, GuiControlState currentState, GuiControlProfile *profile);
  554. /// Returns the extent of the outer rect given the extent of the inner rect.
  555. Point2I getOuterExtent(Point2I innerExtent, GuiControlState currentState, GuiControlProfile *profile);
  556. void inspectPostApply();
  557. void inspectPreApply();
  558. };
  559. /// @}
  560. #endif