# [Programming Project] Renderer unspecific GUI Library



## razaron (Jul 1, 2013)

_Disclaimer: This thread is mostly for keeping me motivated since I'm a lazy something or other. So feel free to be annoying._


I code in Java using OpenGL and hate Java Swing with all my heart. I usually make crappy ad hoc UIs for every thing I code (not that I code much), so I decided to make my own GUI library. 
Since I'm a noob it'd make a good learning experience, what with never having coded a library before. I'm making it renderer unspecific for the same reason.

Although I'm coding it in Java, I'm going to try to not use any Java packages (the import thingies). This way it'll pretty much be OO psuedo-code in Java form, easily convertible into whichever OO language I decide to learn next. Also, it'd increase the cool factor, which is good for motivation.
Renderer unspecific basically means that the library won't handle any of the drawing. You'll have to make your own renderer using whatever graphics library you prefer (in my case, that would be OpenGL).



Spoiler: The rough gist of how I want it to work



-A script generates a UI via the library.
-UI takes in KB/M data from whatever program (now known as Jimmy) is using the library.
-UI updates element positions (x,y coordinates), states and orders (what goes on top of what) based on KB/M input.
-UI sends element positions, orders and states/events to Jimmy.
-Jimmy renders a GUI using received UI element positions and orders.
-Jimmy performs functions and updates its variables using received UI element states/events.





Spoiler: Desired features



-Have everything about the GUI (including what each element does when triggered) be determined via a script. 
-Layers (e.g. inventory screen) that are resizeable, repositionable and min/maximizable during runtime.
-Buttons, text-boxes, drop-down lists, sliders and scrollbars.
-Elements hold very abstracted state/event data (e.g. a double between 0 and 1 for sliders).





Spoiler: What I have so far



-Buttons and layers have click detection.
-Layers are reordered when clicked on.
-Layers are repositioned when you click and drag them.
-Horizontal and vertical scroll bars for layers.
-Layers can be resized.





Spoiler: Checklist






Spoiler



I'm not very good at explaining things so I hope what I've said so far makes sense. If not, just ask.

I̶'̶l̶l̶ ̶u̶p̶l̶o̶a̶d̶ ̶t̶h̶e̶ ̶s̶o̶u̶r̶c̶e̶ ̶a̶f̶t̶e̶r̶ ̶I̶'̶v̶e̶ ̶c̶o̶d̶e̶d̶ ̶a̶ ̶b̶i̶t̶ ̶m̶o̶r̶e̶ ̶a̶n̶d̶ ̶a̶d̶d̶e̶d̶ ̶c̶o̶m̶m̶e̶n̶t̶s̶.̶.̶.̶ Also, scripting support will be the last thing I do, so the source won't be for a library, it'll be for a program with all the classes intended for the library plus a Core class (main) to simulate/act as an abstraction of Jimmy and his renderer.

Compiled runnable version,
http://www.mediafire.com/download/0tl8k4819xkr3i0/GuiDemo.rar
It works like a standard UI. Drag the scroll bar to scroll, click a button to click a button, drag the bottom right corner to resize and drag anywhere else to drag the layer.


Source,
http://pastebin.com/u/razaron
It's under "GUI Library/". Requires LWJGL.


This is all part of a larger goal, the first step of which is to be able to quickly and easily make UIs. By around October I hope to have learned basic AI, coded a fairly versatile cellular automaton library, coded an impulse based physics library and gotten my head around scripting (so I don't have to hard-code everything). I've already learned A*, know how I'm going to do the cellular automaton library and coded a verlet based physics engine beforehand. The only thing I know jack squat about is scripting.


----------



## RCoon (Jul 1, 2013)

1st - Please dont code in Java, please let it die along with flash
2nd - use the time saved to order and wait for pizza
3rd - enjoy

Thank me later.


----------



## Frick (Jul 1, 2013)

Meh, Java isn't so bad.


----------



## FordGT90Concept (Jul 2, 2013)

Microsoft's implementation is brilliant:
http://msdn.microsoft.com/en-us/library/system.windows.forms.aspx

If you're talking GPU accelerated forms, Windows Presentation Foundation is also brilliant, but difficult to master:
http://msdn.microsoft.com/en-us/library/system.windows.aspx

Java completely lacks brilliance.




Frick said:


> Meh, Java isn't so bad.


Java's Swing isn't bad, it's terrible, horrible, and hellish.


----------



## Aquinus (Jul 2, 2013)

FordGT90Concept said:


> Java completely lacks brilliance.



No, but languages that are built on top of it can be brilliant. The JVM is not slow and it runs on just about any platform. There are benefits to using Java for more reasons than how you program it.

Clojure is a good example of brilliance, and it's on top of Java.

So as a general question, what do you not like about Swing? Don't get me wrong, I don't like it either, but what about it in particular do you dislike? You might be able to change what you want without re-inventing the wheel.


----------



## FordGT90Concept (Jul 2, 2013)

The way it handles events (needlessly breaks them into separate functions) and especially the lack of a ShowDialog() method which passes the GUI thread to another form and sends it back on closure.  I had to expose variables that shouldn't have been exposed and other really stupid tactics to get around it.

Lets not forget it looks like shit, has no WYSIWYG editor, and is overall clunky.


----------



## Castiel (Jul 3, 2013)

RCoon said:


> 1st - Please dont code in Java, please let it die along with flash
> 2nd - use the time saved to order and wait for pizza
> 3rd - enjoy
> 
> Thank me later.



Hoping for Java to die is like Hell freezing over, it ain't gonna happen.


----------



## hellrazor (Jul 3, 2013)

Castiel said:


> Hoping for Java to die is like Hell freezing over, it ain't gonna happen.



But could you imagine how much happier programmers would be when nobody forces them to learn and/or use it?


----------



## Aquinus (Jul 4, 2013)

hellrazor said:


> But could you imagine how much happier programmers would be when nobody forces them to learn and/or use it?



It really depends on what you consider bad. Do you consider Java as a programming language bad or do you consider the JVM bad? Personally, I've been enjoying Clojure, which is a functional language and a dialect of Lisp and it was written on top of Java and the JVM. Now I can write Clojure code (which I think looks pretty elegant as a language,) and I still have the benefits that Java provides while writing a minimal of Java code.


----------



## FordGT90Concept (Jul 4, 2013)

I'd rather Microsoft open up .NET and people create languages/compilers for .NET instead of JVM.


----------



## BiggieShady (Jul 8, 2013)

FordGT90Concept said:


> I'd rather Microsoft open up .NET and people create languages/compilers for .NET instead of JVM.



Mono is open. Unity game engine has Mono embedded and uses #C (.NET 2.0 subset) as scripting language. It works really well.


----------



## FordGT90Concept (Jul 8, 2013)

Mono doesn't have WPF.  C# is not a new language to the .NET framework.  It is using the same compilers already included with .NET.  I was talking about new languages compiled for .NET like Haskell, Java, or whatever.  That way you could use .NET instead of JVM.


----------



## razaron (Jul 10, 2013)

Rewrote how shapes are handled and added scroll bar functionality. 
PS. All buttons are always visible for convenient bug finding.



FordGT90Concept said:


> Microsoft's implementation is brilliant:
> http://msdn.microsoft.com/en-us/library/system.windows.forms.aspx
> 
> If you're talking GPU accelerated forms, Windows Presentation Foundation is also brilliant, but difficult to master:
> http://msdn.microsoft.com/en-us/library/system.windows.aspx


I prefer to make my own libraries. It's more entertaining that way. Since I don't program for any serious reasons, that's the only thing that matters.


EDIT: Added a crappy tech demo to the OP.


----------



## razaron (Jul 11, 2013)

Added resize functionality and cleaned up the maths in the Layer class. The only thing left for the Layer class is minimizing/maximizing and closing.


----------



## Zygmunt (Jul 19, 2013)

*Java Is a broad language.*

My dear Java is totally object oriented and broad language. You can do many things which you can't do in other language. You can use Net beans to code java project or GUI forum design, It would help you and make Java easy for you.


----------



## RCoon (Jul 19, 2013)

Zygmunt said:


> My dear Java is totally object oriented and broad language. You can do many things which you can't do in other language. You can use Net beans to code java project or GUI forum design, It would help you and make Java easy for you.



Only spammers use the phrase "my dear"

I'm watching you.


----------



## Zygmunt (Jul 19, 2013)

Don't Worry, I am not Spammer.


----------



## FordGT90Concept (Jul 19, 2013)

Java is not "totally object oriented," only partially.  All primitives are not objects in Java (e.g. int, char, float, etc.).  C#.NET and VB.NET are "totally object oriented."  Everything is derived from the base class System.Object.


----------

