protected override void OnSizeRequested(ref Requisition req) { maxLength = 15; foreach (var cat in categories) { foreach (var item in cat.Items) { maxLength = Math.Min(30, Math.Max(maxLength, (item.ListTitle ?? item.Title).Length)); } } var layout = PangoUtil.CreateLayout(this); int w, h; layout.SetText(new string ('X', maxLength)); layout.GetPixelSize(out w, out h); layout.Dispose(); int totalWidth = 0; int totalHeight = 0; foreach (var cat in categories) { var iconHeight = Math.Max(h, cat.Items[0].Icon.Height + 2); var iconWidth = cat.Items[0].Icon.Width + 2 + w; var headerHeight = h + headerDistance; totalHeight = Math.Max(totalHeight, headerHeight + (Math.Min(cat.Items.Count, maxItems)) * iconHeight); totalWidth += (1 + Math.Min(maxRows - 1, cat.Items.Count / maxItems)) * iconWidth; } req.Width = totalWidth + padding * 2 + (categories.Count - 1) * padding; req.Height = totalHeight + padding * 2; }
protected override void OnBeginPrint(PrintContext context) { layout = PangoUtil.CreateLayout(context); layout.FontDescription = settings.Font; using (var PangoContext = context.CreatePangoContext()) using (var metrics = PangoContext.GetMetrics(settings.Font, PangoContext.Language)) { lineHeight = Math.Ceiling(0.5 + (metrics.Ascent + metrics.Descent) / Pango.Scale.PangoScale); } SetHeaderFormat(settings.HeaderFormat); SetFooterFormat(settings.FooterFormat); style = SyntaxHighlightingService.GetEditorTheme(settings.EditorTheme); pageWidth = context.PageSetup.GetPageWidth(Unit.Pixel); pageHeight = context.PageSetup.GetPageHeight(Unit.Pixel); double contentHeight = pageHeight - (headerLines > 0? settings.HeaderPadding : 0) - (footerLines > 0? settings.FooterPadding : 0); linesPerPage = (int)(contentHeight / lineHeight) - (headerLines + footerLines); totalPages = (int)Math.Ceiling((double)editor.LineCount / linesPerPage); NPages = totalPages; base.OnBeginPrint(context); }
protected override void OnBeginPrint(PrintContext context) { layout = PangoUtil.CreateLayout(context); layout.FontDescription = settings.Font; layout.FontDescription.Weight = Pango.Weight.Bold; layout.SetText(" "); int w, h; layout.GetSize(out w, out h); this.lineHeight = h / Pango.Scale.PangoScale; layout.FontDescription.Weight = Pango.Weight.Normal; SetHeaderFormat(settings.HeaderFormat); SetFooterFormat(settings.FooterFormat); style = Mono.TextEditor.Highlighting.SyntaxModeService.GetColorStyle(null, settings.ColorScheme); pageWidth = context.PageSetup.GetPageWidth(Unit.Mm); pageHeight = context.PageSetup.GetPageHeight(Unit.Mm); double contentHeight = pageHeight - (headerLines > 0? settings.HeaderPadding : 0) - (footerLines > 0? settings.FooterPadding : 0); linesPerPage = (int)(contentHeight / lineHeight) - (headerLines + footerLines); totalPages = (int)Math.Ceiling((double)doc.LineCount / linesPerPage); NPages = totalPages; base.OnBeginPrint(context); }
protected override bool OnExposeEvent(Gdk.EventExpose evnt) { if (HasPolicies) { return(base.OnExposeEvent(evnt)); } var win = evnt.Window; win.Clear(); if (string.IsNullOrEmpty(message)) { return(true); } using (var layout = PangoUtil.CreateLayout(this)) { layout.SetMarkup("<i>" + GLib.Markup.EscapeText(message) + "</i>"); int w, h; layout.GetPixelSize(out w, out h); var a = Allocation; var x = (a.Width - w) / 2; var y = (a.Height - h) / 2; win.DrawLayout(Style.TextGC(Gtk.StateType.Normal), x, y, layout); } return(true); }
private void CreateLayout() { if (layout != null) { layout.Dispose(); } layout = PangoUtil.CreateLayout(this, null); if (use_markup) { layout.Markup = brokentext != null ? brokentext : (text ?? string.Empty); } else { layout.Text = brokentext != null ? brokentext : (text ?? string.Empty); } layout.Trimming = wrapMode; if (width >= 0) { layout.Width = width; } else { layout.Width = -1; } QueueForReallocate(); }
void RenderLineNumberIcon(Widget widget, Cairo.Context cr, Gdk.Rectangle cell_area, int markupHeight, int yOffset) { if (!IsStackFrame) { return; } cr.Save(); #if CENTER_ROUNDED_RECTANGLE cr.Translate(cell_area.X + Padding, (cell_area.Y + (cell_area.Height - RoundedRectangleHeight) / 2.0)); #else cr.Translate(cell_area.X + Padding, cell_area.Y + Padding + yOffset); #endif cr.Antialias = Cairo.Antialias.Subpixel; cr.RoundedRectangle(0.0, 0.0, RoundedRectangleWidth, RoundedRectangleHeight, RoundedRectangleRadius); cr.Clip(); if (IsUserCode) { cr.SetSourceRGBA(0.90, 0.60, 0.87, 1.0); // 230, 152, 223 } else { cr.SetSourceRGBA(0.77, 0.77, 0.77, 1.0); // 197, 197, 197 } cr.RoundedRectangle(0.0, 0.0, RoundedRectangleWidth, RoundedRectangleHeight, RoundedRectangleRadius); cr.Fill(); cr.SetSourceRGBA(0.0, 0.0, 0.0, 0.11); cr.RoundedRectangle(0.0, 0.0, RoundedRectangleWidth, RoundedRectangleHeight, RoundedRectangleRadius); cr.LineWidth = 2; cr.Stroke(); using (var layout = PangoUtil.CreateLayout(widget, LineNumber != -1 ? LineNumber.ToString() : "???")) { layout.Alignment = Pango.Alignment.Left; layout.FontDescription = LineNumberFont; int width, height; layout.GetPixelSize(out width, out height); double y_offset = (RoundedRectangleHeight - height) / 2.0; double x_offset = (RoundedRectangleWidth - width) / 2.0; // render the text shadow cr.Save(); cr.SetSourceRGBA(0.0, 0.0, 0.0, 0.34); cr.Translate(x_offset, y_offset + 1); cr.ShowLayout(layout); cr.Restore(); cr.SetSourceRGBA(1.0, 1.0, 1.0, 1.0); cr.Translate(x_offset, y_offset); cr.ShowLayout(layout); } cr.Restore(); }
private void CreateLayout() { if (layout != null) { layout.Dispose(); } layout = PangoUtil.CreateLayout(this, null); if (use_markup) { layout.SetMarkup(brokentext != null? brokentext : (text ?? string.Empty)); } else { layout.SetText(brokentext != null? brokentext : (text ?? string.Empty)); } layout.Indent = (int)(indent * Pango.Scale.PangoScale); layout.Wrap = wrapMode; if (width >= 0) { layout.Width = (int)(width * Pango.Scale.PangoScale); } else { layout.Width = int.MaxValue; } QueueResize(); }
protected override void Render(Gdk.Drawable window, Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, CellRendererState flags) { if (!CanRender) { return; } using (var cr = Gdk.CairoHelper.Create(window)) { #if CENTER_ROUNDED_RECTANGLE cr.Translate((cell_area.X + (cell_area.Width - RoundedRectangleWidth) / 2.0), (cell_area.Y + (cell_area.Height - RoundedRectangleHeight) / 2.0)); #else cr.Translate((cell_area.X + (cell_area.Width - RoundedRectangleWidth) / 2.0), cell_area.Y + 4); #endif cr.Antialias = Cairo.Antialias.Subpixel; cr.RoundedRectangle(0.0, 0.0, RoundedRectangleWidth, RoundedRectangleHeight, RoundedRectangleRadius); cr.Clip(); if (IsUserCode) { cr.SetSourceRGBA(0.90, 0.60, 0.87, 1.0); // 230, 152, 223 } else { cr.SetSourceRGBA(0.77, 0.77, 0.77, 1.0); // 197, 197, 197 } cr.RoundedRectangle(0.0, 0.0, RoundedRectangleWidth, RoundedRectangleHeight, RoundedRectangleRadius); cr.Fill(); cr.SetSourceRGBA(0.0, 0.0, 0.0, 0.11); cr.RoundedRectangle(0.0, 0.0, RoundedRectangleWidth, RoundedRectangleHeight, RoundedRectangleRadius); cr.LineWidth = 2; cr.Stroke(); using (var layout = PangoUtil.CreateLayout(widget, LineNumber != -1 ? LineNumber.ToString() : "???")) { layout.Alignment = Pango.Alignment.Left; layout.FontDescription = DefaultFont; int width, height; layout.GetPixelSize(out width, out height); double y_offset = (RoundedRectangleHeight - height) / 2.0; double x_offset = (RoundedRectangleWidth - width) / 2.0; // render the text shadow cr.Save(); cr.SetSourceRGBA(0.0, 0.0, 0.0, 0.34); cr.Translate(x_offset, y_offset + 1); cr.ShowLayout(layout); cr.Restore(); cr.SetSourceRGBA(1.0, 1.0, 1.0, 1.0); cr.Translate(x_offset, y_offset); cr.ShowLayout(layout); } } }
protected override bool OnExposeEvent(Gdk.EventExpose evnt) { using (Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window)) { cr.Rectangle(evnt.Region.Clipbox.X, evnt.Region.Clipbox.Y, evnt.Region.Clipbox.Width, evnt.Region.Clipbox.Height); cr.SetSourceColor(editor.ColorStyle.PlainText.Background); cr.Fill(); using (var layout = PangoUtil.CreateLayout(editor)) { layout.FontDescription = editor.Options.Font; layout.SetText("000,00-00"); int minstatusw, minstatush; layout.GetPixelSize(out minstatusw, out minstatush); var line = editor.GetLine(editor.Caret.Line); var visColumn = line.GetVisualColumn(editor.GetTextEditorData(), editor.Caret.Column); if (visColumn != editor.Caret.Column) { layout.SetText(editor.Caret.Line + "," + editor.Caret.Column + "-" + visColumn); } else { layout.SetText(editor.Caret.Line + "," + editor.Caret.Column); } int statusw, statush; layout.GetPixelSize(out statusw, out statush); statusw = System.Math.Max(statusw, minstatusw); statusw += 8; cr.MoveTo(Allocation.Width - statusw, 0); statusw += 8; cr.SetSourceColor(editor.ColorStyle.PlainText.Foreground); cr.ShowLayout(layout); layout.SetText(statusText ?? ""); int w, h; layout.GetPixelSize(out w, out h); var x = System.Math.Min(0, -w + Allocation.Width - editor.TextViewMargin.CharWidth - statusw); cr.MoveTo(x, 0); cr.SetSourceColor(editor.ColorStyle.PlainText.Foreground); cr.ShowLayout(layout); if (ShowCaret) { #if false if (editor.TextViewMargin.caretBlink) { cr.Rectangle(w + x, 0, (int)editor.TextViewMargin.CharWidth, (int)editor.LineHeight); cr.Fill(); } #endif } } } return(true); }
protected override void OnDraw(Xwt.Drawing.Context cr, Rectangle bound) { { cr.Rectangle(bound.X, bound.Y, bound.Width, bound.Height); cr.SetSourceColor(editor.ColorStyle.PlainText.Background); cr.Fill(); using (var layout = PangoUtil.CreateLayout(editor)) { layout.Font = editor.Options.Font; layout.Text = "000,00-00"; var mins = layout.GetSize(); var line = editor.GetLine(editor.Caret.Line); var visColumn = line.GetVisualColumn(editor.GetTextEditorData(), editor.Caret.Column); if (visColumn != editor.Caret.Column) { layout.Text = editor.Caret.Line + "," + editor.Caret.Column + "-" + visColumn; } else { layout.Text = editor.Caret.Line + "," + editor.Caret.Column; } var statuss = layout.GetSize(); statuss.Width = System.Math.Max(statuss.Width, mins.Width); statuss.Width += 8; cr.MoveTo(Size.Width - statuss.Width, 0); statuss.Width += 8; cr.SetSourceColor(editor.ColorStyle.PlainText.Foreground); cr.ShowLayout(layout); layout.Text = statusText ?? ""; var size = layout.GetSize(); var x = System.Math.Min(0, -size.Width + Size.Width - editor.TextViewMargin.CharWidth - statuss.Width); cr.MoveTo(x, 0); cr.SetSourceColor(editor.ColorStyle.PlainText.Foreground); cr.ShowLayout(layout); if (ShowCaret) { if (editor.TextViewMargin.caretBlink) { cr.Rectangle(size.Width + x, 0, (int)editor.TextViewMargin.CharWidth, (int)editor.LineHeight); cr.Fill(); } } } } }
Item GetItemAt(double x, double y) { double xPos = padding, yPos = padding; using (var layout = PangoUtil.CreateLayout(this)) { int w, h; foreach (Category cat in categories) { if (cat.Items.Count == 0) { continue; } yPos = padding; layout.SetMarkup("<b>" + cat.Title + "</b>"); layout.SetMarkup(""); layout.GetPixelSize(out w, out h); yPos += h; yPos += headerDistance; var startY = yPos; int curItem = 0; layout.SetText(new string ('X', maxLength)); layout.GetPixelSize(out w, out h); var iconHeight = Math.Max(h, cat.Items[0].Icon.Height + 2) + itemPadding * 2; if (cat.FirstVisibleItem > 0) { yPos += iconHeight; curItem++; } for (int i = cat.FirstVisibleItem; i < cat.Items.Count; i++) { var item = cat.Items[i]; int itemWidth = w + item.Icon.Width + 2 + itemPadding * 2; if (xPos <= x && yPos <= y && x < xPos + itemWidth && y < yPos + iconHeight) { return(item); } yPos += iconHeight; if (++curItem >= maxItems) { curItem = 0; yPos = startY; xPos += w + cat.Items[0].Icon.Width + 2 + padding + itemPadding * 2; } } xPos += w + cat.Items[0].Icon.Width + 2 + padding + itemPadding * 2; } } return(null); }
void RenderLineNumberIcon(Widget widget, Cairo.Context cr, Gdk.Rectangle cell_area, int markupHeight, int yOffset) { if (Frame == null) { return; } cr.Save(); #if CENTER_ROUNDED_RECTANGLE cr.Translate(cell_area.X + Padding, (cell_area.Y + (cell_area.Height - RoundedRectangleHeight) / 2.0)); #else cr.Translate(cell_area.X + Padding, cell_area.Y + Padding + yOffset); #endif cr.Antialias = Cairo.Antialias.Subpixel; cr.RoundedRectangle(0.0, 0.0, RoundedRectangleWidth, RoundedRectangleHeight, RoundedRectangleRadius); cr.Clip(); if (IsUserCode) { cr.SetSourceColor(Styles.ExceptionCaughtDialog.LineNumberInUserCodeBackgroundColor.ToCairoColor()); // 230, 152, 223 } else { cr.SetSourceColor(Styles.ExceptionCaughtDialog.LineNumberBackgroundColor.ToCairoColor()); // 197, 197, 197 } cr.RoundedRectangle(0.0, 0.0, RoundedRectangleWidth, RoundedRectangleHeight, RoundedRectangleRadius); cr.Fill(); var lineNumber = !string.IsNullOrEmpty(Frame.File) ? Frame.Line : -1; using (var layout = PangoUtil.CreateLayout(widget, lineNumber != -1 ? lineNumber.ToString() : "???")) { layout.Alignment = Pango.Alignment.Left; layout.FontDescription = LineNumberFont; int width, height; layout.GetPixelSize(out width, out height); double y_offset = (RoundedRectangleHeight - height) / 2.0; double x_offset = (RoundedRectangleWidth - width) / 2.0; cr.SetSourceColor(Styles.ExceptionCaughtDialog.LineNumberTextColor.ToCairoColor()); cr.Translate(x_offset, y_offset); cr.ShowLayout(layout); } cr.Restore(); }
void UpdateStyle() { this.GdkWindow.Background = this.Style.Base(StateType.Normal); if (layout != null) { layout.Dispose(); } layout = PangoUtil.CreateLayout(this); layout.Wrap = Pango.WrapMode.Char; FontDescription des = this.Style.FontDescription.Copy(); layout.FontDescription = des; CalcVisibleRows(); }
protected override bool OnExposeEvent(Gdk.EventExpose e) { using (Cairo.Context cr = Gdk.CairoHelper.Create(e.Window)) { cr.LineWidth = Math.Max(1.0, widget.Editor.Options.Zoom); cr.Rectangle(leftSpacer, 0, Allocation.Width, Allocation.Height); cr.SetSourceRGB(0.95, 0.95, 0.95); cr.Fill(); int startLine = widget.Editor.YToLine((int)widget.Editor.VAdjustment.Value); double startY = widget.Editor.LineToY(startLine); while (startLine > 1 && startLine < annotations.Count && annotations[startLine - 1] != null && annotations[startLine] != null && annotations[startLine - 1].Revision == annotations[startLine].Revision) { startLine--; startY -= widget.Editor.GetLineHeight(widget.Editor.Document.GetLine(startLine)); } double curY = startY - widget.Editor.VAdjustment.Value; int line = startLine; while (curY < Allocation.Bottom && line <= widget.Editor.LineCount) { double curStart = curY; // widget.JumpOverFoldings (ref line); int lineStart = line; int authorWidth = 0, revisionWidth = 0, dateWidth = 0, h = 16; Annotation ann = line <= annotations.Count ? annotations[line - 1] : null; if (ann != null) { do { widget.JumpOverFoldings(ref line); line++; } while (line <= annotations.Count && annotations[line - 1] != null && annotations[line - 1].Revision == ann.Revision); double nextY = widget.editor.LineToY(line) - widget.editor.VAdjustment.Value; if (highlightAnnotation != null && highlightAnnotation.Revision == ann.Revision && curStart <= highlightPositon && highlightPositon < nextY) { cr.Rectangle(leftSpacer, curStart + cr.LineWidth, Allocation.Width - leftSpacer, nextY - curStart - cr.LineWidth); cr.SetSourceRGB(1, 1, 1); cr.Fill(); } // use a fixed size revision to get a approx. revision width layout.SetText("88888888"); layout.GetPixelSize(out revisionWidth, out h); layout.SetText(TruncRevision(ann.Revision)); e.Window.DrawLayout(Style.BlackGC, Allocation.Width - revisionWidth - margin, (int)(curY + (widget.Editor.LineHeight - h) / 2), layout); const int dateRevisionSpacing = 16; if (ann.HasDate) { string dateTime = ann.Date.ToShortDateString(); // use a fixed size date to get a approx. date width layout.SetText(new DateTime(1999, 10, 10).ToShortDateString()); layout.GetPixelSize(out dateWidth, out h); layout.SetText(dateTime); e.Window.DrawLayout(Style.BlackGC, Allocation.Width - revisionWidth - margin - revisionWidth - dateRevisionSpacing, (int)(curY + (widget.Editor.LineHeight - h) / 2), layout); } using (var authorLayout = PangoUtil.CreateLayout(this)) { var description = Pango.FontDescription.FromString("Tahoma " + (int)(10 * widget.Editor.Options.Zoom)); authorLayout.FontDescription = description; authorLayout.SetText(ann.Author); authorLayout.GetPixelSize(out authorWidth, out h); var maxWidth = Allocation.Width - revisionWidth - margin - revisionWidth - dateRevisionSpacing; /* if (authorWidth > maxWidth) { * int idx = ann.Author.IndexOf ('<'); * if (idx > 0) * authorLayout.SetText (ann.Author.Substring (0, idx) + Environment.NewLine + ann.Author.Substring (idx)); * authorLayout.GetPixelSize (out authorWidth, out h); * }*/ cr.Save(); cr.Rectangle(0, 0, maxWidth, Allocation.Height); cr.Clip(); cr.Translate(leftSpacer + margin, (int)(curY + (widget.Editor.LineHeight - h) / 2)); cr.SetSourceRGB(0, 0, 0); cr.ShowLayout(authorLayout); cr.ResetClip(); cr.Restore(); } curY = nextY; } else { curY += widget.Editor.GetLineHeight(line); line++; widget.JumpOverFoldings(ref line); } if (ann != null && line - lineStart > 1) { string msg = GetCommitMessage(lineStart, false); if (!string.IsNullOrEmpty(msg)) { msg = Revision.FormatMessage(msg); layout.SetText(msg); layout.Width = (int)(Allocation.Width * Pango.Scale.PangoScale); using (var gc = new Gdk.GC(e.Window)) { gc.RgbFgColor = Style.Dark(State); gc.ClipRectangle = new Rectangle(0, (int)curStart, Allocation.Width, (int)(curY - curStart)); e.Window.DrawLayout(gc, (int)(leftSpacer + margin), (int)(curStart + h), layout); } } } cr.Rectangle(0, curStart, leftSpacer, curY - curStart); if (ann != null && ann != locallyModified && !string.IsNullOrEmpty(ann.Author)) { double a; if (ann != null && (maxDate - minDate).TotalHours > 0) { a = 1 - (ann.Date - minDate).TotalHours / (maxDate - minDate).TotalHours; } else { a = 1; } HslColor color = new Cairo.Color(0.90, 0.90, 1); color.L = 0.4 + a / 2; color.S = 1 - a / 2; cr.SetSourceColor(color); } else { cr.SetSourceColor(ann != null ? new Cairo.Color(1, 1, 0) : new Cairo.Color(0.95, 0.95, 0.95)); } cr.Fill(); if (ann != null) { cr.MoveTo(0, curY + 0.5); cr.LineTo(Allocation.Width, curY + 0.5); cr.SetSourceRGB(0.6, 0.6, 0.6); cr.Stroke(); } } } return(true); }
protected override bool OnExposeEvent(Gdk.EventExpose e) { using (Cairo.Context cr = Gdk.CairoHelper.Create(e.Window)) { cr.LineWidth = 1; cr.Rectangle(0, 0, Allocation.Width, 16); var pattern = new Cairo.LinearGradient(0, 0, 0, 16); 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.Rectangle(0, 16, Allocation.Width, Allocation.Height - 16); pattern = new Cairo.LinearGradient(0, 16, 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.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); 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); 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); }
protected override bool OnExposeEvent(Gdk.EventExpose e) { using (Cairo.Context cr = Gdk.CairoHelper.Create(e.Window)) { 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.SetSourceColor(Style.Text(StateType.Normal).ToCairoColor()); cr.ShowLayout(layout); if (cat.Items.Count == 0) { continue; } 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) + itemPadding * 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) { int itemWidth = w + (int)item.Icon.Width + 2 + itemPadding * 2; cr.Rectangle(xPos, yPos, itemWidth, iconHeight); cr.LineWidth = 1; cr.SetSourceColor(Style.Base(StateType.Selected).ToCairoColor()); cr.Fill(); } else if (item == hoverItem) { int itemWidth = w + (int)item.Icon.Width + 2 + itemPadding * 2; cr.Rectangle(xPos + 0.5, yPos + 0.5, itemWidth - 1, iconHeight); cr.LineWidth = 1; cr.SetSourceColor(Style.Base(StateType.Selected).ToCairoColor()); cr.Stroke(); } cr.SetSourceColor(Style.Text(item == ActiveItem? StateType.Selected : StateType.Normal).ToCairoColor()); cr.MoveTo(xPos + item.Icon.Width + 2 + itemPadding, yPos + (iconHeight - h) / 2); layout.SetText(Ellipsize(item.ListTitle ?? item.Title, maxLength)); cr.ShowLayout(layout); cr.DrawImage(this, item.Icon, (int)xPos + itemPadding, (int)(yPos + (iconHeight - item.Icon.Height) / 2)); yPos += iconHeight; if (++curItem >= maxItems) { curItem = 0; yPos = startY; xPos += w + cat.Items [0].Icon.Width + 2 + padding + itemPadding * 2; row++; } } xPos += w + cat.Items [0].Icon.Width + 2 + padding + itemPadding * 2; } layout.Dispose(); } return(true); }