Jump to content

Dragable Labels


 Share

Recommended Posts

  • Make a label
  • Detect left click
  • While clicked move label in same direction as the mouse has moved.
  • Clean up when left click is not there anymore.
Search for +CyberSlug +GUIBuilder and you will be able to dig up samples.
Link to comment
Share on other sites

  • Make a label
  • Detect left click
  • While clicked move label in same direction as the mouse has moved.
  • Clean up when left click is not there anymore.
Search for +CyberSlug +GUIBuilder and you will be able to dig up samples.
Thanks, but how do i do those things

My problem is in the 2nd and 4th bullets

how do i detect a mouse button being held in over a label?

How do i change the GUI so you can tell moving the mouse will drag it (Signify that it is the one selected)?

Link to comment
Share on other sites

If you have the time and patience, you could pick apart CyberSlug's GuiBuilder and see how it's done.

Look in the GuiBuilder folder in the SciTE folder.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

If you have the time and patience, you could pick apart CyberSlug's GuiBuilder and see how it's done.

Look in the GuiBuilder folder in the SciTE folder.

I tried, but that code is so huge, i was lost before the variables were done being declared :">

Besides, I don't even know what to look for

maybe CyberSlug could direct me to the portion of code I'm looking for :">

or if anyone else has any ideas on how to do it, that be great

cause I'm lost :P:nuke:

Link to comment
Share on other sites

My problem is in the 2nd and 4th bullets

how do i detect a mouse button being held in over a label?

Check out GUIGetCursorInfo which will help you determine if the mouse-buttons have the

clicked in the GUI, if it was clicked over the control you want and what position it was clicked

at.

Edited by Helge
Link to comment
Share on other sites

This is what I'm doing to check if a ctrl is hovered. Maybe you can adapt this...

While 1
    $hovered = GUIGetCursorInfo($guimain)
    If IsArray($hovered) And $hovered[4] <> 0 Then
        Switch $hovered[4]
            Case $thelabel  ;<== control id of the label
                MsgBox(0, "", "hovered!")
        EndSwitch
    EndIf
WEnd

In the array, [2] will tell you if mouse1 is down.

Link to comment
Share on other sites

This is what I'm doing to check if a ctrl is hovered. Maybe you can adapt this...

While 1
    $hovered = GUIGetCursorInfo($guimain)
    If IsArray($hovered) And $hovered[4] <> 0 Then
        Switch $hovered[4]
            Case $thelabel  ;<== control id of the label
                MsgBox(0, "", "hovered!")
        EndSwitch
    EndIf
WEnd

In the array, [2] will tell you if mouse1 is down.

Something like this will probably be what i have to do, Thanks,

anyone know how i can signify it to a user though?, Like make a border around the selected label?

Edited by Paulie
Link to comment
Share on other sites

Ok, there's probably more than needed in this but it works (parts of GuiBuilder).

Select the Config/Move menu so that it's checked and the controls can be move.

Select the Config/Move menu so that it's unchecked and the controls can be used.

#include <GUIConstants.au3>

$main = GUICreate("My GUI Button") ; will create a dialog box that when displayed is centered
$menu_Config = GUICtrlCreateMenu("Config")
$menu_move = GUICtrlCreateMenuitem("Move Controls", $menu_Config)
Dim $overlayTarget  ;guiID# of control under the overlay
$overlay = GUICtrlCreateLabel("foo", -99, -99, 1, 1, 0x107)  ;transparent label with black border

$grippySize = 6 ;pixel size
Dim $grippy[9] ;I'll use indices 1 - 8
For $i = 1 To 8
    $grippy[$i] = GUICtrlCreateLabel("", -99, -99, $grippySize, $grippySize, 0x104) ;black square
Next

Global $NorthWest_Grippy = $grippy[1]
Global $North_Grippy = $grippy[2]
Global $NorthEast_Grippy = $grippy[3]
Global $West_Grippy = $grippy[4]
Global $East_Grippy = $grippy[5]
Global $SouthWest_Grippy = $grippy[6]
Global $South_Grippy = $grippy[7]
Global $SouthEast_Grippy = $grippy[8]

Global $MODE = 2   ; 2 = waiting to move, 3 = moving
Global $INITMOVE = 2, $MOVING = 3
Global $cursorInfo, $hover
$background = GUICtrlCreatePic("", 0, 0, 1024, 768);, $BACKG_STYLE) ;used to show a grid
GUICtrlSetState($background, 128) ;disable background so that user can click buttons

$Button_1 = GUICtrlCreateButton("Run Notepad", 10, 30, 100, 25)
$Button_2 = GUICtrlCreateButton("Button Test", 10, 60, 100, 25)
$label = GUICtrlCreateLabel("This is my lable", 10, 90, 120, 25)

GUISetState()      ; will display an  dialog box with 2 button

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg(1)
    Select
        Case $msg[0] = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg[0] = $Button_1
            Run('Notepad.exe')    ; Will Run/Open Notepad
        Case $msg[0] = $Button_2
            MsgBox(0, 'Testing', 'Button 2 was pressed')    ; Will demonstrate Button 2 being pressed
        Case $msg[0] = $menu_move
            If BitAND(GUICtrlRead($menu_move), $GUI_CHECKED) Then
                GUICtrlSetState($menu_move, $GUI_UNCHECKED)
            Else
                GUICtrlSetState($menu_move, $GUI_CHECKED)
            EndIf
        Case $msg[0] = $overlay And BitAND(GUICtrlRead($menu_move), $GUI_CHECKED)
            ; drag and drop any control; when done moving, the control will show grippies around it
            ;If $hover <> $grippyCtrl Then
            $grippyCtrl = $hover
            ;Else
            $MODE = $MOVING
            $currentCtrl = $hover ;control under the overlay

            $c = ControlGetPos($main, "", $currentCtrl)
            $p = GUIGetCursorInfo($main)
            $xOffset = $p[0] - $c[0]
            $yOffset = $p[1] - $c[1]
            ToolTip($xOffset & "," & $yOffset)
            GUICtrlSetPos($overlay, -99, -99, 1, 1) ;"hide" overlay since we don't need it
            ;EndIf
    EndSelect
    If BitAND(GUICtrlRead($menu_move), $GUI_CHECKED) Then
        $cursorInfo = GUIGetCursorInfo()
        Select
            Case $cursorInfo[4] = $grippy[1] ;North-East
                GUISetCursor(12, 1)
            Case $cursorInfo[4] = $grippy[2] ;North
                GUISetCursor(11, 1)
            Case $cursorInfo[4] = $grippy[3] ;North-West
                GUISetCursor(10, 1)
            Case $cursorInfo[4] = $grippy[4] ;West
                GUISetCursor(13, 1)
            Case $cursorInfo[4] = $grippy[5] ;East
                GUISetCursor(13, 1)
            Case $cursorInfo[4] = $grippy[6] ;South-East
                GUISetCursor(10, 1)
            Case $cursorInfo[4] = $grippy[7] ;South
                GUISetCursor(11, 1)
            Case $cursorInfo[4] = $grippy[8] ;South-West
                GUISetCursor(12, 1)
        EndSelect
        ;If cursor is out of bounds, then continue loop
        $wgcs = WinGetClientSize($main)
        If $cursorInfo[0] <= 0 Or $cursorInfo[1] <= 0 Or $cursorInfo[0] >= $wgcs[0] Or $cursorInfo[1] >= $wgcs[1] Then
            ;;;;;;If $cursorInfo[2] = 1 Then ContinueLoop  ;if mouse button down
            ;If $mode = 3 Then ;drawing
            ;   ; HELP KEEP OVERLAY AND CONTROL IN SYNC WHEN USER MOVES MOUSE QUICKLY
            ;   $c = ControlGetPos($main,"",$currentCtrl)
            ;   GuiCtrlSetPos($overlay, $p[0]-$xOffset, $p[1]-$yOffset, $c[2], $c[3])
            ;EndIf
            ContinueLoop
        EndIf
        ; When cursor hovers over a control, change cursor to the sizeall cursor
        ;  I could use GUICtrlSetCursor instead, but that might hurt performance a bit
        If $cursorInfo[4] = 0 Or $cursorInfo[4] = $background Or ($cursorInfo[4] >= $grippy[1] And $cursorInfo[4] <= $grippy[8]) Then
            $hover = 0
;~          If ($cursorInfo[4] < $grippy[1] Or $cursorInfo[4] > $grippy[8]) Then GUISetCursor(3, 1) ;3=crosshair cursor
            GUICtrlSetPos($overlay, -99, -99, 1, 1)
        Else
            If $cursorInfo[4] <> $overlay Then
                $hover = $cursorInfo[4]

            EndIf
            $cp = ControlGetPos("", "", $cursorInfo[4])
            If $MODE = $INITMOVE Then
                GUICtrlSetPos($overlay, $cp[0], $cp[1], $cp[2], $cp[3])
                If ($cursorInfo[4] < $grippy[1] Or $cursorInfo[4] > $grippy[8]) Then GUISetCursor(2, 1) ;2=regular arrow cursor
                ;;;showGrippies($overlay)
            EndIf
        EndIf
        If $MODE = $MOVING Then ;moving
            GUISetCursor(9, 1) ;9=sizeall

            ;;$p = GuiGetCursorInfo($main)  ;$p[0] = x  and $p[1] = y
            $p = GUIGetCursorInfo($main)
            ToolTip("(" & $p[0] & ", " & $p[1] & ")")


            GUICtrlSetPos($currentCtrl, $p[0] - $xOffset, $p[1] - $yOffset, $c[2], $c[3])
            ;;;GuiCtrlSetPos($overlay, $p[0]-$xOffset, $p[1]-$yOffset, $c[2], $c[3])

            For $i = 1 To 8
                GUICtrlSetPos($grippy[$i], -99, -99, $grippySize, $grippySize) ;"hide" grippies
            Next


            If $cursorInfo[2] = 0 Then
                $MODE = $INITMOVE ;end move mode and go back to ready-to-move mode
;~          GUICtrlSetState($background, 128) ;disable background so that user can click buttons
                $currentType = ""
                ToolTip('')
            EndIf
        EndIf
    EndIf
WEnd
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Ok, there's probably more than needed in this but it works (parts of GuiBuilder).

Select the Config/Move menu so that it's checked and the controls can be move.

Select the Config/Move menu so that it's unchecked and the controls can be used.

Thanks gafrost, thats great, this is pretty much exactly what i needed

thanks :P

Link to comment
Share on other sites

just add the pic to the gui i.e. just below the buttons and label and see what happens

$pic=GUICtrlCreatePic(@Systemdir & "\oobe\images\mslogo.jpg",10,120, 200,50)

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Cleaned it up some, make a little easier to use.

#include <GUIConstants.au3>

Opt("MustDeclareVars", 1)

Global $MODE = 2   ; 2 = waiting to move, 3 = moving
Global $INITMOVE = 2, $MOVING = 3
Global $cursorInfo, $hover, $currentCtrl, $xOffset, $yOffset, $c
Global $grippySize = 6 ;pixel size

_Main()

Func _Main()
    Local $main, $menu_Config, $menu_move, $overlay
    Local $grippy[9] ;I'll use indices 1 - 8
    Local $background, $Button_1, $Button_2, $label, $pic, $msg
    $main = GUICreate("My GUI Button") ; will create a dialog box that when displayed is centered
    $menu_Config = GUICtrlCreateMenu("Config")
    $menu_move = GUICtrlCreateMenuitem("Move Controls", $menu_Config)
    $overlay = GUICtrlCreateLabel("foo", -99, -99, 1, 1, 0x107)  ;transparent label with black border


    For $i = 1 To 8
        $grippy[$i] = GUICtrlCreateLabel("", -99, -99, $grippySize, $grippySize, 0x104) ;black square
    Next


    $background = GUICtrlCreatePic("", 0, 0, 1024, 768);, $BACKG_STYLE) ;used to show a grid
    GUICtrlSetState($background, 128) ;disable background so that user can click buttons

    $Button_1 = GUICtrlCreateButton("Run Notepad", 10, 30, 100, 25)
    $Button_2 = GUICtrlCreateButton("Button Test", 10, 60, 100, 25)
    $label = GUICtrlCreateLabel("This is my lable", 10, 90, 120, 25)
    $pic = GUICtrlCreatePic(@SystemDir & "\oobe\images\mslogo.jpg", 10, 120, 200, 50)

    GUISetState()      ; will display an  dialog box with 2 button

    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg(1)
        Select
            Case $msg[0] = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg[0] = $Button_1
                Run('Notepad.exe')    ; Will Run/Open Notepad
            Case $msg[0] = $Button_2
                MsgBox(0, 'Testing', 'Button 2 was pressed')    ; Will demonstrate Button 2 being pressed
            Case $msg[0] = $menu_move
                If BitAND(GUICtrlRead($menu_move), $GUI_CHECKED) Then
                    GUICtrlSetState($menu_move, $GUI_UNCHECKED)
                Else
                    GUICtrlSetState($menu_move, $GUI_CHECKED)
                EndIf
            Case $msg[0] = $overlay And BitAND(GUICtrlRead($menu_move), $GUI_CHECKED)
                _InitMove($main, $overlay)
        EndSelect
        If BitAND(GUICtrlRead($menu_move), $GUI_CHECKED) Then _MoveItem($main, $grippy, $background, $overlay)
    WEnd
EndFunc   ;==>_Main

Func _InitMove(ByRef $main, ByRef $overlay, $ShowTip = False)
    Local $p
    ; drag and drop any control; when done moving, the control will show grippies around it
    $MODE = $MOVING
    $currentCtrl = $hover ;control under the overlay
    $c = ControlGetPos($main, "", $currentCtrl)
    $p = GUIGetCursorInfo($main)
    $xOffset = $p[0] - $c[0]
    $yOffset = $p[1] - $c[1]
    If $ShowTip Then ToolTip($xOffset & "," & $yOffset)
    GUICtrlSetPos($overlay, -99, -99, 1, 1) ;"hide" overlay since we don't need it
    ;EndIf
EndFunc   ;==>_InitMove

Func _MoveItem(ByRef $main, ByRef $grippy, ByRef $background, ByRef $overlay, $ShowTip = False)
    Local $wgcs, $cp, $p
    $cursorInfo = GUIGetCursorInfo()
    Select
        Case $cursorInfo[4] = $grippy[1] ;North-East
            GUISetCursor(12, 1)
        Case $cursorInfo[4] = $grippy[2] ;North
            GUISetCursor(11, 1)
        Case $cursorInfo[4] = $grippy[3] ;North-West
            GUISetCursor(10, 1)
        Case $cursorInfo[4] = $grippy[4] ;West
            GUISetCursor(13, 1)
        Case $cursorInfo[4] = $grippy[5] ;East
            GUISetCursor(13, 1)
        Case $cursorInfo[4] = $grippy[6] ;South-East
            GUISetCursor(10, 1)
        Case $cursorInfo[4] = $grippy[7] ;South
            GUISetCursor(11, 1)
        Case $cursorInfo[4] = $grippy[8] ;South-West
            GUISetCursor(12, 1)
    EndSelect
    ;If cursor is out of bounds, then continue loop
    $wgcs = WinGetClientSize($main)
    If $cursorInfo[0] <= 0 Or $cursorInfo[1] <= 0 Or $cursorInfo[0] >= $wgcs[0] Or $cursorInfo[1] >= $wgcs[1] Then Return
    ; When cursor hovers over a control, change cursor to the sizeall cursor
    ;  I could use GUICtrlSetCursor instead, but that might hurt performance a bit
    If $cursorInfo[4] = 0 Or $cursorInfo[4] = $background Or ($cursorInfo[4] >= $grippy[1] And $cursorInfo[4] <= $grippy[8]) Then
        $hover = 0
        GUICtrlSetPos($overlay, -99, -99, 1, 1)
    Else
        If $cursorInfo[4] <> $overlay Then
            $hover = $cursorInfo[4]

        EndIf
        $cp = ControlGetPos("", "", $cursorInfo[4])
        If $MODE = $INITMOVE Then
            GUICtrlSetPos($overlay, $cp[0], $cp[1], $cp[2], $cp[3])
            If ($cursorInfo[4] < $grippy[1] Or $cursorInfo[4] > $grippy[8]) Then GUISetCursor(2, 1) ;2=regular arrow cursor
        EndIf
    EndIf
    If $MODE = $MOVING Then ;moving
        GUISetCursor(9, 1) ;9=sizeall

        $p = GUIGetCursorInfo($main)
        If $ShowTip Then ToolTip("(" & $p[0] & ", " & $p[1] & ")")

        If $c[0] <> $p[0] Or $c[1] <> $p[1] Then
            GUICtrlSetPos($currentCtrl, $p[0] - $xOffset, $p[1] - $yOffset, $c[2], $c[3])
            $c[0] = $p[0]
            $c[1] = $p[1]
        EndIf

        For $i = 1 To 8
            GUICtrlSetPos($grippy[$i], -99, -99, $grippySize, $grippySize) ;"hide" grippies
        Next


        If $cursorInfo[2] = 0 Then
            $MODE = $INITMOVE ;end move mode and go back to ready-to-move mode
            ToolTip('')
        EndIf
    EndIf
EndFunc   ;==>_MoveItem

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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