diff --git a/gtk2_ardour/fitted_canvas_widget.cc b/gtk2_ardour/fitted_canvas_widget.cc new file mode 100644 index 0000000000..ac3865a82b --- /dev/null +++ b/gtk2_ardour/fitted_canvas_widget.cc @@ -0,0 +1,85 @@ +/* + Copyright (C) 2019 Paul Davis + Author: Ben Loftis + + 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 +#include + +#include + +#include "pbd/compose.h" + +#include "gtkmm2ext/keyboard.h" +#include "gtkmm2ext/utils.h" + +#include "canvas/canvas.h" +#include "canvas/debug.h" +#include "canvas/utils.h" + +#include "actions.h" +#include "gui_thread.h" +#include "utils.h" +#include "timers.h" + +#include "fitted_canvas_widget.h" + +using namespace std; +using namespace ArdourCanvas; +using namespace Gtk; +using namespace Gtkmm2ext; +using namespace ARDOUR_UI_UTILS; + + +//a gtk widget with fixed-size semantics +FittedCanvasWidget::FittedCanvasWidget (float w, float h, bool follow_scale) +{ + _nominal_width = w; + _nominal_height = h; + _follow_scale = follow_scale; + + //our rendering speed suffers if we re-render knobs simply because they are in-between 2 meters that got invalidated (for example) +// set_single_exposure(false); +//#ifdef __APPLE__ +// use_intermediate_surface (false); +//#endif +} + +void +FittedCanvasWidget::on_size_request (Gtk::Requisition* req) +{ + const double scale = _follow_scale ? UIConfiguration::instance().get_ui_scale() : 1; + if (_nominal_width>0) { + req->width = _nominal_width*scale; + } + if (_nominal_height>0) { + req->height = _nominal_height*scale; + } +} + + +void +FittedCanvasWidget::on_size_allocate (Gtk::Allocation& alloc) +{ + GtkCanvas::on_size_allocate(alloc); + + if (!_root.items().empty()) { + ArdourCanvas::Item *fitted = *_root.items().begin(); + fitted->size_allocate(ArdourCanvas::Rect(0,0,alloc.get_width(), alloc.get_height())); + } +} + diff --git a/gtk2_ardour/fitted_canvas_widget.h b/gtk2_ardour/fitted_canvas_widget.h new file mode 100644 index 0000000000..6ab36b2da4 --- /dev/null +++ b/gtk2_ardour/fitted_canvas_widget.h @@ -0,0 +1,67 @@ +/* + Copyright (C) 2021 Paul Davis + Author: Ben Loftis + + 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 __fitted_canvas_widget__ +#define __fitted_canvas_widget__ + +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include "route_ui.h" + +/* FittedCanvasWidget has these properties: + * it is provided a 'nominal size' on construction, which it will request of gtk + * if asked, will resize itself when the user gui/font scale changes + * it 'fits' the Item that was first attached to Root (presumably the top-level widget or container) + * the fitted Item will be explicitly resized to fit when the canvas size is allocated + * the fitted Item may be a container; it should allocate child positions during size_allocate() + * */ + +class FittedCanvasWidget : public ArdourCanvas::GtkCanvas +{ +public: + /* per gtk convention you may use -1 for width OR height if you don't care about that dimension */ + FittedCanvasWidget(float nominal_width, float nominal_height, bool follow_scale=true); + + void on_size_request (Gtk::Requisition* req); //always returns the nominal size, regardless of children + void on_size_allocate (Gtk::Allocation& alloc); + +private: + float _nominal_width; + float _nominal_height; + bool _follow_scale; +}; + +#endif //__fitted_canvas_widget__ diff --git a/gtk2_ardour/wscript b/gtk2_ardour/wscript index df8e868628..a1058809d6 100644 --- a/gtk2_ardour/wscript +++ b/gtk2_ardour/wscript @@ -120,6 +120,7 @@ gtk2_ardour_sources = [ 'export_preset_selector.cc', 'export_report.cc', 'export_timespan_selector.cc', + 'fitted_canvas_widget.cc', 'fft.cc', 'fft_graph.cc', 'fft_result.cc',