3
// Copyright (C) 2008 GNOME Do
5
// This program is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
10
// This program is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// GNU General Public License for more details.
15
// You should have received a copy of the GNU General Public License
16
// along with this program. If not, see <http://www.gnu.org/licenses/>.
20
using System.Collections.Generic;
21
using System.Diagnostics;
24
using Do.Interface.CairoUtils;
30
using Docky.Utilities;
32
namespace Docky.Interface
35
public enum IconSource {
43
public enum ScalingType {
50
public delegate void UpdateRequestHandler (object sender, UpdateRequestArgs args);
51
public delegate void DockItemsChangedHandler (IEnumerable<AbstractDockItem> items);
53
public static class Util
55
const int Height = 35;
56
const string FormatString = "<span weight=\"600\">{0}</span>";
59
/// Gets a surface containing a transparent black rounded rectangle with the provided text on top.
61
/// <param name="text">
62
/// A <see cref="System.String"/>
64
/// <param name="maxWidth">
65
/// A <see cref="System.Int32"/>
67
/// <param name="similar">
68
/// A <see cref="Surface"/>
71
/// A <see cref="Surface"/>
73
public static Surface GetBorderedTextSurface (string text, int maxWidth, Surface similar,
74
DockOrientation orientation, out Gdk.Rectangle size)
77
// we are going to give ourselves a bit of a buffer due to pango weirdness
78
sr = similar.CreateSimilar (similar.Content, maxWidth + 5, Height);
80
Context cr = new Context (sr);
82
TextRenderContext textContext = new TextRenderContext (cr, string.Format (FormatString, text), maxWidth - 18);
83
textContext.Alignment = Pango.Alignment.Center;
85
Gdk.Rectangle textArea = Core.DockServices.DrawingService.TextPathAtPoint (textContext);
88
size = new Gdk.Rectangle (0, 0, textArea.Width + 20, Height);
89
textContext.MaximumWidth = textArea.Width;
92
int localHeight = textArea.Height;
93
cr.SetRoundedRectanglePath (.5, .5, textArea.Width + 20 - 1, localHeight + 10 - 1, 5);
95
cr.Color = new Cairo.Color (0.1, 0.1, 0.1, .75);
98
cr.Color = new Cairo.Color (1, 1, 1, .4);
104
textContext.LeftCenteredPoint = new Gdk.Point (10, (localHeight + 10) / 2);
105
Core.DockServices.DrawingService.TextPathAtPoint (textContext);
106
cr.Color = new Cairo.Color (0, 0, 0, 0.6);
111
Core.DockServices.DrawingService.TextPathAtPoint (textContext);
112
cr.Color = new Cairo.Color (1, 1, 1);
115
(cr as IDisposable).Dispose ();