mouseDown and within

Alex Tweedly alex at tweedly.net
Sat Apr 23 16:34:43 EDT 2005


Thomas McGrath III wrote:

> Hey Eric and others,
>
> HELP, I am so damn close.
>
> With the adjusted script below I can pretend to trap a mouseUp even 
> though the actual mouseUp handler in my script doesn't receive it. 
> (This is because of the mouseDown issue "bug", sort of, at least to me 
> it is!). Any way the check if the mouse is up works over the new 
> control at present and I get to hear the "mouse up" which will be 
> replaced later with my necessary code.
>
> The problem now comes down to one thing.
> 1. The highlights don't always un-highlight and seems to be a time 
> related thing. I tried 50 ms, 10 ms, 1 ms, and 5 ms - If I move the 
> mouse around in the down state I end up with a trail of highlighted 
> buttons left behind. Not all of them and some times it seems like the 
> same ones but I can't prove that.

Thomas, I haven't had good email access for the last few days, so I 
hadn't been following this thread closely - so I may have missed a 
problem described earlier, but....

your description of the PDA interactions required seemed straightforward 
(and I didn't like the sound of debugging time-related or race 
conditions), so I thought I'd try it from scratch.

The following script does what I think you want :-), with no hilites 
left behind or other issues.

Notes:
1. I created four buttons (B1,B2,B3,B4), and set the "auto-hilite" of 
each to false (otherwise the hilite is unhelpfully removed for you when 
the mouse leaves the initial button)

2. I put all four buttons within a group - and put all the code below in 
the *group*'s script.

3. It assumes that you start off with "theOne" set to empty; this will 
be the case in production use (because it always sets it to empty on 
mouseUp/Release - but beware that in development (e.g. if a script stops 
with an error), you'll need to tidy that up before restarting the 
script.  I added an extra button (tidy) to the group and the script, and 
did this tidying up in there.

4. I left in some of the debugging  - lines like
    put "A" && ..... where the initial letter let's me know which line 
is doing it ...

> global theKeys, theOne
>
> on mouseDown
>  
>   -- tidy up - for development use only
>   if the short name of the mouseControl = "Tidy" then
>     put "B1,B2,B3,B4" into theKeys    -- should be elsewhere !!
>     put empty into theOne
>     exit mouseDown
>   end if
>  
>   put the short name of the mouseControl into theOne
>   set the hilite of button theOne to true
> end mouseDown
>
> on mouseMove x,y
>   if theOne is empty then exit mouseMove
>   repeat for each item B in theKeys
>     if the mouseloc is within the rect of button B then
>       if theOne <> B then
>         if theOne is not empty then
>           set the hilite of button theOne to false
> --          put "A" &&  theOne && "false" & cr after msg
>         end if
>         put B into theOne
>         put B & Cr after msg    -- or into a field to display
>         set the hilight of button B to true
> --        put "B" &&  theOne && "true" & cr after msg
>       end if
>     else
>       if B <> theOne then
>         if the hilite of button B then
>           put B & Cr after msg
>           set the hilight of button B to false
> --          put "C" &&  theOne && "false" & cr after msg
>         end if
>       end if
>     end if
>   end repeat
> end mouseMove
>
> on mouseUp
>   if theOne is not empty then
>     set the hilite of button theOne to false
>     if the mouseloc is within the rect of group id 1076then put 
> "mouseUp select " && theOne & cr after msg
>     put empty into theOne
>   end if
> end mouseUp
>
> on mouseRelease
>   if theOne is not empty then
>     set the hilite of button theOne to false
>     if the mouseloc is within the rect of group id 1076 then put 
> "mouseRelease select " && theOne & cr after msg
>     put empty into theOne
>   end if
> end mouseRelease




-- 
Alex Tweedly       http://www.tweedly.net

-------------- next part --------------
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.10.2 - Release Date: 21/04/2005


More information about the use-livecode mailing list