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