Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (480)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (546)
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 1151 times)
0 Members and 1 Guest are viewing this topic.
Offline Jens

Senior Member




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?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
// 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());
      me.setSource((UIWindow)o);
      ((UIWindow) o).dispatchEvent(me);
    }
  }
}

(code always looks ugly in this forum)

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

Senior Member




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 Member




Java for games!


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

*bump*

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 Member




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
http://xith3d.dev.java.net

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

Senior Member




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 Member




Java for games!


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

*bump*

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

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

atombrot (20 views)
2014-08-19 09:29:53

Tekkerue (21 views)
2014-08-16 06:45:27

Tekkerue (21 views)
2014-08-16 06:22:17

Tekkerue (12 views)
2014-08-16 06:20:21

Tekkerue (19 views)
2014-08-16 06:12:11

Rayexar (55 views)
2014-08-11 02:49:23

BurntPizza (37 views)
2014-08-09 21:09:32

BurntPizza (27 views)
2014-08-08 02:01:56

Norakomi (35 views)
2014-08-06 19:49:38

BurntPizza (64 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org 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‑gaming.org
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!