Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (616)
Games in Android Showcase (173)
games submitted by our members
Games in WIP (659)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Robot.mouseMove and Frame Decoration  (Read 1351 times)
0 Members and 1 Guest are viewing this topic.
Offline Jargon

Junior Newbie

« Posted 2007-01-11 21:14:50 »

Ok, I have a JOGL scene (and no, the problem isn't about JOGL).

I was implementing a mouse look system where one holds the right mouse button and drags to move the direction of the camera around. I wanted to keep the mouse cursor anchored in one position while this is done so the camera doesn't stop rotating when the mouse cursor hits the edge of the screen. Therefore, at the end of the drag calculations, I use Robot.mouseMove to move the mouse cursor back to where it originally was.

The problem is that I can't get the exact coordinates because I can't tell work out the offset generated by the frame's decoration (title bar, minimise, maximise and close buttons). This is throwing my camera rotation way off and driving me nuts. I really don't want to hard code it in as this will just cause problems in future and for other people/systems. How does one find out this offset. Turning off the decoration is out of the question.

If I am going in the totally wrong direction and theres a better way of sensing the mouse drag, don't hesitate to correct me Smiley

Thank in advance,
Offline ryanm

Senior Devvie

Projects: 1
Exp: 15 years

Used to be bleb

« Reply #1 - Posted 2007-01-11 21:32:59 »

JFrame, and indeed any component that extends java.awt.Container, has a getInsets() method that may be what you need.

It sounds like your MouseMotionListener is added to the top-level Frame or JFrame, if you add it instead to the GLCanvas you don't need to worry about any inset shenanigans.
Offline Jargon

Junior Newbie

« Reply #2 - Posted 2007-01-11 21:55:41 »

The MouseMotionListener is attached to the GLCanvas, the problem lies in the Robot class itself, its coordinates work from the top left of the actual JFrame, not the GLCanvas, which gives me the offset problem.

Anyway, despite that, the getInsets() method is EXACTLY what I was looking for Cheesy Thank you very much!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ryanm

Senior Devvie

Projects: 1
Exp: 15 years

Used to be bleb

« Reply #3 - Posted 2007-01-11 23:19:39 »

Is your window always maximised or in the top-left corner? Robot.mouseMove() coordinates are relative to the screen and not any particular component.

I've looked back to how I did this and found the perfectly suited java.awt.Component.getLocationOnScreen() method.
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Coldstream24 (16 views)
2015-09-03 00:41:28

Andrew_3ds (26 views)
2015-09-01 19:08:10

afikri (17 views)
2015-08-31 09:30:22

afikri (25 views)
2015-08-31 09:30:07

afikri (13 views)
2015-08-31 09:27:24

afikri (16 views)
2015-08-31 09:26:40

Roquen (30 views)
2015-08-29 11:30:54

GamerC4 (36 views)
2015-08-22 20:38:50

GamerC4 (33 views)
2015-08-22 20:37:18

GamerC4 (40 views)
2015-08-22 20:37:01
HotSpot Options
by Roquen
2015-08-29 11:33:11

Rendering resources
by Roquen
2015-08-17 12:42:29

Rendering resources
by Roquen
2015-08-17 09:36:56

Rendering resources
by Roquen
2015-08-13 07:40:51

Networking Resources
by Roquen
2015-08-13 07:40:43

List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!