Ejemplo n.º 1
0
		public RectangleF(PointF point, SizeF size)
		{
			this.x = point.X;
			this.y = point.Y;
			this.width = size.Width;
			this.height = size.Height;
		}
Ejemplo n.º 2
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;
		}
Ejemplo n.º 3
0
		public RectangleF(SizeF size)
		{
			this.x = 0;
			this.y = 0;
			this.width = size.Width;
			this.height = size.Height;
		}
Ejemplo n.º 4
0
			public EtoGradient(PointF origin, PointF center, SizeF radius)
				: base(origin.X, origin.Y, 0, center.X, origin.Y - (origin.Y - center.Y) / (radius.Height / radius.Width), radius.Width)
			{
				
				Center = center;
				GradientOrigin = origin;
				Radius = radius;
			}
Ejemplo n.º 5
0
		public MouseEventArgs(MouseButtons buttons, Keys modifiers, PointF location, SizeF? delta = null)
		{
			this.Modifiers = modifiers;
			this.Buttons = buttons;
			this.Location = location;
			this.Pressure = 1.0f;
			this.Delta = delta ?? SizeF.Empty;
		}
Ejemplo n.º 6
0
		public object Create(Color startColor, Color endColor, PointF center, PointF gradientOrigin, SizeF radius)
		{
			var gradient = new EtoGradient(gradientOrigin, center, radius);
			gradient.Radius = radius;
			gradient.Extend = Cairo.Extend.Pad;
			gradient.AddColorStop(0, startColor.ToCairo());
			gradient.AddColorStop(1, endColor.ToCairo());
			return gradient;
		}
Ejemplo n.º 7
0
        public override Eto.Drawing.SizeF GetPreferredSize(Eto.Drawing.SizeF availableSize)
        {
            var size = base.GetPreferredSize(availableSize);

            if (!string.IsNullOrEmpty(Text))
            {
                size.Height += (float)label.Frame.Height;
            }
            return(size);
        }
Ejemplo n.º 8
0
			public Box (Size canvasSize, bool useTexturesAndGradients)
			{
				var size = new SizeF(random.Next (50) + 50, random.Next (50) + 50);
				var location = new PointF(random.Next (canvasSize.Width - (int)size.Width), random.Next (canvasSize.Height - (int)size.Height));
				position = new RectangleF(location, size);
				increment = new SizeF (random.Next (3) + 1, random.Next (3) + 1);
				if (random.Next (2) == 1)
					increment.Width = -increment.Width;
				if (random.Next (2) == 1)
					increment.Height = -increment.Height;

				angle = random.Next (360);
				rotation = (random.Next (20) - 10f) / 4f;

				var rect = new RectangleF (size);
				color = GetRandomColor (random);
				switch (random.Next (useTexturesAndGradients ? 4 : 2)) {
				case 0:
					draw = (g) => g.DrawRectangle (color, rect);
					erase = (g) => g.DrawRectangle (Colors.Black, rect);
					break;
				case 1:
					draw = (g) => g.DrawEllipse (color, rect);
					erase = (g) => g.DrawEllipse (Colors.Black, rect);
					break;
				case 2:
					switch (random.Next (2)) {
					case 0:
						fillBrush = new LinearGradientBrush (GetRandomColor (random), GetRandomColor (random), PointF.Empty, new PointF(size.Width, size.Height));
						break;
					case 1:
						fillBrush = new TextureBrush(texture) {
							Transform = Matrix.FromScale (size / 80)
						};
						break;
					}
					draw = (g) => g.FillEllipse (fillBrush, rect);
					erase = (g) => g.FillEllipse (Colors.Black, rect);
					break;
				case 3:
					switch (random.Next (2)) {
					case 0:
						fillBrush = new LinearGradientBrush (GetRandomColor (random), GetRandomColor (random), PointF.Empty, new PointF(size.Width, size.Height));
						break;
					case 1:
						fillBrush = new TextureBrush(texture) {
							Transform = Matrix.FromScale (size / 80)
						};
						break;
					}
					draw = (g) => g.FillRectangle (fillBrush, rect);
					erase = (g) => g.FillRectangle (Colors.Black, rect);
					break;
				}
			}
Ejemplo n.º 9
0
		public object Create(Color startColor, Color endColor, PointF center, PointF gradientOrigin, SizeF radius)
		{
			return new RadialBrushData
			{
				StartColor = startColor,
				EndColor = endColor,
				Center = center,
				GradientOrigin = gradientOrigin,
				Radius = radius
			};
		}
Ejemplo n.º 10
0
		public object Create(Color startColor, Color endColor, PointF center, PointF gradientOrigin, SizeF radius)
		{
			return new swm.RadialGradientBrush(startColor.ToWpf(), endColor.ToWpf())
			{
				Center = center.ToWpf(),
				GradientOrigin = gradientOrigin.ToWpf(),
				RadiusX = radius.Width,
				RadiusY = radius.Height,
				MappingMode = swm.BrushMappingMode.Absolute,
				SpreadMethod = swm.GradientSpreadMethod.Pad
			};
		}
Ejemplo n.º 11
0
		private void CreateXamlRenderTarget(SizeF size)
		{
			if (!double.IsNaN(size.Width) &&
				!double.IsNaN(size.Height) &&
				!size.IsEmpty &&
				(image == null ||
				 image.Width != size.Width ||
				 image.Height != size.Height))
			{
				if (image != null)
					image.Dispose();

				image = new Bitmap(new Size((int)size.Width, (int)size.Height), PixelFormat.Format32bppRgba);
				CreateWicTarget();
			}
		}
Ejemplo n.º 12
0
		public static SizeF GetPreferredSize(this Control control, SizeF availableSize)
		{
			if (control == null)
				return Size.Empty;
			var mh = control.GetMacControl();
			if (mh != null)
			{
				return mh.GetPreferredSize(availableSize);
			}
			
			var c = control.ControlObject as NSControl;
			if (c != null)
			{
				c.SizeToFit();
				return c.Frame.Size.ToEto();
			}
			var child = control.ControlObject as Control;
			return child == null ? SizeF.Empty : child.GetPreferredSize(availableSize);

		}
Ejemplo n.º 13
0
		public void Align(SizeF size)
		{
			Align(size.Width, size.Height);
		}
Ejemplo n.º 14
0
 /// <summary>
 /// Aligns the rectangle to a grid of the specified <paramref name="gridSize"/>
 /// </summary>
 /// <remarks>
 /// This will align the top, left, right, and bottom to a grid by inflating each edge to the next grid line.
 /// </remarks>
 /// <param name="gridSize">Size of the grid to align the rectangle to</param>
 public void Align(SizeF gridSize)
 {
     Align(gridSize.Width, gridSize.Height);
 }
Ejemplo n.º 15
0
		public void Restrict(PointF point, SizeF size)
		{
			Restrict(new RectangleF(point, size));
		}
Ejemplo n.º 16
0
 public static Size2 ToClarity(this ed.SizeF etoSize) =>
 new Size2(etoSize.Width, etoSize.Height);
Ejemplo n.º 17
0
 /// <summary>
 /// Initializes a new instance of the Rectangle class with X, Y co-ordinates at 0,0 and the specified <paramref name="size"/>
 /// </summary>
 /// <param name="size">Size to give the rectangle</param>
 public RectangleF(SizeF size)
 {
     this.location = new PointF(0, 0);
     this.size     = size;
 }
Ejemplo n.º 18
0
		public void Offset(SizeF size)
		{
			this.x += size.Width;
			this.y += size.Height;
		}
Ejemplo n.º 19
0
		static bool MouseEvent(BubbleEventArgs be, Action<Control, MouseEventArgs> action, bool? capture, Func<MouseButtons, MouseButtons> modifyButtons = null)
		{
			var modifiers = swf.Control.ModifierKeys.ToEto();
			var delta = new SizeF(0, Win32.GetWheelDeltaWParam(be.Message.WParam) / Conversions.WheelDelta);
			var buttons = Win32.GetMouseButtonWParam(be.Message.WParam).ToEto();
			if (modifyButtons != null)
				buttons = modifyButtons(buttons);
			var handler = be.WindowsControl;
			var mousePosition = swf.Control.MousePosition.ToEto();
			var ret = false;
			foreach (var control in be.Controls)
			{
				var me = new MouseEventArgs(buttons, modifiers, control.PointFromScreen(mousePosition), delta);
				action(control, me);
				if (me.Handled)
				{
					ret = true;
					break;
				}
			}
			if (capture != null && ret || (handler != null && handler.ShouldCaptureMouse))
			{
				//be.WinControl.Capture = capture.Value;
			}
			return ret;
		}
Ejemplo n.º 20
0
		public static CGRect SetSize(this CGRect frame, SizeF size)
		{
			frame.Size = size.ToNS();
			return frame;
		}
Ejemplo n.º 21
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="style"></param>
        /// <param name="rect"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        private PointF GetTextOrigin(ShapeStyle style, ref RectangleF rect, ref SizeF size)
        {
            float ox, oy;

            switch (style.TextStyle.TextHAlignment)
            {
                case TextHAlignment.Left:
                    ox = rect.X;
                    break;
                case TextHAlignment.Right:
                    ox = rect.Right - size.Width;
                    break;
                case TextHAlignment.Center:
                default:
                    ox = (rect.Left + rect.Width / 2f) - (size.Width / 2f);
                    break;
            }

            switch (style.TextStyle.TextVAlignment)
            {
                case TextVAlignment.Top:
                    oy = rect.TopLeft.Y;
                    break;
                case TextVAlignment.Bottom:
                    oy = rect.Bottom - size.Height;
                    break;
                case TextVAlignment.Center:
                default:
                    oy = (rect.Bottom - rect.Height / 2f) - (size.Height / 2f);
                    break;
            }

            return new PointF(ox, oy);
        }
Ejemplo n.º 22
0
		/// <summary>
		/// Creates a new matrix with the specified <paramref name="scale"/>
		/// </summary>
		/// <returns>A new matrix with a scale transform</returns>
		/// <param name="scale">Scale size for the X and Y coordinates</param>
		/// <param name="generator">Generator to create the matrix</param>
		public static IMatrix FromScale (SizeF scale, Generator generator = null)
		{
			return FromScale (scale.Width, scale.Height, generator);
		}
Ejemplo n.º 23
0
		/// <summary>
		/// Creates a new matrix with a <paramref name="scale"/> at the specified <paramref name="center"/> point
		/// </summary>
		/// <returns>A new matrix with a scale transform</returns>
		/// <param name="scale">The amount to multiply coordinates by</param>
		/// <param name="center">Point to scale from</param>
		/// <param name="generator">Generator to create the matrix</param>
		public static IMatrix FromScaleAt (SizeF scale, PointF center, Generator generator = null)
		{
			return FromScaleAt (scale.Width, scale.Height, center.X, center.Y, generator);
		}
Ejemplo n.º 24
0
 /// <summary>
 /// Restricts the rectangle to be within the specified <paramref name="size"/> at an X,Y location of 0, 0
 /// </summary>
 /// <remarks>
 /// This is a shortcut for <seealso cref="Restrict(Rectangle)"/>
 /// </remarks>
 /// <param name="size">Maxiumum size for the rectangle</param>
 public void Restrict(SizeF size)
 {
     Restrict(new RectangleF(size));
 }
Ejemplo n.º 25
0
		public sd.RenderTarget InitializeControl()
		{
			var sizeF = new SizeF((float)drawableHandler.Control.Width, (float)drawableHandler.Control.Height);
			CreateXamlRenderTarget(sizeF);
			return Control;
		}
Ejemplo n.º 26
0
			public Box(Size canvasSize, bool useTexturesAndGradients, DirectDrawingRenderer renderer)
			{
				this.renderer = renderer;
				var size = new SizeF(random.Next(50) + 50, random.Next(50) + 50);
				var location = new PointF(random.Next(canvasSize.Width - (int)size.Width), random.Next(canvasSize.Height - (int)size.Height));
				position = new RectangleF(location, size);
				increment = new SizeF(random.Next(3) + 1, random.Next(3) + 1);
				if (random.Next(2) == 1)
					increment.Width = -increment.Width;
				if (random.Next(2) == 1)
					increment.Height = -increment.Height;

				angle = random.Next(360);
				rotation = (random.Next(20) - 10f) / 4f;

				var rect = new RectangleF(size);
				color = GetRandomColor(random);
				var colorPen = new Pen(color, generator: renderer.Generator);
				var blackPen = Pens.Black(renderer.Generator);
				var blackBrush = Brushes.Black(renderer.Generator);
				switch (random.Next(useTexturesAndGradients ? 4 : 2))
				{
					case 0:
						draw = g => g.DrawRectangle(colorPen, rect);
						erase = g => g.DrawRectangle(blackPen, rect);
						break;
					case 1:
						draw = g => g.DrawEllipse(colorPen, rect);
						erase = g => g.DrawEllipse(blackPen, rect);
						break;
					case 2:
						switch (random.Next(2))
						{
							case 0:
								fillBrush = new LinearGradientBrush(GetRandomColor(random), GetRandomColor(random), PointF.Empty, new PointF(size.Width, size.Height), renderer.Generator);
								break;
							case 1:
								fillBrush = new TextureBrush(renderer.texture, 1f, renderer.Generator)
								{
									Transform = Matrix.FromScale(size / 80, renderer.Generator)
								};
								break;
						}
						draw = g => g.FillEllipse(fillBrush, rect);
						erase = g => g.FillEllipse(blackBrush, rect);
						break;
					case 3:
						switch (random.Next(2))
						{
							case 0:
								fillBrush = new LinearGradientBrush(GetRandomColor(random), GetRandomColor(random), PointF.Empty, new PointF(size.Width, size.Height), renderer.Generator);
								break;
							case 1:
								fillBrush = new TextureBrush(renderer.texture, 1f, renderer.Generator)
								{
									Transform = Matrix.FromScale(size / 80, renderer.Generator)
								};
								break;
						}
						draw = g => g.FillRectangle(fillBrush, rect);
						erase = g => g.FillRectangle(blackBrush, rect);
						break;
				}
			}
Ejemplo n.º 27
0
 /// <summary>
 /// Restricts the rectangle to be within the specified <paramref name="location"/> and <paramref name="size"/>
 /// </summary>
 /// <remarks>
 /// This is a shortcut for <seealso cref="Restrict(Rectangle)"/>
 /// </remarks>
 /// <param name="location">Minimum location for the rectangle</param>
 /// <param name="size">Maximum size for the rectangle</param>
 public void Restrict(PointF point, SizeF size)
 {
     Restrict(new RectangleF(point, size));
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Initializes a new instance of the Rectangle class with the specified <paramref name="location"/> and <paramref name="size"/>
 /// </summary>
 /// <param name="location">Location of the rectangle</param>
 /// <param name="size">Size of the rectangle</param>
 public RectangleF(PointF location, SizeF size)
 {
     this.location = location;
     this.size     = size;
 }
Ejemplo n.º 29
0
 /// <summary>
 /// Offsets the location of the rectangle by the specified <paramref name="size"/>
 /// </summary>
 /// <param name="size">Width and Height to move the rectangle</param>
 public void Offset(SizeF size)
 {
     this.location.X += size.Width;
     this.location.Y += size.Height;
 }
Ejemplo n.º 30
0
		/// <summary>
		/// Prepend a scale to the matrix from the specified point
		/// </summary>
		/// <param name="matrix">Matrix to scale</param>
		/// <param name="scale">The amount to multiply coordinates</param>
		/// <param name="center">Point to scale from</param>
		public static void ScaleAt (this IMatrix matrix, SizeF scale, PointF center)
		{
			matrix.ScaleAt (scale.Width, scale.Height, center.X, center.Y);
		}
Ejemplo n.º 31
0
		public static MouseEventArgs GetMouseEvent(NSView view, NSEvent theEvent, bool includeWheel)
		{
			var pt = MacConversions.GetLocation(view, theEvent);
			Keys modifiers = theEvent.ModifierFlags.ToEto();
			MouseButtons buttons = theEvent.GetMouseButtons();
			SizeF? delta = null;
			if (includeWheel)
				delta = new SizeF((float)theEvent.DeltaX, (float)theEvent.DeltaY);
			return new MouseEventArgs(buttons, modifiers, pt, delta);
		}
Ejemplo n.º 32
0
		void UpdateSize(SizeF? topLeft = null, SizeF? bottomRight = null, SizeF? topRight = null, SizeF? bottomLeft = null)
		{
			var bounds = SizeBounds;

			if (topLeft != null)
				bounds.TopLeft += topLeft.Value;
			if (topRight != null)
				bounds.TopRight += topRight.Value;
			if (bottomLeft != null)
				bounds.BottomLeft += bottomLeft.Value;
			if (bottomRight != null)
				bounds.BottomRight += bottomRight.Value;
			SizeBounds = bounds;
		}
Ejemplo n.º 33
0
 /// <summary>
 /// Initializes a new instance of the Rectangle class with the specified <paramref name="x"/>, <paramref name="y"/>, <paramref name="width"/>, and <paramref name="height"/>
 /// </summary>
 /// <param name="x">X co-ordinate for the location of the rectangle</param>
 /// <param name="y">Y co-ordinate for the location of the rectangle</param>
 /// <param name="width">Width of the rectangle</param>
 /// <param name="height">Height of the rectangle</param>
 public RectangleF(float x, float y, float width, float height)
 {
     this.location = new PointF(x, y);
     this.size     = new SizeF(width, height);
 }
Ejemplo n.º 34
0
 /// <summary>
 /// Inflates all dimensions of this rectangle by the specified <paramref name="size"/>
 /// </summary>
 /// <remarks>
 /// This inflates the rectangle in all dimensions by the width and height specified by <paramref name="size"/>.
 /// The resulting rectangle will be increased in width and height twice that of the specified size, and the center
 /// will be in the same location.
 /// A negative width and/or height can be passed in to deflate the rectangle.
 /// </remarks>
 /// <param name="size">Size to inflate the rectangle by</param>
 public void Inflate(SizeF size)
 {
     Inflate(size.Width, size.Height);
 }
Ejemplo n.º 35
0
		public object Create(Color startColor, Color endColor, PointF center, PointF gradientOrigin, SizeF radius)
		{
			return new BrushObject
			{
				Center = center,
				GradientOrigin = gradientOrigin,
				Radius = radius,
				StartColor = startColor,
				EndColor = endColor
			};
		}
Ejemplo n.º 36
0
		public PrintPageEventArgs (Graphics graphics, SizeF pageSize, int currentPage)
		{
			this.Graphics = graphics;
			this.PageSize = pageSize;
			this.CurrentPage = currentPage;
		}
Ejemplo n.º 37
0
		/// <summary>
		/// Creates a new matrix with a translation
		/// </summary>
		/// <returns>A new translation matrix</returns>
		/// <param name="offset">Offset to translate by</param>
		/// <param name="generator">Generator to create the matrix</param>
		public static IMatrix FromTranslation (SizeF offset, Generator generator = null)
		{
			return FromTranslation (offset.Width, offset.Height, generator);
		}
Ejemplo n.º 38
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Eto.Drawing.RadialGradientBrush"/>.
 /// </summary>
 /// <param name="startColor">Start color from the <paramref name="gradientOrigin"/></param>
 /// <param name="endColor">End color at the outer edge of the ellipse</param>
 /// <param name="center">Center of the ellipse</param>
 /// <param name="gradientOrigin">Origin of the gradient.</param>
 /// <param name="radius">Radius of the ellipse.</param>
 public RadialGradientBrush(Color startColor, Color endColor, PointF center, PointF gradientOrigin, SizeF radius)
 {
     handler       = Platform.Instance.CreateShared <IHandler>();
     ControlObject = handler.Create(startColor, endColor, center, gradientOrigin, radius);
 }
Ejemplo n.º 39
0
		/// <summary>
		/// Prepend a translation to the matrix
		/// </summary>
		/// <param name="matrix">Matrix to translate</param>
		/// <param name="offset">The amount to offset</param>
		public static void Translate (this IMatrix matrix, SizeF offset)
		{
			matrix.Translate (offset.Width, offset.Height);
		}
Ejemplo n.º 40
0
		/// <summary>
		/// Prepend a scale to the matrix from the origin (0, 0)
		/// </summary>
		/// <param name="matrix">Matrix to scale</param>
		/// <param name="scale">The amount to multiply coordinates</param>
		public static void Scale (this IMatrix matrix, SizeF scale)
		{
			matrix.Scale (scale.Width, scale.Height);
		}
Ejemplo n.º 41
0
		public static MouseEventArgs ToEto(this swi.MouseWheelEventArgs e, sw.IInputElement control, swi.MouseButtonState buttonState = swi.MouseButtonState.Pressed)
		{
			var buttons = MouseButtons.None;
			if (e.LeftButton == buttonState)
				buttons |= MouseButtons.Primary;
			if (e.RightButton == buttonState)
				buttons |= MouseButtons.Alternate;
			if (e.MiddleButton == buttonState)
				buttons |= MouseButtons.Middle;
			var modifiers = Keys.None;
			var location = e.GetPosition(control).ToEto();
			var delta = new SizeF(0, (float)e.Delta / WheelDelta);

			return new MouseEventArgs(buttons, modifiers, location, delta);
		}
Ejemplo n.º 42
0
 /// <summary>
 /// Initializes a new instance of the Rectangle class with two points
 /// </summary>
 /// <remarks>
 /// This will always create a normalized rect, in that the location will be the minimum of the X and Y co-ordinates of the supplied
 /// points.
 /// </remarks>
 /// <param name="start">Starting point of the rectangle</param>
 /// <param name="end">Ending point of the rectangle</param>
 public RectangleF(PointF start, PointF end)
 {
     location = start;
     size     = new SizeF((end.X >= start.X) ? end.X - start.X + 1 : end.X - start.X, (end.Y >= start.Y) ? end.Y - start.Y + 1: end.Y - start.Y);
 }