1 /* NetHack may be freely redistributed. See license for details. */ 2 3 #ifndef _window_h_ 4 #define _window_h_ 5 6 #include <string> 7 #include <SDL.h> 8 #include <vector> 9 #include "vulture_types.h" 10 11 #define V_LISTITEM_WIDTH 300 12 #define V_LISTITEM_HEIGHT 52 13 14 15 typedef enum { 16 V_WINTYPE_NONE, /* only the root window has this type */ 17 V_WINTYPE_LEVEL, 18 V_WINTYPE_MAP, 19 V_WINTYPE_MAIN, 20 V_WINTYPE_MENU, 21 V_WINTYPE_BUTTON, 22 V_WINTYPE_OPTION, 23 V_WINTYPE_SCROLLBAR, 24 V_WINTYPE_TEXT, 25 V_WINTYPE_CONTEXTMENU, 26 V_WINTYPE_SCROLLAREA, 27 28 /* new-style inventory and object lists (ie multidrop, pickup, loot) */ 29 V_WINTYPE_OBJWIN, 30 V_WINTYPE_OBJITEM, 31 V_WINTYPE_OBJITEMHEADER, 32 33 V_WINTYPE_ENDING, 34 V_WINTYPE_CUSTOM 35 } window_type; 36 37 38 typedef enum { 39 V_EVENT_UNHANDLED, 40 V_EVENT_UNHANDLED_REDRAW, /* pass the event on to a parent win and redraw */ 41 V_EVENT_HANDLED_NOREDRAW, /* don't pass it on and don't redraw */ 42 V_EVENT_HANDLED_REDRAW, /* don't pass it on and redraw */ 43 V_EVENT_HANDLED_FINAL /* redraw and leave the event dispatcher */ 44 } eventresult; 45 46 47 48 enum hotspots { 49 V_HOTSPOT_NONE = 0, 50 /* child windows of the map */ 51 V_HOTSPOT_SCROLL_UPLEFT, 52 V_HOTSPOT_SCROLL_UP, 53 V_HOTSPOT_SCROLL_UPRIGHT, 54 V_HOTSPOT_SCROLL_LEFT, 55 V_HOTSPOT_SCROLL_RIGHT, 56 V_HOTSPOT_SCROLL_DOWNLEFT, 57 V_HOTSPOT_SCROLL_DOWN, 58 V_HOTSPOT_SCROLL_DOWNRIGHT, 59 V_WIN_MINIMAP, 60 V_WIN_STATUSBAR, 61 V_WIN_TOOLBAR1, 62 V_WIN_TOOLBAR2, 63 V_WIN_ENHANCE, 64 65 /* child windows of the statusbar */ 66 V_HOTSPOT_BUTTON_GOLD, 67 V_HOTSPOT_BUTTON_LOOK, 68 V_HOTSPOT_BUTTON_EXTENDED, 69 V_HOTSPOT_BUTTON_MAP, 70 V_HOTSPOT_BUTTON_SPELLBOOK, 71 V_HOTSPOT_BUTTON_INVENTORY, 72 V_HOTSPOT_BUTTON_DISCOVERIES, 73 V_HOTSPOT_BUTTON_MESSAGES, 74 V_HOTSPOT_BUTTON_OPTIONS, 75 V_HOTSPOT_BUTTON_IFOPTIONS, 76 V_HOTSPOT_BUTTON_HELP, 77 78 V_MENU_ACCEPT, 79 V_MENU_CANCEL = -1, 80 81 V_INV_NEXTPAGE, 82 V_INV_PREVPAGE, 83 V_INV_CLOSE 84 }; 85 86 87 88 class window 89 { 90 91 public: 92 window(window *p); 93 virtual ~window(); 94 95 virtual bool draw() = 0; 96 virtual void set_caption(std::string str); 97 virtual void hide(); layout()98 virtual void layout() {}; 99 virtual void update_background(void); 100 101 eventresult event_handler(window* target, void* result, SDL_Event* event); 102 virtual eventresult handle_timer_event(window* target, void* result, int time); 103 virtual eventresult handle_mousemotion_event(window* target, void* result, 104 int xrel, int yrel, int state); 105 virtual eventresult handle_mousebuttonup_event(window* target, void* result, 106 int mouse_x, int mouse_y, int button, int state); 107 virtual eventresult handle_keydown_event(window* target, void* result, 108 int sym, int mod, int unicode); 109 virtual eventresult handle_resize_event(window* target, void* result, int res_w, int res_h); 110 virtual eventresult handle_other_event(window* target, void* result, SDL_Event* event); 111 get_wintype()112 window_type get_wintype() { return v_type; }; get_menu_id()113 void *get_menu_id() { return menu_id_v; }; 114 115 void draw_windows(); 116 window *walk_winlist(bool *descend); 117 window *get_window_from_point(point mouse); 118 bool intersects_invalid(); 119 get_w()120 int get_w() { return w; } get_h()121 int get_h() { return h; } 122 123 bool need_redraw; 124 bool visible; 125 126 virtual std::vector<window*> find_accel(char accel); 127 128 // protected: 129 window_type v_type; 130 std::string caption; 131 char accelerator; 132 char group_accelerator; 133 134 135 /* absolute coords; calculated before drawing */ 136 int abs_x, abs_y; 137 138 /* coords relative to parent */ 139 int x, y; 140 int w, h; 141 142 143 union { 144 void *menu_id_v; 145 int menu_id; 146 }; 147 148 window *first_child, *last_child; 149 window *parent; 150 window *sib_next, *sib_prev; 151 152 protected: 153 bool autobg; 154 SDL_Surface *background; 155 }; 156 157 extern window *ROOTWIN; 158 159 #endif 160