public ClassFigure() : base() { // TODO: de-duplicate this stuff... hideInheritance = false; FillColor = new Cairo.Color (0.6367, 0.6367, 0.9570); }
public ContainerCanvas(): base () { _children = new Dictionary<Widget,ContainerCanvasChild>(); CanFocus = true; Color = new Cairo.Color (1, 1, 1); Hadjustment = NewDefaultAdjustment(); Vadjustment = NewDefaultAdjustment(); }
public BoxCanvasElement (Cairo.Color color, int width = 1, int height = 1) { this.color = color; AnchorX = width / 2.0; AnchorY = height / 2.0; SetPreferedSize (width, height); }
protected override bool OnExposeEvent (Gdk.EventExpose evt) { if (!IsDrawable) return false; int width, height; GdkWindow.GetSize (out width, out height); Gdk.Rectangle a = new Gdk.Rectangle (0,0,width,height); byte b2 = 210; int ssLT = 12; int ssRB = 7; double grey = 0.6; double greyb1 = 0.9; double greyb2 = 0.6; Gdk.Rectangle rect = a; Cairo.Color back1 = new Cairo.Color (greyb1, greyb1, greyb1); Cairo.Color back2 = new Cairo.Color (greyb2, greyb2, greyb2); Cairo.Color cdark = new Cairo.Color (grey, grey, grey, 1); Cairo.Color clight = new Cairo.Color (grey, grey, grey, 0); using (Cairo.Context cr = Gdk.CairoHelper.Create (evt.Window)) { DrawGradient (cr, rect, 0, 0, 1, 1, back1, back2); rect.X = a.X; rect.Y = a.Y; rect.Height = ssLT; rect.Width = a.Width; DrawGradient (cr, rect, 0, 0, 0, 1, cdark, clight); rect.Y = a.Bottom - ssRB; rect.Height = ssRB; DrawGradient (cr, rect, 0, 0, 0, 1, clight, cdark); rect.X = a.X; rect.Y = a.Y; rect.Width = ssLT; rect.Height = a.Height; DrawGradient (cr, rect, 0, 0, 1, 0, cdark, clight); rect.X = a.Right - ssRB; rect.Width = ssRB; DrawGradient (cr, rect, 0, 0, 1, 0, clight, cdark); Gdk.GC gc = new Gdk.GC (GdkWindow); gc.RgbBgColor = new Gdk.Color (b2,b2,b2); gc.RgbFgColor = new Gdk.Color (b2,b2,b2); GdkWindow.DrawRectangle (gc, false, a.X, a.Y, a.Width, a.Height); gc.Dispose (); } return base.OnExposeEvent (evt); }
public ProjectDetails() { buttons_back_color = new Cairo.Color (44d / 255d, 56d / 255d, 119d / 255d, 0.5); buttons_fore_color = new Cairo.Color (1, 1, 1, 1); buttons_fontname = "sans 12"; slideshows_back_color = new Cairo.Color (44d / 255d, 56d / 255d, 119d / 255d, 0.5); slideshows_fore_color = new Cairo.Color (1, 1, 1, 1); slideshows_fontname = "sans 12"; }
public CustomColorProvider() { whiteSqColor = new Cairo.Color (1, 1, 1, 1); blackSqColor = new Cairo.Color (0.9, 0.8, 0.95, 1); backgroundColor = new Cairo.Color (1, 0.95, 0.95, 1); coordColor = new Cairo.Color (0.3, 0.1, 0.1, 1); highlightSqColor = new Cairo.Color (1, 0, 0, 0.7); moveHintColor = new Cairo.Color (1, 0, 0, 0.2); arrowColor = new Cairo.Color (0.5, 0.5, 0.8, 0.5); foregroundColor = new Cairo.Color (0, 0, 0, 1); }
internal protected override void OptionsChanged () { backgroundColor = editor.ColorStyle.IndicatorMargin.Color; separatorColor = editor.ColorStyle.IndicatorMarginSeparator.Color; layout.FontDescription = editor.Options.Font; layout.SetText ("!"); int tmp; layout.GetPixelSize (out tmp, out this.marginWidth); marginWidth *= 12; marginWidth /= 10; }
protected override void DrawFrame (Cairo.Context context, double lineWidth, Cairo.Color lineColor, Cairo.Color fillColor) { // base.DrawFrame (context, lineWidth, lineColor, fillColor); rect = DisplayBox; rect.OffsetDot5(); // HERZUM SPRINT 1.2 // CairoFigures.CurvedRectangle(context, rect, 30); CairoFigures.AngleFrame(context, rect, 0,0,0,0); // END HERZUM SPRINT 1.2 Cairo.Color fillColorOrigin; fillColorOrigin = fillColor; lineWidth = 1; fillColor = new Cairo.Color (1.0, 1.0, 1.0, 1.0); context.Color = fillColor; context.FillPreserve(); context.Color = lineColor; context.LineWidth = lineWidth; double[] dash = {2, 0, 2}; context.SetDash (dash, 0); context.Stroke(); rect2 = DisplayBox; rect2.Width = DisplayBox.Width; rect2.Height = 30; rect2.OffsetDot5(); CairoFigures.CurvedRectangle(context, rect2, 30); fillColor = fillColorOrigin; context.Color = fillColor; context.FillPreserve(); context.Color = lineColor; context.LineWidth = lineWidth; context.Stroke(); // HERZUM SPRINT 2.1 // m_applicationContext.MainWindow.ExperimentCanvasPad.LoopNodeControlCurrent = this; // END HERZUM SPRINT 2.1 // HERZUM SPRINT 5.0: TLAB-235 // DrawScope (); DrawScope ("Enter","Exit"); // END HERZUM SPRINT 5.0: TLAB-235 }
void IChunkMarker.ChangeForeColor (MonoTextEditor editor, Chunk chunk, ref Cairo.Color color) { if (Debugger.DebuggingService.IsDebugging) return; int markerStart = Segment.Offset; int markerEnd = Segment.EndOffset; if (chunk.EndOffset <= markerStart || markerEnd <= chunk.Offset) return; var bgc = editor.ColorStyle.PlainText.Background; double alpha = 0.6; color = new Cairo.Color ( color.R * alpha + bgc.R * (1.0 - alpha), color.G * alpha + bgc.G * (1.0 - alpha), color.B * alpha + bgc.B * (1.0 - alpha) ); }
internal protected override void OptionsChanged () { lineNumberBgGC = editor.ColorStyle.LineNumbers.Background; lineNumberGC = editor.ColorStyle.LineNumbers.Foreground; gutterFont = editor.Options.GutterFont; // gutterFont.Weight = (Pango.Weight)editor.ColorStyle.LineNumbers.FontWeight; // gutterFont.Style = (Pango.Style)editor.ColorStyle.LineNumbers.FontStyle; /* if (Platform.IsWindows) { gutterFont.Size = (int)(Pango.Scale.PangoScale * 8.0 * editor.Options.Zoom); } else { gutterFont.Size = (int)(Pango.Scale.PangoScale * 11.0 * editor.Options.Zoom); }*/ CalculateWidth (); }
public SearchPopupWindow () { headerColor = Styles.GlobalSearch.HeaderTextColor.ToCairoColor (); separatorLine = Styles.GlobalSearch.SeparatorLineColor.ToCairoColor (); lightSearchBackground = Styles.GlobalSearch.HeaderBackgroundColor.ToCairoColor (); darkSearchBackground = Styles.GlobalSearch.BackgroundColor.ToCairoColor (); selectionBackgroundColor = Styles.GlobalSearch.SelectionBackgroundColor.ToCairoColor (); TypeHint = Gdk.WindowTypeHint.Combo; this.SkipTaskbarHint = true; this.SkipPagerHint = true; this.TransientFor = IdeApp.Workbench.RootWindow; this.AllowShrink = false; this.AllowGrow = false; categories.Add (new FileSearchCategory ()); categories.Add (new CommandSearchCategory ()); categories.Add (new SearchInSolutionSearchCategory ()); foreach (var cat in AddinManager.GetExtensionObjects<SearchCategory> ("/MonoDevelop/Ide/SearchCategories")) { categories.Add (cat); cat.Initialize (this); } categories.Sort (); layout = new Pango.Layout (PangoContext); headerLayout = new Pango.Layout (PangoContext); layout.Ellipsize = Pango.EllipsizeMode.End; headerLayout.Ellipsize = Pango.EllipsizeMode.End; Events = Gdk.EventMask.ButtonPressMask | Gdk.EventMask.ButtonMotionMask | Gdk.EventMask.ButtonReleaseMask | Gdk.EventMask.ExposureMask | Gdk.EventMask.PointerMotionMask; ItemActivated += (sender, e) => OpenFile (); }
private static void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { Timer t = (Timer)sender; t.Stop(); const double min = 0.65; const double max = 0.95; const double d = 0.01; switch (rgb) { case rgbadd.addr: if (r >= max) { rgb = rgbadd.minb; } break; case rgbadd.addg: if (g >= max) { rgb = rgbadd.minr; } break; case rgbadd.addb: if (b >= max) { rgb = rgbadd.ming; } break; case rgbadd.minr: if (r <= min) { rgb = rgbadd.addb; } break; case rgbadd.ming: if (g <= min) { rgb = rgbadd.addr; } break; case rgbadd.minb: if (b <= min) { rgb = rgbadd.addg; } break; case rgbadd.addrgb: if (b >= max) { rgb = rgbadd.minb; } break; case rgbadd.minrgb: if (b <= min) { rgb = rgbadd.addb; } break; default: break; } switch (rgb) { case rgbadd.addr: r += d; break; case rgbadd.addg: g += d; break; case rgbadd.addb: b += d; break; case rgbadd.minr: r -= d; break; case rgbadd.ming: g -= d; break; case rgbadd.minb: b -= d; break; case rgbadd.addrgb: r += d; g += d; b += d; break; case rgbadd.minrgb: r -= d; g -= d; b -= d; break; default: break; } back = new Cairo.Color(r, g, b, 0.999); t.Start(); }
protected override bool OnExposeEvent (Gdk.EventExpose e) { using (Cairo.Context cr = Gdk.CairoHelper.Create (e.Window)) { cr.LineWidth = Math.Max (1.0, widget.Editor.Options.Zoom); cr.Rectangle (leftSpacer, 0, Allocation.Width, Allocation.Height); cr.Color = new Cairo.Color (0.95, 0.95, 0.95); cr.Fill (); int startLine = widget.Editor.YToLine ((int)widget.Editor.VAdjustment.Value); double startY = widget.Editor.LineToY (startLine); while (startLine > 1 && startLine < annotations.Count && annotations[startLine - 1] != null && annotations[startLine] != null && annotations[startLine - 1].Revision == annotations[startLine].Revision) { startLine--; startY -= widget.Editor.GetLineHeight (widget.Editor.Document.GetLine (startLine)); } double curY = startY - widget.Editor.VAdjustment.Value; int line = startLine; while (curY < Allocation.Bottom) { double curStart = curY; // widget.JumpOverFoldings (ref line); int lineStart = line; int w = 0, w2 = 0, h = 16; Annotation ann = line <= annotations.Count ? annotations[line - 1] : null; if (ann != null) { do { widget.JumpOverFoldings (ref line); line++; } while (line + 1 <= annotations.Count && annotations[line - 1] != null && annotations[line - 1].Revision == ann.Revision); double nextY = widget.editor.LineToY (line) - widget.editor.VAdjustment.Value; if (highlightAnnotation != null && highlightAnnotation.Revision == ann.Revision && curStart <= highlightPositon && highlightPositon < nextY) { cr.Rectangle (leftSpacer, curStart + cr.LineWidth, Allocation.Width - leftSpacer, nextY - curStart - cr.LineWidth); cr.Color = new Cairo.Color (1, 1, 1); cr.Fill (); } layout.SetText (ann.Author); layout.GetPixelSize (out w, out h); e.Window.DrawLayout (Style.BlackGC, leftSpacer + margin, (int)(curY + (widget.Editor.LineHeight - h) / 2), layout); layout.SetText (TruncRevision (ann.Revision)); layout.GetPixelSize (out w2, out h); e.Window.DrawLayout (Style.BlackGC, Allocation.Width - w2 - margin, (int)(curY + (widget.Editor.LineHeight - h) / 2), layout); if (ann.HasDate) { string dateTime = ann.Date.ToShortDateString (); int middle = w + (Allocation.Width - margin * 2 - leftSpacer - w - w2) / 2; layout.SetText (dateTime); layout.GetPixelSize (out w, out h); e.Window.DrawLayout (Style.BlackGC, leftSpacer + margin + middle - w / 2, (int)(curY + (widget.Editor.LineHeight - h) / 2), layout); } curY = nextY; } else { curY += widget.Editor.GetLineHeight (line); line++; widget.JumpOverFoldings (ref line); } if (ann != null && line - lineStart > 1) { string msg = GetCommitMessage (lineStart); if (!string.IsNullOrEmpty (msg)) { msg = FormatMessage (msg); layout.SetText (msg); layout.Width = (int)(Allocation.Width * Pango.Scale.PangoScale); using (var gc = new Gdk.GC (e.Window)) { gc.RgbFgColor = Style.Dark (State); gc.ClipRectangle = new Rectangle (0, (int)curStart, Allocation.Width, (int)(curY - curStart)); e.Window.DrawLayout (gc, (int)(leftSpacer + margin), (int)(curStart + h), layout); } } } cr.Rectangle (0, curStart, leftSpacer, curY - curStart); if (ann != null && ann != locallyModified && !string.IsNullOrEmpty (ann.Author)) { double a; if (ann != null && (maxDate - minDate).TotalHours > 0) { a = 1 - (ann.Date - minDate).TotalHours / (maxDate - minDate).TotalHours; } else { a = 1; } HslColor color = new Cairo.Color (0.90, 0.90, 1); color.L = 0.4 + a / 2; color.S = 1 - a / 2; cr.Color = color; } else { cr.Color = ann != null ? new Cairo.Color (1, 1, 0) : new Cairo.Color (0.95, 0.95, 0.95); } cr.Fill (); if (ann != null) { cr.MoveTo (0, curY + 0.5); cr.LineTo (Allocation.Width, curY + 0.5); cr.Color = new Cairo.Color (0.6, 0.6, 0.6); cr.Stroke (); } } } return true; }
public BackgroundColor (Cairo.Color color, int fromIdx, int toIdx) { this.Color = color; this.FromIdx = fromIdx; this.ToIdx = toIdx; }
protected override void OnRealized () { SetFlag(Gtk.WidgetFlags.Realized); Gdk.WindowAttr attributes = new Gdk.WindowAttr(); attributes.WindowType = Gdk.WindowType.Child; attributes.X = Allocation.X; attributes.Y = Allocation.Y; attributes.Width = Allocation.Width; attributes.Height = Allocation.Height; attributes.Wclass = WindowClass.InputOutput; attributes.Visual = Visual; attributes.Colormap = Colormap; // This enables all events except PointerMotionHitMask which prevents correct behavior // of MotionNotifyEvent attributes.EventMask = (int) (Gdk.EventMask.AllEventsMask & (~Gdk.EventMask.PointerMotionHintMask)); Gdk.WindowAttributesType mask = WindowAttributesType.X | WindowAttributesType.Y | WindowAttributesType.Visual | WindowAttributesType.Colormap; GdkWindow = new Gdk.Window(ParentWindow, attributes, (int) mask); GdkWindow.UserData = Handle; GdkWindow.SetBackPixmap(null, false); Style = Style.Attach(GdkWindow); Style.SetBackground(GdkWindow, StateType.Normal); Color = new Cairo.Color(1.0, 1.0, 1.0); }
protected override bool OnExposeEvent (Gdk.EventExpose args) { using (var g = Gdk.CairoHelper.Create (args.Window)) { g.SetSourceRGBA (1, 1, 1, 0); g.Operator = Cairo.Operator.Source; g.Paint (); } Cairo.Color bgColor = new Cairo.Color (1, 1, 1); Cairo.Color titleBgColor = new Cairo.Color (0.88, 0.88, 0.98); Cairo.Color categoryBgColor = new Cairo.Color (0.58, 0.58, 0.98); Cairo.Color borderColor = new Cairo.Color (0.4, 0.4, 0.6); Cairo.Color textColor = new Cairo.Color (0.3, 0.3, 1); Cairo.Color gridColor = new Cairo.Color (0.8, 0.8, 0.8); using (var g = Gdk.CairoHelper.Create (args.Window)) { g.LineWidth = 1; Gdk.GC gc = new Gdk.GC (args.Window); layout.SetMarkup (TitleText); int width, height; layout.GetPixelSize (out width, out height); width += xBorder * 2; FoldingScreenbackgroundRenderer.DrawRoundRectangle (g, true, false, 0.5, 0.5, height + yBorder * 2 + 1.5, width, height + yBorder * 2); g.Color = titleBgColor; g.FillPreserve (); g.Color = borderColor; g.Stroke (); gc.RgbFgColor = (HslColor)textColor; args.Window.DrawLayout (gc, xBorder, yBorder, layout); FoldingScreenbackgroundRenderer.DrawRoundRectangle (g, false, true, 0.5, height * 2 + yBorder * 2 + 0.5, height, Allocation.Width - 1, Allocation.Height - height * 2 - yBorder * 2 - 1); g.Color = bgColor; g.FillPreserve (); g.Color = borderColor; g.Stroke (); g.MoveTo (xSpacer + 0.5, height * 2 + yBorder * 2); g.LineTo (xSpacer + 0.5, Allocation.Height - 1); g.Color = gridColor; g.Stroke (); int y = height + yBorder * 2; for (int i = 0; i < Items.Count; i++) { KeyValuePair<string, string> pair = Items[i]; layout.SetMarkup (pair.Key); layout.GetPixelSize (out width, out height); if (i == 0) { FoldingScreenbackgroundRenderer.DrawRoundRectangle (g, false, true, false, false, 0, y + 0.5, height + 1.5, Allocation.Width, height); g.Color = categoryBgColor; g.FillPreserve (); g.Color = borderColor; g.Stroke (); g.MoveTo (xSpacer + 0.5, height + yBorder * 2 + 1); g.LineTo (xSpacer + 0.5, height * 2 + yBorder * 2 + 1); g.Color = gridColor; g.Stroke (); } gc.RgbFgColor = (HslColor)(i == 0 ? bgColor : textColor); args.Window.DrawLayout (gc, xBorder, y, layout); layout.SetMarkup (pair.Value); args.Window.DrawLayout (gc, xSpacer + xBorder, y, layout); // draw top line if (i > 0) { g.MoveTo (1, y + 0.5); g.LineTo (Allocation.Width - 1, y + 0.5); g.Color = gridColor; g.Stroke (); } y += height; } gc.Dispose (); } return false; }
internal static void SetSourceColor(this Cairo.Context cr, Cairo.Color color) { cr.SetSourceRGBA(color.R, color.G, color.B, color.A); }
internal static VBox CreateCategory(string categoryName, string categoryContentMarkup, Cairo.Color foreColor, Pango.FontDescription font) { var vbox = new VBox(); vbox.Spacing = 8; if (categoryName != null) { var catLabel = new FixedWidthWrapLabel(); catLabel.Markup = categoryName; catLabel.ModifyFg(StateType.Normal, foreColor.ToGdkColor()); catLabel.FontDescription = font.Copy(); catLabel.FontDescription.Weight = Pango.Weight.Bold; catLabel.FontDescription.Size = catLabel.FontDescription.Size + (int)(1 * Pango.Scale.PangoScale); vbox.PackStart(catLabel, false, true, 0); } var contentLabel = new FixedWidthWrapLabel(); HBox hbox = new HBox(); // hbox.PackStart (new Label(), false, true, 10); contentLabel.Wrap = Pango.WrapMode.WordChar; contentLabel.Spacing = 1; contentLabel.BreakOnCamelCasing = false; contentLabel.BreakOnPunctuation = false; contentLabel.MaxWidth = 400; contentLabel.Markup = categoryContentMarkup.Trim(); contentLabel.ModifyFg(StateType.Normal, foreColor.ToGdkColor()); contentLabel.FontDescription = font; hbox.PackStart(contentLabel, true, true, 0); vbox.PackStart(hbox, true, true, 0); return(vbox); }
private void DrawBackground(Cairo.Context g, Cairo.Rectangle rect, StyleInfo si) { // LinearGradientBrush linGrBrush = null; // SolidBrush sb = null; if (si.BackgroundColor.IsEmpty) { return; } g.Save(); Cairo.Color c = si.BackgroundColor.ToCairoColor(); Cairo.Gradient gradient = null; if (si.BackgroundGradientType != BackgroundGradientTypeEnum.None && !si.BackgroundGradientEndColor.IsEmpty) { Cairo.Color ec = si.BackgroundGradientEndColor.ToCairoColor(); switch (si.BackgroundGradientType) { case BackgroundGradientTypeEnum.LeftRight: // linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Horizontal); gradient = new Cairo.LinearGradient(rect.X, rect.Y, rect.X + rect.Width, rect.Y); break; case BackgroundGradientTypeEnum.TopBottom: // linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Vertical); gradient = new Cairo.LinearGradient(rect.X, rect.Y, rect.X, rect.Y + rect.Height); break; case BackgroundGradientTypeEnum.Center: // linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Horizontal); throw new NotSupportedException(); // break; case BackgroundGradientTypeEnum.DiagonalLeft: // linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.ForwardDiagonal); gradient = new Cairo.LinearGradient(rect.X, rect.Y, rect.X + rect.Width, rect.Y + rect.Height); break; case BackgroundGradientTypeEnum.DiagonalRight: // linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.BackwardDiagonal); gradient = new Cairo.LinearGradient(rect.X + rect.Width, rect.Y + rect.Height, rect.X, rect.Y); break; case BackgroundGradientTypeEnum.HorizontalCenter: // linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Horizontal); throw new NotSupportedException(); // break; case BackgroundGradientTypeEnum.VerticalCenter: // linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Vertical); throw new NotSupportedException(); // break; default: break; } gradient.AddColorStop(0, c); gradient.AddColorStop(1, ec); } if (gradient != null) { //// g.FillRectangle(linGrBrush, rect); g.FillRectangle(rect, gradient); gradient.Destroy(); } else if (!si.BackgroundColor.IsEmpty) { g.FillRectangle(rect, c); // g.DrawRoundedRectangle (rect, 2, c, 1); // g.FillRoundedRectangle (rect, 8, c); } g.Restore(); }
public static string ColorToPangoMarkup(Cairo.Color color) { return(ColorToPangoMarkup((Gdk.Color)((HslColor)color))); }
public void LoadFromString(string style) { foreach (string pair in style.Split(new [] { ';' }, StringSplitOptions.RemoveEmptyEntries)) { string [] pairParts = pair.Trim().Split(new [] { ':' }, StringSplitOptions.RemoveEmptyEntries); string pixelsValue; if (pairParts.Length == 2) { pixelsValue = pairParts [1].EndsWith("px") ? pairParts [1].Substring(0, pairParts [1].Length - 2) : pairParts [1]; } else { pixelsValue = string.Empty; } float floatValue; bool boolValue; switch (pairParts [0].ToLowerInvariant()) { case "xstart": if (float.TryParse(pixelsValue, out floatValue)) { xStart = floatValue; } break; case "ystart": if (float.TryParse(pixelsValue, out floatValue)) { yStart = floatValue; } break; case "width": if (pairParts [1].EndsWith("%")) { if (float.TryParse(pairParts [1].Substring(0, pairParts [1].Length - 1), out floatValue)) { relativeWidth = floatValue; } } else { if (float.TryParse(pixelsValue, out floatValue)) { width = floatValue; } } break; case "height": if (pairParts [1].EndsWith("%")) { if (float.TryParse(pairParts [1].Substring(0, pairParts [1].Length - 1), out floatValue)) { relativeHeight = floatValue; } } else { if (float.TryParse(pixelsValue, out floatValue)) { height = floatValue; } } break; case "padding": if (float.TryParse(pixelsValue, out floatValue)) { hPadding = vPadding = floatValue; } break; case "hpadding": if (float.TryParse(pixelsValue, out floatValue)) { hPadding = floatValue; } break; case "vpadding": if (float.TryParse(pixelsValue, out floatValue)) { vPadding = floatValue; } break; case "hfill": if (bool.TryParse(pairParts [1], out boolValue)) { hFill = boolValue; } break; case "vfill": if (bool.TryParse(pairParts [1], out boolValue)) { vFill = boolValue; } break; case "border": if (float.TryParse(pixelsValue, out floatValue)) { border = floatValue; } break; case "innerborder": if (float.TryParse(pixelsValue, out floatValue)) { innerHorizontalBorder = innerVerticalBorder = floatValue; } break; case "innerhborder": if (float.TryParse(pixelsValue, out floatValue)) { innerHorizontalBorder = floatValue; } break; case "innervborder": if (float.TryParse(pixelsValue, out floatValue)) { innerVerticalBorder = floatValue; } break; case "spacing": if (float.TryParse(pixelsValue, out floatValue)) { spacing = floatValue; } break; case "innerspacing": if (float.TryParse(pixelsValue, out floatValue)) { innerHSpacing = innerVSpacing = floatValue; } break; case "innerhspacing": if (float.TryParse(pixelsValue, out floatValue)) { innerHSpacing = floatValue; } break; case "innervspacing": if (float.TryParse(pixelsValue, out floatValue)) { innerVSpacing = floatValue; } break; case "halign": switch (pairParts [1].ToLowerInvariant()) { case "left": break; case "right": hAlign = HorizontalAlignment.Right; break; case "center": hAlign = HorizontalAlignment.Center; break; default: hAlign = HorizontalAlignment.Left; break; } break; case "valign": switch (pairParts [1].ToLowerInvariant()) { case "bottom": vAlign = VerticalAlignment.Bottom; break; case "center": vAlign = VerticalAlignment.Center; break; default: vAlign = VerticalAlignment.Top; break; } break; case "drawempty": if (bool.TryParse(pairParts [1], out boolValue)) { drawEmpty = boolValue; } break; case "allowhbreak": if (bool.TryParse(pairParts [1], out boolValue)) { allowHBreak = boolValue; } break; case "allowvbreak": if (bool.TryParse(pairParts [1], out boolValue)) { allowVBreak = boolValue; } break; case "bgcolor": bgColor = CairoExtensions.FromHTMLColor(pairParts [1]); break; case "fgcolor": fgColor = CairoExtensions.FromHTMLColor(pairParts [1]); break; case "bordercolor": borderColor = CairoExtensions.FromHTMLColor(pairParts [1]); break; } } }
public ChunkStyle(Cairo.Color color, ChunkProperties chunkProperties) { this.CairoColor = color; this.ChunkProperties = chunkProperties; }
public ChunkStyle(Cairo.Color color, Cairo.Color bgColor, ChunkProperties chunkProperties) { this.CairoColor = color; this.CairoBackgroundColor = bgColor; this.ChunkProperties = chunkProperties; }
public LineBackgroundMarker (Cairo.Color color) { this.color = color; }
protected internal override void Draw (Cairo.Context cr, Cairo.Rectangle area, LineSegment line, int lineNr, double x, double y, double _lineHeight) { // double xStart = System.Math.Max (area.X, XOffset); // xStart = System.Math.Max (0, xStart); var lineArea = new Cairo.Rectangle (XOffset - 1, y, textEditor.Allocation.Width - XOffset + 1, _lineHeight); int width, height; double pangoPosition = (x - textEditor.HAdjustment.Value + TextStartPosition) * Pango.Scale.PangoScale; defaultBgColor = Document.ReadOnly ? ColorStyle.ReadOnlyTextBg : ColorStyle.Default.CairoBackgroundColor; // Draw the default back color for the whole line. Colors other than the default // background will be drawn when rendering the text chunks. DrawRectangleWithRuler (cr, x, lineArea, defaultBgColor, true); bool isSelectionDrawn = false; if (BackgroundRenderer != null) BackgroundRenderer.Draw (cr, area, line, x, y, _lineHeight); // Check if line is beyond the document length if (line == null) { if (textEditor.Options.ShowInvalidLines) DrawInvalidLineMarker (cr, pangoPosition / Pango.Scale.PangoScale, y); var marker = Document.GetExtendingTextMarker (lineNr); if (marker != null) marker.Draw (textEditor, cr, lineNr, lineArea); return; } IEnumerable<FoldSegment> foldings = Document.GetStartFoldings (line); int offset = line.Offset; int caretOffset = Caret.Offset; bool isEolFolded = false; restart: int logicalRulerColumn = line.GetLogicalColumn (textEditor.GetTextEditorData (), textEditor.Options.RulerColumn); foreach (FoldSegment folding in foldings) { int foldOffset = folding.StartLine.Offset + folding.Column - 1; if (foldOffset < offset) continue; if (folding.IsFolded) { DrawLinePart (cr, line, lineNr, logicalRulerColumn, offset, foldOffset - offset, ref pangoPosition, ref isSelectionDrawn, y, area.X + area.Width); offset = folding.EndLine.Offset + folding.EndColumn; markerLayout.SetText (folding.Description); markerLayout.GetSize (out width, out height); bool isFoldingSelected = !this.HideSelection && textEditor.IsSomethingSelected && textEditor.SelectionRange.Contains (folding.Segment); double pixelX = pangoPosition / Pango.Scale.PangoScale; double pixelWidth = (pangoPosition + width) / Pango.Scale.PangoScale - pixelX; var foldingRectangle = new Cairo.Rectangle (pixelX + 0.5, y + 0.5, pixelWidth - cr.LineWidth, this.LineHeight - cr.LineWidth); if (BackgroundRenderer == null) { cr.Color = isFoldingSelected ? SelectionColor.CairoBackgroundColor : defaultBgColor; cr.Rectangle (foldingRectangle); cr.Fill (); } cr.Color = isFoldingSelected ? SelectionColor.CairoColor : ColorStyle.FoldLine.CairoColor; cr.Rectangle (foldingRectangle); cr.Stroke (); cr.Save (); cr.Translate (pangoPosition / Pango.Scale.PangoScale, y); cr.Color = isFoldingSelected ? SelectionColor.CairoColor : ColorStyle.FoldLine.CairoColor; cr.ShowLayout (markerLayout); cr.Restore (); if (caretOffset == foldOffset && !string.IsNullOrEmpty (folding.Description)) SetVisibleCaretPosition ((int)(pangoPosition / Pango.Scale.PangoScale), y); pangoPosition += width; if (caretOffset == foldOffset + folding.Length && !string.IsNullOrEmpty (folding.Description)) SetVisibleCaretPosition ((int)(pangoPosition / Pango.Scale.PangoScale), y); if (folding.EndLine != line) { line = folding.EndLine; lineNr = Document.OffsetToLineNumber (line.Offset); foldings = Document.GetStartFoldings (line); isEolFolded = line.Length <= folding.EndColumn; goto restart; } isEolFolded = line.Length <= folding.EndColumn; } } // Draw remaining line - must be called for empty line parts as well because the caret may be at this positon // and the caret position is calculated in DrawLinePart. if (line.EndOffsetIncludingDelimiter - offset >= 0) DrawLinePart (cr, line, lineNr, logicalRulerColumn, offset, line.Offset + line.Length - offset, ref pangoPosition, ref isSelectionDrawn, y, area.X + area.Width); bool isEolSelected = !this.HideSelection && textEditor.IsSomethingSelected && textEditor.SelectionMode == SelectionMode.Normal && textEditor.SelectionRange.Contains (line.Offset + line.Length); lineArea = new Cairo.Rectangle (pangoPosition / Pango.Scale.PangoScale, lineArea.Y, textEditor.Allocation.Width - pangoPosition / Pango.Scale.PangoScale, lineArea.Height); if (textEditor.SelectionMode == SelectionMode.Block && textEditor.IsSomethingSelected && textEditor.SelectionRange.Contains (line.Offset + line.Length)) { DocumentLocation start = textEditor.MainSelection.Anchor; DocumentLocation end = textEditor.MainSelection.Lead; DocumentLocation visStart = textEditor.LogicalToVisualLocation (start); DocumentLocation visEnd = textEditor.LogicalToVisualLocation (end); double x1 = this.ColumnToX (line, visStart.Column); double x2 = this.ColumnToX (line, visEnd.Column); if (x1 > x2) { var tmp = x1; x1 = x2; x2 = tmp; } x1 += XOffset - textEditor.HAdjustment.Value; x2 += XOffset - textEditor.HAdjustment.Value; if (x2 > lineArea.X) { if (x1 - lineArea.X > 0) { DrawRectangleWithRuler (cr, x, new Cairo.Rectangle (lineArea.X, lineArea.Y, x1 - lineArea.X, lineArea.Height), defaultBgColor, false); lineArea = new Cairo.Rectangle (x1, lineArea.Y, lineArea.Width, lineArea.Height); } DrawRectangleWithRuler (cr, x, new Cairo.Rectangle (lineArea.X, lineArea.Y, x2 - lineArea.X, lineArea.Height), this.SelectionColor.CairoBackgroundColor, false); lineArea = new Cairo.Rectangle (x2, lineArea.Y, textEditor.Allocation.Width - lineArea.X, lineArea.Height); } } if (!isSelectionDrawn) { if (isEolSelected) { if (!Platform.IsMac) { // prevent "gaps" in the selection drawing ('fuzzy' lines problem) lineArea = new Cairo.Rectangle (pangoPosition / Pango.Scale.PangoScale, lineArea.Y, textEditor.Allocation.Width - pangoPosition / Pango.Scale.PangoScale + 1, lineArea.Height); } else { // prevent "gaps" in the selection drawing ('fuzzy' lines problem) lineArea = new Cairo.Rectangle (pangoPosition / Pango.Scale.PangoScale - 1, lineArea.Y, textEditor.Allocation.Width - pangoPosition / Pango.Scale.PangoScale + 1, lineArea.Height); } DrawRectangleWithRuler (cr, x, lineArea, this.SelectionColor.CairoBackgroundColor, false); } else if (!(HighlightCaretLine || textEditor.Options.HighlightCaretLine) || Caret.Line != lineNr) { LayoutWrapper wrapper = GetLayout (line); if (wrapper.EolSpanStack != null) { foreach (var span in wrapper.EolSpanStack) { var spanStyle = textEditor.ColorStyle.GetChunkStyle (span.Color); if (!spanStyle.TransparentBackround && GetPixel (ColorStyle.Default.BackgroundColor) != GetPixel (spanStyle.BackgroundColor)) { DrawRectangleWithRuler (cr, x, lineArea, spanStyle.CairoBackgroundColor, false); break; } } } } else { double xPos = pangoPosition / Pango.Scale.PangoScale; DrawCaretLineMarker (cr, xPos, y, lineArea.X + lineArea.Width - xPos); } } if (!isEolFolded && textEditor.Options.ShowEolMarkers) DrawEolMarker (cr, line, isEolSelected, pangoPosition / Pango.Scale.PangoScale, y); var extendingMarker = Document.GetExtendingTextMarker (lineNr); if (extendingMarker != null) extendingMarker.Draw (textEditor, cr, lineNr, lineArea); lastLineRenderWidth = pangoPosition / Pango.Scale.PangoScale; }
protected override bool OnExposeEvent(Gdk.EventExpose evnt) { Gdk.Rectangle rect = Allocation; //Gdk.Rectangle.Right and Bottom are inconsistent int right = rect.X + rect.Width, bottom = rect.Y + rect.Height; if (GradientBackround) { HslColor gcol = Style.Background(Gtk.StateType.Normal); using (Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window)) { cr.NewPath(); cr.MoveTo(rect.X, rect.Y); cr.RelLineTo(rect.Width, 0); cr.RelLineTo(0, rect.Height); cr.RelLineTo(-rect.Width, 0); cr.RelLineTo(0, -rect.Height); cr.ClosePath(); Cairo.Gradient pat = new Cairo.LinearGradient(rect.X, rect.Y, rect.X, bottom); Cairo.Color color1 = gcol; pat.AddColorStop(0, color1); gcol.L -= 0.1; if (gcol.L < 0) { gcol.L = 0; } pat.AddColorStop(1, gcol); cr.Pattern = pat; cr.FillPreserve(); } } bool res = base.OnExposeEvent(evnt); using (Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window)) { cr.Color = (HslColor)Style.Dark(Gtk.StateType.Normal); double y = rect.Y + topMargin / 2d; cr.LineWidth = topMargin; cr.Line(rect.X, y, right, y); cr.Stroke(); y = bottom - bottomMargin / 2d; cr.LineWidth = bottomMargin; cr.Line(rect.X, y, right, y); cr.Stroke(); double x = rect.X + leftMargin / 2d; cr.LineWidth = leftMargin; cr.Line(x, rect.Y, x, bottom); cr.Stroke(); x = right - rightMargin / 2d; cr.LineWidth = rightMargin; cr.Line(x, rect.Y, x, bottom); cr.Stroke(); } return(res); }
public abstract void DrawRowCursor(Cairo.Context cr, int x, int y, int width, int height, Cairo.Color color, CairoCorners corners);
public HslColor(Cairo.Color color) : this(color.R, color.G, color.B) { }
public static System.Drawing.Color ToSystemDrawingColor(this Cairo.Color color) { return(System.Drawing.Color.FromArgb((byte)(color.A * 255), (byte)(color.R * 255), (byte)(color.G * 255), (byte)(color.B * 255))); }
void IChunkMarker.ChangeForeColor(MonoTextEditor editor, MonoDevelop.Ide.Editor.Highlighting.ColoredSegment chunk, ref Cairo.Color color) { if (forground == null || editor == null) { return; } int markerStart = Segment.Offset; int markerEnd = Segment.EndOffset; if (chunk.EndOffset <= markerStart || markerEnd <= chunk.Offset) { return; } color = forground(editor).Foreground; }
internal static Cairo.Color DimColor (Cairo.Color color, double dimFactor) { var result = new Cairo.Color (color.R * dimFactor, color.G * dimFactor, color.B * dimFactor); return result; }
// Taken from Mono.TextEditor.HelperMethods. public static void SetSourceColor(Cairo.Context cr, Cairo.Color color) { cr.SetSourceRGBA(color.R, color.G, color.B, color.A); }
protected override bool OnExposeEvent(Gdk.EventExpose e) { using (Cairo.Context cr = Gdk.CairoHelper.Create(e.Window)) { cr.LineWidth = Math.Max(1.0, widget.Editor.Options.Zoom); cr.Rectangle(leftSpacer, 0, Allocation.Width, Allocation.Height); cr.SetSourceRGB(0.95, 0.95, 0.95); cr.Fill(); int startLine = widget.Editor.YToLine((int)widget.Editor.VAdjustment.Value); double startY = widget.Editor.LineToY(startLine); while (startLine > 1 && startLine < annotations.Count && annotations[startLine - 1] != null && annotations[startLine] != null && annotations[startLine - 1].Revision == annotations[startLine].Revision) { startLine--; startY -= widget.Editor.GetLineHeight(widget.Editor.Document.GetLine(startLine)); } double curY = startY - widget.Editor.VAdjustment.Value; int line = startLine; while (curY < Allocation.Bottom && line <= widget.Editor.LineCount) { double curStart = curY; // widget.JumpOverFoldings (ref line); int lineStart = line; int authorWidth = 0, revisionWidth = 0, dateWidth = 0, h = 16; Annotation ann = line <= annotations.Count ? annotations[line - 1] : null; if (ann != null) { do { widget.JumpOverFoldings(ref line); line++; } while (line <= annotations.Count && annotations[line - 1] != null && annotations[line - 1].Revision == ann.Revision); double nextY = widget.editor.LineToY(line) - widget.editor.VAdjustment.Value; if (highlightAnnotation != null && highlightAnnotation.Revision == ann.Revision && curStart <= highlightPositon && highlightPositon < nextY) { cr.Rectangle(leftSpacer, curStart + cr.LineWidth, Allocation.Width - leftSpacer, nextY - curStart - cr.LineWidth); cr.SetSourceRGB(1, 1, 1); cr.Fill(); } // use a fixed size revision to get a approx. revision width layout.SetText("88888888"); layout.GetPixelSize(out revisionWidth, out h); layout.SetText(TruncRevision(ann.Text)); e.Window.DrawLayout(Style.BlackGC, Allocation.Width - revisionWidth - margin, (int)(curY + (widget.Editor.LineHeight - h) / 2), layout); const int dateRevisionSpacing = 16; if (ann.HasDate) { string dateTime = ann.Date.ToShortDateString(); // use a fixed size date to get a approx. date width layout.SetText(new DateTime(1999, 10, 10).ToShortDateString()); layout.GetPixelSize(out dateWidth, out h); layout.SetText(dateTime); e.Window.DrawLayout(Style.BlackGC, Allocation.Width - revisionWidth - margin - revisionWidth - dateRevisionSpacing, (int)(curY + (widget.Editor.LineHeight - h) / 2), layout); } using (var authorLayout = MonoDevelop.Components.PangoUtil.CreateLayout(this)) { var description = Pango.FontDescription.FromString("Tahoma " + (int)(10 * widget.Editor.Options.Zoom)); authorLayout.FontDescription = description; authorLayout.SetText(ann.Author); authorLayout.GetPixelSize(out authorWidth, out h); var maxWidth = Allocation.Width - revisionWidth - margin - revisionWidth - dateRevisionSpacing; /* if (authorWidth > maxWidth) { * int idx = ann.Author.IndexOf ('<'); * if (idx > 0) * authorLayout.SetText (ann.Author.Substring (0, idx) + Environment.NewLine + ann.Author.Substring (idx)); * authorLayout.GetPixelSize (out authorWidth, out h); * }*/ cr.Save(); cr.Rectangle(0, 0, maxWidth, Allocation.Height); cr.Clip(); cr.Translate(leftSpacer + margin, (int)(curY + (widget.Editor.LineHeight - h) / 2)); cr.SetSourceRGB(0, 0, 0); cr.ShowLayout(authorLayout); cr.ResetClip(); cr.Restore(); } curY = nextY; } else { curY += widget.Editor.GetLineHeight(line); line++; widget.JumpOverFoldings(ref line); } if (ann != null && line - lineStart > 1) { string msg = GetCommitMessage(lineStart, false); if (!string.IsNullOrEmpty(msg)) { msg = Revision.FormatMessage(msg); layout.SetText(msg); layout.Width = (int)(Allocation.Width * Pango.Scale.PangoScale); using (var gc = new Gdk.GC(e.Window)) { gc.RgbFgColor = Style.Dark(State); gc.ClipRectangle = new Rectangle(0, (int)curStart, Allocation.Width, (int)(curY - curStart)); e.Window.DrawLayout(gc, (int)(leftSpacer + margin), (int)(curStart + h), layout); } } } cr.Rectangle(0, curStart, leftSpacer, curY - curStart); if (ann != null && !string.IsNullOrEmpty(ann.Author)) { double a; if (ann != null && (maxDate - minDate).TotalHours > 0) { a = 1 - (ann.Date - minDate).TotalHours / (maxDate - minDate).TotalHours; } else { a = 1; } HslColor color = new Cairo.Color(0.90, 0.90, 1); color.L = 0.4 + a / 2; color.S = 1 - a / 2; cr.SetSourceColor(color); } else { cr.SetSourceColor(ann != null ? new Cairo.Color(1, 1, 0) : new Cairo.Color(0.95, 0.95, 0.95)); } cr.Fill(); if (ann != null) { cr.MoveTo(0, curY + 0.5); cr.LineTo(Allocation.Width, curY + 0.5); cr.SetSourceRGB(0.6, 0.6, 0.6); cr.Stroke(); } } } return(true); }
/// <summary> /// Create a cursor icon with a shape that visually represents the tool's thickness. /// </summary> /// <param name="imgName">A string containing the name of the tool's icon image to use.</param> /// <param name="shape">The shape to draw.</param> /// <param name="shapeWidth">The width of the shape.</param> /// <param name="imgToShapeX">The horizontal distance between the image's top-left corner and the shape center.</param> /// <param name="imgToShapeY">The verical distance between the image's top-left corner and the shape center.</param> /// <param name="shapeX">The X position in the returned Pixbuf that will be the center of the shape.</param> /// <param name="shapeY">The Y position in the returned Pixbuf that will be the center of the shape.</param> /// <returns>The new cursor icon with an shape that represents the tool's thickness.</returns> public static Gdk.Pixbuf CreateIconWithShape(string imgName, CursorShape shape, int shapeWidth, int imgToShapeX, int imgToShapeY, out int shapeX, out int shapeY) { Gdk.Pixbuf img = PintaCore.Resources.GetIcon(imgName); double zoom = 1d; if (PintaCore.Workspace.HasOpenDocuments) { zoom = Math.Min(30d, PintaCore.Workspace.ActiveDocument.Workspace.Scale); } shapeWidth = (int)Math.Min(800d, ((double)shapeWidth) * zoom); int halfOfShapeWidth = shapeWidth / 2; // Calculate bounding boxes around the both image and shape // relative to the image top-left corner. Gdk.Rectangle imgBBox = new Gdk.Rectangle(0, 0, img.Width, img.Height); Gdk.Rectangle shapeBBox = new Gdk.Rectangle( imgToShapeX - halfOfShapeWidth, imgToShapeY - halfOfShapeWidth, shapeWidth, shapeWidth); // Inflate shape bounding box to allow for anti-aliasing shapeBBox.Inflate(2, 2); // To determine required size of icon, // find union of the image and shape bounding boxes // (still relative to image top-left corner) Gdk.Rectangle iconBBox = imgBBox.Union(shapeBBox); // Image top-left corner in icon co-ordinates int imgX = imgBBox.Left - iconBBox.Left; int imgY = imgBBox.Top - iconBBox.Top; // Shape center point in icon co-ordinates shapeX = imgToShapeX - iconBBox.Left; shapeY = imgToShapeY - iconBBox.Top; using (var i = CairoExtensions.CreateImageSurface(Cairo.Format.ARGB32, iconBBox.Width, iconBBox.Height)) { using (var g = new Cairo.Context(i)) { // Don't show shape if shapeWidth less than 3, if (shapeWidth > 3) { int diam = Math.Max(1, shapeWidth - 2); Cairo.Rectangle shapeRect = new Cairo.Rectangle(shapeX - halfOfShapeWidth, shapeY - halfOfShapeWidth, diam, diam); Cairo.Color outerColor = new Cairo.Color(255, 255, 255, 0.75); Cairo.Color innerColor = new Cairo.Color(0, 0, 0); switch (shape) { case CursorShape.Ellipse: g.DrawEllipse(shapeRect, outerColor, 2); shapeRect = shapeRect.Inflate(-1, -1); g.DrawEllipse(shapeRect, innerColor, 1); break; case CursorShape.Rectangle: g.DrawRectangle(shapeRect, outerColor, 1); shapeRect = shapeRect.Inflate(-1, -1); g.DrawRectangle(shapeRect, innerColor, 1); break; } } // Draw the image g.DrawPixbuf(img, new Cairo.Point(imgX, imgY)); } return(CairoExtensions.ToPixbuf(i)); } }
static Cairo.Color[,,,,] CreateColorMatrix (TextEditor editor, bool isError) { string typeString = isError ? "error" : "warning"; Cairo.Color[,,,,] colorMatrix = new Cairo.Color[2, 2, 3, 2, 2]; ColorSheme style = editor.ColorStyle; if (style == null) style = new DefaultStyle (editor.Style); var baseColor = style.GetChunkStyle ("bubble." + typeString + "").CairoBackgroundColor; AdjustColorMatrix (colorMatrix, 0, baseColor); var hsl = (HslColor)baseColor; hsl.S *= 0.6; baseColor = hsl; AdjustColorMatrix (colorMatrix, 1, hsl); 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 = ColorSheme.ToCairoColor (style.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); } } } } return colorMatrix; }
public LineBackgroundMarker(Cairo.Color color) { this.color = color; }
internal protected override void OptionsChanged () { CalculateWidth (); lineNumberBgGC = editor.ColorStyle.LineNumber.CairoBackgroundColor; lineNumberGC = editor.ColorStyle.LineNumber.CairoColor; lineNumberHighlightGC = editor.ColorStyle.LineNumberFgHighlighted; }
protected override bool OnExposeEvent(EventExpose evnt) { Style.PaintBox(Style, evnt.Window, StateType.Insensitive, ShadowType.None, Allocation, this, "base", 0, 0, Allocation.Width, Allocation.Height); var expanderBounds = GetExpanderBounds(); using (var cr = CairoHelper.Create(evnt.Window)) { CairoCorners corners = CairoCorners.TopLeft | CairoCorners.TopRight; if (!container.Expanded) { corners = CairoCorners.All; } int r = 10; CairoExtensions.RoundedRectangle(cr, 0, 0, Allocation.Width, Allocation.Height, r, corners); var lg = new Cairo.LinearGradient(0, 0, 0, Allocation.Height); var state = mouseOver ? StateType.Prelight : StateType.Normal; lg.AddColorStop(0, (Mono.TextEditor.HslColor)Style.Mid(state)); lg.AddColorStop(1, (Mono.TextEditor.HslColor)Style.Dark(state)); cr.Pattern = lg; cr.Fill(); if (mouseOver) { CairoExtensions.RoundedRectangle(cr, 0, 0, Allocation.Width, Allocation.Height, r, corners); double rx = mx; double ry = my; Cairo.RadialGradient gradient = new Cairo.RadialGradient(rx, ry, Allocation.Width * 2, rx, ry, 2); gradient.AddColorStop(0, new Cairo.Color(0, 0, 0, 0)); Cairo.Color color = (Mono.TextEditor.HslColor)Style.Light(StateType.Normal); color.A = 0.2; gradient.AddColorStop(1, color); cr.Pattern = gradient; cr.Fill(); } cr.LineWidth = 1; CairoExtensions.RoundedRectangle(cr, 0.5, 0.5, Allocation.Width - 1, Allocation.Height - 1, r, corners); cr.Color = (Mono.TextEditor.HslColor)Style.Dark(StateType.Normal); cr.Stroke(); using (var layout = new Pango.Layout(PangoContext)) { layout.SetMarkup(Label); int w, h; layout.GetPixelSize(out w, out h); const int padding = 4; cr.MoveTo(expanderBounds.Right + padding, (Allocation.Height - h) / 2); cr.Color = new Cairo.Color(0, 0, 0); cr.ShowLayout(layout); } DrawCloseButton(cr); } var state2 = mouseOver && !IsCloseSelected ? StateType.Prelight : StateType.Normal; Style.PaintExpander(Style, evnt.Window, state2, evnt.Region.Clipbox, this, "expander", expanderBounds.X + expanderBounds.Width / 2, expanderBounds.Y + expanderBounds.Width / 2, expanderStyle); return(true); }
/// <summary> /// Draws the text. /// </summary> /// <param name="showCursor">Whether or not to show the mouse cursor in the drawing.</param> /// <param name="useTextLayer">Whether or not to use the TextLayer (as opposed to the Userlayer).</param> private void RedrawText(bool showCursor, bool useTextLayer) { Rectangle r = CurrentTextEngine.GetLayoutBounds(); r.Inflate(10 + OutlineWidth, 10 + OutlineWidth); CurrentTextBounds = r; Rectangle cursorBounds = Rectangle.Zero; Cairo.ImageSurface surf; if (!useTextLayer) { //Draw text on the current UserLayer's surface as finalized text. surf = PintaCore.Workspace.ActiveDocument.CurrentUserLayer.Surface; } else { //Draw text on the current UserLayer's TextLayer's surface as re-editable text. surf = PintaCore.Workspace.ActiveDocument.CurrentUserLayer.TextLayer.Surface; ClearTextLayer(); } using (var g = new Cairo.Context (surf)) { g.Save (); // Show selection if on text layer if (useTextLayer) { // Selected Text Cairo.Color c = new Cairo.Color (0.7, 0.8, 0.9, 0.5); foreach (Rectangle rect in CurrentTextEngine.SelectionRectangles) g.FillRectangle (rect.ToCairoRectangle (), c); } g.AppendPath (PintaCore.Workspace.ActiveDocument.Selection.SelectionPath); g.FillRule = Cairo.FillRule.EvenOdd; g.Clip (); g.MoveTo (new Cairo.PointD (CurrentTextEngine.Origin.X, CurrentTextEngine.Origin.Y)); g.Color = PintaCore.Palette.PrimaryColor; //Fill in background if (BackgroundFill) { using (var g2 = new Cairo.Context (surf)) { g2.FillRectangle(CurrentTextEngine.GetLayoutBounds().ToCairoRectangle(), PintaCore.Palette.SecondaryColor); } } // Draw the text if (FillText) Pango.CairoHelper.ShowLayout (g, CurrentTextEngine.Layout); if (FillText && StrokeText) { g.Color = PintaCore.Palette.SecondaryColor; g.LineWidth = OutlineWidth; Pango.CairoHelper.LayoutPath (g, CurrentTextEngine.Layout); g.Stroke (); } else if (StrokeText) { g.Color = PintaCore.Palette.PrimaryColor; g.LineWidth = OutlineWidth; Pango.CairoHelper.LayoutPath (g, CurrentTextEngine.Layout); g.Stroke (); } if (showCursor) { var loc = CurrentTextEngine.GetCursorLocation (); g.Antialias = Cairo.Antialias.None; g.DrawLine (new Cairo.PointD (loc.X, loc.Y), new Cairo.PointD (loc.X, loc.Y + loc.Height), new Cairo.Color (0, 0, 0, 1), 1); cursorBounds = Rectangle.Inflate (loc, 2, 10); } g.Restore (); if (useTextLayer && (is_editing || ctrlKey) && !CurrentTextEngine.IsEmpty()) { //Draw the text edit rectangle. g.Save(); g.Translate(.5, .5); using (Cairo.Path p = g.CreateRectanglePath(new Cairo.Rectangle(CurrentTextBounds.Left, CurrentTextBounds.Top, CurrentTextBounds.Width, CurrentTextBounds.Height - FontSize))) { g.AppendPath(p); } g.LineWidth = 1; g.Color = new Cairo.Color(1, 1, 1); g.StrokePreserve(); g.SetDash(new double[] { 2, 4 }, 0); g.Color = new Cairo.Color(1, .1, .2); g.Stroke(); g.Restore(); } } InflateAndInvalidate(PintaCore.Workspace.ActiveDocument.CurrentUserLayer.previousTextBounds); PintaCore.Workspace.Invalidate(old_cursor_bounds); PintaCore.Workspace.Invalidate(r); PintaCore.Workspace.Invalidate(cursorBounds); old_cursor_bounds = cursorBounds; }
/// <summary> /// Set the background color. /// </summary> public void SetBackgroundColor(Cairo.Color color) { BackgroundColor = color; }
public TooltipInformationWindow () : base () { TypeHint = Gdk.WindowTypeHint.Tooltip; this.SkipTaskbarHint = true; this.SkipPagerHint = true; if (IdeApp.Workbench != null) this.TransientFor = IdeApp.Workbench.RootWindow; this.AllowShrink = false; this.AllowGrow = false; this.CanFocus = false; this.CanDefault = false; this.Events |= Gdk.EventMask.EnterNotifyMask; headlabel = new FixedWidthWrapLabel (); headlabel.Indent = -20; var des = FontService.GetFontDescription ("Editor").Copy (); des.Size = des.Size * 9 / 10; headlabel.FontDescription = des; // headlabel.MaxWidth = 400; headlabel.Wrap = Pango.WrapMode.WordChar; headlabel.BreakOnCamelCasing = false; headlabel.BreakOnPunctuation = false; descriptionBox.Spacing = 4; VBox vb = new VBox (false, 8); vb.PackStart (headlabel, true, true, 0); vb.PackStart (descriptionBox, true, true, 0); HBox hb = new HBox (false, 0); hb.PackStart (vb, true, true, 0); WindowTransparencyDecorator.Attach (this); vb2.Spacing = 4; vb2.PackStart (hb, true, true, 0); ContentBox.Add (vb2); var scheme = Mono.TextEditor.Highlighting.SyntaxModeService.GetColorStyle (IdeApp.Preferences.ColorScheme); Theme.SetSchemeColors (scheme); foreColor = scheme.PlainText.Foreground; headlabel.ModifyFg (StateType.Normal, (HslColor)foreColor); ShowAll (); DesktopService.RemoveWindowShadow (this); }
public static Gdk.Color ToGdkColor(this Cairo.Color color) { return(new Gdk.Color((byte)(color.R * 255d), (byte)(color.G * 255d), (byte)(color.B * 255d))); }
protected override bool OnExposeEvent(Gdk.EventExpose args) { Gdk.Window win = GdkWindow; int rwidth, rheight; Cairo.Context ctx = CairoHelper.Create (win); win.GetSize (out rwidth, out rheight); if (autoStartY || autoEndY) { double nstartY = double.MaxValue; double nendY = double.MinValue; GetValueRange (AxisDimension.Y, out nstartY, out nendY); if (!autoStartY) nstartY = startY; if (!autoEndY) nendY = endY; if (nendY < nstartY) nendY = nstartY; if (nstartY != startY || nendY != endY) { yrangeChanged = true; startY = nstartY; endY = nendY; } } if (autoStartX || autoEndX) { double nstartX = double.MaxValue; double nendX = double.MinValue; GetValueRange (AxisDimension.X, out nstartX, out nendX); if (!autoStartX) nstartX = startX; if (!autoEndX) nendX = endX; if (nendX < nstartX) nendX = nstartX; if (nstartX != startX || nendX != endX) { xrangeChanged = true; startX = nstartX; endX = nendX; } } if (yrangeChanged) { FixOrigins (); int right = rwidth - 2 - AreaBorderWidth; left = AreaBorderWidth; left += MeasureAxisSize (AxisPosition.Left) + 1; right -= MeasureAxisSize (AxisPosition.Right) + 1; yrangeChanged = false; width = right - left + 1; if (width <= 0) width = 1; } if (xrangeChanged) { FixOrigins (); int bottom = rheight - 2 - AreaBorderWidth; top = AreaBorderWidth; bottom -= MeasureAxisSize (AxisPosition.Bottom); top += MeasureAxisSize (AxisPosition.Top); // Make room for cursor handles foreach (ChartCursor cursor in cursors) { if (cursor.Dimension == AxisDimension.X && top - AreaBorderWidth < cursor.HandleSize) top = cursor.HandleSize + AreaBorderWidth; } xrangeChanged = false; height = bottom - top + 1; if (height <= 0) height = 1; } if (AutoScaleMargin != 0 && height > 0) { double margin = (double)AutoScaleMargin * (endY - startY) / (double) height; if (autoStartY) startY -= margin; if (autoEndY) endY += margin; } // Console.WriteLine ("L:" + left + " T:" + top + " W:" + width + " H:" + height); // Draw the background if (backgroundDisplay == BackgroundDisplay.Gradient) { ctx.Rectangle (left - 1, top - 1, width + 2, height + 2); using (var pat = new Cairo.LinearGradient (left - 1, top - 1, left - 1, height + 2)) { pat.AddColorStop (0, backroundColor); Cairo.Color endc = new Cairo.Color (1,1,1); pat.AddColorStop (1, endc); ctx.SetSource (pat); ctx.Fill (); } } else { ctx.Rectangle (left - 1, top - 1, width + 2, height + 2); ctx.SetSourceColor (backroundColor); ctx.Fill (); } // win.DrawRectangle (Style.WhiteGC, true, left - 1, top - 1, width + 2, height + 2); win.DrawRectangle (Style.BlackGC, false, left - AreaBorderWidth, top - AreaBorderWidth, width + AreaBorderWidth*2, height + AreaBorderWidth*2); // Draw selected area if (enableSelection) { int sx, sy, ex, ey; GetPoint (selectionStart.Value, selectionStart.Value, out sx, out sy); GetPoint (selectionEnd.Value, selectionEnd.Value, out ex, out ey); if (sx > ex) { int tmp = sx; sx = ex; ex = tmp; } Gdk.GC sgc = new Gdk.GC (GdkWindow); sgc.RgbFgColor = new Color (225, 225, 225); win.DrawRectangle (sgc, true, sx, top, ex - sx, height + 1); } // Draw axes Gdk.GC gc = Style.BlackGC; foreach (Axis ax in axis) DrawAxis (win, gc, ax); // Draw values foreach (Serie serie in series) if (serie.Visible) DrawSerie (ctx, serie); // Draw cursors foreach (ChartCursor cursor in cursors) DrawCursor (cursor); // Draw cursor labels foreach (ChartCursor cursor in cursors) if (cursor.ShowValueLabel) DrawCursorLabel (cursor); ((IDisposable)ctx).Dispose (); return true; }
public static Xwt.Drawing.Color ToXwtColor(this Cairo.Color color) { return(new Xwt.Drawing.Color(color.R, color.G, color.B, color.A)); }
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 ()); } }
protected override bool OnExposeEvent(Gdk.EventExpose e) { using (Cairo.Context cr = Gdk.CairoHelper.Create(e.Window)) { cr.LineWidth = Math.Max(1.0, widget.Editor.Options.Zoom); cr.Rectangle(leftSpacer, 0, Allocation.Width, Allocation.Height); cr.Color = new Cairo.Color(0.95, 0.95, 0.95); cr.Fill(); int startLine = widget.Editor.YToLine((int)widget.Editor.VAdjustment.Value); double startY = widget.Editor.LineToY(startLine); while (startLine > 1 && startLine < annotations.Count && annotations[startLine - 1] != null && annotations[startLine] != null && annotations[startLine - 1].Revision == annotations[startLine].Revision) { startLine--; startY -= widget.Editor.GetLineHeight(widget.Editor.Document.GetLine(startLine)); } double curY = startY - widget.Editor.VAdjustment.Value; int line = startLine; while (curY < Allocation.Bottom && line <= widget.Editor.LineCount) { double curStart = curY; // widget.JumpOverFoldings (ref line); int lineStart = line; int w = 0, w2 = 0, h = 16; Annotation ann = line <= annotations.Count ? annotations[line - 1] : null; if (ann != null) { do { widget.JumpOverFoldings(ref line); line++; } while (line <= annotations.Count && annotations[line - 1] != null && annotations[line - 1].Revision == ann.Revision); double nextY = widget.editor.LineToY(line) - widget.editor.VAdjustment.Value; if (highlightAnnotation != null && highlightAnnotation.Revision == ann.Revision && curStart <= highlightPositon && highlightPositon < nextY) { cr.Rectangle(leftSpacer, curStart + cr.LineWidth, Allocation.Width - leftSpacer, nextY - curStart - cr.LineWidth); cr.Color = new Cairo.Color(1, 1, 1); cr.Fill(); } layout.SetText(ann.Author); layout.GetPixelSize(out w, out h); e.Window.DrawLayout(Style.BlackGC, leftSpacer + margin, (int)(curY + (widget.Editor.LineHeight - h) / 2), layout); layout.SetText(TruncRevision(ann.Revision)); layout.GetPixelSize(out w2, out h); e.Window.DrawLayout(Style.BlackGC, Allocation.Width - w2 - margin, (int)(curY + (widget.Editor.LineHeight - h) / 2), layout); if (ann.HasDate) { string dateTime = ann.Date.ToShortDateString(); int middle = w + (Allocation.Width - margin * 2 - leftSpacer - w - w2) / 2; layout.SetText(dateTime); layout.GetPixelSize(out w, out h); e.Window.DrawLayout(Style.BlackGC, leftSpacer + margin + middle - w / 2, (int)(curY + (widget.Editor.LineHeight - h) / 2), layout); } curY = nextY; } else { curY += widget.Editor.GetLineHeight(line); line++; widget.JumpOverFoldings(ref line); } if (ann != null && line - lineStart > 1) { string msg = GetCommitMessage(lineStart); if (!string.IsNullOrEmpty(msg)) { msg = FormatMessage(msg); layout.SetText(msg); layout.Width = (int)(Allocation.Width * Pango.Scale.PangoScale); using (var gc = new Gdk.GC(e.Window)) { gc.RgbFgColor = Style.Dark(State); gc.ClipRectangle = new Rectangle(0, (int)curStart, Allocation.Width, (int)(curY - curStart)); e.Window.DrawLayout(gc, (int)(leftSpacer + margin), (int)(curStart + h), layout); } } } cr.Rectangle(0, curStart, leftSpacer, curY - curStart); if (ann != null && ann != locallyModified && !string.IsNullOrEmpty(ann.Author)) { double a; if (ann != null && (maxDate - minDate).TotalHours > 0) { a = 1 - (ann.Date - minDate).TotalHours / (maxDate - minDate).TotalHours; } else { a = 1; } HslColor color = new Cairo.Color(0.90, 0.90, 1); color.L = 0.4 + a / 2; color.S = 1 - a / 2; cr.Color = color; } else { cr.Color = ann != null ? new Cairo.Color(1, 1, 0) : new Cairo.Color(0.95, 0.95, 0.95); } cr.Fill(); if (ann != null) { cr.MoveTo(0, curY + 0.5); cr.LineTo(Allocation.Width, curY + 0.5); cr.Color = new Cairo.Color(0.6, 0.6, 0.6); cr.Stroke(); } } } return(true); }
public SearchPopupWindow () { headerColor = CairoExtensions.ParseColor ("8c8c8c"); separatorLine = CairoExtensions.ParseColor ("dedede"); lightSearchBackground = CairoExtensions.ParseColor ("ffffff"); darkSearchBackground = CairoExtensions.ParseColor ("f7f7f7"); selectionBackgroundColor = CairoExtensions.ParseColor ("cccccc"); TypeHint = Gdk.WindowTypeHint.Combo; this.SkipTaskbarHint = true; this.SkipPagerHint = true; this.TransientFor = IdeApp.Workbench.RootWindow; this.AllowShrink = false; this.AllowGrow = false; categories.Add (new ProjectSearchCategory (this)); categories.Add (new FileSearchCategory (this)); categories.Add (new CommandSearchCategory (this)); categories.Add (new SearchInSolutionSearchCategory ()); categories.AddRange (AddinManager.GetExtensionObjects<SearchCategory> ("/MonoDevelop/Ide/SearchCategories")); layout = new Pango.Layout (PangoContext); headerLayout = new Pango.Layout (PangoContext); layout.Ellipsize = Pango.EllipsizeMode.End; headerLayout.Ellipsize = Pango.EllipsizeMode.End; Events = Gdk.EventMask.ButtonPressMask | Gdk.EventMask.ButtonMotionMask | Gdk.EventMask.ButtonReleaseMask | Gdk.EventMask.ExposureMask | Gdk.EventMask.PointerMotionMask; ItemActivated += (sender, e) => OpenFile (); /* SizeRequested += delegate(object o, SizeRequestedArgs args) { if (inResize) return; if (args.Requisition.Width != Allocation.Width || args.Requisition.Height != Allocation.Height) { inResize = true; // Visible = false; Resize (args.Requisition.Width, args.Requisition.Height); // Visible = true; if (!Visible) Visible = true; inResize = false; } };*/ }
protected virtual void DrawBar (Cairo.Context cr) { if (vadjustment == null || vadjustment.Upper <= vadjustment.PageSize) return; double x, y, w, h; GetBarDimensions (out x, out y, out w, out h); if (Platform.IsWindows) { cr.Rectangle (x, y, w, h); } else { MonoDevelop.Components.CairoExtensions.RoundedRectangle (cr, x, y, w, h, 4); } bool prelight = State == StateType.Prelight; Cairo.Color c; if (Platform.IsWindows) { c = prelight ? win81SliderPrelight : win81Slider; //compute new color such that it will produce same color when blended with bg c = AddAlpha (win81Background, c, 0.5d); } else { c = new Cairo.Color (0, 0, 0, (prelight ? 50.0 : 22.0) / 255); } cr.SetSourceColor (c); cr.Fill (); }
public void DrawRowCursor(Cairo.Context cr, int x, int y, int width, int height, Cairo.Color color) { DrawRowCursor(cr, x, y, width, height, color, CairoCorners.All); }
public abstract void DrawRowSelection(Cairo.Context cr, int x, int y, int width, int height, bool filled, bool stroked, Cairo.Color color, CairoCorners corners);
void InnerDecorateTabsAndSpaces (Cairo.Context ctx, LayoutWrapper layout, int offset, double x, double y, int selectionStart, int selectionEnd, char spaceOrTab) { var chars = layout.LineChars; if (Array.IndexOf (chars, spaceOrTab) == -1) return; uint curIndex = 0, byteIndex = 0; bool first = true, oldSelected = false; var curchunk = layout.Chunks != null ? layout.Chunks.FirstOrDefault () : null; var dotThickness = textEditor.Options.Zoom * 2; var textEditorWidth = textEditor.Allocation.Width; //Get 1st visible character index from left based on HAdjustment int index, trailing; layout.Layout.XyToIndex ((int)textEditor.HAdjustment.Value, 0, out index, out trailing); double ypos; if (spaceOrTab == ' ') { ypos = System.Math.Floor (y + (LineHeight - dotThickness) / 2); } else { ypos = 0.5 + System.Math.Floor (y + LineHeight / 2); } var showOnlySelected = textEditor.Options.ShowWhitespaces != ShowWhitespaces.Always; var lastColor = new Cairo.Color (); bool firstDraw = true; var foregroundColor = ColorStyle.PlainText.Foreground; int lastIndex = -1; int lastPosX = 0; for (int i = index; i < chars.Length; i++) { if (spaceOrTab != chars [i]) continue; bool selected = selectionStart <= offset + i && offset + i < selectionEnd; if (first || oldSelected != selected) { first = false; oldSelected = selected; } if (showOnlySelected && !selected) continue; int line, posX; if (lastIndex == i) { posX = lastPosX; } else { layout.Layout.IndexToLineX ((int)TranslateToUTF8Index (chars, (uint)i, ref curIndex, ref byteIndex), false, out line, out posX); } double xpos = x + posX / Pango.Scale.PangoScale; if (xpos > textEditorWidth) break; layout.Layout.IndexToLineX ((int)TranslateToUTF8Index (chars, (uint)i + 1, ref curIndex, ref byteIndex), false, out line, out posX); lastPosX = posX; lastIndex = i + 1; double xpos2 = x + posX / Pango.Scale.PangoScale; var col = new Cairo.Color (0, 0, 0); if (SelectionColor.TransparentForeground) { while (curchunk != null && curchunk.EndOffset < offset + i) curchunk = curchunk.Next; if (curchunk != null && curchunk.SpanStack.Count > 0 && curchunk.SpanStack.Peek ().Color != "Plain Text") { var chunkStyle = ColorStyle.GetChunkStyle (curchunk.SpanStack.Peek ().Color); if (chunkStyle != null) col = ColorStyle.GetForeground (chunkStyle); } else { col = foregroundColor; } } else { col = selected ? SelectionColor.Foreground : foregroundColor; } if (firstDraw || (lastColor.R != col.R && lastColor.G != col.G && lastColor.B != col.B)) { ctx.SetSourceRGBA (col.R, col.G, col.B, whitespaceMarkerAlpha); lastColor = col; firstDraw = false; } if (spaceOrTab == ' ') { ctx.Rectangle (xpos + (xpos2 - xpos - dotThickness) / 2, ypos, dotThickness, dotThickness); } else { ctx.MoveTo (0.5 + xpos, ypos); ctx.LineTo (0.5 + xpos2 - charWidth / 2, ypos); } } if (!firstDraw) {//Atleast one draw was called if (spaceOrTab == ' ') { ctx.Fill (); } else { ctx.Stroke (); } } }
public static Color ToEto(this Cairo.Color color) { return(new Color((float)color.R, (float)color.G, (float)color.B, (float)color.A)); }
void DecorateTabsAndSpaces (Cairo.Context ctx, LayoutWrapper layout, int offset, int length, double xPos, double y, int selectionStart, int selectionEnd) { uint curIndex = 0, byteIndex = 0; bool first = true, oldSelected = false; int index, trailing; layout.Layout.XyToIndex ((int)textEditor.HAdjustment.Value, 0, out index, out trailing); var curchunk = layout.Chunks != null ? layout.Chunks.FirstOrDefault () : null; for (int i = index; i < layout.LineChars.Length; i++) { char ch = layout.LineChars [i]; if (ch != ' ' && ch != '\t') continue; if (ch == ' ' && !textEditor.Options.IncludeWhitespaces.HasFlag (IncludeWhitespaces.Space)) continue; if (ch == '\t' && !textEditor.Options.IncludeWhitespaces.HasFlag (IncludeWhitespaces.Tab)) continue; bool selected = selectionStart <= offset + i && offset + i < selectionEnd; if (first || oldSelected != selected) { first = false; oldSelected = selected; } if (!selected && textEditor.Options.ShowWhitespaces != ShowWhitespaces.Always) continue; Pango.Rectangle pos = layout.Layout.IndexToPos ((int)TranslateToUTF8Index (layout.LineChars, (uint)i, ref curIndex, ref byteIndex)); double xpos = xPos + pos.X / Pango.Scale.PangoScale; if (xpos > textEditor.Allocation.Width) break; Pango.Rectangle pos2 = layout.Layout.IndexToPos ((int)TranslateToUTF8Index (layout.LineChars, (uint)i + 1, ref curIndex, ref byteIndex)); double xpos2 = xPos + pos2.X / Pango.Scale.PangoScale; Cairo.Color col = new Cairo.Color (0, 0, 0); if (SelectionColor.TransparentForeground) { while (curchunk != null && curchunk.EndOffset < offset + i) curchunk = curchunk.Next; if (curchunk != null && curchunk.SpanStack.Count > 0 && curchunk.SpanStack.Peek ().Color != "Plain Text") { var chunkStyle = ColorStyle.GetChunkStyle (curchunk.SpanStack.Peek ().Color); if (chunkStyle != null) col = ColorStyle.GetForeground (chunkStyle); } else { col = ColorStyle.PlainText.Foreground; } } else { col = selected ? SelectionColor.Foreground : col = ColorStyle.PlainText.Foreground; } ctx.Color = new Cairo.Color (col.R, col.G, col.B, whitespaceMarkerAlpha); if (ch == '\t') { DrawTabMarker (ctx, selected, xpos, xpos2, y); } else { DrawSpaceMarker (ctx, selected, xpos, xpos2, y); } } }
public Status AddColorStopRgb(double offset, Cairo.Color c) { CairoAPI.cairo_pattern_add_color_stop_rgb(pattern, offset, c.R, c.G, c.B); return(Status); }
protected internal override void Draw (Cairo.Context cr, Cairo.Rectangle area, DocumentLine line, int lineNr, double x, double y, double _lineHeight) { // double xStart = System.Math.Max (area.X, XOffset); // xStart = System.Math.Max (0, xStart); var correctedXOffset = System.Math.Floor (XOffset) - 1; var lineArea = new Cairo.Rectangle (correctedXOffset, y, textEditor.Allocation.Width - correctedXOffset, _lineHeight); int width, height; double pangoPosition = (x - textEditor.HAdjustment.Value + TextStartPosition) * Pango.Scale.PangoScale; defaultBgColor = Document.ReadOnly ? ColorStyle.BackgroundReadOnly.Color : ColorStyle.PlainText.Background; // Draw the default back color for the whole line. Colors other than the default // background will be drawn when rendering the text chunks. if (BackgroundRenderer == null) DrawRectangleWithRuler (cr, x, lineArea, defaultBgColor, true); bool isSelectionDrawn = false; // Check if line is beyond the document length if (line == null) { var marker = Document.GetExtendingTextMarker (lineNr); if (marker != null) marker.Draw (textEditor, cr, lineNr, lineArea); return; } IEnumerable<FoldSegment> foldings = Document.GetStartFoldings (line); int offset = line.Offset; int caretOffset = Caret.Offset; bool isEolFolded = false; restart: int logicalRulerColumn = line.GetLogicalColumn (textEditor.GetTextEditorData (), textEditor.Options.RulerColumn); if ((HighlightCaretLine || textEditor.Options.HighlightCaretLine) && Caret.Line == lineNr) DrawCaretLineMarker (cr, x, y, TextStartPosition, _lineHeight); foreach (FoldSegment folding in foldings) { int foldOffset = folding.StartLine.Offset + folding.Column - 1; if (foldOffset < offset) continue; if (folding.IsFolded) { DrawLinePart (cr, line, lineNr, logicalRulerColumn, offset, foldOffset - offset, ref pangoPosition, ref isSelectionDrawn, y, area.X + area.Width, _lineHeight); offset = folding.EndLine.Offset + folding.EndColumn - 1; markerLayout.SetText (folding.Description); markerLayout.GetSize (out width, out height); bool isFoldingSelected = !this.HideSelection && textEditor.IsSomethingSelected && textEditor.SelectionRange.Contains (folding.Segment); double pixelX = 0.5 + System.Math.Floor (pangoPosition / Pango.Scale.PangoScale); double foldXMargin = foldMarkerXMargin * textEditor.Options.Zoom; double pixelWidth = System.Math.Floor ((pangoPosition + width) / Pango.Scale.PangoScale - pixelX + foldXMargin * 2); var foldingRectangle = new Cairo.Rectangle ( pixelX, y, pixelWidth, this.LineHeight); if (BackgroundRenderer == null && isFoldingSelected) { cr.Color = SelectionColor.Background; cr.Rectangle (foldingRectangle); cr.Fill (); } if (isFoldingSelected && SelectionColor.TransparentForeground) { cr.Color = ColorStyle.CollapsedText.Foreground; } else { cr.Color = isFoldingSelected ? SelectionColor.Foreground : ColorStyle.CollapsedText.Foreground; } var boundingRectangleHeight = foldingRectangle.Height - 1; var boundingRectangleY = System.Math.Floor (foldingRectangle.Y + (foldingRectangle.Height - boundingRectangleHeight) / 2); RoundedRectangle (cr, System.Math.Floor (foldingRectangle.X) + 0.5, boundingRectangleY + 0.5, System.Math.Floor (foldingRectangle.Width - cr.LineWidth), System.Math.Floor (boundingRectangleHeight - cr.LineWidth), LineHeight / 8, CairoCorners.All, false); cr.Stroke (); cr.Save (); cr.Translate ( pangoPosition / Pango.Scale.PangoScale + foldXMargin, System.Math.Floor (boundingRectangleY + (boundingRectangleHeight - System.Math.Floor (height / Pango.Scale.PangoScale)) / 2)); cr.ShowLayout (markerLayout); cr.Restore (); if (caretOffset == foldOffset && !string.IsNullOrEmpty (folding.Description)) { var cx = (int)(pangoPosition / Pango.Scale.PangoScale); SetVisibleCaretPosition (cx, y, cx, y); } pangoPosition += foldingRectangle.Width * Pango.Scale.PangoScale; if (caretOffset == foldOffset + folding.Length && !string.IsNullOrEmpty (folding.Description)) { var cx = (int)(pangoPosition / Pango.Scale.PangoScale); SetVisibleCaretPosition (cx, y, cx, y); } if (folding.EndLine != line) { line = folding.EndLine; lineNr = line.LineNumber; foldings = Document.GetStartFoldings (line); isEolFolded = line.Length <= folding.EndColumn; goto restart; } isEolFolded = line.Length <= folding.EndColumn; } } // Draw remaining line - must be called for empty line parts as well because the caret may be at this positon // and the caret position is calculated in DrawLinePart. if (line.EndOffsetIncludingDelimiter - offset >= 0) { DrawLinePart (cr, line, lineNr, logicalRulerColumn, offset, line.Offset + line.Length - offset, ref pangoPosition, ref isSelectionDrawn, y, area.X + area.Width, _lineHeight); } bool isEolSelected = !this.HideSelection && textEditor.IsSomethingSelected && textEditor.SelectionMode == SelectionMode.Normal && textEditor.SelectionRange.Contains (line.Offset + line.Length); var lx = (int)(pangoPosition / Pango.Scale.PangoScale); lineArea = new Cairo.Rectangle (lx, lineArea.Y, textEditor.Allocation.Width - lx, lineArea.Height); if (textEditor.SelectionMode == SelectionMode.Block && textEditor.IsSomethingSelected && textEditor.SelectionRange.Contains (line.Offset + line.Length)) { DocumentLocation start = textEditor.MainSelection.Anchor; DocumentLocation end = textEditor.MainSelection.Lead; DocumentLocation visStart = textEditor.LogicalToVisualLocation (start); DocumentLocation visEnd = textEditor.LogicalToVisualLocation (end); double x1 = this.ColumnToX (line, visStart.Column); double x2 = this.ColumnToX (line, visEnd.Column); if (x1 > x2) { var tmp = x1; x1 = x2; x2 = tmp; } x1 += correctedXOffset - textEditor.HAdjustment.Value; x2 += correctedXOffset - textEditor.HAdjustment.Value; if (x2 > lineArea.X && BackgroundRenderer == null) { if (x1 - lineArea.X > 0) { DrawRectangleWithRuler (cr, x, new Cairo.Rectangle (lineArea.X, lineArea.Y, x1 - lineArea.X, lineArea.Height), defaultBgColor, false); lineArea = new Cairo.Rectangle (x1, lineArea.Y, lineArea.Width, lineArea.Height); } DrawRectangleWithRuler (cr, x, new Cairo.Rectangle (lineArea.X, lineArea.Y, x2 - lineArea.X, lineArea.Height), this.SelectionColor.Background, false); lineArea = new Cairo.Rectangle (x2, lineArea.Y, textEditor.Allocation.Width - lineArea.X, lineArea.Height); } } if (!isSelectionDrawn && BackgroundRenderer == null) { if (isEolSelected) { // prevent "gaps" in the selection drawing ('fuzzy' lines problem) var eolStartX = System.Math.Floor (pangoPosition / Pango.Scale.PangoScale); lineArea = new Cairo.Rectangle ( eolStartX, lineArea.Y, textEditor.Allocation.Width - eolStartX, lineArea.Height); DrawRectangleWithRuler (cr, x, lineArea, this.SelectionColor.Background, false); if (line.Length == 0) DrawIndent (cr, GetLayout (line), line, lx, y); } else if (!(HighlightCaretLine || textEditor.Options.HighlightCaretLine) || Caret.Line != lineNr) { LayoutWrapper wrapper = GetLayout (line); if (wrapper.EolSpanStack != null) { foreach (var span in wrapper.EolSpanStack) { var spanStyle = textEditor.ColorStyle.GetChunkStyle (span.Color); if (spanStyle == null) continue; if (!spanStyle.TransparentBackground && GetPixel (ColorStyle.PlainText.Background) != GetPixel (spanStyle.Background)) { DrawRectangleWithRuler (cr, x, lineArea, spanStyle.Background, false); break; } } } } else { double xPos = pangoPosition / Pango.Scale.PangoScale; DrawCaretLineMarker (cr, xPos, y, lineArea.X + lineArea.Width - xPos, _lineHeight); } } if (textEditor.Options.ShowWhitespaces != ShowWhitespaces.Never) { if (!isEolFolded && isEolSelected || textEditor.Options.ShowWhitespaces == ShowWhitespaces.Always) if (!(BackgroundRenderer != null && textEditor.Options.ShowWhitespaces == ShowWhitespaces.Selection)) DrawEolMarker (cr, line, isEolSelected, pangoPosition / Pango.Scale.PangoScale, y); } var extendingMarker = Document.GetExtendingTextMarker (lineNr); if (extendingMarker != null) extendingMarker.Draw (textEditor, cr, lineNr, lineArea); if (BackgroundRenderer == null) { var metrics = new EndOfLineMetrics { LineSegment = line, TextRenderEndPosition = TextStartPosition + pangoPosition / Pango.Scale.PangoScale, LineHeight = _lineHeight }; foreach (var marker in line.Markers) { marker.DrawAfterEol (textEditor, cr, y, metrics); } } lastLineRenderWidth = pangoPosition / Pango.Scale.PangoScale; if (textEditor.HAdjustment.Value > 0) { cr.LineWidth = textEditor.Options.Zoom; for (int i = 0; i < verticalShadowAlphaTable.Length; i++) { cr.Color = new Cairo.Color (0, 0, 0, 1 - verticalShadowAlphaTable[i]); cr.MoveTo (x + i * cr.LineWidth + 0.5, y); cr.LineTo (x + i * cr.LineWidth + 0.5, y + 1 + _lineHeight); cr.Stroke (); } } }
/// <summary> /// Draws the rectangle frame into the given cairo context /// </summary> /// <param name="context">Context.</param> /// <param name="lineWidth">Line width.</param> /// <param name="lineColor">Line color.</param> /// <param name="fillColor">Fill color.</param> protected virtual void DrawFrame(Cairo.Context context, double lineWidth, Cairo.Color lineColor, Cairo.Color fillColor) { RectangleD rect = DisplayBox; rect.OffsetDot5(); CairoFigures.CurvedRectangle(context, rect, 8); context.Color = fillColor; context.FillPreserve(); context.Color = lineColor; context.LineWidth = lineWidth; context.Stroke(); }
/// <summary> /// Draws the text. /// </summary> /// <param name="showCursor">Whether or not to show the mouse cursor in the drawing.</param> /// <param name="useTextLayer">Whether or not to use the TextLayer (as opposed to the Userlayer).</param> private void RedrawText(bool showCursor, bool useTextLayer) { Rectangle r = CurrentTextEngine.GetLayoutBounds(); r.Inflate(10 + OutlineWidth, 10 + OutlineWidth); InflateAndInvalidate(r); CurrentTextBounds = r; Rectangle cursorBounds = Rectangle.Zero; Cairo.ImageSurface surf; if (!useTextLayer) { //Draw text on the current UserLayer's surface as finalized text. surf = PintaCore.Workspace.ActiveDocument.CurrentUserLayer.Surface; } else { //Draw text on the current UserLayer's TextLayer's surface as re-editable text. surf = PintaCore.Workspace.ActiveDocument.CurrentUserLayer.TextLayer.Layer.Surface; ClearTextLayer(); } using (var g = new Cairo.Context(surf)) { g.Save(); // Show selection if on text layer if (useTextLayer) { // Selected Text Cairo.Color c = new Cairo.Color(0.7, 0.8, 0.9, 0.5); foreach (Rectangle rect in CurrentTextEngine.SelectionRectangles) { g.FillRectangle(rect.ToCairoRectangle(), c); } } if (selection != null) { g.AppendPath(selection.SelectionPath); g.FillRule = Cairo.FillRule.EvenOdd; g.Clip(); } g.MoveTo(new Cairo.PointD(CurrentTextEngine.Origin.X, CurrentTextEngine.Origin.Y)); g.SetSourceColor(PintaCore.Palette.PrimaryColor); //Fill in background if (BackgroundFill) { using (var g2 = new Cairo.Context(surf)) { g2.FillRectangle(CurrentTextEngine.GetLayoutBounds().ToCairoRectangle(), PintaCore.Palette.SecondaryColor); } } // Draw the text if (FillText) { Pango.CairoHelper.ShowLayout(g, CurrentTextEngine.Layout); } if (FillText && StrokeText) { g.SetSourceColor(PintaCore.Palette.SecondaryColor); g.LineWidth = OutlineWidth; Pango.CairoHelper.LayoutPath(g, CurrentTextEngine.Layout); g.Stroke(); } else if (StrokeText) { g.SetSourceColor(PintaCore.Palette.PrimaryColor); g.LineWidth = OutlineWidth; Pango.CairoHelper.LayoutPath(g, CurrentTextEngine.Layout); g.Stroke(); } if (showCursor) { var loc = CurrentTextEngine.GetCursorLocation(); g.Antialias = Cairo.Antialias.None; g.DrawLine(new Cairo.PointD(loc.X, loc.Y), new Cairo.PointD(loc.X, loc.Y + loc.Height), new Cairo.Color(0, 0, 0, 1), 1); cursorBounds = Rectangle.Inflate(loc, 2, 10); } g.Restore(); if (useTextLayer && (is_editing || ctrlKey) && !CurrentTextEngine.IsEmpty()) { //Draw the text edit rectangle. g.Save(); g.Translate(.5, .5); using (Cairo.Path p = g.CreateRectanglePath(CurrentTextBounds.ToCairoRectangle())) { g.AppendPath(p); } g.LineWidth = 1; g.SetSourceColor(new Cairo.Color(1, 1, 1)); g.StrokePreserve(); g.SetDash(new double[] { 2, 4 }, 0); g.SetSourceColor(new Cairo.Color(1, .1, .2)); g.Stroke(); g.Restore(); } } InflateAndInvalidate(PintaCore.Workspace.ActiveDocument.CurrentUserLayer.previousTextBounds); PintaCore.Workspace.Invalidate(old_cursor_bounds); InflateAndInvalidate(r); PintaCore.Workspace.Invalidate(cursorBounds); old_cursor_bounds = cursorBounds; }
public void Update(Cairo.Color color) { this.color = color; this.QueueDraw(); }
protected override bool OnExposeEvent (Gdk.EventExpose e) { if (TextEditor == null) return true; using (Cairo.Context cr = Gdk.CairoHelper.Create (e.Window)) { cr.LineWidth = 1; cr.Rectangle (0, 0, Allocation.Width, Allocation.Height); if (TextEditor.ColorStyle != null) { if (Platform.IsWindows) { using (var pattern = new Cairo.SolidPattern (win81Background)) { cr.SetSource (pattern); } } else { var col = new Cairo.Color (229 / 255.0, 229 / 255.0, 229 / 255.0); using (var grad = new Cairo.LinearGradient (0, 0, Allocation.Width, 0)) { grad.AddColorStop (0, col); grad.AddColorStop (0.5, new Cairo.Color (1, 1, 1)); grad.AddColorStop (1, col); cr.SetSource (grad); } } } cr.Fill (); if (TextEditor == null) return true; if (TextEditor.HighlightSearchPattern) { DrawSearchResults (cr); DrawSearchIndicator (cr); } else { if (!Debugger.DebuggingService.IsDebugging) { var severity = DrawQuickTasks (cr); DrawIndicator (cr, severity); } } DrawCaret (cr); DrawBar (cr); DrawLeftBorder (cr); } return true; }
void ProcessExpandAnimation(Cairo.Context cr, Category lastCategory, int lastCategoryYpos, Cairo.Color backColor, Gdk.Rectangle area, ref int ypos) { if (lastCategory != null && lastCategory.AnimatingExpand) { int newypos = lastCategory.IsExpanded ? lastCategoryYpos + lastCategory.AnimationHeight : ypos + lastCategory.AnimationHeight; if (newypos < lastCategoryYpos) { newypos = lastCategoryYpos; StopExpandAnimation(lastCategory); } if (newypos > ypos) { newypos = ypos; StopExpandAnimation(lastCategory); } // Clear the area where the category will be drawn since it will be // drawn over the items being hidden/shown cr.SetSourceColor(backColor); cr.Rectangle(area.X, newypos, area.Width, ypos - lastCategoryYpos); cr.Fill(); ypos = newypos; } }