🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.next.programmer
Article #1636

Re: Help: non-rectangular buttons (again)

#1636
From: Ronald P. Blanford
Date: Mon, 28 Sep 1992 16:44
67 lines
2162 bytes
In comp.sys.next.programmer I wrote:
> Some time back there was a discussion of how to implement 
> non-rectangular buttons.  The upshot, I believe, was to define  
a 
> Postscript path and use Postscript functions to determine if  
the 
> mouse click falls within the path.
>
> If you kept this information around, could you please send me  
a 
> copy?  Thanks.
>

Having received no response, I went ahead and figured it out  
myself.

// In your pswraps define the PSW functions...

defineps PSWButtonPath()
    % define the irregular button path
    newpath 0 0 moveto 0 100 lineto 100 0 lineto closepath
    
    % store it in a user path
    /mybuttonpath false upath cvlit def
    
    % show the button if you want to
    0.5 setgray fill
endps

defineps PSWButtonHit(float x, y | boolean *hit)
    % test for intersection between user path and mouse point
    x y mybuttonpath inufill hit
endps


// In your View subclass do...

- drawSelf:(const NXRect *)rects :(int)rectCount
{
    /* draw the user path for control button */
    PSWButtonPath();
    return self;
}

- mouseDown:(NXEvent *)theEvent;
{
    /* check for a hit on the outline */
    NXPoint location = theEvent->location;
    int hit;

    [self convertPoint:&location fromView:nil];
    PSWButtonHit(location.x, location.y, &hit);
    fprintf(stderr, "button %s\n", hit?"hit":"miss");
    
    if (hit) {
      /* do button action */
    }
    
    return self;
}


Of course, it becomes even more fun if the button is moving or  
changing shape as the application runs.  This is left as an  
exercise for the reader...
 
-- Ron
Technical Details
Message-ID: <2AC73676.6ED0@deneva.sdd.trw.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!walter!att-out!pacbell.com!iggy.GW.Vitalink.COM!cs.widener.edu!ukma!darwin.sura.net!spool.mu.edu!sol.ctr.columbia.edu!usc!venice!gumby.dsd.trw.com!deneva!news

Show Full Headers
Complete Article Headers
Newsgroups: comp.sys.next.programmer
Path: arc1-ca.pugleaf.net!sparky!uunet!walter!att-out!pacbell.com!iggy.GW.Vitalink.COM!cs.widener.edu!ukma!darwin.sura.net!spool.mu.edu!sol.ctr.columbia.edu!usc!venice!gumby.dsd.trw.com!deneva!news
From: blanford@spf.trw.com (Ronald P. Blanford)
Subject: Re: Help: non-rectangular buttons (again)
Message-ID: <2AC73676.6ED0@deneva.sdd.trw.com>
Sender: news@deneva.sdd.trw.com
Organization: TRW Inc., Redondo Beach, CA
Date: Mon, 28 Sep 92 16:44:36 GMT
Lines: 67