From b6ec02cef249ad6b0d52e80f7df3d3ee862515b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 30 Nov 2017 02:36:05 +0100 Subject: [PATCH] animation: Load sliced image using resource scale, and reload on change Also make sure that the textures size is matching the container size. https://bugzilla.gnome.org/show_bug.cgi?id=765011 --- js/ui/animation.js | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/js/ui/animation.js b/js/ui/animation.js index 470a6ffbb..0d711567f 100644 --- a/js/ui/animation.js +++ b/js/ui/animation.js @@ -12,7 +12,12 @@ var SPINNER_ANIMATION_DELAY = 1.0; var Animation = class { constructor(file, width, height, speed) { this.actor = new St.Bin(); + this.actor.set_size(width, height); this.actor.connect('destroy', this._onDestroy.bind(this)); + this.actor.connect('notify::size', this._syncAnimationSize.bind(this)); + this.actor.connect('resource-scale-changed', + this._loadFile.bind(this, file, width, height)); + this._speed = speed; this._isLoaded = false; @@ -20,10 +25,7 @@ var Animation = class { this._timeoutId = 0; this._frame = 0; - let scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor; - this._animations = St.TextureCache.get_default().load_sliced_image (file, width, height, scaleFactor, - this._animationsLoaded.bind(this)); - this.actor.set_child(this._animations); + this._loadFile(file, width, height); } play() { @@ -47,6 +49,23 @@ var Animation = class { this._isPlaying = false; } + _loadFile(file, width, height) { + let [validResourceScale, resourceScale] = this.actor.get_resource_scale(); + + this._isLoaded = false; + this.actor.destroy_all_children(); + + if (!validResourceScale) + return; + + let texture_cache = St.TextureCache.get_default(); + let scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor; + this._animations = texture_cache.load_sliced_image(file, width, height, + scaleFactor, resourceScale, + this._animationsLoaded.bind(this)); + this.actor.set_child(this._animations); + } + _showFrame(frame) { let oldFrameActor = this._animations.get_child_at_index(this._frame); if (oldFrameActor) @@ -64,9 +83,21 @@ var Animation = class { return GLib.SOURCE_CONTINUE; } + _syncAnimationSize() { + if (!this._isLoaded) + return; + + let [width, height] = this.actor.get_size(); + + for (let i = 0; i < this._animations.get_n_children(); ++i) + this._animations.get_child_at_index(i).set_size(width, height); + } + _animationsLoaded() { this._isLoaded = this._animations.get_n_children() > 0; + this._syncAnimationSize(); + if (this._isPlaying) this.play(); }