From fb33b4c2f33f4f079326680a52cdb6eb834fcd09 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 26 Mar 2021 13:34:36 +0100 Subject: [PATCH] Add convenience API to render icons on signal_expose_event --- libs/widgets/ardour_icon.cc | 19 +++++++++++++++++++ libs/widgets/widgets/ardour_icon.h | 6 ++++++ tools/icons/makefile | 2 +- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/libs/widgets/ardour_icon.cc b/libs/widgets/ardour_icon.cc index 933b03ceea..fab8a0cbf1 100644 --- a/libs/widgets/ardour_icon.cc +++ b/libs/widgets/ardour_icon.cc @@ -21,6 +21,7 @@ #include // std:min #include "gtkmm2ext/colors.h" +#include "gtkmm2ext/rgb_macros.h" #include "widgets/ardour_icon.h" using namespace ArdourWidgets::ArdourIcon; @@ -1395,3 +1396,21 @@ ArdourWidgets::ArdourIcon::render (cairo_t *cr, cairo_restore (cr); return rv; } + +bool +ArdourWidgets::ArdourIcon::expose (GdkEventExpose* ev, Gtk::Widget* w, const enum ArdourIcon::Icon icon) +{ + Glib::RefPtr win (w->get_window()); + cairo_t* cr = gdk_cairo_create (win->gobj()); + gdk_cairo_rectangle (cr, &ev->area); + cairo_clip (cr); + + Glib::RefPtr style = w->get_style(); + Gdk::Color fg (style->get_fg (Gtk::STATE_NORMAL)); + + ArdourIcon::render (cr, icon, win->get_width (), win->get_height (), Gtkmm2ext::ExplicitActive, + RGBA_TO_UINT (fg.get_red() / 255., fg.get_green() / 255, fg.get_blue() / 255, 255)); + cairo_destroy (cr); + + return true; +} diff --git a/libs/widgets/widgets/ardour_icon.h b/libs/widgets/widgets/ardour_icon.h index ea65d692b8..65bfcaef76 100644 --- a/libs/widgets/widgets/ardour_icon.h +++ b/libs/widgets/widgets/ardour_icon.h @@ -21,6 +21,7 @@ #include #include +#include #include "gtkmm2ext/widget_state.h" #include "widgets/visibility.h" @@ -77,6 +78,11 @@ namespace ArdourWidgets { namespace ArdourIcon { const int width, const int height, const Gtkmm2ext::ActiveState state, const uint32_t fg_color); + + LIBWIDGETS_API bool expose (GdkEventExpose* ev, + Gtk::Widget* w, + const enum Icon icon); + }; } /* end namespace */ #endif diff --git a/tools/icons/makefile b/tools/icons/makefile index 39e98985bb..2f34777b84 100644 --- a/tools/icons/makefile +++ b/tools/icons/makefile @@ -3,7 +3,7 @@ ICONFLAGS?=-g AD = ../.. CXXFLAGS = -Wall CPPFLAGS = -I $(AD)/libs/gtkmm2ext -I $(AD)/libs/widgets -I $(AD)/libs/pbd -I $(AD)/build/libs/pbd -CPPFLAGS += `pkg-config --cflags cairo cairomm-1.0 libxml-2.0 glibmm-2.4` +CPPFLAGS += `pkg-config --cflags cairo cairomm-1.0 libxml-2.0 glibmm-2.4 gtkmm-2.4` LDFLAGS = -L$(AD)/build/libs/pbd -Wl,-rpath=$(AD)/build/libs/pbd LDFLAGS += -L$(AD)/build/libs/gtkmm2ext -Wl,-rpath=$(AD)/build/libs/gtkmm2ext