GdiPlusColor.h
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:10k
源码类别:

模拟服务器

开发平台:

C/C++

  1. /**************************************************************************
  2. *
  3. * Copyright (c) 1998-2001, Microsoft Corp.  All Rights Reserved.
  4. *
  5. * Module Name:
  6. *
  7. *   GdiplusColor.h
  8. *
  9. * Abstract:
  10. *
  11. *   GDI+ Color Object
  12. *
  13. **************************************************************************/
  14. #ifndef _GDIPLUSCOLOR_H
  15. #define _GDIPLUSCOLOR_H
  16. //----------------------------------------------------------------------------
  17. // Color mode
  18. //----------------------------------------------------------------------------
  19. enum ColorMode
  20. {
  21.     ColorModeARGB32 = 0,
  22.     ColorModeARGB64 = 1
  23. };
  24. //----------------------------------------------------------------------------
  25. // Color Channel flags
  26. //----------------------------------------------------------------------------
  27. enum ColorChannelFlags
  28. {
  29.     ColorChannelFlagsC = 0,
  30.     ColorChannelFlagsM,
  31.     ColorChannelFlagsY,
  32.     ColorChannelFlagsK,
  33.     ColorChannelFlagsLast
  34. };
  35. //----------------------------------------------------------------------------
  36. // Color
  37. //----------------------------------------------------------------------------
  38. class Color
  39. {
  40. public:
  41.     Color()
  42.     {
  43.         Argb = (ARGB)Color::Black;
  44.     }
  45.     // Construct an opaque Color object with
  46.     // the specified Red, Green, Blue values.
  47.     //
  48.     // Color values are not premultiplied.
  49.     Color(IN BYTE r,
  50.           IN BYTE g,
  51.           IN BYTE b)
  52.     {
  53.         Argb = MakeARGB(255, r, g, b);
  54.     }
  55.     Color(IN BYTE a,
  56.           IN BYTE r,
  57.           IN BYTE g,
  58.           IN BYTE b)
  59.     {
  60.         Argb = MakeARGB(a, r, g, b);
  61.     }
  62.     Color(IN ARGB argb)
  63.     {
  64.         Argb = argb;
  65.     }
  66.     BYTE GetAlpha() const
  67.     {
  68.         return (BYTE) (Argb >> AlphaShift);
  69.     }
  70.     BYTE GetA() const
  71.     {
  72.         return GetAlpha();
  73.     }
  74.     BYTE GetRed() const
  75.     {
  76.         return (BYTE) (Argb >> RedShift);
  77.     }
  78.     BYTE GetR() const
  79.     {
  80.         return GetRed();
  81.     }
  82.     BYTE GetGreen() const
  83.     {
  84.         return (BYTE) (Argb >> GreenShift);
  85.     }
  86.     BYTE GetG() const
  87.     {
  88.         return GetGreen();
  89.     }
  90.     BYTE GetBlue() const
  91.     {
  92.         return (BYTE) (Argb >> BlueShift);
  93.     }
  94.     BYTE GetB() const
  95.     {
  96.         return GetBlue();
  97.     }
  98.     ARGB GetValue() const
  99.     {
  100.         return Argb;
  101.     }
  102.     VOID SetValue(IN ARGB argb)
  103.     {
  104.         Argb = argb;
  105.     }
  106.     VOID SetFromCOLORREF(IN COLORREF rgb)
  107.     {
  108.         Argb = MakeARGB(255, GetRValue(rgb), GetGValue(rgb), GetBValue(rgb));
  109.     }
  110.     COLORREF ToCOLORREF() const
  111.     {
  112.         return RGB(GetRed(), GetGreen(), GetBlue());
  113.     }
  114. public:
  115.     // Common color constants
  116.     
  117.     enum
  118.     {
  119.         AliceBlue            = 0xFFF0F8FF,
  120.         AntiqueWhite         = 0xFFFAEBD7,
  121.         Aqua                 = 0xFF00FFFF,
  122.         Aquamarine           = 0xFF7FFFD4,
  123.         Azure                = 0xFFF0FFFF,
  124.         Beige                = 0xFFF5F5DC,
  125.         Bisque               = 0xFFFFE4C4,
  126.         Black                = 0xFF000000,
  127.         BlanchedAlmond       = 0xFFFFEBCD,
  128.         Blue                 = 0xFF0000FF,
  129.         BlueViolet           = 0xFF8A2BE2,
  130.         Brown                = 0xFFA52A2A,
  131.         BurlyWood            = 0xFFDEB887,
  132.         CadetBlue            = 0xFF5F9EA0,
  133.         Chartreuse           = 0xFF7FFF00,
  134.         Chocolate            = 0xFFD2691E,
  135.         Coral                = 0xFFFF7F50,
  136.         CornflowerBlue       = 0xFF6495ED,
  137.         Cornsilk             = 0xFFFFF8DC,
  138.         Crimson              = 0xFFDC143C,
  139.         Cyan                 = 0xFF00FFFF,
  140.         DarkBlue             = 0xFF00008B,
  141.         DarkCyan             = 0xFF008B8B,
  142.         DarkGoldenrod        = 0xFFB8860B,
  143.         DarkGray             = 0xFFA9A9A9,
  144.         DarkGreen            = 0xFF006400,
  145.         DarkKhaki            = 0xFFBDB76B,
  146.         DarkMagenta          = 0xFF8B008B,
  147.         DarkOliveGreen       = 0xFF556B2F,
  148.         DarkOrange           = 0xFFFF8C00,
  149.         DarkOrchid           = 0xFF9932CC,
  150.         DarkRed              = 0xFF8B0000,
  151.         DarkSalmon           = 0xFFE9967A,
  152.         DarkSeaGreen         = 0xFF8FBC8B,
  153.         DarkSlateBlue        = 0xFF483D8B,
  154.         DarkSlateGray        = 0xFF2F4F4F,
  155.         DarkTurquoise        = 0xFF00CED1,
  156.         DarkViolet           = 0xFF9400D3,
  157.         DeepPink             = 0xFFFF1493,
  158.         DeepSkyBlue          = 0xFF00BFFF,
  159.         DimGray              = 0xFF696969,
  160.         DodgerBlue           = 0xFF1E90FF,
  161.         Firebrick            = 0xFFB22222,
  162.         FloralWhite          = 0xFFFFFAF0,
  163.         ForestGreen          = 0xFF228B22,
  164.         Fuchsia              = 0xFFFF00FF,
  165.         Gainsboro            = 0xFFDCDCDC,
  166.         GhostWhite           = 0xFFF8F8FF,
  167.         Gold                 = 0xFFFFD700,
  168.         Goldenrod            = 0xFFDAA520,
  169.         Gray                 = 0xFF808080,
  170.         Green                = 0xFF008000,
  171.         GreenYellow          = 0xFFADFF2F,
  172.         Honeydew             = 0xFFF0FFF0,
  173.         HotPink              = 0xFFFF69B4,
  174.         IndianRed            = 0xFFCD5C5C,
  175.         Indigo               = 0xFF4B0082,
  176.         Ivory                = 0xFFFFFFF0,
  177.         Khaki                = 0xFFF0E68C,
  178.         Lavender             = 0xFFE6E6FA,
  179.         LavenderBlush        = 0xFFFFF0F5,
  180.         LawnGreen            = 0xFF7CFC00,
  181.         LemonChiffon         = 0xFFFFFACD,
  182.         LightBlue            = 0xFFADD8E6,
  183.         LightCoral           = 0xFFF08080,
  184.         LightCyan            = 0xFFE0FFFF,
  185.         LightGoldenrodYellow = 0xFFFAFAD2,
  186.         LightGray            = 0xFFD3D3D3,
  187.         LightGreen           = 0xFF90EE90,
  188.         LightPink            = 0xFFFFB6C1,
  189.         LightSalmon          = 0xFFFFA07A,
  190.         LightSeaGreen        = 0xFF20B2AA,
  191.         LightSkyBlue         = 0xFF87CEFA,
  192.         LightSlateGray       = 0xFF778899,
  193.         LightSteelBlue       = 0xFFB0C4DE,
  194.         LightYellow          = 0xFFFFFFE0,
  195.         Lime                 = 0xFF00FF00,
  196.         LimeGreen            = 0xFF32CD32,
  197.         Linen                = 0xFFFAF0E6,
  198.         Magenta              = 0xFFFF00FF,
  199.         Maroon               = 0xFF800000,
  200.         MediumAquamarine     = 0xFF66CDAA,
  201.         MediumBlue           = 0xFF0000CD,
  202.         MediumOrchid         = 0xFFBA55D3,
  203.         MediumPurple         = 0xFF9370DB,
  204.         MediumSeaGreen       = 0xFF3CB371,
  205.         MediumSlateBlue      = 0xFF7B68EE,
  206.         MediumSpringGreen    = 0xFF00FA9A,
  207.         MediumTurquoise      = 0xFF48D1CC,
  208.         MediumVioletRed      = 0xFFC71585,
  209.         MidnightBlue         = 0xFF191970,
  210.         MintCream            = 0xFFF5FFFA,
  211.         MistyRose            = 0xFFFFE4E1,
  212.         Moccasin             = 0xFFFFE4B5,
  213.         NavajoWhite          = 0xFFFFDEAD,
  214.         Navy                 = 0xFF000080,
  215.         OldLace              = 0xFFFDF5E6,
  216.         Olive                = 0xFF808000,
  217.         OliveDrab            = 0xFF6B8E23,
  218.         Orange               = 0xFFFFA500,
  219.         OrangeRed            = 0xFFFF4500,
  220.         Orchid               = 0xFFDA70D6,
  221.         PaleGoldenrod        = 0xFFEEE8AA,
  222.         PaleGreen            = 0xFF98FB98,
  223.         PaleTurquoise        = 0xFFAFEEEE,
  224.         PaleVioletRed        = 0xFFDB7093,
  225.         PapayaWhip           = 0xFFFFEFD5,
  226.         PeachPuff            = 0xFFFFDAB9,
  227.         Peru                 = 0xFFCD853F,
  228.         Pink                 = 0xFFFFC0CB,
  229.         Plum                 = 0xFFDDA0DD,
  230.         PowderBlue           = 0xFFB0E0E6,
  231.         Purple               = 0xFF800080,
  232.         Red                  = 0xFFFF0000,
  233.         RosyBrown            = 0xFFBC8F8F,
  234.         RoyalBlue            = 0xFF4169E1,
  235.         SaddleBrown          = 0xFF8B4513,
  236.         Salmon               = 0xFFFA8072,
  237.         SandyBrown           = 0xFFF4A460,
  238.         SeaGreen             = 0xFF2E8B57,
  239.         SeaShell             = 0xFFFFF5EE,
  240.         Sienna               = 0xFFA0522D,
  241.         Silver               = 0xFFC0C0C0,
  242.         SkyBlue              = 0xFF87CEEB,
  243.         SlateBlue            = 0xFF6A5ACD,
  244.         SlateGray            = 0xFF708090,
  245.         Snow                 = 0xFFFFFAFA,
  246.         SpringGreen          = 0xFF00FF7F,
  247.         SteelBlue            = 0xFF4682B4,
  248.         Tan                  = 0xFFD2B48C,
  249.         Teal                 = 0xFF008080,
  250.         Thistle              = 0xFFD8BFD8,
  251.         Tomato               = 0xFFFF6347,
  252.         Transparent          = 0x00FFFFFF,
  253.         Turquoise            = 0xFF40E0D0,
  254.         Violet               = 0xFFEE82EE,
  255.         Wheat                = 0xFFF5DEB3,
  256.         White                = 0xFFFFFFFF,
  257.         WhiteSmoke           = 0xFFF5F5F5,
  258.         Yellow               = 0xFFFFFF00,
  259.         YellowGreen          = 0xFF9ACD32
  260.     };
  261.     // Shift count and bit mask for A, R, G, B components
  262.     
  263.     enum
  264.     {
  265.         AlphaShift  = 24,
  266.         RedShift    = 16,
  267.         GreenShift  = 8,
  268.         BlueShift   = 0
  269.     };
  270.     enum
  271.     {
  272.         AlphaMask   = 0xff000000,
  273.         RedMask     = 0x00ff0000,
  274.         GreenMask   = 0x0000ff00,
  275.         BlueMask    = 0x000000ff
  276.     };
  277.     // Assemble A, R, G, B values into a 32-bit integer
  278.     
  279.     static ARGB MakeARGB(IN BYTE a,
  280.                          IN BYTE r,
  281.                          IN BYTE g,
  282.                          IN BYTE b)
  283.     {
  284.         return (((ARGB) (b) <<  BlueShift) |
  285.                 ((ARGB) (g) << GreenShift) |
  286.                 ((ARGB) (r) <<   RedShift) |
  287.                 ((ARGB) (a) << AlphaShift));
  288.     }
  289. protected:
  290.     ARGB Argb;
  291. };
  292. #endif