Skip to content

Commit c29d82c

Browse files
committed
Alpha channels!
For RGBA / HSLA capture groups, enable alpha channel and draw on top of a checkerboard pattern. Includes user option to disable (drawing all colors opaque) and option for alternate BG pattern. Current choices are the default 'mid'=GIMP style, and 'light'=Photoshop style.
1 parent f8c3b3b commit c29d82c

File tree

5 files changed

+53
-9
lines changed

5 files changed

+53
-9
lines changed

GutterColor.sublime-settings

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@
1212
/*
1313
* The syntax for which to run GutterColor.
1414
*/
15-
"supported_syntax": ["css", "scss", "sass", "less", "stylus", "css3", "xml"]
15+
"supported_syntax": ["css", "scss", "sass", "less", "stylus", "css3", "xml"],
16+
17+
/*
18+
* Whether to render images with an alpha channel.
19+
* Setting false renders all colors as opaque, true composites
20+
* colors onto a gray checkered background, and "light" is
21+
* the same as true, but with a brighter BG texture
22+
*/
23+
"use_transparency": true
1624

1725
/*
1826
* Additional user-defined color matches.

gutter_color.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def clear_cache(force = False):
1111
from os import makedirs, listdir
1212
from sublime import cache_path
1313
from shutil import rmtree
14-
14+
1515
# The icon cache path
1616
icon_path = join(cache_path(), "GutterColor")
1717

@@ -55,4 +55,13 @@ def settings():
5555

5656
def syntax(view):
5757
"""Return the view syntax"""
58-
return view.settings().get('syntax').split('/')[-1].split('.')[0].lower()
58+
syntax = view.settings().get('syntax')
59+
return syntax.split('/')[-1].split('.')[0].lower() if syntax is not None else "plain text"
60+
61+
def current_directory(full=False):
62+
"""Return the name of the directory containing this plugin"""
63+
from os.path import dirname, realpath, split
64+
if full:
65+
return dirname(realpath(__file__))
66+
else:
67+
return split(dirname(realpath(__file__)))[1]

line.py

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ def rgba_color(self):
6363
"""Returns the color in the line, if any rgba is found."""
6464
matches = re.search(Line.RGBA_REGEXP, self.text)
6565
if matches:
66-
return 'rgb(' + matches.group(1) + ')'
66+
if self.transparency_settings()[0]:
67+
return matches.group(0)
68+
else:
69+
return 'rgb(' + matches.group(1) + ')'
6770

6871
def hsl_color(self):
6972
"""Returns the color in the line, if any hsl is found."""
@@ -75,7 +78,10 @@ def hsla_color(self):
7578
"""Returns the color in the line, if any rgba is found."""
7679
matches = re.search(Line.HSLA_REGEXP, self.text)
7780
if matches:
78-
return 'hsl(' + matches.group(1) + ')'
81+
if self.transparency_settings()[0]:
82+
return matches.group(0)
83+
else:
84+
return 'hsl(' + matches.group(1) + ')'
7985

8086
def custom_color(self):
8187
"""Returns the color in the line, if any user-defined is found."""
@@ -112,6 +118,20 @@ def erase_region(self):
112118
"""Remove icon from the gutter"""
113119
self.view.erase_regions("gutter_color_%s" % self.region.a)
114120

121+
def transparency_settings(self):
122+
from .gutter_color import current_directory
123+
# transparency settings
124+
use_transparency = self.settings.get("use_transparency")
125+
if use_transparency == True:
126+
background_path = os.path.join(current_directory(True),"transparency_circle_mid.png")
127+
elif use_transparency in ("light", "mid"):
128+
background_path = os.path.join(current_directory(True),str("transparency_circle_"+use_transparency+".png"))
129+
print(background_path)
130+
use_transparency = True
131+
else:
132+
use_transparency = False
133+
return (use_transparency, background_path)
134+
115135
def create_icon(self):
116136
paths = [
117137
"/usr/bin/convert",
@@ -138,11 +158,18 @@ def create_icon(self):
138158
convert_path = path
139159
break
140160

161+
(use_transparency, background_path) = self.transparency_settings()
162+
141163
"""Create the color icon using ImageMagick convert"""
142-
script = "\"%s\" -units PixelsPerCentimeter -type TrueColorMatte -channel RGBA " \
143-
"-size 32x32 -alpha transparent xc:none " \
144-
"-fill \"%s\" -draw \"circle 15,16 8,10\" png32:\"%s\"" % \
145-
(convert_path, self.color(), self.icon_path())
164+
if not use_transparency:
165+
script = "\"%s\" -units PixelsPerCentimeter -type TrueColorMatte -channel RGBA " \
166+
"-size 32x32 -alpha transparent xc:none " \
167+
"-fill \"%s\" -draw \"circle 15,16 8,10\" png32:\"%s\"" % \
168+
(convert_path, self.color(), self.icon_path())
169+
else:
170+
script = "\"%s\" \"%s\" -type TrueColorMatte -channel RGBA " \
171+
"-fill \"%s\" -draw \"circle 15,16 8,10\" png32:\"%s\"" % \
172+
(convert_path, background_path, self.color(), self.icon_path())
146173
if not isfile(self.icon_path()):
147174
pr = subprocess.Popen(script,
148175
shell = True,

transparency_circle_light.png

415 Bytes
Loading

transparency_circle_mid.png

411 Bytes
Loading

0 commit comments

Comments
 (0)