2008-04-20 17:59:05 +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;
|
2008-05-03 16:34:39 +00:00
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Threading;
|
2008-04-20 17:59:05 +00:00
|
|
|
|
|
|
|
|
|
using OpenTK;
|
2008-05-03 16:34:39 +00:00
|
|
|
|
using OpenTK.Graphics;
|
2008-05-03 16:33:17 +00:00
|
|
|
|
using OpenTK.Input;
|
2008-04-20 17:59:05 +00:00
|
|
|
|
|
|
|
|
|
namespace Examples.Tests
|
|
|
|
|
{
|
|
|
|
|
[Example("GameWindow states.", ExampleCategory.Test)]
|
|
|
|
|
public class GameWindowStates : GameWindow
|
|
|
|
|
{
|
2008-04-25 21:32:43 +00:00
|
|
|
|
TextureFont font = new TextureFont(new Font(FontFamily.GenericSansSerif, 16.0f));
|
2008-05-03 16:34:39 +00:00
|
|
|
|
TextPrinter printer = new TextPrinter();
|
|
|
|
|
|
|
|
|
|
WindowState[] window_state_sequence = new WindowState[]
|
|
|
|
|
{
|
|
|
|
|
WindowState.Normal,
|
|
|
|
|
WindowState.Maximized,
|
|
|
|
|
WindowState.Fullscreen,
|
|
|
|
|
WindowState.Minimized
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
WindowBorder[] window_border_sequence = new WindowBorder[]
|
|
|
|
|
{
|
|
|
|
|
WindowBorder.Resizable,
|
|
|
|
|
WindowBorder.Fixed,
|
|
|
|
|
WindowBorder.Hidden,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int window_state_counter = 0;
|
|
|
|
|
int WindowStateCounter
|
|
|
|
|
{
|
|
|
|
|
get { return window_state_counter; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value < 0)
|
|
|
|
|
window_state_counter = window_state_sequence.Length - 1;
|
|
|
|
|
else
|
|
|
|
|
window_state_counter = ++window_state_counter % window_state_sequence.Length;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int window_border_counter = 0;
|
|
|
|
|
int WindowBorderCounter
|
|
|
|
|
{
|
|
|
|
|
get { return window_border_counter; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value < 0)
|
|
|
|
|
window_border_counter = window_border_sequence.Length - 1;
|
|
|
|
|
else
|
|
|
|
|
window_border_counter = ++window_border_counter % window_border_sequence.Length;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-03 16:33:17 +00:00
|
|
|
|
|
2008-04-21 20:19:12 +00:00
|
|
|
|
|
2008-04-20 17:59:05 +00:00
|
|
|
|
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.SteelBlue);
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-03 16:33:17 +00:00
|
|
|
|
void Keyboard_KeyUp(KeyboardDevice sender, Key key)
|
2008-04-20 17:59:05 +00:00
|
|
|
|
{
|
2008-04-21 20:19:12 +00:00
|
|
|
|
switch (key)
|
2008-04-20 17:59:05 +00:00
|
|
|
|
{
|
2008-04-21 20:19:12 +00:00
|
|
|
|
case OpenTK.Input.Key.Escape:
|
|
|
|
|
this.Exit();
|
|
|
|
|
break;
|
|
|
|
|
|
2008-05-03 16:34:39 +00:00
|
|
|
|
case OpenTK.Input.Key.Number1:
|
|
|
|
|
if (sender[Key.ShiftLeft] || sender[Key.ShiftRight])
|
|
|
|
|
WindowStateCounter--;
|
|
|
|
|
else
|
|
|
|
|
WindowStateCounter++;
|
|
|
|
|
WindowState = window_state_sequence[WindowStateCounter];
|
2008-05-03 16:33:17 +00:00
|
|
|
|
|
|
|
|
|
// switch (this.WindowState)
|
|
|
|
|
// {
|
|
|
|
|
// case WindowState.Normal: this.WindowState = WindowState.Maximized; break;1
|
2008-05-03 16:34:39 +00:00
|
|
|
|
// case WindowState.Maximized: this.WindowState = WindowState.Fullscreen; break;
|
|
|
|
|
// case WindowState.Fullscreen:
|
|
|
|
|
// this.WindowState = WindowState.Normal;
|
|
|
|
|
// this.WindowState = WindowState.Minimized;
|
|
|
|
|
// break;
|
2008-05-03 16:33:17 +00:00
|
|
|
|
// case WindowState.Minimized: this.WindowState = WindowState.Normal;
|
|
|
|
|
// break;
|
|
|
|
|
//
|
|
|
|
|
// }
|
2008-04-21 20:19:12 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2008-05-03 16:34:39 +00:00
|
|
|
|
case OpenTK.Input.Key.Number2:
|
|
|
|
|
if (sender[Key.ShiftLeft] || sender[Key.ShiftRight])
|
|
|
|
|
WindowBorderCounter--;
|
|
|
|
|
else
|
|
|
|
|
WindowBorderCounter++;
|
2008-05-03 16:33:17 +00:00
|
|
|
|
WindowBorder = window_border_sequence[WindowBorderCounter];
|
|
|
|
|
// this.WindowState = WindowState.Normal;
|
|
|
|
|
// switch (this.WindowBorder)
|
|
|
|
|
// {
|
|
|
|
|
// case WindowBorder.Fixed: this.WindowBorder = WindowBorder.Hidden; break;
|
|
|
|
|
// case WindowBorder.Hidden: this.WindowBorder = WindowBorder.Resizable; break;
|
|
|
|
|
// case WindowBorder.Resizable: this.WindowBorder = WindowBorder.Fixed; break;
|
|
|
|
|
// }
|
2008-04-21 20:19:12 +00:00
|
|
|
|
|
2008-05-03 16:34:39 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case OpenTK.Input.Key.Number3:
|
|
|
|
|
if (this.WindowState == WindowState.Fullscreen)
|
|
|
|
|
this.WindowState = WindowState.Normal;
|
|
|
|
|
else
|
|
|
|
|
this.WindowState = WindowState.Fullscreen;
|
|
|
|
|
|
2008-04-21 20:19:12 +00:00
|
|
|
|
break;
|
2008-04-20 17:59:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-21 20:19:12 +00:00
|
|
|
|
protected override void OnResize(OpenTK.Platform.ResizeEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
GL.Viewport(0, 0, Width, Height);
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-20 17:59:05 +00:00
|
|
|
|
public override void OnRenderFrame(RenderFrameEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
GL.Clear(ClearBufferMask.ColorBufferBit);
|
|
|
|
|
|
2008-04-21 20:19:12 +00:00
|
|
|
|
printer.Begin();
|
|
|
|
|
|
|
|
|
|
printer.Draw("Instructions:", font); GL.Translate(0, font.Height, 0);
|
2008-05-03 16:34:39 +00:00
|
|
|
|
printer.Draw(String.Format("1 - cycle through window styles (current: {0}).", this.WindowState), font);
|
|
|
|
|
GL.Translate(0, font.Height, 0);
|
|
|
|
|
printer.Draw(String.Format("2 - cycle through window borders (current: {0}).", this.WindowBorder), font);
|
2008-04-25 21:32:43 +00:00
|
|
|
|
GL.Translate(0, font.Height, 0);
|
2008-05-03 16:34:39 +00:00
|
|
|
|
printer.Draw(String.Format("3 - toggle fullscreen (current: {0}).",
|
|
|
|
|
this.WindowState == WindowState.Fullscreen ? "enabled" : "disabled"), font);
|
2008-04-25 21:32:43 +00:00
|
|
|
|
|
2008-04-21 20:19:12 +00:00
|
|
|
|
|
|
|
|
|
printer.End();
|
|
|
|
|
|
2008-05-03 16:34:39 +00:00
|
|
|
|
SwapBuffers();
|
2008-05-03 16:33:17 +00:00
|
|
|
|
Thread.Sleep(5);
|
2008-04-20 17:59:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Main()
|
|
|
|
|
{
|
|
|
|
|
using (GameWindowStates ex = new GameWindowStates())
|
|
|
|
|
{
|
2008-05-03 16:34:39 +00:00
|
|
|
|
Utilities.SetWindowTitle(ex);
|
2008-04-20 17:59:05 +00:00
|
|
|
|
ex.Run(20.0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|