diff options
| author | Matthias Melcher <github@matthiasm.com> | 2025-11-29 21:01:48 +0100 |
|---|---|---|
| committer | Matthias Melcher <github@matthiasm.com> | 2025-11-29 21:01:53 +0100 |
| commit | 70527b3bf0289add9cb4c3f8456368f946a5e386 (patch) | |
| tree | 979a5cc55fc890170d09d8d6d408267ff72a998f | |
| parent | 6aa95584e092fc5ab554e408b061a30d4b3811e3 (diff) | |
Improve access to C++ symbols.
For events, fonts, and callback reasons
| -rw-r--r-- | FL/names.h | 41 | ||||
| -rw-r--r-- | test/penpal.cxx | 1 |
2 files changed, 42 insertions, 0 deletions
diff --git a/FL/names.h b/FL/names.h index 3587b3d8d..1d4c42a4c 100644 --- a/FL/names.h +++ b/FL/names.h @@ -92,6 +92,20 @@ std::map<int, const char*> fl_eventnames = { { Fl::Pen::BUTTON_RELEASE, "Fl::Pen::BUTTON_RELEASE" } }; +/** + Return the C++ symbol of an Fl_Event as a string. + \param[in] event index as an integer + \return C++ symbol of event index as a string + */ +inline std::string fl_eventname_str(int event) { + auto it = fl_eventnames.find(event); + if (it == fl_eventnames.end()) { + return "FL_EVENT_" + std::to_string(event); + } else { + return it->second; + } +} + /** This is an array of font names you can use to convert font numbers into names. @@ -131,6 +145,20 @@ const char * const fl_fontnames[] = }; /** + Return the C++ symbol of an Fl_Font as a string. + \param[in] font index as an integer + \return C++ symbol of font index as a string +*/ +inline std::string fl_fontname_str(int font) { + if ((font < 0) || (font >= FL_ZAPF_DINGBATS)) { + return "FL_FONT_" + std::to_string(font); + } else { + return fl_fontnames[font]; + } +} + + +/** This is an array of callback reason names you can use to convert callback reasons into names. The array gets defined inline wherever your '\#include <FL/names.h>' appears. @@ -156,6 +184,19 @@ const char * const fl_callback_reason_names[] = "FL_REASON_USER", "FL_REASON_USER+1", "FL_REASON_USER+2", "FL_REASON_USER+3", }; +/** + Return the C++ symbol of an Fl_Callback_Reason as a string. + \param[in] reason as an integer + \return C++ symbol of reason as a string +*/ +inline std::string fl_callback_reason_str(int reason) { + if ((reason < 0) || (reason >= FL_REASON_USER+3) || (fl_callback_reason_names[reason] == nullptr)) { + return "FL_REASON_" + std::to_string(reason); + } else { + return fl_callback_reason_names[reason]; + } +} + /** @} */ #endif /* FL_NAMES_H */ diff --git a/test/penpal.cxx b/test/penpal.cxx index 69d6e280d..9b5ddde16 100644 --- a/test/penpal.cxx +++ b/test/penpal.cxx @@ -219,6 +219,7 @@ public: : Fl_Widget(x, y, w, h, l), CanvasInterface(this) { } ~CanvasWidget() override { } int handle(int event) override { + // puts(fl_eventname_str(event).c_str()); auto ret = cv_handle(event); return ret ? ret : Fl_Widget::handle(event); } |
