Jump to content

Looking for a GUI - objects and lines in the window


Recommended Posts

I finally figured it out, but I think I need to create a list of things to do, and in what order - for dealing with GDI+ graphics, is there any WIKI, on how to use these functions. I mean the help files are helpful, but they really do not describe the order of things, and how to make something happen on a given control. Not complaining, just am having a very hard time figuring this out.

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>

#include <StaticConstants.au3>

AutoItSetOption("MouseCoordMode", 2)

Global $g_hGUI, $g_hImage, $g_hGDIBitmap, $g_aCtrls[4][9], $hGraphics
Global $ci_MainWidth = 1000, $ci_MainHeight = 800

Example()

Func Example()
    AutoItSetOption("GUIOnEventMode", 1)

    ; X64 running support
    Local $sWow64 = ""
    If @AutoItX64 Then $sWow64 = "\Wow6432Node"

    ;get AutoIt install dir
    Local $sRegPath = "HKLM\SOFTWARE" & $sWow64 & "\AutoIt v3\AutoIt"

    Local $sFile = RegRead($sRegPath, "InstallDir") & "\Examples\GUI\logo4.gif"
    If Not FileExists($sFile) Then
        MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", $sFile & " not found!", 30)
        Exit
    EndIf
    ;$sFile = 'bulb0.jpg'
    If FileExists('logo4.gif') Then $sFile = 'logo4.gif'
    Local $i

    _GDIPlus_Startup()

    $g_hGUI = GUICreate("GDI+", $ci_MainWidth, $ci_MainHeight)

    For $i = 0 To UBound($g_aCtrls) - 1
        $g_aCtrls[$i][1] = 0 ;100 + $i * 150 ;x pos (Starting Position)
        $g_aCtrls[$i][2] = 250 + $i * 120 ;y pos
        $g_aCtrls[$i][0] = GUICtrlCreatePic("", $g_aCtrls[$i][1], $g_aCtrls[$i][2], 169, 68) ;, $SS_BITMAP) ;ctrl id
        $g_aCtrls[$i][3] = 100 ;min x pos
        $g_aCtrls[$i][4] = 250 ; $g_aCtrls[$i][2] - 20 ;min y pos
        Local $aImagePos = ControlGetPos($g_hGUI, '', $g_aCtrls[$i][0])
        $g_aCtrls[$i][5] = $ci_MainWidth - $aImagePos[2] - 10; $ci_MainHeight ;max x pos
        $g_aCtrls[$i][6] = $ci_MainHeight - $aImagePos[3] - 10 ; $g_aCtrls[$i][2] + 20 ;max y pos
        ; have to resize as you are making the control
        $g_aCtrls[$i][7] = _GDIPlus_ImageLoadFromFile($sFile)
        $g_aCtrls[$i][7] = _GDIPlus_ImageResize($g_aCtrls[$i][7], 50, 50)
        $g_aCtrls[$i][8] = _GDIPlus_BitmapCreateHBITMAPFromBitmap($g_aCtrls[$i][7])
    Next


_WinAPI_RedrawWindow($g_hGUI, 0, 0, $RDW_UPDATENOW)

    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    GUISetState(@SW_SHOW)

    ; ScreenUpdate
    CtrlMove($g_aCtrls, 0, $g_hGUI)

    Local $aMChk

    Do
        $aMChk = GUIGetCursorInfo($g_hGUI)
        Switch $aMChk[4]
            Case $g_aCtrls[0][0]
                CtrlMove($g_aCtrls, 0, $g_hGUI)
            Case $g_aCtrls[1][0]
                CtrlMove($g_aCtrls, 1, $g_hGUI)
            Case $g_aCtrls[2][0]
                CtrlMove($g_aCtrls, 2, $g_hGUI)
            Case $g_aCtrls[3][0]
                CtrlMove($g_aCtrls, 3, $g_hGUI)
        EndSwitch
        _GDIPlus_GraphicsDrawRect($hGraphics, $g_aCtrls[0][3], $g_aCtrls[0][4], $ci_MainWidth - 110, $ci_MainHeight - 260)
    Until Not Sleep(50)
EndFunc   ;==>Example

Func CtrlMove(ByRef $g_aCtrls, $iCtrl, $g_hGUI)
    Local $aCtrlPos = ControlGetPos($g_hGUI, "", $g_aCtrls[$iCtrl][0])
    Local $iDX = Abs(MouseGetPos(0) - $aCtrlPos[0])
    Local $iDY = Abs(MouseGetPos(1) - $aCtrlPos[1])
    Local $iX, $iY

    Static $bRan = False
    If Not $bRan Then
        ;MsgBox('','','splash screen - starting')
        For $x = 0 To UBound($g_aCtrls) - 1
            $aCtrlPos = ControlGetPos($g_hGUI, "", $g_aCtrls[$x][0])
            ;#cs
            ;Remove Current Image and replace with smaller one...
            _WinAPI_DeleteObject(GUICtrlSendMsg($g_aCtrls[$x][0], 0x0172, $IMAGE_BITMAP, $g_aCtrls[$x][8])) ;$STM_SETIMAGE = 0x0172
            Sleep(20)
            Local $hBitmap_Scaled = _GDIPlus_ImageResize($g_aCtrls[$x][7], 50, 50)
            If @error Then MsgBox('', '_GDIPlus_ImageResize ' & @error, $hBitmap_Scaled)
            Sleep(20)
            ;
            Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($g_hGUI) ;create a graphics object from a window handle
            If @error Then MsgBox('', '_GDIPlus_GraphicsCreateFromHWND ' & @error, $hGraphics)
            Sleep(20)
            ;
            _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap_Scaled, $aCtrlPos[0], $aCtrlPos[1]) ;$g_aCtrls[$iCtrl][3], $g_aCtrls[$iCtrl][4]) ;MouseGetPos(0), MouseGetPos(1)) ; $aCtrlPos[0], $aCtrlPos[1]) ;$iDX, $iDY)
            Sleep(20)
            $g_aCtrls[$x][8] = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_Scaled) ; handle to a HBITMAP (a handle to a bitmap from a bitmap object)
            Sleep(20)
            $iPic_W = _GDIPlus_ImageGetWidth($hBitmap_Scaled)
            $iPic_H = _GDIPlus_ImageGetHeight($hBitmap_Scaled)
            ;#ce
            _WinAPI_RedrawWindow($g_hGUI, 0, 0, $RDW_UPDATENOW)
        Next

        _WinAPI_RedrawWindow($g_hGUI, 0, 0, $RDW_UPDATENOW)
        $bRan = True
    Else
        ConsoleWrite($aCtrlPos[0] & ',' & $aCtrlPos[1] & @CRLF)
        ;#cs
            ;Remove Current Image and replace with smaller one...
            _WinAPI_DeleteObject(GUICtrlSendMsg($g_aCtrls[$iCtrl][0], 0x0172, $IMAGE_BITMAP, $g_aCtrls[$iCtrl][8])) ;$STM_SETIMAGE = 0x0172
            Sleep(20)
            Local $hBitmap_Scaled = _GDIPlus_ImageResize($g_aCtrls[$iCtrl][7], 50, 50)
            If @error Then MsgBox('', '_GDIPlus_ImageResize ' & @error, $hBitmap_Scaled)
            Sleep(20)
            ;
            Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($g_hGUI) ;create a graphics object from a window handle
            If @error Then MsgBox('', '_GDIPlus_GraphicsCreateFromHWND ' & @error, $hGraphics)
            Sleep(20)
            ;
            _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap_Scaled, $aCtrlPos[0], $aCtrlPos[1]) ;$g_aCtrls[$iCtrl][3], $g_aCtrls[$iCtrl][4]) ;MouseGetPos(0), MouseGetPos(1)) ; $aCtrlPos[0], $aCtrlPos[1]) ;$iDX, $iDY)
            Sleep(20)
            $g_aCtrls[$iCtrl][8] = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_Scaled) ; handle to a HBITMAP (a handle to a bitmap from a bitmap object)
            Sleep(20)
            $iPic_W = _GDIPlus_ImageGetWidth($hBitmap_Scaled)
            $iPic_H = _GDIPlus_ImageGetHeight($hBitmap_Scaled)
            $g_aCtrls[$iCtrl][5] = $ci_MainWidth - $iPic_W - 10 ; width
            $g_aCtrls[$iCtrl][6] = $ci_MainHeight - $iPic_H - 10 ; height
            ;#ce

            $hGraphics = _GDIPlus_GraphicsCreateFromHWND($g_hGUI)

    ;$hGraphics = _GDIPlus_ImageGetGraphicsContext($g_hGUI)
    ; Draw a frame around the inserted image
    _GDIPlus_GraphicsDrawRect($hGraphics, $g_aCtrls[0][3], $g_aCtrls[0][4], $ci_MainWidth - 110, $ci_MainHeight - 260)
    ;_GDIPlus_GraphicsDrawRect($hGraphics, 300, 300, 300, 300)
    ;_WinAPI_DrawLine ( $g_hGUI, $g_aCtrls[0][3], $g_aCtrls[0][4], $ci_MainWidth - 20, $ci_MainHeight - 20 )


    EndIf

    While GUIGetCursorInfo($g_hGUI)[2]
        $iX = MouseGetPos(0) - $iDX
        $iY = MouseGetPos(1) - $iDY
        $aCtrlPos = ControlGetPos($g_hGUI, "", $g_aCtrls[$iCtrl][0])
        $iX_ = $aCtrlPos[0]
        $iY_ = $aCtrlPos[1]
        ConsoleWrite(' ' & $iX & ' ' & $iY & @CRLF)

        ; ternary operator
        ;
        GUICtrlSetPos($g_aCtrls[$iCtrl][0], ($iX < $g_aCtrls[$iCtrl][3]) ? $g_aCtrls[$iCtrl][3] : ($iX > $g_aCtrls[$iCtrl][5]) ? $g_aCtrls[$iCtrl][5] : $iX, _
                ($iY < $g_aCtrls[$iCtrl][4]) ? $g_aCtrls[$iCtrl][4] : ($iY > $g_aCtrls[$iCtrl][6]) ? $g_aCtrls[$iCtrl][6] : $iY)
        Sleep(10)
        _GDIPlus_GraphicsDrawRect($hGraphics, $g_aCtrls[0][3], $g_aCtrls[0][4], $ci_MainWidth - 110, $ci_MainHeight - 260)
        _WinAPI_RedrawWindow($g_hGUI, 0, 0, $RDW_UPDATENOW)
        Sleep(10)
    WEnd

EndFunc   ;==>CtrlMove
;
Func _Exit()
    _WinAPI_DeleteObject($g_hGDIBitmap)
    _GDIPlus_ImageDispose($g_hImage)
    _GDIPlus_Shutdown()
    GUIDelete($g_hGUI)
    Exit
EndFunc   ;==>_Exit

 

'

 

 

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

I am trying to further this example, but am stuck on getting the images to move (after being moved over another object). There is a msgbox('','','hit'), that when enabled, lets only one image move, the one that is being move on top of the original. I do not want the MsgBox to hit, but still want only the image that is being moved, to move to the correct position, but when I disable the msgbox - it moves both images.

To test this example...move an image to the right side of the screen. Now move another on top of it, making sure the mouse is over the first image (still working on the image and not the mouse, but it will come later)

So for those that I confused...I am trying to not allow images to move on top of each other - blocking them from staying over each other. For now, all I have is the mouse over the image working...so you have to release the second image, while the mouse is over the first image.

Here is the code...can someone suggest a way of working this out?

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>

#include <StaticConstants.au3>

AutoItSetOption("MouseCoordMode", 2)

Global $g_hGUI, $g_hImage, $g_hGDIBitmap, $g_aCtrls[4][13], $hGraphics
Global $ci_MainWidth = 1000, $ci_MainHeight = 800

Example()

Func Example()
    AutoItSetOption("GUIOnEventMode", 1)

    ; X64 running support
    Local $sWow64 = ""
    If @AutoItX64 Then $sWow64 = "\Wow6432Node"

    ;get AutoIt install dir
    Local $sRegPath = "HKLM\SOFTWARE" & $sWow64 & "\AutoIt v3\AutoIt"

    Local $sFile = RegRead($sRegPath, "InstallDir") & "\Examples\GUI\logo4.gif"
    If Not FileExists($sFile) Then
        MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", $sFile & " not found!", 30)
        Exit
    EndIf
    ;$sFile = 'bulb0.jpg'
    If FileExists('logo4.gif') Then $sFile = 'logo4.gif'
    Local $i

    _GDIPlus_Startup()

    $g_hGUI = GUICreate("GDI+", $ci_MainWidth, $ci_MainHeight)

    For $i = 0 To UBound($g_aCtrls) - 1
        $g_aCtrls[$i][1] = 0 ;100 + $i * 150 ;x pos (Starting Position)
        $g_aCtrls[$i][2] = 250 + $i * 120 ;y pos
        $g_aCtrls[$i][0] = GUICtrlCreatePic("", $g_aCtrls[$i][1], $g_aCtrls[$i][2], 169, 68) ;, $SS_BITMAP) ;ctrl id
        $g_aCtrls[$i][3] = 100 ;min x pos
        $g_aCtrls[$i][4] = 250 ; $g_aCtrls[$i][2] - 20 ;min y pos
        Local $aImagePos = ControlGetPos($g_hGUI, '', $g_aCtrls[$i][0])
        $g_aCtrls[$i][5] = $ci_MainWidth - $aImagePos[2] - 10; $ci_MainHeight ;max x pos
        $g_aCtrls[$i][6] = $ci_MainHeight - $aImagePos[3] - 10 ; $g_aCtrls[$i][2] + 20 ;max y pos
        ; have to resize as you are making the control
        $g_aCtrls[$i][7] = _GDIPlus_ImageLoadFromFile($sFile)
        $g_aCtrls[$i][7] = _GDIPlus_ImageResize($g_aCtrls[$i][7], 50, 50)
        $g_aCtrls[$i][8] = _GDIPlus_BitmapCreateHBITMAPFromBitmap($g_aCtrls[$i][7])
        $g_aCtrls[$i][10] =   $g_aCtrls[$i][1]

        $g_aCtrls[$i][11] =  $g_aCtrls[$i][2]
    Next


_WinAPI_RedrawWindow($g_hGUI, 0, 0, $RDW_UPDATENOW)

    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    GUISetState(@SW_SHOW)

    ; ScreenUpdate
    CtrlMove($g_aCtrls, 0, $g_hGUI)

    Local $aMChk

    Do
        $aMChk = GUIGetCursorInfo($g_hGUI)
        Switch $aMChk[4]
            Case $g_aCtrls[0][0]
                CtrlMove($g_aCtrls, 0, $g_hGUI)
                CheckObjectLocation(0)
            Case $g_aCtrls[1][0]
                CtrlMove($g_aCtrls, 1, $g_hGUI)
                CheckObjectLocation(1)
            Case $g_aCtrls[2][0]
                CtrlMove($g_aCtrls, 2, $g_hGUI)
                CheckObjectLocation(2)
            Case $g_aCtrls[3][0]
                CtrlMove($g_aCtrls, 3, $g_hGUI)
                CheckObjectLocation(3)
        EndSwitch
        _GDIPlus_GraphicsDrawRect($hGraphics, $g_aCtrls[0][3], $g_aCtrls[0][4], $ci_MainWidth - 110, $ci_MainHeight - 260)
    Until Not Sleep(50)
EndFunc   ;==>Example

Func CtrlMove(ByRef $g_aCtrls, $iCtrl, $g_hGUI)
    Local $aCtrlPos = ControlGetPos($g_hGUI, "", $g_aCtrls[$iCtrl][0])
    Local $iDX = Abs(MouseGetPos(0) - $aCtrlPos[0])
    Local $iDY = Abs(MouseGetPos(1) - $aCtrlPos[1])
    Local $iX, $iY

    Static $bRan = False
    If Not $bRan Then
        ;MsgBox('','','splash screen - starting')
        For $x = 0 To UBound($g_aCtrls) - 1
            $aCtrlPos = ControlGetPos($g_hGUI, "", $g_aCtrls[$x][0])
            ;#cs
            ;Remove Current Image and replace with smaller one...
            _WinAPI_DeleteObject(GUICtrlSendMsg($g_aCtrls[$x][0], 0x0172, $IMAGE_BITMAP, $g_aCtrls[$x][8])) ;$STM_SETIMAGE = 0x0172
            Sleep(20)
            Local $hBitmap_Scaled = _GDIPlus_ImageResize($g_aCtrls[$x][7], 50, 50)
            If @error Then MsgBox('', '_GDIPlus_ImageResize ' & @error, $hBitmap_Scaled)
            Sleep(20)
            ;
            Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($g_hGUI) ;create a graphics object from a window handle
            If @error Then MsgBox('', '_GDIPlus_GraphicsCreateFromHWND ' & @error, $hGraphics)
            Sleep(20)
            ;
            _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap_Scaled, $aCtrlPos[0], $aCtrlPos[1]) ;$g_aCtrls[$iCtrl][3], $g_aCtrls[$iCtrl][4]) ;MouseGetPos(0), MouseGetPos(1)) ; $aCtrlPos[0], $aCtrlPos[1]) ;$iDX, $iDY)
            Sleep(20)
            $g_aCtrls[$x][8] = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_Scaled) ; handle to a HBITMAP (a handle to a bitmap from a bitmap object)
            Sleep(20)
            $iPic_W = _GDIPlus_ImageGetWidth($hBitmap_Scaled)
            $iPic_H = _GDIPlus_ImageGetHeight($hBitmap_Scaled)
            ;#ce
            _WinAPI_RedrawWindow($g_hGUI, 0, 0, $RDW_UPDATENOW)
        Next

        _WinAPI_RedrawWindow($g_hGUI, 0, 0, $RDW_UPDATENOW)
        $bRan = True
    Else
        ConsoleWrite($aCtrlPos[0] & ',' & $aCtrlPos[1] & @CRLF)
        ;#cs
            ;Remove Current Image and replace with smaller one...
            _WinAPI_DeleteObject(GUICtrlSendMsg($g_aCtrls[$iCtrl][0], 0x0172, $IMAGE_BITMAP, $g_aCtrls[$iCtrl][8])) ;$STM_SETIMAGE = 0x0172
            Sleep(20)
            Local $hBitmap_Scaled = _GDIPlus_ImageResize($g_aCtrls[$iCtrl][7], 50, 50)
            If @error Then MsgBox('', '_GDIPlus_ImageResize ' & @error, $hBitmap_Scaled)
            Sleep(20)
            ;
            Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($g_hGUI) ;create a graphics object from a window handle
            If @error Then MsgBox('', '_GDIPlus_GraphicsCreateFromHWND ' & @error, $hGraphics)
            Sleep(20)
            ;
            _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap_Scaled, $aCtrlPos[0], $aCtrlPos[1]) ;$g_aCtrls[$iCtrl][3], $g_aCtrls[$iCtrl][4]) ;MouseGetPos(0), MouseGetPos(1)) ; $aCtrlPos[0], $aCtrlPos[1]) ;$iDX, $iDY)
            Sleep(20)
            $g_aCtrls[$iCtrl][8] = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_Scaled) ; handle to a HBITMAP (a handle to a bitmap from a bitmap object)
            Sleep(20)
            $iPic_W = _GDIPlus_ImageGetWidth($hBitmap_Scaled)
            $iPic_H = _GDIPlus_ImageGetHeight($hBitmap_Scaled)
            $g_aCtrls[$iCtrl][5] = $ci_MainWidth - $iPic_W - 10 ; width
            $g_aCtrls[$iCtrl][6] = $ci_MainHeight - $iPic_H - 10 ; height
            ;#ce

            $hGraphics = _GDIPlus_GraphicsCreateFromHWND($g_hGUI)

    ;$hGraphics = _GDIPlus_ImageGetGraphicsContext($g_hGUI)
    ; Draw a frame around the inserted image
    _GDIPlus_GraphicsDrawRect($hGraphics, $g_aCtrls[0][3], $g_aCtrls[0][4], $ci_MainWidth - 110, $ci_MainHeight - 260)
    ;_GDIPlus_GraphicsDrawRect($hGraphics, 300, 300, 300, 300)
    ;_WinAPI_DrawLine ( $g_hGUI, $g_aCtrls[0][3], $g_aCtrls[0][4], $ci_MainWidth - 20, $ci_MainHeight - 20 )


    EndIf

    While GUIGetCursorInfo($g_hGUI)[2]
        $iX = MouseGetPos(0) - $iDX
        $iY = MouseGetPos(1) - $iDY
        $aCtrlPos = ControlGetPos($g_hGUI, "", $g_aCtrls[$iCtrl][0])
        $iX_ = $aCtrlPos[0]
        $iY_ = $aCtrlPos[1]
        ConsoleWrite(' ' & $iX & ' ' & $iY & @CRLF)

        ; ternary operator
        ;
        #cs
        GUICtrlSetPos($g_aCtrls[$iCtrl][0], ($iX < $g_aCtrls[$iCtrl][3]) ? $g_aCtrls[$iCtrl][3] : ($iX > $g_aCtrls[$iCtrl][5]) ? $g_aCtrls[$iCtrl][5] : $iX, _
                ($iY < $g_aCtrls[$iCtrl][4]) ? $g_aCtrls[$iCtrl][4] : ($iY > $g_aCtrls[$iCtrl][6]) ? $g_aCtrls[$iCtrl][6] : $iY)
        #ce
        Sleep(10)
        _GDIPlus_GraphicsDrawRect($hGraphics, $g_aCtrls[0][3], $g_aCtrls[0][4], $ci_MainWidth - 110, $ci_MainHeight - 260)
        _WinAPI_RedrawWindow($g_hGUI, 0, 0, $RDW_UPDATENOW)
        Sleep(10)
        Local $iX_, $iY_
        If $iX < $g_aCtrls[$iCtrl][3] Then ; get x
            $iX_ = $g_aCtrls[$iCtrl][3]
        ElseIf $iX > $g_aCtrls[$iCtrl][5] Then ; get x
            $iX_ = $g_aCtrls[$iCtrl][5]
        Else
            $iX_ = $iX
        EndIf

        If $iY < $g_aCtrls[$iCtrl][4] Then
            $iY_ = $g_aCtrls[$iCtrl][4]
        ElseIf $iY > $g_aCtrls[$iCtrl][6] Then
            $iY_ = $g_aCtrls[$iCtrl][6]
        Else
            $iY_ = $iY
        EndIf

        ;MsgBox('', '', $iX_ & ',' & $iY_)
        GUICtrlSetPos($g_aCtrls[$iCtrl][0], $iX_, $iY_)
        Sleep(10)

        $g_aCtrls[$iCtrl][10] = $iX_
        $g_aCtrls[$iCtrl][11] = $iY_



    WEnd

EndFunc   ;==>CtrlMove
;
Func _Exit()
    _WinAPI_DeleteObject($g_hGDIBitmap)
    _GDIPlus_ImageDispose($g_hImage)
    _GDIPlus_Shutdown()
    GUIDelete($g_hGUI)
    Exit
EndFunc   ;==>_Exit
;
Func CheckObjectLocation($CtrlID)
    Local $aReadCursorInfo = GUIGetCursorInfo($g_hGUI)
    For $x = 0 To UBound($g_aCtrls) - 1
        If $CtrlID = $x Then ContinueLoop
        Local $aImagePos = ControlGetPos($g_hGUI, '', $g_aCtrls[$x][0])
        If _WinAPI_PtInRectEx($aReadCursorInfo[0], $aReadCursorInfo[1], $g_aCtrls[$x][10], $g_aCtrls[$x][11], $g_aCtrls[$x][10] + $aImagePos[2], $g_aCtrls[$x][11] + $aImagePos[3]) Then
            Sleep(20)
            MsgBox('', '', 'hit') ; if I comment this out, both images move...
            GUICtrlSetPos($g_aCtrls[$CtrlID][0], $g_aCtrls[$x][10] - $aImagePos[2] - 50, $g_aCtrls[$x][11])
            ConsoleWrite($aReadCursorInfo[0] & ',' & $aReadCursorInfo[1] & @CRLF)
            ConsoleWrite($g_aCtrls[$x][3] & ',' & $g_aCtrls[$x][4] & @CRLF)
            ConsoleWrite($g_aCtrls[$x][5] & ',' & $g_aCtrls[$x][6] & @CRLF)
        EndIf
    Next

EndFunc   ;==>CheckObjectLocation
;#ce

 

.

.

EDIT

Possible fix is to move the mouse - I replaced the msgbox with:

MouseMove($g_aCtrls[$x][10] - $aImagePos[2] - 50, $g_aCtrls[$x][11], 0)

 

EDIT 2

That does not seem to work, as the next image will not move  to the next position - moving 1, 2 and then 3 onto 2, does not move 3 away

 

 

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

Anyone know of a post that might help me out? Or any thoughts on how to change what I have to get what I would like to do?

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

Seems I can not get that Math right...can anyone help me out. I feel I am close, but there is an area, beside the math part, that the image will align to, but it is not in my parameters - meaning the image will be closer to the blocked one, and then further away in areas around the corner of the blocked one.

I am trying to not allow the image to come in contact with the smaller square - that will be an image, but for testing wanted a square. The outer square is where I want the image to land (or not go past), but it bleeds into some areas, and then is further away around the corners of the outside square.

 

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <array.au3>
#include <StaticConstants.au3>

AutoItSetOption("MouseCoordMode", 2)

HotKeySet('!^s', 'Draw_A_Rect')

Global $g_hGUI, $g_hImage, $g_hGDIBitmap, $g_aCtrls[4][13], $hGraphics
Global $ci_MainWidth = 1000, $ci_MainHeight = 700
Global $bCheckLocation = False
Global $bDrawLine = False, $h_Pen


Example()

Func Example()
    AutoItSetOption("GUIOnEventMode", 1)

    ; X64 running support
    Local $sWow64 = ""
    If @AutoItX64 Then $sWow64 = "\Wow6432Node"

    ;get AutoIt install dir
    Local $sRegPath = "HKLM\SOFTWARE" & $sWow64 & "\AutoIt v3\AutoIt"

    Local $sFile = RegRead($sRegPath, "InstallDir") & "\Examples\GUI\logo4.gif"
    If Not FileExists($sFile) Then
        MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", $sFile & " not found!", 30)
        Exit
    EndIf
    ;$sFile = 'bulb0.jpg'
    If FileExists('logo4.gif') Then $sFile = 'logo4.gif'
    Local $i
    Local $sTitle = "GDI+"
    _GDIPlus_Startup()
    $h_Pen = _GDIPlus_PenCreate(0xFFFF0000)
    $g_hGUI = GUICreate($sTitle, $ci_MainWidth, $ci_MainHeight)
    ;GUISetBkColor(0xffffff)

    For $i = 0 To UBound($g_aCtrls) - 1
        $g_aCtrls[$i][1] = 0 ;100 + $i * 150 ;x pos (Starting Position)
        $g_aCtrls[$i][2] = 250 + $i * 120 ;y pos
        $g_aCtrls[$i][0] = GUICtrlCreatePic("", $g_aCtrls[$i][1], $g_aCtrls[$i][2], 169, 68) ;, $SS_BITMAP) ;ctrl id
        $g_aCtrls[$i][3] = 100 ;min x pos
        $g_aCtrls[$i][4] = 150 ; $g_aCtrls[$i][2] - 20 ;min y pos
        Local $aImagePos = ControlGetPos($g_hGUI, '', $g_aCtrls[$i][0])
        $g_aCtrls[$i][5] = $ci_MainWidth - $aImagePos[2] - 10; $ci_MainHeight ;max x pos
        $g_aCtrls[$i][6] = $ci_MainHeight - $aImagePos[3] - 10 ; $g_aCtrls[$i][2] + 20 ;max y pos
        ; have to resize as you are making the control
        $g_aCtrls[$i][7] = _GDIPlus_ImageLoadFromFile($sFile)
        $g_aCtrls[$i][7] = _GDIPlus_ImageResize($g_aCtrls[$i][7], 50, 50)
        $g_aCtrls[$i][8] = _GDIPlus_BitmapCreateHBITMAPFromBitmap($g_aCtrls[$i][7])
        $g_aCtrls[$i][10] = $g_aCtrls[$i][1]

        $g_aCtrls[$i][11] = $g_aCtrls[$i][2]
    Next

    ;`($g_aCtrls)

    _WinAPI_RedrawWindow($g_hGUI, 0, 0, $RDW_UPDATENOW)
    GUISetOnEvent($GUI_EVENT_SECONDARYDOWN, 'Get_Stats')
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    GUISetState(@SW_SHOW)

    ; ScreenUpdate
    CtrlMove($g_aCtrls, 0, $g_hGUI)

    Local $aMChk

    Do
        ;ConsoleWrite('*' & @CRLF)
        $aMChk = GUIGetCursorInfo($g_hGUI)
        Switch $aMChk[4]
            Case $g_aCtrls[0][0]
                $bCheckLocation = False
                CtrlMove($g_aCtrls, 0, $g_hGUI)
                CheckObjectLocation($g_aCtrls, 0)
                ;$bCheckLocation = False

            Case $g_aCtrls[1][0]
                $bCheckLocation = False
                CtrlMove($g_aCtrls, 1, $g_hGUI)
                CheckObjectLocation($g_aCtrls, 1)
                ;$bCheckLocation = False
            Case $g_aCtrls[2][0]
                $bCheckLocation = False
                CtrlMove($g_aCtrls, 2, $g_hGUI)
                CheckObjectLocation($g_aCtrls, 2)
                ;$bCheckLocation = False
            Case $g_aCtrls[3][0]
                $bCheckLocation = False
                CtrlMove($g_aCtrls, 3, $g_hGUI)
                CheckObjectLocation($g_aCtrls, 3)
                ;$bCheckLocation = False
        EndSwitch

        ;_GDIPlus_GraphicsDrawRect($hGraphics, $g_aCtrls[0][3], $g_aCtrls[0][4], $ci_MainWidth - 110, $ci_MainHeight - 260)

    Until Not Sleep(50)
EndFunc   ;==>Example
;
Func Draw_A_Rect()
    ;If $bRunning Then
    ConsoleWrite('drawing...' & @CRLF)
    ;0xFF000000
    #cs
        While Not _IsPressed('05', $hDLL)

        $aMouseLocation = GUIGetCursorInfo($h_GUI)

        WEnd ; _IsPressed('05', $hDLL)

        _ArrayDisplay($aMouseLocation)
        Exit
    #ce
    If Not $bDrawLine Then
        $bDrawLine = True
    Else
        $bDrawLine = False
    EndIf

    ;$iX_ > 400 And $iX_ < 600 And $iY_ > 300 And $iY_ < 50 Then  $iX_ = 390
    _GDIPlus_GraphicsDrawRect($hGraphics, 400, 400, 200, 50, $h_Pen)
    ;_GDIPlus_GraphicsDrawLine($hGraphics, 135, 435, 435, 435)
    ;_ML_LineDraw(1, 2, 135, 435, 435, 435) ; $iPen, $hColor, $iThickness)
    ;EndIf
EndFunc   ;==>Draw_A_Rect
;
Func CtrlMove(ByRef $g_aCtrls, $iCtrl, $g_hGUI)
    Local $aCtrlPos = ControlGetPos($g_hGUI, "", $g_aCtrls[$iCtrl][0])
    Local $iDX = Abs(MouseGetPos(0) - $aCtrlPos[0])
    Local $iDY = Abs(MouseGetPos(1) - $aCtrlPos[1])
    Local $iX, $iY

    Static $bRan = False
    If Not $bRan Then
        ;MsgBox('','','splash screen - starting')
        For $x = 0 To UBound($g_aCtrls) - 1
            $aCtrlPos = ControlGetPos($g_hGUI, "", $g_aCtrls[$x][0])
            ;#cs
            ;Remove Current Image and replace with smaller one...
            _WinAPI_DeleteObject(GUICtrlSendMsg($g_aCtrls[$x][0], 0x0172, $IMAGE_BITMAP, $g_aCtrls[$x][8])) ;$STM_SETIMAGE = 0x0172
            Sleep(20)
            Local $hBitmap_Scaled = _GDIPlus_ImageResize($g_aCtrls[$x][7], 50, 50)
            If @error Then MsgBox('', '_GDIPlus_ImageResize ' & @error, $hBitmap_Scaled)
            Sleep(20)
            ;
            Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($g_hGUI) ;create a graphics object from a window handle
            If @error Then MsgBox('', '_GDIPlus_GraphicsCreateFromHWND ' & @error, $hGraphics)
            Sleep(20)
            ;
            _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap_Scaled, $aCtrlPos[0], $aCtrlPos[1]) ;$g_aCtrls[$iCtrl][3], $g_aCtrls[$iCtrl][4]) ;MouseGetPos(0), MouseGetPos(1)) ; $aCtrlPos[0], $aCtrlPos[1]) ;$iDX, $iDY)
            Sleep(20)
            $g_aCtrls[$x][8] = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_Scaled) ; handle to a HBITMAP (a handle to a bitmap from a bitmap object)
            Sleep(20)
            $iPic_W = _GDIPlus_ImageGetWidth($hBitmap_Scaled)
            $iPic_H = _GDIPlus_ImageGetHeight($hBitmap_Scaled)
            ;#ce
            _WinAPI_RedrawWindow($g_hGUI, 0, 0, $RDW_UPDATENOW)
        Next

        _WinAPI_RedrawWindow($g_hGUI, 0, 0, $RDW_UPDATENOW)
        $bRan = True
    Else
        ConsoleWrite($aCtrlPos[0] & ',' & $aCtrlPos[1] & @CRLF)
        ;#cs
        ;Remove Current Image and replace with smaller one...
        _WinAPI_DeleteObject(GUICtrlSendMsg($g_aCtrls[$iCtrl][0], 0x0172, $IMAGE_BITMAP, $g_aCtrls[$iCtrl][8])) ;$STM_SETIMAGE = 0x0172
        Sleep(20)
        Local $hBitmap_Scaled = _GDIPlus_ImageResize($g_aCtrls[$iCtrl][7], 50, 50)
        If @error Then MsgBox('', '_GDIPlus_ImageResize ' & @error, $hBitmap_Scaled)
        Sleep(20)
        ;
        Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($g_hGUI) ;create a graphics object from a window handle
        If @error Then MsgBox('', '_GDIPlus_GraphicsCreateFromHWND ' & @error, $hGraphics)
        Sleep(20)
        ;
        _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap_Scaled, $aCtrlPos[0], $aCtrlPos[1]) ;$g_aCtrls[$iCtrl][3], $g_aCtrls[$iCtrl][4]) ;MouseGetPos(0), MouseGetPos(1)) ; $aCtrlPos[0], $aCtrlPos[1]) ;$iDX, $iDY)
        Sleep(20)
        $g_aCtrls[$iCtrl][8] = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_Scaled) ; handle to a HBITMAP (a handle to a bitmap from a bitmap object)
        Sleep(20)
        $iPic_W = _GDIPlus_ImageGetWidth($hBitmap_Scaled)
        $iPic_H = _GDIPlus_ImageGetHeight($hBitmap_Scaled)
        $g_aCtrls[$iCtrl][5] = $ci_MainWidth - $iPic_W - 10 ; width
        $g_aCtrls[$iCtrl][6] = $ci_MainHeight - $iPic_H - 10 ; height
        ;#ce

        $hGraphics = _GDIPlus_GraphicsCreateFromHWND($g_hGUI)

        ;$hGraphics = _GDIPlus_ImageGetGraphicsContext($g_hGUI)
        ; Draw a frame around the inserted image
        ;_GDIPlus_GraphicsDrawRect($hGraphics, $g_aCtrls[0][3], $g_aCtrls[0][4], $ci_MainWidth - 110, $ci_MainHeight - 260)
        ;_GDIPlus_GraphicsDrawRect($hGraphics, 300, 300, 300, 300)
        ;_WinAPI_DrawLine ( $g_hGUI, $g_aCtrls[0][3], $g_aCtrls[0][4], $ci_MainWidth - 20, $ci_MainHeight - 20 )


    EndIf

    While GUIGetCursorInfo($g_hGUI)[2]
        $iX = MouseGetPos(0) - $iDX
        $iY = MouseGetPos(1) - $iDY
        $aCtrlPos = ControlGetPos($g_hGUI, "", $g_aCtrls[$iCtrl][0])
        $iX_ = $aCtrlPos[0]
        $iY_ = $aCtrlPos[1]
        ConsoleWrite(' --REAL MOUSE-- ' & MouseGetPos(0) & ' ' & MouseGetPos(1) & @CRLF)
        ; ternary operator
        ;
        #cs
            GUICtrlSetPos($g_aCtrls[$iCtrl][0], ($iX < $g_aCtrls[$iCtrl][3]) ? $g_aCtrls[$iCtrl][3] : ($iX > $g_aCtrls[$iCtrl][5]) ? $g_aCtrls[$iCtrl][5] : $iX, _
            ($iY < $g_aCtrls[$iCtrl][4]) ? $g_aCtrls[$iCtrl][4] : ($iY > $g_aCtrls[$iCtrl][6]) ? $g_aCtrls[$iCtrl][6] : $iY)
        #ce
        Sleep(10)
        ; _GDIPlus_GraphicsDrawRect($hGraphics, $g_aCtrls[0][3], $g_aCtrls[0][4], $ci_MainWidth - 110, $ci_MainHeight - 260)
        ; _WinAPI_RedrawWindow($g_hGUI, 0, 0, $RDW_UPDATENOW)
        Sleep(10)
        Local $iX_, $iY_
        If $iX < $g_aCtrls[$iCtrl][3] Then ; get x
            $iX_ = $g_aCtrls[$iCtrl][3]
        ElseIf $iX > $g_aCtrls[$iCtrl][5] Then ; get x
            $iX_ = $g_aCtrls[$iCtrl][5]
        Else
            $iX_ = $iX
        EndIf

        If $iY < $g_aCtrls[$iCtrl][4] Then
            $iY_ = $g_aCtrls[$iCtrl][4]
        ElseIf $iY > $g_aCtrls[$iCtrl][6] Then
            $iY_ = $g_aCtrls[$iCtrl][6]
        Else
            $iY_ = $iY
        EndIf


        ; 400, 300, 200, 50,


        If Not _CheckLocation($g_aCtrls[$iCtrl][0], $iX_, $iY_) Then ContinueLoop



        #cs
            If $iX_ > 400 And $iX_ < 600 And $iY_ > 300 And $iY_ < 450 Then
            If $iX_ > 400 And $iX_ < 600 Then
            If
            $iX_ = 390
            If $iY_ > 300 And $iY_ < 450 Then $iY_ =

        #ce
        ;MsgBox('', '', $iX_ & ',' & $iY_)
        GUICtrlSetPos($g_aCtrls[$iCtrl][0], $iX_, $iY_)
        Sleep(10)

        $g_aCtrls[$iCtrl][10] = $iX_
        $g_aCtrls[$iCtrl][11] = $iY_


        ;_GDIPlus_GraphicsClear($hGraphics, 0xffffffff)
        ;_GDIPlus_GraphicsDrawLine($hGraphics, 535, 335, 835, 335, $h_Pen)

        ;$iX, $iY, $iWidth, $iHeight
        Local $xOffSet = 40
        _GDIPlus_GraphicsDrawRect($hGraphics, 300, 300, 50, 50, $h_Pen)
        _GDIPlus_GraphicsDrawRect($hGraphics, 300 - $xOffSet/2, 300 - $xOffSet/2, 90, 90, $h_Pen)

    WEnd
    ;_ArrayDisplay($g_aCtrls)

EndFunc   ;==>CtrlMove
;
Func _Exit()
    _WinAPI_DeleteObject($g_hGDIBitmap)
    _GDIPlus_ImageDispose($g_hImage)
    _GDIPlus_Shutdown()
    GUIDelete($g_hGUI)
    Exit
EndFunc   ;==>_Exit
;
Func _CheckLocation($iCtrl, $iX, $iY)
    Local $xOffSet = 40
    If ($iX < 350 + $xOffSet - _GDIPlus_ImageGetWidth($g_aCtrls[$iCtrl][7]) / 2 And _
            $iX > 300 - $xOffSet - _GDIPlus_ImageGetWidth($g_aCtrls[$iCtrl][7]) / 2) _
            And ($iY < 350 + $xOffSet - _GDIPlus_ImageGetHeight($g_aCtrls[$iCtrl][7]) / 2 And _
            $iY > 300 - $xOffSet - _GDIPlus_ImageGetHeight($g_aCtrls[$iCtrl][7]) / 2) Then
        Return False
    Else
        Return True
    EndIf
EndFunc   ;==>_CheckLocation
;
Func CheckObjectLocation(ByRef $g_aCtrls, $iCtrl)

    ;_GDIPlus_PathIsVisiblePoint

    ConsoleWrite('Checking Location...' & @CRLF)

    Local $aReadCursorInfo ;= GUIGetCursorInfo($g_hGUI)
    For $x = 0 To UBound($g_aCtrls) - 1
        ;ConsoleWrite('x = ' & $x & @CRLF)

        ;
        If $iCtrl = $x Then ContinueLoop
        $aReadCursorInfo = GUIGetCursorInfo($g_hGUI)
        ConsoleWrite('Mouse ' & $aReadCursorInfo[0] & '|' & $aReadCursorInfo[0] & @CRLF)
        Local $aImagePos = ControlGetPos($g_hGUI, '', $g_aCtrls[$x][0])
        If Not $bCheckLocation And _WinAPI_PtInRectEx($aReadCursorInfo[0], $aReadCursorInfo[1], $g_aCtrls[$x][10], $g_aCtrls[$x][11], $g_aCtrls[$x][10] + $aImagePos[2], $g_aCtrls[$x][11] + $aImagePos[3]) Then
            ;#cs
            Sleep(20)
            ;
            MouseMove($g_aCtrls[$x][10] - $aImagePos[2] - 50, $g_aCtrls[$x][11], 0)
            ConsoleWrite('+> XXX ' & $x & ' ' & $g_aCtrls[$x][10] & '|' & $g_aCtrls[$x][11] & @CRLF)
            ;
            ;MsgBox('', '', 'hit') ; if I comment this out, both images move...
            GUICtrlSetPos($g_aCtrls[$iCtrl][0], $g_aCtrls[$x][10] - $aImagePos[2] - 50, $g_aCtrls[$x][11])
            $g_aCtrls[$iCtrl][10] = $g_aCtrls[$x][10] - $aImagePos[2]
            $g_aCtrls[$iCtrl][11] = $g_aCtrls[$x][11]
            ConsoleWrite('+> MOVED ' & $iCtrl & ' ' & $g_aCtrls[$iCtrl][10] & '|' & $g_aCtrls[$iCtrl][11] & @CRLF)
            MouseClick('Left') ;, $g_aCtrls[$x][10] - $aImagePos[2] - 50, $g_aCtrls[$x][11])
            ;ConsoleWrite($aReadCursorInfo[0] & ',' & $aReadCursorInfo[1] & @CRLF)
            ;ConsoleWrite($g_aCtrls[$x][3] & ',' & $g_aCtrls[$x][4] & @CRLF)
            ;ConsoleWrite($g_aCtrls[$x][5] & ',' & $g_aCtrls[$x][6] & @CRLF)
            ;_ArrayDisplay($g_aCtrls)

            ;#ce
            ;ContinueLoop
            ;Return
            ExitLoop
        Else
            ConsoleWrite('!> ' & $x & ' ' & $g_aCtrls[$x][10] & '|' & $g_aCtrls[$x][11] & @CRLF)
        EndIf
    Next
    ConsoleWrite('+++' & @CRLF)
EndFunc   ;==>CheckObjectLocation
;#ce
Func Get_Stats()
    _ArrayDisplay($g_aCtrls)
EndFunc   ;==>Get_Stats

 

.

 

.

 

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

I will have next week a closer look to the collision problem. Meanwhile have a look here: https://www.autoitscript.com/forum/topic/170315-collision-detection-with-gdi/?do=findComment&comment=1245469

Maybe it will give you some more ideas.

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 comment
Share on other sites

I was going to start a new post on this, but maybe someone will read this and fill in the blanks - since it appears that might be the fix

 

https://www.autoitscript.com/autoit3/docs/libfunctions/_GDIPlus_PathIsVisiblePoint.htm

 

The graphic handle option, cuts off - there are a few help files with this same ending. Can someone fill in the blank?

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

The header is

; #FUNCTION# ====================================================================================================================
; Name...........: _GDIPlus_PathIsVisiblePoint
; Description ...: Determines whether a specified point lies in the area that is filled when a path is filled by a specified
;                  +Graphics object
; Syntax.........: _GDIPlus_PathIsVisiblePoint($hPath, $fX, $fY[, $hGraphics = 0])
; Parameters ....: $hPath       - Pointer to a GraphicsPath object
;                  $fX          - X coordinate of the point to test
;                  $fY          - Y coordinate of the point to test
;                  $hGraphics   - Pointer to a Graphics object that specifies a world-to-device transformation. If 0, the test is
;                   +done in world coordinates; otherwise, the test is done in device coordinates
; Return values .: Success      - True if the point lies in the interior of the path, False otherwise
;                  Failure      - -1
; Author ........: Authenticity
; Modified.......: Eukalyptus
; Remarks .......: None
; Related .......: None
; Link ..........; @@MsdnLink@@ GdipIsVisiblePathPoint
; Example .......; Yes
; ===============================================================================================================================

 

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 comment
Share on other sites

That is twice I have been schooled lol, never thought of going to source - thanks, will look into this soon. 

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

I was not able to understand the Path, so I started again with this, but for the life of me, I cannot figure out why it only works with the first image (the top one on the left). All the other ones, will allow for the any image to cover them. I have been at this for a few days, and no matter what I try, I cannot seem to get it right.

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <array.au3>
#include <StaticConstants.au3>

AutoItSetOption("MouseCoordMode", 2)

Global $g_hGUI, $g_hImage, $g_hGDIBitmap, $g_aCtrls[4][15], $hGraphics, $hPath
Global $ci_MainWidth = 1000, $ci_MainHeight = 700
Global $bCheckLocation = False
Global $bDrawLine = False, $h_Pen
Global $hBitmap_Scaled

Example()

Func Example()
    AutoItSetOption("GUIOnEventMode", 1)

    ; X64 running support
    Local $sWow64 = ""
    If @AutoItX64 Then $sWow64 = "\Wow6432Node"

    ;get AutoIt install dir
    Local $sRegPath = "HKLM\SOFTWARE" & $sWow64 & "\AutoIt v3\AutoIt"

    Local $sFile = RegRead($sRegPath, "InstallDir") & "\Examples\GUI\logo4.gif"
    If Not FileExists($sFile) Then
        MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", $sFile & " not found!", 30)
        Exit
    EndIf
    ;$sFile = 'bulb0.jpg'
    If FileExists('logo4.gif') Then $sFile = 'logo4.gif'
    Local $i
    Local $sTitle = "GDI+"
    _GDIPlus_Startup()
    $h_Pen = _GDIPlus_PenCreate(0xFFFF0000)
    $hPath = _GDIPlus_PathCreate() ;Create new path object
    $g_hGUI = GUICreate($sTitle, $ci_MainWidth, $ci_MainHeight)
    ;GUISetBkColor(0xffffff)

    For $i = 0 To UBound($g_aCtrls) - 1
        $g_aCtrls[$i][1] = 0 ;x pos (Starting Position)
        $g_aCtrls[$i][2] = 250 + $i * 120 ;y pos starting position
        $g_aCtrls[$i][0] = GUICtrlCreatePic("", $g_aCtrls[$i][1], $g_aCtrls[$i][2], 169, 68)
        $g_aCtrls[$i][3] = 100 ; min x pos
        $g_aCtrls[$i][4] = 150 ; min y pos
        Local $aImagePos = ControlGetPos($g_hGUI, '', $g_aCtrls[$i][0])
        $g_aCtrls[$i][5] = $ci_MainWidth - $aImagePos[2] - 10 ; max x pos
        $g_aCtrls[$i][6] = $ci_MainHeight - $aImagePos[3] - 10 ; max y pos
        ; have to resize as you are making the control to make sure the larger image is not on the screen
        $g_aCtrls[$i][7] = _GDIPlus_ImageLoadFromFile($sFile)
        $g_aCtrls[$i][7] = _GDIPlus_ImageResize($g_aCtrls[$i][7], 50, 50)
        $g_aCtrls[$i][8] = _GDIPlus_BitmapCreateHBITMAPFromBitmap($g_aCtrls[$i][7])
        $g_aCtrls[$i][10] = $g_aCtrls[$i][1] ; starting X - then updates to new X position
        $g_aCtrls[$i][11] = $g_aCtrls[$i][2] ; starting y - then updates to new Y position

        $g_aCtrls[$i][12] = _GDIPlus_ImageGetWidth($g_aCtrls[$i][7]) ; Width of image
        $g_aCtrls[$i][13] = _GDIPlus_ImageGetHeight($g_aCtrls[$i][7]) ; Height of image
    Next

    _WinAPI_RedrawWindow($g_hGUI, 0, 0, $RDW_UPDATENOW)
    GUISetOnEvent($GUI_EVENT_SECONDARYDOWN, 'Get_Stats')
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    GUISetState(@SW_SHOW)

    ; ScreenUpdate
    CtrlMove($g_aCtrls, 0, $g_hGUI)

    Local $aMChk

    Do
        ;ConsoleWrite('*' & @CRLF)
        $aMChk = GUIGetCursorInfo($g_hGUI)
        Switch $aMChk[4]
            Case $g_aCtrls[0][0]
                $bCheckLocation = False
                CtrlMove($g_aCtrls, 0, $g_hGUI)
                ;CheckObjectLocation($g_aCtrls, 0)
                ;$bCheckLocation = False
            Case $g_aCtrls[1][0]
                $bCheckLocation = False
                CtrlMove($g_aCtrls, 1, $g_hGUI)
                ;CheckObjectLocation($g_aCtrls, 1)
                ;$bCheckLocation = False
            Case $g_aCtrls[2][0]
                $bCheckLocation = False
                CtrlMove($g_aCtrls, 2, $g_hGUI)
                ;CheckObjectLocation($g_aCtrls, 2)
                ;$bCheckLocation = False
            Case $g_aCtrls[3][0]
                $bCheckLocation = False
                CtrlMove($g_aCtrls, 3, $g_hGUI)
                ;CheckObjectLocation($g_aCtrls, 3)
                ;$bCheckLocation = False
        EndSwitch

    Until Not Sleep(50)
EndFunc   ;==>Example
;
Func CtrlMove(ByRef $g_aCtrls, $iCtrl, $g_hGUI)
    Local $aCtrlPos = ControlGetPos($g_hGUI, "", $g_aCtrls[$iCtrl][0])
    Local $iDX = Abs(MouseGetPos(0) - $aCtrlPos[0])
    Local $iDY = Abs(MouseGetPos(1) - $aCtrlPos[1])
    Local $iX, $iY
    ;

        For $x = 0 To UBound($g_aCtrls) - 1
            $aCtrlPos = ControlGetPos($g_hGUI, "", $g_aCtrls[$x][0])
            _WinAPI_DeleteObject(GUICtrlSendMsg($g_aCtrls[$x][0], 0x0172, $IMAGE_BITMAP, $g_aCtrls[$x][8])) ;$STM_SETIMAGE = 0x0172
            Sleep(20)
            Local $hBitmap_Scaled = _GDIPlus_ImageResize($g_aCtrls[$x][7], 50, 50)
            If @error Then MsgBox('', '_GDIPlus_ImageResize ' & @error, $hBitmap_Scaled)
            Sleep(20)
            ;
            Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($g_hGUI) ;create a graphics object from a window handle
            If @error Then MsgBox('', '_GDIPlus_GraphicsCreateFromHWND ' & @error, $hGraphics)
            Sleep(20)
            ;
            _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap_Scaled, $aCtrlPos[0], $aCtrlPos[1])
            Sleep(20)
            $g_aCtrls[$x][8] = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_Scaled) ; handle to a HBITMAP (a handle to a bitmap from a bitmap object)
            Sleep(20)
            $iPic_W = _GDIPlus_ImageGetWidth($hBitmap_Scaled)
            $iPic_H = _GDIPlus_ImageGetHeight($hBitmap_Scaled)

            _WinAPI_RedrawWindow($g_hGUI, 0, 0, $RDW_UPDATENOW)
        Next

        _WinAPI_RedrawWindow($g_hGUI, 0, 0, $RDW_UPDATENOW)

    While GUIGetCursorInfo($g_hGUI)[2]
        $iX = MouseGetPos(0) - $iDX
        $iY = MouseGetPos(1) - $iDY
        $aCtrlPos = ControlGetPos($g_hGUI, "", $g_aCtrls[$iCtrl][0])
        $iX_ = $aCtrlPos[0]
        $iY_ = $aCtrlPos[1]
        ;ConsoleWrite(' --REAL MOUSE-- ' & MouseGetPos(0) & ' ' & MouseGetPos(1) & @CRLF)
        ; ternary operator
        ;
        #cs
            GUICtrlSetPos($g_aCtrls[$iCtrl][0], ($iX < $g_aCtrls[$iCtrl][3]) ? $g_aCtrls[$iCtrl][3] : ($iX > $g_aCtrls[$iCtrl][5]) ? $g_aCtrls[$iCtrl][5] : $iX, _
            ($iY < $g_aCtrls[$iCtrl][4]) ? $g_aCtrls[$iCtrl][4] : ($iY > $g_aCtrls[$iCtrl][6]) ? $g_aCtrls[$iCtrl][6] : $iY)
        #ce
        Sleep(10)
        Local $iX_, $iY_
        ; check boundries X
        If $iX < $g_aCtrls[$iCtrl][3] Then ; get x
            $iX_ = $g_aCtrls[$iCtrl][3]
        ElseIf $iX > $g_aCtrls[$iCtrl][5] Then ; get x
            $iX_ = $g_aCtrls[$iCtrl][5]
        Else
            $iX_ = $iX
        EndIf
        ; check boundries Y
        If $iY < $g_aCtrls[$iCtrl][4] Then
            $iY_ = $g_aCtrls[$iCtrl][4]
        ElseIf $iY > $g_aCtrls[$iCtrl][6] Then
            $iY_ = $g_aCtrls[$iCtrl][6]
        Else
            $iY_ = $iY
        EndIf

        ; Check to make sure no overlap
        If Not _CheckLocation($iCtrl, $iX_, $iY_) Then
            ContinueLoop
        Else
            ; move image to new position
            GUICtrlSetPos($g_aCtrls[$iCtrl][0], $iX_, $iY_)
            Sleep(10)
            $g_aCtrls[$iCtrl][10] = $iX_
            $g_aCtrls[$iCtrl][11] = $iY_
            ConsoleWrite('!> ' & $iCtrl & ' NEW VALUE...' & $g_aCtrls[$iCtrl][10] & ',' & $g_aCtrls[$iCtrl][11] & @CRLF)
        EndIf

        ;_GDIPlus_GraphicsDrawRect($hGraphics, 300, 300, 50, 50, $h_Pen)
        ;_GDIPlus_GraphicsDrawRect($hGraphics, 290, 290, 70, 70, $h_Pen)

    WEnd

EndFunc   ;==>CtrlMove
;
Func _Exit()
    _WinAPI_DeleteObject($g_hGDIBitmap)
    _GDIPlus_ImageDispose($g_hImage)
    _GDIPlus_Shutdown()
    GUIDelete($g_hGUI)
    Exit
EndFunc   ;==>_Exit
;
Func _CheckLocation($iCtrl, $iX, $iY)
    ;ConsoleWrite('Checking the locatoin...' & $iCtrl & ' ' & $iX & ',' & $iY & ',' & $_x & ',' & $_y & ',' & _GDIPlus_ImageGetWidth($hBitmap_Scaled) & ' ' & _GDIPlus_ImageGetHeight($hBitmap_Scaled) & @CRLF)
    ;ConsoleWrite('Checking the locatoin...' & _GDIPlus_ImageGetWidth($hBitmap_Scaled) & ' ' &  _GDIPlus_ImageGetHeight($hBitmap_Scaled) & @CRLF)

    Local $xOffSet = 10
    Local $aCtrlPos = ControlGetPos($g_hGUI, "", $g_aCtrls[$iCtrl][0])

    For $x = 0 To UBound($g_aCtrls) - 1

        ;ConsoleWrite('!>' & $iX & @CRLF)
        If _WinAPI_PtInRectEx($iX, $iY, $g_aCtrls[$x][10] - $aCtrlPos[2] - $xOffSet, $g_aCtrls[$x][11] - $aCtrlPos[3] - $xOffSet, $g_aCtrls[$x][10] + $aCtrlPos[2] + $xOffSet, $g_aCtrls[$x][11] + $aCtrlPos[3] + $xOffSet) Then
            Return False
        Else
            Return True
        EndIf
    Next
EndFunc   ;==>_CheckLocation
Func CheckObjectLocation(ByRef $g_aCtrls, $iCtrl)
    ConsoleWrite('Checking Location...' & @CRLF)

    Local $aReadCursorInfo ;= GUIGetCursorInfo($g_hGUI)
    For $x = 0 To UBound($g_aCtrls) - 1
        ;ConsoleWrite('x = ' & $x & @CRLF)

        ;
        If $iCtrl = $x Then ContinueLoop
        $aReadCursorInfo = GUIGetCursorInfo($g_hGUI)
        ConsoleWrite('Mouse ' & $aReadCursorInfo[0] & '|' & $aReadCursorInfo[0] & @CRLF)
        Local $aImagePos = ControlGetPos($g_hGUI, '', $g_aCtrls[$x][0])
        If Not $bCheckLocation And _WinAPI_PtInRectEx($aReadCursorInfo[0], $aReadCursorInfo[1], $g_aCtrls[$x][10], $g_aCtrls[$x][11], $g_aCtrls[$x][10] + $aImagePos[2], $g_aCtrls[$x][11] + $aImagePos[3]) Then
            ;#cs
            Sleep(20)
            ;
            MouseMove($g_aCtrls[$x][10] - $aImagePos[2] - 50, $g_aCtrls[$x][11], 0)
            ConsoleWrite('+> XXX ' & $x & ' ' & $g_aCtrls[$x][10] & '|' & $g_aCtrls[$x][11] & @CRLF)
            ;
            ;MsgBox('', '', 'hit') ; if I comment this out, both images move...
            GUICtrlSetPos($g_aCtrls[$iCtrl][0], $g_aCtrls[$x][10] - $aImagePos[2] - 50, $g_aCtrls[$x][11])
            $g_aCtrls[$iCtrl][10] = $g_aCtrls[$x][10] - $aImagePos[2]
            $g_aCtrls[$iCtrl][11] = $g_aCtrls[$x][11]
            ConsoleWrite('+> MOVED ' & $iCtrl & ' ' & $g_aCtrls[$iCtrl][10] & '|' & $g_aCtrls[$iCtrl][11] & @CRLF)
            MouseClick('Left') ;, $g_aCtrls[$x][10] - $aImagePos[2] - 50, $g_aCtrls[$x][11])
            ;ConsoleWrite($aReadCursorInfo[0] & ',' & $aReadCursorInfo[1] & @CRLF)
            ;ConsoleWrite($g_aCtrls[$x][3] & ',' & $g_aCtrls[$x][4] & @CRLF)
            ;ConsoleWrite($g_aCtrls[$x][5] & ',' & $g_aCtrls[$x][6] & @CRLF)
            ;_ArrayDisplay($g_aCtrls)

            ;#ce
            ;ContinueLoop
            ;Return
            ExitLoop
        Else
            ConsoleWrite('!> ' & $x & ' ' & $g_aCtrls[$x][10] & '|' & $g_aCtrls[$x][11] & @CRLF)
        EndIf
    Next
    ConsoleWrite('+++' & @CRLF)
EndFunc   ;==>CheckObjectLocation
;#ce
Func Get_Stats()
    _ArrayDisplay($g_aCtrls)
EndFunc   ;==>Get_Stats

 

.

.

 

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

I do not believe this function -

https://www.autoitscript.com/autoit3/docs/libfunctions/_GDIPlus_PathIsVisiblePoint.htm

is what I was looking for, as I am only using the squares for a reference - meaning, I am going to be moving the images on the left to the right, and once placed, I do not want other images to over lap them by an offset of X. Reading what this function does, it works with lines and arcs, and such.

https://msdn.microsoft.com/en-us/library/530a2kct(v=vs.110).aspx?f=255&MSPPError=-2147217396

I am still looking, though I thought I found a thread that would help, but lost it. It was random boxes floating down and when another came down it stopped at the top of the one below - though I do not remember if it was using the same function or not. And I have looked and still cannot find.

 

This is the closes I have gotten so far...I need to fine tune it.

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <array.au3>
#include <StaticConstants.au3>

AutoItSetOption("MouseCoordMode", 2)

Global $g_hGUI, $g_hImage, $g_hGDIBitmap, $g_aCtrls[4][15], $hGraphics, $hPath
Global $ci_MainWidth = 1000, $ci_MainHeight = 700
Global $bCheckLocation = False
Global $bDrawLine = False, $h_Pen
Global $hBitmap_Scaled

Example()

Func Example()
    AutoItSetOption("GUIOnEventMode", 1)

    ; X64 running support
    Local $sWow64 = ""
    If @AutoItX64 Then $sWow64 = "\Wow6432Node"

    ;get AutoIt install dir
    Local $sRegPath = "HKLM\SOFTWARE" & $sWow64 & "\AutoIt v3\AutoIt"

    Local $sFile = RegRead($sRegPath, "InstallDir") & "\Examples\GUI\logo4.gif"
    If Not FileExists($sFile) Then
        MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", $sFile & " not found!", 30)
        Exit
    EndIf
    ;$sFile = 'bulb0.jpg'
    If FileExists('logo4.gif') Then $sFile = 'logo4.gif'
    Local $i
    Local $sTitle = "GDI+"
    _GDIPlus_Startup()
    $h_Pen = _GDIPlus_PenCreate(0xFFFF0000)
    $hPath = _GDIPlus_PathCreate() ;Create new path object
    $g_hGUI = GUICreate($sTitle, $ci_MainWidth, $ci_MainHeight)
    ;GUISetBkColor(0xffffff)

    For $i = 0 To UBound($g_aCtrls) - 1
        $g_aCtrls[$i][1] = 0 ;x pos (Starting Position)
        $g_aCtrls[$i][2] = 250 + $i * 120 ;y pos starting position
        $g_aCtrls[$i][0] = GUICtrlCreatePic("", $g_aCtrls[$i][1], $g_aCtrls[$i][2], 169, 68)
        $g_aCtrls[$i][3] = 100 ; min x pos
        $g_aCtrls[$i][4] = 150 ; min y pos
        Local $aImagePos = ControlGetPos($g_hGUI, '', $g_aCtrls[$i][0])
        $g_aCtrls[$i][5] = $ci_MainWidth - $aImagePos[2] - 10 ; max x pos
        $g_aCtrls[$i][6] = $ci_MainHeight - $aImagePos[3] - 10 ; max y pos
        ; have to resize as you are making the control to make sure the larger image is not on the screen
        $g_aCtrls[$i][7] = _GDIPlus_ImageLoadFromFile($sFile)
        $g_aCtrls[$i][7] = _GDIPlus_ImageResize($g_aCtrls[$i][7], 50, 50)
        $g_aCtrls[$i][8] = _GDIPlus_BitmapCreateHBITMAPFromBitmap($g_aCtrls[$i][7])
        $g_aCtrls[$i][10] = $g_aCtrls[$i][1] ; starting X - then updates to new X position
        $g_aCtrls[$i][11] = $g_aCtrls[$i][2] ; starting y - then updates to new Y position

        $g_aCtrls[$i][12] = _GDIPlus_ImageGetWidth($g_aCtrls[$i][7]) ; Width of image
        $g_aCtrls[$i][13] = _GDIPlus_ImageGetHeight($g_aCtrls[$i][7]) ; Height of image
    Next

    _WinAPI_RedrawWindow($g_hGUI, 0, 0, $RDW_UPDATENOW)
    GUISetOnEvent($GUI_EVENT_SECONDARYDOWN, 'Get_Stats')
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    GUISetState(@SW_SHOW)

    ; ScreenUpdate
    CtrlMove($g_aCtrls, 0, $g_hGUI)

    Local $aMChk

    Do
        ConsoleWrite('*' & @CRLF)
        $aMChk = GUIGetCursorInfo($g_hGUI)
        Switch $aMChk[4]
            Case $g_aCtrls[0][0]
                $bCheckLocation = False
                If $aMChk[2] Then CtrlMove($g_aCtrls, 0, $g_hGUI)
                ;CheckObjectLocation($g_aCtrls, 0)
                ;$bCheckLocation = False
            Case $g_aCtrls[1][0]
                $bCheckLocation = False
                If $aMChk[2] Then CtrlMove($g_aCtrls, 1, $g_hGUI)
                ;CheckObjectLocation($g_aCtrls, 1)
                ;$bCheckLocation = False
            Case $g_aCtrls[2][0]
                $bCheckLocation = False
                If $aMChk[2] Then CtrlMove($g_aCtrls, 2, $g_hGUI)
                ;CheckObjectLocation($g_aCtrls, 2)
                ;$bCheckLocation = False
            Case $g_aCtrls[3][0]
                $bCheckLocation = False
                If $aMChk[2] Then CtrlMove($g_aCtrls, 3, $g_hGUI)
                ;CheckObjectLocation($g_aCtrls, 3)
                ;$bCheckLocation = False
        EndSwitch

    Until Not Sleep(50)
EndFunc   ;==>Example
;
Func CtrlMove(ByRef $g_aCtrls, $iCtrl, $g_hGUI)
    Local $aCtrlPos = ControlGetPos($g_hGUI, "", $g_aCtrls[$iCtrl][0])
    Local $iDX = Abs(MouseGetPos(0) - $aCtrlPos[0])
    Local $iDY = Abs(MouseGetPos(1) - $aCtrlPos[1])
    Local $iX, $iY
    Static $bRanOnce = False
    ;
    If Not $bRanOnce Then
        For $x = 0 To UBound($g_aCtrls) - 1
            $aCtrlPos = ControlGetPos($g_hGUI, "", $g_aCtrls[$x][0])
            _WinAPI_DeleteObject(GUICtrlSendMsg($g_aCtrls[$x][0], 0x0172, $IMAGE_BITMAP, $g_aCtrls[$x][8])) ;$STM_SETIMAGE = 0x0172
            Sleep(20)
            Local $hBitmap_Scaled = _GDIPlus_ImageResize($g_aCtrls[$x][7], 50, 50)
            If @error Then MsgBox('', '_GDIPlus_ImageResize ' & @error, $hBitmap_Scaled)
            Sleep(20)
            ;
            Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($g_hGUI) ;create a graphics object from a window handle
            If @error Then MsgBox('', '_GDIPlus_GraphicsCreateFromHWND ' & @error, $hGraphics)
            Sleep(20)
            ;
            _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap_Scaled, $aCtrlPos[0], $aCtrlPos[1])
            Sleep(20)
            $g_aCtrls[$x][8] = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_Scaled) ; handle to a HBITMAP (a handle to a bitmap from a bitmap object)
            Sleep(20)
            $iPic_W = _GDIPlus_ImageGetWidth($hBitmap_Scaled)
            $iPic_H = _GDIPlus_ImageGetHeight($hBitmap_Scaled)

            _WinAPI_RedrawWindow($g_hGUI, 0, 0, $RDW_UPDATENOW)
        Next

        _WinAPI_RedrawWindow($g_hGUI, 0, 0, $RDW_UPDATENOW)
        $bRanOnce = True
    EndIf
    ;
    While GUIGetCursorInfo($g_hGUI)[2]
        $iX = MouseGetPos(0) - $iDX
        $iY = MouseGetPos(1) - $iDY
        $aCtrlPos = ControlGetPos($g_hGUI, "", $g_aCtrls[$iCtrl][0])
        $iX_ = $aCtrlPos[0]
        $iY_ = $aCtrlPos[1]
        ;ConsoleWrite(' --REAL MOUSE-- ' & MouseGetPos(0) & ' ' & MouseGetPos(1) & @CRLF)
        ; ternary operator
        ;
        #cs
            GUICtrlSetPos($g_aCtrls[$iCtrl][0], ($iX < $g_aCtrls[$iCtrl][3]) ? $g_aCtrls[$iCtrl][3] : ($iX > $g_aCtrls[$iCtrl][5]) ? $g_aCtrls[$iCtrl][5] : $iX, _
            ($iY < $g_aCtrls[$iCtrl][4]) ? $g_aCtrls[$iCtrl][4] : ($iY > $g_aCtrls[$iCtrl][6]) ? $g_aCtrls[$iCtrl][6] : $iY)
        #ce
        Sleep(10)
        Local $iX_, $iY_
        ; check boundries X
        If $iX < $g_aCtrls[$iCtrl][3] Then ; get min x
            $iX_ = $g_aCtrls[$iCtrl][3]
        ElseIf $iX > $g_aCtrls[$iCtrl][5] Then ; get max x
            $iX_ = $g_aCtrls[$iCtrl][5]
        Else
            $iX_ = $iX
        EndIf
        ; check boundries Y
        If $iY < $g_aCtrls[$iCtrl][4] Then ; get min y
            $iY_ = $g_aCtrls[$iCtrl][4]
        ElseIf $iY > $g_aCtrls[$iCtrl][6] Then ; get max y
            $iY_ = $g_aCtrls[$iCtrl][6]
        Else
            $iY_ = $iY
        EndIf

        ; Check to make sure no overlap
        If _CheckLocation($iCtrl, $iX_, $iY_) Then

            ; move image to new position
            GUICtrlSetPos($g_aCtrls[$iCtrl][0], $iX_, $iY_)
            Sleep(10)
            $aCtrlPos = ControlGetPos($g_hGUI, "", $g_aCtrls[$iCtrl][0])
            If $aCtrlPos[0] <> $iX_ Then MsgBox('','','')
            If $aCtrlPos[1] <> $iY_ Then MsgBox('','','')

            ;ConsoleWrite('!> ' & $iCtrl & ' OLD VALUE...' & $g_aCtrls[$iCtrl][10] & ',' & $g_aCtrls[$iCtrl][11] & @CRLF)
            $g_aCtrls[$iCtrl][10] = $aCtrlPos[0]
            $g_aCtrls[$iCtrl][11] = $aCtrlPos[1]
            ;ConsoleWrite('!> ' & $iCtrl & ' NEW VALUE...' & $g_aCtrls[$iCtrl][10] & ',' & $g_aCtrls[$iCtrl][11] & @CRLF)
        EndIf

        ;_GDIPlus_GraphicsDrawRect($hGraphics, 300, 300, 50, 50, $h_Pen)
        ;_GDIPlus_GraphicsDrawRect($hGraphics, 290, 290, 70, 70, $h_Pen)

    WEnd
    ;_ArrayDisplay($g_aCtrls, '')
EndFunc   ;==>CtrlMove
;
Func _Exit()
    _WinAPI_DeleteObject($g_hGDIBitmap)
    _GDIPlus_ImageDispose($g_hImage)
    _GDIPlus_Shutdown()
    GUIDelete($g_hGUI)
    Exit
EndFunc   ;==>_Exit
;
Func _CheckLocation($iCtrl, $iX, $iY)
    ;ConsoleWrite('Checking the locatoin...' & $iCtrl & ' ' & $iX & ',' & $iY & ',' & $_x & ',' & $_y & ',' & _GDIPlus_ImageGetWidth($hBitmap_Scaled) & ' ' & _GDIPlus_ImageGetHeight($hBitmap_Scaled) & @CRLF)
    ;ConsoleWrite('Checking the locatoin...' & _GDIPlus_ImageGetWidth($hBitmap_Scaled) & ' ' &  _GDIPlus_ImageGetHeight($hBitmap_Scaled) & @CRLF)
    Local $xOffSet = 10
    Static $wtf
    For $x = 0 To UBound($g_aCtrls) - 1
        If $iCtrl = $x Then ContinueLoop
        ;
        Local $aCtrlPos = ControlGetPos($g_hGUI, "", $g_aCtrls[$iCtrl][0])
        ;
        If _WinAPI_PtInRectEx($iX, $iY, $g_aCtrls[$x][10] - $aCtrlPos[2] - $xOffSet, $g_aCtrls[$x][11] - $aCtrlPos[3] - $xOffSet, $g_aCtrls[$x][10] + $aCtrlPos[2] + $xOffSet, $g_aCtrls[$x][11] + $aCtrlPos[3] + $xOffSet) Then
            ;If $x <> UBound($g_aCtrls) - 1 Then
            Return False
        EndIf
        ;
    Next
    Return True
EndFunc   ;==>_CheckLocation
;
Func CheckObjectLocation(ByRef $g_aCtrls, $iCtrl)
    ConsoleWrite('Checking Location...' & @CRLF)

    Local $aReadCursorInfo ;= GUIGetCursorInfo($g_hGUI)
    For $x = 0 To UBound($g_aCtrls) - 1
        ;ConsoleWrite('x = ' & $x & @CRLF)

        ;
        If $iCtrl = $x Then ContinueLoop
        $aReadCursorInfo = GUIGetCursorInfo($g_hGUI)
        ConsoleWrite('Mouse ' & $aReadCursorInfo[0] & '|' & $aReadCursorInfo[0] & @CRLF)
        Local $aImagePos = ControlGetPos($g_hGUI, '', $g_aCtrls[$x][0])
        If Not $bCheckLocation And _WinAPI_PtInRectEx($aReadCursorInfo[0], $aReadCursorInfo[1], $g_aCtrls[$x][10], $g_aCtrls[$x][11], $g_aCtrls[$x][10] + $aImagePos[2], $g_aCtrls[$x][11] + $aImagePos[3]) Then
            ;#cs
            Sleep(20)
            ;
            MouseMove($g_aCtrls[$x][10] - $aImagePos[2] - 50, $g_aCtrls[$x][11], 0)
            ConsoleWrite('+> XXX ' & $x & ' ' & $g_aCtrls[$x][10] & '|' & $g_aCtrls[$x][11] & @CRLF)
            ;
            ;MsgBox('', '', 'hit') ; if I comment this out, both images move...
            GUICtrlSetPos($g_aCtrls[$iCtrl][0], $g_aCtrls[$x][10] - $aImagePos[2] - 50, $g_aCtrls[$x][11])
            $g_aCtrls[$iCtrl][10] = $g_aCtrls[$x][10] - $aImagePos[2]
            $g_aCtrls[$iCtrl][11] = $g_aCtrls[$x][11]
            ConsoleWrite('+> MOVED ' & $iCtrl & ' ' & $g_aCtrls[$iCtrl][10] & '|' & $g_aCtrls[$iCtrl][11] & @CRLF)
            MouseClick('Left') ;, $g_aCtrls[$x][10] - $aImagePos[2] - 50, $g_aCtrls[$x][11])
            ;ConsoleWrite($aReadCursorInfo[0] & ',' & $aReadCursorInfo[1] & @CRLF)
            ;ConsoleWrite($g_aCtrls[$x][3] & ',' & $g_aCtrls[$x][4] & @CRLF)
            ;ConsoleWrite($g_aCtrls[$x][5] & ',' & $g_aCtrls[$x][6] & @CRLF)
            ;_ArrayDisplay($g_aCtrls)

            ;#ce
            ;ContinueLoop
            ;Return
            ExitLoop
        Else
            ConsoleWrite('!> ' & $x & ' ' & $g_aCtrls[$x][10] & '|' & $g_aCtrls[$x][11] & @CRLF)
        EndIf
    Next
    ConsoleWrite('+++' & @CRLF)
EndFunc   ;==>CheckObjectLocation
;#ce
Func Get_Stats()
    _ArrayDisplay($g_aCtrls)
EndFunc   ;==>Get_Stats

 

.

.

EDIT

I found the link with the floating boxes:

https://www.autoitscript.com/forum/topic/129222-issues-collision-backbuffering-ect/#comment-897633

 

 

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

You can try something like this here:

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>

AutoItSetOption("MouseCoordMode", 2)

Global $g_hGUI, $g_hImage, $g_hGDIBitmap, $g_aCtrls[4][5], $hGraphics

Example()

Func Example()
    AutoItSetOption("GUIOnEventMode", 1)

    ; X64 running support
    Local $sWow64 = ""
    If @AutoItX64 Then $sWow64 = "\Wow6432Node"

    ;get AutoIt install dir
    Local $sRegPath = "HKLM\SOFTWARE" & $sWow64 & "\AutoIt v3\AutoIt"

    Local $sFile = RegRead($sRegPath, "InstallDir") & "\Examples\GUI\logo4.gif"
    If Not FileExists($sFile) Then
        MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", $sFile & " not found!", 30)
        Exit
    EndIf
    ;$sFile = 'bulb0.jpg'
    If FileExists('logo4.gif') Then $sFile = 'logo4.gif'
    Local $i
    Local $sTitle = "GDI+"
    _GDIPlus_Startup()
    $g_hImage = _GDIPlus_ImageLoadFromFile($sFile)
    $g_hGDIBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($g_hImage)
    $g_hGUI = GUICreate($sTitle, 1000, 600)
    ;GUISetBkColor(0xffffff)
    Local $iW = 169, $iH = 68
    For $i = 0 To UBound($g_aCtrls) - 1
        $g_aCtrls[$i][0] = 10
        $g_aCtrls[$i][1] = 50 + $i * 150
        $g_aCtrls[$i][2] = $iW
        $g_aCtrls[$i][3] = $iH
        $g_aCtrls[$i][4] = GUICtrlCreatePic("", $g_aCtrls[$i][0], $g_aCtrls[$i][1], $g_aCtrls[$i][2], $g_aCtrls[$i][3])
        _WinAPI_DeleteObject(GUICtrlSendMsg($g_aCtrls[$i][4], 0x0172, $IMAGE_BITMAP, $g_hGDIBitmap)) ;$STM_SETIMAGE = 0x0172
    Next
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    GUISetState(@SW_SHOW)

    Local $aMChk, $aCtrlPos, $iDX, $iDY, $iX_old, $iY_old

    Do
        $aMChk = GUIGetCursorInfo($g_hGUI)
        For $i = 0 To UBound($g_aCtrls) - 1
            Switch $aMChk[4]
                Case $g_aCtrls[$i][4]
                    $aCtrlPos = ControlGetPos($g_hGUI, "", $g_aCtrls[$i][4])
                    $iDX = Abs(MouseGetPos(0) - $aCtrlPos[0])
                    $iDY = Abs(MouseGetPos(1) - $aCtrlPos[1])
                    While GUIGetCursorInfo($g_hGUI)[2]
                        $aCtrlPos = ControlGetPos($g_hGUI, "", $g_aCtrls[$i][4])
                        If Not Collision($i, MouseGetPos(0) - $iDX, MouseGetPos(1) - $iDY) Then
                            ControlMove($g_hGUI, "", $g_aCtrls[$i][4], MouseGetPos(0) - $iDX, MouseGetPos(1) - $iDY)
                            $aCtrlPos = ControlGetPos($g_hGUI, "", $g_aCtrls[$i][4])
                            $g_aCtrls[$i][0] = $aCtrlPos[0]
                            $g_aCtrls[$i][1] = $aCtrlPos[1]
                        EndIf
                        Sleep(10)
                    WEnd
            EndSwitch
        Next
    Until Not Sleep(30)
EndFunc   ;==>Example

Func Collision($iCtrl, $iX, $iY)
    Local $i
    For $i = 0 To UBound($g_aCtrls) - 1
        If $iCtrl <> $i Then
            If _WinAPI_PtInRectEx($iX, $iY, $g_aCtrls[$i][0], $g_aCtrls[$i][1], $g_aCtrls[$i][0] + $g_aCtrls[$i][2], $g_aCtrls[$i][1] + $g_aCtrls[$i][3]) Then Return 1
            If _WinAPI_PtInRectEx($iX + $g_aCtrls[$iCtrl][2], $iY, $g_aCtrls[$i][0], $g_aCtrls[$i][1], $g_aCtrls[$i][0] + $g_aCtrls[$i][2], $g_aCtrls[$i][1] + $g_aCtrls[$i][3]) Then Return 1
            If _WinAPI_PtInRectEx($iX, $iY + $g_aCtrls[$iCtrl][3], $g_aCtrls[$i][0], $g_aCtrls[$i][1], $g_aCtrls[$i][0] + $g_aCtrls[$i][2], $g_aCtrls[$i][1] + $g_aCtrls[$i][3]) Then Return 1
            If _WinAPI_PtInRectEx($iX + $g_aCtrls[$iCtrl][2], $iY + $g_aCtrls[$iCtrl][3], $g_aCtrls[$i][0], $g_aCtrls[$i][1], $g_aCtrls[$i][0] + $g_aCtrls[$i][2], $g_aCtrls[$i][1] + $g_aCtrls[$i][3]) Then Return 1
        EndIf
    Next
    Return 0
EndFunc   ;==>Collision

Func _Exit()
    _GDIPlus_ImageDispose($g_hImage)
    _WinAPI_DeleteObject($g_hGDIBitmap)
    _GDIPlus_Shutdown()
    GUIDelete($g_hGUI)
    Exit
EndFunc   ;==>_Exit
Edited by UEZ
forget to save moved control position

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 comment
Share on other sites

That did not seem to work, as the images were able to overlap each other. I looked but could not find out where it was allowing it, as it appears the code is right, but maybe not the conditions?

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

I understood that the controls should not overlap.

Edit: sorry, found the bug. I updated the code.

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 comment
Share on other sites

I tried yours, and it is not much different than the one I posted. Both still have issues when coming in from the corners - but it is workable. I am still going to look at it, as I have other stuff going to be added, and I will see how much it affects the script.

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

Optimizing the Collision function

Because the rectangles have the same size it's easy to optimize the Collision function. In order to check whether the right rectangle overlaps the left rectangle, it is enough to check if the midpoint of the right rectangle is inside the dotted rectangle.

tst20_zpsxrpaqnx9.png

The height and width of the dotted rectangle is twice the height and width of the solid. The midpoint of the dotted rectangle is the same as the midpoint of the solid.

The four lines in the Collision function can be reduced to one line where you check if the midpoint is inside the dotted rectangle.

You have to store information about the dotted rectangles and the midpoints in the arrays.

Edited by LarsJ
Link to comment
Share on other sites

I will take a look at this tonight, but there are going to be different size rectangles, is that going to make a difference?

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

I tried yours, and it is not much different than the one I posted. Both still have issues when coming in from the corners - but it is workable. I am still going to look at it, as I have other stuff going to be added, and I will see how much it affects the script.

To be honest I didn't check in details what you did. So, the ideas were the same...

 

Optimizing the Collision function

Because the rectangles have the same size it's easy to optimize the Collision function. In order to check whether the right rectangle overlaps the left rectangle, it is enough to check if the midpoint of the right rectangle is inside the dotted rectangle.

tst20_zpsxrpaqnx9.png

The height and width of the dotted rectangle is twice the height and width of the solid. The midpoint of the dotted rectangle is the same as the midpoint of the solid.

The four lines in the Collision function can be reduced to one line where you check if the midpoint is inside the dotted rectangle.

You have to store information about the dotted rectangles and the midpoints in the arrays.

That might be shorter and faster but with the 4 lines version you can check more or less which edge causes the collision if you need more details about the collision.

Anyhow, nice to know that "trick". I will add it, too.

I assume this should also work for different rectangle sizes as long as they are rectangles and not other more complex objects.

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 comment
Share on other sites

nitekram, No, rectangles of different sizes will not make a crucial difference. But you will need to store information about all the dotted rectangles. I'll add an example in the weekend.

UEZ, Because there are many more checks without collision than checks with collision, it's important that the collision check is as fast as possible. For the most checks without collision the extra information is useless anyway. When you know, that there is a collision, you can calculate the extra information.

For more complex objects you can use the trick for the bounding rectangles. When you know that the bounding rectangles collides, you can make a more complex collision check for the objects.

Edited by LarsJ
Complex objects
Link to comment
Share on other sites

Optimizing the Collision function 2

tst20_zpsjtvb7tol.png

Code to determine whether a point is inside a rectangle is very simple and should certainly not be performed with a function call. Perform the calculation directly:

If $x1 < $mx And $mx < $x2 And $y1 < $my And $my < $y2 Then ; Collision

 

Edited by LarsJ
Link to comment
Share on other sites

What are you using for the offset - half the size of the box (rectangle) that is moving or the stationary box?

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...