Beispiel #1
0
        // Paste
        private void btnPaste_Click(object sender, RoutedEventArgs e)
        {
            // Xóa bỏ ContentControl của các hình đang chọn (nếu có)
            UnSelectedTheLastChildrenOfCanvas();

            // Lấy hình ảnh từ Clipboard
            BitmapSource bmi = Clipboard.GetImage();

            if (bmi != null)
            {
                // Tạo ImageBrush để fill cho Rectangle
                ImageBrush imb = new ImageBrush(bmi);

                shape = ShapeCreator.CreateNewShape("TRectangle");
                shape.FillColorBrush   = imb;
                shape.StrokeColorBrush = System.Windows.Media.Brushes.Transparent;
                shape.StartPoint       = new Point(0, 0);
                shape.EndPoint         = new Point(imb.ImageSource.Width, imb.ImageSource.Height);
                Style controlStyle = (Style)FindResource("DesignerItemStyle");
                if (controlStyle != null)
                {
                    shape.controlStyle = controlStyle;
                }

                shape.draw(isShiftKeyDown, PaintCanvas.Children);

                // Show control cho ContentControl
                SelectedTheLastChildrenOfCanvas();
                isSelectShape = true;
                ShapeCommand cmd = new ShapeCommand(PaintCanvas.Children, PaintCanvas.Children[PaintCanvas.Children.Count - 1]);
            }

            // Thoát chế độ Select
            isSelectionTool = false;
        }
Beispiel #2
0
        // Mouse Left Up Event
        private void PaintCanvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            isMouseDown = false;
            EndPoint    = e.GetPosition(PaintCanvas);

            // Chèn hình
            if (shape != null && StartPoint != EndPoint && DrawType == (int)DrawElementType.Shape)
            {
                // Xóa bỏ hình đã vé trước đó
                shape.removeShape(PaintCanvas.Children);

                // Vẽ lại hình mới
                shape.EndPoint = EndPoint;
                shape.draw(isShiftKeyDown, PaintCanvas.Children);

                // Đang chọn shape
                isSelectShape = true;
                SelectedTheLastChildrenOfCanvas();

                // Shape này là SelectionTool
                isSelectionTool = (CurrentTool == (int)DrawElementType.SelectionTool) ? true : false;

                // Tạo một ShapeCommand cho Undo, Redo
                if (!isSelectionTool)
                {
                    ShapeCommand cmd = new ShapeCommand(PaintCanvas.Children, PaintCanvas.Children[PaintCanvas.Children.Count - 1]);
                }
            }

            // Chèn văn bản
            if (DrawType == (int)DrawElementType.Text)
            {
                InsertNewTextBox();
            }
        }
Beispiel #3
0
        private void InsertNewTextBox()
        {
            TTextBox            = TextCreator.CreateNewTextElement();
            TTextBox.StartPoint = EndPoint;
            Style controlStyle = (Style)FindResource("DesignerItemStyle");

            if (controlStyle != null)
            {
                TTextBox.controlStyle = controlStyle;
            }

            TTextBox.insertNewText(PaintCanvas.Children);
            SelectedTheLastChildrenOfCanvas();

            ShapeCommand cmd = new ShapeCommand(PaintCanvas.Children, PaintCanvas.Children[PaintCanvas.Children.Count - 1]);
        }
Beispiel #4
0
        // Open file
        private void btnOpenImage_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog();
            openFileDialog.Filter     = "Png Image|*.png|Jpg Image|*.jpg|Bitmap Image|*.bmp";
            openFileDialog.FileName   = "MyPaint";
            openFileDialog.DefaultExt = ".png";

            if ((bool)openFileDialog.ShowDialog())
            {
                ImageBrush image = new ImageBrush();
                image.ImageSource = new BitmapImage(new Uri(@openFileDialog.FileName, UriKind.Relative));

                shape = ShapeCreator.CreateNewShape("TRectangle");
                shape.FillColorBrush   = image;
                shape.StrokeColorBrush = System.Windows.Media.Brushes.Transparent;
                shape.StartPoint       = new Point(0, 0);
                shape.EndPoint         = new Point(image.ImageSource.Width, image.ImageSource.Height);

                shape.draw(isShiftKeyDown, PaintCanvas.Children);
                ShapeCommand cmd = new ShapeCommand(PaintCanvas.Children, PaintCanvas.Children[PaintCanvas.Children.Count - 1]);
            }
        }
Beispiel #5
0
        // Cut
        private void btnCut_Click(object sender, RoutedEventArgs e)
        {
            if (isSelectionTool)
            {
                // Xóa ContentControl của Select
                removeLastChildren();

                shape                  = ShapeCreator.CreateNewShape("TRectangle");
                shape.StartPoint       = StartPoint;
                shape.EndPoint         = EndPoint;
                shape.FillColorBrush   = System.Windows.Media.Brushes.White;
                shape.StrokeColorBrush = System.Windows.Media.Brushes.Transparent;
                shape.draw(isShiftKeyDown, PaintCanvas.Children);

                // Lưu CroppedBitmapImage vào Clipboard
                saveCroppedBitmapToClipboard();

                ShapeCommand cmd = new ShapeCommand(PaintCanvas.Children, PaintCanvas.Children[PaintCanvas.Children.Count - 1]);
            }

            // Thoát chế độ Select
            isSelectionTool = false;
        }