Show
Ignore:
Timestamp:
11/18/07 10:41:11 (1 year ago)
Author:
patrick
Message:

The code in Gadgteteer that wraps the X11 and Win32 windowing systems handles
mouse events using the upper left-hand corner of the window as the origin.
This is the same as what those native windowing systems use as the origin.
Cocoa has the origin in the lower left-hand corner of the window. The
convention with VR Juggler is to use the lower left-hand corner for
positioning windows, but mouse events have been implemented improperly to use
the upper left-hand corner. Thus, the Cocoa code must be adjusted to use the
same coordinate frame as the other windowing systems.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • juggler/branches/2.2/modules/gadgeteer/gadget/Devices/KeyboardMouseDevice/InputAreaCocoa.mm

    r19844 r20927  
    132132                                           fromView:nil]; 
    133133   const NSPoint root_loc = [NSEvent mouseLocation]; 
    134    gadget::EventPtr mouse_event(new gadget::MouseEvent(type, button, 
    135                                                        view_loc.x, view_loc.y, 
    136                                                        root_loc.x, root_loc.y, 
    137                                                        [event modifierFlags], 
    138                                                        [event timestamp])); 
     134 
     135   // The Cocoa coordinate frame has the origin in the lower left-hand corner 
     136   // just as we ought to want for mouse events, but for some reason, the other 
     137   // windowing systems put the origin in the upper left-hand corner. Hence, 
     138   // we have to transform the coordinate frame to be in the upper left-hand 
     139   // corner to be portable. 
     140   gadget::EventPtr mouse_event( 
     141      new gadget::MouseEvent( 
     142         type, button, view_loc.x, mHeight - view_loc.y, root_loc.x, 
     143         [[mCocoaWindow screen] frame].size.height - root_loc.y, 
     144         [event modifierFlags], [event timestamp] 
     145      ) 
     146   ); 
    139147   doAddEvent(mouse_event, button); 
    140148} 
    141  
    142149 
    143150void InputAreaCocoa::addMouseMoveEvent(NSEvent* event) 
     
    146153                                           fromView:nil]; 
    147154   const NSPoint root_loc = [NSEvent mouseLocation]; 
    148    gadget::EventPtr move_event(new gadget::MouseEvent(gadget::MouseMoveEvent, 
    149                                                       gadget::NO_MBUTTON, 
    150                                                       view_loc.x, view_loc.y, 
    151                                                       root_loc.x, root_loc.y, 
    152                                                       [event modifierFlags], 
    153                                                       [event timestamp])); 
     155 
     156   // The Cocoa coordinate frame has the origin in the lower left-hand corner 
     157   // just as we ought to want for mouse events, but for some reason, the other 
     158   // windowing systems put the origin in the upper left-hand corner. Hence, 
     159   // we have to transform the coordinate frame to be in the upper left-hand 
     160   // corner to be portable. 
     161   gadget::EventPtr move_event( 
     162      new gadget::MouseEvent( 
     163         gadget::MouseMoveEvent, gadget::NO_MBUTTON, view_loc.x, 
     164         mHeight - view_loc.y, root_loc.x, 
     165         [[mCocoaWindow screen] frame].size.height - root_loc.y, 
     166         [event modifierFlags], [event timestamp] 
     167      ) 
     168   ); 
    154169 
    155170   const float cur_x = root_loc.x;