Ejemplo n.º 1
0
        LabelPtr Label::create(const std::string& font, const std::string& text, const Vector2& textAnchor)
        {
            LabelPtr result = std::make_shared<Label>();
            result->init(font, text, textAnchor);

            return result;
        }
Ejemplo n.º 2
0
Label* Interpreter::AddLabel(const tstring& name)
{
    LabelPtr control = new Label ();
    control->Bind( new StringFormatter<tstring>( new tstring( name ), true ) );

    m_ContainerStack.Get().top()->AddChild(control);

    return control;
}
Ejemplo n.º 3
0
PanelPtr SceneEditor::createEditorTab(SceneComponentEditorPtr Editor, IconManagerPtr TheIconManager) const
{
	//Editor Icon
	ImageComponentPtr EditorIcon = TheIconManager->createIconImageComponent(Editor->getPresentationIconName());
    if(EditorIcon == NullFC)
    {
        EditorIcon = ImageComponent::create();
    }

	beginEditCP(EditorIcon, ImageComponent::ScaleFieldMask | ImageComponent::AlignmentFieldMask);
		EditorIcon->setAlignment(Vec2f(0.5f,0.5f));
		EditorIcon->setScale(ImageComponent::SCALE_MIN_AXIS);
	endEditCP(EditorIcon, ImageComponent::ScaleFieldMask | ImageComponent::AlignmentFieldMask);
	
	//Editor Label
	LabelPtr TabLabel = Label::create();
	beginEditCP(TabLabel, Label::TextFieldMask | Label::BordersFieldMask | Label::BackgroundsFieldMask | Label::AlignmentFieldMask);
		TabLabel->setBorders(NullFC);
		TabLabel->setBackgrounds(NullFC);
		TabLabel->setText(Editor->getPresentationName());
		TabLabel->setAlignment(Vec2f(0.5f,0.5f));
	endEditCP(TabLabel, Label::TextFieldMask | Label::BordersFieldMask | Label::BackgroundsFieldMask | Label::AlignmentFieldMask);

	//Tab
	PanelPtr Tab = Panel::createEmpty();

	//Layout
	SpringLayoutPtr TabLayout = SpringLayout::create();

	//Editor Icon
    TabLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, EditorIcon, 0, SpringLayoutConstraints::WEST_EDGE, Tab);
    TabLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, EditorIcon, 0, SpringLayoutConstraints::EAST_EDGE, Tab);
	TabLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, EditorIcon, 0, SpringLayoutConstraints::NORTH_EDGE, Tab);
	TabLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, EditorIcon, -1, SpringLayoutConstraints::NORTH_EDGE, TabLabel);
	
	//Editor Label
    TabLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, TabLabel, 0, SpringLayoutConstraints::WEST_EDGE, Tab);
    TabLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, TabLabel, 0, SpringLayoutConstraints::EAST_EDGE, Tab);
	TabLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, TabLabel, 0, SpringLayoutConstraints::SOUTH_EDGE, Tab);
	TabLayout->putConstraint(SpringLayoutConstraints::HEIGHT_EDGE, TabLabel, LayoutSpring::height(TabLabel));
    
    //Tab Layout
    //TabLayout->putConstraint(SpringLayoutConstraints::WIDTH_EDGE, Tab, LayoutSpring::max(TabLayout->getConstraint(SpringLayoutConstraints::WIDTH_EDGE,TabLabel),TabLayout->getConstraint(SpringLayoutConstraints::WIDTH_EDGE,EditorIcon)));
    //TabLayout->putConstraint(SpringLayoutConstraints::HEIGHT_EDGE, Tab, LayoutSpring::sum(TabLayout->getConstraint(SpringLayoutConstraints::HEIGHT_EDGE,TabLabel),TabLayout->getConstraint(SpringLayoutConstraints::HEIGHT_EDGE,EditorIcon)));
    TabLayout->putConstraint(SpringLayoutConstraints::WIDTH_EDGE, Tab, LayoutSpring::width(Tab));
    TabLayout->putConstraint(SpringLayoutConstraints::HEIGHT_EDGE, Tab, LayoutSpring::height(Tab));

	beginEditCP(Tab, Panel::ChildrenFieldMask | Panel::LayoutFieldMask | Panel::PreferredSizeFieldMask);
		Tab->getChildren().push_back(EditorIcon);
		Tab->getChildren().push_back(TabLabel);
		Tab->setLayout(TabLayout);
		Tab->setPreferredSize(Vec2f(70.0f,50.0f));
	endEditCP(Tab, Panel::ChildrenFieldMask | Panel::LayoutFieldMask | Panel::PreferredSizeFieldMask);

	return Tab;
}
Ejemplo n.º 4
0
LabelPtr toLabel(char* key,
                 int keyLen,
                 char* value,
                 int valueLen)
{
  LabelPtr label = new Label();

  if (key != NULL)
    label->set_key(key, keyLen);

  if (value != NULL)
    label->set_value(value, valueLen);

  return label;
}
ComponentPtr DefaultDialogComponentGenerator::getQuestionComponent(DialogInterfacePtr Parent, const boost::any& Value)
{
    std::string questionString("");
    try
    {
        questionString = lexical_cast(Value);
    }
    catch (boost::bad_lexical_cast &)
    {
        std::cout<<"Unable to display question"<<std::endl;
    }

    LabelPtr TheQuestionString = Label::Ptr::dcast(getQuestionPrototype()->shallowCopy());
    beginEditCP(TheQuestionString, Label::TextFieldMask);
        TheQuestionString->setText(questionString);
    endEditCP(TheQuestionString, Label::TextFieldMask);

    return TheQuestionString;
}
/***************************************************************************\
 *                           Instance methods                              *
\***************************************************************************/
ComponentPtr DefaultCaptionComponentGenerator::getCaptionComponent(CaptionPtr Parent, const boost::any& Value)
{
    std::string CaptionSegment("");
    try
    {
        CaptionSegment = lexical_cast(Value);
    }
    catch (boost::bad_lexical_cast &)
    {
        std::cout<<"Unable to display segment"<<std::endl;
    }

    LabelPtr TheCaptionSegment = Label::Ptr::dcast(getCaptionSegmentPrototype()->shallowCopy());
    beginEditCP(TheCaptionSegment, Label::TextFieldMask);
        TheCaptionSegment->setText(CaptionSegment);
    endEditCP(TheCaptionSegment, Label::TextFieldMask);

    return TheCaptionSegment;
}
Ejemplo n.º 7
0
void fromLabel(LabelPtr l,
               char** key,
               int* keyLen,
               char** value,
               int* valueLen)
{
  if (l->has_key())
    {
      std::string* k = l->mutable_key();
      *key = (char*) k->data();
      *keyLen = k->size();
    }
  if (l->has_value())
    {
      std::string* v = l->mutable_value();
      *value = (char*) v->data();
      *valueLen = v->size();
    }

}
Ejemplo n.º 8
0
void
NepomukTrack::removeLabel( const LabelPtr &label )
{
    const NepomukLabel *nlabel = dynamic_cast<const NepomukLabel*>(label.data());

    if( !nlabel ) return;

    resource()->removeProperty( Soprano::Vocabulary::NAO::hasTag(), nlabel->tag() );

    notifyObservers();
}
Ejemplo n.º 9
0
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);
}
Ejemplo n.º 10
0
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 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 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() );
    }
}
Ejemplo n.º 13
0
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // Set up Window
    TutorialWindowEventProducer = createDefaultWindowEventProducer();
    WindowPtr MainWindow = TutorialWindowEventProducer->initWindow();

    TutorialWindowEventProducer->setDisplayCallback(display);
    TutorialWindowEventProducer->setReshapeCallback(reshape);
    
    TutorialKeyListener TheKeyListener;
    TutorialWindowEventProducer->addKeyListener(&TheKeyListener);
    TutorialUpdateListener TheTutorialUpdateListener;
    TutorialWindowEventProducer->addUpdateListener(&TheTutorialUpdateListener);

    //Create Start and stop buttons for the caption
    ButtonPtr StartButton = osg::Button::create();
    ButtonPtr StopButton = osg::Button::create();
    ButtonPtr PauseButton = osg::Button::create();

    UIFontPtr ButtonFont = osg::UIFont::create();

    beginEditCP(ButtonFont, UIFont::SizeFieldMask);
        ButtonFont->setSize(16);
    endEditCP(ButtonFont, UIFont::SizeFieldMask);
    
    beginEditCP(StartButton, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask |
        Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask | Button::AlignmentFieldMask);
            StartButton->setMinSize(Vec2f(50, 25));
            StartButton->setMaxSize(Vec2f(200, 100));
            StartButton->setPreferredSize(Vec2f(100, 50));
            StartButton->setToolTipText("This will start playing the caption!");

            StartButton->setText("START");
            StartButton->setFont(ButtonFont);
            StartButton->setTextColor(Color4f(1.0, 0.0, 0.0, 1.0));
            StartButton->setRolloverTextColor(Color4f(1.0, 0.0, 1.0, 1.0));
            StartButton->setActiveTextColor(Color4f(1.0, 0.0, 0.0, 1.0));
            StartButton->setAlignment(Vec2f(0.25,0.5));
    endEditCP(StartButton, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask |
        Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask | Button::AlignmentFieldMask);

    beginEditCP(StopButton, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask |
        Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask | Button::AlignmentFieldMask);
            StopButton->setMinSize(Vec2f(50, 25));
            StopButton->setMaxSize(Vec2f(200, 100));
            StopButton->setPreferredSize(Vec2f(100, 50));
            StopButton->setToolTipText("This will stop the caption and reset it!");

            StopButton->setText("STOP");
            StopButton->setFont(ButtonFont);
            StopButton->setTextColor(Color4f(1.0, 0.0, 0.0, 1.0));
            StopButton->setRolloverTextColor(Color4f(1.0, 0.0, 1.0, 1.0));
            StopButton->setActiveTextColor(Color4f(1.0, 0.0, 0.0, 1.0));
            StopButton->setAlignment(Vec2f(0.75,0.5));
    endEditCP(StopButton, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask |
        Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask | Button::AlignmentFieldMask);

    beginEditCP(PauseButton, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask |
        Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask | Button::AlignmentFieldMask);
            PauseButton->setMinSize(Vec2f(50, 25));
            PauseButton->setMaxSize(Vec2f(200, 100));
            PauseButton->setPreferredSize(Vec2f(100, 50));
            PauseButton->setToolTipText("This will Pause the caption!");

            PauseButton->setText("PAUSE");
            PauseButton->setFont(ButtonFont);
            PauseButton->setTextColor(Color4f(1.0, 0.0, 0.0, 1.0));
            PauseButton->setRolloverTextColor(Color4f(1.0, 0.0, 1.0, 1.0));
            PauseButton->setActiveTextColor(Color4f(1.0, 0.0, 0.0, 1.0));
            PauseButton->setAlignment(Vec2f(0.5,0.5));
    endEditCP(PauseButton, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask |
        Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask | Button::AlignmentFieldMask);


    StartButtonActionListener TheStartButtonActionListener;
    StartButton->addActionListener(&TheStartButtonActionListener);

    StopButtonActionListener TheStopButtonActionListener;
    StopButton->addActionListener(&TheStopButtonActionListener);

    PauseButtonActionListener ThePauseButtonActionListener;
    PauseButton->addActionListener(&ThePauseButtonActionListener);

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(MainWindow);
	
    // Make Torus Node (creates Torus in background of scene)
    NodePtr TorusGeometryNode = makeTorus(.5, 2, 16, 16);

    // Make Main Scene Node and add the Torus
    scene = osg::Node::create();
    beginEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask);
        scene->setCore(osg::Group::create());
        scene->addChild(TorusGeometryNode);
    endEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask);


    // Create the Graphics
    GraphicsPtr TutorialGraphics = osg::Graphics2D::create();

    // Initialize the LookAndFeelManager to enable default settings
    LookAndFeelManager::the()->getLookAndFeel()->init();

    
    LayoutPtr MainInternalWindowLayout = osg::FlowLayout::create();



    PanelPtr CaptionContainer = osg::Panel::create();

    beginEditCP(CaptionContainer, Panel::PreferredSizeFieldMask | Panel::LayoutFieldMask);
        CaptionContainer->setPreferredSize(Pnt2f(250.0,30.0));
        CaptionContainer->setLayout(MainInternalWindowLayout);
    endEditCP(CaptionContainer, Panel::PreferredSizeFieldMask | Panel::LayoutFieldMask);

    //Initialize the Sound Manager
    SoundManager::the()->attachUpdateProducer(TutorialWindowEventProducer);

    TutorialSound = SoundManager::the()->createSound();
    beginEditCP(TutorialSound, Sound::FileFieldMask | Sound::VolumeFieldMask | Sound::StreamingFieldMask | Sound::LoopingFieldMask);
        TutorialSound->setFile(Path("./Data/captionSoundFile.ogg"));
        TutorialSound->setVolume(1.0);
        TutorialSound->setStreaming(true);
        TutorialSound->setLooping(0);
    endEditCP(TutorialSound, Sound::FileFieldMask | Sound::VolumeFieldMask | Sound::StreamingFieldMask | Sound::LoopingFieldMask);

    // Create the Caption
    TutorialCaption = osg::Caption::create();

    //Add the segments of text to be displayed
    TutorialCaption->captionSegment("Listeners can be used for a variety",1.7,3.4);
    TutorialCaption->captionSegment("of different applications.",3.4,4.7);
    TutorialCaption->captionSegment("In this tutorial we will",5.0,6.35);
    TutorialCaption->captionSegment("simply be changing the background though.",6.35,8.0);
    TutorialCaption->captionSegment("First we will change the",8.8,10.2);
    TutorialCaption->captionSegment("torus on screen to a sphere.",10.2,11.75);
    TutorialCaption->captionSegment("By timing things correctly we can make",12.7,14.6);
    TutorialCaption->captionSegment("the changes right as the word is spoken.",14.6,16.75);
    TutorialCaption->captionSegment("Such as changing the sphere to a cube",17.3,20.0);
    TutorialCaption->captionSegment("but personally I would prefer",20.33,21.65);
    TutorialCaption->captionSegment("the background to be blank.",21.65,22.8);
    TutorialCaption->captionSegment("Much better!",23.8,25.0);


    //Add the tutorial Caption Listener to the Caption that was set up for the tutorial
    TutorialCaptionListener TheCaptionListener;
    TutorialCaption->addCaptionListener(&TheCaptionListener);

    //Create the Caption component Generator
    TutorialCapGen = DefaultCaptionComponentGenerator::create();

    TutorialCaption->attachWindowEventProducer(TutorialWindowEventProducer);
    beginEditCP(TutorialCaption, Caption::ParentContainerFieldMask | Caption::ComponentGeneratorFieldMask | Caption::CaptionDialogSoundFieldMask);
        TutorialCaption->setParentContainer(CaptionContainer);
        TutorialCaption->setComponentGenerator(TutorialCapGen);
        TutorialCaption->setCaptionDialogSound(TutorialSound);
    endEditCP(TutorialCaption, Caption::ParentContainerFieldMask | Caption::ComponentGeneratorFieldMask | Caption::CaptionDialogSoundFieldMask);


    //Create and modify the Label prototype that will be used for the caption
    LabelPtr LabelPrototype = Label::create();
    LabelPrototype->setAlignment(Pnt2f(0.5f,0.5f));
    LabelPrototype->setPreferredSize(Pnt2f(250.0,30.0));

    //Add the prototype to the Generator for use
    beginEditCP(TutorialCapGen, DefaultCaptionComponentGenerator::CaptionSegmentPrototypeFieldMask);
        TutorialCapGen->setCaptionSegmentPrototype(LabelPrototype);
    endEditCP(TutorialCapGen, DefaultCaptionComponentGenerator::CaptionSegmentPrototypeFieldMask);
    
    // Create The Main InternalWindow
    // Create Background to be used with the Main InternalWindow
    ColorLayerPtr MainInternalWindowBackground = osg::ColorLayer::create();
    MainInternalWindow = osg::InternalWindow::create();
    beginEditCP(MainInternalWindowBackground, ColorLayer::ColorFieldMask);
        MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5));
    endEditCP(MainInternalWindowBackground, ColorLayer::ColorFieldMask);
	beginEditCP(MainInternalWindow, InternalWindow::ChildrenFieldMask | InternalWindow::LayoutFieldMask | InternalWindow::BackgroundsFieldMask | InternalWindow::AlignmentInDrawingSurfaceFieldMask | InternalWindow::ScalingInDrawingSurfaceFieldMask | InternalWindow::DrawTitlebarFieldMask | InternalWindow::ResizableFieldMask);
       MainInternalWindow->setLayout(MainInternalWindowLayout);
       MainInternalWindow->setBackgrounds(MainInternalWindowBackground);
	   MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f));
	   MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f));
	   MainInternalWindow->setDrawTitlebar(false);
	   MainInternalWindow->setResizable(false);
	   MainInternalWindow->getChildren().push_back(CaptionContainer);
	   MainInternalWindow->getChildren().push_back(StartButton);
	   MainInternalWindow->getChildren().push_back(StopButton);
       MainInternalWindow->getChildren().push_back(PauseButton);
    endEditCP(MainInternalWindow, InternalWindow::ChildrenFieldMask | InternalWindow::LayoutFieldMask | InternalWindow::BackgroundsFieldMask | InternalWindow::AlignmentInDrawingSurfaceFieldMask | InternalWindow::ScalingInDrawingSurfaceFieldMask | InternalWindow::DrawTitlebarFieldMask | InternalWindow::ResizableFieldMask);

    // Create the Drawing Surface
    UIDrawingSurfacePtr TutorialDrawingSurface = UIDrawingSurface::create();
    beginEditCP(TutorialDrawingSurface, UIDrawingSurface::GraphicsFieldMask | UIDrawingSurface::EventProducerFieldMask);
        TutorialDrawingSurface->setGraphics(TutorialGraphics);
        TutorialDrawingSurface->setEventProducer(TutorialWindowEventProducer);
    endEditCP(TutorialDrawingSurface, UIDrawingSurface::GraphicsFieldMask | UIDrawingSurface::EventProducerFieldMask);
    
	TutorialDrawingSurface->openWindow(MainInternalWindow);
	
	// Create the UI Foreground Object
    UIForegroundPtr TutorialUIForeground = osg::UIForeground::create();

    beginEditCP(TutorialUIForeground, UIForeground::DrawingSurfaceFieldMask);
        TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface);
    endEditCP(TutorialUIForeground, UIForeground::DrawingSurfaceFieldMask);

    mgr->setRoot(scene);

    // Add the UI Foreground Object to the Scene
    ViewportPtr TutorialViewport = mgr->getWindow()->getPort(0);
    beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask);
        TutorialViewport->getForegrounds().push_back(TutorialUIForeground);
    beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask);

    // Show the whole Scene
    mgr->showAll();
    SoundManager::the()->setCamera(mgr->getCamera());


    Vec2f WinSize(TutorialWindowEventProducer->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindowEventProducer->getDesktopSize() - WinSize) *0.5);
    TutorialWindowEventProducer->openWindow(WinPos,
            WinSize,
            "05Caption");

    //Enter main Loop
    TutorialWindowEventProducer->mainLoop();


    osgExit();

    return 0;
}
Ejemplo n.º 14
0
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // Set up Window
    TutorialWindowEventProducer = createDefaultWindowEventProducer();
    WindowPtr MainWindow = TutorialWindowEventProducer->initWindow();

    TutorialWindowEventProducer->setDisplayCallback(display);
    TutorialWindowEventProducer->setReshapeCallback(reshape);

    TutorialKeyListener TheKeyListener;
    TutorialWindowEventProducer->addKeyListener(&TheKeyListener);
    TutorialUpdateListener TheTutorialUpdateListener;
    TutorialWindowEventProducer->addUpdateListener(&TheTutorialUpdateListener);


    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(MainWindow);
	
    // Make Torus Node (creates Torus in background of scene)
    NodePtr TorusGeometryNode = makeTorus(.5, 2, 16, 16);

    // Make Main Scene Node and add the Torus
    scene = osg::Node::create();
    beginEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask);
        scene->setCore(osg::Group::create());
        scene->addChild(TorusGeometryNode);
    endEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask);


    // Create the Graphics
    GraphicsPtr TutorialGraphics = osg::Graphics2D::create();

    // Initialize the LookAndFeelManager to enable default settings
    LookAndFeelManager::the()->getLookAndFeel()->init();

    DefaultDialogComponentGeneratorPtr TutorialDialogGenerator = DefaultDialogComponentGenerator::create();

    ButtonFont = osg::UIFont::create();

    beginEditCP(ButtonFont, UIFont::SizeFieldMask);
        ButtonFont->setSize(16);
    endEditCP(ButtonFont, UIFont::SizeFieldMask);

    ButtonPtr Response = osg::Button::create();
    beginEditCP(Response, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask |
        Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask );
            Response->setMinSize(Vec2f(50, 25));
            Response->setMaxSize(Vec2f(200, 100));
            Response->setPreferredSize(Vec2f(100, 50));
            Response->setToolTipText("These buttons are for selecting a response!");

            Response->setFont(ButtonFont);
            Response->setTextColor(Color4f(1.0, 0.0, 0.0, 1.0));
            Response->setRolloverTextColor(Color4f(1.0, 0.0, 1.0, 1.0));
            Response->setActiveTextColor(Color4f(1.0, 0.0, 0.0, 1.0));
    endEditCP(Response, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask |
        Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask );

    LabelPtr LabelPrototype = Label::create();
    LabelPrototype->setAlignment(Pnt2f(0.5f,0.5f));
    LabelPrototype->setPreferredSize(Pnt2f(250.0,30.0));

    DialogInterfacePtr TutorialDialogInterface = osg::DialogInterface::create();

    beginEditCP(TutorialDialogGenerator, DefaultDialogComponentGenerator::ResponseButtonPrototypeFieldMask | DefaultDialogComponentGenerator::QuestionPrototypeFieldMask);
        TutorialDialogGenerator->setResponseButtonPrototype(Response);
        TutorialDialogGenerator->setQuestionPrototype(LabelPrototype);
    endEditCP(TutorialDialogGenerator, DefaultDialogComponentGenerator::ResponseButtonPrototypeFieldMask | DefaultDialogComponentGenerator::QuestionPrototypeFieldMask);

    TutorialDialog = osg::DialogHierarchy::create();

    beginEditCP(TutorialDialog, DialogHierarchy::DualNodeStyleFieldMask);
        TutorialDialog->setDualNodeStyle(true);
    endEditCP(TutorialDialog, DialogHierarchy::DualNodeStyleFieldMask);

    DialogPtr rootDialog = TutorialDialog->addDialog("Which do you prefer?", 0.0, NullFC, true, NullFC);

    DialogPtr RootDialogChildA = TutorialDialog->addDialog("Foreground", 0.0, NullFC, false, rootDialog);
    DialogPtr RootDialogChildB = TutorialDialog->addDialog("Background", 0.0, NullFC, false, rootDialog);
    
    DialogPtr SelectableDialogChildA = TutorialDialog->addDialog("What color would you like the forground to be?", 0.0, NullFC, true, RootDialogChildA);
    DialogPtr SelectableDialogChildB = TutorialDialog->addDialog("What object do you want to be in the background?", 0.0, NullFC, true, RootDialogChildB);

    ADialogChildA = TutorialDialog->addDialog("Blue", 0.0, NullFC, false, SelectableDialogChildA);
    ADialogChildB = TutorialDialog->addDialog("Red", 0.0, NullFC, false, SelectableDialogChildA);

    BDialogChildA = TutorialDialog->addDialog("Square", 0.0, NullFC, false, SelectableDialogChildB);
    BDialogChildB = TutorialDialog->addDialog("Sphere", 0.0, NullFC, false, SelectableDialogChildB);

    DialogPtr RestartEnd1 = TutorialDialog->addDialog("What would you like to do?", 0.0, NullFC, true, ADialogChildA);
    DialogPtr RestartEnd2 = TutorialDialog->addDialog("What would you like to do?", 0.0, NullFC, true, ADialogChildB);
    DialogPtr RestartEnd3 = TutorialDialog->addDialog("What would you like to do?", 0.0, NullFC, true, BDialogChildA);
    DialogPtr RestartEnd4 = TutorialDialog->addDialog("What would you like to do?", 0.0, NullFC, true, BDialogChildB);

    Restart1 = TutorialDialog->addDialog("Restart", 0.0, NullFC, false, RestartEnd1);
    End1 = TutorialDialog->addDialog("End", 0.0, NullFC, false, RestartEnd1);
    Restart2 = TutorialDialog->addDialog("Restart", 0.0, NullFC, false, RestartEnd2);
    End2 = TutorialDialog->addDialog("End", 0.0, NullFC, false, RestartEnd2);
    Restart3 = TutorialDialog->addDialog("Restart", 0.0, NullFC, false, RestartEnd3);
    End3 = TutorialDialog->addDialog("End", 0.0, NullFC, false, RestartEnd3);
    Restart4 = TutorialDialog->addDialog("Restart", 0.0, NullFC, false, RestartEnd4);
    End4 = TutorialDialog->addDialog("End", 0.0, NullFC, false, RestartEnd4);

    TutorialDialogListener TheTutorialDialogListener;
    rootDialog->addDialogListener(&TheTutorialDialogListener);
    RootDialogChildA->addDialogListener(&TheTutorialDialogListener);
    RootDialogChildB->addDialogListener(&TheTutorialDialogListener);
    ADialogChildA->addDialogListener(&TheTutorialDialogListener);
    ADialogChildB->addDialogListener(&TheTutorialDialogListener);
    BDialogChildA->addDialogListener(&TheTutorialDialogListener);
    BDialogChildB->addDialogListener(&TheTutorialDialogListener);
    Restart1->addDialogListener(&TheTutorialDialogListener);
    End1->addDialogListener(&TheTutorialDialogListener);
    Restart2->addDialogListener(&TheTutorialDialogListener);
    End2->addDialogListener(&TheTutorialDialogListener);
    Restart3->addDialogListener(&TheTutorialDialogListener);
    End3->addDialogListener(&TheTutorialDialogListener);
    Restart4->addDialogListener(&TheTutorialDialogListener);
    End4->addDialogListener(&TheTutorialDialogListener);

    SelectableDialogChildA->addDialogListener(&TheTutorialDialogListener);
    SelectableDialogChildB->addDialogListener(&TheTutorialDialogListener);
    RestartEnd1->addDialogListener(&TheTutorialDialogListener);
    RestartEnd2->addDialogListener(&TheTutorialDialogListener);
    RestartEnd3->addDialogListener(&TheTutorialDialogListener);
    RestartEnd4->addDialogListener(&TheTutorialDialogListener);
    
    LayoutPtr MainInternalWindowLayout = osg::FlowLayout::create();
    
    // Create The Main InternalWindow
    // Create Background to be used with the Main InternalWindow
    MainInternalWindowBackground = osg::ColorLayer::create();
    MainInternalWindow = osg::InternalWindow::create();
    beginEditCP(MainInternalWindowBackground, ColorLayer::ColorFieldMask);
        MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5));
    endEditCP(MainInternalWindowBackground, ColorLayer::ColorFieldMask);
	beginEditCP(MainInternalWindow, InternalWindow::ChildrenFieldMask | InternalWindow::LayoutFieldMask | InternalWindow::BackgroundsFieldMask | InternalWindow::AlignmentInDrawingSurfaceFieldMask | InternalWindow::ScalingInDrawingSurfaceFieldMask | InternalWindow::DrawTitlebarFieldMask | InternalWindow::ResizableFieldMask);
       MainInternalWindow->setLayout(MainInternalWindowLayout);
       MainInternalWindow->setBackgrounds(MainInternalWindowBackground);
	   MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f));
	   MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f));
	   MainInternalWindow->setDrawTitlebar(false);
	   MainInternalWindow->setResizable(false);
    endEditCP(MainInternalWindow, InternalWindow::ChildrenFieldMask | InternalWindow::LayoutFieldMask | InternalWindow::BackgroundsFieldMask | InternalWindow::AlignmentInDrawingSurfaceFieldMask | InternalWindow::ScalingInDrawingSurfaceFieldMask | InternalWindow::DrawTitlebarFieldMask | InternalWindow::ResizableFieldMask);

    beginEditCP(TutorialDialogInterface, DialogInterface::ComponentGeneratorFieldMask | DialogInterface::ParentContainerFieldMask | DialogInterface::SourceDialogHierarchyFieldMask);
        TutorialDialogInterface->setComponentGenerator(TutorialDialogGenerator);
        TutorialDialogInterface->setParentContainer(MainInternalWindow);
        TutorialDialogInterface->setSourceDialogHierarchy(TutorialDialog);
    endEditCP(TutorialDialogInterface, DialogInterface::ComponentGeneratorFieldMask | DialogInterface::ParentContainerFieldMask | DialogInterface::SourceDialogHierarchyFieldMask);

    // Create the Drawing Surface
    UIDrawingSurfacePtr TutorialDrawingSurface = UIDrawingSurface::create();
    beginEditCP(TutorialDrawingSurface, UIDrawingSurface::GraphicsFieldMask | UIDrawingSurface::EventProducerFieldMask);
        TutorialDrawingSurface->setGraphics(TutorialGraphics);
        TutorialDrawingSurface->setEventProducer(TutorialWindowEventProducer);
    endEditCP(TutorialDrawingSurface, UIDrawingSurface::GraphicsFieldMask | UIDrawingSurface::EventProducerFieldMask);
    
	TutorialDrawingSurface->openWindow(MainInternalWindow);
	
	// Create the UI Foreground Object
    UIForegroundPtr TutorialUIForeground = osg::UIForeground::create();

    beginEditCP(TutorialUIForeground, UIForeground::DrawingSurfaceFieldMask);
        TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface);
    endEditCP(TutorialUIForeground, UIForeground::DrawingSurfaceFieldMask);

    mgr->setRoot(scene);

    // Add the UI Foreground Object to the Scene
    ViewportPtr TutorialViewport = mgr->getWindow()->getPort(0);
    beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask);
        TutorialViewport->getForegrounds().push_back(TutorialUIForeground);
    beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask);

    // Show the whole Scene
    mgr->showAll();
    SoundManager::the()->setCamera(mgr->getCamera());

    TutorialDialog->start();

    Vec2f WinSize(TutorialWindowEventProducer->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindowEventProducer->getDesktopSize() - WinSize) *0.5);
    TutorialWindowEventProducer->openWindow(WinPos,
            WinSize,
            "07DialogTypeTwo");

    //Enter main Loop
    TutorialWindowEventProducer->mainLoop();

    osgExit();

    return 0;
}
Ejemplo n.º 15
0
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() );
	}
Ejemplo n.º 16
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
}
Ejemplo n.º 17
0
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 );
	}
}
// Initialize OpenSG and set up the scene
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // Set up Window
    TutorialWindowEventProducer = createDefaultWindowEventProducer();
    WindowPtr MainWindow = TutorialWindowEventProducer->initWindow();

    TutorialWindowEventProducer->setDisplayCallback(display);
    TutorialWindowEventProducer->setReshapeCallback(reshape);

    //Add Window Listener
    TutorialKeyListener TheKeyListener;
    TutorialWindowEventProducer->addKeyListener(&TheKeyListener);
    TutorialMouseListener TheTutorialMouseListener;
    TutorialMouseMotionListener TheTutorialMouseMotionListener;
    TutorialWindowEventProducer->addMouseListener(&TheTutorialMouseListener);
    TutorialWindowEventProducer->addMouseMotionListener(&TheTutorialMouseMotionListener);
    TutorialUpdateListener TheTutorialUpdateListener;
    TutorialWindowEventProducer->addUpdateListener(&TheTutorialUpdateListener);

    
    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(MainWindow);
    

    //Print key command info
    std::cout << "\n\nKEY COMMANDS:" << std::endl;
    std::cout << "space   Play/Pause the animation" << std::endl;
    std::cout << "B       Show/Hide the bind pose skeleton" << std::endl;
    std::cout << "SHIFT-B Show/Hide the bind pose mesh" << std::endl;
    std::cout << "P       Show/Hide the current pose skeleton" << std::endl;
    std::cout << "SHIFT-P Show/Hide the current pose mesh" << std::endl;
    std::cout << "O       Toggle override status of TheSecondAnimation" << std::endl;
    std::cout << "CTRL-Q  Exit\n\n" << std::endl;


    
    //Import scene from XML
    ChunkMaterialPtr ExampleMaterial;
    std::vector<SkeletonPtr> SkeletonPtrs;
    std::vector<SkeletonBlendedGeometryPtr> SkeletonBlendedGeometryPtrs;
    std::vector<GeometryPtr> GeometryPtrs;

    //Skeleton materaial
    LineChunkPtr SkelLineChunk = LineChunk::create();
    beginEditCP(SkelLineChunk);
        SkelLineChunk->setWidth(0.0f);
        SkelLineChunk->setSmooth(true);
    endEditCP(SkelLineChunk);

    ChunkMaterialPtr SkelMaterial = ChunkMaterial::create();
    beginEditCP(SkelMaterial, ChunkMaterial::ChunksFieldMask);
        SkelMaterial->addChunk(SkelLineChunk);
    endEditCP(SkelMaterial, ChunkMaterial::ChunksFieldMask);

    //LOAD FIRST ANIMATION
    FCFileType::FCPtrStore NewContainers;
    NewContainers = FCFileHandler::the()->read(BoostPath("./Data/23WalkingAnimation.xml"));
    FCFileType::FCPtrStore::iterator Itor;
    for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor)
    {
        if( (*Itor)->getType() == (ChunkMaterial::getClassType()))
        {
            //Set ExampleMaterial to the ChunkMaterial we just read in
            ExampleMaterial = (ChunkMaterial::Ptr::dcast(*Itor));
        }
        if( (*Itor)->getType() == (Skeleton::getClassType()))
        {
            //Add the Skeleton we just read in to SkeletonPtrs
            SkeletonPtrs.push_back(Skeleton::Ptr::dcast(*Itor));
        }
        if( (*Itor)->getType() == (SkeletonBlendedGeometry::getClassType()))
        {
            //Add the SkeletonBlendedGeometry we just read in to SkeletonBlendedGeometryPtrs
            SkeletonBlendedGeometryPtrs.push_back(SkeletonBlendedGeometry::Ptr::dcast(*Itor));
        }
        if( (*Itor)->getType().isDerivedFrom(SkeletonAnimation::getClassType()))
        {
            //Set TheWalkingAnimation to the SkeletonAnimation we just read in
            TheWalkingAnimation = (SkeletonAnimation::Ptr::dcast(*Itor));
        }
        if( (*Itor)->getType() == (Geometry::getClassType()))
        {
            //Add the Geometry we just read in to GeometryPtrs
            GeometryPtrs.push_back(Geometry::Ptr::dcast(*Itor));
        }
    }

    //LOAD SECOND ANIMATION
    NewContainers = FCFileHandler::the()->read(BoostPath("./Data/23SamAnimation.xml"));
    for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor)
    {
         //Import only the skeletonAnimation from the second XML file; we've already imported the skeleton and the geometry
        if( (*Itor)->getType().isDerivedFrom(SkeletonAnimation::getClassType()))
        {
            TheSecondAnimation = (SkeletonAnimation::Ptr::dcast(*Itor));
        }
    }

    //Blend the two animations
    TheSkeletonBlendedAnimation = SkeletonBlendedAnimation::create();
    beginEditCP(TheSkeletonBlendedAnimation);
        TheSkeletonBlendedAnimation->addAnimationBlending(TheWalkingAnimation, BlendWalking, false);
        TheSkeletonBlendedAnimation->addAnimationBlending(TheSecondAnimation, BlendTouchScreen, false);
    endEditCP(TheSkeletonBlendedAnimation);


    
    //Create unbound geometry Node (to show the mesh in its bind pose)
    for (int i(0); i < GeometryPtrs.size(); ++i)
    {
        NodePtr UnboundGeometry = Node::create();
        beginEditCP(UnboundGeometry, Node::CoreFieldMask | Node::TravMaskFieldMask);
            UnboundGeometry->setCore(GeometryPtrs[i]);
            UnboundGeometry->setTravMask(0);  //By default, we don't show the mesh in its bind pose.
        endEditCP(UnboundGeometry, Node::CoreFieldMask | Node::TravMaskFieldMask);

        UnboundGeometries.push_back(UnboundGeometry);
    }


    //Create skeleton nodes
    for (int i(0); i < SkeletonPtrs.size(); ++i)
    {
        //SkeletonDrawer
        SkeletonDrawablePtr ExampleSkeletonDrawable = osg::SkeletonDrawable::create();
        beginEditCP(ExampleSkeletonDrawable, SkeletonDrawable::SkeletonFieldMask | SkeletonDrawable::MaterialFieldMask | SkeletonDrawable::DrawPoseFieldMask | SkeletonDrawable::PoseColorFieldMask  | SkeletonDrawable::DrawBindPoseFieldMask | SkeletonDrawable::BindPoseColorFieldMask);
            ExampleSkeletonDrawable->setSkeleton(SkeletonPtrs[i]);
            ExampleSkeletonDrawable->setMaterial(SkelMaterial);
            ExampleSkeletonDrawable->setDrawPose(true);                                  //By default we draw the current skeleton
            ExampleSkeletonDrawable->setPoseColor(Color4f(1.0, 0.0, 1.0, 1.0));       //Set color of current skeleton
            ExampleSkeletonDrawable->setDrawBindPose(false);                          //By default we don't draw the bind pose skeleton
            ExampleSkeletonDrawable->setBindPoseColor(Color4f(1.0, 1.0, 0.0, 1.0));   //Set color of bind pose skeleton
        endEditCP(ExampleSkeletonDrawable, SkeletonDrawable::SkeletonFieldMask | SkeletonDrawable::MaterialFieldMask | SkeletonDrawable::DrawPoseFieldMask | SkeletonDrawable::PoseColorFieldMask  | SkeletonDrawable::DrawBindPoseFieldMask | SkeletonDrawable::BindPoseColorFieldMask);
        
        //Skeleton Node
        NodePtr SkeletonNode = osg::Node::create();
        beginEditCP(SkeletonNode, Node::CoreFieldMask);
            SkeletonNode->setCore(ExampleSkeletonDrawable);
        endEditCP(SkeletonNode, Node::CoreFieldMask);

        SkeletonNodes.push_back(SkeletonNode);
    }



    //Create skeleton blended geometry nodes
    for (int i(0); i < SkeletonBlendedGeometryPtrs.size(); ++i)
    {
        NodePtr MeshNode = osg::Node::create();
        beginEditCP(MeshNode, Node::CoreFieldMask);
            MeshNode->setCore(SkeletonBlendedGeometryPtrs[i]);
        endEditCP(MeshNode, Node::CoreFieldMask);

        MeshNodes.push_back(MeshNode);
    }



    //Setup scene
    NodePtr EmptyScene = osg::Node::create();
    beginEditCP(EmptyScene, Node::CoreFieldMask);
        EmptyScene->setCore(Group::create());
    endEditCP  (EmptyScene, Node::CoreFieldMask);

    mgr->setRoot(EmptyScene);



    //User Interface
    // Create the Graphics
    GraphicsPtr TutorialGraphics = osg::Graphics2D::create();

    // Initialize the LookAndFeelManager to enable default settings
    LookAndFeelManager::the()->getLookAndFeel()->init();

    // Create the DefaultBoundedRangeModelPtr and 
    // set its values
    DefaultBoundedRangeModelPtr UpperAnimationSliderRangeModel = DefaultBoundedRangeModel::create();
    UpperAnimationSliderRangeModel->setMinimum(0);
    UpperAnimationSliderRangeModel->setMaximum(100);
    UpperAnimationSliderRangeModel->setValue(BlendWalking * 100);
    UpperAnimationSliderRangeModel->setExtent(0);
    
    //Create the upper animation blend amount slider
    LabelPtr TempLabel;
    SliderPtr UpperAnimationSlider = Slider::create();
    beginEditCP(UpperAnimationSlider, Slider::LabelMapFieldMask | Slider::PreferredSizeFieldMask | Slider::MajorTickSpacingFieldMask | Slider::MinorTickSpacingFieldMask | Slider::SnapToTicksFieldMask | Slider::DrawLabelsFieldMask | Slider::RangeModelFieldMask);

     //Label the slider
        TempLabel = Label::Ptr::dcast(UpperAnimationSlider->getLabelPrototype()->shallowCopy());
        beginEditCP(TempLabel, Label::TextFieldMask); TempLabel->setText("0.0"); endEditCP(TempLabel, Label::TextFieldMask);
        UpperAnimationSlider->getLabelMap()[0] = TempLabel;

        TempLabel = Label::Ptr::dcast(UpperAnimationSlider->getLabelPrototype()->shallowCopy());
        beginEditCP(TempLabel, Label::TextFieldMask); TempLabel->setText("1.0"); endEditCP(TempLabel, Label::TextFieldMask);
        UpperAnimationSlider->getLabelMap()[100] = TempLabel;

        //Customize the slider
        UpperAnimationSlider->setPreferredSize(Vec2f(100, 300));
        UpperAnimationSlider->setSnapToTicks(false);
        UpperAnimationSlider->setMajorTickSpacing(10);
        UpperAnimationSlider->setMinorTickSpacing(5);
        UpperAnimationSlider->setOrientation(Slider::VERTICAL_ORIENTATION);
        UpperAnimationSlider->setInverted(true);
        UpperAnimationSlider->setDrawLabels(true);
        UpperAnimationSlider->setRangeModel(UpperAnimationSliderRangeModel);
    endEditCP(UpperAnimationSlider, Slider::LabelMapFieldMask | Slider::PreferredSizeFieldMask | Slider::MajorTickSpacingFieldMask | Slider::MinorTickSpacingFieldMask | Slider::SnapToTicksFieldMask | Slider::DrawLabelsFieldMask | Slider::RangeModelFieldMask);
    
    DefaultBoundedRangeModelPtr LowerAnimationSliderRangeModel = DefaultBoundedRangeModel::create();
    LowerAnimationSliderRangeModel->setMinimum(0);
    LowerAnimationSliderRangeModel->setMaximum(100);
    LowerAnimationSliderRangeModel->setValue(BlendTouchScreen * 100);
    LowerAnimationSliderRangeModel->setExtent(0);
    
    //Create the lower animation blend amount slider
    SliderPtr LowerAnimationSlider = Slider::create();
    beginEditCP(LowerAnimationSlider, Slider::LabelMapFieldMask | Slider::PreferredSizeFieldMask | Slider::MajorTickSpacingFieldMask | Slider::MinorTickSpacingFieldMask | Slider::SnapToTicksFieldMask | Slider::DrawLabelsFieldMask | Slider::RangeModelFieldMask);

     //Label the slider
        TempLabel = Label::Ptr::dcast(LowerAnimationSlider->getLabelPrototype()->shallowCopy());
        beginEditCP(TempLabel, Label::TextFieldMask); TempLabel->setText("0.0"); endEditCP(TempLabel, Label::TextFieldMask);
        LowerAnimationSlider->getLabelMap()[0] = TempLabel;

        TempLabel = Label::Ptr::dcast(LowerAnimationSlider->getLabelPrototype()->shallowCopy());
        beginEditCP(TempLabel, Label::TextFieldMask); TempLabel->setText("1.0"); endEditCP(TempLabel, Label::TextFieldMask);
        LowerAnimationSlider->getLabelMap()[100] = TempLabel;

        //Customize the slider
        LowerAnimationSlider->setPreferredSize(Vec2f(100, 300));
        LowerAnimationSlider->setSnapToTicks(false);
        LowerAnimationSlider->setMajorTickSpacing(10);
        LowerAnimationSlider->setMinorTickSpacing(5);
        LowerAnimationSlider->setOrientation(Slider::VERTICAL_ORIENTATION);
        LowerAnimationSlider->setInverted(true);
        LowerAnimationSlider->setDrawLabels(true);
        LowerAnimationSlider->setRangeModel(LowerAnimationSliderRangeModel);
    endEditCP(LowerAnimationSlider, Slider::LabelMapFieldMask | Slider::PreferredSizeFieldMask | Slider::MajorTickSpacingFieldMask | Slider::MinorTickSpacingFieldMask | Slider::SnapToTicksFieldMask | Slider::DrawLabelsFieldMask | Slider::RangeModelFieldMask);

    // Create Background to be used with the MainFrame
    ColorLayerPtr MainFrameBackground = osg::ColorLayer::create();
    beginEditCP(MainFrameBackground, ColorLayer::ColorFieldMask);
        MainFrameBackground->setColor(Color4f(1.0,1.0,1.0,0.5));
    endEditCP(MainFrameBackground, ColorLayer::ColorFieldMask);

    // Create The Main InternalWindow
    // Create Background to be used with the Main InternalWindow
    ColorLayerPtr MainInternalWindowBackground = osg::ColorLayer::create();
    beginEditCP(MainInternalWindowBackground, ColorLayer::ColorFieldMask);
        MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5));
    endEditCP(MainInternalWindowBackground, ColorLayer::ColorFieldMask);

    LayoutPtr MainInternalWindowLayout = osg::FlowLayout::create();

    //GL Viewport
    ComponentPtr TheGLViewport = createGLPanel();
    InternalWindowPtr MainInternalWindow = osg::InternalWindow::create();
    beginEditCP(MainInternalWindow, InternalWindow::ChildrenFieldMask | InternalWindow::LayoutFieldMask | InternalWindow::BackgroundsFieldMask | InternalWindow::AlignmentInDrawingSurfaceFieldMask | InternalWindow::ScalingInDrawingSurfaceFieldMask | InternalWindow::DrawTitlebarFieldMask | InternalWindow::ResizableFieldMask);
       MainInternalWindow->getChildren().push_back(UpperAnimationSlider);
       MainInternalWindow->getChildren().push_back(LowerAnimationSlider);
       MainInternalWindow->getChildren().push_back(TheGLViewport);
       MainInternalWindow->setLayout(MainInternalWindowLayout);
       MainInternalWindow->setBackgrounds(MainInternalWindowBackground);
       MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f));
       MainInternalWindow->setScalingInDrawingSurface(Vec2f(1.0f,1.0f));
       MainInternalWindow->setDrawTitlebar(false);
       MainInternalWindow->setResizable(false);
    endEditCP(MainInternalWindow, InternalWindow::ChildrenFieldMask | InternalWindow::LayoutFieldMask | InternalWindow::BackgroundsFieldMask | InternalWindow::AlignmentInDrawingSurfaceFieldMask | InternalWindow::ScalingInDrawingSurfaceFieldMask | InternalWindow::DrawTitlebarFieldMask | InternalWindow::ResizableFieldMask);

    // Create the Drawing Surface
    UIDrawingSurfacePtr TutorialDrawingSurface = UIDrawingSurface::create();
    beginEditCP(TutorialDrawingSurface, UIDrawingSurface::GraphicsFieldMask | UIDrawingSurface::EventProducerFieldMask);
        TutorialDrawingSurface->setGraphics(TutorialGraphics);
        TutorialDrawingSurface->setEventProducer(TutorialWindowEventProducer);
    endEditCP(TutorialDrawingSurface, UIDrawingSurface::GraphicsFieldMask | UIDrawingSurface::EventProducerFieldMask);
    
    TutorialDrawingSurface->openWindow(MainInternalWindow);

    // Create the UI Foreground Object
    UIForegroundPtr TutorialUIForeground = osg::UIForeground::create();

    beginEditCP(TutorialUIForeground, UIForeground::DrawingSurfaceFieldMask);
        TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface);
    endEditCP(TutorialUIForeground, UIForeground::DrawingSurfaceFieldMask);

    ViewportPtr TutorialViewport = mgr->getWindow()->getPort(0);
    beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask);
        TutorialViewport->getForegrounds().push_back(TutorialUIForeground);
    beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask);

    //Attach the Slider Listeners
    BlendAmountSliderChangeListener UpperAnimationSliderListener(TheSkeletonBlendedAnimation, 0, UpperAnimationSlider);
    UpperAnimationSlider->addChangeListener(&UpperAnimationSliderListener);
    
    BlendAmountSliderChangeListener LowerAnimationSliderListener(TheSkeletonBlendedAnimation, 1, LowerAnimationSlider);
    LowerAnimationSlider->addChangeListener(&LowerAnimationSliderListener);

    //Animation Advancer
    TheAnimationAdvancer = ElapsedTimeAnimationAdvancer::create();
    beginEditCP(TheAnimationAdvancer);
    ElapsedTimeAnimationAdvancer::Ptr::dcast(TheAnimationAdvancer)->setStartTime( 0.0 );


    beginEditCP(TheAnimationAdvancer);

        //Create the Documentation
        SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow);
    
    // Show the whole Scene
    mgr->showAll();
    TheAnimationAdvancer->start();

     //Show window
    Vec2f WinSize(TutorialWindowEventProducer->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindowEventProducer->getDesktopSize() - WinSize) *0.5);
    TutorialWindowEventProducer->openWindow(WinPos,
                        WinSize,
                                        "23BlendXMLAnimations");

    //Enter main Loop
    TutorialWindowEventProducer->mainLoop();

    osgExit();

    return 0;
}
Ejemplo n.º 19
0
void ReflectBitfieldInterpreter::InterpretField(const Field* field, const std::vector<Reflect::Element*>& instances, Container* parent)
{
  // If you hit this, you are misusing this interpreter
  HELIUM_ASSERT( field->m_SerializerID == Reflect::GetType<Reflect::BitfieldSerializer>() );

  if ( field->m_SerializerID != Reflect::GetType<Reflect::BitfieldSerializer>() )
  {
    return;
  }

  if ( field->m_Flags & FieldFlags::Hide )
  {
    return;
  }

  const EnumerationField* enumField = static_cast< const EnumerationField* >( field );

  // create the panel
  PanelPtr panel = m_Container->GetCanvas()->Create<Panel>(this);
  
  tstring temp;
  bool converted = Helium::ConvertString( field->m_UIName, temp );
  panel->SetText( temp );

  panel->SetExpanded( true );
  parent->AddControl(panel);

  // build the child gui elements
  bool readOnly = ( field->m_Flags & FieldFlags::ReadOnly ) == FieldFlags::ReadOnly;
  M_StrEnumerationElement::const_iterator enumItr = enumField->m_Enumeration->m_ElementsByLabel.begin();
  M_StrEnumerationElement::const_iterator enumEnd = enumField->m_Enumeration->m_ElementsByLabel.end();
  for ( ; enumItr != enumEnd; ++enumItr )
  {
    ContainerPtr row = m_Container->GetCanvas()->Create<Container>( this );
    panel->AddControl( row );

    LabelPtr label = m_Container->GetCanvas()->Create<Label>( this );
    row->AddControl( label );

    tstring temp;
    bool converted = Helium::ConvertString( enumItr->first, temp );
    HELIUM_ASSERT( converted );
    label->SetText( temp );

    BitfieldCheckBoxPtr checkbox = m_Container->GetCanvas()->Create<ReflectBitfieldCheckBox>( this );
    row->AddControl( checkbox );

    converted = Helium::ConvertString( enumItr->first, temp );
    HELIUM_ASSERT( converted );
    checkbox->SetBitfieldString( temp );
    checkbox->SetReadOnly( readOnly );
  }

  // create the serializers
  std::vector<Reflect::Element*>::const_iterator itr = instances.begin();
  std::vector<Reflect::Element*>::const_iterator end = instances.end();
  for ( ; itr != end; ++itr )
  {
    SerializerPtr s = field->CreateSerializer();
    s->ConnectField(*itr, field);
    m_Serializers.push_back(s);
  }

  // bind the ui to the serializers
  panel->Bind( new MultiStringFormatter<Serializer>( (std::vector<Reflect::Serializer*>&)m_Serializers ) );

  // setup the default value
  if (field->m_Default != NULL)
  {
    tstringstream outStream;
    *field->m_Default >> outStream;
    panel->SetDefault( outStream.str() );
  }