Line data Source code
1 0 : /* 2 : 3 : GuiDisplayGen.h 4 : 5 : Class handling interface elements, primarily text, that are not part of the 3D 6 : game world, together with GuiDisplayGen. 7 : 8 : Oolite 9 : Copyright (C) 2004-2013 Giles C Williams and contributors 10 : 11 : This program is free software; you can redistribute it and/or 12 : modify it under the terms of the GNU General Public License 13 : as published by the Free Software Foundation; either version 2 14 : of the License, or (at your option) any later version. 15 : 16 : This program is distributed in the hope that it will be useful, 17 : but WITHOUT ANY WARRANTY; without even the implied warranty of 18 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 : GNU General Public License for more details. 20 : 21 : You should have received a copy of the GNU General Public License 22 : along with this program; if not, write to the Free Software 23 : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 24 : MA 02110-1301, USA. 25 : 26 : */ 27 : 28 : #import "OOCocoa.h" 29 : #import "OOMaths.h" 30 : #import "OOTypes.h" 31 : #include <jsapi.h> 32 : 33 : 34 0 : #define GUI_DEFAULT_COLUMNS 6 35 0 : #define GUI_DEFAULT_ROWS 30 36 : 37 0 : #define GUI_MAX_ROWS 64 38 0 : #define GUI_MAX_COLUMNS 40 39 0 : #define MAIN_GUI_PIXEL_HEIGHT 480 40 0 : #define MAIN_GUI_PIXEL_WIDTH 480 41 0 : #define MAIN_GUI_ROW_HEIGHT 16 42 0 : #define MAIN_GUI_ROW_WIDTH 16 43 0 : #define MAIN_GUI_PIXEL_ROW_START 40 44 : 45 : 46 0 : typedef enum 47 : { 48 : GUI_ALIGN_LEFT, 49 : GUI_ALIGN_RIGHT, 50 : GUI_ALIGN_CENTER 51 : } OOGUIAlignment; 52 : 53 0 : typedef enum 54 : { 55 : GUI_BACKGROUND_SPECIAL_NONE, 56 : GUI_BACKGROUND_SPECIAL_CUSTOM, 57 : GUI_BACKGROUND_SPECIAL_CUSTOM_ANA_SHORTEST, 58 : GUI_BACKGROUND_SPECIAL_CUSTOM_ANA_QUICKEST, 59 : GUI_BACKGROUND_SPECIAL_SHORT, 60 : GUI_BACKGROUND_SPECIAL_SHORT_ANA_SHORTEST, 61 : GUI_BACKGROUND_SPECIAL_SHORT_ANA_QUICKEST, 62 : GUI_BACKGROUND_SPECIAL_LONG, 63 : GUI_BACKGROUND_SPECIAL_LONG_ANA_SHORTEST, 64 : GUI_BACKGROUND_SPECIAL_LONG_ANA_QUICKEST 65 : } OOGUIBackgroundSpecial; 66 : 67 0 : #define GUI_KEY_OK @"OK" 68 0 : #define GUI_KEY_SKIP @"SKIP-ROW" 69 : 70 : // globals 71 0 : static NSString * const kGuiDefaultTextColor = @"default_text_color"; 72 0 : static NSString * const kGuiScreenTitleColor = @"screen_title_color"; 73 0 : static NSString * const kGuiScreenDividerColor = @"screen_divider_color"; 74 0 : static NSString * const kGuiSelectedRowBackgroundColor = @"selected_row_background_color"; 75 0 : static NSString * const kGuiSelectedRowColor = @"selected_row_color"; 76 0 : static NSString * const kGuiTextInputCursorColor = @"text_input_cursor_color"; 77 : // F3 78 0 : static NSString * const kGuiEquipmentCashColor = @"equipment_cash_color"; 79 0 : static NSString * const kGuiEquipmentUnavailableColor = @"equipment_unavailable_color"; 80 0 : static NSString * const kGuiEquipmentScrollColor = @"equipment_scroll_color"; 81 0 : static NSString * const kGuiEquipmentOptionColor = @"equipment_option_color"; 82 0 : static NSString * const kGuiEquipmentRepairColor = @"equipment_repair_color"; 83 0 : static NSString * const kGuiEquipmentDescriptionColor = @"equipment_description_color"; 84 0 : static NSString * const kGuiEquipmentLaserColor = @"equipment_laser_color"; 85 0 : static NSString * const kGuiEquipmentLaserFittedColor = @"equipment_laser_fitted_color"; 86 0 : static NSString * const kGuiEquipmentTabs = @"equipment_tabs"; 87 : // F3 F3 88 0 : static NSString * const kGuiShipyardHeadingColor = @"shipyard_heading_color"; 89 0 : static NSString * const kGuiShipyardScrollColor = @"shipyard_scroll_color"; 90 0 : static NSString * const kGuiShipyardEntryColor = @"shipyard_entry_color"; 91 0 : static NSString * const kGuiShipyardNoshipColor = @"shipyard_noship_color"; 92 0 : static NSString * const kGuiShipyardTradeinColor = @"shipyard_tradein_color"; 93 0 : static NSString * const kGuiShipyardDescriptionColor = @"shipyard_description_color"; 94 0 : static NSString * const kGuiShipyardTabs = @"shipyard_tabs"; 95 : // F4 96 0 : static NSString * const kGuiInterfaceHeadingColor = @"interface_heading_color"; 97 0 : static NSString * const kGuiInterfaceScrollColor = @"interface_scroll_color"; 98 0 : static NSString * const kGuiInterfaceEntryColor = @"interface_entry_color"; 99 0 : static NSString * const kGuiInterfaceDescriptionColor = @"interface_description_color"; 100 0 : static NSString * const kGuiInterfaceNoneColor = @"interface_none_color"; 101 0 : static NSString * const kGuiInterfaceTabs = @"interface_tabs"; 102 : // F5 103 0 : static NSString * const kGuiStatusShipnameColor = @"status_shipname_color"; 104 0 : static NSString * const kGuiStatusDataColor = @"status_data_color"; 105 0 : static NSString * const kGuiStatusEquipmentHeadingColor = @"status_equipment_heading_color"; 106 0 : static NSString * const kGuiStatusEquipmentScrollColor = @"status_equipment_scroll_color"; 107 0 : static NSString * const kGuiStatusEquipmentOkColor = @"status_equipment_ok_color"; 108 0 : static NSString * const kGuiStatusEquipmentDamagedColor = @"status_equipment_damaged_color"; 109 0 : static NSString * const kGuiStatusTabs = @"status_tabs"; 110 0 : static NSString * const kGuiStatusPrioritiseDamaged = @"status_prioritise_damaged"; 111 : // F5 F5 112 0 : static NSString * const kGuiManifestSubheadColor = @"manifest_subhead_color"; 113 0 : static NSString * const kGuiManifestEntryColor = @"manifest_entry_color"; 114 0 : static NSString * const kGuiManifestScrollColor = @"manifest_scroll_color"; 115 0 : static NSString * const kGuiManifestNoScrollColor = @"manifest_no_scroll_color"; 116 0 : static NSString * const kGuiManifestTabs = @"manifest_tabs"; 117 : // F6 118 0 : static NSString * const kGuiChartLabelScale = @"chart_label_scale"; 119 0 : static NSString * const kGuiChartCircleScale = @"chart_circle_scale"; 120 0 : static NSString * const kGuiChartLabelColor = @"chart_label_color"; 121 0 : static NSString * const kGuiChartLabelReachableColor = @"chart_labelreachable_color"; 122 0 : static NSString * const kGuiChartRangeColor = @"chart_range_color"; 123 0 : static NSString * const kGuiChartCrosshairColor = @"chart_crosshair_color"; 124 0 : static NSString * const kGuiChartCursorColor = @"chart_cursor_color"; 125 0 : static NSString * const kGuiChartInfoMarkerColor = @"chart_info_marker_color"; 126 0 : static NSString * const kGuiChartMatchBoxColor = @"chart_match_box_color"; 127 0 : static NSString * const kGuiChartMatchLabelColor = @"chart_match_label_color"; 128 0 : static NSString * const kGuiChartConnectionColor = @"chart_connection_color"; 129 0 : static NSString * const kGuiChartCurrentJumpStartColor = @"chart_currentjumpstart_color"; 130 0 : static NSString * const kGuiChartCurrentJumpEndColor = @"chart_currentjumpend_color"; 131 0 : static NSString * const kGuiChartRouteShortColor = @"chart_route_short_color"; 132 0 : static NSString * const kGuiChartRouteQuickColor = @"chart_route_quick_color"; 133 0 : static NSString * const kGuiChartTraveltimeTabs = @"chart_traveltime_tabs"; 134 : 135 0 : static NSString * const kGuiChartEconomyUColor = @"chart_economy_%lu_color"; 136 0 : static NSString * const kGuiChartGovernmentUColor = @"chart_government_%lu_color"; 137 0 : static NSString * const kGuiChartTechColor = @"chart_tech_color"; 138 : // F7 139 0 : static NSString * const kGuiSystemdataFactsColor = @"systemdata_facts_color"; 140 0 : static NSString * const kGuiSystemdataDescriptionColor = @"systemdata_description_color"; 141 0 : static NSString * const kGuiSystemdataTabs = @"systemdata_tabs"; 142 : // F8 143 0 : static NSString * const kGuiMarketHeadingColor = @"market_heading_color"; 144 0 : static NSString * const kGuiMarketCommodityColor = @"market_commodity_color"; 145 0 : static NSString * const kGuiMarketScrollColor = @"market_scroll_color"; 146 0 : static NSString * const kGuiMarketFilteredAllColor = @"market_filtered_all_color"; 147 0 : static NSString * const kGuiMarketFilterInfoColor = @"market_filter_info_color"; 148 0 : static NSString * const kGuiMarketCashColor = @"market_cash_color"; 149 : // F8 F8 extras 150 0 : static NSString * const kGuiMarketContractedColor = @"market_contracted_color"; 151 0 : static NSString * const kGuiMarketDescriptionColor = @"market_description_color"; 152 0 : static NSString * const kGuiMarketTabs = @"market_tabs"; 153 : // Docking report 154 0 : static NSString * const kGuiDockingReportColor = @"docking_report_color"; 155 0 : static NSString * const kGuiDockingSummaryColor = @"docking_summary_color"; 156 0 : static NSString * const kGuiDockingContinueColor = @"docking_continue_color"; 157 : 158 : 159 : 160 : @class OOSound, OOColor, OOTexture, OOTextureSprite, HeadUpDisplay; 161 : 162 : 163 0 : typedef NSInteger OOGUIRow; // -1 for none 164 0 : typedef NSInteger OOGUITabStop; // negative value = right align text 165 0 : typedef OOGUITabStop OOGUITabSettings[GUI_MAX_COLUMNS]; 166 : 167 : 168 0 : @interface GuiDisplayGen: NSObject 169 : { 170 : @private 171 0 : NSSize size_in_pixels; 172 0 : unsigned n_columns; 173 0 : unsigned n_rows; 174 0 : int pixel_row_center; 175 0 : unsigned pixel_row_height; 176 0 : int pixel_row_start; 177 0 : NSSize pixel_text_size; 178 : 179 0 : BOOL showAdvancedNavArray; 180 : 181 0 : NSSize pixel_title_size; 182 : 183 0 : OOColor *backgroundColor; 184 0 : OOColor *textColor; 185 0 : OOColor *textCommsColor; 186 : 187 0 : OOTextureSprite *backgroundSprite; 188 0 : OOTextureSprite *foregroundSprite; 189 0 : OOGUIBackgroundSpecial backgroundSpecial; 190 : 191 0 : NSString *title; 192 : 193 0 : NSMutableArray *rowText; 194 0 : NSMutableArray *rowKey; 195 0 : NSMutableArray *rowColor; 196 : 197 0 : Vector drawPosition; 198 : 199 0 : NSPoint rowPosition[GUI_MAX_ROWS]; 200 0 : OOGUIAlignment rowAlignment[GUI_MAX_ROWS]; 201 0 : float rowFadeTime[GUI_MAX_ROWS]; 202 : 203 0 : OOGUITabSettings tabStops; 204 : 205 0 : NSDictionary *guiUserSettings; 206 : 207 0 : NSRange rowRange; 208 : 209 0 : OOGUIRow selectedRow; 210 0 : NSRange selectableRange; 211 : 212 0 : BOOL showTextCursor; 213 0 : OOGUIRow currentRow; 214 : 215 0 : GLfloat max_alpha; // main alpha setting 216 0 : GLfloat fade_alpha; // for fade-in / fade-out 217 0 : GLfloat fade_sign; // -1.0 to 1.0 218 0 : NSUInteger statusPage; // status screen: paging equipped items 219 0 : OOSystemID foundSystem; 220 : } 221 : 222 0 : - (id) init; 223 0 : - (id) initWithPixelSize:(NSSize)gui_size 224 : columns:(int)gui_cols 225 : rows:(int)gui_rows 226 : rowHeight:(int)gui_row_height 227 : rowStart:(int)gui_row_start 228 : title:(NSString*)gui_title; 229 : 230 0 : - (void) resizeWithPixelSize:(NSSize)gui_size 231 : columns:(int)gui_cols 232 : rows:(int)gui_rows 233 : rowHeight:(int)gui_row_height 234 : rowStart:(int)gui_row_start 235 : title:(NSString*) gui_title; 236 0 : - (void) resizeTo:(NSSize)gui_size 237 : characterHeight:(int)csize 238 : title:(NSString*)gui_title; 239 0 : - (NSSize)size; 240 0 : - (unsigned)columns; 241 0 : - (unsigned)rows; 242 0 : - (unsigned)rowHeight; 243 0 : - (int)rowStart; 244 : 245 0 : - (NSString *)title; 246 0 : - (void) setTitle:(NSString *)str; 247 : 248 0 : - (void) dealloc; 249 : 250 0 : - (void) setDrawPosition:(Vector) vector; 251 0 : - (Vector) drawPosition; 252 : 253 0 : - (NSDictionary *) userSettings; 254 : 255 0 : - (void) fadeOutFromTime:(OOTimeAbsolute) now_time overDuration:(OOTimeDelta) duration; 256 0 : - (void) stopFadeOuts; 257 : 258 0 : - (GLfloat) alpha; 259 0 : - (void) setAlpha:(GLfloat) an_alpha; 260 0 : - (void) setMaxAlpha:(GLfloat) an_alpha; 261 : 262 0 : - (void) setBackgroundColor:(OOColor*) color; 263 : 264 0 : - (OOColor *) textColor; 265 0 : - (void) setTextColor:(OOColor*) color; 266 0 : - (OOColor *) textCommsColor; 267 0 : - (void) setTextCommsColor:(OOColor*) color; 268 0 : - (OOColor *) colorFromSetting:(NSString *)setting defaultValue:(OOColor *)def; 269 0 : - (void) setGLColorFromSetting:(NSString *)setting defaultValue:(OOColor *)def alpha:(GLfloat)alpha; 270 0 : - (void) setGuiColorSettingFromKey:(NSString *) key color:(OOColor *)col; 271 : 272 0 : - (void) setCharacterSize:(NSSize) character_size; 273 : 274 0 : - (void) setShowAdvancedNavArray:(BOOL)inFlag; 275 : 276 0 : - (void) setColor:(OOColor *)color forRow:(OOGUIRow)row; 277 : 278 0 : - (id) objectForRow:(OOGUIRow)row; 279 0 : - (NSString *) keyForRow:(OOGUIRow)row; 280 0 : - (OOGUIRow) rowForKey:(NSString*)key; 281 0 : - (OOGUIRow) selectedRow; 282 0 : - (BOOL) setSelectedRow:(OOGUIRow)row; 283 0 : - (BOOL) setNextRow:(int) direction; 284 0 : - (BOOL) setFirstSelectableRow; 285 0 : - (BOOL) setLastSelectableRow; 286 0 : - (void) setNoSelectedRow; 287 0 : - (NSString *) selectedRowText; 288 0 : - (NSString *) selectedRowKey; 289 : 290 0 : - (void) setShowTextCursor:(BOOL) yesno; 291 0 : - (void) setCurrentRow:(OOGUIRow) value; 292 : 293 0 : - (NSRange) selectableRange; 294 0 : - (void) setSelectableRange:(NSRange) range; 295 : 296 0 : - (void) setTabStops:(OOGUITabSettings)stops; 297 0 : - (void) overrideTabs:(OOGUITabSettings)stops from:(NSString *)setting length:(NSUInteger)len; 298 : 299 : 300 0 : - (void) clear; 301 0 : - (void) clearAndKeepBackground:(BOOL)keepBackground; 302 : 303 0 : - (void) setKey:(NSString *)str forRow:(OOGUIRow)row; 304 0 : - (void) setText:(NSString *)str forRow:(OOGUIRow)row; 305 0 : - (void) setText:(NSString *)str forRow:(OOGUIRow)row align:(OOGUIAlignment)alignment; 306 0 : - (NSString *) reflowTextForMFD:(NSString *)input; 307 0 : - (OOGUIRow) addLongText:(NSString *)str 308 : startingAtRow:(OOGUIRow)row 309 : align:(OOGUIAlignment)alignment; 310 0 : - (void) printLongText:(NSString *)str 311 : align:(OOGUIAlignment)alignment 312 : color:(OOColor *)text_color 313 : fadeTime:(float)text_fade 314 : key:(NSString *)text_key 315 : addToArray:(NSMutableArray *)text_array; 316 0 : - (void) printLineNoScroll:(NSString *)str 317 : align:(OOGUIAlignment)alignment 318 : color:(OOColor *)text_color 319 : fadeTime:(float)text_fade 320 : key:(NSString *)text_key 321 : addToArray:(NSMutableArray *)text_array; 322 : 323 0 : - (void) setArray:(NSArray *)arr forRow:(OOGUIRow)row; 324 : 325 0 : - (void) insertItemsFromArray:(NSArray *)items 326 : withKeys:(NSArray *)item_keys 327 : intoRow:(OOGUIRow)row 328 : color:(OOColor *)text_color; 329 : 330 : ///////////////////////////////////////////////////// 331 : 332 0 : - (void) scrollUp:(int) how_much; 333 : 334 : /* allows the use of special dynamic backgrounds */ 335 0 : - (void) setBackgroundTextureSpecial:(OOGUIBackgroundSpecial)spec withBackground:(BOOL)withBackground; 336 : 337 : /* 338 : A background/foreground texture descriptor is a dictionary with a string 339 : property keyed "name" and optional number properties keyed "width" and 340 : "height". 341 : */ 342 : 343 0 : - (BOOL) setBackgroundTextureDescriptor:(NSDictionary *)descriptor; 344 0 : - (BOOL) setForegroundTextureDescriptor:(NSDictionary *)descriptor; 345 0 : - (BOOL) setBackgroundTextureKey:(NSString *)key; 346 0 : - (BOOL) setForegroundTextureKey:(NSString *)key; 347 : 348 0 : - (BOOL) preloadGUITexture:(NSDictionary *)descriptor; 349 : 350 : /* 351 : Interpret a JavaScript value as a texture descriptor for 352 : -[GUIDisplayGen set{Background|Foreground}TextureDescriptor:]. Also starts 353 : preloading the texture. 354 : 355 : callerDescription is a string describing the context in which this was 356 : called, generally a method name (like "mission.runScreen()") for warning 357 : generation. 358 : 359 : Requires a request on context. 360 : */ 361 0 : - (NSDictionary *) textureDescriptorFromJSValue:(jsval)value inContext:(JSContext *)context callerDescription:(NSString *)callerDescription; 362 : 363 0 : - (void) clearBackground; 364 : 365 0 : - (void) leaveLastLine; 366 0 : - (NSArray *) getLastLines; 367 : 368 0 : - (int) drawGUI:(GLfloat) alpha drawCursor:(BOOL) drawCursor; 369 0 : - (void) drawGUIBackground; 370 0 : - (void) setStatusPage:(NSInteger) pageNum; 371 0 : - (NSUInteger) statusPage; 372 0 : - (void) refreshStarChart; 373 0 : - (void) setStarChartTitle; 374 : 375 0 : - (OOSystemID) targetNextFoundSystem:(int)direction; 376 : 377 : @end