All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.daxie.joglf.gl.input.mouse.Mouse Maven / Gradle / Ivy

There is a newer version: 11.7.0
Show newest version
package com.daxie.joglf.gl.input.mouse;

import java.awt.AWTException;
import java.awt.Robot;

import com.daxie.joglf.gl.input.CountsAndFlags;
import com.jogamp.newt.event.MouseEvent;
import com.jogamp.newt.event.MouseListener;

/**
 * Mouse
* This class fails to move the mouse to the correct location on some environments.
* There is a JDK bug report that may be related to this problem.
* @see AWT Robot mouseMove fails on Windows 10 1709 with HiDPI * * @author Daba * */ public class Mouse implements MouseListener{ private final int KEY_NUM=9; private CountsAndFlags mouse_buttons; private int window_x,window_y; private int x,y; private int diff_x,diff_y; private float[] rotations; private int fix_pos_x; private int fix_pos_y; private Robot robot;//is used to fix the mouse pointer. private boolean fix_mouse_pointer_flag; public Mouse() { mouse_buttons=new CountsAndFlags(KEY_NUM); window_x=0; window_y=0; x=0; y=0; diff_x=0; diff_y=0; rotations=new float[]{0.0f,0.0f,0.0f}; fix_pos_x=0; fix_pos_y=0; try { robot=new Robot(); } catch(AWTException e) { e.printStackTrace(); } fix_mouse_pointer_flag=false; } public void SetFixMousePointerFlag(boolean fix_mouse_pointer_flag) { this.fix_mouse_pointer_flag=fix_mouse_pointer_flag; } public void SetWindowPosition(int window_x,int window_y) { this.window_x=window_x; this.window_y=window_y; } public void SetFixMousePointerPosition(int x,int y) { fix_pos_x=x; fix_pos_y=y; } public void Update() { mouse_buttons.UpdateCounts(); if(fix_mouse_pointer_flag==true) { diff_x=x-fix_pos_x; diff_y=y-fix_pos_y; } else { diff_x=0; diff_y=0; } if(fix_mouse_pointer_flag==true) { robot.mouseMove(window_x+fix_pos_x,window_y+fix_pos_y); } } @Override public void mouseClicked(MouseEvent e) { } @Override public void mouseDragged(MouseEvent e) { this.mouseMoved(e); } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void mouseMoved(MouseEvent e) { x=e.getX(); y=e.getY(); } @Override public void mousePressed(MouseEvent e) { switch(e.getButton()) { case MouseEvent.BUTTON1: mouse_buttons.SetPressingFlag(0, true); break; case MouseEvent.BUTTON2: mouse_buttons.SetPressingFlag(1, true); break; case MouseEvent.BUTTON3: mouse_buttons.SetPressingFlag(2, true); break; case MouseEvent.BUTTON4: mouse_buttons.SetPressingFlag(3, true); break; case MouseEvent.BUTTON5: mouse_buttons.SetPressingFlag(4, true); break; case MouseEvent.BUTTON6: mouse_buttons.SetPressingFlag(5, true); break; case MouseEvent.BUTTON7: mouse_buttons.SetPressingFlag(6, true); break; case MouseEvent.BUTTON8: mouse_buttons.SetPressingFlag(7, true); break; case MouseEvent.BUTTON9: mouse_buttons.SetPressingFlag(8, true); break; default: break; } } @Override public void mouseReleased(MouseEvent e) { switch(e.getButton()) { case MouseEvent.BUTTON1: mouse_buttons.SetPressingFlag(0, false); break; case MouseEvent.BUTTON2: mouse_buttons.SetPressingFlag(1, false); break; case MouseEvent.BUTTON3: mouse_buttons.SetPressingFlag(2, false); break; case MouseEvent.BUTTON4: mouse_buttons.SetPressingFlag(3, false); break; case MouseEvent.BUTTON5: mouse_buttons.SetPressingFlag(4, false); break; case MouseEvent.BUTTON6: mouse_buttons.SetPressingFlag(5, false); break; case MouseEvent.BUTTON7: mouse_buttons.SetPressingFlag(6, false); break; case MouseEvent.BUTTON8: mouse_buttons.SetPressingFlag(7, false); break; case MouseEvent.BUTTON9: mouse_buttons.SetPressingFlag(8, false); break; default: break; } } @Override public void mouseWheelMoved(MouseEvent e) { rotations=e.getRotation(); } public int GetX() { return x; } public int GetY() { return y; } public int GetDiffX() { return diff_x; } public int GetDiffY() { return diff_y; } public float GetHorizontalRotation() { float rotation=rotations[0]; rotations[0]=0.0f; return rotation; } public float GetVerticalRotation() { float rotation=rotations[1]; rotations[1]=0.0f; return rotation; } public float GetZAxisRotation() { float rotation=rotations[2]; rotations[2]=0.0f; return rotation; } public int GetButtonPressingCount(MouseEnum key) { int count; switch(key) { case MOUSE_LEFT: count=mouse_buttons.GetPressingCount(0); break; case MOUSE_MIDDLE: count=mouse_buttons.GetPressingCount(1); break; case MOUSE_RIGHT: count=mouse_buttons.GetPressingCount(2); break; case MOUSE_BUTTON_4: count=mouse_buttons.GetPressingCount(3); break; case MOUSE_BUTTON_5: count=mouse_buttons.GetPressingCount(4); break; case MOUSE_BUTTON_6: count=mouse_buttons.GetPressingCount(5); break; case MOUSE_BUTTON_7: count=mouse_buttons.GetPressingCount(6); break; case MOUSE_BUTTON_8: count=mouse_buttons.GetPressingCount(7); break; case MOUSE_BUTTON_9: count=mouse_buttons.GetPressingCount(8); break; default: count=0; break; } return count; } public int GetButtonReleasingCount(MouseEnum key) { int count; switch(key) { case MOUSE_LEFT: count=mouse_buttons.GetReleasingCount(0); break; case MOUSE_MIDDLE: count=mouse_buttons.GetReleasingCount(1); break; case MOUSE_RIGHT: count=mouse_buttons.GetReleasingCount(2); break; case MOUSE_BUTTON_4: count=mouse_buttons.GetReleasingCount(3); break; case MOUSE_BUTTON_5: count=mouse_buttons.GetReleasingCount(4); break; case MOUSE_BUTTON_6: count=mouse_buttons.GetReleasingCount(5); break; case MOUSE_BUTTON_7: count=mouse_buttons.GetReleasingCount(6); break; case MOUSE_BUTTON_8: count=mouse_buttons.GetReleasingCount(7); break; case MOUSE_BUTTON_9: count=mouse_buttons.GetReleasingCount(8); break; default: count=0; break; } return count; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy