2007-08-10 09:27:13 +00:00
|
|
|
|
#region --- License ---
|
|
|
|
|
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
|
|
|
|
* See license.txt for license info
|
|
|
|
|
*/
|
|
|
|
|
#endregion
|
|
|
|
|
|
2007-08-10 16:55:24 +00:00
|
|
|
|
#region --- Using Directives ---
|
|
|
|
|
|
2007-08-10 09:27:13 +00:00
|
|
|
|
using System;
|
2007-07-23 00:15:18 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Threading;
|
2007-07-27 12:06:32 +00:00
|
|
|
|
using System.Diagnostics;
|
2007-08-03 00:14:31 +00:00
|
|
|
|
using System.Security;
|
|
|
|
|
using System.Security.Permissions;
|
|
|
|
|
using System.Security.Policy;
|
2007-08-04 12:09:58 +00:00
|
|
|
|
using System.IO;
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
2007-08-10 16:55:24 +00:00
|
|
|
|
using OpenTK;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2007-07-23 00:15:18 +00:00
|
|
|
|
namespace Examples
|
|
|
|
|
{
|
|
|
|
|
public partial class ExampleLauncher : Form
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The main entry point for the application.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[STAThread]
|
|
|
|
|
static void Main()
|
|
|
|
|
{
|
2007-08-10 16:55:24 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (File.Exists("debug.log"))
|
|
|
|
|
File.Delete("debug.log");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Could not access debug.log");
|
|
|
|
|
}
|
2007-08-05 13:42:31 +00:00
|
|
|
|
|
2007-08-10 16:55:24 +00:00
|
|
|
|
Debug.Listeners.Add(new TextWriterTraceListener("debug.log"));
|
|
|
|
|
|
2007-08-05 13:42:31 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using (Form exampleLauncher = new ExampleLauncher())
|
|
|
|
|
{
|
|
|
|
|
Application.EnableVisualStyles();
|
|
|
|
|
Application.Run(exampleLauncher);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
Debug.Flush();
|
|
|
|
|
Debug.Close();
|
|
|
|
|
Trace.Flush();
|
|
|
|
|
Trace.Close();
|
|
|
|
|
}
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-05 13:42:31 +00:00
|
|
|
|
public ExampleLauncher()
|
2007-08-04 12:09:58 +00:00
|
|
|
|
{
|
2007-08-05 13:42:31 +00:00
|
|
|
|
InitializeComponent();
|
2007-08-04 12:09:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-07-23 00:15:18 +00:00
|
|
|
|
private void listBox1_DoubleClick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (listBox1.SelectedItem != null)
|
|
|
|
|
{
|
|
|
|
|
Type example =
|
|
|
|
|
Assembly.GetExecutingAssembly().GetType(
|
|
|
|
|
"Examples." + listBox1.SelectedItem.ToString().Replace(": ", ".").Replace(' ', '_'),
|
|
|
|
|
true,
|
2007-08-10 16:55:24 +00:00
|
|
|
|
true);
|
|
|
|
|
|
|
|
|
|
Debug.Print("Launching example: {0}", example.ToString());
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
|
|
|
|
if (example.BaseType == typeof(GameWindow))
|
|
|
|
|
{
|
|
|
|
|
// Start the GameWindow in a new thread - it runs its own message loop, and it would
|
|
|
|
|
// interfere with the message loop of the ExampleLauncher.
|
|
|
|
|
new Thread(Launch).Start(example);
|
|
|
|
|
}
|
|
|
|
|
else if (example.BaseType == typeof(Form))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// In this we do not want a different thread: these examples rely on the Application.Idle
|
|
|
|
|
// event, which would then be raised by both the ExampleLauncher thread *and* the new one!
|
|
|
|
|
this.AddOwnedForm((Form)example.GetConstructor(Type.EmptyTypes).Invoke(null));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception expt)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(
|
|
|
|
|
String.Format(
|
|
|
|
|
"Stacktrace:{0}{1}{0}{0}Inner exception:{0}{2}",
|
|
|
|
|
System.Environment.NewLine,
|
|
|
|
|
expt.StackTrace,
|
|
|
|
|
expt.InnerException
|
|
|
|
|
),
|
2007-08-10 16:55:24 +00:00
|
|
|
|
expt.Message);
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Launch(object example)
|
|
|
|
|
{
|
2007-08-03 00:14:31 +00:00
|
|
|
|
Type ex = example as Type;
|
2007-08-04 12:09:58 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
(ex.GetConstructor(Type.EmptyTypes).Invoke(null) as IExample).Launch();
|
|
|
|
|
}
|
2007-08-10 16:55:24 +00:00
|
|
|
|
catch (Exception expt)
|
2007-08-04 12:09:58 +00:00
|
|
|
|
{
|
2007-08-10 16:55:24 +00:00
|
|
|
|
MessageBox.Show(
|
|
|
|
|
String.Format(
|
|
|
|
|
"Stacktrace:{0}{1}{0}{0}Inner exception:{0}{2}",
|
|
|
|
|
System.Environment.NewLine,
|
|
|
|
|
expt.StackTrace,
|
|
|
|
|
expt.InnerException
|
|
|
|
|
),
|
|
|
|
|
expt.Message);
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ExampleLauncher_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
SortedList<string, string> sl = new SortedList<string, string>();
|
|
|
|
|
|
|
|
|
|
// Get all examples
|
|
|
|
|
Type[] types = Assembly.GetExecutingAssembly().GetTypes();
|
|
|
|
|
foreach (Type type in types)
|
|
|
|
|
{
|
|
|
|
|
if (type.GetInterface("IExample") != null)
|
|
|
|
|
{
|
|
|
|
|
sl.Add(
|
|
|
|
|
(type.Namespace.Replace("Examples.", String.Empty) + ": " + type.Name).Replace('_', ' '),
|
|
|
|
|
null
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (string s in sl.Keys)
|
|
|
|
|
listBox1.Items.Add(s);
|
|
|
|
|
|
|
|
|
|
// Select first item
|
|
|
|
|
if (listBox1.Items.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
this.listBox1.SelectedIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-08-10 09:27:13 +00:00
|
|
|
|
}
|