Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC fix : Return previous callbacks (set by C) #373

Open
wants to merge 3 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
5 changes: 3 additions & 2 deletions v3.3/glfw/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ void glfwSetMouseButtonCallbackCB(GLFWwindow *window) {
glfwSetMouseButtonCallback(window, (GLFWmousebuttonfun)goMouseButtonCB);
}

void glfwSetCursorPosCallbackCB(GLFWwindow *window) {
glfwSetCursorPosCallback(window, (GLFWcursorposfun)goCursorPosCB);
void goCursorPosCB_call(GLFWcursorposfun cbfun, GLFWwindow *window, double xpos, double ypos)
{
cbfun(window, xpos, ypos);
}

void glfwSetCursorEnterCallbackCB(GLFWwindow *window) {
Expand Down
24 changes: 18 additions & 6 deletions v3.3/glfw/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ package glfw
//#include <stdlib.h>
//#define GLFW_INCLUDE_NONE
//#include "glfw/include/GLFW/glfw3.h"
//
//void goCursorPosCB(GLFWwindow* window, double xpos, double ypos);
//
//void glfwSetJoystickCallbackCB();
//void glfwSetKeyCallbackCB(GLFWwindow *window);
//void glfwSetCharCallbackCB(GLFWwindow *window);
//void glfwSetCharModsCallbackCB(GLFWwindow *window);
//void glfwSetMouseButtonCallbackCB(GLFWwindow *window);
//void glfwSetCursorPosCallbackCB(GLFWwindow *window);
//void goCursorPosCB_call(GLFWcursorposfun cbfun, GLFWwindow *window, double xpos, double ypos);
//void glfwSetCursorEnterCallbackCB(GLFWwindow *window);
//void glfwSetScrollCallbackCB(GLFWwindow *window);
//void glfwSetDropCallbackCB(GLFWwindow *window);
Expand Down Expand Up @@ -335,8 +338,8 @@ func goMouseButtonCB(window unsafe.Pointer, button, action, mods C.int) {
}

//export goCursorPosCB
func goCursorPosCB(window unsafe.Pointer, xpos, ypos C.double) {
w := windows.get((*C.GLFWwindow)(window))
func goCursorPosCB(window *C.GLFWwindow, xpos, ypos C.double) {
w := windows.get(window)
w.fCursorPosHolder(w, float64(xpos), float64(ypos))
}

Expand Down Expand Up @@ -685,13 +688,22 @@ type CursorPosCallback func(w *Window, xpos float64, ypos float64)
func (w *Window) SetCursorPosCallback(cbfun CursorPosCallback) (previous CursorPosCallback) {
previous = w.fCursorPosHolder
w.fCursorPosHolder = cbfun
var previousC C.GLFWcursorposfun
if cbfun == nil {
C.glfwSetCursorPosCallback(w.data, nil)
previousC = C.glfwSetCursorPosCallback(w.data, nil)
} else {
C.glfwSetCursorPosCallbackCB(w.data)
previousC = C.glfwSetCursorPosCallback(w.data, (C.GLFWcursorposfun)(C.goCursorPosCB))
}
panicError()
return previous
if previousC == nil {
return nil
}
if previousC == (C.GLFWcursorposfun)(C.goCursorPosCB) {
return previous
}
return func(w2 *Window, xpos2 float64, ypos2 float64) {
C.goCursorPosCB_call(previousC, w2.data, C.double(xpos2), C.double(ypos2))
}
}

// CursorEnterCallback is the cursor boundary crossing callback.
Expand Down