summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2006-12-17 14:30:45 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2006-12-17 14:30:45 +0000
commit7ecc914a00b10b46579a54feaf9ea72dea8856be (patch)
tree7d4facea90a5b5854afff3bd4848a36fa93798bd
parent3924236bc9cec9165686f17e8854e4899bd64019 (diff)
downloadcrawl-ref-7ecc914a00b10b46579a54feaf9ea72dea8856be.tar.gz
crawl-ref-7ecc914a00b10b46579a54feaf9ea72dea8856be.zip
Cursor fixes for 0.1.6.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/branches/stone_soup-0.1.6@663 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r--crawl-ref/source/acr.cc23
-rw-r--r--crawl-ref/source/beam.cc1
-rw-r--r--crawl-ref/source/libdos.cc56
-rw-r--r--crawl-ref/source/libdos.h20
-rw-r--r--crawl-ref/source/libunix.cc10
-rw-r--r--crawl-ref/source/libunix.h5
-rw-r--r--crawl-ref/source/libutil.h8
-rw-r--r--crawl-ref/source/libw32c.cc41
-rw-r--r--crawl-ref/source/libw32c.h8
-rw-r--r--crawl-ref/source/menu.cc2
-rw-r--r--crawl-ref/source/message.cc16
-rw-r--r--crawl-ref/source/shopping.cc1
-rw-r--r--crawl-ref/source/spl-book.cc1
-rw-r--r--crawl-ref/source/spl-cast.cc3
-rw-r--r--crawl-ref/source/view.cc7
15 files changed, 118 insertions, 84 deletions
diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc
index 81d702e782..e0367a9e47 100644
--- a/crawl-ref/source/acr.cc
+++ b/crawl-ref/source/acr.cc
@@ -884,15 +884,22 @@ static void input() {
return;
}
- command_type cmd = get_next_cmd();
-
- // [dshaligram] If get_next_cmd encountered a Lua macro binding, your turn
- // may be ended by the first invoke of the macro.
- if (!you.turn_is_over && cmd != CMD_NEXT_CMD)
- process_command( cmd );
+ {
+ // Enable the cursor to read input. The cursor stays on while
+ // the command is being processed, so subsidiary prompts
+ // shouldn't need to turn it on explicitly.
+ cursor_control con(true);
+ command_type cmd = get_next_cmd();
- if ( you.turn_is_over ) {
+ // [dshaligram] If get_next_cmd encountered a Lua macro
+ // binding, your turn may be ended by the first invoke of the
+ // macro.
+ if (!you.turn_is_over && cmd != CMD_NEXT_CMD)
+ process_command( cmd );
+ }
+ if (you.turn_is_over)
+ {
if ( apply_berserk_penalty )
do_berserk_no_combat_penalty();
@@ -2816,6 +2823,8 @@ static bool initialise(void)
init_char_table(Options.char_set);
init_feature_table();
#endif
+
+ set_cursor_enabled(false);
viewwindow(1, false); // This just puts the view up for the first turn.
activate_notes(true);
diff --git a/crawl-ref/source/beam.cc b/crawl-ref/source/beam.cc
index d91bdc1419..522dadc077 100644
--- a/crawl-ref/source/beam.cc
+++ b/crawl-ref/source/beam.cc
@@ -1234,6 +1234,7 @@ void fire_beam( struct bolt &pbolt, item_def *item )
bool beamTerminate; // has beam been 'stopped' by something?
int tx = 0, ty = 0; // test(new) x,y - integer
int rangeRemaining;
+ cursor_control coff(false);
beam_message_cache.clear();
diff --git a/crawl-ref/source/libdos.cc b/crawl-ref/source/libdos.cc
index 4eb30860f0..86c7aec1b6 100644
--- a/crawl-ref/source/libdos.cc
+++ b/crawl-ref/source/libdos.cc
@@ -1,21 +1,35 @@
-/*
- * File: libdos.cc
- * Summary: Functions for DOS support.
- * Written by: Darshan Shaligram
- *
- * Added for Crawl Reference by $Author: nlanza $ on $Date: 2006-09-26T03:22:57.300929Z $
- */
-
-// Every .cc must include AppHdr or bad things happen.
-#include "AppHdr.h"
-#include <termios.h>
-
-void init_libdos()
-{
- struct termios charmode;
-
- tcgetattr (0, &charmode);
- // Ignore Ctrl-C
- charmode.c_lflag &= ~ISIG;
- tcsetattr (0, TCSANOW, &charmode);
-}
+/*
+ * File: libdos.cc
+ * Summary: Functions for DOS support.
+ * Written by: Darshan Shaligram
+ *
+ * Added for Crawl Reference by $Author: nlanza $ on $Date: 2006-09-26T03:22:57.300929Z $
+ */
+
+// Every .cc must include AppHdr or bad things happen.
+#include "AppHdr.h"
+#include <termios.h>
+#include <conio.h>
+
+static bool cursor_is_enabled = true;
+
+void init_libdos()
+{
+ struct termios charmode;
+
+ tcgetattr (0, &charmode);
+ // Ignore Ctrl-C
+ charmode.c_lflag &= ~ISIG;
+ tcsetattr (0, TCSANOW, &charmode);
+}
+
+void set_cursor_enabled(bool enabled)
+{
+ cursor_is_enabled = enabled;
+ _setcursortype( enabled? _NORMALCURSOR : _NOCURSOR );
+}
+
+bool is_cursor_enabled()
+{
+ return (cursor_is_enabled);
+}
diff --git a/crawl-ref/source/libdos.h b/crawl-ref/source/libdos.h
index d934171a98..b6fd3d6c05 100644
--- a/crawl-ref/source/libdos.h
+++ b/crawl-ref/source/libdos.h
@@ -1,9 +1,11 @@
-#ifndef __LIBDOS_H__
-#define __LIBDOS_H__
-
-void init_libdos();
-
-inline void enable_smart_cursor(bool ) { }
-inline bool is_smart_cursor_enabled() { return (false); }
-
-#endif
+#ifndef __LIBDOS_H__
+#define __LIBDOS_H__
+
+void init_libdos();
+
+inline void enable_smart_cursor(bool ) { }
+inline bool is_smart_cursor_enabled() { return (false); }
+void set_cursor_enabled(bool enabled);
+bool is_cursor_enabled();
+
+#endif
diff --git a/crawl-ref/source/libunix.cc b/crawl-ref/source/libunix.cc
index 02b8d0d8f5..39efcf371d 100644
--- a/crawl-ref/source/libunix.cc
+++ b/crawl-ref/source/libunix.cc
@@ -69,6 +69,8 @@ int Character_Set = CHARACTER_SET;
short FG_COL = WHITE;
short BG_COL = BLACK;
+static bool cursor_is_enabled = true;
+
static unsigned int convert_to_curses_attr( int chattr )
{
switch (chattr & CHATTR_ATTRMASK)
@@ -401,10 +403,14 @@ int clrscr()
return (retval);
}
+void set_cursor_enabled(bool enabled)
+{
+ curs_set(cursor_is_enabled = enabled);
+}
-void _setcursortype(int curstype)
+bool is_cursor_enabled()
{
- curs_set(curstype);
+ return (cursor_is_enabled);
}
inline unsigned get_brand(int col)
diff --git a/crawl-ref/source/libunix.h b/crawl-ref/source/libunix.h
index 732c383133..c619cf114d 100644
--- a/crawl-ref/source/libunix.h
+++ b/crawl-ref/source/libunix.h
@@ -4,8 +4,6 @@
// Some replacement routines missing in gcc
-#define _NORMALCURSOR 1
-#define _NOCURSOR 0
#define O_BINARY O_RDWR
char *strlwr(char *str);
@@ -30,7 +28,6 @@ int get_number_of_lines_from_curses(void);
int get_number_of_cols_from_curses(void);
void get_input_line_from_curses( char *const buff, int len );
-void _setcursortype(int curstype);
void delay(unsigned long time);
void unixcurses_shutdown(void);
void unixcurses_startup(void);
@@ -41,6 +38,8 @@ void textattr(int col);
void set_altcharset(bool alt_on);
bool get_altcharset();
+void set_cursor_enabled(bool enabled);
+bool is_cursor_enabled();
inline void enable_smart_cursor(bool) { }
inline bool is_smart_cursor_enabled() { return (false); }
diff --git a/crawl-ref/source/libutil.h b/crawl-ref/source/libutil.h
index 2da46f421b..6b31b93728 100644
--- a/crawl-ref/source/libutil.h
+++ b/crawl-ref/source/libutil.h
@@ -128,14 +128,14 @@ enum KEYS
class cursor_control
{
public:
- cursor_control(bool cs)
- : cstate(cs), smartcstate( is_smart_cursor_enabled() )
+ cursor_control(bool cursor_enabled)
+ : cstate(is_cursor_enabled()), smartcstate(is_smart_cursor_enabled())
{
enable_smart_cursor(false);
- _setcursortype(cs? _NORMALCURSOR : _NOCURSOR);
+ set_cursor_enabled(cursor_enabled);
}
~cursor_control() {
- _setcursortype(cstate? _NOCURSOR : _NORMALCURSOR);
+ set_cursor_enabled(cstate);
enable_smart_cursor(smartcstate);
}
private:
diff --git a/crawl-ref/source/libw32c.cc b/crawl-ref/source/libw32c.cc
index 294ad71522..09501eb5bd 100644
--- a/crawl-ref/source/libw32c.cc
+++ b/crawl-ref/source/libw32c.cc
@@ -81,7 +81,7 @@ char oldTitle[80];
static HANDLE inbuf = NULL;
static HANDLE outbuf = NULL;
static int current_color = -1;
-static bool current_cursor = _NOCURSOR;
+static bool cursor_is_enabled = false;
// dirty line (sx,ex,y)
static int chsx=0, chex=0, chy=-1;
// cursor position (start at 0,0 --> 1,1)
@@ -104,7 +104,7 @@ static bool w32_smart_cursor = true;
#define WIN32COLOR(col) (WORD)(col)
static void writeChar(char c);
static void bFlush(void);
-static void _setcursortype_internal(int curstype);
+static void _setcursortype_internal(bool curstype);
// [ds] Unused for portability reasons
/*
@@ -288,7 +288,7 @@ void bFlush(void)
chy = -1;
// if cursor is not NOCURSOR, update screen
- if (current_cursor != _NOCURSOR)
+ if (cursor_is_enabled)
{
COORD xy;
xy.X = cx;
@@ -383,7 +383,7 @@ void init_libw32c(void)
textcolor(DARKGREY);
// initialise cursor to NONE.
- _setcursortype_internal(_NOCURSOR);
+ _setcursortype_internal(false);
// buffering defaults to ON -- very important!
setBuffering(true);
@@ -425,37 +425,42 @@ void deinit_libw32c(void)
setStringInput(true);
// set cursor and normal textcolor
- _setcursortype_internal(_NORMALCURSOR);
+ _setcursortype_internal(true);
textcolor(DARKGREY);
// finally, restore title
SetConsoleTitle( oldTitle );
}
-void _setcursortype(int curstype)
+void set_cursor_enabled(bool enabled)
{
if (!w32_smart_cursor)
- _setcursortype_internal(curstype);
+ _setcursortype_internal(enabled);
}
-void _setcursortype_internal(int curstype)
+bool is_cursor_enabled()
+{
+ return (cursor_is_enabled);
+}
+
+void _setcursortype_internal(bool curstype)
{
CONSOLE_CURSOR_INFO cci;
- if (curstype == current_cursor)
- return;
+ if (curstype == cursor_is_enabled)
+ return;
cci.dwSize = 5;
cci.bVisible = curstype? TRUE : FALSE;
- current_cursor = curstype;
+ cursor_is_enabled = curstype;
CLOCKIN
SetConsoleCursorInfo( outbuf, &cci );
CLOCKOUT(1)
// now, if we just changed from NOCURSOR to CURSOR,
// actually move screen cursor
- if (current_cursor != _NOCURSOR)
- gotoxy(cx+1, cy+1);
+ if (cursor_is_enabled)
+ gotoxy(cx+1, cy+1);
}
void clrscr(void)
@@ -513,7 +518,7 @@ void gotoxy(int x, int y)
cy = y-1;
// if cursor is not NOCURSOR, update screen
- if (current_cursor != _NOCURSOR)
+ if (cursor_is_enabled)
{
COORD xy;
xy.X = cx;
@@ -724,9 +729,9 @@ int getch_ck(void)
return repeat_key;
}
- const bool oldValue = current_cursor;
+ const bool oldValue = cursor_is_enabled;
if (w32_smart_cursor)
- _setcursortype_internal(_NORMALCURSOR);
+ _setcursortype_internal(true);
while(1)
{
@@ -820,10 +825,10 @@ int getConsoleString(char *buf, int maxlen)
setStringInput( true );
// force cursor
- const bool oldValue = current_cursor;
+ const bool oldValue = cursor_is_enabled;
if (w32_smart_cursor)
- _setcursortype_internal(_NORMALCURSOR);
+ _setcursortype_internal(true);
// set actual screen color to current color
SetConsoleTextAttribute( outbuf, WIN32COLOR(current_color) );
diff --git a/crawl-ref/source/libw32c.h b/crawl-ref/source/libw32c.h
index 37372976ee..6bdfa5acc3 100644
--- a/crawl-ref/source/libw32c.h
+++ b/crawl-ref/source/libw32c.h
@@ -16,12 +16,12 @@ typedef std::basic_string<char> string;
#include <excpt.h>
#include <stdarg.h>
-#define _NORMALCURSOR true
-#define _NOCURSOR false
-
void init_libw32c(void);
void deinit_libw32c(void);
-void _setcursortype(int curstype);
+
+void set_cursor_enabled(bool enabled);
+bool is_cursor_enabled();
+
void clrscr(void);
void gotoxy(int x, int y);
void textcolor(int c);
diff --git a/crawl-ref/source/menu.cc b/crawl-ref/source/menu.cc
index 1041e8f494..2d12b56296 100644
--- a/crawl-ref/source/menu.cc
+++ b/crawl-ref/source/menu.cc
@@ -97,6 +97,8 @@ void Menu::reset()
std::vector<MenuEntry *> Menu::show(bool reuse_selections)
{
+ cursor_control cs(false);
+
if (reuse_selections)
get_selected(&sel);
else
diff --git a/crawl-ref/source/message.cc b/crawl-ref/source/message.cc
index fee17318d6..8a01c43c26 100644
--- a/crawl-ref/source/message.cc
+++ b/crawl-ref/source/message.cc
@@ -26,6 +26,7 @@
#include "externs.h"
#include "initfile.h"
+#include "libutil.h"
#include "macro.h"
#include "delay.h"
#include "stuff.h"
@@ -413,7 +414,8 @@ void mesclr( bool force )
}
// turn cursor off -- avoid 'cursor dance'
- _setcursortype(_NOCURSOR);
+
+ cursor_control cs(false);
#ifdef DOS_TERM
window(1, 18, 78, 25);
@@ -448,9 +450,6 @@ void mesclr( bool force )
#endif
#endif
- // turn cursor back on
- _setcursortype(_NORMALCURSOR);
-
Message_Line = 0;
} // end mseclr()
@@ -553,11 +552,11 @@ void replay_messages(void)
win_start_line = 0;
}
+ // Turn off the cursor
+ cursor_control cursoff(false);
+
for(;;)
{
- // turn cursor off
- _setcursortype(_NOCURSOR);
-
clrscr();
gotoxy(1, 1);
@@ -612,9 +611,6 @@ void replay_messages(void)
cprintf(EOL);
cprintf( "<< Lines %d-%d of %d >>", rel_start, rel_end, num_msgs );
- // turn cursor back on
- _setcursortype(_NORMALCURSOR);
-
keyin = get_ch();
if ((full_buffer && NUM_STORED_MESSAGES > num_lines - 2)
diff --git a/crawl-ref/source/shopping.cc b/crawl-ref/source/shopping.cc
index 441be694c0..47625df34f 100644
--- a/crawl-ref/source/shopping.cc
+++ b/crawl-ref/source/shopping.cc
@@ -114,6 +114,7 @@ char in_a_shop( char shoppy, id_arr id )
{
// easier to work with {dlb}
unsigned int greedy = env.shop[shoppy].greed;
+ cursor_control coff(false);
id_fix_arr shop_id;
FixedVector < int, 20 > shop_items;
diff --git a/crawl-ref/source/spl-book.cc b/crawl-ref/source/spl-book.cc
index 4f6e040563..0ff2fa6de0 100644
--- a/crawl-ref/source/spl-book.cc
+++ b/crawl-ref/source/spl-book.cc
@@ -912,6 +912,7 @@ unsigned char spellbook_contents( item_def &book, int action,
unsigned char keyn = 0;
if (update_screen)
{
+ cursor_control coff(false);
#ifdef DOS_TERM
char buffer[4800];
gettext(1, 1, 80, 25, buffer);
diff --git a/crawl-ref/source/spl-cast.cc b/crawl-ref/source/spl-cast.cc
index c492abf60e..f1568ed918 100644
--- a/crawl-ref/source/spl-cast.cc
+++ b/crawl-ref/source/spl-cast.cc
@@ -90,7 +90,8 @@ char list_spells(void)
bool already = false;
const int num_lines = get_number_of_lines();
-
+ cursor_control coff(false);
+
#ifdef DOS_TERM
char buffer[4800];
diff --git a/crawl-ref/source/view.cc b/crawl-ref/source/view.cc
index 136f8c1f5f..49a76a9580 100644
--- a/crawl-ref/source/view.cc
+++ b/crawl-ref/source/view.cc
@@ -1939,7 +1939,7 @@ static void draw_level_map(
screen_buffer_t buffer2[GYM * GXM * 2];
const int num_lines = get_number_of_lines();
- _setcursortype(_NOCURSOR);
+ cursor_control cs(false);
#ifdef PLAIN_TERM
gotoxy(1, 1);
@@ -2027,8 +2027,6 @@ static void draw_level_map(
#ifdef DOS_TERM
puttext(1, 1, 80, 25, buffer2);
#endif
-
- _setcursortype(_NORMALCURSOR);
}
// show_map() now centers the known map along x or y. This prevents
@@ -3441,7 +3439,7 @@ void viewwindow(bool draw_it, bool do_updates)
if (draw_it)
{
- _setcursortype(_NOCURSOR);
+ cursor_control cs(false);
const bool map = player_in_mappable_area();
int bufcount = 0;
@@ -3632,6 +3630,5 @@ void viewwindow(bool draw_it, bool do_updates)
#endif
#endif
- _setcursortype(_NORMALCURSOR);
}
} // end viewwindow()