Drag and Drop of an image in a Dialog

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
EnderFFX
Pro Scripter
Posts: 92
Joined: Mon Mar 08, 2004 6:17 am

Drag and Drop of an image in a Dialog

Post by EnderFFX » Mon Feb 04, 2013 7:59 pm

Basically what I'm trying to do is this:

Have a couple of images in a dialog
Be able to move the images anywhere within the dialog
If I move an image to a certain portion of the dialog, run a subroutine

Right now I'd be pretty happy with being able to move an image within a dialog. I've been playing with the dialog designer and object properties and have had no luck. Any ideas?

EnderFFX
Pro Scripter
Posts: 92
Joined: Mon Mar 08, 2004 6:17 am

Post by EnderFFX » Mon Feb 04, 2013 8:40 pm

Hey I figured it out!!! Any one have any suggestions for my code?

AddDialogHandler>Dialog1,MSImage1,OnMouseDown,srtMouseDown
AddDialogHandler>Dialog1,MSImage1,OnMouseUp,srtMouseUp

srt>srtMouseDown
GetCursorPos>tmp2MouseX,tmp2MouseY
END>srtMouseDown

srt>srtMouseUp
GetCursorPos>tmpMouseX,tmpMouseY
Sub>tmpMouseX,tmp2MouseX
Sub>tmpMouseY,tmp2MouseY
GetDialogProperty>Dialog1,MSImage1,Left,FinalX
GetDialogProperty>Dialog1,MSImage1,Top,FinalY
Add>FinalX,tmpMouseX
Add>FinalY,tmpMouseY
SetDialogProperty>Dialog1,MSImage1,Left,FinalX
SetDialogProperty>Dialog1,MSImage1,Top,FinalY
END>srtMouseUp

Any suggestions would be greatly appreciated, but I must say I'm pretty proud :)

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Feb 04, 2013 9:11 pm

Congrats on your success!

This script is a little more complex but it gives you dynamic movement. Also by placing "(1), (2), (3) etc" at the end of the AddDialogHandler> line you are set up to be able to move multiple images.

Code: Select all

OnEvent>key_down,VK27,0,Quit

SRT>Quit
  Exit>0
END>Quit

Input>Image,Pick a jpg  bmp or png

If>image=
  MDL>No image selected
  Exit>0
EndIf

Let>ClickFlag=0

Dialog>Dialog1
object Dialog1: TForm
  Caption = 'Move Image'
  ClientHeight = 300
  ClientWidth = 500
  object MSImage1: tMSImage
    Left = 0
    Top = 0
    Width = 105
    Height = 105
    AutoSize = True
  end
end
EndDialog>Dialog1

  SetDialogProperty>Dialog1,MSImage1,LoadImage,%image%
  AddDialogHandler>Dialog1,MSImage1,OnMouseDown,MoveImage(1)
  AddDialogHandler>Dialog1,MSImage1,OnMouseUp,StopImage
  AddDialogHandler>Dialog1,,OnClose,Quit

Show>Dialog1

Label>IdleLoop
  Wait>0.01
  If>ClickFlag>1
    Add>ClickFlag,1
    If>ClickFlag>10
      Let>ClickFlag=0
    EndIf
  EndIf
Goto>IdleLoop


SRT>MoveImage
  Label>Loop
  If>ClickFlag=2
    Goto>LoopEnd
  EndIf
    If>ClickFlag=0
      GetCursorPos>CurX,CurY
      GetDialogProperty>Dialog1,msImage%moveimage_var_1%,Left,Xpos
      GetDialogProperty>Dialog1,msImage%moveimage_var_1%,Top,Ypos
      Let>Xdiff={%curX%-%Xpos%}
      Let>Ydiff={%curY%-%Ypos%}
      Let>ClickFlag=1
    EndIf
      If>ClickFlag=1
        GetCursorPos>CurX,CurY
        Let>Xpos=%CurX%-%Xdiff%
        Let>Ypos=%CurY%-%Ydiff%
        SetDialogProperty>Dialog1,msImage%moveimage_var_1%,Left,Xpos
        SetDialogProperty>Dialog1,msImage%moveimage_var_1%,Top,Ypos
      EndIf
    EndIf
  Goto>Loop
  Label>LoopEnd
END>MoveImage

SRT>StopImage
  Let>ClickFlag=2
END>StopImage

EnderFFX
Pro Scripter
Posts: 92
Joined: Mon Mar 08, 2004 6:17 am

Post by EnderFFX » Wed Feb 06, 2013 9:21 pm

Just thought I'd post my final code:

/*I think this section could be minimized with a loop%/
AddDialogHandler>Dialog1,MSImage1,OnMouseDown,srtMoveImage(1)
AddDialogHandler>Dialog1,MSImage1,OnMouseUp,srtFinishImage(1)
AddDialogHandler>Dialog1,MSImage2,OnMouseDown,srtMoveImage(2)
AddDialogHandler>Dialog1,MSImage2,OnMouseUp,srtFinishImage(2)
AddDialogHandler>Dialog1,,OnClose,Quit

SRT>Quit
Exit>0
END>Quit

srt>srtMoveImage
let>tmpClickFlag=1
let>tmpCurrentImage=%srtmoveimage_var_1%
GetCursorPos>tmp2MouseX,tmp2MouseY
END>srtMoveImage

/*Finish image and update image should be able to be combined%/

srt>srtFinishImage
let>tmpClickFlag=0
GetCursorPos>tmpMouseX,tmpMouseY
Sub>tmpMouseX,tmp2MouseX
Sub>tmpMouseY,tmp2MouseY
let>tmpCurrentImage=%srtfinishimage_var_1%
GetDialogProperty>Dialog1,MSImage%srtfinishimage_var_1%,Left,FinalX
GetDialogProperty>Dialog1,MSImage%srtfinishimage_var_1%,Top,FinalY
Add>FinalX,tmpMouseX
Add>FinalY,tmpMouseY
SetDialogProperty>Dialog1,MSImage%srtfinishimage_var_1%,Left,FinalX
SetDialogProperty>Dialog1,MSImage%srtfinishimage_var_1%,Top,FinalY
GetCursorPos>tmp2MouseX,tmp2MouseY
END>srtFinishImage

srt>srtUpdateImage
GetCursorPos>tmpMouseX,tmpMouseY
Sub>tmpMouseX,tmp2MouseX
Sub>tmpMouseY,tmp2MouseY
GetDialogProperty>Dialog1,MSImage%tmpCurrentImage%,Left,FinalX
GetDialogProperty>Dialog1,MSImage%tmpCurrentImage%,Top,FinalY
Add>FinalX,tmpMouseX
Add>FinalY,tmpMouseY
SetDialogProperty>Dialog1,MSImage%tmpCurrentImage%,Left,FinalX
SetDialogProperty>Dialog1,MSImage%tmpCurrentImage%,Top,FinalY
GetCursorPos>tmp2MouseX,tmp2MouseY
END>srtUpdateImage

srt>srtExit
Exit
END>srtExit

Let>tmpClickFlag=0
Let>tmpShowImage=0
Show>Dialog1
Label>IdleLoop

Wait>0.01
If>tmpClickFlag=1
Add>tmpShowImage,1
If>tmpShowImage=2
GoSub>srtUpdateImage
Let>tmpShowImage=0
EndIf
EndIf

Goto>IdleLoop

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Wed Feb 06, 2013 10:43 pm

Hi EnderFFX,

Very interesting macro - thanks for sharing, however I am wondering though about the following line (and others like it):

/*I think this section could be minimized with a loop%/


The above line seems to be a comment line.

For a single line comment, you could have just done this:

//I think this section could be minimized with a loop

And if you highlighted the line in the MS Editor then clicked Edit/Block Comment, it would have generated this:

/*
I think this section could be minimized with a loop
*/

And even if you shortened it, it would have been this:

/*I think this section could be minimized with a loop*/

So basically I am wondering where that % came from.

When you post code here on the forums, if you don't put your code inside a "Code block" and turn things like HTML, BBCode and Smilies off... sometimes certain characters in your script will get messed up and then others won't be able to run it as posted. I am guessing that is what happened here and perhaps other chars have been altered.

To make sure this excellent example is here for others to try, could I ask you to please repost your final working macro in another post below?

This time be sure to highlight your script lines then click the "Code" button.

Also, make sure you have checkmarks beside the following Options:

__ Disable HTML in this post
__ Disable BBCode in this post
__ Disable Smilies in this post

Then submit the post and we should all be able to see your code as intended.

Thanks again for a very interesting example!
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

EnderFFX
Pro Scripter
Posts: 92
Joined: Mon Mar 08, 2004 6:17 am

Post by EnderFFX » Wed Feb 06, 2013 11:07 pm

I'm sorry about the comments!! I just added those two comments real quick when I cut and paste it in! I wasn't even thinking someone would grab my code and it wouldn't work. Thank you for pointing that out.
jpuziano wrote:Hi EnderFFX,

Very interesting macro - thanks for sharing, however I am wondering though about the following line (and others like it):

/*I think this section could be minimized with a loop%/


The above line seems to be a comment line.

For a single line comment, you could have just done this:

//I think this section could be minimized with a loop

And if you highlighted the line in the MS Editor then clicked Edit/Block Comment, it would have generated this:

/*
I think this section could be minimized with a loop
*/

And even if you shortened it, it would have been this:

/*I think this section could be minimized with a loop*/

So basically I am wondering where that % came from.

When you post code here on the forums, if you don't put your code inside a "Code block" and turn things like HTML, BBCode and Smilies off... sometimes certain characters in your script will get messed up and then others won't be able to run it as posted. I am guessing that is what happened here and perhaps other chars have been altered.

To make sure this excellent example is here for others to try, could I ask you to please repost your final working macro in another post below?

This time be sure to highlight your script lines then click the "Code" button.

Also, make sure you have checkmarks beside the following Options:

__ Disable HTML in this post
__ Disable BBCode in this post
__ Disable Smilies in this post

Then submit the post and we should all be able to see your code as intended.

Thanks again for a very interesting example!

EnderFFX
Pro Scripter
Posts: 92
Joined: Mon Mar 08, 2004 6:17 am

Post by EnderFFX » Wed Feb 06, 2013 11:09 pm

I never realized about the Code block option:

Code: Select all


AddDialogHandler>Dialog1,MSImage1,OnMouseDown,srtMoveImage(1)
AddDialogHandler>Dialog1,MSImage1,OnMouseUp,srtFinishImage(1)
AddDialogHandler>Dialog1,MSImage2,OnMouseDown,srtMoveImage(2)
AddDialogHandler>Dialog1,MSImage2,OnMouseUp,srtFinishImage(2)
AddDialogHandler>Dialog1,,OnClose,Quit

SRT>Quit
  Exit>0
END>Quit


srt>srtMoveImage
    let>tmpClickFlag=1
    let>tmpCurrentImage=%srtmoveimage_var_1%
    GetCursorPos>tmp2MouseX,tmp2MouseY
END>srtMoveImage

srt>srtFinishImage
    let>tmpClickFlag=0
    GetCursorPos>tmpMouseX,tmpMouseY
    Sub>tmpMouseX,tmp2MouseX
    Sub>tmpMouseY,tmp2MouseY
    let>tmpCurrentImage=%srtfinishimage_var_1%
    GetDialogProperty>Dialog1,MSImage%srtfinishimage_var_1%,Left,FinalX
    GetDialogProperty>Dialog1,MSImage%srtfinishimage_var_1%,Top,FinalY
    Add>FinalX,tmpMouseX
    Add>FinalY,tmpMouseY
    SetDialogProperty>Dialog1,MSImage%srtfinishimage_var_1%,Left,FinalX
    SetDialogProperty>Dialog1,MSImage%srtfinishimage_var_1%,Top,FinalY
    GetCursorPos>tmp2MouseX,tmp2MouseY
END>srtFinishImage

srt>srtUpdateImage
    GetCursorPos>tmpMouseX,tmpMouseY
    Sub>tmpMouseX,tmp2MouseX
    Sub>tmpMouseY,tmp2MouseY
    GetDialogProperty>Dialog1,MSImage%tmpCurrentImage%,Left,FinalX
    GetDialogProperty>Dialog1,MSImage%tmpCurrentImage%,Top,FinalY
    Add>FinalX,tmpMouseX
    Add>FinalY,tmpMouseY
    SetDialogProperty>Dialog1,MSImage%tmpCurrentImage%,Left,FinalX
    SetDialogProperty>Dialog1,MSImage%tmpCurrentImage%,Top,FinalY
    GetCursorPos>tmp2MouseX,tmp2MouseY
END>srtUpdateImage


srt>srtExit
    Exit
END>srtExit

Let>tmpClickFlag=0
Let>tmpShowImage=0
Show>Dialog1
Label>IdleLoop

Wait>0.01
If>tmpClickFlag=1
    Add>tmpShowImage,1
    If>tmpShowImage=2
        GoSub>srtUpdateImage
        Let>tmpShowImage=0
    EndIf
EndIf

Goto>IdleLoop




User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Wed Feb 06, 2013 11:23 pm

Thanks EnderFFX - looking good!
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts