📄 recttracker.cs
字号:
if (this.dlgtDrawBlendedBufferImage != null)
{
this.dlgtDrawBlendedBufferImage(rect, graphics2);
}
Point point2 = new Point(0, 0);
point2.X = (handleOffsetX + bufferRect.X) - rect.X;
point2.Y = (handleOffsetY + bufferRect.Y) - rect.Y;
if (this.dlgtDrawOriginalBufferImage != null)
{
Rectangle rectangle4 = new Rectangle();
rectangle4 = this.TrueRect;
CaptureHelper.NormalizeRect(ref rectangle4);
this.dlgtDrawOriginalBufferImage(rectangle4, point2, graphics2);
}
this.DirectPaintTracker(point2, graphics2);
if (this.dlgtDrawImageToForm != null)
{
this.dlgtDrawImageToForm(rect, this.bufferImage);
}
return;
}
}
if (rect.IntersectsWith(bufferRect))
{
Rectangle rectangle5 = new Rectangle();
rectangle5 = Rectangle.Union(bufferRect, rect);
this.bufferImage = new Bitmap(rectangle5.Width, rectangle5.Height);
using (Graphics graphics3 = Graphics.FromImage(this.bufferImage))
{
if (this.dlgtDrawBlendedBufferImage != null)
{
this.dlgtDrawBlendedBufferImage(rectangle5, graphics3);
}
Point point3 = new Point(0, 0);
point3.X = (handleOffsetX + bufferRect.X) - rectangle5.X;
point3.Y = (handleOffsetY + bufferRect.Y) - rectangle5.Y;
if (this.dlgtDrawOriginalBufferImage != null)
{
Rectangle rectangle6 = new Rectangle();
rectangle6 = this.TrueRect;
CaptureHelper.NormalizeRect(ref rectangle6);
this.dlgtDrawOriginalBufferImage(rectangle6, point3, graphics3);
}
this.DirectPaintTracker(point3, graphics3);
if (this.dlgtDrawImageToForm != null)
{
this.dlgtDrawImageToForm(rectangle5, this.bufferImage);
}
return;
}
}
this.bufferImage = new Bitmap(rect.Width, rect.Height);
using (Graphics graphics4 = Graphics.FromImage(this.bufferImage))
{
if (this.dlgtDrawBlendedBufferImage != null)
{
this.dlgtDrawBlendedBufferImage(rect, graphics4);
}
if (this.dlgtDrawImageToForm != null)
{
this.dlgtDrawImageToForm(rect, this.bufferImage);
}
return;
}
}
if (e.Button == MouseButtons.None)
{
TrackerHit hitCode = this.HitTest(new Point(e.X, e.Y));
this.SetCursor(hitCode);
if (this.selectStatus == Imps.Client.Pc.Controls.SelectStatus.Empty)
{
this.ShowTip(this.EmptySelectionTipText, e.X, e.Y);
}
else if (Imps.Client.Pc.Controls.SelectStatus.Selected == this.selectStatus)
{
this.ShowTip(this.SelectionTipText, e.X, e.Y);
}
}
}
protected virtual void OnMouseUp(MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (Imps.Client.Pc.Controls.SelectStatus.Selecting == this.selectStatus)
{
this.selectStatus = Imps.Client.Pc.Controls.SelectStatus.Selected;
}
if (!this.SelectionIsEmpty())
{
CaptureHelper.NormalizeRect(ref this.x, ref this.y, ref this.width, ref this.height);
this.RefreshHandleRects(this.TrueRect);
}
else
{
this.InitilizeTracker();
}
}
}
protected virtual void OnPaint(PaintEventArgs e)
{
if (!this.SelectionIsEmpty())
{
Graphics g = e.Graphics;
Rectangle rect = this.TrueRect;
CaptureHelper.NormalizeRect(ref rect);
if (this.dlgtDrawOriginalImage != null)
{
this.dlgtDrawOriginalImage(rect, g);
}
g.DrawRectangle(this.TrackerPen, rect);
this.RefreshHandleRects(this.TrueRect);
g.DrawRectangles(this.handlePen, this.handleRects);
if (this.bFillHandle)
{
g.FillRectangles(this.FilledHandleBrush, this.handleRects);
}
}
}
protected virtual void OnPaintBackground(PaintEventArgs e)
{
}
public void RefreshHandleRects(Rectangle hostRect)
{
if (Rectangle.Empty != hostRect)
{
this.handleRects[0] = new Rectangle(new Point(hostRect.Left - handleOffsetX, hostRect.Top - handleOffsetY), handleSize);
this.handleRects[1] = new Rectangle(new Point(hostRect.Right - handleOffsetX, hostRect.Top - handleOffsetY), handleSize);
this.handleRects[2] = new Rectangle(new Point(hostRect.Right - handleOffsetX, hostRect.Bottom - handleOffsetY), handleSize);
this.handleRects[3] = new Rectangle(new Point(hostRect.Left - handleOffsetX, hostRect.Bottom - handleOffsetY), handleSize);
this.handleRects[4] = new Rectangle(new Point((hostRect.Left + (hostRect.Width / 2)) - handleOffsetX, hostRect.Top - handleOffsetY), handleSize);
this.handleRects[5] = new Rectangle(new Point(hostRect.Right - handleOffsetX, (hostRect.Top + (hostRect.Height / 2)) - handleOffsetY), handleSize);
this.handleRects[6] = new Rectangle(new Point((hostRect.Left + (hostRect.Width / 2)) - handleOffsetX, hostRect.Bottom - handleOffsetY), handleSize);
this.handleRects[7] = new Rectangle(new Point(hostRect.Left - handleOffsetX, (hostRect.Top + (hostRect.Height / 2)) - handleOffsetY), handleSize);
}
else
{
this.handleRects[0] = Rectangle.Empty;
this.handleRects[1] = Rectangle.Empty;
this.handleRects[2] = Rectangle.Empty;
this.handleRects[3] = Rectangle.Empty;
this.handleRects[4] = Rectangle.Empty;
this.handleRects[5] = Rectangle.Empty;
this.handleRects[6] = Rectangle.Empty;
this.handleRects[7] = Rectangle.Empty;
}
}
public bool SelectionIsEmpty()
{
return ((Math.Abs(this.width) * Math.Abs(this.height)) <= 1);
}
public void SetBounds(int x, int y, int width, int height)
{
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
public void SetCursor(TrackerHit hitCode)
{
switch (hitCode)
{
case TrackerHit.hitNothing:
this.owner.Cursor = Cursors.Cross;
return;
case TrackerHit.hitTopLeft:
this.owner.Cursor = Cursors.SizeNWSE;
return;
case TrackerHit.hitTopRight:
this.owner.Cursor = Cursors.SizeNESW;
return;
case TrackerHit.hitBottomRight:
this.owner.Cursor = Cursors.SizeNWSE;
return;
case TrackerHit.hitBottomLeft:
this.owner.Cursor = Cursors.SizeNESW;
return;
case TrackerHit.hitTop:
this.owner.Cursor = Cursors.SizeNS;
return;
case TrackerHit.hitRight:
this.owner.Cursor = Cursors.SizeWE;
return;
case TrackerHit.hitBottom:
this.owner.Cursor = Cursors.SizeNS;
return;
case TrackerHit.hitLeft:
this.owner.Cursor = Cursors.SizeWE;
return;
case TrackerHit.hitMiddle:
this.owner.Cursor = Cursors.SizeAll;
return;
}
this.owner.Cursor = Cursors.Arrow;
}
private void ShowTip(string _tipText, int originX, int originY)
{
int num = 15;
int num2 = 15;
int x = originX + num;
int y = originY + num2;
this.trackerTip.Text = _tipText;
this.tipSize = this.trackerTip.Size;
if ((x + this.tipSize.Width) > Screen.PrimaryScreen.WorkingArea.Width)
{
x = (Screen.PrimaryScreen.WorkingArea.Width - this.tipSize.Width) - 2;
}
if ((y + this.tipSize.Height) > Screen.PrimaryScreen.WorkingArea.Height)
{
y = (Screen.PrimaryScreen.WorkingArea.Height - this.tipSize.Height) - 2;
}
if (((originX > ((Screen.PrimaryScreen.WorkingArea.Width - this.tipSize.Width) - 3)) && (originX < Screen.PrimaryScreen.WorkingArea.Width)) && ((originY > ((Screen.PrimaryScreen.WorkingArea.Height - this.tipSize.Height) - 3)) && (originY < Screen.PrimaryScreen.WorkingArea.Height)))
{
x = (originX - this.tipSize.Width) - num;
y = (originY - this.tipSize.Height) - num2;
}
this.trackerTip.Location = new Point(x, y);
this.trackerTip.Show();
}
public Brush FilledHandleBrush
{
get
{
return this.filledHandleBrush;
}
set
{
this.filledHandleBrush = value;
}
}
public Pen HandlePen
{
get
{
return this.handlePen;
}
set
{
this.handlePen = value;
}
}
public Rectangle InvalidatedRect
{
get
{
Rectangle rect = this.TrueRect;
CaptureHelper.NormalizeRect(ref rect);
rect = Rectangle.Inflate(rect, handleOffsetX, handleOffsetY);
rect.Width++;
rect.Height++;
return rect;
}
}
public Imps.Client.Pc.Controls.SelectStatus SelectStatus
{
get
{
return this.selectStatus;
}
}
public Pen TrackerPen
{
get
{
return this.trackerPen;
}
set
{
this.trackerPen = value;
}
}
public Rectangle TrueRect
{
get
{
return new Rectangle(this.x, this.y, this.width, this.height);
}
set
{
this.SetBounds(value.X, value.Y, value.Width, value.Height);
}
}
public delegate void DlgtDrawBlendedBufferImage(Rectangle bufferRect, Graphics g);
public delegate void DlgtDrawImageToForm(Rectangle originalRect, Image img);
public delegate void DlgtDrawOriginalBufferImage(Rectangle bufferRect, Point offsetPoint, Graphics g);
public delegate void DlgtDrawOriginalImage(Rectangle originalRect, Graphics g);
public enum TrackerHit
{
hitBottom = 6,
hitBottomLeft = 3,
hitBottomRight = 2,
hitLeft = 7,
hitMiddle = 8,
hitNothing = -1,
hitRight = 5,
hitTop = 4,
hitTopLeft = 0,
hitTopRight = 1
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -