Jump to content
Sign in to follow this  
gi_jimbo

Possible bug found using GUICtrlSetGraphic $GUI_GR_PENSIZE with $GUI_GR_DOT

Recommended Posts

I believe I've found a bug in  the GUICtrlSetGraphic() function.  In the help documentation it says that $GUI_GR_PENSIZE has to be defined before $GUI_GR_COLOR to be taken into account.  However, when I do this, the "dots" drawn using $GUI_GR_DOT end up looking very thick and clunky.  Maybe this is how it's supposed to work but I noticed that when I don't define $GUI_GR_PENSIZE before $GUI_GR_COLOR, the dot is still drawn with the pensize I wanted but with a nice fine line instead of the thick clunky line.  Unfortunately when I go to draw the next dot, it's thick and clunky again.  The only way I can get around this is to change pensize, draw something else, then switch the pensize back and draw another dot.

Edit: here's my experimental code (derived from GUICtrlSetGraphic.au3 example from the help documentation)

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

Global Const $g_MAXGr = 2
Global $g_aidGraphics[$g_MAXGr + 1] ; 0 and $g_MAXGr entries not used to allow GUICtrlDelete result
Global $g_idDel, $g_hChild

Example()

Func Example()
    Local $idMsg, $iInc, $i

    GUICreate("My Main", -1, -1, 100, 100)
    Local $idReCreate = GUICtrlCreateButton("ReCreate", 50, 200, 50)
    GUISetState(@SW_SHOW)
    CreateChild()

    $i = 1
    $iInc = 1

    Do
        $idMsg = GUIGetMsg()
        If $idMsg = $idReCreate Then $i = Create($iInc)

        If $idMsg = $g_idDel Then
            GUICtrlDelete($g_aidGraphics[$i])
            $i = $i + $iInc
            If $i < 0 Or $i > $g_MAXGr Then Exit
        EndIf
    Until $idMsg = $GUI_EVENT_CLOSE
EndFunc   ;==>Example

Func Create($iInc)
    GUIDelete($g_hChild)
    CreateChild()
    Return 1
EndFunc   ;==>Create

Func CreateChild()
    $g_hChild = GUICreate("My Draw")
    $g_idDel = GUICtrlCreateButton("Delete", 50, 165, 50)

    $g_aidGraphics[1] = GUICtrlCreateGraphic(150, 10, 60, 50)
    GUICtrlSetBkColor(-1, 0xa0ffa0)
    GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 20, 20) ; start point
    ; ugly blue dot
    GUICtrlSetGraphic(-1, $GUI_GR_PENSIZE, 2)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x0000ff)
    GUICtrlSetGraphic(-1, $GUI_GR_DOT, 25, 25)
    ; line 1 (vertical)
    GUICtrlSetGraphic(-1, $GUI_GR_PENSIZE, 1)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0)
    GUICtrlSetGraphic(-1, $GUI_GR_LINE, 20, 40)
    ; nice red dot
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xff0000)
    GUICtrlSetGraphic(-1, $GUI_GR_PENSIZE, 2)
    GUICtrlSetGraphic(-1, $GUI_GR_DOT, 35, 25)
    ; next dot (green) is ugly
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x009900)
    ;GUICtrlSetGraphic(-1, $GUI_GR_PENSIZE, 2) ; still ugly with or without this line
    GUICtrlSetGraphic(-1, $GUI_GR_DOT, 25, 35)
    ; line 2 (horizontal)
    GUICtrlSetGraphic(-1, $GUI_GR_PENSIZE, 1)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0)
    GUICtrlSetGraphic(-1, $GUI_GR_LINE, 40, 40)
    ; dot (black) is nice again
    GUICtrlSetGraphic(-1, $GUI_GR_PENSIZE, 2)
    GUICtrlSetGraphic(-1, $GUI_GR_DOT, 35, 35)
    ; but if I don't change the color, the dots remain nice
    GUICtrlSetGraphic(-1, $GUI_GR_DOT, 45, 35)
    GUICtrlSetGraphic(-1, $GUI_GR_DOT, 55, 35)


    $g_aidGraphics[2] = GUICtrlCreateGraphic(150, 80, 50, 50)
    ;Default code from GUICtrlSetGraphic.au3 example
    GUICtrlSetBkColor(-1, 0xa0ffa0)
    GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 20, 20) ; start point
    ; it is better to draw line and after point
    ; to avoid to switch color at each drawing
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x0000ff)
    GUICtrlSetGraphic(-1, $GUI_GR_DOT, 30, 30)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0)
    GUICtrlSetGraphic(-1, $GUI_GR_LINE, 20, 40)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xff0000)
    GUICtrlSetGraphic(-1, $GUI_GR_DOT, 25, 25)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0)
    GUICtrlSetGraphic(-1, $GUI_GR_LINE, 40, 40)
    GUICtrlSetGraphic(-1, $GUI_GR_DOT, 30, 40)

    GUISetState(@SW_SHOW)
EndFunc   ;==>CreateChild

 

Edited by gi_jimbo
To better explain what's going on.

Jimbo

Using AutoIt v3.3.14.3 and SciTE version 3.7.3

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...