guiTextEditSliderBitmapCtrl.cpp
Engine/source/gui/controls/guiTextEditSliderBitmapCtrl.cpp
Public Functions
ConsoleDocClass(GuiTextEditSliderBitmapCtrl , "@brief GUI Control which displays <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> numerical <a href="/coding/file/pointer_8h/#pointer_8h_1a32aff7c6c4cd253fdf6563677afab5ce">value</a> which can be increased " "or decreased using <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> pair of bitmap up/down buttons. \<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "This <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> uses the bitmap specified in it's profile " "(GuiControlProfile::bitmapName). It takes this image and breaks up aspects " "of it <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/editortool_8cpp/#editortool_8cpp_1a4cb041169a32ea3d4cacadbb955e06b4">render</a> the up and down arrows. It is also important <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> set " "GuiControlProfile::hasBitmapArray <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> true on the profile as <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">well.\n\n</a>" "The bitmap referenced should be broken up into <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> 1 x 4 grid (using the top " "left color pixel as <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> border color between each of the images) in which it " "will map <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the following <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">places:\n</a>" "<ol>\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "<li>Up arrow active</li>\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "<li>Up arrow inactive</li>\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "<li>Down arrow active</li>\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "<li>Down arrow inactive</li>\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "</ol>\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "<pre>\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "1\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "2\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "3\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "4</pre>\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "singleton <a href="/coding/class/classguicontrolprofile/">GuiControlProfile</a> (SliderBitmapGUIProfile)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " bitmap = \"core/art/gui/images/sliderArray\";\n" " hasBitmapArray = true;\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " opaque = false;\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "};\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "<a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> <a href="/coding/class/classguitexteditsliderbitmapctrl/">GuiTextEditSliderBitmapCtrl</a>()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " profile = \"SliderBitmapGUIProfile\";\n" " format = \"%3.2f\";\n" " range = \"-1e+03 1e+03\";\n" " increment = \"0.1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " focusOnMouseWheel = \"0\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " bitmap = \"\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " //Properties not specific <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> this <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> have been omitted from this <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">example.\n</a>" "};\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiTextEditSliderCtrl\n\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiTextEditCtrl\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiCore\n</a>" )
Detailed Description
Public Functions
ConsoleDocClass(GuiTextEditSliderBitmapCtrl , "@brief GUI Control which displays <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> numerical <a href="/coding/file/pointer_8h/#pointer_8h_1a32aff7c6c4cd253fdf6563677afab5ce">value</a> which can be increased " "or decreased using <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> pair of bitmap up/down buttons. \<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "This <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> uses the bitmap specified in it's profile " "(GuiControlProfile::bitmapName). It takes this image and breaks up aspects " "of it <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/editortool_8cpp/#editortool_8cpp_1a4cb041169a32ea3d4cacadbb955e06b4">render</a> the up and down arrows. It is also important <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> set " "GuiControlProfile::hasBitmapArray <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> true on the profile as <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">well.\n\n</a>" "The bitmap referenced should be broken up into <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> 1 x 4 grid (using the top " "left color pixel as <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> border color between each of the images) in which it " "will map <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the following <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">places:\n</a>" "<ol>\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "<li>Up arrow active</li>\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "<li>Up arrow inactive</li>\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "<li>Down arrow active</li>\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "<li>Down arrow inactive</li>\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "</ol>\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "<pre>\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "1\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "2\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "3\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "4</pre>\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "singleton <a href="/coding/class/classguicontrolprofile/">GuiControlProfile</a> (SliderBitmapGUIProfile)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " bitmap = \"core/art/gui/images/sliderArray\";\n" " hasBitmapArray = true;\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " opaque = false;\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "};\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "<a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> <a href="/coding/class/classguitexteditsliderbitmapctrl/">GuiTextEditSliderBitmapCtrl</a>()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " profile = \"SliderBitmapGUIProfile\";\n" " format = \"%3.2f\";\n" " range = \"-1e+03 1e+03\";\n" " increment = \"0.1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " focusOnMouseWheel = \"0\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " bitmap = \"\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " //Properties not specific <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> this <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> have been omitted from this <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">example.\n</a>" "};\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiTextEditSliderCtrl\n\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiTextEditCtrl\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiCore\n</a>" )
IMPLEMENT_CONOBJECT(GuiTextEditSliderBitmapCtrl )
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/guiTextEditSliderBitmapCtrl.h" 26 27#include "console/consoleTypes.h" 28#include "console/console.h" 29#include "gui/core/guiCanvas.h" 30#include "gfx/gfxDevice.h" 31#include "gfx/gfxDrawUtil.h" 32 33 34IMPLEMENT_CONOBJECT(GuiTextEditSliderBitmapCtrl); 35 36ConsoleDocClass( GuiTextEditSliderBitmapCtrl, 37 "@brief GUI Control which displays a numerical value which can be increased " 38 "or decreased using a pair of bitmap up/down buttons. \n\n" 39 40 "This control uses the bitmap specified in it's profile " 41 "(GuiControlProfile::bitmapName). It takes this image and breaks up aspects " 42 "of it to render the up and down arrows. It is also important to set " 43 "GuiControlProfile::hasBitmapArray to true on the profile as well.\n\n" 44 45 "The bitmap referenced should be broken up into a 1 x 4 grid (using the top " 46 "left color pixel as a border color between each of the images) in which it " 47 "will map to the following places:\n" 48 "<ol>\n" 49 "<li>Up arrow active</li>\n" 50 "<li>Up arrow inactive</li>\n" 51 "<li>Down arrow active</li>\n" 52 "<li>Down arrow inactive</li>\n" 53 "</ol>\n\n" 54 55 "<pre>\n" 56 "1\n" 57 "2\n" 58 "3\n" 59 "4</pre>\n\n" 60 61 "@tsexample\n" 62 "singleton GuiControlProfile (SliderBitmapGUIProfile)\n" 63 "{\n" 64 " bitmap = \"core/art/gui/images/sliderArray\";\n" 65 " hasBitmapArray = true;\n" 66 " opaque = false;\n" 67 "};\n\n" 68 69 "new GuiTextEditSliderBitmapCtrl()\n" 70 "{\n" 71 " profile = \"SliderBitmapGUIProfile\";\n" 72 " format = \"%3.2f\";\n" 73 " range = \"-1e+03 1e+03\";\n" 74 " increment = \"0.1\";\n" 75 " focusOnMouseWheel = \"0\";\n" 76 " bitmap = \"\";\n" 77 " //Properties not specific to this control have been omitted from this example.\n" 78 "};\n" 79 "@endtsexample\n\n" 80 81 "@see GuiTextEditSliderCtrl\n\n" 82 "@see GuiTextEditCtrl\n\n" 83 84 "@ingroup GuiCore\n" 85); 86 87 88GuiTextEditSliderBitmapCtrl::GuiTextEditSliderBitmapCtrl() 89{ 90 mRange.set(0.0f, 1.0f); 91 mIncAmount = 1.0f; 92 mValue = 0.0f; 93 mMulInc = 0; 94 mIncCounter = 0.0f; 95 mFormat = StringTable->insert("%3.2f"); 96 mTextAreaHit = None; 97 mFocusOnMouseWheel = false; 98 mBitmapName = StringTable->insert( "" ); 99 mMouseDownTime = 0; 100 mNumberOfBitmaps = 0; 101} 102 103GuiTextEditSliderBitmapCtrl::~GuiTextEditSliderBitmapCtrl() 104{ 105} 106 107void GuiTextEditSliderBitmapCtrl::initPersistFields() 108{ 109 addField("format", TypeString, Offset(mFormat, GuiTextEditSliderBitmapCtrl), "Character format type to place in the control.\n"); 110 addField("range", TypePoint2F, Offset(mRange, GuiTextEditSliderBitmapCtrl), "Maximum vertical and horizontal range to allow in the control.\n"); 111 addField("increment", TypeF32, Offset(mIncAmount, GuiTextEditSliderBitmapCtrl), "How far to increment the slider on each step.\n"); 112 addField("focusOnMouseWheel", TypeBool, Offset(mFocusOnMouseWheel, GuiTextEditSliderBitmapCtrl), "If true, the control will accept giving focus to the user when the mouse wheel is used.\n"); 113 addField("bitmap", TypeFilename,Offset(mBitmapName, GuiTextEditSliderBitmapCtrl), "Unused" ); 114 115 Parent::initPersistFields(); 116} 117 118void GuiTextEditSliderBitmapCtrl::getText(char *dest) 119{ 120 Parent::getText(dest); 121} 122 123void GuiTextEditSliderBitmapCtrl::setText(const char *txt) 124{ 125 mValue = dAtof(txt); 126 checkRange(); 127 setValue(); 128} 129 130bool GuiTextEditSliderBitmapCtrl::onKeyDown(const GuiEvent &event) 131{ 132 return Parent::onKeyDown(event); 133} 134 135void GuiTextEditSliderBitmapCtrl::checkRange() 136{ 137 if(mValue < mRange.x) 138 mValue = mRange.x; 139 else if(mValue > mRange.y) 140 mValue = mRange.y; 141} 142 143void GuiTextEditSliderBitmapCtrl::setValue() 144{ 145 char buf[20]; 146 // For some reason this sprintf is failing to convert 147 // a floating point number to anything with %d, so cast it. 148 if( dStricmp( mFormat, "%d" ) == 0 ) 149 dSprintf(buf,sizeof(buf),mFormat, (S32)mValue); 150 else 151 dSprintf(buf,sizeof(buf),mFormat, mValue); 152 Parent::setText(buf); 153} 154 155void GuiTextEditSliderBitmapCtrl::onMouseDown(const GuiEvent &event) 156{ 157 // If we're not active then skip out. 158 if ( !mActive || !mAwake || !mVisible ) 159 { 160 Parent::onMouseDown(event); 161 return; 162 } 163 164 char txt[20]; 165 Parent::getText(txt); 166 mValue = dAtof(txt); 167 168 mMouseDownTime = Sim::getCurrentTime(); 169 GuiControl *parent = getParent(); 170 if(!parent) 171 return; 172 Point2I camPos = event.mousePoint; 173 Point2I point = parent->localToGlobalCoord(getPosition()); 174 175 if(camPos.x > point.x + getExtent().x - 14) 176 { 177 if(camPos.y > point.y + (getExtent().y/2)) 178 { 179 mValue -=<a href="/coding/class/classguitexteditsliderbitmapctrl/#classguitexteditsliderbitmapctrl_1a14dacc1ac7df3d7c2e56d52bcb570fd8">mIncAmount</a>; 180 mTextAreaHit = ArrowDown; 181 mMulInc = -0.15f; 182 } 183 else 184 { 185 mValue +=<a href="/coding/class/classguitexteditsliderbitmapctrl/#classguitexteditsliderbitmapctrl_1a14dacc1ac7df3d7c2e56d52bcb570fd8">mIncAmount</a>; 186 mTextAreaHit = ArrowUp; 187 mMulInc = 0.15f; 188 } 189 190 checkRange(); 191 setValue(); 192 mouseLock(); 193 194 // We should get the focus and set the 195 // cursor to the start of the text to 196 // mimic the standard Windows behavior. 197 setFirstResponder(); 198 mCursorPos = mBlockStart = mBlockEnd = 0; 199 setUpdate(); 200 201 return; 202 } 203 204 Parent::onMouseDown(event); 205} 206 207void GuiTextEditSliderBitmapCtrl::onMouseDragged(const GuiEvent &event) 208{ 209 // If we're not active then skip out. 210 if ( !mActive || !mAwake || !mVisible ) 211 { 212 Parent::onMouseDragged(event); 213 return; 214 } 215 216 if(mTextAreaHit == None || mTextAreaHit == Slider) 217 { 218 mTextAreaHit = Slider; 219 GuiControl *parent = getParent(); 220 if(!parent) 221 return; 222 Point2I camPos = event.mousePoint; 223 Point2I point = parent->localToGlobalCoord(getPosition()); 224 F32 maxDis = 100; 225 F32 val; 226 if(camPos.y < point.y) 227 { 228 if((F32)point.y < maxDis) 229 maxDis = (F32)point.y; 230 231 val = point.y - maxDis; 232 233 if(point.y > 0) 234 mMulInc= 1.0f-(((float)camPos.y - val) / maxDis); 235 else 236 mMulInc = 1.0f; 237 238 checkIncValue(); 239 240 return; 241 } 242 else if(camPos.y > point.y + getExtent().y) 243 { 244 GuiCanvas *root = getRoot(); 245 val = (F32)(root->getHeight() - (point.y + getHeight())); 246 if(val < maxDis) 247 maxDis = val; 248 if( val > 0) 249 mMulInc= -(F32)(camPos.y - (point.y + getHeight()))/maxDis; 250 else 251 mMulInc = -1.0f; 252 checkIncValue(); 253 return; 254 } 255 mTextAreaHit = None; 256 Parent::onMouseDragged(event); 257 } 258} 259 260void GuiTextEditSliderBitmapCtrl::onMouseUp(const GuiEvent &event) 261{ 262 // If we're not active then skip out. 263 if ( !mActive || !mAwake || !mVisible ) 264 { 265 Parent::onMouseUp(event); 266 return; 267 } 268 269 mMulInc = 0.0f; 270 mouseUnlock(); 271 272 if ( mTextAreaHit != None ) 273 274 //if we released the mouse within this control, then the parent will call 275 //the mConsoleCommand other wise we have to call it. 276 Parent::onMouseUp(event); 277 278 //if we didn't release the mouse within this control, then perform the action 279 // if (!cursorInControl()) 280 execConsoleCallback(); 281 282 execAltConsoleCallback(); 283 284 mTextAreaHit = None; 285} 286 287bool GuiTextEditSliderBitmapCtrl::onMouseWheelUp(const GuiEvent &event) 288{ 289 if ( !mActive || !mAwake || !mVisible ) 290 return Parent::onMouseWheelUp(event); 291 292 if ( !isFirstResponder() && !mFocusOnMouseWheel ) 293 return false; 294 295 mValue += mIncAmount; 296 297 checkRange(); 298 setValue(); 299 300 setFirstResponder(); 301 mCursorPos = mBlockStart = mBlockEnd = 0; 302 setUpdate(); 303 304 return true; 305} 306 307bool GuiTextEditSliderBitmapCtrl::onMouseWheelDown(const GuiEvent &event) 308{ 309 if ( !mActive || !mAwake || !mVisible ) 310 return Parent::onMouseWheelDown(event); 311 312 if ( !isFirstResponder() && !mFocusOnMouseWheel ) 313 return false; 314 315 mValue -= mIncAmount; 316 317 checkRange(); 318 setValue(); 319 320 setFirstResponder(); 321 mCursorPos = mBlockStart = mBlockEnd = 0; 322 setUpdate(); 323 324 return true; 325} 326 327void GuiTextEditSliderBitmapCtrl::checkIncValue() 328{ 329 if(mMulInc > 1.0f) 330 mMulInc = 1.0f; 331 else if(mMulInc < -1.0f) 332 mMulInc = -1.0f; 333} 334 335void GuiTextEditSliderBitmapCtrl::timeInc(U32 elapseTime) 336{ 337 S32 numTimes = elapseTime / 750; 338 if(mTextAreaHit != Slider && numTimes > 0) 339 { 340 if(mTextAreaHit == ArrowUp) 341 mMulInc = 0.15f * numTimes; 342 else 343 mMulInc = -0.15f * numTimes; 344 345 checkIncValue(); 346 } 347} 348bool GuiTextEditSliderBitmapCtrl::onWake() 349{ 350 if(!Parent::onWake()) 351 return false; 352 353 mNumberOfBitmaps = mProfile->constructBitmapArray(); 354 355 return true; 356} 357 358void GuiTextEditSliderBitmapCtrl::onPreRender() 359{ 360 if (isFirstResponder()) 361 { 362 U32 timeElapsed = Platform::getVirtualMilliseconds() - mTimeLastCursorFlipped; 363 mNumFramesElapsed++; 364 if ((timeElapsed > 500) && (mNumFramesElapsed > 3)) 365 { 366 mCursorOn = !mCursorOn; 367 mTimeLastCursorFlipped = Sim::getCurrentTime(); 368 mNumFramesElapsed = 0; 369 setUpdate(); 370 } 371 372 //update the cursor if the text is scrolling 373 if (mDragHit) 374 { 375 if ((mScrollDir < 0) && (mCursorPos > 0)) 376 { 377 mCursorPos--; 378 } 379 else if ((mScrollDir > 0) && (mCursorPos < (S32)dStrlen(mText))) 380 { 381 mCursorPos++; 382 } 383 } 384 } 385} 386 387void GuiTextEditSliderBitmapCtrl::onRender(Point2I offset, const RectI &updateRect) 388{ 389 if(mTextAreaHit != None) 390 { 391 U32 elapseTime = Sim::getCurrentTime() - mMouseDownTime; 392 if(elapseTime > 750 || mTextAreaHit == Slider) 393 { 394 timeInc(elapseTime); 395 mIncCounter += mMulInc; 396 if(mIncCounter >= 1.0f || mIncCounter <= -1.0f) 397 { 398 mValue = (mMulInc > 0.0f) ? mValue+mIncAmount : mValue-mIncAmount; 399 mIncCounter = (mIncCounter > 0.0f) ? mIncCounter-1 : mIncCounter+1; 400 checkRange(); 401 setValue(); 402 mCursorPos = 0; 403 } 404 } 405 } 406 407 Parent::onRender(offset, updateRect); 408 409 // Arrow placement coordinates 410 Point2I arrowUpStart(offset.x + getWidth() - 14, offset.y + 1 ); 411 Point2I arrowUpEnd(13, getExtent().y/2); 412 413 Point2I arrowDownStart(offset.x + getWidth() - 14, offset.y + 1 + getExtent().y/2); 414 Point2I arrowDownEnd(13, getExtent().y/2); 415 416 // Draw the line that splits the number and bitmaps 417 GFX->getDrawUtil()->drawLine(Point2I(offset.x + getWidth() - 14 -2, offset.y + 1 ), 418 Point2I(arrowUpStart.x -2, arrowUpStart.y + getExtent().y), 419 mProfile->mBorderColor); 420 421 GFX->getDrawUtil()->clearBitmapModulation(); 422 423 if(mNumberOfBitmaps == 0) 424 Con::warnf("No image provided for GuiTextEditSliderBitmapCtrl; do not render"); 425 else 426 { 427 // This control needs 4 images in order to render correctly 428 if(mTextAreaHit == ArrowUp) 429 GFX->getDrawUtil()->drawBitmapStretchSR( mProfile->mTextureObject, RectI(arrowUpStart,arrowUpEnd), mProfile->mBitmapArrayRects[0] ); 430 else 431 GFX->getDrawUtil()->drawBitmapStretchSR( mProfile->mTextureObject, RectI(arrowUpStart,arrowUpEnd), mProfile->mBitmapArrayRects[1] ); 432 433 if(mTextAreaHit == ArrowDown) 434 GFX->getDrawUtil()->drawBitmapStretchSR( mProfile->mTextureObject, RectI(arrowDownStart,arrowDownEnd), mProfile->mBitmapArrayRects[2] ); 435 else 436 GFX->getDrawUtil()->drawBitmapStretchSR( mProfile->mTextureObject, RectI(arrowDownStart,arrowDownEnd), mProfile->mBitmapArrayRects[3] ); 437 } 438} 439 440void GuiTextEditSliderBitmapCtrl::setBitmap(const char *name) 441{ 442 bool awake = mAwake; 443 if(awake) 444 onSleep(); 445 446 mBitmapName = StringTable->insert(name); 447 if(awake) 448 onWake(); 449 setUpdate(); 450} 451