Skip to content

Commit

Permalink
SDL: bring back continuous resize patch (#1077)
Browse files Browse the repository at this point in the history
  • Loading branch information
zbaylin authored May 29, 2021
1 parent d737fcd commit 234b461
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/reason-sdl2/src/sdl2.re
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,7 @@ let _nativeLoop = renderFn => {
};

let renderLoop = (renderFunction: renderFunction) => {
Callback.register("__sdl2_caml_resize__", renderFunction);
switch (Sys.backend_type) {
| Native => _nativeLoop(renderFunction)
| Bytecode => _nativeLoop(renderFunction)
Expand Down
20 changes: 20 additions & 0 deletions packages/reason-sdl2/src/sdl2_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,24 @@ extern "C" {
CAMLreturn(Val_unit);
}

int resdl_eventWatcher(void *data, SDL_Event *event) {
if (event->type == SDL_WINDOWEVENT &&
event->window.event == SDL_WINDOWEVENT_RESIZED) {
value args[] = {Val_unit};

static const value *resizeCallback = NULL;
if (resizeCallback == NULL) {
resizeCallback = caml_named_value("__sdl2_caml_resize__");
}

if (resizeCallback) {
caml_callbackN(*resizeCallback, 1, args);
}
}

return 0;
}

CAMLprim value resdl_SDL_CreateWindow(value vName, value vX, value vY,
value vWidth, value vHeight, value vAcceleration) {
CAMLparam5(vName, vX, vY, vWidth, vHeight);
Expand Down Expand Up @@ -1627,6 +1645,8 @@ extern "C" {
SDL_GetError());
}

SDL_AddEventWatch(resdl_eventWatcher, NULL);

vWindow = resdl_wrapPointer(win);
CAMLreturn(vWindow);
}
Expand Down

0 comments on commit 234b461

Please sign in to comment.