discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Geometry problem


From: Richard Frith-Macdonald
Subject: Re: Geometry problem
Date: Tue, 24 Jun 2003 11:05:21 +0100


On Tuesday, June 24, 2003, at 04:17  am, Kazunobu Kuriyama wrote:

Hi, all.

I have a question about the GNUstep's geometry.
The question is as follows:


       X
   |-------|    Object A
-- +---------------------------------------------------
 | |(0,0)
Y | |
 | |            Object B
-- |       +----------------------------------------
   |       |(X,Y)
   |       |
   |       |
   |       |


Here, you have two GUI objects Object A and Object B.  Object A
is the main window of an GNUstep application, and Object B is an
instance of either the NSView class or its subclass.  The coordinates
system is taken as shown above.

Actually, the direction of increasing Y is upwards (unless you are in a flipped view).

 Ignore the border width for now
because it's a matter of arithmetic.  Then, you need to know the
coordinates values (X, Y) to implement a method declared in the
interface of Object B.  Write a piece of code to calculate X and Y.
The code should be independent of the underlying window system.

I don't understand what you mean.
The coordinates of Object B (an NSView) within the coordinate system of the enclosing ObjectA (an NSWindow), are obtained using the -frame method.
eg.

  NSRect bFrame = [B frame];
  NSLog(@"Position ... x: %f, y: %f", bFrame.origin.x, bFrame.origin.y);


To convert from the local coordinate system (of object A) to the screen coordinate system, you use the NSWindow method -convertBaseToScreen:

eg.

  NSPoint p = [A convertBaseToScreen: bFrame.origin];


If Object A is a parent or ancestor of Object B (in a sense of
window hierarchy), the answer may be easy.  I have no idea,
however, if Object A is an instance of NSApplication.

It isn't.

Could you help me so that I won't devise GSTranslateCoordinates,
a ridiculous wrapper of XTranslateCoordinates() that ruins
the GNUstep's OO structure?

I'm not sure you could wrap XTranslateCoordinates() in such a way that it could meaningfully work within the GNUstep coordinates system... all mappingss betwween X coordinates and GNUstep coordinates are hidden in the backend library and GNUstep user code should never have anything to do with them.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]