Scroll Wheel support?
Monkey Forums/Monkey Beginners/Scroll Wheel support?
| ||
| Where is the code concerning scroll wheels? How do I make use of them? |
| ||
| https://www.google.com/search?q=site%3Amonkey-x.com+mouse+wheel |
| ||
| Look at this: http://www.monkey-x.com/Community/posts.php?topic=7783 My current code is this: https://bitbucket.org/Goodlookinguy/xaddon/src/be666414eb95/mojohacks/?at=default I haven't updated for GLFW 3 because it uses callbacks and I have to change a handful of things to make it play nice. Based on this: http://www.glfw.org/docs/3.0/group__input.html#ga6228cdf94d28fbd3a9a1fbb0e5922a8a typedef void(* GLFWscrollfun)(GLFWwindow *, double, double) I'd have to do something like this or something. (By the way, I think it was supposed to be GLFW scroll func, but someone forgot the c) class MojoHacks
{
static GLFWscrollfun ScrollCallback(GLFWwindow *window, double xOffset, double yOffset)
{
// or something
}
static GLFWscrollfun s_scrollCallback;
}
GLFWscrollfun MojoHacks::s_scrollCallback = MojoHacks::ScrollCallback;Edit: Or if I bothered to click that "glfwSetScrollCallback" link, I'd discover this... http://www.glfw.org/docs/3.0/group__input.html#gacf02eb10504352f16efda4593c3ce60e GLFWscrollfun glfwSetScrollCallback( GLFWwindow *window, GLFWscrollfun cbfun ) I'd need to know where in the native Mojo code to get the GLFWwindow from, then do something like this... class MojoHacks
{
static void BeginMouseWheelUpdate()
{
glfwSetScrollCallback(windowFromBBSomething, MojoHacks::ScrollCallback);
}
static GLFWscrollfun ScrollCallback(GLFWwindow *window, double xOffset, double yOffset)
{
// do stuff
}
} |
| ||
| My code doesn't work on GLFW3 either, sorry. Anyone willing to deal with the event callback stuff and proper externs feel free to do so. |
| ||
| This is my code for glfw3. Unfortunately it's non trivial: native.cpp
GLFWwindow* getWindow() {
return BBGlfwGame::GlfwGame()->GetGLFWwindow();
}
class MouseWheelInfo {
public:
Float x;
Float y;
MouseWheelInfo() : x(0.0), y(0.0) {}
};
MouseWheelInfo* wheelInfo;
void scrollwheelCallback(GLFWwindow* window, double xoffset, double yoffset) {
wheelInfo->x = Float(xoffset);
wheelInfo->y = Float(yoffset);
}
void NativeInit() {
GLFWwindow* window = getWindow();
glfwSetScrollCallback(window, &scrollwheelCallback);
wheelInfo = new MouseWheelInfo();
}
Float MouseZUnsafe() {
if (wheelInfo != 0) {
float z = wheelInfo->y;
wheelInfo->y = 0.0;
return z;
}
return 0.0;
}
native.monkey
#If TARGET = "glfw"
Public
Import "native.cpp"
Extern
Function NativeInit:Void() = "NativeInit"
Function MouseZUnsafe:Float() = "MouseZUnsafe"
Public
#End
Then in your monkey code import native.monkey and set MouseZUnsafe to a variable each frame! You then use this variable for your game code. Calling MouseZUnsafe more than once per frame will mess it up. |