GUI elements definition

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

GUI elements definition

Post by greenya »

Hello.

I read that Irrlicht 1.4 will got only bug-fixes since rev 1000.
But I would like to propose to change all definitions of all GUI elements where we setting up coordinates. For example, take any function:

Code: Select all

irrGUI->addButton(core::rect<s32>(50, 40, 150, 60), ...
This defines x1, y1, x2, y2 and I think this is not convenient. It should be defined as x, y, width, length:

Code: Select all

irrGUI->addButton(core::rect<s32>(50, 40, 100, 20), ...
I think this would be better implementation.
What do you think?

Thank You.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Six of one, half a dozen of the other really...

(If you don't understand that as you're not English that means both are effectively the same)

They both get the same job done just in slightly different ways so there's no real reason for changing it that i can see. Possibly the code within addButton actually performs better if given x1,x2 etc. and requires less calculations but if it was given an x value and a width value it might have to calculate stuff which would take more time (a very small increase in time i'm sure, but still...)
Image Image Image
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

I agree, it's a PITA if you do it that way.

Here's how I did it for the GUI for my game engine:

Code: Select all

core::recti buttonRect(0,0, width, height);
...
gui->addButton(buttonRect+core::position2di(x0,y0)...);
gui->addButton(buttonRect+core::position2di(x1,y1)...);
gui->addButton(buttonRect+core::position2di(x2,y2)...);
This defines the button rect once and makes it easy to position your buttons where you want them. Also, changing the button size is trivial as it's defined just once.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

This has been covered before. You could do a search. Regardless, changing the api would be bad as it would require existing apps to modify their code to work correctly again. Granted there have been many source incompatible changes going into Irrlicht lately, those kinds of changes should be avoided except for major releases.

A simple solution that you can implement yourself is to use the rect constructor that takes a position and a dimension, or simpler yet make a function that takes the position and dimension like you want and returns an appropriately constructed rect.

Code: Select all

template <class T>
inline core::rect<T> rectangle(T x, T y, T w, T h)
{
    return core::rect<T>(x, y, x + w, y + h);
}

irrGUI->addButton(rectangle<s32>(50, 40, 100, 20), ...);
Travis
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

I saying that it is not convenient because i writing something like:

Code: Select all

// Controls Window {
	irrControlsWindow = irrGUI->addWindow(core::rect<s32>(95, 0, 525, 80), false, L"Controls", 0, 1002);
	irrControlsWindow->getCloseButton()->setVisible(false);

	irrGUI->addButton(core::rect<s32>(10, 30, 90, 48), irrControlsWindow, 1653, L"Open World...");
	irrGUI->addButton(core::rect<s32>(10, 52, 90, 70), irrControlsWindow, 1654, L"Open PF...");

	irrGUI->addButton(core::rect<s32>(100, 30, 180, 48), irrControlsWindow, 1655, L"Statistics");
	irrGUI->addButton(core::rect<s32>(100, 52, 180, 70), irrControlsWindow, 1656, L"Geometry");

	irrGUI->addCheckBox(false, core::rect<s32>(200, 30, 300, 48), irrControlsWindow, 1601, L"Show PF Areas");
	irrGUI->addCheckBox(false, core::rect<s32>(200, 52, 300, 70), irrControlsWindow, 1602, L"Show PF Conns");

	irrGUI->addButton(core::rect<s32>(320, 30, 420, 48), irrControlsWindow, 1651, L"Find Single Path");
	irrGUI->addButton(core::rect<s32>(320, 52, 420, 70), irrControlsWindow, 1652, L"Crash Tests");
	// }
So you see some gui design, and then, when i decide to insert some button or move all elements -- i need to recalculate all 4 values of every core::rect.

BUT, if we would use x,y,width,height -- then i would need to update only x and y. That is much easier i think.
CuteAlien
Admin
Posts: 9736
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

After doing a few hundred elements (per xml) I can only agree that it would be better with x,y,width,height. I wish I'd had changed that at least in the serialization before starting with all the dialogs. And it's not the same, it starts to matter as soon as you start to move elements around. Changing only 2 values for that instead of 4 might not seem much work if you do that for a handful elements. But if you have to do it for days ... guess it.

Changing the API for that is certainly bad. But before I start the next project I will change it at least in the serializiation - even if that means it's different in xml and in code.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

I also agree it will be much more easier using width and height but changing the API only cause of this isn't necessary IMO, maybe if you'll find any other reasons, maybe then I'll change my mind. :wink:
And JP, this extra calculation IMO is enough small to forget about it..
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Post by christianclavet »

We could keep the current method and add another one like:

Code: Select all

irrGUI->addButtonRelative(core::rect<s32>(50, 40, 150, 60), ...
or simply:

Code: Select all

irrGUI->addButtonR(core::rect<s32>(50, 40, 150, 60), ...
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

christian, that would double the number of addSomething functions in the gui environment, so it sucks as a solution
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

Yeah, I have to say your best bet would just be to implement a wrapper for 'rect' with a define for a relative rect. Of couse you should just do this per project. I do agree that the API should change, but I can stick with doing it in my own projects for now, so eh.

Code: Select all

#define RECT(x,y,w,h) rect<s32>(x,y,x+w,x+h)
Simple and effective.
TheQuestion = 2B || !2B
Post Reply