diff --git a/gtk2_ardour/waves_grid.cc b/gtk2_ardour/waves_grid.cc new file mode 100644 index 0000000000..4d6f569da7 --- /dev/null +++ b/gtk2_ardour/waves_grid.cc @@ -0,0 +1,89 @@ +/* + Copyright (C) 2014 Waves Audio Ltd. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "waves_grid.h" + +WavesGrid::WavesGrid () +{ +} + +WavesGrid::~WavesGrid() +{ +} + +void +WavesGrid::on_size_allocate (Gtk::Allocation& alloc) +{ + Gtk::Fixed::on_size_allocate (alloc); + int this_x = alloc.get_x (); + int this_y = alloc.get_y (); + int this_width = alloc.get_width (); + int this_height = alloc.get_height (); + int x = 0; + int y = 0; + int next_y = 0; + + std::vector children = get_children (); + + for (std::vector::iterator it = children.begin (); it != children.end (); ++it ) { + Gtk::Widget& child = **it; + Gtk::Allocation child_alloc = child.get_allocation (); + + if ( next_y < (y + child_alloc.get_height ())) { + next_y = y + child_alloc.get_height (); + } + + if (this_width < (x + child_alloc.get_width ())) { + y = next_y; + x = 0; + } + + if ((x != (child_alloc.get_x () - this_x)) || (y != (child_alloc.get_y () - this_y))) { + move (child, x, y); + } + x += child_alloc.get_width (); + } +} + +void +WavesGrid::pack (Gtk::Widget& widget) +{ + std::vector children = get_children (); + int x = 0; + int y = 0; + int width; + int height; + widget.get_size_request (width, height); + + if (!children.empty()) { + Widget& last_child = *children.back (); + Gtk::Allocation child_alloc =last_child.get_allocation (); + int this_width; + int this_height; + get_size_request (this_width, this_height); + + y = child_alloc.get_y (); + if (this_width <= (child_alloc.get_x () + child_alloc.get_width () + width)) { + x = child_alloc.get_x () + child_alloc.get_width (); + } else { + y += height; + } + } + put (widget, x, y); +} diff --git a/gtk2_ardour/waves_grid.h b/gtk2_ardour/waves_grid.h new file mode 100644 index 0000000000..876a6da987 --- /dev/null +++ b/gtk2_ardour/waves_grid.h @@ -0,0 +1,35 @@ +/* + Copyright (C) 2014 Waves Audio Ltd. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef __gtk2_waves_grid_h__ +#define __gtk2_waves_grid_h__ + +#include + +class WavesGrid : public Gtk::Fixed +{ + public: + WavesGrid (); + virtual ~WavesGrid (); + void pack (Gtk::Widget& widget); + + protected: + void on_size_allocate (Gtk::Allocation&); +}; + +#endif /* __gtk2_waves_grid_h__ */ diff --git a/gtk2_ardour/waves_ui.cc b/gtk2_ardour/waves_ui.cc index 6dbca1c68e..6810ad7941 100644 --- a/gtk2_ardour/waves_ui.cc +++ b/gtk2_ardour/waves_ui.cc @@ -128,6 +128,8 @@ WavesUI::create_widget (const XMLNode& definition, const XMLNodeMap& styles) child = manage (new Gtk::ScrolledWindow); } else if (widget_type == "FIXED") { child = manage (new Gtk::Fixed); + } else if (widget_type == "WAVESGRID") { + child = manage (new WavesGrid); } else if (widget_type == "VBOX") { child = manage (new Gtk::VBox); } else if (widget_type == "HBOX") { @@ -261,6 +263,18 @@ WavesUI::add_widget (Gtk::Fixed& parent, const XMLNode& definition, const XMLNod return child; } +Gtk::Widget* +WavesUI::add_widget (WavesGrid& parent, const XMLNode& definition, const XMLNodeMap& styles) +{ + Gtk::Widget* child = create_widget(definition, styles); + + if (child != NULL) + { + parent.pack (*child); + } + return child; +} + Gtk::Widget* WavesUI::add_widget (Gtk::Paned& parent, const XMLNode& definition, const XMLNodeMap& styles) { @@ -766,6 +780,16 @@ WavesUI::get_fixed (const char* id) return *child; } +WavesGrid& +WavesUI::get_waves_grid (const char* id) +{ + WavesGrid* child = dynamic_cast (get_object(id)); + if (child == NULL ) { + dbg_msg (std::string("WavesGrid ") + id + " not found in " + _scrip_file_name + "!"); + abort (); + } + return *child; +} Gtk::Paned& WavesUI::get_paned (const char* id) diff --git a/gtk2_ardour/waves_ui.h b/gtk2_ardour/waves_ui.h index 248c59723c..58c5e94fb8 100644 --- a/gtk2_ardour/waves_ui.h +++ b/gtk2_ardour/waves_ui.h @@ -33,6 +33,7 @@ #include "gtkmm2ext/focus_entry.h" #include "canvas/canvas.h" #include "canvas/xml_ui.h" +#include "waves_grid.h" #include "waves_button.h" #include "waves_icon_button.h" @@ -51,6 +52,7 @@ class WavesUI : public std::map { Gtk::VBox& get_v_box (const char* id); Gtk::HBox& get_h_box (const char* id); Gtk::Fixed& get_fixed (const char* id); + WavesGrid& get_waves_grid (const char* id); Gtk::Paned& get_paned (const char* id); Gtk::HPaned& get_h_paned (const char* id); Gtk::VPaned& get_v_paned (const char* id); @@ -84,6 +86,7 @@ class WavesUI : public std::map { Gtk::Widget* create_widget (const XMLNode& definition, const XMLNodeMap& styles); Gtk::Widget* add_widget (Gtk::Box& parent, const XMLNode& definition, const XMLNodeMap& styles); Gtk::Widget* add_widget (Gtk::Fixed& parent, const XMLNode& definition, const XMLNodeMap& styles); + Gtk::Widget* add_widget (WavesGrid& parent, const XMLNode& definition, const XMLNodeMap& styles); Gtk::Widget* add_widget (Gtk::Paned& parent, const XMLNode& definition, const XMLNodeMap& styles); Gtk::Widget* add_widget (Gtk::Table& parent, const XMLNode& definition, const XMLNodeMap& styles); Gtk::Widget* add_widget (Gtk::ScrolledWindow& parent, const XMLNode& definition, const XMLNodeMap& styles); diff --git a/gtk2_ardour/wscript b/gtk2_ardour/wscript index b11b4585a7..a3800b4c87 100644 --- a/gtk2_ardour/wscript +++ b/gtk2_ardour/wscript @@ -29,6 +29,7 @@ path_prefix = 'gtk2_ardour/' gtk2_ardour_sources = [ 'mixer_bridge_view.cc', 'waves_ui.cc', + 'waves_grid.cc', 'about.cc', 'actions.cc', 'add_route_dialog.cc',