Jump to content
Sign in to follow this  

Recommended Posts

GUI Fun!


Not enough posts here are about just plain fun stuff to do with AutoIt, at least not lately.  So I figure, why not dig up one of my old UDFs, clean it up a bit, and throw it very emphatically at you lot of misfits!

One way of mucking about with AutoIt and Windows that can be entertaining is creating shaped GUIs. Sure, GUIs with regions are nothing new here or in general on the Windows platform. But have you ever just wanted to stare at colorful shapes flying across your screen, for no apparent reason?  Well, my friend, you've come to the right place.

The first UDF I've put up pretty simple.  Boxes, circles, triangles, diamonds, and stars are what I bring you, in technicolor wonder.  I will probably add a few more examples when I find the time..

However, its my hope that more people add to this thread - and maybe provide links to other topics or posts where some nifty GUI fun is to be had!

GUI related Threads & UDFs of Interest

My Examples

I  should point out other GUI manipulation UDF's I've uploaded in the past, as they too can provide some amusement.

 

Okay, on to the new stuff!

_GUIShapes is a UDF with functions to create GUI's shapes like Circles, Boxes, Triangles, Stars, and Diamonds.  These GUI's have no interactive elements or controls and are click-through-able, meaning that a click on the GUI will pass through to whatever window is underneath.

_LineTraverser is a UDF with functions to create a well, line traverser. Given a start and end point, it will allow you to step through a given line without needing to do any extra work on your behalf.  This uses Bresenham's line algorithm to calculate the individual steps. I know this one isn't related to GUI, but its what I used for my second 'GUI fun' example below.

Pacman Line-Traversing GUI (>static or >animated). That's right, I managed to animate a GUI! Check it!  (now included in the ZIP)

Examples that follow will be bundled with the ZIP.  Have fun!

Updates:

2014-01-17:

- New _LineTraverser UDF with floating point math to replace the old (now renamed _LineTraverserB)

- Added Pacman examples

2014-01-17 'Hotfix':

- Fixed majorly borked Atan2() code

GUIShapesExample - whacky shapes flying all over the screen!!!

#include "_GUIShapes.au3"
;~ #include <WinAPI.au3>    ; already included in <_GUIShapes.au3>
; ========================================================================================================
; <GUIShapesExample.au3>
;
; Example use of <_GUIShapes.au3> UDF
;
; This example creates a bunch of random GUI shapes with random attributes, and moves
; everything around - randomly.
;
; Author: Ascend4nt
; ========================================================================================================

; ---------------------- MAIN CODE -------------------------------

Local $iShapeGUIs = 20, $aShapeGUIs[$iShapeGUIs], $iTimer, $iRand, $aRet
Local $iRandX, $iRandY, $iRandColor, $iRandLength
Local $iTriangles = 0, $iCircles = 0, $iStars = 0, $iDiamonds = 0, $iBoxes = 0

For $i = 0 To $iShapeGUIs - 1

    ; Everything random!
    $iRandX = Random(0, @DesktopWidth - 20, 1)
    $iRandY = Random(0, @DesktopHeight - 20, 1)
    $iRandLength = Random(12, 300, 1)
    $iRandColor = Random(0x111111, 0xFFFFFF, 1)

    ; Choose a GUI shape at random, with semi-random attributes
    Switch Random(0, 5, 1)
        Case 0
            $aShapeGUIs[$i] = _TriangleGUICreate($iRandX, $iRandY, $iRandLength, BitAND($iTriangles, 1) * Random(1, 10, 1), Default, Mod($i, 4), $iRandColor)
            $iTriangles += 1
        Case 1
            $aShapeGUIs[$i] = _CircleGUICreate($iRandX, $iRandY, $iRandLength, BitAND($iCircles, 1) * Random(1, 10, 1), Default, $iRandColor)
            $iCircles += 1
        Case 2
            $aShapeGUIs[$i] = _StarGUICreate($iRandX, $iRandY, $iRandLength, BitAND($iStars, 1) * Random(1, 10, 1), $iRandColor)
            $iStars += 1
        Case 3
            $aShapeGUIs[$i] = _DiamondGUICreate($iRandX, $iRandY, $iRandLength, Default, BitAND($iDiamonds, 1) * Random(1, 10, 1), $iRandColor)
            $iDiamonds += 1
        Case Else ; 4
            $aShapeGUIs[$i] = _BoxGUICreate($iRandX, $iRandY, $iRandLength, BitAND($iBoxes, 1) * Random(1, 10, 1), Default, $iRandColor)
            $iBoxes += 1
    EndSwitch

    ; Show the randomly created GUI
    GUISetState(@SW_SHOWNOACTIVATE, $aShapeGUIs[$i])

; And set a random transparency too
    WinSetTrans($aShapeGUIs[$i], '', Random(50, 255, 1))
Next
ConsoleWrite("GUI Totals: Triangles:" & $iTriangles & ", Circles:" & $iCircles & ", Stars:" & $iStars & ", Diamonds:" & $iDiamonds & ", Boxes:" & $iBoxes & @CRLF)

; Timer for moving shapes
$iTimer = TimerInit()
While 1
    ; Exit on 'ESC' keypress (BitAND() test for down-state)
    If BitAND(_WinAPI_GetAsyncKeyState(0x1B), 0x8000) Then ExitLoop

    Sleep(10)

    ; Move a random GUI every 30+ms
    If TimerDiff($iTimer) >= 30 Then
        $iRand = Random(0, $iShapeGUIs - 1, 1)
        ; Set GUI above other windows
        WinSetOnTop($aShapeGUIs[$iRand], "", 1)
        ; Move to a random position
        WinMove($aShapeGUIs[$iRand], "", Random(0, @DesktopWidth - 20, 1), Random(0, @DesktopHeight - 20, 1), Default, Default, 2)
        ; Reset timer
        $iTimer = TimerInit()
    EndIf
WEnd

_

LineTraverserExample - Where's the ball? Huh, where is it, Fido?! Ooh, there it is! Fetch the ball! Gooood circle..

#include "_GUIShapes.au3"
#include "_LineTraverser.au3"
;~ #include <WinAPI.au3>
; ========================================================================================================
; <LineTraverserExample.au3>
;
; Simple Example of using the <_LineTraverser.au3> and <_GuiShapes.au3> UDF's
;
;    A little red-ball will display, and a hollow ball will move towards it.
;    A line will be drawn to show how the path from the hollow ball to the red-ball target should work,
;    and then the hollow ball moves to it in $iStep increments.
;
;
; Author: Ascend4nt
; ========================================================================================================

Global Const $iStep = 2

Local $hHollowCircle, $hDestCircle, $iExt
Local $iXTarget, $iYTarget, $aLineTraverser

; Create the 2 circle GUIs
$hHollowCircle = _CircleGUICreate(Random(0, @DesktopWidth - 20, 1), Random(0, @DesktopHeight - 20, 1), 81, 10, Default, Random(0x111111, 0xFFFFFF, 1))
$hDestCircle = _CircleGUICreate(1, 1, 17, 0, 17, 0xFF0000)

; Set initial target point
$iXTarget = Random(0, @DesktopWidth - 20, 1)
$iYTarget = Random(0, @DesktopHeight - 20, 1)

; Source/Target are same to start off with
$aLineTraverser = _LineTraverserCreate($iXTarget, $iYTarget, $iXTarget, $iYTarget)

; Move windows to start positions
WinMove($hHollowCircle, '', $aLineTraverser[0], $aLineTraverser[1])
; + Center of hollow circle, - half of target circle
WinMove($hDestCircle, '', $iXTarget + 40 - 8, $iYTarget + 40 - 8)

; Transparency on 'seeker' circle
WinSetTrans($hHollowCircle, '', 150)

; Show both GUIs, and put on top of all windows
WinSetState($hDestCircle, '', @SW_SHOWNOACTIVATE)
WinSetState($hHollowCircle, '', @SW_SHOWNOACTIVATE)
WinSetOnTop($hHollowCircle, '', 1)
WinSetOnTop($hDestCircle, '', 1)

While 1
    ; Exit on 'ESC' keypress (in down state)
    If BitAND(_WinAPI_GetAsyncKeyState(0x1B), 0x8000) Then ExitLoop

    ; < 10 ms sleep with an API call
    DllCall("kernel32.dll",'none','Sleep','dword',3)

    If Not _LineTraverserStep($aLineTraverser, $iStep) Then
        $iExt = @extended

        ; Was there movement? Then moooove
        If $iExt Then
            WinMove($hHollowCircle, '', $aLineTraverser[0], $aLineTraverser[1])
        EndIf
        $aPos = WinGetPos($hHollowCircle)

        ; Debug check.  Should never be hit, so long as Window is moved to each step (including any last steps - see @extended)
        If $iXTarget <> $aPos[0] Or $iYTarget <> $aPos[1] Then
            ConsoleWrite("Mismatch: TargetX:" & $iXTarget & ", TraverserX:" & $aLineTraverser[0] & ", Current X:" & $aPos[0] & _
                    ", TargetY:" & $iYTarget & ", TraverserY:" & $aLineTraverser[1] & ", Current Y:" & $aPos[1] & ", @extended:" & $iExt & @CRLF)
                EndIf

        ; A little extra sleep to make it clear we've reached our destination.
        DllCall("kernel32.dll",'none','Sleep','dword',6)

        ; Now we'll set a new destination (with a visible line)
        Dim $iXTarget = Random(0, @DesktopWidth - 20, 1), $iYTarget = Random(0, @DesktopHeight - 20, 1)

        ; Create a new Line-Traverser (no need to explicitly destroy the last one, it was just an array of numbers)
        $aLineTraverser = _LineTraverserCreate($aLineTraverser[0], $aLineTraverser[1], $iXTarget, $iYTarget)

        ; + Center of hollow circle, - center of target circle
        WinMove($hDestCircle, '', $iXTarget + 40 - 8, $iYTarget + 40 - 8)

;~     Draw the line on-screen to give a visual indicator of the path that the hollow circle should take
;~     (note that the line will be overwritten by ANY screen activity, but that's fine for the example)

        ; Get DC to screen
        $hDC = _WinAPI_GetDC(0)
        ; Create pen and select it into DC
        $hPen = _WinAPI_CreatePen(0, 3, 0xFFFFFF)
        $hPenOld = _WinAPI_SelectObject($hDC, $hPen)
        ; Note we add 40 (for the center of the hollow circle GUI)
        _WinAPI_DrawLine($hDC, $aPos[0] + 40 - 1, $aPos[1] + 40 - 1, $iXTarget + 40 - 1, $iYTarget + 40 - 1)
        ; Select the old pen back
        _WinAPI_SelectObject($hDC, $hPenOld)
        ; Clean up pen and then release DC
        _WinAPI_DeleteObject($hPen)
        _WinAPI_ReleaseDC(0, $hDC)
        ; What fun drawing with GDI is  =|
    Else
        WinMove($hHollowCircle, '', $aLineTraverser[0], $aLineTraverser[1])
    EndIf
WEnd

GUIShapesFun.zip ~prev downloads: 60

Edited by Ascend4nt

Share this post


Link to post
Share on other sites

Interesting is the word that springs to mind.


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites

Interesting is the word that springs to mind.

You are known for your wordy posts ;)  But hey, I forgot about your GUI Design Concepts thread - added a link to it.

Additionally, uploaded my 'LineTraverser' example


Share this post


Link to post
Share on other sites

 I forgot about your GUI Design Concepts thread - added a link to it.

Oh yeh, didn't cross my mind when I posted my response or did it?! -_0


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites

jaberwacky, thats pretty funny that I didn't think of that. It could work, though I'd want a bit more flash from it..

Lakes, thats an interesting challenge.  I don't know what the overhead is for creating regions, but what you request would need to create a new region applied to the GUI for each new target the PacGui has to chase.  I would need to break out my maths to calculate angles and convert them into lines, but I'm sure it could be done. Asking it to 'chomp' like pacman would be too much transitioning though.. unless perhaps 2 GUI's are swapped out for each other.  Hmm..  its something I'll ponder doing :)


Share this post


Link to post
Share on other sites

Well, Lakes.. I hope you're happy!  After hours of wading through mathematics crap I finally figured out that up was down and vice versa. And well.. Pacman has cometh forth to do its evil bidding upon your computer screen!

This was actually pretty fun to figure out the maths with, although I totally forgot that the cartesian coordinate system does not match the Windows coordinate system. And I didn't want to tweak around with Mapping modes or whatnot.. so I just flipped things around and hacked out a coordinate system that works (a counterclockwise upside-down one, but hey.. thats pretty much how I see the world) ;)

Here it is (you'll need the ZIP from the first post):

*Edit: Fixed borked ATan() related maths

Pacman Line-Traversing GUI Goodness

#include "_LineTraverser.au3"
#include "_GUIShapes.au3"
#include <WinAPI.au3>
; ========================================================================================================
; <LineTraverserPacmanExample.au3>
;
; Simple Example of using the <_LineTraverser.au3> and <_GuiShapes.au3> UDF's
;
;    A little red-ball displays, while a 'Pacman' GUI moves towards it along a line
;    An actual line is drawn onscreen to show the path from 'Pacman' to the red-ball target GUI,
;    and then the PacGUI moves to it in $iStep increments.
;
; Additional Functions:
;    _GUIApplyPacman()    ; Converts a square GUI into a Pacman-shaped GUI. Regions are recreated
;                        ; each time, based on the input
;    Atan2_Radians()        ; An 'atan2()' function
;
; Author: Ascend4nt
; ========================================================================================================

Global Const $iStep = 2

Local $hPacMan, $hDestCircle, $iExt
Local $iXTarget, $iYTarget, $aLineTraverser

; Create the Pacman GUI and apply shape to it
$hPacMan = GUICreate("", 81, 81,Random(0, @DesktopWidth - 20, 1), Random(0, @DesktopHeight - 20, 1), 0x80000000, 0x08000080 + 0x20)
GUISetBkColor(Random(0x111111, 0xFFFFFF, 1), $hPacMan)
_GUIApplyPacman($hPacMan, 0)

; Red-dot GUI
$hDestCircle = _CircleGUICreate(1, 1, 17, 0, 17, 0xFF0000)

; Set initial target point
$iXTarget = Random(0, @DesktopWidth - 20, 1)
$iYTarget = Random(0, @DesktopHeight - 20, 1)

; Source/Target are same to start off with
$aLineTraverser = _LineTraverserCreate($iXTarget, $iYTarget, $iXTarget, $iYTarget)

; Move windows to start positions
WinMove($hPacMan, '', $aLineTraverser[0], $aLineTraverser[1])
; + Center of hollow circle, - half of target circle
WinMove($hDestCircle, '', $iXTarget + 40 - 8, $iYTarget + 40 - 8)

; Transparency on 'seeker' circle
WinSetTrans($hPacMan, '', 150)

; Show both GUIs, and put on top of all windows
WinSetState($hDestCircle, '', @SW_SHOWNOACTIVATE)
WinSetState($hPacMan, '', @SW_SHOWNOACTIVATE)
WinSetOnTop($hPacMan, '', 1)
WinSetOnTop($hDestCircle, '', 1)

While 1
    ; Exit on 'ESC' keypress (in down state)
    If BitAND(_WinAPI_GetAsyncKeyState(0x1B), 0x8000) Then ExitLoop

    ; < 10 ms sleep with an API call
    DllCall("kernel32.dll",'none','Sleep','dword',3)

    If Not _LineTraverserStep($aLineTraverser, $iStep) Then
        $iExt = @extended

        ; Was there movement? Then moooove
        If $iExt Then
            WinMove($hPacMan, '', $aLineTraverser[0], $aLineTraverser[1])
        EndIf
        $aPos = WinGetPos($hPacMan)

        ; Debug check.  Should never be hit, so long as Window is moved to each step (including any last steps - see @extended)
        If $iXTarget <> $aPos[0] Or $iYTarget <> $aPos[1] Then
            ConsoleWrite("Mismatch: TargetX:" & $iXTarget & ", TraverserX:" & $aLineTraverser[0] & ", Current X:" & $aPos[0] & _
                    ", TargetY:" & $iYTarget & ", TraverserY:" & $aLineTraverser[1] & ", Current Y:" & $aPos[1] & ", @extended:" & $iExt & @CRLF)
                EndIf

        ; A little extra sleep to make it clear we've reached our destination.
        DllCall("kernel32.dll",'none','Sleep','dword',6)

        ; Now we'll set a new destination (with a visible line)
        Dim $iXTarget = Random(0, @DesktopWidth - 20, 1), $iYTarget = Random(0, @DesktopHeight - 20, 1)

        ; Create a new Line-Traverser (no need to explicitly destroy the last one, it was just an array of numbers)
        $aLineTraverser = _LineTraverserCreate($aLineTraverser[0], $aLineTraverser[1], $iXTarget, $iYTarget)

        ; + Center of hollow circle, - center of target circle
        WinMove($hDestCircle, '', $iXTarget + 40 - 8, $iYTarget + 40 - 8)

        ; Apply Pacman GUI with calculated angle of line it should point towards
        _GUIApplyPacman($hPacMan, Atan2_Radians($iYTarget - $aLineTraverser[1], $iXTarget - $aLineTraverser[0]))

    ; Draw the line on-screen to give a visual indicator of the path that the hollow circle should take
    ; (note that the line will be overwritten by ANY screen activity, but that's fine for the example)

        ; Get DC to screen
        $hDC = _WinAPI_GetDC(0)
        ; Create pen and select it into DC
        $hPen = _WinAPI_CreatePen(0, 3, 0xFFFFFF)
        $hPenOld = _WinAPI_SelectObject($hDC, $hPen)
        ; Note we add 40 (for the center of the hollow circle GUI)
        _WinAPI_DrawLine($hDC, $aPos[0] + 40 - 1, $aPos[1] + 40 - 1, $iXTarget + 40 - 1, $iYTarget + 40 - 1)
        ; Select the old pen back
        _WinAPI_SelectObject($hDC, $hPenOld)
        ; Clean up pen and then release DC
        _WinAPI_DeleteObject($hPen)
        _WinAPI_ReleaseDC(0, $hDC)
        ; What fun drawing with GDI is  =|
        ;Sleep(4000)
    Else
        WinMove($hPacMan, '', $aLineTraverser[0], $aLineTraverser[1])
    EndIf
WEnd
Exit


; =================================================================================================================
; Func _GUIApplyPacman($hGUI, $fAngleInRads)
;
; Takes a GUI and applies a 'Pacman' shape to it. The angle of Pacman's mouth is based upon the $fAngleinRads
; variable (the mouth is a 90 degree angle rotated towards the angle given)
;
; Returns:
;  Success: 1, @error = 0
;  Failure: 0, @error set
;
; Author: Ascend4nt
; =================================================================================================================

Func _GUIApplyPacman($hGUI, $fAngleInRads)
    Local $aPos, $aVertices, $hEllipseRgn = 0, $hPieRegion = 0
    Local $iCenterXY

    $aPos = WinGetPos($hGUI)
    If @error Then Return SetError(1, 0, 0)

    $iCenterXY = $aPos[2] / 2
    #cs
    ;; --------------
    ; Vertices array:
    ; ---------------
    ; These vertices make up the mouth. 0.78539816 is a 45 degree difference (in Radians)
    ; Note that the multipler should typically be Radius, not $aPos[2] as here, if we were creating a line
    ; to the circumference of the circle. However, that would cause a weird triangle-inside-a-circle effect
    ; when combining Regions. So we overextend it and let Windows clip the line at the GUI borders,
    ; which does its job of covering up the outer parts of the circle
    ; ----------------------------------------------------------------
    #ce
    Dim $aVertices[3][2] = [ _
        [ $iCenterXY, $iCenterXY ], _    ; We over-extend the lines here ($aPos[2] is way longer than the radius)
        [ $iCenterXY + $aPos[2] * Cos($fAngleInRads - 0.78539816), $iCenterXY + $aPos[2] * Sin($fAngleInRads - 0.78539816) ], _
        [ $iCenterXY + $aPos[2] * Cos($fAngleInRads + 0.78539816), $iCenterXY + $aPos[2] * Sin($fAngleInRads + 0.78539816) ] _
    ]

    Do

        ; Create a Basic Elliptical region
        $hEllipseRgn = _WinAPI_CreateEllipticRgn(_WinAPI_CreateRect(0, 0, $aPos[2], $aPos[3]))
        If $hEllipseRgn = 0 Then
            SetError(10)
            ExitLoop
        EndIf

        ; Create the Pacman Pie area
        $hPieRegion = _WinAPI_CreatePolygonRgn($aVertices, 0, -1, 1)
        If $hPieRegion = 0 Then
            SetError(12)
            ExitLoop
        EndIf

        ; Combine, put resulting region in $hEllipseRgn. RGN_AND = 1, RGN_OR = 2, RGN_XOR = 3, RGN_DIFF = 4
        If Not _WinAPI_CombineRgn($hEllipseRgn, $hEllipseRgn, $hPieRegion, 4) Then
            SetError(14)
            ExitLoop
        EndIf
        ; Don't need this anymore (already combined with the Region injected into the GUI)
        _WinAPI_DeleteObject($hPieRegion)


        ; Set the region into the GUI. (GUI will then own it so there's no need to delete it)
        If Not _WinAPI_SetWindowRgn($hGUI, $hEllipseRgn, True) Then
            SetError(16)
            ExitLoop
        EndIf

        Return 1
    Until 1

    Local $iErr = @error, $iExt = @extended

    ; Cleanup
    _WinAPI_DeleteObject($hEllipseRgn)
    _WinAPI_DeleteObject($hPieRegion)

    Return SetError($iErr, $iExt, 0)
EndFunc   ;==>_GUIApplyPacman


; =================================================================================================================
; Func Atan2_Radians($fY, $fX)
;
; Atan2() implementation, based on Wikipedia description.  See notes
;
; atan2() differs from atan() in that it maps atan(Y/X) to correct Quadrants
;
; References:
; https://en.wikipedia.org/wiki/Atan2
; https://en.wikipedia.org/wiki/Radian
; https://en.wikipedia.org/wiki/Cosine#Unit-circle_definitions
;
; Returns: Atan2() result in radians (for the flipped counterclockwise system)
;
; Author: Ascend4nt
; =================================================================================================================

Func Atan2_Radians($fY, $fX)
    Local Const $f_PI = 3.14159265
    Local Const $f_PIHalf = $f_PI / 2
;~     ConsoleWrite("Atan2 entry, $fY = " & $fY & ", $fX = " & $fX & @CRLF)
    If $fX = 0 Then
        ; Technically 'undefined'
        If $fY = 0 Then Return 0.0

        If $fY < 0 Then
            Return -$f_PIHalf
        Else ; $fY >= 0
            Return $f_PIHalf
        EndIf
    EndIf

    Local $fTmp = ATan($fY / $fX)

    If $fX < 0 Then
        If $fY < 0 Then
            Return $fTmp - $f_PI
        Else
            Return $fTmp + $f_PI
        EndIf
    Else ; $fX > 0    ; already checked == 0 at start
        Return $fTmp
    EndIf
EndFunc   ;==>Atan2_Radians
Edited by Ascend4nt

Share this post


Link to post
Share on other sites

The Pacman animation with the dots is missing  ;)

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

well, helloooo Mr Fancypants! hehe..  hey I know yer a master of the fine arts of GDI+ and GUIs, but making a Pacman GUI that animates is just plain nonsense!  The only thing I could do is swap out different GUIs to make it look like its animating.. OR change the Region every frame or so, but I wanted to avoid the latter in case it sucked up a lot of time, though swapping GUIs could be done simply enough.

Oh, and for some reason I can't change the line style no matter what Pen size/style I choose.. maybe its a limitation of drawing onto the desktop? I've tried CreatePenIndrect as well.. hmm

Anyway, Sifu UEZ.. what do you have up your sleeve?  I bet with GDI+ you could create a dotted line on the desktop. But what would u suggest as far as GUI 'animation' here? The idea is to not draw on the GUI itself..


Share this post


Link to post
Share on other sites

For the dotted lines I would use circles by calculating the slope of the start / end point, divide the line (way from start to end point) into n pieces and place my circles on this line (vector).

The animation of the pacman might be a little more complicated but you have alreay a solution for it. ;) You have to animate it by changing the angle of the "mouth" during the way from start to end point.

Anyhow, as you already said it is "plain nonsense!".

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

For the dotted lines I would use circles by calculating the slope of the start / end point, divide the line (way from start to end point) into n pieces and place my circles on this line (vector).

 

I do remember that line slop algorithm from algebra :)  I have that _LineTraverser UDF included in the ZIP which can be used to traverse a line in any number of steps.  Of course, it uses Bresenham's line algorithm, which was optimized so it wouldn't use floating point math.  However, in this day it makes little sense to use that, especially in a scripted language.. I may create a simplified version using the line algorithm.  But yes, planting circles along a line is a nice idea.. maybe every 5 spaces a circle of radius 3..

The animation of the pacman might be a little more complicated but you have alreay a solution for it. ;) You have to animate it by changing the angle of the "mouth" during the way from start to end point.

 

Yes, I had mentioned that I wasn't too sure about how much time/CPU adjusting Regions would take up.  However, out of curiosity I did an experiment, and it doesn't seem to take up much resources at all.. especially if its paced out.  The result is further below..

Anyhow, as you already said it is "plain nonsense!".

Of course, practicing nonsense is part of the fun of living ;).  I also have a 'bouncing ball' GUI example laying around too that I figure I should add here, once I clean up the simple 'physics'.  I bet you have something along those lines already in GDI+?  Might be fun to do as a GUI.

So here's the 'chomping' version of pacman.  No dots.. yet

Pacman Line-Traversing GUI, Take 2

*edit: Removed - See >Post below for the newer version.

Edited by Ascend4nt

Share this post


Link to post
Share on other sites

Updated

2014-01-17:

- New _LineTraverser UDF with floating point math to replace the old (now renamed _LineTraverserB)

- Added Pacman examples

2014-01-17 'Hotfix':

- Fixed majorly borked Atan2() code

Lakes, thanks but I've about had enough of the PacGUI! haha..

Ah, and here's the final Pacman animated GUI example. The 'final' dot doesn't seem to always line up, and squares happen to draw better than ellipses so you'll have to make do - or improve it as you wish :)

*Edit: Note, this example will eat up memory quickly.

This is due to a bug in Windows where it doesn't properly dispose of previous Regions that have been applied to a Window. Unfortunately, there's no way to get at the region once Window takes over it either...

In the future I may create a versoin with the 3 different 'animations' as 3 different GUI's and try swapping them in and out. It should alleviate the memory leak problem..

Pacman (Animated) Line-Traversing GUI, The Final Act

#include "_LineTraverser.au3"
#include "_GUIShapes.au3"
#include <WinAPI.au3>
; ========================================================================================================
; <LineTraverserPacmanExample.au3>
;
; Simple Example of using the <_LineTraverser.au3> and <_GuiShapes.au3> UDF's
;
;    A little red-ball displays, while a 'Pacman' GUI moves towards it along a line
;    An actual line is drawn onscreen to show the path from 'Pacman' to the red-ball target GUI,
;    and then the PacGUI moves to it in $iStep increments.
;
; Additional Functions:
;    _DrawPlainOldLine()        ; Draws a line on the screen
;    _DrawPacmanDottedLine()    ; Draws a special Pacman-Dotted line
;    _GUIApplyPacman()        ; Converts a square GUI into a Pacman-shaped GUI. Regions are recreated
;                            ; each time, based on the input
;    Atan2_Radians()            ; An 'atan2()' vfunction
;
; Author: Ascend4nt
; ========================================================================================================

Global Const $iStep = 2

Local $hPacMan, $hDestCircle, $iExt, $iStepsTaken = 0, $iMode = 0, $fLineAngleRads = 0
Local $iXTarget, $iYTarget, $aLineTraverser

; Create the Pacman GUI and apply shape to it
$hPacMan = GUICreate("", 81, 81, Random(0, @DesktopWidth - 20, 1), Random(0, @DesktopHeight - 20, 1), 0x80000000, 0x08000080 + 0x20)
GUISetBkColor(Random(0x111111, 0xFFFFFF, 1), $hPacMan)
_GUIApplyPacman($hPacMan, 0)

; Pink-dot GUI
$hDestCircle = _CircleGUICreate(1, 1, 17, 0, 17, 0xDE8394)

; Set initial target point
$iXTarget = Random(0, @DesktopWidth - 20, 1)
$iYTarget = Random(0, @DesktopHeight - 20, 1)

; Source/Target are same to start off with
$aLineTraverser = _LineTraverserCreate($iXTarget, $iYTarget, $iXTarget, $iYTarget)

; Move windows to start positions
WinMove($hPacMan, '', $aLineTraverser[0], $aLineTraverser[1])
; + Center of hollow circle, - half of target circle
WinMove($hDestCircle, '', $iXTarget + 40 - 8, $iYTarget + 40 - 8)

; Transparency on 'seeker' circle
WinSetTrans($hPacMan, '', 150)

; Show both GUIs, and put on top of all windows
WinSetState($hDestCircle, '', @SW_SHOWNOACTIVATE)
WinSetState($hPacMan, '', @SW_SHOWNOACTIVATE)
WinSetOnTop($hPacMan, '', 1)
WinSetOnTop($hDestCircle, '', 1)

While 1
    ; Exit on 'ESC' keypress (in down state)
    If BitAND(_WinAPI_GetAsyncKeyState(0x1B), 0x8000) Then ExitLoop

    ; < 10 ms sleep with an API call
    ;DllCall("kernel32.dll",'none','Sleep','dword',4)

    ; Slower allows to see mouth transitions better
    Sleep(10)

    If Not _LineTraverserStep($aLineTraverser, $iStep) Then
        $iExt = @extended

        ; Was there movement? Then moooove
        If $iExt Then
            WinMove($hPacMan, '', $aLineTraverser[0], $aLineTraverser[1])
        EndIf
        $aPos = WinGetPos($hPacMan)

        ; Debug check.  Should never be hit, so long as Window is moved to each step (including any last steps - see @extended)
        If $iXTarget <> $aPos[0] Or $iYTarget <> $aPos[1] Then
            ConsoleWrite("Mismatch: TargetX:" & $iXTarget & ", TraverserX:" & $aLineTraverser[0] & ", Current X:" & $aPos[0] & _
                    ", TargetY:" & $iYTarget & ", TraverserY:" & $aLineTraverser[1] & ", Current Y:" & $aPos[1] & ", @extended:" & $iExt & @CRLF)
        EndIf

        ; A little extra sleep to make it clear we've reached our destination.
        DllCall("kernel32.dll", 'none', 'Sleep', 'dword', 6)

        ; Now we'll set a new destination (with a visible line)
        Dim $iXTarget = Random(0, @DesktopHeight - 20, 1), $iYTarget = Random(0, @DesktopHeight - 20, 1)

        ;ConsoleWrite("New target: X: " & $iXTarget & ", Y: " & $iYTarget & ", FROM X: " & $aLineTraverser[0] & ", Y: " & $aLineTraverser[1] & @CRLF)

        ; Create a new Line-Traverser (no need to explicitly destroy the last one, it was just an array of numbers)
        $aLineTraverser = _LineTraverserCreate($aLineTraverser[0], $aLineTraverser[1], $iXTarget, $iYTarget)

        ; + Center of hollow circle, - center of target circle
        WinMove($hDestCircle, '', $iXTarget + 40 - 8, $iYTarget + 40 - 8)

        ; Apply Pacman GUI with calculated angle of line it should point towards
        $fLineAngleRads = Atan2_Radians($iYTarget - $aLineTraverser[1], $iXTarget - $aLineTraverser[0])
        _GUIApplyPacman($hPacMan, $fLineAngleRads)

        ; Draw the line on-screen to give a visual indicator of the path that the hollow circle should take
        ; (note that the line will be overwritten by ANY screen activity, but that's fine for the example)

        ; Add 40 for the center of the hollow circle GUI
        _DrawPacmanDottedLine($aPos[0] + 40 - 1, $aPos[1] + 40 - 1, $iXTarget + 40 - 1, $iYTarget + 40 - 1)
        ; Or
;~         _DrawPlainOldLine($aPos[0] + 40 - 1, $aPos[1] + 40 - 1, $iXTarget + 40 - 1, $iYTarget + 40 - 1)

    Else
        $iStepsTaken += 1
        If $iStepsTaken > 7 Then
            $iMode += 1
            ;If $iMode > 2 Then $iMode = 0    ; Function masks off the needed bits
            _GUIApplyPacman($hPacMan, $fLineAngleRads, $iMode)
            $iStepsTaken = 0
        EndIf
        WinMove($hPacMan, '', $aLineTraverser[0], $aLineTraverser[1])
    EndIf
WEnd
Exit

; =================================================================================================================
; Func _DrawPlainOldLine($iX1, $iY1, $iX2, $iY2)
;
; Draws a white line on the screen
;
; Author: Ascend4nt
; =================================================================================================================

Func _DrawPlainOldLine($iX1, $iY1, $iX2, $iY2)
    Local $hDC, $hPen, $hPenOld, $hBrush, $hBrushOld
    ; Get DC to screen
    $hDC = _WinAPI_GetDC(0)

    ; Create Pen (outline) [PS_SOLID = 0, PS_DASH = 1, PS_DOT = 2, PS_DASHDOT = 3, PS_DASHDOTDOT = 4, PS_NULL = 5]
    ; Seems no styles other than PS_SOLID work even if Width is <= 1, at least on the desktop DC in Win7
    $hPen = _WinAPI_CreatePen(0, 3, 0xFFFFFF)

    ; Alternatively, get a Stock Pen.. (width 1 unfortunately)
    ; WHITE_PEN = 6, BLACK_PEN = 7, NULL_PEN = 8
    ;$hPen = _WinAPI_GetStockObject(6)

    ; Create (or Get) Brush (fill)
    ; Doesn't seem to make a difference for Lines actually
    ; WHITE_BRUSH = 0, BLACK_BRUSH = 4, HOLLOW_BRUSH = 5
    $hBrush = _WinAPI_GetStockObject(0)
    ; BS_SOLID = 0, BS_HOLLOW = 1, BS_HATCHED = 2
;~     $hBrush = _WinAPI_CreateBrushIndirect(1, 0xFFFFFF, 0)

    ; Select Pen and Brush (saving old)
    $hPenOld = _WinAPI_SelectObject($hDC, $hPen)
    $hBrushOld = _WinAPI_SelectObject($hDC, $hBrush)

    _WinAPI_DrawLine($hDC, $iX1, $iY1, $iX2, $iY2)

    ; Select the old Brush and Pen back
    _WinAPI_SelectObject($hDC, $hBrushOld)
    _WinAPI_SelectObject($hDC, $hPenOld)

    ; Clean up pen & brush and then release DC
    _WinAPI_DeleteObject($hPen)
    ; _WinAPI_DeleteObject($hBrush)    ; No need to delete Stock Objects
    _WinAPI_ReleaseDC(0, $hDC)
    Return True
EndFunc   ;==>_DrawPlainOldLine

; =================================================================================================================
; Func _DrawPacmanDottedLine($iX1, $iY1, $iX2, $iY2)
;
; Draws a series of 'dots' on a given line.
;
; Unfortunately, in my tests, the Ellipse creates a bunch of artifacts, so the Rectangle is used to plot
; the dots.  Some versions of Pacman look like they use squares anyway..
;
; Author: Ascend4nt
; =================================================================================================================

Func _DrawPacmanDottedLine($iX1, $iY1, $iX2, $iY2)
    Local $hDC, $hPen, $hPenOld, $hBrush, $hBrushOld
    Local $aLineTraverser

    ; Line traverser for plotting Pac dots..
    $aLineTraverser = _LineTraverserCreate($iX1, $iY1, $iX2, $iY2)

    ; Get DC to screen
    $hDC = _WinAPI_GetDC(0)

    ; Create Pen (outline) [PS_SOLID = 0, PS_DASH = 1, PS_DOT = 2, PS_DASHDOT = 3, PS_DASHDOTDOT = 4, PS_NULL = 5]
    $hPen = _WinAPI_CreatePen(5, 3, 0x00FFFF)

    ; Create (or Get) Brush (fill)
    ; [BS_SOLID = 0, BS_HOLLOW = 1, BS_HATCHED = 2]
    ; {Hatch Styles} HS_HORIZONTAL  = 0, HS_VERTICAL  = 1, HS_FDIAGONAL  = 2,
    ;     HS_BDIAGONAL  = 3, HS_CROSS  = 4, HS_DIAGCROSS  = 5, HS_API_MAX  = 12
    $hBrush = _WinAPI_CreateBrushIndirect(0, 0xFFFF00, 0)

    ; Select Pen and Brush (saving old)
    $hPenOld = _WinAPI_SelectObject($hDC, $hPen)
    $hBrushOld = _WinAPI_SelectObject($hDC, $hBrush)

    ; We try to avoid drawing on the target circle
    While _LineTraverserStepsRemaining($aLineTraverser) > 30
        ; Steps of 20
        _LineTraverserStep($aLineTraverser, 20)
;~         _WinAPI_Ellipse($hDC, _WinAPI_CreateRect($aLineTraverser[0] - 5, $aLineTraverser[1] - 5, $aLineTraverser[0] + 5, $aLineTraverser[1] + 5))
        _WinAPI_Rectangle($hDC, _WinAPI_CreateRect($aLineTraverser[0] - 5, $aLineTraverser[1] - 5, $aLineTraverser[0] + 5, $aLineTraverser[1] + 5))
    WEnd

    ; Select the old Brush and Pen back
    _WinAPI_SelectObject($hDC, $hBrushOld)
    _WinAPI_SelectObject($hDC, $hPenOld)

    ; Clean up pen & brush and then release DC
    _WinAPI_DeleteObject($hPen)
    _WinAPI_DeleteObject($hBrush)
    _WinAPI_ReleaseDC(0, $hDC)
    Return True
EndFunc   ;==>_DrawPacmanDottedLine


; =================================================================================================================
; Func _GUIApplyPacman($hGUI, $fAngleInRads, $nMouthMode = 0)
;
; Takes a GUI and applies a 'Pacman' shape to it. The angle of Pacman's mouth is based upon the $fAngleinRads
; variable. It also has 3 modes - mouth closed, partially open, or open to 90 degrees (rotated to face given angle)
;
; Parameters:
;  $hGUI = GUI that will have a 'Pacman' Region applied to it
;  $fAngleInRads = The Angle which the 'mouth' should center on, given in Radians (Degrees * PI / 180)
;  $iMouthMode = 'Mode' of mouth: 0 (default) = 90 degree span, 1 = 40 degree span, 2 = closed (basic circle Region)
;
; Returns:
;  Success: 1, @error = 0
;  Failure: 0, @error set
;
; Author: Ascend4nt
; =================================================================================================================

Func _GUIApplyPacman($hGUI, $fAngleInRads, $iMouthMode = 0)
    Local $aPos, $aVertices, $hEllipseRgn = 0, $hPieRegion = 0
    Local $iCenterXY, $fMouthAngleRad

    $aPos = WinGetPos($hGUI)
    If @error Then Return SetError(1, 0, 0)

    $iCenterXY = $aPos[2] / 2

    $iMouthMode = BitAND($iMouthMode, 3)
    Switch $iMouthMode
        Case 1
            ; 20 Degrees
            $fMouthAngleRad = 0.34906585
        Case 2
            ; No adjustment necessary, we're using a full circle
            $fMouthAngleRad = 0
        Case Else
            ; 45 Degrees
            $fMouthAngleRad = 0.78539816
    EndSwitch

    Do
        ; Create a Basic Elliptical region
        $hEllipseRgn = _WinAPI_CreateEllipticRgn(_WinAPI_CreateRect(0, 0, $aPos[2], $aPos[3]))
        If $hEllipseRgn = 0 Then
            SetError(10)
            ExitLoop
        EndIf

        ; Everything OTHER than Mode 2 gets a 'mouth' applied
        If $iMouthMode <> 2 Then
            #cs
                ;; --------------
                ; Vertices array:
                ; ---------------
                ; These vertices make up the mouth.
                ; Note that the multipler should typically be Radius, not $aPos[2] as here, if we were creating a line
                ; to the circumference of the circle. However, that would cause a weird triangle-inside-a-circle effect
                ; when combining Regions (leaving whats known as a 'Chord' behind). So we overextend it and let
                ; Windows clip the line at the GUI borders, which does its job of covering up the outer parts of the circle
                ; -----------------------------------------------------------------------------------------------------
            #ce
            Dim $aVertices[3][2] = [ _
                    [$iCenterXY, $iCenterXY], _    ; We over-extend the lines here ($aPos[2] is way longer than the radius)
                    [$iCenterXY + $aPos[2] * Cos($fAngleInRads - $fMouthAngleRad), $iCenterXY + $aPos[2] * Sin($fAngleInRads - $fMouthAngleRad)], _
                    [$iCenterXY + $aPos[2] * Cos($fAngleInRads + $fMouthAngleRad), $iCenterXY + $aPos[2] * Sin($fAngleInRads + $fMouthAngleRad)] _
                    ]

            ; Create the Pacman Pie area
            $hPieRegion = _WinAPI_CreatePolygonRgn($aVertices, 0, -1, 1)
            If $hPieRegion = 0 Then
                SetError(12)
                ExitLoop
            EndIf

            ; Combine, put resulting region in $hEllipseRgn. (RGN_AND = 1, RGN_OR = 2, RGN_XOR = 3, RGN_DIFF = 4)
            If Not _WinAPI_CombineRgn($hEllipseRgn, $hEllipseRgn, $hPieRegion, 4) Then
                SetError(14)
                ExitLoop
            EndIf

            ; Don't need this anymore (already combined with the Region injected into the GUI)
            _WinAPI_DeleteObject($hPieRegion)
        EndIf

        ; Set the region into the GUI. (GUI will then own it so there's no need to delete it)
        If Not _WinAPI_SetWindowRgn($hGUI, $hEllipseRgn, True) Then
            SetError(16)
            ExitLoop
        EndIf

        Return 1
    Until 1

    Local $iErr = @error, $iExt = @extended

    ; Cleanup
    _WinAPI_DeleteObject($hEllipseRgn)
    _WinAPI_DeleteObject($hPieRegion)

    Return SetError($iErr, $iExt, 0)
EndFunc   ;==>_GUIApplyPacman


; =================================================================================================================
; Func Atan2_Radians($fY, $fX)
;
; Atan2() implementation, based on Wikipedia description.  See notes
;
; atan2() differs from atan() in that it maps atan(Y/X) to correct Quadrants
;
; References:
; https://en.wikipedia.org/wiki/Atan2
; https://en.wikipedia.org/wiki/Radian
; https://en.wikipedia.org/wiki/Cosine#Unit-circle_definitions
;
; Returns: Atan2() result in radians (for the flipped counterclockwise system)
;
; Author: Ascend4nt
; =================================================================================================================

Func Atan2_Radians($fY, $fX)
    Local Const $f_PI = 3.14159265
    Local Const $f_PIHalf = $f_PI / 2
;~     ConsoleWrite("Atan2 entry, $fY = " & $fY & ", $fX = " & $fX & @CRLF)
    If $fX = 0 Then
        ; Technically 'undefined'
        If $fY = 0 Then Return 0.0

        If $fY < 0 Then
            Return -$f_PIHalf
        Else ; $fY >= 0
            Return $f_PIHalf
        EndIf
    EndIf

    Local $fTmp = ATan($fY / $fX)

    If $fX < 0 Then
        If $fY < 0 Then
            Return $fTmp - $f_PI
        Else
            Return $fTmp + $f_PI
        EndIf
    Else ; $fX > 0    ; already checked == 0 at start
        Return $fTmp
    EndIf
EndFunc   ;==>Atan2_Radians
Edited by Ascend4nt

Share this post


Link to post
Share on other sites

When im trying to compile my file it has a error with my script and i can't fix it. Please Help..

This error on all the examples. ERROR: $IMAGE_BITMAP previously declared as a 'Const'.

Share this post


Link to post
Share on other sites

Kudos and a hearty "hear hear" for this post.

I suck at GUI design, I hate it, and my programs look terrible.  While "having fun" doesn't necessarily lead to efficient GUI design, you never know when you'll stumble across a diamond in the rough that is just what one needs to spice up a boring grey window with buttons.

I vote for more!

Share this post


Link to post
Share on other sites

 

Updated

2014-01-17:

- New _LineTraverser UDF with floating point math to replace the old (now renamed _LineTraverserB)

- Added Pacman examples

2014-01-17 'Hotfix':

- Fixed majorly borked Atan2() code

Lakes, thanks but I've about had enough of the PacGUI! haha..

Ah, and here's the final Pacman animated GUI example. The 'final' dot doesn't seem to always line up, and squares happen to draw better than ellipses so you'll have to make do - or improve it as you wish :)

*Edit: Note, this example will eat up memory quickly.

This is due to a bug in Windows where it doesn't properly dispose of previous Regions that have been applied to a Window. Unfortunately, there's no way to get at the region once Window takes over it either...

In the future I may create a versoin with the 3 different 'animations' as 3 different GUI's and try swapping them in and out. It should alleviate the memory leak problem..

Pacman (Animated) Line-Traversing GUI, The Final Act

#include "_LineTraverser.au3"
#include "_GUIShapes.au3"
#include <WinAPI.au3>
; ========================================================================================================
; <LineTraverserPacmanExample.au3>

Where can I get a hold of the 2 includes that I can't find on any search?

#include "_LineTraverser.au3"

#include "_GUIShapes.au3"

I would love to have those 2 includes. I have collected a good 1,009 includes from all over Autoit forum. These two are the only ones I have not been able to find. Can you please post them?

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  

  • Similar Content

    • By CarlD
      Update: Download the latest version here.
      As my first stab at GUI scripting, I'm trying to write a simple graphical interface for Grep for Windows. I have a basic GUI, but I'm stuck on one point and nothing I've tried so far works. The sticking point is that while the Tab key works to move focus from one input control to the next, clicking the mouse on any but the first input does nothing. This seems like a basic feature of GUI functionality that should work out of the box (like Tab), but clearly I'm missing something. I tried (among many other things) Melba23's technique in the post below, but this doesn't do what I'm after -- getting the left click to set the insertion point for user input. Would greatly appreciate a pointer or two. 😉
      Here's my code so far:
      ; Grep for Windows -- GUI [CLD] #include <AutoItConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> Opt("WinTitleMatchMode", -2) #cs FileInstall("X:\nix\search1.ico", @TempDir & "\search1.ico") FileInstall("X:\nix\grep.exe", @TempDir & "\grep.exe") FileInstall("X:\nix\sed.exe", @TempDir & "\sed.exe") FileInstall("X:\nix\libiconv2.dll", @TempDir & "\libiconv2.dll") FileInstall("X:\nix\libintl3.dll", @TempDir & "\libintl3.dll") FileInstall("X:\nix\pcre3.dll", @TempDir & "\pcre3.dll") FileInstall("X:\nix\regex2.dll", @TempDir & "\regex2.dll") #ce ; $sDefFs = @ScriptDir & "\.txt" $sOut = "" $iX = 20 $iY = 20 $hgGGrep = GUICreate("Grep for Windows: Simple TeXT search", 600, 600) GUISetState(@SW_SHOW, $hgGGrep) ; Obtain value of control: GUICtrlRead() ; left, top, width, height ; $iX, $iY, $iX + n, $iY + m ; $hgIco = GUICtrlCreateIcon(@ScriptDir & "\search1.ico", $iX, $iY, 10) $hgGL0 = GUICtrlCreateLabel("Enter a string or regular expression" & @CRLF & "(space between words means ""OR"")", $iX + 50, $iY, 250, 30) $hgSch = GUICtrlCreateInput("", $iX + 50, $iY + 40, 325, 20, $GUI_SS_DEFAULT_INPUT, -1) $hgXyZ = GUICtrlCreateCheckbox("cAsE-sEnSiTiVe", $iX + 50, $iY + 65, -1, -1) $hgExe = GUICtrlCreateButton("Search", 400, $iY + 40, -1, -1) $hgFL1 = GUICtrlCreateLabel("Filespec", $iX + 50, $iY + 100, 250, 20) $hgFs1 = GUICtrlCreateInput("d:\path\*.txt", $iX + 110, $iY + 100, 250, 20, $GUI_SS_DEFAULT_INPUT, -1) $hgFL2 = GUICtrlCreateLabel("Filespec", $iX + 50, $iY + 120, 250, 20) $hgFs2 = GUICtrlCreateInput("", $iX + 110, $iY + 120, 250, 20, $GUI_SS_DEFAULT_INPUT, -1) $hgFL3 = GUICtrlCreateLabel("Filespec", $iX + 50, $iY + 140, 250, 20) $hgFs3 = GUICtrlCreateInput("", $iX + 110, $iY + 140, 250, 20, $GUI_SS_DEFAULT_INPUT,-1) $hgOut = GUICtrlCreateEdit($sOut, 25, 190, 550, 400, $ES_LEFT, -1) GUICtrlSetState($hgSch, $GUI_FOCUS) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd ; #cs _WinAPI_SetFocus(ControlGetHandle("Grep for Windows", "", $hgSch)) _WinAPI_SetFocus(ControlGetHandle("Grep for Windows", "", $hgFs1)) _WinAPI_SetFocus(ControlGetHandle("Grep for Windows", "", $hgFs2)) _WinAPI_SetFocus(ControlGetHandle("Grep for Windows", "", $hgFs3)) #ce Thanks in advance.
    • By Elizabeth
      Buttons on GUI to perform different tasks. SETUP is a task that involves displaying another GUI, doing calculations, writing lines to 2 external files, displaying information on GUI labels.  The info from the displayed GUI (quantity made and job completed YES or NO) must be included on the written lines. I cannot get the script to run synchronously (waterfall execution 1st one ends before 2nd one starts.) That means lines written to the files do not contain the required data.  I have read through FORUM and thought by inserting a boolean value and changing TRUE FALSE that I could solve this issue. I would have to set/reset the boolean before every function call to make it work. I've tried using Sleep but that just slows everything down and makes main GUI look unresponsive
      Is there a trick or tip someone can provide that forces synchronous execution?
      I am using OPT GUIOnEventMode
      Thank you for any insight into this issue.
    • By TheDcoder
      Hello everyone,
      I encountered this strange issue while working on a freelance project, I cannot give you the webpage/website on which this is happening because it is an internal site which is inaccessible externally. I am attempting to create a GUI with an IE control embedded in it, but when I navigate to the desired address, it shows a blank white page.
      The webpage does load if I use a different browser or normal (non-embedded) IE instance.
      I managed to get my hands on the source of the blank page:
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <link rel="stylesheet" type="text/css" href="res://ieframe.dll/ErrorPageTemplate.css" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Navigationen blev annulleret</title> <script src="res://ieframe.dll/errorPageStrings.js" language="javascript" type="text/javascript"> </script> <script src="res://ieframe.dll/httpErrorPagesScripts.js" language="javascript" type="text/javascript"> </script> </head> <body onLoad="javascript:navCancelInit(); "> <table width="730" cellpadding="0" cellspacing="0" border="0"> <!-- Error title --> <tr> <td id="infoIconAlign" width="60" align="left" valign="top" rowspan="2"> <img src="res://ieframe.dll/info_48.png" id="infoIcon" alt="Oplysningsikon"> </td> <td id="mainTitleAlign" valign="middle" align="left" width="*"> <h1 id="mainTitle">Navigationen til websiden blev annulleret</h1> </td> </tr> <tr> <!-- This row is for HTTP status code, as well as the divider--> <td id="errorCodeAlign" class="errorCodeAndDivider" align="right">&nbsp; <div class="divider"></div> </td> </tr> <!-- Error Body --> <!-- What you can do --> <tr> <td> &nbsp; </td> <td id="whatToTryAlign" valign="top" align="left"> <h2 id="whatToTry">Prøv at:</h2> </td> </tr> <!-- refresh page --> <tr> <td > &nbsp; </td> <td id="refreshPageAlign" align="left" valign="middle"> <h4> <table> <tr> <td valign="top"> <img src="res://ieframe.dll/bullet.png" border="0" alt="" class="actionIcon"> </td> <td valign="top"> <span id="navCancelContainer"></span><noscript id="refreshPage">Opdatere siden.</noscript> </td> </tr> </table> </h4> </td> </tr> </table> </body> </html> The ieframe.dll resources are a point of interest. I am not sure how the server is able to detect the embedded instance of IE ...
      Any suggestions? Here is a basic outline of the script:
      #include <IE.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Main() While True Sleep(1000) WEnd Func Main() ; Create GUI $hGUI = GUICreate("", $GUI_WIDTH, $GUI_HEIGHT, $iLeft, $iTop, $WS_POPUP) $oIE = _IECreateEmbedded() ;$oIE = _IECreate() ; This works, but it is not embedded in the GUI GUICtrlCreateObj($oIE, 0, 0, $GUI_WIDTH, $GUI_HEIGHT) GUISetState() ; Navigate to the URL and authenticate _IENavigate($oIE, $URL) EndFunc Thank you for the advice in advance!
    • By jpomalley
      Hi all,
      Does anyone know if there is a way to disable the Windows "fade effect" that occurs when a window appears or disappears?
      It is possible for a user to disable visual effects in windows in general through the system properties > performance settings, but I am interested just in fixing it for a particular window that pops up in my app.
      I would like it to appear and disappear instantaneously, snapping in and out, out of nowhere, rather than the short (maybe 300 ms?) fade in/fade out effect that windows has.
      Thanks for any tips
      JP
    • By fastman
      I am struggling with activating the 2nd GUI.  References of https://www.autoitscript.com/wiki/Managing_Multiple_GUIs did not help.
      Gui2 and controls are created, but the buttons are not active.  I have tried to remove extra code.
      Thanks for any help.
      ; ; cabinet maker process to automate MasterCam ; ATP nesting process ; #include <AutoItConstants.au3> #include <Array.au3> ;#include <file.au3> ;#include <FileConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <WinAPI.au3> #include <WinAPIFiles.au3> #include <WindowsConstants.au3> ;#include <XML.au3>; If XML library is updated, note that this script requires that save file will overwrite an existing file Opt("GUIOnEventMode", 1) ; 1 = OnEvent mode Opt("WinWaitDelay", 500) ; milliseconds Opt("TrayIconDebug", 1) Opt("WinSearchChildren", 1) Global $hMainGUI Global $hMainGUI2 Func GetAllWindowsControls($hCallersWindow, $bOnlyVisible = Default, $sStringIncludes = Default, $sClass = Default) If Not IsHWnd($hCallersWindow) Then ConsoleWrite("$hCallersWindow must be a handle...provided=[" & $hCallersWindow & "]" & @CRLF) Return False EndIf ; Get all list of controls If $bOnlyVisible = Default Then $bOnlyVisible = True If $sStringIncludes = Default Then $sStringIncludes = "" If $sClass = Default Then $sClass = "" $sClassList = WinGetClassList($hCallersWindow) ; Create array $aClassList = StringSplit($sClassList, @CRLF, 2) ; Sort array _ArraySort($aClassList) _ArrayDelete($aClassList, 0) ; Loop $iCurrentClass = "" $iCurrentCount = 1 $iTotalCounter = 1 If StringLen($sClass) > 0 Then For $i = UBound($aClassList) - 1 To 0 Step -1 If $aClassList[$i] <> $sClass Then _ArrayDelete($aClassList, $i) EndIf Next EndIf For $i = 0 To UBound($aClassList) - 1 If $aClassList[$i] = $iCurrentClass Then $iCurrentCount += 1 Else $iCurrentClass = $aClassList[$i] $iCurrentCount = 1 EndIf $hControl = ControlGetHandle($hCallersWindow, "", "[CLASSNN:" & $iCurrentClass & $iCurrentCount & "]") $text = StringRegExpReplace(ControlGetText($hCallersWindow, "", $hControl), "[\n\r]", "{@CRLF}") $aPos = ControlGetPos($hCallersWindow, "", $hControl) $sControlID = _WinAPI_GetDlgCtrlID($hControl) $bIsVisible = ControlCommand($hCallersWindow, "", $hControl, "IsVisible") If $bOnlyVisible And Not $bIsVisible Then $iTotalCounter += 1 ContinueLoop EndIf If StringLen($sStringIncludes) > 0 Then If Not StringInStr($text, $sStringIncludes) Then $iTotalCounter += 1 ContinueLoop EndIf EndIf If IsArray($aPos) Then ;ConsoleWrite("ControlID=[" & StringFormat("%5s", $sControlID) & "] Handle=[" & StringFormat("%10s", $hControl) & "] ClassNN=[" & StringFormat("%19s", $iCurrentClass & $iCurrentCount) & "] XPos=[" & StringFormat("%4s", $aPos[0]) & "] YPos=[" & StringFormat("%4s", $aPos[1]) & "] Width=[" & StringFormat("%4s", $aPos[2]) & "] Height=[" & StringFormat("%4s", $aPos[3]) & "] IsVisible=[" & $bIsVisible & "] Text=[" & $text & "]." & @CRLF) ConsoleWrite("Func=[GetAllWindowsControls]: ControlCounter=[" & StringFormat("%3s", $iTotalCounter) & "] ControlID=[" & StringFormat("%5s", $sControlID) & "] Handle=[" & StringFormat("%10s", $hControl) & "] ClassNN=[" & StringFormat("%19s", $iCurrentClass & $iCurrentCount) & "] XPos=[" & StringFormat("%4s", $aPos[0]) & "] YPos=[" & StringFormat("%4s", $aPos[1]) & "] Width=[" & StringFormat("%4s", $aPos[2]) & "] Height=[" & StringFormat("%4s", $aPos[3]) & "] IsVisible=[" & $bIsVisible & "] Text=[" & $text & "]." & @CRLF) Else ;ConsoleWrite("ControlID=[" & StringFormat("%5s", $sControlID) & "] Handle=[" & StringFormat("%10s", $hControl) & "] ClassNN=[" & StringFormat("%19s", $iCurrentClass & $iCurrentCount) & "] XPos=[winclosed] YPos=[winclosed] Width=[winclosed] Height=[winclosed] Text=[" & $text & "]." & @CRLF) ConsoleWrite("Func=[GetAllWindowsControls]: ControlCounter=[" & StringFormat("%3s", $iTotalCounter) & "] ControlID=[" & StringFormat("%5s", $sControlID) & "] Handle=[" & StringFormat("%10s", $hControl) & "] ClassNN=[" & StringFormat("%19s", $iCurrentClass & $iCurrentCount) & "] XPos=[winclosed] YPos=[winclosed] Width=[winclosed] Height=[winclosed] Text=[" & $text & "]." & @CRLF) EndIf If Not WinExists($hCallersWindow) Then ExitLoop $iTotalCounter += 1 Next ;MsgBox($MB_SYSTEMMODAL, "title", "check console for control list") EndFunc ;==>GetAllWindowsControls ; ======= Func GetAllWindowsControls($hCallersWindow, $bOnlyVisible = Default, $sStringIncludes = Default, $sClass = Default) ========= Func setNestingOverlay() $ovrWidth = 400 $ovrHeight = 60 $ovrLeft = -1 ;$mcamWindow[0] + $nestControlRelative[0] $ovrTop = -1;$mcamWindow[1] + $nestControlRelative[1]+ 10 $hMainGUI = GUICreate("covering mastercam buttons", $ovrWidth, $ovrHeight, $ovrLeft, $ovrTop, -1, $WS_EX_TOPMOST) GUISetOnEvent($GUI_EVENT_CLOSE, "CloseButton2") Local $iOKButton1 = GUICtrlCreateButton("Continue to gui2", 20, 20, 80) GUICtrlSetOnEvent($iOKButton1, "NestResultButtonOverlay") GUISetState(@SW_SHOW, $hMainGUI) GetAllWindowsControls(WinGetHandle("[ACTIVE]")) ;loop to monitor button click While 1 Sleep(50) ; Sleep to reduce CPU usage WEnd ConsoleWrite(" exit loop setNestingOverlay") EndFunc ;==>setNestingOverlay ;=== 2nd gui ======= 2nd gui ======= 2nd gui ======= 2nd gui ======= 2nd gui ======= 2nd gui ==== func NestResultButtonOverlay() $ovrWidth = -1;$mcamWindow[2] - 10 $ovrHeight = 70 ;40 $ovrLeft = -1 ;$mcamWindow[0] + 5 ;+ $nestControlRelative[0] $ovrTop = -1 ;$mcamWindow[1] + $nestControlRelative[1]+ 10 $hMainGUI2 = GUICreate("gui2-- covering nest result buttons", $ovrWidth, $ovrHeight, $ovrLeft, $ovrTop, -1, $WS_EX_TOPMOST) ;width, height, left, top ;GUISetState(@SW_DISABLE + @SW_MINIMIZE, $hMainGUI) ;GUISwitch($hMainGUI2) GUISetOnEvent($GUI_EVENT_CLOSE, "CloseButton2") local $iBackNestingButton = GUICtrlCreateButton("Back to Nesting", 20, 10, 120) GUICtrlSetOnEvent($iBackNestingButton, "backtoNesting") Local $iOKButton2 = GUICtrlCreateButton("Continue for g-Code", 160, 10, 120) GUICtrlSetOnEvent(-1, "generateGCode") ;GUICtrlSetOnEvent($iOKButton2, "generateGCode") Local $iDoneButton2 = GUICtrlCreateButton("Oops go back to vortex", 300, 10, 120) GUICtrlSetOnEvent($iDoneButton2, "CloseButton2") GUISetState(@SW_SHOW, $hMainGUI2) GUISetState(@SW_DISABLE + @SW_MINIMIZE, $hMainGUI) GUISwitch($hMainGUI2) GetAllWindowsControls(WinGetHandle("[ACTIVE]")) While 1 Sleep(50) ; Sleep to reduce CPU usage WEnd ConsoleWrite(" exit loop NestResultButtonOverlay") EndFunc ;==>setNestingOverlay func backtoNesting() msgbox($MB_SYSTEMMODAL, "gui2","backtoNesting") EndFunc Func CloseButton2() msgbox($MB_SYSTEMMODAL, "gui2","CloseButton2") Exit EndFunc func generateGCode() msgbox($MB_SYSTEMMODAL, "gui2","generateGCode") EndFunc ; =========== main =========== main =========== main =========== main =========== main =========== main setNestingOverlay()  
×
×
  • Create New...