2
0

guiControl.h 26 KB

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