public static void RoundedRectangle(Cairo.Context c, RectangleD rect, double radius) { if (radius > (rect.Width /2) || radius > (rect.Height / 2)) { radius = Math.Min ((rect.Width /2), (rect.Height / 2)); } c.Save (); /* Bottom Left */ c.MoveTo(rect.X, rect.Y + radius); c.Arc (rect.X + radius, rect.Y + radius, radius, Math.PI, -Math.PI/2); c.LineTo (rect.X2 - radius, rect.Y); /* Bottom Right */ c.Arc (rect.X2 - radius, rect.Y + radius, radius, -Math.PI/2, 0); c.LineTo (rect.X2, rect.Y2 - radius); /* Top Right */ c.Arc (rect.X2 - radius, rect.Y2 - radius, radius, 0, Math.PI/2); c.LineTo (rect.X + radius, rect.Y2); /* Top Left */ c.Arc(rect.X + radius, rect.Y2 - radius, radius, Math.PI/2, Math.PI); c.ClosePath (); c.Restore (); }
// TODO: Move this to FigureCollection private RectangleD GetBounds (FigureCollection figures) { RectangleD rectangle = new RectangleD (0, 0, 0, 0); foreach (IFigure figure in figures) { rectangle.Add (figure.DisplayBox); } return rectangle; }
/// <summary> /// Gets a value indicating whether the specified point is potentially a hit for the specified element. /// </summary> /// <param name="element">The element to evaluate.</param> /// <param name="point">The point to evaluate.</param> /// <returns><see langword="true"/> if the specified point is a potential hit; otherwise, <see langword="false"/>.</returns> public static Boolean IsPotentialHit(UIElement element, Point2D point) { if (element.Visibility != Visibility.Visible) return false; if (!element.IsHitTestVisible) return false; if (!element.VisualBounds.Contains(point)) return false; var clip = element.ClipRectangle; if (clip.HasValue) { var absoluteClip = clip.Value; var relativeClip = new RectangleD( absoluteClip.X - element.UntransformedAbsolutePosition.X, absoluteClip.Y - element.UntransformedAbsolutePosition.Y, absoluteClip.Width, absoluteClip.Height); if (!relativeClip.Contains(point)) return false; } return true; }
public static bool RectangleInsideGdkRegion (RectangleD r, Gdk.Region region) { r.Inflate (1.0, 1.0); Gdk.Rectangle gdkRect = GdkRectangle (r); Gdk.OverlapType type = region.RectIn (gdkRect); return (type == Gdk.OverlapType.In || type == Gdk.OverlapType.Part); }
internal Present Render(MapRectangle mapRect, Size size, bool useDocumentTransparency, bool exactColors) { Monitor.Enter(this); Present result; try { RectangleD rectangleD = new RectangleD(mapRect.lon0 * (double)this.boundingBox.Width - 0.5, -mapRect.lat1 * (double)this.boundingBox.Height + (double)this.actualBoundingBox.Height - 0.5, (mapRect.lon1 - mapRect.lon0) * (double)this.boundingBox.Width + (double)this.hackRectangleAdjust, (mapRect.lat1 - mapRect.lat0) * (double)this.boundingBox.Height + (double)this.hackRectangleAdjust); RectangleD rectangleD2 = new RectangleD(0.0, 0.0, (double)size.Width, (double)size.Height); this.Reclip(this.actualBoundingBox, ref rectangleD, ref rectangleD2); D.Say(10, string.Format("Rendering {0} from {1}", mapRect, rectangleD)); GDIBigLockedImage gDIBigLockedImage = new GDIBigLockedImage(size, "GDIVerb"); if (exactColors) { gDIBigLockedImage.SetInterpolationMode(InterpolationMode.NearestNeighbor); } else { gDIBigLockedImage.SetInterpolationMode(InterpolationMode.HighQualityBicubic); } gDIBigLockedImage.DrawImageOntoThis(this.loadedImage, rectangleD2.ToRectangleF(), rectangleD.ToRectangleF()); result = new ImageRef(new ImageRefCounted(gDIBigLockedImage)); } finally { Monitor.Exit(this); } return result; }
public override void MouseDrag (MouseEvent ev) { DrawSelectionRect ((Gtk.Widget) ev.View, ev.GdkEvent.Window); PointD anchor = new PointD (AnchorX, AnchorY); PointD corner = new PointD (ev.X, ev.Y); _selectionRect = new RectangleD (anchor, corner); DrawSelectionRect ((Gtk.Widget) ev.View, ev.GdkEvent.Window); }
protected override void SetAbsoluteBoundsValue(RectangleD newValue) { base.SetAbsoluteBoundsValue(newValue); // trigger bounds rules of children this.relayoutChildren = true; }
public static PointD EdgePointFromAngle (RectangleD r, double angle) { double sin = Math.Sin (angle); double cos = Math.Cos (angle); double e = 0.0001; double x = 0; double y = 0; if (Math.Abs (sin) > e) { x = (1.0 + cos / Math.Abs (sin)) / 2.0 * r.Width; x = Range (0.0, r.Width, x); } else if (cos >= 0.0) { x = r.Width; } if (Math.Abs (cos) > e) { y = (1.0 + sin / Math.Abs (cos)) / 2.0 * r.Height; y = Range (0.0, r.Height, y); } else if (sin >= 0.0) { y = r.Height; } return new PointD (r.X + x, r.Y + y); }
public virtual RectangleD InvalidateRect(PointD b) { var r = new RectangleD (b.X, b.Y, 0.0, 0.0); r.Inflate (15.0, 15.0); return r; }
public ScaleAndTranslate(RectangleD source, RectangleD dest) { this.scx = (dest.Right - dest.Left) / (source.Right - source.Left); this.tx = dest.Left - this.scx * source.Left; this.scy = (dest.Bottom - dest.Top) / (source.Bottom - source.Top); this.ty = dest.Top - this.scy * source.Top; }
public AnalogClockFigure() : base() { DisplayBox = new RectangleD (0.0, 0.0, 100.0, 100.0); LineWidth = 3.0; FillColor = new Color (0.7, 0.7, 0.7, 0.8); _now = DateTime.Now; _handles = new List <IHandle> (); //Handle used to keep height and width synchronized when resizing _handles.Add (new AnalogClockNorthWestHandle (this)); _handlesHand = new List <IHandle> (); //Handles to move hands _handlesHand.Add (new AnalogClockHandHandle (this, new AnalogClockHandLocatorHour ())); _handlesHand.Add (new AnalogClockHandHandle (this, new AnalogClockHandLocatorMinute ())); _handlesHand.Add (new AnalogClockHandHandle (this, new AnalogClockHandLocatorSecond ())); _hourColor = new Color (0.337, 0.612, 0.117, 0.8); _minuteColor = new Color (0.117, 0.337, 0.619, 0.8); _secondColor = new Color (1, 1, 1, 0.8); _hourHandLength = 0.0; //Timer to update time GLib.Timeout.Add (500, new GLib.TimeoutHandler (UpdateClock)); }
public override RectangleD GetCompliantBounds(ShapeElement shape, RectangleD proposedBounds) { if (shape.Store.InSerializationTransaction) return proposedBounds; double width = 0.83675; double height = 0.83675; if (shape is StartableShape || shape is BatchWaitShape || shape is DatabaseBatchWaitShape) { width = 1.243; height = 0.84025; } else if (shape is WorkflowRuleShape) { width = 1.2395; height = 0.84025; } var activityShape = shape as BaseActivityShape; if (activityShape == null) return proposedBounds; var approvedBounds = new RectangleD(); approvedBounds.Location = proposedBounds.Location; // But the height and width are constrained: approvedBounds.Height = height; approvedBounds.Width = width; return approvedBounds; }
public RectangleD Apply(RectangleD a) { double num = this.scx * a.Left + this.tx; double num2 = this.scy * a.Top + this.ty; double num3 = this.scx * a.Right + this.tx; double num4 = this.scy * a.Bottom + this.ty; return new RectangleD(num, num2, num3 - num, num4 - num2); }
public void RectangleD_IsConstructedProperly() { var result = new RectangleD(123.45, 456.78, 789.99, 999.99); TheResultingValue(result) .ShouldHavePosition(123.45, 456.78) .ShouldHaveDimensions(789.99, 999.99); }
public void RectangleD_EqualsObject() { var rectangle1 = new RectangleD(123.45, 456.78, 789.99, 999.99); var rectangle2 = new RectangleD(123.45, 456.78, 789.99, 999.99); TheResultingValue(rectangle1.Equals((Object)rectangle2)).ShouldBe(true); TheResultingValue(rectangle1.Equals("This is a test")).ShouldBe(false); }
/// <summary> /// Draws a radiused arc on the given path, at given location. /// </summary> protected void DrawRadiusedArc(GraphicsPath path, double left, double top, float startAngle, float sweepAngle) { RectangleD arcRectangle = new RectangleD(); arcRectangle.Width = (2 * this.Radius); arcRectangle.Height = (2 * this.Radius); path.AddArc((float)left, (float)top, (float)arcRectangle.Width, (float)arcRectangle.Height, startAngle, sweepAngle); }
/// <summary> /// Moves shape to specified position (in world units) relative to the diagram. /// </summary> public static void MoveTo(this NodeShape shape, PointD position) { var newBounds = new RectangleD(PointD.Empty, shape.AbsoluteBounds.Size); newBounds.X = position.X; newBounds.Y = position.Y; shape.AbsoluteBounds = newBounds; }
protected override void SetAbsoluteBoundsValue(RectangleD newValue) { base.SetAbsoluteBoundsValue(newValue); if (!this.Store.InUndoRedoOrRollback) { this.PerformShapeAnchoringRule(); } }
/// <summary> /// Returns the path of the shape. /// </summary> protected override GraphicsPath GetPath(RectangleD boundingBox) { GraphicsPath basePath = base.GetPath(boundingBox); double radius = this.Radius; // Ensure work to do. if (radius <= (double)0) { return basePath; } // Starting at top left and going clockwise. basePath.Reset(); basePath.StartFigure(); // Top Left corner arc this.DrawRadiusedArc(basePath, boundingBox.Left, boundingBox.Top, 180f, 90f); // Top of tab side line this.DrawLine(basePath, (boundingBox.Left + radius), boundingBox.Top, (boundingBox.Left + TabWidth), boundingBox.Top); // Tab top arc this.DrawRadiusedArc(basePath, (boundingBox.Left + TabWidth), boundingBox.Top, 270f, 45f); // Tab slope line // This line will be joined in automatically // Tab bottom arc this.DrawRadiusedArc(basePath, (boundingBox.Left + TabWidth + TabHeight + radius), (boundingBox.Top + TabHeight - (2 * radius)), 135f, -45f); // Top side line this.DrawLine(basePath, (boundingBox.Left + TabWidth + TabHeight + (2 * radius)), (boundingBox.Top + TabHeight), (boundingBox.Right - radius), (boundingBox.Top + TabHeight)); // Top Right corner arc this.DrawRadiusedArc(basePath, (boundingBox.Right - (2 * radius)), (boundingBox.Top + TabHeight), 270f, 90f); // Right side line this.DrawLine(basePath, boundingBox.Right, (boundingBox.Top + radius + TabHeight), boundingBox.Right, boundingBox.Bottom); // Bottom side line this.DrawLine(basePath, boundingBox.Right, boundingBox.Bottom, (boundingBox.Left + radius), boundingBox.Bottom); // bottom left corner arc this.DrawRadiusedArc(basePath, (boundingBox.Left), (boundingBox.Bottom - (2 * radius)), 90f, 90f); // Left side line this.DrawLine(basePath, boundingBox.Left, (boundingBox.Bottom - radius), boundingBox.Left, (boundingBox.Top + radius)); basePath.CloseFigure(); return basePath; }
public static RectangleD GetBoundingBox( RectangleD r1, RectangleD r2 ) { double new_x0 = System.Math.Min( r1.X0 , r2.X0 ); double new_y0 = System.Math.Min( r1.Y0 , r2.Y0 ); double new_x1 = System.Math.Max( r1.X1 , r2.X1 ); double new_y1 = System.Math.Max( r1.Y1 , r2.Y1 ); RectangleD bb = new RectangleD( new_x0, new_y0, new_x1-new_x0, new_y1-new_y0); return bb; }
/// <summary> /// Return a null path. Not used. /// </summary> protected override GraphicsPath GetPath(RectangleD bounds) { Debug.Fail("Not used. If we see this is firing, then we need to extend " + "this class to specify one of the composite paths (or a custom path) " + "as the path to represent the whole item. Default to the last of the " + "composite paths (the first one drawn).\r\n" + "I have a feeling this may be used in the future if selection drawing " + "around link lines is improved."); return null; }
/// <inheritdoc/> protected override Size2D ArrangeCore(RectangleD finalRect, ArrangeOptions options) { if (clonedElement != null) { if (!clonedElement.IsVisuallyConnectedToViewRoot) { clonedElement.Arrange(new RectangleD(0, 0, clonedElement.DesiredSize.Width, clonedElement.DesiredSize.Height)); } clonedBounds = clonedElement.TransformedVisualBounds; return finalRect.Size; } return base.ArrangeCore(finalRect, options); }
protected TextFigure(SerializationInfo info, StreamingContext context) : base(info, context) { FontColor = (Cairo.Color) info.GetValue ("FontColor", typeof (Cairo.Color)); FontAlignment = (Pango.Alignment) info.GetValue ("FontAlignment", typeof (Pango.Alignment)); FontFamily = (string) info.GetValue ("FontFamily", typeof (string)); FontSize = (double) info.GetDouble ("FontSize"); FontStyle = (Pango.Style) info.GetValue ("FontStyle", typeof (Pango.Style)); displaybox = (RectangleD) info.GetValue ("DisplayBox", typeof (RectangleD)); text = (string) info.GetValue ("Text", typeof (string)); textEditable = info.GetBoolean ("TextEditable"); padding = info.GetDouble ("Padding"); }
public override void MouseDown(MouseEvent ev) { base.MouseDown (ev); var view = ev.View; var gdk_event = (EventButton) ev.GdkEvent; bool shift_pressed = (gdk_event.State & ModifierType.ShiftMask) != 0; if (!shift_pressed) view.ClearSelection (); selectionRectangle = new RectangleD (ev.X, ev.Y, 0, 0); DrawSelectionRect ((Gtk.Widget) view, gdk_event.Window); }
public void RectangleD_OpInequality() { var rectangle1 = new RectangleD(123.45, 456.78, 789.99, 999.99); var rectangle2 = new RectangleD(123.45, 456.78, 789.99, 999.99); var rectangle3 = new RectangleD(222, 456.78, 789.99, 999.99); var rectangle4 = new RectangleD(123.45, 333, 789.99, 999.99); var rectangle5 = new RectangleD(123.45, 456.78, 444, 999.99); var rectangle6 = new RectangleD(123.45, 456.78, 789.99, 555); Assert.AreEqual(false, rectangle1 != rectangle2); Assert.AreEqual(true, rectangle1 != rectangle3); Assert.AreEqual(true, rectangle1 != rectangle4); Assert.AreEqual(true, rectangle1 != rectangle5); Assert.AreEqual(true, rectangle1 != rectangle6); }
public void RectangleD_EqualsRectangleD() { var rectangle1 = new RectangleD(123.45, 456.78, 789.99, 999.99); var rectangle2 = new RectangleD(123.45, 456.78, 789.99, 999.99); var rectangle3 = new RectangleD(222, 456.78, 789.99, 999.99); var rectangle4 = new RectangleD(123.45, 333, 789.99, 999.99); var rectangle5 = new RectangleD(123.45, 456.78, 444, 999.99); var rectangle6 = new RectangleD(123.45, 456.78, 789.99, 555); TheResultingValue(rectangle1.Equals(rectangle2)).ShouldBe(true); TheResultingValue(rectangle1.Equals(rectangle3)).ShouldBe(false); TheResultingValue(rectangle1.Equals(rectangle4)).ShouldBe(false); TheResultingValue(rectangle1.Equals(rectangle5)).ShouldBe(false); TheResultingValue(rectangle1.Equals(rectangle6)).ShouldBe(false); }
/// <summary> /// Paint the composite shape decorators. /// </summary> /// <param name="bounds">Forwarded to composite decorators</param> /// <param name="shape">Forwarded to composite decorators</param> /// <param name="e">Forwarded to composite decorators</param> public override void DoPaintShape(RectangleD bounds, IGeometryHost shape, DiagramPaintEventArgs e) { if (myDecorators == null) { myDecorators = DecoratorCollection; if (myDecorators == null) { myDecorators = new LinkDecorator[]{}; } } for (int i = myDecorators.Count - 1; i >= 0; --i) { myDecorators[i].DoPaintShape(bounds, shape, e); } }
public void VisitFigure(Figure figure) { var point = view.DrawingToView (figure.DisplayBox.X, figure.DisplayBox.Y); var rect = new RectangleD (point.X, point.Y); rect.Width = figure.DisplayBox.Width; rect.Height = figure.DisplayBox.Height; if (!GdkCairoHelper.RectangleInsideGdkRegion (rect, region)) return; if (view.SelectionEnumerator.Contains (figure)) figure.DrawSelected (context); else figure.Draw (context); figures.Add (figure); }
/// <summary> /// Returns the path of the shape. /// </summary> protected override GraphicsPath GetPath(RectangleD boundingBox) { GraphicsPath basePath = base.GetPath(boundingBox); double radius = this.Radius; // Ensure work to do. if (radius <= (double)0) { return basePath; } // Starting at top left and going clockwise. basePath.Reset(); basePath.StartFigure(); // Top Left corner arc this.DrawRadiusedArc(basePath, boundingBox.Left, boundingBox.Top, 180f, 90f); // Top side line this.DrawLine(basePath, (boundingBox.Left + radius), boundingBox.Top, (boundingBox.Right - ArrowWidth), boundingBox.Top); // Arrow top line this.DrawLine(basePath, (boundingBox.Right - ArrowWidth), boundingBox.Top, boundingBox.Right, (boundingBox.Top + (boundingBox.Height / 2))); // Arrow bottom line this.DrawLine(basePath, (boundingBox.Right), (boundingBox.Top + (boundingBox.Height / 2)), (boundingBox.Right - ArrowWidth), boundingBox.Bottom); // Bottom side line this.DrawLine(basePath, (boundingBox.Right - ArrowWidth), boundingBox.Bottom, (boundingBox.Left + radius), boundingBox.Bottom); // Bottom left corner arc this.DrawRadiusedArc(basePath, boundingBox.Left, (boundingBox.Bottom - (2 * radius)), 90f, 90f); // Left side line this.DrawLine(basePath, boundingBox.Left, (boundingBox.Bottom - radius), boundingBox.Left, (boundingBox.Top + radius)); basePath.CloseFigure(); return basePath; }
internal PolygonShape( int recordNumber, RectangleD extent, int[] parts, Vector2D[] positions) : base(recordNumber, ShapeType.Polygon) { _extent = extent; _parts = new ShapePart[parts.Length]; for (int i = 0; i < parts.Length; ++i) { int count = ((i == parts.Length - 1) ? positions.Length : parts[i + 1]) - parts[i]; _parts[i] = new ShapePart(positions, parts[i], count); } }
public override bool ContainsPoint(double x, double y) { RectangleD rect = DisplayBox; rect.Inflate(4.0, 4.0); if (!rect.Contains(x, y)) { return(false); } for (int i = 0; i < _points.Count - 1; i++) { PointD p1 = _points [i]; PointD p2 = _points [i + 1]; if (Geometry.LineContainsPoint(p1.X, p1.Y, p2.X, p2.Y, x, y)) { return(true); } } return(false); }
public RectangleF GetCommentRectangle(Graphics g, RectangleD worldRect, Rectangle canvasRect) { // точка привязки var ptPivot = Conversion.WorldToScreen(new PointD(PivotIndex, PivotPrice), worldRect, canvasRect); // вторая точка стрелки var angle = GetNormalizedArrowAngle(); var ptEnd = new PointD(ptPivot.X + ArrowLength * Math.Cos(angle), ptPivot.Y + ArrowLength * Math.Sin(angle)); var fontSize = Owner == null ? 8 : SeriesComment.FontSize; var fontStyle = SeriesComment.FontBold ? FontStyle.Bold : FontStyle.Regular; using (var fonts = new FontStorage(new Font(FontFamily.GenericSansSerif, fontSize, fontStyle))) { float top, left, width, height; GetTextAreaLeftTop(g, fonts, Text, arrowAngle, ptEnd, out left, out top, out width, out height); return(new RectangleF(left, top, width, height)); } }
public static RectangleD RectangleD(JProperty prop) { if (prop.Value is JValue) { string text = (string)((JValue)prop.Value).Value; var values = text.Split(','); if (values.Length != 4) { throw new Exception("Parsing Error"); } return(new RectangleD(double.Parse(values[0]), double.Parse(values[1]), double.Parse(values[2]), double.Parse(values[3]))); } else { var rect = new RectangleD(); rect.LoadFromJson((JObject)prop.Value); return(rect); } }
/// <summary> /// Перерисовать график /// </summary> private void RePaint() { if (adjusting) { viewport = calcAdjustingViewPort(); } emptyCanvas(); drawAxes(); drawData(data); if (selecting) { drawRect(); } axes.Refresh(); canvas.Refresh(); }
public void RenderGdi(Graphics graphics, RectangleD cameraBounds) { double drawingRotation = _parent.Pitch + Pitch; DVector2 drawingOffset = new DVector2(Math.Cos(drawingRotation), Math.Sin(drawingRotation)) * 0.6; RectangleF screenBounds = RenderUtils.ComputeBoundingBox(Position - drawingOffset, cameraBounds, Width, Height); var offset = new PointF(screenBounds.X + screenBounds.Width * 0.5f, screenBounds.Y + screenBounds.Height * 0.5f); graphics.TranslateTransform(offset.X, offset.Y); graphics.RotateTransform((float)((drawingRotation + Math.PI * 0.5) * 180 / Math.PI)); graphics.TranslateTransform(-offset.X, -offset.Y); graphics.DrawImage(_texture, screenBounds.X, screenBounds.Y, screenBounds.Width, screenBounds.Height); graphics.ResetTransform(); }
public override void Draw(Graphics g, RectangleD worldRect, Rectangle canvasRect) { base.Draw(g, worldRect, canvasRect); var indexMin = Chart.StockPane.WorldRect.Left - 1; var indexMax = Chart.StockPane.WorldRect.Right + 1; using (var font = new Font(Chart.Font.FontFamily, fontSize)) using (var penStorage = new PenStorage()) using (var brushStorage = new BrushesStorage()) { foreach (var tooltip in data) { var index = tooltip.IndexStart; if (index < indexMin || index > indexMax) { continue; } tooltip.Draw(font, g, worldRect, canvasRect, penStorage, brushStorage); } } }
/// <inheritdoc/> protected override Size2D ArrangeOverride(Size2D finalSize, ArrangeOptions options) { var totalPadding = BorderThickness + Padding; var totalPaddingWidth = totalPadding.Left + totalPadding.Right; var totalPaddingHeight = totalPadding.Top + totalPadding.Bottom; var child = Child; if (child != null) { var childArrangeRect = new RectangleD( totalPadding.Left, totalPadding.Right, Math.Max(0, finalSize.Width - totalPaddingWidth), Math.Max(0, finalSize.Height - totalPaddingHeight)); child.Arrange(childArrangeRect, options); } return(finalSize); }
/// <summary> /// Resizes the render target to match the specified element. /// </summary> /// <param name="element">The element for which to resize the render target.</param> /// <param name="bounds">The visual bounds of the element in absolute screen coordinates.</param> /// <returns><see langword="true"/> if the element was resized; otherwise, <see langword="false"/>.</returns> public Boolean ResizeForElement(UIElement element, out RectangleD bounds) { Contract.Require(element, nameof(element)); if (element.View == null) { bounds = RectangleD.Empty; return(false); } bounds = element.TransformedVisualBounds; var effect = element.Effect; if (effect != null) { effect.ModifyVisualBounds(ref bounds); } var display = element.View.Display; var width = Math.Max(1, (Int32)Math.Ceiling(display.DipsToPixels(bounds.Width))); var height = Math.Max(1, (Int32)Math.Ceiling(display.DipsToPixels(bounds.Height))); if (width == renderTarget.Width && height == renderTarget.Height) { return(false); } if (width < 1 || height < 1) { Resize(1, 1); bounds = RectangleD.Empty; } else { Resize(width, height); } return(true); }
public override void ElementAttributeChanged(ElementAttributeChangedEventArgs e) { // only respond to bounds changes if (e.MetaAttribute.Id == NodeShape.AbsoluteBoundsMetaAttributeGuid) { // get the NodeShape reference to work with. NodeShape thisShape = e.ModelElement as NodeShape; if (thisShape != null && thisShape.Diagram != null && thisShape != thisShape.Diagram) { SelectedShapesCollection selection = thisShape.Diagram.ActiveDiagramView.Selection; // make sure the specified shape is in the selection because we only want // the selected shapes to move their connected shapes (not continously // ripple this effect). if (selection != null && selection.Contains(new DiagramItem(thisShape)) == true) { // calculate the change in bounds position. RectangleD oldBounds = (RectangleD)e.OldValue; RectangleD newBounds = (RectangleD)e.NewValue; double deltaX = newBounds.X - oldBounds.X; double deltaY = newBounds.Y - oldBounds.Y; // find all of the connected shapes. List <Shape> connectedShapes = GetConnectedShapes(thisShape); foreach (Shape shape in connectedShapes) { // make sure the shape isn't in the selection, // because those will be on their own as part of drag-drop. if (selection.Contains(new DiagramItem(shape)) == false) { PointD currentLocation = shape.Location; shape.Location = new PointD(currentLocation.X + deltaX, currentLocation.Y + deltaY); } } } } } }
/// <summary> /// 判断线段与矩形的交点个数 /// </summary> /// <param name="L">线段L</param> /// <param name="R">线段R</param> /// <returns>相交返回交点数目,否则返回0,如果有无数个交点则返回null</returns> public static Int32?HasIntersection(LineD L, RectangleD R) { Int32 count = 0; foreach (LineD S in R) { Int32?result = HasIntersection(L, S); if (result == null) { return(null); } count += (Int32)result; } foreach (PointD P in R.GetVertexs()) { if (OnLine(L, P) == true) { count--; } } return(count); }
void ZoomToSelect() { if (mMap != null) { RectangleD sMBR = RectangleD.EmptyMBR; foreach (Layer sLayer in mMap.Layers) { foreach (DataRow sRow in sLayer.SelectedRecords) { if (!Convert.IsDBNull(sRow[2])) { sMBR += ((Geometry)sRow[2]).MBR; } } } if (sMBR.Width > 0 && sMBR.Height > 0) { mapControl1.ZoomByBox(sMBR); mapControl1.RefreshAllAsync(); } } }
private void btnLeadBodyAreaSet_Click(object sender, EventArgs e) { #region Button Status Set btnLeadBodyAreaShow.Enabled = true; btnLeadBodyAreaSet.Enabled = false; btnMaskingShow.Enabled = true; btnMaskingAdd.Enabled = false; btnMaskingSet.Enabled = false; btnMaskingUndo.Enabled = false; btnMaskingRedo.Enabled = false; btnMaskingClear.Enabled = false; #endregion var _GetRegionEvent = GetRegionEvent; CogRectangle _Region = GetRegionEvent?.Invoke(); var _DrawRegionEvent = DrawRegionEvent; _DrawRegionEvent?.Invoke(_Region, true); BodyArea = new RectangleD(); BodyArea.SetCenterWidthHeight(_Region.CenterX, _Region.CenterY, _Region.Width, _Region.Height); }
public EntitySide(PointD p, RectangleD bounds, EntitySideType type) { _type = type; switch (_type) { case EntitySideType.OnBottom: _range = Math.Abs(bounds.Top - p.Y); break; case EntitySideType.OnLeft: _range = Math.Abs(bounds.Right - p.X); break; case EntitySideType.OnRight: _range = Math.Abs(bounds.Left - p.X); break; case EntitySideType.OnTop: _range = Math.Abs(bounds.Bottom - p.Y); break; } }
/// <summary> /// 判断R1与R2是否有交集 /// </summary> /// <param name="R1">矩形R1</param> /// <param name="R2">矩形R2</param> /// <returns>如果有交集返回True,否则返回False。</returns> public static Boolean HasIntersection(RectangleD R1, RectangleD R2) { //第一个矩形左下角x1,y1,右上角x2,y2,第二个左下x3,y3,右上x4,y4 //1 当x2<x3 or x4<x1 or y4<y1 or y3>y2 没有交集 if (R1.Right < R2.Left) { return(false); //x2<x3 } if (R2.Right < R1.Left) { return(false); //x4<x1 } if (R2.Bottom < R1.Top) { return(false); //y4<y1 } if (R1.Bottom < R2.Top) { return(false); //y2<y3 } return(true); }
private void CalculateTextViewSize() { int paddingLeft = (int)(Figure as MultiLineTextFigure).PaddingLeft; int paddingTop = (int)(Figure as MultiLineTextFigure).PaddingTop; int paddingRight = (int)(Figure as MultiLineTextFigure).PaddingRight; int paddingBottom = (int)(Figure as MultiLineTextFigure).PaddingBottom; RectangleD r = Figure.DisplayBox; r.Inflate(-paddingLeft, -paddingTop, -paddingRight, -paddingBottom); // Drawing Coordinates must be translated to View's coordinates in order to // Correctly put the widget in the DrawingView PointD point = View.DrawingToView(r.X, r.Y); int x = (int)point.X; int y = (int)point.Y; int w = (int)Math.Max(r.Width, 10.0) + _textview.RightMargin * 2; int h = (int)Math.Max(r.Height, 10.0); _textview.SetSizeRequest(w, h); View.MoveWidget(_textview, x, y); }
private RenderText FindRenderText(RenderFragmentCollection frags, PointF pt, float dpix, float dpiy) { foreach (RenderFragment rf in frags) { RectangleD rd = rf.Document.FromRU(rf.Bounds, UnitTypeEnum.Pixel, dpix, dpiy); RectangleF rrf = new RectangleF((float)rd.X, (float)rd.Y, (float)rd.Width, (float)rd.Height); if (rrf.Contains(pt)) { if (rf.RenderObject is RenderText) { return(rf.RenderObject as RenderText); } else { pt.X -= (float)rd.Left; pt.Y -= (float)rd.Top; return(FindRenderText(rf.Children, pt, dpix, dpiy)); } } } return(null); }
public RectangleD CalcBBox() { var minX = double.MaxValue; var minY = double.MaxValue; var maxX = double.MinValue; var maxY = double.MinValue; foreach (var coordList in Shape.Coordinates) { foreach (var coord in coordList) { minX = Math.Min(coord.Longitude, minX); maxX = Math.Max(coord.Longitude, maxX); minY = Math.Min(coord.Latitude, minY); maxY = Math.Max(coord.Latitude, maxY); } } return(RectangleD.FromLTRB(minX, maxY, maxX, minY)); }
// Find a box that fits inside the MinMax quadrilateral. private static RectangleD GetMinMaxBox(List <PointD> points) { // Find the MinMax quadrilateral. PointD ul = new PointD(0, 0), ur = ul, ll = ul, lr = ul; GetMinMaxCorners(points, ref ul, ref ur, ref ll, ref lr); // Get the coordinates of a box that lies inside this quadrilateral. double xmin, xmax, ymin, ymax; xmin = ul.X; ymin = ul.Y; xmax = ur.X; if (ymin < ur.Y) { ymin = ur.Y; } if (xmax > lr.X) { xmax = lr.X; } ymax = lr.Y; if (xmin < ll.X) { xmin = ll.X; } if (ymax > ll.Y) { ymax = ll.Y; } RectangleD result = new RectangleD(xmin, xmax, ymin, ymax); g_MinMaxBox = result; // For debugging. return(result); }
// highlight the render object under the mouse, if any private void c1PrintPreviewControl1_PreviewPane_Paint(object sender, PaintEventArgs e) { if (_roUnderMouse == null) { return; } C1PreviewPane pane = c1PrintPreviewControl1.PreviewPane; // paint red rectangles over all fragments of the render object foreach (RenderFragment rf in _roUnderMouse.Fragments) { RectangleD rd = rf.BoundsOnPage; // FromRU converts from "resolved units" (units in which fragment's bounds are // expressed) to any desired unit - in our case, we convert to pixels RectangleD rpreview = _roUnderMouse.Document.FromRU(rd, UnitTypeEnum.Pixel, pane.DpiX, pane.DpiY); // but because the document does not know anything about the preview's zoom // or offset of pages in the preview, we convert "document pixels" to preview ones: RectangleF rectf = pane.DocumentToClient(rf.PageIndex, rpreview.ToRectangleF()); // finally, highlight the rectangle in the preview pane: e.Graphics.DrawRectangle(_hilitePen, rectf.X, rectf.Y, rectf.Width, rectf.Height); } }
/// <summary> /// 获取线段L与矩形R的交点集合 /// </summary> /// <param name="L">线段L</param> /// <param name="R">矩形R</param> /// <returns>返回交点集合,如果有无数个交点则返回null.</returns> public static PointD[] Intersection(LineD L, RectangleD R) { List <PointD> result = new List <PointD>(); foreach (LineD S in R) { PointD[] P = Intersection(L, S); if (P == null) { return(null); } if (P.Length == 0) { continue; } if (result.Contains(P[0]) == false) { result.Add((PointD)P[0]); } } return(result.ToArray()); }
public override void Draw(Graphics g, RectangleD worldRect, Rectangle canvasRect) { base.Draw(g, worldRect, canvasRect); using (var font = new Font(Chart.Font.FontFamily, fontSize)) using (var penStorage = new PenStorage()) using (var brushStorage = new BrushesStorage()) { var brush = brushStorage.GetBrush(Color.White); foreach (var span in data) { DrawSpan(g, worldRect, canvasRect, span, brush, penStorage); } foreach (var proj in projections) { DrawProjection(g, worldRect, canvasRect, proj, brush, font, penStorage, brushStorage); } } }
/// <summary> /// Helper function for TranslateAccessibleObject and EnsureAccessibleObjectVisible /// </summary> private DiagramItem TranslateAccessibleObjectToDiagramItem(AccessibleObject accessibleObject, bool returnShape) { if (accessibleObject == null) { return(null); } DiagramItem hitItem = null; DiagramClientView clientView = myClientView; DiagramHitTestInfo hitInfo = new DiagramHitTestInfo(clientView); RectangleD boundsD = clientView.DeviceToWorld(clientView.RectangleToClient(accessibleObject.Bounds)); if (clientView.Diagram.DoHitTest(boundsD.Center, hitInfo, false)) { hitItem = hitInfo.HitDiagramItem; if (!returnShape) { // Wind back out the parent stack if the hit test went too far if (hitItem.SubField != null) { if (!(accessibleObject is SubfieldAccessibleObject)) { if (!(accessibleObject is FieldAccessibleObject)) { hitItem = new DiagramItem(hitItem.Shape); } else { hitItem = new DiagramItem(hitItem.Shape, hitItem.Field); } } } else if (hitItem.Field != null && !(accessibleObject is FieldAccessibleObject)) { hitItem = new DiagramItem(hitItem.Shape); } } } return(hitItem); }
public TerrainTile( RectangleD extent, Vector2I resolution, float[] heights, float minimumHeight, float maximumHeight) { if (extent.UpperRight.X <= extent.LowerLeft.X || extent.UpperRight.Y <= extent.LowerLeft.Y) { throw new ArgumentOutOfRangeException("extent"); } if (resolution.X < 0 || resolution.Y < 0) { throw new ArgumentOutOfRangeException("resolution"); } if (heights == null) { throw new ArgumentNullException("heights"); } if (heights.Length != resolution.X * resolution.Y) { throw new ArgumentException("heights.Length != resolution.Width * resolution.Height"); } if (minimumHeight > maximumHeight) { throw new ArgumentOutOfRangeException("minimumHeight", "minimumHeight > maximumHeight"); } _extent = extent; _resolution = resolution; _heights = heights; _minimumHeight = minimumHeight; _maximumHeight = maximumHeight; }
public override RectangleD GetCompliantBounds(ShapeElement shape, RectangleD proposedBounds) { RectangleD compliantBounds = VDDefaultBoundsRules.Instance.GetCompliantBounds(shape, proposedBounds); VDCodeSnippetBodyShape bodyShape = shape as VDCodeSnippetBodyShape; if (bodyShape == null) { return(compliantBounds); } VDCodeSnippetShape parentShape = bodyShape.ParentShape as VDCodeSnippetShape; if (parentShape == null) { return(compliantBounds); } compliantBounds.Size = parentShape.Bounds.Size; compliantBounds.X = 0; TextField field = parentShape.FindShapeField(VDCodeSnippetShape.FieldName_PreContent) as TextField; if (field != null) { SizeD size = field.GetMinimumSize(parentShape); compliantBounds.Y = size.Height; compliantBounds.Height -= size.Height; } field = parentShape.FindShapeField(VDCodeSnippetShape.FieldName_PostContent) as TextField; if (field != null) { SizeD size = field.GetMinimumSize(parentShape); compliantBounds.Height -= size.Height; } return(compliantBounds); }
private void DrawRegion(BarRegion r, Graphics g, RectangleD worldRect, Rectangle canvasRect) { double x1 = r.IndexStart.HasValue ? r.IndexStart.Value : r.Start.HasValue ? Chart.CandleRange.GetXCoord(r.Start.Value) : worldRect.Left; double x2 = r.IndexEnd.HasValue ? r.IndexEnd.Value : r.End.HasValue ? Chart.CandleRange.GetXCoord(r.End.Value) : worldRect.Right; if (x2 == x2) { x1 -= singleBarRegionWidth; x2 += singleBarRegionWidth; } double y1 = r.UpperBound.HasValue ? r.UpperBound.Value : worldRect.Bottom; double y2 = r.LowerBound.HasValue ? r.LowerBound.Value : worldRect.Top; PointD p1 = Conversion.WorldToScreen(new PointD(x1, y1), worldRect, canvasRect); PointD p2 = Conversion.WorldToScreen(new PointD(x2, y2), worldRect, canvasRect); if (!DrawAsFrame) { var color = CustomAlphaChannel ? r.Color : Color.FromArgb(regionAlpha, r.Color); using (var brush = new SolidBrush(color)) { g.FillRectangle(brush, (float)p1.X, (float)p1.Y, (float)p2.X - (float)p1.X, (float)p2.Y - (float)p1.Y); } } else { using (var pen = r.MakePen()) { g.DrawRectangle(pen, (float)p1.X, (float)p1.Y, (float)p2.X - (float)p1.X, (float)p2.Y - (float)p1.Y); } } }
private void btnBodyAreaCheck_Click(object sender, EventArgs e) { CogRectangle _InspRegion = new CogRectangle(); _InspRegion.SetCenterWidthHeight(BodyArea.CenterX, BodyArea.CenterY, BodyArea.Width, BodyArea.Height); CogLeadTrimResult _CogLeadTrimResult = new CogLeadTrimResult(); CogLeadTrimAlgo _LeadTrimAlgoDest = new CogLeadTrimAlgo(ResolutionX, ResolutionY); _LeadTrimAlgoDest.BodyCenterOrigin.X = CogLeadTrimAlgoRcp.BodyCenterOrigin.X; _LeadTrimAlgoDest.BodyCenterOrigin.Y = CogLeadTrimAlgoRcp.BodyCenterOrigin.Y; _LeadTrimAlgoDest.BodyMaskingAreaList = new List <RectangleD>(); //for (int iLoopCount = 0; iLoopCount < CogLeadTrimAlgoRcp.BodyMaskingAreaList.Count; ++iLoopCount) //{ // RectangleD _Area = new RectangleD(); // _Area.SetCenterWidthHeight(CogLeadTrimAlgoRcp.BodyMaskingAreaList[iLoopCount].CenterX, CogLeadTrimAlgoRcp.BodyMaskingAreaList[iLoopCount].CenterY, CogLeadTrimAlgoRcp.BodyMaskingAreaList[iLoopCount].Width, CogLeadTrimAlgoRcp.BodyMaskingAreaList[iLoopCount].Height); // _LeadTrimAlgoDest.BodyMaskingAreaList.Add(_Area); //} for (int iLoopCount = 0; iLoopCount < CogLeadTrimAlgoRcp.BodyMaskingAreaList.Count; ++iLoopCount) { RectangleD _Area = new RectangleD(); _Area.SetCenterWidthHeight(BodyMaskingAreaList[iLoopCount].CenterX, BodyMaskingAreaList[iLoopCount].CenterY, BodyMaskingAreaList[iLoopCount].Width, BodyMaskingAreaList[iLoopCount].Height); _LeadTrimAlgoDest.BodyMaskingAreaList.Add(_Area); } var _ApplyLeadTrimValueEvent = ApplyLeadTrimValueEvent; _ApplyLeadTrimValueEvent?.Invoke(CogLeadTrimAlgo.eAlgoMode.BODY_CHECK, _InspRegion, _LeadTrimAlgoDest, ref _CogLeadTrimResult); //_ApplyLeadTrimValueEvent?.Invoke(CogLeadTrimAlgo.eAlgoMode.BODY_CHECK, _InspRegion, CogLeadTrimAlgoRcp, ref _CogLeadTrimResult); BodyCenterOriginX = _CogLeadTrimResult.LeadBodyOriginX; BodyCenterOriginY = _CogLeadTrimResult.LeadBodyOriginY; BodyCenterOffsetX = _CogLeadTrimResult.LeadBodyOffsetX; BodyCenterOffsetY = _CogLeadTrimResult.LeadBodyOffsetY; IsLeadBodyCheck = true; }
public override void Draw(Graphics g, RectangleD worldRect, Rectangle canvasRect) { var size = SizeD.Round(Conversion.WorldToScreen( new SizeD(barWidth / 100.0, 0.0), worldRect, canvasRect)); var barWd = Math.Max(size.Width, 2); var left = worldRect.Left <= 0 ? 0 : (int)worldRect.Left; var right = worldRect.Right >= data.Count ? data.Count - 1 : (int)worldRect.Right; if (right <= left) { return; } for (var i = left; i <= right; i++) //foreach (var bar in data) { var bar = data[i]; Point pointTop = Conversion.WorldToScreen( new PointD(bar.index - 0.45, bar.y), worldRect, canvasRect).Round(); Point pointBottom = Conversion.WorldToScreen( new PointD(bar.index - 0.45, 0), worldRect, canvasRect).Round(); using (var brush = new SolidBrush(bar.color)) { var low = Math.Min(pointTop.Y, pointBottom.Y); var height = Math.Abs(pointTop.Y - pointBottom.Y); g.FillRectangle(brush, pointTop.X - (barWd / 2), low, barWd, height); } } }
/// <summary> /// Renders the space craft at it's correct scale and rotation according to the camera. /// The engines are rendered first and then the space craft body. /// </summary> public override void RenderGdi(Graphics graphics, RectangleD cameraBounds) { // Only draws the ship if it's visible if (Visibility(cameraBounds) > 0) { RectangleD bounds = ComputeBoundingBox(); // In range for render if (cameraBounds.IntersectsWith(bounds)) { RectangleF screenBounds = RenderUtils.ComputeBoundingBox(Position, cameraBounds, Width, Height); // Saftey if (screenBounds.Width > RenderUtils.ScreenWidth * 500) { return; } RenderBelow(graphics, cameraBounds); RenderShip(graphics, cameraBounds, screenBounds); RenderAbove(graphics, cameraBounds); } } // Only draw orbit traces and launch trails for detatched ships if (Parent == null) { if (cameraBounds.Width > 1000) { _launchTrail.Draw(graphics, cameraBounds, GravitationalParent); } // Don't draw orbit traces on the ground base.RenderGdi(graphics, cameraBounds); } }
void PanToSelect() { if (mMap != null) { RectangleD sMBR = RectangleD.EmptyMBR; foreach (Layer sLayer in mMap.Layers) { foreach (DataRow sRow in sLayer.SelectedRecords) { if (!Convert.IsDBNull(sRow[2])) { sMBR += ((Geometry)sRow[2]).MBR; } } } if (sMBR.Width > 0 && sMBR.Height > 0) { PointD sCenter = new PointD(sMBR.MinX + sMBR.Width / 2, sMBR.MinY + sMBR.Height / 2); mapControl1.MoveTo(sCenter); mapControl1.RefreshAllAsync(); } } }
private void CalculateSizeEntry() { int paddingLeft = (int)(Figure as SimpleTextFigure).PaddingLeft; int paddingTop = (int)(Figure as SimpleTextFigure).PaddingTop; int paddingRight = (int)(Figure as MultiLineTextFigure).PaddingRight; int paddingBottom = (int)(Figure as MultiLineTextFigure).PaddingBottom; RectangleD r = Figure.DisplayBox; r.Inflate(-paddingLeft, -paddingTop, -paddingRight, -paddingBottom); r.Inflate(5, 5); // Drawing Coordinates must be translated to View's coordinates in order to // Correctly put the widget in the DrawingView PointD point = View.DrawingToView(r.X, r.Y); int x = (int)Math.Round(point.X, 0); int y = (int)Math.Round(point.Y, 0); int w = (int)Math.Max(r.Width, 10.0); int h = (int)Math.Max(r.Height, 10.0); View.MoveWidget(_entry, x, y); _entry.SetSizeRequest(w, h); }