Torque3D Documentation / _generateds / guiEaseViewCtrl.cpp

guiEaseViewCtrl.cpp

Engine/source/gui/editor/guiEaseViewCtrl.cpp

More...

Public Functions

ConsoleDocClass(GuiEaseViewCtrl , "@brief Control <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> visualize an <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">EaseF.\n\n</a>" "Editor use <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">only.\n\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">EaseF\n\n</a>" "@internal" )

Detailed Description

Public Functions

ConsoleDocClass(GuiEaseViewCtrl , "@brief Control <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> visualize an <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">EaseF.\n\n</a>" "Editor use <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">only.\n\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">EaseF\n\n</a>" "@internal" )

IMPLEMENT_CONOBJECT(GuiEaseViewCtrl )

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#include "gui/editor/guiEaseViewCtrl.h"
 25#include "console/consoleTypes.h"
 26#include "math/mMath.h"
 27#include "gfx/gfxDrawUtil.h"
 28
 29
 30IMPLEMENT_CONOBJECT( GuiEaseViewCtrl );
 31
 32ConsoleDocClass( GuiEaseViewCtrl,
 33   "@brief Control to visualize an EaseF.\n\n"
 34   "Editor use only.\n\n"
 35   "@see EaseF\n\n"
 36   "@internal"
 37);
 38
 39//-----------------------------------------------------------------------------
 40
 41GuiEaseViewCtrl::GuiEaseViewCtrl()
 42{
 43   mEase.set(Ease::In, Ease::Cubic);
 44   mAxisColor.set(1,1,1,1);
 45   mEaseColor.set(1,1,1,1);
 46   mEaseWidth = 4.0f;
 47}
 48
 49//-----------------------------------------------------------------------------
 50
 51void GuiEaseViewCtrl::initPersistFields()
 52{
 53   Parent::initPersistFields();
 54
 55   addField("ease", TypeEaseF, Offset( mEase, GuiEaseViewCtrl ) );
 56   addField("easeColor", TypeColorF, Offset( mEaseColor, GuiEaseViewCtrl ) );
 57   addField("easeWidth", TypeF32, Offset(mEaseWidth, GuiEaseViewCtrl ) );
 58   addField("axisColor", TypeColorF, Offset( mAxisColor, GuiEaseViewCtrl ) );
 59}
 60
 61//-----------------------------------------------------------------------------
 62
 63bool GuiEaseViewCtrl::onWake()
 64{
 65   if (!Parent::onWake())
 66      return false;
 67   setActive(true);
 68   return true;
 69}
 70
 71//-----------------------------------------------------------------------------
 72
 73void GuiEaseViewCtrl::onSleep()
 74{
 75   setActive(false);
 76   Parent::onSleep();
 77}
 78
 79//-----------------------------------------------------------------------------
 80
 81void GuiEaseViewCtrl::onRender(Point2I offset, const RectI &updateRect)
 82{
 83   const F32 W = getExtent().x;
 84   const F32 H = getExtent().y;
 85   const F32 plotW = W;
 86   const F32 plotH = H;
 87   const F32 zeroX = offset.x + 1.f;
 88   const F32 zeroY = offset.y;
 89   
 90   // Draw axis.
 91
 92   GFX->getDrawUtil()->drawLine( zeroX,  zeroY + 0.0f,  zeroX,          zeroY + plotH,  mAxisColor.toColorI());
 93   GFX->getDrawUtil()->drawLine( zeroX,  zeroY + plotH, zeroX + plotW,  zeroY + plotH,  mAxisColor.toColorI());
 94   
 95   F32 numPoints = W;
 96   F32 lastX = zeroX;
 97   F32 lastY = zeroY + plotH;
 98
 99   // Draw curve.
100
101   for( S32 i = 1; i <= numPoints; ++ i )
102   {
103      F32 x = ( F32 ) i / ( F32 ) numPoints;
104      F32 y = mEase.getValue( x, 0, 1, 1 );
105
106      x = zeroX + x * plotW;
107      y = zeroY + plotH - y * plotH;
108      
109      GFX->getDrawUtil()->drawLine( lastX, lastY, x, y, mEaseColor.toColorI());
110
111      lastX = x;
112      lastY = y;
113   }
114}
115