2002-11-15 05:40:55 -05:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2002 Light Weight Java Game Library Project
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* * Neither the name of 'Light Weight Java Game Library' nor the names of
|
|
|
|
* its contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* $Id$
|
|
|
|
*
|
2002-11-15 06:10:32 -05:00
|
|
|
* Linux mouse handling.
|
2002-11-15 05:40:55 -05:00
|
|
|
*
|
2002-11-15 06:10:32 -05:00
|
|
|
* @author elias_naur <elias_naur@users.sourceforge.net>
|
2002-11-15 05:40:55 -05:00
|
|
|
* @version $Revision$
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <X11/X.h>
|
|
|
|
#include <X11/Xlib.h>
|
2002-11-20 08:54:58 -05:00
|
|
|
#include <X11/extensions/xf86vmode.h>
|
2002-11-15 05:40:55 -05:00
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
2003-10-11 12:29:40 -04:00
|
|
|
#include "Window.h"
|
|
|
|
#include "common_tools.h"
|
2002-11-15 05:40:55 -05:00
|
|
|
#include "org_lwjgl_input_Mouse.h"
|
2003-05-16 14:39:46 -04:00
|
|
|
#include "extxcursor.h"
|
2002-11-15 05:40:55 -05:00
|
|
|
|
2002-11-17 11:49:16 -05:00
|
|
|
#define NUM_BUTTONS 3
|
2002-11-15 05:40:55 -05:00
|
|
|
|
2002-11-28 16:49:11 -05:00
|
|
|
#define POINTER_WARP_BORDER 10
|
|
|
|
#define WARP_RETRY 5
|
2003-02-24 14:46:52 -05:00
|
|
|
// scale the mouse wheel according to win32
|
|
|
|
#define WHEEL_SCALE 120
|
2002-11-28 16:49:11 -05:00
|
|
|
|
2003-05-16 14:39:46 -04:00
|
|
|
static bool pointer_grabbed = false;
|
2003-02-12 12:12:01 -05:00
|
|
|
static bool created = false;
|
2003-02-14 06:23:01 -05:00
|
|
|
static bool should_grab = false;
|
2003-05-16 14:39:46 -04:00
|
|
|
static bool native_cursor = false;
|
2002-11-15 05:40:55 -05:00
|
|
|
|
2003-02-08 15:36:31 -05:00
|
|
|
static jfieldID fid_buttons = NULL;
|
|
|
|
static jfieldID fid_dx = NULL;
|
|
|
|
static jfieldID fid_dy = NULL;
|
|
|
|
static jfieldID fid_dwheel = NULL;
|
2002-11-15 05:40:55 -05:00
|
|
|
|
2003-02-08 14:55:07 -05:00
|
|
|
static int last_x;
|
|
|
|
static int last_y;
|
|
|
|
static int last_z;
|
|
|
|
static int current_x;
|
|
|
|
static int current_y;
|
|
|
|
static int current_z;
|
2003-10-11 12:29:40 -04:00
|
|
|
static jbyte buttons[NUM_BUTTONS];
|
|
|
|
static event_queue_t event_queue;
|
|
|
|
static bool buffer_enabled;
|
2002-11-15 05:40:55 -05:00
|
|
|
|
2003-02-08 14:55:07 -05:00
|
|
|
static Cursor blank_cursor;
|
2003-05-16 14:39:46 -04:00
|
|
|
static Cursor current_cursor;
|
|
|
|
|
2003-08-11 12:35:45 -04:00
|
|
|
static int cap(int val, int min, int max) {
|
|
|
|
if (val < min)
|
|
|
|
return min;
|
|
|
|
else if (val > max)
|
|
|
|
return max;
|
|
|
|
else
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setCursorPos(int x, int y) {
|
|
|
|
current_x = cap(x, 0, getWindowWidth() - 1);
|
|
|
|
current_y = cap(y, 0, getWindowHeight() - 1);
|
|
|
|
}
|
|
|
|
|
2003-10-11 08:56:26 -04:00
|
|
|
static void transformCursorPos(int x, int y) {
|
2003-10-11 07:03:06 -04:00
|
|
|
// transform to OpenGL coordinate system center
|
2003-10-11 08:56:26 -04:00
|
|
|
y = getWindowHeight() - 1 - y;
|
2003-10-11 07:03:06 -04:00
|
|
|
setCursorPos(x, y);
|
2003-10-11 08:56:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void centerCursor() {
|
|
|
|
transformCursorPos(getWindowWidth()/2, getWindowHeight()/2);
|
2003-10-11 07:03:06 -04:00
|
|
|
last_x = current_x;
|
|
|
|
last_y = current_y;
|
|
|
|
}
|
|
|
|
|
2002-11-15 05:40:55 -05:00
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_initIDs
|
|
|
|
(JNIEnv * env, jclass clazz)
|
|
|
|
{
|
2003-02-08 15:36:31 -05:00
|
|
|
if (fid_buttons == NULL)
|
2003-10-11 12:29:40 -04:00
|
|
|
fid_buttons = env->GetStaticFieldID(clazz, "buttons", "[B");
|
2003-02-08 15:36:31 -05:00
|
|
|
if (fid_dx == NULL)
|
2002-11-19 03:50:57 -05:00
|
|
|
fid_dx = env->GetStaticFieldID(clazz, "dx", "I");
|
2003-02-08 15:36:31 -05:00
|
|
|
if (fid_dy == NULL)
|
2002-11-19 03:50:57 -05:00
|
|
|
fid_dy = env->GetStaticFieldID(clazz, "dy", "I");
|
2003-02-08 15:36:31 -05:00
|
|
|
if (fid_dwheel == NULL)
|
|
|
|
fid_dwheel = env->GetStaticFieldID(clazz, "dwheel", "I");
|
2002-11-15 05:40:55 -05:00
|
|
|
}
|
|
|
|
|
2003-10-11 09:23:55 -04:00
|
|
|
static bool blankCursor(void) {
|
2002-11-19 03:50:57 -05:00
|
|
|
unsigned int best_width, best_height;
|
2003-03-30 14:26:39 -05:00
|
|
|
if (XQueryBestCursor(getCurrentDisplay(), getCurrentWindow(), 1, 1, &best_width, &best_height) == 0) {
|
2003-12-20 17:03:25 -05:00
|
|
|
printfDebug("Could not query best cursor size\n");
|
2003-10-11 09:23:55 -04:00
|
|
|
return false;
|
2002-11-17 11:14:53 -05:00
|
|
|
}
|
2003-03-30 14:26:39 -05:00
|
|
|
Pixmap mask = XCreatePixmap(getCurrentDisplay(), getCurrentWindow(), best_width, best_height, 1);
|
2002-11-17 11:14:53 -05:00
|
|
|
XGCValues gc_values;
|
|
|
|
gc_values.foreground = 0;
|
2003-03-30 14:26:39 -05:00
|
|
|
GC gc = XCreateGC(getCurrentDisplay(), mask, GCForeground, &gc_values);
|
|
|
|
XFillRectangle(getCurrentDisplay(), mask, gc, 0, 0, best_width, best_height);
|
|
|
|
XFreeGC(getCurrentDisplay(), gc);
|
2002-11-17 11:14:53 -05:00
|
|
|
XColor dummy_color;
|
2003-03-30 14:26:39 -05:00
|
|
|
blank_cursor = XCreatePixmapCursor(getCurrentDisplay(), mask, mask, &dummy_color, &dummy_color, 0, 0);
|
|
|
|
XFreePixmap(getCurrentDisplay(), mask);
|
2003-10-11 09:23:55 -04:00
|
|
|
return true;
|
2002-11-17 11:14:53 -05:00
|
|
|
}
|
|
|
|
|
2003-05-16 14:39:46 -04:00
|
|
|
bool isNativeCursor(void) {
|
|
|
|
return native_cursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void grabPointer(void) {
|
|
|
|
if (isFullscreen() || !native_cursor) {
|
|
|
|
if (!pointer_grabbed) {
|
|
|
|
int result;
|
2003-08-05 10:21:59 -04:00
|
|
|
int grab_mask = PointerMotionMask | ButtonPressMask | ButtonReleaseMask;
|
2003-05-16 14:39:46 -04:00
|
|
|
result = XGrabPointer(getCurrentDisplay(), getCurrentWindow(), False, grab_mask, GrabModeAsync,
|
|
|
|
GrabModeAsync, getCurrentWindow(), current_cursor, CurrentTime);
|
|
|
|
if (result == GrabSuccess) {
|
|
|
|
pointer_grabbed = true;
|
|
|
|
// make sure we have a centered window
|
|
|
|
XF86VidModeSetViewPort(getCurrentDisplay(), getCurrentScreen(), 0, 0);
|
2003-06-01 13:20:03 -04:00
|
|
|
XFlush(getCurrentDisplay());
|
2003-05-16 14:39:46 -04:00
|
|
|
}
|
|
|
|
}
|
2003-05-02 09:41:40 -04:00
|
|
|
}
|
2002-11-20 05:33:37 -05:00
|
|
|
}
|
|
|
|
|
2003-02-14 06:23:01 -05:00
|
|
|
static void ungrabPointer(void) {
|
2003-05-16 14:39:46 -04:00
|
|
|
if (pointer_grabbed) {
|
|
|
|
pointer_grabbed = false;
|
|
|
|
XUngrabPointer(getCurrentDisplay(), CurrentTime);
|
2003-06-01 13:20:03 -04:00
|
|
|
XFlush(getCurrentDisplay());
|
2003-05-16 14:39:46 -04:00
|
|
|
}
|
2002-11-20 05:33:37 -05:00
|
|
|
}
|
|
|
|
|
2003-02-14 06:23:01 -05:00
|
|
|
static void updateGrab(void) {
|
2003-05-16 14:39:46 -04:00
|
|
|
if (!created)
|
|
|
|
return;
|
2003-02-14 06:23:01 -05:00
|
|
|
if (should_grab) {
|
2003-05-16 14:39:46 -04:00
|
|
|
grabPointer();
|
2003-02-14 06:23:01 -05:00
|
|
|
} else {
|
2003-05-16 14:39:46 -04:00
|
|
|
ungrabPointer();
|
2003-02-14 06:23:01 -05:00
|
|
|
}
|
2002-11-20 05:33:37 -05:00
|
|
|
}
|
|
|
|
|
2003-05-02 09:41:40 -04:00
|
|
|
void acquirePointer(void) {
|
|
|
|
should_grab = true;
|
|
|
|
updateGrab();
|
|
|
|
}
|
|
|
|
|
|
|
|
void releasePointer(void) {
|
|
|
|
should_grab = false;
|
|
|
|
updateGrab();
|
|
|
|
}
|
|
|
|
|
2003-10-11 07:03:06 -04:00
|
|
|
static void doWarpPointer(void ) {
|
2003-10-11 12:29:40 -04:00
|
|
|
int i;
|
|
|
|
centerCursor();
|
2003-10-11 07:03:06 -04:00
|
|
|
XWarpPointer(getCurrentDisplay(), None, getCurrentWindow(), 0, 0, 0, 0, current_x, current_y);
|
|
|
|
XEvent event;
|
|
|
|
// Try to catch the warp pointer event
|
2003-10-11 12:29:40 -04:00
|
|
|
for (i = 0; i < WARP_RETRY; i++) {
|
2003-10-11 07:03:06 -04:00
|
|
|
XMaskEvent(getCurrentDisplay(), PointerMotionMask, &event);
|
|
|
|
if (event.xmotion.x > current_x - POINTER_WARP_BORDER &&
|
|
|
|
event.xmotion.x < current_x + POINTER_WARP_BORDER &&
|
|
|
|
event.xmotion.y > current_y - POINTER_WARP_BORDER &&
|
|
|
|
event.xmotion.y < current_y + POINTER_WARP_BORDER)
|
|
|
|
break;
|
2003-12-20 17:03:25 -05:00
|
|
|
printfDebug("Skipped event searching for warp event %d, %d\n", event.xmotion.x, event.xmotion.y);
|
2003-10-11 07:03:06 -04:00
|
|
|
}
|
|
|
|
if (i == WARP_RETRY)
|
2003-12-20 17:03:25 -05:00
|
|
|
printfDebug("Never got warp event\n");
|
2003-10-11 07:03:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void warpPointer(void) {
|
|
|
|
if (!pointer_grabbed || native_cursor)
|
|
|
|
return;
|
|
|
|
// Reset pointer to middle of screen if outside a certain inner border
|
|
|
|
if (current_x < POINTER_WARP_BORDER || current_y < POINTER_WARP_BORDER ||
|
|
|
|
current_x > getWindowWidth() - POINTER_WARP_BORDER || current_y > getWindowHeight() - POINTER_WARP_BORDER)
|
|
|
|
doWarpPointer();
|
|
|
|
}
|
|
|
|
|
2003-05-16 14:39:46 -04:00
|
|
|
/*
|
|
|
|
* Class: org_lwjgl_input_Mouse
|
|
|
|
* Method: nIsNativeCursorSupported
|
|
|
|
* Signature: ()Z
|
|
|
|
*/
|
2003-05-20 08:20:13 -04:00
|
|
|
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nGetNativeCursorCaps
|
2003-05-16 14:39:46 -04:00
|
|
|
(JNIEnv *env, jclass clazz) {
|
2003-10-11 12:29:40 -04:00
|
|
|
int caps = 0;
|
2003-05-16 14:39:46 -04:00
|
|
|
if (!isXcursorLoaded())
|
2003-05-20 08:20:13 -04:00
|
|
|
return caps;
|
2003-05-16 14:39:46 -04:00
|
|
|
XcursorBool argb_supported = XcursorSupportsARGB(getCurrentDisplay());
|
|
|
|
XcursorBool anim_supported = XcursorSupportsAnim(getCurrentDisplay());
|
2003-10-11 12:29:40 -04:00
|
|
|
if (argb_supported)
|
2003-08-29 04:00:44 -04:00
|
|
|
caps |= org_lwjgl_input_Mouse_CURSOR_8_BIT_ALPHA | org_lwjgl_input_Mouse_CURSOR_ONE_BIT_TRANSPARENCY;
|
2003-05-20 08:20:13 -04:00
|
|
|
if (anim_supported)
|
|
|
|
caps |= org_lwjgl_input_Mouse_CURSOR_ANIMATION;
|
|
|
|
return caps;
|
2003-05-16 14:39:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_lwjgl_input_Mouse
|
|
|
|
* Method: nSetNativeCursor
|
|
|
|
* Signature: (I)V
|
|
|
|
*/
|
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nSetNativeCursor
|
2003-10-08 03:49:43 -04:00
|
|
|
(JNIEnv *env, jclass clazz, jlong cursor_handle)
|
2003-05-16 14:39:46 -04:00
|
|
|
{
|
2003-06-24 08:24:55 -04:00
|
|
|
if (cursor_handle != 0) {
|
|
|
|
Cursor cursor = (Cursor)cursor_handle;
|
2003-05-16 14:39:46 -04:00
|
|
|
if (!native_cursor) {
|
2003-10-11 07:03:06 -04:00
|
|
|
doWarpPointer();
|
2003-05-16 14:39:46 -04:00
|
|
|
native_cursor = true;
|
|
|
|
}
|
|
|
|
XDefineCursor(getCurrentDisplay(), getCurrentWindow(), cursor);
|
|
|
|
current_cursor = cursor;
|
|
|
|
updateInput();
|
|
|
|
} else {
|
|
|
|
if (native_cursor) {
|
|
|
|
current_cursor = blank_cursor;
|
|
|
|
XUndefineCursor(getCurrentDisplay(), getCurrentWindow());
|
|
|
|
native_cursor = false;
|
|
|
|
updateInput();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_lwjgl_input_Mouse
|
|
|
|
* Method: nGetMaxCursorSize
|
|
|
|
* Signature: ()I
|
|
|
|
*/
|
|
|
|
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nGetMinCursorSize
|
|
|
|
(JNIEnv *env, jclass clazz)
|
|
|
|
{
|
2003-06-08 10:30:53 -04:00
|
|
|
unsigned int width_return = 0;
|
|
|
|
unsigned int height_return = 0;
|
|
|
|
XQueryBestCursor(getCurrentDisplay(), getCurrentWindow(), 1, 1, &width_return, &height_return);
|
2003-06-08 10:32:30 -04:00
|
|
|
return width_return > height_return ? width_return : height_return;
|
2003-05-16 14:39:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_lwjgl_input_Mouse
|
|
|
|
* Method: nGetMaxCursorSize
|
|
|
|
* Signature: ()I
|
|
|
|
*/
|
|
|
|
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nGetMaxCursorSize
|
|
|
|
(JNIEnv *env, jclass clazz)
|
|
|
|
{
|
|
|
|
unsigned int width_return = 0;
|
|
|
|
unsigned int height_return = 0;
|
|
|
|
XQueryBestCursor(getCurrentDisplay(), getCurrentWindow(), 0xffffffff, 0xffffffff, &width_return, &height_return);
|
|
|
|
return width_return > height_return ? height_return : width_return;
|
|
|
|
}
|
|
|
|
|
2003-10-07 09:10:17 -04:00
|
|
|
JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_Mouse_nHasWheel(JNIEnv *, jclass) {
|
|
|
|
return JNI_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nGetButtonCount(JNIEnv *, jclass) {
|
|
|
|
return NUM_BUTTONS;
|
|
|
|
}
|
|
|
|
|
2003-09-30 07:14:06 -04:00
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nCreate
|
2002-11-15 05:40:55 -05:00
|
|
|
(JNIEnv * env, jclass clazz)
|
|
|
|
{
|
|
|
|
int i;
|
2003-10-11 07:03:06 -04:00
|
|
|
current_z = last_z = 0;
|
2002-11-15 05:40:55 -05:00
|
|
|
for (i = 0; i < NUM_BUTTONS; i++)
|
2003-10-11 12:29:40 -04:00
|
|
|
buttons[i] = 0;
|
2002-11-17 11:14:53 -05:00
|
|
|
if (!blankCursor()) {
|
2003-09-30 07:14:06 -04:00
|
|
|
throwException(env, "Could not create blank cursor");
|
|
|
|
return;
|
2002-11-15 05:40:55 -05:00
|
|
|
}
|
2003-05-16 14:39:46 -04:00
|
|
|
current_cursor = blank_cursor;
|
2003-10-11 12:29:40 -04:00
|
|
|
native_cursor = false;
|
2003-02-12 12:12:01 -05:00
|
|
|
created = true;
|
2003-02-14 06:23:01 -05:00
|
|
|
should_grab = true;
|
2003-10-11 12:29:40 -04:00
|
|
|
pointer_grabbed = false;
|
|
|
|
buffer_enabled = false;
|
2003-02-14 06:23:01 -05:00
|
|
|
updateGrab();
|
2003-10-11 12:29:40 -04:00
|
|
|
initEventQueue(&event_queue);
|
2003-05-16 14:39:46 -04:00
|
|
|
loadXcursor();
|
2003-10-20 08:49:50 -04:00
|
|
|
doWarpPointer();
|
2002-11-15 05:40:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nDestroy
|
|
|
|
(JNIEnv * env, jclass clazz)
|
|
|
|
{
|
2003-05-16 14:39:46 -04:00
|
|
|
closeXcursor();
|
|
|
|
ungrabPointer();
|
2003-03-30 14:26:39 -05:00
|
|
|
XFreeCursor(getCurrentDisplay(), blank_cursor);
|
2003-02-12 12:12:01 -05:00
|
|
|
created = false;
|
2003-02-14 06:23:01 -05:00
|
|
|
should_grab = false;
|
2002-11-15 05:40:55 -05:00
|
|
|
}
|
|
|
|
|
2003-10-11 12:29:40 -04:00
|
|
|
static unsigned char mapButton(XButtonEvent *event) {
|
|
|
|
switch (event->button) {
|
|
|
|
case Button1:
|
|
|
|
return 0;
|
|
|
|
case Button2:
|
|
|
|
return 2;
|
|
|
|
case Button3:
|
|
|
|
return 1;
|
|
|
|
default: return NUM_BUTTONS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handleButton(XButtonEvent *event, unsigned char state) {
|
|
|
|
unsigned char button_num = mapButton(event);
|
|
|
|
if (button_num == NUM_BUTTONS)
|
|
|
|
return;
|
|
|
|
buttons[button_num] = state;
|
|
|
|
if (buffer_enabled) {
|
|
|
|
putEventElement(&event_queue, button_num);
|
|
|
|
putEventElement(&event_queue, state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-09 12:01:01 -05:00
|
|
|
void handleButtonPress(XButtonEvent *event) {
|
2003-05-16 14:39:46 -04:00
|
|
|
if (pointer_grabbed || native_cursor) {
|
|
|
|
switch (event->button) {
|
|
|
|
case Button4:
|
|
|
|
current_z += WHEEL_SCALE;
|
|
|
|
break;
|
|
|
|
case Button5:
|
|
|
|
current_z -= WHEEL_SCALE;
|
|
|
|
break;
|
2003-10-11 12:29:40 -04:00
|
|
|
default: break;
|
2003-05-16 14:39:46 -04:00
|
|
|
}
|
2003-10-11 12:29:40 -04:00
|
|
|
handleButton(event, 1);
|
2002-11-15 05:40:55 -05:00
|
|
|
}
|
2003-02-09 12:01:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void handleButtonRelease(XButtonEvent *event) {
|
2003-05-16 14:39:46 -04:00
|
|
|
if (pointer_grabbed || native_cursor) {
|
2003-10-11 12:29:40 -04:00
|
|
|
handleButton(event, 0);
|
2003-02-09 12:01:01 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void handlePointerMotion(XMotionEvent *event) {
|
2003-08-11 12:35:45 -04:00
|
|
|
if (pointer_grabbed || native_cursor)
|
2003-10-11 12:29:40 -04:00
|
|
|
setCursorPos(event->x, event->y);
|
2002-11-15 05:40:55 -05:00
|
|
|
}
|
|
|
|
|
2003-10-11 12:29:40 -04:00
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nPoll(JNIEnv * env, jclass clazz) {
|
2002-11-15 05:40:55 -05:00
|
|
|
int moved_x = current_x - last_x;
|
2003-10-11 12:29:40 -04:00
|
|
|
int moved_y = -(current_y - last_y);
|
2002-11-17 11:49:16 -05:00
|
|
|
int moved_z = current_z - last_z;
|
2002-11-19 03:50:57 -05:00
|
|
|
env->SetStaticIntField(clazz, fid_dx, (jint)moved_x);
|
2003-10-11 12:29:40 -04:00
|
|
|
env->SetStaticIntField(clazz, fid_dy, (jint)moved_y);
|
2003-02-08 15:36:31 -05:00
|
|
|
env->SetStaticIntField(clazz, fid_dwheel, (jint)moved_z);
|
2002-11-15 05:40:55 -05:00
|
|
|
last_x = current_x;
|
|
|
|
last_y = current_y;
|
2002-11-17 11:49:16 -05:00
|
|
|
last_z = current_z;
|
2003-10-11 12:29:40 -04:00
|
|
|
jbyteArray buttons_array = (jbyteArray)env->GetStaticObjectField(clazz, fid_buttons);
|
|
|
|
env->SetByteArrayRegion(buttons_array, 0, NUM_BUTTONS, buttons);
|
2003-02-12 12:12:01 -05:00
|
|
|
warpPointer();
|
2002-11-29 06:51:10 -05:00
|
|
|
}
|
2003-10-11 12:29:40 -04:00
|
|
|
|
|
|
|
JNIEXPORT jobject JNICALL Java_org_lwjgl_input_Mouse_nEnableBuffer(JNIEnv *env, jclass clazz) {
|
|
|
|
jobject newBuffer = env->NewDirectByteBuffer(getOutputList(&event_queue), getEventBufferSize(&event_queue));
|
|
|
|
buffer_enabled = true;
|
|
|
|
return newBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nRead(JNIEnv *env, jclass clazz) {
|
|
|
|
return copyEvents(&event_queue, 2);
|
|
|
|
}
|