draw-to-elements 5
This commit is contained in:
parent
78be404571
commit
ca96e76d12
21
draw.js
21
draw.js
|
|
@ -45,28 +45,11 @@ const CAIRO_DEBUG_EXTENDS = false;
|
||||||
const SVG_DEBUG_EXTENDS = false;
|
const SVG_DEBUG_EXTENDS = false;
|
||||||
const TEXT_CURSOR_TIME = 600; // ms
|
const TEXT_CURSOR_TIME = 600; // ms
|
||||||
|
|
||||||
const reverseEnumeration = function(obj) {
|
const { Shapes, Manipulations, Transformations, LineCapNames, LineJoinNames, FillRuleNames,
|
||||||
let reversed = {};
|
FontWeightNames, FontStyleNames, FontStretchNames, FontVariantNames } = Elements;
|
||||||
Object.keys(obj).forEach(key => {
|
|
||||||
reversed[obj[key]] = key.slice(0,1) + key.slice(1).toLowerCase().replace('_', '-');
|
|
||||||
});
|
|
||||||
return reversed;
|
|
||||||
};
|
|
||||||
|
|
||||||
const Shapes = { NONE: 0, LINE: 1, ELLIPSE: 2, RECTANGLE: 3, TEXT: 4, POLYGON: 5, POLYLINE: 6 };
|
|
||||||
const Manipulations = { MOVE: 100, RESIZE: 101, MIRROR: 102 };
|
|
||||||
const Transformations = { TRANSLATION: 0, ROTATION: 1, SCALE_PRESERVE: 2, STRETCH: 3, REFLECTION: 4, INVERSION: 5 };
|
|
||||||
var Tools = Object.assign({}, Shapes, Manipulations);
|
var Tools = Object.assign({}, Shapes, Manipulations);
|
||||||
var ToolNames = { 0: "Free drawing", 1: "Line", 2: "Ellipse", 3: "Rectangle", 4: "Text", 5: "Polygon", 6: "Polyline", 100: "Move", 101: "Resize", 102: "Mirror" };
|
var ToolNames = { 0: "Free drawing", 1: "Line", 2: "Ellipse", 3: "Rectangle", 4: "Text", 5: "Polygon", 6: "Polyline", 100: "Move", 101: "Resize", 102: "Mirror" };
|
||||||
var LineCapNames = Object.assign(reverseEnumeration(Cairo.LineCap), { 2: 'Square' });
|
|
||||||
var LineJoinNames = reverseEnumeration(Cairo.LineJoin);
|
|
||||||
var FillRuleNames = { 0: 'Nonzero', 1: 'Evenodd' };
|
|
||||||
var FontGenericNames = { 0: 'Theme', 1: 'Sans-Serif', 2: 'Serif', 3: 'Monospace', 4: 'Cursive', 5: 'Fantasy' };
|
var FontGenericNames = { 0: 'Theme', 1: 'Sans-Serif', 2: 'Serif', 3: 'Monospace', 4: 'Cursive', 5: 'Fantasy' };
|
||||||
var FontWeightNames = Object.assign(reverseEnumeration(Pango.Weight), { 200: "Ultra-light", 350: "Semi-light", 600: "Semi-bold", 800: "Ultra-bold" });
|
|
||||||
delete FontWeightNames[Pango.Weight.ULTRAHEAVY];
|
|
||||||
var FontStyleNames = reverseEnumeration(Pango.Style);
|
|
||||||
var FontStretchNames = reverseEnumeration(Pango.Stretch);
|
|
||||||
var FontVariantNames = reverseEnumeration(Pango.Variant);
|
|
||||||
|
|
||||||
var getDateString = function() {
|
var getDateString = function() {
|
||||||
let date = GLib.DateTime.new_now_local();
|
let date = GLib.DateTime.new_now_local();
|
||||||
|
|
|
||||||
15
elements.js
15
elements.js
|
|
@ -30,8 +30,6 @@ const ExtensionUtils = imports.misc.extensionUtils;
|
||||||
const Me = ExtensionUtils.getCurrentExtension();
|
const Me = ExtensionUtils.getCurrentExtension();
|
||||||
const _ = imports.gettext.domain(Me.metadata['gettext-domain']).gettext;
|
const _ = imports.gettext.domain(Me.metadata['gettext-domain']).gettext;
|
||||||
|
|
||||||
const SVG_DEBUG_SUPERPOSES_CAIRO = false;
|
|
||||||
|
|
||||||
const reverseEnumeration = function(obj) {
|
const reverseEnumeration = function(obj) {
|
||||||
let reversed = {};
|
let reversed = {};
|
||||||
Object.keys(obj).forEach(key => {
|
Object.keys(obj).forEach(key => {
|
||||||
|
|
@ -40,21 +38,20 @@ const reverseEnumeration = function(obj) {
|
||||||
return reversed;
|
return reversed;
|
||||||
};
|
};
|
||||||
|
|
||||||
const Shapes = { NONE: 0, LINE: 1, ELLIPSE: 2, RECTANGLE: 3, TEXT: 4, POLYGON: 5, POLYLINE: 6 };
|
var Shapes = { NONE: 0, LINE: 1, ELLIPSE: 2, RECTANGLE: 3, TEXT: 4, POLYGON: 5, POLYLINE: 6 };
|
||||||
const Manipulations = { MOVE: 100, RESIZE: 101, MIRROR: 102 };
|
var Manipulations = { MOVE: 100, RESIZE: 101, MIRROR: 102 };
|
||||||
const Transformations = { TRANSLATION: 0, ROTATION: 1, SCALE_PRESERVE: 2, STRETCH: 3, REFLECTION: 4, INVERSION: 5 };
|
var Transformations = { TRANSLATION: 0, ROTATION: 1, SCALE_PRESERVE: 2, STRETCH: 3, REFLECTION: 4, INVERSION: 5 };
|
||||||
var Tools = Object.assign({}, Shapes, Manipulations);
|
|
||||||
var ToolNames = { 0: "Free drawing", 1: "Line", 2: "Ellipse", 3: "Rectangle", 4: "Text", 5: "Polygon", 6: "Polyline", 100: "Move", 101: "Resize", 102: "Mirror" };
|
|
||||||
var LineCapNames = Object.assign(reverseEnumeration(Cairo.LineCap), { 2: 'Square' });
|
var LineCapNames = Object.assign(reverseEnumeration(Cairo.LineCap), { 2: 'Square' });
|
||||||
var LineJoinNames = reverseEnumeration(Cairo.LineJoin);
|
var LineJoinNames = reverseEnumeration(Cairo.LineJoin);
|
||||||
var FillRuleNames = { 0: 'Nonzero', 1: 'Evenodd' };
|
var FillRuleNames = { 0: 'Nonzero', 1: 'Evenodd' };
|
||||||
var FontGenericNames = { 0: 'Theme', 1: 'Sans-Serif', 2: 'Serif', 3: 'Monospace', 4: 'Cursive', 5: 'Fantasy' };
|
|
||||||
var FontWeightNames = Object.assign(reverseEnumeration(Pango.Weight), { 200: "Ultra-light", 350: "Semi-light", 600: "Semi-bold", 800: "Ultra-bold" });
|
var FontWeightNames = Object.assign(reverseEnumeration(Pango.Weight), { 200: "Ultra-light", 350: "Semi-light", 600: "Semi-bold", 800: "Ultra-bold" });
|
||||||
delete FontWeightNames[Pango.Weight.ULTRAHEAVY];
|
delete FontWeightNames[Pango.Weight.ULTRAHEAVY];
|
||||||
var FontStyleNames = reverseEnumeration(Pango.Style);
|
var FontStyleNames = reverseEnumeration(Pango.Style);
|
||||||
var FontStretchNames = reverseEnumeration(Pango.Stretch);
|
var FontStretchNames = reverseEnumeration(Pango.Stretch);
|
||||||
var FontVariantNames = reverseEnumeration(Pango.Variant);
|
var FontVariantNames = reverseEnumeration(Pango.Variant);
|
||||||
|
|
||||||
|
|
||||||
|
const SVG_DEBUG_SUPERPOSES_CAIRO = false;
|
||||||
const RADIAN = 180 / Math.PI; // degree
|
const RADIAN = 180 / Math.PI; // degree
|
||||||
const INVERSION_CIRCLE_RADIUS = 12; // px
|
const INVERSION_CIRCLE_RADIUS = 12; // px
|
||||||
const REFLECTION_TOLERANCE = 5; // px, to select vertical and horizontal directions
|
const REFLECTION_TOLERANCE = 5; // px, to select vertical and horizontal directions
|
||||||
|
|
@ -67,7 +64,7 @@ const MIN_DRAWING_SIZE = 3; // px
|
||||||
// DrawingElement represents a "brushstroke".
|
// DrawingElement represents a "brushstroke".
|
||||||
// It can be converted into a cairo path as well as a svg element.
|
// It can be converted into a cairo path as well as a svg element.
|
||||||
// See DrawingArea._startDrawing() to know its params.
|
// See DrawingArea._startDrawing() to know its params.
|
||||||
const DrawingElement = new Lang.Class({
|
var DrawingElement = new Lang.Class({
|
||||||
Name: 'DrawOnYourScreenDrawingElement',
|
Name: 'DrawOnYourScreenDrawingElement',
|
||||||
|
|
||||||
_init: function(params) {
|
_init: function(params) {
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ const ExtensionUtils = imports.misc.extensionUtils;
|
||||||
const Me = ExtensionUtils.getCurrentExtension();
|
const Me = ExtensionUtils.getCurrentExtension();
|
||||||
const Convenience = ExtensionUtils.getSettings && ExtensionUtils.initTranslations ? ExtensionUtils : Me.imports.convenience;
|
const Convenience = ExtensionUtils.getSettings && ExtensionUtils.initTranslations ? ExtensionUtils : Me.imports.convenience;
|
||||||
const Draw = Me.imports.draw;
|
const Draw = Me.imports.draw;
|
||||||
const Osd = Me.imports.osd;
|
const Helper = Me.imports.helper;
|
||||||
const _ = imports.gettext.domain(Me.metadata['gettext-domain']).gettext;
|
const _ = imports.gettext.domain(Me.metadata['gettext-domain']).gettext;
|
||||||
|
|
||||||
const GS_VERSION = Config.PACKAGE_VERSION;
|
const GS_VERSION = Config.PACKAGE_VERSION;
|
||||||
|
|
@ -155,7 +155,7 @@ var AreaManager = new Lang.Class({
|
||||||
for (let i = 0; i < this.monitors.length; i++) {
|
for (let i = 0; i < this.monitors.length; i++) {
|
||||||
let monitor = this.monitors[i];
|
let monitor = this.monitors[i];
|
||||||
let container = new St.Widget({ name: 'drawOnYourSreenContainer' + i });
|
let container = new St.Widget({ name: 'drawOnYourSreenContainer' + i });
|
||||||
let helper = new Osd.DrawingHelper({ name: 'drawOnYourSreenHelper' + i }, monitor);
|
let helper = new Helper.DrawingHelper({ name: 'drawOnYourSreenHelper' + i }, monitor);
|
||||||
let loadPersistent = i == Main.layoutManager.primaryIndex && this.settings.get_boolean('persistent-drawing');
|
let loadPersistent = i == Main.layoutManager.primaryIndex && this.settings.get_boolean('persistent-drawing');
|
||||||
let area = new Draw.DrawingArea({ name: 'drawOnYourSreenArea' + i }, monitor, helper, loadPersistent);
|
let area = new Draw.DrawingArea({ name: 'drawOnYourSreenArea' + i }, monitor, helper, loadPersistent);
|
||||||
container.add_child(area);
|
container.add_child(area);
|
||||||
|
|
|
||||||
9
menu.js
9
menu.js
|
|
@ -37,6 +37,7 @@ const Slider = imports.ui.slider;
|
||||||
const ExtensionUtils = imports.misc.extensionUtils;
|
const ExtensionUtils = imports.misc.extensionUtils;
|
||||||
const Me = ExtensionUtils.getCurrentExtension();
|
const Me = ExtensionUtils.getCurrentExtension();
|
||||||
const Draw = Me.imports.draw;
|
const Draw = Me.imports.draw;
|
||||||
|
const Elements = Me.imports.elements;
|
||||||
const Extension = Me.imports.extension;
|
const Extension = Me.imports.extension;
|
||||||
const _ = imports.gettext.domain(Me.metadata['gettext-domain']).gettext;
|
const _ = imports.gettext.domain(Me.metadata['gettext-domain']).gettext;
|
||||||
|
|
||||||
|
|
@ -164,8 +165,8 @@ var DrawingMenu = new Lang.Class({
|
||||||
|
|
||||||
let lineSection = new PopupMenu.PopupMenuSection();
|
let lineSection = new PopupMenu.PopupMenuSection();
|
||||||
this._addSliderItem(lineSection, this.area, 'currentLineWidth');
|
this._addSliderItem(lineSection, this.area, 'currentLineWidth');
|
||||||
this._addSubMenuItem(lineSection, this.linejoinIcon, Draw.LineJoinNames, this.area, 'currentLineJoin');
|
this._addSubMenuItem(lineSection, this.linejoinIcon, Elements.LineJoinNames, this.area, 'currentLineJoin');
|
||||||
this._addSubMenuItem(lineSection, this.linecapIcon, Draw.LineCapNames, this.area, 'currentLineCap');
|
this._addSubMenuItem(lineSection, this.linecapIcon, Elements.LineCapNames, this.area, 'currentLineCap');
|
||||||
this._addSwitchItem(lineSection, _("Dashed"), this.fullLineIcon, this.dashedLineIcon, this.area, 'dashedLine');
|
this._addSwitchItem(lineSection, _("Dashed"), this.fullLineIcon, this.dashedLineIcon, this.area, 'dashedLine');
|
||||||
this._addSeparator(lineSection);
|
this._addSeparator(lineSection);
|
||||||
this.menu.addMenuItem(lineSection);
|
this.menu.addMenuItem(lineSection);
|
||||||
|
|
@ -176,8 +177,8 @@ var DrawingMenu = new Lang.Class({
|
||||||
let FontGenericNamesCopy = Object.create(Draw.FontGenericNames);
|
let FontGenericNamesCopy = Object.create(Draw.FontGenericNames);
|
||||||
FontGenericNamesCopy[0] = this.area.currentThemeFontFamily;
|
FontGenericNamesCopy[0] = this.area.currentThemeFontFamily;
|
||||||
this._addSubMenuItem(fontSection, 'font-x-generic-symbolic', FontGenericNamesCopy, this.area, 'currentFontGeneric');
|
this._addSubMenuItem(fontSection, 'font-x-generic-symbolic', FontGenericNamesCopy, this.area, 'currentFontGeneric');
|
||||||
this._addSubMenuItem(fontSection, 'format-text-bold-symbolic', Draw.FontWeightNames, this.area, 'currentFontWeight');
|
this._addSubMenuItem(fontSection, 'format-text-bold-symbolic', Elements.FontWeightNames, this.area, 'currentFontWeight');
|
||||||
this._addSubMenuItem(fontSection, 'format-text-italic-symbolic', Draw.FontStyleNames, this.area, 'currentFontStyle');
|
this._addSubMenuItem(fontSection, 'format-text-italic-symbolic', Elements.FontStyleNames, this.area, 'currentFontStyle');
|
||||||
this._addSwitchItem(fontSection, _("Right aligned"), 'format-justify-left-symbolic', 'format-justify-right-symbolic', this.area, 'currentTextRightAligned');
|
this._addSwitchItem(fontSection, _("Right aligned"), 'format-justify-left-symbolic', 'format-justify-right-symbolic', this.area, 'currentTextRightAligned');
|
||||||
this._addSeparator(fontSection);
|
this._addSeparator(fontSection);
|
||||||
this.menu.addMenuItem(fontSection);
|
this.menu.addMenuItem(fontSection);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue