~ubuntu-branches/ubuntu/wily/gnome-do/wily

« back to all changes in this revision

Viewing changes to Do.Interface.Linux.Docky/src/Docky.Interface/Util.cs

  • Committer: Bazaar Package Importer
  • Author(s): Christopher James Halse Rogers
  • Date: 2011-02-15 21:50:02 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20110215215002-1j8ylb69o15asb06
Tags: 0.8.4-0ubuntu1
* The Race Against FF upload.  Merge from unreleased Debian git.
  Remaining Ubuntu changes:
  + debian/patches/05_disable_resize_grips.patch.diff:
    Disable resize handles for the Do windows.
  + debian/control:
    Bump gtk# build dep for HasResizeGrip API.
* New Debian changes:
* The long fortold release
  + Fixes a threadsafety issue resulting in 100% CPU usage (Closes: 565591,
    LP: #450852).
  + Proxies all keyring calls to the GTK main thread, as required by the new
    gnome-keyring (Closes: 603876, LP: #553643)
* debian/patches/00_bundledlibs.dpatch:
* debian/rules:
  + Upstream has dropped bundled gmcs binary; now 100% DFSG-free, so we don't
    have to repack the tarball or patch the buildsystem.
* debian/patches/03_disable_docky.dpatch:
  + Drop.  Docky is now gone in the upstream tarball.
* debian/rules:
* debian/control:
* debian/patches/*:
  + Switch to quilt to harmonise with other pkg-cli-* packages.
* debian/control:
  + Drop recommends on gnome-do-docklets.  Docky is now a separate package,
    so the docklets are useless for Do.
  + Bump Breaks on gnome-do-plugins to 0.8.3.  Do no longer provides the Wink
    library, which has been imported into the 0.8.3 do-plugins sources.
  + Bump standards-version; no changes needed.
  + Migrate to git and update VCS fields appropriately

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Util.cs
2
 
// 
3
 
// Copyright (C) 2008 GNOME Do
4
 
//
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.
9
 
//
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.
14
 
//
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/>.
17
 
//
18
 
 
19
 
using System;
20
 
using System.Collections.Generic;
21
 
using System.Diagnostics;
22
 
 
23
 
using Do.Universe;
24
 
using Do.Interface.CairoUtils;
25
 
 
26
 
using Cairo;
27
 
using Gtk;
28
 
using Gdk;
29
 
 
30
 
using Docky.Utilities;
31
 
 
32
 
namespace Docky.Interface
33
 
{
34
 
 
35
 
        public enum IconSource {
36
 
                Statistics,
37
 
                Custom,
38
 
                Application,
39
 
                Docklet,
40
 
                Unknown,
41
 
        }
42
 
        
43
 
        public enum ScalingType {
44
 
                None = 0,
45
 
                Upscaled,
46
 
                Downscaled,
47
 
                HighLow,
48
 
        }
49
 
        
50
 
        public delegate void UpdateRequestHandler (object sender, UpdateRequestArgs args);
51
 
        public delegate void DockItemsChangedHandler (IEnumerable<AbstractDockItem> items);
52
 
        
53
 
        public static class Util
54
 
        {
55
 
                const int Height = 35;
56
 
                const string FormatString = "<span weight=\"600\">{0}</span>";
57
 
                
58
 
                /// <summary>
59
 
                /// Gets a surface containing a transparent black rounded rectangle with the provided text on top.
60
 
                /// </summary>
61
 
                /// <param name="text">
62
 
                /// A <see cref="System.String"/>
63
 
                /// </param>
64
 
                /// <param name="maxWidth">
65
 
                /// A <see cref="System.Int32"/>
66
 
                /// </param>
67
 
                /// <param name="similar">
68
 
                /// A <see cref="Surface"/>
69
 
                /// </param>
70
 
                /// <returns>
71
 
                /// A <see cref="Surface"/>
72
 
                /// </returns>
73
 
                public static Surface GetBorderedTextSurface (string text, int maxWidth, Surface similar, 
74
 
                                                              DockOrientation orientation, out Gdk.Rectangle size)
75
 
                {
76
 
                        Surface sr;
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);
79
 
                        
80
 
                        Context cr = new Context (sr);
81
 
                        
82
 
                        TextRenderContext textContext = new TextRenderContext (cr, string.Format (FormatString, text), maxWidth - 18);
83
 
                        textContext.Alignment = Pango.Alignment.Center;
84
 
                        
85
 
                        Gdk.Rectangle textArea = Core.DockServices.DrawingService.TextPathAtPoint (textContext);
86
 
                        cr.NewPath ();
87
 
                        
88
 
                        size = new Gdk.Rectangle (0, 0, textArea.Width + 20, Height);
89
 
                        textContext.MaximumWidth = textArea.Width;
90
 
                        
91
 
                        
92
 
                        int localHeight = textArea.Height;
93
 
                        cr.SetRoundedRectanglePath (.5, .5, textArea.Width + 20 - 1, localHeight + 10 - 1, 5);
94
 
                        
95
 
                        cr.Color = new Cairo.Color (0.1, 0.1, 0.1, .75);
96
 
                        cr.FillPreserve ();
97
 
 
98
 
                        cr.Color = new Cairo.Color (1, 1, 1, .4);
99
 
                        cr.LineWidth = 1;
100
 
                        cr.Stroke ();
101
 
 
102
 
                        cr.Translate(1,1);
103
 
                        
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);
107
 
                        cr.Fill ();
108
 
                        
109
 
                        cr.Translate(-1,-1);
110
 
 
111
 
                        Core.DockServices.DrawingService.TextPathAtPoint (textContext);
112
 
                        cr.Color = new Cairo.Color (1, 1, 1);
113
 
                        cr.Fill ();
114
 
 
115
 
                        (cr as IDisposable).Dispose ();
116
 
                        return sr;
117
 
                }
118
 
        }
119
 
}