[futurebasic] Re: [FB] Beginner: Mouse function

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : January 2010 : Group Archive : Group : All Groups

From: Robert Covington <artlythere@...>
Date: Sat, 30 Jan 2010 11:09:38 -0500
On Jan 30, 2010, at 4:05 AM, Emmett wrote:

> I am actually working on a program finally. Building it by reading  
> the FB Help.
> Need to use mouse locations.
> Wanted to study the Example shown for mouse <position> function.
>
> The program does not work as shown. It does run it just don't work.
> Made some corrections and it runs and works kinda.
> Made more corrections and it runs and works good but not as expected.
> Still won't quit without Command + Option + Escape.
>
> It will not print anything like it says "Move the mouse around"
> unless you hold the L or R or Both mouse button down while moving  
> the mouse.
> It will not quit with Cmd-period.
> Emmett

There may have been some changes since the new FB5/C runtime came  
about making things report differently (haven't tested that example)

For knowing where my mouse is , I tend to use the toolbox  GetMouse 
(pt) and track rectangles with Fn PtInRect(pt,r).

There are newer ways to do this with CarbonEvents.

Let's say you want the mouse position relative to the window,

dim pt as point

Window 1 // make it active, assuming we have one here :)
GetMouse(pt)

Now if you need to track that globally (relative to the screen) can  
use LocalToGlobal(pt) or alternately GlobalToLocal(pt)

For loops,  in Fn DoMouse, if using On Mouse Fn DoMouse vector, can  
check via

dim as point pt1, pt2
dim as int x , y

GetMouse(pt1)
pt2 = pt1
// Let's say you want to move something while it is down

While Fn StillDown // need to add a KillSpinningCursor for the  
beachball though
GetMouse(pt2)
long if (Fn EqualPt(pt1,pt2) = _False) //  current location has changed
x = pt2.h%-pt1.h%
y= pt2.v%-pt1.v%
// Do Something
Fn OffsetTheWorldAndDrawInAnotherPlace(x,y)
pt1 = pt2 // set equal again so loop does not repeat if not necessary.
end if
Wend

I wrote this in the email, so might need some tweaking.

If you need to constantly track mouse location for information  
purposes, might be best to use CarbonEvents, or set up some kind of  
checker in your event loop. In FB4, can just stick one in the  
HandleEvents loop

Do
HandleEvents
Fn TrackMouse
until gFBQuit

But in FB5, that is not polled like it used to be without some manual  
adjustment.

(methinks, I am rusty right now, mostly in code maintenance mode for  
a while)

rc