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 antonioj84
      I am not able to use the $GUI_READ_EXTENDED with the  Metro UDF,  any work around ?
      Local $aPos[2] = [$Radio1, $Radio2] For $Radio In $aPos If GUICtrlRead($Radio) = $GUI_UNCHECKED Then ContinueLoop IniWrite($sGUIstate_IniFile, "Data", "POS", GUICtrlRead($Radio, $GUI_READ_EXTENDED)) ;; return the text of the menu item ExitLoop Next  
    • By _Vlad
      Hello forum,
      I want to create a program with multiple menus and many elements inside. The problem is my way of doing this and below I have an example of how I do these menus.
      I know it's a bad way of doing them as using this method for more elements and menus cause big flickering.
       
      Can someone please help me with some tips of optimizing this or tell me another way of creating that menus with many elements without cause flickering? From a long time ago I still try to solve this but without any results, just small improvements.
      Many thanks for everyone.
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $MENU_HOVER = '' Global $MENU_SELECTED = '' Global $COLOR_STANDARD = 0x94A5E9 Global $COLOR_HOVER = 0x8292d1 Global $COLOR_SELECTED = 0x7584bf $MENU = GUICreate("Menu", 615, 437, -1, -1, -1, -1, 0) GUISetFont(10, 400, 0, "Arial") $MENU_1 = GUICtrlCreateLabel("Menu 1", 8, 24, 106, 28, BitOR($SS_CENTER, $SS_CENTERIMAGE)) $MENU_2 = GUICtrlCreateLabel("Menu 2", 8, 56, 106, 28, BitOR($SS_CENTER, $SS_CENTERIMAGE)) $MENU_3 = GUICtrlCreateLabel("Menu 3", 8, 88, 106, 28, BitOR($SS_CENTER, $SS_CENTERIMAGE)) ;MENU 1 ELEMENTS $MENU_1_ELEMENT_1 = GUICtrlCreateButton("Menu1 Button", 128, 24, 147, 25) ;MENU 2 ELEMENTS $MENU_2_ELEMENT_1 = GUICtrlCreateButton("Menu2 Button", 128, 24, 147, 25) $MENU_2_ELEMENT_2 = GUICtrlCreateLabel("Another element", 128, 64, 99, 20) _Design() _Hide_All() GUISetState(@SW_SHOW, $MENU) While 1 $Cursor = GUIGetCursorInfo($MENU) $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $MENU_1 _Previous_Selected_Cancel() $MENU_SELECTED = 'Menu1' GUICtrlSetBkColor($MENU_1, $COLOR_SELECTED) _Show('Menu1') Case $MENU_2 _Previous_Selected_Cancel() $MENU_SELECTED = 'Menu2' GUICtrlSetBkColor($MENU_2, $COLOR_SELECTED) _Show('Menu2') Case $MENU_3 _Previous_Selected_Cancel() $MENU_SELECTED = 'Menu3' GUICtrlSetBkColor($MENU_3, $COLOR_SELECTED) _Show('Menu3') EndSwitch If $Cursor[4] = $MENU_1 Then If $MENU_HOVER <> 'Menu1' And $MENU_SELECTED <> 'Menu1' Then _Previous_Hover_Cancel() GUICtrlSetBkColor($MENU_1, $COLOR_HOVER) $MENU_HOVER = 'Menu1' EndIf ElseIf $Cursor[4] = $MENU_2 Then If $MENU_HOVER <> 'Menu2' And $MENU_SELECTED <> 'Menu2' Then _Previous_Hover_Cancel() GUICtrlSetBkColor($MENU_2, $COLOR_HOVER) $MENU_HOVER = 'Menu2' EndIf ElseIf $Cursor[4] = $MENU_3 Then If $MENU_HOVER <> 'Menu3' And $MENU_SELECTED <> 'Menu3' Then _Previous_Hover_Cancel() GUICtrlSetBkColor($MENU_3, $COLOR_HOVER) $MENU_HOVER = 'Menu3' EndIf Else _Previous_Hover_Cancel() $MENU_HOVER = 'Idle' EndIf WEnd Func _Design() GUICtrlSetColor($MENU_1, 0xFFFFFF) GUICtrlSetBkColor($MENU_1, $COLOR_STANDARD) GUICtrlSetCursor($MENU_1, 0) GUICtrlSetColor($MENU_2, 0xFFFFFF) GUICtrlSetBkColor($MENU_2, $COLOR_STANDARD) GUICtrlSetCursor($MENU_2, 0) GUICtrlSetColor($MENU_3, 0xFFFFFF) GUICtrlSetBkColor($MENU_3, $COLOR_STANDARD) GUICtrlSetCursor($MENU_3, 0) EndFunc ;==>_Design Func _Hide_All() GUICtrlSetState($MENU_1_ELEMENT_1, $GUI_HIDE) GUICtrlSetState($MENU_2_ELEMENT_1, $GUI_HIDE) GUICtrlSetState($MENU_2_ELEMENT_2, $GUI_HIDE) EndFunc ;==>_Hide_All Func _Show($MENU_SHOW) _Hide_All() If $MENU_SHOW = 'Menu1' Then GUICtrlSetState($MENU_1_ELEMENT_1, $GUI_SHOW) ElseIf $MENU_SHOW = 'Menu2' Then GUICtrlSetState($MENU_2_ELEMENT_1, $GUI_SHOW) GUICtrlSetState($MENU_2_ELEMENT_2, $GUI_SHOW) ElseIf $MENU_SHOW = 'Menu3' Then EndIf EndFunc ;==>_Show Func _Previous_Hover_Cancel() If $MENU_HOVER = 'Menu1' Then If $MENU_SELECTED <> 'Menu1' Then GUICtrlSetBkColor($MENU_1, $COLOR_STANDARD) ElseIf $MENU_HOVER = 'Menu2' Then If $MENU_SELECTED <> 'Menu2' Then GUICtrlSetBkColor($MENU_2, $COLOR_STANDARD) ElseIf $MENU_HOVER = 'Menu3' Then If $MENU_SELECTED <> 'Menu3' Then GUICtrlSetBkColor($MENU_3, $COLOR_STANDARD) EndIf EndFunc ;==>_Previous_Hover_Cancel Func _Previous_Selected_Cancel() If $MENU_SELECTED = 'Menu1' Then GUICtrlSetBkColor($MENU_1, $COLOR_STANDARD) If $MENU_SELECTED = 'Menu2' Then GUICtrlSetBkColor($MENU_2, $COLOR_STANDARD) If $MENU_SELECTED = 'Menu3' Then GUICtrlSetBkColor($MENU_3, $COLOR_STANDARD) EndFunc ;==>_Previous_Selected_Cancel  
    • By Tony007
      Hi,
      is it possible to export only the area "$idOutput" with the TEXT as a PNG?
      Thanks
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> Example() Func Example() Local $hGUI = GUICreate("Test", 700, 700, -1, -1) Local $input1 = GUICtrlCreateInput("", 10, 10, 150, 20) Local $idButtonStart = GUICtrlCreateButton("Start", 200, 10, 50, 30) Local $idButtonClear = GUICtrlCreateButton("Clear", 260, 10, 50, 30) Local $idButtonExport = GUICtrlCreateButton("Export", 320, 10, 50, 30) Local $idOutput = GUICtrlCreateLabel("TEXT", 10, 50, 500, 500, BitOR($BS_PUSHLIKE, $SS_CENTER)) GUICtrlSetFont($idOutput, 45, 800, "", "Impact") GUISetState(@SW_SHOW, $hGUI) ; Run the GUI until the dialog is closed While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idButtonStart $ContentInput1 = GUICtrlRead($input1) GUICtrlSetData($idOutput, $ContentInput1) Case $idButtonClear GUICtrlSetData($input1, "") GUICtrlSetData($idOutput, "") Case $idButtonExport EndSwitch WEnd GUIDelete($hGUI) Exit EndFunc ;==>Example  
    • By muchki
      i am more or less happy with my code
      only the X button does not exit
      what can i do?
      I made an 'exit' button and it works
      pressing Esc works
      just the X button not working
       
      here's my code:
       
      URLTrimmer 1.5.2 12 21 2019.txt
    • By t0nZ
      Often I need to create a panel to monitor a lot of things (users, files, items etc) so I use this piece of code to create a dynamic grid of buttons.
      The number of buttons is variable, and it's related to the size of the gui, the size of the buttons and the distance between buttons.
      Every "button" is a set of three with a real button stacked on the top of two labels, imagine reading a .CSV file or an array or a database and displaying all the things using the labels (Text and COLOR too) and clickin' on the relative button you can call further info on the item or call a particular function.
      So you can decide the number of the buttons, the width of the buttons, and also the distance  between buttons.
      It's quick and dirty, simple  and very improvable (I know..) so fell free to play with the code.
      ;TEST ;GOL-Grill ;Grill test/template ; (c) 2019 NSC ; V.0.6 #Region ;************ Includes ************ #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <EditConstants.au3> #include <ProgressConstants.au3> #include <_GOLLOG.au3>; NSC first UDF #EndRegion ;************ Includes ************ Dim $agButton[1] Global $ButtonU, $rProgress, $form1, $labeltot, $ntotButtonS ; the number of buttons is variable based on the guisize, the button size and button distance, three examples.... ;Global $guiwidth = 850, $guiheight = 500, $buttonW = 150, $buttonHDistance = 10, $buttonVDistance = 20 ; SMALL GUI / BIG BUTTONS <- try it ! Global $guiwidth = 1500, $guiheight = 700, $buttonW = 90 , $buttonHDistance = 29, $buttonVDistance = 3; BIG GUI / SMALL BUTTONS ;Global $guiwidth = 1200, $guiheight = 800, $buttonW = 300, $buttonHDistance = 30, $buttonVDistance = 7; last two variables are horizontal and vertical distance between buttons Global $ver = "V.0.6" Gollog(">>>>> START") Dim $aResult[11] = [10, "a", "b", "c", "d", "e", "f", "g", "h", "i", "j"] ; this is an example, it can be an array, a DB, a .text file read in real time. Gui() Gollog("start analyzing...") Monitor() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE CLOSEClicked() Exit Case $ButtonU Monitor() Case Else For $i = 1 To $ntotButtonS If $nMsg = $agButton[$i] Then $Bhit = GUICtrlRead($agButton[$i]) infoB($Bhit) EndIf Next EndSwitch WEnd Func Gui() $form1 = GUICreate("Buttons on a grill " & $ver & " (c) NSC 2019", $guiwidth, $guiheight, 90, 10) $ButtonU = GUICtrlCreateButton("Update", 2, 2, 170, 50) $labeltot = GUICtrlCreateLabel("Total found", 5, 55) $Gollogedit = GUICtrlCreateEdit("", 2, $guiheight - 255, 180, 250, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN, $WS_BORDER)) $rProgress = GUICtrlCreateProgress($guiwidth - 18, 5, 16, $guiheight - 7, BitOR($PBS_SMOOTH, $PBS_VERTICAL, $WS_BORDER)) GUICtrlSetColor(-1, 0x00FF00) GUICtrlSetBkColor(-1, 0x000000) GUISetState(@SW_SHOW) EndFunc ;==>Gui Func Monitor() GUIDelete($form1) Gui() $leftSTART = 186 ;left align $topSTART = 5 ;start from top $lineDOWN = 45 + $buttonVDistance ; vertical line distance 45 is buttons very near $extraHSTEP = 3 ; extra line distance $buttonSEMIH = 15 ; height of one of the 3 vertical impiled semibuttons $separatorSEMIH = 2 ;vertical distance between 3 semibuttons $separatorW = 2 ;aux horizontal distance ;---------- derived measures $rightLIMIT = $guiwidth - 123 ; right limit befor Carriage Return $leftINCREMENT = $buttonHDistance + $buttonW ; horizontal increment button after button $leftSTEP = $leftSTART ;incremental horizontal $topSTEP = $topSTART ;incremental vertical $foundB = $aResult[0] GUICtrlSetData($labeltot, "Found n°" & $foundB) $ntotButtonS = 0 $nomorebuttons = 0 For $i = 1 To $foundB Local $itemFound = $aResult[$i] ;\TA1000 Gollog($itemFound) GUICtrlCreateGroup('', $leftSTEP, $topSTEP - 3, $buttonW + 3, 50) ;______first-----------------------------_______line___________________UNO________11111_____\\\\\\\\\\------------ Local $textbutton = "button n°" & $i _ArrayAdd($agButton, GUICtrlCreateButton($textbutton, $leftSTEP + $separatorSEMIH, $topSTEP + $extraHSTEP, $buttonW, $buttonSEMIH, $BS_flat)) GUICtrlSetBkColor(-1, 0xccffcc) ;green, sort of GUICtrlSetFont(-1, 7, -1, -1, 'verdana') GUICtrlSetColor(-1, 0x000000) ;___second__________line___________________DUE ________222222-------------------------------------------------------------------- Local $textLINE2 = $itemFound GUICtrlCreateLabel($textLINE2, $leftSTEP + $separatorW, $topSTEP + $buttonSEMIH + $separatorSEMIH, $buttonW, $buttonSEMIH, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetBkColor(-1, 0xD2D7A8) GUICtrlSetFont(-1, 7, -1, -1, 'verdana') GUICtrlSetColor(-1, 0x000000) ; __third______line________tre___________________________________________________________333333-3333333-333333333-333333-33333-33333-3333-------------------------------- Local $textLINE3 = "line3" GUICtrlCreateLabel($textLINE3, $leftSTEP + $separatorW, $topSTEP + $buttonSEMIH + $buttonSEMIH + $separatorSEMIH, $buttonW, $buttonSEMIH, BitOR($SS_CENTER, $SS_CENTERIMAGE)) ; NSC modify GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetFont(-1, 7, -1, -1, 'verdana') GUICtrlSetColor(-1, 0x000000) $ntotButtonS += 1 GUICtrlSetData($rProgress, (100 * $ntotButtonS / $foundB)) If $leftSTEP + $buttonW < $rightLIMIT Then ; $leftSTEP += $leftINCREMENT ;53 Else $leftSTEP = $leftSTART $topSTEP += $lineDOWN If $topSTEP >= $guiheight - 50 Then $nomorebuttons = 1 Gollog("displayed " & $ntotButtonS & " buttons") Gollog("NO more buttons !") EndIf EndIf Sleep(100) ; REMOVE is only for demo Next While $nomorebuttons = 0 ; draw empty buttons (nice to do) $ntotButtonS += 1 _ArrayAdd($agButton, GUICtrlCreateButton("B-" & $ntotButtonS, $leftSTEP + $separatorSEMIH, $topSTEP + $extraHSTEP, $buttonW, $buttonSEMIH, $BS_flat)) If $leftSTEP + $buttonW < $rightLIMIT Then ; $leftSTEP += $leftINCREMENT Else $leftSTEP = $leftSTART $topSTEP += $lineDOWN If $topSTEP >= $guiheight - 50 Then $nomorebuttons = 1 Gollog("displayed " & $ntotButtonS & " buttons") Gollog("NO more buttons !") EndIf EndIf WEnd GUISetState(@SW_SHOW) EndFunc ;==>Monitor Func infoB($Bhit) ; this function act on the pressed button, it's an example so assign the task you need. gollog("infoB -> " & $Bhit) EndFunc ;==>infoB Func CLOSEClicked() MsgBox(64, "exit", "program exiting", 1) Gollog("<---STOP") Exit EndFunc ;==>CLOSEClicked You will need also the Include from this post for the LOG (Gollog) instructions, but you can also just remove the gollog and the EDIT box.
      Look at the screenshot, It's from an APP made using this code.

      21/11/2019 V.0.6
      Script lightly updated with better management of buttons size and distance.
       
×
×
  • Create New...