Opened 16 years ago
Closed 16 years ago
#1399 closed Bug (Fixed)
_ColorSetRGB() is returning wrong color value
| Reported by: | Beege | Owned by: | J-Paul Mesnage |
|---|---|---|---|
| Milestone: | 3.3.7.0 | Component: | Standard UDFs |
| Version: | 3.3.2.0 | Severity: | None |
| Keywords: | _ColorSetRGB | Cc: |
Description
The documentation of function _ColorSetRGB() states that the parameters of the function should be an array of values in the range 0-255 in the order of [RED,GREEN,BLUE], but in the following example, "[255,0,0]" will return blue instead of red and vice versa for [0,0,255].
|
#Include <GuiRichEdit.au3>
#include <GUIConstantsEx.au3>
#include <Color.au3>
Global $GUI = GUICreate("Form1", 405, 333)
Global $R_Edit = _GUICtrlRichEdit_Create($GUI, "" & @CRLF, 32, 8, 345, 225,$ES_MULTILINE)
GUISetState(@SW_SHOW)
; R , G, B
Global $aRed[3] = [255, 0, 0]
Global $aBlue[3] = [0, 0, 255]
_RichEdit_Color_Append($R_Edit,'RED RED RED', _ColorSetRGB($aRed))
_RichEdit_Color_Append($R_Edit,'BLUE BLUE BLUE', _ColorSetRGB($aBlue))
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
_GUICtrlRichEdit_Destroy($R_Edit)
Exit
EndSwitch
WEnd
Func _RichEdit_Color_Append($hRichEdit, $sMsg, $COLORREF)
_GUICtrlRichEdit_AppendText($hRichEdit, @CRLF & $sMsg)
_GUICtrlRichEdit_SetSel($hRichEdit, _GUICtrlRichEdit_GetFirstCharPosOnLine($hRichEdit), -1, True)
_GUICtrlRichEdit_SetCharColor($hRichEdit, $COLORREF)
EndFunc ;==>_RichEdit_Append
-AutoIt:3.3.2.0 (Os:WIN_7/X86 Language:0409 Keyboard:00000409 Cpu:X64)
|
Fixes could be to reverse the order of the FOR-LOOP in the function or change the documentation to [BLUE,GREEN,RED].
Attachments (0)
Change History (12)
comment:1 by , 16 years ago
comment:2 by , 16 years ago
perfectly right the doc should not have mention COLORREF as under all other function as GUI/Pixel the color is 0x00RRGGBB
We miss a function as _ColorSetCOLOREF or we do a script-breaking inside _GUICtrlRichEdit...() functions to use the standard AutoIt iColor which is 0x00RRGGBB
I prefer to add a new _ColorSetCOLOREF function.
Do you agree?
comment:4 by , 16 years ago
| Milestone: | → 3.3.3.3 |
|---|---|
| Owner: | changed from to |
| Resolution: | → Fixed |
| Status: | new → closed |
Fixed by revision [5567] in version: 3.3.3.3
comment:6 by , 16 years ago
| Resolution: | Fixed |
|---|---|
| Status: | closed → reopened |
comment:7 by , 16 years ago
Not quite sure I follow this. ColorSetRGB is clearly broken. Are we saying that we can't fix it because it's already used in other functions?
comment:8 by , 16 years ago
| Milestone: | 3.3.3.3 → Future Release |
|---|
comment:10 by , 16 years ago
From the searching I did, changing ColorSetRGB() would not effect any other functions. I don't see being used anywhere. Also, I don't even think its possible to make _GUICtrlRichEdit...() functions use standard AutoIt iColor since the MSDN states the value must be COLORREF. Perhaps a function similar in style to _ChooseColor() could be made. One that allows the user to specify what kind of color code value they would like returned. Either RGB Hex,BGR Hex, or COLORREF.
|
; R , G, B
Global $aRed[3] = [255, 0, 0]
Global $aBlue[3] = [0, 0, 255]
Global $aPink[3] = [255, 0, 255]
ConsoleWrite('COLORREF Value of Blue = ' & _ColorSetValue($aBlue, 0) & @CRLF);COLORREF
ConsoleWrite('BGR HEX Value of Blue = ' & _ColorSetValue($aBlue, 1) & @CRLF);BGR Hex
ConsoleWrite('RGB HEX Value of Blue = ' & _ColorSetValue($aBlue, 2) & @CRLF & @CRLF);RGB Hex
Func _ColorSetValue($aColor, $iReturn_Type = 0)
If UBound($aColor) <> 3 Then Return SetError(1, 0, -1) ; invalid array
For $i = 0 To 2
If $aColor[$i] < 0 Or $aColor[$i] > 255 Then Return SetError(2, 0, -1);invalad color
Next
Switch $iReturn_Type
Case 0;COLORREF
Return Dec(Hex($aColor[2], 2) & Hex($aColor[1], 2) & Hex($aColor[0], 2))
Case 1;BGR HEX CODE
Return '0x' & Hex($aColor[2], 2) & Hex($aColor[1], 2) & Hex($aColor[0], 2)
Case 2;RGB HEX CODE
Return '0x' & Hex($aColor[0], 2) & Hex($aColor[1], 2) & Hex($aColor[2], 2)
Case Else
Return SetError(3, 0, -1);invalad return type
EndSwitch
EndFunc ;==>_ColorSetValue
comment:11 by , 16 years ago
in fact _ColorSetRGB is coherent with GUI/Pixel functions.
The introduction of a new function with will set as MSDN request is the only way to avoid script-breaking in _GUICtrlRichEdit_...() functions as you mention.
I have a preference to be _ColorSetCOLORREF but why not to have a more general function as _ColorSetValue
comment:12 by , 16 years ago
| Milestone: | → 3.3.7.0 |
|---|---|
| Owner: | changed from to |
| Resolution: | → Fixed |
| Status: | reopened → closed |
Fixed by revision [5811] in version: 3.3.7.0

Sorry I forgot to state that the description of _ColorSetRGB() is "Returns the RGB color to work with (COLORREF)." And the MSDN says that a COLORREF value must be in hex format 0x00BBGGRR.