Esempio n. 1
1
		Control LargeCanvas ()
		{
			var control = new Drawable{
				Size = new Size (1000, 1000),
				BackgroundColor = Colors.Blue
			};
			var image = Bitmap.FromResource ("Eto.Test.TestImage.png");
			control.Paint += delegate(object sender, PaintEventArgs pe) {
				pe.Graphics.FillRectangle (Colors.Black, new Rectangle (150, 150, 100, 100));
				var inc = 400;
				for (int i = 0; i <= control.Size.Width / inc; i++) {
					var pos = i * inc;
					pe.Graphics.DrawLine (Colors.White, new Point (pos, 0), new Point (pos + control.Size.Width, control.Size.Height));
					pe.Graphics.DrawLine (Colors.White, new Point (pos, 0), new Point (pos - control.Size.Width, control.Size.Height));
				}
				var lpos = 100;
				pe.Graphics.DrawLine (Colors.White, new Point (0, lpos), new Point (control.Size.Width, lpos));
				pe.Graphics.DrawLine (Colors.White, new Point (lpos, 0), new Point (lpos, control.Size.Height));
				pe.Graphics.DrawImage (image, 100, 10);
				pe.Graphics.DrawImage (image, 250, 10, 80, 20);
			};
			LogEvents (control);

			var layout = new PixelLayout (new Scrollable {
				Size = new Size (450, 250)
			});
			layout.Add (control, 25, 25);
			return layout.Container;
		}
Esempio n. 2
0
		/// <summary>
		/// Test paint operations on a drawable
		/// </summary>
		/// <param name="paint">Delegate to execute during the paint event</param>
		/// <param name="size">Size of the drawable, or null for 200x200</param>
		/// <param name="timeout">Timeout to wait for the operation to complete</param>
		public static void Paint(Action<Drawable, PaintEventArgs> paint, Size? size = null, int timeout = DefaultTimeout)
		{
			Exception exception = null;
			Form(form =>
			{
				var drawable = new Drawable { Size = size ?? new Size(200, 200) };
				drawable.Paint += (sender, e) =>
				{
					try
					{
						paint(drawable, e);
					}
					catch (Exception ex)
					{
						exception = ex;
					}
					finally
					{
						Application.Instance.AsyncInvoke(form.Close);
					}
				};
				form.Content = drawable;
			}, timeout);
			if (exception != null)
				throw new Exception("Paint event caused exception", exception);
		}
Esempio n. 3
0
		public GetPixelSection()
		{
			var location = new Point(100, 100);
			var image = TestIcons.Textures;
			var drawable = new Drawable();
			var drawableTarget = new DrawableTarget(drawable) { UseOffScreenBitmap = true };
			this.Content = drawable;

			EventHandler<MouseEventArgs> mouseHandler = (s, e) => {
				location = new Point(e.Location);
				((Control)s).Invalidate();
				e.Handled = true;
			};

			drawable.MouseMove += mouseHandler;
			drawable.MouseDown += mouseHandler;

			var font = SystemFonts.Default();
			drawable.BackgroundColor = Colors.Green;
			drawable.Paint += (s, e) => {
				var graphics = drawableTarget.BeginDraw(e);
				var imageLocation = new PointF(100, 100);
				graphics.DrawText(font, Colors.White, 3, 3, "Move the mouse in this area to read the pixel color.");
				graphics.DrawImage(image, imageLocation);

				var loc = location - (Point)imageLocation;
				loc.Restrict(new Rectangle(image.Size));
				var pixelColor = image.GetPixel(loc.X, loc.Y);
				graphics.DrawText(font, Colors.White, 3, 20, "Color: " + pixelColor);

				drawableTarget.EndDraw(e);
			};
		}
Esempio n. 4
0
		public BrushSection()
		{
			var layout = new DynamicLayout { DefaultSpacing = new Size(5, 5), Padding = new Padding(10) };

			// defaults
			ScaleX = 100f;
			ScaleY = 100f;
			Center = new PointF(100, 50);
			GradientOrigin = new PointF(150, 80);
			Radius = new SizeF(100f, 50f);
			StartPoint = new PointF(50, 50);
			EndPoint = new PointF(100, 100);

			drawable = new Drawable { Size = new Size(450, 400) };

			drawable.Paint += (sender, pe) => Draw(pe.Graphics);

			layout.AddSeparateRow(null, BrushControl(), UseBackgroundColorControl(), null);
			if (Platform.Supports<NumericUpDown>())
			{
				matrixRow = layout.AddSeparateRow(null, new Label { Text = "Rot" }, RotationControl(), new Label { Text = "Sx" }, ScaleXControl(), new Label { Text = "Sy" }, ScaleYControl(), new Label { Text = "Ox" }, OffsetXControl(), new Label { Text = "Oy" }, OffsetYControl(), null);
				matrixRow.Table.Visible = false;
			}
			gradientRow = layout.AddSeparateRow(null, GradientWrapControl(), null);
			gradientRow.Table.Visible = false;
			radialRow = layout.AddSeparateRow(null, "Center:", CenterControl(), "GradientOrigin:", GradientOriginControl(), null);
			radiusRow = layout.AddSeparateRow(null, "Radius:", RadiusControl(), null);
			linearRow = layout.AddSeparateRow(null, "Start:", StartPointControl(), "End:", EndPointControl(), null);
			layout.AddSeparateRow(null, drawable, null);
			layout.Add(null);

			this.Content = layout;
		}
Esempio n. 5
0
		Control LargeCanvas()
		{
			var control = new Drawable
			{
				Size = new Size (1000, 1000),
				BackgroundColor = Colors.Blue
			};
			var image = TestIcons.TestImage();
			control.Paint += delegate(object sender, PaintEventArgs pe)
			{
				pe.Graphics.FillRectangle(Brushes.Black(), new Rectangle(150, 150, 100, 100));
				var whitePen = Pens.White();
				const int inc = 400;
				for (int i = 0; i <= control.Size.Width / inc; i++)
				{
					var pos = i * inc;
					pe.Graphics.DrawLine(whitePen, new Point(pos, 0), new Point(pos + control.Size.Width, control.Size.Height));
					pe.Graphics.DrawLine(whitePen, new Point(pos, 0), new Point(pos - control.Size.Width, control.Size.Height));
				}
				const int lpos = 100;
				pe.Graphics.DrawLine(whitePen, new Point(0, lpos), new Point(control.Size.Width, lpos));
				pe.Graphics.DrawLine(whitePen, new Point(lpos, 0), new Point(lpos, control.Size.Height));
				pe.Graphics.DrawImage(image, 100, 10);
				pe.Graphics.DrawImage(image, 250, 10, 80, 20);
			};
			LogEvents(control);

			var layout = new PixelLayout();
			layout.Add(control, 25, 25);
			return new Scrollable
			{
				Size = new Size (250, 250),
				Content = layout
			};
		}
Esempio n. 6
0
		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;
		}
Esempio n. 7
0
		public TransformSection()
		{
			image = TestIcons.TestIcon;
			font = Fonts.Sans(10);

			var layout = new DynamicLayout();

			var drawable = new Drawable { Size = canvasSize };
			drawable.Paint += (sender, pe) => {
				pe.Graphics.FillRectangle(Brushes.Black, pe.ClipRectangle);
				MatrixTests(pe.Graphics);
			};
			layout.AddRow(new Label { Text = "Matrix" }, drawable);

			drawable = new Drawable { Size = canvasSize };
			drawable.Paint += (sender, pe) => {
				pe.Graphics.FillRectangle(Brushes.Black, pe.ClipRectangle);
				DirectTests(pe.Graphics);
			};
			layout.AddRow(new Label { Text = "Direct" }, drawable);
			layout.Add(null);

			var m = Matrix.Create();
			m.Scale(100, 100);
			var m2 = m.Clone();
			m2.Translate(10, 10);

			if (m == m2)
				throw new Exception("Grr!");

			Content = layout;
		}
Esempio n. 8
0
		public BrushSection()
		{
			var layout = new DynamicLayout();
			brush = solidBrush = Brushes.LightSkyBlue;
			gradientBrush = new LinearGradientBrush(Colors.AliceBlue, Colors.Black, new PointF(0, 0), new PointF(100f, 100f));
			//gradientBrush = new LinearGradientBrush (new RectangleF (0, 0, 50, 50), Colors.AliceBlue, Colors.Black, 10);
			gradientBrush.Wrap = GradientWrapMode.Repeat;
			textureBrush = new TextureBrush(image, 0.5f);
			brush = textureBrush;

			ScaleX = 100f;
			ScaleY = 100f;

			drawable = new Drawable { Size = new Size(300, 200) };

			drawable.Paint += (sender, pe) => Draw(pe.Graphics);

			layout.AddSeparateRow(null, BrushControl(), UseBackgroundColorControl(), null);
			if (Platform.Supports<NumericUpDown>())
			{
				matrixRow = layout.AddSeparateRow(null, new Label { Text = "Rot" }, RotationControl(), new Label { Text = "Sx" }, ScaleXControl(), new Label { Text = "Sy" }, ScaleYControl(), new Label { Text = "Ox" }, OffsetXControl(), new Label { Text = "Oy" }, OffsetYControl(), null);
				matrixRow.Table.Visible = false;
			}
			gradientRow = layout.AddSeparateRow(null, GradientWrapControl(), null);
			gradientRow.Table.Visible = false;
			layout.AddSeparateRow(null, drawable, null);
			layout.Add(null);

			this.Content = layout;
		}
Esempio n. 9
0
		Control CreateIndexedDrawable()
		{
			var control = new Drawable { Size = new Size(100, 100) };
			var image = CreateImage();
			control.Paint += (sender, pe) => pe.Graphics.DrawImage(image, 0, 0);
			return control;
		}
Esempio n. 10
0
		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;
		}
Esempio n. 11
0
		public PixelOffsetSection()
		{
			var layout = new DynamicLayout { DefaultSpacing = new Size(5, 5), Padding = new Padding(10) };

			var drawable = new Drawable { Size = canvasSize };
			drawable.Paint += (sender, pe) =>
			{
				pe.Graphics.FillRectangle(Brushes.Black, pe.ClipRectangle);
				pe.Graphics.PixelOffsetMode = PixelOffsetMode.None;
				Draw(pe.Graphics);
			};
			layout.AddRow(new Label { Text = "None (Default)" }, drawable);

			drawable = new Drawable { Size = canvasSize };
			drawable.Paint += (sender, pe) =>
			{
				pe.Graphics.FillRectangle(Brushes.Black, pe.ClipRectangle);
				pe.Graphics.PixelOffsetMode = PixelOffsetMode.Half;
				Draw(pe.Graphics);
			};
			layout.AddRow(new Label { Text = "Half" }, drawable);
			layout.Add(null);

			Content = layout;
		}
Esempio n. 12
0
		Control ScreenLayout()
		{
			var drawable = new Drawable();
			drawable.Paint += (sender, pe) =>
			{
				var scaleSize = (SizeF)drawable.Size / displayBounds.Size;
				var scale = Math.Min(scaleSize.Width, scaleSize.Height);
				var offset = (drawable.Size - (displayBounds.Size * scale)) / 2;
				offset.Height -= displayBounds.Y * scale;
                offset = Size.Round(offset);
				foreach (var screen in screens)
				{
					var screenBounds = (screen.Bounds * scale) + offset;
                    screenBounds.Size -= 1;

                    pe.Graphics.FillRectangle(Colors.White, screenBounds);

					var workingArea = (screen.WorkingArea * scale) + offset;
					pe.Graphics.FillRectangle(Colors.Blue, workingArea);

					pe.Graphics.DrawRectangle(Colors.Black, screenBounds);
				}

                var windowBounds = ((RectangleF)ParentWindow.Bounds * scale) + offset;
                windowBounds.Size -= 1;
                pe.Graphics.FillRectangle(new Color(Colors.LightSkyBlue, 0.8f), windowBounds);
                pe.Graphics.DrawRectangle(Colors.White, windowBounds);
			};
			return drawable;
		}
Esempio n. 13
0
		public TextureBrushesSection()
		{
			var layout = new DynamicLayout();
			for (var i = 0; i < 10; ++i)
			{
				var w = image.Size.Width / 3; // same as height
				var img = image;
				if (i > 0)
					img = img.Clone(new Rectangle((i - 1) % 3 * w, (i - 1) / 3 * w, w, w));

				var brush = new TextureBrush(img);
				var drawable = new Drawable { Size = image.Size * 2 };

				drawable.Paint += (s, e) => {
					var destRect = new RectangleF(new PointF(100, 100), image.Size);
					var temp = brush.Transform; // save state
					brush.Transform = Matrix.FromRotation(90);
					e.Graphics.TranslateTransform(destRect.Location);
					e.Graphics.FillRectangle(brush, new RectangleF(destRect.Size));
					brush.Transform = temp;
				};
				layout.AddRow(drawable);
			}
			layout.Add(null);
			Content = layout;
		}
Esempio n. 14
0
		Control CreateIndexedDrawable ()
		{
			var control = new Drawable { Size = new Size(100, 100) };
			var image = CreateImage();
			control.Paint += delegate(object sender, PaintEventArgs pe) {
				pe.Graphics.DrawImage (image, 0, 0);
			};
			return control;
		}
Esempio n. 15
0
		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;
		}
Esempio n. 16
0
		Control FillLinePath ()
		{
			var control = new Drawable { Size = new Size (100, 100), BackgroundColor = Color.Black };

			var path = CreatePath ();
			control.Paint += (sender, e) => {
				e.Graphics.FillPath (Color.White, path);
			};

			return control;
		}
Esempio n. 17
0
		Control Default ()
		{
			var control = new Drawable {
				Size = new Size (150, 50)
			};
			control.Paint += delegate (object sender, PaintEventArgs pe) {
				pe.Graphics.DrawLine (Colors.Black, Point.Empty, new Point (control.Size));
			};
			LogEvents (control);

			return control;
		}
Esempio n. 18
0
		Control AntialiasOff()
		{
			var control = new Drawable { Size = new Size (100, 100), BackgroundColor = Colors.Black };

			var path = CreatePath();
			control.Paint += (sender, e) => {
				e.Graphics.Antialias = false;
				e.Graphics.DrawPath(Pens.White(), path);
			};

			return control;
		}
Esempio n. 19
0
		public DrawLoopSection()
		{
			drawable = new Drawable
			{
				Style = "direct",
				BackgroundColor = Colors.Black
			};
			drawable.Paint += (sender, e) => renderer.DrawFrame(e.Graphics, drawable.Size);
			renderer = new DirectDrawingRenderer();

			var layout = new DynamicLayout(new Padding(10));
			layout.AddSeparateRow(null, UseTexturesAndGradients(), UseCreateGraphics(), null);
			layout.Add(content = new Panel { Content = drawable });
			this.Content = layout;
		}
Esempio n. 20
0
		Control WithBackground()
		{
			var control = new Drawable
			{
				Size = new Size (50, 50),
				BackgroundColor = Colors.Lime
			};
			control.Paint += delegate (object sender, PaintEventArgs pe)
			{
				pe.Graphics.DrawLine(Pens.Black(), Point.Empty, new Point(control.Size));
			};
			LogEvents(control);

			return control;
		}
Esempio n. 21
0
		Control CreateImage(ImageInterpolation interpolation)
		{
			var image = TestIcons.TestImage;
			var drawable = new Drawable { Size = new Size(250, 160) };

			drawable.Paint += (sender, pe) =>
			{
				pe.Graphics.ImageInterpolation = interpolation;
				pe.Graphics.DrawImage(image, 0, 0, 20, 20);
				pe.Graphics.DrawImage(image, 0, 20, 50, 50);
				pe.Graphics.DrawImage(image, 0, 70, 100, 100);
				pe.Graphics.DrawImage(image, 120, 0, 300, 300);
			};

			return drawable;
		}
Esempio n. 22
0
		Control Default ()
		{
			var control = new Drawable { Size = new Size (400, 400), BackgroundColor = Colors.Black };

			control.Paint += (sender, e) => {
				var g = e.Graphics;

				float y = 0;
				foreach (var info in GetDrawInfo ()) {
					var size = g.MeasureString (info.Font, info.Text);
					g.DrawText (info.Font, Colors.White, 10, (int)y, info.Text);
					y += size.Height;
				}
			};

			return control;
		}
Esempio n. 23
0
		Control CreateImage (ImageInterpolation interpolation)
		{
			var resourceStream = GetType().Assembly.GetManifestResourceStream ("Eto.Test.TestImage.png");

			var image = new Bitmap (resourceStream);
			var drawable = new Drawable { Size = new Size(250, 160) };

			drawable.Paint += (sender, pe) => {
				pe.Graphics.ImageInterpolation = interpolation;
				pe.Graphics.DrawImage (image, 0, 0, 20, 20);
				pe.Graphics.DrawImage (image, 0, 20, 50, 50);
				pe.Graphics.DrawImage (image, 0, 70, 100, 100);
				pe.Graphics.DrawImage (image, 120, 0, 300, 300);
			};

			return drawable;
		}
Esempio n. 24
0
		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;
			};
		}
Esempio n. 26
0
		public TextureBrushesSection()
		{
			var image = TestIcons.Textures();
			var drawable = new Drawable { Size = new Size(image.Size.Width, image.Size.Height * 10) };
			var drawableTarget = new DrawableTarget(drawable);
			var layout = new DynamicLayout(new Padding(10));
			layout.AddSeparateRow(null, drawableTarget.Checkbox(), null);
			layout.Add(new Scrollable { Content = drawable });
			Content = layout;

			var renderers = new List<Action<Graphics>>();

			for (var i = 0; i < 10; ++i)
			{
				var w = image.Size.Width / 3; // same as height
				var img = image;
				if (i > 0)
					img = img.Clone(new Rectangle((i - 1) % 3 * w, (i - 1) / 3 * w, w, w));

				var brush = new TextureBrush(img);

				renderers.Add(graphics =>
				{
					var temp = brush.Transform; // save state
					brush.Transform = Matrix.FromRotation(90, Generator);
					graphics.FillRectangle(brush, new RectangleF(image.Size));
					graphics.TranslateTransform(0, image.Size.Height);
					brush.Transform = temp;
				});
			}

			drawable.Paint += (s, e) =>
			{
				var graphics = drawableTarget.BeginDraw(e);
				foreach (var renderer in renderers)
					renderer(graphics);
				drawableTarget.EndDraw(e);
			};
		}
Esempio n. 27
0
		void LogEvents(Drawable control)
		{
			control.Paint += delegate (object sender, PaintEventArgs pe)
			{
				Log.Write(control, "Paint, ClipRectangle: {0}", pe.ClipRectangle);
			};
		}
Esempio n. 28
0
			/// <summary>
			/// Raises the paint event.
			/// </summary>
			public void OnPaint(Drawable widget, PaintEventArgs e)
			{
				widget.Platform.Invoke(() => widget.OnPaint(e));
			}
Esempio n. 29
0
		Control DrawableControl()
		{
			var control = new Drawable { Size = new Size(100, 30), CanFocus = true };
			control.Paint += delegate(object sender, PaintEventArgs pe)
			{
				pe.Graphics.FillRectangle(Brushes.Blue(), pe.ClipRectangle);
			};
			LogEvents(control);
			return control;
		}
Esempio n. 30
0
		Drawable GetDrawable()
		{
			drawable = new Drawable
			{
				Size = new Size (560, 300)
			};
			drawable.Paint += (sender, pe) => {
				Draw(pe.Graphics, null);
			};
			return drawable;
		}