prosperon/source/engine/input.c

77 lines
1.8 KiB
C
Raw Permalink Normal View History

2021-11-30 21:29:18 -06:00
#include "input.h"
2022-08-26 09:19:17 -05:00
#include "sokol/sokol_app.h"
2023-05-12 13:22:05 -05:00
#include "font.h"
#include "log.h"
#include "script.h"
2022-08-26 09:19:17 -05:00
#include "stb_ds.h"
2023-04-25 16:59:12 -05:00
#include "time.h"
#include <ctype.h>
#include "resources.h"
2023-12-20 09:19:04 -06:00
#include "jsffi.h"
2021-11-30 21:29:18 -06:00
2023-12-20 09:19:04 -06:00
void input_dropped_files(int n)
{
script_evalf("prosperon.droppedfile(`%s`);", sapp_get_dropped_file_path(0));
}
void input_clipboard_paste(char *str)
{
script_evalf("prosperon.clipboardpaste(`%s`);", sapp_get_clipboard_string());
2023-04-25 14:59:26 -05:00
}
/*
0 free
1 lock
*/
void set_mouse_mode(int mousemode) { sapp_lock_mouse(mousemode); }
2023-05-12 13:22:05 -05:00
void cursor_hide() { sapp_show_mouse(0); }
void cursor_show() { sapp_show_mouse(1); }
2022-08-26 09:19:17 -05:00
2024-02-25 17:31:48 -06:00
void cursor_img(const char *path)
{
/* NSdesting *dest = [NSdesting destingWithUTF8desting:path];
NSImage *img = [[NSImage alloc] initWithContentsOfFile:dest];
2024-02-25 17:31:48 -06:00
NSCursor *custom = [[NSCursor alloc] initWithImage:img hotSpot:NSMakePoint(0,0)];
[custom set];
*/
}
static char *touch_jstrn(char *dest, int len, sapp_touchpoint *touch, int n)
{
dest[0] = 0;
char touchdest[512] = {0};
strncat(dest,"[", 512);
for (int i = 0; i < n; i++) {
snprintf(touchdest, 512, "{id:%zd, x:%g, y:%g},", touch[i].identifier, touch[i].pos_x, touch[i].pos_y);
strncat(dest,touchdest,512);
}
strncat(dest,"]", 512);
return dest;
}
void touch_start(sapp_touchpoint *touch, int n)
{
char dest[512] = {0};
script_evalf("prosperon.touchpress(%s);", touch_jstrn(dest, 512, touch, n));
}
void touch_move(sapp_touchpoint *touch, int n)
{
char dest[512] = {0};
script_evalf("prosperon.touchmove(%s);", touch_jstrn(dest,512,touch,n));
}
void touch_end(sapp_touchpoint *touch, int n)
{
char dest[512] = {0};
script_evalf("prosperon.touchend(%s);", touch_jstrn(dest,512,touch,n));
}
void touch_cancelled(sapp_touchpoint *touch, int n)
{
char dest[512] = {0};
script_evalf("prosperon.touchend(%s);", touch_jstrn(dest,512,touch,n));
}