Jump to content

_GUICtrlCreateGradient - wrong Par Width,height


Recommended Posts

EDIT3: Now I noticed somebody changed my original title from GuiCtrlCreateGraphic to _GUICtrlCreateGradient !!

But problem is really in AutoIt function GuiCtrlCreateGraphic and not in this user function _GUICtrlCreateGradient.

See that parameters $nWidth, $nHeight passed to _GUICtrlCreateGradient function are directly without change passed to GuiCtrlCreateGraphic...

EDIT2: please can somebody correct wrong title of this topic:

there should be GuiCtrlCreateGraphic instead of _GUICtrlCreateGradient

GuiCtrlCreateGraphic:

parameter width acts as right (position of corner of rectangle) and NOT as width

parameter height acts as bottom (position of corner of rectangle) and NOT as height

Here is my example for color rainbow:

#include <Color.au3>

Global $GUI_GR_LINE  = 2
Global $GUI_GR_MOVE  = 6
Global $GUI_GR_COLOR    = 8

$gui = GUICreate("Rainbow",@DesktopWidth -5, @DesktopHeight - 25, 0, 0)
$size = WinGetClientSize($gui)
$step = $size[0] / 6

_GUICtrlCreateGradient(0xFF0000, 0xFFFF00, 0*$step, 0, 1*$step, $size[1])
_GUICtrlCreateGradient(0xFFFF00, 0x00FF00, 1*$step, 0, 2*$step, $size[1])
_GUICtrlCreateGradient(0x00FF00, 0x00FFFF, 2*$step, 0, 3*$step, $size[1])
_GUICtrlCreateGradient(0x00FFFF, 0x0000FF, 3*$step, 0, 4*$step, $size[1])
_GUICtrlCreateGradient(0x0000FF, 0xFF00FF, 4*$step, 0, 5*$step, $size[1])
_GUICtrlCreateGradient(0xFF00FF, 0xFF0000, 5*$step, 0, 6*$step, $size[1])
GUISetState()

While 1
    $msg = GUIGetMsg()
    If $msg = -3 Then Exit
Wend

Func _GUICtrlCreateGradient($nStartColor, $nEndColor, $nX, $nY, $nWidth, $nHeight)
    Local $color1R = _ColorGetRed($nStartColor)
    Local $color1G = _ColorGetGreen($nStartColor)
    Local $color1B = _ColorGetBlue($nStartColor)

    Local $nStepR = (_ColorGetRed($nEndColor) - $color1R) / $step
    Local $nStepG = (_ColorGetGreen($nEndColor) - $color1G) / $step
    Local $nStepB = (_ColorGetBlue($nEndColor) - $color1B) / $step

    GuiCtrlCreateGraphic($nX, $nY, $nWidth, $nHeight)
    For $i = 0 To $nWidth - $nX
        $sColor = "0x" & StringFormat("%02X%02X%02X", $color1R+$nStepR*$i, $color1G+$nStepG*$i, $color1B+$nStepB*$i)
        GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $sColor, 0xffffff)
        GUICtrlSetGraphic(-1, $GUI_GR_MOVE, $i, 0)
        GUICtrlSetGraphic(-1, $GUI_GR_LINE, $i, $nHeight)
    Next
EndFunc

EDIT:

I must use workaround:

_GUICtrlCreateGradient(0xFF0000, 0xFFFF00, (n-1)*$step, 0, n*$step, $size[1])

if width would be really width in GuiCtrlCreateGraphic it should be called like this:

_GUICtrlCreateGradient(0xFF0000, 0xFFFF00, (n-1)*$step, 0, $step, $size[1])

EDIT2: please can somebody correct wrong title of this topic:

there should be GuiCtrlCreateGraphic instead of _GUICtrlCreateGradient

Edited by Zedna
Link to comment
Share on other sites

I just tried this corrected code and it works,

so problem was in script and not in AutoIt!

For $i = 0 To $nWidth - $nX

For $i = 0 To $nWidth

Please delete this post or move it to NO BUG subforum.

And sorry for confusion :)

#include <Color.au3>

Global $GUI_GR_LINE  = 2
Global $GUI_GR_MOVE  = 6
Global $GUI_GR_COLOR    = 8

$gui = GUICreate("Rainbow",@DesktopWidth -5, @DesktopHeight - 25, 0, 0)
$size = WinGetClientSize($gui)
$step = $size[0] / 6

_GUICtrlCreateGradient(0xFF0000, 0xFFFF00, 0*$step, 0, $step, $size[1])
_GUICtrlCreateGradient(0xFFFF00, 0x00FF00, 1*$step, 0, $step, $size[1])
_GUICtrlCreateGradient(0x00FF00, 0x00FFFF, 2*$step, 0, $step, $size[1])
_GUICtrlCreateGradient(0x00FFFF, 0x0000FF, 3*$step, 0, $step, $size[1])
_GUICtrlCreateGradient(0x0000FF, 0xFF00FF, 4*$step, 0, $step, $size[1])
_GUICtrlCreateGradient(0xFF00FF, 0xFF0000, 5*$step, 0, $step, $size[1])
GUISetState()

While 1
    $msg = GUIGetMsg()
    If $msg = -3 Then Exit
Wend

Func _GUICtrlCreateGradient($nStartColor, $nEndColor, $nX, $nY, $nWidth, $nHeight)
    Local $color1R = _ColorGetRed($nStartColor)
    Local $color1G = _ColorGetGreen($nStartColor)
    Local $color1B = _ColorGetBlue($nStartColor)

    Local $nStepR = (_ColorGetRed($nEndColor) - $color1R) / $step
    Local $nStepG = (_ColorGetGreen($nEndColor) - $color1G) / $step
    Local $nStepB = (_ColorGetBlue($nEndColor) - $color1B) / $step

    GuiCtrlCreateGraphic($nX, $nY, $nWidth, $nHeight)
    For $i = 0 To $nWidth
        $sColor = "0x" & StringFormat("%02X%02X%02X", $color1R+$nStepR*$i, $color1G+$nStepG*$i, $color1B+$nStepB*$i)
        GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $sColor, 0xffffff)
        GUICtrlSetGraphic(-1, $GUI_GR_MOVE, $i, 0)
        GUICtrlSetGraphic(-1, $GUI_GR_LINE, $i, $nHeight)
    Next
EndFunc

If you like it fullscreen use:

$gui = GUICreate("Rainbow",@DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP)
Edited by Zedna
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...