1 #ifndef _SCREEN_H_
2 #define _SCREEN_H_
3 /*
4 SCREEN.H
5 
6 	Copyright (C) 1991-2001 and beyond by Bungie Studios, Inc.
7 	and the "Aleph One" developers.
8 
9 	This program is free software; you can redistribute it and/or modify
10 	it under the terms of the GNU General Public License as published by
11 	the Free Software Foundation; either version 3 of the License, or
12 	(at your option) any later version.
13 
14 	This program is distributed in the hope that it will be useful,
15 	but WITHOUT ANY WARRANTY; without even the implied warranty of
16 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 	GNU General Public License for more details.
18 
19 	This license is contained in the file "COPYING",
20 	which is included with this source code; it is available online at
21 	http://www.gnu.org/licenses/gpl.html
22 
23 Thursday, August 24, 1995 5:36:27 PM  (Jason)
24 
25 Feb 13, 2000 (Loren Petrich):
26 	Added screendump capability: dump_screen()
27 
28 Mar 5, 2000 (Loren Petrich):
29 	Added reset_screen() function,
30 	for the purpose of resetting its state when starting a game
31 
32 Mar 18, 2000 (Loren Petrich):
33 	Added OpenGL support, including OpenGL-acceleration mode
34 
35 Jun 15, 2000 (Loren Petrich):
36 	Added support for Chris Pruett's Pfhortran
37 
38 July 2, 2000 (Loren Petrich):
39 	Reversed the order of the screen-size symbolic constants, in preparation for really big
40 	screen sizes.
41 
42 	The HUD is now always buffered
43 
44 Jul 5, 2000 (Loren Petrich):
45 	Prepared for expanding the number of resolutions available
46 	by defining a number of view sizes
47 
48 Dec 2, 2000 (Loren Petrich):
49 	Added support for hiding and re-showing the app
50 
51 Mar 19, 2001 (Loren Petrich):
52 	Added some even bigger screen resolutions
53 
54 Sept 9, 2001 (Loren Petrich):
55 	Eliminated the Valkyrie-acceleration option once and for all;
56 	will take care of any side effects elsewhere in the code
57 
58 Jan 25, 2002 (Br'fin (Jeremy Parsons)):
59 	Included Steve Bytnar's OSX QDPort flushing code
60 */
61 
62 #include <utility>
63 #include <vector>
64 #include <SDL.h>
65 
66 struct Rect;
67 
68 struct screen_mode_data;
69 namespace alephone
70 {
71 	class Screen
72 	{
73 	public:
instance()74 		static inline Screen* instance() {
75 			return &m_instance;
76 		}
77 
78 		void Initialize(screen_mode_data* mode);
GetModes()79 		const std::vector<std::pair<int, int> >& GetModes() { return m_modes; };
FindMode(int width,int height)80 		int FindMode(int width, int height) {
81 			for (int i = 0; i < m_modes.size(); ++i)
82 			{
83 				if (m_modes[i].first == width &&
84 				    m_modes[i].second == height)
85 				{
86 					return i;
87 				}
88 			}
89 			return -1;
90 		}
ModeHeight(int mode)91 		int ModeHeight(int mode) { return m_modes[mode].second; }
ModeWidth(int mode)92 		int ModeWidth(int mode) { return m_modes[mode].first; }
93 
94 		int height();
95 		int width();
96 		float pixel_scale();
97 		int window_height();
98 		int window_width();
99 		bool hud();
100 		bool lua_hud();
101 		bool openGL();
102 		bool fifty_percent();
103 		bool seventyfive_percent();
104 		SDL_Rect window_rect(); // 3D view + interface
105 		SDL_Rect view_rect(); // main 3D view
106 		SDL_Rect map_rect();
107 		SDL_Rect term_rect();
108 		SDL_Rect hud_rect();
109 
110 		void bound_screen(bool in_game = true);
111 		void bound_screen_to_rect(SDL_Rect &r, bool in_game = true);
112 		void scissor_screen_to_rect(SDL_Rect &r);
113 		void window_to_screen(int &x, int &y);
114 
115 		SDL_Rect lua_clip_rect;
116 		SDL_Rect lua_view_rect;
117 		SDL_Rect lua_map_rect;
118 		SDL_Rect lua_term_rect;
119 
120 	private:
Screen()121 		Screen() : m_initialized(false) { }
122 		static Screen m_instance;
123 		bool m_initialized;
124 		SDL_Rect m_viewport_rect;
125 		SDL_Rect m_ortho_rect;
126 
127 		std::vector<std::pair<int, int> > m_modes;
128 	};
129 }
130 
131 extern SDL_PixelFormat pixel_format_16;
132 extern SDL_PixelFormat pixel_format_32;
133 
134 /* ---------- constants */
135 
136 // Original screen-size definitions
137 enum /* screen sizes */
138 {
139 	_50_percent,
140 	_75_percent,
141 	_100_percent,
142 	_full_screen,
143 };
144 
145 enum /* hardware acceleration codes */
146 {
147 	_no_acceleration,
148 	_opengl_acceleration
149 };
150 
151 enum /* screen selection based on game state */
152 {
153 	_screentype_level,
154 	_screentype_menu,
155 	_screentype_chapter
156 };
157 
158 /* ---------- missing from QUICKDRAW.H */
159 
160 #define deviceIsGrayscale 0x0000
161 #define deviceIsColor 0x0001
162 
163 /* ---------- structures */
164 
165 /* ---------- globals */
166 
167 extern struct color_table *world_color_table, *visible_color_table, *interface_color_table;
168 
169 /* ---------- prototypes/SCREEN.C */
170 
171 void initialize_gamma(void);
172 
173 void change_screen_clut(struct color_table *color_table);
174 void change_interface_clut(struct color_table *color_table);
175 void animate_screen_clut(struct color_table *color_table, bool full_screen);
176 
177 void build_direct_color_table(struct color_table *color_table, short bit_depth);
178 
179 void start_teleporting_effect(bool out);
180 void start_extravision_effect(bool out);
181 
182 void render_screen(short ticks_elapsed);
183 
184 void toggle_overhead_map_display_status(void);
185 
186 // Returns whether the size scale had been changed
187 bool zoom_overhead_map_out(void);
188 bool zoom_overhead_map_in(void);
189 
190 bool map_is_translucent(void);
191 
192 void enter_screen(void);
193 void exit_screen(void);
194 
195 void darken_world_window(void);
196 void validate_world_window(void);
197 
198 void change_gamma_level(short gamma_level);
199 
200 void assert_world_color_table(struct color_table *world_color_table, struct color_table *interface_color_table);
201 
202 // LP change: added function for resetting the screen state when starting a game
203 void reset_screen();
204 
205 // CP addition: added function to return the the game size
206 screen_mode_data *get_screen_mode(void);
207 
208 // LP: when initing, ask whether to show the monitor-frequency dialog
209 //void initialize_screen(struct screen_mode_data *mode, bool ShowFreqDialog);
210 void change_screen_mode(struct screen_mode_data *mode, bool redraw);
211 void change_screen_mode(short screentype);
212 
213 void toggle_fullscreen(bool fs);
214 void toggle_fullscreen();
215 void update_screen_window(void);
216 void clear_screen(bool update = true);
217 
218 void calculate_destination_frame(short size, bool high_resolution, Rect *frame);
219 
220 // LP addition: a routine for dumping the screen contents into a file.
221 // May need to be modified for pass-through video cards like the older 3dfx ones.
222 void dump_screen();
223 
224 // For getting and setting tunnel-vision mode
225 bool GetTunnelVision();
226 bool SetTunnelVision(bool TunnelVisionOn);
227 
228 // Request for drawing the HUD
229 void RequestDrawingHUD();
230 // Request for drawing the terminal
231 void RequestDrawingTerm();
232 // Request for drawing (or redrawing) a menu or intro screen
233 void draw_intro_screen();
234 
235 // Corresponding with-and-without-HUD sizes for some view-size index,
236 // for the convenience of Pfhortran scripting;
237 // the purpose is to get a similar size of display with the HUD status possibly changed
238 short SizeWithHUD(short _size);
239 short SizeWithoutHUD(short _size);
240 
241 // Displays a message on the screen for a second or so; may be good for debugging
242 void ShowMessage(char *Text);
243 
244 /* SB: Custom Blizzard-style overlays */
245 #define MAXIMUM_NUMBER_OF_SCRIPT_HUD_ELEMENTS 6
246 bool IsScriptHUDNonlocal();
247 void SetScriptHUDNonlocal(bool nonlocal = true);
248 /* color is a terminal color */
249 void SetScriptHUDColor(int player, int idx, int color);
250 /* text == NULL or "" removes that HUD element
251    to turn HUD elements off, set all elements NULL or "" */
252 void SetScriptHUDText(int player, int idx, const char* text);
253 /* icon == NULL turns the icon off
254    someday I'll document the format */
255 bool SetScriptHUDIcon(int player, int idx, const char* icon, size_t length);
256 /* sets the icon for that HUD to a colored square (same colors as SetScriptHUDColor) */
257 void SetScriptHUDSquare(int player, int idx, int color);
258 
259 bool MainScreenVisible();
260 int MainScreenLogicalWidth();
261 int MainScreenLogicalHeight();
262 int MainScreenWindowWidth();
263 int MainScreenWindowHeight();
264 int MainScreenPixelWidth();
265 int MainScreenPixelHeight();
266 float MainScreenPixelScale();
267 bool MainScreenIsOpenGL();
268 void MainScreenSwap();
269 void MainScreenCenterMouse();
270 SDL_Surface *MainScreenSurface();
271 void MainScreenUpdateRect(int x, int y, int w, int h);
272 void MainScreenUpdateRects(size_t count, const SDL_Rect *rects);
273 
274 #endif
275