[Summary] Adding WavesGrid class (UI).

This commit is contained in:
VKamyshniy 2014-08-06 14:08:44 +03:00
parent fedb86cc8b
commit 32423b16c9
5 changed files with 152 additions and 0 deletions

89
gtk2_ardour/waves_grid.cc Normal file
View file

@ -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<Gtk::Widget*> children = get_children ();
for (std::vector<Gtk::Widget*>::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<Gtk::Widget*> 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);
}

35
gtk2_ardour/waves_grid.h Normal file
View file

@ -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 <gtkmm/fixed.h>
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__ */

View file

@ -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<WavesGrid*> (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)

View file

@ -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<std::string, Gtk::Object*> {
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<std::string, Gtk::Object*> {
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);

View file

@ -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',