summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/tilereg.h
diff options
context:
space:
mode:
authorennewalker <ennewalker@c06c8d41-db1a-0410-9941-cceddc491573>2008-07-15 04:07:07 +0000
committerennewalker <ennewalker@c06c8d41-db1a-0410-9941-cceddc491573>2008-07-15 04:07:07 +0000
commitaf3cd3ff34ef5da884b2c673afe1321f0cf372e7 (patch)
treea574c2155f571f216f29c44b29e333ea320322a6 /crawl-ref/source/tilereg.h
parent71ed1a7fd6819916d79d194126c061ac1f087b11 (diff)
downloadcrawl-ref-af3cd3ff34ef5da884b2c673afe1321f0cf372e7.tar.gz
crawl-ref-af3cd3ff34ef5da884b2c673afe1321f0cf372e7.zip
Large tiles-related changes. Platform-specific rendering removed and replaced with SDL/OpenGL.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@6550 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/tilereg.h')
-rw-r--r--crawl-ref/source/tilereg.h371
1 files changed, 371 insertions, 0 deletions
diff --git a/crawl-ref/source/tilereg.h b/crawl-ref/source/tilereg.h
new file mode 100644
index 0000000000..dcc8b92606
--- /dev/null
+++ b/crawl-ref/source/tilereg.h
@@ -0,0 +1,371 @@
+/*
+ * 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_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 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