diff --git a/area.js b/area.js index 57c2b68..ea0eebd 100644 --- a/area.js +++ b/area.js @@ -1,5 +1,5 @@ /* jslint esversion: 6 */ -/* exported Tools, DrawingArea */ +/* exported Tool, DrawingArea */ /* * Copyright 2019 Abakkk @@ -53,17 +53,17 @@ const GRID_TILES_HORIZONTAL_NUMBER = 30; const COLOR_PICKER_EXTENSION_UUID = 'color-picker@tuberry'; const UUID = Me.uuid.replace(/@/gi, '_at_').replace(/[^a-z0-9+_-]/gi, '_'); -const { Shapes, TextAlignment, Transformations } = Elements; +const { Shape, TextAlignment, Transformation } = Elements; const { DisplayStrings } = Menu; const FontGenericFamilies = ['Sans-Serif', 'Serif', 'Monospace', 'Cursive', 'Fantasy']; -const Manipulations = { MOVE: 100, RESIZE: 101, MIRROR: 102 }; -var Tools = Object.assign({ +const Manipulation = { MOVE: 100, RESIZE: 101, MIRROR: 102 }; +var Tool = Object.assign({ getNameOf: function(value) { return Object.keys(this).find(key => this[key] == value); } -}, Shapes, Manipulations); -Object.defineProperty(Tools, 'getNameOf', { enumerable: false }); +}, Shape, Manipulation); +Object.defineProperty(Tool, 'getNameOf', { enumerable: false }); // toJSON provides a string suitable for SVG color attribute whereas // toString provides a string suitable for displaying the color name to the user. @@ -150,7 +150,7 @@ var DrawingArea = new Lang.Class({ this.elements = []; this.undoneElements = []; this.currentElement = null; - this.currentTool = Shapes.NONE; + this.currentTool = Shape.NONE; this.currentImage = null; this.currentTextAlignment = Clutter.get_default_text_direction() == Clutter.TextDirection.RTL ? TextAlignment.RIGHT : TextAlignment.LEFT; let fontName = St.Settings && St.Settings.get().font_name || Convenience.getSettings('org.gnome.desktop.interface').get_string('font-name'); @@ -178,7 +178,7 @@ var DrawingArea = new Lang.Class({ get menu() { if (!this._menu) - this._menu = new Menu.DrawingMenu(this, this.monitor, Tools, this.areaManagerUtils); + this._menu = new Menu.DrawingMenu(this, this.monitor, Tool, this.areaManagerUtils); return this._menu; }, @@ -251,7 +251,7 @@ var DrawingArea = new Lang.Class({ get hasManipulationTool() { // No Object.values method in GS 3.24. - return Object.keys(Manipulations).map(key => Manipulations[key]).indexOf(this.currentTool) != -1; + return Object.keys(Manipulation).map(key => Manipulation[key]).indexOf(this.currentTool) != -1; }, // Boolean wrapper for switch menu item. @@ -325,7 +325,7 @@ var DrawingArea = new Lang.Class({ if (this.elements[i].fill && !this.elements[i].isStraightLine) { cr.fillPreserve(); - if (this.elements[i].shape == Shapes.NONE || this.elements[i].shape == Shapes.LINE) + if (this.elements[i].shape == Shape.NONE || this.elements[i].shape == Shape.LINE) cr.closePath(); } @@ -335,7 +335,7 @@ var DrawingArea = new Lang.Class({ if (this.currentElement && this.currentElement.eraser) { this.currentElement.buildCairo(cr, { showTextCursor: this.textHasCursor, - showTextRectangle: this.currentElement.shape != Shapes.TEXT || !this.isWriting, + showTextRectangle: this.currentElement.shape != Shape.TEXT || !this.isWriting, dummyStroke: this.currentElement.fill && this.currentElement.line.lineWidth == 0 }); cr.stroke(); } @@ -346,7 +346,7 @@ var DrawingArea = new Lang.Class({ return; this.currentElement.buildCairo(cr, { showTextCursor: this.textHasCursor, - showTextRectangle: this.currentElement.shape != Shapes.TEXT || !this.isWriting, + showTextRectangle: this.currentElement.shape != Shape.TEXT || !this.isWriting, dummyStroke: this.currentElement.fill && this.currentElement.line.lineWidth == 0 }); cr.stroke(); }, @@ -379,11 +379,11 @@ var DrawingArea = new Lang.Class({ }, _getHasImageBack: function() { - return this.elements.some(element => element.shape == Shapes.IMAGE); + return this.elements.some(element => element.shape == Shape.IMAGE); }, _getHasImageFore: function() { - return this.currentElement && this.currentElement.shape == Shapes.IMAGE || false; + return this.currentElement && this.currentElement.shape == Shape.IMAGE || false; }, _redisplay: function() { @@ -411,7 +411,7 @@ var DrawingArea = new Lang.Class({ let controlPressed = event.has_control_modifier(); let shiftPressed = event.has_shift_modifier(); - if (this.currentElement && this.currentElement.shape == Shapes.TEXT && this.isWriting) + if (this.currentElement && this.currentElement.shape == Shape.TEXT && this.isWriting) // finish writing this._stopWriting(); @@ -471,7 +471,7 @@ var DrawingArea = new Lang.Class({ }, _onKeyPressed: function(actor, event) { - if (this.currentElement && this.currentElement.shape == Shapes.LINE && + if (this.currentElement && this.currentElement.shape == Shape.LINE && (event.get_key_symbol() == Clutter.KEY_Return || event.get_key_symbol() == Clutter.KEY_KP_Enter || event.get_key_symbol() == Clutter.KEY_Control_L)) { @@ -485,7 +485,7 @@ var DrawingArea = new Lang.Class({ this._redisplay(); return Clutter.EVENT_STOP; } else if (this.currentElement && - (this.currentElement.shape == Shapes.POLYGON || this.currentElement.shape == Shapes.POLYLINE) && + (this.currentElement.shape == Shape.POLYGON || this.currentElement.shape == Shape.POLYLINE) && (event.get_key_symbol() == Clutter.KEY_Return || event.get_key_symbol() == Clutter.KEY_KP_Enter)) { this.currentElement.addPoint(); @@ -560,7 +560,7 @@ var DrawingArea = new Lang.Class({ if (!success) return; - if (this.currentTool == Manipulations.MIRROR) { + if (this.currentTool == Manipulation.MIRROR) { this.grabbedElementLocked = !this.grabbedElementLocked; if (this.grabbedElementLocked) { this.updatePointerCursor(); @@ -591,12 +591,12 @@ var DrawingArea = new Lang.Class({ let undoable = !duplicate; - if (this.currentTool == Manipulations.MOVE) - this.grabbedElement.startTransformation(startX, startY, controlPressed ? Transformations.ROTATION : Transformations.TRANSLATION, undoable); - else if (this.currentTool == Manipulations.RESIZE) - this.grabbedElement.startTransformation(startX, startY, controlPressed ? Transformations.STRETCH : Transformations.SCALE_PRESERVE, undoable); - else if (this.currentTool == Manipulations.MIRROR) { - this.grabbedElement.startTransformation(startX, startY, controlPressed ? Transformations.INVERSION : Transformations.REFLECTION, undoable); + if (this.currentTool == Manipulation.MOVE) + this.grabbedElement.startTransformation(startX, startY, controlPressed ? Transformation.ROTATION : Transformation.TRANSLATION, undoable); + else if (this.currentTool == Manipulation.RESIZE) + this.grabbedElement.startTransformation(startX, startY, controlPressed ? Transformation.STRETCH : Transformation.SCALE_PRESERVE, undoable); + else if (this.currentTool == Manipulation.MIRROR) { + this.grabbedElement.startTransformation(startX, startY, controlPressed ? Transformation.INVERSION : Transformation.REFLECTION, undoable); this._redisplay(); } @@ -616,28 +616,28 @@ var DrawingArea = new Lang.Class({ _updateTransforming: function(x, y, controlPressed) { let undoable = this.grabbedElement.lastTransformation.undoable || false; - if (controlPressed && this.grabbedElement.lastTransformation.type == Transformations.TRANSLATION) { + if (controlPressed && this.grabbedElement.lastTransformation.type == Transformation.TRANSLATION) { this.grabbedElement.stopTransformation(); - this.grabbedElement.startTransformation(x, y, Transformations.ROTATION, undoable); - } else if (!controlPressed && this.grabbedElement.lastTransformation.type == Transformations.ROTATION) { + this.grabbedElement.startTransformation(x, y, Transformation.ROTATION, undoable); + } else if (!controlPressed && this.grabbedElement.lastTransformation.type == Transformation.ROTATION) { this.grabbedElement.stopTransformation(); - this.grabbedElement.startTransformation(x, y, Transformations.TRANSLATION, undoable); + this.grabbedElement.startTransformation(x, y, Transformation.TRANSLATION, undoable); } - if (controlPressed && this.grabbedElement.lastTransformation.type == Transformations.SCALE_PRESERVE) { + if (controlPressed && this.grabbedElement.lastTransformation.type == Transformation.SCALE_PRESERVE) { this.grabbedElement.stopTransformation(); - this.grabbedElement.startTransformation(x, y, Transformations.STRETCH, undoable); - } else if (!controlPressed && this.grabbedElement.lastTransformation.type == Transformations.STRETCH) { + this.grabbedElement.startTransformation(x, y, Transformation.STRETCH, undoable); + } else if (!controlPressed && this.grabbedElement.lastTransformation.type == Transformation.STRETCH) { this.grabbedElement.stopTransformation(); - this.grabbedElement.startTransformation(x, y, Transformations.SCALE_PRESERVE, undoable); + this.grabbedElement.startTransformation(x, y, Transformation.SCALE_PRESERVE, undoable); } - if (controlPressed && this.grabbedElement.lastTransformation.type == Transformations.REFLECTION) { + if (controlPressed && this.grabbedElement.lastTransformation.type == Transformation.REFLECTION) { this.grabbedElement.transformations.pop(); - this.grabbedElement.startTransformation(x, y, Transformations.INVERSION, undoable); - } else if (!controlPressed && this.grabbedElement.lastTransformation.type == Transformations.INVERSION) { + this.grabbedElement.startTransformation(x, y, Transformation.INVERSION, undoable); + } else if (!controlPressed && this.grabbedElement.lastTransformation.type == Transformation.INVERSION) { this.grabbedElement.transformations.pop(); - this.grabbedElement.startTransformation(x, y, Transformations.REFLECTION, undoable); + this.grabbedElement.startTransformation(x, y, Transformation.REFLECTION, undoable); } this.grabbedElement.updateTransformation(x, y); @@ -669,7 +669,7 @@ var DrawingArea = new Lang.Class({ this._stopDrawing(); }); - if (this.currentTool == Shapes.TEXT) { + if (this.currentTool == Shape.TEXT) { this.currentElement = new Elements.DrawingElement({ shape: this.currentTool, color: this.currentColor, @@ -680,7 +680,7 @@ var DrawingArea = new Lang.Class({ textAlignment: this.currentTextAlignment, points: [] }); - } else if (this.currentTool == Shapes.IMAGE) { + } else if (this.currentTool == Shape.IMAGE) { this.currentElement = new Elements.DrawingElement({ shape: this.currentTool, color: this.currentColor, @@ -703,8 +703,8 @@ var DrawingArea = new Lang.Class({ this.currentElement.startDrawing(startX, startY); - if (this.currentTool == Shapes.POLYGON || this.currentTool == Shapes.POLYLINE) { - let icon = Files.Icons[this.currentTool == Shapes.POLYGON ? 'TOOL_POLYGON' : 'TOOL_POLYLINE']; + if (this.currentTool == Shape.POLYGON || this.currentTool == Shape.POLYLINE) { + let icon = Files.Icons[this.currentTool == Shape.POLYGON ? 'TOOL_POLYGON' : 'TOOL_POLYLINE']; // Translators: %s is a key label this.emit('show-osd', icon, _("Press %s to mark vertices") .format(Gtk.accelerator_get_label(Clutter.KEY_Return, 0)), "", -1, true); @@ -727,7 +727,7 @@ var DrawingArea = new Lang.Class({ let controlPressed = event.has_control_modifier(); this._updateDrawing(x, y, controlPressed); - if (this.currentTool == Shapes.NONE) { + if (this.currentTool == Shape.NONE) { let device = event.get_device(); let sequence = event.get_event_sequence(); @@ -781,14 +781,14 @@ var DrawingArea = new Lang.Class({ } // skip when a polygon has not at least 3 points - if (this.currentElement && this.currentElement.shape == Shapes.POLYGON && this.currentElement.points.length < 3) + if (this.currentElement && this.currentElement.shape == Shape.POLYGON && this.currentElement.points.length < 3) this.currentElement = null; if (this.currentElement) this.currentElement.stopDrawing(); if (this.currentElement && this.currentElement.points.length >= 2) { - if (this.currentElement.shape == Shapes.TEXT && !this.isWriting) { + if (this.currentElement.shape == Shape.TEXT && !this.isWriting) { this._startWriting(); return; } @@ -891,15 +891,15 @@ var DrawingArea = new Lang.Class({ }, updatePointerCursor: function(controlPressed) { - if (this.currentTool == Manipulations.MIRROR && this.grabbedElementLocked) + if (this.currentTool == Manipulation.MIRROR && this.grabbedElementLocked) this.setPointerCursor('CROSSHAIR'); else if (this.hasManipulationTool) this.setPointerCursor(this.grabbedElement ? 'MOVE_OR_RESIZE_WINDOW' : 'DEFAULT'); - else if (this.currentElement && this.currentElement.shape == Shapes.TEXT && this.isWriting) + else if (this.currentElement && this.currentElement.shape == Shape.TEXT && this.isWriting) this.setPointerCursor('IBEAM'); else if (!this.currentElement) - this.setPointerCursor(this.currentTool == Shapes.NONE ? 'POINTING_HAND' : 'CROSSHAIR'); - else if (this.currentElement.shape != Shapes.NONE && controlPressed) + this.setPointerCursor(this.currentTool == Shape.NONE ? 'POINTING_HAND' : 'CROSSHAIR'); + else if (this.currentElement.shape != Shape.NONE && controlPressed) this.setPointerCursor('MOVE_OR_RESIZE_WINDOW'); }, @@ -988,7 +988,7 @@ var DrawingArea = new Lang.Class({ }, smoothLastElement: function() { - if (this.elements.length > 0 && this.elements[this.elements.length - 1].shape == Shapes.NONE) { + if (this.elements.length > 0 && this.elements[this.elements.length - 1].shape == Shape.NONE) { this.elements[this.elements.length - 1].smoothAll(); this._redisplay(); } @@ -1069,7 +1069,7 @@ var DrawingArea = new Lang.Class({ selectTool: function(tool) { this.currentTool = tool; - this.emit('show-osd', Files.Icons[`TOOL_${Tools.getNameOf(tool)}`] || null, DisplayStrings.Tool[tool], "", -1, false); + this.emit('show-osd', Files.Icons[`TOOL_${Tool.getNameOf(tool)}`] || null, DisplayStrings.Tool[tool], "", -1, false); this.updatePointerCursor(); }, @@ -1169,7 +1169,7 @@ var DrawingArea = new Lang.Class({ pasteImageFiles: function() { Files.Images.addImagesFromClipboard(lastImage => { this.currentImage = lastImage; - this.currentTool = Shapes.IMAGE; + this.currentTool = Shape.IMAGE; this.updatePointerCursor(); this.emit('show-osd', this.currentImage.gicon, this.currentImage.toString(), "", -1, false); }); @@ -1369,7 +1369,7 @@ var DrawingArea = new Lang.Class({ this._stopAll(); let prefixes = 'xmlns="http://www.w3.org/2000/svg"'; - if (this.elements.some(element => element.shape == Shapes.IMAGE)) + if (this.elements.some(element => element.shape == Shape.IMAGE)) prefixes += ' xmlns:xlink="http://www.w3.org/1999/xlink"'; let content = ``; let backgroundColorString = this.hasBackground ? String(this.areaBackgroundColor) : 'transparent'; diff --git a/elements.js b/elements.js index 4ed73e5..c1249a8 100644 --- a/elements.js +++ b/elements.js @@ -1,5 +1,5 @@ /* jslint esversion: 6 */ -/* exported Shapes, Transformations, getAllFontFamilies, DrawingElement */ +/* exported Shape, TextAlignment, Transformation, getAllFontFamilies, DrawingElement */ /* * Copyright 2019 Abakkk @@ -30,9 +30,9 @@ const PangoCairo = imports.gi.PangoCairo; const Me = imports.misc.extensionUtils.getCurrentExtension(); const UUID = Me.uuid.replace(/@/gi, '_at_').replace(/[^a-z0-9+_-]/gi, '_'); -var Shapes = { NONE: 0, LINE: 1, ELLIPSE: 2, RECTANGLE: 3, TEXT: 4, POLYGON: 5, POLYLINE: 6, IMAGE: 7 }; +var Shape = { NONE: 0, LINE: 1, ELLIPSE: 2, RECTANGLE: 3, TEXT: 4, POLYGON: 5, POLYLINE: 6, IMAGE: 7 }; var TextAlignment = { LEFT: 0, CENTER: 1, RIGHT: 2 }; -var Transformations = { TRANSLATION: 0, ROTATION: 1, SCALE_PRESERVE: 2, STRETCH: 3, REFLECTION: 4, INVERSION: 5, SMOOTH: 100 }; +var Transformation = { TRANSLATION: 0, ROTATION: 1, SCALE_PRESERVE: 2, STRETCH: 3, REFLECTION: 4, INVERSION: 5, SMOOTH: 100 }; var getAllFontFamilies = function() { return PangoCairo.font_map_get_default().list_families().map(fontFamily => fontFamily.get_name()).sort((a,b) => a.localeCompare(b)); @@ -66,8 +66,8 @@ const MIN_DRAWING_SIZE = 3; // px const MIN_INTERMEDIATE_POINT_DISTANCE = 1; // px, the higher it is, the fewer points there will be var DrawingElement = function(params) { - return params.shape == Shapes.TEXT ? new TextElement(params) : - params.shape == Shapes.IMAGE ? new ImageElement(params) : + return params.shape == Shape.TEXT ? new TextElement(params) : + params.shape == Shape.IMAGE ? new ImageElement(params) : new _DrawingElement(params); }; @@ -104,9 +104,9 @@ const _DrawingElement = new Lang.Class({ if (params.transform && params.transform.center) { let angle = (params.transform.angle || 0) + (params.transform.startAngle || 0); if (angle) - this.transformations.push({ type: Transformations.ROTATION, angle: angle }); + this.transformations.push({ type: Transformation.ROTATION, angle: angle }); } - if (params.shape == Shapes.ELLIPSE && params.transform && params.transform.ratio && params.transform.ratio != 1 && params.points.length >= 2) { + if (params.shape == Shape.ELLIPSE && params.transform && params.transform.ratio && params.transform.ratio != 1 && params.points.length >= 2) { let [ratio, p0, p1] = [params.transform.ratio, params.points[0], params.points[1]]; // Add a fake point that will give the right ellipse ratio when building the element. this.points.push([ratio * (p1[0] - p0[0]) + p0[0], ratio * (p1[1] - p0[1]) + p0[1]]); @@ -129,7 +129,7 @@ const _DrawingElement = new Lang.Class({ fill: this.fill, fillRule: this.fillRule, eraser: this.eraser, - transformations: this.transformations.filter(transformation => transformation.type != Transformations.SMOOTH) + transformations: this.transformations.filter(transformation => transformation.type != Transformation.SMOOTH) .map(transformation => Object.assign({}, transformation, { undoable: undefined })), points: this.points.map((point) => [Math.round(point[0]*100)/100, Math.round(point[1]*100)/100]) }; @@ -142,7 +142,7 @@ const _DrawingElement = new Lang.Class({ if (this.showSymmetryElement) { let transformation = this.lastTransformation; setDummyStroke(cr); - if (transformation.type == Transformations.REFLECTION) { + if (transformation.type == Transformation.REFLECTION) { cr.moveTo(transformation.startX, transformation.startY); cr.lineTo(transformation.endX, transformation.endY); } else { @@ -177,21 +177,21 @@ const _DrawingElement = new Lang.Class({ } this.transformations.slice(0).reverse().forEach(transformation => { - if (transformation.type == Transformations.TRANSLATION) { + if (transformation.type == Transformation.TRANSLATION) { cr.translate(transformation.slideX, transformation.slideY); - } else if (transformation.type == Transformations.ROTATION) { + } else if (transformation.type == Transformation.ROTATION) { let center = this._getTransformedCenter(transformation); cr.translate(center[0], center[1]); cr.rotate(transformation.angle); cr.translate(-center[0], -center[1]); - } else if (transformation.type == Transformations.SCALE_PRESERVE || transformation.type == Transformations.STRETCH) { + } else if (transformation.type == Transformation.SCALE_PRESERVE || transformation.type == Transformation.STRETCH) { let center = this._getTransformedCenter(transformation); cr.translate(center[0], center[1]); cr.rotate(transformation.angle); cr.scale(transformation.scaleX, transformation.scaleY); cr.rotate(-transformation.angle); cr.translate(-center[0], -center[1]); - } else if (transformation.type == Transformations.REFLECTION || transformation.type == Transformations.INVERSION) { + } else if (transformation.type == Transformation.REFLECTION || transformation.type == Transformation.INVERSION) { cr.translate(transformation.slideX, transformation.slideY); cr.rotate(transformation.angle); cr.scale(transformation.scaleX, transformation.scaleY); @@ -208,21 +208,21 @@ const _DrawingElement = new Lang.Class({ _drawCairo: function(cr, params) { let [points, shape] = [this.points, this.shape]; - if (shape == Shapes.LINE && points.length == 3) { + if (shape == Shape.LINE && points.length == 3) { cr.moveTo(points[0][0], points[0][1]); cr.curveTo(points[0][0], points[0][1], points[1][0], points[1][1], points[2][0], points[2][1]); - } else if (shape == Shapes.LINE && points.length == 4) { + } else if (shape == Shape.LINE && points.length == 4) { cr.moveTo(points[0][0], points[0][1]); cr.curveTo(points[1][0], points[1][1], points[2][0], points[2][1], points[3][0], points[3][1]); - } else if (shape == Shapes.NONE || shape == Shapes.LINE) { + } else if (shape == Shape.NONE || shape == Shape.LINE) { cr.moveTo(points[0][0], points[0][1]); for (let j = 1; j < points.length; j++) { cr.lineTo(points[j][0], points[j][1]); } - } else if (shape == Shapes.ELLIPSE && points.length >= 2) { + } else if (shape == Shape.ELLIPSE && points.length >= 2) { let radius = Math.hypot(points[1][0] - points[0][0], points[1][1] - points[0][1]); let ratio = 1; @@ -238,15 +238,15 @@ const _DrawingElement = new Lang.Class({ } else cr.arc(points[0][0], points[0][1], radius, 0, 2 * Math.PI); - } else if (shape == Shapes.RECTANGLE && points.length == 2) { + } else if (shape == Shape.RECTANGLE && points.length == 2) { cr.rectangle(points[0][0], points[0][1], points[1][0] - points[0][0], points[1][1] - points[0][1]); - } else if ((shape == Shapes.POLYGON || shape == Shapes.POLYLINE) && points.length >= 2) { + } else if ((shape == Shape.POLYGON || shape == Shape.POLYLINE) && points.length >= 2) { cr.moveTo(points[0][0], points[0][1]); for (let j = 1; j < points.length; j++) { cr.lineTo(points[j][0], points[j][1]); } - if (shape == Shapes.POLYGON) + if (shape == Shape.POLYGON) cr.closePath(); } @@ -268,19 +268,19 @@ const _DrawingElement = new Lang.Class({ this.transformations.slice(0).reverse().forEach(transformation => { let center = this._getTransformedCenter(transformation); - if (transformation.type == Transformations.TRANSLATION) { + if (transformation.type == Transformation.TRANSLATION) { transforms.push(['translate', transformation.slideX, transformation.slideY]); - } else if (transformation.type == Transformations.ROTATION) { + } else if (transformation.type == Transformation.ROTATION) { transforms.push(['translate', center[0], center[1]]); transforms.push(['rotate', transformation.angle * RADIAN]); transforms.push(['translate', -center[0], -center[1]]); - } else if (transformation.type == Transformations.SCALE_PRESERVE || transformation.type == Transformations.STRETCH) { + } else if (transformation.type == Transformation.SCALE_PRESERVE || transformation.type == Transformation.STRETCH) { transforms.push(['translate', center[0], center[1]]); transforms.push(['rotate', transformation.angle * RADIAN]); transforms.push(['scale', transformation.scaleX, transformation.scaleY]); transforms.push(['rotate', -transformation.angle * RADIAN]); transforms.push(['translate', -center[0], -center[1]]); - } else if (transformation.type == Transformations.REFLECTION || transformation.type == Transformations.INVERSION) { + } else if (transformation.type == Transformation.REFLECTION || transformation.type == Transformation.INVERSION) { transforms.push(['translate', transformation.slideX, transformation.slideY]); transforms.push(['rotate', transformation.angle * RADIAN]); transforms.push(['scale', transformation.scaleX, transformation.scaleY]); @@ -348,45 +348,45 @@ const _DrawingElement = new Lang.Class({ attributes += ` stroke-dasharray="${this.dash.array[0]} ${this.dash.array[1]}" stroke-dashoffset="${this.dash.offset}"`; } - if (this.shape == Shapes.LINE && points.length == 4) { + if (this.shape == Shape.LINE && points.length == 4) { row += ``; - } else if (this.shape == Shapes.LINE && points.length == 3) { + } else if (this.shape == Shape.LINE && points.length == 3) { row += ``; - } else if (this.shape == Shapes.LINE) { + } else if (this.shape == Shape.LINE) { row += ``; - } else if (this.shape == Shapes.NONE) { + } else if (this.shape == Shape.NONE) { row += ``; - } else if (this.shape == Shapes.ELLIPSE && points.length == 3) { + } else if (this.shape == Shape.ELLIPSE && points.length == 3) { let ry = Math.hypot(points[1][0] - points[0][0], points[1][1] - points[0][1]); let rx = Math.hypot(points[2][0] - points[0][0], points[2][1] - points[0][1]); row += ``; - } else if (this.shape == Shapes.ELLIPSE && points.length == 2) { + } else if (this.shape == Shape.ELLIPSE && points.length == 2) { let r = Math.hypot(points[1][0] - points[0][0], points[1][1] - points[0][1]); row += ``; - } else if (this.shape == Shapes.RECTANGLE && points.length == 2) { + } else if (this.shape == Shape.RECTANGLE && points.length == 2) { row += ``; - } else if (this.shape == Shapes.POLYGON && points.length >= 3) { + } else if (this.shape == Shape.POLYGON && points.length >= 3) { row += ``; - } else if (this.shape == Shapes.POLYLINE && points.length >= 2) { + } else if (this.shape == Shape.POLYLINE && points.length >= 2) { row += ` 0; this.redoButton.child.reactive = this.area.undoneElements.length > 0 || (this.area.elements.length && this.area.elements[this.area.elements.length - 1].canUndo); this.eraseButton.child.reactive = this.area.elements.length > 0; - this.smoothButton.child.reactive = this.area.elements.length > 0 && this.area.elements[this.area.elements.length - 1].shape == this.drawingTools.NONE; + this.smoothButton.child.reactive = this.area.elements.length > 0 && this.area.elements[this.area.elements.length - 1].shape == this.DrawingTool.NONE; this.saveButton.child.reactive = this.area.elements.length > 0; this.svgButton.child.reactive = this.area.elements.length > 0; this.saveDrawingSubMenuItem.setSensitive(this.area.elements.length > 0); }, _updateSectionVisibility: function() { - let [isText, isImage] = [this.area.currentTool == this.drawingTools.TEXT, this.area.currentTool == this.drawingTools.IMAGE]; + let [isText, isImage] = [this.area.currentTool == this.DrawingTool.TEXT, this.area.currentTool == this.DrawingTool.IMAGE]; this.lineSection.actor.visible = !isText && !isImage; this.fontSection.actor.visible = isText; this.imageSection.actor.visible = isImage; @@ -425,7 +425,7 @@ var DrawingMenu = new Lang.Class({ let item = new PopupMenu.PopupSubMenuMenuItem('', true); item.update = () => { item.label.set_text(DisplayStrings.Tool[this.area.currentTool]); - let toolName = this.drawingTools.getNameOf(this.area.currentTool); + let toolName = this.DrawingTool.getNameOf(this.area.currentTool); item.icon.set_gicon(Files.Icons[`TOOL_${toolName}`]); }; item.update(); @@ -435,7 +435,7 @@ var DrawingMenu = new Lang.Class({ GLib.idle_add(GLib.PRIORITY_DEFAULT_IDLE, () => { Object.keys(DisplayStrings.Tool).forEach(key => { let text = DisplayStrings.Tool[key]; - let toolName = this.drawingTools.getNameOf(key); + let toolName = this.DrawingTool.getNameOf(key); let subItemIcon = Files.Icons[`TOOL_${toolName}`]; let subItem = item.menu.addAction(text, () => { this.area.currentTool = Number(key); @@ -447,10 +447,10 @@ var DrawingMenu = new Lang.Class({ getActor(subItem).connect('key-focus-in', updateSubMenuAdjustment); // change the display order of tools - if (key == this.drawingTools.POLYGON) - item.menu.moveMenuItem(subItem, Number(this.drawingTools.TEXT)); - else if (key == this.drawingTools.POLYLINE) - item.menu.moveMenuItem(subItem, Number(this.drawingTools.TEXT) + 1); + if (key == this.DrawingTool.POLYGON) + item.menu.moveMenuItem(subItem, Number(this.DrawingTool.TEXT)); + else if (key == this.DrawingTool.POLYLINE) + item.menu.moveMenuItem(subItem, Number(this.DrawingTool.TEXT) + 1); }); return GLib.SOURCE_REMOVE; }); @@ -680,7 +680,7 @@ var DrawingMenu = new Lang.Class({ let insertCallback = () => { this.area.currentImage = json.image; this.imageItem.update(); - this.area.currentTool = this.drawingTools.IMAGE; + this.area.currentTool = this.DrawingTool.IMAGE; this.toolItem.update(); this._updateSectionVisibility(); };