Exemplo n.º 1
0
        public UGSolidColorBrush(IUGContext context, UGColor color)
        {
            var native = new SolidColorBrush(color.ToWPFColor());

            native.Freeze();
            _native = native;
        }
Exemplo n.º 2
0
 public static CGColor ToCGColor(this UGColor color)
 {
     using (var colorSpace = CGColorSpace.CreateSrgb())
     {
         return(new CGColor(colorSpace, color.ToColorComponents()));
     }
 }
        public override void InitializeResources(IUGContext context)
        {
            _linear = new UGLinearGradientBrush(
                context,
                new Vector2(0F, 0F),
                new Vector2(1F, 1F),
                new[] {
                new UGGradientStop(UGColor.FromHSL(0F / 3F, 1F, .5F), .25F),
                new UGGradientStop(UGColor.FromHSL(2F / 3F, 1F, .5F), .75F),
            },
                UGEdgeBehavior.Clamp);

            _radial = new UGRadialGradientBrush(
                context,
                new Vector2(.2F, .2F),
                .75F,
                new[] {
                new UGGradientStop(UGColor.FromHSL(0F / 3F, 1F, .5F), 0F),
                new UGGradientStop(UGColor.FromHSL(.5F / 3F, 1F, .5F), .25F),
                new UGGradientStop(UGColor.FromHSL(1F / 3F, 1F, .5F), .5F),
                new UGGradientStop(UGColor.FromHSL(1.5F / 3F, 1F, .5F), .75F),
                new UGGradientStop(UGColor.FromHSL(2F / 3F, 1F, .5F), 1F),
            },
                UGEdgeBehavior.Wrap);
        }
Exemplo n.º 4
0
 private static unsafe void SetMixedColor(nfloat ratio, UGColor inFromColor, UGColor inToColor, nfloat *outColor)
 {
     outColor[0] = (inFromColor.R + ratio * (inToColor.R - inFromColor.R)) / 255;
     outColor[1] = (inFromColor.G + ratio * (inToColor.G - inFromColor.G)) / 255;
     outColor[2] = (inFromColor.B + ratio * (inToColor.B - inFromColor.B)) / 255;
     outColor[3] = (inFromColor.A + ratio * (inToColor.A - inFromColor.A)) / 255;
 }
Exemplo n.º 5
0
 private static unsafe void SetColor(UGColor inColor, nfloat *outColor)
 {
     outColor[0] = (nfloat)inColor.R / 255;
     outColor[1] = (nfloat)inColor.G / 255;
     outColor[2] = (nfloat)inColor.B / 255;
     outColor[3] = (nfloat)inColor.A / 255;
 }
Exemplo n.º 6
0
        internal void Draw(Canvas canvas, UGColor color)
        {
            _textFormat.Native.Color = color.ToAGColor();

            var layout = GetLayout();
            var bounds = LayoutBounds;

            canvas.Translate(0F, bounds.Y);
            layout.Draw(canvas);
        }
Exemplo n.º 7
0
        internal void Draw(CGContext context, float x, float y, UGColor color)
        {
#if __MACOS__
            NSStringAttributes attributes = null;
            using (var nsColor = color.ToNSColor())
            {
                attributes = new NSStringAttributes()
                {
                    Font            = _textFormat.Native,
                    ForegroundColor = nsColor,
                };
            }
#else
            UIStringAttributes attributes = null;
            using (var uiColor = color.ToUIColor())
            {
                attributes = new UIStringAttributes()
                {
                    Font            = _textFormat.Native,
                    ForegroundColor = uiColor,
                };
            }
#endif

            var bounds = LayoutBounds;
            var rect   = new CGRect(
                x + bounds.X,
                y + bounds.Y,
                bounds.Width,
                bounds.Height);
            var scaleMatrix = CGAffineTransformHelper.CreateScale(
                1F,
                -1F,
                (float)rect.X,
                (float)rect.Y);
            try
            {
                context.SaveState();
                context.ConcatCTM(scaleMatrix);
                context.TranslateCTM(0, -bounds.Height);
#if __MACOS__
                _native.DrawInRect(rect, attributes);
#else
                _native.DrawString(rect, attributes);
#endif
            }
            finally { context.RestoreState(); }
        }
        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;
            }
        }
Exemplo n.º 9
0
        public Color GetTranslatedColor(UGColor color)
        {
            var hTransform = _hTransform;

            if (hTransform == IntPtr.Zero)
            {
                return(color.ToGDIColor());
            }

            var value = color.Color;

            if (!_translatedColors.TryGetValue(value, out var translatedColor))
            {
                var colors = new RGBColor[1];
                colors[0].R = (ushort)(257 * color.R);
                colors[0].G = (ushort)(257 * color.G);
                colors[0].B = (ushort)(257 * color.B);

                var buf = NativeMethods.ColorTransform.TranslateColors(hTransform, colors, ColorType.RGB, ColorType.RGB);
                translatedColor = Color.FromArgb(color.A, (byte)(buf[0].R / 257), (byte)(buf[0].G / 257), (byte)(buf[0].B / 257));
                _translatedColors.Add(value, translatedColor);
            }
            return(translatedColor);
        }
Exemplo n.º 10
0
 public UGSolidColorBrush(IUGContext context, UGColor color)
 {
     _native = color.ToAGColor();
 }
Exemplo n.º 11
0
 public static UIColor ToUIColor(this UGColor color)
 => UIColor.FromRGBA(color.R, color.G, color.B, color.A);
Exemplo n.º 12
0
 public static NSColor ToNSColor(this UGColor color)
 => NSColor.FromRgba(color.R, color.G, color.B, color.A);
Exemplo n.º 13
0
 public UGSolidColorBrush(IUGContext context, UGColor color)
 => _native = new CanvasSolidColorBrush(((UGContext)context).Device, color.ToWinRTColor());
Exemplo n.º 14
0
 public UGLinearGradientBrush(IUGContext context, UGColor startColor, UGColor endColor, float angle, UGEdgeBehavior edgeBehavior)
     : this(context, Vector2.Zero, UGLinearGradientHelper.EndPointFromAngle(angle), startColor, endColor, edgeBehavior)
 {
 }
Exemplo n.º 15
0
 public static Color ToWinRTColor(this UGColor color)
 => Color.FromArgb(color.A, color.R, color.G, color.B);
Exemplo n.º 16
0
 public static Color ToGDIColor(this UGColor color)
 => Color.FromArgb(color.ColorAsInt);
Exemplo n.º 17
0
 public UGSolidColorBrush(IUGContext context, UGColor color)
 => _native = new SolidBrush(color.ToGDIColor());
Exemplo n.º 18
0
		private void FillRectangle(IUGContext context, UGSize size, UGColor color)
		{
			context.FillRectangle(MARGIN, MARGIN, size.Width - 2 * MARGIN, size.Height - 2 * MARGIN, color);
		}
Exemplo n.º 19
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);
						}
					}
				}
			}
		}
 public UGRadialGradientBrush(IUGContext context, UGColor startColor, UGColor endColor)
     : this(context, startColor, endColor, UGEdgeBehavior.Clamp)
 {
 }
Exemplo n.º 21
0
 public UGLinearGradientBrush(IUGContext context, Vector2 startPoint, Vector2 endPoint, UGColor startColor, UGColor endColor, UGEdgeBehavior edgeBehavior)
     : this(context, startPoint, endPoint, new[] { new UGGradientStop(startColor, 0F), new UGGradientStop(endColor, 1F) }, edgeBehavior)
 {
 }
Exemplo n.º 22
0
 public static nfloat[] ToColorComponents(this UGColor color)
 => new[] { (nfloat)color.R / 255, (nfloat)color.G / 255, (nfloat)color.B / 255, (nfloat)color.A / 255 };
 public UGRadialGradientBrush(IUGContext context, UGColor startColor, UGColor endColor, UGEdgeBehavior edgeBehavior)
     : this(context, new Vector2(.5F, .5F), .5F, new[] { new UGGradientStop(startColor, 0F), new UGGradientStop(endColor, 1F) }, edgeBehavior)
 {
 }
Exemplo n.º 24
0
 public static Color ToAGColor(this UGColor color)
 => new Color(color.ColorAsInt);