Files
armorpaint/base/sources/iron_system.c
T

622 lines
19 KiB
C
Raw Normal View History

2025-02-26 13:24:16 +01:00
#include "iron_system.h"
#include <stdio.h>
#include <stdlib.h>
2025-10-15 13:06:40 +02:00
#include <string.h>
2025-03-09 17:02:12 +01:00
#ifdef IRON_WINDOWS
2025-03-07 11:30:51 +01:00
#include <backends/windows_mini.h>
#include <backends/windows_system.h>
2025-02-26 13:24:16 +01:00
#endif
2025-03-09 17:02:12 +01:00
#ifdef IRON_ANDROID
2025-02-26 13:24:16 +01:00
#include <android/log.h>
#endif
#include <iron_file.h>
2025-02-26 18:46:36 +01:00
#include <memory.h>
#include <stddef.h>
2025-02-26 13:24:16 +01:00
2025-03-01 13:39:46 +01:00
typedef enum {
2025-03-09 17:02:12 +01:00
IRON_LOG_LEVEL_INFO,
IRON_LOG_LEVEL_ERROR
} iron_log_level_t;
2025-02-26 13:24:16 +01:00
2025-03-09 17:02:12 +01:00
void iron_log_args(iron_log_level_t level, const char *format, va_list args) {
2026-01-05 21:13:49 +01:00
#ifdef IRON_WASM
printf(format);
return;
#endif
2025-03-09 17:02:12 +01:00
#ifdef IRON_ANDROID
2025-02-26 13:24:16 +01:00
va_list args_android_copy;
va_copy(args_android_copy, args);
switch (level) {
2025-03-09 17:02:12 +01:00
case IRON_LOG_LEVEL_INFO:
__android_log_vprint(ANDROID_LOG_INFO, "Iron", format, args_android_copy);
2025-02-26 13:24:16 +01:00
break;
2025-03-09 17:02:12 +01:00
case IRON_LOG_LEVEL_ERROR:
__android_log_vprint(ANDROID_LOG_ERROR, "Iron", format, args_android_copy);
2025-02-26 13:24:16 +01:00
break;
}
va_end(args_android_copy);
#endif
2025-03-01 13:39:46 +01:00
2025-03-09 17:02:12 +01:00
#ifdef IRON_WINDOWS
2025-02-26 13:24:16 +01:00
wchar_t buffer[4096];
2025-03-09 17:02:12 +01:00
iron_microsoft_format(format, args, buffer);
2025-02-26 13:24:16 +01:00
wcscat(buffer, L"\r\n");
OutputDebugStringW(buffer);
DWORD written;
2025-03-09 17:02:12 +01:00
WriteConsoleW(GetStdHandle(level == IRON_LOG_LEVEL_INFO ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE), buffer, (DWORD)wcslen(buffer), &written, NULL);
2025-02-26 13:24:16 +01:00
#else
char buffer[4096];
vsnprintf(buffer, 4090, format, args);
strcat(buffer, "\n");
2025-03-09 17:02:12 +01:00
fprintf(level == IRON_LOG_LEVEL_INFO ? stdout : stderr, "%s", buffer);
2025-02-26 13:24:16 +01:00
#endif
}
2025-03-09 17:02:12 +01:00
void iron_log(const char *format, ...) {
2025-03-01 13:39:46 +01:00
va_list args;
va_start(args, format);
2025-03-09 17:02:12 +01:00
iron_log_args(IRON_LOG_LEVEL_INFO, format == NULL ? "null" : format, args);
2025-03-01 13:39:46 +01:00
va_end(args);
2025-02-26 13:24:16 +01:00
}
2025-03-09 17:02:12 +01:00
void iron_error(const char *format, ...) {
2025-02-26 13:24:16 +01:00
{
va_list args;
va_start(args, format);
2025-03-09 17:02:12 +01:00
iron_log_args(IRON_LOG_LEVEL_ERROR, format, args);
2025-02-26 13:24:16 +01:00
va_end(args);
}
2025-03-09 17:02:12 +01:00
#ifdef IRON_WINDOWS
2025-02-26 13:24:16 +01:00
{
va_list args;
va_start(args, format);
wchar_t buffer[4096];
2025-03-09 17:02:12 +01:00
iron_microsoft_format(format, args, buffer);
2025-02-26 13:24:16 +01:00
MessageBoxW(NULL, buffer, L"Error", 0);
va_end(args);
}
#endif
}
2025-03-09 17:02:12 +01:00
#if !defined(IRON_WASM) && !defined(IRON_ANDROID) && !defined(IRON_WINDOWS)
double iron_time(void) {
return iron_timestamp() / iron_frequency();
2025-02-26 13:24:16 +01:00
}
#endif
2026-01-05 21:13:49 +01:00
static void (*update_callback)(void) = NULL;
2025-10-15 13:06:40 +02:00
static void (*foreground_callback)(void *) = NULL;
static void *foreground_callback_data = NULL;
static void (*background_callback)(void *) = NULL;
static void *background_callback_data = NULL;
static void (*pause_callback)(void *) = NULL;
static void *pause_callback_data = NULL;
static void (*resume_callback)(void *) = NULL;
static void *resume_callback_data = NULL;
static void (*shutdown_callback)(void *) = NULL;
static void *shutdown_callback_data = NULL;
2025-09-28 19:38:08 +02:00
static void (*drop_files_callback)(char *, void *) = NULL;
2025-10-15 13:06:40 +02:00
static void *drop_files_callback_data = NULL;
static char *(*cut_callback)(void *) = NULL;
static void *cut_callback_data = NULL;
static char *(*copy_callback)(void *) = NULL;
static void *copy_callback_data = NULL;
static void (*paste_callback)(char *, void *) = NULL;
static void *paste_callback_data = NULL;
2025-02-26 13:24:16 +01:00
2025-03-09 17:02:12 +01:00
#if defined(IRON_IOS) || defined(IRON_MACOS)
2025-08-05 00:58:28 +02:00
bool with_autoreleasepool(bool (*f)(void));
2025-02-26 13:24:16 +01:00
#endif
2026-01-05 21:13:49 +01:00
void iron_set_update_callback(void (*callback)(void)) {
update_callback = callback;
2025-02-26 13:24:16 +01:00
}
2025-03-09 17:02:12 +01:00
void iron_set_foreground_callback(void (*callback)(void *), void *data) {
2025-10-15 13:06:40 +02:00
foreground_callback = callback;
2025-02-26 13:24:16 +01:00
foreground_callback_data = data;
}
2025-03-09 17:02:12 +01:00
void iron_set_resume_callback(void (*callback)(void *), void *data) {
2025-10-15 13:06:40 +02:00
resume_callback = callback;
2025-02-26 13:24:16 +01:00
resume_callback_data = data;
}
2025-03-09 17:02:12 +01:00
void iron_set_pause_callback(void (*callback)(void *), void *data) {
2025-10-15 13:06:40 +02:00
pause_callback = callback;
2025-02-26 13:24:16 +01:00
pause_callback_data = data;
}
2025-03-09 17:02:12 +01:00
void iron_set_background_callback(void (*callback)(void *), void *data) {
2025-10-15 13:06:40 +02:00
background_callback = callback;
2025-02-26 13:24:16 +01:00
background_callback_data = data;
}
2025-03-09 17:02:12 +01:00
void iron_set_shutdown_callback(void (*callback)(void *), void *data) {
2025-10-15 13:06:40 +02:00
shutdown_callback = callback;
2025-02-26 13:24:16 +01:00
shutdown_callback_data = data;
}
2025-09-28 19:38:08 +02:00
void iron_set_drop_files_callback(void (*callback)(char *, void *), void *data) {
2025-10-15 13:06:40 +02:00
drop_files_callback = callback;
2025-02-26 13:24:16 +01:00
drop_files_callback_data = data;
}
2025-03-09 17:02:12 +01:00
void iron_set_cut_callback(char *(*callback)(void *), void *data) {
2025-10-15 13:06:40 +02:00
cut_callback = callback;
2025-02-26 13:24:16 +01:00
cut_callback_data = data;
}
2025-03-09 17:02:12 +01:00
void iron_set_copy_callback(char *(*callback)(void *), void *data) {
2025-10-15 13:06:40 +02:00
copy_callback = callback;
2025-02-26 13:24:16 +01:00
copy_callback_data = data;
}
2025-03-09 17:02:12 +01:00
void iron_set_paste_callback(void (*callback)(char *, void *), void *data) {
2025-10-15 13:06:40 +02:00
paste_callback = callback;
2025-02-26 13:24:16 +01:00
paste_callback_data = data;
}
2025-03-09 17:02:12 +01:00
void iron_internal_update_callback(void) {
2025-02-26 13:24:16 +01:00
if (update_callback != NULL) {
2026-01-05 21:13:49 +01:00
update_callback();
2025-02-26 13:24:16 +01:00
}
}
2025-03-09 17:02:12 +01:00
void iron_internal_foreground_callback(void) {
2025-02-26 13:24:16 +01:00
if (foreground_callback != NULL) {
foreground_callback(foreground_callback_data);
}
}
2025-03-09 17:02:12 +01:00
void iron_internal_resume_callback(void) {
2025-02-26 13:24:16 +01:00
if (resume_callback != NULL) {
resume_callback(resume_callback_data);
}
}
2025-03-09 17:02:12 +01:00
void iron_internal_pause_callback(void) {
2025-02-26 13:24:16 +01:00
if (pause_callback != NULL) {
pause_callback(pause_callback_data);
}
}
2025-03-09 17:02:12 +01:00
void iron_internal_background_callback(void) {
2025-02-26 13:24:16 +01:00
if (background_callback != NULL) {
background_callback(background_callback_data);
}
}
2025-03-09 17:02:12 +01:00
void iron_internal_shutdown_callback(void) {
2025-02-26 13:24:16 +01:00
if (shutdown_callback != NULL) {
shutdown_callback(shutdown_callback_data);
}
}
2025-09-28 19:38:08 +02:00
void iron_internal_drop_files_callback(char *filePath) {
2025-02-26 13:24:16 +01:00
if (drop_files_callback != NULL) {
drop_files_callback(filePath, drop_files_callback_data);
}
}
2025-03-09 17:02:12 +01:00
char *iron_internal_cut_callback(void) {
2025-02-26 13:24:16 +01:00
if (cut_callback != NULL) {
return cut_callback(cut_callback_data);
}
return NULL;
}
2025-03-09 17:02:12 +01:00
char *iron_internal_copy_callback(void) {
2025-02-26 13:24:16 +01:00
if (copy_callback != NULL) {
return copy_callback(copy_callback_data);
}
return NULL;
}
2025-03-09 17:02:12 +01:00
void iron_internal_paste_callback(char *value) {
2025-02-26 13:24:16 +01:00
if (paste_callback != NULL) {
paste_callback(value, paste_callback_data);
}
}
2025-10-15 13:06:40 +02:00
static bool running = false;
2025-03-09 17:02:12 +01:00
static char application_name[1024] = {"Iron Application"};
2025-02-26 13:24:16 +01:00
2025-03-09 17:02:12 +01:00
const char *iron_application_name(void) {
2025-02-26 13:24:16 +01:00
return application_name;
}
2025-03-09 17:02:12 +01:00
void iron_set_app_name(const char *name) {
2025-02-26 13:24:16 +01:00
strcpy(application_name, name);
}
2025-03-09 17:02:12 +01:00
void iron_stop(void) {
2025-02-26 13:24:16 +01:00
running = false;
}
2025-03-09 17:02:12 +01:00
bool iron_internal_frame(void) {
iron_internal_update_callback();
iron_internal_handle_messages();
2025-02-26 13:24:16 +01:00
return running;
}
2025-03-19 16:29:14 +01:00
void iron_start(void) {
2025-02-26 13:24:16 +01:00
running = true;
2025-03-09 17:02:12 +01:00
#if !defined(IRON_WASM)
2025-02-26 13:24:16 +01:00
2025-03-09 17:02:12 +01:00
#if defined(IRON_IOS) || defined(IRON_MACOS)
2025-08-05 00:58:28 +02:00
while (with_autoreleasepool(iron_internal_frame)) {
2025-02-26 13:24:16 +01:00
}
#else
2025-03-09 17:02:12 +01:00
while (iron_internal_frame()) {
2025-02-26 13:24:16 +01:00
}
#endif
2025-03-09 17:02:12 +01:00
iron_internal_shutdown();
2025-02-26 13:24:16 +01:00
#endif
}
2025-10-15 13:06:40 +02:00
static uint8_t *current_file = NULL;
static size_t current_file_size = 0;
2025-02-26 13:24:16 +01:00
2025-03-09 17:02:12 +01:00
bool iron_save_file_loaded(void) {
2025-02-26 13:24:16 +01:00
return true;
}
2025-03-09 17:02:12 +01:00
uint8_t *iron_get_save_file(void) {
2025-02-26 13:24:16 +01:00
return current_file;
}
2025-03-09 17:02:12 +01:00
size_t iron_get_save_file_size(void) {
2025-02-26 13:24:16 +01:00
return current_file_size;
}
2025-03-09 17:02:12 +01:00
void iron_load_save_file(const char *filename) {
2025-02-26 13:24:16 +01:00
free(current_file);
2025-10-15 13:06:40 +02:00
current_file = NULL;
2025-02-26 13:24:16 +01:00
current_file_size = 0;
2025-03-09 17:02:12 +01:00
iron_file_reader_t reader;
if (iron_file_reader_open(&reader, filename, IRON_FILE_TYPE_SAVE)) {
current_file_size = iron_file_reader_size(&reader);
2025-10-15 13:06:40 +02:00
current_file = (uint8_t *)malloc(current_file_size);
2025-03-09 17:02:12 +01:00
iron_file_reader_read(&reader, current_file, current_file_size);
iron_file_reader_close(&reader);
2025-02-26 13:24:16 +01:00
}
}
2025-03-09 17:02:12 +01:00
void iron_save_save_file(const char *filename, uint8_t *data, size_t size) {
iron_file_writer_t writer;
if (iron_file_writer_open(&writer, filename)) {
iron_file_writer_write(&writer, data, (int)size);
iron_file_writer_close(&writer);
2025-02-26 13:24:16 +01:00
}
}
2025-03-09 17:02:12 +01:00
bool iron_save_is_saving(void) {
2025-02-26 13:24:16 +01:00
return false;
}
2025-03-09 17:02:12 +01:00
#if !defined(IRON_WINDOWS) && !defined(IRON_LINUX) && !defined(IRON_MACOS)
void iron_copy_to_clipboard(const char *text) {
iron_log("Oh no, iron_copy_to_clipboard is not implemented for this system.");
2025-02-26 13:24:16 +01:00
}
#endif
2025-02-26 18:46:36 +01:00
2025-10-15 13:06:40 +02:00
static void (*keyboard_key_down_callback)(int /*key_code*/, void * /*data*/) = NULL;
static void *keyboard_key_down_callback_data = NULL;
static void (*keyboard_key_up_callback)(int /*key_code*/, void * /*data*/) = NULL;
static void *keyboard_key_up_callback_data = NULL;
2025-02-26 18:46:36 +01:00
static void (*keyboard_key_press_callback)(unsigned /*character*/, void * /*data*/) = NULL;
2025-10-15 13:06:40 +02:00
static void *keyboard_key_press_callback_data = NULL;
2025-02-26 18:46:36 +01:00
2025-03-09 17:02:12 +01:00
void iron_keyboard_set_key_down_callback(void (*value)(int /*key_code*/, void * /*data*/), void *data) {
2025-10-15 13:06:40 +02:00
keyboard_key_down_callback = value;
2025-02-26 18:46:36 +01:00
keyboard_key_down_callback_data = data;
}
2025-03-09 17:02:12 +01:00
void iron_keyboard_set_key_up_callback(void (*value)(int /*key_code*/, void * /*data*/), void *data) {
2025-10-15 13:06:40 +02:00
keyboard_key_up_callback = value;
2025-02-26 18:46:36 +01:00
keyboard_key_up_callback_data = data;
}
2025-03-09 17:02:12 +01:00
void iron_keyboard_set_key_press_callback(void (*value)(unsigned /*character*/, void * /*data*/), void *data) {
2025-10-15 13:06:40 +02:00
keyboard_key_press_callback = value;
2025-02-26 18:46:36 +01:00
keyboard_key_press_callback_data = data;
}
2025-03-09 17:02:12 +01:00
void iron_internal_keyboard_trigger_key_down(int key_code) {
2025-02-26 18:46:36 +01:00
if (keyboard_key_down_callback != NULL) {
keyboard_key_down_callback(key_code, keyboard_key_down_callback_data);
}
}
2025-03-09 17:02:12 +01:00
void iron_internal_keyboard_trigger_key_up(int key_code) {
2025-02-26 18:46:36 +01:00
if (keyboard_key_up_callback != NULL) {
keyboard_key_up_callback(key_code, keyboard_key_up_callback_data);
}
}
2025-03-09 17:02:12 +01:00
void iron_internal_keyboard_trigger_key_press(unsigned character) {
2025-02-26 18:46:36 +01:00
if (keyboard_key_press_callback != NULL) {
keyboard_key_press_callback(character, keyboard_key_press_callback_data);
}
}
2025-10-15 13:06:40 +02:00
static void (*mouse_press_callback)(int /*button*/, int /*x*/, int /*y*/, void * /*data*/) = NULL;
static void *mouse_press_callback_data = NULL;
static void (*mouse_release_callback)(int /*button*/, int /*x*/, int /*y*/, void * /*data*/) = NULL;
static void *mouse_release_callback_data = NULL;
2025-02-26 18:46:36 +01:00
static void (*mouse_move_callback)(int /*x*/, int /*y*/, int /*movementX*/, int /*movementY*/, void * /*data*/) = NULL;
2025-10-15 13:06:40 +02:00
static void *mouse_move_callback_data = NULL;
2026-01-05 21:13:49 +01:00
static void (*mouse_scroll_callback)(float /*delta*/, void * /*data*/) = NULL;
2025-10-15 13:06:40 +02:00
static void *mouse_scroll_callback_data = NULL;
2025-02-26 18:46:36 +01:00
2025-03-09 17:02:12 +01:00
void iron_mouse_set_press_callback(void (*value)(int /*button*/, int /*x*/, int /*y*/, void * /*data*/), void *data) {
2025-10-15 13:06:40 +02:00
mouse_press_callback = value;
2025-02-26 18:46:36 +01:00
mouse_press_callback_data = data;
}
2025-03-09 17:02:12 +01:00
void iron_mouse_set_release_callback(void (*value)(int /*button*/, int /*x*/, int /*y*/, void * /*data*/), void *data) {
2025-10-15 13:06:40 +02:00
mouse_release_callback = value;
2025-02-26 18:46:36 +01:00
mouse_release_callback_data = data;
}
2025-03-09 17:02:12 +01:00
void iron_mouse_set_move_callback(void (*value)(int /*x*/, int /*y*/, int /*movement_x*/, int /*movement_y*/, void * /*data*/), void *data) {
2025-10-15 13:06:40 +02:00
mouse_move_callback = value;
2025-02-26 18:46:36 +01:00
mouse_move_callback_data = data;
}
2025-12-01 10:59:35 +01:00
void iron_mouse_set_scroll_callback(void (*value)(float /*delta*/, void * /*data*/), void *data) {
2025-10-15 13:06:40 +02:00
mouse_scroll_callback = value;
2025-02-26 18:46:36 +01:00
mouse_scroll_callback_data = data;
}
2025-03-09 17:02:12 +01:00
void iron_internal_mouse_trigger_release(int button, int x, int y) {
2025-02-26 18:46:36 +01:00
if (mouse_release_callback != NULL) {
mouse_release_callback(button, x, y, mouse_release_callback_data);
}
}
2025-12-01 10:59:35 +01:00
void iron_internal_mouse_trigger_scroll(float delta) {
2025-02-26 18:46:36 +01:00
if (mouse_scroll_callback != NULL) {
mouse_scroll_callback(delta, mouse_scroll_callback_data);
}
}
2025-03-09 17:02:12 +01:00
void iron_internal_mouse_window_activated() {
if (iron_mouse_is_locked()) {
2025-09-16 22:05:29 +02:00
iron_mouse_hide();
2025-02-26 18:46:36 +01:00
}
}
2025-03-09 17:02:12 +01:00
void iron_internal_mouse_window_deactivated() {
if (iron_mouse_is_locked()) {
2025-09-16 22:05:29 +02:00
iron_mouse_show();
2025-02-26 18:46:36 +01:00
}
}
2025-10-15 13:06:40 +02:00
static bool moved = false;
static bool locked = false;
static int preLockX = 0;
static int preLockY = 0;
static int lastX = 0;
static int lastY = 0;
2025-02-26 18:46:36 +01:00
2025-03-09 17:02:12 +01:00
void iron_internal_mouse_trigger_press(int button, int x, int y) {
2025-02-26 18:46:36 +01:00
lastX = x;
lastY = y;
if (mouse_press_callback != NULL) {
mouse_press_callback(button, x, y, mouse_press_callback_data);
}
}
2025-03-09 17:02:12 +01:00
void iron_internal_mouse_trigger_move(int x, int y) {
2025-02-26 18:46:36 +01:00
int movementX = 0;
int movementY = 0;
2025-03-09 17:02:12 +01:00
if (iron_mouse_is_locked()) {
2025-09-16 22:05:29 +02:00
movementX = x - preLockX;
movementY = y - preLockY;
2025-02-26 18:46:36 +01:00
if (movementX != 0 || movementY != 0) {
2025-09-16 22:05:29 +02:00
iron_mouse_set_position(preLockX, preLockY);
x = preLockX;
y = preLockY;
2025-02-26 18:46:36 +01:00
}
}
else if (moved) {
movementX = x - lastX;
movementY = y - lastY;
}
moved = true;
lastX = x;
lastY = y;
if (mouse_move_callback != NULL && (movementX != 0 || movementY != 0)) {
mouse_move_callback(x, y, movementX, movementY, mouse_move_callback_data);
}
}
2025-03-09 17:02:12 +01:00
bool iron_mouse_is_locked(void) {
2025-02-26 18:46:36 +01:00
return locked;
}
2025-03-09 17:02:12 +01:00
void iron_mouse_lock() {
2025-09-16 22:05:29 +02:00
if (iron_mouse_is_locked() || !iron_mouse_can_lock()) {
2025-02-26 18:46:36 +01:00
return;
}
locked = true;
2025-03-09 17:02:12 +01:00
iron_mouse_get_position(&preLockX, &preLockY);
2025-09-16 22:05:29 +02:00
iron_mouse_hide();
2025-02-26 18:46:36 +01:00
}
2025-03-09 17:02:12 +01:00
void iron_mouse_unlock(void) {
2025-09-16 22:05:29 +02:00
if (!iron_mouse_is_locked() || !iron_mouse_can_lock()) {
2025-02-26 18:46:36 +01:00
return;
}
2025-10-15 13:06:40 +02:00
moved = false;
2025-02-26 18:46:36 +01:00
locked = false;
2025-03-09 17:02:12 +01:00
iron_mouse_set_position(preLockX, preLockY);
2025-09-16 22:05:29 +02:00
iron_mouse_show();
2025-02-26 18:46:36 +01:00
}
2025-10-15 13:06:40 +02:00
static void (*pen_press_callback)(int /*x*/, int /*y*/, float /*pressure*/) = NULL;
static void (*pen_move_callback)(int /*x*/, int /*y*/, float /*pressure*/) = NULL;
2025-02-26 18:46:36 +01:00
static void (*pen_release_callback)(int /*x*/, int /*y*/, float /*pressure*/) = NULL;
2025-10-15 13:06:40 +02:00
static void (*eraser_press_callback)(int /*x*/, int /*y*/, float /*pressure*/) = NULL;
static void (*eraser_move_callback)(int /*x*/, int /*y*/, float /*pressure*/) = NULL;
2025-02-26 18:46:36 +01:00
static void (*eraser_release_callback)(int /*x*/, int /*y*/, float /*pressure*/) = NULL;
2025-03-09 17:02:12 +01:00
void iron_pen_set_press_callback(void (*value)(int /*x*/, int /*y*/, float /*pressure*/)) {
2025-02-26 18:46:36 +01:00
pen_press_callback = value;
}
2025-03-09 17:02:12 +01:00
void iron_pen_set_move_callback(void (*value)(int /*x*/, int /*y*/, float /*pressure*/)) {
2025-02-26 18:46:36 +01:00
pen_move_callback = value;
}
2025-03-09 17:02:12 +01:00
void iron_pen_set_release_callback(void (*value)(int /*x*/, int /*y*/, float /*pressure*/)) {
2025-02-26 18:46:36 +01:00
pen_release_callback = value;
}
2025-03-09 17:02:12 +01:00
void iron_eraser_set_press_callback(void (*value)(int /*x*/, int /*y*/, float /*pressure*/)) {
2025-02-26 18:46:36 +01:00
eraser_press_callback = value;
}
2025-03-09 17:02:12 +01:00
void iron_eraser_set_move_callback(void (*value)(int /*x*/, int /*y*/, float /*pressure*/)) {
2025-02-26 18:46:36 +01:00
eraser_move_callback = value;
}
2025-03-09 17:02:12 +01:00
void iron_eraser_set_release_callback(void (*value)(int /*x*/, int /*y*/, float /*pressure*/)) {
2025-02-26 18:46:36 +01:00
eraser_release_callback = value;
}
2025-03-09 17:02:12 +01:00
void iron_internal_pen_trigger_press(int x, int y, float pressure) {
2025-02-26 18:46:36 +01:00
if (pen_press_callback != NULL) {
pen_press_callback(x, y, pressure);
}
}
2025-03-09 17:02:12 +01:00
void iron_internal_pen_trigger_move(int x, int y, float pressure) {
2025-02-26 18:46:36 +01:00
if (pen_move_callback != NULL) {
pen_move_callback(x, y, pressure);
}
}
2025-03-09 17:02:12 +01:00
void iron_internal_pen_trigger_release(int x, int y, float pressure) {
2025-02-26 18:46:36 +01:00
if (pen_release_callback != NULL) {
pen_release_callback(x, y, pressure);
}
}
2025-03-09 17:02:12 +01:00
void iron_internal_eraser_trigger_press(int x, int y, float pressure) {
2025-02-26 18:46:36 +01:00
if (eraser_press_callback != NULL) {
eraser_press_callback(x, y, pressure);
}
}
2025-03-09 17:02:12 +01:00
void iron_internal_eraser_trigger_move(int x, int y, float pressure) {
2025-02-26 18:46:36 +01:00
if (eraser_move_callback != NULL) {
eraser_move_callback(x, y, pressure);
}
}
2025-03-09 17:02:12 +01:00
void iron_internal_eraser_trigger_release(int x, int y, float pressure) {
2025-02-26 18:46:36 +01:00
if (eraser_release_callback != NULL) {
eraser_release_callback(x, y, pressure);
}
}
static void (*surface_touch_start_callback)(int /*index*/, int /*x*/, int /*y*/) = NULL;
2025-10-15 13:06:40 +02:00
static void (*surface_move_callback)(int /*index*/, int /*x*/, int /*y*/) = NULL;
static void (*surface_touch_end_callback)(int /*index*/, int /*x*/, int /*y*/) = NULL;
2025-02-26 18:46:36 +01:00
2025-03-09 17:02:12 +01:00
void iron_surface_set_touch_start_callback(void (*value)(int /*index*/, int /*x*/, int /*y*/)) {
2025-02-26 18:46:36 +01:00
surface_touch_start_callback = value;
}
2025-03-09 17:02:12 +01:00
void iron_surface_set_move_callback(void (*value)(int /*index*/, int /*x*/, int /*y*/)) {
2025-02-26 18:46:36 +01:00
surface_move_callback = value;
}
2025-03-09 17:02:12 +01:00
void iron_surface_set_touch_end_callback(void (*value)(int /*index*/, int /*x*/, int /*y*/)) {
2025-02-26 18:46:36 +01:00
surface_touch_end_callback = value;
}
2025-03-09 17:02:12 +01:00
void iron_internal_surface_trigger_touch_start(int index, int x, int y) {
2025-02-26 18:46:36 +01:00
if (surface_touch_start_callback != NULL) {
surface_touch_start_callback(index, x, y);
}
}
2025-03-09 17:02:12 +01:00
void iron_internal_surface_trigger_move(int index, int x, int y) {
2025-02-26 18:46:36 +01:00
if (surface_move_callback != NULL) {
surface_move_callback(index, x, y);
}
}
2025-03-09 17:02:12 +01:00
void iron_internal_surface_trigger_touch_end(int index, int x, int y) {
2025-02-26 18:46:36 +01:00
if (surface_touch_end_callback != NULL) {
surface_touch_end_callback(index, x, y);
}
}
2025-08-03 13:23:42 +02:00
#ifdef WITH_GAMEPAD
2025-10-15 13:06:40 +02:00
static void (*gamepad_connect_callback)(int /*gamepad*/, void * /*userdata*/) = NULL;
static void *gamepad_connect_callback_userdata = NULL;
static void (*gamepad_disconnect_callback)(int /*gamepad*/, void * /*userdata*/) = NULL;
static void *gamepad_disconnect_callback_userdata = NULL;
static void (*gamepad_axis_callback)(int /*gamepad*/, int /*axis*/, float /*value*/, void * /*userdata*/) = NULL;
static void *gamepad_axis_callback_userdata = NULL;
2025-02-26 18:46:36 +01:00
static void (*gamepad_button_callback)(int /*gamepad*/, int /*button*/, float /*value*/, void * /*userdata*/) = NULL;
2025-10-15 13:06:40 +02:00
static void *gamepad_button_callback_userdata = NULL;
2025-02-26 18:46:36 +01:00
2025-03-09 17:02:12 +01:00
void iron_gamepad_set_connect_callback(void (*value)(int /*gamepad*/, void * /*userdata*/), void *userdata) {
2025-10-15 13:06:40 +02:00
gamepad_connect_callback = value;
2025-02-26 18:46:36 +01:00
gamepad_connect_callback_userdata = userdata;
}
2025-03-09 17:02:12 +01:00
void iron_gamepad_set_disconnect_callback(void (*value)(int /*gamepad*/, void * /*userdata*/), void *userdata) {
2025-10-15 13:06:40 +02:00
gamepad_disconnect_callback = value;
2025-02-26 18:46:36 +01:00
gamepad_disconnect_callback_userdata = userdata;
}
2025-03-09 17:02:12 +01:00
void iron_gamepad_set_axis_callback(void (*value)(int /*gamepad*/, int /*axis*/, float /*value*/, void * /*userdata*/), void *userdata) {
2025-10-15 13:06:40 +02:00
gamepad_axis_callback = value;
2025-02-26 18:46:36 +01:00
gamepad_axis_callback_userdata = userdata;
}
2025-03-09 17:02:12 +01:00
void iron_gamepad_set_button_callback(void (*value)(int /*gamepad*/, int /*button*/, float /*value*/, void * /*userdata*/), void *userdata) {
2025-10-15 13:06:40 +02:00
gamepad_button_callback = value;
2025-02-26 18:46:36 +01:00
gamepad_button_callback_userdata = userdata;
}
2025-03-09 17:02:12 +01:00
void iron_internal_gamepad_trigger_connect(int gamepad) {
2025-02-26 18:46:36 +01:00
if (gamepad_connect_callback != NULL) {
gamepad_connect_callback(gamepad, gamepad_connect_callback_userdata);
}
}
2025-03-09 17:02:12 +01:00
void iron_internal_gamepad_trigger_disconnect(int gamepad) {
2025-02-26 18:46:36 +01:00
if (gamepad_disconnect_callback != NULL) {
gamepad_disconnect_callback(gamepad, gamepad_disconnect_callback_userdata);
}
}
2025-03-09 17:02:12 +01:00
void iron_internal_gamepad_trigger_axis(int gamepad, int axis, float value) {
2025-02-26 18:46:36 +01:00
if (gamepad_axis_callback != NULL) {
gamepad_axis_callback(gamepad, axis, value, gamepad_axis_callback_userdata);
}
}
2025-03-09 17:02:12 +01:00
void iron_internal_gamepad_trigger_button(int gamepad, int button, float value) {
2025-02-26 18:46:36 +01:00
if (gamepad_button_callback != NULL) {
gamepad_button_callback(gamepad, button, value, gamepad_button_callback_userdata);
}
}
2025-08-03 13:23:42 +02:00
#endif