LCOV - code coverage report
Current view: top level - Core - HeadUpDisplay.h (source / functions) Hit Total Coverage
Test: coverxygen.info Lines: 0 247 0.0 %
Date: 2025-05-28 07:50:54 Functions: 0 0 -

          Line data    Source code
       1           0 : /*
       2             : 
       3             : HeadUpDisplay.h
       4             : 
       5             : Class handling the player ship’s heads-up display, and 2D drawing functions.
       6             : 
       7             : Oolite
       8             : Copyright (C) 2004-2013 Giles C Williams and contributors
       9             : 
      10             : This program is free software; you can redistribute it and/or
      11             : modify it under the terms of the GNU General Public License
      12             : as published by the Free Software Foundation; either version 2
      13             : of the License, or (at your option) any later version.
      14             : 
      15             : This program is distributed in the hope that it will be useful,
      16             : but WITHOUT ANY WARRANTY; without even the implied warranty of
      17             : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      18             : GNU General Public License for more details.
      19             : 
      20             : You should have received a copy of the GNU General Public License
      21             : along with this program; if not, write to the Free Software
      22             : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
      23             : MA 02110-1301, USA.
      24             : 
      25             : */
      26             : 
      27             : #import "OOCocoa.h"
      28             : #import "OOOpenGL.h"
      29             : 
      30             : #import "OOTypes.h"
      31             : #import "OOMaths.h"
      32             : #import "MyOpenGLView.h"
      33             : #import "ShipEntity.h"
      34             : 
      35             : @class OOCrosshairs, OOColor;
      36             : 
      37             : @protocol OOHUDBeaconIcon;
      38             : 
      39             : 
      40           0 : #define SCANNER_CENTRE_X        0
      41           0 : #define SCANNER_CENTRE_Y        -180
      42           0 : #define SCANNER_SCALE           256
      43           0 : #define SCANNER_WIDTH           288
      44           0 : #define SCANNER_HEIGHT          72
      45             : 
      46           0 : #define SCANNER_MAX_ZOOM                        5.0
      47           0 : #define SCANNER_ZOOM_LEVELS                     5
      48           0 : #define ZOOM_INDICATOR_CENTRE_X         108
      49           0 : #define ZOOM_INDICATOR_CENTRE_Y         -216
      50           0 : #define ZOOM_INDICATOR_WIDTH            11.0f
      51           0 : #define ZOOM_INDICATOR_HEIGHT           14.0f
      52           0 : #define ZOOM_LEVELS_IMAGE                       @"zoom.png"
      53             : 
      54           0 : #define COMPASS_IMAGE                   @"compass.png"
      55           0 : #define COMPASS_CENTRE_X                132
      56           0 : #define COMPASS_CENTRE_Y                -216
      57           0 : #define COMPASS_SIZE                    56
      58           0 : #define COMPASS_HALF_SIZE               28
      59           0 : #define COMPASS_REDDOT_IMAGE    @"reddot.png"
      60           0 : #define COMPASS_GREENDOT_IMAGE  @"greendot.png"
      61           0 : #define COMPASS_DOT_SIZE                16
      62           0 : #define COMPASS_HALF_DOT_SIZE   8
      63             : 
      64           0 : #define AEGIS_IMAGE                             @"aegis.png"
      65           0 : #define AEGIS_CENTRE_X                  -132
      66           0 : #define AEGIS_CENTRE_Y                  -216
      67           0 : #define AEGIS_WIDTH                             24
      68           0 : #define AEGIS_HEIGHT                    24
      69             : 
      70           0 : #define SPEED_BAR_CENTRE_X              200
      71           0 : #define SPEED_BAR_CENTRE_Y              -145
      72           0 : #define SPEED_BAR_WIDTH                 80
      73           0 : #define SPEED_BAR_HEIGHT                8
      74           0 : #define SPEED_BAR_DRAW_SURROUND YES
      75             : 
      76           0 : #define ROLL_BAR_CENTRE_X               200
      77           0 : #define ROLL_BAR_CENTRE_Y               -160
      78           0 : #define ROLL_BAR_WIDTH                  80
      79           0 : #define ROLL_BAR_HEIGHT                 8
      80           0 : #define ROLL_BAR_DRAW_SURROUND  YES
      81             : 
      82           0 : #define PITCH_BAR_CENTRE_X              200
      83           0 : #define PITCH_BAR_CENTRE_Y              -170
      84           0 : #define PITCH_BAR_WIDTH                 80
      85           0 : #define PITCH_BAR_HEIGHT                8
      86           0 : #define PITCH_BAR_DRAW_SURROUND YES
      87             : 
      88           0 : #define ENERGY_GAUGE_CENTRE_X           200
      89           0 : #define ENERGY_GAUGE_CENTRE_Y           -205
      90           0 : #define ENERGY_GAUGE_WIDTH                      80
      91           0 : #define ENERGY_GAUGE_HEIGHT                     48
      92           0 : #define ENERGY_GAUGE_DRAW_SURROUND      YES
      93             : 
      94           0 : #define FORWARD_SHIELD_BAR_CENTRE_X                     -200
      95           0 : #define FORWARD_SHIELD_BAR_CENTRE_Y                     -146
      96           0 : #define FORWARD_SHIELD_BAR_WIDTH                        80
      97           0 : #define FORWARD_SHIELD_BAR_HEIGHT                       8
      98           0 : #define FORWARD_SHIELD_BAR_DRAW_SURROUND        YES
      99             : 
     100           0 : #define AFT_SHIELD_BAR_CENTRE_X                 -200
     101           0 : #define AFT_SHIELD_BAR_CENTRE_Y                 -162
     102           0 : #define AFT_SHIELD_BAR_WIDTH                    80
     103           0 : #define AFT_SHIELD_BAR_HEIGHT                   8
     104           0 : #define AFT_SHIELD_BAR_DRAW_SURROUND    YES
     105             : 
     106           0 : #define FUEL_BAR_CENTRE_X                       -200
     107           0 : #define FUEL_BAR_CENTRE_Y                       -179
     108           0 : #define FUEL_BAR_WIDTH                          80
     109           0 : #define FUEL_BAR_HEIGHT                         8
     110             : 
     111           0 : #define WITCHDEST_CENTRE_X                      -200
     112           0 : #define WITCHDEST_CENTRE_Y                      -179
     113           0 : #define WITCHDEST_WIDTH                         80
     114           0 : #define WITCHDEST_HEIGHT                                8
     115             : 
     116           0 : #define CABIN_TEMP_BAR_CENTRE_X         -200
     117           0 : #define CABIN_TEMP_BAR_CENTRE_Y         -189
     118           0 : #define CABIN_TEMP_BAR_WIDTH            80
     119           0 : #define CABIN_TEMP_BAR_HEIGHT           8
     120             : 
     121           0 : #define WEAPON_TEMP_BAR_CENTRE_X        -200
     122           0 : #define WEAPON_TEMP_BAR_CENTRE_Y        -199
     123           0 : #define WEAPON_TEMP_BAR_WIDTH           80
     124           0 : #define WEAPON_TEMP_BAR_HEIGHT          8
     125             : 
     126           0 : #define ALTITUDE_BAR_CENTRE_X           -200
     127           0 : #define ALTITUDE_BAR_CENTRE_Y           -209
     128           0 : #define ALTITUDE_BAR_WIDTH                      80
     129           0 : #define ALTITUDE_BAR_HEIGHT                     8
     130             : 
     131           0 : #define MISSILES_DISPLAY_X                      -228
     132           0 : #define MISSILES_DISPLAY_Y                      -224
     133           0 : #define MISSILES_DISPLAY_SPACING        16
     134           0 : #define MISSILE_ICON_WIDTH                      12
     135           0 : #define MISSILE_ICON_HEIGHT                     MISSILE_ICON_WIDTH
     136             : 
     137           0 : #define PRIMED_DISPLAY_X                                -144
     138           0 : #define PRIMED_DISPLAY_Y                                -256
     139           0 : #define PRIMED_DISPLAY_WIDTH                    12
     140           0 : #define PRIMED_DISPLAY_HEIGHT           12
     141             : 
     142           0 : #define ASCTARGET_DISPLAY_X                             64
     143           0 : #define ASCTARGET_DISPLAY_Y                             -234
     144           0 : #define ASCTARGET_DISPLAY_WIDTH                 10
     145           0 : #define ASCTARGET_DISPLAY_HEIGHT                10
     146             : 
     147           0 : #define CLOCK_DISPLAY_X                         -44
     148           0 : #define CLOCK_DISPLAY_Y                         -234
     149           0 : #define CLOCK_DISPLAY_WIDTH                     12
     150           0 : #define CLOCK_DISPLAY_HEIGHT            12
     151             : 
     152           0 : #define WEAPONSOFFLINETEXT_DISPLAY_X    -175
     153           0 : #define WEAPONSOFFLINETEXT_DISPLAY_Y    2
     154           0 : #define WEAPONSOFFLINETEXT_WIDTH        8
     155           0 : #define WEAPONSOFFLINETEXT_HEIGHT       8
     156             : 
     157           0 : #define FPSINFO_DISPLAY_X                       -300
     158           0 : #define FPSINFO_DISPLAY_Y                       220
     159           0 : #define FPSINFO_DISPLAY_WIDTH           12
     160           0 : #define FPSINFO_DISPLAY_HEIGHT          12
     161             : 
     162           0 : #define STATUS_LIGHT_CENTRE_X           -108
     163           0 : #define STATUS_LIGHT_CENTRE_Y           -216
     164           0 : #define STATUS_LIGHT_WIDTH                      8
     165           0 : #define STATUS_LIGHT_HEIGHT                     8
     166             : 
     167           0 : #define HIT_INDICATOR_CENTRE_X          200
     168           0 : #define HIT_INDICATOR_CENTRE_Y          0
     169             : 
     170           0 : #define SCOOPSTATUS_CENTRE_X            -132
     171           0 : #define SCOOPSTATUS_CENTRE_Y            -152
     172           0 : #define SCOOPSTATUS_WIDTH                       16.0
     173           0 : #define SCOOPSTATUS_HEIGHT                      16.0
     174             : 
     175           0 : #define MFD_TEXT_WIDTH                  10
     176           0 : #define MFD_TEXT_HEIGHT                 10
     177             : 
     178           0 : #define DIALS_KEY                               @"dials"
     179           0 : #define LEGENDS_KEY                             @"legends"
     180           0 : #define MFDS_KEY                                @"multi_function_displays"
     181           0 : #define X_KEY                                   @"x"
     182           0 : #define Y_KEY                                   @"y"
     183           0 : #define X_ORIGIN_KEY                    @"x_origin"
     184           0 : #define Y_ORIGIN_KEY                    @"y_origin"
     185           0 : #define SPACING_KEY                             @"spacing"
     186           0 : #define ALPHA_KEY                               @"alpha"
     187           0 : #define SELECTOR_KEY                    @"selector"
     188           0 : #define IMAGE_KEY                               @"image"
     189           0 : #define WIDTH_KEY                               @"width"
     190           0 : #define HEIGHT_KEY                              @"height"
     191           0 : #define SPRITE_KEY                              @"sprite"
     192           0 : #define DRAW_SURROUND_KEY               @"draw_surround"
     193           0 : #define EQUIPMENT_REQUIRED_KEY  @"equipment_required"
     194           0 : #define ALERT_CONDITIONS_KEY    @"alert_conditions"
     195           0 : #define VIEWSCREEN_KEY                  @"viewscreen_only"
     196           0 : #define DIAL_REQUIRED_KEY               @"with_dial"
     197           0 : #define LABELLED_KEY                    @"labelled"
     198           0 : #define TEXT_KEY                                @"text"
     199           0 : #define RGB_COLOR_KEY                   @"rgb_color"
     200           0 : #define COLOR_KEY                               @"color"
     201           0 : #define COLOR_KEY_LOW                   @"color_low"
     202           0 : #define COLOR_KEY_MEDIUM                @"color_medium"
     203           0 : #define COLOR_KEY_HIGH                  @"color_high"
     204           0 : #define COLOR_KEY_CRITICAL              @"color_critical"
     205           0 : #define COLOR_KEY_SURROUND              @"color_surround"
     206           0 : #define N_BARS_KEY                              @"n_bars"
     207           0 : #define CUSTOM_DIAL_KEY                 @"data_source"
     208             : 
     209           0 : #define ROWS_KEY                                @"rows"
     210           0 : #define COLUMNS_KEY                             @"columns"
     211           0 : #define ROW_HEIGHT_KEY                  @"row_height"
     212           0 : #define ROW_START_KEY                   @"row_start"
     213           0 : #define TITLE_KEY                               @"title"
     214           0 : #define BACKGROUND_RGBA_KEY             @"background_rgba"
     215           0 : #define OVERALL_ALPHA_KEY               @"overall_alpha"
     216           0 : #define NONLINEAR_SCANNER               @"nonlinear_scanner"
     217             : 
     218           0 : #define Z1                                              [(MyOpenGLView *)[[player universe] gameView] display_z]
     219             : 
     220           0 : #define ONE_EIGHTH                              0.125
     221             : 
     222           0 : #define MAX_ACCURACY_RANGE                      7000   // 7.000km
     223           0 : #define ACCURACY_PROBABILITY_DECREASE_FACTOR    0.000035f   // for every 1000km decrease by 3.5% the chance of high accuracy
     224           0 : #define MIN_PROBABILITY_ACCURACY                0.35f   // floor value for probability of high accuracy is 35%
     225             : 
     226           0 : enum
     227             : {
     228             :         OO_RETICLE_COLOR_TARGET = 0,
     229             :         OO_RETICLE_COLOR_TARGET_SENSITIVE,
     230             :         OO_RETICLE_COLOR_WORMHOLE
     231             : };
     232             : 
     233             : 
     234             : @class Entity, PlayerEntity, OOTextureSprite;
     235             : 
     236             : 
     237           0 : @interface HeadUpDisplay: NSObject
     238             : {
     239             : @private
     240           0 :         NSMutableArray          *legendArray;
     241           0 :         NSMutableArray          *dialArray;
     242           0 :         NSMutableArray          *mfdArray;
     243             :         
     244             :         // zoom level
     245           0 :         GLfloat                         scanner_zoom;
     246             :         
     247             :         //where to draw it
     248           0 :         GLfloat                         z1;
     249           0 :         GLfloat                         lineWidth;
     250             :         
     251           0 :         NSString                        *hudName;
     252           0 :         NSString                        *deferredHudName;       // Usually it will be nil. If not nil, then it means that we have a deferred HUD waiting to be drawn This may happen
     253             :                                                                                         // for example when a script handler attempts to switch HUD while it is being rendered. - Nikos 20110628
     254           0 :         BOOL                            hudUpdating;
     255             :         
     256           0 :         GLfloat                         overallAlpha;
     257             :         
     258           0 :         BOOL                            reticleTargetSensitive;   // TO DO: Move this into the propertiesReticleTargetSensitive structure (Getafix - 2010/08/21)
     259           0 :         NSMutableDictionary *propertiesReticleTargetSensitive;
     260             :         
     261           0 :         BOOL                            cloakIndicatorOnStatusLight;
     262             :         
     263           0 :         BOOL                            hudHidden;
     264             :         
     265           0 :         BOOL                            allowBigGui;
     266             : 
     267           0 :         int                                     last_transmitter;
     268             : 
     269           0 :         NSMutableSet            *_hiddenSelectors;
     270             :         
     271             :         // Crosshairs
     272           0 :         OOCrosshairs            *_crosshairs;
     273           0 :         OOWeaponType            _lastWeaponType;
     274           0 :         GLfloat                         _lastOverallAlpha;
     275           0 :         BOOL                            _lastWeaponsOnline;
     276           0 :         NSDictionary            *_crosshairOverrides;
     277           0 :         OOColor                         *_crosshairColor;
     278           0 :         GLfloat                         _crosshairScale;
     279           0 :         GLfloat                         _crosshairWidth;
     280           0 :         NSString                        *crosshairDefinition;
     281           0 :         BOOL                            _compassActive;
     282             :         
     283           0 :         NSMutableArray          *_reticleColors;
     284             :         
     285             :         // essentially scanner without gridlines
     286           0 :         BOOL                    minimalistic_scanner;
     287             :         
     288             :         // Nonlinear scanner
     289           0 :         BOOL                    nonlinear_scanner;
     290           0 :         BOOL                    scanner_ultra_zoom;
     291             : 
     292             : }
     293             : 
     294           0 : - (id) initWithDictionary:(NSDictionary *)hudinfo;
     295           0 : - (id) initWithDictionary:(NSDictionary *)hudinfo inFile:(NSString *)hudFileName;
     296             : 
     297           0 : - (void) resetGuis:(NSDictionary *)info;
     298           0 : - (void) resetGuiPositions;
     299             : 
     300           0 : - (NSString *) hudName;
     301           0 : - (void) setHudName:(NSString *)newHudName;
     302             : 
     303           0 : - (GLfloat) scannerZoom;
     304           0 : - (void) setScannerZoom:(GLfloat)value;
     305             : 
     306           0 : - (GLfloat) overallAlpha;
     307           0 : - (void) setOverallAlpha:(GLfloat)newAlphaValue;
     308             : 
     309           0 : - (BOOL) reticleTargetSensitive;
     310           0 : - (void) setReticleTargetSensitive:(BOOL)newReticleTargetSensitiveValue;
     311           0 : - (NSMutableDictionary *) propertiesReticleTargetSensitive;
     312             : 
     313           0 : - (BOOL) isHidden;
     314           0 : - (void) setHidden:(BOOL)newValue;
     315             : 
     316           0 : - (BOOL) allowBigGui;
     317             : 
     318           0 : - (BOOL) hasHidden:(NSString *)selectorName;
     319           0 : - (void) setHiddenSelector:(NSString *)selectorName hidden:(BOOL)hide;
     320           0 : - (void) clearHiddenSelectors;
     321             : 
     322           0 : - (BOOL) isCompassActive;
     323           0 : - (void) setCompassActive:(BOOL)newValue;
     324             : 
     325           0 : - (BOOL) isUpdating;
     326           0 : - (void) setDeferredHudName:(NSString *)newDeferredHudName;
     327           0 : - (NSString *) deferredHudName;
     328           0 : - (NSString *) crosshairDefinition;
     329           0 : - (BOOL) setCrosshairDefinition:(NSString *)newDefinition;
     330             : 
     331           0 : - (void) addLegend:(NSDictionary *)info;
     332           0 : - (void) addDial:(NSDictionary *)info;
     333           0 : - (void) addMFD:(NSDictionary *)info;
     334             : 
     335           0 : - (NSUInteger) mfdCount;
     336             : 
     337           0 : - (void) renderHUD;
     338             : 
     339           0 : - (void) refreshLastTransmitter;
     340             : 
     341           0 : - (void) setLineWidth:(GLfloat)value;
     342           0 : - (GLfloat) lineWidth;
     343             : 
     344           0 : - (BOOL) minimalisticScanner;
     345           0 : - (void) setMinimalisticScanner: (BOOL) newValue;
     346             : 
     347           0 : + (Vector) nonlinearScannerScale:(Vector) V Zoom:(GLfloat) zoom Scale:(double) scale;
     348           0 : - (BOOL) nonlinearScanner;
     349           0 : - (void) setNonlinearScanner: (BOOL)newValue;
     350             : 
     351           0 : - (BOOL) scannerUltraZoom;
     352           0 : - (void) setScannerUltraZoom: (BOOL)newValue;
     353             : 
     354           0 : - (OOColor *) reticleColorForIndex:(NSUInteger)idx;
     355           0 : - (BOOL) setReticleColorForIndex:(NSUInteger)idx toColor:(OOColor *)newColor;
     356             : 
     357             : @end
     358             : 
     359             : 
     360             : @interface NSString (OODisplayEncoding)
     361             : 
     362             : // Return a C string in the 8-bit encoding used for display.
     363           0 : - (const char *) cStringUsingOoliteEncoding;
     364             : 
     365             : // Return a C string in the 8-bit encoding used for display, with substitutions performed.
     366           0 : - (const char *) cStringUsingOoliteEncodingAndRemapping;
     367             : 
     368             : @end
     369             : 
     370             : 
     371             : /*
     372             :         Protocol for things that can be used as HUD compass items. Really ought
     373             :         to grow into a general protocol for HUD elements.
     374             : */
     375             : @protocol OOHUDBeaconIcon <NSObject>
     376             : 
     377           0 : - (void) oo_drawHUDBeaconIconAt:(NSPoint)where size:(NSSize)size alpha:(GLfloat)alpha z:(GLfloat)z;
     378             : 
     379             : @end
     380             : 
     381             : 
     382             : @interface NSString (OOHUDBeaconIcon) <OOHUDBeaconIcon>
     383             : @end
     384             : 
     385             : 
     386           0 : void OODrawString(NSString *text, GLfloat x, GLfloat y, GLfloat z, NSSize siz);
     387           0 : void OODrawStringAligned(NSString *text, GLfloat x, GLfloat y, GLfloat z, NSSize siz, BOOL rightAlign);
     388             : 
     389             : /* OODrawString(Aligned) handles all the string drawing, but because
     390             :  * it does texture application and GL_QUADS beginning once per string
     391             :  * it's quite slow.
     392             :  *
     393             :  * Where efficiency is needed, call OOStartDrawingStrings(), then
     394             :  * OODrawStringQuadsAligned for each bit of text, then
     395             :  * OOStopDrawingStrings().
     396             :  *
     397             :  * Trying to draw anything else between OOStartDrawingStrings() and
     398             :  * OOStopDrawingStrings() will have messy results. You can safely call
     399             :  * Stop, draw the other thing you want, then call Start again - it's
     400             :  * just a little inefficient. Similarly calling
     401             :  * OODrawStringQuadsAligned() without calling OOStartDrawingStrings()
     402             :  * won't work very well.
     403             :  *
     404             :  * - CIM
     405             :  */
     406           0 : void OOStartDrawingStrings(void);
     407           0 : void OODrawStringQuadsAligned(NSString *text, GLfloat x, GLfloat y, GLfloat z, NSSize siz, BOOL rightAlign);
     408           0 : void OOStopDrawingStrings(void);
     409             : 
     410             : 
     411             : 
     412           0 : void OODrawHilightedString(NSString *text, GLfloat x, GLfloat y, GLfloat z, NSSize siz);
     413           0 : void OODrawPlanetInfo(int gov, int eco, int tec, GLfloat x, GLfloat y, GLfloat z, NSSize siz);
     414           0 : void OODrawHilightedPlanetInfo(int gov, int eco, int tec, GLfloat x, GLfloat y, GLfloat z, NSSize siz);
     415           0 : NSRect OORectFromString(NSString *text, GLfloat x, GLfloat y, NSSize siz);
     416           0 : CGFloat OOStringWidthInEm(NSString *text);
     417             : 
     418           0 : void OOHUDResetTextEngine(void);

Generated by: LCOV version 1.14