From 71bf7be8a15312001e3b2edb31e55c588ed076ff Mon Sep 17 00:00:00 2001 From: dshaligram Date: Mon, 4 Jun 2007 07:47:19 +0000 Subject: Fixed libw32c.cc to work with the new viewport changes. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1525 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/libw32c.cc | 91 +++++++++++++++++++++++-------------------- crawl-ref/source/libw32c.h | 2 - crawl-ref/source/makefile.mgw | 1 + crawl-ref/source/misc.cc | 2 +- 4 files changed, 50 insertions(+), 46 deletions(-) (limited to 'crawl-ref/source') diff --git a/crawl-ref/source/libw32c.cc b/crawl-ref/source/libw32c.cc index 2797568046..dd0822deee 100644 --- a/crawl-ref/source/libw32c.cc +++ b/crawl-ref/source/libw32c.cc @@ -57,12 +57,7 @@ #include #include -#include -#include -#include -#include -#include -#include +#include // END -- WINDOWS INCLUDES @@ -75,6 +70,7 @@ #include "AppHdr.h" #include "version.h" #include "defines.h" +#include "stuff.h" #include "view.h" #include "libutil.h" @@ -92,9 +88,9 @@ static int cx=0, cy=0; //static FILE *foo = NULL; //DEBUG // and now, for the screen buffer -static CHAR_INFO screen[80 * WIN_NUMBER_OF_LINES]; +static CHAR_INFO *screen = NULL; static COORD screensize; -#define SCREENINDEX(x,y) (x)+80*(y) +#define SCREENINDEX(x,y) ((x)+screensize.X*(y)) static bool buffering = false; // static const char *windowTitle = "Crawl " VERSION; static unsigned InputCP, OutputCP; @@ -253,7 +249,7 @@ void writeChar(char c) // update x position cx += 1; - if (cx >= 80) cx = 80; + if (cx >= screensize.X) cx = screensize.X; } void enable_smart_cursor(bool cursor) @@ -383,9 +379,21 @@ void init_libw32c(void) } // set up screen size - screensize.X = 80; - screensize.Y = get_number_of_lines(); + CONSOLE_SCREEN_BUFFER_INFO cinf; + if (::GetConsoleScreenBufferInfo(outbuf, &cinf)) + { + screensize.X = cinf.srWindow.Right - cinf.srWindow.Left + 1; + screensize.Y = cinf.srWindow.Bottom - cinf.srWindow.Top + 1; + } + else + { + screensize.X = 80; + screensize.Y = 25; + } + + screen = new CHAR_INFO[screensize.X * screensize.Y]; + // initialise text color textcolor(DARKGREY); @@ -398,7 +406,6 @@ void init_libw32c(void) //DEBUG //foo = fopen("debug.txt", "w"); - // JWM, 06/12/2004: Code page setting, as XP does not use ANSI 437 by // default. InputCP = GetConsoleCP(); @@ -435,6 +442,9 @@ void deinit_libw32c(void) _setcursortype_internal(true); textcolor(DARKGREY); + delete [] screen; + screen = NULL; + // finally, restore title SetConsoleTitle( oldTitle ); } @@ -485,13 +495,11 @@ void clrscr(void) COORD source; SMALL_RECT target; - const int num_lines = get_number_of_lines(); - PCHAR_INFO pci = screen; - for(x=0; x<80; x++) + for(x = 0; x < screensize.X; x++) { - for(y=0; yChar.AsciiChar = ' '; pci->Attributes = 0; @@ -503,8 +511,8 @@ void clrscr(void) source.Y = 0; target.Left = 0; target.Top = 0; - target.Right = 79; - target.Bottom = num_lines - 1; + target.Right = screensize.X - 1; + target.Bottom = screensize.Y - 1; WriteConsoleOutput(outbuf, screen, screensize, source, &target); @@ -514,24 +522,22 @@ void clrscr(void) void gotoxy(int x, int y) { - const int num_lines = get_number_of_lines(); - // always flush on goto bFlush(); // bounds check - if (x<1) - x=1; - if (x>80) - x=80; - if (y<1) - y=1; - if (y>num_lines) - y=num_lines; + if (x < 1) + x = 1; + if (x > screensize.X) + x = screensize.X; + if (y < 1) + y = 1; + if (y > screensize.Y) + y = screensize.Y; // change current cursor - cx = x-1; - cy = y-1; + cx = x - 1; + cy = y - 1; // if cursor is not NOCURSOR, update screen if (cursor_is_enabled) @@ -561,8 +567,7 @@ void clear_message_window() { PCHAR_INFO pci = screen + SCREENINDEX(crawl_view.msgp.x - 1, crawl_view.msgp.y - 1); - const int ncols = get_number_of_cols(); - for (int x = 0; x < ncols; x++) + for (int x = 0; x < screensize.X; x++) { for (int y = 0; y < crawl_view.msgsz.y; y++) { @@ -579,8 +584,8 @@ void clear_message_window() source.Y = crawl_view.msgp.y - 1; target.Left = crawl_view.msgp.x - 1; target.Top = crawl_view.msgp.y - 1; - target.Right = get_number_of_cols() - 1; - target.Bottom = get_number_of_lines() - 1; + target.Right = screensize.X - 1; + target.Bottom = screensize.Y - 1; WriteConsoleOutput(outbuf, screen, screensize, source, &target); } @@ -589,7 +594,7 @@ static void scroll_message_buffer() { memmove( screen + SCREENINDEX(crawl_view.msgp.x - 1, crawl_view.msgp.y - 1), screen + SCREENINDEX(crawl_view.msgp.x - 1, crawl_view.msgp.y), - crawl_view.msgsz.y * get_number_of_cols() * sizeof(*screen) ); + crawl_view.msgsz.y * screensize.X * sizeof(*screen) ); } static void scroll_message_window() @@ -597,8 +602,8 @@ static void scroll_message_window() SMALL_RECT scroll_rectangle, clip_rectangle; scroll_rectangle.Left = crawl_view.msgp.x - 1; scroll_rectangle.Top = crawl_view.msgp.y; - scroll_rectangle.Right = get_number_of_cols() - 1; - scroll_rectangle.Bottom = get_number_of_lines() - 1; + scroll_rectangle.Right = screensize.X - 1; + scroll_rectangle.Bottom = screensize.Y - 1; clip_rectangle = scroll_rectangle; clip_rectangle.Top = crawl_view.msgp.y - 1; @@ -618,7 +623,7 @@ static void scroll_message_window() scroll_message_buffer(); // Cursor also scrolls up so prompts don't look brain-damaged. - if (wherey() == get_number_of_lines()) + if (wherey() == screensize.Y) gotoxy(wherex(), wherey() - 1); } @@ -628,13 +633,13 @@ void message_out(int which_line, int colour, const char *s, int firstcol, if (!firstcol) firstcol = Options.delay_message_clear? 2 : 1; - gotoxy(firstcol - 1 + crawl_view.viewp.x, - which_line + crawl_view.viewp.y); + gotoxy(firstcol - 1 + crawl_view.msgp.x, + which_line + crawl_view.msgp.y); textcolor(colour); cprintf("%s", s); - if (newline && which_line == get_message_window_height() - 1) + if (newline && which_line == crawl_view.msgsz.y - 1) scroll_message_window(); } @@ -972,12 +977,12 @@ bool setBuffering( bool value ) int get_number_of_lines() { - return (25); + return (screensize.Y); } int get_number_of_cols() { - return (80); + return (screensize.X); } #endif /* #if defined(WIN32CONSOLE) */ diff --git a/crawl-ref/source/libw32c.h b/crawl-ref/source/libw32c.h index 887a3c6446..9e01a44fd7 100644 --- a/crawl-ref/source/libw32c.h +++ b/crawl-ref/source/libw32c.h @@ -5,8 +5,6 @@ #ifndef LIBW32C_H #define LIBW32C_H -#define WIN_NUMBER_OF_LINES 25 - #include #include diff --git a/crawl-ref/source/makefile.mgw b/crawl-ref/source/makefile.mgw index eeb54e9ab8..d0056cd958 100644 --- a/crawl-ref/source/makefile.mgw +++ b/crawl-ref/source/makefile.mgw @@ -126,6 +126,7 @@ ifneq ($(OPATH),$(INSTALLDIR)) endif mkdir $(INSTALLDIR)\dat 2>nul || echo "" >nul copy /y dat\*.des $(INSTALLDIR)\dat + copy /y dat\*.txt $(INSTALLDIR)\dat copy /y ..\init.txt $(INSTALLDIR) clean: diff --git a/crawl-ref/source/misc.cc b/crawl-ref/source/misc.cc index 01281e2198..1c030dbb27 100644 --- a/crawl-ref/source/misc.cc +++ b/crawl-ref/source/misc.cc @@ -1143,7 +1143,7 @@ void new_level(void) { textcolor(LIGHTGREY); - gotoxy(46, 12); + gotoxy(crawl_view.hudp.x + 6, 12); #if DEBUG_DIAGNOSTICS cprintf( "(%d) ", you.your_level + 1 ); -- cgit v1.2.3-54-g00ecf