Exemplo n.º 1
0
        public IDrawingObject Intersect(Point pos)
        {
            int x = this.From.X, y = this.From.Y;

            if (this.From.X > this.To.X)
            {
                x = this.To.X;
            }
            if (this.From.Y > this.To.Y)
            {
                y = this.To.Y;
            }

            if (pos.X > x && pos.X < x + Math.Abs(this.From.X - this.To.X) && pos.Y > y && pos.Y < y + Math.Abs(this.From.Y - this.To.Y))
            {
                return(this);
            }
            foreach (IDrawingObject obj in this.component)
            {
                IDrawingObject temp = obj.Intersect(pos);
                if (temp != null)
                {
                    return(this);
                }
            }
            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Process when draw is finish
        /// </summary>
        /// <param name="obj">The object.</param>
        public void CreateObject(IDrawingObject obj)
        {
            IAction action = null;

            if (obj.GetObjectType() == DrawingObjectType.Shape)
            {
                action = new CreateShapeAction((ShapeBase)obj);
            }
            else if (obj.GetObjectType() == DrawingObjectType.Text)
            {
                var text = obj as TextObject;
                if (text != null)
                {
                    action = new UpdateTextControlAction()
                    {
                        Text     = "",
                        Font     = text.Font,
                        Location = text.Location
                    }
                }
                ;
            }

            SendAction(action);

            if (obj.GetObjectType() == DrawingObjectType.Text)
            {
                action = new CreateTextAction((TextObject)obj);
                SendAction(action);
            }

            _page.AddDrawingObject(obj);
        }
Exemplo n.º 3
0
 private void buttonDrawFigure_Click(object sender, EventArgs e)
 {
     if (radioButtonSquare.Checked)
     {
         figure = new DrawingSquare(x, y, currentcolor);
     }
     if (radioButtonCircle.Checked)
     {
         figure = new DrawingCircle(x, y, currentcolor);
     }
     if (radioButtonRhombus.Checked)
     {
         figure = new DrawingRhombus(x, y, currentcolor);
     }
     if (radioButtonTriangle.Checked)
     {
         figure = new DrawingTriangle(x, y, currentcolor);
     }
     if (radioButtonRectangle.Checked)
     {
         figure = new DrawingRectangle(x, y, currentcolor);
     }
     g.Push(figure);
     x += 30;
     panel1.Invalidate();
 }
Exemplo n.º 4
0
        public static IDrawingObject ReadDrawingObject(BinaryReader reader)
        {
            // read object type
            IDrawingObject obj  = null;
            int            type = reader.ReadInt32();

            switch ((DrawingObjectType)type)
            {
            case DrawingObjectType.Shape:
            {
                // read shape type
                int       shapeType = reader.ReadInt32();
                ShapeBase shape;

                if ((ShapeType)shapeType == ShapeType.Ellipse)
                {
                    shape = new Ellipse();
                }
                else
                {
                    shape = new FreePencil();
                }
                //var shape = ShapeFactory.CreateShape((ShapeType) shapeType);
                // write shape location
                shape.Location = ReadPoint(reader);
                // write shape size
                shape.Size = ReadSize(reader);
                // write shape outline color
                shape.OutlineColor = ReadColor(reader);
                // write shape outline width
                shape.OutlineWidth = reader.ReadSingle();
                // write shape outline dash
                shape.OutlineDash = (DashStyle)reader.ReadInt32();
                // write shape fill color
                shape.FillColor = ReadColor(reader);

                if (shape.GetShapeType() != ShapeType.Ellipse)
                {
                    // write count vertex
                    var vcount = reader.ReadInt32();
                    for (int i = 0; i < vcount; i++)
                    {
                        Vertex v = ReadVertex(reader);
                        shape.Vertices.Add(v);
                    }
                }

                if (shape.GetShapeType() == ShapeType.Polygon || shape.GetShapeType() == ShapeType.Oblong ||
                    shape.GetShapeType() == ShapeType.IsoscelesTriangle)
                {
                    var s = shape as PolygonBase;
                    s.IsClosedFigure = true;
                }
            }
            break;
            }

            return(obj);
        }
Exemplo n.º 5
0
 private void ChangeThickness(IDrawingObject drawingObject, MouseWheelEventArgs e)
 {
     if (drawingObject is IHasThickness)
     {
         IHasThickness tl = drawingObject as IHasThickness;
         tl.Thickness += e.Delta / 120;
     }
 }
        /// <summary>
        /// Adds an object to the specified layer
        /// </summary>
        /// <param name="layerName">the layer on which to add the object</param>
        /// <param name="page">the page on which the object was created</param>
        /// <param name="drawingObject">the drawing-object to add on the given page</param>
        void IInternalDocument.AddLayerObject(string layerName, Page page, IDrawingObject drawingObject)
        {
            Layer layer = layers.First(n => n.LayerName == layerName);

            layer.Objects.Add(new LayerObject {
                Layer = layer, Page = page, Object = drawingObject
            });
        }
Exemplo n.º 7
0
        public Shape()
        {
            IDrawingObject drawingObject = this;

            drawingObject.OnDraw += DrawingObject_OnDraw;
            IShape shapeObject = this;

            shapeObject.OnDraw += shapeObject_OnDraw;
        }
Exemplo n.º 8
0
        public override void Add(IDrawingObject item)
        {
            base.Add(item);

            if (this.owner.Worksheet != null)
            {
                this.owner.Worksheet.RequestInvalidate();
            }
        }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            IDrawingObject[] instances = new IDrawingObject[] { new Line(), new Rectangle(), new Line() };

            foreach (IDrawingObject item in instances)
            {
                item.Draw();
            }
        }
Exemplo n.º 10
0
        public static void Draw(this IDrawingObject obj, Canvas c)
        {
            string className = obj.GetType().ToString();

            if (methodMap.ContainsKey(className))
            {
                methodMap[className](obj, c);
            }
        }
Exemplo n.º 11
0
        public virtual void Draw(this IDrawingObject p, ICanvas g)
        {
            Polygon poly = p as Polygon;

            if (poly == null)
            {
                return;
            }
            g.DrawPolygon(poly.Points, poly.Fill);
        }
Exemplo n.º 12
0
 public void AddObject(IDrawingObject target, string layerName)
 {
     if (layerName == null)
     {
         objects.Add(target);
     }
     else
     {
         parent.AddLayerObject(layerName, this, target);
     }
 }
Exemplo n.º 13
0
        public override bool Remove(IDrawingObject item)
        {
            bool ret = base.Remove(item);

            if (ret && this.owner.Worksheet != null)
            {
                this.owner.Worksheet.RequestInvalidate();
            }

            return(ret);
        }
Exemplo n.º 14
0
 public void OnMouseDown(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         IDrawingObject obj = this.canvas.SelectObjectAt(e.Location);
         if (obj != null)
         {
             this.cp.ActiveColor = obj.ActiveColor;
         }
     }
 }
Exemplo n.º 15
0
        public static void Main()
        {
            IDrawingObject[] instances = new IDrawingObject[] { new Line(), new Rectangle() }; // 다형성 구현

            foreach (IDrawingObject item in instances)                                         // 각 요소에 접근하여 값을 메소드 호출
            {
                item.Draw();
            }

            IDrawingObject instance = new Line();   // 여기도 다형성

            instance.Draw();
        }
Exemplo n.º 16
0
        private void BeginDrawingObject(MouseButtonEventArgs e)
        {
            Vector mousePos = (Vector)e.GetPosition(MainImageContainer);

            switch (currentlyPressedButton.Name)
            {
            case "DrawLineButon":
                ILine line = new ClippedLine((Vector)e.GetPosition(MainImageContainer), (Vector)e.GetPosition(MainImageContainer), 2, CurrentColor, ClipRectangles);
                currentlyDrawnObject = line;
                DrawingObjects.Add(currentlyDrawnObject);
                currentlyDrawnPoint = line.Point2;
                break;

            case "DrawCircleButton":
                MidpointCircle circle = new MidpointCircle((Vector)e.GetPosition(MainImageContainer), (Vector)e.GetPosition(MainImageContainer), CurrentColor);
                currentlyDrawnObject = circle;
                DrawingObjects.Add(currentlyDrawnObject);
                currentlyDrawnPoint = circle.radiusUtilityPoint;
                break;

            case "DrawPolygonButton":
                Polygon poly = new FilledPolygon(CurrentColor, 2, ClipRectangles, (Vector)e.GetPosition(MainImageContainer), (Vector)e.GetPosition(MainImageContainer));
                currentlyDrawnObject = poly;
                DrawingObjects.Add(currentlyDrawnObject);
                currentlyDrawnPoint = poly.Points[1];
                break;

            case "DrawCapsuleButton":
                Capsule cap = new Capsule(mousePos, mousePos, 0, CurrentColor);
                currentlyDrawnObject = cap;
                DrawingObjects.Add(currentlyDrawnObject);
                currentlyDrawnPoint = cap.Point2;
                break;

            case "DrawRectangleButton":
                DrawingRectangle rec = new DrawingRectangle(CurrentColor, 2, mousePos, mousePos);
                currentlyDrawnObject = rec;
                DrawingObjects.Add(currentlyDrawnObject);
                currentlyDrawnPoint = rec.Points[2];
                break;

            case "FloodFillButton":
                FloodFill fill = new FloodFill(mousePos, CurrentColor);
                DrawingObjects.Add(fill);
                currentState = UIState.PreparingToDraw;
                break;

            default:
                throw new NotImplementedException();
            }
        }
Exemplo n.º 17
0
        static void Main(string[] args)
        {
            IDrawingObject[] instances = new IDrawingObject[] { new Line(), new Rectangle() };

            foreach (IDrawingObject item in instances)
            {
                item.Draw();    // 인터페이스를 상속받은 객체의 Draw 메서드가 호출됨.
            }

            // 자식 클래스로부터 암시적 형변환 가능
            IDrawingObject instance = new Line();

            instance.Draw();
        }
Exemplo n.º 18
0
        static void Main(string[] args)
        {
            //ㅇ인터페이스 자체는 new 로 인스턴스화 할 수 없지만 인터페이스 배열은 가능하다.
            IDrawingObject[] instances = new IDrawingObject[] { new Line(), new Rectangle() };

            foreach (IDrawingObject item in instances)
            {
                item.Draw(); //인터페이스를 상속받은 개체의 Draw메서드가 호출됨.
            }

            //자식 클래스로부터 암시적 형변환 가능
            IDrawingObject instance = new Line();

            instance.Draw();
        }
Exemplo n.º 19
0
        public IDrawingObject SelectObjectAt(Point pos)
        {
            IDrawingObject selected = null;

            foreach (IDrawingObject obj in ObjectToDraw)
            {
                selected = obj.Intersect(pos);
                if (selected != null)
                {
                    selected.Select();
                    break;
                }
            }
            return(selected);
        }
Exemplo n.º 20
0
 public void OnMouseDown(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         IDrawingObject temp = this.TargetCanvas.SelectObjectAt(e.Location);
         if (temp != null && temp.ObjName != "LineCon")
         {
             Console.WriteLine(temp.ObjName);
             lineConnector = new LineConnector()
             {
                 A  = temp,
                 To = e.Location
             };
             this.TargetCanvas.AddDrawingObject(lineConnector);
             temp.Deselect();
         }
     }
 }
Exemplo n.º 21
0
 public void OnMouseDown(object sender, MouseEventArgs e)
 {
     this.StateLeftMouseDown = true;
     if (StateShiftDown)
     {
         IDrawingObject temp = this.TargetCanvas.SelectObjectAt(e.Location);
         if (temp != null)
         {
             if (this.targetObj.Contains(temp))
             {
                 this.targetObj.Remove(temp);
                 temp.Deselect();
             }
             else
             {
                 this.targetObj.Add(temp);
                 lastPoint = e.Location;
             }
         }
         else
         {
             foreach (IDrawingObject obj in this.targetObj)
             {
                 obj.Deselect();
             }
             this.targetObj.Clear();
         }
     }
     else
     {
         foreach (IDrawingObject obj in this.targetObj)
         {
             obj.Deselect();
         }
         this.targetObj.Clear();
         IDrawingObject temp = this.TargetCanvas.SelectObjectAt(e.Location);
         if (temp != null)
         {
             this.targetObj.Add(temp);
             lastPoint = e.Location;
         }
     }
 }
Exemplo n.º 22
0
        private void CancelDrawingObject()
        {
            if (currentlyDrawnObject != null)
            {
                if (currentlyDrawnObject is Polygon && (currentlyDrawnObject as Polygon).Points.Count > 2)
                {
                    currentlyDrawnPoint = null;
                    (currentlyDrawnObject as Polygon).RemoveLastPoint();
                    currentlyDrawnObject = null;
                }
                else
                {
                    DrawingObjects.Remove(currentlyDrawnObject);
                    currentlyDrawnObject = null;
                    currentlyDrawnPoint  = null;
                }

                UpdateMainImage();
            }
        }
Exemplo n.º 23
0
        public static void SaveDrawingObject(BinaryWriter writer, IDrawingObject obj)
        {
            var type = (Int32)obj.GetObjectType();

            // write object type
            writer.Write(type);

            switch (obj.GetObjectType())
            {
            case DrawingObjectType.Shape:
            {
                var shape     = (ShapeBase)obj;
                var shapeType = shape.GetShapeType();
                // write shape type
                writer.Write((Int32)shapeType);
                // write shape location
                WritePoint(writer, shape.Location);
                // write shape size
                WriteSize(writer, shape.Size);
                // write shape outline color
                WriteColor(writer, shape.OutlineColor);
                // write shape outline width
                writer.Write(shape.OutlineWidth);
                // write shape outline dash
                writer.Write((Int32)shape.OutlineDash);
                // write shape fill color
                WriteColor(writer, shape.FillColor);

                if (shapeType != ShapeType.Ellipse)
                {
                    // write count vertex
                    writer.Write((Int32)shape.Vertices.Count);
                    foreach (var vertex in shape.Vertices)
                    {
                        WriteVertex(writer, vertex);
                    }
                }
            }
            break;
            }
        }
Exemplo n.º 24
0
        public void OnMouseUp(object sender, MouseEventArgs e)
        {
            if (lineConnector != null)
            {
                IDrawingObject temp = this.TargetCanvas.SelectObjectAt(e.Location);
                if (temp == null)
                {
                    this.TargetCanvas.RemoveDrawingObject(lineConnector);
                }
                else
                {
                    lineConnector.B = temp;
                    lineConnector.B = temp;

                    lineConnector.Deselect();
                    this.TargetCanvas.RemoveDrawingObject(lineConnector);
                    this.TargetCanvas.AddDrawingObjectAt(0, lineConnector);
                    lineConnector = null;
                }
            }
        }
Exemplo n.º 25
0
 public static void Draw(IDrawingObject p, Canvas c)
 {
     c.DrawPoint(p as Point);
 }
Exemplo n.º 26
0
 public void AddObject(string key, IDrawingObject o)
 {
     ObjectList.Add(key, o);
 }
Exemplo n.º 27
0
 public AddedObjectEventArgs(IDrawingObject obj)
 {
     _object = obj;
 }
Exemplo n.º 28
0
 public void AddNew(IDrawingObject drawingObject)
 {
     drawingObject.Left = _drawingObjects.Sum(x => x.Width);
     _drawingObjects.Add(drawingObject);
 }
Exemplo n.º 29
0
        public static void SaveDrawingObject(BinaryWriter writer, IDrawingObject obj)
        {
            var type = (Int32)obj.GetObjectType();
            // write object type
            writer.Write(type);

            switch (obj.GetObjectType())
            {
                case DrawingObjectType.Shape:
                {
                    var shape = (ShapeBase) obj;
                    var shapeType = shape.GetShapeType();
                    // write shape type
                    writer.Write((Int32) shapeType);
                    // write shape location
                    WritePoint(writer, shape.Location);
                    // write shape size
                    WriteSize(writer, shape.Size);
                    // write shape outline color
                    WriteColor(writer, shape.OutlineColor);
                    // write shape outline width
                    writer.Write(shape.OutlineWidth);
                    // write shape outline dash
                    writer.Write((Int32) shape.OutlineDash);
                    // write shape fill color
                    WriteColor(writer, shape.FillColor);

                    if (shapeType != ShapeType.Ellipse)
                    {
                        // write count vertex
                        writer.Write((Int32)shape.Vertices.Count);
                        foreach (var vertex in shape.Vertices)
                            WriteVertex(writer, vertex);
                    }
                }
                    break;
            }
        }
Exemplo n.º 30
0
        public Subscriber1(Shape sh)
        {
            IDrawingObject drawObj = (IDrawingObject)sh;

            drawObj.OnDraw += OnDraw;
        }
Exemplo n.º 31
0
 public void AddObject(IDrawingObject o)
 {
     ObjectList.Add(_nextId++.ToString("D10"), o);
 }
Exemplo n.º 32
0
 public void AddDrawingObject(IDrawingObject item)
 {
     _drawingObjects.Add(item);
 }
Exemplo n.º 33
0
        // References the shape object as an IDrawingObject
        public Subscriber1(Shape shape)
        {
            IDrawingObject d = (IDrawingObject)shape;

            d.OnDraw += d_OnDraw;
        }
Exemplo n.º 34
0
            public Subscriber1(shape shape)
            {
                IDrawingObject d = shape;

                d.onDrawn += d_OnDraw;
            }