| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 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 |
|
|---|
| 48 |
|
|---|
| 49 |
typedef struct term_data term_data; |
|---|
| 50 |
typedef struct xtra_win_data xtra_win_data; |
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 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; |
|---|
| 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 |
|
|---|
| 135 |
|
|---|
| 136 |
static term_data data[MAX_TERM_DATA]; |
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
static xtra_win_data xdata[MAX_XTRA_WIN_DATA]; |
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
static GtkWidget *big_tile_item; |
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 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, |
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 186 |
const char help_gtk[] = "GTK for X11, subopts -n<windows>, -i to ignore prefs, and standard GTK options"; |
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 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 |
|
|---|
| 199 |
static int max_win_width(term_data *td); |
|---|
| 200 |
static int max_win_height(term_data *td); |
|---|
| 201 |
|
|---|
| 202 |
|
|---|
| 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 |
|
|---|
| 208 |
static GdkRectangle cairo_rect_to_gdk(cairo_rectangle_t *r); |
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
static cairo_rectangle_t gdk_rect_to_cairo(GdkRectangle *r); |
|---|
| 212 |
|
|---|
| 213 |
|
|---|
| 214 |
static void invalidate_drawing_area(GtkWidget *widget, cairo_rectangle_t r); |
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 |
gboolean configure_event_handler(GtkWidget *widget, GdkEventConfigure *event, gpointer user_data); |
|---|
| 218 |
|
|---|
| 219 |
|
|---|
| 220 |
gboolean xtra_configure_event_handler(GtkWidget *widget, GdkEventConfigure *event, gpointer user_data); |
|---|
| 221 |
|
|---|
| 222 |
|
|---|
| 223 |
static void set_window_defaults(term_data *td); |
|---|
| 224 |
|
|---|
| 225 |
|
|---|
| 226 |
static void set_window_size(term_data *td); |
|---|
| 227 |
|
|---|
| 228 |
|
|---|
| 229 |
static void set_xtra_window_size(xtra_win_data *xd); |
|---|
| 230 |
|
|---|
| 231 |
|
|---|
| 232 |
gboolean show_event_handler(GtkWidget *widget, GdkEventExpose *event, gpointer user_data); |
|---|
| 233 |
|
|---|
| 234 |
|
|---|
| 235 |
static errr Term_clear_gtk(void); |
|---|
| 236 |
|
|---|
| 237 |
|
|---|
| 238 |
static errr Term_wipe_gtk(int x, int y, int n); |
|---|
| 239 |
|
|---|
| 240 |
|
|---|
| 241 |
static errr Term_text_gtk(int x, int y, int n, byte a, cptr s); |
|---|
| 242 |
|
|---|
| 243 |
|
|---|
| 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 |
|
|---|
| 247 |
static errr Term_flush_gtk(void); |
|---|
| 248 |
|
|---|
| 249 |
|
|---|
| 250 |
static errr Term_fresh_gtk(void); |
|---|
| 251 |
|
|---|
| 252 |
|
|---|
| 253 |
static errr Term_xtra_gtk(int n, int v); |
|---|
| 254 |
|
|---|
| 255 |
|
|---|
| 256 |
static errr Term_curs_gtk(int x, int y); |
|---|
| 257 |
|
|---|
| 258 |
|
|---|
| 259 |
|
|---|
| 260 |
|
|---|
| 261 |
|
|---|
| 262 |
|
|---|
| 263 |
static void term_data_redraw(term_data *td); |
|---|
| 264 |
|
|---|
| 265 |
|
|---|
| 266 |
static errr CheckEvent(bool wait); |
|---|
| 267 |
|
|---|
| 268 |
|
|---|
| 269 |
static bool save_game_gtk(void); |
|---|
| 270 |
|
|---|
| 271 |
|
|---|
| 272 |
static void hook_quit(cptr str); |
|---|
| 273 |
|
|---|
| 274 |
|
|---|
| 275 |
gboolean quit_event_handler(GtkWidget *widget, GdkEventButton *event, gpointer user_data); |
|---|
| 276 |
|
|---|
| 277 |
|
|---|
| 278 |
gboolean destroy_event_handler(GtkWidget *widget, GdkEventButton *event, gpointer user_data); |
|---|
| 279 |
|
|---|
| 280 |
|
|---|
| 281 |
gboolean hide_event_handler(GtkWidget *widget, GdkEventButton *event, gpointer user_data); |
|---|
| 282 |
|
|---|
| 283 |
|
|---|
| 284 |
gboolean xtra_hide_event_handler(GtkWidget *widget, GdkEventButton *event, gpointer user_data); |
|---|
| 285 |
|
|---|
| 286 |
|
|---|
| 287 |
gboolean new_event_handler(GtkWidget *widget, GdkEventButton *event, gpointer user_data); |
|---|
| 288 |
|
|---|
| 289 |
|
|---|
| 290 |
static void load_font_by_name(term_data *td, cptr font_name); |
|---|
| 291 |
|
|---|
| 292 |
|
|---|
| 293 |
void set_term_font(GtkFontButton *widget, gpointer user_data); |
|---|
| 294 |
|
|---|
| 295 |
|
|---|
| 296 |
void set_xtra_font(GtkFontButton *widget, gpointer user_data); |
|---|
| 297 |
|
|---|
| 298 |
|
|---|
| 299 |
static gboolean file_open_filter(const GtkFileFilterInfo *filter_info, gpointer data); |
|---|
| 300 |
|
|---|
| 301 |
|
|---|
| 302 |
static bool save_dialog_box(bool save); |
|---|
| 303 |
|
|---|
| 304 |
|
|---|
| 305 |
void open_event_handler(GtkButton *was_clicked, gpointer user_data); |
|---|
| 306 |
|
|---|
| 307 |
|
|---|
| 308 |
gboolean save_event_handler(GtkWidget *widget, GdkEvent *event, gpointer user_data); |
|---|
| 309 |
|
|---|
| 310 |
|
|---|
| 311 |
gboolean delete_event_handler(GtkWidget *widget, GdkEvent *event, gpointer user_data); |
|---|
| 312 |
|
|---|
| 313 |
|
|---|
| 314 |
gboolean keypress_event_handler(GtkWidget *widget, GdkEventKey *event, gpointer user_data); |
|---|
| 315 |
|
|---|
| 316 |
|
|---|
| 317 |
static void save_prefs(void); |
|---|
| 318 |
|
|---|
| 319 |
|
|---|
| 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 |
|
|---|
| 325 |
static void load_prefs(); |
|---|
| 326 |
|
|---|
| 327 |
|
|---|
| 328 |
gboolean on_mouse_click(GtkWidget *widget, GdkEventButton *event, gpointer user_data); |
|---|
| 329 |
|
|---|
| 330 |
|
|---|
| 331 |
gboolean expose_event_handler(GtkWidget *widget, GdkEventExpose *event, gpointer user_data); |
|---|
| 332 |
|
|---|
| 333 |
|
|---|
| 334 |
gboolean hide_options(GtkWidget *widget, GdkEvent *event, gpointer user_data); |
|---|
| 335 |
|
|---|
| 336 |
|
|---|
| 337 |
gboolean toggle_term_window(GtkWidget *widget, GdkEvent *event, gpointer user_data); |
|---|
| 338 |
|
|---|
| 339 |
|
|---|
| 340 |
gboolean toggle_xtra_window(GtkWidget *widget, GdkEvent *event, gpointer user_data); |
|---|
| 341 |
|
|---|
| 342 |
|
|---|
| 343 |
static void init_graf(int g); |
|---|
| 344 |
|
|---|
| 345 |
|
|---|
| 346 |
static void setup_graphics_menu(); |
|---|
| 347 |
|
|---|
| 348 |
|
|---|
| 349 |
gboolean on_graphics_activate(GtkWidget *widget, GdkEventExpose *event, gpointer user_data); |
|---|
| 350 |
|
|---|
| 351 |
|
|---|
| 352 |
static void white_on_black_textview(xtra_win_data *xd); |
|---|
| 353 |
|
|---|
| 354 |
|
|---|
| 355 |
static void xtra_data_init(xtra_win_data *xd, int i); |
|---|
| 356 |
|
|---|
| 357 |
|
|---|
| 358 |
static void init_xtra_windows(void); |
|---|
| 359 |
|
|---|
| 360 |
|
|---|
| 361 |
static void init_gtk_windows(void); |
|---|
| 362 |
|
|---|
| 363 |
|
|---|
| 364 |
static void show_windows(); |
|---|
| 365 |
|
|---|
| 366 |
|
|---|
| 367 |
static errr term_data_init(term_data *td, int i); |
|---|
| 368 |
|
|---|
| 369 |
|
|---|
| 370 |
static game_command get_init_cmd(); |
|---|
| 371 |
|
|---|
| 372 |
|
|---|
| 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 |
|
|---|
| 378 |
static void init_color_tags(xtra_win_data *xd); |
|---|
| 379 |
|
|---|
| 380 |
|
|---|
| 381 |
static void text_view_put(xtra_win_data *xd, const char *str, byte color); |
|---|
| 382 |
|
|---|
| 383 |
|
|---|
| 384 |
static void text_view_print(xtra_win_data *xd, const char *str, byte color); |
|---|
| 385 |
|
|---|
| 386 |
|
|---|
| 387 |
void gtk_log_fmt(byte c, cptr fmt, ...); |
|---|
| 388 |
|
|---|
| 389 |
|
|---|
| 390 |
static void handle_message(game_event_type type, game_event_data *data, void *user); |
|---|
| 391 |
|
|---|
| 392 |
|
|---|
| 393 |
static int last_inv_slot(void); |
|---|
| 394 |
|
|---|
| 395 |
|
|---|
| 396 |
static void inv_slot(char *str, size_t len, int i, bool equip); |
|---|
| 397 |
|
|---|
| 398 |
|
|---|
| 399 |
static void handle_inv(game_event_type type, game_event_data *data, void *user); |
|---|
| 400 |
|
|---|
| 401 |
|
|---|
| 402 |
static void handle_equip(game_event_type type, game_event_data *data, void *user); |
|---|
| 403 |
|
|---|
| 404 |
|
|---|
| 405 |
static void handle_mons_list(game_event_type type, game_event_data *data, void *user); |
|---|
| 406 |
|
|---|
| 407 |
|
|---|
| 408 |
static void handle_sidebar(game_event_type type, game_event_data *data, void *user); |
|---|
| 409 |
static void glog(cptr fmt, ...); |
|---|
| 410 |
|
|---|
| 411 |
|
|---|
| 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 |
|
|---|
| 422 |
static void init_handlers(); |
|---|
| 423 |
|
|---|
| 424 |
|
|---|
| 425 |
errr init_gtk(int argc, char **argv); |
|---|
| 426 |
|
|---|
| 427 |
|
|---|
| 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 |
|
|---|
| 435 |
extern byte monster_health_attr(); |
|---|
| 436 |
extern byte player_sp_attr(); |
|---|
| 437 |
extern byte player_hp_attr(); |
|---|
| 438 |
#endif |
|---|