Beispiel #1
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);
			};
		}
Beispiel #2
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 {
                Padding = 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);
                    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);
            };
        }
Beispiel #3
0
        public TextureBrushesSection2()
        {
            image = TestIcons.Textures;
            var drawable       = new Drawable();
            var drawableTarget = new DrawableTarget(drawable);
            var layout         = new DynamicLayout {
                Padding = new Padding(10)
            };

            layout.AddSeparateRow(null, drawableTarget.Checkbox(), null);
            layout.Add(drawable);
            this.Content = layout;

            var w                   = image.Size.Width / 3; // same as height
            var img                 = image.Clone(new Rectangle(w, w, w, w));
            var textureBrush        = new TextureBrush(img);
            var solidBrush          = new SolidBrush(Colors.Blue);
            var linearGradientBrush = new LinearGradientBrush(Colors.White, Colors.Black, PointF.Empty, new PointF(0, 100), Platform);
            var font                = SystemFonts.Default();

            drawable.BackgroundColor = Colors.Green;
            drawable.MouseMove      += HandleMouseMove;
            drawable.MouseDown      += HandleMouseMove;

            drawable.Paint += (s, e) =>
            {
                var graphics = drawableTarget.BeginDraw(e);

                graphics.DrawText(font, Colors.White, 3, 3, "Move the mouse in this area to move the shapes.");
                // texture brushes
                var temp = location;
                DrawShapes(textureBrush, temp, img.Size, graphics);
                // solid brushes
                temp = temp + new PointF(200, 0);
                DrawShapes(solidBrush, temp, img.Size, graphics);
                // linear gradient brushes
                temp = temp + new PointF(200, 0);
                DrawShapes(linearGradientBrush, temp, img.Size, graphics);

                drawableTarget.EndDraw(e);
            };
        }
		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);
			};
		}
Beispiel #5
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);
            };
        }
		public TextureBrushesSection2()
		{
			image = TestIcons.Textures;
			var drawable = new Drawable();
			var drawableTarget = new DrawableTarget(drawable);
			var layout = new DynamicLayout { Padding = new Padding(10) };
			layout.AddSeparateRow(null, drawableTarget.Checkbox(), null);
			layout.Add(drawable);
			this.Content = layout;

			var w = image.Size.Width / 3; // same as height
			var img = image.Clone(new Rectangle(w, w, w, w));
			var textureBrush = new TextureBrush(img);
			var solidBrush = new SolidBrush(Colors.Blue);
			var linearGradientBrush = new LinearGradientBrush(Colors.White, Colors.Black, PointF.Empty, new PointF(0, 100), Platform);
			var font = SystemFonts.Default();
			drawable.BackgroundColor = Colors.Green;
			drawable.MouseMove += HandleMouseMove;
			drawable.MouseDown += HandleMouseMove;

			drawable.Paint += (s, e) =>
			{
				var graphics = drawableTarget.BeginDraw(e);

				graphics.DrawText(font, Colors.White, 3, 3, "Move the mouse in this area to move the shapes.");
				// texture brushes
				var temp = location;
				DrawShapes(textureBrush, temp, img.Size, graphics);
				// solid brushes
				temp = temp + new PointF(200, 0);
				DrawShapes(solidBrush, temp, img.Size, graphics);
				// linear gradient brushes
				temp = temp + new PointF(200, 0);
				DrawShapes(linearGradientBrush, temp, img.Size, graphics);

				drawableTarget.EndDraw(e);
			};
		}