mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-02-03 03:51:03 +00:00
Added GetNext and GetPrevious methods to improve toggling of window states and borders.
This commit is contained in:
parent
6ee92bb453
commit
1540fab506
|
@ -23,48 +23,42 @@ namespace Examples.Tests
|
||||||
TextureFont font = new TextureFont(new Font(FontFamily.GenericSansSerif, 16.0f));
|
TextureFont font = new TextureFont(new Font(FontFamily.GenericSansSerif, 16.0f));
|
||||||
TextPrinter printer = new TextPrinter();
|
TextPrinter printer = new TextPrinter();
|
||||||
|
|
||||||
WindowState[] window_state_sequence = new WindowState[]
|
#region GetNext and GetPrevious methods for enums.
|
||||||
{
|
|
||||||
WindowState.Normal,
|
|
||||||
WindowState.Maximized,
|
|
||||||
WindowState.Fullscreen,
|
|
||||||
WindowState.Minimized
|
|
||||||
};
|
|
||||||
|
|
||||||
WindowBorder[] window_border_sequence = new WindowBorder[]
|
T GetNext<T>(T t)
|
||||||
{
|
{
|
||||||
WindowBorder.Resizable,
|
if (!(t is Enum))
|
||||||
WindowBorder.Fixed,
|
throw new ArgumentException(String.Format("Should be an Enum type (is {0}).", t.GetType().ToString()),
|
||||||
WindowBorder.Hidden,
|
"t");
|
||||||
};
|
|
||||||
|
string[] names = Enum.GetNames(t.GetType());
|
||||||
|
T[] values = (T[])Enum.GetValues(t.GetType());
|
||||||
|
|
||||||
|
int current_index = Array.IndexOf(names, t.ToString());
|
||||||
|
if (current_index >= values.Length - 1)
|
||||||
|
return values[0];
|
||||||
|
else
|
||||||
|
return values[current_index + 1];
|
||||||
|
|
||||||
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;
|
T GetPrevious<T>(T t)
|
||||||
int WindowBorderCounter
|
|
||||||
{
|
{
|
||||||
get { return window_border_counter; }
|
if (!(t is Enum))
|
||||||
set
|
throw new ArgumentException(String.Format("Should be an Enum type (is {0}).", t.GetType().ToString()),
|
||||||
{
|
"t");
|
||||||
if (value < 0)
|
|
||||||
window_border_counter = window_border_sequence.Length - 1;
|
string[] names = Enum.GetNames(t.GetType());
|
||||||
else
|
T[] values = (T[])Enum.GetValues(t.GetType());
|
||||||
window_border_counter = ++window_border_counter % window_border_sequence.Length;
|
|
||||||
}
|
int current_index = Array.IndexOf(names, t.ToString());
|
||||||
|
if (current_index <= 0)
|
||||||
|
return values[values.Length - 1];
|
||||||
|
else
|
||||||
|
return values[current_index - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
public GameWindowStates()
|
public GameWindowStates()
|
||||||
: base(800, 600)
|
: base(800, 600)
|
||||||
|
@ -85,43 +79,25 @@ namespace Examples.Tests
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OpenTK.Input.Key.Number1:
|
case OpenTK.Input.Key.Number1:
|
||||||
if (sender[Key.ShiftLeft] || sender[Key.ShiftRight])
|
|
||||||
WindowStateCounter--;
|
|
||||||
else
|
|
||||||
WindowStateCounter++;
|
|
||||||
WindowState = window_state_sequence[WindowStateCounter];
|
|
||||||
|
|
||||||
// switch (this.WindowState)
|
if (sender[Key.ShiftLeft] || sender[Key.ShiftRight])
|
||||||
// {
|
WindowState = GetPrevious(WindowState);
|
||||||
// case WindowState.Normal: this.WindowState = WindowState.Maximized; break;1
|
else
|
||||||
// case WindowState.Maximized: this.WindowState = WindowState.Fullscreen; break;
|
WindowState = GetNext(WindowState);
|
||||||
// case WindowState.Fullscreen:
|
|
||||||
// this.WindowState = WindowState.Normal;
|
|
||||||
// this.WindowState = WindowState.Minimized;
|
|
||||||
// break;
|
|
||||||
// case WindowState.Minimized: this.WindowState = WindowState.Normal;
|
|
||||||
// break;
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OpenTK.Input.Key.Number2:
|
case OpenTK.Input.Key.Number2:
|
||||||
|
|
||||||
if (sender[Key.ShiftLeft] || sender[Key.ShiftRight])
|
if (sender[Key.ShiftLeft] || sender[Key.ShiftRight])
|
||||||
WindowBorderCounter--;
|
WindowBorder = GetPrevious(WindowBorder);
|
||||||
else
|
else
|
||||||
WindowBorderCounter++;
|
WindowBorder = GetNext(WindowBorder);
|
||||||
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;
|
|
||||||
// }
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OpenTK.Input.Key.Number3:
|
case OpenTK.Input.Key.Number3:
|
||||||
|
|
||||||
if (this.WindowState == WindowState.Fullscreen)
|
if (this.WindowState == WindowState.Fullscreen)
|
||||||
this.WindowState = WindowState.Normal;
|
this.WindowState = WindowState.Normal;
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue