mirror of
https://github.com/Ale32bit/Capy64.git
synced 2025-01-18 18:46:43 +00:00
Add togglable console window
This commit is contained in:
parent
b477e74141
commit
1b2ad30759
4 changed files with 76 additions and 0 deletions
|
@ -142,6 +142,11 @@ local function installOS()
|
|||
promptKey()
|
||||
end
|
||||
|
||||
local function toggleConsole()
|
||||
local status = getConsole()
|
||||
setConsole(not status)
|
||||
end
|
||||
|
||||
term.setBlink(false)
|
||||
|
||||
local function setupScreen()
|
||||
|
@ -150,6 +155,10 @@ local function setupScreen()
|
|||
"Open data folder",
|
||||
openDataFolder,
|
||||
},
|
||||
{
|
||||
"Toggle console window",
|
||||
toggleConsole,
|
||||
},
|
||||
{
|
||||
"Install default OS",
|
||||
installOS,
|
||||
|
|
25
Capy64/Extensions/Bindings/Common.cs
Normal file
25
Capy64/Extensions/Bindings/Common.cs
Normal file
|
@ -0,0 +1,25 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Capy64.Extensions.Bindings;
|
||||
|
||||
public partial class Common
|
||||
{
|
||||
public const int SW_HIDE = 0;
|
||||
public const int SW_SHOW = 5;
|
||||
|
||||
[LibraryImport("kernel32.dll")]
|
||||
public static partial IntPtr GetConsoleWindow();
|
||||
|
||||
[LibraryImport("user32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static partial bool IsWindowVisible(IntPtr hWnd);
|
||||
|
||||
[LibraryImport("user32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static partial bool ShowWindow(IntPtr hWnd, int nCmdShow);
|
||||
}
|
|
@ -54,4 +54,19 @@ public static class GameWindowExtensions
|
|||
{
|
||||
return window.GetWindowFlags().HasFlag(WindowFlags.SDL_WINDOW_MAXIMIZED);
|
||||
}
|
||||
|
||||
public static void ToggleConsole(this GameWindow _, bool show)
|
||||
{
|
||||
var console = Common.GetConsoleWindow();
|
||||
if (console != IntPtr.Zero)
|
||||
Common.ShowWindow(console, show ? Common.SW_SHOW : Common.SW_HIDE);
|
||||
}
|
||||
|
||||
public static bool IsConsoleVisible(this GameWindow _)
|
||||
{
|
||||
var console = Common.GetConsoleWindow();
|
||||
if (console != IntPtr.Zero)
|
||||
return false;
|
||||
return Common.IsWindowVisible(console);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Capy64.API;
|
||||
using Capy64.Eventing.Events;
|
||||
using Capy64.Extensions;
|
||||
using Capy64.Runtime.Libraries;
|
||||
using KeraLua;
|
||||
using System;
|
||||
|
@ -113,6 +114,12 @@ internal class RuntimeManager : IPlugin
|
|||
luaState.Thread.PushCFunction(L_Exit);
|
||||
luaState.Thread.SetGlobal("exit");
|
||||
|
||||
luaState.Thread.PushCFunction(L_SetConsole);
|
||||
luaState.Thread.SetGlobal("setConsole");
|
||||
|
||||
luaState.Thread.PushCFunction(L_GetConsole);
|
||||
luaState.Thread.SetGlobal("getConsole");
|
||||
|
||||
var status = luaState.Thread.LoadFile("Assets/bios.lua");
|
||||
if (status != LuaStatus.OK)
|
||||
{
|
||||
|
@ -203,6 +210,26 @@ internal class RuntimeManager : IPlugin
|
|||
return 0;
|
||||
}
|
||||
|
||||
private static int L_SetConsole(IntPtr state)
|
||||
{
|
||||
var L = Lua.FromIntPtr(state);
|
||||
|
||||
var status = L.ToBoolean(1);
|
||||
_game.Window.ToggleConsole(status);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static int L_GetConsole(IntPtr state)
|
||||
{
|
||||
var L = Lua.FromIntPtr(state);
|
||||
|
||||
var status = _game.Window.IsConsoleVisible();
|
||||
L.PushBoolean(status);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
private void OnInit(object sender, EventArgs e)
|
||||
{
|
||||
Start();
|
||||
|
|
Loading…
Reference in a new issue