Merge branch 'development' into imageAsset_refactor_rev3

This commit is contained in:
marauder2k7 2025-03-24 20:07:06 +00:00 committed by GitHub
commit 0da0903599
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4189 changed files with 29881 additions and 635347 deletions

View file

@ -175,16 +175,16 @@ void GuiTSCtrl::initPersistFields()
docsURL;
addGroup( "Camera" );
addField("cameraZRot", TypeF32, Offset(mCameraZRot, GuiTSCtrl),
addFieldV("cameraZRot", TypeRangedF32, Offset(mCameraZRot, GuiTSCtrl), &CommonValidators::DegreeRange,
"Z rotation angle of camera." );
addField("forceFOV", TypeF32, Offset(mForceFOV, GuiTSCtrl),
addFieldV("forceFOV", TypeRangedF32, Offset(mForceFOV, GuiTSCtrl), &CommonValidators::PosDegreeRange,
"The vertical field of view in degrees or zero to use the normal camera FOV." );
endGroup( "Camera" );
addGroup( "Rendering" );
addField( "reflectPriority", TypeF32, Offset( mReflectPriority, GuiTSCtrl ),
addFieldV( "reflectPriority", TypeRangedF32, Offset( mReflectPriority, GuiTSCtrl ), &CommonValidators::PositiveFloat,
"The share of the per-frame reflection update work this control's rendering should run.\n"
"The reflect update priorities of all visible GuiTSCtrls are added together and each control is assigned "
"a share of the per-frame reflection update time according to its percentage of the total priority value." );

View file

@ -134,9 +134,9 @@ void GuiIconButtonCtrl::initPersistFields()
addField( "makeIconSquare", TypeBool, Offset( mMakeIconSquare, GuiIconButtonCtrl ),"If true, will make sure the icon is square.\n");
addField( "textLocation", TYPEID< TextLocation >(), Offset( mTextLocation, GuiIconButtonCtrl ),"Where to place the text on the control.\n"
"Options are 0 (None), 1 (Bottom), 2 (Right), 3 (Top), 4 (Left), 5 (Center).\n");
addField( "textMargin", TypeS32, Offset( mTextMargin, GuiIconButtonCtrl ),"Margin between the icon and the text.\n");
addFieldV( "textMargin", TypeRangedS32, Offset( mTextMargin, GuiIconButtonCtrl ),&CommonValidators::PositiveInt,"Margin between the icon and the text.\n");
addField( "autoSize", TypeBool, Offset( mAutoSize, GuiIconButtonCtrl ),"If true, the text and icon will be automatically sized to the size of the control.\n");
addField( "bitmapMargin", TypeS32, Offset( mBitmapMargin, GuiIconButtonCtrl), "Margin between the icon and the border.\n");
addFieldV( "bitmapMargin", TypeRangedS32, Offset( mBitmapMargin, GuiIconButtonCtrl), &CommonValidators::PositiveInt, "Margin between the icon and the border.\n");
Parent::initPersistFields();
}

View file

@ -112,14 +112,14 @@ void GuiAutoScrollCtrl::initPersistFields()
addField( "scrollDirection", TYPEID< Direction >(), Offset( mDirection, GuiAutoScrollCtrl ),
"Direction in which the child control is moved." );
addField( "startDelay", TypeF32, Offset( mStartDelay, GuiAutoScrollCtrl ),
addFieldV( "startDelay", TypeRangedF32, Offset( mStartDelay, GuiAutoScrollCtrl ), &CommonValidators::PositiveFloat,
"Seconds to wait before starting to scroll." );
addField( "resetDelay", TypeF32, Offset( mResetDelay, GuiAutoScrollCtrl ),
addFieldV( "resetDelay", TypeRangedF32, Offset( mResetDelay, GuiAutoScrollCtrl ), &CommonValidators::PositiveFloat,
"Seconds to wait after scrolling completes before resetting and starting over.\n\n"
"@note Only takes effect if #isLooping is true." );
addField( "childBorder", TypeS32, Offset( mChildBorder, GuiAutoScrollCtrl ),
addFieldV( "childBorder", TypeRangedS32, Offset( mChildBorder, GuiAutoScrollCtrl ), &CommonValidators::PositiveInt,
"Padding to put around child control (in pixels)." );
addField( "scrollSpeed", TypeF32, Offset( mScrollSpeed, GuiAutoScrollCtrl ),
addFieldV( "scrollSpeed", TypeRangedF32, Offset( mScrollSpeed, GuiAutoScrollCtrl ), &CommonValidators::PositiveFloat,
"Scrolling speed in pixels per second." );
addField( "isLooping", TypeBool, Offset( mIsLooping, GuiAutoScrollCtrl ),
"If true, the scrolling will reset to the beginning once completing a cycle." );

View file

@ -56,15 +56,15 @@ void GuiControlArrayControl::initPersistFields()
docsURL;
addGroup( "Array" );
addField( "colCount", TypeS32, Offset(mCols, GuiControlArrayControl),
addFieldV( "colCount", TypeRangedS32, Offset(mCols, GuiControlArrayControl), &CommonValidators::PositiveInt,
"Number of colums in the array." );
addField( "colSizes", TypeS32Vector, Offset(mColumnSizes, GuiControlArrayControl),
"Size of each individual column." );
addField( "rowSize", TypeS32, Offset(mRowSize, GuiControlArrayControl),
addFieldV( "rowSize", TypeRangedS32, Offset(mRowSize, GuiControlArrayControl), &CommonValidators::PositiveInt,
"Heigth of a row in the array." );
addField( "rowSpacing", TypeS32, Offset(mRowSpacing, GuiControlArrayControl),
addFieldV( "rowSpacing", TypeRangedS32, Offset(mRowSpacing, GuiControlArrayControl), &CommonValidators::PositiveInt,
"Padding to put between rows." );
addField( "colSpacing", TypeS32, Offset(mColSpacing, GuiControlArrayControl),
addFieldV( "colSpacing", TypeRangedS32, Offset(mColSpacing, GuiControlArrayControl), &CommonValidators::PositiveInt,
"Padding to put between columns." );
endGroup( "Array" );

View file

@ -215,6 +215,9 @@ void GuiDragAndDropControl::onMouseDragged( const GuiEvent& event )
// Allow the control under the drag to react to a potential drop
GuiControl* enterTarget = findDragTarget( event.mousePoint, "onControlDragEnter" );
if(enterTarget != nullptr)
Con::printf("GuiDragAndDropControl::onMouseDragged() - enterTarget: %d", enterTarget->getId());
if( mLastTarget != enterTarget )
{
if( mLastTarget )

View file

@ -98,28 +98,28 @@ ConsoleDocClass( GuiDynamicCtrlArrayControl,
void GuiDynamicCtrlArrayControl::initPersistFields()
{
docsURL;
addField( "colCount", TypeS32, Offset( mCols, GuiDynamicCtrlArrayControl ),
addFieldV( "colCount", TypeRangedS32, Offset( mCols, GuiDynamicCtrlArrayControl ), &CommonValidators::PositiveInt,
"Number of columns the child controls have been arranged into. This "
"value is calculated automatically when children are added, removed or "
"resized; writing it directly has no effect." );
addField( "colSize", TypeS32, Offset( mColSize, GuiDynamicCtrlArrayControl ),
addFieldV( "colSize", TypeRangedS32, Offset( mColSize, GuiDynamicCtrlArrayControl ), &CommonValidators::PositiveInt,
"Width of each column. If <i>autoCellSize</i> is set, this will be "
"calculated automatically from the widest child control" );
addField( "rowCount", TypeS32, Offset( mRows, GuiDynamicCtrlArrayControl ),
addFieldV( "rowCount", TypeRangedS32, Offset( mRows, GuiDynamicCtrlArrayControl ), &CommonValidators::PositiveInt,
"Number of rows the child controls have been arranged into. This value "
"is calculated automatically when children are added, removed or resized; "
"writing it directly has no effect." );
addField( "rowSize", TypeS32, Offset( mRowSize, GuiDynamicCtrlArrayControl ),
addFieldV( "rowSize", TypeRangedS32, Offset( mRowSize, GuiDynamicCtrlArrayControl ), &CommonValidators::PositiveInt,
"Height of each row. If <i>autoCellSize</i> is set, this will be "
"calculated automatically from the tallest child control" );
addField( "rowSpacing", TypeS32, Offset( mRowSpacing, GuiDynamicCtrlArrayControl ),
addFieldV( "rowSpacing", TypeRangedS32, Offset( mRowSpacing, GuiDynamicCtrlArrayControl ), &CommonValidators::PositiveInt,
"Spacing between rows" );
addField( "colSpacing", TypeS32, Offset( mColSpacing, GuiDynamicCtrlArrayControl ),
addFieldV( "colSpacing", TypeRangedS32, Offset( mColSpacing, GuiDynamicCtrlArrayControl ), &CommonValidators::PositiveInt,
"Spacing between columns" );
addField( "frozen", TypeBool, Offset( mFrozen, GuiDynamicCtrlArrayControl ),

View file

@ -92,7 +92,7 @@ void GuiFrameSetCtrl::initPersistFields()
addField( "rows", TypeS32Vector, Offset(mRowOffsets, GuiFrameSetCtrl),
"A vector of row offsets (determines the height of each row)." );
addField( "borderWidth", TypeS32, Offset(mFramesetDetails.mBorderWidth, GuiFrameSetCtrl),
addFieldV( "borderWidth", TypeRangedS32, Offset(mFramesetDetails.mBorderWidth, GuiFrameSetCtrl), &CommonValidators::PositiveInt,
"Width of interior borders between cells in pixels." );
addField( "borderColor", TypeColorI, Offset(mFramesetDetails.mBorderColor, GuiFrameSetCtrl),
@ -111,7 +111,7 @@ void GuiFrameSetCtrl::initPersistFields()
"If true, row and column offsets are automatically scaled to match the "
"new extents when the control is resized." );
addField( "fudgeFactor", TypeS32, Offset(mFudgeFactor, GuiFrameSetCtrl),
addFieldV( "fudgeFactor", TypeRangedS32, Offset(mFudgeFactor, GuiFrameSetCtrl), &CommonValidators::PositiveInt,
"Offset for row and column dividers in pixels" );
Parent::initPersistFields();

View file

@ -99,7 +99,7 @@ void GuiRolloutCtrl::initPersistFields()
"Text label to display on the rollout header." );
addField( "margin", TypeRectI, Offset( mMargin, GuiRolloutCtrl ),
"Margin to put around child control." );
addField( "defaultHeight", TypeS32, Offset( mDefaultHeight, GuiRolloutCtrl ),
addFieldV( "defaultHeight", TypeRangedS32, Offset( mDefaultHeight, GuiRolloutCtrl ), &CommonValidators::PositiveInt,
"Default height of the client area. This is used when no child control has been added to the rollout." );
addProtectedField( "expanded", TypeBool, Offset( mIsExpanded, GuiRolloutCtrl), &setExpanded, &defaultProtectedGetFn,
"The current rollout expansion state." );

View file

@ -111,7 +111,7 @@ void GuiScrollCtrl::initPersistFields()
addField( "constantThumbHeight", TypeBool, Offset(mUseConstantHeightThumb, GuiScrollCtrl));
addField( "childMargin", TypePoint2I, Offset(mChildMargin, GuiScrollCtrl),
"Padding region to put around child contents." );
addField( "mouseWheelScrollSpeed", TypeS32, Offset(mScrollAnimSpeed, GuiScrollCtrl),
addFieldV( "mouseWheelScrollSpeed", TypeRangedS32, Offset(mScrollAnimSpeed, GuiScrollCtrl), &CommonValidators::NegDefaultInt,
"Pixels/Tick - if not positive then mousewheel scrolling occurs instantly (like other scrolling).");
endGroup( "Scrolling" );

View file

@ -118,14 +118,14 @@ void GuiSplitContainer::initPersistFields()
addField( "orientation", TYPEID< Orientation >(), Offset( mOrientation, GuiSplitContainer),
"Whether to split between top and bottom (horizontal) or between left and right (vertical)." );
addField( "splitterSize", TypeS32, Offset( mSplitterSize, GuiSplitContainer),
addFieldV( "splitterSize", TypeRangedS32, Offset( mSplitterSize, GuiSplitContainer), &CommonValidators::PositiveInt,
"Width of the splitter bar between the two sides. Default is 2." );
addField( "splitPoint", TypePoint2I, Offset( mSplitPoint, GuiSplitContainer),
"Point on control through which the splitter goes.\n\n"
"Changed relatively if size of control changes." );
addField( "fixedPanel", TYPEID< FixedPanel >(), Offset( mFixedPanel, GuiSplitContainer),
"Which (if any) side of the splitter to keep at a fixed size." );
addField( "fixedSize", TypeS32, Offset( mFixedPanelSize, GuiSplitContainer),
addFieldV( "fixedSize", TypeRangedS32, Offset( mFixedPanelSize, GuiSplitContainer), &CommonValidators::PositiveInt,
"Width of the fixed panel specified by #fixedPanel (if any)." );
endGroup( "Splitter" );

View file

@ -110,4 +110,4 @@ DefineEnumType( GuiSplitFixedPanel );
/// @}
#endif // _GUI_SPLTCONTAINER_H_
#endif // _GUI_SPLTCONTAINER_H_

View file

@ -110,7 +110,7 @@ void GuiStackControl::initPersistFields()
"Controls the type of vertical stacking to use (<i>Top to Bottom</i> or "
"<i>Bottom to Top</i>)" );
addField( "padding", TypeS32, Offset(mPadding, GuiStackControl),
addFieldV( "padding", TypeRangedS32, Offset(mPadding, GuiStackControl), &CommonValidators::PositiveInt,
"Distance (in pixels) between stacked child controls." );
addField( "dynamicSize", TypeBool, Offset(mDynamicSize, GuiStackControl),

View file

@ -27,6 +27,7 @@
#include "gui/controls/guiPopUpCtrl.h"
#include "gui/core/guiDefaultControlRender.h"
#include "gfx/gfxDrawUtil.h"
#include "console/typeValidators.h"
IMPLEMENT_CONOBJECT( GuiTabBookCtrl );
@ -107,19 +108,19 @@ void GuiTabBookCtrl::initPersistFields()
addField( "tabPosition", TYPEID< TabPosition >(), Offset( mTabPosition, GuiTabBookCtrl ),
"Where to place the tab page headers." );
addField( "tabMargin", TypeS32, Offset( mTabMargin, GuiTabBookCtrl ),
addFieldV( "tabMargin", TypeRangedS32, Offset( mTabMargin, GuiTabBookCtrl ), &CommonValidators::PositiveInt,
"Spacing to put between individual tab page headers." );
addField( "minTabWidth", TypeS32, Offset( mMinTabWidth, GuiTabBookCtrl ),
addFieldV( "minTabWidth", TypeRangedS32, Offset( mMinTabWidth, GuiTabBookCtrl ), &CommonValidators::PositiveInt,
"Minimum width allocated to a tab page header." );
addField( "tabHeight", TypeS32, Offset( mTabHeight, GuiTabBookCtrl ),
addFieldV( "tabHeight", TypeRangedS32, Offset( mTabHeight, GuiTabBookCtrl ), &CommonValidators::PositiveInt,
"Height of tab page headers." );
addField( "allowReorder", TypeBool, Offset( mAllowReorder, GuiTabBookCtrl ),
"Whether reordering tabs with the mouse is allowed." );
addField( "defaultPage", TypeS32, Offset( mDefaultPageNum, GuiTabBookCtrl ),
addFieldV( "defaultPage", TypeRangedS32, Offset( mDefaultPageNum, GuiTabBookCtrl ), &CommonValidators::NegDefaultInt,
"Index of page to select on first onWake() call (-1 to disable)." );
addProtectedField( "selectedPage", TypeS32, Offset( mSelectedPageNum, GuiTabBookCtrl ),
&_setSelectedPage, &defaultProtectedGetFn,
addProtectedFieldV( "selectedPage", TypeRangedS32, Offset( mSelectedPageNum, GuiTabBookCtrl ),
&_setSelectedPage, &defaultProtectedGetFn, &CommonValidators::PositiveInt,
"Index of currently selected page." );
addField( "frontTabPadding", TypeS32, Offset( mFrontTabPadding, GuiTabBookCtrl ),
@ -320,6 +321,15 @@ bool GuiTabBookCtrl::resize(const Point2I &newPosition, const Point2I &newExtent
bool result = Parent::resize( newPosition, newExtent );
calculatePageTabs();
for (S32 i = 0; i < mPages.size(); i++)
{
const TabHeaderInfo& info = mPages[i];
GuiTabPageCtrl* page = info.Page;
if(page->getFitBook())
fitPage(page);
}
return result;
}
@ -430,6 +440,18 @@ void GuiTabBookCtrl::onMouseMove(const GuiEvent &event)
void GuiTabBookCtrl::onMouseLeave( const GuiEvent &event )
{
Parent::onMouseLeave( event );
if(mDraggingTab)
{
//we dragged the tab out, so do something about that
GuiTabPageCtrl* selectedPage = NULL;
if (mSelectedPageNum != -1)
selectedPage = mPages[mSelectedPageNum].Page;
mDraggingTab = false;
Con::executef(this, "onTabDraggedOut", selectedPage->getIdString());
}
mHoverTab = NULL;
}

View file

@ -143,7 +143,7 @@ void GuiWindowCtrl::initPersistFields()
"Whether the window can be resized horizontally." );
addField( "resizeHeight", TypeBool, Offset( mResizeHeight, GuiWindowCtrl ),
"Whether the window can be resized vertically." );
addField("resizeMargin", TypeF32, Offset(mResizeMargin, GuiWindowCtrl),
addFieldV("resizeMargin", TypeRangedF32, Offset(mResizeMargin, GuiWindowCtrl), &CommonValidators::PositiveFloat,
"Margin along the window edge to allow grabbing.");
addField( "canMove", TypeBool, Offset( mCanMove, GuiWindowCtrl ),
"Whether the window can be moved by dragging its titlebar." );

View file

@ -28,6 +28,7 @@
#include "console/engineAPI.h"
#include "gfx/gfxDevice.h"
#include "gfx/gfxDrawUtil.h"
#include "console/typeValidators.h"
@ -89,7 +90,7 @@ void guiAnimBitmapCtrl::initPersistFields()
addField("reverse", TypeBool, Offset(mReverse, guiAnimBitmapCtrl), "play reversed?");
addField("fps", TypeS32, Offset(mFramesPerSec, guiAnimBitmapCtrl), "Frame Rate");
addProtectedField("curFrame", TypeS32, Offset(mCurFrameIndex, guiAnimBitmapCtrl), &ptSetFrame, &defaultProtectedGetFn, "Index of currently Displaying Frame ");
addProtectedFieldV("curFrame", TypeRangedS32, Offset(mCurFrameIndex, guiAnimBitmapCtrl), &ptSetFrame, &defaultProtectedGetFn, &CommonValidators::S32Range, "Index of currently Displaying Frame ");
Parent::initPersistFields();
removeField("wrap");
@ -126,16 +127,21 @@ bool guiAnimBitmapCtrl::ptSetFrame(void *object, const char *index, const char *
S32 val = dAtoi(data);
if (val < 0)
if ((val < 0) || (val >pData->mNumFrames))
{
pData->mCurFrameIndex = pData->mNumFrames;
if (pData->mLoop)
{
int len = pData->mNumFrames;
val = (val >= 0 ? val % len : -val % len ? len - (-val % len) : 0);
}
else
{
if (val < 0) val = 0;
if (val >pData->mNumFrames) val = pData->mNumFrames;
}
pData->mCurFrameIndex = val;
return false;
}
else if (val > pData->mNumFrames)
{
pData->mCurFrameIndex = 0;
return false;
};
pData->mCurFrameIndex = val;
return true;

View file

@ -44,7 +44,7 @@ GuiBitmapBarCtrl::GuiBitmapBarCtrl(void)
void GuiBitmapBarCtrl::initPersistFields()
{
docsURL;
addField("percent", TypeF32, Offset(mPercent, GuiBitmapBarCtrl),
addFieldV("percent", TypeRangedF32, Offset(mPercent, GuiBitmapBarCtrl), &CommonValidators::NormalizedFloat,
"% shown");
addField("vertical", TypeBool, Offset(mVertical, GuiBitmapBarCtrl),
"If true, the bitmap is clipped vertically.");

View file

@ -73,12 +73,9 @@ void GuiBitmapCtrl::initPersistFields()
INITPERSISTFIELD_IMAGEASSET_REFACTOR(Bitmap, GuiBitmapCtrl, "The bitmap to render in this BitmapCtrl.")
addField("color", TypeColorI, Offset(mColor, GuiBitmapCtrl), "color mul");
addField("wrap", TypeBool, Offset(mWrap, GuiBitmapCtrl),
"If true, the bitmap is tiled inside the control rather than stretched to fit.");
addField("angle", TypeF32, Offset(mAngle, GuiBitmapCtrl), "rotation");
endGroup("Bitmap");
addField("wrap", TypeBool, Offset(mWrap, GuiBitmapCtrl), "If true, the bitmap is tiled inside the control rather than stretched to fit.");
addFieldV("angle", TypeRangedF32, Offset(mAngle, GuiBitmapCtrl), &CommonValidators::DegreeRange, "rotation");
endGroup( "Bitmap" );
Parent::initPersistFields();
}

View file

@ -29,6 +29,9 @@
#include "gui/controls/guiColorPicker.h"
#include "gfx/primBuilder.h"
#include "gfx/gfxDrawUtil.h"
#include "console/typeValidators.h"
#include "postFx/postEffectManager.h"
#include "gfx/screenshot.h"
IMPLEMENT_CONOBJECT(GuiColorPickerCtrl);
@ -47,15 +50,23 @@ GuiColorPickerCtrl::GuiColorPickerCtrl()
mActive = true;
mSelectorGap = 1;
mActionOnMove = false;
mDropperActive = false;
mShowReticle = true;
mSelectedHue = 0;
mSelectedAlpha = 255;
mSelectedSaturation = 100;
mSelectedBrightness = 100;
eyeDropperPos = Point2I::Zero;
eyeDropperCap = NULL;
}
GuiColorPickerCtrl::~GuiColorPickerCtrl()
{
if (eyeDropperCap != NULL)
{
delete eyeDropperCap;
eyeDropperCap = NULL;
}
}
ImplementEnumType( GuiColorPickMode,
@ -81,7 +92,7 @@ void GuiColorPickerCtrl::initPersistFields()
{
docsURL;
addGroup("ColorPicker");
addField("selectorGap", TypeS32, Offset(mSelectorGap, GuiColorPickerCtrl));
addFieldV("selectorGap", TypeRangedS32, Offset(mSelectorGap, GuiColorPickerCtrl),&CommonValidators::NaturalNumber);
addField("displayMode", TYPEID< PickMode >(), Offset(mDisplayMode, GuiColorPickerCtrl) );
addField("selectorMode", TYPEID< SelectorMode >(), Offset(mSelectorMode, GuiColorPickerCtrl) );
addField("actionOnMove", TypeBool,Offset(mActionOnMove, GuiColorPickerCtrl));
@ -94,7 +105,7 @@ void GuiColorPickerCtrl::initPersistFields()
void GuiColorPickerCtrl::renderBlendRange(RectI& bounds)
{
ColorI currentColor;
currentColor.set(ColorI::Hsb(mSelectedHue, 100, 100));
currentColor.set(Hsb(mSelectedHue, 100, 100));
GFX->getDrawUtil()->drawRectFill(bounds, currentColor, 0.0f, ColorI(0,0,0,0), true);
}
@ -114,7 +125,7 @@ void GuiColorPickerCtrl::renderBlendSelector(RectI& bounds)
selectorRect.set(Point2I(selectorPos.x - mSelectorGap, selectorPos.y - mSelectorGap), Point2I(mSelectorGap * 2, mSelectorGap * 2));
ColorI currentColor;
currentColor.set(ColorI::Hsb(mSelectedHue, mSelectedSaturation, mSelectedBrightness));
currentColor.set(Hsb(mSelectedHue, mSelectedSaturation, mSelectedBrightness));
GFX->getDrawUtil()->drawRectFill(selectorRect, currentColor, 2.0f, ColorI::WHITE);
}
@ -136,8 +147,8 @@ void GuiColorPickerCtrl::renderHueGradient(RectI& bounds, U32 numColours)
U32 nextHue = static_cast<U32>((F32(i + 1) / F32(numColours)) * 360.0f);
ColorI currentColor, nextColor;
currentColor.set(ColorI::Hsb(currentHue, 100, 100));
nextColor.set(ColorI::Hsb(nextHue, 100, 100));
currentColor.set(Hsb(currentHue, 100, 100));
nextColor.set(Hsb(nextHue, 100, 100));
switch (mSelectorMode)
{
@ -217,7 +228,7 @@ void GuiColorPickerCtrl::renderHueSelector(RectI& bounds)
}
ColorI currentColor;
currentColor.set(ColorI::Hsb(mSelectedHue, 100, 100));
currentColor.set(Hsb(mSelectedHue, 100, 100));
GFX->getDrawUtil()->drawRectFill(selectorRect, currentColor, 2.0f, ColorI::WHITE);
}
@ -232,7 +243,7 @@ void GuiColorPickerCtrl::renderAlphaGradient(RectI& bounds)
S32 b = bounds.point.y + bounds.extent.y;
ColorI currentColor;
currentColor.set(ColorI::Hsb(mSelectedHue, 100, 100));
currentColor.set(Hsb(mSelectedHue, 100, 100));
ColorI alphaCol = ColorI::BLACK;
alphaCol.alpha = 0;
@ -308,12 +319,38 @@ void GuiColorPickerCtrl::renderAlphaSelector(RectI& bounds)
}
ColorI currentColor;
currentColor.set(ColorI::Hsb(mSelectedHue, 100, 100));
currentColor.set(Hsb(mSelectedHue, 100, 100));
currentColor.alpha = mSelectedAlpha;
GFX->getDrawUtil()->drawRectFill(selectorRect, currentColor, 2.0f, ColorI::WHITE);
}
void GuiColorPickerCtrl::renderEyeDropper()
{
if (eyeDropperCap != NULL)
{
GFX->getDrawUtil()->drawBitmap(eyeHandle, getRoot()->getPosition());
Point2I resolution = getRoot()->getExtent();
Point2I magnifierSize(100, 100);
Point2I magnifierPosition = eyeDropperPos + Point2I(20, 20);
// Adjust position to ensure magnifier stays on screen
if (magnifierPosition.x + magnifierSize.x > resolution.x)
magnifierPosition.x = eyeDropperPos.x - magnifierSize.x - 20;
if (magnifierPosition.y + magnifierSize.y > resolution.y)
magnifierPosition.y = eyeDropperPos.y - magnifierSize.y - 20;
RectI magnifierBounds(magnifierPosition, magnifierSize);
ColorI currentColor;
currentColor.set(Hsb(mSelectedHue, mSelectedSaturation, mSelectedBrightness));
currentColor.alpha = mSelectedAlpha;
GFX->getDrawUtil()->drawRectFill(magnifierBounds, currentColor, 2.0f, ColorI::BLACK);
}
}
void GuiColorPickerCtrl::onRender(Point2I offset, const RectI& updateRect)
{
if (mStateBlock.isNull())
@ -333,7 +370,7 @@ void GuiColorPickerCtrl::onRender(Point2I offset, const RectI& updateRect)
case GuiColorPickerCtrl::pPalette:
{
ColorI currentColor;
currentColor.set(ColorI::Hsb(mSelectedHue, mSelectedSaturation, mSelectedBrightness));
currentColor.set(Hsb(mSelectedHue, mSelectedSaturation, mSelectedBrightness));
currentColor.alpha = mSelectedAlpha;
GFX->getDrawUtil()->drawRectFill(boundsRect, currentColor);
break;
@ -356,6 +393,15 @@ void GuiColorPickerCtrl::onRender(Point2I offset, const RectI& updateRect)
if (mShowReticle) renderAlphaSelector(boundsRect);
break;
}
case GuiColorPickerCtrl::pDropperBackground:
{
if (mDropperActive)
{
// Render the magnified view of our currently selected color.
renderEyeDropper();
}
break;
}
default:
break;
}
@ -364,72 +410,31 @@ void GuiColorPickerCtrl::onRender(Point2I offset, const RectI& updateRect)
renderChildControls(offset, updateRect);
}
Point2I GuiColorPickerCtrl::findColor(const LinearColorF & color, const Point2I& offset, const Point2I& resolution, GBitmap& bmp)
{
Point2I ext = getExtent();
Point2I closestPos(-1, -1);
/* Debugging
char filename[256];
dSprintf( filename, 256, "%s.%s", "colorPickerTest", "png" );
// Open up the file on disk.
FileStream fs;
if ( !fs.open( filename, Torque::FS::File::Write ) )
Con::errorf( "GuiObjectView::saveAsImage() - Failed to open output file '%s'!", filename );
else
{
// Write it and close.
bmp.writeBitmap( "png", fs );
fs.close();
}
*/
ColorI tmp;
U32 buf_x;
U32 buf_y;
LinearColorF curColor;
F32 val(10000.0f);
F32 closestVal(10000.0f);
bool closestSet = false;
for (S32 x = 0; x < ext.x; x++)
{
for (S32 y = 0; y < ext.y; y++)
{
buf_x = offset.x + x;
buf_y = (resolution.y - (offset.y + y));
buf_y = resolution.y - buf_y;
//Get the color at that position
bmp.getColor(buf_x, buf_y, tmp);
curColor = (LinearColorF)tmp;
//Evaluate how close the color is to our desired color
val = mFabs(color.red - curColor.red) + mFabs(color.green - curColor.green) + mFabs(color.blue - curColor.blue);
if (!closestSet)
{
closestVal = val;
closestPos.set(x, y);
closestSet = true;
}
else if (val < closestVal)
{
closestVal = val;
closestPos.set(x, y);
}
}
}
return closestPos;
}
void GuiColorPickerCtrl::onMouseDown(const GuiEvent &event)
{
if (!mActive)
return;
// we need to do this first.
if (mDisplayMode == GuiColorPickerCtrl::pDropperBackground) {
if (mDropperActive)
{
mDropperActive = false;
//getRoot()->pushObjectToBack(this);
onAction();
mouseUnlock();
if (eyeDropperCap != NULL)
{
delete eyeDropperCap;
eyeDropperCap = NULL;
}
}
return;
}
mouseLock(this);
@ -510,14 +515,15 @@ void GuiColorPickerCtrl::onMouseDragged(const GuiEvent &event)
Point2I ext = getExtent();
Point2I mousePoint = globalToLocalCoord(event.mousePoint);
F32 relX = mClampF(F32(mousePoint.x) / F32(ext.x), 0.0, 1.0);
F32 relY = mClampF(F32(mousePoint.y) / F32(ext.y), 0.0, 1.0);
switch (mDisplayMode)
{
case GuiColorPickerCtrl::pPalette:
return;
case GuiColorPickerCtrl::pBlendRange:
{
F32 relX = F32(mousePoint.x) / F32(ext.x);
F32 relY = 1.0f - F32(mousePoint.y) / F32(ext.y);
relY = 1.0f - relY;
setSelectedSaturation(relX * 100.0);
setSelectedBrightness(relY * 100.0);
break;
@ -528,13 +534,11 @@ void GuiColorPickerCtrl::onMouseDragged(const GuiEvent &event)
{
case GuiColorPickerCtrl::sHorizontal:
{
F32 relX = F32(mousePoint.x) / F32(ext.x);
setSelectedHue(relX * 360.0);
break;
}
case GuiColorPickerCtrl::sVertical:
{
F32 relY = F32(mousePoint.y) / F32(ext.y);
setSelectedHue(relY * 360.0);
break;
}
@ -549,13 +553,11 @@ void GuiColorPickerCtrl::onMouseDragged(const GuiEvent &event)
{
case GuiColorPickerCtrl::sHorizontal:
{
F32 relX = F32(mousePoint.x) / F32(ext.x);
setSelectedAlpha(relX * 255.0);
break;
}
case GuiColorPickerCtrl::sVertical:
{
F32 relY = F32(mousePoint.y) / F32(ext.y);
setSelectedAlpha(relY * 255.0);
break;
}
@ -574,6 +576,29 @@ void GuiColorPickerCtrl::onMouseDragged(const GuiEvent &event)
void GuiColorPickerCtrl::onMouseMove(const GuiEvent &event)
{
if (mDisplayMode != pDropperBackground)
return;
if (!mDropperActive)
return;
// should not need globalToLocal as we are capturing the whole screen.
eyeDropperPos = globalToLocalCoord(event.mousePoint);
if (eyeDropperCap != NULL)
{
// Sample the pixel color at the mouse position. Mouse position should translate directly.
ColorI sampledColor;
eyeDropperCap->getColor(eyeDropperPos.x, eyeDropperPos.y, sampledColor);
// Convert the sampled color to HSB
Hsb hsb = sampledColor.getHSB();
mSelectedHue = hsb.hue;
mSelectedSaturation = hsb.sat;
mSelectedBrightness = hsb.brightness;
mSelectedAlpha = sampledColor.alpha;
}
}
void GuiColorPickerCtrl::onMouseEnter(const GuiEvent &event)
@ -587,7 +612,16 @@ void GuiColorPickerCtrl::onMouseLeave(const GuiEvent &)
mMouseOver = false;
}
void GuiColorPickerCtrl::setSelectedHue(const F64& hueValue)
void GuiColorPickerCtrl::onMouseUp(const GuiEvent&)
{
//if we released the mouse within this control, perform the action
if (mActive && mMouseDown)
mMouseDown = false;
mouseUnlock();
}
void GuiColorPickerCtrl::setSelectedHue(const U32& hueValue)
{
if (hueValue < 0)
{
@ -605,7 +639,7 @@ void GuiColorPickerCtrl::setSelectedHue(const F64& hueValue)
}
void GuiColorPickerCtrl::setSelectedBrightness(const F64& brightValue)
void GuiColorPickerCtrl::setSelectedBrightness(const U32& brightValue)
{
if (brightValue < 0)
{
@ -622,7 +656,7 @@ void GuiColorPickerCtrl::setSelectedBrightness(const F64& brightValue)
mSelectedBrightness = brightValue;
}
void GuiColorPickerCtrl::setSelectedSaturation(const F64& satValue)
void GuiColorPickerCtrl::setSelectedSaturation(const U32& satValue)
{
if (satValue < 0)
{
@ -639,7 +673,7 @@ void GuiColorPickerCtrl::setSelectedSaturation(const F64& satValue)
mSelectedSaturation = satValue;
}
void GuiColorPickerCtrl::setSelectedAlpha(const F64& alphaValue)
void GuiColorPickerCtrl::setSelectedAlpha(const U32& alphaValue)
{
if (alphaValue < 0)
{
@ -656,13 +690,27 @@ void GuiColorPickerCtrl::setSelectedAlpha(const F64& alphaValue)
mSelectedAlpha = alphaValue;
}
void GuiColorPickerCtrl::onMouseUp(const GuiEvent &)
void GuiColorPickerCtrl::activateEyeDropper()
{
//if we released the mouse within this control, perform the action
if (mActive && mMouseDown)
mMouseDown = false;
// Make sure we are a pDropperBackground
if (mDisplayMode == GuiColorPickerCtrl::pDropperBackground)
{
mouseLock(this); // take over!
mouseUnlock();
setFirstResponder(); // we need this to be first responder regardless.
//getRoot()->bringObjectToFront(this);
mDropperActive = true;
// Set up our resolution.
Point2I resolution = getRoot()->getExtent();
eyeDropperCap = gScreenShot->_captureBackBuffer();
// Texture handle to resolve the target to.
eyeHandle.set(eyeDropperCap, &GFXStaticTextureSRGBProfile, false, avar("%s() - bb (line %d)", __FUNCTION__, __LINE__));
}
}
/// <summary>
@ -673,49 +721,57 @@ DefineEngineMethod(GuiColorPickerCtrl, executeUpdate, void, (), , "Execute the o
object->onAction();
}
DefineEngineMethod(GuiColorPickerCtrl, setSelectedHue, void, (F64 hueValue), , "Sets the selected hue value should be 0-360.")
/// <summary>
/// This command should only be used with guiColorPicker in pDropperBackground mode.
/// </summary>
DefineEngineMethod(GuiColorPickerCtrl, activateEyeDropper, void, (), , "Activate the dropper mode.")
{
object->activateEyeDropper();
}
DefineEngineMethod(GuiColorPickerCtrl, setSelectedHue, void, (S32 hueValue), , "Sets the selected hue value should be 0-360.")
{
object->setSelectedHue(hueValue);
}
DefineEngineMethod(GuiColorPickerCtrl, getSelectedHue, F64, (), , "Gets the current selected hue value.")
DefineEngineMethod(GuiColorPickerCtrl, getSelectedHue, S32, (), , "Gets the current selected hue value.")
{
return object->getSelectedHue();
}
DefineEngineMethod(GuiColorPickerCtrl, setSelectedBrightness, void, (F64 brightness), , "Sets the selected brightness value should be 0-100.")
DefineEngineMethod(GuiColorPickerCtrl, setSelectedBrightness, void, (S32 brightness), , "Sets the selected brightness value should be 0-100.")
{
object->setSelectedBrightness(brightness);
}
DefineEngineMethod(GuiColorPickerCtrl, getSelectedBrightness, F64, (), , "Gets the current selected brightness.")
DefineEngineMethod(GuiColorPickerCtrl, getSelectedBrightness, S32, (), , "Gets the current selected brightness.")
{
return object->getSelectedBrightness();
}
DefineEngineMethod(GuiColorPickerCtrl, setSelectedSaturation, void, (F64 saturation), , "Sets the selected saturation value should be 0-100.")
DefineEngineMethod(GuiColorPickerCtrl, setSelectedSaturation, void, (S32 saturation), , "Sets the selected saturation value should be 0-100.")
{
object->setSelectedSaturation(saturation);
}
DefineEngineMethod(GuiColorPickerCtrl, getSelectedSaturation, F64, (), , "Gets the current selected saturation value.")
DefineEngineMethod(GuiColorPickerCtrl, getSelectedSaturation, S32, (), , "Gets the current selected saturation value.")
{
return object->getSelectedSaturation();
}
DefineEngineMethod(GuiColorPickerCtrl, setSelectedAlpha, void, (F64 alpha), , "Sets the selected alpha value should be 0-255.")
DefineEngineMethod(GuiColorPickerCtrl, setSelectedAlpha, void, (S32 alpha), , "Sets the selected alpha value should be 0-255.")
{
object->setSelectedAlpha(alpha);
}
DefineEngineMethod(GuiColorPickerCtrl, getSelectedAlpha, F64, (), , "Gets the current selected alpha value.")
DefineEngineMethod(GuiColorPickerCtrl, getSelectedAlpha, S32, (), , "Gets the current selected alpha value.")
{
return object->getSelectedAlpha();
}
DefineEngineMethod(GuiColorPickerCtrl, setSelectedColorI, void, (ColorI col), , "Sets the current selected hsb from a colorI value.")
{
ColorI::Hsb hsb(col.getHSB());
Hsb hsb(col.getHSB());
object->setSelectedHue(hsb.hue);
object->setSelectedSaturation(hsb.sat);
object->setSelectedBrightness(hsb.brightness);
@ -725,26 +781,25 @@ DefineEngineMethod(GuiColorPickerCtrl, setSelectedColorI, void, (ColorI col), ,
DefineEngineMethod(GuiColorPickerCtrl, getSelectedColorI, ColorI, (), , "Gets the current selected hsb as a colorI value.")
{
ColorI col;
col.set(ColorI::Hsb(object->getSelectedHue(), object->getSelectedSaturation(), object->getSelectedBrightness()));
col.set(Hsb(object->getSelectedHue(), object->getSelectedSaturation(), object->getSelectedBrightness()));
col.alpha = object->getSelectedAlpha();
return col;
}
DefineEngineMethod(GuiColorPickerCtrl, setSelectedLinearColor, void, (LinearColorF colF), , "Sets the current selected hsb froma a LinearColorF value.")
{
ColorI col = colF.toColorI();
ColorI::Hsb hsb(col.getHSB());
Hsb hsb = colF.getHSB();
object->setSelectedHue(hsb.hue);
object->setSelectedSaturation(hsb.sat);
object->setSelectedBrightness(hsb.brightness);
object->setSelectedAlpha(col.alpha);
object->setSelectedAlpha(colF.alpha * 255.0);
}
DefineEngineMethod(GuiColorPickerCtrl, getSelectedLinearColor, LinearColorF, (), , "Gets the current selected hsb as a LinearColorF value.")
{
ColorI col;
col.set(ColorI::Hsb(object->getSelectedHue(), object->getSelectedSaturation(), object->getSelectedBrightness()));
col.alpha = object->getSelectedAlpha();
return LinearColorF(col);
LinearColorF col;
col.set(Hsb(object->getSelectedHue(), object->getSelectedSaturation(), object->getSelectedBrightness()));
col.alpha = (F32)object->getSelectedAlpha() / 255.0f;
return col;
}

View file

@ -108,23 +108,27 @@ class GuiColorPickerCtrl : public GuiControl
/// <param name="bounds">The bounds of the ctrl.</param>
void renderAlphaSelector(RectI& bounds);
void renderEyeDropper();
/// @name Core Variables
/// @{
PickMode mDisplayMode; ///< Current color display mode of the selector
PickMode mDisplayMode; ///< Current color display mode of the selector
SelectorMode mSelectorMode; ///< Current color display mode of the selector
F64 mSelectedHue;
F64 mSelectedSaturation;
F64 mSelectedBrightness;
F64 mSelectedAlpha;
U32 mSelectedHue;
U32 mSelectedSaturation;
U32 mSelectedBrightness;
U32 mSelectedAlpha;
Point2I eyeDropperPos;
GBitmap* eyeDropperCap;
GFXTexHandle eyeHandle;
bool mMouseOver; ///< Mouse is over?
bool mMouseDown; ///< Mouse button down?
bool mActionOnMove; ///< Perform onAction() when position has changed?
bool mShowReticle; ///< Show reticle on render
bool mDropperActive; ///< Is the eye dropper active?
bool mMouseOver; ///< Mouse is over?
bool mMouseDown; ///< Mouse button down?
bool mActionOnMove; ///< Perform onAction() when position has changed?
bool mShowReticle; ///< Show reticle on render
Point2I findColor(const LinearColorF & color, const Point2I& offset, const Point2I& resolution, GBitmap& bmp);
S32 mSelectorGap; ///< The half-way "gap" between the selector pos and where the selector is allowed to draw.
S32 mSelectorGap; ///< The half-way "gap" between the selector pos and where the selector is allowed to draw.
GFXStateBlockRef mStateBlock;
/// @}
@ -158,29 +162,32 @@ class GuiColorPickerCtrl : public GuiControl
/// Set the selected hue.
/// </summary>
/// <param name="hueValue">Hue value, 0 - 360.</param>
void setSelectedHue(const F64& hueValue);
F64 getSelectedHue() { return mSelectedHue; }
void setSelectedHue(const U32& hueValue);
U32 getSelectedHue() { return mSelectedHue; }
/// <summary>
/// Set the selected brightness.
/// </summary>
/// <param name="brightValue">Brightness value, 0 - 100.</param>
void setSelectedBrightness(const F64& brightValue);
F64 getSelectedBrightness() { return mSelectedBrightness; }
void setSelectedBrightness(const U32& brightValue);
U32 getSelectedBrightness() { return mSelectedBrightness; }
/// <summary>
/// Set the selected saturation.
/// </summary>
/// <param name="satValue">Saturation value, 0 - 100.</param>
void setSelectedSaturation(const F64& satValue);
F64 getSelectedSaturation() { return mSelectedSaturation; }
void setSelectedSaturation(const U32& satValue);
U32 getSelectedSaturation() { return mSelectedSaturation; }
/// <summary>
/// Set the selected alpha.
/// </summary>
/// <param name="alphaValue">Alpha value, 0 - 255.</param>
void setSelectedAlpha(const F64& alphaValue);
F64 getSelectedAlpha() { return mSelectedAlpha; }
void setSelectedAlpha(const U32& alphaValue);
U32 getSelectedAlpha() { return mSelectedAlpha; }
void activateEyeDropper();
};
typedef GuiColorPickerCtrl::PickMode GuiColorPickMode;

View file

@ -29,6 +29,7 @@
#include "gui/containers/guiScrollCtrl.h"
#include "sim/actionMap.h"
#include "core/strings/stringUnit.h"
#include "console/typeValidators.h"
//-----------------------------------------------------------------------------
// GuiGameListMenuCtrl
@ -1878,10 +1879,10 @@ void GuiGameListMenuProfile::initPersistFields()
addField( "rowSize", TypePoint2I, Offset(mRowSize, GuiGameListMenuProfile),
"The base size (\"width height\") of a row" );
addField("columnSplit", TypeS32, Offset(mColumnSplit, GuiGameListMenuProfile),
addFieldV("columnSplit", TypeRangedS32, Offset(mColumnSplit, GuiGameListMenuProfile), &CommonValidators::PositiveInt,
"Padding between the leftmost edge of the control, and the row's left arrow.");
addField("rightPad", TypeS32, Offset(mRightPad, GuiGameListMenuProfile),
addFieldV("rightPad", TypeRangedS32, Offset(mRightPad, GuiGameListMenuProfile), &CommonValidators::PositiveInt,
"Padding between the rightmost edge of the control and the row's right arrow.");
Parent::initPersistFields();

View file

@ -544,10 +544,10 @@ ConsoleDocClass( GuiGameListOptionsProfile,
void GuiGameListOptionsProfile::initPersistFields()
{
docsURL;
addField( "columnSplit", TypeS32, Offset(mColumnSplit, GuiGameListOptionsProfile),
addFieldV( "columnSplit", TypeRangedS32, Offset(mColumnSplit, GuiGameListOptionsProfile), &CommonValidators::PositiveInt,
"Padding between the leftmost edge of the control, and the row's left arrow." );
addField( "rightPad", TypeS32, Offset(mRightPad, GuiGameListOptionsProfile),
addFieldV( "rightPad", TypeRangedS32, Offset(mRightPad, GuiGameListOptionsProfile), &CommonValidators::PositiveInt,
"Padding between the rightmost edge of the control and the row's right arrow." );
Parent::initPersistFields();

View file

@ -29,6 +29,7 @@
#include "gui/containers/guiScrollCtrl.h"
#include "core/strings/stringUnit.h"
#include "gui/core/guiDefaultControlRender.h"
#include "console/typeValidators.h"
//-----------------------------------------------------------------------------
// GuiGameSettingsCtrl
@ -829,13 +830,13 @@ void GuiGameSettingsCtrl::initPersistFields()
INITPERSISTFIELD_IMAGEASSET_REFACTOR(PreviousBitmap, GuiGameSettingsCtrl, "Bitmap used for the previous button when in list mode.");
INITPERSISTFIELD_IMAGEASSET_REFACTOR(NextBitmap, GuiGameSettingsCtrl, "Bitmap used for the next button when in list mode.");
addField("arrowSize", TypeS32, Offset(mArrowSize, GuiGameSettingsCtrl),
addFieldV("arrowSize", TypeRangedS32, Offset(mArrowSize, GuiGameSettingsCtrl), &CommonValidators::PositiveInt,
"Size of the arrow buttons' extents");
addField("columnSplit", TypeS32, Offset(mColumnSplit, GuiGameSettingsCtrl),
addFieldV("columnSplit", TypeRangedS32, Offset(mColumnSplit, GuiGameSettingsCtrl), &CommonValidators::NaturalNumber,
"Position of the split between the leftside label and the rightside setting parts");
addField("rightPad", TypeS32, Offset(mRightPad, GuiGameSettingsCtrl),
addFieldV("rightPad", TypeRangedS32, Offset(mRightPad, GuiGameSettingsCtrl), &CommonValidators::NaturalNumber,
"Padding between the rightmost edge of the control and right arrow.");
addField("callbackOnA", TypeString, Offset(mCallbackOnA, GuiGameSettingsCtrl),

View file

@ -32,6 +32,7 @@
#include "sfx/sfxTrack.h"
#include "sfx/sfxTypes.h"
#include "console/engineAPI.h"
#include "console/typeValidators.h"
IMPLEMENT_CONOBJECT( GuiMLTextCtrl );
@ -301,18 +302,18 @@ void GuiMLTextCtrl::initPersistFields()
docsURL;
addGroup( "Text" );
addField("lineSpacing", TypeS32, Offset(mLineSpacingPixels, GuiMLTextCtrl), "The number of blank pixels to place between each line.\n");
addFieldV("lineSpacing", TypeRangedS32, Offset(mLineSpacingPixels, GuiMLTextCtrl), &CommonValidators::PositiveInt, "The number of blank pixels to place between each line.\n");
addField("allowColorChars", TypeBool, Offset(mAllowColorChars, GuiMLTextCtrl), "If true, the control will allow characters to have unique colors.");
addField("maxChars", TypeS32, Offset(mMaxBufferSize, GuiMLTextCtrl), "Maximum number of characters that the control will display.");
addFieldV("maxChars", TypeRangedS32, Offset(mMaxBufferSize, GuiMLTextCtrl), &CommonValidators::NegDefaultInt, "Maximum number of characters that the control will display.");
INITPERSISTFIELD_SOUNDASSET(DeniedSound, GuiMLTextCtrl, "If the text will not fit in the control, the deniedSound is played.");
addField("text", TypeCaseString, Offset( mInitialText, GuiMLTextCtrl ), "Text to display in this control.");
addField("useURLMouseCursor", TypeBool, Offset(mUseURLMouseCursor, GuiMLTextCtrl), "If true, the mouse cursor will turn into a hand cursor while over a link in the text.\n"
"This is dependant on the markup language used by the GuiMLTextCtrl\n");
addField("useTypeOverTime", TypeBool, Offset(mUseTypeOverTime, GuiMLTextCtrl), "");
addField("typeOverTimeSpeedMS", TypeF32, Offset(mTypeOverTimeSpeedMS, GuiMLTextCtrl), "");
addFieldV("typeOverTimeSpeedMS", TypeRangedF32, Offset(mTypeOverTimeSpeedMS, GuiMLTextCtrl), &CommonValidators::PositiveFloat, "");
addField("typeoutSound", TypeSFXTrackName, Offset(mTypeoutSound, GuiMLTextCtrl), "Played when the text is being typed out");
addField("typeoutSoundRate", TypeS32, Offset(mTypeoutSoundRate, GuiMLTextCtrl), "Dictates how many characters must be typed out before the sound is played again. -1 for the sound to only play once at the start.");
addFieldV("typeoutSoundRate", TypeRangedS32, Offset(mTypeoutSoundRate, GuiMLTextCtrl), &CommonValidators::NegDefaultInt, "Dictates how many characters must be typed out before the sound is played again. -1 for the sound to only play once at the start.");
endGroup( "Text" );

View file

@ -295,7 +295,7 @@ GuiPopUpMenuCtrl::~GuiPopUpMenuCtrl()
void GuiPopUpMenuCtrl::initPersistFields(void)
{
docsURL;
addField("maxPopupHeight", TypeS32, Offset(mMaxPopupHeight, GuiPopUpMenuCtrl));
addFieldV("maxPopupHeight", TypeRangedS32, Offset(mMaxPopupHeight, GuiPopUpMenuCtrl), &CommonValidators::PositiveInt);
addField("sbUsesNAColor", TypeBool, Offset(mRenderScrollInNA, GuiPopUpMenuCtrl));
addField("reverseTextList", TypeBool, Offset(mReverseTextList, GuiPopUpMenuCtrl));

View file

@ -28,6 +28,7 @@
#include "gfx/primBuilder.h"
#include "gfx/gfxDrawUtil.h"
#include "console/engineAPI.h"
#include "console/typeValidators.h"
ConsoleDocClass( GuiPopUpMenuCtrlEx,
"@brief A control that allows to select a value from a drop-down list.\n\n"
@ -349,7 +350,7 @@ GuiPopUpMenuCtrlEx::~GuiPopUpMenuCtrlEx()
void GuiPopUpMenuCtrlEx::initPersistFields(void)
{
docsURL;
addField("maxPopupHeight", TypeS32, Offset(mMaxPopupHeight, GuiPopUpMenuCtrlEx), "Length of menu when it extends");
addFieldV("maxPopupHeight", TypeRangedS32, Offset(mMaxPopupHeight, GuiPopUpMenuCtrlEx), &CommonValidators::PositiveInt, "Length of menu when it extends");
addField("sbUsesNAColor", TypeBool, Offset(mRenderScrollInNA, GuiPopUpMenuCtrlEx), "Deprecated" "@internal");
addField("reverseTextList", TypeBool, Offset(mReverseTextList, GuiPopUpMenuCtrlEx), "Reverses text list if popup extends up, instead of down");
@ -1229,7 +1230,7 @@ void GuiPopUpMenuCtrlEx::onRender(Point2I offset, const RectI &updateRect)
{
localStart.x = getWidth() - txt_w - 12;
}
}
}
else
{
localStart.x = mProfile->mTextOffset.x; // Use mProfile->mTextOffset as a controlable margin for the control's text.

View file

@ -96,7 +96,7 @@ void GuiTextCtrl::initPersistFields()
addField( "textID", TypeString, Offset( mInitialTextID, GuiTextCtrl ),
"Maps the text of this control to a variable used in localization, rather than raw text.");
addField( "maxLength", TypeS32, Offset( mMaxStrLen, GuiTextCtrl ),
addFieldV( "maxLength", TypeRangedS32, Offset( mMaxStrLen, GuiTextCtrl ), &CommonValidators::PositiveInt,
"Defines the maximum length of the text. The default is 1024." );
Parent::initPersistFields();

View file

@ -36,6 +36,7 @@
#include "sfx/sfxSystem.h"
#include "core/strings/unicode.h"
#include "console/engineAPI.h"
#include "console/typeValidators.h"
IMPLEMENT_CONOBJECT(GuiTextEditCtrl);
@ -177,7 +178,7 @@ void GuiTextEditCtrl::initPersistFields()
addField("validate", TypeRealString,Offset(mValidateCommand, GuiTextEditCtrl), "Script command to be called when the first validater is lost.\n");
addField("escapeCommand", TypeRealString,Offset(mEscapeCommand, GuiTextEditCtrl), "Script command to be called when the Escape key is pressed.\n");
addField("historySize", TypeS32, Offset(mHistorySize, GuiTextEditCtrl), "How large of a history buffer to maintain.\n");
addFieldV("historySize", TypeRangedS32, Offset(mHistorySize, GuiTextEditCtrl), &CommonValidators::PositiveInt, "How large of a history buffer to maintain.\n");
addField("tabComplete", TypeBool, Offset(mTabComplete, GuiTextEditCtrl), "If true, when the 'tab' key is pressed, it will act as if the Enter key was pressed on the control.\n");
addField("deniedSound", TypeSFXTrackName, Offset(mDeniedSound, GuiTextEditCtrl), "If the attempted text cannot be entered, this sound effect will be played.\n");
addField("sinkAllKeyEvents", TypeBool, Offset(mSinkAllKeyEvents, GuiTextEditCtrl), "If true, every key event will act as if the Enter key was pressed.\n");

View file

@ -341,6 +341,8 @@ void GuiTextEditSliderCtrl::onRender(Point2I offset, const RectI &updateRect)
mIncCounter = (mIncCounter > 0.0f) ? mIncCounter-1 : mIncCounter+1;
checkRange();
setValue();
execConsoleCallback();
execAltConsoleCallback();
mCursorPos = 0;
}
}

View file

@ -29,6 +29,7 @@
#include "gui/core/guiDefaultControlRender.h"
#include "gfx/gfxDrawUtil.h"
#include "console/engineAPI.h"
#include "console/typeValidators.h"
IMPLEMENT_CONOBJECT(GuiTextListCtrl);
@ -134,7 +135,7 @@ void GuiTextListCtrl::initPersistFields()
addField("columns", TypeS32Vector, Offset(mColumnOffsets, GuiTextListCtrl), "A vector of column offsets. The number of values determines the number of columns in the table.\n" );
addField("fitParentWidth", TypeBool, Offset(mFitParentWidth, GuiTextListCtrl), "If true, the width of this control will match the width of its parent.\n");
addField("clipColumnText", TypeBool, Offset(mClipColumnText, GuiTextListCtrl), "If true, text exceeding a column's given width will get clipped.\n" );
addField("rowHeightPadding", TypeS32, Offset(mRowHeightPadding, GuiTextListCtrl), "Sets how much padding to add to the row heights on top of the font height");
addFieldV("rowHeightPadding", TypeRangedS32, Offset(mRowHeightPadding, GuiTextListCtrl), &CommonValidators::PositiveInt, "Sets how much padding to add to the row heights on top of the font height");
Parent::initPersistFields();
}

View file

@ -883,10 +883,10 @@ void GuiTreeViewCtrl::initPersistFields()
docsURL;
addGroup( "TreeView" );
addField( "tabSize", TypeS32, Offset(mTabSize, GuiTreeViewCtrl));
addFieldV( "tabSize", TypeRangedS32, Offset(mTabSize, GuiTreeViewCtrl), &CommonValidators::PositiveInt);
addField( "textOffset", TypeS32, Offset(mTextOffset, GuiTreeViewCtrl));
addField( "fullRowSelect", TypeBool, Offset(mFullRowSelect, GuiTreeViewCtrl));
addField( "itemHeight", TypeS32, Offset(mItemHeight, GuiTreeViewCtrl));
addFieldV( "itemHeight", TypeRangedS32, Offset(mItemHeight, GuiTreeViewCtrl), &CommonValidators::PositiveInt);
addField( "destroyTreeOnSleep", TypeBool, Offset(mDestroyOnSleep, GuiTreeViewCtrl),
"If true, the entire tree item hierarchy is deleted when the control goes to sleep." );
addField( "mouseDragging", TypeBool, Offset(mSupportMouseDragging, GuiTreeViewCtrl));

View file

@ -2169,7 +2169,7 @@ void GuiCanvas::setFirstResponder( GuiControl* newResponder )
if( oldResponder && ( oldResponder != newResponder ) )
oldResponder->onLoseFirstResponder();
if( newResponder && ( newResponder != oldResponder ) )
if( newResponder && ( newResponder != oldResponder ) && newResponder->isProperlyAdded())
newResponder->onGainFirstResponder();
}

View file

@ -39,6 +39,7 @@
#include "gui/core/guiDefaultControlRender.h"
#include "gui/editor/guiEditCtrl.h"
#include "gfx/gfxDrawUtil.h"
#include "console/typeValidators.h"
//#define DEBUG_SPEW
@ -306,7 +307,7 @@ void GuiControl::initPersistFields()
"Control profile to use when rendering tooltips for this control." );
addField("tooltip", TypeRealString, Offset(mTooltip, GuiControl),
"String to show in tooltip for this control." );
addField("hovertime", TypeS32, Offset(mTipHoverTime, GuiControl),
addFieldV("hovertime", TypeRangedS32, Offset(mTipHoverTime, GuiControl), &CommonValidators::PositiveInt,
"Time for mouse to hover over control until tooltip is shown (in milliseconds)." );
endGroup( "ToolTip" );
@ -2230,10 +2231,10 @@ void GuiControl::setFirstResponder( GuiControl* firstResponder )
void GuiControl::setFirstResponder()
{
if( mAwake && mVisible )
if( mAwake && mVisible && isProperlyAdded())
{
GuiControl *parent = getParent();
if ( mProfile->mCanKeyFocus == true && parent != NULL )
if ( mProfile->mCanKeyFocus == true && parent && parent->isProperlyAdded())
parent->setFirstResponder( this );
}
}

View file

@ -741,7 +741,7 @@ class GuiControl : public SimGroup
GuiControl *getFirstResponder() { return mFirstResponder; }
/// Occurs when the control gains first-responder status.
virtual void onGainFirstResponder();
void onGainFirstResponder();
/// Occurs when the control loses first-responder status.
virtual void onLoseFirstResponder();

View file

@ -34,6 +34,7 @@
#include "sfx/sfxTrack.h"
#include "sfx/sfxTypes.h"
#include "console/engineAPI.h"
#include "console/typeValidators.h"
//#define DEBUG_SPEW
@ -370,9 +371,9 @@ void GuiControlProfile::initPersistFields()
addField("fillColorNA", TypeColorI, Offset(mFillColorNA, GuiControlProfile));
addField("fillColorERR", TypeColorI, Offset(mFillColorERR, GuiControlProfile));
addField("fillColorSEL", TypeColorI, Offset(mFillColorSEL, GuiControlProfile));
addField("border", TypeS32, Offset(mBorder, GuiControlProfile),
addFieldV("border", TypeRangedS32, Offset(mBorder, GuiControlProfile), &CommonValidators::S32Range,
"Border type (0=no border)." );
addField("borderThickness",TypeS32, Offset(mBorderThickness, GuiControlProfile),
addFieldV("borderThickness", TypeRangedS32, Offset(mBorderThickness, GuiControlProfile), &CommonValidators::PositiveInt,
"Thickness of border in pixels." );
addField("borderColor", TypeColorI, Offset(mBorderColor, GuiControlProfile),
"Color to draw border with." );
@ -394,7 +395,7 @@ void GuiControlProfile::initPersistFields()
addField("fontType", TypeString, Offset(mFontType, GuiControlProfile),
"Name of font family and typeface (e.g. \"Arial Bold\")." );
addField("fontSize", TypeS32, Offset(mFontSize, GuiControlProfile),
addFieldV("fontSize", TypeRangedS32, Offset(mFontSize, GuiControlProfile), &CommonValidators::PositiveInt,
"Font size in points." );
addField("fontCharset", TYPEID< FontCharset >(), Offset(mFontCharset, GuiControlProfile) );
addField("fontColors", TypeColorI, Offset(mFontColors, GuiControlProfile), ColorMax,

View file

@ -54,7 +54,7 @@ void GuiEaseViewCtrl::initPersistFields()
addField("ease", TypeEaseF, Offset( mEase, GuiEaseViewCtrl ) );
addField("easeColor", TypeColorF, Offset( mEaseColor, GuiEaseViewCtrl ) );
addField("easeWidth", TypeF32, Offset(mEaseWidth, GuiEaseViewCtrl ) );
addFieldV("easeWidth", TypeRangedF32, Offset(mEaseWidth, GuiEaseViewCtrl ), &CommonValidators::PositiveNonZeroFloat);
addField("axisColor", TypeColorF, Offset( mAxisColor, GuiEaseViewCtrl ) );
}

View file

@ -152,7 +152,7 @@ void GuiEditCtrl::initPersistFields()
"If true, selection edges will snap into alignment when moved or resized." );
addField( "snapToCenters", TypeBool, Offset( mSnapToCenters, GuiEditCtrl ),
"If true, selection centers will snap into alignment when moved or resized." );
addField( "snapSensitivity", TypeS32, Offset( mSnapSensitivity, GuiEditCtrl ),
addFieldV( "snapSensitivity", TypeRangedS32, Offset( mSnapSensitivity, GuiEditCtrl ), &CommonValidators::PositiveInt,
"Distance in pixels that edge and center snapping will work across." );
endGroup( "Snapping" );

View file

@ -29,6 +29,7 @@
#include "guiFilterCtrl.h"
#include "math/mMath.h"
#include "gfx/gfxDrawUtil.h"
#include "console/typeValidators.h"
IMPLEMENT_CONOBJECT(GuiFilterCtrl);
@ -51,7 +52,7 @@ GuiFilterCtrl::GuiFilterCtrl()
void GuiFilterCtrl::initPersistFields()
{
docsURL;
addField("controlPoints", TypeS32, Offset(mControlPointRequest, GuiFilterCtrl),
addFieldV("controlPoints", TypeRangedS32, Offset(mControlPointRequest, GuiFilterCtrl), &CommonValidators::NaturalNumber,
"Total number of control points in the spline curve." );
addField("filter", TypeF32Vector, Offset(mFilter, GuiFilterCtrl),
"Vector of control points." );

View file

@ -105,7 +105,7 @@ void GuiGraphCtrl::initPersistFields()
docsURL;
addGroup( "Graph" );
addField( "centerY", TypeF32, Offset( mCenterY, GuiGraphCtrl ),
addFieldV( "centerY", TypeRangedF32, Offset( mCenterY, GuiGraphCtrl ), &CommonValidators::NormalizedFloat,
"Ratio of where to place the center coordinate of the graph on the Y axis. 0.5=middle height of control.\n\n"
"This allows to account for graphs that have only positive or only negative data points, for example." );
@ -119,7 +119,7 @@ void GuiGraphCtrl::initPersistFields()
"Name of the variable to automatically plot on the curves. If empty, auto-plotting "
"is disabled for the respective curve." );
addField( "plotInterval", TypeS32, Offset( mAutoPlotDelay, GuiGraphCtrl ), MaxPlots,
addFieldV( "plotInterval", TypeRangedS32, Offset( mAutoPlotDelay, GuiGraphCtrl ), &CommonValidators::PositiveInt, MaxPlots,
"Interval between auto-plots of #plotVariable for the respective curve (in milliseconds)." );
endGroup( "Graph" );

View file

@ -28,6 +28,7 @@
#include "gui/editor/inspector/dynamicGroup.h"
#include "gui/containers/guiScrollCtrl.h"
#include "gui/editor/inspector/customField.h"
#include "console/typeValidators.h"
IMPLEMENT_CONOBJECT(GuiInspector);
@ -38,6 +39,12 @@ ConsoleDocClass( GuiInspector,
);
IMPLEMENT_CALLBACK(GuiInspector, onPreInspectObject, void, (SimObject* object), (object),
"Called prior to inspecting a new object.\n");
IMPLEMENT_CALLBACK(GuiInspector, onPostInspectObject, void, (SimObject* object), (object),
"Called after inspecting a new object.\n");
//#define DEBUG_SPEW
@ -71,7 +78,7 @@ void GuiInspector::initPersistFields()
docsURL;
addGroup( "Inspector" );
addField( "dividerMargin", TypeS32, Offset( mDividerMargin, GuiInspector ) );
addFieldV( "dividerMargin", TypeRangedS32, Offset( mDividerMargin, GuiInspector ), &CommonValidators::PositiveInt);
addField( "groupFilters", TypeRealString, Offset( mGroupFilters, GuiInspector ),
"Specify groups that should be shown or not. Specifying 'shown' implicitly does 'not show' all other groups. Example string: +name -otherName" );
@ -79,7 +86,7 @@ void GuiInspector::initPersistFields()
addField( "showCustomFields", TypeBool, Offset( mShowCustomFields, GuiInspector ),
"If false the custom fields Name, Id, and Source Class will not be shown." );
addField("forcedArrayIndex", TypeS32, Offset(mForcedArrayIndex, GuiInspector));
addFieldV("forcedArrayIndex", TypeRangedS32, Offset(mForcedArrayIndex, GuiInspector), &CommonValidators::NegDefaultInt);
addField("searchText", TypeString, Offset(mSearchText, GuiInspector), "A string that, if not blank, is used to filter shown fields");
endGroup( "Inspector" );
@ -325,11 +332,14 @@ bool GuiInspector::isInspectingObject( SimObject* object )
//-----------------------------------------------------------------------------
void GuiInspector::inspectObject( SimObject *object )
{
{
onPreInspectObject_callback((mTargets.size() > 1)? mTargets[0] : NULL);
if( mTargets.size() > 1 || !isInspectingObject( object ) )
clearInspectObjects();
addInspectObject( object );
onPostInspectObject_callback(object);
}
//-----------------------------------------------------------------------------
@ -349,7 +359,8 @@ void GuiInspector::clearInspectObjects()
void GuiInspector::addInspectObject( SimObject* object, bool autoSync )
{
// If we are already inspecting the object, just update the groups.
onPreInspectObject_callback((mTargets.size() > 1) ? mTargets[0] : NULL);
if( isInspectingObject( object ) )
{
#ifdef DEBUG_SPEW
@ -379,6 +390,7 @@ void GuiInspector::addInspectObject( SimObject* object, bool autoSync )
if( autoSync )
refresh();
onPostInspectObject_callback(object);
}
//-----------------------------------------------------------------------------
@ -629,7 +641,7 @@ void GuiInspector::refresh()
GuiInspectorGroup *newGroup = new GuiInspectorGroup( itr->pGroupname, this );
newGroup->setForcedArrayIndex(mForcedArrayIndex);
newGroup->registerObject();
newGroup->registerObject();
if( !newGroup->getNumFields() )
{
#ifdef DEBUG_SPEW
@ -995,6 +1007,21 @@ DefineEngineMethod(GuiInspector, findExistentGroup, S32, (const char* groupName)
return group ? group->getId() : 0;
}
DefineEngineMethod(GuiInspector, getInspectedGroupCount, S32, (), ,
"How many inspected groups there are.\n"
"@return how many inspected groups there are")
{
return object->getGroups().size();
}
DefineEngineMethod(GuiInspector, getInspectedGroup, GuiInspectorGroup*, (S32 key), ,
"Finds an existing GuiInspectorGroup if it exists and returns it's Id.\n"
"@param key nth group out of the list of groups."
"@return id of the GuiInspectorGroup")
{
return object->getGroups()[key];
}
DefineEngineMethod(GuiInspector, removeGroup, void, (const char* groupName), ,
"Finds an existing GuiInspectorGroup if it exists removes it.\n"
"@param groupName Name of the new GuiInspectorGroup to find in this Inspector.")

View file

@ -174,7 +174,9 @@ public:
StringTableEntry getSearchText() { return mSearchText; }
void setSearchText(StringTableEntry searchText);
Vector<GuiInspectorGroup*> getGroups() { return mGroups; };
DECLARE_CALLBACK(void, onPreInspectObject, (SimObject* object) );
DECLARE_CALLBACK(void, onPostInspectObject, (SimObject* object) );
protected:
typedef Vector< SimObjectPtr< SimObject > > TargetVector;

View file

@ -41,7 +41,7 @@
#include "math/mEase.h"
#include "math/mathTypes.h"
#include "sim/actionMap.h"
#include "console/typeValidators.h"
//-----------------------------------------------------------------------------
// GuiInspectorTypeMenuBase
@ -1350,6 +1350,117 @@ void GuiInspectorTypeS32::setValue( StringTableEntry newValue )
ctrl->setText( newValue );
}
//-----------------------------------------------------------------------------
// GuiInspectorTypeRangedF32
//-----------------------------------------------------------------------------
IMPLEMENT_CONOBJECT(GuiInspectorTypeRangedF32);
ConsoleDocClass(GuiInspectorTypeRangedF32,
"@brief Inspector field type for range-clamped F32\n\n"
"Editor use only.\n\n"
"@internal"
);
void GuiInspectorTypeRangedF32::consoleInit()
{
Parent::consoleInit();
ConsoleBaseType::getType(TypeRangedF32)->setInspectorFieldType("GuiInspectorTypeRangedF32");
}
GuiControl* GuiInspectorTypeRangedF32::constructEditControl()
{
GuiControl* retCtrl = new GuiTextEditSliderCtrl();
retCtrl->setDataField(StringTable->insert("profile"), NULL, "GuiInspectorTextEditProfile");
// Don't forget to register ourselves
_registerEditControl(retCtrl);
char szBuffer[512];
dSprintf(szBuffer, 512, "%d.apply(%d.getText());", getId(), retCtrl->getId());
retCtrl->setField("AltCommand", szBuffer);
FRangeValidator* validator = dynamic_cast<FRangeValidator*>(mField->validator);
if (validator)
{
retCtrl->setField("format", "%g");
retCtrl->setField("range", String::ToString("%g %g", validator->getMin(), validator->getMax()));
if (validator->getFidelity()>0.0f)
retCtrl->setField("increment", String::ToString("%g", (validator->getMax()-validator->getMin())/validator->getFidelity()));
else
retCtrl->setField("increment", String::ToString("%g", 0.01));
}
return retCtrl;
}
void GuiInspectorTypeRangedF32::setValue(StringTableEntry newValue)
{
GuiTextEditSliderCtrl* ctrl = dynamic_cast<GuiTextEditSliderCtrl*>(mEdit);
if (ctrl != NULL)
ctrl->setText(newValue);
}
//-----------------------------------------------------------------------------
// GuiInspectorTypeRangedS32
//-----------------------------------------------------------------------------
IMPLEMENT_CONOBJECT(GuiInspectorTypeRangedS32);
ConsoleDocClass(GuiInspectorTypeRangedS32,
"@brief Inspector field type for range-clamped S32\n\n"
"Editor use only.\n\n"
"@internal"
);
void GuiInspectorTypeRangedS32::consoleInit()
{
Parent::consoleInit();
ConsoleBaseType::getType(TypeRangedS32)->setInspectorFieldType("GuiInspectorTypeRangedS32");
}
GuiControl* GuiInspectorTypeRangedS32::constructEditControl()
{
GuiControl* retCtrl = new GuiTextEditSliderCtrl();
retCtrl->setDataField(StringTable->insert("profile"), NULL, "GuiInspectorTextEditProfile");
// Don't forget to register ourselves
_registerEditControl(retCtrl);
char szBuffer[512];
dSprintf(szBuffer, 512, "%d.apply(%d.getText());", getId(), retCtrl->getId());
retCtrl->setField("AltCommand", szBuffer);
IRangeValidator* validator = dynamic_cast<IRangeValidator*>(mField->validator);
retCtrl->setField("increment", "1");
retCtrl->setField("format", "%d");
retCtrl->setField("range", "-2147483648 2147483647");
if (validator)
{
retCtrl->setField("range", String::ToString("%d %d", validator->getMin(), validator->getMax()));
if (validator->getFidelity() > 1)
retCtrl->setField("increment", String::ToString("%d", (validator->getMax() - validator->getMin()) / validator->getFidelity()));
}
else
{
IRangeValidatorScaled* scaledValidator = dynamic_cast<IRangeValidatorScaled*>(mField->validator);
if (scaledValidator)
{
retCtrl->setField("range", String::ToString("%d %d", scaledValidator->getMin(), scaledValidator->getMax()));
if (validator->getFidelity() > 1)
retCtrl->setField("increment", String::ToString("%d", scaledValidator->getScaleFactor()));
}
}
return retCtrl;
}
void GuiInspectorTypeRangedS32::setValue(StringTableEntry newValue)
{
GuiTextEditSliderCtrl* ctrl = dynamic_cast<GuiTextEditSliderCtrl*>(mEdit);
if (ctrl != NULL)
ctrl->setText(newValue);
}
//-----------------------------------------------------------------------------
// GuiInspectorTypeS32Mask
//-----------------------------------------------------------------------------
@ -1522,6 +1633,32 @@ void GuiInspectorTypeBitMask32::setValue( StringTableEntry value )
{
U32 mask = dAtoui( value );
if (mask == 0 && mask != -1) //zero we need to double check. -1 we know is all on
{
BitSet32 bitMask;
const EngineEnumTable* table = mField->table;
if (!table)
{
ConsoleBaseType* type = ConsoleBaseType::getType(mField->type);
if (type && type->getEnumTable())
table = type->getEnumTable();
}
if (table)
{
const EngineEnumTable& t = *table;
const U32 numEntries = t.getNumValues();
String inString(value);
for (U32 i = 0; i < numEntries; i++)
{
if (inString.find(t[i].getName()) != String::NPos)
bitMask.set(t[i].getInt());
}
mask = bitMask.getMask();
}
}
for ( U32 i = 0; i < mArrayCtrl->size(); i++ )
{
GuiCheckBoxCtrl *pCheckBox = dynamic_cast<GuiCheckBoxCtrl*>( mArrayCtrl->at(i) );

View file

@ -473,6 +473,35 @@ public:
void setValue( StringTableEntry newValue ) override;
};
//------------------------------------------------------------------------------
// TypeRangedF32 GuiInspectorField class
//------------------------------------------------------------------------------
class GuiInspectorTypeRangedF32 : public GuiInspectorField
{
private:
typedef GuiInspectorField Parent;
public:
DECLARE_CONOBJECT(GuiInspectorTypeRangedF32);
static void consoleInit();
GuiControl* constructEditControl() override;
void setValue(StringTableEntry newValue) override;
};
//------------------------------------------------------------------------------
// TypeRangedS32 GuiInspectorField class
//------------------------------------------------------------------------------
class GuiInspectorTypeRangedS32 : public GuiInspectorField
{
private:
typedef GuiInspectorField Parent;
public:
DECLARE_CONOBJECT(GuiInspectorTypeRangedS32);
static void consoleInit();
GuiControl* constructEditControl() override;
void setValue(StringTableEntry newValue) override;
};
//------------------------------------------------------------------------------
// TypeBitMask32 GuiInspectorField class

View file

@ -34,6 +34,7 @@
#include "gfx/primBuilder.h"
#include "console/engineAPI.h"
#include "gui/editor/guiPopupMenuCtrl.h"
#include "console/typeValidators.h"
// menu bar:
// basic idea - fixed height control bar at the top of a window, placed and sized in gui editor
@ -188,9 +189,9 @@ void GuiMenuBar::onRemove()
void GuiMenuBar::initPersistFields()
{
docsURL;
addField("padding", TypeS32, Offset( mPadding, GuiMenuBar ),"Extra padding to add to the bounds of the control.\n");
addFieldV("padding", TypeRangedS32, Offset( mPadding, GuiMenuBar ), &CommonValidators::PositiveInt,"Extra padding to add to the bounds of the control.\n");
addField("menubarHeight", TypeS32, Offset(mMenubarHeight, GuiMenuBar), "Sets the height of the menubar when attached to the canvas.\n");
addFieldV("menubarHeight", TypeRangedS32, Offset(mMenubarHeight, GuiMenuBar), &CommonValidators::PositiveInt, "Sets the height of the menubar when attached to the canvas.\n");
Parent::initPersistFields();
}
@ -506,6 +507,16 @@ void GuiMenuBar::onAction()
mouseDownMenu->popupMenu->showPopup(root, pos.x, pos.y);
}
void GuiMenuBar::closeMenu()
{
if(mouseDownMenu)
mouseDownMenu->popupMenu->hidePopup();
mouseOverMenu = NULL;
mouseDownMenu = NULL;
mMouseInMenu = false;
}
// Process a tick
void GuiMenuBar::processTick()
{

View file

@ -247,6 +247,10 @@ void GuiPopupMenuTextListCtrl::onMouseUp(const GuiEvent &event)
{
if (item->mEnabled)
{
if(mMenuBar)
{
mMenuBar->closeMenu();
}
Con::executef(mPopup, "onSelectItem", Con::getIntArg(getSelectedCell().y), item->mText.isNotEmpty() ? item->mText : String(""));
}
}

View file

@ -25,6 +25,7 @@
#include "console/engineAPI.h"
#include "gfx/gfxDevice.h"
#include "gfx/gfxDrawUtil.h"
#include "console/typeValidators.h"
#include "gui/editor/guiRectHandles.h"
@ -55,7 +56,7 @@ void GuiRectHandles::initPersistFields()
{
docsURL;
addField("handleRect", TypeRectF, Offset(mHandleRect, GuiRectHandles), "RectF of handle's box." );
addField("handleSize", TypeS32, Offset(mHandleSize, GuiRectHandles), "Size of handles in pixels." );
addFieldV("handleSize", TypeRangedS32, Offset(mHandleSize, GuiRectHandles), &CommonValidators::NaturalNumber, "Size of handles in pixels." );
addField("useCustomColor", TypeBool, Offset(mUseCustomColor, GuiRectHandles), "Use given custom color for handles." );
addField("handleColor", TypeColorI, Offset(mHandleColor, GuiRectHandles), "Use given custom color for handles." );

View file

@ -29,6 +29,7 @@
#include "console/consoleTypes.h"
#include "gui/core/guiCanvas.h"
#include "gui/core/guiDefaultControlRender.h"
#include "console/typeValidators.h"
IMPLEMENT_CONOBJECT(GuiSeparatorCtrl);
@ -77,9 +78,9 @@ void GuiSeparatorCtrl::initPersistFields()
"Optional text label to display." );
addField("type", TYPEID< separatorTypeOptions >(), Offset(mSeparatorType, GuiSeparatorCtrl),
"Orientation of separator." );
addField("borderMargin", TypeS32, Offset(mMargin, GuiSeparatorCtrl));
addFieldV("borderMargin", TypeRangedS32, Offset(mMargin, GuiSeparatorCtrl), &CommonValidators::PositiveInt);
addField("invisible", TypeBool, Offset(mInvisible, GuiSeparatorCtrl));// Nonsense. Should use GuiControl's visibility.
addField("leftMargin", TypeS32, Offset(mTextLeftMargin, GuiSeparatorCtrl),
addFieldV("leftMargin", TypeRangedS32, Offset(mTextLeftMargin, GuiSeparatorCtrl), &CommonValidators::PositiveInt,
"Left margin of text label." );
Parent::initPersistFields();

View file

@ -174,7 +174,7 @@ void GuiShapeEdPreview::initPersistFields()
addGroup( "Detail Stats" );
addField( "fixedDetail", TypeBool, Offset( mFixedDetail, GuiShapeEdPreview ),
"If false, the current detail is selected based on camera distance" );
addField( "orbitDist", TypeF32, Offset( mOrbitDist, GuiShapeEdPreview ),
addFieldV( "orbitDist", TypeRangedF32, Offset( mOrbitDist, GuiShapeEdPreview ), &CommonValidators::PositiveFloat,
"The current distance from the camera to the model" );
addProtectedField( "currentDL", TypeS32, Offset( mCurrentDL, GuiShapeEdPreview ), &setFieldCurrentDL, &defaultProtectedGetFn,
"The current detail level" );

View file

@ -86,6 +86,7 @@ void GuiInspectorDynamicField::setData( const char* data, bool callbacks )
// give the target a chance to validate
target->inspectPostApply();
Con::executef(mInspector, "onPostInspectorFieldModified", mInspector->getIdString(), target->getIdString());
}
}

View file

@ -233,7 +233,7 @@ void GuiInspectorField::setFirstResponder( GuiControl *firstResponder )
{
Parent::setFirstResponder( firstResponder );
if ( firstResponder == this || firstResponder == mEdit )
if (( firstResponder == this || firstResponder == mEdit ) && (firstResponder && firstResponder->isProperlyAdded()))
{
mInspector->setHighlightField( this );
}
@ -275,7 +275,7 @@ void GuiInspectorField::setWordData(const S32& wordIndex, const char* data, bool
const char* wordData = StringUnit::getUnit(fieldData, wordIndex, " \t\n");
S32 type = mField->type;
if (type == TypeS8 || type == TypeS32 || type == TypeF32 || type == TypeS32Vector
if (type == TypeS8 || type == TypeS16 || type == TypeS32 || type == TypeF32 || type == TypeS32Vector
|| type == TypeF32Vector
|| type == TypeColorI
|| type == TypeColorF
@ -323,7 +323,7 @@ void GuiInspectorField::setWordData(const S32& wordIndex, const char* data, bool
const char* wordData = StringUnit::getUnit(fieldData, wordIndex, " \t\n");
S32 type = mField->type;
if (type == TypeS8 || type == TypeS32 || type == TypeF32 || type == TypeS32Vector
if (type == TypeS8 || type == TypeS16 || type == TypeS32 || type == TypeF32 || type == TypeS32Vector
|| type == TypeF32Vector
|| type == TypeColorI
|| type == TypeColorF
@ -396,7 +396,7 @@ void GuiInspectorField::setWordData(const S32& wordIndex, const char* data, bool
const char* wordData = StringUnit::getUnit(fieldData, wordIndex, " \t\n");
S32 type = mField->type;
if (type == TypeS8 || type == TypeS32 || type == TypeF32 || type == TypeS32Vector
if (type == TypeS8 || type == TypeS16 || type == TypeS32 || type == TypeF32 || type == TypeS32Vector
|| type == TypeF32Vector
|| type == TypeColorI
|| type == TypeColorF
@ -544,7 +544,7 @@ void GuiInspectorField::setData( const char* data, bool callbacks )
String newValue = strData;
S32 type= mField->type;
ConsoleValue evaluationResult;
if( type == TypeS8 || type == TypeS32 || type == TypeF32 )
if( type == TypeS8 || type == TypeS16 || type == TypeS32 || type == TypeF32 )
{
char buffer[ 2048 ];
expandEscape( buffer, newValue );
@ -615,6 +615,8 @@ void GuiInspectorField::setData( const char* data, bool callbacks )
// Give the target a chance to validate.
target->inspectPostApply();
if (String::compare(oldValue.c_str(), newValue.c_str()) != 0)
Con::executef(mInspector, "onPostInspectorFieldModified", mInspector->getIdString(), target->getIdString());
}
if( callbacks && numTargets > 1 )
@ -851,7 +853,8 @@ void GuiInspectorField::setHLEnabled( bool enabled )
edit->setCursorPos(0);
}
}
_executeSelectedCallback();
if (isProperlyAdded())
_executeSelectedCallback();
}
}
@ -930,6 +933,34 @@ void GuiInspectorField::_setFieldDocs( StringTableEntry docs )
else
mFieldDocs = docs;
}
String inDocs(docs);
String outDocs("");
String outLine("");
S32 newline = inDocs.find('\n');
if (newline == -1)
outDocs = docs;
else
{
U32 uCount = StringUnit::getUnitCount(inDocs, " ");
for (U32 i = 0; i < uCount; i++)
{
String docWord = StringUnit::getUnit(inDocs, i, " ");
if (!docWord.isEmpty())
outLine += docWord;
if (outLine.length() > 80)
{
outLine += "\n";
outDocs += outLine;
outLine.clear();
}
else
outLine += " ";
}
}
outDocs += String("\n") + outLine;
mTooltip = outDocs;
}
void GuiInspectorField::setHeightOverride(bool useOverride, U32 heightOverride)

View file

@ -282,7 +282,7 @@ bool GuiInspectorGroup::inspectGroup()
bGrabItems = false;
continue;
}
// Skip field if it has the HideInInspectors flag set.
if (field->flag.test(AbstractClassRep::FIELD_HideInInspectors))
@ -761,6 +761,26 @@ void GuiInspectorGroup::removeInspectorField(StringTableEntry name)
}
}
void GuiInspectorGroup::hideInspectorField(StringTableEntry fieldName, bool setHidden)
{
SimObject* inspectObj = mParent->getInspectObject();
if (inspectObj == nullptr)
return;
AbstractClassRep::Field* field = const_cast<AbstractClassRep::Field*>(inspectObj->getClassRep()->findField(fieldName));
if (field == NULL)
{
Con::errorf("fieldName not found: %s.%s", inspectObj->getName(), fieldName);
return;
}
if (setHidden)
field->flag.set(AbstractClassRep::FIELD_HideInInspectors);
else
field->flag.clear(AbstractClassRep::FIELD_HideInInspectors);
}
DefineEngineMethod(GuiInspectorGroup, createInspectorField, GuiInspectorField*, (), , "createInspectorField()")
{
return object->createInspectorField();
@ -798,6 +818,16 @@ DefineEngineMethod(GuiInspectorGroup, removeField, void, (const char* fieldName)
object->removeInspectorField(StringTable->insert(fieldName));
}
DefineEngineMethod(GuiInspectorGroup, hideField, void, (const char* fieldName, bool setHidden), (true),
"Removes a Inspector field to this group of a given name.\n"
"@param fieldName The name of the field to be removed.")
{
if (dStrEqual(fieldName, ""))
return;
object->hideInspectorField(StringTable->insert(fieldName), setHidden);
}
DefineEngineMethod(GuiInspectorGroup, setForcedArrayIndex, void, (S32 arrayIndex), (-1),
"Sets the ForcedArrayIndex for the group. Used to force presentation of arrayed fields to only show a specific field index."
"@param arrayIndex The specific field index for arrayed fields to show. Use -1 or blank arg to go back to normal behavior.")

View file

@ -86,6 +86,7 @@ public:
void addInspectorField(StringTableEntry name, StringTableEntry typeName, const char* description, const char* callbackName);
void addInspectorField(GuiInspectorField* field);
void removeInspectorField(StringTableEntry name);
void hideInspectorField(StringTableEntry fieldName, bool setHidden);
void setForcedArrayIndex(const S32& arrayIndex = -1)
{

View file

@ -92,11 +92,11 @@ void GuiFadeinBitmapCtrl::initPersistFields()
addField( "fadeColor", TypeColorF, Offset( mFadeColor, GuiFadeinBitmapCtrl ),
"Color to fade in from and fade out to." );
addField( "fadeInTime", TypeS32, Offset( mFadeInTime, GuiFadeinBitmapCtrl ),
addFieldV( "fadeInTime", TypeRangedS32, Offset( mFadeInTime, GuiFadeinBitmapCtrl ), &CommonValidators::PositiveInt,
"Milliseconds for the bitmap to fade in." );
addField( "waitTime", TypeS32, Offset( mWaitTime, GuiFadeinBitmapCtrl ),
addFieldV( "waitTime", TypeRangedS32, Offset( mWaitTime, GuiFadeinBitmapCtrl ), &CommonValidators::PositiveInt,
"Milliseconds to wait after fading in before fading out the bitmap." );
addField( "fadeOutTime", TypeS32, Offset( mFadeOutTime, GuiFadeinBitmapCtrl ),
addFieldV( "fadeOutTime", TypeRangedS32, Offset( mFadeOutTime, GuiFadeinBitmapCtrl ), &CommonValidators::PositiveInt,
"Milliseconds for the bitmap to fade out." );
addField( "fadeInEase", TypeEaseF, Offset( mFadeInEase, GuiFadeinBitmapCtrl ),
"Easing curve for fade-in." );

View file

@ -22,6 +22,7 @@
#include "platform/platform.h"
#include "gui/controls/guiBitmapCtrl.h"
#include "console/typeValidators.h"
#include "console/console.h"
#include "console/consoleTypes.h"
@ -161,8 +162,8 @@ public:
static void initPersistFields()
{
addField("fadeinTime", TypeS32, Offset(fadeinTime, GuiIdleCamFadeBitmapCtrl));
addField("fadeoutTime", TypeS32, Offset(fadeoutTime, GuiIdleCamFadeBitmapCtrl));
addFieldV("fadeinTime", TypeRangedS32, Offset(fadeinTime, GuiIdleCamFadeBitmapCtrl), &CommonValidators::PositiveInt);
addFieldV("fadeoutTime", TypeRangedS32, Offset(fadeoutTime, GuiIdleCamFadeBitmapCtrl), &CommonValidators::PositiveInt);
addField("done", TypeBool, Offset(done, GuiIdleCamFadeBitmapCtrl));
Parent::initPersistFields();
}

View file

@ -22,6 +22,7 @@
#include "platform/platform.h"
#include "gui/game/guiMessageVectorCtrl.h"
#include "console/typeValidators.h"
#include "gui/utility/messageVector.h"
#include "console/consoleTypes.h"
@ -193,11 +194,11 @@ GuiMessageVectorCtrl::~GuiMessageVectorCtrl()
void GuiMessageVectorCtrl::initPersistFields()
{
docsURL;
addField("lineSpacing", TypeS32, Offset(mLineSpacingPixels, GuiMessageVectorCtrl));
addField("lineContinuedIndex", TypeS32, Offset(mLineContinuationIndent, GuiMessageVectorCtrl));
addFieldV("lineSpacing", TypeRangedS32, Offset(mLineSpacingPixels, GuiMessageVectorCtrl), &CommonValidators::PositiveInt);
addFieldV("lineContinuedIndex", TypeRangedS32, Offset(mLineContinuationIndent, GuiMessageVectorCtrl), &CommonValidators::PositiveInt);
addField("allowedMatches", TypeString, Offset(mAllowedMatches, GuiMessageVectorCtrl), 16);
addField("matchColor", TypeColorI, Offset(mSpecialColor, GuiMessageVectorCtrl));
addField("maxColorIndex", TypeS32, Offset(mMaxColorIndex, GuiMessageVectorCtrl));
addFieldV("maxColorIndex", TypeRangedS32, Offset(mMaxColorIndex, GuiMessageVectorCtrl), &CommonValidators::S32_8BitCap);
Parent::initPersistFields();
}

View file

@ -88,7 +88,7 @@ void GuiShaderEditor::initPersistFields()
{
docsURL;
addGroup("Node Settings");
addFieldV("nodeSize", TypeS32, Offset(mNodeSize, GuiShaderEditor),&nodeSizeRange,
addFieldV("nodeSize", TypeRangedS32, Offset(mNodeSize, GuiShaderEditor),&nodeSizeRange,
"Size of nodes.");
endGroup("Node Settings");

View file

@ -26,6 +26,7 @@
#include "sfx/sfxTrack.h"
#include "sfx/sfxSource.h"
#include "sfx/sfxTypes.h"
#include "console/typeValidators.h"
#define TickMs 32
@ -116,7 +117,7 @@ void GuiAudioCtrl::initPersistFields()
{
addGroup("Sounds");
INITPERSISTFIELD_SOUNDASSET(Sound, GuiAudioCtrl, "Looping SoundAsset to play while GuiAudioCtrl is active.");
addField("tickPeriodMS", TypeS32, Offset(mTickPeriodMS, GuiAudioCtrl),
addFieldV("tickPeriodMS", TypeRangedS32, Offset(mTickPeriodMS, GuiAudioCtrl), &CommonValidators::MSTickRange,
"@brief Time in milliseconds between calls to onTick().\n\n"
"@see onTickTrigger()\n");
addField("playIf", TypeCommand, Offset(mPlayIf, GuiAudioCtrl), "evaluation condition to trip playback (true/false)");
@ -127,19 +128,19 @@ void GuiAudioCtrl::initPersistFields()
"The SFXSource to which to assign the sound of this emitter as a child.\n"
"@note This field is ignored if #useTrackDescriptionOnly is true.\n\n"
"@see SFXDescription::sourceGroup");
addField("volume", TypeF32, Offset(mVolume, GuiAudioCtrl),
addFieldV("volume", TypeRangedF32, Offset(mVolume, GuiAudioCtrl), &CommonValidators::PositiveFloat,
"Volume level to apply to the sound.\n"
"@note This field is ignored if #useTrackDescriptionOnly is true.\n\n"
"@see SFXDescription::volume");
addField("pitch", TypeF32, Offset(mPitch, GuiAudioCtrl),
addFieldV("pitch", TypeRangedF32, Offset(mPitch, GuiAudioCtrl), &CommonValidators::PositiveFloat,
"Pitch shift to apply to the sound. Default is 1 = play at normal speed.\n"
"@note This field is ignored if #useTrackDescriptionOnly is true.\n\n"
"@see SFXDescription::pitch");
addField("fadeInTime", TypeF32, Offset(mFadeInTime, GuiAudioCtrl),
addFieldV("fadeInTime", TypeRangedF32, Offset(mFadeInTime, GuiAudioCtrl), &CommonValidators::PositiveFloat,
"Number of seconds to gradually fade in volume from zero when playback starts.\n"
"@note This field is ignored if #useTrackDescriptionOnly is true.\n\n"
"@see SFXDescription::fadeInTime");
addField("fadeOutTime", TypeF32, Offset(mFadeOutTime, GuiAudioCtrl),
addFieldV("fadeOutTime", TypeRangedF32, Offset(mFadeOutTime, GuiAudioCtrl), &CommonValidators::PositiveFloat,
"Number of seconds to gradually fade out volume down to zero when playback is stopped or paused.\n"
"@note This field is ignored if #useTrackDescriptionOnly is true.\n\n"
"@see SFXDescription::fadeOutTime");
@ -184,6 +185,8 @@ void GuiAudioCtrl::_update()
mSoundPlaying->setFadeTimes(mFadeInTime, mFadeOutTime);
}
else
getSoundDescription()->mSourceGroup->addObject(mSoundPlaying);
mSoundPlaying->play();
}

View file

@ -37,6 +37,7 @@
#include "scene/sceneManager.h"
#include "scene/sceneRenderState.h"
#include "renderInstance/renderBinManager.h"
#include "console/typeValidators.h"
#include "T3D/Scene.h"
@ -238,7 +239,7 @@ void EditTSCtrl::initPersistFields()
addField("renderMissionArea", TypeBool, Offset(mRenderMissionArea, EditTSCtrl));
addField("missionAreaFillColor", TypeColorI, Offset(mMissionAreaFillColor, EditTSCtrl));
addField("missionAreaFrameColor", TypeColorI, Offset(mMissionAreaFrameColor, EditTSCtrl));
addField("missionAreaHeightAdjust", TypeF32, Offset(mMissionAreaHeightAdjust, EditTSCtrl),
addFieldV("missionAreaHeightAdjust", TypeRangedF32, Offset(mMissionAreaHeightAdjust, EditTSCtrl), &CommonValidators::PositiveFloat,
"How high above and below the terrain to render the mission area bounds." );
endGroup("Mission Area");
@ -246,8 +247,8 @@ void EditTSCtrl::initPersistFields()
addGroup("BorderMovement");
addField("allowBorderMove", TypeBool, Offset(mAllowBorderMove, EditTSCtrl));
addField("borderMovePixelSize", TypeS32, Offset(mMouseMoveBorder, EditTSCtrl));
addField("borderMoveSpeed", TypeF32, Offset(mMouseMoveSpeed, EditTSCtrl));
addFieldV("borderMovePixelSize", TypeRangedS32, Offset(mMouseMoveBorder, EditTSCtrl), &CommonValidators::PositiveInt);
addFieldV("borderMoveSpeed", TypeRangedF32, Offset(mMouseMoveSpeed, EditTSCtrl), &CommonValidators::PositiveFloat);
endGroup("BorderMovement");
@ -255,9 +256,9 @@ void EditTSCtrl::initPersistFields()
addField("consoleFrameColor", TypeColorI, Offset(mConsoleFrameColor, EditTSCtrl));
addField("consoleFillColor", TypeColorI, Offset(mConsoleFillColor, EditTSCtrl));
addField("consoleSphereLevel", TypeS32, Offset(mConsoleSphereLevel, EditTSCtrl));
addField("consoleCircleSegments", TypeS32, Offset(mConsoleCircleSegments, EditTSCtrl));
addField("consoleLineWidth", TypeS32, Offset(mConsoleLineWidth, EditTSCtrl));
addFieldV("consoleSphereLevel", TypeRangedS32, Offset(mConsoleSphereLevel, EditTSCtrl), &CommonValidators::NaturalNumber);
addFieldV("consoleCircleSegments", TypeRangedS32, Offset(mConsoleCircleSegments, EditTSCtrl), &CommonValidators::NaturalNumber);
addFieldV("consoleLineWidth", TypeRangedS32, Offset(mConsoleLineWidth, EditTSCtrl), &CommonValidators::NaturalNumber);
addField("gizmoProfile", TYPEID< GizmoProfile >(), Offset(mGizmoProfile, EditTSCtrl));
endGroup("Misc");

View file

@ -26,6 +26,7 @@
#include "gui/core/guiCanvas.h"
TerrainScratchPad gTerrainScratchPad;
//------------------------------------------------------------------------------
bool TerrainAction::isValid(GridInfo tile)
{
@ -746,60 +747,212 @@ void PaintNoiseAction::process(Selection * sel, const Gui3DMouseEvent &, bool se
mTerrainEditor->scheduleGridUpdate();
}
}
/*
void ThermalErosionAction::process(Selection * sel, const Gui3DMouseEvent &, bool selChanged, Type)
void ThermalErosionAction::process(Selection * sel, const Gui3DMouseEvent &, bool selChanged, Type type)
{
if( selChanged )
// If this is the ending
// mouse down event, then
// update the noise values.
TerrainBlock* tblock = mTerrainEditor->getActiveTerrain();
if (!tblock)
return;
F32 selRange = sel->getMaxHeight()-sel->getMinHeight();
F32 avg = sel->getAvgHeight();
if (selChanged)
{
TerrainBlock *tblock = mTerrainEditor->getActiveTerrain();
if ( !tblock )
return;
F32 height = 0;
F32 maxHeight = 0;
U32 shift = getBinLog2( TerrainBlock::BlockSize );
for ( U32 x = 0; x < TerrainBlock::BlockSize; x++ )
{
for ( U32 y = 0; y < TerrainBlock::BlockSize; y++ )
{
height = fixedToFloat( tblock->getHeight( x, y ) );
mTerrainHeights[ x + (y << 8)] = height;
if ( height > maxHeight )
maxHeight = height;
}
}
//mNoise.erodeThermal( &mTerrainHeights, &mNoiseData, 30.0f, 5.0f, 5, TerrainBlock::BlockSize, tblock->getSquareSize(), maxHeight );
mNoise.erodeHydraulic( &mTerrainHeights, &mNoiseData, 1, TerrainBlock::BlockSize );
F32 heightDiff = 0;
for( U32 i = 0; i < sel->size(); i++ )
for (U32 i = 0; i < sel->size(); i++)
{
if (!isValid((*sel)[i]))
continue;
mTerrainEditor->getUndoSel()->add((*sel)[i]);
const Point2I &gridPos = (*sel)[i].mGridPoint.gridPos;
// Need to get the height difference
// between the current height and the
// erosion height to properly apply the
// softness and pressure settings of the brush
// for this selection.
heightDiff = (*sel)[i].mHeight - mNoiseData[ gridPos.x + (gridPos.y << shift)];
F32 bias = ((*sel)[i].mHeight - avg) / selRange;
F32 nudge = mRandF(-mTerrainEditor->getBrushPressure(), mTerrainEditor->getBrushPressure());
F32 heightTarg = mRoundF((*sel)[i].mHeight - bias * nudge, mTerrainEditor->getBrushPressure() * 2.0f) ;
heightDiff = heightTarg - (*sel)[i].mHeight;
(*sel)[i].mHeight += heightDiff * (*sel)[i].mWeight;
(*sel)[i].mHeight -= (heightDiff * (*sel)[i].mWeight);
if ((*sel)[i].mHeight > mTerrainEditor->mTileMaxHeight)
(*sel)[i].mHeight = mTerrainEditor->mTileMaxHeight;
if ((*sel)[i].mHeight < mTerrainEditor->mTileMinHeight)
(*sel)[i].mHeight = mTerrainEditor->mTileMinHeight;
mTerrainEditor->setGridInfo((*sel)[i]);
}
mTerrainEditor->gridUpdateComplete();
mTerrainEditor->scheduleGridUpdate();
}
}
*/
void HydraulicErosionAction::process(Selection* sel, const Gui3DMouseEvent&, bool selChanged, Type type)
{
// If this is the ending
// mouse down event, then
// update the noise values.
TerrainBlock* tblock = mTerrainEditor->getActiveTerrain();
if (!tblock)
return;
F32 selRange = sel->getMaxHeight() - sel->getMinHeight();
F32 avg = sel->getAvgHeight();
if (selChanged)
{
F32 heightDiff = 0;
const F32 squareSize = tblock->getSquareSize();
for (U32 i = 0; i < sel->size(); i++)
{
if (!isValid((*sel)[i]))
continue;
mTerrainEditor->getUndoSel()->add((*sel)[i]);
Point2F p;
Point3F norm;
p.x = (*sel)[i].mGridPoint.gridPos.x * squareSize;
p.y = (*sel)[i].mGridPoint.gridPos.y * squareSize;
tblock->getNormal(p, &norm, true);
F32 bias = mPow(norm.z,3.0f) * ((*sel)[i].mHeight - avg) / selRange;
F32 nudge = mRandF(-mTerrainEditor->getBrushPressure(), mTerrainEditor->getBrushPressure());
heightDiff = bias * (-(*sel)[i].mHeight + bias * nudge) / tblock->getObjBox().len_z() * 2.0;
(*sel)[i].mHeight += heightDiff * (*sel)[i].mWeight;
if ((*sel)[i].mHeight > mTerrainEditor->mTileMaxHeight)
(*sel)[i].mHeight = mTerrainEditor->mTileMaxHeight;
if ((*sel)[i].mHeight < mTerrainEditor->mTileMinHeight)
(*sel)[i].mHeight = mTerrainEditor->mTileMinHeight;
mTerrainEditor->setGridInfo((*sel)[i]);
}
mTerrainEditor->scheduleGridUpdate();
}
}
void TerrainScratchPad::addTile(F32 height, U8 material)
{
mContents.push_back(new gridStub(height, material));
mBottom = mMin(height, mBottom);
mTop = mMax(height, mTop);
};
void TerrainScratchPad::clear()
{
for (U32 i = 0; i < mContents.size(); i++)
delete(mContents[i]);
mContents.clear();
mBottom = F32_MAX;
mTop = F32_MIN_EX;
}
void copyAction::process(Selection* sel, const Gui3DMouseEvent&, bool selChanged, Type type)
{
gTerrainScratchPad.clear();
for (U32 i=0;i<sel->size();i++)
{
if (isValid((*sel)[i]))
gTerrainScratchPad.addTile((*sel)[i].mHeight, (*sel)[i].mMaterial);
else
gTerrainScratchPad.addTile(0, 0);
}
}
void pasteAction::process(Selection* sel, const Gui3DMouseEvent&, bool selChanged, Type type)
{
if (gTerrainScratchPad.size() == 0)
return;
if (gTerrainScratchPad.size() != sel->size())
return;
if (type != Begin)
return;
for (U32 i = 0; i < sel->size(); i++)
{
if (isValid((*sel)[i]))
{
mTerrainEditor->getUndoSel()->add((*sel)[i]);
(*sel)[i].mHeight = gTerrainScratchPad[i]->mHeight;
(*sel)[i].mMaterial = gTerrainScratchPad[i]->mMaterial;
mTerrainEditor->setGridInfo((*sel)[i]);
}
}
mTerrainEditor->scheduleGridUpdate();
mTerrainEditor->scheduleMaterialUpdate();
}
void pasteUpAction::process(Selection* sel, const Gui3DMouseEvent&, bool selChanged, Type type)
{
if (gTerrainScratchPad.size() == 0)
return;
if (gTerrainScratchPad.size() != sel->size())
return;
if (type != Begin)
return;
F32 floor = F32_MAX;
for (U32 i = 0; i < sel->size(); i++)
{
floor = mMin((*sel)[i].mHeight, floor);
}
for (U32 i = 0; i < sel->size(); i++)
{
if (isValid((*sel)[i]))
{
mTerrainEditor->getUndoSel()->add((*sel)[i]);
(*sel)[i].mHeight = gTerrainScratchPad[i]->mHeight - gTerrainScratchPad.mBottom + floor;
(*sel)[i].mMaterial = gTerrainScratchPad[i]->mMaterial;
mTerrainEditor->setGridInfo((*sel)[i]);
}
}
mTerrainEditor->scheduleGridUpdate();
mTerrainEditor->scheduleMaterialUpdate();
}
void pasteDownAction::process(Selection* sel, const Gui3DMouseEvent&, bool selChanged, Type type)
{
if (gTerrainScratchPad.size() == 0)
return;
if (gTerrainScratchPad.size() != sel->size())
return;
if (type != Begin)
return;
F32 ceiling = F32_MIN_EX;
for (U32 i = 0; i < sel->size(); i++)
{
ceiling = mMax((*sel)[i].mHeight, ceiling);
}
for (U32 i = 0; i < sel->size(); i++)
{
if (isValid((*sel)[i]))
{
mTerrainEditor->getUndoSel()->add((*sel)[i]);
(*sel)[i].mHeight = gTerrainScratchPad[i]->mHeight - gTerrainScratchPad.mTop + ceiling;
(*sel)[i].mMaterial = gTerrainScratchPad[i]->mMaterial;
mTerrainEditor->setGridInfo((*sel)[i]);
}
}
mTerrainEditor->scheduleGridUpdate();
mTerrainEditor->scheduleMaterialUpdate();
}
IMPLEMENT_CONOBJECT( TerrainSmoothAction );

View file

@ -302,27 +302,94 @@ class PaintNoiseAction : public TerrainAction
F32 mScale;
};
/*
class ThermalErosionAction : public TerrainAction
{
public:
ThermalErosionAction(TerrainEditor * editor)
: TerrainAction(editor)
{
mNoise.setSeed( 1 );//Sim::getCurrentTime() );
mNoiseData.setSize( TerrainBlock::BlockSize * TerrainBlock::BlockSize );
mTerrainHeights.setSize( TerrainBlock::BlockSize * TerrainBlock::BlockSize );
}
}
StringTableEntry getName(){return("thermalErode");}
void process(Selection * sel, const Gui3DMouseEvent & event, bool selChanged, Type type);
Noise2D mNoise;
Vector<F32> mNoiseData;
Vector<F32> mTerrainHeights;
};
*/
class HydraulicErosionAction : public TerrainAction
{
public:
HydraulicErosionAction(TerrainEditor* editor)
: TerrainAction(editor)
{
}
StringTableEntry getName() { return("hydraulicErode"); }
void process(Selection* sel, const Gui3DMouseEvent& event, bool selChanged, Type type);
};
class TerrainScratchPad
{
public:
F32 mBottom, mTop;
TerrainScratchPad(): mBottom(F32_MAX), mTop(F32_MIN_EX){};
~TerrainScratchPad() { mContents.clear(); };
void clear();
class gridStub
{
public:
gridStub(F32 height, U8 material) : mHeight(height), mMaterial(material) {};
F32 mHeight;
U8 mMaterial;
};
void addTile(F32 height, U8 material);
U32 size() { return(mContents.size()); };
gridStub* operator [](U32 index) { return mContents[index]; };
private:
Vector<gridStub*> mContents;
};
class copyAction : public TerrainAction
{
public:
copyAction(TerrainEditor* editor)
: TerrainAction(editor)
{
}
StringTableEntry getName() { return("copy"); }
void process(Selection* sel, const Gui3DMouseEvent& event, bool selChanged, Type type);
};
class pasteAction : public TerrainAction
{
public:
pasteAction(TerrainEditor* editor)
: TerrainAction(editor)
{
}
StringTableEntry getName() { return("paste"); }
void process(Selection* sel, const Gui3DMouseEvent& event, bool selChanged, Type type);
};
class pasteUpAction : public TerrainAction
{
public:
pasteUpAction(TerrainEditor* editor)
: TerrainAction(editor)
{
}
StringTableEntry getName() { return("pasteUp"); }
void process(Selection* sel, const Gui3DMouseEvent& event, bool selChanged, Type type);
};
class pasteDownAction : public TerrainAction
{
public:
pasteDownAction(TerrainEditor* editor)
: TerrainAction(editor)
{
}
StringTableEntry getName() { return("pasteDown"); }
void process(Selection* sel, const Gui3DMouseEvent& event, bool selChanged, Type type);
};
/// An undo action used to perform terrain wide smoothing.
class TerrainSmoothAction : public UndoAction

View file

@ -712,8 +712,13 @@ TerrainEditor::TerrainEditor() :
mActions.push_back(new SmoothHeightAction(this));
mActions.push_back(new SmoothSlopeAction(this));
mActions.push_back(new PaintNoiseAction(this));
//mActions.push_back(new ThermalErosionAction(this));
mActions.push_back(new ThermalErosionAction(this));
mActions.push_back(new HydraulicErosionAction(this));
mActions.push_back(new copyAction(this));
mActions.push_back(new pasteAction(this));
mActions.push_back(new pasteUpAction(this));
mActions.push_back(new pasteDownAction(this));
// set the default action
mCurrentAction = mActions[0];

View file

@ -2464,7 +2464,7 @@ static void findDragMeshCallback( SceneObject *obj, void *data )
if ( dragData->mWorldEditor->objClassIgnored( obj ) ||
!obj->isSelectionEnabled() ||
obj->getTypeMask() & ( TerrainObjectType | ProjectileObjectType ) ||
dynamic_cast< GroundPlane* >( obj ) ||
dynamic_cast< GroundPlane* >( obj ) || dynamic_cast<SubScene*>(obj) ||
Prefab::getPrefabByChild( obj ) )
{
return;