예제 #1
0
        private void ExportSpriteAsImage()
        {
            var sfd = new SaveFileDialog
            {
                Title = "Export Sprite File as PNG",
                Filter = "PNG File (*.png)|*.png|JPG File (*.jpg)|*.jpg",
                FileName = "Export",
                AddExtension = true
            };

            if (sfd.ShowDialog() == true)
            {
                var file = sfd.FileName;

                var flag = new Bitmap(LoadedSprite.Width * WindowDataContext.SpriteBlockSize.Size, LoadedSprite.Height * WindowDataContext.SpriteBlockSize.Size);
                flag.SetResolution(100, 100);
                var flagGraphics = Graphics.FromImage(flag);

                for (var i = 0; i < LoadedSprite.Width; i++)
                {
                    for (var j = 0; j < LoadedSprite.Height; j++)
                    {
                        var c = LoadedSprite.GetColour(i, j);
                        var correctColor = ColourHandler.ByCode(c);

                        if(correctColor == null) continue;

                        flagGraphics.FillRectangle(correctColor.Color.ToSolidBrush(), 
                            new RectangleF(i * WindowDataContext.SpriteBlockSize.Size, 
                                j * WindowDataContext.SpriteBlockSize.Size, 
                                WindowDataContext.SpriteBlockSize.Size, 
                                WindowDataContext.SpriteBlockSize.Size));
                    }
                }

                switch (Path.GetExtension(file).Split('.').Last().ToLower())
                {
                    case "png":
                        flag.Save(file, ImageFormat.Png);
                        break;
                    case "jpg":
                        flag.Save(file, ImageFormat.Jpeg);
                        break;
                }

                WindowDataContext.CurrentProgramStatus = $"Exported: {Path.GetFileName(file)}";
            }
        }
예제 #2
0
        private void UpdateCanvas()
        {
            SpriteViewCanvas.IsEnabled = false;

            SpriteViewCanvas.Width = LoadedSprite.Width * WindowDataContext.SpriteBlockSize.Size;
            SpriteViewCanvas.Height = LoadedSprite.Height * WindowDataContext.SpriteBlockSize.Size;
                
            for (var column = 0; column < LoadedSprite.Height; column++)
            {
                for (var row = 0; row < LoadedSprite.Width; row++)
                {
                    var row1 = row;
                    var column1 = column;

                    var c = LoadedSprite.GetColour(row, column);
                    var g = LoadedSprite.GetGlyph(row, column);                    
                    var correctColor = ColourHandler.ByCode(c, (Pixal)g);

                    if(correctColor == null) continue;
                    
                    var rect = new Rectangle
                    {
                        Width = WindowDataContext.SpriteBlockSize.Size,
                        Height = WindowDataContext.SpriteBlockSize.Size,
                        Fill = correctColor.Brush,    
                        StrokeThickness = 2
                    };

                    if (Default.UseGridOnCanvas)
                    {
                        rect.Stroke = _gridColorBrush;
                    }

                    rect.MouseEnter += (sender, args) =>
                    {
                        var rr = (Rectangle) sender;
                        var ca = _activeColour;
                        if (_isRightClickHeldDown)
                        {
                            ca = ColourHandler.Colours[0];
                        }

                        if (_isLeftClickHeldDown || _isRightClickHeldDown)
                        {
                            UpdateRect(rr, row1, column1, ca);
                        }

                        Colour rectColour = GetColourFromRect(rr);
                        rr.ToolTip = new ToolTip();

                        var rrT = (ToolTip) rr.ToolTip;
                        rrT.Content += $"POS: {rr.Tag}" +
                                       $"{Environment.NewLine}Hex: #{rectColour.Hex}" +
                                       $"{Environment.NewLine}Pixal: {(char)rectColour.Pixal}";
                        rect.Stroke = _hoverBrush;
                    };

                    rect.MouseLeave += (sender, args) =>
                    {
                        var rr = (Rectangle)sender;
                        rr.ToolTip = null;

                        if (Default.UseGridOnCanvas)
                        {
                            rect.Stroke = _gridColorBrush;
                            return;
                        }

                        rect.Stroke = null;
                    };

                    rect.MouseUp += (sender, args) =>
                    {
                        if (args.LeftButton == MouseButtonState.Released)
                        {
                            _isLeftClickHeldDown = false;
                            WindowDataContext.CurrentSystemTool = "";
                        }

                        if (args.RightButton == MouseButtonState.Released)
                        {
                            _isRightClickHeldDown = false;
                            WindowDataContext.CurrentSystemTool = "";
                        }
                    };

                    rect.MouseDown += (sender, args) =>
                    {
                        var ca = _activeColour;
                        if (args.LeftButton == MouseButtonState.Pressed)
                        {
                            _isRightClickHeldDown = false;
                            _isLeftClickHeldDown = true;
                            WindowDataContext.CurrentSystemTool = "Dragging Mode";

                        }
                        else if (args.RightButton == MouseButtonState.Pressed)
                        {
                            _isLeftClickHeldDown = false;
                            _isRightClickHeldDown = true;
                            WindowDataContext.CurrentSystemTool = "Erasing Mode";
                            ca = ColourHandler.Colours[0];
                        }
                        
                        UpdateRect((Rectangle)sender, row1, column1, ca);
                    };

                    rect.Tag = $"{(column + 1)}, {(row + 1)}";

                    SpriteViewCanvas.Children.Add(rect);
                    Canvas.SetTop(rect, column * WindowDataContext.SpriteBlockSize.Size);
                    Canvas.SetLeft(rect, row * WindowDataContext.SpriteBlockSize.Size);
                }
            }

            SpriteViewCanvas.IsEnabled = true;
        }