Esempio n. 1
0
        public override void Paint(Graphics g, IPaintContext paintContext)
        {
            if (null == _cachedLayerSegment) // _privLayer should be set before in FixupInternalDataStructures
            {
                PaintErrorInvalidLayerType(g, paintContext);
                return;
            }

            if (_background == null)
            {
                _axisStyle.Paint(g, paintContext, _cachedLayerSegment, _cachedLayerSegment.GetAxisStyleInformation);
            }
            else
            {
                // if we have a background, we paint in a dummy bitmap in order to measure all items
                // the real painting is done later on after painting the background.
                using (var bmp = new Bitmap(4, 4))
                {
                    using (var gg = Graphics.FromImage(bmp))
                    {
                        _axisStyle.Paint(gg, paintContext, _cachedLayerSegment, _cachedLayerSegment.GetAxisStyleInformation);
                    }
                }
            }

            _cachedPath = _axisStyle.AxisLineStyle.GetObjectPath(_cachedLayerSegment, true);

            // calculate size information
            RectangleD2D bounds1 = _cachedPath.GetBounds();

            if (_axisStyle.AreMinorLabelsEnabled)
            {
                var path = _axisStyle.MinorLabelStyle.GetSelectionPath();
                if (path.PointCount > 0)
                {
                    _cachedPath.AddPath(path, false);
                    RectangleD2D bounds2 = path.GetBounds();
                    bounds1.ExpandToInclude(bounds2);
                }
            }
            if (_axisStyle.AreMajorLabelsEnabled)
            {
                var path = _axisStyle.MajorLabelStyle.GetSelectionPath();
                if (path.PointCount > 0)
                {
                    _cachedPath.AddPath(path, false);
                    RectangleD2D bounds2 = path.GetBounds();
                    bounds1.ExpandToInclude(bounds2);
                }
            }

            ((ItemLocationDirectAutoSize)_location).SetSizeInAutoSizeMode(bounds1.Size, false); // size here is important only for selection, thus we set size silently

            if (_background != null)
            {
                bounds1.Expand(_backgroundPadding);
                _background.Draw(g, bounds1);
                _axisStyle.Paint(g, paintContext, _cachedLayerSegment, _cachedLayerSegment.GetAxisStyleInformation);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the bounds of the root layer.
        /// </summary>
        /// <returns></returns>
        private RectangleD2D GetBounds()
        {
            var s  = _rootLayer.Size;
            var p1 = _rootLayer.TransformCoordinatesFromHereToParent(new PointD2D(0, 0));
            var p2 = _rootLayer.TransformCoordinatesFromHereToParent(new PointD2D(s.X, 0));
            var p3 = _rootLayer.TransformCoordinatesFromHereToParent(new PointD2D(0, s.Y));
            var p4 = _rootLayer.TransformCoordinatesFromHereToParent(new PointD2D(s.X, s.Y));

            var r = new RectangleD2D(p1, PointD2D.Empty);

            r.ExpandToInclude(p2);
            r.ExpandToInclude(p3);
            r.ExpandToInclude(p4);
            return(r);
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the absolute enclosing rectangle, taking into account ScaleX, ScaleY, Rotation and Shear (SSRS).
        /// </summary>
        /// <returns>The enclosing rectangle in absolute values.</returns>
        public RectangleD2D GetAbsoluteEnclosingRectangle()
        {
            var m = new MatrixD2D();

            m.SetTranslationRotationShearxScale(AbsolutePivotPositionX, AbsolutePivotPositionY, -Rotation, ShearX, ScaleX, ScaleY);
            m.TranslatePrepend(AbsoluteVectorPivotToLeftUpper.X, AbsoluteVectorPivotToLeftUpper.Y);

            var s  = AbsoluteSize;
            var p1 = m.TransformPoint(new PointD2D(0, 0));
            var p2 = m.TransformPoint(new PointD2D(s.X, 0));
            var p3 = m.TransformPoint(new PointD2D(0, s.Y));
            var p4 = m.TransformPoint(new PointD2D(s.X, s.Y));

            var r = new RectangleD2D(p1, PointD2D.Empty);

            r.ExpandToInclude(p2);
            r.ExpandToInclude(p3);
            r.ExpandToInclude(p4);
            return(r);
        }
Esempio n. 4
0
        /// <summary>
        /// Adjusts the position and auto size of this group shape according to the contained elements. Must be called after changing any of the contained elements.
        /// </summary>
        public void AdjustPosition()
        {
            RectangleD2D bounds            = RectangleD2D.Empty;
            bool         boundsInitialized = false;

            foreach (var e in _groupedObjects)
            {
                var p1 = new PointD2D(0, 0);
                var p2 = new PointD2D(1, 0);
                var p3 = new PointD2D(0, 1);
                var p4 = new PointD2D(1, 1);

                p1 = e.RelativeLocalToAbsoluteParentCoordinates(p1);
                p2 = e.RelativeLocalToAbsoluteParentCoordinates(p2);
                p3 = e.RelativeLocalToAbsoluteParentCoordinates(p3);
                p4 = e.RelativeLocalToAbsoluteParentCoordinates(p4);

                if (boundsInitialized)
                {
                    bounds.ExpandToInclude(p1);
                }
                else
                {
                    bounds            = new RectangleD2D(p1.X, p1.Y, 0, 0);
                    boundsInitialized = true;
                }
                bounds.ExpandToInclude(p2);
                bounds.ExpandToInclude(p3);
                bounds.ExpandToInclude(p4);
            }

            if (bounds != Bounds)
            {
                // adjust position in this way that bounds.X and bounds.Y get zero
                var dx = bounds.X;
                var dy = bounds.Y;

                foreach (var e in _groupedObjects)
                {
                    e.ShiftPosition(-dx, -dy);
                }
                ShiftPosition(dx, dy);

                ((ItemLocationDirectAutoSize)_location).SetSizeInAutoSizeMode(bounds.Size, false);

                bounds.Location = new PointD2D(0, 0);
                UpdateTransformationMatrix();
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Handles the mouse move event.
        /// </summary>
        /// <param name="position">Mouse position.</param>
        /// <param name="e">MouseEventArgs as provided by the view.</param>
        /// <returns>The next mouse state handler that should handle mouse events.</returns>
        public override void OnMouseMove(PointD2D position, MouseEventArgs e)
        {
            base.OnMouseMove(position, e);

            if (null != ActiveGrip)
            {
                PointD2D graphCoord = _grac.ConvertMouseToRootLayerCoordinates(position);
                ActiveGrip.MoveGrip(graphCoord);
                _wereObjectsMoved = true;
                _grac.RenderOverlay();
            }
            else if (e.LeftButton == MouseButtonState.Pressed)
            {
                var diffPos = position - _positionLastMouseDownInMouseCoordinates;

                var oldRect = _rectangleSelectionArea_GraphCoordinates;

                if (null != _rectangleSelectionArea_GraphCoordinates ||
                    Math.Abs(diffPos.X) >= System.Windows.SystemParameters.MinimumHorizontalDragDistance ||
                    Math.Abs(diffPos.Y) >= System.Windows.SystemParameters.MinimumHorizontalDragDistance)
                {
                    if (null == _rectangleSelectionArea_GraphCoordinates)
                    {
                        (_grac.ViewObject as IGraphView).CaptureMouseOnCanvas();
                    }

                    var pt1  = _grac.ConvertMouseToRootLayerCoordinates(_positionLastMouseDownInMouseCoordinates);
                    var rect = new RectangleD2D(pt1, PointD2D.Empty);
                    rect.ExpandToInclude(_grac.ConvertMouseToRootLayerCoordinates(position));
                    _rectangleSelectionArea_GraphCoordinates = rect;
                }
                if (null != _rectangleSelectionArea_GraphCoordinates)
                {
                    _grac.RenderOverlay();
                }
            }
        }