root/trunk/src/gtk/main-gtk.h

Revision 1022, 12.9 kB (checked in by shanoah, 2 months ago)

Bring the gtk port up to date with the state changes made in revision 999

  • Property svn:eol-style set to native
Line 
1 /*
2  * File: main-gtk.h
3  * Purpose: Header file for the GTK port for Angband
4  *
5  * Copyright (c) 2000-2007 Robert Ruehlmann, Shanoah Alkire
6  *
7  * This work is free software; you can redistribute it and/or modify it
8  * under the terms of either:
9  *
10  * a) the GNU General Public License as published by the Free Software
11  *    Foundation, version 2, or
12  *
13  * b) the "Angband licence":
14  *    This software may be copied and distributed for educational, research,
15  *    and not for profit purposes provided that this copyright and statement
16  *    are included in all such copies.  Other copyrights may also apply.
17  */
18  
19 #include "angband.h"
20
21 #include "object/tvalsval.h"
22
23 #ifndef INCLUDED_MAIN_GTK_H
24 #define INCLUDED_MAIN_GTK_H
25
26 #define USE_PANGO
27 #define USE_CAIRO_UTILS
28
29 #include "main.h"
30 #include "cairo-utils.h"
31 #include "game-cmd.h"
32 #include "game-event.h"
33
34 #include <gtk/gtk.h>
35 #include <gdk/gdkkeysyms.h>
36 #include <glade/glade.h>
37
38 #define MAX_TERM_DATA 8
39 #define MAX_XTRA_WIN_DATA 6
40 #define USE_GRAPHICS
41 #define MAIN_WINDOW(td) (td == &data[0])
42
43 #define GENERAL_PREFS 0
44 #define TERM_PREFS 1
45 #define XTRA_WIN_PREFS 2
46
47 /*#define USE_GUI_SELECTION*/
48
49 typedef struct term_data term_data;
50 typedef struct xtra_win_data xtra_win_data;
51
52 /*
53  * Extra data to associate with each "window"
54  *
55  * Each "window" is represented by a "term_data" structure, which
56  * contains a "term" structure, which contains a pointer (t->data)
57  * back to the term_data structure.
58  */
59
60 struct term_data
61 {
62         term t;
63         cptr name;
64         int number;
65        
66         bool visible, initialized;
67         int rows;
68         int cols;
69         point location;
70         measurements size; /* of the window */
71         measurements tile, actual;
72        
73         cairo_surface_t *surface;
74         cairo_matrix_t matrix;
75         font_info font;
76        
77         GtkWidget *win;
78         GtkWidget *drawing_area;
79         GtkWidget *menu_item;
80 };
81
82 struct xtra_win_data
83 {
84         int x;
85         cptr name, win_name, text_view_name, item_name, drawing_area_name, font_button_name;
86         bool visible;
87         font_info font;
88        
89         GtkWidget *win, *text_view, *menu, *drawing_area;
90         GtkTextBuffer *buf;
91         cairo_t *cr;
92         cairo_surface_t *surface;
93         measurements size;
94         point location;
95         game_event_type event;
96 };
97
98 static game_event_type xtra_events[]=
99 {
100         EVENT_MESSAGE,
101         EVENT_INVENTORY,
102         EVENT_EQUIPMENT,
103         EVENT_MONSTERLIST,
104         0,
105         EVENT_PLAYERTITLE
106 };
107
108 GdkColor black = { 0, 0x0000, 0x0000, 0x0000 };
109 GdkColor white = { 0, 0xffff, 0xffff, 0xffff };
110        
111 char xtra_names[MAX_XTRA_WIN_DATA][20] =
112 { "Messages", "Inventory", "Equipment", "Monster List", "Debug", "Status" };
113
114 char xtra_win_names[MAX_XTRA_WIN_DATA][20] =
115 { "message_window", "inv_window", "equip_window", "monst_list_window", "debug_window", "status_window" };
116
117 char xtra_text_names[MAX_XTRA_WIN_DATA][20] =
118 { "message_text", "inv_text", "equip_text", "monst_list_text", "debug_text", "status_text" };
119
120 char xtra_drawing_names[MAX_XTRA_WIN_DATA][24] =
121 { "message_drawing_area", "inv_drawing_area", "equip_drawing_area", "monst_list_drawing_area", "debug_drawing_area", "status_drawing_area" };
122
123 char xtra_menu_names[MAX_XTRA_WIN_DATA][20] =
124 { "message_item", "inv_item", "equip_item", "monst_list_item", "debug_item", "status_item" };
125
126 char xtra_font_button_names[MAX_XTRA_WIN_DATA][20] =
127 { "message_font", "inv_font", "equip_font", "monst_list_font", "debug_font", "status_font" };
128
129 char sidebar_text[24][20] =
130 {
131         "","","","","Level:", "XP: ", "Gold:", "", "STR:", "INT:", "WIS:", "DEX:", "CON:", "CHR:", "", "AC:", "HP:", "", "SP:", "", "","", "", ""
132 };
133 /*
134  * An array of "term_data" structures, one for each "sub-window"
135  */
136 static term_data data[MAX_TERM_DATA];
137
138 /*
139  * A similar array for my extra, non-term windows.
140  */
141 static xtra_win_data xdata[MAX_XTRA_WIN_DATA];
142
143 /* An array of graphic menu items */
144 /*static GtkWidget *graphics_item[4];*/
145 static GtkWidget *big_tile_item;
146 /*
147  * There are a few functions installed to be triggered by several
148  * of the basic player events.  For convenience, these have been grouped
149  * in this list that I swiped from xtra3.c. These really should be in one of the
150  * headers, shouldn't they?
151  */
152 static game_event_type my_player_events[] =
153 {
154         EVENT_RACE_CLASS,
155         EVENT_PLAYERTITLE,
156         EVENT_EXPERIENCE,
157         EVENT_PLAYERLEVEL,
158         EVENT_GOLD,
159         EVENT_EQUIPMENT,  /* For equippy chars */
160         EVENT_STATS,
161         EVENT_HP,
162         EVENT_MANA,
163         EVENT_AC,
164
165         EVENT_MONSTERHEALTH,
166
167         EVENT_PLAYERSPEED,
168         EVENT_DUNGEONLEVEL,
169 };
170
171 static game_event_type my_statusline_events[] =
172 {
173         EVENT_STUDYSTATUS,
174         EVENT_STATUS,
175         EVENT_DETECTIONSTATUS,
176         EVENT_STATE,
177 };
178
179 /*  Various variables  */
180 static void save_prefs(void);
181 static bool ignore_prefs = FALSE;
182 static bool game_in_progress = FALSE;
183 static int num_term = 8;
184
185 /* Command line help */
186 const char help_gtk[] = "GTK for X11, subopts -n<windows>, -i to ignore prefs, and standard GTK options";
187
188 /*  Path to the Gtk settings file */
189 static char settings[1024];
190 static game_command cmd = { CMD_NULL, 0, {0} };
191 bool game_saved;
192
193 static GtkWidget *toolbar;
194 static GtkWidget *toolbar_items[12];
195 static int toolbar_size;
196 static unsigned char toolbar_keypress[12];
197
198 /* Abstracted out for future changes */
199 static int max_win_width(term_data *td);
200 static int max_win_height(term_data *td);
201 /*
202  * Find the square a particular pixel is part of.
203  */
204 static void pixel_to_square(int * const x, int * const y, const int ox, const int oy);
205
206 void set_term_matrix(term_data *td);
207 /* Cairo's rect type to Gdks */
208 static GdkRectangle cairo_rect_to_gdk(cairo_rectangle_t *r);
209
210 /* And vice-versa */
211 static cairo_rectangle_t gdk_rect_to_cairo(GdkRectangle *r);
212
213 /* Mark part of a window as invalid, so it gets redrawn */
214 static void invalidate_drawing_area(GtkWidget *widget, cairo_rectangle_t r);
215
216 /* Get the position of a term window when it changes */
217 gboolean configure_event_handler(GtkWidget *widget, GdkEventConfigure *event, gpointer user_data);
218
219 /* Get the position of an extra window when it changes */
220 gboolean xtra_configure_event_handler(GtkWidget *widget, GdkEventConfigure *event, gpointer user_data);
221
222 /* Set the window geometry */
223 static void set_window_defaults(term_data *td);
224
225 /* Set the term window size */
226 static void set_window_size(term_data *td);
227
228 /* Set the extra window size */
229 static void set_xtra_window_size(xtra_win_data *xd);
230
231 /* If a term window is shown, do a few checks */
232 gboolean show_event_handler(GtkWidget *widget, GdkEventExpose *event, gpointer user_data);
233
234 /* Erase the whole term. */
235 static errr Term_clear_gtk(void);
236
237 /* Erase some characters. */
238 static errr Term_wipe_gtk(int x, int y, int n);
239
240 /* Draw some textual characters. */
241 static errr Term_text_gtk(int x, int y, int n, byte a, cptr s);
242
243 /* Draw pretty pictures instead. */
244 static errr Term_pict_gtk(int x, int y, int n, const byte *ap, const char *cp, const byte *tap, const char *tcp);
245
246 /* Do gtk things */
247 static errr Term_flush_gtk(void);
248
249 /* Refresh things */
250 static errr Term_fresh_gtk(void);
251
252 /*  Handle a "special request" */
253 static errr Term_xtra_gtk(int n, int v);
254
255 /* Draw the cursor */
256 static errr Term_curs_gtk(int x, int y);
257
258 /*
259  * Hack -- redraw a term_data
260  *
261  * Note that "Term_redraw()" calls "TERM_XTRA_CLEAR"
262  */
263 static void term_data_redraw(term_data *td);
264
265 /* Check for events - Traditional */
266 static errr CheckEvent(bool wait);
267
268 /* Save the game */
269 static bool save_game_gtk(void);
270
271 /* Quit the game - from Angband */
272 static void hook_quit(cptr str);
273
274 /* Quit the game - from Gtk */
275 gboolean quit_event_handler(GtkWidget *widget, GdkEventButton *event, gpointer user_data);
276
277 /* Kill the Kin... err... the game */
278 gboolean destroy_event_handler(GtkWidget *widget, GdkEventButton *event, gpointer user_data);
279
280 /* Hide away, term windows */
281 gboolean hide_event_handler(GtkWidget *widget, GdkEventButton *event, gpointer user_data);
282
283 /* Hide away, extra windows */
284 gboolean xtra_hide_event_handler(GtkWidget *widget, GdkEventButton *event, gpointer user_data);
285
286 /* Huzzah! A new game. */
287 gboolean new_event_handler(GtkWidget *widget, GdkEventButton *event, gpointer user_data);
288
289 /* Given a term window and font, load the font */
290 static void load_font_by_name(term_data *td, cptr font_name);
291
292 /* Set the name of a font for a term window and load it. */
293 void set_term_font(GtkFontButton *widget, gpointer user_data);
294
295 /* Set the name of a font for an extra window and load it. */
296 void set_xtra_font(GtkFontButton *widget, gpointer user_data);
297
298 /* Filter function for the savefile list */
299 static gboolean file_open_filter(const GtkFileFilterInfo *filter_info, gpointer data);
300
301 /* Open/Save Dialog box */
302 static bool save_dialog_box(bool save);
303
304 /* Open a saved game */
305 void open_event_handler(GtkButton *was_clicked, gpointer user_data);
306
307 /* Save the game */
308 gboolean save_event_handler(GtkWidget *widget, GdkEvent *event, gpointer user_data);
309
310 /* Save the game before deleting? */
311 gboolean delete_event_handler(GtkWidget *widget, GdkEvent *event, gpointer user_data);
312
313 /* Register keypresses */
314 gboolean keypress_event_handler(GtkWidget *widget, GdkEventKey *event, gpointer user_data);
315
316 /* Prefs - copied straight from main-x11.c and hacked. */
317 static void save_prefs(void);
318
319 /* Util functions for prefs */
320 static int check_env_i(char* name, int i, int dfault);
321 static int get_value(cptr buf);
322 static void load_term_prefs();
323
324 /* Load the prefs */
325 static void load_prefs();
326
327 /* Register a mouse click */
328 gboolean on_mouse_click(GtkWidget *widget, GdkEventButton *event, gpointer user_data);
329
330 /* Redraw a term window */
331 gboolean expose_event_handler(GtkWidget *widget, GdkEventExpose *event, gpointer user_data);
332
333 /* Hide the options window */
334 gboolean hide_options(GtkWidget *widget, GdkEvent *event, gpointer user_data);
335
336 /* Toggle the appropriate checkmark for a term menu */
337 gboolean toggle_term_window(GtkWidget *widget, GdkEvent *event, gpointer user_data);
338
339 /* Toggle the appropriate checkmark for the exra menu */
340 gboolean toggle_xtra_window(GtkWidget *widget, GdkEvent *event, gpointer user_data);
341
342 /* Set up graphics */
343 static void init_graf(int g);
344
345 /* Initially choose arg_graphics */
346 static void setup_graphics_menu();
347
348 /* Hooks for graphics menu items */
349 gboolean on_graphics_activate(GtkWidget *widget, GdkEventExpose *event, gpointer user_data);
350
351 /*  Make text views "Angbandy"  */
352 static void white_on_black_textview(xtra_win_data *xd);
353
354 /* Init data for extra windows */
355 static void xtra_data_init(xtra_win_data *xd, int i);
356
357 /* Init the windows themselves */
358 static void init_xtra_windows(void);
359
360 /* Init the rest of the windows */
361 static void init_gtk_windows(void);
362
363 /* Show everything */
364 static void show_windows();
365
366 /* Init the term window data */
367 static errr term_data_init(term_data *td, int i);
368
369 /* Handle commands */
370  static game_command get_init_cmd();
371  
372  /* Stubs */
373  static void handle_map(game_event_type type, game_event_data *data, void *user);
374  static void handle_moved(game_event_type type, game_event_data *data, void *user);
375  static void handle_mons_target(game_event_type type, game_event_data *data, void *user);
376  
377  /* Set up color tags for all the angband colors. */
378 static void init_color_tags(xtra_win_data *xd);
379
380 /* Put text in a textview without a \n */
381 static void text_view_put(xtra_win_data *xd, const char *str, byte color);
382
383 /* Put text in a textview with a \n */
384 static void text_view_print(xtra_win_data *xd, const char *str, byte color);
385
386 /* plog_fmt reborn */
387 void gtk_log_fmt(byte c, cptr fmt, ...);
388
389 /* Update our own personal message window. */
390 static void handle_message(game_event_type type, game_event_data *data, void *user);
391
392 /* Return the last inventory slot. */
393 static int last_inv_slot(void);
394
395 /* Return an inventory slot */
396 static void inv_slot(char *str, size_t len, int i, bool equip);
397
398 /* Print the inventory */
399 static void handle_inv(game_event_type type, game_event_data *data, void *user);
400
401 /* Print the equipment list */
402 static void handle_equip(game_event_type type, game_event_data *data, void *user);
403
404 /* Print the monster window */
405 static void handle_mons_list(game_event_type type, game_event_data *data, void *user);
406
407 /* Print the sidebar */
408 static void handle_sidebar(game_event_type type, game_event_data *data, void *user);
409 static void glog(cptr fmt, ...);
410
411 /* More Stubs */
412 static void handle_init_status(game_event_type type, game_event_data *data, void *user);
413 static void handle_birth(game_event_type type, game_event_data *data, void *user);
414 static void handle_game(game_event_type type, game_event_data *data, void *user);
415 static void handle_store(game_event_type type, game_event_data *data, void *user);
416 static void handle_death(game_event_type type, game_event_data *data, void *user);
417 static void handle_end(game_event_type type, game_event_data *data, void *user);
418 static void handle_splash(game_event_type type, game_event_data *data, void *user);
419 static void handle_statusline(game_event_type type, game_event_data *data, void *user);
420
421 /* init the handlers */
422 static void init_handlers();
423
424 /* Init gtk */
425 errr init_gtk(int argc, char **argv);
426
427 /* Nuke things */
428 static void xtra_data_destroy(xtra_win_data *xd);
429 static void term_data_destroy(term_data *td);
430 static void release_memory();
431
432 static void force_redraw();
433
434 /* From xtra3.h */
435 extern byte monster_health_attr();
436 extern byte player_sp_attr();
437 extern byte player_hp_attr();
438 #endif /* INCLUDED_MAIN_GTK_H */
Note: See TracBrowser for help on using the browser.