PageRenderTime 92ms CodeModel.GetById 40ms app.highlight 14ms RepoModel.GetById 27ms app.codeStats 6ms

/Samples/ExampleToolWPF/MainWindow.xaml.cs

#
C# | 67 lines | 45 code | 6 blank | 16 comment | 2 complexity | f604c573a66d3bc02986820eaa4d1a6a MD5 | raw file
 1using Delta.Platforms.Windows;
 2using Delta.Engine;
 3using Delta.Rendering.Basics.Materials;
 4using Delta.Utilities.Datatypes;
 5using Delta.InputSystem;
 6using Delta.Rendering.Basics.Drawing;
 7using Delta.Rendering.Basics.Fonts;
 8using FormsColor = System.Drawing.Color;
 9using FormsPanel = System.Windows.Forms.Panel;
10
11namespace Delta.Tools.ExampleToolWPF
12{
13	/// <summary>
14	/// Sample on how to integrate WPF editors and tools with the Delta Engine!
15	/// </summary>
16	public partial class MainWindow : System.Windows.Window
17	{
18		#region Constructor
19		/// <summary>
20		/// Create main window
21		/// </summary>
22		public MainWindow()
23		{
24			InitializeComponent();
25
26			// Setup the WPF window and create a panel in the ViewportHoster for us
27			WindowsApplication.SetEditorWPFWindow(this, ViewportHoster);
28			
29			// Do initialization code like setting the background color (optional)
30			Application.BackgroundColor = Color.DarkBlue;//.Green;//LightBlue;
31
32			float wheelValue = 0.0f;
33			// And finally start the Delta Engine like you normally would
34			Application.Start(delegate
35			{
36				// Line from top left up to bottom right in quadratic space
37				Line.Draw(new Point(0, 0), new Point(1, 1), Color.Red);
38				// Draw a rotating default material in the middle
39				Material2D.Default.Draw(Rectangle.FromCenter(Point.Half, 0.25f),
40					Time.Milliseconds / 25.0f);
41
42				// Also draw some information about the mouse
43				Font.Default.Draw("Mouse: " + Input.Mouse.Position,
44					Rectangle.FromCenter(Point.Half, Size.Half));
45				float wheelDelta = Input.Mouse.ScrollWheelDelta;
46				if (wheelDelta != 0)
47				{
48					wheelValue += wheelDelta;
49				} // if
50				Font.Default.Draw("Mouse wheelValue= '" + wheelValue + "'",
51					Rectangle.FromCenter(new Point(0.5f, 0.55f), Size.Half));
52			});
53		}
54		#endregion
55
56		#region OnExitClicked
57		/// <summary>
58		/// On exit clicked, not needed, just shown as an example how to quit the
59		/// whole app (including the engine and the wpf tool window).
60		/// </summary>
61		private void OnExitClicked(object sender, System.Windows.RoutedEventArgs e)
62		{
63			Application.Quit();
64		}
65		#endregion
66	}
67}