Shade windows in OpenTTD
Posted: 15 May 2009 13:20
Hi,
In Linux, most window managers can "shade" windows. That is, it can roll up the entire window into the title bar, so it takes up less space but isn't closed or minimized to the taskbar.
In OpenTTD this would be handy as well: for taking a quick peek behind a window; for rolling up a big window that you want to monitor every now and then or that just got popped up where you were laying track; for organizing train windows; etc.
So I started to code this (first time in C++) and this is what I came up with. I've added an extra button to most windows (to some it doesn't make sense to shade it). Click it and the window disappears into its title bar. Click it again and it goes back to full size.
You can also use the scrollwheel of your mouse on the title of the window with the same result. The behavior of the scroll wheel is configurable in 'Advanced settings -> Interface -> Interaction'.
As an extra, clicking a window with middle mouse button also shades the window. Because a third mouse button is new to OpenTTD (and not all platforms support this), I've put this in an extra patch. The behavior of the third mouse button is also configurable.
Three patches:
- shade-code.patch: this patch adds the basic shading functionality to OpenTTD.
- shade-windowdefs.patch: this patch modifies a lot of window definitions to give them shade buttons and keep them from drawing anything below the titlebar.
- shade-code-add-middle.patch: this patch adds middle mouse button functionality to OpenTTD. This patch should be applied after the shade-code.patch.
The patches are against svn-trunk. Backporting to 0.7 would be difficult for the windowdefs.patch because some window definitions have changed since then.
Also needed: a newgrf for the new shade/unshade buttons.
I've created a bug on flyspray: http://bugs.openttd.org/task/2943
New version
Here is a new (beta) version of this patch. It is a more sophisticated version: not simply cutting everything below pixel y=14, but defining for each widget to which shade level it belongs. Shading a window then can be done in steps: big window -> smaller window -> shaded window.
Current version(s)
Update r17434: update to windowdefs and code-patches.
- Updated to svn-17434. Recently, a lot of changes were done in trunk to the window and widget code, so I hope I got all the changes correctly and didn't leave any old stuff.
Version 2 (beta)
- New version of this patch. It uses a less hackier way of shading windows, by defining shade levels for each widget.
Note: it is still beta! Especially in all the gui.cpp's there is still a lot of cleaning up to do.
The most important changes are in window.cpp and widget.cpp; all functional window shading code is found there.
For an (useless) example of a window with more than two shade levels: check out the news history window.
For more information: see docs/shadelevel.txt
Older updates
Update r16943: update to windowdefs and code-patches.
- Updated to svn-r16943
- Fixed coding style
- Removed hardcoded values for the size of the shadebox
Update r16883: update to windowdefs and code-patches.
- Updated to svn-r16883.
- No other changes, not even to coding style.
Update r16571: update to windowdefs and code-patches.
- Updated the code so now it also works with the new nested widgets alberth is introducing in trunk
- Updated to svn-r16571.
Update r16492: update to windowdefs and code-patch; code patch split up in two parts.
- Unshading a window that is near the bottom of the screen moves the window up so it is completely visible.
- Fix the shading in the game options window.
- Move the third mouse button functionality to a separate patch. This new patch should be applied after the code patch.
- Calculate the height of the shaded window via the height of the title/caption bar. Only fall back on hardcoded height if the title bar doesn't have a caption, like the news windows.
- A few fixes to the code that weren't directly connected to shading are now in trunk; therefore they are removed from the patch.
- Updated to svn-r16492.
- Added a bug on flyspray: http://bugs.openttd.org/task/2943
Update r16345: update to windowdefs-patch only.
- Fix size of autoreplace window for road vehicles, ships and airplanes.
- The vehicle list button in the ship and airplane depot screens was too small
- Updated to svn-r16345.
Update r16336: updates to both code and windowdefs-patches.
- Middle click with mouse on window now also shades the window (suggestion by SHADOW-XIII). Untested on windows and allegro.
- Moved ShadeWindow and UnShadeWindow to seperate functions.
- When setting scroll and middle-click to 'off', unshade all existing windows to prevent windows to get stuck in shaded position.
- Updated to svn-r16336.
In Linux, most window managers can "shade" windows. That is, it can roll up the entire window into the title bar, so it takes up less space but isn't closed or minimized to the taskbar.
In OpenTTD this would be handy as well: for taking a quick peek behind a window; for rolling up a big window that you want to monitor every now and then or that just got popped up where you were laying track; for organizing train windows; etc.
So I started to code this (first time in C++) and this is what I came up with. I've added an extra button to most windows (to some it doesn't make sense to shade it). Click it and the window disappears into its title bar. Click it again and it goes back to full size.
You can also use the scrollwheel of your mouse on the title of the window with the same result. The behavior of the scroll wheel is configurable in 'Advanced settings -> Interface -> Interaction'.
As an extra, clicking a window with middle mouse button also shades the window. Because a third mouse button is new to OpenTTD (and not all platforms support this), I've put this in an extra patch. The behavior of the third mouse button is also configurable.
Three patches:
- shade-code.patch: this patch adds the basic shading functionality to OpenTTD.
- shade-windowdefs.patch: this patch modifies a lot of window definitions to give them shade buttons and keep them from drawing anything below the titlebar.
- shade-code-add-middle.patch: this patch adds middle mouse button functionality to OpenTTD. This patch should be applied after the shade-code.patch.
The patches are against svn-trunk. Backporting to 0.7 would be difficult for the windowdefs.patch because some window definitions have changed since then.
Also needed: a newgrf for the new shade/unshade buttons.
I've created a bug on flyspray: http://bugs.openttd.org/task/2943
New version
Here is a new (beta) version of this patch. It is a more sophisticated version: not simply cutting everything below pixel y=14, but defining for each widget to which shade level it belongs. Shading a window then can be done in steps: big window -> smaller window -> shaded window.
Current version(s)
Update r17434: update to windowdefs and code-patches.
- Updated to svn-17434. Recently, a lot of changes were done in trunk to the window and widget code, so I hope I got all the changes correctly and didn't leave any old stuff.
Version 2 (beta)
- New version of this patch. It uses a less hackier way of shading windows, by defining shade levels for each widget.
Note: it is still beta! Especially in all the gui.cpp's there is still a lot of cleaning up to do.
The most important changes are in window.cpp and widget.cpp; all functional window shading code is found there.
For an (useless) example of a window with more than two shade levels: check out the news history window.
For more information: see docs/shadelevel.txt
Older updates
Update r16943: update to windowdefs and code-patches.
- Updated to svn-r16943
- Fixed coding style
- Removed hardcoded values for the size of the shadebox
Update r16883: update to windowdefs and code-patches.
- Updated to svn-r16883.
- No other changes, not even to coding style.
Update r16571: update to windowdefs and code-patches.
- Updated the code so now it also works with the new nested widgets alberth is introducing in trunk
- Updated to svn-r16571.
Update r16492: update to windowdefs and code-patch; code patch split up in two parts.
- Unshading a window that is near the bottom of the screen moves the window up so it is completely visible.
- Fix the shading in the game options window.
- Move the third mouse button functionality to a separate patch. This new patch should be applied after the code patch.
- Calculate the height of the shaded window via the height of the title/caption bar. Only fall back on hardcoded height if the title bar doesn't have a caption, like the news windows.
- A few fixes to the code that weren't directly connected to shading are now in trunk; therefore they are removed from the patch.
- Updated to svn-r16492.
- Added a bug on flyspray: http://bugs.openttd.org/task/2943
Update r16345: update to windowdefs-patch only.
- Fix size of autoreplace window for road vehicles, ships and airplanes.
- The vehicle list button in the ship and airplane depot screens was too small
- Updated to svn-r16345.
Update r16336: updates to both code and windowdefs-patches.
- Middle click with mouse on window now also shades the window (suggestion by SHADOW-XIII). Untested on windows and allegro.
- Moved ShadeWindow and UnShadeWindow to seperate functions.
- When setting scroll and middle-click to 'off', unshade all existing windows to prevent windows to get stuck in shaded position.
- Updated to svn-r16336.