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
public class SparkleSpinner : Image {
public bool Active;
private Gdk.Pixbuf [] Images;
private Timer Timer;
private int CycleDuration;
private int CurrentStep;
private int NumSteps;
private int Size;
private Timer timer;
public SparkleSpinner (int size) : base ()
{
Size = size;
CycleDuration = 600;
CurrentStep = 0;
Gdk.Pixbuf spinner_gallery = SparkleUIHelpers.GetIcon ("process-working", Size);
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 current_frame = 0;
Gdk.Pixbuf spinner_gallery = SparkleUIHelpers.GetIcon ("process-working", size);
int frames_in_width = spinner_gallery.Width / size;
int frames_in_height = spinner_gallery.Height / size;
int frame_count = (frames_in_width * frames_in_height) - 1;
Gdk.Pixbuf [] frames = new Gdk.Pixbuf [frame_count - 1];
int i = 0;
for (int y = 0; y < frames_in_height; y++) {
for (int x = 0; x < frames_in_width; x++) {
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++;
}
}
}
Timer = new Timer () {
Interval = CycleDuration / NumSteps
timer = new Timer () {
Interval = 600 / frame_count
};
Timer.Elapsed += delegate {
NextImage ();
timer.Elapsed += delegate {
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 ()
{
CurrentStep = 0;
Active = true;
Timer.Start ();
timer.Start ();
}
public void Stop ()
{
Active = false;
Timer.Stop ();
timer.Stop ();
}
}
}

View file

@ -25,51 +25,49 @@ namespace SparkleShare {
public class SparkleSpinner : Image {
private Image [] images;
private Timer timer;
private int num_steps;
private int current_step = 0;
public SparkleSpinner (int size) : base ()
{
Width = size;
Height = size;
{
Width = size;
Height = size;
BitmapSource spinner_gallery = SparkleUIHelpers.GetImageSource ("process-working-22");
int frames_in_width = spinner_gallery.PixelWidth / size;
int frames_in_height = spinner_gallery.PixelHeight / size;
this.num_steps = (frames_in_width * frames_in_height) - 1;
this.images = new Image [this.num_steps];
int current_frame = 0;
BitmapSource spinner_gallery = SparkleUIHelpers.Getframesource ("process-working-22");
int frames_in_width = spinner_gallery.PixelWidth / size;
int frames_in_height = spinner_gallery.PixelHeight / size;
int frame_count = (frames_in_width * frames_in_height) - 1;
Image [] frames = new Image [frame_count];
int i = 0;
for (int y = 0; y < frames_in_height; y++) {
for (int x = 0; x < frames_in_width; x++) {
if (!(y == 0 && x == 0)) {
CroppedBitmap crop = new CroppedBitmap (spinner_gallery,
new Int32Rect (size * x, size * y, size, size));
this.images [i] = new Image ();
this.images [i].Source = crop;
frames [i] = new Image ();
frames [i].Source = crop;
i++;
}
}
}
this.timer = new Timer () {
Interval = 400 / this.num_steps
Interval = 400 / frame_count
};
this.timer.Elapsed += 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 ()
{
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;
}
}
}