Realistphill Posted September 6, 2015 Share Posted September 6, 2015 Hey guys,Is there an easy way to check if controls on a GUI overlap?something like: IF $control overlaps $othercontrol then dosomething.^ i realise that syntax is wrong, but thats sort of what im trying to achieve.Any help would be appreciated!thanks! Link to comment Share on other sites More sharing options...
Surya Posted September 6, 2015 Share Posted September 6, 2015 (edited) you could use controlgetpos to get the position of the controls in the window by comparing the two positions you could test wether they overlap Edited September 6, 2015 by Surya No matter whatever the challenge maybe control on the outcome its on you its always have been. MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition) Link to comment Share on other sites More sharing options...
orbs Posted September 6, 2015 Share Posted September 6, 2015 use ControlGetPos to retrieve and compare position and size of controls. i'll leave you to do the math yourself, not very difficult.if you wish to prevent controls overlap at runtime, due to user resizing your GUI, use GUICtrlSetResizing to dock your controls in a way they will not overlap. Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Link to comment Share on other sites More sharing options...
Realistphill Posted September 6, 2015 Author Share Posted September 6, 2015 Thats what ive been doing so far, before i got fully into it though i wanted to make sure there was no easier way, thanks for info Link to comment Share on other sites More sharing options...
Surya Posted September 6, 2015 Share Posted September 6, 2015 (edited) made a function for you (CODE UNTESTED): check wether this works; #FUNCTION# ==================================================================================================================== ; Name ..........: _checkifOverlap ; Description ...: ; Syntax ........: _checkifOverlap($hndl, $ctrl1, $ctrl2) ; Parameters ....: $hndl - a handle to the window ; $ctrl1 - the handle to the first cintrol ; $ctrl2 - the handle to the second control ; Return values .: true if overlaps false if doesnt ; Author ........: Surya Saradhi.B ; Modified ......: 06/09/15 ; =============================================================================================================================== Func _checkifOverlap($hndl,$ctrl1,$ctrl2) $pos1 = ControlGetPos($hndl,"",$ctrl1) $pos2 = ControlGetPos($hndl,"",$ctrl2) $tws1 = $pos1[0] + $pos1[2] $tms2 = $pos1[1] + $pos1[3] If $pos1[0] <= $pos2[0] And $pos2[0] <= $tws1 And $pos1[1] <= $pos2[1] And $pos2[1] <= $tms2 Then Return True EndIf Return False EndFuncif you want any more help feel free to ask Edited September 6, 2015 by Surya No matter whatever the challenge maybe control on the outcome its on you its always have been. MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition) Link to comment Share on other sites More sharing options...
Realistphill Posted September 6, 2015 Author Share Posted September 6, 2015 made a function for you (CODE UNTESTED): check wether this works; #FUNCTION# ==================================================================================================================== ; Name ..........: _checkifOverlap ; Description ...: ; Syntax ........: _checkifOverlap($hndl, $ctrl1, $ctrl2) ; Parameters ....: $hndl - a handle to the window ; $ctrl1 - the handle to the first cintrol ; $ctrl2 - the handle to the second control ; Return values .: true if overlaps false if doesnt ; Author ........: Surya Saradhi.B ; Modified ......: 06/09/15 ; =============================================================================================================================== Func _checkifOverlap($hndl,$ctrl1,$ctrl2) $pos1 = ControlGetPos($hndl,"",$ctrl1) $pos2 = ControlGetPos($hndl,"",$ctrl2) $tws1 = $pos1[0] + $pos1[2] $tms2 = $pos1[1] + $pos1[3] If $pos1[0] <= $pos2[0] And $pos2[0] <= $tws1 And $pos1[1] <= $pos2[1] And $pos2[1] <= $tms2 Then Return True EndIf Return False EndFuncif you want any more help feel free to askWow, thank you! ill test in a bit and ill report my results. Link to comment Share on other sites More sharing options...
Realistphill Posted September 6, 2015 Author Share Posted September 6, 2015 It doesnt work properly I think one of the math forumlas you have there are wrong Link to comment Share on other sites More sharing options...
Surya Posted September 6, 2015 Share Posted September 6, 2015 no worries i will look onto it soon No matter whatever the challenge maybe control on the outcome its on you its always have been. MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition) Link to comment Share on other sites More sharing options...
Surya Posted September 6, 2015 Share Posted September 6, 2015 i tested the code and I think it works actual;ly:try changing the position of the label over the button when the label is over the button it will return trueexpandcollapse popup#include <GUIConstantsEx.au3> Example() Func Example() ; Create a GUI with various controls. Local $hGUI = GUICreate("Example") Local $idOK = GUICtrlCreateButton("OK", 310, 370, 85, 25) Local $lbl = GUICtrlCreateLabel ("hello",310,390) MsgBox("","",_checkifOverlap($hGUI,$idOK,$lbl)) ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idOK ExitLoop EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>Example Func _checkifOverlap($hndl,$ctrl1,$ctrl2) $pos1 = ControlGetPos($hndl,"",$ctrl1) $pos2 = ControlGetPos($hndl,"",$ctrl2) $tws1 = $pos1[0] + $pos1[2] $tms2 = $pos1[1] + $pos1[3] If $pos1[0] <= $pos2[0] And $pos2[0] <= $tws1 And $pos1[1] <= $pos2[1] And $pos2[1] <= $tms2 Then Return True EndIf Return False EndFuncpost me your code i will check that also No matter whatever the challenge maybe control on the outcome its on you its always have been. MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition) Link to comment Share on other sites More sharing options...
Realistphill Posted September 6, 2015 Author Share Posted September 6, 2015 Ok check my code out: expandcollapse popup#include <GUIConstantsEx.au3> #include <Misc.au3> guicreate("test", 700, 700) guisetstate() $player = guictrlcreateGraphic(150, 150, 50, 50) GUICtrlSetbkColor(-1, 0xfffff) $object = GUICtrlCreateGraphic(100, 200, 50, 50) GUICtrlSetbkColor(-1, 0xfffdddd) $action = 0 while $action <> $GUI_EVENT_CLOSE $action = GUIGetMsg() Select case _IsPressed(27) and _IsPressed(28) ;right-down $pos = controlgetpos("", "", $player) controlmove("", "", $player, $pos[0] + 2, $pos[1] + 2) case _IsPressed(27) ;right $pos = controlgetpos("", "", $player) controlmove("", "", $player, $pos[0] + 2, $pos[1]) case _IsPressed(28) ;down $pos = controlgetpos("", "", $player) controlmove("", "", $player, $pos[0], $pos[1] + 2) case _IsPressed(25) ;left $pos = controlgetpos("", "", $player) controlmove("", "", $player, $pos[0] - 2, $pos[1]) case _IsPressed(26) ;up $pos = controlgetpos("", "", $player) controlmove("", "", $player, $pos[0], $pos[1] - 2) EndSelect if _checkifOverlap("test", $object, $player) = true Then traytip("x", "x", 200) endif WEnd Func _checkifOverlap($hndl,$ctrl1,$ctrl2) $pos1 = ControlGetPos($hndl,"",$ctrl1) $pos2 = ControlGetPos($hndl,"",$ctrl2) $tws1 = $pos1[0] + $pos1[2] $tms2 = $pos1[1] + $pos1[3] If $pos1[0] <= $pos2[0] And $pos2[0] <= $tws1 And $pos1[1] <= $pos2[1] And $pos2[1] <= $tms2 Then Return True EndIf Return False EndFuncJust play it and youll see what i mean Link to comment Share on other sites More sharing options...
Realistphill Posted September 7, 2015 Author Share Posted September 7, 2015 (edited) Ok i figured it out, heres the updated UDF: (me and my dad rewrote most of it)Func _checkifOverlap($ctrl1, $ctrl2) ;expects 2 control variables to check if overlapping. ; return TRUE if overlapped, otherwise false Local $pos1 = ControlGetPos("", "", $ctrl1) Local $pos2 = ControlGetPos("", "", $ctrl2) local $iX = 0, $iY = 1, $iWidth = 2, $iHeight = 3 Local $iCtrl1_X1 = $pos1[$iX] Local $iCtrl1_Y1 = $pos1[$iY] Local $iCtrl1_X2 = $pos1[$iX] + $pos1[$iWidth] Local $iCtrl1_Y2 = $pos1[$iY] + $pos1[$iHeight] Local $iCtrl2_X1 = $pos2[$iX] Local $iCtrl2_Y1 = $pos2[$iY] Local $iCtrl2_X2 = $pos2[$iX] + $pos2[$iWidth] Local $iCtrl2_Y2 = $pos2[$iY] + $pos2[$iHeight] ;top left corner If ($iCtrl2_X1 >= $iCtrl1_X1 And $iCtrl2_X1 <= $iCtrl1_X2) And ($iCtrl2_Y1 >= $iCtrl1_Y1 And $iCtrl2_Y1 <= $iCtrl1_Y2) Then Return True EndIf ;Bottom left corner If ($iCtrl2_X1 >= $iCtrl1_X1 And $iCtrl2_X1 <= $iCtrl1_X2) And ($iCtrl2_Y2 >= $iCtrl1_Y1 And $iCtrl2_Y2 <= $iCtrl1_Y2) Then Return True EndIf ;Bottom right corner If ($iCtrl2_X2 >= $iCtrl1_X1 And $iCtrl2_X2 <= $iCtrl1_X2) And ($iCtrl2_Y2 >= $iCtrl1_Y1 And $iCtrl2_Y2 <= $iCtrl1_Y2) Then Return True EndIf ;top right corner If ($iCtrl2_X2 >= $iCtrl1_X1 And $iCtrl2_X2 <= $iCtrl1_X2) And ($iCtrl2_Y1 >= $iCtrl1_Y1 And $iCtrl2_Y1 <= $iCtrl1_Y2) Then Return True EndIf Return False EndFunc ;==>_checkifOverlapIt works!!! Edited September 7, 2015 by Realistphill Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now