@@ -27,16 +27,25 @@ class font_string;
2727 * case, the "normal" font is rendered with a slight offset that you
2828 * are free to define.
2929 *
30- * Note that a button has frame::enable_mouse set to `true` by
30+ * The button "click" event will be triggered by all registered combinations
31+ * of mouse events configured with button::enable_button_clicks.
32+ *
33+ * Note that a button has frame::enable_mouse set to `true` and
34+ * button::enable_button_clicks set to `true` for `"LeftMouseUp"` by
3135 * default.
3236 *
3337 * __Events.__ Hard-coded events available to all buttons, in
3438 * addition to those from frame:
3539 *
3640 * - `OnClick`: Triggered when the button is clicked, either when
37- * button::click is called, or just when a mouse button is pressed
38- * when the cursor is over the button.
39- * - `OnDoubleClick`: Triggered when the button is double-clicked.
41+ * button::click is called, or just when a mouse button is released or
42+ * pressed when the cursor is over the button (depending on whether clicks
43+ * are enabled for the mouse button and mouse button state, see
44+ * button::enable_button_clicks). This event provides five arguments to
45+ * the registered callback: a number identifying the mouse button, a number
46+ * identifying the mouse button event, a string containing the human-readable
47+ * name of this button event (e.g., `"LeftButtonUp"`, `"RightButtonDown"`, ...),
48+ * and the mouse X and Y position.
4049 * - `OnEnable`: Triggered by button::enable.
4150 * - `OnDisable`: Triggered by button::disable.
4251 */
@@ -301,6 +310,21 @@ class button : public frame {
301310 */
302311 virtual void release ();
303312
313+ /* *
314+ * \brief Handle a mouse click over this button.
315+ * \param mouse_event The mouse event with which to generate a click
316+ * \note This calls the OnClick() handler only if the event is registered for clicks.
317+ */
318+ void click (const std::string& mouse_event);
319+
320+ /* *
321+ * \brief Handle a mouse click over this button.
322+ * \param button_id The mouse button with which to generate a click
323+ * \param button_event The mouse button event with which to generate a click
324+ * \note This calls the OnClick() handler only if the event is registered for clicks.
325+ */
326+ void click (input::mouse_button button_id, input::mouse_button_event button_event);
327+
304328 /* *
305329 * \brief Highlights this button.
306330 * \note The button will be highlighted even if the
@@ -345,6 +369,99 @@ class button : public frame {
345369 */
346370 const vector2f& get_pushed_text_offset () const ;
347371
372+ /* *
373+ * \brief Make this button generate OnClick events when a specific mouse event occurs over the button.
374+ * \param mouse_event The mouse event for which to enable or disable OnClick events
375+ * \param enable 'true' to enable, 'false' to disable
376+ * \see enable_button_clicks()
377+ * \see disable_button_clicks()
378+ */
379+ void set_button_clicks_enabled (const std::string& mouse_event, bool enable) {
380+ if (enable) {
381+ enable_button_clicks (mouse_event);
382+ } else {
383+ disable_button_clicks (mouse_event);
384+ }
385+ }
386+
387+ /* *
388+ * \brief Make this button generate OnClick events when a specific mouse event occurs over the button.
389+ * \param button_id The mouse button for which to enable or disable OnClick events
390+ * \param button_event The mouse button event for which to enable or disable OnClick events
391+ * \param enable 'true' to enable, 'false' to disable
392+ * \see enable_button_clicks()
393+ * \see disable_button_clicks()
394+ */
395+ void set_button_clicks_enabled (
396+ input::mouse_button button_id, input::mouse_button_event button_event, bool enable) {
397+ if (enable) {
398+ enable_button_clicks (button_id, button_event);
399+ } else {
400+ disable_button_clicks (button_id, button_event);
401+ }
402+ }
403+
404+ /* *
405+ * \brief Make this button generate OnClick events when a specific mouse event occurs over the button.
406+ * \param mouse_event The mouse event for which to enable OnClick events
407+ * \note The mouse event string must be of the form "<button>Up" or "<button>Down". For
408+ * example, "LeftButtonUp".
409+ * \see disable_button_clicks()
410+ */
411+ void enable_button_clicks (const std::string& mouse_event);
412+
413+ /* *
414+ * \brief Make this button generate OnClick events when a specific mouse event occurs over the button.
415+ * \param button_id The mouse button for which to enable OnClick events
416+ * \param button_event The mouse button event for which to enable OnClick events
417+ * \note See @ref enable_button_clicks(const std::string&) for more information.
418+ * \see disable_button_clicks()
419+ */
420+ void
421+ enable_button_clicks (input::mouse_button button_id, input::mouse_button_event button_event);
422+
423+ /* *
424+ * \brief Stop this button from generating OnClick events when a specific mouse event occurs over the button.
425+ * \param mouse_event The mouse event for which to stop generating OnClick events
426+ * \see enable_button_clicks()
427+ */
428+ void disable_button_clicks (const std::string& mouse_event);
429+
430+ /* *
431+ * \brief Stop this button from generating OnClick events when a specific mouse event occurs over the button.
432+ * \param button_id The mouse button for which to stop generating OnClick events
433+ * \param button_event The state of the button for which to stop generating OnClick events
434+ * \note See @ref disable_button_clicks(const std::string&) for more information.
435+ * \see enable_button_clicks()
436+ */
437+ void
438+ disable_button_clicks (input::mouse_button button_id, input::mouse_button_event button_event);
439+
440+ /* *
441+ * \brief Stop this button from generating OnClick events.
442+ * \see enable_button_clicks()
443+ * \see is_button_clicks_enabled()
444+ */
445+ void disable_button_clicks ();
446+
447+ /* *
448+ * \brief Checks if this button can generate OnClick events when a specific mouse event occurs over the button.
449+ * \param mouse_event The mouse event to check
450+ * \return 'true' if this button can generate OnClick events from this mouse event
451+ * \see enable_button_clicks()
452+ */
453+ bool is_button_clicks_enabled (const std::string& mouse_event) const ;
454+
455+ /* *
456+ * \brief Checks if this button can generate OnClick events when a specific mouse event occurs over the button.
457+ * \param button_id The mouse button for which to check
458+ * \param button_event The mouse button event for which to check
459+ * \return 'true' if this button can generate OnClick events from this mouse event
460+ * \see enable_button_clicks()
461+ */
462+ bool is_button_clicks_enabled (
463+ input::mouse_button button_id, input::mouse_button_event button_event) const ;
464+
348465 // / Registers this region class to the provided Lua state
349466 static void register_on_lua (sol::state& lua);
350467
@@ -354,6 +471,11 @@ class button : public frame {
354471 void parse_attributes_ (const layout_node& node) override ;
355472 void parse_all_nodes_before_children_ (const layout_node& node) override ;
356473
474+ bool is_button_clicks_enabled_ (input::mouse_button button_id) const ;
475+
476+ virtual void click_ (
477+ input::mouse_button button_id, input::mouse_button_event button_event, float mx, float my);
478+
357479 const std::vector<std::string>& get_type_list_ () const override ;
358480
359481 state state_ = state::up;
@@ -373,6 +495,8 @@ class button : public frame {
373495 utils::observer_ptr<font_string> current_font_string_ = nullptr ;
374496
375497 vector2f pushed_text_offset_ = vector2f::zero;
498+
499+ std::set<std::string> reg_click_list_;
376500};
377501
378502} // namespace lxgui::gui
0 commit comments