protected override void Render (Gdk.Drawable window, Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, CellRendererState flags) { base.Render (window, widget, background_area, cell_area, expose_area, flags); if (PackageSourceViewModel == null) return; using (var layout = new Pango.Layout (widget.PangoContext)) { layout.Alignment = Pango.Alignment.Left; layout.SetMarkup (GetPackageSourceNameMarkup ()); int packageSourceNameWidth = GetLayoutWidth (layout); StateType state = GetState (widget, flags); layout.SetMarkup (GetPackageSourceDescriptionMarkup ()); window.DrawLayout (widget.Style.TextGC (state), cell_area.X + textSpacing, cell_area.Y + textTopSpacing, layout); if (!PackageSourceViewModel.IsValid) { using (var ctx = Gdk.CairoHelper.Create (window)) { ctx.DrawImage (widget, warningImage, cell_area.X + textSpacing + packageSourceNameWidth + imageSpacing, cell_area.Y + textTopSpacing); } layout.SetMarkup (GetPackageSourceErrorMarkup ()); int packageSourceErrorTextX = cell_area.X + textSpacing + packageSourceNameWidth + (int)warningImage.Width + (2 * imageSpacing); window.DrawLayout (widget.Style.TextGC (state), packageSourceErrorTextX, cell_area.Y + textTopSpacing, layout); } } }
public int ComputeRowHeight(Widget widget) { int lw, lh; Pango.Layout layout = new Pango.Layout (widget.PangoContext); layout.SetMarkup ("<big>W</big>"); layout.GetPixelSize (out lw, out lh); layout.Dispose (); return lh + 8; }
public override Gdk.Size Measure(Widget widget) { using (var layout = new Pango.Layout (widget.PangoContext)) { int lw, lh; layout.SetMarkup ("<b>W</b>\n<small><i>W</i></small>"); layout.GetPixelSize (out lw, out lh); return new Gdk.Size (0, lh + 8); } }
public BigList (IListModel provider) { this.provider = provider; //Accessibility RefAccessible ().Role = Atk.Role.List; adjustment = new Gtk.Adjustment (0, 0, provider.Rows, 1, 1, 1); adjustment.ValueChanged += new EventHandler (ValueChangedHandler); layout = new Pango.Layout (PangoContext); ExposeEvent += new ExposeEventHandler (ExposeHandler); ButtonPressEvent += new ButtonPressEventHandler (ButtonPressEventHandler); ButtonReleaseEvent += new ButtonReleaseEventHandler (ButtonReleaseEventHandler); KeyPressEvent += new KeyPressEventHandler (KeyHandler); Realized += new EventHandler (RealizeHandler); Unrealized += new EventHandler (UnrealizeHandler); ScrollEvent += new ScrollEventHandler (ScrollHandler); SizeAllocated += new SizeAllocatedHandler (SizeAllocatedHandler); MotionNotifyEvent += new MotionNotifyEventHandler (MotionNotifyEventHandler); AddEvents ((int) EventMask.ButtonPressMask | (int) EventMask.ButtonReleaseMask | (int) EventMask.KeyPressMask | (int) EventMask.PointerMotionMask); CanFocus = true; style_widget = new EventBox (); style_widget.StyleSet += new StyleSetHandler (StyleHandler); // // Compute the height and ellipsis width of the font, // and the en_width for our ellipsizing algorithm // layout.SetMarkup (ellipsis); layout.GetPixelSize (out ellipsis_width, out line_height); layout.SetMarkup ("n"); layout.GetPixelSize (out en_width, out line_height); layout.SetMarkup ("W"); layout.GetPixelSize (out en_width, out line_height); old_width = Allocation.Width; }
protected override void Render (Drawable window, Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, CellRendererState flags) { try{ Gdk.Rectangle text_area1 = new Gdk.Rectangle(); Gdk.Rectangle text_area2 = new Gdk.Rectangle(); Gdk.Rectangle text_area3 = new Gdk.Rectangle(); text_area1.Y= cell_area.Y; text_area2.Y= cell_area.Y+33; text_area3.X = cell_area.Width-20; text_area3.Y= cell_area.Y+33; text_area3.Width = 75; Pango.Layout text_l1 = new Pango.Layout(widget.PangoContext); text_l1.FontDescription = Pango.FontDescription.FromString ("Meiryo,Arial 10.5"); text_l1.SetText(text1); Pango.Layout text_l2 = new Pango.Layout(widget.PangoContext); text_l2.FontDescription = Pango.FontDescription.FromString ("Meiryo,MS Gothic,Arial 8"); text_l2.SetText(text2); text_l2.Alignment = Pango.Alignment.Right; Pango.Layout text_l3 = new Pango.Layout(widget.PangoContext); text_l3.Width = Pango.Units.FromPixels(text_area3.Width); text_l3.FontDescription = Pango.FontDescription.FromString ("Meiryo,MS Gothic,Arial 8"); text_l3.Alignment = Pango.Alignment.Right; text_l3.SetText(text3); text_l2.Width = Pango.Units.FromPixels(cell_area.Width-text_l3.Text.Length*8-13); StateType state = flags.HasFlag(CellRendererState.Selected) ? widget.IsFocus ? StateType.Selected : StateType.Active : StateType.Normal; text_l3.SetMarkup("<span color=" + (char)34 + "grey" + (char)34 + ">" + text_l3.Text + "</span>");; window.DrawLayout(widget.Style.TextGC(state), 55, text_area1.Y, text_l1); window.DrawLayout(widget.Style.TextGC(state), 55, text_area2.Y, text_l2); window.DrawLayout(widget.Style.TextGC(state), text_area3.X, text_area3.Y, text_l3); text_l1.Dispose (); text_l2.Dispose (); text_l3.Dispose (); }catch(Exception e){ Console.WriteLine (e); } }
protected override bool OnExposeEvent (Gdk.EventExpose evnt) { Pango.Layout la = new Pango.Layout (PangoContext); int w, h; if (UseMarkup) la.SetMarkup (Text); else la.SetText (Text); la.GetPixelSize (out w, out h); int tx = Allocation.X + (int) Xpad + (int) ((float)(Allocation.Width - (int)(Xpad*2) - w) * Xalign); int ty = Allocation.Y + (int) Ypad + (int) ((float)(Allocation.Height - (int)(Ypad*2) - h) * Yalign); using (var ctx = CairoHelper.Create (evnt.Window)) { ctx.SetSourceColor (Style.Text (State).ToCairoColor ()); ctx.MoveTo (tx, ty); // In order to get the same result as in MonoDevelop.Components.DockNotebook.TabStrip.DrawTab() // (document tabs) we need to draw using a LinearGradient (because of issues below), // but we don't want to mask the actual text here, like in the doc tabs. // Therefore we use a LinearGradient and mask only the last vertical pixel line // of the label with 0.99 alpha, which forces Cairo to render the whole layout // in the desired way. // Semi-transparent gradient disables sub-pixel rendering of the label (reverting to grayscale antialiasing). // As Mac sub-pixel font rendering looks stronger than grayscale rendering, the label used in pad tabs // looked different. We need to simulate same gradient treatment as we have in document tabs. using (var lg = new LinearGradient (tx + w - 1, 0, tx + w, 0)) { var color = Style.Text (State).ToCairoColor (); lg.AddColorStop (0, color); color.A = 0.99; lg.AddColorStop (1, color); ctx.SetSource (lg); Pango.CairoHelper.ShowLayout (ctx, la); } } la.Dispose (); return true; }
protected override bool OnExposeEvent (Gdk.EventExpose evnt) { if (!dropShadowVisible) return base.OnExposeEvent (evnt); Pango.Layout la = new Pango.Layout (PangoContext); int w, h; if (UseMarkup) la.SetMarkup (Text); else la.SetText (Text); la.GetPixelSize (out w, out h); int tx = Allocation.X + (int) Xpad + (int) ((float)(Allocation.Width - (int)(Xpad*2) - w) * Xalign); int ty = Allocation.Y + (int) Ypad + (int) ((float)(Allocation.Height - (int)(Ypad*2) - h) * Yalign); GdkWindow.DrawLayout (Style.TextGC (State), tx, ty, la); la.Dispose (); return true; }
protected override bool OnExposeEvent(EventExpose evnt) { using (var ctx = Gdk.CairoHelper.Create(GdkWindow)) { ctx.Rectangle(0, 0, Allocation.Width, Allocation.Height); using (var g = new Cairo.LinearGradient(0, 0, 0, Allocation.Height)) { g.AddColorStop(0, Styles.BreadcrumbBackgroundColor); g.AddColorStop(1, Styles.BreadcrumbGradientEndColor); ctx.SetSource(g); } ctx.Fill(); if (widths == null) { return(true); } // Calculate the total required with, and the reduction to be applied in case it doesn't fit the available space int totalWidth = widths.Sum(); totalWidth += leftPadding + (arrowSize + arrowRightPadding) * leftPath.Length - 1; totalWidth += rightPadding + arrowSize * rightPath.Length - 1; int[] currentWidths = widths; bool widthReduced = false; int overflow = totalWidth - Allocation.Width; if (overflow > 0) { currentWidths = ReduceWidths(overflow); widthReduced = true; } // Render the paths int textTopPadding = topPadding + (height - textHeight) / 2; int xpos = leftPadding, ypos = topPadding; for (int i = 0; i < leftPath.Length; i++) { bool last = i == leftPath.Length - 1; // Reduce the item size when required int itemWidth = currentWidths [i]; int x = xpos; xpos += itemWidth; if (hoverIndex >= 0 && hoverIndex < Path.Length && leftPath [i] == Path [hoverIndex] && (menuVisible || pressed || hovering)) { DrawButtonBorder(ctx, x - padding, itemWidth + padding + padding); } int textOffset = 0; if (leftPath [i].DarkIcon != null) { int iy = (height - (int)leftPath [i].DarkIcon.Height) / 2 + topPadding; ctx.DrawImage(this, leftPath [i].DarkIcon, x, iy); textOffset += (int)leftPath [i].DarkIcon.Width + iconSpacing; } layout.Attributes = (i == activeIndex) ? boldAtts : null; layout.SetMarkup(GetFirstLineFromMarkup(leftPath [i].Markup)); ctx.Save(); // If size is being reduced, ellipsize it bool showText = true; if (widthReduced) { int w = itemWidth - textOffset; if (w > 0) { ctx.Rectangle(x + textOffset, textTopPadding, w, height); ctx.Clip(); } else { showText = false; } } else { layout.Width = -1; } if (showText) { // Text ctx.SetSourceColor(Styles.BreadcrumbTextColor.ToCairoColor()); ctx.MoveTo(x + textOffset, textTopPadding); Pango.CairoHelper.ShowLayout(ctx, layout); } ctx.Restore(); if (!last) { xpos += arrowLeftPadding; if (leftPath [i].IsPathEnd) { Style.PaintVline(Style, GdkWindow, State, evnt.Area, this, "", ypos, ypos + height, xpos - arrowSize / 2); } else { int arrowH = Math.Min(height, arrowSize); int arrowY = ypos + (height - arrowH) / 2; DrawPathSeparator(ctx, xpos, arrowY, arrowH); } xpos += arrowSize + arrowRightPadding; } } int xposRight = Allocation.Width - rightPadding; for (int i = 0; i < rightPath.Length; i++) { // bool last = i == rightPath.Length - 1; // Reduce the item size when required int itemWidth = currentWidths [i + leftPath.Length]; xposRight -= itemWidth; xposRight -= arrowSize; int x = xposRight; if (hoverIndex >= 0 && hoverIndex < Path.Length && rightPath [i] == Path [hoverIndex] && (menuVisible || pressed || hovering)) { DrawButtonBorder(ctx, x - padding, itemWidth + padding + padding); } int textOffset = 0; if (rightPath [i].DarkIcon != null) { ctx.DrawImage(this, rightPath [i].DarkIcon, x, ypos); textOffset += (int)rightPath [i].DarkIcon.Width + padding; } layout.Attributes = (i == activeIndex) ? boldAtts : null; layout.SetMarkup(GetFirstLineFromMarkup(rightPath [i].Markup)); ctx.Save(); // If size is being reduced, ellipsize it bool showText = true; if (widthReduced) { int w = itemWidth - textOffset; if (w > 0) { ctx.Rectangle(x + textOffset, textTopPadding, w, height); ctx.Clip(); } else { showText = false; } } else { layout.Width = -1; } if (showText) { // Text ctx.SetSourceColor(Styles.BreadcrumbTextColor.ToCairoColor()); ctx.MoveTo(x + textOffset, textTopPadding); Pango.CairoHelper.ShowLayout(ctx, layout); } ctx.Restore(); } ctx.MoveTo(0, Allocation.Height - 0.5); ctx.RelLineTo(Allocation.Width, 0); ctx.SetSourceColor(Styles.BreadcrumbBottomBorderColor); ctx.LineWidth = 1; ctx.Stroke(); } return(true); }
public override void DrawAfterEol (TextEditor textEditor, Cairo.Context g, double y, EndOfLineMetrics metrics) { if (!IsVisible) return; EnsureLayoutCreated (editor); int errorCounterWidth = 0, eh = 0; if (errorCountLayout != null) { errorCountLayout.GetPixelSize (out errorCounterWidth, out eh); errorCounterWidth = Math.Max (15, Math.Max (errorCounterWidth + 3, (int)(editor.LineHeight * 3 / 4))); } var sx = metrics.TextRenderEndPosition; var width = LayoutWidth + errorCounterWidth + editor.LineHeight; var drawLayout = layouts[0].Layout; int ex = 0 , ey = 0; bool customLayout = true; //sx + width > editor.Allocation.Width; bool hideText = false; bubbleIsReduced = customLayout; var showErrorCount = errorCounterWidth > 0 && errorCountLayout != null; if (customLayout) { width = editor.Allocation.Width - sx; string text = layouts[0].Layout.Text; drawLayout = new Pango.Layout (editor.PangoContext); drawLayout.FontDescription = cache.fontDescription; var paintWidth = (width - errorCounterWidth - editor.LineHeight + 4); var minWidth = Math.Max (17, errorCounterWidth) + editor.LineHeight; if (paintWidth < minWidth) { hideText = true; drawLayout.SetMarkup ("<span weight='heavy'>···</span>"); width = minWidth; showErrorCount = false; sx = Math.Min (sx, editor.Allocation.Width - width); } else { drawLayout.Ellipsize = Pango.EllipsizeMode.End; drawLayout.Width = (int)(paintWidth * Pango.Scale.PangoScale); drawLayout.SetText (text); int w2, h2; drawLayout.GetPixelSize (out w2, out h2); width = w2 + errorCounterWidth + editor.LineHeight; } } bubbleDrawX = sx - editor.TextViewMargin.XOffset; bubbleDrawY = y; bubbleWidth = width; var bubbleHeight = editor.LineHeight - 1; g.RoundedRectangle (sx, y + 1, width, bubbleHeight, editor.LineHeight / 2 - 1); g.SetSourceColor (TagColor.Color); g.Fill (); // Draw error count icon if (showErrorCount) { var errorCounterHeight = bubbleHeight - 2; var errorCounterX = sx + width - errorCounterWidth - 3; var errorCounterY = y + 1 + (bubbleHeight - errorCounterHeight) / 2; g.RoundedRectangle ( errorCounterX - 1, errorCounterY - 1, errorCounterWidth + 2, errorCounterHeight + 2, editor.LineHeight / 2 - 3 ); g.SetSourceColor (new Cairo.Color (0, 0, 0, 0.081)); g.Fill (); g.RoundedRectangle ( errorCounterX, errorCounterY, errorCounterWidth, errorCounterHeight, editor.LineHeight / 2 - 3 ); using (var lg = new Cairo.LinearGradient (errorCounterX, errorCounterY, errorCounterX, errorCounterY + errorCounterHeight)) { lg.AddColorStop (0, CounterColor.Color); lg.AddColorStop (1, CounterColor.Color.AddLight (-0.1)); g.Pattern = lg; g.Fill (); } g.Save (); int ew; errorCountLayout.GetPixelSize (out ew, out eh); g.Translate ( errorCounterX + (errorCounterWidth - ew) / 2, errorCounterY + (errorCounterHeight - eh) / 2 ); g.SetSourceColor (CounterColor.SecondColor); g.ShowLayout (errorCountLayout); g.Restore (); } // Draw label text if (!showErrorCount || !hideText) { g.Save (); g.Translate (sx + editor.LineHeight / 2, y + (editor.LineHeight - layouts [0].Height) / 2 + 1); // draw shadow g.SetSourceColor (MessageBubbleCache.ShadowColor); g.ShowLayout (drawLayout); g.Translate (0, -1); g.SetSourceColor (TagColor.SecondColor); g.ShowLayout (drawLayout); g.Restore (); } if (customLayout) drawLayout.Dispose (); }
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 (); }
void breakText() { brokentext = null; if ((!breakOnCamelCasing && !breakOnPunctuation) || string.IsNullOrEmpty(text)) { QueueResize(); return; } System.Text.StringBuilder sb = new System.Text.StringBuilder(text.Length); bool prevIsLower = false; bool inMarkup = false; bool inEntity = false; for (int i = 0; i < text.Length; i++) { char c = text[i]; //ignore markup if (use_markup) { switch (c) { case '<': inMarkup = true; sb.Append(c); continue; case '>': inMarkup = false; sb.Append(c); continue; case '&': inEntity = true; sb.Append(c); continue; case ';': if (inEntity) { inEntity = false; sb.Append(c); continue; } break; } } if (inMarkup || inEntity) { sb.Append(c); continue; } //insert breaks using zero-width space unicode char if ((breakOnPunctuation && char.IsPunctuation(c)) || (breakOnCamelCasing && prevIsLower && char.IsUpper(c))) { sb.Append('\u200b'); } sb.Append(c); if (breakOnCamelCasing) { prevIsLower = char.IsLower(c); } } brokentext = sb.ToString(); if (layout != null) { if (use_markup) { layout.SetMarkup(brokentext != null? brokentext : (text ?? string.Empty)); } else { layout.SetText(brokentext != null? brokentext : (text ?? string.Empty)); } } QueueResize(); }
protected override void OnSizeAllocated (Gdk.Rectangle allocation) { base.OnSizeAllocated (allocation); if (!resizeRequested) return; using (var layout = new Pango.Layout (this.PangoContext)) { layout.Width = (int)(allocation.Width * Pango.Scale.PangoScale); layout.Wrap = Pango.WrapMode.Word; layout.Alignment = Pango.Alignment.Left; layout.SetMarkup (Markup); int w, h; layout.GetPixelSize (out w, out h); if (h > 0 && h != allocation.Height) { HeightRequest = h; resizeRequested = false; QueueResize (); } } }
public LineRenderer (Pango.Context ctx, string str) { var pieces = str.Split (null as string[], StringSplitOptions.RemoveEmptyEntries); List<TokenRenderer> line = new List<TokenRenderer> (); var currentLine = ""; var desc = ctx.FontDescription.Copy (); desc.AbsoluteSize = Pango.Units.FromPixels (14); desc.Weight = Pango.Weight.Bold; var layout = new Pango.Layout (ctx); layout.SetMarkup (" "); int w, h; layout.GetPixelSize (out w, out h); Spacing = w; foreach (var token in pieces) { if (rx.IsMatch (token)) { if (!String.IsNullOrEmpty (currentLine)) line.Add (new TokenRenderer (ctx, currentLine, false)); line.Add (new TokenRenderer (ctx, token.Substring (1, token.Length - 2), true)); currentLine = ""; } else { if (!String.IsNullOrEmpty (currentLine)) currentLine += " "; currentLine += token; } } if (!String.IsNullOrEmpty (currentLine)) line.Add (new TokenRenderer (ctx, currentLine, false)); tokens = line.ToArray (); Width = tokens.Sum (t => t.Width + t.Spacing); Height = tokens.Max (t => t.Height); }
protected override bool OnExposeEvent(EventExpose evnt) { Gdk.Rectangle focusRect = new Gdk.Rectangle(0, 0, 0, 0); using (var ctx = Gdk.CairoHelper.Create(GdkWindow)) { int index = 0; ctx.Rectangle(0, 0, Allocation.Width, Allocation.Height); ctx.SetSourceColor(Styles.BreadcrumbBackgroundColor.ToCairoColor()); ctx.Fill(); if (widths == null) { return(true); } // Calculate the total required with, and the reduction to be applied in case it doesn't fit the available space bool widthReduced; var currentWidths = GetCurrentWidths(out widthReduced); // Render the paths int textTopPadding = topPadding + (height - textHeight) / 2; int xpos = leftPadding, ypos = topPadding; for (int i = 0; i < leftPath.Length; i++, index++) { bool last = i == leftPath.Length - 1; // Reduce the item size when required int itemWidth = currentWidths [i]; int x = xpos; xpos += itemWidth; SetAccessibilityFrame(leftPath [i], x, itemWidth); if (hoverIndex >= 0 && hoverIndex < Path.Length && leftPath [i] == Path [hoverIndex] && (menuVisible || pressed || hovering)) { DrawButtonBorder(ctx, x - padding, itemWidth + padding + padding); } if (index == focusedPathIndex) { focusRect = new Gdk.Rectangle(x - padding, 0, itemWidth + (padding * 2), 0); } int textOffset = 0; if (leftPath [i].DarkIcon != null) { int iy = (height - (int)leftPath [i].DarkIcon.Height) / 2 + topPadding; ctx.DrawImage(this, leftPath [i].DarkIcon, x, iy); textOffset += (int)leftPath [i].DarkIcon.Width + iconSpacing; } layout.Attributes = (i == activeIndex) ? boldAtts : null; layout.FontDescription = FontService.SansFont.CopyModified(Styles.FontScale11); layout.SetMarkup(GetFirstLineFromMarkup(leftPath [i].Markup)); ctx.Save(); // If size is being reduced, ellipsize it bool showText = true; if (widthReduced) { int w = itemWidth - textOffset; if (w > 0) { ctx.Rectangle(x + textOffset, textTopPadding, w, height); ctx.Clip(); } else { showText = false; } } else { layout.Width = -1; } if (showText) { // Text ctx.SetSourceColor(Styles.BreadcrumbTextColor.ToCairoColor()); ctx.MoveTo(x + textOffset, textTopPadding); Pango.CairoHelper.ShowLayout(ctx, layout); } ctx.Restore(); if (!last) { xpos += arrowLeftPadding; if (leftPath [i].IsPathEnd) { Style.PaintVline(Style, GdkWindow, State, evnt.Area, this, "", ypos, ypos + height, xpos - arrowSize / 2); } else { int arrowH = Math.Min(height, arrowSize); int arrowY = ypos + (height - arrowH) / 2; DrawPathSeparator(ctx, xpos, arrowY, arrowH); } xpos += arrowSize + arrowRightPadding; } } int xposRight = Allocation.Width - rightPadding; for (int i = 0; i < rightPath.Length; i++, index++) { // bool last = i == rightPath.Length - 1; // Reduce the item size when required int itemWidth = currentWidths [i + leftPath.Length]; xposRight -= itemWidth; xposRight -= arrowSize; int x = xposRight; SetAccessibilityFrame(rightPath [i], x, itemWidth); if (hoverIndex >= 0 && hoverIndex < Path.Length && rightPath [i] == Path [hoverIndex] && (menuVisible || pressed || hovering)) { DrawButtonBorder(ctx, x - padding, itemWidth + padding + padding); } if (index == focusedPathIndex) { focusRect = new Gdk.Rectangle(x - padding, 0, itemWidth + (padding * 2), 0); } int textOffset = 0; if (rightPath [i].DarkIcon != null) { ctx.DrawImage(this, rightPath [i].DarkIcon, x, ypos); textOffset += (int)rightPath [i].DarkIcon.Width + padding; } layout.Attributes = (i == activeIndex) ? boldAtts : null; layout.FontDescription = FontService.SansFont.CopyModified(Styles.FontScale11); layout.SetMarkup(GetFirstLineFromMarkup(rightPath [i].Markup)); ctx.Save(); // If size is being reduced, ellipsize it bool showText = true; if (widthReduced) { int w = itemWidth - textOffset; if (w > 0) { ctx.Rectangle(x + textOffset, textTopPadding, w, height); ctx.Clip(); } else { showText = false; } } else { layout.Width = -1; } if (showText) { // Text ctx.SetSourceColor(Styles.BreadcrumbTextColor.ToCairoColor()); ctx.MoveTo(x + textOffset, textTopPadding); Pango.CairoHelper.ShowLayout(ctx, layout); } ctx.Restore(); } ctx.MoveTo(0, Allocation.Height - 0.5); ctx.RelLineTo(Allocation.Width, 0); ctx.SetSourceColor(Styles.BreadcrumbBottomBorderColor.ToCairoColor()); ctx.LineWidth = 1; ctx.Stroke(); if (HasFocus) { int focusY = topPadding - buttonPadding; int focusHeight = Allocation.Height - topPadding - bottomPadding + buttonPadding * 2; Gtk.Style.PaintFocus(Style, GdkWindow, State, Allocation, this, "label", focusRect.X, focusY, focusRect.Width, focusHeight); } } return(true); }
protected override void Render(Drawable window, Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, CellRendererState flags) { if (isDisposed) { return; } if (diffMode) { if (path.Equals(selctedPath)) { selectedLine = -1; selctedPath = null; } int w, maxy; window.GetSize(out w, out maxy); if (DrawLeft) { cell_area.Width += cell_area.X - leftSpace; cell_area.X = leftSpace; } var treeview = widget as FileTreeView; var p = treeview != null? treeview.CursorLocation : null; cell_area.Width -= RightPadding; window.DrawRectangle(widget.Style.BaseGC(Gtk.StateType.Normal), true, cell_area.X, cell_area.Y, cell_area.Width - 1, cell_area.Height); Gdk.GC normalGC = widget.Style.TextGC(StateType.Normal); Gdk.GC removedGC = new Gdk.GC(window); removedGC.Copy(normalGC); removedGC.RgbFgColor = baseRemoveColor.AddLight(-0.3); Gdk.GC addedGC = new Gdk.GC(window); addedGC.Copy(normalGC); addedGC.RgbFgColor = baseAddColor.AddLight(-0.3); Gdk.GC infoGC = new Gdk.GC(window); infoGC.Copy(normalGC); infoGC.RgbFgColor = widget.Style.Text(StateType.Normal).AddLight(0.2); Cairo.Context ctx = CairoHelper.Create(window); // Rendering is done in two steps: // 1) Get a list of blocks to render // 2) render the blocks int y = cell_area.Y + 2; // cline keeps track of the current source code line (the one to jump to when double clicking) int cline = 1; bool inHeader = true; BlockInfo currentBlock = null; List <BlockInfo> blocks = new List <BlockInfo> (); for (int n = 0; n < lines.Length; n++, y += lineHeight) { string line = lines [n]; if (line.Length == 0) { currentBlock = null; y -= lineHeight; continue; } char tag = line [0]; if (line.StartsWith("---") || line.StartsWith("+++")) { // Ignore this part of the header. currentBlock = null; y -= lineHeight; continue; } if (tag == '@') { int l = ParseCurrentLine(line); if (l != -1) { cline = l - 1; } inHeader = false; } else if (tag != '-' && !inHeader) { cline++; } BlockType type; switch (tag) { case '-': type = BlockType.Removed; break; case '+': type = BlockType.Added; break; case '@': type = BlockType.Info; break; default: type = BlockType.Unchanged; break; } if (currentBlock == null || type != currentBlock.Type) { if (y > maxy) { break; } // Starting a new block. Mark section ends between a change block and a normal code block if (currentBlock != null && IsChangeBlock(currentBlock.Type) && !IsChangeBlock(type)) { currentBlock.SectionEnd = true; } currentBlock = new BlockInfo() { YStart = y, FirstLine = n, Type = type, SourceLineStart = cline, SectionStart = (blocks.Count == 0 || !IsChangeBlock(blocks[blocks.Count - 1].Type)) && IsChangeBlock(type) }; blocks.Add(currentBlock); } // Include the line in the current block currentBlock.YEnd = y + lineHeight; currentBlock.LastLine = n; } // Now render the blocks // The y position of the highlighted line int selectedLineRowTop = -1; BlockInfo lastCodeSegmentStart = null; BlockInfo lastCodeSegmentEnd = null; foreach (BlockInfo block in blocks) { if (block.Type == BlockType.Info) { // Finished drawing the content of a code segment. Now draw the segment border and label. if (lastCodeSegmentStart != null) { DrawCodeSegmentBorder(infoGC, ctx, cell_area.X, cell_area.Width, lastCodeSegmentStart, lastCodeSegmentEnd, lines, widget, window); } lastCodeSegmentStart = block; } lastCodeSegmentEnd = block; if (block.YEnd < 0) { continue; } // Draw the block background DrawBlockBg(ctx, cell_area.X + 1, cell_area.Width - 2, block); // Get all text for the current block StringBuilder sb = new StringBuilder(); for (int n = block.FirstLine; n <= block.LastLine; n++) { string s = ProcessLine(lines [n]); if (n > block.FirstLine) { sb.Append('\n'); } if (block.Type != BlockType.Info && s.Length > 0) { sb.Append(s, 1, s.Length - 1); } else { sb.Append(s); } } // Draw a special background for the selected line if (block.Type != BlockType.Info && p.HasValue && p.Value.X >= cell_area.X && p.Value.X <= cell_area.Right && p.Value.Y >= block.YStart && p.Value.Y <= block.YEnd) { int row = (p.Value.Y - block.YStart) / lineHeight; double yrow = block.YStart + lineHeight * row; double xrow = cell_area.X + LeftPaddingBlock; int wrow = cell_area.Width - 1 - LeftPaddingBlock; if (block.Type == BlockType.Added) { ctx.Color = baseAddColor.AddLight(0.1).ToCairoColor(); } else if (block.Type == BlockType.Removed) { ctx.Color = baseRemoveColor.AddLight(0.1).ToCairoColor(); } else { ctx.Color = widget.Style.Base(Gtk.StateType.Prelight).AddLight(0.1).ToCairoColor(); xrow -= LeftPaddingBlock; wrow += LeftPaddingBlock; } ctx.Rectangle(xrow, yrow, wrow, lineHeight); ctx.Fill(); selectedLine = block.SourceLineStart + row; selctedPath = path; selectedLineRowTop = (int)yrow; } // Draw the line text. Ignore header blocks, since they are drawn as labels in DrawCodeSegmentBorder if (block.Type != BlockType.Info) { layout.SetMarkup(""); layout.SetText(sb.ToString()); Gdk.GC gc; switch (block.Type) { case BlockType.Removed: gc = removedGC; break; case BlockType.Added: gc = addedGC; break; case BlockType.Info: gc = infoGC; break; default: gc = normalGC; break; } window.DrawLayout(gc, cell_area.X + 2 + LeftPaddingBlock, block.YStart, layout); } // Finally draw the change symbol at the left margin DrawChangeSymbol(ctx, cell_area.X + 1, cell_area.Width - 2, block); } // Finish the drawing of the code segment if (lastCodeSegmentStart != null) { DrawCodeSegmentBorder(infoGC, ctx, cell_area.X, cell_area.Width, lastCodeSegmentStart, lastCodeSegmentEnd, lines, widget, window); } // Draw the source line number at the current selected line. It must be done at the end because it must // be drawn over the source code text and segment borders. if (selectedLineRowTop != -1) { DrawLineBox(normalGC, ctx, ((Gtk.TreeView)widget).VisibleRect.Right - 4, selectedLineRowTop, selectedLine, widget, window); } ((IDisposable)ctx).Dispose(); removedGC.Dispose(); addedGC.Dispose(); infoGC.Dispose(); } else { // Rendering a normal text row int y = cell_area.Y + (cell_area.Height - height) / 2; window.DrawLayout(widget.Style.TextGC(GetState(flags)), cell_area.X, y, layout); } }
void DrawList() { int winWidth, winHeight; this.GdkWindow.GetSize(out winWidth, out winHeight); int ypos = margin; int lineWidth = winWidth - margin * 2; int xpos = margin + padding; int n = (int)(vadj.Value / rowHeight); while (ypos < winHeight - margin && n < win.DataProvider.IconCount) { string text = win.DataProvider.GetMarkup(n) ?? "<null>"; layout.SetMarkup(text); Gdk.Pixbuf icon = win.DataProvider.GetIcon(n); int iconHeight = icon != null ? icon.Height : 24; int iconWidth = icon != null ? icon.Width : 0; int wi, he, typos, iypos; layout.GetPixelSize(out wi, out he); if (wi > Allocation.Width) { int idx, trail; if (layout.XyToIndex( (int)((Allocation.Width - xpos - iconWidth - 2) * Pango.Scale.PangoScale), 0, out idx, out trail ) && idx > 3) { text = AmbienceService.UnescapeText(text); text = text.Substring(0, idx - 3) + "..."; text = AmbienceService.EscapeText(text); layout.SetMarkup(text); layout.GetPixelSize(out wi, out he); } } typos = he < rowHeight ? ypos + (rowHeight - he) / 2 : ypos; iypos = iconHeight < rowHeight ? ypos + (rowHeight - iconHeight) / 2 : ypos; if (n == selection) { if (!disableSelection) { this.GdkWindow.DrawRectangle(this.Style.BaseGC(StateType.Selected), true, margin, ypos, lineWidth, he + padding); this.GdkWindow.DrawLayout(this.Style.TextGC(StateType.Selected), xpos + iconWidth + 2, typos, layout); } else { this.GdkWindow.DrawRectangle(this.Style.BaseGC(StateType.Selected), false, margin, ypos, lineWidth, he + padding); this.GdkWindow.DrawLayout(this.Style.TextGC(StateType.Normal), xpos + iconWidth + 2, typos, layout); } } else { this.GdkWindow.DrawLayout(this.Style.TextGC(StateType.Normal), xpos + iconWidth + 2, typos, layout); } if (icon != null) { this.GdkWindow.DrawPixbuf(this.Style.ForegroundGC(StateType.Normal), icon, 0, 0, xpos, iypos, iconWidth, iconHeight, Gdk.RgbDither.None, 0, 0); } ypos += rowHeight; n++; //reset the markup or it carries over to the next SetText layout.SetMarkup(string.Empty); } }
void SetMarkup(Pango.Layout layout, string text) { string markup = "<span size='smaller'>" + text + "</span>"; layout.SetMarkup(markup); }
void DrawList() { int winWidth, winHeight; GdkWindow.GetSize(out winWidth, out winHeight); int lineWidth = winWidth - leftXAlignment * 2; const int xpos = leftXAlignment + padding; int n = (int)(vAdjustment.Value / rowHeight); int ypos = (int)(leftXAlignment + n * rowHeight - vAdjustment.Value); while (ypos < winHeight - leftXAlignment && n < win.DataProvider.IconCount) { string text = win.DataProvider.GetMarkup(n) ?? "<null>"; var icon = win.DataProvider.GetIcon(n); int iconHeight = icon != null ? (int)icon.Height : 24; int iconWidth = icon != null ? (int)icon.Width : 0; layout.Ellipsize = Pango.EllipsizeMode.End; layout.Width = (Allocation.Width - xpos - iconWidth - iconTextDistance) * (int)Pango.Scale.PangoScale; layout.SetMarkup(PathBar.GetFirstLineFromMarkup(text)); int wi, he, typos, iypos; layout.GetPixelSize(out wi, out he); typos = he < rowHeight ? ypos + (rowHeight - he) / 2 : ypos; iypos = iconHeight < rowHeight ? ypos + (rowHeight - iconHeight) / 2 : ypos; if (n == selection) { if (!disableSelection) { GdkWindow.DrawRectangle(Style.BaseGC(StateType.Selected), true, leftXAlignment, ypos, lineWidth, rowHeight); GdkWindow.DrawLayout(Style.TextGC(StateType.Selected), xpos + iconWidth + iconTextDistance, typos, layout); } else { GdkWindow.DrawRectangle(Style.BaseGC(StateType.Selected), false, leftXAlignment, ypos, lineWidth, rowHeight); GdkWindow.DrawLayout(Style.TextGC(StateType.Normal), xpos + iconWidth + iconTextDistance, typos, layout); } } else { GdkWindow.DrawLayout(Style.TextGC(StateType.Normal), xpos + iconWidth + iconTextDistance, typos, layout); } if (icon != null) { using (var ctx = Gdk.CairoHelper.Create(this.GdkWindow)) ctx.DrawImage(this, icon, xpos, iypos); } ypos += rowHeight; n++; //reset the markup or it carries over to the next SetText layout.SetMarkup(string.Empty); } }
protected override void RenderTrackInfo(Context cr, TrackInfo track, bool render_track, bool render_artist_album) { if (track == null) { return; } Gdk.Rectangle alloc = RenderAllocation; int width = ArtworkSizeRequest; int fl_width, fl_height, sl_width, sl_height, tl_width, tl_height; int pango_width = (int)(width * Pango.Scale.PangoScale); string first_line = GetFirstLineText(track); // FIXME: This is incredibly bad, but we don't want to break // translations right now. It needs to be replaced for 1.4!! string line = GetSecondLineText(track); string second_line = line, third_line = String.Empty; int split_pos = line.LastIndexOf("<span"); if (split_pos >= 0 // Check that there are at least 3 spans in the string, else this // will break for tracks with missing artist or album info. && StringUtil.SubstringCount(line, "<span") >= 3) { second_line = line.Substring(0, Math.Max(0, split_pos - 1)) + "</span>"; third_line = String.Format("<span color=\"{0}\">{1}", CairoExtensions.ColorGetHex(TextColor, false), line.Substring(split_pos, line.Length - split_pos)); } if (first_line_layout == null) { first_line_layout = CairoExtensions.CreateLayout(this, cr); first_line_layout.Wrap = Pango.WrapMode.Word; first_line_layout.Ellipsize = Pango.EllipsizeMode.None; first_line_layout.Alignment = Pango.Alignment.Right; int base_size = first_line_layout.FontDescription.Size; first_line_layout.FontDescription.Size = (int)(base_size * Pango.Scale.XLarge); } if (second_line_layout == null) { second_line_layout = CairoExtensions.CreateLayout(this, cr); second_line_layout.Wrap = Pango.WrapMode.Word; second_line_layout.Ellipsize = Pango.EllipsizeMode.None; second_line_layout.Alignment = Pango.Alignment.Right; } if (third_line_layout == null) { third_line_layout = CairoExtensions.CreateLayout(this, cr); third_line_layout.Wrap = Pango.WrapMode.Word; third_line_layout.Ellipsize = Pango.EllipsizeMode.None; third_line_layout.Alignment = Pango.Alignment.Right; } // Set up the text layouts first_line_layout.Width = pango_width; second_line_layout.Width = pango_width; third_line_layout.Width = pango_width; // Compute the layout coordinates first_line_layout.SetMarkup(first_line); first_line_layout.GetPixelSize(out fl_width, out fl_height); second_line_layout.SetMarkup(second_line); second_line_layout.GetPixelSize(out sl_width, out sl_height); third_line_layout.SetMarkup(third_line); third_line_layout.GetPixelSize(out tl_width, out tl_height); track_info_alloc.X = alloc.X; track_info_alloc.Width = width; track_info_alloc.Height = fl_height + sl_height + tl_height; track_info_alloc.Y = alloc.Y + (ArtworkSizeRequest - track_info_alloc.Height) / 2; // Render the layouts cr.Antialias = Cairo.Antialias.Default; if (render_track) { cr.MoveTo(track_info_alloc.X, track_info_alloc.Y); cr.Color = TextColor; PangoCairoHelper.ShowLayout(cr, first_line_layout); RenderTrackRating(cr, track); } if (render_artist_album) { cr.MoveTo(track_info_alloc.X, track_info_alloc.Y + fl_height); PangoCairoHelper.ShowLayout(cr, second_line_layout); cr.MoveTo(track_info_alloc.X, track_info_alloc.Y + fl_height + sl_height); PangoCairoHelper.ShowLayout(cr, third_line_layout); } }
public override void GetSize (Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) { using (var layout = new Pango.Layout (Context)) { Pango.Rectangle ink, logical; layout.Width = (int) (MaxMarkupWidth * Pango.Scale.PangoScale); layout.SetMarkup (GetMarkup (false)); layout.GetPixelExtents (out ink, out logical); width = Padding + RoundedRectangleWidth + Padding + Padding + logical.Width + Padding; height = Padding + Math.Max (RoundedRectangleHeight, logical.Height) + Padding; x_offset = 0; y_offset = 0; } }
protected override void Render (Gdk.Drawable window, Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, CellRendererState flags) { using (var cr = Gdk.CairoHelper.Create (window)) { cr.Rectangle (background_area.X, background_area.Y, background_area.Width, background_area.Height); using (var layout = new Pango.Layout (widget.PangoContext)) { layout.FontDescription = font; if ((flags & CellRendererState.Selected) != 0) { cr.SetSourceRGB (Styles.ExceptionCaughtDialog.TreeSelectedBackgroundColor.Red, Styles.ExceptionCaughtDialog.TreeSelectedBackgroundColor.Green, Styles.ExceptionCaughtDialog.TreeSelectedBackgroundColor.Blue); // selected cr.Fill (); cr.SetSourceRGB (Styles.ExceptionCaughtDialog.TreeSelectedTextColor.Red, Styles.ExceptionCaughtDialog.TreeSelectedTextColor.Green, Styles.ExceptionCaughtDialog.TreeSelectedTextColor.Blue); } else { cr.SetSourceRGB (Styles.ExceptionCaughtDialog.TreeBackgroundColor.Red, Styles.ExceptionCaughtDialog.TreeBackgroundColor.Green, Styles.ExceptionCaughtDialog.TreeBackgroundColor.Blue); // background cr.Fill (); cr.SetSourceRGB (Styles.ExceptionCaughtDialog.TreeTextColor.Red, Styles.ExceptionCaughtDialog.TreeTextColor.Green, Styles.ExceptionCaughtDialog.TreeTextColor.Blue); } layout.SetMarkup (Text); cr.Translate (cell_area.X + 10, cell_area.Y + 1); cr.ShowLayout (layout); } } }
protected override void Render (Gdk.Drawable window, Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, CellRendererState flags) { using (var cr = Gdk.CairoHelper.Create (window)) { using (var layout = new Pango.Layout (Context)) { Pango.Rectangle ink, logical; layout.Width = (int) (MaxMarkupWidth * Pango.Scale.PangoScale); layout.SetMarkup (GetMarkup ((flags & CellRendererState.Selected) != 0)); layout.GetPixelExtents (out ink, out logical); RenderLineNumberIcon (widget, cr, cell_area, logical.Height, ink.Y); cr.Rectangle (expose_area.X, expose_area.Y, expose_area.Width, expose_area.Height); cr.Clip (); cr.Translate (cell_area.X + Padding + RoundedRectangleWidth + Padding + Padding, cell_area.Y + Padding); cr.ShowLayout (layout); } } }
protected override void Render (Gdk.Drawable window, Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, CellRendererState flags) { using (var cr = Gdk.CairoHelper.Create (window)) { Pango.Rectangle ink, logical; using (var layout = new Pango.Layout (Context)) { layout.FontDescription = font; layout.SetMarkup (GetFileMarkup ((flags & CellRendererState.Selected) != 0)); layout.GetPixelExtents (out ink, out logical); var width = widget.Allocation.Width; cr.Translate (width - logical.Width - 10, cell_area.Y); cr.ShowLayout (layout); cr.IdentityMatrix (); layout.SetMarkup (GetMethodMarkup ((flags & CellRendererState.Selected) != 0)); layout.Width = (int)((width - logical.Width - 35) * Pango.Scale.PangoScale); layout.Ellipsize = Pango.EllipsizeMode.Middle; cr.Translate (cell_area.X + 10, cell_area.Y); cr.ShowLayout (layout); } } }
public TokenRenderer (Pango.Context ctx, string str, bool outlined) { Outlined = outlined; Spacing = 6; if (str == "%UP%") { Symbol = SymbolTokenType.Up; Width = 14; Height = 10; } else if (str == "%DOWN%") { Symbol = SymbolTokenType.Down; Width = 14; Height = 10; } else { Symbol = SymbolTokenType.None; var desc = ctx.FontDescription.Copy (); desc.AbsoluteSize = Pango.Units.FromPixels (Outlined ? outlinedFontSize : normalFontSize); if (Outlined) { desc.Weight = Pango.Weight.Bold; Spacing += outlinePadding; } layout = new Pango.Layout (ctx); layout.FontDescription = desc; layout.Spacing = (int)(Spacing * Pango.Scale.PangoScale); layout.SetMarkup (str); int w, h; layout.GetPixelSize (out w, out h); Width = w; Height = h - 1; } }
void DrawCursorLabel(ChartCursor cursor) { Gdk.GC gc = new Gdk.GC (GdkWindow); gc.RgbFgColor = cursor.Color; int x, y; GetPoint (cursor.Value, cursor.Value, out x, out y); if (cursor.Dimension == AxisDimension.X) { string text; if (cursor.LabelAxis != null) { double minStep = GetMinTickStep (cursor.Dimension); TickEnumerator tenum = cursor.LabelAxis.GetTickEnumerator (minStep); tenum.Init (cursor.Value); text = tenum.CurrentLabel; } else { text = GetValueLabel (cursor.Dimension, cursor.Value); } if (text != null && text.Length > 0) { Pango.Layout layout = new Pango.Layout (this.PangoContext); layout.FontDescription = Pango.FontDescription.FromString ("Tahoma 8"); layout.SetMarkup (text); int tw, th; layout.GetPixelSize (out tw, out th); int tl = x - tw/2; int tt = top + 4; if (tl + tw + 2 >= left + width) tl = left + width - tw - 1; if (tl < left + 1) tl = left + 1; GdkWindow.DrawRectangle (Style.WhiteGC, true, tl - 1, tt - 1, tw + 2, th + 2); GdkWindow.DrawRectangle (Style.BlackGC, false, tl - 2, tt - 2, tw + 3, th + 3); GdkWindow.DrawLayout (gc, tl, tt, layout); } } else { throw new NotSupportedException (); } }
protected override bool OnExposeEvent (Gdk.EventExpose evnt) { using (var layout = new Pango.Layout (this.PangoContext)) { layout.Width = (int)(Allocation.Width * Pango.Scale.PangoScale); layout.Wrap = Pango.WrapMode.Word; layout.Alignment = Pango.Alignment.Left; layout.SetMarkup (Markup); evnt.Window.DrawLayout (Style.TextGC (StateType.Normal), 0, 0, layout); } return true; }
protected void GetCellSize(Widget widget, int availableWidth, out int width, out int height) { layout.SetMarkup(Text); layout.Width = -1; layout.GetPixelSize(out width, out height); }
public override void GetSize (Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) { using (var layout = new Pango.Layout (widget.PangoContext)) { layout.FontDescription = font; Pango.Rectangle ink, logical; layout.SetMarkup ("<b>" + Text + "</b>"); layout.GetPixelExtents (out ink, out logical); width = logical.Width + 10; height = logical.Height + 2; x_offset = 0; y_offset = 0; } }
protected override bool OnExposeEvent(EventExpose evnt) { int width, height, center, lCenter, vCenter, totalCount; double localPercent, visitorPercent; this.GdkWindow.Clear(); width = Allocation.Width; center = width / 2; lCenter = center - textSize / 2; vCenter = center + textSize / 2; width = width - textSize - 10; height = Allocation.Height; if (category != null) { totalCount = category.TotalCount; } else { totalCount = stat.TotalCount; } if (totalCount != 0) { localPercent = (double)stat.LocalTeamCount / totalCount; visitorPercent = (double)stat.VisitorTeamCount / totalCount; } else { localPercent = 0; visitorPercent = 0; } using (Cairo.Context g = Gdk.CairoHelper.Create(this.GdkWindow)) { int localW, visitorW; localW = (int)(width / 2 * localPercent); visitorW = (int)(width / 2 * visitorPercent); /* Home bar */ CairoUtils.DrawRoundedRectangle(g, lCenter - localW, 0, localW, height, 0, HomeColor, HomeColor); /* Away bar */ CairoUtils.DrawRoundedRectangle(g, vCenter, 0, visitorW, height, 0, AwayColor, AwayColor); /* Category name */ layout.Width = Pango.Units.FromPixels(textSize); layout.Alignment = Pango.Alignment.Center; layout.SetMarkup(String.Format(name_tpl, GLib.Markup.EscapeText(stat.Name))); GdkWindow.DrawLayout(Style.TextGC(StateType.Normal), center - textSize / 2, 0, layout); /* Home count */ layout.Width = Pango.Units.FromPixels(COUNT_WIDTH); layout.Alignment = Pango.Alignment.Right; layout.SetMarkup(String.Format(count_tpl, stat.LocalTeamCount, (localPercent * 100).ToString("f2"))); GdkWindow.DrawLayout(Style.TextGC(StateType.Normal), lCenter - (COUNT_WIDTH + 3), 0, layout); /* Away count */ layout.Width = Pango.Units.FromPixels(COUNT_WIDTH); layout.Alignment = Pango.Alignment.Left; layout.SetMarkup(String.Format(count_tpl, stat.VisitorTeamCount, (visitorPercent * 100).ToString("f2"))); GdkWindow.DrawLayout(Style.TextGC(StateType.Normal), vCenter + 3, 0, layout); } return(true); }
public override void GetSize (Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) { using (var layout = new Pango.Layout (Context)) { Pango.Rectangle ink, logical; layout.FontDescription = font; layout.SetMarkup (GetMethodMarkup (false)); layout.GetPixelExtents (out ink, out logical); height = logical.Height; width = 0; x_offset = 0; y_offset = 0; } }
protected override bool OnExposeEvent(Gdk.EventExpose evnt) { using (var ctx = Gdk.CairoHelper.Create (evnt.Window)) { if (mouseOver) DrawHoverBackground (ctx); // Draw the icon DrawIcon (ctx); // Draw the text int textWidth = Allocation.Width - LeftTextPadding - InternalPadding * 2; Pango.Layout titleLayout = new Pango.Layout (PangoContext); titleLayout.Width = Pango.Units.FromPixels (textWidth); titleLayout.Ellipsize = Pango.EllipsizeMode.End; titleLayout.SetMarkup (WelcomePageSection.FormatText (TitleFontFace, titleFontSize, TitleFontWeight, MediumTitleColor, title)); Pango.Layout subtitleLayout = null; if (!string.IsNullOrEmpty (subtitle)) { subtitleLayout = new Pango.Layout (PangoContext); subtitleLayout.Width = Pango.Units.FromPixels (textWidth); subtitleLayout.Ellipsize = Pango.EllipsizeMode.Start; subtitleLayout.SetMarkup (WelcomePageSection.FormatText (SmallTitleFontFace, smallTitleFontSize, Pango.Weight.Normal, SmallTitleColor, subtitle)); } int height = 0; int w, h1, h2; titleLayout.GetPixelSize (out w, out h1); height += h1; if (subtitleLayout != null) { height += Styles.WelcomeScreen.Pad.Solutions.SolutionTile.TitleBottomMargin; subtitleLayout.GetPixelSize (out w, out h2); height += h2; } int tx = Allocation.X + InternalPadding + LeftTextPadding; int ty = Allocation.Y + (Allocation.Height - height) / 2; DrawLayout (ctx, titleLayout, TitleFontFace, titleFontSize, TitleFontWeight, MediumTitleColor, tx, ty); if (subtitleLayout != null) { ty += h1 + Styles.WelcomeScreen.Pad.Solutions.SolutionTile.TitleBottomMargin; DrawLayout (ctx, subtitleLayout, SmallTitleFontFace, smallTitleFontSize, Pango.Weight.Normal, SmallTitleColor, tx, ty); } } return true; }
public void AddOverload (CompletionData data) { var tooltipInformation = data.CreateTooltipInformation (false); if (string.IsNullOrEmpty (tooltipInformation.SignatureMarkup)) return; using (var layout = new Pango.Layout (PangoContext)) { var des = FontService.GetFontDescription ("Editor"); layout.FontDescription = des; layout.SetMarkup (tooltipInformation.SignatureMarkup); int w, h; layout.GetPixelSize (out w, out h); if (w >= Allocation.Width - 10) { tooltipInformation = data.CreateTooltipInformation (true); } } AddOverload (tooltipInformation); }
void DrawTemplateCategoryText (Drawable window, Widget widget, Rectangle cell_area, CellRendererState flags) { StateType state = GetState (widget, flags); using (var layout = new Pango.Layout (widget.PangoContext)) { layout.Ellipsize = Pango.EllipsizeMode.End; int textPixelWidth = widget.Allocation.Width - ((int)Xpad * 2); layout.Width = (int)(textPixelWidth * Pango.Scale.PangoScale); layout.SetMarkup (TemplateCategory); int w, h; layout.GetPixelSize (out w, out h); int textX = cell_area.X + (int)Xpad + categoryTextPaddingX; int textY = cell_area.Y + (cell_area.Height - h) / 2 + groupTemplateHeadingYOffset; window.DrawLayout (widget.Style.TextGC (state), textX, textY, layout); } }
int MeasureTicksSize(TickEnumerator e, AxisDimension ad) { int max = 0; Pango.Layout layout = new Pango.Layout (this.PangoContext); layout.FontDescription = Pango.FontDescription.FromString ("Tahoma 8"); double start = GetStart (ad); double end = GetEnd (ad); e.Init (GetOrigin (ad)); while (e.CurrentValue > start) e.MovePrevious (); for ( ; e.CurrentValue <= end; e.MoveNext ()) { int tw = 0, th = 0; layout.SetMarkup (e.CurrentLabel); layout.GetPixelSize (out tw, out th); if (ad == AxisDimension.X) { if (th > max) max = th; } else { if (tw > max) max = tw; } } return max; }
void DrawTemplateNameText (Drawable window, Widget widget, Rectangle cell_area, Rectangle iconRect, Rectangle languageRect, CellRendererState flags) { StateType state = GetState (widget, flags); using (var layout = new Pango.Layout (widget.PangoContext)) { layout.Ellipsize = Pango.EllipsizeMode.End; int textPixelWidth = widget.Allocation.Width - ((int)Xpad * 2) - iconRect.Width - iconTextPadding - languageRect.Width; layout.Width = (int)(textPixelWidth * Pango.Scale.PangoScale); layout.SetMarkup (GLib.Markup.EscapeText (Template.Name)); int w, h; layout.GetPixelSize (out w, out h); int textY = cell_area.Y + (cell_area.Height - h) / 2; window.DrawLayout (widget.Style.TextGC (state), iconRect.Right + iconTextPadding, textY, layout); } }
public override void DrawAfterEol (TextEditor textEditor, Cairo.Context g, double y, EndOfLineMetrics metrics) { EnsureLayoutCreated (editor); int errorCounterWidth = 0, eh = 0; if (errorCountLayout != null) errorCountLayout.GetPixelSize (out errorCounterWidth, out eh); var sx = metrics.TextRenderEndPosition; var width = LayoutWidth + errorCounterWidth + editor.LineHeight; var drawLayout = layouts[0].Layout; int ex = 0 , ey = 0; bool customLayout = sx + width > editor.Allocation.Width; bool hideText = false; bubbleIsReduced = customLayout; if (customLayout) { width = editor.Allocation.Width - sx; string text = layouts[0].Layout.Text; drawLayout = new Pango.Layout (editor.PangoContext); drawLayout.FontDescription = cache.fontDescription; for (int j = text.Length - 4; j > 0; j--) { drawLayout.SetText (text.Substring (0, j) + "..."); drawLayout.GetPixelSize (out ex, out ey); if (ex + (errorCountLayout != null ? errorCounterWidth : 0) + editor.LineHeight < width) break; } if (ex + (errorCountLayout != null ? errorCounterWidth : 0) + editor.LineHeight > width) { hideText = true; drawLayout.SetMarkup ("<span weight='heavy'>···</span>"); width = Math.Max (17, errorCounterWidth) + editor.LineHeight; sx = Math.Min (sx, editor.Allocation.Width - width); } } bubbleDrawX = sx - editor.TextViewMargin.XOffset; bubbleDrawY = y; bubbleWidth = width; g.RoundedRectangle (sx, y + 1, width, editor.LineHeight - 2, editor.LineHeight / 2 - 1); g.Color = TagColor.Color; g.Fill (); if (errorCounterWidth > 0 && errorCountLayout != null) { g.RoundedRectangle (sx + width - errorCounterWidth - editor.LineHeight / 2, y + 2, errorCounterWidth, editor.LineHeight - 4, editor.LineHeight / 2 - 3); g.Color = CounterColor.Color; g.Fill (); g.Save (); g.Translate (sx + width - errorCounterWidth - editor.LineHeight / 2 + (errorCounterWidth - errorCounterWidth) / 2, y + 1); g.Color = CounterColor.SecondColor; g.ShowLayout (errorCountLayout); g.Restore (); } if (errorCounterWidth <= 0 || errorCountLayout == null || !hideText) { g.Save (); g.Translate (sx + editor.LineHeight / 2, y + (editor.LineHeight - layouts [0].Height) / 2 + layouts [0].Height % 2); g.Color = TagColor.SecondColor; g.ShowLayout (drawLayout); g.Restore (); } if (customLayout) drawLayout.Dispose (); }
public InsertionCursorLayoutModeHelpWindow () { titleLayout = new Pango.Layout (PangoContext); descriptionLayout = new Pango.Layout (PangoContext); descriptionLayout.SetMarkup ("<small>Use Up/Down to move to another location.\nPress Enter to select the location\nPress Esc to cancel this operation</small>"); }
Pango.Layout CreateLayout (Widget container, string text) { Pango.Layout layout = new Pango.Layout (container.PangoContext); layout.SingleParagraphMode = false; if (diffMode) { layout.FontDescription = font; layout.SetText (text); } else layout.SetMarkup (text); return layout; }
public override void GetSize (Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) { base.GetSize (widget, ref cell_area, out x_offset, out y_offset, out width, out height); using (var layout = new Pango.Layout (widget.PangoContext)) { layout.SetMarkup (GetPackageSourceDescriptionMarkup ()); height = GetLayoutSize (layout).Height + 8 + textTopSpacing; } }
void DrawString (string text, bool isMarkup, Cairo.Context context, int x, int y, int width, double opacity, Pango.Context pango, StatusArea.RenderArg arg) { Pango.Layout pl = new Pango.Layout (pango); if (isMarkup) pl.SetMarkup (text); else pl.SetText (text); pl.FontDescription = Styles.StatusFont; pl.FontDescription.AbsoluteSize = Pango.Units.FromPixels (Styles.StatusFontPixelHeight); pl.Ellipsize = Pango.EllipsizeMode.End; pl.Width = Pango.Units.FromPixels(width); int w, h; pl.GetPixelSize (out w, out h); context.Save (); // use widget height instead of message box height as message box does not have a true height when no widgets are packed in it // also ensures animations work properly instead of getting clipped context.Rectangle (new Rectangle (x, arg.Allocation.Y, width, arg.Allocation.Height)); context.Clip (); // Subtract off remainder instead of drop to prefer higher centering when centering an odd number of pixels context.MoveTo (x, y - h / 2 - (h % 2)); context.Color = Styles.WithAlpha (FontColor (), opacity); Pango.CairoHelper.ShowLayout (context, pl); pl.Dispose (); context.Restore (); }
protected override bool OnExposeEvent(Gdk.EventExpose evnt) { using (var ctx = Gdk.CairoHelper.Create(evnt.Window)) { if (mouseOver) { if (BorderPadding <= 0) { ctx.Rectangle(Allocation.X, Allocation.Y, Allocation.Width, Allocation.Height); ctx.Color = CairoExtensions.ParseColor(Styles.WelcomeScreen.Pad.Solutions.SolutionTile.HoverBackgroundColor); ctx.Fill(); ctx.MoveTo(Allocation.X, Allocation.Y + 0.5); ctx.RelLineTo(Allocation.Width, 0); ctx.MoveTo(Allocation.X, Allocation.Y + Allocation.Height - 0.5); ctx.RelLineTo(Allocation.Width, 0); if (DrawRightBorder) { ctx.MoveTo(Allocation.Right + 0.5, Allocation.Y + 0.5); ctx.LineTo(Allocation.Right + 0.5, Allocation.Bottom - 0.5); } if (DrawLeftBorder) { ctx.MoveTo(Allocation.Left + 0.5, Allocation.Y + 0.5); ctx.LineTo(Allocation.Left + 0.5, Allocation.Bottom - 0.5); } ctx.LineWidth = 1; ctx.Color = CairoExtensions.ParseColor(Styles.WelcomeScreen.Pad.Solutions.SolutionTile.HoverBorderColor); ctx.Stroke(); } else { Gdk.Rectangle region = Allocation; region.Inflate(-BorderPadding, -BorderPadding); ctx.RoundedRectangle(region.X + 0.5, region.Y + 0.5, region.Width - 1, region.Height - 1, 3); ctx.Color = CairoExtensions.ParseColor(Styles.WelcomeScreen.Pad.Solutions.SolutionTile.HoverBackgroundColor); ctx.FillPreserve(); ctx.LineWidth = 1; ctx.Color = CairoExtensions.ParseColor(Styles.WelcomeScreen.Pad.Solutions.SolutionTile.HoverBorderColor); ctx.Stroke(); } } // Draw the icon int x = Allocation.X + InternalPadding; int y = Allocation.Y + (Allocation.Height - icon.Height) / 2; Gdk.CairoHelper.SetSourcePixbuf(ctx, icon, x, y); ctx.Paint(); if (AllowPinning && (mouseOver || pinned)) { Gdk.Pixbuf star; if (pinned) { if (mouseOverStar) { star = starPinnedHover; } else { star = starPinned; } } else { if (mouseOverStar) { star = starNormalHover; } else { star = starNormal; } } x = x + icon.Width - star.Width + 3; y = y + icon.Height - star.Height + 3; Gdk.CairoHelper.SetSourcePixbuf(ctx, star, x, y); ctx.Paint(); starRect = new Gdk.Rectangle(x, y, star.Width, star.Height); } // Draw the text int textWidth = Allocation.Width - LeftTextPadding - InternalPadding * 2; var face = Platform.IsMac ? Styles.WelcomeScreen.Pad.TitleFontFamilyMac : Styles.WelcomeScreen.Pad.TitleFontFamilyWindows; Pango.Layout titleLayout = new Pango.Layout(PangoContext); titleLayout.Width = Pango.Units.FromPixels(textWidth); titleLayout.Ellipsize = Pango.EllipsizeMode.End; titleLayout.SetMarkup(WelcomePageSection.FormatText(face, Styles.WelcomeScreen.Pad.Solutions.SolutionTile.TitleFontSize, false, Styles.WelcomeScreen.Pad.MediumTitleColor, title)); Pango.Layout subtitleLayout = null; if (!string.IsNullOrEmpty(subtitle)) { subtitleLayout = new Pango.Layout(PangoContext); subtitleLayout.Width = Pango.Units.FromPixels(textWidth); subtitleLayout.Ellipsize = Pango.EllipsizeMode.Start; subtitleLayout.SetMarkup(WelcomePageSection.FormatText(face, Styles.WelcomeScreen.Pad.Solutions.SolutionTile.PathFontSize, false, Styles.WelcomeScreen.Pad.SmallTitleColor, subtitle)); } int height = 0; int w, h1, h2; titleLayout.GetPixelSize(out w, out h1); height += h1; if (subtitleLayout != null) { height += Styles.WelcomeScreen.Pad.Solutions.SolutionTile.TitleBottomMargin; subtitleLayout.GetPixelSize(out w, out h2); height += h2; } int tx = Allocation.X + InternalPadding + LeftTextPadding; int ty = Allocation.Y + (Allocation.Height - height) / 2; ctx.MoveTo(tx, ty); Pango.CairoHelper.ShowLayout(ctx, titleLayout); if (subtitleLayout != null) { ty += h1 + Styles.WelcomeScreen.Pad.Solutions.SolutionTile.TitleBottomMargin; ctx.MoveTo(tx, ty); Pango.CairoHelper.ShowLayout(ctx, subtitleLayout); } } return(true); }