/// <summary> /// Nastaví dané souřadnice do Owner prvku. Pokud to prvek umožňuje, předá i další informace. /// </summary> /// <param name="e"></param> /// <param name="boundsTarget"></param> private void _DragOwnerCall(GDragActionArgs e, Rectangle boundsTarget) { if (!this._DragOwnerBoundsOriginal.HasValue) { return; } Rectangle boundsOriginal = this._DragOwnerBoundsOriginal.Value; // Souřadnice výchozí, před začátkem procesu Resize Rectangle boundsCurrent = this._InteractiveOwner.Bounds; // Souřadnice nynější, před jejich změnou aktuálním krokem Resize DragActionType action = e.DragAction; if (this._IResizeObject != null) { // a) varianta přes interface IResizeObject a jeho metodu SetBoundsResized(): RectangleSide side = RectangleSide.None; // Najdeme reálné strany, kde došlo ke změně souřadnice proti původní souřadnici: // (ono při pohybu myši NAHORU na LEVÉ straně sice máme pohyb, ale nemáme změnu Bounds) // (a dále při povolení UpsideDown můžeme sice pohybovat PRAVÝM resizerem doleva, ale nakonec měníme LEFT i RIGHT souřadnici) side = (boundsOriginal.Left != boundsTarget.Left ? RectangleSide.Left : RectangleSide.None) | (boundsOriginal.Top != boundsTarget.Top ? RectangleSide.Top : RectangleSide.None) | (boundsOriginal.Right != boundsTarget.Right ? RectangleSide.Right : RectangleSide.None) | (boundsOriginal.Bottom != boundsTarget.Bottom ? RectangleSide.Bottom : RectangleSide.None); if (side != RectangleSide.None || action == DragActionType.DragThisCancel) { ResizeObjectArgs args = new ResizeObjectArgs(e, boundsOriginal, boundsCurrent, boundsTarget, side); this._IResizeObject.SetBoundsResized(args); } } else if (boundsTarget != boundsCurrent || action == DragActionType.DragThisCancel) { // b) varianta s prostým setováním Bounds do prvku (tehdy, když prvek nemá interface IResizeObject): this._InteractiveOwner.Bounds = boundsTarget; ((IInteractiveItem)this._InteractiveOwner).Parent.Repaint(); } }
private static Rectangle MergeRectangles(Rectangle first, Rectangle second, RectangleSide side) { Rectangle mergedRectangle; switch (side) { case RectangleSide.Left: mergedRectangle = new Rectangle(first.width + second.width, first.height, second.x, first.y); break; case RectangleSide.Right: mergedRectangle = new Rectangle(first.width + second.width, first.height, first.x, first.y); break; case RectangleSide.Top: mergedRectangle = new Rectangle(first.width, first.height + second.height, first.x, first.y); break; case RectangleSide.Bottom: mergedRectangle = new Rectangle(first.width, first.height + second.height, first.x, second.y); break; default: throw new InternalRuntimeException("A rectangle can only be joined on the sides left, right, top or bottom, not " + side.ToString()); } Rectangle[] oldRectangles = new Rectangle[] { first, second }; Rectangle.ReplaceRectangles(oldRectangles, mergedRectangle); return(mergedRectangle); }
/// <summary> /// Gets the closest projected <see cref="Point"/> perpendicular to the middle of the specified edge of the rectangle /// for a given target <see cref="Point"/>. /// </summary> /// <param name="targetPoint">The target <see cref="Point"/>.</param> /// <param name="rectangleEdge"> /// A <see cref="RectangleSide"/> value describing the edge of the rectangle to project perpendicularly. /// </param> /// <returns> /// The closest projected <see cref="Point"/> perpendicular to the middle of the <paramref name="rectangleEdge"/> for the <paramref name="targetPoint"/>. /// </returns> public Point ClosestPerpendicularPointToEdgeMidPoint(Point targetPoint, RectangleSide rectangleEdge) { Line edge = GetEdge(rectangleEdge); Ray ray = new Ray(Center, edge.PerpendicularDirection); return(ray.Project(targetPoint)); }
/// <summary> /// Konstruktor /// </summary> /// <param name="resizeControl">Kontroler Resize</param> /// <param name="side">Strana</param> public ResizeItem(ResizeControl resizeControl, RectangleSide side) : base() { this._ResizeControl = resizeControl; this._Side = side; this._Orientation = (((side & RectangleSide.Horizontal) != 0) ? System.Windows.Forms.Orientation.Horizontal : System.Windows.Forms.Orientation.Vertical); this.Parent = this.InteractiveOwner; }
/// <summary> /// Metoda vrací okraje pro <see cref="InteractiveObject.InteractivePadding"/> pro dané aktivní strany /// </summary> /// <param name="sides"></param> /// <returns></returns> private Padding _GetOwnerPadding(RectangleSide sides) { Padding padding = new Padding( (sides.HasFlag(RectangleSide.Left) ? 3 : 0), (sides.HasFlag(RectangleSide.Top) ? 3 : 0), (sides.HasFlag(RectangleSide.Right) ? 3 : 0), (sides.HasFlag(RectangleSide.Bottom) ? 3 : 0) ); return(padding); }
/// <summary> /// Metoda vrací počet pixelů distance mezi danou hranou Rectangle a daným bodem /// </summary> /// <param name="bounds"></param> /// <param name="side"></param> /// <param name="point"></param> /// <returns></returns> private int?_DragItemGetDistance(Rectangle bounds, RectangleSide side, Point point) { switch (side) { case RectangleSide.Left: return(point.X - bounds.X); case RectangleSide.Top: return(point.Y - bounds.Y); case RectangleSide.Right: return(point.X - bounds.Right); case RectangleSide.Bottom: return(point.Y - bounds.Bottom); } return(null); }
/// <summary> /// Konstruktor /// </summary> /// <param name="interactiveOwner"></param> /// <param name="resizeSides"></param> public ResizeControl(InteractiveObject interactiveOwner, RectangleSide resizeSides) { this._InteractiveOwner = interactiveOwner; this._IResizeObject = interactiveOwner as IResizeObject; this._ShowResizeAllways = false; this._CanUpsideDown = false; this._ChildList = new List <ResizeItem>(); this._InactiveColor = Skin.Splitter.InactiveColor; this._MouseOnParentColor = Skin.Splitter.MouseOnParentColor; this._MouseOverColor = Skin.Splitter.MouseOverColor; this._MouseDownColor = Skin.Splitter.MouseDownColor; this.ResizeSides = resizeSides; }
/// <summary> /// Metoda vrací okraje pro <see cref="InteractiveObject.InteractivePadding"/> pro danou stranu <see cref="ResizeItem.Side"/> /// </summary> /// <param name="sides"></param> /// <returns></returns> private Padding?_GetResizeItemPadding(RectangleSide sides) { switch (sides) { case RectangleSide.Left: return(new Padding(3, 0, 2, 0)); case RectangleSide.Top: return(new Padding(0, 3, 0, 2)); case RectangleSide.Right: return(new Padding(2, 0, 3, 0)); case RectangleSide.Bottom: return(new Padding(0, 2, 0, 3)); } return(null); }
public override void LoadFromXML(XElement xml) { base.LoadFromXML(xml); String portDefString = XmlUtilits.GetFieldValue(xml, "PortDefenitionGuid", Guid.Empty.ToString()); if (!Guid.TryParse(portDefString, out PortDefenitionGuid)) { PortDefenitionGuid = Guid.Empty; } rectanglePainter.LoadFromXML(xml); String side = XmlUtilits.GetFieldValue(xml, "ConnectionPortLocation", RectangleSide.Left.ToString()); ConnectionPortLocation = (RectangleSide)Enum.Parse(typeof(RectangleSide), side, true); }
public void SetSize(Vector3 bottom, float height, RectangleSide direction, float floorThickness, float ceilingThickness, Vector3 tileScale) { var smallerScale = tileScale.x < tileScale.z ? tileScale.x : tileScale.z; topPart.localScale = new Vector3(smallerScale / 4, topPart.localScale.y * (tileScale.y / 2), smallerScale / 4); bottomPart.localScale = new Vector3(smallerScale / 4, bottomPart.localScale.y * (tileScale.y / 2), smallerScale / 4); pillar.localScale = new Vector3(smallerScale / 8, height - ceilingThickness, smallerScale / 8); pillar.localPosition = new Vector3(0, height / 2, 0); topPart.localPosition = new Vector3(0, height - (ceilingThickness * 0.75f), 0); bottomPart.localPosition = new Vector3(0, floorThickness * 0.75f, 0); switch (direction) { case RectangleSide.TopLeft: transform.localPosition = new Vector3( bottom.x - (bottomPart.localScale.x / 2), bottom.y, bottom.z - (topPart.localScale.z / 2)); break; case RectangleSide.TopRight: transform.localPosition = new Vector3( bottom.x - (bottomPart.localScale.x / 2), bottom.y, bottom.z + (topPart.localScale.z / 2)); break; case RectangleSide.BottomLeft: transform.localPosition = new Vector3( bottom.x + (bottomPart.localScale.x / 2), bottom.y, bottom.z - (topPart.localScale.z / 2)); break; case RectangleSide.BottomRight: transform.localPosition = new Vector3( bottom.x + (bottomPart.localScale.x / 2), bottom.y, bottom.z + (topPart.localScale.z / 2)); break; } }
private static bool IsLSplitWorthIt(Rectangle first, Rectangle second, RectangleSide side) { int horizontalSegment; int verticalSegment; bool isAlreadyOptimallySplit; //Check if splitting even improves the rectangles if (side.IsVertical()) { if (first.width < second.width) { horizontalSegment = first.width; verticalSegment = second.height; } else { horizontalSegment = second.width; verticalSegment = first.height; } isAlreadyOptimallySplit = Rectangle.ShouldSplitAtHorizontalLineSegment(verticalSegment, horizontalSegment); } else if (side.IsHorizontal()) { if (first.height < second.height) { horizontalSegment = second.width; verticalSegment = first.height; } else { horizontalSegment = first.width; verticalSegment = second.height; } isAlreadyOptimallySplit = !Rectangle.ShouldSplitAtHorizontalLineSegment(verticalSegment, horizontalSegment); } else { throw new InternalRuntimeException("Logic error."); } bool doesSplitMatter = verticalSegment != horizontalSegment; return(doesSplitMatter && !isAlreadyOptimallySplit); }
public static Rectangle TryMergeOptimization(Board board, Rectangle rectangle) { Rectangle bestMerge = null; int bestScore = 0; RectangleSide bestMergeSide = RectangleSide.None; //First find the best pair of rectangles to merge if there is any foreach (Rectangle candidate in rectangle.AdjacentRectangles) { //Can only merge two empty rectangles if (!board.EmptyRectangles.ContainsKey(candidate)) { continue; } RectangleSide mergeSide = GetMergeSideIfAny(rectangle, candidate); if (mergeSide != RectangleSide.None) { int score = rectangle.GetArea() + candidate.GetArea(); if (score > bestScore) { bestMerge = candidate; bestScore = score; bestMergeSide = mergeSide; } } } //If a pair was found then merge them if (bestMerge != null) { Rectangle mergedRectangle = MergeRectangles(rectangle, bestMerge, bestMergeSide); //Remove old rectangles and add the new rectangle to the board board.EmptyRectangles.Remove(rectangle); board.EmptyRectangles.Remove(bestMerge); board.EmptyRectangles.Add(mergedRectangle, mergedRectangle); return(mergedRectangle); } return(null); }
/// <summary> /// Nastaví viditelné strany, aktualizuje soupis Child prvků /// </summary> /// <param name="resizeSides"></param> private void _SetResizeSides(RectangleSide resizeSides) { RectangleSide sides = RectangleSide.None; this._ChildList.Clear(); // Pořadí: v pořadí tchto řádků budou prvky vykreslovány (odspodu nahoru) a interaktivní (odshora dolů): this._SetResizeSide(resizeSides, RectangleSide.Top, ref sides, ref this._ItemTop); this._SetResizeSide(resizeSides, RectangleSide.Bottom, ref sides, ref this._ItemBottom); this._SetResizeSide(resizeSides, RectangleSide.Left, ref sides, ref this._ItemLeft); this._SetResizeSide(resizeSides, RectangleSide.Right, ref sides, ref this._ItemRight); bool isChange = (this._ResizeSides != sides); this._ResizeSides = sides; this._InteractiveOwner.InteractivePadding = _GetOwnerPadding(sides); // Owner objekt musí mít o něco větší interaktivní prostor, aby bylo možno aktivovat patřičné ResizeItem // Po změně překreslit: if (isChange) { this.Repaint(); } }
public int RenderBound(ScreenInfo.DisplayInfoCollection DI, RectangleSide Side, int Offset, int Dimension) { var display = DI[Value]; switch (Side) { case RectangleSide.Left: return(display.WorkArea.Left); case RectangleSide.Top: return(display.WorkArea.Top); case RectangleSide.Right: return(display.WorkArea.Right); case RectangleSide.Bottom: return(display.WorkArea.Bottom); } return(0); }
public static RectangleSide OppositeDirection(this RectangleSide side) { switch (side) { case RectangleSide.Left: return(RectangleSide.Right); case RectangleSide.Right: return(RectangleSide.Left); case RectangleSide.Top: return(RectangleSide.Bottom); case RectangleSide.Bottom: return(RectangleSide.Top); default: throw new InternalRuntimeException($"Can't take the opposite direction of the direction: {side.ToString()}"); } }
/// <summary> /// Vrátí požadovaný bod, nacházející se na daném místě absolutní souřadnice daného prvku. /// Pokud je prvek neviditelný (on, nebo kterýkoli z jeho Parentů), může vrátit null pokud je požadavek "onlyVisible" = true. /// </summary> /// <param name="item"></param> /// <param name="side"></param> /// <param name="onlyVisible">true = vracet bod pouze pro objekt, který může být viditelný (z hlediska Is.Visible jeho a všech jeho Parentů)</param> /// <param name="shiftInner">Posunout výsledný bod mírně směrem doprostřed objektu</param> /// <returns></returns> protected static Point?GetPoint(InteractiveObject item, RectangleSide side, bool onlyVisible, bool shiftInner) { if (item == null) { return(null); } BoundsInfo boundsInfo = item.BoundsInfo; if (onlyVisible && !boundsInfo.CurrentItemIsVisible) { return(null); } Rectangle absBounds = boundsInfo.CurrentItemAbsoluteBounds; if (shiftInner) { absBounds = GetInnerBounds(absBounds); } return(absBounds.GetPoint(side)); }
/// <summary> /// Připraví jeden prvek <see cref="ResizeItem"/> pro jednu stranu "currentSide" /// </summary> /// <param name="requestSides">Požadované strany</param> /// <param name="currentSide">Strana tohoto konkrétního prvku</param> /// <param name="realSides">Souhrn viditelných stran</param> /// <param name="item">Vizuální prvek</param> private void _SetResizeSide(RectangleSide requestSides, RectangleSide currentSide, ref RectangleSide realSides, ref ResizeItem item) { bool isVisible = ((requestSides & currentSide) != 0); if (!isVisible) { // Nemá být vidět: if (item != null) { item.Is.Visible = false; } } else { // Má být vidět: if (item == null) { item = new ResizeItem(this, currentSide); } item.Is.Visible = true; realSides |= currentSide; this._ChildList.Add(item); } }
/// <summary> /// Konstruktor /// </summary> /// <param name="e"></param> /// <param name="boundsSource"></param> /// <param name="boundsCurrent"></param> /// <param name="boundsTarget"></param> /// <param name="side"></param> public ResizeObjectArgs(GDragActionArgs e, Rectangle boundsSource, Rectangle boundsCurrent, Rectangle boundsTarget, RectangleSide side) { this.DragArgs = e; this.BoundsOriginal = boundsSource; this.BoundsCurrent = boundsCurrent; this.BoundsTarget = boundsTarget; this.ChangedSide = side; }
/// <summary> /// Gets the distance to the specified rectangle edge from a <see cref="Point"/> perpendicular to the middle of the specified rectangle edge. /// </summary> /// <param name="perpendicularPoint">A <see cref="Point"/> perpendicular to the <paramref name="rectangleEdge"/>.</param> /// <param name="rectangleEdge"> /// A <see cref="RectangleSide"/> value describing the edge of the rectangle perpendicular to the <paramref name="perpendicularPoint"/>. /// </param> /// <returns>The distance from the <paramref name="perpendicularPoint"/> to the <paramref name="rectangleEdge"/>.</returns> public double DistanceFromPerpendicularPointToEdgeMidPoint(Point perpendicularPoint, RectangleSide rectangleEdge) { Line edge = GetEdge(rectangleEdge); double distance = edge.MidPoint.DistanceTo(perpendicularPoint); Point center = Center; return((center.DistanceTo(edge.MidPoint) > center.DistanceTo(perpendicularPoint)) ? -distance : distance); }
/// <summary> /// Gets a <see cref="Line"/> representing the edge of the rectangle /// corresponding to the specified <see cref="RectangleSide"/> value. /// </summary> /// <param name="rectangleEdge"> /// A <see cref="RectangleSide"/> value describing the edge of the rectangle. /// </param> /// <returns>A <see cref="Line"/> representing an edge of the rectangle.</returns> private Line GetEdge(RectangleSide rectangleEdge) => rectangleEdge switch {
public static bool IsHorizontal(this RectangleSide side) { return(side == RectangleSide.Left || side == RectangleSide.Right); }
public static void RenderEntrails(RenderContext context, RectanglePainter rectangle, RectangleSide side) { if (side == RectangleSide.Right) { context.DrawEllipseCentered(rectangle.Left + 4, rectangle.Top + 4, rectangle.Right - 4, rectangle.Bottom - 4, Colors.Blue, 2); context.DrawFillRectangle((rectangle.Left + rectangle.Right) / 2, rectangle.Top + 1, rectangle.Right - 1, rectangle.Bottom - 1, Colors.White); } else if (side == RectangleSide.Left) { context.DrawEllipseCentered(rectangle.Left + 4, rectangle.Top + 4, rectangle.Right - 4, rectangle.Bottom - 4, Colors.Blue, 2); context.DrawFillRectangle(rectangle.Left + 1, rectangle.Bottom - 1, (rectangle.Left + rectangle.Right) / 2, rectangle.Top + 1, Colors.White); } else if (side == RectangleSide.Bottom) { context.DrawEllipseCentered(rectangle.Left + 4, rectangle.Top + 4, rectangle.Right - 4, rectangle.Bottom - 4, Colors.Blue, 2); context.DrawFillRectangle(rectangle.Left + 1, rectangle.Bottom - 1, rectangle.Right - 1, (rectangle.Top + rectangle.Bottom) / 2, Colors.White); } else if (side == RectangleSide.Top) { context.DrawEllipseCentered(rectangle.Left + 4, rectangle.Top + 4, rectangle.Right - 4, rectangle.Bottom - 4, Colors.Blue, 2); context.DrawFillRectangle(rectangle.Left + 1, rectangle.Top + 1, rectangle.Right - 1, (rectangle.Top + rectangle.Bottom) / 2, Colors.White); } }
private static Rectangle[] GetLShapeInformation(Rectangle first, Rectangle second, RectangleSide side, RectangleSide extendDirection) { Rectangle smaller; Rectangle bigger; if (side.IsVertical() && first.width < second.width || side.IsHorizontal() && first.height < second.height) { smaller = first; bigger = second; } else { smaller = second; bigger = first; side = side.OppositeDirection(); } if (side.IsVertical()) { int movedXPos = extendDirection == RectangleSide.Right ? smaller.width : 0; int movedYPos = side == RectangleSide.Bottom ? bigger.height : 0; Rectangle newSmaller = new Rectangle(smaller.width, smaller.height + bigger.height, smaller.x, smaller.y - movedYPos); Rectangle newBigger = new Rectangle(bigger.width - smaller.width, bigger.height, bigger.x + movedXPos, bigger.y); return(new Rectangle[] { newSmaller, newBigger }); } else { int movedXPos = side == RectangleSide.Left ? bigger.width : 0; int movedYPos = extendDirection == RectangleSide.Top ? smaller.height : 0; Rectangle newSmaller = new Rectangle(smaller.width + bigger.width, smaller.height, smaller.x - movedXPos, smaller.y); Rectangle newBigger = new Rectangle(bigger.width, bigger.height - smaller.height, bigger.x, bigger.y + movedYPos); return(new Rectangle[] { newSmaller, newBigger }); } }
public int RenderBound(ScreenInfo.DisplayInfoCollection DI, RectangleSide Side, int Offset, int Dimension) { return((int)(Dimension * Decimal) + Offset); }
public static Point getNearestPointInPerimeter(double left, double top, double width, double height, double x, double y, out RectangleSide side) { double right = left + width; double bottom = top + height; double X = clamp(x, left, right); double Y = clamp(y, top, bottom); double dl = Math.Abs(X - left); double dr = Math.Abs(X - right); double dt = Math.Abs(Y - top); double db = Math.Abs(Y - bottom); double m = Math.Min(dl, dr); m = Math.Min(m, dt); m = Math.Min(m, db); if (m == dt) { side = RectangleSide.Top; return(new Point(X, top)); } else if (m == db) { side = RectangleSide.Bottom; return(new Point(X, bottom)); } else if (m == dl) { side = RectangleSide.Left; return(new Point(left, Y)); } else { side = RectangleSide.Right; return(new Point(right, Y)); } }
public static void RenderEntrails(RenderContext context, RectanglePainter rectangle, RectangleSide side) { if (side == RectangleSide.Left) { double x1 = rectangle.Right - 4; double y1 = rectangle.Top + 4; double x2 = rectangle.Left + 4; double y2 = rectangle.Top + rectangle.Height / 2; double x3 = x1; double y3 = rectangle.BottomRight.Y - 4; context.DrawFillTriangle(x2, y2, x1, y1, x3, y3, Colors.Black); context.DrawLine(x1, y1, x2, y2, Colors.Black); context.DrawLine(x3, y3, x2, y2, Colors.Black); context.DrawLine(x3, y3, x1, y1, Colors.Black); } else if (side == RectangleSide.Right) { double x1 = rectangle.Left + 4; double y1 = rectangle.Top + 4; double x2 = rectangle.Right - 4; double y2 = rectangle.Top + rectangle.Height / 2; double x3 = x1; double y3 = rectangle.BottomRight.Y - 4; context.DrawFillTriangle(x2, y2, x1, y1, x3, y3, Colors.Black); context.DrawLine(x1, y1, x2, y2, Colors.Black); context.DrawLine(x3, y3, x2, y2, Colors.Black); context.DrawLine(x3, y3, x1, y1, Colors.Black); } else if (side == RectangleSide.Top) { double x1 = rectangle.Left + 4; double y1 = rectangle.Bottom - 4; double x2 = rectangle.Right - 4; double y2 = y1; double x3 = (x1 + x2) / 2.0; double y3 = rectangle.Top + 4; context.DrawFillTriangle(x2, y2, x1, y1, x3, y3, Colors.Black); context.DrawLine(x1, y1, x2, y2, Colors.Black); context.DrawLine(x3, y3, x2, y2, Colors.Black); context.DrawLine(x3, y3, x1, y1, Colors.Black); } else if (side == RectangleSide.Bottom) { double x1 = rectangle.Left + 4; double y1 = rectangle.Top + 4; double x2 = rectangle.Right - 4; double y2 = y1; double x3 = (x1 + x2) / 2.0; double y3 = rectangle.BottomRight.Y - 4; context.DrawFillTriangle(x2, y2, x1, y1, x3, y3, Colors.Black); context.DrawLine(x1, y1, x2, y2, Colors.Black); context.DrawLine(x3, y3, x2, y2, Colors.Black); context.DrawLine(x3, y3, x1, y1, Colors.Black); } }
public static bool IsVertical(this RectangleSide side) { return(side == RectangleSide.Top || side == RectangleSide.Bottom); }