mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-13 15:44:36 +00:00
Merge pull request #598 from OTHGMars/canvasCallbacks
GuiCanvas keyboard mode callbacks.
This commit is contained in:
commit
4de330eaed
2 changed files with 73 additions and 6 deletions
|
|
@ -94,6 +94,33 @@ ConsoleDocClass( GuiCanvas,
|
||||||
|
|
||||||
"@ingroup GuiCore\n");
|
"@ingroup GuiCore\n");
|
||||||
|
|
||||||
|
ImplementEnumType(KeyboardTranslationMode,
|
||||||
|
"Modes for handling keyboard translation or native accelerator requests.\n\n")
|
||||||
|
{ GuiCanvas::TranslationMode_Platform, "Platform",
|
||||||
|
"Requests will be passed to the platform window for handling." },
|
||||||
|
{ GuiCanvas::TranslationMode_Callback, "Callback",
|
||||||
|
"Script callbacks will be issued to notify and allow override of these events." },
|
||||||
|
{ GuiCanvas::TranslationMode_Ignore, "Ignore",
|
||||||
|
"Requsts to enable/disable keyboard translations or native accelerators will be ignored "
|
||||||
|
"with no callback triggered." },
|
||||||
|
EndImplementEnumType;
|
||||||
|
|
||||||
|
IMPLEMENT_CALLBACK(GuiCanvas, onSetKeyboardTranslationEnabled, bool, (bool enable), (enable),
|
||||||
|
"Called when the canvas receives an enableKeyboardTranslation request. This is usually the "
|
||||||
|
"result of a GuitTextInputCtrl gaining or losing focus. Return true to allow the request "
|
||||||
|
"to be passed to the platform window. Return false to override the request and handle it in script.\n\n"
|
||||||
|
"@note This callback is only issued if keyTranslationMode is set to \"Callback\" for this canvas.\n"
|
||||||
|
"@param enable Requested keyboard translation state.\n"
|
||||||
|
"@see KeyboardTranslationMode\n");
|
||||||
|
|
||||||
|
IMPLEMENT_CALLBACK(GuiCanvas, onSetNativeAcceleratorsEnabled, bool, (bool enable), (enable),
|
||||||
|
"Called when the canvas receives a setNativeAcceleratorsEnabled request. This is usually the "
|
||||||
|
"result of a GuitTextInputCtrl gaining or losing focus. Return true to allow the request to "
|
||||||
|
"be passed to the platform window. Return false to override the request and handle it in script.\n\n"
|
||||||
|
"@note This callback is only issued if nativeAcceleratorMode is set to \"Callback\" for this canvas.\n"
|
||||||
|
"@param enable Requested accelerator state.\n"
|
||||||
|
"@see KeyboardTranslationMode\n");
|
||||||
|
|
||||||
ColorI gCanvasClearColor( 255, 0, 255 ); ///< For GFX->clear
|
ColorI gCanvasClearColor( 255, 0, 255 ); ///< For GFX->clear
|
||||||
|
|
||||||
extern InputModifiers convertModifierBits(const U32 in);
|
extern InputModifiers convertModifierBits(const U32 in);
|
||||||
|
|
@ -127,6 +154,8 @@ GuiCanvas::GuiCanvas(): GuiControl(),
|
||||||
mHoverPositionSet(false),
|
mHoverPositionSet(false),
|
||||||
mLeftMouseLast(false),
|
mLeftMouseLast(false),
|
||||||
mHoverLeftControlTime(0),
|
mHoverLeftControlTime(0),
|
||||||
|
mKeyTranslationMode(TranslationMode_Platform),
|
||||||
|
mNativeAcceleratorMode(TranslationMode_Platform),
|
||||||
mMiddleMouseLast(false),
|
mMiddleMouseLast(false),
|
||||||
mRightMouseLast(false),
|
mRightMouseLast(false),
|
||||||
mMouseDownPoint(0.0f,0.0f),
|
mMouseDownPoint(0.0f,0.0f),
|
||||||
|
|
@ -183,6 +212,13 @@ void GuiCanvas::initPersistFields()
|
||||||
addField("displayWindow", TypeBool, Offset(mDisplayWindow, GuiCanvas), "Controls if the canvas window is rendered or not." );
|
addField("displayWindow", TypeBool, Offset(mDisplayWindow, GuiCanvas), "Controls if the canvas window is rendered or not." );
|
||||||
endGroup("Canvas Rendering");
|
endGroup("Canvas Rendering");
|
||||||
|
|
||||||
|
addGroup("KeyboardMode Callbacks");
|
||||||
|
addField("keyTranslationMode", TYPEID< KeyTranslationMode >(), Offset(mKeyTranslationMode, GuiCanvas),
|
||||||
|
"How to handle enable/disable keyboard translation requests. \"Platform\", \"Callback\" or \"Ignore\".\n");
|
||||||
|
addField("nativeAcceleratorMode", TYPEID< KeyTranslationMode >(), Offset(mNativeAcceleratorMode, GuiCanvas),
|
||||||
|
"How to handle enable/disable native accelerator requests. \"Platform\", \"Callback\" or \"Ignore\".\n");
|
||||||
|
endGroup("KeyboardMode Callbacks");
|
||||||
|
|
||||||
Parent::initPersistFields();
|
Parent::initPersistFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -442,20 +478,32 @@ Point2I GuiCanvas::getWindowSize()
|
||||||
|
|
||||||
void GuiCanvas::enableKeyboardTranslation()
|
void GuiCanvas::enableKeyboardTranslation()
|
||||||
{
|
{
|
||||||
AssertISV(mPlatformWindow, "GuiCanvas::enableKeyboardTranslation - no window present!");
|
if ((mKeyTranslationMode == TranslationMode_Platform) ||
|
||||||
mPlatformWindow->setKeyboardTranslation(true);
|
((mKeyTranslationMode == TranslationMode_Callback) && onSetKeyboardTranslationEnabled_callback(true)))
|
||||||
|
{
|
||||||
|
AssertISV(mPlatformWindow, "GuiCanvas::enableKeyboardTranslation - no window present!");
|
||||||
|
mPlatformWindow->setKeyboardTranslation(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiCanvas::disableKeyboardTranslation()
|
void GuiCanvas::disableKeyboardTranslation()
|
||||||
{
|
{
|
||||||
AssertISV(mPlatformWindow, "GuiCanvas::disableKeyboardTranslation - no window present!");
|
if ((mKeyTranslationMode == TranslationMode_Platform) ||
|
||||||
mPlatformWindow->setKeyboardTranslation(false);
|
((mKeyTranslationMode == TranslationMode_Callback) && onSetKeyboardTranslationEnabled_callback(false)))
|
||||||
|
{
|
||||||
|
AssertISV(mPlatformWindow, "GuiCanvas::disableKeyboardTranslation - no window present!");
|
||||||
|
mPlatformWindow->setKeyboardTranslation(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiCanvas::setNativeAcceleratorsEnabled( bool enabled )
|
void GuiCanvas::setNativeAcceleratorsEnabled( bool enabled )
|
||||||
{
|
{
|
||||||
AssertISV(mPlatformWindow, "GuiCanvas::setNativeAcceleratorsEnabled - no window present!");
|
if ((mNativeAcceleratorMode == TranslationMode_Platform) ||
|
||||||
mPlatformWindow->setAcceleratorsEnabled( enabled );
|
((mNativeAcceleratorMode == TranslationMode_Callback) && onSetNativeAcceleratorsEnabled_callback(enabled)))
|
||||||
|
{
|
||||||
|
AssertISV(mPlatformWindow, "GuiCanvas::setNativeAcceleratorsEnabled - no window present!");
|
||||||
|
mPlatformWindow->setAcceleratorsEnabled(enabled);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiCanvas::setForceMouseToGUI(bool onOff)
|
void GuiCanvas::setForceMouseToGUI(bool onOff)
|
||||||
|
|
|
||||||
|
|
@ -178,6 +178,19 @@ protected:
|
||||||
bool mHoverPositionSet;
|
bool mHoverPositionSet;
|
||||||
U32 mHoverLeftControlTime;
|
U32 mHoverLeftControlTime;
|
||||||
|
|
||||||
|
public:
|
||||||
|
/// Setting for how to handle 'enableKeyboardTranslation' and 'setNativeAcceleratorsEnabled' requests.
|
||||||
|
enum KeyTranslationMode
|
||||||
|
{
|
||||||
|
TranslationMode_Platform,
|
||||||
|
TranslationMode_Callback,
|
||||||
|
TranslationMode_Ignore,
|
||||||
|
};
|
||||||
|
|
||||||
|
protected:
|
||||||
|
KeyTranslationMode mKeyTranslationMode;
|
||||||
|
KeyTranslationMode mNativeAcceleratorMode;
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
// Internal event handling callbacks for use with PlatformWindow.
|
// Internal event handling callbacks for use with PlatformWindow.
|
||||||
|
|
@ -454,6 +467,10 @@ public:
|
||||||
|
|
||||||
virtual void setWindowTitle(const char *newTitle);
|
virtual void setWindowTitle(const char *newTitle);
|
||||||
|
|
||||||
|
DECLARE_CALLBACK(bool, onSetKeyboardTranslationEnabled, (bool enable));
|
||||||
|
DECLARE_CALLBACK(bool, onSetNativeAcceleratorsEnabled, (bool enable));
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const U32 MAX_GAMEPADS = 4; ///< The maximum number of supported gamepads
|
static const U32 MAX_GAMEPADS = 4; ///< The maximum number of supported gamepads
|
||||||
protected:
|
protected:
|
||||||
|
|
@ -464,5 +481,7 @@ private:
|
||||||
void setConsumeLastInputEvent(bool flag) { mConsumeLastInputEvent = flag; }
|
void setConsumeLastInputEvent(bool flag) { mConsumeLastInputEvent = flag; }
|
||||||
bool getLastCursorPoint(Point2I& pt) const { pt = mLastCursorPt; return mLastCursorEnabled; }
|
bool getLastCursorPoint(Point2I& pt) const { pt = mLastCursorPt; return mLastCursorEnabled; }
|
||||||
};
|
};
|
||||||
|
typedef GuiCanvas::KeyTranslationMode KeyboardTranslationMode;
|
||||||
|
DefineEnumType(KeyboardTranslationMode);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue