Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Thu Oct 10, 2002 8:12 pm Post subject: Capture Area Coords with Mouse... |
|
|
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
|
|