From 06f7a12c72b4dc99a4c31d9db0a80cff7ec47ac7 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Mon, 17 Sep 2012 18:17:50 +0100 Subject: [PATCH] spinner: Remove unused code --- SparkleShare/Linux/SparkleSpinner.cs | 77 +++++++------------------- SparkleShare/Windows/SparkleSpinner.cs | 56 ++++++------------- 2 files changed, 39 insertions(+), 94 deletions(-) diff --git a/SparkleShare/Linux/SparkleSpinner.cs b/SparkleShare/Linux/SparkleSpinner.cs index ef4c3347..6d82323f 100755 --- a/SparkleShare/Linux/SparkleSpinner.cs +++ b/SparkleShare/Linux/SparkleSpinner.cs @@ -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 (); } } } diff --git a/SparkleShare/Windows/SparkleSpinner.cs b/SparkleShare/Windows/SparkleSpinner.cs index 1de3fedb..13821406 100644 --- a/SparkleShare/Windows/SparkleSpinner.cs +++ b/SparkleShare/Windows/SparkleSpinner.cs @@ -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; } } }