package org.mote.wiimote.whiteboard.mouse;

import java.awt.Point;

import org.mote.wiimote.whiteboard.mouse.rightclick.RightClickStrategy;
import org.mote.wiimote.whiteboard.preferences.WWPreferences;

public class DefaultControlStrategy implements CursorControlStrategy {
	
	private static final WWPreferences prefs = WWPreferences.getPreferences();
	private RightClickStrategy rcs = WWPreferences.RIGHT_CLICK_STRATEGY;
	
	public void process(Point p) {
		
		rcs.process(p);
		
		if (p != null) {
			Mouse.move(p);
			if (prefs.isLeftClick() && !(prefs.isRightClick() && rcs.trigger())) {
				if (WWPreferences.MOUSE_PRESS_DELAY > 0 && !Mouse.LEFT_BUTTON.isPressed()) {
					Mouse.sleep(WWPreferences.MOUSE_PRESS_DELAY);
				}
				Mouse.LEFT_BUTTON.setPressed(true);
			}
		} else {
			Mouse.LEFT_BUTTON.setPressed(false);
		}
		
	}

}
