field.cpp 23 KB

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