foxygit / doom Log in
commit 58fba3477da8fc6bdec3558489556c3439f90fc5
Author:     Simon Howard <fraggle@gmail.com>
AuthorDate: Sat Aug 31 00:12:09 2013 +0000
Commit:     Simon Howard <fraggle@gmail.com>
CommitDate: Sat Aug 31 00:12:09 2013 +0000

    Add textscreen functions to raise and lower windows.

    Subversion-branch: /branches/v2-branch
    Subversion-revision: 2628
---
 textscreen/txt_desktop.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++
 textscreen/txt_desktop.h | 20 +++++++++++++++++++
 2 files changed, 72 insertions(+)

diff --git a/textscreen/txt_desktop.c b/textscreen/txt_desktop.c
index 09589688..2316145f 100644
--- a/textscreen/txt_desktop.c
+++ b/textscreen/txt_desktop.c
@@ -97,6 +97,58 @@ txt_window_t *TXT_GetActiveWindow(void)
     return all_windows[num_windows - 1];
 }

+int TXT_RaiseWindow(txt_window_t *window)
+{
+    int i;
+
+    for (i = 0; i < num_windows - 1; ++i)
+    {
+        if (all_windows[i] == window)
+        {
+            all_windows[i] = all_windows[i + 1];
+            all_windows[i + 1] = window;
+
+            if (i == num_windows - 2)
+            {
+                TXT_SetWindowFocus(all_windows[i], 0);
+                TXT_SetWindowFocus(window, 1);
+            }
+
+            return 1;
+        }
+    }
+
+    // Window not in the list, or at the end of the list (top) already.
+
+    return 0;
+}
+
+int TXT_LowerWindow(txt_window_t *window)
+{
+    int i;
+
+    for (i = 0; i < num_windows - 1; ++i)
+    {
+        if (all_windows[i + 1] == window)
+        {
+            all_windows[i + 1] = all_windows[i];
+            all_windows[i] = window;
+
+            if (i == num_windows - 2)
+            {
+                TXT_SetWindowFocus(window, 0);
+                TXT_SetWindowFocus(all_windows[i + 1], 1);
+            }
+
+            return 1;
+        }
+    }
+
+    // Window not in the list, or at the start of the list (bottom) already.
+
+    return 0;
+}
+
 static void DrawDesktopBackground(const char *title)
 {
     int i;
diff --git a/textscreen/txt_desktop.h b/textscreen/txt_desktop.h
index 9e2a42c7..f98d4627 100644
--- a/textscreen/txt_desktop.h
+++ b/textscreen/txt_desktop.h
@@ -91,5 +91,25 @@ void TXT_SetPeriodicCallback(TxtIdleCallback callback,
                              void *user_data,
                              unsigned int period);

+/**
+ * Raise the z-position of the given window relative to other windows.
+ *
+ * @param window        The window to raise.
+ * @return              Non-zero if the window was raised successfully,
+ *                      or zero if the window could not be raised further.
+ */
+
+int TXT_RaiseWindow(txt_window_t *window);
+
+/**
+ * Lower the z-position of the given window relative to other windows.
+ *
+ * @param window        The window to make inactive.
+ * @return              Non-zero if the window was lowered successfully,
+ *                      or zero if the window could not be lowered further.
+ */
+
+int TXT_LowerWindow(txt_window_t *window);
+
 #endif /* #ifndef TXT_DESKTOP_H */