Small fixes for the Zoom and its performance improvements

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2285 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-11-14 09:34:33 +00:00
commit 9ca5f0d3bd
3 changed files with 43 additions and 6 deletions

View file

@ -59,7 +59,6 @@ namespace Greenshot.Forms {
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
this.ClientSize = new System.Drawing.Size(0, 0); this.ClientSize = new System.Drawing.Size(0, 0);
this.Cursor = System.Windows.Forms.Cursors.Cross; this.Cursor = System.Windows.Forms.Cursors.Cross;
this.DoubleBuffered = true;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "CaptureForm"; this.Name = "CaptureForm";
this.ShowIcon = false; this.ShowIcon = false;

View file

@ -81,6 +81,17 @@ namespace Greenshot.Forms {
} }
} }
/// <summary>
/// This should prevent childs to draw backgrounds
/// </summary>
protected override CreateParams CreateParams {
get {
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000;
return cp;
}
}
public CaptureForm(ICapture capture, List<WindowDetails> windows) { public CaptureForm(ICapture capture, List<WindowDetails> windows) {
if (currentForm != null) { if (currentForm != null) {
LOG.Debug("Found currentForm, Closing already opened CaptureForm"); LOG.Debug("Found currentForm, Closing already opened CaptureForm");
@ -105,6 +116,8 @@ namespace Greenshot.Forms {
// The InitializeComponent() call is required for Windows Forms designer support. // The InitializeComponent() call is required for Windows Forms designer support.
// //
InitializeComponent(); InitializeComponent();
// Only double-buffer when we are not in a TerminalServerSession
this.DoubleBuffered = !System.Windows.Forms.SystemInformation.TerminalServerSession;
this.Text = "Greenshot capture form"; this.Text = "Greenshot capture form";
// Make sure we never capture the captureform // Make sure we never capture the captureform
@ -368,6 +381,13 @@ namespace Greenshot.Forms {
} }
} }
/// <summary>
/// This makes sure there is no background painted, as we have complete "paint" control it doesn't make sense to do otherwise.
/// </summary>
/// <param name="pevent"></param>
protected override void OnPaintBackground(PaintEventArgs pevent) {
}
void OnPaint(object sender, PaintEventArgs e) { void OnPaint(object sender, PaintEventArgs e) {
Graphics graphics = e.Graphics; Graphics graphics = e.Graphics;
Rectangle clipRectangle = e.ClipRectangle; Rectangle clipRectangle = e.ClipRectangle;

View file

@ -45,6 +45,17 @@ namespace Greenshot.Forms {
Zoom = 400; Zoom = 400;
} }
/// <summary>
/// Prevent the clipping of the child (this Form is a child of another)
/// </summary>
protected override CreateParams CreateParams {
get {
var parms = base.CreateParams;
parms.Style &= ~0x02000000; // Turn off WS_CLIPCHILDREN
return parms;
}
}
public Point MouseLocation { public Point MouseLocation {
get { get {
return mouseLocation; return mouseLocation;
@ -74,6 +85,12 @@ namespace Greenshot.Forms {
get; get;
set; set;
} }
/// <summary>
/// This makes sure there is no background painted, as we have complete "paint" control it doesn't make sense to do otherwise.
/// </summary>
/// <param name="pevent"></param>
protected override void OnPaintBackground(PaintEventArgs pevent) {
}
protected override void OnPaint(PaintEventArgs e) { protected override void OnPaint(PaintEventArgs e) {
if (captureToZoom == null || captureToZoom.Image == null) { if (captureToZoom == null || captureToZoom.Image == null) {
@ -83,13 +100,13 @@ namespace Greenshot.Forms {
graphics.SmoothingMode = SmoothingMode.None; graphics.SmoothingMode = SmoothingMode.None;
graphics.InterpolationMode = InterpolationMode.NearestNeighbor; graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
graphics.CompositingQuality = CompositingQuality.HighSpeed; graphics.CompositingQuality = CompositingQuality.HighSpeed;
graphics.PixelOffsetMode = PixelOffsetMode.None; graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
Rectangle clipRectangle = e.ClipRectangle; Rectangle clipRectangle = e.ClipRectangle;
float zoom = (float)100 / (float)Zoom; float zoom = (float)100 / (float)Zoom;
int sourceWidth = (int)(Width * zoom); int sourceWidth = (int)(Width * zoom);
int sourceHeight = (int)(Height * zoom); int sourceHeight = (int)(Height * zoom);
Rectangle sourceRectangle = new Rectangle(MouseLocation.X - (sourceHeight / 2), MouseLocation.Y - (sourceHeight / 2), sourceWidth, sourceHeight); Rectangle sourceRectangle = new Rectangle(MouseLocation.X - (sourceWidth / 2), MouseLocation.Y - (sourceHeight / 2), sourceWidth, sourceHeight);
Rectangle destinationRectangle = new Rectangle(0, 0, Width, Height); Rectangle destinationRectangle = new Rectangle(0, 0, Width, Height);
graphics.DrawImage(captureToZoom.Image, destinationRectangle, sourceRectangle, GraphicsUnit.Pixel); graphics.DrawImage(captureToZoom.Image, destinationRectangle, sourceRectangle, GraphicsUnit.Pixel);
@ -115,11 +132,12 @@ namespace Greenshot.Forms {
this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None; this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
this.ClientSize = new System.Drawing.Size(100, 100); this.ClientSize = new System.Drawing.Size(100, 100);
this.ControlBox = false; this.ControlBox = false;
this.DoubleBuffered = true; // Only double-buffer when we are not in a TerminalServerSession
this.DoubleBuffered = !System.Windows.Forms.SystemInformation.TerminalServerSession;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.MaximizeBox = false; this.MaximizeBox = false;
this.MinimizeBox = false; this.MinimizeBox = false;
this.MinimumSize = new Size(50, 50); this.MinimumSize = ClientSize;
this.Name = "Zoom"; this.Name = "Zoom";
this.ShowIcon = false; this.ShowIcon = false;
this.ShowInTaskbar = false; this.ShowInTaskbar = false;