view Progress.cs @ 0:8439bec53421

Initial commit under the GPLv3
author IBBoard <dev@ibboard.co.uk>
date Sat, 06 Oct 2018 20:00:56 +0100
parents
children
line wrap: on
line source

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

using IBBoard.Relic.RelicTools;

namespace IBBoard.Relic.IChunkyViewer
{
	/// <summary>
	/// Summary description for Progress.
	/// </summary>
	public class Progress : System.Windows.Forms.Form
	{
		private System.Windows.Forms.ProgressBar progressBar;
		private System.Windows.Forms.Timer timer;
		private System.Windows.Forms.Label lblProgress;
		private System.ComponentModel.IContainer components;

		Form1.ChunkyOpenedDelegate OnChunkyOpened = null;
		Form1.ChunkyNodesCountedDelegate OnChunkyNodesCounted = null;
		Form1.ChunkyNodeAddedDelegate OnChunkyNodeAdded = null;
		Form1.ChunkyNodesAddedDelegate OnChunkyNodesAdded = null;
		Form1.ChunkyOpenFailedDelegate OnChunkyOpenFailed = null;
		Form1 parent;

		public Progress(Form1 parent)
		{
			OnChunkyOpened = new Form1.ChunkyOpenedDelegate(chunkyOpened);
			OnChunkyNodesCounted = new Form1.ChunkyNodesCountedDelegate(nodesCounted);
			OnChunkyNodeAdded = new Form1.ChunkyNodeAddedDelegate(nodeAdded);
			OnChunkyNodesAdded = new Form1.ChunkyNodesAddedDelegate(nodesAdded);
			OnChunkyOpenFailed = new Form1.ChunkyOpenFailedDelegate(openFailed);

			parent.OnChunkyOpened+= OnChunkyOpened;
			parent.OnChunkyNodesCounted+= OnChunkyNodesCounted;
			parent.OnChunkyNodeAdded+= OnChunkyNodeAdded;
			parent.OnChunkyNodesAdded+= OnChunkyNodesAdded;
			parent.OnChunkyOpenFailed+= OnChunkyOpenFailed;

			InitializeComponent();

			this.parent = parent;

			timer.Enabled = true;
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{			
			parent.OnChunkyOpened-= OnChunkyOpened;
			parent.OnChunkyNodesCounted-= OnChunkyNodesCounted;
			parent.OnChunkyNodeAdded-= OnChunkyNodeAdded;
			parent.OnChunkyNodesAdded-= OnChunkyNodesAdded;
			parent.OnChunkyOpenFailed-= OnChunkyOpenFailed;

			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			this.progressBar = new System.Windows.Forms.ProgressBar();
			this.timer = new System.Windows.Forms.Timer(this.components);
			this.lblProgress = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// progressBar
			// 
			this.progressBar.Location = new System.Drawing.Point(8, 8);
			this.progressBar.Name = "progressBar";
			this.progressBar.Size = new System.Drawing.Size(288, 23);
			this.progressBar.TabIndex = 0;
			// 
			// timer
			// 
			this.timer.Interval = 40;
			this.timer.Tick += new System.EventHandler(this.timer_Tick);
			// 
			// lblProgress
			// 
			this.lblProgress.Location = new System.Drawing.Point(8, 32);
			this.lblProgress.Name = "lblProgress";
			this.lblProgress.Size = new System.Drawing.Size(288, 23);
			this.lblProgress.TabIndex = 1;
			this.lblProgress.Text = "Loading Chunky file...";
			this.lblProgress.TextAlign = System.Drawing.ContentAlignment.TopRight;
			// 
			// Progress
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(304, 52);
			this.ControlBox = false;
			this.Controls.Add(this.lblProgress);
			this.Controls.Add(this.progressBar);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
			this.Name = "Progress";
			this.ShowInTaskbar = false;
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
			this.Text = "Loading Relic Chunky file...";
			this.ResumeLayout(false);

		}
		#endregion

		private void timer_Tick(object sender, System.EventArgs e)
		{
			progressBar.PerformStep();
		}

		private void nodesCounted(int nodes)
		{
			lblProgress.Text = "Adding chunks...";
			timer.Enabled = false;
			progressBar.Step = 1;
			progressBar.Value = 1;
			progressBar.Minimum = 1;
			progressBar.Maximum = nodes;
		}

		private void nodeAdded(ChunkyChunk chunk)
		{
			progressBar.PerformStep();
		}

		private void nodesAdded(bool rendered)
		{
			progressBar.Value = progressBar.Maximum;
			
			if (rendered)
			{
				this.Close();
				this.Dispose();
			}
			else
			{
				lblProgress.Text = "Displaying tree...";
			}
		}

		private void chunkyOpened(string filename)
		{
			lblProgress.Text = "Counting chunks...";
		}

		private void openFailed()
		{
			timer.Enabled = false;
			progressBar.Value = progressBar.Maximum;
			this.Hide();
			this.Close();
			try
			{
				this.Dispose();
			}
			catch{}
		}
	}
}