From 2c7b9131fe69467ae8fedf64f7ed3dee10676a12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Garramu=C3=B1o?= Date: Mon, 25 Mar 2024 05:36:12 -0300 Subject: [PATCH] Added AudioButton. --- mrv2/lib/mrvWidgets/mrvAudioButton.cpp | 90 ++++++++++++++++++++++++++ mrv2/lib/mrvWidgets/mrvAudioButton.h | 34 ++++++++++ 2 files changed, 124 insertions(+) create mode 100644 mrv2/lib/mrvWidgets/mrvAudioButton.cpp create mode 100644 mrv2/lib/mrvWidgets/mrvAudioButton.h diff --git a/mrv2/lib/mrvWidgets/mrvAudioButton.cpp b/mrv2/lib/mrvWidgets/mrvAudioButton.cpp new file mode 100644 index 000000000..7ee8b74bb --- /dev/null +++ b/mrv2/lib/mrvWidgets/mrvAudioButton.cpp @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: BSD-3-Clause +// mrv2 +// Copyright Contributors to the mrv2 Project. All rights reserved. + + +#include + +#include "mrvCore/mrvI8N.h" + +#include "mrvWidgets/mrvAudioButton.h" + +#include "mrvFl/mrvCallbacks.h" + +#include "mrvApp/mrvApp.h" + +namespace mrv +{ + + static void change_audio_track_cb(Fl_Menu_Button* o, void* d) + { + auto audioButton = static_cast(d); + int idx = o->value(); + + audioButton->current_track(idx); + + clone_and_replace_cb(o, d); + } + + AudioButton::AudioButton(int X, int Y, int W, int H, const char* l) : + Fl_Button(X, Y, W, H, l) + { + } + + int AudioButton::current_track() const + { + return currentTrack; + } + + void AudioButton::current_track(int idx) + { + currentTrack = idx; + } + + int AudioButton::handle(int e) + { + switch (e) + { + case FL_PUSH: + if (Fl::event_button3() && audioTracks.size() > 1) + { + Fl_Menu_Button menu(0, 0, 0, 0); + menu.type(Fl_Menu_Button::POPUP3); + menu.clear(); + + for (const auto& track : audioTracks) + { + menu.add( + track.c_str(), 0, (Fl_Callback*)change_audio_track_cb, + this); + } + menu.menu_end(); + + menu.popup(); + return 1; + } + break; + } + return Fl_Button::handle(e); + } + + void AudioButton::clear_tracks() + { + currentTrack = -1; + audioTracks.clear(); + } + + void AudioButton::add_track(const std::string& name) + { + audioTracks.push_back(name); + } + + void AudioButton::add_track() + { + char buf[256]; + unsigned idx = audioTracks.size() + 1; + snprintf(buf, 256, _("Track #%d"), idx); + add_track(buf); + } + +} // namespace mrv diff --git a/mrv2/lib/mrvWidgets/mrvAudioButton.h b/mrv2/lib/mrvWidgets/mrvAudioButton.h new file mode 100644 index 000000000..e7eead9b2 --- /dev/null +++ b/mrv2/lib/mrvWidgets/mrvAudioButton.h @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: BSD-3-Clause +// mrv2 +// Copyright Contributors to the mrv2 Project. All rights reserved. + +#pragma once + +#include +#include + +#include + +namespace mrv +{ + + class AudioButton : public Fl_Button + { + public: + AudioButton(int, int, int, int, const char* = 0); + virtual ~AudioButton(){}; + virtual int handle(int e) override; + + int current_track() const; + void current_track(int idx); + + void clear_tracks(); + void add_track(const std::string& name); + void add_track(); + + protected: + int currentTrack = -1; + std::vector audioTracks; + }; + +} // namespace mrv