Apply the new ground_level method.
[crawl.git] / crawl-ref / source / tilesdl.h
blobfdaf9e2a8a4f9ae9f67631d3755f371fddaed82b
1 /*
2 * File: tilesdl.h
3 * Summary: SDL-related functionality for the tiles port
4 * Written by: Enne Walker
5 */
7 #ifdef USE_TILE
8 #ifndef TILESDL_H
9 #define TILESDL_H
11 #include "externs.h"
12 #include "tilereg.h"
13 #include "tiletex.h"
15 class Region;
16 class CRTRegion;
17 class CRTRegionSingleSelect;
18 class MenuRegion;
19 class TileRegion;
20 class DungeonRegion;
21 class GridRegion;
22 class InventoryRegion;
23 class SpellRegion;
24 class MemoriseRegion;
25 class ActorRegion;
26 class MonsterRegion;
27 class SkillRegion;
28 class CommandRegion;
29 class ActorRegion;
30 class TabbedRegion;
31 class MapRegion;
32 class ControlRegion;
33 class TitleRegion;
34 class DollEditRegion;
35 class StatRegion;
36 class MessageRegion;
38 struct map_cell;
40 typedef std::map<int, TabbedRegion*>::iterator tab_iterator;
42 enum key_mod
44 MOD_NONE = 0x0,
45 MOD_SHIFT = 0x1,
46 MOD_CTRL = 0x2,
47 MOD_ALT = 0x4,
50 struct MouseEvent
52 enum mouse_event_type
54 PRESS,
55 RELEASE,
56 MOVE,
59 enum mouse_event_button
61 NONE = 0x00,
62 LEFT = 0x01,
63 MIDDLE = 0x02,
64 RIGHT = 0x04,
65 SCROLL_UP = 0x08,
66 SCROLL_DOWN = 0x10,
69 // Padding for ui_event
70 unsigned char type;
72 // kind of event
73 mouse_event_type event;
74 // if PRESS or RELEASE, the button pressed
75 mouse_event_button button;
76 // bitwise-or of buttons currently pressed
77 unsigned short held;
78 // bitwise-or of key mods currently pressed
79 unsigned char mod;
80 // location of events in pixels and in window coordinate space
81 unsigned int px;
82 unsigned int py;
85 class FontWrapper;
86 class crawl_view_buffer;
88 class TilesFramework
90 public:
91 TilesFramework();
92 virtual ~TilesFramework();
94 bool initialise();
95 void shutdown();
96 void load_dungeon(const crawl_view_buffer &vbuf, const coord_def &gc);
97 void load_dungeon(const coord_def &gc);
98 int getch_ck();
99 void resize();
100 void layout_statcol();
101 void calculate_default_options();
102 void clrscr();
104 void cgotoxy(int x, int y, GotoRegion region = GOTO_CRT);
105 GotoRegion get_cursor_region() const;
106 int get_number_of_lines();
107 int get_number_of_cols();
109 void update_minimap(const coord_def &gc);
110 void clear_minimap();
111 void update_minimap_bounds();
112 void toggle_inventory_display();
113 void update_tabs();
115 void set_need_redraw(unsigned int min_tick_delay = 0);
116 bool need_redraw() const;
117 void redraw();
119 void place_cursor(cursor_type type, const coord_def &gc);
120 void clear_text_tags(text_tag_type type);
121 void add_text_tag(text_tag_type type, const std::string &tag,
122 const coord_def &gc);
123 void add_text_tag(text_tag_type type, const monster* mon);
125 bool initialise_items();
127 const coord_def &get_cursor() const;
129 void add_overlay(const coord_def &gc, tileidx_t idx);
130 void clear_overlays();
132 void draw_title();
133 void update_title_msg(std::string load_msg);
134 void hide_title();
136 void draw_doll_edit();
138 MenuRegion *get_menu() { return m_region_menu; }
139 bool is_fullscreen() { return m_fullscreen; }
141 FontWrapper* get_crt_font() { return m_fonts.at(m_crt_font).font; }
142 CRTRegion* get_crt() { return m_region_crt; }
143 const ImageManager* get_image_manager() { return m_image; }
144 int to_lines(int num_tiles);
145 protected:
146 int load_font(const char *font_file, int font_size,
147 bool default_on_fail, bool outline);
148 int handle_mouse(MouseEvent &event);
150 void use_control_region(ControlRegion *region);
152 // screen pixel dimensions
153 coord_def m_windowsz;
154 // screen pixels per view cell
155 coord_def m_viewsc;
157 bool m_fullscreen;
158 bool m_need_redraw;
160 enum TabID
162 TAB_ITEM,
163 TAB_SPELL,
164 TAB_MEMORISE,
165 TAB_MONSTER,
166 TAB_SKILL,
167 TAB_COMMAND,
168 TAB_MAX,
171 enum LayerID
173 LAYER_NORMAL,
174 LAYER_CRT,
175 LAYER_TILE_CONTROL,
176 LAYER_MAX,
179 class Layer
181 public:
182 // Layers don't own these regions
183 std::vector<Region*> m_regions;
185 Layer m_layers[LAYER_MAX];
186 LayerID m_active_layer;
188 // Normal layer
189 TileRegionInit m_init;
190 DungeonRegion *m_region_tile;
191 StatRegion *m_region_stat;
192 MessageRegion *m_region_msg;
193 MapRegion *m_region_map;
194 TabbedRegion *m_region_tab;
195 InventoryRegion *m_region_inv;
196 SpellRegion *m_region_spl;
197 MemoriseRegion *m_region_mem;
198 MonsterRegion *m_region_mon;
199 SkillRegion *m_region_skl;
200 CommandRegion *m_region_cmd;
202 std::map<int, TabbedRegion*> m_tabs;
204 // Full-screen CRT layer
205 CRTRegion *m_region_crt;
206 MenuRegion *m_region_menu;
208 struct font_info
210 std::string name;
211 int size;
212 bool outline;
213 FontWrapper *font;
215 std::vector<font_info> m_fonts;
216 int m_crt_font;
217 int m_msg_font;
218 int m_tip_font;
219 int m_lbl_font;
221 int m_tab_margin;
222 int m_stat_col;
223 int m_stat_x_divider;
224 int m_statcol_top;
225 int m_statcol_bottom;
226 int m_map_pixels;
228 void do_layout();
229 int calc_tab_lines(const int num_elements);
230 void place_tab(int idx);
231 void autosize_minimap();
232 void place_minimap();
233 void resize_inventory();
234 void place_gold_turns();
236 ImageManager *m_image;
238 // Mouse state.
239 unsigned short m_buttons_held;
240 unsigned char m_key_mod;
241 coord_def m_mouse;
242 unsigned int m_last_tick_moved;
243 unsigned int m_last_tick_redraw;
245 std::string m_tooltip;
247 int m_screen_width;
248 int m_screen_height;
250 struct cursor_loc
252 cursor_loc() { reset(); }
253 void reset() { reg = NULL; cx = cy = -1; mode = MOUSE_MODE_MAX; }
254 bool operator==(const cursor_loc &rhs) const
256 return (rhs.reg == reg
257 && rhs.cx == cx
258 && rhs.cy == cy
259 && rhs.mode == mode);
261 bool operator!=(const cursor_loc &rhs) const
263 return !(*this == rhs);
266 Region *reg;
267 int cx, cy;
268 mouse_mode mode;
270 cursor_loc m_cur_loc;
273 // Main interface for tiles functions
274 extern TilesFramework tiles;
276 #ifdef TARGET_COMPILER_MINGW
277 #ifndef alloca
278 // Srsly, MinGW, wtf?
279 void *alloca(size_t);
280 #endif
281 #endif
283 #endif
284 #endif