1 #ifndef __SCREEN_DRAWING_H
2 #define __SCREEN_DRAWING_H
3 
4 /*
5 	SCREEN_DRAWING.H
6 
7 	Copyright (C) 1991-2001 and beyond by Bungie Studios, Inc.
8 	and the "Aleph One" developers.
9 
10 	This program is free software; you can redistribute it and/or modify
11 	it under the terms of the GNU General Public License as published by
12 	the Free Software Foundation; either version 3 of the License, or
13 	(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 	This license is contained in the file "COPYING",
21 	which is included with this source code; it is available online at
22 	http://www.gnu.org/licenses/gpl.html
23 
24 	Monday, August 15, 1994 3:11:38 PM
25 
26 Apr 21, 2000 (Loren Petrich): Added XML parser object for the rectangle set,
27 	and exporting color data for game_window color parser
28 
29 Jul 2, 2000 (Loren Petrich):
30 	The HUD is now always buffered
31 */
32 
33 #include	"shape_descriptors.h"
34 #include "sdl_fonts.h"
35 
36 struct rgb_color;
37 
38 /* Rectangles for the interface, etc.. */
39 /* rectangle id's */
40 enum {
41 	/* game window rectangles */
42 	_player_name_rect= 0,
43 	_oxygen_rect,
44 	_shield_rect,
45 	_motion_sensor_rect,
46 	_microphone_rect,
47 	_inventory_rect,
48 	_weapon_display_rect,
49 
50 	/* interface rectangles */
51 	START_OF_MENU_INTERFACE_RECTS,
52 	_new_game_button_rect = 7,
53 	_load_game_button_rect,
54 	_gather_button_rect,
55 	_join_button_rect,
56 	_prefs_button_rect,
57 	_replay_last_button_rect,
58 	_save_last_button_rect,
59 	_replay_saved_button_rect,
60 	_credits_button_rect,
61 	_quit_button_rect,
62 	_center_button_rect,
63 	_singleton_game_button_rect,
64 	_about_alephone_rect,
65 	END_OF_MENU_INTERFACE_RECTS,
66 
67 	/* Marathon compatibility rectangles */
68 	_terminal_screen_rect = 20,
69 	_terminal_header_rect,
70 	_terminal_footer_rect,
71 	_terminal_full_text_rect,
72 	_terminal_left_rect,
73 	_terminal_right_rect,
74 	_terminal_logon_graphic_rect,
75 	_terminal_logon_title_rect,
76 	_terminal_logon_location_rect,
77 	_respawn_indicator_rect,
78 	_blinker_rect,
79 
80 	NUMBER_OF_INTERFACE_RECTANGLES
81 };
82 
83 /* Colors for drawing.. */
84 enum {
85 	_energy_weapon_full_color,
86 	_energy_weapon_empty_color,
87 	_black_color,
88 	_inventory_text_color,
89 	_inventory_header_background_color,
90 	_inventory_background_color,
91 	PLAYER_COLOR_BASE_INDEX,
92 
93 	_white_color= 14,
94 	_invalid_weapon_color,
95 	_computer_border_background_text_color,
96 	_computer_border_text_color,
97 	_computer_interface_text_color,
98 	_computer_interface_color_purple,
99 	_computer_interface_color_red,
100 	_computer_interface_color_pink,
101 	_computer_interface_color_aqua,
102 	_computer_interface_color_yellow,
103 	_computer_interface_color_brown,
104 	_computer_interface_color_blue,
105     NUMBER_OF_INTERFACE_COLORS
106 };
107 
108 enum { /* justification flags for _draw_screen_text */
109 	_no_flags,
110 	_center_horizontal= 0x01,
111 	_center_vertical= 0x02,
112 	_right_justified= 0x04,
113 	_top_justified= 0x08,
114 	_bottom_justified= 0x10,
115 	_wrap_text= 0x20
116 };
117 
118 enum { /* Fonts for the interface et al.. */
119 	_interface_font,
120 	_weapon_name_font,
121 	_player_name_font,
122 	_interface_item_count_font,
123 	_computer_interface_font,
124 	_computer_interface_title_font,
125 	_net_stats_font,
126 	NUMBER_OF_INTERFACE_FONTS
127 };
128 
129 /* Structure for portable rectangles.  notice it is exactly same as Rect */
130 struct screen_rectangle {
131 	short top, left;
132 	short bottom, right;
133 };
134 typedef struct screen_rectangle screen_rectangle;
135 
136 /* ------- Prototypes */
137 void initialize_screen_drawing(void);
138 
139 void _set_port_to_screen_window(void);
140 void _set_port_to_gworld(void);
141 void _restore_port(void);
142 #if defined SDL
143 void _set_port_to_term(void);
144 void _set_port_to_intro(void);
145 void _set_port_to_map(void);
146 void _set_port_to_custom(SDL_Surface *surface);
147 #endif
148 
149 /* If source==NULL, source= the shapes bounding rectangle */
150 void _draw_screen_shape(shape_descriptor shape_id, screen_rectangle *destination,
151 	screen_rectangle *source);
152 void _draw_screen_shape_at_x_y(shape_descriptor shape, short x, short y);
153 void _draw_screen_shape_centered(shape_descriptor shape, screen_rectangle *rectangle,
154 	short flags);
155 void _draw_screen_text(const char *text, screen_rectangle *destination,
156 	short flags, short font_id, short text_color);
157 short _text_width(const char *buffer, short font_id);
158 short _text_width(const char *buffer, int start, int length, short font_id);
159 
160 void _erase_screen(short color_index);
161 
162 void _scroll_window(short dy, short rectangle_id, short background_color_index);
163 
164 void _fill_screen_rectangle(screen_rectangle *rectangle, short color_index);
165 
166 screen_rectangle *get_interface_rectangle(short index);
167 rgb_color &get_interface_color(short index);
168 class FontSpecifier;
169 FontSpecifier &get_interface_font(short index);
170 
171 short _get_font_line_height(short font_index);
172 
173 void _fill_rect(screen_rectangle *rectangle, short color_index);
174 
175 void _frame_rect(screen_rectangle *rectangle, short color_index);
176 
177 // LP addition: stuff to use a buffer for the Heads-Up Display
178 void _set_port_to_HUD();
179 
180 struct world_point2d;
181 
182 static inline int draw_text(SDL_Surface *s, const char *text, size_t length, int x, int y, uint32 pixel, const font_info *font, uint16 style, bool utf8 = false)
183 {
184 	return font ? font->draw_text(s, text, length, x, y, pixel, style, utf8) : 0;
185 }
186 
187 static inline int draw_text(SDL_Surface *s, const char *text, int x, int y, uint32 pixel, const font_info *font, uint16 style, bool utf8 = false)
188 {
189 	return font ? font->draw_text(s, text, strlen(text), x, y, pixel, style, utf8) : 0;
190 }
191 
char_width(uint8 c,const font_info * font,uint16 style)192 static inline int8 char_width(uint8 c, const font_info *font, uint16 style)
193 {
194 	return font ? font->char_width(c, style) : 0;
195 }
196 
197 static inline uint16 text_width(const char *text, const font_info *font, uint16 style, bool utf8 = false)
198 {
199 	return font ? font->text_width(text, style, utf8) : 0;
200 }
201 
202 static inline uint16 text_width(const char *text, size_t length, const font_info *font, uint16 style, bool utf8 = false)
203 {
204 	return font ? font->text_width(text, length, style, utf8) : 0;
205 }
206 
trunc_text(const char * text,int max_width,const font_info * font,uint16 style)207 static inline int trunc_text(const char *text, int max_width, const font_info *font, uint16 style)
208 {
209 	return font ? font->trunc_text(text, max_width, style) : 0;
210 }
211 
212 extern void draw_polygon(SDL_Surface *s, const world_point2d *vertex_array, int vertex_count, uint32 pixel);
213 extern void draw_line(SDL_Surface *s, const world_point2d *v1, const world_point2d *v2, uint32 pixel, int pen_size);
214 extern void draw_rectangle(SDL_Surface *s, const SDL_Rect *r, uint32 pixel);
215 
216 #endif
217