Multiple window support (I'm a dev, want to write)

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
lost
Engineer
Engineer
Posts: 1
Joined: 19 Mar 2016 18:17

Multiple window support (I'm a dev, want to write)

Post by lost »

Hey guys,

I'm very interested in adding a convenient multi-window ability to OpenTTD. I've just started with OpenTTD source code, but I have a lot of dev experience in general.
Here's what I want so far:
- add a "pop-out"/"get-it" button to every in-game window (let's call it Win), similar to Shade, Resize, and Mark uncloseable.
- on "pop-out" create an OS window (Wos), and starting at this moment render Win in Wos, change the button to "pop-in"
- handle Win or Wos resizing in that state
- on "pop-in" - remove Wos, and from now on render Win in main window again.

Since OpenTTD is a relatively big project, I'd be happy to see pointers to classes and functions I should start with to get those 4 steps done.

P.S. At this moment I'm also looking forward to seeing any alternative propositions on multi-window experience for users.
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Multiple window support (I'm a dev, want to write)

Post by planetmaker »

That's a complex issue :) But generally windows are handled in the *window* files, which in turn make use of the widgets, found in the *widget* source files. The actual different windows which show in game are found in the *_gui.* files.

However depending on the OS you run on, OpenTTD makes use of different video drivers which handle the actual drawing of the OpenTTD window onto the screen. Thus you'll have to touch every video driver for every OS to make here some progress and start supporting several windows. The video driver code is found in the video folder.
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 988
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: Multiple window support (I'm a dev, want to write)

Post by frosch »

There are various things you need to look at.

First you need to look at src/video/*_v.cpp
There you will find the video drivers for win, linux and osx.
I suggest to pick the one you are using and to ignore the rest. In case of linux you likely need to first port the sdl1 code to sdl2, maybe there is already some partial patch for that on the forums.
The important part of the video driver is the gameloop, which calls the drawing at some point. Some other methods fill values in _screen, which defines the framebuffer. Also important is _cursor, which contains the mouse position.
The hardest part is probably to extend the cursor position with some os window id, so the cursor can be mapped to logical windows.

The second part which you need to modify is the cursor/window handling in src/window.cpp
There you will find stuff like a stacking window manager, window-moving, resizing; centering, alignment to other windows, closing of windows and so on.

So, overall you need to look at stuff that uses _cursor and _screen. Though esp. _screen stuff is also copied to other stuff.

Some problems you will run into: Hiding of all windows, for example during map generation. Also moving and resizing windows will probably be quite hard.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 24 guests