mirror of
https://github.com/Ale32bit/Capy64.git
synced 2025-12-14 18:15:44 +00:00
add setClipboard and getClipboard to machine
This commit is contained in:
parent
1d484f17ad
commit
85221d3da7
3 changed files with 47 additions and 1 deletions
|
|
@ -29,6 +29,11 @@ public class SDL
|
|||
return SDL2.UTF8_ToManaged(SDL2.Native_SDL_GetClipboardText(), true);
|
||||
}
|
||||
|
||||
public static void SetClipboardText(string contents)
|
||||
{
|
||||
SDL2.Native_SDL_SetClipboardText(contents);
|
||||
}
|
||||
|
||||
public static bool HasClipboardText()
|
||||
{
|
||||
return SDL2.SDL_HasClipboardText() == 1;
|
||||
|
|
|
|||
|
|
@ -41,6 +41,10 @@ public partial class SDL2
|
|||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||
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)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||
internal static partial void SDL_free(IntPtr memblock);
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
// limitations under the License.
|
||||
|
||||
using Capy64.API;
|
||||
using Capy64.Core;
|
||||
using KeraLua;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
|
|
@ -22,6 +23,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Capy64.Runtime.Libraries;
|
||||
|
||||
|
|
@ -65,6 +67,16 @@ public class Machine : IPlugin
|
|||
name = "vibrate",
|
||||
function = L_Vibrate,
|
||||
},
|
||||
new()
|
||||
{
|
||||
name = "setClipboard",
|
||||
function = L_SetClipboard,
|
||||
},
|
||||
new()
|
||||
{
|
||||
name = "getClipboard",
|
||||
function = L_GetClipboard,
|
||||
},
|
||||
new(),
|
||||
};
|
||||
|
||||
|
|
@ -104,7 +116,12 @@ public class Machine : IPlugin
|
|||
{
|
||||
var newTitle = L.CheckString(1);
|
||||
|
||||
L.ArgumentCheck(!string.IsNullOrEmpty(newTitle), 1, "string must not be empty");
|
||||
if (string.IsNullOrEmpty(newTitle))
|
||||
{
|
||||
newTitle = "Capy64 " + Capy64.Version;
|
||||
}
|
||||
|
||||
newTitle = newTitle[..Math.Min(newTitle.Length, 256)];
|
||||
|
||||
Capy64.Instance.Window.Title = newTitle;
|
||||
}
|
||||
|
|
@ -114,6 +131,26 @@ public class Machine : IPlugin
|
|||
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)
|
||||
{
|
||||
var L = Lua.FromIntPtr(state);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue