guiControl.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _GUICONTROL_H_
  23. #define _GUICONTROL_H_
  24. #ifndef _MPOINT3_H_
  25. #include "math/mPoint3.h"
  26. #endif
  27. #ifndef _MRECT_H_
  28. #include "math/mRect.h"
  29. #endif
  30. #ifndef _COLOR_H_
  31. #include "core/color.h"
  32. #endif
  33. #ifndef _SIMBASE_H_
  34. #include "console/simBase.h"
  35. #endif
  36. #ifndef _GUITYPES_H_
  37. #include "gui/core/guiTypes.h"
  38. #endif
  39. #ifndef _UTIL_DELEGATE_H_
  40. #include "core/util/delegate.h"
  41. #endif
  42. #ifndef _LANG_H_
  43. #include "i18n/lang.h"
  44. #endif
  45. class GuiCanvas;
  46. class GuiEditCtrl;
  47. class GuiWindowCtrl;
  48. DECLARE_SCOPE( GuiAPI );
  49. /// A delegate used in tool tip rendering.
  50. ///
  51. /// @param hoverPos position to display the tip near
  52. /// @param cursorPos the actual position of the cursor when the delegate is called
  53. /// @param tipText optional alternate tip to be rendered
  54. /// @return Returns true if the tooltip was rendered.
  55. ///
  56. /// @see GuiControl::mRenderTooltipDelegate
  57. typedef Delegate<bool( const Point2I &hoverPos, const Point2I &cursorPos, const char *tipText )> RenderTooltipDelegate;
  58. /// @defgroup gui_group Gui System
  59. /// The GUI system in Torque provides a powerful way of creating
  60. /// WYSIWYG User Interfaces for your Game or Application written
  61. /// in Torque.
  62. ///
  63. /// The GUI Provides a range of different controls that you may use
  64. /// to arrange and layout your GUI's, including Buttons, Lists, Bitmaps
  65. /// Windows, Containers, and HUD elements.
  66. ///
  67. /// The Base Control Class GuiControl provides a basis upon which to
  68. /// write GuiControl's that may be specific to your particular type
  69. /// of game.
  70. /// @addtogroup gui_core_group Core
  71. /// @section GuiControl_Intro Introduction
  72. ///
  73. /// GuiControl is the base class for GUI controls in Torque. It provides these
  74. /// basic areas of functionality:
  75. /// - Inherits from SimGroup, so that controls can have children.
  76. /// - Interfacing with a GuiControlProfile.
  77. /// - An abstraction from the details of handling user input
  78. /// and so forth, providing friendly hooks like onMouseEnter(), onMouseMove(),
  79. /// and onMouseLeave(), onKeyDown(), and so forth.
  80. /// - An abstraction from the details of rendering and resizing.
  81. /// - Helper functions to manipulate the mouse (mouseLock and
  82. /// mouseUnlock), and convert coordinates (localToGlobalCoord() and
  83. /// globalToLocalCoord()).
  84. ///
  85. /// @ref GUI has an overview of the GUI system.
  86. ///
  87. ///
  88. /// @ingroup gui_group Gui System
  89. /// @{
  90. class GuiControl : public SimGroup
  91. {
  92. public:
  93. typedef SimGroup Parent;
  94. friend class GuiWindowCtrl; // mCollapseGroupVec
  95. friend class GuiCanvas;
  96. friend class GuiEditCtrl;
  97. friend class GuiDragAndDropControl; // drag callbacks
  98. /// Additional write flags for GuiControls.
  99. enum
  100. {
  101. NoCheckParentCanSave = BIT( 31 ), ///< Don't inherit mCanSave=false from parents.
  102. };
  103. enum horizSizingOptions
  104. {
  105. horizResizeRight = 0, ///< fixed on the left and width
  106. horizResizeWidth, ///< fixed on the left and right
  107. horizResizeLeft, ///< fixed on the right and width
  108. horizResizeCenter,
  109. horizResizeRelative, ///< resize relative
  110. horizResizeAspectLeft, ///< resize relative to height delta (offset Left)
  111. horizResizeAspectRight, ///< resize relative to height delta (offset Right)
  112. horizResizeAspectCenter, ///< resize relative to height delta (Centered)
  113. horizResizeWindowRelative ///< resize window relative
  114. };
  115. enum vertSizingOptions
  116. {
  117. vertResizeBottom = 0, ///< fixed on the top and in height
  118. vertResizeHeight, ///< fixed on the top and bottom
  119. vertResizeTop, ///< fixed in height and on the bottom
  120. vertResizeCenter,
  121. vertResizeRelative, ///< resize relative
  122. vertResizeAspectTop, ///< resize relative to width delta (offset Left)
  123. vertResizeAspectBottom, ///< resize relative to width delta (offset Right)
  124. vertResizeAspectCenter, ///< resize relative to width delta Centered)
  125. vertResizeWindowRelative ///< resize window relative
  126. };
  127. private:
  128. SimGroup *mAddGroup; ///< The internal name of a SimGroup child of the global GuiGroup in which to organize this gui on creation
  129. RectI mBounds; ///< The internal bounds of this control
  130. protected:
  131. GuiControlProfile* mProfile; ///< The profile for this gui (data settings that are likely to be shared by multiple guis)
  132. GuiControlProfile* mTooltipProfile; ///< The profile for any tooltips
  133. /// @name Control State
  134. /// @{
  135. static bool setProfileProt( void *object, const char *index, const char *data );
  136. static bool setTooltipProfileProt( void *object, const char *index, const char *data );
  137. S32 mTipHoverTime;
  138. /// Delegate called to render a tooltip for this control.
  139. /// By default this will be set to defaultTooltipRender.
  140. RenderTooltipDelegate mRenderTooltipDelegate;
  141. /// The default tooltip rendering function.
  142. /// @see RenderTooltipDelegate
  143. bool defaultTooltipRender( const Point2I &hoverPos, const Point2I &cursorPos, const char* tipText = NULL );
  144. bool mVisible;
  145. bool mActive;
  146. bool mAwake;
  147. bool mSetFirstResponder;
  148. bool mIsContainer; ///< if true, then the GuiEditor can drag other controls into this one.
  149. bool mCanResize;
  150. bool mCanHit;
  151. S32 mLayer;
  152. Point2I mMinExtent;
  153. StringTableEntry mLangTableName;
  154. LangTable *mLangTable;
  155. bool mNotifyChildrenResized;
  156. // Contains array of windows located inside GuiControl
  157. typedef Vector< Vector< GuiWindowCtrl *> > CollapseGroupVec;
  158. CollapseGroupVec mCollapseGroupVec;
  159. static bool smDesignTime; ///< static GuiControl boolean that specifies if the GUI Editor is active
  160. /// @}
  161. /// @name Design Time Editor Access
  162. /// @{
  163. static GuiEditCtrl *smEditorHandle; ///< static GuiEditCtrl pointer that gives controls access to editor-NULL if editor is closed
  164. /// @}
  165. /// @name Keyboard Input
  166. /// @{
  167. GuiControl *mFirstResponder;
  168. static GuiControl *smPrevResponder;
  169. static GuiControl *smCurResponder;
  170. /// @}
  171. /// @name Control State
  172. /// @{
  173. S32 mHorizSizing; ///< Set from horizSizingOptions.
  174. S32 mVertSizing; ///< Set from vertSizingOptions.
  175. StringTableEntry mAcceleratorKey;
  176. StringTableEntry mConsoleVariable;
  177. String mConsoleCommand;
  178. String mAltConsoleCommand;
  179. String mTooltip;
  180. /// @}
  181. /// @name Console
  182. /// The console variable collection of functions allows a console variable to be bound to the GUI control.
  183. ///
  184. /// This allows, say, an edit field to be bound to '$foo'. The value of the console
  185. /// variable '$foo' would then be equal to the text inside the text field. Changing
  186. /// either changes the other.
  187. /// @{
  188. /// $ThisControl variable for callback execution.
  189. static GuiControl* smThisControl;
  190. /// Set $ThisControl and evaluate the given script code.
  191. const char* evaluate( const char* str );
  192. /// Sets the value of the console variable bound to this control
  193. /// @param value String value to assign to control's console variable
  194. void setVariable(const char *value);
  195. /// Sets the value of the console variable bound to this control
  196. /// @param value Integer value to assign to control's console variable
  197. void setIntVariable(S32 value);
  198. /// Sets the value of the console variable bound to this control
  199. /// @param value Float value to assign to control's console variable
  200. void setFloatVariable(F32 value);
  201. const char* getVariable(); ///< Returns value of control's bound variable as a string
  202. S32 getIntVariable(); ///< Returns value of control's bound variable as a integer
  203. F32 getFloatVariable(); ///< Returns value of control's bound variable as a float
  204. GFXStateBlockRef mDefaultGuiSB;
  205. /// @name Callbacks
  206. /// @{
  207. DECLARE_CALLBACK( void, onAdd, () );
  208. DECLARE_CALLBACK( void, onRemove, () );
  209. DECLARE_CALLBACK( void, onWake, () );
  210. DECLARE_CALLBACK( void, onSleep, () );
  211. DECLARE_CALLBACK( void, onLoseFirstResponder, () );
  212. DECLARE_CALLBACK( void, onGainFirstResponder, () );
  213. DECLARE_CALLBACK( void, onAction, () );
  214. DECLARE_CALLBACK( void, onVisible, ( bool state ) );
  215. DECLARE_CALLBACK( void, onActive, ( bool state ) );
  216. DECLARE_CALLBACK( void, onDialogPush, () );
  217. DECLARE_CALLBACK( void, onDialogPop, () );
  218. DECLARE_CALLBACK( void, onControlDragEnter, ( GuiControl* control, const Point2I& dropPoint ) );
  219. DECLARE_CALLBACK( void, onControlDragExit, ( GuiControl* control, const Point2I& dropPoint ) );
  220. DECLARE_CALLBACK( void, onControlDragged, ( GuiControl* control, const Point2I& dropPoint ) );
  221. DECLARE_CALLBACK( void, onControlDropped, ( GuiControl* control, const Point2I& dropPoint ) );
  222. /// @}
  223. public:
  224. /// Set the name of the console variable which this GuiObject is bound to
  225. /// @param variable Variable name
  226. void setConsoleVariable(const char *variable);
  227. /// Set the name of the console function bound to, such as a script function
  228. /// a button calls when clicked.
  229. /// @param newCmd Console function to attach to this GuiControl
  230. void setConsoleCommand( const String& newCmd );
  231. const char * getConsoleCommand(); ///< Returns the name of the function bound to this GuiControl
  232. LangTable *getGUILangTable(void);
  233. const UTF8 *getGUIString(S32 id);
  234. inline String& getTooltip() { return mTooltip; } ///< Returns the tooltip
  235. /// @}
  236. /// @name Callbacks
  237. /// @{
  238. /// Executes a console command, and returns the result.
  239. ///
  240. /// The global console variable $ThisControl is set to the id of the calling
  241. /// control. WARNING: because multiple controls may set $ThisControl, at any time,
  242. /// the value of $ThisControl should be stored in a local variable by the
  243. /// callback code. The use of the $ThisControl variable is not thread safe.
  244. /// Executes mConsoleCommand, and returns the result.
  245. const char* execConsoleCallback();
  246. /// Executes mAltConsoleCommand, and returns the result.
  247. const char* execAltConsoleCallback();
  248. /// @}
  249. static bool _setVisible( void *object, const char *index, const char *data ) { static_cast<GuiControl*>(object)->setVisible( dAtob( data ) ); return false; };
  250. static bool _setActive( void *object, const char *index, const char *data ) { static_cast<GuiControl*>(object)->setActive( dAtob( data ) ); return false; };
  251. /// @name Editor
  252. /// These functions are used by the GUI Editor
  253. /// @{
  254. /// Sets the size of the GuiControl
  255. /// @param horz Width of the control
  256. /// @param vert Height of the control
  257. void setSizing(S32 horz, S32 vert);
  258. /// Overrides Parent Serialization to allow specific controls to not be saved (Dynamic Controls, etc)
  259. void write(Stream &stream, U32 tabStop, U32 flags);
  260. /// Returns boolean as to whether any parent of this control has the 'no serialization' flag set.
  261. bool getCanSaveParent();
  262. /// @}
  263. /// @name Initialization
  264. /// @{
  265. DECLARE_CONOBJECT(GuiControl);
  266. DECLARE_CATEGORY( "Gui Core" );
  267. DECLARE_DESCRIPTION( "Base class for GUI controls. Can also be used as a generic container." );
  268. GuiControl();
  269. virtual ~GuiControl();
  270. virtual bool processArguments(S32 argc, ConsoleValueRef *argv);
  271. static void initPersistFields();
  272. static void consoleInit();
  273. /// @}
  274. /// @name Accessors
  275. /// @{
  276. inline const Point2I& getPosition() const { return mBounds.point; } ///< Returns position of the control
  277. inline const Point2I& getExtent() const { return mBounds.extent; } ///< Returns extents of the control
  278. inline const RectI getBounds()const { return mBounds; } ///< Returns the bounds of the control
  279. inline const RectI getGlobalBounds() ///< Returns the bounds of this object, in global coordinates
  280. {
  281. RectI retRect = getBounds();
  282. retRect.point = localToGlobalCoord( Point2I(0,0) );
  283. return retRect;
  284. };
  285. virtual Point2I getMinExtent() const { return mMinExtent; } ///< Returns minimum size the control can be
  286. virtual void setMinExtent( const Point2I &newMinExtent ) { mMinExtent = newMinExtent; };
  287. inline const S32 getLeft() const { return mBounds.point.x; } ///< Returns the X position of the control
  288. inline const S32 getTop() const { return mBounds.point.y; } ///< Returns the Y position of the control
  289. inline const S32 getWidth() const { return mBounds.extent.x; } ///< Returns the width of the control
  290. inline const S32 getHeight() const { return mBounds.extent.y; } ///< Returns the height of the control
  291. inline const S32 getHorizSizing() const { return mHorizSizing; }
  292. inline const S32 getVertSizing() const { return mVertSizing; }
  293. /// @}
  294. /// @name Flags
  295. /// @{
  296. /// Sets the visibility of the control
  297. /// @param value True if object should be visible
  298. virtual void setVisible(bool value);
  299. inline bool isVisible() const { return mVisible; } ///< Returns true if the object is visible
  300. virtual bool isHidden() const { return !isVisible(); }
  301. virtual void setHidden( bool state ) { setVisible( !state ); }
  302. void setCanHit( bool value ) { mCanHit = value; }
  303. /// Sets the status of this control as active and responding or inactive
  304. /// @param value True if this is active
  305. virtual void setActive(bool value);
  306. bool isActive() { return mActive; } ///< Returns true if this control is active
  307. bool isAwake() { return mAwake; } ///< Returns true if this control is awake
  308. /// @}
  309. /// Get information about the size of a scroll line.
  310. ///
  311. /// @param rowHeight The height, in pixels, of a row
  312. /// @param columnWidth The width, in pixels, of a column
  313. virtual void getScrollLineSizes(U32 *rowHeight, U32 *columnWidth);
  314. /// Get information about the cursor.
  315. /// @param cursor Cursor information will be stored here
  316. /// @param showCursor Will be set to true if the cursor is visible
  317. /// @param lastGuiEvent GuiEvent containing cursor position and modifier keys (ie ctrl, shift, alt etc)
  318. virtual void getCursor(GuiCursor *&cursor, bool &showCursor, const GuiEvent &lastGuiEvent);
  319. /// @name Children
  320. /// @{
  321. /// Adds an object as a child of this object.
  322. /// @param obj New child object of this control
  323. void addObject(SimObject *obj);
  324. /// Removes a child object from this control.
  325. /// @param obj Object to remove from this control
  326. void removeObject(SimObject *obj);
  327. GuiControl *getParent(); ///< Returns the control which owns this one.
  328. GuiCanvas *getRoot(); ///< Returns the root canvas of this control.
  329. virtual bool acceptsAsChild( SimObject* object ) const;
  330. virtual void onGroupRemove();
  331. /// @}
  332. /// @name Coordinates
  333. /// @{
  334. /// Translates local coordinates (wrt this object) into global coordinates
  335. ///
  336. /// @param src Local coordinates to translate
  337. Point2I localToGlobalCoord(const Point2I &src);
  338. /// Returns global coordinates translated into local space
  339. ///
  340. /// @param src Global coordinates to translate
  341. Point2I globalToLocalCoord(const Point2I &src);
  342. /// @}
  343. /// @name Resizing
  344. /// @{
  345. /// Changes the size and/or position of this control
  346. /// @param newPosition New position of this control
  347. /// @param newExtent New size of this control
  348. virtual bool resize(const Point2I &newPosition, const Point2I &newExtent);
  349. /// Changes the position of this control
  350. /// @param newPosition New position of this control
  351. virtual bool setPosition( const Point2I &newPosition );
  352. inline void setPosition( const S32 x, const S32 y ) { setPosition(Point2I(x,y)); }
  353. /// Changes the size of this control
  354. /// @param newExtent New size of this control
  355. virtual bool setExtent( const Point2I &newExtent );
  356. inline void setExtent( const S32 width, const S32 height) { setExtent(Point2I(width, height)); }
  357. /// Changes the bounds of this control
  358. /// @param newBounds New bounds of this control
  359. virtual bool setBounds( const RectI &newBounds );
  360. inline void setBounds( const S32 left, const S32 top,
  361. const S32 width, const S32 height) { setBounds(RectI(left, top, width, height)); }
  362. /// Changes the X position of this control
  363. /// @param newXPosition New X Position of this control
  364. virtual void setLeft( S32 newLeft );
  365. /// Changes the Y position of this control
  366. /// @param newYPosition New Y Position of this control
  367. virtual void setTop( S32 newTop );
  368. /// Changes the width of this control
  369. /// @param newWidth New width of this control
  370. virtual void setWidth( S32 newWidth );
  371. /// Changes the height of this control
  372. /// @param newHeight New Height of this control
  373. virtual void setHeight( S32 newHeight );
  374. /// Called when a child control of the object is resized
  375. /// @param child Child object
  376. virtual void childResized(GuiControl *child);
  377. /// Called when this objects parent is resized
  378. /// @param oldParentRect The old rectangle of the parent object
  379. /// @param newParentRect The new rectangle of the parent object
  380. virtual void parentResized(const RectI &oldParentRect, const RectI &newParentRect);
  381. /// @}
  382. /// @name Rendering
  383. /// @{
  384. /// Called when this control is to render itself
  385. /// @param offset The location this control is to begin rendering
  386. /// @param updateRect The screen area this control has drawing access to
  387. virtual void onRender(Point2I offset, const RectI &updateRect);
  388. /// Called when this control should render its children
  389. /// @param offset The location this control is to begin rendering
  390. /// @param updateRect The screen area this control has drawing access to
  391. void renderChildControls(Point2I offset, const RectI &updateRect);
  392. /// Sets the area (local coordinates) this control wants refreshed each frame
  393. /// @param pos UpperLeft point on rectangle of refresh area
  394. /// @param ext Extent of update rect
  395. void setUpdateRegion(Point2I pos, Point2I ext);
  396. /// Sets the update area of the control to encompass the whole control
  397. virtual void setUpdate();
  398. /// @}
  399. //child hierarchy calls
  400. void awaken(); ///< Called when this control and its children have been wired up.
  401. void sleep(); ///< Called when this control is no more.
  402. void preRender(); ///< Pre-render this control and all its children.
  403. /// @name Events
  404. ///
  405. /// If you subclass these, make sure to call the Parent::'s versions.
  406. ///
  407. /// @{
  408. /// Called when this object is asked to wake up returns true if it's actually awake at the end
  409. virtual bool onWake();
  410. /// Called when this object is asked to sleep
  411. virtual void onSleep();
  412. /// Do special pre-render processing
  413. virtual void onPreRender();
  414. /// Called when this object is removed
  415. virtual void onRemove();
  416. /// Called when one of this objects children is removed
  417. virtual void onChildRemoved( GuiControl *child );
  418. /// Called when this object is added to the scene
  419. virtual bool onAdd();
  420. /// Called when the mProfile or mToolTipProfile is deleted
  421. virtual void onDeleteNotify(SimObject *object);
  422. /// Called when this object has a new child
  423. virtual void onChildAdded( GuiControl *child );
  424. /// @}
  425. /// @name Console
  426. /// @{
  427. /// Returns the value of the variable bound to this object
  428. virtual const char *getScriptValue();
  429. /// Sets the value of the variable bound to this object
  430. virtual void setScriptValue(const char *value);
  431. /// @}
  432. /// @name Input (Keyboard/Mouse)
  433. /// @{
  434. /// This function will return true if the provided coordinates (wrt parent object) are
  435. /// within the bounds of this control
  436. /// @param parentCoordPoint Coordinates to test
  437. virtual bool pointInControl(const Point2I& parentCoordPoint);
  438. /// Returns true if the global cursor is inside this control
  439. bool cursorInControl();
  440. /// Returns the control which the provided point is under, with layering
  441. /// @param pt Point to test
  442. /// @param initialLayer Layer of gui objects to begin the search
  443. virtual GuiControl* findHitControl(const Point2I &pt, S32 initialLayer = -1 );
  444. enum EHitTestFlags
  445. {
  446. HIT_FullBoxOnly = BIT( 0 ), ///< Hit only counts if all of a control's bounds are within the hit rectangle.
  447. HIT_ParentPreventsChildHit = BIT( 1 ), ///< A positive hit test on a parent control will prevent hit tests on children.
  448. HIT_AddParentHits = BIT( 2 ), ///< Parent's that get hit should be added regardless of whether any of their children get hit, too.
  449. HIT_NoCanHitNoRecurse = BIT( 3 ), ///< A hit-disabled control will not recurse into children.
  450. };
  451. ///
  452. virtual bool findHitControls( const RectI& rect, Vector< GuiControl* >& outResult, U32 flags = 0, S32 initialLayer = -1, U32 depth = 0 );
  453. /// Lock the mouse within the provided control
  454. /// @param lockingControl Control to lock the mouse within
  455. void mouseLock(GuiControl *lockingControl);
  456. /// Turn on mouse locking with last used lock control
  457. void mouseLock();
  458. /// Unlock the mouse
  459. void mouseUnlock();
  460. /// Returns true if the mouse is locked
  461. bool isMouseLocked();
  462. /// @}
  463. /// General input handler.
  464. virtual bool onInputEvent(const InputEventInfo &event);
  465. /// @name Mouse Events
  466. /// These functions are called when the input event which is
  467. /// in the name of the function occurs.
  468. /// @{
  469. virtual void onMouseUp(const GuiEvent &event);
  470. virtual void onMouseDown(const GuiEvent &event);
  471. virtual void onMouseMove(const GuiEvent &event);
  472. virtual void onMouseDragged(const GuiEvent &event);
  473. virtual void onMouseEnter(const GuiEvent &event);
  474. virtual void onMouseLeave(const GuiEvent &event);
  475. virtual bool onMouseWheelUp(const GuiEvent &event);
  476. virtual bool onMouseWheelDown(const GuiEvent &event);
  477. virtual void onRightMouseDown(const GuiEvent &event);
  478. virtual void onRightMouseUp(const GuiEvent &event);
  479. virtual void onRightMouseDragged(const GuiEvent &event);
  480. virtual void onMiddleMouseDown(const GuiEvent &event);
  481. virtual void onMiddleMouseUp(const GuiEvent &event);
  482. virtual void onMiddleMouseDragged(const GuiEvent &event);
  483. /// @}
  484. /// @name Gamepad Events
  485. /// These functions are called when the input event which is in the name of
  486. /// the function occurs.
  487. /// @{
  488. virtual bool onGamepadButtonDown(const GuiEvent &event); ///< Default behavior is call-through to onKeyDown
  489. virtual bool onGamepadButtonUp(const GuiEvent &event); ///< Default behavior is call-through to onKeyUp
  490. virtual bool onGamepadAxisUp(const GuiEvent &event);
  491. virtual bool onGamepadAxisDown(const GuiEvent &event);
  492. virtual bool onGamepadAxisLeft(const GuiEvent &event);
  493. virtual bool onGamepadAxisRight(const GuiEvent &event);
  494. virtual bool onGamepadTrigger(const GuiEvent &event);
  495. /// @}
  496. /// @name Editor Mouse Events
  497. ///
  498. /// These functions are called when the input event which is
  499. /// in the name of the function occurs. Conversely from normal
  500. /// mouse events, these have a boolean return value that, if
  501. /// they return true, the editor will NOT act on them or be able
  502. /// to respond to this particular event.
  503. ///
  504. /// This is particularly useful for when writing controls so that
  505. /// they may become aware of the editor and allow customization
  506. /// of their data or appearance as if they were actually in use.
  507. /// For example, the GuiTabBookCtrl catches on mouse down to select
  508. /// a tab and NOT let the editor do any instant group manipulation.
  509. ///
  510. /// @{
  511. /// Called when a mouseDown event occurs on a control and the GUI editor is active
  512. /// @param event the GuiEvent which caused the call to this function
  513. /// @param offset the offset which is representative of the units x and y that the editor takes up on screen
  514. virtual bool onMouseDownEditor(const GuiEvent &event, Point2I offset) { return false; };
  515. /// Called when a mouseUp event occurs on a control and the GUI editor is active
  516. /// @param event the GuiEvent which caused the call to this function
  517. /// @param offset the offset which is representative of the units x and y that the editor takes up on screen
  518. virtual bool onMouseUpEditor(const GuiEvent &event, Point2I offset) { return false; };
  519. /// Called when a rightMouseDown event occurs on a control and the GUI editor is active
  520. /// @param event the GuiEvent which caused the call to this function
  521. /// @param offset the offset which is representative of the units x and y that the editor takes up on screen
  522. virtual bool onRightMouseDownEditor(const GuiEvent &event, Point2I offset) { return false; };
  523. /// Called when a mouseDragged event occurs on a control and the GUI editor is active
  524. /// @param event the GuiEvent which caused the call to this function
  525. /// @param offset the offset which is representative of the units x and y that the editor takes up on screen
  526. virtual bool onMouseDraggedEditor(const GuiEvent &event, Point2I offset) { return false; };
  527. /// @}
  528. /// @name Tabs
  529. /// @{
  530. /// Find the first tab-accessible child of this control
  531. virtual GuiControl* findFirstTabable();
  532. /// Find the last tab-accessible child of this control
  533. /// @param firstCall Set to true to clear the global previous responder
  534. virtual GuiControl* findLastTabable(bool firstCall = true);
  535. /// Find previous tab-accessible control with respect to the provided one
  536. /// @param curResponder Current control
  537. /// @param firstCall Set to true to clear the global previous responder
  538. virtual GuiControl* findPrevTabable(GuiControl *curResponder, bool firstCall = true);
  539. /// Find next tab-accessible control with regards to the provided control.
  540. ///
  541. /// @param curResponder Current control
  542. /// @param firstCall Set to true to clear the global current responder
  543. virtual GuiControl* findNextTabable(GuiControl *curResponder, bool firstCall = true);
  544. /// @}
  545. /// Returns true if the provided control is a child (grandchild, or great-grandchild) of this one.
  546. ///
  547. /// @param child Control to test
  548. virtual bool controlIsChild(GuiControl *child);
  549. /// @name First Responder
  550. /// A first responder is the control which reacts first, in it's responder chain, to keyboard events
  551. /// The responder chain is set for each parent and so there is only one first responder amongst it's
  552. /// children.
  553. /// @{
  554. /// Sets the first responder for child controls
  555. /// @param firstResponder First responder for this chain
  556. virtual void setFirstResponder(GuiControl *firstResponder);
  557. /// Sets up this control to be the first in it's group to respond to an input event
  558. /// @param value True if this should be a first responder
  559. virtual void makeFirstResponder(bool value);
  560. /// Returns true if this control is a first responder
  561. bool isFirstResponder();
  562. /// Sets this object to be a first responder
  563. virtual void setFirstResponder();
  564. /// Clears the first responder for this chain
  565. void clearFirstResponder();
  566. /// Returns the first responder for this chain
  567. GuiControl *getFirstResponder() { return mFirstResponder; }
  568. /// Occurs when the control gains first-responder status.
  569. virtual void onGainFirstResponder();
  570. /// Occurs when the control loses first-responder status.
  571. virtual void onLoseFirstResponder();
  572. /// @}
  573. /// @name Keyboard Events
  574. /// @{
  575. /// Adds the accelerator key for this object to the canvas
  576. void addAcceleratorKey();
  577. /// Adds this control's accelerator key to the accelerator map, and
  578. /// recursively tells all children to do the same.
  579. virtual void buildAcceleratorMap();
  580. /// Occurs when the accelerator key for this control is pressed
  581. ///
  582. /// @param index Index in the accelerator map of the key
  583. virtual void acceleratorKeyPress(U32 index);
  584. /// Occurs when the accelerator key for this control is released
  585. ///
  586. /// @param index Index in the accelerator map of the key
  587. virtual void acceleratorKeyRelease(U32 index);
  588. /// Happens when a key is depressed
  589. /// @param event Event descriptor (which contains the key)
  590. virtual bool onKeyDown(const GuiEvent &event);
  591. /// Happens when a key is released
  592. /// @param event Event descriptor (which contains the key)
  593. virtual bool onKeyUp(const GuiEvent &event);
  594. /// Happens when a key is held down, resulting in repeated keystrokes.
  595. /// @param event Event descriptor (which contains the key)
  596. virtual bool onKeyRepeat(const GuiEvent &event);
  597. /// @}
  598. /// Return the delegate used to render tooltips on this control.
  599. RenderTooltipDelegate& getRenderTooltipDelegate() { return mRenderTooltipDelegate; }
  600. const RenderTooltipDelegate& getRenderTooltipDelegate() const { return mRenderTooltipDelegate; }
  601. /// Returns our tooltip profile (and finds the profile if it hasn't been set yet)
  602. GuiControlProfile* getTooltipProfile() { return mTooltipProfile; }
  603. /// Sets the tooltip profile for this control.
  604. ///
  605. /// @see GuiControlProfile
  606. /// @param prof Tooltip profile to apply
  607. void setTooltipProfile(GuiControlProfile *prof);
  608. /// Returns our profile (and finds the profile if it hasn't been set yet)
  609. GuiControlProfile* getControlProfile() { return mProfile; }
  610. /// Sets the control profile for this control.
  611. ///
  612. /// @see GuiControlProfile
  613. /// @param prof Control profile to apply
  614. void setControlProfile(GuiControlProfile *prof);
  615. /// Occurs when this control performs its "action"
  616. virtual void onAction();
  617. /// @name Peer Messaging
  618. /// Used to send a message to other GUIControls which are children of the same parent.
  619. ///
  620. /// This is mostly used by radio controls.
  621. /// @{
  622. void messageSiblings(S32 message); ///< Send a message to all siblings
  623. virtual void onMessage(GuiControl *sender, S32 msg); ///< Receive a message from another control
  624. /// @}
  625. /// @name Canvas Events
  626. /// Functions called by the canvas
  627. /// @{
  628. /// Called if this object is a dialog, when it is added to the visible layers
  629. virtual void onDialogPush();
  630. /// Called if this object is a dialog, when it is removed from the visible layers
  631. virtual void onDialogPop();
  632. /// @}
  633. /// Renders justified text using the profile.
  634. ///
  635. /// @note This should move into the graphics library at some point
  636. void renderJustifiedText(Point2I offset, Point2I extent, const char *text);
  637. /// Returns text clipped to fit within a pixel width. The clipping
  638. /// occurs on the right side and "..." is appended. It returns width
  639. /// of the final clipped text in pixels.
  640. U32 clipText( String &inOutText, U32 width ) const;
  641. void inspectPostApply();
  642. void inspectPreApply();
  643. };
  644. typedef GuiControl::horizSizingOptions GuiHorizontalSizing;
  645. typedef GuiControl::vertSizingOptions GuiVerticalSizing;
  646. DefineEnumType( GuiHorizontalSizing );
  647. DefineEnumType( GuiVerticalSizing );
  648. /// @}
  649. #endif