Shade windows in OpenTTD

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

erikjanp
Engineer
Engineer
Posts: 15
Joined: 29 Aug 2008 22:30

Shade windows in OpenTTD

Post by erikjanp »

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.
Attachments
Example of OpenTTD with a few shaded windows
Example of OpenTTD with a few shaded windows
shade-demo.png (45.27 KiB) Viewed 10495 times
openttd-svn-17434-shade-code.patch
The code to add shaded windows
(22.11 KiB) Downloaded 221 times
openttd-svn-17434-shade-windowdefs.patch
A lot of changes to the window definitions
(206.1 KiB) Downloaded 173 times
Last edited by erikjanp on 09 Sep 2009 22:09, edited 13 times in total.
erikjanp
Engineer
Engineer
Posts: 15
Joined: 29 Aug 2008 22:30

Re: Shade windows in OpenTTD

Post by erikjanp »

And here are the patch for the middle mouse button and the needed newgrf.

For the hardcore fans: a big patch with version 2 (beta!) of this patch
Attachments
shade.grf
The newgrf for the shade button
(80 Bytes) Downloaded 222 times
openttd-svn-17434-shade-code-add-middle.patch
This patch adds middle mouse button functionality
(10.72 KiB) Downloaded 177 times
openttd-svn-17490-shade-version-2-beta.patch
Version 2 (beta!)
(396.84 KiB) Downloaded 189 times
Last edited by erikjanp on 09 Sep 2009 22:11, edited 7 times in total.
User avatar
Bob Smith
Engineer
Engineer
Posts: 111
Joined: 17 May 2005 23:25

Re: Shade windows in OpenTTD

Post by Bob Smith »

Looks really quite handy.
Timmaexx
Transport Coordinator
Transport Coordinator
Posts: 301
Joined: 03 Jan 2009 17:55

Re: Shade windows in OpenTTD

Post by Timmaexx »

Could be nice, if you create a sidebar and there are these shaded windows.
Very good Thank you!
SHADOW-XIII
Tycoon
Tycoon
Posts: 14275
Joined: 09 Jan 2003 08:37

Re: Shade windows in OpenTTD

Post by SHADOW-XIII »

Nice idea.
Got some more for it:
- middle button press toggle shade/normal window
- sticky windows to move together when one of them is dragged
what are you looking at? it's a signature!
User avatar
belugas
OpenTTD Developer
OpenTTD Developer
Posts: 1507
Joined: 05 Apr 2005 01:48
Location: Deep down the deepest blue
Contact:

Re: Shade windows in OpenTTD

Post by belugas »

:bow:
Really, all I can comment on.
From my personal point of view, that is.
Just ... :bow:
If you are not ready to work a bit for your ideas, it means they don't count much for you.
OpenTTD and Realism? Well... Here are a few thoughs on the matter.
He he he he
------------------------------------------------------------
Music from the Bloody Time Zones
puukko
Engineer
Engineer
Posts: 3
Joined: 01 Dec 2007 21:07

Re: Shade windows in OpenTTD

Post by puukko »

Superb!
User avatar
ChillCore
Tycoon
Tycoon
Posts: 2822
Joined: 04 Oct 2008 23:05
Location: Lost in spaces

Re: Shade windows in OpenTTD

Post by ChillCore »

Ba ba ba ba ba ba ba ba ....

/Moutch stays locked in open position.

What Belugas said.

Attached win32 binaries.
Grf and patches included in zip.

EDIT
Binaries removed.
Patch is now included in trunk.
/EDIT
Last edited by ChillCore on 21 Dec 2009 21:18, edited 2 times in total.
-- .- -.-- / - .... . / ..-. --- .-. -.-. . / -... . / .-- .. - .... / -.-- --- ..- .-.-.-
--- .... / -.-- . .- .... --..-- / .- -. -.. / .--. .-. .- .. ... . / - .... . / .-.. --- .-. -.. / ..-. --- .-. / .... . / --. .- ...- . / ..- ... / -.-. .... --- --- -.-. .... --- --- ... .-.-.- / ---... .--.

Playing with my patchpack? Ask questions on usage and report bugs in the correct thread first, please.
All included patches have been modified and are no longer 100% original.
User avatar
SirXavius
Transport Coordinator
Transport Coordinator
Posts: 302
Joined: 28 Jun 2006 18:25
Location: Florida

Re: Shade windows in OpenTTD

Post by SirXavius »

As a mac user i'm used to rolled up windows, and esp. in an app where A LOT of windows can be open at once, this is a godsend!

May the gods of trunk inclusion smile upon you and deliver your work to the heavens! :bow:
erikjanp
Engineer
Engineer
Posts: 15
Joined: 29 Aug 2008 22:30

Re: Shade windows in OpenTTD

Post by erikjanp »

Update r16336: update 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.

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.

I've updated the patches in the first post.

Oh, and ChillCore, thanks for creating Windows binaries.
User avatar
ChillCore
Tycoon
Tycoon
Posts: 2822
Joined: 04 Oct 2008 23:05
Location: Lost in spaces

Re: Shade windows in OpenTTD

Post by ChillCore »

I really like this patch.
With the middleclick-shade it was even better and I see you have a new version allready. I will test it in a bit.

I do not know if it would be possible and if so how hard it would be, but i have a suggestion.
Here it goes.

If I put a shaded window near the bottom edge of my screen and I unshade it.
Would it be possible to unshade upwards, to not have the window partially offscreen.
I guess this would need querying the currently used screensize ... if too hard do not bother.

ps:
No problem for the binaries.
As long as people do not expect me to compile every single version of every patch i like ...
-- .- -.-- / - .... . / ..-. --- .-. -.-. . / -... . / .-- .. - .... / -.-- --- ..- .-.-.-
--- .... / -.-- . .- .... --..-- / .- -. -.. / .--. .-. .- .. ... . / - .... . / .-.. --- .-. -.. / ..-. --- .-. / .... . / --. .- ...- . / ..- ... / -.-. .... --- --- -.-. .... --- --- ... .-.-.- / ---... .--.

Playing with my patchpack? Ask questions on usage and report bugs in the correct thread first, please.
All included patches have been modified and are no longer 100% original.
erikjanp
Engineer
Engineer
Posts: 15
Joined: 29 Aug 2008 22:30

Re: Shade windows in OpenTTD

Post by erikjanp »

Update r16492: update to windowdefs and code-patch; code patch split up in two parts. Patches are in the first and second post.

- 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
User avatar
Xander
Route Supervisor
Route Supervisor
Posts: 485
Joined: 18 May 2007 12:47
Location: Oxford
Contact:

Re: Shade windows in OpenTTD

Post by Xander »

Looks awesome. I'm rubbish with patching and the like but I can't wait to see this in trunk :)
Real Tycoons do it on Trains!

JAMI: Just Another Moronic Intelligence
xZise
Engineer
Engineer
Posts: 57
Joined: 19 Mar 2009 16:52
Location: Bad Schwartau

Re: Shade windows in OpenTTD

Post by xZise »

Hi,

I'm applied the patch, but I get an error on compiling the code (window.cpp):

Code: Select all

static void DispatchMouseWheelEvent(Window *w, int widget, int wheel)
{
	[...]
	/* Scroll on window caption or on news window: shade/unshade */
	if (((w->window_class == WC_NEWS_WINDOW) ||
		(wi1->type == WWT_CAPTION)) &&
		(_settings_client.gui.shade_on_scroll_on_caption != 0) &&
		((_settings_client.gui.shade_on_scroll_on_caption == 2) || (w->desc_flags & WDF_SHADE_BUTTON))) {
		if (w->flags4 & WF_SHADE) {
			UnShadeWindow(w);
		}
		else if (!(w->flags4 & WF_SHADE)) {
			ShadeWindow(w);
		}
	}
}
I'm getting the error on line 6, because "wi1" is unknown. What I have to do? You are using wi1 (and wi2) some lines before (but in an if-block). I doesn't what I could do (e.g. define wi1 outside from the if-clause).

Sincerely
xZise
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Shade windows in OpenTTD

Post by planetmaker »

I'm pretty sure that it must be "w" instead of "wi1"
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: Shade windows in OpenTTD

Post by Alberth »

The variable is(/was) correct, I'm pretty sure that the reason is that I modified the GUI code heavily in r16513 through r16517.

The patch was written for r16492. That is the only revision for which the author tested the patch (hopefully :) ), and for which a build should always work.

For all other revisions, it may or may not work out of the box.

If it does not, you must make changes to the patch to make it work again.
(and if you use a revision different from where the patch was written for, you should check whether the patch was correctly inserted).

Albert
xZise
Engineer
Engineer
Posts: 57
Joined: 19 Mar 2009 16:52
Location: Bad Schwartau

Re: Shade windows in OpenTTD

Post by xZise »

planetmaker wrote:I'm pretty sure that it must be "w" instead of "wi1"
I'm realy unsure, because in my opinion a widget isn't a window (or not?)
Alberth wrote:The variable is(/was) correct, I'm pretty sure that the reason is that I modified the GUI code heavily in r16513 through r16517.

The patch was written for r16492. That is the only revision for which the author tested the patch (hopefully :) ), and for which a build should always work.

For all other revisions, it may or may not work out of the box.

If it does not, you must make changes to the patch to make it work again.
(and if you use a revision different from where the patch was written for, you should check whether the patch was correctly inserted).

Albert
I never said that this code isn't correct, but I want to compile it with the trunk, because I applied some other patches :)
I checked the changes between your used version (window.cpp from r16491) and the trunk. You could use wi1 every time, but (I think) in the trunk it is more "save" to access to.

Sincerely
xZise
xZise
Engineer
Engineer
Posts: 57
Joined: 19 Mar 2009 16:52
Location: Bad Schwartau

Re: Shade windows in OpenTTD

Post by xZise »

Okay I doesn't know if it is correct so, but I tested it brief with moving this block into the if-clause with the widget. For the r16520 it works with following method:

Code: Select all

static void DispatchMouseWheelEvent(Window *w, int widget, int wheel)
{
	if (widget < 0) return;

	Scrollbar *sb = NULL;
	if (w->widget != NULL) {
		const Widget *wi1 = &w->widget[widget];
		const Widget *wi2 = &w->widget[widget + 1];
		if (wi1->type == WWT_SCROLLBAR || wi2->type == WWT_SCROLLBAR) {
			sb = &w->vscroll;
		} else if (wi1->type == WWT_SCROLL2BAR || wi2->type == WWT_SCROLL2BAR) {
			sb = &w->vscroll2;
		}

		//
		// HERE THE NEW CODE STARTS
		//
		/* Scroll on window caption or on news window: shade/unshade */
		if (((w->window_class == WC_NEWS_WINDOW) ||
			(wi1->type == WWT_CAPTION)) &&
			(_settings_client.gui.shade_on_scroll_on_caption != 0) &&
			((_settings_client.gui.shade_on_scroll_on_caption == 2) || (w->desc_flags & WDF_SHADE_BUTTON))) {
			if (w->flags4 & WF_SHADE) {
				UnShadeWindow(w);
			}
			else if (!(w->flags4 & WF_SHADE)) {
				ShadeWindow(w);
			}
		}
		//
		// HERE THE NEW CODE ENDS
		//
	}

	if (w->nested_array != NULL && (uint)widget < w->nested_array_size) sb = w->nested_array[widget]->FindScrollbar(w);

	if (sb != NULL && sb->count > sb->cap) {
		int pos = Clamp(sb->pos + wheel, 0, sb->count - sb->cap);
		if (pos != sb->pos) {
			sb->pos = pos;
			w->SetDirty();
		}
	}
}
Sincerely
xZise
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: Shade windows in OpenTTD

Post by Alberth »

It 'works' or it 'compiles' ?

The latter I believe. The former I don't believe.

(Hint: Try shading the town directory window)
erikjanp
Engineer
Engineer
Posts: 15
Joined: 29 Aug 2008 22:30

Re: Shade windows in OpenTTD

Post by erikjanp »

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.
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 46 guests