Skip to content

Commit

Permalink
Show 'Add track' menu when right-cliking on empty area on main Keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
gvnnz committed Oct 11, 2024
1 parent 544b9f5 commit 3e00492
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 9 deletions.
48 changes: 43 additions & 5 deletions src/gui/elems/mainWindow/keyboard/keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "gui/drawing.h"
#include "gui/elems/basics/boxtypes.h"
#include "gui/elems/basics/dial.h"
#include "gui/elems/basics/menu.h"
#include "gui/elems/basics/resizerBar.h"
#include "gui/elems/basics/textButton.h"
#include "gui/elems/mainWindow/keyboard/channelButton.h"
Expand All @@ -51,6 +52,18 @@ extern giada::v::Ui* g_ui;

namespace giada::v
{
namespace
{
enum class Menu
{
ADD_TRACK = 0
};
} // namespace

/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

geKeyboard::ChannelDragger::ChannelDragger(geKeyboard& k)
: m_keyboard(k)
, m_channelId(-1)
Expand Down Expand Up @@ -187,6 +200,27 @@ size_t geKeyboard::countTracks() const

/* -------------------------------------------------------------------------- */

void geKeyboard::showMenu() const
{
geMenu menu;

menu.addItem((ID)Menu::ADD_TRACK, g_ui->getI18Text(LangMap::MAIN_TRACK_BUTTON_ADD_TRACK));

menu.onSelect = [this](ID menuId)
{
switch (static_cast<Menu>(menuId))
{
case Menu::ADD_TRACK:
addTrack();
break;
}
};

menu.popup();
}

/* -------------------------------------------------------------------------- */

void geKeyboard::init()
{
deleteAllTracks();
Expand Down Expand Up @@ -260,7 +294,7 @@ int geKeyboard::handle(int e)
}
if (Fl::event_button3())
{
openTrackMenu();
openMenu();
return 1;
}

Expand Down Expand Up @@ -355,7 +389,7 @@ geompp::Rect<int> geKeyboard::getTrackBackround(const geTrack& c) const

/* -------------------------------------------------------------------------- */

void geKeyboard::addTrack()
void geKeyboard::addTrack() const
{
c::channel::addTrack();
}
Expand Down Expand Up @@ -455,11 +489,15 @@ std::vector<std::string> geKeyboard::getDroppedFilePaths() const

/* -------------------------------------------------------------------------- */

void geKeyboard::openTrackMenu() const
void geKeyboard::openMenu() const
{
const geTrack* track = getTrackAtCursor(Fl::event_x());
if (track == nullptr || track->getChannelAtCursor(Fl::event_y()) != nullptr)
if (track == nullptr) // No track hovered: show Keyboard menu
{
showMenu();
return;
track->showMenu();
}
if (track->getChannelAtCursor(Fl::event_y()) == nullptr) // No channel hovered: show track menu
track->showMenu();
}
} // namespace giada::v
14 changes: 10 additions & 4 deletions src/gui/elems/mainWindow/keyboard/keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ class geKeyboard : public geScroll

size_t countTracks() const;

/* showMenu
Displays the menu for adding/removing tracks. */

void showMenu() const;

/* rebuild
Rebuilds this widget from scratch. Used when the model has changed. */

Expand All @@ -79,7 +84,7 @@ class geKeyboard : public geScroll
/* addTrack
Adds new track at the end of the stack. */

void addTrack();
void addTrack() const;

/* deleteTrack
Deletes track by index. */
Expand Down Expand Up @@ -141,10 +146,11 @@ class geKeyboard : public geScroll

std::vector<std::string> getDroppedFilePaths() const;

/* openTrackMenu
Opens the 'add/remove channel' menu for the track under the cursor. */
/* openMenu
Opens the Track menu for the track under the cursor, or the generic one if
no tracks hovered. */

void openTrackMenu() const;
void openMenu() const;

/* getTrackAtCursor
Returns the track below the cursor. */
Expand Down

0 comments on commit 3e00492

Please sign in to comment.