summaryrefslogtreecommitdiff
path: root/libs/gtkmm2ext/pixfader.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2013-01-17 15:36:35 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2013-01-17 15:36:35 +0000
commitd0272c4558539706abf015c32f0032641474fda2 (patch)
treec515aec3bead8ea52eff2f566a2092968a53c4a2 /libs/gtkmm2ext/pixfader.cc
parenta3bd17970ef1f168d7d942a130ec4934251f45fe (diff)
cache cairo_pattern_t's for PixFader so that we don't generate one per fader, but rather one per size+color combination
git-svn-id: svn://localhost/ardour2/branches/3.0@13874 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/gtkmm2ext/pixfader.cc')
-rw-r--r--libs/gtkmm2ext/pixfader.cc33
1 files changed, 20 insertions, 13 deletions
diff --git a/libs/gtkmm2ext/pixfader.cc b/libs/gtkmm2ext/pixfader.cc
index 43657a5902..994c719cd3 100644
--- a/libs/gtkmm2ext/pixfader.cc
+++ b/libs/gtkmm2ext/pixfader.cc
@@ -33,13 +33,14 @@ using namespace std;
#define CORNER_RADIUS 4
#define FADER_RESERVE (2*CORNER_RADIUS)
+std::list<PixFader::FaderImage*> PixFader::_patterns;
+
PixFader::PixFader (Gtk::Adjustment& adj, int orientation, int fader_length, int fader_girth)
: adjustment (adj)
, span (fader_length)
, girth (fader_girth)
, _orien (orientation)
, pattern (0)
- , texture_pattern (0)
, _hovering (false)
, last_drawn (-1)
, dragging (false)
@@ -55,27 +56,24 @@ PixFader::PixFader (Gtk::Adjustment& adj, int orientation, int fader_length, int
PixFader::~PixFader ()
{
- free_patterns ();
}
-void
-PixFader::free_patterns ()
+cairo_pattern_t*
+PixFader::find_pattern (double afr, double afg, double afb,
+ double abr, double abg, double abb,
+ int w, int h)
{
- if (pattern) {
- cairo_pattern_destroy (pattern);
- pattern = 0;
- }
- if (texture_pattern) {
- cairo_pattern_destroy (texture_pattern);
- texture_pattern = 0;
+ for (list<FaderImage*>::iterator f = _patterns.begin(); f != _patterns.end(); ++f) {
+ if ((*f)->matches (afr, afg, afb, abr, abg, abb, w, h)) {
+ return (*f)->pattern;
+ }
}
+ return 0;
}
void
PixFader::create_patterns ()
{
- free_patterns ();
-
Gdk::Color c = get_style()->get_fg (get_state());
float fr, fg, fb;
float br, bg, bb;
@@ -96,6 +94,11 @@ PixFader::create_patterns ()
double w = get_width();
+ if ((pattern = find_pattern (fr, fg, fb, br, bg, bb, get_width(), get_height())) != 0) {
+ /* found it - use it */
+ return;
+ }
+
if (_orien == VERT) {
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, get_width(), get_height() * 2.0);
@@ -154,6 +157,10 @@ PixFader::create_patterns ()
pattern = cairo_pattern_create_for_surface (surface);
}
+ /* cache it for others to use */
+
+ _patterns.push_back (new FaderImage (pattern, fr, fg, fb, br, bg, bb, get_width(), get_height()));
+
cairo_destroy (tc);
cairo_surface_destroy (surface);