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 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; } }