Views/MapView.m

00001 //
00002 //  MapView.m
00003 //  MacTrek
00004 //
00005 //  Created by Aqua on 02/06/2006.
00006 //  Copyright 2006 Luky Soft. All rights reserved.
00007 //
00008 
00009 #import "MapView.h"
00010 
00011 
00012 @implementation MapView
00013 
00014 NSRect gameBounds;
00015 
00016 - (void) awakeFromNib {
00017     [super awakeFromNib];
00018     
00019     // use larger steps to zoom
00020     step *= 2; // twice
00021     
00022     [self setScaleFullView];
00023     // should disable torps etc
00024     
00025     // find out what are the gameBounds
00026     gameBounds.origin.x = 0;
00027     gameBounds.origin.y = 0;
00028     gameBounds.size.width = UNIVERSE_PIXEL_SIZE;
00029     gameBounds.size.height = UNIVERSE_PIXEL_SIZE;
00030 
00031     centerPoint = NSMakePoint(UNIVERSE_PIXEL_SIZE/2, UNIVERSE_PIXEL_SIZE/2);
00032     
00033     // use the default painter here, we could use the same theme....
00034     // $$ are we sure?
00035     painter = [[PainterFactory alloc] init];
00036     
00037     // use simpler drawing (eg omit weapons)
00038     [painter setSimplifyDrawing:YES];
00039 }
00040 
00041 - (NSPoint) gamePointRepresentingCentreOfView {
00042     return centerPoint;
00043 }
00044 
00045 - (void) keyDown:(NSEvent *)theEvent {
00046     NSLog(@"MapView.keyDown entered");
00047     [super keyDown:theEvent];
00048 }
00049 
00050 // draw the view 
00051 // without locking the read thread !!
00052 - (void)drawRect:(NSRect)aRect {
00053     [painter drawRect:aRect ofViewBounds:[self bounds] whichRepresentsGameBounds:gameBounds withScale:scale];
00054 }
00055 
00056 - (void) mouseDown:(NSEvent *)theEvent {
00057     // where you click becomes the center
00058     centerPoint = [painter gamePointFromViewPoint:[self mousePos] 
00059                                              viewRect:[self bounds]
00060                                 gamePosInCentreOfView:[self gamePointRepresentingCentreOfView] 
00061                                             withScale:scale]; 
00062     
00063     // set up the gamebounds based on my position
00064     gameBounds = [painter gameRectAround:[self gamePointRepresentingCentreOfView]
00065                                         forView:[self bounds]
00066                                       withScale:scale]; 
00067 }
00068 
00069 - (void) scrollWheel:(NSEvent *)theEvent {
00070 
00071     [super scrollWheel:theEvent];
00072     // set up the gamebounds based on my position AND SCALE
00073     gameBounds = [painter gameRectAround:[self gamePointRepresentingCentreOfView]
00074                                  forView:[self bounds]
00075                                withScale:scale]; 
00076 }
00077 
00078 
00079 - (void) otherMouseDown:(NSEvent *)theEvent {
00080     // no phaser
00081 }
00082 
00083 @end

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