shithub: choc

Download patch

ref: ef92ce016e328c1270597f2f1627c72bc3490d64
parent: a990e948564aa96f95dc5c692e512a68fd48852e
author: Simon Howard <fraggle@gmail.com>
date: Fri Jun 2 16:14:39 EDT 2006

Make mouse button presses on widgets actually do useful things

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 553

--- a/textscreen/txt_button.c
+++ b/textscreen/txt_button.c
@@ -64,6 +64,18 @@
     return 0;
 }
 
+static void TXT_ButtonMousePress(TXT_UNCAST_ARG(button), int x, int y, int b)
+{
+    TXT_CAST_ARG(txt_button_t, button);
+
+    if (b == TXT_MOUSE_LEFT)
+    {
+        // Equivalent to pressing enter
+
+        TXT_ButtonKeyPress(button, KEY_ENTER);
+    }
+}
+
 txt_widget_class_t txt_button_class =
 {
     TXT_ButtonSizeCalc,
@@ -70,6 +82,7 @@
     TXT_ButtonDrawer,
     TXT_ButtonKeyPress,
     TXT_ButtonDestructor,
+    TXT_ButtonMousePress,
 };
 
 txt_button_t *TXT_NewButton(char *label)
--- a/textscreen/txt_checkbox.c
+++ b/textscreen/txt_checkbox.c
@@ -82,6 +82,18 @@
     return 0;
 }
 
+static void TXT_CheckBoxMousePress(TXT_UNCAST_ARG(checkbox), int x, int y, int b)
+{
+    TXT_CAST_ARG(txt_checkbox_t, checkbox);
+
+    if (b == TXT_MOUSE_LEFT)
+    {
+        // Equivalent to pressing enter
+
+        TXT_CheckBoxKeyPress(checkbox, KEY_ENTER);
+    }
+}
+
 txt_widget_class_t txt_checkbox_class =
 {
     TXT_CheckBoxSizeCalc,
@@ -88,6 +100,7 @@
     TXT_CheckBoxDrawer,
     TXT_CheckBoxKeyPress,
     TXT_CheckBoxDestructor,
+    TXT_CheckBoxMousePress,
 };
 
 txt_checkbox_t *TXT_NewCheckBox(char *label, int *variable)
--- a/textscreen/txt_inputbox.c
+++ b/textscreen/txt_inputbox.c
@@ -188,6 +188,24 @@
     return 1;
 }
 
+static void TXT_InputBoxMousePress(TXT_UNCAST_ARG(inputbox),
+                                   int x, int y, int b)
+{
+    TXT_CAST_ARG(txt_inputbox_t, inputbox);
+
+    if (b == TXT_MOUSE_LEFT)
+    {
+        // Make mouse clicks start editing the box
+
+        if (!inputbox->editing)
+        {
+            // Send a simulated keypress to start editing
+
+            TXT_WidgetKeyPress(inputbox, KEY_ENTER);
+        }
+    }
+}
+
 txt_widget_class_t txt_inputbox_class =
 {
     TXT_InputBoxSizeCalc,
@@ -194,6 +212,7 @@
     TXT_InputBoxDrawer,
     TXT_InputBoxKeyPress,
     TXT_InputBoxDestructor,
+    TXT_InputBoxMousePress,
 };
 
 txt_widget_class_t txt_int_inputbox_class =
@@ -202,6 +221,7 @@
     TXT_InputBoxDrawer,
     TXT_IntInputBoxKeyPress,
     TXT_InputBoxDestructor,
+    TXT_InputBoxMousePress,
 };
 
 static void SetBufferFromValue(txt_inputbox_t *inputbox)
--- a/textscreen/txt_radiobutton.c
+++ b/textscreen/txt_radiobutton.c
@@ -85,6 +85,19 @@
     return 0;
 }
 
+static void TXT_RadioButtonMousePress(TXT_UNCAST_ARG(radiobutton), 
+                                      int x, int y, int b)
+{
+    TXT_CAST_ARG(txt_radiobutton_t, radiobutton);
+
+    if (b == TXT_MOUSE_LEFT)
+    {
+        // Equivalent to pressing enter
+
+        TXT_RadioButtonKeyPress(radiobutton, KEY_ENTER);
+    }
+}
+
 txt_widget_class_t txt_radiobutton_class =
 {
     TXT_RadioButtonSizeCalc,
@@ -91,6 +104,7 @@
     TXT_RadioButtonDrawer,
     TXT_RadioButtonKeyPress,
     TXT_RadioButtonDestructor,
+    TXT_RadioButtonMousePress,
 };
 
 txt_radiobutton_t *TXT_NewRadioButton(char *label, int *variable, int value)
--- a/textscreen/txt_window.c
+++ b/textscreen/txt_window.c
@@ -307,7 +307,9 @@
 static void MouseButtonPress(txt_window_t *window, int b)
 {
     int x, y;
+    int i;
     txt_widget_t *widgets;
+    txt_widget_t *widget;
 
     // Lay out the window, set positions and sizes of all widgets
 
@@ -325,6 +327,21 @@
      && y >= widgets->y && y < widgets->y + widgets->h)
     {
         TXT_WidgetMousePress(window, x, y, b);
+    }
+
+    // Was one of the action area buttons pressed?
+
+    for (i=0; i<3; ++i)
+    {
+        widget = (txt_widget_t *) window->actions[i];
+
+        if (widget != NULL
+         && x >= widget->x && x < widget->x + widget->w
+         && y >= widget->y && y < widget->y + widget->h)
+        {
+            TXT_WidgetMousePress(widget, x, y, b);
+            break;
+        }
     }
 }
 
--- a/textscreen/txt_window_action.c
+++ b/textscreen/txt_window_action.c
@@ -58,6 +58,19 @@
     return 0;
 }
 
+static void TXT_WindowActionMousePress(TXT_UNCAST_ARG(action), 
+                                       int x, int y, int b)
+{
+    TXT_CAST_ARG(txt_window_action_t, action);
+
+    // Simulate a press of the key
+
+    if (b == TXT_MOUSE_LEFT)
+    {
+        TXT_WindowActionKeyPress(action, action->key);
+    }
+}
+
 txt_widget_class_t txt_window_action_class =
 {
     TXT_WindowActionSizeCalc,
@@ -64,6 +77,7 @@
     TXT_WindowActionDrawer,
     TXT_WindowActionKeyPress,
     TXT_WindowActionDestructor,
+    TXT_WindowActionMousePress,
 };
 
 txt_window_action_t *TXT_NewWindowAction(int key, char *label)