Oolite
Loading...
Searching...
No Matches
MyOpenGLView Class Reference

#include <MyOpenGLView.h>

Inheritance diagram for MyOpenGLView:
Collaboration diagram for MyOpenGLView:

Instance Methods

(id) - init
(NSString *) - getWindowCaption
(void) - createWindowWithSize:
(void) - initSplashScreen
(void) - endSplashScreen
(NSSize) - viewSize
(NSSize) - backingViewSize
(GLfloat) - display_z
(GLfloat) - x_offset
(GLfloat) - y_offset
(GameController *) - gameController
(void) - setGameController:
(void) - initialiseGLWithSize:
(void) - updateGLSize:
(BOOL) - isRunningOnPrimaryDisplayDevice
(void) - getDisplayDimensions:height:
(OOSDRToneMapper) - sdrToneMapper
(void) - setSDRToneMapper:
(float) - colorSaturation
(void) - adjustColorSaturation:
(BOOL) - hdrOutput
(BOOL) - isOutputDisplayHDREnabled
(void) - grabMouseInsideGameWindow:
(void) - stringToClipboard:
(void) - updateScreen
(BOOL) - snapShot:
(SDL_DisplayID) - getDisplayId
(NSMutableDictionary *) - getNativeSize
(void) - setFullScreenMode:
(BOOL) - inFullScreenMode
(void) - toggleScreenMode
(void) - setDisplayMode:fullScreen:
(void) - setScreenSize:
(NSMutableArray *) - getScreenSizeArray
(void) - populateFullScreenModelist
(NSSize) - modeAsSize:
(void) - saveWindowSize:
(NSSize) - loadWindowSize
(int) - loadFullscreenSettings
(int) - findDisplayModeForWidth:Height:Refresh:
(NSSize) - currentScreenSize
(NSDictionary *) - currentScreenMode
(void) - setFov:fromFraction:
(float) - fov:
(void) - setMsaa:
(BOOL) - msaa
(OOOpenGLMatrixManager *) - getOpenGLMatrixManager
(void) - dumpRGBAToFileNamed:bytes:width:height:rowBytes:
(void) - dumpRGBToFileNamed:bytes:width:height:rowBytes:
(void) - dumpGrayToFileNamed:bytes:width:height:rowBytes:
(void) - dumpGrayAlphaToFileNamed:bytes:width:height:rowBytes:
(void) - dumpRGBAToRGBFileNamed:andGrayFileNamed:bytes:width:height:rowBytes:
(void) - setUpBasicOpenGLStateWithSize [implementation]
(void) - dealloc [implementation]
(void) - autoShowMouse
(void) - initKeyMappingData
(void) - setStringInput:
(void) - allowStringInput:
(void) - resetTypedString
(void) - setTypedString:
(void) - noteMouseInteractionModeChangedFrom:to:
(void) - pollControls
(void) - setVirtualJoystick:vmy:
(void) - clearKeys
(void) - clearMouse
(void) - clearKey:
(void) - resetMouse
(void) - suppressKeysUntilKeyUp
(BOOL) - isDown:
(BOOL) - isOptDown
(BOOL) - isCtrlDown
(BOOL) - isCommandDown
(BOOL) - isShiftDown
(BOOL) - isCapsLockOn
(BOOL) - lastKeyWasShifted
(int) - numKeys
(int) - mouseWheelState
(float) - mouseWheelDelta
(void) - setMouseWheelDelta:
(BOOL) - isCommandQDown
(BOOL) - isCommandFDown
(void) - clearCommandF
(void) - setMouseInDeltaMode:
(void) - handleStringInput:keyID:
(BOOL) - isCommandModifierKeyDown [implementation]

Class Methods

(BOOL) + pollShiftKey

Protected Attributes

GameController * gameController
BOOL keys [NUM_KEYS]
int scancode2Unicode [NUM_KEYS]
NSDictionary * keyMappings_normal
NSDictionary * keyMappings_shifted
BOOL suppressKeys
BOOL opt
BOOL ctrl
BOOL command
BOOL shift
BOOL lastKeyShifted
enum StringInput allowingStringInput
BOOL isAlphabetKeyDown
int keycodetrans [255]
NSPoint mouseDragStartPoint
BOOL mouseWarped
NSTimeInterval timeIntervalAtLastClick
NSTimeInterval timeSinceLastMouseWheel
BOOL doubleClick
NSMutableString * typedString
NSPoint virtualJoystickPosition
float _mouseVirtualStickSensitivityFactor
NSSize viewSize
GLfloat display_z
GLfloat x_offset
GLfloat y_offset
double squareX
double squareY
NSRect bounds
float _fov
BOOL _msaa
NSMutableArray * screenSizes
int currentSize
BOOL fullScreen
NSSize currentWindowSize
BOOL showSplashScreen
SDL_Window * window
SDL_GLContext glContext
int bitsPerColorComponent
BOOL vSyncPreference
int _sdrToneMapper
float _colorSaturation
BOOL _hdrOutput
BOOL grabMouseStatus
NSSize firstScreen
OOOpenGLMatrixManager * matrixManager
BOOL mouseInDeltaMode
float _mouseWheelDelta

Detailed Description

Definition at line 164 of file MyOpenGLView.h.

Method Documentation

◆ adjustColorSaturation:

- (void) adjustColorSaturation: (float) colorSaturationAdjustment

Definition at line 1008 of file MyOpenGLView.m.

1008 :(float)colorSaturationAdjustment;
1009{
1010 _colorSaturation += colorSaturationAdjustment;
1012}
#define MAX_COLOR_SATURATION
OOINLINE float OOClamp_0_max_f(float value, float max) INLINE_CONST_FUNC
float _colorSaturation

References _colorSaturation, MAX_COLOR_SATURATION, and OOClamp_0_max_f().

Referenced by PlayerEntity(OOPrivate)::gameOverFadeToBW, OoliteSetProperty(), and OoliteSetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ allowStringInput:

- (void) allowStringInput: (BOOL) value

Provided by category MyOpenGLView(Input).

Definition at line 63 of file MyOpenGLView+Input.m.

63 :(BOOL)value
64{
65 if (value)
67 else
69}
@ gvStringInputAlpha
@ gvStringInputNo
enum StringInput allowingStringInput

Referenced by PlayerEntity(OOControlsPrivate)::pollApplicationControls, PlayerEntity(OOControlsPrivate)::pollDemoControls:, PlayerEntity(OOControlsPrivate)::pollDockedControls:, PlayerEntity(OOControlsPrivate)::pollFlightControls:, PlayerEntity(OOControlsPrivate)::pollGuiArrowKeyControls:, and PlayerEntity(Controls)::switchToMainView.

Here is the caller graph for this function:

◆ autoShowMouse

- (void) autoShowMouse

Provided by category MyOpenGLView(Input).

Definition at line 48 of file MyOpenGLView+Input.m.

49{
50 // don't touch the 'please wait...' cursor.
51 if (fullScreen) {
52 if (SDL_CursorVisible())
53 SDL_HideCursor();
54 } else {
55 if (!SDL_CursorVisible())
56 SDL_ShowCursor();
57 }
58}

Referenced by endSplashScreen, init, initialiseGLWithSize:, and MyOpenGLView(Input)::noteMouseInteractionModeChangedFrom:to:.

Here is the caller graph for this function:

◆ backingViewSize

- (NSSize) backingViewSize

Definition at line 642 of file MyOpenGLView.m.

643{
644 return bounds.size;
645}

References backingViewSize, and bounds.

Referenced by backingViewSize, Universe::drawUniverse, Universe::gameSettings, Universe::initWithGameView:, and viewSize.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clearCommandF

- (void) clearCommandF

Provided by category MyOpenGLView(Input).

Definition at line 221 of file MyOpenGLView+Input.m.

222{
223 // SDL stub for the mac function.
224}

Referenced by PlayerEntity(OOControlsPrivate)::pollApplicationControls.

Here is the caller graph for this function:

◆ clearKey:

- (void) clearKey: (int) theKey

Provided by category MyOpenGLView(Input).

Definition at line 115 of file MyOpenGLView+Input.m.

115 :(int)theKey
116{
117 if (theKey >= 0 && theKey < [self numKeys]) {
118 keys[theKey] = NO;
119 }
120}
BOOL keys[NUM_KEYS]
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque

Referenced by PlayerEntity(OOControlsPrivate)::pollFlightControls:.

Here is the caller graph for this function:

◆ clearKeys

◆ clearMouse

◆ colorSaturation

- (float) colorSaturation

Definition at line 1003 of file MyOpenGLView.m.

1004{
1005 return _colorSaturation;
1006}

References _colorSaturation, and colorSaturation.

Referenced by colorSaturation, gameController, PlayerEntity(OOPrivate)::gameOverFadeToBW, OoliteSetProperty(), and OoliteSetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createWindowWithSize:

- (void) createWindowWithSize: (NSSize) size

Definition at line 106 of file MyOpenGLView.m.

106 :(NSSize)size
107{
108 NSUserDefaults* prefs = [NSUserDefaults standardUserDefaults];
109
110 OOLog(@"display.initGL", @"Trying %d-bpcc, 24-bit depth buffer", bitsPerColorComponent);
111 if (bitsPerColorComponent > 8) {
112 SDL_GL_SetAttribute(SDL_GL_FLOATBUFFERS, 1);
113 _hdrOutput = YES;
114 } else {
115 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, bitsPerColorComponent);
116 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, bitsPerColorComponent);
117 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, bitsPerColorComponent);
118 SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, bitsPerColorComponent);
119 _hdrOutput = NO;
120 }
121 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
122 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
123
124 /* Multisampling significantly improves graphics quality with
125 * basically no extra programming effort on our part, especially
126 * for curved surfaces like the planet, but is also expensive - in
127 * the worst case the entire scene must be rendered four
128 * times. For now it can be a hidden setting. If early testing
129 * doesn't give any problems (other than speed on low-end graphics
130 * cards) a game options entry might be useful. - CIM, 24 Aug 2013*/
131
132 if ([prefs oo_boolForKey:@"anti-aliasing" defaultValue:NO]) {
133 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
134 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);
135 }
136
137 NSString* windowCaption = [self getWindowCaption];
138 Uint32 windowFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS | SDL_WINDOW_HIGH_PIXEL_DENSITY;
139 if (glContext) {
140 // Game window replacing the splash window: create it hidden with its final
141 // decorations so it is mapped only once (see endSplashScreen).
142 windowFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN | SDL_WINDOW_HIGH_PIXEL_DENSITY;
143 }
144
145 // Define modern SDL3 properties for window configuration
146 SDL_PropertiesID props = SDL_CreateProperties();
147 SDL_SetStringProperty(props, SDL_PROP_WINDOW_CREATE_TITLE_STRING, [windowCaption UTF8String]);
148 SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_WIDTH_NUMBER, size.width);
149 SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_HEIGHT_NUMBER, size.height);
150 SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_FLAGS_NUMBER, windowFlags);
151
152 // Explicit centering properties setup for SDL3
153 SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_X_NUMBER, SDL_WINDOWPOS_CENTERED);
154 SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_Y_NUMBER, SDL_WINDOWPOS_CENTERED);
155
156 window = SDL_CreateWindowWithProperties(props);
157 if (!window) {
158 OOLog(@"display.initGL", @"%@", @"Trying 8-bpcc, 24-bit depth buffer");
159 SDL_GL_SetAttribute(SDL_GL_FLOATBUFFERS, 0);
160 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
161 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
162 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
163 SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
164 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
165 window = SDL_CreateWindowWithProperties(props);
166 _hdrOutput = NO;
167 }
168
169 if (!window) {
170 OOLog(@"display.initGL", @"%@", @"Trying 5-bpcc, 16-bit depth buffer");
171 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
172 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
173 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
174 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
175 // and if it's this bad, forget even trying to multisample!
176 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
177 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
178 window = SDL_CreateWindowWithProperties(props);
179 }
180
181 // Clean up properties block
182 SDL_DestroyProperties(props);
183
184 if (!window) {
185 const char* errStr = SDL_GetError();
186 OOLogERR(@"display.mode.error", @"Could not create window: %s", errStr);
187 exit(1);
188 }
189 if (glContext) {
190 // Keep the splash screen's context (and its textures); the GL attributes are unchanged,
191 // so the new window's pixel format matches.
192 if (!SDL_GL_MakeCurrent(window, glContext)) {
193 OOLog(@"sdl.create_context", @"Could not make OpenGL context current: %s", SDL_GetError());
194 exit(1);
195 }
196 } else {
197 glContext = SDL_GL_CreateContext(window);
198 }
199 if (!glContext) {
200 OOLog(@"sdl.create_context", @"%@", @"Could not create OpenGL context");
201 exit(1);
202 }
203#if !OOLITE_MAC_OS_X
204 // On macOS a window surface replaces the OpenGL drawable, so it must not be created there.
205 SDL_Surface* surface = SDL_GetWindowSurface(window);
206 if (!SDL_SetSurfaceColorspace(surface, SDL_COLORSPACE_SRGB_LINEAR)) {
207 OOLogWARN(@"sdl.use_edr_surface", @"%@ %s", @"Failed to set SDR linear surface - falling back to SDR. Error was:", SDL_GetError());
208 SDL_SetSurfaceColorspace(surface, SDL_COLORSPACE_SRGB);
209 }
210#endif
211 // Every window shares the single glContext, which owns Universe's GL objects (VAOs, FBOs,
212 // shaders). SDL_GetWindowSurface() may create an internal GL renderer context for the window
213 // and leave it current, so make glContext current again before any GL call.
214 if (!SDL_GL_MakeCurrent(window, glContext)) {
215 OOLog(@"sdl.create_context", @"Could not make OpenGL context current: %s", SDL_GetError());
216 exit(1);
217 }
218
219#if OOLITE_WINDOWS
220 // capture the window handle for later (only needed for ugly hack later when transitioning between
221 // full screen and window). Don't use anywhere else.
222 SDL_PropertiesID windowPropertiesId = SDL_GetWindowProperties(window);
223 windowHandle = SDL_GetPointerProperty(windowPropertiesId, SDL_PROP_WINDOW_WIN32_HWND_POINTER, NULL);
224 if (!windowHandle) {
225 OOLog(@"sdl.window_handle", @"%@", @"Failed to retrieve window handle");
226 exit(1);
227 }
228
229 atDesktopResolution = YES;
230
231#endif // OOLITE_WINDOWS
232
233#if !OOLITE_MAC_OS_X
234 // On macOS SDL would set this 32x32 image as the Dock icon, replacing the bundle's
235 // high-resolution oolite-icon.icns.
236 NSString* imagesDir = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Images"];
237 SDL_Surface* icon = SDL_LoadBMP([[imagesDir stringByAppendingPathComponent:@"WMicon.bmp"] UTF8String]);
238
239 if (icon != NULL) {
240 const SDL_PixelFormatDetails* pixelFormat = SDL_GetPixelFormatDetails(icon->format);
241 const SDL_Palette* palette = SDL_GetSurfacePalette(icon);
242 Uint32 colorkey = SDL_MapRGB(pixelFormat, palette, 128, 0, 128);
243 SDL_SetSurfaceColorKey(icon, YES, colorkey);
244 SDL_SetWindowIcon(window, icon);
245 }
246 SDL_DestroySurface(icon);
247#endif
248
249 _colorSaturation = 1.0f;
250
251#if OOLITE_WINDOWS
252 _hdrMaxBrightness = [prefs oo_floatForKey:@"hdr-max-brightness" defaultValue:1000.0f];
253 _hdrPaperWhiteBrightness = [prefs oo_floatForKey:@"hdr-paperwhite-brightness" defaultValue:200.0f];
254 _hdrToneMapper = OOHDRToneMapperFromString([prefs oo_stringForKey:@"hdr-tone-mapper" defaultValue:@"OOHDR_TONEMAPPER_ACES_APPROX"]);
255#endif
256
257 _sdrToneMapper = OOSDRToneMapperFromString([prefs oo_stringForKey:@"sdr-tone-mapper" defaultValue:@"OOSDR_TONEMAPPER_ACES"]);
258
259#if OOLITE_MAC_OS_X
260 SDL_GL_SetSwapInterval(vSyncPreference ? 1 : 0);
261#else
262 SDL_SetWindowSurfaceVSync(window, vSyncPreference);
263#endif
264 OOLog(@"display.initGL", @"V-Sync %@requested.", vSyncPreference ? @"" : @"not ");
265
266 int testAttrib = -1;
267 OOLog(@"display.initGL", @"%@", @"Achieved color / depth buffer sizes (bits):");
268 SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &testAttrib);
269 OOLog(@"display.initGL", @"Red: %d", testAttrib);
270 SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &testAttrib);
271 OOLog(@"display.initGL", @"Green: %d", testAttrib);
272 SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &testAttrib);
273 OOLog(@"display.initGL", @"Blue: %d", testAttrib);
274 SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE, &testAttrib);
275 OOLog(@"display.initGL", @"Alpha: %d", testAttrib);
276 SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &testAttrib);
277 OOLog(@"display.initGL", @"Depth Buffer: %d", testAttrib);
278
279 SDL_GL_GetAttribute(SDL_GL_FLOATBUFFERS, &testAttrib);
280 OOLog(@"display.initGL", @"Pixel type is float : %d", testAttrib);
281
282 SDL_PixelFormat format = SDL_GetWindowPixelFormat(window);
283 OOLog(@"display.initGL", @"Window Pixel Format: %s", SDL_GetPixelFormatName(format));
284
285 // Verify V-sync successfully set - report it if not
286
287 int hasVsync;
288#if OOLITE_MAC_OS_X
289 if (vSyncPreference && (!SDL_GL_GetSwapInterval(&hasVsync) || !hasVsync)) {
290#else
291 if (vSyncPreference && (!SDL_GetWindowSurfaceVSync(window, &hasVsync) || !hasVsync)) {
292#endif
293 OOLogWARN(@"display.initGL", @"Could not enable V-Sync. Please check that your graphics driver supports the %@_swap_control extension.",
294 OOLITE_WINDOWS ? @"WGL_EXT" : @"[GLX_SGI/GLX_MESA]");
295 } else {
296 OOLog(@"display.initGL", @"%@", @"V-Sync set");
297 }
298
299 int width, height;
300 SDL_GetWindowSizeInPixels(window, &width, &height);
301 bounds.size.width = width;
302 bounds.size.height = height;
303
304 return;
305}
OOSDRToneMapper OOSDRToneMapperFromString(NSString *string)
OOHDRToneMapper OOHDRToneMapperFromString(NSString *string)
#define OOLITE_WINDOWS
#define OOLogWARN(class, format,...)
Definition OOLogging.h:126
#define OOLogERR(class, format,...)
Definition OOLogging.h:125
#define OOLog(class, format,...)
Definition OOLogging.h:84
int bitsPerColorComponent
SDL_Window * window
SDL_GLContext glContext
voidpf void uLong size
Definition ioapi.h:126

References _colorSaturation, _hdrOutput, _sdrToneMapper, bitsPerColorComponent, bounds, getWindowCaption, glContext, OOHDRToneMapperFromString(), OOLITE_WINDOWS, OOLog, OOLogERR, OOLogWARN, OOSDRToneMapperFromString(), vSyncPreference, and window.

Referenced by endSplashScreen, initialiseGLWithSize:, and initSplashScreen.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ currentScreenMode

- (NSDictionary *) currentScreenMode

Definition at line 1276 of file MyOpenGLView.m.

1277{
1278 NSDictionary* mode = [screenSizes objectAtIndex:currentSize];
1279 return [[mode retain] autorelease];
1280}
const char int mode
Definition ioapi.h:125

References currentScreenMode.

Referenced by currentScreenMode, and modeAsSize:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ currentScreenSize

- (NSSize) currentScreenSize

Definition at line 1264 of file MyOpenGLView.m.

1265{
1266 NSDictionary* mode = [screenSizes objectAtIndex:currentSize];
1267
1268 if (mode) {
1269 return NSMakeSize([[mode objectForKey:kOODisplayWidth] intValue],
1270 [[mode objectForKey:kOODisplayHeight] intValue]);
1271 }
1272 OOLog(@"display.mode.unknown", @"%@", @"Screen size unknown!");
1274}
#define WINDOW_SIZE_DEFAULT_HEIGHT
#define WINDOW_SIZE_DEFAULT_WIDTH
#define kOODisplayHeight
#define kOODisplayWidth

References currentScreenSize, kOODisplayHeight, kOODisplayWidth, OOLog, WINDOW_SIZE_DEFAULT_HEIGHT, and WINDOW_SIZE_DEFAULT_WIDTH.

Referenced by currentScreenSize, and modeAsSize:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dealloc

- (void) dealloc
implementation

Definition at line 601 of file MyOpenGLView.m.

602{
603 if (typedString)
604 [typedString release];
605
606 if (screenSizes)
607 [screenSizes release];
608
609 if (window) {
610 SDL_DestroyWindow(window);
611 }
612
613 if (glContext) {
614 SDL_GL_DestroyContext(glContext);
615 }
616
618 [keyMappings_normal release];
619
621 [keyMappings_shifted release];
622
623 SDL_Quit();
624
625 if (matrixManager) {
626 [matrixManager release];
627 }
628
629 [super dealloc];
630}
NSDictionary * keyMappings_shifted
NSMutableString * typedString
NSMutableArray * screenSizes
OOOpenGLMatrixManager * matrixManager
NSDictionary * keyMappings_normal

References dealloc, glContext, keyMappings_normal, keyMappings_shifted, matrixManager, screenSizes, typedString, and window.

Referenced by dealloc, and init.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ display_z

- (GLfloat) display_z

References display_z.

◆ dumpGrayAlphaToFileNamed:bytes:width:height:rowBytes:

- (void) dumpGrayAlphaToFileNamed: (NSString*) name
bytes: (uint8_t*) bytes
width: (NSUInteger) width
height: (NSUInteger) height
rowBytes: (NSUInteger) rowBytes 

Definition at line 1383 of file MyOpenGLView.m.

1383 :(NSString*)name
1384 bytes:(uint8_t*)bytes
1385 width:(NSUInteger)width
1386 height:(NSUInteger)height
1387 rowBytes:(NSUInteger)rowBytes
1388{
1389 if (name == nil || bytes == NULL || width == 0 || height == 0 || rowBytes < width * 2)
1390 return;
1391
1392 // use the snapshots directory
1393 NSString* dumpFile = [[NSHomeDirectory() stringByAppendingPathComponent:@SAVEDIR] stringByAppendingPathComponent:@SNAPSHOTDIR];
1394 dumpFile = [dumpFile stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", name]];
1395
1396 SDL_Surface* tmpSurface = SDL_CreateSurfaceFrom(width, height, SDL_PIXELFORMAT_RGBA32, bytes, rowBytes);
1397 for (int y = 0; y < height; y++) {
1398 uint8_t* srcRow = bytes + rowBytes * y;
1399 uint8_t* dstRow = (uint8_t*)tmpSurface->pixels + y * tmpSurface->pitch;
1400 for (int x = 0; x < width; x++) {
1401 dstRow[4 * x + 0] = srcRow[2 * x];
1402 dstRow[4 * x + 1] = srcRow[2 * x];
1403 dstRow[4 * x + 2] = srcRow[2 * x];
1404 dstRow[4 * x + 3] = srcRow[2 * x + 1];
1405 }
1406 }
1407 SDL_SavePNG(tmpSurface, [dumpFile UTF8String]);
1408 SDL_DestroySurface(tmpSurface);
1409}
return nil
float y
float x

References nil, x, and y.

Referenced by OODumpPixMap().

Here is the caller graph for this function:

◆ dumpGrayToFileNamed:bytes:width:height:rowBytes:

- (void) dumpGrayToFileNamed: (NSString*) name
bytes: (uint8_t*) bytes
width: (NSUInteger) width
height: (NSUInteger) height
rowBytes: (NSUInteger) rowBytes 

Definition at line 1355 of file MyOpenGLView.m.

1355 :(NSString*)name
1356 bytes:(uint8_t*)bytes
1357 width:(NSUInteger)width
1358 height:(NSUInteger)height
1359 rowBytes:(NSUInteger)rowBytes
1360{
1361 if (name == nil || bytes == NULL || width == 0 || height == 0 || rowBytes < width)
1362 return;
1363
1364 // use the snapshots directory
1365 NSString* dumpFile = [[NSHomeDirectory() stringByAppendingPathComponent:@SAVEDIR] stringByAppendingPathComponent:@SNAPSHOTDIR];
1366 dumpFile = [dumpFile stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", name]];
1367
1368 SDL_Surface* tmpSurface = SDL_CreateSurface(width, height, SDL_PIXELFORMAT_RGBA32);
1369 for (int y = 0; y < height; y++) {
1370 uint8_t* srcRow = bytes + rowBytes * y;
1371 uint8_t* dstRow = (uint8_t*)tmpSurface->pixels + y * tmpSurface->pitch;
1372 for (int x = 0; x < width; x++) {
1373 dstRow[4 * x + 0] = srcRow[x];
1374 dstRow[4 * x + 1] = srcRow[x];
1375 dstRow[4 * x + 2] = srcRow[x];
1376 dstRow[4 * x + 3] = '\xff';
1377 }
1378 }
1379 SDL_SavePNG(tmpSurface, [dumpFile UTF8String]);
1380 SDL_DestroySurface(tmpSurface);
1381}

References nil, x, and y.

Referenced by dumpRGBAToRGBFileNamed:andGrayFileNamed:bytes:width:height:rowBytes:, and OODumpPixMap().

Here is the caller graph for this function:

◆ dumpRGBAToFileNamed:bytes:width:height:rowBytes:

- (void) dumpRGBAToFileNamed: (NSString*) name
bytes: (uint8_t*) bytes
width: (NSUInteger) width
height: (NSUInteger) height
rowBytes: (NSUInteger) rowBytes 

Definition at line 1319 of file MyOpenGLView.m.

1319 :(NSString*)name
1320 bytes:(uint8_t*)bytes
1321 width:(NSUInteger)width
1322 height:(NSUInteger)height
1323 rowBytes:(NSUInteger)rowBytes
1324{
1325 if (name == nil || bytes == NULL || width == 0 || height == 0 || rowBytes < width * 4)
1326 return;
1327
1328 // use the snapshots directory
1329 NSString* dumpFile = [[NSHomeDirectory() stringByAppendingPathComponent:@SAVEDIR] stringByAppendingPathComponent:@SNAPSHOTDIR];
1330 dumpFile = [dumpFile stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", name]];
1331
1332 SDL_Surface* tmpSurface = SDL_CreateSurfaceFrom(width, height, SDL_PIXELFORMAT_RGBA32, bytes, rowBytes);
1333 SDL_SavePNG(tmpSurface, [dumpFile UTF8String]);
1334 SDL_DestroySurface(tmpSurface);
1335}

References nil.

◆ dumpRGBAToRGBFileNamed:andGrayFileNamed:bytes:width:height:rowBytes:

- (void) dumpRGBAToRGBFileNamed: (NSString*) rgbName
andGrayFileNamed: (NSString*) grayName
bytes: (uint8_t*) bytes
width: (NSUInteger) width
height: (NSUInteger) height
rowBytes: (NSUInteger) rowBytes 

Definition at line 1411 of file MyOpenGLView.m.

1411 :(NSString*)rgbName
1412 andGrayFileNamed:(NSString*)grayName
1413 bytes:(uint8_t*)bytes
1414 width:(NSUInteger)width
1415 height:(NSUInteger)height
1416 rowBytes:(NSUInteger)rowBytes
1417{
1418 if ((rgbName == nil && grayName == nil) || bytes == NULL || width == 0 || height == 0 || rowBytes < width * 4)
1419 return;
1420
1421 uint8_t *rgbBytes, *rgbPx, *grayBytes, *grayPx, *srcPx;
1422 NSUInteger x, y;
1423 BOOL trivalAlpha = YES;
1424
1425 rgbPx = rgbBytes = malloc(width * height * 3);
1426 if (rgbBytes == NULL)
1427 return;
1428
1429 grayPx = grayBytes = malloc(width * height);
1430 if (grayBytes == NULL) {
1431 free(rgbBytes);
1432 return;
1433 }
1434
1435 for (y = 0; y < height; y++) {
1436 srcPx = bytes + rowBytes * y;
1437
1438 for (x = 0; x < width; x++) {
1439 *rgbPx++ = *srcPx++;
1440 *rgbPx++ = *srcPx++;
1441 *rgbPx++ = *srcPx++;
1442 trivalAlpha = trivalAlpha && ((*srcPx == 0xFF) || (*srcPx == 0x00)); // Look for any "interesting" pixels in alpha.
1443 *grayPx++ = *srcPx++;
1444 }
1445 }
1446
1447 [self dumpRGBToFileNamed:rgbName
1448 bytes:rgbBytes
1449 width:width
1450 height:height
1451 rowBytes:width * 3];
1452 free(rgbBytes);
1453
1454 if (!trivalAlpha) {
1455 [self dumpGrayToFileNamed:grayName
1456 bytes:grayBytes
1457 width:width
1458 height:height
1459 rowBytes:width];
1460 }
1461 free(grayBytes);
1462}

References dumpGrayToFileNamed:bytes:width:height:rowBytes:, dumpRGBToFileNamed:bytes:width:height:rowBytes:, nil, x, and y.

Referenced by OODumpPixMap().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dumpRGBToFileNamed:bytes:width:height:rowBytes:

- (void) dumpRGBToFileNamed: (NSString*) name
bytes: (uint8_t*) bytes
width: (NSUInteger) width
height: (NSUInteger) height
rowBytes: (NSUInteger) rowBytes 

Definition at line 1337 of file MyOpenGLView.m.

1337 :(NSString*)name
1338 bytes:(uint8_t*)bytes
1339 width:(NSUInteger)width
1340 height:(NSUInteger)height
1341 rowBytes:(NSUInteger)rowBytes
1342{
1343 if (name == nil || bytes == NULL || width == 0 || height == 0 || rowBytes < width * 3)
1344 return;
1345
1346 // use the snapshots directory
1347 NSString* dumpFile = [[NSHomeDirectory() stringByAppendingPathComponent:@SAVEDIR] stringByAppendingPathComponent:@SNAPSHOTDIR];
1348 dumpFile = [dumpFile stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", name]];
1349
1350 SDL_Surface* tmpSurface = SDL_CreateSurfaceFrom(width, height, SDL_PIXELFORMAT_RGB24, bytes, rowBytes);
1351 SDL_SavePNG(tmpSurface, [dumpFile UTF8String]);
1352 SDL_DestroySurface(tmpSurface);
1353}

References nil.

Referenced by dumpRGBAToRGBFileNamed:andGrayFileNamed:bytes:width:height:rowBytes:.

Here is the caller graph for this function:

◆ endSplashScreen

- (void) endSplashScreen

Definition at line 425 of file MyOpenGLView.m.

426{
427#if OOLITE_WINDOWS
428 // we need to get through here even if splash screen has not
429 // been shown - this method also prepares the main game window
430 if ([self hdrOutput] && ![self isOutputDisplayHDREnabled]) {
431 if (MessageBox(NULL, "No primary display in HDR mode was detected.\n\n"
432 "If you continue, graphics will not be rendered as intended.\n"
433 "Click OK to launch anyway, or Cancel to exit.",
434 "oolite.exe - HDR requested",
435 MB_OKCANCEL | MB_ICONWARNING)
436 == IDCANCEL) {
437 [gameController exitAppWithContext:@"Cancel selected on no-HDR confirmation dialog"];
438 }
439 }
440
441#endif
442 BOOL replaceSplashWindow = showSplashScreen && !fullScreen && window && glContext;
443 if (!replaceSplashWindow) {
444 SDL_SetWindowResizable(window, true);
445 SDL_SetWindowBordered(window, true);
446 }
447 if (!showSplashScreen)
448 return;
449
450 if (fullScreen) {
451 SDL_SetWindowFullscreen(window, true);
452 } else {
453 // Some window managers (e.g. Marco) leave the borderless splash window unframed
454 // after it gains a border, and some (e.g. Mutter under XWayland) drop its focus.
455 // Replace it with a new window that has its final size, border and centred
456 // position before it is mapped. The splash window is destroyed before the new one
457 // is shown, so no other Oolite window holds focus when the new one is mapped.
458 SDL_Window* previousWindow = window; // the window in use so far, which showed the splash
459 window = NULL;
460 [self createWindowWithSize:firstScreen];
461 SDL_DestroyWindow(previousWindow);
462 // createWindowWithSize: left glContext current, and SDL_DestroyWindow does not destroy
463 // it. But destroying the old window frees the GL context of its SDL framebuffer renderer,
464 // which SDL makes current and then releases, so no context is current afterwards.
465 // Rebind glContext before anything draws.
466 if (!SDL_GL_MakeCurrent(window, glContext)) {
467 OOLog(@"sdl.create_context", @"Could not make OpenGL context current: %s", SDL_GetError());
468 exit(1);
469 }
470 SDL_ShowWindow(window);
471 }
472
473 /* MKW 2011.11.11
474 * Eat all SDL events to gobble up any resize events while the
475 * splash-screen was visible. They affected the main window after 1.74.
476 * TODO: should really process SDL events while showing the splash-screen
477
478 int numEvents = 0;
479 */
480 SDL_Event dummyEvent;
481 while (SDL_PollEvent(&dummyEvent)) {
482 /* Do nothing; the below is for development info
483 numEvents++;
484 OOLog(@"display.splash", @"Suppressed splash-screen event %d: %d ", numEvents, dummyEvent.type);
485 */
486 }
487
488 [self initialiseGLWithSize:firstScreen];
489 [self updateScreen];
490 [self autoShowMouse];
491}
BOOL showSplashScreen
BOOL isOutputDisplayHDREnabled()

References autoShowMouse, createWindowWithSize:, endSplashScreen, GameController::exitAppWithContext:, fullScreen, glContext, hdrOutput, initialiseGLWithSize:, isOutputDisplayHDREnabled, OOLog, showSplashScreen, updateScreen, and window.

Referenced by GameController::endSplashScreen, endSplashScreen, and initSplashScreen.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ findDisplayModeForWidth:Height:Refresh:

- (int) findDisplayModeForWidth: (unsigned int) d_width
Height: (unsigned int) d_height
Refresh: (unsigned int) d_refresh 

Definition at line 1240 of file MyOpenGLView.m.

1240 :(unsigned int)d_width Height:(unsigned int)d_height Refresh:(unsigned int)d_refresh
1241{
1242 int i, modeCount;
1243 NSDictionary* mode;
1244 unsigned int modeWidth, modeHeight, modeRefresh;
1245
1246 modeCount = [screenSizes count];
1247
1248 for (i = 0; i < modeCount; i++) {
1249 mode = [screenSizes objectAtIndex:i];
1250 modeWidth = [[mode objectForKey:kOODisplayWidth] intValue];
1251 modeHeight = [[mode objectForKey:kOODisplayHeight] intValue];
1252 modeRefresh = [[mode objectForKey:kOODisplayRefreshRate] intValue];
1253 if ((modeWidth == d_width) && (modeHeight == d_height) && (modeRefresh == d_refresh)) {
1254 OOLog(@"display.mode.found", @"Found mode %@", mode);
1255 return i;
1256 }
1257 }
1258
1259 OOLog(@"display.mode.found.failed", @"Failed to find mode: width=%d height=%d refresh=%d", d_width, d_height, d_refresh);
1260 OOLog(@"display.mode.found.failed.list", @"Contents of list: %@", screenSizes);
1261 return 0;
1262}

References int(), OOLog, and screenSizes.

Referenced by loadFullscreenSettings.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fov:

- (float) fov: (BOOL) inFraction

Definition at line 1287 of file MyOpenGLView.m.

1287 :(BOOL)inFraction
1288{
1289 return inFraction ? _fov : 2 * atan(_fov) * 180 / M_PI;
1290}
#define M_PI
Definition OOMaths.h:54

References _fov, and M_PI.

Referenced by HeadUpDisplay::drawScannerGrid, Universe::drawUniverse, Universe::gameSettings, PlayerEntity(OOControlsPrivate)::handleGameOptionsScreenKeys, and PlayerEntity::setGuiToGameOptionsScreen.

Here is the caller graph for this function:

◆ gameController

References colorSaturation, gameController, getDisplayId, getNativeSize, hdrOutput, isOutputDisplayHDREnabled, isRunningOnPrimaryDisplayDevice, sdrToneMapper, and updateScreen.

Here is the call graph for this function:

◆ getDisplayDimensions:height:

- (void) getDisplayDimensions: (unsigned*) width
height: (unsigned*) height 

Definition at line 858 of file MyOpenGLView.m.

858 :(unsigned*)width height:(unsigned*)height
859{
860 SDL_DisplayID displayID = SDL_GetDisplayForWindow(window);
861
862 SDL_Rect displaybounds;
863 if (SDL_GetDisplayBounds(displayID, &displaybounds)) {
864 if (width)
865 *width = (unsigned)displaybounds.w;
866 if (height)
867 *height = (unsigned)displaybounds.h;
868 }
869}

References window.

Referenced by PlayerEntity::setGuiToGameOptionsScreen.

Here is the caller graph for this function:

◆ getDisplayId

- (SDL_DisplayID) getDisplayId

Definition at line 59 of file MyOpenGLView.m.

60{
61 SDL_DisplayID displayId = 0;
62 if (window) {
63 displayId = SDL_GetDisplayForWindow(window);
64 } else {
65 int displayCount;
66 SDL_DisplayID* displayIds = SDL_GetDisplays(&displayCount);
67 if (displayIds) {
68 displayId = displayIds[0];
69 } else {
70 OOLog(@"sdl.display_id", @"Could not get list of displays. Error was: %s", SDL_GetError());
71 }
72 SDL_free(displayIds);
73 }
74 return displayId;
75}

References getDisplayId, OOLog, and window.

Referenced by gameController, getDisplayId, getNativeSize, and populateFullScreenModelist.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getNativeSize

- (NSMutableDictionary *) getNativeSize

Definition at line 77 of file MyOpenGLView.m.

78{
79 NSMutableDictionary* mode = [[NSMutableDictionary alloc] init];
80 int nativeDisplayWidth = 1024;
81 int nativeDisplayHeight = 768;
82
83 SDL_DisplayID displayId = [self getDisplayId];
84 SDL_Rect boundsRect;
85 if (displayId && SDL_GetDisplayUsableBounds(displayId, &boundsRect)) {
86 nativeDisplayWidth = boundsRect.w;
87 nativeDisplayHeight = boundsRect.h;
88 OOLog(@"display.mode.list.native", @"Native display resolution detected: %d x %d", nativeDisplayWidth, nativeDisplayHeight);
89 } else {
90 OOLog(@"display.mode.list.native.failed", @"%@", @"SDL_GetWMInfo failed, defaulting to 1024x768 for native size");
91 }
92
93 [mode setValue:[NSNumber numberWithInt:nativeDisplayWidth] forKey:kOODisplayWidth];
94 [mode setValue:[NSNumber numberWithInt:nativeDisplayHeight] forKey:kOODisplayHeight];
95 [mode setValue:[NSNumber numberWithInt:0] forKey:kOODisplayRefreshRate];
96
97 return [mode autorelease];
98}

References getDisplayId, getNativeSize, and OOLog.

Referenced by gameController, getNativeSize, and populateFullScreenModelist.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getOpenGLMatrixManager

- (OOOpenGLMatrixManager *) getOpenGLMatrixManager

Definition at line 1302 of file MyOpenGLView.m.

1303{
1304 return matrixManager;
1305}

References getOpenGLMatrixManager, and matrixManager.

Referenced by getOpenGLMatrixManager, and modeAsSize:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getScreenSizeArray

- (NSMutableArray *) getScreenSizeArray

References getScreenSizeArray, and populateFullScreenModelist.

Referenced by getScreenSizeArray.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getWindowCaption

- (NSString *) getWindowCaption

Definition at line 100 of file MyOpenGLView.m.

101{
102 NSString* caption = [NSString stringWithFormat:@"Oolite v%@ by %@ - %@", @OO_VERSION_FULL, @OO_BUILDER, @OO_BUILD_DATE];
103 return [[caption retain] autorelease];
104}

References getWindowCaption.

Referenced by createWindowWithSize:, and getWindowCaption.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ grabMouseInsideGameWindow:

- (void) grabMouseInsideGameWindow: (BOOL) value

Definition at line 883 of file MyOpenGLView.m.

883 :(BOOL)value
884{
885 SDL_SetWindowMouseGrab(window, value);
886 grabMouseStatus = value;
887}

References grabMouseStatus, and window.

Referenced by PlayerEntity(OOControlsPrivate)::pollApplicationControls.

Here is the caller graph for this function:

◆ handleStringInput:keyID:

- (void) handleStringInput: (SDL_KeyboardEvent*) kbd_event
keyID: (Uint16) key_id 

Provided by category MyOpenGLView(Input).

Definition at line 862 of file MyOpenGLView+Input.m.

862 :(SDL_KeyboardEvent*)kbd_event keyID:(Uint16)key_id
863{
864 SDL_Keycode key = kbd_event->key;
865
866 // Del, Backspace
867 if ((key == SDLK_BACKSPACE || key == SDLK_DELETE) && [typedString length] > 0) {
868 // delete
869 [typedString deleteCharactersInRange:NSMakeRange([typedString length] - 1, 1)];
870 }
871
873
874 // TODO: a more flexible mechanism for max. string length ?
875 if ([typedString length] < 40) {
878 // inputAlpha - limited input for planet find screen
879 if (key >= SDLK_A && key <= SDLK_Z) {
880 isAlphabetKeyDown = YES;
881 [typedString appendFormat:@"%c", key];
882 // if in inputAlpha, keep in lower case.
883 }
884 } else {
885 // Uint16 unicode = kbd_event->keysym.unicode;
886 // printable range
887 if (key_id >= 32 && key_id <= 255) // 126
888 {
889 if ((char)key_id != '/' || allowingStringInput == gvStringInputAll) {
890 isAlphabetKeyDown = YES;
891 [typedString appendFormat:@"%c", key_id];
892 }
893 }
894 }
895 }
896}
@ gvStringInputAll
BOOL isAlphabetKeyDown

Referenced by MyOpenGLView(Input)::pollControls.

Here is the caller graph for this function:

◆ hdrOutput

- (BOOL) hdrOutput

Definition at line 977 of file MyOpenGLView.m.

978{
979 return NO;
980}

References hdrOutput.

Referenced by endSplashScreen, gameController, hdrOutput, and snapShot:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ inFullScreenMode

- (BOOL) inFullScreenMode

Definition at line 672 of file MyOpenGLView.m.

673{
674 return fullScreen;
675}

References fullScreen, and inFullScreenMode.

Referenced by inFullScreenMode, and setFullScreenMode:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initialiseGLWithSize:

- (void) initialiseGLWithSize: (NSSize) v_size

Definition at line 553 of file MyOpenGLView.m.

553 :(NSSize)v_size
554{
555 if (!window) {
556 [self createWindowWithSize:v_size];
557 }
558
559 viewSize = v_size;
560
561 OOLog(@"display.initGL", @"Requested a new surface of %d x %d, %@.", (int)viewSize.width, (int)viewSize.height,
562 (fullScreen ? @"fullscreen" : @"windowed"));
563
564 SDL_GL_SwapWindow(window); // clear the buffer before resize
565
566 SDL_SetWindowFullscreen(window, fullScreen);
567
568 if (!fullScreen) {
569 SDL_SetWindowSize(window, viewSize.width, viewSize.height);
570 SDL_SetWindowBordered(window, YES);
571 }
572#if OOLITE_WINDOWS
573 else // Hack for Windows SDL3 pause issue: https://github.com/libsdl-org/SDL/issues/12791
574 { // Occurs on some systems eg. when going fullscreen -> window or vice versa
575 LONG currentWindowStyle = GetWindowLong(windowHandle, GWL_STYLE);
576 currentWindowStyle &= ~WS_POPUP;
577 SetWindowLong(windowHandle, GWL_STYLE, currentWindowStyle);
578 }
579#endif
580
581 int pixelWidth, pixelHeight;
582 SDL_GetWindowSizeInPixels(window, &pixelWidth, &pixelHeight);
583
584 [self updateGLSize:NSMakeSize(pixelWidth, pixelHeight)];
585
586 OOLog(@"display.initGL",
587 @"Created a new surface of %d x %d, %@.",
588 (int)viewSize.width,
589 (int)viewSize.height,
590 (fullScreen ? @"fullscreen" : @"windowed"));
591
592 [self autoShowMouse];
593
594 [self setUpBasicOpenGLStateWithSize];
595
596 SDL_GL_SwapWindow(window);
597
598 squareX = 0.0f;
599}

References autoShowMouse, createWindowWithSize:, fullScreen, OOLog, setUpBasicOpenGLStateWithSize, squareX, updateGLSize:, viewSize, and window.

Referenced by endSplashScreen, and init.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initKeyMappingData

- (void) initKeyMappingData

Provided by category MyOpenGLView(Input).

Definition at line 30 of file MyOpenGLView+Input.m.

31{
32 NSUserDefaults* prefs = [NSUserDefaults standardUserDefaults];
33 // load in our keyboard scancode mappings
34#if OOLITE_WINDOWS
35 NSDictionary* kmap = [NSDictionary dictionaryWithDictionary:[ResourceManager dictionaryFromFilesNamed:@"keymappings_windows.plist" inFolder:@"Config" mergeMode:MERGE_BASIC cache:NO]];
36#else
37 NSDictionary* kmap = [NSDictionary dictionaryWithDictionary:[ResourceManager dictionaryFromFilesNamed:@"keymappings_linux.plist" inFolder:@"Config" mergeMode:MERGE_BASIC cache:NO]];
38#endif
39 // get the stored keyboard code from preferences
40 NSString* kbd = [prefs oo_stringForKey:@"keyboard-code" defaultValue:@"default"];
41 NSDictionary* subset = [kmap objectForKey:kbd];
42
43 [keyMappings_normal release];
44 keyMappings_normal = [[subset objectForKey:@"mapping_normal"] copy];
45 [keyMappings_shifted release];
46 keyMappings_shifted = [[subset objectForKey:@"mapping_shifted"] copy];
47}
NSDictionary * dictionaryFromFilesNamed:inFolder:mergeMode:cache:(NSString *fileName,[inFolder] NSString *folderName,[mergeMode] OOResourceMergeMode mergeMode,[cache] BOOL useCache)

Referenced by init.

Here is the caller graph for this function:

◆ initSplashScreen

- (void) initSplashScreen

Definition at line 745 of file MyOpenGLView.m.

746{
747 if (!showSplashScreen)
748 return;
749
750 // too early for OOTexture!
751 SDL_Surface* image = NULL;
752 SDL_Rect dest;
753
754 NSString* imagesDir = [[ResourceManager builtInPath] stringByAppendingPathComponent:@"Images"];
755
756 image = SDL_LoadBMP([[imagesDir stringByAppendingPathComponent:@"splash.bmp"] UTF8String]);
757
758 if (image == NULL) {
759 SDL_DestroySurface(image);
760 OOLogWARN(@"sdl.gameStart", @"%@", @"image 'splash.bmp' not found!");
761 [self endSplashScreen];
762 return;
763 }
764
765 dest.x = 0;
766 dest.y = 0;
767 dest.w = image->w;
768 dest.h = image->h;
769
770 [self createWindowWithSize:NSMakeSize(image->w, image->h)];
772 float pixelDensity = SDL_GetWindowPixelDensity(window);
773 if (pixelDensity == 0.0f) {
774 pixelDensity = 1.0f;
775 }
776
777 glViewport(0, 0, dest.w * pixelDensity, dest.h * pixelDensity);
778
779 glEnable(GL_TEXTURE_2D);
780 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
781 glClear(GL_COLOR_BUFFER_BIT);
782
783 [matrixManager resetProjection];
784 [matrixManager orthoLeft:0.0f right:1.0f bottom:1.0f top:0.0f near:-1.0f far:1.0f];
785 [matrixManager syncProjection];
786
787 [matrixManager resetModelView];
788 [matrixManager syncModelView];
789
790 GLuint texture;
791 GLenum texture_format;
792 GLint nOfColors;
793
794 // get the number of channels in the SDL image
795 const SDL_PixelFormatDetails* pixelFormat = SDL_GetPixelFormatDetails(image->format);
796 nOfColors = pixelFormat->bytes_per_pixel;
797 if (nOfColors == 4) // contains an alpha channel
798 {
799 if (pixelFormat->Rmask == 0x000000ff)
800 texture_format = GL_RGBA;
801 else
802 texture_format = GL_BGRA;
803 } else if (nOfColors == 3) // no alpha channel
804 {
805 if (pixelFormat->Rmask == 0x000000ff)
806 texture_format = GL_RGB;
807 else
808 texture_format = GL_BGR;
809 } else {
810 SDL_DestroySurface(image);
811 OOLog(@"Sdl.GameStart", @"%@", @"----- Encoding error within image 'splash.bmp'");
812 [self endSplashScreen];
813 return;
814 }
815
816 glGenTextures(1, &texture);
817 glBindTexture(GL_TEXTURE_2D, texture);
818
819 // Set the texture's stretching properties
820 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
821 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
822
823 // Set the texture image data with the information from SDL_Surface
824 glTexImage2D(GL_TEXTURE_2D, 0, nOfColors, image->w, image->h, 0,
825 texture_format, GL_UNSIGNED_BYTE, image->pixels);
826
827 glBindTexture(GL_TEXTURE_2D, texture);
828 glBegin(GL_QUADS);
829
830 glTexCoord2i(0, 0);
831 glVertex2i(0, 0);
832 glTexCoord2i(1, 0);
833 glVertex2i(1, 0);
834 glTexCoord2i(1, 1);
835 glVertex2i(1, 1);
836 glTexCoord2i(0, 1);
837 glVertex2i(0, 1);
838
839 glEnd();
840 glFinish();
841
842 SDL_GL_SwapWindow(window);
843 [matrixManager resetModelView];
844 [matrixManager syncModelView];
845
846 if (image) {
847 SDL_DestroySurface(image);
848 }
849 glDeleteTextures(1, &texture);
850
851 glDisable(GL_TEXTURE_2D);
853
854 SDL_DestroySurface(image);
855 return;
856}
@ OPENGL_STATE_OVERLAY
Definition OOOpenGL.h:124
#define OOVerifyOpenGLState()
Definition OOOpenGL.h:133
#define OOSetOpenGLState(STATE)
Definition OOOpenGL.h:132
NSString * builtInPath()

References ResourceManager::builtInPath, createWindowWithSize:, endSplashScreen, initSplashScreen, OOLog, OOLogWARN, OOSetOpenGLState, OOVerifyOpenGLState, OPENGL_STATE_OVERLAY, OOOpenGLMatrixManager::orthoLeft:right:bottom:top:near:far:, OOOpenGLMatrixManager::resetModelView, OOOpenGLMatrixManager::resetProjection, showSplashScreen, OOOpenGLMatrixManager::syncModelView, OOOpenGLMatrixManager::syncProjection, and window.

Referenced by GameController::beginSplashScreen, and initSplashScreen.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isCapsLockOn

- (BOOL) isCapsLockOn

Provided by category MyOpenGLView(Input).

Definition at line 178 of file MyOpenGLView+Input.m.

179{
180 /* Caps Lock state check - This effectively gives us
181 an alternate keyboard state to play with and, in
182 the future, we could assign different behaviours
183 to existing controls, depending on the state of
184 Caps Lock. - Nikos 20160304
185 */
186 return (SDL_GetModState() & SDL_KMOD_CAPS) == SDL_KMOD_CAPS;
187}

Referenced by PlayerEntity(OOControlsPrivate)::pollFlightArrowKeyControls:.

Here is the caller graph for this function:

◆ isCommandDown

- (BOOL) isCommandDown

Provided by category MyOpenGLView(Input).

Definition at line 170 of file MyOpenGLView+Input.m.

171{
172 return command;
173}

◆ isCommandFDown

- (BOOL) isCommandFDown

Provided by category MyOpenGLView(Input).

Definition at line 217 of file MyOpenGLView+Input.m.

218{
219 return NO;
220}

◆ isCommandModifierKeyDown

- (BOOL) isCommandModifierKeyDown
implementation

Provided by category MyOpenGLView(OOLoadSaveExtensions).

Definition at line 1132 of file PlayerEntityLoadSave.m.

1133{
1134 return [self isCtrlDown];
1135}

◆ isCommandQDown

- (BOOL) isCommandQDown

Provided by category MyOpenGLView(Input).

Definition at line 213 of file MyOpenGLView+Input.m.

214{
215 return NO;
216}

◆ isCtrlDown

- (BOOL) isCtrlDown

Provided by category MyOpenGLView(Input).

Definition at line 166 of file MyOpenGLView+Input.m.

167{
168 return ctrl;
169}

Referenced by MyOpenGLView(OOLoadSaveExtensions)::isCommandModifierKeyDown, PlayerEntity(OOControlsPrivate)::pollCustomViewControls, PlayerEntity(OOControlsPrivate)::pollFlightArrowKeyControls:, and PlayerEntity(OOControlsPrivate)::pollGuiArrowKeyControls:.

Here is the caller graph for this function:

◆ isDown:

- (BOOL) isDown: (int) key

Provided by category MyOpenGLView(Input).

Definition at line 152 of file MyOpenGLView+Input.m.

152 :(int)key
153{
154 if (suppressKeys)
155 return NO;
156 if (key < 0)
157 return NO;
158 if (key >= [self numKeys])
159 return NO;
160 return keys[key];
161}

Referenced by PlayerEntity(OOControlsPrivate)::handleGameOptionsScreenKeys, PlayerEntity(Controls)::handleGUIUpDownArrowKeys, PlayerEntity(KeyMapper)::handleKeyboardLayoutEntryKeys:view:, PlayerEntity(KeyMapper)::handleKeyConfigKeys:view:, PlayerEntity(KeyMapper)::handleKeyMapperConfirmClearKeys:view:, PlayerEntity(KeyMapper)::keyMapperInputHandler:view:, PlayerEntity(OOControlsPrivate)::pollGuiArrowKeyControls:, and PlayerEntity(StickMapper)::stickMapperInputHandler:view:.

Here is the caller graph for this function:

◆ isOptDown

- (BOOL) isOptDown

Provided by category MyOpenGLView(Input).

Definition at line 162 of file MyOpenGLView+Input.m.

163{
164 return opt;
165}

Referenced by PlayerEntity(OOControlsPrivate)::pollGuiArrowKeyControls:.

Here is the caller graph for this function:

◆ isOutputDisplayHDREnabled

- (BOOL) isOutputDisplayHDREnabled

Definition at line 982 of file MyOpenGLView.m.

983{
984 return NO;
985}

References isOutputDisplayHDREnabled.

Referenced by endSplashScreen, gameController, and isOutputDisplayHDREnabled.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isRunningOnPrimaryDisplayDevice

- (BOOL) isRunningOnPrimaryDisplayDevice

Definition at line 871 of file MyOpenGLView.m.

872{
873 if (!window) {
874 return NO;
875 }
876
877 SDL_DisplayID windowDisplayID = SDL_GetDisplayForWindow(window);
878 SDL_DisplayID primaryDisplayID = SDL_GetPrimaryDisplay();
879
880 return (windowDisplayID != 0 && windowDisplayID == primaryDisplayID);
881}

References isRunningOnPrimaryDisplayDevice, and window.

Referenced by gameController, isRunningOnPrimaryDisplayDevice, and PlayerEntity::setGuiToGameOptionsScreen.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isShiftDown

- (BOOL) isShiftDown

Provided by category MyOpenGLView(Input).

Definition at line 174 of file MyOpenGLView+Input.m.

175{
176 return shift;
177}

Referenced by PlayerEntity(OOControlsPrivate)::pollCustomViewControls, and PlayerEntity(OOControlsPrivate)::pollGuiArrowKeyControls:.

Here is the caller graph for this function:

◆ lastKeyWasShifted

- (BOOL) lastKeyWasShifted

Provided by category MyOpenGLView(Input).

Definition at line 188 of file MyOpenGLView+Input.m.

189{
190 return lastKeyShifted;
191}

◆ loadFullscreenSettings

- (int) loadFullscreenSettings

Definition at line 1205 of file MyOpenGLView.m.

1206{
1207 currentSize = 0;
1208 int width = 0, height = 0, refresh = 0;
1209 unsigned i;
1210
1211 NSArray* cmdline_arguments = [[NSProcessInfo processInfo] arguments];
1212
1213 NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
1214 if ([userDefaults objectForKey:@"display_width"])
1215 width = [userDefaults integerForKey:@"display_width"];
1216 if ([userDefaults objectForKey:@"display_height"])
1217 height = [userDefaults integerForKey:@"display_height"];
1218 if ([userDefaults objectForKey:@"display_refresh"])
1219 refresh = [userDefaults integerForKey:@"display_refresh"];
1220 if ([userDefaults objectForKey:@"fullscreen"])
1221 fullScreen = [userDefaults boolForKey:@"fullscreen"];
1222
1223 // Check if -fullscreen or -windowed has been passed on the command line. If yes,
1224 // set it regardless of what is set by .GNUstepDefaults. If both are found in the
1225 // arguments list, the one that comes last wins.
1226 for (i = 0; i < [cmdline_arguments count]; i++) {
1227 if ([[cmdline_arguments objectAtIndex:i] isEqual:@"-fullscreen"])
1228 fullScreen = YES;
1229 if ([[cmdline_arguments objectAtIndex:i] isEqual:@"-windowed"])
1230 fullScreen = NO;
1231 }
1232
1233 if (width && height) {
1234 currentSize = [self findDisplayModeForWidth:width Height:height Refresh:refresh];
1235 return currentSize;
1236 }
1237 return currentSize;
1238}

References currentSize, findDisplayModeForWidth:Height:Refresh:, fullScreen, int(), and loadFullscreenSettings.

Referenced by init, loadFullscreenSettings, and modeAsSize:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadWindowSize

- (NSSize) loadWindowSize

Definition at line 1191 of file MyOpenGLView.m.

1192{
1193 NSSize windowSize;
1194 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
1195 if ([defaults objectForKey:@"window_width"] && [defaults objectForKey:@"window_height"]) {
1196 windowSize = NSMakeSize([defaults integerForKey:@"window_width"],
1197 [defaults integerForKey:@"window_height"]);
1198 } else {
1199 windowSize = NSMakeSize(WINDOW_SIZE_DEFAULT_WIDTH, WINDOW_SIZE_DEFAULT_HEIGHT);
1200 }
1201 currentWindowSize = windowSize;
1202 return windowSize;
1203}
NSSize currentWindowSize

References currentWindowSize, loadWindowSize, WINDOW_SIZE_DEFAULT_HEIGHT, and WINDOW_SIZE_DEFAULT_WIDTH.

Referenced by init, loadWindowSize, and modeAsSize:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ modeAsSize:

- (NSSize) modeAsSize: (int) sizeIndex

References currentScreenMode, currentScreenSize, getOpenGLMatrixManager, int(), loadFullscreenSettings, loadWindowSize, msaa, and pollShiftKey.

Here is the call graph for this function:

◆ mouseWheelDelta

- (float) mouseWheelDelta

Provided by category MyOpenGLView(Input).

Definition at line 205 of file MyOpenGLView+Input.m.

206{
208}
#define OOMOUSEWHEEL_DELTA
float _mouseWheelDelta

Referenced by PlayerEntity::doBookkeeping:.

Here is the caller graph for this function:

◆ mouseWheelState

- (int) mouseWheelState

Provided by category MyOpenGLView(Input).

Definition at line 196 of file MyOpenGLView+Input.m.

197{
198 if (_mouseWheelDelta > 0.0f)
199 return gvMouseWheelUp;
200 else if (_mouseWheelDelta < 0.0f)
201 return gvMouseWheelDown;
202 else
203 return gvMouseWheelNeutral;
204}
@ gvMouseWheelDown
@ gvMouseWheelNeutral
@ gvMouseWheelUp

◆ msaa

- (BOOL) msaa

Definition at line 1292 of file MyOpenGLView.m.

1293{
1294 return _msaa;
1295}

References _msaa, and msaa.

Referenced by modeAsSize:, and msaa.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ noteMouseInteractionModeChangedFrom:to:

- (void) noteMouseInteractionModeChangedFrom: (OOMouseInteractionMode) oldMode
to: (OOMouseInteractionMode) newMode 

Provided by category MyOpenGLView(Input).

Definition at line 86 of file MyOpenGLView+Input.m.

87{
88 [self autoShowMouse];
89 [self setMouseInDeltaMode:OOMouseInteractionModeIsFlightMode(newMode)];
90}
OOMouseInteractionMode

Referenced by GameController::setMouseInteractionMode:.

Here is the caller graph for this function:

◆ numKeys

- (int) numKeys

Provided by category MyOpenGLView(Input).

Definition at line 192 of file MyOpenGLView+Input.m.

193{
194 return NUM_KEYS;
195}
#define NUM_KEYS

Referenced by MyOpenGLView(Input)::clearKeys.

Here is the caller graph for this function:

◆ pollControls

- (void) pollControls

Provided by category MyOpenGLView(Input).

Definition at line 225 of file MyOpenGLView+Input.m.

226{
227 SDL_Event event;
228 SDL_KeyboardEvent* kbd_event;
229 SDL_MouseButtonEvent* mbtn_event;
230 SDL_MouseMotionEvent* mmove_event;
231 SDL_MouseWheelEvent* mw_event;
232 float mxdelta, mydelta;
233 float mouseVirtualStickSensitivityX = viewSize.width * _mouseVirtualStickSensitivityFactor;
234 float mouseVirtualStickSensitivityY = viewSize.height * _mouseVirtualStickSensitivityFactor;
235 NSTimeInterval timeNow = [NSDate timeIntervalSinceReferenceDate];
236 Uint16 key_id;
237 SDL_Scancode scan_code;
238 float inDelta;
239 bool resize_pending = false;
240
241 while (SDL_PollEvent(&event)) {
242 switch (event.type) {
243 case SDL_EVENT_JOYSTICK_AXIS_MOTION:
244 case SDL_EVENT_JOYSTICK_BUTTON_UP:
245 case SDL_EVENT_JOYSTICK_BUTTON_DOWN:
246 case SDL_EVENT_GAMEPAD_AXIS_MOTION:
247 case SDL_EVENT_GAMEPAD_BUTTON_UP:
248 case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
249 case SDL_EVENT_JOYSTICK_HAT_MOTION:
251 break;
252
253 case SDL_EVENT_MOUSE_BUTTON_DOWN:
254 mbtn_event = (SDL_MouseButtonEvent*)&event;
255
256 switch (mbtn_event->button) {
257 case SDL_BUTTON_LEFT:
258 keys[gvMouseLeftButton] = YES;
259 break;
260 case SDL_BUTTON_RIGHT:
261 // Cocoa version does this in the GameController
262 /*
263 The mouseWarped variable is quite important as far as mouse control is concerned. When we
264 reset the virtual joystick (mouse) coordinates, we need to send a WarpMouse call because we
265 must recenter the pointer physically on screen. This goes together with a mouse motion event,
266 so we use mouseWarped to simply ignore handling of motion events in this case. - Nikos 20110721
267 */
268 [self resetMouse]; // Will set mouseWarped to YES
269 break;
270 // mousewheel stuff
271 }
272 break;
273
274 case SDL_EVENT_MOUSE_BUTTON_UP:
275 mbtn_event = (SDL_MouseButtonEvent*)&event;
276 NSTimeInterval timeBetweenClicks = timeNow - timeIntervalAtLastClick;
277 timeIntervalAtLastClick += timeBetweenClicks;
278 if (mbtn_event->button == SDL_BUTTON_LEFT) {
279 if (!doubleClick) {
280 doubleClick = (timeBetweenClicks < MOUSE_DOUBLE_CLICK_INTERVAL); // One fifth of a second
281 keys[gvMouseDoubleClick] = doubleClick;
282 }
283 keys[gvMouseLeftButton] = NO;
284 }
285 break;
286
287 case SDL_EVENT_MOUSE_WHEEL:
288 mw_event = (SDL_MouseWheelEvent*)&event;
289
290 inDelta = mw_event->y;
291 if (inDelta > 0) {
292 if (_mouseWheelDelta >= 0.0f)
293 _mouseWheelDelta += inDelta;
294 else
295 _mouseWheelDelta = 0.0f;
296 } else if (inDelta < 0) {
297 if (_mouseWheelDelta <= 0.0f)
298 _mouseWheelDelta += inDelta;
299 else
300 _mouseWheelDelta = 0.0f;
301 }
302 /*
303 Mousewheel handling - just note time since last use here and mark as inactive,
304 if needed, at the end of this method. Note that the mousewheel button up event is
305 kind of special, as in, it is sent at the same time as its corresponding mousewheel
306 button down one - Nikos 20140809
307 */
308 NSTimeInterval timeBetweenMouseWheels = timeNow - timeSinceLastMouseWheel;
309 timeSinceLastMouseWheel += timeBetweenMouseWheels;
310 break;
311
312 case SDL_EVENT_MOUSE_MOTION: {
313 // Delta mode is set when the game is in 'flight' mode.
314 // In this mode, the mouse movement delta is used rather
315 // than absolute position. This is because if the user
316 // clicks the right button to recentre the virtual joystick,
317 // if we are using absolute joystick positioning, as soon
318 // as the player touches the mouse again, the virtual joystick
319 // will snap back to the absolute position (which can be
320 // annoyingly fatal in battle).
321 if (mouseInDeltaMode) {
322 // note: virtual stick sensitivity is configurable
323 SDL_GetRelativeMouseState(&mxdelta, &mydelta);
324 double mxd = (double)mxdelta / mouseVirtualStickSensitivityX;
325 double myd = (double)mydelta / mouseVirtualStickSensitivityY;
326
327 if (!mouseWarped) // Standard event, update coordinates
328 {
331
332 // if we excceed the limits, revert changes
335 }
338 }
339 } else {
340 // Motion event generated by WarpMouse is ignored and
341 // we reset mouseWarped for the next time.
342 mouseWarped = NO;
343 }
344 } else {
345 // Windowed mode. Use the absolute position so the
346 // Oolite mouse pointer appears under the X Window System
347 // mouse pointer.
348 mmove_event = (SDL_MouseMotionEvent*)&event;
349
350 int w = viewSize.width;
351 int h = viewSize.height;
352
353 if (!mouseWarped) // standard event, handle it
354 {
355 // Event coordinates are in points, viewSize in pixels (they differ on high-DPI displays)
356 float pixelDensity = SDL_GetWindowPixelDensity(window);
357 if (pixelDensity <= 0.0f)
358 pixelDensity = 1.0f;
359 double mx = mmove_event->x * pixelDensity - w / 2.0;
360 double my = mmove_event->y * pixelDensity - h / 2.0;
361 if (display_z > 640.0) {
363 my /= h;
364 } else {
365 mx /= MAIN_GUI_PIXEL_WIDTH * w / 640.0;
366 my /= MAIN_GUI_PIXEL_HEIGHT * w / 640.0;
367 }
368
369 [self setVirtualJoystick:mx vmy:my];
370 } else {
371 // event coming from WarpMouse ignored, get ready for the next
372 mouseWarped = NO;
373 }
374 }
375 break;
376 }
377 case SDL_EVENT_KEY_DOWN:
378 kbd_event = (SDL_KeyboardEvent*)&event;
379 key_id = SDL_GetKeyFromScancode(kbd_event->scancode, kbd_event->mod, NO);
380 scan_code = kbd_event->scancode;
381
382 // char *keychar = SDL_GetKeyName(kbd_event->keysym.sym);
383 // deal with modifiers first
384 BOOL modifier_pressed = NO;
385 BOOL special_key = NO;
386
387 shift = (kbd_event->mod & SDL_KMOD_SHIFT) != 0;
388 ctrl = (kbd_event->mod & SDL_KMOD_CTRL) != 0;
389 opt = (kbd_event->mod & SDL_KMOD_ALT) != 0;
390
391 // translate scancode to unicode equiv
392 switch (kbd_event->key) {
393 case SDLK_LSHIFT:
394 case SDLK_RSHIFT:
395 case SDLK_LCTRL:
396 case SDLK_RCTRL:
397 case SDLK_LALT:
398 case SDLK_RALT:
399 modifier_pressed = YES;
400 break;
401
402 case SDLK_KP_0:
404 special_key = YES;
405 break;
406 case SDLK_KP_1:
408 special_key = YES;
409 break;
410 case SDLK_KP_2:
412 special_key = YES;
413 break;
414 case SDLK_KP_3:
416 special_key = YES;
417 break;
418 case SDLK_KP_4:
420 special_key = YES;
421 break;
422 case SDLK_KP_5:
424 special_key = YES;
425 break;
426 case SDLK_KP_6:
428 special_key = YES;
429 break;
430 case SDLK_KP_7:
432 special_key = YES;
433 break;
434 case SDLK_KP_8:
436 special_key = YES;
437 break;
438 case SDLK_KP_9:
440 special_key = YES;
441 break;
442 case SDLK_KP_PERIOD:
443 key_id = (!allowingStringInput ? gvNumberPadKeyPeriod : 46);
444 special_key = YES;
445 break;
446 case SDLK_KP_DIVIDE:
447 key_id = (!allowingStringInput ? gvNumberPadKeyDivide : 47);
448 special_key = YES;
449 break;
450 case SDLK_KP_MULTIPLY:
452 special_key = YES;
453 break;
454 case SDLK_KP_MINUS:
455 key_id = (!allowingStringInput ? gvNumberPadKeyMinus : 45);
456 special_key = YES;
457 break;
458 case SDLK_KP_PLUS:
459 key_id = (!allowingStringInput ? gvNumberPadKeyPlus : 43);
460 special_key = YES;
461 break;
462 case SDLK_KP_EQUALS:
463 key_id = (!allowingStringInput ? gvNumberPadKeyEquals : 61);
464 special_key = YES;
465 break;
466 case SDLK_KP_ENTER:
467 key_id = gvNumberPadKeyEnter;
468 special_key = YES;
469 break;
470 case SDLK_HOME:
471 key_id = gvHomeKey;
472 special_key = YES;
473 break;
474 case SDLK_END:
475 key_id = gvEndKey;
476 special_key = YES;
477 break;
478 case SDLK_INSERT:
479 key_id = gvInsertKey;
480 special_key = YES;
481 break;
482 case SDLK_PAGEUP:
483 key_id = gvPageUpKey;
484 special_key = YES;
485 break;
486 case SDLK_PAGEDOWN:
487 key_id = gvPageDownKey;
488 special_key = YES;
489 break;
490 case SDLK_SPACE:
491 key_id = 32;
492 special_key = YES;
493 break;
494 case SDLK_RETURN:
495 key_id = 13;
496 special_key = YES;
497 break;
498 case SDLK_TAB:
499 key_id = 9;
500 special_key = YES;
501 break;
502 case SDLK_UP:
503 key_id = gvArrowKeyUp;
504 special_key = YES;
505 break;
506 case SDLK_DOWN:
507 key_id = gvArrowKeyDown;
508 special_key = YES;
509 break;
510 case SDLK_LEFT:
511 key_id = gvArrowKeyLeft;
512 special_key = YES;
513 break;
514 case SDLK_RIGHT:
515 key_id = gvArrowKeyRight;
516 special_key = YES;
517 break;
518 case SDLK_PAUSE:
519 key_id = gvPauseKey;
520 special_key = YES;
521 break;
522 case SDLK_BACKSPACE:
523 key_id = gvBackspaceKey;
524 special_key = YES;
525 break;
526 case SDLK_DELETE:
527 key_id = gvDeleteKey;
528 special_key = YES;
529 break;
530 case SDLK_F1:
531 key_id = gvFunctionKey1;
532 special_key = YES;
533 break;
534 case SDLK_F2:
535 key_id = gvFunctionKey2;
536 special_key = YES;
537 break;
538 case SDLK_F3:
539 key_id = gvFunctionKey3;
540 special_key = YES;
541 break;
542 case SDLK_F4:
543 key_id = gvFunctionKey4;
544 special_key = YES;
545 break;
546 case SDLK_F5:
547 key_id = gvFunctionKey5;
548 special_key = YES;
549 break;
550 case SDLK_F6:
551 key_id = gvFunctionKey6;
552 special_key = YES;
553 break;
554 case SDLK_F7:
555 key_id = gvFunctionKey7;
556 special_key = YES;
557 break;
558 case SDLK_F8:
559 key_id = gvFunctionKey8;
560 special_key = YES;
561 break;
562 case SDLK_F9:
563 key_id = gvFunctionKey9;
564 special_key = YES;
565 break;
566 case SDLK_F10:
567 key_id = gvFunctionKey10;
568 special_key = YES;
569 break;
570 case SDLK_F11:
571 key_id = gvFunctionKey11;
572 special_key = YES;
573 break;
574 case SDLK_F12:
575 key_id = 327;
576 [self toggleScreenMode];
577 special_key = YES;
578 break;
579
580 case SDLK_ESCAPE:
581 if (shift) {
582 SDL_DestroyWindow(window);
583 [gameController exitAppWithContext:@"Shift-escape pressed"];
584 } else {
585 key_id = 27;
586 special_key = YES;
587 }
588 break;
589 default:
590 // OOLog(@"keys.test", @"Unhandled Keydown scancode with unicode = 0: %d", scan_code);
591 ;
592 }
593
594 // the keyup event doesn't give us the unicode value, so store it here so it can be retrieved on keyup
595 // the ctrl key tends to mix up the unicode values, so deal with some special cases
596 // we also need (in most cases) to get the character without the impact of caps lock.
597
598 if (((!special_key && (ctrl || key_id == 0)) || ([self isCapsLockOn] && (!special_key && !allowingStringInput))) && !modifier_pressed) //
599 {
600 // ctrl changes alpha characters to control codes (1-26)
601 if (ctrl && key_id >= 1 && key_id <= 26) {
602 if (shift)
603 key_id += 64; // A-Z is from 65, offset by -1 for the scancode start point
604 else
605 key_id += 96; // a-z is from 97, offset by -1 for the scancode start point
606 } else {
607 // SDL3 - the key_id should contain the correct unicode value, so we shouldn't need to run the key mapping
608 // - kanthoney
609 // key_id = 0; // reset the value here to force a lookup from the keymappings data
610 }
611 }
612
613 // if we've got the unicode value, we can store it in our array now
614 if (key_id > 0)
615 scancode2Unicode[scan_code] = key_id;
616
617 if (allowingStringInput && !modifier_pressed) {
618 [self handleStringInput:kbd_event keyID:key_id];
619 }
620
621 OOLog(kOOLogKeyDown, @"Keydown scancode = %d, unicode = %i", scan_code, key_id);
622
623 if (key_id > 0 && key_id <= [self numKeys]) {
624 keys[key_id] = YES;
625 } else {
626 OOLog(@"keys.test", @"Unhandled Keydown scancode/unicode: %d %i", scan_code, key_id);
627 }
628 break;
629
630 case SDL_EVENT_KEY_UP:
631 suppressKeys = NO; // DJS
632 kbd_event = (SDL_KeyboardEvent*)&event;
633 scan_code = kbd_event->scancode;
634
635 shift = kbd_event->mod & SDL_KMOD_SHIFT;
636 ctrl = kbd_event->mod & SDL_KMOD_CTRL;
637 opt = kbd_event->mod & SDL_KMOD_ALT;
638
639 // all the work should have been down on the keydown event, so all we need to do is get the unicode value from the array
640 key_id = scancode2Unicode[scan_code];
641
642 // deal with modifiers first
643 switch (kbd_event->key) {
644 case SDLK_LSHIFT:
645 case SDLK_RSHIFT:
646 shift = NO;
647 break;
648
649 case SDLK_LCTRL:
650 case SDLK_RCTRL:
651 ctrl = NO;
652 break;
653
654 case SDLK_LALT:
655 case SDLK_RALT:
656 opt = NO;
657 break;
658 default:;
659 }
660 OOLog(kOOLogKeyUp, @"Keyup scancode = %d, unicode = %i, character = %c, shift = %d, ctrl = %d, alt = %d", scan_code, key_id, key_id, shift, ctrl, opt);
661 // OOLog(kOOLogKeyUp, @"Keyup scancode = %d, shift = %d, ctrl = %d, alt = %d", scan_code, shift, ctrl, opt);
662
663 // translate scancode to unicode equiv
664 switch (kbd_event->key) {
665 case SDLK_KP_0:
667 break;
668 case SDLK_KP_1:
670 break;
671 case SDLK_KP_2:
673 break;
674 case SDLK_KP_3:
676 break;
677 case SDLK_KP_4:
679 break;
680 case SDLK_KP_5:
682 break;
683 case SDLK_KP_6:
685 break;
686 case SDLK_KP_7:
688 break;
689 case SDLK_KP_8:
691 break;
692 case SDLK_KP_9:
694 break;
695 case SDLK_KP_PERIOD:
696 key_id = (!allowingStringInput ? gvNumberPadKeyPeriod : 46);
697 break;
698 case SDLK_KP_DIVIDE:
699 key_id = (!allowingStringInput ? gvNumberPadKeyDivide : 47);
700 break;
701 case SDLK_KP_MULTIPLY:
703 break;
704 case SDLK_KP_MINUS:
705 key_id = (!allowingStringInput ? gvNumberPadKeyMinus : 45);
706 break;
707 case SDLK_KP_PLUS:
708 key_id = (!allowingStringInput ? gvNumberPadKeyPlus : 43);
709 break;
710 case SDLK_KP_EQUALS:
711 key_id = (!allowingStringInput ? gvNumberPadKeyEquals : 61);
712 break;
713 case SDLK_KP_ENTER:
714 key_id = gvNumberPadKeyEnter;
715 break;
716 case SDLK_HOME:
717 key_id = gvHomeKey;
718 break;
719 case SDLK_END:
720 key_id = gvEndKey;
721 break;
722 case SDLK_INSERT:
723 key_id = gvInsertKey;
724 break;
725 case SDLK_PAGEUP:
726 key_id = gvPageUpKey;
727 break;
728 case SDLK_PAGEDOWN:
729 key_id = gvPageDownKey;
730 break;
731 case SDLK_SPACE:
732 key_id = 32;
733 break;
734 case SDLK_RETURN:
735 key_id = 13;
736 break;
737 case SDLK_TAB:
738 key_id = 9;
739 break;
740 case SDLK_ESCAPE:
741 key_id = 27;
742 break;
743 case SDLK_UP:
744 key_id = gvArrowKeyUp;
745 break;
746 case SDLK_DOWN:
747 key_id = gvArrowKeyDown;
748 break;
749 case SDLK_LEFT:
750 key_id = gvArrowKeyLeft;
751 break;
752 case SDLK_RIGHT:
753 key_id = gvArrowKeyRight;
754 break;
755 case SDLK_PAUSE:
756 key_id = gvPauseKey;
757 break;
758 case SDLK_F1:
759 key_id = gvFunctionKey1;
760 break;
761 case SDLK_F2:
762 key_id = gvFunctionKey2;
763 break;
764 case SDLK_F3:
765 key_id = gvFunctionKey3;
766 break;
767 case SDLK_F4:
768 key_id = gvFunctionKey4;
769 break;
770 case SDLK_F5:
771 key_id = gvFunctionKey5;
772 break;
773 case SDLK_F6:
774 key_id = gvFunctionKey6;
775 break;
776 case SDLK_F7:
777 key_id = gvFunctionKey7;
778 break;
779 case SDLK_F8:
780 key_id = gvFunctionKey8;
781 break;
782 case SDLK_F9:
783 key_id = gvFunctionKey9;
784 break;
785 case SDLK_F10:
786 key_id = gvFunctionKey10;
787 break;
788 case SDLK_F11:
789 key_id = gvFunctionKey11;
790 break;
791 case SDLK_F12:
792 key_id = 327;
793 break;
794 case SDLK_BACKSPACE:
795 key_id = gvBackspaceKey;
796 break;
797 case SDLK_DELETE:
798 key_id = gvDeleteKey;
799 break;
800
801 default:
802 // OOLog(@"keys.test", @"Unhandled Keyup scancode with unicode = 0: %d", kbd_event->keysym.scancode);
803 ;
804 }
805
806 if (key_id > 0 && key_id <= [self numKeys]) {
807 keys[key_id] = NO;
808 } else {
809 // OOLog(@"keys.test", @"Unhandled Keyup scancode: %d", kbd_event->keysym.scancode);
810 }
811 break;
812
813 case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED: {
814 resize_pending = true;
815 break;
816 }
817
818#if OOLITE_WINDOWS
819 case SDL_EVENT_WINDOW_FOCUS_GAINED: {
820 [gameController setEcoQoS:[gameController isGamePaused]];
821 break;
822 }
823
824 case SDL_EVENT_WINDOW_FOCUS_LOST: {
825 [gameController setEcoQoS:YES];
826 break;
827 }
828#endif
829
830 // caused by INTR or someone hitting close
831 case SDL_EVENT_QUIT: {
832 SDL_DestroyWindow(window);
833 [gameController exitAppWithContext:@"SDL_QUIT event received"];
834 }
835 }
836 }
837 // check if enough time has passed since last use of the mousewheel and act
838 // if needed
840 _mouseWheelDelta = 0.0f;
841 }
842 if (resize_pending) {
843 int pixelWidth, pixelHeight;
844 // Fetch actual pixel bounds back from SDL
845 SDL_GetWindowSizeInPixels(window, &pixelWidth, &pixelHeight);
846
847 [self updateGLSize:NSMakeSize(pixelWidth, pixelHeight)];
848
849 if (!fullScreen) {
850 // Save the window size in points, not pixels: they differ on high-DPI displays,
851 // and the saved size is passed back to SDL_SetWindowSize().
852 int windowWidth, windowHeight;
853 SDL_GetWindowSize(window, &windowWidth, &windowHeight);
854 [self saveWindowSize:NSMakeSize(windowWidth, windowHeight)];
855 }
856 resize_pending = false;
857 }
858}
#define MAIN_GUI_PIXEL_WIDTH
#define MAIN_GUI_PIXEL_HEIGHT
static NSString * kOOLogKeyDown
static NSString * kOOLogKeyUp
#define MOUSE_DOUBLE_CLICK_INTERVAL
@ gvNumberKey4
@ gvNumberPadKeyDivide
@ gvNumberPadKeyMultiply
@ gvNumberKey9
@ gvNumberKey5
@ gvNumberPadKeyPeriod
@ gvFunctionKey2
@ gvBackspaceKey
@ gvInsertKey
@ gvNumberPadKeyPlus
@ gvNumberPadKey9
@ gvNumberPadKey1
@ gvFunctionKey10
@ gvFunctionKey5
@ gvDeleteKey
@ gvNumberKey2
@ gvArrowKeyDown
@ gvNumberPadKey2
@ gvFunctionKey9
@ gvNumberPadKey3
@ gvFunctionKey4
@ gvEndKey
@ gvNumberKey0
@ gvNumberKey7
@ gvHomeKey
@ gvNumberPadKeyEquals
@ gvNumberPadKey6
@ gvNumberPadKeyEnter
@ gvNumberPadKey5
@ gvNumberPadKey4
@ gvNumberKey8
@ gvNumberKey3
@ gvNumberKey6
@ gvPauseKey
@ gvNumberPadKeyMinus
@ gvNumberPadKey7
@ gvFunctionKey11
@ gvFunctionKey8
@ gvNumberKey1
@ gvPageDownKey
@ gvNumberPadKey8
@ gvFunctionKey3
@ gvArrowKeyUp
@ gvArrowKeyRight
@ gvFunctionKey6
@ gvArrowKeyLeft
@ gvFunctionKey7
@ gvPageUpKey
@ gvNumberPadKey0
@ gvFunctionKey1
#define MOUSEY_MAXIMUM
#define OOMOUSEWHEEL_EVENTS_DELAY_INTERVAL
#define MOUSEX_MAXIMUM
GLfloat display_z
int scancode2Unicode[NUM_KEYS]
BOOL mouseInDeltaMode
float _mouseVirtualStickSensitivityFactor
NSPoint virtualJoystickPosition
NSTimeInterval timeSinceLastMouseWheel
NSTimeInterval timeIntervalAtLastClick
BOOL handleSDLEvent:(SDL_Event *evt)

Referenced by GameController::performGameTick:.

Here is the caller graph for this function:

◆ pollShiftKey

+ (BOOL) pollShiftKey

Definition at line 1307 of file MyOpenGLView.m.

1308{
1309#if !OOLITE_WINDOWS
1310 return 0 != (SDL_GetModState() & (SDL_KMOD_LSHIFT | SDL_KMOD_RSHIFT));
1311#else
1312 // SDL_GetModState() does not seem to do exactly what is intended under Windows. For this reason,
1313 // the GetKeyState Windows API call is used to detect the Shift keypress. -- Nikos.
1314 return 0 != (GetKeyState(VK_SHIFT) & 0x100);
1315#endif
1316}

References pollShiftKey.

Referenced by modeAsSize:, and pollShiftKey.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ populateFullScreenModelist

- (void) populateFullScreenModelist

Definition at line 1145 of file MyOpenGLView.m.

1146{
1147 int i;
1148 SDL_DisplayMode** modes;
1149 NSMutableDictionary* mode;
1150 SDL_DisplayID displayId = [self getDisplayId];
1151
1152 screenSizes = [[NSMutableArray alloc] init];
1153
1154 // The default resolution (slot 0) is the resolution we are
1155 // already in since this is guaranteed to work.
1156 mode = [self getNativeSize];
1157 [screenSizes addObject:mode];
1158
1159 int displayModeCount;
1160 modes = SDL_GetFullscreenDisplayModes(displayId, &displayModeCount);
1161 if (!displayModeCount) {
1162 OOLog(@"display.mode.list.none", @"%@", @"SDL didn't return any screen modes");
1163 return;
1164 }
1165
1166 for (i = 0; i < displayModeCount; i++) {
1167 mode = [NSMutableDictionary dictionary];
1168 [mode setValue:[NSNumber numberWithInt:(int)modes[i]->w]
1169 forKey:kOODisplayWidth];
1170 [mode setValue:[NSNumber numberWithInt:(int)modes[i]->h]
1171 forKey:kOODisplayHeight];
1172 [mode setValue:[NSNumber numberWithFloat:(int)modes[i]->refresh_rate]
1173 forKey:kOODisplayRefreshRate];
1174 if (![screenSizes containsObject:mode]) {
1175 [screenSizes addObject:mode];
1176 OOLog(@"display.mode.list", @"Added res %d x %d", modes[i]->w, modes[i]->h);
1177 }
1178 }
1179 SDL_free(modes);
1180}

References getDisplayId, getNativeSize, OOLog, populateFullScreenModelist, and screenSizes.

Referenced by getScreenSizeArray, init, and populateFullScreenModelist.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resetMouse

- (void) resetMouse

Provided by category MyOpenGLView(Input).

Definition at line 121 of file MyOpenGLView+Input.m.

122{
123 [self setVirtualJoystick:0.0 vmy:0.0];
124 if ([[PlayerEntity sharedPlayer] isMouseControlOn]) {
125 // viewSize is in pixels; SDL mouse coordinates are in points (they differ on high-DPI displays)
126 float pixelDensity = SDL_GetWindowPixelDensity(window);
127 if (pixelDensity <= 0.0f)
128 pixelDensity = 1.0f;
129 SDL_WarpMouseInWindow(window, viewSize.width / 2 / pixelDensity, viewSize.height / 2 / pixelDensity);
130 mouseWarped = YES;
131 }
132}

Referenced by PlayerEntity(OOControlsPrivate)::pollApplicationControls, MyOpenGLView(Input)::pollControls, and PlayerEntity(OOControlsPrivate)::pollCustomViewControls.

Here is the caller graph for this function:

◆ resetTypedString

- (void) resetTypedString

Provided by category MyOpenGLView(Input).

Definition at line 78 of file MyOpenGLView+Input.m.

79{
80 [typedString setString:@""];
81}

Referenced by PlayerEntity(OOControlsPrivate)::pollGuiArrowKeyControls:, PlayerEntity(KeyMapper)::setGuiToKeyConfigEntryScreen, and PlayerEntity(Scripting)::setMissionChoiceByTextEntry:.

Here is the caller graph for this function:

◆ saveWindowSize:

- (void) saveWindowSize: (NSSize) windowSize

Definition at line 1183 of file MyOpenGLView.m.

1183 :(NSSize)windowSize
1184{
1185 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
1186 [defaults setInteger:(int)windowSize.width forKey:@"window_width"];
1187 [defaults setInteger:(int)windowSize.height forKey:@"window_height"];
1188 currentWindowSize = windowSize;
1189}

References currentWindowSize.

Referenced by MyOpenGLView(Input)::pollControls.

Here is the caller graph for this function:

◆ sdrToneMapper

- (OOSDRToneMapper) sdrToneMapper

Definition at line 989 of file MyOpenGLView.m.

990{
991 return _sdrToneMapper;
992}

References _sdrToneMapper, and sdrToneMapper.

Referenced by gameController, Universe::gameSettings, and sdrToneMapper.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setDisplayMode:fullScreen:

- (void) setDisplayMode: (int) mode
fullScreen: (BOOL) fsm 

◆ setFov:fromFraction:

- (void) setFov: (float) value
fromFraction: (BOOL) fromFraction 

Definition at line 1282 of file MyOpenGLView.m.

1282 :(float)value fromFraction:(BOOL)fromFraction
1283{
1284 _fov = fromFraction ? value : tan((value / 2) * M_PI / 180);
1285}

References _fov, and M_PI.

Referenced by PlayerEntity(OOControlsPrivate)::handleGameOptionsScreenKeys, and Universe::initWithGameView:.

Here is the caller graph for this function:

◆ setFullScreenMode:

- (void) setFullScreenMode: (BOOL) fsm

References inFullScreenMode.

Here is the call graph for this function:

◆ setGameController:

- (void) setGameController: (GameController*) controller

Definition at line 667 of file MyOpenGLView.m.

667 :(GameController*)controller
668{
669 gameController = controller;
670}
GameController * gameController

References gameController.

Referenced by GameController::beginSplashScreen, and GameController::setGameView:.

Here is the caller graph for this function:

◆ setMouseInDeltaMode:

- (void) setMouseInDeltaMode: (BOOL) inDelta

Provided by category MyOpenGLView(Input).

Definition at line 897 of file MyOpenGLView+Input.m.

897 :(BOOL)inDelta
898{
899 mouseInDeltaMode = inDelta;
900}

Referenced by MyOpenGLView(Input)::noteMouseInteractionModeChangedFrom:to:.

Here is the caller graph for this function:

◆ setMouseWheelDelta:

- (void) setMouseWheelDelta: (float) newWheelDelta

Provided by category MyOpenGLView(Input).

Definition at line 209 of file MyOpenGLView+Input.m.

209 :(float)newWheelDelta
210{
211 _mouseWheelDelta = newWheelDelta * OOMOUSEWHEEL_DELTA;
212}

Referenced by PlayerEntity::doBookkeeping:.

Here is the caller graph for this function:

◆ setMsaa:

- (void) setMsaa: (BOOL) newMsaa

Definition at line 1297 of file MyOpenGLView.m.

1297 :(BOOL)newMsaa
1298{
1299 _msaa = !!newMsaa;
1300}

References _msaa.

Referenced by Universe::initWithGameView:.

Here is the caller graph for this function:

◆ setScreenSize:

- (void) setScreenSize: (int) sizeIndex

Referenced by PlayerEntity(OOControlsPrivate)::handleGameOptionsScreenKeys.

Here is the caller graph for this function:

◆ setSDRToneMapper:

- (void) setSDRToneMapper: (OOSDRToneMapper) newToneMapper

Definition at line 994 of file MyOpenGLView.m.

994 :(OOSDRToneMapper)newToneMapper
995{
996 if (newToneMapper > OOSDR_TONEMAPPER_REINHARD)
997 newToneMapper = OOSDR_TONEMAPPER_REINHARD;
998 if (newToneMapper < OOSDR_TONEMAPPER_NONE)
999 newToneMapper = OOSDR_TONEMAPPER_NONE;
1000 _sdrToneMapper = newToneMapper;
1001}
OOSDRToneMapper
@ OOSDR_TONEMAPPER_REINHARD
@ OOSDR_TONEMAPPER_NONE

References _sdrToneMapper, OOSDR_TONEMAPPER_NONE, and OOSDR_TONEMAPPER_REINHARD.

Referenced by OoliteSetProperty(), and OoliteSetProperty().

Here is the caller graph for this function:

◆ setStringInput:

- (void) setStringInput: (enum StringInput) value

Provided by category MyOpenGLView(Input).

Definition at line 59 of file MyOpenGLView+Input.m.

59 :(enum StringInput)value
60{
61 allowingStringInput = value;
62}
StringInput

Referenced by PlayerEntity(OOControlsPrivate)::pollDemoControls:, PlayerEntity(OOControlsPrivate)::pollGuiArrowKeyControls:, PlayerEntity(KeyMapper)::setGuiToKeyConfigEntryScreen, and PlayerEntity(OOLoadSavePrivate)::setGuiToOverwriteScreen:.

Here is the caller graph for this function:

◆ setTypedString:

- (void) setTypedString: (NSString*) value

Provided by category MyOpenGLView(Input).

Definition at line 82 of file MyOpenGLView+Input.m.

82 :(NSString*)value
83{
84 [typedString setString:value];
85}

Referenced by PlayerEntity(LoadSave)::saveCommanderInputHandler, PlayerEntity(KeyMapper)::setGuiToKeyConfigEntryScreen, and PlayerEntity(OOLoadSavePrivate)::setGuiToSaveCommanderScreen:.

Here is the caller graph for this function:

◆ setUpBasicOpenGLStateWithSize

- (void) setUpBasicOpenGLStateWithSize
implementation

Definition at line 516 of file MyOpenGLView.m.

517{
518 OOOpenGLExtensionManager* extMgr = [OOOpenGLExtensionManager sharedManager];
519
520 OOGL(glClearColor(0.0, 0.0, 0.0, 0.0));
521 OOGL(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
522 OOGL(glClearDepth(1.0));
523 OOGL(glDepthFunc(GL_LESS)); // depth buffer
524
525 if (UNIVERSE) {
526 [UNIVERSE setLighting];
527 } else {
528 GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
529 GLfloat white[] = { 1.0, 1.0, 1.0, 1.0 };
530 GLfloat stars_ambient[] = { 0.25, 0.2, 0.25, 1.0 };
531
532 OOGL(glLightfv(GL_LIGHT1, GL_AMBIENT, black));
533 OOGL(glLightfv(GL_LIGHT1, GL_SPECULAR, white));
534 OOGL(glLightfv(GL_LIGHT1, GL_DIFFUSE, white));
535 OOGL(glLightfv(GL_LIGHT1, GL_POSITION, black));
536 OOGL(glLightModelfv(GL_LIGHT_MODEL_AMBIENT, stars_ambient));
537 }
538
539 if ([extMgr usePointSmoothing]) {
540 OOGL(glEnable(GL_POINT_SMOOTH));
541 }
542
543 if ([extMgr useLineSmoothing]) {
544 OOGL(glEnable(GL_LINE_SMOOTH));
545 }
546
547 OOGL(glDisable(GL_NORMALIZE));
548 OOGL(glDisable(GL_RESCALE_NORMAL));
549
550 OOGL(glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR));
551}
#define OOGL(statement)
Definition OOOpenGL.h:262
#define UNIVERSE
Definition Universe.h:827
OOOpenGLExtensionManager * sharedManager()

References OOGL, setUpBasicOpenGLStateWithSize, OOOpenGLExtensionManager::sharedManager, and UNIVERSE.

Referenced by initialiseGLWithSize:, and setUpBasicOpenGLStateWithSize.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setVirtualJoystick:vmy:

- (void) setVirtualJoystick: (double) vmx
vmy: (double) vmy 

Provided by category MyOpenGLView(Input).

Definition at line 91 of file MyOpenGLView+Input.m.

91 :(double)vmx vmy:(double)vmy
92{
95}

Referenced by MyOpenGLView(Input)::pollControls, and MyOpenGLView(Input)::resetMouse.

Here is the caller graph for this function:

◆ snapShot:

- (BOOL) snapShot: (NSString*) filename

Definition at line 1014 of file MyOpenGLView.m.

1014 :(NSString*)filename
1015{
1016 BOOL snapShotOK = YES;
1017 SDL_Surface* tmpSurface;
1018
1019#if OOLITE_MAC_OS_X
1020 // The back buffer is undefined after a swap on macOS, so read the frame currently on screen.
1021 OOGL(glReadBuffer(GL_FRONT));
1022#endif
1023
1024 // backup the previous directory
1025 NSString* originalDirectory = [[NSFileManager defaultManager] currentDirectoryPath];
1026 // use the snapshots directory
1027 [[NSFileManager defaultManager] chdirToSnapshotPath];
1028
1029 BOOL withFilename = (filename != nil);
1030 static unsigned imageNo = 0;
1031 unsigned tmpImageNo = 0;
1032 NSString* pathToPic = nil;
1033 NSString* baseName = @"oolite";
1034
1035#if SNAPSHOTS_PNG_FORMAT
1036 NSString* extension = @".png";
1037#else
1038 NSString* extension = @".bmp";
1039#endif
1040
1041 if (withFilename) {
1042 baseName = filename;
1043 pathToPic = [filename stringByAppendingString:extension];
1044 } else {
1045 tmpImageNo = imageNo;
1046 }
1047
1048 if (withFilename && [[NSFileManager defaultManager] fileExistsAtPath:pathToPic]) {
1049 OOLog(@"screenshot.filenameExists", @"Snapshot \"%@%@\" already exists - adding numerical sequence.", pathToPic, extension);
1050 pathToPic = nil;
1051 }
1052
1053 if (pathToPic == nil) {
1054 do {
1055 tmpImageNo++;
1056 pathToPic = [NSString stringWithFormat:@"%@-%03d%@", baseName, tmpImageNo, extension];
1057 } while ([[NSFileManager defaultManager] fileExistsAtPath:pathToPic]);
1058 }
1059
1060 if (!withFilename) {
1061 imageNo = tmpImageNo;
1062 }
1063
1064#if OOLITE_MAC_OS_X
1065 // No window surface on macOS (see createWindowWithSize:); describe the GL drawable instead.
1066 SDL_Surface* surface = NULL;
1067 {
1068 int pixelWidth, pixelHeight;
1069 SDL_GetWindowSizeInPixels(window, &pixelWidth, &pixelHeight);
1070 surface = SDL_CreateSurface(pixelWidth, pixelHeight, SDL_PIXELFORMAT_ARGB8888);
1071 }
1072#else
1073 SDL_Surface* surface = SDL_GetWindowSurface(window);
1074#endif
1075 OOLog(@"screenshot", @"Saving screen shot \"%@\" (%u x %u pixels).", pathToPic, surface->w, surface->h);
1076
1077 int pitch = surface->pitch;
1078 unsigned char* pixls = malloc(pitch * surface->h);
1079 int y;
1080 int off;
1081
1082 if (surface->w % 4)
1083 glPixelStorei(GL_PACK_ALIGNMENT, 1);
1084 else
1085 glPixelStorei(GL_PACK_ALIGNMENT, 4);
1086 for (y = surface->h - 1, off = 0; y >= 0; y--, off += pitch) {
1087 glReadPixels(0, y, surface->w, 1, GL_BGRA, GL_UNSIGNED_BYTE, pixls + off);
1088 }
1089
1090 tmpSurface = SDL_CreateSurfaceFrom(surface->w, surface->h, surface->format, pixls, surface->pitch);
1091#if SNAPSHOTS_PNG_FORMAT
1092 if (!SDL_SavePNG(tmpSurface, [pathToPic UTF8String])) {
1093 OOLog(@"screenshotPNG", @"Failed to save %@", pathToPic);
1094 snapShotOK = NO;
1095 }
1096#else
1097 if (!SDL_SaveBMP(tmpSurface, [pathToPic UTF8String])) {
1098 OOLog(@"screenshotBMP", @"Failed to save %@", pathToPic);
1099 snapShotOK = NO;
1100 }
1101#endif
1102 SDL_DestroySurface(tmpSurface);
1103 free(pixls);
1104
1105 // if outputting HDR signal, save also either an .exr or a Radiance .hdr snapshot
1106 if ([self hdrOutput]) {
1107 NSString* fileExtension = [[NSUserDefaults standardUserDefaults] oo_stringForKey:@"hdr-snapshot-format" defaultValue:SNAPSHOTHDR_EXTENSION_DEFAULT];
1108
1109 // we accept file extension with or without a leading dot; if it is without, insert it at the beginning now
1110 if (![[fileExtension substringToIndex:1] isEqual:@"."])
1111 fileExtension = [@"." stringByAppendingString:fileExtension];
1112
1113 if (![fileExtension isEqual:SNAPSHOTHDR_EXTENSION_EXR] && ![fileExtension isEqual:SNAPSHOTHDR_EXTENSION_HDR]) {
1114 OOLog(@"screenshotHDR", @"Unrecognized HDR file format requested, defaulting to %@", SNAPSHOTHDR_EXTENSION_DEFAULT);
1115 fileExtension = SNAPSHOTHDR_EXTENSION_DEFAULT;
1116 }
1117
1118 NSString* pathToPicHDR = [pathToPic stringByReplacingOccurrencesOfString:@".png" withString:fileExtension];
1119 OOLog(@"screenshot", @"Saving screen shot \"%@\" (%u x %u pixels).", pathToPicHDR, surface->w, surface->h);
1120 GLfloat* pixlsf = (GLfloat*)malloc(pitch * surface->h * sizeof(GLfloat));
1121 for (y = surface->h - 1, off = 0; y >= 0; y--, off += pitch) {
1122 glReadPixels(0, y, surface->w, 1, GL_RGB, GL_FLOAT, pixlsf + off);
1123 }
1124
1125 if (([fileExtension isEqual:SNAPSHOTHDR_EXTENSION_EXR] && SaveEXRSnapshot([pathToPicHDR cStringUsingEncoding:NSUTF8StringEncoding], surface -> w, surface -> h, pixlsf) != 0) // TINYEXR_SUCCESS
1126 || ([fileExtension isEqual:SNAPSHOTHDR_EXTENSION_HDR] && !stbi_write_hdr([pathToPicHDR cStringUsingEncoding:NSUTF8StringEncoding], surface -> w, surface -> h, 3, pixlsf))) {
1127 OOLog(@"screenshotHDR", @"Failed to save %@", pathToPicHDR);
1128 snapShotOK = NO;
1129 }
1130
1131 free(pixlsf);
1132 }
1133
1134#if OOLITE_MAC_OS_X
1135 SDL_DestroySurface(surface);
1136 OOGL(glReadBuffer(GL_BACK));
1137#endif
1138
1139 // return to the previous directory
1140 [[NSFileManager defaultManager] changeCurrentDirectoryPath:originalDirectory];
1141 return snapShotOK;
1142}
#define SNAPSHOTHDR_EXTENSION_HDR
#define SNAPSHOTHDR_EXTENSION_DEFAULT
#define SNAPSHOTHDR_EXTENSION_EXR
int SaveEXRSnapshot(const char *outfilename, int width, int height, const float *rgb)
const char * filename
Definition ioapi.h:125
STBIWDEF int stbi_write_hdr(char const *filename, int w, int h, int comp, const float *data)

References hdrOutput, nil, OOGL, OOLog, SaveEXRSnapshot(), SNAPSHOTHDR_EXTENSION_DEFAULT, SNAPSHOTHDR_EXTENSION_EXR, SNAPSHOTHDR_EXTENSION_HDR, stbi_write_hdr(), window, and y.

Referenced by PlayerEntity(OOControlsPrivate)::pollApplicationControls.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stringToClipboard:

- (void) stringToClipboard: (NSString*) stringToCopy

Definition at line 889 of file MyOpenGLView.m.

889 :(NSString*)stringToCopy
890{
891 if (stringToCopy) {
892 const char* clipboardText = [stringToCopy UTF8String];
893 if (!SDL_SetClipboardText(clipboardText)) {
894 OOLog(@"stringToClipboard.failed", @"Failed to copy string %@ to clipboard: %s", stringToCopy, SDL_GetError());
895 }
896 }
897}

References OOLog.

◆ suppressKeysUntilKeyUp

- (void) suppressKeysUntilKeyUp

Provided by category MyOpenGLView(Input).

Definition at line 143 of file MyOpenGLView+Input.m.

144{
145 if (keys[gvMouseDoubleClick] == NO) {
146 suppressKeys = YES;
147 [self clearKeys];
148 } else {
149 [self clearMouse];
150 }
151}
@ gvMouseDoubleClick

Referenced by PlayerEntity(LoadSave)::commanderSelector, PlayerEntity(KeyMapper)::handleKeyConfigEntryKeys:view:, PlayerEntity(KeyMapper)::handleKeyMapperConfirmClearKeys:view:, PlayerEntity(LoadSave)::saveCommanderInputHandler, and PlayerEntity(OOLoadSavePrivate)::setGuiToSaveCommanderScreen:.

Here is the caller graph for this function:

◆ toggleScreenMode

- (void) toggleScreenMode

References toggleScreenMode.

Referenced by PlayerEntity(OOControlsPrivate)::handleGameOptionsScreenKeys, MyOpenGLView(Input)::pollControls, and toggleScreenMode.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateGLSize:

- (void) updateGLSize: (NSSize) size

Definition at line 493 of file MyOpenGLView.m.

493 :(NSSize)size
494{
495 bounds.size = size;
496 viewSize = size;
497
498 if (bounds.size.width / bounds.size.height > 4.0 / 3.0) {
499 display_z = 480.0 * bounds.size.width / bounds.size.height;
500 x_offset = 240.0 * bounds.size.width / bounds.size.height;
501 y_offset = 240.0;
502 } else {
503 display_z = 640.0;
504 x_offset = 320.0;
505 y_offset = 320.0 * bounds.size.height / bounds.size.width;
506 }
507
508 float ratio = 0.5;
509 float aspect = bounds.size.height / bounds.size.width;
510
511 OOGL(glViewport(0, 0, bounds.size.width, bounds.size.height));
513 OOGLFrustum(-ratio, ratio, -aspect * ratio, aspect * ratio, 1.0, MAX_CLEAR_DEPTH);
514}
#define MAX_CLEAR_DEPTH
void OOGLFrustum(double left, double right, double bottom, double top, double near, double far)
void OOGLResetProjection(void)
GLfloat x_offset
GLfloat y_offset

References bounds, display_z, MAX_CLEAR_DEPTH, OOGL, OOGLFrustum(), OOGLResetProjection(), viewSize, x_offset, and y_offset.

Referenced by initialiseGLWithSize:, and MyOpenGLView(Input)::pollControls.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateScreen

- (void) updateScreen

Definition at line 733 of file MyOpenGLView.m.

734{
735 if (UNIVERSE) {
736 [UNIVERSE drawUniverse]; // do all the drawing!
737 } else {
738 glClearColor(0.0, 0.0, 0.0, 0.0); // not set up yet, draw a black screen
739 glClear(GL_COLOR_BUFFER_BIT);
740 }
741
742 SDL_GL_SwapWindow(window);
743}

References UNIVERSE, updateScreen, and window.

Referenced by GameController::beginSplashScreen, endSplashScreen, gameController, updateScreen, and GameController::windowDidResize:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ viewSize

- (NSSize) viewSize

References backingViewSize, and viewSize.

Here is the call graph for this function:

◆ x_offset

- (GLfloat) x_offset

References x_offset.

◆ y_offset

- (GLfloat) y_offset

References y_offset.

Member Data Documentation

◆ _colorSaturation

- (float) _colorSaturation
protected

Definition at line 232 of file MyOpenGLView.h.

Referenced by adjustColorSaturation:, colorSaturation, and createWindowWithSize:.

◆ _fov

- (float) _fov
protected

Definition at line 200 of file MyOpenGLView.h.

Referenced by fov:, and setFov:fromFraction:.

◆ _hdrOutput

- (BOOL) _hdrOutput
protected

Definition at line 234 of file MyOpenGLView.h.

Referenced by createWindowWithSize:.

◆ _mouseVirtualStickSensitivityFactor

- (float) _mouseVirtualStickSensitivityFactor
protected

Definition at line 191 of file MyOpenGLView.h.

Referenced by init.

◆ _mouseWheelDelta

- (float) _mouseWheelDelta
protected

Definition at line 245 of file MyOpenGLView.h.

Referenced by init.

◆ _msaa

- (BOOL) _msaa
protected

Definition at line 201 of file MyOpenGLView.h.

Referenced by msaa, and setMsaa:.

◆ _sdrToneMapper

- (int) _sdrToneMapper
protected

Definition at line 230 of file MyOpenGLView.h.

Referenced by createWindowWithSize:, sdrToneMapper, and setSDRToneMapper:.

◆ allowingStringInput

◆ bitsPerColorComponent

- (int) bitsPerColorComponent
protected

Definition at line 214 of file MyOpenGLView.h.

Referenced by createWindowWithSize:, and init.

◆ bounds

- (NSRect) bounds
protected

Definition at line 632 of file MyOpenGLView.m.

633{
634 return bounds;
635}

Referenced by backingViewSize, createWindowWithSize:, and updateGLSize:.

◆ command

- (BOOL) command
protected

Definition at line 173 of file MyOpenGLView.h.

◆ ctrl

- (BOOL) ctrl
protected

Definition at line 173 of file MyOpenGLView.h.

◆ currentSize

- (int) currentSize
protected

Definition at line 205 of file MyOpenGLView.h.

Referenced by init, and loadFullscreenSettings.

◆ currentWindowSize

- (NSSize) currentWindowSize
protected

Definition at line 209 of file MyOpenGLView.h.

Referenced by init, loadWindowSize, and saveWindowSize:.

◆ display_z

- (GLfloat) display_z
protected

Definition at line 647 of file MyOpenGLView.m.

648{
649 return display_z;
650}

Referenced by display_z, OOSunEntity::drawDirectVisionSunGlare, OOSunEntity::drawStarGlare, and updateGLSize:.

◆ doubleClick

- (BOOL) doubleClick
protected

Definition at line 185 of file MyOpenGLView.h.

◆ firstScreen

- (NSSize) firstScreen
protected

Definition at line 238 of file MyOpenGLView.h.

Referenced by init.

◆ fullScreen

- (BOOL) fullScreen
protected

◆ gameController

◆ glContext

- (SDL_GLContext) glContext
protected

Definition at line 213 of file MyOpenGLView.h.

Referenced by createWindowWithSize:, dealloc, and endSplashScreen.

◆ grabMouseStatus

- (BOOL) grabMouseStatus
protected

Definition at line 236 of file MyOpenGLView.h.

Referenced by grabMouseInsideGameWindow:, and init.

◆ isAlphabetKeyDown

- (BOOL) isAlphabetKeyDown
protected

◆ keycodetrans

- (int keycodetrans[255])
protected

Definition at line 177 of file MyOpenGLView.h.

◆ keyMappings_normal

- (NSDictionary*) keyMappings_normal
protected

Definition at line 168 of file MyOpenGLView.h.

Referenced by dealloc.

◆ keyMappings_shifted

- (NSDictionary*) keyMappings_shifted
protected

Definition at line 169 of file MyOpenGLView.h.

Referenced by dealloc.

◆ keys

- (BOOL keys[NUM_KEYS])
protected

Definition at line 166 of file MyOpenGLView.h.

◆ lastKeyShifted

- (BOOL) lastKeyShifted
protected

Definition at line 173 of file MyOpenGLView.h.

◆ matrixManager

- (OOOpenGLMatrixManager*) matrixManager
protected

Definition at line 240 of file MyOpenGLView.h.

Referenced by dealloc, getOpenGLMatrixManager, and init.

◆ mouseDragStartPoint

- (NSPoint) mouseDragStartPoint
protected

Definition at line 179 of file MyOpenGLView.h.

◆ mouseInDeltaMode

- (BOOL) mouseInDeltaMode
protected

Definition at line 243 of file MyOpenGLView.h.

◆ mouseWarped

- (BOOL) mouseWarped
protected

Definition at line 181 of file MyOpenGLView.h.

Referenced by init.

◆ opt

- (BOOL) opt
protected

Definition at line 173 of file MyOpenGLView.h.

◆ scancode2Unicode

- (int scancode2Unicode[NUM_KEYS])
protected

Definition at line 167 of file MyOpenGLView.h.

Referenced by init.

◆ screenSizes

- (NSMutableArray*) screenSizes
protected

◆ shift

- (BOOL) shift
protected

Definition at line 173 of file MyOpenGLView.h.

◆ showSplashScreen

- (BOOL) showSplashScreen
protected

Definition at line 211 of file MyOpenGLView.h.

Referenced by endSplashScreen, init, and initSplashScreen.

◆ squareX

- (double) squareX
protected

Definition at line 197 of file MyOpenGLView.h.

Referenced by initialiseGLWithSize:.

◆ squareY

- (double) squareY
protected

Definition at line 197 of file MyOpenGLView.h.

◆ suppressKeys

- (BOOL) suppressKeys
protected

Definition at line 171 of file MyOpenGLView.h.

◆ timeIntervalAtLastClick

- (NSTimeInterval) timeIntervalAtLastClick
protected

Definition at line 183 of file MyOpenGLView.h.

Referenced by init.

◆ timeSinceLastMouseWheel

- (NSTimeInterval) timeSinceLastMouseWheel
protected

Definition at line 184 of file MyOpenGLView.h.

Referenced by init.

◆ typedString

◆ viewSize

- (NSSize) viewSize
protected

◆ virtualJoystickPosition

◆ vSyncPreference

- (BOOL) vSyncPreference
protected

Definition at line 215 of file MyOpenGLView.h.

Referenced by createWindowWithSize:, and init.

◆ window

◆ x_offset

- (GLfloat) x_offset
protected

Definition at line 652 of file MyOpenGLView.m.

653{
654 return x_offset;
655}

Referenced by updateGLSize:, and x_offset.

◆ y_offset

- (GLfloat) y_offset
protected

Definition at line 657 of file MyOpenGLView.m.

658{
659 return y_offset;
660}

Referenced by updateGLSize:, and y_offset.


The documentation for this class was generated from the following files: