本文整理汇总了C#中Cairo.Context.Restore方法的典型用法代码示例。如果您正苦于以下问题:C# Cairo.Context.Restore方法的具体用法?C# Cairo.Context.Restore怎么用?C# Cairo.Context.Restore使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cairo.Context
的用法示例。
在下文中一共展示了Cairo.Context.Restore方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleApply
// Called from asynchronously from Renderer.OnCompletion ()
void HandleApply ()
{
Debug.WriteLine ("LivePreviewManager.HandleApply()");
using (var ctx = new Cairo.Context (layer.Surface)) {
ctx.Save ();
PintaCore.Workspace.ActiveDocument.Selection.Clip (ctx);
ctx.Operator = Cairo.Operator.Source;
layer.Draw(ctx, live_preview_surface, 1);
ctx.Restore ();
}
PintaCore.History.PushNewItem (history_item);
history_item = null;
FireLivePreviewEndedEvent(RenderStatus.Completed, null);
live_preview_enabled = false;
PintaCore.Workspace.Invalidate (); //TODO keep track of dirty bounds.
CleanUp ();
}
示例2: HandleApply
// Called from asynchronously from Renderer.OnCompletion ()
void HandleApply ()
{
Debug.WriteLine ("LivePreviewManager.HandleApply()");
var item = new SimpleHistoryItem (effect.Icon, effect.Name);
item.TakeSnapshotOfLayer (PintaCore.Layers.CurrentLayerIndex);
using (var ctx = new Cairo.Context (layer.Surface)) {
ctx.Save ();
ctx.AppendPath (PintaCore.Workspace.ActiveDocument.Selection.SelectionPath);
ctx.FillRule = Cairo.FillRule.EvenOdd;
ctx.Clip ();
ctx.Operator = Cairo.Operator.Source;
ctx.SetSourceSurface (live_preview_surface, (int)layer.Offset.X, (int)layer.Offset.Y);
ctx.Paint ();
ctx.Restore ();
}
PintaCore.History.PushNewItem (item);
FireLivePreviewEndedEvent(RenderStatus.Completed, null);
live_preview_enabled = false;
PintaCore.Workspace.Invalidate (); //TODO keep track of dirty bounds.
CleanUp ();
}
示例3: RedrawText
/// <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();
//.........这里部分代码省略.........
示例4: BuildImage
public Gdk.Pixbuf BuildImage(FontService fontService)
{
Cairo.ImageSurface image = new Cairo.ImageSurface (Cairo.Format.ARGB32, WIDTH, HEIGHT);
Cairo.Context ctx = new Cairo.Context (image);
Pango.Layout layout = Pango.CairoHelper.CreateLayout (ctx);
fontService.AssignLayout (layout);
// fill background
ctx.Save ();
ctx.Color = new Cairo.Color (0.0, 0.0, 0.0, 1.0);
ctx.Paint ();
ctx.Restore ();
int charCode = 0;
int maxHeight = 0;
Cairo.Point pos = new Cairo.Point (PADDING, PADDING);
while ((!fontService.OnlyEnglish && charCode < 224) ||
(fontService.OnlyEnglish && charCode < (224 - 66))) {
layout.SetText (alphabet[charCode].ToString());
Pango.Rectangle te = GetTextExtents (layout, pos);
// next line
if (pos.X + te.Width + fontService.Spacing + PADDING > image.Width) {
pos.X = PADDING;
pos.Y = te.Y + maxHeight + PADDING;
}
te = DrawText (ctx, layout, pos);
boxes[charCode] = te;
pos.X = te.X + te.Width + fontService.Spacing + PADDING;
maxHeight = Math.Max (maxHeight, te.Height);
charCode++;
}
int cropHeight = NextP2 (boxes[charCode - 1].Y + boxes[charCode - 1].Height - 1);
Gdk.Pixbuf pixbuf = new Gdk.Pixbuf (
image.Data, true, 8,
image.Width,
cropHeight,
image.Stride);
// manual dispose
(image as IDisposable).Dispose ();
(layout as IDisposable).Dispose ();
(ctx.Target as IDisposable).Dispose ();
(ctx as IDisposable).Dispose ();
return pixbuf;
}
示例5: RedrawText
private void RedrawText(bool showCursor, bool useToolLayer)
{
Cairo.ImageSurface surf;
var invalidate_cursor = old_cursor_bounds;
if (!useToolLayer)
surf = PintaCore.Workspace.ActiveDocument.CurrentLayer.Surface;
else {
surf = PintaCore.Workspace.ActiveDocument.ToolLayer.Surface;
surf.Clear ();
}
using (var g = new Cairo.Context (surf)) {
g.Save ();
// Show selection if on tool layer
if (useToolLayer) {
// Selected Text
Cairo.Color c = new Cairo.Color (0.7, 0.8, 0.9, 0.5);
foreach (Rectangle rect in engine.SelectionRectangles)
g.FillRectangle (rect.ToCairoRectangle (), c);
}
g.AppendPath (PintaCore.Workspace.ActiveDocument.SelectionPath);
g.FillRule = Cairo.FillRule.EvenOdd;
g.Clip ();
g.MoveTo (new Cairo.PointD (engine.Origin.X, engine.Origin.Y));
g.Color = PintaCore.Palette.PrimaryColor;
if (BackgroundFill) {
using (var g2 = new Cairo.Context (surf)) {
g2.FillRectangle (engine.GetLayoutBounds ().ToCairoRectangle (),PintaCore.Palette.SecondaryColor);
}
}
if (FillText) {
Pango.CairoHelper.ShowLayout (g, engine.Layout);
}
if (FillText && StrokeText) {
g.Color = PintaCore.Palette.SecondaryColor;
g.LineWidth = OutlineWidth;
Pango.CairoHelper.LayoutPath (g, engine.Layout);
g.Stroke ();
} else if (StrokeText) {
g.Color = PintaCore.Palette.PrimaryColor;
g.LineWidth = OutlineWidth;
Pango.CairoHelper.LayoutPath (g, engine.Layout);
g.Stroke ();
}
if (showCursor) {
var loc = engine.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);
loc.Inflate (2, 10);
old_cursor_bounds = loc;
}
g.Restore ();
}
Rectangle r = engine.GetLayoutBounds ();
r.Inflate (10 + OutlineWidth, 10 + OutlineWidth);
PintaCore.Workspace.Invalidate (old_bounds);
PintaCore.Workspace.Invalidate (invalidate_cursor);
PintaCore.Workspace.Invalidate (r);
old_bounds = r;
}
示例6: Render
public void Render (List<Layer> layers, Cairo.ImageSurface dst, Gdk.Point offset)
{
dst.Flush ();
// Our rectangle of interest
var r = new Gdk.Rectangle (offset, dst.GetBounds ().Size).ToCairoRectangle ();
using (var g = new Cairo.Context (dst)) {
// Create the transparent checkerboard background
g.Translate (-offset.X, -offset.Y);
g.FillRectangle (r, tranparent_pattern, new Cairo.PointD (offset.X, offset.Y));
for (var i = 0; i < layers.Count; i++) {
var layer = layers[i];
// If we're in LivePreview, substitute current layer with the preview layer
if (layer == PintaCore.Layers.CurrentLayer && PintaCore.LivePreview.IsEnabled)
layer = CreateLivePreviewLayer (layer);
// If the layer is offset, handle it here
if (!layer.Transform.IsIdentity ())
layer = CreateOffsetLayer (layer);
// No need to resize the surface if we're at 100% zoom
if (scale_factor.Ratio == 1)
layer.Draw (g, layer.Surface, layer.Opacity, false);
else {
using (var scaled = new Cairo.ImageSurface (Cairo.Format.Argb32, dst.Width, dst.Height)) {
g.Save ();
// Have to undo the translate set above
g.Translate (offset.X, offset.Y);
CopyScaled (layer.Surface, scaled, r.ToGdkRectangle ());
layer.Draw (g, scaled, layer.Opacity, false);
g.Restore ();
}
}
}
}
// If we are at least 200% and grid is requested, draw it
if (enable_pixel_grid && PintaCore.Actions.View.PixelGrid.Active && scale_factor.Ratio <= 0.5d)
RenderPixelGrid (dst, offset);
dst.MarkDirty ();
}