2018-02-05 00:08:20 +01:00
|
|
|
using OpenTK;
|
|
|
|
using OpenTK.Graphics;
|
2018-03-03 02:49:17 +01:00
|
|
|
using OpenTK.Input;
|
2018-02-20 21:09:23 +01:00
|
|
|
using Ryujinx.Core;
|
2018-03-03 02:49:17 +01:00
|
|
|
using Ryujinx.Core.Input;
|
2018-02-20 21:09:23 +01:00
|
|
|
using Ryujinx.Graphics.Gal;
|
2018-02-05 00:08:20 +01:00
|
|
|
using System;
|
|
|
|
|
|
|
|
namespace Ryujinx
|
|
|
|
{
|
|
|
|
public class GLScreen : GameWindow
|
|
|
|
{
|
2018-03-03 02:49:17 +01:00
|
|
|
private const int TouchScreenWidth = 1280;
|
|
|
|
private const int TouchScreenHeight = 720;
|
|
|
|
|
|
|
|
private const float TouchScreenRatioX = (float)TouchScreenWidth / TouchScreenHeight;
|
|
|
|
private const float TouchScreenRatioY = (float)TouchScreenHeight / TouchScreenWidth;
|
|
|
|
|
2018-02-05 00:08:20 +01:00
|
|
|
private Switch Ns;
|
|
|
|
|
|
|
|
private IGalRenderer Renderer;
|
|
|
|
|
|
|
|
public GLScreen(Switch Ns, IGalRenderer Renderer)
|
|
|
|
: base(1280, 720,
|
|
|
|
new GraphicsMode(), "Ryujinx", 0,
|
|
|
|
DisplayDevice.Default, 3, 3,
|
|
|
|
GraphicsContextFlags.ForwardCompatible)
|
|
|
|
{
|
2018-02-23 22:48:27 +01:00
|
|
|
this.Ns = Ns;
|
2018-02-05 00:08:20 +01:00
|
|
|
this.Renderer = Renderer;
|
2018-03-05 00:32:18 +01:00
|
|
|
|
|
|
|
Location = new Point(
|
|
|
|
(DisplayDevice.Default.Width / 2) - (Width / 2),
|
|
|
|
(DisplayDevice.Default.Height / 2) - (Height / 2));
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
|
2018-02-14 03:43:08 +01:00
|
|
|
protected override void OnLoad(EventArgs e)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
|
|
|
VSync = VSyncMode.On;
|
2018-04-14 06:31:27 +02:00
|
|
|
|
|
|
|
Renderer.SetWindowSize(Width, Height);
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnUpdateFrame(FrameEventArgs e)
|
|
|
|
{
|
2018-03-03 02:49:17 +01:00
|
|
|
HidControllerButtons CurrentButton = 0;
|
|
|
|
HidJoystickPosition LeftJoystick;
|
|
|
|
HidJoystickPosition RightJoystick;
|
2018-02-22 14:28:27 +01:00
|
|
|
|
2018-03-04 04:06:44 +01:00
|
|
|
if (Keyboard[Key.Escape]) this.Exit();
|
2018-02-18 00:54:19 +01:00
|
|
|
|
|
|
|
int LeftJoystickDX = 0;
|
|
|
|
int LeftJoystickDY = 0;
|
2018-03-03 02:49:17 +01:00
|
|
|
int RightJoystickDX = 0;
|
|
|
|
int RightJoystickDY = 0;
|
|
|
|
|
|
|
|
//RightJoystick
|
|
|
|
if (Keyboard[(Key)Config.FakeJoyCon.Left.StickUp]) LeftJoystickDY = short.MaxValue;
|
|
|
|
if (Keyboard[(Key)Config.FakeJoyCon.Left.StickDown]) LeftJoystickDY = -short.MaxValue;
|
|
|
|
if (Keyboard[(Key)Config.FakeJoyCon.Left.StickLeft]) LeftJoystickDX = -short.MaxValue;
|
|
|
|
if (Keyboard[(Key)Config.FakeJoyCon.Left.StickRight]) LeftJoystickDX = short.MaxValue;
|
2018-02-18 00:54:19 +01:00
|
|
|
|
|
|
|
//LeftButtons
|
2018-03-03 02:49:17 +01:00
|
|
|
if (Keyboard[(Key)Config.FakeJoyCon.Left.StickButton]) CurrentButton |= HidControllerButtons.KEY_LSTICK;
|
|
|
|
if (Keyboard[(Key)Config.FakeJoyCon.Left.DPadUp]) CurrentButton |= HidControllerButtons.KEY_DUP;
|
|
|
|
if (Keyboard[(Key)Config.FakeJoyCon.Left.DPadDown]) CurrentButton |= HidControllerButtons.KEY_DDOWN;
|
|
|
|
if (Keyboard[(Key)Config.FakeJoyCon.Left.DPadLeft]) CurrentButton |= HidControllerButtons.KEY_DLEFT;
|
|
|
|
if (Keyboard[(Key)Config.FakeJoyCon.Left.DPadRight]) CurrentButton |= HidControllerButtons.KEY_DRIGHT;
|
|
|
|
if (Keyboard[(Key)Config.FakeJoyCon.Left.ButtonMinus]) CurrentButton |= HidControllerButtons.KEY_MINUS;
|
|
|
|
if (Keyboard[(Key)Config.FakeJoyCon.Left.ButtonL]) CurrentButton |= HidControllerButtons.KEY_L;
|
|
|
|
if (Keyboard[(Key)Config.FakeJoyCon.Left.ButtonZL]) CurrentButton |= HidControllerButtons.KEY_ZL;
|
2018-02-18 00:54:19 +01:00
|
|
|
|
|
|
|
//RightJoystick
|
2018-03-03 02:49:17 +01:00
|
|
|
if (Keyboard[(Key)Config.FakeJoyCon.Right.StickUp]) RightJoystickDY = short.MaxValue;
|
|
|
|
if (Keyboard[(Key)Config.FakeJoyCon.Right.StickDown]) RightJoystickDY = -short.MaxValue;
|
|
|
|
if (Keyboard[(Key)Config.FakeJoyCon.Right.StickLeft]) RightJoystickDX = -short.MaxValue;
|
|
|
|
if (Keyboard[(Key)Config.FakeJoyCon.Right.StickRight]) RightJoystickDX = short.MaxValue;
|
2018-02-18 00:54:19 +01:00
|
|
|
|
|
|
|
//RightButtons
|
2018-03-03 02:49:17 +01:00
|
|
|
if (Keyboard[(Key)Config.FakeJoyCon.Right.StickButton]) CurrentButton |= HidControllerButtons.KEY_RSTICK;
|
|
|
|
if (Keyboard[(Key)Config.FakeJoyCon.Right.ButtonA]) CurrentButton |= HidControllerButtons.KEY_A;
|
|
|
|
if (Keyboard[(Key)Config.FakeJoyCon.Right.ButtonB]) CurrentButton |= HidControllerButtons.KEY_B;
|
|
|
|
if (Keyboard[(Key)Config.FakeJoyCon.Right.ButtonX]) CurrentButton |= HidControllerButtons.KEY_X;
|
|
|
|
if (Keyboard[(Key)Config.FakeJoyCon.Right.ButtonY]) CurrentButton |= HidControllerButtons.KEY_Y;
|
|
|
|
if (Keyboard[(Key)Config.FakeJoyCon.Right.ButtonPlus]) CurrentButton |= HidControllerButtons.KEY_PLUS;
|
|
|
|
if (Keyboard[(Key)Config.FakeJoyCon.Right.ButtonR]) CurrentButton |= HidControllerButtons.KEY_R;
|
|
|
|
if (Keyboard[(Key)Config.FakeJoyCon.Right.ButtonZR]) CurrentButton |= HidControllerButtons.KEY_ZR;
|
|
|
|
|
|
|
|
LeftJoystick = new HidJoystickPosition
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-02-18 00:54:19 +01:00
|
|
|
DX = LeftJoystickDX,
|
|
|
|
DY = LeftJoystickDY
|
|
|
|
};
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-03-03 02:49:17 +01:00
|
|
|
RightJoystick = new HidJoystickPosition
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-02-18 00:54:19 +01:00
|
|
|
DX = RightJoystickDX,
|
|
|
|
DY = RightJoystickDY
|
|
|
|
};
|
|
|
|
|
2018-03-03 02:49:17 +01:00
|
|
|
bool HasTouch = false;
|
|
|
|
|
2018-02-22 14:28:27 +01:00
|
|
|
//Get screen touch position from left mouse click
|
2018-03-03 02:49:17 +01:00
|
|
|
//OpenTK always captures mouse events, even if out of focus, so check if window is focused.
|
2018-03-04 04:06:44 +01:00
|
|
|
if (Focused && Mouse?.GetState().LeftButton == ButtonState.Pressed)
|
2018-03-03 02:49:17 +01:00
|
|
|
{
|
|
|
|
int ScrnWidth = Width;
|
|
|
|
int ScrnHeight = Height;
|
|
|
|
|
|
|
|
if (Width > Height * TouchScreenRatioX)
|
2018-02-22 14:28:27 +01:00
|
|
|
{
|
2018-03-03 02:49:17 +01:00
|
|
|
ScrnWidth = (int)(Height * TouchScreenRatioX);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ScrnHeight = (int)(Width * TouchScreenRatioY);
|
|
|
|
}
|
|
|
|
|
|
|
|
int StartX = (Width - ScrnWidth) >> 1;
|
|
|
|
int StartY = (Height - ScrnHeight) >> 1;
|
|
|
|
|
|
|
|
int EndX = StartX + ScrnWidth;
|
|
|
|
int EndY = StartY + ScrnHeight;
|
|
|
|
|
|
|
|
if (Mouse.X >= StartX &&
|
|
|
|
Mouse.Y >= StartY &&
|
|
|
|
Mouse.X < EndX &&
|
|
|
|
Mouse.Y < EndY)
|
|
|
|
{
|
|
|
|
int ScrnMouseX = Mouse.X - StartX;
|
|
|
|
int ScrnMouseY = Mouse.Y - StartY;
|
|
|
|
|
|
|
|
int MX = (int)(((float)ScrnMouseX / ScrnWidth) * TouchScreenWidth);
|
|
|
|
int MY = (int)(((float)ScrnMouseY / ScrnHeight) * TouchScreenHeight);
|
|
|
|
|
|
|
|
HidTouchPoint CurrentPoint = new HidTouchPoint
|
2018-02-22 14:28:27 +01:00
|
|
|
{
|
2018-03-03 02:49:17 +01:00
|
|
|
X = MX,
|
|
|
|
Y = MY,
|
2018-02-22 14:28:27 +01:00
|
|
|
|
|
|
|
//Placeholder values till more data is acquired
|
|
|
|
DiameterX = 10,
|
|
|
|
DiameterY = 10,
|
2018-03-03 02:49:17 +01:00
|
|
|
Angle = 90
|
2018-02-22 14:28:27 +01:00
|
|
|
};
|
2018-03-03 02:49:17 +01:00
|
|
|
|
|
|
|
HasTouch = true;
|
|
|
|
|
|
|
|
Ns.Hid.SetTouchPoints(CurrentPoint);
|
2018-02-22 14:28:27 +01:00
|
|
|
}
|
2018-03-03 02:49:17 +01:00
|
|
|
}
|
2018-02-22 14:28:27 +01:00
|
|
|
|
2018-03-03 02:49:17 +01:00
|
|
|
if (!HasTouch)
|
|
|
|
{
|
|
|
|
Ns.Hid.SetTouchPoints();
|
|
|
|
}
|
|
|
|
|
2018-04-13 22:39:45 +02:00
|
|
|
Ns.Hid.SetJoyconButton(
|
|
|
|
HidControllerId.CONTROLLER_HANDHELD,
|
|
|
|
HidControllerLayouts.Handheld_Joined,
|
|
|
|
CurrentButton,
|
|
|
|
LeftJoystick,
|
|
|
|
RightJoystick);
|
|
|
|
|
2018-03-03 02:49:17 +01:00
|
|
|
Ns.Hid.SetJoyconButton(
|
|
|
|
HidControllerId.CONTROLLER_HANDHELD,
|
|
|
|
HidControllerLayouts.Main,
|
|
|
|
CurrentButton,
|
|
|
|
LeftJoystick,
|
|
|
|
RightJoystick);
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnRenderFrame(FrameEventArgs e)
|
|
|
|
{
|
2018-03-06 21:18:49 +01:00
|
|
|
Ns.Statistics.StartSystemFrame();
|
|
|
|
|
|
|
|
Title = $"Ryujinx Screen - (Vsync: {VSync} - FPS: {Ns.Statistics.SystemFrameRate:0} - Guest FPS: " +
|
|
|
|
$"{Ns.Statistics.GameFrameRate:0})";
|
2018-02-09 01:43:22 +01:00
|
|
|
|
2018-02-05 00:08:20 +01:00
|
|
|
Renderer.RunActions();
|
2018-02-22 14:28:27 +01:00
|
|
|
Renderer.Render();
|
2018-02-05 00:08:20 +01:00
|
|
|
|
|
|
|
SwapBuffers();
|
2018-03-06 21:18:49 +01:00
|
|
|
|
|
|
|
Ns.Statistics.EndSystemFrame();
|
2018-03-19 19:58:46 +01:00
|
|
|
|
|
|
|
Ns.Os.SignalVsync();
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
|
2018-02-20 11:52:35 +01:00
|
|
|
protected override void OnResize(EventArgs e)
|
|
|
|
{
|
2018-02-23 22:48:27 +01:00
|
|
|
Renderer.SetWindowSize(Width, Height);
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|