Skip to content
This repository has been archived by the owner on Jun 6, 2020. It is now read-only.

Add bindings to GetWindowPosition #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions examples/basic.re
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ let run = () => {
/* glfwSetWindowSize(secondaryWindow, 800, 600); */
/* glfwSetWindowTitle(secondaryWindow, "second window"); */

let (x, y) = Sdl2.Window.getPosition(primaryWindow)

print_endline(
"Window position:\t" ++
string_of_int(x) ++
" x " ++
string_of_int(y)
);

let cursors = [|
Sdl2.Cursor.createSystem(Arrow),
Sdl2.Cursor.createSystem(IBeam),
Expand Down
1 change: 1 addition & 0 deletions src/sdl2.re
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ module Window = {
external setBordered: (t, bool) => unit = "resdl_SDL_SetWindowBordered";
external setIcon: (t, Surface.t) => unit = "resdl_SDL_SetWindowIcon";
external setPosition: (t, int, int) => unit = "resdl_SDL_SetWindowPosition";
external getPosition: t => (int, int) = "resdl_SDL_GetWindowPosition";
external center: t => unit = "resdl_SDL_WindowCenter";
external setResizable: (t, bool) => unit = "resdl_SDL_SetWindowResizable";
external setSize: (t, int, int) => unit = "resdl_SDL_SetWindowSize";
Expand Down
15 changes: 15 additions & 0 deletions src/sdl2_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,21 @@ CAMLprim value resdl_SDL_SetWindowPosition(value vWin, value vX, value vY) {
CAMLreturn(Val_unit);
}

CAMLprim value resdl_SDL_GetWindowPosition(value vWin) {
CAMLparam1(vWin);
int x, y;
SDL_Window *win = (SDL_Window *)vWin;
SDL_GetWindowPosition(win, &x, &y);

CAMLlocal1(ret);
ret = caml_alloc(2, 0);

Store_field(ret, 0, x);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be Store_field(ret, 0, Val_int(x))? I recall sometimes that there would be issues with this - see resdl_SDL_GetWindowSize/resdl_SDL_GetDrawableSize?

Store_field(ret, 1, y);

CAMLreturn(ret);
}

CAMLprim value resdl_SDL_WindowCenter(value vWin) {
CAMLparam1(vWin);

Expand Down