[comp.sys.next] YAPQ - Yet another programming question

zimmer@calvin.stanford.edu (Andrew Zimmerman) (03/12/91)

    I have a routine in a custom view that makes a call to 
NXRect (I think that is the function.  It is like NXDrawButton).
It seems that the coordinate system that it uses is different depending
on which method calls it.  I have a method called selfDraw which seems
to work just fine (The origin in the origin of the custom view).  The
other method that calls it (mouseDown) seems to use the origin of the
window that the custom view is in.  I do know that to get the coordinates
of where the mouse is, I have to send a message to convert to the
view coordinate system (That seems to work).  
    My Question:  Is there a way to make a C routine that calls the
NX functions always use the coordinate system of my custom view?

Thanks,
Andrew
zimmer@calvin.stanford.edu

scott@texnext.gac.edu (Scott Hess) (03/13/91)

In article <1991Mar12.082358.3527@neon.Stanford.EDU> zimmer@calvin.stanford.edu (Andrew Zimmerman) writes:
       I have a routine in a custom view that makes a call to 
   NXRect (I think that is the function.  It is like NXDrawButton).
   It seems that the coordinate system that it uses is different depending
   on which method calls it.  I have a method called selfDraw which seems
   to work just fine (The origin in the origin of the custom view).  The
   other method that calls it (mouseDown) seems to use the origin of the
   window that the custom view is in.  I do know that to get the coordinates
   of where the mouse is, I have to send a message to convert to the
   view coordinate system (That seems to work).  

Depends on what you mean.  The "coordinate system" of methods in a
View subclass would be that of the View itself.  But, for some methods,
parameters passed are in different coordinate systems.  Many methods
(hitTest: comes to mind, but just because I had to read its docs
last night) pass in points or rects in the superview's coordinate
system.  mouseDown: passes an event record.  The e->location (e
is the passed event pointer) is in the window's coordinate system.
To convert to the view's, copy the value to another variable and do
convertPoint:fromView: to get something that you can work with:

- mouseDown:(NXEvent *)e
{
  NXPoint p=e->location;                // Copy the point.
  [self convertPoint:&p fromView:nil];  // Convert to your coordinates.
  [self mungeInGnarlyWays:&p];          // Play with the result.
  return self;
}

You'll have to read the docs to find out which other methods have
parameters which are not in the View's coordinates.

BTW:  There are also weird and wonderful border conditions at the top
and bottom that happen if you're using a flipped view and testing
a point for inclusion in a rectangle.  In that case, use View's
mouse:inRect: to test for inclusion.

Later,
--
scott hess                      scott@gac.edu
Independent NeXT Developer	GAC Undergrad
<I still speak for nobody>
"Tried anarchy, once.  Found it had too many constraints . . ."
"I smoke the nose Lucifer . . . Banana, banana."