From 43067f9aa41760eb061feccea03ed6f41b5a3eba Mon Sep 17 00:00:00 2001
From: Till Hartmann <ich@till-hartmann.de>
Date: Thu, 5 Jan 2012 19:26:42 +0100
Subject: [PATCH] pick context: ignore erasers
 Fixed http://gna.org/bugs/?19044 and added an additional
 brushsetting "pickable" which determines whether the brush
 may get picked or not (where a value of 0.0 means "not
 pickable" and 1.0 means "pickable").

---
 brushlib/brushsettings.py  |    1 +
 gui/brushsettingswindow.py |    2 +-
 lib/brush.py               |    3 +++
 lib/layer.py               |   11 +++++++----
 lib/stroke.py              |    3 +--
 5 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/brushlib/brushsettings.py b/brushlib/brushsettings.py
index cc30bcc..808a861 100644
--- a/brushlib/brushsettings.py
+++ b/brushlib/brushsettings.py
@@ -88,6 +88,7 @@ settings_list = [
 
     ['lock_alpha', _('Lock alpha'), False, 0.0, 0.0, 1.0, _("Do not modify the alpha channel of the layer (paint only where there is paint already)\n 0.0 normal painting\n 0.5 half of the paint gets applied normally\n 1.0 alpha channel fully locked")],
     ['colorize', _('Colorize'), False, 0.0, 0.0, 1.0, _("Colorize the target layer, setting its hue and saturation from the active brush colour while retaining its value and alpha.")],
+    ['pickable', _('Pick-Context enabled'), True, 0.0, 1.0, 1.0, _("Determines whether the brush can be picked (1.0) with pick-context or not (0.0)")],
     ]
 
 settings_hidden = 'color_h color_s color_v'.split()
diff --git a/gui/brushsettingswindow.py b/gui/brushsettingswindow.py
index 816997b..16b1544 100644
--- a/gui/brushsettingswindow.py
+++ b/gui/brushsettingswindow.py
@@ -106,7 +106,7 @@ class Window(windowing.SubWindow):
             {'id' : 'tracking', 'title' : _('Tracking'),'settings' : [ 'slow_tracking', 'slow_tracking_per_dab', 'tracking_noise' ]},
             {'id' : 'stroke',   'title' : _('Stroke'),  'settings' : [ 'stroke_threshold', 'stroke_duration_logarithmic', 'stroke_holdtime' ]},
             {'id' : 'color',    'title' : _('Color'),   'settings' : [ 'change_color_h', 'change_color_l', 'change_color_hsl_s', 'change_color_v', 'change_color_hsv_s', 'restore_color', 'colorize' ]},
-            {'id' : 'custom',   'title' : _('Custom'),  'settings' : [ 'custom_input', 'custom_input_slowness' ]}
+            {'id' : 'custom',   'title' : _('Custom'),  'settings' : [ 'custom_input', 'custom_input_slowness', 'pickable' ]}
             ]
 
         for group in groups:
diff --git a/lib/brush.py b/lib/brush.py
index 338b051..80023f6 100644
--- a/lib/brush.py
+++ b/lib/brush.py
@@ -357,6 +357,9 @@ class BrushInfo:
     def is_alpha_locked(self):
         return self.has_large_base_value("lock_alpha")
 
+    def is_pickable(self):
+        return self.has_large_base_value("pickable") or self.is_eraser()
+
     def get_effective_radius(self):
         """Return brush radius in pixels for cursor shape."""
         base_radius = math.exp(self.get_base_value('radius_logarithmic'))
diff --git a/lib/layer.py b/lib/layer.py
index d2abf83..3110c7b 100644
--- a/lib/layer.py
+++ b/lib/layer.py
@@ -119,10 +119,13 @@ class Layer:
     def add_stroke(self, stroke, snapshot_before):
         before = snapshot_before[1] # extract surface snapshot
         after  = self._surface.save_snapshot()
-        shape = strokemap.StrokeShape()
-        shape.init_from_snapshots(before, after)
-        shape.brush_string = stroke.brush_settings
-        self.strokes.append(shape)
+        if stroke.pickable:
+            shape = strokemap.StrokeShape()
+            shape.init_from_snapshots(before, after)
+            shape.brush_string = stroke.brush_settings
+            self.strokes.append(shape)
+        else:
+            pass
 
 
     def save_strokemap_to_file(self, f, translate_x, translate_y):
diff --git a/lib/stroke.py b/lib/stroke.py
index ef0202b..82d96d0 100644
--- a/lib/stroke.py
+++ b/lib/stroke.py
@@ -28,7 +28,6 @@ class Stroke:
         assert not self.finished
 
         self.brush_settings = brush.brushinfo.save_to_string() # fast (brush caches this string)
-
         states = brush.get_state()
         assert states.dtype == 'float32'
         self.brush_state = states.tostring()
@@ -51,7 +50,7 @@ class Stroke:
         data = data.tostring()
         version = '2'
         self.stroke_data = version + data
-
+        self.pickable = self.brush.brushinfo.is_pickable()
         self.total_painting_time = self.brush.stroke_total_painting_time
         #if not self.empty:
         #    print 'Recorded', len(self.stroke_data), 'bytes. (painting time: %.2fs)' % self.total_painting_time
-- 
1.7.8.1

