Help with GUI Ideas...

Blitz3D Forums/Blitz3D Programming/Help with GUI Ideas...

mk2y10(Posted 2012) [#1]
I have been working on finding the easiest, lightest way to use a GUI system, and have discovered (like most people already know) that you need a smart drawing system to save processing time. Here is my idea:

The Overlay System:
This is an Image that has a layer of images drawn on it. Each image has a specific color (an int that is the handle of the bank.)
Why do this? When a full screen render is called, it will draw ONLY the pixels that are visible and won't waste time drawing pixels that are not. Not only will this system improve both individual and full rendering, but it will also allow gadgets that are custom shaped (like oval, triangle, and all other shapes you can think of!)
Another advantage is the ordering used. Want to bring a gadget to the top? It is just a DrawImage() away!

As far as that I am drawing a blank :(

Does anyone else have Ideas of a method to use? I am open to types, banks, and dimensions for information storage, but I do need help setting up a way for parent/child control...

And then the crazy idea of making a virtual processor that is given access to images and buffer controls... :( I am thinking too far in to it...

Anyway, you guys have any ideas?


Yasha(Posted 2012) [#2]
You'd get a much, much bigger speed increase from scrapping 2D drawing altogether and using 2D-in-3D, even for 2D-oriented projects. Pixel crunching 2D is really slow even when run through a third buffer like that, unfortunately (and more importantly, it can't be combined with 3D without slowing down both systems dramatically). Whereas a 2D-in-3D system just lets the graphics card do its thing and handle this stuff automatically.

There are a few decent GUI libraries already made, so I wouldn't recommend designing a new one unless you have some radical new idea for doing it more efficiently.

My final observation is that without native support for function pointers, it is literally impossible to design a GUI system that's actually easy to use or efficient, so you kinda have to make do with second place in B3D. However, you can get a lot of the same effect using integer function IDs and dispatch functions - but you have to be willing to write said dispatch functions yourself (I have a very simple GUI framework based around this... it kinda works, can share it if you like).


mk2y10(Posted 2012) [#3]
Well I use to use window's API in my program for GUI functions (like buttons and stuff,) but this GUI is not really for public use (although they can use it if they want to.) All gadgets are being redesigned and the number of commands are to be kept at a minimum. It is going for many programs, so I can't make any shortcuts. Also I like to write my own code for practice (I program for the learning experience, problem solving, and experimenting with new ideas, not really for profit (that is for when I turn 25 or so :)

How would I go about using 3D for such things (like alpha or so?) Do I just use Graphics3D and call 2D commands only (Could a 3D graphics speed them up?) or do I have to use a different projection mode on a camera, and then set the texture of a one-sided square face to draw a gadget (or something similar?)

Thank you for responding btw, I do appreciate it!


Yasha(Posted 2012) [#4]
do I have to use a different projection mode on a camera, and then set the texture of a one-sided square face to draw a gadget (or something similar?)


Something like that, more or less.

You can get an excellent 2D-in-3D library that does just that here: http://www.blitzbasic.com/Community/posts.php?topic=75362

It now has an all-new improved sequel, which actually includes a GUI: http://www.blitzbasic.com/Community/posts.php?topic=92270

This system has some quirks to do with surface ordering, but nothing that will get in the way of good design. If you want some practice and to write your own code, you could build on the old one (which has all the math in place, but is smaller feature-wise), or perhaps update it to use types instead of banks for a minor speed boost or something.


mk2y10(Posted 2012) [#5]
Do you think types are faster than banks? I never thought about which was was faster (puts down on list to see.) Thanks, I will check it out! It would be awesome to get my idea's down and working, GUI is the most annoying part of making a program for me, so anything to make it easier will make me a happy person ^,^


Yasha(Posted 2012) [#6]
Types are significantly faster than banks or arrays for all operations (one pointer dereference vs. function call + bounds check + two derefs; created from a pool memory rather than arbitrary size alloc).

Incindentally, there's full documentation for that Draw3D lib here: http://www.blitzforum.de/help/?cat=8

(Google Translate works well if you don't read German.)


mk2y10(Posted 2012) [#7]
Cool, I will start using that instead! Milliseconds count to me :)

Hey, I have another question, kinda unrelated, but..

How to I check to see if a program had lost Direct Draw and reconnect it if it did? (I have a desktop Gadget I mad that losses Direct Draw when returning from hibernation) Here is info on it:

http://www.blitzbasic.com/Community/posts.php?topic=96996


Yasha(Posted 2012) [#8]
GraphicsLost sounds like it might be what you want?

(It's not in the online docs, which are old - you may need to install the updated documentation patch.)


mk2y10(Posted 2012) [#9]
That is what I need ^.^ Thanks Yasha! Haha


Rroff(Posted 2012) [#10]
Also you don't need to update/refresh/redraw the UI every frame - with some intelligent handling of input commands (keyboard/mouse) you can update the UI at say a fixed 30fps into an image buffer and render that image buffer every frame.

Last edited 2012


jfk EO-11110(Posted 2012) [#11]
Wot? Types faster than arrays?? THouth the opposite was true? Anyhow, there's a certain dedicated usage for banks, arrays and types. Types are especially useful when you don't know how many data sets you'll need. At the other hand, accessing a type by a simple index, such as the chessboard index XY might be significantly slower with types, compared to arrays, at least it was when I checked it last time. Using types is also more kind of "let Blitz do the maths behind the curtain", using things like "For Each (no matter how many there are)" - something you may like or not.


Yasha(Posted 2012) [#12]
Accessing a field within a single object is measurably faster for typed-objects than elements of array objects, or arbitrary peeking for bank objects.

I wasn't talking about the prepackaged lists for each type. If you need O(1) access to a specific object by index though, there's nothing stopping you putting said objects in an appropriately-typed array.

You're right in that finding an object by For/Each is really quite an inefficient way to do it (although Object/Handle is fast enough for realtime use... don't know how that one works internally, I think it might use a map). This isn't really comparable to arrays or banks though since... no built-in list of either of those is provided at all (in fact, no mechanism for indirectly referencing them is provided at all).

(The builtin lists have literally nothing to do with types or objects, and are a prime example of the confusing design flaws I was talking about in the Education thread. It doesn't make sense to associate lists with types! This is probably why they were removed for BlitzMax.)


jfk EO-11110(Posted 2012) [#13]
Well, you've got a point there. cya.