field.cpp 23 KB

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