Torque3D Documentation / _generateds / guiButtonBaseCtrl.cpp

guiButtonBaseCtrl.cpp

Engine/source/gui/buttons/guiButtonBaseCtrl.cpp

More...

Public Variables

Public Functions

ConsoleDocClass(GuiButtonBaseCtrl , "@brief The base class <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the various button <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">controls.\n\n</a>" "This is the base class <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the various types of button controls. If no more specific functionality is <a href="/coding/file/tsshapeconstruct_8cpp/#tsshapeconstruct_8cpp_1a21625ca11566389388a748ad1acc0990">required</a> than " "offered by this class, then it can be instantiated and used directly. Otherwise, its subclasses should be <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">used:\n</a>" "- <a href="/coding/class/classguiradioctrl/">GuiRadioCtrl</a>(radio buttons)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "- <a href="/coding/class/classguicheckboxctrl/">GuiCheckBoxCtrl</a>(checkboxes)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "- <a href="/coding/class/classguibuttonctrl/">GuiButtonCtrl</a>(push buttons with text labels)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "- <a href="/coding/class/classguibitmapbuttonctrl/">GuiBitmapButtonCtrl</a>(bitmapped buttons)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "- <a href="/coding/class/classguibitmapbuttontextctrl/">GuiBitmapButtonTextCtrl</a>(bitmapped buttons with <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> text label)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "- <a href="/coding/class/classguitogglebuttonctrl/">GuiToggleButtonCtrl</a>(toggle buttons, i.e. push buttons with \"sticky\" behavior)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "- <a href="/coding/class/classguiswatchbuttonctrl/">GuiSwatchButtonCtrl</a> (color swatch buttons)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "- <a href="/coding/class/classguiborderbuttonctrl/">GuiBorderButtonCtrl</a> (push buttons <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> surrounding child controls)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "@ingroup GuiButtons" )
DefineEngineMethod(GuiButtonBaseCtrl , getText , const char * , () , "Get the text display on the button's label (<a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> any).\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "@return The button's label." )
DefineEngineMethod(GuiButtonBaseCtrl , performClick , void , () , "Simulate <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> click on the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">button.\n</a>" "This method will trigger the button's action just as <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the button had been pressed by the " "<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">user.\n\n</a>" )
DefineEngineMethod(GuiButtonBaseCtrl , resetState , void , () , "Reset the mousing state of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">button.\n\n</a>" "This method should not generally be called." )
DefineEngineMethod(GuiButtonBaseCtrl , setStateOn , void , (bool isOn) , (true) , "For toggle or radio buttons, set whether the button is currently activated or not. For radio buttons, " "toggling <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> button on will toggle all other radio buttons in its group <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">off.\n\n</a>" " @param isOn If true, the button will be toggled on(<a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> not already);<a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> false, it will be toggled <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">off.\n\n</a>" " @note Toggling the state of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> button with this method will< em >not</em > not trigger the action associated with the " "button. To do that, use performClick()." )
DefineEngineMethod(GuiButtonBaseCtrl , setText , void , (const char *text) , "Set the text displayed on the button's <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">label.\n</a>" "@param text The text <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> display as the button's text <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">label.\n</a>" "@note Not all buttons <a href="/coding/file/editortool_8cpp/#editortool_8cpp_1a4cb041169a32ea3d4cacadbb955e06b4">render</a> text <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">labels.\n\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">getText\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">setTextID\n</a>" )
DefineEngineMethod(GuiButtonBaseCtrl , setTextID , void , (const char *id) , "Set the text displayed on the button's label using <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> string from the string table " "assigned <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">control.\n\n</a>" "@param <a href="/coding/file/win32cursorcontroller_8cpp/#win32cursorcontroller_8cpp_1ab38592509822a5f4674447022cc62efe">id</a> Name of the variable that contains the integer string ID. Used <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> look up " "string in <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">table.\n\n</a>" "@note Not all buttons <a href="/coding/file/editortool_8cpp/#editortool_8cpp_1a4cb041169a32ea3d4cacadbb955e06b4">render</a> text <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">labels.\n\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">setText\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">getText\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiControl::langTableMod\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">LangTable\n\n</a>" "@ref Gui_i18n" )
IMPLEMENT_CALLBACK(GuiButtonBaseCtrl , onClick , void , () , () , "Called when the primary action of the button is triggered (e.g. by <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> left mouse click)." )
IMPLEMENT_CALLBACK(GuiButtonBaseCtrl , onDoubleClick , void , () , () , "Called when the left mouse button is double-clicked on the button." )
IMPLEMENT_CALLBACK(GuiButtonBaseCtrl , onMouseDown , void , () , () , "If #useMouseEvents is true, this is called when the left mouse button is pressed on an(active) " "button." )
IMPLEMENT_CALLBACK(GuiButtonBaseCtrl , onMouseDragged , void , () , () , "If #useMouseEvents is true, this is called when <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> left mouse button drag is detected, i.e. when the user " "pressed the left mouse button on the <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> and then moves the mouse over <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> certain distance threshold with " "the mouse button still pressed." )
IMPLEMENT_CALLBACK(GuiButtonBaseCtrl , onMouseEnter , void , () , () , "If #useMouseEvents is true, this is called when the mouse <a href="/coding/file/sdlcursorcontroller_8cpp/#sdlcursorcontroller_8cpp_1a06e8dd1f849973ccc456f8553601e8b9">cursor</a> moves over the button(only <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the button " "is the front-most visible <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a>, though)." )
IMPLEMENT_CALLBACK(GuiButtonBaseCtrl , onMouseLeave , void , () , () , "If #useMouseEvents is true, this is called when the mouse <a href="/coding/file/sdlcursorcontroller_8cpp/#sdlcursorcontroller_8cpp_1a06e8dd1f849973ccc456f8553601e8b9">cursor</a> moves off the button(only <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the button " "had previously received an onMouseEvent() event)." )
IMPLEMENT_CALLBACK(GuiButtonBaseCtrl , onMouseUp , void , () , () , "If #useMouseEvents is true, this is called when the left mouse button is release over an(active) " "<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">button.\n\n</a>" " @note To trigger actions, better use onClick() since onMouseUp() will also be called when the mouse was " "not originally pressed on the button." )
IMPLEMENT_CALLBACK(GuiButtonBaseCtrl , onRightClick , void , () , () , "Called when the right mouse button is clicked on the button." )
ImplementEnumType(GuiButtonType , "Type of button <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">control.\n\n</a>" "@ingroup GuiButtons" )

Detailed Description

Public Variables

 EndImplementEnumType 

Public Functions

ConsoleDocClass(GuiButtonBaseCtrl , "@brief The base class <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the various button <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">controls.\n\n</a>" "This is the base class <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the various types of button controls. If no more specific functionality is <a href="/coding/file/tsshapeconstruct_8cpp/#tsshapeconstruct_8cpp_1a21625ca11566389388a748ad1acc0990">required</a> than " "offered by this class, then it can be instantiated and used directly. Otherwise, its subclasses should be <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">used:\n</a>" "- <a href="/coding/class/classguiradioctrl/">GuiRadioCtrl</a>(radio buttons)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "- <a href="/coding/class/classguicheckboxctrl/">GuiCheckBoxCtrl</a>(checkboxes)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "- <a href="/coding/class/classguibuttonctrl/">GuiButtonCtrl</a>(push buttons with text labels)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "- <a href="/coding/class/classguibitmapbuttonctrl/">GuiBitmapButtonCtrl</a>(bitmapped buttons)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "- <a href="/coding/class/classguibitmapbuttontextctrl/">GuiBitmapButtonTextCtrl</a>(bitmapped buttons with <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> text label)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "- <a href="/coding/class/classguitogglebuttonctrl/">GuiToggleButtonCtrl</a>(toggle buttons, i.e. push buttons with \"sticky\" behavior)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "- <a href="/coding/class/classguiswatchbuttonctrl/">GuiSwatchButtonCtrl</a> (color swatch buttons)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "- <a href="/coding/class/classguiborderbuttonctrl/">GuiBorderButtonCtrl</a> (push buttons <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> surrounding child controls)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "@ingroup GuiButtons" )

DefineEngineMethod(GuiButtonBaseCtrl , getText , const char * , () , "Get the text display on the button's label (<a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> any).\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "@return The button's label." )

DefineEngineMethod(GuiButtonBaseCtrl , performClick , void , () , "Simulate <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> click on the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">button.\n</a>" "This method will trigger the button's action just as <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the button had been pressed by the " "<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">user.\n\n</a>" )

DefineEngineMethod(GuiButtonBaseCtrl , resetState , void , () , "Reset the mousing state of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">button.\n\n</a>" "This method should not generally be called." )

DefineEngineMethod(GuiButtonBaseCtrl , setStateOn , void , (bool isOn) , (true) , "For toggle or radio buttons, set whether the button is currently activated or not. For radio buttons, " "toggling <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> button on will toggle all other radio buttons in its group <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">off.\n\n</a>" " @param isOn If true, the button will be toggled on(<a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> not already);<a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> false, it will be toggled <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">off.\n\n</a>" " @note Toggling the state of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> button with this method will< em >not</em > not trigger the action associated with the " "button. To do that, use performClick()." )

DefineEngineMethod(GuiButtonBaseCtrl , setText , void , (const char *text) , "Set the text displayed on the button's <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">label.\n</a>" "@param text The text <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> display as the button's text <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">label.\n</a>" "@note Not all buttons <a href="/coding/file/editortool_8cpp/#editortool_8cpp_1a4cb041169a32ea3d4cacadbb955e06b4">render</a> text <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">labels.\n\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">getText\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">setTextID\n</a>" )

DefineEngineMethod(GuiButtonBaseCtrl , setTextID , void , (const char *id) , "Set the text displayed on the button's label using <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> string from the string table " "assigned <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">control.\n\n</a>" "@param <a href="/coding/file/win32cursorcontroller_8cpp/#win32cursorcontroller_8cpp_1ab38592509822a5f4674447022cc62efe">id</a> Name of the variable that contains the integer string ID. Used <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> look up " "string in <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">table.\n\n</a>" "@note Not all buttons <a href="/coding/file/editortool_8cpp/#editortool_8cpp_1a4cb041169a32ea3d4cacadbb955e06b4">render</a> text <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">labels.\n\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">setText\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">getText\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiControl::langTableMod\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">LangTable\n\n</a>" "@ref Gui_i18n" )

IMPLEMENT_CALLBACK(GuiButtonBaseCtrl , onClick , void , () , () , "Called when the primary action of the button is triggered (e.g. by <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> left mouse click)." )

IMPLEMENT_CALLBACK(GuiButtonBaseCtrl , onDoubleClick , void , () , () , "Called when the left mouse button is double-clicked on the button." )

IMPLEMENT_CALLBACK(GuiButtonBaseCtrl , onMouseDown , void , () , () , "If #useMouseEvents is true, this is called when the left mouse button is pressed on an(active) " "button." )

IMPLEMENT_CALLBACK(GuiButtonBaseCtrl , onMouseDragged , void , () , () , "If #useMouseEvents is true, this is called when <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> left mouse button drag is detected, i.e. when the user " "pressed the left mouse button on the <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> and then moves the mouse over <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> certain distance threshold with " "the mouse button still pressed." )

IMPLEMENT_CALLBACK(GuiButtonBaseCtrl , onMouseEnter , void , () , () , "If #useMouseEvents is true, this is called when the mouse <a href="/coding/file/sdlcursorcontroller_8cpp/#sdlcursorcontroller_8cpp_1a06e8dd1f849973ccc456f8553601e8b9">cursor</a> moves over the button(only <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the button " "is the front-most visible <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a>, though)." )

IMPLEMENT_CALLBACK(GuiButtonBaseCtrl , onMouseLeave , void , () , () , "If #useMouseEvents is true, this is called when the mouse <a href="/coding/file/sdlcursorcontroller_8cpp/#sdlcursorcontroller_8cpp_1a06e8dd1f849973ccc456f8553601e8b9">cursor</a> moves off the button(only <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the button " "had previously received an onMouseEvent() event)." )

IMPLEMENT_CALLBACK(GuiButtonBaseCtrl , onMouseUp , void , () , () , "If #useMouseEvents is true, this is called when the left mouse button is release over an(active) " "<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">button.\n\n</a>" " @note To trigger actions, better use onClick() since onMouseUp() will also be called when the mouse was " "not originally pressed on the button." )

IMPLEMENT_CALLBACK(GuiButtonBaseCtrl , onRightClick , void , () , () , "Called when the right mouse button is clicked on the button." )

IMPLEMENT_CONOBJECT(GuiButtonBaseCtrl )

ImplementEnumType(GuiButtonType , "Type of button <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">control.\n\n</a>" "@ingroup GuiButtons" )

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#include "gui/buttons/guiButtonBaseCtrl.h"
 25
 26#include "console/console.h"
 27#include "console/engineAPI.h"
 28#include "gfx/gfxDevice.h"
 29#include "gui/core/guiCanvas.h"
 30#include "i18n/lang.h"
 31#include "sfx/sfxSystem.h"
 32#include "sfx/sfxTrack.h"
 33
 34
 35IMPLEMENT_CONOBJECT( GuiButtonBaseCtrl );
 36
 37ConsoleDocClass( GuiButtonBaseCtrl,
 38   "@brief The base class for the various button controls.\n\n"
 39   
 40   "This is the base class for the various types of button controls.  If no more specific functionality is required than "
 41   "offered by this class, then it can be instantiated and used directly.  Otherwise, its subclasses should be used:\n"
 42   
 43   "- GuiRadioCtrl (radio buttons)\n"
 44   "- GuiCheckBoxCtrl (checkboxes)\n"
 45   "- GuiButtonCtrl (push buttons with text labels)\n"
 46   "- GuiBitmapButtonCtrl (bitmapped buttons)\n"
 47   "- GuiBitmapButtonTextCtrl (bitmapped buttons with a text label)\n"
 48   "- GuiToggleButtonCtrl (toggle buttons, i.e. push buttons with \"sticky\" behavior)\n"
 49   "- GuiSwatchButtonCtrl (color swatch buttons)\n"
 50   "- GuiBorderButtonCtrl (push buttons for surrounding child controls)\n\n"
 51   
 52   "@ingroup GuiButtons"
 53);
 54
 55IMPLEMENT_CALLBACK( GuiButtonBaseCtrl, onMouseDown, void, (), (),
 56   "If #useMouseEvents is true, this is called when the left mouse button is pressed on an (active) "
 57   "button." );
 58
 59IMPLEMENT_CALLBACK( GuiButtonBaseCtrl, onMouseUp, void, (), (),
 60   "If #useMouseEvents is true, this is called when the left mouse button is release over an (active) "
 61   "button.\n\n"
 62   "@note To trigger actions, better use onClick() since onMouseUp() will also be called when the mouse was "
 63      "not originally pressed on the button." );
 64
 65IMPLEMENT_CALLBACK( GuiButtonBaseCtrl, onClick, void, (), (),
 66   "Called when the primary action of the button is triggered (e.g. by a left mouse click)." );
 67
 68IMPLEMENT_CALLBACK( GuiButtonBaseCtrl, onDoubleClick, void, (), (),
 69   "Called when the left mouse button is double-clicked on the button." );
 70
 71IMPLEMENT_CALLBACK( GuiButtonBaseCtrl, onRightClick, void, (), (),
 72   "Called when the right mouse button is clicked on the button." );
 73
 74IMPLEMENT_CALLBACK( GuiButtonBaseCtrl, onMouseEnter, void, (), (),
 75   "If #useMouseEvents is true, this is called when the mouse cursor moves over the button (only if the button "
 76   "is the front-most visible control, though)." );
 77
 78IMPLEMENT_CALLBACK( GuiButtonBaseCtrl, onMouseLeave, void, (), (),
 79   "If #useMouseEvents is true, this is called when the mouse cursor moves off the button (only if the button "
 80   "had previously received an onMouseEvent() event)." );
 81
 82IMPLEMENT_CALLBACK( GuiButtonBaseCtrl, onMouseDragged, void, (), (),
 83   "If #useMouseEvents is true, this is called when a left mouse button drag is detected, i.e. when the user "
 84   "pressed the left mouse button on the control and then moves the mouse over a certain distance threshold with "
 85   "the mouse button still pressed." );
 86
 87
 88ImplementEnumType( GuiButtonType,
 89   "Type of button control.\n\n"
 90   "@ingroup GuiButtons" )
 91   { GuiButtonBaseCtrl::ButtonTypePush, "PushButton", "A button that triggers an action when clicked." },
 92   { GuiButtonBaseCtrl::ButtonTypeCheck, "ToggleButton", "A button that is toggled between on and off state." },
 93   { GuiButtonBaseCtrl::ButtonTypeRadio, "RadioButton", "A button placed in groups for presenting choices." },
 94EndImplementEnumType;
 95
 96
 97//-----------------------------------------------------------------------------
 98
 99GuiButtonBaseCtrl::GuiButtonBaseCtrl()
100{
101   mDepressed = false;
102   mMouseOver = false;
103   mActive = true;
104   static StringTableEntry sButton = StringTable->insert( "Button" );
105   mButtonText = sButton;
106   mButtonTextID = StringTable->EmptyString();
107   mStateOn = false;
108   mRadioGroup = -1;
109   mButtonType = ButtonTypePush;
110   mUseMouseEvents = false;
111   mMouseDragged = false;
112}
113
114//-----------------------------------------------------------------------------
115
116void GuiButtonBaseCtrl::initPersistFields()
117{
118   addGroup( "Button" );
119      
120      addField( "text", TypeCaseString, Offset(mButtonText, GuiButtonBaseCtrl),
121         "Text label to display on button (if button class supports text labels)." );
122      addField( "textID", TypeString, Offset(mButtonTextID, GuiButtonBaseCtrl),
123         "ID of string in string table to use for text label on button.\n\n"
124         "@see setTextID\n"
125         "@see GuiControl::langTableMod\n"
126         "@see LangTable\n\n" );
127      addField( "groupNum", TypeS32, Offset(mRadioGroup, GuiButtonBaseCtrl),
128         "Radio button toggle group number.  All radio buttons that are assigned the same #groupNum and that "
129         "are parented to the same control will synchronize their toggle state, i.e. if one radio button is toggled on "
130         "all other radio buttons in its group will be toggled off.\n\n" 
131         "The default group is -1." );
132      addField( "buttonType", TYPEID< ButtonType >(), Offset(mButtonType, GuiButtonBaseCtrl),
133         "Button behavior type.\n" );
134      addField( "useMouseEvents", TypeBool, Offset(mUseMouseEvents, GuiButtonBaseCtrl),
135         "If true, mouse events will be passed on to script.  Default is false.\n" );
136      
137   endGroup( "Button" );
138   
139   Parent::initPersistFields();
140}
141
142//-----------------------------------------------------------------------------
143
144bool GuiButtonBaseCtrl::onWake()
145{
146   if(!Parent::onWake())
147      return false;
148
149   // is we have a script variable, make sure we're in sync
150   if ( mConsoleVariable[0] )
151      mStateOn = Con::getBoolVariable( mConsoleVariable );
152   if(mButtonTextID && *mButtonTextID != 0)
153      setTextID(mButtonTextID);
154
155   return true;
156}
157
158//-----------------------------------------------------------------------------
159
160void GuiButtonBaseCtrl::setText( const char* text )
161{
162   mButtonText = StringTable->insert(text, true);
163}
164
165//-----------------------------------------------------------------------------
166
167void GuiButtonBaseCtrl::setTextID(const char *id)
168{
169   S32 n = Con::getIntVariable(id, -1);
170   if(n != -1)
171   {
172      mButtonTextID = StringTable->insert(id);
173      setTextID(n);
174   }
175}
176
177//-----------------------------------------------------------------------------
178
179void GuiButtonBaseCtrl::setTextID(S32 id)
180{
181   const UTF8 *str = getGUIString(id);
182   if(str)
183      setText((const char*)str);
184   //mButtonTextID = id;
185}
186
187//-----------------------------------------------------------------------------
188
189const char *GuiButtonBaseCtrl::getText()
190{
191   return mButtonText;
192}
193
194//-----------------------------------------------------------------------------
195
196void GuiButtonBaseCtrl::setStateOn( bool bStateOn )
197{
198   if(!mActive)
199      return;
200
201   if(mButtonType == ButtonTypeCheck)
202   {
203      mStateOn = bStateOn;
204   }
205   else if(mButtonType == ButtonTypeRadio)
206   {
207      messageSiblings(mRadioGroup);
208      mStateOn = bStateOn;
209   }     
210   setUpdate();
211}
212
213//-----------------------------------------------------------------------------
214
215void GuiButtonBaseCtrl::acceleratorKeyPress(U32)
216{
217   if( !mActive )
218      return;
219
220   //set the bool
221   mDepressed = true;
222
223   if (mProfile->mTabable)
224      setFirstResponder();
225}
226
227//-----------------------------------------------------------------------------
228
229void GuiButtonBaseCtrl::acceleratorKeyRelease(U32)
230{
231   if (! mActive)
232      return;
233
234   if (mDepressed)
235   {
236      //set the bool
237      mDepressed = false;
238      //perform the action
239      onAction();
240   }
241
242   //update
243   setUpdate();
244}
245
246//-----------------------------------------------------------------------------
247
248void GuiButtonBaseCtrl::onMouseDown(const GuiEvent &event)
249{
250   if (! mActive)
251      return;
252
253   if (mProfile->mCanKeyFocus)
254      setFirstResponder();
255
256   if (mProfile->mSoundButtonDown)
257      SFX->playOnce(mProfile->mSoundButtonDown);
258      
259   mMouseDownPoint = event.mousePoint;
260   mMouseDragged = false;
261
262   if( mUseMouseEvents )
263     onMouseDown_callback();
264
265   //lock the mouse
266   mouseLock();
267   mDepressed = true;
268
269   // If we have a double click then execute the alt command.
270   if ( event.mouseClickCount == 2 )
271   {
272      onDoubleClick_callback();
273      execAltConsoleCallback();
274   }
275
276   //update
277   setUpdate();
278}
279
280//-----------------------------------------------------------------------------
281
282void GuiButtonBaseCtrl::onMouseEnter(const GuiEvent &event)
283{
284   setUpdate();
285
286   if( mUseMouseEvents )
287      onMouseEnter_callback();
288
289   if(isMouseLocked())
290   {
291      mDepressed = true;
292      mMouseOver = true;
293   }
294   else
295   {
296      if ( mActive && mProfile->mSoundButtonOver )
297         SFX->playOnce(mProfile->mSoundButtonOver);
298
299      mMouseOver = true;
300   }
301}
302
303//-----------------------------------------------------------------------------
304
305void GuiButtonBaseCtrl::onMouseLeave(const GuiEvent &)
306{
307   setUpdate();
308
309   if( mUseMouseEvents )
310      onMouseLeave_callback();
311   if( isMouseLocked() )
312      mDepressed = false;
313   mMouseOver = false;
314}
315
316//-----------------------------------------------------------------------------
317
318void GuiButtonBaseCtrl::onMouseUp(const GuiEvent &event)
319{
320   mouseUnlock();
321
322   if( !mActive )
323      return;
324   
325   setUpdate();
326
327   if( mUseMouseEvents )
328      onMouseUp_callback();
329
330   //if we released the mouse within this control, perform the action
331   if( mDepressed )
332      onAction();
333
334   mDepressed = false;
335   mMouseDragged = false;
336}
337
338//-----------------------------------------------------------------------------
339
340void GuiButtonBaseCtrl::onRightMouseUp(const GuiEvent &event)
341{
342   onRightClick_callback();
343   Parent::onRightMouseUp( event );
344}
345
346//-----------------------------------------------------------------------------
347
348void GuiButtonBaseCtrl::onMouseDragged( const GuiEvent& event )
349{
350   if( mUseMouseEvents )
351   {
352      // If we haven't started a drag yet, find whether we have moved past
353      // the tolerance value.
354      
355      if( !mMouseDragged )
356      {
357         Point2I delta = mMouseDownPoint - event.mousePoint;
358         if( mAbs( delta.x ) > 2 || mAbs( delta.y ) > 2 )
359            mMouseDragged = true;
360      }
361      
362      if( mMouseDragged )
363         onMouseDragged_callback();
364   }
365      
366   Parent::onMouseDragged( event );
367}
368
369//-----------------------------------------------------------------------------
370
371bool GuiButtonBaseCtrl::onKeyDown(const GuiEvent &event)
372{
373   //if the control is a dead end, kill the event
374   if (!mActive)
375      return true;
376
377   //see if the key down is a return or space or not
378   if ((event.keyCode == KEY_RETURN || event.keyCode == KEY_SPACE)
379       && event.modifier == 0)
380   {
381      if ( mProfile->mSoundButtonDown )
382         SFX->playOnce( mProfile->mSoundButtonDown);
383
384      return true;
385   }
386   //otherwise, pass the event to it's parent
387   return Parent::onKeyDown(event);
388}
389
390//-----------------------------------------------------------------------------
391
392bool GuiButtonBaseCtrl::onKeyUp(const GuiEvent &event)
393{
394   //if the control is a dead end, kill the event
395   if (!mActive)
396      return true;
397
398   //see if the key down is a return or space or not
399   if (mDepressed &&
400      (event.keyCode == KEY_RETURN || event.keyCode == KEY_SPACE) &&
401      event.modifier == 0)
402   {
403      onAction();
404      return true;
405   }
406
407   //otherwise, pass the event to it's parent
408   return Parent::onKeyUp(event);
409}
410
411//-----------------------------------------------------------------------------
412
413void GuiButtonBaseCtrl::setScriptValue(const char *value)
414{
415   mStateOn = dAtob(value);
416
417   // Update the console variable:
418   if ( mConsoleVariable[0] )
419      Con::setBoolVariable( mConsoleVariable, mStateOn );
420
421   setUpdate();
422}
423
424//-----------------------------------------------------------------------------
425
426const char *GuiButtonBaseCtrl::getScriptValue()
427{
428   return mStateOn ? "1" : "0";
429}
430
431//-----------------------------------------------------------------------------
432
433void GuiButtonBaseCtrl::onAction()
434{
435    if(!mActive)
436        return;
437
438    if(mButtonType == ButtonTypeCheck)
439    {
440        mStateOn = mStateOn ? false : true;
441   }
442   else if(mButtonType == ButtonTypeRadio)
443    {
444        mStateOn = true;
445        messageSiblings(mRadioGroup);
446    }
447    setUpdate();
448
449   // Update the console variable:
450   if ( mConsoleVariable[0] )
451      Con::setBoolVariable( mConsoleVariable, mStateOn );
452
453    onClick_callback();
454    Parent::onAction();
455}
456
457//-----------------------------------------------------------------------------
458
459void GuiButtonBaseCtrl::onMessage( GuiControl *sender, S32 msg )
460{
461   Parent::onMessage(sender, msg);
462   if( mRadioGroup == msg && mButtonType == ButtonTypeRadio )
463   {
464      setUpdate();
465      mStateOn = ( sender == this );
466
467      // Update the console variable:
468      if ( mConsoleVariable[0] )
469         Con::setBoolVariable( mConsoleVariable, mStateOn );
470   }
471}
472
473//=============================================================================
474//    Console Methods.
475//=============================================================================
476// MARK: ---- Console Methods ----
477
478//-----------------------------------------------------------------------------
479
480DefineEngineMethod( GuiButtonBaseCtrl, performClick, void, (),,
481   "Simulate a click on the button.\n"
482   "This method will trigger the button's action just as if the button had been pressed by the "
483   "user.\n\n" )
484{
485   object->onAction();
486}
487
488//-----------------------------------------------------------------------------
489
490DefineEngineMethod( GuiButtonBaseCtrl, setText, void, ( const char* text ),,
491   "Set the text displayed on the button's label.\n"
492   "@param text The text to display as the button's text label.\n"
493   "@note Not all buttons render text labels.\n\n"
494   "@see getText\n"
495   "@see setTextID\n" )
496{
497   object->setText( text );
498}
499
500//-----------------------------------------------------------------------------
501
502DefineEngineMethod( GuiButtonBaseCtrl, setTextID, void, ( const char* id ),,
503   "Set the text displayed on the button's label using a string from the string table "
504   "assigned to the control.\n\n"
505   "@param id Name of the variable that contains the integer string ID.  Used to look up "
506      "string in table.\n\n"
507   "@note Not all buttons render text labels.\n\n"
508   "@see setText\n"
509   "@see getText\n"
510   "@see GuiControl::langTableMod\n"
511   "@see LangTable\n\n"
512   "@ref Gui_i18n" )
513{
514   object->setTextID( id );
515}
516
517//-----------------------------------------------------------------------------
518
519DefineEngineMethod( GuiButtonBaseCtrl, getText, const char*, (),,
520   "Get the text display on the button's label (if any).\n\n"
521   "@return The button's label." )
522{
523   return object->getText( );
524}
525
526//-----------------------------------------------------------------------------
527
528DefineEngineMethod( GuiButtonBaseCtrl, setStateOn, void, ( bool isOn ), ( true ),
529   "For toggle or radio buttons, set whether the button is currently activated or not.  For radio buttons, "
530   "toggling a button on will toggle all other radio buttons in its group to off.\n\n"
531   "@param isOn If true, the button will be toggled on (if not already); if false, it will be toggled off.\n\n"
532   "@note Toggling the state of a button with this method will <em>not</em> not trigger the action associated with the "
533      "button.  To do that, use performClick()." )
534{
535   object->setStateOn( isOn );
536}
537
538//-----------------------------------------------------------------------------
539
540DefineEngineMethod( GuiButtonBaseCtrl, resetState, void, (),,
541   "Reset the mousing state of the button.\n\n"
542   "This method should not generally be called." )
543{
544   object->resetState();
545}
546