Menu bar

Open-source port of PoP that runs natively on Windows, Linux, etc.

Moderator: English Moderator Team

Post Reply
Falcury
Wise Scribe
Wise Scribe
Posts: 326
Joined: June 25th, 2009, 10:01 pm

Menu bar

Post by Falcury » September 14th, 2017, 11:59 pm

I'm experimenting with adding a menu bar to the SDLPoP main window, taking inspiration from oitofelix's recent additions to MININIM, as well as Norbert's work on the settings window.

So far so good:
window menu.png
Unfortunately there is no easy way to do it in SDL. At the very least, we need separate native implementations for Windows, X11, etc...
SDL normally hides the native window handle and callback. This makes it hard (on Windows) to intercept the WM_COMMAND messages (these are sent each time a menu item is clicked, but apparently SDL does not send these messages through as events; see for instance here). The way I'm getting it to work now is by creating a native window first using CreateWindow(), and then giving that window handle to SDL using SDL_CreateWindowFrom()

User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 3139
Joined: April 9th, 2009, 10:58 pm
Contact:

Re: Settings window

Post by Norbert » September 15th, 2017, 7:51 pm

Experiments can be useful/educational/fun/etc. For anything beyond experimentation, I'd vote against separate native implementations. If SDL alone, such as with the window that I suggested and implemented, is insufficient, if more complex widgets such as menus are truly necessary, it might be time to consider adding a framework or toolkit in the mix that's cross-platform. If you had to rewrite my networking code using Winsock, then I made a mistake and should have used SDL_net or something similar. My 2¢.

salvadorc17
Calif
Calif
Posts: 521
Joined: August 27th, 2011, 2:04 am

Re: Settings window

Post by salvadorc17 » September 15th, 2017, 10:16 pm

Falcury wrote:I'm experimenting with adding a menu bar to the SDLPoP main window, taking inspiration from oitofelix's recent additions to MININIM, as well as Norbert's work on the settings window.
Windows api with sld is not best option, but could be used...

Falcury
Wise Scribe
Wise Scribe
Posts: 326
Joined: June 25th, 2009, 10:01 pm

Re: Settings window

Post by Falcury » September 15th, 2017, 11:42 pm

Hm, maybe GTK?
The Windows API basically provides menu bars for free, though. So on Windows, it wouldn't be necessary to use middleware. I appreciate the concern about native implementations, but... the differences could quite likely be abstracted away. I would expect there to be minimal code duplication in the end. (Yeah, I actually enjoy coding that kind of stuff. ;) )

I expect a menu bar system by itself will not be sufficient for things like editing numbers, like you could do with an actual settings window.
Similarly, I imagine that a settings window is more logical to use for very long lists of options (e.g. choosing which bugfixes to enable/disable, etc.)
And I agree that sticking to SDL for a settings window looks like a good strategy. (It's good that you have experience with GUIs, Norbert... I'm noticing how hard it is...)

A menu system would I think be more convenient for quick toggles, file loading, a reminder of which hotkeys to use, that sort of thing.

I've attached a test build (Windows only). Not all options are working, but it should be enough to try out for testing purposes.
The menu bar auto-hides in fullscreen mode. If you move the mouse to the top of the screen it should become visible again.
Attachments
SDLPoP menubar test.zip
(4.67 MiB) Downloaded 3 times

User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 3139
Joined: April 9th, 2009, 10:58 pm
Contact:

Re: Settings window

Post by Norbert » September 15th, 2017, 11:59 pm

Falcury wrote:I've attached a test build (Windows only).
The better you make this Windows-only thing, the more you are going in the wrong direction.

Falcury
Wise Scribe
Wise Scribe
Posts: 326
Joined: June 25th, 2009, 10:01 pm

Re: Settings window

Post by Falcury » September 16th, 2017, 9:18 am

Norbert wrote:The better you make this Windows-only thing, the more you are going in the wrong direction.
If you're concerned that I might neglect the other platforms, I assure you that I wouldn't even have started on this if I didn't see it as a step towards a good cross-platform implementation with minimal OS abstraction. If it turns out that I can't achieve that, then I'm abandoning the effort. (Maybe I wasn't clear on that...)

Otherwise, I am not really sure what you are saying.

salvadorc17
Calif
Calif
Posts: 521
Joined: August 27th, 2011, 2:04 am

Re: Settings window

Post by salvadorc17 » September 16th, 2017, 10:18 pm

Falcury wrote:
Norbert wrote:The better you make this Windows-only thing, the more you are going in the wrong direction.
If you're concerned that I might neglect the other platforms, I assure you that I wouldn't even have started on this if I didn't see it as a step towards a good cross-platform implementation with minimal OS abstraction. If it turns out that I can't achieve that, then I'm abandoning the effort. (Maybe I wasn't clear on that...)

Otherwise, I am not really sure what you are saying.
Is not that bad, windows api can still be used on others with Wine configurations..

User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 3139
Joined: April 9th, 2009, 10:58 pm
Contact:

Re: Settings window

Post by Norbert » September 16th, 2017, 11:57 pm

Falcury wrote:If you're concerned that I might neglect the other platforms, [...]
The entire approach is fundamentally flawed, because it attacks the platform-agnostic nature of the program. Let me ask you this: do you have the skills and time to not only implement native menus for all operating systems supported by SDL - that's Linux, Windows, OS X, iOS, Android, FreeBSD, Haiku - but can the project also rely on you to keep updating this code until the end of time to keep these native menus functional on all these OSes and whatever else will arrive on the scene, or do you think it might be wise to stick with SDL (and, if truly necessary, a single cross-platform framework or toolkit)? Even if you set up all the development environments required to test these native menus everywhere, do you expect other developers to do the same thing if they want to build on and improve your work? If you can get it to work everywhere except on iOS, will you tell those people 'tough luck'? If you look closely, you may even see the embrace, extend, and extinguish parallels. And if your OS doesn't get the fanciest features, just use Wine. Right, Salvador? ;)

David
The Prince of Persia
The Prince of Persia
Posts: 1496
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Settings window

Post by David » September 17th, 2017, 10:12 am

Falcury wrote:I'm experimenting with adding a menu bar to the SDLPoP main window, taking inspiration from oitofelix's recent additions to MININIM,
It looks like Allegro (which is used by MININIM) has built-in support for menus: http://liballeg.org/a5docs/trunk/native ... html#menus
That's why he could add it in a cross-platform way...

salvadorc17
Calif
Calif
Posts: 521
Joined: August 27th, 2011, 2:04 am

Re: Settings window

Post by salvadorc17 » September 24th, 2017, 10:18 pm

The windows api can not be used with wine on multiplatform??

Falcury
Wise Scribe
Wise Scribe
Posts: 326
Joined: June 25th, 2009, 10:01 pm

Re: Settings window

Post by Falcury » October 30th, 2017, 12:42 am

David wrote:
September 17th, 2017, 10:12 am
It looks like Allegro (which is used by MININIM) has built-in support for menus: http://liballeg.org/a5docs/trunk/native ... html#menus
That's why he could add it in a cross-platform way...
I have tried very hard to get SDL2 and GTK (Allegro uses GTK for its UI elements on X) to cooperate within the same X window, but unfortunately I couldn't get it to work in the end.

If I still want to proceed with experimenting with menu bars on GNU/Linux systems, I think the most logical option is to create the menu bar as an independent (floating) GTK window. That way, the SDL2 window and the GTK window would not interfere. Obviously that's not ideal, but it's better than nothing.

Either that, or I would need to write code for manually drawing the menus. The advantage of that approach would be that I could simply use the existing SDL2 drawing area, and no native routines would be necessary. It seems like it could be an interesting challenge, although it might be more effort than it is worth.
salvadorc17 wrote:
September 24th, 2017, 10:18 pm
The windows api can not be used with wine on multiplatform??
Thanks for the suggestion, but I do not think that Wine is really an ideal solution... Wine's goal is to make Windows programs run on GNU/Linux systems, but SDLPoP is already cross-platform. And it probably does not make good sense anyway to rely on Win32 routines on any other platform than Windows.

Falcury
Wise Scribe
Wise Scribe
Posts: 326
Joined: June 25th, 2009, 10:01 pm

Re: Settings window

Post by Falcury » November 14th, 2017, 7:57 pm

I experimented with rendering a menubar as an overlay, on this branch.
None of the menu items do anything, so it's not really usable. But it has been a good exercise, at least.
menubar_screenshot.png
menubar_screenshot.png (7.65 KiB) Viewed 34 times

User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 3139
Joined: April 9th, 2009, 10:58 pm
Contact:

Re: Settings window

Post by Norbert » November 14th, 2017, 8:09 pm

Falcury wrote:
November 14th, 2017, 7:57 pm
I experimented with rendering a menubar as an overlay, on this branch.
The transparency is nice.

Suggestion, maybe we should split this thread in two, one with posts about the Settings window, and one with posts about adding a menu bar.

David
The Prince of Persia
The Prince of Persia
Posts: 1496
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Settings window

Post by David » Yesterday, 1:23 pm

Norbert wrote:
November 14th, 2017, 8:09 pm
Suggestion, maybe we should split this thread in two, one with posts about the Settings window, and one with posts about adding a menu bar.
Done.

Post Reply