Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Questions about GUI design

This thread is locked; no one can reply to it. rss feed Print
Questions about GUI design
jmasterx
Member #11,410
October 2009

I think unique ptr would just let you keep your widgets stack allocated, whereas I think shared_ptr would be useful for listeners and other weak reference usages.

axilmar
Member #1,204
April 2001

There are many cases that you need a shared pointer to a widget. For example, a container widget contains a list of widget pointers, but your container subclass contains pointers to specific widgets that are also on the parent's widget list.

Thomas Fjellstrom
Member #476
June 2000
avatar

axilmar said:

widget messages. No widget messages please, this is 2014 and c++ has virtual methods for this reason.

::) That is entirely just a style preference. I'd prefer having a low level widget message, which then is used to implement a higher level system like listeners or sigslots. Rather than a crap load of virtual method calls.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

axilmar
Member #1,204
April 2001

Rather than a crap load of virtual method calls.

A crap load of virtual method calls is a code smell. You can design GUIs without such a code smell.

Thomas Fjellstrom
Member #476
June 2000
avatar

Usually that's done by limiting functionality.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

axilmar
Member #1,204
April 2001

Usually that's done by limiting functionality.

I don't think so, but perhaps there is a case I have not thought about. Do you have an example? (aside from win32 which imposes Objective-C style OOP onto C objects).

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

I don't have time to reply fully, but I will say a lot of the things on your list are on my todo like namespaces, and no I won't abandon widget messages, that is the basic form of communication among the gui. I don't need a thousand different onMySpecificCallbackForThisFunction methods and two it centralizes input to a single source which is cleaner code. Your widgets input functions will usually not be more than a couple pages of code for simple widgets anyway.

::) That is entirely just a style preference. I'd prefer having a low level widget message, which then is used to implement a higher level system like listeners or sigslots. Rather than a crap load of virtual method calls.

Yes I agree.

axilmar said:

there is no reason to put yet another multimedia layer on top of Allegro, especially if the new layer matches 99% that of Allegro. If a platform does not support Allegro, porting Allegro to it would suffice. The GUI must be built on top of Allegro. For example, your event id list matches 99% that of Allegro. That's not enough abstraction to justify yet another layer on top of Allegro. Your event source organization matches that of Allegro exactly. Again, not enough justified abstraction.

Yes you do need an abstraction layer so your widgets can use a virtual graphics engine. The whole reason I designed it this way was so you could use multiple different backends, even simultaneously in the same program. The reason it matches Allegro so closely is merely for convenience porting code to Eagle from Allegro 5. I assure you it will be quite different for different engines I will have to map their events to my own and so on.

I will respond fully later but I have class now.
:-/

axilmar
Member #1,204
April 2001

and no I won't abandon widget messages, that is the basic form of communication among the gui. I don't need a thousand different onMySpecificCallbackForThisFunction methods

If you design your gui properly, you will never ever reach a state where you need a thousand different onMySpecificCallbackForThisFunction methods.

Quote:

two it centralizes input to a single source which is cleaner code

All you need is a dispatch-allegro-event method on your widgets. You certainly don't need messages.

Quote:

Yes you do need an abstraction layer so your widgets can use a virtual graphics engine.

Allegro is the abstraction layer.

Quote:

The whole reason I designed it this way was so you could use multiple different backends

You don't need that, since Allegro provides the abstraction.

Quote:

even simultaneously in the same program

Not needed.

Quote:

The reason it matches Allegro so closely is merely for convenience porting code to Eagle from Allegro 5. I assure you it will be quite different for different engines I will have to map their events to my own and so on.

If you define different event ids for other engines, then your abstraction has failed.

If you map the events of other systems to your events that look like Allegro events, then Allegro does exactly that. There is no need for code duplication.

Anyway, there is no need for this to go on. You clearly do not wish to make an effort to understand anything beyond your own design decisions, and I am sure you will respond to this in the way you did before, i.e. not understanding what I am saying, so simply forget it. It's just a waste of time.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

If you can't even get past the fact that I want my gui library not to be dependent on allegro, then I don't know how we'll ever get anywhere. :P

Edit-
I forgot to say the widget library is in an earlier version of my eagle library, that works with allegro 4. Ie. I still need to port them to the new system.
svn checkout "svn://svn.code.sf.net/p/eaglegui/code/trunk eaglegui-code"

axilmar
Member #1,204
April 2001

If you can't even get past the fact that I want my gui library not to be dependent on allegro, then I don't know how we'll ever get anywhere

I understand that, although there is no reason to do so.

Do you understand that if you adopt the Allegro 5 semantics then your effort is redundant and you might just use Allegro 5 as the backend?

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

axilmar
Member #1,204
April 2001

I also wanted an SDL backend, as well as possible SFML, and maybe even Cairo. That way people can use their favorite graphics library right alongside eagle with no problems.

And the event ids for SDL would be these?

#SelectExpand
1enum EAGLE_EVENT_TYPE { 2EAGLE_EVENT_NONE = 0, 3EAGLE_EVENT_JOYSTICK_AXIS = 1, 4EAGLE_EVENT_JOYSTICK_BUTTON_DOWN = 2, 5EAGLE_EVENT_JOYSTICK_BUTTON_UP = 3, 6EAGLE_EVENT_JOYSTICK_CONFIGURATION = 4, 7EAGLE_EVENT_KEY_DOWN = 10, 8EAGLE_EVENT_KEY_CHAR = 11, 9EAGLE_EVENT_KEY_UP = 12, 10EAGLE_EVENT_MOUSE_AXES = 20, 11EAGLE_EVENT_MOUSE_BUTTON_DOWN = 21, 12EAGLE_EVENT_MOUSE_BUTTON_UP = 22, 13EAGLE_EVENT_MOUSE_ENTER_DISPLAY = 23, 14EAGLE_EVENT_MOUSE_LEAVE_DISPLAY = 24, 15EAGLE_EVENT_MOUSE_WARPED = 25, 16EAGLE_EVENT_TIMER = 30, 17EAGLE_EVENT_DISPLAY_EXPOSE = 40, 18EAGLE_EVENT_DISPLAY_RESIZE = 41, 19EAGLE_EVENT_DISPLAY_CLOSE = 42, 20EAGLE_EVENT_DISPLAY_LOST = 43, 21EAGLE_EVENT_DISPLAY_FOUND = 44, 22EAGLE_EVENT_DISPLAY_SWITCH_IN = 45, 23EAGLE_EVENT_DISPLAY_SWITCH_OUT = 46, 24EAGLE_EVENT_DISPLAY_ORIENTATION = 47, 25EAGLE_EVENT_DISPLAY_HALT_DRAWING = 48, 26EAGLE_EVENT_DISPLAY_RESUME_DRAWING = 49, 27EAGLE_EVENT_TOUCH_BEGIN = 50, 28EAGLE_EVENT_TOUCH_END = 51, 29EAGLE_EVENT_TOUCH_MOVE = 52, 30EAGLE_EVENT_TOUCH_CANCEL = 53, 31EAGLE_EVENT_WIDGET = 60, 32EAGLE_EVENT_USER_START = 1024 33};

jmasterx
Member #11,410
October 2009

Nevermind, I see the problem.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

axilmar said:

And the event ids for SDL would be these?

No, there would most likely be an EAGLE_EVENT_TYPE GetEagleEventType(SDL_EVENT_ID); function.

axilmar said:

If you define different event ids for other engines, then your abstraction has failed.

No, not at all. I can either support the union of the two libraries event abilities or the superset and have some functionality disabled for specific backends.

axilmar said:

Yes you do need an abstraction layer so your widgets can use a virtual graphics engine.

Allegro is the abstraction layer.

Not if I want to drive the system with SDL for example, then Eagle would still be the abstraction layer. If I want to say win->DrawLine(x,y,x2,y2,EagleColor(0,0,255,125), 2.0); in my widget then the graphics context can either call allegro's draw line routine, or sdl's draw routine. It is no longer bound to allegro. This is the whole reason I abandoned my earlier gui engine was because it relied on Allegro 4. Now I could support Allegro 4 or 5 if I wanted to. The flexibility is what I wanted.

axilmar said:

Anyway, there is no need for this to go on. You clearly do not wish to make an effort to understand anything beyond your own design decisions, and I am sure you will respond to this in the way you did before, i.e. not understanding what I am saying, so simply forget it. It's just a waste of time.

Well clearly all you can do is criticize and if you don't want to hear my responses then why do you ask me questions? Merely to state your opinion and ignore mine? Were there even any features of my gui that you thought were worth keeping?

jmasterx
Member #11,410
October 2009

I have to go with Edgar on this. I could never bring myself to writing an API just for Allegro.

bamccaig
Member #7,536
July 2006
avatar

Abstraction makes sense. The similarities to Allegro 5 cause minor alarm. It suggests that you lack a higher-level knowledge of the problem domain and are copying what you know. Which sort of defeats the purpose of abstraction. If you just duplicate Allegro then you'll at best accomplish nothing new and at worst duplicate the Allegro developers' mistakes. Additionally, you may find that it's difficult to implement backends for other libraries if they aren't structured similarly to Allegro. It could be that the other backend implementations are such major hacks that performance is atrocious and the backend is unusable. Which sort of defeats the purpose. I haven't looked into your implementation so I'm just taking axilmar's comments at face value, but I would suggest you aim to strive away from Allegro. Perhaps learn SDL or whatever. Familiarizing yourself with other planned backends will help you to recognize the common elements between them. You basically have to prioritize. You either want to make something backend independent or you want to build an Allegro GUI. You can always add the abstractions after. It is software for a reason.

The arguing is more or less what I expected. It is probably a necessary stage to work through. Like I said, everybody thinks that their shit doesn't stink, but everybody thinks that everybody else' shit does. If you want to collaborate then you have to make sacrifices. Accept that what you build together won't be perfect, and figure out what will be good enough. Try to learn from one another instead of trying to prove superiority over one another. Protip: You're all wrong. Now you get to explore how each of you is wrong, but at the same time, sometimes, each of you is a little bit right.

Allegro is far from perfect. A GUI doesn't have to be perfect to be useful. Make yourself willing to fail and you just might make something useful. You'll surely learn along the way, which will increase your chances of getting it perfect next time.

Pho75_
Member #12,377
November 2010

It's getting a little hot in here!
Perhaps now is not the best time to bring up the topic
of writing the GUI library in C so that it's usable
by everybody (C,C++,OBJ-C) ?
::)

bamccaig
Member #7,536
July 2006
avatar

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Writing a gui library using C comes at a price though - you sacrifice inheritance and function overloading for the sake of binary compatibility. Which is fine if you like that sort of thing. Matthew wrote a C gui library with A5 as I believe I stated above. You might want to see how far he got.

axilmar
Member #1,204
April 2001

bamccaig said:

Abstraction makes sense. The similarities to Allegro 5 cause minor alarm. It suggests that you lack a higher-level knowledge of the problem domain and are copying what you know. Which sort of defeats the purpose of abstraction. If you just duplicate Allegro then you'll at best accomplish nothing new and at worst duplicate the Allegro developers' mistakes. Additionally, you may find that it's difficult to implement backends for other libraries if they aren't structured similarly to Allegro. It could be that the other backend implementations are such major hacks that performance is atrocious and the backend is unusable. Which sort of defeats the purpose. I haven't looked into your implementation so I'm just taking axilmar's comments at face value, but I would suggest you aim to strive away from Allegro. Perhaps learn SDL or whatever. Familiarizing yourself with other planned backends will help you to recognize the common elements between them. You basically have to prioritize. You either want to make something backend independent or you want to build an Allegro GUI. You can always add the abstractions after. It is software for a reason.

Exactly. Well said.

I am fully in favor of abstraction. Who wouldn't be? It would be nice to have a new gui library that can be used with any graphical subsystem.

But that is a tremendously difficult task. wxWidgets and Qt probably have millions of man days of work behind them, and they do not take into account games. We should not fool ourselves that we are capable of going that route.

Pho75_ said:

of writing the GUI library in C so that it's usable by everybody

I have no problem with that, although C++ makes things so much easier and safer to the point that it makes using Objective-C redundant.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

bamccaig said:

Abstraction makes sense. The similarities to Allegro 5 cause minor alarm. It suggests that you lack a higher-level knowledge of the problem domain and are copying what you know. Which sort of defeats the purpose of abstraction. If you just duplicate Allegro then you'll at best accomplish nothing new and at worst duplicate the Allegro developers' mistakes. Additionally, you may find that it's difficult to implement backends for other libraries if they aren't structured similarly to Allegro. It could be that the other backend implementations are such major hacks that performance is atrocious and the backend is unusable. Which sort of defeats the purpose. I haven't looked into your implementation so I'm just taking axilmar's comments at face value, but I would suggest you aim to strive away from Allegro. Perhaps learn SDL or whatever. Familiarizing yourself with other planned backends will help you to recognize the common elements between them. You basically have to prioritize. You either want to make something backend independent or you want to build an Allegro GUI. You can always add the abstractions after. It is software for a reason.

The similarities to A5 are simply due to the fact that the first backend I planned to implement was A5. When/if I get time to write other backends, I am sure the overall implementation will change to accomodate the new backend.

I don't care to be accused of copying libraries. If you had looked at the library you'll see the only thing that was really copied was the event definitions. As I don't know SDL or any other graphics library well at this point, there was no purpose making a whole bunch of different events. The events are the same as Allegro for ease in porting A5 programs to my library, nothing more. That will probably change once I write another backend, and I will translate allegro's events into my own then when necessary.

Quote:

You either want to make something backend independent or you want to build an Allegro GUI. You can always add the abstractions after. It is software for a reason.

I want backend independence. That's why I designed my library the way that I did, with system and graphics drivers for abstraction layers. That frees my gui from dependence on any one backend. Adding the abstractions later would be like redesigning the engine of a car after it is already built. Pointless for the current car, but useful for the future. If I was to add the abstraction in later it would most likely be some sort of giant hack, because it wasn't designed into the library from the beginning.

axilmar said:

I am fully in favor of abstraction. Who wouldn't be? It would be nice to have a new gui library that can be used with any graphical subsystem.

That's not what you said before. You said it was pointless to build a gui for allegro that wasn't built on allegro directly. And so you know, my library can be used with any graphical subsystem as long as you write a driver for it, and the backend is capable of implementing the core functionality. SDL should work with my library just fine, as its abilities are quite comparable to Allegro.

bamccaig
Member #7,536
July 2006
avatar

People swap car engines all the time... It's easier with software because the frame is far more malleable. In any case, you admit that your abstraction layer will probably need to change to accommodate other backends so that pretty much makes the current abstraction layer not really an abstraction at all, but a redundant layer. :-*

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

bamccaig said:

In any case, you admit that your abstraction layer will probably need to change to accommodate other backends so that pretty much makes the current abstraction layer not really an abstraction at all, but a redundant layer.

WTF are you talking about? It's not redundant at all, if you had even bothered to look at my library. My library makes setup super easy, and provides everything you need to jump right into your program. An event handler is provided, and it is hooked up to all the inputs available in the system. There is a full input library which makes reading input super easy and convenient. There are debugging and logging abilities, as well as automated memory management. There's far much more to my library than the event definitions.

So what if the abstraction layer needs to change some? It works fine as it is, and I doubt it would have to change much to accomodate SDL. Perhaps more for SFML/Cairo, but I'm not as concerned with those. SDL and Allegro are the main graphics engines out there that I wanted to be able to support, as they seem to have the most longevity.

Without the abstraction, it would just be another library dependent on allegro. And as soon as Allegro 5 is irrelevant, so would be my library. That's what happened with Allegro 4, and is the whole reason I added the abstraction layer. If I had another driver written, I could run two programs simultaneously with different drivers, and compare the performance of the two. Try that without an abstraction layer. :-*

jmasterx
Member #11,410
October 2009

Don't worry Edgar, a backend abstraction layer is a good thing :)

GWEN and guichan both used the abstraction layer method. It's just a generally good idea not to tie down to a specific backend. It would be like if Allegro tied itself down to OpenGL or Windows.

bamccaig
Member #7,536
July 2006
avatar

When/if I get time to write other backends, I am sure the overall implementation will change to accomodate the new backend.

This is all I was referring to. If the abstraction layer needs to change in order to accommodate the other backends then it's not really an abstraction layer. It's a redundant layer (i.e., it doesn't serve a purpose yet, and will need to change before it could). Not trying to insult your library which I know nothing about (I admire your aspirations and efforts). :-*



Go to: