13
0

Add ArdourButton::set_fixed_colors() (equivalent to ::set_bg_colors() in Valeriy's original changes)

This commit is contained in:
Paul Davis 2014-03-06 08:05:33 -05:00
parent b360274e34
commit 4a915ee541
2 changed files with 42 additions and 1 deletions

View File

@ -493,6 +493,10 @@ ArdourButton::on_size_request (Gtk::Requisition* req)
req->width += _corner_radius;
}
/**
* This sets the colors used for rendering based on the name of the button, and
* thus uses information from the GUI config data.
*/
void
ArdourButton::set_colors ()
{
@ -514,6 +518,41 @@ ArdourButton::set_colors ()
build_patterns ();
}
/**
* This sets the colors used for rendering based on two fixed values, rather
* than basing them on the button name, and thus information in the GUI config
* data.
*/
void ArdourButton::set_fixed_colors (const uint32_t color_active, const uint32_t color_inactive)
{
set_name (""); /* this will trigger a "style-changed" message and then
set_colors()
*/
fill_start_active_color = fill_end_active_color = color_active;
unsigned char r, g, b, a;
UINT_TO_RGBA(color_active, &r, &g, &b, &a);
double white_contrast = (max (double(r), 255.) - min (double(r), 255.)) +
(max (double(g), 255.) - min (double(g), 255.)) +
(max (double(b), 255.) - min (double(b), 255.));
double black_contrast = (max (double(r), 0.) - min (double(r), 0.)) +
(max (double(g), 0.) - min (double(g), 0.)) +
(max (double(b), 0.) - min (double(b), 0.));
text_active_color =
text_inactive_color = (white_contrast > black_contrast) ?
RGBA_TO_UINT(255, 255, 255, 255) : /* use white */
RGBA_TO_UINT( 0, 0, 0, 255); /* use black */
fill_start_inactive_color = fill_end_inactive_color = color_inactive;
/* XXX what about led colors ? */
build_patterns ();
}
void
ArdourButton::build_patterns ()

View File

@ -96,6 +96,8 @@ class ArdourButton : public CairoWidget , public Gtkmm2ext::Activatable
void set_image (const Glib::RefPtr<Gdk::Pixbuf>&);
void set_fixed_colors (const uint32_t active_color, const uint32_t inactive_color);
protected:
void render (cairo_t *);
void on_size_request (Gtk::Requisition* req);