summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/tilereg.h
blob: 50c631752699d88bfac0537fc9a514d52699b65b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
/*
 *  File:       tilereg.h
 *  Created by: ennewalker on Sat Jan 5 01:33:53 2008 UTC
 *
 *  Modified for Crawl Reference by $Author: j-p-e-g $ on $Date: 2008-03-07 $
 */

#ifdef USE_TILE
#ifndef TILEREG_H
#define TILEREG_H

#include "tiletex.h"
#include "tiles.h"
#include <vector>

class ImageManager
{
public:
    ImageManager();
    virtual ~ImageManager();

    bool load_textures();
    bool load_item_texture();
    void unload_textures();

    FixedVector<TilesTexture, TEX_MAX> m_textures;
};

// Windows and internal regions (text, dungeon, map, etc)
class MouseEvent;

class Region
{
public:
    Region();
    virtual ~Region();

    void resize(unsigned int mx, unsigned int my);
    void place(unsigned int sx, unsigned int sy, unsigned int margin);
    void resize_to_fit(int wx, int wy);

    // Returns true if the mouse position is over the region
    // If true, then cx and cy are set in the range [0..mx-1], [0..my-1]
    virtual bool mouse_pos(int mouse_x, int mouse_y, int &cx, int &cy);

    bool inside(unsigned int px, unsigned int py);
    virtual bool update_tip_text(std::string &tip) { return false; }
    virtual int handle_mouse(MouseEvent &event) = 0;

    virtual void render() = 0;
    virtual void clear() = 0;

    // Geometry
    // <-----------------wx----------------------->
    // sx     ox                                ex
    // |margin| text/tile area            |margin|

    // Offset in pixels
    unsigned int ox;
    unsigned int oy;

    // Unit size
    unsigned int dx;
    unsigned int dy;

    // Region size in dx/dy
    unsigned int mx;
    unsigned int my;

    // Width of the region in pixels
    unsigned int wx;
    unsigned int wy;

    // Start position in pixels (top left)
    unsigned int sx;
    unsigned int sy;

    // End position in pixels (bottom right)
    unsigned int ex;
    unsigned int ey;

    static coord_def NO_CURSOR;

protected:
    void recalculate();
    virtual void on_resize() = 0;
};

class FTFont;

class TextRegion : public Region
{
public:
    TextRegion(FTFont *font);
    ~TextRegion();

    virtual void render();
    virtual void clear();

    // STATIC -
    // TODO enne - move these to TilesFramework?

    // where now printing? what color?
    static unsigned int print_x;
    static unsigned int print_y;
    static int text_col;
    // which region now printing?
    static class TextRegion *text_mode;
    // display cursor? where is the cursor now?
    static int cursor_flag;
    static class TextRegion *cursor_region;
    static unsigned int cursor_x;
    static unsigned int cursor_y;

    // class methods
    static void cgotoxy(int x, int y);
    static int wherex();
    static int wherey();
    //static int get_number_of_lines(void);
    static void _setcursortype(int curstype);
    static void textbackground(int bg);
    static void textcolor(int col);

    // Object's method
    void clear_to_end_of_line(void);
    void putch(unsigned char chr);
    void writeWChar(unsigned char *ch);

    unsigned char *cbuf; //text backup
    unsigned char *abuf; //textcolor backup

    int cx_ofs; //cursor x offset
    int cy_ofs; //cursor y offset

    void addstr(char *buffer);
    void addstr_aux(char *buffer, unsigned int len);
    void adjust_region(int *x1, int *x2, int y);
    void scroll();

    //Sys dep
    void draw_cursor(int x, int y, int width);
    void draw_cursor(int x, int y);
    void erase_cursor();

protected:
    virtual void on_resize();
    FTFont *m_font;
};

class StatRegion : public TextRegion
{
public:
    StatRegion(FTFont *font);

    virtual int handle_mouse(MouseEvent &event);
    virtual bool update_tip_text(std::string &tip);
};

class MessageRegion : public TextRegion
{
public:
    MessageRegion(FTFont *font);

    virtual int handle_mouse(MouseEvent &event);
    virtual bool update_tip_text(std::string &tip);
};

class CRTRegion : public TextRegion
{
public:
    CRTRegion(FTFont *font);

    virtual int handle_mouse(MouseEvent &event);
};

class TileRegion : public Region
{
public:
    TileRegion(ImageManager *im, unsigned int tile_x, unsigned int tile_y);
    ~TileRegion();

protected:
    void add_quad(TextureID tex, unsigned int idx, unsigned int x, unsigned int y, int ofs_x = 0, int ofs_y = 0);

    ImageManager *m_image;

    struct tile_vert
    {
        float pos_x;
        float pos_y;
        float tex_x;
        float tex_y;
    };

    std::vector<tile_vert> m_verts;
};

struct TextTag
{
    std::string tag;
    coord_def gc;
};

enum cursor_type
{
    CURSOR_MOUSE,
    CURSOR_TUTORIAL,
    CURSOR_MAX
};

enum text_tag_type
{
    TAG_NAMED_MONSTER,
    TAG_TUTORIAL,
    TAG_CELL_DESC,
    TAG_MAX
};

class DungeonRegion : public TileRegion
{
public:
    DungeonRegion(ImageManager *im, FTFont *tag_font,
                  unsigned int tile_x, unsigned int tile_y);
    virtual ~DungeonRegion();

    virtual void render();
    virtual void clear();
    virtual int handle_mouse(MouseEvent &event);
    virtual bool update_tip_text(std::string &tip);
    virtual void on_resize();

    void load_dungeon(unsigned int* tileb, int cx_to_gx, int cy_to_gy);
    void place_cursor(cursor_type type, const coord_def &gc);
    bool on_screen(const coord_def &gc) const;

    void clear_text_tags(text_tag_type type);
    void add_text_tag(text_tag_type type, const std::string &tag,
                      const coord_def &gc);

    const coord_def &get_cursor() const { return m_cursor[CURSOR_MOUSE]; }

protected:
    void draw_background(unsigned int bg, unsigned int x, unsigned int y);
    bool draw_objects(unsigned int fg, unsigned int x, unsigned int y);
    void draw_player(unsigned int x, unsigned int y);
    void draw_monster(unsigned int fg, unsigned int x, unsigned int y);
    void draw_foreground(unsigned int bg, unsigned int fg, unsigned int x, unsigned int y);
    void draw_doll(dolls_data &doll, unsigned int x, unsigned int y);
    void draw_draco(int colour, int mon_idx, int equ_tile, unsigned int x, unsigned int y);
    void draw_cursor(cursor_type type, unsigned int tile);

    void add_quad_doll(unsigned int part, unsigned int idx, int ymax, unsigned int x, unsigned int y, int ox, int oy);

    int get_buffer_index(const coord_def &gc);
    void to_screen_coords(const coord_def &gc, coord_def& pc) const;
    
    std::vector<unsigned int> m_tileb; 
    int m_cx_to_gx;
    int m_cy_to_gy;
    coord_def m_cursor[CURSOR_MAX];
    std::vector<TextTag> m_tags[TAG_MAX];
    FTFont *m_tag_font;
};

class InventoryTile
{
public:
    InventoryTile();

    // tile index
    int tile;
    // mitm/you.inv idx (depends on flag & TILEI_FLAG_FLOOR)
    int idx;
    // quantity of this item (0-999 valid, >999 shows as 999, <0 shows nothing)
    short quantity;
    // bitwise-or of TILEI_FLAG enumeration
    unsigned short flag;
    // for inventory items, the slot
    char key;

    bool empty() const;
};

class InventoryRegion : public TileRegion
{
public:
    InventoryRegion(ImageManager *im, unsigned int tile_x, unsigned int tile_y);
    virtual ~InventoryRegion();

    virtual void clear();
    virtual void render();
    virtual void on_resize();
    virtual int handle_mouse(MouseEvent &event);

    void update(unsigned int num, InventoryTile *items);
    void update_slot(unsigned int slot, InventoryTile &item);
    virtual bool update_tip_text(std::string &tip);

protected:
    void pack_tile(unsigned int x, unsigned int y, unsigned int idx);
    void pack_verts();
    void add_quad_char(char c, unsigned int x, unsigned int y, int ox, int oy);
    void place_cursor(const coord_def &cursor);
    unsigned int cursor_index() const;

    unsigned int m_base_verts;
    std::vector<InventoryTile> m_items;
    unsigned char *m_flavour;

    coord_def m_cursor;

    bool m_need_to_pack;
};

enum map_colour
{
    MAP_BLACK,
    MAP_DKGREY,
    MAP_MDGREY,
    MAP_LTGREY,
    MAP_WHITE,
    MAP_BLUE,
    MAP_LTBLUE,
    MAP_DKBLUE,
    MAP_GREEN,
    MAP_LTGREEN,
    MAP_DKGREEN,
    MAP_CYAN,
    MAP_LTCYAN,
    MAP_DKCYAN,
    MAP_RED,
    MAP_LTRED,
    MAP_DKRED,
    MAP_MAGENTA,
    MAP_LTMAGENTA,
    MAP_DKMAGENTA,
    MAP_YELLOW,
    MAP_LTYELLOW,
    MAP_DKYELLOW,
    MAP_BROWN,
    MAX_MAP_COL
};

class MapRegion : public Region
{
public:
    MapRegion(unsigned int pixsz);
    ~MapRegion();

    virtual void render();
    virtual void clear();
    virtual int handle_mouse(MouseEvent &event);
    virtual bool update_tip_text(std::string &tip);

    void init_colours();
    void set(unsigned int gx, unsigned int gy, map_feature f);
    void set_window(const coord_def &start, const coord_def &end);

protected:
    virtual void on_resize();
    void update_offsets();

    map_colour m_colours[MF_MAX];
    unsigned int m_min_gx, m_max_gx, m_min_gy, m_max_gy;
    coord_def m_win_start;
    coord_def m_win_end;
    unsigned char *m_buf;
    bool m_far_view;
};


#endif
#endif