Jump to content

Graphics Update Flicker


 Share

Recommended Posts

I know this outside the bounds of Autoit as a Scripting language, but the graphics commands are there, so..

#include <GUIConstants.au3>
#include <Math.au3>

; == GUI generated with Koda ==);
$Graphics = GUICreate("Graphics Test", 600, 600, 192, 125)

$Gh = GuiCtrlCreateGraphic(-1, -1, 600,600)

$X = 300
$Y = 300

$Size = 300
$Wid = $Size
$Hgt = $Size
$Col = 0xffffff
$Col1 = 0x000000

GUISetState(@SW_SHOW)

GUICtrlSetGraphic(-1,$GUI_GR_PENSIZE, 1)

GUICtrlSetGraphic(-1,$GUI_GR_MOVE, $Size,$Size)
GUICtrlSetGraphic(-1,$GUI_GR_COLOR, $Col,0)
_DrawGraphic(0.5)

GUICtrlSetGraphic(-1,$GUI_GR_MOVE, $Size,$Size)
GUICtrlSetGraphic(-1,$GUI_GR_COLOR, $Col1,0)
_DrawGraphic(2)



While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
    ;;;;;;;
    EndSelect
WEnd

Func _DrawGraphic($Step)
For $R1 =1 to 360 Step $Step
    $Rad = _Radian ($R1)
    $Px = Sin($Rad)*$Size + $x
    $Py = Cos($Rad)*$Size + $y
    GUICtrlSetGraphic(-1,$GUI_GR_MOVE, $X,$Y)
    GUICtrlSetGraphic(-1,$GUI_GR_LINE, $Px,$Py)
        GUICtrlSetGraphic($Gh, $GUI_GR_REFRESH)
Next


EndFunc

I know that I could have it update after the graphics have been drawn, but I think the best part is seeing the graphics being drawn!

2015 - Still no flying cars, instead blankets with sleeves.

Link to comment
Share on other sites

Stick a Sleep(30) in there.

Func _DrawGraphic($Step)
For $R1 =1 to 360 Step $Step
    $Rad = _Radian ($R1)
    $Px = Sin($Rad)*$Size + $x
    $Py = Cos($Rad)*$Size + $y
    GUICtrlSetGraphic(-1,$GUI_GR_MOVE, $X,$Y)
    GUICtrlSetGraphic(-1,$GUI_GR_LINE, $Px,$Py)
    GUICtrlSetGraphic(-1,$GUI_GR_REFRESH)
    Sleep(30)
Next


EndFunc

#)

I tried including my AutoIt3D's DisplayManager in there, but then it is too bulky and slow for such a small application.

Edited by nfwu
Link to comment
Share on other sites

  • 3 weeks later...

This works without redrawing the whole GUI

#include <GUIConstants.au3>
#include <Math.au3>

; == GUI generated with Koda ==);
$Graphics = GUICreate("Graphics Test", 600, 600, 192, 125, $WS_POPUP)
Global $gdi_dll = DllOpen ("gdi32.dll"), $user32_dll = DllOpen ("user32.dll")

$Black  = "0x000000"
$White  = "0xFFFFFF"
$Red      = "0xFF0000"
$Green  = "0x00FF00"
$Blue     = "0x0000FF"
$Yellow = "0xFFFF00"

Dim $PenVar[10]
$PenVar[0] = "Black"
$PenVar[1] = "White"
$PenVar[2] = "Red"
$PenVar[3] = "Green"
$PenVar[4] = "Blue" 
$PenVar[5] = "Yellow"

$X = 300
$Y = 300

$Size = 300
$Wid = $Size
$Hgt = $Size

Dim $PenCol[10]
$PenCol[0] = $Black
$PenCol[1] = $White
$PenCol[2] = $Red
$PenCol[3] = $Green
$PenCol[4] = $Blue
$PenCol[5] = $Yellow


;$PenColour = "0xFFFFFF"
$BackgrndPen = "0x00D8E9EC"

GUISetState(@SW_SHOW)

For $n =0 to 5
$PenColour = $PenCol[$n]
;msgbox(0,"Colour", "Colour is " &$PenVar[$n] &" its value is " &$PenCol[$n] &"Size is " &$Size )
_DrawGraphic(0.2)
$Size = $Size - 50
next

While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
            DllClose ($gdi_dll)
            DllClose ($user32_dll)
        ExitLoop
    Case Else
    ;;;;;;;
    EndSelect
WEnd

Func _DrawGraphic($Step)
    For $R1 =363 to 1 Step -$Step
        $i = int($R1/3.6)
        $Rad = _Radian ($R1)
        $Px = Sin($Rad)*$Size + $x
        $Py = Cos($Rad)*$Size + $y
    ;Sleep(1)                       ;If you want to slow it down
        _DrawLine ($Graphics,$X,$Y,$Px,$Py,$PenColour,$BackgrndPen)
    Next
EndFunc

Func _DrawLine($GUI,$x, $y, $EndPntX, $EndPointY, $PenColour,$BackgrndPen )
    $GUIHDC = DllCall ($user32_dll,"int","GetDC","hwnd", $GUI)
    $Pen = DllCall($gdi_dll, "hwnd", "CreatePen", "int", "0", "int", "0", "hwnd", $PenColour)
    $Pen = $Pen[0]

    DllCall($gdi_dll, "hwnd", "SelectObject", "hwnd", $GUIHDC[0], "hwnd", $Pen)
    DllCall ($gdi_dll, "int", "MoveToEx", "hwnd", $GUIHDC[0], "int", $x, "int", $y, "ptr", 0)
    DllCall ($gdi_dll, "int", "LineTo", "hwnd", $GUIHDC[0], "int", $EndPntX, "int", $EndPointY)
    DllCall ($user32_dll,"int","ReleaseDC","int",$GUIHDC[0],"hwnd",$GUI)
EndFunc

Thanks to GreenMachine & NeoGia :think:

Not perfect, as the drawing is wiped out by any overlapping window, even if its made topmost.

Maybe do a capture, and then rewrite?, how to detect window overlap?

Thanks, Still Learning! :(

2015 - Still no flying cars, instead blankets with sleeves.

Link to comment
Share on other sites

:( @Lakes

graphics are drawn always in background so ONTOP cannot be used

Oh.. :think:

Anyone know how to detect when a window is overlapping the one I`m drawing on?

That way I could do a redraw or whatever after the other window has been moved.

Hmm.. Get position of Draw Window, then monitor positions of all other visable windows...

Gotta be a better way than that..

2015 - Still no flying cars, instead blankets with sleeves.

Link to comment
Share on other sites

Oh.. :think:

Anyone know how to detect when a window is overlapping the one I`m drawing on?

That way I could do a redraw or whatever after the other window has been moved.

Hmm.. Get position of Draw Window, then monitor positions of all other visable windows...

Gotta be a better way than that..

If a window is overlapping your window, could you assume that your window is not active? If so, check out my clock again - it has some checking for active or not, and if the window is moved off screen.

Link to comment
Share on other sites

If a window is overlapping your window, could you assume that your window is not active? If so, check out my clock again - it has some checking for active or not, and if the window is moved off screen.

Good Idea! :think: will do thanks! :(

2015 - Still no flying cars, instead blankets with sleeves.

Link to comment
Share on other sites

Anyone know how to detect when a window is overlapping the one I`m drawing on?

you could draw to a memorydc, GUIRegisterMsg( $WM_PAINT,) , BitBlt from the memorydc.

http://www.autoitscript.com/fileman/users/outeast/files/clock.au3

http://www.autoitscript.com/fileman/users/outeast/files/gdi32.au3

http://www.autoitscript.com/fileman/users/outeast/files/user32.au3

Link to comment
Share on other sites

you could draw to a memorydc, GUIRegisterMsg( $WM_PAINT,) , BitBlt from the memorydc.

http://www.autoitscript.com/fileman/users/outeast/files/clock.au3

http://www.autoitscript.com/fileman/users/outeast/files/gdi32.au3

http://www.autoitscript.com/fileman/users/outeast/files/user32.au3

Wow!, lots of functions to play with! thanks! :think:

2015 - Still no flying cars, instead blankets with sleeves.

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