1.1 --- a/GUI/Gadget.cs Sun Jun 19 14:14:00 2011 +0000
1.2 +++ b/GUI/Gadget.cs Wed Jun 22 22:36:17 2011 +0000
1.3 @@ -16,7 +16,7 @@
1.4
1.5 The Initial Developer of the Original Code is
1.6 Michael Möller <m.moeller@gmx.ch>.
1.7 - Portions created by the Initial Developer are Copyright (C) 2010
1.8 + Portions created by the Initial Developer are Copyright (C) 2010-2011
1.9 the Initial Developer. All Rights Reserved.
1.10
1.11 Contributor(s):
1.12 @@ -37,25 +37,22 @@
1.13
1.14 using System;
1.15 using System.Drawing;
1.16 -using System.Drawing.Drawing2D;
1.17 -using System.Drawing.Imaging;
1.18 -using System.Drawing.Text;
1.19 using System.Windows.Forms;
1.20
1.21 namespace OpenHardwareMonitor.GUI {
1.22 public abstract class Gadget : IDisposable {
1.23
1.24 private GadgetWindow window;
1.25 - private Bitmap buffer;
1.26 - private Graphics graphics;
1.27
1.28 public Gadget() {
1.29 this.window = new GadgetWindow();
1.30 - CreateBuffer();
1.31 + this.window.Paint += delegate(object sender, PaintEventArgs e) {
1.32 + OnPaint(e);
1.33 + };
1.34 }
1.35
1.36 public virtual void Dispose() {
1.37 - DisposeBuffer();
1.38 + window.Dispose();
1.39 }
1.40
1.41 public Point Location {
1.42 @@ -148,27 +145,6 @@
1.43 }
1.44 }
1.45
1.46 - private void CreateBuffer() {
1.47 - this.buffer = new Bitmap(window.Size.Width, window.Size.Height,
1.48 - PixelFormat.Format32bppArgb);
1.49 - this.graphics = Graphics.FromImage(this.buffer);
1.50 - if (Environment.OSVersion.Version.Major > 5) {
1.51 - this.graphics.TextRenderingHint = TextRenderingHint.SystemDefault;
1.52 - this.graphics.SmoothingMode = SmoothingMode.HighQuality;
1.53 - }
1.54 - }
1.55 -
1.56 - private void DisposeBuffer() {
1.57 - if (buffer != null) {
1.58 - this.buffer.Dispose();
1.59 - this.buffer = null;
1.60 - }
1.61 - if (graphics != null) {
1.62 - this.graphics.Dispose();
1.63 - this.graphics = null;
1.64 - }
1.65 - }
1.66 -
1.67 public bool Visible {
1.68 get {
1.69 return window.Visible;
1.70 @@ -187,17 +163,7 @@
1.71 public event EventHandler VisibleChanged;
1.72
1.73 public void Redraw() {
1.74 - if (!window.Visible)
1.75 - return;
1.76 -
1.77 - if (window.Size != buffer.Size) {
1.78 - DisposeBuffer();
1.79 - CreateBuffer();
1.80 - }
1.81 -
1.82 - OnPaint(new PaintEventArgs(graphics,
1.83 - new Rectangle(Point.Empty, window.Size)));
1.84 - window.Update(buffer);
1.85 + window.Redraw();
1.86 }
1.87
1.88 protected abstract void OnPaint(PaintEventArgs e);