guiChunkedBitmapCtrl.cpp
Engine/source/gui/game/guiChunkedBitmapCtrl.cpp
Public Functions
ConsoleDocClass(GuiChunkedBitmapCtrl , "@brief This is <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> that will <a href="/coding/file/editortool_8cpp/#editortool_8cpp_1a4cb041169a32ea3d4cacadbb955e06b4">render</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> specified bitmap or <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> bitmap specified in <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> referenced <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">variable.\n\n</a>" "This <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> allows you <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> either set <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> bitmap with the \"bitmap\" field or with the setBitmap method. You can also choose " "<a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> reference <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> variable in the \"variable\" field such as \"$image\" and then set \"useVariable\" to true. This will cause it <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> " "synchronize the variable with the bitmap displayed (<a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the variable holds <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> valid image). You can then change the variable and " "effectively changed the displayed <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">image.\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" " $image)
DefineEngineMethod(GuiChunkedBitmapCtrl , setBitmap , void , (const char *filename) , "@brief Set the image rendered in this <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">control.\n\n</a>" "@param filename The image name you want <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">set\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "ChunkedBitmap.setBitmap(\"images/background.png\");" "@endtsexample\n\n" )
Detailed Description
Public Functions
ConsoleDocClass(GuiChunkedBitmapCtrl , "@brief This is <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> that will <a href="/coding/file/editortool_8cpp/#editortool_8cpp_1a4cb041169a32ea3d4cacadbb955e06b4">render</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> specified bitmap or <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> bitmap specified in <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> referenced <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">variable.\n\n</a>" "This <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> allows you <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> either set <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> bitmap with the \"bitmap\" field or with the setBitmap method. You can also choose " "<a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> reference <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> variable in the \"variable\" field such as \"$image\" and then set \"useVariable\" to true. This will cause it <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> " "synchronize the variable with the bitmap displayed (<a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the variable holds <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> valid image). You can then change the variable and " "effectively changed the displayed <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">image.\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" " $image)
DefineEngineMethod(GuiChunkedBitmapCtrl , setBitmap , void , (const char *filename) , "@brief Set the image rendered in this <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">control.\n\n</a>" "@param filename The image name you want <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">set\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "ChunkedBitmap.setBitmap(\"images/background.png\");" "@endtsexample\n\n" )
IMPLEMENT_CONOBJECT(GuiChunkedBitmapCtrl )
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 "console/console.h" 27#include "console/consoleTypes.h" 28#include "gfx/bitmap/gBitmap.h" 29#include "gui/core/guiControl.h" 30#include "gfx/gfxDevice.h" 31#include "gfx/gfxTextureHandle.h" 32#include "gfx/gfxDrawUtil.h" 33#include "console/engineAPI.h" 34 35#include "guiChunkedBitmapCtrl.h" 36 37 38IMPLEMENT_CONOBJECT(GuiChunkedBitmapCtrl); 39 40ConsoleDocClass( GuiChunkedBitmapCtrl, 41 "@brief This is a control that will render a specified bitmap or a bitmap specified in a referenced variable.\n\n" 42 43 "This control allows you to either set a bitmap with the \"bitmap\" field or with the setBitmap method. You can also choose " 44 "to reference a variable in the \"variable\" field such as \"$image\" and then set \"useVariable\" to true. This will cause it to " 45 "synchronize the variable with the bitmap displayed (if the variable holds a valid image). You can then change the variable and " 46 "effectively changed the displayed image.\n\n" 47 48 "@tsexample\n" 49 "$image = \"anotherbackground.png\";\n" 50 "new GuiChunkedBitmapCtrl(ChunkedBitmap)\n" 51 "{\n" 52 " bitmap = \"background.png\";\n" 53 " variable = \"$image\";\n" 54 " useVariable = false;\n" 55 "}\n\n" 56 "// This will result in the control rendering \"background.png\"\n" 57 "// If we now set the useVariable to true it will now render \"anotherbackground.png\"\n" 58 "ChunkedBitmap.useVariable = true;\n" 59 "@endtsexample\n\n" 60 61 "@see GuiControl::variable\n\n" 62 63 "@ingroup GuiImages\n" 64); 65 66 67void GuiChunkedBitmapCtrl::initPersistFields() 68{ 69 addGroup("GuiChunkedBitmapCtrl"); 70 addField( "bitmap", TypeFilename, Offset( mBitmapName, GuiChunkedBitmapCtrl ), "This is the bitmap to render to the control." ); 71 addField( "useVariable", TypeBool, Offset( mUseVariable, GuiChunkedBitmapCtrl ), "This decides whether to use the \"bitmap\" file " 72 "or a bitmap stored in \"variable\""); 73 addField( "tile", TypeBool, Offset( mTile, GuiChunkedBitmapCtrl ), "This is no longer in use"); 74 endGroup("GuiChunkedBitmapCtrl"); 75 Parent::initPersistFields(); 76} 77 78DefineEngineMethod( GuiChunkedBitmapCtrl, setBitmap, void, (const char* filename),, 79 "@brief Set the image rendered in this control.\n\n" 80 "@param filename The image name you want to set\n" 81 "@tsexample\n" 82 "ChunkedBitmap.setBitmap(\"images/background.png\");" 83 "@endtsexample\n\n") 84{ 85 object->setBitmap( filename ); 86} 87 88GuiChunkedBitmapCtrl::GuiChunkedBitmapCtrl() 89{ 90 mBitmapName = StringTable->EmptyString(); 91 mUseVariable = false; 92 mTile = false; 93} 94 95void GuiChunkedBitmapCtrl::setBitmap(const char *name) 96{ 97 bool awake = mAwake; 98 if(awake) 99 onSleep(); 100 101 mBitmapName = StringTable->insert(name); 102 if(awake) 103 onWake(); 104 setUpdate(); 105} 106 107bool GuiChunkedBitmapCtrl::onWake() 108{ 109 if(!Parent::onWake()) 110 return false; 111 112 if( !mTexHandle 113 && ( ( mBitmapName && mBitmapName[ 0 ] ) 114 || ( mUseVariable && mConsoleVariable && mConsoleVariable[ 0 ] ) ) ) 115 { 116 if ( mUseVariable ) 117 mTexHandle.set( Con::getVariable( mConsoleVariable ), &GFXDefaultGUIProfile, avar("%s() - mTexHandle (line %d)", __FUNCTION__, __LINE__) ); 118 else 119 mTexHandle.set( mBitmapName, &GFXDefaultGUIProfile, avar("%s() - mTexHandle (line %d)", __FUNCTION__, __LINE__) ); 120 } 121 122 return true; 123} 124 125void GuiChunkedBitmapCtrl::onSleep() 126{ 127 mTexHandle = NULL; 128 Parent::onSleep(); 129} 130 131void GuiChunkedBitmapCtrl::renderRegion(const Point2I &offset, const Point2I &extent) 132{ 133/* 134 U32 widthCount = mTexHandle.getTextureCountWidth(); 135 U32 heightCount = mTexHandle.getTextureCountHeight(); 136 if(!widthCount || !heightCount) 137 return; 138 139 F32 widthScale = F32(extent.x) / F32(mTexHandle.getWidth()); 140 F32 heightScale = F32(extent.y) / F32(mTexHandle.getHeight()); 141 GFX->setBitmapModulation(LinearColorF(1,1,1)); 142 for(U32 i = 0; i < widthCount; i++) 143 { 144 for(U32 j = 0; j < heightCount; j++) 145 { 146 GFXTexHandle t = mTexHandle.getSubTexture(i, j); 147 RectI stretchRegion; 148 stretchRegion.point.x = (S32)(i * 256 * widthScale + offset.x); 149 stretchRegion.point.y = (S32)(j * 256 * heightScale + offset.y); 150 if(i == widthCount - 1) 151 stretchRegion.extent.x = extent.x + offset.x - stretchRegion.point.x; 152 else 153 stretchRegion.extent.x = (S32)((i * 256 + t.getWidth() ) * widthScale + offset.x - stretchRegion.point.x); 154 if(j == heightCount - 1) 155 stretchRegion.extent.y = extent.y + offset.y - stretchRegion.point.y; 156 else 157 stretchRegion.extent.y = (S32)((j * 256 + t.getHeight()) * heightScale + offset.y - stretchRegion.point.y); 158 GFX->drawBitmapStretch(t, stretchRegion); 159 } 160 } 161*/ 162} 163 164 165void GuiChunkedBitmapCtrl::onRender(Point2I offset, const RectI &updateRect) 166{ 167 168 if( mTexHandle ) 169 { 170 RectI boundsRect( offset, getExtent()); 171 GFX->getDrawUtil()->drawBitmapStretch( mTexHandle, boundsRect, GFXBitmapFlip_None, GFXTextureFilterLinear ); 172 } 173 174 renderChildControls(offset, updateRect); 175} 176