| 1 |
const Clutter = imports.gi.Clutter; |
| 2 |
const GdkPixbuf = imports.gi.GdkPixbuf; |
| 3 |
const Cogl = imports.gi.Cogl; |
| 4 |
const Lang = imports.lang; |
| 5 |
const Endless = imports.gi.Endless; |
| 6 |
Clutter.init(null, null); |
| 7 |
|
| 8 |
let crossfade = ARGV[0] === "crossfade"; |
| 9 |
|
| 10 |
let file_dir = Endless.getCurrentFileDir(); |
| 11 |
|
| 12 |
let BACKGROUND1_PATH = file_dir + '/1080/background1.jpg'; |
| 13 |
let BACKGROUND2_PATH = file_dir + '/1080/background2.jpg'; |
| 14 |
if (ARGV[1] === "720") { |
| 15 |
BACKGROUND1_PATH = file_dir + '/720/background1.jpg'; |
| 16 |
BACKGROUND2_PATH = file_dir + '/720/background2.jpg'; |
| 17 |
} |
| 18 |
|
| 19 |
// Convenience function to load a gresource image into a Clutter.Image |
| 20 |
function load_clutter_image(path) { |
| 21 |
let pixbuf = GdkPixbuf.Pixbuf.new_from_file(path); |
| 22 |
let image = new Clutter.Image(); |
| 23 |
if (pixbuf != null) { |
| 24 |
image.set_data(pixbuf.get_pixels(), |
| 25 |
pixbuf.get_has_alpha() |
| 26 |
? Cogl.PixelFormat.RGBA_8888 |
| 27 |
: Cogl.PixelFormat.RGB_888, |
| 28 |
pixbuf.get_width(), |
| 29 |
pixbuf.get_height(), |
| 30 |
pixbuf.get_rowstride()); |
| 31 |
} |
| 32 |
return image; |
| 33 |
} |
| 34 |
|
| 35 |
const TestStage = new Lang.Class ({ |
| 36 |
Name: 'TestStage', |
| 37 |
Extends: Clutter.Stage, |
| 38 |
|
| 39 |
_init: function(params) { |
| 40 |
this.parent(params); |
| 41 |
this.set_fullscreen(true); |
| 42 |
this.connect("allocation-changed", Lang.bind(this, function(actor, allocation) { |
| 43 |
this._update_actors(); |
| 44 |
})); |
| 45 |
|
| 46 |
this._page1 = new Clutter.Actor({ |
| 47 |
"x-expand": true, |
| 48 |
"y-expand": true, |
| 49 |
"content": load_clutter_image(BACKGROUND1_PATH), |
| 50 |
"reactive": true |
| 51 |
}); |
| 52 |
this.add_child(this._page1); |
| 53 |
this._page1.connect("button-press-event", Lang.bind(this, function(actor, event) { |
| 54 |
this._swap(); |
| 55 |
})); |
| 56 |
|
| 57 |
this._page2 = new Clutter.Actor({ |
| 58 |
"x-expand": true, |
| 59 |
"y-expand": true, |
| 60 |
"content": load_clutter_image(BACKGROUND2_PATH), |
| 61 |
"reactive": true |
| 62 |
}); |
| 63 |
this.add_child(this._page2); |
| 64 |
this._page2.connect("button-press-event", Lang.bind(this, function(actor, event) { |
| 65 |
this._swap(); |
| 66 |
})); |
| 67 |
|
| 68 |
this._update_actors(); |
| 69 |
this.connect("key-press-event", Clutter.main_quit); |
| 70 |
}, |
| 71 |
|
| 72 |
_swap: function() { |
| 73 |
this._swapped = !this._swapped; |
| 74 |
this._page1.save_easing_state(); |
| 75 |
this._page2.save_easing_state(); |
| 76 |
this._page1.set_easing_duration(10000); |
| 77 |
this._page2.set_easing_duration(10000); |
| 78 |
this._update_actors(); |
| 79 |
this._page1.restore_easing_state(); |
| 80 |
this._page2.restore_easing_state(); |
| 81 |
}, |
| 82 |
|
| 83 |
_update_actors: function() { |
| 84 |
this._page1.x = 0; |
| 85 |
this._page1.width = this.get_width(); |
| 86 |
this._page1.height = this.get_height(); |
| 87 |
this._page2.x = 0; |
| 88 |
this._page2.width = this.get_width(); |
| 89 |
this._page2.height = this.get_height(); |
| 90 |
if (crossfade) { |
| 91 |
if(this._swapped) |
| 92 |
this._page2.opacity = 255; |
| 93 |
else |
| 94 |
this._page2.opacity = 0; |
| 95 |
} |
| 96 |
else { |
| 97 |
if(this._swapped) |
| 98 |
this._page1.x = -this.get_width(); |
| 99 |
else |
| 100 |
this._page2.x = this.get_width(); |
| 101 |
} |
| 102 |
} |
| 103 |
}); |
| 104 |
|
| 105 |
|
| 106 |
let stage = new TestStage(); |
| 107 |
stage.show(); |
| 108 |
Clutter.main(); |
| 109 |
stage.destroy(); |