Java Code Examples for org.lwjgl.input.Mouse#poll()

The following examples show how to use org.lwjgl.input.Mouse#poll() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CPSKey.java    From Hyperium with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void renderKey(int x, int y) {
    int yOffset = this.yOffset;

    if (!mod.getSettings().isShowingMouseButtons()) yOffset -= 24;
    if (!mod.getSettings().isShowingSpacebar()) yOffset -= 18;
    if (!mod.getSettings().isShowingSneak()) yOffset -= 18;
    if (!mod.getSettings().isShowingWASD()) yOffset -= 48;

    Mouse.poll();

    int textColor = getColor();

    if (mod.getSettings().isKeyBackgroundEnabled()) {
        Gui.drawRect(x + xOffset, y + yOffset, x + xOffset + 70, y + yOffset + 16,
            new Color(mod.getSettings().getKeyBackgroundRed(), mod.getSettings().getKeyBackgroundGreen(), mod.getSettings().getKeyBackgroundBlue(),
                mod.getSettings().getKeyBackgroundOpacity()).getRGB());
    }

    String name = (mod.getSettings().isLeftClick() ? getLeftCPS() : getRightCPS()) + " CPS";
    if (mod.getSettings().isChroma()) {
        drawChromaString(name, ((x + (xOffset + 70) / 2) - mc.fontRendererObj.getStringWidth(name) / 2), y + (yOffset + 4), 1.0F);
    } else {
        drawCenteredString(name, x + (xOffset + 70) / 2, y + (yOffset + 4), textColor);
    }
}
 
Example 2
Source File: Game.java    From FEMultiPlayer-V2 with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets the input.
 *
 * @return the input
 */
public static void getInput() {
	Keyboard.poll();
	keys.clear();
	while(Keyboard.next()) {
		KeyboardEvent ke = new KeyboardEvent(Keyboard.getEventKey(), Keyboard.getEventCharacter(),
        Keyboard.isRepeatEvent(), Keyboard.getEventKeyState(), KeyboardEvent.generateModifiers());
		keys.add(ke);
	}
	Mouse.poll();
	mouseEvents.clear();
	while(Mouse.next()) {
		MouseEvent me = new MouseEvent(
				Mouse.getEventX(),
				Mouse.getEventY(),
				Mouse.getEventDWheel(),
				Mouse.getEventButton(),
				Mouse.getEventButtonState());
		mouseEvents.add(me);
	}
}
 
Example 3
Source File: Game.java    From FEMultiplayer with GNU General Public License v3.0 6 votes vote down vote up
public static void getInput() {
	Keyboard.poll();
	keys.clear();
	while(Keyboard.next()) {
		KeyboardEvent ke = new KeyboardEvent(
				Keyboard.getEventKey(),
				Keyboard.getEventCharacter(),
				Keyboard.isRepeatEvent(),
				Keyboard.getEventKeyState());
		keys.add(ke);
	}
	Mouse.poll();
	mouseEvents.clear();
	while(Mouse.next()) {
		MouseEvent me = new MouseEvent(
				Mouse.getEventX(),
				Mouse.getEventY(),
				Mouse.getEventDWheel(),
				Mouse.getEventButton(),
				Mouse.getEventButtonState());
		mouseEvents.add(me);
	}
}
 
Example 4
Source File: CPSKey.java    From Hyperium with GNU Lesser General Public License v3.0 5 votes vote down vote up
@InvokeEvent
public void onRender(RenderEvent event) {
    Mouse.poll();

    boolean downNow = Mouse.isButtonDown(mod.getRenderer().getMouseButtons()[0].getButton());
    if (downNow != leftWasDown && downNow) leftClicks.add(System.currentTimeMillis());

    leftWasDown = downNow;
    downNow = Mouse.isButtonDown(mod.getRenderer().getMouseButtons()[1].getButton());
    if (downNow != rightWasDown && downNow) rightClicks.add(System.currentTimeMillis());

    rightWasDown = downNow;
}
 
Example 5
Source File: PointerInput.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
public final static void poll(GUIRoot gui_root) {
	Deterministic deterministic = LocalEventQueue.getQueue().getDeterministic();
	if (deterministic.log(!Mouse.isCreated()))
		return;
	Mouse.poll();
	int accum_x = last_x;
	int accum_y = last_y;
	int accum_dz = 0;
	while (deterministic.log(Mouse.next())) {
		accum_x = deterministic.log(Mouse.getEventX());
		accum_y = deterministic.log(Mouse.getEventY());
		accum_dz += deterministic.log(Mouse.getEventDWheel());
		int button = deterministic.log(Mouse.getEventButton());
		if (button >= 0 && button < buttons.length) {
			updateMouse(gui_root, accum_x, accum_y, accum_dz);
			accum_dz = 0;
			buttons[button] = deterministic.log(Mouse.getEventButtonState());
			if (buttons[button]) {
				if (drag_button == -1) {
					drag_button = button;
				}
				LocalInput.getLocalInput().mousePressed(gui_root, button);
			} else {
				drag_button = -1;
				LocalInput.getLocalInput().mouseReleased(gui_root, button);
			}
		}
	}
	updateMouse(gui_root, accum_x, accum_y, accum_dz);
}
 
Example 6
Source File: MouseButton.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void renderKey(int x, int y) {
    int yOffset = this.yOffset;

    Mouse.poll();
    boolean pressed = Mouse.isButtonDown(button);

    if (!mod.getSettings().isShowingWASD()) yOffset -= 48;

    String name = BUTTONS[button];
    if (pressed != wasPressed) {
        wasPressed = pressed;
        lastPress = System.currentTimeMillis();
    }

    int textColor = getColor();
    int pressedColor = getPressedColor();

    int color;
    double textBrightness;

    if (pressed) {
        color = Math.min(255, (int) ((mod.getSettings().getFadeTime() * 5) * (System.currentTimeMillis() - lastPress)));
        textBrightness = Math.max(0.0D, 1.0D - (double) (System.currentTimeMillis() - lastPress) / (mod.getSettings().getFadeTime() * 2));
    } else {
        color = Math.max(0, 255 - (int) ((mod.getSettings().getFadeTime() * 5) * (System.currentTimeMillis() - lastPress)));
        textBrightness = Math.min(1.0D, (double) (System.currentTimeMillis() - lastPress) / (mod.getSettings().getFadeTime() * 2));
    }

    if (mod.getSettings().isKeyBackgroundEnabled()) {
        if (mod.getSettings().getKeyBackgroundRed() == 0 && mod.getSettings().getKeyBackgroundGreen() == 0 && mod.getSettings().getKeyBackgroundBlue() == 0) {
            Gui.drawRect(x + xOffset, y + yOffset, x + xOffset + 34, y + yOffset + 22,
                new Color(mod.getSettings().getKeyBackgroundRed(), mod.getSettings().getKeyBackgroundGreen(), mod.getSettings().getKeyBackgroundBlue(),
                    mod.getSettings().getKeyBackgroundOpacity()).getRGB() + (color << 16) + (color << 8) + color);
        } else {
            Gui.drawRect(x + xOffset, y + yOffset, x + xOffset + 34, y + yOffset + 22,
                new Color(mod.getSettings().getKeyBackgroundRed(), mod.getSettings().getKeyBackgroundGreen(), mod.getSettings().getKeyBackgroundBlue(),
                    mod.getSettings().getKeyBackgroundOpacity()).getRGB());
        }
    }

    int red = textColor >> 16 & 255;
    int green = textColor >> 8 & 255;
    int blue = textColor & 255;

    int colorN = new Color(0, 0, 0).getRGB() + ((int) ((double) red * textBrightness) << 16) + ((int) ((double) green * textBrightness) << 8) + (int) ((double) blue * textBrightness);

    if (mod.getSettings().isShowingCPSOnButtons() && mod.getSettings().isShowingCPS()) {
        final int round = Math.round(y / 0.5f + yOffset / 0.5f + 28.0f);
        if (mod.getSettings().isChroma()) {
            drawChromaString(name, x + xOffset + 8, y + yOffset + 4, 1.0F);
            GL11.glPushMatrix();
            GL11.glScalef(0.5f, 0.5f, 0.0f);
            drawChromaString((name.equals(BUTTONS[0]) ? mod.getRenderer().getCPSKeys()[0].getLeftCPS() :
                mod.getRenderer().getCPSKeys()[0].getRightCPS()) + " CPS", Math.round(x / 0.5f + xOffset / 0.5f + 10 / 0.5f), round, .5);
        } else {
            mc.fontRendererObj.drawString(name, x + xOffset + 8, y + yOffset + 4, pressed ? pressedColor : colorN);
            GL11.glPushMatrix();
            GL11.glScalef(0.5f, 0.5f, 0.0f);
            mc.fontRendererObj.drawString((name.equals(MouseButton.BUTTONS[0]) ? mod.getRenderer().getCPSKeys()[0].getLeftCPS() :
                mod.getRenderer().getCPSKeys()[0].getRightCPS()) + " CPS", Math.round(x / 0.5f + xOffset / 0.5f + 20.0f), round, pressed ? pressedColor : colorN);
        }
        GL11.glPopMatrix();
    } else {
        if (mod.getSettings().isChroma()) {
            drawChromaString(name, x + xOffset + 8, y + yOffset + 8, 1.0F);
        } else {
            mc.fontRendererObj.drawString(name, x + xOffset + 8, y + yOffset + 8, pressed ? pressedColor : colorN);
        }
    }
}