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"); } }
public void RefreshProject() { //ProjectNameNode.Text = "Project Name"; //ProjectNameNode.Nodes.Clear(); Canvas.XnaGraphics = null; Canvas.DrawingBatch = null; Canvas.DrawingContext = null; Canvas.LineBatch = null; Canvas.SpriteFont = null; Canvas.Effect = null; Canvas.Texture = null; if (xnaGraphics != null) { xnaGraphics = 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); xnaGraphics = new XnaGraphics(this.graphicsDeviceService.GraphicsDevice, drawingContext); PDefaults.DefaultGraphics = xnaGraphics; PDefaults.DefaultSpriteFont = fontManager.GetFont("SpriteFont").Font; Canvas.SpriteFont = segoeUIFont.Font; Canvas.Effect = roundlineEffect.Effect; Canvas.Texture = tulipsPng.Texture; Canvas.DrawingBatch = drawingBatch; Canvas.DrawingContext = drawingContext; Canvas.LineBatch = lineBatch; Canvas.XnaGraphics = xnaGraphics; } }