Modify

Opened 14 years ago

Closed 14 years ago

#1399 closed Bug (Fixed)

_ColorSetRGB() is returning wrong color value

Reported by: Beege Owned by: Jpm
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 Changed 14 years ago by Beege

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.

comment:2 Changed 14 years ago by Jpm

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:3 Changed 14 years ago by Beege

Yes I very much agree. I was going to ask for that next. :)

comment:4 Changed 14 years ago by Jon

  • Milestone set to 3.3.3.3
  • Owner changed from Gary to Jon
  • Resolution set to Fixed
  • Status changed from new to closed

Fixed by revision [5567] in version: 3.3.3.3

comment:5 Changed 14 years ago by Jon

Fixed by revision [5568] in version: 3.3.3.3

comment:6 Changed 14 years ago by Jon

  • Resolution Fixed deleted
  • Status changed from closed to reopened

comment:7 Changed 14 years ago by Jon

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 Changed 14 years ago by Jon

  • Milestone changed from 3.3.3.3 to Future Release

comment:9 Changed 14 years ago by TicketCleanup

  • Milestone Future Release deleted

Automatic ticket cleanup.

comment:10 Changed 14 years ago by Beege

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 Changed 14 years ago by Jpm

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 Changed 14 years ago by Jpm

  • Milestone set to 3.3.7.0
  • Owner changed from Jon to Jpm
  • Resolution set to Fixed
  • Status changed from reopened to closed

Fixed by revision [5811] in version: 3.3.7.0

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The owner will remain Jpm.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.