2012-12-21 21:22:37 +00:00
|
|
|
|
// 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
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Demonstrates basic recommended mouse input, and to see if it actually works
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Example("Basic Mouse Input", ExampleCategory.OpenTK,"Basic Mouse Input")]
|
|
|
|
|
public class BasicMouseInput : GameWindow
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public BasicMouseInput()
|
2013-01-24 21:48:01 +00:00
|
|
|
|
: base(800, 600)
|
2012-12-21 21:22:37 +00:00
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnLoad(e);
|
2013-01-03 16:07:50 +00:00
|
|
|
|
|
|
|
|
|
this.Mouse.ButtonUp += (object sender, MouseButtonEventArgs buttonEvent) => {
|
|
|
|
|
Console.WriteLine("Mouse button up: " + buttonEvent.Button + " at: " + buttonEvent.Position);
|
|
|
|
|
};
|
2012-12-22 03:22:55 +00:00
|
|
|
|
|
2012-12-21 21:22:37 +00:00
|
|
|
|
GL.ClearColor(Color.MidnightBlue);
|
|
|
|
|
GL.Enable(EnableCap.DepthTest);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnUpdateFrame(FrameEventArgs e)
|
|
|
|
|
{
|
2013-01-24 21:48:01 +00:00
|
|
|
|
base.OnUpdateFrame(e);
|
|
|
|
|
|
2012-12-21 21:22:37 +00:00
|
|
|
|
// Here's the big test!
|
|
|
|
|
if(OpenTK.Input.Mouse.GetState()[MouseButton.Left]){
|
2012-12-21 23:11:39 +00:00
|
|
|
|
Console.WriteLine("The left mouse button is down!");
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-22 03:22:55 +00:00
|
|
|
|
|
2012-12-21 23:11:39 +00:00
|
|
|
|
// While we are here, test keyboard.
|
|
|
|
|
if(OpenTK.Input.Keyboard.GetState()[Key.A]){
|
2012-12-22 00:43:19 +00:00
|
|
|
|
Console.WriteLine("The A key is down!");
|
2012-12-21 21:22:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2013-01-24 21:48:01 +00:00
|
|
|
|
GL.Clear(ClearBufferMask.ColorBufferBit);
|
2012-12-21 21:22:37 +00:00
|
|
|
|
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);
|
2013-01-24 21:48:01 +00:00
|
|
|
|
|
|
|
|
|
example.Run(30.0);
|
2012-12-21 21:22:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|