Generic/BaseView.m

00001 //
00002 //  BaseView.m
00003 //  MacTrek
00004 //
00005 //  Created by Aqua on 24/07/2006.
00006 //  Copyright 2006 Luky Soft. All rights reserved.
00007 //
00008 
00009 #import "BaseView.h"
00010 
00011 
00012 @implementation BaseView
00013 
00014 - (void) awakeFromNib {
00015     
00016     notificationCenter = [LLNotificationCenter defaultCenter];
00017     universe = [Universe defaultInstance];
00018 }
00019 
00020 // view and window exist, add rects
00021 - (void) viewDidMoveToWindow {
00022     
00023     // add a tracking rectangle so we get mouseEnter and mouseExit events
00024     bool mouseInView = NSPointInRect([self mousePos], [self bounds]);
00025     [self addTrackingRect:[self bounds] owner:self userData:nil assumeInside:mouseInView];
00026     if (mouseInView) { // fire inital event
00027         [self mouseEntered:nil];
00028     }
00029 }
00030 
00031 // default behaviour = focus follows mouse
00032 - (void) mouseEntered:(NSEvent*)evt {
00033     NSLog(@"BaseView.mouseEntered making myself first responder");
00034     [[self window] makeFirstResponder:self];
00035     [[NSCursor crosshairCursor] push];
00036 }
00037 
00038 - (void) mouseExited:(NSEvent*)evt {
00039     NSLog(@"BaseView.mouseExited resigning myself as first responder");
00040     [[self window] resignFirstResponder];
00041     [[NSCursor crosshairCursor] pop];
00042 }
00043 
00044 - (NSPoint) mousePos {
00045     // get mouse point in window
00046     NSPoint mouseBase = [[self window] mouseLocationOutsideOfEventStream];
00047     
00048     // convert to GameView coordinates
00049     NSPoint mouseLocation = [self convertPoint:mouseBase fromView:nil];
00050     
00051     return mouseLocation;
00052 }
00053 
00054 - (bool) acceptsFirstMouse {
00055     return YES; // $$ check...
00056 }
00057 
00058 - (bool) opaque{
00059     return YES; // speed bump
00060 }
00061 
00062 // old X11 calls were flipped
00063 - (bool) isFlipped {
00064     return YES;
00065 }
00066 
00067 
00068 // i will accept key and mouse input
00069 - (bool) acceptsFirstResponder {
00070     return YES;
00071 }
00072 
00073 // and i will accept it now
00074 - (bool) becomeFirstResponder {
00075     [self setNeedsDisplay:YES];
00076     /* not needed, done by trackingRect and mouseEnter
00077     if([[self window] makeFirstResponder:self]) { // make this view first responder
00078         NSLog(@"BaseView.becomeFirstResponder OK");
00079     } else {
00080         NSLog(@"BaseView.becomeFirstResponder failed");
00081     }
00082      */ 
00083     return YES; // always accept
00084 }
00085 
00086 - (bool) resignFirstResponder {
00087     [self setNeedsDisplay:YES];
00088     return [super resignFirstResponder];
00089 }
00090 
00091 
00092 @end

Generated on Sat Aug 26 21:14:15 2006 for MacTrek by  doxygen 1.4.7