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 TXT_LayoutWindow(window); // Get the current mouse position TXT_GetMousePosition(&x, &y); // Try the mouse button listener // This happens whether it is in the window range or not if (window->mouse_listener != NULL) { // Mouse listener can eat button presses if (window->mouse_listener(window, x, y, b, window->mouse_listener_data)) { return; } } // Is it within the table range? widgets = (txt_widget_t *) window; if (x >= widgets->x && x < (signed) (widgets->x + widgets->w) && y >= widgets->y && y < (signed) (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 < (signed) (widget->x + widget->w) && y >= widget->y && y < (signed) (widget->y + widget->h)) { TXT_WidgetMousePress(widget, x, y, b); break; } } }
int TXT_HoveringOverWidget(TXT_UNCAST_ARG(widget)) { TXT_CAST_ARG(txt_widget_t, widget); txt_window_t *active_window; int x, y; // We can only be hovering over widgets in the active window. active_window = TXT_GetActiveWindow(); if (active_window == NULL || !TXT_ContainsWidget(active_window, widget)) { return 0; } // Is the mouse cursor within the bounds of the widget? TXT_GetMousePosition(&x, &y); return (x >= widget->x && x < widget->x + widget->w && y >= widget->y && y < widget->y + widget->h); }
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 TXT_LayoutWindow(window); // Get the current mouse position TXT_GetMousePosition(&x, &y); // Try the mouse button listener // This happens whether it is in the window range or not if (window->mouse_listener != NULL) { // Mouse listener can eat button presses if (window->mouse_listener(window, x, y, b, window->mouse_listener_data)) { return; } } // Is it within the table range? widgets = (txt_widget_t *) window; if (x >= widgets->x && x < (signed) (widgets->x + widgets->w) && y >= widgets->y && y < (signed) (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 < (signed) (widget->x + widget->w) && y >= widget->y && y < (signed) (widget->y + widget->h)) { int was_focused; // Main table temporarily loses focus when action area button // is clicked. This way, any active input boxes that depend // on having focus will save their values before the // action is performed. was_focused = window->table.widget.focused; TXT_SetWidgetFocus(window, 0); TXT_SetWidgetFocus(window, was_focused); // Pass through mouse press. TXT_WidgetMousePress(widget, x, y, b); break; } } }