public override void OnDraw(IUGContext context)
        {
            base.OnDraw(context);

            var size = new UGSize((context.CanvasSize.Width - SPACE * (COLUMN - 1)) / COLUMN, (context.CanvasSize.Height - SPACE * (ROW - 1)) / ROW);
            var pos  = new Vector2();

            context.FillCircleInRectangle(pos, Math.Min(size.Width, size.Height), _linear);
            pos.X += SPACE + size.Width;
            context.FillEllipseInRectangle(pos, size.Width, size.Height, _linear);
            pos.X += SPACE + size.Width;
            context.FillRectangle(pos, size.Width, size.Height, _linear);
            pos.X += SPACE + size.Width;
            context.FillRoundedRectangle(pos, size.Width, size.Height, 10F, 20F, _linear);
            pos.X = 0F;

            pos.Y = SPACE + size.Height;
            context.FillCircleInRectangle(pos, Math.Min(size.Width, size.Height), _radial);
            pos.X += SPACE + size.Width;
            context.FillEllipseInRectangle(pos, size.Width, size.Height, _radial);
            pos.X += SPACE + size.Width;
            context.FillRectangle(pos, size.Width, size.Height, _radial);
            pos.X += SPACE + size.Width;
            context.FillRoundedRectangle(pos, size.Width, size.Height, 10F, 20F, _radial);
            pos.X = 0F;
        }
        private void Draw()
        {
            if (Holder.IsCreating || _destroyed)
            {
                return;
            }

            Canvas canvas = null;

            try
            {
                canvas = Holder.LockCanvas();
                var density    = Resources.DisplayMetrics.Density;
                var canvasSize = new UGSize(Width / density, Height / density);
                using (var ugContext = new UGContext(canvas, canvasSize, density))
                {
                    canvas.Scale(density, density);
                    DrawOverride(ugContext);
                }
            }
            finally
            {
                if (canvas != null)
                {
                    Holder.UnlockCanvasAndPost(canvas);
                }
            }
        }
예제 #3
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            var hMonitor = NativeMethods.GetHMonitor(ClientRectangle);

            _colorService.Initialize(hMonitor);

            var graphics = e.Graphics;

#if NET47 || NET471
            var scale = DeviceDpi / 96F;
            graphics.ScaleTransform(scale, scale);
            var scaledClientSize = new UGSize(
                ClientSize.Width / scale,
                ClientSize.Height / scale);
            using (var ugContext = new UGContext(graphics, scaledClientSize, DeviceDpi / 96F, _colorService))
#else
            var clientSize = new UGSize(
                ClientSize.Width,
                ClientSize.Height);
            using (var ugContext = new UGContext(graphics, clientSize, 1F, _colorService))
#endif
            {
                DrawOverride(ugContext);
            }
        }
예제 #4
0
        public UGCanvasRenderTarget(UGSize canvasSize, float scale)
        {
            Size  = canvasSize;
            Scale = scale;

            _device = CanvasDevice.GetSharedDevice();
            _native = new CanvasRenderTarget(_device, Width, Height, Scale * 96.0F);
        }
예제 #5
0
        public UGTextLayout(IUGContext context, string textString, IUGTextFormat textFormat, UGSize requestedSize)
        {
            _textFormat    = (UGTextFormat)textFormat;
            _textString    = textString;
            _requestedSize = requestedSize;

            _scale = context.ScaleFactor;
        }
예제 #6
0
        internal UGContext(Canvas native, UGSize canvasRect, float scale, Action disposeAction)
        {
            Native         = native;
            CanvasSize     = canvasRect;
            ScaleFactor    = scale;
            _disposeAction = disposeAction;

            _context     = new Paint();
            Antialiasing = true;
        }
예제 #7
0
        public override void InitializeResources(IUGContext context)
        {
            var size = new UGSize(64F, 64F);

            _offScreenTarget = new UGCanvasRenderTarget(size, 2F);
            using (var session = _offScreenTarget.CreateDrawingSession())
            {
                session.ClearColor(WHITE);
                session.FillEllipse(32F, 32F, 24F, 32F, BLUE);
            }
        }
예제 #8
0
        public UGCanvasRenderTarget(UGSize canvasSize, float scale)
        {
            Size  = canvasSize;
            Scale = scale;

            var width  = (int)(Scale * Width + .5F);
            var height = (int)(Scale * Height + .5F);
            var dpi    = 96F * Scale;

            _native = new RenderTargetBitmap(width, height, dpi, dpi, PixelFormats.Default);
        }
예제 #9
0
        internal UGContext(Graphics native, UGSize canvasRect, float scale, ColorService colorService, Action disposeAction)
        {
            Native         = native;
            CanvasSize     = canvasRect;
            ScaleFactor    = scale;
            _colorService  = colorService;
            _disposeAction = disposeAction;

            native.CompositingQuality = CompositingQuality.HighQuality | CompositingQuality.GammaCorrected;
            native.PixelOffsetMode    = PixelOffsetMode.Half;
            native.SmoothingMode      = SmoothingMode.AntiAlias;
        }
예제 #10
0
        protected sealed override void OnDraw(Canvas canvas)
        {
            base.OnDraw(canvas);

            var density    = Resources.DisplayMetrics.Density;
            var canvasSize = new UGSize(Width / density, Height / density);

            using (var ugContext = new UGContext(canvas, canvasSize, density))
            {
                canvas.Scale(density, density);
                DrawOverride(ugContext);
            }
        }
        public UGCanvasRenderTarget(UGSize canvasSize, float scale)
        {
            Size  = canvasSize;
            Scale = scale;

            var width  = (int)(Scale * Size.Width + .5F);
            var height = (int)(Scale * Size.Height + .5F);
            var dpi    = (int)(Scale * 96F + .5F);
            var native = new Bitmap(width, height, PixelFormat.Format32bppPArgb);

            native.SetResolution(dpi, dpi);
            _native = native;
        }
        public override void OnDraw(IUGContext context)
        {
            base.OnDraw(context);

            var size = new UGSize((context.CanvasSize.Width - 40F) / 3, (context.CanvasSize.Height - 40F) / 3F);

            context.FillRectangle(0, 0, size.Width, size.Height, _linear0);
            context.FillRectangle(20F + size.Width, 0, size.Width, size.Height, _linear45);
            context.FillRectangle(40F + 2F * size.Width, 0, size.Width, size.Height, _linear90);

            context.FillRectangle(0, 20F + size.Height, size.Width, size.Height, _radialClamp);
            context.FillRectangle(20F + size.Width, 20F + size.Height, size.Width, size.Height, _radialWrap);
            context.FillRectangle(40F + 2F * size.Width, 20F + size.Height, size.Width, size.Height, _radialMirror);

            context.FillRectangle(0, 40F + 2F * size.Height, size.Width, size.Height, _radialClamp2);
            context.FillRectangle(20F + size.Width, 40F + 2F * size.Height, size.Width, size.Height, _radialWrap2);
            context.FillRectangle(40F + 2F * size.Width, 40F + 2F * size.Height, size.Width, size.Height, _radialMirror2);
        }
        public void OnDraw(IUGContext context)
        {
            context.ClearColor(white);

            var pos  = new Vector2();
            var size = new UGSize(context.CanvasSize.Width / xStep, context.CanvasSize.Height / yStep);

            for (var h = 0; h < xStep; ++h)
            {
                pos.Y = 0F;
                for (var l = 0; l < yStep; ++l)
                {
                    var color = UGColor.FromHSL((float)h / xStep, 1F, (float)l / yStep);
                    context.FillRectangle(pos, size, color);
                    pos.Y += size.Height;
                }
                pos.X += size.Width;
            }
        }
예제 #14
0
        public UGCanvasRenderTarget(UGSize canvasSize, float scale)
        {
            Size  = canvasSize;
            Scale = scale;

            var    width  = (int)(scale * Width + .5F);
            var    height = (int)(scale * Height + .5F);
            Bitmap native;

            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                using (var colorSpace = ColorSpace.Get(ColorSpace.Named.Srgb))
                {
                    native = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888, true, colorSpace);
                }
            }
            else
            {
                native = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888);
            }
            native.Density = (int)(160F * Scale + .5F);
            _native        = native;
        }
예제 #15
0
        public UGTextLayout(IUGContext context, string textString, IUGTextFormat textFormat, UGSize requestedSize)
        {
            var device = ((UGContext)context).Device;
            var format = ((UGTextFormat)textFormat).Native;

            _native = new CanvasTextLayout(device, textString, format, requestedSize.Width, requestedSize.Height);
        }
예제 #16
0
		private void DrawRectangle(IUGContext context, UGSize size)
		{
			context.DrawRectangle(MARGIN, MARGIN, size.Width - 2 * MARGIN, size.Height - 2 * MARGIN, BLACK, 2F, STYLE);
		}
예제 #17
0
		public void OnDraw(IUGContext context)
		{
			context.ClearColor(WHITE);

			var translate = new Vector2();
			var center = new Vector2() { X = context.CanvasSize.Width / SPLIT_X / 2F, Y = context.CanvasSize.Height / SPLIT_Y / 2F };
			var size = new UGSize(context.CanvasSize.Width / SPLIT_X, context.CanvasSize.Height / SPLIT_Y);
			for (var y = 0; y < SPLIT_Y; ++y, translate.Y += size.Height)
			{
				translate.X = 0F;
				for (var x = 0; x < SPLIT_X; ++x, translate.X += size.Width)
				{
					var d = SPLIT_Y * y + x;
					var color = UGColor.FromHSL((float)d / SPLIT_LENGTH, 1F, .5F);
					color.A = 128;
					using (context.CreateLayer())
					{
						context.Translate(translate);
						using (context.CreateLayer())
						{
							switch (d)
							{
								case 1:
									context.ScaleX(.5F);
									break;

								case 2:
									context.ScaleY(.5F);
									break;

								case 3:
									context.Scale(.25F, .5F);
									break;
									
								case 4:
									context.Rotate(25F);
									break;

								case 5:
									context.Rotate(45F);
									break;

								case 6:
									context.SkewX(20F);
									break;

								case 7:
									context.SkewY(40F);
									break;

								case 8:
									context.Skew(5F, 10F);
									break;

								case 9:
									context.TranslateX(10F);
									break;

								case 10:
									context.TranslateY(10F);
									break;

								case 11:
									context.Translate(5F, 10F);
									break;

								case 12:
									context.Rotate(20F, center);
									break;

								case 13:
									context.SkewX(20F, center);
									break;

								case 14:
									context.Scale(.25F, .5F, center);
									break;

								case 15:
									context.Transform(new Matrix3x2()
									{
										M11 = .25F,
										M12 = (float)Math.Tan(5.0 * Math.PI / 180.0),
										M21 = (float)Math.Tan(10.0 * Math.PI / 180.0),
										M22 = .75F,
										M31 = 10F,
										M32 = 20F,
									});
									break;
							}
							FillRectangle(context, size, color);
						}
						DrawRectangle(context, size);

						string label = null;
						switch (d)
						{
							case 0: label = "Identity"; break;
							case 1: label = "ScaleX(0.5)"; break;
							case 2: label = "ScaleY(0.5)"; break;
							case 3: label = "Scale(0.25, 0.5)"; break;
							case 4: label = "Rotate(25°)"; break;
							case 5: label = "Rotate(45°)"; break;
							case 6: label = "SkewX(20°)"; break;
							case 7: label = "SkewY(40°)"; break;
							case 8: label = "Skew(5°, 10°)"; break;
							case 9: label = "TranslateX(10)"; break;
							case 10: label = "TranslateY(10)"; break;
							case 11: label = "Translate(5, 10)"; break;
							case 12: label = "Rotate(20°, C)"; break;
							case 13: label = "SkewX(20°, C)"; break;
							case 14: label = "Scale(0.25, 0.5, C)"; break;
							case 15: label = "Matrix"; break;
						}
						using (var layout = new UGTextLayout(context, label, FORMAT, new UGSize(size.Width - 2F * MARGIN, size.Height - 2F * MARGIN)))
						{
							layout.HorizontalAlignment = UGHorizontalAlignment.Center;
							layout.VerticalAlignment = UGVerticalAlignment.Center;
							DrawText(context, layout);
						}
					}
				}
			}
		}
예제 #18
0
 public UGCanvasRenderTarget(UGSize canvasSize) : this(canvasSize, 1F)
 {
 }
예제 #19
0
		private void FillRectangle(IUGContext context, UGSize size, UGColor color)
		{
			context.FillRectangle(MARGIN, MARGIN, size.Width - 2 * MARGIN, size.Height - 2 * MARGIN, color);
		}
예제 #20
0
 internal UGContext(Canvas native, UGSize canvasRect, float scale)
     : this(native, canvasRect, scale, null)
 {
 }
예제 #21
0
 internal UGContext(Graphics native, UGSize canvasRect, float scale, ColorService service)
     : this(native, canvasRect, scale, service, null)
 {
 }
예제 #22
0
 public static CGSize ToCGSize(this UGSize size)
 => new CGSize(size.Width, size.Height);
예제 #23
0
        public override void OnDraw(IUGContext context)
        {
            base.OnDraw(context);

            context.ClearColor(WHITE);

            var halfWidth = context.CanvasSize.Width / 2F;
            var pos       = new Vector2(10F, 10F);
            var size      = new UGSize(halfWidth - 20F, 200F);

            context.TextAntialiasing = UGTextAntialiasing.Aliased;
            using (var textAntialiasingTextLayout = new UGTextLayout(context, "[Aliased]", _textFormat, size))
            {
                context.DrawTextLayout(textAntialiasingTextLayout, pos, BLACK);
                pos.Y += textAntialiasingTextLayout.LayoutBounds.Height;
            }
            using (var leftTextLayout = new UGTextLayout(context, "Left text.", _textFormat, size))
            {
                leftTextLayout.HorizontalAlignment = UGHorizontalAlignment.Left;
                context.DrawTextLayout(leftTextLayout, pos, BLUE);
                pos.Y += leftTextLayout.LayoutBounds.Height;
            }
            using (var centerTextLayout = new UGTextLayout(context, "Center text.", _textFormat, size))
            {
                centerTextLayout.HorizontalAlignment = UGHorizontalAlignment.Center;
                context.DrawTextLayout(centerTextLayout, pos, BLUE);
                pos.Y += centerTextLayout.LayoutBounds.Height;
            }
            using (var rightTextLayout = new UGTextLayout(context, "Right text.", _textFormat, size))
            {
                rightTextLayout.HorizontalAlignment = UGHorizontalAlignment.Right;
                context.DrawTextLayout(rightTextLayout, pos, BLUE);
                pos.Y += rightTextLayout.LayoutBounds.Height;
            }
            pos.Y += 50F;

            context.TextAntialiasing = UGTextAntialiasing.Antialiased;
            using (var textAntialiasingTextLayout = new UGTextLayout(context, "[Antialiased]", _textFormat, size))
            {
                context.DrawTextLayout(textAntialiasingTextLayout, pos, BLACK);
                pos.Y += textAntialiasingTextLayout.LayoutBounds.Height;
            }
            using (var leftTextLayout = new UGTextLayout(context, "Left text.", _textFormat, size))
            {
                leftTextLayout.HorizontalAlignment = UGHorizontalAlignment.Left;
                context.DrawTextLayout(leftTextLayout, pos, BLUE);
                pos.Y += leftTextLayout.LayoutBounds.Height;
            }
            using (var centerTextLayout = new UGTextLayout(context, "Center text.", _textFormat, size))
            {
                centerTextLayout.HorizontalAlignment = UGHorizontalAlignment.Center;
                context.DrawTextLayout(centerTextLayout, pos, BLUE);
                pos.Y += centerTextLayout.LayoutBounds.Height;
            }
            using (var rightTextLayout = new UGTextLayout(context, "Right text.", _textFormat, size))
            {
                rightTextLayout.HorizontalAlignment = UGHorizontalAlignment.Right;
                context.DrawTextLayout(rightTextLayout, pos, BLUE);
                pos.Y += rightTextLayout.LayoutBounds.Height;
            }
            pos.Y += 50F;

            context.TextAntialiasing = UGTextAntialiasing.SubpixelAntialiased;
            using (var textAntialiasingTextLayout = new UGTextLayout(context, "[SubpixelAntialiased]", _textFormat, size))
            {
                context.DrawTextLayout(textAntialiasingTextLayout, pos, BLACK);
                pos.Y += textAntialiasingTextLayout.LayoutBounds.Height;
            }
            using (var leftTextLayout = new UGTextLayout(context, "Left text.", _textFormat, size))
            {
                leftTextLayout.HorizontalAlignment = UGHorizontalAlignment.Left;
                context.DrawTextLayout(leftTextLayout, pos, BLUE);
                pos.Y += leftTextLayout.LayoutBounds.Height;
            }
            using (var centerTextLayout = new UGTextLayout(context, "Center text.", _textFormat, size))
            {
                centerTextLayout.HorizontalAlignment = UGHorizontalAlignment.Center;
                context.DrawTextLayout(centerTextLayout, pos, BLUE);
                pos.Y += centerTextLayout.LayoutBounds.Height;
            }
            using (var rightTextLayout = new UGTextLayout(context, "Right text.", _textFormat, size))
            {
                rightTextLayout.HorizontalAlignment = UGHorizontalAlignment.Right;
                context.DrawTextLayout(rightTextLayout, pos, BLUE);
                pos.Y += rightTextLayout.LayoutBounds.Height;
            }
            pos.Y += 50F;

            context.FillRectangle(halfWidth, 0F, halfWidth, context.CanvasSize.Height, GRAY);

            var pos2  = new Vector2(10F + halfWidth, 10F);
            var size2 = new UGSize(halfWidth - 20F, 200F);

            context.DrawRectangle(pos2, size2, BLACK, 2F, STYLE);
            using (var centerTextLayout = new UGTextLayout(context, "H = Center\nV = Center\nText Test", _textFormat, size2))
            {
                centerTextLayout.HorizontalAlignment = UGHorizontalAlignment.Center;
                centerTextLayout.VerticalAlignment   = UGVerticalAlignment.Center;
                context.DrawTextLayout(centerTextLayout, pos2, BLUE);
                pos2.Y += size2.Height + 10F;
            }
            context.DrawRectangle(pos2, size2, BLACK, 2F, STYLE);
            using (var centerTextLayout = new UGTextLayout(context, "H = Center\nV = Bottom\nText Test", _textFormat, size2))
            {
                centerTextLayout.HorizontalAlignment = UGHorizontalAlignment.Center;
                centerTextLayout.VerticalAlignment   = UGVerticalAlignment.Bottom;
                context.DrawTextLayout(centerTextLayout, pos2, BLUE);
                pos2.Y += size2.Height + 10F;
            }
        }
예제 #24
0
 public static Size ToGDISize(this UGSize size)
 => new Size((int)(size.Width + .5F), (int)(size.Height + .5F));
 public UGCanvasRenderTarget(UGSize canvasSize, float scale)
 {
     Size  = canvasSize;
     Scale = scale;
 }
예제 #26
0
 public UGTextLayout(IUGContext context, string textString, IUGTextFormat textFormat, UGSize requestedSize)
 {
     _native        = new NSString(textString);
     _textFormat    = (UGTextFormat)textFormat;
     _requestedSize = requestedSize;
 }