Jump to content

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

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

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

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 :)

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
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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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

Link to post
Share on other sites
  • 1 year later...

 

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?

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By XGamerGuide
      I'm trying to assign a faint text in the background to an input field that disappears after the input has started. This should have a certain color such as gray.
    • By Bruceway
      Hi All, 
      I am trying to mark out the middle square of this Magnify Routine "window on right" (stolen from M23 - Thanks) - I assume the DllCall is overwriting the boxes. But wherever I try and redraw, they won't stay on the Magnify Window. Can anyone advise, bet way to keep boxes around the middle square.
      Please be kind with my code, it is ripped from a MUCH bigger exe.
      The "half" transparent window, is for dragging to where you want it, and the buttons are for more precise placement.
      #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <GUIConstantsEx.au3> #include <WinAPI.au3> Global $hMag_GUI, $hMagDC, $hDeskDC, $hPen, $oObj, $aWinPos[2], $iLast_Mouse_X = 0, $iLast_Mouse_Y = 0 Global $pWindowCaptureX, $pWindowCaptureY Global $pWindowMagWinX, $pWindowMagWinY #Region - GUI3 ; *** Grabber/Picker Window Global $hGUI3 = GUICreate("Capture", 150, 150, $pWindowCaptureX, $pWindowCaptureY, $WS_EX_TOOLWINDOW) Global $Pic1 = GUICtrlCreatePic("", 70, 40, 10, 10, BitOR($GUI_SS_DEFAULT_PIC,$WS_BORDER)) Global $hButtonUp = GUICtrlCreateButton("U", 65, 60, 20, 20) Global $hButtonDown = GUICtrlCreateButton("D", 65, 100, 20, 20) Global $hButtonLeft = GUICtrlCreateButton("L", 40, 80, 20, 20) Global $hButtonRight = GUICtrlCreateButton("R", 90, 80, 20, 20) Global $hButtonOK = GUICtrlCreateButton("OK", 60, 80, 30, 20) #EndRegion - GUI3 #Region - GUI4 Global $hGUI4 = GUICreate("MagWin", 250, 250, 325, 195) Global $hButtonMOK = GUICtrlCreateButton("OK", 45, 140, 30, 20) Global $hButtonMUp = GUICtrlCreateButton("U", 50, 120, 20, 20) Global $hButtonMDown = GUICtrlCreateButton("D", 50, 160, 20, 20) Global $hButtonMLeft = GUICtrlCreateButton("L", 25, 140, 20, 20) Global $hButtonMRight = GUICtrlCreateButton("R", 75, 140, 20, 20) Global $hLabelWindow = GUICtrlCreateLabel("Window", 5, 185, 44, 15) Global $hLabelWindowText = GUICtrlCreateLabel("", 60, 185, 176, 15) Global $hLabelCheck = GUICtrlCreateLabel("Check", 5, 205, 44, 15) Global $hLabelCheckText = GUICtrlCreateLabel("", 60, 205, 176, 15) Global $hLabelScreen = GUICtrlCreateLabel("Screen", 5, 225, 44, 15) Global $hLabelScreenText = GUICtrlCreateLabel("", 60, 225, 176, 15) #EndRegion - GUI4 ;GUISetState(@SW_HIDE, $hGUI1) GUISetState(@SW_SHOW, $hGUI3) GUISetState(@SW_SHOW, $hGUI4) WinSetTrans($hGUI3, "", 100) $hMag_GUI = WinGetHandle("MagWin") ; Get device context for Mag GUI $hMagDC = _WinAPI_GetDC($hMag_GUI) If @error Then Exit ; Get device context for desktop $hDeskDC = _WinAPI_GetDC(0) If @error Then _WinAPI_ReleaseDC($hMag_GUI, $hMagDC) Exit EndIf ; Create pen $hPen = _WinAPI_CreatePen($PS_SOLID, 5, 0x7E7E7E) $oObj = _WinAPI_SelectObject($hMagDC, $hPen) ; Loop until the user exits. ; *** Static Window While 1 ; Reset position Local $aWinPos = WinGetPos("Capture") If $aWinPos[0] <> $iLast_Mouse_X Or $aWinPos[1] <> $iLast_Mouse_Y Then ; Redraw Mag GUI _FOEA_Loupe($aWinPos) ;~ Local $TWPx = $aWinPos[0]+81 ;+81 Top Left Corner; +85 Middle ;~ Local $TWPy = $aWinPos[1]+75 ;+75 Top Left Corner; +80 Middle ;~ ;*** WINDOW COORDS = x+81 & y+75 (top left of picker square) GUISetState(@SW_HIDE, $hGUI3) Local $output1 = PixelCheckSum($aWinPos[0]+81, $aWinPos[1]+75, $aWinPos[0]+91, $aWinPos[1]+85) Local $output2 = PixelCheckSum($aWinPos[0]+73, $aWinPos[1]+66, $aWinPos[0]+83, $aWinPos[1]+76) If $aWinPos[0] < 1440 Then GUICtrlSetData($hLabelWindowText, $aWinPos[0]+81 & "(" & $aWinPos[0]+81+1440 &")," & $aWinPos[1]+75 & " : " & $output1) GUICtrlSetData($hLabelCheckText, $aWinPos[0]+73 & "(" & $aWinPos[0]+73+1440 & ")," & $aWinPos[1]+66 & " : " & $output2) GUICtrlSetData($hLabelScreenText, "W: " & $aWinPos[0]+73 & "(" & $aWinPos[0]+73+1440 &")," & $aWinPos[1]+66 & " C: " & $aWinPos[0]+81 & "," & $aWinPos[1]+75) Else GUICtrlSetData($hLabelWindowText, $aWinPos[0]+81-1440 & "(" & $aWinPos[0]+81 &")," & $aWinPos[1]+75 & " : " & $output1) GUICtrlSetData($hLabelCheckText, $aWinPos[0]+89-1440 & "(" & $aWinPos[0]+89 &")," & $aWinPos[1]+84 & " : " & $output2) GUICtrlSetData($hLabelScreenText, "W: " & $aWinPos[0]+73-1440 & "(" & $aWinPos[0]+73 & ")," & $aWinPos[1]+66 & " C: " & $aWinPos[0]+81 & "," & $aWinPos[1]+75) ;GUICtrlSetData($hLabel2, $aWinPos[1]+75) EndIf GUISetState(@SW_SHOW, $hGUI3) $iLast_Mouse_X = $aWinPos[0] $iLast_Mouse_Y = $aWinPos[1] $pWindowCaptureX = $aWinPos[0] $pWindowCaptureY = $aWinPos[1] ; *** Box ; Tried it here - doesn't work ;~ Global $Graphic = GUICtrlCreateGraphic(176, 55, 2, 20) ;~ Global $Graphic = GUICtrlCreateGraphic(194, 55, 2, 20) ;~ Global $Graphic = GUICtrlCreateGraphic(176, 55, 20, 2) ;~ Global $Graphic = GUICtrlCreateGraphic(176, 73, 20, 2) ;~ Global $Graphic = GUICtrlCreateGraphic(0, 0, 1, 1) EndIf Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Local $aWinPos = WinGetPos("MagWin") $pWindowMagWinX = $aWinPos[0] $pWindowMagWinY = $aWinPos[1] ;GUISetState(@SW_HIDE, $hGUI3) GUIDelete($hGUI3) ; Clear up Mag GUI _WinAPI_SelectObject($hMagDC, $oObj) _WinAPI_DeleteObject($hPen) _WinAPI_ReleaseDC(0, $hDeskDC) _WinAPI_ReleaseDC($hMag_GUI, $hMagDC) ;GUISetState(@SW_HIDE, $hMag_G GUIDelete($hGUI4) GUIDelete($hMag_GUI) ExitLoop Case $hButtonMOK GUISetState(@SW_HIDE, $hGUI3) Local $aWinPos = WinGetPos("Capture") Local $TWPx = $aWinPos[0]+81 ;+81 Top Left Corner; +85 Middle Local $TWPy = $aWinPos[1]+75 ;+75 Top Left Corner; +80 Middle ;*** WINDOW COORDS = x+81 & y+75 (top left of picker square) If $aWinPos[0] > 1440 Then $aWinPos[0] = $aWinPos[0]-1440 $TWPx = $TWPx-1440 EndIf Local $output0 = PixelCheckSum($TWPx-8, $TWPy-9, $TWPx-8+10, $TWPy+1) ;_FOEA_WinAPI_DrawRect(LRChecksum($TWPx-8), $TWPy-9, LRChecksum($TWPx-8)+10, $TWPy+1, 0xFFFFFF, 50) MsgBox($MB_SYSTEMMODAL, "Results ", _ "Window Coords" & @CRLF & _ $TWPx & "(" & $TWPx+1440 & "), " & $TWPy & @CRLF & _ "Checksum0: " & $output0 & @CRLF) GUISetState(@SW_SHOW, $hGUI3) WinActivate($hGUI3, "Capture") Case $hButtonMUp _FOEA_ButtonMUp() Case $hButtonMDown _FOEA_ButtonMDown() Case $hButtonMRight _FOEA_ButtonMRight() Case $hButtonMLeft _FOEA_ButtonMLeft() EndSwitch WEnd Func _FOEA_Loupe($aWinPos) Local $iX, $iY DllCall("gdi32.dll", "int", "StretchBlt", _ "int", $hMagDC, "int", 10, "int", 10, "int", 110, "int", 110, _ "int", $hDeskDC, "int", $aWinPos[0]+68, "int", $aWinPos[1]+61, "int", 20, "int", 20, _ "long", $SRCCOPY) DllCall("gdi32.dll", "int", "StretchBlt", _ "int", $hMagDC, "int", 130, "int", 10, "int", 110, "int", 110, _ "int", $hDeskDC, "int", $aWinPos[0]+70, "int", $aWinPos[1]+63, "int", 7, "int", 7, _ "long", $SRCCOPY) ; Appears initially - then disappears... Global $Graph1 = GUICtrlCreateGraphic(170, 57, 8, 16, $SS_WHITERECT) Global $Graph2 = GUICtrlCreateGraphic(170, 73, 31, 8, $SS_WHITERECT) Global $Graph3 = GUICtrlCreateGraphic(193, 57, 8, 16, $SS_WHITERECT) Global $Graph4 = GUICtrlCreateGraphic(170, 49, 31, 8, $SS_WHITERECT) ; This apears to be needed to stop the Magnify window moving Global $Graph5 = GUICtrlCreateGraphic(0, 0, 1, 1) ;Tried this too - no difference GUISetState(@SW_SHOW, $Graph1) GUISetState(@SW_SHOW, $Graph2) GUISetState(@SW_SHOW, $Graph3) GUISetState(@SW_SHOW, $Graph4) EndFunc ;==>Loupe Func _FOEA_ButtonMUp() Local $aWinPos = WinGetPos("Capture") WinMove($hGUI3, "Capture", $aWinPos[0], $aWinPos[1]-1) EndFunc Func _FOEA_ButtonMDown() Local $aWinPos = WinGetPos("Capture") WinMove($hGUI3, "Capture", $aWinPos[0], $aWinPos[1]+1) EndFunc Func _FOEA_ButtonMRight() Local $aWinPos = WinGetPos("Capture") WinMove($hGUI3, "Capture", $aWinPos[0]+1, $aWinPos[1]) EndFunc Func _FOEA_ButtonMLeft() Local $aWinPos = WinGetPos("Capture") WinMove($hGUI3, "Capture", $aWinPos[0]-1, $aWinPos[1]) EndFunc  
    • By XGamerGuide
      I'm trying to display a GIF. However, the GUI should not be visible. Here is an attempt that doesn't work:
      $sGIF = "MyGIF.gif" #Include <IE.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WINAPI.au3> #include <SendMessage.au3> Global Const $SC_DRAGMOVE = 0xF012 HotKeySet("{ESC}", "_Exit") $hGui = GUICreate("Test", 400, 300, -1, -1, $WS_POPUP, $WS_EX_LAYERED) GUISetBkColor(0xABCDEF) $oIE = _IECreateEmbedded() GUICtrlCreateObj($oIE, 10, 10, 380, 280) _WinAPI_SetLayeredWindowAttributes($hGUI, 0xABCDEF, 250) _IENavigate($oIE, $sGIF) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_PRIMARYDOWN _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0) EndSwitch WEnd Func _Exit() Exit  
    • By kcvinu
      Hi all,
      I am creating a GUI library in Nim with win32 API functions. Even though the syntax is similar to Python, coding is almost similar to C in Nim. 
      I can change the back color of the button in NM_CUSTOMDRAW. But I can't change the button text color. here is my pseudo code.  
      proc setBtnBackColor*(me : Button, lp: LPNMCUSTOMDRAW ) = if lp.uItemState and CDIS_SELECTED : #------------------ btn clicked # Here i am changing the button color with SelectObject & FillRect. elif lp.uItemState and CDIS_HOT : # ----------------Mouse over # Here i am changing the button's mouse hover color with SelectObject & FillRect. else: # -------------------------Default color set # Here i am changing the button's default color with SelectObject & FillRect. # Here i tried---> SetTextColor(lp.hdc, RGB(102, 255, 51) ) #------- But no luck. #------------------------------------------------------------------------- Please guide me. What i am doing wrong here ?  I am returning "CDRF_SKIPDEFAULT" after calling this function.
      Note : I am using subclassed button. So when the parent window receives WM_NOTIFY message, it sends that to my button's WndProc. There i am handling the message.
    • By paw
      I use SetSoundDevice to control my audio devices but the UI was either
       
      blurry like this:
      or unusable like this:

      so I made this horrible thing to add scaling to the GUI:
      #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Change2CUI=y #AutoIt3Wrapper_Res_HiDpi=y #AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 #AutoIt3Wrapper_Run_Au3Stripper=y #Au3Stripper_Parameters=/sf /sv /rm #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <File.au3> ;~ _convertGUI("") If $CmdLine[0] <> 0 Then _convertGUI($CmdLine[1]) Func _convertGUI($sFilePath) If $sFilePath <> "" Then Local $aArray = FileReadToArray($sFilePath) Else ;TEST DATA Local $aArray[6] = ['$H_Res_Language = GUICtrlCreateProgress(5, 120, 210 + 25, 480, 20, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE)) ; $CBS_DROPDOWNLIST)', _ 'Local $h_Ok = GUICtrlCreateButton("Ok", 72, 224, 81, 33, 0)', _ 'GUICreate($Warning_TiTle, 700, 310, -1, -1, $WS_SIZEBOX + $WS_SYSMENU + $WS_MINIMIZEBOX)', _ 'GUICtrlCreateLabel("Output type: ", 30, 130, 65, 20) ;, $SS_RIGHT)', _ '$H_FieldNameEdit = GUICtrlCreateEdit($INP_FieldNameEdit, 100,260+25, 500, 150 - 25) ;comment', 'Local $H_CANCEL = GUICtrlCreateGraphic("Cancel", 224, 224, 97, 33, 0)'] EndIf Local $hTimer = TimerInit(), $iGUIElementCount = 0, $sResult = "", $sFileName = "", $sDrive = "", $sDir = "", $sExtension = "" If @Compiled Then _PathSplit($sFilePath, $sDrive, $sDir, $sFileName, $sExtension) $sFileName = StringRegExpReplace($sFilePath, "^.*\\", "") EndIf For $i = 0 To (UBound($aArray) - 1) If StringRegExp($aArray[$i], "GUICtrlCreate|GUICreate") Then $sResult = _splitComma($aArray[$i]) If Not @error Then $aArray[$i] = $sResult $iGUIElementCount += 1 EndIf Next ConsoleWrite("t = " & TimerDiff($hTimer) & " GUI elements = " & $iGUIElementCount & " lines = " & (UBound($aArray) - 1) & @CRLF) If $sFileName <> "" Then Local $hFile = FileOpen("edited." & $sFileName, 2) _FileWriteFromArray("edited." & $sFileName, $aArray) FileClose($hFile) EndIf Exit EndFunc ;==>_convertGUI Func _splitComma($sString) Local $sSplitResult = "", $sTrimmedR = "", $sTrimmedL = "" Local $aSplit = StringSplit($sString, ',') If Not @error Then $sTrimmedR = "" $sTrimmedL = "" For $j = 1 To $aSplit[0] If StringRegExp($aSplit[1], "(?:.GUICtrlCreateGraphic|GUICtrlCreateProgress|GUICtrlCreateSlider|GUICtrlCreateTab|GUICtrlCreateTreeView)") Then If $j = 1 Then While StringLeft($aSplit[$j], 1) <> '(' $sTrimmedL &= StringLeft($aSplit[$j], 1) $aSplit[$j] = StringTrimLeft($aSplit[$j], 1) WEnd $aSplit[$j] = StringTrimLeft($aSplit[$j], 1) EndIf EndIf If $j = $aSplit[0] Then While StringRight($aSplit[$j], 1) <> ')' $sTrimmedR &= StringRight($aSplit[$j], 1) $aSplit[$j] = StringTrimRight($aSplit[$j], 1) WEnd $aSplit[$j] = StringTrimRight($aSplit[$j], 1) EndIf If StringRegExp($aSplit[$j], "[0-9]") And $aSplit[$j] <> -1 And $aSplit[$j] <> 0 And $aSplit[$j] <> 1 And Not StringInStr($aSplit[$j], ')') Then If StringRegExp($aSplit[$j], "\-|\+") Then ;put parenthesis around + or - $aSplit[$j] = '(' & $aSplit[$j] & ")*$g_DPI" Else $aSplit[$j] = $aSplit[$j] & "*$g_DPI" EndIf EndIf If $j < $aSplit[0] Then $sSplitResult &= $aSplit[$j] & ',' ElseIf $j = $aSplit[0] Then $sSplitResult &= $aSplit[$j] & ')' Else $sSplitResult &= $aSplit[$j] EndIf Next If $sTrimmedR <> "" Then $sSplitResult &= StringReverse($sTrimmedR) If $sTrimmedL <> "" Then $sSplitResult = $sTrimmedL & '(' & $sSplitResult Else SetError(1) Return EndIf ConsoleWrite($sSplitResult & @CRLF) Return $sSplitResult EndFunc ;==>_splitComma
      And now it looks good: 
      but it doesn't work on everything, for example the "GUICtrlCreateLabel("Output type: ", 30, 130, 65, 20) ;, $SS_RIGHT)" (from the autoit3wrapper gui)
      because the comment contains a parenthesis and it would break completely if there were variables as parameters..
      Is there some kind of parser around that I could use instead or maybe someone who has already done something like this?
×
×
  • Create New...