1/* 2 File: MBCBoardView.h 3 Contains: Displays and manipulates an OpenGL chess board 4 Copyright: � 2002-2012 by Apple Inc., all rights reserved. 5 6 IMPORTANT: This Apple software is supplied to you by Apple Computer, 7 Inc. ("Apple") in consideration of your agreement to the following 8 terms, and your use, installation, modification or redistribution of 9 this Apple software constitutes acceptance of these terms. If you do 10 not agree with these terms, please do not use, install, modify or 11 redistribute this Apple software. 12 13 In consideration of your agreement to abide by the following terms, 14 and subject to these terms, Apple grants you a personal, non-exclusive 15 license, under Apple's copyrights in this original Apple software (the 16 "Apple Software"), to use, reproduce, modify and redistribute the 17 Apple Software, with or without modifications, in source and/or binary 18 forms; provided that if you redistribute the Apple Software in its 19 entirety and without modifications, you must retain this notice and 20 the following text and disclaimers in all such redistributions of the 21 Apple Software. Neither the name, trademarks, service marks or logos 22 of Apple Inc. may be used to endorse or promote products 23 derived from the Apple Software without specific prior written 24 permission from Apple. Except as expressly stated in this notice, no 25 other rights or licenses, express or implied, are granted by Apple 26 herein, including but not limited to any patent rights that may be 27 infringed by your derivative works or by other works in which the 28 Apple Software may be incorporated. 29 30 The Apple Software is provided by Apple on an "AS IS" basis. APPLE 31 MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 32 THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND 33 FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS 34 USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 35 36 IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, 37 INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 38 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 39 PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, 40 REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, 41 HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING 42 NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN 43 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 44*/ 45 46#import "MBCBoard.h" 47#import <sys/time.h> 48 49struct MBCColor { 50 GLfloat color[4]; 51 52 operator GLfloat *() { return color; } 53 54 NSColor * GetColor() const; 55 void SetColor(NSColor * newColor); 56}; 57 58struct MBCPosition { 59 GLfloat pos[3]; 60 61 operator GLfloat *() { return pos; } 62 GLfloat & operator[](int i) { return pos[i]; } 63 GLfloat operator[](int i) const { return pos[i]; } 64 float FlatDistance(const MBCPosition & other) 65 { 66 return hypot(pos[0]-other[0], pos[2]-other[2]); 67 } 68}; 69 70MBCPosition operator-(const MBCPosition & a, const MBCPosition & b); 71 72extern MBCPieceCode gInHandOrder[]; 73const float kInHandPieceX = 51.0f; 74const float kInHandPieceZOffset = 3.0f; 75const float kInHandPieceSize = 8.0f; 76const float kPromotionPieceX = 50.0f; 77const float kPromotionPieceZ = 35.0f; 78const float kBoardRadius = 40.0f; 79const float kBorderWidth = 6.25f; 80const float kMinElevation = 10.0f; 81const float kMaxElevation = 80.0f; 82 83@class MBCInteractivePlayer; 84@class MBCDrawStyle; 85@class MBCBoardWin; 86 87@interface MBCBoardView : NSOpenGLView 88{ 89 MBCBoardWin * fController; 90 MBCInteractivePlayer *fInteractive; 91 MBCBoard * fBoard; 92 MBCSquare fPickedSquare; 93 MBCPiece fSelectedPiece; 94 MBCSquare fSelectedSquare; 95 MBCSquare fSelectedDest; 96 MBCPosition fSelectedPos; 97 MBCPosition fLastSelectedPos; 98 float fRawAzimuth; 99 NSPoint fOrigMouse; 100 NSPoint fCurMouse; 101 struct timeval fLastRedraw; 102@public 103 float fAzimuth; 104 float fElevation; 105 float fBoardReflectivity; 106 float fLabelIntensity; 107 float fAmbient; 108 MBCDrawStyle * fBoardDrawStyle[2]; 109 MBCDrawStyle * fPieceDrawStyle[2]; 110 MBCDrawStyle * fBorderDrawStyle; 111 MBCDrawStyle * fSelectedPieceDrawStyle; 112 GLfloat fLightPos[4]; 113@private 114 GLuint fNumberTextures[8]; 115 GLuint fLetterTextures[8]; 116 int fMaxFSAA; 117 int fCurFSAA; 118 int fLastFSAASize; 119 bool fNeedStaticModels; 120 bool fIsPickingFormat; 121 bool fIsFloating; 122 bool fWantMouse; 123 bool fNeedPerspective; 124 bool fInAnimation; 125 bool fInBoardManipulation; 126 MBCVariant fVariant; 127 MBCSide fSide; 128 MBCSide fPromotionSide; 129 NSDictionary * fBoardAttr; 130 NSDictionary * fPieceAttr; 131 NSString * fBoardStyle; 132 NSString * fPieceStyle; 133 MBCMove * fHintMove; 134 MBCMove * fLastMove; 135 NSCursor * fHandCursor; 136 NSCursor * fArrowCursor; 137 MBCPiece fLastPieceDrawn; 138 char fKeyBuffer; 139 float fAnisotropy; 140 GLint fNumSamples; 141 NSTrackingArea * fTrackingArea; 142} 143 144// 145// Basic view routines 146// 147- (id) initWithFrame:(NSRect)rect; 148- (void) awakeFromNib; 149- (void) drawRect:(NSRect)rect; 150 151- (void) startGame:(MBCVariant)variant playing:(MBCSide) side; 152- (void) drawNow; // Redraw immediately 153- (void) profileDraw; // Redraw in a tight loop 154- (void) needsUpdate; // Perspective changed 155- (void) endGame; // Clean up the previous game 156- (void) startAnimation; // Start animation 157- (void) animationDone; // Animation finished 158 159// 160// Fall back to less memory hungry graphics format 161// 162- (void) pickPixelFormat:(BOOL)afterFailure; 163 164// 165// Change textures 166// 167- (void) setStyleForBoard:(NSString *)boardStyle pieces:(NSString *)pieceStyle; 168 169// 170// Selection manipulation 171// 172- (void) selectPiece:(MBCPiece)piece at:(MBCSquare)square; 173- (void) selectPiece:(MBCPiece)piece at:(MBCSquare)square to:(MBCSquare)dest; 174- (void) moveSelectionTo:(MBCPosition *)position; 175- (void) unselectPiece; 176- (void) clickPiece; 177 178// 179// Show hints and last moves 180// 181- (void) showMoveAsHint:(MBCMove *)move; 182- (void) showMoveAsLast:(MBCMove *)move; 183- (void) hideMoves; 184 185// 186// Translate between squares and positions 187// 188- (MBCSquare) positionToSquare:(const MBCPosition *)position; 189- (MBCSquare) positionToSquareOrRegion:(const MBCPosition *)position; 190- (MBCPosition) squareToPosition:(MBCSquare)square; 191- (void) snapToSquare:(MBCPosition *)position; 192- (MBCSide) facing; // What player are we facing? 193- (BOOL) facingWhite; // Are we facing white? 194 195// 196// Pass mouse clicks on to interactive player? 197// 198- (void) wantMouse:(BOOL)wantIt; 199 200@end 201 202// Local Variables: 203// mode:ObjC 204// End: 205