|
From: <sch...@us...> - 2008-11-24 05:32:26
|
Revision: 55
http://deraciel.svn.sourceforge.net/deraciel/?rev=55&view=rev
Author: schnippi001
Date: 2008-11-24 05:32:17 +0000 (Mon, 24 Nov 2008)
Log Message:
-----------
Fixed a regression in which resizing the terminal caused the game windows to spread
completely over the new size instead of their fixed size
Modified Paths:
--------------
trunk/main.c
trunk/map_window.c
trunk/map_window.h
trunk/text_window.c
trunk/text_window.h
Added Paths:
-----------
trunk/status_window.c
trunk/status_window.h
Removed Paths:
-------------
trunk/stat_window.c
trunk/stat_window.h
Modified: trunk/main.c
===================================================================
--- trunk/main.c 2008-11-22 13:48:46 UTC (rev 54)
+++ trunk/main.c 2008-11-24 05:32:17 UTC (rev 55)
@@ -6,7 +6,7 @@
#include <ncurses.h>
#include "text_window.h"
-#include "stat_window.h"
+#include "status_window.h"
#include "map_window.h"
#include "random.h"
#include "keyboard.h"
@@ -19,7 +19,7 @@
static struct char_struct main_char =
{
- "Foobar",
+ "Foobar the Apprentice",
{ 16, 16, 16, 16, 16, 16 },
0,
1,
@@ -54,7 +54,7 @@
text_window_create();
map_window_create();
- stat_window_create();
+ status_window_create();
invt_init(&main_char.inventory);
@@ -80,7 +80,7 @@
/* If text window is still existing, destroy it */
text_window_destroy();
map_window_destroy();
- stat_window_destroy();
+ status_window_destroy();
/* End ncurses library */
endwin();
@@ -103,6 +103,9 @@
endwin();
curs_set(0); /* Hide the cursor */
+ text_window_resize();
+ map_window_resize();
+ status_window_resize();
clear();
refresh();
}
@@ -137,7 +140,7 @@
map_window_update(map);
}
- stat_window_update(&main_char);
+ status_window_update(&main_char);
doupdate();
}
Modified: trunk/map_window.c
===================================================================
--- trunk/map_window.c 2008-11-22 13:48:46 UTC (rev 54)
+++ trunk/map_window.c 2008-11-24 05:32:17 UTC (rev 55)
@@ -3,51 +3,59 @@
#include <string.h>
#include <ncurses.h>
-#define MAPWND_MAXWIDTH (80)
-#define MAPWND_MAXHEIGHT (20)
-#define MAPWND_SCREENSIZE (MAPWND_MAXWIDTH * MAPWND_MAXHEIGHT)
+#define MAPWINDOW_MAXWIDTH (80)
+#define MAPWINDOW_MAXHEIGHT (20)
+#define MAPWINDOW_SCREENSIZE (MAPWINDOW_MAXWIDTH * MAPWINDOW_MAXHEIGHT)
-static WINDOW *border_wnd; /* Window handle */
+static WINDOW *map_wnd; /* Window handle */
void map_window_create(void)
{
- border_wnd = newwin(MAPWND_MAXHEIGHT, MAPWND_MAXWIDTH, 2, 0);
+ map_wnd = newwin(MAPWINDOW_MAXHEIGHT, MAPWINDOW_MAXWIDTH, 2, 0);
- if (!border_wnd) {
+ if (!map_wnd) {
fprintf(stderr, "map window creation failed!\n");
return;
}
- wattron(border_wnd, COLOR_PAIR(4));
- wbkgd(border_wnd, COLOR_PAIR(4));
+ wattron(map_wnd, COLOR_PAIR(4));
+ wbkgd(map_wnd, COLOR_PAIR(4));
- wrefresh(border_wnd);
+ wrefresh(map_wnd);
}
void map_window_destroy()
{
- if (border_wnd) {
+ if (map_wnd) {
/* Free resources consumed by the window */
- delwin(border_wnd);
- border_wnd = NULL;
+ delwin(map_wnd);
+ map_wnd = NULL;
}
}
+void map_window_resize(void)
+{
+ /* Reallocate storage for resized text window */
+ wresize(map_wnd, MAPWINDOW_MAXHEIGHT, MAPWINDOW_MAXWIDTH);
+}
+
+
+
void map_window_update(const chtype *map)
{
/* Set cursor to first position (upper left) in map window */
- wmove(border_wnd, 0, 0);
+ wmove(map_wnd, 0, 0);
/* Copy map to local map */
- for (int s = 0; s < MAPWND_SCREENSIZE; s++) {
- waddch(border_wnd, map[s]);
+ for (int s = 0; s < MAPWINDOW_SCREENSIZE; s++) {
+ waddch(map_wnd, map[s]);
}
- wnoutrefresh(border_wnd);
+ wnoutrefresh(map_wnd);
}
Modified: trunk/map_window.h
===================================================================
--- trunk/map_window.h 2008-11-22 13:48:46 UTC (rev 54)
+++ trunk/map_window.h 2008-11-24 05:32:17 UTC (rev 55)
@@ -5,6 +5,7 @@
void map_window_create(void);
void map_window_destroy(void);
+void map_window_resize(void);
void map_window_update(const chtype *m);
#endif // !DERACIEL_MAP_WINDOW_H
Deleted: trunk/stat_window.c
===================================================================
--- trunk/stat_window.c 2008-11-22 13:48:46 UTC (rev 54)
+++ trunk/stat_window.c 2008-11-24 05:32:17 UTC (rev 55)
@@ -1,73 +0,0 @@
-#include "stat_window.h"
-
-#include <string.h>
-#include <ncurses.h>
-
-#define BORDER_WND_MAXWIDTH (80)
-#define BORDER_WND_MAXHEIGHT (3)
-
-#define STATWINDOW_BORDER
-
-static WINDOW *border_wnd; /* Window handle */
-
-static void draw_border();
-
-
-void stat_window_create(void)
-{
- border_wnd = newwin(BORDER_WND_MAXHEIGHT, BORDER_WND_MAXWIDTH, 25-BORDER_WND_MAXHEIGHT, 0);
-
- if (!border_wnd) {
- fprintf(stderr, "stat window creation failed!\n");
- return;
- }
-
- wattron(border_wnd, COLOR_PAIR(3));
- wbkgd(border_wnd, COLOR_PAIR(3));
-
-#ifdef STATWINDOW_BORDER
- /* Redraw border with new dimensions */
- draw_border();
-#endif // !STATWINDOW_BORDER
-
- wrefresh(border_wnd);
-}
-
-
-
-void stat_window_destroy()
-{
- if (border_wnd) {
- /* Free resources consumed by the window */
- delwin(border_wnd);
- border_wnd = NULL;
- }
-}
-
-
-
-void draw_border()
-{
- wborder(border_wnd, 0, 0, 0, ' ', '/', '\\', ACS_VLINE, ACS_VLINE);
-}
-
-
-
-void stat_window_update(const struct char_struct *ch)
-{
-#ifdef STATWINDOW_BORDER
- /* Redraw border with new dimensions */
- draw_border();
-#endif // !STATWINDOW_BORDER
-
- mvwprintw(border_wnd, 1, 2, "$:%d HP:%d(%d) MP:%d(%d) St:%2d Dx:%2d Co:%2d Wi:%2d Wp:%2d Ch:%2d",
- *(uint32_t*)(ch->inventory.coins->user_data),
- ch->cur_hitpoints, ch->max_hitpoints, ch->cur_magic, ch->max_magic,
- ch->stats[STAT_STRENGTH], ch->stats[STAT_DEXTERITY], ch->stats[STAT_CONSTITUTION],
- ch->stats[STAT_WISDOM], ch->stats[STAT_WILLPOWER], ch->stats[STAT_CHARISMA]);
-
- mvwprintw(border_wnd, 2, 2, "%s Xp:%2d/%d T:%d S:%d",
- ch->name, ch->level, ch->experience, ch->turns, ch->score);
-
- wnoutrefresh(border_wnd);
-}
Deleted: trunk/stat_window.h
===================================================================
--- trunk/stat_window.h 2008-11-22 13:48:46 UTC (rev 54)
+++ trunk/stat_window.h 2008-11-24 05:32:17 UTC (rev 55)
@@ -1,11 +0,0 @@
-#ifndef DERACIEL_STAT_WINDOW_H
-#define DERACIEL_STAT_WINDOW_H
-
-#include "char.h"
-
-void stat_window_create(void);
-void stat_window_destroy(void);
-void stat_window_update(const struct char_struct *ch);
-
-#endif // !DERACIEL_STAT_WINDOW_H
-
Copied: trunk/status_window.c (from rev 54, trunk/stat_window.c)
===================================================================
--- trunk/status_window.c (rev 0)
+++ trunk/status_window.c 2008-11-24 05:32:17 UTC (rev 55)
@@ -0,0 +1,80 @@
+#include "status_window.h"
+
+#include <string.h>
+#include <ncurses.h>
+
+#define STATUSWINDOW_MAXWIDTH (80)
+#define STATUSWINDOW_MAXHEIGHT (3)
+#define STATUSWINDOW_BORDER
+
+static WINDOW *status_wnd; /* Window handle */
+
+static void draw_border();
+
+
+void status_window_create(void)
+{
+ status_wnd = newwin(STATUSWINDOW_MAXHEIGHT, STATUSWINDOW_MAXWIDTH, 25-STATUSWINDOW_MAXHEIGHT, 0);
+
+ if (!status_wnd) {
+ fprintf(stderr, "stat window creation failed!\n");
+ return;
+ }
+
+ wattron(status_wnd, COLOR_PAIR(3));
+ wbkgd(status_wnd, COLOR_PAIR(3));
+
+#ifdef STATUSWINDOW_BORDER
+ /* Redraw border with new dimensions */
+ draw_border();
+#endif // !STATUSWINDOW_BORDER
+
+ wrefresh(status_wnd);
+}
+
+
+
+void status_window_destroy()
+{
+ if (status_wnd) {
+ /* Free resources consumed by the window */
+ delwin(status_wnd);
+ status_wnd = NULL;
+ }
+}
+
+
+
+void status_window_resize(void)
+{
+ /* Reallocate storage for resized text window */
+ wresize(status_wnd, STATUSWINDOW_MAXHEIGHT, STATUSWINDOW_MAXWIDTH);
+}
+
+
+
+void draw_border()
+{
+ wborder(status_wnd, 0, 0, 0, ' ', '/', '\\', ACS_VLINE, ACS_VLINE);
+}
+
+
+
+void status_window_update(const struct char_struct *ch)
+{
+#ifdef STATUSWINDOW_BORDER
+ /* Redraw border with new dimensions */
+ draw_border();
+#endif // !STATUSWINDOW_BORDER
+
+ mvwprintw(status_wnd, 1, 2, "$:%d HP:%d(%d) MP:%d(%d) St:%2d Dx:%2d Co:%2d Wi:%2d Wp:%2d Ch:%2d",
+ *(uint32_t*)(ch->inventory.coins->user_data),
+ ch->cur_hitpoints, ch->max_hitpoints, ch->cur_magic, ch->max_magic,
+ ch->stats[STAT_STRENGTH], ch->stats[STAT_DEXTERITY], ch->stats[STAT_CONSTITUTION],
+ ch->stats[STAT_WISDOM], ch->stats[STAT_WILLPOWER], ch->stats[STAT_CHARISMA]);
+
+ mvwprintw(status_wnd, 2, 2, "%s Xp:%2d/%d T:%d S:%d",
+ ch->name, ch->level, ch->experience, ch->turns, ch->score);
+
+ wnoutrefresh(status_wnd);
+}
Property changes on: trunk/status_window.c
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:mergeinfo
+
Added: svn:eol-style
+ native
Copied: trunk/status_window.h (from rev 54, trunk/stat_window.h)
===================================================================
--- trunk/status_window.h (rev 0)
+++ trunk/status_window.h 2008-11-24 05:32:17 UTC (rev 55)
@@ -0,0 +1,12 @@
+#ifndef DERACIEL_STATUS_WINDOW_H
+#define DERACIEL_STATUS_WINDOW_H
+
+#include "char.h"
+
+void status_window_create(void);
+void status_window_destroy(void);
+void status_window_resize(void);
+void status_window_update(const struct char_struct *ch);
+
+#endif // !DERACIEL_STATUS_WINDOW_H
+
Property changes on: trunk/status_window.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:mergeinfo
+
Added: svn:eol-style
+ native
Modified: trunk/text_window.c
===================================================================
--- trunk/text_window.c 2008-11-22 13:48:46 UTC (rev 54)
+++ trunk/text_window.c 2008-11-24 05:32:17 UTC (rev 55)
@@ -3,8 +3,8 @@
#include <string.h>
#include <ncurses.h>
-#define BORDER_WND_MAXWIDTH (80)
-#define BORDER_WND_MAXHEIGHT (2)
+#define TEXTWINDOW_MAXWIDTH (80)
+#define TEXTWINDOW_MAXHEIGHT (2)
#define TEXTWINDOW_BORDER
static WINDOW *border_wnd; /* Window handle */
@@ -15,8 +15,8 @@
void text_window_create(void)
{
- border_wnd = newwin(BORDER_WND_MAXHEIGHT, BORDER_WND_MAXWIDTH, 0, 0);
- text_wnd = newwin(BORDER_WND_MAXHEIGHT-1, BORDER_WND_MAXWIDTH-2, 0, 1);
+ border_wnd = newwin(TEXTWINDOW_MAXHEIGHT, TEXTWINDOW_MAXWIDTH, 0, 0);
+ text_wnd = newwin(TEXTWINDOW_MAXHEIGHT-1, TEXTWINDOW_MAXWIDTH-2, 0, 1);
if (!border_wnd || !text_wnd) {
fprintf(stderr, "text window creation failed!\n");
@@ -51,6 +51,15 @@
+void text_window_resize(void)
+{
+ /* Reallocate storage for resized text window */
+ wresize(border_wnd, TEXTWINDOW_MAXHEIGHT, TEXTWINDOW_MAXWIDTH);
+ wresize(text_wnd, TEXTWINDOW_MAXHEIGHT-1, TEXTWINDOW_MAXWIDTH-2);
+}
+
+
+
void text_window_out(const char *string)
{
#ifdef TEXTWINDOW_BORDER
Modified: trunk/text_window.h
===================================================================
--- trunk/text_window.h 2008-11-22 13:48:46 UTC (rev 54)
+++ trunk/text_window.h 2008-11-24 05:32:17 UTC (rev 55)
@@ -3,6 +3,7 @@
void text_window_create(void);
void text_window_destroy(void);
+void text_window_resize(void);
void text_window_out(const char *string);
void text_window_clear(void);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|