diff --git a/draw.js b/draw.js
index f3581cf..7f33741 100644
--- a/draw.js
+++ b/draw.js
@@ -60,6 +60,7 @@ var DrawingArea = new Lang.Class({
this.connect('style-changed', this._onStyleChanged.bind(this));
this.connect('repaint', this._repaint.bind(this));
+ this.settings = Convenience.getSettings();
this.emitter = new DrawingAreaEmitter();
this.helper = helper;
@@ -217,6 +218,8 @@ var DrawingArea = new Lang.Class({
this._stopDrawing();
});
+ this.smoothedStroke = this.settings.get_boolean('smoothed-stroke');
+
this.currentElement = new DrawingElement ({
color: this.currentColor,
line: { lineWidth: this.currentLineWidth, lineJoin: this.currentLineJoin, lineCap: this.currentLineCap },
@@ -269,7 +272,7 @@ var DrawingArea = new Lang.Class({
if (!this.currentElement)
return;
if (this.currentElement.shape == Shapes.NONE)
- this.currentElement.points.push([x, y]);
+ this.currentElement.addPoint(x, y, this.smoothedStroke);
else
this.currentElement.points[1] = [x, y];
this._redisplay();
@@ -336,6 +339,13 @@ var DrawingArea = new Lang.Class({
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() {
this.hasBackground = !this.hasBackground;
this.get_parent().set_background_color(this.hasBackground ? this.activeBackgroundColor : null);
@@ -598,7 +608,25 @@ var DrawingElement = new Lang.Class({
}
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;
diff --git a/extension.js b/extension.js
index b95021f..2712137 100644
--- a/extension.js
+++ b/extension.js
@@ -117,6 +117,7 @@ var AreaManager = new Lang.Class({
'undo': this.activeArea.undo.bind(this.activeArea),
'redo': this.activeArea.redo.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),
'toggle-background': this.activeArea.toggleBackground.bind(this.activeArea),
'increment-line-width': () => this.activeArea.incrementLineWidth(1),
diff --git a/locale/draw-on-your-screen.pot b/locale/draw-on-your-screen.pot
index 401e176..1f7af00 100644
--- a/locale/draw-on-your-screen.pot
+++ b/locale/draw-on-your-screen.pot
@@ -70,6 +70,9 @@ msgstr ""
msgid "Erase last brushstroke"
msgstr ""
+msgid "Smooth last brushstroke"
+msgstr ""
+
msgid "Increment line width"
msgstr ""
@@ -186,6 +189,12 @@ msgstr ""
msgid "(in drawing mode)"
msgstr ""
+msgid "Smooth stroke during the drawing process"
+msgstr ""
+
+msgid "You can smooth the stroke afterward\nSee"
+msgstr ""
+
msgid "Change the style"
msgstr ""
diff --git a/prefs.js b/prefs.js
index e459618..21b40ca 100644
--- a/prefs.js
+++ b/prefs.js
@@ -41,6 +41,7 @@ var INTERNAL_KEYBINDINGS = {
'undo': "Undo last brushstroke",
'redo': "Redo last brushstroke",
'delete-last-element' : "Erase last brushstroke",
+ 'smooth-last-element': "Smooth last brushstroke",
'-separator-1': '',
'increment-line-width': "Increment 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 }));
+ 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: "" + _("You can smooth the stroke afterward\nSee") + " \"" + _("Smooth last brushstroke") + "\"" });
+ 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);
internalKeybindingsWidget.margin = MARGIN;
listBox.add(internalKeybindingsWidget);
diff --git a/schemas/gschemas.compiled b/schemas/gschemas.compiled
index 0d32dc8..1300e09 100644
Binary files a/schemas/gschemas.compiled and b/schemas/gschemas.compiled differ
diff --git a/schemas/org.gnome.shell.extensions.draw-on-your-screen.gschema.xml b/schemas/org.gnome.shell.extensions.draw-on-your-screen.gschema.xml
index c018f29..ef4d5e8 100644
--- a/schemas/org.gnome.shell.extensions.draw-on-your-screen.gschema.xml
+++ b/schemas/org.gnome.shell.extensions.draw-on-your-screen.gschema.xml
@@ -1,6 +1,11 @@
+
+ false
+ smoothed stroke
+ smoothed stroke
+
["<Alt><Super>d"]
toggle drawing
@@ -26,6 +31,11 @@
delete last element
delete last element
+
+ ["<Primary>equal"]
+ smooth last brushstroke
+ smooth last brushstroke
+
["<Primary>b"]
toggle background
@@ -57,7 +67,7 @@
select text
- ["<Primary>u"]
+ ["<Primary>p"]
unselect shape (free drawing)
unselect shape (free drawing)