protected override void MakePatterns() { d_outer = new Cairo.LinearGradient(0, 1, 0, 0); d_outer.AddColorStopRgb(0, new Cairo.Color(0.5, 0.5, 0.8)); d_outer.AddColorStopRgb(d_object != null ? d_object.Allocation.Height : 1, new Cairo.Color(1, 1, 1)); d_inner = new Cairo.LinearGradient(0, 1, 0, 0); d_inner.AddColorStopRgb(0, new Cairo.Color(0.75, 0.85, 1)); d_inner.AddColorStopRgb((d_object != null ? d_object.Allocation.Height : 1) * 0.8, new Cairo.Color(1, 1, 1)); }
protected virtual void MakePatterns() { d_outer = new Cairo.LinearGradient(0, 1, 0, 0); d_outer.AddColorStopRgb(0, new Cairo.Color(1, 1, 1)); d_outer.AddColorStopRgb(d_object != null ? d_object.Allocation.Height : 1, new Cairo.Color(1, 1, 1)); d_inner = new Cairo.LinearGradient(0, 1, 0, 0); d_inner.AddColorStopRgb(0, new Cairo.Color(1, 1, 1)); d_inner.AddColorStopRgb(d_object != null ? d_object.Allocation.Height : 1, new Cairo.Color(1, 1, 1)); }
private void SetBrush(Brush brush, Size destinationSize) { var solid = brush as SolidColorBrush; var linearGradientBrush = brush as LinearGradientBrush; if (solid != null) { _context.SetSourceRGBA( solid.Color.R / 255.0, solid.Color.G / 255.0, solid.Color.B / 255.0, solid.Color.A / 255.0); } else if (linearGradientBrush != null) { Cairo.LinearGradient g = new Cairo.LinearGradient(linearGradientBrush.StartPoint.X * destinationSize.Width, linearGradientBrush.StartPoint.Y * destinationSize.Height, linearGradientBrush.EndPoint.X * destinationSize.Width, linearGradientBrush.EndPoint.Y * destinationSize.Height); foreach (var s in linearGradientBrush.GradientStops) { g.AddColorStopRgb(s.Offset, new Cairo.Color(s.Color.R, s.Color.G, s.Color.B, s.Color.A)); } g.Extend = Cairo.Extend.Pad; _context.SetSource(g); } }
protected override bool OnExposeEvent(Gdk.EventExpose e) { using (Cairo.Context cr = Gdk.CairoHelper.Create(e.Window)) { cr.Rectangle(0, 0, Allocation.Width, upperGradientHeight); using (var pattern = new Cairo.LinearGradient(0, 0, 0, upperGradientHeight)) { pattern.AddColorStopRgb(0, new Cairo.Color(0.6, 0.8, 0.6)); pattern.AddColorStopRgb(1, new Cairo.Color(0.8, 1.0, 0.8)); cr.Pattern = pattern; cr.Fill(); } cr.Rectangle(0, upperGradientHeight, Allocation.Width, Allocation.Height - upperGradientHeight); using (var pattern = new Cairo.LinearGradient(0, upperGradientHeight, 0, Allocation.Height)) { pattern.AddColorStop(0, new Cairo.Color(0.8, 1.0, 0.8)); pattern.AddColorStop(1, new Cairo.Color(0.6, 0.8, 0.6)); cr.Pattern = pattern; cr.Fill(); } cr.LineWidth = 1; cr.Line(0, 0, Allocation.Width, 0); cr.Color = new Cairo.Color(0.4, 0.6, 0.4); cr.Stroke(); double xPos = padding, yPos = padding; var layout = PangoUtil.CreateLayout(this); int w, h; layout.SetText(new string ('X', maxLength)); layout.GetPixelSize(out w, out h); foreach (Category cat in categories) { yPos = padding; cr.MoveTo(xPos, yPos); layout.SetMarkup("<b>" + cat.Title + "</b>"); cr.Color = (HslColor)Style.Text(StateType.Normal); cr.ShowLayout(layout); layout.SetMarkup(""); int w2, h2; layout.GetPixelSize(out w2, out h2); yPos += h2; yPos += headerDistance; var startY = yPos; int curItem = 0; int row = 0; var iconHeight = Math.Max(h, cat.Items [0].Icon.Height + 2); if (cat.FirstVisibleItem > 0) { Gtk.Style.PaintArrow(Style, e.Window, State, ShadowType.None, new Rectangle((int)xPos, (int)yPos, w, h), this, "", ArrowType.Up, true, (int)xPos, (int)yPos, w, h); yPos += iconHeight; curItem++; } for (int i = cat.FirstVisibleItem; i < cat.Items.Count; i++) { var item = cat.Items [i]; if (curItem + 1 >= maxItems && row + 1 >= maxRows && i + 1 < cat.Items.Count) { Gtk.Style.PaintArrow(Style, e.Window, State, ShadowType.None, new Rectangle((int)xPos, (int)yPos, w, h), this, "", ArrowType.Down, true, (int)xPos, (int)yPos, w, h); break; } if (item == ActiveItem) { cr.Rectangle(xPos + 0.5, yPos + 0.5, w + item.Icon.Width + 2, iconHeight); using (var pattern = new Cairo.LinearGradient(xPos, yPos, xPos, yPos + iconHeight * 2)) { pattern.AddColorStop(0, (HslColor)Style.Base(StateType.Selected)); pattern.AddColorStop(1, new Cairo.Color(0.8, 1.0, 0.8)); cr.Pattern = pattern; cr.FillPreserve(); } cr.Color = (HslColor)Style.Base(StateType.Selected); cr.Stroke(); cr.Color = (HslColor)Style.Text(StateType.Selected); } else if (item == hoverItem) { cr.Rectangle(xPos + 0.5, yPos + 0.5, w + item.Icon.Width + 2, iconHeight); using (var pattern = new Cairo.LinearGradient(xPos, yPos, xPos, yPos + iconHeight)) { pattern.AddColorStop(0, new Cairo.Color(0.6, 0.8, 0.6)); pattern.AddColorStop(1, new Cairo.Color(0.8, 1.0, 0.8)); cr.Pattern = pattern; cr.Fill(); } cr.Color = (HslColor)Style.Text(StateType.Normal); } else { cr.Color = (HslColor)Style.Text(StateType.Normal); } cr.MoveTo(xPos + item.Icon.Width + 2, yPos + (iconHeight - h) / 2); layout.SetText(Ellipsize(item.ListTitle ?? item.Title, maxLength)); cr.ShowLayout(layout); e.Window.DrawPixbuf(Style.BaseGC(StateType.Normal), item.Icon, 0, 0, (int)xPos, (int)(yPos + (iconHeight - item.Icon.Height) / 2), item.Icon.Width, item.Icon.Height, RgbDither.None, 0, 0); yPos += iconHeight; if (++curItem >= maxItems) { curItem = 0; yPos = startY; xPos += w + cat.Items [0].Icon.Width + 2 + padding; row++; } } xPos += w + cat.Items [0].Icon.Width + 2 + padding; } layout.Dispose(); } return(true); }
private void SetBrush(Brush brush, Size destinationSize) { var solid = brush as SolidColorBrush; var linearGradientBrush = brush as LinearGradientBrush; if (solid != null) { _context.SetSourceRGBA( solid.Color.R / 255.0, solid.Color.G / 255.0, solid.Color.B / 255.0, solid.Color.A / 255.0); } else if (linearGradientBrush != null) { Cairo.LinearGradient g = new Cairo.LinearGradient(linearGradientBrush.StartPoint.X * destinationSize.Width, linearGradientBrush.StartPoint.Y * destinationSize.Height, linearGradientBrush.EndPoint.X * destinationSize.Width, linearGradientBrush.EndPoint.Y * destinationSize.Height); foreach (var s in linearGradientBrush.GradientStops) g.AddColorStopRgb(s.Offset, new Cairo.Color(s.Color.R, s.Color.G, s.Color.B, s.Color.A)); g.Extend = Cairo.Extend.Pad; _context.SetSource(g); } }
protected override bool OnExposeEvent (Gdk.EventExpose e) { using (Cairo.Context cr = Gdk.CairoHelper.Create (e.Window)) { cr.Rectangle (0, 0, Allocation.Width, upperGradientHeight); using (var pattern = new Cairo.LinearGradient (0, 0, 0, upperGradientHeight)) { pattern.AddColorStopRgb (0, new Cairo.Color (0.6, 0.8, 0.6)); pattern.AddColorStopRgb (1, new Cairo.Color (0.8, 1.0, 0.8)); cr.Pattern = pattern; cr.Fill (); } cr.Rectangle (0, upperGradientHeight, Allocation.Width, Allocation.Height - upperGradientHeight); using (var pattern = new Cairo.LinearGradient (0, upperGradientHeight, 0, Allocation.Height)) { pattern.AddColorStop (0, new Cairo.Color (0.8, 1.0, 0.8)); pattern.AddColorStop (1, new Cairo.Color (0.6, 0.8, 0.6)); cr.Pattern = pattern; cr.Fill (); } cr.LineWidth = 1; cr.Line (0, 0, Allocation.Width, 0); cr.Color = new Cairo.Color (0.4, 0.6, 0.4); cr.Stroke (); double xPos = padding, yPos = padding; var layout = PangoUtil.CreateLayout (this); int w, h; layout.SetText (new string ('X', maxLength)); layout.GetPixelSize (out w, out h); foreach (Category cat in categories) { yPos = padding; cr.MoveTo (xPos, yPos); layout.SetMarkup ("<b>" + cat.Title + "</b>"); cr.Color = (HslColor)Style.Text (StateType.Normal); cr.ShowLayout (layout); layout.SetMarkup (""); int w2, h2; layout.GetPixelSize (out w2, out h2); yPos += h2; yPos += headerDistance; var startY = yPos; int curItem = 0; int row = 0; var iconHeight = Math.Max (h, cat.Items [0].Icon.Height + 2); if (cat.FirstVisibleItem > 0) { Gtk.Style.PaintArrow (Style, e.Window, State, ShadowType.None, new Rectangle ((int)xPos, (int)yPos, w, h), this, "", ArrowType.Up, true, (int)xPos, (int)yPos, w, h); yPos += iconHeight; curItem++; } for (int i = cat.FirstVisibleItem; i < cat.Items.Count; i++) { var item = cat.Items [i]; if (curItem + 1 >= maxItems && row + 1 >= maxRows && i + 1 < cat.Items.Count) { Gtk.Style.PaintArrow (Style, e.Window, State, ShadowType.None, new Rectangle ((int)xPos, (int)yPos, w, h), this, "", ArrowType.Down, true, (int)xPos, (int)yPos, w, h); break; } if (item == ActiveItem) { cr.Rectangle (xPos + 0.5, yPos + 0.5, w + item.Icon.Width + 2, iconHeight); using (var pattern = new Cairo.LinearGradient (xPos, yPos, xPos, yPos + iconHeight * 2)) { pattern.AddColorStop (0, (HslColor)Style.Base (StateType.Selected)); pattern.AddColorStop (1, new Cairo.Color (0.8, 1.0, 0.8)); cr.Pattern = pattern; cr.FillPreserve (); } cr.Color = (HslColor)Style.Base (StateType.Selected); cr.Stroke (); cr.Color = (HslColor)Style.Text (StateType.Selected); } else if (item == hoverItem) { cr.Rectangle (xPos + 0.5, yPos + 0.5, w + item.Icon.Width + 2, iconHeight); using (var pattern = new Cairo.LinearGradient (xPos, yPos, xPos, yPos + iconHeight)) { pattern.AddColorStop (0, new Cairo.Color (0.6, 0.8, 0.6)); pattern.AddColorStop (1, new Cairo.Color (0.8, 1.0, 0.8)); cr.Pattern = pattern; cr.Fill (); } cr.Color = (HslColor)Style.Text (StateType.Normal); } else { cr.Color = (HslColor)Style.Text (StateType.Normal); } cr.MoveTo (xPos + item.Icon.Width + 2, yPos + (iconHeight - h) / 2); layout.SetText (Ellipsize (item.ListTitle ?? item.Title, maxLength)); cr.ShowLayout (layout); e.Window.DrawPixbuf (Style.BaseGC (StateType.Normal), item.Icon, 0, 0, (int)xPos, (int)(yPos + (iconHeight - item.Icon.Height) / 2), item.Icon.Width, item.Icon.Height, RgbDither.None, 0, 0); yPos += iconHeight; if (++curItem >= maxItems) { curItem = 0; yPos = startY; xPos += w + cat.Items [0].Icon.Width + 2 + padding; row++; } } xPos += w + cat.Items [0].Icon.Width + 2 + padding; } layout.Dispose (); } return true; }