Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (636)
Games in Android Showcase (178)
games submitted by our members
Games in WIP (687)
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  
  distinguishing userinterface events from others  (Read 1446 times)
0 Members and 1 Guest are viewing this topic.
Offline Jens

Senior Devvie

Java for games!

« Posted 2003-12-01 17:45:42 »

Currently I see no way of distinguishing userinterface events from events on the canvas. In most apps the UIEventAdapter will catch all events. It uses them for dragging UIWindows or hands it over to the appropriate JComponent. On its way the event itself is not changed, besides its coordinates are translated relative to the UIWindow it occured in. Usually an app has a second event handler (for instance for handling picking). However this event handler has no chance to detect if the event occured in a UIWindow or not (correct me, if I'm wrong here).

Simple example: User clicks somewhere on a UIWindow without triggering a specific action. Usually this should not lead to any reaction within the scene, because the user often doesn't even know what object he clicked on within the scene.

I have added a simple one-line-patch (see below) to the UIWindowManager, which sets the source of a mouse event to the UIWindow the event occured in. This allows the app to find out if the event occured in a UIWindow and which UIWindow it occured in. This works for me.

How is this supposed to work in Xith3D? In case you had the problem: How did you handle it?

// if we get here, but we have not consumed the mouse message then
// determine if the mouse event should be sent
if (!eventConsumed) {
  if (w != null) {
    Object o = (Object) w.getOverlay();

    if (o instanceof UIWindow) {
      me.translatePoint(-(int) w.getRectangle().getX(),
                              -(int) w.getRectangle().getY());
      ((UIWindow) o).dispatchEvent(me);

(code always looks ugly in this forum)

Xith3D Getting Started Guide (PDF,HTML,Source)
Offline Jens

Senior Devvie

Java for games!

« Reply #1 - Posted 2003-12-05 15:41:51 »

The translation of the coordinates causes additional problems. Let's say you get an event and determine it comes from a certain UIWindow (which is possible with the small patch above). You have two scenarios:

The first is you decide you don't need the event (in most cases this will be true) and drop it. The second is that you decide you need the event and want to something with it. An example of the second case is dragging around an image (which is a UIWindow with only one transparent JPanel) with the mouse. The image is near to the cursor. It's possible to move the cursor onto the image. Now you get wrong coordinates for the mouse event, because they are now relative to upper left corner of the image. The consequence is that the image appears somewhere in the upper left corner of the screen, because I think the cursor is there.

To make a long story short I think the userinterface event handling can be improved. In my opinion you should be able to 1.) find out if the event occured on a UIWindow or not and 2.) be able to get the canvas coordinates of the mouse event. The question is how this can be added to Xith3D. It's not trivial.

If my explanation is not clear, please ask.

If you know a better way to drag around an image in the scene, please tell me. Dragging around a UIWindow is a performance killer. :-)

Xith3D Getting Started Guide (PDF,HTML,Source)
Offline Jens

Senior Devvie

Java for games!

« Reply #2 - Posted 2003-12-18 11:33:59 »


Is it possible that at least the coordinates of the mouse events are not modified or the event is changed, so that it can be distinguished from non-userinterface events?

Xith3D Getting Started Guide (PDF,HTML,Source)
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline DavidYazel

Junior Devvie

Java games rock!

« Reply #3 - Posted 2003-12-18 12:56:39 »

I will take care of this, but it will require that the event be copied in order to protect the event from corruption.

David Yazel
Xith3D Project Founder

It may look complicated, but in the end it is just a bunch of triangles
Offline Jens

Senior Devvie

Java for games!

« Reply #4 - Posted 2003-12-18 17:01:09 »

That sounds like a good idea. One copy is used to handle all the userinterface internal stuff and the app will only "see" the copy with the unmodified x-y-position.

Currently I use the simple patch above to set the source of the mouse event to the UIWindow the event occured on, but I don't know if this is generally a good idea. I see two ways for an app to find out which UIWindow an event occured on:
1. Use a helper method which takes a point as an argument and returns a UIOverlayInterface.
2. Modify the event itself.
Sometimes you will want that to use an event for picking behind a UIWindow (for instance if you have a simple translucent overlay, which just displays text somewhere on the screen), but in most cases you will want to ignore events which occured on a UIWindow.

Xith3D Getting Started Guide (PDF,HTML,Source)
Offline Jens

Senior Devvie

Java for games!

« Reply #5 - Posted 2004-01-02 16:53:26 »


Xith3D Getting Started Guide (PDF,HTML,Source)
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Dwinin (72 views)
2015-11-07 13:29:08

Rems19 (81 views)
2015-10-31 01:36:56

Rems19 (78 views)
2015-10-31 01:32:37

williamwoles (107 views)
2015-10-23 10:42:59

williamwoles (93 views)
2015-10-23 10:42:45

Jervac_ (110 views)
2015-10-18 23:29:12

DarkCart (135 views)
2015-10-16 00:58:11

KaiHH (117 views)
2015-10-11 14:10:14

KaiHH (157 views)
2015-10-11 13:26:18

BurntPizza (172 views)
2015-10-08 03:11:46
Rendering resources
by Roquen
2015-11-13 14:37:59

Rendering resources
by Roquen
2015-11-13 14:36:58

Math: Resources
by Roquen
2015-10-22 07:46:10

Networking Resources
by Roquen
2015-10-16 07:12:30

Rendering resources
by Roquen
2015-10-15 07:40:48

Math: Inequality properties
by Roquen
2015-10-01 13:30:46

Math: Inequality properties
by Roquen
2015-09-30 16:06:05

HotSpot Options
by Roquen
2015-08-29 11:33:11 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!