From e6dcab0e1261bc96d7754b24b798cc3a5f262335 Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Thu, 29 Aug 2013 22:05:05 +0200
Subject: [PATCH] Moved several windows control functions from misc library
 into new wincontrol library.

---
 src/control.c    |  6 ++---
 src/main.c       |  5 ++--
 src/misc.c       | 64 +++---------------------------------------------
 src/misc.h       | 30 +----------------------
 src/wincontrol.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/wincontrol.h | 44 +++++++++++++++++++++++++++++++++
 6 files changed, 117 insertions(+), 96 deletions(-)
 create mode 100644 src/wincontrol.c
 create mode 100644 src/wincontrol.h

diff --git a/src/control.c b/src/control.c
index a2a44b2..0c782ab 100644
--- a/src/control.c
+++ b/src/control.c
@@ -11,9 +11,9 @@
 #include "map.h" /* for map_scroll(), map_center_player(), dir enum */
 #include "main.h" /* for World struct */
 #include "rexit.h" /* for exit_err() */
-#include "misc.h" /* for scroll_pad(), toggle_window(),
-                   * growshrink_active_window()
-                   */
+#include "wincontrol.h" /* for scroll_pad(), toggle_window(),
+                         * growshrink_active_window()
+                         */
 #include "map_object_actions.h" /* for player_wait(), move_player() */
 #include "command_db.h" /* for is_command_id_shortdsc() */
 
diff --git a/src/main.c b/src/main.c
index f240975..6c60afa 100644
--- a/src/main.c
+++ b/src/main.c
@@ -21,9 +21,8 @@
                           * build_map_objects()
                           */
 #include "map.h" /* for struct Map, init_map() */
-#include "misc.h" /* for update_log(), toggle_window(), find_passable_pos(),
-                   * save_game()
-                   */
+#include "misc.h" /* for update_log(), find_passable_pos(), save_game() */
+#include "wincontrol.h" /* for toggle_window() */
 #include "rrand.h" /* for rrand(), rrand_seed() */
 #include "rexit.h" /* for exit_game() */
 #include "control.h" /* for meta_control() */
diff --git a/src/misc.c b/src/misc.c
index b826436..b007dcd 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -5,20 +5,18 @@
 #include <unistd.h> /* for unlink(), acess() */
 #include <stdlib.h> /* for calloc(), free() */
 #include <string.h> /* for strlen(), strcmp(), memcpy() */
-#include <stdint.h> /* for uint8_t */
-#include "windows.h" /* for suspend_win(), append_win(), reset_pad_offset(),
-                      * resize_active_win(), struct Win, struct WinMeta
-                      */
+#include <stdint.h> /* for uint16_t */
 #include "readwrite.h" /* for [read/write]_uint[8/16/32][_bigendian]() */
 #include "map_objects.h" /* for struct Monster, write_map_objects(), */
 #include "map_object_actions.h" /* for is_passable(), move_monster() */
 #include "map.h" /* for Map struct */
 #include "main.h" /* for World struct */
-#include "yx_uint16.h" /* for yx_uint16 */
+#include "yx_uint16.h" /* for yx_uint16 struct */
 #include "rrand.h" /* for rrand(), rrand_seed() */
 #include "rexit.h" /* for exit_err() */
 
 
+
 extern void textfile_sizes(FILE * file, uint16_t * linemax_p,
                            uint16_t * n_lines_p)
 {
@@ -191,62 +189,6 @@ extern void save_game(struct World * world)
 
 
 
-extern uint8_t toggle_window(struct WinMeta * win_meta, struct Win * win)
-{
-    if (0 != win->frame.curses_win)
-    {
-        return suspend_win(win_meta, win);
-    }
-    else
-    {
-        return append_win(win_meta, win);
-    }
-}
-
-
-
-extern void scroll_pad(struct WinMeta * win_meta, char dir)
-{
-    if      ('+' == dir)
-    {
-        reset_pad_offset(win_meta, win_meta->pad_offset + 1);
-    }
-    else if ('-' == dir)
-    {
-        reset_pad_offset(win_meta, win_meta->pad_offset - 1);
-    }
-}
-
-
-
-extern uint8_t growshrink_active_window(struct WinMeta * win_meta, char change)
-{
-    if (0 != win_meta->active)
-    {
-        struct yx_uint16 size = win_meta->active->frame.size;
-        if      (change == '-')
-        {
-            size.y--;
-        }
-        else if (change == '+')
-        {
-            size.y++;
-        }
-        else if (change == '_')
-        {
-            size.x--;
-        }
-        else if (change == '*')
-        {
-            size.x++;
-        }
-        return resize_active_win (win_meta, size);
-    }
-    return 0;
-}
-
-
-
 extern struct yx_uint16 find_passable_pos(struct Map * map)
 {
     struct yx_uint16 pos;
diff --git a/src/misc.h b/src/misc.h
index eb2d0cd..be43197 100644
--- a/src/misc.h
+++ b/src/misc.h
@@ -9,12 +9,10 @@
 
 
 
-#include <stdint.h>    /* for uint8_t, uint16_t, uint32_t */
+#include <stdint.h>    /* for uint16_t */
 #include <stdio.h>     /* for FILE typedef */
 #include "yx_uint16.h" /* for yx_uint16 coordinates */
 struct World;
-struct WinMeta;
-struct Win;
 struct Map;
 
 
@@ -54,32 +52,6 @@ extern void save_game(struct World * world);
 
 
 
-/* Toggle display of a window "win".
- *
- * Return 0 on success, 1 on (ncurses pad/window memory allocation) error.
- */
-extern uint8_t toggle_window(struct WinMeta * win_meta, struct Win * win);
-
-
-
-/* Try to scroll virtual screen left ("dir" = "-") or right ("dir" = "+"),
- * subject to the limitations provided by the window manager via
- * reset_pad_offset().
- */
-extern void scroll_pad(struct WinMeta * win_meta, char dir);
-
-
-
-/* Try to grow or shrink the active window horizontally ("change" = "*"/"_") or
- * vertically ("change = "+"/"-") by one cell size, subject to the limitations
- * provided by the window manager via resize_active_win().
- *
- * Return 0 on success, 1 on (ncurses pad/window memory allocation) error.
- */
-extern uint8_t growshrink_active_window(struct WinMeta * win_meta, char change);
-
-
-
 /* Return a random position on the map "map" that is passable (as determined by
  * is_passable().
  */
diff --git a/src/wincontrol.c b/src/wincontrol.c
new file mode 100644
index 0000000..4d166e8
--- /dev/null
+++ b/src/wincontrol.c
@@ -0,0 +1,64 @@
+/* wincontrol.c */
+
+#include "wincontrol.h"
+#include <stdint.h> /* for uint8_t */
+#include "windows.h" /* for suspend_win(), append_win(), reset_pad_offset(),
+                      * resize_active_win(), struct Win, struct WinMeta
+                      */
+#include "yx_uint16.h" /* for yx_uint16 struct */
+
+
+extern uint8_t toggle_window(struct WinMeta * win_meta, struct Win * win)
+{
+    if (0 != win->frame.curses_win)
+    {
+        return suspend_win(win_meta, win);
+    }
+    else
+    {
+        return append_win(win_meta, win);
+    }
+}
+
+
+
+extern void scroll_pad(struct WinMeta * win_meta, char dir)
+{
+    if      ('+' == dir)
+    {
+        reset_pad_offset(win_meta, win_meta->pad_offset + 1);
+    }
+    else if ('-' == dir)
+    {
+        reset_pad_offset(win_meta, win_meta->pad_offset - 1);
+    }
+}
+
+
+
+extern uint8_t growshrink_active_window(struct WinMeta * win_meta, char change)
+{
+    if (0 != win_meta->active)
+    {
+        struct yx_uint16 size = win_meta->active->frame.size;
+        if      (change == '-')
+        {
+            size.y--;
+        }
+        else if (change == '+')
+        {
+            size.y++;
+        }
+        else if (change == '_')
+        {
+            size.x--;
+        }
+        else if (change == '*')
+        {
+            size.x++;
+        }
+        return resize_active_win (win_meta, size);
+    }
+    return 0;
+}
+
diff --git a/src/wincontrol.h b/src/wincontrol.h
new file mode 100644
index 0000000..18ac01c
--- /dev/null
+++ b/src/wincontrol.h
@@ -0,0 +1,44 @@
+/* wincontrol.h
+ *
+ * Routines that build on top of the windows library to provide a simple window
+ * management API to the game.
+ */
+
+#ifndef WINCONTROL_H
+#define WINCONTROL_H
+
+
+
+#include <stdint.h> /* for uint8_t */
+struct Win;
+struct WinMeta;
+
+
+
+/* Toggle display of a window "win".
+ *
+ * Return 0 on success, 1 on (ncurses pad/window memory allocation) error.
+ */
+extern uint8_t toggle_window(struct WinMeta * win_meta, struct Win * win);
+
+
+
+/* Try to scroll virtual screen left ("dir" = "-") or right ("dir" = "+"),
+ * subject to the limitations provided by the window manager via
+ * reset_pad_offset().
+ */
+extern void scroll_pad(struct WinMeta * win_meta, char dir);
+
+
+
+/* Try to grow or shrink the active window horizontally ("change" = "*"/"_") or
+ * vertically ("change = "+"/"-") by one cell size, subject to the limitations
+ * provided by the window manager via resize_active_win().
+ *
+ * Return 0 on success, 1 on (ncurses pad/window memory allocation) error.
+ */
+extern uint8_t growshrink_active_window(struct WinMeta * win_meta, char change);
+
+
+
+#endif
-- 
2.30.2