本文整理汇总了C#中Cairo.Context.Transform方法的典型用法代码示例。如果您正苦于以下问题:C# Context.Transform方法的具体用法?C# Context.Transform怎么用?C# Context.Transform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cairo.Context
的用法示例。
在下文中一共展示了Context.Transform方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateImageBrush
public static SurfacePattern CreateImageBrush(ImageBrush brush, Size targetSize)
{
if (brush.Source == null)
{
return null;
}
// TODO: This is directly ported from Direct2D and could probably be made more
// efficient on cairo by taking advantage of the fact that cairo has Extend.None.
var image = ((BitmapImpl)brush.Source.PlatformImpl).Surface;
var imageSize = new Size(brush.Source.PixelWidth, brush.Source.PixelHeight);
var tileMode = brush.TileMode;
var sourceRect = brush.SourceRect.ToPixels(imageSize);
var destinationRect = brush.DestinationRect.ToPixels(targetSize);
var scale = brush.Stretch.CalculateScaling(destinationRect.Size, sourceRect.Size);
var translate = CalculateTranslate(brush, sourceRect, destinationRect, scale);
var intermediateSize = CalculateIntermediateSize(tileMode, targetSize, destinationRect.Size);
var intermediate = new ImageSurface (Format.ARGB32, (int)intermediateSize.Width, (int)intermediateSize.Height);
using (var context = new Context(intermediate))
{
Rect drawRect;
var transform = CalculateIntermediateTransform(
tileMode,
sourceRect,
destinationRect,
scale,
translate,
out drawRect);
context.Rectangle(drawRect.ToCairo());
context.Clip();
context.Transform(transform.ToCairo());
Gdk.CairoHelper.SetSourcePixbuf(context, image, 0, 0);
context.Rectangle(0, 0, imageSize.Width, imageSize.Height);
context.Fill();
var result = new SurfacePattern(intermediate);
if ((brush.TileMode & TileMode.FlipXY) != 0)
{
// TODO: Currently always FlipXY as that's all cairo supports natively.
// Support separate FlipX and FlipY by drawing flipped images to intermediate
// surface.
result.Extend = Extend.Reflect;
}
else
{
result.Extend = Extend.Repeat;
}
if (brush.TileMode != TileMode.None)
{
var matrix = result.Matrix;
matrix.InitTranslate(-destinationRect.X, -destinationRect.Y);
result.Matrix = matrix;
}
return result;
}
}
示例2: CreateVisualBrush
public static SurfacePattern CreateVisualBrush(VisualBrush brush, Size targetSize)
{
var visual = brush.Visual;
if (visual == null)
{
return null;
}
var layoutable = visual as ILayoutable;
if (layoutable?.IsArrangeValid == false)
{
layoutable.Measure(Size.Infinity);
layoutable.Arrange(new Rect(layoutable.DesiredSize));
}
// TODO: This is directly ported from Direct2D and could probably be made more
// efficient on cairo by taking advantage of the fact that cairo has Extend.None.
var tileMode = brush.TileMode;
var sourceRect = brush.SourceRect.ToPixels(layoutable.Bounds.Size);
var destinationRect = brush.DestinationRect.ToPixels(targetSize);
var scale = brush.Stretch.CalculateScaling(destinationRect.Size, sourceRect.Size);
var translate = CalculateTranslate(brush, sourceRect, destinationRect, scale);
var intermediateSize = CalculateIntermediateSize(tileMode, targetSize, destinationRect.Size);
using (var intermediate = new ImageSurface(Format.ARGB32, (int)intermediateSize.Width, (int)intermediateSize.Height))
using (var context = new Context(intermediate))
{
Rect drawRect;
var transform = CalculateIntermediateTransform(
tileMode,
sourceRect,
destinationRect,
scale,
translate,
out drawRect);
var renderer = new Renderer(intermediate);
context.Rectangle(drawRect.ToCairo());
context.Clip();
context.Transform(transform.ToCairo());
renderer.Render(visual, new PlatformHandle(IntPtr.Zero, "RTB"), transform, drawRect);
var result = new SurfacePattern(intermediate);
if ((brush.TileMode & TileMode.FlipXY) != 0)
{
// TODO: Currently always FlipXY as that's all cairo supports natively.
// Support separate FlipX and FlipY by drawing flipped images to intermediate
// surface.
result.Extend = Extend.Reflect;
}
else
{
result.Extend = Extend.Repeat;
}
if (brush.TileMode != TileMode.None)
{
var matrix = result.Matrix;
matrix.InitTranslate(-destinationRect.X, -destinationRect.Y);
result.Matrix = matrix;
}
return result;
}
}
示例3: DrawWithOperator
public void DrawWithOperator(Context ctx, ImageSurface surface, Operator op, double opacity = 1.0, bool transform = true)
{
ctx.Save ();
if (transform)
ctx.Transform (Transform);
ctx.Operator = op;
ctx.SetSourceSurface (surface, 0, 0);
if (opacity >= 1.0)
ctx.Paint ();
else
ctx.PaintWithAlpha (opacity);
ctx.Restore ();
}
示例4: CreateScene
private Surface CreateScene (Cairo.Context window_cr, ImageSurface image, int reflect)
{
Surface surface = window_cr.Target.CreateSimilar (window_cr.Target.Content,
image.Width, image.Height + reflect);
Cairo.Context cr = new Context (surface);
cr.Save ();
cr.SetSource (image);
cr.Paint ();
cr.Rectangle (0, image.Height, image.Width, reflect);
cr.Clip ();
Matrix matrix = new Matrix ();
matrix.InitScale (1, -1);
matrix.Translate (0, -(2 * image.Height) + 1);
cr.Transform (matrix);
cr.SetSource (image);
cr.Paint ();
cr.Restore ();
Color bg_transparent = BackgroundColor;
bg_transparent.A = 0.65;
LinearGradient mask = new LinearGradient (0, image.Height, 0, image.Height + reflect);
mask.AddColorStop (0, bg_transparent);
mask.AddColorStop (1, BackgroundColor);
cr.Rectangle (0, image.Height, image.Width, reflect);
cr.Pattern = mask;
cr.Fill ();
((IDisposable)cr).Dispose ();
return surface;
}
示例5: Draw
public void Draw(Context ctx, ImageSurface surface, double opacity, bool transform = true)
{
ctx.Save ();
if (transform)
ctx.Transform (Transform);
ctx.BlendSurface (surface, BlendMode, opacity);
ctx.Restore ();
}
示例6: ApplyTransform
public virtual void ApplyTransform(Matrix xform, Size new_size)
{
var old_size = PintaCore.Workspace.ImageSize;
var dest = new ImageSurface (Format.ARGB32, new_size.Width, new_size.Height);
using (var g = new Context (dest))
{
g.Transform (xform);
g.SetSource (Surface);
g.Paint ();
}
Surface old = Surface;
Surface = dest;
old.Dispose ();
}
示例7: CreateScene
private Surface CreateScene(Cairo.Context window_cr, ImageSurface image, int reflect)
{
var target = window_cr.GetTarget ();
Surface surface = target.CreateSimilar (target.Content,
image.Width, image.Height + reflect);
using (var cr = new Context (surface)) {
cr.Save ();
cr.SetSource (image);
cr.Paint ();
cr.Rectangle (0, image.Height, image.Width, reflect);
cr.Clip ();
Matrix matrix = new Matrix ();
matrix.InitScale (1, -1);
matrix.Translate (0, -(2 * image.Height) + 1);
cr.Transform (matrix);
cr.SetSource (image);
cr.Paint ();
cr.Restore ();
Color bg_transparent = BackgroundColor;
bg_transparent.A = 0.65;
using (var mask = new LinearGradient (0, image.Height, 0, image.Height + reflect)) {
mask.AddColorStop (0, bg_transparent);
mask.AddColorStop (1, BackgroundColor);
cr.Rectangle (0, image.Height, image.Width, reflect);
cr.SetSource (mask);
cr.Fill ();
}
}
return surface;
}
示例8: RenderNode
void RenderNode(Node current, Context context)
{
if (current.Renderer == null)
AssignRenderers (current);
var cairoRenderer = current.Renderer as ICairoRenderer;
if (cairoRenderer == null)
return;
context.Save ();
context.Transform (current.GetTransform ());
cairoRenderer.Render (current, context);
context.Save ();
if (cairoRenderer.Clip)
cairoRenderer.ClipChildren (current, context);
if (current.Children != null)
current.Children.ForEach (n => RenderNode (n, context));
context.Restore ();
if (cairoRenderer.Post)
cairoRenderer.PostRender (current, context);
context.Restore ();
}
示例9: Draw
public void Draw(Context ctx, ImageSurface surface, double opacity)
{
ctx.Save();
ctx.Transform(Transform);
ctx.SetSourceSurface(surface, 0, 0);
ctx.PaintWithAlpha(opacity);
ctx.Restore();
}