public ScreenRegionForm(Rectangle regionRectangle, bool activateWindow = true) { InitializeComponent(); this.activateWindow = activateWindow; borderRectangle = regionRectangle.Offset(1); borderRectangle0Based = new Rectangle(0, 0, borderRectangle.Width, borderRectangle.Height); Location = borderRectangle.Location; int windowWidth = Math.Max(borderRectangle.Width, pInfo.Width); Size = new Size(windowWidth, borderRectangle.Height + pInfo.Height + 1); pInfo.Location = new Point(0, borderRectangle.Height + 1); Region region = new Region(ClientRectangle); region.Exclude(borderRectangle0Based.Offset(-1)); region.Exclude(new Rectangle(0, borderRectangle.Height, windowWidth, 1)); if (borderRectangle.Width < pInfo.Width) { region.Exclude(new Rectangle(borderRectangle.Width, 0, pInfo.Width - borderRectangle.Width, borderRectangle.Height)); } else if (borderRectangle.Width > pInfo.Width) { region.Exclude(new Rectangle(pInfo.Width, borderRectangle.Height + 1, borderRectangle.Width - pInfo.Width, pInfo.Height)); } Region = region; Timer = new Stopwatch(); }
public void PaintSelection(SelectionRendererEventArgs info) { Rectangle inside=info.Bounds; inside.Inflate(1,1); inside.Width--; inside.Height--; Rectangle outside=info.Bounds; outside.Inflate(info.Width,info.Width); outside.Width--; outside.Height--; if(!info.BorderColor.IsEmpty) { using(Pen pen=new Pen(info.BorderColor,1)) { info.Graphics.DrawRectangle(pen,inside); info.Graphics.DrawRectangle(pen,outside); } } if(!info.FillColor.IsEmpty) { using(SolidBrush brush=new SolidBrush(info.FillColor)) { Region region=new Region(outside); region.Exclude(inside); info.Graphics.FillRegion(brush,region); } } }
public void set_inner_surfaces(List <surface_store> i_inner_surfaces) { // add inner surface one after another for (int i = 0; i < i_inner_surfaces.Count; i++) { if (i_inner_surfaces[i].SignedPolygonArea() > 0) // check whether the inner surface is oriented clockwise (positive area = anti-clockwise) { // anti-clockwise orientation detected so reverse the orientation to be clockwise i_inner_surfaces[i].reverse_surface_orinetation(); } inner_surfaces.Add(i_inner_surfaces[i]); // inner surface is clockwise } //inner_surfaces.AddRange(i_inner_surfaces); foreach (surface_store surf in inner_surfaces) // cycle through all the inner surfaces { // Set the path of inner surface List <PointF> temp_sur_pts = new List <PointF>(); foreach (edge2d ed in surf.surface_edges) { temp_sur_pts.Add(ed.end_pt.get_point()); } System.Drawing.Drawing2D.GraphicsPath inner_surface = new System.Drawing.Drawing2D.GraphicsPath(); inner_surface.StartFigure(); inner_surface.AddPolygon(temp_sur_pts.ToArray()); inner_surface.CloseFigure(); // set region surface_region.Exclude(inner_surface); // exclude the inner surface region } }
/// <summary> /// Does a hit test for specified control (is point of control visible to user) /// </summary> /// <param name="ctrlRect">the rectangle (usually Bounds) of the control</param> /// <param name="ctrlHandle">the handle for the control</param> /// <returns>boolean value indicating if ctrlRect is overlayed by another control </returns> public static bool IsOverLayed( Rectangle ctrlRect, IntPtr ctrlHandle ) { // clear results enumedwindowPtrs.Clear(); enumedwindowRects.Clear(); // Create callback and start enumeration callBackPtr = new CallBackPtr( EnumCallBack ); EnumDesktopWindows( IntPtr.Zero, callBackPtr, 0 ); // Go from last to first window, and substract them from the ctrlRect area Region r = new Region( ctrlRect ); bool StartClipping = false; for( int i = enumedwindowRects.Count - 1; i >= 0; i-- ) { if( StartClipping ) { r.Exclude( enumedwindowRects[i] ); } if( enumedwindowPtrs[i] == ctrlHandle ) StartClipping = true; } //Creating a list of points scattered on the edges of the window. IList<System.Drawing.Point> pointList = new List<System.Drawing.Point>(); pointList.Add( new System.Drawing.Point( ctrlRect.X, ctrlRect.Y ) ); pointList.Add( new System.Drawing.Point( ctrlRect.X + ctrlRect.Width - 2, ctrlRect.Y ) ); pointList.Add( new System.Drawing.Point( ctrlRect.X + ctrlRect.Width - 2, ctrlRect.Y + ctrlRect.Height - 2 ) ); pointList.Add( new System.Drawing.Point( ctrlRect.X, ctrlRect.Y + ctrlRect.Height - 2 ) ); //TODO : choose the scale considering the width and height of the window. int scale = 50; int xOffset = 0; int yOffset = 0; int offset = 2; for( int x = 0; x <= scale; x++ ) { for( int y = 0; y <= scale; y++ ) { if( y == scale ) yOffset = offset; else yOffset = 0; if( x == scale ) xOffset = offset; else xOffset = 0; pointList.Add( new System.Drawing.Point( ctrlRect.X + ctrlRect.Width / scale * x - xOffset, ctrlRect.Y + ctrlRect.Height / scale * y - yOffset ) ); } } //Checking if theses points are visible by the user foreach( var item in pointList ) { if( !r.IsVisible( item ) ) return true; } return false; }
public ScreenRegionForm(Rectangle regionRectangle) { InitializeComponent(); borderRectangle = regionRectangle.RectangleOffset(1); borderRectangle0Based = new Rectangle(0, 0, borderRectangle.Width, borderRectangle.Height); Location = borderRectangle.Location; Size = new Size(borderRectangle.Width, borderRectangle.Height + pInfo.Height); pInfo.Location = new Point(Width - pInfo.Width, Height - pInfo.Height); Region region = new Region(ClientRectangle); region.Exclude(borderRectangle0Based.RectangleOffset(-1)); region.Exclude(new Rectangle(0, pInfo.Location.Y, pInfo.Location.X, pInfo.Height)); Region = region; Timer = new Stopwatch(); }
private void DrawRegion(Graphics graphics, Color color, bool drawPoints, bool fill, BTBLib.Region region) { Pen pen = new Pen(color, _regionPenWidth / _zoom); Brush brush = new SolidBrush(color); Point[] points = null; bool shouldFill = fill && region.IsClosed; if (shouldFill) { points = new Point[region.Lines.Count]; } for (int i = 0; i < region.Lines.Count; ++i) { var segment = region.Lines[i]; int startX = segment.StartX / 8; int startY = (_battle.Height - segment.StartY) / 8; int endX = segment.EndX / 8; int endY = (_battle.Height - segment.EndY) / 8; graphics.DrawLine(pen, startX, startY, endX, endY); if (drawPoints) { graphics.FillRectangle(brush, startX - _regionPointSize / 2, startY - _regionPointSize / 2, _regionPointSize, _regionPointSize); } if (shouldFill) { points[i] = new Point(startX, startY); } } if (drawPoints) { if (!region.IsClosed && region.Lines.Count > 0) { BTBLib.Region.LineSegment segment = region.Lines[region.Lines.Count - 1]; int endX = segment.EndX / 8; int endY = (_battle.Height - segment.EndY) / 8; graphics.FillRectangle(brush, endX - _regionPointSize / 2, endY - _regionPointSize / 2, _regionPointSize, _regionPointSize); } } if (shouldFill) { Brush regionBrush = new SolidBrush(Color.FromArgb(128, color.R, color.G, color.B)); if (region.IsBoundaryInversed) { System.Drawing.Region graphicsRegion = new System.Drawing.Region(); graphicsRegion.MakeInfinite(); GraphicsPath path = new GraphicsPath(); path.AddPolygon(points); graphicsRegion.Exclude(path); graphics.FillRegion(regionBrush, graphicsRegion); } else { graphics.FillPolygon(regionBrush, points); } } }
private void Form1_Load(object sender, EventArgs e) { rect = new Rectangle(Point.Empty, this.Size); region = new Region(rect); rect.Inflate(-1 * (this.Width - 3), -1 * (this.Height - 3)); region.Exclude(rect); this.Region = region; this.Owner = Program.GUIref; }
static BlockRegions() { int n = Constants.PROJ_WIDTH / 4; WholeBlock = new Region(); WholeBlock.MakeEmpty(); for (int i = 0; i <= n; i++) { WholeBlock.Union(new Rectangle(n * 2 - 1 - 2 * i, i, i * 4 + 2, Constants.PROJ_HEIGHT - 2 * i)); } WholeBlock.Intersect(new Rectangle(0, 0, Constants.PROJ_WIDTH, Constants.PROJ_HEIGHT)); InnerBlock = new Region(); InnerBlock.MakeEmpty(); for (int i = 0; i <= n; i++) { InnerBlock.Union(new Rectangle(n * 2 - 1 - 2 * i, i + 1, i * 4 + 2, Constants.PROJ_HEIGHT - 2 - 2 * i)); } InnerBlock.Intersect(new Rectangle(1, 1, Constants.PROJ_WIDTH - 2, Constants.PROJ_HEIGHT - 2)); OuterBorder = WholeBlock.Clone(); OuterBorder.Exclude(InnerBlock); Top = InnerBlock.Clone(); Top.Translate(0, -Constants.BLOCK_HEIGHT); Top.Intersect(InnerBlock); Left = InnerBlock.Clone(); Left.Exclude(Top); Top.Translate(0, 1); Left.Exclude(Top); Top.Translate(0, -1); Right = Left.Clone(); Left.Intersect(new Rectangle(0, 0, Constants.PROJ_WIDTH / 2, Constants.PROJ_HEIGHT)); Right.Intersect(new Rectangle(Constants.PROJ_WIDTH / 2 + 1, 0, Constants.PROJ_WIDTH / 2, Constants.PROJ_HEIGHT)); InnerBorder = InnerBlock.Clone(); InnerBorder.Exclude(Top); InnerBorder.Exclude(Left); InnerBorder.Exclude(Right); }
public void Set(Point location, int height) { Region rgn = new Region(BoundingRectangle); this.location = location; this.height = height; rgn.Exclude(BoundingRectangle); owner.Invalidate(rgn); ShowNew(); }
public ScreenRegionForm(Rectangle regionRectangle) { InitializeComponent(); Location = new Point(regionRectangle.X - 1, regionRectangle.Y - 1); Size = new Size(regionRectangle.Width + 2, regionRectangle.Height + 2); Rectangle rect = ClientRectangle; Region region = new Region(rect); rect.Inflate(-1, -1); region.Exclude(rect); Region = region; }
public ScreenRecordForm(Rectangle regionRectangle, bool activateWindow = true, float duration = 0) { InitializeComponent(); niTray.Icon = ShareXResources.Icon; this.activateWindow = activateWindow; this.duration = duration; borderRectangle = regionRectangle.Offset(1); borderRectangle0Based = new Rectangle(0, 0, borderRectangle.Width, borderRectangle.Height); Location = borderRectangle.Location; int windowWidth = Math.Max(borderRectangle.Width, pInfo.Width); Size = new Size(windowWidth, borderRectangle.Height + pInfo.Height + 1); pInfo.Location = new Point(0, borderRectangle.Height + 1); Region region = new Region(ClientRectangle); region.Exclude(borderRectangle0Based.Offset(-1)); region.Exclude(new Rectangle(0, borderRectangle.Height, windowWidth, 1)); if (borderRectangle.Width < pInfo.Width) { region.Exclude(new Rectangle(borderRectangle.Width, 0, pInfo.Width - borderRectangle.Width, borderRectangle.Height)); } else if (borderRectangle.Width > pInfo.Width) { region.Exclude(new Rectangle(pInfo.Width, borderRectangle.Height + 1, borderRectangle.Width - pInfo.Width, pInfo.Height)); } Region = region; Timer = new Stopwatch(); UpdateTimer(); RecordResetEvent = new ManualResetEvent(false); ChangeState(ScreenRecordState.Waiting); }
public void ApplyRegion() { var r = new Region(new Rectangle(0, 0, MaskImage.Width, MaskImage.Height)); for (int y = 0; y < MaskImage.Height; y++) { for (int x = 0; x < MaskImage.Width; x++) { if (MaskImage.GetPixel(x, y) == TransparencyKey) { r.Exclude(new Rectangle(x, y, 1, 1)); } } } Control.Region = r; Control.BackgroundImage = MaskImage; }
private void DrawFinalImage() { using (var g = Graphics.FromImage(FinalComposedImage)) { g.DrawImage(BackgroundImage, new Rectangle(0, 0, m_width, m_height)); g.DrawImage(ContentImage, new Rectangle(0, 0, m_width, m_height)); if (SelectedSubTexture != null) { Region rgn = new Region(new Rectangle(0, 0, m_width, m_height)); rgn.Exclude(new Rectangle(SelectedSubTexture.Left, SelectedSubTexture.Top, SelectedSubTexture.Width, SelectedSubTexture.Height)); g.FillRegion(m_maskBrush, rgn); } } }
private void doDraw(Graphics g) { Region baseR = new Region(new Rectangle(0, 0, this.pbParent.Width, this.pbParent.Height)); foreach (KeyValuePair<String, drawObject> item in drawObjects) { if (item.Key.Substring(0, 5) == "table") { baseR.Exclude(Rectangle.Round(item.Value.loc)); } } g.FillRegion(new SolidBrush(this.pbParent.BackColor), baseR); foreach (KeyValuePair<String, drawObject> item in drawObjects) { item.Value.draw(g); } }
/// <summary> /// Paints the non item region. /// </summary> private void PaintNonItemRegion() { using (Graphics g = Graphics.FromHwnd(Handle)) { using (Region r = new Region(ClientRectangle)) { for (int i = 0; i < Items.Count; i++) { Rectangle itemRect = GetItemRectangle(i); r.Exclude(itemRect); } g.FillRegion(SystemBrushes.Window, r); } } }
private void PaintNonItemRegion() { using (Graphics g = Graphics.FromHwnd(this.Handle)) using (Region r = new Region(this.ClientRectangle)) { for (int i = 0; i < this.Items.Count; i++) { Rectangle itemRect = this.GetItemRectangle(i); r.Exclude(itemRect); } using (var brush = new SolidBrush(this.BackColor)) { g.FillRegion(SystemBrushes.Window, r); } } }
/// <summary> /// Initialize a new instance of the Clipping class. /// </summary> /// <param name="graphics">Graphics context.</param> /// <param name="path">Path to clip.</param> /// <param name="exclude">Exclude path from clipping.</param> public Clipping(Graphics graphics, GraphicsPath path, bool exclude) { // Cache graphics instance _graphics = graphics; // Save the existing clipping region _previousRegion = _graphics.Clip; // Add clipping of path to existing clipping region _newRegion = _previousRegion.Clone(); if (exclude) _newRegion.Exclude(path); else _newRegion.Intersect(path); _graphics.Clip = _newRegion; }
protected override void OnPaint(PaintEventArgs e) { switch (cBAreo.CheckState) { case CheckState.Checked: e.Graphics.Clear(Color.Black); //将窗体整个背景绘制成黑色 break; case CheckState.Indeterminate: Rectangle rect = this.ClientRectangle; rect.Inflate(-20, -20); Region region = new Region(rect); rect.Inflate(-20, -20); region.Exclude(rect); //获取非Areo区域部分区域 e.Graphics.FillRegion(Brushes.Black, region); //窗体部分非Areo区域全透明 e.Graphics.FillRegion(Brushes.Black, regionAreo);//将窗体Areo边框绘制成黑色 break; } }
protected override void OnPaint(PaintEventArgs e) { if (Areo.IsAreoEnabled()) //检测系统是否开启Areo功能 { switch (cBAreo.CheckState) { case CheckState.Checked: e.Graphics.Clear(Color.Black); //将窗体整个背景绘制成黑色 break; case CheckState.Indeterminate: Region region = new Region(this.ClientRectangle); Rectangle rect = this.ClientRectangle; rect.Inflate(-50, -50); region.Exclude(rect); e.Graphics.FillRegion(Brushes.Black, region);//将窗体Areo边框绘制成黑色 break; } } }
public FormTest() { this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint, true); InitializeComponent(); FileManager.FileManager.Initialize(); deviceTreeList = FileManager.FileManager.GetDeviceList(); InitTreeView(deviceTreeList, this.tree); InitTreeView(deviceTreeList, this.treeView1); InitTreeView(deviceTreeList, this.treeViewAlarm); checkBox_analyze.Checked = false; checkBox_cruise.Checked = false; checkBox_record.Checked = false; Rectangle rect = video1.Bounds; rect.Inflate(-3,-3); Region maskRegion = new Region(video1.Bounds); maskRegion.Exclude(rect); lMask1.Region = maskRegion; label_video2.Region = maskRegion; }
public void set_inner_surfaces(surface_store i_inner_surface) { inner_surfaces.Add(i_inner_surface); // Set the path of inner surface List <PointF> temp_sur_pts = new List <PointF>(); foreach (edge2d ed in inner_surfaces[inner_surfaces.Count - 1].surface_edges) { temp_sur_pts.Add(ed.end_pt.get_point()); } System.Drawing.Drawing2D.GraphicsPath inner_surface = new System.Drawing.Drawing2D.GraphicsPath(); inner_surface.StartFigure(); inner_surface.AddPolygon(temp_sur_pts.ToArray()); inner_surface.CloseFigure(); // set region surface_region.Exclude(inner_surface); // exclude the inner surface region }
void DrawRegionOperation() { g = this.CreateGraphics(); Rectangle rect1 = new Rectangle(100, 100, 120, 120); Rectangle rect2 = new Rectangle(70, 70, 120, 120); Region rgn1 = new Region(rect1); Region rgn2 = new Region(rect2); g.DrawRectangle(Pens.Blue, rect1); g.DrawRectangle(Pens.Red, rect2); switch(rgnOperation) { case RegionOperation.Union: rgn1.Union(rgn2); break; case RegionOperation.Complement: rgn1.Complement(rgn2); break; case RegionOperation.Intersect: rgn1.Intersect(rgn2); break; case RegionOperation.Exclude: rgn1.Exclude(rgn2); break; case RegionOperation.Xor: rgn1.Xor(rgn2); break; default: break; } g.FillRegion(Brushes.Tomato, rgn1); g.Dispose(); }
private void DrawRegionOperations() { g = this.CreateGraphics(); // Создаем два прямоугольника Rectangle rect1 = new Rectangle(100, 100, 120, 120); Rectangle rect2 = new Rectangle(70, 70, 120, 120); // Создаем два региона Region rgn1 = new Region(rect1); Region rgn2 = new Region(rect2); // рисуем прямоугольники g.DrawRectangle(Pens.Green, rect1); g.DrawRectangle(Pens.Black, rect2); // обработаем перечисление и вызовем соответствующий метод switch (rgnOperation) { case RegionOperations.Union: rgn1.Union(rgn2); break; case RegionOperations.Complement: rgn1.Complement(rgn2); break; case RegionOperations.Intersect: rgn1.Intersect(rgn2); break; case RegionOperations.Exclude: rgn1.Exclude(rgn2); break; case RegionOperations.Xor: rgn1.Xor(rgn2); break; default: break; } // Рисуем регион g.FillRegion(Brushes.Blue, rgn1); g.Dispose(); }
// 绘制剪裁效果,即除剪裁区域外整个图片的其他部分都绘制一层阴影。 private void DrawCrop(Graphics g) { if ((this.Capture || ((_cropMode == false) || (_editMode == false)))) { return; } if (_cropHelper.Empty) { return; } // 获取剪裁区域 Rectangle area = _cropHelper.SelectedArea; // 绘制阴影区域 System.Drawing.Region region = new System.Drawing.Region(_photoBounds); region.Exclude(area); g.FillRegion(_brushDimCrop, region); region.Dispose(); // 绘制区域的边界 ControlPaint.DrawFocusRectangle(g, _cropHelper.SelectedArea, Color.White, Color.Black); }
private void ClearInsertionMark(ToolStripItem item) { if ((ToolStripDesigner.LastCursorPosition == Point.Empty) || (ToolStripDesigner.LastCursorPosition != Cursor.Position)) { ToolStripKeyboardHandlingService keyBoardHandlingService = this.GetKeyBoardHandlingService(item); if ((keyBoardHandlingService == null) || !keyBoardHandlingService.TemplateNodeActive) { Rectangle empty = Rectangle.Empty; if ((item != null) && (item.Site != null)) { IDesignerHost service = (IDesignerHost) item.Site.GetService(typeof(IDesignerHost)); if (service != null) { empty = GetPaintingBounds(service, item); empty.Inflate(1, 1); Region r = new Region(empty); try { empty.Inflate(-2, -2); r.Exclude(empty); BehaviorService behaviorService = this.GetBehaviorService(item); if ((behaviorService != null) && (empty != Rectangle.Empty)) { behaviorService.Invalidate(r); } } finally { r.Dispose(); r = null; } } } } } }
/// <summary> /// Draw a tint over everything in the ObjectListView except the /// row under the mouse. /// </summary> /// <param name="olv"></param> /// <param name="g"></param> /// <param name="r"></param> public override void Draw(ObjectListView olv, Graphics g, Rectangle r) { if (!r.Contains(olv.PointToClient(Cursor.Position))) return; Rectangle bounds = RowBounds; if (bounds.IsEmpty) { if (olv.View == View.Tile) g.FillRectangle(FillBrush, r); return; } using (var newClip = new Region(r)) { bounds.Inflate(BoundsPadding); newClip.Exclude(GetRoundedRect(bounds, CornerRounding)); Region originalClip = g.Clip; g.Clip = newClip; g.FillRectangle(FillBrush, r); g.Clip = originalClip; } }
/// <summary> /// Draw the decoration /// </summary> /// <param name="olv"></param> /// <param name="g"></param> /// <param name="r"></param> public override void Draw(ObjectListView olv, Graphics g, Rectangle r) { if (!olv.IsCellEditing) return; Rectangle bounds = olv.CellEditor.Bounds; if (bounds.IsEmpty) return; bounds.Inflate(BoundsPadding); GraphicsPath path = GetRoundedRect(bounds, CornerRounding); if (FillBrush != null) { if (UseLightbox) { using (var newClip = new Region(r)) { newClip.Exclude(path); Region originalClip = g.Clip; g.Clip = newClip; g.FillRectangle(FillBrush, r); g.Clip = originalClip; } } else { g.FillPath(FillBrush, path); } } if (BorderPen != null) g.DrawPath(BorderPen, path); }
/// <summary> /// Draws the colorslider control using passed colors. /// </summary> /// <param name = "e">The <see cref = "T:System.Windows.Forms.PaintEventArgs" /> instance containing the event data.</param> /// <param name = "thumbOuterColorPaint">The thumb outer color paint.</param> /// <param name = "thumbInnerColorPaint">The thumb inner color paint.</param> /// <param name = "thumbPenColorPaint">The thumb pen color paint.</param> /// <param name = "barOuterColorPaint">The bar outer color paint.</param> /// <param name = "barInnerColorPaint">The bar inner color paint.</param> /// <param name = "barPenColorPaint">The bar pen color paint.</param> /// <param name = "elapsedOuterColorPaint">The elapsed outer color paint.</param> /// <param name = "elapsedInnerColorPaint">The elapsed inner color paint.</param> private void DrawColorSlider(PaintEventArgs e, Color thumbOuterColorPaint, Color thumbInnerColorPaint, Color thumbPenColorPaint, Color barOuterColorPaint, Color barInnerColorPaint, Color barPenColorPaint, Color elapsedOuterColorPaint, Color elapsedInnerColorPaint) { try { //set up thumbRect aproprietly if (barOrientation == Orientation.Horizontal) { int TrackX = (((trackerValue - barMinimum) * (ClientRectangle.Width - thumbSize)) / (barMaximum - barMinimum)); thumbRect = new Rectangle(TrackX, 1, thumbSize - 1, ClientRectangle.Height - 3); } else { int TrackY = (((trackerValue - barMinimum) * (ClientRectangle.Height - thumbSize)) / (barMaximum - barMinimum)); thumbRect = new Rectangle(1, TrackY, ClientRectangle.Width - 3, thumbSize - 1); } //adjust drawing rects barRect = ClientRectangle; thumbHalfRect = thumbRect; LinearGradientMode gradientOrientation; if (barOrientation == Orientation.Horizontal) { barRect.Inflate(-1, -barRect.Height / 3); barHalfRect = barRect; barHalfRect.Height /= 2; gradientOrientation = LinearGradientMode.Vertical; thumbHalfRect.Height /= 2; elapsedRect = barRect; elapsedRect.Width = thumbRect.Left + thumbSize / 2; } else { barRect.Inflate(-barRect.Width / 3, -1); barHalfRect = barRect; barHalfRect.Width /= 2; gradientOrientation = LinearGradientMode.Horizontal; thumbHalfRect.Width /= 2; elapsedRect = barRect; elapsedRect.Height = thumbRect.Top + thumbSize / 2; } //get thumb shape path GraphicsPath thumbPath; if (thumbCustomShape == null) thumbPath = CreateRoundRectPath(thumbRect, thumbRoundRectSize); else { thumbPath = thumbCustomShape; Matrix m = new Matrix(); m.Translate(thumbRect.Left - thumbPath.GetBounds().Left, thumbRect.Top - thumbPath.GetBounds().Top); thumbPath.Transform(m); } //draw bar using ( LinearGradientBrush lgbBar = new LinearGradientBrush(barHalfRect, barOuterColorPaint, barInnerColorPaint, gradientOrientation) ) { lgbBar.WrapMode = WrapMode.TileFlipXY; e.Graphics.FillRectangle(lgbBar, barRect); //draw elapsed bar using ( LinearGradientBrush lgbElapsed = new LinearGradientBrush(barHalfRect, elapsedOuterColorPaint, elapsedInnerColorPaint, gradientOrientation)) { lgbElapsed.WrapMode = WrapMode.TileFlipXY; if (Capture && drawSemitransparentThumb) { Region elapsedReg = new Region(elapsedRect); elapsedReg.Exclude(thumbPath); e.Graphics.FillRegion(lgbElapsed, elapsedReg); } else e.Graphics.FillRectangle(lgbElapsed, elapsedRect); } //draw bar band using (Pen barPen = new Pen(barPenColorPaint, 0.5f)) { e.Graphics.DrawRectangle(barPen, barRect); } } //draw thumb Color newthumbOuterColorPaint = thumbOuterColorPaint, newthumbInnerColorPaint = thumbInnerColorPaint; if (Capture && drawSemitransparentThumb) { newthumbOuterColorPaint = Color.FromArgb(175, thumbOuterColorPaint); newthumbInnerColorPaint = Color.FromArgb(175, thumbInnerColorPaint); } using ( LinearGradientBrush lgbThumb = new LinearGradientBrush(thumbHalfRect, newthumbOuterColorPaint, newthumbInnerColorPaint, gradientOrientation)) { lgbThumb.WrapMode = WrapMode.TileFlipXY; e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; e.Graphics.FillPath(lgbThumb, thumbPath); //draw thumb band Color newThumbPenColor = thumbPenColorPaint; if (mouseEffects && (Capture || mouseInThumbRegion)) newThumbPenColor = ControlPaint.Dark(newThumbPenColor); using (Pen thumbPen = new Pen(newThumbPenColor)) { e.Graphics.DrawPath(thumbPen, thumbPath); } //gp.Dispose(); /*if (Capture || mouseInThumbRegion) using (LinearGradientBrush lgbThumb2 = new LinearGradientBrush(thumbHalfRect, Color.FromArgb(150, Color.Blue), Color.Transparent, gradientOrientation)) { lgbThumb2.WrapMode = WrapMode.TileFlipXY; e.Graphics.FillPath(lgbThumb2, gp); }*/ } //draw focusing rectangle if (Focused & drawFocusRectangle) using (Pen p = new Pen(Color.FromArgb(200, barPenColorPaint))) { p.DashStyle = DashStyle.Dot; Rectangle r = ClientRectangle; r.Width -= 2; r.Height--; r.X++; //ControlPaint.DrawFocusRectangle(e.Graphics, r); using (GraphicsPath gpBorder = CreateRoundRectPath(r, borderRoundRectSize)) { e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; e.Graphics.DrawPath(p, gpBorder); } } } catch (Exception Err) { Console.WriteLine("DrawBackGround Error in " + Name + ":" + Err.Message); } finally {} }
public override void OnLoseCapture(Glyph g, EventArgs e) { this.captureLost = true; if (this.pushedBehavior) { this.pushedBehavior = false; if (this.BehaviorService != null) { if (this.dragging) { this.dragging = false; for (int i = 0; !this.captureLost && (i < this.resizeComponents.Length); i++) { Control resizeControl = this.resizeComponents[i].resizeControl as Control; Rectangle rect = this.BehaviorService.ControlRectInAdornerWindow(resizeControl); if (!rect.IsEmpty) { using (Graphics graphics = this.BehaviorService.AdornerWindowGraphics) { graphics.SetClip(rect); using (Region region = new Region(rect)) { region.Exclude(Rectangle.Inflate(rect, -2, -2)); this.BehaviorService.Invalidate(region); } graphics.ResetClip(); } } } this.BehaviorService.EnableAllAdorners(true); } this.BehaviorService.PopBehavior(this); if (this.lastResizeRegion != null) { this.BehaviorService.Invalidate(this.lastResizeRegion); this.lastResizeRegion.Dispose(); this.lastResizeRegion = null; } } } if (this.resizeTransaction != null) { DesignerTransaction resizeTransaction = this.resizeTransaction; this.resizeTransaction = null; using (resizeTransaction) { resizeTransaction.Cancel(); } } }
public override bool OnMouseMove(Glyph g, MouseButtons button, Point mouseLoc) { if (!this.pushedBehavior) { return false; } bool flag = Control.ModifierKeys == Keys.Alt; if (flag && (this.dragManager != null)) { this.dragManager.EraseSnapLines(); } if (flag || !mouseLoc.Equals(this.lastMouseLoc)) { if (this.lastMouseAbs != null) { System.Design.NativeMethods.POINT pt = new System.Design.NativeMethods.POINT(mouseLoc.X, mouseLoc.Y); System.Design.UnsafeNativeMethods.ClientToScreen(new HandleRef(this, this.behaviorService.AdornerWindowControl.Handle), pt); if ((pt.x == this.lastMouseAbs.x) && (pt.y == this.lastMouseAbs.y)) { return true; } } if (!this.dragging) { if ((Math.Abs((int) (this.initialPoint.X - mouseLoc.X)) <= (DesignerUtils.MinDragSize.Width / 2)) && (Math.Abs((int) (this.initialPoint.Y - mouseLoc.Y)) <= (DesignerUtils.MinDragSize.Height / 2))) { return false; } this.InitiateResize(); this.dragging = true; } if ((this.resizeComponents == null) || (this.resizeComponents.Length == 0)) { return false; } PropertyDescriptor descriptor = null; PropertyDescriptor descriptor2 = null; PropertyDescriptor descriptor3 = null; PropertyDescriptor descriptor4 = null; if (this.initialResize) { descriptor = TypeDescriptor.GetProperties(this.resizeComponents[0].resizeControl)["Width"]; descriptor2 = TypeDescriptor.GetProperties(this.resizeComponents[0].resizeControl)["Height"]; descriptor3 = TypeDescriptor.GetProperties(this.resizeComponents[0].resizeControl)["Top"]; descriptor4 = TypeDescriptor.GetProperties(this.resizeComponents[0].resizeControl)["Left"]; if ((descriptor != null) && !typeof(int).IsAssignableFrom(descriptor.PropertyType)) { descriptor = null; } if ((descriptor2 != null) && !typeof(int).IsAssignableFrom(descriptor2.PropertyType)) { descriptor2 = null; } if ((descriptor3 != null) && !typeof(int).IsAssignableFrom(descriptor3.PropertyType)) { descriptor3 = null; } if ((descriptor4 != null) && !typeof(int).IsAssignableFrom(descriptor4.PropertyType)) { descriptor4 = null; } } Control resizeControl = this.resizeComponents[0].resizeControl as Control; this.lastMouseLoc = mouseLoc; this.lastMouseAbs = new System.Design.NativeMethods.POINT(mouseLoc.X, mouseLoc.Y); System.Design.UnsafeNativeMethods.ClientToScreen(new HandleRef(this, this.behaviorService.AdornerWindowControl.Handle), this.lastMouseAbs); int num = Math.Max(resizeControl.MinimumSize.Height, 10); int num2 = Math.Max(resizeControl.MinimumSize.Width, 10); if (this.dragManager != null) { bool flag2 = true; bool shouldSnapHorizontally = true; if ((((this.targetResizeRules & SelectionRules.BottomSizeable) != SelectionRules.None) || ((this.targetResizeRules & SelectionRules.TopSizeable) != SelectionRules.None)) && (resizeControl.Height == num)) { flag2 = false; } else if ((((this.targetResizeRules & SelectionRules.RightSizeable) != SelectionRules.None) || ((this.targetResizeRules & SelectionRules.LeftSizeable) != SelectionRules.None)) && (resizeControl.Width == num2)) { flag2 = false; } PropertyDescriptor descriptor5 = TypeDescriptor.GetProperties(resizeControl)["IntegralHeight"]; if (descriptor5 != null) { object obj2 = descriptor5.GetValue(resizeControl); if ((obj2 is bool) && ((bool) obj2)) { shouldSnapHorizontally = false; } } if (!flag && flag2) { this.lastSnapOffset = this.dragManager.OnMouseMove(resizeControl, this.GenerateSnapLines(this.targetResizeRules, mouseLoc), ref this.didSnap, shouldSnapHorizontally); } else { this.dragManager.OnMouseMove(new Rectangle(-100, -100, 0, 0)); } mouseLoc.X += this.lastSnapOffset.X; mouseLoc.Y += this.lastSnapOffset.Y; } Rectangle rectangle = new Rectangle(this.resizeComponents[0].resizeBounds.X, this.resizeComponents[0].resizeBounds.Y, this.resizeComponents[0].resizeBounds.Width, this.resizeComponents[0].resizeBounds.Height); if (this.didSnap && (resizeControl.Parent != null)) { rectangle.Location = this.behaviorService.MapAdornerWindowPoint(resizeControl.Parent.Handle, rectangle.Location); if (resizeControl.Parent.IsMirrored) { rectangle.Offset(-rectangle.Width, 0); } } Rectangle empty = Rectangle.Empty; Rectangle dragRect = Rectangle.Empty; bool flag4 = true; Color backColor = (resizeControl.Parent != null) ? resizeControl.Parent.BackColor : Color.Empty; for (int i = 0; i < this.resizeComponents.Length; i++) { Control c = this.resizeComponents[i].resizeControl as Control; Rectangle bounds = c.Bounds; Rectangle rc = bounds; Rectangle resizeBounds = this.resizeComponents[i].resizeBounds; Rectangle rect = this.BehaviorService.ControlRectInAdornerWindow(c); bool flag5 = true; System.Design.UnsafeNativeMethods.SendMessage(c.Handle, 11, false, 0); try { bool flag6 = false; if ((c.Parent != null) && c.Parent.IsMirrored) { flag6 = true; } BoundsSpecified none = BoundsSpecified.None; SelectionRules resizeRules = this.resizeComponents[i].resizeRules; if (((this.targetResizeRules & SelectionRules.BottomSizeable) != SelectionRules.None) && ((resizeRules & SelectionRules.BottomSizeable) != SelectionRules.None)) { int num4; if (this.didSnap) { num4 = mouseLoc.Y - rectangle.Bottom; } else { num4 = AdjustPixelsForIntegralHeight(c, mouseLoc.Y - this.initialPoint.Y); } bounds.Height = Math.Max(num, resizeBounds.Height + num4); none |= BoundsSpecified.Height; } if (((this.targetResizeRules & SelectionRules.TopSizeable) != SelectionRules.None) && ((resizeRules & SelectionRules.TopSizeable) != SelectionRules.None)) { int num5; if (this.didSnap) { num5 = rectangle.Y - mouseLoc.Y; } else { num5 = AdjustPixelsForIntegralHeight(c, this.initialPoint.Y - mouseLoc.Y); } none |= BoundsSpecified.Height; bounds.Height = Math.Max(num, resizeBounds.Height + num5); if ((bounds.Height != num) || ((bounds.Height == num) && (rc.Height != num))) { none |= BoundsSpecified.Y; bounds.Y = Math.Min((int) (resizeBounds.Bottom - num), (int) (resizeBounds.Y - num5)); } } if (((((this.targetResizeRules & SelectionRules.RightSizeable) != SelectionRules.None) && ((resizeRules & SelectionRules.RightSizeable) != SelectionRules.None)) && !flag6) || ((((this.targetResizeRules & SelectionRules.LeftSizeable) != SelectionRules.None) && ((resizeRules & SelectionRules.LeftSizeable) != SelectionRules.None)) && flag6)) { none |= BoundsSpecified.Width; int x = this.initialPoint.X; if (this.didSnap) { x = !flag6 ? rectangle.Right : rectangle.Left; } bounds.Width = Math.Max(num2, resizeBounds.Width + (!flag6 ? (mouseLoc.X - x) : (x - mouseLoc.X))); } if (((((this.targetResizeRules & SelectionRules.RightSizeable) != SelectionRules.None) && ((resizeRules & SelectionRules.RightSizeable) != SelectionRules.None)) && flag6) || ((((this.targetResizeRules & SelectionRules.LeftSizeable) != SelectionRules.None) && ((resizeRules & SelectionRules.LeftSizeable) != SelectionRules.None)) && !flag6)) { none |= BoundsSpecified.Width; int num7 = this.initialPoint.X; if (this.didSnap) { num7 = !flag6 ? rectangle.Left : rectangle.Right; } int num8 = !flag6 ? (num7 - mouseLoc.X) : (mouseLoc.X - num7); bounds.Width = Math.Max(num2, resizeBounds.Width + num8); if ((bounds.Width != num2) || ((bounds.Width == num2) && (rc.Width != num2))) { none |= BoundsSpecified.X; bounds.X = Math.Min((int) (resizeBounds.Right - num2), (int) (resizeBounds.X - num8)); } } if (!this.parentGridSize.IsEmpty) { bounds = this.AdjustToGrid(bounds, this.targetResizeRules); } if ((((none & BoundsSpecified.Width) == BoundsSpecified.Width) && this.dragging) && (this.initialResize && (descriptor != null))) { descriptor.SetValue(this.resizeComponents[i].resizeControl, bounds.Width); } if ((((none & BoundsSpecified.Height) == BoundsSpecified.Height) && this.dragging) && (this.initialResize && (descriptor2 != null))) { descriptor2.SetValue(this.resizeComponents[i].resizeControl, bounds.Height); } if ((((none & BoundsSpecified.X) == BoundsSpecified.X) && this.dragging) && (this.initialResize && (descriptor4 != null))) { descriptor4.SetValue(this.resizeComponents[i].resizeControl, bounds.X); } if ((((none & BoundsSpecified.Y) == BoundsSpecified.Y) && this.dragging) && (this.initialResize && (descriptor3 != null))) { descriptor3.SetValue(this.resizeComponents[i].resizeControl, bounds.Y); } if (this.dragging) { c.SetBounds(bounds.X, bounds.Y, bounds.Width, bounds.Height, none); empty = this.BehaviorService.ControlRectInAdornerWindow(c); if (c.Equals(resizeControl)) { dragRect = empty; } if (c.Bounds == rc) { flag5 = false; } if (c.Bounds != bounds) { flag4 = false; } } if ((c == this.primaryControl) && (this.statusCommandUI != null)) { this.statusCommandUI.SetStatusInformation(c); } } finally { System.Design.UnsafeNativeMethods.SendMessage(c.Handle, 11, true, 0); if (flag5) { Control parent = c.Parent; if (parent != null) { c.Invalidate(true); parent.Invalidate(rc, true); parent.Update(); } else { c.Refresh(); } } if (!empty.IsEmpty) { using (Region region = new Region(empty)) { region.Exclude(Rectangle.Inflate(empty, -2, -2)); if (flag5) { using (Region region2 = new Region(rect)) { region2.Exclude(Rectangle.Inflate(rect, -2, -2)); this.BehaviorService.Invalidate(region2); } } if (!this.captureLost) { using (Graphics graphics = this.BehaviorService.AdornerWindowGraphics) { if ((this.lastResizeRegion != null) && !this.lastResizeRegion.Equals(region, graphics)) { this.lastResizeRegion.Exclude(region); this.BehaviorService.Invalidate(this.lastResizeRegion); this.lastResizeRegion.Dispose(); this.lastResizeRegion = null; } DesignerUtils.DrawResizeBorder(graphics, region, backColor); } if (this.lastResizeRegion == null) { this.lastResizeRegion = region.Clone(); } } } } } } if ((flag4 && !flag) && (this.dragManager != null)) { this.dragManager.RenderSnapLinesInternal(dragRect); } this.initialResize = false; } return true; }
/// <summary> /// This method will use User32 code to capture the specified captureBounds from the screen /// </summary> /// <param name="captureBounds">Rectangle with the bounds to capture</param> /// <returns>Bitmap which is captured from the screen at the location specified by the captureBounds</returns> public static Bitmap CaptureRectangle(Rectangle captureBounds) { Bitmap returnBitmap = null; if (captureBounds.Height <= 0 || captureBounds.Width <= 0) { LOG.Warn("Nothing to capture, ignoring!"); return null; } LOG.Debug("CaptureRectangle Called!"); // .NET GDI+ Solution, according to some post this has a GDI+ leak... // See http://connect.microsoft.com/VisualStudio/feedback/details/344752/gdi-object-leak-when-calling-graphics-copyfromscreen // Bitmap capturedBitmap = new Bitmap(captureBounds.Width, captureBounds.Height); // using (Graphics graphics = Graphics.FromImage(capturedBitmap)) { // graphics.CopyFromScreen(captureBounds.Location, Point.Empty, captureBounds.Size, CopyPixelOperation.CaptureBlt); // } // capture.Image = capturedBitmap; // capture.Location = captureBounds.Location; using (SafeWindowDCHandle desktopDCHandle = SafeWindowDCHandle.fromDesktop()) { if (desktopDCHandle.IsInvalid) { // Get Exception before the error is lost Exception exceptionToThrow = CreateCaptureException("desktopDCHandle", captureBounds); // throw exception throw exceptionToThrow; } // create a device context we can copy to using (SafeCompatibleDCHandle safeCompatibleDCHandle = GDI32.CreateCompatibleDC(desktopDCHandle)) { // Check if the device context is there, if not throw an error with as much info as possible! if (safeCompatibleDCHandle.IsInvalid) { // Get Exception before the error is lost Exception exceptionToThrow = CreateCaptureException("CreateCompatibleDC", captureBounds); // throw exception throw exceptionToThrow; } // Create BITMAPINFOHEADER for CreateDIBSection BITMAPINFOHEADER bmi = new BITMAPINFOHEADER(captureBounds.Width, captureBounds.Height, 24); // Make sure the last error is set to 0 Win32.SetLastError(0); // create a bitmap we can copy it to, using GetDeviceCaps to get the width/height IntPtr bits0; // not used for our purposes. It returns a pointer to the raw bits that make up the bitmap. using (SafeDibSectionHandle safeDibSectionHandle = GDI32.CreateDIBSection(desktopDCHandle, ref bmi, BITMAPINFOHEADER.DIB_RGB_COLORS, out bits0, IntPtr.Zero, 0)) { if (safeDibSectionHandle.IsInvalid) { // Get Exception before the error is lost Exception exceptionToThrow = CreateCaptureException("CreateDIBSection", captureBounds); exceptionToThrow.Data.Add("hdcDest", safeCompatibleDCHandle.DangerousGetHandle().ToInt32()); exceptionToThrow.Data.Add("hdcSrc", desktopDCHandle.DangerousGetHandle().ToInt32()); // Throw so people can report the problem throw exceptionToThrow; } // select the bitmap object and store the old handle using (safeCompatibleDCHandle.SelectObject(safeDibSectionHandle)) { // bitblt over (make copy) GDI32.BitBlt(safeCompatibleDCHandle, 0, 0, captureBounds.Width, captureBounds.Height, desktopDCHandle, captureBounds.X, captureBounds.Y, CopyPixelOperation.SourceCopy | CopyPixelOperation.CaptureBlt); } // get a .NET image object for it // A suggestion for the "A generic error occurred in GDI+." E_FAIL/0×80004005 error is to re-try... bool success = false; ExternalException exception = null; for (int i = 0; i < 3; i++) { try { // Collect all screens inside this capture List<Screen> screensInsideCapture = new List<Screen>(); foreach (Screen screen in Screen.AllScreens) { if (screen.Bounds.IntersectsWith(captureBounds)) { screensInsideCapture.Add(screen); } } // Check all all screens are of an equal size bool offscreenContent; using (Region captureRegion = new Region(captureBounds)) { // Exclude every visible part foreach (Screen screen in screensInsideCapture) { captureRegion.Exclude(screen.Bounds); } // If the region is not empty, we have "offscreenContent" using (Graphics screenGraphics = Graphics.FromHwnd(User32.GetDesktopWindow())) { offscreenContent = !captureRegion.IsEmpty(screenGraphics); } } // Check if we need to have a transparent background, needed for offscreen content if (offscreenContent) { using (Bitmap tmpBitmap = Image.FromHbitmap(safeDibSectionHandle.DangerousGetHandle())) { // Create a new bitmap which has a transparent background returnBitmap = ImageHelper.CreateEmpty(tmpBitmap.Width, tmpBitmap.Height, PixelFormat.Format32bppArgb, Color.Transparent, tmpBitmap.HorizontalResolution, tmpBitmap.VerticalResolution); // Content will be copied here using (Graphics graphics = Graphics.FromImage(returnBitmap)) { // For all screens copy the content to the new bitmap foreach (Screen screen in Screen.AllScreens) { Rectangle screenBounds = screen.Bounds; // Make sure the bounds are offsetted to the capture bounds screenBounds.Offset(-captureBounds.X, -captureBounds.Y); graphics.DrawImage(tmpBitmap, screenBounds, screenBounds.X, screenBounds.Y, screenBounds.Width, screenBounds.Height, GraphicsUnit.Pixel); } } } } else { // All screens, which are inside the capture, are of equal size // assign image to Capture, the image will be disposed there.. returnBitmap = Image.FromHbitmap(safeDibSectionHandle.DangerousGetHandle()); } // We got through the capture without exception success = true; break; } catch (ExternalException ee) { LOG.Warn("Problem getting bitmap at try " + i + " : ", ee); exception = ee; } } if (!success) { LOG.Error("Still couldn't create Bitmap!"); if (exception != null) { throw exception; } } } } } return returnBitmap; }
private void SnippingTool_Paint(object sender, PaintEventArgs e) { using (Brush b = new SolidBrush(Color.FromArgb(120, Color.White))) using (Pen pen = new Pen(Color.Red, 1)) using (Region region = new Region(new Rectangle(0, 0, Width, Height))) { // Create a region // Negate it from the current sleection region.Exclude(rcSelect); region.Intersect(e.ClipRectangle); // Draw overlay of non-selected portions e.Graphics.FillRegion(b, region); // Draw selection e.Graphics.DrawRectangle(pen, rcSelect.X, rcSelect.Y, rcSelect.Width - 1, rcSelect.Height - 1); } }
/// <summary> /// Custom OnPaint event. /// Just override the default method to draw text and do our stuff. /// </summary> /// <param name="e">Arguments from Paint Event</param> protected override void OnPaint(PaintEventArgs e) { // Take area of progressbar var rect = ClientRectangle; // Create a bitmap to draw all elements of progress bar and, finally, paint in in main control using (var bmp = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppPArgb)) { // Take bitmap graphics to paint stuff using (var bg = System.Drawing.Graphics.FromImage(bmp)) { // set atialiasing bg.SmoothingMode = SmoothingMode.HighQuality; // AntiAlias bg.InterpolationMode = InterpolationMode.HighQualityBicubic; // High bg.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; bg.PixelOffsetMode = PixelOffsetMode.HighQuality; // Fill it with Background Color bg.FillRectangle(new SolidBrush(BackColor), rect); // If we have a value to show... if (Value > 0) { // Decrease rectangle to paint progress bar rect.Inflate(-2, -2); // Get progress bar area var clip = new Rectangle(rect.X, rect.Y, (int)Math.Round(((float)Value / Maximum) * rect.Width), rect.Height); // And paint it bg.FillRectangle(new SolidBrush(ForeColor), clip); } // Get text: given text + percent or simply % by default var txt = (text.Length == 0) ? string.Format("{0}%", Value) : string.Format("{0} ({1}%)", text, Value); var size = bg.MeasureString(txt, font); var pos = new PointF((Width - size.Width) / 2, (Height - size.Height) / 2); // Paint it inverted over the bar: Get the progress bar rect = ClientRectangle; rect.Inflate(-2, -2); // Progress bar width as percent of progress rect.Width = (int)Math.Round(((float)Value / Maximum) * rect.Width); // Create regions: region on the left is the progress bar region using (var leftRegion = new Region(rect)) { // And region in the right is the main bar, as exclusion of whole bar minus progress bar using (var rightRegion = new Region(ClientRectangle)) { rightRegion.Exclude(leftRegion); // Use progress bar (region on the left) as clip bg.Clip = leftRegion; // And draw text over it bg.DrawString(txt, font, new SolidBrush(BackColor), pos); // Now, the main bar part (region on the right): use it as clip bg.Clip = rightRegion; // And draw text in same way but inversed color bg.DrawString(txt, font, new SolidBrush(ForeColor), pos); // Finally, paint bar in main control :D e.Graphics.DrawImage(bmp, new Point(0,0)); } } } } }
/// <summary> /// Draws each element in group on graph object /// </summary> /// <param name="graphObj">Graph object to be drawn on</param> /// <param name="dx">X region</param> /// <param name="dy">Y region</param> /// <param name="zoom">Zoom value</param> public override void Draw(Graphics graphObj, int dx, int dy, float zoom) { GraphicsState oldGraphState = graphObj.Save(); //store previos trasformation Matrix matrix = graphObj.Transform; // get previous trasformation PointF point = new PointF(zoom * (region.X0 + dx + (region.X1 - region.X0) / 2), zoom * (region.Y0 + dy + (region.Y1 - region.Y0) / 2)); if (this.Rotation > 0) { matrix.RotateAt(this.Rotation, point, MatrixOrder.Append); //add a trasformation } //X MIRROR //Y MIRROR if (this.xMirror || this.yMirror) { matrix.Translate(-(region.X0 + region.Width / 2 + dx) * zoom, -(region.Y0 + region.Height / 2 + dy) * zoom, MatrixOrder.Append); if (this.xMirror) { matrix.Multiply(new Matrix(-1, 0, 0, 1, 0, 0), MatrixOrder.Append); } if (this.yMirror) { matrix.Multiply(new Matrix(1, 0, 0, -1, 0, 0), MatrixOrder.Append); } matrix.Translate((region.X0 + region.Width / 2 + dx) * zoom, (region.Y0 + region.Height / 2 + dy) * zoom, MatrixOrder.Append); } if (this.groupZoomX > 0 && this.groupZoomY > 0) { matrix.Translate((-1) * zoom * (region.X0 + dx + (region.X1 - region.X0) / 2), (-1) * zoom * (region.Y0 + dy + (region.Y1 - region.Y0) / 2), MatrixOrder.Append); matrix.Scale(this.groupZoomX, this.groupZoomY, MatrixOrder.Append); matrix.Translate(zoom * (region.X0 + dx + (region.X1 - region.X0) / 2), zoom * (region.Y0 + dy + (region.Y1 - region.Y0) / 2), MatrixOrder.Append); } graphObj.Transform = matrix; if (this.IsGraphPath) { Brush myBrush = GetBrush(dx, dy, zoom); Pen myPen = this.CreatePen(zoom); GraphicsPath graphPath = new GraphicsPath(); foreach (ShapeElement element in this.elementList) { element.AddToGraphPath(graphPath, dx, dy, zoom); } if (this.FillEnabled) { graphObj.FillPath(myBrush, graphPath); if (this.ShowBorder) { graphObj.DrawPath(myPen, graphPath); } } else { graphObj.DrawPath(myPen, graphPath); } if (myBrush != null) { myBrush.Dispose(); } myPen.Dispose(); } else { //MANAGE This.GroupDisplay System.Drawing.Region gregion = new System.Drawing.Region(); if (GroupDisplay != GroupDisplay.Default) { bool first = true; foreach (ShapeElement element in this.elementList) { GraphicsPath graphPath = new GraphicsPath(FillMode.Winding); element.AddToGraphPath(graphPath, dx, dy, zoom); if (first) { gregion.Intersect(graphPath); } else { switch (GroupDisplay) { case GroupDisplay.Intersect: gregion.Intersect(graphPath); break; case GroupDisplay.Xor: gregion.Xor(graphPath); break; case GroupDisplay.Exclude: gregion.Exclude(graphPath); break; default: break; } } first = false; } graphObj.SetClip(gregion, CombineMode.Intersect); } foreach (ShapeElement element in this.elementList) { element.Draw(graphObj, dx, dy, zoom); } if (GroupDisplay != GroupDisplay.Default) { graphObj.ResetClip(); } } graphObj.Restore(oldGraphState);//restore previos trasformation if (this.Selected) { Brush myBrush = GetBrush(dx, dy, zoom); Pen myPen = this.CreatePen(zoom); graphObj.DrawRectangle(myPen, Rectangle.Round(region.GetRectangleF(dx, dy, zoom))); if (myBrush != null) { myBrush.Dispose(); } myPen.Dispose(); } matrix.Dispose(); }
public void Outline(ref Region region, ref GraphicsPath path, Graphics g, Font f, string str, int x, int y, int xOffset, int yOffset, int cw, int lineHeight, int border, int index, int length) { if (region == null) { if (this.m_Region == null) { this.m_Region = new Region(); } this.m_Region.MakeInfinite(); region = this.m_Region; } if (path == null) { if (this.m_Path == null) { this.m_Path = new GraphicsPath(); } else { this.m_Path.Reset(); } path = this.m_Path; } Region[] regionArray = this.Measure(g, f, str, 0, y, xOffset, yOffset, cw, index, length); for (int i = 0; i < regionArray.Length; i++) { Rectangle rect = Rectangle.Ceiling(regionArray[i].GetBounds(g)); rect.X -= border; rect.Width += border * 2; rect.Y = y + 1; rect.Height = lineHeight; region.Exclude(rect); path.AddRectangle(rect); this.m_Brush.Color = ControlPaint.Dark(this.BackColor, -0.4f); g.FillRectangle(this.m_Brush, rect); this.m_Brush.Color = this.ForeColor; } }
private void PaintVisual(PaintEventArgs pevent) { Graphics g = pevent.Graphics; base.Paint(g); var taskbarLocation = this.MainForm.TaskbarLocation; bool horizontal = taskbarLocation == Native.ABEdge.Top || taskbarLocation == Native.ABEdge.Bottom; int spaceAfterX = horizontal ? ButtonConstants.SpaceAfter : 1; int spaceAfterY = horizontal ? 0 : ButtonConstants.SpaceAfter; if (!MainForm.IsHidden) { // paint background Region originalClip = g.Clip; using (Region r = new System.Drawing.Region(g.ClipBounds)) { // exclude corners since they should be rounded r.Exclude(new Rectangle(0, 0, 2, 2)); r.Exclude(new Rectangle(Width - spaceAfterX - 1, 0, 2, 2)); r.Exclude(new Rectangle(0, Height - 2, 2, 2)); r.Exclude(new Rectangle(Width - spaceAfterX - 1, Height - 2, 2, 2)); g.Clip = r; ProgressBarDecorator.Paint(g, _buttonBounds, _progress); if (_flashActive) { g.FillRectangle(new LinearGradientBrush(_buttonBounds, Theme.ButtonFlashBackgroundFrom, Theme.ButtonFlashBackgroundTo, 90f), _buttonBounds); } else if (Hover) { HotTrackDecorator.Paint(g, this.Tag as SecondDisplayProcess, this.Image as Bitmap, _buttonBounds, this.PointToClient(Cursor.Position)); } HighlightDecorator.Paint(g, _buttonBounds); if ((this.Focused || this._isClicked) && !_flashActive) { g.FillRectangle(Theme.ButtonBackgroundFocused, 2, 2, Width - spaceAfterX - 2, Height - spaceAfterY - 2); } } g.Clip = originalClip; } #region Border // draw border over background GraphicsPath path = RoundedRectangle.Create(new Rectangle(0, 0, Width - spaceAfterX, Height - spaceAfterY - 1), 2, RoundedRectangle.RectangleCorners.All); g.DrawPath(Theme.ButtonOuterBorder, path); path = RoundedRectangle.Create(new Rectangle(1, 1, Width - spaceAfterX - 2, Height - spaceAfterY - 3), 2, RoundedRectangle.RectangleCorners.All); g.DrawPath(Theme.ButtonInnerBorder, path); #endregion if (MainForm.IsHidden) { return; } DrawImageAndText(g, horizontal, spaceAfterX, spaceAfterY); }
protected override void OnPaint(PaintEventArgs e) { try { base.OnPaint(e); if (base.ClientRectangle.Width - 2 * (this.m_BorderExteriorLength + this.m_OuterBorderLength + this.m_MiddleBorderLength + this.m_InnerBorderLength) > 0 && base.ClientRectangle.Height - 2 * (this.m_BorderExteriorLength + this.m_OuterBorderLength + this.m_MiddleBorderLength + this.m_InnerBorderLength) > 0) { DrawGraphics _DrawGraphics = new DrawGraphics(); int left = base.ClientRectangle.Left; int top = base.ClientRectangle.Top; Rectangle clientRectangle = base.ClientRectangle; Rectangle rectangle = base.ClientRectangle; Rectangle width = new Rectangle(left, top, clientRectangle.Width - 1, rectangle.Height - 1); e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; e.Graphics.TextRenderingHint = TextRenderingHint.AntiAlias; SolidBrush solidBrush = new SolidBrush(base.Parent.BackColor); e.Graphics.FillRectangle(solidBrush, base.ClientRectangle); Pen pen = new Pen(solidBrush); e.Graphics.DrawRectangle(pen, base.ClientRectangle); pen.Dispose(); solidBrush.Dispose(); StringFormat stringFormat = new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }; if (this.m_TextVisible && this.Text != string.Empty || !this.m_IndicatorAutoSize) { int m_IndicatorWidth2 = this.m_IndicatorWidth; int m_IndicatorHeight2 = this.m_IndicatorHeight; if (m_IndicatorWidth2 > width.Width) { m_IndicatorWidth2 = width.Width; } if (m_IndicatorHeight2 > width.Height) { m_IndicatorHeight2 = width.Height; } width.Width = m_IndicatorWidth2; width.Height = m_IndicatorHeight2; if (this.m_TextPosition == DAS_TextPosStyle.TPS_Left) { int x_ClientRectangle = base.ClientRectangle.X; Rectangle clientRectangle1 = base.ClientRectangle; width.X = x_ClientRectangle + clientRectangle1.Width - 1 - m_IndicatorWidth2; int y_ClientRectangle = base.ClientRectangle.Y; Rectangle rectangle1 = base.ClientRectangle; width.Y = y_ClientRectangle + (rectangle1.Height - 1 - m_IndicatorHeight2) / 2; stringFormat.Alignment = StringAlignment.Near; } else if (this.m_TextPosition == DAS_TextPosStyle.TPS_Right) { width.X = base.ClientRectangle.X; int num = base.ClientRectangle.Y; Rectangle clientRectangle2 = base.ClientRectangle; width.Y = num + (clientRectangle2.Height - 1 - m_IndicatorHeight2) / 2; stringFormat.Alignment = StringAlignment.Far; } else if (this.m_TextPosition == DAS_TextPosStyle.TPS_Top) { int x1 = base.ClientRectangle.X; Rectangle rectangle2 = base.ClientRectangle; width.X = x1 + (rectangle2.Width - 1 - m_IndicatorWidth2) / 2; int y1 = base.ClientRectangle.Y; Rectangle clientRectangle3 = base.ClientRectangle; width.Y = y1 + (clientRectangle3.Height - 1 - m_IndicatorHeight2); stringFormat.LineAlignment = StringAlignment.Near; } else if (this.m_TextPosition != DAS_TextPosStyle.TPS_Bottom) { int num1 = base.ClientRectangle.X; Rectangle rectangle3 = base.ClientRectangle; width.X = num1 + (rectangle3.Width - 1 - m_IndicatorWidth2) / 2; int y2 = base.ClientRectangle.Y; Rectangle clientRectangle4 = base.ClientRectangle; width.Y = y2 + (clientRectangle4.Height - 1 - m_IndicatorHeight2) / 2; } else { int x2 = base.ClientRectangle.X; Rectangle rectangle4 = base.ClientRectangle; width.X = x2 + (rectangle4.Width - 1 - m_IndicatorWidth2) / 2; width.Y = base.ClientRectangle.Y; stringFormat.LineAlignment = StringAlignment.Far; } } Rectangle rectangle5 = new Rectangle(width.Left + this.m_BorderExteriorLength + this.m_OuterBorderLength + this.m_MiddleBorderLength + this.m_InnerBorderLength - 1, width.Top + this.m_BorderExteriorLength + this.m_OuterBorderLength + this.m_MiddleBorderLength + this.m_InnerBorderLength - 1, width.Width - 2 * (this.m_BorderExteriorLength + this.m_OuterBorderLength + this.m_MiddleBorderLength + this.m_InnerBorderLength - 1), width.Height - 2 * (this.m_BorderExteriorLength + this.m_OuterBorderLength + this.m_MiddleBorderLength + this.m_InnerBorderLength - 1)); GraphicsPath graphicsPath = null; if (this.m_Shape != DAS_ShapeStyle.SS_Rect && this.m_Shape != DAS_ShapeStyle.SS_RoundRect && this.m_Shape != DAS_ShapeStyle.SS_Circle) { graphicsPath = new GraphicsPath(); _DrawGraphics.method_6(graphicsPath, width, this.m_Shape, this.m_ArrowWidth + this.m_BorderExteriorLength + this.m_OuterBorderLength + this.m_MiddleBorderLength + this.m_InnerBorderLength, this.m_BorderExteriorLength + this.m_OuterBorderLength + this.m_MiddleBorderLength + this.m_InnerBorderLength); } if (!this.m_Value) { _DrawGraphics.SetValue(e.Graphics, rectangle5, this.m_Shape, graphicsPath, this.m_OffColor, this.m_OffGradientColor, this.m_GradientType, this.m_GradientAngle, this.m_GradientRate, this.m_RoundRadius - this.m_BorderExteriorLength - this.m_OuterBorderLength - this.m_MiddleBorderLength - this.m_InnerBorderLength, this.m_ArrowWidth, this.m_ShinePosition); } else { _DrawGraphics.SetValue(e.Graphics, rectangle5, this.m_Shape, graphicsPath, this.m_OnColor, this.m_OnGradientColor, this.m_GradientType, this.m_GradientAngle, this.m_GradientRate, this.m_RoundRadius - this.m_BorderExteriorLength - this.m_OuterBorderLength - this.m_MiddleBorderLength - this.m_InnerBorderLength, this.m_ArrowWidth, this.m_ShinePosition); } if (graphicsPath != null) { graphicsPath.Dispose(); } if (this.m_Shape == DAS_ShapeStyle.SS_Rect) { _DrawGraphics.SetRect(e.Graphics, width, this.m_OuterBorderLength, this.m_OuterBorderDarkColor, this.m_OuterBorderLightColor, this.m_MiddleBorderLength, this.m_MiddleBorderColor, this.m_InnerBorderLength, this.m_InnerBorderDarkColor, this.m_InnerBorderLightColor, this.m_BorderExteriorLength, this.m_BorderExteriorColor, this.m_BorderGradientType, this.m_BorderGradientAngle, this.m_BorderGradientRate, this.m_BorderGradientLightPos1, this.m_BorderGradientLightPos2, this.m_BorderLightIntermediateBrightness); } else if (this.m_Shape == DAS_ShapeStyle.SS_RoundRect) { System.Drawing.Region region = new System.Drawing.Region(base.ClientRectangle); GraphicsPath graphicsPath1 = new GraphicsPath(); _DrawGraphics.SetRoundRect(graphicsPath1, rectangle5, this.m_RoundRadius - this.m_BorderExteriorLength - this.m_OuterBorderLength - this.m_MiddleBorderLength - this.m_InnerBorderLength); region.Exclude(graphicsPath1); SolidBrush solidBrush1 = new SolidBrush(base.Parent.BackColor); e.Graphics.FillRegion(solidBrush1, region); solidBrush1.Dispose(); graphicsPath1.Dispose(); region.Dispose(); _DrawGraphics.SetRoundRect2(e.Graphics, width, this.m_RoundRadius, this.m_OuterBorderLength, this.m_OuterBorderDarkColor, this.m_OuterBorderLightColor, this.m_MiddleBorderLength, this.m_MiddleBorderColor, this.m_InnerBorderLength, this.m_InnerBorderDarkColor, this.m_InnerBorderLightColor, this.m_BorderExteriorLength, this.m_BorderExteriorColor, this.m_BorderGradientType, (long)this.m_BorderGradientAngle, this.m_BorderGradientRate, this.m_BorderGradientLightPos1, this.m_BorderGradientLightPos2, this.m_BorderLightIntermediateBrightness); } else if (this.m_Shape != DAS_ShapeStyle.SS_Circle) { _DrawGraphics.SetArrow(e.Graphics, width, this.m_Shape, this.m_RoundRadius, this.m_ArrowWidth, this.m_OuterBorderLength, this.m_OuterBorderDarkColor, this.m_OuterBorderLightColor, this.m_MiddleBorderLength, this.m_MiddleBorderColor, this.m_InnerBorderLength, this.m_InnerBorderDarkColor, this.m_InnerBorderLightColor, this.m_BorderExteriorLength, this.m_BorderExteriorColor, this.m_BorderGradientType, (long)this.m_BorderGradientAngle, this.m_BorderGradientRate, this.m_BorderGradientLightPos1, this.m_BorderGradientLightPos2, this.m_BorderLightIntermediateBrightness); } else { System.Drawing.Region region1 = new System.Drawing.Region(base.ClientRectangle); GraphicsPath graphicsPath2 = new GraphicsPath(); graphicsPath2.AddEllipse(rectangle5); region1.Exclude(graphicsPath2); SolidBrush solidBrush2 = new SolidBrush(base.Parent.BackColor); e.Graphics.FillRegion(solidBrush2, region1); solidBrush2.Dispose(); graphicsPath2.Dispose(); region1.Dispose(); _DrawGraphics.SetCircle(e.Graphics, width, this.m_OuterBorderLength, this.m_OuterBorderDarkColor, this.m_OuterBorderLightColor, this.m_MiddleBorderLength, this.m_MiddleBorderColor, this.m_InnerBorderLength, this.m_InnerBorderDarkColor, this.m_InnerBorderLightColor, this.m_BorderExteriorLength, this.m_BorderExteriorColor, this.m_BorderGradientType, (long)this.m_BorderGradientAngle, this.m_BorderGradientRate, this.m_BorderGradientLightPos1, this.m_BorderGradientLightPos2, this.m_BorderLightIntermediateBrightness); } if (this.m_TextVisible && this.Text != string.Empty) { SolidBrush solidBrush3 = new SolidBrush(this.ForeColor); e.Graphics.DrawString(this.Text, this.Font, solidBrush3, base.ClientRectangle, stringFormat); solidBrush3.Dispose(); } } } catch (ApplicationException applicationException) { MessageBox.Show(applicationException.ToString()); } }
private void SetRegion(Rectangle[] clipRects) { if (!IsClipRectsChanged(clipRects)) return; m_clipRects = clipRects; if (m_clipRects == null || m_clipRects.GetLength(0) == 0) Region = null; else { Region region = new Region(new Rectangle(0, 0, this.Width, this.Height)); foreach (Rectangle rect in m_clipRects) region.Exclude(rect); if (Region != null) { Region.Dispose(); } Region = region; } }
private void CalcWalkableArea() { if (_battle == null) { return; } int width = _battle.Width / 8; int height = _battle.Height / 8; Image image = new Bitmap(width, height); Graphics graphics = Graphics.FromImage(image); graphics.FillRectangle(new SolidBrush(Color.Black), new Rectangle(0, 0, width, height)); BTBLib.Region battleBoundary = null; List <BTBLib.Region> boundaries = new List <BTBLib.Region>(); List <BTBLib.Region> inverseBoundaries = new List <BTBLib.Region>(); foreach (BTBLib.Region region in _battle.Regions) { if (region.IsClosed) { if (region.IsBattleBoundary) { battleBoundary = region; } else if (region.IsBoundaryInversed) { inverseBoundaries.Add(region); } else if (region.IsBoundary) { boundaries.Add(region); } } } if (battleBoundary == null) { return; } boundaries.Insert(0, battleBoundary); System.Drawing.Region graphicsRegion = new System.Drawing.Region(new Rectangle(0, 0, width, height)); foreach (BTBLib.Region region in boundaries) { Point[] points = new Point[region.Lines.Count]; for (int i = 0; i < points.Length; ++i) { var segment = region.Lines[i]; points[i] = new Point(segment.StartX / 8, height - segment.StartY / 8); } GraphicsPath graphicsPath = new GraphicsPath(); graphicsPath.AddPolygon(points); graphicsRegion.Intersect(graphicsPath); } foreach (BTBLib.Region region in inverseBoundaries) { Point[] points = new Point[region.Lines.Count]; for (int i = 0; i < points.Length; ++i) { var segment = region.Lines[i]; points[i] = new Point(segment.StartX / 8, height - segment.StartY / 8); } GraphicsPath graphicsPath = new GraphicsPath(); graphicsPath.AddPolygon(points); graphicsRegion.Exclude(graphicsPath); } graphics.FillRegion(new SolidBrush(Color.Red), graphicsRegion); //Form form = new Form(); //form.ClientSize = new Size(width * 3, height * 3); //PictureBox pictureBox = new PictureBox(); //pictureBox.Image = image; //pictureBox.SizeMode = PictureBoxSizeMode.Zoom; //form.Controls.Add(pictureBox); //pictureBox.Dock = DockStyle.Fill; //form.Show(); ImageForm form = new ImageForm(); form.SetImage(image); form.ShowDialog(); }