guiControl.h 29 KB

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