foxygit / doom Log in
commit e4681dd485de5a393070e3fcb91505116405cc1d
Author:     Simon Howard <fraggle@gmail.com>
AuthorDate: Sun Jul 29 23:41:12 2007 +0000
Commit:     Simon Howard <fraggle@gmail.com>
CommitDate: Sun Jul 29 23:41:12 2007 +0000

    Allow more than the standard three mouse buttons to be defined through
    setup (hopefully)

    Subversion-branch: /trunk/chocolate-doom
    Subversion-revision: 939
---
 setup/txt_mouseinput.c  | 17 +----------------
 textscreen/txt_main.h   | 10 ++++++----
 textscreen/txt_sdl.c    | 28 ++++++++++++++++++++++------
 textscreen/txt_window.c |  4 +---
 4 files changed, 30 insertions(+), 29 deletions(-)

diff --git a/setup/txt_mouseinput.c b/setup/txt_mouseinput.c
index 6b70d110..05c89b39 100644
--- a/setup/txt_mouseinput.c
+++ b/setup/txt_mouseinput.c
@@ -33,21 +33,6 @@

 #define MOUSE_INPUT_WIDTH 8

-static int MouseButtonToSetting(int b)
-{
-    switch (b)
-    {
-        case TXT_MOUSE_LEFT:
-            return 0;
-        case TXT_MOUSE_RIGHT:
-            return 1;
-        case TXT_MOUSE_MIDDLE:
-            return 2;
-        default:
-            return -1;
-    }
-}
-
 static int MousePressCallback(txt_window_t *window,
                               int x, int y, int b,
                               TXT_UNCAST_ARG(mouse_input))
@@ -56,7 +41,7 @@ static int MousePressCallback(txt_window_t *window,

     // Got the mouse press.  Save to the variable and close the window.

-    *mouse_input->variable = MouseButtonToSetting(b);
+    *mouse_input->variable = b - TXT_MOUSE_BASE;
     TXT_EmitSignal(mouse_input, "set");
     TXT_CloseWindow(window);

diff --git a/textscreen/txt_main.h b/textscreen/txt_main.h
index 7978c8b7..4357d656 100644
--- a/textscreen/txt_main.h
+++ b/textscreen/txt_main.h
@@ -33,10 +33,12 @@
 #include "txt_sdl.h"

 // Special keypress values that correspond to mouse button clicks
-//
-#define TXT_MOUSE_LEFT   1
-#define TXT_MOUSE_RIGHT  2
-#define TXT_MOUSE_MIDDLE 3
+
+#define TXT_MOUSE_BASE   0x10000
+#define TXT_MOUSE_LEFT   (TXT_MOUSE_BASE + 0)
+#define TXT_MOUSE_RIGHT  (TXT_MOUSE_BASE + 1)
+#define TXT_MOUSE_MIDDLE (TXT_MOUSE_BASE + 2)
+#define TXT_MAX_MOUSE_BUTTONS  16

 // Screen size

diff --git a/textscreen/txt_sdl.c b/textscreen/txt_sdl.c
index 7a0e3ba8..73a69569 100644
--- a/textscreen/txt_sdl.c
+++ b/textscreen/txt_sdl.c
@@ -322,6 +322,24 @@ static int TranslateKey(SDL_keysym *sym)
     }
 }

+// Convert an SDL button index to textscreen button index.
+//
+// Note special cases because 2 == mid in SDL, 3 == mid in textscreen/setup
+
+static int SDLButtonToTXTButton(int button)
+{
+    switch (button)
+    {
+        case SDL_BUTTON_LEFT:
+            return TXT_MOUSE_LEFT;
+        case SDL_BUTTON_RIGHT:
+            return TXT_MOUSE_RIGHT;
+        case SDL_BUTTON_MIDDLE:
+            return TXT_MOUSE_MIDDLE;
+        default:
+            return TXT_MOUSE_BASE + button - 1;
+    }
+}

 signed int TXT_GetChar(void)
 {
@@ -345,12 +363,10 @@ signed int TXT_GetChar(void)
         switch (ev.type)
         {
             case SDL_MOUSEBUTTONDOWN:
-                if (ev.button.button == SDL_BUTTON_LEFT)
-                    return TXT_MOUSE_LEFT;
-                else if (ev.button.button == SDL_BUTTON_RIGHT)
-                    return TXT_MOUSE_RIGHT;
-                else if (ev.button.button == SDL_BUTTON_MIDDLE)
-                    return TXT_MOUSE_MIDDLE;
+                if (ev.button.button < TXT_MAX_MOUSE_BUTTONS)
+                {
+                    return SDLButtonToTXTButton(ev.button.button);
+                }
                 break;

             case SDL_KEYDOWN:
diff --git a/textscreen/txt_window.c b/textscreen/txt_window.c
index 7a965d27..33f53d4a 100644
--- a/textscreen/txt_window.c
+++ b/textscreen/txt_window.c
@@ -390,9 +390,7 @@ void TXT_WindowKeyPress(txt_window_t *window, int c)

     // Is this a mouse button ?

-    if (c == TXT_MOUSE_LEFT
-     || c == TXT_MOUSE_MIDDLE
-     || c == TXT_MOUSE_RIGHT)
+    if (c >= TXT_MOUSE_BASE && c < TXT_MOUSE_BASE + TXT_MAX_MOUSE_BUTTONS)
     {
         MouseButtonPress(window, c);
         return;