Page 1 of 1

weird MouseLoc() results

Posted: Mon Jun 30, 2008 3:12 pm
by rozek
Sigh,

nothing works out of the box...

I'm currently trying to keep track of mouse movements in order to draw a polygon. On MouseDown, I prepare a "templateGraphic" of style "polygon" and

Code: Select all

set the Points of templateGraphic to (MouseLoc() & return)
because I want the polygon to remain open. I then "create graphic" to create the polygon and make it visible.

"On MouseMove newX,newY" I then run the following code:

Code: Select all

local PointList; put the points of the last graphic into PointList
  put newX & comma & newY & return after PointList
set the points of the last graphic to PointList
As a result, I get many vertical bars. If I look into "the points of the last graphic", I see several large positive and negative values (with absolute values > 20000). The mouse positions seem ok, my impression is, that the extension of the polygon produces those weird values...

Does anybody have an idea what goes wrong?

mouseLoc

Posted: Mon Jun 30, 2008 11:19 pm
by bn
Hi Andreas,

I put this script in the card script
-------------------------
local tLocList
on mouseDown
put "" into tLocList
send "recordMouseLoc" to me in 10 milliseconds
end mouseDown

on recordMouseLoc
put the mouseloc & return after tLocList
if the mouse is up then
delete last char of tLocList -- return
set the style of the templategraphic to "polygon"
set the points of the templategraphic to tLocList

-- to avoid a "funny graphic" by accidentally clicking on the card
if the number of lines of tLocList > 4 then
create graphic "myNewPolygon"
end if
else
send "recordMouseLoc" to me in 60 milliseconds -- adjust the timing
end if
end recordMouseLoc
-----------------------------

this works pretty well unless I misunderstood what you were trying to do


to delete all the graphics (it is fun to doodle like this) I added a button to the card with this script:

-------------------------
on mouseUp
put the number of graphics of this card into tSoMany
repeat with i = tSoMany down to 1
delete graphic i
end repeat
end mouseUp

on mouseDown
-- block the mousedown here else you start a new graphic
end mouseDown
--------------------------

regards

Bernd

Posted: Tue Jul 01, 2008 6:56 pm
by rozek
Hello Bernd!

Thanks a lot for your code: I used your idea to write a similar handler which could be slowed down so much that I was able to find the actual reason for the weird behaviour mentioned above.

Although I always appended a "return" to the end of "the points of the last graphic" (to get an open polygon), it seems that this "return" gets lost when I "get the points of the last graphic". Simply adding "(the mouseloc & return)" to that list therefore produced giant point coordinates which RR cannot deal with (and which result in arbitrary coordinates). Appending "(return & the mouseloc & return)" works as foreseen...

Thus, your idea pointed me to the right direction - thank you!