summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/libgui.h
blob: 30bbafdf3f79ef07c5b8f945675c81c933e8dd5b (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
/*
 *  File:       libgui.cc
 *  Summary:    Functions for x11
 *  Written by: M.Itakura (?)
 *
 *  Modified for Crawl Reference by $Author: j-p-e-g $ on $Date: 2008-03-07 $
 */

#ifndef LIBGUI_H
#define LIBGUI_H
#ifdef USE_TILE

#ifdef USE_X11
  #include <X11/Xlib.h>
  #include <X11/X.h>
#elif defined(WINDOWS)
  #include <windows.h>
  // windows.h defines 'near' as an empty string for compatibility.
  // This breaks the use of that as a variable name.  Urgh.
  #ifdef near
    #undef near
  #endif
  #include <commdlg.h>
#endif

#include "defines.h"

typedef unsigned int screen_buffer_t;

void libgui_init();
void libgui_shutdown();

void edit_prefs();
/* ***********************************************************************
 Minimap related
 * called from: misc view spells2
 * *********************************************************************** */
void GmapInit(bool upd_tile);
void GmapDisplay(int linex, int liney);
void GmapUpdate(int x, int y, int what, bool upd_tile = true);

//dungeon display size
extern int tile_dngn_x;
extern int tile_dngn_y;

void set_mouse_enabled(bool enabled);

// mouse ops
// set mouse op mode
void mouse_set_mode(int mode);
// get mouse mode
int mouse_get_mode();

class mouse_control
{
public:
    mouse_control(int mode)
    {
        oldmode = mouse_get_mode();
        mouse_set_mode(mode);
    }

    ~mouse_control()
    {
        mouse_set_mode(oldmode);
    }
private:
    int oldmode;
};

struct coord_def;
struct crawl_view_geometry;

void gui_init_view_params(crawl_view_geometry &geom);

// If mouse on dungeon map, returns true and sets gc.
// Otherwise, it just returns false.
bool gui_get_mouse_grid_pos(coord_def &gc);

enum InvAction
{
    INV_DROP,
    INV_USE,  // primary   inventory use
    INV_USE2, // secondary inventory use
    INV_PICKUP,
    INV_VIEW,
    INV_USE_FLOOR,
    INV_EAT_FLOOR,
    INV_SELECT,
    INV_NUMACTIONS
};

void gui_get_mouse_inv(int &idx, InvAction &act);

void tile_place_cursor(int x, int y, bool display);

void lock_region(int r);
void unlock_region(int r);

enum ScreenRegion
{
    REGION_NONE,
    REGION_CRT,
    REGION_STAT,  // stat area
    REGION_MSG,   // message area
    REGION_MAP,   // overview map area
    REGION_DNGN,
    REGION_TDNGN,
    REGION_INV1,  // items in inventory
    REGION_INV2,  // items in inventory?
    REGION_XMAP,
    REGION_TIP,
    NUM_REGIONS
};

/* text display */
void clrscr(void);
void textcolor(int color);
void cgotoxy(int x, int y, int region = GOTO_CRT);
void message_out(int mline, int colour, const char *str, int firstcol = 0,
                 bool newline = true);
void clear_message_window();
int wherex();
int wherey();
void cprintf(const char *format,...);    
void clear_to_end_of_line(void);
void clear_to_end_of_screen(void);
int get_number_of_lines(void);
int get_number_of_cols(void);
void get_input_line_gui(char *const buff, int len);
void _setcursortype(int curstype);
void textbackground(int bg);
void textcolor(int col);
void putch(unsigned char chr);
void putwch(unsigned chr);
void put_colour_ch(int colour, unsigned ch);
void writeWChar(unsigned char *ch);

void puttext(int x, int y, int lx, int ly, unsigned char *buf, 
             bool mono = false, int where = 0);
void ViewTextFile(const char *name);

#define textattr(x) textcolor(x)
void set_cursor_enabled(bool enabled);
bool is_cursor_enabled();
void enable_smart_cursor(bool);
bool is_smart_cursor_enabled();

#ifdef USE_X11
char *strlwr(char *str); // non-unix
int itoa(int value, char *strptr, int radix); // non-unix
int stricmp(const char *str1, const char *str2); // non-unix
#endif

void delay(unsigned long time);
int kbhit(void);
void window(int x1, int y1, int x2, int y2);
void update_screen(void);
int getch();
int getch_ck();

// types of events
#define EV_KEYIN    1
#define EV_MOVE     2
#define EV_BUTTON   3
#define EV_UNBUTTON 4

#define _NORMALCURSOR 1
#define _NOCURSOR     0

#define textcolor_cake(col) textcolor((col)<<4 | (col))

#endif // USE_TILE
#endif // LIBGUI_H