forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Capture Area Coords with Mouse...

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Visual DialogScript 3 Source Code
View previous topic :: View next topic  
Author Message
Mac
Professional Member
Professional Member


Joined: 08 Jul 2000
Posts: 1585
Location: Oklahoma USA

PostPosted: Thu Oct 10, 2002 8:12 pm    Post subject: Capture Area Coords with Mouse... Reply with quote

Here's a couple of methods to capture coordinates
in a viewable area. One uses a rectangle, the other
uses 4 dots (squares) to show the area. Both use
4 text elements to draw with. The text elements are
clickable, because when drawing in reverse (right
to left and/or upward) the mouse is over one of them.

The %%startX, %%endX, %%startY and %%endY
vars contain the coordinates inside the VDS window.
If you need width/height of the area, just subtract the
X and Y differences.

To use these examples: Click to start, click again
to release, and right click to clear screen. If you have
VDS4, you could use the @mousedown() function.

Using the rectangle:
Code:

OPTION SCALE, 96
OPTION DECIMALSEP, "."
TITLE By Mac
%s = "L Click draw/stop, R Click clear -"
%%wintitle = "Get Rectangle Coordinates"
DIALOG CREATE,%%wintitle,-1,0,300,200,CLICK
  DIALOG ADD,STYLE,S1,,,,BLACK
  DIALOG ADD,TEXT,Top,0,0,1,1,,CLICK,S1
  DIALOG ADD,TEXT,Left,0,0,1,1,,,CLICK,S1
  DIALOG ADD,TEXT,Right,0,0,1,1,,,CLICK,S1
  DIALOG ADD,TEXT,Bottom,0,0,1,1,,,CLICK,S1
  DIALOG ADD,STATUS,Stat,%s
  GOSUB Hide
DIALOG SHOW

rem -- Change this for wider line --
%%linewidth = 1

:TopCLICK
:LeftCLICK
:RightCLICK
:BottomCLICK
:EVLOOP
  WAIT EVENT
  goto @event()

:CLICK
  GOSUB Hide
  if @equal(@click(B), "RIGHT")
     DIALOG SET, Stat, %s
     goto EVLOOP
  end
  %%startX = @diff(@mouse(X), @sum(@winpos(%%wintitle, L), 3))
  %%startY = @diff(@mouse(Y), @sum(@winpos(%%wintitle, T), 22))
  GOSUB Show
  REPEAT
    %%endX = @diff(@mouse(X), @sum(@winpos(%%wintitle, L), 3))
    %%endY = @diff(@mouse(Y), @sum(@winpos(%%wintitle, T), 22))
    DIALOG SET, Stat, %s %%startX|%%startY to %%endX|%%endY
    GOSUB Draw
  UNTIL @event()
  if @equal(@click(B), "LEFT")
     GOSUB AdjustXY
     DIALOG SET, Stat, %s %%startX|%%startY to %%endX|%%endY
  else
     DIALOG SET, Stat, %s
     GOSUB Hide
  end
  goto EVLOOP

:CLOSE
  EXIT

rem ---- SUB ----

:Draw
  if @greater(%%endX,%%startX)
     DIALOG SETPOS,Top,%%startY,%%startX,@diff(%%endX,%%startX),%%linewidth
     DIALOG SETPOS,Bottom,%%endY,%%startX,@diff(%%endX,%%startX),%%linewidth
  else
     DIALOG SETPOS,Top,%%endY,%%endX,@diff(%%startX,%%endX),%%linewidth
     DIALOG SETPOS,Bottom,%%startY,%%endX,@diff(%%startX,%%endX),%%linewidth
  end
  if @greater(%%endY,%%startY)
     DIALOG SETPOS,Left,%%startY,%%startX,%%linewidth,@sum(@diff(%%endY,%%startY),%%linewidth)
     DIALOG SETPOS,Right,%%startY,%%endX,%%linewidth,@sum(@diff(%%endY,%%startY),%%linewidth)
  else
     DIALOG SETPOS,Left,%%endY,%%startX,%%linewidth,@sum(@diff(%%startY,%%endY),%%linewidth)
     DIALOG SETPOS,Right,%%endY,%%endX,%%linewidth,@sum(@diff(%%startY,%%endY),%%linewidth)
  end
  exit

:AdjustXY
  rem -- Make sure the smaller XY is considered starting point --
  if @greater(%%startX, %%endX)
     %%tmp = %%startX
     %%startX = %%endX
     %%endX = %%tmp
  end
  if @greater(%%startY, %%endY)
     %%tmp = %%startY
     %%startY = %%endY
     %%endY = %%tmp
  end
  %%tmp = ""
  exit

:Hide
  rem -- Prevent leftover coords from last rectangle --
  DIALOG SETPOS,Top,0,0,1,1
  DIALOG SETPOS,Left,0,0,1,1
  DIALOG SETPOS,Right,0,0,1,1
  DIALOG SETPOS,Bottom,0,0,1,1
  rem -- Hide in reverse order of creation --
  DIALOG HIDE, Bottom
  DIALOG HIDE, Right
  DIALOG HIDE, Left
  DIALOG HIDE, Top
  exit

:Show
  DIALOG SHOW, Top
  DIALOG SHOW, Left
  DIALOG SHOW, Right
  DIALOG SHOW, Bottom
  exit


Using the dots:
Code:

OPTION SCALE, 96
OPTION DECIMALSEP, "."
TITLE By Mac
%s = "L Click draw/stop, R Click clear -"
%%wintitle = "Get Rectangle Coordinates"
DIALOG CREATE,%%wintitle,-1,0,300,200,CLICK
  DIALOG ADD,STYLE,S1,,,,BLACK
  DIALOG ADD,TEXT,T1,0,0,1,1,,CLICK,S1
  DIALOG ADD,TEXT,T2,0,0,1,1,,,CLICK,S1
  DIALOG ADD,TEXT,T3,0,0,1,1,,,CLICK,S1
  DIALOG ADD,TEXT,T4,0,0,1,1,,,CLICK,S1
  DIALOG ADD,STATUS,Stat,%s
  GOSUB Hide
DIALOG SHOW

rem -- Change this for larger dots --
%%linewidth = 2

:T1CLICK
:T2CLICK
:T3CLICK
:T4CLICK
:EVLOOP
  WAIT EVENT
  goto @event()

:CLICK
  GOSUB Hide
  if @equal(@click(B), "RIGHT")
     DIALOG SET, Stat, %s
     goto EVLOOP
  end
  %%startX = @diff(@mouse(X), @sum(@winpos(%%wintitle, L), 3))
  %%startY = @diff(@mouse(Y), @sum(@winpos(%%wintitle, T), 22))
  GOSUB Show
  REPEAT
    %%endX = @diff(@mouse(X), @sum(@winpos(%%wintitle, L), 3))
    %%endY = @diff(@mouse(Y), @sum(@winpos(%%wintitle, T), 22))
    DIALOG SET, Stat, %s %%startX|%%startY to %%endX|%%endY
    GOSUB Draw
  UNTIL @event()
  if @equal(@click(B), "LEFT")
     GOSUB AdjustXY
     DIALOG SET, Stat, %s %%startX|%%startY to %%endX|%%endY
  else
     DIALOG SET, Stat, %s
     GOSUB Hide
  end
  goto EVLOOP

:CLOSE
  EXIT

rem ---- SUB ----

:Draw
  DIALOG SETPOS,T1,%%startY,%%startX,%%linewidth,%%linewidth
  DIALOG SETPOS,T2,%%startY,%%endX,%%linewidth,%%linewidth
  DIALOG SETPOS,T3,%%endY,%%startX,%%linewidth,%%linewidth
  DIALOG SETPOS,T4,%%endY,%%endX,%%linewidth,%%linewidth
  exit

:AdjustXY
  rem -- Make sure the smaller XY is considered starting point --
  if @greater(%%startX, %%endX)
     %%tmp = %%startX
     %%startX = %%endX
     %%endX = %%tmp
  end
  if @greater(%%startY, %%endY)
     %%tmp = %%startY
     %%startY = %%endY
     %%endY = %%tmp
  end
  %%tmp = ""
  exit

:Hide
  rem -- Prevent leftover coords from last rectangle --
  DIALOG SETPOS,T1,0,0,1,1
  DIALOG SETPOS,T2,0,0,1,1
  DIALOG SETPOS,T3,0,0,1,1
  DIALOG SETPOS,T4,0,0,1,1
  rem -- Hide in reverse order of creation --
  DIALOG HIDE, T4
  DIALOG HIDE, T3
  DIALOG HIDE, T2
  DIALOG HIDE, T1
  exit

:Show
  DIALOG SHOW, T1
  DIALOG SHOW, T2
  DIALOG SHOW, T3
  DIALOG SHOW, T4
  exit

Cheers, Mac

_________________
VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
Back to top
View user's profile Send private message Send e-mail
marty
Professional Member
Professional Member


Joined: 10 May 2001
Posts: 789

PostPosted: Thu Oct 10, 2002 11:50 pm    Post subject: Reply with quote

Great example Mac!!


Thanks! Very Happy Very Happy Very Happy
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Mac
Professional Member
Professional Member


Joined: 08 Jul 2000
Posts: 1585
Location: Oklahoma USA

PostPosted: Fri Oct 11, 2002 9:38 am    Post subject: Reply with quote

No problem Marty, thanks for givin' me the idea. Wink

Cheers, Mac Smile

_________________
VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Visual DialogScript 3 Source Code All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group