/
Fill Color.jsf
61 lines (55 loc) · 2.58 KB
/
Fill Color.jsf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
Show Color Picker Command v1.0
Ale Muñoz
Bind to keyboard shortcut for fullscreen panel-less colorpicking goodness
TODO: Add support for text selections
shortcut: CTRL + C
**DOC**
Set fill color. If the selection is a group, every object inside the group will be filled with the selected color. If the selected object has a gradient fill, it will be replaced with a solid fill. If the selected object is a Symbol, a Color Effect will be applied to it.
**DOC**
*/
try {
fw.runScript(fw.appJsCommandsDir + "/bs.js");
} catch(e){
alert("There was a problem running this command.\rThis is usually related to an installation problem, so please visit http://orangecommands.com and download an updated installer.\r\rSorry for the inconvenience.");
};
var choice = orangecommands.params || fw.popupColorPickerOverMouse("#00000000", true, false);
Selection.each(function(sel) {
fw.selection = sel;
switch (sel.kind()) {
case "symbol":
// TODO: do not replace effects in symbol, just add the color fill effect
var original_effects = fw.selection[0].effectList,
has_color_fill = false,
color_effect = { Blendmode:0, Color:choice, EffectIsVisible:true, EffectMoaID:"{dd54adc0-a279-11d3-b92a000502f3fdbe}", Opacity:100, category:"Adjust Color", name:"Color Fill" };
for( var i=0; i < original_effects.effects.length; i++) {
if (original_effects.effects[i].name == "Color Fill") {
original_effects.effects[i] = color_effect;
has_color_fill = true;
}
}
if (!has_color_fill) {
original_effects.effects[original_effects.effects.length] = color_effect;
};
fw.getDocumentDOM().applyEffects(original_effects);
break;
case "element":
// if the current object's fill is set to none, we'll have to assign a default fill before we can change the color.
if(!sel.pathAttributes.fill){
fw.getDocumentDOM().setFillNColor({ category:"fc_Solid", ditherColors:[ "#000000", "#000000" ], edgeType:"antialiased", feather:0, gradient:null, name:"fn_Normal", pattern:null, shape:"solid", stampingMode:"blend opaque", textureBlend:0, webDitherTransparent:false }, "#000000");
}
// make the object's fill a solid color
sel.pathAttributes.fill.category = 'fc_Solid';
default:
switch (choice) {
case "#ffffff00":
fw.getDocumentDOM().setFillNColor(null, choice);
break;
default:
fw.getDocumentDOM().setFillColor(choice);
break;
}
}
// Finally, copy the chosen color to the clipboard, just because...
fw.copy(choice);
});