Running a Meeting Agenda with DotImage
One thing that we do at Atalasoft is a biweekly staff meeting where we cover what’s going on. The responsibility for running the meeting bounces around and it is encouraged to pick a format that works best for you. At the last meeting, I decided to let a monkey decide in what order departments were going to present. I budgeted myself an hour to write an app do that, of which I spent a half hour writing code and a half hour getting/editing images.
Note that the code that I present, while functional, is representative more of the time budget than the actual architectural beauty.
I decided that I would do something more or less like a slot machine where pictures are displayed one after the other until settling on the choice.
To do this, I made a data structure with a list of the departments and pictures to use for them. I was going to select images at random, but I decided to hand-pick moderately benevolent pictures out of a larger set so as not to inadvertently hurt anyone’s feelings.
Here is the data declaration:
NameFilename[] _deptPics = new NameFilename[] {
new NameFilename {Name = "DotImage Sales", Filename = "diving.jpg"},
new NameFilename {Name = "Vizit Sales", Filename = "ni.jpg"},
new NameFilename {Name = "DotImage Marketing", Filename = "weasel.jpg"},
new NameFilename {Name = "Vizit Marketing", Filename = "cranberryharvest.jpg"},
new NameFilename {Name = "Vizit Engineering", Filename = "keghead.jpg"},
new NameFilename {Name = "DotImage Engineering", Filename = "steamengine.jpg"},
new NameFilename {Name = "CEO", Filename = "roosevelt.jpg"},
new NameFilename {Name = "HR", Filename = "fingerpaint.jpg"},
new NameFilename {Name = "Operations", Filename = "iwojima.jpg"},
new NameFilename {Name = "Support", Filename = "neckbrace.jpg"},
};
FilenameImage[] _images;
NameFilename is just that – a pair of a UI name and a filename.
FilenameImage is also just that – a pair of a filename and an image.
The next step was to shuffle _deptPics. To do that, I did a quick FYK Shuffle:
public static void Shuffle<T>(T[] array)
{
var random = _random;
for (int i = array.Length; i > 1; i--)
{
int j = random.Next(i);
T tmp = array[j];
array[j] = array[i - 1];
array[i - 1] = tmp;
}
}
Then I loaded the _images array:
FilenameImage[] GetImages(string[] files)
{
FilenameImage[] fileImages = new FilenameImage[files.Length];
for (int i = 0; i < files.Length; i++)
{
AtalaImage image = new AtalaImage(files[i]);
string fn = Path.GetFileName(files[i]);
fileImages[i] = new FilenameImage { Filename = fn, Image = image };
}
return fileImages;
}
Then I built the application framework – there is a button that initiates shuffling. I chose a cascading state machine for the model of operation. When the shuffle button is pressed, it disables itself and activates a fast timer (actually, the timer is always running, but isn’t working):
private void hitMe_Click(object sender, EventArgs e)
{
department.Text = "";
hitMe.Enabled = false;
_fastSpinCount = 20;
}
The fast timer handler looks like this:
private void fastTimer_Tick(object sender, EventArgs e)
{
if (_fastSpinCount == 0)
return;
imageViewer1.Image = GetRandomImage();
imageViewer1.Invalidate();
_fastSpinCount--;
if (_fastSpinCount == 0)
{
_slowSpinCount = 8;
}
}
In this code, if _fastSpinCount is 0, nothing happens. Otherwise, it sets the Atalasoft ImageViewer to display a “random” image (the randomness is such that the same image is never selected twice). If it has counted down to 0, then the _slowSpinCount is activated.
Here’s the slow timer handler:
private void slowTimer_Tick(object sender, EventArgs e)
{
if (_slowSpinCount == 0)
return;
_slowSpinCount--;
if (_slowSpinCount == 0)
{
imageViewer1.Image = GetChosenImage(_choice);
this.department.Text = _deptPics[_choice].Name;
_choice++;
hitMe.Enabled = _choice < _deptPics.Length;
}
else
{
imageViewer1.Image = GetRandomImage();
imageViewer1.Invalidate();
}
}
In this code, if it’s not active, it does nothing. Otherwise it drops its count. If it reaches zero, it displays the next department image and sets the text for it. If there are more departments, the shuffle button is enabled. If the count is non-zero, a new random image is displayed.
Clearly, there are a number of things that should be in a professional application that aren’t here (error checking being the most important). The application was very straight forward to write, however, and I was quite happy to not have to worry about the imaging at all, but just get the app done in my time budget.