Line data Source code
1 0 : /*
2 :
3 : MyOpenGLView.h
4 :
5 : Oolite
6 : Copyright (C) 2004-2013 Giles C Williams and contributors
7 :
8 : This program is free software; you can redistribute it and/or
9 : modify it under the terms of the GNU General Public License
10 : as published by the Free Software Foundation; either version 2
11 : of the License, or (at your option) any later version.
12 :
13 : This program is distributed in the hope that it will be useful,
14 : but WITHOUT ANY WARRANTY; without even the implied warranty of
15 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 : GNU General Public License for more details.
17 :
18 : You should have received a copy of the GNU General Public License
19 : along with this program; if not, write to the Free Software
20 : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 : MA 02110-1301, USA.
22 :
23 : */
24 :
25 : #import "OOCocoa.h"
26 : #import "OOOpenGL.h"
27 : #import "OOMouseInteractionMode.h"
28 : #import "OOOpenGLMatrixManager.h"
29 :
30 :
31 0 : #define MAX_CLEAR_DEPTH 10000000000.0
32 : // 10 000 000 km.
33 0 : #define INTERMEDIATE_CLEAR_DEPTH 100.0
34 : // 100 m.
35 :
36 0 : #define MIN_FOV_DEG 30.0f
37 0 : #define MAX_FOV_DEG 80.0f
38 0 : #define MIN_FOV (tan((MIN_FOV_DEG / 2) * M_PI / 180.0f))
39 0 : #define MAX_FOV (tan((MAX_FOV_DEG / 2) * M_PI / 180.0f))
40 :
41 0 : #define NUM_KEYS 327
42 0 : #define MOUSE_DOUBLE_CLICK_INTERVAL 0.40
43 0 : #define OOMOUSEWHEEL_EVENTS_DELAY_INTERVAL 0.05
44 0 : #define OOMOUSEWHEEL_DELTA 1.0
45 :
46 : @class Entity, GameController;
47 :
48 0 : enum GameViewKeys
49 : {
50 :
51 : gvFunctionKey1 = 256,
52 : gvFunctionKey2,
53 : gvFunctionKey3,
54 : gvFunctionKey4,
55 : gvFunctionKey5, // 260
56 : gvFunctionKey6,
57 : gvFunctionKey7,
58 : gvFunctionKey8,
59 : gvFunctionKey9,
60 : gvFunctionKey10,
61 : gvFunctionKey11,
62 : gvArrowKeyRight,
63 : gvArrowKeyLeft,
64 : gvArrowKeyDown,
65 : gvArrowKeyUp, // 270
66 : gvPauseKey,
67 : gvPrintScreenKey, // 272
68 : gvMouseLeftButton = 301,
69 : gvMouseDoubleClick,
70 : gvHomeKey,
71 : gvEndKey,
72 : gvInsertKey,
73 : gvDeleteKey,
74 : gvPageUpKey,
75 : gvPageDownKey,
76 : gvBackspaceKey, // 309
77 : gvNumberKey0 = 48,
78 : gvNumberKey1,
79 : gvNumberKey2,
80 : gvNumberKey3,
81 : gvNumberKey4,
82 : gvNumberKey5,
83 : gvNumberKey6,
84 : gvNumberKey7,
85 : gvNumberKey8,
86 : gvNumberKey9, // 57
87 : gvNumberPadKey0 = 310,
88 : gvNumberPadKey1,
89 : gvNumberPadKey2,
90 : gvNumberPadKey3,
91 : gvNumberPadKey4,
92 : gvNumberPadKey5,
93 : gvNumberPadKey6,
94 : gvNumberPadKey7,
95 : gvNumberPadKey8,
96 : gvNumberPadKey9,
97 : gvNumberPadKeyDivide, // 320
98 : gvNumberPadKeyMultiply,
99 : gvNumberPadKeyMinus,
100 : gvNumberPadKeyPlus,
101 : gvNumberPadKeyPeriod,
102 : gvNumberPadKeyEquals,
103 : gvNumberPadKeyEnter // 326
104 : };
105 :
106 0 : enum MouseWheelStatus
107 : {
108 : gvMouseWheelDown = -1,
109 : gvMouseWheelNeutral,
110 : gvMouseWheelUp
111 : };
112 :
113 0 : enum StringInput
114 : {
115 : gvStringInputNo = 0,
116 : gvStringInputAlpha = 1,
117 : gvStringInputLoadSave = 2,
118 : gvStringInputAll = 3
119 : };
120 :
121 0 : extern int debug;
122 :
123 0 : @interface MyOpenGLView: NSOpenGLView
124 : {
125 : @private
126 0 : GameController *gameController;
127 :
128 0 : BOOL keys[NUM_KEYS];
129 0 : int scancode2Unicode[NUM_KEYS];
130 0 : NSDictionary *keyMappings_normal;
131 0 : NSDictionary *keyMappings_shifted;
132 :
133 0 : BOOL suppressKeys; // DJS
134 :
135 0 : BOOL opt, ctrl, command, shift, capsLockOn, lastKeyShifted;
136 0 : BOOL allowingStringInput;
137 0 : BOOL isAlphabetKeyDown;
138 0 : BOOL commandQ;
139 0 : BOOL commandF;
140 0 : BOOL f12;
141 :
142 0 : int keycodetrans[255];
143 :
144 0 : BOOL m_glContextInitialized;
145 :
146 0 : NSTimeInterval timeIntervalAtLastClick;
147 0 : NSTimeInterval timeIntervalAtLastMouseWheel;
148 0 : BOOL doubleClick;
149 :
150 0 : NSMutableString *typedString;
151 :
152 0 : NSPoint virtualJoystickPosition;
153 0 : float _mouseWheelDelta;
154 :
155 0 : NSSize viewSize;
156 0 : NSSize backingViewSize;
157 0 : GLfloat display_z;
158 0 : GLfloat x_offset, y_offset;
159 :
160 0 : float _fov;
161 :
162 0 : int _virtualScreen;
163 0 : NSData *_pixelFormatAttributes;
164 :
165 0 : OOOpenGLMatrixManager *matrixManager;
166 :
167 : }
168 :
169 :
170 0 : - (void) initKeyMappingData;
171 0 : - (void) setStringInput: (enum StringInput) value;
172 0 : - (void) allowStringInput: (BOOL) value;
173 0 : - (enum StringInput) allowingStringInput;
174 0 : - (NSString *) typedString;
175 0 : - (void) resetTypedString;
176 0 : - (void) setTypedString:(NSString*) value;
177 :
178 0 : - (NSSize) viewSize;
179 0 : - (NSSize) backingViewSize;
180 0 : - (GLfloat) display_z;
181 0 : - (GLfloat) x_offset;
182 0 : - (GLfloat) y_offset;
183 :
184 0 : - (GameController *) gameController;
185 0 : - (void) setGameController:(GameController *) controller;
186 :
187 0 : - (void) noteMouseInteractionModeChangedFrom:(OOMouseInteractionMode)oldMode to:(OOMouseInteractionMode)newMode;
188 :
189 0 : - (void) initialiseGLWithSize:(NSSize) v_size;
190 :
191 0 : - (NSData *)pixelFormatAttributes;
192 :
193 0 : - (void) drawRect:(NSRect)rect;
194 0 : - (void) updateScreen;
195 0 : - (void) pollControls;
196 :
197 0 : - (void) stringToClipboard:(NSString *)stringToCopy;
198 :
199 0 : - (BOOL) snapShot:(NSString *)filename;
200 :
201 0 : - (void)mouseDown:(NSEvent *)theEvent;
202 0 : - (void)mouseUp:(NSEvent *)theEvent;
203 0 : - (void)resetMouse;
204 :
205 0 : - (void) setVirtualJoystick:(double) vmx :(double) vmy;
206 0 : - (NSPoint) virtualJoystickPosition;
207 :
208 0 : - (void) clearKeys;
209 0 : - (void) clearMouse;
210 0 : - (void) clearKey: (int)theKey;
211 0 : - (BOOL) isAlphabetKeyDown;
212 0 : - (void) suppressKeysUntilKeyUp; // DJS
213 0 : - (BOOL) isDown: (int) key;
214 0 : - (BOOL) isOptDown;
215 0 : - (BOOL) isCtrlDown;
216 0 : - (BOOL) isCommandDown;
217 0 : - (BOOL) isShiftDown;
218 0 : - (BOOL) isCapsLockOn;
219 0 : - (BOOL) lastKeyWasShifted;
220 0 : - (int) numKeys;
221 0 : - (int) mouseWheelState;
222 0 : - (float) mouseWheelDelta;
223 0 : - (void) setMouseWheelDelta: (float) newWheelDelta;
224 :
225 : // Command-key combinations need special handling.
226 0 : - (BOOL) isCommandQDown;
227 0 : - (BOOL) isCommandFDown;
228 0 : - (void) clearCommandF;
229 :
230 : // Check current state of shift key rather than relying on last event.
231 0 : + (BOOL)pollShiftKey;
232 :
233 0 : - (OOOpenGLMatrixManager *) getOpenGLMatrixManager;
234 :
235 : #ifndef NDEBUG
236 : // General image-dumping methods.
237 0 : - (void) dumpRGBAToFileNamed:(NSString *)name
238 : bytes:(uint8_t *)bytes
239 : width:(NSUInteger)width
240 : height:(NSUInteger)height
241 : rowBytes:(NSUInteger)rowBytes;
242 :
243 0 : - (void) dumpRGBToFileNamed:(NSString *)name
244 : bytes:(uint8_t *)bytes
245 : width:(NSUInteger)width
246 : height:(NSUInteger)height
247 : rowBytes:(NSUInteger)rowBytes;
248 :
249 0 : - (void) dumpGrayToFileNamed:(NSString *)name
250 : bytes:(uint8_t *)bytes
251 : width:(NSUInteger)width
252 : height:(NSUInteger)height
253 : rowBytes:(NSUInteger)rowBytes;
254 :
255 0 : - (void) dumpGrayAlphaToFileNamed:(NSString *)name
256 : bytes:(uint8_t *)bytes
257 : width:(NSUInteger)width
258 : height:(NSUInteger)height
259 : rowBytes:(NSUInteger)rowBytes;
260 :
261 : // Split alpha into separate file.
262 0 : - (void) dumpRGBAToRGBFileNamed:(NSString *)rgbName
263 : andGrayFileNamed:(NSString *)grayName
264 : bytes:(uint8_t *)bytes
265 : width:(NSUInteger)width
266 : height:(NSUInteger)height
267 : rowBytes:(NSUInteger)rowBytes;
268 : #endif
269 :
270 : // no-ops to allow gamma value to be easily saved/restored
271 0 : - (void) setGammaValue: (float) value;
272 0 : - (float) gammaValue;
273 :
274 0 : - (void) setFov:(float)value fromFraction:(BOOL)fromFraction;
275 0 : - (float) fov:(BOOL)inFraction;
276 :
277 : @end
|