summaryrefslogtreecommitdiff
path: root/plugingui
diff options
context:
space:
mode:
Diffstat (limited to 'plugingui')
-rw-r--r--plugingui/drumkittab.cc6
-rw-r--r--plugingui/drumkittab.h5
-rw-r--r--plugingui/image.cc10
-rw-r--r--plugingui/image.h3
-rw-r--r--plugingui/mainwindow.cc16
-rw-r--r--plugingui/mainwindow.h3
-rw-r--r--plugingui/tabbutton.cc13
-rw-r--r--plugingui/tabbutton.h6
-rw-r--r--plugingui/tabwidget.cc32
-rw-r--r--plugingui/tabwidget.h6
10 files changed, 90 insertions, 10 deletions
diff --git a/plugingui/drumkittab.cc b/plugingui/drumkittab.cc
index d6475fa..c3ee62e 100644
--- a/plugingui/drumkittab.cc
+++ b/plugingui/drumkittab.cc
@@ -42,12 +42,10 @@ namespace GUI
DrumkitTab::DrumkitTab(Widget* parent,
Settings& settings,
- SettingsNotifier& settings_notifier/*,
- Config& config*/)
+ SettingsNotifier& settings_notifier)
: Widget(parent)
, settings(settings)
, settings_notifier(settings_notifier)
- /*, config(config)*/
{
velocity_label.move(10, height()-velocity_label.height()-5);
updateVelocityLabel();
@@ -293,6 +291,8 @@ void DrumkitTab::init(std::string const& image_file,
}
}
}
+
+ imageChangeNotifier(drumkit_image->isValid());
}
void DrumkitTab::drumkitFileChanged(const std::string& drumkit_file)
diff --git a/plugingui/drumkittab.h b/plugingui/drumkittab.h
index b1ccb73..a14a9c5 100644
--- a/plugingui/drumkittab.h
+++ b/plugingui/drumkittab.h
@@ -50,8 +50,7 @@ class DrumkitTab
public:
DrumkitTab(Widget* parent,
Settings& settings,
- SettingsNotifier& settings_notifier/*,
- Config& config*/);
+ SettingsNotifier& settings_notifier);
// From Widget:
void resize(std::size_t width, std::size_t height) override;
@@ -62,6 +61,8 @@ public:
void init(std::string const& image_file, std::string const& map_file);
+ Notifier<bool> imageChangeNotifier; // bool has_valid_image
+
private:
float current_velocity{.5};
std::string current_instrument{""};
diff --git a/plugingui/image.cc b/plugingui/image.cc
index 4b5622e..70ee08e 100644
--- a/plugingui/image.cc
+++ b/plugingui/image.cc
@@ -76,15 +76,17 @@ Image& Image::operator=(Image&& other)
image_data = std::move(other.image_data);
_width = other._width;
_height = other._height;
+ valid = other.valid;
other._width = 0;
other._height = 0;
-
+ other.valid = false;
return *this;
}
void Image::setError()
{
+ valid = false;
Resource rc(":resources/png_error");
const unsigned char* ptr = (const unsigned char*)rc.data();
@@ -155,6 +157,7 @@ void Image::load(const char* data, size_t size)
assert(image_data.size() == (_width * _height));
std::free(char_image_data);
+ valid = true;
}
size_t Image::width() const
@@ -177,4 +180,9 @@ const Colour& Image::getPixel(size_t x, size_t y) const
return image_data[x + y * _width];
}
+bool Image::isValid() const
+{
+ return valid;
+}
+
} // GUI::
diff --git a/plugingui/image.h b/plugingui/image.h
index e70215e..dd7f347 100644
--- a/plugingui/image.h
+++ b/plugingui/image.h
@@ -51,8 +51,11 @@ public:
const Colour& getPixel(size_t x, size_t y) const override;
+ bool isValid() const;
+
private:
void setError();
+ bool valid{false};
void load(const char* data, size_t size);
diff --git a/plugingui/mainwindow.cc b/plugingui/mainwindow.cc
index a0364fa..a625bc3 100644
--- a/plugingui/mainwindow.cc
+++ b/plugingui/mainwindow.cc
@@ -51,8 +51,12 @@ MainWindow::MainWindow(Settings& settings, void* native_window)
tabs.setTabWidth(100);
tabs.move(16, 0); // x-offset to make room for the left side bar.
tabs.addTab("Main", &main_tab);
- tabs.addTab("Drumkit", &drumkit_tab);
+ drumkit_tab_id = tabs.addTab("Drumkit", &drumkit_tab);
+ changeDrumkitTabVisibility(false); // Hide while no kit is loaded
tabs.addTab("About", &about_tab);
+
+ CONNECT(&drumkit_tab, imageChangeNotifier,
+ this, &MainWindow::changeDrumkitTabVisibility);
}
MainWindow::~MainWindow()
@@ -105,6 +109,16 @@ void MainWindow::sizeChanged(std::size_t width, std::size_t height)
tabs.resize(std::max((int)width - 2 * 16, 0), height);
}
+void MainWindow::changeDrumkitTabVisibility(bool visible)
+{
+ // TODO: Check if the currently active tab is the drumkit tab and switch to
+ // the main tab if it is.
+
+ // TODO: Add disabled state to the TabButtons and make it disabled instead of
+ // hidden here.
+ tabs.setVisible(drumkit_tab_id, visible);
+}
+
void MainWindow::closeEventHandler()
{
closing = true;
diff --git a/plugingui/mainwindow.h b/plugingui/mainwindow.h
index ea05ad6..ffd0566 100644
--- a/plugingui/mainwindow.h
+++ b/plugingui/mainwindow.h
@@ -57,6 +57,7 @@ public:
private:
void sizeChanged(std::size_t width, std::size_t height);
+ void changeDrumkitTabVisibility(bool visible);
// From Widget
void repaintEvent(RepaintEvent* repaintEvent) override final;
@@ -82,6 +83,8 @@ private:
17, 1, 1}; // dy1, dy2, dy3
bool closing{false};
+
+ TabID drumkit_tab_id;
};
} // GUI::
diff --git a/plugingui/tabbutton.cc b/plugingui/tabbutton.cc
index 845dedb..6a27f61 100644
--- a/plugingui/tabbutton.cc
+++ b/plugingui/tabbutton.cc
@@ -31,10 +31,18 @@
namespace GUI
{
+static TabID getNextTabID()
+{
+ static TabID next{0};
+ next++;
+ return next;
+}
+
TabButton::TabButton(Widget* parent, Widget* tab_widget)
: ButtonBase(parent)
, tab_widget(tab_widget)
{
+ tab_id = getNextTabID();
CONNECT(this, clickNotifier, this, &TabButton::clickHandler);
}
@@ -77,6 +85,11 @@ void TabButton::setActive(bool active)
redraw();
}
+TabID TabButton::getID() const
+{
+ return tab_id;
+}
+
void TabButton::repaintEvent(RepaintEvent* e)
{
Painter p(*this);
diff --git a/plugingui/tabbutton.h b/plugingui/tabbutton.h
index 29e6e05..1e9371a 100644
--- a/plugingui/tabbutton.h
+++ b/plugingui/tabbutton.h
@@ -37,6 +37,8 @@ namespace GUI
class ScrollEvent;
+using TabID = int;
+
class TabButton
: public ButtonBase
{
@@ -49,6 +51,8 @@ public:
std::size_t getMinimalHeight() const;
void setActive(bool active);
+ TabID getID() const;
+
Notifier<Widget*> switchTabNotifier;
Notifier<float> scrollNotifier; // float delta
@@ -58,6 +62,8 @@ protected:
virtual void scrollEvent(ScrollEvent* scroll_event) override;
private:
+ TabID tab_id;
+
void clickHandler();
Widget* tab_widget;
diff --git a/plugingui/tabwidget.cc b/plugingui/tabwidget.cc
index 7ba39c9..17a540e 100644
--- a/plugingui/tabwidget.cc
+++ b/plugingui/tabwidget.cc
@@ -39,7 +39,7 @@ TabWidget::TabWidget(Widget *parent)
CONNECT(&stack, currentChanged, this, &TabWidget::setActiveButtons);
}
-void TabWidget::addTab(const std::string& title, Widget* widget)
+TabID TabWidget::addTab(const std::string& title, Widget* widget)
{
buttons.emplace_back(this, widget);
auto& button = buttons.back();
@@ -48,11 +48,13 @@ void TabWidget::addTab(const std::string& title, Widget* widget)
CONNECT(&button, switchTabNotifier, this, &TabWidget::switchTab);
CONNECT(&button, scrollNotifier, this, &TabWidget::rotateTab);
sizeChanged(width(), height());
+ return button.getID();
}
void TabWidget::setTabWidth(std::size_t width)
{
tab_width = width;
+ relayout();
}
std::size_t TabWidget::getTabWidth() const
@@ -60,6 +62,19 @@ std::size_t TabWidget::getTabWidth() const
return tab_width;
}
+void TabWidget::setVisible(TabID tab_id, bool visible)
+{
+ for (auto& button : buttons)
+ {
+ if(button.getID() == tab_id)
+ {
+ button.setVisible(visible);
+ relayout();
+ return;
+ }
+ }
+}
+
std::size_t TabWidget::getBarHeight() const
{
return topbar.height();
@@ -116,8 +131,12 @@ void TabWidget::sizeChanged(int width, int height)
if(buttons.size() > 0)
{
- for (auto& button : buttons)
+ for(auto& button : buttons)
{
+ if(!button.visible())
+ {
+ continue;
+ }
int min_width = button.getMinimalWidth();
button_width = std::max(button_width, min_width + button_border_width);
}
@@ -136,6 +155,10 @@ void TabWidget::sizeChanged(int width, int height)
pos = button_padding_left;
for(auto& button : buttons)
{
+ if(!button.visible())
+ {
+ continue;
+ }
button.resize(button_width, bar_height);
button.move(pos, 0);
pos += button_width + button_padding_inner;
@@ -145,4 +168,9 @@ void TabWidget::sizeChanged(int width, int height)
stack.resize(width, std::max((int)height - bar_height, 0));
}
+void TabWidget::relayout()
+{
+ sizeChanged(TabWidget::width(), TabWidget::height()); // Force re-layout
+}
+
} // GUI::
diff --git a/plugingui/tabwidget.h b/plugingui/tabwidget.h
index ff239a8..dc69776 100644
--- a/plugingui/tabwidget.h
+++ b/plugingui/tabwidget.h
@@ -43,18 +43,22 @@ public:
//! Add new tab to the tab widget.
//! \param title The title to display on the tab button.
//! \param widget The widget to show in the tab.
- void addTab(const std::string& title, Widget* widget);
+ //! \returns The TabID of the newly added tab.
+ TabID addTab(const std::string& title, Widget* widget);
std::size_t getBarHeight() const;
void setTabWidth(std::size_t width);
std::size_t getTabWidth() const;
+ void setVisible(TabID tab_id, bool visible);
+
private:
//! Callback for Widget::sizeChangeNotifier
void sizeChanged(int width, int height);
private:
+ void relayout();
//! Switch to the next tab if delta is > 0 or previous tab if delta is <= 0.
void rotateTab(float delta);
void switchTab(Widget* tabWidget);