field.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  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. ConsoleValue evaluationResult;
  251. if( type == TypeS8 || type == TypeS32 || type == TypeF32 )
  252. {
  253. char buffer[ 2048 ];
  254. expandEscape( buffer, newValue );
  255. evaluationResult = Con::evaluatef("$f = \"%s\"; return ( %s );", oldValue.c_str(), buffer);
  256. newValue = evaluationResult.getString();
  257. Con::evaluatef("$f=0;");
  258. }
  259. else if( type == TypeS32Vector
  260. || type == TypeF32Vector
  261. || type == TypeColorI
  262. || type == TypeColorF
  263. || type == TypePoint2I
  264. || type == TypePoint2F
  265. || type == TypePoint3F
  266. || type == TypePoint4F
  267. || type == TypeRectI
  268. || type == TypeRectF
  269. || type == TypeMatrixPosition
  270. || type == TypeMatrixRotation
  271. || type == TypeBox3F
  272. || type == TypeRectUV
  273. || type == TypeRotationF)
  274. {
  275. //TODO: we should actually take strings into account and not chop things up between quotes
  276. U32 numNewUnits = StringUnit::getUnitCount( newValue, " \t\n\r" );
  277. StringBuilder strNew;
  278. bool isFirst = true;
  279. for( U32 n = 0; n < numNewUnits; ++ n )
  280. {
  281. char oldComponentVal[ 1024 ];
  282. StringUnit::getUnit( oldValue, n, " \t\n\r", oldComponentVal, sizeof( oldComponentVal ) );
  283. char newComponentExpr[ 1024 ];
  284. StringUnit::getUnit( newValue, n, " \t\n\r", newComponentExpr, sizeof( newComponentExpr ) );
  285. char buffer[ 2048 ];
  286. expandEscape( buffer, newComponentExpr );
  287. evaluationResult = Con::evaluatef("$f = \"%s\"; $v = \"%s\"; return ( %s );",
  288. oldComponentVal, oldValue.c_str(), buffer);
  289. Con::evaluatef("$f=0;$v=0;");
  290. if( !isFirst )
  291. strNew.append( ' ' );
  292. strNew.append( evaluationResult.getString() );
  293. isFirst = false;
  294. }
  295. newValue = strNew.end();
  296. }
  297. target->inspectPreApply();
  298. // Fire callback single-object undo.
  299. if( callbacks )
  300. Con::executef( mInspector, "onInspectorFieldModified",
  301. target->getIdString(),
  302. mField->pFieldname,
  303. mFieldArrayIndex ? mFieldArrayIndex : "(null)",
  304. oldValue.c_str(),
  305. newValue.c_str() );
  306. target->setDataField( mField->pFieldname, mFieldArrayIndex, newValue );
  307. // Give the target a chance to validate.
  308. target->inspectPostApply();
  309. }
  310. if( callbacks && numTargets > 1 )
  311. Con::executef( mInspector, "onEndCompoundEdit" );
  312. }
  313. // Force our edit to update
  314. updateValue();
  315. }
  316. //-----------------------------------------------------------------------------
  317. const char* GuiInspectorField::getData( U32 inspectObjectIndex )
  318. {
  319. if (!mSpecialEditField)
  320. {
  321. if (mField == NULL)
  322. return "";
  323. if (mTargetObject)
  324. return mTargetObject->getDataField(mField->pFieldname, mFieldArrayIndex);
  325. return mInspector->getInspectObject(inspectObjectIndex)->getDataField(mField->pFieldname, mFieldArrayIndex);
  326. }
  327. else
  328. {
  329. if (mTargetObject != nullptr && mVariableName != StringTable->EmptyString())
  330. {
  331. return mTargetObject->getDataField(mVariableName, NULL);
  332. }
  333. else if (mVariableName != StringTable->EmptyString())
  334. {
  335. return Con::getVariable(mVariableName);
  336. }
  337. else
  338. {
  339. return "";
  340. }
  341. }
  342. }
  343. //-----------------------------------------------------------------------------
  344. void GuiInspectorField::resetData()
  345. {
  346. if( !mField )
  347. return;
  348. SimObject* inspectObject = getInspector()->getInspectObject();
  349. SimObject* tempObject = static_cast< SimObject* >( inspectObject->getClassRep()->create() );
  350. setData( tempObject->getDataField( mField->pFieldname, mFieldArrayIndex ) );
  351. delete tempObject;
  352. }
  353. //-----------------------------------------------------------------------------
  354. void GuiInspectorField::setInspectorField( AbstractClassRep::Field *field, StringTableEntry caption, const char*arrayIndex )
  355. {
  356. mField = field;
  357. if ( arrayIndex != NULL )
  358. mFieldArrayIndex = StringTable->insert( arrayIndex );
  359. if ( !caption || !caption[0] )
  360. mCaption = getFieldName();
  361. else
  362. mCaption = caption;
  363. if ( mField != NULL )
  364. _setFieldDocs( mField->pFieldDocs );
  365. }
  366. //-----------------------------------------------------------------------------
  367. StringTableEntry GuiInspectorField::getRawFieldName()
  368. {
  369. if( !mField )
  370. return StringTable->EmptyString();
  371. return mField->pFieldname;
  372. }
  373. //-----------------------------------------------------------------------------
  374. StringTableEntry GuiInspectorField::getFieldName()
  375. {
  376. // Sanity
  377. if ( mField == NULL )
  378. return StringTable->EmptyString();
  379. // Array element?
  380. if( mFieldArrayIndex != NULL )
  381. {
  382. S32 frameTempSize = dStrlen( mField->pFieldname ) + 32;
  383. FrameTemp<char> valCopy( frameTempSize );
  384. dSprintf( (char *)valCopy, frameTempSize, "%s[%s]", mField->pFieldname, mFieldArrayIndex );
  385. // Return formatted element
  386. return StringTable->insert( valCopy );
  387. }
  388. // Plain field name.
  389. return mField->pFieldname;
  390. }
  391. //-----------------------------------------------------------------------------
  392. StringTableEntry GuiInspectorField::getFieldType()
  393. {
  394. if( !mField )
  395. return StringTable->EmptyString();
  396. return ConsoleBaseType::getType( mField->type )->getTypeName();
  397. }
  398. //-----------------------------------------------------------------------------
  399. GuiControl* GuiInspectorField::constructEditControl()
  400. {
  401. GuiControl* retCtrl = new GuiTextEditCtrl();
  402. static StringTableEntry sProfile = StringTable->insert( "profile" );
  403. retCtrl->setDataField( sProfile, NULL, "GuiInspectorTextEditProfile" );
  404. _registerEditControl( retCtrl );
  405. char szBuffer[512];
  406. dSprintf( szBuffer, 512, "%d.apply(%d.getText());",getId(), retCtrl->getId() );
  407. // Suffices to hook on to "validate" as regardless of whether we lose
  408. // focus through the user pressing enter or clicking away on another
  409. // keyboard control, we will see a validate call.
  410. retCtrl->setField("validate", szBuffer );
  411. return retCtrl;
  412. }
  413. //-----------------------------------------------------------------------------
  414. void GuiInspectorField::setInspectorProfile()
  415. {
  416. GuiControlProfile *profile = NULL;
  417. if( mInspector && (mInspector->getNumInspectObjects() > 1) )
  418. {
  419. if( !hasSameValueInAllObjects() )
  420. Sim::findObject( "GuiInspectorMultiFieldDifferentProfile", profile );
  421. else
  422. Sim::findObject( "GuiInspectorMultiFieldProfile", profile );
  423. }
  424. if( !profile )
  425. Sim::findObject( "GuiInspectorFieldProfile", profile );
  426. if( profile )
  427. setControlProfile( profile );
  428. }
  429. //-----------------------------------------------------------------------------
  430. void GuiInspectorField::setValue( StringTableEntry newValue )
  431. {
  432. GuiTextEditCtrl *ctrl = dynamic_cast<GuiTextEditCtrl*>( mEdit );
  433. if( ctrl != NULL )
  434. ctrl->setText( newValue );
  435. }
  436. //-----------------------------------------------------------------------------
  437. void GuiInspectorField::setEditControl(GuiControl* editCtrl)
  438. {
  439. if (mEdit)
  440. mEdit->deleteObject();
  441. mEdit = editCtrl;
  442. addObject(mEdit);
  443. }
  444. //-----------------------------------------------------------------------------
  445. bool GuiInspectorField::updateRects()
  446. {
  447. S32 dividerPos, dividerMargin;
  448. mInspector->getDivider( dividerPos, dividerMargin );
  449. Point2I fieldExtent = getExtent();
  450. Point2I fieldPos = getPosition();
  451. S32 editWidth = dividerPos - dividerMargin;
  452. mEditCtrlRect.set( fieldExtent.x - dividerPos + dividerMargin, 1, editWidth, fieldExtent.y - 1 );
  453. mCaptionRect.set( 0, 0, fieldExtent.x - dividerPos - dividerMargin, fieldExtent.y );
  454. if ( !mEdit )
  455. return false;
  456. return mEdit->resize( mEditCtrlRect.point, mEditCtrlRect.extent );
  457. }
  458. //-----------------------------------------------------------------------------
  459. void GuiInspectorField::updateValue()
  460. {
  461. if( mInspector->getNumInspectObjects() > 1 )
  462. {
  463. setInspectorProfile();
  464. if( !hasSameValueInAllObjects() )
  465. setValue( StringTable->EmptyString() );
  466. else
  467. setValue( getData() );
  468. }
  469. else
  470. setValue( getData() );
  471. }
  472. //-----------------------------------------------------------------------------
  473. void GuiInspectorField::setHLEnabled( bool enabled )
  474. {
  475. mHighlighted = enabled;
  476. if ( mHighlighted )
  477. {
  478. if ( mEdit && !mEdit->isFirstResponder() )
  479. {
  480. mEdit->setFirstResponder();
  481. GuiTextEditCtrl *edit = dynamic_cast<GuiTextEditCtrl*>( mEdit );
  482. if ( edit )
  483. {
  484. mouseUnlock();
  485. edit->mouseLock();
  486. edit->setCursorPos(0);
  487. }
  488. }
  489. _executeSelectedCallback();
  490. }
  491. }
  492. //-----------------------------------------------------------------------------
  493. bool GuiInspectorField::hasSameValueInAllObjects()
  494. {
  495. char value1[ 2048 ];
  496. // Get field value from first object.
  497. const char* data1 = getData( 0 );
  498. if( data1 )
  499. {
  500. dStrncpy( value1, data1, sizeof( value1 ) );
  501. value1[ sizeof( value1 ) - 1 ] = 0;
  502. }
  503. else
  504. value1[ 0 ] = 0;
  505. // Check if all other objects have the same value.
  506. const U32 numObjects = mInspector->getNumInspectObjects();
  507. for( U32 i = 1; i < numObjects; ++ i )
  508. {
  509. const char* value2 = getData( i );
  510. if( !value2 )
  511. value2 = "";
  512. if( String::compare( value1, value2 ) != 0 )
  513. return false;
  514. }
  515. return true;
  516. }
  517. //-----------------------------------------------------------------------------
  518. void GuiInspectorField::_executeSelectedCallback()
  519. {
  520. if( mField )
  521. Con::executef( mInspector, "onFieldSelected", mField->pFieldname, ConsoleBaseType::getType(mField->type)->getTypeName(), mFieldDocs.c_str() );
  522. }
  523. //-----------------------------------------------------------------------------
  524. void GuiInspectorField::_registerEditControl( GuiControl *ctrl )
  525. {
  526. char szName[512];
  527. if(mInspector->getInspectObject() != nullptr)
  528. dSprintf( szName, 512, "IE_%s_%d_%s_Field", ctrl->getClassName(), mInspector->getInspectObject()->getId(), mCaption);
  529. else
  530. dSprintf(szName, 512, "IE_%s_%s_Field", ctrl->getClassName(), mCaption);
  531. // Register the object
  532. ctrl->registerObject( szName );
  533. }
  534. //-----------------------------------------------------------------------------
  535. void GuiInspectorField::_setFieldDocs( StringTableEntry docs )
  536. {
  537. mFieldDocs = String();
  538. if( docs && docs[ 0 ] )
  539. {
  540. // Only accept first line of docs for brevity.
  541. const char* newline = dStrchr( docs, '\n' );
  542. if( newline )
  543. mFieldDocs = String( docs, newline - docs );
  544. else
  545. mFieldDocs = docs;
  546. }
  547. }
  548. void GuiInspectorField::setHeightOverride(bool useOverride, U32 heightOverride)
  549. {
  550. mUseHeightOverride = useOverride;
  551. if (useOverride)
  552. mHeightOverride = heightOverride;
  553. S32 fieldHeight = 18;
  554. if (mUseHeightOverride)
  555. fieldHeight = mHeightOverride;
  556. RectI bnds = getBounds();
  557. setBounds(bnds.point.x, bnds.point.y, bnds.extent.x, fieldHeight);
  558. // Calculate Caption and EditCtrl Rects
  559. updateRects();
  560. // Force our editField to set it's value
  561. updateValue();
  562. }
  563. //=============================================================================
  564. // Console Methods.
  565. //=============================================================================
  566. // MARK: ---- Console Methods ----
  567. //-----------------------------------------------------------------------------
  568. DefineEngineMethod( GuiInspectorField, getInspector, S32, (), , "() - Return the GuiInspector to which this field belongs." )
  569. {
  570. return object->getInspector()->getId();
  571. }
  572. //-----------------------------------------------------------------------------
  573. DefineEngineMethod( GuiInspectorField, getInspectedFieldName, const char*, (), , "() - Return the name of the field edited by this inspector field." )
  574. {
  575. return object->getFieldName();
  576. }
  577. //-----------------------------------------------------------------------------
  578. DefineEngineMethod( GuiInspectorField, getInspectedFieldType, const char*, (), , "() - Return the type of the field edited by this inspector field." )
  579. {
  580. return object->getFieldType();
  581. }
  582. //-----------------------------------------------------------------------------
  583. 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." )
  584. {
  585. object->setData( newValue, callbacks );
  586. }
  587. //-----------------------------------------------------------------------------
  588. DefineEngineMethod( GuiInspectorField, applyWithoutUndo, void, (const char * data), , "() - Set field value without recording undo (same as 'apply( value, false )')." )
  589. {
  590. object->setData( data, false );
  591. }
  592. //-----------------------------------------------------------------------------
  593. DefineEngineMethod( GuiInspectorField, getData, const char*, (), , "() - Return the value currently displayed on the field." )
  594. {
  595. return object->getData();
  596. }
  597. //-----------------------------------------------------------------------------
  598. DefineEngineMethod( GuiInspectorField, reset, void, (), , "() - Reset to default value." )
  599. {
  600. object->resetData();
  601. }
  602. DefineEngineMethod(GuiInspectorField, setCaption, void, (String newCaption),, "() - Reset to default value.")
  603. {
  604. object->setCaption(StringTable->insert(newCaption.c_str()));
  605. }
  606. DefineEngineMethod(GuiInspectorField, setHeightOverride, void, (bool useOverride, U32 heightOverride), , "")
  607. {
  608. object->setHeightOverride(useOverride, heightOverride);
  609. }
  610. DefineEngineMethod(GuiInspectorField, setEditControl, void, (GuiControl* editCtrl), (nullAsType<GuiControl*>()), "() - Reset to default value.")
  611. {
  612. object->setEditControl(editCtrl);
  613. }