Exemple #1
0
        private void chkFillBackGround_Checked(object sender, RoutedEventArgs e)
        {
            CheckFilled();
            ExpFilledCustom.IsEnabled = true;
            int x = DrawArea.TheLayers.ActiveLayerIndex;
            int n = DrawArea.TheLayers[x].Graphics.SelectionCount;

            if (n > 0)
            {
                n = DrawArea.TheLayers[x].Graphics.Count;
                for (int i = 0; i < n; i++)
                {
                    if (DrawArea.TheLayers[x].Graphics[i].Selected == true)
                    {
                        DrawObject obj = DrawArea.TheLayers[x].Graphics[i];
                        if (DrawArea.DrawFilled == true)
                        {
                            obj.Gradient  = false;
                            obj.Filled    = true;
                            obj.Hatch     = false;
                            obj.Texture   = false;
                            obj.FillColor = DrawArea.FillColor;
                            DrawArea.TheLayers[x].Graphics.Replace(i, obj);
                        }
                        else if (DrawArea.DrawGradient == true)
                        {
                            obj.Gradient = true;
                            obj.Filled   = false;
                            obj.Hatch    = false;
                            obj.Texture  = false;
                            DrawArea.TheLayers[x].Graphics.Replace(i, obj);
                        }
                        else if (DrawArea.DrawHatch == true)
                        {
                            obj.Gradient = false;
                            obj.Filled   = false;
                            obj.Hatch    = true;
                            obj.Texture  = false;
                            DrawArea.TheLayers[x].Graphics.Replace(i, obj);
                        }
                        else if (DrawArea.DrawTexture == true)
                        {
                            obj.Gradient  = false;
                            obj.Filled    = false;
                            obj.Hatch     = false;
                            obj.Texture   = true;
                            obj.FillImage = DrawArea.FillImage;
                            DrawArea.TheLayers[x].Graphics.Replace(i, obj);
                        }
                    }
                }
                DrawArea.Refresh();
            }
        }
 // Đổ dữ liệu trong field từ đối tượng này đến đối tượng Clone
 protected void FillDrawObjectFields(DrawObject drawObject)
 {
     drawObject.selected   = selected;
     drawObject.color      = color;
     drawObject.penWidth   = penWidth;
     drawObject.ID         = ID;
     drawObject._penType   = _penType;
     drawObject._shapeName = _shapeName;
     drawObject.drawpen    = drawpen;
     drawObject.filled     = filled;
     drawObject.gradient   = gradient;
     drawObject.hatch      = hatch;
     drawObject.texture    = texture;
     drawObject.fillImage  = fillImage;
     drawObject.fillColor  = fillColor;
     drawObject._rotation  = _rotation;
     drawObject._center    = _center;
 }
Exemple #3
0
        private void btnFilledTexture_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog op = new OpenFileDialog();

            op.Title  = "Select a picture";
            op.Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" +
                        "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" +
                        "Portable Network Graphic (*.png)|*.png";
            DrawArea.DrawTexture      = true;
            btnFilledTexture.Content  = "C";
            DrawArea.DrawHatch        = false;
            btnFilledHatch.Content    = "";
            DrawArea.DrawFilled       = false;
            btnFilledSolid.Content    = "";
            DrawArea.DrawGradient     = false;
            btnFilledGradient.Content = "";

            if (op.ShowDialog() == true)
            {
                DrawArea.FillImage = new Bitmap(op.FileName);
            }
            int x = DrawArea.TheLayers.ActiveLayerIndex;
            int n = DrawArea.TheLayers[x].Graphics.SelectionCount;

            if (n > 0)
            {
                n = DrawArea.TheLayers[x].Graphics.Count;
                for (int i = 0; i < n; i++)
                {
                    if (DrawArea.TheLayers[x].Graphics[i].Selected == true)
                    {
                        DrawObject obj = DrawArea.TheLayers[x].Graphics[i];
                        obj.Gradient  = false;
                        obj.Filled    = false;
                        obj.Hatch     = false;
                        obj.Texture   = true;
                        obj.FillImage = DrawArea.FillImage;
                        DrawArea.TheLayers[x].Graphics.Replace(i, obj);
                    }
                }
                DrawArea.Refresh();
            }
        }
Exemple #4
0
        // Hàm này được gọi khi user click trái vào draw area và một tool được active
        public void AddNewObject(DrawArea drawArea, DrawObject o)
        {
            int al = drawArea.TheLayers.ActiveLayerIndex;

            drawArea.TheLayers[al].Graphics.UnselectAll();

            o.Selected = true;
            o.Dirty    = true;
            int objectID = 0;

            // Lấy id của đối tượng
            for (int i = 0; i < drawArea.TheLayers.Count; i++)
            {
                objectID = +drawArea.TheLayers[i].Graphics.Count;
            }
            objectID++;
            o.ID = objectID;
            drawArea.TheLayers[al].Graphics.Add(o);

            drawArea.Capture = true;
            drawArea.Refresh();
        }
Exemple #5
0
        // Replace phục vụ cho Undo và Redo
        private void ReplaceObjects(GraphicsList graphicsList, List <DrawObject> list)
        {
            for (int i = 0; i < graphicsList.Count; i++)
            {
                DrawObject replacement = null;

                foreach (DrawObject o in list)
                {
                    if (o.ID ==
                        graphicsList[i].ID)
                    {
                        replacement = o;
                        break;
                    }
                }

                if (replacement != null)
                {
                    graphicsList.Replace(i, replacement);
                }
            }
        }
        /* So sánh với ZOrder để xem đối tượng nào nổi lên
         * Trả về -1: Nằm dưới
         * Trả về 0: Nằm ngang nhau
         * Trả về 1: Nằm trên
         */
        public int CompareTo(object obj)
        {
            DrawObject d = obj as DrawObject;
            int        x = 0;

            if (d != null)
            {
                if (d.ZOrder == ZOrder)
                {
                    x = 0;
                }
                else if (d.ZOrder > ZOrder)
                {
                    x = -1;
                }
                else
                {
                    x = 1;
                }
            }
            return(x);
        }
Exemple #7
0
        private void cbxDashArrow_Checked(object sender, RoutedEventArgs e)
        {
            DrawArea.PenType    = TypeOfPen.PenType.DashArrow;
            DrawArea.CurrentPen = TypeOfPen.SetCurrentPen(TypeOfPen.PenType.DashArrow, DrawArea.LineColor, DrawArea.LineWidth);
            int x = DrawArea.TheLayers.ActiveLayerIndex;
            int n = DrawArea.TheLayers[x].Graphics.SelectionCount;

            if (n > 0)
            {
                n = DrawArea.TheLayers[x].Graphics.Count;
                for (int i = 0; i < n; i++)
                {
                    if (DrawArea.TheLayers[x].Graphics[i].Selected == true)
                    {
                        DrawObject obj = DrawArea.TheLayers[x].Graphics[i];
                        obj.PenType = TypeOfPen.PenType.DashArrow;
                        obj.DrawPen = DrawArea.CurrentPen;
                        DrawArea.TheLayers[x].Graphics.Replace(i, obj);
                    }
                }
                DrawArea.Refresh();
            }
        }
Exemple #8
0
 public void Append(DrawObject obj)
 {
     graphicsList.Add(obj);
 }
Exemple #9
0
        /* --- Phương thức --- */
        public override void OnMouseDown(DrawArea drawArea, MouseEventArgs e)
        {
            commandChangeState = null;
            wasMove            = false;

            selectMode = SelectionMode.None;
            Point point = drawArea.BackTrackMouse(new Point(e.X, e.Y));

            // Kiểm tra có phải là đang resize
            int al = drawArea.TheLayers.ActiveLayerIndex;
            int n  = drawArea.TheLayers[al].Graphics.SelectionCount;

            for (int i = 0; i < n; i++)
            {
                DrawObject o            = drawArea.TheLayers[al].Graphics.GetSelectedObject(i);
                int        handleNumber = o.HitTest(point);

                if (handleNumber > 0)
                {
                    selectMode = SelectionMode.Size;
                    // Giữ đối tượng cần resize
                    resizedObject       = o;
                    resizedObjectHandle = handleNumber;
                    // Khi resize một đối tượng phải unselect các đối tượng khác
                    drawArea.TheLayers[al].Graphics.UnselectAll();
                    o.Selected         = true;
                    commandChangeState = new CommandChangeState(drawArea.TheLayers);
                    break;
                }
            }

            // Kiểm tra có phải là đang move
            if (selectMode == SelectionMode.None)
            {
                int        n1 = drawArea.TheLayers[al].Graphics.Count;
                DrawObject o  = null;

                for (int i = 0; i < n1; i++)
                {
                    if (drawArea.TheLayers[al].Graphics[i].HitTest(point) == 0)
                    {
                        o = drawArea.TheLayers[al].Graphics[i];
                        break;
                    }
                }

                if (o != null)
                {
                    selectMode = SelectionMode.Move;

                    // Unselect tất cả nếu Ctrl chưa nhấn và một đối tượng chưa được chọn
                    if ((Control.ModifierKeys & Keys.Control) == 0 &&
                        !o.Selected)
                    {
                        drawArea.TheLayers[al].Graphics.UnselectAll();
                    }

                    o.Selected         = true;
                    commandChangeState = new CommandChangeState(drawArea.TheLayers);
                    drawArea.Cursor    = Cursors.SizeAll;
                }
            }

            // Kiểm tra có phải là đang group selection
            if (selectMode == SelectionMode.None)
            {
                if ((Control.ModifierKeys & Keys.Control) == 0)
                {
                    drawArea.TheLayers[al].Graphics.UnselectAll();
                }

                selectMode = SelectionMode.NetSelection;
                drawArea.DrawNetRectangle = true;
            }

            lastPoint.X  = point.X;
            lastPoint.Y  = point.Y;
            startPoint.X = point.X;
            startPoint.Y = point.Y;

            drawArea.Capture      = true;
            drawArea.NetRectangle = DrawRectangle.GetNormalizedRectangle(startPoint, lastPoint);
            drawArea.Refresh();
        }