summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2006-11-22 11:38:34 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2006-11-22 11:38:34 +0000
commit6bda7067bc268b6104b4f55940049b2db25b96fa (patch)
tree1bc59eb4c3ea2a2644aeb3a95d3a0322ee7b96cb
parentddfbd2a60be7ce857997097f6bc03eac22f55be1 (diff)
downloadcrawl-ref-6bda7067bc268b6104b4f55940049b2db25b96fa.tar.gz
crawl-ref-6bda7067bc268b6104b4f55940049b2db25b96fa.zip
Restore old cursor behaviour on Windows, with little icky hooks to make it controllable for the newgame slider menu.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@459 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r--crawl-ref/source/libdos.h3
-rw-r--r--crawl-ref/source/libunix.h3
-rw-r--r--crawl-ref/source/libutil.h8
-rw-r--r--crawl-ref/source/libw32c.cc38
-rw-r--r--crawl-ref/source/libw32c.h3
5 files changed, 44 insertions, 11 deletions
diff --git a/crawl-ref/source/libdos.h b/crawl-ref/source/libdos.h
index 647ce12b00..d934171a98 100644
--- a/crawl-ref/source/libdos.h
+++ b/crawl-ref/source/libdos.h
@@ -3,4 +3,7 @@
void init_libdos();
+inline void enable_smart_cursor(bool ) { }
+inline bool is_smart_cursor_enabled() { return (false); }
+
#endif
diff --git a/crawl-ref/source/libunix.h b/crawl-ref/source/libunix.h
index d42454dadc..732c383133 100644
--- a/crawl-ref/source/libunix.h
+++ b/crawl-ref/source/libunix.h
@@ -41,6 +41,9 @@ void textattr(int col);
void set_altcharset(bool alt_on);
bool get_altcharset();
+inline void enable_smart_cursor(bool) { }
+inline bool is_smart_cursor_enabled() { return (false); }
+
#ifndef _LIBUNIX_IMPLEMENTATION
/* Some stuff from curses, to remove compiling warnings.. */
extern "C"
diff --git a/crawl-ref/source/libutil.h b/crawl-ref/source/libutil.h
index d05ef53bd4..2da46f421b 100644
--- a/crawl-ref/source/libutil.h
+++ b/crawl-ref/source/libutil.h
@@ -13,6 +13,7 @@
#ifndef LIBUTIL_H
#define LIBUTIL_H
+#include "AppHdr.h"
#include "defines.h"
#include <string>
#include <vector>
@@ -127,14 +128,19 @@ enum KEYS
class cursor_control
{
public:
- cursor_control(bool cs) : cstate(cs) {
+ cursor_control(bool cs)
+ : cstate(cs), smartcstate( is_smart_cursor_enabled() )
+ {
+ enable_smart_cursor(false);
_setcursortype(cs? _NORMALCURSOR : _NOCURSOR);
}
~cursor_control() {
_setcursortype(cstate? _NOCURSOR : _NORMALCURSOR);
+ enable_smart_cursor(smartcstate);
}
private:
bool cstate;
+ bool smartcstate;
};
// Reads lines of text; used internally by cancelable_get_line.
diff --git a/crawl-ref/source/libw32c.cc b/crawl-ref/source/libw32c.cc
index 60062c36ea..294ad71522 100644
--- a/crawl-ref/source/libw32c.cc
+++ b/crawl-ref/source/libw32c.cc
@@ -98,6 +98,8 @@ static bool buffering = false;
static unsigned InputCP, OutputCP;
static const unsigned PREFERRED_CODEPAGE = 437;
+static bool w32_smart_cursor = true;
+
// we can do straight translation of DOS color to win32 console color.
#define WIN32COLOR(col) (WORD)(col)
static void writeChar(char c);
@@ -251,6 +253,16 @@ void writeChar(char c)
if (cx >= 80) cx = 80;
}
+void enable_smart_cursor(bool cursor)
+{
+ w32_smart_cursor = cursor;
+}
+
+bool is_smart_cursor_enabled()
+{
+ return (w32_smart_cursor);
+}
+
void bFlush(void)
{
COORD source;
@@ -420,14 +432,12 @@ void deinit_libw32c(void)
SetConsoleTitle( oldTitle );
}
-// we don't take our cues from Crawl. Cursor is shown
-// only on input.
void _setcursortype(int curstype)
{
- _setcursortype_internal(curstype);
+ if (!w32_smart_cursor)
+ _setcursortype_internal(curstype);
}
-
void _setcursortype_internal(int curstype)
{
CONSOLE_CURSOR_INFO cci;
@@ -714,6 +724,10 @@ int getch_ck(void)
return repeat_key;
}
+ const bool oldValue = current_cursor;
+ if (w32_smart_cursor)
+ _setcursortype_internal(_NORMALCURSOR);
+
while(1)
{
CLOCKIN
@@ -740,8 +754,9 @@ int getch_ck(void)
}
}
}
- // DEBUG
- //fprintf(foo, "getch() returning %02x (%c)\n", key, key);
+
+ if (w32_smart_cursor)
+ _setcursortype_internal(oldValue);
return key;
}
@@ -755,7 +770,7 @@ int getch(void)
int getche(void)
{
// turn buffering off temporarily
- bool oldValue = buffering;
+ const bool oldValue = buffering;
setBuffering(false);
int val = getch();
@@ -805,8 +820,10 @@ int getConsoleString(char *buf, int maxlen)
setStringInput( true );
// force cursor
- bool oldValue = current_cursor;
- _setcursortype_internal(_NORMALCURSOR);
+ const bool oldValue = current_cursor;
+
+ if (w32_smart_cursor)
+ _setcursortype_internal(_NORMALCURSOR);
// set actual screen color to current color
SetConsoleTextAttribute( outbuf, WIN32COLOR(current_color) );
@@ -830,7 +847,8 @@ int getConsoleString(char *buf, int maxlen)
setStringInput( false );
// restore old cursor
- _setcursortype_internal(oldValue);
+ if (w32_smart_cursor)
+ _setcursortype_internal(oldValue);
// return # of bytes read
return (int)nread;
diff --git a/crawl-ref/source/libw32c.h b/crawl-ref/source/libw32c.h
index 3a818a71e9..37372976ee 100644
--- a/crawl-ref/source/libw32c.h
+++ b/crawl-ref/source/libw32c.h
@@ -45,6 +45,9 @@ int kbhit(void);
void delay(int ms);
void textbackground(int c);
+void enable_smart_cursor(bool cursor);
+bool is_smart_cursor_enabled();
+
inline void srandom(unsigned int seed) { srand(seed); }
#endif