~ubuntu-branches/ubuntu/trusty/gnome-do/trusty-proposed

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// DockBackgroundRenderer.cs
// 
// Copyright (C) 2008 GNOME Do
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//

using System;
using System.Collections.Generic;

using Cairo;
using Gdk;

using Do.Interface.CairoUtils;

using Docky.Utilities;

namespace Docky.Interface.Painters
{
	
	
	public static class DockBackgroundRenderer
	{
		static Surface sr;
		static int height;
		
		const int ShineWidth = 120;
		const int width = 1500;
		
		public static void RenderDockBackground (Context context, Gdk.Rectangle dockArea)
		{
			if (sr == null || dockArea.Height != height) {
				
				if (sr != null)
					sr.Destroy ();
				
				height = dockArea.Height;
				sr = context.Target.CreateSimilar (context.Target.Content, width, dockArea.Height);
				
				using (Context cr = new Context (sr)) {
					cr.SetRoundedRectanglePath (.5, .5, width - 1, height + 40, 5); // fall off the bottom
					cr.Color = new Cairo.Color (0.1, 0.1, 0.1, .75);
					cr.FillPreserve ();
			
					// gives the dock a "lifted" look and feel
					cr.Color = new Cairo.Color (0, 0, 0, .6);
					cr.LineWidth = 1;
					cr.Stroke ();
			
					cr.SetRoundedRectanglePath (1.5, 1.5, width - 3, height + 40, 5);
					LinearGradient lg = new LinearGradient (0, 1.5, 0, 10);
					lg.AddColorStop (0, new Cairo.Color (1, 1, 1, .4));
					lg.AddColorStop (1, new Cairo.Color (1, 1, 1, 0));
					cr.Pattern = lg;
					cr.LineWidth = 1;
					cr.Stroke ();
				
					lg.Destroy ();
				}
			}
			
			switch (DockPreferences.Orientation) {
			case DockOrientation.Bottom:
				RenderBackground (context, dockArea);
				break;
			case DockOrientation.Top:
				context.Scale (1, -1);
				context.Translate (0, 0 - (dockArea.Height + dockArea.Y));
				
				RenderBackground (context, dockArea);
				
				context.Translate (0, dockArea.Height + dockArea.Y);
				context.Scale (1, -1);
				break;
			}
		}

		static void RenderBackground (Context context, Gdk.Rectangle dockArea)
		{
			context.SetSource (sr, dockArea.X, dockArea.Y);
			context.Rectangle (dockArea.X, dockArea.Y, dockArea.Width / 2, dockArea.Height);
			context.Fill ();
			
			context.SetSource (sr, dockArea.X + dockArea.Width - width, dockArea.Y);
			context.Rectangle (dockArea.X + dockArea.Width / 2, dockArea.Y, dockArea.Width - dockArea.Width / 2, dockArea.Height);
			context.Fill ();
		}
	}
}