Torque3D Documentation / _generateds / guiBitmapBorderCtrl.cpp

guiBitmapBorderCtrl.cpp

Engine/source/gui/controls/guiBitmapBorderCtrl.cpp

More...

Classes:

class

Renders a skinned border.

Detailed Description

Public Functions

ConsoleDocClass(GuiBitmapBorderCtrl )

IMPLEMENT_CONOBJECT(GuiBitmapBorderCtrl )

  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
 26#include "gui/core/guiControl.h"
 27#include "gfx/gfxDevice.h"
 28#include "gfx/gfxDrawUtil.h"
 29
 30
 31// [rene 11/09/09] Why does this not use the bitmap array from its profile?
 32
 33
 34/// Renders a skinned border.
 35class GuiBitmapBorderCtrl : public GuiControl
 36{
 37   typedef GuiControl Parent;
 38
 39   enum {
 40      BorderTopLeft,
 41      BorderTopRight,
 42      BorderTop,
 43      BorderLeft,
 44      BorderRight,
 45      BorderBottomLeft,
 46      BorderBottom,
 47      BorderBottomRight,
 48      NumBitmaps
 49   };
 50   RectI *mBitmapBounds;  ///< bmp is [3*n], bmpHL is [3*n + 1], bmpNA is [3*n + 2]
 51   GFXTexHandle mTextureObject;
 52public:
 53   bool onWake();
 54   void onSleep();
 55   void onRender(Point2I offset, const RectI &updateRect);
 56   DECLARE_CONOBJECT(GuiBitmapBorderCtrl);
 57   DECLARE_CATEGORY( "Gui Images" );
 58   DECLARE_DESCRIPTION( "A control that renders a skinned border." );
 59};
 60
 61IMPLEMENT_CONOBJECT(GuiBitmapBorderCtrl);
 62
 63ConsoleDocClass( GuiBitmapBorderCtrl,
 64   "@brief A control that renders a skinned border specified in its profile.\n\n"
 65
 66   "This control uses the bitmap specified in it's profile (GuiControlProfile::bitmapName).  It takes this image and breaks up aspects of it "
 67   "to skin the border of this control with.  It is also important to set GuiControlProfile::hasBitmapArray to true on the profile as well.\n\n"
 68
 69   "The bitmap referenced should be broken up into a 3 x 3 grid (using the top left color pixel as a border color between each of the images) "
 70   "in which it will map to the following places:\n"
 71   "1 = Top Left Corner\n"
 72   "2 = Top Right Corner\n"
 73   "3 = Top Center\n"
 74   "4 = Left Center\n"
 75   "5 = Right Center\n"
 76   "6 = Bottom Left Corner\n"
 77   "7 = Bottom Center\n"
 78   "8 = Bottom Right Corner\n"
 79   "0 = Nothing\n\n"
 80
 81   "1 2 3\n"
 82   "4 5 0\n"
 83   "6 7 8\n\n"
 84
 85   "@tsexample\n"
 86   "singleton GuiControlProfile (BorderGUIProfile)\n"
 87   "{\n"
 88   "   bitmap = \"core/art/gui/images/borderArray\";\n"
 89   "   hasBitmapArray = true;\n"
 90   "   opaque = false;\n"
 91   "};\n\n"
 92
 93   "new GuiBitmapBorderCtrl(BitmapBorderGUI)\n"
 94   "{\n"
 95   "   profile = \"BorderGUIProfile\";\n"
 96   "   position = \"0 0\";\n"
 97   "   extent = \"400 40\";\n"
 98   "   visible = \"1\";\n"
 99   "};"
100   "@endtsexample\n\n"
101
102   "@see GuiControlProfile::bitmapName\n"
103   "@see GuiControlProfile::hasBitmapArray\n\n"
104
105   "@ingroup GuiImages"
106);
107
108bool GuiBitmapBorderCtrl::onWake()
109{
110   if (! Parent::onWake())
111      return false;
112
113   //get the texture for the close, minimize, and maximize buttons
114   mBitmapBounds = NULL;
115   mTextureObject = mProfile->mTextureObject;
116   if( mProfile->constructBitmapArray() >= NumBitmaps )
117      mBitmapBounds = mProfile->mBitmapArrayRects.address();
118   else
119      Con::errorf( "GuiBitmapBorderCtrl: Could not construct bitmap array for profile '%s'", mProfile->getName() );
120      
121   return true;
122}
123
124void GuiBitmapBorderCtrl::onSleep()
125{
126   mTextureObject = NULL;
127   mBitmapBounds = NULL;
128   
129   Parent::onSleep();
130}
131
132void GuiBitmapBorderCtrl::onRender(Point2I offset, const RectI &updateRect)
133{
134   renderChildControls( offset, updateRect );
135   
136   if( mBitmapBounds )
137   {
138      GFX->setClipRect(updateRect);
139
140      GFXDrawUtil* drawUtil = GFX->getDrawUtil();
141
142      //draw the outline
143      RectI winRect;
144      winRect.point = offset;
145      winRect.extent = getExtent();
146
147      winRect.point.x += mBitmapBounds[BorderLeft].extent.x;
148      winRect.point.y += mBitmapBounds[BorderTop].extent.y;
149
150      winRect.extent.x -= mBitmapBounds[BorderLeft].extent.x + mBitmapBounds[BorderRight].extent.x;
151      winRect.extent.y -= mBitmapBounds[BorderTop].extent.y + mBitmapBounds[BorderBottom].extent.y;
152
153      if(mProfile->mOpaque)
154        drawUtil->drawRectFill(winRect, mProfile->mFillColor);
155
156      drawUtil->clearBitmapModulation();
157      drawUtil->drawBitmapSR(mTextureObject, offset, mBitmapBounds[BorderTopLeft]);
158      drawUtil->drawBitmapSR(mTextureObject, Point2I(offset.x + getWidth() - mBitmapBounds[BorderTopRight].extent.x, offset.y),
159                      mBitmapBounds[BorderTopRight]);
160
161      RectI destRect;
162      destRect.point.x = offset.x + mBitmapBounds[BorderTopLeft].extent.x;
163      destRect.point.y = offset.y;
164      destRect.extent.x = getWidth() - mBitmapBounds[BorderTopLeft].extent.x - mBitmapBounds[BorderTopRight].extent.x;
165      destRect.extent.y = mBitmapBounds[BorderTop].extent.y;
166      RectI stretchRect = mBitmapBounds[BorderTop];
167      stretchRect.inset(1,0);
168      drawUtil->drawBitmapStretchSR(mTextureObject, destRect, stretchRect);
169
170      destRect.point.x = offset.x;
171      destRect.point.y = offset.y + mBitmapBounds[BorderTopLeft].extent.y;
172      destRect.extent.x = mBitmapBounds[BorderLeft].extent.x;
173      destRect.extent.y = getHeight() - mBitmapBounds[BorderTopLeft].extent.y - mBitmapBounds[BorderBottomLeft].extent.y;
174      stretchRect = mBitmapBounds[BorderLeft];
175      stretchRect.inset(0,1);
176      drawUtil->drawBitmapStretchSR(mTextureObject, destRect, stretchRect);
177
178      destRect.point.x = offset.x + getWidth() - mBitmapBounds[BorderRight].extent.x;
179      destRect.extent.x = mBitmapBounds[BorderRight].extent.x;
180      destRect.point.y = offset.y + mBitmapBounds[BorderTopRight].extent.y;
181      destRect.extent.y = getHeight() - mBitmapBounds[BorderTopRight].extent.y - mBitmapBounds[BorderBottomRight].extent.y;
182
183      stretchRect = mBitmapBounds[BorderRight];
184      stretchRect.inset(0,1);
185      drawUtil->drawBitmapStretchSR(mTextureObject, destRect, stretchRect);
186
187      drawUtil->drawBitmapSR(mTextureObject, offset + Point2I(0, getHeight() - mBitmapBounds[BorderBottomLeft].extent.y), mBitmapBounds[BorderBottomLeft]);
188      drawUtil->drawBitmapSR(mTextureObject, offset + getExtent() - mBitmapBounds[BorderBottomRight].extent, mBitmapBounds[BorderBottomRight]);
189
190      destRect.point.x = offset.x + mBitmapBounds[BorderBottomLeft].extent.x;
191      destRect.extent.x = getWidth() - mBitmapBounds[BorderBottomLeft].extent.x - mBitmapBounds[BorderBottomRight].extent.x;
192
193      destRect.point.y = offset.y + getHeight() - mBitmapBounds[BorderBottom].extent.y;
194      destRect.extent.y = mBitmapBounds[BorderBottom].extent.y;
195      stretchRect = mBitmapBounds[BorderBottom];
196      stretchRect.inset(1,0);
197
198      drawUtil->drawBitmapStretchSR(mTextureObject, destRect, stretchRect);
199   }
200}
201