LCOV - code coverage report
Current view: top level - SDL - MyOpenGLView.h (source / functions) Hit Total Coverage
Test: coverxygen.info Lines: 1 135 0.7 %
Date: 2025-05-28 07:50:54 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 : extern int debug;
     150             : 
     151             : @interface MyOpenGLView : NSObject
     152             : {
     153             :         GameController          *gameController;
     154             :         BOOL                            keys[NUM_KEYS];
     155             :         int                                     scancode2Unicode[NUM_KEYS];
     156             :         NSDictionary            *keyMappings_normal;
     157             :         NSDictionary            *keyMappings_shifted;
     158             : 
     159             :         BOOL                            suppressKeys;    // DJS
     160             : 
     161             :         BOOL                            opt, ctrl, command, shift, lastKeyShifted;
     162             :         BOOL                            allowingStringInput;
     163             :         BOOL                            isAlphabetKeyDown;
     164             : 
     165             :         int                                     keycodetrans[255];
     166             : 
     167             :         BOOL                            m_glContextInitialized;
     168           0 :     NSPoint                             mouseDragStartPoint;
     169             : 
     170           0 :         BOOL                            mouseWarped;
     171             : 
     172             :         NSTimeInterval          timeIntervalAtLastClick;
     173           0 :         NSTimeInterval          timeSinceLastMouseWheel;
     174             :         BOOL                            doubleClick;
     175             : 
     176             :         NSMutableString         *typedString;
     177             : 
     178             :         NSPoint                         virtualJoystickPosition;
     179             :         
     180           0 :         float                           _mouseVirtualStickSensitivityFactor;
     181             : 
     182             :         NSSize                          viewSize;
     183             :         GLfloat                         display_z;
     184             :         GLfloat                         x_offset, y_offset;
     185             : 
     186           0 :     double                              squareX,squareY;
     187           0 :         NSRect                          bounds;
     188             : 
     189           0 :         float                           _gamma;
     190             :         float                           _fov;
     191           0 :         BOOL                            _msaa;
     192             : 
     193             :    // Full screen sizes
     194           0 :         NSMutableArray          *screenSizes;
     195           0 :         int                                     currentSize;    //we need an int!
     196           0 :         BOOL                            fullScreen;
     197             : 
     198             :         // Windowed mode
     199           0 :         NSSize                          currentWindowSize;
     200           0 :         SDL_Surface                     *surface;
     201             : 
     202           0 :         BOOL                            showSplashScreen;
     203             : 
     204             : #if OOLITE_WINDOWS
     205             : 
     206             :         BOOL                            wasFullScreen;
     207             :         BOOL                            updateContext;
     208             :         BOOL                            saveSize;
     209             :         BOOL                            atDesktopResolution;
     210             :         unsigned                        keyboardMap; // *** FLAGGED for deletion 
     211             :         HWND                            SDL_Window;
     212             :         MONITORINFOEX           monitorInfo;
     213             :         RECT                            lastGoodRect;
     214             :         float                           _hdrMaxBrightness;
     215             :         float                           _hdrPaperWhiteBrightness;
     216             : 
     217             : #endif
     218             : 
     219           0 :         float                           _colorSaturation;
     220             :         
     221           0 :         BOOL                            _hdrOutput;
     222             : 
     223           0 :         BOOL                            grabMouseStatus;
     224             : 
     225           0 :         NSSize                          firstScreen;
     226             :         
     227             :         OOOpenGLMatrixManager           *matrixManager;
     228             : 
     229             :    // Mouse mode indicator (for mouse movement model)
     230           0 :    BOOL                                 mouseInDeltaMode;
     231             :    
     232             :    float                                _mouseWheelDelta;
     233             : }
     234             : 
     235             : /**
     236             :  * \ingroup cli
     237             :  * Scans the command line for -nosplash, --nosplash, -splash, --splash- -novsync and --novsync arguments.
     238             :  */
     239           1 : - (id) init;
     240             : 
     241           0 : - (void) initSplashScreen;
     242           0 : - (void) endSplashScreen;
     243           0 : - (void) autoShowMouse;
     244             : 
     245           0 : - (void) initKeyMappingData;
     246             : 
     247           0 : - (void) setStringInput: (enum StringInput) value;
     248           0 : - (void) allowStringInput: (BOOL) value;
     249           0 : - (enum StringInput) allowingStringInput;
     250           0 : - (NSString *) typedString;
     251           0 : - (void) resetTypedString;
     252           0 : - (void) setTypedString:(NSString*) value;
     253             : 
     254           0 : - (NSSize) viewSize;
     255           0 : - (NSSize) backingViewSize;
     256           0 : - (GLfloat) display_z;
     257           0 : - (GLfloat) x_offset;
     258           0 : - (GLfloat) y_offset;
     259             : 
     260           0 : - (GameController *) gameController;
     261           0 : - (void) setGameController:(GameController *) controller;
     262             : 
     263           0 : - (void) noteMouseInteractionModeChangedFrom:(OOMouseInteractionMode)oldMode to:(OOMouseInteractionMode)newMode;
     264             : 
     265           0 : - (void) initialiseGLWithSize:(NSSize) v_size;
     266           0 : - (void) initialiseGLWithSize:(NSSize) v_size useVideoMode:(BOOL) v_mode;
     267           0 : - (BOOL) isRunningOnPrimaryDisplayDevice;
     268             : #if OOLITE_WINDOWS
     269             : - (BOOL) getCurrentMonitorInfo:(MONITORINFOEX *)mInfo;
     270             : - (MONITORINFOEX) currentMonitorInfo;
     271             : - (void) refreshDarKOrLightMode;
     272             : - (BOOL) isDarkModeOn;
     273             : - (BOOL) atDesktopResolution;
     274             : - (float) hdrMaxBrightness;
     275             : - (void) setHDRMaxBrightness:(float)newMaxBrightness;
     276             : - (float) hdrPaperWhiteBrightness;
     277             : - (void) setHDRPaperWhiteBrightness:(float)newPaperWhiteBrightness;
     278             : #endif
     279           0 : - (float) colorSaturation;
     280           0 : - (void) adjustColorSaturation:(float)colorSaturationAdjustment;
     281           0 : - (BOOL) hdrOutput;
     282           0 : - (BOOL) isOutputDisplayHDREnabled;
     283             : 
     284           0 : - (void) grabMouseInsideGameWindow:(BOOL) value;
     285             : 
     286           0 : - (void) stringToClipboard:(NSString *)stringToCopy;
     287             : 
     288           0 : - (void) drawRect:(NSRect)rect;
     289           0 : - (void) updateScreen;
     290           0 : - (void) updateScreenWithVideoMode:(BOOL) v_mode;
     291           0 : - (void) display;
     292             : 
     293           0 : - (BOOL) snapShot:(NSString *)filename;
     294             : #if SNAPSHOTS_PNG_FORMAT
     295           0 : - (BOOL) pngSaveSurface:(NSString *)fileName withSurface:(SDL_Surface *)surf;
     296             : #endif
     297             : 
     298           0 : - (NSRect) bounds;
     299           0 : + (NSMutableDictionary *) getNativeSize;
     300             : 
     301           0 : - (void) setFullScreenMode:(BOOL)fsm;
     302           0 : - (BOOL) inFullScreenMode;
     303           0 : - (void) toggleScreenMode;
     304           0 : - (void) setDisplayMode:(int)mode fullScreen:(BOOL)fsm;
     305             : 
     306           0 : - (int) indexOfCurrentSize;
     307           0 : - (void) setScreenSize: (int)sizeIndex;
     308           0 : - (NSMutableArray *)getScreenSizeArray;
     309           0 : - (void) populateFullScreenModelist;
     310           0 : - (NSSize) modeAsSize: (int)sizeIndex;
     311           0 : - (void) saveWindowSize: (NSSize) windowSize;
     312           0 : - (NSSize) loadWindowSize;
     313           0 : - (int) loadFullscreenSettings;
     314           0 : - (int) findDisplayModeForWidth: (unsigned int) d_width Height:(unsigned int) d_height
     315             :                         Refresh: (unsigned int)d_refresh;
     316           0 : - (NSSize) currentScreenSize;
     317             : 
     318           0 : - (void) pollControls;
     319             : 
     320           0 : - (void) setVirtualJoystick:(double) vmx :(double) vmy;
     321           0 : - (NSPoint) virtualJoystickPosition;
     322             : 
     323           0 : - (void) clearKeys;
     324           0 : - (void) clearMouse;
     325           0 : - (void) clearKey: (int)theKey;
     326           0 : - (void) resetMouse;
     327           0 : - (BOOL) isAlphabetKeyDown;
     328           0 : - (void) suppressKeysUntilKeyUp; // DJS
     329           0 : - (BOOL) isDown: (int) key;
     330           0 : - (BOOL) isOptDown; // opt == alt key
     331           0 : - (BOOL) isCtrlDown;
     332           0 : - (BOOL) isCommandDown;
     333           0 : - (BOOL) isShiftDown;
     334           0 : - (BOOL) isCapsLockOn;
     335           0 : - (BOOL) lastKeyWasShifted;
     336           0 : - (int) numKeys;
     337           0 : - (int) mouseWheelState;
     338           0 : - (float) mouseWheelDelta;
     339           0 : - (void) setMouseWheelDelta: (float) newWheelDelta;
     340             : 
     341             : // Command-key combinations need special handling. SDL stubs for these mac functions.
     342           0 : - (BOOL) isCommandQDown;
     343           0 : - (BOOL) isCommandFDown;
     344           0 : - (void) clearCommandF;
     345             : 
     346           0 : - (void) setMouseInDeltaMode: (BOOL) inDelta;
     347             : 
     348           0 : - (void) setGammaValue: (float) value;
     349           0 : - (float) gammaValue;
     350             : 
     351           0 : - (void) setFov:(float)value fromFraction:(BOOL)fromFraction;
     352           0 : - (float) fov:(BOOL)inFraction;
     353             : 
     354           0 : - (void) setMsaa:(BOOL)newMsaa;
     355           0 : - (BOOL) msaa;
     356             : 
     357             : // Check current state of shift key rather than relying on last event.
     358           0 : + (BOOL)pollShiftKey;
     359             : 
     360           0 : - (OOOpenGLMatrixManager *) getOpenGLMatrixManager;
     361             : 
     362             : #ifndef NDEBUG
     363             : // General image-dumping method.
     364           0 : - (void) dumpRGBAToFileNamed:(NSString *)name
     365             :                                            bytes:(uint8_t *)bytes
     366             :                                            width:(NSUInteger)width
     367             :                                           height:(NSUInteger)height
     368             :                                         rowBytes:(NSUInteger)rowBytes;
     369           0 : - (void) dumpRGBToFileNamed:(NSString *)name
     370             :                                            bytes:(uint8_t *)bytes
     371             :                                            width:(NSUInteger)width
     372             :                                           height:(NSUInteger)height
     373             :                                         rowBytes:(NSUInteger)rowBytes;
     374           0 : - (void) dumpGrayToFileNamed:(NSString *)name
     375             :                                            bytes:(uint8_t *)bytes
     376             :                                            width:(NSUInteger)width
     377             :                                           height:(NSUInteger)height
     378             :                                         rowBytes:(NSUInteger)rowBytes;
     379           0 : - (void) dumpGrayAlphaToFileNamed:(NSString *)name
     380             :                                                         bytes:(uint8_t *)bytes
     381             :                                                         width:(NSUInteger)width
     382             :                                                    height:(NSUInteger)height
     383             :                                                  rowBytes:(NSUInteger)rowBytes;
     384           0 : - (void) dumpRGBAToRGBFileNamed:(NSString *)rgbName
     385             :                            andGrayFileNamed:(NSString *)grayName
     386             :                                                   bytes:(uint8_t *)bytes
     387             :                                                   width:(NSUInteger)width
     388             :                                                  height:(NSUInteger)height
     389             :                                            rowBytes:(NSUInteger)rowBytes;
     390             : #endif
     391             : 
     392             : @end

Generated by: LCOV version 1.14