Merge lp:~ricotz/docky/pangolayout into lp:docky
- pangolayout
- Merge into trunk
Proposed by
Rico Tzschichholz
Status: | Needs review |
---|---|
Proposed branch: | lp:~ricotz/docky/pangolayout |
Merge into: | lp:docky |
Diff against target: |
1371 lines (+566/-558) 9 files modified
Docky.Items/Docky.Items/AbstractDockItem.cs (+93/-91) Docky.Items/Docky.Items/IconEmblem.cs (+1/-0) Docky/Docky/Interface/DockWindow.cs (+29/-26) Docky/Docky/Menus/MenuItemWidget.cs (+45/-45) Docky/Docky/Menus/SeparatorWidget.cs (+31/-21) StandardPlugins/Clock/src/CalendarPainter.cs (+100/-98) StandardPlugins/Clock/src/ClockDockItem.cs (+119/-123) StandardPlugins/Weather/src/WeatherDocklet.cs (+33/-29) StandardPlugins/Weather/src/WeatherPainter.cs (+115/-125) |
To merge this branch: | bzr merge lp:~ricotz/docky/pangolayout |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Robert Dyer (community) | Needs Fixing | ||
Review via email:
|
Commit message
Description of the change
Use static Pango.Layouts to hopefully reduce memory leaks and get some more performance.
To post a comment you must log in.
lp:~ricotz/docky/pangolayout
updated
- 1654. By Rico Tzschichholz
-
fix leaking FontDescriptions
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Robert Dyer (psybers) wrote : | # |
In ADI, you can lift the FontDescription stuff for hover_layout
review:
Needs Fixing
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Robert Dyer (psybers) wrote : | # |
Same thing in DockWindow
review:
Needs Fixing
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Robert Dyer (psybers) wrote : | # |
You need to override Dispose *everywhere* and properly dispose the layouts and font descriptions, since they are now global in the class!
review:
Needs Fixing
lp:~ricotz/docky/pangolayout
updated
- 1655. By Rico Tzschichholz
-
merge trunk 1736
- 1656. By Rico Tzschichholz
-
fix build
- 1657. By Rico Tzschichholz
-
remove Width settings
- 1658. By Rico Tzschichholz
-
and more layout-stuff moved
- 1659. By Rico Tzschichholz
-
reset Width
- 1660. By Rico Tzschichholz
-
still one more
- 1661. By Rico Tzschichholz
-
merge trunk 1745
- 1662. By Rico Tzschichholz
-
fix leak
Unmerged revisions
- 1662. By Rico Tzschichholz
-
fix leak
- 1661. By Rico Tzschichholz
-
merge trunk 1745
- 1660. By Rico Tzschichholz
-
still one more
- 1659. By Rico Tzschichholz
-
reset Width
- 1658. By Rico Tzschichholz
-
and more layout-stuff moved
- 1657. By Rico Tzschichholz
-
remove Width settings
- 1656. By Rico Tzschichholz
-
fix build
- 1655. By Rico Tzschichholz
-
merge trunk 1736
- 1654. By Rico Tzschichholz
-
fix leaking FontDescriptions
- 1653. By Rico Tzschichholz
-
Use static Pango.Layouts instead of creating new one everytime
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'Docky.Items/Docky.Items/AbstractDockItem.cs' | |||
2 | --- Docky.Items/Docky.Items/AbstractDockItem.cs 2010-12-28 16:43:48 +0000 | |||
3 | +++ Docky.Items/Docky.Items/AbstractDockItem.cs 2011-01-03 11:34:09 +0000 | |||
4 | @@ -44,6 +44,35 @@ | |||
5 | 44 | 44 | ||
6 | 45 | public abstract class AbstractDockItem : IDisposable | 45 | public abstract class AbstractDockItem : IDisposable |
7 | 46 | { | 46 | { |
8 | 47 | const int HoverTextFontSize = 11; | ||
9 | 48 | |||
10 | 49 | static Pango.Layout badge_layout; | ||
11 | 50 | static Pango.Layout hover_layout; | ||
12 | 51 | static Pango.Layout message_layout; | ||
13 | 52 | |||
14 | 53 | static AbstractDockItem () | ||
15 | 54 | { | ||
16 | 55 | Gtk.Style style = new Gtk.Style (); | ||
17 | 56 | |||
18 | 57 | badge_layout = DockServices.Drawing.ThemedPangoLayout (); | ||
19 | 58 | badge_layout.Ellipsize = Pango.EllipsizeMode.None; | ||
20 | 59 | badge_layout.FontDescription = style.FontDescription; | ||
21 | 60 | badge_layout.FontDescription.Weight = Pango.Weight.Bold; | ||
22 | 61 | |||
23 | 62 | hover_layout = DockServices.Drawing.ThemedPangoLayout (); | ||
24 | 63 | hover_layout.Ellipsize = Pango.EllipsizeMode.End; | ||
25 | 64 | hover_layout.FontDescription = style.FontDescription; | ||
26 | 65 | hover_layout.FontDescription.Weight = Pango.Weight.Bold; | ||
27 | 66 | hover_layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (HoverTextFontSize); | ||
28 | 67 | |||
29 | 68 | message_layout = DockServices.Drawing.ThemedPangoLayout (); | ||
30 | 69 | message_layout.Ellipsize = Pango.EllipsizeMode.None; | ||
31 | 70 | message_layout.FontDescription = style.FontDescription; | ||
32 | 71 | message_layout.FontDescription.Weight = Pango.Weight.Normal; | ||
33 | 72 | |||
34 | 73 | style.Dispose (); | ||
35 | 74 | } | ||
36 | 75 | |||
37 | 47 | string hover_text, remote_text; | 76 | string hover_text, remote_text; |
38 | 48 | string badge_text, remote_badge_text; | 77 | string badge_text, remote_badge_text; |
39 | 49 | bool[] redraw; | 78 | bool[] redraw; |
40 | @@ -696,29 +725,20 @@ | |||
41 | 696 | } | 725 | } |
42 | 697 | } | 726 | } |
43 | 698 | 727 | ||
67 | 699 | using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) | 728 | message_layout.Width = Pango.Units.FromPixels (surface.Width - iconSize - 8); |
68 | 700 | { | 729 | message_layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) slotHeight - 6); |
69 | 701 | layout.Width = Pango.Units.FromPixels (surface.Width - iconSize - 8); | 730 | message_layout.SetText (message); |
70 | 702 | layout.Ellipsize = Pango.EllipsizeMode.None; | 731 | |
71 | 703 | layout.FontDescription = new Gtk.Style ().FontDescription; | 732 | Pango.Rectangle inkRect, logicalRect; |
72 | 704 | layout.FontDescription.Weight = Pango.Weight.Normal; | 733 | message_layout.GetPixelExtents (out inkRect, out logicalRect); |
73 | 705 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) slotHeight - 6); | 734 | |
74 | 706 | layout.SetText (message); | 735 | surface.Context.MoveTo (surface.Width - 4 - logicalRect.Width, yOffset + (slotHeight - 2 - logicalRect.Height) / 2); |
75 | 707 | 736 | ||
76 | 708 | Pango.Rectangle inkRect, logicalRect; | 737 | Pango.CairoHelper.LayoutPath (surface.Context, message_layout); |
77 | 709 | layout.GetPixelExtents (out inkRect, out logicalRect); | 738 | surface.Context.LineWidth = 2; |
78 | 710 | 739 | surface.Context.StrokePreserve (); | |
79 | 711 | surface.Context.MoveTo (surface.Width - 4 - logicalRect.Width, yOffset + (slotHeight - 2 - logicalRect.Height) / 2); | 740 | surface.Context.Color = new Cairo.Color (1, 1, 1, 1); |
80 | 712 | 741 | surface.Context.Fill (); | |
58 | 713 | Pango.CairoHelper.LayoutPath (surface.Context, layout); | ||
59 | 714 | surface.Context.LineWidth = 2; | ||
60 | 715 | surface.Context.StrokePreserve (); | ||
61 | 716 | surface.Context.Color = new Cairo.Color (1, 1, 1, 1); | ||
62 | 717 | surface.Context.Fill (); | ||
63 | 718 | |||
64 | 719 | layout.FontDescription.Dispose (); | ||
65 | 720 | layout.Context.Dispose (); | ||
66 | 721 | } | ||
81 | 722 | } | 742 | } |
82 | 723 | 743 | ||
83 | 724 | void PaintProgressSurface (DockySurface surface) | 744 | void PaintProgressSurface (DockySurface surface) |
84 | @@ -862,47 +882,38 @@ | |||
85 | 862 | padding = 2; | 882 | padding = 2; |
86 | 863 | } | 883 | } |
87 | 864 | 884 | ||
128 | 865 | using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) | 885 | badge_layout.Width = Pango.Units.FromPixels (surface.Height / 2); |
129 | 866 | { | 886 | |
130 | 867 | layout.Width = Pango.Units.FromPixels (surface.Height / 2); | 887 | Pango.Rectangle inkRect, logicalRect; |
131 | 868 | layout.Ellipsize = Pango.EllipsizeMode.None; | 888 | badge_layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (surface.Height / 2); |
132 | 869 | layout.FontDescription = new Gtk.Style ().FontDescription; | 889 | badge_layout.SetText (BadgeText); |
133 | 870 | layout.FontDescription.Weight = Pango.Weight.Bold; | 890 | badge_layout.GetPixelExtents (out inkRect, out logicalRect); |
134 | 871 | 891 | ||
135 | 872 | Pango.Rectangle inkRect, logicalRect; | 892 | size -= 2 * padding + 2 * lineWidth; |
136 | 873 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (surface.Height / 2); | 893 | |
137 | 874 | layout.SetText (BadgeText); | 894 | double scale = Math.Min (1, Math.Min (size / (double) logicalRect.Width, size / (double) logicalRect.Height)); |
138 | 875 | layout.GetPixelExtents (out inkRect, out logicalRect); | 895 | |
139 | 876 | 896 | if (!IsSmall) { | |
140 | 877 | size -= 2 * padding + 2 * lineWidth; | 897 | surface.Context.Color = new Cairo.Color (0, 0, 0, 0.2); |
141 | 878 | 898 | } else { | |
142 | 879 | double scale = Math.Min (1, Math.Min (size / (double) logicalRect.Width, size / (double) logicalRect.Height)); | 899 | surface.Context.Color = new Cairo.Color (0, 0, 0, 0.6); |
143 | 880 | 900 | x = surface.Width - scale * logicalRect.Width / 2; | |
144 | 881 | if (!IsSmall) { | 901 | y = scale * logicalRect.Height / 2; |
105 | 882 | surface.Context.Color = new Cairo.Color (0, 0, 0, 0.2); | ||
106 | 883 | } else { | ||
107 | 884 | surface.Context.Color = new Cairo.Color (0, 0, 0, 0.6); | ||
108 | 885 | x = surface.Width - scale * logicalRect.Width / 2; | ||
109 | 886 | y = scale * logicalRect.Height / 2; | ||
110 | 887 | } | ||
111 | 888 | |||
112 | 889 | surface.Context.MoveTo (x - scale * logicalRect.Width / 2, y - scale * logicalRect.Height / 2); | ||
113 | 890 | |||
114 | 891 | // draw text | ||
115 | 892 | surface.Context.Save (); | ||
116 | 893 | if (scale < 1) | ||
117 | 894 | surface.Context.Scale (scale, scale); | ||
118 | 895 | |||
119 | 896 | surface.Context.LineWidth = 2; | ||
120 | 897 | Pango.CairoHelper.LayoutPath (surface.Context, layout); | ||
121 | 898 | surface.Context.StrokePreserve (); | ||
122 | 899 | surface.Context.Color = new Cairo.Color (1, 1, 1, 1); | ||
123 | 900 | surface.Context.Fill (); | ||
124 | 901 | surface.Context.Restore (); | ||
125 | 902 | |||
126 | 903 | layout.FontDescription.Dispose (); | ||
127 | 904 | layout.Context.Dispose (); | ||
145 | 905 | } | 902 | } |
146 | 903 | |||
147 | 904 | surface.Context.MoveTo (x - scale * logicalRect.Width / 2, y - scale * logicalRect.Height / 2); | ||
148 | 905 | |||
149 | 906 | // draw text | ||
150 | 907 | surface.Context.Save (); | ||
151 | 908 | if (scale < 1) | ||
152 | 909 | surface.Context.Scale (scale, scale); | ||
153 | 910 | |||
154 | 911 | surface.Context.LineWidth = 2; | ||
155 | 912 | Pango.CairoHelper.LayoutPath (surface.Context, badge_layout); | ||
156 | 913 | surface.Context.StrokePreserve (); | ||
157 | 914 | surface.Context.Color = new Cairo.Color (1, 1, 1, 1); | ||
158 | 915 | surface.Context.Fill (); | ||
159 | 916 | surface.Context.Restore (); | ||
160 | 906 | } | 917 | } |
161 | 907 | 918 | ||
162 | 908 | /// <summary> | 919 | /// <summary> |
163 | @@ -923,35 +934,26 @@ | |||
164 | 923 | return null; | 934 | return null; |
165 | 924 | 935 | ||
166 | 925 | if (text_buffer == null) { | 936 | if (text_buffer == null) { |
195 | 926 | using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) { | 937 | hover_layout.SetText (HoverText); |
196 | 927 | layout.FontDescription = style.FontDescription; | 938 | |
197 | 928 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (11); | 939 | Pango.Rectangle inkRect, logicalRect; |
198 | 929 | layout.FontDescription.Weight = Pango.Weight.Bold; | 940 | hover_layout.GetPixelExtents (out inkRect, out logicalRect); |
199 | 930 | layout.Ellipsize = Pango.EllipsizeMode.End; | 941 | if (logicalRect.Width > 0.8 * Gdk.Screen.Default.Width) { |
200 | 931 | 942 | hover_layout.Width = Pango.Units.FromPixels ((int) (0.8 * Gdk.Screen.Default.Width)); | |
201 | 932 | layout.SetText (HoverText); | 943 | hover_layout.GetPixelExtents (out inkRect, out logicalRect); |
174 | 933 | |||
175 | 934 | Pango.Rectangle inkRect, logicalRect; | ||
176 | 935 | layout.GetPixelExtents (out inkRect, out logicalRect); | ||
177 | 936 | if (logicalRect.Width > 0.8 * Gdk.Screen.Default.Width) { | ||
178 | 937 | layout.Width = Pango.Units.FromPixels ((int) (0.8 * Gdk.Screen.Default.Width)); | ||
179 | 938 | layout.GetPixelExtents (out inkRect, out logicalRect); | ||
180 | 939 | } | ||
181 | 940 | |||
182 | 941 | int textWidth = logicalRect.Width; | ||
183 | 942 | int textHeight = logicalRect.Height; | ||
184 | 943 | int buffer = HoverTextHeight - textHeight; | ||
185 | 944 | text_buffer = new DockySurface (Math.Max (HoverTextHeight, textWidth + buffer), HoverTextHeight, model); | ||
186 | 945 | |||
187 | 946 | Cairo.Context cr = text_buffer.Context; | ||
188 | 947 | |||
189 | 948 | cr.MoveTo (buffer / 2, buffer / 2); | ||
190 | 949 | Pango.CairoHelper.LayoutPath (cr, layout); | ||
191 | 950 | cr.Color = isLight ? new Cairo.Color (0.1, 0.1, 0.1) : new Cairo.Color (1, 1, 1); | ||
192 | 951 | cr.Fill (); | ||
193 | 952 | |||
194 | 953 | layout.Context.Dispose (); | ||
202 | 954 | } | 944 | } |
203 | 945 | |||
204 | 946 | int textWidth = inkRect.Width; | ||
205 | 947 | int textHeight = logicalRect.Height; | ||
206 | 948 | int buffer = HoverTextHeight - textHeight; | ||
207 | 949 | text_buffer = new DockySurface (Math.Max (HoverTextHeight, textWidth + buffer), HoverTextHeight, model); | ||
208 | 950 | |||
209 | 951 | Cairo.Context cr = text_buffer.Context; | ||
210 | 952 | |||
211 | 953 | cr.MoveTo ((text_buffer.Width - textWidth) / 2, buffer / 2); | ||
212 | 954 | Pango.CairoHelper.LayoutPath (cr, hover_layout); | ||
213 | 955 | cr.Color = isLight ? new Cairo.Color (0.1, 0.1, 0.1) : new Cairo.Color (1, 1, 1); | ||
214 | 956 | cr.Fill (); | ||
215 | 955 | } | 957 | } |
216 | 956 | 958 | ||
217 | 957 | return text_buffer; | 959 | return text_buffer; |
218 | 958 | 960 | ||
219 | === modified file 'Docky.Items/Docky.Items/IconEmblem.cs' | |||
220 | --- Docky.Items/Docky.Items/IconEmblem.cs 2010-06-25 13:06:51 +0000 | |||
221 | +++ Docky.Items/Docky.Items/IconEmblem.cs 2011-01-03 11:34:09 +0000 | |||
222 | @@ -97,6 +97,7 @@ | |||
223 | 97 | return; | 97 | return; |
224 | 98 | } | 98 | } |
225 | 99 | ForcePixbuf = info.LoadIcon (); | 99 | ForcePixbuf = info.LoadIcon (); |
226 | 100 | info.Dispose (); | ||
227 | 100 | } | 101 | } |
228 | 101 | 102 | ||
229 | 102 | public Pixbuf GetPixbuf (int parentWidth, int parentHeight) { | 103 | public Pixbuf GetPixbuf (int parentWidth, int parentHeight) { |
230 | 103 | 104 | ||
231 | === modified file 'Docky/Docky/Interface/DockWindow.cs' | |||
232 | --- Docky/Docky/Interface/DockWindow.cs 2010-11-22 08:46:18 +0000 | |||
233 | +++ Docky/Docky/Interface/DockWindow.cs 2011-01-03 11:34:09 +0000 | |||
234 | @@ -135,7 +135,9 @@ | |||
235 | 135 | const int NormalIndicatorSize = 20; | 135 | const int NormalIndicatorSize = 20; |
236 | 136 | const int UrgentIndicatorSize = 26; | 136 | const int UrgentIndicatorSize = 26; |
237 | 137 | const int GlowSize = 30; | 137 | const int GlowSize = 30; |
239 | 138 | 138 | const int HoverTextHeight = 26; | |
240 | 139 | const int HoverTextFontSize = 11; | ||
241 | 140 | |||
242 | 139 | const int WaitGroups = 3; | 141 | const int WaitGroups = 3; |
243 | 140 | const int WaitArmsPerGroup = 8; | 142 | const int WaitArmsPerGroup = 8; |
244 | 141 | 143 | ||
245 | @@ -338,31 +340,20 @@ | |||
246 | 338 | 340 | ||
247 | 339 | DockySurface DrawHoverText (DockySurface surface, string text) | 341 | DockySurface DrawHoverText (DockySurface surface, string text) |
248 | 340 | { | 342 | { |
274 | 341 | using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) { | 343 | hover_layout.SetText (text); |
275 | 342 | layout.FontDescription = Style.FontDescription; | 344 | |
276 | 343 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (11); | 345 | Pango.Rectangle inkRect, logicalRect; |
277 | 344 | layout.FontDescription.Weight = Pango.Weight.Bold; | 346 | hover_layout.GetPixelExtents (out inkRect, out logicalRect); |
278 | 345 | layout.Ellipsize = Pango.EllipsizeMode.End; | 347 | |
279 | 346 | layout.Width = Pango.Units.FromPixels (500); | 348 | int textWidth = inkRect.Width; |
280 | 347 | 349 | int textHeight = logicalRect.Height; | |
281 | 348 | layout.SetText (text); | 350 | int buffer = HoverTextHeight - textHeight; |
282 | 349 | 351 | surface = new DockySurface (Math.Max (HoverTextHeight, textWidth + buffer), HoverTextHeight, background_buffer); | |
283 | 350 | Pango.Rectangle inkRect, logicalRect; | 352 | |
284 | 351 | layout.GetPixelExtents (out inkRect, out logicalRect); | 353 | surface.Context.MoveTo ((surface.Width - textWidth) / 2, buffer / 2); |
285 | 352 | 354 | Pango.CairoHelper.LayoutPath (surface.Context, hover_layout); | |
286 | 353 | const int HoverTextHeight = 26; | 355 | surface.Context.Color = HoverTextManager.IsLight ? new Cairo.Color (0.1, 0.1, 0.1) : new Cairo.Color (1, 1, 1); |
287 | 354 | int textWidth = inkRect.Width; | 356 | surface.Context.Fill (); |
263 | 355 | int textHeight = logicalRect.Height; | ||
264 | 356 | int buffer = HoverTextHeight - textHeight; | ||
265 | 357 | surface = new DockySurface (Math.Max (HoverTextHeight, textWidth + buffer), HoverTextHeight, background_buffer); | ||
266 | 358 | |||
267 | 359 | surface.Context.MoveTo ((surface.Width - textWidth) / 2, buffer / 2); | ||
268 | 360 | Pango.CairoHelper.LayoutPath (surface.Context, layout); | ||
269 | 361 | surface.Context.Color = HoverTextManager.IsLight ? new Cairo.Color (0.1, 0.1, 0.1) : new Cairo.Color (1, 1, 1); | ||
270 | 362 | surface.Context.Fill (); | ||
271 | 363 | |||
272 | 364 | layout.Context.Dispose (); | ||
273 | 365 | } | ||
288 | 366 | 357 | ||
289 | 367 | return surface; | 358 | return surface; |
290 | 368 | } | 359 | } |
291 | @@ -676,9 +667,21 @@ | |||
292 | 676 | 667 | ||
293 | 677 | #endregion | 668 | #endregion |
294 | 678 | 669 | ||
295 | 670 | static Pango.Layout hover_layout; | ||
296 | 671 | |||
297 | 679 | static DockWindow () | 672 | static DockWindow () |
298 | 680 | { | 673 | { |
299 | 681 | DockyItem = new DockyItem (); | 674 | DockyItem = new DockyItem (); |
300 | 675 | |||
301 | 676 | Gtk.Style style = new Gtk.Style (); | ||
302 | 677 | |||
303 | 678 | hover_layout = DockServices.Drawing.ThemedPangoLayout (); | ||
304 | 679 | hover_layout.Ellipsize = Pango.EllipsizeMode.End; | ||
305 | 680 | hover_layout.FontDescription = style.FontDescription; | ||
306 | 681 | hover_layout.FontDescription.Weight = Pango.Weight.Bold; | ||
307 | 682 | hover_layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (HoverTextFontSize); | ||
308 | 683 | |||
309 | 684 | style.Dispose (); | ||
310 | 682 | } | 685 | } |
311 | 683 | 686 | ||
312 | 684 | public DockWindow () : base(Gtk.WindowType.Toplevel) | 687 | public DockWindow () : base(Gtk.WindowType.Toplevel) |
313 | 685 | 688 | ||
314 | === modified file 'Docky/Docky/Menus/MenuItemWidget.cs' | |||
315 | --- Docky/Docky/Menus/MenuItemWidget.cs 2010-11-14 14:17:17 +0000 | |||
316 | +++ Docky/Docky/Menus/MenuItemWidget.cs 2011-01-03 11:34:09 +0000 | |||
317 | @@ -63,6 +63,21 @@ | |||
318 | 63 | 63 | ||
319 | 64 | DockySurface icon_surface, emblem_surface; | 64 | DockySurface icon_surface, emblem_surface; |
320 | 65 | 65 | ||
321 | 66 | static Pango.Layout layout; | ||
322 | 67 | |||
323 | 68 | static MenuItemWidget () | ||
324 | 69 | { | ||
325 | 70 | Gtk.Style style = new Gtk.Style (); | ||
326 | 71 | |||
327 | 72 | layout = DockServices.Drawing.ThemedPangoLayout (); | ||
328 | 73 | layout.Ellipsize = Pango.EllipsizeMode.End; | ||
329 | 74 | layout.FontDescription = style.FontDescription; | ||
330 | 75 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (FontSize); | ||
331 | 76 | layout.FontDescription.Weight = Pango.Weight.Bold; | ||
332 | 77 | |||
333 | 78 | style.Dispose (); | ||
334 | 79 | } | ||
335 | 80 | |||
336 | 66 | internal MenuItemWidget (MenuItem item) : base() | 81 | internal MenuItemWidget (MenuItem item) : base() |
337 | 67 | { | 82 | { |
338 | 68 | TextColor = new Cairo.Color (1, 1, 1); | 83 | TextColor = new Cairo.Color (1, 1, 1); |
339 | @@ -91,26 +106,19 @@ | |||
340 | 91 | 106 | ||
341 | 92 | void CalcTextWidth () | 107 | void CalcTextWidth () |
342 | 93 | { | 108 | { |
363 | 94 | using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) { | 109 | char accel; |
364 | 95 | char accel; | 110 | |
365 | 96 | 111 | if (item.Mnemonic.HasValue) | |
366 | 97 | if (item.Mnemonic.HasValue) | 112 | layout.SetMarkupWithAccel (item.Text, '_', out accel); |
367 | 98 | layout.SetMarkupWithAccel (item.Text, '_', out accel); | 113 | else |
368 | 99 | else | 114 | layout.SetMarkup (item.Text); |
369 | 100 | layout.SetMarkup (item.Text); | 115 | |
370 | 101 | layout.FontDescription = Style.FontDescription; | 116 | layout.Width = -1; |
371 | 102 | layout.Ellipsize = Pango.EllipsizeMode.End; | 117 | Pango.Rectangle logical, ink; |
372 | 103 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (FontSize); | 118 | layout.GetPixelExtents (out ink, out logical); |
373 | 104 | layout.FontDescription.Weight = Pango.Weight.Bold; | 119 | |
374 | 105 | 120 | TextWidth = Math.Min (MaxWidth, Math.Max (MinWidth, logical.Width)); | |
375 | 106 | Pango.Rectangle logical, ink; | 121 | HasTooltip = TextWidth < logical.Width; |
356 | 107 | layout.GetPixelExtents (out ink, out logical); | ||
357 | 108 | |||
358 | 109 | TextWidth = Math.Min (MaxWidth, Math.Max (MinWidth, logical.Width)); | ||
359 | 110 | HasTooltip = TextWidth < logical.Width; | ||
360 | 111 | |||
361 | 112 | layout.Context.Dispose (); | ||
362 | 113 | } | ||
376 | 114 | 122 | ||
377 | 115 | SetSize (); | 123 | SetSize (); |
378 | 116 | } | 124 | } |
379 | @@ -265,31 +273,23 @@ | |||
380 | 265 | } | 273 | } |
381 | 266 | } | 274 | } |
382 | 267 | 275 | ||
408 | 268 | using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) { | 276 | char accel; |
409 | 269 | char accel; | 277 | if (item.Mnemonic.HasValue) |
410 | 270 | if (item.Mnemonic.HasValue) | 278 | layout.SetMarkupWithAccel (item.Text, '_', out accel); |
411 | 271 | layout.SetMarkupWithAccel (item.Text, '_', out accel); | 279 | else |
412 | 272 | else | 280 | layout.SetMarkup (item.Text); |
413 | 273 | layout.SetMarkup (item.Text); | 281 | layout.Width = Pango.Units.FromPixels (TextWidth); |
414 | 274 | layout.Width = Pango.Units.FromPixels (TextWidth); | 282 | |
415 | 275 | layout.FontDescription = Style.FontDescription; | 283 | Pango.Rectangle logical, ink; |
416 | 276 | layout.Ellipsize = Pango.EllipsizeMode.End; | 284 | layout.GetPixelExtents (out ink, out logical); |
417 | 277 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (FontSize); | 285 | |
418 | 278 | layout.FontDescription.Weight = Pango.Weight.Bold; | 286 | int offset = Padding; |
419 | 279 | 287 | if (MenuShowingIcons) | |
420 | 280 | Pango.Rectangle logical, ink; | 288 | offset += MenuHeight + Padding; |
421 | 281 | layout.GetPixelExtents (out ink, out logical); | 289 | cr.MoveTo (allocation.X + offset, allocation.Y + (allocation.Height - logical.Height) / 2); |
422 | 282 | 290 | Pango.CairoHelper.LayoutPath (cr, layout); | |
423 | 283 | int offset = Padding; | 291 | cr.Color = TextColor.SetAlpha (item.Disabled ? 0.5 : 1); |
424 | 284 | if (MenuShowingIcons) | 292 | cr.Fill (); |
400 | 285 | offset += MenuHeight + Padding; | ||
401 | 286 | cr.MoveTo (allocation.X + offset, allocation.Y + (allocation.Height - logical.Height) / 2); | ||
402 | 287 | Pango.CairoHelper.LayoutPath (cr, layout); | ||
403 | 288 | cr.Color = TextColor.SetAlpha (item.Disabled ? 0.5 : 1); | ||
404 | 289 | cr.Fill (); | ||
405 | 290 | |||
406 | 291 | layout.Context.Dispose (); | ||
407 | 292 | } | ||
425 | 293 | 293 | ||
426 | 294 | (cr.Target as IDisposable).Dispose (); | 294 | (cr.Target as IDisposable).Dispose (); |
427 | 295 | } | 295 | } |
428 | 296 | 296 | ||
429 | === modified file 'Docky/Docky/Menus/SeparatorWidget.cs' | |||
430 | --- Docky/Docky/Menus/SeparatorWidget.cs 2010-10-15 15:32:36 +0000 | |||
431 | +++ Docky/Docky/Menus/SeparatorWidget.cs 2011-01-03 11:34:09 +0000 | |||
432 | @@ -28,12 +28,29 @@ | |||
433 | 28 | { | 28 | { |
434 | 29 | public class SeparatorWidget : EventBox | 29 | public class SeparatorWidget : EventBox |
435 | 30 | { | 30 | { |
436 | 31 | const int FontSize = 8; | ||
437 | 32 | |||
438 | 31 | string title; | 33 | string title; |
439 | 32 | 34 | ||
440 | 33 | public Cairo.Color TextColor { get; set; } | 35 | public Cairo.Color TextColor { get; set; } |
441 | 34 | 36 | ||
442 | 35 | public bool DrawLine { get; set; } | 37 | public bool DrawLine { get; set; } |
443 | 36 | 38 | ||
444 | 39 | static Pango.Layout layout; | ||
445 | 40 | |||
446 | 41 | static SeparatorWidget () | ||
447 | 42 | { | ||
448 | 43 | Gtk.Style style = new Gtk.Style (); | ||
449 | 44 | |||
450 | 45 | layout = DockServices.Drawing.ThemedPangoLayout (); | ||
451 | 46 | layout.Ellipsize = Pango.EllipsizeMode.End; | ||
452 | 47 | layout.FontDescription = style.FontDescription; | ||
453 | 48 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (FontSize); | ||
454 | 49 | layout.FontDescription.Weight = Pango.Weight.Bold; | ||
455 | 50 | |||
456 | 51 | style.Dispose (); | ||
457 | 52 | } | ||
458 | 53 | |||
459 | 37 | public SeparatorWidget (string title) | 54 | public SeparatorWidget (string title) |
460 | 38 | { | 55 | { |
461 | 39 | this.title = title; | 56 | this.title = title; |
462 | @@ -63,27 +80,20 @@ | |||
463 | 63 | int xMiddle = x + width / 2; | 80 | int xMiddle = x + width / 2; |
464 | 64 | double yMiddle = Allocation.Y + Allocation.Height / 2.0; | 81 | double yMiddle = Allocation.Y + Allocation.Height / 2.0; |
465 | 65 | 82 | ||
487 | 66 | if (!string.IsNullOrEmpty (title)) | 83 | if (!string.IsNullOrEmpty (title)) { |
488 | 67 | using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) { | 84 | layout.SetText (title); |
489 | 68 | layout.SetText (title); | 85 | layout.Width = Pango.Units.FromPixels (Allocation.Width - Allocation.Height); |
490 | 69 | layout.Width = Pango.Units.FromPixels (Allocation.Width - Allocation.Height); | 86 | |
491 | 70 | layout.FontDescription = Style.FontDescription; | 87 | Pango.Rectangle logical, ink; |
492 | 71 | layout.Ellipsize = Pango.EllipsizeMode.End; | 88 | layout.GetPixelExtents (out ink, out logical); |
493 | 72 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (8); | 89 | |
494 | 73 | layout.FontDescription.Weight = Pango.Weight.Bold; | 90 | cr.MoveTo (Allocation.X + 2, Allocation.Y + (Allocation.Height - logical.Height) / 2); |
495 | 74 | 91 | Pango.CairoHelper.LayoutPath (cr, layout); | |
496 | 75 | Pango.Rectangle logical, ink; | 92 | cr.Color = TextColor.SetAlpha (.6); |
497 | 76 | layout.GetPixelExtents (out ink, out logical); | 93 | cr.Fill (); |
498 | 77 | 94 | ||
499 | 78 | cr.MoveTo (Allocation.X + 2, Allocation.Y + (Allocation.Height - logical.Height) / 2); | 95 | x += logical.Width + 5; |
500 | 79 | Pango.CairoHelper.LayoutPath (cr, layout); | 96 | } |
480 | 80 | cr.Color = TextColor.SetAlpha (.6); | ||
481 | 81 | cr.Fill (); | ||
482 | 82 | |||
483 | 83 | x += logical.Width + 5; | ||
484 | 84 | |||
485 | 85 | layout.Context.Dispose (); | ||
486 | 86 | } | ||
501 | 87 | 97 | ||
502 | 88 | if (DrawLine) { | 98 | if (DrawLine) { |
503 | 89 | cr.MoveTo (x, yMiddle); | 99 | cr.MoveTo (x, yMiddle); |
504 | 90 | 100 | ||
505 | === modified file 'StandardPlugins/Clock/src/CalendarPainter.cs' | |||
506 | --- StandardPlugins/Clock/src/CalendarPainter.cs 2010-07-15 07:44:12 +0000 | |||
507 | +++ StandardPlugins/Clock/src/CalendarPainter.cs 2011-01-03 11:34:09 +0000 | |||
508 | @@ -42,6 +42,31 @@ | |||
509 | 42 | } | 42 | } |
510 | 43 | } | 43 | } |
511 | 44 | 44 | ||
512 | 45 | static Pango.Layout header_layout; | ||
513 | 46 | static Pango.Layout line_layout; | ||
514 | 47 | static Pango.Layout month_layout; | ||
515 | 48 | |||
516 | 49 | static CalendarPainter () | ||
517 | 50 | { | ||
518 | 51 | Gtk.Style style = new Gtk.Style (); | ||
519 | 52 | |||
520 | 53 | header_layout = DockServices.Drawing.ThemedPangoLayout (); | ||
521 | 54 | header_layout.FontDescription = style.FontDescription; | ||
522 | 55 | header_layout.FontDescription.Weight = Pango.Weight.Bold; | ||
523 | 56 | header_layout.Ellipsize = Pango.EllipsizeMode.None; | ||
524 | 57 | |||
525 | 58 | line_layout = DockServices.Drawing.ThemedPangoLayout (); | ||
526 | 59 | line_layout.FontDescription = style.FontDescription; | ||
527 | 60 | line_layout.Ellipsize = Pango.EllipsizeMode.None; | ||
528 | 61 | |||
529 | 62 | month_layout = DockServices.Drawing.ThemedPangoLayout (); | ||
530 | 63 | month_layout.FontDescription = style.FontDescription; | ||
531 | 64 | month_layout.FontDescription.Weight = Pango.Weight.Bold; | ||
532 | 65 | month_layout.Ellipsize = Pango.EllipsizeMode.None; | ||
533 | 66 | |||
534 | 67 | style.Dispose (); | ||
535 | 68 | } | ||
536 | 69 | |||
537 | 45 | public CalendarPainter () : base (3) | 70 | public CalendarPainter () : base (3) |
538 | 46 | { | 71 | { |
539 | 47 | StartDate = DateTime.Today.AddDays (1 - DateTime.Today.Day); | 72 | StartDate = DateTime.Today.AddDays (1 - DateTime.Today.Day); |
540 | @@ -106,33 +131,25 @@ | |||
541 | 106 | { | 131 | { |
542 | 107 | string month = StartDate.ToString ("MMMM").ToUpper (); | 132 | string month = StartDate.ToString ("MMMM").ToUpper (); |
543 | 108 | 133 | ||
571 | 109 | using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) { | 134 | month_layout.Width = Pango.Units.FromPixels (Allocation.Height); |
572 | 110 | layout.FontDescription = new Gtk.Style().FontDescription; | 135 | month_layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (Allocation.Height / 6); |
573 | 111 | layout.FontDescription.Weight = Pango.Weight.Bold; | 136 | |
574 | 112 | layout.Ellipsize = Pango.EllipsizeMode.None; | 137 | cr.Save (); |
575 | 113 | layout.Width = Pango.Units.FromPixels (Allocation.Height); | 138 | cr.Color = new Cairo.Color (1, 1, 1, .5); |
576 | 114 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (Allocation.Height / 6); | 139 | month_layout.SetText (month); |
577 | 115 | 140 | ||
578 | 116 | cr.Save (); | 141 | Pango.Rectangle inkRect, logicalRect; |
579 | 117 | cr.Color = new Cairo.Color (1, 1, 1, .5); | 142 | month_layout.GetPixelExtents (out inkRect, out logicalRect); |
580 | 118 | layout.SetText (month); | 143 | double scale = Math.Min (1, Math.Min (Allocation.Height / (double) inkRect.Width, (Allocation.Width / 9.0) / (double) logicalRect.Height)); |
581 | 119 | 144 | ||
582 | 120 | Pango.Rectangle inkRect, logicalRect; | 145 | cr.Rotate (Math.PI / -2.0); |
583 | 121 | layout.GetPixelExtents (out inkRect, out logicalRect); | 146 | cr.MoveTo ((Allocation.Height - scale * inkRect.Width) / 2 - Allocation.Height, Allocation.Width / 9 - scale * logicalRect.Height); |
584 | 122 | double scale = Math.Min (1, Math.Min (Allocation.Height / (double) inkRect.Width, (Allocation.Width / 9.0) / (double) logicalRect.Height)); | 147 | if (scale < 1) |
585 | 123 | 148 | cr.Scale (scale, scale); | |
586 | 124 | cr.Rotate (Math.PI / -2.0); | 149 | |
587 | 125 | cr.MoveTo ((Allocation.Height - scale * inkRect.Width) / 2 - Allocation.Height, Allocation.Width / 9 - scale * logicalRect.Height); | 150 | Pango.CairoHelper.LayoutPath (cr, month_layout); |
588 | 126 | if (scale < 1) | 151 | cr.Fill (); |
589 | 127 | cr.Scale (scale, scale); | 152 | cr.Restore (); |
563 | 128 | |||
564 | 129 | Pango.CairoHelper.LayoutPath (cr, layout); | ||
565 | 130 | cr.Fill (); | ||
566 | 131 | cr.Restore (); | ||
567 | 132 | |||
568 | 133 | layout.FontDescription.Dispose (); | ||
569 | 134 | layout.Context.Dispose (); | ||
570 | 135 | } | ||
590 | 136 | } | 153 | } |
591 | 137 | 154 | ||
592 | 138 | void RenderHeader (Context cr, DateTime start) | 155 | void RenderHeader (Context cr, DateTime start) |
593 | @@ -142,28 +159,20 @@ | |||
594 | 142 | 159 | ||
595 | 143 | DateTime day = CalendarStartDate; | 160 | DateTime day = CalendarStartDate; |
596 | 144 | 161 | ||
619 | 145 | using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) { | 162 | header_layout.Width = Pango.Units.FromPixels (offsetSize); |
620 | 146 | layout.FontDescription = new Gtk.Style().FontDescription; | 163 | header_layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (0.625 * LineHeight)); |
621 | 147 | layout.FontDescription.Weight = Pango.Weight.Bold; | 164 | |
622 | 148 | layout.Ellipsize = Pango.EllipsizeMode.None; | 165 | cr.Color = new Cairo.Color (1, 1, 1, .5); |
623 | 149 | layout.Width = Pango.Units.FromPixels (offsetSize); | 166 | for (int i = 0; i < 7; i++) { |
624 | 150 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (0.625 * LineHeight)); | 167 | header_layout.SetText (day.ToString ("ddd").ToUpper ()); |
625 | 151 | 168 | ||
626 | 152 | cr.Color = new Cairo.Color (1, 1, 1, .5); | 169 | Pango.Rectangle inkRect, logicalRect; |
627 | 153 | for (int i = 0; i < 7; i++) { | 170 | header_layout.GetPixelExtents (out inkRect, out logicalRect); |
628 | 154 | layout.SetText (day.ToString ("ddd").ToUpper ()); | 171 | cr.MoveTo (offsetSize + offsetSize * i + (offsetSize - inkRect.Width) / 2, centerLine - logicalRect.Height); |
629 | 155 | 172 | ||
630 | 156 | Pango.Rectangle inkRect, logicalRect; | 173 | Pango.CairoHelper.LayoutPath (cr, header_layout); |
631 | 157 | layout.GetPixelExtents (out inkRect, out logicalRect); | 174 | cr.Fill (); |
632 | 158 | cr.MoveTo (offsetSize + offsetSize * i + (offsetSize - inkRect.Width) / 2, centerLine - logicalRect.Height); | 175 | day = day.AddDays (1); |
611 | 159 | |||
612 | 160 | Pango.CairoHelper.LayoutPath (cr, layout); | ||
613 | 161 | cr.Fill (); | ||
614 | 162 | day = day.AddDays (1); | ||
615 | 163 | } | ||
616 | 164 | |||
617 | 165 | layout.FontDescription.Dispose (); | ||
618 | 166 | layout.Context.Dispose (); | ||
633 | 167 | } | 176 | } |
634 | 168 | } | 177 | } |
635 | 169 | 178 | ||
636 | @@ -174,58 +183,51 @@ | |||
637 | 174 | int centerLine = LineHeight + LineHeight * line + ((Allocation.Height % LineHeight) / 2); | 183 | int centerLine = LineHeight + LineHeight * line + ((Allocation.Height % LineHeight) / 2); |
638 | 175 | int dayOffset = 0; | 184 | int dayOffset = 0; |
639 | 176 | 185 | ||
675 | 177 | using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) { | 186 | Pango.Rectangle inkRect, logicalRect; |
676 | 178 | Pango.Rectangle inkRect, logicalRect; | 187 | |
677 | 179 | 188 | line_layout.Width = Pango.Units.FromPixels (offsetSize); | |
678 | 180 | layout.FontDescription = new Gtk.Style().FontDescription; | 189 | line_layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (0.625 * LineHeight)); |
679 | 181 | layout.Ellipsize = Pango.EllipsizeMode.None; | 190 | |
680 | 182 | layout.Width = Pango.Units.FromPixels (offsetSize); | 191 | for (int i = 0; i < 7; i++) { |
681 | 183 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (0.625 * LineHeight)); | 192 | line_layout.FontDescription.Weight = Pango.Weight.Normal; |
682 | 184 | 193 | ||
683 | 185 | for (int i = 0; i < 7; i++) { | 194 | DateTime day = lineStart.AddDays (dayOffset); |
684 | 186 | layout.FontDescription.Weight = Pango.Weight.Normal; | 195 | |
685 | 187 | 196 | if (day.Month == CalendarStartDate.AddDays (6).Month) | |
686 | 188 | DateTime day = lineStart.AddDays (dayOffset); | 197 | cr.Color = new Cairo.Color (1, 1, 1); |
687 | 189 | 198 | else | |
688 | 190 | if (day.Month == CalendarStartDate.AddDays (6).Month) | 199 | cr.Color = new Cairo.Color (1, 1, 1, 0.5); |
689 | 191 | cr.Color = new Cairo.Color (1, 1, 1); | 200 | |
690 | 192 | else | 201 | if (day.Date == DateTime.Today) |
691 | 193 | cr.Color = new Cairo.Color (1, 1, 1, 0.5); | 202 | { |
692 | 194 | 203 | line_layout.FontDescription.Weight = Pango.Weight.Bold; | |
693 | 195 | if (day.Date == DateTime.Today) | 204 | Gdk.Color color = Style.Backgrounds [(int) StateType.Selected].SetMinimumValue (100); |
694 | 196 | { | 205 | cr.Color = new Cairo.Color ((double) color.Red / ushort.MaxValue, |
695 | 197 | layout.FontDescription.Weight = Pango.Weight.Bold; | 206 | (double) color.Green / ushort.MaxValue, |
696 | 198 | Gdk.Color color = Style.Backgrounds [(int) StateType.Selected].SetMinimumValue (100); | 207 | (double) color.Blue / ushort.MaxValue, |
697 | 199 | cr.Color = new Cairo.Color ((double) color.Red / ushort.MaxValue, | 208 | 1.0); |
663 | 200 | (double) color.Green / ushort.MaxValue, | ||
664 | 201 | (double) color.Blue / ushort.MaxValue, | ||
665 | 202 | 1.0); | ||
666 | 203 | } | ||
667 | 204 | dayOffset++; | ||
668 | 205 | |||
669 | 206 | layout.SetText (string.Format ("{0:00}", day.Day)); | ||
670 | 207 | layout.GetPixelExtents (out inkRect, out logicalRect); | ||
671 | 208 | cr.MoveTo (offsetSize + offsetSize * i + (offsetSize - inkRect.Width) / 2, centerLine - logicalRect.Height); | ||
672 | 209 | |||
673 | 210 | Pango.CairoHelper.LayoutPath (cr, layout); | ||
674 | 211 | cr.Fill (); | ||
698 | 212 | } | 209 | } |
710 | 213 | 210 | dayOffset++; | |
711 | 214 | cr.Color = new Cairo.Color (1, 1, 1, 0.4); | 211 | |
712 | 215 | int woy = CultureInfo.CurrentCulture.Calendar.GetWeekOfYear (lineStart.AddDays (6), | 212 | line_layout.SetText (string.Format ("{0:00}", day.Day)); |
713 | 216 | DateTimeFormatInfo.CurrentInfo.CalendarWeekRule, | 213 | line_layout.GetPixelExtents (out inkRect, out logicalRect); |
714 | 217 | DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek); | 214 | cr.MoveTo (offsetSize + offsetSize * i + (offsetSize - inkRect.Width) / 2, centerLine - logicalRect.Height); |
715 | 218 | layout.FontDescription.Weight = Pango.Weight.Bold; | 215 | |
716 | 219 | layout.SetText (string.Format ("W{0:00}", woy)); | 216 | Pango.CairoHelper.LayoutPath (cr, line_layout); |
706 | 220 | layout.GetPixelExtents (out inkRect, out logicalRect); | ||
707 | 221 | cr.MoveTo (offsetSize * 8, centerLine - logicalRect.Height); | ||
708 | 222 | |||
709 | 223 | Pango.CairoHelper.LayoutPath (cr, layout); | ||
717 | 224 | cr.Fill (); | 217 | cr.Fill (); |
718 | 225 | |||
719 | 226 | layout.FontDescription.Dispose (); | ||
720 | 227 | layout.Context.Dispose (); | ||
721 | 228 | } | 218 | } |
722 | 219 | |||
723 | 220 | cr.Color = new Cairo.Color (1, 1, 1, 0.4); | ||
724 | 221 | int woy = CultureInfo.CurrentCulture.Calendar.GetWeekOfYear (lineStart.AddDays (6), | ||
725 | 222 | DateTimeFormatInfo.CurrentInfo.CalendarWeekRule, | ||
726 | 223 | DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek); | ||
727 | 224 | line_layout.FontDescription.Weight = Pango.Weight.Bold; | ||
728 | 225 | line_layout.SetText (string.Format ("W{0:00}", woy)); | ||
729 | 226 | line_layout.GetPixelExtents (out inkRect, out logicalRect); | ||
730 | 227 | cr.MoveTo (offsetSize * 8, centerLine - logicalRect.Height); | ||
731 | 228 | |||
732 | 229 | Pango.CairoHelper.LayoutPath (cr, line_layout); | ||
733 | 230 | cr.Fill (); | ||
734 | 229 | } | 231 | } |
735 | 230 | 232 | ||
736 | 231 | protected override void OnShown () | 233 | protected override void OnShown () |
737 | 232 | 234 | ||
738 | === modified file 'StandardPlugins/Clock/src/ClockDockItem.cs' | |||
739 | --- StandardPlugins/Clock/src/ClockDockItem.cs 2010-11-21 22:19:54 +0000 | |||
740 | +++ StandardPlugins/Clock/src/ClockDockItem.cs 2011-01-03 11:34:09 +0000 | |||
741 | @@ -141,6 +141,20 @@ | |||
742 | 141 | } | 141 | } |
743 | 142 | } | 142 | } |
744 | 143 | 143 | ||
745 | 144 | static Pango.Layout layout; | ||
746 | 145 | |||
747 | 146 | static ClockDockItem () | ||
748 | 147 | { | ||
749 | 148 | Gtk.Style style = new Gtk.Style (); | ||
750 | 149 | |||
751 | 150 | layout = DockServices.Drawing.ThemedPangoLayout (); | ||
752 | 151 | layout.FontDescription = style.FontDescription; | ||
753 | 152 | layout.FontDescription.Weight = Pango.Weight.Bold; | ||
754 | 153 | layout.Ellipsize = Pango.EllipsizeMode.None; | ||
755 | 154 | |||
756 | 155 | style.Dispose (); | ||
757 | 156 | } | ||
758 | 157 | |||
759 | 144 | public ClockDockItem () | 158 | public ClockDockItem () |
760 | 145 | { | 159 | { |
761 | 146 | ScalableRendering = !ShowDigital; | 160 | ScalableRendering = !ShowDigital; |
762 | @@ -215,78 +229,69 @@ | |||
763 | 215 | int center = surface.Height / 2; | 229 | int center = surface.Height / 2; |
764 | 216 | 230 | ||
765 | 217 | // shared by all text | 231 | // shared by all text |
782 | 218 | using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) { | 232 | layout.Width = Pango.Units.FromPixels (surface.Width); |
783 | 219 | layout.FontDescription = new Gtk.Style().FontDescription; | 233 | |
784 | 220 | layout.FontDescription.Weight = Pango.Weight.Bold; | 234 | // draw the time, outlined |
785 | 221 | layout.Ellipsize = Pango.EllipsizeMode.None; | 235 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (timeSize); |
786 | 222 | layout.Width = Pango.Units.FromPixels (surface.Width); | 236 | |
787 | 223 | 237 | if (ShowMilitary) | |
788 | 224 | 238 | layout.SetText (DateTime.Now.ToString ("HH:mm")); | |
789 | 225 | // draw the time, outlined | 239 | else |
790 | 226 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (timeSize); | 240 | layout.SetText (DateTime.Now.ToString ("h:mm")); |
791 | 227 | 241 | ||
792 | 228 | if (ShowMilitary) | 242 | Pango.Rectangle inkRect, logicalRect; |
793 | 229 | layout.SetText (DateTime.Now.ToString ("HH:mm")); | 243 | layout.GetPixelExtents (out inkRect, out logicalRect); |
794 | 230 | else | 244 | |
795 | 231 | layout.SetText (DateTime.Now.ToString ("h:mm")); | 245 | int timeYOffset = ShowMilitary ? timeSize : timeSize / 2; |
796 | 232 | 246 | int timeXOffset = (surface.Width - inkRect.Width) / 2; | |
797 | 233 | Pango.Rectangle inkRect, logicalRect; | 247 | if (ShowDate) |
798 | 248 | cr.MoveTo (timeXOffset, timeYOffset); | ||
799 | 249 | else | ||
800 | 250 | cr.MoveTo (timeXOffset, timeYOffset + timeSize / 2); | ||
801 | 251 | |||
802 | 252 | Pango.CairoHelper.LayoutPath (cr, layout); | ||
803 | 253 | cr.LineWidth = 3; | ||
804 | 254 | cr.Color = new Cairo.Color (0, 0, 0, 0.5); | ||
805 | 255 | cr.StrokePreserve (); | ||
806 | 256 | cr.Color = new Cairo.Color (1, 1, 1, 0.8); | ||
807 | 257 | cr.Fill (); | ||
808 | 258 | |||
809 | 259 | // draw the date, outlined | ||
810 | 260 | if (ShowDate) { | ||
811 | 261 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (dateSize); | ||
812 | 262 | |||
813 | 263 | layout.SetText (DateTime.Now.ToString ("MMM dd")); | ||
814 | 234 | layout.GetPixelExtents (out inkRect, out logicalRect); | 264 | layout.GetPixelExtents (out inkRect, out logicalRect); |
822 | 235 | 265 | cr.MoveTo ((surface.Width - inkRect.Width) / 2, surface.Height - spacing - dateSize); | |
816 | 236 | int timeYOffset = ShowMilitary ? timeSize : timeSize / 2; | ||
817 | 237 | int timeXOffset = (surface.Width - inkRect.Width) / 2; | ||
818 | 238 | if (ShowDate) | ||
819 | 239 | cr.MoveTo (timeXOffset, timeYOffset); | ||
820 | 240 | else | ||
821 | 241 | cr.MoveTo (timeXOffset, timeYOffset + timeSize / 2); | ||
823 | 242 | 266 | ||
824 | 243 | Pango.CairoHelper.LayoutPath (cr, layout); | 267 | Pango.CairoHelper.LayoutPath (cr, layout); |
826 | 244 | cr.LineWidth = 3; | 268 | cr.LineWidth = 2.5; |
827 | 245 | cr.Color = new Cairo.Color (0, 0, 0, 0.5); | 269 | cr.Color = new Cairo.Color (0, 0, 0, 0.5); |
828 | 246 | cr.StrokePreserve (); | 270 | cr.StrokePreserve (); |
829 | 247 | cr.Color = new Cairo.Color (1, 1, 1, 0.8); | 271 | cr.Color = new Cairo.Color (1, 1, 1, 0.8); |
830 | 248 | cr.Fill (); | 272 | cr.Fill (); |
872 | 249 | 273 | } | |
873 | 250 | // draw the date, outlined | 274 | |
874 | 251 | if (ShowDate) { | 275 | if (!ShowMilitary) { |
875 | 252 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (dateSize); | 276 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (ampmSize); |
876 | 253 | 277 | ||
877 | 254 | layout.SetText (DateTime.Now.ToString ("MMM dd")); | 278 | int yOffset = ShowDate ? center - spacing : surface.Height - spacing - ampmSize; |
878 | 255 | layout.GetPixelExtents (out inkRect, out logicalRect); | 279 | |
879 | 256 | cr.MoveTo ((surface.Width - inkRect.Width) / 2, surface.Height - spacing - dateSize); | 280 | // draw AM indicator |
880 | 257 | 281 | layout.SetText ("am"); | |
881 | 258 | Pango.CairoHelper.LayoutPath (cr, layout); | 282 | cr.Color = new Cairo.Color (1, 1, 1, DateTime.Now.Hour < 12 ? 0.8 : 0.2); |
882 | 259 | cr.LineWidth = 2.5; | 283 | layout.GetPixelExtents (out inkRect, out logicalRect); |
883 | 260 | cr.Color = new Cairo.Color (0, 0, 0, 0.5); | 284 | cr.MoveTo ((center - inkRect.Width) / 2, yOffset); |
884 | 261 | cr.StrokePreserve (); | 285 | Pango.CairoHelper.LayoutPath (cr, layout); |
885 | 262 | cr.Color = new Cairo.Color (1, 1, 1, 0.8); | 286 | cr.Fill (); |
886 | 263 | cr.Fill (); | 287 | |
887 | 264 | } | 288 | // draw PM indicator |
888 | 265 | 289 | layout.SetText ("pm"); | |
889 | 266 | if (!ShowMilitary) { | 290 | cr.Color = new Cairo.Color (1, 1, 1, DateTime.Now.Hour > 11 ? 0.8 : 0.2); |
890 | 267 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (ampmSize); | 291 | layout.GetPixelExtents (out inkRect, out logicalRect); |
891 | 268 | 292 | cr.MoveTo (center + (center - inkRect.Width) / 2, yOffset); | |
892 | 269 | int yOffset = ShowDate ? center - spacing : surface.Height - spacing - ampmSize; | 293 | Pango.CairoHelper.LayoutPath (cr, layout); |
893 | 270 | 294 | cr.Fill (); | |
853 | 271 | // draw AM indicator | ||
854 | 272 | layout.SetText ("am"); | ||
855 | 273 | cr.Color = new Cairo.Color (1, 1, 1, DateTime.Now.Hour < 12 ? 0.8 : 0.2); | ||
856 | 274 | layout.GetPixelExtents (out inkRect, out logicalRect); | ||
857 | 275 | cr.MoveTo ((center - inkRect.Width) / 2, yOffset); | ||
858 | 276 | Pango.CairoHelper.LayoutPath (cr, layout); | ||
859 | 277 | cr.Fill (); | ||
860 | 278 | |||
861 | 279 | // draw PM indicator | ||
862 | 280 | layout.SetText ("pm"); | ||
863 | 281 | cr.Color = new Cairo.Color (1, 1, 1, DateTime.Now.Hour > 11 ? 0.8 : 0.2); | ||
864 | 282 | layout.GetPixelExtents (out inkRect, out logicalRect); | ||
865 | 283 | cr.MoveTo (center + (center - inkRect.Width) / 2, yOffset); | ||
866 | 284 | Pango.CairoHelper.LayoutPath (cr, layout); | ||
867 | 285 | cr.Fill (); | ||
868 | 286 | } | ||
869 | 287 | |||
870 | 288 | layout.FontDescription.Dispose (); | ||
871 | 289 | layout.Context.Dispose (); | ||
894 | 290 | } | 295 | } |
895 | 291 | } | 296 | } |
896 | 292 | 297 | ||
897 | @@ -301,72 +306,63 @@ | |||
898 | 301 | int spacing = timeSize / 2; | 306 | int spacing = timeSize / 2; |
899 | 302 | 307 | ||
900 | 303 | // shared by all text | 308 | // shared by all text |
913 | 304 | using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) { | 309 | layout.Width = Pango.Units.FromPixels (surface.Width); |
914 | 305 | layout.FontDescription = new Gtk.Style().FontDescription; | 310 | |
915 | 306 | layout.FontDescription.Weight = Pango.Weight.Bold; | 311 | // draw the time, outlined |
916 | 307 | layout.Ellipsize = Pango.EllipsizeMode.None; | 312 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (timeSize); |
917 | 308 | layout.Width = Pango.Units.FromPixels (surface.Width); | 313 | |
918 | 309 | 314 | if (ShowMilitary) | |
919 | 310 | 315 | layout.SetText (DateTime.Now.ToString ("HH:mm")); | |
920 | 311 | // draw the time, outlined | 316 | else |
921 | 312 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (timeSize); | 317 | layout.SetText (DateTime.Now.ToString ("h:mm")); |
922 | 313 | 318 | ||
923 | 314 | if (ShowMilitary) | 319 | Pango.Rectangle inkRect, logicalRect; |
924 | 315 | layout.SetText (DateTime.Now.ToString ("HH:mm")); | 320 | layout.GetPixelExtents (out inkRect, out logicalRect); |
925 | 321 | |||
926 | 322 | int timeYOffset = timeSize / 2; | ||
927 | 323 | if (!ShowDate) | ||
928 | 324 | timeYOffset += timeSize / 2; | ||
929 | 325 | cr.MoveTo ((surface.Width - inkRect.Width) / 2, timeYOffset); | ||
930 | 326 | |||
931 | 327 | Pango.CairoHelper.LayoutPath (cr, layout); | ||
932 | 328 | cr.LineWidth = 2; | ||
933 | 329 | cr.Color = new Cairo.Color (0, 0, 0, 0.5); | ||
934 | 330 | cr.StrokePreserve (); | ||
935 | 331 | cr.Color = new Cairo.Color (1, 1, 1, 0.8); | ||
936 | 332 | cr.Fill (); | ||
937 | 333 | |||
938 | 334 | // draw the date, outlined | ||
939 | 335 | if (ShowDate) { | ||
940 | 336 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (dateSize); | ||
941 | 337 | |||
942 | 338 | layout.SetText (DateTime.Now.ToString ("MMM dd")); | ||
943 | 339 | layout.GetPixelExtents (out inkRect, out logicalRect); | ||
944 | 340 | cr.MoveTo ((surface.Width - inkRect.Width) / 2, surface.Height - spacing - dateSize); | ||
945 | 341 | |||
946 | 342 | Pango.CairoHelper.LayoutPath (cr, layout); | ||
947 | 343 | cr.Color = new Cairo.Color (0, 0, 0, 0.5); | ||
948 | 344 | cr.StrokePreserve (); | ||
949 | 345 | cr.Color = new Cairo.Color (1, 1, 1, 0.8); | ||
950 | 346 | cr.Fill (); | ||
951 | 347 | } | ||
952 | 348 | |||
953 | 349 | if (!ShowMilitary) { | ||
954 | 350 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (ampmSize); | ||
955 | 351 | |||
956 | 352 | if (DateTime.Now.Hour < 12) | ||
957 | 353 | layout.SetText ("am"); | ||
958 | 316 | else | 354 | else |
960 | 317 | layout.SetText (DateTime.Now.ToString ("h:mm")); | 355 | layout.SetText ("pm"); |
961 | 318 | 356 | ||
962 | 319 | Pango.Rectangle inkRect, logicalRect; | ||
963 | 320 | layout.GetPixelExtents (out inkRect, out logicalRect); | 357 | layout.GetPixelExtents (out inkRect, out logicalRect); |
966 | 321 | 358 | int yOffset = timeSize; | |
965 | 322 | int timeYOffset = timeSize / 2; | ||
967 | 323 | if (!ShowDate) | 359 | if (!ShowDate) |
970 | 324 | timeYOffset += timeSize / 2; | 360 | yOffset += timeSize / 2; |
971 | 325 | cr.MoveTo ((surface.Width - inkRect.Width) / 2, timeYOffset); | 361 | cr.MoveTo (surface.Width - logicalRect.Width, yOffset - inkRect.Height); |
972 | 326 | 362 | ||
973 | 327 | Pango.CairoHelper.LayoutPath (cr, layout); | 363 | Pango.CairoHelper.LayoutPath (cr, layout); |
974 | 328 | cr.LineWidth = 2; | ||
975 | 329 | cr.Color = new Cairo.Color (0, 0, 0, 0.5); | ||
976 | 330 | cr.StrokePreserve (); | ||
977 | 331 | cr.Color = new Cairo.Color (1, 1, 1, 0.8); | 364 | cr.Color = new Cairo.Color (1, 1, 1, 0.8); |
978 | 332 | cr.Fill (); | 365 | cr.Fill (); |
979 | 333 | |||
980 | 334 | // draw the date, outlined | ||
981 | 335 | if (ShowDate) { | ||
982 | 336 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (dateSize); | ||
983 | 337 | |||
984 | 338 | layout.SetText (DateTime.Now.ToString ("MMM dd")); | ||
985 | 339 | layout.GetPixelExtents (out inkRect, out logicalRect); | ||
986 | 340 | cr.MoveTo ((surface.Width - inkRect.Width) / 2, surface.Height - spacing - dateSize); | ||
987 | 341 | |||
988 | 342 | Pango.CairoHelper.LayoutPath (cr, layout); | ||
989 | 343 | cr.Color = new Cairo.Color (0, 0, 0, 0.5); | ||
990 | 344 | cr.StrokePreserve (); | ||
991 | 345 | cr.Color = new Cairo.Color (1, 1, 1, 0.8); | ||
992 | 346 | cr.Fill (); | ||
993 | 347 | } | ||
994 | 348 | |||
995 | 349 | if (!ShowMilitary) { | ||
996 | 350 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (ampmSize); | ||
997 | 351 | |||
998 | 352 | if (DateTime.Now.Hour < 12) | ||
999 | 353 | layout.SetText ("am"); | ||
1000 | 354 | else | ||
1001 | 355 | layout.SetText ("pm"); | ||
1002 | 356 | |||
1003 | 357 | layout.GetPixelExtents (out inkRect, out logicalRect); | ||
1004 | 358 | int yOffset = timeSize; | ||
1005 | 359 | if (!ShowDate) | ||
1006 | 360 | yOffset += timeSize / 2; | ||
1007 | 361 | cr.MoveTo (surface.Width - logicalRect.Width, yOffset - inkRect.Height); | ||
1008 | 362 | |||
1009 | 363 | Pango.CairoHelper.LayoutPath (cr, layout); | ||
1010 | 364 | cr.Color = new Cairo.Color (1, 1, 1, 0.8); | ||
1011 | 365 | cr.Fill (); | ||
1012 | 366 | } | ||
1013 | 367 | |||
1014 | 368 | layout.FontDescription.Dispose (); | ||
1015 | 369 | layout.Context.Dispose (); | ||
1016 | 370 | } | 366 | } |
1017 | 371 | } | 367 | } |
1018 | 372 | 368 | ||
1019 | 373 | 369 | ||
1020 | === modified file 'StandardPlugins/Weather/src/WeatherDocklet.cs' | |||
1021 | --- StandardPlugins/Weather/src/WeatherDocklet.cs 2010-11-21 22:19:54 +0000 | |||
1022 | +++ StandardPlugins/Weather/src/WeatherDocklet.cs 2011-01-03 11:34:09 +0000 | |||
1023 | @@ -62,6 +62,20 @@ | |||
1024 | 62 | 62 | ||
1025 | 63 | ConfigDialog Config; | 63 | ConfigDialog Config; |
1026 | 64 | 64 | ||
1027 | 65 | static Pango.Layout layout; | ||
1028 | 66 | |||
1029 | 67 | static WeatherDocklet () | ||
1030 | 68 | { | ||
1031 | 69 | Gtk.Style style = new Gtk.Style (); | ||
1032 | 70 | |||
1033 | 71 | layout = DockServices.Drawing.ThemedPangoLayout (); | ||
1034 | 72 | layout.FontDescription = style.FontDescription; | ||
1035 | 73 | layout.FontDescription.Weight = Pango.Weight.Bold; | ||
1036 | 74 | layout.Ellipsize = Pango.EllipsizeMode.None; | ||
1037 | 75 | |||
1038 | 76 | style.Dispose (); | ||
1039 | 77 | } | ||
1040 | 78 | |||
1041 | 65 | /// <summary> | 79 | /// <summary> |
1042 | 66 | /// Creates a new weather docklet. | 80 | /// Creates a new weather docklet. |
1043 | 67 | /// </summary> | 81 | /// </summary> |
1044 | @@ -154,35 +168,25 @@ | |||
1045 | 154 | int size = Math.Min (surface.Width, surface.Height); | 168 | int size = Math.Min (surface.Width, surface.Height); |
1046 | 155 | Context cr = surface.Context; | 169 | Context cr = surface.Context; |
1047 | 156 | 170 | ||
1077 | 157 | using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) | 171 | Pango.Rectangle inkRect, logicalRect; |
1078 | 158 | { | 172 | |
1079 | 159 | layout.FontDescription = new Gtk.Style().FontDescription; | 173 | layout.Width = Pango.Units.FromPixels (size); |
1080 | 160 | layout.FontDescription.Weight = Pango.Weight.Bold; | 174 | layout.SetText (WeatherController.Weather.Temp + AbstractWeatherSource.TempUnit); |
1081 | 161 | layout.Ellipsize = Pango.EllipsizeMode.None; | 175 | if (IsSmall) |
1082 | 162 | 176 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (size / 2.5)); | |
1083 | 163 | Pango.Rectangle inkRect, logicalRect; | 177 | else |
1084 | 164 | 178 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (size / 3.5)); | |
1085 | 165 | layout.Width = Pango.Units.FromPixels (size); | 179 | |
1086 | 166 | layout.SetText (WeatherController.Weather.Temp + AbstractWeatherSource.TempUnit); | 180 | layout.GetPixelExtents (out inkRect, out logicalRect); |
1087 | 167 | if (IsSmall) | 181 | cr.MoveTo ((size - inkRect.Width) / 2, size - logicalRect.Height); |
1088 | 168 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (size / 2.5)); | 182 | |
1089 | 169 | else | 183 | Pango.CairoHelper.LayoutPath (cr, layout); |
1090 | 170 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (size / 3.5)); | 184 | cr.LineWidth = 2; |
1091 | 171 | 185 | cr.Color = new Cairo.Color (0, 0, 0, 0.8); | |
1092 | 172 | layout.GetPixelExtents (out inkRect, out logicalRect); | 186 | cr.StrokePreserve (); |
1093 | 173 | cr.MoveTo ((size - inkRect.Width) / 2, size - logicalRect.Height); | 187 | |
1094 | 174 | 188 | cr.Color = new Cairo.Color (1, 1, 1, 0.8); | |
1095 | 175 | Pango.CairoHelper.LayoutPath (cr, layout); | 189 | cr.Fill (); |
1067 | 176 | cr.LineWidth = 2; | ||
1068 | 177 | cr.Color = new Cairo.Color (0, 0, 0, 0.8); | ||
1069 | 178 | cr.StrokePreserve (); | ||
1070 | 179 | |||
1071 | 180 | cr.Color = new Cairo.Color (1, 1, 1, 0.8); | ||
1072 | 181 | cr.Fill (); | ||
1073 | 182 | |||
1074 | 183 | layout.FontDescription.Dispose (); | ||
1075 | 184 | layout.Context.Dispose (); | ||
1076 | 185 | } | ||
1096 | 186 | } | 190 | } |
1097 | 187 | 191 | ||
1098 | 188 | protected override Gdk.Pixbuf ProcessPixbuf (Gdk.Pixbuf pbuf) | 192 | protected override Gdk.Pixbuf ProcessPixbuf (Gdk.Pixbuf pbuf) |
1099 | 189 | 193 | ||
1100 | === modified file 'StandardPlugins/Weather/src/WeatherPainter.cs' | |||
1101 | --- StandardPlugins/Weather/src/WeatherPainter.cs 2010-06-24 11:45:49 +0000 | |||
1102 | +++ StandardPlugins/Weather/src/WeatherPainter.cs 2011-01-03 11:34:09 +0000 | |||
1103 | @@ -49,6 +49,20 @@ | |||
1104 | 49 | /// </value> | 49 | /// </value> |
1105 | 50 | static readonly Cairo.Color colorLow = new Cairo.Color (0.427, 0.714, 0.945, 1); | 50 | static readonly Cairo.Color colorLow = new Cairo.Color (0.427, 0.714, 0.945, 1); |
1106 | 51 | 51 | ||
1107 | 52 | static Pango.Layout layout; | ||
1108 | 53 | |||
1109 | 54 | static WeatherPainter () | ||
1110 | 55 | { | ||
1111 | 56 | Gtk.Style style = new Gtk.Style (); | ||
1112 | 57 | |||
1113 | 58 | layout = DockServices.Drawing.ThemedPangoLayout (); | ||
1114 | 59 | layout.FontDescription = style.FontDescription; | ||
1115 | 60 | layout.FontDescription.Weight = Pango.Weight.Bold; | ||
1116 | 61 | layout.Ellipsize = Pango.EllipsizeMode.None; | ||
1117 | 62 | |||
1118 | 63 | style.Dispose (); | ||
1119 | 64 | } | ||
1120 | 65 | |||
1121 | 52 | /// <summary> | 66 | /// <summary> |
1122 | 53 | /// Creates a new weather painter object. | 67 | /// Creates a new weather painter object. |
1123 | 54 | /// </summary> | 68 | /// </summary> |
1124 | @@ -102,68 +116,60 @@ | |||
1125 | 102 | int xOffset = BUTTON_SIZE; | 116 | int xOffset = BUTTON_SIZE; |
1126 | 103 | int cellWidth = (Allocation.Width - 2 * BUTTON_SIZE) / (WeatherController.Weather.ForecastDays * 2); | 117 | int cellWidth = (Allocation.Width - 2 * BUTTON_SIZE) / (WeatherController.Weather.ForecastDays * 2); |
1127 | 104 | 118 | ||
1190 | 105 | using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) { | 119 | Pango.Rectangle inkRect, logicalRect; |
1191 | 106 | Pango.Rectangle inkRect, logicalRect; | 120 | |
1192 | 107 | 121 | layout.Width = Pango.Units.FromPixels (cellWidth); | |
1193 | 108 | layout.FontDescription = new Gtk.Style().FontDescription; | 122 | |
1194 | 109 | layout.FontDescription.Weight = Pango.Weight.Bold; | 123 | for (int day = 0; day < WeatherController.Weather.ForecastDays; day++) |
1195 | 110 | layout.Ellipsize = Pango.EllipsizeMode.None; | 124 | { |
1196 | 111 | layout.Width = Pango.Units.FromPixels (cellWidth); | 125 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (cellWidth / 5)); |
1197 | 112 | 126 | ||
1198 | 113 | for (int day = 0; day < WeatherController.Weather.ForecastDays; day++) | 127 | cr.Color = colorTitle; |
1199 | 114 | { | 128 | layout.SetText (string.Format ("{0}", WeatherForecast.DayShortName (WeatherController.Weather.Forecasts [day].dow))); |
1200 | 115 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (cellWidth / 5)); | 129 | layout.GetPixelExtents (out inkRect, out logicalRect); |
1201 | 116 | 130 | cr.MoveTo (xOffset + (cellWidth - inkRect.Width) / 2, 0); | |
1202 | 117 | cr.Color = colorTitle; | 131 | Pango.CairoHelper.LayoutPath (cr, layout); |
1203 | 118 | layout.SetText (string.Format ("{0}", WeatherForecast.DayShortName (WeatherController.Weather.Forecasts [day].dow))); | 132 | cr.Fill (); |
1204 | 119 | layout.GetPixelExtents (out inkRect, out logicalRect); | 133 | |
1205 | 120 | cr.MoveTo (xOffset + (cellWidth - inkRect.Width) / 2, 0); | 134 | cr.Color = colorHigh; |
1206 | 121 | Pango.CairoHelper.LayoutPath (cr, layout); | 135 | layout.SetText (string.Format ("{0}{1}", WeatherController.Weather.Forecasts [day].high, AbstractWeatherSource.TempUnit)); |
1207 | 122 | cr.Fill (); | 136 | layout.GetPixelExtents (out inkRect, out logicalRect); |
1208 | 123 | 137 | cr.MoveTo (xOffset + (cellWidth - inkRect.Width) / 2, Allocation.Height / 2 - logicalRect.Height / 2); | |
1209 | 124 | cr.Color = colorHigh; | 138 | Pango.CairoHelper.LayoutPath (cr, layout); |
1210 | 125 | layout.SetText (string.Format ("{0}{1}", WeatherController.Weather.Forecasts [day].high, AbstractWeatherSource.TempUnit)); | 139 | cr.Fill (); |
1211 | 126 | layout.GetPixelExtents (out inkRect, out logicalRect); | 140 | |
1212 | 127 | cr.MoveTo (xOffset + (cellWidth - inkRect.Width) / 2, Allocation.Height / 2 - logicalRect.Height / 2); | 141 | cr.Color = colorLow; |
1213 | 128 | Pango.CairoHelper.LayoutPath (cr, layout); | 142 | layout.SetText (string.Format ("{0}{1}", WeatherController.Weather.Forecasts [day].low, AbstractWeatherSource.TempUnit)); |
1214 | 129 | cr.Fill (); | 143 | layout.GetPixelExtents (out inkRect, out logicalRect); |
1215 | 130 | 144 | cr.MoveTo (xOffset + (cellWidth - inkRect.Width) / 2, Allocation.Height - logicalRect.Height); | |
1216 | 131 | cr.Color = colorLow; | 145 | Pango.CairoHelper.LayoutPath (cr, layout); |
1217 | 132 | layout.SetText (string.Format ("{0}{1}", WeatherController.Weather.Forecasts [day].low, AbstractWeatherSource.TempUnit)); | 146 | cr.Fill (); |
1218 | 133 | layout.GetPixelExtents (out inkRect, out logicalRect); | 147 | |
1219 | 134 | cr.MoveTo (xOffset + (cellWidth - inkRect.Width) / 2, Allocation.Height - logicalRect.Height); | 148 | using (Gdk.Pixbuf pbuf = DockServices.Drawing.LoadIcon (WeatherController.Weather.Forecasts [day].image, cellWidth - 5)) |
1220 | 135 | Pango.CairoHelper.LayoutPath (cr, layout); | 149 | { |
1221 | 136 | cr.Fill (); | 150 | Gdk.CairoHelper.SetSourcePixbuf (cr, pbuf, xOffset + cellWidth + 2, 5 + (Allocation.Height - cellWidth) / 2); |
1222 | 137 | 151 | cr.PaintWithAlpha (WeatherController.Weather.Forecasts [day].chanceOf ? .6 : 1); | |
1223 | 138 | using (Gdk.Pixbuf pbuf = DockServices.Drawing.LoadIcon (WeatherController.Weather.Forecasts [day].image, cellWidth - 5)) | 152 | } |
1224 | 139 | { | 153 | |
1225 | 140 | Gdk.CairoHelper.SetSourcePixbuf (cr, pbuf, xOffset + cellWidth + 2, 5 + (Allocation.Height - cellWidth) / 2); | 154 | if (WeatherController.Weather.Forecasts [day].chanceOf) |
1226 | 141 | cr.PaintWithAlpha (WeatherController.Weather.Forecasts [day].chanceOf ? .6 : 1); | 155 | { |
1227 | 142 | } | 156 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (cellWidth / 2)); |
1228 | 143 | 157 | ||
1229 | 144 | if (WeatherController.Weather.Forecasts [day].chanceOf) | 158 | layout.SetText ("?"); |
1230 | 145 | { | 159 | |
1231 | 146 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (cellWidth / 2)); | 160 | layout.GetPixelExtents (out inkRect, out logicalRect); |
1232 | 147 | 161 | cr.MoveTo (xOffset + cellWidth + (cellWidth - inkRect.Width) / 2, Allocation.Height / 2 - logicalRect.Height / 2); | |
1233 | 148 | layout.SetText ("?"); | 162 | |
1234 | 149 | 163 | cr.LineWidth = 4; | |
1235 | 150 | layout.GetPixelExtents (out inkRect, out logicalRect); | 164 | cr.Color = new Cairo.Color (0, 0, 0, 0.3); |
1236 | 151 | cr.MoveTo (xOffset + cellWidth + (cellWidth - inkRect.Width) / 2, Allocation.Height / 2 - logicalRect.Height / 2); | 165 | Pango.CairoHelper.LayoutPath (cr, layout); |
1237 | 152 | 166 | cr.StrokePreserve (); | |
1238 | 153 | cr.LineWidth = 4; | 167 | |
1239 | 154 | cr.Color = new Cairo.Color (0, 0, 0, 0.3); | 168 | cr.Color = new Cairo.Color (1, 1, 1, .6); |
1240 | 155 | Pango.CairoHelper.LayoutPath (cr, layout); | 169 | cr.Fill (); |
1241 | 156 | cr.StrokePreserve (); | 170 | } |
1242 | 157 | 171 | ||
1243 | 158 | cr.Color = new Cairo.Color (1, 1, 1, .6); | 172 | xOffset += 2 * cellWidth; |
1182 | 159 | cr.Fill (); | ||
1183 | 160 | } | ||
1184 | 161 | |||
1185 | 162 | xOffset += 2 * cellWidth; | ||
1186 | 163 | } | ||
1187 | 164 | |||
1188 | 165 | layout.FontDescription.Dispose (); | ||
1189 | 166 | layout.Context.Dispose (); | ||
1244 | 167 | } | 173 | } |
1245 | 168 | } | 174 | } |
1246 | 169 | 175 | ||
1247 | @@ -192,47 +198,39 @@ | |||
1248 | 192 | if (max <= min) | 198 | if (max <= min) |
1249 | 193 | return; | 199 | return; |
1250 | 194 | 200 | ||
1291 | 195 | using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) { | 201 | Pango.Rectangle inkRect, logicalRect; |
1292 | 196 | Pango.Rectangle inkRect, logicalRect; | 202 | |
1293 | 197 | 203 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (Allocation.Height / 5)); | |
1294 | 198 | layout.FontDescription = new Gtk.Style().FontDescription; | 204 | |
1295 | 199 | layout.FontDescription.Weight = Pango.Weight.Bold; | 205 | // high/low temp |
1296 | 200 | layout.Ellipsize = Pango.EllipsizeMode.None; | 206 | layout.Width = Pango.Units.FromPixels (Allocation.Height); |
1297 | 201 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (Allocation.Height / 5)); | 207 | cr.Color = colorHigh; |
1298 | 202 | 208 | layout.SetText (string.Format ("{0}{1}", max, AbstractWeatherSource.TempUnit)); | |
1299 | 203 | // high/low temp | 209 | layout.GetPixelExtents (out inkRect, out logicalRect); |
1300 | 204 | layout.Width = Pango.Units.FromPixels (Allocation.Height); | 210 | cr.MoveTo (Allocation.Width - Allocation.Height + (Allocation.Height - inkRect.Width) / 2 - BUTTON_SIZE, Allocation.Height / 6 - logicalRect.Height / 2); |
1301 | 205 | cr.Color = colorHigh; | 211 | Pango.CairoHelper.LayoutPath (cr, layout); |
1302 | 206 | layout.SetText (string.Format ("{0}{1}", max, AbstractWeatherSource.TempUnit)); | 212 | cr.Fill (); |
1303 | 207 | layout.GetPixelExtents (out inkRect, out logicalRect); | 213 | |
1304 | 208 | cr.MoveTo (Allocation.Width - Allocation.Height + (Allocation.Height - inkRect.Width) / 2 - BUTTON_SIZE, Allocation.Height / 6 - logicalRect.Height / 2); | 214 | cr.Color = colorLow; |
1305 | 209 | Pango.CairoHelper.LayoutPath (cr, layout); | 215 | layout.SetText (string.Format ("{0}{1}", min, AbstractWeatherSource.TempUnit)); |
1306 | 210 | cr.Fill (); | 216 | layout.GetPixelExtents (out inkRect, out logicalRect); |
1307 | 211 | 217 | cr.MoveTo (Allocation.Width - Allocation.Height + (Allocation.Height - inkRect.Width) / 2 - BUTTON_SIZE, Allocation.Height * 6 / 9 - logicalRect.Height / 2); | |
1308 | 212 | cr.Color = colorLow; | 218 | Pango.CairoHelper.LayoutPath (cr, layout); |
1309 | 213 | layout.SetText (string.Format ("{0}{1}", min, AbstractWeatherSource.TempUnit)); | 219 | cr.Fill (); |
1310 | 214 | layout.GetPixelExtents (out inkRect, out logicalRect); | 220 | |
1311 | 215 | cr.MoveTo (Allocation.Width - Allocation.Height + (Allocation.Height - inkRect.Width) / 2 - BUTTON_SIZE, Allocation.Height * 6 / 9 - logicalRect.Height / 2); | 221 | // day names |
1312 | 216 | Pango.CairoHelper.LayoutPath (cr, layout); | 222 | layout.Width = Pango.Units.FromPixels (2 * Allocation.Height); |
1313 | 217 | cr.Fill (); | 223 | |
1314 | 218 | 224 | cr.Color = colorTitle; | |
1315 | 219 | // day names | 225 | for (int day = 0; day < WeatherController.Weather.ForecastDays; day++) |
1316 | 220 | layout.Width = Pango.Units.FromPixels (2 * Allocation.Height); | 226 | { |
1317 | 221 | 227 | layout.SetText (WeatherForecast.DayShortName (WeatherController.Weather.Forecasts [day].dow)); | |
1318 | 222 | cr.Color = colorTitle; | 228 | layout.GetPixelExtents (out inkRect, out logicalRect); |
1319 | 223 | for (int day = 0; day < WeatherController.Weather.ForecastDays; day++) | 229 | cr.MoveTo (BUTTON_SIZE + day * Allocation.Height * 2 + (Allocation.Height - inkRect.Width) / 2, Allocation.Height * 8 / 9 - logicalRect.Height / 2); |
1320 | 224 | { | 230 | Pango.CairoHelper.LayoutPath (cr, layout); |
1281 | 225 | layout.SetText (WeatherForecast.DayShortName (WeatherController.Weather.Forecasts [day].dow)); | ||
1282 | 226 | layout.GetPixelExtents (out inkRect, out logicalRect); | ||
1283 | 227 | cr.MoveTo (BUTTON_SIZE + day * Allocation.Height * 2 + (Allocation.Height - inkRect.Width) / 2, Allocation.Height * 8 / 9 - logicalRect.Height / 2); | ||
1284 | 228 | Pango.CairoHelper.LayoutPath (cr, layout); | ||
1285 | 229 | } | ||
1286 | 230 | cr.Fill (); | ||
1287 | 231 | cr.Save (); | ||
1288 | 232 | |||
1289 | 233 | layout.FontDescription.Dispose (); | ||
1290 | 234 | layout.Context.Dispose (); | ||
1321 | 235 | } | 231 | } |
1322 | 232 | cr.Fill (); | ||
1323 | 233 | cr.Save (); | ||
1324 | 236 | 234 | ||
1325 | 237 | // draw tick lines | 235 | // draw tick lines |
1326 | 238 | cr.Color = new Cairo.Color (0.627, 0.627, 0.627, .8); | 236 | cr.Color = new Cairo.Color (0.627, 0.627, 0.627, .8); |
1327 | @@ -359,29 +357,21 @@ | |||
1328 | 359 | 357 | ||
1329 | 360 | void DrawConditionText (Cairo.Context cr, int x, int xWidth, int yCenter, string text) | 358 | void DrawConditionText (Cairo.Context cr, int x, int xWidth, int yCenter, string text) |
1330 | 361 | { | 359 | { |
1354 | 362 | using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) { | 360 | Pango.Rectangle inkRect, logicalRect; |
1355 | 363 | Pango.Rectangle inkRect, logicalRect; | 361 | |
1356 | 364 | 362 | layout.Width = Pango.Units.FromPixels (Allocation.Width - BUTTON_SIZE - x); | |
1357 | 365 | layout.FontDescription = new Gtk.Style().FontDescription; | 363 | |
1358 | 366 | layout.FontDescription.Weight = Pango.Weight.Bold; | 364 | if (WeatherController.Weather.ForecastDays < 6) |
1359 | 367 | layout.Ellipsize = Pango.EllipsizeMode.None; | 365 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (Allocation.Height / 5)); |
1360 | 368 | layout.Width = Pango.Units.FromPixels (Allocation.Width - BUTTON_SIZE - x); | 366 | else |
1361 | 369 | 367 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (Allocation.Height / 3.5)); | |
1362 | 370 | if (WeatherController.Weather.ForecastDays < 6) | 368 | |
1363 | 371 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (Allocation.Height / 5)); | 369 | cr.Color = new Cairo.Color (1, 1, 1, 0.9); |
1364 | 372 | else | 370 | layout.SetText (text); |
1365 | 373 | layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (Allocation.Height / 3.5)); | 371 | layout.GetPixelExtents (out inkRect, out logicalRect); |
1366 | 374 | 372 | cr.MoveTo (x + (xWidth - logicalRect.Width) / 2, yCenter - logicalRect.Height / 2); | |
1367 | 375 | cr.Color = new Cairo.Color (1, 1, 1, 0.9); | 373 | Pango.CairoHelper.LayoutPath (cr, layout); |
1368 | 376 | layout.SetText (text); | 374 | cr.Fill (); |
1346 | 377 | layout.GetPixelExtents (out inkRect, out logicalRect); | ||
1347 | 378 | cr.MoveTo (x + (xWidth - logicalRect.Width) / 2, yCenter - logicalRect.Height / 2); | ||
1348 | 379 | Pango.CairoHelper.LayoutPath (cr, layout); | ||
1349 | 380 | cr.Fill (); | ||
1350 | 381 | |||
1351 | 382 | layout.FontDescription.Dispose (); | ||
1352 | 383 | layout.Context.Dispose (); | ||
1353 | 384 | } | ||
1369 | 385 | } | 375 | } |
1370 | 386 | 376 | ||
1371 | 387 | /// <summary> | 377 | /// <summary> |
In CalendarPainter, you dont need 3 layouts. Look where you create them, 2 are the same.