field.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 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/engineAPI.h"
  23. #include "platform/platform.h"
  24. #include "gui/editor/inspector/field.h"
  25. #include "gui/buttons/guiIconButtonCtrl.h"
  26. #include "gui/editor/guiInspector.h"
  27. #include "core/util/safeDelete.h"
  28. #include "gfx/gfxDrawUtil.h"
  29. #include "math/mathTypes.h"
  30. #include "core/strings/stringUnit.h"
  31. IMPLEMENT_CONOBJECT(GuiInspectorField);
  32. ConsoleDocClass( GuiInspectorField,
  33. "@brief The GuiInspectorField control is a representation of a single abstract "
  34. "field for a given ConsoleObject derived object.\n\n"
  35. "Editor use only.\n\n"
  36. "@internal"
  37. );
  38. //-----------------------------------------------------------------------------
  39. GuiInspectorField::GuiInspectorField( GuiInspector* inspector,
  40. GuiInspectorGroup* parent,
  41. AbstractClassRep::Field* field )
  42. : mParent( parent ),
  43. mInspector( inspector ),
  44. mField( field ),
  45. mFieldArrayIndex( NULL ),
  46. mEdit( NULL ),
  47. mTargetObject(NULL),
  48. mUseHeightOverride(false),
  49. mHighlighted(false),
  50. mHeightOverride(18),
  51. mSpecialEditField(false),
  52. mVariableName(StringTable->EmptyString()),
  53. mCallbackName(StringTable->EmptyString())
  54. {
  55. if( field != NULL )
  56. mCaption = field->pFieldname;
  57. else
  58. mCaption = StringTable->EmptyString();
  59. setCanSave( false );
  60. setBounds(0,0,100,18);
  61. if( field != NULL )
  62. _setFieldDocs( field->pFieldDocs );
  63. }
  64. //-----------------------------------------------------------------------------
  65. GuiInspectorField::GuiInspectorField()
  66. : mParent( NULL ),
  67. mInspector( NULL ),
  68. mField( NULL ),
  69. mEdit( NULL ),
  70. mCaption( StringTable->EmptyString() ),
  71. mFieldArrayIndex( NULL ),
  72. mHighlighted( false ),
  73. mTargetObject(NULL),
  74. mVariableName(StringTable->EmptyString()),
  75. mCallbackName(StringTable->EmptyString()),
  76. mSpecialEditField(false),
  77. mUseHeightOverride(false),
  78. mHeightOverride(18)
  79. {
  80. setCanSave( false );
  81. }
  82. //-----------------------------------------------------------------------------
  83. GuiInspectorField::~GuiInspectorField()
  84. {
  85. }
  86. //-----------------------------------------------------------------------------
  87. void GuiInspectorField::init( GuiInspector *inspector, GuiInspectorGroup *group )
  88. {
  89. mInspector = inspector;
  90. mParent = group;
  91. }
  92. //-----------------------------------------------------------------------------
  93. bool GuiInspectorField::onAdd()
  94. {
  95. setInspectorProfile();
  96. if ( !Parent::onAdd() )
  97. return false;
  98. if ( !mInspector )
  99. return false;
  100. mEdit = constructEditControl();
  101. if ( mEdit == NULL )
  102. return false;
  103. S32 fieldHeight = 18;
  104. if (mUseHeightOverride)
  105. fieldHeight = mHeightOverride;
  106. setBounds(0,0,100, fieldHeight);
  107. // Add our edit as a child
  108. addObject( mEdit );
  109. // Calculate Caption and EditCtrl Rects
  110. updateRects();
  111. // Force our editField to set it's value
  112. updateValue();
  113. Con::evaluatef("%d.edit = %d;", this->getId(), mEdit->getId());
  114. return true;
  115. }
  116. //-----------------------------------------------------------------------------
  117. bool GuiInspectorField::resize( const Point2I &newPosition, const Point2I &newExtent )
  118. {
  119. if ( !Parent::resize( newPosition, newExtent ) )
  120. return false;
  121. return updateRects();
  122. }
  123. //-----------------------------------------------------------------------------
  124. void GuiInspectorField::onRender( Point2I offset, const RectI &updateRect )
  125. {
  126. RectI ctrlRect(offset, getExtent());
  127. // Render fillcolor...
  128. if ( mProfile->mOpaque )
  129. GFX->getDrawUtil()->drawRectFill(ctrlRect, mProfile->mFillColor);
  130. // Render caption...
  131. if ( mCaption && mCaption[0] )
  132. {
  133. // Backup current ClipRect
  134. RectI clipBackup = GFX->getClipRect();
  135. RectI clipRect = updateRect;
  136. // The rect within this control in which our caption must fit.
  137. RectI rect( offset + mCaptionRect.point + mProfile->mTextOffset, mCaptionRect.extent + Point2I(1,1) - Point2I(5,0) );
  138. // Now clipRect is the amount of our caption rect that is actually visible.
  139. bool hit = clipRect.intersect( rect );
  140. if ( hit )
  141. {
  142. GFX->setClipRect( clipRect );
  143. GFXDrawUtil *drawer = GFX->getDrawUtil();
  144. // Backup modulation color
  145. ColorI currColor;
  146. drawer->getBitmapModulation( &currColor );
  147. // Draw caption background...
  148. if( !isActive() )
  149. GFX->getDrawUtil()->drawRectFill( clipRect, mProfile->mFillColorNA );
  150. else if ( mHighlighted )
  151. GFX->getDrawUtil()->drawRectFill( clipRect, mProfile->mFillColorHL );
  152. // Draw caption text...
  153. drawer->setBitmapModulation( !isActive() ? mProfile->mFontColorNA : mHighlighted ? mProfile->mFontColorHL : mProfile->mFontColor );
  154. // Clip text with '...' if too long to fit
  155. String clippedText( mCaption );
  156. clipText( clippedText, clipRect.extent.x );
  157. renderJustifiedText( offset + mProfile->mTextOffset, getExtent(), clippedText );
  158. // Restore modulation color
  159. drawer->setBitmapModulation( currColor );
  160. // Restore previous ClipRect
  161. GFX->setClipRect( clipBackup );
  162. }
  163. }
  164. // Render Children...
  165. renderChildControls(offset, updateRect);
  166. // Render border...
  167. if ( mProfile->mBorder )
  168. renderBorder(ctrlRect, mProfile);
  169. // Render divider...
  170. Point2I worldPnt = mEditCtrlRect.point + offset;
  171. GFX->getDrawUtil()->drawLine( worldPnt.x - 5,
  172. worldPnt.y,
  173. worldPnt.x - 5,
  174. worldPnt.y + getHeight(),
  175. !isActive() ? mProfile->mBorderColorNA : mHighlighted ? mProfile->mBorderColorHL : mProfile->mBorderColor );
  176. }
  177. //-----------------------------------------------------------------------------
  178. void GuiInspectorField::setFirstResponder( GuiControl *firstResponder )
  179. {
  180. Parent::setFirstResponder( firstResponder );
  181. if ( firstResponder == this || firstResponder == mEdit )
  182. {
  183. mInspector->setHighlightField( this );
  184. }
  185. }
  186. //-----------------------------------------------------------------------------
  187. void GuiInspectorField::onMouseDown( const GuiEvent &event )
  188. {
  189. if ( mCaptionRect.pointInRect( globalToLocalCoord( event.mousePoint ) ) )
  190. {
  191. if ( mEdit )
  192. //mEdit->onMouseDown( event );
  193. mInspector->setHighlightField( this );
  194. }
  195. else
  196. Parent::onMouseDown( event );
  197. }
  198. //-----------------------------------------------------------------------------
  199. void GuiInspectorField::onRightMouseUp( const GuiEvent &event )
  200. {
  201. if ( mCaptionRect.pointInRect( globalToLocalCoord( event.mousePoint ) ) )
  202. Con::executef( mInspector, "onFieldRightClick", getIdString() );
  203. else
  204. Parent::onMouseDown( event );
  205. }
  206. //-----------------------------------------------------------------------------
  207. void GuiInspectorField::setData( const char* data, bool callbacks )
  208. {
  209. if (mSpecialEditField)
  210. {
  211. if (mTargetObject != nullptr && mVariableName != StringTable->EmptyString())
  212. {
  213. mTargetObject->setDataField(mVariableName, NULL, data);
  214. if (mCallbackName != StringTable->EmptyString())
  215. Con::executef(mInspector, mCallbackName, mVariableName, data, mTargetObject);
  216. }
  217. else if (mVariableName != StringTable->EmptyString())
  218. {
  219. Con::setVariable(mVariableName, data);
  220. if (mCallbackName != StringTable->EmptyString())
  221. Con::executef(mInspector, mCallbackName, mVariableName, data);
  222. }
  223. }
  224. if( mField == NULL )
  225. return;
  226. if( verifyData( data ) )
  227. {
  228. String strData = data;
  229. const U32 numTargets = mInspector->getNumInspectObjects();
  230. if( callbacks && numTargets > 1 )
  231. Con::executef( mInspector, "onBeginCompoundEdit" );
  232. for( U32 i = 0; i < numTargets; ++ i )
  233. {
  234. //For now, for simplicity's sake, you can only edit the components in a simple edit
  235. SimObject* target = NULL;
  236. if (numTargets == 1)
  237. {
  238. target = mTargetObject;
  239. if (!target)
  240. target = mInspector->getInspectObject(i);
  241. }
  242. else
  243. {
  244. target = mInspector->getInspectObject(i);
  245. }
  246. String oldValue = target->getDataField( mField->pFieldname, mFieldArrayIndex);
  247. // For numeric fields, allow input expressions.
  248. String newValue = strData;
  249. S32 type= mField->type;
  250. if( type == TypeS8 || type == TypeS32 || type == TypeF32 )
  251. {
  252. char buffer[ 2048 ];
  253. expandEscape( buffer, newValue );
  254. newValue = (const char*)Con::evaluatef( "$f = \"%s\"; return ( %s );", oldValue.c_str(), buffer );
  255. Con::evaluatef("$f=0;");
  256. }
  257. else if( type == TypeS32Vector
  258. || type == TypeF32Vector
  259. || type == TypeColorI
  260. || type == TypeColorF
  261. || type == TypePoint2I
  262. || type == TypePoint2F
  263. || type == TypePoint3F
  264. || type == TypePoint4F
  265. || type == TypeRectI
  266. || type == TypeRectF
  267. || type == TypeMatrixPosition
  268. || type == TypeMatrixRotation
  269. || type == TypeBox3F
  270. || type == TypeRectUV
  271. || type == TypeRotationF)
  272. {
  273. //TODO: we should actually take strings into account and not chop things up between quotes
  274. U32 numNewUnits = StringUnit::getUnitCount( newValue, " \t\n\r" );
  275. StringBuilder strNew;
  276. bool isFirst = true;
  277. for( U32 n = 0; n < numNewUnits; ++ n )
  278. {
  279. char oldComponentVal[ 1024 ];
  280. StringUnit::getUnit( oldValue, n, " \t\n\r", oldComponentVal, sizeof( oldComponentVal ) );
  281. char newComponentExpr[ 1024 ];
  282. StringUnit::getUnit( newValue, n, " \t\n\r", newComponentExpr, sizeof( newComponentExpr ) );
  283. char buffer[ 2048 ];
  284. expandEscape( buffer, newComponentExpr );
  285. const char* newComponentVal = Con::evaluatef( "$f = \"%s\"; $v = \"%s\"; return ( %s );",
  286. oldComponentVal, oldValue.c_str(), buffer );
  287. Con::evaluatef("$f=0;$v=0;");
  288. if( !isFirst )
  289. strNew.append( ' ' );
  290. strNew.append( newComponentVal );
  291. isFirst = false;
  292. }
  293. newValue = strNew.end();
  294. }
  295. target->inspectPreApply();
  296. // Fire callback single-object undo.
  297. if( callbacks )
  298. Con::executef( mInspector, "onInspectorFieldModified",
  299. target->getIdString(),
  300. mField->pFieldname,
  301. mFieldArrayIndex ? mFieldArrayIndex : "(null)",
  302. oldValue.c_str(),
  303. newValue.c_str() );
  304. target->setDataField( mField->pFieldname, mFieldArrayIndex, newValue );
  305. // Give the target a chance to validate.
  306. target->inspectPostApply();
  307. }
  308. if( callbacks && numTargets > 1 )
  309. Con::executef( mInspector, "onEndCompoundEdit" );
  310. }
  311. // Force our edit to update
  312. updateValue();
  313. }
  314. //-----------------------------------------------------------------------------
  315. const char* GuiInspectorField::getData( U32 inspectObjectIndex )
  316. {
  317. if (!mSpecialEditField)
  318. {
  319. if (mField == NULL)
  320. return "";
  321. if (mTargetObject)
  322. return mTargetObject->getDataField(mField->pFieldname, mFieldArrayIndex);
  323. return mInspector->getInspectObject(inspectObjectIndex)->getDataField(mField->pFieldname, mFieldArrayIndex);
  324. }
  325. else
  326. {
  327. if (mTargetObject != nullptr && mVariableName != StringTable->EmptyString())
  328. {
  329. return mTargetObject->getDataField(mVariableName, NULL);
  330. }
  331. else if (mVariableName != StringTable->EmptyString())
  332. {
  333. return Con::getVariable(mVariableName);
  334. }
  335. else
  336. {
  337. return "";
  338. }
  339. }
  340. }
  341. //-----------------------------------------------------------------------------
  342. void GuiInspectorField::resetData()
  343. {
  344. if( !mField )
  345. return;
  346. SimObject* inspectObject = getInspector()->getInspectObject();
  347. SimObject* tempObject = static_cast< SimObject* >( inspectObject->getClassRep()->create() );
  348. setData( tempObject->getDataField( mField->pFieldname, mFieldArrayIndex ) );
  349. delete tempObject;
  350. }
  351. //-----------------------------------------------------------------------------
  352. void GuiInspectorField::setInspectorField( AbstractClassRep::Field *field, StringTableEntry caption, const char*arrayIndex )
  353. {
  354. mField = field;
  355. if ( arrayIndex != NULL )
  356. mFieldArrayIndex = StringTable->insert( arrayIndex );
  357. if ( !caption || !caption[0] )
  358. mCaption = getFieldName();
  359. else
  360. mCaption = caption;
  361. if ( mField != NULL )
  362. _setFieldDocs( mField->pFieldDocs );
  363. }
  364. //-----------------------------------------------------------------------------
  365. StringTableEntry GuiInspectorField::getRawFieldName()
  366. {
  367. if( !mField )
  368. return StringTable->EmptyString();
  369. return mField->pFieldname;
  370. }
  371. //-----------------------------------------------------------------------------
  372. StringTableEntry GuiInspectorField::getFieldName()
  373. {
  374. // Sanity
  375. if ( mField == NULL )
  376. return StringTable->EmptyString();
  377. // Array element?
  378. if( mFieldArrayIndex != NULL )
  379. {
  380. S32 frameTempSize = dStrlen( mField->pFieldname ) + 32;
  381. FrameTemp<char> valCopy( frameTempSize );
  382. dSprintf( (char *)valCopy, frameTempSize, "%s[%s]", mField->pFieldname, mFieldArrayIndex );
  383. // Return formatted element
  384. return StringTable->insert( valCopy );
  385. }
  386. // Plain field name.
  387. return mField->pFieldname;
  388. }
  389. //-----------------------------------------------------------------------------
  390. StringTableEntry GuiInspectorField::getFieldType()
  391. {
  392. if( !mField )
  393. return StringTable->EmptyString();
  394. return ConsoleBaseType::getType( mField->type )->getTypeName();
  395. }
  396. //-----------------------------------------------------------------------------
  397. GuiControl* GuiInspectorField::constructEditControl()
  398. {
  399. GuiControl* retCtrl = new GuiTextEditCtrl();
  400. static StringTableEntry sProfile = StringTable->insert( "profile" );
  401. retCtrl->setDataField( sProfile, NULL, "GuiInspectorTextEditProfile" );
  402. _registerEditControl( retCtrl );
  403. char szBuffer[512];
  404. dSprintf( szBuffer, 512, "%d.apply(%d.getText());",getId(), retCtrl->getId() );
  405. // Suffices to hook on to "validate" as regardless of whether we lose
  406. // focus through the user pressing enter or clicking away on another
  407. // keyboard control, we will see a validate call.
  408. retCtrl->setField("validate", szBuffer );
  409. return retCtrl;
  410. }
  411. //-----------------------------------------------------------------------------
  412. void GuiInspectorField::setInspectorProfile()
  413. {
  414. GuiControlProfile *profile = NULL;
  415. if( mInspector && (mInspector->getNumInspectObjects() > 1) )
  416. {
  417. if( !hasSameValueInAllObjects() )
  418. Sim::findObject( "GuiInspectorMultiFieldDifferentProfile", profile );
  419. else
  420. Sim::findObject( "GuiInspectorMultiFieldProfile", profile );
  421. }
  422. if( !profile )
  423. Sim::findObject( "GuiInspectorFieldProfile", profile );
  424. if( profile )
  425. setControlProfile( profile );
  426. }
  427. //-----------------------------------------------------------------------------
  428. void GuiInspectorField::setValue( StringTableEntry newValue )
  429. {
  430. GuiTextEditCtrl *ctrl = dynamic_cast<GuiTextEditCtrl*>( mEdit );
  431. if( ctrl != NULL )
  432. ctrl->setText( newValue );
  433. }
  434. //-----------------------------------------------------------------------------
  435. void GuiInspectorField::setEditControl(GuiControl* editCtrl)
  436. {
  437. if (mEdit)
  438. mEdit->deleteObject();
  439. mEdit = editCtrl;
  440. addObject(mEdit);
  441. }
  442. //-----------------------------------------------------------------------------
  443. bool GuiInspectorField::updateRects()
  444. {
  445. S32 dividerPos, dividerMargin;
  446. mInspector->getDivider( dividerPos, dividerMargin );
  447. Point2I fieldExtent = getExtent();
  448. Point2I fieldPos = getPosition();
  449. S32 editWidth = dividerPos - dividerMargin;
  450. mEditCtrlRect.set( fieldExtent.x - dividerPos + dividerMargin, 1, editWidth, fieldExtent.y - 1 );
  451. mCaptionRect.set( 0, 0, fieldExtent.x - dividerPos - dividerMargin, fieldExtent.y );
  452. if ( !mEdit )
  453. return false;
  454. return mEdit->resize( mEditCtrlRect.point, mEditCtrlRect.extent );
  455. }
  456. //-----------------------------------------------------------------------------
  457. void GuiInspectorField::updateValue()
  458. {
  459. if( mInspector->getNumInspectObjects() > 1 )
  460. {
  461. setInspectorProfile();
  462. if( !hasSameValueInAllObjects() )
  463. setValue( StringTable->EmptyString() );
  464. else
  465. setValue( getData() );
  466. }
  467. else
  468. setValue( getData() );
  469. }
  470. //-----------------------------------------------------------------------------
  471. void GuiInspectorField::setHLEnabled( bool enabled )
  472. {
  473. mHighlighted = enabled;
  474. if ( mHighlighted )
  475. {
  476. if ( mEdit && !mEdit->isFirstResponder() )
  477. {
  478. mEdit->setFirstResponder();
  479. GuiTextEditCtrl *edit = dynamic_cast<GuiTextEditCtrl*>( mEdit );
  480. if ( edit )
  481. {
  482. mouseUnlock();
  483. edit->mouseLock();
  484. edit->setCursorPos(0);
  485. }
  486. }
  487. _executeSelectedCallback();
  488. }
  489. }
  490. //-----------------------------------------------------------------------------
  491. bool GuiInspectorField::hasSameValueInAllObjects()
  492. {
  493. char value1[ 2048 ];
  494. // Get field value from first object.
  495. const char* data1 = getData( 0 );
  496. if( data1 )
  497. {
  498. dStrncpy( value1, data1, sizeof( value1 ) );
  499. value1[ sizeof( value1 ) - 1 ] = 0;
  500. }
  501. else
  502. value1[ 0 ] = 0;
  503. // Check if all other objects have the same value.
  504. const U32 numObjects = mInspector->getNumInspectObjects();
  505. for( U32 i = 1; i < numObjects; ++ i )
  506. {
  507. const char* value2 = getData( i );
  508. if( !value2 )
  509. value2 = "";
  510. if( String::compare( value1, value2 ) != 0 )
  511. return false;
  512. }
  513. return true;
  514. }
  515. //-----------------------------------------------------------------------------
  516. void GuiInspectorField::_executeSelectedCallback()
  517. {
  518. if( mField )
  519. Con::executef( mInspector, "onFieldSelected", mField->pFieldname, ConsoleBaseType::getType(mField->type)->getTypeName(), mFieldDocs.c_str() );
  520. }
  521. //-----------------------------------------------------------------------------
  522. void GuiInspectorField::_registerEditControl( GuiControl *ctrl )
  523. {
  524. char szName[512];
  525. if(mInspector->getInspectObject() != nullptr)
  526. dSprintf( szName, 512, "IE_%s_%d_%s_Field", ctrl->getClassName(), mInspector->getInspectObject()->getId(), mCaption);
  527. else
  528. dSprintf(szName, 512, "IE_%s_%s_Field", ctrl->getClassName(), mCaption);
  529. // Register the object
  530. ctrl->registerObject( szName );
  531. }
  532. //-----------------------------------------------------------------------------
  533. void GuiInspectorField::_setFieldDocs( StringTableEntry docs )
  534. {
  535. mFieldDocs = String();
  536. if( docs && docs[ 0 ] )
  537. {
  538. // Only accept first line of docs for brevity.
  539. const char* newline = dStrchr( docs, '\n' );
  540. if( newline )
  541. mFieldDocs = String( docs, newline - docs );
  542. else
  543. mFieldDocs = docs;
  544. }
  545. }
  546. void GuiInspectorField::setHeightOverride(bool useOverride, U32 heightOverride)
  547. {
  548. mUseHeightOverride = useOverride;
  549. if (useOverride)
  550. mHeightOverride = heightOverride;
  551. S32 fieldHeight = 18;
  552. if (mUseHeightOverride)
  553. fieldHeight = mHeightOverride;
  554. RectI bnds = getBounds();
  555. setBounds(bnds.point.x, bnds.point.y, bnds.extent.x, fieldHeight);
  556. // Calculate Caption and EditCtrl Rects
  557. updateRects();
  558. // Force our editField to set it's value
  559. updateValue();
  560. }
  561. //=============================================================================
  562. // Console Methods.
  563. //=============================================================================
  564. // MARK: ---- Console Methods ----
  565. //-----------------------------------------------------------------------------
  566. DefineEngineMethod( GuiInspectorField, getInspector, S32, (), , "() - Return the GuiInspector to which this field belongs." )
  567. {
  568. return object->getInspector()->getId();
  569. }
  570. //-----------------------------------------------------------------------------
  571. DefineEngineMethod( GuiInspectorField, getInspectedFieldName, const char*, (), , "() - Return the name of the field edited by this inspector field." )
  572. {
  573. return object->getFieldName();
  574. }
  575. //-----------------------------------------------------------------------------
  576. DefineEngineMethod( GuiInspectorField, getInspectedFieldType, const char*, (), , "() - Return the type of the field edited by this inspector field." )
  577. {
  578. return object->getFieldType();
  579. }
  580. //-----------------------------------------------------------------------------
  581. DefineEngineMethod( GuiInspectorField, apply, void, ( const char * newValue, bool callbacks ), (true), "( string newValue, bool callbacks=true ) - Set the field's value. Suppress callbacks for undo if callbacks=false." )
  582. {
  583. object->setData( newValue, callbacks );
  584. }
  585. //-----------------------------------------------------------------------------
  586. DefineEngineMethod( GuiInspectorField, applyWithoutUndo, void, (const char * data), , "() - Set field value without recording undo (same as 'apply( value, false )')." )
  587. {
  588. object->setData( data, false );
  589. }
  590. //-----------------------------------------------------------------------------
  591. DefineEngineMethod( GuiInspectorField, getData, const char*, (), , "() - Return the value currently displayed on the field." )
  592. {
  593. return object->getData();
  594. }
  595. //-----------------------------------------------------------------------------
  596. DefineEngineMethod( GuiInspectorField, reset, void, (), , "() - Reset to default value." )
  597. {
  598. object->resetData();
  599. }
  600. DefineEngineMethod(GuiInspectorField, setCaption, void, (String newCaption),, "() - Reset to default value.")
  601. {
  602. object->setCaption(StringTable->insert(newCaption.c_str()));
  603. }
  604. DefineEngineMethod(GuiInspectorField, setHeightOverride, void, (bool useOverride, U32 heightOverride), , "")
  605. {
  606. object->setHeightOverride(useOverride, heightOverride);
  607. }
  608. DefineEngineMethod(GuiInspectorField, setEditControl, void, (GuiControl* editCtrl), (nullAsType<GuiControl*>()), "() - Reset to default value.")
  609. {
  610. object->setEditControl(editCtrl);
  611. }