View Full Version : Marquee with mouse tool


d3coy
02 February 2006, 02:02 PM
Hi all,
I was wondering if there is a way to easily display a marquee with a mouse tool--the mouse tool function can return the viewpoint (point2 loc of mouse in viewport), but I can't find a function to display a marquee in the reference. The script I'm working on has two mouse clicks involved, one that gets the start position and one that gets the end position.

Bobo
02 February 2006, 03:19 PM
Hi all,
I was wondering if there is a way to easily display a marquee with a mouse tool--the mouse tool function can return the viewpoint (point2 loc of mouse in viewport), but I can't find a function to display a marquee in the reference. The script I'm working on has two mouse clicks involved, one that gets the start position and one that gets the end position.


Take a look at the gw. drawing methods. These allow you to draw graphic primitives and text staight to the viewport.

d3coy
02 February 2006, 07:59 PM
Thanks Bobo,

With drawing the polyline -- since it requires point3 data and I'm wanting to go off of point2 derived from the viewpoint in a mousetool, I'm running into a problem in the conversion. Anytime I send point3's to the gw methods, it uses the currently active viewport's transform matrix. Is there a way I can override this and supply my own matrix? I've tried using the mapscreentoview function, but again, this only supplies point3's using the current transform matrix. Running into a wall here! Been at it for a few days -- I've only been able to draw my polyline in the top view successfully since this viewport inately has the necessary transform matrix (matrix3 [1,0,0] [0,1,0] [0,0,1] [0,0,0]). Even though it draws here, there're strange things involving the updating of it. gw.updatescreen() doesn't seem to work all the time?

Bobo
02 February 2006, 03:56 AM
Thanks Bobo,

With drawing the polyline -- since it requires point3 data and I'm wanting to go off of point2 derived from the viewpoint in a mousetool, I'm running into a problem in the conversion. Anytime I send point3's to the gw methods, it uses the currently active viewport's transform matrix. Is there a way I can override this and supply my own matrix? I've tried using the mapscreentoview function, but again, this only supplies point3's using the current transform matrix. Running into a wall here! Been at it for a few days -- I've only been able to draw my polyline in the top view successfully since this viewport inately has the necessary transform matrix (matrix3 [1,0,0] [0,1,0] [0,0,1] [0,0,0]). Even though it draws here, there're strange things involving the updating of it. gw.updatescreen() doesn't seem to work all the time?




(
global testMarquee
try(destroyDialog testMarquee)catch()
rollout testMarquee "Marquee Test"
(
local theLine = #()
checkbox enableIt "Enable"
timer theTimer interval:50 active:false
button resetLine "Reset"

on enableIt changed state do theTimer.active = state
on resetLine pressed do theLine = #()

on theTimer tick do
(
if mouse.buttonStates[1] == true then
(
thePos = mouse.pos
append theLine [thePos.x, thePos.y, 0]
gw.setTransform (viewport.getTM())
gw.wpolyLine theLine false
gw.enlargeUpdateRect #whole
gw.updateScreen()
)
else
theLine = #()
)
)
createDialog testMarquee
)

First, set the transformation matrix to the TM of the current view.
Then draw the polyline, enlarge the update rectange to the whole screen and update the screen. It is a good idea to set the driver to "Redraw On Windows Expose" for clean results.

Start the tool, check the checkbox, click in a viewport and drag while holding the left mouse button pressed.

d3coy
02 February 2006, 07:50 AM
Awesome, thanks again Bobo. I incorporated it into a render region tool:


tool getRegion
(
local firstcoord
local secondcoord
local viewsize
local finalregion
local marquee = #(0, 0, 0, 0)

on mousepoint clickno do
(
if clickno == 1 do
(
viewsize = getviewsize()
firstcoord = viewpoint
marquee[1] = [viewpoint.x, viewpoint.y, 0]
)

if clickno == 2 do
(
secondcoord = viewpoint
if firstcoord.x > secondcoord.x do
(
local fx = firstcoord.x
local sx = secondcoord.x
firstcoord.x = sx
secondcoord.x = fx
)
if firstcoord.y > secondcoord.y do
(
local fy = firstcoord.y
local sy = secondcoord.y
firstcoord.y = sy
secondcoord.y = fy
)
finalregion = box2 firstcoord.x firstcoord.y (secondcoord.x - firstcoord.x) (secondcoord.y - firstcoord.y)
render outputwidth:viewsize.x outputheight:viewsize.y rendertype:#regioncrop region:finalregion
stoptool getRegion
)
)

on mousemove clickno do
(
completeredraw()
gw.setcolor #line (color 125 175 255)
marquee[3] = [viewpoint.x, viewpoint.y, 0]
marquee[2] = [marquee[1].x, marquee[3].y, 0]
marquee[4] = [marquee[3].x, marquee[1].y, 0]
gw.settransform(viewport.gettm())
gw.wpolyline marquee true
gw.enlargeupdaterect #whole
gw.updatescreen()
)
)


The completeredraw in there slows things down quite a lot -- is there possibly a way to clear the previously created polylines yet still retain the geometry underneath so the user can see what they are marquee'ing? I tried a few methods -- I suppose I could just keep the ghosting lines there and just clean them up after the tool ends.

CGTalk Moderation
02 February 2006, 07:50 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.


1