It is currently Thu Dec 12, 2019 7:54 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: ColorSpectrum - Module
PostPosted: Thu Feb 21, 2019 2:43 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jul 07, 2013 11:35 am
Posts: 450
Location: Canada
Hello everyone,

A ColorRequester() alternative, more compact than the currently available one apparently very similar to the MS Paint one's.
I deserve credit for converting the original code into a Module. Function to translate/customize the requester are included.

Best regards
StarBootics

Code:
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : ColorSpectrum - Module
; File Name : ColorSpectrum - Module.pb
; File version: 1.0.1
; Programming : OK
; Programmed by : StarBootics
; Date : 19-02-2019
; Last Update : 21-02-2019
; PureBasic code : V5.70 LTS
; Platform : Windows, Linux, MacOS X
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Programming notes
;
; Based on original code for GallyHC and Guimauve (French Forum)
; See here : https://www.purebasic.fr/french/viewtopic.php?f=6&t=12596
;
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

DeclareModule ColorSpectrum
 
  Declare Initialize()
  Declare Requester(Color = -1)
  Declare Reset()
 
  Declare SetTextTitle(Title.s)
  Declare SetTextHue(Hue.s)
  Declare SetTextSaturation(Saturation.s)
  Declare SetTextLightness(Lightness.s)
  Declare SetTextRed(Red.s)
  Declare SetTextGreen(Green.s)
  Declare SetTextBlue(Blue.s)
  Declare SetTextRefresh(Refresh.s)
  Declare SetTextValidate(Validate.s)
  Declare SetTextCancel(Cancel.s)
 
EndDeclareModule

Module ColorSpectrum
 
  Enumeration
   
    #COLOR_SPECTRUM_TARGET_HUE
    #COLOR_SPECTRUM_TARGET_SATURATION
    #COLOR_SPECTRUM_TARGET_LIGHTNESS
    #COLOR_SPECTRUM_TARGET_RED
    #COLOR_SPECTRUM_TARGET_GREEN
    #COLOR_SPECTRUM_TARGET_BLUE
   
    #COLOR_SPECTRUM_TARGET_MAX
   
  EndEnumeration
 
  Enumeration
   
    #COLOR_SPECTRUM_TEXT_HUE
    #COLOR_SPECTRUM_TEXT_SATURATION
    #COLOR_SPECTRUM_TEXT_LIGHTNESS
    #COLOR_SPECTRUM_TEXT_RED
    #COLOR_SPECTRUM_TEXT_GREEN
    #COLOR_SPECTRUM_TEXT_BLUE
    #COLOR_SPECTRUM_TEXT_WIN_TITLE
    #COLOR_SPECTRUM_TEXT_BTN_REFRESH
    #COLOR_SPECTRUM_TEXT_BTN_VALIDATE
    #COLOR_SPECTRUM_TEXT_BTN_CANCEL
   
    #COLOR_SPECTRUM_TEXT_MAX
   
  EndEnumeration
 
  Enumeration
   
    #COLOR_SPECTRUM_BTN_REFRESH
    #COLOR_SPECTRUM_BTN_VALIDATE
    #COLOR_SPECTRUM_BTN_CANCEL
   
    #COLOR_SPECTRUM_BTN_MAX
   
  EndEnumeration
 
  #COLOR_SPECTRUM_SIZE_MAX = 255
 
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< Déclaration des Structures <<<<<
 
  Structure Color
   
    StructureUnion
      Red.a
      Hue.a
    EndStructureUnion
   
    StructureUnion
      Green.a
      Saturation.a
    EndStructureUnion
   
    StructureUnion
      Blue.a
      Lightness.a
    EndStructureUnion
   
  EndStructure
 
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< Les observateurs <<<<<
 
  Macro GetColorRed(ColorA)
   
    ColorA\Red
   
  EndMacro
 
  Macro GetColorHue(ColorA)
   
    ColorA\Hue
   
  EndMacro
 
  Macro GetColorGreen(ColorA)
   
    ColorA\Green
   
  EndMacro
 
  Macro GetColorSaturation(ColorA)
   
    ColorA\Saturation
   
  EndMacro
 
  Macro GetColorBlue(ColorA)
   
    ColorA\Blue
   
  EndMacro
 
  Macro GetColorLightness(ColorA)
   
    ColorA\Lightness
   
  EndMacro
 
  ; <<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< Les mutateurs <<<<<
 
  Macro SetColorRed(ColorA, P_Red)
   
    GetColorRed(ColorA) = P_Red
   
  EndMacro
 
  Macro SetColorHue(ColorA, P_Hue)
   
    GetColorHue(ColorA) = P_Hue
   
  EndMacro
 
  Macro SetColorGreen(ColorA, P_Green)
   
    GetColorGreen(ColorA) = P_Green
   
  EndMacro
 
  Macro SetColorLightness(ColorA, P_Lightness)
   
    GetColorLightness(ColorA) = P_Lightness
   
  EndMacro
 
  Macro SetColorBlue(ColorA, P_Blue)
   
    GetColorBlue(ColorA) = P_Blue
   
  EndMacro
 
  Macro SetColorSaturation(ColorA, P_Saturation)
   
    GetColorSaturation(ColorA) = P_Saturation
   
  EndMacro
 
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< Conversion vers couleur entier long <<<<<
 
  Macro ColorSpectrum_RGB()
   
    (Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_BLUE] << 16 + Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_GREEN] << 8 + Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_RED])
   
  EndMacro
 
  Macro Color_RGB(ColorA)
   
    (GetColorBlue(ColorA) << 16 + GetColorGreen(ColorA) << 8 + GetColorRed(ColorA))
   
  EndMacro
 
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< Conversion RGB vers Hexa <<<<<
 
  Macro ColorSpectrum_RGB_To_Hexa()
   
    RSet(Hex(Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_RED]), 2, "0") + RSet(Hex(Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_GREEN]), 2, "0") + RSet(Hex(Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_BLUE]), 2, "0")
   
  EndMacro
 
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< Min et Max de 3 nombres <<<<<
 
  Macro MinMaxNumber(P_Min, P_Max, P_Number01, P_Number02, P_Number03)
   
    P_Min = P_Number01
   
    If P_Number02 < P_Min
      P_Min = P_Number02
    EndIf
   
    If P_Number03 < P_Min
      P_Min = P_Number03
    EndIf
   
    P_Max = P_Number01
   
    If P_Number02 > P_Max
      P_Max = P_Number02
    EndIf
   
    If P_Number03 > P_Max
      P_Max = P_Number03
    EndIf
   
  EndMacro
 
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< Déclaration de la Structure <<<<<
 
  Structure Instance
   
    HSLRGB.a[#COLOR_SPECTRUM_TARGET_MAX] ; Hue, Saturation, Lightness, Red, Green, Blue
    SafeHSLRGB.a[#COLOR_SPECTRUM_TARGET_MAX] ; SafeHue, SafeSaturation, SafeLightness, SafeRed, SafeGreen, SafeBlue
    BackgroundLayer.i
    SpectrumCanvas.i
    LightnessCanvas.i
    WindowHandle.i
    WindowBackgroundColor.i
    ColorPreviewHandle.i
    Text.s[#COLOR_SPECTRUM_TEXT_MAX]
    TextHandle.i[#COLOR_SPECTRUM_TARGET_MAX]
    StringHandle.i[#COLOR_SPECTRUM_TARGET_MAX]
    ButtonHandle.i[#COLOR_SPECTRUM_BTN_MAX]
   
  EndStructure
 
  Global Instance.Instance
 
  Procedure GetWindowBackgroundColor()
   
    CompilerSelect #PB_Compiler_OS
       
      CompilerCase #PB_OS_Windows
        BackgroundColor = GetSysColor_(#COLOR_3DFACE)
       
      CompilerCase #PB_OS_Linux
        BackgroundColor = RGB(232, 232, 231)
       
      CompilerCase #PB_OS_MacOS
        BackgroundColor = RGB(237, 235, 236)
       
    CompilerEndSelect
   
    ProcedureReturn BackgroundColor
  EndProcedure
 
  Procedure UpdateColorPreviewGadget(GadgetID, Color)
   
    If GetGadgetData(GadgetID) <> #Null
     
      Width = GadgetWidth(GadgetID)
      Height = GadgetHeight(GadgetID)
     
      If StartDrawing(ImageOutput(GetGadgetData(GadgetID)))
       
        Box(0, 0, Width, Height, Color)
        DrawingMode(#PB_2DDrawing_Outlined)
        Box(0, 0, Width, Height, 0)
       
        StopDrawing()
       
        SetGadgetState(GadgetID, ImageID(GetGadgetData(GadgetID)))
       
      EndIf
     
    EndIf
   
  EndProcedure
 
  Procedure ColorPreviewGadget(GadgetID, x.w, y.w, Width.w, Height.w, Color)
   
    GadgetHandle = ImageGadget(GadgetID, x, y, Width, Height, 0)
   
    If GadgetID = #PB_Any
      GadgetID = GadgetHandle
    EndIf
   
    SetGadgetData(GadgetID, CreateImage(#PB_Any, Width, Height))
    UpdateColorPreviewGadget(GadgetID, Color)
   
    ProcedureReturn GadgetHandle
  EndProcedure
 
  Procedure FreeColorPreviewGadget(GadgetID)
   
    If GetGadgetData(GadgetID) <> #Null
      If IsImage(GetGadgetData(GadgetID))
        FreeImage(GetGadgetData(GadgetID))
      EndIf
    EndIf
   
  EndProcedure
 
  Procedure Private_ConvertRM(M1.f, M2.f, HueColor.f)
   
    ; ROUTINE DE CALCUL DE LA COMPOSANTE DE COULEUR.
   
    If HueColor > 360
      HueColor - 360
    EndIf
   
    If HueColor < 0
      HueColor + 360
    EndIf
   
    If HueColor < 60
      M1 = M1 + (M2 - M1) * HueColor / 60
    Else
     
      If HueColor < 180
        M1 = M2
      Else
       
        If HueColor < 240
          M1 = M1 + (M2 - M1) * (240 - HueColor) / 60
        EndIf
       
      EndIf
     
    EndIf
   
    ProcedureReturn M1 * 255
  EndProcedure
 
  Procedure Convert_HSL_To_RGB(HueColor.f, LightnessColor.f, SaturationColor.f, *RGBColorA.Color)
   
    ; ROUTINE DE CONSERTION DU HSL EN RGB.
   
    HueColor = HueColor * 360 / #COLOR_SPECTRUM_SIZE_MAX
    SaturationColor = SaturationColor / #COLOR_SPECTRUM_SIZE_MAX
    LightnessColor = LightnessColor / #COLOR_SPECTRUM_SIZE_MAX
   
    If SaturationColor = 0.0
     
      SetColorRed(*RGBColorA, LightnessColor * #COLOR_SPECTRUM_SIZE_MAX)
      SetColorGreen(*RGBColorA, LightnessColor * #COLOR_SPECTRUM_SIZE_MAX)
      SetColorBlue(*RGBColorA, LightnessColor * #COLOR_SPECTRUM_SIZE_MAX)
     
    Else
     
      If LightnessColor <= 0.5
        M2.f = LightnessColor + LightnessColor * SaturationColor
      Else
        M2 = LightnessColor + SaturationColor - LightnessColor * SaturationColor
      EndIf
     
      M1.f = 2 * LightnessColor - M2
     
      SetColorRed(*RGBColorA, Private_ConvertRm(M1, M2, HueColor + 120))
      SetColorGreen(*RGBColorA, Private_ConvertRm(M1, M2, HueColor))
      SetColorBlue(*RGBColorA, Private_ConvertRm(M1, M2, HueColor - 120))
     
    EndIf
   
  EndProcedure
 
  Procedure Convert_RGB_To_HSL(*RGBColorA.Color, *HSLColorA.Color)
   
    ; ROUTINE DE CONVERTION DU RGB EN HLS.
   
    MinMaxNumber(Min, Max, GetColorRed(*RGBColorA), GetColorGreen(*RGBColorA), GetColorBlue(*RGBColorA))
   
    DeltaMaxMin = Max - Min
    SumMaxMin = Max + Min
   
    LightnessColor.f = SumMaxMin / 510
   
    If Max = Min
     
      HueColor.f = 0
      SaturationColor.f = 0
     
    Else
     
      NormalizedRed = (Max - GetColorRed(*RGBColorA)) / DeltaMaxMin
      NormalizedGreen = (Max - GetColorGreen(*RGBColorA)) / DeltaMaxMin
      NormalizedBlue = (Max - GetColorBlue(*RGBColorA)) / DeltaMaxMin
     
      If LightnessColor <= 0.5
        SaturationColor = DeltaMaxMin / SumMaxMin
      Else
        SaturationColor = DeltaMaxMin / (510 - SumMaxMin)
      EndIf
     
      If GetColorRed(*RGBColorA) = Max
        HueColor = 60 * (6 + NormalizedBlue - NormalizedGreen)
      EndIf
     
      If GetColorGreen(*RGBColorA) = Max
        HueColor = 60 * (2 + NormalizedRed - NormalizedBlue)
      EndIf
     
      If GetColorBlue(*RGBColorA) = Max
        HueColor = 60 * (4 + NormalizedGreen - NormalizedRed)
      EndIf
     
    EndIf
   
    If HueColor = 360
      HueColor = 0
    EndIf
   
    HueColor = HueColor / 360 * #COLOR_SPECTRUM_SIZE_MAX
    LightnessColor = LightnessColor * #COLOR_SPECTRUM_SIZE_MAX
    SaturationColor = SaturationColor * #COLOR_SPECTRUM_SIZE_MAX
   
    SetColorHue(*HSLColorA, Int(HueColor))
    SetColorSaturation(*HSLColorA, Int(SaturationColor))
    SetColorLightness(*HSLColorA, Int(LightnessColor))
   
  EndProcedure
 
  Procedure GenerateColorSpectrumBackgroundLayer()
   
    ; ROUTINE DE PRECALCUL DU SPECTRE DE COULEUR.
   
    Instance\BackgroundLayer = CreateImage(#PB_Any, #COLOR_SPECTRUM_SIZE_MAX + 2, #COLOR_SPECTRUM_SIZE_MAX + 2)
   
    If Instance\BackgroundLayer <> #Null
     
      If StartDrawing(ImageOutput(Instance\BackgroundLayer))
       
        Box(0, 0, #COLOR_SPECTRUM_SIZE_MAX + 2, #COLOR_SPECTRUM_SIZE_MAX + 2, $000000)
       
        For SaturationID = 1 To #COLOR_SPECTRUM_SIZE_MAX
         
          For HueID = 1 To #COLOR_SPECTRUM_SIZE_MAX
           
            Convert_HSL_To_RGB(HueID, #COLOR_SPECTRUM_SIZE_MAX >> 1, SaturationID, RGBColor.Color)
           
            Plot(HueID, (#COLOR_SPECTRUM_SIZE_MAX - SaturationID) + 1, Color_RGB(RGBColor))
           
          Next
         
        Next
       
        StopDrawing()
       
      EndIf
     
    EndIf
   
  EndProcedure
 
  Procedure ColorSpectrum_DrawCross()
   
    ; ROUTINE DE TRACAGE DE LA CROIX DU SPECTRE.
   
    PosX = Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_HUE]
    PosY = #COLOR_SPECTRUM_SIZE_MAX - Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_SATURATION]
   
    If PosX < #COLOR_SPECTRUM_SIZE_MAX
      PosX + 1
    EndIf
   
    If PosY < #COLOR_SPECTRUM_SIZE_MAX
      PosY + 1
    EndIf
   
    Box(PosX - 1, PosY - 9, 3, 5, 0)
    Box(PosX - 1, PosY + 5, 3, 5, 0)
    Box(PosX - 9, PosY - 1, 5, 3, 0)
    Box(PosX + 5, PosY - 1, 5, 3, 0)
   
  EndProcedure
 
  Procedure ColorSpectrum_DrawArrow()
   
    ; ROUTINE DE TRACAGE DE LA BARRE DE LIGHTNESS
   
    y1 = #COLOR_SPECTRUM_SIZE_MAX - Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_LIGHTNESS]
   
    If y1 => #COLOR_SPECTRUM_SIZE_MAX
      y1 = #COLOR_SPECTRUM_SIZE_MAX - 1
    EndIf
   
    x1 = 22
    x2 = 33
    y1 + 1
    y2 = y1 + 5
    y3 = y1 - 5
    xm = (x1 + x2) >> 1
   
    LineXY(x1, y1, x2, y2, 0)
    LineXY(x2, y2, x2, y3, 0)
    LineXY(x2, y3, x1, y1, 0)
    FillArea(xm, y1, 0, 0)
   
  EndProcedure
 
  Procedure ColorSpectrum_SpectrumRedraw()
   
    ; ROUTINE D'AFFICHAGE DU SPECTRE ET CROIX.
   
    If StartDrawing(CanvasOutput(Instance\SpectrumCanvas))
     
      If Instance\BackgroundLayer <> #Null
        DrawImage(ImageID(Instance\BackgroundLayer), 0, 0)
      EndIf
     
      ColorSpectrum_DrawCross()
     
      StopDrawing()
     
      Convert_HSL_To_RGB(Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_HUE], Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_LIGHTNESS], Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_SATURATION], RGBColor.Color)
      UpdateColorPreviewGadget(Instance\ColorPreviewHandle, Color_RGB(RGBColor))
     
    EndIf
   
  EndProcedure
 
  Procedure ColorSpectrum_LightnessRedraw()
   
    ; ROUTINE DE TRACAGE DE LA BARRE LUMIERE.
   
    If StartDrawing(CanvasOutput(Instance\LightnessCanvas))
     
      CurrentLightness = Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_LIGHTNESS]
     
      Box(0, 0, #COLOR_SPECTRUM_SIZE_MAX + 2, #COLOR_SPECTRUM_SIZE_MAX + 2, Instance\WindowBackgroundColor)     
      Box(0, 0, 20, #COLOR_SPECTRUM_SIZE_MAX + 2, $000000)
     
      For LightnessID = 1 To #COLOR_SPECTRUM_SIZE_MAX
       
        Convert_HSL_To_RGB(Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_HUE], LightnessID, Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_SATURATION], RGBColor.Color)
        LineXY(1, (#COLOR_SPECTRUM_SIZE_MAX - LightnessID) + 1, 18, (#COLOR_SPECTRUM_SIZE_MAX - LightnessID) + 1, Color_RGB(RGBColor))
       
      Next
     
      Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_LIGHTNESS] = CurrentLightness
     
      ColorSpectrum_DrawArrow()   
      StopDrawing()
     
      Convert_HSL_To_RGB(Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_HUE], Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_LIGHTNESS], Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_SATURATION], RGBColor.Color)
      UpdateColorPreviewGadget(Instance\ColorPreviewHandle, Color_RGB(RGBColor))
     
    EndIf
   
  EndProcedure
 
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< L'opérateur RefeshHSLColorOutput <<<<<
 
  Procedure RefreshHSLColorOutput()
   
    For TargetID = #COLOR_SPECTRUM_TARGET_HUE To #COLOR_SPECTRUM_TARGET_LIGHTNESS
      SetGadgetText(Instance\StringHandle[TargetID], Str(Instance\HSLRGB[TargetID]))
    Next

  EndProcedure
 
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< L'opérateur RefeshRGBColorOutput <<<<<
 
  Procedure RefreshRGBColorOutput()
   
    Convert_HSL_To_RGB(Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_HUE], Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_LIGHTNESS], Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_SATURATION], RGBColor.Color)
   
    Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_RED] = GetColorRed(RGBColor)
    Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_GREEN] = GetColorGreen(RGBColor)
    Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_BLUE] = GetColorBlue(RGBColor)

    For TargetID = #COLOR_SPECTRUM_TARGET_RED To #COLOR_SPECTRUM_TARGET_BLUE
      SetGadgetText(Instance\StringHandle[TargetID], Str(Instance\HSLRGB[TargetID]))
    Next
   
  EndProcedure
 
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< L'opérateur CatchSafeHSLRGB <<<<<
 
  Procedure CatchSafeHSLRGB()
   
    For TargetID = #COLOR_SPECTRUM_TARGET_HUE To #COLOR_SPECTRUM_TARGET_BLUE
      Instance\SafeHSLRGB[TargetID] = Val(GetGadgetText(Instance\StringHandle[TargetID]))
    Next
   
  EndProcedure
 
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< L'opérateur CatchRGBColorInput <<<<<
 
  Procedure CatchRGBColorInput()
   
    For TargetID = #COLOR_SPECTRUM_TARGET_RED To #COLOR_SPECTRUM_TARGET_BLUE
      Instance\HSLRGB[TargetID]  = Val(GetGadgetText(Instance\StringHandle[TargetID]))
    Next
   
    SetColorRed(RGBColor.Color, Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_RED])
    SetColorGreen(RGBColor, Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_GREEN])
    SetColorBlue(RGBColor, Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_BLUE])
   
    Convert_RGB_To_HSL(RGBColor, HSLColor.Color)
   
    Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_HUE] = GetColorHue(HSLColor)
    Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_SATURATION] = GetColorSaturation(HSLColor)
    Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_LIGHTNESS] = GetColorLightness(HSLColor)
   
  EndProcedure
 
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< L'opérateur RefeshSpectrum <<<<<
 
  Procedure RefeshColorSpectrum()
   
    Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_HUE] = 0
    Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_SATURATION] = 0
    Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_LIGHTNESS] = 127
    Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_RED] = 0
    Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_GREEN] = 0
    Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_BLUE] = 0
   
    ColorSpectrum_SpectrumRedraw()
    ColorSpectrum_LightnessRedraw()
    RefreshHSLColorOutput()
    RefreshRGBColorOutput()
    CatchSafeHSLRGB()
   
  EndProcedure
 
  Procedure ForceColorSpectrumStartColor(Color)
   
    If Color <> - 1
     
      Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_RED] = Red(Color)
      Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_GREEN] = Green(Color)
      Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_BLUE] = Blue(Color)
     
      For TargetID = #COLOR_SPECTRUM_TARGET_RED To #COLOR_SPECTRUM_TARGET_BLUE
        SetGadgetText(Instance\StringHandle[TargetID], Str(Instance\HSLRGB[TargetID]))
      Next
     
      CatchRGBColorInput()
      RefreshHSLColorOutput()
     
    Else
     
      RefreshRGBColorOutput()
      RefreshHSLColorOutput()
     
    EndIf
   
  EndProcedure
 
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< L'opérateur ColorSpectrum_SpectrumCanvas_EventManager <<<<<
 
  Procedure ColorSpectrum_SpectrumCanvas_EventManager()
   
    EventType = EventType()
   
    If EventType = #PB_EventType_LeftButtonDown Or ( EventType = #PB_EventType_MouseMove And GetGadgetAttribute(Instance\SpectrumCanvas, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton)
     
      MouseX = GetGadgetAttribute(Instance\SpectrumCanvas, #PB_Canvas_MouseX)
      MouseY = GetGadgetAttribute(Instance\SpectrumCanvas, #PB_Canvas_MouseY)
     
      If MouseX < 0
        MouseX = 0
      Else
        If MouseX > #COLOR_SPECTRUM_SIZE_MAX
          MouseX = #COLOR_SPECTRUM_SIZE_MAX
        EndIf
       
      EndIf
     
      If MouseY < 0
        MouseY = 0
      Else
        If MouseY > #COLOR_SPECTRUM_SIZE_MAX
          MouseY = #COLOR_SPECTRUM_SIZE_MAX
        EndIf
      EndIf
     
      Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_HUE] = MouseX
      Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_SATURATION] = #COLOR_SPECTRUM_SIZE_MAX - MouseY
     
      ColorSpectrum_SpectrumRedraw()
      ColorSpectrum_LightnessRedraw()
      RefreshHSLColorOutput()
      RefreshRGBColorOutput()
      CatchSafeHSLRGB()
     
    EndIf
   
  EndProcedure
 
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< L'opérateur ColorSpectrum_LightnessCanvas_EventManager <<<<<
 
  Procedure ColorSpectrum_LightnessCanvas_EventManager()
   
    EventType = EventType()
   
    If EventType = #PB_EventType_LeftButtonDown Or (EventType = #PB_EventType_MouseMove And GetGadgetAttribute(Instance\LightnessCanvas, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton)
     
      MouseY = GetGadgetAttribute(Instance\LightnessCanvas, #PB_Canvas_MouseY)
     
      If MouseY < 0
        MouseY = 0
      Else
       
        If MouseY > #COLOR_SPECTRUM_SIZE_MAX
          MouseY = #COLOR_SPECTRUM_SIZE_MAX
        EndIf
       
      EndIf
     
      Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_LIGHTNESS] = #COLOR_SPECTRUM_SIZE_MAX - MouseY
     
      ColorSpectrum_LightnessRedraw()
     
      RefreshHSLColorOutput()
      RefreshRGBColorOutput()
     
      CatchSafeHSLRGB()
     
    EndIf
   
  EndProcedure
 
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< L'opérateur Hue Input Control <<<<<
 
  Procedure ColorSpectrum_Input_Control(Target.b)
   
    EventType = EventType()
   
    If EventType = #PB_EventType_Change
     
      Instance\SafeHSLRGB[Target] = Val(GetGadgetText(Instance\StringHandle[Target]))
     
      If Instance\SafeHSLRGB[Target] < 0
        Instance\SafeHSLRGB[Target] = 0
      EndIf
     
      If Instance\SafeHSLRGB[Target] > 255
        Instance\SafeHSLRGB[Target] = 255
      EndIf
     
      Select Target
         
        Case #COLOR_SPECTRUM_TARGET_HUE, #COLOR_SPECTRUM_TARGET_LIGHTNESS, #COLOR_SPECTRUM_TARGET_SATURATION
          Instance\HSLRGB[Target] = Instance\SafeHSLRGB[Target]
         
        Case #COLOR_SPECTRUM_TARGET_RED, #COLOR_SPECTRUM_TARGET_GREEN, #COLOR_SPECTRUM_TARGET_BLUE
          Instance\HSLRGB[Target] = Instance\SafeHSLRGB[Target]
         
          SetColorRed(RGBColor.Color, Instance\SafeHSLRGB[#COLOR_SPECTRUM_TARGET_RED])
          SetColorGreen(RGBColor, Instance\SafeHSLRGB[#COLOR_SPECTRUM_TARGET_GREEN])
          SetColorBlue(RGBColor, Instance\SafeHSLRGB[#COLOR_SPECTRUM_TARGET_BLUE])
          Convert_RGB_To_HSL(RGBColor, HSLColor.Color)
          Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_HUE] = GetColorHue(HSLColor)
          Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_SATURATION] = GetColorSaturation(HSLColor)
          Instance\HSLRGB[#COLOR_SPECTRUM_TARGET_LIGHTNESS] = GetColorLightness(HSLColor)
         
      EndSelect
     
      ColorSpectrum_SpectrumRedraw()
      ColorSpectrum_LightnessRedraw()
     
    ElseIf EventType = #PB_EventType_LostFocus
     
      SetGadgetText(Instance\StringHandle[Target], Str(Instance\SafeHSLRGB[Target]))
     
    EndIf
   
  EndProcedure
 
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< L'opérateur Initialize <<<<<
 
  Procedure Initialize()
   
    Instance\Text[#COLOR_SPECTRUM_TEXT_WIN_TITLE] = "Color Spectrum"
    Instance\Text[#COLOR_SPECTRUM_TEXT_HUE] = "Hue"
    Instance\Text[#COLOR_SPECTRUM_TEXT_SATURATION] = "Saturation"
    Instance\Text[#COLOR_SPECTRUM_TEXT_LIGHTNESS] = "Lightness"
    Instance\Text[#COLOR_SPECTRUM_TEXT_RED] = "Red"
    Instance\Text[#COLOR_SPECTRUM_TEXT_GREEN] = "Green"
    Instance\Text[#COLOR_SPECTRUM_TEXT_BLUE] = "Blue"
    Instance\Text[#COLOR_SPECTRUM_TEXT_BTN_REFRESH] = "Refresh"
    Instance\Text[#COLOR_SPECTRUM_TEXT_BTN_VALIDATE] = "Validate"
    Instance\Text[#COLOR_SPECTRUM_TEXT_BTN_CANCEL] = "Cancel"
 
  EndProcedure
 
  Procedure SetTextTitle(Title.s)
   
    Instance\Text[#COLOR_SPECTRUM_TEXT_WIN_TITLE] = Title
   
  EndProcedure
 
  Procedure SetTextHue(Hue.s)
   
    Instance\Text[#COLOR_SPECTRUM_TEXT_HUE] = Hue
   
  EndProcedure
 
  Procedure SetTextSaturation(Saturation.s)
   
    Instance\Text[#COLOR_SPECTRUM_TEXT_SATURATION] = Saturation
   
  EndProcedure
 
  Procedure SetTextLightness(Lightness.s)
   
    Instance\Text[#COLOR_SPECTRUM_TEXT_LIGHTNESS] = Lightness
   
  EndProcedure
 
  Procedure SetTextRed(Red.s)
   
    Instance\Text[#COLOR_SPECTRUM_TEXT_RED] = Red
   
  EndProcedure
 
  Procedure SetTextGreen(Green.s)
   
    Instance\Text[#COLOR_SPECTRUM_TEXT_GREEN] = Green
   
  EndProcedure
 
  Procedure SetTextBlue(Blue.s)
   
    Instance\Text[#COLOR_SPECTRUM_TEXT_BLUE] = Blue
   
  EndProcedure
 
  Procedure SetTextRefresh(Refresh.s)
   
    Instance\Text[#COLOR_SPECTRUM_TEXT_BTN_REFRESH] = Refresh
   
  EndProcedure
 
  Procedure SetTextValidate(Validate.s)
   
    Instance\Text[#COLOR_SPECTRUM_TEXT_BTN_VALIDATE] = Validate
   
  EndProcedure
 
  Procedure SetTextCancel(Cancel.s)
   
    Instance\Text[#COLOR_SPECTRUM_TEXT_BTN_CANCEL] = Cancel
   
  EndProcedure
 
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< L'opérateur Reset <<<<<
 
  Procedure Reset()
   
    For HSLRGBID = 0 To #COLOR_SPECTRUM_TARGET_MAX - 1
      Instance\HSLRGB[HSLRGBID] = 0
      Instance\SafeHSLRGB[HSLRGBID] = 0
    Next
   
    If IsImage(Instance\BackgroundLayer)
      FreeImage(Instance\BackgroundLayer)
      Instance\BackgroundLayer = 0
    EndIf
   
    Instance\SpectrumCanvas = 0
    Instance\LightnessCanvas = 0
    Instance\WindowHandle = 0
    Instance\WindowBackgroundColor = 0
    Instance\ColorPreviewHandle = 0
   
    For TextID = 0 To #COLOR_SPECTRUM_TEXT_MAX - 1
      Instance\Text[TextID] = ""
    Next
   
    For Index = 0 To #COLOR_SPECTRUM_TARGET_MAX - 1
      Instance\TextHandle[Index] = 0
      Instance\StringHandle[Index] = 0
    Next
   
    For BtnID = 0 To #COLOR_SPECTRUM_BTN_MAX - 1
      Instance\ButtonHandle[BtnID] = 0
    Next
   
  EndProcedure
 
 
  Procedure Requester(Color = -1)
   
    Instance\WindowHandle = OpenWindow(#PB_Any, 0, 0, #COLOR_SPECTRUM_SIZE_MAX + 197, #COLOR_SPECTRUM_SIZE_MAX + 34+15, Instance\Text[#COLOR_SPECTRUM_TEXT_WIN_TITLE] , #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
   
    If Instance\WindowHandle <> #Null

      Instance\SpectrumCanvas = CanvasGadget(#PB_Any, 5, 5, #COLOR_SPECTRUM_SIZE_MAX + 2, #COLOR_SPECTRUM_SIZE_MAX + 2)
      Instance\LightnessCanvas = CanvasGadget(#PB_Any, #COLOR_SPECTRUM_SIZE_MAX + 15, 5, 35, #COLOR_SPECTRUM_SIZE_MAX + 2)
     

      PosY = 5
     
      For Index = 0 To #COLOR_SPECTRUM_TARGET_MAX - 1
        Instance\TextHandle[Index] = StringGadget(#PB_Any, #COLOR_SPECTRUM_SIZE_MAX + 55, PosY, 95, 34,  Instance\Text[Index], #PB_String_ReadOnly)
        Instance\StringHandle[Index] = StringGadget(#PB_Any, #COLOR_SPECTRUM_SIZE_MAX + 150, PosY, 42, 34, "000")
        PosY + 34
      Next
     
      Instance\ColorPreviewHandle = ColorPreviewGadget(#PB_Any, #COLOR_SPECTRUM_SIZE_MAX + 55, PosY+5, 137, 47, 0)

      PosX = ((#COLOR_SPECTRUM_SIZE_MAX + 197) - 135*3+10) >> 1
     
      For BtnID = 0 To #COLOR_SPECTRUM_BTN_MAX - 1
        Instance\ButtonHandle[BtnID] = ButtonGadget(#PB_Any, PosX, #COLOR_SPECTRUM_SIZE_MAX+10, 135, 34, Instance\Text[BtnID + #COLOR_SPECTRUM_TEXT_BTN_REFRESH])
        PosX + 140
      Next
     
      Instance\WindowBackgroundColor = GetWindowBackgroundColor()
      GenerateColorSpectrumBackgroundLayer()
     
      ForceColorSpectrumStartColor(Color)
      CatchSafeHSLRGB()
      ColorSpectrum_SpectrumRedraw()
      ColorSpectrum_LightnessRedraw()
      ReturnSelectedColor = -1
     
      Repeat
       
        EventID = WaitWindowEvent()
       
        Select EventID
           
          Case #PB_Event_Gadget
           
            Select EventGadget()
               
              Case Instance\SpectrumCanvas
                ColorSpectrum_SpectrumCanvas_EventManager()
               
              Case Instance\LightnessCanvas
                ColorSpectrum_LightnessCanvas_EventManager()
               
              Case Instance\StringHandle[#COLOR_SPECTRUM_TARGET_HUE]
                ColorSpectrum_Input_Control(#COLOR_SPECTRUM_TARGET_HUE)
               
              Case Instance\StringHandle[#COLOR_SPECTRUM_TARGET_LIGHTNESS]
                ColorSpectrum_Input_Control(#COLOR_SPECTRUM_TARGET_LIGHTNESS)
               
              Case Instance\StringHandle[#COLOR_SPECTRUM_TARGET_SATURATION]
                ColorSpectrum_Input_Control(#COLOR_SPECTRUM_TARGET_SATURATION)
               
              Case Instance\StringHandle[#COLOR_SPECTRUM_TARGET_RED]
                ColorSpectrum_Input_Control(#COLOR_SPECTRUM_TARGET_RED)
               
              Case Instance\StringHandle[#COLOR_SPECTRUM_TARGET_GREEN]
                ColorSpectrum_Input_Control(#COLOR_SPECTRUM_TARGET_GREEN)
               
              Case Instance\StringHandle[#COLOR_SPECTRUM_TARGET_BLUE]
                ColorSpectrum_Input_Control(#COLOR_SPECTRUM_TARGET_BLUE)
               
              Case Instance\ButtonHandle[#COLOR_SPECTRUM_BTN_REFRESH]
                RefeshColorSpectrum()
               
              Case Instance\ButtonHandle[#COLOR_SPECTRUM_BTN_VALIDATE]
                ReturnSelectedColor = ColorSpectrum_RGB()
                EventID = #PB_Event_CloseWindow
               
              Case Instance\ButtonHandle[#COLOR_SPECTRUM_BTN_CANCEL]
                EventID = #PB_Event_CloseWindow
               
            EndSelect
           
        EndSelect
       
      Until EventID = #PB_Event_CloseWindow
     
      If IsImage(Instance\BackgroundLayer)
        FreeImage(Instance\BackgroundLayer)
        Instance\BackgroundLayer = 0
      EndIf
     
      FreeColorPreviewGadget(Instance\ColorPreviewHandle)
      CloseWindow(Instance\WindowHandle)
     
    EndIf
   
    ProcedureReturn ReturnSelectedColor
  EndProcedure
 
EndModule

CompilerIf #PB_Compiler_IsMainFile
 
  ColorSpectrum::Initialize()
 
  Color = ColorSpectrum::Requester()
 
  If Color <> -1
    Debug "RGB(" + Str(Red(Color)) + ", " + Str(Green(Color)) + ", " + Str(Blue(Color)) + ")"
  Else
    Debug "The User click the Cancel button"
  EndIf
 
  ; Translation in French
  ColorSpectrum::SetTextTitle("Choix d'une couleur")
  ColorSpectrum::SetTextHue("Teinte")
  ColorSpectrum::SetTextSaturation("Saturation")
  ColorSpectrum::SetTextLightness("Luminosité")
  ColorSpectrum::SetTextRed("Rouge")
  ColorSpectrum::SetTextGreen("Vert")
  ColorSpectrum::SetTextBlue("Bleu")
  ColorSpectrum::SetTextRefresh("Rafraichir")
  ColorSpectrum::SetTextValidate("Sélectionner")
  ColorSpectrum::SetTextCancel("Annuler")
 
 
  Color = ColorSpectrum::Requester()
 
  If Color <> -1
    Debug "RGB(" + Str(Red(Color)) + ", " + Str(Green(Color)) + ", " + Str(Blue(Color)) + ")"
  Else
    Debug "The User click the Cancel button"
  EndIf
 
  ColorSpectrum::Reset()
 
CompilerEndIf

; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<

_________________
The Stone Age did not end due to a shortage of stones !


Last edited by StarBootics on Thu Feb 21, 2019 1:58 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: ColorSpectrum - Module
PostPosted: Thu Feb 21, 2019 4:18 am 
Offline
Enthusiast
Enthusiast

Joined: Mon Nov 25, 2013 6:41 am
Posts: 794
in my mac book x64
It doesn’t work because of this ".l" instead of ".i"


Top
 Profile  
Reply with quote  
 Post subject: Re: ColorSpectrum - Module
PostPosted: Thu Feb 21, 2019 6:17 am 
Offline
Addict
Addict

Joined: Fri Nov 09, 2012 11:04 pm
Posts: 1710
Location: Uttoxeter, UK
@StarBootics ,
I like this, thank you. :D

@mestnyi,
Thank you. I made your suggested changes.

_________________
DE AA EB


Top
 Profile  
Reply with quote  
 Post subject: Re: ColorSpectrum - Module
PostPosted: Thu Feb 21, 2019 12:05 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Apr 25, 2003 5:10 pm
Posts: 513
Location: Doubs - France
Nice StarBootics.

First window is in english and when i validate, French translation appears.
I didn't take a deeper look to your code but for me it will be interresting to get all in French.

:wink:

_________________
A+
Denis


Top
 Profile  
Reply with quote  
 Post subject: Re: ColorSpectrum - Module
PostPosted: Thu Feb 21, 2019 2:00 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jul 07, 2013 11:35 am
Posts: 450
Location: Canada
mestnyi wrote:
in my mac book x64
It doesn’t work because of this ".l" instead of ".i"

Just change that, should work fine now.

Best regards
StarBootics

_________________
The Stone Age did not end due to a shortage of stones !


Top
 Profile  
Reply with quote  
 Post subject: Re: ColorSpectrum - Module
PostPosted: Thu Feb 28, 2019 1:07 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4545
Location: Lyon - France
Works fine on W7 x86, can be usefull
Thanks for sharing 8)

_________________
ImageThe happiness is a road...
Not a destination


Top
 Profile  
Reply with quote  
 Post subject: Re: ColorSpectrum - Module
PostPosted: Sun Mar 31, 2019 8:48 pm 
Offline
User
User
User avatar

Joined: Thu May 28, 2009 9:07 pm
Posts: 27
Location: France
Hello All,

here is the version I'm using now (sorry for my bad English).

Code:
; +======================================================+
; |                                                      |
; +------------------------------------------------------+
; | COPYRIGHT(C)2017-2018, ALL RIGHT RESERVED KOAKDESIGN |
; +--------------+---------------------------------------+
; | Program type | PUREBASIC 5.62 (MODULE)               |
; +--------------+---------------------------------------+
; | VER & REV    | 0.0.4                                 |
; +--------------+---------------------------------------+
; | Program name |                                       |
; +======================================================+

; +======================================================+
; | Original Version: 0.0.4                              |
; +--------------+---------------------------------------+
; | Created by   | GallyHomeCorp                         |
; | Graphix by   | GallyHomeCorp                         |
; +--------------+---------------------------------------+
; | Comments:    |                                       |
; +--------------+                                       |
; |                                                      |
; |                                                      |
; |                                                      |
; +======================================================+

; +======================================================+
; | Système d'Exploitation                               |
; +--------------+---------------------------------------+
; | Window       | Oui                                   |
; | Linux        | Oui                                   |
; | MacOS        | Oui                                   |
; +======================================================+

; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
;- INITIALISATION DES DIRECTIVES DU COMPILEUR.

DisableASM
CompilerIf #PB_Compiler_EnableExplicit
  EnableExplicit
CompilerEndIf

; ****************************************************************************
; ****************************************************************************
; ****************************************************************************

#PB_Event_CustomGadget_Color  = #PB_Event_FirstCustomValue + 102

; ****************************************************************************
; ****************************************************************************
; ****************************************************************************

DeclareModule ColorSelector
  ;
  DisableASM
  CompilerIf #PB_Compiler_EnableExplicit
    EnableExplicit
  CompilerEndIf
  ;
  ;- DECLARATION PUBLIQUES DU MODULE.
  ;
  CompilerIf Defined(PB_Event_CustomGadget_Color, #PB_Constant) = #False
    #PB_Event_CustomGadget_Color = #PB_Event_FirstCustomValue + 102
  CompilerEndIf
  ;
  CompilerIf Defined(_CONVERTRM, #PB_Procedure) = #False
    Declare.l _CONVERTRM(fM1.f, fM2.f, fCH.f)
  CompilerEndIf
  CompilerIf Defined(_RGB_TO_HSL, #PB_Procedure) = #False
    Declare.l _RGB_TO_HSL(red.a, green.a, blue.a, alpha=0)
  CompilerEndIf
  CompilerIf Defined(_HSL_TO_RGB, #PB_Procedure) = #False
    Declare _HSL_TO_RGB(fCH.f, fCL.f, fCS.f, *bCR, *bCG, *bCB)
  CompilerEndIf
  ;
  Declare _CreateGadget       (gadget.i, x.l, y.l)
  Declare _GetGadgetState     (gadget.i)
  Declare _SetGadgetState     (gadget.i, color.i)
  Declare _GetGadgetData      (gadget.i, colortype.s)
  Declare _SetGadgetData      (gadget.i, colortype.s, value.l)
  Declare _DisableGadget      (gadget.i, stat.b)
  Declare _HideGadget         (gadget.i, stat.b)
  Declare _FreeGadget         (gadget.i)
  Declare _GetGadgetBackColor (gadget.i) 
  Declare _SetGadgetBackColor (gadget.i, color.i)
 
EndDeclareModule
;
;
;
Module ColorSelector
  ;
  DisableASM
  CompilerIf #PB_Compiler_EnableExplicit
    EnableExplicit
  CompilerEndIf
  ;
  ;- DECLARATION PRIVES DU MODULE.
  ;
  #COLOR_SELECTOR_SIZE_MAX  = 256
  #COLOR_SELECTOR_LIGHT_PX  = 263
  #COLOR_SELECTOR_LIGHT_PY  = 31
  ;
  CompilerIf #PB_Compiler_OS <> #PB_OS_Windows
    Structure point
      x.l
      y.l
    EndStructure
  CompilerEndIf
  CompilerIf Defined(_WINDOW_BACKGROUND, #PB_Procedure) = #False
    Procedure _WINDOW_BACKGROUND(hwnd.i = 0)
      ;
      ; http://www.purebasic.fr/english/viewtopic.php?p=472982#p472982
      ;
      CompilerSelect #PB_Compiler_OS
        CompilerCase #PB_OS_Windows
          ;
          Protected color = GetSysColor_(#COLOR_WINDOW)
          If color = $FFFFFF Or color=0
            color = GetSysColor_(#COLOR_BTNFACE)
          EndIf
          ProcedureReturn color
          ;
        CompilerCase #PB_OS_Linux
          ;
          Protected *style.GtkStyle, *color.GdkColor
          *style = gtk_widget_get_style_(hwnd)
          *color = *style\bg[0]
          ProcedureReturn RGB(*color\red >> 8, *color\green >> 8, *color\blue >> 8)
          ;
        CompilerCase #PB_OS_MacOS
          ;
          Protected.i color, Rect.NSRect, Image
          Protected.i NSColor = CocoaMessage(#Null, #Null, "NSColor windowBackgroundColor")
          If NSColor
            Rect\size\width = 1
            Rect\size\height = 1
            Image = CreateImage(#PB_Any, 1, 1)
            StartDrawing(ImageOutput(Image))
            CocoaMessage(#Null, NSColor, "drawSwatchInRect:@", @Rect)
            color = Point(0, 0)
            StopDrawing()
            FreeImage(Image)
            ProcedureReturn color
          Else
            ProcedureReturn -1
          EndIf
          ;
      CompilerEndSelect

    EndProcedure
  CompilerEndIf
  Structure _STRUTURE_COLORSELECT
    window.i
    gadget.i
    gadgetid.i
    x.l
    y.l
    position.point
    state.l
    bordercolor.i
    background.i
    disable.b
    actived.b
    hide.b
    bCH.l
    bCS.l
    bCL.l
    bCY.l
    iImage.i
    ;
    lchannel_r.l
    lchannel_g.l
    lchannel_b.l
  EndStructure
  Global.i iimage_selectcolor
  Global.i iimage_selectcross
  Global.i iimage_selectarrow
  Global NewMap _CREATE_COLORSELECT._STRUTURE_COLORSELECT()
  ;
  ;-
  ;
  Procedure.l _CONVERTRM(fM1.f, fM2.f, fCH.f)
    ;
    ;
    ;
    If fCH > 360
      fCH - 360
    ElseIf fCH < 0
      fCH + 360
    EndIf
    ;
    If fCH < 60
      fM1 = fM1 + (fM2 - fM1) * fCH / 60
    ElseIf fCH < 180
      fM1 = fM2
    ElseIf fCH < 240
      fM1 = fM1 + (fM2 - fM1) * (240 - fCH) / 60
    EndIf
    ;
    ;
    ;
    ProcedureReturn fM1 * (#COLOR_SELECTOR_SIZE_MAX - 1)
 
  EndProcedure
  ;
  ;-
  ;
  Procedure.l _RGB_TO_HSL(red.a, green.a, blue.a, alpha=0)
    ;
    ;
    ;
    Protected.f r = red   / 255
    Protected.f g = green / 255
    Protected.f b = blue  / 255
    Protected.f cmax, cmin, h_, c, m, h, s, l
    Protected.l imax, imin
    ;
    If r>=g And r>=b
      imax=1
      cmax=r
    EndIf
    If g>=r And g>=b
      imax=2
      cmax=g
    EndIf
    If b>=r And b>=g
      imax=3
      cmax=b
    EndIf
    If r<=g And r<=b
      imin=1
      cmin=r
    EndIf
    If g<=r And g<=b
      imin=2
      cmin=g
    EndIf
    If b<=r And b<=g
      imin=3
      cmin=b
    EndIf
    c=cmax-cmin
    Select imax
      Case 1
        h_ = Mod((g - b) / c + 6, 6)
      Case 2
        h_ = (b - r) / c + 2
      Case 3
        h_ = (r - g) / c + 4
    EndSelect
    h = h_ / 6
    l = (cmax + cmin) / 2
    If l <> 1
      s = c / (1 - Abs(2 * l - 1))
    Else
      s=0
    EndIf
    ProcedureReturn RGB(h * 255, s * 255, l *255)
   
  EndProcedure
  ;
  Procedure _HSL_TO_RGB(fCH.f, fCL.f, fCS.f, *bCR, *bCG, *bCB)
    ;
    ; ROUTINE DE CONSERTION DU HLS EN RGB.
    ;
    Protected.f fM1, fM2
    ;
    fCH = fCH * 360 / (#COLOR_SELECTOR_SIZE_MAX - 1)
    fCL = fCL       / #COLOR_SELECTOR_SIZE_MAX
    fCS = fCS       / (#COLOR_SELECTOR_SIZE_MAX - 1)
    If fCL < 0.5
      fM2 = fCL + fCL * fCS
    Else
      fM2 = fCL + fCS - fCL * fCS
    EndIf
    fM1 = 2 * fCL - fM2
    ;
    ;
    ;
    If fCS = 0
      PokeL(*bCR, fCL * 255)
      PokeL(*bCG, fCL * 255)
      PokeL(*bCB, fCL * 255)
    Else
      PokeL(*bCR, _CONVERTRM(fM1, fM2, fCH + 120))
      PokeL(*bCG, _CONVERTRM(fM1, fM2, fCH      ))
      PokeL(*bCB, _CONVERTRM(fM1, fM2, fCH - 120))
    EndIf
 
  EndProcedure
  ;
  ;-
  ;
  Procedure CUSTUMGadget_ColorCross(lX.l, lY.l)
    ;
    ; ROUTINE DE TRACAGE DE LA CROIX DU PAN/TILT.
    ;
    If IsImage(iimage_selectcross) = 0
      iimage_selectcross = CreateImage(#PB_Any, (lX * 2) + 1, (lY * 2) + 1, 32, #PB_Image_Transparent)
      If IsImage(iimage_selectcross)
        If StartDrawing(ImageOutput(iimage_selectcross)) 
          DrawingMode(#PB_2DDrawing_AllChannels)
          Box(lX - 1, lY - 9, 3, 5,   $FF010101)
          Box(lX - 1, lY + 5, 3, 5,   $FF010101)
          Box(lX - 9, lY - 1, 5, 3,   $FF010101)
          Box(lX + 5, lY - 1, 5, 3,   $FF010101)
          Box(lX - 3, lY - 3, 7, 7,   $FF010101)
          Box(lX - 1, lY - 1, 3, 3,   $000000FF)
          StopDrawing()
        EndIf
      EndIf
    EndIf
   
  EndProcedure

  Procedure CUSTUMGadget_ColorArrow(lX.l, lY.l)
    ;
    ;
    ;
    If IsImage(iimage_selectarrow) = 0
      iimage_selectarrow = CreateImage(#PB_Any, 6, 11, 32, #PB_Image_Transparent)
      If IsImage(iimage_selectarrow)
        If StartDrawing(ImageOutput(iimage_selectarrow))
          DrawingMode(#PB_2DDrawing_AlphaChannel)
          Box ( 0,        0,      6,     11,     RGBA(255, 255, 255, 0))
          DrawingMode(#PB_2DDrawing_AlphaBlend)
          Line(lX,       lY,      5,     -5,     $FF444444)
          Line(lX,       lY,      5,      5,     $FF444444)
          LineXY(lX + 5, lY - 5, lX + 5, lY + 5, $FF444444)
          FillArea(lX + 2, lY, $FF444444, $FF444444)
          StopDrawing()
        EndIf
      EndIf
    EndIf
 
  EndProcedure

  Procedure CUSTUMGadget_ColorBox()
    ;
    ; ROUTINE DE PRECALCUL DU SPECTRE DE COULEUR.
    ;
    Protected.l lH, lS
    Protected.l bCR, bCG, bCB
   
    If IsImage(iimage_selectcolor) = 0
      iimage_selectcolor = CreateImage(#PB_Any,  #COLOR_SELECTOR_SIZE_MAX + 2,  #COLOR_SELECTOR_SIZE_MAX + 2, 24, $0)
      If IsImage(iimage_selectcolor)
        If StartDrawing(ImageOutput(iimage_selectcolor))
          For lS = 1 To #COLOR_SELECTOR_SIZE_MAX
           For lH = 1 To #COLOR_SELECTOR_SIZE_MAX
             _HSL_TO_RGB (lH - 1, (#COLOR_SELECTOR_SIZE_MAX - 1) / 2, lS, @bCR, @bCG, @bCB)
             Plot(lH, (#COLOR_SELECTOR_SIZE_MAX - lS) + 1, RGB(bCR, bCG, bCB))
           Next lH
          Next lS
          StopDrawing()
        EndIf
      EndIf
    EndIf
 
  EndProcedure

  Procedure CUSTUMGadget_DrawColorLight(gadget.i)
    ;
    ; ROUTINE DE TRACAGE DE LA BARRE LUMIERE.
    ;
    Protected.l j, bCR, bCG, bCB
    Protected.f fpas = 255 / 216
    ;
    If FindMapElement(_CREATE_COLORSELECT(), Str(gadget)) <> #Null
      If IsImage(_CREATE_COLORSELECT()\iImage)
        FreeImage(_CREATE_COLORSELECT()\iImage)
      EndIf
      _CREATE_COLORSELECT()\iImage = CreateImage(#PB_Any,  27, #COLOR_SELECTOR_SIZE_MAX - 27)
      If IsImage(_CREATE_COLORSELECT()\iImage)
        If StartDrawing(ImageOutput(_CREATE_COLORSELECT()\iImage))
          DrawingMode(#PB_2DDrawing_Default)
          Box(0, 0, 27, #COLOR_SELECTOR_SIZE_MAX - 27, _CREATE_COLORSELECT()\background)
          DrawingMode(#PB_2DDrawing_Outlined)
          Box(0, 4, 19, #COLOR_SELECTOR_SIZE_MAX - 37 , _CREATE_COLORSELECT()\bordercolor)
          ;
          For j = 0 To #COLOR_SELECTOR_SIZE_MAX - 40
            _HSL_TO_RGB(_CREATE_COLORSELECT()\bCH, j * fpas, _CREATE_COLORSELECT()\bCS, @bCR, @bCG, @bCB)
            LineXY(1, (#COLOR_SELECTOR_SIZE_MAX - 40 + 5) - j, 17, (#COLOR_SELECTOR_SIZE_MAX - 40 + 5) - j, RGB(bCR, bCG, bCB))
          Next j
          ;
          DrawingMode(#PB_2DDrawing_Default)
          LineXY(19,  5,  22,   5, _CREATE_COLORSELECT()\bordercolor)
          LineXY(19, 221, 22, 221, _CREATE_COLORSELECT()\bordercolor)
          LineXY(19, ((#COLOR_SELECTOR_SIZE_MAX - 27) / 2) - 1, 22, ((#COLOR_SELECTOR_SIZE_MAX - 27) / 2) - 1, _CREATE_COLORSELECT()\bordercolor)
          ;
          StopDrawing()
        EndIf
      EndIf
    EndIf
 
  EndProcedure

  Procedure CUSTUMGadget_DrawColorselect(gadget.i)
    ;
    ; ROUTINE DE TRACAGE DU .
    ;
    Protected.l iCR, iCG, iCB
    Protected.l x, y, j
    ;
    If FindMapElement(_CREATE_COLORSELECT(), Str(gadget)) <> #Null
      _HSL_TO_RGB (_CREATE_COLORSELECT()\bCH, _CREATE_COLORSELECT()\bCL, _CREATE_COLORSELECT()\bCS, @iCR, @iCG, @iCB)
      ;
      If _CREATE_COLORSELECT()\actived = #True And IsGadget(_CREATE_COLORSELECT()\gadget)
        If StartDrawing(CanvasOutput(_CREATE_COLORSELECT()\gadget))
          DrawingMode(#PB_2DDrawing_Default)
          Box(0, 0, 290, 258, _CREATE_COLORSELECT()\background)
          ;
          If IsImage(iimage_selectcolor)
            DrawImage(ImageID(iimage_selectcolor), 0, 0)
          EndIf
          If IsImage(iimage_selectcross)
            DrawAlphaImage(ImageID(iimage_selectcross), _CREATE_COLORSELECT()\position\x - 9, _CREATE_COLORSELECT()\position\y - 9)
          EndIf
          Box(258, 0, 290, 258, _CREATE_COLORSELECT()\background)
          ;
          Box(262, 0, 28, 28, _CREATE_COLORSELECT()\bordercolor)
          Box(263, 1, 26, 26, RGB(iCR, iCG, iCB))
          If IsImage(_CREATE_COLORSELECT()\iImage)
            DrawImage(ImageID(_CREATE_COLORSELECT()\iImage), #COLOR_SELECTOR_LIGHT_PX, #COLOR_SELECTOR_LIGHT_PY)
          EndIf
          If IsImage(iimage_selectarrow)
            DrawAlphaImage(ImageID(iimage_selectarrow), #COLOR_SELECTOR_LIGHT_PX + 21, #COLOR_SELECTOR_LIGHT_PY + _CREATE_COLORSELECT()\bCY - 5)
          EndIf
          DrawingMode(#PB_2DDrawing_Outlined)
          Box(0, 0, #COLOR_SELECTOR_SIZE_MAX + 2, #COLOR_SELECTOR_SIZE_MAX + 2, $606060)
          ;
          If _CREATE_COLORSELECT()\disable = #True
            DrawingMode(#PB_2DDrawing_AlphaBlend)
            Box(0, 0, 290, 258, RGBA(Red(_CREATE_COLORSELECT()\background), Green(_CREATE_COLORSELECT()\background), Blue(_CREATE_COLORSELECT()\background), 144))
          EndIf
          StopDrawing()
        EndIf
      EndIf
    EndIf
 
  EndProcedure
  ;
  ;-
  ;
  Procedure _OnEvent_SCANBORDERS(lvalue.l, lmin.l, lmax.l)
    ;
    ;
    ;
    If lvalue < lmin
      lvalue = lmin
    ElseIf lvalue > lmax
      lvalue = lmax
    EndIf
    ;
    ProcedureReturn lvalue
 
  EndProcedure
  ;
  Procedure _OnEvent_CUSTUMCOLOR()
    ;
    ;
    ;
    Protected.i event  = EventType  ()
    Protected.i gadget = EventGadget()
    Protected.i _SAV_MOUSE_X, _SAV_MOUSE_Y
    Static.b _SAV_MOUSE_CLIC, _SAV_CAPTURE
    ;
    If FindMapElement(_CREATE_COLORSELECT(), Str(gadget)) <> #Null
      If GetGadgetAttribute(gadget, #PB_Canvas_WheelDelta)
        ;
        If _CREATE_COLORSELECT()\disable = #False
          _CREATE_COLORSELECT()\bCL + GetGadgetAttribute(gadget, #PB_Canvas_WheelDelta)
          _CREATE_COLORSELECT()\bCL = _OnEvent_SCANBORDERS(_CREATE_COLORSELECT()\bCL, 0, #COLOR_SELECTOR_SIZE_MAX)
          _CREATE_COLORSELECT()\bCY = 221 - Round(_CREATE_COLORSELECT()\bCL / (256 / 216), #PB_Round_Up)
          ;
          PostEvent(#PB_Event_CustomGadget_Color, _CREATE_COLORSELECT()\window, _CREATE_COLORSELECT()\gadget)
          CUSTUMGadget_DrawColorselect(_CREATE_COLORSELECT()\gadget)
          ;
          ProcedureReturn
        EndIf
        ;
      EndIf
      If event = #PB_EventType_LeftButtonDown Or (event = #PB_EventType_MouseMove And GetGadgetAttribute(gadget, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton) And _SAV_CAPTURE = #True
        _SAV_CAPTURE = #True
        ;
        _SAV_MOUSE_X  = GetGadgetAttribute(gadget, #PB_Canvas_MouseX)
        _SAV_MOUSE_Y  = GetGadgetAttribute(gadget, #PB_Canvas_MouseY)
        ;
        If _SAV_MOUSE_CLIC = 0
          If _SAV_MOUSE_X >= 0 And _SAV_MOUSE_Y >= 0 And _SAV_MOUSE_X <= #COLOR_SELECTOR_SIZE_MAX And _SAV_MOUSE_Y <= #COLOR_SELECTOR_SIZE_MAX
            _SAV_MOUSE_CLIC = 1
          EndIf
          If _SAV_MOUSE_X >= #COLOR_SELECTOR_LIGHT_PX And _SAV_MOUSE_Y >= #COLOR_SELECTOR_LIGHT_PY And _SAV_MOUSE_X <= #COLOR_SELECTOR_LIGHT_PX + 17 And _SAV_MOUSE_Y <= #COLOR_SELECTOR_LIGHT_PY + (#COLOR_SELECTOR_SIZE_MAX - 27)
            _SAV_MOUSE_CLIC = 2
          EndIf
        EndIf
        ;
        If _SAV_MOUSE_CLIC <> 0
          If _CREATE_COLORSELECT()\disable = #False
            If _SAV_MOUSE_CLIC = 1
              _SAV_MOUSE_X  = _OnEvent_SCANBORDERS(_SAV_MOUSE_X, 1, #COLOR_SELECTOR_SIZE_MAX)
              _SAV_MOUSE_Y  = _OnEvent_SCANBORDERS(_SAV_MOUSE_Y, 1, #COLOR_SELECTOR_SIZE_MAX)
              ;
              _CREATE_COLORSELECT()\position\x  = _SAV_MOUSE_X
              _CREATE_COLORSELECT()\position\y  = _SAV_MOUSE_Y
              _CREATE_COLORSELECT()\bCH         = _CREATE_COLORSELECT()\position\x - 1
              _CREATE_COLORSELECT()\bCS         = #COLOR_SELECTOR_SIZE_MAX - _CREATE_COLORSELECT()\position\y
              ;
              CUSTUMGadget_DrawColorLight (_CREATE_COLORSELECT()\gadget)
            EndIf
            If _SAV_MOUSE_CLIC = 2
              _SAV_MOUSE_Y  = _OnEvent_SCANBORDERS(_SAV_MOUSE_Y, #COLOR_SELECTOR_LIGHT_PY + 5, #COLOR_SELECTOR_LIGHT_PY + (#COLOR_SELECTOR_SIZE_MAX - 35))
              ;
              _CREATE_COLORSELECT()\bCY = (_SAV_MOUSE_Y - #COLOR_SELECTOR_LIGHT_PY)
              _CREATE_COLORSELECT()\bCL = 256 - Int(((_SAV_MOUSE_Y - #COLOR_SELECTOR_LIGHT_PY) - 5) * (256 / 216))
            EndIf
            ;
            If _SAV_MOUSE_CLIC <> 0
              PostEvent(#PB_Event_CustomGadget_Color, _CREATE_COLORSELECT()\window, _CREATE_COLORSELECT()\gadget)
            EndIf
            CUSTUMGadget_DrawColorselect(_CREATE_COLORSELECT()\gadget)
            ;
          EndIf
        EndIf
        ;
      Else
        If _SAV_MOUSE_CLIC <> 0
            _SAV_MOUSE_CLIC = 0
        EndIf
        If event = #PB_EventType_MouseLeave
          _SAV_CAPTURE = #False
        EndIf
      EndIf
    EndIf
   
  EndProcedure
  ;
  ;-
  ;
  Procedure _CreateGadget(gadget.i, x.l, y.l)
    ;
    ;
    ;
    Protected.i ivalue
    ;
    ;
    ;
    If gadget = #PB_Any
      gadget = CanvasGadget(#PB_Any, x, y, 290, 258, #PB_Container_BorderLess | #PB_Canvas_Keyboard)
      ivalue = gadget
    Else
      ivalue = CanvasGadget(gadget,  x, y, 290, 258, #PB_Container_BorderLess | #PB_Canvas_Keyboard)
    EndIf
    AddMapElement(_CREATE_COLORSELECT(), Str(gadget), #PB_Map_ElementCheck)
    ;
    ;
    ;
    _CREATE_COLORSELECT()\window        = GetActiveWindow()
    _CREATE_COLORSELECT()\gadget        = gadget
    _CREATE_COLORSELECT()\gadgetid      = ivalue
    _CREATE_COLORSELECT()\x             = x
    _CREATE_COLORSELECT()\y             = y
    _CREATE_COLORSELECT()\position\x    = _CREATE_COLORSELECT()\bCH + 1
    _CREATE_COLORSELECT()\position\y    = #COLOR_SELECTOR_SIZE_MAX - _CREATE_COLORSELECT()\bCS
    _CREATE_COLORSELECT()\disable       = #False
    _CREATE_COLORSELECT()\actived       = #True
    _CREATE_COLORSELECT()\state         = 2
    ;
    _CREATE_COLORSELECT()\bordercolor   = $505050
    CompilerIf #PB_Compiler_OS = #PB_OS_Windows
      _CREATE_COLORSELECT()\background  = _WINDOW_BACKGROUND(#Null)
    CompilerElse
      _CREATE_COLORSELECT()\background  = _WINDOW_BACKGROUND(WindowID(_CREATE_COLORSELECT()\window))
    CompilerEndIf
    ;
    _CREATE_COLORSELECT()\bCH           = 0
    _CREATE_COLORSELECT()\bCS           = 0
    _CREATE_COLORSELECT()\bCL           = 0
    _CREATE_COLORSELECT()\bCY           = 216 - Int(_CREATE_COLORSELECT()\bCL * (216 / 255)) + 5
    ;
    ;
    ;
    CUSTUMGadget_DrawColorLight (_CREATE_COLORSELECT()\gadget)
    CUSTUMGadget_DrawColorselect(_CREATE_COLORSELECT()\gadget)
    ;
    BindGadgetEvent (_CREATE_COLORSELECT()\gadget, @_OnEvent_CUSTUMCOLOR(), #PB_All)
    ;
    ProcedureReturn ivalue
 
  EndProcedure
 
  Procedure _GetGadgetState(gadget.i)
    ;
    ;
    ;
    Protected.l iCR, iCG, iCB
    ;
    If FindMapElement(_CREATE_COLORSELECT(), Str(gadget)) <> #Null
      _HSL_TO_RGB (_CREATE_COLORSELECT()\bCH, _CREATE_COLORSELECT()\bCL, _CREATE_COLORSELECT()\bCS, @iCR, @iCG, @iCB)
      ProcedureReturn RGB(iCR, iCG, iCB)
    EndIf
   
  EndProcedure
 
  Procedure _SetGadgetState(gadget.i, color.i)
    ;
    ;
    ;
   
  EndProcedure
 
  Procedure _GetGadgetBackColor(gadget.i)
    ;
    ;
    ;
    If FindMapElement(_CREATE_COLORSELECT(), Str(gadget)) <> #Null
      ProcedureReturn _CREATE_COLORSELECT()\background
    EndIf
   
  EndProcedure
 
  Procedure _SetGadgetBackColor(gadget.i, color.i)
    ;
    ;
    ;
    If FindMapElement(_CREATE_COLORSELECT(), Str(gadget)) <> #Null
      _CREATE_COLORSELECT()\background = color
      CUSTUMGadget_DrawColorLight (_CREATE_COLORSELECT()\gadget)
      CUSTUMGadget_DrawColorselect(_CREATE_COLORSELECT()\gadget)
    EndIf

  EndProcedure
 
  Procedure _GetGadgetData(gadget.i, colortype.s)
    ;
    ; ROUTINE DE RECUPERATION DU LA VALEUR DU SLIDER.
    ;
    If FindMapElement(_CREATE_COLORSELECT(), Str(gadget)) <> #Null
      Select LCase(colortype)
        Case "red"
          ProcedureReturn _CREATE_COLORSELECT()\lchannel_r
        Case "green"
          ProcedureReturn _CREATE_COLORSELECT()\lchannel_g
        Case "blue"
          ProcedureReturn _CREATE_COLORSELECT()\lchannel_b
      EndSelect
    EndIf
 
  EndProcedure

  Procedure _SetGadgetData(gadget.i, colortype.s, value.l)
    ;
    ; ROUTINE DE CHANGEMENT DE LA VALEUR DU SLIDER.
    ;
    If FindMapElement(_CREATE_COLORSELECT(), Str(gadget)) <> #Null
      Select LCase(colortype)
        Case "red"
          _CREATE_COLORSELECT()\lchannel_r = value
        Case "green"
          _CREATE_COLORSELECT()\lchannel_g = value
        Case "blue"
          _CREATE_COLORSELECT()\lchannel_b = value
      EndSelect
    EndIf
 
  EndProcedure

  Procedure _DisableGadget(gadget.i, value.b)
    ;
    ;
    ;
    If FindMapElement(_CREATE_COLORSELECT(), Str(gadget)) <> #Null
      _CREATE_COLORSELECT()\disable = value
      ;
      CUSTUMGadget_DrawColorselect(_CREATE_COLORSELECT()\gadget)
    EndIf
 
  EndProcedure

  Procedure _HideGadget(gadget.i, value.b)
    ;
    ;
    ;
    If FindMapElement(_CREATE_COLORSELECT(), Str(gadget)) <> #Null
      _CREATE_COLORSELECT()\hide = value
      HideGadget(gadget, value)
    EndIf
 
  EndProcedure

  Procedure _FreeGadget(gadget.i)
    ;
    ;
    ;
    If FindMapElement(_CREATE_COLORSELECT(), Str(gadget)) <> #Null
      UnbindGadgetEvent(_CREATE_COLORSELECT()\gadget, @_OnEvent_CUSTUMCOLOR())
      ;
      FreeGadget(_CREATE_COLORSELECT()\gadget)
      DeleteMapElement(_CREATE_COLORSELECT(), Str(gadget))
    EndIf
 
  EndProcedure
  ;
  CUSTUMGadget_ColorBox   ()
  CUSTUMGadget_ColorArrow (0, 5)
  CUSTUMGadget_ColorCross (9, 9)

EndModule

; ; ****************************************************************************
; ; ****************************************************************************
; ; ****************************************************************************
; ;-
; ;- ROUTINE DE TEST DES FONCTIONS (MODULE).
;
CompilerIf #PB_Compiler_IsMainFile = 1
 
  Define.l event, i, j = 1
  Define.b aa, ba, ab, bb
  OpenWindow   (0, 0, 0, 640, 425, "Custum Gadget", #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
 
 
  Define a =      ColorSelector::_CreateGadget(#PB_Any, 10,  10)
  Define b =      ColorSelector::_CreateGadget(#PB_Any, 340, 10)

  ButtonGadget(10, 10,  280, 150, 40, "hide Selector 1")
  ButtonGadget(11, 10,  322, 150, 40, "hide Selector 2")
  ButtonGadget(12, 162, 280, 150, 40, "Disable Selector 1")
  ButtonGadget(13, 162, 322, 150, 40, "Disable Selector 2")
  ButtonGadget(14, 314, 280, 150, 40, "Delete Selector 1")
  ButtonGadget(15, 314, 322, 150, 40, "Delete Selector 2")
 
  TextGadget  (16, 10, 380, 400, 20, "COLOR: $0")
  TextGadget  (17, 10, 405, 400, 20, "COLOR: $0")
 
  Repeat
    event = WaitWindowEvent(10)
    If event = #PB_Event_Gadget
      Select EventGadget()
        Case 10
          aa ! 1
          ColorSelector::_HideGadget(a, aa)
        Case 11
          ba ! 1
          ColorSelector::_HideGadget(b, ba)
        Case 12
          ab ! 1
          ColorSelector::_DisableGadget(a, ab)
        Case 13
          bb ! 1
          ColorSelector::_DisableGadget(b, bb)
        Case 14
          ColorSelector::_FreeGadget(a)
        Case 15
          ColorSelector::_FreeGadget(b)
      EndSelect
    EndIf
    If event = #PB_Event_CustomGadget_Color
      Select EventGadget()
        Case a
          SetGadgetText(16, "COLOR: $" + Hex(ColorSelector::_GetGadgetState(a)))
        Case b
          SetGadgetText(17, "COLOR: $" + Hex(ColorSelector::_GetGadgetState(b)))
      EndSelect
    EndIf
  Until event = #PB_Event_CloseWindow

CompilerEndIf

cordially,
GallyHC

_________________
GallyHC
http://www.koakdesign.info


Last edited by gally on Sun Mar 31, 2019 9:12 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: ColorSpectrum - Module
PostPosted: Sun Mar 31, 2019 9:03 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jul 07, 2013 11:35 am
Posts: 450
Location: Canada
Hello gally,

Your code don't work under Linux. There is a problem with this line :
Code:
_CREATE_COLORSELECT()\background  = _WINDOW_BACKGROUND(WindowID(_CREATE_SLIDER()\window))

Quote:
[15 :58 :12] [COMPILER] Ligne 575: _CREATE_SLIDER() is Not a function, Array, List, Map Or Macro.

Best regards
StarBootics

_________________
The Stone Age did not end due to a shortage of stones !


Top
 Profile  
Reply with quote  
 Post subject: Re: ColorSpectrum - Module
PostPosted: Sun Mar 31, 2019 9:19 pm 
Offline
User
User
User avatar

Joined: Thu May 28, 2009 9:07 pm
Posts: 27
Location: France
thank you

Just a little forgetfulness, and I had not retested for Linux. I corrected in the post.

Code:
_CREATE_COLORSELECT()\background  = _WINDOW_BACKGROUND(WindowID(_CREATE_COLORSELECT()\window))


I'm tested in my virtual machine in linux.

Best regards
GallyHC

_________________
GallyHC
http://www.koakdesign.info


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye