本文整理汇总了C#中Cairo.Context.MoveTo方法的典型用法代码示例。如果您正苦于以下问题:C# Cairo.Context.MoveTo方法的具体用法?C# Cairo.Context.MoveTo怎么用?C# Cairo.Context.MoveTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cairo.Context
的用法示例。
在下文中一共展示了Cairo.Context.MoveTo方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
//.........这里部分代码省略.........
示例2: OnMouseMove
protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
{
if (!painting || offset.IsNotSet ())
return;
int x = (int)point.X;
int y = (int)point.Y;
if (last_point.IsNotSet ()) {
last_point = new Point (x, y);
return;
}
using (Cairo.Context g = new Cairo.Context (PintaCore.Layers.ToolLayer.Surface)) {
g.AppendPath (PintaCore.Layers.SelectionPath);
g.FillRule = Cairo.FillRule.EvenOdd;
g.Clip ();
g.Antialias = Cairo.Antialias.Subpixel;
g.MoveTo (last_point.X, last_point.Y);
g.LineTo (x, y);
g.SetSource (PintaCore.Workspace.ActiveDocument.CurrentLayer.Surface, offset.X, offset.Y);
g.LineWidth = BrushWidth;
g.LineCap = Cairo.LineCap.Round;
g.Stroke ();
}
var dirty_rect = GetRectangleFromPoints (last_point, new Point (x, y));
last_point = new Point (x, y);
surface_modified = true;
PintaCore.Workspace.Invalidate (dirty_rect);
}
示例3: DrawConstDataIcon
protected Gdk.Pixbuf DrawConstDataIcon()
{
using (var surface = new Cairo.ImageSurface (Cairo.Format.Argb32, rectSizing.Width, rectSizing.Height)) {
using (Cairo.Context cr = new Cairo.Context (surface)) {
// background
cr.SetSourceRGB (0.7, 0.7, 0.7);
cr.Paint ();
// text
cr.SetSourceRGB (1, 0, 0);
// simple Cairo text API instead of Pango
//cr.MoveTo (10, 0.3 * height);
//cr.SetFontSize (20);
//cr.ShowText ("const");
using (var layout = Pango.CairoHelper.CreateLayout (cr)) {
// font size 12 seems suitable for iconHeight 48 pixels
float fontSize = 12 * rectSizing.Height / 48f;
layout.FontDescription = Pango.FontDescription.FromString ("Sans " + fontSize.ToString ());
layout.SetText ("const");
layout.Width = rectSizing.Width;
layout.Alignment = Pango.Alignment.Center;
int lwidth, lheight;
layout.GetPixelSize (out lwidth, out lheight);
// 0, 0 = left top
//cr.MoveTo (0.5 * (width - lwidth), 0.5 * (height - lheight));
cr.MoveTo (0.5 * rectSizing.Width, 0.5 * (rectSizing.Height - lheight));
Pango.CairoHelper.ShowLayout (cr, layout);
}
}
return new Gdk.Pixbuf (surface.Data, Gdk.Colorspace.Rgb, true, 8, rectSizing.Width, rectSizing.Height, surface.Stride, null);
}
}
示例4: 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;
}
示例5: CreateBitmap
internal static Gdk.Pixbuf CreateBitmap(string stockId, double width, double height, double scaleFactor)
{
Gdk.Pixbuf result = null;
Gtk.IconSet iconset = Gtk.IconFactory.LookupDefault (stockId);
if (iconset != null) {
// Find the size that better fits the requested size
Gtk.IconSize gsize = Util.GetBestSizeFit (width);
result = iconset.RenderIcon (Gtk.Widget.DefaultStyle, Gtk.TextDirection.Ltr, Gtk.StateType.Normal, gsize, null, null, scaleFactor);
if (result == null || result.Width < width * scaleFactor) {
var gsize2x = Util.GetBestSizeFit (width * scaleFactor, iconset.Sizes);
if (gsize2x != Gtk.IconSize.Invalid && gsize2x != gsize)
// Don't dispose the previous result since the icon is owned by the IconSet
result = iconset.RenderIcon (Gtk.Widget.DefaultStyle, Gtk.TextDirection.Ltr, Gtk.StateType.Normal, gsize2x, null, null);
}
}
if (result == null && Gtk.IconTheme.Default.HasIcon (stockId))
result = Gtk.IconTheme.Default.LoadIcon (stockId, (int)width, (Gtk.IconLookupFlags)0);
if (result == null)
{
// render a custom gtk-missing-image icon
// if Gtk.Stock.MissingImage is not found
int w = (int)width;
int h = (int)height;
#if XWT_GTK3
Cairo.ImageSurface s = new Cairo.ImageSurface(Cairo.Format.ARGB32, w, h);
Cairo.Context cr = new Cairo.Context(s);
cr.SetSourceRGB(255, 255, 255);
cr.Rectangle(0, 0, w, h);
cr.Fill();
cr.SetSourceRGB(0, 0, 0);
cr.LineWidth = 1;
cr.Rectangle(0.5, 0.5, w - 1, h - 1);
cr.Stroke();
cr.SetSourceRGB(255, 0, 0);
cr.LineWidth = 3;
cr.LineCap = Cairo.LineCap.Round;
cr.LineJoin = Cairo.LineJoin.Round;
cr.MoveTo(w / 4, h / 4);
cr.LineTo((w - 1) - w / 4, (h - 1) - h / 4);
cr.MoveTo(w / 4, (h - 1) - h / 4);
cr.LineTo((w - 1) - w / 4, h / 4);
cr.Stroke();
result = Gtk3Extensions.GetFromSurface(s, 0, 0, w, h);
#else
using (Gdk.Pixmap pmap = new Gdk.Pixmap (Gdk.Screen.Default.RootWindow, w, h))
using (Gdk.GC gc = new Gdk.GC (pmap)) {
gc.RgbFgColor = new Gdk.Color (255, 255, 255);
pmap.DrawRectangle (gc, true, 0, 0, w, h);
gc.RgbFgColor = new Gdk.Color (0, 0, 0);
pmap.DrawRectangle (gc, false, 0, 0, (w - 1), (h - 1));
gc.SetLineAttributes (3, Gdk.LineStyle.Solid, Gdk.CapStyle.Round, Gdk.JoinStyle.Round);
gc.RgbFgColor = new Gdk.Color (255, 0, 0);
pmap.DrawLine (gc, (w / 4), (h / 4), ((w - 1) - (w / 4)), ((h - 1) - (h / 4)));
pmap.DrawLine (gc, ((w - 1) - (w / 4)), (h / 4), (w / 4), ((h - 1) - (h / 4)));
result = Gdk.Pixbuf.FromDrawable (pmap, pmap.Colormap, 0, 0, 0, 0, w, h);
}
#endif
}
return result;
}