4
// Copyright (C) 2008 Lukas Lipka <lukaslipka@gmail.com>
11
namespace Beagle.Search {
13
public class Spinner : Gtk.Image {
15
private IconTheme theme;
17
private Pixbuf idle_pixbuf;
18
private Pixbuf[] frames;
20
private int current_frame;
21
private uint timeout_id;
23
private const int target_size = 24;
24
private const int refresh_rate = 125;
40
if (frames == null || frames.Length == 0)
46
timeout_id = GLib.Timeout.Add (refresh_rate, TimeoutHandler);
54
GLib.Source.Remove (timeout_id);
60
private bool TimeoutHandler ()
62
Pixbuf = frames [current_frame];
63
current_frame = (current_frame + 1) % frames.Length;
68
protected override void OnRealized ()
72
theme = Gtk.IconTheme.GetForScreen (Screen);
73
theme.Changed += ThemeChanged;
78
private void ThemeChanged (object o, EventArgs args)
83
private void LoadImages ()
85
int icon_size = target_size;
87
// Find available spinner sizes and use the appropriate one
89
foreach (int size in theme.GetIconSizes ("gnome-spinner-rest")) {
90
if (size >= target_size) {
97
idle_pixbuf = theme.LoadIcon ("gnome-spinner-rest", icon_size, 0);
99
Console.Error.WriteLine ("Could not load spinner image");
105
Gdk.Pixbuf frames_pixbuf = null;
108
frames_pixbuf = theme.LoadIcon ("gnome-spinner", icon_size, 0);
110
Console.Error.WriteLine ("Could not load spinner image");
112
Pixbuf = idle_pixbuf;
116
int frame_width = idle_pixbuf.Width, frame_height = idle_pixbuf.Height;
117
int width = frames_pixbuf.Width, height = frames_pixbuf.Height;
119
if (width % frame_width != 0 || height % frame_height != 0) {
120
Console.Error.WriteLine ("Spinner images are wrong size");
122
Pixbuf = idle_pixbuf;
126
int rows = height / frame_height, cols = width / frame_width;
128
frames = new Pixbuf [rows * cols];
130
for (int y = 0, n = 0; y < rows; y++) {
131
for (int x = 0; x < cols; x++) {
132
frames [n++] = new Pixbuf (frames_pixbuf,
143
Pixbuf = frames [current_frame];
145
Pixbuf = idle_pixbuf;