fix syntax

This commit is contained in:
2026-02-17 09:12:48 -06:00
parent 6f6f987649
commit d509f7cbb8
21 changed files with 503 additions and 453 deletions

91
video.c
View File

@@ -73,7 +73,7 @@ static JSValue js_SDL_Window_constructor(JSContext *js, JSValueConst new_target,
// Handle window position
JSValue x_val = JS_GetPropertyStr(js, opts, "x");
if (!JS_IsNull(x_val)) {
if (JS_IsString(x_val)) {
if (JS_IsText(x_val)) {
const char *pos = JS_ToCString(js, x_val);
if (strcmp(pos, "centered") == 0)
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_X_NUMBER, SDL_WINDOWPOS_CENTERED);
@@ -88,7 +88,7 @@ static JSValue js_SDL_Window_constructor(JSContext *js, JSValueConst new_target,
JSValue y_val = JS_GetPropertyStr(js, opts, "y");
if (!JS_IsNull(y_val)) {
if (JS_IsString(y_val)) {
if (JS_IsText(y_val)) {
const char *pos = JS_ToCString(js, y_val);
if (strcmp(pos, "centered") == 0)
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_Y_NUMBER, SDL_WINDOWPOS_CENTERED);
@@ -170,39 +170,40 @@ static JSValue js_SDL_Window_constructor(JSContext *js, JSValueConst new_target,
}
// Create the window JS object
JSValue window_obj = SDL_Window2js(js, window);
JS_FRAME(js);
JS_LOCAL(window_obj, SDL_Window2js(js, window));
// Set additional properties that can't be set during creation
// These will be applied through the property setters
JSValue opacity_val = JS_GetPropertyStr(js, opts, "opacity");
if (!JS_IsNull(opacity_val)) {
JS_SetPropertyStr(js, window_obj, "opacity", opacity_val);
}
JSValue min_size_val = JS_GetPropertyStr(js, opts, "minimumSize");
if (!JS_IsNull(min_size_val)) {
JS_SetPropertyStr(js, window_obj, "minimumSize", min_size_val);
}
JSValue max_size_val = JS_GetPropertyStr(js, opts, "maximumSize");
if (!JS_IsNull(max_size_val)) {
JS_SetPropertyStr(js, window_obj, "maximumSize", max_size_val);
}
JSValue pos_val = JS_GetPropertyStr(js, opts, "position");
if (!JS_IsNull(pos_val)) {
JS_SetPropertyStr(js, window_obj, "position", pos_val);
}
// Handle text input
JSValue text_input = JS_GetPropertyStr(js, opts, "textInput");
if (JS_ToBool(js, text_input)) {
// SDL_StartTextInput(window);
}
JS_FreeValue(js, text_input);
return window_obj;
JS_RETURN(window_obj);
}
JSC_CCALL(SDL_Window_fullscreen,
@@ -534,7 +535,7 @@ JSValue js_window_flash(JSContext *js, JSValue self, int argc, JSValue *argv)
{
SDL_Window *w = js2SDL_Window(js,self);
SDL_FlashOperation op = SDL_FLASH_BRIEFLY;
if (argc > 0 && JS_IsString(argv[0])) {
if (argc > 0 && JS_IsText(argv[0])) {
const char *operation = JS_ToCString(js,argv[0]);
if (strcmp(operation, "cancel") == 0) op = SDL_FLASH_CANCEL;
else if (strcmp(operation, "briefly") == 0) op = SDL_FLASH_BRIEFLY;
@@ -616,14 +617,14 @@ JSValue js_window_updateSurfaceRects(JSContext *js, JSValue self, int argc, JSVa
{
SDL_Window *w = js2SDL_Window(js,self);
if (!JS_IsArray(js, argv[0]))
if (!JS_IsArray(argv[0]))
return JS_ThrowTypeError(js, "Expected array of rectangles");
int len = JS_ArrayLength(js, argv[0]);
SDL_Rect rects[len];
for (int i = 0; i < len; i++) {
JSValue val = JS_GetPropertyUint32(js, argv[0], i);
JSValue val = JS_GetPropertyNumber(js, argv[0], i);
rect r = js2rect(js, val);
rects[i] = (SDL_Rect){r.x, r.y, r.w, r.h};
JS_FreeValue(js, val);
@@ -638,8 +639,9 @@ JSValue js_window_get_flags(JSContext *js, JSValue self)
{
SDL_Window *w = js2SDL_Window(js,self);
SDL_WindowFlags flags = SDL_GetWindowFlags(w);
JSValue ret = JS_NewObject(js);
JS_FRAME(js);
JS_LOCAL(ret, JS_NewObject(js));
JS_SetPropertyStr(js, ret, "fullscreen", JS_NewBool(js, flags & SDL_WINDOW_FULLSCREEN));
JS_SetPropertyStr(js, ret, "opengl", JS_NewBool(js, flags & SDL_WINDOW_OPENGL));
JS_SetPropertyStr(js, ret, "occluded", JS_NewBool(js, flags & SDL_WINDOW_OCCLUDED));
@@ -665,8 +667,8 @@ JSValue js_window_get_flags(JSContext *js, JSValue self)
JS_SetPropertyStr(js, ret, "metal", JS_NewBool(js, flags & SDL_WINDOW_METAL));
JS_SetPropertyStr(js, ret, "transparent", JS_NewBool(js, flags & SDL_WINDOW_TRANSPARENT));
JS_SetPropertyStr(js, ret, "notFocusable", JS_NewBool(js, flags & SDL_WINDOW_NOT_FOCUSABLE));
return ret;
JS_RETURN(ret);
}
JSValue js_window_sync(JSContext *js, JSValue self, int argc, JSValue *argv)
@@ -742,52 +744,53 @@ JSValue js_window_set(JSContext *js, JSValue self, int argc, JSValue *argv)
JSValue js_window_state(JSContext *js, JSValue self, int argc, JSValue *argv)
{
SDL_Window *w = js2SDL_Window(js,self);
JSValue ret = JS_NewObject(js);
JS_FRAME(js);
JS_LOCAL(ret, JS_NewObject(js));
// Title
const char *title = SDL_GetWindowTitle(w);
JS_SetPropertyStr(js, ret, "title", JS_NewString(js, title ? title : ""));
// Size
int width, height;
SDL_GetWindowSize(w, &width, &height);
JSValue sizeObj = JS_NewObject(js);
JS_LOCAL(sizeObj, JS_NewObject(js));
JS_SetPropertyStr(js, sizeObj, "x", JS_NewInt32(js, width));
JS_SetPropertyStr(js, sizeObj, "y", JS_NewInt32(js, height));
JS_SetPropertyStr(js, ret, "size", sizeObj);
// Position
int x, y;
SDL_GetWindowPosition(w, &x, &y);
JSValue posObj = JS_NewObject(js);
JS_LOCAL(posObj, JS_NewObject(js));
JS_SetPropertyStr(js, posObj, "x", JS_NewInt32(js, x));
JS_SetPropertyStr(js, posObj, "y", JS_NewInt32(js, y));
JS_SetPropertyStr(js, ret, "position", posObj);
// Minimum size
int minW, minH;
SDL_GetWindowMinimumSize(w, &minW, &minH);
JSValue minSizeObj = JS_NewObject(js);
JS_LOCAL(minSizeObj, JS_NewObject(js));
JS_SetPropertyStr(js, minSizeObj, "x", JS_NewInt32(js, minW));
JS_SetPropertyStr(js, minSizeObj, "y", JS_NewInt32(js, minH));
JS_SetPropertyStr(js, ret, "minimumSize", minSizeObj);
// Maximum size
int maxW, maxH;
SDL_GetWindowMaximumSize(w, &maxW, &maxH);
JSValue maxSizeObj = JS_NewObject(js);
JS_LOCAL(maxSizeObj, JS_NewObject(js));
JS_SetPropertyStr(js, maxSizeObj, "x", JS_NewInt32(js, maxW));
JS_SetPropertyStr(js, maxSizeObj, "y", JS_NewInt32(js, maxH));
JS_SetPropertyStr(js, ret, "maximumSize", maxSizeObj);
// Opacity
float opacity = SDL_GetWindowOpacity(w);
JS_SetPropertyStr(js, ret, "opacity", JS_NewFloat64(js, opacity));
// Grabs
JS_SetPropertyStr(js, ret, "mouseGrab", JS_NewBool(js, SDL_GetWindowMouseGrab(w)));
JS_SetPropertyStr(js, ret, "keyboardGrab", JS_NewBool(js, SDL_GetWindowKeyboardGrab(w)));
// Flags-based properties
SDL_WindowFlags flags = SDL_GetWindowFlags(w);
JS_SetPropertyStr(js, ret, "fullscreen", JS_NewBool(js, flags & SDL_WINDOW_FULLSCREEN));
@@ -803,28 +806,28 @@ JSValue js_window_state(JSContext *js, JSValue self, int argc, JSValue *argv)
// Display properties
JS_SetPropertyStr(js, ret, "displayScale", JS_NewFloat64(js, SDL_GetWindowDisplayScale(w)));
JS_SetPropertyStr(js, ret, "pixelDensity", JS_NewFloat64(js, SDL_GetWindowPixelDensity(w)));
// Size in pixels
int pixelW, pixelH;
SDL_GetWindowSizeInPixels(w, &pixelW, &pixelH);
JSValue pixelSizeObj = JS_NewObject(js);
JS_LOCAL(pixelSizeObj, JS_NewObject(js));
JS_SetPropertyStr(js, pixelSizeObj, "x", JS_NewInt32(js, pixelW));
JS_SetPropertyStr(js, pixelSizeObj, "y", JS_NewInt32(js, pixelH));
JS_SetPropertyStr(js, ret, "sizeInPixels", pixelSizeObj);
// Flags
JS_SetPropertyStr(js, ret, "flags", JS_NewInt64(js, flags));
JS_SetPropertyStr(js, ret, "id", JS_NewUint32(js, SDL_GetWindowID(w)));
// Parent
SDL_Window *parent = SDL_GetWindowParent(w);
if (parent)
JS_SetPropertyStr(js, ret, "parent", SDL_Window2js(js, parent));
else
JS_SetPropertyStr(js, ret, "parent", JS_NULL);
return ret;
JS_RETURN(ret);
}
@@ -873,17 +876,17 @@ JSC_CCALL(sdl_set_cursor,
CELL_USE_INIT(
if (!SDL_Init(SDL_INIT_VIDEO))
return JS_ThrowInternalError(js, "Unable to initialize video subsystem: %s", SDL_GetError());
JSValue ret = JS_NewObject(js);
JS_FRAME(js);
JS_LOCAL(ret, JS_NewObject(js));
JS_SetPropertyStr(js, ret, "window", QJSCLASSPREP_FUNCS_CTOR(SDL_Window, 1));
QJSCLASSPREP_NO_FUNCS(SDL_Cursor);
// Add cursor functions
JS_SetPropertyStr(js, ret, "createCursor", JS_NewCFunction(js, js_sdl_create_cursor, "createCursor", 2));
JS_SetPropertyStr(js, ret, "setCursor", JS_NewCFunction(js, js_sdl_set_cursor, "setCursor", 1));
return ret;
JS_RETURN(ret);
)