Ver Fonte

Update to GuiProgressCtrl

Added smooth animations and support for Advanced Profiles.
Peter Robinson há 4 anos atrás
pai
commit
7f3fd749f4

+ 1 - 0
engine/compilers/VisualStudio 2017/Torque 2D.vcxproj

@@ -1175,6 +1175,7 @@
     <ClInclude Include="..\..\source\gui\guiPopUpCtrl.h" />
     <ClInclude Include="..\..\source\gui\guiPopUpCtrl.h" />
     <ClInclude Include="..\..\source\gui\guiPopUpCtrlEx.h" />
     <ClInclude Include="..\..\source\gui\guiPopUpCtrlEx.h" />
     <ClInclude Include="..\..\source\gui\guiProgressCtrl.h" />
     <ClInclude Include="..\..\source\gui\guiProgressCtrl.h" />
+    <ClInclude Include="..\..\source\gui\guiProgressCtrl_ScriptBinding.h" />
     <ClInclude Include="..\..\source\gui\guiSliderCtrl.h" />
     <ClInclude Include="..\..\source\gui\guiSliderCtrl.h" />
     <ClInclude Include="..\..\source\gui\guiTextEditCtrl.h" />
     <ClInclude Include="..\..\source\gui\guiTextEditCtrl.h" />
     <ClInclude Include="..\..\source\gui\guiTextEditSliderCtrl.h" />
     <ClInclude Include="..\..\source\gui\guiTextEditSliderCtrl.h" />

+ 3 - 0
engine/compilers/VisualStudio 2017/Torque 2D.vcxproj.filters

@@ -3328,6 +3328,9 @@
     <ClInclude Include="..\..\source\gui\containers\guiDragAndDropCtrl_ScriptBinding.h">
     <ClInclude Include="..\..\source\gui\containers\guiDragAndDropCtrl_ScriptBinding.h">
       <Filter>gui\containers</Filter>
       <Filter>gui\containers</Filter>
     </ClInclude>
     </ClInclude>
+    <ClInclude Include="..\..\source\gui\guiProgressCtrl_ScriptBinding.h">
+      <Filter>gui</Filter>
+    </ClInclude>
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="Torque 2D.rc" />
     <ResourceCompile Include="Torque 2D.rc" />

+ 1 - 1
engine/source/gui/containers/guiExpandCtrl.cc

@@ -185,4 +185,4 @@ void GuiExpandCtrl::processTick()
 	{
 	{
 		setProcessTicks(false);
 		setProcessTicks(false);
 	}
 	}
-};
+}

+ 1 - 1
engine/source/gui/guiControl_ScriptBinding.h

@@ -108,7 +108,7 @@ ConsoleMethodWithDocs( GuiControl, getValue, ConsoleString, 2, 2, ())
 }
 }
 
 
 /*! Use the setActive method to (de)activate this control. Once active, a control can accept inputs. Controls automatically re-shade/skin themselves to reflect their active/inactive state.
 /*! Use the setActive method to (de)activate this control. Once active, a control can accept inputs. Controls automatically re-shade/skin themselves to reflect their active/inactive state.
-    @param isActive A boolean value. f isActive is true, this control is activated, else it is set to inactive.
+    @param isActive A boolean value. If isActive is true, this control is activated, else it is set to inactive.
     @return No return value
     @return No return value
 */
 */
 ConsoleMethodWithDocs( GuiControl, setActive, ConsoleVoid, 3, 3, ( isActive ))
 ConsoleMethodWithDocs( GuiControl, setActive, ConsoleVoid, 3, 3, ( isActive ))

+ 100 - 33
engine/source/gui/guiProgressCtrl.cc

@@ -23,70 +23,137 @@
 #include "console/console.h"
 #include "console/console.h"
 #include "console/consoleTypes.h"
 #include "console/consoleTypes.h"
 #include "graphics/dgl.h"
 #include "graphics/dgl.h"
+#include "gui/guiDefaultControlRender.h"
 
 
 #include "gui/guiProgressCtrl.h"
 #include "gui/guiProgressCtrl.h"
 
 
+#include "gui/guiProgressCtrl_ScriptBinding.h"
+
 IMPLEMENT_CONOBJECT(GuiProgressCtrl);
 IMPLEMENT_CONOBJECT(GuiProgressCtrl);
 
 
 GuiProgressCtrl::GuiProgressCtrl()
 GuiProgressCtrl::GuiProgressCtrl()
 {
 {
-   mProgress = 0.0f;
+   mCurrent = 0.0f;
+   mStart = 0.0f;
+   mEnd = 0.0f;
+
+   setAnimationLength(250);
+   setEasingFunction(EaseInOut);
+
+   setField("profile", "GuiProgressProfile");
+}
+
+void GuiProgressCtrl::initPersistFields()
+{
+	Parent::initPersistFields();
+
+	addField("animationTime", TypeS32, Offset(mAnimationLength, GuiProgressCtrl));
 }
 }
 
 
 const char* GuiProgressCtrl::getScriptValue()
 const char* GuiProgressCtrl::getScriptValue()
 {
 {
    char * ret = Con::getReturnBuffer(64);
    char * ret = Con::getReturnBuffer(64);
-   dSprintf(ret, 64, "%g", mProgress);
+   dSprintf(ret, 64, "%g", mCurrent);
    return ret;
    return ret;
 }
 }
 
 
 void GuiProgressCtrl::setScriptValue(const char *value)
 void GuiProgressCtrl::setScriptValue(const char *value)
 {
 {
    //set the value
    //set the value
-   if (! value)
-      mProgress = 0.0f;
-   else
-      mProgress = dAtof(value);
+   F32 target = 0.0f;
+   if (value)
+	   target = dAtof(value);
 
 
-   //validate the value
-   mProgress = mClampF(mProgress, 0.f, 1.f);
-   setUpdate();
+	setCurrentProgress(target);
 }
 }
 
 
-void GuiProgressCtrl::onPreRender()
+void GuiProgressCtrl::setCurrentProgress(F32 target)
 {
 {
-   const char * var = getVariable();
-   if(var)
+	setCurrentProgress(target, mAnimationLength);
+}
+
+void GuiProgressCtrl::setCurrentProgress(F32 target, S32 time)
+{
+	mAnimationLength = time;
+
+   //validate the value
+   target = mClampF(target, 0.f, 1.f);
+
+   if (target != mCurrent)
    {
    {
-      F32 value = mClampF(dAtof(var), 0.f, 1.f);
-      if(value != mProgress)
-      {
-         mProgress = value;
-         setUpdate();
-      }
+		mStart = mCurrent;
+		mEnd = target;
+		startFluidAnimation();
+		setProcessTicks(true);
    }
    }
+
+   setUpdate();
+}
+
+void GuiProgressCtrl::resetProgress()
+{
+	setCurrentProgress(0.0f);
 }
 }
 
 
 void GuiProgressCtrl::onRender(Point2I offset, const RectI &updateRect)
 void GuiProgressCtrl::onRender(Point2I offset, const RectI &updateRect)
 {
 {
-   RectI ctrlRect(offset, mBounds.extent);
+	//Render the background box
+	RectI backRect = applyMargins(offset, mBounds.extent, NormalState, mProfile);
+	renderUniversalRect(backRect, mProfile, NormalState);
 
 
-   //draw the progress
-   S32 width = (S32)((F32)mBounds.extent.x * mProgress);
-   if (width > 0)
-   {
-      RectI progressRect = ctrlRect;
-      progressRect.extent.x = width;
-      dglDrawRectFill(progressRect, mProfile->mFillColor);
-   }
+	if (mCurrent == 0.0f)
+	{
+		return;
+	}
+
+	GuiControlState currentState = SelectedState;
+	if(mCurrent < 1.0f)
+	{
+		currentState = HighlightState;
+	}
+
+	//Render the progress bar
+	RectI ctrlRect = applyMargins(offset, mBounds.extent, currentState, mProfile);
+	ctrlRect.extent.x = ctrlRect.extent.x * mCurrent;
+	renderUniversalRect(ctrlRect, mProfile, currentState);
+
+	//Render Text
+	dglSetBitmapModulation(mProfile->getFontColor(currentState));
+	RectI fillRect = applyBorders(ctrlRect.point, ctrlRect.extent, currentState, mProfile);
+	RectI contentRect = applyPadding(fillRect.point, fillRect.extent, currentState, mProfile);
 
 
-   //now draw the border
-   if (mProfile->mBorderDefault && *mProfile->mBorderDefault->mBorder > 0)
-      dglDrawRect(ctrlRect, mProfile->mBorderDefault->mBorderColor[0]);
+	if (contentRect.isValidRect())
+	{
+		renderText(contentRect.point, contentRect.extent, mText, mProfile);
+	}
+}
+
+void GuiProgressCtrl::processTick()
+{
+	bool shouldWeContinue = false;
+
+	//Expanding
+	shouldWeContinue |= animateProgressBar();
+
+	if (!shouldWeContinue)
+	{
+		setProcessTicks(false);
+	}
+}
+
+bool GuiProgressCtrl::animateProgressBar()
+{
+	F32 progress = getProgress(32.0f);
 
 
-   Parent::onRender( offset, updateRect );
+	setUpdate();
+	mCurrent = processValue(progress, mStart, mEnd);
 
 
-   //render the children
-   renderChildControls(offset, mBounds, updateRect);
+	if (mAnimationProgress >= 1.0f)
+	{
+		mAnimationProgress = 1.0f;
+		return false;
+	}
+	return true;
 }
 }
+	
 
 

+ 16 - 4
engine/source/gui/guiProgressCtrl.h

@@ -32,24 +32,36 @@
 #endif
 #endif
 
 
 
 
-class GuiProgressCtrl : public GuiControl
+class GuiProgressCtrl : public GuiControl, public Fluid
 {
 {
 private:
 private:
    typedef GuiControl Parent;
    typedef GuiControl Parent;
 
 
-   F32 mProgress;
+   F32 mCurrent;
+   F32 mStart;
+   F32 mEnd;
 
 
 public:
 public:
    //creation methods
    //creation methods
    DECLARE_CONOBJECT(GuiProgressCtrl);
    DECLARE_CONOBJECT(GuiProgressCtrl);
    GuiProgressCtrl();
    GuiProgressCtrl();
+   static void initPersistFields();
 
 
-   //console related methods
+   //these methods are here for backwards compatability
    virtual const char *getScriptValue();
    virtual const char *getScriptValue();
    virtual void setScriptValue(const char *value);
    virtual void setScriptValue(const char *value);
 
 
-   void onPreRender();
+   void setCurrentProgress(F32 target);
+   void setCurrentProgress(F32 target, S32 time);
+   void resetProgress();
+   inline F32 getCurrentProgress() { return mEnd; }
+   inline F32 getDisplayedProgress() { return mCurrent; }
+
    void onRender(Point2I offset, const RectI &updateRect);
    void onRender(Point2I offset, const RectI &updateRect);
+
+protected:
+	virtual void processTick();
+	bool animateProgressBar();
 };
 };
 
 
 #endif
 #endif

+ 94 - 0
engine/source/gui/guiProgressCtrl_ScriptBinding.h

@@ -0,0 +1,94 @@
+//-----------------------------------------------------------------------------
+// Copyright (c) 2013 GarageGames, LLC
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+//-----------------------------------------------------------------------------
+
+ConsoleMethodGroupBeginWithDocs(GuiProgressCtrl, GuiControl)
+
+/*! Sets the current progress. The smoothly animate to the given progress over the optional time or previously used time.
+	@param progress The updated progress of the progress bar as a decimal value between 0 and 1.
+	@param time The optional time in milliseconds it will take to animate from the progress bar's current position to the updated one.
+	@return No return value.
+*/
+ConsoleMethodWithDocs(GuiProgressCtrl, setProgress, ConsoleVoid, 3, 4, "( F32 progress, [S32 time] )")
+{
+	if (argc == 3)
+	{
+		object->setCurrentProgress(dAtof(argv[2]));
+	}
+	else if (argc == 4)
+	{
+		object->setCurrentProgress(dAtof(argv[2]), dAtoi(argv[3]));
+	}
+	else
+	{
+		Con::warnf("GuiProgressCtrl::setProgress() - Wrong number of parameters!");
+	}
+}
+
+/*! Returns the current progress.
+	@return The progress as a decimal value between 0 and 1.
+*/
+ConsoleMethodWithDocs(GuiProgressCtrl, getProgress, ConsoleFloat, 2, 2, "()")
+{
+	return object->getCurrentProgress();
+}
+
+/*! Returns the currently displayed progress. This may be differnt if the animation to the most recently set progress is still running.
+	@return The displayed progress as a decimal value between 0 and 1.
+*/
+ConsoleMethodWithDocs(GuiProgressCtrl, getDisplayProgress, ConsoleFloat, 2, 2, "()")
+{
+	return object->getDisplayedProgress();
+}
+
+/*! Sets the progress bar back to the start.
+	@return No return value.
+*/
+ConsoleMethodWithDocs(GuiProgressCtrl, resetProgress, ConsoleVoid, 2, 2, "()")
+{
+	return object->resetProgress();
+}
+
+/*! Sets the amount of time in milliseconds that it will take to animate each time the progress is updated.
+	@param time The animation time in milliseconds.
+	@return No return value.
+*/
+ConsoleMethodWithDocs(GuiProgressCtrl, setAnimationTime, ConsoleVoid, 3, 3, "( S32 time )")
+{
+	if (argc == 3)
+	{
+		object->setAnimationLength(dAtoi(argv[2]));
+	}
+	else
+	{
+		Con::warnf("GuiProgressCtrl::setAnimationTime() - Wrong number of parameters!");
+	}
+}
+
+/*! Gets the time it takes in milliseconds for the progress bar to animate to its set progress.
+	@return No return value.
+*/
+ConsoleMethodWithDocs(GuiProgressCtrl, getAnimationTime, ConsoleInt, 2, 2, "()")
+{
+	return object->getAnimationLength();
+}
+
+ConsoleMethodGroupEndWithDocs(GuiProgressCtrl)

+ 39 - 0
toybox/Sandbox/1/gui/guiProfiles.cs

@@ -737,3 +737,42 @@ if(!isObject(GuiDragAndDropProfile)) new GuiControlProfile (GuiDragAndDropProfil
    fillColor = SetColorAlpha($color4, 50);
    fillColor = SetColorAlpha($color4, 50);
    fontColor = $color5;
    fontColor = $color5;
 };
 };
+
+if (!isObject(GuiProgressBorderProfile)) new GuiBorderProfile (GuiProgressBorderProfile : GuiDefaultBorderProfile)
+{
+	padding = 2;
+	paddingHL = 0;
+	paddingSL = 0;
+
+	border = 2;
+	borderHL = 2;
+	borderSL = 2;
+
+	margin = 0;
+	marginHL = 3;
+	marginSL = 3;
+
+	borderColor = AdjustColorValue($color1, -10);
+	borderColorHL = "255 255 255 50";
+	borderColorSL = "255 255 255 50";
+};
+
+if (!isObject(GuiProgressDarkBorderProfile)) new GuiBorderProfile (GuiProgressDarkBorderProfile : GuiProgressBorderProfile)
+{
+	borderColorHL = "0 0 0 50";
+	borderColorSL = "0 0 0 50";
+};
+
+if(!isObject(GuiProgressProfile)) new GuiControlProfile (GuiProgressProfile : GuiDefaultProfile)
+{
+   fillColor = $color1;
+   fillColorHL = $color4;
+   fillColorSL = AdjustColorValue($color4, 10);
+
+   fontColorHL = $color3;
+   fontColorSL = $color5;
+
+   borderDefault = GuiProgressBorderProfile;
+   borderBottom = GuiProgressDarkBorderProfile;
+   borderRight = GuiProgressDarkBorderProfile;
+};