guiControl.h 26 KB

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