Improved the gadget formatting and added an option to remove the hardware names in the gadget.
3 Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 The contents of this file are subject to the Mozilla Public License Version
6 1.1 (the "License"); you may not use this file except in compliance with
7 the License. You may obtain a copy of the License at
9 http://www.mozilla.org/MPL/
11 Software distributed under the License is distributed on an "AS IS" basis,
12 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 for the specific language governing rights and limitations under the License.
15 The Original Code is the Open Hardware Monitor code.
17 The Initial Developer of the Original Code is
18 Michael Möller <m.moeller@gmx.ch>.
19 Portions created by the Initial Developer are Copyright (C) 2010
20 the Initial Developer. All Rights Reserved.
24 Alternatively, the contents of this file may be used under the terms of
25 either the GNU General Public License Version 2 or later (the "GPL"), or
26 the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 in which case the provisions of the GPL or the LGPL are applicable instead
28 of those above. If you wish to allow use of your version of this file only
29 under the terms of either the GPL or the LGPL, and not to allow others to
30 use your version of this file under the terms of the MPL, indicate your
31 decision by deleting the provisions above and replace them with the notice
32 and other provisions required by the GPL or the LGPL. If you do not delete
33 the provisions above, a recipient may use your version of this file under
34 the terms of any one of the MPL, the GPL or the LGPL.
40 using System.Drawing.Drawing2D;
41 using System.Drawing.Imaging;
42 using System.Drawing.Text;
43 using System.Windows.Forms;
45 namespace OpenHardwareMonitor.GUI {
46 public abstract class Gadget : IDisposable {
48 private GadgetWindow window;
49 private Bitmap buffer;
50 private Graphics graphics;
53 this.window = new GadgetWindow();
57 public virtual void Dispose() {
61 public Point Location {
63 return window.Location;
66 window.Location = value;
70 public event EventHandler LocationChanged {
72 window.LocationChanged += value;
75 window.LocationChanged -= value;
79 protected virtual Size Size {
84 if (window.Size != value) {
86 this.window.Size = value;
94 return window.Opacity;
97 window.Opacity = value;
101 public bool LockPosition {
103 return window.LockPosition;
106 window.LockPosition = value;
110 public bool AlwaysOnTop {
112 return window.AlwaysOnTop;
115 window.AlwaysOnTop = value;
119 public ContextMenu ContextMenu {
121 return window.ContextMenu;
124 window.ContextMenu = value;
128 private void CreateBuffer() {
129 this.buffer = new Bitmap(window.Size.Width, window.Size.Height,
130 PixelFormat.Format32bppArgb);
131 this.graphics = Graphics.FromImage(this.buffer);
132 if (Environment.OSVersion.Version.Major > 5) {
133 this.graphics.TextRenderingHint = TextRenderingHint.SystemDefault;
134 this.graphics.SmoothingMode = SmoothingMode.HighQuality;
138 private void DisposeBuffer() {
139 if (buffer != null) {
140 this.buffer.Dispose();
143 if (graphics != null) {
144 this.graphics.Dispose();
145 this.graphics = null;
149 public bool Visible {
151 return window.Visible;
154 if (value != window.Visible) {
157 window.Visible = value;
162 public void Redraw() {
163 OnPaint(new PaintEventArgs(graphics,
164 new Rectangle(Point.Empty, window.Size)));
165 window.Update(buffer);
168 protected abstract void OnPaint(PaintEventArgs e);