bind grid layer visibility and hasGrid

Repaint an empty grid layer is useless.
This commit is contained in:
abakkk 2020-10-10 15:05:12 +02:00
parent dd45e87f01
commit bb90ab6040
1 changed files with 10 additions and 5 deletions

13
area.js
View File

@ -140,6 +140,7 @@ var DrawingArea = new Lang.Class({
this.foreLayer = new DrawingLayer(this._repaintFore.bind(this), this._getHasImageFore.bind(this)); this.foreLayer = new DrawingLayer(this._repaintFore.bind(this), this._getHasImageFore.bind(this));
this.layerContainer.add_child(this.foreLayer); this.layerContainer.add_child(this.foreLayer);
this.gridLayer = new DrawingLayer(this._repaintGrid.bind(this)); this.gridLayer = new DrawingLayer(this._repaintGrid.bind(this));
this.gridLayer.hide();
this.layerContainer.add_child(this.gridLayer); this.layerContainer.add_child(this.gridLayer);
this.elements = []; this.elements = [];
@ -157,7 +158,6 @@ var DrawingArea = new Lang.Class({
this.currentLineCap = Cairo.LineCap.ROUND; this.currentLineCap = Cairo.LineCap.ROUND;
this.currentFillRule = Cairo.FillRule.WINDING; this.currentFillRule = Cairo.FillRule.WINDING;
this.isSquareArea = false; this.isSquareArea = false;
this.hasGrid = false;
this.hasBackground = false; this.hasBackground = false;
this.textHasCursor = false; this.textHasCursor = false;
this.dashedLine = false; this.dashedLine = false;
@ -348,7 +348,7 @@ var DrawingArea = new Lang.Class({
}, },
_repaintGrid: function(cr) { _repaintGrid: function(cr) {
if (!this.reactive || !this.hasGrid) if (!this.reactive)
return; return;
Clutter.cairo_set_source_color(cr, this.gridColor); Clutter.cairo_set_source_color(cr, this.gridColor);
@ -386,6 +386,7 @@ var DrawingArea = new Lang.Class({
// force area to emit 'repaint' // force area to emit 'repaint'
this.backLayer.queue_repaint(); this.backLayer.queue_repaint();
this.foreLayer.queue_repaint(); this.foreLayer.queue_repaint();
if (this.hasGrid)
this.gridLayer.queue_repaint(); this.gridLayer.queue_repaint();
}, },
@ -1008,9 +1009,13 @@ var DrawingArea = new Lang.Class({
this.set_background_color(this.hasBackground ? this.areaBackgroundColor : null); this.set_background_color(this.hasBackground ? this.areaBackgroundColor : null);
}, },
get hasGrid() {
return this.gridLayer.visible;
},
toggleGrid: function() { toggleGrid: function() {
this.hasGrid = !this.hasGrid; // The grid layer is repainted when the visibility changes.
this._redisplay(); this.gridLayer.visible = !this.gridLayer.visible;
}, },
toggleSquareArea: function() { toggleSquareArea: function() {