Torque3D Documentation / _generateds / guiIdleCamFadeBitmapCtrl.cpp

guiIdleCamFadeBitmapCtrl.cpp

Engine/source/gui/game/guiIdleCamFadeBitmapCtrl.cpp

More...

Classes:

Public Functions

ConsoleDocClass(GuiIdleCamFadeBitmapCtrl , "@brief GUI that will fade the current view in and <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">out.\n\n</a>" "Main difference between this and FadeinBitmap is this appears <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> " "fade based on the <a href="/coding/file/pointer_8h/#pointer_8h_1adb82dfe18535e9a30aa97d275f82bd55">source</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">texture.\n\n</a>" "This is going <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be deprecated, and any useful code ported <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">FadeinBitmap\n\n</a>" " @internal" )
DefineEngineMethod(GuiIdleCamFadeBitmapCtrl , fadeIn , void , () , "()" "@internal" )
DefineEngineMethod(GuiIdleCamFadeBitmapCtrl , fadeOut , void , () , "()" "@internal" )

Detailed Description

Public Functions

ConsoleDocClass(GuiIdleCamFadeBitmapCtrl , "@brief GUI that will fade the current view in and <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">out.\n\n</a>" "Main difference between this and FadeinBitmap is this appears <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> " "fade based on the <a href="/coding/file/pointer_8h/#pointer_8h_1adb82dfe18535e9a30aa97d275f82bd55">source</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">texture.\n\n</a>" "This is going <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be deprecated, and any useful code ported <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">FadeinBitmap\n\n</a>" " @internal" )

DefineEngineMethod(GuiIdleCamFadeBitmapCtrl , fadeIn , void , () , "()" "@internal" )

DefineEngineMethod(GuiIdleCamFadeBitmapCtrl , fadeOut , void , () , "()" "@internal" )

IMPLEMENT_CONOBJECT(GuiIdleCamFadeBitmapCtrl )

  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 "platform/platform.h"
 25#include "gui/controls/guiBitmapCtrl.h"
 26
 27#include "console/console.h"
 28#include "console/consoleTypes.h"
 29#include "console/engineAPI.h"
 30#include "gfx/gfxDrawUtil.h"
 31
 32
 33class GuiIdleCamFadeBitmapCtrl : public GuiBitmapCtrl
 34{
 35   typedef GuiBitmapCtrl Parent;
 36public:
 37   DECLARE_CONOBJECT(GuiIdleCamFadeBitmapCtrl);
 38   DECLARE_CATEGORY( "Gui Images" );
 39
 40   U32 wakeTime;
 41   bool done;
 42   U32 fadeinTime;
 43   U32 fadeoutTime;
 44   bool doFadeIn;
 45   bool doFadeOut;
 46
 47   GuiIdleCamFadeBitmapCtrl()
 48   {
 49      wakeTime    = 0;
 50      fadeinTime  = 1000;
 51      fadeoutTime = 1000;
 52      done        = false;
 53
 54      doFadeIn    = false;
 55      doFadeOut   = false;
 56   }
 57   void onPreRender()
 58   {
 59      Parent::onPreRender();
 60      setUpdate();
 61   }
 62   void onMouseDown(const GuiEvent &)
 63   {
 64      Con::executef(this, "click");
 65   }
 66   bool onKeyDown(const GuiEvent &)
 67   {
 68      Con::executef(this, "click");
 69      return true;
 70   }
 71   bool onWake()
 72   {
 73      if(!Parent::onWake())
 74         return false;
 75      wakeTime = Platform::getRealMilliseconds();
 76      return true;
 77   }
 78
 79   void fadeIn()
 80   {
 81      wakeTime = Platform::getRealMilliseconds();
 82      doFadeIn = true;
 83      doFadeOut = false;
 84      done = false;
 85   }
 86
 87   void fadeOut()
 88   {
 89      wakeTime = Platform::getRealMilliseconds();
 90      doFadeIn = false;
 91      doFadeOut = true;
 92      done = false;
 93   }
 94
 95   void onRender(Point2I offset, const RectI &updateRect)
 96   {
 97      U32 elapsed = Platform::getRealMilliseconds() - wakeTime;
 98
 99      U32 alpha;
100      if (doFadeOut && elapsed < fadeoutTime)
101      {
102         // fade out
103         alpha = 255 - (255 * (F32(elapsed) / F32(fadeoutTime)));
104      }
105      else if (doFadeIn && elapsed < fadeinTime)
106      {
107         // fade in
108         alpha = 255 * F32(elapsed) / F32(fadeinTime);
109      }
110      else
111      {
112         // done state
113         alpha = doFadeIn ? 255 : 0;
114         done = true;
115      }
116
117      ColorI color(255,255,255,alpha);
118      if (mTextureObject)
119      {
120         GFX->getDrawUtil()->setBitmapModulation(color);
121
122         if(mWrap)
123         {
124
125            GFXTextureObject* texture = mTextureObject;
126            RectI srcRegion;
127            RectI dstRegion;
128            F32 xdone = ((F32)getExtent().x/(F32)texture->mBitmapSize.x)+1;
129            F32 ydone = ((F32)getExtent().y/(F32)texture->mBitmapSize.y)+1;
130
131            S32 xshift = mStartPoint.x</a>%texture-><a href="/coding/class/classgfxtextureobject/#classgfxtextureobject_1ac2d6a6fef6cde71207314fe42cfcdce1">mBitmapSize.x;
132            S32 yshift = mStartPoint.y</a>%texture-><a href="/coding/class/classgfxtextureobject/#classgfxtextureobject_1ac2d6a6fef6cde71207314fe42cfcdce1">mBitmapSize.y;
133            for(S32 y = 0; y < ydone; ++y)
134               for(S32 x = 0; x < xdone; ++x)
135               {
136                  srcRegion.set(0,0,texture->mBitmapSize.x,texture->mBitmapSize.y);
137                  dstRegion.set( ((texture->mBitmapSize.x*x)+offset.x)-xshift,
138                     ((texture->mBitmapSize.y*y)+offset.y)-yshift,
139                     texture->mBitmapSize.x,
140                     texture->mBitmapSize.y);
141                  GFX->getDrawUtil()->drawBitmapStretchSR(texture,dstRegion, srcRegion);
142               }
143
144         }
145         else
146         {
147            RectI rect(offset, getExtent());
148            GFX->getDrawUtil()->drawBitmapStretch(mTextureObject, rect);
149         }
150      }
151
152      if (mProfile->mBorder || !mTextureObject)
153      {
154         RectI rect(offset.x, offset.y, getExtent().x, getExtent().y);
155         ColorI borderCol(mProfile->mBorderColor);
156         borderCol.alpha = alpha;
157         GFX->getDrawUtil()->drawRect(rect, borderCol);
158      }
159
160      renderChildControls(offset, updateRect);
161   }
162
163   static void initPersistFields()
164   {
165      addField("fadeinTime", TypeS32, Offset(fadeinTime, GuiIdleCamFadeBitmapCtrl));
166      addField("fadeoutTime", TypeS32, Offset(fadeoutTime, GuiIdleCamFadeBitmapCtrl));
167      addField("done", TypeBool, Offset(done, GuiIdleCamFadeBitmapCtrl));
168      Parent::initPersistFields();
169   }
170};
171
172IMPLEMENT_CONOBJECT(GuiIdleCamFadeBitmapCtrl);
173
174ConsoleDocClass( GuiIdleCamFadeBitmapCtrl,
175            "@brief GUI that will fade the current view in and out.\n\n"
176            "Main difference between this and FadeinBitmap is this appears to "
177            "fade based on the source texture.\n\n"
178            "This is going to be deprecated, and any useful code ported to FadeinBitmap\n\n"
179            "@internal");
180
181DefineEngineMethod(GuiIdleCamFadeBitmapCtrl, fadeIn, void, (), , "()"
182           "@internal")
183{
184   object->fadeIn();
185}
186
187DefineEngineMethod(GuiIdleCamFadeBitmapCtrl, fadeOut, void, (), , "()"
188           "@internal")
189{
190   object->fadeOut();
191}
192