void ReflectVectorInterpreter::InterpretField(const Field* field, const std::vector<Reflect::Element*>& instances, Container* parent) { if ( field->m_Flags & FieldFlags::Hide ) { return; } // create the container ContainerPtr container = CreateControl< Container >(); parent->AddChild( container ); // create the label LabelPtr label = CreateControl< Label >(); container->AddChild( label ); label->a_HelpText.Set( field->GetProperty( TXT( "HelpText" ) ) ); tstring temp; bool converted = Helium::ConvertString( field->m_UIName, temp ); HELIUM_ASSERT( converted ); label->BindText( temp ); // compute dimensions int dimensions = 2; if ( field->m_SerializerID == Reflect::GetType<Vector3Serializer>() ) { dimensions += 1; } if ( field->m_SerializerID == Reflect::GetType<Vector4Serializer>() ) { dimensions += 2; } // create the dimension ui for ( int offset = 0; offset < dimensions*4; offset += 4 ) { // create the serializers std::vector<Reflect::Serializer*> data; std::vector<Reflect::Element*>::const_iterator itr = instances.begin(); std::vector<Reflect::Element*>::const_iterator end = instances.end(); for ( ; itr != end; ++itr ) { SerializerPtr s = new F32Serializer (); s->ConnectField(*itr, field, offset); m_Serializers.push_back(s); data.push_back(s); } // create the text box ValuePtr value = CreateControl< Value >(); container->AddChild( value ); value->a_IsReadOnly.Set( ( field->m_Flags & FieldFlags::ReadOnly ) == FieldFlags::ReadOnly ); value->a_HelpText.Set( field->GetProperty( TXT( "HelpText" ) ) ); // bind the ui to the serializers value->Bind( new MultiStringFormatter<Serializer>( data ) ); } }
void ReflectValueInterpreter::InterpretField(const Field* field, const std::vector<Reflect::Object*>& instances, Container* parent) { if (field->m_Flags & FieldFlags::Hide) { return; } // // Create the ui we are generating // ContainerPtr container = CreateControl<Container>(); bool readOnly = ( field->m_Flags & FieldFlags::ReadOnly ) == FieldFlags::ReadOnly; // // Parse // tstring fieldUI; field->GetProperty( TXT( "UIScript" ), fieldUI ); bool result = Script::Parse(fieldUI, this, parent->GetCanvas(), container, field->m_Flags); if (!result) { if ( field->m_DataClass == Reflect::GetClass<EnumerationData>() ) { ChoicePtr choice = CreateControl<Choice>(); const Reflect::Enumeration* enumeration = Reflect::ReflectionCast< Enumeration >( field->m_Type ); std::vector< ChoiceItem > items; items.resize( enumeration->m_Elements.GetSize() ); DynArray< EnumerationElement >::ConstIterator itr = enumeration->m_Elements.Begin(); DynArray< EnumerationElement >::ConstIterator end = enumeration->m_Elements.End(); for ( size_t index=0; itr != end; ++itr, ++index ) { ChoiceItem& item = items[index]; item.m_Key = itr->m_Name; item.m_Data = itr->m_Name; } choice->a_HelpText.Set( field->GetProperty( TXT( "HelpText" ) ) ); choice->a_Items.Set( items ); choice->a_IsDropDown.Set( true ); choice->a_IsReadOnly.Set( readOnly ); container->AddChild(choice); } else { if ( field->m_DataClass == Reflect::GetClass<BoolData>() ) { CheckBoxPtr checkBox = CreateControl<CheckBox>(); checkBox->a_IsReadOnly.Set( readOnly ); checkBox->a_HelpText.Set( field->GetProperty( TXT( "HelpText" ) ) ); container->AddChild( checkBox ); } else { ValuePtr value = CreateControl<Value>(); value->a_IsReadOnly.Set( readOnly ); value->a_HelpText.Set( field->GetProperty( TXT( "HelpText" ) ) ); container->AddChild( value ); } } } // // Setup label // LabelPtr label = NULL; { V_Control::const_iterator itr = container->GetChildren().begin(); V_Control::const_iterator end = container->GetChildren().end(); for( ; itr != end; ++itr ) { Label* label = Reflect::SafeCast<Label>( *itr ); if (label) { break; } } } if (!label.ReferencesObject()) { label = CreateControl<Label>(); tstring temp; field->GetProperty( TXT( "UIName" ), temp ); if ( temp.empty() ) { bool converted = Helium::ConvertString( field->m_Name, temp ); HELIUM_ASSERT( converted ); } label->BindText( temp ); label->a_HelpText.Set( field->GetProperty( TXT( "HelpText" ) ) ); container->InsertChild(0, label); } // // Bind data // std::vector<Data*> ser; { std::vector<Reflect::Object*>::const_iterator itr = instances.begin(); std::vector<Reflect::Object*>::const_iterator end = instances.end(); for ( ; itr != end; ++itr ) { DataPtr s = field->CreateData(); if (!s->IsClass(Reflect::GetClass<ContainerData>())) { s->ConnectField(*itr, field); ser.push_back(s); m_Datas.push_back(s); } } } Helium::SmartPtr< MultiStringFormatter<Data> > data = new MultiStringFormatter<Data>( ser ); container->Bind( data ); // // Set default // DataPtr defaultData = field->CreateDefaultData(); if (defaultData.ReferencesObject()) { tstringstream defaultStream; *defaultData >> defaultStream; container->a_Default.Set( defaultStream.str() ); }
void ReflectStlVectorInterpreter::InterpretField(const Field* field, const std::vector<Reflect::Object*>& instances, Container* parent) { if (field->m_Flags & FieldFlags::Hide) { return; } // create the label ContainerPtr labelContainer = CreateControl<Container>(); parent->AddChild( labelContainer ); LabelPtr label = CreateControl< Label >(); label->a_HelpText.Set( field->GetProperty( TXT( "HelpText" ) ) ); labelContainer->AddChild( label ); tstring temp; field->GetProperty( TXT( "UIName" ), temp ); if ( temp.empty() ) { bool converted = Helium::ConvertString( field->m_Name, temp ); HELIUM_ASSERT( converted ); } label->BindText( temp ); // create the list view ContainerPtr listContainer = CreateControl<Container>(); parent->AddChild( listContainer ); ListPtr list = CreateControl<List>(); list->a_HelpText.Set( field->GetProperty( TXT( "HelpText" ) ) ); listContainer->AddChild( list ); // create the buttons ButtonPtr addButton; ButtonPtr removeButton; ButtonPtr upButton; ButtonPtr downButton; if ( !(field->m_Flags & FieldFlags::ReadOnly) ) { addButton = AddAddButton( list ); removeButton = AddRemoveButton( list ); upButton = AddMoveUpButton( list ); downButton = AddMoveDownButton( list ); } // add the buttons to the container ContainerPtr buttonContainer = CreateControl<Container>(); parent->AddChild( buttonContainer ); if ( addButton ) { buttonContainer->AddChild( addButton ); } if ( removeButton ) { buttonContainer->AddChild( removeButton ); } if ( upButton ) { buttonContainer->AddChild( upButton ); } if ( downButton ) { buttonContainer->AddChild( downButton ); } // create the data objects std::vector<Reflect::Object*>::const_iterator itr = instances.begin(); std::vector<Reflect::Object*>::const_iterator end = instances.end(); for ( ; itr != end; ++itr ) { DataPtr s = field->CreateData(); OnCreateFieldData( s ); s->ConnectField(*itr, field); m_Datas.push_back(s); } // bind the ui to the data objects Helium::SmartPtr< MultiStringFormatter<Data> > data = new MultiStringFormatter<Reflect::Data>( (std::vector<Reflect::Data*>&)m_Datas ); list->Bind( data ); // setup the default value DataPtr defaultData = field->CreateDefaultData(); if (defaultData) { tstringstream defaultStream; *defaultData >> defaultStream; list->a_Default.Set( defaultStream.str() ); } }
void ReflectInterpreter::InterpretFilePathField( const std::vector< Reflect::Pointer >& pointers, Reflect::Translator* translator, const Reflect::Field* field, Container* parent ) { #if INSPECT_REFACTOR if (field->m_Flags & FieldFlags::Hide) { return; } // // Create the ui we are generating // std::vector< ContainerPtr > groups; ContainerPtr container = CreateControl<Container>(); groups.push_back( container ); bool pathField = field->m_DataClass == Reflect::GetMetaClass< PathData >(); bool readOnly = ( field->m_Flags & FieldFlags::ReadOnly ) == FieldFlags::ReadOnly; DataChangingSignature::Delegate changingDelegate; FileDialogButtonPtr fileDialogButton; // // Parse // std::string fieldUI; field->GetProperty( TXT( "UIScript" ), fieldUI ); bool result = Script::Parse(fieldUI, this, parent->GetCanvas(), container, field->m_Flags); if (!result) { if ( pathField || field->m_DataClass == Reflect::GetMetaClass<StlStringData>() ) { ContainerPtr valueContainer = CreateControl<Container>(); ValuePtr value = CreateControl< Value >(); value->a_Justification.Set( Justifications::Right ); value->a_IsReadOnly.Set( readOnly ); value->a_HelpText.Set( field->GetProperty( TXT( "HelpText" ) ) ); valueContainer->AddChild( value ); groups.push_back( valueContainer ); if ( !readOnly ) { changingDelegate = DataChangingSignature::Delegate(this, &PathInterpreter::DataChanging); // File dialog button fileDialogButton = CreateControl< FileDialogButton >(); fileDialogButton->a_HelpText.Set( TXT( "Open a file dialog to choose a new file." ) ); field->GetProperty( TXT( "FileFilter" ), m_FileFilter ); if ( !m_FileFilter.empty() ) { fileDialogButton->a_Filter.Set( m_FileFilter ); } container->AddChild( fileDialogButton ); value->SetProperty( TXT( "FileFilter" ), m_FileFilter ); } if ( objects.size() == 1 ) { // File edit button ButtonPtr editButton = CreateControl< Button >(); editButton->ButtonClickedEvent().Add( ButtonClickedSignature::Delegate ( this, &PathInterpreter::Edit ) ); editButton->a_Label.Set( TXT( "Edit" ) ); editButton->a_HelpText.Set( TXT( "Attempt to edit the file using its associated default application." ) ); container->AddChild( editButton ); } } } else { ValuePtr value = CreateControl< Value >(); value->a_IsReadOnly.Set( readOnly ); value->a_HelpText.Set( field->GetProperty( TXT( "HelpText" ) ) ); container->AddChild( value ); } // // Setup label // LabelPtr label = NULL; { std::vector< ControlPtr >::const_iterator itr = container->GetChildren().begin(); std::vector< ControlPtr >::const_iterator end = container->GetChildren().end(); for( ; itr != end; ++itr ) { Label* label = Reflect::SafeCast<Label>( *itr ); if (label) { break; } } } if (!label.ReferencesObject()) { label = CreateControl< Label >(); std::string temp; field->GetProperty( TXT( "UIName" ), temp ); if ( temp.empty() ) { bool converted = Helium::ConvertString( field->m_Name, temp ); HELIUM_ASSERT( converted ); } label->BindText( temp ); label->a_HelpText.Set( field->GetProperty( TXT( "HelpText" ) ) ); container->InsertChild(0, label); } // // Create type m_FinderSpecific data bound to this and additional objects // std::vector<Data*> datas; { std::vector<Reflect::Object*>::const_iterator itr = objects.begin(); std::vector<Reflect::Object*>::const_iterator end = objects.end(); for ( ; itr != end; ++itr ) { Data s = field->CreateData(); if (s->IsA(Reflect::GetMetaClass<ContainerData>())) { return; } s->ConnectField(*itr, field); datas.push_back(s); m_Datas.push_back(s); } } // // Create data and bind // Helium::SmartPtr< MultiStringFormatter<Data> > data = new MultiStringFormatter<Data>( datas ); if (changingDelegate.Valid()) { data->AddChangingListener( changingDelegate ); } { std::vector<ContainerPtr>::const_iterator itr = groups.begin(); std::vector<ContainerPtr>::const_iterator end = groups.end(); for ( ; itr != end; ++itr ) { (*itr)->Bind( data ); } } // // Set default // Data defaultData = field->CreateDefaultData(); if (defaultData.ReferencesObject()) { std::stringstream defaultStream; *defaultData >> defaultStream; container->a_Default.Set( defaultStream.str() ); }
void ReflectInterpreter::InterpretColorField( const std::vector< Reflect::Pointer >& pointers, Reflect::Translator* translator, const Reflect::Field* field, Container* parent ) { #if INSPECT_REFACTOR ContainerPtr container = CreateControl< Container >(); parent->AddChild( container ); LabelPtr label = CreateControl< Label >(); std::string temp; field->GetProperty( TXT( "UIName" ), temp ); if ( temp.empty() ) { bool converted = Helium::ConvertString( field->m_Name, temp ); HELIUM_ASSERT( converted ); } label->BindText( temp ); label->a_HelpText.Set( field->GetProperty( TXT( "HelpText" ) ) ); container->AddChild( label ); bool color3 = field->m_ValueType == Reflect::GetMetaStruct<Color3>() || field->m_ValueType == Reflect::GetMetaStruct<HDRColor3>(); bool color4 = field->m_ValueType == Reflect::GetMetaStruct<Color4>() || field->m_ValueType == Reflect::GetMetaStruct<HDRColor4>(); HELIUM_ASSERT( !(color3 && color4) ); // we shouldn't ever have both! if ( color3 || color4 ) { std::vector<Data*> datas; std::vector<Reflect::Object*>::const_iterator itr = objects.begin(); std::vector<Reflect::Object*>::const_iterator end = objects.end(); for ( ; itr != end; ++itr ) { Data s; if ( color3 ) { s = new Color3Data(); } if ( color4 ) { s = new Color4Data(); } if (s.ReferencesObject()) { s->ConnectField( *itr, field ); datas.push_back( s ); m_Datas.push_back( s ); } } if ( !m_Datas.empty() ) { ColorPickerPtr colorPicker = CreateControl<ColorPicker>(); container->AddChild( colorPicker ); colorPicker->a_HelpText.Set( field->GetProperty( TXT( "HelpText" ) ) ); bool readOnly = ( field->m_Flags & FieldFlags::ReadOnly ) == FieldFlags::ReadOnly; colorPicker->a_IsReadOnly.Set( readOnly ); DataBindingPtr data = new MultiStringFormatter<Data>( datas ); colorPicker->Bind( data ); if ( color3 ) { colorPicker->a_Alpha.Set( false ); } if ( color4 ) { colorPicker->a_Alpha.Set( true ); SliderPtr slider = CreateControl<Slider>(); container->AddChild( slider ); slider->a_Min.Set( 0.0 ); slider->a_Max.Set( 255.0f ); slider->a_IsReadOnly.Set( readOnly ); slider->a_HelpText.Set( TXT( "Sets the alpha value for the color." ) ); ValuePtr value = CreateControl<Value>(); container->AddChild( value ); value->a_IsReadOnly.Set( readOnly ); value->a_HelpText.Set( TXT( "Sets the alpha value for the color." ) ); std::vector<Data*> alphaSer; std::vector<Reflect::Object*>::const_iterator itr = objects.begin(); std::vector<Reflect::Object*>::const_iterator end = objects.end(); for ( ; itr != end; ++itr ) { Data s = new UInt8Data (); uintptr_t fieldAddress = (uintptr_t)(*itr) + field->m_Offset; Color4* col = (Color4*)fieldAddress; intptr_t offsetInField = (intptr_t)( &col->a ) - fieldAddress; s->ConnectField( *itr, field, offsetInField ); alphaSer.push_back( s ); m_Datas.push_back( s ); } data = new MultiStringFormatter<Data>( alphaSer ); slider->Bind( data ); value->Bind( data ); } if ( field->m_DataClass == Reflect::GetMetaClass<HDRColor3Data>() || field->m_DataClass == Reflect::GetMetaClass<HDRColor4Data>() ) { SliderPtr slider = CreateControl<Slider>(); container->AddChild( slider ); slider->a_Min.Set( 0.0 ); slider->a_Max.Set( 8.0 ); slider->a_IsReadOnly.Set( readOnly ); slider->a_HelpText.Set( TXT( "Adjusts the HDR value of the color." ) ); ValuePtr value = CreateControl<Value>(); container->AddChild( value ); value->a_IsReadOnly.Set( readOnly ); value->a_HelpText.Set( TXT( "Adjusts the HDR value of the color." ) ); std::vector<Data*> intensitySer; std::vector<Reflect::Object*>::const_iterator itr = objects.begin(); std::vector<Reflect::Object*>::const_iterator end = objects.end(); for ( ; itr != end; ++itr ) { Data s = new Float32Data(); uintptr_t fieldAddress = (uintptr_t)(*itr) + field->m_Offset; if ( color3 ) { HDRColor3* col = (HDRColor3*)fieldAddress; intptr_t offsetInField = (intptr_t)( &col->s ) - fieldAddress; s->ConnectField( *itr, field, offsetInField ); } if ( color4 ) { HDRColor4* col = (HDRColor4*)fieldAddress; intptr_t offsetInField = (intptr_t)( &col->s ) - fieldAddress; s->ConnectField( *itr, field, offsetInField ); } intensitySer.push_back( s ); m_Datas.push_back( s ); } data = new MultiStringFormatter<Data>( intensitySer ); slider->Bind( data ); value->Bind( data ); } } } #endif }
void ReflectInterpreter::InterpretBitfieldField( const std::vector< Reflect::Pointer >& pointers, Reflect::Translator* translator, const Reflect::Field* field, Container* parent ) { bool isEnumeration = field->m_Translator->IsA( Reflect::MetaIds::EnumerationTranslator ); // If you hit this, you are misusing this interpreter HELIUM_ASSERT( isEnumeration ); if ( !isEnumeration ) { return; } if ( field->m_Flags & FieldFlags::Hide ) { return; } // create the container ContainerPtr container = CreateControl<Container>(); std::string temp; field->GetProperty( TXT( "UIName" ), temp ); if ( temp.empty() ) { bool converted = Helium::ConvertString( field->m_Name, temp ); HELIUM_ASSERT( converted ); } container->a_Name.Set( temp ); parent->AddChild(container); // create the data objects std::vector<Data*> datas; for ( std::vector< Reflect::Pointer >::const_iterator itr = pointers.begin(), end = pointers.end(); itr != end; ++itr ) { datas.push_back( new Data ( *itr, translator ) ); } String defaultStr; Pointer defaultPtr ( field, field->m_Structure->m_Default, NULL ); ScalarTranslator* scalar = Reflect::ReflectionCast< ScalarTranslator >( field->m_Translator ); if ( scalar ) { scalar->Print( defaultPtr, defaultStr ); } const Reflect::MetaEnum* enumeration = Reflect::ReflectionCast< MetaEnum >( field->m_ValueType ); // build the child gui elements bool readOnly = ( field->m_Flags & FieldFlags::ReadOnly ) == FieldFlags::ReadOnly; DynamicArray< Reflect::MetaEnum::Element >::ConstIterator enumItr = enumeration->m_Elements.Begin(); DynamicArray< Reflect::MetaEnum::Element >::ConstIterator enumEnd = enumeration->m_Elements.End(); for ( ; enumItr != enumEnd; ++enumItr ) { ContainerPtr row = CreateControl< Container >(); container->AddChild( row ); LabelPtr label = CreateControl< Label >(); label->a_HelpText.Set( enumItr->m_HelpText ); label->BindText( enumItr->m_Name ); row->AddChild( label ); CheckBoxPtr checkbox = CreateControl< CheckBox >(); checkbox->a_IsReadOnly.Set( readOnly ); checkbox->a_HelpText.Set( enumItr->m_HelpText ); // TODO: Compute correct default value checkbox->a_Default.Set( defaultStr.GetData() ); checkbox->Bind( new MultiBitfieldStringFormatter ( &*enumItr, datas ) ); row->AddChild( checkbox ); } }
void ReflectInterpreter::InterpretValueField( const std::vector< Reflect::Pointer >& pointers, Reflect::Translator* translator, const Field* field, Container* parent ) { if (field->m_Flags & FieldFlags::Hide) { return; } // // Create the ui we are generating // ContainerPtr container = CreateControl<Container>(); bool readOnly = ( field->m_Flags & FieldFlags::ReadOnly ) == FieldFlags::ReadOnly; if ( field->m_ValueType && field->m_ValueType->IsA( MetaIds::MetaEnum ) ) { const Reflect::MetaEnum* enumeration = Reflect::ReflectionCast< MetaEnum >( field->m_ValueType ); ChoicePtr choice = CreateControl<Choice>(); std::vector< ChoiceItem > items; items.resize( enumeration->m_Elements.GetSize() ); DynamicArray< MetaEnum::Element >::ConstIterator itr = enumeration->m_Elements.Begin(); DynamicArray< MetaEnum::Element >::ConstIterator end = enumeration->m_Elements.End(); for ( size_t index=0; itr != end; ++itr, ++index ) { ChoiceItem& item = items[index]; item.m_Key = itr->m_Name; item.m_Data = itr->m_Name; } choice->a_HelpText.Set( field->GetProperty( TXT( "HelpText" ) ) ); choice->a_Items.Set( items ); choice->a_IsDropDown.Set( true ); choice->a_IsReadOnly.Set( readOnly ); container->AddChild(choice); } else { ScalarTranslator* scalar = ReflectionCast< ScalarTranslator >( field->m_Translator ); if ( scalar && scalar->m_Type == ScalarTypes::Boolean ) { CheckBoxPtr checkBox = CreateControl<CheckBox>(); checkBox->a_IsReadOnly.Set( readOnly ); checkBox->a_HelpText.Set( field->GetProperty( TXT( "HelpText" ) ) ); container->AddChild( checkBox ); } else { ValuePtr value = CreateControl<Value>(); value->a_IsReadOnly.Set( readOnly ); value->a_HelpText.Set( field->GetProperty( TXT( "HelpText" ) ) ); container->AddChild( value ); } } // // Setup label // LabelPtr label = NULL; { std::vector< ControlPtr >::const_iterator itr = container->GetChildren().begin(); std::vector< ControlPtr >::const_iterator end = container->GetChildren().end(); for( ; itr != end; ++itr ) { Label* label = Reflect::SafeCast<Label>( *itr ); if (label) { break; } } } if (!label.ReferencesObject()) { label = CreateControl<Label>(); std::string temp; field->GetProperty( TXT( "UIName" ), temp ); if ( temp.empty() ) { bool converted = Helium::ConvertString( field->m_Name, temp ); HELIUM_ASSERT( converted ); } label->BindText( temp ); label->a_HelpText.Set( field->GetProperty( TXT( "HelpText" ) ) ); container->InsertChild(0, label); } // // Bind data // std::vector<Data*> datas; for ( std::vector< Reflect::Pointer >::const_iterator itr = pointers.begin(), end = pointers.end(); itr != end; ++itr ) { datas.push_back( new Data ( *itr, translator ) ); } Helium::SmartPtr< MultiStringFormatter<Data> > data = new MultiStringFormatter<Data>( datas, true ); container->Bind( data ); // // Set default // String defaultStr; Pointer defaultPtr ( field, field->m_Structure->m_Default, NULL ); ScalarTranslator* scalar = Reflect::ReflectionCast< ScalarTranslator >( field->m_Translator ); if ( scalar ) { scalar->Print( defaultPtr, defaultStr ); } container->a_Default.Set( defaultStr.GetData() ); // // Close // parent->AddChild(container); }