/// <summary>
        /// Loads a new 3D model file into the ModelViewerControl.
        /// </summary>
        FyriTexture2d LoadTexture2dToProject(string fileName)
        {
            if (currentProject != null)
            {
                Cursor = Cursors.WaitCursor;

                FyriTexture2d loadedTexture = texture2dManager.LoadTexture2d(fileName);

                if (loadedTexture != null)
                {
                    if (!currentProject.LoadedTexture2ds.Exists(p => p.OriginalFileName == fileName))
                    {
                        currentProject.LoadedTexture2ds.Add(loadedTexture);
                    }

                    //texture2dViewerControl.Texture = loadedTexture.Texture;
                    AddTexture2dToTreeView(loadedTexture);
                }
                Cursor = Cursors.Arrow;

                return(loadedTexture);
            }

            return(null);
        }
示例#2
0
        void AddTexture2dToTreeView(FyriTexture2d textureToAdd)
        {
            if (Texture2dNode == null)
            {
                if (AssetsNode == null)
                {
                    AssetsNode      = new TreeNode();
                    AssetsNode.Text = "Assets";
                    ProjectNameNode.Nodes.Add(AssetsNode);
                }
                Texture2dNode      = new TreeNode();
                Texture2dNode.Text = "Textures";
                AssetsNode.Nodes.Add(Texture2dNode);
            }

            TreeNode nodeToAdd = new TreeNode();

            nodeToAdd.Text = textureToAdd.TextureName;
            nodeToAdd.Tag  = textureToAdd;

            Texture2dNode.Nodes.Add(nodeToAdd);

            contentTreeView.CollapseAll();
            nodeToAdd.EnsureVisible();
            contentTreeView.Refresh();
        }
示例#3
0
        public void LoadContent()
        {
            spriteBatch  = new SpriteBatch(this.GraphicsDevice);
            drawingBatch = new XnaDrawingBatch(this.GraphicsDevice);

            screen = new RenderTarget2D(
                this.GraphicsDevice,
                this.GraphicsDevice.PresentationParameters.BackBufferWidth,
                this.GraphicsDevice.PresentationParameters.BackBufferHeight,
                false,
                this.GraphicsDevice.PresentationParameters.BackBufferFormat,
                DepthFormat.Depth24);

            blank = new Texture2D(GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
            blank.SetData(new[] { Color.White });

            XnaDrawing.blank        = blank;
            XnaDrawing.spriteBatch  = spriteBatch;
            XnaDrawing.drawingBatch = drawingBatch;
            XnaDrawing.defaultFont  = font;

            camera      = new XnaCamera2d(this.GraphicsDevice.Viewport);
            camera.Pos  = new Vector2(400.0f, 300.0f);
            camera.Zoom = 300;

            float rho  = 100;
            bool  blue = false;

            for (float y = -2000; y <= 2000; y += 200)
            {
                for (float x = -1000; x <= 1000; x += 200)
                {
                    blue = !blue;
                    for (float deg = 0; deg < 360; deg += 10)
                    {
                        float theta = MathHelper.ToRadians(deg);
                        float x1    = rho * (float)Math.Cos(theta);
                        float y1    = rho * (float)Math.Sin(theta);

                        if (blue)
                        {
                            blueRoundLines.Add(new RoundLine(x, y, x + x1, y + y1));
                        }
                        else
                        {
                            greenRoundLines.Add(new RoundLine(x, y, x + x1, y + y1));
                        }
                    }
                }
            }

            //Create2DViewMatrix();
            Create2DProjectionMatrix();

            if (textureManager != null)
            {
                cursorTexture = textureManager.LoadTexture2d(@"C:\Users\dovieya\Desktop\XNA 2D Editor\fyri2deditor\Xna2dEditor\Resources\Cursor.png");
            }
        }
        void AddTexture2dToTreeView(FyriTexture2d textureToAdd)
        {
            if (Texture2dNode == null)
            {
                Texture2dNode      = new TreeNode();
                Texture2dNode.Text = "Textures";
                //ProjectNameNode.Nodes.Add(Texture2dNode);
            }

            TreeNode nodeToAdd = new TreeNode();

            nodeToAdd.Text = textureToAdd.TextureName;
            nodeToAdd.Tag  = textureToAdd;

            Texture2dNode.Nodes.Add(nodeToAdd);

            //projectContentTV.CollapseAll();
            nodeToAdd.EnsureVisible();
            //projectContentTV.Refresh();
        }
        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;
            }
        }
示例#6
0
        public override FyriTexture2d LoadTexture2d(string fileName)
        {
            if (textureList.FirstOrDefault(p => p.OriginalFileName == fileName) != null)
            {
                return(textureList.FirstOrDefault(p => p.OriginalFileName == fileName));
            }

            FyriTexture2d newlyAddedTexture = new FyriTexture2d();

            newlyAddedTexture.OriginalFileName = fileName;

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

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

            newlyAddedTexture.XnbFileLocation = contentBuilder.OutputDirectory;

            string textureName = Path.GetFileNameWithoutExtension(fileName);

            newlyAddedTexture.TextureName = textureName;

            Texture2D loadedTexture = null;

            string xnbFileLoc    = newlyAddedTexture.XnbFileLocation + "\\" + textureName + ".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, textureName, null, "TextureProcessor");

                // 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.
                    loadedTexture = contentManager.Load <Texture2D>(textureName);
                }
                else
                {
                    // If the build failed, display an error message.
                    MessageBox.Show(buildError, "Error");
                    return(null);
                }
            }
            else
            {
                loadedTexture = contentManager.Load <Texture2D>(textureName);
            }

            if (loadedTexture != null)
            {
                newlyAddedTexture.Texture = loadedTexture;
            }
            else
            {
                return(null);
            }

            textureList.Add(newlyAddedTexture);
            return(newlyAddedTexture);
        }
示例#7
0
        public override FyriTexture2d GetTexture2d(string textureName)
        {
            FyriTexture2d textureToReturn = textureList.FirstOrDefault(p => p.TextureName == textureName);

            return(textureToReturn);
        }