GUI/HardwareTypeImage.cs
author moel.mich
Wed, 22 Jun 2011 22:36:17 +0000
changeset 302 44c0e7f76e9e
child 344 3145aadca3d2
permissions -rw-r--r--
Removed the bitmap.GetHbitmap call for every redraw of the gadget. This should reduce dynamic memory allocation and freeing and removes some of the page faults increasing.
     1 /*
     2   
     3   Version: MPL 1.1/GPL 2.0/LGPL 2.1
     4 
     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
     8  
     9   http://www.mozilla.org/MPL/
    10 
    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.
    14 
    15   The Original Code is the Open Hardware Monitor code.
    16 
    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.
    21 
    22   Contributor(s):
    23 
    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.
    35  
    36 */
    37 
    38 using System;
    39 using System.Drawing;
    40 using System.Collections.Generic;
    41 using OpenHardwareMonitor.Hardware;
    42 
    43 namespace OpenHardwareMonitor.GUI {
    44   public class HardwareTypeImage {
    45     private static HardwareTypeImage instance = new HardwareTypeImage();
    46 
    47     private IDictionary<HardwareType, Image> images = 
    48       new Dictionary<HardwareType, Image>();
    49 
    50     private HardwareTypeImage() { }
    51 
    52     public static HardwareTypeImage Instance {
    53       get { return instance; }
    54     }
    55 
    56     public Image GetImage(HardwareType hardwareType) {
    57       Image image;
    58       if (images.TryGetValue(hardwareType, out image)) {
    59         return image;
    60       } else {
    61         switch (hardwareType) {
    62           case HardwareType.CPU:
    63             image = Utilities.EmbeddedResources.GetImage("cpu.png");
    64             break;
    65           case HardwareType.GpuNvidia:
    66             image = Utilities.EmbeddedResources.GetImage("nvidia.png");
    67             break;
    68           case HardwareType.GpuAti:
    69             image = Utilities.EmbeddedResources.GetImage("ati.png");
    70             break;
    71           case HardwareType.HDD:
    72             image = Utilities.EmbeddedResources.GetImage("hdd.png");
    73             break;
    74           case HardwareType.Heatmaster:
    75             image = Utilities.EmbeddedResources.GetImage("bigng.png");
    76             break;
    77           case HardwareType.Mainboard:
    78             image = Utilities.EmbeddedResources.GetImage("mainboard.png");
    79             break;
    80           case HardwareType.SuperIO:
    81             image = Utilities.EmbeddedResources.GetImage("chip.png");
    82             break;
    83           case HardwareType.TBalancer:
    84             image = Utilities.EmbeddedResources.GetImage("bigng.png");
    85             break;
    86           default:
    87             image = new Bitmap(1, 1);
    88             break;
    89         }
    90         images.Add(hardwareType, image);
    91         return image;
    92       }
    93     }
    94   }
    95 }