123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- namespace PaintDotNet.Measurement
- {
- public abstract class CanvasControl : SurfaceBoxGraphicsRenderer
- {
- private PointF location;
- private SizeF size;
- private Cursor cursor;
- public event EventHandler CursorChanged;
- protected virtual void OnCursorChanged()
- {
- if (CursorChanged != null)
- {
- CursorChanged(this, EventArgs.Empty);
- }
- }
- public Cursor Cursor
- {
- get
- {
- return this.cursor;
- }
- set
- {
- if (this.cursor != value)
- {
- this.cursor = value;
- OnCursorChanged();
- }
- }
- }
- public event EventHandler LocationChanging;
- protected virtual void OnLocationChanging()
- {
- if (LocationChanging != null)
- {
- LocationChanging(this, EventArgs.Empty);
- }
- }
- public event EventHandler LocationChanged;
- protected virtual void OnLocationChanged()
- {
- if (LocationChanged != null)
- {
- LocationChanged(this, EventArgs.Empty);
- }
- }
- public PointF Location
- {
- get
- {
- return this.location;
- }
- set
- {
- if (this.location != value)
- {
- OnLocationChanging();
- this.location = value;
- OnLocationChanged();
- }
- }
- }
- public event EventHandler SizeChanging;
- protected virtual void OnSizeChanging()
- {
- if (SizeChanging != null)
- {
- SizeChanging(this, EventArgs.Empty);
- }
- }
- public event EventHandler SizeChanged;
- protected virtual void OnSizeChanged()
- {
- if (SizeChanged != null)
- {
- SizeChanged(this, EventArgs.Empty);
- }
- }
- public SizeF Size
- {
- get
- {
- return this.size;
- }
- set
- {
- if (this.size != value)
- {
- OnSizeChanging();
- this.size = value;
- OnSizeChanged();
- }
- }
- }
- public float Width
- {
- get
- {
- return Size.Width;
- }
- set
- {
- Size = new SizeF(value, Size.Height);
- }
- }
- public float Height
- {
- get
- {
- return Size.Height;
- }
- set
- {
- Size = new SizeF(Size.Width, value);
- }
- }
- public RectangleF Bounds
- {
- get
- {
- return new RectangleF(this.location, this.size);
- }
- set
- {
- Location = value.Location;
- Size = value.Size;
- }
- }
- public PointF CanvasPointToControlPoint(PointF canvasPtF)
- {
- return new PointF(canvasPtF.X - this.location.X, canvasPtF.Y - this.location.Y);
- }
- public PointF ControlPointToCanvasPoint(PointF controlPtF)
- {
- return new PointF(controlPtF.X + this.location.X, controlPtF.Y + this.location.Y);
- }
- public RectangleF CanvasRectToControlRect(RectangleF canvasRectF)
- {
- return new RectangleF(CanvasPointToControlPoint(canvasRectF.Location), canvasRectF.Size);
- }
- public RectangleF ControlRectToCanvasRect(RectangleF controlRectF)
- {
- return new RectangleF(ControlPointToCanvasPoint(controlRectF.Location), controlRectF.Size);
- }
- public void PerformMouseEnter()
- {
- MouseEnter();
- }
- private void MouseEnter()
- {
- OnMouseEnter();
- }
- protected virtual void OnMouseEnter()
- {
- }
- public void PerformMouseDown(MouseEventArgs e)
- {
- MouseDown(e);
- }
- private void MouseDown(MouseEventArgs e)
- {
- MouseDown(e);
- }
- protected virtual void OnMouseDown(MouseEventArgs e)
- {
- }
- public void PerformMouseUp(MouseEventArgs e)
- {
- MouseUp(e);
- }
- private void MouseUp(MouseEventArgs e)
- {
- OnMouseUp(e);
- }
- protected virtual void OnMouseUp(MouseEventArgs e)
- {
- }
- public void PerformMouseLeave()
- {
- MouseLeave();
- }
- private void MouseLeave()
- {
- OnMouseLeave();
- }
- protected virtual void OnMouseLeave()
- {
- }
- public void PerformPulse()
- {
- Pulse();
- }
- private void Pulse()
- {
- OnPulse();
- }
- protected virtual void OnPulse()
- {
- }
- public override sealed void RenderToGraphics(Graphics g, Point offset)
- {
- OnRender(g, offset);
- }
- protected virtual void OnRender(Graphics g, Point offset)
- {
- }
- protected CanvasControl(SurfaceBoxRendererList ownerList)
- : base(ownerList)
- {
- }
- }
- }
|