13
0

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.
This commit is contained in:
Robin Gareus 2021-01-26 23:01:05 +01:00
parent 046d7d01f5
commit 70ad205bc1
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
6 changed files with 65 additions and 40 deletions

View File

@ -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<void,Gtk::Widget*> 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<void,Gtk::Widget*> s)
{

View File

@ -0,0 +1,57 @@
/*
* Copyright (C) 2011-2016 Paul Davis <paul@linuxaudiosystems.com>
* Copyright (C) 2021 Robin Gareus <robin@gareus.org>
*
* 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

View File

@ -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<void,Gtk::Widget*> focus_handler;

View File

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

View File

@ -262,7 +262,7 @@ ArdourButton::render (Cairo::RefPtr<Cairo::Context> 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<Cairo::Context> 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<Cairo::Context> 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);

View File

@ -111,7 +111,7 @@ ArdourKnob::render (Cairo::RefPtr<Cairo::Context> 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;