// 圆角代码 public void Round(System.Drawing.Region region) { // ----------------------------------------------------------------------------------------------- // 已经是.net提供给我们的最容易的改窗体的属性了(以前要自己调API) System.Drawing.Drawing2D.GraphicsPath oPath = new System.Drawing.Drawing2D.GraphicsPath(); int x = 0; int y = 0; int thisWidth = this.Width; int thisHeight = this.Height; int angle = _Radius; if (angle > 0) { oPath.AddEllipse(x, y, this.Width, this.Height); // 左下角 oPath.CloseAllFigures(); Region = new System.Drawing.Region(oPath); } // ----------------------------------------------------------------------------------------------- else { oPath.AddLine(x + angle, y, thisWidth - angle, y); // 顶端 oPath.AddLine(thisWidth, y + angle, thisWidth, thisHeight - angle); // 右边 oPath.AddLine(thisWidth - angle, thisHeight, x + angle, thisHeight); // 底边 oPath.AddLine(x, y + angle, x, thisHeight - angle); oPath.Flatten(); // 左边 oPath.CloseAllFigures(); Region = new System.Drawing.Region(oPath); } }
// 圆角代码 public void Round(System.Drawing.Region region) { // ----------------------------------------------------------------------------------------------- // 已经是.net提供给我们的最容易的改窗体的属性了(以前要自己调API) System.Drawing.Drawing2D.GraphicsPath oPath = new System.Drawing.Drawing2D.GraphicsPath(); int x = 0; int y = 0; int thisWidth = this.Width; int thisHeight = this.Height; int angle = _Radius; if (angle > 0) { System.Drawing.Graphics g = CreateGraphics(); oPath.AddArc(x, y, angle, angle, 180, 90); // 左上角 oPath.AddArc(thisWidth - angle, y, angle, angle, 270, 90); // 右上角 oPath.AddArc(thisWidth - angle, thisHeight - angle, angle, angle, 0, 90); // 右下角 oPath.AddArc(x, thisHeight - angle, angle, angle, 90, 90); // 左下角 oPath.CloseAllFigures(); Region = new System.Drawing.Region(oPath); } // ----------------------------------------------------------------------------------------------- else { oPath.AddLine(x + angle, y, thisWidth - angle, y); // 顶端 oPath.AddLine(thisWidth, y + angle, thisWidth, thisHeight - angle); // 右边 oPath.AddLine(thisWidth - angle, thisHeight, x + angle, thisHeight); // 底边 oPath.AddLine(x, y + angle, x, thisHeight - angle); // 左边 oPath.CloseAllFigures(); Region = new System.Drawing.Region(oPath); } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics g = e.Graphics; g.Clear(this.BackColor); GraphicsPath gp1 = new GraphicsPath(); GraphicsPath gp2 = new GraphicsPath(); float xInnerPos = -innerRadius / 2f + this.Width / 2f; float yInnerPos = -innerRadius / 2f + this.Height / 2f; float xOuterPos = -outerRadius / 2f + this.Width / 2f; float yOuterPos = -outerRadius / 2f + this.Height / 2f; if (innerRadius != 0.0) { gp1.AddPie(xInnerPos, yInnerPos, innerRadius, innerRadius, startAngle, sweepAngle); } gp2.AddPie(xOuterPos, yOuterPos, outerRadius, outerRadius, startAngle, sweepAngle); Region rg1 = new System.Drawing.Region(gp1); Region rg2 = new System.Drawing.Region(gp2); g.DrawPath(Pens.Transparent, gp1); g.DrawPath(Pens.Transparent, gp2); rg1.Xor(rg2); g.FillRegion(Brushes.Black, rg1); this.Region = rg1; }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics g = e.Graphics; g.Clear(this.BackColor); GraphicsPath gp1 = new GraphicsPath(); GraphicsPath gp2 = new GraphicsPath(); gp1.AddPie(0, 0, this.Width, this.Height, 0, 90); gp2.AddPie(this.Width / 4f, this.Height / 4f, this.Width / 2f, this.Height / 2f, 0, 90); Region rg1 = new System.Drawing.Region(gp1); Region rg2 = new System.Drawing.Region(gp2); g.DrawPath(Pens.Transparent, gp1); g.DrawPath(Pens.Transparent, gp2); rg1.Xor(rg2); g.FillRegion(Brushes.Black, rg1); this.Region = rg1; }
private bool HitTestForOutLine(System.Drawing.PointF[] points, Point hitPoint) { bool retVal = false; for (int i = 0; i < HandleCount - 1; i++) { // Create path which contains wide line // for easy mouse selection GraphicsPath areaPath1 = new GraphicsPath(); System.Drawing.Pen AreaPen1 = new System.Drawing.Pen(System.Drawing.Color.Black, 2); areaPath1.AddLine(points[i].X, points[i].Y, points[i + 1].X, points[i + 1].Y); areaPath1.Widen(AreaPen1); // Create region from the path System.Drawing.Region areaRegion = new System.Drawing.Region(areaPath1); System.Drawing.Point hPoint = new System.Drawing.Point(hitPoint.X, hitPoint.Y); retVal = areaRegion.IsVisible(hPoint); InsertAt = i + 1; _pointToInsert = new Point(hitPoint.X, hitPoint.Y); if (retVal) { break; } } return(retVal); }
private System.Drawing.Point GetCharSize(System.Drawing.Graphics CurGraphics) { //prntSome.printSome("GetCharSize"); // DrawString doesn't actually print where you tell it to but instead consistently prints // with an offset. This is annoying when the other draw commands do not print with an offset // this method returns a point defining the offset so we can take it off the printstring command. System.Drawing.CharacterRange[] characterRanges = { new System.Drawing.CharacterRange(0, 1) }; System.Drawing.RectangleF layoutRect = new System.Drawing.RectangleF(0, 0, 100, 100); System.Drawing.StringFormat stringFormat = new System.Drawing.StringFormat(); stringFormat.SetMeasurableCharacterRanges(characterRanges); System.Drawing.Region[] stringRegions = new System.Drawing.Region[1]; stringRegions = CurGraphics.MeasureCharacterRanges( "A", this.Font, layoutRect, stringFormat); System.Drawing.RectangleF measureRect1 = stringRegions[0].GetBounds(CurGraphics); return(new System.Drawing.Point((int)(measureRect1.Width + 0.5), (int)(measureRect1.Height + 0.5))); }
/// <summary> /// 圆角代码 /// </summary> public void Round() { GraphicsPath oPath = new GraphicsPath(); const int x = 0; const int y = 0; int thisWidth = this.Width; int thisHeight = this.Height; int angle = _radius; if (angle > 0) { oPath.AddArc(x, y, angle, angle, 180, 90); // 左上角 oPath.AddArc(thisWidth - angle, y, angle, angle, 270, 90); // 右上角 oPath.AddArc(thisWidth - angle, thisHeight - angle, angle, angle, 0, 90); // 右下角 oPath.AddArc(x, thisHeight - angle, angle, angle, 90, 90); // 左下角 oPath.CloseAllFigures(); Region = new System.Drawing.Region(oPath); } else { oPath.AddLine(x + angle, y, thisWidth - angle, y); // 顶端 oPath.AddLine(thisWidth, y + angle, thisWidth, thisHeight - angle); // 右边 oPath.AddLine(thisWidth - angle, thisHeight, x + angle, thisHeight); // 底边 oPath.AddLine(x, y + angle, x, thisHeight - angle); // 左边 oPath.CloseAllFigures(); Region = new System.Drawing.Region(oPath); } }
public Form1() { InitializeComponent(); saveLogs("InitializeComponent"); cookies = ReadCookiesFromDisk("cookies.dat"); if ((!check()) && (Properties.Settings.Default.email != "") && (Properties.Settings.Default.password != "")) { if (!auth()) resultLabel.Text = "Error authentication"; } Microsoft.Win32.RegistryKey readKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\ETS2MP"); if (readKey != null) { regInstallLocation = (string)readKey.GetValue("InstallLocation"); regInstallDir = (string)readKey.GetValue("InstallDir"); } else { saveLogs("Game not found!"); } System.Drawing.Drawing2D.GraphicsPath Button_Path = new System.Drawing.Drawing2D.GraphicsPath(); Button_Path.AddEllipse(0, 0, btnPlay.Width, btnPlay.Height); System.Drawing.Region Button_Region = new System.Drawing.Region(Button_Path); this.btnPlay.Region = Button_Region; }
public Form1() { InitializeComponent(); saveLogs("InitializeComponent"); cookies = ReadCookiesFromDisk("cookies.dat"); if ((!check()) && (Properties.Settings.Default.email != "") && (Properties.Settings.Default.password != "")) { if (!auth()) { resultLabel.Text = "Error authentication"; } } Microsoft.Win32.RegistryKey readKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\ETS2MP"); if (readKey != null) { regInstallLocation = (string)readKey.GetValue("InstallLocation"); regInstallDir = (string)readKey.GetValue("InstallDir"); } else { saveLogs("Game not found!"); } System.Drawing.Drawing2D.GraphicsPath Button_Path = new System.Drawing.Drawing2D.GraphicsPath(); Button_Path.AddEllipse(0, 0, btnPlay.Width, btnPlay.Height); System.Drawing.Region Button_Region = new System.Drawing.Region(Button_Path); this.btnPlay.Region = Button_Region; }
public Area(Shape s) { if (s == null) { region = new System.Drawing.Region(); } else if (s is Area) { Area a = (Area)s; if (a.region == null) { region = new System.Drawing.Region(); } else { region = (System.Drawing.Region)a.region.Clone(); } } else if (s is Rectangle) { Rectangle rc = (Rectangle)s; region = new System.Drawing.Region(new System.Drawing.Rectangle(rc.x, rc.y, rc.width, rc.height)); } else { serr.println( "fixme: org.kbinani.java.awt.Area#.ctor(org.kbinani.java.awt.Shape); type of argument s is not supported for '" + s.GetType() + "'."); region = new System.Drawing.Region(); } }
/// <summary> /// 角の丸いアイコンの画像領域を取得します /// </summary> /// <returns></returns> private System.Drawing.Region getRegion() { if (region == null) { region = new System.Drawing.Region(getGraphicsPath()); } return(region); }
public void SetRegion(IntPtr hwnd, System.Drawing.Region region) { var graphics = System.Drawing.Graphics.FromHwnd(hwnd); hRgnBlur = region.GetHrgn(graphics); dwFlags |= DWM_BB.BlurRegion; graphics.Dispose(); }
protected override void OnPaint(PaintEventArgs pevent) { GraphicsPath grPath = new GraphicsPath(); grPath.AddEllipse(0, 0, ClientSize.Width, ClientSize.Height); Region = new System.Drawing.Region(grPath); base.OnPaint(pevent); }
protected override void OnPaint(PaintEventArgs pevent) { base.OnPaint(pevent); GraphicsPath graphicsPath = new GraphicsPath(); graphicsPath.AddEllipse(ClientRectangle.X + 2, ClientRectangle.Y + 2, ClientSize.Width - 4, ClientSize.Height - 4); Region = new System.Drawing.Region(graphicsPath); }
public override void Dispose() { if (rgn != null) { rgn.Dispose(); rgn = null; } }
public override void Dispose() { if (rgn != null) { rgn.Dispose(); rgn = null; } }
public static bool GetWindowRegion(IntPtr hWnd, out System.Drawing.Region region) { IntPtr hRgn = CreateRectRgn(0, 0, 0, 0); RegionType regionType = (RegionType)GetWindowRgn(hWnd, hRgn); region = System.Drawing.Region.FromHrgn(hRgn); return(regionType != RegionType.ERROR && regionType != RegionType.NULLREGION); }
/// <summary> /// アイコンの画像領域以外の領域(4隅)を取得します /// </summary> /// <returns></returns> private System.Drawing.Region getInvRegion() { if (invRegion == null) { invRegion = new System.Drawing.Region(); invRegion.Exclude(getGraphicsPath()); } return(invRegion); }
public void Clip(IReadOnlyRegion2D region) { var clip = new System.Drawing.Region(System.Drawing.Rectangle.Empty); foreach (var rect in region.Rects) { clip.Union(new System.Drawing.Rectangle(rect.X, rect.Y, rect.Width, rect.Height)); } Graphics.SetClip(clip, System.Drawing.Drawing2D.CombineMode.Replace); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> Genera el evento <see cref="E:System.Windows.Forms.Control.Paint" />.\n /// Generate event <see cref="E:System.Windows.Forms.Control.Paint" />. </summary> /// /// <remarks> Javier Fernández Fernández, 19/04/2020. </remarks> /// /// <param name="pe"> /// Objeto <see cref="T:System.Windows.Forms.PaintEventArgs" /> que contiene los datos del evento. /// Object <see cref="T:System.Windows.Forms.PaintEventArgs" /> that contain all data of the event. /// </param> //////////////////////////////////////////////////////////////////////////////////////////////////// protected override void OnPaint(PaintEventArgs pe) { try { GraphicsPath gPath = new GraphicsPath(); gPath.AddEllipse(0, 0, ClientSize.Width, ClientSize.Height); Region = new System.Drawing.Region(gPath); base.OnPaint(pe); } catch (Exception ex) { Utilities.createErrorMessage(ex.Message.ToString(), Utilities.showDevelopMessages, 406, null); } }
protected override void OnPaint(PaintEventArgs pe) { base.OnPaint(pe); pe.Graphics.SmoothingMode = SmoothingMode.HighQuality; pe.Graphics.DrawEllipse(new System.Drawing.Pen(new System.Drawing.SolidBrush(this.BackColor)), new System.Drawing.Rectangle(0, 0, this.Width - 2, this.Height - 2)); GraphicsPath gp = new GraphicsPath(); gp.AddEllipse(0, 0, this.Width - 1, this.Height - 1); Region = new System.Drawing.Region(gp); }
protected override void OnPaintBackground(PaintEventArgs e) { var buttonPath = new System.Drawing.Drawing2D.GraphicsPath(); var newRectangle = ClientRectangle; newRectangle.Inflate(-10, -10); e.Graphics.DrawEllipse(System.Drawing.Pens.Black, newRectangle); newRectangle.Inflate(1, 1); buttonPath.AddEllipse(newRectangle); Region = new System.Drawing.Region(buttonPath); base.OnPaintBackground(e); }
public override void Draw(RangePaintEventArgs e) { RangeRegion region = mSelection.GetSelectionRegion(); if (region.IsEmpty()) return; // get visible range for scrollable area Range visibleScrollabeRange = mSelection.Grid.RangeAtAreaExpanded(CellPositionType.Scrollable); System.Drawing.Brush brush = e.GraphicsCache.BrushsCache.GetBrush(mSelection.BackColor); CellContext focusContext = new CellContext(e.Grid, mSelection.ActivePosition); // get focus rectangle // clipped to visible range Range focusClippedRange = visibleScrollabeRange.Intersect(new Range(mSelection.ActivePosition, mSelection.ActivePosition)); System.Drawing.Rectangle focusRect = e.Grid.PositionToRectangle(focusClippedRange.Start); //Draw each selection range foreach (Range rangeToLoop in region) { // intersect given range with visible range // this way we ensure we don't loop through thousands // of rows to calculate rectToDraw Range rng = visibleScrollabeRange.Intersect(rangeToLoop); System.Drawing.Rectangle rectToDraw = e.Grid.RangeToRectangle(rng); if (rectToDraw == System.Drawing.Rectangle.Empty) continue; System.Drawing.Region regionToDraw = new System.Drawing.Region(rectToDraw); if (rectToDraw.IntersectsWith(focusRect)) regionToDraw.Exclude(focusRect); e.GraphicsCache.Graphics.FillRegion(brush, regionToDraw); //Draw the border only if there isn't a editing cell // and is the range that contains the focus or there is a single range if (rng.Contains(mSelection.ActivePosition) || region.Count == 1) { if (focusContext.IsEditing() == false) mSelection.Border.Draw(e.GraphicsCache, rectToDraw); } } //Draw Focus System.Drawing.Brush brushFocus = e.GraphicsCache.BrushsCache.GetBrush(mSelection.FocusBackColor); e.GraphicsCache.Graphics.FillRectangle(brushFocus, focusRect); }
public override void Draw(RangePaintEventArgs e) { RangeRegion region = mSelection.GetSelectionRegion(); if (region.IsEmpty()) { return; } System.Drawing.Brush brush = e.GraphicsCache.BrushsCache.GetBrush(mSelection.BackColor); CellContext focusContext = new CellContext(e.Grid, mSelection.ActivePosition); System.Drawing.Rectangle focusRect = e.Grid.PositionToRectangle(mSelection.ActivePosition); RangeCollection ranges = region.GetRanges(); //Draw each selection range foreach (Range rng in ranges) { System.Drawing.Rectangle rectToDraw = e.Grid.RangeToRectangle(rng); if (rectToDraw == System.Drawing.Rectangle.Empty) { continue; } System.Drawing.Region regionToDraw = new System.Drawing.Region(rectToDraw); if (rectToDraw.IntersectsWith(focusRect)) { regionToDraw.Exclude(focusRect); } e.GraphicsCache.Graphics.FillRegion(brush, regionToDraw); //Draw the border only if there isn't a editing cell // and is the range that contains the focus or there is a single range if (rng.Contains(mSelection.ActivePosition) || ranges.Count == 1) { if (focusContext == null || focusContext.IsEditing() == false) { mSelection.Border.Draw(e.GraphicsCache, rectToDraw); } } } //Draw Focus System.Drawing.Brush brushFocus = e.GraphicsCache.BrushsCache.GetBrush(mSelection.FocusBackColor); e.GraphicsCache.Graphics.FillRectangle(brushFocus, focusRect); }
public void subtract(Area rhs) { if (rhs == null) { return; } if (rhs.region == null) { return; } if (region == null) { region = new System.Drawing.Region(); } region.Exclude(rhs.region); }
public void add(Area rhs) { if (rhs == null) { return; } if (rhs.region == null) { return; } if (region == null) { region = new System.Drawing.Region(); } region.Union(rhs.region); }
private System.Drawing.SizeF MeasureString(string s, System.Drawing.Graphics g, System.Drawing.Font drawFont, System.Drawing.StringFormat drawFormat) { if (s == null || s.Length == 0) { return(System.Drawing.SizeF.Empty); } System.Drawing.CharacterRange[] cr = { new System.Drawing.CharacterRange(0, s.Length) }; drawFormat.SetMeasurableCharacterRanges(cr); System.Drawing.Region[] rs = new System.Drawing.Region[1]; rs = g.MeasureCharacterRanges(s, drawFont, new System.Drawing.RectangleF(0, 0, float.MaxValue, float.MaxValue), drawFormat); System.Drawing.RectangleF mr = rs[0].GetBounds(g); return(new System.Drawing.SizeF(mr.Width, mr.Height)); }
// Permet d'ajouter une zone de glass public void AddGlass(System.Drawing.Rectangle Rect) { if (AeroActive > 0) { if (this.GlassRegion == null) // Teste si on a déjà une zone de glass { this.GlassRegion = new System.Drawing.Region(Rect); // On crée une nouvelle zone de glass } else { this.GlassRegion.Union(Rect); // On ajoute la zone à la region } this.FormRegion.Exclude(Rect); UpdateGlass(); } }
/// <summary> /// 点在区域中是否可见(现已废弃,替代方法 PointInPolygon) /// </summary> /// <param name="point"></param> /// <param name="pointColl"></param> /// <returns></returns> public static bool IsVisible_Region(Point point, List <Point> pointColl) { System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Region region = new System.Drawing.Region(); List <System.Drawing.Point> pathPoints = new List <System.Drawing.Point>(); foreach (var pathPoint in pointColl) { pathPoints.Add(new System.Drawing.Point((int)Math.Round(pathPoint.X), (int)Math.Round(pathPoint.Y))); } path.AddPolygon(pathPoints.ToArray()); path.CloseFigure(); region.MakeEmpty(); region.Union(path); return(region.IsVisible(new System.Drawing.Point((int)Math.Round(point.X), (int)Math.Round(point.Y)))); }
private void DrawInternal(System.Drawing.Graphics g, ICoordinateMapper coordinateMapper, System.Drawing.Rectangle renderingRect) { System.Drawing.Region oldClip = g.Clip; g.SetClip(renderingRect); System.Drawing.Drawing2D.Matrix oldMatrix = (System.Drawing.Drawing2D.Matrix)g.Transform.Clone(); try { if (_rect.DrawMode == VObjectDrawMode.Normal) { g.SmoothingMode = normalSmoothingMode; g.InterpolationMode = normalInterpolationMode; } else { g.SmoothingMode = draftSmoothingMode; g.InterpolationMode = draftInterpolationMode; } System.Drawing.RectangleF bounds = _rect.GetVObjectBounds(); System.Drawing.RectangleF transformedBounds = _rect.GetTransformedVObjectBounds(); System.Drawing.Rectangle mappedBounds = coordinateMapper.WorkspaceToControl(transformedBounds, Aurigma.GraphicsMill.Unit.Point); if (transformedBounds.Width > VObject.Eps && transformedBounds.Height > VObject.Eps) { float scaleX = mappedBounds.Width / transformedBounds.Width, scaleY = mappedBounds.Height / transformedBounds.Height; using (System.Drawing.Drawing2D.Matrix outputMatrix = (System.Drawing.Drawing2D.Matrix)_rect.Transform.Clone()) { outputMatrix.Translate(-transformedBounds.X, -transformedBounds.Y, System.Drawing.Drawing2D.MatrixOrder.Append); outputMatrix.Scale(scaleX, scaleY, System.Drawing.Drawing2D.MatrixOrder.Append); outputMatrix.Translate(mappedBounds.X, mappedBounds.Y, System.Drawing.Drawing2D.MatrixOrder.Append); g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; g.Transform = outputMatrix; g.DrawImage(this.DrawnImage, 0, 0, bounds.Width, bounds.Height); } } } finally { g.Transform = oldMatrix; g.SetClip(oldClip, System.Drawing.Drawing2D.CombineMode.Replace); } }
/// <summary> /// Create graphic objects used from hit test. /// </summary> protected virtual void CreateObjects() { if (AreaPath != null) { return; } // Create path which contains wide line // for easy mouse selection AreaPath = new GraphicsPath(); AreaPen = new System.Drawing.Pen(System.Drawing.Color.Black, 2); AreaPath.AddLine(_startPoint.X, _startPoint.Y, _endPoint.X, _endPoint.Y); AreaPath.Widen(AreaPen); // Create region from the path AreaRegion = new System.Drawing.Region(AreaPath); }
private System.Drawing.Region BuildRegionFromBitmap(BitmapSource bitmap, Point offset) { var region = new System.Drawing.Region(); region.MakeEmpty(); var rectangle = System.Drawing.Rectangle.Empty; bool inImage = false; for (int y = 0; y < bitmap.Height; y++) { for (int x = 0; x < bitmap.Width; x++) { var croppedPixel = new CroppedBitmap(bitmap, new Int32Rect(x, y, 1, 1)); byte[] pixel = new byte[bitmap.Format.BitsPerPixel / 8]; croppedPixel.CopyPixels(pixel, bitmap.Format.BitsPerPixel / 8, 0); var pixelAlpha = pixel[0]; if (!inImage && pixelAlpha > 0) { inImage = true; rectangle.X = x; rectangle.Y = y; rectangle.Height = 1; } else if (inImage && pixelAlpha == 0) { inImage = false; rectangle.Width = x - rectangle.X; rectangle.Offset((int)offset.X, (int)offset.Y); region.Union(rectangle); } } if (inImage) { inImage = false; rectangle.Width = (int)bitmap.Width - rectangle.X; rectangle.Offset((int)offset.X, (int)offset.Y); region.Union(rectangle); } } return(region); }
public AeroGlassForm() { // On vérifie si on à bien vista if (!base.DesignMode && System.Environment.OSVersion.Version.Major >= 6) { // Teste si on a le theme glass d'activé DwmIsCompositionEnabled(ref AeroActive); if (AeroActive > 0) { this.FormRegion = new System.Drawing.Region(base.ClientRectangle); } } else { throw new System.Exception("Windows Vista or upper needed"); } }
//private static SySal.DAQSystem.Scanning.ZoneDesc[] GetRegionScans(SySal.DAQSystem.Scanning.ZoneDesc newZones, SySal.DAQSystem.Scanning.ZoneDesc[] oldZones) //{ // if (oldZones.Length == 1) return GetRegionScans(newZones, oldZones[0]); // foreach (SySal.DAQSystem.Scanning.ZoneDesc o in oldZones) // { // newZones = GetRegionScans(newZones, o); // } // return newZones; //} private static SySal.DAQSystem.Scanning.ZoneDesc[] GetRegionScans(SySal.DAQSystem.Scanning.ZoneDesc newZone, SySal.DAQSystem.Scanning.ZoneDesc oldZone) { float scale = 1000; float x = Convert.ToSingle(newZone.MinX / scale); float y = Convert.ToSingle(newZone.MinY / scale); float width = Convert.ToSingle((newZone.MaxX - newZone.MinX) / scale); float height = Convert.ToSingle((newZone.MaxY - newZone.MinY) / scale); System.Drawing.RectangleF ZoneToScan = new System.Drawing.RectangleF(x, y, width, height); x = Convert.ToSingle(oldZone.MinX / scale); y = Convert.ToSingle(oldZone.MinY / scale); width = Convert.ToSingle((oldZone.MaxX - oldZone.MinX) / scale); height = Convert.ToSingle((oldZone.MaxY - oldZone.MinY) / scale); System.Drawing.RectangleF OldZone = new System.Drawing.RectangleF(x, y, width, height); Console.WriteLine("ZoneToScan: " + ZoneToScan.Left + " " + ZoneToScan.Right + " " + ZoneToScan.Top + " " + ZoneToScan.Bottom); Console.WriteLine("OldZone: " + OldZone.Left + " " + OldZone.Right + " " + OldZone.Top + " " + OldZone.Bottom); System.Drawing.Region NewRegion = new System.Drawing.Region(ZoneToScan); NewRegion.Exclude(OldZone); System.Drawing.RectangleF[] rectangles = NewRegion.GetRegionScans(new System.Drawing.Drawing2D.Matrix()); if (rectangles.Length == 0) { return(null); } SySal.DAQSystem.Scanning.ZoneDesc[] zones = new SySal.DAQSystem.Scanning.ZoneDesc[rectangles.Length]; for (int i = 0; i < zones.Length; i++) { zones[i] = new SySal.DAQSystem.Scanning.ZoneDesc(); zones[i].MinX = rectangles[i].Left * scale; zones[i].MaxX = rectangles[i].Right * scale; zones[i].MinY = rectangles[i].Top * scale; zones[i].MaxY = rectangles[i].Bottom * scale; } return(zones); }
public override void Draw(RangePaintEventArgs e) { RangeRegion region = mSelection.GetSelectionRegion(); if (region.IsEmpty()) return; System.Drawing.Brush brush = e.GraphicsCache.BrushsCache.GetBrush(mSelection.BackColor); CellContext focusContext = new CellContext(e.Grid, mSelection.ActivePosition); System.Drawing.Rectangle focusRect = e.Grid.PositionToRectangle(mSelection.ActivePosition); RangeCollection ranges = region.GetRanges(); //Draw each selection range foreach (Range rng in ranges) { System.Drawing.Rectangle rectToDraw = e.Grid.RangeToRectangle(rng); if (rectToDraw == System.Drawing.Rectangle.Empty) continue; System.Drawing.Region regionToDraw = new System.Drawing.Region(rectToDraw); if (rectToDraw.IntersectsWith(focusRect)) regionToDraw.Exclude(focusRect); e.GraphicsCache.Graphics.FillRegion(brush, regionToDraw); //Draw the border only if there isn't a editing cell // and is the range that contains the focus or there is a single range if (rng.Contains(mSelection.ActivePosition) || ranges.Count == 1) { if (focusContext == null || focusContext.IsEditing() == false) mSelection.Border.Draw(e.GraphicsCache, rectToDraw); } } //Draw Focus System.Drawing.Brush brushFocus = e.GraphicsCache.BrushsCache.GetBrush(mSelection.FocusBackColor); e.GraphicsCache.Graphics.FillRectangle(brushFocus, focusRect); }
private double Area(BindableRect rect1) { System.Drawing.PointF[] vertices = new System.Drawing.PointF[] { rect1.BottomLeft.ToPointF(), rect1.TopLeft.ToPointF(), rect1.TopRight.ToPointF(), rect1.BottomRight.ToPointF()}; var rectangle = new System.Drawing.Drawing2D.GraphicsPath(); rectangle.AddPolygon(vertices); var region = new System.Drawing.Region(rectangle); var rects = region.GetRegionScans(new System.Drawing.Drawing2D.Matrix()); float area = 0; foreach (var rc in rects) area += rc.Width * rc.Height; return area; }
private double AreaMiss(BindableRect rect1, BindableRect rect2) { System.Drawing.PointF[] vertices1 = new System.Drawing.PointF[] { rect1.BottomLeft.ToPointF(), rect1.TopLeft.ToPointF(), rect1.TopRight.ToPointF(), rect1.BottomRight.ToPointF()}; var rectangle1 = new System.Drawing.Drawing2D.GraphicsPath(); rectangle1.AddPolygon(vertices1); System.Drawing.PointF[] vertices2 = new System.Drawing.PointF[] { rect2.BottomLeft.ToPointF(), rect2.TopLeft.ToPointF(), rect2.TopRight.ToPointF(), rect2.BottomRight.ToPointF()}; var rectangle2 = new System.Drawing.Drawing2D.GraphicsPath(); rectangle2.AddPolygon(vertices2); var region = new System.Drawing.Region(rectangle1); region.Complement(rectangle2); var rects = region.GetRegionScans(new System.Drawing.Drawing2D.Matrix()); float area = 0; foreach (var rc in rects) area += rc.Width * rc.Height; return area; }
public override void Draw(RangePaintEventArgs e) { RangeRegion region = mSelection.GetSelectionRegion(); if (region.IsEmpty()) return; // get visible range for scrollable area // AlanP: June 2014. Changed the call from RangeAtAreaExpanded to RangeAtArea to fix a bug that occurred on Partner/Find screen // The grid on this screen has 3 fixed columns on the left but the highlight was always applied to the cell 'behind' the last fixed column // as well as the rest of the row. This is because of getting the 'expanded' range. // To be honest I don't understand what the expanded range is for. The comment for it is not helpful (to me anyway). // It may be something to do with drawing the focus cell? If we see a problem later we could revies this code //Range visibleScrollabeRange = mSelection.Grid.RangeAtAreaExpanded(CellPositionType.Scrollable); Range visibleScrollableRange = mSelection.Grid.RangeAtArea(CellPositionType.Scrollable); System.Drawing.Brush brush = e.GraphicsCache.BrushsCache.GetBrush(mSelection.BackColor); // In OP we would like to have the rows of fixed columns highlighted as well - this seems non-standard // This code is the same as is used in the standard code below, but for the FixedLeft Range Range visibleFixedLeftRange = mSelection.Grid.RangeAtArea(CellPositionType.FixedLeft); foreach (Range rangeToLoop in region) { Range rng = visibleFixedLeftRange.Intersect(rangeToLoop); System.Drawing.Rectangle rectToDraw = e.Grid.RangeToRectangle(rng); if (rectToDraw == System.Drawing.Rectangle.Empty) continue; System.Drawing.Region regionToDraw = new System.Drawing.Region(rectToDraw); e.GraphicsCache.Graphics.FillRegion(brush, regionToDraw); } // Deal with the focus rectangle... The original grid code does not seem to support the focus being on a fixed column, which seems like a bug // but does not affect OpenPetra CellContext focusContext = new CellContext(e.Grid, mSelection.ActivePosition); // get focus rectangle // clipped to visible range Range focusClippedRange = visibleScrollableRange.Intersect(new Range(mSelection.ActivePosition, mSelection.ActivePosition)); System.Drawing.Rectangle focusRect = e.Grid.PositionToRectangle(focusClippedRange.Start); //Draw each selection range foreach (Range rangeToLoop in region) { // intersect given range with visible range // this way we ensure we don't loop through thousands // of rows to calculate rectToDraw Range rng = visibleScrollableRange.Intersect(rangeToLoop); System.Drawing.Rectangle rectToDraw = e.Grid.RangeToRectangle(rng); if (rectToDraw == System.Drawing.Rectangle.Empty) continue; System.Drawing.Region regionToDraw = new System.Drawing.Region(rectToDraw); if (rectToDraw.IntersectsWith(focusRect)) regionToDraw.Exclude(focusRect); e.GraphicsCache.Graphics.FillRegion(brush, regionToDraw); //Draw the border only if there isn't a editing cell // and is the range that contains the focus or there is a single range if (rng.Contains(mSelection.ActivePosition) || region.Count == 1) { if (focusContext.IsEditing() == false) mSelection.Border.Draw(e.GraphicsCache, rectToDraw); } } //Draw Focus System.Drawing.Brush brushFocus = e.GraphicsCache.BrushsCache.GetBrush(mSelection.FocusBackColor); e.GraphicsCache.Graphics.FillRectangle(brushFocus, focusRect); }
public void subtract( Area rhs ) { if ( rhs == null ) { return; } if ( rhs.region == null ) { return; } if ( region == null ) { region = new System.Drawing.Region(); } region.Exclude( rhs.region ); }
public void add( Area rhs ) { if ( rhs == null ) { return; } if ( rhs.region == null ) { return; } if ( region == null ) { region = new System.Drawing.Region(); } region.Union( rhs.region ); }
public Area( Shape s ) { if ( s == null ) { region = new System.Drawing.Region(); } else if ( s is Area ) { Area a = (Area)s; if ( a.region == null ) { region = new System.Drawing.Region(); } else { region = (System.Drawing.Region)a.region.Clone(); } } else if ( s is Rectangle ) { Rectangle rc = (Rectangle)s; region = new System.Drawing.Region( new System.Drawing.Rectangle( rc.x, rc.y, rc.width, rc.height ) ); } else { serr.println( "fixme: org.kbinani.java.awt.Area#.ctor(org.kbinani.java.awt.Shape); type of argument s is not supported for '" + s.GetType() + "'." ); region = new System.Drawing.Region(); } }
public Area() { region = new System.Drawing.Region(); region.MakeEmpty(); }
private System.Drawing.Point GetDrawStringOffset(System.Drawing.Graphics CurGraphics, System.Int32 X, System.Int32 Y, System.Char CurChar) { //prntSome.printSome("GetDrawStringOffset"); // DrawString doesn't actually print where you tell it to but instead consistently prints // with an offset. This is annoying when the other draw commands do not print with an offset // this method returns a point defining the offset so we can take it off the printstring command. System.Drawing.CharacterRange[] characterRanges = { new System.Drawing.CharacterRange(0, 1) }; System.Drawing.RectangleF layoutRect = new System.Drawing.RectangleF (X, Y, 100, 100); System.Drawing.StringFormat stringFormat = new System.Drawing.StringFormat(); stringFormat.SetMeasurableCharacterRanges(characterRanges); System.Drawing.Region[] stringRegions = new System.Drawing.Region[1]; stringRegions = CurGraphics.MeasureCharacterRanges( CurChar.ToString (), this.Font, layoutRect, stringFormat); System.Drawing.RectangleF measureRect1 = stringRegions[0].GetBounds (CurGraphics); return new System.Drawing.Point ((int) (measureRect1.X + 0.5), (int) (measureRect1.Y + 0.5)); }
/// <summary> /// 圆角代码 /// </summary> public void Round() { GraphicsPath oPath = new GraphicsPath(); const int x = 0; const int y = 0; int thisWidth = this.Width; int thisHeight = this.Height; int angle = _radius; if (angle > 0) { oPath.AddArc(x, y, angle, angle, 180, 90); // 左上角 oPath.AddArc(thisWidth - angle, y, angle, angle, 270, 90); // 右上角 oPath.AddArc(thisWidth - angle, thisHeight - angle, angle, angle, 0, 90); // 右下角 oPath.AddArc(x, thisHeight - angle, angle, angle, 90, 90); // 左下角 oPath.CloseAllFigures(); Region = new System.Drawing.Region(oPath); } else { oPath.AddLine(x + angle, y, thisWidth - angle, y); // 顶端 oPath.AddLine(thisWidth, y + angle, thisWidth, thisHeight - angle); // 右边 oPath.AddLine(thisWidth - angle, thisHeight, x + angle, thisHeight); // 底边 oPath.AddLine(x, y + angle, x, thisHeight - angle); // 左边 oPath.CloseAllFigures(); Region = new System.Drawing.Region(oPath); } }