Mouse Grabbing

Probably a stupid question but, is it possible to use the mouse in both the grabbed and un-grabbed state in a single session?

It helps a great deal if I can use the mouse deltas to move and position stuff in my glwindow, but obviously this renders the swing gui useless. If I set a key to grab and un-grab the mouse it becomes unreadable.

Anyone know if there is a workaround for this?

Cheers.

Im not very sure what you mean, but if you want the mouse to reappear when its outside the LWJGL AWT canvas, you can do the following:


public class MouseGrabber {
  public float x, y;

  public void logic() {
    x += Mouse.getDX();
    y += Mouse.getDY();

    if (x >= -GameStats.getWidth()/2 && x <= GameStats.getWidth()/2 && y >= -GameStats.getHeight()/2 && y <=GameStats.getHeight/2) {
       Mouse.setGrabbed(true);
    } else {
      Mouse.setGrabbed(false);
    }
  }
}

That will class will grab the mouse when its inside the display, and release it when its outside. GameStates is just a class that holds the width/height of the AWTCanvas

DP

Oh Dear, just been looking at my mouse code (which was quick and dirty temp stuff I done a while ago) and there appears to be huge amounts of funkyness going on all over the place. Some bits of code are calling myMouseObject and other bits are calling the default Mouse, long story. I think that’s where the problem is.

I’ll rewrite it over the weekend and that should hopefully sort it out.

Cheers DP, and sorry for wasting your time. Feel free to issue a slap.

Na, slaps are reserved for heated arguments with my cat… :stuck_out_tongue:

Glad you solved it eventually tho…

Ok, I tidied up my mouse calls today and I’m still loosing my cursor after I setGrabbed(false).

What I’m trying to do is grab the mouse so I can use the deltas to move a little picking box around the glscene, then ungrab the mouse so I can use the normal cursor to interact with the giu (a bit hacky I know, but it saves mucking about with ray picking).

My mouse object initially sets Mouse.setGrabbed(true) and I can then later press space to setGrabbed(false), but when I do this the cursor doen’t appear on the screen.

Is there anything else I need to do to make the cursor reappear?

[edit] Meant to mention before, if I start my app with the mouse un-grabbed and then later set it to grabbed the cursor still remains on screen, is this supposed to happen?

Cheers.

As far as I can tell you simply need to set that boolean. I’ve never had any trouble getting it to turn visible when I want it to. Perhaps you are changing something else?

Not changing anything else, I’ve double checked.

[edit] ok checked it again and found out what I was doing wrong. Alls I’ll say is, thank gawd I don’t program professionally.

Think I’ll delete this thread later if its possible :smiley:

Cheers all :slight_smile:

Ha ha. I’m sure pro’s have the same stupid mistakes every once in a while. Sometimes I find the best solution is just to rewrite everything.

I’d like to think they don’t make cock ups on the scale that I’m capable of :smiley:

In my defense (well sort of) I’ve still never gotten out of the habit of writing messy code. My objects and stuff are pretty tidy but in almost everything I’ve ever wrote the main program has always been a shoddy mess with bits all other the place. I blame eclipse, it does so much for me that I’ve become more lazy than I could possibly imagine :slight_smile:

Ha, yeah, I’ll bet that can happen. Fortunately, I learned Java on BlueJ (which consequentally does nothing for you) and had a Nazi for a teacher (which is a good thing), so I had good coding practices driven into my brain. If I were you, I’d just make sure to have understandable variable names (no matter how long), proper indentation at all times, and don’t be afraid to waste space in favor of more readable code: it’s electronic space, which means you have infinite of it. :slight_smile: