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 ) );
    }
}
Beispiel #2
0
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
}