Beispiel #1
0
 public void SetItemSelector(ItemLayer item)
 {
     if (item != null)
     {
         itemChoose          = item;
         itemChoose.Selected = true;
     }
 }
Beispiel #2
0
        private void MainCanvas_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
            {
                return;
            }
            if (!(e.Source != MainCanvas && e.Source.GetType() == typeof(ItemLayer) && controlSelector.itemChoose == (ItemLayer)e.Source))
            {
                for (int i = 0; i < MainCanvas.Children.Count; ++i)
                {
                    if (!(MainCanvas.Children[i] is ItemLayer))
                    {
                        continue;
                    }
                    ItemLayer item = (ItemLayer)MainCanvas.Children[i];
                    if (item.Selected == true)
                    {
                        item.Selected = false;
                        SaveHistory();
                    }
                    //Canvas.SetZIndex(item, 0);
                }
                controlSelector.itemChoose = null;
                //SaveCanvas();
                for (int i = 0; i < MainCanvas.Children.Count; ++i)
                {
                    if (!(MainCanvas.Children[i] is ItemLayer))
                    {
                        continue;
                    }
                    ItemLayer item = (ItemLayer)MainCanvas.Children[i];
                    MainCanvas.Children.Remove((ItemLayer)MainCanvas.Children[i]);
                }
            }
            if (TypeDraw == TypeShape.Eraser)
            {
                isEraser = true;
                Point        p   = Mouse.GetPosition(MainCanvas);
                BitmapSource bmp = (BitmapSource)MainCanvasImage.Source;

                if (bmp == null)
                {
                    return;
                }
                MyBitmap = new WriteableBitmap(bmp);
                MainCanvasImage.Source = MyBitmap;
                ImageProcess.Rubber((int)p.X, (int)p.Y, penWidth, MyBitmap);
            }
            if (TypeDraw == TypeShape.Fill)
            {
                System.Drawing.Color color = System.Drawing.Color.FromArgb(fillColor.A, fillColor.R, fillColor.G, fillColor.B);
                Point p = Mouse.GetPosition(MainCanvas);
                ImageProcess.FloodFill(MainCanvas, MainCanvasImage, p, color);
                SaveHistory();
                return;
            }
        }
Beispiel #3
0
        private void MainCanvas_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (e.RightButton == MouseButtonState.Pressed)
            {
                return;
            }
            if (IsMouseDown != false)
            {
                IsMouseDown = false;
                yOffset     = Translate.Y;
                xOffset     = Translate.X;
                return;
            }
            controlSelector.OnMouse_Up();
            if (isEraser == true && TypeDraw == TypeShape.Eraser)
            {
                isEraser = false;
                SaveHistory();
                return;
            }
            if (TypeDraw == TypeShape.PolyGon)
            {
                return;
            }
            if (TypeDraw == TypeShape.PolyLine)
            {
                if (controlSelector.itemChoose != null)
                {
                    controlSelector.itemChoose.Selected = false;
                    controlSelector.itemChoose          = null;
                    SaveHistory();
                    for (int i = 0; i < MainCanvas.Children.Count; ++i)
                    {
                        if (!(MainCanvas.Children[i] is ItemLayer))
                        {
                            continue;
                        }
                        ItemLayer item = (ItemLayer)MainCanvas.Children[i];
                        MainCanvas.Children.Remove((ItemLayer)MainCanvas.Children[i]);
                    }
                }
                //TypeDraw = TypeShape.None;
                return;
            }
            //btnSelect.IsChecked = true;
            TypeDraw = TypeShape.None;

            //if (TypeDraw != TypeShape.None)
            //{
            //    TypeDraw = TypeShape.None;
            //}
        }
Beispiel #4
0
 public void SetItemCreate(ItemLayer item)
 {
     MouseHitType = HitType.LR;
     if (item.Type == TypeShape.PolyLine)
     {
         MouseHitType = HitType.None;
     }
     DragInProgress = true;
     SetMouseCursor();
     LastPoint     = Mouse.GetPosition(MainCanvas);
     item.Selected = true;
     itemChoose    = item;
 }
Beispiel #5
0
 private void btnNew_Click(object sender, RoutedEventArgs e)
 {
     for (int i = 0; i < MainCanvas.Children.Count; ++i)
     {
         if (!(MainCanvas.Children[i] is ItemLayer))
         {
             continue;
         }
         ItemLayer item = (ItemLayer)MainCanvas.Children[i];
         MainCanvas.Children.Remove((ItemLayer)MainCanvas.Children[i]);
     }
     MainCanvasImage.Source = null;
     FileSystem.ClearTemp();
     history.ClearTemp();
     history.ClearMain();
 }
Beispiel #6
0
        private void MainCanvas_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.RightButton == MouseButtonState.Pressed)
            {
                return;
            }
            if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
            {
                IsMouseDown = true;
                initial     = Mouse.GetPosition(this);
                return;
            }
            if (TypeDraw == TypeShape.Fill || TypeDraw == TypeShape.Eraser)
            {
                return;
            }
            if (controlSelector.itemChoose != null && TypeDraw != TypeShape.PolyGon)
            {
                controlSelector.OnMouse_Down();
                return;
            }

            if (TypeDraw == TypeShape.PolyGon)
            {
                if (controlSelector.itemChoose != null)
                {
                    if (e.ClickCount == 2)
                    {
                        TypeDraw = TypeShape.None;
                        controlSelector.itemChoose.Selected = false;
                        controlSelector.itemChoose          = null;
                        SaveHistory();
                        for (int i = 0; i < MainCanvas.Children.Count; ++i)
                        {
                            if (!(MainCanvas.Children[i] is ItemLayer))
                            {
                                continue;
                            }
                            ItemLayer item = (ItemLayer)MainCanvas.Children[i];
                            MainCanvas.Children.Remove((ItemLayer)MainCanvas.Children[i]);
                        }
                        return;
                    }
                    // Mouse.GetPosition(MainCanvas);
                    Point CurPoint = Mouse.GetPosition(MainCanvas);
                    CurPoint = MainCanvas.PointToScreen(CurPoint);
                    CurPoint = ((PolyGonObject)controlSelector.itemChoose.objectBase).rect.PointFromScreen(CurPoint);
                    ((PolyGonObject)controlSelector.itemChoose.objectBase).rect.Points.Add(CurPoint);
                    return;
                }
            }

            if (TypeDraw == TypeShape.None)
            {
                if (controlSelector.itemChoose != null)
                {
                    if (e.ClickCount == 2 && controlSelector.itemChoose.Type == TypeShape.Text)
                    {
                        MessageBox.Show("Show tab chỉnh sửa text");
                        /*Tạo 1 tab mới để chỉnh sửa*/
                        ItemLayer itemLayer = controlSelector.itemChoose;
                        itemLayer.RectText        = "Set lại dòng text";
                        itemLayer.RectFontSize    = 30;
                        itemLayer.ColorStroke     = Color.FromRgb(255, 255, 0);
                        itemLayer.RectFontStyle   = FontStyles.Italic;
                        itemLayer.RectFontStretch = FontStretches.ExtraExpanded;
                        return;
                    }
                }
                controlSelector.OnMouse_Down();
            }
            else if (TypeDraw != TypeShape.Text)
            {
                Point CurPoint = Mouse.GetPosition(MainCanvas);

                ItemLayer item = new ItemLayer(TypeDraw); // TypeDraw loại hình
                Canvas.SetLeft(item, CurPoint.X);
                Canvas.SetTop(item, CurPoint.Y);
                item.Width                 = 1;
                item.Height                = 1;
                item.ColorStroke           = outlineColor; // tùy chỉnh màu vẽ
                item.ColorFill             = fillColor;    // Tùy chỉnh màu fill, không fill thì = new Color();
                item.PenWidth              = penWidth;     // Tùy chỉnh Độ rộng
                item.MainCanvas_MouseDown += MainCanvas_MouseDown;
                item.MainCanvas_MouseUp   += MainCanvas_MouseUp;
                item.MainCanvas_MouseMove += MainCanvas_MouseMove;
                item.StyleLine             = styleLine;
                item.Create();
                MainCanvas.Children.Add(item);
                //history.PushBack(item);
                controlSelector.SetItemCreate(item);
            }
            else
            {
                Point CurPoint = Mouse.GetPosition(MainCanvas);

                ItemLayer item = new ItemLayer(TypeShape.Text); // TypeDraw loại hình
                Canvas.SetLeft(item, CurPoint.X);
                Canvas.SetTop(item, CurPoint.Y);
                item.Width  = 1;
                item.Height = 1;
                item.MainCanvas_MouseDown += MainCanvas_MouseDown;
                item.MainCanvas_MouseUp   += MainCanvas_MouseUp;
                item.MainCanvas_MouseMove += MainCanvas_MouseMove;

                if (textToolsGroup != null)
                {
                    textToolsGroup.Visibility = Visibility.Visible;
                }
                if (MainRibbon != null)
                {
                    MainRibbon.SelectedTabIndex = 0;
                }

                item.Create();
                /*Sử dụng sau hàm Create*/
                item.RectFontFamily = fontFamilyText;
                item.RectText       = "Helllo31387126378216hfdjisdhfkjsdhkfjdshf";
                item.RectFontSize   = fontSizeText;
                item.ColorStroke    = textColor; // tùy chỉnh màu vẽ

                MainCanvas.Children.Add(item);
                //history.PushBack(item);
                controlSelector.SetItemCreate(item);
            }
        }