    001package net.minecraft.util;
    002
    003import cpw.mods.fml.relauncher.Side;
    004import cpw.mods.fml.relauncher.SideOnly;
    005import java.awt.Component;
    006import net.minecraft.client.settings.GameSettings;
    007import org.lwjgl.input.Mouse;
    008
    009@SideOnly(Side.CLIENT)
    010public class MouseHelper
    011{
    012    private final Component windowComponent;
    013    private final GameSettings field_85184_d;
    014
    015    /** Mouse delta X this frame */
    016    public int deltaX;
    017
    018    /** Mouse delta Y this frame */
    019    public int deltaY;
    020
    021    public MouseHelper(Component par1Component, GameSettings par2GameSettings)
    022    {
    023        this.windowComponent = par1Component;
    024        this.field_85184_d = par2GameSettings;
    025    }
    026
    027    /**
    028     * Grabs the mouse cursor it doesn't move and isn't seen.
    029     */
    030    public void grabMouseCursor()
    031    {
    032        Mouse.setGrabbed(true);
    033        this.deltaX = 0;
    034        this.deltaY = 0;
    035    }
    036
    037    /**
    038     * Ungrabs the mouse cursor so it can be moved and set it to the center of the screen
    039     */
    040    public void ungrabMouseCursor()
    041    {
    042        int i = this.windowComponent.getWidth();
    043        int j = this.windowComponent.getHeight();
    044
    045        if (this.windowComponent.getParent() != null)
    046        {
    047            i = this.windowComponent.getParent().getWidth();
    048            j = this.windowComponent.getParent().getHeight();
    049        }
    050
    051        Mouse.setCursorPosition(i / 2, j / 2);
    052        Mouse.setGrabbed(false);
    053    }
    054
    055    public void mouseXYChange()
    056    {
    057        this.deltaX = Mouse.getDX();
    058        this.deltaY = Mouse.getDY();
    059    }
    060}