Fullscreen mode changes now work!

This commit is contained in:
the_fiddler 2008-01-24 12:36:40 +00:00
parent 54224ed65c
commit 3a026d5d5e
6 changed files with 76 additions and 18 deletions

View file

@ -14,6 +14,7 @@ using OpenTK;
using OpenTK.OpenGL;
using OpenTK.Fonts;
using OpenTK.OpenGL.Enums;
using OpenTK.Input;
namespace Examples.Tutorial
{
@ -23,8 +24,28 @@ namespace Examples.Tutorial
[Example("Simple Window", ExampleCategory.Tutorial, 1)]
public class T01_Simple_Window : GameWindow
{
public T01_Simple_Window() : base(new DisplayMode(800, 600))
{ }
public T01_Simple_Window() : base()
{
Keyboard.KeyDown += new OpenTK.Input.KeyDownEvent(Keyboard_KeyDown);
}
#region Keyboard_KeyDown
/// <summary>
/// Occurs when a key is pressed.
/// </summary>
/// <param name="sender">The KeyboardDevice which generated this event.</param>
/// <param name="key">The key that was pressed.</param>
void Keyboard_KeyDown(KeyboardDevice sender, Key key)
{
if ((sender[Key.AltLeft] || sender[Key.AltRight]) && sender[Key.Enter])
this.Fullscreen = !this.Fullscreen;
if (sender[Key.Escape])
this.Exit();
}
#endregion
#region OnLoad
@ -68,10 +89,7 @@ namespace Examples.Tutorial
/// <remarks>There is no need to call the base implementation.</remarks>
public override void OnUpdateFrame(UpdateFrameEventArgs e)
{
base.OnUpdateFrame(e);
if (Keyboard[OpenTK.Input.Key.Escape])
this.Exit();
// Nothing to do!
}
#endregion
@ -114,8 +132,7 @@ namespace Examples.Tutorial
using (T01_Simple_Window example = new T01_Simple_Window())
{
// 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);
Utilities.SetWindowTitle(example);
example.Run(30.0, 0.0);
}
}

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Text;
using System.Drawing;
using OpenTK;
using OpenTK.Input;
namespace Examples
{

View file

@ -201,8 +201,8 @@ namespace OpenTK
/// </summary>
public bool Fullscreen
{
get { return false;/* return glWindow.Fullscreen; */ }
set { /* glWindow.Fullscreen = value; */}
get { return glWindow.Fullscreen; }
set { glWindow.Fullscreen = value; }
}
#endregion

View file

@ -31,6 +31,7 @@ namespace OpenTK.Platform
bool IsIdle { get; }
//IGLContext Context { get; }
IInputDriver InputDriver { get; }
bool Fullscreen { get; set; }
event CreateEvent Create;
event DestroyEvent Destroy;

View file

@ -2299,6 +2299,13 @@ namespace OpenTK.Platform.Windows
[StructLayout(LayoutKind.Sequential)]
internal struct Rectangle
{
internal Rectangle(int width, int height)
{
left = top = 0;
right = width;
bottom = height;
}
/// <summary>
/// Specifies the x-coordinate of the upper-left corner of the rectangle.
/// </summary>
@ -2316,6 +2323,9 @@ namespace OpenTK.Platform.Windows
/// </summary>
internal LONG bottom;
internal int Width { get { return right - left; } }
internal int Height { get { return bottom - top; } }
public override string ToString()
{
return String.Format("({0},{1})-({2},{3})", left, top, right, bottom);

View file

@ -30,13 +30,14 @@ namespace OpenTK.Platform.Windows
private DisplayMode mode = new DisplayMode();
private IInputDriver driver;
//private bool fullscreen;
private bool fullscreen, visible = true;
private bool disposed;
private bool isExiting;
private bool exists;
private WindowInfo window = new WindowInfo();
private int top, bottom, left, right;
private int width = 0, height = 0;
private Rectangle pre_maximized;
private ResizeEventArgs resizeEventArgs = new ResizeEventArgs();
@ -192,13 +193,32 @@ namespace OpenTK.Platform.Windows
{
get
{
return false;
//throw new NotImplementedException();
return fullscreen;
}
set
{
throw new NotImplementedException();
//fullscreen = false;
IntPtr style = IntPtr.Zero;
ShowWindowCommand command = (ShowWindowCommand)0;
if (value && !Fullscreen)
{
style = (IntPtr)(int)(WindowStyle.Popup | WindowStyle.ClipChildren | WindowStyle.ClipSiblings);
command = ShowWindowCommand.SHOWMAXIMIZED;
pre_maximized = new Rectangle(width, height);
Functions.AdjustWindowRect(ref pre_maximized, WindowStyle.OverlappedWindow, false);
}
else if (!value && Fullscreen)
{
style = (IntPtr)(int)(WindowStyle.OverlappedWindow | WindowStyle.ClipChildren | WindowStyle.ClipSiblings);
command = ShowWindowCommand.SHOWNORMAL;
}
Functions.SetWindowLongPtr(Handle, GetWindowLongOffsets.STYLE, style);
Functions.ShowWindow(Handle, command);
if (!value && Fullscreen)
Functions.SetWindowPos(Handle, WindowPlacementOptions.TOP, 0, 0, pre_maximized.Width, pre_maximized.Height,
SetWindowPosFlags.SHOWWINDOW);
fullscreen = value;
}
}
@ -253,11 +273,20 @@ namespace OpenTK.Platform.Windows
{
get
{
//Functions.GetW
return true;
return visible;
}
set
{
if (value && !Visible)
{
Functions.ShowWindow(Handle, ShowWindowCommand.SHOWNORMAL);
visible = true;
}
else if (!value && Visible)
{
Functions.ShowWindow(Handle, ShowWindowCommand.HIDE);
visible = false;
}
}
}
@ -313,7 +342,7 @@ namespace OpenTK.Platform.Windows
cp.Width = rect.right - rect.left;
cp.Height = rect.bottom - rect.top;
cp.Caption = "OpenTK Game Window";
// Keep in mind that some construction code runs in WM_CREATE,
// which is raised CreateHandle()
CreateHandle(cp);