示例#1
0
        private void CreateColorPalletWindow()
        {
            var size = 32;

            _activeColour = ColourHandler.ByHex("00000000", Pixal.PIXEL_SPACE);

            ColorViewCanvas.Width = ColorScrollViewer.Width;

            var width = (int)(ColorViewCanvas.Width / size);
            var height = (int)Math.Ceiling((decimal)ColourHandler.Colours.Count / width);
            ColorViewCanvas.Height = height * size;

            var colorIdx = 0;
            for (var j = 0; j < height; j++)
            {
                for (var i = 0; i < width; i++)
                {
                    if (colorIdx == ColourHandler.Colours.Count)
                    {
                        break;
                    }

                    var c = ColourHandler.Colours[colorIdx];

                    var rect = new Rectangle
                    {
                        Width = size,
                        Height = size,
                        Fill = c.Brush,
                        Stroke = _colorBorder,
                        StrokeThickness = 1.2
                    };

                    rect.MouseEnter += (sender, args) =>
                    {
                        var brush = (SolidColorBrush)rect.Stroke;
                        if (Equals(brush.Color, Colors.Red)) return;

                        rect.Stroke = _hoverBrush;
                    };

                    rect.MouseLeave += (sender, args) =>
                    {
                        var brush = (SolidColorBrush)rect.Stroke;
                        if (Equals(brush.Color, Colors.Red)) return;

                        rect.Stroke = _colorBorder;
                    };

                    rect.MouseUp += (sender, args) =>
                    {
                        _isLeftClickHeldDown = false;
                        _isRightClickHeldDown = false;

                        var p = (Rectangle)sender;

                        p.Stroke = _activeColor;
                        _activeColour = c;

                        foreach (var child in ColorViewCanvas.Children)
                        {
                            var r = (Rectangle)child;
                            if (Equals(r, p)) continue;

                            if (!Equals(r.Stroke, _activeColor)) continue;
                            r.Stroke = _colorBorder;
                            break;

                        }
                    };

                    var tt = new ToolTip
                    {
                        Content = $"Hex: #{c.Hex}{Environment.NewLine}" +
                                  $"RGB: {c.R},{c.G},{c.B}" +
                                  $"{(c.A < 255 ? $"{Environment.NewLine}Transparent" : "")}{Environment.NewLine}" +
                                  $"IDX: {colorIdx}{Environment.NewLine}" +
                                  $"Pixal: {(char)c.Pixal}",
                        Background = new SolidColorBrush(Color.FromArgb(200, 255, 255, 255))
                    };

                    rect.ToolTip = tt;

                    if (_activeColour != null && _activeColour.Hex == c.Hex)
                    {
                        rect.Stroke = _activeColor;
                    }

                    ColorViewCanvas.Children.Add(rect);
                    Canvas.SetLeft(rect, i * size);
                    Canvas.SetTop(rect, j * size);

                    colorIdx++;
                }
            }
        }
        private void HandleButton_Clicked(object sender, RoutedEventArgs e)
        {
            var name = ((Button)sender).Name;

            switch (name)
            {
            case "CreateSprite":
                _mainWindow.LoadedSprite             = new Sprite(NumberPickerWidth.Value, NumberPickerHeight.Value, ColourHandler.ByHex("00000000", Pixal.PIXEL_SPACE), _mainWindow);
                Properties.Settings.Default.Create_H = _mainWindow.LoadedSprite.Height;
                Properties.Settings.Default.Create_W = _mainWindow.LoadedSprite.Width;

                _mainWindow.WindowDataContext.CurrentProgramStatus = $"Created {_mainWindow.LoadedSprite.Width}x{_mainWindow.LoadedSprite.Height} Sprite";

                Properties.Settings.Default.Save();
                DialogResult = true;
                break;

            case "CancelSprite":
                DialogResult = false;
                break;
            }

            Close();
        }