//----------------------------------------------------------------------- // // Copyright © 2012 Nils Hammar. All rights reserved. // //----------------------------------------------------------------------- /* * Software to access vehicle information via the OBD-II connector. * * Copyright © 2012 Nils Hammar * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Alternative licensing is possible, see the licensing document. * * The above text may not be removed or modified. */ namespace Gauges.TelltalePanel { using System.Drawing; using System.Drawing.Imaging; /// /// Create palettes for icons to allow for an easy way to get flashing icons. /// public class PaletteCreator { /// /// Primary color list, flash 'on'. /// private static readonly Color[] cols1 = new Color[] { Color.Transparent, Color.Black, Color.Red, Color.Gold, Color.LimeGreen, Color.Blue, Color.Magenta, Color.White, Color.Transparent, Color.Black, Color.Red, Color.Gold, Color.LimeGreen, Color.Blue, Color.Magenta, Color.White, }; /// /// Secondary color list, flash 'off'. /// private static readonly Color[] cols2 = new Color[] { Color.Transparent, Color.Black, Color.Red, Color.Gold, Color.LimeGreen, Color.Blue, Color.Magenta, Color.White, Color.Black, Color.Black, Color.Black, Color.Black, Color.Black, Color.Black, Color.Black, Color.Black, }; /// /// Gets Palette for flash 'on'. /// public ColorPalette paletteFlashOn { get; private set; } /// /// Gets Palette for flash 'off'. /// public ColorPalette paletteFlashOff { get; private set; } /// /// Initializes a new instance of the class. /// public PaletteCreator() { using (Bitmap bmpZ = new Bitmap(16, 16, System.Drawing.Imaging.PixelFormat.Format8bppIndexed)) { this.paletteFlashOn = bmpZ.Palette; this.paletteFlashOff = bmpZ.Palette; for (int i = 0; i < cols1.Length; i++) { this.paletteFlashOn.Entries[i] = cols1[i]; } for (int i = 0; i < cols2.Length; i++) { this.paletteFlashOff.Entries[i] = cols2[i]; } } } /// /// Get the color index of a given color. /// /// Color to get index for. /// 'true' if the color shall be flashing. /// Color index value. public static byte getColorIndex(Color color, bool flash) { byte ix = 0; foreach (Color col in cols1) { if (col.Equals(color)) { break; } ix++; } // Default to index for Flashing white if color not found. if (ix == cols1.Length) { ix = 15; } if (flash) { ix |= 0x08; } return ix; } } }