Thread View: comp.sys.next.programmer
1 messages
1 total messages
Started by Ronald P. Blanford
Mon, 28 Sep 1992 16:44
Re: Help: non-rectangular buttons (again)
Author: Ronald P. Blanford
Date: Mon, 28 Sep 1992 16:44
Date: Mon, 28 Sep 1992 16:44
67 lines
2162 bytes
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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads