2
// Copyright (C) 2009 GNOME Do
4
// This program is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
14
// You should have received a copy of the GNU General Public License
15
// along with this program. If not, see <http://www.gnu.org/licenses/>.
19
using System.Collections.Generic;
28
using Do.Interface.CairoUtils;
31
using Docky.Interface.Painters;
33
namespace Docky.Interface
37
public class ClockDockItem : AbstractDockletItem
40
CalendarPainter cal_painter;
42
public override string Name {
48
public override ScalingType ScalingType {
50
return ScalingType.HighLow;
56
if (Directory.Exists (System.IO.Path.Combine (Services.Paths.UserDataDirectory, "ClockTheme")))
57
return System.IO.Path.Combine (Services.Paths.UserDataDirectory, "ClockTheme");
58
if (Directory.Exists ("/usr/share/gnome-do/ClockTheme"))
59
return "/usr/share/gnome-do/ClockTheme";
60
if (Directory.Exists ("/usr/local/share/gnome-do/ClockTheme"))
61
return "/usr/local/share/gnome-do/ClockTheme";
66
public ClockDockItem()
68
cal_painter = new CalendarPainter (this);
69
Core.DockServices.PainterService.RegisterPainter (cal_painter);
70
GLib.Timeout.Add (1000, ClockUpdateTimer);
73
bool ClockUpdateTimer ()
75
if (minute != DateTime.UtcNow.Minute) {
76
SetText (DateTime.Now.ToString ("ddd, MMM dd h:mm tt"));
78
minute = DateTime.UtcNow.Minute;
83
protected override Pixbuf GetSurfacePixbuf (int size)
88
void RenderFileOntoContext (Context cr, string file, int size)
90
if (!File.Exists (file))
93
Gdk.Pixbuf pbuf = Rsvg.Tool.PixbufFromFileAtSize (file, size, size);
94
CairoHelper.SetSourcePixbuf (cr, pbuf, 0, 0);
99
protected override Surface MakeIconSurface (Cairo.Surface similar, int size)
102
Surface tmp_surface = similar.CreateSimilar (similar.Content, size, size);
104
using (Context cr = new Context (tmp_surface)) {
107
int center = size / 2;
110
RenderFileOntoContext (cr, System.IO.Path.Combine (ThemePath, "clock-drop-shadow.svg"), radius * 2);
111
RenderFileOntoContext (cr, System.IO.Path.Combine (ThemePath, "clock-face.svg"), radius * 2);
112
RenderFileOntoContext (cr, System.IO.Path.Combine (ThemePath, "clock-marks.svg"), radius * 2);
113
RenderFileOntoContext (cr, System.IO.Path.Combine (ThemePath, "clock-face-shadow.svg"), radius * 2);
114
RenderFileOntoContext (cr, System.IO.Path.Combine (ThemePath, "clock-glass.svg"), radius * 2);
115
RenderFileOntoContext (cr, System.IO.Path.Combine (ThemePath, "clock-frame.svg"), radius * 2);
117
cr.Translate (center, center);
118
cr.Color = new Cairo.Color (.15, .15, .15);
120
cr.LineWidth = Math.Max (1, size / 48);
121
cr.LineCap = LineCap.Round;
122
double minuteRotation = 2 * Math.PI * (DateTime.Now.Minute / 60.0) + Math.PI;
123
cr.Rotate (minuteRotation);
124
cr.MoveTo (0, radius - radius * .35);
125
cr.LineTo (0, 0 - radius * .15);
127
cr.Rotate (0 - minuteRotation);
129
cr.Color = new Cairo.Color (0, 0, 0);
130
double hourRotation = 2 * Math.PI * (DateTime.Now.Hour / 12.0) +
131
Math.PI + (Math.PI / 6) * DateTime.Now.Minute / 60.0;
132
cr.Rotate (hourRotation);
133
cr.MoveTo (0, radius - radius * .5);
134
cr.LineTo (0, 0 - radius * .15);
136
cr.Rotate (0 - hourRotation);
138
cr.Translate (0 - center, 0 - center);
144
public override void Clicked (uint button, Gdk.ModifierType state, Gdk.Point position)
146
cal_painter.Summon ();
147
base.Clicked (button, state, position);