static void draw (Cairo.Context gr, int width, int height) { int w, h; ImageSurface image; gr.Scale (width, height); gr.LineWidth = 0.04; gr.Arc (0.5, 0.5, 0.3, 0, 2*M_PI); gr.Clip (); gr.NewPath (); image = new ImageSurface("data/e.png"); w = image.Width; h = image.Height; gr.Scale (1.0/w, 1.0/h); image.Show (gr, 0, 0); image.Destroy(); gr.Arc (0.5, 0.5, 0.3, 0, 2 * M_PI); gr.Clip (); gr.NewPath (); gr.Rectangle (new PointD (0, 0), 1, 1); gr.Fill (); gr.Color = new Color (0, 1, 0, 1); gr.MoveTo ( new PointD (0, 0) ); gr.LineTo ( new PointD (1, 1) ); gr.MoveTo ( new PointD (1, 0) ); gr.LineTo ( new PointD (0, 1) ); gr.Stroke (); }
public static void DrawRoundRectangle (Cairo.Context cr, double x, double y, double r, double w, double h) { const double ARC_TO_BEZIER = 0.55228475; double radius_x = r; double radius_y = r / 4; if (radius_x > w - radius_x) radius_x = w / 2; if (radius_y > h - radius_y) radius_y = h / 2; double c1 = ARC_TO_BEZIER * radius_x; double c2 = ARC_TO_BEZIER * radius_y; cr.NewPath (); cr.MoveTo (x + radius_x, y); cr.RelLineTo (w - 2 * radius_x, 0.0); cr.RelCurveTo (c1, 0.0, radius_x, c2, radius_x, radius_y); cr.RelLineTo (0, h - 2 * radius_y); cr.RelCurveTo (0.0, c2, c1 - radius_x, radius_y, -radius_x, radius_y); cr.RelLineTo (-w + 2 * radius_x, 0); cr.RelCurveTo (-c1, 0, -radius_x, -c2, -radius_x, -radius_y); cr.RelLineTo (0, -h + 2 * radius_y); cr.RelCurveTo (0.0, -c2, radius_x - c1, -radius_y, radius_x, -radius_y); cr.ClosePath (); }
public static void Fill(Cairo.Context context, Gtk.Widget widget, Cairo.Color color) { context.NewPath(); context.Color = color; context.Rectangle(0, 0, widget.Allocation.Width, widget.Allocation.Height); context.Fill(); }
protected void DrawCircle (Cairo.Context cr, double x, double y, double size) { x += 0.5; y += 0.5; cr.NewPath (); cr.Arc (x + size/2, y + size / 2, (size-4)/2, 0, 2 * Math.PI); cr.ClosePath (); }
public static void Fill(Cairo.Context context, int width, int height, Cairo.Color color) { context.NewPath(); context.Color = color; context.Rectangle(0, 0, width, height); context.Fill(); }
protected void DrawDiamond (Cairo.Context cr, double x, double y, double size) { x += 0.5; y += 0.5; size -= 2; cr.NewPath (); cr.MoveTo (x + size/2, y); cr.LineTo (x + size, y + size/2); cr.LineTo (x + size/2, y + size); cr.LineTo (x, y + size/2); cr.LineTo (x + size/2, y); cr.ClosePath (); }
static void draw (Cairo.Context gr, int width, int height) { gr.Scale (width, height); gr.LineWidth = 0.04; gr.Arc (0.5, 0.5, 0.3, 0, 2 * M_PI); gr.Clip (); gr.NewPath (); gr.Rectangle (new PointD (0, 0), 1, 1); gr.Fill (); gr.Color = new Color (0, 1, 0, 1); gr.MoveTo ( new PointD (0, 0) ); gr.LineTo ( new PointD (1, 1) ); gr.MoveTo ( new PointD (1, 0) ); gr.LineTo ( new PointD (0, 1) ); gr.Stroke (); }
public void Draw (Cairo.Context cr, Cairo.Rectangle rectangle) { if (IsSeparator) { cr.NewPath (); double x = Math.Ceiling (rectangle.X + rectangle.Width / 2) + 0.5; cr.MoveTo (x, rectangle.Y + 0.5 + 2); cr.RelLineTo (0, rectangle.Height - 1 - 4); cr.ClosePath (); cr.SetSourceColor (Styles.SubTabBarSeparatorColor.ToCairoColor ()); cr.LineWidth = 1; cr.Stroke (); return; } if (Active || HoverPosition.X >= 0) { if (Active) { cr.Rectangle (rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); cr.SetSourceColor (Styles.SubTabBarActiveBackgroundColor.ToCairoColor ()); cr.Fill (); } else if (HoverPosition.X >= 0) { cr.Rectangle (rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); cr.SetSourceColor (Styles.SubTabBarHoverBackgroundColor.ToCairoColor ()); cr.Fill (); } } if (Active) { cr.SetSourceColor (Styles.SubTabBarActiveTextColor.ToCairoColor ()); layout.FontDescription = FontService.SansFont.CopyModified (Styles.FontScale11, Pango.Weight.Bold); } else { cr.SetSourceColor (Styles.SubTabBarTextColor.ToCairoColor ()); layout.FontDescription = FontService.SansFont.CopyModified (Styles.FontScale11); } layout.Width = (int)rectangle.Width; cr.MoveTo (rectangle.X + (int)(rectangle.Width / 2), (rectangle.Height - h) / 2 - 1); Pango.CairoHelper.ShowLayout (cr, layout); }
public override void DrawForeground (TextEditor editor, Cairo.Context cr, MarginDrawMetrics metrics) { cr.Arc (metrics.X + metrics.Width / 2 + 2, metrics.Y + metrics.Height / 2, 7 * editor.Options.Zoom, 0, Math.PI * 2); isFailed = false; var test = NUnitService.Instance.SearchTestById (unitTest.UnitTestIdentifier); bool searchCases = false; if (unitTest.IsIgnored) { cr.SetSourceRGB (0.9, 0.9, 0); } else { if (test != null) { var result = test.GetLastResult (); if (result == null) { cr.SetSourceRGB (0.5, 0.5, 0.5); searchCases = true; } else if (result.IsNotRun) { cr.SetSourceRGBA (0.9, 0.9, 0, test.IsHistoricResult ? 0.5 : 1.0); } else if (result.IsSuccess) { cr.SetSourceRGBA (0, 1, 0, test.IsHistoricResult ? 0.2 : 1.0); } else if (result.IsFailure) { cr.SetSourceRGBA (1, 0, 0, test.IsHistoricResult ? 0.2 : 1.0); failMessage = result.Message; isFailed = true; } else if (result.IsInconclusive) { cr.SetSourceRGBA (0, 1, 1, test.IsHistoricResult ? 0.2 : 1.0); } else { cr.SetSourceRGB (0.5, 0.5, 0.5); } } else { cr.SetSourceRGB (0.5, 0.5, 0.5); searchCases = true; } if (searchCases) { foreach (var caseId in unitTest.TestCases) { test = NUnitService.Instance.SearchTestById (unitTest.UnitTestIdentifier + caseId); if (test != null) { var result = test.GetLastResult (); if (result == null || result.IsNotRun || test.IsHistoricResult) { } else if (result.IsNotRun) { cr.SetSourceRGB (0.9, 0.9, 0); } else if (result.IsSuccess) { cr.SetSourceRGB (0, 1, 0); } else if (result.IsFailure) { cr.SetSourceRGB (1, 0, 0); failMessage = result.Message; isFailed = true; break; } else if (result.IsInconclusive) { cr.SetSourceRGB (0, 1, 1); } } } } } cr.FillPreserve (); if (unitTest.IsIgnored) { cr.SetSourceRGB (0.4, 0.4, 0); cr.Stroke (); } else { if (test != null) { var result = test.GetLastResult (); if (result == null) { cr.SetSourceRGB (0.2, 0.2, 0.2); cr.Stroke (); } else if (result.IsNotRun && !test.IsHistoricResult) { cr.SetSourceRGB (0.4, 0.4, 0); cr.Stroke (); } else if (result.IsSuccess && !test.IsHistoricResult) { cr.SetSourceRGB (0, 0.5, 0); cr.Stroke (); } else if (result.IsFailure && !test.IsHistoricResult) { cr.SetSourceRGB (0.5, 0, 0); cr.Stroke (); } else if (result.IsInconclusive && !test.IsHistoricResult) { cr.SetSourceRGB (0, 0.7, 0.7); cr.Stroke (); } } } cr.NewPath (); }
public void Render (Cairo.Context context, StatusArea.RenderArg arg) { context.CachedDraw (surface: ref backgroundSurface, region: arg.Allocation, draw: (c, o) => DrawBackground (c, new Gdk.Rectangle (0, 0, arg.Allocation.Width, arg.Allocation.Height))); if (arg.BuildAnimationOpacity > 0.001f) DrawBuildEffect (context, arg.Allocation, arg.BuildAnimationProgress, arg.BuildAnimationOpacity); if (arg.ErrorAnimationProgress > 0.001 && arg.ErrorAnimationProgress < .999) { DrawErrorAnimation (context, arg); } DrawBorder (context, arg.Allocation); if (arg.HoverProgress > 0.001f) { context.Clip (); int x1 = arg.Allocation.X + arg.MousePosition.X - 200; int x2 = x1 + 400; using (Cairo.LinearGradient gradient = new LinearGradient (x1, 0, x2, 0)) { Cairo.Color targetColor = Styles.StatusBarFill1Color; Cairo.Color transparentColor = targetColor; targetColor.A = .7; transparentColor.A = 0; targetColor.A = .7 * arg.HoverProgress; gradient.AddColorStop (0.0, transparentColor); gradient.AddColorStop (0.5, targetColor); gradient.AddColorStop (1.0, transparentColor); context.Pattern = gradient; context.Rectangle (x1, arg.Allocation.Y, x2 - x1, arg.Allocation.Height); context.Fill (); } context.ResetClip (); } else { context.NewPath (); } int progress_bar_x = arg.ChildAllocation.X; int progress_bar_width = arg.ChildAllocation.Width; if (arg.CurrentPixbuf != null) { int y = arg.Allocation.Y + (arg.Allocation.Height - arg.CurrentPixbuf.Height) / 2; Gdk.CairoHelper.SetSourcePixbuf (context, arg.CurrentPixbuf, arg.ChildAllocation.X, y); context.Paint (); progress_bar_x += arg.CurrentPixbuf.Width + Styles.ProgressBarOuterPadding; progress_bar_width -= arg.CurrentPixbuf.Width + Styles.ProgressBarOuterPadding; } int center = arg.Allocation.Y + arg.Allocation.Height / 2; Gdk.Rectangle progressArea = new Gdk.Rectangle (progress_bar_x, center - Styles.ProgressBarHeight / 2, progress_bar_width, Styles.ProgressBarHeight); if (arg.ShowProgressBar || arg.ProgressBarAlpha > 0) { DrawProgressBar (context, arg.ProgressBarFraction, progressArea, arg); ClipProgressBar (context, progressArea); } int text_x = progress_bar_x + Styles.ProgressBarInnerPadding; int text_width = progress_bar_width - (Styles.ProgressBarInnerPadding * 2); double textTweenValue = arg.TextAnimationProgress; if (arg.LastText != null) { double opacity = Math.Max (0.0f, 1.0f - textTweenValue); DrawString (arg.LastText, arg.LastTextIsMarkup, context, text_x, center - (int)(textTweenValue * arg.Allocation.Height * 0.3), text_width, opacity, arg.Pango, arg); } if (arg.CurrentText != null) { DrawString (arg.CurrentText, arg.CurrentTextIsMarkup, context, text_x, center + (int)((1.0f - textTweenValue) * arg.Allocation.Height * 0.3), text_width, Math.Min (textTweenValue, 1.0), arg.Pango, arg); } if (arg.ShowProgressBar || arg.ProgressBarAlpha > 0) context.ResetClip (); }
protected void paintTrail(Cairo.Context context, int x, int y) { context.Save (); context.SetSourceRGB (0, 1, 0); context.Translate (x, y); context.Rectangle (new Cairo.Rectangle (0, 0, fieldSize, fieldSize)); context.SetSourceRGBA (0, 1, 0, 0.3); context.FillPreserve (); context.NewPath (); context.Restore (); }
void DrawSerie(Cairo.Context ctx, Serie serie) { ctx.NewPath (); ctx.Rectangle (left, top, width + 1, height + 1); ctx.Clip (); ctx.NewPath (); ctx.SetSourceColor (serie.Color); ctx.LineWidth = serie.LineWidth; bool first = true; bool blockMode = serie.DisplayMode == DisplayMode.BlockLine; double lastY = 0; foreach (Data d in serie.GetData (startX, endX)) { double x, y; GetPoint (d.X, d.Y, out x, out y); if (first) { ctx.MoveTo (x, y); lastY = y; first = false; } else { if (blockMode) { if (lastY != y) ctx.LineTo (x, lastY); ctx.LineTo (x, y); } else ctx.LineTo (x, y); } lastY = y; } ctx.Stroke (); }
void DrawExpander (Cairo.Context ctx, double ex, double ey, bool expanded, bool hilight) { ctx.NewPath (); ctx.LineWidth = 1; ctx.Rectangle (ex, ey, ExpanderSize, ExpanderSize); if (hilight) ctx.SetSourceColor (Style.Background (Gtk.StateType.Normal).ToCairoColor ()); else ctx.SetSourceColor (Style.White.ToCairoColor ()); ctx.FillPreserve (); ctx.SetSourceColor (Style.Foreground (Gtk.StateType.Normal).ToCairoColor ()); ctx.Stroke (); ctx.NewPath (); ctx.MoveTo (ex + 2, ey + (ExpanderSize/2)); ctx.RelLineTo (ExpanderSize - 4, 0); if (!expanded) { ctx.MoveTo (ex + (ExpanderSize/2), ey + 2); ctx.RelLineTo (0, ExpanderSize - 4); } ctx.Stroke (); }
protected void paintWanderer(Cairo.Context context, Monster monster) { context.Save (); context.Translate (monster.X + fieldSize / 2, monster.Y + fieldSize / 2); for (int i = 0; i < 12; i++) { context.LineTo ((fieldSize / 2) * Math.Cos (i * Math.PI / 6), (fieldSize / 2) * Math.Sin (i * Math.PI / 6)); context.LineTo ((fieldSize / 3) * Math.Cos (Math.PI / 12 + i * Math.PI / 6), (fieldSize / 3) * Math.Sin (Math.PI / 12 + i * Math.PI / 6)); } context.ClosePath (); context.FillPreserve (); context.NewPath (); context.Restore (); }
protected void paintSniffer(Cairo.Context context, Monster monster) { context.Save (); context.Translate (monster.X, monster.Y); rotateContext (context, monster.Direction); context.Arc (fieldSize / 2, fieldSize / 2, fieldSize / 3, 0, 2 * Math.PI); context.FillPreserve (); context.MoveTo (0, 0); context.LineTo (fieldSize, fieldSize); context.Stroke (); context.NewPath (); context.MoveTo (fieldSize, 0); context.LineTo (0, fieldSize); context.Stroke (); context.NewPath (); context.MoveTo (0, fieldSize / 2); context.LineTo (fieldSize, fieldSize / 2); context.Stroke (); context.NewPath (); context.Restore (); }
protected override bool OnExposed(Cairo.Context cr, Cairo.Rectangle area) { Rectangle rectT = new Rectangle(0.0, 0.0, Allocation.Width, EdgeSize); Rectangle rectB = new Rectangle(0.0, Allocation.Height - EdgeSize, Allocation.Width, EdgeSize); Rectangle rectL = new Rectangle(0.0, 0.0, EdgeSize, Allocation.Height); Rectangle rectR = new Rectangle(Allocation.Width - EdgeSize, 0.0, EdgeSize, Allocation.Height); Rectangle areaT = Widget.Intersect(area, rectT); Rectangle areaB = Widget.Intersect(area, rectB); Rectangle areaL = Widget.Intersect(area, rectL); Rectangle areaR = Widget.Intersect(area, rectR); if(areaT.Width != 0.0 && areaT.Height != 0.0) { LinearGradient grT = new LinearGradient(0.0, 0.0, 0.0, EdgeSize); grT.AddColorStop(0.0, new Color(1.0, 1.0, 1.0, 1.0)); grT.AddColorStop(1.0, new Color(1.0, 1.0, 1.0, 0.0)); cr.Save(); cr.Pattern = grT; //cr.Rectangle(areaT); cr.NewPath(); cr.MoveTo(0.0, 0.0); cr.LineTo(Allocation.Width, 0.0); cr.LineTo(Allocation.Width - EdgeSize, EdgeSize); cr.LineTo(EdgeSize, EdgeSize); cr.ClosePath(); cr.Clip(); cr.Paint(); cr.Restore(); } if(areaB.Width != 0.0 && areaB.Height != 0.0) { LinearGradient grB = new LinearGradient(0.0, Allocation.Height, 0.0, Allocation.Height - EdgeSize); grB.AddColorStop(0.0, new Color(0.0, 0.0, 0.0, 1.0)); grB.AddColorStop(1.0, new Color(0.0, 0.0, 0.0, 0.0)); cr.Save(); cr.Pattern = grB; //cr.Rectangle(areaB); cr.MoveTo(0.0, Allocation.Height); cr.LineTo(Allocation.Width, Allocation.Height); cr.LineTo(Allocation.Width - EdgeSize, Allocation.Height - EdgeSize); cr.LineTo(EdgeSize, Allocation.Height - EdgeSize); cr.ClosePath(); cr.Clip(); cr.Paint(); cr.Restore(); } if(areaL.Width != 0.0 && areaL.Height != 0.0) { LinearGradient grL = new LinearGradient(0.0, 0.0, EdgeSize, 0.0); grL.AddColorStop(0.0, new Color(1.0, 1.0, 1.0, 1.0)); grL.AddColorStop(1.0, new Color(1.0, 1.0, 1.0, 0.0)); cr.Save(); cr.Pattern = grL; //cr.Rectangle(areaL); cr.MoveTo(0.0, 0.0); cr.LineTo(0.0, Allocation.Height); cr.LineTo(EdgeSize, Allocation.Height - EdgeSize); cr.LineTo(EdgeSize, EdgeSize); cr.ClosePath(); cr.Clip(); cr.Paint(); cr.Restore(); } if(areaR.Width != 0.0 && areaR.Height != 0.0) { LinearGradient grR = new LinearGradient(Allocation.Width, 0.0, Allocation.Width - EdgeSize, 0.0); grR.AddColorStop(0.0, new Color(0.0, 0.0, 0.0, 1.0)); grR.AddColorStop(1.0, new Color(0.0, 0.0, 0.0, 0.0)); cr.Save(); cr.Pattern = grR; //cr.Rectangle(areaR); cr.MoveTo(Allocation.Width, 0.0); cr.LineTo(Allocation.Width, Allocation.Height); cr.LineTo(Allocation.Width - EdgeSize, Allocation.Height - EdgeSize); cr.LineTo(Allocation.Width - EdgeSize, EdgeSize); cr.ClosePath(); cr.Clip(); cr.Paint(); cr.Restore(); } return true; }
void DrawButtonTabs (Cairo.Context cr, Cairo.Rectangle rectangle) { if (IsSeparator) { cr.NewPath (); double x = Math.Ceiling (rectangle.X + rectangle.Width / 2) + 0.5; cr.MoveTo (x, rectangle.Y + 0.5 + 2); cr.RelLineTo (0, rectangle.Height - 1 - 4); cr.ClosePath (); cr.Color = (HslColor)parent.Style.Dark (StateType.Normal); cr.LineWidth = 1; cr.Stroke (); return; } int topPadding = 2; if (Active || HoverPosition.X >= 0) { cr.Rectangle (rectangle.X + 1, rectangle.Y + 1 + topPadding, rectangle.Width - 1, rectangle.Height - topPadding); if (Active) { cr.Color = (HslColor)parent.Style.Background (StateType.Prelight); } else if (HoverPosition.X >= 0) { double rx = rectangle.X + HoverPosition.X; double ry = rectangle.Y + HoverPosition.Y; Cairo.RadialGradient gradient = new Cairo.RadialGradient (rx, ry, rectangle.Height * 1.5, rx, ry, 2); var color = (HslColor)parent.Style.Dark (StateType.Normal); color.L *= 1.1; gradient.AddColorStop (0, color); color.L *= 1.1; gradient.AddColorStop (1, color); cr.Pattern = gradient; } cr.Fill (); if (Active) { cr.Rectangle (rectangle.X + 0.5, rectangle.Y + 0.5 + topPadding, rectangle.Width - 1, rectangle.Height - topPadding); cr.Color = (HslColor)parent.Style.Dark (StateType.Normal); cr.LineWidth = 1; cr.Stroke (); } } cr.Save (); cr.Translate (rectangle.X + (rectangle.Width - w) / 2, (rectangle.Height - h) / 2 + topPadding); cr.Color = (HslColor)parent.Style.Text (StateType.Normal); cr.ShowLayout (layout); cr.Restore (); }
protected override void OnDrawn (Cairo.Context cr, Gdk.Rectangle rect) { if (BackgroundColor.HasValue) { cr.Rectangle (rect.X, rect.Y, rect.Width, rect.Height); cr.SetSourceColor (BackgroundColor.Value.ToCairoColor ()); cr.Fill (); } if (GradientBackround) { Color gcol = Style.Background (Gtk.StateType.Normal).ToXwtValue (); 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 (); using (var pat = new Cairo.LinearGradient (rect.X, rect.Y, rect.X, rect.Bottom)) { Cairo.Color color1 = gcol.ToCairoColor (); pat.AddColorStop (0, color1); gcol.Light -= 0.1; pat.AddColorStop (1, gcol.ToCairoColor ()); cr.SetSource (pat); cr.FillPreserve (); } } cr.SetSourceColor (color.HasValue ? color.Value.ToCairoColor () : Style.Dark (Gtk.StateType.Normal).ToXwtValue ().ToCairoColor ()); cr.Rectangle (rect.X, rect.Y, rect.Width, topMargin); cr.Rectangle (rect.X, rect.Y + rect.Height - bottomMargin, rect.Width, bottomMargin); cr.Rectangle (rect.X, rect.Y, leftMargin, rect.Height); cr.Rectangle (rect.X + rect.Width - rightMargin, rect.Y, rightMargin, rect.Height); cr.Fill (); }
public new void Draw (Cairo.Context cr) { Gdk.Rectangle rect; if (GradientBackround) { rect = new Gdk.Rectangle (Allocation.X, Allocation.Y, Allocation.Width, Allocation.Height); HslColor gcol = useCustomColor ? customColor : Parent.Style.Background (Gtk.StateType.Normal); 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 (); using (Cairo.Gradient pat = new Cairo.LinearGradient (rect.X, rect.Y, rect.X, rect.Y + rect.Height - 1)) { 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 (); } } base.Draw (cr); //FIXME: Get this drawing properly again! // Gdk.Color colour = Parent.Style.Dark (Gtk.StateType.Normal); // cr.SetSourceRGB (colour.Red, colour.Green, colour.Blue); // // rect = Allocation; // for (int n=0; n<topMargin; n++) // GdkWindow.DrawLine (borderColor, rect.X, rect.Y + n, rect.Left + rect.Width - 1, rect.Y + n); // // for (int n=0; n<bottomMargin; n++) // GdkWindow.DrawLine (borderColor, rect.X, rect.Top + rect.Height - 1 - n, rect.Left + rect.Width - 1, rect.Top + rect.Height - 1 - n); // // for (int n=0; n<leftMargin; n++) // GdkWindow.DrawLine (borderColor, rect.X + n, rect.Y, rect.X + n, rect.Top + rect.Height - 1); // // for (int n=0; n<rightMargin; n++) // GdkWindow.DrawLine (borderColor, rect.Left + rect.Width - 1 - n, rect.Y, rect.Left + rect.Width - 1 - n, rect.Top + rect.Height - 1); }
protected void paintArrow(Cairo.Context context, Direction direction, int x, int y) { context.Save (); context.Translate (x, y); rotateContext (context, direction); context.MoveTo (fieldSize / 2, 0); context.LineTo (fieldSize, fieldSize); context.LineTo (fieldSize / 2, 3 * fieldSize / 4); context.LineTo (0, fieldSize); context.LineTo (fieldSize / 2, 0); context.FillPreserve (); context.NewPath (); context.Restore (); }
void DrawTab (Cairo.Context ctx, DockNotebookTab tab, Gdk.Rectangle allocation, Gdk.Rectangle tabBounds, bool highlight, bool active, bool dragging, Pango.Layout la) { // This logic is stupid to have here, should be in the caller! if (dragging) { tabBounds.X = (int) (tabBounds.X + (dragX - tabBounds.X) * dragXProgress); tabBounds.X = Clamp (tabBounds.X, tabStartX, tabEndX - tabBounds.Width); } int padding = LeftRightPadding; padding = (int) (padding * Math.Min (1.0, Math.Max (0.5, (tabBounds.Width - 30) / 70.0))); ctx.LineWidth = 1; LayoutTabBorder (ctx, allocation, tabBounds.Width, tabBounds.X, 0, active); ctx.ClosePath (); using (LinearGradient gr = new LinearGradient (tabBounds.X, TopBarPadding, tabBounds.X, allocation.Bottom)) { if (active) { gr.AddColorStop (0, Styles.BreadcrumbGradientStartColor.MultiplyAlpha (tab.Opacity)); gr.AddColorStop (1, Styles.BreadcrumbBackgroundColor.MultiplyAlpha (tab.Opacity)); } else { gr.AddColorStop (0, CairoExtensions.ParseColor ("f4f4f4").MultiplyAlpha (tab.Opacity)); gr.AddColorStop (1, CairoExtensions.ParseColor ("cecece").MultiplyAlpha (tab.Opacity)); } ctx.SetSource (gr); } ctx.Fill (); ctx.SetSourceColor (new Cairo.Color (1, 1, 1, .5).MultiplyAlpha (tab.Opacity)); LayoutTabBorder (ctx, allocation, tabBounds.Width, tabBounds.X, 1, active); ctx.Stroke (); ctx.SetSourceColor (Styles.BreadcrumbBorderColor.MultiplyAlpha (tab.Opacity)); LayoutTabBorder (ctx, allocation, tabBounds.Width, tabBounds.X, 0, active); ctx.StrokePreserve (); if (tab.GlowStrength > 0) { Gdk.Point mouse = tracker.MousePosition; using (var rg = new RadialGradient (mouse.X, tabBounds.Bottom, 0, mouse.X, tabBounds.Bottom, 100)) { rg.AddColorStop (0, new Cairo.Color (1, 1, 1, 0.4 * tab.Opacity * tab.GlowStrength)); rg.AddColorStop (1, new Cairo.Color (1, 1, 1, 0)); ctx.SetSource (rg); ctx.Fill (); } } else { ctx.NewPath (); } // Render Close Button (do this first so we can tell how much text to render) var ch = allocation.Height - TopBarPadding - BottomBarPadding + CloseImageTopOffset; var crect = new Gdk.Rectangle (tabBounds.Right - padding - CloseButtonSize + 3, tabBounds.Y + TopBarPadding + (ch - CloseButtonSize) / 2, CloseButtonSize, CloseButtonSize); tab.CloseButtonAllocation = crect; tab.CloseButtonAllocation.Inflate (2, 2); bool closeButtonHovered = tracker.Hovered && tab.CloseButtonAllocation.Contains (tracker.MousePosition) && tab.WidthModifier >= 1.0f; bool drawCloseButton = tabBounds.Width > 60 || highlight || closeButtonHovered; if (drawCloseButton) { DrawCloseButton (ctx, new Gdk.Point (crect.X + crect.Width / 2, crect.Y + crect.Height / 2), closeButtonHovered, tab.Opacity, tab.DirtyStrength); } // Render Text int w = tabBounds.Width - (padding * 2 + CloseButtonSize); if (!drawCloseButton) w += CloseButtonSize; int textStart = tabBounds.X + padding; ctx.MoveTo (textStart, tabBounds.Y + TopPadding + TextOffset + VerticalTextSize); if (!MonoDevelop.Core.Platform.IsMac && !MonoDevelop.Core.Platform.IsWindows) { // This is a work around for a linux specific problem. // A bug in the proprietary ATI driver caused TAB text not to draw. // If that bug get's fixed remove this HACK asap. la.Ellipsize = Pango.EllipsizeMode.End; la.Width = (int)(w * Pango.Scale.PangoScale); ctx.SetSourceColor (tab.Notify ? new Cairo.Color (0, 0, 1) : Styles.TabBarActiveTextColor); Pango.CairoHelper.ShowLayoutLine (ctx, la.GetLine (0)); } else { // ellipses are for space wasting ..., we cant afford that using (var lg = new LinearGradient (textStart + w - 5, 0, textStart + w + 3, 0)) { var color = tab.Notify ? new Cairo.Color (0, 0, 1) : Styles.TabBarActiveTextColor; color = color.MultiplyAlpha (tab.Opacity); lg.AddColorStop (0, color); color.A = 0; lg.AddColorStop (1, color); ctx.SetSource (lg); Pango.CairoHelper.ShowLayoutLine (ctx, la.GetLine (0)); } } la.Dispose (); }
void DrawShadow(Cairo.Context ctx, Gdk.Rectangle ar, PositionType pos, List<Section> secs) { foreach (Section s in secs) { Cairo.Gradient pat = null; Gdk.Rectangle r = ar; switch (pos) { case PositionType.Top: r.Height = shadowSize > r.Height ? r.Height / 2 : shadowSize; r.X += s.Offset; r.Width = s.Size; pat = new Cairo.LinearGradient (r.X, r.Y, r.X, r.Bottom); break; case PositionType.Bottom: r.Y = r.Bottom - shadowSize; r.Height = shadowSize > r.Height ? r.Height / 2 : shadowSize; r.X = r.X + s.Offset; r.Width = s.Size; pat = new Cairo.LinearGradient (r.X, r.Bottom, r.X, r.Y); break; case PositionType.Left: r.Width = shadowSize > r.Width ? r.Width / 2 : shadowSize; r.Y += s.Offset; r.Height = s.Size; pat = new Cairo.LinearGradient (r.X, r.Y, r.Right, r.Y); break; case PositionType.Right: r.X = r.Right - shadowSize; r.Width = shadowSize > r.Width ? r.Width / 2 : shadowSize; r.Y += s.Offset; r.Height = s.Size; pat = new Cairo.LinearGradient (r.Right, r.Y, r.X, r.Y); break; } Cairo.Color c = darkColor.ToCairoColor (); pat.AddColorStop (0, c); c.A = 0; pat.AddColorStop (1, c); ctx.NewPath (); ctx.Rectangle (r.X, r.Y, r.Width, r.Height); ctx.Pattern = pat; ctx.Fill (); pat.Destroy (); } }
public void Draw (Cairo.Context cr, Cairo.Rectangle rectangle) { if (IsSeparator) { cr.NewPath (); double x = Math.Ceiling (rectangle.X + rectangle.Width / 2) + 0.5; cr.MoveTo (x, rectangle.Y + 0.5 + 2); cr.RelLineTo (0, rectangle.Height - 1 - 4); cr.ClosePath (); cr.Color = (HslColor)parent.Style.Dark (StateType.Normal); cr.LineWidth = 1; cr.Stroke (); return; } if (Active || HoverPosition.X >= 0) { if (Active) { cr.Rectangle (rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); using (var gr = new LinearGradient (rectangle.X, rectangle.Y, rectangle.X, rectangle.Y + rectangle.Height)) { gr.AddColorStop (0, Tabstrip.ActiveGradientStart); gr.AddColorStop (1, Tabstrip.ActiveGradientEnd); cr.Pattern = gr; } cr.Fill (); cr.Rectangle (rectangle.X + 0.5, rectangle.Y + 0.5, rectangle.Width - 1, rectangle.Height - 1); cr.Color = new Cairo.Color (1, 1, 1, 0.05); cr.LineWidth = 1; cr.Stroke (); } else if (HoverPosition.X >= 0) { cr.Rectangle (rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); using (var gr = new LinearGradient (rectangle.X, rectangle.Y, rectangle.X, rectangle.Y + rectangle.Height)) { var c1 = Tabstrip.ActiveGradientStart; var c2 = Tabstrip.ActiveGradientEnd; c1.A = 0.2; c2.A = 0.2; gr.AddColorStop (0, c1); gr.AddColorStop (1, c2); cr.Pattern = gr; } cr.Fill (); } } if (Active) cr.Color = new Cairo.Color (1, 1, 1); else cr.Color = parent.Style.Text (StateType.Normal).ToCairoColor (); cr.MoveTo (rectangle.X + (rectangle.Width - w) / 2, (rectangle.Height - h) / 2); Pango.CairoHelper.ShowLayout (cr, layout); }
CanvasElement GetInputElementAt (Cairo.Context context, CanvasElement root, double x, double y) { if (root.InputTransparent) return null; var children = root.Children; if (children != null) { // Manual loop to avoid excessive creation of iterators for (int i = children.Count - 1; i >= 0; i--) { var result = GetInputElementAt (context, children[i], x, y); if (result != null) return result; } } context.Save (); root.LayoutOutline (context); var point = TransformPoint (root, x, y); if (context.InFill (point.X, point.Y)) { context.NewPath (); context.Restore (); return root; } context.NewPath (); context.Restore (); return null; }
void DrawValue (Cairo.Context ctx, Gdk.GC gc, DateTime initialTime, int ytop, int lx, int tx, ref int ty, ref int maxx, ref int maxy, int indent, CounterValueInfo val) { Gdk.Color color; if (val.Counter != null) color = val.Counter.GetColor (); else color = Style.Black; // Draw text gc.RgbFgColor = color; double ms = (val.Time - initialTime).TotalMilliseconds; string txt = (ms / 1000).ToString ("0.00000") + ": " + (val.Duration.TotalMilliseconds / 1000).ToString ("0.00000") + " " + val.Trace; layout.SetText (txt); GdkWindow.DrawLayout (gc, tx + indent, ty, layout); int tw, th; layout.GetPixelSize (out tw, out th); if (tx + tw + indent > maxx) maxx = tx + tw + indent; HotSpot hp = AddHotSpot (tx + indent, ty, tw, th); int tempTy = ty; hp.Action = delegate { int ytm = ytop + (int) ((ms * scale) / 1000); SetBaseTime ((int) (tempTy + (th / 2) + 0.5) - ytm); }; hp.OnMouseOver += delegate { overValue = val; QueueDraw (); }; hp.Action += delegate { focusedValue = val; QueueDraw (); }; // Draw time marker int ytime = ytop + (int) ((ms * scale) / 1000) + baseTime; if (val == focusedValue || val == overValue) { ctx.NewPath (); double dx = val == focusedValue ? 0 : 2; ctx.Rectangle (lx + 0.5 + dx - SelectedValuePadding, ytime + 0.5, LineEndWidth - dx*2 + SelectedValuePadding, ((val.Duration.TotalMilliseconds * scale) / 1000)); Mono.TextEditor.HslColor hsl = color; hsl.L = val == focusedValue ? 0.9 : 0.8; ctx.SetSourceColor (hsl); ctx.Fill (); } ctx.NewPath (); ctx.LineWidth = 1; ctx.MoveTo (lx + 0.5, ytime + 0.5); ctx.LineTo (lx + LineEndWidth + 0.5, ytime + 0.5); ctx.LineTo (tx - 3 - LineEndWidth + 0.5, ty + (th / 2) + 0.5); ctx.LineTo (tx + indent - 3 + 0.5, ty + (th / 2) + 0.5); ctx.SetSourceColor (color.ToCairoColor ()); ctx.Stroke (); // Expander bool incLine = true; if (val.CanExpand) { double ex = tx + indent - 3 - ExpanderSize - 2 + 0.5; double ey = ty + (th / 2) - (ExpanderSize/2) + 0.5; hp = AddHotSpot (ex, ey, ExpanderSize, ExpanderSize); DrawExpander (ctx, ex, ey, val.Expanded, false); hp.OnMouseOver = delegate { using (Cairo.Context c = CairoHelper.Create (GdkWindow)) { DrawExpander (c, ex, ey, val.Expanded, true); } }; hp.OnMouseLeave = delegate { using (Cairo.Context c = CairoHelper.Create (GdkWindow)) { DrawExpander (c, ex, ey, val.Expanded, false); } }; hp.Action = delegate { ToggleExpand (val); }; if (val.Expanded && val.ExpandedTimerTraces.Count > 0) { ty += th + LineSpacing; foreach (CounterValueInfo cv in val.ExpandedTimerTraces) DrawValue (ctx, gc, initialTime, ytop, lx, tx, ref ty, ref maxx, ref maxy, indent + ChildIndent, cv); incLine = false; } } if (incLine) ty += th + LineSpacing; if (ytime > maxy) maxy = ytime; }
void DrawGradient (Cairo.Context cr, Gdk.Rectangle rect, int fx, int fy, int fw, int fh, Cairo.Color c1, Cairo.Color c2) { 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.LinearGradient pat = new Cairo.LinearGradient (rect.X + rect.Width*fx, rect.Y + rect.Height*fy, rect.X + rect.Width*fw, rect.Y + rect.Height*fh); pat.AddColorStop (0, c1); pat.AddColorStop (1, c2); cr.Pattern = pat; cr.FillPreserve (); }
protected void DrawArrow (Cairo.Context cr, double x, double y, double size) { y += 2.5; x += 2.5; size -= 4; double awidth = 0.5; double aheight = 0.4; double pich = (size - (size * aheight)) / 2; cr.NewPath (); cr.MoveTo (x + size * awidth, y); cr.LineTo (x + size, y + size / 2); cr.LineTo (x + size * awidth, y + size); cr.RelLineTo (0, -pich); cr.RelLineTo (-size * awidth, 0); cr.RelLineTo (0, -size * aheight); cr.RelLineTo (size * awidth, 0); cr.RelLineTo (0, -pich); cr.ClosePath (); }
public static void DrawRoundRectangle (Cairo.Context cr, bool topLeftRound, bool topRightRound, bool bottomLeftRound, bool bottomRightRound, double x, double y, double r, double w, double h) { // UA****BQ // H C // * * // G D // TF****ES cr.NewPath (); if (topLeftRound) { cr.MoveTo (x + r, y); // Move to A } else { cr.MoveTo (x, y); // Move to U } if (topRightRound) { cr.LineTo (x + w - r, y); // Straight line to B cr.CurveTo (x + w, y, x + w, y, x + w, y + r); // Curve to C, Control points are both at Q } else { cr.LineTo (x + w, y); // Straight line to Q } if (bottomRightRound) { cr.LineTo (x + w, y + h - r); // Move to D cr.CurveTo (x + w, y + h, x + w, y + h, x + w - r, y + h); // Curve to E } else { cr.LineTo (x + w, y + h); // Move to S } if (bottomLeftRound) { cr.LineTo (x + r, y + h); // Line to F cr.CurveTo (x, y + h, x, y + h , x, y + h - r); // Curve to G } else { cr.LineTo (x, y + h); // Line to T } if (topLeftRound) { cr.LineTo (x, y + r); // Line to H cr.CurveTo (x, y, x , y, x + r, y); // Curve to A } else { cr.LineTo (x, y); // Line to U } cr.ClosePath (); }
private void DrawShape (Cairo.Context g, int width, int height) { int inner_x = radius + border + inner; int cx = Center.X; int cy = Center.Y; g.Operator = Operator.Source; g.Source = new SolidPattern (new Cairo.Color (0,0,0,0)); g.Rectangle (0, 0, width, height); g.Paint (); g.NewPath (); g.Translate (cx, cy); g.Rotate (angle); g.Source = new SolidPattern (new Cairo.Color (0.2, 0.2, 0.2, .6)); g.Operator = Operator.Over; g.Rectangle (0, - (border + inner), inner_x, 2 * (border + inner)); g.Arc (inner_x, 0, inner + border, 0, 2 * Math.PI); g.Arc (0, 0, radius + border, 0, 2 * Math.PI); g.Fill (); g.Source = new SolidPattern (new Cairo.Color (0, 0, 0, 1.0)); g.Operator = Operator.DestOut; g.Arc (inner_x, 0, inner, 0, 2 * Math.PI); #if true g.Fill (); #else g.FillPreserve (); g.Operator = Operator.Over; RadialGradient rg = new RadialGradient (inner_x - (inner * 0.3), inner * 0.3 , inner * 0.1, inner_x, 0, inner); rg.AddColorStop (0, new Cairo.Color (0.0, 0.2, .8, 0.5)); rg.AddColorStop (0.7, new Cairo.Color (0.0, 0.2, .8, 0.1)); rg.AddColorStop (1.0, new Cairo.Color (0.0, 0.0, 0.0, 0.0)); g.Source = rg; g.Fill (); rg.Destroy (); #endif g.Operator = Operator.Over; g.Matrix = new Matrix (); g.Translate (cx, cy); if (source != null) SetSourcePixbuf (g, source, -source.Width / 2, -source.Height / 2); g.Arc (0, 0, radius, 0, 2 * Math.PI); g.Fill (); if (overlay != null) { SetSourcePixbuf (g, overlay, -overlay.Width / 2, -overlay.Height / 2); g.Arc (0, 0, radius, angle, angle + Math.PI); g.ClosePath (); g.FillPreserve (); g.Source = new SolidPattern (new Cairo.Color (1.0, 1.0, 1.0, 1.0)); g.Stroke (); } }
protected void paintSquare(Cairo.Context context, int x, int y, bool fill) { context.Save (); context.SetSourceRGB (0, 0, 1); context.Translate (x, y); context.Rectangle (new Cairo.Rectangle (0, 0, fieldSize, fieldSize)); context.SetSourceRGBA (0, 0, 0, fill ? 0.5 : 0.3); context.FillPreserve (); context.NewPath (); context.Restore (); }