From 3c609872fe0e2757f70737be5d72ca884f47ea45 Mon Sep 17 00:00:00 2001 From: Andy Korth Date: Fri, 21 Dec 2012 15:22:37 -0600 Subject: [PATCH] New test for Basic Mouse Input. Does not work on Mac. --- Source/Examples/Main.cs | 2 + .../Examples/OpenTK/Test/BasicMouseInput.cs | 76 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 Source/Examples/OpenTK/Test/BasicMouseInput.cs diff --git a/Source/Examples/Main.cs b/Source/Examples/Main.cs index 56e08415..ad30e767 100644 --- a/Source/Examples/Main.cs +++ b/Source/Examples/Main.cs @@ -49,6 +49,8 @@ namespace Examples Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); + // Examples.Tests.BasicMouseInput.Main (); + using (Form browser = new ExampleBrowser()) { try diff --git a/Source/Examples/OpenTK/Test/BasicMouseInput.cs b/Source/Examples/OpenTK/Test/BasicMouseInput.cs new file mode 100644 index 00000000..4ab4f63f --- /dev/null +++ b/Source/Examples/OpenTK/Test/BasicMouseInput.cs @@ -0,0 +1,76 @@ +// This code was written for the OpenTK library and has been released +// to the Public Domain by Andy Korth +// It is provided "as is" without express or implied warranty of any kind. + +#region --- Using Directives --- + +using System; +using System.Collections.Generic; +using System.Drawing; + +using OpenTK; +using OpenTK.Graphics; +using OpenTK.Graphics.OpenGL; +using OpenTK.Input; + +#endregion --- Using Directives --- + +namespace Examples.Tests +{ + /// + /// Demonstrates basic recommended mouse input, and to see if it actually works + /// + [Example("Basic Mouse Input", ExampleCategory.OpenTK,"Basic Mouse Input")] + public class BasicMouseInput : GameWindow + { + + public BasicMouseInput() + : base(800, 600, GraphicsMode.Default) + { } + + protected override void OnLoad(EventArgs e) + { + base.OnLoad(e); + + GL.ClearColor(Color.MidnightBlue); + GL.Enable(EnableCap.DepthTest); + } + + protected override void OnUpdateFrame(FrameEventArgs e) + { + // Here's the big test! + if(OpenTK.Input.Mouse.GetState()[MouseButton.Left]){ + Console.WriteLine("You clicked the left mouse button!"); + } + + if (Keyboard[OpenTK.Input.Key.Escape]) + this.Exit(); + + if (Keyboard[OpenTK.Input.Key.F11]) + if (WindowState != WindowState.Fullscreen) + WindowState = WindowState.Fullscreen; + else + WindowState = WindowState.Normal; + } + + + protected override void OnRenderFrame(FrameEventArgs e) + { + GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); + SwapBuffers(); + } + + [STAThread] + public static void Main() + { + using (BasicMouseInput example = new BasicMouseInput()) + { + // Get the title and category of this example using reflection. + ExampleAttribute info = ((ExampleAttribute)example.GetType().GetCustomAttributes(false)[0]); + example.Title = String.Format("OpenTK | {0} {1}: {2}", info.Category, info.Difficulty, info.Title); + example.Run(30.0, 0.0); + } + } + + } +}