public CodeSegmentPreviewWindow (TextEditor editor, bool hideCodeSegmentPreviewInformString, ISegment segment, int width, int height) : base (Gtk.WindowType.Popup) { this.HideCodeSegmentPreviewInformString = hideCodeSegmentPreviewInformString; this.editor = editor; this.AppPaintable = true; layout = PangoUtil.CreateLayout (this); informLayout = PangoUtil.CreateLayout (this); informLayout.SetText (CodeSegmentPreviewInformString); fontDescription = Pango.FontDescription.FromString (editor.Options.FontName); fontDescription.Size = (int)(fontDescription.Size * 0.8f); layout.FontDescription = fontDescription; layout.Ellipsize = Pango.EllipsizeMode.End; // setting a max size for the segment (40 lines should be enough), // no need to markup thousands of lines for a preview window int startLine = editor.Document.OffsetToLineNumber (segment.Offset); int endLine = editor.Document.OffsetToLineNumber (segment.EndOffset); const int maxLines = 40; bool pushedLineLimit = endLine - startLine > maxLines; if (pushedLineLimit) segment = new Segment (segment.Offset, editor.Document.GetLine (startLine + maxLines).Offset - segment.Offset); layout.Ellipsize = Pango.EllipsizeMode.End; layout.SetMarkup (editor.Document.SyntaxMode.GetMarkup (editor.Document, editor.Options, editor.ColorStyle, segment.Offset, segment.Length, true) + (pushedLineLimit ? Environment.NewLine + "..." : "")); CalculateSize (); }
public override void Render(Drawable window, Widget widget, Rectangle cell_area, Rectangle expose_area, StateType cell_state, IPhoto photo) { string text = GetRenderText (photo); var layout = new Pango.Layout (widget.PangoContext); layout.SetText (text); Rectangle layout_bounds; layout.GetPixelSize (out layout_bounds.Width, out layout_bounds.Height); layout_bounds.Y = cell_area.Y; layout_bounds.X = cell_area.X + (cell_area.Width - layout_bounds.Width) / 2; if (layout_bounds.IntersectsWith (expose_area)) { Style.PaintLayout (widget.Style, window, cell_state, true, expose_area, widget, "IconView", layout_bounds.X, layout_bounds.Y, layout); } }
protected override LayoutWrapper RenderLine (long line) { Pango.Layout layout = new Pango.Layout (Editor.PangoContext); layout.FontDescription = Editor.Options.Font; layout.SetText (string.Format ("{0:X}", line * Editor.BytesInRow)); return new LayoutWrapper (layout); }
public FormattedTextImpl( Pango.Context context, string text, string fontFamily, double fontSize, FontStyle fontStyle, TextAlignment textAlignment, FontWeight fontWeight) { Contract.Requires<ArgumentNullException>(context != null); Contract.Requires<ArgumentNullException>(text != null); Layout = new Pango.Layout(context); _text = text; Layout.SetText(text); Layout.FontDescription = new Pango.FontDescription { Family = fontFamily, Size = Pango.Units.FromDouble(CorrectScale(fontSize)), Style = (Pango.Style)fontStyle, Weight = fontWeight.ToCairo() }; Layout.Alignment = textAlignment.ToCairo(); Layout.Attributes = new Pango.AttrList(); }
protected override bool OnDrawn(Cairo.Context cr) { double step_width = Allocation.Width / (double)steps; double step_height = Allocation.Height / (double)steps; double h = 1.0; double s = 0.0; for (int xi = 0, i = 0; xi < steps; xi++) { for (int yi = 0; yi < steps; yi++, i++) { double bg_b = (double)(i / 255.0); double fg_b = 1.0 - bg_b; double x = xi * step_width; double y = yi * step_height; cr.Rectangle (x, y, step_width, step_height); cr.Color = CairoExtensions.ColorFromHsb (h, s, bg_b); cr.Fill (); int tw, th; Pango.Layout layout = new Pango.Layout (PangoContext); layout.SetText (((int)(bg_b * 255.0)).ToString ()); layout.GetPixelSize (out tw, out th); cr.Translate (0.5, 0.5); cr.MoveTo (x + (step_width - tw) / 2.0, y + (step_height - th) / 2.0); cr.Color = CairoExtensions.ColorFromHsb (h, s, fg_b); PangoCairoHelper.ShowLayout (cr, layout); cr.Translate (-0.5, -0.5); } } return true; }
public int ComputeRowHeight(Widget widget) { int w_width, row_height; using (var layout = new Pango.Layout (widget.PangoContext)) { layout.SetText ("W"); layout.GetPixelSize (out w_width, out row_height); return row_height + 8; } }
internal protected override void OptionsChanged () { Pango.Layout layout = new Pango.Layout (Editor.PangoContext); layout.FontDescription = Editor.Options.Font; layout.SetText (string.Format ("0{0:X}", Data.Length) + "_"); int height; layout.GetPixelSize (out this.width, out height); layout.Dispose (); }
internal protected override void OptionsChanged () { Pango.Layout layout = new Pango.Layout (Editor.PangoContext); layout.FontDescription = Editor.Options.Font; layout.SetText ("."); int height; layout.GetPixelSize (out charWidth, out height); layout.Dispose (); bgGC = GetGC (Style.HexDigitBg); fgGC = GetGC (Style.HexDigit); }
internal protected override void OptionsChanged () { Pango.Layout layout = new Pango.Layout (Editor.PangoContext); layout.FontDescription = Editor.Options.Font; string groupString = new string ('0', Editor.Options.GroupBytes * 2); layout.SetText (groupString + " "); int lineHeight; layout.GetPixelSize (out groupWidth, out lineHeight); Data.LineHeight = lineHeight; layout.SetText ("00"); layout.GetPixelSize (out byteWidth, out lineHeight); layout.Dispose (); tabArray = new Pango.TabArray (1, true); tabArray.SetTab (0, Pango.TabAlign.Left, groupWidth); bgGC = GetGC (Style.HexDigitBg); fgGC = GetGC (Style.HexDigit); }
internal protected override void OptionsChanged () { backgroundGC = GetGC (Style.IconBarBg); separatorGC = GetGC (Style.IconBarSeperator); Pango.Layout layout = new Pango.Layout (Editor.PangoContext); layout.FontDescription = Editor.Options.Font; layout.SetText ("!"); int tmp; layout.GetPixelSize (out tmp, out this.marginWidth); marginWidth *= 12; marginWidth /= 10; layout.Dispose (); }
private void ComputeLayoutSize() { if (segments.Count == 0) { return; } Pango.Layout layout = null; layout_width = layout_height = 0; for (int i = 0, n = segments.Count; i < n; i++) { int aw, ah, bw, bh; layout = CreateAdaptLayout(layout, false, true); layout.SetText(FormatSegmentText(segments[i])); layout.GetPixelSize(out aw, out ah); layout = CreateAdaptLayout(layout, true, false); layout.SetText(FormatSegmentValue(segments[i])); layout.GetPixelSize(out bw, out bh); int w = Math.Max(aw, bw); int h = ah + bh; segments[i].LayoutWidth = w; segments[i].LayoutHeight = Math.Max(h, segment_box_size * 2); layout_width += segments[i].LayoutWidth + segment_box_size + segment_box_spacing + (i < n - 1 ? segment_label_spacing : 0); layout_height = Math.Max(layout_height, segments[i].LayoutHeight); } layout.Dispose(); }
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 virtual int ComputeRowHeight(Widget widget) { int height; int text_w, text_h; Pango.Layout layout = new Pango.Layout(widget.PangoContext); layout.FontDescription = widget.PangoContext.FontDescription; layout.FontDescription.Weight = Pango.Weight.Bold; layout.SetText("W"); layout.GetPixelSize(out text_w, out text_h); height = text_h; layout.FontDescription.Weight = Pango.Weight.Normal; layout.FontDescription.Size = (int)(layout.FontDescription.Size * Pango.Scale.Small); layout.FontDescription.Style = Pango.Style.Italic; layout.SetText("W"); layout.GetPixelSize(out text_w, out text_h); height += text_h; layout.Dispose(); return((height < image_size ? image_size : height) + 6); }
void SetLayoutMarkupAndResize() { if (layout != null) { if (use_markup) { layout.SetMarkup(brokentext ?? (text ?? string.Empty)); } else { layout.SetText(brokentext ?? (text ?? string.Empty)); } } QueueResize(); }
internal protected override void OptionsChanged() { backgroundGC = GetGC(Style.IconBarBg); separatorGC = GetGC(Style.IconBarSeperator); Pango.Layout layout = new Pango.Layout(Editor.PangoContext); layout.FontDescription = Editor.Options.Font; layout.SetText("!"); int tmp; layout.GetPixelSize(out tmp, out this.marginWidth); marginWidth *= 12; marginWidth /= 10; layout.Dispose(); }
public Tab(Tabstrip parent, string label, TabPosition tabPosition) { this.parent = parent; this.Label = label; layout = PangoUtil.CreateLayout(parent); layout.SetText(label); layout.GetPixelSize(out w, out h); if (IsSeparator) { w = SpacerWidth * 2; } this.TabPosition = tabPosition; }
internal void CalcRowHeight() { if (FixedRowHeight > 0) { rowHeight = FixedRowHeight; } else { layout.SetText("|"); int rowWidth; layout.GetPixelSize(out rowWidth, out rowHeight); rowHeight += padding; } SetBounds(); }
void EnsureWidths() { if (leftWidths != null) { return; } layout.SetText("#"); int w; layout.GetPixelSize(out w, out this.height); leftWidths = CreateWidthArray(leftPath); rightWidths = CreateWidthArray(rightPath); }
internal LayoutDescriptor CreateLayoutDescriptor(ErrorText errorText) { LayoutDescriptor result; if (!textWidthDictionary.TryGetValue(errorText.ErrorMessage, out result)) { Pango.Layout layout = new Pango.Layout(editor.PangoContext); layout.FontDescription = fontDescription; layout.SetText(GetFirstLine(errorText)); int w, h; layout.GetPixelSize(out w, out h); textWidthDictionary[errorText.ErrorMessage] = result = new LayoutDescriptor(layout, w, h); } return(result); }
public override void Render(Gdk.Drawable window, Cairo.Context ctx, Gdk.Rectangle bounds, Gtk.StateType state) { var values = Enum.GetValues(Property.PropertyType); if (values.Length < MaxCheckCount) { if (style == null) { InitializeStyle(Container); } var container = (Widget)Container; using (var layout = new Pango.Layout(container.PangoContext)) { layout.Width = -1; layout.FontDescription = FontService.SansFont.CopyModified(Ide.Gui.Styles.FontScale11); ulong value = Convert.ToUInt64(Value); int dy = 2; foreach (var val in values) { ulong uintVal = Convert.ToUInt64(val); Gtk.ShadowType sh = (value & uintVal) != 0 ? Gtk.ShadowType.In : Gtk.ShadowType.Out; if (value == 0 && uintVal == 0) { sh = Gtk.ShadowType.In; } int s = indicatorSize - 1; Gtk.Style.PaintCheck(style, window, state, sh, bounds, Container, "checkbutton", bounds.X + indicatorSpacing - 1, bounds.Y + dy, s, s); layout.SetText(val.ToString()); int tw, th; layout.GetPixelSize(out tw, out th); ctx.Save(); ctx.SetSourceColor(container.Style.Text(state).ToCairoColor()); ctx.MoveTo(bounds.X + indicatorSize + indicatorSpacing, dy + bounds.Y + ((indicatorSize - th) / 2)); Pango.CairoHelper.ShowLayout(ctx, layout); ctx.Restore(); dy += indicatorSize + CheckSpacing; } } } else { base.Render(window, ctx, bounds, state); return; } }
protected override void PostProcessIconSurface(DockySurface surface) { if (Status == WeatherDockletStatus.Error) { return; } if (Status == WeatherDockletStatus.Initializing) { return; } int size = Math.Min(surface.Width, surface.Height); Context cr = surface.Context; using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout()) { layout.FontDescription = new Gtk.Style().FontDescription; layout.FontDescription.Weight = Pango.Weight.Bold; layout.Ellipsize = Pango.EllipsizeMode.None; Pango.Rectangle inkRect, logicalRect; layout.Width = Pango.Units.FromPixels(size); layout.SetText(WeatherController.Weather.Temp + AbstractWeatherSource.TempUnit); if (IsSmall) { layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels((int)(size / 2.5)); } else { layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels((int)(size / 3.5)); } layout.GetPixelExtents(out inkRect, out logicalRect); cr.MoveTo((size - inkRect.Width) / 2, size - logicalRect.Height); Pango.CairoHelper.LayoutPath(cr, layout); cr.LineWidth = 2; cr.Color = new Cairo.Color(0, 0, 0, 0.8); cr.StrokePreserve(); cr.Color = new Cairo.Color(1, 1, 1, 0.8); cr.Fill(); layout.FontDescription.Dispose(); layout.Context.Dispose(); } }
internal void EnsureLayoutCreated (TextEditor editor) { if (layouts != null) return; layouts = new List<MessageBubbleCache.LayoutDescriptor> (); foreach (ErrorText errorText in errors) { layouts.Add (cache.CreateLayoutDescriptor (errorText)); } if (errorCountLayout == null && errors.Count > 1) { errorCountLayout = new Pango.Layout (editor.PangoContext); errorCountLayout.FontDescription = cache.fontDescription; errorCountLayout.SetText (errors.Count.ToString ()); } }
public void DrawText(Font font, Color color, int x, int y, string text) { if (widget != null) { using (var layout = new Pango.Layout(widget.PangoContext)) { layout.FontDescription = (Pango.FontDescription)font.ControlObject; layout.SetText(text); Control.Save(); Control.Color = Generator.ConvertC(color); Control.MoveTo(x, y); Pango.CairoHelper.LayoutPath(Control, layout); Control.Fill(); Control.Restore(); } } }
public SizeF MeasureString(string text) { if (measureLayout == null) { measureLayout = new Pango.Layout(FontsHandler.Context); measureLayout.FontDescription = Control; measureLayout.Spacing = 0; measureLayout.Alignment = Pango.Alignment.Left; measureLayout.Width = int.MaxValue; } measureLayout.SetText(text); int width, height; measureLayout.GetPixelSize(out width, out height); return(new SizeF(width, height)); }
public FormattedTextImpl( Pango.Context context, string text, Typeface typeface, TextAlignment textAlignment, TextWrapping wrapping, Size constraint, IReadOnlyList <FormattedTextStyleSpan> spans) { Contract.Requires <ArgumentNullException>(context != null); Contract.Requires <ArgumentNullException>(text != null); Layout = new Pango.Layout(context); Layout.SetText(text); Layout.FontDescription = new Pango.FontDescription { Family = typeface?.FontFamilyName ?? "monospace", Size = Pango.Units.FromDouble(CorrectScale(typeface?.FontSize ?? 12)), Style = (Pango.Style)(typeface?.Style ?? FontStyle.Normal), Weight = (typeface?.Weight ?? FontWeight.Normal).ToCairo(), }; Layout.Alignment = textAlignment.ToCairo(); Layout.Attributes = new Pango.AttrList(); Layout.Width = double.IsPositiveInfinity(constraint.Width) ? -1 : Pango.Units.FromDouble(constraint.Width); if (spans != null) { foreach (var span in spans) { if (span.ForegroundBrush is SolidColorBrush scb) { var color = new Pango.Color(); color.Parse(string.Format("#{0}", scb.Color.ToString().Substring(3))); var brushAttr = new Pango.AttrForeground(color); brushAttr.StartIndex = (uint)TextIndexToPangoIndex(span.StartIndex); brushAttr.EndIndex = (uint)TextIndexToPangoIndex(span.StartIndex + span.Length); this.Layout.Attributes.Insert(brushAttr); } } } Size = Measure(); }
public override void Render(Drawable window, Widget widget, Rectangle cell_area, Rectangle expose_area, StateType cell_state, IPhoto photo) { string date_text = null; if (photo is IInvalidPhotoCheck && (photo as IInvalidPhotoCheck).IsInvalid) { return; } if (cell_area.Width > 200) { date_text = photo.Time.ToString(); } else { date_text = photo.Time.ToShortDateString(); } Pango.Layout layout = null; if (!cache.TryGetValue(date_text, out layout)) { layout = new Pango.Layout(widget.PangoContext); layout.SetText(date_text); cache.Add(date_text, layout); } Rectangle layout_bounds; layout.GetPixelSize(out layout_bounds.Width, out layout_bounds.Height); layout_bounds.Y = cell_area.Y; layout_bounds.X = cell_area.X + (cell_area.Width - layout_bounds.Width) / 2; if (layout_bounds.IntersectsWith(expose_area)) { Style.PaintLayout(widget.Style, window, cell_state, true, expose_area, widget, "IconView", layout_bounds.X, layout_bounds.Y, layout); } }
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 LayoutWrapper RenderLine(long line) { Pango.Layout layout = new Pango.Layout(Editor.PangoContext); layout.FontDescription = Editor.Options.Font; layout.Tabs = tabArray; StringBuilder sb = new StringBuilder(); long startOffset = line * Editor.BytesInRow; long endOffset = System.Math.Min(startOffset + Editor.BytesInRow, Data.Length); byte[] lineBytes = Data.GetBytes(startOffset, (int)(endOffset - startOffset)); for (int i = 0; i < lineBytes.Length; i++) { sb.Append(string.Format("{0:X2}", lineBytes[i])); if (i % Editor.Options.GroupBytes == 0) { sb.Append("\t"); } } layout.SetText(sb.ToString()); char[] lineChars = sb.ToString().ToCharArray(); Margin.LayoutWrapper result = new LayoutWrapper(layout); uint curIndex = 0, byteIndex = 0; if (Data.IsSomethingSelected) { ISegment selection = Data.MainSelection.Segment; HandleSelection(selection.Offset, selection.EndOffset, startOffset, endOffset, null, delegate(long start, long end) { Pango.AttrForeground selectedForeground = new Pango.AttrForeground(Style.Selection.Red, Style.Selection.Green, Style.Selection.Blue); selectedForeground.StartIndex = TranslateToUTF8Index(lineChars, TranslateColumn(start - startOffset), ref curIndex, ref byteIndex); selectedForeground.EndIndex = TranslateToUTF8Index(lineChars, TranslateColumn(end - startOffset) - 1, ref curIndex, ref byteIndex); result.Add(selectedForeground); Pango.AttrBackground attrBackground = new Pango.AttrBackground(Style.SelectionBg.Red, Style.SelectionBg.Green, Style.SelectionBg.Blue); attrBackground.StartIndex = selectedForeground.StartIndex; attrBackground.EndIndex = selectedForeground.EndIndex; result.Add(attrBackground); }); } result.SetAttributes(); return(result); }
protected override void OnDrawContent(Gdk.EventExpose evnt, Cairo.Context g) { Theme.BorderColor = marker.TooltipColor.Color; g.Rectangle(0, 0, Allocation.Width, Allocation.Height); g.SetSourceColor(marker.TooltipColor.Color); g.Fill(); using (var drawingLayout = new Pango.Layout(this.PangoContext)) { drawingLayout.FontDescription = cache.tooltipFontDescription; double y = verticalTextBorder; var showBulletedList = marker.Errors.Count > 1; foreach (var msg in marker.Errors) { var icon = msg.IsError ? cache.errorPixbuf : cache.warningPixbuf; int w, h; if (!showBulletedList) { drawingLayout.Width = maxTextWidth; } drawingLayout.SetText(GetFirstLine(msg)); drawingLayout.GetPixelSize(out w, out h); if (showBulletedList) { g.Save(); g.Translate(textBorder, y + verticalTextSpace / 2 + Math.Max(0, (h - icon.Height) / 2)); g.DrawImage(this, icon, 0, 0); g.Restore(); } g.Save(); g.Translate(showBulletedList ? textBorder + iconTextSpacing + icon.Width: textBorder, y + verticalTextSpace / 2); g.SetSourceColor(marker.TagColor.SecondColor); g.ShowLayout(drawingLayout); g.Restore(); y += h + verticalTextSpace; } } }
internal protected override void OptionsChanged() { DisposeGCs(); backgroundGC = new Gdk.GC(editor.GdkWindow); backgroundGC.RgbFgColor = editor.ColorStyle.IconBarBg; separatorGC = new Gdk.GC(editor.GdkWindow); separatorGC.RgbFgColor = editor.ColorStyle.IconBarSeperator; layout.FontDescription = editor.Options.Font; layout.SetText("!"); int tmp; layout.GetPixelSize(out tmp, out this.marginWidth); marginWidth *= 12; marginWidth /= 10; }
private void ShowError(Context context, string error) { PreparePlot(context); Pango.Layout layout = context.CreateLayout(); layout.SetText(error); layout.Alignment = Alignment.Center; layout.Width = (int)(VirtualSize.Width * Pango.Scale.PangoScale); layout.Wrap = WrapMode.Word; int text_width; int text_height; layout.GetPixelSize(out text_width, out text_height); context.MoveTo(0, (VirtualSize.Height - text_height) / 2); context.Color = new Cairo.Color(0, 0, 0); context.ShowLayout(layout); }
private Pango.Layout CreatePagenumbersLayout(Gtk.PrintContext context, int page_number, int total_pages) { Pango.Layout layout = context.CreatePangoLayout(); layout.FontDescription = Window.Editor.Style.FontDesc; layout.Width = Pango.Units.FromPixels((int)context.Width); layout.FontDescription.Style = Pango.Style.Normal; layout.FontDescription.Weight = Pango.Weight.Light; string footer_left = string.Format(Catalog.GetString("Page {0} of {1}"), page_number, total_pages); layout.Alignment = Pango.Alignment.Left; layout.SetText(footer_left); return(layout); }
Pango.Layout clone(Pango.Layout pl) { var al = new Pango.Layout(pl.Context) { FontDescription = pl.FontDescription, Width = pl.Width, Ellipsize = pl.Ellipsize, Wrap = pl.Wrap, Alignment = pl.Alignment, Justify = pl.Justify, SingleParagraphMode = pl.SingleParagraphMode, Spacing = pl.Spacing, }; al.SetText(pl.Text); return(al); }
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); } }
private void PaintMotionIndicators(Cairo.Context gc, double width, double height, double centerx, double centery) { if (this.isTranslating) { gc.Save(); gc.Matrix.InitIdentity(); RenderPixbufToSurf(gc, arrowUp, (width / 2.0) - (arrowUp.Width / 2.0), 10); RenderPixbufToSurf(gc, arrowDown, (width / 2.0) - (arrowDown.Width / 2.0), (height - 10 - arrowDown.Height)); RenderPixbufToSurf(gc, arrowRight, (width - 10 - arrowRight.Width) + 0.5, (height / 2.0) - (arrowRight.Height / 2.0)); RenderPixbufToSurf(gc, arrowLeft, 10, (height / 2.0) - (arrowRight.Height / 2.0)); gc.Restore(); return; } if (this.isScaling) { gc.Save(); CreateRoundedRectPath(gc, width - 104, 4, 100, 110, 30); gc.Color = new Cairo.Color(0, 0, 0, 0.5); gc.Fill(); RenderPixbufToSurf(gc, zoomGlass, width - 102, 6); Pango.Layout layout = new Pango.Layout(this.PangoContext); layout.FontDescription = this.PangoContext.FontDescription.Copy(); layout.FontDescription.Size = Pango.Units.FromDouble(10.0); layout.SetText("Zooming"); Size te = GetTextSize(layout); gc.MoveTo(width - 52 - (te.Width / 2.0), 109); gc.Color = new Cairo.Color(1, 1, 1, 0.7); Pango.CairoHelper.ShowLayout(gc, layout); gc.Restore(); return; } }
private void UpdateLayout(Pango.Layout layout, string text) { string final_text = GetFormattedText(text); if (SingleParagraphMode && final_text.IndexOfAny(lfcr) >= 0) { final_text = final_text.Replace("\r\n", "\x20").Replace('\n', '\x20').Replace('\r', '\x20'); } if (use_markup) { layout.SetMarkup(final_text); } else { layout.SetText(final_text); } }
void EnsureWidths() { if (widths != null) { return; } layout.SetText("#"); int w; layout.GetPixelSize(out w, out this.height); textHeight = height; widths = new int [leftPath.Length + rightPath.Length]; CreateWidthArray(widths, 0, leftPath); CreateWidthArray(widths, leftPath.Length, rightPath); }
protected override LayoutWrapper RenderLine (long line) { Pango.Layout layout = new Pango.Layout (Editor.PangoContext); layout.FontDescription = Editor.Options.Font; StringBuilder sb = new StringBuilder (); long startOffset = line * Editor.BytesInRow; long endOffset = System.Math.Min (startOffset + Editor.BytesInRow, Data.Length); byte[] lineBytes = Data.GetBytes (startOffset, (int)(endOffset - startOffset)); for (int i = 0; i < lineBytes.Length; i++) { byte b = lineBytes[i]; char ch = (char)b; if (b < 128 && (Char.IsLetterOrDigit (ch) || Char.IsPunctuation (ch))) { sb.Append (ch); } else { sb.Append ("."); } } layout.SetText (sb.ToString ()); char[] lineChars = layout.Text.ToCharArray (); Margin.LayoutWrapper result = new LayoutWrapper (layout); uint curIndex = 0, byteIndex = 0; if (Data.IsSomethingSelected) { ISegment selection = Data.MainSelection.Segment; HandleSelection (selection.Offset, selection.EndOffset, startOffset, endOffset, null, delegate(long start, long end) { Pango.AttrForeground selectedForeground = new Pango.AttrForeground (Style.Selection.Red, Style.Selection.Green, Style.Selection.Blue); selectedForeground.StartIndex = TranslateToUTF8Index (lineChars, (uint)(start - startOffset), ref curIndex, ref byteIndex); selectedForeground.EndIndex = TranslateToUTF8Index (lineChars, (uint)(end - startOffset), ref curIndex, ref byteIndex); result.Add (selectedForeground); Pango.AttrBackground attrBackground = new Pango.AttrBackground (Style.SelectionBg.Red, Style.SelectionBg.Green, Style.SelectionBg.Blue); attrBackground.StartIndex = selectedForeground.StartIndex; attrBackground.EndIndex = selectedForeground.EndIndex; result.Add (attrBackground); }); } result.SetAttributes (); return result; }
public void Draw(Gtk.PrintContext context) { Cairo.Context con = context.CairoContext; Pango.Layout layout = context.CreatePangoLayout(); layout.SetText(this.textValue); layout.FontDescription = Pango.FontDescription.FromString(this.FontDescription); int pixelSizeWidth, pixelSizeHeight; layout.GetPixelSize(out pixelSizeWidth, out pixelSizeHeight); Console.WriteLine(" Text value: " + this.textValue); Console.WriteLine(" Pixel size width: " + pixelSizeWidth); Console.WriteLine(" Pixel size height: " + pixelSizeHeight); Console.WriteLine(" Text X position: " + this.x); Console.WriteLine(" Text Y position: " + this.y); double x_offset = pixelSizeWidth * 0; // Disabled double y_offset = pixelSizeHeight * 0.83; Console.WriteLine("width: " + x_offset); Console.WriteLine("height: " + y_offset); /// Alignment /// If text.Alignment == "center", then x coordinate is indicating /// the center, not the left side. That's way we add pixelSizeWidth/2 /// to x_offset if (this.alignment.Equals("center")) { layout.Alignment = Pango.Alignment.Center; x_offset += pixelSizeWidth / 2; } con.MoveTo(this.x - x_offset, this.y - y_offset); Pango.CairoHelper.ShowLayout(con, layout); // con.MoveTo(text.X, text.Y - y_offset); // con.LineTo(text.X + 100, text.Y - y_offset); // con.Stroke(); // // con.MoveTo(text.X, 38.4376957919563); // con.LineTo(text.X + 100, 38.4376957919563); // con.Stroke(); }
public Tab(Tabstrip parent, string label, TabPosition tabPosition) { //this.parent = parent; this.Label = label; layout = PangoUtil.CreateLayout(parent); layout.FontDescription = FontService.SansFont.CopyModified(Styles.FontScale11); layout.SetText(label); layout.Alignment = Pango.Alignment.Center; layout.GetPixelSize(out w, out h); if (IsSeparator) { w = SpacerWidth * 2; } this.TabPosition = tabPosition; }
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); int xPos = cell_area.X; if(this.Pixbuf != null){ window.DrawPixbuf(widget.Style.MidGC( StateType.Normal), this.Pixbuf, 0, 0, xPos + 1, cell_area.Y + 1, 16, 16, Gdk.RgbDither.Normal, 0, 0); xPos += 20; } using (var layout = new Pango.Layout(widget.PangoContext)) { layout.Alignment = Pango.Alignment.Left; layout.SetText(this.Text ?? ""); StateType state = flags.HasFlag(CellRendererState.Selected) ? widget.IsFocus ? StateType.Selected : StateType.Active : StateType.Normal; window.DrawLayout(widget.Style.TextGC(state), xPos, cell_area.Y + 2, layout); } }
private void UpdateButton() { if (calendarItem != null && calendarItem.id > 0) { this.Image = null; PangoText.SetText(calendarItem.Text); this.TooltipText = calendarItem.FullText; this.Relief = ReliefStyle.Normal; Drag.DestUnset(this); Drag.SourceSet(this, Gdk.ModifierType.Button1Mask, null, Gdk.DragAction.Move); Gdk.Color col = new Gdk.Color(); Gdk.Color.Parse(calendarItem.Color, ref col); logger.Debug("a={0} - {1} - {2}", col.Red, col.Green, col.Blue); this.ModifyBg(StateType.Normal, col); byte r = (byte)Math.Min(((double)col.Red / ushort.MaxValue) * byte.MaxValue + 30, byte.MaxValue); byte g = (byte)Math.Min(((double)col.Green / ushort.MaxValue) * byte.MaxValue + 30, byte.MaxValue); byte b = (byte)Math.Min(((double)col.Blue / ushort.MaxValue) * byte.MaxValue + 30, byte.MaxValue); col = new Gdk.Color(r, g, b); this.ModifyBg(StateType.Prelight, col); logger.Debug("b={0} - {1} - {2}", col.Red, col.Green, col.Blue); //Tag PangoTag.SetText(calendarItem.Tag); PangoMessages.SetText(calendarItem.MessageCount + "✉"); } else if (calendarItem != null && calendarItem.id == 0) { Pango.FontDescription desc = Pango.FontDescription.FromString("Serif Bold 35"); PangoText.FontDescription = desc; PangoText.SetText(calendarItem.Text); this.Relief = ReliefStyle.Normal; Gdk.Color col = new Gdk.Color(); Gdk.Color.Parse(calendarItem.Color, ref col); this.ModifyBg(StateType.Normal, col); this.ModifyBg(StateType.Prelight, col); } else { this.Image = null; this.TooltipText = null; Drag.SourceUnset(this); this.Relief = ReliefStyle.None; this.ModifyBg(StateType.Normal); } }
public CodePreviewWindow( Gdk.Window parentWindow, string fontName = null, EditorTheme theme = null) : base(Gtk.WindowType.Popup) { ParentWindow = parentWindow ?? MonoDevelop.Ide.IdeApp.Workbench.RootWindow.GdkWindow; AppPaintable = true; SkipPagerHint = SkipTaskbarHint = true; TypeHint = WindowTypeHint.Menu; this.fontName = fontName = fontName ?? DefaultSourceEditorOptions.Instance.FontName; layout = PangoUtil.CreateLayout(this); var font = Xwt.Drawing.Font.FromName(fontName); if (font == null) { LoggingService.LogError("Can't parse font " + fontName); } else { fontDescription = font.ToPangoFont(); fontDescription.Size = (int)(fontDescription.Size * 0.8f); layout.FontDescription = fontDescription; } layout.Ellipsize = Pango.EllipsizeMode.End; var geometry = Screen.GetUsableMonitorGeometry(Screen.GetMonitorAtWindow(ParentWindow)); maxWidth = geometry.Width * 2 / 5; maxHeight = geometry.Height * 2 / 5; layout.SetText("n"); layout.GetPixelSize(out int _, out int lineHeight); MaximumLineCount = maxHeight / lineHeight; theme = theme ?? DefaultSourceEditorOptions.Instance.GetEditorTheme(); colorText = SyntaxHighlightingService.GetColor(theme, EditorThemeColors.Foreground); colorBg = SyntaxHighlightingService.GetColor(theme, EditorThemeColors.Background); colorFold = SyntaxHighlightingService.GetColor(theme, EditorThemeColors.CollapsedText); }
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; }
public CodeSegmentPreviewWindow (TextEditor editor, bool hideCodeSegmentPreviewInformString, TextSegment segment, int width, int height, bool removeIndent = true) : base (Gtk.WindowType.Popup) { this.HideCodeSegmentPreviewInformString = hideCodeSegmentPreviewInformString; this.Segment = segment; this.editor = editor; this.AppPaintable = true; this.SkipPagerHint = this.SkipTaskbarHint = true; this.TypeHint = WindowTypeHint.Menu; layout = PangoUtil.CreateLayout (this); informLayout = PangoUtil.CreateLayout (this); informLayout.SetText (CodeSegmentPreviewInformString); fontDescription = Pango.FontDescription.FromString (editor.Options.FontName); fontDescription.Size = (int)(fontDescription.Size * 0.8f); layout.FontDescription = fontDescription; layout.Ellipsize = Pango.EllipsizeMode.End; // setting a max size for the segment (40 lines should be enough), // no need to markup thousands of lines for a preview window SetSegment (segment, removeIndent); CalculateSize (width); }
public FormattedTextImpl( string text, string fontFamily, double fontSize, FontStyle fontStyle, TextAlignment textAlignment, FontWeight fontWeight) { var context = Locator.Current.GetService<Pango.Context>(); Layout = new Pango.Layout(context); Layout.SetText(text); Layout.FontDescription = new Pango.FontDescription { Family = fontFamily, Size = Pango.Units.FromDouble(fontSize * 0.73), Style = (Pango.Style)fontStyle, Weight = fontWeight.ToCairo() }; Layout.Alignment = textAlignment.ToCairo(); }
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; }
public virtual int ComputeRowHeight(Widget widget) { int height; int text_w, text_h; Pango.Layout layout = new Pango.Layout (widget.PangoContext); layout.FontDescription = widget.PangoContext.FontDescription; layout.FontDescription.Weight = Pango.Weight.Bold; layout.SetText ("W"); layout.GetPixelSize (out text_w, out text_h); height = text_h; layout.FontDescription.Weight = Pango.Weight.Normal; layout.FontDescription.Size = (int)(layout.FontDescription.Size * Pango.Scale.Small); layout.FontDescription.Style = Pango.Style.Italic; layout.SetText ("W"); layout.GetPixelSize (out text_w, out text_h); height += text_h; layout.Dispose (); return (height < image_size ? image_size : height) + 6; }
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 (); }
private int ComputeWidgetHeight() { int width, height; Pango.Layout layout = new Pango.Layout (PangoContext); layout.SetText ("W"); layout.GetPixelSize (out width, out height); layout.Dispose (); return 2 * height; }
public void DrawText( Gdk.GC gc, Gtk.Widget widget, String text, int x, int y ) { Pango.Layout l = new Pango.Layout( widget.PangoContext ); l.SetText( text ); this.DrawLayout( gc, x, y, l ); }
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 (); }
internal LayoutDescriptor CreateLayoutDescriptor (ErrorText errorText) { LayoutDescriptor result; if (!textWidthDictionary.TryGetValue (errorText.ErrorMessage, out result)) { Pango.Layout layout = new Pango.Layout (editor.PangoContext); layout.FontDescription = fontDescription; layout.SetText (GetFirstLine (errorText)); int w, h; layout.GetPixelSize (out w, out h); textWidthDictionary[errorText.ErrorMessage] = result = new LayoutDescriptor (layout, w, h); } return result; }
void EnsureLayoutCreated (TextEditor editor) { if (editor.ColorStyle != null) { bool isError = errors.Any (e => e.IsError); string typeString = isError ? "error" : "warning"; gc = (HslColor)(editor.ColorStyle.GetChunkStyle ("bubble." + typeString + ".text").Color); gcSelected = (HslColor)editor.ColorStyle.Selection.Color; gcLight = new Cairo.Color (1, 1, 1); colorMatrix[0, 0, 0, 0, 0] = Mono.TextEditor.Highlighting.Style.ToCairoColor (editor.ColorStyle.GetChunkStyle ("bubble." + typeString + ".light.color1").Color); colorMatrix[0, 1, 0, 0, 0] = Mono.TextEditor.Highlighting.Style.ToCairoColor (editor.ColorStyle.GetChunkStyle ("bubble." + typeString + ".light.color2").Color); colorMatrix[0, 0, 1, 0, 0] = Mono.TextEditor.Highlighting.Style.ToCairoColor (editor.ColorStyle.GetChunkStyle ("bubble." + typeString + ".dark.color1").Color); colorMatrix[0, 1, 1, 0, 0] = Mono.TextEditor.Highlighting.Style.ToCairoColor (editor.ColorStyle.GetChunkStyle ("bubble." + typeString + ".dark.color2").Color); colorMatrix[0, 0, 2, 0, 0] = Mono.TextEditor.Highlighting.Style.ToCairoColor (editor.ColorStyle.GetChunkStyle ("bubble." + typeString + ".line.top").Color); colorMatrix[0, 1, 2, 0, 0] = Mono.TextEditor.Highlighting.Style.ToCairoColor (editor.ColorStyle.GetChunkStyle ("bubble." + typeString + ".line.bottom").Color); colorMatrix[1, 0, 0, 0, 0] = Mono.TextEditor.Highlighting.Style.ToCairoColor (editor.ColorStyle.GetChunkStyle ("bubble.inactive." + typeString + ".light.color1").Color); colorMatrix[1, 1, 0, 0, 0] = Mono.TextEditor.Highlighting.Style.ToCairoColor (editor.ColorStyle.GetChunkStyle ("bubble.inactive." + typeString + ".light.color2").Color); colorMatrix[1, 0, 1, 0, 0] = Mono.TextEditor.Highlighting.Style.ToCairoColor (editor.ColorStyle.GetChunkStyle ("bubble.inactive." + typeString + ".dark.color1").Color); colorMatrix[1, 1, 1, 0, 0] = Mono.TextEditor.Highlighting.Style.ToCairoColor (editor.ColorStyle.GetChunkStyle ("bubble.inactive." + typeString + ".dark.color2").Color); colorMatrix[1, 0, 2, 0, 0] = Mono.TextEditor.Highlighting.Style.ToCairoColor (editor.ColorStyle.GetChunkStyle ("bubble.inactive." + typeString + ".line.top").Color); colorMatrix[1, 1, 2, 0, 0] = Mono.TextEditor.Highlighting.Style.ToCairoColor (editor.ColorStyle.GetChunkStyle ("bubble.inactive." + typeString + ".line.bottom").Color); double factor = 1.03; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 3; k++) { HslColor color = colorMatrix[i, j, k, 0, 0]; color.L *= factor; colorMatrix[i, j, k, 1, 0] = color; } } } var selectionColor = Style.ToCairoColor (editor.ColorStyle.Selection.BackgroundColor); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 3; k++) { for (int l = 0; l < 2; l++) { var color = colorMatrix[i, j, k, l, 0]; colorMatrix[i, j, k, l, 1] = new Cairo.Color ((color.R + selectionColor.R * 1.5) / 2.5, (color.G + selectionColor.G * 1.5) / 2.5, (color.B + selectionColor.B * 1.5) / 2.5); } } } } } if (layouts != null) return; layouts = new List<LayoutDescriptor> (); fontDescription = Pango.FontDescription.FromString (editor.Options.FontName); var label = new Gtk.Label (""); fontDescription.Family = label.Style.FontDescription.Family; label.Destroy (); fontDescription.Size = (int)(fontDescription.Size * 0.9f * editor.Options.Zoom); foreach (ErrorText errorText in errors) { Pango.Layout layout = new Pango.Layout (editor.PangoContext); layout.FontDescription = fontDescription; layout.SetText (errorText.ErrorMessage); KeyValuePair<int, int> textSize; if (!textWidthDictionary.TryGetValue (errorText.ErrorMessage, out textSize)) { int w, h; layout.GetPixelSize (out w, out h); textSize = new KeyValuePair<int, int> (w, h); textWidthDictionary[errorText.ErrorMessage] = textSize; } layouts.Add (new LayoutDescriptor (layout, textSize.Key, textSize.Value)); } if (errorCountLayout == null && errors.Count > 1) { errorCountLayout = new Pango.Layout (editor.PangoContext); errorCountLayout.FontDescription = fontDescription; errorCountLayout.SetText (errors.Count.ToString ()); } }
internal void EnsureLayoutCreated (TextEditor editor) { if (layouts != null) return; layouts = new List<MessageBubbleCache.LayoutDescriptor> (); foreach (ErrorText errorText in errors) { layouts.Add (cache.CreateLayoutDescriptor (errorText)); } if (errorCountLayout == null && errors.Count > 1) { errorCountLayout = new Pango.Layout (editor.PangoContext); errorCountLayout.FontDescription = FontService.GetFontDescription ("MessageBubbles"); errorCountLayout.SetText (errors.Count.ToString ()); } }
protected override void OnDrawContent (Gdk.EventExpose evnt, Cairo.Context g) { g.Rectangle (0, 0, Allocation.Width, Allocation.Height); g.SetSourceColor (marker.TooltipColor.Color); g.Fill (); using (var drawingLayout = new Pango.Layout (this.PangoContext)) { drawingLayout.FontDescription = cache.tooltipFontDescription; double y = verticalTextBorder; var showBulletedList = marker.Errors.Count > 1; foreach (var msg in marker.Errors) { var icon = msg.IsError ? errorPixbuf : warningPixbuf; int w, h; if (!showBulletedList) drawingLayout.Width = maxTextWidth; drawingLayout.SetText (GetFirstLine (msg)); drawingLayout.GetPixelSize (out w, out h); if (showBulletedList) { g.Save (); g.Translate (textBorder, y + verticalTextSpace / 2 + Math.Max (0, (h - icon.Height) / 2)); g.DrawImage (this, icon, 0, 0); g.Restore (); } g.Save (); g.Translate (showBulletedList ? textBorder + iconTextSpacing + icon.Width: textBorder, y + verticalTextSpace / 2); g.SetSourceColor (marker.TagColor.SecondColor); g.ShowLayout (drawingLayout); g.Restore (); y += h + verticalTextSpace; } } }
protected override void OnSizeRequested (ref Gtk.Requisition requisition) { base.OnSizeRequested (ref requisition); double y = verticalTextBorder * 2 - verticalTextSpace + (MonoDevelop.Core.Platform.IsWindows ? 10 : 2); using (var drawingLayout = new Pango.Layout (this.PangoContext)) { drawingLayout.FontDescription = cache.tooltipFontDescription; foreach (var msg in marker.Errors) { if (marker.Layouts.Count == 1) drawingLayout.Width = maxTextWidth; drawingLayout.SetText (GetFirstLine (msg)); int w; int h; drawingLayout.GetPixelSize (out w, out h); if (marker.Layouts.Count > 1) w += (int)warningPixbuf.Width + iconTextSpacing; requisition.Width = Math.Max (w + textBorder * 2, requisition.Width); y += h + verticalTextSpace - 3; } } requisition.Height = (int)y; }
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; }
protected override bool OnExposeEvent (EventExpose evnt) { var ret = base.OnExposeEvent (evnt); if (image.Pixbuf != null) return ret; using (var cr = CairoHelper.Create (evnt.Window)) { cr.Rectangle (evnt.Region.Clipbox.X, evnt.Region.Clipbox.Y, evnt.Region.Clipbox.Width, evnt.Region.Clipbox.Height); cr.Clip (); var imgAlloc = image.Allocation; cr.Translate (imgAlloc.X, imgAlloc.Y); using (var layout = new Pango.Layout (PangoContext)) { layout.SetText (GettextCatalog.GetString ("No image")); layout.Width = (int)((imgAlloc.Width - 20) * Pango.Scale.PangoScale); layout.Wrap = Pango.WrapMode.WordChar; layout.Alignment = Pango.Alignment.Center; int pw, ph; layout.GetPixelSize (out pw, out ph); cr.MoveTo ((imgAlloc.Width - layout.Width / Pango.Scale.PangoScale) / 2, (imgAlloc.Height - ph) / 2); cr.Color = new Cairo.Color (0.5, 0.5, 0.5); cr.ShowLayout (layout); } CairoExtensions.RoundedRectangle (cr, 5, 5, imgAlloc.Width - 10, imgAlloc.Height - 10, 5); cr.LineWidth = 3; cr.Color = new Cairo.Color (0.8, 0.8, 0.8); cr.SetDash (new double[] { 12, 2 }, 0); cr.Stroke (); } return ret; }
public override void Render(Drawable window, Widget widget, Rectangle cell_area, Rectangle expose_area, StateType cell_state, IPhoto photo) { string date_text = null; if (photo is IInvalidPhotoCheck && (photo as IInvalidPhotoCheck).IsInvalid) return; if (cell_area.Width > 200) { date_text = photo.Time.ToString (); } else { date_text = photo.Time.ToShortDateString (); } Pango.Layout layout = null; if ( ! cache.TryGetValue (date_text, out layout)) { layout = new Pango.Layout (widget.PangoContext); layout.SetText (date_text); cache.Add (date_text, layout); } Rectangle layout_bounds; layout.GetPixelSize (out layout_bounds.Width, out layout_bounds.Height); layout_bounds.Y = cell_area.Y; layout_bounds.X = cell_area.X + (cell_area.Width - layout_bounds.Width) / 2; if (layout_bounds.IntersectsWith (expose_area)) { Style.PaintLayout (widget.Style, window, cell_state, true, expose_area, widget, "IconView", layout_bounds.X, layout_bounds.Y, layout); } }