variableField.cpp
Engine/source/gui/editor/inspector/variableField.cpp
Public Functions
ConsoleDocClass(GuiInspectorVariableField , "@brief Inspector support <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> variables in <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiVariableInspector.\n\n</a>" "Editor use <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">only.\n\n</a>" "@internal" )
Detailed Description
Public Functions
ConsoleDocClass(GuiInspectorVariableField , "@brief Inspector support <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> variables in <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiVariableInspector.\n\n</a>" "Editor use <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">only.\n\n</a>" "@internal" )
IMPLEMENT_CONOBJECT(GuiInspectorVariableField )
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#include "platform/platform.h" 25#include "gui/editor/inspector/variableField.h" 26 27#include "gui/buttons/guiIconButtonCtrl.h" 28#include "gui/editor/guiInspector.h" 29#include "core/util/safeDelete.h" 30#include "gfx/gfxDrawUtil.h" 31#include "util/settings.h" 32 33//----------------------------------------------------------------------------- 34// GuiInspectorVariableField 35//----------------------------------------------------------------------------- 36 37IMPLEMENT_CONOBJECT(GuiInspectorVariableField); 38 39ConsoleDocClass( GuiInspectorVariableField, 40 "@brief Inspector support for variables in a GuiVariableInspector.\n\n" 41 "Editor use only.\n\n" 42 "@internal" 43); 44 45GuiInspectorVariableField::GuiInspectorVariableField() 46 : mVariableName(StringTable->EmptyString()), 47 mSetCallbackName(StringTable->EmptyString()), 48 mOwnerObject(NULL) 49{ 50} 51 52GuiInspectorVariableField::~GuiInspectorVariableField() 53{ 54} 55 56bool GuiInspectorVariableField::onAdd() 57{ 58 if( !mInspector ) 59 { 60 Con::errorf("GuiInspectorVariableField::onAdd - Fail - No inspector"); 61 return false; 62 } 63 64 setInspectorProfile(); 65 66 // Hack: skip our immediate parent 67 if ( !Parent::Parent::onAdd() ) 68 return false; 69 70 { 71 GuiTextEditCtrl *edit = new GuiTextEditCtrl(); 72 73 edit->setDataField( StringTable->insert("profile"), NULL, "GuiInspectorTextEditProfile" ); 74 75 edit->registerObject(); 76 77 char szBuffer[512]; 78 dSprintf( szBuffer, 512, "%d.apply(%d.getText());",getId(), edit->getId() ); 79 edit->setField("AltCommand", szBuffer ); 80 edit->setField("Validate", szBuffer ); 81 82 mEdit = edit; 83 } 84 85 setBounds(0,0,100,18); 86 87 // Add our edit as a child 88 addObject( mEdit ); 89 90 // Calculate Caption and EditCtrl Rects 91 updateRects(); 92 93 // Force our editField to set it's value 94 updateValue(); 95 96 return true; 97} 98 99void GuiInspectorVariableField::setData( const char* data, bool callbacks ) 100{ 101 if (mOwnerObject == nullptr && mVariableName == StringTable->EmptyString()) 102 { 103 if (!mCaption || mCaption[0] == 0) 104 return; 105 106 Con::setVariable(mCaption, data); 107 } 108 else 109 { 110 if (mOwnerObject != nullptr) 111 { 112 //Special case: if our object is a Settings class, we'll assume that we're trying to get/set the fields via the Setting class's normal behavior 113 //otherwise, use fields as normal 114 Settings* setting = dynamic_cast<Settings*>(mOwnerObject); 115 if (setting) 116 { 117 setting->setValue(mVariableName, data); 118 } 119 else 120 { 121 mOwnerObject->setDataField(mVariableName, NULL, data); 122 } 123 } 124 else 125 { 126 //probably a global var if we have no object attached, so just let it set 127 Con::setVariable(mVariableName, data); 128 } 129 } 130 131 // Force our edit to update 132 updateValue(); 133} 134 135const char* GuiInspectorVariableField::getData( U32 inspectObjectIndex ) 136{ 137 if ( !mCaption || mCaption[0] == 0 ) 138 return ""; 139 140 Settings* setting = dynamic_cast<Settings*>(mOwnerObject); 141 if (setting) 142 { 143 return setting->value(mVariableName); 144 } 145 else 146 { 147 return Con::getVariable(mCaption); 148 } 149} 150 151void GuiInspectorVariableField::setValue( const char* newValue ) 152{ 153 GuiTextEditCtrl *ctrl = dynamic_cast<GuiTextEditCtrl*>( mEdit ); 154 if( ctrl != NULL ) 155 ctrl->setText( newValue ); 156} 157 158void GuiInspectorVariableField::updateValue() 159{ 160 if ( !mCaption || mCaption[0] == 0 ) 161 return; 162 163 setValue( getData() ); 164} 165