Advertisement
AZJIO

HSB_RGB_BGR - example

Sep 16th, 2011
626
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 4.78 KB | None | 0 0
  1. #include <GUIConstantsEx.au3>
  2. #include <WindowsConstants.au3>
  3. #include <HSB_RGB_BGR.au3>
  4.  
  5. ; При округлении происходит небольшое изменение цвета при двойной конвертации, поэтому внутрение рассчёты лучше не округлять, а вывод в GUI делать с округлением.
  6.  
  7. ; En
  8. $LngTitle = 'Color'
  9. $LngHue = 'Hue'
  10. $LngSaturation = 'Saturation'
  11. $LngBrightness = 'Brightness'
  12. $LngRed = 'Red'
  13. $LngGreen = 'Green'
  14. $LngBlue = 'Blue'
  15.  
  16. ; Ru
  17. ; если русская локализация, то русский язык
  18. If @OSLang = 0419 Then
  19.     $LngTitle = 'Цвет'
  20.     $LngHue = 'Тон'
  21.     $LngSaturation = 'Насыщенность'
  22.     $LngBrightness = 'Яркость'
  23.     $LngRed = 'Красный'
  24.     $LngGreen = 'Зелёный'
  25.     $LngBlue = 'Синий'
  26. EndIf
  27.  
  28. Global $HSB[3] = [60, 45, 100], $RGB[3], $iScale1 = 360, $iScale2 = 100, $iScale3 = 100
  29. $GUI = GUICreate($LngTitle, 340, 270)
  30.  
  31. $iColorLabel = GUICtrlCreateLabel('', 90, 5, 200, 30, $WS_BORDER)
  32. $iNumLabel = GUICtrlCreateLabel('', 20, 12, 70, 17)
  33.  
  34. GUICtrlCreateGroup('HSB', 3, 45, 333, 103)
  35. GUICtrlCreateGroup('RGB', 3, 155, 333, 103)
  36.  
  37. GUICtrlCreateLabel($LngHue, 10, 61, 80, 17)
  38. $iValSld1 = GUICtrlCreateLabel($HSB[0], 300, 60, 30, 17)
  39. $slider1 = GUICtrlCreateSlider(90, 55, 200, 30)
  40. GUICtrlSetLimit(-1, $iScale1, 0)
  41. GUICtrlSetData(-1, $HSB[0])
  42. $hSlider_Handle1 = GUICtrlGetHandle(-1)
  43.  
  44. GUICtrlCreateLabel($LngSaturation, 10, 91, 80, 17)
  45. $iValSld2 = GUICtrlCreateLabel($HSB[1], 300, 90, 30, 17)
  46. $slider2 = GUICtrlCreateSlider(90, 85, 200, 30)
  47. GUICtrlSetLimit(-1, $iScale2, 0)
  48. GUICtrlSetData(-1, $HSB[1])
  49. $hSlider_Handle2 = GUICtrlGetHandle(-1)
  50.  
  51. GUICtrlCreateLabel($LngBrightness, 10, 121, 80, 17)
  52. $iValSld3 = GUICtrlCreateLabel($HSB[2], 300, 120, 30, 17)
  53. $slider3 = GUICtrlCreateSlider(90, 115, 200, 30)
  54. GUICtrlSetLimit(-1, $iScale3, 0)
  55. GUICtrlSetData(-1, $HSB[2])
  56. $hSlider_Handle3 = GUICtrlGetHandle(-1)
  57.  
  58. GUICtrlCreateLabel($LngRed, 10, 171, 80, 17)
  59. $iValSldRGB1 = GUICtrlCreateLabel($HSB[0], 300, 170, 30, 17)
  60. $sliderRGB1 = GUICtrlCreateSlider(90, 165, 200, 30)
  61. GUICtrlSetLimit(-1, 255, 0)
  62. GUICtrlSetData(-1, $HSB[0])
  63. $hSlider_HandleRGB1 = GUICtrlGetHandle(-1)
  64.  
  65. GUICtrlCreateLabel($LngGreen, 10, 201, 80, 17)
  66. $iValSldRGB2 = GUICtrlCreateLabel($HSB[1], 300, 200, 30, 17)
  67. $sliderRGB2 = GUICtrlCreateSlider(90, 195, 200, 30)
  68. GUICtrlSetLimit(-1, 255, 0)
  69. GUICtrlSetData(-1, $HSB[1])
  70. $hSlider_HandleRGB2 = GUICtrlGetHandle(-1)
  71.  
  72. GUICtrlCreateLabel($LngBlue, 10, 231, 80, 17)
  73. $iValSldRGB3 = GUICtrlCreateLabel($HSB[2], 300, 230, 30, 17)
  74. $sliderRGB3 = GUICtrlCreateSlider(90, 225, 200, 30)
  75. GUICtrlSetLimit(-1, 255, 0)
  76. GUICtrlSetData(-1, $HSB[2])
  77. $hSlider_HandleRGB3 = GUICtrlGetHandle(-1)
  78.  
  79. _SetColorRGB()
  80.  
  81. GUISetState()
  82. GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL")
  83.  
  84. Do
  85. Until GUIGetMsg() = -3
  86.  
  87. Func WM_HSCROLL($hWnd, $Msg, $wParam, $lParam)
  88.     #forceref $Msg, $wParam, $lParam
  89.     Local $nScrollCode = BitAND($wParam, 0xFFFF) ; _WinAPI_LoWord
  90.     Local $value = BitShift($wParam, 16) ; _WinAPI_HiWord
  91.  
  92.     If $nScrollCode = 5 Then
  93.         Switch $lParam
  94.             Case $hSlider_Handle1
  95.                 GUICtrlSetData($iValSld1, $value)
  96.                 $HSB[0] = $value
  97.                 _SetColorRGB()
  98.             Case $hSlider_Handle2
  99.                 GUICtrlSetData($iValSld2, $value)
  100.                 $HSB[1] = $value
  101.                 _SetColorRGB()
  102.             Case $hSlider_Handle3
  103.                 GUICtrlSetData($iValSld3, $value)
  104.                 $HSB[2] = $value
  105.                 _SetColorRGB()
  106.             Case $hSlider_HandleRGB1
  107.                 GUICtrlSetData($iValSldRGB1, $value)
  108.                 $RGB[0] = $value
  109.                 _SetColorHSB()
  110.             Case $hSlider_HandleRGB2
  111.                 GUICtrlSetData($iValSldRGB2, $value)
  112.                 $RGB[1] = $value
  113.                 _SetColorHSB()
  114.             Case $hSlider_HandleRGB3
  115.                 GUICtrlSetData($iValSldRGB3, $value)
  116.                 $RGB[2] = $value
  117.                 _SetColorHSB()
  118.         EndSwitch
  119.     EndIf
  120.  
  121.     Return $GUI_RUNDEFMSG
  122. EndFunc
  123.  
  124. Func _SetColorRGB()
  125.     $RGB = _HSB_to_RGB($HSB, 0, $iScale1, $iScale2, $iScale3)
  126.     $a = Hex($RGB[0], 2) & Hex($RGB[1], 2) & Hex($RGB[2], 2)
  127.     GUICtrlSetData($iNumLabel, $a)
  128.     GUICtrlSetBkColor($iColorLabel, Dec($a))
  129.  
  130.     Local $aRGB = $RGB
  131.     _Round($aRGB)
  132.     GUICtrlSetData($iValSldRGB1, $aRGB[0])
  133.     GUICtrlSetData($iValSldRGB2, $aRGB[1])
  134.     GUICtrlSetData($iValSldRGB3, $aRGB[2])
  135.  
  136.     GUICtrlSetData($sliderRGB1, $aRGB[0])
  137.     GUICtrlSetData($sliderRGB2, $aRGB[1])
  138.     GUICtrlSetData($sliderRGB3, $aRGB[2])
  139. EndFunc
  140.  
  141. Func _SetColorHSB()
  142.     $HSB = _RGB_to_HSB($RGB, $iScale1, $iScale2, $iScale3)
  143.     $a = Hex($RGB[0], 2) & Hex($RGB[1], 2) & Hex($RGB[2], 2)
  144.     GUICtrlSetData($iNumLabel, $a)
  145.     GUICtrlSetBkColor($iColorLabel, Dec($a))
  146.  
  147.     Local $aHSB = $HSB
  148.     _Round($aHSB)
  149.     GUICtrlSetData($iValSld1, $aHSB[0])
  150.     GUICtrlSetData($iValSld2, $aHSB[1])
  151.     GUICtrlSetData($iValSld3, $aHSB[2])
  152.  
  153.     GUICtrlSetData($slider1, $aHSB[0])
  154.     GUICtrlSetData($slider2, $aHSB[1])
  155.     GUICtrlSetData($slider3, $aHSB[2])
  156. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement