color-picker extension support
The color picker use the ["Color Picker" extensions](https://github.com/tuberry/color-picker) if it is available thanks to `pickAsync` "api". In comparaison to the GS color picker, it provides a colored cursor and a menu to adjust the color.
This commit is contained in:
parent
af694382c8
commit
737bc856c4
25
area.js
25
area.js
|
|
@ -50,6 +50,7 @@ const SVG_DEBUG_EXTENDS = false;
|
||||||
const TEXT_CURSOR_TIME = 600; // ms
|
const TEXT_CURSOR_TIME = 600; // ms
|
||||||
const ELEMENT_GRABBER_TIME = 80; // ms, default is about 16 ms
|
const ELEMENT_GRABBER_TIME = 80; // ms, default is about 16 ms
|
||||||
const GRID_TILES_HORIZONTAL_NUMBER = 30;
|
const GRID_TILES_HORIZONTAL_NUMBER = 30;
|
||||||
|
const COLOR_PICKER_EXTENSION_UUID = 'color-picker@tuberry';
|
||||||
|
|
||||||
const { Shapes, Transformations } = Elements;
|
const { Shapes, Transformations } = Elements;
|
||||||
const { DisplayStrings } = Menu;
|
const { DisplayStrings } = Menu;
|
||||||
|
|
@ -75,10 +76,6 @@ const getColorFromString = function(string, fallback) {
|
||||||
return color;
|
return color;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getColorFromRGB = function(red, green, blue) {
|
|
||||||
return getColorFromString(`rgb(${red},${green},${blue})`, 'White');
|
|
||||||
};
|
|
||||||
|
|
||||||
// DrawingArea is the widget in which we draw, thanks to Cairo.
|
// DrawingArea is the widget in which we draw, thanks to Cairo.
|
||||||
// It creates and manages a DrawingElement for each "brushstroke".
|
// It creates and manages a DrawingElement for each "brushstroke".
|
||||||
// It handles pointer/mouse/(touch?) events and some keyboard events.
|
// It handles pointer/mouse/(touch?) events and some keyboard events.
|
||||||
|
|
@ -1038,8 +1035,10 @@ var DrawingArea = new Lang.Class({
|
||||||
},
|
},
|
||||||
|
|
||||||
_onColorPicked: function(color) {
|
_onColorPicked: function(color) {
|
||||||
let { red, green, blue } = color;
|
if (color instanceof Clutter.Color)
|
||||||
this.currentColor = getColorFromRGB(red, green, blue);
|
color = color.to_string().slice(0, -2);
|
||||||
|
|
||||||
|
this.currentColor = getColorFromString(color);
|
||||||
if (this.currentElement) {
|
if (this.currentElement) {
|
||||||
this.currentElement.color = this.currentColor;
|
this.currentElement.color = this.currentColor;
|
||||||
this._redisplay();
|
this._redisplay();
|
||||||
|
|
@ -1056,6 +1055,20 @@ var DrawingArea = new Lang.Class({
|
||||||
// Translators: It is displayed in an OSD notification to ask the user to start picking, so it should use the imperative mood.
|
// Translators: It is displayed in an OSD notification to ask the user to start picking, so it should use the imperative mood.
|
||||||
this.emit('show-osd', Files.Icons.COLOR_PICKER, pgettext("osd-notification", "Pick a color"), "", -1, false);
|
this.emit('show-osd', Files.Icons.COLOR_PICKER, pgettext("osd-notification", "Pick a color"), "", -1, false);
|
||||||
|
|
||||||
|
let extension = Main.extensionManager && Main.extensionManager.lookup(COLOR_PICKER_EXTENSION_UUID);
|
||||||
|
if (extension && extension.state == ExtensionUtils.ExtensionState.ENABLED && extension.stateObj && extension.stateObj.pickAsync) {
|
||||||
|
extension.stateObj.pickAsync().then(result => {
|
||||||
|
if (typeof result == 'string')
|
||||||
|
this._onColorPicked(result);
|
||||||
|
else
|
||||||
|
this.initPointerCursor();
|
||||||
|
}).catch(e => {
|
||||||
|
this.initPointerCursor();
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let screenshot = new Shell.Screenshot();
|
let screenshot = new Shell.Screenshot();
|
||||||
let pickPixel = new Screenshot.PickPixel(screenshot);
|
let pickPixel = new Screenshot.PickPixel(screenshot);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue