Lazarus

Programming => Graphics and Multimedia => Games => Topic started by: Paul_ on June 14, 2019, 11:29:02 am

Title: Looking for lightweight GUI
Post by: Paul_ on June 14, 2019, 11:29:02 am
I can't find any usefull Pascal GUI for games:

- simple structure, expandable

- the ability to easily overwrite the rendering function (e.g. for OpenGL)

- basic components set

Title: Re: Looking for lightweight GUI
Post by: sash on June 14, 2019, 11:57:40 pm
the ability to easily overwrite the rendering function (e.g. for OpenGL)

I fear this is near to impossible (to do it in optimal way).

Most GUI systems exists in context of particular rendering engine, because it is not simply "render rectangles to somewhere".
GUI depends on underlying infrastructure of base types and conventions, input, messages, resources, font rendering and again, rendering techniques.

So you'll end with your "independent GUI library" would be either very basic or will result of duplication of said infrastructure independently existing in engine/application.

I'd rather consider a use of complete engine with GUI.
Title: Re: Looking for lightweight GUI
Post by: User137 on June 15, 2019, 12:38:33 pm
Yeah a UI library shouldn't be directly calling graphics API such as OpenGL but a more higher level implementation of it. nxPascal has some kind of UI but it is a little tricky to link your own code to button clicks and other events. Because the editor is in no way linked to the actual app that uses it source code you can't directly assign the events in it, and it has to be done by code. But there is an example in the UITester\
https://github.com/Zaflis/nxpascal/tree/master/tools
Editor is in same place, and you can check what components are currently included by checking source code:
https://github.com/Zaflis/nxpascal/blob/master/src/nxUI.pas
It goes as far as letting you drag windows with mouse, and you can completely customize them with any images you like, even partially transparent pngs and possible custom after-effects. Scaling with form size, keeping pixel perfectness with fonts and so on are taken care of. I still only considered it work-in-progress, although you can do a whole lot with it already it want to.
Title: Re: Looking for lightweight GUI
Post by: lainz on June 16, 2019, 03:38:07 am
Great games build with FPC?
Title: Re: Looking for lightweight GUI
Post by: julkas on June 16, 2019, 03:27:03 pm
Good question.
My own experience with games - DOOM  port for i3micro STB (C code  :D).
Title: Re: Looking for lightweight GUI
Post by: Ñuño_Martínez on June 18, 2019, 11:23:40 am
Great games build with FPC?
Not sure they're great, but there are a few (https://wiki.freepascal.org/Games). Also, a few of us are trying to improve and expand this section*. :)
_______________________

* Unfortunatelly for me, I have not much time so I'm working too slowly.  :(
Title: Re: Looking for lightweight GUI
Post by: Paul_ on June 19, 2019, 10:23:55 am
Yeah a UI library shouldn't be directly calling graphics API such as OpenGL but a more higher level implementation of it. nxPascal has some kind of UI but it is a little tricky to link your own code to button clicks and other events. Because the editor is in no way linked to the actual app that uses it source code you can't directly assign the events in it, and it has to be done by code.

All what I need is some good OOP structure, in case of GUI it can be bit problematic and complex. Yes, events must be hardcoded, but I suppose it's normal for games.

I have done it "simply" in the current code - pointer to procedure:

Code: Pascal  [Select][+][-]
  1.   TGUI_Element = class
  2.     private
  3.       OnClick_proc        : procedure;
  4.  
  5.     public
  6.       procedure RegisterOnClick(p: pointer);
  7.  
  8.       procedure OnClick; virtual; abstract;
  9.   end;  
  10.  
  11. procedure TGUI_Element.RegisterOnClick(p: pointer);
  12. begin
  13.   pointer(onClick_proc) := p;
  14. end;
  15.  
  16. ..
  17.  
  18. TGUI_Button = class ( TGUI_Element )
  19. public
  20.   procedure onClick; override;  
  21.  
  22.   pressed     : Boolean;
  23. end;            
  24.  
  25. procedure TGUI_Button.onClick;
  26. begin
  27.   if assigned( onClick_proc ) and pressed then onClick_proc;
  28. end;  
  29.  
  30. ..
  31.  
  32. // In program
  33.  
  34. Var
  35.   Button : TGUI_Element;
  36.  
  37. procedure SomeProcedure;
  38. begin
  39.   Writeln('Test');
  40. end.
  41.  
  42. begin
  43.   Button.RegisterOnClick( @SomeProcedure );
  44. ..
  45.  

Although it is clear that clarity is gradually decreasing.
Title: Re: Looking for lightweight GUI
Post by: Paul_ on June 19, 2019, 10:25:19 am
Great games build with FPC?

My game will be "great" :)
Title: Re: Looking for lightweight GUI
Post by: furious programming on June 19, 2019, 11:00:09 am
Don't forget about my Deep Platformer (https://forum.lazarus.freepascal.org/index.php/topic,44908.msg316120.html#msg316120) — it is still under development! 8)
Title: Re: Looking for lightweight GUI
Post by: Ñuño_Martínez on June 19, 2019, 11:01:12 am
I forgot: my MinGRo game engine has a semi-complex GUI system.  The engine is still in alpha but the GUI is quite stable and I doubt it will change a lot.  I'm using Allegro (not WinAPI/XWindow) but you can see how it works and compare with your ideas.

You can take a peek here, at SVN (https://sourceforge.net/p/mingro/code/HEAD/tree/TRUNK/src/engine/) (was rewritten from scratch since the last release so do not download the package), the files that start with "mnggui...".  You have the example here (https://sourceforge.net/p/mingro/code/HEAD/tree/TRUNK/src/examples/gui.pp), and an actual use in the map editor (https://sourceforge.net/p/mingro/code/HEAD/tree/TRUNK/src/tools/mapedit/).
Title: Re: Looking for lightweight GUI
Post by: lainz on June 20, 2019, 06:29:04 pm
I as well did games with Lazarus, small ones but I learned the basics of tilemap and tileset with it, and basic physics.
https://github.com/bgrabitmap/bgragames

Unfortunately none of these has GUI, so is not usefull for the original question.
Title: Re: Looking for lightweight GUI
Post by: sash on August 19, 2019, 09:03:47 pm
BTW I occasionally found that ImGui library have Pascal bindings.

https://github.com/ocornut/imgui/wiki/Bindings
Title: Re: Looking for lightweight GUI
Post by: Paul_ on August 20, 2019, 01:53:49 am
ImGui is great, but it's designed rather for editors, tools and debug than for game purposes like menus, indicators, buttons with graphics and such things.

I checked some of code and later started writing my own GUI unit + LCL editor, probably the easiest solution. It's done in simple way, +- similar style as User137 code (NX).

From Pascal world is most advanced probably ZenGUI, what I found. With full exporter for events code (it generates unit).

Title: Re: Looking for lightweight GUI
Post by: sash on August 20, 2019, 11:17:54 am
ImGui is great, but it's designed rather for editors, tools and debug than for game purposes like menus, indicators, buttons with graphics and such things.
My (limited) knowledge about ImGui tells me you could use/write custom widgets for that purpose, but this will require C/C++.

Well, it's pity to admit game development world is not very Pascal-friendly.
Title: Re: Looking for lightweight GUI
Post by: Paul_ on August 20, 2019, 05:33:09 pm
My (limited) knowledge about ImGui tells me you could use/write custom widgets for that purpose, but this will require C/C++.

Maybe you're right. I saw only few skins for menu's. What especially discourageds me from ImGUI is that such libraries are native C++, then someone made C bindings and DLL's and after that someone made Pascal headers :) I'm enjoying this with SFML yet, can't debug DLL code.

Would be easier to use at least the C library like https://github.com/vurtun/nuklear and only translate headers. But it's funny because header have 26 000 lines of code or something like that.

nxPascal has some kind of UI but it is a little tricky to link your own code to button clicks and other events. Because the editor is in no way linked to the actual app that uses it source code you can't directly assign the events in it

If we return to this issue, how it's done in Lazarus IDE that it creates "event interface" code for components directly into the code in editor?
Title: Re: Looking for lightweight GUI
Post by: sash on August 21, 2019, 11:30:51 am
libraries are native C++, then someone made C bindings and DLL's and after that someone made Pascal headers :)

Pascal headers are not wrappers (like C interface to C++) they are just another alternative (to C's headers) client interface, so there should be no runtime overhead in C -> Pascal conversion, maybe with exception of pchar to string assignments.

can't debug DLL code.
Why? Normally it is possible.
Title: Re: Looking for lightweight GUI
Post by: Paul_ on August 21, 2019, 02:07:23 pm
I can debug the program, but it in case of SFML DLL's it mostly returns assembler code without any clue where the error occurred. Not even function from Pascal headers that was called. SFML have no exceptions, only text output in some cases when you can't create window or you're loading nonexistent or unsupported file.

I don't have much experience with that. There is any possibility?
Title: Re: Looking for lightweight GUI
Post by: mr-highball on August 21, 2019, 03:13:43 pm
for games in pascal these are probably your best bet (to my knowledge)

castle has been around for quite a while and is continually being updated, and pasvulkan is not quite a full engine yet (also to my knowledge), but appears to have some good stuff and may be more lightweight. each have UI implementations, but I've only really played around with castle and it has quite a bit of documentation. If you're up for reading some code then vulkan may be path you want to take, and it appears there is at least a template to start you out
https://github.com/BeRo1985/pasvulkan/tree/master/projects/template
Title: Re: Looking for lightweight GUI
Post by: sash on August 22, 2019, 10:59:06 am
I don't have much experience with that. There is any possibility?
As I said earlier, yes, but of course to debug SFML (C++ code) you need that code to be compiled with debug info and (IDE that supports) C++ debugger.
Everything without debugging info (and proper language support) is seen "as assembler" by any native-code debuggers (incl. Lazarus).

Practically, I doubt you need it. Just handle the data you're feeding to SFML properly, with checks/exceptions on Pascal' side and it will be ok.
TinyPortal © 2005-2018