@@ -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 */
@@ -345,6 +354,99 @@ class button : public frame {
345354 */
346355 const vector2f& get_pushed_text_offset () const ;
347356
357+ /* *
358+ * \brief Make this button generate OnClick events when a specific mouse event occurs over the button.
359+ * \param mouse_event The mouse event for which to enable or disable OnClick events
360+ * \param enable 'true' to enable, 'false' to disable
361+ * \see enable_button_clicks()
362+ * \see disable_button_clicks()
363+ */
364+ void set_button_clicks_enabled (const std::string& mouse_event, bool enable) {
365+ if (enable) {
366+ enable_button_clicks (mouse_event);
367+ } else {
368+ disable_button_clicks (mouse_event);
369+ }
370+ }
371+
372+ /* *
373+ * \brief Make this button generate OnClick events when a specific mouse event occurs over the button.
374+ * \param button_id The mouse button for which to enable or disable OnClick events
375+ * \param button_event The mouse button event for which to enable or disable OnClick events
376+ * \param enable 'true' to enable, 'false' to disable
377+ * \see enable_button_clicks()
378+ * \see disable_button_clicks()
379+ */
380+ void set_button_clicks_enabled (
381+ input::mouse_button button_id, input::mouse_button_event button_event, bool enable) {
382+ if (enable) {
383+ enable_button_clicks (button_id, button_event);
384+ } else {
385+ disable_button_clicks (button_id, button_event);
386+ }
387+ }
388+
389+ /* *
390+ * \brief Make this button generate OnClick events when a specific mouse event occurs over the button.
391+ * \param mouse_event The mouse event for which to enable OnClick events
392+ * \note The mouse event string must be of the form "<button>Up" or "<button>Down". For
393+ * example, "LeftButtonUp".
394+ * \see disable_button_clicks()
395+ */
396+ void enable_button_clicks (const std::string& mouse_event);
397+
398+ /* *
399+ * \brief Make this button generate OnClick events when a specific mouse event occurs over the button.
400+ * \param button_id The mouse button for which to enable OnClick events
401+ * \param button_event The mouse button event for which to enable OnClick events
402+ * \note See @ref enable_button_clicks(const std::string&) for more information.
403+ * \see disable_button_clicks()
404+ */
405+ void
406+ enable_button_clicks (input::mouse_button button_id, input::mouse_button_event button_event);
407+
408+ /* *
409+ * \brief Stop this button from generating OnClick events when a specific mouse event occurs over the button.
410+ * \param mouse_event The mouse event for which to stop generating OnClick events
411+ * \see enable_button_clicks()
412+ */
413+ void disable_button_clicks (const std::string& mouse_event);
414+
415+ /* *
416+ * \brief Stop this button from generating OnClick events when a specific mouse event occurs over the button.
417+ * \param button_id The mouse button for which to stop generating OnClick events
418+ * \param button_event The state of the button for which to stop generating OnClick events
419+ * \note See @ref disable_button_clicks(const std::string&) for more information.
420+ * \see enable_button_clicks()
421+ */
422+ void
423+ disable_button_clicks (input::mouse_button button_id, input::mouse_button_event button_event);
424+
425+ /* *
426+ * \brief Stop this button from generating OnClick events.
427+ * \see enable_button_clicks()
428+ * \see is_button_clicks_enabled()
429+ */
430+ void disable_button_clicks ();
431+
432+ /* *
433+ * \brief Checks if this button can generate OnClick events when a specific mouse event occurs over the button.
434+ * \param mouse_event The mouse event to check
435+ * \return 'true' if this button can generate OnClick events from this mouse event
436+ * \see enable_button_clicks()
437+ */
438+ bool is_button_clicks_enabled (const std::string& mouse_event) const ;
439+
440+ /* *
441+ * \brief Checks if this button can generate OnClick events when a specific mouse event occurs over the button.
442+ * \param button_id The mouse button for which to check
443+ * \param button_event The mouse button event for which to check
444+ * \return 'true' if this button can generate OnClick events from this mouse event
445+ * \see enable_button_clicks()
446+ */
447+ bool is_button_clicks_enabled (
448+ input::mouse_button button_id, input::mouse_button_event button_event) const ;
449+
348450 // / Registers this region class to the provided Lua state
349451 static void register_on_lua (sol::state& lua);
350452
@@ -373,6 +475,8 @@ class button : public frame {
373475 utils::observer_ptr<font_string> current_font_string_ = nullptr ;
374476
375477 vector2f pushed_text_offset_ = vector2f::zero;
478+
479+ std::set<std::string> reg_click_list_;
376480};
377481
378482} // namespace lxgui::gui
0 commit comments