Пример #1
0
        protected override WSize ArrangeOverride(global::Windows.Foundation.Size finalSize)
        {
            var myRect = new WRect(0, 0, finalSize.Width, finalSize.Height);

            if (Control != null)
            {
                Control.Arrange(myRect);
            }

            var mauiContext = Element?.Handler?.MauiContext;

            if (Element is not IVisualTreeElement vte || mauiContext == null)
            {
                return(finalSize);
            }

            var mauiRect = new Graphics.Rect(0, 0, finalSize.Width, finalSize.Height);

            foreach (var child in vte.GetVisualChildren())
            {
                if (child is Maui.IElement childElement && childElement.Handler is IPlatformViewHandler nvh)
                {
                    nvh.PlatformArrangeHandler(mauiRect);
                }
            }

            return(finalSize);
        }
Пример #2
0
        internal static void UpdatePath(this Path borderPath, IShape?borderShape, double width, double height)
        {
            if (borderShape == null)
            {
                return;
            }

            var strokeThickness = borderPath?.StrokeThickness ?? 0;

            if (width <= 0 || height <= 0)
            {
                return;
            }

            var pathSize  = new Graphics.Rect(0, 0, width + strokeThickness, height + strokeThickness);
            var shapePath = borderShape.PathForBounds(pathSize);
            var geometry  = shapePath.AsPathGeometry();

            if (borderPath != null)
            {
                borderPath.Data            = geometry;
                borderPath.RenderTransform = new TranslateTransform()
                {
                    X = -(strokeThickness / 2), Y = -(strokeThickness / 2)
                };
            }
        }
Пример #3
0
        private Graphics.Rect centerBox(Graphics.Viewport viewport, Graphics.Rect size)
        {
            Graphics.Rect result = size;
            result.X = (float)System.Math.Floor((viewport.Width - size.Width) / 2);
            result.Y = (float)System.Math.Floor((viewport.Height - size.Height) / 2);

            return(result);
        }
Пример #4
0
        PathF IShape.PathForBounds(Graphics.Rect bounds)
        {
            var path = new PathF();

            AppendPath(path);

            return(path);
        }
Пример #5
0
        public MsgBox(Resource.ResourceManager globalContent, string text, MsgBoxType type)
        {
            _type     = type;
            _isActive = true;

            // we need to load all the positioning data and whatnot from a file...
            Resource.TextResource layout = new Gk3Main.Resource.TextResource("MSGBOX.TXT", FileSystem.Open("MSGBOX.TXT"));
            string[] lines = layout.Text.Split('\n');

            Dictionary <string, string> layoutInfo = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            foreach (string line in lines)
            {
                if (line.StartsWith(";") == false)
                {
                    int equal = line.IndexOf('=');
                    if (equal > 0)
                    {
                        layoutInfo.Add(line.Substring(0, equal).Trim(), line.Substring(equal + 1).Trim());
                    }
                }
            }

            _font = Font.Load(globalContent.Load <FontSpec>(layoutInfo["Font"]));

            _yes          = new Button(this, globalContent, layoutInfo["yesSpriteDown"], layoutInfo["yesSpriteHov"], layoutInfo["yesSpriteUp"], null, null);
            _no           = new Button(this, globalContent, layoutInfo["noSpriteDown"], layoutInfo["noSpriteHov"], layoutInfo["noSpriteUp"], null, null);
            _ok           = new Button(this, globalContent, layoutInfo["okSpriteDown"], layoutInfo["okSpriteHov"], layoutInfo["okSpriteUp"], null, null);
            _yes.OnClick += new EventHandler(onButtonClicked);
            _no.OnClick  += new EventHandler(onButtonClicked);
            _ok.OnClick  += new EventHandler(onButtonClicked);


            _bg    = globalContent.Load <Graphics.TextureResource>("black");
            _vert  = globalContent.Load <Graphics.TextureResource>(layoutInfo["vertSprite"]);
            _horiz = globalContent.Load <Graphics.TextureResource>(layoutInfo["horizSprite"]);
            _ur    = globalContent.Load <Graphics.TextureResource>(layoutInfo["urCornerSprite"]);
            _ul    = globalContent.Load <Graphics.TextureResource>(layoutInfo["ulCornerSprite"]);
            _lr    = globalContent.Load <Graphics.TextureResource>(layoutInfo["lrCornerSprite"]);
            _ll    = globalContent.Load <Graphics.TextureResource>(layoutInfo["llCornerSprite"]);

            tryParse2f(layoutInfo["minSize"], out _rect.Width, out _rect.Height);
            tryParse2f(layoutInfo["textOffset"], out _textOffsetX, out _textOffsetY);

            _rect = centerBox(Graphics.RendererManager.CurrentRenderer.Viewport, calculateBoxSize(text, _rect));

            if (_type == MsgBoxType.YesNo)
            {
                positionButtons(true, true, false);
            }
            else
            {
                positionButtons(false, false, true);
            }
        }
Пример #6
0
        protected internal override void Draw(ref Graphics.Rect drawableArea, IGUIRenderer renderer)
        {
            Color c = this.focused ? this.BackgroundColor : Color.AddContrast(this.BackgroundColor, 0.2f);

            drawableArea.W = this.Width;
            drawableArea.H = this.Height;

            renderer.DrawRect(ref drawableArea, c);
            if (Image != null)
            {
                renderer.DrawFrame(Image, ref drawableArea, ImageColor);
            }
        }
Пример #7
0
        async void OnScrollRequested(object sender, ScrollToRequestedEventArgs e)
        {
            var x = e.ScrollX;
            var y = e.ScrollY;

            if (e.Mode == ScrollToMode.Element)
            {
                Graphics.Point itemPosition = (Element as IScrollViewController).GetScrollPositionForElement(e.Element as VisualElement, e.Position);
                x = itemPosition.X;
                y = itemPosition.Y;
            }

            ERect region = new Graphics.Rect(x, y, Element.Width, Element.Height).ToEFLPixel();
            await Control.ScrollToAsync(region, e.ShouldAnimate);

            Element.SendScrollFinished();
        }
Пример #8
0
        private Graphics.Rect calculateBoxSize(string text, Graphics.Rect minSize)
        {
            Math.Vector2 textSize = Font.MeasureString(_font, text);
            float        area     = textSize.X * textSize.Y;

            const float goalRatio = 3.0f;
            float       newHeight = (float)System.Math.Sqrt(area / goalRatio);
            float       newWidth  = newHeight * goalRatio;

            splitStrings(text, System.Math.Max(newWidth, minSize.Width - _textOffsetX * 2));

            Graphics.Rect result = new Graphics.Rect();
            result.Width  = (float)System.Math.Ceiling(System.Math.Max(minSize.Width, newWidth + _textOffsetX * 2.0f));
            result.Height = (float)System.Math.Ceiling(System.Math.Max(minSize.Height, newHeight + _textOffsetY * 2.0f + _ok.Height + _buttonPadding * 2.0f));

            return(result);
        }
Пример #9
0
        public override void PlatformArrange(Graphics.Rect frame)
        {
            if (PlatformView.GetScaleType() == ImageView.ScaleType.CenterCrop)
            {
                // If the image is center cropped (AspectFill), then the size of the image likely exceeds
                // the view size in some dimension. So we need to clip to the view's bounds.

                var(left, top, right, bottom) = PlatformView.Context !.ToPixels(frame);
                var clipRect = new Android.Graphics.Rect(0, 0, right - left, bottom - top);
                PlatformView.ClipBounds = clipRect;
            }
            else
            {
                PlatformView.ClipBounds = null;
            }

            base.PlatformArrange(frame);
        }
Пример #10
0
        private void calculateBoxRect()
        {
            float width = _width;

            foreach (KeyValuePair <string, string> item in _items)
            {
                float itemWidth = Gk3Main.Gui.Font.MeasureString(_font, item.Value).X;
                if (itemWidth > width)
                {
                    width = itemWidth;
                }
            }

            float boxLeft = _screenX - width + _downArrow.Width;
            int   height  = _items.Count * (_font.Font.LineHeight + _itemVerticalPadding);

            _boxRect = new Gk3Main.Graphics.Rect(boxLeft + 1, _screenY + _downArrow.Height + 1, width - 2, height - 2);
        }
Пример #11
0
        void UpdateClip()
        {
            if (Child == null)
            {
                return;
            }

            var clipGeometry = Clip;

            if (clipGeometry == null)
            {
                return;
            }

            double width  = Child.ActualWidth;
            double height = Child.ActualHeight;

            if (height <= 0 && width <= 0)
            {
                return;
            }

            var visual     = ElementCompositionPreview.GetElementVisual(Child);
            var compositor = visual.Compositor;

            var pathSize = new Graphics.Rect(0, 0, width, height);
            var clipPath = clipGeometry.PathForBounds(pathSize);
            var device   = CanvasDevice.GetSharedDevice();
            var geometry = clipPath.AsPath(device);

            var path          = new CompositionPath(geometry);
            var pathGeometry  = compositor.CreatePathGeometry(path);
            var geometricClip = compositor.CreateGeometricClip(pathGeometry);

            visual.Clip = geometricClip;
        }
Пример #12
0
        public static APath ToAPath(this Geometry geometry, Context context)
        {
            APath path = new APath();

            float density = context.Resources.DisplayMetrics.Density;

            if (geometry is LineGeometry)
            {
                LineGeometry lineGeometry = geometry as LineGeometry;

                path.MoveTo(
                    density * (float)lineGeometry.StartPoint.X,
                    density * (float)lineGeometry.StartPoint.Y);

                path.LineTo(
                    density * (float)lineGeometry.EndPoint.X,
                    density * (float)lineGeometry.EndPoint.Y);
            }
            else if (geometry is RectangleGeometry)
            {
                Graphics.Rect rect = (geometry as RectangleGeometry).Rect;

                path.AddRect(
                    density * (float)rect.Left,
                    density * (float)rect.Top,
                    density * (float)rect.Right,
                    density * (float)rect.Bottom,
                    APath.Direction.Cw);
            }
            else if (geometry is EllipseGeometry)
            {
                EllipseGeometry ellipseGeometry = geometry as EllipseGeometry;

                path.AddOval(new Graphics.RectF(
                                 density * (float)(ellipseGeometry.Center.X - ellipseGeometry.RadiusX),
                                 density * (float)(ellipseGeometry.Center.Y - ellipseGeometry.RadiusY),
                                 density * (float)(ellipseGeometry.Center.X + ellipseGeometry.RadiusX),
                                 density * (float)(ellipseGeometry.Center.Y + ellipseGeometry.RadiusY)),
                             APath.Direction.Cw);
            }
            else if (geometry is GeometryGroup)
            {
                GeometryGroup geometryGroup = geometry as GeometryGroup;

                path.SetFillType(geometryGroup.FillRule == FillRule.Nonzero ? APath.FillType.Winding : APath.FillType.EvenOdd);

                foreach (Geometry child in geometryGroup.Children)
                {
                    APath childPath = child.ToAPath(context);
                    path.AddPath(childPath);
                }
            }
            else if (geometry is PathGeometry)
            {
                PathGeometry pathGeometry = geometry as PathGeometry;

                path.SetFillType(pathGeometry.FillRule == FillRule.Nonzero ? APath.FillType.Winding : APath.FillType.EvenOdd);

                foreach (PathFigure pathFigure in pathGeometry.Figures)
                {
                    path.MoveTo(
                        density * (float)pathFigure.StartPoint.X,
                        density * (float)pathFigure.StartPoint.Y);

                    Point lastPoint = pathFigure.StartPoint;

                    foreach (PathSegment pathSegment in pathFigure.Segments)
                    {
                        // LineSegment
                        if (pathSegment is LineSegment)
                        {
                            LineSegment lineSegment = pathSegment as LineSegment;

                            path.LineTo(
                                density * (float)lineSegment.Point.X,
                                density * (float)lineSegment.Point.Y);
                            lastPoint = lineSegment.Point;
                        }
                        // PolylineSegment
                        else if (pathSegment is PolyLineSegment)
                        {
                            PolyLineSegment polylineSegment = pathSegment as PolyLineSegment;
                            PointCollection points          = polylineSegment.Points;

                            for (int i = 0; i < points.Count; i++)
                            {
                                path.LineTo(
                                    density * (float)points[i].X,
                                    density * (float)points[i].Y);
                            }
                            lastPoint = points[points.Count - 1];
                        }
                        // BezierSegment
                        else if (pathSegment is BezierSegment)
                        {
                            BezierSegment bezierSegment = pathSegment as BezierSegment;

                            path.CubicTo(
                                density * (float)bezierSegment.Point1.X, density * (float)bezierSegment.Point1.Y,
                                density * (float)bezierSegment.Point2.X, density * (float)bezierSegment.Point2.Y,
                                density * (float)bezierSegment.Point3.X, density * (float)bezierSegment.Point3.Y);

                            lastPoint = bezierSegment.Point3;
                        }
                        // PolyBezierSegment
                        else if (pathSegment is PolyBezierSegment)
                        {
                            PolyBezierSegment polyBezierSegment = pathSegment as PolyBezierSegment;
                            PointCollection   points            = polyBezierSegment.Points;

                            if (points.Count >= 3)
                            {
                                for (int i = 0; i < points.Count; i += 3)
                                {
                                    path.CubicTo(
                                        density * (float)points[i + 0].X, density * (float)points[i + 0].Y,
                                        density * (float)points[i + 1].X, density * (float)points[i + 1].Y,
                                        density * (float)points[i + 2].X, density * (float)points[i + 2].Y);
                                }
                            }

                            lastPoint = points[points.Count - 1];
                        }
                        // QuadraticBezierSegment
                        else if (pathSegment is QuadraticBezierSegment)
                        {
                            QuadraticBezierSegment bezierSegment = pathSegment as QuadraticBezierSegment;

                            path.QuadTo(
                                density * (float)bezierSegment.Point1.X, density * (float)bezierSegment.Point1.Y,
                                density * (float)bezierSegment.Point2.X, density * (float)bezierSegment.Point2.Y);

                            lastPoint = bezierSegment.Point2;
                        }
                        // PolyQuadraticBezierSegment
                        else if (pathSegment is PolyQuadraticBezierSegment)
                        {
                            PolyQuadraticBezierSegment polyBezierSegment = pathSegment as PolyQuadraticBezierSegment;
                            PointCollection            points            = polyBezierSegment.Points;

                            if (points.Count >= 2)
                            {
                                for (int i = 0; i < points.Count; i += 2)
                                {
                                    path.QuadTo(
                                        density * (float)points[i + 0].X, density * (float)points[i + 0].Y,
                                        density * (float)points[i + 1].X, density * (float)points[i + 1].Y);
                                }
                            }

                            lastPoint = points[points.Count - 1];
                        }
                        // ArcSegment
                        else if (pathSegment is ArcSegment)
                        {
                            ArcSegment arcSegment = pathSegment as ArcSegment;

                            List <Point> points = new List <Point>();

                            GeometryHelper.FlattenArc(
                                points,
                                lastPoint,
                                arcSegment.Point,
                                arcSegment.Size.Width,
                                arcSegment.Size.Height,
                                arcSegment.RotationAngle,
                                arcSegment.IsLargeArc,
                                arcSegment.SweepDirection == SweepDirection.CounterClockwise,
                                1);

                            for (int i = 0; i < points.Count; i++)
                            {
                                path.LineTo(
                                    density * (float)points[i].X,
                                    density * (float)points[i].Y);
                            }

                            if (points.Count > 0)
                            {
                                lastPoint = points[points.Count - 1];
                            }
                        }
                    }

                    if (pathFigure.IsClosed)
                    {
                        path.Close();
                    }
                }
            }

            return(path);
        }
Пример #13
0
        protected override void OnDraw(Shape?shape, Canvas?canvas, APaint?paint)
        {
            if (_disposed)
            {
                return;
            }

            if (HasBorder())
            {
                if (Paint != null)
                {
                    SetBackground(Paint);
                }

                if (_borderPaint != null)
                {
                    _borderPaint.StrokeWidth = _strokeThickness;
                    _borderPaint.StrokeJoin  = _strokeLineJoin;
                    _borderPaint.StrokeCap   = _strokeLineCap;
                    _borderPaint.StrokeMiter = _strokeMiterLimit * 2;

                    if (_borderPathEffect != null)
                    {
                        _borderPaint.SetPathEffect(_borderPathEffect);
                    }

                    if (_borderColor != null)
                    {
                        _borderPaint.Color = _borderColor.Value;
                    }
                    else
                    {
                        if (_stroke != null)
                        {
                            SetPaint(_borderPaint, _stroke);
                        }
                    }
                }

                if (_invalidatePath)
                {
                    _invalidatePath = false;

                    if (_shape != null)
                    {
                        var bounds   = new Graphics.Rect(0, 0, _width, _height);
                        var path     = _shape.PathForBounds(bounds);
                        var clipPath = path?.AsAndroidPath();

                        if (clipPath == null)
                        {
                            return;
                        }

                        if (_clipPath != null)
                        {
                            _clipPath.Reset();
                            _clipPath.Set(clipPath);
                        }
                    }
                }

                if (canvas == null)
                {
                    return;
                }

                var saveCount = canvas.SaveLayer(0, 0, _width, _height, null);

                if (_clipPath != null && Paint != null)
                {
                    canvas.DrawPath(_clipPath, Paint);
                }

                if (_clipPath != null && _borderPaint != null)
                {
                    canvas.DrawPath(_clipPath, _borderPaint);
                }

                canvas.RestoreToCount(saveCount);
            }
            else
            {
                if (paint != null)
                {
                    SetBackground(paint);
                }

                base.OnDraw(shape, canvas, paint);
            }
        }
Пример #14
0
 public static (int left, int top, int right, int bottom) ToPixels(this Context context, Graphics.Rect rectangle)
 {
     return
         (
         (int)context.ToPixels(rectangle.Left),
         (int)context.ToPixels(rectangle.Top),
         (int)context.ToPixels(rectangle.Right),
         (int)context.ToPixels(rectangle.Bottom)
         );
 }
Пример #15
0
 public override void PlatformArrange(Graphics.Rect frame)
 {
     base.PlatformArrange(frame);
 }
Пример #16
0
 protected internal override void Draw(ref Graphics.Rect area, IGUIRenderer batch)
 {
     throw new NotImplementedException();
 }
Пример #17
0
        protected override void OnDraw(Shape?shape, Canvas?canvas, APaint?paint)
        {
            if (_disposed)
            {
                return;
            }

            if (HasBorder())
            {
                if (Paint != null)
                {
                    SetBackground(Paint);
                }

                if (_borderPaint != null)
                {
                    _borderPaint.StrokeWidth = _strokeThickness;
                    _borderPaint.StrokeJoin  = _strokeLineJoin;
                    _borderPaint.StrokeCap   = _strokeLineCap;
                    _borderPaint.StrokeMiter = _strokeMiterLimit * 2;

                    if (_borderPathEffect != null)
                    {
                        _borderPaint.SetPathEffect(_borderPathEffect);
                    }

                    if (_borderColor != null)
#pragma warning disable CA1416 // https://github.com/xamarin/xamarin-android/issues/6962
                    {
                        _borderPaint.Color = _borderColor.Value;
                    }
#pragma warning restore CA1416
                    else
                    {
                        if (_stroke != null)
                        {
                            SetPaint(_borderPaint, _stroke);
                        }
                    }
                }

                if (_invalidatePath)
                {
                    _invalidatePath = false;

                    if (_shape != null)
                    {
                        float offset = _strokeThickness / 2;
                        float w      = (float)(_width / _density) - _strokeThickness;
                        float h      = (float)(_height / _density) - _strokeThickness;

                        var bounds   = new Graphics.Rect(offset, offset, w, h);
                        var path     = _shape.PathForBounds(bounds);
                        var clipPath = path?.AsAndroidPath(scaleX: (float)_density, scaleY: (float)_density);

                        if (clipPath == null)
                        {
                            return;
                        }

                        if (_clipPath != null)
                        {
                            _clipPath.Reset();
                            _clipPath.Set(clipPath);
                        }
                    }
                }

                if (canvas == null)
                {
                    return;
                }

                var saveCount = canvas.SaveLayer(0, 0, _width, _height, null);

                if (_clipPath != null && Paint != null)
                {
                    canvas.DrawPath(_clipPath, Paint);
                }

                if (_clipPath != null && _borderPaint != null)
                {
                    canvas.DrawPath(_clipPath, _borderPaint);
                }

                canvas.RestoreToCount(saveCount);
            }
            else
            {
                if (paint != null)
                {
                    SetBackground(paint);
                }

                base.OnDraw(shape, canvas, paint);
            }
        }