Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (537)
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  
  Gui framework design  (Read 2791 times)
0 Members and 1 Guest are viewing this topic.
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Posted 2002-12-03 16:27:56 »

As I embark on my latest project again I'm trying another different set of core data structures, which in turn requires a custom level editor. Which I don't mind, and is usually quite a bit of fun to put together, but this time I'm avoiding Awt/Swing altogether and creating the whole interface in openGL (but 2d only, hence the topic living in this forum).

My main questions for building a Gui framework would be:
  • How to handle mouse clicks
  • How to deal with components expanding past their parent bounds (combo box drop down lists etc.)
  • Dealing with dragging
  • Mouse focus (active or require click?)


I'm still designing on the fly (a Bad Thing most of the time, so most of my current code will probably go out the window) but if the whole project stays on triack then i'll probably release the gui stuff as a separate library for anyone who wants to use/abuse it..

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline markuskidd

Junior Member


Medals: 1



« Reply #1 - Posted 2002-12-03 17:53:52 »

I don't know if you'd consider this, but we're probably going to need someone to help with a GUI for the Java Open-Source RTS @ http://www.stardart.net/jos-rts/ . On the flipside, you could probably get some help (I know I'm interested in developing GUI components) this way as well.

One big problem (IMO) right now is that a lot of the developers there are afriad of working with OpenGL, and seeing as you are the only person whose really written a working game with the LWJGL, your input would really just be appreciated in general  Wink. Right now we're debating whether or not to tough it out with the Sun fullscreen stuff or go with an OGL wrapper..
Offline princec

JGO Kernel


Medals: 343
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #2 - Posted 2002-12-03 21:09:03 »

I've got one all done Smiley Ask Brian what it's like. I'm going to demo it up here soon.

Cas Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Matzon

JGO Knight


Medals: 19
Projects: 1


I'm gonna wring your pants!


« Reply #3 - Posted 2002-12-04 05:23:50 »

Grin

Yeah the demo is really going to be nice - will finally show of that lwjgl *is* a good approach for java games - ofcourse there is a steeper learning curve with OGL as opposed to AWT - but as Cas will demo, it is very doable. And his library is accessible too:
http://sourceforge.net/projects/spgl

Offline Golthar

Junior Member




;)


« Reply #4 - Posted 2002-12-04 10:23:47 »

Quote

My main questions for building a Gui framework would be:
How to handle mouse clicks.

Depends, if you are using some lower level library, use that to implement a Event system like in AWT/Swing

How to deal with components expanding past their parent bounds (combo box drop down lists etc.)

Normaly you arent allowed to draw outside those bounds.
We solved the problem by making a popup panel which is drawn last over the rest.
You might have an easier deal with this because you implement from scratch, we implemented on top of AWT


come visit us: http://www.otf1337.com
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #5 - Posted 2002-12-04 11:07:56 »

Cas: I can't wait to see that game, should give me a target to aim at Wink

I've been keeping half an eye on the RTS game, but at the moment it seems a tad haphazard, but such is to be expected. I'd highly recommend usig LWJGL, and really much of the game code remains the same (I'd be willing to be that a Java2D version of CounterSheep or Gems could be done in a weekend). Give me a week of working on it and I should have a basic set of functionality up (got a draggable window working last night) and you can see if its the kind of thing could be of use...

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline Themroc

Junior Member





« Reply #6 - Posted 2002-12-04 16:21:58 »

http://developer.java.sun.com/developer/Books/Java3D/

There is a book about user interfaces in 3D. Don't know if it is any good, I didn't read it. Two chapters are for free download, so you can check it out.
Offline Harley Rana

Junior Member




Java games rock!


« Reply #7 - Posted 2002-12-10 00:48:20 »

Hey i have actually been working on a gui system for the java open source game and my own projects.   I have used some of the swing design but trying to replace some objects with int properties.

There are two main classes, GComponent which is like the base component with all the normal methods and empty event methods,update(time), and abstract render().

The other class is GComponents which is the bridge between java's gui to mine.  It contains event processing, update(time),render(g), etc.

I think the most important thing is getting events to the right component quickly.  The hardest part has been getting mouse drag events to the scroll bar quickly.
My last design used a kind of quadtree, which pre-computed the screen region of a component, so you just needed a array lookup.  Just uses more memory.
At the moment i wanted to get a game gui, so memory was more important.  

The parent-child relationship is also important as it decides how you render and process events down the heirachy.  As the last version contained a 1 component array, when a child was added to a parent, the childs index was added to the parents child list ( the list is a Trove IntArrayList ).

The JFrame that contains my system, calls GComponent.processXXXEvent(x,x,x), which then finds the matching component, calling the appropriate component.xxxEvent();  The big performace sucker is findComponent().  

It would be cool to share some code, to get some different ideas.  I have just put up a page with a few versions of the system with some screen shots and code.  http://www.froggy.com.au/harleyrana/gui.html

Harley.
Offline Captain-Goatse

Junior Member




I suck at teh 2D. XBOX IS BIG LOL!111


« Reply #8 - Posted 2002-12-10 06:29:06 »

Damn that looks nice Harley!

Did you use java2D only without any GL?

May I ask how fast is it?
Offline Golthar

Junior Member




;)


« Reply #9 - Posted 2002-12-10 06:57:11 »

Indeed very nice looking Smiley

I had the added challange of making it work in all the 1.1 VM's.
What you mention about the find component is true, it takes some time to find the right component to send events to.
I create a function in my Component class that would return the top most child that is under an absolute dimension.

It might not be lightning fast, but it got the job done

come visit us: http://www.otf1337.com
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #10 - Posted 2002-12-11 21:22:19 »

Heres a shot of my current progress if anyone wants a quick look:

Unfortunatly progress has come to something of a standstill while i figure out a good way to sort out texturing my maps. And after that I'll take a sabbatical from code and computers in all forms over xmas, so likely it'll be a while before it looks any different..

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline Harley Rana

Junior Member




Java games rock!


« Reply #11 - Posted 2002-12-13 00:32:58 »

Hey that looks cool!  So its a 2D gui being rendered over a 3D scene.  I feel so inaduquate, my level editor is plane old 2D!

I was just thinking of a new method for sorting the components making it quiker to find.
Instead of finding which area on a grid the component was in,  i found which horizontal line it was on.  
For each line i know the index of the components on it.  

This method uses less memory than the grid because the grid needs to be fairly fine, and is a fixed size.  Where as the each line can be spaced further apart, and uses only as much as needed.

Tell me what you think.  You can see its not optimized, im still working on the idea.

[this code has been tested and edited, and now works]
Also how do i get my formating to stay?
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
/************************* SORT  ******************************/

    public static void sortComponents ()
    {
      if(!isDepthSorted) depthSort ();
      int y=0;
      int maxLines = height/yPad;
      compRegions = new int[maxLines+1][0];
      int[] compLine = new int[200]; // max 200 components per line ( way more than needed).
     int compOnLine = 0;
      lineLoop: for(int i=0; i<=maxLines; i++)
      {          
          compLoop: for(int j=0; j<componentCount; j++)
          {
            GComponent comp = components[j];
            for(int k=0; k<width; k++)
            {
                if(comp.contains (k,y) ||
                comp.contains (k,y-(yPad/2)) ||
                comp.contains (k,y+(yPad/2)) )
                {                        
                  compLine[compOnLine++] = j;                  
                  continue compLoop;                  
                }
            }
          }
                   
          compRegions[i] = new int[compOnLine];  // compRegions[i] will be 0 if the compOnLine = 0.
         for(int k=0; k<compOnLine; k++)
          {
            compRegions[i][k] = compLine[k];            
          }
          y += yPad;
          compOnLine = 0;
      }

      // you could sort the componets by thier getX(), on each line.
     // not really needed when the number of components on the line is low, as it is now.      
     
    }


/************************* FIND  ******************************/

    private static GComponent findComponent (int x,int y)
    {
      if(lastContainer!=null && lastContainer.contains (x,y))
      {
         
          int[] kids = lastContainer.getChildren ();
          for(int i=kids.length-1; i>=0; i--)
          {
            if(components[kids[i]].contains (x,y))return components[kids[i]];
          }
      }
      int[] comps = compRegions[(y/yPad)];
      if(comps.length<1)return null;
      for(int i=comps.length-1; i>=0; i--)
      {
          GComponent comp = components[comps[i]];          
          if(x >= comp.getX () && x<comp.getX ()+comp.getWidth ())
          {
            return comp;
          }
      }
      return null;
    }
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.

CogWheelz (16 views)
2014-08-01 22:53:16

CogWheelz (15 views)
2014-08-01 22:51:43

CopyableCougar4 (18 views)
2014-08-01 19:37:19

CogWheelz (19 views)
2014-07-30 21:08:39

Riven (27 views)
2014-07-29 18:09:19

Riven (16 views)
2014-07-29 18:08:52

Dwinin (14 views)
2014-07-29 10:59:34

E.R. Fleming (42 views)
2014-07-29 03:07:13

E.R. Fleming (13 views)
2014-07-29 03:06:25

pw (44 views)
2014-07-24 01:59:36
Resources for WIP games
by CogWheelz
2014-08-01 18:20:17

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

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

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

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

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22
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!