Skip to content

Commit

Permalink
tests with a striped background for ciecam-sliders...
Browse files Browse the repository at this point in the history
  • Loading branch information
toniwe committed Jun 28, 2018
1 parent 3a3f8e6 commit 19fc4d6
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion gui/colors/adjbases.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,25 @@ def render_background_cb(self, cr, wd, ht):
b_w = wd - b - b - 1
b_h = ht - b - b - 1

# Build a background (wip and very hacky!!!)
# temporarly check type to only show in these sliders...
from gui.colors.sliders import CIECAMLumaSlider, CIECAMChromaSlider, CIECAMHueSlider
if isinstance(self, (CIECAMLumaSlider, CIECAMChromaSlider, CIECAMHueSlider)):
if self.vertical:
stripes_gradient = cairo.LinearGradient(0, b, bar_length / 4, b + bar_length)
else:
stripes_gradient = cairo.LinearGradient(b, 0, b + bar_length, bar_length / 4)
num_stripes = int(bar_length / 2) # 2px per line, high dpi scaling? :)
for s in xrange(num_stripes):
p = s / num_stripes
r = g = b = 1 # white lines
if s % 2 == 0:
r = g = b = 0 # black lines
stripes_gradient.add_color_stop_rgba(p, r, g, b, 0.4)
cr.set_source(stripes_gradient)
cr.rectangle(b_x - 0.5, b_y - 0.5, b_w + 1, b_h + 1)
cr.fill()

# Build the gradient
if self.vertical:
bar_gradient = cairo.LinearGradient(0, b, 0, b + bar_length)
Expand All @@ -995,9 +1014,21 @@ def render_background_cb(self, cr, wd, ht):
p = s / samples
col = self.get_color_for_bar_amount(p)
r, g, b = col.get_rgb()
a = 1

if isinstance(self, (CIECAMLumaSlider, CIECAMChromaSlider, CIECAMHueSlider)):
# assume grey means invalid color
# TODO: need actual alpha in given color (return separate rgba color for sliders maybe?)
# TODO: "position" is inaccurate, more samples?
if r == g == b:
r = g = b = 0.4
a = 0
# test for clean cut
bar_gradient.add_color_stop_rgba(p - (1 / samples - 0.0001), r, g, b, a)
bar_gradient.add_color_stop_rgba(p + (1 / samples - 0.0001), r, g, b, a)
if self.vertical:
p = 1 - p
bar_gradient.add_color_stop_rgb(p, r, g, b)
bar_gradient.add_color_stop_rgba(p, r, g, b, a)

# Paint bar with Tango-like edges
cr.set_line_join(cairo.LINE_JOIN_ROUND)
Expand Down

0 comments on commit 19fc4d6

Please sign in to comment.