add iconName param to showOsd function

Prepare save and open drawing features.
This commit is contained in:
abakkk 2020-01-02 00:56:40 +01:00
parent 6d27a37478
commit f0ac2a21b0
2 changed files with 17 additions and 14 deletions

24
draw.js
View File

@ -70,7 +70,7 @@ var FontFamilyNames = { 0: 'Default', 1: 'Sans-Serif', 2: 'Serif', 3: 'Monospac
var DrawingArea = new Lang.Class({ var DrawingArea = new Lang.Class({
Name: 'DrawOnYourScreenDrawingArea', Name: 'DrawOnYourScreenDrawingArea',
Extends: St.DrawingArea, Extends: St.DrawingArea,
Signals: { 'show-osd': { param_types: [GObject.TYPE_STRING, GObject.TYPE_DOUBLE] }, Signals: { 'show-osd': { param_types: [GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_DOUBLE] },
'stop-drawing': {} }, 'stop-drawing': {} },
_init: function(params, monitor, helper, loadJson) { _init: function(params, monitor, helper, loadJson) {
@ -322,7 +322,7 @@ var DrawingArea = new Lang.Class({
if (this.currentElement.shape == Shapes.TEXT && this.currentElement.state == TextState.DRAWING) { if (this.currentElement.shape == Shapes.TEXT && this.currentElement.state == TextState.DRAWING) {
this.currentElement.state = TextState.WRITING; this.currentElement.state = TextState.WRITING;
this.currentElement.text = ''; this.currentElement.text = '';
this.emit('show-osd', _("Type your text\nand press Enter"), -1); this.emit('show-osd', null, _("Type your text\nand press Enter"), -1);
this._updateCursorTimeout(); this._updateCursorTimeout();
this.textHasCursor = true; this.textHasCursor = true;
this._redisplay(); this._redisplay();
@ -468,38 +468,38 @@ var DrawingArea = new Lang.Class({
this.currentElement.color = this.currentColor.to_string(); this.currentElement.color = this.currentColor.to_string();
this._redisplay(); this._redisplay();
} }
this.emit('show-osd', `<span foreground="${this.currentColor.to_string()}">${this.currentColor.to_string()}</span>`, -1); this.emit('show-osd', null, `<span foreground="${this.currentColor.to_string()}">${this.currentColor.to_string()}</span>`, -1);
}, },
selectShape: function(shape) { selectShape: function(shape) {
this.currentShape = shape; this.currentShape = shape;
this.emit('show-osd', _(ShapeNames[shape]), -1); this.emit('show-osd', null, _(ShapeNames[shape]), -1);
this.updatePointerCursor(); this.updatePointerCursor();
}, },
toggleFill: function() { toggleFill: function() {
this.fill = !this.fill; this.fill = !this.fill;
this.emit('show-osd', this.fill ? _("Fill") : _("Stroke"), -1); this.emit('show-osd', null, this.fill ? _("Fill") : _("Stroke"), -1);
}, },
toggleDash: function() { toggleDash: function() {
this.dashedLine = !this.dashedLine; this.dashedLine = !this.dashedLine;
this.emit('show-osd', this.dashedLine ? _("Dashed line") : _("Full line"), -1); this.emit('show-osd', null, this.dashedLine ? _("Dashed line") : _("Full line"), -1);
}, },
incrementLineWidth: function(increment) { incrementLineWidth: function(increment) {
this.currentLineWidth = Math.max(this.currentLineWidth + increment, 0); this.currentLineWidth = Math.max(this.currentLineWidth + increment, 0);
this.emit('show-osd', this.currentLineWidth + " " + _("px"), 2 * this.currentLineWidth); this.emit('show-osd', null, this.currentLineWidth + " " + _("px"), 2 * this.currentLineWidth);
}, },
toggleLineJoin: function() { toggleLineJoin: function() {
this.currentLineJoin = this.currentLineJoin == 2 ? 0 : this.currentLineJoin + 1; this.currentLineJoin = this.currentLineJoin == 2 ? 0 : this.currentLineJoin + 1;
this.emit('show-osd', _(LineJoinNames[this.currentLineJoin]), -1); this.emit('show-osd', null, _(LineJoinNames[this.currentLineJoin]), -1);
}, },
toggleLineCap: function() { toggleLineCap: function() {
this.currentLineCap = this.currentLineCap == 2 ? 0 : this.currentLineCap + 1; this.currentLineCap = this.currentLineCap == 2 ? 0 : this.currentLineCap + 1;
this.emit('show-osd', _(LineCapNames[this.currentLineCap]), -1); this.emit('show-osd', null, _(LineCapNames[this.currentLineCap]), -1);
}, },
toggleFontWeight: function() { toggleFontWeight: function() {
@ -508,7 +508,7 @@ var DrawingArea = new Lang.Class({
this.currentElement.font.weight = this.currentFontWeight; this.currentElement.font.weight = this.currentFontWeight;
this._redisplay(); this._redisplay();
} }
this.emit('show-osd', `<span font_weight="${FontWeightNames[this.currentFontWeight].toLowerCase()}">${_(FontWeightNames[this.currentFontWeight])}</span>`, -1); this.emit('show-osd', null, `<span font_weight="${FontWeightNames[this.currentFontWeight].toLowerCase()}">${_(FontWeightNames[this.currentFontWeight])}</span>`, -1);
}, },
toggleFontStyle: function() { toggleFontStyle: function() {
@ -517,7 +517,7 @@ var DrawingArea = new Lang.Class({
this.currentElement.font.style = this.currentFontStyle; this.currentElement.font.style = this.currentFontStyle;
this._redisplay(); this._redisplay();
} }
this.emit('show-osd', `<span font_style="${FontStyleNames[this.currentFontStyle].toLowerCase()}">${_(FontStyleNames[this.currentFontStyle])}</span>`, -1); this.emit('show-osd', null, `<span font_style="${FontStyleNames[this.currentFontStyle].toLowerCase()}">${_(FontStyleNames[this.currentFontStyle])}</span>`, -1);
}, },
toggleFontFamily: function() { toggleFontFamily: function() {
@ -527,7 +527,7 @@ var DrawingArea = new Lang.Class({
this.currentElement.font.family = currentFontFamily; this.currentElement.font.family = currentFontFamily;
this._redisplay(); this._redisplay();
} }
this.emit('show-osd', `<span font_family="${currentFontFamily}">${_(currentFontFamily)}</span>`, -1); this.emit('show-osd', null, `<span font_family="${currentFontFamily}">${_(currentFontFamily)}</span>`, -1);
}, },
toggleHelp: function() { toggleHelp: function() {

View File

@ -315,11 +315,12 @@ var AreaManager = new Lang.Class({
}, },
// use level -1 to set no level (null) // use level -1 to set no level (null)
showOsd: function(emitter, label, level, maxLevel) { showOsd: function(emitter, iconName, label, level) {
if (this.osdDisabled) if (this.osdDisabled)
return; return;
let activeIndex = this.areas.indexOf(this.activeArea); let activeIndex = this.areas.indexOf(this.activeArea);
if (activeIndex != -1) { if (activeIndex != -1) {
let maxLevel;
if (level == -1) if (level == -1)
level = null; level = null;
else if (level > 100) else if (level > 100)
@ -329,7 +330,9 @@ var AreaManager = new Lang.Class({
// GS 3.34+ : bar from 0 to 1 // GS 3.34+ : bar from 0 to 1
if (level && GS_VERSION > '3.33.0') if (level && GS_VERSION > '3.33.0')
level = level / 100; level = level / 100;
Main.osdWindowManager.show(activeIndex, this.enterGicon, label, level, maxLevel);
let icon = iconName && new Gio.ThemedIcon({ name: iconName });
Main.osdWindowManager.show(activeIndex, icon || this.enterGicon, label, level, maxLevel);
Main.osdWindowManager._osdWindows[activeIndex]._label.get_clutter_text().set_use_markup(true); Main.osdWindowManager._osdWindows[activeIndex]._label.get_clutter_text().set_use_markup(true);
if (level === 0) { if (level === 0) {