JRowe Posted June 21, 2008 Share Posted June 21, 2008 (edited) What I'm trying to accomplish is pretty simple. I want to be able to drag a box from a sidebar onto a designated Droppable Area. CODE#include <GUIConstants.au3> Opt("MouseCoordMode", 0) #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 633, 447, 193, 125) $DroppableArea = GUICtrlCreateLabel("", 144, 8, 476, 428) GUICtrlSetBkColor(-1, 0x555555) $Tab1 = GUICtrlCreateTab(0, 8, 137, 433) GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT) $TabSheet1 = GUICtrlCreateTabItem("TabSheet1") $Button1 = GUICtrlCreateButton("", 16, 48, 36, 36, 0) $Button2 = GUICtrlCreateButton("", 56, 48, 36, 36, 0) $Button3 = GUICtrlCreateButton("", 56, 88, 36, 36, 0) $BoxButton1 = GUICtrlCreateLabel("", 16, 88, 36, 36) GUICtrlSetBkColor(-1, 0xFFF000) $Label2 = GUICtrlCreateLabel("Label2", 16, 232, 92, 57) $TabSheet2 = GUICtrlCreateTabItem("TabSheet2") GUICtrlCreateTabItem("") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $boxIndex = 0 Dim $boxes[1000] $newBox = False While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_PRIMARYDOWN $watch = GUIGetCursorInfo () Switch $watch[4] Case $watch[4] = $BoxButton1 If $watch[4] = $BoxButton1 And $watch[4] <> 0 Then DragNDrop() EndIf EndSwitch EndSwitch WEnd Func DragNDrop() $newBox = True $pos = MouseGetPos() $BoxID = CreateDraggableSquare($pos[0], $pos[1], $boxIndex) $boxIndex += 1 $watch2 = GUIGetMsg() While $watch2 <> $GUI_EVENT_PRIMARYUP $pos = MouseGetPos() GUICtrlSetPos($boxes[$BoxID], $pos[0]-8, $pos[1]-6) $watch2 = GUIGetMsg() If $watch2 = $GUI_EVENT_PRIMARYUP Then $watch = GUIGetCursorInfo () If $watch[4] = $DroppableArea Then Return "Success" Else GUICtrlDelete($boxes[$BoxID]) EndIf EndIf WEnd EndFunc Func CreateDraggableSquare($mouseX, $mouseY, $ID) $boxes[$ID] = GUICtrlCreateLabel("", $mouseX-36 , $mouseY-18, 36, 36, $WS_BORDER) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) Return $ID EndFunc How can I do a hit test against the boundaries of the $DraggableArea control, without using getCursorInfo()? getCursorInfo() returns the ID of previously dropped items if I try to drop over them, which prevents the drop from occuring. Edited June 21, 2008 by Jrowe [center]However, like ninjas, cyber warriors operate in silence.AutoIt Chat Engine (+Chatbot) , Link Grammar for AutoIt , Simple Speech RecognitionArtificial Neural Networks UDF , Bayesian Networks UDF , Pattern Matching UDFTransparent PNG GUI Elements , Au3Irrlicht 2Advanced Mouse Events MonitorGrammar Database GeneratorTransitions & Tweening UDFPoker Hand Evaluator[/center] Link to comment Share on other sites More sharing options...
martin Posted June 21, 2008 Share Posted June 21, 2008 What I'm trying to accomplish is pretty simple. I want to be able to drag a box from a sidebar onto a designated Droppable Area. CODE#include <GUIConstants.au3> Opt("MouseCoordMode", 0) #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 633, 447, 193, 125) $DroppableArea = GUICtrlCreateLabel("", 144, 8, 476, 428) GUICtrlSetBkColor(-1, 0x555555) $Tab1 = GUICtrlCreateTab(0, 8, 137, 433) GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT) $TabSheet1 = GUICtrlCreateTabItem("TabSheet1") $Button1 = GUICtrlCreateButton("", 16, 48, 36, 36, 0) $Button2 = GUICtrlCreateButton("", 56, 48, 36, 36, 0) $Button3 = GUICtrlCreateButton("", 56, 88, 36, 36, 0) $BoxButton1 = GUICtrlCreateLabel("", 16, 88, 36, 36) GUICtrlSetBkColor(-1, 0xFFF000) $Label2 = GUICtrlCreateLabel("Label2", 16, 232, 92, 57) $TabSheet2 = GUICtrlCreateTabItem("TabSheet2") GUICtrlCreateTabItem("") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $boxIndex = 0 Dim $boxes[1000] $newBox = False While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_PRIMARYDOWN $watch = GUIGetCursorInfo () Switch $watch[4] Case $watch[4] = $BoxButton1 If $watch[4] = $BoxButton1 And $watch[4] <> 0 Then DragNDrop() EndIf EndSwitch EndSwitch WEnd Func DragNDrop() $newBox = True $pos = MouseGetPos() $BoxID = CreateDraggableSquare($pos[0], $pos[1], $boxIndex) $boxIndex += 1 $watch2 = GUIGetMsg() While $watch2 <> $GUI_EVENT_PRIMARYUP $pos = MouseGetPos() GUICtrlSetPos($boxes[$BoxID], $pos[0]-8, $pos[1]-6) $watch2 = GUIGetMsg() If $watch2 = $GUI_EVENT_PRIMARYUP Then $watch = GUIGetCursorInfo () If $watch[4] = $DroppableArea Then Return "Success" Else GUICtrlDelete($boxes[$BoxID]) EndIf EndIf WEnd EndFunc Func CreateDraggableSquare($mouseX, $mouseY, $ID) $boxes[$ID] = GUICtrlCreateLabel("", $mouseX-36 , $mouseY-18, 36, 36, $WS_BORDER) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) Return $ID EndFunc How can I do a hit test against the boundaries of the $DraggableArea control, without using getCursorInfo()? getCursorInfo() returns the ID of previously dropped items if I try to drop over them, which prevents the drop from occuring. This might do waht you want. expandcollapse popup#include <GUIConstants.au3> Opt("MouseCoordMode", 0) #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 633, 447, 193, 125) $DroppableArea = GUICtrlCreateLabel("", 144, 8, 476, 428) GUICtrlSetBkColor(-1, 0x555555) $Tab1 = GUICtrlCreateTab(0, 8, 137, 433) GUICtrlSetResizing(-1, $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT) $TabSheet1 = GUICtrlCreateTabItem("TabSheet1") $Button1 = GUICtrlCreateButton("", 16, 48, 36, 36, 0) $Button2 = GUICtrlCreateButton("", 56, 48, 36, 36, 0) $Button3 = GUICtrlCreateButton("", 56, 88, 36, 36, 0) $BoxButton1 = GUICtrlCreateLabel("", 16, 88, 36, 36) GUICtrlSetBkColor(-1, 0xFFF000) $Label2 = GUICtrlCreateLabel("Label2", 16, 232, 92, 57) $TabSheet2 = GUICtrlCreateTabItem("TabSheet2") GUICtrlCreateTabItem("") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $boxIndex = 0 Dim $boxes[1000] $newBox = False While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_PRIMARYDOWN $watch = GUIGetCursorInfo() Switch $watch[4] Case $watch[4] = $BoxButton1 ;If $watch[4] = $BoxButton1 And $watch[4] <> 0 Then DragNDrop() ;EndIf EndSwitch EndSwitch WEnd Func DragNDrop() $newBox = True $pos = MouseGetPos() $BoxID = CreateDraggableSquare($pos[0], $pos[1], $boxIndex) $boxIndex += 1 $watch2 = GUIGetMsg() While $watch2 <> $GUI_EVENT_PRIMARYUP $pos = MouseGetPos() GUICtrlSetPos($boxes[$BoxID], $pos[0] - 8, $pos[1] - 6) $watch2 = GUIGetMsg() If $watch2 = $GUI_EVENT_PRIMARYUP Then ;$watch = GUIGetCursorInfo() If Fits($boxes[$BoxID], $DroppableArea) Then Return "Success" Else GUICtrlDelete($boxes[$BoxID]) $boxIndex -= 1;<----------------- EndIf EndIf WEnd EndFunc ;==>DragNDrop Func Fits($Obj, $Ctrl) Local $cp = ControlGetPos($Form1, "", $Ctrl) Local $op = ControlGetPos($Form1, "", $Obj) If ($op[0] + $op[2]) > ($cp[0] + $cp[2]) Then Return False If $op[0] < $cp[0] Then Return False If ($op[1] + $op[3]) > ($cp[1] + $cp[3]) Then Return False If $op[1] < $cp[1] Then Return False Return True EndFunc ;==>Fits Func CreateDraggableSquare($mouseX, $mouseY, $ID) $boxes[$ID] = GUICtrlCreateLabel("", $mouseX - 36, $mouseY - 18, 36, 36, $WS_BORDER) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) Return $ID EndFunc ;==>CreateDraggableSquare Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
JRowe Posted June 21, 2008 Author Share Posted June 21, 2008 Much thanks I wasn't sure how to access the x/y values of the corners of a control. [center]However, like ninjas, cyber warriors operate in silence.AutoIt Chat Engine (+Chatbot) , Link Grammar for AutoIt , Simple Speech RecognitionArtificial Neural Networks UDF , Bayesian Networks UDF , Pattern Matching UDFTransparent PNG GUI Elements , Au3Irrlicht 2Advanced Mouse Events MonitorGrammar Database GeneratorTransitions & Tweening UDFPoker Hand Evaluator[/center] 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