guiControl.cc 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896
  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 <sstream>
  37. #include <iostream>
  38. #include <vector>
  39. #include <string>
  40. #include "guiControl_ScriptBinding.h"
  41. #ifndef _FRAMEALLOCATOR_H_
  42. #include "memory/frameAllocator.h"
  43. #endif
  44. //------------------------------------------------------------------------------
  45. IMPLEMENT_CONOBJECT_CHILDREN(GuiControl);
  46. //used to locate the next/prev responder when tab is pressed
  47. S32 GuiControl::smCursorChanged = -1;
  48. GuiControl *GuiControl::smPrevResponder = NULL;
  49. GuiControl *GuiControl::smCurResponder = NULL;
  50. GuiEditCtrl *GuiControl::smEditorHandle = NULL;
  51. bool GuiControl::smDesignTime = false;
  52. GuiControl::GuiControl()
  53. {
  54. mLayer = 0;
  55. mBounds.set(0, 0, 64, 64);
  56. mStoredExtent.set(0, 0);
  57. mRenderInsetLT.set(0, 0);
  58. mRenderInsetRB.set(0, 0);
  59. mMinExtent.set(0, 0);
  60. mProfile = NULL;
  61. mConsoleVariable = StringTable->EmptyString;
  62. mConsoleCommand = StringTable->EmptyString;
  63. mAltConsoleCommand = StringTable->EmptyString;
  64. mAcceleratorKey = StringTable->EmptyString;
  65. mLangTableName = StringTable->EmptyString;
  66. mText = StringTable->EmptyString;
  67. mTextID = StringTable->EmptyString;
  68. mLangTable = NULL;
  69. mFirstResponder = NULL;
  70. mCanSaveFieldDictionary = false;
  71. mVisible = true;
  72. mActive = false;
  73. mAwake = false;
  74. mCanSave = true;
  75. mHorizSizing = horizResizeRight;
  76. mVertSizing = vertResizeBottom;
  77. mTooltipProfile = NULL;
  78. mTooltip = StringTable->EmptyString;
  79. mTipHoverTime = 1000;
  80. mTooltipWidth = 250;
  81. mIsContainer = false;
  82. mTextWrap = false;
  83. }
  84. GuiControl::~GuiControl()
  85. {
  86. }
  87. bool GuiControl::onAdd()
  88. {
  89. // Let Parent Do Work.
  90. if(!Parent::onAdd())
  91. return false;
  92. // Grab the classname of this object
  93. const char *cName = getClassName();
  94. // if we're a pure GuiControl, then we're a container by default.
  95. if(dStrcmp("GuiControl", cName) == 0)
  96. mIsContainer = true;
  97. // Clamp to minExtent
  98. mBounds.extent.x = getMax( mMinExtent.x, mBounds.extent.x );
  99. mBounds.extent.y = getMax( mMinExtent.y, mBounds.extent.y );
  100. // Add to root group.
  101. Sim::getGuiGroup()->addObject(this);
  102. // Return Success.
  103. return true;
  104. }
  105. void GuiControl::onChildAdded( GuiControl *child )
  106. {
  107. if(mProfile)
  108. {
  109. //This will cause the child control to be centered if it needs to be.
  110. RectI innerRect = this->getInnerRect(mBounds.point, mBounds.extent, GuiControlState::NormalState, mProfile);
  111. child->parentResized(innerRect.extent, innerRect.extent);
  112. }
  113. }
  114. static EnumTable::Enums horzEnums[] =
  115. {
  116. { GuiControl::horizResizeRight, "right" },
  117. { GuiControl::horizResizeWidth, "width" },
  118. { GuiControl::horizResizeLeft, "left" },
  119. { GuiControl::horizResizeCenter, "center" },
  120. { GuiControl::horizResizeRelative, "relative" }
  121. };
  122. static EnumTable gHorizSizingTable(5, &horzEnums[0]);
  123. static EnumTable::Enums vertEnums[] =
  124. {
  125. { GuiControl::vertResizeBottom, "bottom" },
  126. { GuiControl::vertResizeHeight, "height" },
  127. { GuiControl::vertResizeTop, "top" },
  128. { GuiControl::vertResizeCenter, "center" },
  129. { GuiControl::vertResizeRelative, "relative" }
  130. };
  131. static EnumTable gVertSizingTable(5, &vertEnums[0]);
  132. void GuiControl::initPersistFields()
  133. {
  134. Parent::initPersistFields();
  135. // Things relevant only to the editor.
  136. addGroup("Gui Editing");
  137. addField("isContainer", TypeBool, Offset(mIsContainer, GuiControl));
  138. endGroup("Gui Editing");
  139. // Parent Group.
  140. addGroup("GuiControl");
  141. addField("Profile", TypeGuiProfile, Offset(mProfile, GuiControl));
  142. addField("HorizSizing", TypeEnum, Offset(mHorizSizing, GuiControl), 1, &gHorizSizingTable);
  143. addField("VertSizing", TypeEnum, Offset(mVertSizing, GuiControl), 1, &gVertSizingTable);
  144. addField("Position", TypePoint2I, Offset(mBounds.point, GuiControl));
  145. addProtectedField("Extent", TypePoint2I, Offset(mBounds.extent, GuiControl), &setExtentFn, &defaultProtectedGetFn, "The size of the control writen as width and height.");
  146. addProtectedField("MinExtent", TypePoint2I, Offset(mMinExtent, GuiControl), &setMinExtentFn, &defaultProtectedGetFn, &writeMinExtentFn, "The extent will not shrink below this size.");
  147. addField("canSave", TypeBool, Offset(mCanSave, GuiControl));
  148. addField("Visible", TypeBool, Offset(mVisible, GuiControl));
  149. addDepricatedField("Modal");
  150. addDepricatedField("SetFirstResponder");
  151. addField("Variable", TypeString, Offset(mConsoleVariable, GuiControl));
  152. addField("Command", TypeString, Offset(mConsoleCommand, GuiControl));
  153. addField("AltCommand", TypeString, Offset(mAltConsoleCommand, GuiControl));
  154. addField("Accelerator", TypeString, Offset(mAcceleratorKey, GuiControl));
  155. addField("Active", TypeBool, Offset(mActive, GuiControl));
  156. endGroup("GuiControl");
  157. addGroup("ToolTip");
  158. addField("tooltipprofile", TypeGuiProfile, Offset(mTooltipProfile, GuiControl));
  159. addField("tooltip", TypeString, Offset(mTooltip, GuiControl));
  160. addField("tooltipWidth", TypeS32, Offset(mTooltipWidth, GuiControl));
  161. addField("hovertime", TypeS32, Offset(mTipHoverTime, GuiControl));
  162. endGroup("ToolTip");
  163. addGroup("Localization");
  164. addField("langTableMod", TypeString, Offset(mLangTableName, GuiControl));
  165. endGroup("Localization");
  166. addGroup("Text");
  167. addProtectedField("text", TypeCaseString, Offset(mText, GuiControl), setTextProperty, getTextProperty, "");
  168. addField("textID", TypeString, Offset(mTextID, GuiControl));
  169. addField("textWrap", TypeBool, Offset(mTextWrap, GuiControl), &writeTextWrapFn, "If true, text will wrap to additional lines.");
  170. endGroup("Text");
  171. }
  172. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
  173. LangTable * GuiControl::getGUILangTable()
  174. {
  175. if(mLangTable)
  176. return mLangTable;
  177. if(mLangTableName && *mLangTableName)
  178. {
  179. mLangTable = (LangTable *)getModLangTable((const UTF8*)mLangTableName);
  180. return mLangTable;
  181. }
  182. GuiControl *parent = getParent();
  183. if(parent)
  184. return parent->getGUILangTable();
  185. return NULL;
  186. }
  187. const UTF8 * GuiControl::getGUIString(S32 id)
  188. {
  189. LangTable *lt = getGUILangTable();
  190. if(lt)
  191. return lt->getString(id);
  192. return NULL;
  193. }
  194. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
  195. void GuiControl::addObject(SimObject *object)
  196. {
  197. GuiControl *ctrl = dynamic_cast<GuiControl *>(object);
  198. if(!ctrl)
  199. {
  200. AssertWarn(0, "GuiControl::addObject: attempted to add NON GuiControl to set");
  201. return;
  202. }
  203. if(object->getGroup() == this)
  204. return;
  205. Parent::addObject(object);
  206. AssertFatal(!ctrl->isAwake(), "GuiControl::addObject: object is already awake before add");
  207. if(mAwake)
  208. ctrl->awaken();
  209. // If we are a child, notify our parent that we've been added
  210. GuiControl *parent = ctrl->getParent();
  211. if( parent )
  212. parent->onChildAdded( ctrl );
  213. }
  214. void GuiControl::removeObject(SimObject *object)
  215. {
  216. GuiControl *ctrl = dynamic_cast<GuiControl *>(object);
  217. if (!ctrl)
  218. {
  219. AssertWarn(0, "GuiControl::removeObject: attempted to remove NON GuiControl from set");
  220. return;
  221. }
  222. GuiControl *parent = ctrl->getParent();
  223. AssertFatal(mAwake == static_cast<GuiControl*>(object)->isAwake(), "GuiControl::removeObject: child control wake state is bad");
  224. if (mAwake)
  225. static_cast<GuiControl*>(object)->sleep();
  226. Parent::removeObject(object);
  227. // If we are a child, notify our parent that we've been removed
  228. if (parent)
  229. parent->onChildRemoved(ctrl);
  230. }
  231. GuiControl *GuiControl::getParent()
  232. {
  233. SimObject *obj = getGroup();
  234. if (GuiControl* gui = dynamic_cast<GuiControl*>(obj))
  235. return gui;
  236. return 0;
  237. }
  238. GuiCanvas *GuiControl::getRoot()
  239. {
  240. GuiControl *root = NULL;
  241. GuiControl *parent = getParent();
  242. while (parent)
  243. {
  244. root = parent;
  245. parent = parent->getParent();
  246. }
  247. if (root)
  248. return dynamic_cast<GuiCanvas*>(root);
  249. else
  250. return NULL;
  251. }
  252. void GuiControl::inspectPreApply()
  253. {
  254. if(smDesignTime && smEditorHandle)
  255. smEditorHandle->controlInspectPreApply(this);
  256. // The canvas never sleeps
  257. if(mAwake && dynamic_cast<GuiCanvas*>(this) == NULL )
  258. {
  259. onSleep(); // release all our resources.
  260. mAwake = true;
  261. }
  262. }
  263. void GuiControl::inspectPostApply()
  264. {
  265. // Shhhhhhh, you don't want to wake the canvas!
  266. if(mAwake && dynamic_cast<GuiCanvas*>(this) == NULL )
  267. {
  268. mAwake = false;
  269. onWake();
  270. }
  271. if(smDesignTime && smEditorHandle)
  272. smEditorHandle->controlInspectPostApply(this);
  273. }
  274. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
  275. Point2I GuiControl::localToGlobalCoord(const Point2I &src)
  276. {
  277. Point2I ret = src;
  278. ret += (mBounds.point + mRenderInsetLT);
  279. GuiControl *walk = getParent();
  280. while(walk)
  281. {
  282. ret += (walk->getPosition() + walk->mRenderInsetLT);
  283. walk = walk->getParent();
  284. }
  285. return ret;
  286. }
  287. Point2I GuiControl::globalToLocalCoord(const Point2I &src)
  288. {
  289. Point2I ret = src;
  290. ret -= (mBounds.point + mRenderInsetLT);
  291. GuiControl *walk = getParent();
  292. while(walk)
  293. {
  294. ret -= (walk->getPosition() + walk->mRenderInsetLT);
  295. walk = walk->getParent();
  296. }
  297. return ret;
  298. }
  299. //----------------------------------------------------------------
  300. void GuiControl::resize(const Point2I &newPosition, const Point2I &newExtent)
  301. {
  302. Point2I actualNewExtent = Point2I(getMax(mMinExtent.x, newExtent.x),
  303. getMax(mMinExtent.y, newExtent.y));
  304. Point2I oldExtent = mBounds.extent;
  305. // only do the child control resizing stuff if you really need to.
  306. bool extentChanged = (actualNewExtent != oldExtent);
  307. if (extentChanged) {
  308. //call set update both before and after
  309. setUpdate();
  310. mBounds.set(newPosition, actualNewExtent);
  311. iterator i;
  312. for(i = begin(); i != end(); i++)
  313. {
  314. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  315. ctrl->parentResized(oldExtent - (ctrl->mRenderInsetLT + ctrl->mRenderInsetRB), actualNewExtent - (ctrl->mRenderInsetLT + ctrl->mRenderInsetRB));
  316. }
  317. GuiControl *parent = getParent();
  318. if (parent)
  319. parent->childResized(this);
  320. setUpdate();
  321. }
  322. else {
  323. mBounds.point = newPosition;
  324. }
  325. }
  326. void GuiControl::setPosition( const Point2I &newPosition )
  327. {
  328. resize( newPosition, mBounds.extent );
  329. }
  330. void GuiControl::setExtent( const Point2I &newExtent )
  331. {
  332. resize( mBounds.point, newExtent );
  333. }
  334. void GuiControl::setBounds( const RectI &newBounds )
  335. {
  336. resize( newBounds.point, newBounds.extent );
  337. }
  338. void GuiControl::setLeft( S32 newLeft )
  339. {
  340. resize( Point2I( newLeft, mBounds.point.y), mBounds.extent );
  341. }
  342. void GuiControl::setTop( S32 newTop )
  343. {
  344. resize( Point2I( mBounds.point.x, newTop ), mBounds.extent );
  345. }
  346. void GuiControl::setWidth( S32 newWidth )
  347. {
  348. resize( mBounds.point, Point2I( newWidth, mBounds.extent.y ) );
  349. }
  350. void GuiControl::setHeight( S32 newHeight )
  351. {
  352. resize( mBounds.point, Point2I( mBounds.extent.x, newHeight ) );
  353. }
  354. void GuiControl::childResized(GuiControl *child)
  355. {
  356. // Default to do nothing. Do not call resize from here as it will create an infinite loop.
  357. }
  358. void GuiControl::parentResized(const Point2I &oldParentExtent, const Point2I &newParentExtent)
  359. {
  360. Point2I newPosition = getPosition();
  361. Point2I newExtent = getExtent();
  362. S32 deltaX = newParentExtent.x - oldParentExtent.x;
  363. S32 deltaY = newParentExtent.y - oldParentExtent.y;
  364. //In the case of centering, we want to make doubly sure we are using the inner rect.
  365. GuiControl* parent = getParent();
  366. Point2I parentInnerExt = Point2I(newParentExtent);
  367. if(mHorizSizing == horizResizeCenter || mVertSizing == vertResizeCenter)
  368. {
  369. //This is based on the "new" outer extent of the parent.
  370. parentInnerExt = getInnerRect(Point2I(0, 0), parent->mBounds.extent, NormalState, parent->mProfile).extent;
  371. }
  372. if (mHorizSizing == horizResizeCenter)
  373. newPosition.x = (parentInnerExt.x - mBounds.extent.x) >> 1;
  374. else if (mHorizSizing == horizResizeWidth)
  375. newExtent.x += deltaX;
  376. else if (mHorizSizing == horizResizeLeft)
  377. newPosition.x += deltaX;
  378. else if (mHorizSizing == horizResizeRelative && oldParentExtent.x != 0)
  379. {
  380. S32 newLeft = (newPosition.x * newParentExtent.x) / oldParentExtent.x;
  381. S32 newRight = ((newPosition.x + newExtent.x) * newParentExtent.x) / oldParentExtent.x;
  382. newPosition.x = newLeft;
  383. newExtent.x = newRight - newLeft;
  384. }
  385. if (mVertSizing == vertResizeCenter)
  386. newPosition.y = (parentInnerExt.y - mBounds.extent.y) >> 1;
  387. else if (mVertSizing == vertResizeHeight)
  388. newExtent.y += deltaY;
  389. else if (mVertSizing == vertResizeTop)
  390. newPosition.y += deltaY;
  391. else if(mVertSizing == vertResizeRelative && oldParentExtent.y != 0)
  392. {
  393. S32 newTop = (newPosition.y * newParentExtent.y) / oldParentExtent.y;
  394. S32 newBottom = ((newPosition.y + newExtent.y) * newParentExtent.y) / oldParentExtent.y;
  395. newPosition.y = newTop;
  396. newExtent.y = newBottom - newTop;
  397. }
  398. newExtent = extentBattery(newExtent);
  399. resize(newPosition, newExtent);
  400. }
  401. Point2I GuiControl::extentBattery(Point2I &newExtent)
  402. {
  403. if (mMinExtent.x == 0 && mMinExtent.y == 0)
  404. {
  405. return newExtent;
  406. }
  407. Point2I result = Point2I(newExtent);
  408. if (newExtent.x < mBounds.extent.x && newExtent.x < mMinExtent.x)
  409. {
  410. mStoredExtent.x += mBounds.extent.x > mMinExtent.x ? (mMinExtent.x - newExtent.x) : (mBounds.extent.x - newExtent.x);
  411. result.x = mMinExtent.x;
  412. }
  413. else if (newExtent.x > mBounds.extent.x && mStoredExtent.x > 0)
  414. {
  415. S32 charge = getMin(newExtent.x - mBounds.extent.x, mStoredExtent.x);
  416. mStoredExtent.x -= charge;
  417. result.x = newExtent.x - charge;
  418. }
  419. if (newExtent.y < mBounds.extent.y && newExtent.y < mMinExtent.y)
  420. {
  421. mStoredExtent.y += mBounds.extent.y > mMinExtent.y ? (mMinExtent.y - newExtent.y) : (mBounds.extent.y - newExtent.y);
  422. result.y = mMinExtent.y;
  423. }
  424. else if (newExtent.y > mBounds.extent.y && mStoredExtent.y > 0)
  425. {
  426. S32 charge = getMin(newExtent.y - mBounds.extent.y, mStoredExtent.y);
  427. mStoredExtent.y -= charge;
  428. result.y = newExtent.y - charge;
  429. }
  430. return result;
  431. }
  432. //----------------------------------------------------------------
  433. void GuiControl::onRender(Point2I offset, const RectI &updateRect)
  434. {
  435. RectI ctrlRect = applyMargins(offset, mBounds.extent, NormalState, mProfile);
  436. if (!ctrlRect.isValidRect())
  437. {
  438. return;
  439. }
  440. renderUniversalRect(ctrlRect, mProfile, NormalState);
  441. //Render Text
  442. dglSetBitmapModulation(mProfile->mFontColor);
  443. RectI fillRect = applyBorders(ctrlRect.point, ctrlRect.extent, NormalState, mProfile);
  444. RectI contentRect = applyPadding(fillRect.point, fillRect.extent, NormalState, mProfile);
  445. if(contentRect.isValidRect())
  446. {
  447. renderText(contentRect.point, contentRect.extent, mText, mProfile);
  448. //Render the childen
  449. renderChildControls(offset, contentRect, updateRect);
  450. }
  451. }
  452. RectI GuiControl::applyMargins(Point2I &offset, Point2I &extent, GuiControlState currentState, GuiControlProfile *profile)
  453. {
  454. //Get the border profiles
  455. GuiBorderProfile *leftProfile = profile->getLeftBorder();
  456. GuiBorderProfile *rightProfile = profile->getRightBorder();
  457. GuiBorderProfile *topProfile = profile->getTopBorder();
  458. GuiBorderProfile *bottomProfile = profile->getBottomBorder();
  459. S32 leftSize = (leftProfile) ? leftProfile->getMargin(currentState) : 0;
  460. S32 rightSize = (rightProfile) ? rightProfile->getMargin(currentState) : 0;
  461. S32 topSize = (topProfile) ? topProfile->getMargin(currentState) : 0;
  462. S32 bottomSize = (bottomProfile) ? bottomProfile->getMargin(currentState) : 0;
  463. return RectI(offset.x + leftSize, offset.y + topSize, (extent.x - leftSize) - rightSize, (extent.y - topSize) - bottomSize);
  464. }
  465. RectI GuiControl::applyBorders(Point2I &offset, Point2I &extent, GuiControlState currentState, GuiControlProfile *profile)
  466. {
  467. //Get the border profiles
  468. GuiBorderProfile *leftProfile = profile->getLeftBorder();
  469. GuiBorderProfile *rightProfile = profile->getRightBorder();
  470. GuiBorderProfile *topProfile = profile->getTopBorder();
  471. GuiBorderProfile *bottomProfile = profile->getBottomBorder();
  472. S32 leftSize = (leftProfile) ? leftProfile->getBorder(currentState) : 0;
  473. S32 rightSize = (rightProfile) ? rightProfile->getBorder(currentState) : 0;
  474. S32 topSize = (topProfile) ? topProfile->getBorder(currentState) : 0;
  475. S32 bottomSize = (bottomProfile) ? bottomProfile->getBorder(currentState) : 0;
  476. return RectI(offset.x + leftSize, offset.y + topSize, (extent.x - leftSize) - rightSize, (extent.y - topSize) - bottomSize);
  477. }
  478. RectI GuiControl::applyPadding(Point2I &offset, Point2I &extent, GuiControlState currentState, GuiControlProfile *profile)
  479. {
  480. //Get the border profiles
  481. GuiBorderProfile *leftProfile = profile->getLeftBorder();
  482. GuiBorderProfile *rightProfile = profile->getRightBorder();
  483. GuiBorderProfile *topProfile = profile->getTopBorder();
  484. GuiBorderProfile *bottomProfile = profile->getBottomBorder();
  485. S32 leftSize = (leftProfile) ? leftProfile->getPadding(currentState) : 0;
  486. S32 rightSize = (rightProfile) ? rightProfile->getPadding(currentState) : 0;
  487. S32 topSize = (topProfile) ? topProfile->getPadding(currentState) : 0;
  488. S32 bottomSize = (bottomProfile) ? bottomProfile->getPadding(currentState) : 0;
  489. return RectI(offset.x + leftSize, offset.y + topSize, (extent.x - leftSize) - rightSize, (extent.y - topSize) - bottomSize);
  490. }
  491. RectI GuiControl::getInnerRect(Point2I &offset, Point2I &extent, GuiControlState currentState, GuiControlProfile *profile)
  492. {
  493. //Get the border profiles
  494. GuiBorderProfile *leftProfile = profile->getLeftBorder();
  495. GuiBorderProfile *rightProfile = profile->getRightBorder();
  496. GuiBorderProfile *topProfile = profile->getTopBorder();
  497. GuiBorderProfile *bottomProfile = profile->getBottomBorder();
  498. S32 leftSize = (leftProfile) ? leftProfile->getMargin(currentState) + leftProfile->getBorder(currentState) + leftProfile->getPadding(currentState) : 0;
  499. S32 rightSize = (rightProfile) ? rightProfile->getMargin(currentState) + rightProfile->getBorder(currentState) + rightProfile->getPadding(currentState) : 0;
  500. S32 topSize = (topProfile) ? topProfile->getMargin(currentState) + topProfile->getBorder(currentState) + topProfile->getPadding(currentState) : 0;
  501. S32 bottomSize = (bottomProfile) ? bottomProfile->getMargin(currentState) + bottomProfile->getBorder(currentState) + bottomProfile->getPadding(currentState) : 0;
  502. return RectI(offset.x + leftSize, offset.y + topSize, (extent.x - leftSize) - rightSize, (extent.y - topSize) - bottomSize);
  503. }
  504. Point2I GuiControl::getOuterExtent(Point2I &innerExtent, GuiControlState currentState, GuiControlProfile *profile)
  505. {
  506. //Get the border profiles
  507. GuiBorderProfile *leftProfile = profile->getLeftBorder();
  508. GuiBorderProfile *rightProfile = profile->getRightBorder();
  509. GuiBorderProfile *topProfile = profile->getTopBorder();
  510. GuiBorderProfile *bottomProfile = profile->getBottomBorder();
  511. S32 leftSize = (leftProfile) ? leftProfile->getMargin(currentState) + leftProfile->getBorder(currentState) + leftProfile->getPadding(currentState) : 0;
  512. S32 rightSize = (rightProfile) ? rightProfile->getMargin(currentState) + rightProfile->getBorder(currentState) + rightProfile->getPadding(currentState) : 0;
  513. S32 topSize = (topProfile) ? topProfile->getMargin(currentState) + topProfile->getBorder(currentState) + topProfile->getPadding(currentState) : 0;
  514. S32 bottomSize = (bottomProfile) ? bottomProfile->getMargin(currentState) + bottomProfile->getBorder(currentState) + bottomProfile->getPadding(currentState) : 0;
  515. return Point2I(innerExtent.x + leftSize + rightSize, innerExtent.y + topSize + bottomSize);
  516. }
  517. bool GuiControl::renderTooltip(Point2I &cursorPos, const char* tipText )
  518. {
  519. #if !defined(TORQUE_OS_IOS) && !defined(TORQUE_OS_ANDROID) && !defined(TORQUE_OS_EMSCRIPTEN)
  520. // Short Circuit.
  521. if (!mAwake)
  522. return false;
  523. if ( dStrlen( mTooltip ) == 0 && ( tipText == NULL || dStrlen( tipText ) == 0 ) )
  524. return false;
  525. const char* renderTip = mTooltip;
  526. if( tipText != NULL )
  527. renderTip = tipText;
  528. // Finish if no root.
  529. GuiCanvas *root = getRoot();
  530. if ( !root )
  531. return false;
  532. if (!mTooltipProfile)
  533. setField("TooltipProfile", "GuiTooltipProfile");
  534. GFont *font = mTooltipProfile->mFont;
  535. // Set text bounds.
  536. Point2I textBounds( 0, 0 );
  537. // Fetch the width of a space.
  538. const S32 spaceWidth = (S32)font->getStrWidth(" ");
  539. // Fetch the maximum allowed tooltip extent.
  540. const S32 maxTooltipWidth = mTooltipWidth;
  541. // Fetch word count.
  542. const S32 wordCount = StringUnit::getUnitCount( renderTip, " " );
  543. // Reset line storage.
  544. const S32 tooltipLineStride = (S32)font->getHeight() + 4;
  545. const S32 maxTooltipLines = 20;
  546. S32 tooltipLineCount = 0;
  547. S32 tooltipLineWidth = 0;
  548. FrameTemp<StringBuffer> tooltipLines( maxTooltipLines );
  549. // Reset word indexing.
  550. S32 wordStartIndex = 0;
  551. S32 wordEndIndex = 0;
  552. // Search for end word.
  553. while( true )
  554. {
  555. // Do we have any words left?
  556. if ( wordEndIndex < wordCount )
  557. {
  558. // Yes, so fetch the word.
  559. const char* pWord = StringUnit::getUnit( renderTip, wordEndIndex, " " );
  560. // Add word length.
  561. const S32 wordLength = (S32)font->getStrWidth( pWord ) + spaceWidth;
  562. // Do we still have room?
  563. if ( (tooltipLineWidth + wordLength) < maxTooltipWidth )
  564. {
  565. // Yes, so add word length.
  566. tooltipLineWidth += wordLength;
  567. // Next word.
  568. wordEndIndex++;
  569. continue;
  570. }
  571. // Do we have any lines left?
  572. if ( tooltipLineCount < maxTooltipLines )
  573. {
  574. // Yes, so insert line.
  575. tooltipLines[tooltipLineCount++] = StringUnit::getUnits( renderTip, wordStartIndex, wordEndIndex-1, " " );
  576. // Update horizontal text bounds.
  577. if ( tooltipLineWidth > textBounds.x )
  578. textBounds.x = tooltipLineWidth;
  579. }
  580. // Set new line length.
  581. tooltipLineWidth = wordLength;
  582. // Set word start.
  583. wordStartIndex = wordEndIndex;
  584. // Next word.
  585. wordEndIndex++;
  586. continue;
  587. }
  588. // Do we have any words left?
  589. if ( wordStartIndex < wordCount )
  590. {
  591. // Yes, so do we have any lines left?
  592. if ( tooltipLineCount < maxTooltipLines )
  593. {
  594. // Yes, so insert line.
  595. tooltipLines[tooltipLineCount++] = StringUnit::getUnits( renderTip, wordStartIndex, wordCount-1, " " );
  596. // Update horizontal text bounds.
  597. if ( tooltipLineWidth > textBounds.x )
  598. textBounds.x = tooltipLineWidth;
  599. }
  600. }
  601. break;
  602. }
  603. // Controls the size of the inside (gutter) tooltip region.
  604. const S32 tooltipGutterSize = 5;
  605. // Adjust text bounds.
  606. textBounds.x += tooltipGutterSize * 2;
  607. textBounds.y = (((S32)font->getHeight() + 4) * tooltipLineCount - 4) + (tooltipGutterSize * 2);
  608. // Adjust to tooltip is always on-screen.
  609. Point2I screensize = Platform::getWindowSize();
  610. Point2I offset = cursorPos;
  611. offset.y += 22;
  612. if (screensize.x < (offset.x + textBounds.x))
  613. offset.x = screensize.x - textBounds.x;
  614. if(screensize.y < (offset.y + textBounds.y) )
  615. offset.y = screensize.y - textBounds.y;
  616. // Fetch the old clip.
  617. RectI oldClip = dglGetClipRect();
  618. // Set rectangle for the box, and set the clip rectangle.
  619. RectI rect(offset, textBounds);
  620. dglSetClipRect(rect);
  621. // Draw body and border of the tool tip
  622. renderUniversalRect(rect, mTooltipProfile, NormalState);
  623. // Draw the text centered in the tool tip box
  624. dglSetBitmapModulation( mTooltipProfile->mFontColor );
  625. Point2I start( tooltipGutterSize, tooltipGutterSize );
  626. for ( S32 lineIndex = 0; lineIndex < tooltipLineCount; lineIndex++ )
  627. {
  628. dglDrawText( font, start + offset, tooltipLines[lineIndex].getPtr8(), mProfile->mFontColors );
  629. offset.y += tooltipLineStride;
  630. }
  631. dglSetClipRect( oldClip );
  632. #endif
  633. return true;
  634. }
  635. void GuiControl::renderChildControls(Point2I offset, RectI content, const RectI &updateRect)
  636. {
  637. // 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.
  638. // updateRect is the area that this control was allowed to draw in. It should almost always be the same as the value in onRender.
  639. // content is the area that child controls are allowed to draw in.
  640. RectI clipRect = content;
  641. if(clipRect.intersect(dglGetClipRect()))
  642. {
  643. S32 size = objectList.size();
  644. S32 size_cpy = size;
  645. //-Mat look through our vector all normal-like, trying to use an iterator sometimes gives us
  646. //bad cast on good objects
  647. for( S32 count = 0; count < objectList.size(); count++ )
  648. {
  649. GuiControl *ctrl = (GuiControl *)objectList[count];
  650. if( ctrl == NULL ) {
  651. Con::errorf( "GuiControl::renderChildControls() object %i is NULL", count );
  652. continue;
  653. }
  654. if (ctrl->mVisible)
  655. {
  656. ctrl->mRenderInsetLT = content.point - offset;
  657. ctrl->mRenderInsetRB = mBounds.extent - (ctrl->mRenderInsetLT + content.extent);
  658. Point2I childPosition = content.point + ctrl->getPosition();
  659. RectI childClip(childPosition, ctrl->getExtent());
  660. if (childClip.intersect(clipRect))
  661. {
  662. RectI old = dglGetClipRect();
  663. dglSetClipRect(clipRect);
  664. glDisable(GL_CULL_FACE);
  665. ctrl->onRender(childPosition, RectI(childPosition, ctrl->getExtent()));
  666. dglSetClipRect(old);
  667. }
  668. }
  669. size_cpy = objectList.size(); // CHRIS: i know its wierd but the size of the list changes sometimes during execution of this loop
  670. if(size != size_cpy)
  671. {
  672. size = size_cpy;
  673. count--; // CHRIS: just to make sure one wasnt skipped.
  674. }
  675. }
  676. }
  677. }
  678. void GuiControl::setUpdateRegion(Point2I pos, Point2I ext)
  679. {
  680. Point2I upos = localToGlobalCoord(pos);
  681. GuiCanvas *root = getRoot();
  682. if (root)
  683. {
  684. root->addUpdateRegion(upos, ext);
  685. }
  686. }
  687. void GuiControl::setUpdate()
  688. {
  689. setUpdateRegion(Point2I(0,0), mBounds.extent);
  690. }
  691. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
  692. void GuiControl::awaken()
  693. {
  694. AssertFatal(!mAwake, "GuiControl::awaken: control is already awake");
  695. if(mAwake)
  696. return;
  697. iterator i;
  698. for(i = begin(); i != end(); i++)
  699. {
  700. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  701. AssertFatal(!ctrl->isAwake(), "GuiControl::awaken: child control is already awake");
  702. if(!ctrl->isAwake())
  703. ctrl->awaken();
  704. }
  705. AssertFatal(!mAwake, "GuiControl::awaken: should not be awake here");
  706. if(!mAwake)
  707. {
  708. if(!onWake())
  709. {
  710. Con::errorf(ConsoleLogEntry::General, "GuiControl::awaken: failed onWake for obj: %s", getName());
  711. AssertFatal(0, "GuiControl::awaken: failed onWake");
  712. deleteObject();
  713. }
  714. else
  715. {
  716. if (mTextID && *mTextID != 0)
  717. setTextID(mTextID);
  718. }
  719. }
  720. }
  721. void GuiControl::sleep()
  722. {
  723. AssertFatal(mAwake, "GuiControl::sleep: control is not awake");
  724. if(!mAwake)
  725. return;
  726. iterator i;
  727. for(i = begin(); i != end(); i++)
  728. {
  729. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  730. AssertFatal(ctrl->isAwake(), "GuiControl::sleep: child control is already asleep");
  731. if(ctrl->isAwake())
  732. ctrl->sleep();
  733. }
  734. AssertFatal(mAwake, "GuiControl::sleep: should not be asleep here");
  735. if(mAwake)
  736. onSleep();
  737. }
  738. void GuiControl::preRender()
  739. {
  740. AssertFatal(mAwake, "GuiControl::preRender: control is not awake");
  741. if(!mAwake)
  742. return;
  743. iterator i;
  744. for(i = begin(); i != end(); i++)
  745. {
  746. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  747. ctrl->preRender();
  748. }
  749. onPreRender();
  750. }
  751. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
  752. bool GuiControl::onWake()
  753. {
  754. AssertFatal( !mAwake, "GuiControl::onWake: control is already awake" );
  755. if( mAwake )
  756. return false;
  757. // [tom, 4/18/2005] Cause mLangTable to be refreshed in case it was changed
  758. mLangTable = NULL;
  759. // Grab the classname of this object
  760. const char *cName = getClassName();
  761. //make sure we have a profile
  762. if( !mProfile )
  763. {
  764. // Ensure the classname is a valid name...
  765. if( cName && cName[0] )
  766. {
  767. S32 pos = 0;
  768. for( pos = 0; pos <= (S32)dStrlen( cName ); pos++ )
  769. if( !dStrncmp( cName + pos, "Ctrl", 4 ) )
  770. break;
  771. if( pos != 0 ) {
  772. char buff[255];
  773. dStrncpy( buff, cName, pos );
  774. buff[pos] = '\0';
  775. dStrcat( buff, "Profile\0" );
  776. SimObject *obj = Sim::findObject( buff );
  777. if( obj )
  778. mProfile = dynamic_cast<GuiControlProfile*>( obj );
  779. }
  780. }
  781. // Ok lets check to see if that worked
  782. if( !mProfile ) {
  783. SimObject *obj = Sim::findObject( "GuiDefaultProfile" );
  784. if( obj )
  785. mProfile = dynamic_cast<GuiControlProfile*>(obj);
  786. }
  787. AssertFatal( mProfile, avar( "GuiControl: %s created with no profile.", getName() ) );
  788. }
  789. //set the flag
  790. mAwake = true;
  791. //set the layer
  792. GuiCanvas *root = getRoot();
  793. AssertFatal(root, "Unable to get the root Canvas.");
  794. GuiControl *parent = getParent();
  795. if (parent && parent != root)
  796. mLayer = parent->mLayer;
  797. //make sure the first responder exists
  798. if (! mFirstResponder)
  799. mFirstResponder = findFirstTabable();
  800. //see if we should force this control to be the first responder
  801. //if (mProfile->mTabable && mProfile->mCanKeyFocus)
  802. // setFirstResponder();
  803. //increment the profile
  804. mProfile->incRefCount();
  805. // Only invoke script callbacks if we have a namespace in which to do so
  806. // This will suppress warnings
  807. if( isMethod("onWake") )
  808. Con::executef(this, 1, "onWake");
  809. if (mTooltipProfile != NULL)
  810. mTooltipProfile->incRefCount();
  811. return true;
  812. }
  813. void GuiControl::onSleep()
  814. {
  815. AssertFatal(mAwake, "GuiControl::onSleep: control is not awake");
  816. if(!mAwake)
  817. return;
  818. //decrement the profile referrence
  819. if( mProfile != NULL )
  820. mProfile->decRefCount();
  821. clearFirstResponder();
  822. mouseUnlock();
  823. // Only invoke script callbacks if we have a namespace in which to do so
  824. // This will suppress warnings
  825. if( isMethod("onSleep") )
  826. Con::executef(this, 1, "onSleep");
  827. if (mTooltipProfile != NULL)
  828. mTooltipProfile->decRefCount();
  829. // Set Flag
  830. mAwake = false;
  831. }
  832. void GuiControl::setControlProfile(GuiControlProfile *prof)
  833. {
  834. AssertFatal(prof, "GuiControl::setControlProfile: invalid profile");
  835. if(prof == mProfile)
  836. return;
  837. if(mAwake)
  838. mProfile->decRefCount();
  839. mProfile = prof;
  840. if(mAwake)
  841. mProfile->incRefCount();
  842. }
  843. void GuiControl::onPreRender()
  844. {
  845. // do nothing.
  846. }
  847. //-----------------------------------------------------------------------------
  848. // checks up the parent hierarchy - if anyone above us is not savable returns false
  849. // otherwise, returns true.
  850. //-----------------------------------------------------------------------------
  851. bool GuiControl::getCanSaveParent()
  852. {
  853. GuiControl *walk = this;
  854. while(walk)
  855. {
  856. if(!walk->getCanSave())
  857. return false;
  858. walk = walk->getParent();
  859. }
  860. return true;
  861. }
  862. //-----------------------------------------------------------------------------
  863. // Can we Save to a TorqueScript file?
  864. //-----------------------------------------------------------------------------
  865. bool GuiControl::getCanSave()
  866. {
  867. return mCanSave;
  868. }
  869. //-----------------------------------------------------------------------------
  870. // Sets whether we can save out to a file (TorqueScript)
  871. //-----------------------------------------------------------------------------
  872. void GuiControl::setCanSave(bool bCanSave)
  873. {
  874. mCanSave = bCanSave;
  875. }
  876. ////////////////////////////////////////////////////////////////////////////////////////////////////
  877. // checks out mCanSave flag, if true just passes along to our parent,
  878. // if false, then we return without writing. Note, also, that
  879. // if our parent is not writeable, then we should not be writable...
  880. ////////////////////////////////////////////////////////////////////////////////////////////////////
  881. void GuiControl::write(Stream &stream, U32 tabStop, U32 flags)
  882. {
  883. //note: this will return false if either we, or any of our parents, are non-save controls
  884. bool bCanSave = getCanSaveParent();
  885. if(bCanSave)
  886. {
  887. Parent::write(stream, tabStop, flags);
  888. }
  889. }
  890. //This is only called if the control is deleted, not when the control is removed from its parent.
  891. void GuiControl::onRemove()
  892. {
  893. Parent::onRemove();
  894. }
  895. //For GuiControls, this will always just before it is actually removed.
  896. void GuiControl::onGroupRemove()
  897. {
  898. clearFirstResponder();
  899. }
  900. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
  901. const char *GuiControl::getScriptValue()
  902. {
  903. return NULL;
  904. }
  905. void GuiControl::setScriptValue(const char *value)
  906. {
  907. }
  908. void GuiControl::setConsoleVariable(const char *variable)
  909. {
  910. if (variable)
  911. {
  912. mConsoleVariable = StringTable->insert(variable);
  913. }
  914. else
  915. {
  916. mConsoleVariable = StringTable->EmptyString;
  917. }
  918. }
  919. //-----------------------------------------------------------------------------
  920. // finds and returns the first immediate child of ours whose
  921. // internal name matches the passed String. returns Null if not found.
  922. //-----------------------------------------------------------------------------
  923. void GuiControl::setConsoleCommand(const char *newCmd)
  924. {
  925. if (newCmd)
  926. mConsoleCommand = StringTable->insert(newCmd);
  927. else
  928. mConsoleCommand = StringTable->EmptyString;
  929. }
  930. const char * GuiControl::getConsoleCommand()
  931. {
  932. return mConsoleCommand;
  933. }
  934. void GuiControl::setSizing(S32 horz, S32 vert)
  935. {
  936. mHorizSizing = horz;
  937. mVertSizing = vert;
  938. }
  939. void GuiControl::setVariable(const char *value)
  940. {
  941. if (mConsoleVariable[0])
  942. Con::setVariable(mConsoleVariable, value);
  943. }
  944. void GuiControl::setIntVariable(S32 value)
  945. {
  946. if (mConsoleVariable[0])
  947. Con::setIntVariable(mConsoleVariable, value);
  948. }
  949. void GuiControl::setFloatVariable(F32 value)
  950. {
  951. if (mConsoleVariable[0])
  952. Con::setFloatVariable(mConsoleVariable, value);
  953. }
  954. const char * GuiControl::getVariable()
  955. {
  956. if (mConsoleVariable[0])
  957. return Con::getVariable(mConsoleVariable);
  958. else return NULL;
  959. }
  960. S32 GuiControl::getIntVariable()
  961. {
  962. if (mConsoleVariable[0])
  963. return Con::getIntVariable(mConsoleVariable);
  964. else return 0;
  965. }
  966. F32 GuiControl::getFloatVariable()
  967. {
  968. if (mConsoleVariable[0])
  969. return Con::getFloatVariable(mConsoleVariable);
  970. else return 0.0f;
  971. }
  972. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
  973. bool GuiControl::cursorInControl()
  974. {
  975. GuiCanvas *root = getRoot();
  976. if (! root) return false;
  977. Point2I pt = root->getCursorPos();
  978. Point2I offset = localToGlobalCoord(Point2I(0, 0));
  979. if (pt.x >= offset.x && pt.y >= offset.y &&
  980. pt.x < offset.x + mBounds.extent.x && pt.y < offset.y + mBounds.extent.y)
  981. {
  982. return true;
  983. }
  984. else
  985. {
  986. return false;
  987. }
  988. }
  989. bool GuiControl::pointInControl(const Point2I& parentCoordPoint)
  990. {
  991. S32 xt = parentCoordPoint.x - mBounds.point.x;
  992. S32 yt = parentCoordPoint.y - mBounds.point.y;
  993. return xt >= 0 && yt >= 0 && xt < mBounds.extent.x && yt < mBounds.extent.y;
  994. }
  995. GuiControl* GuiControl::findHitControl(const Point2I &pt, S32 initialLayer)
  996. {
  997. iterator i = end(); // find in z order (last to first)
  998. while (i != begin())
  999. {
  1000. i--;
  1001. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  1002. if (initialLayer >= 0 && ctrl->mLayer > initialLayer)
  1003. {
  1004. continue;
  1005. }
  1006. else if (ctrl->mVisible && ctrl->pointInControl(pt - ctrl->mRenderInsetLT))
  1007. {
  1008. Point2I ptemp = pt - (ctrl->mBounds.point + ctrl->mRenderInsetLT);
  1009. GuiControl *hitCtrl = ctrl->findHitControl(ptemp);
  1010. if(hitCtrl->mProfile->mUseInput)
  1011. return hitCtrl;
  1012. }
  1013. }
  1014. return this;
  1015. }
  1016. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
  1017. bool GuiControl::isMouseLocked()
  1018. {
  1019. GuiCanvas *root = getRoot();
  1020. return root ? root->getMouseLockedControl() == this : false;
  1021. }
  1022. void GuiControl::mouseLock(GuiControl *lockingControl)
  1023. {
  1024. GuiCanvas *root = getRoot();
  1025. if (root)
  1026. root->mouseLock(lockingControl);
  1027. }
  1028. void GuiControl::mouseLock()
  1029. {
  1030. GuiCanvas *root = getRoot();
  1031. if (root)
  1032. root->mouseLock(this);
  1033. }
  1034. void GuiControl::mouseUnlock()
  1035. {
  1036. GuiCanvas *root = getRoot();
  1037. if (root)
  1038. root->mouseUnlock(this);
  1039. }
  1040. bool GuiControl::onInputEvent(const InputEvent &event)
  1041. {
  1042. // Do nothing by default...
  1043. return( false );
  1044. }
  1045. void GuiControl::onTouchUp(const GuiEvent &event)
  1046. {
  1047. }
  1048. void GuiControl::onTouchDown(const GuiEvent &event)
  1049. {
  1050. }
  1051. void GuiControl::onTouchMove(const GuiEvent &event)
  1052. {
  1053. //if this control is a dead end, make sure the event stops here
  1054. if ( !mVisible || !mAwake )
  1055. return;
  1056. //pass the event to the parent
  1057. GuiControl *parent = getParent();
  1058. if ( parent )
  1059. parent->onTouchMove( event );
  1060. }
  1061. void GuiControl::onTouchDragged(const GuiEvent &event)
  1062. {
  1063. }
  1064. void GuiControl::onTouchEnter(const GuiEvent &)
  1065. {
  1066. }
  1067. void GuiControl::onTouchLeave(const GuiEvent &)
  1068. {
  1069. }
  1070. bool GuiControl::onMouseWheelUp( const GuiEvent &event )
  1071. {
  1072. //if this control is a dead end, make sure the event stops here
  1073. if ( !mVisible || !mAwake )
  1074. return true;
  1075. //pass the event to the parent
  1076. GuiControl *parent = getParent();
  1077. if ( parent )
  1078. return parent->onMouseWheelUp( event );
  1079. else
  1080. return false;
  1081. }
  1082. bool GuiControl::onMouseWheelDown( const GuiEvent &event )
  1083. {
  1084. //if this control is a dead end, make sure the event stops here
  1085. if ( !mVisible || !mAwake )
  1086. return true;
  1087. //pass the event to the parent
  1088. GuiControl *parent = getParent();
  1089. if ( parent )
  1090. return parent->onMouseWheelDown( event );
  1091. else
  1092. return false;
  1093. }
  1094. void GuiControl::onRightMouseDown(const GuiEvent &)
  1095. {
  1096. }
  1097. void GuiControl::onRightMouseUp(const GuiEvent &)
  1098. {
  1099. }
  1100. void GuiControl::onRightMouseDragged(const GuiEvent &)
  1101. {
  1102. }
  1103. void GuiControl::onMiddleMouseDown(const GuiEvent &)
  1104. {
  1105. }
  1106. void GuiControl::onMiddleMouseUp(const GuiEvent &)
  1107. {
  1108. }
  1109. void GuiControl::onMiddleMouseDragged(const GuiEvent &)
  1110. {
  1111. }
  1112. GuiControl* GuiControl::findFirstTabable()
  1113. {
  1114. GuiControl *tabCtrl = NULL;
  1115. iterator i;
  1116. for (i = begin(); i != end(); i++)
  1117. {
  1118. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  1119. tabCtrl = ctrl->findFirstTabable();
  1120. if (tabCtrl)
  1121. {
  1122. mFirstResponder = tabCtrl;
  1123. return tabCtrl;
  1124. }
  1125. }
  1126. //nothing was found, therefore, see if this ctrl is tabable
  1127. return ( mProfile != NULL ) ? ( ( mProfile->mTabable && mAwake && mVisible ) ? this : NULL ) : NULL;
  1128. }
  1129. GuiControl* GuiControl::findLastTabable(bool firstCall)
  1130. {
  1131. //if this is the first call, clear the global
  1132. if (firstCall)
  1133. smPrevResponder = NULL;
  1134. //if this control is tabable, set the global
  1135. if (mProfile->mTabable)
  1136. smPrevResponder = this;
  1137. iterator i;
  1138. for (i = begin(); i != end(); i++)
  1139. {
  1140. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  1141. ctrl->findLastTabable(false);
  1142. }
  1143. //after the entire tree has been traversed, return the last responder found
  1144. mFirstResponder = smPrevResponder;
  1145. return smPrevResponder;
  1146. }
  1147. GuiControl *GuiControl::findNextTabable(GuiControl *curResponder, bool firstCall)
  1148. {
  1149. //if this is the first call, clear the global
  1150. if (firstCall)
  1151. smCurResponder = NULL;
  1152. //first find the current responder
  1153. if (curResponder == this)
  1154. smCurResponder = this;
  1155. //if the first responder has been found, return the very next *tabable* control
  1156. else if ( smCurResponder && mProfile->mTabable && mAwake && mVisible && mActive )
  1157. return( this );
  1158. //loop through, checking each child to see if it is the one that follows the firstResponder
  1159. GuiControl *tabCtrl = NULL;
  1160. iterator i;
  1161. for (i = begin(); i != end(); i++)
  1162. {
  1163. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  1164. tabCtrl = ctrl->findNextTabable(curResponder, false);
  1165. if (tabCtrl) break;
  1166. }
  1167. mFirstResponder = tabCtrl;
  1168. return tabCtrl;
  1169. }
  1170. GuiControl *GuiControl::findPrevTabable(GuiControl *curResponder, bool firstCall)
  1171. {
  1172. if (firstCall)
  1173. smPrevResponder = NULL;
  1174. //if this is the current reponder, return the previous one
  1175. if (curResponder == this)
  1176. return smPrevResponder;
  1177. //else if this is a responder, store it in case the next found is the current responder
  1178. else if ( mProfile->mTabable && mAwake && mVisible && mActive )
  1179. smPrevResponder = this;
  1180. //loop through, checking each child to see if it is the one that follows the firstResponder
  1181. GuiControl *tabCtrl = NULL;
  1182. iterator i;
  1183. for (i = begin(); i != end(); i++)
  1184. {
  1185. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  1186. tabCtrl = ctrl->findPrevTabable(curResponder, false);
  1187. if (tabCtrl) break;
  1188. }
  1189. mFirstResponder = tabCtrl;
  1190. return tabCtrl;
  1191. }
  1192. void GuiControl::onLoseFirstResponder()
  1193. {
  1194. // Since many controls have visual cues when they are the firstResponder...
  1195. setUpdate();
  1196. }
  1197. bool GuiControl::ControlIsChild(GuiControl *child)
  1198. {
  1199. //function returns true if this control, or one of it's children is the child control
  1200. if (child == this)
  1201. return true;
  1202. //loop through, checking each child to see if it is ,or contains, the firstResponder
  1203. iterator i;
  1204. for (i = begin(); i != end(); i++)
  1205. {
  1206. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  1207. if (ctrl->ControlIsChild(child)) return true;
  1208. }
  1209. //not found, therefore false
  1210. return false;
  1211. }
  1212. void GuiControl::onFocus()
  1213. {
  1214. //bubble the focus up
  1215. GuiControl *parent = getParent();
  1216. if (parent)
  1217. parent->onFocus();
  1218. }
  1219. bool GuiControl::isFirstResponder()
  1220. {
  1221. GuiCanvas *root = getRoot();
  1222. return root && root->getFirstResponder() == this;
  1223. }
  1224. void GuiControl::setFirstResponder( GuiControl* firstResponder )
  1225. {
  1226. if ( firstResponder && firstResponder->mProfile->mCanKeyFocus )
  1227. mFirstResponder = firstResponder;
  1228. GuiControl *parent = getParent();
  1229. if ( parent )
  1230. parent->setFirstResponder( firstResponder );
  1231. }
  1232. void GuiControl::setFirstResponder()
  1233. {
  1234. if ( mAwake && mVisible )
  1235. {
  1236. GuiControl *parent = getParent();
  1237. if (mProfile->mCanKeyFocus == true && parent != NULL )
  1238. {
  1239. parent->setFirstResponder(this);
  1240. // Since many controls have visual cues when they are the firstResponder...
  1241. this->setUpdate();
  1242. }
  1243. }
  1244. }
  1245. void GuiControl::clearFirstResponder()
  1246. {
  1247. GuiControl *parent = this;
  1248. while((parent = parent->getParent()) != NULL)
  1249. {
  1250. if(parent->mFirstResponder == this)
  1251. parent->mFirstResponder = NULL;
  1252. else
  1253. break;
  1254. }
  1255. }
  1256. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
  1257. void GuiControl::buildAcceleratorMap()
  1258. {
  1259. //add my own accel key
  1260. addAcceleratorKey();
  1261. //add all my childrens keys
  1262. iterator i;
  1263. for(i = begin(); i != end(); i++)
  1264. {
  1265. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  1266. ctrl->buildAcceleratorMap();
  1267. }
  1268. }
  1269. void GuiControl::addAcceleratorKey()
  1270. {
  1271. //see if we have an accelerator
  1272. if (mAcceleratorKey == StringTable->EmptyString)
  1273. return;
  1274. EventDescriptor accelEvent;
  1275. ActionMap::createEventDescriptor(mAcceleratorKey, &accelEvent);
  1276. //now we have a modifier, and a key, add them to the canvas
  1277. GuiCanvas *root = getRoot();
  1278. if (root)
  1279. root->addAcceleratorKey(this, 0, accelEvent.eventCode, accelEvent.flags);
  1280. }
  1281. void GuiControl::acceleratorKeyPress(U32 index)
  1282. {
  1283. onAction();
  1284. }
  1285. void GuiControl::acceleratorKeyRelease(U32 index)
  1286. {
  1287. //do nothing
  1288. }
  1289. bool GuiControl::onKeyDown(const GuiEvent &event)
  1290. {
  1291. //pass the event to the parent
  1292. GuiControl *parent = getParent();
  1293. if (parent)
  1294. return parent->onKeyDown(event);
  1295. else
  1296. return false;
  1297. }
  1298. bool GuiControl::onKeyRepeat(const GuiEvent &event)
  1299. {
  1300. // default to just another key down.
  1301. return onKeyDown(event);
  1302. }
  1303. bool GuiControl::onKeyUp(const GuiEvent &event)
  1304. {
  1305. //pass the event to the parent
  1306. GuiControl *parent = getParent();
  1307. if (parent)
  1308. return parent->onKeyUp(event);
  1309. else
  1310. return false;
  1311. }
  1312. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
  1313. void GuiControl::onAction()
  1314. {
  1315. if (! mActive)
  1316. return;
  1317. //execute the console command
  1318. if (mConsoleCommand && mConsoleCommand[0])
  1319. {
  1320. execConsoleCallback();
  1321. }
  1322. else
  1323. Con::executef(this, 1, "onAction");
  1324. }
  1325. void GuiControl::onMessage(GuiControl *sender, S32 msg)
  1326. {
  1327. }
  1328. void GuiControl::messageSiblings(S32 message)
  1329. {
  1330. GuiControl *parent = getParent();
  1331. if (! parent) return;
  1332. GuiControl::iterator i;
  1333. for(i = parent->begin(); i != parent->end(); i++)
  1334. {
  1335. GuiControl *ctrl = dynamic_cast<GuiControl *>(*i);
  1336. if (ctrl != this)
  1337. ctrl->onMessage(this, message);
  1338. }
  1339. }
  1340. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
  1341. void GuiControl::onDialogPush()
  1342. {
  1343. // Notify Script.
  1344. if( isMethod("onDialogPush") )
  1345. Con::executef(this, 1, "onDialogPush");
  1346. }
  1347. void GuiControl::onDialogPop()
  1348. {
  1349. // Notify Script.
  1350. if( isMethod("onDialogPop") )
  1351. Con::executef(this, 1, "onDialogPop");
  1352. }
  1353. //------------------------------------------------------------------------------
  1354. void GuiControl::setVisible(bool value)
  1355. {
  1356. mVisible = value;
  1357. iterator i;
  1358. setUpdate();
  1359. for(i = begin(); i != end(); i++)
  1360. {
  1361. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  1362. ctrl->clearFirstResponder();
  1363. }
  1364. GuiControl *parent = getParent();
  1365. if (parent)
  1366. parent->childResized(this);
  1367. }
  1368. void GuiControl::makeFirstResponder(bool value)
  1369. {
  1370. if ( value )
  1371. //setFirstResponder(this);
  1372. setFirstResponder();
  1373. else
  1374. clearFirstResponder();
  1375. }
  1376. void GuiControl::setActive( bool value )
  1377. {
  1378. mActive = value;
  1379. if (value && isMethod("onActive"))
  1380. Con::executef(this, 1, "onActive");
  1381. else if (!value && isMethod("onInactive"))
  1382. Con::executef(this, 1, "onInactive");
  1383. if ( !mActive )
  1384. clearFirstResponder();
  1385. if ( mVisible && mAwake )
  1386. setUpdate();
  1387. }
  1388. void GuiControl::getScrollLineSizes(U32 *rowHeight, U32 *columnWidth)
  1389. {
  1390. // default to 10 pixels in y, 30 pixels in x
  1391. *columnWidth = 30;
  1392. *rowHeight = 30;
  1393. }
  1394. void GuiControl::renderText(Point2I &offset, Point2I &extent, const char *text, GuiControlProfile *profile, TextRotationOptions rot)
  1395. {
  1396. RectI old = dglGetClipRect();
  1397. RectI clipRect = RectI(offset, extent);
  1398. if (clipRect.intersect(old))
  1399. {
  1400. dglSetClipRect(clipRect);
  1401. GFont *font = profile->mFont;
  1402. S32 textWidth = 0;
  1403. const S32 textHeight = font->getHeight();
  1404. S32 totalWidth = extent.x;
  1405. S32 totalHeight = extent.y;
  1406. if (rot != tRotateNone)
  1407. {
  1408. totalWidth = extent.y;
  1409. totalHeight = extent.x;
  1410. }
  1411. Point2I startOffset = Point2I(0,0);
  1412. vector<string> lineList = vector<string>();
  1413. if (!mTextWrap)
  1414. {
  1415. lineList.push_back(text);
  1416. }
  1417. else
  1418. {
  1419. vector<string> paragraphList = vector<string>();
  1420. istringstream f(text);
  1421. string s;
  1422. while(getline(f, s)) {
  1423. paragraphList.push_back(s);
  1424. }
  1425. for (string &paragraph : paragraphList)
  1426. {
  1427. vector<string> wordList = vector<string>();
  1428. istringstream f2(paragraph);
  1429. string s2;
  1430. while (getline(f2, s2, ' ')) {
  1431. wordList.push_back(s2);
  1432. }
  1433. //now process the word list
  1434. string line;
  1435. line.clear();
  1436. for (string &word : wordList)
  1437. {
  1438. if (font->getStrWidth(word.c_str()) >= totalWidth)
  1439. {
  1440. if (line.size() > 0)
  1441. {
  1442. lineList.push_back(string(line));
  1443. line.clear();
  1444. }
  1445. lineList.push_back(word);
  1446. continue;
  1447. }
  1448. string prevLine = string(line);
  1449. line += (line.size() > 0) ? " " + word : word;
  1450. if (font->getStrWidth(line.c_str()) >= totalWidth)
  1451. {
  1452. lineList.push_back(prevLine);
  1453. line = word;
  1454. }
  1455. }
  1456. lineList.push_back(string(line));
  1457. }
  1458. }
  1459. //first align vertical
  1460. S32 blockHeight = textHeight * lineList.size();
  1461. if (blockHeight < totalHeight)
  1462. {
  1463. startOffset.y = getTextVerticalOffset(blockHeight, totalHeight, profile->mVAlignment);
  1464. }
  1465. else
  1466. {
  1467. startOffset.y = getTextVerticalOffset(blockHeight, totalHeight, GuiControlProfile::VertAlignmentType::MiddleVAlign);
  1468. }
  1469. //Now print each line
  1470. for(string &line : lineList)
  1471. {
  1472. // align the horizontal
  1473. textWidth = font->getStrWidth(line.c_str());
  1474. if(textWidth < totalWidth)
  1475. {
  1476. startOffset.x = getTextHorizontalOffset(textWidth, totalWidth, profile->mAlignment);
  1477. }
  1478. Point2I start = Point2I(0, 0);
  1479. F32 rotation;
  1480. if (rot == tRotateNone)
  1481. {
  1482. start += startOffset;
  1483. rotation = 0.0f;
  1484. }
  1485. else if (rot == tRotateLeft)
  1486. {
  1487. start.x = startOffset.y;
  1488. start.y = extent.y + startOffset.x;
  1489. rotation = 90.0f;
  1490. }
  1491. else if (rot == tRotateRight)
  1492. {
  1493. start.x = extent.x - startOffset.y;
  1494. start.y = startOffset.x;
  1495. rotation = -90.0f;
  1496. }
  1497. dglDrawText( font, start + offset + profile->mTextOffset, line.c_str(), profile->mFontColors, 9, rotation );
  1498. startOffset.y += textHeight;
  1499. }
  1500. dglSetClipRect(old);
  1501. }
  1502. }
  1503. S32 GuiControl::getTextHorizontalOffset(S32 textWidth, S32 totalWidth, GuiControlProfile::AlignmentType align)
  1504. {
  1505. if (align == GuiControlProfile::RightAlign)
  1506. {
  1507. return totalWidth - textWidth;
  1508. }
  1509. else if (align == GuiControlProfile::CenterAlign)
  1510. {
  1511. return (totalWidth - textWidth) / 2;
  1512. }
  1513. return 0;//left aligned
  1514. }
  1515. S32 GuiControl::getTextVerticalOffset(S32 textHeight, S32 totalHeight, GuiControlProfile::VertAlignmentType align)
  1516. {
  1517. if (align == GuiControlProfile::MiddleVAlign)
  1518. {
  1519. return (totalHeight - textHeight) / 2;
  1520. }
  1521. else if (align == GuiControlProfile::BottomVAlign)
  1522. {
  1523. return totalHeight - textHeight;
  1524. }
  1525. return 0;
  1526. }
  1527. void GuiControl::getCursor(GuiCursor *&cursor, bool &showCursor, const GuiEvent &lastGuiEvent)
  1528. {
  1529. lastGuiEvent;
  1530. if(GuiControl::smCursorChanged != -1 && !isMouseLocked())
  1531. {
  1532. // We've already changed the cursor,
  1533. // so set it back before we change it again.
  1534. Input::popCursor();
  1535. // We haven't changed it
  1536. GuiControl::smCursorChanged = -1;
  1537. }
  1538. }
  1539. const char* GuiControl::execConsoleCallback()
  1540. {
  1541. if (mConsoleCommand && mConsoleCommand[0])
  1542. {
  1543. Con::setVariable("$ThisControl", avar("%d",getId()));
  1544. return Con::evaluate(mConsoleCommand, false);
  1545. }
  1546. return "";
  1547. }
  1548. const char* GuiControl::execAltConsoleCallback()
  1549. {
  1550. if(mAltConsoleCommand && mAltConsoleCommand[0])
  1551. {
  1552. Con::setVariable("$ThisControl", avar("%d",getId()));
  1553. return Con::evaluate(mAltConsoleCommand, false);
  1554. }
  1555. return "";
  1556. }
  1557. void GuiControl::setText(const char *text)
  1558. {
  1559. mText = StringTable->insert(text, true);
  1560. }
  1561. void GuiControl::setTextID(const char *id)
  1562. {
  1563. S32 n = Con::getIntVariable(id, -1);
  1564. if (n != -1)
  1565. {
  1566. mTextID = StringTable->insert(id);
  1567. setTextID(n);
  1568. }
  1569. }
  1570. void GuiControl::setTextID(S32 id)
  1571. {
  1572. const UTF8 *str = getGUIString(id);
  1573. if (str)
  1574. setText((const char*)str);
  1575. }
  1576. const char *GuiControl::getText()
  1577. {
  1578. return mText;
  1579. }