Do

Merge lp:~psybers/do/digiclock into lp:do

Proposed by Robert Dyer
Status: Merged
Merged at revision: not available
Proposed branch: lp:~psybers/do/digiclock
Merge into: lp:do
Diff against target: None lines
To merge this branch: bzr merge lp:~psybers/do/digiclock
Reviewer Review Type Date Requested Status
Jason Smith (community) Approve
Review via email: mp+8041@code.launchpad.net
To post a comment you must log in.
lp:~psybers/do/digiclock updated
1237. By Robert Dyer <rdyer@narmada>

adding icons to menus

1238. By Robert Dyer <rdyer@narmada>

icons were backwards

1239. By Robert Dyer <rdyer@narmada>

add 24hr clock option

Revision history for this message
Jason Smith (jassmith) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Do.Interface.Linux.Docky/src/Docky.Interface/Docky.Interface.Items/ClockDockItem.cs'
2--- Do.Interface.Linux.Docky/src/Docky.Interface/Docky.Interface.Items/ClockDockItem.cs 2009-05-16 17:48:47 +0000
3+++ Do.Interface.Linux.Docky/src/Docky.Interface/Docky.Interface.Items/ClockDockItem.cs 2009-06-28 05:46:08 +0000
4@@ -28,17 +28,37 @@
5 using Do.Interface.CairoUtils;
6 using Do.Platform;
7
8+using Docky.Core;
9+using Docky.Interface.Menus;
10 using Docky.Interface.Painters;
11
12 namespace Docky.Interface
13 {
14-
15-
16- public class ClockDockItem : AbstractDockletItem
17+ public class ClockDockItem : AbstractDockletItem, IRightClickable
18 {
19 int minute;
20 CalendarPainter cal_painter;
21
22+ static IPreferences prefs = Services.Preferences.Get<ClockDockItem> ();
23+
24+ bool digital = prefs.Get<bool> ("ShowDigital", false);
25+ bool ShowDigital {
26+ get { return digital; }
27+ set {
28+ digital = value;
29+ prefs.Set<bool> ("ShowDigital", value);
30+ }
31+ }
32+
33+ bool show_date = prefs.Get<bool> ("ShowDate", false);
34+ bool ShowDate {
35+ get { return show_date; }
36+ set {
37+ show_date = value;
38+ prefs.Set<bool> ("ShowDate", value);
39+ }
40+ }
41+
42 public override string Name {
43 get {
44 return "Clock";
45@@ -47,7 +67,7 @@
46
47 public override ScalingType ScalingType {
48 get {
49- return ScalingType.HighLow;
50+ return ShowDigital ? ScalingType.Downscaled : ScalingType.HighLow;
51 }
52 }
53
54@@ -96,49 +116,156 @@
55 Surface tmp_surface = similar.CreateSimilar (Cairo.Content.ColorAlpha, size, size);
56
57 using (Context cr = new Context (tmp_surface)) {
58- cr.AlphaFill ();
59-
60- int center = size / 2;
61- int radius = center;
62-
63- RenderFileOntoContext (cr, System.IO.Path.Combine (ThemePath, "clock-drop-shadow.svg"), radius * 2);
64- RenderFileOntoContext (cr, System.IO.Path.Combine (ThemePath, "clock-face.svg"), radius * 2);
65- RenderFileOntoContext (cr, System.IO.Path.Combine (ThemePath, "clock-marks.svg"), radius * 2);
66- RenderFileOntoContext (cr, System.IO.Path.Combine (ThemePath, "clock-face-shadow.svg"), radius * 2);
67- RenderFileOntoContext (cr, System.IO.Path.Combine (ThemePath, "clock-glass.svg"), radius * 2);
68- RenderFileOntoContext (cr, System.IO.Path.Combine (ThemePath, "clock-frame.svg"), radius * 2);
69-
70- cr.Translate (center, center);
71- cr.Color = new Cairo.Color (.15, .15, .15);
72-
73- cr.LineWidth = Math.Max (1, size / 48);
74- cr.LineCap = LineCap.Round;
75- double minuteRotation = 2 * Math.PI * (DateTime.Now.Minute / 60.0) + Math.PI;
76- cr.Rotate (minuteRotation);
77- cr.MoveTo (0, radius - radius * .35);
78- cr.LineTo (0, 0 - radius * .15);
79- cr.Stroke ();
80- cr.Rotate (0 - minuteRotation);
81-
82- cr.Color = new Cairo.Color (0, 0, 0);
83- double hourRotation = 2 * Math.PI * (DateTime.Now.Hour / 12.0) +
84- Math.PI + (Math.PI / 6) * DateTime.Now.Minute / 60.0;
85- cr.Rotate (hourRotation);
86- cr.MoveTo (0, radius - radius * .5);
87- cr.LineTo (0, 0 - radius * .15);
88- cr.Stroke ();
89- cr.Rotate (0 - hourRotation);
90-
91- cr.Translate (0 - center, 0 - center);
92+ if (ShowDigital)
93+ MakeDigitalIcon (cr, size);
94+ else
95+ MakeAnalogIcon (cr, size);
96 }
97
98 return tmp_surface;
99 }
100
101+ void MakeDigitalIcon (Context cr, int size)
102+ {
103+ // shared by all text
104+ TextRenderContext textContext = new TextRenderContext (cr, string.Empty, size);
105+ textContext.Alignment = Pango.Alignment.Center;
106+ textContext.EllipsizeMode = Pango.EllipsizeMode.None;
107+
108+ // draw the time, outlined
109+ textContext.FontSize = size / 4;
110+ if (ShowDate)
111+ textContext.LeftCenteredPoint = new Gdk.Point (- size / 20, textContext.FontSize);
112+ else
113+ textContext.LeftCenteredPoint = new Gdk.Point (- size / 20, size / 2 - size / 8);
114+
115+ textContext.Text = string.Format ("<b>{0}</b>", DateTime.Now.ToString ("h:mm"));
116+
117+ DockServices.DrawingService.TextPathAtPoint (textContext);
118+ cr.LineWidth = 3;
119+ cr.Color = new Cairo.Color (0, 0, 0, 0.5);
120+ cr.Stroke ();
121+
122+ DockServices.DrawingService.TextPathAtPoint (textContext);
123+ cr.Color = new Cairo.Color (1, 1, 1, 0.8);
124+ cr.Fill ();
125+
126+ // draw the date, outlined
127+ if (ShowDate) {
128+ textContext.FontSize = size / 5;
129+ textContext.LeftCenteredPoint = new Gdk.Point (-size / 20, size - textContext.FontSize);
130+
131+ textContext.Text = string.Format ("<b>{0}</b>", DateTime.Now.ToString ("MMM dd"));
132+
133+ DockServices.DrawingService.TextPathAtPoint (textContext);
134+ cr.Color = new Cairo.Color (0, 0, 0, 0.5);
135+ cr.Stroke ();
136+
137+ DockServices.DrawingService.TextPathAtPoint (textContext);
138+ cr.Color = new Cairo.Color (1, 1, 1, 0.8);
139+ cr.Fill ();
140+ }
141+
142+ // shared for AM/PM
143+ textContext = new TextRenderContext (cr, string.Empty, size / 2);
144+ textContext.FontSize = size / 5;
145+
146+ // draw AM indicator
147+ if (DateTime.Now.Hour < 12)
148+ cr.Color = new Cairo.Color (1, 1, 1, 0.9);
149+ else
150+ cr.Color = new Cairo.Color (1, 1, 1, 0.5);
151+
152+ textContext.Text = "<b>am</b>";
153+ if (ShowDate)
154+ textContext.LeftCenteredPoint = new Gdk.Point (0, size / 2);
155+ else
156+ textContext.LeftCenteredPoint = new Gdk.Point (0, size / 8 + size / 2 + textContext.FontSize);
157+ DockServices.DrawingService.TextPathAtPoint (textContext);
158+ cr.Fill ();
159+
160+ // draw PM indicator
161+ if (DateTime.Now.Hour > 11)
162+ cr.Color = new Cairo.Color (1, 1, 1, 0.9);
163+ else
164+ cr.Color = new Cairo.Color (1, 1, 1, 0.5);
165+
166+ textContext.Text = "<b>pm</b>";
167+ if (ShowDate)
168+ textContext.LeftCenteredPoint = new Gdk.Point (size / 2, size / 2);
169+ else
170+ textContext.LeftCenteredPoint = new Gdk.Point (size / 2, size / 8 + size / 2 + textContext.FontSize);
171+ DockServices.DrawingService.TextPathAtPoint (textContext);
172+ cr.Fill ();
173+ }
174+
175+ void MakeAnalogIcon (Context cr, int size)
176+ {
177+ cr.AlphaFill ();
178+
179+ int center = size / 2;
180+ int radius = center;
181+
182+ RenderFileOntoContext (cr, System.IO.Path.Combine (ThemePath, "clock-drop-shadow.svg"), radius * 2);
183+ RenderFileOntoContext (cr, System.IO.Path.Combine (ThemePath, "clock-face.svg"), radius * 2);
184+ RenderFileOntoContext (cr, System.IO.Path.Combine (ThemePath, "clock-marks.svg"), radius * 2);
185+ RenderFileOntoContext (cr, System.IO.Path.Combine (ThemePath, "clock-face-shadow.svg"), radius * 2);
186+ RenderFileOntoContext (cr, System.IO.Path.Combine (ThemePath, "clock-glass.svg"), radius * 2);
187+ RenderFileOntoContext (cr, System.IO.Path.Combine (ThemePath, "clock-frame.svg"), radius * 2);
188+
189+ cr.Translate (center, center);
190+ cr.Color = new Cairo.Color (.15, .15, .15);
191+
192+ cr.LineWidth = Math.Max (1, size / 48);
193+ cr.LineCap = LineCap.Round;
194+ double minuteRotation = 2 * Math.PI * (DateTime.Now.Minute / 60.0) + Math.PI;
195+ cr.Rotate (minuteRotation);
196+ cr.MoveTo (0, radius - radius * .35);
197+ cr.LineTo (0, 0 - radius * .15);
198+ cr.Stroke ();
199+ cr.Rotate (0 - minuteRotation);
200+
201+ cr.Color = new Cairo.Color (0, 0, 0);
202+ double hourRotation = 2 * Math.PI * (DateTime.Now.Hour / 12.0) +
203+ Math.PI + (Math.PI / 6) * DateTime.Now.Minute / 60.0;
204+ cr.Rotate (hourRotation);
205+ cr.MoveTo (0, radius - radius * .5);
206+ cr.LineTo (0, 0 - radius * .15);
207+ cr.Stroke ();
208+ cr.Rotate (0 - hourRotation);
209+
210+ cr.Translate (0 - center, 0 - center);
211+ }
212+
213 public override void Clicked (uint button, Gdk.ModifierType state, PointD position)
214 {
215 cal_painter.Summon ();
216 base.Clicked (button, state, position);
217 }
218+
219+ #region IRightClickable implementation
220+
221+ public event EventHandler RemoveClicked;
222+
223+ public IEnumerable<AbstractMenuArgs> GetMenuItems ()
224+ {
225+ yield return new SeparatorMenuButtonArgs ();
226+
227+ if (!ShowDigital) {
228+ yield return new SimpleMenuButtonArgs (() => { ShowDigital = true; RedrawIcon (); },
229+ Catalog.GetString ("Show Digital"), "");
230+ } else {
231+ yield return new SimpleMenuButtonArgs (() => { ShowDigital = false; RedrawIcon (); },
232+ Catalog.GetString ("Show Analog"), "");
233+ if (ShowDate)
234+ yield return new SimpleMenuButtonArgs (() => { ShowDate = false; RedrawIcon (); },
235+ Catalog.GetString ("Hide Date"), "");
236+ else
237+ yield return new SimpleMenuButtonArgs (() => { ShowDate = true; RedrawIcon (); },
238+ Catalog.GetString ("Show Date"), "");
239+ }
240+ }
241+
242+ #endregion
243 }
244 }