void UpdateDecoratorPreview(bool resetScale) { Decorator selectedDecorator = null; if (puzzlePropertyGrid.SelectedObject is GraphElement graphElement) { selectedDecorator = graphElement.Decorator; } if (puzzlePropertyGrid.SelectedObject is Decorator) { selectedDecorator = puzzlePropertyGrid.SelectedObject as Decorator; } if (editView != null) { decoratorPreviewBuffer.Graphics.Clear(editView.Graph.MetaData.BackgroundColor); if (selectedDecorator != null) { if (resetScale) { decoratorPreviewScale = PuzzleToolkit.GetSuggestedDecorationScale(selectedDecorator); } PuzzleGraphRenderer renderer = new PuzzleGraphRenderer(decoratorPreviewBuffer.Graphics); double width = decoratorPreviewPictureBox.Width; double height = decoratorPreviewPictureBox.Height; renderer.DrawDecorator(selectedDecorator, new MathHelper.Vector(width / 2.0, height / 2.0), height * decoratorPreviewScale, editView.Graph.MetaData, editView.Graph.MetaData.BackgroundColor, true); } decoratorPreviewBuffer.Render(); } }
internal void ExportToFile(string savePath) { EditView exportView = new EditView(Graph, Graph.MetaData.ExportWidth, Graph.MetaData.ExportHeight, (int)tetrisTemplateEditorSize.X, (int)tetrisTemplateEditorSize.Y); Bitmap bitmap = new Bitmap(Convert.ToInt32(Graph.MetaData.ExportWidth), Convert.ToInt32(Graph.MetaData.ExportHeight), System.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(bitmap); PuzzleGraphRenderer renderer = new PuzzleGraphRenderer(g); renderer.Draw(exportView); bitmap.Save(savePath, ImageFormat.Png); }
public MainForm(string[] args) { InitializeComponent(); // Init graph drawing Graphics graphTargetGraphics = editorPictureBox.CreateGraphics(); graphBuffer = BufferedGraphicsManager.Current.Allocate(graphTargetGraphics, new Rectangle(0, 0, Screen.FromControl(this).Bounds.Width, Screen.FromControl(this).Bounds.Height)); graphBuffer.Graphics.SmoothingMode = SmoothingMode.AntiAlias; graphRenderer = new PuzzleGraphRenderer(graphBuffer.Graphics); // Init tetris template drawing Graphics tetrisTemplateTargetGraphics = tetrisTemplatePictureBox.CreateGraphics(); tetrisTemplateBuffer = BufferedGraphicsManager.Current.Allocate(tetrisTemplateTargetGraphics, new Rectangle(0, 0, Screen.FromControl(this).Bounds.Width, Screen.FromControl(this).Bounds.Height)); tetrisTemplateBuffer.Graphics.SmoothingMode = SmoothingMode.AntiAlias; tetrisTemplateRenderer = new TetrisTemplateRenderer(tetrisTemplateBuffer.Graphics); // Init preview graph box Graphics decoratorPreviewGraphics = decoratorPreviewPictureBox.CreateGraphics(); decoratorPreviewBuffer = BufferedGraphicsManager.Current.Allocate(decoratorPreviewGraphics, new Rectangle(0, 0, Screen.FromControl(this).Bounds.Width, Screen.FromControl(this).Bounds.Height)); decoratorPreviewBuffer.Graphics.SmoothingMode = SmoothingMode.AntiAlias; // Init other stuff editorPictureBox.MouseWheel += EditorPictureBox_MouseWheel; decoratorPreviewPictureBox.MouseWheel += DecoratorPreviewPictureBox_MouseWheel; InitToolkit(); UpdateToolkitListView(); if (args.Length >= 1) { string fileName = args[0]; try { Graph graph = Graph.LoadFromFile(fileName); if (ObsolateFormatFixer.FixObsoletedTetrisFormat(graph)) { Console.WriteLine("[Info] We have automatically upgraded the obsoleted file format. Please remember to save."); } editView = new EditView(graph, editorPictureBox.Width, editorPictureBox.Height, tetrisTemplatePictureBox.Width, tetrisTemplatePictureBox.Height); UpdateGraphDrawing(); UpdateTetrisTemplateDrawing(); savePath = fileName; } catch { MessageBox.Show(Resources.Lang.Warnings_FailToLoad + fileName); savePath = null; editView = null; } } }
public void Draw(Graphics graphics, int width, int height) { PuzzleGraphRenderer renderer = new PuzzleGraphRenderer(graphics); renderer.DrawDecorator(Decorator, new Vector(width / 2.0, height / 2.0), width * AdditionalScale, metaData, metaData.BackgroundColor, true); }