From 70ad205bc168686625d9baeda94fd1676b5838ba Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 26 Jan 2021 23:01:05 +0100 Subject: [PATCH] Separate static widget theme into abstract class This allow the style to be used in classed that are not directly derived from Ardour's CairoWidget, notably container widgets or plugin UIs. --- libs/gtkmm2ext/cairo_widget.cc | 23 ---------- libs/gtkmm2ext/gtkmm2ext/cairo_theme.h | 57 +++++++++++++++++++++++++ libs/gtkmm2ext/gtkmm2ext/cairo_widget.h | 16 ++----- libs/gtkmm2ext/wscript | 1 + libs/widgets/ardour_button.cc | 6 +-- libs/widgets/ardour_knob.cc | 2 +- 6 files changed, 65 insertions(+), 40 deletions(-) create mode 100644 libs/gtkmm2ext/gtkmm2ext/cairo_theme.h diff --git a/libs/gtkmm2ext/cairo_widget.cc b/libs/gtkmm2ext/cairo_widget.cc index c79bf8acfe..7454149d5a 100644 --- a/libs/gtkmm2ext/cairo_widget.cc +++ b/libs/gtkmm2ext/cairo_widget.cc @@ -31,10 +31,6 @@ static const char* has_cairo_widget_background_info = "has_cairo_widget_background_info"; -bool CairoWidget::_flat_buttons = false; -bool CairoWidget::_boxy_buttons = false; -bool CairoWidget::_widget_prelight = true; - sigc::slot CairoWidget::focus_handler; void CairoWidget::set_source_rgb_a( cairo_t* cr, Gdk::Color col, float a) //ToDo: this one and the Canvas version should be in a shared file (?) @@ -438,25 +434,6 @@ CairoWidget::provide_background_for_cairo_widget (Gtk::Widget& w, const Gdk::Col g_object_set_data (G_OBJECT(w.gobj()), has_cairo_widget_background_info, (void*) 0xfeedface); } -void -CairoWidget::set_flat_buttons (bool yn) -{ - _flat_buttons = yn; -} - -void -CairoWidget::set_boxy_buttons (bool yn) -{ - _boxy_buttons = yn; -} - - -void -CairoWidget::set_widget_prelight (bool yn) -{ - _widget_prelight = yn; -} - void CairoWidget::set_focus_handler (sigc::slot s) { diff --git a/libs/gtkmm2ext/gtkmm2ext/cairo_theme.h b/libs/gtkmm2ext/gtkmm2ext/cairo_theme.h new file mode 100644 index 0000000000..6e8af0d174 --- /dev/null +++ b/libs/gtkmm2ext/gtkmm2ext/cairo_theme.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2011-2016 Paul Davis + * Copyright (C) 2021 Robin Gareus + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef _libgtkmm2ext_cairo_theme_h_ +#define _libgtkmm2ext_cairo_theme_h_ + +#include "gtkmm2ext/visibility.h" + +namespace Gtkmm2ext +{ + +class LIBGTKMM2EXT_API CairoTheme +{ +public: + static void set_flat_buttons (bool yn); + static void set_boxy_buttons (bool yn); + static void set_widget_prelight (bool yn); + + static bool flat_buttons () + { + return _flat_buttons; + } + + static bool boxy_buttons () + { + return _boxy_buttons; + } + + static bool widget_prelight () + { + return _widget_prelight; + } + +private: + static bool _flat_buttons; + static bool _boxy_buttons; + static bool _widget_prelight; +}; + +} // namespace Gtkmm2ext +#endif diff --git a/libs/gtkmm2ext/gtkmm2ext/cairo_widget.h b/libs/gtkmm2ext/gtkmm2ext/cairo_widget.h index 73db99a0d4..9af68d00e4 100644 --- a/libs/gtkmm2ext/gtkmm2ext/cairo_widget.h +++ b/libs/gtkmm2ext/gtkmm2ext/cairo_widget.h @@ -27,12 +27,13 @@ #include "gtkmm2ext/visibility.h" #include "gtkmm2ext/cairo_canvas.h" +#include "gtkmm2ext/cairo_theme.h" #include "gtkmm2ext/widget_state.h" /** A parent class for widgets that are rendered using Cairo. */ -class LIBGTKMM2EXT_API CairoWidget : public Gtk::EventBox, public Gtkmm2ext::CairoCanvas +class LIBGTKMM2EXT_API CairoWidget : public Gtk::EventBox, public Gtkmm2ext::CairoCanvas, public Gtkmm2ext::CairoTheme { public: CairoWidget (); @@ -86,13 +87,6 @@ public: uint32_t background_color (); - static void set_flat_buttons (bool yn); - static void set_boxy_buttons (bool yn); - static bool flat_buttons() { return _flat_buttons; } - static bool boxy_buttons() { return _boxy_buttons; } - - static void set_widget_prelight (bool yn); - static bool widget_prelight() { return _widget_prelight; } static void set_source_rgb_a( cairo_t* cr, Gdk::Color, float a=1.0 ); @@ -134,11 +128,7 @@ protected: Gtkmm2ext::ActiveState _active_state; Gtkmm2ext::VisualState _visual_state; bool _need_bg; - - static bool _flat_buttons; - static bool _boxy_buttons; - static bool _widget_prelight; - bool _grabbed; + bool _grabbed; static sigc::slot focus_handler; diff --git a/libs/gtkmm2ext/wscript b/libs/gtkmm2ext/wscript index b6dbaa63ec..90bf1c8880 100644 --- a/libs/gtkmm2ext/wscript +++ b/libs/gtkmm2ext/wscript @@ -28,6 +28,7 @@ gtkmm2ext_sources = [ 'application.cc', 'bindings.cc', 'cairo_packer.cc', + 'cairo_theme.cc', 'cairo_widget.cc', 'cell_renderer_color_selector.cc', 'cell_renderer_pixbuf_multi.cc', diff --git a/libs/widgets/ardour_button.cc b/libs/widgets/ardour_button.cc index 73efb155de..56e120cd3a 100644 --- a/libs/widgets/ardour_button.cc +++ b/libs/widgets/ardour_button.cc @@ -262,7 +262,7 @@ ArdourButton::render (Cairo::RefPtr const& ctx, cairo_rectangle_ uint32_t text_color; uint32_t led_color; - const float corner_radius = _boxy_buttons ? 0 : std::max(2.f, _corner_radius * UIConfigurationBase::instance().get_ui_scale()); + const float corner_radius = boxy_buttons () ? 0 : std::max(2.f, _corner_radius * UIConfigurationBase::instance().get_ui_scale()); if (_update_colors) { set_colors (); @@ -337,7 +337,7 @@ ArdourButton::render (Cairo::RefPtr const& ctx, cairo_rectangle_ } //show the "convex" or "concave" gradient - if (!_flat_buttons && (_elements & Body)==Body) { + if (!flat_buttons () && (_elements & Body)==Body) { if ( active_state() == Gtkmm2ext::ExplicitActive && ( !((_elements & Indicator)==Indicator) || use_custom_led_color) ) { //concave cairo_set_source (cr, concave_pattern); @@ -521,7 +521,7 @@ ArdourButton::render (Cairo::RefPtr const& ctx, cairo_rectangle_ } //inset - if (!_flat_buttons) { + if (!flat_buttons ()) { cairo_arc (cr, 0, 0, _diameter * .5, 0, 2 * M_PI); cairo_set_source (cr, led_inset_pattern); cairo_fill (cr); diff --git a/libs/widgets/ardour_knob.cc b/libs/widgets/ardour_knob.cc index 7f6fddf0dc..eecceead52 100644 --- a/libs/widgets/ardour_knob.cc +++ b/libs/widgets/ardour_knob.cc @@ -111,7 +111,7 @@ ArdourKnob::render (Cairo::RefPtr const& ctx, cairo_rectangle_t* bool arc = (_elements & Arc)==Arc; bool bevel = (_elements & Bevel)==Bevel; - bool flat = _flat_buttons; + bool flat = flat_buttons (); if ( arc ) { center_radius = scale*0.33;