summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2008-07-21 16:15:40 +0000
committerharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2008-07-21 16:15:40 +0000
commitb17182f59fdb23979c9dbd910f57b0ec5675c5c9 (patch)
treea3d525959ef1fbb71de217d9bda6a51fc4793e30
parent412b189793a250f3233178b1bde1f17a085a73c3 (diff)
downloadcrawl-ref-b17182f59fdb23979c9dbd910f57b0ec5675c5c9.tar.gz
crawl-ref-b17182f59fdb23979c9dbd910f57b0ec5675c5c9.zip
Fix for 2022236: HP bar could be blanked out when gaining XP. [Thanks sorear]
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@6624 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r--crawl-ref/source/cio.cc45
-rw-r--r--crawl-ref/source/cio.h3
-rw-r--r--crawl-ref/source/output.cc8
3 files changed, 52 insertions, 4 deletions
diff --git a/crawl-ref/source/cio.cc b/crawl-ref/source/cio.cc
index f12061eb25..64ec293350 100644
--- a/crawl-ref/source/cio.cc
+++ b/crawl-ref/source/cio.cc
@@ -187,6 +187,51 @@ void cursorxy(int x, int y)
#endif
}
+// cprintf that stops outputting when wrapped
+// Conceptually very similar to wrapcprintf()
+int nowrapcprintf( int wrapcol, const char *s, ... )
+{
+ char buf[1000]; // Hard max
+
+ va_list args;
+ va_start(args, s);
+ // XXX: If snprintf isn't available, vsnprintf probably isn't, either.
+ const int len = vsnprintf(buf, sizeof buf, s, args);
+ va_end(args);
+
+ // Sanity checking to prevent buffer overflows
+ const int maxlen = std::min( std::max( wrapcol + 1 - wherex(), 0 ), len );
+
+ // Force the string to terminate at maxlen
+ buf[maxlen] = 0;
+
+ cprintf("%s", buf);
+ return std::min(len, maxlen);
+}
+
+// convenience wrapper (hah) for nowrapcprintf
+// FIXME: should pass off to nowrapcprintf() instead of doing it manually
+int nowrap_eol_cprintf( const char *s, ... )
+{
+ const int wrapcol = get_number_of_cols() - 1;
+ char buf[1000]; // Hard max
+
+ va_list args;
+ va_start(args, s);
+ // XXX: If snprintf isn't available, vsnprintf probably isn't, either.
+ const int len = vsnprintf(buf, sizeof buf, s, args);
+ va_end(args);
+
+ // Sanity checking to prevent buffer overflows
+ const int maxlen = std::min( std::max( wrapcol + 1 - wherex(), 0 ), len );
+
+ // Force the string to terminate at maxlen
+ buf[maxlen] = 0;
+
+ cprintf("%s", buf);
+ return std::min(len, maxlen);
+}
+
// cprintf that knows how to wrap down lines (primitive, but what the heck)
int wrapcprintf( int wrapcol, const char *s, ... )
{
diff --git a/crawl-ref/source/cio.h b/crawl-ref/source/cio.h
index a28d601256..fdc6254dca 100644
--- a/crawl-ref/source/cio.h
+++ b/crawl-ref/source/cio.h
@@ -58,6 +58,9 @@ void get_input_line( char *const buff, int len );
// In view.cc, declared here for default argument to cancelable_get_line()
int get_number_of_cols(void);
+int nowrapcprintf( int wrapcol, const char *s, ... );
+int nowrap_eol_cprintf( const char *s, ... );
+
// Returns zero if user entered text and pressed Enter, otherwise returns the
// key pressed that caused the exit, usually Escape.
//
diff --git a/crawl-ref/source/output.cc b/crawl-ref/source/output.cc
index 92963b99ec..9190fd7529 100644
--- a/crawl-ref/source/output.cc
+++ b/crawl-ref/source/output.cc
@@ -25,6 +25,7 @@
#include "abl-show.h"
#include "branch.h"
+#include "cio.h"
#include "describe.h"
#include "directn.h"
#include "format.h"
@@ -959,11 +960,10 @@ void redraw_skill(const std::string &your_name, const std::string &class_name)
// Level N Minotaur [of God]
textcolor( YELLOW );
cgotoxy(1, 2, GOTO_STAT);
- cprintf("Level %d %s",
- you.experience_level,
- species_name( you.species, you.experience_level ).c_str());
+ nowrap_eol_cprintf("Level %d %s", you.experience_level,
+ species_name(you.species,you.experience_level).c_str());
if (you.religion != GOD_NO_GOD)
- cprintf(" of %s", god_name(you.religion).c_str());
+ nowrap_eol_cprintf(" of %s", god_name(you.religion).c_str());
clear_to_end_of_line();
textcolor( LIGHTGREY );