winX.h

Go to the documentation of this file.
00001 /*      SCCS Id: @(#)winX.h     3.4     1996/08/18      */
00002 /* Copyright (c) Dean Luick, 1992                                 */
00003 /* NetHack may be freely redistributed.  See license for details. */
00004 
00005 /*
00006  * Definitions for the X11 window-port.  See doc/window.doc for details on
00007  * the window interface.
00008  */
00009 #ifndef WINX_H
00010 #define WINX_H
00011 
00012 #ifndef E
00013 #define E extern
00014 #endif
00015 
00016 #if defined(BOS) || defined(NHSTDC)
00017 #define DIMENSION_P int
00018 #else
00019 # ifdef WIDENED_PROTOTYPES
00020 #define DIMENSION_P unsigned int
00021 # else
00022 #define DIMENSION_P Dimension
00023 # endif
00024 #endif
00025 
00026 /*
00027  * Generic text buffer.
00028  */
00029 #define START_SIZE 512  /* starting text buffer size */
00030 struct text_buffer {
00031     char *text;
00032     int  text_size;
00033     int  text_last;
00034     int  num_lines;
00035 };
00036 
00037 
00038 /*
00039  * Information specific to a map window.
00040  */
00041 struct text_map_info_t {
00042     unsigned char   text[ROWNO][COLNO]; /* Actual displayed screen. */
00043 #ifdef TEXTCOLOR
00044     unsigned char   colors[ROWNO][COLNO];       /* Color of each character. */
00045     GC              color_gcs[CLR_MAX],         /* GC for each color */
00046                     inv_color_gcs[CLR_MAX];     /* GC for each inverse color */
00047 #define copy_gc     color_gcs[NO_COLOR]
00048 #define inv_copy_gc inv_color_gcs[NO_COLOR]
00049 #else
00050     GC              copy_gc,                    /* Drawing GC */
00051                     inv_copy_gc;                /* Inverse drawing GC */
00052 #endif
00053 };
00054 
00055 struct tile_map_info_t {
00056     unsigned short glyphs[ROWNO][COLNO];        /* Saved glyph numbers. */
00057     GC  white_gc;
00058     GC  black_gc;
00059     unsigned long image_width;                  /* dimensions of tile image */
00060     unsigned long image_height;
00061 };
00062 
00063 struct map_info_t {
00064     Dimension       viewport_width,     /* Saved viewport size, so we can */
00065                     viewport_height;    /*   clip to cursor on a resize.  */
00066     unsigned char   t_start[ROWNO],     /* Starting column for new info. */
00067                     t_stop[ROWNO];      /* Ending column for new info. */
00068     int             square_width,       /* Saved font/tile information so */
00069                     square_height,      /*   we can calculate the correct */
00070                     square_ascent,      /*   placement of changes.        */
00071                     square_lbearing;
00072     boolean         is_tile;
00073     union {
00074         struct text_map_info_t *text_map;
00075         struct tile_map_info_t *tile_map;
00076     } mtype;
00077 };
00078 
00079 
00080 /*
00081  * Information specific to a message window.
00082  */
00083 struct line_element {
00084     struct line_element *next;
00085     char *line;                 /* char buffer */
00086     int  buf_length;            /* length of buffer */
00087     int  str_length;            /* length of string in buffer */
00088 };
00089 
00090 struct mesg_info_t {
00091     XFontStruct *fs;            /* Font for the window. */
00092     int         num_lines;      /* line count */
00093     struct line_element *head;  /* head of circular line queue */
00094     struct line_element *line_here;/* current drawn line position */
00095     struct line_element *last_pause;/* point to the line after the prev */
00096                                 /*     bottom of screen                 */
00097     struct line_element *last_pause_head;/* pointer to head of previous */
00098                                 /* turn                                 */
00099     GC          gc;             /* GC for text drawing */
00100     int         char_width,     /* Saved font information so we can  */
00101                 char_height,    /*   calculate the correct placement */
00102                 char_ascent,    /*   of changes.                     */
00103                 char_lbearing;
00104     Dimension   viewport_width, /* Saved viewport size, so we can adjust */
00105                 viewport_height;/*   the slider on a resize.             */
00106     Boolean     dirty;          /* Lines have been added to the window. */
00107 };
00108 
00109 /*
00110  * Information specific to a "text" status window.
00111  */
00112 struct status_info_t {
00113     struct text_buffer text;    /* Just a text buffer. */
00114 };
00115 
00116 /*
00117  * Information specific to a menu window.  First a structure for each
00118  * menu entry, then the structure for each menu window.
00119  */
00120 typedef struct x11_mi {
00121     struct x11_mi *next;
00122     anything identifier;        /* Opaque type to identify this selection */
00123     long pick_count;            /* specific selection count; -1 if none */
00124     char *str;                  /* The text of the item. */
00125     int  attr;                  /* Attribute for the line. */
00126     boolean selected;           /* Been selected? */
00127     char selector;              /* Char used to select this entry. */
00128     char gselector;             /* Group selector. */
00129 } x11_menu_item;
00130 
00131 struct menu {
00132     x11_menu_item *base;        /* Starting pointer for item list. */
00133     x11_menu_item *last;        /* End pointer for item list. */
00134     const char    *query;       /* Query string. */
00135     const char    *gacc;        /* Group accelerators. */
00136     int           count;        /* Number of strings. */
00137     String        *list_pointer;/* String list. */
00138     Boolean       *sensitive;   /* Active list. */
00139     char          curr_selector;/* Next keyboard accelerator to assign, */
00140                                 /*   if 0, then we're out.              */
00141 };
00142 
00143 struct menu_info_t {
00144     struct menu curr_menu;      /* Menu being displayed. */
00145     struct menu new_menu;       /* New menu being built. */
00146 
00147     XFontStruct *fs;            /* Font for the window. */
00148     long menu_count;            /* number entered by user */
00149     Dimension line_height;      /* Total height of a line of text. */
00150     Dimension internal_height;  /* Internal height between widget & border */
00151     Dimension internal_width;   /* Internal width between widget & border */
00152     short how;                  /* Menu mode PICK_NONE, PICK_ONE, PICK_ANY */
00153     boolean valid_widgets;      /* TRUE if widgets have been created. */
00154     boolean is_menu;            /* Has been confirmed to being a menu window. */
00155     boolean is_active;          /* TRUE when waiting for user input. */
00156     boolean is_up;              /* TRUE when window is popped-up. */
00157     boolean cancelled;  /* Menu has been explicitly cancelled. */
00158     boolean counting;   /* true when menu_count has a valid value */
00159 };
00160 
00161 /*
00162  * Information specific to a text window.
00163  */
00164 struct text_info_t {
00165     struct text_buffer text;
00166     XFontStruct *fs;            /* Font for the text window. */
00167     int         max_width;      /* Width of widest line so far. */
00168     int         extra_width,    /* Sum of left and right border widths. */
00169                 extra_height;   /* Sum of top and bottom border widths. */
00170     boolean     blocked;        /*  */
00171     boolean     destroy_on_ack; /* Destroy this window when acknowleged. */
00172 #ifdef GRAPHIC_TOMBSTONE
00173     boolean     is_rip;         /* This window needs a tombstone. */
00174 #endif
00175 };
00176 
00177 
00178 /*
00179  * Basic window structure.
00180  */
00181 struct xwindow {
00182     int       type;             /* type of nethack window */
00183     Widget    popup;            /* direct parent of widget w or viewport */
00184     Widget    w;                /* the widget that does things */
00185     Dimension pixel_width;      /* window size, in pixels */
00186     Dimension pixel_height;
00187     int       prevx, cursx;     /* Cursor position, only used by    */
00188     int       prevy, cursy;     /*   map and "plain" status windows.*/
00189 
00190     union {
00191         struct map_info_t    *Map_info;     /* map window info */
00192         struct mesg_info_t   *Mesg_info;    /* message window info */
00193         struct status_info_t *Status_info;  /* status window info */
00194         struct menu_info_t   *Menu_info;    /* menu window info */
00195         struct text_info_t   *Text_info;    /* menu window info */
00196     } Win_info;
00197     boolean     keep_window;
00198 };
00199 
00200 /* Defines to use for the window information union. */
00201 #define map_information    Win_info.Map_info
00202 #define mesg_information   Win_info.Mesg_info
00203 #define status_information Win_info.Status_info
00204 #define menu_information   Win_info.Menu_info
00205 #define text_information   Win_info.Text_info
00206 
00207 
00208 #define MAX_WINDOWS 20          /* max number of open windows */
00209 
00210 #define NHW_NONE 0              /* Unallocated window type.  Must be    */
00211                                 /* different from any other NHW_* type. */
00212 
00213 #define NO_CLICK 0              /* No click occured on the map window. Must */
00214                                 /* be different than CLICK_1 and CLICK_2.   */
00215 
00216 #define DEFAULT_MESSAGE_WIDTH 60/* width in chars of the message window */
00217 
00218 #define DISPLAY_FILE_SIZE 35    /* Max number of lines in the default   */
00219                                 /* file display window.                 */
00220 
00221 #define MAX_KEY_STRING 64       /* String size for converting a keypress */
00222                                 /* event into a character(s)             */
00223 
00224 #define DEFAULT_LINES_DISPLAYED 12 /* # of lines displayed message window */
00225 #define MAX_HISTORY 60          /* max history saved on message window */
00226 
00227 
00228 /* Window variables (winX.c). */
00229 E struct xwindow window_list[MAX_WINDOWS];
00230 E XtAppContext   app_context;           /* context of application */
00231 E Widget         toplevel;              /* toplevel widget */
00232 E Atom           wm_delete_window;      /* delete window protocol */
00233 E boolean        exit_x_event;          /* exit condition for event loop */
00234 #define EXIT_ON_KEY_PRESS           0   /* valid values for exit_x_event */
00235 #define EXIT_ON_KEY_OR_BUTTON_PRESS 1
00236 #define EXIT_ON_EXIT                2
00237 #define EXIT_ON_SENT_EVENT          3
00238 E int click_x, click_y, click_button, updated_inventory;
00239 
00240 typedef struct {
00241     Boolean slow;
00242     Boolean autofocus;
00243     Boolean message_line;
00244     Boolean double_tile_size;   /* double tile size */
00245     String  tile_file;          /* name of file to open for tiles */
00246     String  icon;               /* name of desired icon */
00247     int     message_lines;      /* number of lines to attempt to show */
00248     String  pet_mark_bitmap;    /* X11 bitmap file used to mark pets */
00249     Pixel   pet_mark_color;     /* color of pet mark */
00250 #ifdef GRAPHIC_TOMBSTONE
00251     String  tombstone;          /* name of XPM file for tombstone */
00252     int     tombtext_x;         /* x-coord of center of first tombstone text */
00253     int     tombtext_y;         /* y-coord of center of first tombstone text */
00254     int     tombtext_dx;        /* x-displacement between tombstone line */
00255     int     tombtext_dy;        /* y-displacement between tombstone line */
00256 #endif
00257 } AppResources;
00258 
00259 E AppResources appResources;
00260 E void (*input_func)();
00261 
00262 extern struct window_procs X11_procs;
00263 
00264 /* Check for an invalid window id. */
00265 #define check_winid(window)                                     \
00266         if ((window) < 0 || (window) >= MAX_WINDOWS) {          \
00267             panic("illegal windid [%d] in %s at line %d",       \
00268                 window, __FILE__, __LINE__);                    \
00269         }
00270 
00271 
00272 /* ### dialogs.c ### */
00273 E Widget FDECL(CreateDialog, (Widget, String, XtCallbackProc, XtCallbackProc));
00274 E void FDECL(SetDialogPrompt,(Widget, String));
00275 E String FDECL(GetDialogResponse,(Widget));
00276 E void FDECL(SetDialogResponse,(Widget, String));
00277 E void FDECL(positionpopup,(Widget,BOOLEAN_P));
00278 
00279 /* ### winX.c ### */
00280 E struct xwindow *FDECL(find_widget,(Widget));
00281 E Boolean FDECL(nhApproxColor,(Screen*, Colormap, char*, XColor*));
00282 E Dimension FDECL(nhFontHeight,(Widget));
00283 E char FDECL(key_event_to_char,(XKeyEvent*));
00284 E void FDECL(msgkey, (Widget, XtPointer, XEvent*));
00285 E void FDECL(nh_XtPopup, (Widget, int, Widget));
00286 E void FDECL(nh_XtPopdown, (Widget));
00287 E void NDECL(win_X11_init);
00288 E void FDECL(nh_keyscroll, (Widget, XEvent*, String*, Cardinal*));
00289 
00290 /* ### winmesg.c ### */
00291 E void FDECL(set_message_slider, (struct xwindow*));
00292 E void FDECL(create_message_window,(struct xwindow*, BOOLEAN_P, Widget));
00293 E void FDECL(destroy_message_window,(struct xwindow*));
00294 E void FDECL(display_message_window, (struct xwindow*));
00295 E void FDECL(append_message,(struct xwindow*, const char*));
00296 E void FDECL(set_last_pause, (struct xwindow*));
00297 
00298 /* ### winmap.c ### */
00299 E void NDECL(post_process_tiles);
00300 E void FDECL(check_cursor_visibility,(struct xwindow*));
00301 E void FDECL(display_map_window,(struct xwindow*));
00302 E void FDECL(clear_map_window,(struct xwindow*));
00303 E void FDECL(map_input, (Widget, XEvent*, String*, Cardinal*));
00304 E void FDECL(set_map_size,(struct xwindow*, DIMENSION_P, DIMENSION_P));
00305 E void FDECL(create_map_window,(struct xwindow*, BOOLEAN_P, Widget));
00306 E void FDECL(destroy_map_window,(struct xwindow*));
00307 E int  FDECL(x_event,(int));
00308 
00309 /* ### winmenu.c ### */
00310 E void FDECL(menu_delete, (Widget, XEvent*, String*, Cardinal*));
00311 E void FDECL(menu_key,(Widget, XEvent*, String*, Cardinal*));
00312 E void FDECL(create_menu_window,(struct xwindow*));
00313 E void FDECL(destroy_menu_window,(struct xwindow*));
00314 
00315 /* ### winmisc.c ### */
00316 E void FDECL(ps_key,(Widget, XEvent*, String*, Cardinal*)); /* player selection action */
00317 E void FDECL(race_key,(Widget, XEvent*, String*, Cardinal*)); /* race selection action */
00318 E void FDECL(gend_key, (Widget,XEvent *,String *,Cardinal *)); /* gender */
00319 E void FDECL(algn_key, (Widget,XEvent *,String *,Cardinal *)); /* alignment */
00320 E void FDECL(ec_delete, (Widget, XEvent*, String*, Cardinal*));
00321 E void FDECL(ec_key,(Widget, XEvent*, String*, Cardinal*)); /* extended command action */
00322 
00323 /* ### winstatus.c ### */
00324 E void FDECL(create_status_window,(struct xwindow*, BOOLEAN_P, Widget));
00325 E void FDECL(destroy_status_window,(struct xwindow*));
00326 E void FDECL(adjust_status,(struct xwindow*, const char*));
00327 E void NDECL(null_out_status);
00328 E void NDECL(check_turn_events);
00329 
00330 /* ### wintext.c ### */
00331 E void FDECL(delete_text, (Widget, XEvent*, String*, Cardinal*));
00332 E void FDECL(dismiss_text,(Widget, XEvent*, String*, Cardinal*));
00333 E void FDECL(key_dismiss_text,(Widget, XEvent*, String*, Cardinal*));
00334 #ifdef GRAPHIC_TOMBSTONE
00335 E void FDECL(rip_dismiss_text,(Widget, XEvent*, String*, Cardinal*));
00336 #endif
00337 E void FDECL(add_to_text_window,(struct xwindow*, int, const char*));
00338 E void FDECL(display_text_window,(struct xwindow*, BOOLEAN_P));
00339 E void FDECL(create_text_window,(struct xwindow*));
00340 E void FDECL(destroy_text_window,(struct xwindow*));
00341 E void FDECL(clear_text_window,(struct xwindow*));
00342 E void FDECL(append_text_buffer,(struct text_buffer*, const char*, BOOLEAN_P)); /* text buffer routines */
00343 E void FDECL(init_text_buffer,(struct text_buffer*));
00344 E void FDECL(clear_text_buffer,(struct text_buffer*));
00345 E void FDECL(free_text_buffer,(struct text_buffer*));
00346 #ifdef GRAPHIC_TOMBSTONE
00347 E void FDECL(calculate_rip_text, (int));
00348 #endif
00349 
00350 
00351 /* ### winval.c ### */
00352 E Widget FDECL(create_value,(Widget, const char*));
00353 E void   FDECL(set_name,(Widget, char*));
00354 E void   FDECL(set_name_width,(Widget, int));
00355 E int    FDECL(get_name_width,(Widget));
00356 E void   FDECL(set_value,(Widget, const char*));
00357 E void   FDECL(set_value_width,(Widget, int));
00358 E int    FDECL(get_value_width,(Widget));
00359 E void   FDECL(hilight_value,(Widget));
00360 E void   FDECL(swap_fg_bg,(Widget));
00361 
00362 /* external declarations */
00363 E void FDECL(X11_init_nhwindows, (int *, char **));
00364 E void NDECL(X11_player_selection);
00365 E void NDECL(X11_askname);
00366 E void NDECL(X11_get_nh_event) ;
00367 E void FDECL(X11_exit_nhwindows, (const char *));
00368 E void FDECL(X11_suspend_nhwindows, (const char *));
00369 E void NDECL(X11_resume_nhwindows);
00370 E winid FDECL(X11_create_nhwindow, (int));
00371 E void FDECL(X11_clear_nhwindow, (winid));
00372 E void FDECL(X11_display_nhwindow, (winid, BOOLEAN_P));
00373 E void FDECL(X11_destroy_nhwindow, (winid));
00374 E void FDECL(X11_curs, (winid,int,int));
00375 E void FDECL(X11_putstr, (winid, int, const char *));
00376 E void FDECL(X11_display_file, (const char *, BOOLEAN_P));
00377 E void FDECL(X11_start_menu, (winid));
00378 E void FDECL(X11_add_menu, (winid,int,const ANY_P *,
00379                         CHAR_P, CHAR_P, int, const char *, BOOLEAN_P));
00380 E void FDECL(X11_end_menu, (winid, const char *));
00381 E int FDECL(X11_select_menu, (winid, int, MENU_ITEM_P **));
00382 E void NDECL(X11_update_inventory);
00383 E void NDECL(X11_mark_synch);
00384 E void NDECL(X11_wait_synch);
00385 #ifdef CLIPPING
00386 E void FDECL(X11_cliparound, (int, int));
00387 #endif
00388 E void FDECL(X11_print_glyph, (winid,XCHAR_P,XCHAR_P,int));
00389 E void FDECL(X11_raw_print, (const char *));
00390 E void FDECL(X11_raw_print_bold, (const char *));
00391 E int NDECL(X11_nhgetch);
00392 E int FDECL(X11_nh_poskey, (int *, int *, int *));
00393 E void NDECL(X11_nhbell);
00394 E int NDECL(X11_doprev_message);
00395 E char FDECL(X11_yn_function, (const char *, const char *, CHAR_P));
00396 E void FDECL(X11_getlin, (const char *,char *));
00397 E int NDECL(X11_get_ext_cmd);
00398 E void FDECL(X11_number_pad, (int));
00399 E void NDECL(X11_delay_output);
00400 
00401 /* other defs that really should go away (they're tty specific) */
00402 E void NDECL(X11_start_screen);
00403 E void NDECL(X11_end_screen);
00404 
00405 #ifdef GRAPHIC_TOMBSTONE
00406 E void FDECL(X11_outrip, (winid,int));
00407 #else
00408 E void FDECL(genl_outrip, (winid,int));
00409 #endif
00410 
00411 #endif /* WINX_H */