84 lines
2.4 KiB
C
84 lines
2.4 KiB
C
#include "cell.h"
|
|
#include <SDL3/SDL.h>
|
|
|
|
// Pen axis enum to string
|
|
static const char *pen_axis_to_string(SDL_PenAxis axis) {
|
|
switch (axis) {
|
|
case SDL_PEN_AXIS_PRESSURE: return "pressure";
|
|
case SDL_PEN_AXIS_XTILT: return "xtilt";
|
|
case SDL_PEN_AXIS_YTILT: return "ytilt";
|
|
case SDL_PEN_AXIS_DISTANCE: return "distance";
|
|
case SDL_PEN_AXIS_ROTATION: return "rotation";
|
|
case SDL_PEN_AXIS_SLIDER: return "slider";
|
|
case SDL_PEN_AXIS_TANGENTIAL_PRESSURE: return "tangential_pressure";
|
|
default: return "unknown";
|
|
}
|
|
}
|
|
|
|
static SDL_PenAxis string_to_pen_axis(const char *str) {
|
|
if (!str) return SDL_PEN_AXIS_PRESSURE;
|
|
if (!strcmp(str, "pressure")) return SDL_PEN_AXIS_PRESSURE;
|
|
if (!strcmp(str, "xtilt")) return SDL_PEN_AXIS_XTILT;
|
|
if (!strcmp(str, "ytilt")) return SDL_PEN_AXIS_YTILT;
|
|
if (!strcmp(str, "distance")) return SDL_PEN_AXIS_DISTANCE;
|
|
if (!strcmp(str, "rotation")) return SDL_PEN_AXIS_ROTATION;
|
|
if (!strcmp(str, "slider")) return SDL_PEN_AXIS_SLIDER;
|
|
if (!strcmp(str, "tangential_pressure")) return SDL_PEN_AXIS_TANGENTIAL_PRESSURE;
|
|
return SDL_PEN_AXIS_PRESSURE;
|
|
}
|
|
|
|
// Get pen axis count
|
|
JSC_CCALL(pen_get_axis_count,
|
|
return JS_NewInt32(js, SDL_PEN_AXIS_COUNT);
|
|
)
|
|
|
|
// Get pen axis name
|
|
JSC_CCALL(pen_get_axis_name,
|
|
int axis;
|
|
JS_ToInt32(js, &axis, argv[0]);
|
|
return JS_NewString(js, pen_axis_to_string((SDL_PenAxis)axis));
|
|
)
|
|
|
|
// Get pen axis from name
|
|
JSC_SCALL(pen_get_axis_from_name,
|
|
const char *name = JS_ToCString(js, argv[0]);
|
|
if (!name) return JS_EXCEPTION;
|
|
SDL_PenAxis axis = string_to_pen_axis(name);
|
|
JS_FreeCString(js, name);
|
|
return JS_NewInt32(js, axis);
|
|
)
|
|
|
|
// Pen input flags helpers
|
|
JSC_CCALL(pen_input_down,
|
|
return JS_NewUint32(js, SDL_PEN_INPUT_DOWN);
|
|
)
|
|
|
|
JSC_CCALL(pen_input_button_1,
|
|
return JS_NewUint32(js, SDL_PEN_INPUT_BUTTON_1);
|
|
)
|
|
|
|
JSC_CCALL(pen_input_button_2,
|
|
return JS_NewUint32(js, SDL_PEN_INPUT_BUTTON_2);
|
|
)
|
|
|
|
JSC_CCALL(pen_input_button_3,
|
|
return JS_NewUint32(js, SDL_PEN_INPUT_BUTTON_3);
|
|
)
|
|
|
|
JSC_CCALL(pen_input_eraser_tip,
|
|
return JS_NewUint32(js, SDL_PEN_INPUT_ERASER_TIP);
|
|
)
|
|
|
|
static const JSCFunctionListEntry js_pen_funcs[] = {
|
|
MIST_FUNC_DEF(pen, get_axis_count, 0),
|
|
MIST_FUNC_DEF(pen, get_axis_name, 1),
|
|
MIST_FUNC_DEF(pen, get_axis_from_name, 1),
|
|
MIST_FUNC_DEF(pen, input_down, 0),
|
|
MIST_FUNC_DEF(pen, input_button_1, 0),
|
|
MIST_FUNC_DEF(pen, input_button_2, 0),
|
|
MIST_FUNC_DEF(pen, input_button_3, 0),
|
|
MIST_FUNC_DEF(pen, input_eraser_tip, 0),
|
|
};
|
|
|
|
CELL_USE_FUNCS(js_pen_funcs)
|