guiControl.h 35 KB

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