PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/Samples/ExampleToolWPF/MainWindow.xaml.cs

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