Exemple #1
0
        /// <summary>
        /// 維護 undo stack ,把目前狀態存起來.並清空redo stack,如果之前有undo 動作,是回覆到某一狀態,在此之後的動作都可清除
        /// </summary>
        /// <param name="Data"></param>
        /// <param name="Action"></param>
        public void writeIn(gPath Data, int Action)
        {
            saveState pa;

            int lens = RedoStack.Count;

            RedoStack.Clear();
            FullList.RemoveRange(FullList.Count - lens, lens);



            if (Action == 0)//新增動作
            {
                gPath g = new gPath();
                //等一下會加入到list 中,所以count 正好為其在list  所在的位置
                pa = new saveState(Action, sroot.PathList.Count, (FullList.Count));

                UndoStack.Push(pa);
                g.copyVal(Data);
                FullList.Add(Data);
                sroot.PathList.Add(g);
            }
            else  //修改動作(物件已存在)
            {
                pa = new saveState(Action, Data.ListPlace, FullList.Count);
                FullList.Add(Data);
                UndoStack.Push(pa);
            }
        }
Exemple #2
0
        /// <summary>
        /// 重作到目前狀態
        ///
        /// </summary>
        public void reDo()
        {
            if (RedoStack.Count > 0)
            {
                gPath     tempPath = new gPath();
                saveState tempPA;

                tempPA = (saveState)RedoStack.Pop();

                if (tempPA.currSate >= 0 && tempPA.currSate < FullList.Count)
                {
                    tempPath.copyVal(FullList[tempPA.currSate]);


                    if (tempPA.Action == 0)
                    {
                        sroot.PathList[tempPA.GraphIndex].IsDelete = false;
                    }

                    sroot.PathList[tempPA.GraphIndex] = tempPath;
                    sroot.PathList[tempPA.GraphIndex].redraw(1);
                }
                else
                {
                    // sroot.PathList.RemoveAt(tempPA.GraphIndex);
                }
                UndoStack.Push(tempPA);
            }
        }
Exemple #3
0
        public override void DrawShape(gView gv, gPath data, Boolean bfirst)
        {
            if (bfirst)
            {
                shapeLib.Data.Status = "rest";
                shapeLib.Data.bfirst = false;
                Path p = buildShape(data);

                r = data.state.colorR;
                g = data.state.colorG;
                b = data.state.colorB;

                p.Stroke          = new SolidColorBrush(System.Windows.Media.Color.FromRgb(r, g, b));
                p.StrokeThickness = shapeLib.Data.strokeT;
                // p.StrokeEndLineCap = PenLineCap.Round;
                // p.StrokeStartLineCap = PenLineCap.Flat;
                shapeLib.Data.mygrid.Children.Add(p);
                gv.baseShape.Add(p);

                Debug.WriteLine("draw pencil");
            }
            else
            {
                Path myLine = (Path)gv.baseShape[0];

                buildShape(data, myLine);
            }


            //shapeLib.Data.mygrid.MouseDown += new System.Windows.Input.MouseButtonEventHandler(LeftButtonDown);
        }
Exemple #4
0
 public override void DisplayControlPoints(gView gv, gPath data)
 {
     if (gv.controlShape.Count == 0)
     {
         Rectangle myRect = new Rectangle();
         myRect.Stroke = new SolidColorBrush(System.Windows.Media.Color.FromRgb(255, 0, 0));
         myRect.Width  = Math.Abs(data.controlBtn4.X - data.controlBtn1.X);
         myRect.Height = Math.Abs(data.controlBtn4.Y - data.controlBtn1.Y);
         myRect.Margin = new Thickness(data.controlBtn1.X, data.controlBtn1.Y, 0, 0);
         myRect.HorizontalAlignment  = System.Windows.HorizontalAlignment.Left;
         myRect.VerticalAlignment    = VerticalAlignment.Center;
         myRect.StrokeThickness      = shapeLib.Data.strokeT;
         myRect.MouseLeftButtonDown += data.myLine_MouseLeftButtonDown;
         myRect.MouseEnter          += data.myLine_MouseEnter;
         myRect.MouseLeave          += data.myLine_MouseLeave;
         shapeLib.Data.mygrid.Children.Add(myRect);
         gv.controlShape.Add(myRect);
     }
     else
     {
         Rectangle myRect = (Rectangle)gv.controlShape[0];
         myRect.Width  = Math.Abs(data.controlBtn4.X - data.controlBtn1.X);
         myRect.Height = Math.Abs(data.controlBtn4.Y - data.controlBtn1.Y);
         myRect.Margin = new Thickness(data.controlBtn1.X, data.controlBtn1.Y, 0, 0);
     }
 }
Exemple #5
0
        public override void DisplayControlPoints(gView gv, gPath data)
        {
            if (gv.controlShape.Count == 0)
            {
                Polyline myTri = new Polyline();

                //        //如果要繪製中心顏色,可開啟這段
                myTri.Stroke = new SolidColorBrush(System.Windows.Media.Color.FromRgb(255, 255, 0));
                PointCollection Points = new PointCollection();
                Points.Add(new System.Windows.Point(data.controlBtn1.X + (data.controlBtn4.X - data.controlBtn1.X) / 2, data.controlBtn1.Y));
                Points.Add(new System.Windows.Point(data.controlBtn1.X, data.controlBtn4.Y));
                Points.Add(new System.Windows.Point(data.controlBtn4.X, data.controlBtn4.Y));
                Points.Add(new System.Windows.Point(data.controlBtn1.X + (data.controlBtn4.X - data.controlBtn1.X) / 2, data.controlBtn1.Y));
                myTri.Points = new PointCollection(Points);
                myTri.HorizontalAlignment  = System.Windows.HorizontalAlignment.Left;
                myTri.VerticalAlignment    = VerticalAlignment.Center;
                myTri.StrokeThickness      = shapeLib.Data.strokeT;
                myTri.MouseLeftButtonDown += data.myLine_MouseLeftButtonDown;
                myTri.MouseEnter          += data.myLine_MouseEnter;
                myTri.MouseLeave          += data.myLine_MouseLeave;
                shapeLib.Data.mygrid.Children.Add(myTri);
                gv.controlShape.Add(myTri);
            }

            else
            {
                Polyline        myTri  = (Polyline)gv.controlShape[0];// =(Line) currPath.getDrawShape();
                PointCollection Points = new PointCollection();
                Points.Add(new System.Windows.Point(data.controlBtn1.X + (data.controlBtn4.X - data.controlBtn1.X) / 2, data.controlBtn1.Y));
                Points.Add(new System.Windows.Point(data.controlBtn1.X, data.controlBtn4.Y));
                Points.Add(new System.Windows.Point(data.controlBtn4.X, data.controlBtn4.Y));
                Points.Add(new System.Windows.Point(data.controlBtn1.X + (data.controlBtn4.X - data.controlBtn1.X) / 2, data.controlBtn1.Y));
                myTri.Points = new PointCollection(Points);
            }
        }
Exemple #6
0
        public override void DrawShape(gView gv, gPath data, Boolean bfirst)
        {
            if (bfirst)
            {
                shapeLib.Data.Status = "rest";
                shapeLib.Data.bfirst = false;

                Rectangle myRect = new Rectangle();

                //如果要繪製中心顏色,可開啟這段
                myRect.Stroke = new SolidColorBrush(System.Windows.Media.Color.FromRgb(data.state.colorR, data.state.colorG, data.state.colorB));
                myRect.Width  = Math.Abs(data.controlBtn4.X - data.controlBtn1.X);
                myRect.Height = Math.Abs(data.controlBtn4.Y - data.controlBtn1.Y);
                myRect.Margin = new Thickness(data.controlBtn1.X, data.controlBtn1.Y, 0, 0);
                myRect.HorizontalAlignment  = System.Windows.HorizontalAlignment.Left;
                myRect.VerticalAlignment    = VerticalAlignment.Center;
                myRect.MouseLeftButtonDown += data.myLine_MouseLeftButtonDown;
                myRect.MouseEnter          += data.myLine_MouseEnter;
                myRect.MouseLeave          += data.myLine_MouseLeave;
                myRect.StrokeThickness      = shapeLib.Data.strokeT;
                myRect.MouseLeftButtonDown += data.myLine_MouseLeftButtonDown;
                shapeLib.Data.mygrid.Children.Add(myRect);
                gv.baseShape.Add(myRect);
            }
            else
            {
                Rectangle myRect = (Rectangle)gv.baseShape[0];// =(Line) currPath.getDrawShape();
                myRect.Width  = Math.Abs(data.controlBtn4.X - data.controlBtn1.X);
                myRect.Height = Math.Abs(data.controlBtn4.Y - data.controlBtn1.Y);
                myRect.Margin = new Thickness(data.controlBtn1.X, data.controlBtn1.Y, 0, 0);
            }


            //   throw new NotImplementedException();
        }
Exemple #7
0
        public override void MouseDownInsert(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (e.ChangedButton == MouseButton.Right)
            // if (e.RightButton == System.Windows.Input.MouseButtonState.Pressed)
            {
                shapeLib.Data.gdc.writeIn(currPath, 0);
                shapeLib.Data.gdc.Release();
                shapeLib.Data.mClick = 0;
                return;
            }


            Canvas mygrid = shapeLib.Data.mygrid;

            shapeLib.Data.pStart = e.GetPosition(mygrid);

            if (shapeLib.Data.mClick == 0)
            {
                currPath          = new gPath();
                currPath.drawtype = shapeLib.SupportedShape(null).IndexOf(this);
                currPath.pList.Add(shapeLib.Data.pStart);
            }
            shapeLib.Data.tempStart = shapeLib.Data.pStart;
            shapeLib.Data.bCanMove  = true;
        }
Exemple #8
0
        public virtual void DisplayControlPoints(gView gv, gPath data)
        {
            if (gv.controlShape.Count == 0)
            {
                Line myLine = new Line();
                myLine.Stroke = new SolidColorBrush(System.Windows.Media.Color.FromRgb(0, 255, 0));
                myLine.X1     = data.controlBtn1.X;
                myLine.Y1     = data.controlBtn1.Y;
                myLine.X2     = data.controlBtn4.X;
                myLine.Y2     = data.controlBtn4.Y;
                myLine.HorizontalAlignment  = System.Windows.HorizontalAlignment.Left;
                myLine.VerticalAlignment    = VerticalAlignment.Center;
                myLine.StrokeThickness      = shapeLib.Data.strokeT;
                myLine.MouseLeftButtonDown += data.myLine_MouseLeftButtonDown;
                myLine.MouseEnter          += data.myLine_MouseEnter;
                myLine.MouseLeave          += data.myLine_MouseLeave;
                shapeLib.Data.mygrid.Children.Add(myLine);
                gv.controlShape.Add(myLine);
            }
            else
            {
                Line myLine = (Line)gv.controlShape[0];// =(Line) currPath.getDrawShape();

                myLine.X1 = data.controlBtn1.X;
                myLine.Y1 = data.controlBtn1.Y;
                myLine.X2 = data.controlBtn4.X;
                myLine.Y2 = data.controlBtn4.Y;
            }


            // throw new NotImplementedException();
        }
Exemple #9
0
        public bool checkHitCurve(String Data, gPath p)
        {
            bool tf = true;

            String[] tmpStr    = Data.Split(',');
            double[] tmpDouStr = new double[tmpStr.Length];
            for (int i = 0; i < tmpStr.Length; i++)
            {
                tmpDouStr[i] = Convert.ToDouble(tmpStr[i]);
            }
            System.Windows.Point tmpPoint0 = new System.Windows.Point(tmpDouStr[0], tmpDouStr[1]);
            System.Windows.Point tmpPoint1 = new System.Windows.Point(tmpDouStr[2], tmpDouStr[3]);
            System.Windows.Point tmpPoint2 = new System.Windows.Point(tmpDouStr[4], tmpDouStr[5]);
            System.Windows.Point tmpPoint3 = new System.Windows.Point(tmpDouStr[6], tmpDouStr[7]);

            if (!tmpPoint0.Equals(p.controlBtn1))
            {
                tf = false;
            }
            if (!tmpPoint1.Equals(p.controlBtn2))
            {
                tf = false;
            }
            if (!tmpPoint2.Equals(p.controlBtn3))
            {
                tf = false;
            }
            if (!tmpPoint3.Equals(p.controlBtn4))
            {
                tf = false;
            }
            return(tf);
        }
Exemple #10
0
        public override void DrawShape(gView gv, gPath data, Boolean bfirst)
        {
            if (bfirst)
            {
                shapeLib.Data.Status = "rest";
                shapeLib.Data.bfirst = false;

                Shape myEllipse;
                if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
                {
                    Path            mypath = new Path();
                    EllipseGeometry mye    = new EllipseGeometry();
                    mye.Center  = data.controlBtn1;
                    mypath.Data = mye;


                    myEllipse = mypath;
                }
                else
                {
                    myEllipse = new Ellipse();
                    // Create a SolidColorBrush with a red color to fill the
                    // Ellipse with.

                    // Set the width and height of the Ellipse.
                    myEllipse.Width  = Math.Abs(data.controlBtn4.X - data.controlBtn1.X);
                    myEllipse.Height = Math.Abs(data.controlBtn4.Y - data.controlBtn1.Y);
                    myEllipse.Margin = new Thickness(data.controlBtn1.X, data.controlBtn1.Y, 0, 0);
                }

                myEllipse.Stroke = new SolidColorBrush(Color.FromRgb(data.state.colorR, data.state.colorG, data.state.colorB));
                myEllipse.MouseLeftButtonDown += data.myLine_MouseLeftButtonDown;
                myEllipse.MouseEnter          += data.myLine_MouseEnter;
                myEllipse.MouseLeave          += data.myLine_MouseLeave;
                shapeLib.Data.mygrid.Children.Add(myEllipse);
                gv.baseShape.Add(myEllipse);
            }
            else
            {
                Shape myEllipse = (Shape)gv.baseShape[0];

                if (myEllipse is Ellipse)
                {
                    myEllipse.Width  = Math.Abs(data.controlBtn4.X - data.controlBtn1.X);
                    myEllipse.Height = Math.Abs(data.controlBtn4.Y - data.controlBtn1.Y);
                    myEllipse.Margin = new Thickness(data.controlBtn1.X, data.controlBtn1.Y, 0, 0);
                }
                else
                {
                    Path            myp  = (Path)gv.baseShape[0];
                    EllipseGeometry myre = (EllipseGeometry)myp.Data;
                    myre.RadiusX = Math.Abs(data.controlBtn4.X - data.controlBtn1.X);
                    myre.RadiusY = Math.Abs(data.controlBtn4.Y - data.controlBtn1.Y);
                }
            }
        }
Exemple #11
0
        public virtual void MouseDownInsert(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            Canvas mygrid = shapeLib.Data.mygrid;

            shapeLib.Data.pStart = correctPoint(e.GetPosition(mygrid));

            if ((this.GetType() != typeof(ShapeCurve) && this.GetType() != typeof(ShapePencil)) || shapeLib.Data.mClick == 0)
            {
                currPath          = new gPath();
                currPath.drawtype = shapeLib.SupportedShape(null).IndexOf(this);
            }
            shapeLib.Data.tempStart = shapeLib.Data.pStart;
            shapeLib.Data.bCanMove  = true;
        }
Exemple #12
0
        public bool checkHitCenter(System.Windows.Point downPlace, gPath p)
        {
            bool tf = true;

            if (downPlace.X > p.controlBtn2.X || downPlace.X < p.controlBtn1.X)
            {
                tf = false;
            }
            if (downPlace.Y > p.controlBtn4.Y || downPlace.Y < p.controlBtn1.Y)
            {
                tf = false;
            }
            return(tf);
        }
Exemple #13
0
        /// <summary>
        /// undo 回到前一狀態
        /// </summary>
        public void unDo()
        {
            //檢查是否有可undo 的事件
            if (UndoStack.Count > 0)
            {
                gPath     tempPath = new gPath();
                saveState tempPA;
                shapeLib.Data.mClick = 0;

                tempPA = (saveState)UndoStack.Pop();

                if (tempPA.currSate >= 0 && tempPA.currSate < FullList.Count)
                {
                    if (tempPA.Action == 0)
                    {
                        sroot.PathList[tempPA.GraphIndex].IsDelete = true;
                    }
                    else
                    {
                        //找出前一個state
                        int i;
                        for (i = tempPA.currSate - 1; i >= 0; i--)
                        {
                            if (FullList[i].ListPlace == tempPA.GraphIndex)
                            {
                                tempPath.copyVal(FullList[i]);
                                sroot.PathList[tempPA.GraphIndex] = tempPath;
                                sroot.PathList[tempPA.GraphIndex].redraw(1);
                                break;
                            }
                        }
                        if (i < 0) //something wrong
                        {
                            Debug.WriteLine("something wrong");
                        }
                    }
                }
                else
                {
                    //something wrong
                    Debug.WriteLine("something wrong");

                    //sroot.PathList.RemoveAt(tempPA.GraphIndex);
                }
                //將該事件放入redo stack
                RedoStack.Push(tempPA);
            }
        }
Exemple #14
0
        public bool checkHitLine(System.Windows.Point downPlace, gPath p)
        {
            bool   tf = false;
            double m  = (p.controlBtn4.Y - p.controlBtn1.Y) / (p.controlBtn4.X - p.controlBtn1.X);
            double xm = (downPlace.Y - p.controlBtn1.Y) / m + p.controlBtn1.X;
            double ym = (downPlace.X - p.controlBtn1.X) * m + p.controlBtn1.Y;

            if (downPlace.X >= xm - 3 && downPlace.X <= xm + 3)
            {
                tf = true;
            }
            if (downPlace.Y >= ym - 3 && downPlace.Y <= ym + 3)
            {
                tf = true;
            }
            return(tf);
        }
Exemple #15
0
        public void copyVal(gPath obj)
        {
            drawtype   = obj.drawtype;
            state      = obj.state;
            ListPlace  = obj.ListPlace;
            shapeIndex = obj.shapeIndex;

            controlBtn1 = obj.controlBtn1;
            controlBtn2 = obj.controlBtn2;
            controlBtn3 = obj.controlBtn3;
            controlBtn4 = obj.controlBtn4;

            foreach (Point p in obj.pList)
            {
                pList.Add(p);
            }
        }
Exemple #16
0
        public override void DrawShape(gView gv, gPath data, Boolean bfirst)
        {
            if (bfirst)
            {
                shapeLib.Data.Status = "rest";
                shapeLib.Data.bfirst = false;

                Polygon myTri = new Polygon();

                //        //如果要繪製中心顏色,可開啟這段
                SolidColorBrush mySolidColorBrush = new SolidColorBrush();
                myTri.Stroke = new SolidColorBrush(System.Windows.Media.Color.FromRgb(data.state.colorR, data.state.colorG, data.state.colorB));
                PointCollection Points = new PointCollection();
                Points.Add(data.controlBtn1);
                Points.Add(data.controlBtn3);
                Points.Add(data.controlBtn4);
                // Points.Add(data.controlBtn1);


                myTri.Points = new PointCollection(Points);
                myTri.HorizontalAlignment  = System.Windows.HorizontalAlignment.Left;
                myTri.VerticalAlignment    = VerticalAlignment.Center;
                myTri.StrokeThickness      = shapeLib.Data.strokeT;
                myTri.MouseLeftButtonDown += data.myLine_MouseLeftButtonDown;
                myTri.MouseEnter          += data.myLine_MouseEnter;
                myTri.MouseLeave          += data.myLine_MouseLeave;
                shapeLib.Data.mygrid.Children.Add(myTri);
                gv.baseShape.Add(myTri);
            }
            else
            {
                Polygon         myTri  = (Polygon)gv.baseShape[0];// =(Line) currPath.getDrawShape();
                PointCollection Points = new PointCollection();
                Points.Add(data.controlBtn1);
                Points.Add(data.controlBtn3);
                Points.Add(data.controlBtn4);
                //   Points.Add(data.controlBtn1);
                myTri.Points = new PointCollection(Points);
            }


            //   throw new NotImplementedException();
        }
Exemple #17
0
        public override void DrawShape(gView gv, gPath data, Boolean bfirst)
        {
            if (bfirst)
            {
                shapeLib.Data.Status = "rest";
                shapeLib.Data.bfirst = false;
                BezierSegment bezier = new BezierSegment();
                bezier.Point3 = data.controlBtn3;
                PathFigure figure = new PathFigure();
                figure.StartPoint = data.controlBtn1;
                bezier.Point1     = figure.StartPoint;
                bezier.Point2     = bezier.Point3;
                figure.Segments.Add(bezier);
                PathGeometry geometry = new PathGeometry();
                geometry.Figures.Add(figure);
                Path            myPath            = new System.Windows.Shapes.Path();
                SolidColorBrush mySolidColorBrush = new SolidColorBrush();
                // Describes the brush's color using RGB values.
                // Each value has a range of 0-255.

                myPath.Stroke          = new SolidColorBrush(Color.FromRgb(data.state.colorR, data.state.colorG, data.state.colorB));
                myPath.StrokeThickness = data.state.strokeT;

                /*myPath.MouseLeftButtonDown += data.myLine_MouseLeftButtonDown;
                 * myPath.MouseEnter += data.myLine_MouseEnter;
                 * myPath.MouseLeave += data.myLine_MouseLeave; */
                myPath.Data = geometry;
                shapeLib.Data.mygrid.Children.Add(myPath);
                gv.baseShape.Add(myPath);
            }
            else
            {
                Path         myPath   = (Path)gv.baseShape[0];// =(Line) currPath.getDrawShape();
                PathGeometry geometry = (PathGeometry)myPath.Data;
                geometry.Figures[0].StartPoint = data.controlBtn1;
                BezierSegment bs = (BezierSegment)geometry.Figures[0].Segments[0];
                bs.Point1 = data.controlBtn2;
                bs.Point2 = data.controlBtn3;
                bs.Point3 = data.controlBtn4;
            }
        }
Exemple #18
0
        public int checkWhich(gPath gp)
        {
            int whichOne = -1;

            for (int i = sroot.PathList.Count - 1; i >= 0; i--)
            {
                if (gp.drawtype < 3 || gp.drawtype == 4)
                {
                    if (sroot.PathList[i].controlBtn1 != gp.controlBtn1)
                    {
                        continue;
                    }
                    if (sroot.PathList[i].controlBtn2 != gp.controlBtn2)
                    {
                        continue;
                    }
                    if (sroot.PathList[i].controlBtn3 != gp.controlBtn3)
                    {
                        continue;
                    }
                    if (sroot.PathList[i].controlBtn4 != gp.controlBtn4)
                    {
                        continue;
                    }
                }
                if (gp.drawtype == 3)
                {
                    if (sroot.PathList[i].controlBtn1 != gp.controlBtn1)
                    {
                        continue;
                    }
                    if (sroot.PathList[i].controlBtn4 != gp.controlBtn4)
                    {
                        continue;
                    }
                }
                whichOne = i;
            }
            return(whichOne);
        }
Exemple #19
0
        public int checkHitCorner(System.Windows.Point downPlace, gPath p)
        {
            int Node = -1;

            if ((downPlace.X >= p.controlBtn1.X - 4) && (downPlace.X <= p.controlBtn1.X + 4) && (downPlace.Y >= p.controlBtn1.Y - 4) && (downPlace.Y <= p.controlBtn1.Y + 4))
            {
                Node = 0;
            }
            if ((downPlace.X >= p.controlBtn2.X - 4) && (downPlace.X <= p.controlBtn2.X + 4) && (downPlace.Y >= p.controlBtn2.Y - 4) && (downPlace.Y <= p.controlBtn2.Y + 4))
            {
                Node = 1;
            }
            if ((downPlace.X >= p.controlBtn3.X - 4) && (downPlace.X <= p.controlBtn3.X + 4) && (downPlace.Y >= p.controlBtn3.Y - 4) && (downPlace.Y <= p.controlBtn3.Y + 4))
            {
                Node = 2;
            }
            if ((downPlace.X >= p.controlBtn4.X - 4) && (downPlace.X <= p.controlBtn4.X + 4) && (downPlace.Y >= p.controlBtn4.Y - 4) && (downPlace.Y <= p.controlBtn4.Y + 4))
            {
                Node = 3;
            }
            return(Node);
        }
Exemple #20
0
        //依data 繪製,如果是第一次畫要新建shape, 更新的話只要更新最後一點
        public virtual void DrawShape(gView gv, gPath data, Boolean bfirst)
        {
            if (bfirst)
            {
                shapeLib.Data.Status = "rest";
                shapeLib.Data.bfirst = false;

                Line myLine = new Line();
                myLine.Stroke = new SolidColorBrush(System.Windows.Media.Color.FromRgb(data.state.colorR, data.state.colorG, data.state.colorB));

                myLine.X1 = data.controlBtn1.X;
                myLine.Y1 = data.controlBtn1.Y;
                myLine.X2 = data.controlBtn4.X;
                myLine.Y2 = data.controlBtn4.Y;
                myLine.HorizontalAlignment  = System.Windows.HorizontalAlignment.Left;
                myLine.VerticalAlignment    = VerticalAlignment.Center;
                myLine.StrokeThickness      = shapeLib.Data.strokeT;
                myLine.MouseLeftButtonDown += data.myLine_MouseLeftButtonDown;
                myLine.MouseEnter          += data.myLine_MouseEnter;
                myLine.MouseLeave          += data.myLine_MouseLeave;
                shapeLib.Data.mygrid.Children.Add(myLine);
                gv.baseShape.Add(myLine);
                // currPath.setDrawShape( myLine);
            }
            else
            {
                Line myLine = (Line)gv.baseShape[0];// =(Line) currPath.getDrawShape();

                myLine.X1 = data.controlBtn1.X;
                myLine.Y1 = data.controlBtn1.Y;


                myLine.X2 = data.controlBtn4.X;
                myLine.Y2 = data.controlBtn4.Y;
            }


            //   throw new NotImplementedException();
        }
Exemple #21
0
        //public void RightButtonDown(object sender, MouseButtonEventArgs e)
        //{
        //    shapeLib.Data.mygrid.Children.Remove(textBox);

        //}

        public override void DrawShape(gView gv, gPath data, Boolean bfirst)
        {
            if (bfirst)
            {
                shapeLib.Data.Status = "rest";
                shapeLib.Data.bfirst = false;

                if (txt == null)
                {
                    x = data.controlBtn1.X;
                    y = data.controlBtn1.Y;
                    r = data.state.colorR;
                    g = data.state.colorG;
                    b = data.state.colorB;
                    textBox.Foreground = new SolidColorBrush(System.Windows.Media.Color.FromRgb(r, g, b));
                    Canvas.SetLeft(textBox, x);
                    Canvas.SetTop(textBox, y);
                    textBox.FontSize = 10 + shapeLib.Data.strokeT * 4;
                    shapeLib.Data.mygrid.Children.Add(textBox);
                    textBox.Focus();
                    textBox.AcceptsReturn = true;
                    textBox.AcceptsTab    = true;
                    txt  = textBox.Text;
                    last = false;
                    // shapeLib.Data.mygrid.MouseDown += this.MouseDownInsert;
                    //new System.Windows.Input.MouseButtonEventHandler(LeftButtonDown);
                }
                else if (!last)
                {
                    txt = null;
                    textBox.Focus();
                }
            }
            else
            {
                txt = null;
            }
        }
Exemple #22
0
        public override void DisplayControlPoints(gView gv, gPath data)
        {
            if (gv.controlShape.Count == 0)
            {
                BezierSegment bezier = new BezierSegment();
                bezier.Point3 = data.controlBtn3;
                PathFigure figure = new PathFigure();
                figure.StartPoint = data.controlBtn1;
                bezier.Point1     = figure.StartPoint;
                bezier.Point2     = bezier.Point3;
                figure.Segments.Add(bezier);
                PathGeometry geometry = new PathGeometry();
                geometry.Figures.Add(figure);
                Path myPath = new System.Windows.Shapes.Path();
                myPath.Stroke          = new SolidColorBrush(System.Windows.Media.Color.FromRgb(255, 0, 255));
                myPath.StrokeThickness = data.state.strokeT;

                /* myPath.MouseLeftButtonDown += data.myLine_MouseLeftButtonDown;
                 * myPath.MouseEnter += data.myLine_MouseEnter;
                 * myPath.MouseLeave += data.myLine_MouseLeave;  */
                myPath.Data = geometry;
                shapeLib.Data.mygrid.Children.Add(myPath);
                gv.controlShape.Add(myPath);
            }

            else
            {
                Path         myPath   = (Path)gv.controlShape[0];// =(Line) currPath.getDrawShape();
                PathGeometry geometry = (PathGeometry)myPath.Data;
                geometry.Figures[0].StartPoint = data.controlBtn1;
                BezierSegment bs = (BezierSegment)geometry.Figures[0].Segments[0];
                bs.Point1 = data.controlBtn2;
                bs.Point2 = data.controlBtn3;
                bs.Point3 = data.controlBtn4;
            }
        }
Exemple #23
0
        public override void DrawShape(gView gv, gPath data, Boolean bfirst)
        {
            if (bfirst)
            {
                shapeLib.Data.Status = "rest";
                shapeLib.Data.bfirst = false;

                double num1   = Math.Atan2((data.controlBtn4.X - data.controlBtn1.X), (data.controlBtn4.Y - data.controlBtn1.Y));
                double num2   = 0.5;
                double num3   = 6.0;
                Point  point1 = new Point();
                Point  point2 = new Point();
                Point  point3 = new Point();
                point1.X = data.controlBtn4.X - ((num3 * Math.Sin(num1 - num2)));
                point1.Y = data.controlBtn4.Y - ((num3 * Math.Cos(num1 - num2)));
                point2.X = data.controlBtn4.X - ((num3 * Math.Sin(num1 + num2)));
                point2.Y = data.controlBtn4.Y - ((num3 * Math.Cos(num1 + num2)));
                point3.X = point1.X - (point1.X - point2.X) / 2;
                point3.Y = point1.Y - (point1.Y - point2.Y) / 2;
                Polyline myArr = new Polyline();

                //        //如果要繪製中心顏色,可開啟這段

                myArr.Stroke = new SolidColorBrush(System.Windows.Media.Color.FromRgb(data.state.colorR, data.state.colorG, data.state.colorB));
                //myArr.Width = Math.Abs(data.controlBtn4.X - data.controlBtn1.X);
                //myArr.Height = Math.Abs(data.controlBtn4.Y - data.controlBtn1.Y);
                PointCollection Points = new PointCollection();

                Points.Add(data.controlBtn1);
                Points.Add(point3);
                Points.Add(point1);
                Points.Add(data.controlBtn4);
                Points.Add(point2);
                Points.Add(point3);


                myArr.Points = new PointCollection(Points);
                //  myArr.Margin = new Thickness(data.controlBtn1.X, data.controlBtn1.Y, 0, 0);
                myArr.HorizontalAlignment  = System.Windows.HorizontalAlignment.Left;
                myArr.VerticalAlignment    = VerticalAlignment.Center;
                myArr.StrokeThickness      = shapeLib.Data.strokeT;
                myArr.MouseLeftButtonDown += data.myLine_MouseLeftButtonDown;
                myArr.MouseEnter          += data.myLine_MouseEnter;
                myArr.MouseLeave          += data.myLine_MouseLeave;
                //   myLine.MouseEnter += data.myLine_MouseEnter;
                //   myLine.MouseLeave += data.myLine_MouseLeave;
                shapeLib.Data.mygrid.Children.Add(myArr);
                gv.baseShape.Add(myArr);
                // currPath.setDrawShape( myArr);
            }
            else
            {
                Polyline        myArr  = (Polyline)gv.baseShape[0];// =(Line) currPath.getDrawShape();
                PointCollection Points = new PointCollection();
                double          num1   = Math.Atan2((data.controlBtn4.X - data.controlBtn1.X), (data.controlBtn4.Y - data.controlBtn1.Y));
                double          num2   = 0.5;
                double          num3   = 6.0;
                Point           point1 = new Point();
                Point           point2 = new Point();
                Point           point3 = new Point();
                point1.X = data.controlBtn4.X - ((num3 * Math.Sin(num1 - num2)));
                point1.Y = data.controlBtn4.Y - ((num3 * Math.Cos(num1 - num2)));
                point2.X = data.controlBtn4.X - ((num3 * Math.Sin(num1 + num2)));
                point2.Y = data.controlBtn4.Y - ((num3 * Math.Cos(num1 + num2)));
                point3.X = point1.X - (point1.X - point2.X) / 2;
                point3.Y = point1.Y - (point1.Y - point2.Y) / 2;

                Points.Add(data.controlBtn1);
                Points.Add(point3);
                Points.Add(point1);
                Points.Add(data.controlBtn4);
                Points.Add(point2);
                Points.Add(point3);
                myArr.Points = new PointCollection(Points);
                // myLine.Margin = new Thickness(data.controlBtn1.X, data.controlBtn1.Y, 0, 0);
            }
        }
Exemple #24
0
        public override void DrawShape(gView gv, gPath data, Boolean bfirst)
        {
            if (count == 0)
            {
                myarr[3] = data.controlBtn1;
                Path         myPath   = new System.Windows.Shapes.Path();
                PathGeometry geometry = (PathGeometry)myPath.Data;
                shapeLib.Data.mygrid.Children.Add(myPath);
                gv.baseShape.Add(myPath);
                count++;
            }
            else
            {
                if (bfirst)
                {
                    shapeLib.Data.Status = "rest";
                    shapeLib.Data.bfirst = false;
                    BezierSegment bezier = new BezierSegment();
                    PathFigure    figure = new PathFigure();



                    for (int a = 0; a < 4; a++)
                    {
                        if ((3 - a) > 0)
                        {
                            myarr[2 - a] = myarr[3 - a];
                        }
                        else
                        {
                            myarr[a] = data.controlBtn1;
                        }
                    }

                    for (int i = 0; i < m - 3; i++)
                    {
                        if (i == m - 4)
                        {
                            extra = 1;
                        }
                        else
                        {
                            extra = 0;
                        }
                        for (int j = 0; j < MAX_STEPS + extra; j++)
                        {
                            double u  = j / MAX_STEPS;
                            double Qx = B0(u) * myarr[i].X +
                                        B1(u) * myarr[i + 1].X +
                                        B2(u) * myarr[i + 2].X +
                                        B3(u) * myarr[i + 3].X;

                            double Qy = B0(u) * myarr[i].Y +
                                        B1(u) * myarr[i + 1].Y +
                                        B2(u) * myarr[i + 2].Y +
                                        B3(u) * myarr[i + 3].Y;

                            myarr[i].X = Qx;
                            myarr[i].Y = Qy;
                        }
                    }
                    //figure.StartPoint = myarr[0];
                    //bezier.Point1 = myarr[1];
                    //bezier.Point2 = data.controlBtn4;
                    //bezier.Point3 = myarr[3];

                    figure.Segments.Add(bezier);
                    PathGeometry geometry = new PathGeometry();
                    geometry.Figures.Add(figure);

                    //myPath.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(curve_MouseLeftButtonDown);
                    SolidColorBrush mySolidColorBrush = new SolidColorBrush();
                    // Describes the brush's color using RGB values.
                    // Each value has a range of 0-255.

                    Path myPath = new System.Windows.Shapes.Path();
                    myPath.Stroke          = new SolidColorBrush(Color.FromRgb(data.state.colorR, data.state.colorG, data.state.colorB));
                    myPath.StrokeThickness = data.state.strokeT;

                    /*myPath.MouseLeftButtonDown += data.myLine_MouseLeftButtonDown;
                     * myPath.MouseEnter += data.myLine_MouseEnter;
                     * myPath.MouseLeave += data.myLine_MouseLeave; */
                    myPath.Data = geometry;
                    shapeLib.Data.mygrid.Children.Add(myPath);
                    gv.baseShape.Add(myPath);
                }
                else
                {
                    Path         myPath   = (Path)gv.baseShape[0];// =(Line) currPath.getDrawShape();
                    PathGeometry geometry = (PathGeometry)myPath.Data;
                    if (geometry != null)
                    {
                        BezierSegment bs = (BezierSegment)geometry.Figures[0].Segments[0];

                        geometry.Figures[0].StartPoint = myarr[0];
                        bs.Point1 = myarr[1];
                        bs.Point2 = data.controlBtn4;
                        bs.Point3 = myarr[3];
                    }
                }
            }
        }
Exemple #25
0
        private Path buildShape(gPath data, Path old = null)
        {
            Path ret = old;

            if (old == null)
            {
                ret = new Path();
            }
            int m = data.pList.Count;

            Point[] plist = new Point[m + 3];
            data.pList.CopyTo(plist, 1);
            plist[0]     = plist[1];
            plist[m + 1] = plist[m + 2] = data.controlBtn4;
            m            = m + 3;

            int MAX_STEPS = 10;

            PathFigure myPathFigure = new PathFigure();


            PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();

            myPathFigure.Segments = myPathSegmentCollection;

            PathFigureCollection myPathFigureCollection = new PathFigureCollection();

            myPathFigureCollection.Add(myPathFigure);

            PathGeometry myPathGeometry = new PathGeometry();

            myPathGeometry.Figures = myPathFigureCollection;

            ret.Data = myPathGeometry;

            bool bstart = true;

            for (int i = 0; i < m - 3; i++)
            {
                Point p  = (Point)plist[i];
                Point p1 = (Point)plist[i + 1];
                Point p2 = (Point)plist[i + 2];
                Point p3 = (Point)plist[i + 3];


                if (i == m - 4)
                {
                    extra = 1;
                }

                // sx = p.X;
                // sy = p.Y;

                for (int j = 0; j < MAX_STEPS + extra; j++)
                {
                    double u  = j * 1.0 / MAX_STEPS;
                    double Qx = B0(u) * p.X +
                                B1(u) * p1.X +
                                B2(u) * p2.X +
                                B3(u) * p3.X;

                    double Qy = B0(u) * p.Y +
                                B1(u) * p1.Y +
                                B2(u) * p2.Y +
                                B3(u) * p3.Y;

                    if (bstart)
                    {
                        bstart = false;
                        myPathFigure.StartPoint = new System.Windows.Point((int)Qx, (int)Qy);
                    }
                    else
                    {
                        LineSegment lineseg = new LineSegment();
                        lineseg.Point = new System.Windows.Point((int)Qx, (int)Qy);
                        myPathSegmentCollection.Add(lineseg);
                    }
                }
            }

            return(ret);
        }