Best strategy to move the cam when touching the edge of the screen

Hey everyone,
I’m having a hard time figuring out, what’s the best strategy to solve my problem. I’m trying to move my camera like in strategy games where you just have to touch the edge of the screen with your cursor and it’ll move it in that direction.
I could always ask the position of the coursor, of course, but that doesn’t sound very pretty to me. Is there any better way to handle this?

AFAIK theres no Event (TouchingEdgeOfScreenEvent, possibly in Nifty maybe? i doubt it :P), so you will have to do this yourself. Luckily for you, 99% of screens are rectangular, so the math isn’t that hard to figure out. There is potentially a few methods you could use but the easiest, is to just get the screen size, and check how close the mouse cursor is to each edge, if its within a few pixel tolerance, then its touching. I.e for the left and right, you would do:

[java]
int screenWidth = settings.GetWidth ();
if (inputManager.getCursorPosition ().getX () < 4) {
// then its touching the left side of the screen
} else if (screenWidth - inputManager.GetCursorPosition().getX () < 4 {
// then its touching the right side of the screen
}[/java]

You could probably create 4 functions, isTouchingLeft (), right, top, bottom, or isTouching (Side side) and pass it an enum, or w.e. Many different ways to accomplish the same thing, just do the easiest and most intuitive to you.

[java]
private void updateCameraPosition(float tpf) {
if (inputManager.getCursorPosition().x settings.getWidth() - 10f) {
cam.setLocation(new Vector3f(cam.getLocation().x + tpf * cameraSpeed, cam.getLocation().y, cam.getLocation().z));
} else if (inputManager.getCursorPosition().y settings.getHeight() - 10f) {
cam.setLocation(new Vector3f(cam.getLocation().x, cam.getLocation().y, cam.getLocation().z - tpf * cameraSpeed));
}
}
[/java]

I solved it like this. Any suggestions?

EDIT: For some reason, it will only take these couple of lines. Can I now post more?
It will even cut off my if statements…