Make mouse button presses on widgets actually do useful things
Subversion-branch: /trunk/chocolate-doom Subversion-revision: 553
This commit is contained in:
parent
a990e94856
commit
ef92ce016e
6 changed files with 91 additions and 0 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue