Manage your ASL charts, play aids and other documents.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
asl-charts/src/MainForm.cs

78 lines
3.0 KiB

using System ;
using System.Text ;
using System.Drawing ;
using System.IO ;
using System.Runtime.InteropServices ;
using System.Collections.Generic ;
using System.Windows.Forms ;
using System.Diagnostics ;
// --------------------------------------------------------------------
public class MainForm : Form
{
private readonly HashSet<string> mValidImageExtensions = new HashSet<string>{ ".png", ".jpg", ".gif" } ;
private Dictionary<string,Image> mImages = new Dictionary<string,Image>() ;
private Dictionary<string,Image>.Enumerator mImagesIter ;
private PictureBox mImagePictureBox = new PictureBox() ;
public MainForm()
{
// initialize the form
this.Text = Program.APP_NAME ;
this.MinimumSize = new Size( 800, 500 ) ;
// initialize the form
// FIXME! We will probably need something better to render the images, but this will do, for now...
this.mImagePictureBox.Dock = DockStyle.Fill ;
this.mImagePictureBox.SizeMode = PictureBoxSizeMode.Zoom ;
this.Controls.Add( mImagePictureBox ) ;
// initialize handlers
this.Load += new EventHandler( this.MainForm_Load ) ;
this.KeyDown += new System.Windows.Forms.KeyEventHandler( this.MainForm_KeyDown ) ;
}
private void MainForm_Load( object sender, EventArgs args )
{
// locate the image files
string dataDir = Path.GetFullPath( Program.dataDir ) ;
IEnumerable<string> files = Directory.EnumerateFiles(
dataDir, "*.*", SearchOption.AllDirectories
) ;
foreach( string fname in files ) {
string extn = Path.GetExtension( fname ).ToLower() ;
if ( ! mValidImageExtensions.Contains( extn ) )
continue ;
string fname2 = Path.GetFullPath( fname ) ;
if ( fname2.StartsWith( dataDir ) ) {
fname2 = fname.Substring( dataDir.Length ) ;
if ( fname2.StartsWith( "/" ) || fname2.StartsWith( "\\" ) )
fname2 = fname2.Substring( 1 ) ;
} else {
// NOTE: I don't think we should ever get here :-/ If we do, the user will have to manage
// their configuration using full paths for the image files, but at least we will still run...
}
Program.logTraceMsg( String.Format( "Loading image: {0}", fname2 ) ) ;
mImages[ fname2 ] = Image.FromFile( fname ) ;
}
mImagesIter = mImages.GetEnumerator() ;
}
private void MainForm_KeyDown( object sender, KeyEventArgs args )
{
// FIXME! For now, we just allow the user to cycle through the loaded images.
if ( args.KeyCode == Keys.Space ) {
// show the next image
KeyValuePair<String,Image> val ;
if ( ! mImagesIter.MoveNext() ) {
mImagesIter = mImages.GetEnumerator() ;
mImagesIter.MoveNext() ;
}
val = mImagesIter.Current ;
mImagePictureBox.Image = val.Value ;
}
}
}