Merge lp:~ricotz/docky/pangolayout into lp:docky

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
Reviewer Review Type Date Requested Status
Robert Dyer (community) Needs Fixing
Review via email: mp+37947@code.launchpad.net

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
Robert Dyer (psybers) wrote :

In CalendarPainter, you dont need 3 layouts. Look where you create them, 2 are the same.

review: Needs Fixing
Revision history for this message
Robert Dyer (psybers) wrote :

In ADI, you can lift the FontDescription stuff for hover_layout

review: Needs Fixing
Revision history for this message
Robert Dyer (psybers) wrote :

Same thing in DockWindow

review: Needs Fixing
Revision history for this message
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
=== modified file 'Docky.Items/Docky.Items/AbstractDockItem.cs'
--- Docky.Items/Docky.Items/AbstractDockItem.cs 2010-12-28 16:43:48 +0000
+++ Docky.Items/Docky.Items/AbstractDockItem.cs 2011-01-03 11:34:09 +0000
@@ -44,6 +44,35 @@
44 44
45 public abstract class AbstractDockItem : IDisposable45 public abstract class AbstractDockItem : IDisposable
46 {46 {
47 const int HoverTextFontSize = 11;
48
49 static Pango.Layout badge_layout;
50 static Pango.Layout hover_layout;
51 static Pango.Layout message_layout;
52
53 static AbstractDockItem ()
54 {
55 Gtk.Style style = new Gtk.Style ();
56
57 badge_layout = DockServices.Drawing.ThemedPangoLayout ();
58 badge_layout.Ellipsize = Pango.EllipsizeMode.None;
59 badge_layout.FontDescription = style.FontDescription;
60 badge_layout.FontDescription.Weight = Pango.Weight.Bold;
61
62 hover_layout = DockServices.Drawing.ThemedPangoLayout ();
63 hover_layout.Ellipsize = Pango.EllipsizeMode.End;
64 hover_layout.FontDescription = style.FontDescription;
65 hover_layout.FontDescription.Weight = Pango.Weight.Bold;
66 hover_layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (HoverTextFontSize);
67
68 message_layout = DockServices.Drawing.ThemedPangoLayout ();
69 message_layout.Ellipsize = Pango.EllipsizeMode.None;
70 message_layout.FontDescription = style.FontDescription;
71 message_layout.FontDescription.Weight = Pango.Weight.Normal;
72
73 style.Dispose ();
74 }
75
47 string hover_text, remote_text;76 string hover_text, remote_text;
48 string badge_text, remote_badge_text;77 string badge_text, remote_badge_text;
49 bool[] redraw;78 bool[] redraw;
@@ -696,29 +725,20 @@
696 }725 }
697 }726 }
698 727
699 using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ())728 message_layout.Width = Pango.Units.FromPixels (surface.Width - iconSize - 8);
700 {729 message_layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) slotHeight - 6);
701 layout.Width = Pango.Units.FromPixels (surface.Width - iconSize - 8);730 message_layout.SetText (message);
702 layout.Ellipsize = Pango.EllipsizeMode.None;731
703 layout.FontDescription = new Gtk.Style ().FontDescription;732 Pango.Rectangle inkRect, logicalRect;
704 layout.FontDescription.Weight = Pango.Weight.Normal;733 message_layout.GetPixelExtents (out inkRect, out logicalRect);
705 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) slotHeight - 6);734
706 layout.SetText (message);735 surface.Context.MoveTo (surface.Width - 4 - logicalRect.Width, yOffset + (slotHeight - 2 - logicalRect.Height) / 2);
707 736
708 Pango.Rectangle inkRect, logicalRect;737 Pango.CairoHelper.LayoutPath (surface.Context, message_layout);
709 layout.GetPixelExtents (out inkRect, out logicalRect);738 surface.Context.LineWidth = 2;
710 739 surface.Context.StrokePreserve ();
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);
712 741 surface.Context.Fill ();
713 Pango.CairoHelper.LayoutPath (surface.Context, layout);
714 surface.Context.LineWidth = 2;
715 surface.Context.StrokePreserve ();
716 surface.Context.Color = new Cairo.Color (1, 1, 1, 1);
717 surface.Context.Fill ();
718
719 layout.FontDescription.Dispose ();
720 layout.Context.Dispose ();
721 }
722 }742 }
723 743
724 void PaintProgressSurface (DockySurface surface)744 void PaintProgressSurface (DockySurface surface)
@@ -862,47 +882,38 @@
862 padding = 2;882 padding = 2;
863 }883 }
864 884
865 using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ())885 badge_layout.Width = Pango.Units.FromPixels (surface.Height / 2);
866 {886
867 layout.Width = Pango.Units.FromPixels (surface.Height / 2);887 Pango.Rectangle inkRect, logicalRect;
868 layout.Ellipsize = Pango.EllipsizeMode.None;888 badge_layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (surface.Height / 2);
869 layout.FontDescription = new Gtk.Style ().FontDescription;889 badge_layout.SetText (BadgeText);
870 layout.FontDescription.Weight = Pango.Weight.Bold;890 badge_layout.GetPixelExtents (out inkRect, out logicalRect);
871 891
872 Pango.Rectangle inkRect, logicalRect;892 size -= 2 * padding + 2 * lineWidth;
873 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (surface.Height / 2);893
874 layout.SetText (BadgeText);894 double scale = Math.Min (1, Math.Min (size / (double) logicalRect.Width, size / (double) logicalRect.Height));
875 layout.GetPixelExtents (out inkRect, out logicalRect);895
876 896 if (!IsSmall) {
877 size -= 2 * padding + 2 * lineWidth;897 surface.Context.Color = new Cairo.Color (0, 0, 0, 0.2);
878 898 } else {
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);
880 900 x = surface.Width - scale * logicalRect.Width / 2;
881 if (!IsSmall) {901 y = scale * logicalRect.Height / 2;
882 surface.Context.Color = new Cairo.Color (0, 0, 0, 0.2);
883 } else {
884 surface.Context.Color = new Cairo.Color (0, 0, 0, 0.6);
885 x = surface.Width - scale * logicalRect.Width / 2;
886 y = scale * logicalRect.Height / 2;
887 }
888
889 surface.Context.MoveTo (x - scale * logicalRect.Width / 2, y - scale * logicalRect.Height / 2);
890
891 // draw text
892 surface.Context.Save ();
893 if (scale < 1)
894 surface.Context.Scale (scale, scale);
895
896 surface.Context.LineWidth = 2;
897 Pango.CairoHelper.LayoutPath (surface.Context, layout);
898 surface.Context.StrokePreserve ();
899 surface.Context.Color = new Cairo.Color (1, 1, 1, 1);
900 surface.Context.Fill ();
901 surface.Context.Restore ();
902
903 layout.FontDescription.Dispose ();
904 layout.Context.Dispose ();
905 }902 }
903
904 surface.Context.MoveTo (x - scale * logicalRect.Width / 2, y - scale * logicalRect.Height / 2);
905
906 // draw text
907 surface.Context.Save ();
908 if (scale < 1)
909 surface.Context.Scale (scale, scale);
910
911 surface.Context.LineWidth = 2;
912 Pango.CairoHelper.LayoutPath (surface.Context, badge_layout);
913 surface.Context.StrokePreserve ();
914 surface.Context.Color = new Cairo.Color (1, 1, 1, 1);
915 surface.Context.Fill ();
916 surface.Context.Restore ();
906 }917 }
907 918
908 /// <summary>919 /// <summary>
@@ -923,35 +934,26 @@
923 return null;934 return null;
924 935
925 if (text_buffer == null) {936 if (text_buffer == null) {
926 using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) {937 hover_layout.SetText (HoverText);
927 layout.FontDescription = style.FontDescription;938
928 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (11);939 Pango.Rectangle inkRect, logicalRect;
929 layout.FontDescription.Weight = Pango.Weight.Bold;940 hover_layout.GetPixelExtents (out inkRect, out logicalRect);
930 layout.Ellipsize = Pango.EllipsizeMode.End;941 if (logicalRect.Width > 0.8 * Gdk.Screen.Default.Width) {
931 942 hover_layout.Width = Pango.Units.FromPixels ((int) (0.8 * Gdk.Screen.Default.Width));
932 layout.SetText (HoverText);943 hover_layout.GetPixelExtents (out inkRect, out logicalRect);
933
934 Pango.Rectangle inkRect, logicalRect;
935 layout.GetPixelExtents (out inkRect, out logicalRect);
936 if (logicalRect.Width > 0.8 * Gdk.Screen.Default.Width) {
937 layout.Width = Pango.Units.FromPixels ((int) (0.8 * Gdk.Screen.Default.Width));
938 layout.GetPixelExtents (out inkRect, out logicalRect);
939 }
940
941 int textWidth = logicalRect.Width;
942 int textHeight = logicalRect.Height;
943 int buffer = HoverTextHeight - textHeight;
944 text_buffer = new DockySurface (Math.Max (HoverTextHeight, textWidth + buffer), HoverTextHeight, model);
945
946 Cairo.Context cr = text_buffer.Context;
947
948 cr.MoveTo (buffer / 2, buffer / 2);
949 Pango.CairoHelper.LayoutPath (cr, layout);
950 cr.Color = isLight ? new Cairo.Color (0.1, 0.1, 0.1) : new Cairo.Color (1, 1, 1);
951 cr.Fill ();
952
953 layout.Context.Dispose ();
954 }944 }
945
946 int textWidth = inkRect.Width;
947 int textHeight = logicalRect.Height;
948 int buffer = HoverTextHeight - textHeight;
949 text_buffer = new DockySurface (Math.Max (HoverTextHeight, textWidth + buffer), HoverTextHeight, model);
950
951 Cairo.Context cr = text_buffer.Context;
952
953 cr.MoveTo ((text_buffer.Width - textWidth) / 2, buffer / 2);
954 Pango.CairoHelper.LayoutPath (cr, hover_layout);
955 cr.Color = isLight ? new Cairo.Color (0.1, 0.1, 0.1) : new Cairo.Color (1, 1, 1);
956 cr.Fill ();
955 }957 }
956 958
957 return text_buffer;959 return text_buffer;
958960
=== modified file 'Docky.Items/Docky.Items/IconEmblem.cs'
--- Docky.Items/Docky.Items/IconEmblem.cs 2010-06-25 13:06:51 +0000
+++ Docky.Items/Docky.Items/IconEmblem.cs 2011-01-03 11:34:09 +0000
@@ -97,6 +97,7 @@
97 return;97 return;
98 }98 }
99 ForcePixbuf = info.LoadIcon ();99 ForcePixbuf = info.LoadIcon ();
100 info.Dispose ();
100 }101 }
101 102
102 public Pixbuf GetPixbuf (int parentWidth, int parentHeight) {103 public Pixbuf GetPixbuf (int parentWidth, int parentHeight) {
103104
=== modified file 'Docky/Docky/Interface/DockWindow.cs'
--- Docky/Docky/Interface/DockWindow.cs 2010-11-22 08:46:18 +0000
+++ Docky/Docky/Interface/DockWindow.cs 2011-01-03 11:34:09 +0000
@@ -135,7 +135,9 @@
135 const int NormalIndicatorSize = 20;135 const int NormalIndicatorSize = 20;
136 const int UrgentIndicatorSize = 26;136 const int UrgentIndicatorSize = 26;
137 const int GlowSize = 30;137 const int GlowSize = 30;
138 138 const int HoverTextHeight = 26;
139 const int HoverTextFontSize = 11;
140
139 const int WaitGroups = 3;141 const int WaitGroups = 3;
140 const int WaitArmsPerGroup = 8;142 const int WaitArmsPerGroup = 8;
141 143
@@ -338,31 +340,20 @@
338 340
339 DockySurface DrawHoverText (DockySurface surface, string text)341 DockySurface DrawHoverText (DockySurface surface, string text)
340 {342 {
341 using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) {343 hover_layout.SetText (text);
342 layout.FontDescription = Style.FontDescription;344
343 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (11);345 Pango.Rectangle inkRect, logicalRect;
344 layout.FontDescription.Weight = Pango.Weight.Bold;346 hover_layout.GetPixelExtents (out inkRect, out logicalRect);
345 layout.Ellipsize = Pango.EllipsizeMode.End;347
346 layout.Width = Pango.Units.FromPixels (500);348 int textWidth = inkRect.Width;
347 349 int textHeight = logicalRect.Height;
348 layout.SetText (text);350 int buffer = HoverTextHeight - textHeight;
349 351 surface = new DockySurface (Math.Max (HoverTextHeight, textWidth + buffer), HoverTextHeight, background_buffer);
350 Pango.Rectangle inkRect, logicalRect;352
351 layout.GetPixelExtents (out inkRect, out logicalRect);353 surface.Context.MoveTo ((surface.Width - textWidth) / 2, buffer / 2);
352 354 Pango.CairoHelper.LayoutPath (surface.Context, hover_layout);
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);
354 int textWidth = inkRect.Width;356 surface.Context.Fill ();
355 int textHeight = logicalRect.Height;
356 int buffer = HoverTextHeight - textHeight;
357 surface = new DockySurface (Math.Max (HoverTextHeight, textWidth + buffer), HoverTextHeight, background_buffer);
358
359 surface.Context.MoveTo ((surface.Width - textWidth) / 2, buffer / 2);
360 Pango.CairoHelper.LayoutPath (surface.Context, layout);
361 surface.Context.Color = HoverTextManager.IsLight ? new Cairo.Color (0.1, 0.1, 0.1) : new Cairo.Color (1, 1, 1);
362 surface.Context.Fill ();
363
364 layout.Context.Dispose ();
365 }
366 357
367 return surface;358 return surface;
368 }359 }
@@ -676,9 +667,21 @@
676667
677 #endregion668 #endregion
678 669
670 static Pango.Layout hover_layout;
671
679 static DockWindow ()672 static DockWindow ()
680 {673 {
681 DockyItem = new DockyItem ();674 DockyItem = new DockyItem ();
675
676 Gtk.Style style = new Gtk.Style ();
677
678 hover_layout = DockServices.Drawing.ThemedPangoLayout ();
679 hover_layout.Ellipsize = Pango.EllipsizeMode.End;
680 hover_layout.FontDescription = style.FontDescription;
681 hover_layout.FontDescription.Weight = Pango.Weight.Bold;
682 hover_layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (HoverTextFontSize);
683
684 style.Dispose ();
682 }685 }
683 686
684 public DockWindow () : base(Gtk.WindowType.Toplevel)687 public DockWindow () : base(Gtk.WindowType.Toplevel)
685688
=== modified file 'Docky/Docky/Menus/MenuItemWidget.cs'
--- Docky/Docky/Menus/MenuItemWidget.cs 2010-11-14 14:17:17 +0000
+++ Docky/Docky/Menus/MenuItemWidget.cs 2011-01-03 11:34:09 +0000
@@ -63,6 +63,21 @@
63 63
64 DockySurface icon_surface, emblem_surface;64 DockySurface icon_surface, emblem_surface;
65 65
66 static Pango.Layout layout;
67
68 static MenuItemWidget ()
69 {
70 Gtk.Style style = new Gtk.Style ();
71
72 layout = DockServices.Drawing.ThemedPangoLayout ();
73 layout.Ellipsize = Pango.EllipsizeMode.End;
74 layout.FontDescription = style.FontDescription;
75 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (FontSize);
76 layout.FontDescription.Weight = Pango.Weight.Bold;
77
78 style.Dispose ();
79 }
80
66 internal MenuItemWidget (MenuItem item) : base()81 internal MenuItemWidget (MenuItem item) : base()
67 {82 {
68 TextColor = new Cairo.Color (1, 1, 1);83 TextColor = new Cairo.Color (1, 1, 1);
@@ -91,26 +106,19 @@
91 106
92 void CalcTextWidth ()107 void CalcTextWidth ()
93 {108 {
94 using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) {109 char accel;
95 char accel;110
96 111 if (item.Mnemonic.HasValue)
97 if (item.Mnemonic.HasValue)112 layout.SetMarkupWithAccel (item.Text, '_', out accel);
98 layout.SetMarkupWithAccel (item.Text, '_', out accel);113 else
99 else114 layout.SetMarkup (item.Text);
100 layout.SetMarkup (item.Text);115
101 layout.FontDescription = Style.FontDescription;116 layout.Width = -1;
102 layout.Ellipsize = Pango.EllipsizeMode.End;117 Pango.Rectangle logical, ink;
103 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (FontSize);118 layout.GetPixelExtents (out ink, out logical);
104 layout.FontDescription.Weight = Pango.Weight.Bold;119
105 120 TextWidth = Math.Min (MaxWidth, Math.Max (MinWidth, logical.Width));
106 Pango.Rectangle logical, ink;121 HasTooltip = TextWidth < logical.Width;
107 layout.GetPixelExtents (out ink, out logical);
108
109 TextWidth = Math.Min (MaxWidth, Math.Max (MinWidth, logical.Width));
110 HasTooltip = TextWidth < logical.Width;
111
112 layout.Context.Dispose ();
113 }
114 122
115 SetSize ();123 SetSize ();
116 }124 }
@@ -265,31 +273,23 @@
265 }273 }
266 }274 }
267 275
268 using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) {276 char accel;
269 char accel;277 if (item.Mnemonic.HasValue)
270 if (item.Mnemonic.HasValue)278 layout.SetMarkupWithAccel (item.Text, '_', out accel);
271 layout.SetMarkupWithAccel (item.Text, '_', out accel);279 else
272 else280 layout.SetMarkup (item.Text);
273 layout.SetMarkup (item.Text);281 layout.Width = Pango.Units.FromPixels (TextWidth);
274 layout.Width = Pango.Units.FromPixels (TextWidth);282
275 layout.FontDescription = Style.FontDescription;283 Pango.Rectangle logical, ink;
276 layout.Ellipsize = Pango.EllipsizeMode.End;284 layout.GetPixelExtents (out ink, out logical);
277 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (FontSize);285
278 layout.FontDescription.Weight = Pango.Weight.Bold;286 int offset = Padding;
279 287 if (MenuShowingIcons)
280 Pango.Rectangle logical, ink;288 offset += MenuHeight + Padding;
281 layout.GetPixelExtents (out ink, out logical);289 cr.MoveTo (allocation.X + offset, allocation.Y + (allocation.Height - logical.Height) / 2);
282 290 Pango.CairoHelper.LayoutPath (cr, layout);
283 int offset = Padding;291 cr.Color = TextColor.SetAlpha (item.Disabled ? 0.5 : 1);
284 if (MenuShowingIcons)292 cr.Fill ();
285 offset += MenuHeight + Padding;
286 cr.MoveTo (allocation.X + offset, allocation.Y + (allocation.Height - logical.Height) / 2);
287 Pango.CairoHelper.LayoutPath (cr, layout);
288 cr.Color = TextColor.SetAlpha (item.Disabled ? 0.5 : 1);
289 cr.Fill ();
290
291 layout.Context.Dispose ();
292 }
293 293
294 (cr.Target as IDisposable).Dispose ();294 (cr.Target as IDisposable).Dispose ();
295 }295 }
296296
=== modified file 'Docky/Docky/Menus/SeparatorWidget.cs'
--- Docky/Docky/Menus/SeparatorWidget.cs 2010-10-15 15:32:36 +0000
+++ Docky/Docky/Menus/SeparatorWidget.cs 2011-01-03 11:34:09 +0000
@@ -28,12 +28,29 @@
28{28{
29 public class SeparatorWidget : EventBox29 public class SeparatorWidget : EventBox
30 {30 {
31 const int FontSize = 8;
32
31 string title;33 string title;
32 34
33 public Cairo.Color TextColor { get; set; }35 public Cairo.Color TextColor { get; set; }
34 36
35 public bool DrawLine { get; set; }37 public bool DrawLine { get; set; }
36 38
39 static Pango.Layout layout;
40
41 static SeparatorWidget ()
42 {
43 Gtk.Style style = new Gtk.Style ();
44
45 layout = DockServices.Drawing.ThemedPangoLayout ();
46 layout.Ellipsize = Pango.EllipsizeMode.End;
47 layout.FontDescription = style.FontDescription;
48 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (FontSize);
49 layout.FontDescription.Weight = Pango.Weight.Bold;
50
51 style.Dispose ();
52 }
53
37 public SeparatorWidget (string title)54 public SeparatorWidget (string title)
38 {55 {
39 this.title = title;56 this.title = title;
@@ -63,27 +80,20 @@
63 int xMiddle = x + width / 2;80 int xMiddle = x + width / 2;
64 double yMiddle = Allocation.Y + Allocation.Height / 2.0;81 double yMiddle = Allocation.Y + Allocation.Height / 2.0;
65 82
66 if (!string.IsNullOrEmpty (title))83 if (!string.IsNullOrEmpty (title)) {
67 using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) {84 layout.SetText (title);
68 layout.SetText (title);85 layout.Width = Pango.Units.FromPixels (Allocation.Width - Allocation.Height);
69 layout.Width = Pango.Units.FromPixels (Allocation.Width - Allocation.Height);86
70 layout.FontDescription = Style.FontDescription;87 Pango.Rectangle logical, ink;
71 layout.Ellipsize = Pango.EllipsizeMode.End;88 layout.GetPixelExtents (out ink, out logical);
72 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (8);89
73 layout.FontDescription.Weight = Pango.Weight.Bold;90 cr.MoveTo (Allocation.X + 2, Allocation.Y + (Allocation.Height - logical.Height) / 2);
74 91 Pango.CairoHelper.LayoutPath (cr, layout);
75 Pango.Rectangle logical, ink;92 cr.Color = TextColor.SetAlpha (.6);
76 layout.GetPixelExtents (out ink, out logical);93 cr.Fill ();
77 94
78 cr.MoveTo (Allocation.X + 2, Allocation.Y + (Allocation.Height - logical.Height) / 2);95 x += logical.Width + 5;
79 Pango.CairoHelper.LayoutPath (cr, layout);96 }
80 cr.Color = TextColor.SetAlpha (.6);
81 cr.Fill ();
82
83 x += logical.Width + 5;
84
85 layout.Context.Dispose ();
86 }
87 97
88 if (DrawLine) {98 if (DrawLine) {
89 cr.MoveTo (x, yMiddle);99 cr.MoveTo (x, yMiddle);
90100
=== modified file 'StandardPlugins/Clock/src/CalendarPainter.cs'
--- StandardPlugins/Clock/src/CalendarPainter.cs 2010-07-15 07:44:12 +0000
+++ StandardPlugins/Clock/src/CalendarPainter.cs 2011-01-03 11:34:09 +0000
@@ -42,6 +42,31 @@
42 }42 }
43 }43 }
44 44
45 static Pango.Layout header_layout;
46 static Pango.Layout line_layout;
47 static Pango.Layout month_layout;
48
49 static CalendarPainter ()
50 {
51 Gtk.Style style = new Gtk.Style ();
52
53 header_layout = DockServices.Drawing.ThemedPangoLayout ();
54 header_layout.FontDescription = style.FontDescription;
55 header_layout.FontDescription.Weight = Pango.Weight.Bold;
56 header_layout.Ellipsize = Pango.EllipsizeMode.None;
57
58 line_layout = DockServices.Drawing.ThemedPangoLayout ();
59 line_layout.FontDescription = style.FontDescription;
60 line_layout.Ellipsize = Pango.EllipsizeMode.None;
61
62 month_layout = DockServices.Drawing.ThemedPangoLayout ();
63 month_layout.FontDescription = style.FontDescription;
64 month_layout.FontDescription.Weight = Pango.Weight.Bold;
65 month_layout.Ellipsize = Pango.EllipsizeMode.None;
66
67 style.Dispose ();
68 }
69
45 public CalendarPainter () : base (3)70 public CalendarPainter () : base (3)
46 {71 {
47 StartDate = DateTime.Today.AddDays (1 - DateTime.Today.Day);72 StartDate = DateTime.Today.AddDays (1 - DateTime.Today.Day);
@@ -106,33 +131,25 @@
106 {131 {
107 string month = StartDate.ToString ("MMMM").ToUpper ();132 string month = StartDate.ToString ("MMMM").ToUpper ();
108 133
109 using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) {134 month_layout.Width = Pango.Units.FromPixels (Allocation.Height);
110 layout.FontDescription = new Gtk.Style().FontDescription;135 month_layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (Allocation.Height / 6);
111 layout.FontDescription.Weight = Pango.Weight.Bold;136
112 layout.Ellipsize = Pango.EllipsizeMode.None;137 cr.Save ();
113 layout.Width = Pango.Units.FromPixels (Allocation.Height);138 cr.Color = new Cairo.Color (1, 1, 1, .5);
114 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (Allocation.Height / 6);139 month_layout.SetText (month);
115 140
116 cr.Save ();141 Pango.Rectangle inkRect, logicalRect;
117 cr.Color = new Cairo.Color (1, 1, 1, .5);142 month_layout.GetPixelExtents (out inkRect, out logicalRect);
118 layout.SetText (month);143 double scale = Math.Min (1, Math.Min (Allocation.Height / (double) inkRect.Width, (Allocation.Width / 9.0) / (double) logicalRect.Height));
119 144
120 Pango.Rectangle inkRect, logicalRect;145 cr.Rotate (Math.PI / -2.0);
121 layout.GetPixelExtents (out inkRect, out logicalRect);146 cr.MoveTo ((Allocation.Height - scale * inkRect.Width) / 2 - Allocation.Height, Allocation.Width / 9 - scale * logicalRect.Height);
122 double scale = Math.Min (1, Math.Min (Allocation.Height / (double) inkRect.Width, (Allocation.Width / 9.0) / (double) logicalRect.Height));147 if (scale < 1)
123 148 cr.Scale (scale, scale);
124 cr.Rotate (Math.PI / -2.0);149
125 cr.MoveTo ((Allocation.Height - scale * inkRect.Width) / 2 - Allocation.Height, Allocation.Width / 9 - scale * logicalRect.Height);150 Pango.CairoHelper.LayoutPath (cr, month_layout);
126 if (scale < 1)151 cr.Fill ();
127 cr.Scale (scale, scale);152 cr.Restore ();
128
129 Pango.CairoHelper.LayoutPath (cr, layout);
130 cr.Fill ();
131 cr.Restore ();
132
133 layout.FontDescription.Dispose ();
134 layout.Context.Dispose ();
135 }
136 }153 }
137 154
138 void RenderHeader (Context cr, DateTime start)155 void RenderHeader (Context cr, DateTime start)
@@ -142,28 +159,20 @@
142 159
143 DateTime day = CalendarStartDate;160 DateTime day = CalendarStartDate;
144 161
145 using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) {162 header_layout.Width = Pango.Units.FromPixels (offsetSize);
146 layout.FontDescription = new Gtk.Style().FontDescription;163 header_layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (0.625 * LineHeight));
147 layout.FontDescription.Weight = Pango.Weight.Bold;164
148 layout.Ellipsize = Pango.EllipsizeMode.None;165 cr.Color = new Cairo.Color (1, 1, 1, .5);
149 layout.Width = Pango.Units.FromPixels (offsetSize);166 for (int i = 0; i < 7; i++) {
150 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (0.625 * LineHeight));167 header_layout.SetText (day.ToString ("ddd").ToUpper ());
151 168
152 cr.Color = new Cairo.Color (1, 1, 1, .5);169 Pango.Rectangle inkRect, logicalRect;
153 for (int i = 0; i < 7; i++) {170 header_layout.GetPixelExtents (out inkRect, out logicalRect);
154 layout.SetText (day.ToString ("ddd").ToUpper ());171 cr.MoveTo (offsetSize + offsetSize * i + (offsetSize - inkRect.Width) / 2, centerLine - logicalRect.Height);
155 172
156 Pango.Rectangle inkRect, logicalRect;173 Pango.CairoHelper.LayoutPath (cr, header_layout);
157 layout.GetPixelExtents (out inkRect, out logicalRect);174 cr.Fill ();
158 cr.MoveTo (offsetSize + offsetSize * i + (offsetSize - inkRect.Width) / 2, centerLine - logicalRect.Height);175 day = day.AddDays (1);
159
160 Pango.CairoHelper.LayoutPath (cr, layout);
161 cr.Fill ();
162 day = day.AddDays (1);
163 }
164
165 layout.FontDescription.Dispose ();
166 layout.Context.Dispose ();
167 }176 }
168 }177 }
169 178
@@ -174,58 +183,51 @@
174 int centerLine = LineHeight + LineHeight * line + ((Allocation.Height % LineHeight) / 2);183 int centerLine = LineHeight + LineHeight * line + ((Allocation.Height % LineHeight) / 2);
175 int dayOffset = 0;184 int dayOffset = 0;
176 185
177 using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) {186 Pango.Rectangle inkRect, logicalRect;
178 Pango.Rectangle inkRect, logicalRect;187
179 188 line_layout.Width = Pango.Units.FromPixels (offsetSize);
180 layout.FontDescription = new Gtk.Style().FontDescription;189 line_layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (0.625 * LineHeight));
181 layout.Ellipsize = Pango.EllipsizeMode.None;190
182 layout.Width = Pango.Units.FromPixels (offsetSize);191 for (int i = 0; i < 7; i++) {
183 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (0.625 * LineHeight));192 line_layout.FontDescription.Weight = Pango.Weight.Normal;
184 193
185 for (int i = 0; i < 7; i++) {194 DateTime day = lineStart.AddDays (dayOffset);
186 layout.FontDescription.Weight = Pango.Weight.Normal;195
187 196 if (day.Month == CalendarStartDate.AddDays (6).Month)
188 DateTime day = lineStart.AddDays (dayOffset);197 cr.Color = new Cairo.Color (1, 1, 1);
189 198 else
190 if (day.Month == CalendarStartDate.AddDays (6).Month)199 cr.Color = new Cairo.Color (1, 1, 1, 0.5);
191 cr.Color = new Cairo.Color (1, 1, 1);200
192 else201 if (day.Date == DateTime.Today)
193 cr.Color = new Cairo.Color (1, 1, 1, 0.5);202 {
194 203 line_layout.FontDescription.Weight = Pango.Weight.Bold;
195 if (day.Date == DateTime.Today)204 Gdk.Color color = Style.Backgrounds [(int) StateType.Selected].SetMinimumValue (100);
196 {205 cr.Color = new Cairo.Color ((double) color.Red / ushort.MaxValue,
197 layout.FontDescription.Weight = Pango.Weight.Bold;206 (double) color.Green / ushort.MaxValue,
198 Gdk.Color color = Style.Backgrounds [(int) StateType.Selected].SetMinimumValue (100);207 (double) color.Blue / ushort.MaxValue,
199 cr.Color = new Cairo.Color ((double) color.Red / ushort.MaxValue,208 1.0);
200 (double) color.Green / ushort.MaxValue,
201 (double) color.Blue / ushort.MaxValue,
202 1.0);
203 }
204 dayOffset++;
205
206 layout.SetText (string.Format ("{0:00}", day.Day));
207 layout.GetPixelExtents (out inkRect, out logicalRect);
208 cr.MoveTo (offsetSize + offsetSize * i + (offsetSize - inkRect.Width) / 2, centerLine - logicalRect.Height);
209
210 Pango.CairoHelper.LayoutPath (cr, layout);
211 cr.Fill ();
212 }209 }
213 210 dayOffset++;
214 cr.Color = new Cairo.Color (1, 1, 1, 0.4);211
215 int woy = CultureInfo.CurrentCulture.Calendar.GetWeekOfYear (lineStart.AddDays (6), 212 line_layout.SetText (string.Format ("{0:00}", day.Day));
216 DateTimeFormatInfo.CurrentInfo.CalendarWeekRule, 213 line_layout.GetPixelExtents (out inkRect, out logicalRect);
217 DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek);214 cr.MoveTo (offsetSize + offsetSize * i + (offsetSize - inkRect.Width) / 2, centerLine - logicalRect.Height);
218 layout.FontDescription.Weight = Pango.Weight.Bold;215
219 layout.SetText (string.Format ("W{0:00}", woy));216 Pango.CairoHelper.LayoutPath (cr, line_layout);
220 layout.GetPixelExtents (out inkRect, out logicalRect);
221 cr.MoveTo (offsetSize * 8, centerLine - logicalRect.Height);
222
223 Pango.CairoHelper.LayoutPath (cr, layout);
224 cr.Fill ();217 cr.Fill ();
225
226 layout.FontDescription.Dispose ();
227 layout.Context.Dispose ();
228 }218 }
219
220 cr.Color = new Cairo.Color (1, 1, 1, 0.4);
221 int woy = CultureInfo.CurrentCulture.Calendar.GetWeekOfYear (lineStart.AddDays (6),
222 DateTimeFormatInfo.CurrentInfo.CalendarWeekRule,
223 DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek);
224 line_layout.FontDescription.Weight = Pango.Weight.Bold;
225 line_layout.SetText (string.Format ("W{0:00}", woy));
226 line_layout.GetPixelExtents (out inkRect, out logicalRect);
227 cr.MoveTo (offsetSize * 8, centerLine - logicalRect.Height);
228
229 Pango.CairoHelper.LayoutPath (cr, line_layout);
230 cr.Fill ();
229 }231 }
230 232
231 protected override void OnShown ()233 protected override void OnShown ()
232234
=== modified file 'StandardPlugins/Clock/src/ClockDockItem.cs'
--- StandardPlugins/Clock/src/ClockDockItem.cs 2010-11-21 22:19:54 +0000
+++ StandardPlugins/Clock/src/ClockDockItem.cs 2011-01-03 11:34:09 +0000
@@ -141,6 +141,20 @@
141 }141 }
142 }142 }
143 143
144 static Pango.Layout layout;
145
146 static ClockDockItem ()
147 {
148 Gtk.Style style = new Gtk.Style ();
149
150 layout = DockServices.Drawing.ThemedPangoLayout ();
151 layout.FontDescription = style.FontDescription;
152 layout.FontDescription.Weight = Pango.Weight.Bold;
153 layout.Ellipsize = Pango.EllipsizeMode.None;
154
155 style.Dispose ();
156 }
157
144 public ClockDockItem ()158 public ClockDockItem ()
145 {159 {
146 ScalableRendering = !ShowDigital;160 ScalableRendering = !ShowDigital;
@@ -215,78 +229,69 @@
215 int center = surface.Height / 2;229 int center = surface.Height / 2;
216 230
217 // shared by all text231 // shared by all text
218 using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) {232 layout.Width = Pango.Units.FromPixels (surface.Width);
219 layout.FontDescription = new Gtk.Style().FontDescription;233
220 layout.FontDescription.Weight = Pango.Weight.Bold;234 // draw the time, outlined
221 layout.Ellipsize = Pango.EllipsizeMode.None;235 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (timeSize);
222 layout.Width = Pango.Units.FromPixels (surface.Width);236
223 237 if (ShowMilitary)
224 238 layout.SetText (DateTime.Now.ToString ("HH:mm"));
225 // draw the time, outlined239 else
226 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (timeSize);240 layout.SetText (DateTime.Now.ToString ("h:mm"));
227 241
228 if (ShowMilitary)242 Pango.Rectangle inkRect, logicalRect;
229 layout.SetText (DateTime.Now.ToString ("HH:mm"));243 layout.GetPixelExtents (out inkRect, out logicalRect);
230 else244
231 layout.SetText (DateTime.Now.ToString ("h:mm"));245 int timeYOffset = ShowMilitary ? timeSize : timeSize / 2;
232 246 int timeXOffset = (surface.Width - inkRect.Width) / 2;
233 Pango.Rectangle inkRect, logicalRect;247 if (ShowDate)
248 cr.MoveTo (timeXOffset, timeYOffset);
249 else
250 cr.MoveTo (timeXOffset, timeYOffset + timeSize / 2);
251
252 Pango.CairoHelper.LayoutPath (cr, layout);
253 cr.LineWidth = 3;
254 cr.Color = new Cairo.Color (0, 0, 0, 0.5);
255 cr.StrokePreserve ();
256 cr.Color = new Cairo.Color (1, 1, 1, 0.8);
257 cr.Fill ();
258
259 // draw the date, outlined
260 if (ShowDate) {
261 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (dateSize);
262
263 layout.SetText (DateTime.Now.ToString ("MMM dd"));
234 layout.GetPixelExtents (out inkRect, out logicalRect);264 layout.GetPixelExtents (out inkRect, out logicalRect);
235 265 cr.MoveTo ((surface.Width - inkRect.Width) / 2, surface.Height - spacing - dateSize);
236 int timeYOffset = ShowMilitary ? timeSize : timeSize / 2;
237 int timeXOffset = (surface.Width - inkRect.Width) / 2;
238 if (ShowDate)
239 cr.MoveTo (timeXOffset, timeYOffset);
240 else
241 cr.MoveTo (timeXOffset, timeYOffset + timeSize / 2);
242 266
243 Pango.CairoHelper.LayoutPath (cr, layout);267 Pango.CairoHelper.LayoutPath (cr, layout);
244 cr.LineWidth = 3;268 cr.LineWidth = 2.5;
245 cr.Color = new Cairo.Color (0, 0, 0, 0.5);269 cr.Color = new Cairo.Color (0, 0, 0, 0.5);
246 cr.StrokePreserve ();270 cr.StrokePreserve ();
247 cr.Color = new Cairo.Color (1, 1, 1, 0.8);271 cr.Color = new Cairo.Color (1, 1, 1, 0.8);
248 cr.Fill ();272 cr.Fill ();
249 273 }
250 // draw the date, outlined274
251 if (ShowDate) {275 if (!ShowMilitary) {
252 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (dateSize);276 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (ampmSize);
253 277
254 layout.SetText (DateTime.Now.ToString ("MMM dd"));278 int yOffset = ShowDate ? center - spacing : surface.Height - spacing - ampmSize;
255 layout.GetPixelExtents (out inkRect, out logicalRect);279
256 cr.MoveTo ((surface.Width - inkRect.Width) / 2, surface.Height - spacing - dateSize);280 // draw AM indicator
257 281 layout.SetText ("am");
258 Pango.CairoHelper.LayoutPath (cr, layout);282 cr.Color = new Cairo.Color (1, 1, 1, DateTime.Now.Hour < 12 ? 0.8 : 0.2);
259 cr.LineWidth = 2.5;283 layout.GetPixelExtents (out inkRect, out logicalRect);
260 cr.Color = new Cairo.Color (0, 0, 0, 0.5);284 cr.MoveTo ((center - inkRect.Width) / 2, yOffset);
261 cr.StrokePreserve ();285 Pango.CairoHelper.LayoutPath (cr, layout);
262 cr.Color = new Cairo.Color (1, 1, 1, 0.8);286 cr.Fill ();
263 cr.Fill ();287
264 }288 // draw PM indicator
265 289 layout.SetText ("pm");
266 if (!ShowMilitary) {290 cr.Color = new Cairo.Color (1, 1, 1, DateTime.Now.Hour > 11 ? 0.8 : 0.2);
267 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (ampmSize);291 layout.GetPixelExtents (out inkRect, out logicalRect);
268 292 cr.MoveTo (center + (center - inkRect.Width) / 2, yOffset);
269 int yOffset = ShowDate ? center - spacing : surface.Height - spacing - ampmSize;293 Pango.CairoHelper.LayoutPath (cr, layout);
270 294 cr.Fill ();
271 // draw AM indicator
272 layout.SetText ("am");
273 cr.Color = new Cairo.Color (1, 1, 1, DateTime.Now.Hour < 12 ? 0.8 : 0.2);
274 layout.GetPixelExtents (out inkRect, out logicalRect);
275 cr.MoveTo ((center - inkRect.Width) / 2, yOffset);
276 Pango.CairoHelper.LayoutPath (cr, layout);
277 cr.Fill ();
278
279 // draw PM indicator
280 layout.SetText ("pm");
281 cr.Color = new Cairo.Color (1, 1, 1, DateTime.Now.Hour > 11 ? 0.8 : 0.2);
282 layout.GetPixelExtents (out inkRect, out logicalRect);
283 cr.MoveTo (center + (center - inkRect.Width) / 2, yOffset);
284 Pango.CairoHelper.LayoutPath (cr, layout);
285 cr.Fill ();
286 }
287
288 layout.FontDescription.Dispose ();
289 layout.Context.Dispose ();
290 }295 }
291 }296 }
292 297
@@ -301,72 +306,63 @@
301 int spacing = timeSize / 2;306 int spacing = timeSize / 2;
302 307
303 // shared by all text308 // shared by all text
304 using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) {309 layout.Width = Pango.Units.FromPixels (surface.Width);
305 layout.FontDescription = new Gtk.Style().FontDescription;310
306 layout.FontDescription.Weight = Pango.Weight.Bold;311 // draw the time, outlined
307 layout.Ellipsize = Pango.EllipsizeMode.None;312 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (timeSize);
308 layout.Width = Pango.Units.FromPixels (surface.Width);313
309 314 if (ShowMilitary)
310 315 layout.SetText (DateTime.Now.ToString ("HH:mm"));
311 // draw the time, outlined316 else
312 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (timeSize);317 layout.SetText (DateTime.Now.ToString ("h:mm"));
313 318
314 if (ShowMilitary)319 Pango.Rectangle inkRect, logicalRect;
315 layout.SetText (DateTime.Now.ToString ("HH:mm"));320 layout.GetPixelExtents (out inkRect, out logicalRect);
321
322 int timeYOffset = timeSize / 2;
323 if (!ShowDate)
324 timeYOffset += timeSize / 2;
325 cr.MoveTo ((surface.Width - inkRect.Width) / 2, timeYOffset);
326
327 Pango.CairoHelper.LayoutPath (cr, layout);
328 cr.LineWidth = 2;
329 cr.Color = new Cairo.Color (0, 0, 0, 0.5);
330 cr.StrokePreserve ();
331 cr.Color = new Cairo.Color (1, 1, 1, 0.8);
332 cr.Fill ();
333
334 // draw the date, outlined
335 if (ShowDate) {
336 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (dateSize);
337
338 layout.SetText (DateTime.Now.ToString ("MMM dd"));
339 layout.GetPixelExtents (out inkRect, out logicalRect);
340 cr.MoveTo ((surface.Width - inkRect.Width) / 2, surface.Height - spacing - dateSize);
341
342 Pango.CairoHelper.LayoutPath (cr, layout);
343 cr.Color = new Cairo.Color (0, 0, 0, 0.5);
344 cr.StrokePreserve ();
345 cr.Color = new Cairo.Color (1, 1, 1, 0.8);
346 cr.Fill ();
347 }
348
349 if (!ShowMilitary) {
350 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (ampmSize);
351
352 if (DateTime.Now.Hour < 12)
353 layout.SetText ("am");
316 else354 else
317 layout.SetText (DateTime.Now.ToString ("h:mm"));355 layout.SetText ("pm");
318 356
319 Pango.Rectangle inkRect, logicalRect;
320 layout.GetPixelExtents (out inkRect, out logicalRect);357 layout.GetPixelExtents (out inkRect, out logicalRect);
321 358 int yOffset = timeSize;
322 int timeYOffset = timeSize / 2;
323 if (!ShowDate)359 if (!ShowDate)
324 timeYOffset += timeSize / 2;360 yOffset += timeSize / 2;
325 cr.MoveTo ((surface.Width - inkRect.Width) / 2, timeYOffset);361 cr.MoveTo (surface.Width - logicalRect.Width, yOffset - inkRect.Height);
326 362
327 Pango.CairoHelper.LayoutPath (cr, layout);363 Pango.CairoHelper.LayoutPath (cr, layout);
328 cr.LineWidth = 2;
329 cr.Color = new Cairo.Color (0, 0, 0, 0.5);
330 cr.StrokePreserve ();
331 cr.Color = new Cairo.Color (1, 1, 1, 0.8);364 cr.Color = new Cairo.Color (1, 1, 1, 0.8);
332 cr.Fill ();365 cr.Fill ();
333
334 // draw the date, outlined
335 if (ShowDate) {
336 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (dateSize);
337
338 layout.SetText (DateTime.Now.ToString ("MMM dd"));
339 layout.GetPixelExtents (out inkRect, out logicalRect);
340 cr.MoveTo ((surface.Width - inkRect.Width) / 2, surface.Height - spacing - dateSize);
341
342 Pango.CairoHelper.LayoutPath (cr, layout);
343 cr.Color = new Cairo.Color (0, 0, 0, 0.5);
344 cr.StrokePreserve ();
345 cr.Color = new Cairo.Color (1, 1, 1, 0.8);
346 cr.Fill ();
347 }
348
349 if (!ShowMilitary) {
350 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (ampmSize);
351
352 if (DateTime.Now.Hour < 12)
353 layout.SetText ("am");
354 else
355 layout.SetText ("pm");
356
357 layout.GetPixelExtents (out inkRect, out logicalRect);
358 int yOffset = timeSize;
359 if (!ShowDate)
360 yOffset += timeSize / 2;
361 cr.MoveTo (surface.Width - logicalRect.Width, yOffset - inkRect.Height);
362
363 Pango.CairoHelper.LayoutPath (cr, layout);
364 cr.Color = new Cairo.Color (1, 1, 1, 0.8);
365 cr.Fill ();
366 }
367
368 layout.FontDescription.Dispose ();
369 layout.Context.Dispose ();
370 }366 }
371 }367 }
372 368
373369
=== modified file 'StandardPlugins/Weather/src/WeatherDocklet.cs'
--- StandardPlugins/Weather/src/WeatherDocklet.cs 2010-11-21 22:19:54 +0000
+++ StandardPlugins/Weather/src/WeatherDocklet.cs 2011-01-03 11:34:09 +0000
@@ -62,6 +62,20 @@
62 62
63 ConfigDialog Config;63 ConfigDialog Config;
64 64
65 static Pango.Layout layout;
66
67 static WeatherDocklet ()
68 {
69 Gtk.Style style = new Gtk.Style ();
70
71 layout = DockServices.Drawing.ThemedPangoLayout ();
72 layout.FontDescription = style.FontDescription;
73 layout.FontDescription.Weight = Pango.Weight.Bold;
74 layout.Ellipsize = Pango.EllipsizeMode.None;
75
76 style.Dispose ();
77 }
78
65 /// <summary>79 /// <summary>
66 /// Creates a new weather docklet.80 /// Creates a new weather docklet.
67 /// </summary>81 /// </summary>
@@ -154,35 +168,25 @@
154 int size = Math.Min (surface.Width, surface.Height);168 int size = Math.Min (surface.Width, surface.Height);
155 Context cr = surface.Context;169 Context cr = surface.Context;
156 170
157 using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ())171 Pango.Rectangle inkRect, logicalRect;
158 {172
159 layout.FontDescription = new Gtk.Style().FontDescription;173 layout.Width = Pango.Units.FromPixels (size);
160 layout.FontDescription.Weight = Pango.Weight.Bold;174 layout.SetText (WeatherController.Weather.Temp + AbstractWeatherSource.TempUnit);
161 layout.Ellipsize = Pango.EllipsizeMode.None;175 if (IsSmall)
162 176 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (size / 2.5));
163 Pango.Rectangle inkRect, logicalRect;177 else
164 178 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (size / 3.5));
165 layout.Width = Pango.Units.FromPixels (size);179
166 layout.SetText (WeatherController.Weather.Temp + AbstractWeatherSource.TempUnit);180 layout.GetPixelExtents (out inkRect, out logicalRect);
167 if (IsSmall)181 cr.MoveTo ((size - inkRect.Width) / 2, size - logicalRect.Height);
168 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (size / 2.5));182
169 else183 Pango.CairoHelper.LayoutPath (cr, layout);
170 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (size / 3.5));184 cr.LineWidth = 2;
171 185 cr.Color = new Cairo.Color (0, 0, 0, 0.8);
172 layout.GetPixelExtents (out inkRect, out logicalRect);186 cr.StrokePreserve ();
173 cr.MoveTo ((size - inkRect.Width) / 2, size - logicalRect.Height);187
174 188 cr.Color = new Cairo.Color (1, 1, 1, 0.8);
175 Pango.CairoHelper.LayoutPath (cr, layout);189 cr.Fill ();
176 cr.LineWidth = 2;
177 cr.Color = new Cairo.Color (0, 0, 0, 0.8);
178 cr.StrokePreserve ();
179
180 cr.Color = new Cairo.Color (1, 1, 1, 0.8);
181 cr.Fill ();
182
183 layout.FontDescription.Dispose ();
184 layout.Context.Dispose ();
185 }
186 }190 }
187 191
188 protected override Gdk.Pixbuf ProcessPixbuf (Gdk.Pixbuf pbuf)192 protected override Gdk.Pixbuf ProcessPixbuf (Gdk.Pixbuf pbuf)
189193
=== modified file 'StandardPlugins/Weather/src/WeatherPainter.cs'
--- StandardPlugins/Weather/src/WeatherPainter.cs 2010-06-24 11:45:49 +0000
+++ StandardPlugins/Weather/src/WeatherPainter.cs 2011-01-03 11:34:09 +0000
@@ -49,6 +49,20 @@
49 /// </value>49 /// </value>
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);
51 51
52 static Pango.Layout layout;
53
54 static WeatherPainter ()
55 {
56 Gtk.Style style = new Gtk.Style ();
57
58 layout = DockServices.Drawing.ThemedPangoLayout ();
59 layout.FontDescription = style.FontDescription;
60 layout.FontDescription.Weight = Pango.Weight.Bold;
61 layout.Ellipsize = Pango.EllipsizeMode.None;
62
63 style.Dispose ();
64 }
65
52 /// <summary>66 /// <summary>
53 /// Creates a new weather painter object.67 /// Creates a new weather painter object.
54 /// </summary>68 /// </summary>
@@ -102,68 +116,60 @@
102 int xOffset = BUTTON_SIZE;116 int xOffset = BUTTON_SIZE;
103 int cellWidth = (Allocation.Width - 2 * BUTTON_SIZE) / (WeatherController.Weather.ForecastDays * 2);117 int cellWidth = (Allocation.Width - 2 * BUTTON_SIZE) / (WeatherController.Weather.ForecastDays * 2);
104 118
105 using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) {119 Pango.Rectangle inkRect, logicalRect;
106 Pango.Rectangle inkRect, logicalRect;120
107 121 layout.Width = Pango.Units.FromPixels (cellWidth);
108 layout.FontDescription = new Gtk.Style().FontDescription;122
109 layout.FontDescription.Weight = Pango.Weight.Bold;123 for (int day = 0; day < WeatherController.Weather.ForecastDays; day++)
110 layout.Ellipsize = Pango.EllipsizeMode.None;124 {
111 layout.Width = Pango.Units.FromPixels (cellWidth);125 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (cellWidth / 5));
112 126
113 for (int day = 0; day < WeatherController.Weather.ForecastDays; day++)127 cr.Color = colorTitle;
114 {128 layout.SetText (string.Format ("{0}", WeatherForecast.DayShortName (WeatherController.Weather.Forecasts [day].dow)));
115 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (cellWidth / 5));129 layout.GetPixelExtents (out inkRect, out logicalRect);
116 130 cr.MoveTo (xOffset + (cellWidth - inkRect.Width) / 2, 0);
117 cr.Color = colorTitle;131 Pango.CairoHelper.LayoutPath (cr, layout);
118 layout.SetText (string.Format ("{0}", WeatherForecast.DayShortName (WeatherController.Weather.Forecasts [day].dow)));132 cr.Fill ();
119 layout.GetPixelExtents (out inkRect, out logicalRect);133
120 cr.MoveTo (xOffset + (cellWidth - inkRect.Width) / 2, 0);134 cr.Color = colorHigh;
121 Pango.CairoHelper.LayoutPath (cr, layout);135 layout.SetText (string.Format ("{0}{1}", WeatherController.Weather.Forecasts [day].high, AbstractWeatherSource.TempUnit));
122 cr.Fill ();136 layout.GetPixelExtents (out inkRect, out logicalRect);
123 137 cr.MoveTo (xOffset + (cellWidth - inkRect.Width) / 2, Allocation.Height / 2 - logicalRect.Height / 2);
124 cr.Color = colorHigh;138 Pango.CairoHelper.LayoutPath (cr, layout);
125 layout.SetText (string.Format ("{0}{1}", WeatherController.Weather.Forecasts [day].high, AbstractWeatherSource.TempUnit));139 cr.Fill ();
126 layout.GetPixelExtents (out inkRect, out logicalRect);140
127 cr.MoveTo (xOffset + (cellWidth - inkRect.Width) / 2, Allocation.Height / 2 - logicalRect.Height / 2);141 cr.Color = colorLow;
128 Pango.CairoHelper.LayoutPath (cr, layout);142 layout.SetText (string.Format ("{0}{1}", WeatherController.Weather.Forecasts [day].low, AbstractWeatherSource.TempUnit));
129 cr.Fill ();143 layout.GetPixelExtents (out inkRect, out logicalRect);
130 144 cr.MoveTo (xOffset + (cellWidth - inkRect.Width) / 2, Allocation.Height - logicalRect.Height);
131 cr.Color = colorLow;145 Pango.CairoHelper.LayoutPath (cr, layout);
132 layout.SetText (string.Format ("{0}{1}", WeatherController.Weather.Forecasts [day].low, AbstractWeatherSource.TempUnit));146 cr.Fill ();
133 layout.GetPixelExtents (out inkRect, out logicalRect);147
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))
135 Pango.CairoHelper.LayoutPath (cr, layout);149 {
136 cr.Fill ();150 Gdk.CairoHelper.SetSourcePixbuf (cr, pbuf, xOffset + cellWidth + 2, 5 + (Allocation.Height - cellWidth) / 2);
137 151 cr.PaintWithAlpha (WeatherController.Weather.Forecasts [day].chanceOf ? .6 : 1);
138 using (Gdk.Pixbuf pbuf = DockServices.Drawing.LoadIcon (WeatherController.Weather.Forecasts [day].image, cellWidth - 5))152 }
139 {153
140 Gdk.CairoHelper.SetSourcePixbuf (cr, pbuf, xOffset + cellWidth + 2, 5 + (Allocation.Height - cellWidth) / 2);154 if (WeatherController.Weather.Forecasts [day].chanceOf)
141 cr.PaintWithAlpha (WeatherController.Weather.Forecasts [day].chanceOf ? .6 : 1);155 {
142 }156 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (cellWidth / 2));
143 157
144 if (WeatherController.Weather.Forecasts [day].chanceOf)158 layout.SetText ("?");
145 {159
146 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (cellWidth / 2));160 layout.GetPixelExtents (out inkRect, out logicalRect);
147 161 cr.MoveTo (xOffset + cellWidth + (cellWidth - inkRect.Width) / 2, Allocation.Height / 2 - logicalRect.Height / 2);
148 layout.SetText ("?");162
149 163 cr.LineWidth = 4;
150 layout.GetPixelExtents (out inkRect, out logicalRect);164 cr.Color = new Cairo.Color (0, 0, 0, 0.3);
151 cr.MoveTo (xOffset + cellWidth + (cellWidth - inkRect.Width) / 2, Allocation.Height / 2 - logicalRect.Height / 2);165 Pango.CairoHelper.LayoutPath (cr, layout);
152 166 cr.StrokePreserve ();
153 cr.LineWidth = 4;167
154 cr.Color = new Cairo.Color (0, 0, 0, 0.3);168 cr.Color = new Cairo.Color (1, 1, 1, .6);
155 Pango.CairoHelper.LayoutPath (cr, layout);169 cr.Fill ();
156 cr.StrokePreserve ();170 }
157 171
158 cr.Color = new Cairo.Color (1, 1, 1, .6);172 xOffset += 2 * cellWidth;
159 cr.Fill ();
160 }
161
162 xOffset += 2 * cellWidth;
163 }
164
165 layout.FontDescription.Dispose ();
166 layout.Context.Dispose ();
167 }173 }
168 }174 }
169 175
@@ -192,47 +198,39 @@
192 if (max <= min)198 if (max <= min)
193 return;199 return;
194 200
195 using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) {201 Pango.Rectangle inkRect, logicalRect;
196 Pango.Rectangle inkRect, logicalRect;202
197 203 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (Allocation.Height / 5));
198 layout.FontDescription = new Gtk.Style().FontDescription;204
199 layout.FontDescription.Weight = Pango.Weight.Bold;205 // high/low temp
200 layout.Ellipsize = Pango.EllipsizeMode.None;206 layout.Width = Pango.Units.FromPixels (Allocation.Height);
201 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (Allocation.Height / 5));207 cr.Color = colorHigh;
202 208 layout.SetText (string.Format ("{0}{1}", max, AbstractWeatherSource.TempUnit));
203 // high/low temp209 layout.GetPixelExtents (out inkRect, out logicalRect);
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);
205 cr.Color = colorHigh;211 Pango.CairoHelper.LayoutPath (cr, layout);
206 layout.SetText (string.Format ("{0}{1}", max, AbstractWeatherSource.TempUnit));212 cr.Fill ();
207 layout.GetPixelExtents (out inkRect, out logicalRect);213
208 cr.MoveTo (Allocation.Width - Allocation.Height + (Allocation.Height - inkRect.Width) / 2 - BUTTON_SIZE, Allocation.Height / 6 - logicalRect.Height / 2);214 cr.Color = colorLow;
209 Pango.CairoHelper.LayoutPath (cr, layout);215 layout.SetText (string.Format ("{0}{1}", min, AbstractWeatherSource.TempUnit));
210 cr.Fill ();216 layout.GetPixelExtents (out inkRect, out logicalRect);
211 217 cr.MoveTo (Allocation.Width - Allocation.Height + (Allocation.Height - inkRect.Width) / 2 - BUTTON_SIZE, Allocation.Height * 6 / 9 - logicalRect.Height / 2);
212 cr.Color = colorLow;218 Pango.CairoHelper.LayoutPath (cr, layout);
213 layout.SetText (string.Format ("{0}{1}", min, AbstractWeatherSource.TempUnit));219 cr.Fill ();
214 layout.GetPixelExtents (out inkRect, out logicalRect);220
215 cr.MoveTo (Allocation.Width - Allocation.Height + (Allocation.Height - inkRect.Width) / 2 - BUTTON_SIZE, Allocation.Height * 6 / 9 - logicalRect.Height / 2);221 // day names
216 Pango.CairoHelper.LayoutPath (cr, layout);222 layout.Width = Pango.Units.FromPixels (2 * Allocation.Height);
217 cr.Fill ();223
218 224 cr.Color = colorTitle;
219 // day names225 for (int day = 0; day < WeatherController.Weather.ForecastDays; day++)
220 layout.Width = Pango.Units.FromPixels (2 * Allocation.Height);226 {
221 227 layout.SetText (WeatherForecast.DayShortName (WeatherController.Weather.Forecasts [day].dow));
222 cr.Color = colorTitle;228 layout.GetPixelExtents (out inkRect, out logicalRect);
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);
224 {230 Pango.CairoHelper.LayoutPath (cr, layout);
225 layout.SetText (WeatherForecast.DayShortName (WeatherController.Weather.Forecasts [day].dow));
226 layout.GetPixelExtents (out inkRect, out logicalRect);
227 cr.MoveTo (BUTTON_SIZE + day * Allocation.Height * 2 + (Allocation.Height - inkRect.Width) / 2, Allocation.Height * 8 / 9 - logicalRect.Height / 2);
228 Pango.CairoHelper.LayoutPath (cr, layout);
229 }
230 cr.Fill ();
231 cr.Save ();
232
233 layout.FontDescription.Dispose ();
234 layout.Context.Dispose ();
235 }231 }
232 cr.Fill ();
233 cr.Save ();
236 234
237 // draw tick lines235 // draw tick lines
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);
@@ -359,29 +357,21 @@
359 357
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)
361 {359 {
362 using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) {360 Pango.Rectangle inkRect, logicalRect;
363 Pango.Rectangle inkRect, logicalRect;361
364 362 layout.Width = Pango.Units.FromPixels (Allocation.Width - BUTTON_SIZE - x);
365 layout.FontDescription = new Gtk.Style().FontDescription;363
366 layout.FontDescription.Weight = Pango.Weight.Bold;364 if (WeatherController.Weather.ForecastDays < 6)
367 layout.Ellipsize = Pango.EllipsizeMode.None;365 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (Allocation.Height / 5));
368 layout.Width = Pango.Units.FromPixels (Allocation.Width - BUTTON_SIZE - x);366 else
369 367 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (Allocation.Height / 3.5));
370 if (WeatherController.Weather.ForecastDays < 6)368
371 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (Allocation.Height / 5));369 cr.Color = new Cairo.Color (1, 1, 1, 0.9);
372 else370 layout.SetText (text);
373 layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels ((int) (Allocation.Height / 3.5));371 layout.GetPixelExtents (out inkRect, out logicalRect);
374 372 cr.MoveTo (x + (xWidth - logicalRect.Width) / 2, yCenter - logicalRect.Height / 2);
375 cr.Color = new Cairo.Color (1, 1, 1, 0.9);373 Pango.CairoHelper.LayoutPath (cr, layout);
376 layout.SetText (text);374 cr.Fill ();
377 layout.GetPixelExtents (out inkRect, out logicalRect);
378 cr.MoveTo (x + (xWidth - logicalRect.Width) / 2, yCenter - logicalRect.Height / 2);
379 Pango.CairoHelper.LayoutPath (cr, layout);
380 cr.Fill ();
381
382 layout.FontDescription.Dispose ();
383 layout.Context.Dispose ();
384 }
385 }375 }
386 376
387 /// <summary>377 /// <summary>

Subscribers

People subscribed via source and target branches

to status/vote changes: