Example #1
0
        private RectangleF GetAbsoluteGdiRectangleF <TRectangle>(TRectangle relativeRect)
            where TRectangle : IRectangle
        {
            var absRect = _boxModel.GetAbsoluteRect(relativeRect, ZoomLevel);

            return(GdiTypeConverter.GetRect(absRect));
        }
        public override ValueSize MeasureString(String s, IFont font)
        {
            var useFont = GdiTypeConverter.GetFont(font);
            var sz      = Graphics.MeasureString(s, useFont);

            return(new ValueSize(sz.Width, sz.Height));
        }
Example #3
0
        public override IPoint2D GetOffset(IPoint2D input)
        {
            var point = GdiTypeConverter.GetPoint(input);

            point = PointToClient(point);
            return(GdiTypeConverter.GetPoint(point));
        }
Example #4
0
        protected override void PushClip <TRectangle>(TRectangle rect)
        {
            _clipCounter++;
            var useRect = GdiTypeConverter.GetRect(rect);

            Graphics.SetClip(useRect);
        }
Example #5
0
        private Rectangle GetAbsoluteGdiRectangle(
            IRectangle relativeRect)
        {
            var absRect = _boxModel.GetAbsoluteRect(relativeRect, ZoomLevel);

            return(GdiTypeConverter.GetRect(absRect));
        }
Example #6
0
        public override void FillRectangle <TRectangle, TBrush>(TRectangle rect,
                                                                TBrush brush)
        {
            var useRect  = GetAbsoluteGdiRectangle(rect);
            var useBrush = GdiTypeConverter.GetBrush(brush);

            Graphics.FillRectangle(useBrush, useRect);
        }
Example #7
0
        public override void DrawRect <TRectangle, TPen>(TRectangle rect,
                                                         TPen pen)
        {
            var useRect = GetAbsoluteGdiRectangle(rect);
            var usePen  = GdiTypeConverter.GetPen(pen);

            Graphics.DrawRectangle(usePen, useRect);
        }
Example #8
0
        public override void DrawLine <TPen, TPoint1, TPoint2>(TPen pen,
                                                               TPoint1 pt1,
                                                               TPoint2 pt2)
        {
            var usePen = GdiTypeConverter.GetPen(pen);
            var l1     = GetAbsoluteGdiPoint(pt1);
            var l2     = GetAbsoluteGdiPoint(pt2);

            Graphics.DrawLine(usePen, l1, l2);
        }
Example #9
0
        public override void DrawLines(IPen pen, IPoint2D[] points)
        {
            var usePen  = GdiTypeConverter.GetPen(pen);
            var gPoints = new PointF[points.Length];

            for (var c = 0; c < points.Length; c++)
            {
                gPoints[c] = GetAbsoluteGdiPoint(points[c]);
            }

            Graphics.DrawLines(usePen, gPoints);
        }
Example #10
0
        public override void DrawEllipse <TPoint, TPen>(TPoint center,
                                                        Double radius,
                                                        TPen pen)
        {
            var c = _boxModel.GetAbsolutePoint(center, ZoomLevel);

            var usePen = GdiTypeConverter.GetPen(pen);
            var asRect = new Rectangle(Convert.ToInt32(c.X - radius),
                                       Convert.ToInt32(c.Y - radius),
                                       Convert.ToInt32(radius * 2), Convert.ToInt32(radius * 2));

            Graphics.DrawEllipse(usePen, asRect);
        }
Example #11
0
        public override void DrawString <TFont, TBrush, TRectangle>(String s,
                                                                    TFont font,
                                                                    TRectangle location,
                                                                    TBrush brush)
        {
            var rect = GetAbsoluteGdiRectangle(location);

            var useBrush = GdiTypeConverter.GetBrush(brush);
            var useFont  = GdiTypeConverter.GetFont(font);

            Graphics.DrawString(s, useFont, useBrush, rect, StringFormat.GenericDefault);
            // text renderer doesn't wrap the text
            //TextRenderer.DrawText(Graphics, s, useFont, rect, color);
        }
Example #12
0
        public ViewWindow Show <TRectangle>(IView view,
                                            TRectangle rect)
            where TRectangle : IRectangle
        {
            //var styleContext = view.StyleContext;

            var control = new GdiHostedElement(view);
            var form    = new ViewWindow(control);

            Cook(form);

            form.Bounds = GdiTypeConverter.GetRect(rect);

            WindowShown?.Invoke(form);

            return(form);
        }
Example #13
0
        public override void DrawString <TFont, TBrush, TPoint>(String s,
                                                                TFont font,
                                                                TBrush brush,
                                                                TPoint location)
        {
            var loc = GetAbsoluteGdiPoint(location);

            if (!(brush is SolidColorBrush scb))
            {
                throw new NotSupportedException(nameof(DrawString) +
                                                " - " + brush);
            }

            var color   = GdiTypeConverter.GetColor(scb.Color);
            var useFont = GdiTypeConverter.GetFont(font);

            TextRenderer.DrawText(Graphics, s, useFont, loc, color,
                                  TextFormatFlags.PreserveGraphicsClipping);
        }
Example #14
0
        public override void DrawRoundedRect <TRectangle, TPen, TThickness>(TRectangle rect,
                                                                            TPen pen,
                                                                            TThickness cornerRadii)
        {
            if (cornerRadii.IsEmpty)
            {
                DrawRect(rect, pen);
                return;
            }

            var useRect = _boxModel.GetAbsoluteRect(rect, ZoomLevel);
            var usePen  = GdiTypeConverter.GetPen(pen);

            using (var path = new GdiGraphicsPath())
            {
                path.SetRoundedRectangle(useRect, cornerRadii);
                Graphics.DrawPath(usePen, path.Path);
            }
        }
Example #15
0
        public override void FillPie <TPoint, TBrush>(TPoint center,
                                                      Double radius,
                                                      Double startAngle,
                                                      Double endAngle,
                                                      TBrush brush)
        {
            var c = _boxModel.GetAbsolutePoint(center, ZoomLevel);

            var useBrush = GdiTypeConverter.GetBrush(brush);
            var asRect   = new RectangleF((Single)(c.X - radius), (Single)(c.Y - radius),
                                          (Single)radius * 2, (Single)radius * 2);

            if (asRect.Width <= 0 || asRect.Height <= 0)
            {
                return;
            }

            Graphics.FillPie(useBrush, asRect.X, asRect.Y, asRect.Width, asRect.Height,
                             (Single)startAngle, (Single)(endAngle - startAngle));
        }
Example #16
0
        public override void FillRoundedRectangle <TRectangle, TBrush, TThickness>(TRectangle rect,
                                                                                   TBrush brush,
                                                                                   TThickness cornerRadii)
        {
            if (cornerRadii.IsEmpty)
            {
                FillRectangle(rect, brush);
                return;
            }

            var useRect = _boxModel.GetAbsoluteRect(rect, ZoomLevel);

            var useBrush = GdiTypeConverter.GetBrush(brush);

            using (var path = new GdiGraphicsPath())
            {
                path.SetRoundedRectangle(useRect, cornerRadii);
                Graphics.FillPath(useBrush, path.Path);
            }
        }
Example #17
0
        public ViewWindow Show(IView view)
        {
            //var styleContext = view.StyleContext;

            var control = new GdiHostedElement(view);
            var form    = new ViewWindow(control);

            Cook(form);

            var viewWidth  = view.Width ?? 0;
            var viewHeight = view.Height ?? 0;

            if (viewWidth.IsNotZero() && viewHeight.IsNotZero())
            {
                form.Size = GdiTypeConverter.GetSize(viewWidth, viewHeight);
            }

            WindowShown?.Invoke(form);

            return(form);
        }