-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
// mrv2 | ||
// Copyright Contributors to the mrv2 Project. All rights reserved. | ||
|
||
|
||
#include <FL/Fl_Menu_Button.H> | ||
|
||
#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<AudioButton*>(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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
// mrv2 | ||
// Copyright Contributors to the mrv2 Project. All rights reserved. | ||
|
||
#pragma once | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include <FL/Fl_Button.H> | ||
|
||
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<std::string> audioTracks; | ||
}; | ||
|
||
} // namespace mrv |