Make Basic Colors Functions

Created:5/31/2000
Description:

Use these functions to help you create new color objects. You can create RGBColors, CMYKColors, HSVColors, or HLSColors and specify 1 of 16 basic colors for the new color class. The 16 basic colors reflect the colors typically found in a 4 bit, 16 color system.

How to use:
  1. Copy and paste the required functions into your application. Make sure the enumeration is defined in an appropriate place, i.e. that it is global to all the functions which need to use it.
  2. Call MakeRGB, MakeCMYK, MakeHLS or MakeHSV using a color from the basicColorEnum enumeration as the paramater in the function call to create a new color object, for example:
    '
    ' This enumeration creates constants for the 16 basic colors used in a 4bit
    ' color system.
    '
    Private Enum basicColorEnum
      colorBlack
      colorDarkRed
      colorDarkGreen
      colorDarkYellow
      colorDarkBlue
      colorDarkPurple
      colorDarkCyan
      colorPaleGray
      colorMidGray
      colorRed
      colorGreen
      colorYellow
      colorBlue
      colorMagenta
      colorCyan
      colorWhite
    End Enum
    '
    ' This function will return a new CMYKColor object.
    ' Its color is initialized to the passed in constant.
    '
    Private Function MakeCMYK(ByVal inColor As basicColorEnum) As ICmykColor
      Dim pCMYK As esriCore.ICmykColor
      Set pCMYK = New esriCore.CmykColor
      pCMYK.RGB = MakeRGB(inColor).RGB
      Set MakeCMYK = pCMYK
    End Function
    '
    ' This function will return a new HSVColor object.
    ' Its color is initialized to the passed in constant.
    '
    Private Function MakeHSV(ByVal inColor As basicColorEnum) As IHsvColor
      Dim pHSV As esriCore.IHsvColor
      Set pHSV = New esriCore.HsvColor
      pHSV.RGB = MakeRGB(inColor).RGB
      Set MakeHSV = pHSV
    End Function
    '
    ' This function will return a new HLSColor object.
    ' Its color is initialized to the passed in constant.
    '
    Private Function MakeHLS(ByVal inColor As basicColorEnum) As IHlsColor
      Dim pHLS As esriCore.IHlsColor
      Set pHLS = New esriCore.HlsColor
      pHLS.RGB = MakeRGB(inColor).RGB
      Set MakeHLS = pHLS
    End Function
    '
    ' This function will return a new RGBColor object.
    ' Its color is initialized to the passed in constant.
    '
    Private Function MakeRGB(ByVal inColor As basicColorEnum) As IRgbColor
      Dim pRGB As IRgbColor
      Set pRGB = New esriCore.RgbColor
      
      Select Case inColor
      Case colorBlack
        pRGB.RGB = RGB(0, 0, 0)
      Case colorDarkRed
        pRGB.RGB = RGB(128, 0, 0)
      Case colorDarkGreen
        pRGB.RGB = RGB(0, 128, 0)
      Case colorDarkYellow
        pRGB.RGB = RGB(128, 128, 0)
      Case colorDarkBlue
        pRGB.RGB = RGB(0, 0, 128)
      Case colorDarkPurple
        pRGB.RGB = RGB(128, 0, 128)
      Case colorDarkCyan
        pRGB.RGB = RGB(0, 128, 128)
      Case colorPaleGray
        pRGB.RGB = RGB(192, 192, 192)
      Case colorMidGray
        pRGB.RGB = RGB(128, 128, 128)
      Case colorRed
        pRGB.RGB = RGB(255, 0, 0)
      Case colorGreen
        pRGB.RGB = RGB(0, 255, 0)
      Case colorYellow
        pRGB.RGB = RGB(255, 255, 0)
      Case colorBlue
        pRGB.RGB = RGB(0, 0, 255)
      Case colorMagenta
        pRGB.RGB = RGB(255, 0, 255)
      Case colorCyan
        pRGB.RGB = RGB(0, 255, 255)
      Case colorWhite
        pRGB.RGB = RGB(255, 255, 255)
      End Select
      Set MakeRGB = pRGB
    End Function
    
'
' This enumeration creates constants for the 16 basic colors used in a 4bit
' color system.
'
Private Enum basicColorEnum
  colorBlack
  colorDarkRed
  colorDarkGreen
  colorDarkYellow
  colorDarkBlue
  colorDarkPurple
  colorDarkCyan
  colorPaleGray
  colorMidGray
  colorRed
  colorGreen
  colorYellow
  colorBlue
  colorMagenta
  colorCyan
  colorWhite
End Enum
'
' This function will return a new CMYKColor object.
' Its color is initialized to the passed in constant.
'
Private Function MakeCMYK(ByVal inColor As basicColorEnum) As ICmykColor
  Dim pCMYK As esriCore.ICmykColor
  Set pCMYK = New esriCore.CmykColor
  pCMYK.RGB = MakeRGB(inColor).RGB
  Set MakeCMYK = pCMYK
End Function
'
' This function will return a new HSVColor object.
' Its color is initialized to the passed in constant.
'
Private Function MakeHSV(ByVal inColor As basicColorEnum) As IHsvColor
  Dim pHSV As esriCore.IHsvColor
  Set pHSV = New esriCore.HsvColor
  pHSV.RGB = MakeRGB(inColor).RGB
  Set MakeHSV = pHSV
End Function
'
' This function will return a new HLSColor object.
' Its color is initialized to the passed in constant.
'
Private Function MakeHLS(ByVal inColor As basicColorEnum) As IHlsColor
  Dim pHLS As esriCore.IHlsColor
  Set pHLS = New esriCore.HlsColor
  pHLS.RGB = MakeRGB(inColor).RGB
  Set MakeHLS = pHLS
End Function
'
' This function will return a new RGBColor object.
' Its color is initialized to the passed in constant.
'
Private Function MakeRGB(ByVal inColor As basicColorEnum) As IRgbColor
  Dim pRGB As IRgbColor
  Set pRGB = New esriCore.RgbColor
  
  Select Case inColor
  Case colorBlack
    pRGB.RGB = RGB(0, 0, 0)
  Case colorDarkRed
    pRGB.RGB = RGB(128, 0, 0)
  Case colorDarkGreen
    pRGB.RGB = RGB(0, 128, 0)
  Case colorDarkYellow
    pRGB.RGB = RGB(128, 128, 0)
  Case colorDarkBlue
    pRGB.RGB = RGB(0, 0, 128)
  Case colorDarkPurple
    pRGB.RGB = RGB(128, 0, 128)
  Case colorDarkCyan
    pRGB.RGB = RGB(0, 128, 128)
  Case colorPaleGray
    pRGB.RGB = RGB(192, 192, 192)
  Case colorMidGray
    pRGB.RGB = RGB(128, 128, 128)
  Case colorRed
    pRGB.RGB = RGB(255, 0, 0)
  Case colorGreen
    pRGB.RGB = RGB(0, 255, 0)
  Case colorYellow
    pRGB.RGB = RGB(255, 255, 0)
  Case colorBlue
    pRGB.RGB = RGB(0, 0, 255)
  Case colorMagenta
    pRGB.RGB = RGB(255, 0, 255)
  Case colorCyan
    pRGB.RGB = RGB(0, 255, 255)
  Case colorWhite
    pRGB.RGB = RGB(255, 255, 255)
  End Select
  Set MakeRGB = pRGB
End Function