1 // 2 // MapGridView.h 3 // avida/apps/viewer-macos 4 // 5 // Created by David on 11/23/10. 6 // Copyright 2010-2011 Michigan State University. All rights reserved. 7 // http://avida.devosoft.org/viewer-macos 8 // 9 // Redistribution and use in source and binary forms, with or without modification, are permitted provided that the 10 // following conditions are met: 11 // 12 // 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the 13 // following disclaimer. 14 // 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the 15 // following disclaimer in the documentation and/or other materials provided with the distribution. 16 // 3. Neither the name of Michigan State University, nor the names of contributors may be used to endorse or promote 17 // products derived from this software without specific prior written permission. 18 // 19 // THIS SOFTWARE IS PROVIDED BY MICHIGAN STATE UNIVERSITY AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 // DISCLAIMED. IN NO EVENT SHALL MICHIGAN STATE UNIVERSITY OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 25 // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // 27 // Authors: David M. Bryson <david@programerror.com> 28 // 29 30 #import <Cocoa/Cocoa.h> 31 32 #include "apto/core.h" 33 34 namespace Avida { 35 namespace CoreView { 36 class Map; 37 }; 38 }; 39 40 @class MapGridView; 41 42 @protocol MapSelectionDelegate <NSObject> 43 @optional 44 - (BOOL) mapView:(MapGridView*)mapView shouldSelectObjectAtPoint:(NSPoint)point; 45 - (void) mapViewSelectionChanged:(MapGridView*)mapView; 46 @end 47 48 49 @interface MapGridView : NSView { 50 int map_width; 51 int map_height; 52 int num_colors; 53 double zoom; 54 55 Apto::Array<int> map_colors; 56 Apto::Array<int> map_tags; 57 NSMutableArray* color_cache; 58 59 IBOutlet id<MapSelectionDelegate> selectionDelegate; 60 int selected_x; 61 int selected_y; 62 } 63 64 - (id) initWithFrame:(NSRect)frame; 65 - (void) awakeFromNib; 66 67 - (void) drawRect:(NSRect)rect; 68 - (BOOL) isOpaque; 69 70 - (void) updateState:(Avida::CoreView::Map*)state; 71 72 - (void) mouseDown:(NSEvent*)event; 73 74 - (NSColor*) colorOfX:(int)x Y:(int)y; 75 76 @property (readwrite, nonatomic) double zoom; 77 @property (readwrite, retain) id<MapSelectionDelegate> selectionDelegate; 78 79 @property (readwrite, nonatomic) NSPoint selectedObject; 80 - (void) clearSelectedObject; 81 82 @end 83