spinner: Remove unused code

This commit is contained in:
Hylke Bons 2012-09-17 18:17:50 +01:00
parent 284234514f
commit 06f7a12c72
2 changed files with 39 additions and 94 deletions

View file

@ -23,89 +23,54 @@ namespace SparkleShare {
// This is a close implementation of GtkSpinner // This is a close implementation of GtkSpinner
public class SparkleSpinner : Image { public class SparkleSpinner : Image {
public bool Active; private Timer timer;
private Gdk.Pixbuf [] Images;
private Timer Timer;
private int CycleDuration;
private int CurrentStep;
private int NumSteps;
private int Size;
public SparkleSpinner (int size) : base () public SparkleSpinner (int size) : base ()
{ {
Size = size; int current_frame = 0;
Gdk.Pixbuf spinner_gallery = SparkleUIHelpers.GetIcon ("process-working", size);
CycleDuration = 600; int frames_in_width = spinner_gallery.Width / size;
CurrentStep = 0; int frames_in_height = spinner_gallery.Height / size;
int frame_count = (frames_in_width * frames_in_height) - 1;
Gdk.Pixbuf spinner_gallery = SparkleUIHelpers.GetIcon ("process-working", Size); Gdk.Pixbuf [] frames = new Gdk.Pixbuf [frame_count - 1];
int frames_in_width = spinner_gallery.Width / Size;
int frames_in_height = spinner_gallery.Height / Size;
NumSteps = frames_in_width * frames_in_height;
Images = new Gdk.Pixbuf [NumSteps - 1];
int i = 0; int i = 0;
for (int y = 0; y < frames_in_height; y++) { for (int y = 0; y < frames_in_height; y++) {
for (int x = 0; x < frames_in_width; x++) { for (int x = 0; x < frames_in_width; x++) {
if (!(y == 0 && x == 0)) { if (!(y == 0 && x == 0)) {
Images [i] = new Gdk.Pixbuf (spinner_gallery, x * Size, y * Size, Size, Size); frames [i] = new Gdk.Pixbuf (spinner_gallery, x * size, y * size, size, size);
i++; i++;
} }
} }
} }
Timer = new Timer () { timer = new Timer () {
Interval = CycleDuration / NumSteps Interval = 600 / frame_count
}; };
Timer.Elapsed += delegate { timer.Elapsed += delegate {
NextImage (); if (current_frame < frame_count - 1)
current_frame++;
else
current_frame = 0;
Application.Invoke (delegate {
Pixbuf = frames [current_frame];
});
}; };
Start ();
}
private void NextImage ()
{
if (CurrentStep < NumSteps - 2)
CurrentStep++;
else
CurrentStep = 0;
Application.Invoke (delegate { SetImage (); });
}
private void SetImage ()
{
Pixbuf = Images [CurrentStep];
}
public bool IsActive ()
{
return Active;
} }
public void Start () public void Start ()
{ {
CurrentStep = 0; timer.Start ();
Active = true;
Timer.Start ();
} }
public void Stop () public void Stop ()
{ {
Active = false; timer.Stop ();
Timer.Stop ();
} }
} }
} }

View file

@ -25,51 +25,49 @@ namespace SparkleShare {
public class SparkleSpinner : Image { public class SparkleSpinner : Image {
private Image [] images;
private Timer timer; private Timer timer;
private int num_steps;
private int current_step = 0;
public SparkleSpinner (int size) : base () public SparkleSpinner (int size) : base ()
{ {
Width = size; Width = size;
Height = size; Height = size;
BitmapSource spinner_gallery = SparkleUIHelpers.GetImageSource ("process-working-22"); int current_frame = 0;
BitmapSource spinner_gallery = SparkleUIHelpers.Getframesource ("process-working-22");
int frames_in_width = spinner_gallery.PixelWidth / size; int frames_in_width = spinner_gallery.PixelWidth / size;
int frames_in_height = spinner_gallery.PixelHeight / size; int frames_in_height = spinner_gallery.PixelHeight / size;
int frame_count = (frames_in_width * frames_in_height) - 1;
this.num_steps = (frames_in_width * frames_in_height) - 1; Image [] frames = new Image [frame_count];
this.images = new Image [this.num_steps];
int i = 0; int i = 0;
for (int y = 0; y < frames_in_height; y++) { for (int y = 0; y < frames_in_height; y++) {
for (int x = 0; x < frames_in_width; x++) { for (int x = 0; x < frames_in_width; x++) {
if (!(y == 0 && x == 0)) { if (!(y == 0 && x == 0)) {
CroppedBitmap crop = new CroppedBitmap (spinner_gallery, CroppedBitmap crop = new CroppedBitmap (spinner_gallery,
new Int32Rect (size * x, size * y, size, size)); new Int32Rect (size * x, size * y, size, size));
this.images [i] = new Image (); frames [i] = new Image ();
this.images [i].Source = crop; frames [i].Source = crop;
i++; i++;
} }
} }
} }
this.timer = new Timer () { this.timer = new Timer () {
Interval = 400 / this.num_steps Interval = 400 / frame_count
}; };
this.timer.Elapsed += delegate { this.timer.Elapsed += delegate {
Dispatcher.BeginInvoke ((Action) delegate { Dispatcher.BeginInvoke ((Action) delegate {
NextImage (); if (current_frame < frame_count - 1)
current_frame++;
else
current_frame = 0;
Source = this.frames [current_frame].Source;
}); });
}; };
Start ();
} }
@ -82,24 +80,6 @@ namespace SparkleShare {
public void Stop () public void Stop ()
{ {
this.timer.Stop (); this.timer.Stop ();
this.current_step = 0;
}
private void NextImage ()
{
if (this.current_step < this.num_steps - 1)
this.current_step++;
else
this.current_step = 0;
SetImage ();
}
private void SetImage ()
{
Source = this.images [this.current_step].Source;
} }
} }
} }