123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- using PaintDotNet.SystemLayer;
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- namespace PaintDotNet
- {
- public class PanelEx : SystemLayer.ScrollPanel
- {
- private ScaleFactor scaleFactor;
- private bool hideHScroll = false;
- private bool hideVScroll = false;
- private bool response = false;
- public Rectangle[] realUpdateRects = null;
- public PanelEx()
- {
- SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true);
- }
- public bool Response
- {
- set
- {
- this.response = value;
- }
- }
- public bool HideVScroll
- {
- get
- {
- return this.hideVScroll;
- }
- set
- {
- this.hideVScroll = value;
- }
- }
- public bool HideHScroll
- {
- get
- {
- return this.hideHScroll;
- }
- set
- {
- this.hideHScroll = value;
- }
- }
- protected override void OnSizeChanged(EventArgs e)
- {
- if (this.hideHScroll || this.HideVScroll)
- {
- SystemLayer.UI.SuspendControlPainting(this);
- }
- base.OnSizeChanged(e);
- if (this.hideHScroll || this.HideVScroll)
- {
- if (this.hideHScroll && this.HideVScroll)
- {
- SystemLayer.UI.HideAllScrollBar(this);
- }
- else
- {
- if (this.hideHScroll)
- SystemLayer.UI.HideHorizontalScrollBar(this);
- if (this.HideVScroll)
- SystemLayer.UI.HideVerticalScrollBar(this);
- }
- SystemLayer.UI.ResumeControlPainting(this);
- Invalidate(true);
- }
- }
- protected override void WndProc(ref Message m)
- {
- IntPtr preR = m.Result;
- // Ignore focus
- if (m.Msg == 7 /* WM_SETFOCUS */)
- {
- return;
- }
- else if (m.Msg == 0x000f /* WM_PAINT */)
- {
- this.realUpdateRects = UI.GetUpdateRegion(this);
- if (this.realUpdateRects != null &&
- this.realUpdateRects.Length >= 5) // '5' chosen arbitrarily
- {
- this.realUpdateRects = null;
- }
- base.WndProc(ref m);
- }
- else
- {
- base.WndProc(ref m);
- }
- }
- protected override void OnMouseWheel(MouseEventArgs e)
- {
- if (response)
- {
- response = false;
- base.OnMouseWheel(e);
- }
- }
- public ScaleFactor ScaleFactor
- {
- get
- {
- return this.scaleFactor;
- }
- set
- {
- this.scaleFactor = value;
- }
- }
- /// <summary>
- /// Converts from control client coordinates to surface coordinates
- /// This is useful when this.Bounds != surface.Bounds (i.e. some sort of zooming is in effect)
- /// </summary>
- /// <param name="clientPt"></param>
- /// <returns></returns>
- public PointF ClientToSurface(PointF clientPt)
- {
- return ScaleFactor.UnscalePoint(clientPt);
- }
- public Point ClientToSurface(Point clientPt)
- {
- return ScaleFactor.UnscalePoint(clientPt);
- }
- public SizeF ClientToSurface(SizeF clientSize)
- {
- return ScaleFactor.UnscaleSize(clientSize);
- }
- public Size ClientToSurface(Size clientSize)
- {
- return Size.Round(ClientToSurface((SizeF)clientSize));
- }
- public RectangleF ClientToSurface(RectangleF clientRect)
- {
- return new RectangleF(ClientToSurface(clientRect.Location), ClientToSurface(clientRect.Size));
- }
- public Rectangle ClientToSurface(Rectangle clientRect)
- {
- return new Rectangle(ClientToSurface(clientRect.Location), ClientToSurface(clientRect.Size));
- }
- public PointF SurfaceToClient(PointF surfacePt)
- {
- return ScaleFactor.ScalePoint(surfacePt);
- }
- public Point SurfaceToClient(Point surfacePt)
- {
- return ScaleFactor.ScalePoint(surfacePt);
- }
- public SizeF SurfaceToClient(SizeF surfaceSize)
- {
- return ScaleFactor.ScaleSize(surfaceSize);
- }
- public Size SurfaceToClient(Size surfaceSize)
- {
- return Size.Round(SurfaceToClient((SizeF)surfaceSize));
- }
- public RectangleF SurfaceToClient(RectangleF surfaceRect)
- {
- return new RectangleF(SurfaceToClient(surfaceRect.Location), SurfaceToClient(surfaceRect.Size));
- }
- public Rectangle SurfaceToClient(Rectangle surfaceRect)
- {
- return new Rectangle(SurfaceToClient(surfaceRect.Location), SurfaceToClient(surfaceRect.Size));
- }
- }
- }
|