Control RectangleClip() { var control = new Drawable { Size = new Size(300, 100) }; control.Paint += (sender, e) => { e.Graphics.SetClip(new RectangleF(25, 25, 50, 50)); if (ResetClip) e.Graphics.ResetClip(); e.Graphics.FillRectangle(Brushes.Blue, new RectangleF(25, 0, 100, 100)); e.Graphics.SetClip(new RectangleF(125, 25, 50, 50)); if (ResetClip) e.Graphics.ResetClip(); e.Graphics.FillRectangle(Brushes.Red, new RectangleF(125, 0, 100, 100)); e.Graphics.SetClip(new RectangleF(225, 25, 50, 50)); if (ResetClip) e.Graphics.ResetClip(); e.Graphics.FillRectangle(Brushes.Green, new RectangleF(225, 0, 100, 100)); }; PropertyChanged += (sender, e) => { if (e.PropertyName == "ResetClip") control.Invalidate(); }; return control; }
Control ClearGraphicsTest() { var control = new Drawable { Size = new Size(200, 200), BackgroundColor = Colors.Yellow }; control.Paint += (sender, e) => DrawSample(e.Graphics); PropertyChanged += (sender, e) => control.Invalidate(); return control; }
public UnitTestSection() { var layout = new DynamicLayout(); var button = new Button { Text = "Start Tests" }; var drawable = new Drawable(); layout.BeginVertical(xscale: true); layout.Add(drawable, yscale: true); layout.Add(button); layout.EndVertical(); Content = layout; // Run the tests in a Paint callback var startTests = false; button.Click += (s, e) => { startTests = true; drawable.Invalidate(); }; drawable.Paint += (s, e) => { if (startTests) { startTests = false; button.Enabled = false; // run the tests try { new TestRunner().RunTests<DrawingTests>(() => new DrawingTests { Drawable = drawable, Graphics = e.Graphics }); } finally { button.Enabled = true; } } }; }
public TextureBrushesSection2() { var w = image.Size.Width / 3; // same as height var img = image.Clone(new Rectangle(w, w, w, w)); var brush = new TextureBrush(img); var drawable = new Drawable(); var font = new Font(SystemFont.Default); this.Content = drawable; var location = new PointF(100, 100); drawable.BackgroundColor = Colors.Green; drawable.MouseMove += (s, e) => { location = e.Location; drawable.Invalidate(); }; drawable.Paint += (s, e) => { e.Graphics.DrawText(font, Colors.White, 3, 3, "Move the mouse in this area to move the image."); var temp = brush.Transform; // save state brush.Transform = Matrix.FromTranslation(location); e.Graphics.FillRectangle(brush, new RectangleF(location, img.Size)); brush.Transform = temp; }; }
Control PathClip() { var control = new Drawable { Size = new Size(350, 250) }; control.Paint += (sender, e) => { var path = new GraphicsPath(); path.AddEllipse(25, 25, 50, 50); path.AddRectangle(125, 25, 50, 50); path.AddLines(new PointF(225, 25), new PointF(225, 75), new PointF(275, 50)); path.CloseFigure(); e.Graphics.SetClip(path); if (ResetClip) e.Graphics.ResetClip(); e.Graphics.FillRectangle(Brushes.Blue, path.Bounds); path.Transform(Matrix.FromTranslation(0, 75)); e.Graphics.SetClip(path); if (ResetClip) e.Graphics.ResetClip(); e.Graphics.FillRectangle(Brushes.Red, path.Bounds); path.Transform(Matrix.FromTranslation(0, 75)); e.Graphics.SetClip(path); if (ResetClip) e.Graphics.ResetClip(); e.Graphics.FillRectangle(Brushes.Green, path.Bounds); }; PropertyChanged += (sender, e) => { if (e.PropertyName == "ResetClip") control.Invalidate(); }; return control; }
public ClipTransformSection() { Padding = new Padding(10); var drawable = new Drawable(); bool showInvalid = false; var showInvalidCheckBox = new CheckBox { Text = "Show Invalid Regions" }; showInvalidCheckBox.CheckedBinding.Bind(() => showInvalid, v => { showInvalid = v ?? false; drawable.Invalidate(); }); drawable.Paint += (sender, e) => { var g = e.Graphics; var rect = new RectangleF(drawable.ClientSize); Func<RectangleF> boundsRect = () => g.CurrentTransform.Inverse().TransformRectangle(rect); g.SaveTransform(); g.SetClip(new RectangleF(0, 0, 50, 50)); g.FillRectangle(Colors.Red, rect); g.TranslateTransform(50, 0); if (!showInvalid) g.FillRectangle(Colors.Green, boundsRect()); g.TranslateTransform(0, 50); g.SetClip(new RectangleF(0, 0, 50, 50)); g.FillRectangle(Colors.Red, boundsRect()); g.ScaleTransform(2, 2); g.TranslateTransform(25, 25); if (!showInvalid) g.FillRectangle(Colors.Green, boundsRect()); g.SetClip(GraphicsPath.GetRoundRect(new RectangleF(0, 0, 25, 25), 4)); g.FillRectangle(Colors.Red, boundsRect()); g.ScaleTransform(2, 2); g.TranslateTransform(25, 25); if (!showInvalid) g.FillRectangle(Colors.Green, boundsRect()); g.SetClip(new RectangleF(-25/2f, -25/2f, 25/2f, 25/2f)); g.FillRectangle(Colors.Red, boundsRect()); g.RestoreTransform(); if (!showInvalid) g.FillRectangle(Colors.Green, boundsRect()); }; var options = new StackLayout { Orientation = Orientation.Horizontal, VerticalContentAlignment = VerticalAlignment.Center, Spacing = 5, Items = { showInvalidCheckBox } }; Content = new StackLayout { Spacing = 5, HorizontalContentAlignment = HorizontalAlignment.Stretch, Items = { options, new StackLayoutItem(drawable, expand: true) } }; }