summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2006-12-17 13:11:17 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2006-12-17 13:11:17 +0000
commita8855a831f9a789f19e2525962d0e5c4a8463a18 (patch)
tree0a2b9caa6732a4cfa392df0352649a6cfccdff1c /crawl-ref/source
parent39379c48505b14bfbe8ac8292e5938ad33d5989a (diff)
downloadcrawl-ref-a8855a831f9a789f19e2525962d0e5c4a8463a18.tar.gz
crawl-ref-a8855a831f9a789f19e2525962d0e5c4a8463a18.zip
An attempt at a more comprehensive fix for cursor inconsistencies between
platforms. We'll probably need to tweak this further. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@659 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source')
-rw-r--r--crawl-ref/source/acr.cc23
-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.cc15
-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/view.cc7
11 files changed, 100 insertions, 70 deletions
diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc
index 3c531604f9..f4608ac336 100644
--- a/crawl-ref/source/acr.cc
+++ b/crawl-ref/source/acr.cc
@@ -859,15 +859,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();
@@ -2821,6 +2828,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/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 ef1312caa3..09c01ce817 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 e14c65d206..f12618d7ca 100644
--- a/crawl-ref/source/libutil.h
+++ b/crawl-ref/source/libutil.h
@@ -159,14 +159,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..1905c5bd56 100644
--- a/crawl-ref/source/libw32c.cc
+++ b/crawl-ref/source/libw32c.cc
@@ -432,18 +432,23 @@ void deinit_libw32c(void)
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 (current_cursor);
+}
+
+void _setcursortype_internal(bool curstype)
{
CONSOLE_CURSOR_INFO cci;
if (curstype == current_cursor)
- return;
+ return;
cci.dwSize = 5;
cci.bVisible = curstype? TRUE : FALSE;
@@ -455,7 +460,7 @@ void _setcursortype_internal(int curstype)
// now, if we just changed from NOCURSOR to CURSOR,
// actually move screen cursor
if (current_cursor != _NOCURSOR)
- gotoxy(cx+1, cy+1);
+ gotoxy(cx+1, cy+1);
}
void clrscr(void)
diff --git a/crawl-ref/source/libw32c.h b/crawl-ref/source/libw32c.h
index 441fdf374d..e4efd254c1 100644
--- a/crawl-ref/source/libw32c.h
+++ b/crawl-ref/source/libw32c.h
@@ -15,12 +15,12 @@ typedef std::basic_string<char> string;
#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 164035089a..1e7e749808 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/view.cc b/crawl-ref/source/view.cc
index 6e9f1b88f5..095ba43dc0 100644
--- a/crawl-ref/source/view.cc
+++ b/crawl-ref/source/view.cc
@@ -1921,7 +1921,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);
@@ -2009,8 +2009,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
@@ -3325,7 +3323,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;
@@ -3517,6 +3515,5 @@ void viewwindow(bool draw_it, bool do_updates)
#endif
#endif
- _setcursortype(_NORMALCURSOR);
}
} // end viewwindow()