tFunctional scroll facility for curses client message window. - vaccinewars - b… | |
git clone git://src.adamsgaard.dk/vaccinewars | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit dbbbb4f9a3c6ce5c73a819dd91c641a3bfa498d7 | |
parent 8c093126e4c298561cb3094be900d2f90d3d3054 | |
Author: Ben Webb <[email protected]> | |
Date: Sat, 4 Jan 2003 19:39:24 +0000 | |
Functional scroll facility for curses client message window. | |
Diffstat: | |
M ChangeLog | 4 ++++ | |
M TODO | 1 - | |
M src/curses_client/curses_client.c | 55 ++++++++++++++++++++++++++++-… | |
3 files changed, 54 insertions(+), 6 deletions(-) | |
--- | |
diff --git a/ChangeLog b/ChangeLog | |
t@@ -1,3 +1,7 @@ | |
+cvs | |
+ - The messages window in the curses client can now be scrolled with the | |
+ + and - keys | |
+ | |
1.5.8 21-10-2002 | |
- Options dialog now allows sounds for all supported game events to be set | |
- BindAddress config variable added, to allow the server to be bound to | |
diff --git a/TODO b/TODO | |
t@@ -1,4 +1,3 @@ | |
-- Scrollbar in curses client "Messages" box | |
- Better use of screen space in curses client for large xterms etc. | |
- Preserve chat messages at end of game (so they aren't lost when looking at | |
the high score list) ? | |
diff --git a/src/curses_client/curses_client.c b/src/curses_client/curses_clien… | |
t@@ -44,9 +44,6 @@ | |
#include "sound.h" | |
#include "tstring.h" | |
-static void PrepareHighScoreScreen(void); | |
-static void PrintHighScore(char *Data); | |
- | |
static int ResizedFlag; | |
static SCREEN *cur_screen; | |
t@@ -95,6 +92,11 @@ static void PrintMessage(const gchar *text); | |
static void GunShop(Player *Play); | |
static void LoanShark(Player *Play); | |
static void Bank(Player *Play); | |
+static void PrepareHighScoreScreen(void); | |
+static void PrintHighScore(char *Data); | |
+static void scroll_msg_area_up(void); | |
+static void scroll_msg_area_down(void); | |
+ | |
#ifdef NETWORKING | |
static void HttpAuthFunc(HttpConnection *conn, gboolean proxyauth, | |
t@@ -1515,6 +1517,14 @@ int GetKey(char *allowed, char *orig_allowed, gboolean … | |
do { | |
ch = bgetch(); | |
ch = toupper(ch); | |
+ /* Handle scrolling of message window */ | |
+ if (ch == '-') { | |
+ scroll_msg_area_up(); | |
+ continue; | |
+ } else if (ch == '+') { | |
+ scroll_msg_area_down(); | |
+ continue; | |
+ } | |
for (AllowInd = 0; AllowInd < strlen(allowed); AllowInd++) { | |
if (allowed[AllowInd] == ch) { | |
addch((guint)ch | TextAttr); | |
t@@ -1660,6 +1670,27 @@ static int get_msg_area_bottom(void) | |
return 14; | |
} | |
+/* Number of lines that the message window is scrolled back by */ | |
+static int scrollpos = 0; | |
+ | |
+/* | |
+ * Scrolls the message area up a page | |
+ */ | |
+static void scroll_msg_area_up(void) | |
+{ | |
+ scrollpos += (get_msg_area_bottom() - get_msg_area_top() + 1); | |
+ display_message(""); | |
+} | |
+ | |
+/* | |
+ * Scrolls the message area down a page | |
+ */ | |
+static void scroll_msg_area_down(void) | |
+{ | |
+ scrollpos -= (get_msg_area_bottom() - get_msg_area_top() + 1); | |
+ display_message(""); | |
+} | |
+ | |
/* | |
* Displays a network message "buf" in the message area | |
* scrolling previous messages up. | |
t@@ -1689,6 +1720,7 @@ void display_message(const char *buf) | |
g_list_free(msgs); | |
msgs = NULL; | |
num_msgs = 0; | |
+ scrollpos = 0; | |
/* Display a blank message area */ | |
if (Network) { | |
for (y = 0; y < depth; y++) { | |
t@@ -1712,7 +1744,14 @@ void display_message(const char *buf) | |
pt = NULL; | |
data = NULL; | |
if (nextpt) { | |
- int lines = 0, displines = depth; | |
+ int lines = 0, displines, total_lines = 0; | |
+ | |
+ /* Correct for having scrolled down too far */ | |
+ if (scrollpos < 0) { | |
+ scrollpos = 0; | |
+ } | |
+ | |
+ displines = depth + scrollpos; | |
/* Find the message to display at the top of the message area */ | |
do { | |
displines -= lines; | |
t@@ -1720,7 +1759,13 @@ void display_message(const char *buf) | |
nextpt = g_list_previous(pt); | |
data = pt->data; | |
lines = (strlen(data) + wid - 1) / wid; | |
+ total_lines += lines; | |
} while (displines > lines && nextpt); | |
+ | |
+ /* Correct for having scrolled up too far */ | |
+ if ((depth + scrollpos) > total_lines && total_lines > depth) { | |
+ scrollpos = total_lines - depth; | |
+ } | |
/* Correct for the first line starting partway through a message */ | |
if (displines < lines) { | |
t@@ -1818,7 +1863,7 @@ void print_status(Player *Play, gboolean DispDrug) | |
addch(ACS_RTEE); | |
/* Title of the "Messages" window in the curses client */ | |
- mvaddstr(9, 15, _("Messages")); | |
+ mvaddstr(9, 15, _("Messages (-/+ scrolls up/down)")); | |
mvaddch(9, Width / 2, ACS_BTEE); | |
mvaddch(15, 1, ACS_LLCORNER); |