[gnome-shell] animation: Load sliced image using resource scale, and reload on change
- From: Jonas Ådahl <jadahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] animation: Load sliced image using resource scale, and reload on change
- Date: Fri, 1 Mar 2019 18:08:15 +0000 (UTC)
commit b6ec02cef249ad6b0d52e80f7df3d3ee862515b3
Author: Marco Trevisan (Treviño) <mail 3v1n0 net>
Date: Thu Nov 30 02:36:05 2017 +0100
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();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]