本文整理汇总了C#中Cairo.SetSource方法的典型用法代码示例。如果您正苦于以下问题:C# Cairo.SetSource方法的具体用法?C# Cairo.SetSource怎么用?C# Cairo.SetSource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cairo
的用法示例。
在下文中一共展示了Cairo.SetSource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawIcon
static void DrawIcon (MonoTextEditor editor, Cairo.Context cr, DocumentLine lineSegment, double x, double y, double width, double height)
{
if (lineSegment.IsBookmarked) {
var color1 = editor.ColorStyle.Bookmarks.Color;
var color2 = editor.ColorStyle.Bookmarks.SecondColor;
DrawRoundRectangle (cr, x + 1, y + 1, 8, width - 4, height - 4);
// FIXME: VV: Remove gradient features
using (var pat = new Cairo.LinearGradient (x + width / 4, y, x + width / 2, y + height - 4)) {
pat.AddColorStop (0, color1);
pat.AddColorStop (1, color2);
cr.SetSource (pat);
cr.FillPreserve ();
}
// FIXME: VV: Remove gradient features
using (var pat = new Cairo.LinearGradient (x, y + height, x + width, y)) {
pat.AddColorStop (0, color2);
//pat.AddColorStop (1, color1);
cr.SetSource (pat);
cr.Stroke ();
}
}
}
示例2: DrawFrameBackground
public override void DrawFrameBackground(Cairo.Context cr, Gdk.Rectangle alloc, Cairo.Color color, Cairo.Pattern pattern)
{
color.A = Context.FillAlpha;
if (pattern != null) {
cr.SetSource (pattern);
} else {
cr.SetSourceColor (color);
}
CairoExtensions.RoundedRectangle (cr, alloc.X, alloc.Y, alloc.Width, alloc.Height, Context.Radius, CairoCorners.All);
cr.Fill ();
}
示例3: DrawFace
static void DrawFace(Cairo.PointD center, double radius, Cairo.Context e)
{
e.Arc(center.X, center.Y, radius, 0, 360);
Cairo.Gradient pat = new Cairo.LinearGradient(100, 200, 200, 100);
pat.AddColorStop(0, Eto.Drawing.Color.FromArgb(240, 240, 230, 75).ToCairo());
pat.AddColorStop(1, Eto.Drawing.Color.FromArgb(0, 0, 0, 50).ToCairo());
e.LineWidth = 0.1;
e.SetSource(pat);
e.FillPreserve();
e.Stroke();
}
示例4: DrawColumnHighlight
public void DrawColumnHighlight(Cairo.Context cr, Gdk.Rectangle alloc, Cairo.Color color)
{
Cairo.Color light_color = CairoExtensions.ColorShade (color, 1.6);
Cairo.Color dark_color = CairoExtensions.ColorShade (color, 1.3);
LinearGradient grad = new LinearGradient (alloc.X, alloc.Y, alloc.X, alloc.Bottom - 1);
grad.AddColorStop (0, light_color);
grad.AddColorStop (1, dark_color);
cr.SetSource (grad);
cr.Rectangle (alloc.X + 1.5, alloc.Y + 1.5, alloc.Width - 3, alloc.Height - 2);
cr.Fill ();
grad.Dispose ();
}
示例5: Gradient
public static void Gradient(Cairo.Context cr, Theme theme, Rect rect, double opacity)
{
cr.Save ();
cr.Translate (rect.X, rect.Y);
var x = rect.Width / 2.0;
var y = rect.Height / 2.0;
using (var grad = new Cairo.RadialGradient (x, y, 0, x, y, rect.Width / 2.0)) {
grad.AddColorStop (0, new Cairo.Color (0, 0, 0, 0.1 * opacity));
grad.AddColorStop (1, new Cairo.Color (0, 0, 0, 0.35 * opacity));
cr.SetSource (grad);
CairoExtensions.RoundedRectangle (cr, rect.X, rect.Y, rect.Width, rect.Height, theme.Context.Radius);
cr.Fill ();
}
cr.Restore ();
}
示例6: DrawBackground
void DrawBackground(Cairo.Context context, Gdk.Rectangle region, int radius, StateType state)
{
double rad = radius - 0.5;
int centerX = region.X + region.Width / 2;
int centerY = region.Y + region.Height / 2;
context.MoveTo (centerX + rad, centerY);
context.Arc (centerX, centerY, rad, 0, Math.PI * 2);
double high;
double low;
switch (state) {
case StateType.Selected:
high = 0.85;
low = 1.0;
break;
case StateType.Prelight:
high = 1.0;
low = 0.9;
break;
case StateType.Insensitive:
high = 0.95;
low = 0.83;
break;
default:
high = 1.0;
low = 0.85;
break;
}
using (var lg = new LinearGradient (0, centerY - rad, 0, centerY +rad)) {
lg.AddColorStop (0, new Cairo.Color (high, high, high));
lg.AddColorStop (1, new Cairo.Color (low, low, low));
context.SetSource (lg);
context.FillPreserve ();
}
context.SetSourceRGBA (0, 0, 0, 0.4);
context.LineWidth = 1;
context.Stroke ();
}
示例7: DrawSurfaceAt
protected void DrawSurfaceAt(Cairo.Context gr, ImageSurface surface, double x, double y)
{
gr.Save();
gr.SetSource(surface, this._x + x, this._y + y);
gr.Paint();
gr.Restore();
}
示例8: DrawCloseButton
void DrawCloseButton (Cairo.Context context, Gdk.Point center, bool hovered, double opacity, double animationProgress)
{
if (hovered) {
double radius = 6;
context.Arc (center.X, center.Y, radius, 0, Math.PI * 2);
context.SetSourceRGBA (.6, .6, .6, opacity);
context.Fill ();
context.SetSourceRGBA (0.95, 0.95, 0.95, opacity);
context.LineWidth = 2;
context.MoveTo (center.X - 3, center.Y - 3);
context.LineTo (center.X + 3, center.Y + 3);
context.MoveTo (center.X - 3, center.Y + 3);
context.LineTo (center.X + 3, center.Y - 3);
context.Stroke ();
} else {
double lineColor = .63 - .1 * animationProgress;
double fillColor = .74;
double heightMod = Math.Max (0, 1.0 - animationProgress * 2);
context.MoveTo (center.X - 3, center.Y - 3 * heightMod);
context.LineTo (center.X + 3, center.Y + 3 * heightMod);
context.MoveTo (center.X - 3, center.Y + 3 * heightMod);
context.LineTo (center.X + 3, center.Y - 3 * heightMod);
context.LineWidth = 2;
context.SetSourceRGBA (lineColor, lineColor, lineColor, opacity);
context.Stroke ();
if (animationProgress > 0.5) {
double partialProg = (animationProgress - 0.5) * 2;
context.MoveTo (center.X - 3, center.Y);
context.LineTo (center.X + 3, center.Y);
context.LineWidth = 2 - partialProg;
context.SetSourceRGBA (lineColor, lineColor, lineColor, opacity);
context.Stroke ();
double radius = partialProg * 3.5;
// Background
context.Arc (center.X, center.Y, radius, 0, Math.PI * 2);
context.SetSourceRGBA (fillColor, fillColor, fillColor, opacity);
context.Fill ();
// Inset shadow
using (var lg = new Cairo.LinearGradient (0, center.Y - 5, 0, center.Y)) {
context.Arc (center.X, center.Y + 1, radius, 0, Math.PI * 2);
lg.AddColorStop (0, new Cairo.Color (0, 0, 0, 0.2 * opacity));
lg.AddColorStop (1, new Cairo.Color (0, 0, 0, 0));
context.SetSource (lg);
context.Stroke ();
}
// Outline
context.Arc (center.X, center.Y, radius, 0, Math.PI * 2);
context.SetSourceRGBA (lineColor, lineColor, lineColor, opacity);
context.Stroke ();
}
}
}
示例9: DrawTab
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 ();
}
示例10: DrawFrameBorder
public override void DrawFrameBorder(Cairo.Context cr, Gdk.Rectangle alloc)
{
cr.LineWidth = BorderWidth;
border_color.A = 0.3;
cr.SetSourceColor (border_color);
double offset = (double)BorderWidth / 2.0;
double w = Math.Max (0, alloc.Width * 0.75);
double x = alloc.X + (alloc.Width - w) * 0.5 + offset;
double y = alloc.Y + alloc.Height + offset;
LinearGradient g = new LinearGradient (x, y, x + w, y);
Color transparent = border_color;
transparent.A = 0.0;
g.AddColorStop (0, transparent);
g.AddColorStop (0.4, border_color);
g.AddColorStop (0.6, border_color);
g.AddColorStop (1, transparent);
cr.SetSource (g);
cr.MoveTo (x, y);
cr.LineTo (x + w, y);
cr.Stroke ();
g.Dispose ();
}
示例11: SetMCUSurface
/// <summary>
/// Draws the Boards picture.
/// </summary>
/// <param name="context">Context.</param>
/// <param name="path">Path.</param>
/// <param name="maxWidth">Max width.</param>
public static void SetMCUSurface(Cairo.Context context, string path, int maxWidth = int.MaxValue)
{
try {
var surf = GetImage (path);
MCUImageXZero = ShiftX - surf.Width / 2;
MCUImageYZero = ShiftY - surf.Height / 2;
context.SetSource (
surf,
MCUImageXZero,
MCUImageYZero
);
context.Paint ();
surf.Dispose ();
} catch (Exception ex) {
Console.Error.WriteLine (ex);
}
}
示例12: ClippedRender
protected override void ClippedRender(Cairo.Context cr)
{
LinearGradient grad = new LinearGradient (0, 0, RenderSize.Width, RenderSize.Height);
grad.AddColorStop (0, new Color (0.5, 0.5, 0.5));
grad.AddColorStop (1, new Color (0, 0, 0));
cr.SetSource (grad);
cr.Rectangle (0, 0, RenderSize.Width, RenderSize.Height);
cr.Fill ();
grad.Dispose ();
base.ClippedRender (cr);
}
示例13: RenderThumbnail
public static void RenderThumbnail (Cairo.Context cr, ImageSurface image, bool dispose,
double x, double y, double width, double height, double radius,
bool fill, Cairo.Color fillColor, CairoCorners corners, double scale)
{
if (image == null || image.Handle == IntPtr.Zero) {
image = null;
}
double p_x = x;
double p_y = y;
if (image != null) {
double scaled_image_width = scale * image.Width;
double scaled_image_height = scale * image.Height;
p_x += (scaled_image_width < width ? (width - scaled_image_width) / 2 : 0) / scale;
p_y += (scaled_image_height < height ? (height - scaled_image_height) / 2 : 0) / scale;
}
cr.Antialias = Cairo.Antialias.Default;
if (image != null) {
if (fill) {
CairoExtensions.RoundedRectangle (cr, x, y, width, height, radius, corners);
cr.Color = fillColor;
cr.Fill ();
}
cr.Scale (scale, scale);
CairoExtensions.RoundedRectangle (cr, p_x, p_y, image.Width, image.Height, radius, corners);
cr.SetSource (image, p_x, p_y);
cr.Fill ();
cr.Scale (1.0/scale, 1.0/scale);
} else {
CairoExtensions.RoundedRectangle (cr, x, y, width, height, radius, corners);
if (fill) {
var grad = new LinearGradient (x, y, x, y + height);
grad.AddColorStop (0, fillColor);
grad.AddColorStop (1, CairoExtensions.ColorShade (fillColor, 1.3));
cr.Pattern = grad;
cr.Fill ();
grad.Destroy ();
}
}
cr.Stroke ();
if (dispose && image != null) {
((IDisposable)image).Dispose ();
}
}
示例14: DrawBackground
public override bool DrawBackground (TextEditor editor, Cairo.Context cr, double y, LineMetrics metrics)
{
if (metrics.SelectionStart >= 0 || editor.CurrentMode is TextLinkEditMode || editor.TextViewMargin.SearchResultMatchCount > 0)
return false;
foreach (var usage in Usages) {
int markerStart = usage.TextSegment.Offset;
int markerEnd = usage.TextSegment.EndOffset;
if (markerEnd < metrics.TextStartOffset || markerStart > metrics.TextEndOffset)
return false;
double @from;
double to;
if (markerStart < metrics.TextStartOffset && metrics.TextEndOffset < markerEnd) {
@from = metrics.TextRenderStartPosition;
to = metrics.TextRenderEndPosition;
} else {
int start = metrics.TextStartOffset < markerStart ? markerStart : metrics.TextStartOffset;
int end = metrics.TextEndOffset < markerEnd ? metrics.TextEndOffset : markerEnd;
uint curIndex = 0, byteIndex = 0;
TextViewMargin.TranslateToUTF8Index (metrics.Layout.LineChars, (uint)(start - metrics.TextStartOffset), ref curIndex, ref byteIndex);
int x_pos = metrics.Layout.Layout.IndexToPos ((int)byteIndex).X;
@from = metrics.TextRenderStartPosition + (int)(x_pos / Pango.Scale.PangoScale);
TextViewMargin.TranslateToUTF8Index (metrics.Layout.LineChars, (uint)(end - metrics.TextStartOffset), ref curIndex, ref byteIndex);
x_pos = metrics.Layout.Layout.IndexToPos ((int)byteIndex).X;
to = metrics.TextRenderStartPosition + (int)(x_pos / Pango.Scale.PangoScale);
}
@from = System.Math.Max (@from, editor.TextViewMargin.XOffset);
to = System.Math.Max (to, editor.TextViewMargin.XOffset);
if (@from < to) {
Mono.TextEditor.Highlighting.AmbientColor colorStyle;
if ((usage.UsageType & ReferenceUsageType.Write) == ReferenceUsageType.Write) {
colorStyle = editor.ColorStyle.ChangingUsagesRectangle;
} else {
colorStyle = editor.ColorStyle.UsagesRectangle;
}
using (var lg = new LinearGradient (@from + 1, y + 1, to , y + editor.LineHeight)) {
lg.AddColorStop (0, colorStyle.Color);
lg.AddColorStop (1, colorStyle.SecondColor);
cr.SetSource (lg);
cr.RoundedRectangle (@from + 0.5, y + 1.5, to - @from - 1, editor.LineHeight - 2, editor.LineHeight / 4);
cr.FillPreserve ();
}
cr.SetSourceColor (colorStyle.BorderColor);
cr.Stroke ();
}
}
return true;
}
示例15: DrawBackground
void DrawBackground (Cairo.Context cr, Gdk.Rectangle allocation)
{
cr.LineWidth = 1;
cr.Rectangle (0, 0, allocation.Width, allocation.Height);
if (TextEditor.ColorStyle != null) {
if (MonoDevelop.Core.Platform.IsWindows) {
using (var pattern = new Cairo.SolidPattern (win81Background)) {
cr.SetSource (pattern);
cr.Fill ();
}
} else {
var col = TextEditor.ColorStyle.PlainText.Background.ToXwtColor ();
col.Light *= 0.948;
using (var grad = new Cairo.LinearGradient (0, 0, allocation.Width, 0)) {
grad.AddColorStop (0, col.ToCairoColor ());
grad.AddColorStop (0.7, TextEditor.ColorStyle.PlainText.Background);
grad.AddColorStop (1, col.ToCairoColor ());
cr.SetSource (grad);
cr.Fill ();
}
}
}
DrawLeftBorder (cr);
}