mirror of
https://github.com/Ale32bit/Capy64.git
synced 2025-01-18 18:46:43 +00:00
add setClipboard and getClipboard to machine (#5)
This commit is contained in:
parent
1dbbb23ff6
commit
03e0992328
3 changed files with 47 additions and 0 deletions
|
@ -24,6 +24,11 @@ public class SDL
|
||||||
return SDL2.UTF8_ToManaged(SDL2.Native_SDL_GetClipboardText(), true);
|
return SDL2.UTF8_ToManaged(SDL2.Native_SDL_GetClipboardText(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void SetClipboardText(string contents)
|
||||||
|
{
|
||||||
|
SDL2.Native_SDL_SetClipboardText(contents);
|
||||||
|
}
|
||||||
|
|
||||||
public static bool HasClipboardText()
|
public static bool HasClipboardText()
|
||||||
{
|
{
|
||||||
return SDL2.SDL_HasClipboardText() == 1;
|
return SDL2.SDL_HasClipboardText() == 1;
|
||||||
|
|
|
@ -41,6 +41,10 @@ public partial class SDL2
|
||||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||||
internal static partial int SDL_HasClipboardText();
|
internal static partial int SDL_HasClipboardText();
|
||||||
|
|
||||||
|
[LibraryImport(SDL, EntryPoint = "SDL_SetClipboardText", StringMarshalling = StringMarshalling.Utf8)]
|
||||||
|
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||||
|
internal static partial int Native_SDL_SetClipboardText(string contents);
|
||||||
|
|
||||||
[LibraryImport(SDL)]
|
[LibraryImport(SDL)]
|
||||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||||
internal static partial void SDL_free(IntPtr memblock);
|
internal static partial void SDL_free(IntPtr memblock);
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
using Capy64.API;
|
using Capy64.API;
|
||||||
|
using Capy64.Core;
|
||||||
using KeraLua;
|
using KeraLua;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Input;
|
using Microsoft.Xna.Framework.Input;
|
||||||
|
@ -61,6 +62,16 @@ public class Machine : IComponent
|
||||||
name = "vibrate",
|
name = "vibrate",
|
||||||
function = L_Vibrate,
|
function = L_Vibrate,
|
||||||
},
|
},
|
||||||
|
new()
|
||||||
|
{
|
||||||
|
name = "setClipboard",
|
||||||
|
function = L_SetClipboard,
|
||||||
|
},
|
||||||
|
new()
|
||||||
|
{
|
||||||
|
name = "getClipboard",
|
||||||
|
function = L_GetClipboard,
|
||||||
|
},
|
||||||
new(),
|
new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -99,6 +110,13 @@ public class Machine : IComponent
|
||||||
if (!L.IsNoneOrNil(1))
|
if (!L.IsNoneOrNil(1))
|
||||||
{
|
{
|
||||||
var newTitle = L.CheckString(1);
|
var newTitle = L.CheckString(1);
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(newTitle))
|
||||||
|
{
|
||||||
|
newTitle = "Capy64 " + Capy64.Version;
|
||||||
|
}
|
||||||
|
|
||||||
|
newTitle = newTitle[..Math.Min(newTitle.Length, 256)];
|
||||||
|
|
||||||
Capy64.Instance.Window.Title = newTitle;
|
Capy64.Instance.Window.Title = newTitle;
|
||||||
}
|
}
|
||||||
|
@ -108,6 +126,26 @@ public class Machine : IComponent
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int L_GetClipboard(IntPtr state)
|
||||||
|
{
|
||||||
|
var L = Lua.FromIntPtr(state);
|
||||||
|
|
||||||
|
L.PushString(SDL.GetClipboardText());
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int L_SetClipboard(IntPtr state)
|
||||||
|
{
|
||||||
|
var L = Lua.FromIntPtr(state);
|
||||||
|
|
||||||
|
var newcontents = L.CheckString(1);
|
||||||
|
|
||||||
|
SDL.SetClipboardText(newcontents);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
private static int L_Version(IntPtr state)
|
private static int L_Version(IntPtr state)
|
||||||
{
|
{
|
||||||
var L = Lua.FromIntPtr(state);
|
var L = Lua.FromIntPtr(state);
|
||||||
|
|
Loading…
Reference in a new issue