Jump to content

delay in updating input


pillbug
 Share

Recommended Posts

Hi,

I'm having trouble. I am trying to make program that puts images on a graph. Unfortunately, it is delaying by one count. I've look it over and I can't seem to find the mistake, I'm new to GUIs.

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

    Global $del, $child, $numberofshapes = 2, $a[1000]
    Global $height = @DesktopHeight * .90, $width = @DesktopWidth * .90
    Global $xorig = $width * .5, $yorig = $height * .5

    Example()

    Func Example()

        $child = GUICreate("My Draw", $width, $height)

        $del = GUICtrlCreateButton("Delete", $width * .5 + 25, $height * .9, 50)
        $add = GUICtrlCreateButton("Add", $width * .5 - 50, $height * .9, 50)

        $xvalue = GUICtrlCreateInput("0", $width * .5 - 200, $height * .9, 50, 20)
        $yvalue = GUICtrlCreateInput("0", $width * .5 - 150, $height * .9, 50, 20)
        $wvalue = GUICtrlCreateInput("10", $width * .5 - 200, $height * .95, 50, 20)
        $hvalue = GUICtrlCreateInput("10", $width * .5 - 150, $height * .95, 50, 20)



        $bottom = GUICtrlCreateGraphic(-1, $height * .85, $width, $height * .15)
        GUICtrlSetBkColor(-1, 0xffffff)

        $axis = GUICtrlCreateGraphic(-1, -1, $width, $height * .8); Main area

        $xaxis = GUICtrlSetGraphic(-1, $GUI_GR_RECT, $xorig - 150, $yorig, 300, 1); x axis line
        $yaxis = GUICtrlSetGraphic(-1, $GUI_GR_RECT, $xorig, $yorig - 150, 1, 300); y axis line

        For $i = 0 To 300 Step 10
            GUICtrlSetGraphic(-1, $GUI_GR_RECT, $xorig - 5, $i + $yorig - 150, 10, 1); y axis tick marks
            GUICtrlSetGraphic(-1, $GUI_GR_RECT, $i + $xorig - 150, $yorig - 5, 1, 10); x axis tick marks
        Next

        $a[1] = GUICtrlCreateGraphic(-1, 50, 100, 100)
        GUICtrlSetBkColor(-1, 0xffffff);sets background of that specific space
        GUICtrlSetGraphic(-1, $GUI_GR_RECT, 50, 50, 50, 80)


    GUISetState()

        Do
            $msg = GUIGetMsg()

            If $msg = $del Then; deletes a graphic
                GUICtrlDelete($a[$numberofshapes])
                $numberofshapes -= 1
            EndIf

            If $msg = $add Then; addes a graphic
                $x = GUICtrlRead($xvalue)
                $w = GUICtrlRead($wvalue)
                $y = GUICtrlRead($yvalue)
                $h = GUICtrlRead($hvalue)
                $numberofshapes += 1
                $a[$numberofshapes] = GUICtrlCreateGraphic(-1, -1, $width, $height * .8)
                GUICtrlSetGraphic(-1, $GUI_GR_RECT, $xorig - $x - $w / 2, $yorig - $y - $h / 2, $w, $h)

            EndIf
        Until $msg = $GUI_EVENT_CLOSE
        
    EndFunc  ;==>Example
Link to comment
Share on other sites

It's not obvious I admit, but it's due to rounding of your calculations.

Try this

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

Global $del, $child, $numberofshapes = 2, $a[1000]
Global $height = @DesktopHeight * .90, $width = @DesktopWidth * .90
Global $xorig = Floor($width * .5), $yorig = floor($height * .5)

Example ()

Func Example ()

    $child = GUICreate("My Draw", $width, $height)

    $del = GUICtrlCreateButton("Delete", $width * .5 + 25, $height * .9, 50)
    $add = GUICtrlCreateButton("Add", $width * .5 - 50, $height * .9, 50)

    $xvalue = GUICtrlCreateInput("0", $width * .5 - 200, $height * .9, 50, 20)
    $yvalue = GUICtrlCreateInput("0", $width * .5 - 150, $height * .9, 50, 20)
    $wvalue = GUICtrlCreateInput("10", $width * .5 - 200, $height * .95, 50, 20)
    $hvalue = GUICtrlCreateInput("10", $width * .5 - 150, $height * .95, 50, 20)



    $bottom = GUICtrlCreateGraphic(-1, $height * .85, $width, $height * .15)
    GUICtrlSetBkColor(-1, 0xffffff)

    $axis = GUICtrlCreateGraphic(-1, -1, $width, $height * .8); Main area
    GUICtrlSetGraphic(-1, $GUI_GR_MOVE, $xorig - 150, $yorig)
    $xaxis = GUICtrlSetGraphic(-1, $GUI_GR_LINE, $xorig + 150, $yorig); x axis line
    GUICtrlSetGraphic(-1, $GUI_GR_MOVE, $xorig, $yorig - 150)
    $yaxis = GUICtrlSetGraphic(-1, $GUI_GR_LINE, $xorig, $yorig + 150); y axis line

    For $i = 0 To 300 Step 10
        GUICtrlSetGraphic(-1, $GUI_GR_RECT, $xorig - 5, $i + $yorig - 150, 10, 1); y axis tick marks
        GUICtrlSetGraphic(-1, $GUI_GR_RECT, $i + $xorig - 150, $yorig - 5, 1, 10); x axis tick marks
    Next

    $a[1] = GUICtrlCreateGraphic(-1, 50, 100, 100)
    GUICtrlSetBkColor(-1, 0xffffff);sets background of that specific space
    GUICtrlSetGraphic(-1, $GUI_GR_RECT, 50, 50, 50, 80)


    GUISetState()

    Do
        $msg = GUIGetMsg()

        If $numberofshapes > 1 And $msg = $del Then; deletes a graphic
            GUICtrlDelete($a[$numberofshapes])
            $numberofshapes -= 1
        EndIf

        If $msg = $add Then; addes a graphic
            
            $x = GUICtrlRead($xvalue)
            $w = GUICtrlRead($wvalue)
            $y = GUICtrlRead($yvalue)
            $h = GUICtrlRead($hvalue)
            $numberofshapes += 1
            $a[$numberofshapes] = GUICtrlCreateGraphic(-1, -1, $width, $height * .8)
            For $i = 0 To 300 Step 10
                GUICtrlSetGraphic(-1, $GUI_GR_RECT, $xorig - 5, $i + $yorig - 150, 10, 1); y axis tick marks
                GUICtrlSetGraphic(-1, $GUI_GR_RECT, $i + $xorig - 150, $yorig - 5, 1, 10); x axis tick marks
            Next
            GUICtrlSetGraphic(-1, $GUI_GR_RECT, $xorig - $x - floor($w / 2), $yorig - $y - floor($h / 2), $w, $h)

        EndIf
    Until $msg = $GUI_EVENT_CLOSE

EndFunc  ;==>Example

Where I changed your rectangles with a height or width of 1 for lines it was just to see if that was the problem but it wasn't. I added the Floor function in a couple of places which fixed it.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

It's not obvious I admit, but it's due to rounding of your calculations.

Try this

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

Global $del, $child, $numberofshapes = 2, $a[1000]
Global $height = @DesktopHeight * .90, $width = @DesktopWidth * .90
Global $xorig = Floor($width * .5), $yorig = floor($height * .5)

Example ()

Func Example ()

    $child = GUICreate("My Draw", $width, $height)

    $del = GUICtrlCreateButton("Delete", $width * .5 + 25, $height * .9, 50)
    $add = GUICtrlCreateButton("Add", $width * .5 - 50, $height * .9, 50)

    $xvalue = GUICtrlCreateInput("0", $width * .5 - 200, $height * .9, 50, 20)
    $yvalue = GUICtrlCreateInput("0", $width * .5 - 150, $height * .9, 50, 20)
    $wvalue = GUICtrlCreateInput("10", $width * .5 - 200, $height * .95, 50, 20)
    $hvalue = GUICtrlCreateInput("10", $width * .5 - 150, $height * .95, 50, 20)



    $bottom = GUICtrlCreateGraphic(-1, $height * .85, $width, $height * .15)
    GUICtrlSetBkColor(-1, 0xffffff)

    $axis = GUICtrlCreateGraphic(-1, -1, $width, $height * .8); Main area
    GUICtrlSetGraphic(-1, $GUI_GR_MOVE, $xorig - 150, $yorig)
    $xaxis = GUICtrlSetGraphic(-1, $GUI_GR_LINE, $xorig + 150, $yorig); x axis line
    GUICtrlSetGraphic(-1, $GUI_GR_MOVE, $xorig, $yorig - 150)
    $yaxis = GUICtrlSetGraphic(-1, $GUI_GR_LINE, $xorig, $yorig + 150); y axis line

    For $i = 0 To 300 Step 10
        GUICtrlSetGraphic(-1, $GUI_GR_RECT, $xorig - 5, $i + $yorig - 150, 10, 1); y axis tick marks
        GUICtrlSetGraphic(-1, $GUI_GR_RECT, $i + $xorig - 150, $yorig - 5, 1, 10); x axis tick marks
    Next

    $a[1] = GUICtrlCreateGraphic(-1, 50, 100, 100)
    GUICtrlSetBkColor(-1, 0xffffff);sets background of that specific space
    GUICtrlSetGraphic(-1, $GUI_GR_RECT, 50, 50, 50, 80)


    GUISetState()

    Do
        $msg = GUIGetMsg()

        If $numberofshapes > 1 And $msg = $del Then; deletes a graphic
            GUICtrlDelete($a[$numberofshapes])
            $numberofshapes -= 1
        EndIf

        If $msg = $add Then; addes a graphic
            
            $x = GUICtrlRead($xvalue)
            $w = GUICtrlRead($wvalue)
            $y = GUICtrlRead($yvalue)
            $h = GUICtrlRead($hvalue)
            $numberofshapes += 1
            $a[$numberofshapes] = GUICtrlCreateGraphic(-1, -1, $width, $height * .8)
            For $i = 0 To 300 Step 10
                GUICtrlSetGraphic(-1, $GUI_GR_RECT, $xorig - 5, $i + $yorig - 150, 10, 1); y axis tick marks
                GUICtrlSetGraphic(-1, $GUI_GR_RECT, $i + $xorig - 150, $yorig - 5, 1, 10); x axis tick marks
            Next
            GUICtrlSetGraphic(-1, $GUI_GR_RECT, $xorig - $x - floor($w / 2), $yorig - $y - floor($h / 2), $w, $h)

        EndIf
    Until $msg = $GUI_EVENT_CLOSE

EndFunc ;==>Example

Where I changed your rectangles with a height or width of 1 for lines it was just to see if that was the problem but it wasn't. I added the Floor function in a couple of places which fixed it.

The floor makes it a more precise program, but that wasn't my problem. My problem is that if I click add, it doesn't add until the second click.

To duplicate my problem:

Click add, this adds a box of size 10 by 10 and position 0 0,

change the 0 0 to 30 30, then click add

then change to 30 30 to 20 20, then click add

The gui doesn't update until another action is called

Link to comment
Share on other sites

Here is code I cleared up:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <Array.au3>
Global $x[500], $y[500], $w[500], $h[500]; x, y, w, h
Global $del, $child, $numberofshapes = 0, $a[500]
Global $height = @DesktopHeight * .90, $width = @DesktopWidth * .90
Global $xorig = Floor($width * .5), $yorig = floor($height * .5)

Example ()

Func Example ()

    GUICreate("My Draw", $width, $height)
    $connect = GUICtrlCreateButton("connect", $width * .5 + 100, $height * .9, 50)
    $del = GUICtrlCreateButton("Delete", $width * .5 + 25, $height * .9, 50)
    $add = GUICtrlCreateButton("Add", $width * .5 - 50, $height * .9, 50)

    $xvalue = GUICtrlCreateInput("0", $width * .5 - 200, $height * .9, 50, 20)
    $yvalue = GUICtrlCreateInput("0", $width * .5 - 150, $height * .9, 50, 20)
    $wvalue = GUICtrlCreateInput("10", $width * .5 - 200, $height * .95, 50, 20)
    $hvalue = GUICtrlCreateInput("10", $width * .5 - 150, $height * .95, 50, 20)

    $bottom = GUICtrlCreateGraphic(-1, $height * .85, $width, $height * .15)
    GUICtrlSetBkColor(-1, 0xffffff)

    $axis = GUICtrlCreateGraphic(-1, -1, $width, $height * .8); Main area
    GUICtrlSetGraphic(-1, $GUI_GR_MOVE, $xorig - 150, $yorig)
    $xaxis = GUICtrlSetGraphic(-1, $GUI_GR_LINE, $xorig + 150, $yorig); x axis line
    GUICtrlSetGraphic(-1, $GUI_GR_MOVE, $xorig, $yorig - 150)
    $yaxis = GUICtrlSetGraphic(-1, $GUI_GR_LINE, $xorig, $yorig + 150); y axis line

    For $i = 0 To 300 Step 10
        GUICtrlSetGraphic(-1, $GUI_GR_RECT, $xorig - 5, $i + $yorig - 150, 10, 1); y axis tick marks
        GUICtrlSetGraphic(-1, $GUI_GR_RECT, $i + $xorig - 150, $yorig - 5, 1, 10); x axis tick marks
    Next


    GUISetState()

    Do
        $msg = GUIGetMsg()

        If $numberofshapes > 1 And $msg = $del Then; deletes a graphic
            GUICtrlDelete($a[$numberofshapes])
            $numberofshapes =$numberofshapes-1
        EndIf

        If $msg = $add Then; addes a graphic
             $numberofshapes =$numberofshapes+1
            $x[$numberofshapes] = GUICtrlRead($xvalue)
            $y[$numberofshapes] = GUICtrlRead($yvalue)
                        $w[$numberofshapes] = GUICtrlRead($wvalue)
            $h[$numberofshapes] = GUICtrlRead($hvalue)
           
            $a[$numberofshapes] = GUICtrlCreateGraphic(-1, -1, $width, $height * .8)
            GUICtrlSetGraphic(-1, $GUI_GR_RECT, $xorig + $x[$numberofshapes]  - floor($w[$numberofshapes]  / 2), $yorig - $y[$numberofshapes]  - floor($h[$numberofshapes]  / 2), $w[$numberofshapes] , $h[$numberofshapes] )
            

            msgbox(0,"", $numberofshapes)
            _ArrayDisplay($x)
        EndIf
        
        If $msg=$connect Then
            
        endif
    Until $msg = $GUI_EVENT_CLOSE

EndFunc ;==>Example


Func connect()
    
endfunc
Edited by pillbug
Link to comment
Share on other sites

I am able to stop the problem by adding some GUISetState(@SW_hide) and @SW_Show. Does anyone know if there is a better way to fix this?

If $msg = $add Then; addes a graphic
                GUISetState(@SW_hide)
             $numberofshapes =$numberofshapes+1
            $x[$numberofshapes] = GUICtrlRead($xvalue)
            $y[$numberofshapes] = GUICtrlRead($yvalue)
                        $w[$numberofshapes] = GUICtrlRead($wvalue)
            $h[$numberofshapes] = GUICtrlRead($hvalue)
           
            $a[$numberofshapes] = GUICtrlCreateGraphic(-1, -1, $width, $height * .8)
            GUICtrlSetGraphic(-1, $GUI_GR_RECT, $xorig + $x[$numberofshapes]  - floor($w[$numberofshapes]  / 2), $yorig - $y[$numberofshapes]  - floor($h[$numberofshapes]  / 2), $w[$numberofshapes] , $h[$numberofshapes] )
            

        ;msgbox(0,"", $numberofshapes)
        ;_ArrayDisplay($x)
                GUISetState(@SW_SHOW)
        EndIf
Edited by pillbug
Link to comment
Share on other sites

Oh! I thought "out by one" meant out by one pixel.

The reason is that you need to replace your msgbox line with

GUICtrlSetGraphic(-1,$GUI_GR_REFRESH)

because the graphics don't refresh themselves. It's a very annoying feature that you can draw lines etc and they don't show until they are refreshed.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Oh! I thought "out by one" meant out by one pixel.

The reason is that you need to replace your msgbox line with

GUICtrlSetGraphic(-1,$GUI_GR_REFRESH)

because the graphics don't refresh themselves. It's a very annoying feature that you can draw lines etc and they don't show until they are refreshed.

Wow, that was so easy! Thanks

Next question Martin. How do I draw lines? when I use line it is always 45 degrees. I was using rectangles before for the axis because I couldn't figure out lines. Now I need to connect two points.

Link to comment
Share on other sites

Wow, that was so easy! Thanks

Next question Martin. How do I draw lines? when I use line it is always 45 degrees. I was using rectangles before for the axis because I couldn't figure out lines. Now I need to connect two points.

I figured it out!

I need the move feature $GUI_GR_MOVE

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...