Apply the new ground_level method.
[crawl.git] / crawl-ref / source / libgui.cc
blobe07794d5ea72ee058c409de1c2f946e538a7f46e
1 /*
2 * File: libgui.cc
3 * Summary: Functions that any display port needs to implement.
4 * Written by: M.Itakura
5 */
7 #include "AppHdr.h"
9 #ifdef USE_TILE
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
15 #include "cio.h"
16 #include "defines.h"
17 #include "env.h"
18 #include "externs.h"
19 #include "tilereg-text.h"
20 #include "message.h"
21 #include "stash.h"
22 #include "state.h"
23 #include "stuff.h"
24 #include "terrain.h"
25 #include "tiledef-main.h"
26 #include "travel.h"
27 #include "viewgeom.h"
28 #include "windowmanager.h"
30 int m_getch()
32 return getch();
35 void set_mouse_enabled(bool enabled)
37 crawl_state.mouse_enabled = enabled;
40 void gui_init_view_params(crawl_view_geometry &geom)
42 // The tile version handles its own layout on a pixel-by-pixel basis.
43 // Pretend that all of the regions start at character location (1,1).
45 geom.termp.x = 1;
46 geom.termp.y = 1;
48 geom.termsz.x = 80;
49 geom.termsz.y = 24;
51 geom.viewp.x = 1;
52 geom.viewp.y = 1;
54 geom.hudp.x = 1;
55 geom.hudp.y = 1;
57 geom.msgp.x = 1;
58 geom.msgp.y = 1;
60 geom.mlistp.x = 1;
61 geom.mlistp.y = 1;
62 geom.mlistsz.x = 0;
63 geom.mlistsz.y = 0;
65 geom.viewsz.x = 17;
66 geom.viewsz.y = 17;
69 int putch(unsigned char chr)
71 // object's method
72 TextRegion::text_mode->putch(chr);
73 return 0;
76 int putwch(unsigned chr)
78 // No unicode support.
79 putch(static_cast<unsigned char>(chr));
80 return 0;
83 void writeWChar(unsigned char *ch)
85 // object's method
86 TextRegion::text_mode->writeWChar(ch);
89 void clear_to_end_of_line()
91 // object's method
92 TextRegion::text_mode->clear_to_end_of_line();
95 int cprintf(const char *format,...)
97 char buffer[2048]; // One full screen if no control seq...
98 va_list argp;
99 va_start(argp, format);
100 vsnprintf(buffer, sizeof(buffer), format, argp);
101 va_end(argp);
102 // object's method
103 TextRegion::text_mode->addstr(buffer);
104 return 0;
107 void textcolor(int color)
109 TextRegion::textcolor(color);
112 void textbackground(int bg)
114 TextRegion::textbackground(bg);
117 void set_cursor_enabled(bool enabled)
119 if (enabled)
120 TextRegion::_setcursortype(1);
121 else
122 TextRegion::_setcursortype(0);
125 bool is_cursor_enabled()
127 if (TextRegion::cursor_flag)
128 return (true);
130 return (false);
133 int wherex()
135 return TextRegion::wherex();
138 int wherey()
140 return TextRegion::wherey();
143 int get_number_of_lines()
145 return tiles.get_number_of_lines();
148 int get_number_of_cols()
150 return tiles.get_number_of_cols();
153 void put_colour_ch(int colour, unsigned ch)
155 textcolor(colour);
156 putwch(ch);
159 int window(int x1, int y1, int x2, int y2)
161 return 0;
164 int getch_ck()
166 return (tiles.getch_ck());
169 int getch()
171 return getch_ck();
174 int clrscr()
176 tiles.clrscr();
177 return 0;
180 void cgotoxy(int x, int y, GotoRegion region)
182 tiles.cgotoxy(x, y, region);
185 coord_def cgetpos(GotoRegion region)
187 ASSERT(region == get_cursor_region());
188 return (coord_def(wherex(), wherey()));
191 GotoRegion get_cursor_region()
193 return (tiles.get_cursor_region());
196 void delay(int ms)
198 tiles.redraw();
199 wm->delay(ms);
202 void update_screen()
204 tiles.set_need_redraw();
207 int kbhit()
209 // Look for the presence of any keyboard events in the queue.
210 int count = wm->get_event_count(WM_KEYDOWN);
211 return (count > 0);
214 #ifdef UNIX
215 int itoa(int value, char *strptr, int radix)
217 unsigned int bitmask = 32768;
218 int ctr = 0;
219 int startflag = 0;
221 if (radix == 10)
223 sprintf(strptr, "%i", value);
225 else if (radix == 2) /* int to "binary string" */
227 while (bitmask)
229 if (value & bitmask)
231 startflag = 1;
232 sprintf(strptr + ctr, "1");
234 else if (startflag)
236 sprintf(strptr + ctr, "0");
239 bitmask = bitmask >> 1;
240 if (startflag)
241 ctr++;
244 if (!startflag) /* Special case if value == 0 */
245 sprintf((strptr + ctr++), "0");
247 strptr[ctr] = (char) NULL;
249 return (0); /* Me? Fail? Nah. */
253 // Convert string to lowercase.
254 char *strlwr(char *str)
256 unsigned int i;
258 for (i = 0; i < strlen(str); i++)
259 str[i] = tolower(str[i]);
261 return (str);
264 #endif // #ifdef UNIX
265 #endif // #ifdef USE_TILE