add smooth feature
This commit is contained in:
parent
7f9a3195b4
commit
c59f499b4c
30
draw.js
30
draw.js
|
|
@ -60,6 +60,7 @@ var DrawingArea = new Lang.Class({
|
||||||
this.connect('style-changed', this._onStyleChanged.bind(this));
|
this.connect('style-changed', this._onStyleChanged.bind(this));
|
||||||
this.connect('repaint', this._repaint.bind(this));
|
this.connect('repaint', this._repaint.bind(this));
|
||||||
|
|
||||||
|
this.settings = Convenience.getSettings();
|
||||||
this.emitter = new DrawingAreaEmitter();
|
this.emitter = new DrawingAreaEmitter();
|
||||||
this.helper = helper;
|
this.helper = helper;
|
||||||
|
|
||||||
|
|
@ -217,6 +218,8 @@ var DrawingArea = new Lang.Class({
|
||||||
this._stopDrawing();
|
this._stopDrawing();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.smoothedStroke = this.settings.get_boolean('smoothed-stroke');
|
||||||
|
|
||||||
this.currentElement = new DrawingElement ({
|
this.currentElement = new DrawingElement ({
|
||||||
color: this.currentColor,
|
color: this.currentColor,
|
||||||
line: { lineWidth: this.currentLineWidth, lineJoin: this.currentLineJoin, lineCap: this.currentLineCap },
|
line: { lineWidth: this.currentLineWidth, lineJoin: this.currentLineJoin, lineCap: this.currentLineCap },
|
||||||
|
|
@ -269,7 +272,7 @@ var DrawingArea = new Lang.Class({
|
||||||
if (!this.currentElement)
|
if (!this.currentElement)
|
||||||
return;
|
return;
|
||||||
if (this.currentElement.shape == Shapes.NONE)
|
if (this.currentElement.shape == Shapes.NONE)
|
||||||
this.currentElement.points.push([x, y]);
|
this.currentElement.addPoint(x, y, this.smoothedStroke);
|
||||||
else
|
else
|
||||||
this.currentElement.points[1] = [x, y];
|
this.currentElement.points[1] = [x, y];
|
||||||
this._redisplay();
|
this._redisplay();
|
||||||
|
|
@ -336,6 +339,13 @@ var DrawingArea = new Lang.Class({
|
||||||
this._redisplay();
|
this._redisplay();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
smoothLastElement: function() {
|
||||||
|
if (this.elements.length > 0 && this.elements[this.elements.length - 1].shape == Shapes.NONE) {
|
||||||
|
this.elements[this.elements.length - 1].smoothAll();
|
||||||
|
this._redisplay();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
toggleBackground: function() {
|
toggleBackground: function() {
|
||||||
this.hasBackground = !this.hasBackground;
|
this.hasBackground = !this.hasBackground;
|
||||||
this.get_parent().set_background_color(this.hasBackground ? this.activeBackgroundColor : null);
|
this.get_parent().set_background_color(this.hasBackground ? this.activeBackgroundColor : null);
|
||||||
|
|
@ -598,7 +608,25 @@ var DrawingElement = new Lang.Class({
|
||||||
}
|
}
|
||||||
|
|
||||||
return row;
|
return row;
|
||||||
|
},
|
||||||
|
|
||||||
|
addPoint: function(x, y, smoothedStroke) {
|
||||||
|
this.points.push([x, y]);
|
||||||
|
if (smoothedStroke)
|
||||||
|
this.smooth(this.points.length - 1);
|
||||||
|
},
|
||||||
|
|
||||||
|
smooth: function(i) {
|
||||||
|
if (i < 2)
|
||||||
|
return;
|
||||||
|
this.points[i-1] = [(this.points[i-2][0] + this.points[i][0]) / 2, (this.points[i-2][1] + this.points[i][1]) / 2];
|
||||||
|
},
|
||||||
|
|
||||||
|
smoothAll: function() {
|
||||||
|
for (let i = 0; i < this.points.length; i++) {
|
||||||
|
this.smooth(i);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var HELPER_ANIMATION_TIME = 0.25;
|
var HELPER_ANIMATION_TIME = 0.25;
|
||||||
|
|
|
||||||
|
|
@ -117,6 +117,7 @@ var AreaManager = new Lang.Class({
|
||||||
'undo': this.activeArea.undo.bind(this.activeArea),
|
'undo': this.activeArea.undo.bind(this.activeArea),
|
||||||
'redo': this.activeArea.redo.bind(this.activeArea),
|
'redo': this.activeArea.redo.bind(this.activeArea),
|
||||||
'delete-last-element': this.activeArea.deleteLastElement.bind(this.activeArea),
|
'delete-last-element': this.activeArea.deleteLastElement.bind(this.activeArea),
|
||||||
|
'smooth-last-element': this.activeArea.smoothLastElement.bind(this.activeArea),
|
||||||
'save-as-svg': this.activeArea.save.bind(this.activeArea),
|
'save-as-svg': this.activeArea.save.bind(this.activeArea),
|
||||||
'toggle-background': this.activeArea.toggleBackground.bind(this.activeArea),
|
'toggle-background': this.activeArea.toggleBackground.bind(this.activeArea),
|
||||||
'increment-line-width': () => this.activeArea.incrementLineWidth(1),
|
'increment-line-width': () => this.activeArea.incrementLineWidth(1),
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,9 @@ msgstr ""
|
||||||
msgid "Erase last brushstroke"
|
msgid "Erase last brushstroke"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "Smooth last brushstroke"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
msgid "Increment line width"
|
msgid "Increment line width"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
|
@ -186,6 +189,12 @@ msgstr ""
|
||||||
msgid "(in drawing mode)"
|
msgid "(in drawing mode)"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "Smooth stroke during the drawing process"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "You can smooth the stroke afterward\nSee"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
msgid "Change the style"
|
msgid "Change the style"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
|
|
||||||
15
prefs.js
15
prefs.js
|
|
@ -41,6 +41,7 @@ var INTERNAL_KEYBINDINGS = {
|
||||||
'undo': "Undo last brushstroke",
|
'undo': "Undo last brushstroke",
|
||||||
'redo': "Redo last brushstroke",
|
'redo': "Redo last brushstroke",
|
||||||
'delete-last-element' : "Erase last brushstroke",
|
'delete-last-element' : "Erase last brushstroke",
|
||||||
|
'smooth-last-element': "Smooth last brushstroke",
|
||||||
'-separator-1': '',
|
'-separator-1': '',
|
||||||
'increment-line-width': "Increment line width",
|
'increment-line-width': "Increment line width",
|
||||||
'decrement-line-width': "Decrement line width",
|
'decrement-line-width': "Decrement line width",
|
||||||
|
|
@ -148,6 +149,20 @@ const PrefsPage = new GObject.Class({
|
||||||
|
|
||||||
listBox.add(new Gtk.Box({ margin_top: MARGIN, margin_left: MARGIN, margin_right: MARGIN }));
|
listBox.add(new Gtk.Box({ margin_top: MARGIN, margin_left: MARGIN, margin_right: MARGIN }));
|
||||||
|
|
||||||
|
let smoothBox = new Gtk.Box({ margin: MARGIN });
|
||||||
|
let smoothLabelBox = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL });
|
||||||
|
let smoothLabel1 = new Gtk.Label({label: _("Smooth stroke during the drawing process")});
|
||||||
|
let smoothLabel2 = new Gtk.Label({ use_markup: true, halign: 1, label: "<small>" + _("You can smooth the stroke afterward\nSee") + " \"" + _("Smooth last brushstroke") + "\"</small>" });
|
||||||
|
smoothLabel1.set_halign(1);
|
||||||
|
smoothLabel2.get_style_context().add_class("dim-label");
|
||||||
|
smoothLabelBox.pack_start(smoothLabel1, true, true, 0);
|
||||||
|
smoothLabelBox.pack_start(smoothLabel2, true, true, 0);
|
||||||
|
let smoothSwitch = new Gtk.Switch({valign: 3});
|
||||||
|
this.settings.bind("smoothed-stroke", smoothSwitch, "active", 0);
|
||||||
|
smoothBox.pack_start(smoothLabelBox, true, true, 4);
|
||||||
|
smoothBox.pack_start(smoothSwitch, false, false, 4);
|
||||||
|
listBox.add(smoothBox);
|
||||||
|
|
||||||
let internalKeybindingsWidget = new KeybindingsWidget(INTERNAL_KEYBINDINGS, this.settings);
|
let internalKeybindingsWidget = new KeybindingsWidget(INTERNAL_KEYBINDINGS, this.settings);
|
||||||
internalKeybindingsWidget.margin = MARGIN;
|
internalKeybindingsWidget.margin = MARGIN;
|
||||||
listBox.add(internalKeybindingsWidget);
|
listBox.add(internalKeybindingsWidget);
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -1,6 +1,11 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<schemalist gettext-domain="gnome-shell-extensions">
|
<schemalist gettext-domain="gnome-shell-extensions">
|
||||||
<schema path="/org/gnome/shell/extensions/draw-on-your-screen/" id="org.gnome.shell.extensions.draw-on-your-screen">
|
<schema path="/org/gnome/shell/extensions/draw-on-your-screen/" id="org.gnome.shell.extensions.draw-on-your-screen">
|
||||||
|
<key type="b" name="smoothed-stroke">
|
||||||
|
<default>false</default>
|
||||||
|
<summary>smoothed stroke</summary>
|
||||||
|
<description>smoothed stroke</description>
|
||||||
|
</key>
|
||||||
<key type="as" name="toggle-drawing">
|
<key type="as" name="toggle-drawing">
|
||||||
<default>["<Alt><Super>d"]</default>
|
<default>["<Alt><Super>d"]</default>
|
||||||
<summary>toggle drawing</summary>
|
<summary>toggle drawing</summary>
|
||||||
|
|
@ -26,6 +31,11 @@
|
||||||
<summary>delete last element</summary>
|
<summary>delete last element</summary>
|
||||||
<description>delete last element</description>
|
<description>delete last element</description>
|
||||||
</key>
|
</key>
|
||||||
|
<key type="as" name="smooth-last-element">
|
||||||
|
<default>["<Primary>equal"]</default>
|
||||||
|
<summary>smooth last brushstroke</summary>
|
||||||
|
<description>smooth last brushstroke</description>
|
||||||
|
</key>
|
||||||
<key type="as" name="toggle-background">
|
<key type="as" name="toggle-background">
|
||||||
<default>["<Primary>b"]</default>
|
<default>["<Primary>b"]</default>
|
||||||
<summary>toggle background</summary>
|
<summary>toggle background</summary>
|
||||||
|
|
@ -57,7 +67,7 @@
|
||||||
<description>select text</description>
|
<description>select text</description>
|
||||||
</key>
|
</key>
|
||||||
<key type="as" name="select-none-shape">
|
<key type="as" name="select-none-shape">
|
||||||
<default>["<Primary>u"]</default>
|
<default>["<Primary>p"]</default>
|
||||||
<summary>unselect shape (free drawing)</summary>
|
<summary>unselect shape (free drawing)</summary>
|
||||||
<description>unselect shape (free drawing)</description>
|
<description>unselect shape (free drawing)</description>
|
||||||
</key>
|
</key>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue