diff options
author | Simon Howard | 2006-06-02 20:14:39 +0000 |
---|---|---|
committer | Simon Howard | 2006-06-02 20:14:39 +0000 |
commit | ef92ce016e328c1270597f2f1627c72bc3490d64 (patch) | |
tree | 0a487dc17f613bd7deeecd7c931d02c19834808f /textscreen | |
parent | a990e948564aa96f95dc5c692e512a68fd48852e (diff) | |
download | chocolate-doom-ef92ce016e328c1270597f2f1627c72bc3490d64.tar.gz chocolate-doom-ef92ce016e328c1270597f2f1627c72bc3490d64.tar.bz2 chocolate-doom-ef92ce016e328c1270597f2f1627c72bc3490d64.zip |
Make mouse button presses on widgets actually do useful things
Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 553
Diffstat (limited to 'textscreen')
-rw-r--r-- | textscreen/txt_button.c | 13 | ||||
-rw-r--r-- | textscreen/txt_checkbox.c | 13 | ||||
-rw-r--r-- | textscreen/txt_inputbox.c | 20 | ||||
-rw-r--r-- | textscreen/txt_radiobutton.c | 14 | ||||
-rw-r--r-- | textscreen/txt_window.c | 17 | ||||
-rw-r--r-- | textscreen/txt_window_action.c | 14 |
6 files changed, 91 insertions, 0 deletions
diff --git a/textscreen/txt_button.c b/textscreen/txt_button.c index 8b8e704b..26e148b0 100644 --- a/textscreen/txt_button.c +++ b/textscreen/txt_button.c @@ -64,12 +64,25 @@ static int TXT_ButtonKeyPress(TXT_UNCAST_ARG(button), int key) 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, TXT_ButtonDrawer, TXT_ButtonKeyPress, TXT_ButtonDestructor, + TXT_ButtonMousePress, }; txt_button_t *TXT_NewButton(char *label) diff --git a/textscreen/txt_checkbox.c b/textscreen/txt_checkbox.c index d32a240c..cde095a8 100644 --- a/textscreen/txt_checkbox.c +++ b/textscreen/txt_checkbox.c @@ -82,12 +82,25 @@ static int TXT_CheckBoxKeyPress(TXT_UNCAST_ARG(checkbox), int key) 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, TXT_CheckBoxDrawer, TXT_CheckBoxKeyPress, TXT_CheckBoxDestructor, + TXT_CheckBoxMousePress, }; txt_checkbox_t *TXT_NewCheckBox(char *label, int *variable) diff --git a/textscreen/txt_inputbox.c b/textscreen/txt_inputbox.c index cb7bf4fa..59d62da3 100644 --- a/textscreen/txt_inputbox.c +++ b/textscreen/txt_inputbox.c @@ -188,12 +188,31 @@ static int TXT_IntInputBoxKeyPress(TXT_UNCAST_ARG(inputbox), int key) 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, TXT_InputBoxDrawer, TXT_InputBoxKeyPress, TXT_InputBoxDestructor, + TXT_InputBoxMousePress, }; txt_widget_class_t txt_int_inputbox_class = @@ -202,6 +221,7 @@ txt_widget_class_t txt_int_inputbox_class = TXT_InputBoxDrawer, TXT_IntInputBoxKeyPress, TXT_InputBoxDestructor, + TXT_InputBoxMousePress, }; static void SetBufferFromValue(txt_inputbox_t *inputbox) diff --git a/textscreen/txt_radiobutton.c b/textscreen/txt_radiobutton.c index d5f694f7..56cec359 100644 --- a/textscreen/txt_radiobutton.c +++ b/textscreen/txt_radiobutton.c @@ -85,12 +85,26 @@ static int TXT_RadioButtonKeyPress(TXT_UNCAST_ARG(radiobutton), int key) 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, TXT_RadioButtonDrawer, TXT_RadioButtonKeyPress, TXT_RadioButtonDestructor, + TXT_RadioButtonMousePress, }; txt_radiobutton_t *TXT_NewRadioButton(char *label, int *variable, int value) diff --git a/textscreen/txt_window.c b/textscreen/txt_window.c index 0cc46308..7481ccfa 100644 --- a/textscreen/txt_window.c +++ b/textscreen/txt_window.c @@ -307,7 +307,9 @@ void TXT_SetWindowPosition(txt_window_t *window, 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 @@ -326,6 +328,21 @@ static void MouseButtonPress(txt_window_t *window, int b) { 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; + } + } } void TXT_WindowKeyPress(txt_window_t *window, int c) diff --git a/textscreen/txt_window_action.c b/textscreen/txt_window_action.c index 727e9b56..a70d0002 100644 --- a/textscreen/txt_window_action.c +++ b/textscreen/txt_window_action.c @@ -58,12 +58,26 @@ static int TXT_WindowActionKeyPress(TXT_UNCAST_ARG(action), int key) 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, TXT_WindowActionDrawer, TXT_WindowActionKeyPress, TXT_WindowActionDestructor, + TXT_WindowActionMousePress, }; txt_window_action_t *TXT_NewWindowAction(int key, char *label) |