Merge pull request #730 from Areloch/BaseUIModuleStandardizePR

Base UI module standardize pr
This commit is contained in:
Brian Roberts 2022-02-23 10:45:00 -06:00 committed by GitHub
commit 10c3188171
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
140 changed files with 2938 additions and 2505 deletions

View file

@ -186,7 +186,7 @@ void VEditorButton::onRender( Point2I offset, const RectI& updateRect )
{
RectI boundsRect( offset, getExtent() );
if ( mDepressed || mStateOn || mMouseOver )
if ( mDepressed || mStateOn || mHighlighted )
{
renderFilledBorder( boundsRect, mProfile->mBorderColorHL, mProfile->mFillColorHL );
}

View file

@ -221,7 +221,7 @@ void afxSpellButton::onRender(Point2I offset, const RectI& updateRect)
if (mActive)
{
if (mMouseOver) state = HILIGHT;
if (mHighlighted) state = HILIGHT;
if (mDepressed || mStateOn) state = DEPRESSED;
}
else

View file

@ -138,7 +138,7 @@ class GuiBitmapButtonCtrl : public GuiButtonCtrl
if( mActive )
{
if( mDepressed || mStateOn ) return DEPRESSED;
if( mMouseOver ) return HILIGHT;
if( mHighlighted ) return HILIGHT;
return NORMAL;
}
else

View file

@ -79,7 +79,7 @@ void GuiBorderButtonCtrl::onRender(Point2I offset, const RectI &updateRect)
}
}
if ( mMouseOver )
if ( mHighlighted )
{
RectI bounds( offset, getExtent() );
for ( S32 i=0; i < mProfile->mBorderThickness; i++ )

View file

@ -98,7 +98,7 @@ EndImplementEnumType;
GuiButtonBaseCtrl::GuiButtonBaseCtrl()
{
mDepressed = false;
mMouseOver = false;
mHighlighted = false;
mActive = true;
static StringTableEntry sButton = StringTable->insert( "Button" );
mButtonText = sButton;
@ -288,14 +288,14 @@ void GuiButtonBaseCtrl::onMouseEnter(const GuiEvent &event)
if(isMouseLocked())
{
mDepressed = true;
mMouseOver = true;
mHighlighted = true;
}
else
{
if ( mActive && mProfile->mSoundButtonOver )
SFX->playOnce(mProfile->mSoundButtonOver);
mMouseOver = true;
mHighlighted = true;
}
}
@ -309,7 +309,7 @@ void GuiButtonBaseCtrl::onMouseLeave(const GuiEvent &)
onMouseLeave_callback();
if( isMouseLocked() )
mDepressed = false;
mMouseOver = false;
mHighlighted = false;
}
//-----------------------------------------------------------------------------
@ -542,3 +542,17 @@ DefineEngineMethod( GuiButtonBaseCtrl, resetState, void, (),,
{
object->resetState();
}
DefineEngineMethod(GuiButtonBaseCtrl, setHighlighted, void, (bool highlighted), (false),
"Reset the mousing state of the button.\n\n"
"This method should not generally be called.")
{
object->setHighlighted(highlighted);
}
DefineEngineMethod(GuiButtonBaseCtrl, isHighlighted, bool, (),,
"Reset the mousing state of the button.\n\n"
"This method should not generally be called.")
{
return object->isHighlighted();
}

View file

@ -49,7 +49,7 @@ class GuiButtonBaseCtrl : public GuiControl
StringTableEntry mButtonText;
StringTableEntry mButtonTextID;
bool mDepressed;
bool mMouseOver;
bool mHighlighted;
bool mStateOn;
S32 mButtonType;
S32 mRadioGroup;
@ -95,7 +95,10 @@ class GuiButtonBaseCtrl : public GuiControl
bool getStateOn() const { return mStateOn; }
void setDepressed( bool depressed ) { mDepressed = depressed; }
void resetState() {mDepressed = false; mMouseOver = false;}
void resetState() {mDepressed = false; mHighlighted = false;}
void setHighlighted(bool highlighted) { mHighlighted = highlighted; }
bool isHighlighted() { return mHighlighted; }
void acceleratorKeyPress(U32 index);
void acceleratorKeyRelease(U32 index);

View file

@ -83,7 +83,7 @@ bool GuiButtonCtrl::onWake()
void GuiButtonCtrl::onRender(Point2I offset,
const RectI& updateRect)
{
bool highlight = mMouseOver;
bool highlight = mHighlighted;
bool depressed = mDepressed;
ColorI fontColor = mActive ? ( highlight ? mProfile->mFontColorHL : mProfile->mFontColor ) : mProfile->mFontColorNA;
@ -107,7 +107,7 @@ void GuiButtonCtrl::onRender(Point2I offset,
indexMultiplier = 4;
else if ( mDepressed || mStateOn )
indexMultiplier = 2;
else if ( mMouseOver )
else if ( mHighlighted )
indexMultiplier = 3;
renderSizableBitmapBordersFilled( boundsRect, indexMultiplier, mProfile );
@ -123,3 +123,4 @@ void GuiButtonCtrl::onRender(Point2I offset,
//render the children
renderChildControls( offset, updateRect);
}

View file

@ -106,7 +106,7 @@ void GuiCheckBoxCtrl::onRender(Point2I offset, const RectI &updateRect)
}
ColorI backColor = mActive ? mProfile->mFillColor : mProfile->mFillColorNA;
ColorI fontColor = mActive ? (mMouseOver ? mProfile->mFontColorHL : mProfile->mFontColor) : mProfile->mFontColorNA;
ColorI fontColor = mActive ? (mHighlighted ? mProfile->mFontColorHL : mProfile->mFontColor) : mProfile->mFontColorNA;
ColorI insideBorderColor = isFirstResponder() ? mProfile->mBorderColorHL : mProfile->mBorderColor;
// just draw the check box and the text:

View file

@ -218,7 +218,7 @@ void GuiIconButtonCtrl::onRender(Point2I offset, const RectI& updateRect)
void GuiIconButtonCtrl::renderButton( Point2I &offset, const RectI& updateRect )
{
bool highlight = mMouseOver;
bool highlight = mHighlighted;
bool depressed = mDepressed;
ColorI fontColor = mActive ? (highlight ? mProfile->mFontColorHL : mProfile->mFontColor) : mProfile->mFontColorNA;
@ -236,7 +236,7 @@ void GuiIconButtonCtrl::renderButton( Point2I &offset, const RectI& updateRect )
else
renderSlightlyLoweredBox(boundsRect, mProfile);
}
else if(mMouseOver && mActive)
else if(mHighlighted && mActive)
{
// If there is a bitmap array then render using it.
// Otherwise use a standard fill.

View file

@ -90,7 +90,7 @@ bool GuiSwatchButtonCtrl::onWake()
void GuiSwatchButtonCtrl::onRender( Point2I offset, const RectI &updateRect )
{
bool highlight = mMouseOver;
bool highlight = mHighlighted;
ColorI borderColor = mActive ? ( highlight ? mProfile->mBorderColorHL : mProfile->mBorderColor ) : mProfile->mBorderColorNA;

View file

@ -66,7 +66,7 @@ void GuiToggleButtonCtrl::onPreRender()
void GuiToggleButtonCtrl::onRender(Point2I offset,
const RectI& updateRect)
{
bool highlight = mMouseOver;
bool highlight = mHighlighted;
bool depressed = mDepressed;
ColorI fontColor = mActive ? ( highlight ? mProfile->mFontColorHL : mProfile->mFontColor ) : mProfile->mFontColorNA;
@ -89,7 +89,7 @@ void GuiToggleButtonCtrl::onRender(Point2I offset,
indexMultiplier = 4;
else if ( mDepressed || mStateOn )
indexMultiplier = 2;
else if ( mMouseOver )
else if ( mHighlighted )
indexMultiplier = 3;

View file

@ -144,7 +144,7 @@ void GuiToolboxButtonCtrl::onRender(Point2I offset, const RectI& updateRect)
RectI r(offset, getExtent());
if ( mDepressed || mStateOn )
renderStateRect( mLoweredBitmap , r );
else if ( mMouseOver )
else if ( mHighlighted )
renderStateRect( mHoverBitmap , r );
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,313 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _GuiGameSettingsCtrl_H_
#define _GuiGameSettingsCtrl_H_
#include "gui/buttons/guiButtonCtrl.h"
#include "T3D/assets/ImageAsset.h"
/// \class GuiGameSettingsCtrl
/// A base class for cross platform menu controls that are gamepad friendly.
class GuiGameSettingsCtrl : public GuiButtonCtrl
{
public:
typedef GuiButtonCtrl Parent;
enum Mode
{
Default = 0,
OptionList,
Slider,
Keybind,
Text
};
protected:
/// \struct OptionEntry
/// Display text and ID key for each entry in an option.
struct OptionEntry
{
StringTableEntry mDisplayText; ///< The text that is displayed for the option
StringTableEntry mKeyString; ///< Key value that is associated with this option
OptionEntry() : mDisplayText(StringTable->EmptyString()), mKeyString(StringTable->EmptyString()) {}
virtual ~OptionEntry() {}
};
StringTableEntry mLabel; ///< Text to display in the control as a label
StringTableEntry mScriptCallback; ///< Script callback when control is activated
StringTableEntry mTooltip; ///< A descriptive tooltip message for what the control is
Mode mMode;
//List options
Vector<OptionEntry> mOptions; ///< Collection of options available to display
S32 mSelectedOption; ///< Index into mOptions pointing at the selected option
bool mWrapOptions; ///< Determines if options should "wrap around" at the ends
//Slider option
F32 mValue; ///< When working as a slider, this contains the value
F32 mStepSize; ///< When working as a slider, this is the increment levels in the range
Point2F mRange; ///< When working as a slider, this sets our min/max range
//Keybind option
DECLARE_IMAGEASSET(GuiGameSettingsCtrl, KeybindBitmap, changeBitmap, GFXDefaultGUIProfile);
DECLARE_ASSET_SETGET(GuiGameSettingsCtrl, KeybindBitmap);
DECLARE_IMAGEASSET(GuiGameSettingsCtrl, PreviousBitmap, changeBitmap, GFXDefaultGUIProfile);
DECLARE_ASSET_SETGET(GuiGameSettingsCtrl, PreviousBitmap);
DECLARE_IMAGEASSET(GuiGameSettingsCtrl, NextBitmap, changeBitmap, GFXDefaultGUIProfile);
DECLARE_ASSET_SETGET(GuiGameSettingsCtrl, NextBitmap);
S32 mArrowSize;
S32 mColumnSplit; //Padding between the leftmost edge of the control, and the left side of the 'option'.
S32 mRightPad;
bool mEnabled;
bool mSelected;
public:
void changeBitmap() {}
/// Sets the control as selected . Only controls that are enabled can be selected.
virtual void setSelected();
/// Determines if the specified control is enabled or disabled.
///
/// \return True if the specified control is enabled. False if the control is not
/// enabled
virtual bool isEnabled() const;
/// Sets a control's enabled status according to the given parameters.
///
/// \param enabled Indicate true to enable the control or false to disable it.
virtual void setEnabled(bool enabled);
/// Gets the label displayed on the control.
///
/// \return The label for the control.
virtual StringTableEntry getLabel() const;
/// Sets the label on the control.
///
/// \param label Text to set as the label.
virtual void setLabel(const char * label);
/// Sets the control to a List setting.
///
/// \param label The text to display on the control as a label.
/// \param optionsList A tab separated list of options for the control.
/// \param wrapOptions Specify true to allow options to wrap at the ends or
/// false to prevent wrapping.
/// \param callback [optional] Name of a script function to use as a callback
/// when this control is activated. Default NULL means no callback.
/// \param enabled [optional] If this control is initially enabled. Default true.
void setListSetting(const char* label, const char* optionsList, bool wrapOptions, const char* callback,bool enabled, const char* tooltip = "", const char* defaultValue = "");
/// Sets the control to a Slider setting
///
/// \param label The text to display on the control as a label.
/// \param defaultValue A float indicating the slider's default value
/// \param increments A float indicating the incremental values the slider snaps along between it's range
/// \param range A Point2F that indicates the minimum and maximum value range
/// \param callback [optional] Name of a script function to use as a callback
/// when this control is activated. Default NULL means no callback.
/// \param enabled [optional] If this control is initially enabled. Default true.
void setSliderSetting(const char* label, F32 defaultValue, F32 increments, Point2F range, const char* callback, bool enabled, const char* tooltip = "");
/// Sets the control to a Keybind setting
///
/// \param label The text to display on the control as a label.
/// \param bitmapAssetId The assetId for the button display image
/// \param range A Point2F that indicates the minimum and maximum value range
/// \param callback [optional] Name of a script function to use as a callback
/// when this control is activated. Default NULL means no callback.
/// \param enabled [optional] If this control is initially enabled. Default true.
void setKeybindSetting(const char* label, const char* bitmapAssetId, const char* callback, bool enabled, const char* tooltip);
/// Gets the text for the currently selected option of the control.
///
/// \return A string representing the text currently displayed as the selected
/// option on the control. If there is no such displayed text then the empty
/// string is returned.
StringTableEntry getCurrentOption() const;
/// Gets the key string for the currently selected option of the control
///
/// \return The key (or id) that was assigned to the selected option on the
/// control. If there is no selected option then the empty string is returned.
StringTableEntry getCurrentOptionKey() const;
/// Gets the index into the option list for the currently selected option of the control.
///
/// \return The index of the selected option on the control. If there is no
/// selected option then -1 is returned.
S32 getCurrentOptionIndex() const;
/// Attempts to set the control to the specified selected option. The option
/// will only be set if the option exists in the control.
///
/// \param option The option to be made active.
/// \return True if the control contained the option and was set, false otherwise.
bool selectOption(const char* option);
/// Attempts to set the control to the option with the specified key. The
/// option will only be set if the key exists in the control.
///
/// \param optionKey The key string that was assigned to the option to be made active.
/// \return True if the control contained the key and the option and was set, false otherwise.
bool selectOptionByKey(const char* optionKey);
/// Attempts to set the control to the option at the specified index. The option
/// will only be set if the index is valid.
///
/// \param optionIndex The index of the option to be made active.
/// \return True if the index was valid and the option and was set, false otherwise.
bool selectOptionByIndex(S32 optionIndex);
/// Sets the list of options on the control.
///
/// \param optionsList A tab separated list of options for the control.
void setOptions(const char* optionsList);
/// Adds an option to the list of options on the control.
///
/// \param displayText The text to display for this option.
/// \param keyText The id string to associate with this value. If NULL the
/// id will be the same as the display text.
void addOption(const char* displayText, const char* keyText);
/// Activates the control. The script callback of the control will
/// be called (if it has one).
virtual void activate();
/// Gets the value
///
F32 getValue();
/// Sets the value
///
/// \param value The new value to be set.
void setValue(F32 value);
Mode getMode() { return mMode; }
/// Gets the tooltip
const char* getTooltip();
GuiGameSettingsCtrl();
~GuiGameSettingsCtrl();
void onRender(Point2I offset, const RectI &updateRect);
void onRenderListOption(Point2I currentOffset);
void onRenderSliderOption(Point2I currentOffset);
void onRenderKeybindOption(Point2I currentOffset);
/// Callback when the object is registered with the sim.
///
/// \return True if the profile was successfully added, false otherwise.
bool onAdd();
/// Callback when the control wakes up.
bool onWake();
void clear();
virtual void onMouseMove(const GuiEvent& event);
virtual void onMouseUp(const GuiEvent& event);
DECLARE_CONOBJECT(GuiGameSettingsCtrl);
DECLARE_CATEGORY( "Gui Game" );
DECLARE_DESCRIPTION( "Base class for cross platform menu controls that are gamepad friendly." );
/// Initializes fields accessible through the console.
static void initPersistFields();
static const S32 NO_OPTION = -1; ///< Indicates there is no option
protected:
/// Sets up the option
///
/// \param label The text to display on the control as a label.
/// \param callback Name of a script function to use as a callback when this
/// control is activated.
/// \param enabled [optional] If this control is initially enabled. Default true.
virtual void set(const char* label, const char* callback, bool useHighlightIcon = true, bool enabled = true, S32 mode = 0, const char* tooltip = "");
/// Sets the script variable $ThisControl to reflect this control.
virtual void setThisControl();
/// @name Callbacks
/// @{
DECLARE_CALLBACK( void, onChange, () );
DECLARE_CALLBACK(void, onInputEvent, (const char* device, const char* action, bool state));
DECLARE_CALLBACK(void, onAxisEvent, (const char* device, const char* action, F32 axisValue));
/// @}
/// Evaluates some script. If the command is empty then nothing is evaluated.
///
/// \param command The script to evaluate.
void doScriptCommand(StringTableEntry command);
StringTableEntry mCallbackOnA; ///< Script callback when the 'A' button is pressed
StringTableEntry mCallbackOnB; ///< Script callback when the 'B' button is pressed
StringTableEntry mCallbackOnX; ///< Script callback when the 'X' button is pressed
StringTableEntry mCallbackOnY; ///< Script callback when the 'Y' button is pressed
private:
/// Performs a click on the current option. The x position is used to
/// determine if the left or right arrow were clicked. If one was clicked, the
/// option will be changed. If neither was clicked, the option is unaffected.
/// This method should only be called when there is an actively selected control.
///
/// \param xPos The x position of the the click, relative to the control.
void clickOption(S32 xPos);
/// Changes the option on the currently selected control.
///
/// \param delta The amount to change the option selection by. Typically this
/// will be 1 or -1.
void changeOption(S32 delta);
/// Performs a click on the current slider control. The x position is used to
/// determine if the left or right arrow were clicked, or if it landed somewhere on the sliderbar.
/// If one was clicked, the option will be changed. If neither was clicked, the option is unaffected.
/// This method should only be called when there is an actively selected control.
///
/// \param xPos The x position of the the click, relative to the control.
void clickSlider(S32 xPos);
void clickKeybind(S32 xPos);
private:
bool mCallbackOnInputs;
bool mConsumeKeyInputEvents;
};
#endif

View file

@ -99,7 +99,7 @@ bool GuiGradientSwatchCtrl::onWake()
void GuiGradientSwatchCtrl::onRender( Point2I offset, const RectI &updateRect )
{
bool highlight = mMouseOver;
bool highlight = mHighlighted;
ColorI borderColor = mActive ? ( highlight ? mProfile->mBorderColorHL : mProfile->mBorderColor ) : mProfile->mBorderColorNA;
RectI renderRect( offset, getExtent() );
@ -632,4 +632,4 @@ DefineEngineMethod(GuiGradientCtrl, getColor, LinearColorF, (S32 idx), , "Get co
}
return LinearColorF::ONE;
}
}

View file

@ -706,6 +706,9 @@ bool GuiCanvas::processInputEvent(InputEventInfo &inputEvent)
if (mCursorEnabled || mForceMouseToGUI ||
(mAlwaysHandleMouseButtons && inputEvent.objType == SI_BUTTON) )
{
if (inputEvent.objType != SI_AXIS && inputEvent.action == SI_MAKE)
bool asdfasdf = true;
return processMouseEvent(inputEvent);
}
break;

View file

@ -61,7 +61,8 @@ ConsoleDocClass( GuiInputCtrl,
GuiInputCtrl::GuiInputCtrl()
: mSendAxisEvents(false),
mSendBreakEvents(false),
mSendModifierEvents(false)
mSendModifierEvents(false),
mIgnoreMouseEvents(false)
{
}
@ -76,6 +77,8 @@ void GuiInputCtrl::initPersistFields()
"If true, break events for all devices will generate callbacks (Default false).");
addField("sendModifierEvents", TypeBool, Offset(mSendModifierEvents, GuiInputCtrl),
"If true, Make events will be sent for modifier keys (Default false).");
addField("ignoreMouseEvents", TypeBool, Offset(mIgnoreMouseEvents, GuiInputCtrl),
"If true, any events from mouse devices will be passed through.");
endGroup("GuiInputCtrl");
Parent::initPersistFields();
@ -97,7 +100,7 @@ bool GuiInputCtrl::onWake()
if ( !Parent::onWake() )
return( false );
if( !smDesignTime )
if( !smDesignTime && !mIgnoreMouseEvents)
mouseLock();
setFirstResponder();
@ -151,6 +154,9 @@ IMPLEMENT_CALLBACK(GuiInputCtrl, onAxisEvent, void, (const char* device, const c
//------------------------------------------------------------------------------
bool GuiInputCtrl::onInputEvent( const InputEventInfo &event )
{
if (mIgnoreMouseEvents && event.deviceType == MouseDeviceType)
return false;
char deviceString[32];
if ( event.action == SI_MAKE )
{

View file

@ -36,6 +36,7 @@ protected:
bool mSendAxisEvents;
bool mSendBreakEvents;
bool mSendModifierEvents;
bool mIgnoreMouseEvents;
public: