From e469ce0961196a3075c391b2256c84e6042c1e2a Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Wed, 24 Jul 2013 22:05:24 +0200 Subject: [PATCH] get meter color from gtkrc style file --- gtk2_ardour/meter_patterns.cc | 28 ++++++++++++++++----- gtk2_ardour/utils.cc | 47 +++++++++++++++++++++++++++++++++++ gtk2_ardour/utils.h | 2 ++ 3 files changed, 71 insertions(+), 6 deletions(-) diff --git a/gtk2_ardour/meter_patterns.cc b/gtk2_ardour/meter_patterns.cc index 4cd96f2433..0182cc3e89 100644 --- a/gtk2_ardour/meter_patterns.cc +++ b/gtk2_ardour/meter_patterns.cc @@ -200,10 +200,14 @@ static inline float mtr_col_and_fract( } static void set_bg_color(Gtk::Widget& w, cairo_t* cr, MeterType type) { - // TODO use "meterstrip*" stype + float r,g,b; switch(type) { case MeterVU: - cairo_set_source_rgb (cr, 1.0, 1.0, 0.85); + if (rgba_p_from_style("meterstripVU", &r, &g, &b, "bg")) { + cairo_set_source_rgb (cr, r, g, b); + } else { + cairo_set_source_rgb (cr, 1.0, 1.0, 0.85); + } break; case MeterIEC1DIN: case MeterIEC1NOR: @@ -211,7 +215,11 @@ static void set_bg_color(Gtk::Widget& w, cairo_t* cr, MeterType type) { case MeterIEC2EBU: case MeterK14: case MeterK20: - cairo_set_source_rgb (cr, 0.1, 0.1, 0.1); + if (rgba_p_from_style("meterstripPPM", &r, &g, &b, "bg")) { + cairo_set_source_rgb (cr, r, g, b); + } else { + cairo_set_source_rgb (cr, 0.1, 0.1, 0.1); + } break; default: { @@ -223,13 +231,21 @@ static void set_bg_color(Gtk::Widget& w, cairo_t* cr, MeterType type) { } static void set_fg_color(Gtk::Widget& w, MeterType type, Gdk::Color * c) { - // TODO use "meterstrip*" stype + float r,g,b; switch(type) { case MeterVU: - c->set_rgb_p(0.0, 0.0, 0.0); + if (rgba_p_from_style("meterstripVU", &r, &g, &b)) { + c->set_rgb_p(r, g, b); + } else { + c->set_rgb_p(0.0, 0.0, 0.0); + } break; default: - c->set_rgb_p(1.0, 1.0, 1.0); + if (rgba_p_from_style("meterstripPPM", &r, &g, &b)) { + c->set_rgb_p(r, g, b); + } else { + c->set_rgb_p(1.0, 1.0, 1.0); + } break; } } diff --git a/gtk2_ardour/utils.cc b/gtk2_ardour/utils.cc index d4bc460269..72a922046f 100644 --- a/gtk2_ardour/utils.cc +++ b/gtk2_ardour/utils.cc @@ -301,6 +301,53 @@ rgba_from_style (string style, uint32_t r, uint32_t g, uint32_t b, uint32_t a, s } } +bool +rgba_p_from_style (string style, float *r, float *g, float *b, string attr, int state) +{ + static Gtk::Window* window = 0; + assert (r && g && b); + + if (window == 0) { + window = new Window (WINDOW_TOPLEVEL); + } + + Gtk::EventBox foo; + + window->add (foo); + + foo.set_name (style); + foo.ensure_style (); + + GtkRcStyle* rc = foo.get_style()->gobj()->rc_style; + + if (!rc) { + warning << string_compose (_("missing RGBA style for \"%1\""), style) << endl; + return false; + } + if (attr == "fg") { + *r = rc->fg[state].red / 65535.0; + *g = rc->fg[state].green / 65535.0; + *b = rc->fg[state].blue / 65535.0; + } else if (attr == "bg") { + *r = rc->bg[state].red / 65535.0; + *g = rc->bg[state].green / 65535.0; + *b = rc->bg[state].blue / 65535.0; + } else if (attr == "base") { + *r = rc->base[state].red / 65535.0; + *g = rc->base[state].green / 65535.0; + *b = rc->base[state].blue / 65535.0; + } else if (attr == "text") { + *r = rc->text[state].red / 65535.0; + *g = rc->text[state].green / 65535.0; + *b = rc->text[state].blue / 65535.0; + } else { + return false; + } + + window->remove (); + return true; +} + bool canvas_item_visible (ArdourCanvas::Item* item) { diff --git a/gtk2_ardour/utils.h b/gtk2_ardour/utils.h index d3110104fb..5d7bf000ea 100644 --- a/gtk2_ardour/utils.h +++ b/gtk2_ardour/utils.h @@ -56,6 +56,8 @@ Pango::FontDescription get_font_for_style (std::string widgetname); uint32_t rgba_from_style (std::string, uint32_t, uint32_t, uint32_t, uint32_t, std::string = "fg", int = Gtk::STATE_NORMAL, bool = true); +bool rgba_p_from_style (std::string, float*, float*, float*, std::string = "fg", int = Gtk::STATE_NORMAL); + void decorate (Gtk::Window& w, Gdk::WMDecoration d); bool canvas_item_visible (ArdourCanvas::Item* item);