virtual void actionPerformed(const ActionEventUnrecPtr e)
    {
        if(e->getSource() == LoadButton)
        {
            std::cout<<"Loading a file"<<std::endl;
            std::vector<WindowEventProducer::FileDialogFilter> Filters;
            Filters.push_back(WindowEventProducer::FileDialogFilter("All","*"));
            Filters.push_back(WindowEventProducer::FileDialogFilter("Lua Files","lua"));


            std::vector<BoostPath> FilesToOpen;
            FilesToOpen = TutorialWindow->openFileDialog("Open File Window",
                          Filters,
                          BoostPath(".."),
                          false);

            /*for(std::vector<BoostPath>::iterator Itor(FilesToOpen.begin()) ; Itor != FilesToOpen.end(); ++Itor)
            {
                _ContentPanel->addTabWithText(*Itor);
            }*/


            //GetSystemTime(&now);
            //unsigned int t1 = now.wSecond * 1000 + now.wMilliseconds;

            theTextEditor->loadNewFile(FilesToOpen[0]);

            //GetSystemTime(&now);
            //unsigned int t2 = now.wSecond * 1000 + now.wMilliseconds;

            //std::cout<<"\nstart time in milliseconds:"<<t1<<std::endl;    // start time in milliseconds
            //std::cout<<"\nduration in milliseconds:"<<t2-t1<<std::endl;        // end time in milliseconds


            //if(TheDocument)
            //    ExampleTextDomArea->setDocumentModel(TheDocument);
            //else std::cout<<"Failed Loading the Document"<<std::endl;
        }
        else if(e->getSource() == SaveButton)
        {
            std::cout<<"Saving a file"<<std::endl;
            std::vector<WindowEventProducer::FileDialogFilter> Filters;
            Filters.push_back(WindowEventProducer::FileDialogFilter("All","*"));
            Filters.push_back(WindowEventProducer::FileDialogFilter("Lua Files","lua"));

            BoostPath SavePath = TutorialWindow->saveFileDialog("Save File Window",
                                 Filters,
                                 std::string("newFile.lua"),
                                 BoostPath(".."),
                                 true);
            //theTextEditor->saveFile(SavePath);
        }
    }
void setupAnimation(void)
{
    std::vector<BoostPath> _ImagePaths;
    _ImagePaths.push_back(BoostPath("./Data/Anim001.jpg"));
    _ImagePaths.push_back(BoostPath("./Data/Anim002.jpg"));
    _ImagePaths.push_back(BoostPath("./Data/Anim003.jpg"));
    _ImagePaths.push_back(BoostPath("./Data/Anim004.jpg"));
    _ImagePaths.push_back(BoostPath("./Data/Anim005.jpg"));

    //Make the textures
    for(UInt32 i(0) ; i<_ImagePaths.size(); ++i)
    {
        ImageUnrecPtr AnimFrameImage = ImageFileHandler::the()->read(_ImagePaths[i].string().c_str());
           
        _Images.push_back(AnimFrameImage);
    }
    
    TextureObjChunkUnrecPtr AnimFrameTexture = TextureObjChunk::create();
    AnimFrameTexture->setImage(_Images.front());

    //Box Material
    MaterialChunkUnrecPtr TheMaterialChunk = MaterialChunk::create();
    TheMaterialChunk->setAmbient(Color4f(0.4,0.4,0.4,1.0));
    TheMaterialChunk->setDiffuse(Color4f(0.8,0.8,0.8,1.0));
    TheMaterialChunk->setSpecular(Color4f(1.0,1.0,1.0,1.0));

    TheBoxMaterial = ChunkMaterial::create();
    TheBoxMaterial->addChunk(AnimFrameTexture);

    //Texture Keyframe Sequence
    KeyframeFCPtrSequenceUnrecPtr TextureKeyframes = KeyframeFCPtrSequenceImage::create();
    for(UInt32 i(0) ; i<_Images.size(); ++i)
    {
        TextureKeyframes->addKeyframe(_Images[i],static_cast<Real32>(i)*0.5f);
    }
    
    //Animator
    TutorialTextureAnimator = KeyframeAnimator::create();
    TutorialTextureAnimator->setKeyframeSequence(TextureKeyframes);
    
    //Animation
    TutorialTextureAnimation = FieldAnimation::create();
    TutorialTextureAnimation->setAnimator(TutorialTextureAnimator);
    TutorialTextureAnimation->setInterpolationType(Animator::STEP_INTERPOLATION);
    TutorialTextureAnimation->setCycling(-1);
    TutorialTextureAnimation->setAnimatedField(AnimFrameTexture,TextureObjChunk::ImageFieldId);

    //Animation Listener
    TutorialTextureAnimation->addAnimationListener(&TutorialTextureAnimationListener);

    TutorialTextureAnimation->attachUpdateProducer(TutorialWindow->editEventProducer());
    TutorialTextureAnimation->start();
}
void VideoFieldContainerEditor::handleLoadAction(ActionEventDetails* const details)
{
    if(_AttachedVideo != NULL)
    {
        //Stop the video
        _AttachedVideo->stop();
    }

    //Have the user select the file to import
    std::vector<WindowEventProducer::FileDialogFilter> Filters;

    Filters.push_back(WindowEventProducer::FileDialogFilter("All (*.*)","*"));

    std::vector<BoostPath> FilesToOpen;
    FilesToOpen =
        getParentWindow()->getParentDrawingSurface()->getEventProducer()->openFileDialog("Load a video file.",
                                                                          Filters,
                                                                          BoostPath("."),
                                                                          false);

    if(FilesToOpen.size() > 0)
    {
        _AttachedVideo->open(FilesToOpen[0],getParentWindow()->getParentDrawingSurface()->getEventProducer());
        if(_AttachedVideo->hasAudio())
        {
            _AttachedVideo->enableAudio();
            _AttachedVideo->setAudioVolume(0.5f);
        }
    }
    updateVideoPreviewPanel();
}
void LuaDebuggerInterface::openScriptButtonAction(void)
{
    //Get a file using the open file dialog
    std::vector<WindowEventProducer::FileDialogFilter> Filters;
    Filters.push_back(WindowEventProducer::FileDialogFilter("Lua File Type","lua"));
    Filters.push_back(WindowEventProducer::FileDialogFilter("All","*"));

    std::vector<BoostPath> FilesToOpen;
    FilesToOpen = _CodeTextArea->
        getParentWindow()->
        getParentDrawingSurface()->
        getEventProducer()->
        openFileDialog("Open Lua Script File.",
                       Filters,
                       BoostPath("Data"),
                       true);

    //Try to open the files
    for(UInt32 i = 0; i < FilesToOpen.size(); ++i)
    {
        if(boost::filesystem::exists(FilesToOpen[i]))
        {
            _CodeTextArea->loadFile(FilesToOpen[i]);
        }
    }
    clearError();
}
void SaveProjectAsCommand::execute(void)
{
	std::vector<WindowEventProducer::FileDialogFilter> KEProjectFileFilters;
	KEProjectFileFilters.push_back(WindowEventProducer::FileDialogFilter("Project File","xml"));
	KEProjectFileFilters.push_back(WindowEventProducer::FileDialogFilter("All Files","*"));


	//Project File
	BoostPath InitialProjectFilePath(MainApplication::the()->getProject()->getFilePath());
	if(!boost::filesystem::exists(InitialProjectFilePath))
	{
        const Char8* ProjectName(getName(MainApplication::the()->getProject()));
        InitialProjectFilePath = BoostPath(std::string("./") + 
                                           ( ProjectName ? ProjectName : "Project") +
                                           ".xml");
	}

	BoostPath ProjectFilePath;
    ProjectFilePath = MainApplication::the()->getMainWindow()->saveFileDialog("Save Project As ...",KEProjectFileFilters,InitialProjectFilePath.filename(),InitialProjectFilePath.parent_path(), true);

    if(!ProjectFilePath.empty())
    {
        if(ProjectFilePath.extension().empty())
        {
            ProjectFilePath = ProjectFilePath.string() + ".xml";
        }
	    MainApplication::the()->saveProject(ProjectFilePath);
	}
}
void setupAnimation(void)
{
	//Read animation data from XML file
	FCFileType::FCPtrStore NewContainers;
	NewContainers = FCFileHandler::the()->read(BoostPath("./Data/15TestAnimations.xml"));

	FCFileType::FCPtrStore::iterator Itor;
    for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor)
    {
		if( (*Itor)->getType().isDerivedFrom(Animation::getClassType()))
		{
			//Set the animation to the one we just read in
			TheAnimation = (dynamic_pointer_cast<Animation>(*Itor));
		}
		else if( (*Itor)->getType() == (SimpleMaterial::getClassType()))
		{
			//Set torus material
			TheTorusMaterial = (dynamic_pointer_cast<SimpleMaterial>(*Itor));
			
			//Attach torus material to torus geometry
				TorusGeometry->setMaterial(TheTorusMaterial);
		}
    }

    TheAnimation->attachUpdateProducer(TutorialWindow->editEventProducer());
    TheAnimation->start();
}
Exemple #7
0
BoostPath
    PassiveWindow::saveFileDialog(const std::string&,
                   const std::vector<WindowEventProducer::FileDialogFilter,
                   std::allocator<WindowEventProducer::FileDialogFilter> >&,
                   const std::string&, const BoostPath&, bool)
{
    //Do nothing
    return BoostPath();
}
Exemple #8
0
OSG_BEGIN_NAMESPACE

/********************** OS X **************************/
#ifdef __APPLE__

BoostPath getPlatformUserAppDataDir(void)
{
    return BoostPath("~/Library/Application Support");
}
void ImageFieldEditor::openCreateHandler(void)
{
    //Have the user select the file to import
    std::vector<WindowEventProducer::FileDialogFilter> Filters;

    std::list< const Char8 * > ReadableImageSuff;
    ImageFileHandler::the()->getSuffixList(ReadableImageSuff, ImageFileType::OSG_READ_SUPPORTED);
    //Determine all of the readable image filetypes
    Filters.push_back(WindowEventProducer::FileDialogFilter("All Image filetypes",""));
    std::string AllImageSuffixes;
    std::string AllImageSuffixesDesc("All Image filetypes (");
    for(std::list<const Char8*>::const_iterator SuffixItor(ReadableImageSuff.begin()) ; SuffixItor != ReadableImageSuff.end() ; ++SuffixItor)
    {
        if(ImageFileHandler::the()->getFileType(*SuffixItor))
        {
            if(!AllImageSuffixes.empty())
            {
                AllImageSuffixes += ",";
                AllImageSuffixesDesc += ", ";
            }
            AllImageSuffixes += *SuffixItor;
            AllImageSuffixesDesc = AllImageSuffixesDesc + "*." + *SuffixItor;
            Filters.push_back(WindowEventProducer::FileDialogFilter(std::string(ImageFileHandler::the()->getFileType(*SuffixItor)->getMimeType()) +  " (*." + *SuffixItor + ")",*SuffixItor));
        }
    }
    AllImageSuffixesDesc += ")";
    Filters[0] = WindowEventProducer::FileDialogFilter(AllImageSuffixesDesc,AllImageSuffixes);
    Filters.push_back(WindowEventProducer::FileDialogFilter("All (*.*)","*"));

    std::vector<BoostPath> FilesToOpen;
    FilesToOpen = getParentWindow()->getParentDrawingSurface()->getEventProducer()->openFileDialog("Import a image file.",
                                                                          Filters,
                                                                          BoostPath("."),
                                                                          false);

    ImageRefPtr NewImage = NULL;

    if(FilesToOpen.size() > 0)
    {
        //Try loading the file using the ImageFileHandler
        NewImage = ImageFileHandler::the()->read(FilesToOpen[0].string().c_str());

        if(NewImage)
        {
            FilePathAttachment::setFilePath(NewImage, FilesToOpen[0]);

            //Set the value of the field
            SetFieldValueCommandPtr SetCommand =
                SetFieldValueCommand::create(getEditingFC(),
                                             getEditingFieldId(),
                                             boost::lexical_cast<std::string>(NewImage->getId()),
                                             getEditingFieldIndex());

            getCommandManager()->executeCommand(SetCommand);
        }
    }
}
void LuaDebuggerInterface::handleSplitMenuAction(ActionEventDetails* const details)
{
    try
    {
        std::string ValueString = boost::any_cast<std::string>(_SplitButton->getSelectionValue());

        BoostPath IconPath;
        if(ValueString.compare("Horizontal") == 0)
        {
            IconPath = BoostPath(_BaseIconDir / BoostPath("view-split-left-right.png"));
            _CodeTextArea->setIsSplit(true);
            _CodeTextArea->setSplitOrientation(SplitPanel::HORIZONTAL_ORIENTATION);
        }
        else if(ValueString.compare("Vertical") == 0)
        {
            IconPath = BoostPath(_BaseIconDir / BoostPath("view-split-top-bottom.png"));
            _CodeTextArea->setIsSplit(true);
            _CodeTextArea->setSplitOrientation(SplitPanel::VERTICAL_ORIENTATION);
        }
        else
        {
            IconPath = BoostPath(_BaseIconDir / BoostPath("view-split-none.png"));
            _CodeTextArea->setIsSplit(false);
        }

        _SplitButton->setImages(IconPath.string());
    }
    catch (boost::bad_lexical_cast &)
    {
        //Could not convert to string
    }
}
BoostPath getPlatformTempDataDir(void)
{
    BoostPath Result("");

    //Carbon
    FSRef foundRef;
    OSErr err = FSFindFolder(kUserDomain, kTemporaryFolderType,
                             kDontCreateFolder, &foundRef);
    if (err == noErr)
    {
        Result = BoostPath(FSRef2String(foundRef));
    }
    return Result;
}
ComponentTransitPtr LuaDebuggerInterface::generateSplitOptionListComponent(List* const Parent,
                                                     const boost::any& Value,
                                                     UInt32 Index,
                                                     bool IsSelected,
                                                     bool HasFocus)
{
    ButtonRecPtr TheComponent = Button::create();
    TheComponent->setBackgrounds(NULL);
    TheComponent->setAlignment(Vec2f(0.0f,0.5f));

    std::string ValueString;
    try
    {
        ValueString = boost::any_cast<std::string>(Value);

        BoostPath IconPath;
        if(ValueString.compare("Horizontal") == 0)
        {
            IconPath = BoostPath(_BaseIconDir / BoostPath("view-split-left-right.png"));
        }
        else if(ValueString.compare("Vertical") == 0)
        {
            IconPath = BoostPath(_BaseIconDir / BoostPath("view-split-top-bottom.png"));
        }
        else
        {
            IconPath = BoostPath(_BaseIconDir / BoostPath("view-split-none.png"));
        }

        TheComponent->setImages(IconPath.string());
    }
    catch (boost::bad_lexical_cast &)
    {
        //Could not convert to string
    }

    TheComponent->setText(ValueString);

    if(IsSelected)
    {
        LineBorderRecPtr LabelBorder = LineBorder::create();
        LabelBorder->setWidth(1.0f);
        LabelBorder->setColor(Color4f(0.0f,0.0f,0.0f,1.0f));
        TheComponent->setBorders(LabelBorder);
    }
    else
    {
        TheComponent->setBorders(NULL);
    }

    return ComponentTransitPtr(TheComponent);
}
Exemple #13
0
void handleSaveButtonAction(ActionEventDetails* const details,
                            WindowEventProducer* const TutorialWindow,
                            TextEditor* const theTextEditor)
{
	std::vector<WindowEventProducer::FileDialogFilter> Filters;
	Filters.push_back(WindowEventProducer::FileDialogFilter("All","*"));
	Filters.push_back(WindowEventProducer::FileDialogFilter("Lua Files","lua"));

	BoostPath SavePath = TutorialWindow->saveFileDialog("Save File Window",
														Filters,
														std::string("newFile.lua"),
														BoostPath(".."),
														true);
	if(SavePath.string() != "")
    {
	    theTextEditor->saveFile(SavePath);
    }

}
Exemple #14
0
void handleLoadButtonAction(ActionEventDetails* const details,
                            WindowEventProducer* const TutorialWindow,
                            TextEditor* const theTextEditor)
{
	std::vector<WindowEventProducer::FileDialogFilter> Filters;
	Filters.push_back(WindowEventProducer::FileDialogFilter("All","*"));
	Filters.push_back(WindowEventProducer::FileDialogFilter("Lua Files","lua"));


	std::vector<BoostPath> FilesToOpen;
	FilesToOpen = TutorialWindow->openFileDialog("Open File Window",
												Filters,
												BoostPath(".."),
												false);

    if(FilesToOpen.size() > 0)
    {
	    theTextEditor->loadFile(FilesToOpen[0]);
    }
}
void LoadProjectCommand::execute(void)
{
    //Have the user select the file to import
    std::vector<WindowEventProducer::FileDialogFilter> Filters;

    Filters.push_back(WindowEventProducer::FileDialogFilter("Project Filetypes","xml"));
    Filters.push_back(WindowEventProducer::FileDialogFilter("All (*.*)","*"));

	std::vector<BoostPath> FilesToOpen;
    FilesToOpen = MainApplication::the()->getMainWindow()->openFileDialog("Open a Project.",
        Filters,
        BoostPath("."),
        false);

    if(FilesToOpen.size() > 0)
    {
        //Exit the Debugger
        //bool isInDebugger(dynamic_pointer_cast<ApplicationPlayer>(MainApplication::the()->getPlayerMode())->isDebugging());
        //if(isInDebugger)
        //{
            //dynamic_pointer_cast<ApplicationPlayer>(MainApplication::the()->getPlayerMode())->enableDebug(false);
        //}

        //ApplicationMode* InitialMode(MainApplication::the()->getCurrentMode());
        //MainApplication::the()->setCurrentMode(MainApplication::the()->getStartScreenMode());

        //Try loading the file using the XML file handler
        MainApplication::the()->loadProject(FilesToOpen[0]);

        //if(InitialMode != MainApplication::the()->getCurrentMode())
        //{
            //MainApplication::the()->setCurrentMode(InitialMode);
        //}

        //Reenter the Debugger
        //if(isInDebugger)
        //{
            //dynamic_pointer_cast<ApplicationPlayer>(MainApplication::the()->getPlayerMode())->enableDebug(true);
        //}
    }
}
void LuaDebuggerInterface::saveScriptButtonAction(void)
{
    std::vector<WindowEventProducer::FileDialogFilter> Filters;
    Filters.push_back(WindowEventProducer::FileDialogFilter("Lua File Type","lua"));
    Filters.push_back(WindowEventProducer::FileDialogFilter("All","*"));

    BoostPath SavePath = _CodeTextArea->
        getParentWindow()->
        getParentDrawingSurface()->
        getEventProducer()->
        saveFileDialog("Save Lua Script to?",
                       Filters,
                       std::string("LuaScript.lua"),
                       BoostPath("Data"),
                       true);

    //Try to write the file
    std::ofstream OutFile(SavePath.string().c_str());
    if(OutFile)
    {
        OutFile << _CodeTextArea->getText();
        OutFile.close();
    }
}
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // Set up Window
    TutorialWindow = createNativeWindow();
    TutorialWindow->initWindow();

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

    //Add Window Listener
    TutorialKeyListener TheKeyListener;
    TutorialWindow->addKeyListener(&TheKeyListener);
    TutorialMouseListener TheTutorialMouseListener;
    TutorialMouseMotionListener TheTutorialMouseMotionListener;
    TutorialWindow->addMouseListener(&TheTutorialMouseListener);
    TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

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


    //Print key command info
    std::cout << "\n\nKEY COMMANDS:" << std::endl;
    std::cout << "CTRL-Q  Exit\n\n" << std::endl;


    //SkeletonDrawer System Material
    LineChunkUnrecPtr ExampleLineChunk = LineChunk::create();
    ExampleLineChunk->setWidth(2.0f);
    ExampleLineChunk->setSmooth(true);

    BlendChunkUnrecPtr ExampleBlendChunk = BlendChunk::create();
    ExampleBlendChunk->setSrcFactor(GL_SRC_ALPHA);
    ExampleBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);

    MaterialChunkUnrecPtr ExampleMaterialChunk = MaterialChunk::create();
    ExampleMaterialChunk->setAmbient(Color4f(1.0f,1.0f,1.0f,1.0f));
    ExampleMaterialChunk->setDiffuse(Color4f(0.0f,0.0f,0.0f,1.0f));
    ExampleMaterialChunk->setSpecular(Color4f(0.0f,0.0f,0.0f,1.0f));

    ChunkMaterialUnrecPtr ExampleMaterial = ChunkMaterial::create();
    ExampleMaterial->addChunk(ExampleLineChunk);
    ExampleMaterial->addChunk(ExampleMaterialChunk);
    ExampleMaterial->addChunk(ExampleBlendChunk);

    //Joint Node Hierarchy
    NodeRecPtr ExampleJointNode;

    //Create a new skeleton
    SkeletonBlendedGeometryRecPtr ExampleSkeleton;

    //Load skeleton from an XML file
    FCFileType::FCPtrStore NewContainers;
    NewContainers = FCFileHandler::the()->read(BoostPath("./Data/14Skeleton.xml"));

    FCFileType::FCPtrStore::iterator Itor;
    for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor)
    {
        //We only want the skeleton; ignore anything else saved in the XML file
        if( (*Itor)->getType() == (SkeletonBlendedGeometry::getClassType()))
        {
            ExampleSkeleton = (dynamic_pointer_cast<SkeletonBlendedGeometry>(*Itor));
        }

        if( (*Itor)->getType() == (Node::getClassType()) && 
            (dynamic_pointer_cast<Node>(*Itor)->getParent() == NULL))
        {
            ExampleJointNode = (dynamic_pointer_cast<Node>(*Itor));
        }
    }



    //SkeletonDrawer
    SkeletonDrawableUnrecPtr ExampleSkeletonDrawable = SkeletonDrawable::create();
    ExampleSkeletonDrawable->setSkeleton(ExampleSkeleton);
    ExampleSkeletonDrawable->setMaterial(ExampleMaterial);

    //Skeleton Node 
    NodeUnrecPtr SkeletonNode = Node::create();
    SkeletonNode->setCore(ExampleSkeletonDrawable);


    // Make Main Scene Node and add the Torus
    NodeUnrecPtr scene = Node::create();
    scene->setCore(Group::create());
    scene->addChild(SkeletonNode);

    mgr->setRoot(scene);

    // Show the whole Scene
    mgr->showAll();


    //Open Window
    Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
    TutorialWindow->openWindow(WinPos,
            WinSize,
            "14SkeletonLoader");

    //Main Loop
    TutorialWindow->mainLoop();

    osgExit();

    return 0;
}
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    {
        // Set up Window
        WindowEventProducerRecPtr TutorialWindow = createNativeWindow();

        //Initialize Window
        TutorialWindow->initWindow();

        SimpleSceneManager sceneManager;
        TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
        TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));

        // Tell the Manager what to manage
        sceneManager.setWindow(TutorialWindow);

        //Attach to events
        TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager));
        TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager));
        TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
        TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));

        BoostPath FilePath("../Animation/Data/Nanobot.dae");
        if(argc >= 2)
        {
            FilePath = BoostPath(argv[1]);
            if(!boost::filesystem::exists(FilePath))
            {
                std::cerr << "Could not load file: "<< FilePath.string()
                          << ", because no such files exists."<< std::endl;
                FilePath = BoostPath("../Animation/Data/Nanobot.dae");
            }
        }

        NodeRefPtr LoadedRoot;
        std::vector<AnimationRecPtr> LoadedAnimations;

        FCFileType::FCPtrStore ObjStore;
        try
        {
            ObjStore = FCFileHandler::the()->read(FilePath);
        }
        catch(std::exception &ex)
        {
            std::cerr << "Failed to load file: " << FilePath.string() << ", error:"
                     << ex.what()                        << std::endl;
            return -1;
        }
        for(FCFileType::FCPtrStore::iterator StorItor(ObjStore.begin());
            StorItor != ObjStore.end();
            ++StorItor)
        {
            //Animations
            if((*StorItor)->getType().isDerivedFrom(Animation::getClassType()))
            {
                LoadedAnimations.push_back(dynamic_pointer_cast<Animation>(*StorItor));
                LoadedAnimations.back()->attachUpdateProducer(TutorialWindow);
                LoadedAnimations.back()->start();
            }
            //Root Node
            if((*StorItor)->getType() == Node::getClassType() &&
                    dynamic_pointer_cast<Node>(*StorItor)->getParent() == NULL)
            {
                LoadedRoot = dynamic_pointer_cast<Node>(*StorItor);
            }
        }

        if(LoadedRoot == NULL)
        {
            LoadedRoot = SceneFileHandler::the()->read(FilePath.string().c_str());
        }

        if(LoadedRoot == NULL)
        {
            LoadedRoot= makeTorus(.5, 2, 32, 32);
        }

        //Make the fog node
        PostShaderStageRecPtr PostShaderStageCore = PostShaderStage::create();
        PostShaderStageCore->clearPasses();
        PostShaderStageCore->addPass("", generateNoEffectProg());


        DirectionalLightRecPtr SceneLightCore = DirectionalLight::create();
        SceneLightCore->setAmbient(Color4f(0.2f, 0.2f, 0.2f, 1.0f));
        SceneLightCore->setDiffuse(Color4f(0.8f, 0.8f, 0.8f, 1.0f));
        SceneLightCore->setSpecular(Color4f(1.0f, 1.0f, 1.0f, 1.0f));

        NodeRefPtr SceneLight = makeNodeFor(SceneLightCore);
        SceneLight->addChild(LoadedRoot);

        NodeRefPtr PostShaderStageNode = makeNodeFor(PostShaderStageCore);
        PostShaderStageNode->addChild(SceneLight);

        //Make Main Scene Node
        NodeRefPtr scene = makeCoredNode<Group>();

        scene->addChild(PostShaderStageNode);

        // tell the manager what to manage
        sceneManager.setRoot  (scene);
        SceneLightCore->setBeacon(sceneManager.getCamera()->getBeacon());

        //Create the Documentation Foreground and add it to the viewport
        SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow);

        // show the whole scene
        sceneManager.showAll();

        sceneManager.getWindow()->getPort(0)->setTravMask(1);
        RenderOptionsRecPtr ViewportRenderOptions = RenderOptions::create();
        ViewportRenderOptions->setRenderProperties(0x0);
        ViewportRenderOptions->setRenderProperties(RenderPropertiesPool::the()->getFrom1("Default"));
        ViewportRenderOptions->setRenderProperties(0x01);

        sceneManager.getWindow()->getPort(0)->setRenderOptions(ViewportRenderOptions);

        Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
        Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
        TutorialWindow->openWindow(WinPos,
                                   WinSize,
                                   "Collada Loader");

        TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1,
                                                      TutorialWindow.get(),
                                                      PostShaderStageCore.get()));

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

    }

    osgExit();

    return 0;
}
// Initialize WIN32 & OpenSG and set up the scene
int main(int argc, char **argv)
{
    std::cout << "\n\nKEY COMMANDS:" << std::endl
              << "1-9     Play Sounds 1-9" << std::endl
              << "p       Pause Sounds" << std::endl
              << "u       Unpause Sounds" << std::endl
              << "-       Decrease Sound Group Volume" << std::endl
              << "=       Increase Sound Group Volume" << std::endl
              << "CTRL-Q  Exit\n\n" << std::endl;
    // OSG init
    osgInit(argc,argv);
    
    TheWindowEventProducer = createNativeWindow();
    TheWindowEventProducer->initWindow();
    
    TheWindowEventProducer->setDisplayCallback(display);
    TheWindowEventProducer->setReshapeCallback(reshape);

    //Attach Mouse Listener
    TutorialMouseListener TheTutorialMouseListener;
    MouseEventConnection = TheWindowEventProducer->addMouseListener(&TheTutorialMouseListener);
    //Attach Key Listener
    TutorialKeyListener TheTutorialKeyListener;
    TheWindowEventProducer->addKeyListener(&TheTutorialKeyListener);
    //Attach MouseMotion Listener
    TutorialMouseMotionListener TheTutorialMouseMotionListener;
    TheWindowEventProducer->addMouseMotionListener(&TheTutorialMouseMotionListener);
    

    // create the scene
    NodeUnrecPtr scene = makeTorus(1.0, 2.0, 16, 16);

    // create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // tell the manager what to manage
    mgr->setWindow(TheWindowEventProducer );
    mgr->setRoot  (scene);

    // show the whole scene
    mgr->showAll();

    //Load Sound Definitions
	FCFileType::FCPtrStore NewContainers;
    NewContainers = FCFileHandler::the()->read(BoostPath("Data/04SoundData.xml"));

    FCFileType::FCPtrStore::iterator Itor;
    TutorialSoundListener TheSoundListerner;
    for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor)
    {
        //Get Sounds
        if( (*Itor)->getType().isDerivedFrom(Sound::getClassType()))
        {
            Sounds.push_back(dynamic_pointer_cast<Sound>(*Itor));
            dynamic_pointer_cast<Sound>(*Itor)->addSoundListener(&TheSoundListerner);
        }
        //Get Sound Groups
        if( (*Itor)->getType().isDerivedFrom(SoundGroup::getClassType()))
        {
            SoundGroups.push_back(dynamic_pointer_cast<SoundGroup>(*Itor));
        }
    }

    //Initialize the Sound Manager
    SoundManager::the()->attachUpdateProducer(TheWindowEventProducer);
    SoundManager::the()->setCamera(mgr->getCamera());

    Vec2f WinSize(TheWindowEventProducer->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TheWindowEventProducer->getDesktopSize() - WinSize) *0.5);
    TheWindowEventProducer->openWindow(WinPos,
            WinSize,
            "04 XML Sound Loading Window");

    //Enter main loop
    TheWindowEventProducer->mainLoop();

    osgExit();
    return 0;
}
void LuaDebuggerInterface::createCodeEditor(void)
{
    //Create the Breakpoint images
    BoostPath BreakpointIconPath(_BaseIconDir / BoostPath("breakpoint.png")),
              BreakpointDisabledIconPath(_BaseIconDir / BoostPath("breakpoint-disabled.png")),
              BreakpointConditionalIconPath(_BaseIconDir / BoostPath("breakpoint-conditional.png")),
              BreakpointConditionalDisabledIconPath(_BaseIconDir / BoostPath("breakpoint-conditional-disabled.png")),
              BreakpointCountIconPath(_BaseIconDir / BoostPath("breakpoint-count.png")),
              BreakpointCountDisabledIconPath(_BaseIconDir / BoostPath("breakpoint-count-disabled.png"));
    
    //Breakpoint Button prototypes
    //Regular Breakpoint
    ButtonRecPtr BreakpointProtoButton = Button::create();
    BreakpointProtoButton->setPreferredSize(Vec2f(18.0f, 18.0f));
    BreakpointProtoButton->setImages(BreakpointIconPath.string());
    BreakpointProtoButton->setDisabledImage(BreakpointDisabledIconPath.string());
    BreakpointProtoButton->setBorders(NULL);
    BreakpointProtoButton->setBackgrounds(NULL);
    BreakpointProtoButton->setForegrounds(NULL);

    //Count Breakpoint
    ButtonRecPtr BreakpointCountProtoButton = Button::create();
    BreakpointCountProtoButton->setPreferredSize(Vec2f(18.0f, 18.0f));
    BreakpointCountProtoButton->setImages(BreakpointCountIconPath.string());
    BreakpointCountProtoButton->setDisabledImage(BreakpointCountDisabledIconPath.string());
    BreakpointCountProtoButton->setBorders(NULL);
    BreakpointCountProtoButton->setBackgrounds(NULL);
    BreakpointCountProtoButton->setForegrounds(NULL);

    //Conditional breakpoint
    ButtonRecPtr BreakpointConditionalProtoButton = Button::create();
    BreakpointConditionalProtoButton->setPreferredSize(Vec2f(18.0f, 18.0f));
    BreakpointConditionalProtoButton->setImages(BreakpointConditionalIconPath.string());
    BreakpointConditionalProtoButton->setDisabledImage(BreakpointConditionalDisabledIconPath.string());
    BreakpointConditionalProtoButton->setBorders(NULL);
    BreakpointConditionalProtoButton->setBackgrounds(NULL);
    BreakpointConditionalProtoButton->setForegrounds(NULL);

    //Create the default font
    _CodeFont = UIFont::create();
    _CodeFont->setFamily("Courier New");
    _CodeFont->setSize(21);
    _CodeFont->setGlyphPixelSize(22);
    _CodeFont->setAntiAliasing(false);

    // Create a TextArea component
    _CodeTextArea = TextEditor::create();
    _CodeTextArea->setIsSplit(false);
    _CodeTextArea->setClipboardVisible(false);
    //_CodeTextArea->getTextDomArea()->setFont(_CodeFont);
    //_CodeTextArea->setGutterWidth(50.0f);
    _CodeTextArea->setText(createDefaultCodeText());

    //_CodeTextArea->connectCaretChanged(boost::bind(&LuaDebuggerInterface::codeAreaCaretChanged,this, _1));
    //_CodeTextArea->connectMouseClicked(boost::bind(&LuaDebuggerInterface::handleCodeAreaMouseClicked,this, _1));

    _MainSplitPanel = SplitPanel::create();
    _MainSplitPanel->setMinComponent(_CodeTextArea);
    _MainSplitPanel->setMaxComponent(_InfoTabPanel);
    _MainSplitPanel->setOrientation(SplitPanel::VERTICAL_ORIENTATION);
    _MainSplitPanel->setDividerPosition(0.7);
    // location from the left/top
    _MainSplitPanel->setDividerSize(4);
    _MainSplitPanel->setMaxDividerPosition(.8);
    _MainSplitPanel->setMinDividerPosition(.2);

    //Code Area Info
    LabelRefPtr LineLabel = Label::create();
    LineLabel->setText("Line:");
    LineLabel->setPreferredSize(Vec2f(40.0f, 30.0f));
    LineLabel->setAlignment(Vec2f(1.0f, 0.5f));

    _LineValueLabel = Label::create();
    _LineValueLabel->setText("");
    _LineValueLabel->setPreferredSize(Vec2f(40.0f, 30.0f));

    LabelRefPtr ColumnLabel = Label::create();
    ColumnLabel->setText("Column:");
    ColumnLabel->setPreferredSize(Vec2f(55.0f, 30.0f));
    ColumnLabel->setAlignment(Vec2f(1.0f, 0.5f));

    _ColumnValueLabel = Label::create();
    _ColumnValueLabel->setText("");
    _ColumnValueLabel->setPreferredSize(Vec2f(40.0f, 30.0f));
    //TextArea Info Panel

    _CodeAreaInfoPanel = Panel::create();

    SpringLayoutRefPtr CodeAreaInfoLayout = SpringLayout::create();

    //ColumnValueLabel
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, _ColumnValueLabel, 0, SpringLayoutConstraints::NORTH_EDGE, _CodeAreaInfoPanel);
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, _ColumnValueLabel, 0, SpringLayoutConstraints::SOUTH_EDGE, _CodeAreaInfoPanel);
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, _ColumnValueLabel, 0, SpringLayoutConstraints::EAST_EDGE, _CodeAreaInfoPanel);

    //ColumnLabel    
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, ColumnLabel, 0, SpringLayoutConstraints::NORTH_EDGE, _CodeAreaInfoPanel);
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, ColumnLabel, 0, SpringLayoutConstraints::SOUTH_EDGE, _CodeAreaInfoPanel);
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, ColumnLabel, -1, SpringLayoutConstraints::WEST_EDGE, _ColumnValueLabel);

    //LineValueLabel    
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, _LineValueLabel, 0, SpringLayoutConstraints::NORTH_EDGE, _CodeAreaInfoPanel);
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, _LineValueLabel, 0, SpringLayoutConstraints::SOUTH_EDGE, _CodeAreaInfoPanel);
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, _LineValueLabel, -1, SpringLayoutConstraints::WEST_EDGE, ColumnLabel);

    //LineLabel    
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, LineLabel, 0, SpringLayoutConstraints::NORTH_EDGE, _CodeAreaInfoPanel);
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, LineLabel, 0, SpringLayoutConstraints::SOUTH_EDGE, _CodeAreaInfoPanel);
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, LineLabel, -1, SpringLayoutConstraints::WEST_EDGE, _LineValueLabel);

    _CodeAreaInfoPanel->setPreferredSize(Vec2f(400.0f, 22.0f));
    _CodeAreaInfoPanel->pushToChildren(LineLabel);
    _CodeAreaInfoPanel->pushToChildren(_LineValueLabel);
    _CodeAreaInfoPanel->pushToChildren(ColumnLabel);
    _CodeAreaInfoPanel->pushToChildren(_ColumnValueLabel);
    _CodeAreaInfoPanel->setBorders(NULL);
    _CodeAreaInfoPanel->setLayout(CodeAreaInfoLayout);
}
void LuaDebuggerInterface::createEditorToolbar(void)
{
    BoostPath OpenIconPath(_BaseIconDir / BoostPath("open.png"));
    ButtonRefPtr OpenButton = Button::create();
    OpenButton->setToolTipText("Open");
    OpenButton->setPreferredSize(_ToolButtonSize);
    OpenButton->setImages(OpenIconPath.string());
    setName(OpenButton,"Open Button");
    OpenButton->connectActionPerformed(boost::bind(&LuaDebuggerInterface::openScriptButtonAction,this));

    BoostPath SaveIconPath(_BaseIconDir / BoostPath("Save.png"));
    ButtonRefPtr SaveButton = Button::create();
    SaveButton->setPreferredSize(_ToolButtonSize);
    SaveButton->setToolTipText("Save");
    setName(SaveButton,"Save Button");
    SaveButton->setImages(SaveIconPath.string());
    SaveButton->connectActionPerformed(boost::bind(&LuaDebuggerInterface::saveScriptButtonAction,this));

    BoostPath ClearIconPath(_BaseIconDir / BoostPath("clear.png"));
    ButtonRefPtr ClearButton = Button::create();
    ClearButton->setPreferredSize(_ToolButtonSize);
    ClearButton->setToolTipText("Clear");
    setName(ClearButton,"Clear Button");
    ClearButton->setImages(ClearIconPath.string());
    ClearButton->connectActionPerformed(boost::bind(&LuaDebuggerInterface::clearScriptButtonAction,this));



    BoostPath SplitHorzIconPath(_BaseIconDir / BoostPath("view-split-left-right.png"));
    BoostPath SplitVertIconPath(_BaseIconDir / BoostPath("view-split-top-bottom.png"));
    BoostPath SplitNoneIconPath(_BaseIconDir / BoostPath("view-split-none.png"));

    //Split Options Component Generator
    FunctorListComponentGeneratorRecPtr SplitOptionsCompGenerator =
        FunctorListComponentGenerator::create();

    SplitOptionsCompGenerator->setGenerateFunction(boost::bind(&LuaDebuggerInterface::generateSplitOptionListComponent,
                                                               this,
                                                               _1, _2, _3, _4, _5));

    //Split Options List Model
    DefaultListModelRecPtr SplitOptionsListModel = DefaultListModel::create();
    SplitOptionsListModel->pushBack(boost::any(std::string("None")));
    SplitOptionsListModel->pushBack(boost::any(std::string("Horizontal")));
    SplitOptionsListModel->pushBack(boost::any(std::string("Vertical")));

    _SplitButton = MenuButton::create();
    _SplitButton->setToolTipText("Split Options");
    _SplitButton->setPreferredSize(_ToolButtonSize);
    _SplitButton->setImages(SplitNoneIconPath.string());
    _SplitButton->setModel(SplitOptionsListModel);
    _SplitButton->setCellGenerator(SplitOptionsCompGenerator);
    setName(_SplitButton,"Split Button");
    _SplitButton->connectMenuActionPerformed(boost::bind(&LuaDebuggerInterface::handleSplitMenuAction,
                                                         this,
                                                         _1));

    //Make the Button Panel
    FlowLayoutRefPtr ButtonPanelLayout = FlowLayout::create();
    ButtonPanelLayout->setOrientation(FlowLayout::HORIZONTAL_ORIENTATION);
    ButtonPanelLayout->setHorizontalGap(3.0f);
    ButtonPanelLayout->setMajorAxisAlignment(0.0f);
    ButtonPanelLayout->setMinorAxisAlignment(0.5);

    _EditorButtonPanel = Panel::createEmpty();
    _EditorButtonPanel->setPreferredSize(Vec2f(200.0f, 45.0f));
    _EditorButtonPanel->pushToChildren(OpenButton);
    _EditorButtonPanel->pushToChildren(SaveButton);
    _EditorButtonPanel->pushToChildren(ClearButton);
    _EditorButtonPanel->pushToChildren(_SplitButton);
    _EditorButtonPanel->setLayout(ButtonPanelLayout);
    setName(_EditorButtonPanel,"Button Panel");
}
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // Set up Window
    TutorialWindow = createNativeWindow();
    TutorialWindow->initWindow();

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

    //Add Key Listener
    TutorialKeyListener TheKeyListener;
    TutorialWindow->addKeyListener(&TheKeyListener);
    //Add Mouse Listeners
    TutorialMouseListener TheTutorialMouseListener;
    TutorialMouseMotionListener TheTutorialMouseMotionListener;
    TutorialWindow->addMouseListener(&TheTutorialMouseListener);
    TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(TutorialWindow);
    // open window

    /* Set up complete, now performing XML import */

    BoostPath ExecutableDirectory(argv[0]);
    ExecutableDirectory.remove_leaf();
    BoostPath FilePath;
    if(argc > 1)
    {
        FilePath  = BoostPath(argv[1]);
    }
    else
    {
        FilePath = BoostPath("./Data/mayaExport1.xml");
    }

    if(!boost::filesystem::exists(FilePath))
    {
        std::cerr << "Could not find file by path: " << FilePath.string() << std::endl;
        osgExit();
        return -1;
    }


    // parse XML file to get field container data
    FCFileType::FCPtrStore NewContainers;
    NewContainers = FCFileHandler::the()->read(FilePath);

    // find root node from container, attach update listeners to particle systems
    std::vector<NodeRefPtr> RootNodes;
    for(FCFileType::FCPtrStore::iterator Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor)
    {
        // get root node
        if( (*Itor)->getType() == Node::getClassType() &&
            dynamic_pointer_cast<Node>(*Itor)->getParent() == NULL)
        {
            RootNodes.push_back(dynamic_pointer_cast<Node>(*Itor));
        }
        else if( (*Itor)->getType() == ParticleSystem::getClassType()) //attach update listeners to particle systems present
        {
            ParticleSystemRefPtr ExampleParticleSystems = dynamic_pointer_cast<ParticleSystem>(*Itor);
            ExampleParticleSystems->attachUpdateListener(TutorialWindow);
        }
    }

    // get root node that was extracted from XML file
    if(RootNodes.size() > 0)
    {
        NodeRefPtr scene = RootNodes[0];

        // set root node
        mgr->setRoot(scene);

    }

    // Show the whole Scene
    mgr->showAll();
    mgr->setHeadlight(true);
    mgr->getCamera()->setFar(10000);

    // main loop
    //Open Window
    Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
    TutorialWindow->openWindow(WinPos,
                               WinSize,
                               "15FCFileTypeIO");

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


    osgExit();

    return 0;
}
void LuaDebuggerInterface::createExecutionToolbar(void)
{
    //Execute Button
    BoostPath ExecuteIconPath(_BaseIconDir / BoostPath("execute.png"));
    BoostPath ExecuteDisabledIconPath(_BaseIconDir / BoostPath("execute-disabled.png"));
    _ExecuteButton = Button::create();
    _ExecuteButton->setPreferredSize(_ToolButtonSize);
    _ExecuteButton->setImages(ExecuteIconPath.string());
    _ExecuteButton->setDisabledImage(ExecuteDisabledIconPath.string());
    _ExecuteButton->setAlignment(Vec2f(0.5f,0.5f));
    _ExecuteButton->setToolTipText("Execute");
    _ExecuteButton->connectActionPerformed(boost::bind(&LuaDebuggerInterface::executeScriptButtonAction,this));

    //Step Into Button
    BoostPath StepInIconPath(_BaseIconDir / BoostPath("basicstepinto.png"));
    BoostPath StepInDisabledIconPath(_BaseIconDir / BoostPath("basicstepinto-disabled.png"));
    _StepInButton = Button::create();
    _StepInButton->setPreferredSize(_ToolButtonSize);
    _StepInButton->setImages(StepInIconPath.string());
    _StepInButton->setDisabledImage(StepInDisabledIconPath.string());
    _StepInButton->setAlignment(Vec2f(0.5f,0.5f));
    _StepInButton->setToolTipText("Step In");

    //Step Out Button
    BoostPath StepOutIconPath(_BaseIconDir / BoostPath("basicstepout.png"));
    BoostPath StepOutDisabledIconPath(_BaseIconDir / BoostPath("basicstepout-disabled.png"));
    _StepOutButton = Button::create();
    _StepOutButton->setPreferredSize(_ToolButtonSize);
    _StepOutButton->setImages(StepOutIconPath.string());
    _StepOutButton->setDisabledImage(StepOutDisabledIconPath.string());
    _StepOutButton->setAlignment(Vec2f(0.5f,0.5f));
    _StepOutButton->setToolTipText("Step Out");

    //Step Over Button
    BoostPath StepOverIconPath(_BaseIconDir / BoostPath("basicstepover.png"));
    BoostPath StepOverDisabledIconPath(_BaseIconDir / BoostPath("basicstepover-disabled.png"));
    _StepOverButton = Button::create();
    _StepOverButton->setPreferredSize(_ToolButtonSize);
    _StepOverButton->setImages(StepOverIconPath.string());
    _StepOverButton->setDisabledImage(StepOverDisabledIconPath.string());
    _StepOverButton->setAlignment(Vec2f(0.5f,0.5f));
    _StepOverButton->setToolTipText("Step Over");

    //Stop Button
    BoostPath StopExecutionIconPath(_BaseIconDir / BoostPath("stop.png"));
    BoostPath StopExecutionDisabledIconPath(_BaseIconDir / BoostPath("stop-disabled.png"));
    _StopExecutionButton = Button::create();
    _StopExecutionButton->setPreferredSize(_ToolButtonSize);
    _StopExecutionButton->setImages(StopExecutionIconPath.string());
    _StopExecutionButton->setDisabledImage(StopExecutionDisabledIconPath.string());
    _StopExecutionButton->setAlignment(Vec2f(0.5f,0.5f));
    _StopExecutionButton->setToolTipText("Stop");

    //Code Execution Toolbar
    //Layout
    FlowLayoutRecPtr ToolbarLayout = FlowLayout::create();
    ToolbarLayout->setOrientation(FlowLayout::HORIZONTAL_ORIENTATION);
    ToolbarLayout->setHorizontalGap(3.0f);
    ToolbarLayout->setMajorAxisAlignment(0.0f);
    ToolbarLayout->setMinorAxisAlignment(0.5);

    _CodeExecutionToolbar = Panel::createEmpty();
    _CodeExecutionToolbar->setPreferredSize(Vec2f(45.0f, 45.0f));
    _CodeExecutionToolbar->setLayout(ToolbarLayout);
    _CodeExecutionToolbar->pushToChildren(_ExecuteButton);
    _CodeExecutionToolbar->pushToChildren(_StopExecutionButton);
    _CodeExecutionToolbar->pushToChildren(_StepOverButton);
    _CodeExecutionToolbar->pushToChildren(_StepInButton);
    _CodeExecutionToolbar->pushToChildren(_StepOutButton);

    updateExecutionToolbar();
}
// Initialize WIN32 & OpenSG and set up the scene
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    {
        // Set up Window
        WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
        TutorialWindow->initWindow();

        // Create the SimpleSceneManager helper
        SimpleSceneManager sceneManager;
        TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
        TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));

        // Tell the Manager what to manage
        sceneManager.setWindow(TutorialWindow);

        //Attach to events
        TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager));
        TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager));
        TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
        TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));

        //Sound Emitter Node
        SoundEmitterRecPtr TheEmitter = SoundEmitter::create();
        TheEmitter->attachUpdateProducer(TutorialWindow);

        NodeUnrecPtr TheEmitterNode = Node::create();
        TheEmitterNode->setCore(TheEmitter);

        //Sphere Transformation Node
        Matrix Translate;
        Translate.setTranslate(0.0,0.0,-5.0);
        Matrix Rotation;
        Rotation.setRotate(Quaternion(Vec3f(0.0,1.0,0.0), 0.0));

        Matrix Total(Translate);
        Total.mult(Rotation);

        TransformRecPtr TheSphereTransform = Transform::create();
        TheSphereTransform->setMatrix(Total);

        NodeUnrecPtr SphereTransformNode = Node::create();
        SphereTransformNode->setCore(TheSphereTransform);
        SphereTransformNode->addChild(makeSphere(2, 1.0));
        SphereTransformNode->addChild(TheEmitterNode);

        // create the scene
        NodeUnrecPtr scene = Node::create();
        scene->setCore(Group::create());
        scene->addChild(SphereTransformNode);

        // tell the manager what to manage
        sceneManager.setRoot  (scene);

        CameraUnrecPtr TheCamera = sceneManager.getCamera();
        TheCamera->setNear(0.1);
        TheCamera->setFar(100.0);

        //Initialize the Sound Manager
        SoundManager::the()->attachUpdateProducer(TutorialWindow);
        SoundManager::the()->setCamera(sceneManager.getCamera());

        SoundRecPtr PopSound = SoundManager::the()->createSound();
        PopSound->setFile(BoostPath("./Data/pop.wav"));
        PopSound->setVolume(1.0);
        PopSound->setStreaming(false);
        PopSound->setLooping(-1);
        PopSound->setEnable3D(true);

        PopSound->connectSoundPlayed  (boost::bind(handleSoundPlayed,   _1));
        PopSound->connectSoundStopped (boost::bind(handleSoundStopped,  _1));
        PopSound->connectSoundPaused  (boost::bind(handleSoundPaused,   _1));
        PopSound->connectSoundUnpaused(boost::bind(handleSoundUnpaused, _1));
        PopSound->connectSoundLooped  (boost::bind(handleSoundLooped,   _1));

        //Attach this sound to the emitter node
        TheEmitter->setSound(PopSound);

        TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1,
                                                    TheEmitter.get()));
        TutorialWindow->connectUpdate(boost::bind(handleUpdate, _1,
                                                  TheSphereTransform.get()));

        //Create the Documentation
        SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow);

        Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
        Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
        TutorialWindow->openWindow(WinPos,
                                   WinSize,
                                   "02 Sound3D Window");


        //Enter main loop
        TutorialWindow->mainLoop();

    }
    osgExit();
    return 0;
}
// Initialize WIN32 & OpenSG and set up the scene
int main(int argc, char **argv)
{
    std::cout << "\n\nKEY COMMANDS:" << std::endl
        << "space   Play/Pause the playing sounds" << std::endl
        << "1       Play Pop Sound" << std::endl
        << "2       Play Click Sound" << std::endl
        << "CTRL-Q  Exit\n\n" << std::endl;

    // OSG init
    osgInit(argc,argv);

    {
        // Set up Window
        WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
        TutorialWindow->initWindow();

        // Create the SimpleSceneManager helper
        SimpleSceneManager sceneManager;
        TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
        TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));

        // Tell the Manager what to manage
        sceneManager.setWindow(TutorialWindow);

        //Attach to events
        TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager));
        TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager));
        TutorialWindow->connectMouseMoved(boost::bind(mouseMoved, _1, &sceneManager));
        TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
        TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));
 
        // create the scene
        NodeUnrecPtr scene = makeTorus(1.0, 2.0, 16, 16);

        //Initialize the Sound Manager
        SoundManager::the()->attachUpdateProducer(TutorialWindow);
        SoundManager::the()->setCamera(sceneManager.getCamera());

        //Create Pop Sound
        SoundRecPtr ZapSound = SoundManager::the()->createSound();
        ZapSound->setFile(BoostPath("./Data/zap.wav"));
        ZapSound->setVolume(1.0);
        ZapSound->setStreaming(false);
        ZapSound->setLooping(1);

        //Attach Sound Events
        ZapSound->connectSoundPlayed  (boost::bind(handleSoundPlayed,   _1));
        ZapSound->connectSoundStopped (boost::bind(handleSoundStopped,  _1));
        ZapSound->connectSoundPaused  (boost::bind(handleSoundPaused,   _1));
        ZapSound->connectSoundUnpaused(boost::bind(handleSoundUnpaused, _1));
        ZapSound->connectSoundLooped  (boost::bind(handleSoundLooped,   _1));

        //Create Click Sound
        SoundRecPtr ClickSound = SoundManager::the()->createSound();
        ClickSound->setFile(BoostPath("./Data/click.wav"));
        ClickSound->setVolume(1.0);
        ClickSound->setStreaming(false);
        ClickSound->setLooping(0);

        //Attach Sound Events
        ClickSound->connectSoundPlayed  (boost::bind(handleSoundPlayed,   _1));
        ClickSound->connectSoundStopped (boost::bind(handleSoundStopped,  _1));
        ClickSound->connectSoundPaused  (boost::bind(handleSoundPaused,   _1));
        ClickSound->connectSoundUnpaused(boost::bind(handleSoundUnpaused, _1));
        ClickSound->connectSoundLooped  (boost::bind(handleSoundLooped,   _1));

        TutorialWindow->connectKeyTyped(boost::bind(&KeyTypedHandler::keyTyped,
                                                    _1,
                                                    ZapSound.get(),
                                                    ClickSound.get()));

        // tell the manager what to manage
        sceneManager.setRoot  (scene);

        // show the whole scene
        sceneManager.showAll();


        Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
        Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
        TutorialWindow->openWindow(WinPos,
                                   WinSize,
                                   "01 DefaultSound Window");

        //Enter main loop
        TutorialWindow->mainLoop();

    }
    osgExit();
    return 0;
}
// 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;
}
//-----------------------------------------------------------------------------
// open: Depending on what type of media files we want to load, we 
//                will initialize the appropriate graph.  WMV (Requires a 
//                different source filter to operate properly)
//-----------------------------------------------------------------------------
bool DirectShowVideoWrapper::open(const std::string& ThePath, Window* const window)
{
    //Check that the file exists
    if(!boost::filesystem::exists(BoostPath(ThePath)))
    {
        SWARNING << "Could not open file: " << ThePath << ", because no such file exists." << std::endl;
        return false;
    }

    // Determine the file to load based on DirectX Media path (from SDK)
    // Use a helper function included in DXUtils.cpp
    std::vector<std::string> wmv_ext;
    wmv_ext.push_back("wmv");
    wmv_ext.push_back("wma");
    wmv_ext.push_back("asf");

    std::vector<std::string> mpg_ext;
    mpg_ext.push_back("mpg");
    mpg_ext.push_back("mpeg");
    mpg_ext.push_back("m2v");

    std::vector<std::string> avchd_ext;
    avchd_ext.push_back("mts");
    avchd_ext.push_back("m2ts");

    //Get the file extension
    std::string ext;
    std::string::size_type dot_pos(ThePath.find_last_of("."));
    if(dot_pos == std::string::npos)
    {
        SWARNING << "Could not determine extension of file: " << ThePath << std::endl;
        return false;
    }
    ext = ThePath.substr(dot_pos+1);
    std::transform(ext.begin(), ext.end(), ext.begin(), (int(*)(int)) std::tolower);// explicit cast needed to resolve ambiguity

    //Determine if the file is a WMV
    bool isWMV(false);
    for(UInt32 i(0) ; i<wmv_ext.size() ; ++i)
    {
        if(ext.compare(wmv_ext[i]) == 0)
        {
            isWMV = true;
            break;
        }
    }
    //Determine if the file is a MPG
    bool isMPG(false);
    for(UInt32 i(0) ; i<mpg_ext.size() ; ++i)
    {
        if(ext.compare(mpg_ext[i]) == 0)
        {
            isMPG = true;
            break;
        }
    }
    
    //Determine if the file is a AVCHD
    bool isAVCHD(false);
    for(UInt32 i(0) ; i<avchd_ext.size() ; ++i)
    {
        if(ext.compare(avchd_ext[i]) == 0)
        {
            isAVCHD = true;
            break;
        }
    }

    HRESULT hr = S_OK;
    TCHAR szErr[MAX_ERROR_TEXT_LEN];

    // Create the filter graph
    if(_pGraphBuilder == NULL)
    {
        hr = _pGraphBuilder.CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER);
        if (FAILED(hr))
        {
            AMGetErrorText(hr, szErr, MAX_ERROR_TEXT_LEN);
            SWARNING << "Unable to Create FilterGraph object, error: " << szErr << std::endl;
            return !FAILED(hr);
        }
    }

    // Create the capture filter graph
    if(_pGraphCaptureBuilder == NULL)
    {
        hr = _pGraphCaptureBuilder.CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC_SERVER);
        if (FAILED(hr))
        {
            AMGetErrorText(hr, szErr, MAX_ERROR_TEXT_LEN);
            SWARNING << "Unable to Create CaptureFilterGraph object, error: " << szErr << std::endl;
            return !FAILED(hr);
        }
    }

    hr = _pGraphCaptureBuilder->SetFiltergraph(_pGraphBuilder);
    if (FAILED(hr))
    {
        AMGetErrorText(hr, szErr, MAX_ERROR_TEXT_LEN);
        SWARNING << "Unable to attach FilterGraph object, error: " << szErr << std::endl;
        return !FAILED(hr);
    }

    

    //Create the Source Filter
    if (isWMV) 
    {
        hr = ConnectWMVFile(ThePath);
        if (FAILED(hr))
        {
            SWARNING << "Could not connect wmv file: " << ThePath << std::endl;
            return !FAILED(hr);
        }
    }
    else if(isMPG) 
    {
        hr = ConnectMPGFile(ThePath);
        if (FAILED(hr))
        {
            SWARNING << "Could not connect mpg file: " << ThePath << std::endl;
            return !FAILED(hr);
        }
    }
    else if(isAVCHD) 
    {
        hr = ConnectAVCHDFile(ThePath);
        if (FAILED(hr))
        {
            SWARNING << "Could not connect AVCHD file: " << ThePath << std::endl;
            return !FAILED(hr);
        }
    }
    else
    {
        // This is all other standard media types that do not use the 
        // Microsoft DirectX Media Objects
        hr = ConnectAVIFile(ThePath);
        if (FAILED(hr))
        {
            SWARNING << "Could not connect avi file: " << ThePath << std::endl;
            return !FAILED(hr);
        }
    }

    // A Null Audio Renderer
    if(_pNullAudioFilter == NULL)
    {
        hr = _pNullAudioFilter.CoCreateInstance(CLSID_NullRenderer,   NULL, CLSCTX_INPROC_SERVER);
        if (FAILED(hr))
        {
            AMGetErrorText(hr, szErr, MAX_ERROR_TEXT_LEN);
            SWARNING << "Unable to create Null Audio Renderer, error: " << szErr << std::endl;
            return !FAILED(hr);
        }
    }

    //The Audio Renderer
    hr = FindAudioRenderer(_pGraphBuilder,&_pAudioRenderer);
    if (_pAudioRenderer == NULL)
    {
        SLOG << "Video has no Audio renderer." << std::endl;
    }


    if(FAILED(ConnectSampleGrabber()))
    {
       /* std::wstring WideFileName;
        WideFileName.assign(ThePath.begin(), ThePath.end());
        std::wstring WideFileNameGrf = WideFileName + L".grf";
        SaveGraphFile(_pGraphBuilder, const_cast<WCHAR*>(WideFileNameGrf.c_str()));*/
        return !FAILED(hr);
    }


	_VideoInitialized = true;

    SLOG << "Successfully created filter graph for file: " << ThePath << std::endl;
	produceOpened();

    // Register the graph in the Running Object Table (for debug purposes)
    AddGraphToROT(_pGraphBuilder, &dwROT);

    return true;
}
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // Set up Window
    TutorialWindow = createNativeWindow();
    TutorialWindow->initWindow();

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

    //Add Window Listener
    TutorialKeyListener TheKeyListener;
    TutorialWindow->addKeyListener(&TheKeyListener);
    TutorialMouseListener TheTutorialMouseListener;
    TutorialMouseMotionListener TheTutorialMouseMotionListener;
    TutorialWindow->addMouseListener(&TheTutorialMouseListener);
    TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

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


    //SkeletonDrawer System Material
    LineChunkUnrecPtr ExampleLineChunk = LineChunk::create();
    ExampleLineChunk->setWidth(2.0f);
    ExampleLineChunk->setSmooth(true);

    BlendChunkUnrecPtr ExampleBlendChunk = BlendChunk::create();
    ExampleBlendChunk->setSrcFactor(GL_SRC_ALPHA);
    ExampleBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);

    MaterialChunkUnrecPtr ExampleMaterialChunk = MaterialChunk::create();
    ExampleMaterialChunk->setAmbient(Color4f(1.0f,1.0f,1.0f,1.0f));
    ExampleMaterialChunk->setDiffuse(Color4f(0.0f,0.0f,0.0f,1.0f));
    ExampleMaterialChunk->setSpecular(Color4f(0.0f,0.0f,0.0f,1.0f));

    ChunkMaterialUnrecPtr ExampleMaterial = ChunkMaterial::create();
    ExampleMaterial->addChunk(ExampleLineChunk);


    //Read skeleton from XML file
    FCFileType::FCPtrStore NewContainers;
    NewContainers = FCFileHandler::the()->read(BoostPath("./Data/16Skeleton.xml"));

    SkeletonUnrecPtr ExampleSkeleton;

    FCFileType::FCPtrStore::iterator Itor;
    for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor)
    {
        //Only import skeleton data; we ignore anything else saved in the XML file
        if( (*Itor)->getType() == (Skeleton::getClassType()))
        {
            //Set the Skeleton to the one we just read in
            ExampleSkeleton = (dynamic_pointer_cast<Skeleton>(*Itor));
        }
    }

    //SkeletonDrawer
    SkeletonDrawableUnrecPtr ExampleSkeletonDrawable = SkeletonDrawable::create();
    ExampleSkeletonDrawable->setSkeleton(ExampleSkeleton);
    ExampleSkeletonDrawable->setMaterial(ExampleMaterial);

    //Skeleton Particle System Node
    NodeUnrecPtr SkeletonNode = Node::create();
    SkeletonNode->setCore(ExampleSkeletonDrawable);


    //Torus Node
    NodeUnrecPtr TorusNode = makeTorus(.5, 2, 32, 32);

    // Make Main Scene Node and add the Torus
    NodeUnrecPtr scene = Node::create();
    scene->setCore(Group::create());
    scene->addChild(SkeletonNode);
    //scene->addChild(TorusNode);
    scene->addChild(makeCoordAxis(10.0));

    mgr->setRoot(scene);
    mgr->turnHeadlightOff();

    // Show the whole Scene
    mgr->showAll();

    Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
    TutorialWindow->openWindow(WinPos,
            WinSize,
            "16LoadXMLSkeleton");

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

    osgExit();

    return 0;
}
// Initialize WIN32 & OpenSG and set up the scene
int main(int argc, char **argv)
{
    preloadSharedObject("OSGTBFileIO");

    // OSG init
    osgInit(argc,argv);

    {
        // Set up Window
        WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
        TutorialWindow->initWindow();

        // Create the SimpleSceneManager helper
        SimpleSceneManager sceneManager;
        TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
        TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));

        // Tell the Manager what to manage
        sceneManager.setWindow(TutorialWindow);

        //Attach to events
        TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager));
        TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager));
        TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
        TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));
        TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1));

        // create the scene
        NodeUnrecPtr scene = makeTorus(1.0, 2.0, 16, 16);
        sceneManager.setRoot  (scene);

        //Create the Documentation
        SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow);

        // show the whole scene
        sceneManager.showAll();

        //Load Sound Definitions
        FCFileType::FCPtrStore NewContainers;
        NewContainers = FCFileHandler::the()->read(BoostPath("Data/04SoundData.xml"));

        FCFileType::FCPtrStore::iterator Itor;
        for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor)
        {
            //Get Sounds
            if( (*Itor)->getType().isDerivedFrom(Sound::getClassType()))
            {
                Sounds.push_back(dynamic_pointer_cast<Sound>(*Itor));
                Sounds.back()->connectSoundPlayed  (boost::bind(handleSoundPlayed,   _1));
                Sounds.back()->connectSoundStopped (boost::bind(handleSoundStopped,  _1));
                Sounds.back()->connectSoundPaused  (boost::bind(handleSoundPaused,   _1));
                Sounds.back()->connectSoundUnpaused(boost::bind(handleSoundUnpaused, _1));
                Sounds.back()->connectSoundLooped  (boost::bind(handleSoundLooped,   _1));
            }
            //Get Sound Groups
            if( (*Itor)->getType().isDerivedFrom(SoundGroup::getClassType()))
            {
                SoundGroups.push_back(dynamic_pointer_cast<SoundGroup>(*Itor));
            }
        }

        //Initialize the Sound Manager
        SoundManager::the()->attachUpdateProducer(TutorialWindow);
        SoundManager::the()->setCamera(sceneManager.getCamera());

        Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
        Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
        TutorialWindow->openWindow(WinPos,
                                   WinSize,
                                   "04 XML Sound Loading Window");

        //Enter main loop
        TutorialWindow->mainLoop();

    }
    osgExit();
    return 0;
}
AnimationTransitPtr setupAnimation(ChunkMaterial* const TheBoxMaterial)
{
    std::vector<BoostPath> _ImagePaths;
    _ImagePaths.push_back(BoostPath("./Data/Anim001.jpg"));
    _ImagePaths.push_back(BoostPath("./Data/Anim002.jpg"));
    _ImagePaths.push_back(BoostPath("./Data/Anim003.jpg"));
    _ImagePaths.push_back(BoostPath("./Data/Anim004.jpg"));
    _ImagePaths.push_back(BoostPath("./Data/Anim005.jpg"));

    TextureSelectChunkRefPtr AnimSequenceTexture = TextureSelectChunk::create();
    AnimSequenceTexture->setChoice(0);

    //Make the textures
    for(UInt32 i(0) ; i<_ImagePaths.size(); ++i)
    {
        ImageRefPtr AnimFrameImage = ImageFileHandler::the()->read(_ImagePaths[i].string().c_str());

        TextureObjChunkRefPtr AnimFrameTexture = TextureObjChunk::create();
        AnimFrameTexture->setImage(AnimFrameImage);

        AnimSequenceTexture->pushToTextures(AnimFrameTexture);
    }

    //Box Material
    MaterialChunkUnrecPtr TheMaterialChunk = MaterialChunk::create();
    TheMaterialChunk->setAmbient(Color4f(0.4,0.4,0.4,1.0));
    TheMaterialChunk->setDiffuse(Color4f(0.8,0.8,0.8,1.0));
    TheMaterialChunk->setSpecular(Color4f(1.0,1.0,1.0,1.0));

    //Texture Env Chunk
    TextureEnvChunkRefPtr TexEnv = TextureEnvChunk::create();
    TexEnv->setEnvMode(GL_MODULATE);

    TheBoxMaterial->addChunk(AnimSequenceTexture);
    TheBoxMaterial->addChunk(TexEnv);
    TheBoxMaterial->addChunk(TheMaterialChunk);

    //Texture Keyframe Sequence
    KeyframeNumberSequenceUInt32RefPtr FrameChoiceKeyframes = KeyframeNumberSequenceUInt32::create();
    Real32 Rate(0.05f);
    for(UInt32 i(0) ; i<AnimSequenceTexture->getMFTextures()->size(); ++i)
    {
        FrameChoiceKeyframes->addRawKeyframe(i,static_cast<Real32>(i)*Rate);
    }
    for(UInt32 i(0) ; i<AnimSequenceTexture->getMFTextures()->size(); ++i)
    {
        FrameChoiceKeyframes->addRawKeyframe(AnimSequenceTexture->getMFTextures()->size()-i-1,
                                             static_cast<Real32>(i+AnimSequenceTexture->getMFTextures()->size())*Rate);
    }

    //Animator
    KeyframeAnimatorUnrecPtr TutorialTextureAnimator = KeyframeAnimator::create();
    TutorialTextureAnimator->setKeyframeSequence(FrameChoiceKeyframes);

    //Animation
    FieldAnimationUnrecPtr TutorialTextureAnimation = FieldAnimation::create();
    TutorialTextureAnimation->setAnimator(TutorialTextureAnimator);
    TutorialTextureAnimation->setInterpolationType(Animator::STEP_INTERPOLATION);
    TutorialTextureAnimation->setCycling(-1);
    TutorialTextureAnimation->setAnimatedField(AnimSequenceTexture,TextureSelectChunk::ChoiceFieldId);

    return AnimationTransitPtr(TutorialTextureAnimation);
}