guiControl.cc 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "console/consoleTypes.h"
  23. #include "console/console.h"
  24. #include "console/consoleInternal.h"
  25. #include "console/codeBlock.h"
  26. #include "platform/event.h"
  27. #include "graphics/gBitmap.h"
  28. #include "graphics/dgl.h"
  29. #include "input/actionMap.h"
  30. #include "gui/guiCanvas.h"
  31. #include "gui/guiControl.h"
  32. #include "gui/guiDefaultControlRender.h"
  33. #include "gui/editor/guiEditCtrl.h"
  34. #include "string/unicode.h"
  35. #include "collection/vector.h"
  36. #include "2d/core/Utility.h"
  37. #include "gui/containers/guiScrollCtrl.h"
  38. #include "gui/editor/guiEditCtrl.h"
  39. #include <sstream>
  40. #include <iostream>
  41. #include <vector>
  42. #include <string>
  43. #include "guiControl_ScriptBinding.h"
  44. #ifndef _FRAMEALLOCATOR_H_
  45. #include "memory/frameAllocator.h"
  46. #endif
  47. //------------------------------------------------------------------------------
  48. IMPLEMENT_CONOBJECT_CHILDREN(GuiControl);
  49. static EnumTable::Enums alignCtrlEnums[] =
  50. {
  51. { AlignmentType::LeftAlign, "left" },
  52. { AlignmentType::CenterAlign, "center" },
  53. { AlignmentType::RightAlign, "right" },
  54. { AlignmentType::DefaultAlign, "default" }
  55. };
  56. static EnumTable gAlignCtrlTable(3, &alignCtrlEnums[0]);
  57. static EnumTable::Enums vAlignCtrlEnums[] =
  58. {
  59. { VertAlignmentType::TopVAlign, "top" },
  60. { VertAlignmentType::MiddleVAlign, "middle" },
  61. { VertAlignmentType::BottomVAlign, "bottom" },
  62. { VertAlignmentType::DefaultVAlign, "default" }
  63. };
  64. static EnumTable gVAlignCtrlTable(3, &vAlignCtrlEnums[0]);
  65. //used to locate the next/prev responder when tab is pressed
  66. S32 GuiControl::smCursorChanged = -1;
  67. GuiControl *GuiControl::smPrevResponder = NULL;
  68. GuiControl *GuiControl::smCurResponder = NULL;
  69. GuiEditCtrl *GuiControl::smEditorHandle = NULL;
  70. bool GuiControl::smDesignTime = false;
  71. GuiControl::GuiControl()
  72. {
  73. mLayer = 0;
  74. mBounds.set(0, 0, 64, 64);
  75. mStoredExtent.set(0, 0);
  76. mRenderInsetLT.set(0, 0);
  77. mRenderInsetRB.set(0, 0);
  78. mMinExtent.set(0, 0);
  79. mStoredRelativePosH.set(0, 0);
  80. mStoredRelativePosV.set(0, 0);
  81. mUseRelPosH = false;
  82. mUseRelPosV = false;
  83. mProfile = NULL;
  84. mConsoleVariable = StringTable->EmptyString;
  85. mConsoleCommand = StringTable->EmptyString;
  86. mAltConsoleCommand = StringTable->EmptyString;
  87. mAcceleratorKey = StringTable->EmptyString;
  88. mLangTableName = StringTable->EmptyString;
  89. mText = StringTable->EmptyString;
  90. mTextID = StringTable->EmptyString;
  91. mAlignment = AlignmentType::DefaultAlign;
  92. mVAlignment = VertAlignmentType::DefaultVAlign;
  93. mFontSizeAdjust = 1;
  94. mFontColor.set(0, 0, 0, 255);
  95. mOverrideFontColor = false;
  96. mLangTable = NULL;
  97. mFirstResponder = NULL;
  98. mCanSaveFieldDictionary = false;
  99. mVisible = true;
  100. mActive = false;
  101. mAwake = false;
  102. mCanSave = true;
  103. mHorizSizing = horizResizeRight;
  104. mVertSizing = vertResizeBottom;
  105. mTooltipProfile = NULL;
  106. mTooltip = StringTable->EmptyString;
  107. mTipHoverTime = 1000;
  108. mTooltipWidth = 250;
  109. mIsContainer = true;
  110. mTextWrap = false;
  111. mTextExtend = false;
  112. mUseInput = true;
  113. }
  114. GuiControl::~GuiControl()
  115. {
  116. }
  117. bool GuiControl::onAdd()
  118. {
  119. // Let Parent Do Work.
  120. if(!Parent::onAdd())
  121. return false;
  122. // Grab the classname of this object
  123. const char *cName = getClassName();
  124. // if we're a pure GuiControl, then we're a container by default.
  125. if(dStrcmp("GuiControl", cName) == 0)
  126. mIsContainer = true;
  127. // Clamp to minExtent
  128. mBounds.extent.x = getMax( mMinExtent.x, mBounds.extent.x );
  129. mBounds.extent.y = getMax( mMinExtent.y, mBounds.extent.y );
  130. // Add to root group.
  131. Sim::getGuiGroup()->addObject(this);
  132. // Return Success.
  133. return true;
  134. }
  135. void GuiControl::onChildAdded( GuiControl *child )
  136. {
  137. if(mProfile)
  138. {
  139. //This will cause the child control to be centered if it needs to be.
  140. RectI innerRect = getInnerRect();
  141. child->parentResized(innerRect.extent, innerRect.extent);
  142. if (isMethod("onChildAdded"))
  143. {
  144. Con::executef(this, 3, "onChildAdded", child->getIdString());
  145. }
  146. }
  147. }
  148. void GuiControl::onChildRemoved(GuiControl* child)
  149. {
  150. if (mProfile && isMethod("onChildRemoved"))
  151. {
  152. Con::executef(this, 3, "onChildRemoved", child->getIdString());
  153. }
  154. }
  155. static EnumTable::Enums horzEnums[] =
  156. {
  157. { GuiControl::horizResizeRight, "right" },
  158. { GuiControl::horizResizeWidth, "width" },
  159. { GuiControl::horizResizeLeft, "left" },
  160. { GuiControl::horizResizeCenter, "center" },
  161. { GuiControl::horizResizeRelative, "relative" }
  162. };
  163. static EnumTable gHorizSizingTable(5, &horzEnums[0]);
  164. static EnumTable::Enums vertEnums[] =
  165. {
  166. { GuiControl::vertResizeBottom, "bottom" },
  167. { GuiControl::vertResizeHeight, "height" },
  168. { GuiControl::vertResizeTop, "top" },
  169. { GuiControl::vertResizeCenter, "center" },
  170. { GuiControl::vertResizeRelative, "relative" }
  171. };
  172. static EnumTable gVertSizingTable(5, &vertEnums[0]);
  173. void GuiControl::initPersistFields()
  174. {
  175. Parent::initPersistFields();
  176. // Things relevant only to the editor.
  177. addGroup("Gui Editing");
  178. addField("isContainer", TypeBool, Offset(mIsContainer, GuiControl));
  179. endGroup("Gui Editing");
  180. // Parent Group.
  181. addGroup("GuiControl");
  182. addField("Profile", TypeGuiProfile, Offset(mProfile, GuiControl));
  183. addField("HorizSizing", TypeEnum, Offset(mHorizSizing, GuiControl), 1, &gHorizSizingTable);
  184. addField("VertSizing", TypeEnum, Offset(mVertSizing, GuiControl), 1, &gVertSizingTable);
  185. addProtectedField("Position", TypePoint2I, Offset(mBounds.point, GuiControl), &setPositionFn, &defaultProtectedGetFn, "The location of the control in relation to its parent's content area.");
  186. addProtectedField("Extent", TypePoint2I, Offset(mBounds.extent, GuiControl), &setExtentFn, &defaultProtectedGetFn, "The size of the control writen as width and height.");
  187. addProtectedField("MinExtent", TypePoint2I, Offset(mMinExtent, GuiControl), &setMinExtentFn, &defaultProtectedGetFn, &writeMinExtentFn, "The extent will not shrink below this size.");
  188. addField("canSave", TypeBool, Offset(mCanSave, GuiControl));
  189. addField("Visible", TypeBool, Offset(mVisible, GuiControl));
  190. addField("useInput", TypeBool, Offset(mUseInput, GuiControl));
  191. addField("Variable", TypeString, Offset(mConsoleVariable, GuiControl));
  192. addField("Command", TypeString, Offset(mConsoleCommand, GuiControl));
  193. addField("AltCommand", TypeString, Offset(mAltConsoleCommand, GuiControl));
  194. addField("Accelerator", TypeString, Offset(mAcceleratorKey, GuiControl));
  195. addField("Active", TypeBool, Offset(mActive, GuiControl));
  196. endGroup("GuiControl");
  197. addGroup("ToolTip");
  198. addField("tooltipprofile", TypeGuiProfile, Offset(mTooltipProfile, GuiControl));
  199. addField("tooltip", TypeString, Offset(mTooltip, GuiControl));
  200. addField("tooltipWidth", TypeS32, Offset(mTooltipWidth, GuiControl));
  201. addField("hovertime", TypeS32, Offset(mTipHoverTime, GuiControl));
  202. endGroup("ToolTip");
  203. addGroup("Localization");
  204. addField("langTableMod", TypeString, Offset(mLangTableName, GuiControl));
  205. endGroup("Localization");
  206. addGroup("Text");
  207. addProtectedField("text", TypeCaseString, Offset(mText, GuiControl), setTextProperty, getTextProperty, "");
  208. addField("textID", TypeString, Offset(mTextID, GuiControl));
  209. addField("textWrap", TypeBool, Offset(mTextWrap, GuiControl), &writeTextWrapFn, "If true, text will wrap to additional lines.");
  210. addField("textExtend", TypeBool, Offset(mTextExtend, GuiControl), &writeTextExtendFn, "If true, extent will change based on the size of the control's text when possible.");
  211. addField("align", TypeEnum, Offset(mAlignment, GuiControl), 1, &gAlignCtrlTable);
  212. addField("vAlign", TypeEnum, Offset(mVAlignment, GuiControl), 1, &gVAlignCtrlTable);
  213. addField("fontSizeAdjust", TypeF32, Offset(mFontSizeAdjust, GuiControl), "A decimal value that is multiplied with the profile's fontSize to determine the control's actual font size.");
  214. addField("overrideFontColor", TypeBool, Offset(mOverrideFontColor, GuiControl), "If true, the control's fontColor will override the profile's font color.");
  215. addField("fontColor", TypeColorI, Offset(mFontColor, GuiControl), "A color to override the font color of the control's profile. OverrideFontColor must be set to true for this to work.");
  216. endGroup("Text");
  217. }
  218. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
  219. LangTable * GuiControl::getGUILangTable()
  220. {
  221. if(mLangTable)
  222. return mLangTable;
  223. if(mLangTableName && *mLangTableName)
  224. {
  225. mLangTable = (LangTable *)getModLangTable((const UTF8*)mLangTableName);
  226. return mLangTable;
  227. }
  228. GuiControl *parent = getParent();
  229. if(parent)
  230. return parent->getGUILangTable();
  231. return NULL;
  232. }
  233. const UTF8 * GuiControl::getGUIString(S32 id)
  234. {
  235. LangTable *lt = getGUILangTable();
  236. if(lt)
  237. return lt->getString(id);
  238. return NULL;
  239. }
  240. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
  241. void GuiControl::addObject(SimObject *object)
  242. {
  243. GuiControl *ctrl = dynamic_cast<GuiControl *>(object);
  244. if(!ctrl)
  245. {
  246. AssertWarn(0, "GuiControl::addObject: attempted to add NON GuiControl to set");
  247. return;
  248. }
  249. if(object->getGroup() == this)
  250. return;
  251. Parent::addObject(object);
  252. AssertFatal(!ctrl->isAwake(), "GuiControl::addObject: object is already awake before add");
  253. if(mAwake)
  254. ctrl->awaken();
  255. onChildAdded( ctrl );
  256. }
  257. void GuiControl::removeObject(SimObject *object)
  258. {
  259. GuiControl *ctrl = dynamic_cast<GuiControl *>(object);
  260. if (!ctrl)
  261. {
  262. AssertWarn(0, "GuiControl::removeObject: attempted to remove NON GuiControl from set");
  263. return;
  264. }
  265. AssertFatal(mAwake == ctrl->isAwake(), "GuiControl::removeObject: child control wake state is bad");
  266. if (mAwake)
  267. ctrl->sleep();
  268. Parent::removeObject(object);
  269. // If we are a child, notify our parent that we've been removed
  270. onChildRemoved(ctrl);
  271. }
  272. GuiControl *GuiControl::getParent()
  273. {
  274. SimObject *obj = getGroup();
  275. if (GuiControl* gui = dynamic_cast<GuiControl*>(obj))
  276. return gui;
  277. return 0;
  278. }
  279. GuiCanvas *GuiControl::getRoot()
  280. {
  281. GuiControl *root = NULL;
  282. GuiControl *parent = getParent();
  283. while (parent)
  284. {
  285. root = parent;
  286. parent = parent->getParent();
  287. }
  288. if (root)
  289. return dynamic_cast<GuiCanvas*>(root);
  290. else
  291. return NULL;
  292. }
  293. void GuiControl::inspectPreApply()
  294. {
  295. if(isEditMode())
  296. smEditorHandle->controlInspectPreApply(this);
  297. // The canvas never sleeps
  298. // This forced sleep will allow us to unload and reload things in the editor.
  299. mPreviouslyAwake = mAwake;
  300. if(mAwake && dynamic_cast<GuiCanvas*>(this) == NULL )
  301. {
  302. onSleep(); // release all our resources.
  303. }
  304. }
  305. void GuiControl::inspectPostApply()
  306. {
  307. // Shhhhhhh, you don't want to wake the canvas!
  308. // If this control was awake before we should revive it.
  309. if(mPreviouslyAwake && !mAwake && dynamic_cast<GuiCanvas*>(this) == NULL )
  310. {
  311. onWake();
  312. }
  313. if(isEditMode())
  314. smEditorHandle->controlInspectPostApply(this);
  315. }
  316. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
  317. Point2I GuiControl::localToGlobalCoord(const Point2I &src)
  318. {
  319. Point2I ret = src;
  320. ret += (mBounds.point + mRenderInsetLT);
  321. GuiControl *walk = getParent();
  322. while(walk)
  323. {
  324. ret += (walk->getPosition() + walk->mRenderInsetLT);
  325. walk = walk->getParent();
  326. }
  327. return ret;
  328. }
  329. Point2I GuiControl::globalToLocalCoord(const Point2I &src)
  330. {
  331. Point2I ret = src;
  332. ret -= (mBounds.point + mRenderInsetLT);
  333. GuiControl *walk = getParent();
  334. while(walk)
  335. {
  336. ret -= (walk->getPosition() + walk->mRenderInsetLT);
  337. walk = walk->getParent();
  338. }
  339. return ret;
  340. }
  341. //----------------------------------------------------------------
  342. void GuiControl::resize(const Point2I &newPosition, const Point2I &newExtent)
  343. {
  344. Point2I actualNewExtent = Point2I(getMax(mMinExtent.x, newExtent.x),
  345. getMax(mMinExtent.y, newExtent.y));
  346. Point2I oldExtent = mBounds.extent;
  347. //force center if using center positioning
  348. Point2I oldPosition = mBounds.point;
  349. Point2I actualNewPosition = Point2I(newPosition);
  350. GuiControl* parent = getParent();
  351. if (parent && parent->mProfile)
  352. {
  353. Point2I parentInnerExtent = parent->getInnerRect().extent;
  354. if (mHorizSizing == horizResizeCenter)
  355. {
  356. actualNewPosition.x = (parentInnerExtent.x - actualNewExtent.x) / 2;
  357. }
  358. if (mVertSizing == vertResizeCenter)
  359. {
  360. actualNewPosition.y = (parentInnerExtent.y - actualNewExtent.y) / 2;
  361. }
  362. }
  363. // only do the child control resizing stuff if you really need to.
  364. bool extentChanged = (actualNewExtent != oldExtent);
  365. bool positionChanged = (actualNewPosition != oldPosition);
  366. if (extentChanged) {
  367. //call set update both before and after
  368. setUpdate();
  369. mBounds.set(actualNewPosition, actualNewExtent);
  370. iterator i;
  371. for(i = begin(); i != end(); i++)
  372. {
  373. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  374. ctrl->parentResized(oldExtent - (ctrl->mRenderInsetLT + ctrl->mRenderInsetRB), actualNewExtent - (ctrl->mRenderInsetLT + ctrl->mRenderInsetRB));
  375. }
  376. if (parent)
  377. parent->childResized(this);
  378. setUpdate();
  379. if (isMethod("onResize"))
  380. {
  381. Con::executef(this, 2, "onResize");
  382. }
  383. }
  384. if(positionChanged)
  385. {
  386. mBounds.point = actualNewPosition;
  387. if(parent)
  388. parent->childMoved(this);
  389. if (isMethod("onMoved"))
  390. {
  391. Con::executef(this, 2, "onMoved");
  392. }
  393. }
  394. }
  395. void GuiControl::setPosition( const Point2I &newPosition )
  396. {
  397. resize( newPosition, mBounds.extent );
  398. }
  399. void GuiControl::setExtent( const Point2I &newExtent )
  400. {
  401. resize( mBounds.point, newExtent );
  402. }
  403. void GuiControl::setBounds( const RectI &newBounds )
  404. {
  405. resize( newBounds.point, newBounds.extent );
  406. }
  407. void GuiControl::setLeft( S32 newLeft )
  408. {
  409. resize( Point2I( newLeft, mBounds.point.y), mBounds.extent );
  410. }
  411. void GuiControl::setTop( S32 newTop )
  412. {
  413. resize( Point2I( mBounds.point.x, newTop ), mBounds.extent );
  414. }
  415. void GuiControl::setWidth( S32 newWidth )
  416. {
  417. resize( mBounds.point, Point2I( newWidth, mBounds.extent.y ) );
  418. }
  419. void GuiControl::setHeight( S32 newHeight )
  420. {
  421. resize( mBounds.point, Point2I( mBounds.extent.x, newHeight ) );
  422. }
  423. void GuiControl::childResized(GuiControl *child)
  424. {
  425. // Default to do nothing. Do not call resize from here as it will create an infinite loop.
  426. if (isMethod("onChildResized"))
  427. {
  428. Con::executef(this, 3, "onChildResized", child->getIdString());
  429. }
  430. }
  431. void GuiControl::childMoved(GuiControl* child)
  432. {
  433. // Default to do nothing. Do not call resize from here as it will create an infinite loop.
  434. if (isMethod("onChildMoved"))
  435. {
  436. Con::executef(this, 3, "onChildMoved", child->getIdString());
  437. }
  438. }
  439. void GuiControl::childrenReordered()
  440. {
  441. // Default to do nothing.
  442. if (isMethod("onChildrenReordered"))
  443. {
  444. Con::executef(this, 2, "onChildrenReordered");
  445. }
  446. }
  447. void GuiControl::parentResized(const Point2I &oldParentExtent, const Point2I &newParentExtent)
  448. {
  449. Point2I newPosition = getPosition();
  450. Point2I newExtent = getExtent();
  451. S32 deltaX = newParentExtent.x - oldParentExtent.x;
  452. S32 deltaY = newParentExtent.y - oldParentExtent.y;
  453. //In the case of centering, we want to make doubly sure we are using the inner rect.
  454. GuiControl* parent = getParent();
  455. Point2I parentInnerExt = Point2I(newParentExtent);
  456. if(mHorizSizing == horizResizeCenter || mVertSizing == vertResizeCenter)
  457. {
  458. //This is based on the "new" outer extent of the parent.
  459. parentInnerExt = parent->getInnerRect().extent;
  460. }
  461. if (mHorizSizing == horizResizeCenter)
  462. newPosition.x = (parentInnerExt.x - mBounds.extent.x) >> 1;
  463. else if (mHorizSizing == horizResizeWidth)
  464. newExtent.x += deltaX;
  465. else if (mHorizSizing == horizResizeLeft)
  466. newPosition.x += deltaX;
  467. else if (mHorizSizing == horizResizeRelative && oldParentExtent.x != 0)
  468. {
  469. Point2F percent = relPosBatteryH(newPosition.x, newExtent.x, oldParentExtent.x);
  470. S32 newLeft = mRound(percent.x * newParentExtent.x);
  471. S32 newRight = mRound(percent.y * newParentExtent.x);
  472. newPosition.x = newLeft;
  473. newExtent.x = newRight - newLeft;
  474. }
  475. if (mVertSizing == vertResizeCenter)
  476. newPosition.y = (parentInnerExt.y - mBounds.extent.y) >> 1;
  477. else if (mVertSizing == vertResizeHeight)
  478. newExtent.y += deltaY;
  479. else if (mVertSizing == vertResizeTop)
  480. newPosition.y += deltaY;
  481. else if(mVertSizing == vertResizeRelative && oldParentExtent.y != 0)
  482. {
  483. Point2F percent = relPosBatteryV(newPosition.y, newExtent.y, oldParentExtent.y);
  484. S32 newTop = mRound(percent.x * newParentExtent.y);
  485. S32 newBottom = mRound(percent.y * newParentExtent.y);
  486. newPosition.y = newTop;
  487. newExtent.y = newBottom - newTop;
  488. }
  489. newExtent = extentBattery(newExtent);
  490. resize(newPosition, newExtent);
  491. }
  492. Point2I GuiControl::extentBattery(Point2I &newExtent)
  493. {
  494. if (mMinExtent.x == 0 && mMinExtent.y == 0)
  495. {
  496. return newExtent;
  497. }
  498. Point2I result = Point2I(newExtent);
  499. if (mHorizSizing != horizResizeRelative)
  500. {
  501. if (newExtent.x < mBounds.extent.x && newExtent.x < mMinExtent.x)
  502. {
  503. mStoredExtent.x += mBounds.extent.x > mMinExtent.x ? (mMinExtent.x - newExtent.x) : (mBounds.extent.x - newExtent.x);
  504. result.x = mMinExtent.x;
  505. }
  506. else if (newExtent.x > mBounds.extent.x && mStoredExtent.x > 0)
  507. {
  508. S32 charge = getMin(newExtent.x - mBounds.extent.x, mStoredExtent.x);
  509. mStoredExtent.x -= charge;
  510. result.x = newExtent.x - charge;
  511. }
  512. }
  513. if (mVertSizing != vertResizeRelative)
  514. {
  515. if (newExtent.y < mBounds.extent.y && newExtent.y < mMinExtent.y)
  516. {
  517. mStoredExtent.y += mBounds.extent.y > mMinExtent.y ? (mMinExtent.y - newExtent.y) : (mBounds.extent.y - newExtent.y);
  518. result.y = mMinExtent.y;
  519. }
  520. else if (newExtent.y > mBounds.extent.y && mStoredExtent.y > 0)
  521. {
  522. S32 charge = getMin(newExtent.y - mBounds.extent.y, mStoredExtent.y);
  523. mStoredExtent.y -= charge;
  524. result.y = newExtent.y - charge;
  525. }
  526. }
  527. return result;
  528. }
  529. Point2F GuiControl::relPosBatteryH(S32 pos, S32 ext, S32 parentExt)
  530. {
  531. if (!mUseRelPosH)
  532. {
  533. relPosBattery(mStoredRelativePosH, pos, ext, parentExt);
  534. mUseRelPosH = true;
  535. }
  536. return mStoredRelativePosH;
  537. }
  538. Point2F GuiControl::relPosBatteryV(S32 pos, S32 ext, S32 parentExt)
  539. {
  540. if (!mUseRelPosV)
  541. {
  542. relPosBattery(mStoredRelativePosV, pos, ext, parentExt);
  543. mUseRelPosV = true;
  544. }
  545. return mStoredRelativePosV;
  546. }
  547. void GuiControl::relPosBattery(Point2F& battery, S32 pos, S32 ext, S32 parentExt)
  548. {
  549. battery.x = static_cast<F32>(pos) / parentExt;
  550. battery.y = static_cast<F32>(pos + ext) / parentExt;
  551. }
  552. //----------------------------------------------------------------
  553. void GuiControl::onRender(Point2I offset, const RectI &updateRect)
  554. {
  555. RectI ctrlRect = applyMargins(offset, mBounds.extent, NormalState, mProfile);
  556. if (!ctrlRect.isValidRect())
  557. {
  558. return;
  559. }
  560. renderUniversalRect(ctrlRect, mProfile, NormalState);
  561. //Render Text
  562. dglSetBitmapModulation(getFontColor(mProfile));
  563. RectI fillRect = applyBorders(ctrlRect.point, ctrlRect.extent, NormalState, mProfile);
  564. RectI contentRect = applyPadding(fillRect.point, fillRect.extent, NormalState, mProfile);
  565. if(contentRect.isValidRect())
  566. {
  567. renderText(contentRect.point, contentRect.extent, mText, mProfile);
  568. //Render the childen
  569. renderChildControls(offset, contentRect, updateRect);
  570. }
  571. }
  572. RectI GuiControl::applyMargins(Point2I &offset, Point2I &extent, GuiControlState currentState, GuiControlProfile *profile)
  573. {
  574. //Get the border profiles
  575. GuiBorderProfile *leftProfile = profile->getLeftBorder();
  576. GuiBorderProfile *rightProfile = profile->getRightBorder();
  577. GuiBorderProfile *topProfile = profile->getTopBorder();
  578. GuiBorderProfile *bottomProfile = profile->getBottomBorder();
  579. S32 leftSize = (leftProfile) ? leftProfile->getMargin(currentState) : 0;
  580. S32 rightSize = (rightProfile) ? rightProfile->getMargin(currentState) : 0;
  581. S32 topSize = (topProfile) ? topProfile->getMargin(currentState) : 0;
  582. S32 bottomSize = (bottomProfile) ? bottomProfile->getMargin(currentState) : 0;
  583. return RectI(offset.x + leftSize, offset.y + topSize, (extent.x - leftSize) - rightSize, (extent.y - topSize) - bottomSize);
  584. }
  585. RectI GuiControl::applyBorders(Point2I &offset, Point2I &extent, GuiControlState currentState, GuiControlProfile *profile)
  586. {
  587. //Get the border profiles
  588. GuiBorderProfile *leftProfile = profile->getLeftBorder();
  589. GuiBorderProfile *rightProfile = profile->getRightBorder();
  590. GuiBorderProfile *topProfile = profile->getTopBorder();
  591. GuiBorderProfile *bottomProfile = profile->getBottomBorder();
  592. S32 leftSize = (leftProfile) ? leftProfile->getBorder(currentState) : 0;
  593. S32 rightSize = (rightProfile) ? rightProfile->getBorder(currentState) : 0;
  594. S32 topSize = (topProfile) ? topProfile->getBorder(currentState) : 0;
  595. S32 bottomSize = (bottomProfile) ? bottomProfile->getBorder(currentState) : 0;
  596. return RectI(offset.x + leftSize, offset.y + topSize, (extent.x - leftSize) - rightSize, (extent.y - topSize) - bottomSize);
  597. }
  598. RectI GuiControl::applyPadding(Point2I &offset, Point2I &extent, GuiControlState currentState, GuiControlProfile *profile)
  599. {
  600. //Get the border profiles
  601. GuiBorderProfile *leftProfile = profile->getLeftBorder();
  602. GuiBorderProfile *rightProfile = profile->getRightBorder();
  603. GuiBorderProfile *topProfile = profile->getTopBorder();
  604. GuiBorderProfile *bottomProfile = profile->getBottomBorder();
  605. S32 leftSize = (leftProfile) ? leftProfile->getPadding(currentState) : 0;
  606. S32 rightSize = (rightProfile) ? rightProfile->getPadding(currentState) : 0;
  607. S32 topSize = (topProfile) ? topProfile->getPadding(currentState) : 0;
  608. S32 bottomSize = (bottomProfile) ? bottomProfile->getPadding(currentState) : 0;
  609. return RectI(offset.x + leftSize, offset.y + topSize, (extent.x - leftSize) - rightSize, (extent.y - topSize) - bottomSize);
  610. }
  611. RectI GuiControl::getInnerRect(GuiControlState currentState)
  612. {
  613. return getInnerRect(mBounds.point, mBounds.extent, currentState, mProfile);
  614. }
  615. RectI GuiControl::getInnerRect(Point2I& offset, GuiControlState currentState)
  616. {
  617. return getInnerRect(offset, mBounds.extent, currentState, mProfile);
  618. }
  619. RectI GuiControl::getInnerRect(Point2I &offset, Point2I &extent, GuiControlState currentState, GuiControlProfile *profile)
  620. {
  621. if (!profile)
  622. {
  623. return mBounds;
  624. }
  625. //Get the border profiles
  626. GuiBorderProfile *leftProfile = profile->getLeftBorder();
  627. GuiBorderProfile *rightProfile = profile->getRightBorder();
  628. GuiBorderProfile *topProfile = profile->getTopBorder();
  629. GuiBorderProfile *bottomProfile = profile->getBottomBorder();
  630. S32 leftSize = (leftProfile) ? leftProfile->getMargin(currentState) + leftProfile->getBorder(currentState) + leftProfile->getPadding(currentState) : 0;
  631. S32 rightSize = (rightProfile) ? rightProfile->getMargin(currentState) + rightProfile->getBorder(currentState) + rightProfile->getPadding(currentState) : 0;
  632. S32 topSize = (topProfile) ? topProfile->getMargin(currentState) + topProfile->getBorder(currentState) + topProfile->getPadding(currentState) : 0;
  633. S32 bottomSize = (bottomProfile) ? bottomProfile->getMargin(currentState) + bottomProfile->getBorder(currentState) + bottomProfile->getPadding(currentState) : 0;
  634. return RectI(offset.x + leftSize, offset.y + topSize, (extent.x - leftSize) - rightSize, (extent.y - topSize) - bottomSize);
  635. }
  636. Point2I GuiControl::getOuterExtent(Point2I &innerExtent, GuiControlState currentState, GuiControlProfile *profile)
  637. {
  638. return Point2I(getOuterWidth(innerExtent.x, currentState, profile), getOuterHeight(innerExtent.y, currentState, profile));
  639. }
  640. S32 GuiControl::getOuterWidth(S32 innerWidth, GuiControlState currentState, GuiControlProfile* profile)
  641. {
  642. //Get the border profiles
  643. GuiBorderProfile* leftProfile = profile->getLeftBorder();
  644. GuiBorderProfile* rightProfile = profile->getRightBorder();
  645. S32 leftSize = (leftProfile) ? leftProfile->getMargin(currentState) + leftProfile->getBorder(currentState) + leftProfile->getPadding(currentState) : 0;
  646. S32 rightSize = (rightProfile) ? rightProfile->getMargin(currentState) + rightProfile->getBorder(currentState) + rightProfile->getPadding(currentState) : 0;
  647. return innerWidth + leftSize + rightSize;
  648. }
  649. S32 GuiControl::getOuterHeight(S32 innerHeight, GuiControlState currentState, GuiControlProfile* profile)
  650. {
  651. //Get the border profiles
  652. GuiBorderProfile* topProfile = profile->getTopBorder();
  653. GuiBorderProfile* bottomProfile = profile->getBottomBorder();
  654. S32 topSize = (topProfile) ? topProfile->getMargin(currentState) + topProfile->getBorder(currentState) + topProfile->getPadding(currentState) : 0;
  655. S32 bottomSize = (bottomProfile) ? bottomProfile->getMargin(currentState) + bottomProfile->getBorder(currentState) + bottomProfile->getPadding(currentState) : 0;
  656. return innerHeight + topSize + bottomSize;
  657. }
  658. bool GuiControl::renderTooltip(Point2I &cursorPos, const char* tipText )
  659. {
  660. #if !defined(TORQUE_OS_IOS) && !defined(TORQUE_OS_ANDROID) && !defined(TORQUE_OS_EMSCRIPTEN)
  661. // Short Circuit.
  662. if (!mAwake)
  663. return false;
  664. if ( dStrlen( mTooltip ) == 0 && ( tipText == NULL || dStrlen( tipText ) == 0 ) )
  665. return false;
  666. const char* renderTip = mTooltip;
  667. if( tipText != NULL )
  668. renderTip = tipText;
  669. // Finish if no root.
  670. GuiCanvas *root = getRoot();
  671. if ( !root )
  672. return false;
  673. if (!mTooltipProfile)
  674. setField("TooltipProfile", "GuiTooltipProfile");
  675. GFont *font = mTooltipProfile->getFont();
  676. // Set text bounds.
  677. Point2I textBounds( 0, 0 );
  678. // Fetch the width of a space.
  679. const S32 spaceWidth = (S32)font->getStrWidth(" ");
  680. // Fetch the maximum allowed tooltip extent.
  681. const S32 maxTooltipWidth = mTooltipWidth;
  682. // Fetch word count.
  683. const S32 wordCount = StringUnit::getUnitCount( renderTip, " " );
  684. // Reset line storage.
  685. const S32 tooltipLineStride = (S32)font->getHeight() + 4;
  686. const S32 maxTooltipLines = 20;
  687. S32 tooltipLineCount = 0;
  688. S32 tooltipLineWidth = 0;
  689. FrameTemp<StringBuffer> tooltipLines( maxTooltipLines );
  690. // Reset word indexing.
  691. S32 wordStartIndex = 0;
  692. S32 wordEndIndex = 0;
  693. // Search for end word.
  694. while( true )
  695. {
  696. // Do we have any words left?
  697. if ( wordEndIndex < wordCount )
  698. {
  699. // Yes, so fetch the word.
  700. const char* pWord = StringUnit::getUnit( renderTip, wordEndIndex, " " );
  701. // Add word length.
  702. const S32 wordLength = (S32)font->getStrWidth( pWord ) + spaceWidth;
  703. // Do we still have room?
  704. if ( (tooltipLineWidth + wordLength) < maxTooltipWidth )
  705. {
  706. // Yes, so add word length.
  707. tooltipLineWidth += wordLength;
  708. // Next word.
  709. wordEndIndex++;
  710. continue;
  711. }
  712. // Do we have any lines left?
  713. if ( tooltipLineCount < maxTooltipLines )
  714. {
  715. // Yes, so insert line.
  716. tooltipLines[tooltipLineCount++] = StringUnit::getUnits( renderTip, wordStartIndex, wordEndIndex-1, " " );
  717. // Update horizontal text bounds.
  718. if ( tooltipLineWidth > textBounds.x )
  719. textBounds.x = tooltipLineWidth;
  720. }
  721. // Set new line length.
  722. tooltipLineWidth = wordLength;
  723. // Set word start.
  724. wordStartIndex = wordEndIndex;
  725. // Next word.
  726. wordEndIndex++;
  727. continue;
  728. }
  729. // Do we have any words left?
  730. if ( wordStartIndex < wordCount )
  731. {
  732. // Yes, so do we have any lines left?
  733. if ( tooltipLineCount < maxTooltipLines )
  734. {
  735. // Yes, so insert line.
  736. tooltipLines[tooltipLineCount++] = StringUnit::getUnits( renderTip, wordStartIndex, wordCount-1, " " );
  737. // Update horizontal text bounds.
  738. if ( tooltipLineWidth > textBounds.x )
  739. textBounds.x = tooltipLineWidth;
  740. }
  741. }
  742. break;
  743. }
  744. // Controls the size of the inside (gutter) tooltip region.
  745. const S32 tooltipGutterSize = 5;
  746. // Adjust text bounds.
  747. textBounds.x += tooltipGutterSize * 2;
  748. textBounds.y = (((S32)font->getHeight() + 4) * tooltipLineCount - 4) + (tooltipGutterSize * 2);
  749. // Adjust to tooltip is always on-screen.
  750. Point2I screensize = Platform::getWindowSize();
  751. Point2I offset = cursorPos;
  752. offset.y += 22;
  753. if (screensize.x < (offset.x + textBounds.x))
  754. offset.x = screensize.x - textBounds.x;
  755. if(screensize.y < (offset.y + textBounds.y) )
  756. offset.y = screensize.y - textBounds.y;
  757. // Fetch the old clip.
  758. RectI oldClip = dglGetClipRect();
  759. // Set rectangle for the box, and set the clip rectangle.
  760. RectI rect(offset, textBounds);
  761. dglSetClipRect(rect);
  762. // Draw body and border of the tool tip
  763. renderUniversalRect(rect, mTooltipProfile, NormalState);
  764. // Draw the text centered in the tool tip box
  765. dglSetBitmapModulation( mTooltipProfile->mFontColor );
  766. Point2I start( tooltipGutterSize, tooltipGutterSize );
  767. for ( S32 lineIndex = 0; lineIndex < tooltipLineCount; lineIndex++ )
  768. {
  769. dglDrawText( font, start + offset, tooltipLines[lineIndex].getPtr8(), mProfile->mFontColors );
  770. offset.y += tooltipLineStride;
  771. }
  772. dglSetClipRect( oldClip );
  773. #endif
  774. return true;
  775. }
  776. void GuiControl::renderChildControls(Point2I offset, RectI content, const RectI &updateRect)
  777. {
  778. // offset is the upper-left corner of this control in screen coordinates. It should almost always be the same offset passed into the onRender method.
  779. // updateRect is the area that this control was allowed to draw in. It should almost always be the same as the value in onRender.
  780. // content is the area that child controls are allowed to draw in.
  781. RectI clipRect = content;
  782. if(clipRect.intersect(dglGetClipRect()))
  783. {
  784. S32 size = objectList.size();
  785. S32 size_cpy = size;
  786. //-Mat look through our vector all normal-like, trying to use an iterator sometimes gives us
  787. //bad cast on good objects
  788. for( S32 count = 0; count < objectList.size(); count++ )
  789. {
  790. GuiControl *ctrl = (GuiControl *)objectList[count];
  791. if( ctrl == NULL ) {
  792. Con::errorf( "GuiControl::renderChildControls() object %i is NULL", count );
  793. continue;
  794. }
  795. if (ctrl->mVisible)
  796. {
  797. ctrl->mRenderInsetLT = content.point - offset;
  798. ctrl->mRenderInsetRB = mBounds.extent - (ctrl->mRenderInsetLT + content.extent);
  799. Point2I childPosition = content.point + ctrl->getPosition();
  800. RectI childClip(childPosition, ctrl->getExtent());
  801. if (childClip.intersect(clipRect))
  802. {
  803. RectI old = dglGetClipRect();
  804. dglSetClipRect(clipRect);
  805. glDisable(GL_CULL_FACE);
  806. ctrl->onRender(childPosition, RectI(childPosition, ctrl->getExtent()));
  807. dglSetClipRect(old);
  808. }
  809. }
  810. size_cpy = objectList.size(); // CHRIS: i know its wierd but the size of the list changes sometimes during execution of this loop
  811. if(size != size_cpy)
  812. {
  813. size = size_cpy;
  814. count--; // CHRIS: just to make sure one wasnt skipped.
  815. }
  816. }
  817. }
  818. }
  819. void GuiControl::setUpdateRegion(Point2I pos, Point2I ext)
  820. {
  821. Point2I upos = localToGlobalCoord(pos);
  822. GuiCanvas *root = getRoot();
  823. if (root)
  824. {
  825. root->addUpdateRegion(upos, ext);
  826. }
  827. }
  828. void GuiControl::setUpdate()
  829. {
  830. setUpdateRegion(Point2I(0,0), mBounds.extent);
  831. }
  832. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
  833. void GuiControl::awaken()
  834. {
  835. AssertFatal(!mAwake, "GuiControl::awaken: control is already awake");
  836. if(mAwake)
  837. return;
  838. iterator i;
  839. for(i = begin(); i != end(); i++)
  840. {
  841. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  842. AssertFatal(!ctrl->isAwake(), "GuiControl::awaken: child control is already awake");
  843. if(!ctrl->isAwake())
  844. ctrl->awaken();
  845. }
  846. AssertFatal(!mAwake, "GuiControl::awaken: should not be awake here");
  847. if(!mAwake)
  848. {
  849. if(!onWake())
  850. {
  851. Con::errorf(ConsoleLogEntry::General, "GuiControl::awaken: failed onWake for obj: %s", getName());
  852. AssertFatal(0, "GuiControl::awaken: failed onWake");
  853. deleteObject();
  854. }
  855. else
  856. {
  857. if (mTextID && *mTextID != 0)
  858. setTextID(mTextID);
  859. }
  860. }
  861. }
  862. void GuiControl::sleep()
  863. {
  864. AssertFatal(mAwake, "GuiControl::sleep: control is not awake");
  865. if(!mAwake)
  866. return;
  867. iterator i;
  868. for(i = begin(); i != end(); i++)
  869. {
  870. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  871. AssertFatal(ctrl->isAwake(), "GuiControl::sleep: child control is already asleep");
  872. if(ctrl->isAwake())
  873. ctrl->sleep();
  874. }
  875. AssertFatal(mAwake, "GuiControl::sleep: should not be asleep here");
  876. if(mAwake)
  877. onSleep();
  878. }
  879. void GuiControl::preRender()
  880. {
  881. AssertFatal(mAwake, "GuiControl::preRender: control is not awake");
  882. if(!mAwake)
  883. return;
  884. iterator i;
  885. for(i = begin(); i != end(); i++)
  886. {
  887. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  888. if (ctrl->isVisible())
  889. {
  890. ctrl->preRender();
  891. }
  892. }
  893. onPreRender();
  894. }
  895. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
  896. bool GuiControl::onWake()
  897. {
  898. AssertFatal( !mAwake, "GuiControl::onWake: control is already awake" );
  899. if( mAwake )
  900. return false;
  901. // [tom, 4/18/2005] Cause mLangTable to be refreshed in case it was changed
  902. mLangTable = NULL;
  903. // Grab the classname of this object
  904. const char *cName = getClassName();
  905. //make sure we have a profile
  906. if( !mProfile )
  907. {
  908. // Ensure the classname is a valid name...
  909. if( cName && cName[0] )
  910. {
  911. S32 pos = 0;
  912. for( pos = 0; pos <= (S32)dStrlen( cName ); pos++ )
  913. if( !dStrncmp( cName + pos, "Ctrl", 4 ) )
  914. break;
  915. if( pos != 0 ) {
  916. char buff[255];
  917. dStrncpy( buff, cName, pos );
  918. buff[pos] = '\0';
  919. dStrcat( buff, "Profile\0" );
  920. SimObject *obj = Sim::findObject( buff );
  921. if( obj )
  922. mProfile = dynamic_cast<GuiControlProfile*>( obj );
  923. }
  924. }
  925. // Ok lets check to see if that worked
  926. if( !mProfile ) {
  927. SimObject *obj = Sim::findObject( "GuiDefaultProfile" );
  928. if( obj )
  929. mProfile = dynamic_cast<GuiControlProfile*>(obj);
  930. }
  931. AssertFatal( mProfile, avar( "GuiControl: %s created with no profile.", getName() ) );
  932. }
  933. //set the flag
  934. mAwake = true;
  935. //set the layer
  936. GuiCanvas *root = getRoot();
  937. AssertFatal(root, "Unable to get the root Canvas.");
  938. GuiControl *parent = getParent();
  939. if (parent && parent != root)
  940. mLayer = parent->mLayer;
  941. //make sure the first responder exists
  942. if (! mFirstResponder)
  943. mFirstResponder = findFirstTabable();
  944. //see if we should force this control to be the first responder
  945. //if (mProfile->mTabable && mProfile->mCanKeyFocus)
  946. // setFirstResponder();
  947. //increment the profile
  948. mProfile->incRefCount();
  949. // Only invoke script callbacks if we have a namespace in which to do so
  950. // This will suppress warnings
  951. if( isMethod("onWake") )
  952. Con::executef(this, 1, "onWake");
  953. if (mTooltipProfile != NULL)
  954. mTooltipProfile->incRefCount();
  955. return true;
  956. }
  957. void GuiControl::onSleep()
  958. {
  959. AssertFatal(mAwake, "GuiControl::onSleep: control is not awake");
  960. if(!mAwake)
  961. return;
  962. //decrement the profile referrence
  963. if( mProfile != NULL )
  964. mProfile->decRefCount();
  965. clearFirstResponder();
  966. mouseUnlock();
  967. // Only invoke script callbacks if we have a namespace in which to do so
  968. // This will suppress warnings
  969. if( isMethod("onSleep") )
  970. Con::executef(this, 1, "onSleep");
  971. if (mTooltipProfile != NULL)
  972. mTooltipProfile->decRefCount();
  973. // Set Flag
  974. mAwake = false;
  975. }
  976. void GuiControl::setControlProfile(GuiControlProfile *prof)
  977. {
  978. AssertFatal(prof, "GuiControl::setControlProfile: invalid profile");
  979. if(prof == mProfile)
  980. return;
  981. if(mAwake)
  982. mProfile->decRefCount();
  983. mProfile = prof;
  984. if(mAwake)
  985. mProfile->incRefCount();
  986. }
  987. void GuiControl::onPreRender()
  988. {
  989. // do nothing.
  990. }
  991. //-----------------------------------------------------------------------------
  992. // checks up the parent hierarchy - if anyone above us is not savable returns false
  993. // otherwise, returns true.
  994. //-----------------------------------------------------------------------------
  995. bool GuiControl::getCanSaveParent()
  996. {
  997. GuiControl *walk = this;
  998. while(walk)
  999. {
  1000. if(!walk->getCanSave())
  1001. return false;
  1002. walk = walk->getParent();
  1003. }
  1004. return true;
  1005. }
  1006. //-----------------------------------------------------------------------------
  1007. // Can we Save to a TorqueScript file?
  1008. //-----------------------------------------------------------------------------
  1009. bool GuiControl::getCanSave()
  1010. {
  1011. return mCanSave;
  1012. }
  1013. //-----------------------------------------------------------------------------
  1014. // Sets whether we can save out to a file (TorqueScript)
  1015. //-----------------------------------------------------------------------------
  1016. void GuiControl::setCanSave(bool bCanSave)
  1017. {
  1018. mCanSave = bCanSave;
  1019. }
  1020. ////////////////////////////////////////////////////////////////////////////////////////////////////
  1021. // checks out mCanSave flag, if true just passes along to our parent,
  1022. // if false, then we return without writing. Note, also, that
  1023. // if our parent is not writeable, then we should not be writable...
  1024. ////////////////////////////////////////////////////////////////////////////////////////////////////
  1025. void GuiControl::write(Stream &stream, U32 tabStop, U32 flags)
  1026. {
  1027. //note: this will return false if either we, or any of our parents, are non-save controls
  1028. bool bCanSave = getCanSaveParent();
  1029. if(bCanSave)
  1030. {
  1031. Parent::write(stream, tabStop, flags);
  1032. }
  1033. }
  1034. //This is only called if the control is deleted, not when the control is removed from its parent.
  1035. void GuiControl::onRemove()
  1036. {
  1037. Parent::onRemove();
  1038. }
  1039. //For GuiControls, this will always just before it is actually removed.
  1040. void GuiControl::onGroupRemove()
  1041. {
  1042. clearFirstResponder();
  1043. }
  1044. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
  1045. const char *GuiControl::getScriptValue()
  1046. {
  1047. return NULL;
  1048. }
  1049. void GuiControl::setScriptValue(const char *value)
  1050. {
  1051. }
  1052. void GuiControl::setConsoleVariable(const char *variable)
  1053. {
  1054. if (variable)
  1055. {
  1056. mConsoleVariable = StringTable->insert(variable);
  1057. }
  1058. else
  1059. {
  1060. mConsoleVariable = StringTable->EmptyString;
  1061. }
  1062. }
  1063. //-----------------------------------------------------------------------------
  1064. // finds and returns the first immediate child of ours whose
  1065. // internal name matches the passed String. returns Null if not found.
  1066. //-----------------------------------------------------------------------------
  1067. void GuiControl::setConsoleCommand(const char *newCmd)
  1068. {
  1069. if (newCmd)
  1070. mConsoleCommand = StringTable->insert(newCmd);
  1071. else
  1072. mConsoleCommand = StringTable->EmptyString;
  1073. }
  1074. const char * GuiControl::getConsoleCommand()
  1075. {
  1076. return mConsoleCommand;
  1077. }
  1078. void GuiControl::setSizing(S32 horz, S32 vert)
  1079. {
  1080. mHorizSizing = horz;
  1081. mVertSizing = vert;
  1082. }
  1083. void GuiControl::setVariable(const char *value)
  1084. {
  1085. if (mConsoleVariable[0])
  1086. Con::setVariable(mConsoleVariable, value);
  1087. }
  1088. void GuiControl::setIntVariable(S32 value)
  1089. {
  1090. if (mConsoleVariable[0])
  1091. Con::setIntVariable(mConsoleVariable, value);
  1092. }
  1093. void GuiControl::setFloatVariable(F32 value)
  1094. {
  1095. if (mConsoleVariable[0])
  1096. Con::setFloatVariable(mConsoleVariable, value);
  1097. }
  1098. const char * GuiControl::getVariable()
  1099. {
  1100. if (mConsoleVariable[0])
  1101. return Con::getVariable(mConsoleVariable);
  1102. else return NULL;
  1103. }
  1104. S32 GuiControl::getIntVariable()
  1105. {
  1106. if (mConsoleVariable[0])
  1107. return Con::getIntVariable(mConsoleVariable);
  1108. else return 0;
  1109. }
  1110. F32 GuiControl::getFloatVariable()
  1111. {
  1112. if (mConsoleVariable[0])
  1113. return Con::getFloatVariable(mConsoleVariable);
  1114. else return 0.0f;
  1115. }
  1116. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
  1117. bool GuiControl::cursorInControl()
  1118. {
  1119. GuiCanvas *root = getRoot();
  1120. if (! root) return false;
  1121. Point2I pt = root->getCursorPos();
  1122. Point2I offset = localToGlobalCoord(Point2I(0, 0));
  1123. if (pt.x >= offset.x && pt.y >= offset.y &&
  1124. pt.x < offset.x + mBounds.extent.x && pt.y < offset.y + mBounds.extent.y)
  1125. {
  1126. return true;
  1127. }
  1128. else
  1129. {
  1130. return false;
  1131. }
  1132. }
  1133. bool GuiControl::pointInControl(const Point2I& parentCoordPoint)
  1134. {
  1135. S32 xt = parentCoordPoint.x - mBounds.point.x;
  1136. S32 yt = parentCoordPoint.y - mBounds.point.y;
  1137. return xt >= 0 && yt >= 0 && xt < mBounds.extent.x && yt < mBounds.extent.y;
  1138. }
  1139. GuiControl* GuiControl::findHitControl(const Point2I &pt, S32 initialLayer)
  1140. {
  1141. iterator i = end(); // find in z order (last to first)
  1142. while (i != begin())
  1143. {
  1144. i--;
  1145. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  1146. if (initialLayer >= 0 && ctrl->mLayer > initialLayer)
  1147. {
  1148. continue;
  1149. }
  1150. else if (ctrl->mVisible && ctrl->pointInControl(pt - ctrl->mRenderInsetLT) && ctrl->mUseInput)
  1151. {
  1152. Point2I ptemp = pt - (ctrl->mBounds.point + ctrl->mRenderInsetLT);
  1153. GuiControl *hitCtrl = ctrl->findHitControl(ptemp);
  1154. if(hitCtrl->mUseInput)
  1155. return hitCtrl;
  1156. }
  1157. }
  1158. return this;
  1159. }
  1160. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
  1161. bool GuiControl::isMouseLocked()
  1162. {
  1163. if (isEditMode())
  1164. {
  1165. return smEditorHandle->editIsMouseLocked(this);
  1166. }
  1167. GuiCanvas *root = getRoot();
  1168. return root ? root->getMouseLockedControl() == this : false;
  1169. }
  1170. void GuiControl::mouseLock(GuiControl *lockingControl)
  1171. {
  1172. if (isEditMode())
  1173. {
  1174. smEditorHandle->editMouseLock(lockingControl);
  1175. return;
  1176. }
  1177. GuiCanvas *root = getRoot();
  1178. if (root)
  1179. root->mouseLock(lockingControl);
  1180. }
  1181. void GuiControl::mouseLock()
  1182. {
  1183. mouseLock(this);
  1184. }
  1185. void GuiControl::mouseUnlock()
  1186. {
  1187. if (isEditMode())
  1188. {
  1189. smEditorHandle->editMouseUnlock();
  1190. return;
  1191. }
  1192. GuiCanvas *root = getRoot();
  1193. if (root)
  1194. root->mouseUnlock(this);
  1195. }
  1196. bool GuiControl::sendScriptMouseEvent(const char* name, const GuiEvent& event)
  1197. {
  1198. bool consumed = false;
  1199. if (isMethod(name))
  1200. {
  1201. char buf[3][32];
  1202. dSprintf(buf[0], 32, "%d", event.modifier);
  1203. dSprintf(buf[1], 32, "%d %d", event.mousePoint.x, event.mousePoint.y);
  1204. dSprintf(buf[2], 32, "%d", event.mouseClickCount);
  1205. consumed = dAtob(Con::executef(this, 4, name, buf[0], buf[1], buf[2]));
  1206. }
  1207. return consumed;
  1208. }
  1209. bool GuiControl::sendScriptKeyEvent(const char* name, const InputEvent& event)
  1210. {
  1211. bool consumed = false;
  1212. if (isMethod(name))
  1213. {
  1214. char buf[2][32];
  1215. dSprintf(buf[0], 32, "%d", event.modifier);
  1216. if (!ActionMap::getKeyString(event.objInst, buf[1]))
  1217. return(false);
  1218. consumed = dAtob(Con::executef(this, 3, name, buf[0], buf[1]));
  1219. }
  1220. return consumed;
  1221. }
  1222. bool GuiControl::onInputEvent(const InputEvent &event)
  1223. {
  1224. if (event.objType == SI_KEY)
  1225. {
  1226. if (event.action == SI_MAKE)
  1227. {
  1228. return sendScriptKeyEvent("onKeyDown", event);
  1229. }
  1230. else if (event.action == SI_BREAK)
  1231. {
  1232. return sendScriptKeyEvent("onKeyUp", event);
  1233. }
  1234. else if (event.action == SI_REPEAT)
  1235. {
  1236. return sendScriptKeyEvent("onKeyRepeat", event);
  1237. }
  1238. }
  1239. return false;
  1240. }
  1241. void GuiControl::onTouchUp(const GuiEvent &event)
  1242. {
  1243. if (!mVisible || !mAwake)
  1244. return;
  1245. bool consumed1 = sendScriptMouseEvent("onTouchUp", event);
  1246. bool consumed2 = sendScriptMouseEvent("onMouseUp", event);
  1247. GuiControl* parent = getParent();
  1248. if (parent && !consumed1 && !consumed2)
  1249. parent->onTouchUp(event);
  1250. }
  1251. void GuiControl::onTouchDown(const GuiEvent &event)
  1252. {
  1253. if (!mVisible || !mAwake)
  1254. return;
  1255. bool consumed1 = sendScriptMouseEvent("onTouchDown", event);
  1256. bool consumed2 = sendScriptMouseEvent("onMouseDown", event);
  1257. GuiControl* parent = getParent();
  1258. if (parent && !consumed1 && !consumed2)
  1259. parent->onTouchDown(event);
  1260. }
  1261. void GuiControl::onTouchMove(const GuiEvent &event)
  1262. {
  1263. if ( !mVisible || !mAwake )
  1264. return;
  1265. bool consumed1 = sendScriptMouseEvent("onTouchMove", event);
  1266. bool consumed2 = sendScriptMouseEvent("onMouseMove", event);
  1267. GuiControl *parent = getParent();
  1268. if (parent && !consumed1 && !consumed2)
  1269. parent->onTouchMove( event );
  1270. }
  1271. void GuiControl::onTouchDragged(const GuiEvent &event)
  1272. {
  1273. if (!mVisible || !mAwake)
  1274. return;
  1275. bool consumed1 = sendScriptMouseEvent("onTouchDragged", event);
  1276. bool consumed2 = sendScriptMouseEvent("onMouseDragged", event);
  1277. GuiControl* parent = getParent();
  1278. if (parent && !consumed1 && !consumed2)
  1279. parent->onTouchDragged(event);
  1280. }
  1281. void GuiControl::onTouchEnter(const GuiEvent &event)
  1282. {
  1283. if (!mVisible || !mAwake)
  1284. return;
  1285. sendScriptMouseEvent("onTouchEnter", event);
  1286. sendScriptMouseEvent("onMouseEnter", event);
  1287. //Entering a child means nothing to a parent
  1288. }
  1289. void GuiControl::onTouchLeave(const GuiEvent &event)
  1290. {
  1291. if (!mVisible || !mAwake)
  1292. return;
  1293. sendScriptMouseEvent("onTouchLeave", event);
  1294. sendScriptMouseEvent("onMouseLeave", event);
  1295. //Leaving a child means nothing to a parent
  1296. }
  1297. void GuiControl::onMouseWheelUp( const GuiEvent &event )
  1298. {
  1299. if ( !mVisible || !mAwake )
  1300. return;
  1301. bool consumed = sendScriptMouseEvent("onMouseWheelUp", event);
  1302. GuiControl *parent = getParent();
  1303. if (parent && !consumed)
  1304. return parent->onMouseWheelUp(event);
  1305. }
  1306. void GuiControl::onMouseWheelDown( const GuiEvent &event )
  1307. {
  1308. if ( !mVisible || !mAwake )
  1309. return;
  1310. bool consumed = sendScriptMouseEvent("onMouseWheelDown", event);
  1311. GuiControl *parent = getParent();
  1312. if (parent && !consumed)
  1313. return parent->onMouseWheelDown(event);
  1314. }
  1315. void GuiControl::onRightMouseDown(const GuiEvent &event)
  1316. {
  1317. if (!mVisible || !mAwake)
  1318. return;
  1319. bool consumed = sendScriptMouseEvent("onRightMouseDown", event);
  1320. GuiControl* parent = getParent();
  1321. if (parent && !consumed)
  1322. parent->onRightMouseDown(event);
  1323. }
  1324. void GuiControl::onRightMouseUp(const GuiEvent &event)
  1325. {
  1326. if (!mVisible || !mAwake)
  1327. return;
  1328. bool consumed = sendScriptMouseEvent("onRightMouseUp", event);
  1329. GuiControl* parent = getParent();
  1330. if (parent && !consumed)
  1331. parent->onRightMouseUp(event);
  1332. }
  1333. void GuiControl::onRightMouseDragged(const GuiEvent &event)
  1334. {
  1335. if (!mVisible || !mAwake)
  1336. return;
  1337. bool consumed = sendScriptMouseEvent("onRightMouseDragged", event);
  1338. GuiControl* parent = getParent();
  1339. if (parent && !consumed)
  1340. parent->onRightMouseDragged(event);
  1341. }
  1342. void GuiControl::onMiddleMouseDown(const GuiEvent &event)
  1343. {
  1344. if (!mVisible || !mAwake)
  1345. return;
  1346. bool consumed = sendScriptMouseEvent("onMiddleMouseDown", event);
  1347. GuiControl* parent = getParent();
  1348. if (parent && !consumed)
  1349. parent->onMiddleMouseDown(event);
  1350. }
  1351. void GuiControl::onMiddleMouseUp(const GuiEvent &event)
  1352. {
  1353. if (!mVisible || !mAwake)
  1354. return;
  1355. bool consumed = sendScriptMouseEvent("onMiddleMouseUp", event);
  1356. GuiControl* parent = getParent();
  1357. if (parent && !consumed)
  1358. parent->onMiddleMouseUp(event);
  1359. }
  1360. void GuiControl::onMiddleMouseDragged(const GuiEvent &event)
  1361. {
  1362. if (!mVisible || !mAwake)
  1363. return;
  1364. bool consumed = sendScriptMouseEvent("onMiddleMouseDragged", event);
  1365. GuiControl* parent = getParent();
  1366. if (parent && !consumed)
  1367. parent->onMiddleMouseDragged(event);
  1368. }
  1369. GuiControl* GuiControl::findFirstTabable()
  1370. {
  1371. GuiControl *tabCtrl = NULL;
  1372. if(mVisible && mAwake)
  1373. {
  1374. iterator i;
  1375. for (i = begin(); i != end(); i++)
  1376. {
  1377. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  1378. tabCtrl = ctrl->findFirstTabable();
  1379. if (tabCtrl)
  1380. {
  1381. mFirstResponder = tabCtrl;
  1382. return tabCtrl;
  1383. }
  1384. }
  1385. }
  1386. //nothing was found, therefore, see if this ctrl is tabable
  1387. return ( mProfile != NULL ) ? ( ( mProfile->mTabable && mAwake && mVisible ) ? this : NULL ) : NULL;
  1388. }
  1389. GuiControl* GuiControl::findLastTabable(bool firstCall)
  1390. {
  1391. //if this is the first call, clear the global
  1392. if (firstCall)
  1393. smPrevResponder = NULL;
  1394. //if this control is tabable, set the global
  1395. if (mProfile->mTabable)
  1396. smPrevResponder = this;
  1397. if(mVisible && mAwake)
  1398. {
  1399. iterator i;
  1400. for (i = begin(); i != end(); i++)
  1401. {
  1402. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  1403. ctrl->findLastTabable(false);
  1404. }
  1405. }
  1406. //after the entire tree has been traversed, return the last responder found
  1407. mFirstResponder = smPrevResponder;
  1408. return smPrevResponder;
  1409. }
  1410. GuiControl *GuiControl::findNextTabable(GuiControl *curResponder, bool firstCall)
  1411. {
  1412. //if this is the first call, clear the global
  1413. if (firstCall)
  1414. smCurResponder = NULL;
  1415. //first find the current responder
  1416. if (curResponder == this)
  1417. smCurResponder = this;
  1418. //if the first responder has been found, return the very next *tabable* control
  1419. else if ( smCurResponder && mProfile->mTabable && mAwake && mVisible && mActive )
  1420. return( this );
  1421. //loop through, checking each child to see if it is the one that follows the firstResponder
  1422. GuiControl *tabCtrl = NULL;
  1423. if (mVisible && mAwake)
  1424. {
  1425. iterator i;
  1426. for (i = begin(); i != end(); i++)
  1427. {
  1428. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  1429. tabCtrl = ctrl->findNextTabable(curResponder, false);
  1430. if (tabCtrl) break;
  1431. }
  1432. }
  1433. mFirstResponder = tabCtrl;
  1434. return tabCtrl;
  1435. }
  1436. GuiControl *GuiControl::findPrevTabable(GuiControl *curResponder, bool firstCall)
  1437. {
  1438. if (firstCall)
  1439. smPrevResponder = NULL;
  1440. //if this is the current reponder, return the previous one
  1441. if (curResponder == this)
  1442. return smPrevResponder;
  1443. //else if this is a responder, store it in case the next found is the current responder
  1444. else if ( mProfile->mTabable && mAwake && mVisible && mActive )
  1445. smPrevResponder = this;
  1446. //loop through, checking each child to see if it is the one that follows the firstResponder
  1447. GuiControl *tabCtrl = NULL;
  1448. if (mVisible && mAwake)
  1449. {
  1450. iterator i;
  1451. for (i = begin(); i != end(); i++)
  1452. {
  1453. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  1454. tabCtrl = ctrl->findPrevTabable(curResponder, false);
  1455. if (tabCtrl) break;
  1456. }
  1457. }
  1458. mFirstResponder = tabCtrl;
  1459. return tabCtrl;
  1460. }
  1461. void GuiControl::onLoseFirstResponder()
  1462. {
  1463. // Since many controls have visual cues when they are the firstResponder...
  1464. setUpdate();
  1465. if (isMethod("onLoseFirstResponder"))
  1466. {
  1467. Con::executef(this, 2, "onLoseFirstResponder");
  1468. }
  1469. else if (isMethod("onBlur"))
  1470. {
  1471. Con::executef(this, 2, "onBlur");
  1472. }
  1473. }
  1474. bool GuiControl::ControlIsChild(GuiControl *child)
  1475. {
  1476. //function returns true if this control, or one of it's children is the child control
  1477. if (child == this)
  1478. return true;
  1479. //loop through, checking each child to see if it is ,or contains, the firstResponder
  1480. iterator i;
  1481. for (i = begin(); i != end(); i++)
  1482. {
  1483. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  1484. if (ctrl->ControlIsChild(child)) return true;
  1485. }
  1486. //not found, therefore false
  1487. return false;
  1488. }
  1489. void GuiControl::onFocus(bool foundFirstResponder)
  1490. {
  1491. if (!foundFirstResponder && isFirstResponder())
  1492. {
  1493. foundFirstResponder = true;
  1494. }
  1495. //bubble the focus up
  1496. GuiControl *parent = getParent();
  1497. if (parent)
  1498. parent->onFocus(foundFirstResponder);
  1499. }
  1500. bool GuiControl::isFirstResponder()
  1501. {
  1502. GuiCanvas *root = getRoot();
  1503. return root && root->getFirstResponder() == this;
  1504. }
  1505. void GuiControl::setFirstResponder( GuiControl* firstResponder )
  1506. {
  1507. if ( firstResponder && firstResponder->mProfile && firstResponder->mProfile->mCanKeyFocus )
  1508. mFirstResponder = firstResponder;
  1509. GuiControl *parent = getParent();
  1510. if ( parent )
  1511. parent->setFirstResponder( firstResponder );
  1512. }
  1513. void GuiControl::setFirstResponder()
  1514. {
  1515. if ( mAwake && mVisible )
  1516. {
  1517. GuiControl *parent = getParent();
  1518. if (mProfile->mCanKeyFocus && parent )
  1519. {
  1520. parent->setFirstResponder(this);
  1521. // Since many controls have visual cues when they are the firstResponder...
  1522. this->setUpdate();
  1523. if (isMethod("onGainFirstResponder"))
  1524. {
  1525. Con::executef(this, 2, "onGainFirstResponder");
  1526. }
  1527. else if (isMethod("onFocus"))
  1528. {
  1529. Con::executef(this, 2, "onFocus");
  1530. }
  1531. }
  1532. }
  1533. }
  1534. void GuiControl::clearFirstResponder()
  1535. {
  1536. clearFirstResponder(this);
  1537. }
  1538. void GuiControl::clearFirstResponder(GuiControl* target)
  1539. {
  1540. GuiControl *parent = this;
  1541. while((parent = parent->getParent()) != NULL)
  1542. {
  1543. if(parent->mFirstResponder == target)
  1544. parent->mFirstResponder = NULL;
  1545. else
  1546. break;
  1547. }
  1548. }
  1549. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
  1550. void GuiControl::buildAcceleratorMap()
  1551. {
  1552. //add my own accel key
  1553. addAcceleratorKey();
  1554. //add all my childrens keys
  1555. iterator i;
  1556. for(i = begin(); i != end(); i++)
  1557. {
  1558. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  1559. ctrl->buildAcceleratorMap();
  1560. }
  1561. }
  1562. void GuiControl::addAcceleratorKey()
  1563. {
  1564. //see if we have an accelerator
  1565. if (mAcceleratorKey == StringTable->EmptyString)
  1566. return;
  1567. EventDescriptor accelEvent;
  1568. ActionMap::createEventDescriptor(mAcceleratorKey, &accelEvent);
  1569. //now we have a modifier, and a key, add them to the canvas
  1570. GuiCanvas *root = getRoot();
  1571. if (root)
  1572. root->addAcceleratorKey(this, 0, accelEvent.eventCode, accelEvent.flags);
  1573. }
  1574. void GuiControl::acceleratorKeyPress(U32 index)
  1575. {
  1576. onAction();
  1577. }
  1578. void GuiControl::acceleratorKeyRelease(U32 index)
  1579. {
  1580. //do nothing
  1581. }
  1582. bool GuiControl::onKeyDown(const GuiEvent &event)
  1583. {
  1584. //pass the event to the parent
  1585. GuiControl *parent = getParent();
  1586. if (parent)
  1587. return parent->onKeyDown(event);
  1588. else
  1589. return false;
  1590. }
  1591. bool GuiControl::onKeyRepeat(const GuiEvent &event)
  1592. {
  1593. // default to just another key down.
  1594. return onKeyDown(event);
  1595. }
  1596. bool GuiControl::onKeyUp(const GuiEvent &event)
  1597. {
  1598. //pass the event to the parent
  1599. GuiControl *parent = getParent();
  1600. if (parent)
  1601. return parent->onKeyUp(event);
  1602. else
  1603. return false;
  1604. }
  1605. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
  1606. void GuiControl::onAction()
  1607. {
  1608. if (! mActive)
  1609. return;
  1610. //execute the console command
  1611. if (mConsoleCommand && mConsoleCommand[0])
  1612. {
  1613. execConsoleCallback();
  1614. }
  1615. else if(isMethod("onAction"))
  1616. {
  1617. Con::executef(this, 1, "onAction");
  1618. }
  1619. }
  1620. void GuiControl::onMessage(GuiControl *sender, S32 msg)
  1621. {
  1622. }
  1623. void GuiControl::messageSiblings(S32 message)
  1624. {
  1625. GuiControl *parent = getParent();
  1626. if (! parent) return;
  1627. GuiControl::iterator i;
  1628. for(i = parent->begin(); i != parent->end(); i++)
  1629. {
  1630. GuiControl *ctrl = dynamic_cast<GuiControl *>(*i);
  1631. if (ctrl != this)
  1632. ctrl->onMessage(this, message);
  1633. }
  1634. }
  1635. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
  1636. void GuiControl::onDialogPush()
  1637. {
  1638. // Notify Script.
  1639. if( isMethod("onDialogPush") )
  1640. Con::executef(this, 1, "onDialogPush");
  1641. }
  1642. void GuiControl::onDialogPop()
  1643. {
  1644. // Notify Script.
  1645. if( isMethod("onDialogPop") )
  1646. Con::executef(this, 1, "onDialogPop");
  1647. }
  1648. //------------------------------------------------------------------------------
  1649. void GuiControl::setVisible(bool value)
  1650. {
  1651. mVisible = value;
  1652. iterator i;
  1653. setUpdate();
  1654. for(i = begin(); i != end(); i++)
  1655. {
  1656. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  1657. ctrl->clearFirstResponder();
  1658. }
  1659. GuiControl *parent = getParent();
  1660. if (parent)
  1661. parent->childResized(this);
  1662. }
  1663. void GuiControl::makeFirstResponder(bool value)
  1664. {
  1665. if ( value )
  1666. //setFirstResponder(this);
  1667. setFirstResponder();
  1668. else
  1669. clearFirstResponder();
  1670. }
  1671. void GuiControl::setActive( bool value )
  1672. {
  1673. mActive = value;
  1674. if (value && isMethod("onActive"))
  1675. Con::executef(this, 1, "onActive");
  1676. else if (!value && isMethod("onInactive"))
  1677. Con::executef(this, 1, "onInactive");
  1678. if ( !mActive )
  1679. clearFirstResponder();
  1680. if ( mVisible && mAwake )
  1681. setUpdate();
  1682. }
  1683. void GuiControl::getScrollLineSizes(U32 *rowHeight, U32 *columnWidth)
  1684. {
  1685. // default to 10 pixels in y, 30 pixels in x
  1686. *columnWidth = 30;
  1687. *rowHeight = 30;
  1688. }
  1689. void GuiControl::renderText(const Point2I& offset, const Point2I& extent, const char* text, GuiControlProfile* profile, TextRotationOptions rot)
  1690. {
  1691. RectI old = dglGetClipRect();
  1692. RectI clipRect = RectI(offset, extent);
  1693. if (clipRect.intersect(old))
  1694. {
  1695. dglSetClipRect(clipRect);
  1696. const S32 textHeight = profile->getFont(mFontSizeAdjust)->getHeight();
  1697. S32 totalWidth = (rot == tRotateNone) ? extent.x : extent.y;
  1698. S32 totalHeight = (rot == tRotateNone) ? extent.y : extent.x;
  1699. S32 startOffsetY = 0;
  1700. vector<string> lineList = getLineList(text, profile, totalWidth);
  1701. //first align vertical
  1702. S32 blockHeight = textHeight * lineList.size();
  1703. if (mTextExtend)
  1704. {
  1705. Point2I extent = getExtent();
  1706. if (mTextWrap)
  1707. {
  1708. extent.y = getOuterHeight(blockHeight, NormalState, profile);
  1709. }
  1710. else
  1711. {
  1712. extent.x = getOuterWidth(profile->getFont(mFontSizeAdjust)->getStrWidth(text), NormalState, profile);
  1713. }
  1714. setExtent(extent);
  1715. }
  1716. if (blockHeight < totalHeight)
  1717. {
  1718. startOffsetY = getTextVerticalOffset(blockHeight, totalHeight, getVertAlignmentType(profile));
  1719. }
  1720. else if (!mTextWrap)
  1721. {
  1722. startOffsetY = getTextVerticalOffset(blockHeight, totalHeight, VertAlignmentType::MiddleVAlign);
  1723. }
  1724. else
  1725. {
  1726. startOffsetY = getTextVerticalOffset(blockHeight, totalHeight, VertAlignmentType::TopVAlign);
  1727. }
  1728. renderLineList(offset, extent, startOffsetY, lineList, profile, rot);
  1729. dglSetClipRect(old);
  1730. }
  1731. }
  1732. void GuiControl::renderLineList(const Point2I& offset, const Point2I& extent, const S32 startOffsetY, const vector<string> lineList, GuiControlProfile* profile, const TextRotationOptions rot)
  1733. {
  1734. const S32 textHeight = profile->getFont(mFontSizeAdjust)->getHeight();
  1735. S32 totalWidth = (rot == tRotateNone) ? extent.x : extent.y;
  1736. //Now print each line
  1737. U32 ibeamPos = 0;
  1738. U32 lineNumber = 0;
  1739. S32 offsetX = 0;
  1740. S32 offsetY = startOffsetY;
  1741. for(string line : lineList)
  1742. {
  1743. // align the horizontal
  1744. string trimmedLine = Utility::trim_copy(line);
  1745. U32 textWidth = profile->getFont(mFontSizeAdjust)->getStrWidth(trimmedLine.c_str());
  1746. if(textWidth < totalWidth)
  1747. {
  1748. offsetX = getTextHorizontalOffset(textWidth, totalWidth, getAlignmentType(profile));
  1749. }
  1750. Point2I start = Point2I(0, 0);
  1751. F32 rotation = 0.0f;
  1752. if (rot == tRotateNone)
  1753. {
  1754. start.x += offsetX;
  1755. start.y += offsetY;
  1756. rotation = 0.0f;
  1757. }
  1758. else if (rot == tRotateLeft)
  1759. {
  1760. start.x = offsetY;
  1761. start.y = extent.y + offsetX;
  1762. rotation = 90.0f;
  1763. }
  1764. else if (rot == tRotateRight)
  1765. {
  1766. start.x = extent.x - offsetY;
  1767. start.y = offsetX;
  1768. rotation = -90.0f;
  1769. }
  1770. renderTextLine(start + offset + profile->mTextOffset, trimmedLine, profile, rotation, ibeamPos, lineNumber);
  1771. offsetY += textHeight;
  1772. ibeamPos += line.length();
  1773. lineNumber++;
  1774. }
  1775. }
  1776. vector<string> GuiControl::getLineList(const char* text, GuiControlProfile* profile, S32 totalWidth)
  1777. {
  1778. GFont* font = profile->getFont(mFontSizeAdjust);
  1779. vector<string> lineList = vector<string>();
  1780. if (!mTextWrap)
  1781. {
  1782. lineList.push_back(text);
  1783. }
  1784. else
  1785. {
  1786. vector<string> paragraphList = vector<string>();
  1787. istringstream f(text);
  1788. string s;
  1789. while (getline(f, s)) {
  1790. paragraphList.push_back(s);
  1791. }
  1792. for (string& paragraph : paragraphList)
  1793. {
  1794. vector<string> wordList = vector<string>();
  1795. istringstream f2(paragraph);
  1796. string s2;
  1797. while (getline(f2, s2, ' ')) {
  1798. wordList.push_back(s2);
  1799. }
  1800. //now process the word list
  1801. string line;
  1802. bool newLine = true;
  1803. line.clear();
  1804. for (string& word : wordList)
  1805. {
  1806. if (font->getStrWidth(word.c_str()) >= totalWidth)
  1807. {
  1808. if (line.size() > 0)
  1809. {
  1810. lineList.push_back(string(line + " "));
  1811. line.clear();
  1812. }
  1813. lineList.push_back(word + " ");
  1814. newLine = true;
  1815. continue;
  1816. }
  1817. string prevLine = string(line);
  1818. line += (!newLine) ? " " + word : word;
  1819. newLine = false;
  1820. if (font->getStrWidth(line.c_str()) >= totalWidth && word.length() != 0)
  1821. {
  1822. lineList.push_back(prevLine + " ");
  1823. line = word;
  1824. }
  1825. }
  1826. if (paragraph.back() == ' ')
  1827. {
  1828. line += " ";
  1829. }
  1830. lineList.push_back(string(line));
  1831. }
  1832. }
  1833. return lineList;
  1834. }
  1835. void GuiControl::renderTextLine(const Point2I& startPoint, const string line, GuiControlProfile* profile, F32 rotationInDegrees, U32, U32)
  1836. {
  1837. dglDrawText(profile->getFont(mFontSizeAdjust), startPoint, line.c_str(), profile->mFontColors, 9, rotationInDegrees);
  1838. }
  1839. S32 GuiControl::getTextHorizontalOffset(S32 textWidth, S32 totalWidth, AlignmentType align)
  1840. {
  1841. if (align == RightAlign)
  1842. {
  1843. return totalWidth - textWidth;
  1844. }
  1845. else if (align == CenterAlign)
  1846. {
  1847. return (totalWidth - textWidth) / 2;
  1848. }
  1849. return 0;//left aligned
  1850. }
  1851. S32 GuiControl::getTextVerticalOffset(S32 textHeight, S32 totalHeight, VertAlignmentType align)
  1852. {
  1853. if (align == MiddleVAlign)
  1854. {
  1855. return (totalHeight - textHeight) / 2;
  1856. }
  1857. else if (align == BottomVAlign)
  1858. {
  1859. return totalHeight - textHeight;
  1860. }
  1861. return 0;
  1862. }
  1863. void GuiControl::getCursor(GuiCursor *&cursor, bool &showCursor, const GuiEvent &lastGuiEvent)
  1864. {
  1865. lastGuiEvent;
  1866. if(GuiControl::smCursorChanged != -1 && !isMouseLocked())
  1867. {
  1868. // We've already changed the cursor,
  1869. // so set it back before we change it again.
  1870. Input::popCursor();
  1871. // We haven't changed it
  1872. GuiControl::smCursorChanged = -1;
  1873. }
  1874. }
  1875. const char* GuiControl::execConsoleCallback()
  1876. {
  1877. if (mConsoleCommand && mConsoleCommand[0])
  1878. {
  1879. Con::setVariable("$ThisControl", avar("%d",getId()));
  1880. return Con::evaluate(mConsoleCommand, false);
  1881. }
  1882. return "";
  1883. }
  1884. const char* GuiControl::execAltConsoleCallback()
  1885. {
  1886. if(mAltConsoleCommand && mAltConsoleCommand[0])
  1887. {
  1888. Con::setVariable("$ThisControl", avar("%d",getId()));
  1889. return Con::evaluate(mAltConsoleCommand, false);
  1890. }
  1891. return "";
  1892. }
  1893. void GuiControl::setText(const char *text)
  1894. {
  1895. mText = StringTable->insert(text, true);
  1896. }
  1897. void GuiControl::setTextID(const char *id)
  1898. {
  1899. S32 n = Con::getIntVariable(id, -1);
  1900. if (n != -1)
  1901. {
  1902. mTextID = StringTable->insert(id);
  1903. setTextID(n);
  1904. }
  1905. }
  1906. void GuiControl::setTextID(S32 id)
  1907. {
  1908. const UTF8 *str = getGUIString(id);
  1909. if (str)
  1910. setText((const char*)str);
  1911. }
  1912. const char *GuiControl::getText()
  1913. {
  1914. return mText;
  1915. }
  1916. void GuiControl::setDataField(StringTableEntry slotName, const char* array, const char* value)
  1917. {
  1918. this->findField(slotName);
  1919. const AbstractClassRep::Field* fld = this->findField(slotName);
  1920. if(fld)
  1921. {
  1922. if (fld->type == AbstractClassRep::DepricatedFieldType ||
  1923. fld->type == AbstractClassRep::StartGroupFieldType ||
  1924. fld->type == AbstractClassRep::EndGroupFieldType)
  1925. return;
  1926. ConsoleBaseType* cbt = ConsoleBaseType::getType(fld->type);
  1927. bool isProfile = strcmp(cbt->getTypeName(), "TypeGuiProfile") == 0;
  1928. if(isProfile && mAwake)
  1929. {
  1930. //Decrease the ref count on the old profile
  1931. void* dptr = (void*)(((const char*)this) + fld->offset);
  1932. GuiControlProfile** obj = (GuiControlProfile**)dptr;
  1933. if((*obj))
  1934. (*obj)->decRefCount();
  1935. }
  1936. SimObject::setDataField(slotName, array, value);
  1937. if (isProfile && mAwake)
  1938. {
  1939. //Increase the ref count on the new profile
  1940. void* dptr = (void*)(((const char*)this) + fld->offset);
  1941. GuiControlProfile** obj = (GuiControlProfile**)dptr;
  1942. if ((*obj))
  1943. (*obj)->incRefCount();
  1944. }
  1945. }
  1946. else
  1947. {
  1948. SimObject::setDataField(slotName, array, value);
  1949. }
  1950. }
  1951. AlignmentType GuiControl::getAlignmentType()
  1952. {
  1953. return getAlignmentType(mProfile);
  1954. }
  1955. AlignmentType GuiControl::getAlignmentType(GuiControlProfile* profile)
  1956. {
  1957. return mAlignment == AlignmentType::DefaultAlign ? profile->mAlignment : mAlignment;
  1958. }
  1959. VertAlignmentType GuiControl::getVertAlignmentType()
  1960. {
  1961. return getVertAlignmentType(mProfile);
  1962. }
  1963. VertAlignmentType GuiControl::getVertAlignmentType(GuiControlProfile* profile)
  1964. {
  1965. return mVAlignment == VertAlignmentType::DefaultVAlign ? profile->mVAlignment : mVAlignment;
  1966. }
  1967. const ColorI& GuiControl::getFontColor(GuiControlProfile* profile, const GuiControlState state)
  1968. {
  1969. return mOverrideFontColor ? mFontColor : profile->getFontColor(state);
  1970. }
  1971. bool GuiControl::isEditMode()
  1972. {
  1973. if (smDesignTime && smEditorHandle)
  1974. {
  1975. GuiEditCtrl* edit = GuiControl::smEditorHandle;
  1976. if (this == edit->getRoot())
  1977. {
  1978. return true;
  1979. }
  1980. //work up the parent chain to see if one of the parents is the edit root
  1981. GuiControl* parent = getParent();
  1982. if (parent)
  1983. {
  1984. return parent->isEditMode();
  1985. }
  1986. }
  1987. return false;
  1988. }
  1989. bool GuiControl::isEditSelected()
  1990. {
  1991. if (smDesignTime && smEditorHandle)
  1992. {
  1993. GuiEditCtrl* edit = GuiControl::smEditorHandle;
  1994. bool selected = false;
  1995. auto list = edit->getSelected();
  1996. for (auto i = list->begin(); i < list->end(); i++)
  1997. {
  1998. GuiControl* ctrl = dynamic_cast<GuiControl*>(*i);
  1999. if (ctrl && ctrl == this)
  2000. {
  2001. return true;
  2002. }
  2003. }
  2004. }
  2005. return false;
  2006. }
  2007. bool GuiControl::onMouseDownEditor(const GuiEvent& event, const Point2I& offset)
  2008. {
  2009. GuiEditCtrl* edit = GuiControl::smEditorHandle;
  2010. GuiControl* parent = getParent();
  2011. if (this != edit->getRoot() && parent)
  2012. {
  2013. return parent->onMouseDownEditor(event, offset);
  2014. }
  2015. return false;
  2016. }
  2017. //--------------------------------------------------------------------
  2018. GuiEasingSupport::GuiEasingSupport()
  2019. {
  2020. //fill color
  2021. mEaseFillColorHL = EasingFunction::Linear;
  2022. mEaseFillColorSL = EasingFunction::Linear;
  2023. mEaseTimeFillColorHL = 500;
  2024. mEaseTimeFillColorSL = 0;
  2025. //control state
  2026. mPreviousState = GuiControlState::DisabledState;
  2027. mCurrentState = GuiControlState::DisabledState;
  2028. mFluidFillColor = FluidColorI(); //The actual fill color as it moves fluidly from one color to another.
  2029. }
  2030. void GuiEasingSupport::initPersistFields()
  2031. {
  2032. Parent::initPersistFields();
  2033. addGroup("Gui Easing Settings");
  2034. addField("easeFillColorHL", TypeEnum, Offset(mEaseFillColorHL, GuiEasingSupport), 1, &gEasingTable);
  2035. addField("easeFillColorSL", TypeEnum, Offset(mEaseFillColorSL, GuiEasingSupport), 1, &gEasingTable);
  2036. addField("easeTimeFillColorHL", TypeS32, Offset(mEaseTimeFillColorHL, GuiEasingSupport));
  2037. addField("easeTimeFillColorSL", TypeS32, Offset(mEaseTimeFillColorSL, GuiEasingSupport));
  2038. endGroup("Gui Easing Settings");
  2039. }
  2040. const ColorI& GuiEasingSupport::getFillColor(const GuiControlState state)
  2041. {
  2042. if (state != mCurrentState)
  2043. {
  2044. //We have just switched states!
  2045. mPreviousState = mCurrentState;
  2046. mCurrentState = state;
  2047. if (mCurrentState == GuiControlState::DisabledState || mPreviousState == GuiControlState::DisabledState)
  2048. {
  2049. mFluidFillColor.stopFluidAnimation();
  2050. mFluidFillColor.set(mProfile->getFillColor(state));
  2051. }
  2052. else if (mCurrentState == GuiControlState::SelectedState || mPreviousState == GuiControlState::SelectedState)
  2053. {
  2054. mFluidFillColor.setEasingFunction(mEaseFillColorSL);
  2055. mFluidFillColor.setAnimationLength(mEaseTimeFillColorSL);
  2056. mFluidFillColor.startFluidAnimation(mProfile->getFillColor(state));
  2057. }
  2058. else if (mCurrentState == GuiControlState::HighlightState || mPreviousState == GuiControlState::HighlightState)
  2059. {
  2060. mFluidFillColor.setEasingFunction(mEaseFillColorHL);
  2061. mFluidFillColor.setAnimationLength(mEaseTimeFillColorHL);
  2062. mFluidFillColor.startFluidAnimation(mProfile->getFillColor(state));
  2063. }
  2064. else
  2065. {
  2066. //we should never get here...
  2067. mFluidFillColor.stopFluidAnimation();
  2068. mFluidFillColor.set(mProfile->getFillColor(state));
  2069. }
  2070. }
  2071. if (mFluidFillColor.isAnimating() && !isProcessingTicks())
  2072. {
  2073. setProcessTicks(true);
  2074. }
  2075. if (!mFluidFillColor.isAnimating())
  2076. {
  2077. mFluidFillColor.set(mProfile->getFillColor(state));
  2078. }
  2079. return mFluidFillColor;
  2080. }
  2081. void GuiEasingSupport::processTick()
  2082. {
  2083. bool shouldWeContinue = false;
  2084. shouldWeContinue |= mFluidFillColor.processTick();
  2085. if (!shouldWeContinue)
  2086. {
  2087. setProcessTicks(false);
  2088. }
  2089. }
  2090. void GuiEasingSupport::setControlProfile(GuiControlProfile* prof)
  2091. {
  2092. Parent::setControlProfile(prof);
  2093. mCurrentState = mCurrentState == DisabledState ? NormalState : DisabledState;
  2094. }