コード例 #1
0
ファイル: GraphObj.cs プロジェクト: sntree/ZedGraph
        /// <summary>
        /// Update location of object according given x/y offset
        /// </summary>
        /// <param name="_pane"></param>
        /// <param name="dx">x offset in screen</param>
        /// <param name="dy">y offset in screen</param>
        virtual public void UpdateLocation(PaneBase _pane, float dx, float dy)
        {
            GraphPane pane = _pane as GraphPane;

            // convert location to screen coordinate
            PointF ptPix1 = pane.GeneralTransform(_location.X1, _location.Y1,
                                                  _location.CoordinateFrame);

            PointF ptPix2 = pane.GeneralTransform(_location.X2, _location.Y2,
                                                  _location.CoordinateFrame);

            // calc new position
            ptPix1.X += (float)dx;
            ptPix1.Y += (float)dy;

            ptPix2.X += (float)dx;
            ptPix2.Y += (float)dy;

            // convert to user coordinate
            PointD pt1 = pane.GeneralReverseTransform(ptPix1, _location.CoordinateFrame);
            PointD pt2 = pane.GeneralReverseTransform(ptPix2, _location.CoordinateFrame);

            _location.X      = pt1.X;
            _location.Y      = pt1.Y;
            _location.Width  = pt2.X - pt1.X;
            _location.Height = pt2.Y - pt1.Y;

            OnLocationChanged(pane, dx, dy);
        }
コード例 #2
0
ファイル: PolyObj.cs プロジェクト: 15835229565/ZedGraph-3
        override public void ResizeEdge(int edge, PointF pt, PaneBase pane)
        {
            // when edge is int.MaxValue, we assume it is last point
            if (edge == int.MaxValue)
            {
                edge = _points.Count - 1;
            }

            // do nothing if edge is invalid
            if (edge < 0 || edge >= _points.Count)
            {
                return;
            }

            GraphPane gPane = pane as GraphPane;

            PointD ptPix = gPane.GeneralReverseTransform(
                pt.X,
                pt.Y, _location.CoordinateFrame);

            _points[edge] = ptPix;
        }
コード例 #3
0
ファイル: PolyObj.cs プロジェクト: 15835229565/ZedGraph-3
        public override void UpdateLocation(PaneBase _pane, float dx, float dy)
        {
            GraphPane pane = _pane as GraphPane;

            // update each points
            for (int i = 0; i < _points.Count; i++)
            {
                // convert location to screen coordinate
                PointF ptPix1 = pane.GeneralTransform(_points[i].X, _points[i].Y,
                                                      _location.CoordinateFrame);

                // calc new position
                ptPix1.X += (float)dx;
                ptPix1.Y += (float)dy;

                // convert to user coordinate
                PointD pt1 = pane.GeneralReverseTransform(ptPix1, _location.CoordinateFrame);

                _points[i] = pt1;
            }

            OnLocationChanged(pane, dx, dy);
        }
コード例 #4
0
        override public void ResizeEdge(int edge, PointF pt, PaneBase pane)
        {
            // set edget to right-bottom edge when edget is -1
            if (edge == int.MaxValue)
            {
                edge = 1;
            }

            /** sample code
             * // convert location to screen coordinate
             * PointF ptPix1 = pane.GeneralTransform(obj.Location.X1, obj.Location.Y1,
             *      obj.Location.CoordinateFrame);
             *
             * PointF ptPix2 = pane.GeneralTransform(obj.Location.X2, obj.Location.Y2,
             *      obj.Location.CoordinateFrame);
             *
             * // calc new position
             * ptPix1.X += (mousePt.X - _dragStartPt.X);
             * ptPix1.Y += (mousePt.Y - _dragStartPt.Y);
             *
             * ptPix2.X += (mousePt.X - _dragStartPt.X);
             * ptPix2.Y += (mousePt.Y - _dragStartPt.Y);
             *
             * // convert to user coordinate
             * PointD pt1 = pane.GeneralReverseTransform(ptPix1, obj.Location.CoordinateFrame);
             * PointD pt2 = pane.GeneralReverseTransform(ptPix2, obj.Location.CoordinateFrame);
             *
             * obj.Location.X = pt1.X;
             * obj.Location.Y = pt1.Y;
             * obj.Location.Width = pt2.X - pt1.X;
             * obj.Location.Height = pt2.Y - pt1.Y;
             */
            GraphPane gPane = pane as GraphPane;

            switch (edge)
            {
            case 0: // resize left
            case 1: // resize right
            {
                PointF o = Center(gPane);

                double ds    = Utils.Distance(pt.Y - o.Y, pt.X - o.X);
                double angle = Utils.AngleInDegree(pt.Y - o.Y, pt.X - o.X);

                if (ds > 0.01)
                {
                    //_location.X = (o.X - ds) / pane.Rect.Width;
                    //_location.Width = ds * 2 / pane.Rect.Width;

                    PointD pt1 = gPane.GeneralReverseTransform((float)(o.X - ds), 0,
                                                               _location.CoordinateFrame);
                    PointD pt2 = gPane.GeneralReverseTransform((float)(o.X + ds), 0,
                                                               _location.CoordinateFrame);

                    _location.X     = pt1.X;
                    _location.Width = pt2.X - pt1.X;
                }

                Angle = (float)angle;
            }
            break;

            case 2: // resize top
            case 3: // resize bottom
            {
                PointF o  = Center(pane);
                double ds = Utils.Distance(pt.Y - o.Y, pt.X - o.X);

                if (ds > 0.01)
                {
                    //_location.Y = (o.Y - ds) / pane.Rect.Height;
                    //_location.Height = ds * 2 / pane.Rect.Height;

                    PointD pt1 = gPane.GeneralReverseTransform(0, (float)(o.Y - ds),
                                                               _location.CoordinateFrame);
                    PointD pt2 = gPane.GeneralReverseTransform(0, (float)(o.Y + ds),
                                                               _location.CoordinateFrame);

                    _location.Y      = pt1.Y;
                    _location.Height = pt2.Y - pt1.Y;
                }
            }
            break;
            }
        }
コード例 #5
0
ファイル: BoxObj.cs プロジェクト: 15835229565/ZedGraph-3
        override public void ResizeEdge(int edge, PointF pt, PaneBase pane)
        {
            // set edget to right-bottom edge when edget is -1
            if (edge == int.MaxValue)
            {
                edge = 4;
            }

            // do nothing if edge is invalid
            if (edge < 0 || edge > 8)
            {
                return;
            }

            RectangleF[] edges = EdgeRects(pane);
            //RectangleF s = edges[edge];

            GraphPane gPane = pane as GraphPane;

            // convert location to screen coordinate
            PointF ptPix1 = gPane.GeneralTransform(_location.X1, _location.Y1,
                                                   _location.CoordinateFrame);

            PointF ptPix2 = gPane.GeneralTransform(_location.X2, _location.Y2,
                                                   _location.CoordinateFrame);

            /*
             * // calc new position
             * ptPix1.X += (mousePt.X - _dragStartPt.X);
             * ptPix1.Y += (mousePt.Y - _dragStartPt.Y);
             *
             * ptPix2.X += (mousePt.X - _dragStartPt.X);
             * ptPix2.Y += (mousePt.Y - _dragStartPt.Y);
             *
             * // convert to user coordinate
             * PointD pt1 = pane.GeneralReverseTransform(ptPix1, obj.Location.CoordinateFrame);
             * PointD pt2 = pane.GeneralReverseTransform(ptPix2, obj.Location.CoordinateFrame);
             *
             * obj.Location.X = pt1.X;
             * obj.Location.Y = pt1.Y;
             * obj.Location.Width = pt2.X - pt1.X;
             * obj.Location.Height = pt2.Y - pt1.Y;
             */

            //float dx = (pt.X - s.X) / pane.Rect.Width;
            //float dy = (pt.Y - s.Y) / pane.Rect.Height;

            //float dx = (pt.X - s.X - 2) ;
            //float dy = (pt.Y - s.Y - 2) ;

            /*
             * 0       1       2
             +---------------+
             |               |
             | 7 |               | 3
             |               |
             +---------------+
             | 6       5       4
             */

            switch (edge)
            {
            case 0:
                //_location.X += dx;
                //_location.Y += dy;
                //_location.Width -= dx;
                //_location.Height -= dy;

                // calc new position
                //ptPix1.X += dx;
                //ptPix1.Y += dy;
                ptPix1.X = pt.X;
                ptPix1.Y = pt.Y;
                break;

            case 1:
                //_location.Y += dy;
                //_location.Height -= dy;

                // calc new position
                //ptPix1.Y += dy;
                ptPix1.Y = pt.Y;
                break;

            case 2:
                //_location.Y += dy;
                //_location.Width += dx;
                //_location.Height -= dy;

                // calc new position
                //ptPix1.Y += dy;
                //ptPix2.X += dx;
                ptPix1.Y = pt.Y;
                ptPix2.X = pt.X;
                break;

            case 3:
                //_location.Width += dx;

                // calc new position
                //ptPix2.X += dx;
                ptPix2.X = pt.X;
                break;

            case 4:
                //_location.Width += dx;
                //_location.Height += dy;

                // calc new position
                //ptPix2.X += dx;
                //ptPix2.Y += dy;
                ptPix2.X = pt.X;
                ptPix2.Y = pt.Y;
                break;

            case 5:
                //_location.Height += dy;

                // calc new position
                //ptPix2.Y += dy;
                ptPix2.Y = pt.Y;
                break;

            case 6:
                //_location.X += dx;
                //_location.Width -= dx;
                //_location.Height += dy;

                // calc new position
                //ptPix1.X += dx;
                //ptPix2.Y += dy;
                ptPix1.X = pt.X;
                ptPix2.Y = pt.Y;
                break;

            case 7:
                //_location.X += dx;
                //_location.Width -= dx;

                // calc new position
                //ptPix1.X += dx;
                ptPix1.X = pt.X;
                break;
            }

            //System.Diagnostics.Debug.WriteLine(string.Format("resize edget {4} pt1 {0}  pt2 {1}  s {2}  pt {3}  ",
            //    ptPix1, ptPix2, s, pt, edge));


            // convert to user space coordinate
            PointD pt1 = gPane.GeneralReverseTransform(ptPix1, _location.CoordinateFrame);
            PointD pt2 = gPane.GeneralReverseTransform(ptPix2, _location.CoordinateFrame);

            _location.X      = pt1.X;
            _location.Y      = pt1.Y;
            _location.Width  = pt2.X - pt1.X;
            _location.Height = pt2.Y - pt1.Y;
        }