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