Created
May 14, 2014 15:06
-
-
Save felipeborges/123a39d5fec820ec1224 to your computer and use it in GitHub Desktop.
Hover effect in Gtk Image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const GdkPixbuf = imports.gi.GdkPixbuf; | |
const Gtk = imports.gi.Gtk; | |
const Lang = imports.lang; | |
Gtk.init(null, 0); | |
let test_window = new Gtk.Window({ | |
default_width: 128, | |
default_height: 128 | |
}); | |
let events = new Gtk.EventBox(); | |
let layers = new Gtk.Overlay(); | |
events.add(layers); | |
let original_pix = GdkPixbuf.Pixbuf.new_from_file_at_scale("image.jpg", 128, 128, false); | |
let bw_pix = original_pix.copy(); | |
original_pix.saturate_and_pixelate(bw_pix, 0, 0); | |
layers.add(Gtk.Image.new_from_pixbuf(bw_pix)); | |
let hover_image = Gtk.Image.new_from_pixbuf(original_pix); | |
hover_image.set_opacity(0); | |
hover_image.get_style_context().add_class('hover'); | |
layers.add_overlay(hover_image); | |
events.connect('enter-notify-event', Lang.bind(this, function() { | |
hover_image.set_opacity(1); | |
hover_image.get_style_context().remove_class('hover'); | |
})); | |
test_window.add(events); | |
test_window.show_all(); | |
Gtk.main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment