From 9ca5f0d3bd03973857c02f4414e1c0f4e421a9b2 Mon Sep 17 00:00:00 2001 From: RKrom Date: Wed, 14 Nov 2012 09:34:33 +0000 Subject: [PATCH] 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 --- Greenshot/Forms/CaptureForm.Designer.cs | 1 - Greenshot/Forms/CaptureForm.cs | 22 ++++++++++++++++++++- Greenshot/Forms/ZoomForm.cs | 26 +++++++++++++++++++++---- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/Greenshot/Forms/CaptureForm.Designer.cs b/Greenshot/Forms/CaptureForm.Designer.cs index c09689558..bb2495b17 100644 --- a/Greenshot/Forms/CaptureForm.Designer.cs +++ b/Greenshot/Forms/CaptureForm.Designer.cs @@ -59,7 +59,6 @@ namespace Greenshot.Forms { this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.ClientSize = new System.Drawing.Size(0, 0); this.Cursor = System.Windows.Forms.Cursors.Cross; - this.DoubleBuffered = true; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.Name = "CaptureForm"; this.ShowIcon = false; diff --git a/Greenshot/Forms/CaptureForm.cs b/Greenshot/Forms/CaptureForm.cs index d41dae78d..e2d0e7307 100644 --- a/Greenshot/Forms/CaptureForm.cs +++ b/Greenshot/Forms/CaptureForm.cs @@ -81,6 +81,17 @@ namespace Greenshot.Forms { } } + /// + /// This should prevent childs to draw backgrounds + /// + protected override CreateParams CreateParams { + get { + CreateParams cp = base.CreateParams; + cp.ExStyle |= 0x02000000; + return cp; + } + } + public CaptureForm(ICapture capture, List windows) { if (currentForm != null) { 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. // InitializeComponent(); + // Only double-buffer when we are not in a TerminalServerSession + this.DoubleBuffered = !System.Windows.Forms.SystemInformation.TerminalServerSession; this.Text = "Greenshot capture form"; // Make sure we never capture the captureform @@ -367,7 +380,14 @@ namespace Greenshot.Forms { } } } - + + /// + /// This makes sure there is no background painted, as we have complete "paint" control it doesn't make sense to do otherwise. + /// + /// + protected override void OnPaintBackground(PaintEventArgs pevent) { + } + void OnPaint(object sender, PaintEventArgs e) { Graphics graphics = e.Graphics; Rectangle clipRectangle = e.ClipRectangle; diff --git a/Greenshot/Forms/ZoomForm.cs b/Greenshot/Forms/ZoomForm.cs index 3a32e5dd4..dee4b3be3 100644 --- a/Greenshot/Forms/ZoomForm.cs +++ b/Greenshot/Forms/ZoomForm.cs @@ -45,6 +45,17 @@ namespace Greenshot.Forms { Zoom = 400; } + /// + /// Prevent the clipping of the child (this Form is a child of another) + /// + protected override CreateParams CreateParams { + get { + var parms = base.CreateParams; + parms.Style &= ~0x02000000; // Turn off WS_CLIPCHILDREN + return parms; + } + } + public Point MouseLocation { get { return mouseLocation; @@ -74,6 +85,12 @@ namespace Greenshot.Forms { get; set; } + /// + /// This makes sure there is no background painted, as we have complete "paint" control it doesn't make sense to do otherwise. + /// + /// + protected override void OnPaintBackground(PaintEventArgs pevent) { + } protected override void OnPaint(PaintEventArgs e) { if (captureToZoom == null || captureToZoom.Image == null) { @@ -83,13 +100,13 @@ namespace Greenshot.Forms { graphics.SmoothingMode = SmoothingMode.None; graphics.InterpolationMode = InterpolationMode.NearestNeighbor; graphics.CompositingQuality = CompositingQuality.HighSpeed; - graphics.PixelOffsetMode = PixelOffsetMode.None; + graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; Rectangle clipRectangle = e.ClipRectangle; float zoom = (float)100 / (float)Zoom; int sourceWidth = (int)(Width * 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); graphics.DrawImage(captureToZoom.Image, destinationRectangle, sourceRectangle, GraphicsUnit.Pixel); @@ -115,11 +132,12 @@ namespace Greenshot.Forms { this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None; this.ClientSize = new System.Drawing.Size(100, 100); 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.MaximizeBox = false; this.MinimizeBox = false; - this.MinimumSize = new Size(50, 50); + this.MinimumSize = ClientSize; this.Name = "Zoom"; this.ShowIcon = false; this.ShowInTaskbar = false;