예제 #1
0
 public LineTool()
 {
     Instance = this;
     EditorContext.Toolbox = this;
     previewLayer          = new EditorImageLayer()
     {
         pixlmap = new Pixlmap(1, 1, true)
     };
 }
예제 #2
0
        public override void MouseUp(EditorContext context, MouseButtonEventArgs args)
        {
            if (isPressed)
            {
                isPressed = false;
                context.EditorControl.Images.Remove(previewLayer);

                Point mousePosition = context.EditorControl.MouseToPixelCoords(context, args);

                EditorImageLayer lyr = context.EditorControl.Images[context.CurrentLayer];

                int minX = (int)Math.Min(previousPoint.X, mousePosition.X), maxX = (int)Math.Max(previousPoint.X, mousePosition.X);
                int minY = (int)Math.Min(previousPoint.Y, mousePosition.Y), maxY = (int)Math.Max(previousPoint.Y, mousePosition.Y);

                void ContinueWithAction()
                {
                    if (brushIsSquare)
                    {
                        if (useIndexColor)
                        {
                            lyr.pixlmap.DrawLineSquare(previousPoint, mousePosition, brushWidth, indexColor);
                        }
                        else
                        {
                            lyr.pixlmap.DrawLineSquare(context, previousPoint, mousePosition, brushWidth, drawColor);
                        }
                    }
                    else
                    {
                        if (useIndexColor)
                        {
                            lyr.pixlmap.DrawLineCircle(previousPoint, mousePosition, brushWidth, indexColor);
                        }
                        else
                        {
                            lyr.pixlmap.DrawLineCircle(context, previousPoint, mousePosition, brushWidth, drawColor);
                        }
                    }

                    lyr.image = lyr.pixlmap.GetImage(context);
                    context.EditorControl.UpdateImageLayers = true;
                }

                Int32Rect rect = new Int32Rect(Math.Max(minX - brushWidth * 2, 0), Math.Max(minY - brushWidth * 2, 0), (int)Math.Min(maxX - minX + brushWidth * 4, context.CanvasSize.Width), (int)Math.Min(maxY - minY + brushWidth * 4, context.CanvasSize.Width));

                ChangePartUndo undo = new ChangePartUndo(lyr, rect, ContinueWithAction);

                context.AddUndo(undo);
            }
        }
예제 #3
0
        public PencilTool()
        {
            previewLayer = new EditorImageLayer
            {
                pixlmap = new Pixlmap(1, 1, true)
            };
            EditorContext.Toolbox = this;
            Instance = this;

            UI_BrushIsSquare            = new CheckBox();
            UI_BrushIsSquare.IsChecked  = true;
            UI_BrushIsSquare.Checked   += UI_BrushIsSquare_Checked;
            UI_BrushIsSquare.Unchecked += UI_BrushIsSquare_Unchecked;
            UI_BrushIsSquare.Content    = new TextBlock()
            {
                Text = "Circle Brush"
            };
            UI_PixelPerfect            = new CheckBox();
            UI_PixelPerfect.IsChecked  = true;
            UI_PixelPerfect.Checked   += UI_PixelPerfect_Checked;
            UI_PixelPerfect.Unchecked += UI_PixelPerfect_Unchecked;
            UI_PixelPerfect.Content    = new TextBlock()
            {
                Text = "Pixel Perfect"
            };
            UI_BrushSize = new TextBox();
            UI_BrushSize.PreviewTextInput += UI_BrushSize_PreviewTextInput;
            UI_BrushSize.MouseWheel       += UI_BrushSize_MouseWheel;
            UI_BrushSize.Text              = "1";
            UI_BrushSize.VerticalAlignment = VerticalAlignment.Center;
            UI_BrushSizeLabel              = new TextBlock()
            {
                Text = "Brush Size", TextAlignment = TextAlignment.Right, Padding = new Thickness(0, 0, 8, 0), VerticalAlignment = VerticalAlignment.Center
            };

            OptionsPanel.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(128, GridUnitType.Star)
            });
            OptionsPanel.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(128, GridUnitType.Star)
            });
            OptionsPanel.RowDefinitions.Add(new RowDefinition()
            {
                Height = new GridLength(32, GridUnitType.Pixel)
            });
            OptionsPanel.RowDefinitions.Add(new RowDefinition()
            {
                Height = new GridLength(32, GridUnitType.Pixel)
            });

            OptionsPanel.Children.Add(UI_BrushIsSquare);
            OptionsPanel.Children.Add(UI_PixelPerfect);
            OptionsPanel.Children.Add(UI_BrushSize);
            OptionsPanel.Children.Add(UI_BrushSizeLabel);

            Grid.SetColumn(UI_BrushIsSquare, 0);
            Grid.SetRow(UI_BrushIsSquare, 0);
            Grid.SetColumn(UI_PixelPerfect, 1);
            Grid.SetRow(UI_PixelPerfect, 0);
            Grid.SetColumn(UI_BrushSizeLabel, 0);
            Grid.SetRow(UI_BrushSizeLabel, 1);
            Grid.SetColumn(UI_BrushSize, 1);
            Grid.SetRow(UI_BrushSize, 1);
        }
예제 #4
0
        public override void MouseUp(EditorContext context, MouseButtonEventArgs args)
        {
            if (isPressed)
            {
                isPressed = false;
                context.EditorControl.Images.Remove(previewLayer);

                if (points.Count <= 0)
                {
                    return;
                }

                EditorImageLayer lyr = context.EditorControl.Images[context.CurrentLayer];

                void ContinueWithAction()
                {
                    if (pixelPerfect)
                    {
                        if (brushIsSquare)
                        {
                            if (useIndexColor)
                            {
                                lyr.pixlmap.DrawPerfectPathSquare(points, brushWidth, indexColor);
                            }
                            else
                            {
                                lyr.pixlmap.DrawPerfectPathSquare(context, points, brushWidth, drawColor);
                            }
                        }
                        else
                        {
                            if (useIndexColor)
                            {
                                lyr.pixlmap.DrawPerfectPathCircle(points, brushWidth, indexColor);
                            }
                            else
                            {
                                lyr.pixlmap.DrawPerfectPathCircle(context, points, brushWidth, drawColor);
                            }
                        }
                    }
                    else
                    {
                        if (brushIsSquare)
                        {
                            if (useIndexColor)
                            {
                                lyr.pixlmap.DrawPathSquare(points, brushWidth, indexColor);
                            }
                            else
                            {
                                lyr.pixlmap.DrawPathSquare(context, points, brushWidth, drawColor);
                            }
                        }
                        else
                        {
                            if (useIndexColor)
                            {
                                lyr.pixlmap.DrawPathCircle(points, brushWidth, indexColor);
                            }
                            else
                            {
                                lyr.pixlmap.DrawPathCircle(context, points, brushWidth, drawColor);
                            }
                        }
                    }

                    lyr.image = lyr.pixlmap.GetImage(context);
                    context.EditorControl.UpdateImageLayers = true;
                }

                int minX = (int)points[0].X, minY = (int)points[0].Y, maxX = (int)points[0].X, maxY = (int)points[0].Y;

                foreach (Point p in points)
                {
                    if (p.X < minX)
                    {
                        minX = (int)p.X;
                    }
                    if (p.Y < minY)
                    {
                        minY = (int)p.Y;
                    }
                    if (p.X > maxX)
                    {
                        maxX = (int)p.X;
                    }
                    if (p.Y > maxY)
                    {
                        maxY = (int)p.Y;
                    }
                }

                Int32Rect rect = new Int32Rect(Math.Max(minX - brushWidth * 2, 0), Math.Max(minY - brushWidth * 2, 0), (int)Math.Min(maxX - minX + brushWidth * 4, context.CanvasSize.Width), (int)Math.Min(maxY - minY + brushWidth * 4, context.CanvasSize.Width));

                ChangePartUndo undo = new ChangePartUndo(lyr, rect, ContinueWithAction);

                context.AddUndo(undo);
            }
        }