foxygit / doom Log in
commit 98ecb00e9d480d6391417883e6f1f035fd2014b7
Author:     Simon Howard <fraggle@gmail.com>
AuthorDate: Tue Sep 20 22:06:12 2011 +0000
Commit:     Simon Howard <fraggle@gmail.com>
CommitDate: Tue Sep 20 22:06:12 2011 +0000

    Don't allow dropdown widget pop-up window to be placed outside the
    boundaries of the screen.

    Subversion-branch: /branches/v2-branch
    Subversion-revision: 2391
---
 textscreen/txt_dropdown.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/textscreen/txt_dropdown.c b/textscreen/txt_dropdown.c
index c9a5d015..a6185a4c 100644
--- a/textscreen/txt_dropdown.c
+++ b/textscreen/txt_dropdown.c
@@ -49,14 +49,29 @@ static int ValidSelection(txt_dropdown_list_t *list)

 static int SelectorWindowY(txt_dropdown_list_t *list)
 {
+    int result;
+
     if (ValidSelection(list))
     {
-        return list->widget.y - 1 - *list->variable;
+        result = list->widget.y - 1 - *list->variable;
     }
     else
     {
-        return list->widget.y - 1 - (list->num_values / 2);
+        result = list->widget.y - 1 - (list->num_values / 2);
+    }
+
+    // Keep dropdown inside the screen.
+
+    if (result < 1)
+    {
+        result = 1;
+    }
+    else if (result + list->num_values > (TXT_SCREEN_H - 3))
+    {
+        result = TXT_SCREEN_H - list->num_values - 3;
     }
+
+    return result;
 }

 // Called when a button in the selector window is pressed