void AddEffectToTreeView(FyriEffect effectToAdd)
        {
            if (EffectNode == null)
            {
                if (AssetsNode == null)
                {
                    AssetsNode      = new TreeNode();
                    AssetsNode.Text = "Assets";
                    ProjectNameNode.Nodes.Add(AssetsNode);
                }
                EffectNode      = new TreeNode();
                EffectNode.Text = "Effects";
                AssetsNode.Nodes.Add(EffectNode);
            }

            TreeNode nodeToAdd = new TreeNode();

            nodeToAdd.Text = effectToAdd.EffectName;
            nodeToAdd.Tag  = effectToAdd;

            EffectNode.Nodes.Add(nodeToAdd);

            contentTreeView.CollapseAll();
            nodeToAdd.EnsureVisible();
            contentTreeView.Refresh();
        }
        /// <summary>
        /// Loads a new 3D model file into the ModelViewerControl.
        /// </summary>
        FyriEffect LoadEffectToProject(string effectName)
        {
            if (currentProject != null)
            {
                Cursor = Cursors.WaitCursor;

                FyriEffect loadedEffect = effectManager.LoadEffect(effectName);

                if (loadedEffect != null)
                {
                    if (!currentProject.LoadedFonts.Exists(p => p.FontName == effectName))
                    {
                        currentProject.LoadedEffects.Add(loadedEffect);
                    }

                    //effectViewerControl.Effect = loadedEffect.Effect;
                    AddEffectToTreeView(loadedEffect);
                }
                Cursor = Cursors.Arrow;

                return(loadedEffect);
            }

            return(null);
        }
        void AddEffectToTreeView(FyriEffect effectToAdd)
        {
            if (EffectNode == null)
            {
                EffectNode      = new TreeNode();
                EffectNode.Text = "Effects";
                //ProjectNameNode.Nodes.Add(EffectNode);
            }

            TreeNode nodeToAdd = new TreeNode();

            nodeToAdd.Text = effectToAdd.EffectName;
            nodeToAdd.Tag  = effectToAdd;

            EffectNode.Nodes.Add(nodeToAdd);

            //projectContentTV.CollapseAll();
            nodeToAdd.EnsureVisible();
            //projectContentTV.Refresh();
        }
        public void Initialize(IntPtr handle, int width, int height)
        {
            graphicsDeviceService = GraphicsDeviceService.AddRef(handle,
                                                                 width,
                                                                 height);

            // Register the service, so components like ContentManager can find it.
            services.AddService <IGraphicsDeviceService>(graphicsDeviceService);

            contentBuilder = new ContentBuilder(ProjectContentFolder, false);

            contentManager = new ContentManager(this.Services,
                                                contentBuilder.OutputDirectory);

            modelManager = new XnaModelManager(contentBuilder, contentManager, OriginalContentFolder);

            texture2dManager = new XnaTexture2dManager(contentBuilder, contentManager, OriginalContentFolder);

            fontManager = new XnaFontManager(contentBuilder, contentManager, OriginalContentFolder);

            effectManager = new XnaEffectManager(contentBuilder, contentManager, OriginalContentFolder);

            spriterManager = new XnaSpriterManager(contentBuilder, contentManager, OriginalContentFolder);

            RefreshLists();

            FyriEffect roundlineEffect = effectManager.GetEffect("RoundLine");
            FyriFont   roundlineFont   = fontManager.GetFont("SpriteFont");

            roundLineManager = new RoundLineManager();
            roundLineManager.Init(this.graphicsDeviceService.GraphicsDevice, roundlineEffect.Effect);

            lineBatch = new XnaLine2dBatch();
            lineBatch.Init(this.graphicsDeviceService.GraphicsDevice, roundlineEffect.Effect);

            drawingContext = new XnaDrawingContext(this.graphicsDeviceService.GraphicsDevice);

            IsInitialized = true;
        }
        public override FyriEffect LoadEffect(string fileName)
        {
            if (effectList.FirstOrDefault(p => p.OriginalFileName == fileName) != null)
            {
                return(effectList.FirstOrDefault(p => p.OriginalFileName == fileName));
            }

            FyriEffect newlyAddedEffect = new FyriEffect();

            newlyAddedEffect.OriginalFileName = fileName;

            string pathToMoveTo = ProjectOriginalContentFolder + "\\" + Path.GetFileName(fileName);

            if (!File.Exists(pathToMoveTo))
            {
                File.Copy(fileName, pathToMoveTo);
            }
            newlyAddedEffect.FileName = fileName;

            newlyAddedEffect.XnbFileLocation = contentBuilder.OutputDirectory;

            string effectName = Path.GetFileNameWithoutExtension(fileName);

            newlyAddedEffect.EffectName = effectName;

            Effect loadedEffect = null;

            string xnbFileLoc    = newlyAddedEffect.XnbFileLocation + "\\" + effectName + ".xnb";
            bool   xnbFileExists = File.Exists(xnbFileLoc);

            if (!xnbFileExists)
            {
                // Unload any existing model.
                //xna2dEditorControl.Model = null;
                //contentManager.Unload();

                // Tell the ContentBuilder what to build.
                contentBuilder.Clear();

                contentBuilder.Add(fileName, effectName, null, "EffectProcessor");

                // Build this new model data.
                string buildError = contentBuilder.Build();

                if (string.IsNullOrEmpty(buildError))
                {
                    // If the build succeeded, use the ContentManager to
                    // load the temporary .xnb file that we just created.
                    loadedEffect = contentManager.Load <Effect>(effectName);
                }
                else
                {
                    // If the build failed, display an error message.
                    MessageBox.Show(buildError, "Error");
                    return(null);
                }
            }
            else
            {
                loadedEffect = contentManager.Load <Effect>(effectName);
            }

            if (loadedEffect != null)
            {
                newlyAddedEffect.Effect = loadedEffect;
            }
            else
            {
                return(null);
            }

            effectList.Add(newlyAddedEffect);
            return(newlyAddedEffect);
        }
        public override FyriEffect GetEffect(string effectName)
        {
            FyriEffect effectToReturn = effectList.FirstOrDefault(p => p.EffectName == effectName);

            return(effectToReturn);
        }
        public void RefreshProject()
        {
            //ProjectNameNode.Text = "Project Name";

            //ProjectNameNode.Nodes.Clear();

            roundLineDemoViewerControl.RoundLineManager = null;
            roundLineDemoViewerControl.SpriteFont       = null;
            roundLineDemoViewerControl.Effect           = null;

            if (roundLineManager != null)
            {
                roundLineManager = null;
            }

            if (effectManager != null)
            {
                effectManager = null;
            }

            if (fontManager != null)
            {
                fontManager = null;
            }

            if (texture2dManager != null)
            {
                texture2dManager = null;
            }

            if (modelManager != null)
            {
                modelManager = null;
            }

            if (contentManager != null)
            {
                contentManager.Unload();
                contentManager.Dispose();
                contentManager = null;
            }

            if (contentBuilder != null)
            {
                contentBuilder.Clear();
                contentBuilder.Dispose();
                contentBuilder = null;
            }

            if (currentProject != null)
            {
                //ProjectNameNode.Text = currentProject.ProjectName;

                contentBuilder = new ContentBuilder(currentProject.ProjectContentFolder, false);

                contentManager = new ContentManager(this.Services,
                                                    contentBuilder.OutputDirectory);

                modelManager = new XnaModelManager(contentBuilder, contentManager, currentProject.OriginalContentFolder);

                texture2dManager = new XnaTexture2dManager(contentBuilder, contentManager, currentProject.OriginalContentFolder);

                fontManager = new XnaFontManager(contentBuilder, contentManager, currentProject.OriginalContentFolder);

                effectManager = new XnaEffectManager(contentBuilder, contentManager, currentProject.OriginalContentFolder);


                //roundLineTechniqueNames = roundLineManager.TechniqueNames;

                //ProjectNameNode.Nodes.Clear();
                ModelNode     = null;
                Texture2dNode = null;
                FontNode      = null;
                EffectNode    = null;

                //effectViewerControl.Effect = null;

                if (currentProject.LoadedModels.Count > 0)
                {
                    currentProject.LoadedModels = modelManager.RefreshList(currentProject.LoadedModels);

                    //foreach (FyriModel model in currentProject.LoadedModels)
                    //{
                    //    AddModelToTreeView(model);
                    //}
                }
                else
                {
                    //Load default Sphere
                    string defSphereFileName = Directory.GetCurrentDirectory() + "\\Default\\Sphere.fbx";
                    if (File.Exists(defSphereFileName))
                    {
                        LoadModelToProject(defSphereFileName);
                    }
                }

                if (currentProject.LoadedTexture2ds.Count > 0)
                {
                    currentProject.LoadedTexture2ds = texture2dManager.RefreshList(currentProject.LoadedTexture2ds);

                    //foreach (FyriTexture2d texture in currentProject.LoadedTexture2ds)
                    //{
                    //    AddTexture2dToTreeView(texture);
                    //}
                }

                if (currentProject.LoadedFonts.Count > 0)
                {
                    currentProject.LoadedFonts = fontManager.RefreshList(currentProject.LoadedFonts);

                    //foreach (FyriFont font in currentProject.LoadedFonts)
                    //{
                    //    AddFontToTreeView(font);
                    //}
                }
                else
                {
                    //Load default Sphere
                    string defSpriteFontFileName = Directory.GetCurrentDirectory() + "\\Default\\SpriteFont.spritefont";
                    if (File.Exists(defSpriteFontFileName))
                    {
                        LoadFontToProject(defSpriteFontFileName);
                    }
                }

                if (currentProject.LoadedEffects.Count > 0)
                {
                    currentProject.LoadedEffects = effectManager.RefreshList(currentProject.LoadedEffects);

                    //foreach (FyriEffect effect in currentProject.LoadedEffects)
                    //{
                    //    AddEffectToTreeView(effect);
                    //}
                }
                else
                {
                    //Load default Sphere
                    string defRLEffectFileName = Directory.GetCurrentDirectory() + "\\Default\\RoundLine.fx";
                    if (File.Exists(defRLEffectFileName))
                    {
                        LoadEffectToProject(defRLEffectFileName);
                    }
                }

                FyriEffect roundlineEffect = effectManager.GetEffect("RoundLine");
                FyriFont   roundlineFont   = fontManager.GetFont("SpriteFont");

                roundLineManager = new RoundLineManager();
                roundLineManager.Init(this.graphicsDeviceService.GraphicsDevice, roundlineEffect.Effect);

                roundLineDemoViewerControl.RoundLineManager = roundLineManager;
                roundLineDemoViewerControl.SpriteFont       = roundlineFont.Font;
                roundLineDemoViewerControl.Effect           = roundlineEffect.Effect;
            }
        }
        public void RefreshProject()
        {
            //ProjectNameNode.Text = "Project Name";

            //ProjectNameNode.Nodes.Clear();

            xnaToolBox1.ToolSelectionChanged   += SetTool;
            xna2dShapeControl1.ItemsSelected   += ItemsSelected;
            propertyGrid1.PropertyValueChanged += new PropertyValueChangedEventHandler(propertyGrid1_PropertyValueChanged);

            xna2dShapeControl1.Project          = null;
            xna2dShapeControl1.TextureManager   = null;
            xna2dShapeControl1.RoundLineManager = null;
            xna2dShapeControl1.LineBatch        = null;
            xna2dShapeControl1.SpriteFont       = null;
            xna2dShapeControl1.Effect           = null;
            xna2dShapeControl1.DrawingContext   = null;

            if (drawingContext != null)
            {
                drawingContext = null;
            }

            if (roundLineManager != null)
            {
                roundLineManager = null;
            }

            if (lineBatch != null)
            {
                lineBatch = null;
            }

            if (effectManager != null)
            {
                effectManager = null;
            }

            if (fontManager != null)
            {
                fontManager = null;
            }

            if (texture2dManager != null)
            {
                texture2dManager = null;
            }

            if (modelManager != null)
            {
                modelManager = null;
            }

            if (contentManager != null)
            {
                contentManager.Unload();
                contentManager.Dispose();
                contentManager = null;
            }

            if (contentBuilder != null)
            {
                contentBuilder.Clear();
                contentBuilder.Dispose();
                contentBuilder = null;
            }

            if (currentProject != null)
            {
                //ProjectNameNode.Text = currentProject.ProjectName;

                contentBuilder = new ContentBuilder(currentProject.ProjectContentFolder, false);

                contentManager = new ContentManager(this.Services,
                                                    contentBuilder.OutputDirectory);

                modelManager = new XnaModelManager(contentBuilder, contentManager, currentProject.OriginalContentFolder);

                texture2dManager = new XnaTexture2dManager(contentBuilder, contentManager, currentProject.OriginalContentFolder);

                fontManager = new XnaFontManager(contentBuilder, contentManager, currentProject.OriginalContentFolder);

                effectManager = new XnaEffectManager(contentBuilder, contentManager, currentProject.OriginalContentFolder);


                //roundLineTechniqueNames = roundLineManager.TechniqueNames;

                //ProjectNameNode.Nodes.Clear();
                ModelNode     = null;
                Texture2dNode = null;
                FontNode      = null;
                EffectNode    = null;

                //effectViewerControl.Effect = null;

                if (currentProject.LoadedModels.Count > 0)
                {
                    currentProject.LoadedModels = modelManager.RefreshList(currentProject.LoadedModels);

                    //foreach (FyriModel model in currentProject.LoadedModels)
                    //{
                    //    AddModelToTreeView(model);
                    //}
                }
                else
                {
                    //Load default Sphere
                    string defSphereFileName = Directory.GetCurrentDirectory() + "\\Default\\Sphere.fbx";
                    if (File.Exists(defSphereFileName))
                    {
                        LoadModelToProject(defSphereFileName);
                    }
                }

                if (currentProject.LoadedTexture2ds.Count > 0)
                {
                    currentProject.LoadedTexture2ds = texture2dManager.RefreshList(currentProject.LoadedTexture2ds);

                    //foreach (FyriTexture2d texture in currentProject.LoadedTexture2ds)
                    //{
                    //    AddTexture2dToTreeView(texture);
                    //}
                }

                if (currentProject.LoadedFonts.Count > 0)
                {
                    currentProject.LoadedFonts = fontManager.RefreshList(currentProject.LoadedFonts);

                    //foreach (FyriFont font in currentProject.LoadedFonts)
                    //{
                    //    AddFontToTreeView(font);
                    //}
                }
                else
                {
                    //Load default Sphere
                    string defSpriteFontFileName = Directory.GetCurrentDirectory() + "\\Default\\SpriteFont.spritefont";
                    if (File.Exists(defSpriteFontFileName))
                    {
                        LoadFontToProject(defSpriteFontFileName);
                    }
                }

                if (currentProject.LoadedEffects.Count > 0)
                {
                    currentProject.LoadedEffects = effectManager.RefreshList(currentProject.LoadedEffects);

                    //foreach (FyriEffect effect in currentProject.LoadedEffects)
                    //{
                    //    AddEffectToTreeView(effect);
                    //}
                }
                else
                {
                    //Load default Sphere
                    string defRLEffectFileName = Directory.GetCurrentDirectory() + "\\Default\\RoundLine.fx";
                    if (File.Exists(defRLEffectFileName))
                    {
                        LoadEffectToProject(defRLEffectFileName);
                    }
                }

                FyriEffect roundlineEffect = effectManager.GetEffect("RoundLine");
                FyriFont   roundlineFont   = fontManager.GetFont("SpriteFont");

                roundLineManager = new RoundLineManager();
                roundLineManager.Init(this.graphicsDeviceService.GraphicsDevice, roundlineEffect.Effect);

                lineBatch = new XnaLine2dBatch();
                lineBatch.Init(this.graphicsDeviceService.GraphicsDevice, roundlineEffect.Effect);

                drawingContext = new XnaDrawingContext(this.graphicsDeviceService.GraphicsDevice);


                xna2dShapeControl1.ShapeProperties  = this.propertyGrid1;
                xna2dShapeControl1.ToolBox          = this.xnaToolBox1;
                xna2dShapeControl1.RoundLineManager = roundLineManager;
                xna2dShapeControl1.LineBatch        = lineBatch;
                xna2dShapeControl1.SpriteFont       = roundlineFont.Font;
                xna2dShapeControl1.Effect           = roundlineEffect.Effect;
                xna2dShapeControl1.DrawingContext   = drawingContext;
                xna2dShapeControl1.TextureManager   = texture2dManager;
                xna2dShapeControl1.Project          = currentProject;
            }
        }
        public void RefreshProject()
        {
            //ProjectNameNode.Text = "Project Name";

            //ProjectNameNode.Nodes.Clear();

            //xna2dSvgPaintVC.DrawingBatch = null;
            //xna2dSvgPaintVC.DrawingContext = null;
            //xna2dSvgPaintVC.LineBatch = null;
            //xna2dSvgPaintVC.SpriteFont = null;
            //xna2dSvgPaintVC.Effect = null;
            //xna2dSvgPaintVC.Texture = null;

            _svgMainFiles.XnaItems = null;

            if (drawingContext != null)
            {
                drawingContext = null;
            }

            if (drawingBatch != null)
            {
                drawingBatch = null;
            }

            if (lineBatch != null)
            {
                lineBatch = null;
            }

            if (effectManager != null)
            {
                effectManager = null;
            }

            if (fontManager != null)
            {
                fontManager = null;
            }

            if (texture2dManager != null)
            {
                texture2dManager = null;
            }

            if (modelManager != null)
            {
                modelManager = null;
            }

            if (contentManager != null)
            {
                contentManager.Unload();
                contentManager.Dispose();
                contentManager = null;
            }

            if (contentBuilder != null)
            {
                contentBuilder.Clear();
                contentBuilder.Dispose();
                contentBuilder = null;
            }

            if (currentProject != null)
            {
                //ProjectNameNode.Text = currentProject.ProjectName;

                contentBuilder = new ContentBuilder(currentProject.ProjectContentFolder, false);

                contentManager = new ContentManager(this.Services,
                                                    contentBuilder.OutputDirectory);

                modelManager = new XnaModelManager(contentBuilder, contentManager, currentProject.OriginalContentFolder);

                texture2dManager = new XnaTexture2dManager(contentBuilder, contentManager, currentProject.OriginalContentFolder);

                fontManager = new XnaFontManager(contentBuilder, contentManager, currentProject.OriginalContentFolder);

                effectManager = new XnaEffectManager(contentBuilder, contentManager, currentProject.OriginalContentFolder);


                //roundLineTechniqueNames = roundLineManager.TechniqueNames;

                //ProjectNameNode.Nodes.Clear();
                ModelNode     = null;
                Texture2dNode = null;
                FontNode      = null;
                EffectNode    = null;

                //effectViewerControl.Effect = null;

                if (currentProject.LoadedModels.Count > 0)
                {
                    currentProject.LoadedModels = modelManager.RefreshList(currentProject.LoadedModels);

                    //foreach (FyriModel model in currentProject.LoadedModels)
                    //{
                    //    AddModelToTreeView(model);
                    //}
                }
                else
                {
                    //Load default Sphere
                    string defSphereFileName = Directory.GetCurrentDirectory() + "\\Default\\Sphere.fbx";
                    if (File.Exists(defSphereFileName))
                    {
                        LoadModelToProject(defSphereFileName);
                    }
                }

                if (currentProject.LoadedTexture2ds.Count > 0)
                {
                    currentProject.LoadedTexture2ds = texture2dManager.RefreshList(currentProject.LoadedTexture2ds);

                    //foreach (FyriTexture2d texture in currentProject.LoadedTexture2ds)
                    //{
                    //    AddTexture2dToTreeView(texture);
                    //}
                }
                else
                {
                    //Load default Sphere
                    string defTulipsPngFileName = Directory.GetCurrentDirectory() + "\\Default\\Tulips.png";
                    if (File.Exists(defTulipsPngFileName))
                    {
                        LoadTexture2dToProject(defTulipsPngFileName);
                    }
                }

                if (currentProject.LoadedFonts.Count > 0)
                {
                    currentProject.LoadedFonts = fontManager.RefreshList(currentProject.LoadedFonts);

                    //foreach (FyriFont font in currentProject.LoadedFonts)
                    //{
                    //    AddFontToTreeView(font);
                    //}
                }
                else
                {
                    //Load default Sphere
                    string defSpriteFontFileName = Directory.GetCurrentDirectory() + "\\Default\\SpriteFont.spritefont";
                    if (File.Exists(defSpriteFontFileName))
                    {
                        LoadFontToProject(defSpriteFontFileName);
                    }

                    string defSegoeFontFileName = Directory.GetCurrentDirectory() + "\\Default\\SegoeUI.spritefont";
                    if (File.Exists(defSegoeFontFileName))
                    {
                        LoadFontToProject(defSegoeFontFileName);
                    }
                }

                if (currentProject.LoadedEffects.Count > 0)
                {
                    currentProject.LoadedEffects = effectManager.RefreshList(currentProject.LoadedEffects);

                    //foreach (FyriEffect effect in currentProject.LoadedEffects)
                    //{
                    //    AddEffectToTreeView(effect);
                    //}
                }
                else
                {
                    //Load default Sphere
                    string defRLEffectFileName = Directory.GetCurrentDirectory() + "\\Default\\RoundLine.fx";
                    if (File.Exists(defRLEffectFileName))
                    {
                        LoadEffectToProject(defRLEffectFileName);
                    }
                }

                FyriEffect    roundlineEffect = effectManager.GetEffect("RoundLine");
                FyriFont      roundlineFont   = fontManager.GetFont("SpriteFont");
                FyriFont      segoeUIFont     = fontManager.GetFont("SegoeUI");
                FyriTexture2d tulipsPng       = texture2dManager.GetTexture2d("Tulips");

                lineBatch = new XnaLine2dBatch();
                lineBatch.Init(this.graphicsDeviceService.GraphicsDevice, roundlineEffect.Effect);

                drawingBatch   = new XnaDrawingBatch(this.graphicsDeviceService.GraphicsDevice);
                drawingContext = new XnaDrawingContext(this.graphicsDeviceService.GraphicsDevice);

                _svgMainFiles.XnaItems = new XnaItems();
                _svgMainFiles.XnaItems.ModelManager     = modelManager;
                _svgMainFiles.XnaItems.Texture2dManager = texture2dManager;
                _svgMainFiles.XnaItems.EffectManager    = effectManager;
                _svgMainFiles.XnaItems.FontManager      = fontManager;

                _svgMainFiles.XnaItems.DrawingBatch   = drawingBatch;
                _svgMainFiles.XnaItems.DrawingContext = drawingContext;
                _svgMainFiles.XnaItems.LineBatch      = lineBatch;

                //xna2dSvgPaintVC.SpriteFont = segoeUIFont.Font;
                //xna2dSvgPaintVC.Effect = roundlineEffect.Effect;
                //xna2dSvgPaintVC.Texture = tulipsPng.Texture;
                //xna2dSvgPaintVC.DrawingBatch = drawingBatch;
                //xna2dSvgPaintVC.DrawingContext = drawingContext;
                //xna2dSvgPaintVC.LineBatch = lineBatch;
            }
        }