guiControl.cc 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897
  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. Point2I origin = Point2I(0, 0);
  371. parentInnerExt = getInnerRect(origin, parent->mBounds.extent, NormalState, parent->mProfile).extent;
  372. }
  373. if (mHorizSizing == horizResizeCenter)
  374. newPosition.x = (parentInnerExt.x - mBounds.extent.x) >> 1;
  375. else if (mHorizSizing == horizResizeWidth)
  376. newExtent.x += deltaX;
  377. else if (mHorizSizing == horizResizeLeft)
  378. newPosition.x += deltaX;
  379. else if (mHorizSizing == horizResizeRelative && oldParentExtent.x != 0)
  380. {
  381. S32 newLeft = (newPosition.x * newParentExtent.x) / oldParentExtent.x;
  382. S32 newRight = ((newPosition.x + newExtent.x) * newParentExtent.x) / oldParentExtent.x;
  383. newPosition.x = newLeft;
  384. newExtent.x = newRight - newLeft;
  385. }
  386. if (mVertSizing == vertResizeCenter)
  387. newPosition.y = (parentInnerExt.y - mBounds.extent.y) >> 1;
  388. else if (mVertSizing == vertResizeHeight)
  389. newExtent.y += deltaY;
  390. else if (mVertSizing == vertResizeTop)
  391. newPosition.y += deltaY;
  392. else if(mVertSizing == vertResizeRelative && oldParentExtent.y != 0)
  393. {
  394. S32 newTop = (newPosition.y * newParentExtent.y) / oldParentExtent.y;
  395. S32 newBottom = ((newPosition.y + newExtent.y) * newParentExtent.y) / oldParentExtent.y;
  396. newPosition.y = newTop;
  397. newExtent.y = newBottom - newTop;
  398. }
  399. newExtent = extentBattery(newExtent);
  400. resize(newPosition, newExtent);
  401. }
  402. Point2I GuiControl::extentBattery(Point2I &newExtent)
  403. {
  404. if (mMinExtent.x == 0 && mMinExtent.y == 0)
  405. {
  406. return newExtent;
  407. }
  408. Point2I result = Point2I(newExtent);
  409. if (newExtent.x < mBounds.extent.x && newExtent.x < mMinExtent.x)
  410. {
  411. mStoredExtent.x += mBounds.extent.x > mMinExtent.x ? (mMinExtent.x - newExtent.x) : (mBounds.extent.x - newExtent.x);
  412. result.x = mMinExtent.x;
  413. }
  414. else if (newExtent.x > mBounds.extent.x && mStoredExtent.x > 0)
  415. {
  416. S32 charge = getMin(newExtent.x - mBounds.extent.x, mStoredExtent.x);
  417. mStoredExtent.x -= charge;
  418. result.x = newExtent.x - charge;
  419. }
  420. if (newExtent.y < mBounds.extent.y && newExtent.y < mMinExtent.y)
  421. {
  422. mStoredExtent.y += mBounds.extent.y > mMinExtent.y ? (mMinExtent.y - newExtent.y) : (mBounds.extent.y - newExtent.y);
  423. result.y = mMinExtent.y;
  424. }
  425. else if (newExtent.y > mBounds.extent.y && mStoredExtent.y > 0)
  426. {
  427. S32 charge = getMin(newExtent.y - mBounds.extent.y, mStoredExtent.y);
  428. mStoredExtent.y -= charge;
  429. result.y = newExtent.y - charge;
  430. }
  431. return result;
  432. }
  433. //----------------------------------------------------------------
  434. void GuiControl::onRender(Point2I offset, const RectI &updateRect)
  435. {
  436. RectI ctrlRect = applyMargins(offset, mBounds.extent, NormalState, mProfile);
  437. if (!ctrlRect.isValidRect())
  438. {
  439. return;
  440. }
  441. renderUniversalRect(ctrlRect, mProfile, NormalState);
  442. //Render Text
  443. dglSetBitmapModulation(mProfile->mFontColor);
  444. RectI fillRect = applyBorders(ctrlRect.point, ctrlRect.extent, NormalState, mProfile);
  445. RectI contentRect = applyPadding(fillRect.point, fillRect.extent, NormalState, mProfile);
  446. if(contentRect.isValidRect())
  447. {
  448. renderText(contentRect.point, contentRect.extent, mText, mProfile);
  449. //Render the childen
  450. renderChildControls(offset, contentRect, updateRect);
  451. }
  452. }
  453. RectI GuiControl::applyMargins(Point2I &offset, Point2I &extent, GuiControlState currentState, GuiControlProfile *profile)
  454. {
  455. //Get the border profiles
  456. GuiBorderProfile *leftProfile = profile->getLeftBorder();
  457. GuiBorderProfile *rightProfile = profile->getRightBorder();
  458. GuiBorderProfile *topProfile = profile->getTopBorder();
  459. GuiBorderProfile *bottomProfile = profile->getBottomBorder();
  460. S32 leftSize = (leftProfile) ? leftProfile->getMargin(currentState) : 0;
  461. S32 rightSize = (rightProfile) ? rightProfile->getMargin(currentState) : 0;
  462. S32 topSize = (topProfile) ? topProfile->getMargin(currentState) : 0;
  463. S32 bottomSize = (bottomProfile) ? bottomProfile->getMargin(currentState) : 0;
  464. return RectI(offset.x + leftSize, offset.y + topSize, (extent.x - leftSize) - rightSize, (extent.y - topSize) - bottomSize);
  465. }
  466. RectI GuiControl::applyBorders(Point2I &offset, Point2I &extent, GuiControlState currentState, GuiControlProfile *profile)
  467. {
  468. //Get the border profiles
  469. GuiBorderProfile *leftProfile = profile->getLeftBorder();
  470. GuiBorderProfile *rightProfile = profile->getRightBorder();
  471. GuiBorderProfile *topProfile = profile->getTopBorder();
  472. GuiBorderProfile *bottomProfile = profile->getBottomBorder();
  473. S32 leftSize = (leftProfile) ? leftProfile->getBorder(currentState) : 0;
  474. S32 rightSize = (rightProfile) ? rightProfile->getBorder(currentState) : 0;
  475. S32 topSize = (topProfile) ? topProfile->getBorder(currentState) : 0;
  476. S32 bottomSize = (bottomProfile) ? bottomProfile->getBorder(currentState) : 0;
  477. return RectI(offset.x + leftSize, offset.y + topSize, (extent.x - leftSize) - rightSize, (extent.y - topSize) - bottomSize);
  478. }
  479. RectI GuiControl::applyPadding(Point2I &offset, Point2I &extent, GuiControlState currentState, GuiControlProfile *profile)
  480. {
  481. //Get the border profiles
  482. GuiBorderProfile *leftProfile = profile->getLeftBorder();
  483. GuiBorderProfile *rightProfile = profile->getRightBorder();
  484. GuiBorderProfile *topProfile = profile->getTopBorder();
  485. GuiBorderProfile *bottomProfile = profile->getBottomBorder();
  486. S32 leftSize = (leftProfile) ? leftProfile->getPadding(currentState) : 0;
  487. S32 rightSize = (rightProfile) ? rightProfile->getPadding(currentState) : 0;
  488. S32 topSize = (topProfile) ? topProfile->getPadding(currentState) : 0;
  489. S32 bottomSize = (bottomProfile) ? bottomProfile->getPadding(currentState) : 0;
  490. return RectI(offset.x + leftSize, offset.y + topSize, (extent.x - leftSize) - rightSize, (extent.y - topSize) - bottomSize);
  491. }
  492. RectI GuiControl::getInnerRect(Point2I &offset, Point2I &extent, GuiControlState currentState, GuiControlProfile *profile)
  493. {
  494. //Get the border profiles
  495. GuiBorderProfile *leftProfile = profile->getLeftBorder();
  496. GuiBorderProfile *rightProfile = profile->getRightBorder();
  497. GuiBorderProfile *topProfile = profile->getTopBorder();
  498. GuiBorderProfile *bottomProfile = profile->getBottomBorder();
  499. S32 leftSize = (leftProfile) ? leftProfile->getMargin(currentState) + leftProfile->getBorder(currentState) + leftProfile->getPadding(currentState) : 0;
  500. S32 rightSize = (rightProfile) ? rightProfile->getMargin(currentState) + rightProfile->getBorder(currentState) + rightProfile->getPadding(currentState) : 0;
  501. S32 topSize = (topProfile) ? topProfile->getMargin(currentState) + topProfile->getBorder(currentState) + topProfile->getPadding(currentState) : 0;
  502. S32 bottomSize = (bottomProfile) ? bottomProfile->getMargin(currentState) + bottomProfile->getBorder(currentState) + bottomProfile->getPadding(currentState) : 0;
  503. return RectI(offset.x + leftSize, offset.y + topSize, (extent.x - leftSize) - rightSize, (extent.y - topSize) - bottomSize);
  504. }
  505. Point2I GuiControl::getOuterExtent(Point2I &innerExtent, GuiControlState currentState, GuiControlProfile *profile)
  506. {
  507. //Get the border profiles
  508. GuiBorderProfile *leftProfile = profile->getLeftBorder();
  509. GuiBorderProfile *rightProfile = profile->getRightBorder();
  510. GuiBorderProfile *topProfile = profile->getTopBorder();
  511. GuiBorderProfile *bottomProfile = profile->getBottomBorder();
  512. S32 leftSize = (leftProfile) ? leftProfile->getMargin(currentState) + leftProfile->getBorder(currentState) + leftProfile->getPadding(currentState) : 0;
  513. S32 rightSize = (rightProfile) ? rightProfile->getMargin(currentState) + rightProfile->getBorder(currentState) + rightProfile->getPadding(currentState) : 0;
  514. S32 topSize = (topProfile) ? topProfile->getMargin(currentState) + topProfile->getBorder(currentState) + topProfile->getPadding(currentState) : 0;
  515. S32 bottomSize = (bottomProfile) ? bottomProfile->getMargin(currentState) + bottomProfile->getBorder(currentState) + bottomProfile->getPadding(currentState) : 0;
  516. return Point2I(innerExtent.x + leftSize + rightSize, innerExtent.y + topSize + bottomSize);
  517. }
  518. bool GuiControl::renderTooltip(Point2I &cursorPos, const char* tipText )
  519. {
  520. #if !defined(TORQUE_OS_IOS) && !defined(TORQUE_OS_ANDROID) && !defined(TORQUE_OS_EMSCRIPTEN)
  521. // Short Circuit.
  522. if (!mAwake)
  523. return false;
  524. if ( dStrlen( mTooltip ) == 0 && ( tipText == NULL || dStrlen( tipText ) == 0 ) )
  525. return false;
  526. const char* renderTip = mTooltip;
  527. if( tipText != NULL )
  528. renderTip = tipText;
  529. // Finish if no root.
  530. GuiCanvas *root = getRoot();
  531. if ( !root )
  532. return false;
  533. if (!mTooltipProfile)
  534. setField("TooltipProfile", "GuiTooltipProfile");
  535. GFont *font = mTooltipProfile->mFont;
  536. // Set text bounds.
  537. Point2I textBounds( 0, 0 );
  538. // Fetch the width of a space.
  539. const S32 spaceWidth = (S32)font->getStrWidth(" ");
  540. // Fetch the maximum allowed tooltip extent.
  541. const S32 maxTooltipWidth = mTooltipWidth;
  542. // Fetch word count.
  543. const S32 wordCount = StringUnit::getUnitCount( renderTip, " " );
  544. // Reset line storage.
  545. const S32 tooltipLineStride = (S32)font->getHeight() + 4;
  546. const S32 maxTooltipLines = 20;
  547. S32 tooltipLineCount = 0;
  548. S32 tooltipLineWidth = 0;
  549. FrameTemp<StringBuffer> tooltipLines( maxTooltipLines );
  550. // Reset word indexing.
  551. S32 wordStartIndex = 0;
  552. S32 wordEndIndex = 0;
  553. // Search for end word.
  554. while( true )
  555. {
  556. // Do we have any words left?
  557. if ( wordEndIndex < wordCount )
  558. {
  559. // Yes, so fetch the word.
  560. const char* pWord = StringUnit::getUnit( renderTip, wordEndIndex, " " );
  561. // Add word length.
  562. const S32 wordLength = (S32)font->getStrWidth( pWord ) + spaceWidth;
  563. // Do we still have room?
  564. if ( (tooltipLineWidth + wordLength) < maxTooltipWidth )
  565. {
  566. // Yes, so add word length.
  567. tooltipLineWidth += wordLength;
  568. // Next word.
  569. wordEndIndex++;
  570. continue;
  571. }
  572. // Do we have any lines left?
  573. if ( tooltipLineCount < maxTooltipLines )
  574. {
  575. // Yes, so insert line.
  576. tooltipLines[tooltipLineCount++] = StringUnit::getUnits( renderTip, wordStartIndex, wordEndIndex-1, " " );
  577. // Update horizontal text bounds.
  578. if ( tooltipLineWidth > textBounds.x )
  579. textBounds.x = tooltipLineWidth;
  580. }
  581. // Set new line length.
  582. tooltipLineWidth = wordLength;
  583. // Set word start.
  584. wordStartIndex = wordEndIndex;
  585. // Next word.
  586. wordEndIndex++;
  587. continue;
  588. }
  589. // Do we have any words left?
  590. if ( wordStartIndex < wordCount )
  591. {
  592. // Yes, so do we have any lines left?
  593. if ( tooltipLineCount < maxTooltipLines )
  594. {
  595. // Yes, so insert line.
  596. tooltipLines[tooltipLineCount++] = StringUnit::getUnits( renderTip, wordStartIndex, wordCount-1, " " );
  597. // Update horizontal text bounds.
  598. if ( tooltipLineWidth > textBounds.x )
  599. textBounds.x = tooltipLineWidth;
  600. }
  601. }
  602. break;
  603. }
  604. // Controls the size of the inside (gutter) tooltip region.
  605. const S32 tooltipGutterSize = 5;
  606. // Adjust text bounds.
  607. textBounds.x += tooltipGutterSize * 2;
  608. textBounds.y = (((S32)font->getHeight() + 4) * tooltipLineCount - 4) + (tooltipGutterSize * 2);
  609. // Adjust to tooltip is always on-screen.
  610. Point2I screensize = Platform::getWindowSize();
  611. Point2I offset = cursorPos;
  612. offset.y += 22;
  613. if (screensize.x < (offset.x + textBounds.x))
  614. offset.x = screensize.x - textBounds.x;
  615. if(screensize.y < (offset.y + textBounds.y) )
  616. offset.y = screensize.y - textBounds.y;
  617. // Fetch the old clip.
  618. RectI oldClip = dglGetClipRect();
  619. // Set rectangle for the box, and set the clip rectangle.
  620. RectI rect(offset, textBounds);
  621. dglSetClipRect(rect);
  622. // Draw body and border of the tool tip
  623. renderUniversalRect(rect, mTooltipProfile, NormalState);
  624. // Draw the text centered in the tool tip box
  625. dglSetBitmapModulation( mTooltipProfile->mFontColor );
  626. Point2I start( tooltipGutterSize, tooltipGutterSize );
  627. for ( S32 lineIndex = 0; lineIndex < tooltipLineCount; lineIndex++ )
  628. {
  629. dglDrawText( font, start + offset, tooltipLines[lineIndex].getPtr8(), mProfile->mFontColors );
  630. offset.y += tooltipLineStride;
  631. }
  632. dglSetClipRect( oldClip );
  633. #endif
  634. return true;
  635. }
  636. void GuiControl::renderChildControls(Point2I offset, RectI content, const RectI &updateRect)
  637. {
  638. // 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.
  639. // updateRect is the area that this control was allowed to draw in. It should almost always be the same as the value in onRender.
  640. // content is the area that child controls are allowed to draw in.
  641. RectI clipRect = content;
  642. if(clipRect.intersect(dglGetClipRect()))
  643. {
  644. S32 size = objectList.size();
  645. S32 size_cpy = size;
  646. //-Mat look through our vector all normal-like, trying to use an iterator sometimes gives us
  647. //bad cast on good objects
  648. for( S32 count = 0; count < objectList.size(); count++ )
  649. {
  650. GuiControl *ctrl = (GuiControl *)objectList[count];
  651. if( ctrl == NULL ) {
  652. Con::errorf( "GuiControl::renderChildControls() object %i is NULL", count );
  653. continue;
  654. }
  655. if (ctrl->mVisible)
  656. {
  657. ctrl->mRenderInsetLT = content.point - offset;
  658. ctrl->mRenderInsetRB = mBounds.extent - (ctrl->mRenderInsetLT + content.extent);
  659. Point2I childPosition = content.point + ctrl->getPosition();
  660. RectI childClip(childPosition, ctrl->getExtent());
  661. if (childClip.intersect(clipRect))
  662. {
  663. RectI old = dglGetClipRect();
  664. dglSetClipRect(clipRect);
  665. glDisable(GL_CULL_FACE);
  666. ctrl->onRender(childPosition, RectI(childPosition, ctrl->getExtent()));
  667. dglSetClipRect(old);
  668. }
  669. }
  670. size_cpy = objectList.size(); // CHRIS: i know its wierd but the size of the list changes sometimes during execution of this loop
  671. if(size != size_cpy)
  672. {
  673. size = size_cpy;
  674. count--; // CHRIS: just to make sure one wasnt skipped.
  675. }
  676. }
  677. }
  678. }
  679. void GuiControl::setUpdateRegion(Point2I pos, Point2I ext)
  680. {
  681. Point2I upos = localToGlobalCoord(pos);
  682. GuiCanvas *root = getRoot();
  683. if (root)
  684. {
  685. root->addUpdateRegion(upos, ext);
  686. }
  687. }
  688. void GuiControl::setUpdate()
  689. {
  690. setUpdateRegion(Point2I(0,0), mBounds.extent);
  691. }
  692. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
  693. void GuiControl::awaken()
  694. {
  695. AssertFatal(!mAwake, "GuiControl::awaken: control is already awake");
  696. if(mAwake)
  697. return;
  698. iterator i;
  699. for(i = begin(); i != end(); i++)
  700. {
  701. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  702. AssertFatal(!ctrl->isAwake(), "GuiControl::awaken: child control is already awake");
  703. if(!ctrl->isAwake())
  704. ctrl->awaken();
  705. }
  706. AssertFatal(!mAwake, "GuiControl::awaken: should not be awake here");
  707. if(!mAwake)
  708. {
  709. if(!onWake())
  710. {
  711. Con::errorf(ConsoleLogEntry::General, "GuiControl::awaken: failed onWake for obj: %s", getName());
  712. AssertFatal(0, "GuiControl::awaken: failed onWake");
  713. deleteObject();
  714. }
  715. else
  716. {
  717. if (mTextID && *mTextID != 0)
  718. setTextID(mTextID);
  719. }
  720. }
  721. }
  722. void GuiControl::sleep()
  723. {
  724. AssertFatal(mAwake, "GuiControl::sleep: control is not awake");
  725. if(!mAwake)
  726. return;
  727. iterator i;
  728. for(i = begin(); i != end(); i++)
  729. {
  730. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  731. AssertFatal(ctrl->isAwake(), "GuiControl::sleep: child control is already asleep");
  732. if(ctrl->isAwake())
  733. ctrl->sleep();
  734. }
  735. AssertFatal(mAwake, "GuiControl::sleep: should not be asleep here");
  736. if(mAwake)
  737. onSleep();
  738. }
  739. void GuiControl::preRender()
  740. {
  741. AssertFatal(mAwake, "GuiControl::preRender: control is not awake");
  742. if(!mAwake)
  743. return;
  744. iterator i;
  745. for(i = begin(); i != end(); i++)
  746. {
  747. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  748. ctrl->preRender();
  749. }
  750. onPreRender();
  751. }
  752. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
  753. bool GuiControl::onWake()
  754. {
  755. AssertFatal( !mAwake, "GuiControl::onWake: control is already awake" );
  756. if( mAwake )
  757. return false;
  758. // [tom, 4/18/2005] Cause mLangTable to be refreshed in case it was changed
  759. mLangTable = NULL;
  760. // Grab the classname of this object
  761. const char *cName = getClassName();
  762. //make sure we have a profile
  763. if( !mProfile )
  764. {
  765. // Ensure the classname is a valid name...
  766. if( cName && cName[0] )
  767. {
  768. S32 pos = 0;
  769. for( pos = 0; pos <= (S32)dStrlen( cName ); pos++ )
  770. if( !dStrncmp( cName + pos, "Ctrl", 4 ) )
  771. break;
  772. if( pos != 0 ) {
  773. char buff[255];
  774. dStrncpy( buff, cName, pos );
  775. buff[pos] = '\0';
  776. dStrcat( buff, "Profile\0" );
  777. SimObject *obj = Sim::findObject( buff );
  778. if( obj )
  779. mProfile = dynamic_cast<GuiControlProfile*>( obj );
  780. }
  781. }
  782. // Ok lets check to see if that worked
  783. if( !mProfile ) {
  784. SimObject *obj = Sim::findObject( "GuiDefaultProfile" );
  785. if( obj )
  786. mProfile = dynamic_cast<GuiControlProfile*>(obj);
  787. }
  788. AssertFatal( mProfile, avar( "GuiControl: %s created with no profile.", getName() ) );
  789. }
  790. //set the flag
  791. mAwake = true;
  792. //set the layer
  793. GuiCanvas *root = getRoot();
  794. AssertFatal(root, "Unable to get the root Canvas.");
  795. GuiControl *parent = getParent();
  796. if (parent && parent != root)
  797. mLayer = parent->mLayer;
  798. //make sure the first responder exists
  799. if (! mFirstResponder)
  800. mFirstResponder = findFirstTabable();
  801. //see if we should force this control to be the first responder
  802. //if (mProfile->mTabable && mProfile->mCanKeyFocus)
  803. // setFirstResponder();
  804. //increment the profile
  805. mProfile->incRefCount();
  806. // Only invoke script callbacks if we have a namespace in which to do so
  807. // This will suppress warnings
  808. if( isMethod("onWake") )
  809. Con::executef(this, 1, "onWake");
  810. if (mTooltipProfile != NULL)
  811. mTooltipProfile->incRefCount();
  812. return true;
  813. }
  814. void GuiControl::onSleep()
  815. {
  816. AssertFatal(mAwake, "GuiControl::onSleep: control is not awake");
  817. if(!mAwake)
  818. return;
  819. //decrement the profile referrence
  820. if( mProfile != NULL )
  821. mProfile->decRefCount();
  822. clearFirstResponder();
  823. mouseUnlock();
  824. // Only invoke script callbacks if we have a namespace in which to do so
  825. // This will suppress warnings
  826. if( isMethod("onSleep") )
  827. Con::executef(this, 1, "onSleep");
  828. if (mTooltipProfile != NULL)
  829. mTooltipProfile->decRefCount();
  830. // Set Flag
  831. mAwake = false;
  832. }
  833. void GuiControl::setControlProfile(GuiControlProfile *prof)
  834. {
  835. AssertFatal(prof, "GuiControl::setControlProfile: invalid profile");
  836. if(prof == mProfile)
  837. return;
  838. if(mAwake)
  839. mProfile->decRefCount();
  840. mProfile = prof;
  841. if(mAwake)
  842. mProfile->incRefCount();
  843. }
  844. void GuiControl::onPreRender()
  845. {
  846. // do nothing.
  847. }
  848. //-----------------------------------------------------------------------------
  849. // checks up the parent hierarchy - if anyone above us is not savable returns false
  850. // otherwise, returns true.
  851. //-----------------------------------------------------------------------------
  852. bool GuiControl::getCanSaveParent()
  853. {
  854. GuiControl *walk = this;
  855. while(walk)
  856. {
  857. if(!walk->getCanSave())
  858. return false;
  859. walk = walk->getParent();
  860. }
  861. return true;
  862. }
  863. //-----------------------------------------------------------------------------
  864. // Can we Save to a TorqueScript file?
  865. //-----------------------------------------------------------------------------
  866. bool GuiControl::getCanSave()
  867. {
  868. return mCanSave;
  869. }
  870. //-----------------------------------------------------------------------------
  871. // Sets whether we can save out to a file (TorqueScript)
  872. //-----------------------------------------------------------------------------
  873. void GuiControl::setCanSave(bool bCanSave)
  874. {
  875. mCanSave = bCanSave;
  876. }
  877. ////////////////////////////////////////////////////////////////////////////////////////////////////
  878. // checks out mCanSave flag, if true just passes along to our parent,
  879. // if false, then we return without writing. Note, also, that
  880. // if our parent is not writeable, then we should not be writable...
  881. ////////////////////////////////////////////////////////////////////////////////////////////////////
  882. void GuiControl::write(Stream &stream, U32 tabStop, U32 flags)
  883. {
  884. //note: this will return false if either we, or any of our parents, are non-save controls
  885. bool bCanSave = getCanSaveParent();
  886. if(bCanSave)
  887. {
  888. Parent::write(stream, tabStop, flags);
  889. }
  890. }
  891. //This is only called if the control is deleted, not when the control is removed from its parent.
  892. void GuiControl::onRemove()
  893. {
  894. Parent::onRemove();
  895. }
  896. //For GuiControls, this will always just before it is actually removed.
  897. void GuiControl::onGroupRemove()
  898. {
  899. clearFirstResponder();
  900. }
  901. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
  902. const char *GuiControl::getScriptValue()
  903. {
  904. return NULL;
  905. }
  906. void GuiControl::setScriptValue(const char *value)
  907. {
  908. }
  909. void GuiControl::setConsoleVariable(const char *variable)
  910. {
  911. if (variable)
  912. {
  913. mConsoleVariable = StringTable->insert(variable);
  914. }
  915. else
  916. {
  917. mConsoleVariable = StringTable->EmptyString;
  918. }
  919. }
  920. //-----------------------------------------------------------------------------
  921. // finds and returns the first immediate child of ours whose
  922. // internal name matches the passed String. returns Null if not found.
  923. //-----------------------------------------------------------------------------
  924. void GuiControl::setConsoleCommand(const char *newCmd)
  925. {
  926. if (newCmd)
  927. mConsoleCommand = StringTable->insert(newCmd);
  928. else
  929. mConsoleCommand = StringTable->EmptyString;
  930. }
  931. const char * GuiControl::getConsoleCommand()
  932. {
  933. return mConsoleCommand;
  934. }
  935. void GuiControl::setSizing(S32 horz, S32 vert)
  936. {
  937. mHorizSizing = horz;
  938. mVertSizing = vert;
  939. }
  940. void GuiControl::setVariable(const char *value)
  941. {
  942. if (mConsoleVariable[0])
  943. Con::setVariable(mConsoleVariable, value);
  944. }
  945. void GuiControl::setIntVariable(S32 value)
  946. {
  947. if (mConsoleVariable[0])
  948. Con::setIntVariable(mConsoleVariable, value);
  949. }
  950. void GuiControl::setFloatVariable(F32 value)
  951. {
  952. if (mConsoleVariable[0])
  953. Con::setFloatVariable(mConsoleVariable, value);
  954. }
  955. const char * GuiControl::getVariable()
  956. {
  957. if (mConsoleVariable[0])
  958. return Con::getVariable(mConsoleVariable);
  959. else return NULL;
  960. }
  961. S32 GuiControl::getIntVariable()
  962. {
  963. if (mConsoleVariable[0])
  964. return Con::getIntVariable(mConsoleVariable);
  965. else return 0;
  966. }
  967. F32 GuiControl::getFloatVariable()
  968. {
  969. if (mConsoleVariable[0])
  970. return Con::getFloatVariable(mConsoleVariable);
  971. else return 0.0f;
  972. }
  973. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
  974. bool GuiControl::cursorInControl()
  975. {
  976. GuiCanvas *root = getRoot();
  977. if (! root) return false;
  978. Point2I pt = root->getCursorPos();
  979. Point2I offset = localToGlobalCoord(Point2I(0, 0));
  980. if (pt.x >= offset.x && pt.y >= offset.y &&
  981. pt.x < offset.x + mBounds.extent.x && pt.y < offset.y + mBounds.extent.y)
  982. {
  983. return true;
  984. }
  985. else
  986. {
  987. return false;
  988. }
  989. }
  990. bool GuiControl::pointInControl(const Point2I& parentCoordPoint)
  991. {
  992. S32 xt = parentCoordPoint.x - mBounds.point.x;
  993. S32 yt = parentCoordPoint.y - mBounds.point.y;
  994. return xt >= 0 && yt >= 0 && xt < mBounds.extent.x && yt < mBounds.extent.y;
  995. }
  996. GuiControl* GuiControl::findHitControl(const Point2I &pt, S32 initialLayer)
  997. {
  998. iterator i = end(); // find in z order (last to first)
  999. while (i != begin())
  1000. {
  1001. i--;
  1002. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  1003. if (initialLayer >= 0 && ctrl->mLayer > initialLayer)
  1004. {
  1005. continue;
  1006. }
  1007. else if (ctrl->mVisible && ctrl->pointInControl(pt - ctrl->mRenderInsetLT))
  1008. {
  1009. Point2I ptemp = pt - (ctrl->mBounds.point + ctrl->mRenderInsetLT);
  1010. GuiControl *hitCtrl = ctrl->findHitControl(ptemp);
  1011. if(hitCtrl->mProfile->mUseInput)
  1012. return hitCtrl;
  1013. }
  1014. }
  1015. return this;
  1016. }
  1017. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
  1018. bool GuiControl::isMouseLocked()
  1019. {
  1020. GuiCanvas *root = getRoot();
  1021. return root ? root->getMouseLockedControl() == this : false;
  1022. }
  1023. void GuiControl::mouseLock(GuiControl *lockingControl)
  1024. {
  1025. GuiCanvas *root = getRoot();
  1026. if (root)
  1027. root->mouseLock(lockingControl);
  1028. }
  1029. void GuiControl::mouseLock()
  1030. {
  1031. GuiCanvas *root = getRoot();
  1032. if (root)
  1033. root->mouseLock(this);
  1034. }
  1035. void GuiControl::mouseUnlock()
  1036. {
  1037. GuiCanvas *root = getRoot();
  1038. if (root)
  1039. root->mouseUnlock(this);
  1040. }
  1041. bool GuiControl::onInputEvent(const InputEvent &event)
  1042. {
  1043. // Do nothing by default...
  1044. return( false );
  1045. }
  1046. void GuiControl::onTouchUp(const GuiEvent &event)
  1047. {
  1048. }
  1049. void GuiControl::onTouchDown(const GuiEvent &event)
  1050. {
  1051. }
  1052. void GuiControl::onTouchMove(const GuiEvent &event)
  1053. {
  1054. //if this control is a dead end, make sure the event stops here
  1055. if ( !mVisible || !mAwake )
  1056. return;
  1057. //pass the event to the parent
  1058. GuiControl *parent = getParent();
  1059. if ( parent )
  1060. parent->onTouchMove( event );
  1061. }
  1062. void GuiControl::onTouchDragged(const GuiEvent &event)
  1063. {
  1064. }
  1065. void GuiControl::onTouchEnter(const GuiEvent &)
  1066. {
  1067. }
  1068. void GuiControl::onTouchLeave(const GuiEvent &)
  1069. {
  1070. }
  1071. bool GuiControl::onMouseWheelUp( const GuiEvent &event )
  1072. {
  1073. //if this control is a dead end, make sure the event stops here
  1074. if ( !mVisible || !mAwake )
  1075. return true;
  1076. //pass the event to the parent
  1077. GuiControl *parent = getParent();
  1078. if ( parent )
  1079. return parent->onMouseWheelUp( event );
  1080. else
  1081. return false;
  1082. }
  1083. bool GuiControl::onMouseWheelDown( const GuiEvent &event )
  1084. {
  1085. //if this control is a dead end, make sure the event stops here
  1086. if ( !mVisible || !mAwake )
  1087. return true;
  1088. //pass the event to the parent
  1089. GuiControl *parent = getParent();
  1090. if ( parent )
  1091. return parent->onMouseWheelDown( event );
  1092. else
  1093. return false;
  1094. }
  1095. void GuiControl::onRightMouseDown(const GuiEvent &)
  1096. {
  1097. }
  1098. void GuiControl::onRightMouseUp(const GuiEvent &)
  1099. {
  1100. }
  1101. void GuiControl::onRightMouseDragged(const GuiEvent &)
  1102. {
  1103. }
  1104. void GuiControl::onMiddleMouseDown(const GuiEvent &)
  1105. {
  1106. }
  1107. void GuiControl::onMiddleMouseUp(const GuiEvent &)
  1108. {
  1109. }
  1110. void GuiControl::onMiddleMouseDragged(const GuiEvent &)
  1111. {
  1112. }
  1113. GuiControl* GuiControl::findFirstTabable()
  1114. {
  1115. GuiControl *tabCtrl = NULL;
  1116. iterator i;
  1117. for (i = begin(); i != end(); i++)
  1118. {
  1119. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  1120. tabCtrl = ctrl->findFirstTabable();
  1121. if (tabCtrl)
  1122. {
  1123. mFirstResponder = tabCtrl;
  1124. return tabCtrl;
  1125. }
  1126. }
  1127. //nothing was found, therefore, see if this ctrl is tabable
  1128. return ( mProfile != NULL ) ? ( ( mProfile->mTabable && mAwake && mVisible ) ? this : NULL ) : NULL;
  1129. }
  1130. GuiControl* GuiControl::findLastTabable(bool firstCall)
  1131. {
  1132. //if this is the first call, clear the global
  1133. if (firstCall)
  1134. smPrevResponder = NULL;
  1135. //if this control is tabable, set the global
  1136. if (mProfile->mTabable)
  1137. smPrevResponder = this;
  1138. iterator i;
  1139. for (i = begin(); i != end(); i++)
  1140. {
  1141. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  1142. ctrl->findLastTabable(false);
  1143. }
  1144. //after the entire tree has been traversed, return the last responder found
  1145. mFirstResponder = smPrevResponder;
  1146. return smPrevResponder;
  1147. }
  1148. GuiControl *GuiControl::findNextTabable(GuiControl *curResponder, bool firstCall)
  1149. {
  1150. //if this is the first call, clear the global
  1151. if (firstCall)
  1152. smCurResponder = NULL;
  1153. //first find the current responder
  1154. if (curResponder == this)
  1155. smCurResponder = this;
  1156. //if the first responder has been found, return the very next *tabable* control
  1157. else if ( smCurResponder && mProfile->mTabable && mAwake && mVisible && mActive )
  1158. return( this );
  1159. //loop through, checking each child to see if it is the one that follows the firstResponder
  1160. GuiControl *tabCtrl = NULL;
  1161. iterator i;
  1162. for (i = begin(); i != end(); i++)
  1163. {
  1164. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  1165. tabCtrl = ctrl->findNextTabable(curResponder, false);
  1166. if (tabCtrl) break;
  1167. }
  1168. mFirstResponder = tabCtrl;
  1169. return tabCtrl;
  1170. }
  1171. GuiControl *GuiControl::findPrevTabable(GuiControl *curResponder, bool firstCall)
  1172. {
  1173. if (firstCall)
  1174. smPrevResponder = NULL;
  1175. //if this is the current reponder, return the previous one
  1176. if (curResponder == this)
  1177. return smPrevResponder;
  1178. //else if this is a responder, store it in case the next found is the current responder
  1179. else if ( mProfile->mTabable && mAwake && mVisible && mActive )
  1180. smPrevResponder = this;
  1181. //loop through, checking each child to see if it is the one that follows the firstResponder
  1182. GuiControl *tabCtrl = NULL;
  1183. iterator i;
  1184. for (i = begin(); i != end(); i++)
  1185. {
  1186. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  1187. tabCtrl = ctrl->findPrevTabable(curResponder, false);
  1188. if (tabCtrl) break;
  1189. }
  1190. mFirstResponder = tabCtrl;
  1191. return tabCtrl;
  1192. }
  1193. void GuiControl::onLoseFirstResponder()
  1194. {
  1195. // Since many controls have visual cues when they are the firstResponder...
  1196. setUpdate();
  1197. }
  1198. bool GuiControl::ControlIsChild(GuiControl *child)
  1199. {
  1200. //function returns true if this control, or one of it's children is the child control
  1201. if (child == this)
  1202. return true;
  1203. //loop through, checking each child to see if it is ,or contains, the firstResponder
  1204. iterator i;
  1205. for (i = begin(); i != end(); i++)
  1206. {
  1207. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  1208. if (ctrl->ControlIsChild(child)) return true;
  1209. }
  1210. //not found, therefore false
  1211. return false;
  1212. }
  1213. void GuiControl::onFocus()
  1214. {
  1215. //bubble the focus up
  1216. GuiControl *parent = getParent();
  1217. if (parent)
  1218. parent->onFocus();
  1219. }
  1220. bool GuiControl::isFirstResponder()
  1221. {
  1222. GuiCanvas *root = getRoot();
  1223. return root && root->getFirstResponder() == this;
  1224. }
  1225. void GuiControl::setFirstResponder( GuiControl* firstResponder )
  1226. {
  1227. if ( firstResponder && firstResponder->mProfile->mCanKeyFocus )
  1228. mFirstResponder = firstResponder;
  1229. GuiControl *parent = getParent();
  1230. if ( parent )
  1231. parent->setFirstResponder( firstResponder );
  1232. }
  1233. void GuiControl::setFirstResponder()
  1234. {
  1235. if ( mAwake && mVisible )
  1236. {
  1237. GuiControl *parent = getParent();
  1238. if (mProfile->mCanKeyFocus == true && parent != NULL )
  1239. {
  1240. parent->setFirstResponder(this);
  1241. // Since many controls have visual cues when they are the firstResponder...
  1242. this->setUpdate();
  1243. }
  1244. }
  1245. }
  1246. void GuiControl::clearFirstResponder()
  1247. {
  1248. GuiControl *parent = this;
  1249. while((parent = parent->getParent()) != NULL)
  1250. {
  1251. if(parent->mFirstResponder == this)
  1252. parent->mFirstResponder = NULL;
  1253. else
  1254. break;
  1255. }
  1256. }
  1257. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
  1258. void GuiControl::buildAcceleratorMap()
  1259. {
  1260. //add my own accel key
  1261. addAcceleratorKey();
  1262. //add all my childrens keys
  1263. iterator i;
  1264. for(i = begin(); i != end(); i++)
  1265. {
  1266. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  1267. ctrl->buildAcceleratorMap();
  1268. }
  1269. }
  1270. void GuiControl::addAcceleratorKey()
  1271. {
  1272. //see if we have an accelerator
  1273. if (mAcceleratorKey == StringTable->EmptyString)
  1274. return;
  1275. EventDescriptor accelEvent;
  1276. ActionMap::createEventDescriptor(mAcceleratorKey, &accelEvent);
  1277. //now we have a modifier, and a key, add them to the canvas
  1278. GuiCanvas *root = getRoot();
  1279. if (root)
  1280. root->addAcceleratorKey(this, 0, accelEvent.eventCode, accelEvent.flags);
  1281. }
  1282. void GuiControl::acceleratorKeyPress(U32 index)
  1283. {
  1284. onAction();
  1285. }
  1286. void GuiControl::acceleratorKeyRelease(U32 index)
  1287. {
  1288. //do nothing
  1289. }
  1290. bool GuiControl::onKeyDown(const GuiEvent &event)
  1291. {
  1292. //pass the event to the parent
  1293. GuiControl *parent = getParent();
  1294. if (parent)
  1295. return parent->onKeyDown(event);
  1296. else
  1297. return false;
  1298. }
  1299. bool GuiControl::onKeyRepeat(const GuiEvent &event)
  1300. {
  1301. // default to just another key down.
  1302. return onKeyDown(event);
  1303. }
  1304. bool GuiControl::onKeyUp(const GuiEvent &event)
  1305. {
  1306. //pass the event to the parent
  1307. GuiControl *parent = getParent();
  1308. if (parent)
  1309. return parent->onKeyUp(event);
  1310. else
  1311. return false;
  1312. }
  1313. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
  1314. void GuiControl::onAction()
  1315. {
  1316. if (! mActive)
  1317. return;
  1318. //execute the console command
  1319. if (mConsoleCommand && mConsoleCommand[0])
  1320. {
  1321. execConsoleCallback();
  1322. }
  1323. else
  1324. Con::executef(this, 1, "onAction");
  1325. }
  1326. void GuiControl::onMessage(GuiControl *sender, S32 msg)
  1327. {
  1328. }
  1329. void GuiControl::messageSiblings(S32 message)
  1330. {
  1331. GuiControl *parent = getParent();
  1332. if (! parent) return;
  1333. GuiControl::iterator i;
  1334. for(i = parent->begin(); i != parent->end(); i++)
  1335. {
  1336. GuiControl *ctrl = dynamic_cast<GuiControl *>(*i);
  1337. if (ctrl != this)
  1338. ctrl->onMessage(this, message);
  1339. }
  1340. }
  1341. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
  1342. void GuiControl::onDialogPush()
  1343. {
  1344. // Notify Script.
  1345. if( isMethod("onDialogPush") )
  1346. Con::executef(this, 1, "onDialogPush");
  1347. }
  1348. void GuiControl::onDialogPop()
  1349. {
  1350. // Notify Script.
  1351. if( isMethod("onDialogPop") )
  1352. Con::executef(this, 1, "onDialogPop");
  1353. }
  1354. //------------------------------------------------------------------------------
  1355. void GuiControl::setVisible(bool value)
  1356. {
  1357. mVisible = value;
  1358. iterator i;
  1359. setUpdate();
  1360. for(i = begin(); i != end(); i++)
  1361. {
  1362. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  1363. ctrl->clearFirstResponder();
  1364. }
  1365. GuiControl *parent = getParent();
  1366. if (parent)
  1367. parent->childResized(this);
  1368. }
  1369. void GuiControl::makeFirstResponder(bool value)
  1370. {
  1371. if ( value )
  1372. //setFirstResponder(this);
  1373. setFirstResponder();
  1374. else
  1375. clearFirstResponder();
  1376. }
  1377. void GuiControl::setActive( bool value )
  1378. {
  1379. mActive = value;
  1380. if (value && isMethod("onActive"))
  1381. Con::executef(this, 1, "onActive");
  1382. else if (!value && isMethod("onInactive"))
  1383. Con::executef(this, 1, "onInactive");
  1384. if ( !mActive )
  1385. clearFirstResponder();
  1386. if ( mVisible && mAwake )
  1387. setUpdate();
  1388. }
  1389. void GuiControl::getScrollLineSizes(U32 *rowHeight, U32 *columnWidth)
  1390. {
  1391. // default to 10 pixels in y, 30 pixels in x
  1392. *columnWidth = 30;
  1393. *rowHeight = 30;
  1394. }
  1395. void GuiControl::renderText(Point2I &offset, Point2I &extent, const char *text, GuiControlProfile *profile, TextRotationOptions rot)
  1396. {
  1397. RectI old = dglGetClipRect();
  1398. RectI clipRect = RectI(offset, extent);
  1399. if (clipRect.intersect(old))
  1400. {
  1401. dglSetClipRect(clipRect);
  1402. GFont *font = profile->mFont;
  1403. S32 textWidth = 0;
  1404. const S32 textHeight = font->getHeight();
  1405. S32 totalWidth = extent.x;
  1406. S32 totalHeight = extent.y;
  1407. if (rot != tRotateNone)
  1408. {
  1409. totalWidth = extent.y;
  1410. totalHeight = extent.x;
  1411. }
  1412. Point2I startOffset = Point2I(0,0);
  1413. vector<string> lineList = vector<string>();
  1414. if (!mTextWrap)
  1415. {
  1416. lineList.push_back(text);
  1417. }
  1418. else
  1419. {
  1420. vector<string> paragraphList = vector<string>();
  1421. istringstream f(text);
  1422. string s;
  1423. while(getline(f, s)) {
  1424. paragraphList.push_back(s);
  1425. }
  1426. for (string &paragraph : paragraphList)
  1427. {
  1428. vector<string> wordList = vector<string>();
  1429. istringstream f2(paragraph);
  1430. string s2;
  1431. while (getline(f2, s2, ' ')) {
  1432. wordList.push_back(s2);
  1433. }
  1434. //now process the word list
  1435. string line;
  1436. line.clear();
  1437. for (string &word : wordList)
  1438. {
  1439. if (font->getStrWidth(word.c_str()) >= totalWidth)
  1440. {
  1441. if (line.size() > 0)
  1442. {
  1443. lineList.push_back(string(line));
  1444. line.clear();
  1445. }
  1446. lineList.push_back(word);
  1447. continue;
  1448. }
  1449. string prevLine = string(line);
  1450. line += (line.size() > 0) ? " " + word : word;
  1451. if (font->getStrWidth(line.c_str()) >= totalWidth)
  1452. {
  1453. lineList.push_back(prevLine);
  1454. line = word;
  1455. }
  1456. }
  1457. lineList.push_back(string(line));
  1458. }
  1459. }
  1460. //first align vertical
  1461. S32 blockHeight = textHeight * lineList.size();
  1462. if (blockHeight < totalHeight)
  1463. {
  1464. startOffset.y = getTextVerticalOffset(blockHeight, totalHeight, profile->mVAlignment);
  1465. }
  1466. else
  1467. {
  1468. startOffset.y = getTextVerticalOffset(blockHeight, totalHeight, GuiControlProfile::VertAlignmentType::MiddleVAlign);
  1469. }
  1470. //Now print each line
  1471. for(string &line : lineList)
  1472. {
  1473. // align the horizontal
  1474. textWidth = font->getStrWidth(line.c_str());
  1475. if(textWidth < totalWidth)
  1476. {
  1477. startOffset.x = getTextHorizontalOffset(textWidth, totalWidth, profile->mAlignment);
  1478. }
  1479. Point2I start = Point2I(0, 0);
  1480. F32 rotation;
  1481. if (rot == tRotateNone)
  1482. {
  1483. start += startOffset;
  1484. rotation = 0.0f;
  1485. }
  1486. else if (rot == tRotateLeft)
  1487. {
  1488. start.x = startOffset.y;
  1489. start.y = extent.y + startOffset.x;
  1490. rotation = 90.0f;
  1491. }
  1492. else if (rot == tRotateRight)
  1493. {
  1494. start.x = extent.x - startOffset.y;
  1495. start.y = startOffset.x;
  1496. rotation = -90.0f;
  1497. }
  1498. dglDrawText( font, start + offset + profile->mTextOffset, line.c_str(), profile->mFontColors, 9, rotation );
  1499. startOffset.y += textHeight;
  1500. }
  1501. dglSetClipRect(old);
  1502. }
  1503. }
  1504. S32 GuiControl::getTextHorizontalOffset(S32 textWidth, S32 totalWidth, GuiControlProfile::AlignmentType align)
  1505. {
  1506. if (align == GuiControlProfile::RightAlign)
  1507. {
  1508. return totalWidth - textWidth;
  1509. }
  1510. else if (align == GuiControlProfile::CenterAlign)
  1511. {
  1512. return (totalWidth - textWidth) / 2;
  1513. }
  1514. return 0;//left aligned
  1515. }
  1516. S32 GuiControl::getTextVerticalOffset(S32 textHeight, S32 totalHeight, GuiControlProfile::VertAlignmentType align)
  1517. {
  1518. if (align == GuiControlProfile::MiddleVAlign)
  1519. {
  1520. return (totalHeight - textHeight) / 2;
  1521. }
  1522. else if (align == GuiControlProfile::BottomVAlign)
  1523. {
  1524. return totalHeight - textHeight;
  1525. }
  1526. return 0;
  1527. }
  1528. void GuiControl::getCursor(GuiCursor *&cursor, bool &showCursor, const GuiEvent &lastGuiEvent)
  1529. {
  1530. lastGuiEvent;
  1531. if(GuiControl::smCursorChanged != -1 && !isMouseLocked())
  1532. {
  1533. // We've already changed the cursor,
  1534. // so set it back before we change it again.
  1535. Input::popCursor();
  1536. // We haven't changed it
  1537. GuiControl::smCursorChanged = -1;
  1538. }
  1539. }
  1540. const char* GuiControl::execConsoleCallback()
  1541. {
  1542. if (mConsoleCommand && mConsoleCommand[0])
  1543. {
  1544. Con::setVariable("$ThisControl", avar("%d",getId()));
  1545. return Con::evaluate(mConsoleCommand, false);
  1546. }
  1547. return "";
  1548. }
  1549. const char* GuiControl::execAltConsoleCallback()
  1550. {
  1551. if(mAltConsoleCommand && mAltConsoleCommand[0])
  1552. {
  1553. Con::setVariable("$ThisControl", avar("%d",getId()));
  1554. return Con::evaluate(mAltConsoleCommand, false);
  1555. }
  1556. return "";
  1557. }
  1558. void GuiControl::setText(const char *text)
  1559. {
  1560. mText = StringTable->insert(text, true);
  1561. }
  1562. void GuiControl::setTextID(const char *id)
  1563. {
  1564. S32 n = Con::getIntVariable(id, -1);
  1565. if (n != -1)
  1566. {
  1567. mTextID = StringTable->insert(id);
  1568. setTextID(n);
  1569. }
  1570. }
  1571. void GuiControl::setTextID(S32 id)
  1572. {
  1573. const UTF8 *str = getGUIString(id);
  1574. if (str)
  1575. setText((const char*)str);
  1576. }
  1577. const char *GuiControl::getText()
  1578. {
  1579. return mText;
  1580. }