From 5b7d1eedf43b9e4017633c8e682e2e8dd6bbb515 Mon Sep 17 00:00:00 2001 From: abakkk Date: Sun, 7 Jun 2020 20:05:30 +0200 Subject: [PATCH] new polyline shape Mark vertices with `Enter` and finish drawing by releasing clic, like other shapes. --- draw.js | 28 +++++++++++++----- extension.js | 1 + locale/draw-on-your-screen.pot | 6 ++++ schemas/gschemas.compiled | Bin 3588 -> 3660 bytes ...extensions.draw-on-your-screen.gschema.xml | 5 ++++ 5 files changed, 33 insertions(+), 7 deletions(-) diff --git a/draw.js b/draw.js index 27f3d6d..88c5e9a 100644 --- a/draw.js +++ b/draw.js @@ -56,9 +56,9 @@ const LINECAP_ICON_PATH = Me.dir.get_child('data').get_child('icons').get_child( const DASHED_LINE_ICON_PATH = Me.dir.get_child('data').get_child('icons').get_child('dashed-line-symbolic.svg').get_path(); const FULL_LINE_ICON_PATH = Me.dir.get_child('data').get_child('icons').get_child('full-line-symbolic.svg').get_path(); -var Shapes = { NONE: 0, LINE: 1, ELLIPSE: 2, RECTANGLE: 3, TEXT: 4, POLYGON: 5 }; +var Shapes = { NONE: 0, LINE: 1, ELLIPSE: 2, RECTANGLE: 3, TEXT: 4, POLYGON: 5, POLYLINE: 6 }; const TextState = { DRAWING: 0, WRITING: 1 }; -const ShapeNames = { 0: "Free drawing", 1: "Line", 2: "Ellipse", 3: "Rectangle", 4: "Text", 5: "Polygon" }; +const ShapeNames = { 0: "Free drawing", 1: "Line", 2: "Ellipse", 3: "Rectangle", 4: "Text", 5: "Polygon", 6: "Polyline" }; const LineCapNames = { 0: 'Butt', 1: 'Round', 2: 'Square' }; const LineJoinNames = { 0: 'Miter', 1: 'Round', 2: 'Bevel' }; const FontWeightNames = { 0: 'Normal', 1: 'Bold' }; @@ -326,7 +326,8 @@ var DrawingArea = new Lang.Class({ this._redisplay(); return Clutter.EVENT_STOP; - } else if (this.currentElement && this.currentElement.shape == Shapes.POLYGON && + } else if (this.currentElement && + (this.currentElement.shape == Shapes.POLYGON || this.currentElement.shape == Shapes.POLYLINE) && (event.get_key_symbol() == Clutter.KEY_Return || event.get_key_symbol() == 65421)) { // copy last point let lastPoint = this.currentElement.points[this.currentElement.points.length - 1]; @@ -391,7 +392,7 @@ var DrawingArea = new Lang.Class({ this.currentElement.state = TextState.DRAWING; } - if (this.currentShape == Shapes.POLYGON) { + if (this.currentShape == Shapes.POLYGON || this.currentShape == Shapes.POLYLINE) { this.currentElement.points.push([startX, startY]); this.emit('show-osd', null, _("Press Enter\nto mark vertices"), "", -1); } @@ -463,9 +464,9 @@ var DrawingArea = new Lang.Class({ this.currentElement.transformEllipse(x, y); else if (this.currentElement.shape == Shapes.LINE && (controlPressed || this.currentElement.transform.active)) this.currentElement.transformLine(x, y); - else if (this.currentElement.shape == Shapes.POLYGON && (controlPressed || this.currentElement.transform.active)) + else if ((this.currentElement.shape == Shapes.POLYGON || this.currentElement.shape == Shapes.POLYLINE) && (controlPressed || this.currentElement.transform.active)) this.currentElement.transformPolygon(x, y); - else if (this.currentElement.shape == Shapes.POLYGON) + else if (this.currentElement.shape == Shapes.POLYGON || this.currentElement.shape == Shapes.POLYLINE) this.currentElement.points[this.currentElement.points.length - 1] = [x, y]; else this.currentElement.points[1] = [x, y]; @@ -974,7 +975,7 @@ const DrawingElement = new Lang.Class({ cr.rectangle(points[0][0], points[0][1], points[1][0] - points[0][0], points[1][1] - points[0][1]); this.rotate(cr, - trans.angle, trans.center[0], trans.center[1]); - } else if (shape == Shapes.POLYGON && points.length >= 2) { + } else if ((shape == Shapes.POLYGON || shape == Shapes.POLYLINE) && points.length >= 2) { this.rotate(cr, trans.angle, trans.center[0], trans.center[1]); cr.moveTo(points[0][0], points[0][1]); for (let j = 1; j < points.length; j++) { @@ -1053,6 +1054,17 @@ const DrawingElement = new Lang.Class({ row += ` ${points[i][0]},${points[i][1]}`; row += `"${transAttribute}/>`; + } else if (this.shape == Shapes.POLYLINE && points.length >= 2) { + let transAttribute = ""; + if (this.transform.angle != 0) { + let angle = this.transform.angle * 180 / Math.PI; + transAttribute = ` transform="rotate(${angle}, ${this.transform.center[0]}, ${this.transform.center[1]})"`; + } + row += ``; + } else if (this.shape == Shapes.TEXT && points.length == 2) { let transAttribute = ""; if (this.transform.angle != 0) { @@ -1554,6 +1566,8 @@ const DrawingMenu = new Lang.Class({ // change the display order of shapes if (obj == ShapeNames && i == Shapes.POLYGON) item.menu.moveMenuItem(subItem, 4); + else if (obj == ShapeNames && i == Shapes.POLYLINE) + item.menu.moveMenuItem(subItem, 5); } return GLib.SOURCE_REMOVE; }); diff --git a/extension.js b/extension.js index bc628a8..f8854a8 100644 --- a/extension.js +++ b/extension.js @@ -192,6 +192,7 @@ var AreaManager = new Lang.Class({ 'select-rectangle-shape': () => this.activeArea.selectShape(Draw.Shapes.RECTANGLE), 'select-text-shape': () => this.activeArea.selectShape(Draw.Shapes.TEXT), 'select-polygon-shape': () => this.activeArea.selectShape(Draw.Shapes.POLYGON), + 'select-polyline-shape': () => this.activeArea.selectShape(Draw.Shapes.POLYLINE), 'toggle-font-family': this.activeArea.toggleFontFamily.bind(this.activeArea), 'toggle-font-weight': this.activeArea.toggleFontWeight.bind(this.activeArea), 'toggle-font-style': this.activeArea.toggleFontStyle.bind(this.activeArea), diff --git a/locale/draw-on-your-screen.pot b/locale/draw-on-your-screen.pot index 9863ac1..e4ca8c7 100644 --- a/locale/draw-on-your-screen.pot +++ b/locale/draw-on-your-screen.pot @@ -61,6 +61,9 @@ msgstr "" msgid "Polygon" msgstr "" +msgid "Polyline" +msgstr "" + msgid "Fill" msgstr "" @@ -164,6 +167,9 @@ msgstr "" msgid "Select polygon" msgstr "" +msgid "Select polyline" +msgstr "" + msgid "Select text" msgstr "" diff --git a/schemas/gschemas.compiled b/schemas/gschemas.compiled index ab895c757111c49a03e8bbd59f7659fb51befd82..0f24469927fcef1b6ad543e34f371e63d8c29bd3 100644 GIT binary patch literal 3660 zcmZ`+ZEO@(6djaG`Q8c?TB&@4}pf6Ksqf!%nA)MkKZPK~yc`K(##RStu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