spinner: fix coding style and whitespace

This commit is contained in:
Hylke Bons 2011-05-14 01:38:55 +01:00
parent 632c57da13
commit aed1c9fa2d

View file

@ -14,112 +14,98 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
using Gtk;
using System.Timers; using System.Timers;
using Gtk;
namespace SparkleShare { 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; public bool Active;
private Gdk.Pixbuf [] Images; private Gdk.Pixbuf [] Images;
private Timer Timer; private Timer Timer;
private int CycleDuration; private int CycleDuration;
private int CurrentStep; private int CurrentStep;
private int NumSteps; private int NumSteps;
private int Size; private int Size;
public SparkleSpinner (int size) : base ()
{
Size = size; public SparkleSpinner (int size) : base ()
{
Size = size;
CycleDuration = 600; CycleDuration = 600;
CurrentStep = 0; CurrentStep = 0;
Gdk.Pixbuf spinner_gallery = SparkleUIHelpers.GetIcon ("process-working", Size); Gdk.Pixbuf spinner_gallery = SparkleUIHelpers.GetIcon ("process-working", Size);
int frames_in_width = spinner_gallery.Width / Size; int frames_in_width = spinner_gallery.Width / Size;
int frames_in_height = spinner_gallery.Height / Size; int frames_in_height = spinner_gallery.Height / Size;
NumSteps = frames_in_width * frames_in_height; NumSteps = frames_in_width * frames_in_height;
Images = new Gdk.Pixbuf [NumSteps - 1]; 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++) {
if (!(y == 0 && x == 0)) {
Images [i] = new Gdk.Pixbuf (spinner_gallery, x * Size, y * Size, Size, Size);
i++;
}
}
}
for (int x = 0; x < frames_in_width; x++) { Timer = new Timer () {
Interval = CycleDuration / NumSteps
};
if (!(y == 0 && x == 0)) { Timer.Elapsed += delegate {
NextImage ();
Images [i] = new Gdk.Pixbuf (spinner_gallery, x * Size, y * Size, Size, Size); };
i++;
} Start ();
}
}
} private void NextImage ()
{
if (CurrentStep < NumSteps - 2)
CurrentStep++;
else
CurrentStep = 0;
Timer = new Timer () { Application.Invoke (delegate { SetImage (); });
Interval = CycleDuration / NumSteps }
};
Timer.Elapsed += delegate {
NextImage ();
};
Start (); private void SetImage ()
{
Pixbuf = Images [CurrentStep];
}
}
private void NextImage () public bool IsActive ()
{ {
return Active;
}
if (CurrentStep < NumSteps - 2)
CurrentStep++;
else
CurrentStep = 0;
Application.Invoke (delegate { SetImage (); }); public void Start ()
{
CurrentStep = 0;
Active = true;
Timer.Start ();
}
}
private void SetImage ()
{
Pixbuf = Images [CurrentStep];
}
public bool IsActive ()
{
return Active;
}
public void Start ()
{
CurrentStep = 0;
Active = true;
Timer.Start ();
}
public void Stop ()
{
Active = false;
Timer.Stop ();
}
}
public void Stop ()
{
Active = false;
Timer.Stop ();
}
}
} }