Fixed mouse hot spot coordinate

This commit is contained in:
Elias Naur 2003-10-11 12:56:26 +00:00
parent 43b2d67a71
commit 0fa67c9680
3 changed files with 9 additions and 7 deletions

View file

@ -77,6 +77,7 @@ public class Cursor {
if (!initialized) {
initialize();
}
yHotspot = height - 1 - yHotspot;
assert Mouse.isCreated();
assert width*height*numImages <= images.remaining(): "width*height*numImages > images.remaining()";
assert delays == null || numImages <= delays.remaining(): "delays != null && numImages > delays.remaining()";
@ -84,7 +85,7 @@ public class Cursor {
assert yHotspot < height && yHotspot >= 0: "yHotspot > height || yHotspot < 0";
IntBuffer images_copy = ByteBuffer.allocateDirect(images.remaining()*4).order(ByteOrder.nativeOrder()).asIntBuffer();
flipImages(width, height, numImages, images, images_copy);
nativeHandle = nCreateCursor(width, height, xHotspot, height - yHotspot, numImages, images_copy, 0, delays, delays != null ? delays.position() : 0);
nativeHandle = nCreateCursor(width, height, xHotspot, yHotspot, numImages, images_copy, 0, delays, delays != null ? delays.position() : 0);
}
private static void initialize() {

View file

@ -45,7 +45,6 @@
#include <X11/extensions/xf86vmode.h>
#include <assert.h>
#include <string.h>
#include <math.h>
#include <Window.h>
#include "org_lwjgl_input_Mouse.h"
#include "extxcursor.h"
@ -92,11 +91,14 @@ static void setCursorPos(int x, int y) {
current_y = cap(y, 0, getWindowHeight() - 1);
}
static void centerCursor() {
static void transformCursorPos(int x, int y) {
// transform to OpenGL coordinate system center
int x = getWindowWidth()/2;
int y = (int)ceil(getWindowHeight()/2.0f);
y = getWindowHeight() - 1 - y;
setCursorPos(x, y);
}
static void centerCursor() {
transformCursorPos(getWindowWidth()/2, getWindowHeight()/2);
last_x = current_x;
last_y = current_y;
}

View file

@ -41,7 +41,6 @@
#define WIN32_LEAN_AND_MEAN
#include "org_lwjgl_input_Mouse.h"
#include <windows.h>
#include <math.h>
#undef DIRECTINPUT_VERSION
#define DIRECTINPUT_VERSION 0x0300
#include "Window.h"
@ -175,7 +174,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nSetNativeCursor
GetWindowRect(hwnd, &windowRect);
getScreenClientRect(&clientRect, &windowRect);
cursorPos.x = (clientRect.left + clientRect.right)/2;
cursorPos.y = (int)ceil((clientRect.top + clientRect.bottom)/2.0f);
cursorPos.y = clientRect.bottom - 1 - (clientRect.bottom - clientRect.top)/2;
SetCursorPos(cursorPos.x, cursorPos.y);
ShowCursor(TRUE);
usingNativeCursor = true;