Progressing the XPCE GUI

I’ve created this topic next to Progressing the SWI-Prolog environment. That topic is about using xpce for the Prolig IDE. This is about XPCE itself. The main achievements that relate to both are:

  • Tabs and tiled subwindows are now used extensively by the IDE, stopping the many windows floating over your screen. Tools run in panes, a tab can hold multiple panes as tiled subwindows and a frame holds one or more tabs. panes can be dragged to reorganize the tiling, move them to other tabs or frames. Preferred arrangements can be remembered and are learned if they are used frequently.
  • The '95 look and feel has been replaced by something modern that is fairly neutral in many desktop environments.
  • On MacOS we use the unified menu bar at the top.
  • Theme selection is now live, i.e., it follows the desktop setting real time (or user selection if it is not set to Follow desktop)
  • There is a theme editor to edit the colours of a theme graphically. Created themes are based on other themes and can be saved (as a Prolog file in your personal library).
  • There is a GUI preferences editor that lets you control fonts and a lot of settings that apply to the tools. All changes are immediate and can be saved to your preferences file.

Then there are changes that merely have impact on people who what to use XPCE for a GUI. The above are of course part of this, but there is more. Already in the development releases:

  • Replaced @Address terms with Prolog blobs, written as <pce>(Address, Class). This provides safe mutual garbage collection as well as protection from using arbitrary numbers as pointers in the other environment. The same mechanism is used in the Janus Python interface, the JPL Java interface, the WASM JavaScript interface, etc.
  • Support for transparency and matrix transformation (rotation, scaling, sheering)
  • Full support for Cairo 2D graphics and Pango text rendering.

The upcoming patch take XPCE to a next level

  • Support Pango markup in most of the widgets. This allows for read-only text objects that have multiple fonts and (possibly themed) colours.
  • SDL support:
    • Support all SDL standard input devices: keyboard, mouse, but also touchpad, pen and gamepad. Add missing event details and events (e.g., key_up). Input devices are represented by an object that is added to the event. Most objects can be polled (e.g., is the ‘k’ key down?, Is the right trigger of the gamepad down?)
    • Add sdl_window as new window type. It allows drawing as any other window through the Cairo layer, but it also renders GPU managed SDL textures and a lot of stuff to combine and manage these. sdl_mesh renders an array of triangles using gradients, the typical way to render complex coloured regions using the GPU.
    • Support sound and video input and output. This includes support for compressed and streaming sound and video, both playing and generating. The latter uses ffmpeg, stripped down to the bare minimum for the MacOS and Windows binary installers. There are demos recording and playing sound as wel as video.

There are two game demos: Pong and Asteroids. Asteroids started using xpce graphical objects, but now runs using SDL’s GPU rendered objects.

Programming SDL differs from how this normally works. A normal game engine renders a frame, polls the input, computes the next frame, etc. XPCE is completely event based. The main loop is “process pending events. If there is no pending event, push the pending changes to the UI and wait for the next event”. The current two game demos use a 50Hz timer. On each time tick they poll the input and update the graphics. My ADM395AI system runs Asteroids in about 3-5% CPU. If people want to try adapting game frameworks, I’m happy to help thinking how this could be done. There surely are options, both single and multi-threaded.

Ideas on how to progress this further or make nice attractive applications using Prolog are welcome!

Neat. I was having a free Minimax model port XPCE/Cosmos and write a basic rogue. SDL might be useful.