2009-02-22 10:43:35 +00:00
|
|
|
|
#region --- License ---
|
|
|
|
|
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
|
|
|
|
* See license.txt for license info
|
|
|
|
|
*/
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
|
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
2009-08-14 13:13:28 +00:00
|
|
|
|
using OpenTK.Graphics.OpenGL;
|
2009-02-22 10:43:35 +00:00
|
|
|
|
using OpenTK.Input;
|
|
|
|
|
|
|
|
|
|
namespace Examples.Tests
|
|
|
|
|
{
|
2009-04-21 13:33:25 +00:00
|
|
|
|
[Example("GameWindow states", ExampleCategory.OpenTK, "Test", Documentation="GameWindowStates")]
|
2009-02-22 10:43:35 +00:00
|
|
|
|
public class GameWindowStates : GameWindow
|
|
|
|
|
{
|
|
|
|
|
Font font = new Font(FontFamily.GenericSansSerif, 16.0f);
|
|
|
|
|
TextPrinter printer = new TextPrinter();
|
|
|
|
|
|
|
|
|
|
public GameWindowStates()
|
|
|
|
|
: base(800, 600)
|
|
|
|
|
{
|
|
|
|
|
this.VSync = VSyncMode.On;
|
|
|
|
|
this.Keyboard.KeyRepeat = true;
|
|
|
|
|
this.Keyboard.KeyUp += new OpenTK.Input.KeyUpEvent(Keyboard_KeyUp);
|
|
|
|
|
|
|
|
|
|
GL.ClearColor(System.Drawing.Color.MidnightBlue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Keyboard_KeyUp(KeyboardDevice sender, Key key)
|
|
|
|
|
{
|
|
|
|
|
switch (key)
|
|
|
|
|
{
|
|
|
|
|
case OpenTK.Input.Key.Escape:
|
|
|
|
|
this.Exit();
|
|
|
|
|
break;
|
|
|
|
|
|
2009-08-14 13:13:28 +00:00
|
|
|
|
case Key.Number1:
|
|
|
|
|
WindowState = WindowState.Normal;
|
|
|
|
|
break;
|
|
|
|
|
case Key.Number2:
|
|
|
|
|
WindowState = WindowState.Maximized;
|
|
|
|
|
break;
|
|
|
|
|
case Key.Number3:
|
|
|
|
|
WindowState = WindowState.Fullscreen;
|
|
|
|
|
break;
|
|
|
|
|
case Key.Number4:
|
|
|
|
|
WindowState = WindowState.Minimized;
|
2009-02-22 10:43:35 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2009-08-14 13:13:28 +00:00
|
|
|
|
case Key.Number5:
|
|
|
|
|
WindowBorder = WindowBorder.Resizable;
|
2009-02-22 10:43:35 +00:00
|
|
|
|
break;
|
2009-08-14 13:13:28 +00:00
|
|
|
|
case Key.Number6:
|
|
|
|
|
WindowBorder = WindowBorder.Fixed;
|
|
|
|
|
break;
|
|
|
|
|
case Key.Number7:
|
|
|
|
|
WindowBorder = WindowBorder.Hidden;
|
2009-02-22 10:43:35 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
|
protected override void OnResize(EventArgs e)
|
2009-02-22 10:43:35 +00:00
|
|
|
|
{
|
|
|
|
|
GL.Viewport(0, 0, Width, Height);
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
|
protected override void OnRenderFrame(FrameEventArgs e)
|
2009-02-22 10:43:35 +00:00
|
|
|
|
{
|
|
|
|
|
GL.Clear(ClearBufferMask.ColorBufferBit);
|
|
|
|
|
|
|
|
|
|
printer.Begin();
|
|
|
|
|
|
|
|
|
|
printer.Print("Instructions:", font, Color.White);
|
|
|
|
|
GL.Translate(0, font.Height, 0);
|
2009-08-14 13:13:28 +00:00
|
|
|
|
printer.Print(String.Format("[1 - 4]: change WindowState (current: {0}).", this.WindowState), font, Color.White, RectangleF.Empty);
|
2009-02-22 10:43:35 +00:00
|
|
|
|
GL.Translate(0, font.Height, 0);
|
2009-08-14 13:13:28 +00:00
|
|
|
|
printer.Print(String.Format("[5 - 7]: change WindowBorder (current: {0}).", this.WindowBorder), font, Color.White, RectangleF.Empty);
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
|
|
printer.End();
|
|
|
|
|
|
|
|
|
|
SwapBuffers();
|
|
|
|
|
Thread.Sleep(5);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Main()
|
|
|
|
|
{
|
|
|
|
|
using (GameWindowStates ex = new GameWindowStates())
|
|
|
|
|
{
|
|
|
|
|
Utilities.SetWindowTitle(ex);
|
|
|
|
|
ex.Run(20.0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|