LCOV - code coverage report
Current view: top level - SDL - MyOpenGLView.h (source / functions) Hit Total Coverage
Test: coverxygen.info Lines: 1 140 0.7 %
Date: 2025-08-24 10:25:05 Functions: 0 0 -

          Line data    Source code
       1           0 : /*
       2             : 
       3             : MyOpenGLView.h
       4             : 
       5             : Oolite
       6             : Copyright (C) 2004-2013 Giles C Williams and contributors
       7             : 
       8             : This program is free software; you can redistribute it and/or
       9             : modify it under the terms of the GNU General Public License
      10             : as published by the Free Software Foundation; either version 2
      11             : of the License, or (at your option) any later version.
      12             : 
      13             : This program is distributed in the hope that it will be useful,
      14             : but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16             : GNU General Public License for more details.
      17             : 
      18             : You should have received a copy of the GNU General Public License
      19             : along with this program; if not, write to the Free Software
      20             : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
      21             : MA 02110-1301, USA.
      22             : 
      23             : */
      24             : 
      25             : #import "OOCocoa.h"
      26             : #import "OOOpenGL.h"
      27             : #import "OOMouseInteractionMode.h"
      28             : #import "OOOpenGLMatrixManager.h"
      29             : 
      30             : 
      31             : #include <SDL.h>
      32             : 
      33           0 : #define WINDOW_SIZE_DEFAULT_WIDTH       1280
      34           0 : #define WINDOW_SIZE_DEFAULT_HEIGHT      720
      35             : 
      36           0 : #define MIN_FOV_DEG             30.0f
      37           0 : #define MAX_FOV_DEG             80.0f
      38           0 : #define MIN_FOV                 (tan((MIN_FOV_DEG / 2) * M_PI / 180.0f))
      39           0 : #define MAX_FOV                 (tan((MAX_FOV_DEG / 2) * M_PI / 180.0f))
      40             : 
      41           0 : #define MIN_HDR_MAXBRIGHTNESS   400.0
      42           0 : #define MAX_HDR_MAXBRIGHTNESS   1000.0
      43             : 
      44           0 : #define MIN_HDR_PAPERWHITE              80.0f
      45           0 : #define MAX_HDR_PAPERWHITE              280.0f
      46             : 
      47           0 : #define MAX_COLOR_SATURATION    2.0f
      48             : 
      49           0 : #define MOUSEX_MAXIMUM 0.6
      50           0 : #define MOUSEY_MAXIMUM 0.6
      51             : 
      52           0 : #define MAX_CLEAR_DEPTH         10000000000.0
      53             : // 10 000 000 km.
      54           0 : #define INTERMEDIATE_CLEAR_DEPTH                100.0
      55             : // 100 m.
      56             : 
      57             : 
      58           0 : #define NUM_KEYS                        327
      59           0 : #define MOUSE_DOUBLE_CLICK_INTERVAL     0.40
      60           0 : #define OOMOUSEWHEEL_EVENTS_DELAY_INTERVAL      0.05
      61           0 : #define OOMOUSEWHEEL_DELTA      120 // Same as Windows WHEEL_DELTA
      62             : 
      63           0 : #define SNAPSHOTS_PNG_FORMAT            1
      64           0 : #define SNAPSHOTHDR_EXTENSION_EXR       @".exr"
      65           0 : #define SNAPSHOTHDR_EXTENSION_HDR       @".hdr"
      66           0 : #define SNAPSHOTHDR_EXTENSION_DEFAULT   SNAPSHOTHDR_EXTENSION_EXR
      67             : 
      68             : @class Entity, GameController, OpenGLSprite;
      69             : 
      70           0 : enum GameViewKeys
      71             : {
      72             :         gvFunctionKey1 = 256,
      73             :         gvFunctionKey2,
      74             :         gvFunctionKey3,
      75             :         gvFunctionKey4,
      76             :         gvFunctionKey5, // 260
      77             :         gvFunctionKey6,
      78             :         gvFunctionKey7,
      79             :         gvFunctionKey8,
      80             :         gvFunctionKey9,
      81             :         gvFunctionKey10,
      82             :         gvFunctionKey11,
      83             :         gvArrowKeyRight,
      84             :         gvArrowKeyLeft,
      85             :         gvArrowKeyDown,
      86             :         gvArrowKeyUp, // 270
      87             :         gvPauseKey,
      88             :         gvPrintScreenKey, // 272
      89             :         gvMouseLeftButton = 301,
      90             :         gvMouseDoubleClick,
      91             :         gvHomeKey,
      92             :         gvEndKey,
      93             :         gvInsertKey,
      94             :         gvDeleteKey,
      95             :         gvPageUpKey,
      96             :         gvPageDownKey, // 308
      97             :         gvBackspaceKey, // 309
      98             :         gvNumberKey0 = 48,
      99             :         gvNumberKey1,
     100             :         gvNumberKey2,
     101             :         gvNumberKey3,
     102             :         gvNumberKey4,
     103             :         gvNumberKey5,
     104             :         gvNumberKey6,
     105             :         gvNumberKey7,
     106             :         gvNumberKey8,
     107             :         gvNumberKey9, //57
     108             :         gvNumberPadKey0 = 310,
     109             :         gvNumberPadKey1,
     110             :         gvNumberPadKey2,
     111             :         gvNumberPadKey3,
     112             :         gvNumberPadKey4,
     113             :         gvNumberPadKey5,
     114             :         gvNumberPadKey6,
     115             :         gvNumberPadKey7,
     116             :         gvNumberPadKey8,
     117             :         gvNumberPadKey9,
     118             :         gvNumberPadKeyDivide, // 320
     119             :         gvNumberPadKeyMultiply,
     120             :         gvNumberPadKeyMinus,
     121             :         gvNumberPadKeyPlus,
     122             :         gvNumberPadKeyPeriod,
     123             :         gvNumberPadKeyEquals,
     124             :         gvNumberPadKeyEnter // 326
     125             : };
     126             : 
     127           0 : enum MouseWheelStatus
     128             : {
     129             :         gvMouseWheelDown = -1,
     130             :         gvMouseWheelNeutral,
     131             :         gvMouseWheelUp
     132             : };
     133             : 
     134           0 : enum StringInput
     135             : {
     136             :         gvStringInputNo = 0,
     137             :         gvStringInputAlpha = 1,
     138             :         gvStringInputLoadSave = 2,      
     139             :         gvStringInputAll = 3
     140             : };
     141             : 
     142           0 : enum KeyboardType
     143             : {
     144             :         gvKeyboardAuto,
     145             :         gvKeyboardUS,
     146             :         gvKeyboardUK
     147             : };
     148             : 
     149           0 : typedef enum
     150             : {
     151             :         OOHDR_TONEMAPPER_NONE = -1,
     152             :         OOHDR_TONEMAPPER_ACES_APPROX = 0,
     153             :         OOHDR_TONEMAPPER_DICE,
     154             :         OOHDR_TONEMAPPER_UCHIMURA,
     155             :         OOHDR_TONEMAPPER_REINHARD
     156             : } OOHDRToneMapper;
     157             : 
     158           0 : typedef enum
     159             : {
     160             :         OOSDR_TONEMAPPER_NONE = -1,
     161             :         OOSDR_TONEMAPPER_ACES = 0,
     162             :         OOSDR_TONEMAPPER_AgX,
     163             :         OOSDR_TONEMAPPER_HEJLDAWSON,
     164             :         OOSDR_TONEMAPPER_UC2,
     165             :         OOSDR_TONEMAPPER_UCHIMURA,
     166             :         OOSDR_TONEMAPPER_REINHARD
     167             : } OOSDRToneMapper;
     168             : 
     169           0 : extern int debug;
     170             : 
     171             : @interface MyOpenGLView : NSObject
     172             : {
     173             :         GameController          *gameController;
     174             :         BOOL                            keys[NUM_KEYS];
     175             :         int                                     scancode2Unicode[NUM_KEYS];
     176             :         NSDictionary            *keyMappings_normal;
     177             :         NSDictionary            *keyMappings_shifted;
     178             : 
     179             :         BOOL                            suppressKeys;    // DJS
     180             : 
     181             :         BOOL                            opt, ctrl, command, shift, lastKeyShifted;
     182             :         BOOL                            allowingStringInput;
     183             :         BOOL                            isAlphabetKeyDown;
     184             : 
     185             :         int                                     keycodetrans[255];
     186             : 
     187             :         BOOL                            m_glContextInitialized;
     188           0 :     NSPoint                             mouseDragStartPoint;
     189             : 
     190           0 :         BOOL                            mouseWarped;
     191             : 
     192             :         NSTimeInterval          timeIntervalAtLastClick;
     193           0 :         NSTimeInterval          timeSinceLastMouseWheel;
     194             :         BOOL                            doubleClick;
     195             : 
     196             :         NSMutableString         *typedString;
     197             : 
     198             :         NSPoint                         virtualJoystickPosition;
     199             :         
     200           0 :         float                           _mouseVirtualStickSensitivityFactor;
     201             : 
     202             :         NSSize                          viewSize;
     203             :         GLfloat                         display_z;
     204             :         GLfloat                         x_offset, y_offset;
     205             : 
     206           0 :     double                              squareX,squareY;
     207           0 :         NSRect                          bounds;
     208             : 
     209           0 :         float                           _gamma;
     210             :         float                           _fov;
     211           0 :         BOOL                            _msaa;
     212             : 
     213             :    // Full screen sizes
     214           0 :         NSMutableArray          *screenSizes;
     215           0 :         int                                     currentSize;    //we need an int!
     216           0 :         BOOL                            fullScreen;
     217             : 
     218             :         // Windowed mode
     219           0 :         NSSize                          currentWindowSize;
     220           0 :         SDL_Surface                     *surface;
     221             : 
     222           0 :         BOOL                            showSplashScreen;
     223             : 
     224             : #if OOLITE_WINDOWS
     225             : 
     226             :         BOOL                            wasFullScreen;
     227             :         BOOL                            updateContext;
     228             :         BOOL                            saveSize;
     229             :         BOOL                            atDesktopResolution;
     230             :         unsigned                        keyboardMap; // *** FLAGGED for deletion 
     231             :         HWND                            SDL_Window;
     232             :         MONITORINFOEX           monitorInfo;
     233             :         RECT                            lastGoodRect;
     234             :         float                           _hdrMaxBrightness;
     235             :         float                           _hdrPaperWhiteBrightness;
     236             :         int                                     _hdrToneMapper;
     237             : 
     238             : #endif
     239             : 
     240           0 :         int                                     _sdrToneMapper;
     241             : 
     242           0 :         float                           _colorSaturation;
     243             :         
     244           0 :         BOOL                            _hdrOutput;
     245             : 
     246           0 :         BOOL                            grabMouseStatus;
     247             : 
     248           0 :         NSSize                          firstScreen;
     249             :         
     250             :         OOOpenGLMatrixManager           *matrixManager;
     251             : 
     252             :    // Mouse mode indicator (for mouse movement model)
     253           0 :    BOOL                                 mouseInDeltaMode;
     254             :    
     255             :    float                                _mouseWheelDelta;
     256             : }
     257             : 
     258             : /**
     259             :  * \ingroup cli
     260             :  * Scans the command line for -nosplash, --nosplash, -splash, --splash- -novsync and --novsync arguments.
     261             :  */
     262           1 : - (id) init;
     263             : 
     264           0 : - (void) initSplashScreen;
     265           0 : - (void) endSplashScreen;
     266           0 : - (void) autoShowMouse;
     267             : 
     268           0 : - (void) initKeyMappingData;
     269             : 
     270           0 : - (void) setStringInput: (enum StringInput) value;
     271           0 : - (void) allowStringInput: (BOOL) value;
     272           0 : - (enum StringInput) allowingStringInput;
     273           0 : - (NSString *) typedString;
     274           0 : - (void) resetTypedString;
     275           0 : - (void) setTypedString:(NSString*) value;
     276             : 
     277           0 : - (NSSize) viewSize;
     278           0 : - (NSSize) backingViewSize;
     279           0 : - (GLfloat) display_z;
     280           0 : - (GLfloat) x_offset;
     281           0 : - (GLfloat) y_offset;
     282             : 
     283           0 : - (GameController *) gameController;
     284           0 : - (void) setGameController:(GameController *) controller;
     285             : 
     286           0 : - (void) noteMouseInteractionModeChangedFrom:(OOMouseInteractionMode)oldMode to:(OOMouseInteractionMode)newMode;
     287             : 
     288           0 : - (void) initialiseGLWithSize:(NSSize) v_size;
     289           0 : - (void) initialiseGLWithSize:(NSSize) v_size useVideoMode:(BOOL) v_mode;
     290           0 : - (BOOL) isRunningOnPrimaryDisplayDevice;
     291             : #if OOLITE_WINDOWS
     292             : - (BOOL) getCurrentMonitorInfo:(MONITORINFOEX *)mInfo;
     293             : - (MONITORINFOEX) currentMonitorInfo;
     294             : - (void) refreshDarKOrLightMode;
     295             : - (BOOL) isDarkModeOn;
     296             : - (BOOL) atDesktopResolution;
     297             : - (float) hdrMaxBrightness;
     298             : - (void) setHDRMaxBrightness:(float)newMaxBrightness;
     299             : - (float) hdrPaperWhiteBrightness;
     300             : - (void) setHDRPaperWhiteBrightness:(float)newPaperWhiteBrightness;
     301             : - (OOHDRToneMapper) hdrToneMapper;
     302             : - (void) setHDRToneMapper: (OOHDRToneMapper)newToneMapper;
     303             : #endif
     304           0 : - (OOSDRToneMapper) sdrToneMapper;
     305           0 : - (void) setSDRToneMapper: (OOSDRToneMapper)newToneMapper;
     306           0 : - (float) colorSaturation;
     307           0 : - (void) adjustColorSaturation:(float)colorSaturationAdjustment;
     308           0 : - (BOOL) hdrOutput;
     309           0 : - (BOOL) isOutputDisplayHDREnabled;
     310             : 
     311           0 : - (void) grabMouseInsideGameWindow:(BOOL) value;
     312             : 
     313           0 : - (void) stringToClipboard:(NSString *)stringToCopy;
     314             : 
     315           0 : - (void) drawRect:(NSRect)rect;
     316           0 : - (void) updateScreen;
     317           0 : - (void) updateScreenWithVideoMode:(BOOL) v_mode;
     318           0 : - (void) display;
     319             : 
     320           0 : - (BOOL) snapShot:(NSString *)filename;
     321             : #if SNAPSHOTS_PNG_FORMAT
     322           0 : - (BOOL) pngSaveSurface:(NSString *)fileName withSurface:(SDL_Surface *)surf;
     323             : #endif
     324             : 
     325           0 : - (NSRect) bounds;
     326           0 : + (NSMutableDictionary *) getNativeSize;
     327             : 
     328           0 : - (void) setFullScreenMode:(BOOL)fsm;
     329           0 : - (BOOL) inFullScreenMode;
     330           0 : - (void) toggleScreenMode;
     331           0 : - (void) setDisplayMode:(int)mode fullScreen:(BOOL)fsm;
     332             : 
     333           0 : - (int) indexOfCurrentSize;
     334           0 : - (void) setScreenSize: (int)sizeIndex;
     335           0 : - (NSMutableArray *)getScreenSizeArray;
     336           0 : - (void) populateFullScreenModelist;
     337           0 : - (NSSize) modeAsSize: (int)sizeIndex;
     338           0 : - (void) saveWindowSize: (NSSize) windowSize;
     339           0 : - (NSSize) loadWindowSize;
     340           0 : - (int) loadFullscreenSettings;
     341           0 : - (int) findDisplayModeForWidth: (unsigned int) d_width Height:(unsigned int) d_height
     342             :                         Refresh: (unsigned int)d_refresh;
     343           0 : - (NSSize) currentScreenSize;
     344             : 
     345           0 : - (void) pollControls;
     346             : 
     347           0 : - (void) setVirtualJoystick:(double) vmx :(double) vmy;
     348           0 : - (NSPoint) virtualJoystickPosition;
     349             : 
     350           0 : - (void) clearKeys;
     351           0 : - (void) clearMouse;
     352           0 : - (void) clearKey: (int)theKey;
     353           0 : - (void) resetMouse;
     354           0 : - (BOOL) isAlphabetKeyDown;
     355           0 : - (void) suppressKeysUntilKeyUp; // DJS
     356           0 : - (BOOL) isDown: (int) key;
     357           0 : - (BOOL) isOptDown; // opt == alt key
     358           0 : - (BOOL) isCtrlDown;
     359           0 : - (BOOL) isCommandDown;
     360           0 : - (BOOL) isShiftDown;
     361           0 : - (BOOL) isCapsLockOn;
     362           0 : - (BOOL) lastKeyWasShifted;
     363           0 : - (int) numKeys;
     364           0 : - (int) mouseWheelState;
     365           0 : - (float) mouseWheelDelta;
     366           0 : - (void) setMouseWheelDelta: (float) newWheelDelta;
     367             : 
     368             : // Command-key combinations need special handling. SDL stubs for these mac functions.
     369           0 : - (BOOL) isCommandQDown;
     370           0 : - (BOOL) isCommandFDown;
     371           0 : - (void) clearCommandF;
     372             : 
     373           0 : - (void) setMouseInDeltaMode: (BOOL) inDelta;
     374             : 
     375           0 : - (void) setGammaValue: (float) value;
     376           0 : - (float) gammaValue;
     377             : 
     378           0 : - (void) setFov:(float)value fromFraction:(BOOL)fromFraction;
     379           0 : - (float) fov:(BOOL)inFraction;
     380             : 
     381           0 : - (void) setMsaa:(BOOL)newMsaa;
     382           0 : - (BOOL) msaa;
     383             : 
     384             : // Check current state of shift key rather than relying on last event.
     385           0 : + (BOOL)pollShiftKey;
     386             : 
     387           0 : - (OOOpenGLMatrixManager *) getOpenGLMatrixManager;
     388             : 
     389             : #ifndef NDEBUG
     390             : // General image-dumping method.
     391           0 : - (void) dumpRGBAToFileNamed:(NSString *)name
     392             :                                            bytes:(uint8_t *)bytes
     393             :                                            width:(NSUInteger)width
     394             :                                           height:(NSUInteger)height
     395             :                                         rowBytes:(NSUInteger)rowBytes;
     396           0 : - (void) dumpRGBToFileNamed:(NSString *)name
     397             :                                            bytes:(uint8_t *)bytes
     398             :                                            width:(NSUInteger)width
     399             :                                           height:(NSUInteger)height
     400             :                                         rowBytes:(NSUInteger)rowBytes;
     401           0 : - (void) dumpGrayToFileNamed:(NSString *)name
     402             :                                            bytes:(uint8_t *)bytes
     403             :                                            width:(NSUInteger)width
     404             :                                           height:(NSUInteger)height
     405             :                                         rowBytes:(NSUInteger)rowBytes;
     406           0 : - (void) dumpGrayAlphaToFileNamed:(NSString *)name
     407             :                                                         bytes:(uint8_t *)bytes
     408             :                                                         width:(NSUInteger)width
     409             :                                                    height:(NSUInteger)height
     410             :                                                  rowBytes:(NSUInteger)rowBytes;
     411           0 : - (void) dumpRGBAToRGBFileNamed:(NSString *)rgbName
     412             :                            andGrayFileNamed:(NSString *)grayName
     413             :                                                   bytes:(uint8_t *)bytes
     414             :                                                   width:(NSUInteger)width
     415             :                                                  height:(NSUInteger)height
     416             :                                            rowBytes:(NSUInteger)rowBytes;
     417             : #endif
     418             : 
     419             : @end

Generated by: LCOV version 1.14