Add stroke to fill

When 'fill' is selected, the stroke is also drawn.

other: add markup to font menu items
This commit is contained in:
abakkk 2019-03-29 22:31:13 +01:00
parent 7a1fc3acff
commit 8780e3607b
1 changed files with 32 additions and 17 deletions

49
draw.js
View File

@ -138,14 +138,22 @@ var DrawingArea = new Lang.Class({
let cr = area.get_context(); let cr = area.get_context();
for (let i = 0; i < this.elements.length; i++) { for (let i = 0; i < this.elements.length; i++) {
this.elements[i].buildCairo(cr, false);
let isStraightLine = this.elements[i].shape == Shapes.LINE && let isStraightLine = this.elements[i].shape == Shapes.LINE &&
(this.elements[i].points.length < 3 || this.elements[i].points[2] == this.elements[i].points[1] || this.elements[i].points[2] == this.elements[i].points[0]); (this.elements[i].points.length < 3 || this.elements[i].points[2] == this.elements[i].points[1] || this.elements[i].points[2] == this.elements[i].points[0]);
if (this.elements[i].fill && !isStraightLine)
cr.fill(); if (this.elements[i].fill && !isStraightLine) {
else // first paint stroke
this.elements[i].buildCairo(cr, false);
if (this.elements[i].shape == Shapes.NONE || this.elements[i].shape == Shapes.LINE)
cr.closePath();
cr.stroke(); cr.stroke();
// secondly paint fill
this.elements[i].buildCairo(cr, false);
cr.fill();
} else {
this.elements[i].buildCairo(cr, false);
cr.stroke();
}
} }
if (this.currentElement) { if (this.currentElement) {
@ -731,8 +739,8 @@ var DrawingElement = new Lang.Class({
let isStraightLine = this.shape == Shapes.LINE && (points.length < 3 || points[2] == points[1] || points[2] == points[0]); let isStraightLine = this.shape == Shapes.LINE && (points.length < 3 || points[2] == points[1] || points[2] == points[0]);
let fill = this.fill && !isStraightLine; let fill = this.fill && !isStraightLine;
let attributes = `fill="${fill ? color : 'transparent'}" ` + let attributes = `fill="${fill ? color : 'transparent'}" ` +
`stroke="${fill ? 'transparent' : color}" ` + `stroke="${color}" ` +
`${fill ? 'stroke-opacity="0"' : 'fill-opacity="0"'} ` + `${fill ? '' : 'fill-opacity="0"'} ` +
`stroke-width="${this.line.lineWidth}" ` + `stroke-width="${this.line.lineWidth}" ` +
`stroke-linecap="${LineCapNames[this.line.lineCap].toLowerCase()}" ` + `stroke-linecap="${LineCapNames[this.line.lineCap].toLowerCase()}" ` +
`stroke-linejoin="${LineJoinNames[this.line.lineJoin].toLowerCase()}"`; `stroke-linejoin="${LineJoinNames[this.line.lineJoin].toLowerCase()}"`;
@ -1067,7 +1075,7 @@ var DrawingMenu = new Lang.Class({
this._addSubMenuItem(this.menu, null, ShapeNames, this.area, 'currentShape', this.updateSectionVisibility.bind(this)); this._addSubMenuItem(this.menu, null, ShapeNames, this.area, 'currentShape', this.updateSectionVisibility.bind(this));
this._addColorSubMenuItem(this.menu); this._addColorSubMenuItem(this.menu);
this.fillItem = this._addSwitchItem(this.menu, _("Fill"), this.strokeIcon, this.fillIcon, this.area, 'fill', this.updateSectionVisibility.bind(this)); this.fillItem = this._addSwitchItem(this.menu, _("Fill"), this.strokeIcon, this.fillIcon, this.area, 'fill');
this._addSeparator(this.menu); this._addSeparator(this.menu);
let lineSection = new PopupMenu.PopupMenuSection(); let lineSection = new PopupMenu.PopupMenuSection();
@ -1104,21 +1112,18 @@ var DrawingMenu = new Lang.Class({
}, },
updateSectionVisibility: function() { updateSectionVisibility: function() {
if (this.area.fill || this.area.currentShape == Shapes.TEXT)
this.lineSection.actor.hide();
else
this.lineSection.actor.show();
if (this.area.currentShape != Shapes.TEXT) { if (this.area.currentShape != Shapes.TEXT) {
this.lineSection.actor.show();
this.fontSection.actor.hide(); this.fontSection.actor.hide();
this.fillItem.setSensitive(true); this.fillItem.setSensitive(true);
} else { } else {
this.lineSection.actor.hide();
this.fontSection.actor.show(); this.fontSection.actor.show();
this.fillItem.setSensitive(false); this.fillItem.setSensitive(false);
} }
}, },
_addSwitchItem: function(menu, label, iconFalse, iconTrue, target, targetProperty, callback) { _addSwitchItem: function(menu, label, iconFalse, iconTrue, target, targetProperty) {
let item = new PopupMenu.PopupSwitchMenuItem(label, target[targetProperty]); let item = new PopupMenu.PopupSwitchMenuItem(label, target[targetProperty]);
item.icon = new St.Icon({ style_class: 'popup-menu-icon blabla' }); item.icon = new St.Icon({ style_class: 'popup-menu-icon blabla' });
@ -1128,8 +1133,6 @@ var DrawingMenu = new Lang.Class({
item.connect('toggled', (item, state) => { item.connect('toggled', (item, state) => {
target[targetProperty] = state; target[targetProperty] = state;
item.icon.set_gicon(target[targetProperty] ? iconTrue : iconFalse); item.icon.set_gicon(target[targetProperty] ? iconTrue : iconFalse);
if (callback)
callback();
}); });
menu.addMenuItem(item); menu.addMenuItem(item);
return item; return item;
@ -1170,12 +1173,24 @@ var DrawingMenu = new Lang.Class({
Mainloop.timeout_add(0, () => { Mainloop.timeout_add(0, () => {
for (let i in obj) { for (let i in obj) {
item.menu.addAction(_(obj[i]), () => { let text;
if (targetProperty == 'currentFontFamilyId')
text = `<span font_family="${obj[i]}">${_(obj[i])}</span>`;
else if (targetProperty == 'currentFontWeight')
text = `<span font_weight="${obj[i].toLowerCase()}">${_(obj[i])}</span>`;
else if (targetProperty == 'currentFontStyle')
text = `<span font_style="${obj[i].toLowerCase()}">${_(obj[i])}</span>`;
else
text = _(obj[i]);
let subItem = item.menu.addAction(text, () => {
item.label.set_text(_(obj[i])); item.label.set_text(_(obj[i]));
target[targetProperty] = i; target[targetProperty] = i;
if (callback) if (callback)
callback(); callback();
}); });
subItem.label.get_clutter_text().set_use_markup(true);
} }
return GLib.SOURCE_REMOVE; return GLib.SOURCE_REMOVE;
}); });