1 /*
2 Copyright (C) 1997-2001 Id Software, Inc.
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 
13 See the GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 
19 */
20 
21 #ifndef __QMENU_H__
22 #define __QMENU_H__
23 
24 #include "q_shared.h"
25 #include "q_list.h"
26 #include "q_field.h"
27 #include "uis.h"
28 #include "qfiles.h"
29 #include "com_public.h"
30 #include "ref_public.h"
31 #include "key_public.h"
32 #include "snd_public.h"
33 #include "ui_public.h"
34 
35 #define UI_Malloc( size )	com.TagMalloc( size, TAG_UI )
36 
37 #define SMALLCHAR_WIDTH		8
38 #define SMALLCHAR_HEIGHT	8
39 
40 #define MAXMENUITEMS	64
41 
42 #define MTYPE_BAD			0
43 #define MTYPE_SLIDER		1
44 #define MTYPE_LIST			2
45 #define MTYPE_ACTION		3
46 #define MTYPE_SPINCONTROL	4
47 #define MTYPE_SEPARATOR  	5
48 #define MTYPE_FIELD			6
49 #define MTYPE_BITMAP		7
50 #define MTYPE_IMAGELIST		8
51 #define MTYPE_STATIC		9
52 #define MTYPE_KEYBIND		10
53 
54 #define QMF_LEFT_JUSTIFY	0x00000001
55 #define QMF_GRAYED			0x00000002
56 #define QMF_NUMBERSONLY		0x00000004
57 #define QMF_HASFOCUS		0x00000008
58 #define QMF_HIDDEN			0x00000010
59 #define QMF_DISABLED		0x00000020
60 #define QMF_CUSTOM_COLOR	0x00000040
61 
62 #define ID_MENU				-1
63 
64 #define QM_GOTFOCUS			1
65 #define QM_LOSTFOCUS		2
66 #define QM_ACTIVATE			3
67 #define QM_CHANGE			4
68 #define QM_KEY				5
69 #define QM_CHAR				6
70 #define QM_MOUSE			7
71 #define QM_DESTROY			8
72 #define QM_DESTROY_CHILD	9
73 
74 #define QMS_NOTHANDLED		0
75 #define QMS_SILENT			1
76 #define QMS_IN				2
77 #define QMS_MOVE			3
78 #define QMS_OUT				4
79 #define QMS_BEEP			5
80 
81 #define RCOLUMN_OFFSET  16
82 #define LCOLUMN_OFFSET -16
83 
84 #define	MENU_SPACING	12
85 
86 #define DOUBLE_CLICK_DELAY	300
87 
88 #define BUTTON_YPOS			( uis.glconfig.vidHeight - ( 60 + 32 ) / 2 )
89 
90 #define UI_IsItemSelectable( item ) \
91 	( (item)->type != MTYPE_SEPARATOR && \
92 	(item)->type != MTYPE_STATIC && \
93 	!( (item)->flags & (QMF_GRAYED|QMF_HIDDEN|QMF_DISABLED) ) )
94 
95 typedef struct menuFrameWork_s {
96 	char	*statusbar;
97 
98 	int		nitems;
99 	void	*items[MAXMENUITEMS];
100 
101 	qboolean transparent;
102 	qboolean keywait;
103 
104 	void		(*draw)( struct menuFrameWork_s *self );
105 	int			(*callback)( int id, int msg, int param );
106 } menuFrameWork_t;
107 
108 typedef struct menuCommon_s {
109 	int type;
110 	int id;
111 	const char *name;
112 	menuFrameWork_t *parent;
113 	color_t	color;
114 	vrect_t rect;
115 
116 	int x, y;
117 	int width, height;
118 
119 	uint32 flags;
120 	uint32 uiFlags;
121 } menuCommon_t;
122 
123 typedef struct menuField_s {
124 	menuCommon_t generic;
125 	inputField_t field;
126 } menuField_t;
127 
128 typedef struct menuSlider_s {
129 	menuCommon_t generic;
130 
131 	float minvalue;
132 	float maxvalue;
133 	float curvalue;
134 
135 	float range;
136 } menuSlider_t;
137 
138 #define MAX_COLUMNS	8
139 #define MLIST_SPACING	10
140 #define MLIST_BORDER_WIDTH	1
141 #define MLIST_SCROLLBAR_WIDTH	10
142 #define MLIST_PRESTEP	3
143 
144 typedef enum menuListFlags_e {
145 	MLF_NOSELECT				= (1<<0),
146 	MLF_HIDE_SCROLLBAR			= (1<<1),
147 	MLF_HIDE_SCROLLBAR_EMPTY	= (1<<2),
148 	MLF_HIDE_BACKGROUND			= (1<<3)
149 } menuListFlags_t;
150 
151 typedef struct menuListColumn_s {
152 	const char	*name;
153 	int		width;
154 	int		uiFlags;
155 } menuListColumn_t;
156 
157 typedef struct menuList_s {
158 	menuCommon_t generic;
159 
160 	const char	**itemnames;
161 	int			numItems;
162 	int			maxItems;
163 	menuListFlags_t mlFlags;
164 
165 	int		prestep;
166 	int		curvalue;
167 	int		clickTime;
168 
169     char    scratch[8];
170     int     scratchCount;
171     int     scratchTime;
172 
173 	menuListColumn_t	columns[MAX_COLUMNS];
174 	int					numcolumns;
175 	qboolean			drawNames;
176 } menuList_t;
177 
178 typedef struct imageList_s {
179 	menuCommon_t generic;
180 
181 	const char *name;
182 
183 	int prestep;
184 	int curvalue;
185 	const char **names;
186 	const qhandle_t *images;
187 	int clickTime;
188 
189 	int numcolumns;
190 	int numRows;
191 
192 	int imageWidth;
193 	int imageHeight;
194 } imageList_t;
195 
196 typedef struct menuSpinControl_s {
197 	menuCommon_t generic;
198 
199 	const char	**itemnames;
200 	int			numItems;
201 	int			curvalue;
202 } menuSpinControl_t;
203 
204 typedef struct menuAction_s {
205 	menuCommon_t generic;
206 } menuAction_t;
207 
208 typedef struct menuSeparator_s {
209 	menuCommon_t generic;
210 } menuSeparator_t;
211 
212 typedef struct menuBitmap_s {
213 	menuCommon_t generic;
214 	qhandle_t	pic;
215 	const char *errorImage;
216 } menuBitmap_t;
217 
218 typedef struct menuStatic_s {
219 	menuCommon_t	generic;
220 	int				maxChars;
221 } menuStatic_t;
222 
223 typedef struct menuKeybind_s {
224 	menuCommon_t	generic;
225 	char			binding[32];
226 	char			altbinding[32];
227 } menuKeybind_t;
228 
229 #define MAX_PLAYERMODELS 32
230 
231 typedef struct playerModelInfo_s {
232 	int		nskins;
233 	char	**skindisplaynames;
234 	char **weaponNames;
235 	int numWeapons;
236 	char	directory[MAX_QPATH];
237 } playerModelInfo_t;
238 
239 void PlayerModel_Load( void );
240 void PlayerModel_Free( void );
241 
242 #define	MAX_MENU_DEPTH	8
243 
244 typedef struct uiStatic_s {
245 	int realtime;
246 	glconfig_t glconfig;
247     clipRect_t clipRect;
248 	int menuDepth;
249 	menuFrameWork_t	*layers[MAX_MENU_DEPTH];
250 	menuFrameWork_t *activeMenu;
251 	int mouseCoords[2];
252 	qboolean	entersound;		// play after drawing a frame, so caching
253 								// won't disrupt the sound
254 	qboolean	transparent;
255 	int		numPlayerModels;
256 	playerModelInfo_t	pmi[MAX_PLAYERMODELS];
257 
258 	qhandle_t	backgroundHandle;
259 	qhandle_t	fontHandle;
260 	qhandle_t	cursorHandle;
261 	int			cursorWidth, cursorHeight;
262 } uiStatic_t;
263 
264 extern uiStatic_t	uis;
265 
266 extern cvar_t		*ui_debug;
267 
268 void		UI_PushMenu( menuFrameWork_t *menu );
269 void		UI_ForceMenuOff( void );
270 void		UI_PopMenu( void );
271 qboolean	UI_DoHitTest( void );
272 qboolean	UI_CursorInRect( vrect_t *rect, int mx, int my );
273 char		*UI_FormatColumns( int numArgs, ... );
274 void		UI_AddToServerList( const serverStatus_t *status );
275 char		*UI_CopyString( const char *in );
276 void		UI_DrawLoading( int realtime );
277 void		UI_SetupDefaultBanner( menuStatic_t *banner, const char *name );
278 void		UI_DrawString( int x, int y, const color_t color, uint32 flags, const char *string );
279 void		UI_DrawChar( int x, int y, uint32 flags, int ch );
280 void		UI_StringDimensions( vrect_t *rc, uint32 flags, const char *string );
281 
282 void		Menu_Draw( menuFrameWork_t *menu );
283 void		Menu_AddItem( menuFrameWork_t *menu, void *item );
284 int			Menu_SelectItem( menuFrameWork_t *menu );
285 int			Menu_SlideItem( menuFrameWork_t *menu, int dir );
286 int			Menu_KeyEvent( menuCommon_t *item, int key );
287 int			Menu_CharEvent( menuCommon_t *item, int key );
288 int			Menu_MouseMove( menuCommon_t *item );
289 void		Menu_SetFocus( menuCommon_t *item );
290 int			Menu_AdjustCursor( menuFrameWork_t *menu, int dir );
291 menuCommon_t	*Menu_ItemAtCursor( menuFrameWork_t *menu );
292 menuCommon_t	*Menu_HitTest( menuFrameWork_t *menu, int x, int y );
293 void		MenuList_Init( menuList_t *l );
294 void		MenuList_SetValue( menuList_t *l, int value );
295 
296 void SpinControl_Init( menuSpinControl_t *s );
297 void Bitmap_Init( menuBitmap_t *b );
298 
299 void M_Menu_Error_f( comErrorType_t type, const char *text );
300 void M_Menu_Confirm_f( const char *text, void (*action)( qboolean yes ) );
301 void M_Menu_Main_f (void);
302 	void M_Menu_Game_f (void);
303 		void M_Menu_LoadGame_f (void);
304 		void M_Menu_SaveGame_f (void);
305 		void M_Menu_PlayerConfig_f (void);
306 			void M_Menu_DownloadOptions_f (void);
307 		void M_Menu_Credits_f( void );
308 	void M_Menu_Multiplayer_f( void );
309 		void M_Menu_JoinServer_f (void);
310 			void M_Menu_AddressBook_f( void );
311 		void M_Menu_StartServer_f (void);
312 			void M_Menu_DMOptions_f (void);
313 	void M_Menu_Video_f (void);
314 	void M_Menu_Options_f (void);
315 		void M_Menu_Keys_f (void);
316 		void M_Menu_Weapons_f( void );
317 	void M_Menu_Quit_f (void);
318 	void M_Menu_Demos_f( void );
319 
320 	void M_Menu_Credits( void );
321 	void M_Menu_Network_f( void );
322 
323 	void M_Menu_Mods_f( void );
324 	void M_Menu_Ingame_f( void );
325 
326 
327 #endif
328