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