mirror of
https://github.com/Ale32bit/Capy64.git
synced 2025-01-31 08:16:42 +00:00
first window with a working magenta pixel
This commit is contained in:
parent
db3956600b
commit
0d358b09b9
7 changed files with 169 additions and 14 deletions
|
@ -54,6 +54,9 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Assets\Lua\" />
|
<Folder Include="Assets\Lua\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\SDL2-CS\SDL2-CS.Core.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT' ">
|
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT' ">
|
||||||
<DefineConstants>_WINDOWS</DefineConstants>
|
<DefineConstants>_WINDOWS</DefineConstants>
|
||||||
|
|
|
@ -21,16 +21,19 @@ public class SDL
|
||||||
{
|
{
|
||||||
public static string GetClipboardText()
|
public static string GetClipboardText()
|
||||||
{
|
{
|
||||||
return SDL2.UTF8_ToManaged(SDL2.Native_SDL_GetClipboardText(), true);
|
return SDL2.SDL.SDL_GetClipboardText();
|
||||||
|
//return SDL2.UTF8_ToManaged(SDL2.Native_SDL_GetClipboardText(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetClipboardText(string contents)
|
public static void SetClipboardText(string contents)
|
||||||
{
|
{
|
||||||
SDL2.Native_SDL_SetClipboardText(contents);
|
SDL2.SDL.SDL_SetClipboardText(contents);
|
||||||
|
//SDL2.Native_SDL_SetClipboardText(contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool HasClipboardText()
|
public static bool HasClipboardText()
|
||||||
{
|
{
|
||||||
return SDL2.SDL_HasClipboardText() == 1;
|
return SDL2.SDL.SDL_HasClipboardText() == SDL2.SDL.SDL_bool.SDL_TRUE;
|
||||||
|
//return SDL2.SDL_HasClipboardText() == 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,7 +108,7 @@ public class InputManager
|
||||||
UpdateGamePad(GamePad.GetState(PlayerIndex.One), IsActive);
|
UpdateGamePad(GamePad.GetState(PlayerIndex.One), IsActive);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateMouse(MouseState state, bool isActive)
|
public void UpdateMouse(MouseState state, bool isActive)
|
||||||
{
|
{
|
||||||
if (!isActive)
|
if (!isActive)
|
||||||
return;
|
return;
|
||||||
|
@ -217,7 +217,7 @@ public class InputManager
|
||||||
mouseButtonStates[MouseButton.Button5] = state.XButton2;
|
mouseButtonStates[MouseButton.Button5] = state.XButton2;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateKeyboard(KeyboardState state, bool isActive)
|
public void UpdateKeyboard(KeyboardState state, bool isActive)
|
||||||
{
|
{
|
||||||
var keys = state.GetPressedKeys();
|
var keys = state.GetPressedKeys();
|
||||||
|
|
||||||
|
@ -306,7 +306,7 @@ public class InputManager
|
||||||
}
|
}
|
||||||
|
|
||||||
private GamePadState oldGamePadState = new();
|
private GamePadState oldGamePadState = new();
|
||||||
private void UpdateGamePad(GamePadState state, bool isActive)
|
public void UpdateGamePad(GamePadState state, bool isActive)
|
||||||
{
|
{
|
||||||
if (!isActive)
|
if (!isActive)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -58,12 +58,14 @@ public static class GameWindowExtensions
|
||||||
|
|
||||||
public static WindowFlags GetWindowFlags(this GameWindow window)
|
public static WindowFlags GetWindowFlags(this GameWindow window)
|
||||||
{
|
{
|
||||||
return (WindowFlags)SDL2.SDL_GetWindowFlags(window.Handle);
|
return (WindowFlags)SDL2.SDL.SDL_GetWindowFlags(window.Handle);
|
||||||
|
//return (WindowFlags)SDL2.SDL_GetWindowFlags(window.Handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void MaximizeWindow(this GameWindow window)
|
public static void MaximizeWindow(this GameWindow window)
|
||||||
{
|
{
|
||||||
SDL2.SDL_MaximizeWindow(window.Handle);
|
SDL2.SDL.SDL_MaximizeWindow(window.Handle);
|
||||||
|
//SDL2.SDL_MaximizeWindow(window.Handle);
|
||||||
}
|
}
|
||||||
public static bool IsMaximized(this GameWindow window)
|
public static bool IsMaximized(this GameWindow window)
|
||||||
{
|
{
|
||||||
|
|
|
@ -17,9 +17,9 @@ using Capy64;
|
||||||
|
|
||||||
if (args.Length > 0 && args[0] == "sdl")
|
if (args.Length > 0 && args[0] == "sdl")
|
||||||
{
|
{
|
||||||
var entry = new SDLEntry();
|
using var game = new SDLEntry();
|
||||||
|
|
||||||
entry.Run();
|
game.Run();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,7 +5,8 @@
|
||||||
"distributionName": ""
|
"distributionName": ""
|
||||||
},
|
},
|
||||||
"Capy64": {
|
"Capy64": {
|
||||||
"commandName": "Project"
|
"commandName": "Project",
|
||||||
|
"commandLineArgs": "sdl"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -15,11 +15,157 @@
|
||||||
|
|
||||||
namespace Capy64;
|
namespace Capy64;
|
||||||
|
|
||||||
public class SDLEntry
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using static global::Capy64.Utils;
|
||||||
|
using static SDL2.SDL;
|
||||||
|
|
||||||
|
public class SDLEntry : IDisposable
|
||||||
{
|
{
|
||||||
|
public const string Version = "1.1.0-beta";
|
||||||
|
public nint Window { get; private set; } = 0;
|
||||||
|
public nint Renderer { get; private set; } = 0;
|
||||||
|
public nint VideoSurface { get; private set; } = 0;
|
||||||
|
public int WindowWidth { get; private set; }
|
||||||
|
public int WindowHeight { get; private set; }
|
||||||
|
public int Width { get; set; } = DefaultParameters.Width;
|
||||||
|
public int Height { get; set; } = DefaultParameters.Height;
|
||||||
|
public float Scale { get; set; } = DefaultParameters.Scale;
|
||||||
|
public uint BorderColor { get; set; } = 0x0;
|
||||||
|
|
||||||
|
public Borders Borders
|
||||||
|
{
|
||||||
|
get => _borders;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_borders = value;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private SDL_Rect _bordersRect;
|
||||||
|
private Borders _borders;
|
||||||
|
|
||||||
|
public static readonly string AssemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||||
|
public static readonly string AssetsPath = Path.Combine(AssemblyPath, "Assets");
|
||||||
|
|
||||||
|
public static class DefaultParameters
|
||||||
|
{
|
||||||
|
public const int Width = 318;
|
||||||
|
public const int Height = 240;
|
||||||
|
public const float Scale = 2f;
|
||||||
|
public const float BorderMultiplier = 1.5f;
|
||||||
|
public static readonly EngineMode EngineMode = EngineMode.Classic;
|
||||||
|
|
||||||
|
public const int ClassicTickrate = 30;
|
||||||
|
public const int FreeTickrate = 60;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string AppDataPath
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
string baseDir =
|
||||||
|
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
|
||||||
|
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData,
|
||||||
|
Environment.SpecialFolderOption.Create) :
|
||||||
|
RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ?
|
||||||
|
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData,
|
||||||
|
Environment.SpecialFolderOption.Create) :
|
||||||
|
RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ?
|
||||||
|
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData,
|
||||||
|
Environment.SpecialFolderOption.Create) :
|
||||||
|
"./";
|
||||||
|
|
||||||
|
return Path.Combine(baseDir, "Capy64");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public SDLEntry()
|
||||||
|
{
|
||||||
|
Borders = new()
|
||||||
|
{
|
||||||
|
Top = 0,
|
||||||
|
Bottom = 0,
|
||||||
|
Left = 0,
|
||||||
|
Right = 0,
|
||||||
|
};
|
||||||
|
WindowWidth = (int)(Width * Scale) + Borders.Left + Borders.Right;
|
||||||
|
WindowHeight = (int)(Height * Scale) + Borders.Top + Borders.Bottom;
|
||||||
|
}
|
||||||
public void Run()
|
public void Run()
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
|
SDL_SetHint(SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING, "1");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine(SDL_GetError());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Window = SDL_CreateWindow("Capy64 " + Version,
|
||||||
|
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
||||||
|
WindowWidth, WindowHeight,
|
||||||
|
SDL_WindowFlags.SDL_WINDOW_OPENGL);
|
||||||
|
|
||||||
|
if (Window == nint.Zero)
|
||||||
|
{
|
||||||
|
Console.WriteLine(SDL_GetError());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Renderer = SDL_CreateRenderer(Window,
|
||||||
|
0,
|
||||||
|
SDL_RendererFlags.SDL_RENDERER_ACCELERATED | SDL_RendererFlags.SDL_RENDERER_PRESENTVSYNC);
|
||||||
|
|
||||||
|
if (Renderer == nint.Zero)
|
||||||
|
{
|
||||||
|
Console.WriteLine(SDL_GetError());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
VideoSurface = SDL_CreateRGBSurfaceWithFormat(0, Width, Height, 32, SDL_PIXELFORMAT_ARGB8888);
|
||||||
|
|
||||||
|
var running = true;
|
||||||
|
while (running)
|
||||||
|
{
|
||||||
|
while (SDL_PollEvent(out var ev) != 0)
|
||||||
|
{
|
||||||
|
switch (ev.type)
|
||||||
|
{
|
||||||
|
case SDL_EventType.SDL_QUIT:
|
||||||
|
running = false;
|
||||||
|
break;
|
||||||
|
case SDL_EventType.SDL_KEYDOWN:
|
||||||
|
if (ev.key.keysym.scancode == SDL_Scancode.SDL_SCANCODE_ESCAPE)
|
||||||
|
running = false;
|
||||||
|
|
||||||
|
unsafe
|
||||||
|
{
|
||||||
|
var pitch = ((SDL_Surface*)VideoSurface)->pitch;
|
||||||
|
((uint*)((SDL_Surface*)VideoSurface)->pixels)[10 + 10 * pitch / 4] = 0xFFFF00FF;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_RenderClear(Renderer);
|
||||||
|
var texture = SDL_CreateTextureFromSurface(Renderer, VideoSurface);
|
||||||
|
SDL_RenderCopy(Renderer, texture, 0, 0);
|
||||||
|
SDL_DestroyTexture(texture);
|
||||||
|
SDL_RenderPresent(Renderer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
SDL_DestroyRenderer(Renderer);
|
||||||
|
SDL_DestroyWindow(Window);
|
||||||
|
|
||||||
|
SDL_Quit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue