本文整理汇总了C#中Cairo.DrawImage方法的典型用法代码示例。如果您正苦于以下问题:C# Cairo.DrawImage方法的具体用法?C# Cairo.DrawImage怎么用?C# Cairo.DrawImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cairo
的用法示例。
在下文中一共展示了Cairo.DrawImage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawForeground
public override void DrawForeground (MonoTextEditor editor, Cairo.Context cr, MarginDrawMetrics metrics)
{
double size = metrics.Margin.Width;
double borderLineWidth = cr.LineWidth;
double x = Math.Floor (metrics.Margin.XOffset - borderLineWidth / 2);
double y = Math.Floor (metrics.Y + (metrics.Height - size) / 2);
var deltaX = size / 2 - DebugIcon.Width / 2 + 0.5f;
var deltaY = size / 2 - DebugIcon.Height / 2 + 0.5f;
cr.DrawImage (editor, DebugIcon, Math.Round (x + deltaX), Math.Round (y + deltaY));
}
示例2: OnDrawContent
protected override void OnDrawContent (Gdk.EventExpose evnt, Cairo.Context g)
{
g.Rectangle (0, 0, Allocation.Width, Allocation.Height);
g.SetSourceColor (marker.TooltipColor.Color);
g.Fill ();
using (var drawingLayout = new Pango.Layout (this.PangoContext)) {
drawingLayout.FontDescription = cache.tooltipFontDescription;
double y = verticalTextBorder;
var showBulletedList = marker.Errors.Count > 1;
foreach (var msg in marker.Errors) {
var icon = msg.IsError ? errorPixbuf : warningPixbuf;
int w, h;
if (!showBulletedList)
drawingLayout.Width = maxTextWidth;
drawingLayout.SetText (GetFirstLine (msg));
drawingLayout.GetPixelSize (out w, out h);
if (showBulletedList) {
g.Save ();
g.Translate (textBorder, y + verticalTextSpace / 2 + Math.Max (0, (h - icon.Height) / 2));
g.DrawImage (this, icon, 0, 0);
g.Restore ();
}
g.Save ();
g.Translate (showBulletedList ? textBorder + iconTextSpacing + icon.Width: textBorder, y + verticalTextSpace / 2);
g.SetSourceColor (marker.TagColor.SecondColor);
g.ShowLayout (drawingLayout);
g.Restore ();
y += h + verticalTextSpace;
}
}
}
示例3: DrawChangeSymbol
void DrawChangeSymbol (Cairo.Context ctx, Widget widget, double x, int width, BlockInfo block)
{
if (!IsChangeBlock (block.Type))
return;
if (block.Type == BlockType.Added) {
var ix = x + (LeftPaddingBlock/2) - (gutterAdded.Width / 2);
var iy = block.YStart + ((block.YEnd - block.YStart) / 2 - gutterAdded.Height / 2);
ctx.DrawImage (widget, gutterAdded, ix, iy);
} else {
var ix = x + (LeftPaddingBlock/2) - (gutterRemoved.Width / 2);
var iy = block.YStart + ((block.YEnd - block.YStart) / 2 - gutterRemoved.Height / 2);
ctx.DrawImage (widget, gutterRemoved, ix, iy);
}
}
示例4: RenderIcon
void RenderIcon (Cairo.Context context, Xwt.Drawing.Image surface, double opacity)
{
context.DrawImage (this, surface.WithAlpha (opacity),
Allocation.X + (Allocation.Width - surface.Width) / 2,
Allocation.Y + (Allocation.Height - surface.Height) / 2);
}
示例5: OnDrawContent
protected override void OnDrawContent (Gdk.EventExpose evnt, Cairo.Context context)
{
context.LineWidth = 1;
var alloc = ChildAllocation;
var adjustedMarginSize = alloc.X - Allocation.X + headerMarginSize;
var r = results.Where (res => res.Item2.ItemCount > 0).ToArray ();
if (r.Any ()) {
context.SetSourceColor (lightSearchBackground);
context.Rectangle (Allocation.X, Allocation.Y, adjustedMarginSize, Allocation.Height);
context.Fill ();
context.SetSourceColor (darkSearchBackground);
context.Rectangle (Allocation.X + adjustedMarginSize, Allocation.Y, Allocation.Width - adjustedMarginSize, Allocation.Height);
context.Fill ();
context.MoveTo (0.5 + Allocation.X + adjustedMarginSize, 0);
context.LineTo (0.5 + Allocation.X + adjustedMarginSize, Allocation.Height);
context.SetSourceColor (separatorLine);
context.Stroke ();
} else {
context.SetSourceRGB (1, 1, 1);
context.Rectangle (Allocation.X, Allocation.Y, Allocation.Width, Allocation.Height);
context.Fill ();
}
double y = alloc.Y + yMargin;
int w, h;
if (topItem != null) {
headerLayout.SetText (GettextCatalog.GetString ("Top Result"));
headerLayout.GetPixelSize (out w, out h);
context.MoveTo (alloc.Left + headerMarginSize - w - xMargin, y);
context.SetSourceColor (headerColor);
Pango.CairoHelper.ShowLayout (context, headerLayout);
var category = topItem.Category;
var dataSrc = topItem.DataSource;
var i = topItem.Item;
double x = alloc.X + xMargin + headerMarginSize;
context.SetSourceRGB (0, 0, 0);
layout.SetMarkup (GetRowMarkup (dataSrc, i));
layout.GetPixelSize (out w, out h);
if (selectedItem != null && selectedItem.Category == category && selectedItem.Item == i) {
context.SetSourceColor (selectionBackgroundColor);
context.Rectangle (alloc.X + headerMarginSize, y, Allocation.Width - adjustedMarginSize, h);
context.Fill ();
context.SetSourceRGB (1, 1, 1);
}
var px = dataSrc.GetIcon (i);
if (px != null) {
context.DrawImage (this, px, (int)x + marginIconSpacing, (int)y + (h - px.Height) / 2);
x += px.Width + iconTextSpacing + marginIconSpacing;
}
context.MoveTo (x, y);
context.SetSourceRGB (0, 0, 0);
Pango.CairoHelper.ShowLayout (context, layout);
y += h + itemSeparatorHeight;
}
foreach (var result in r) {
var category = result.Item1;
var dataSrc = result.Item2;
if (dataSrc.ItemCount == 0)
continue;
if (dataSrc.ItemCount == 1 && topItem != null && topItem.DataSource == dataSrc)
continue;
headerLayout.SetText (category.Name);
headerLayout.GetPixelSize (out w, out h);
if (y + h > Allocation.Height)
break;
context.MoveTo (alloc.X + headerMarginSize - w - xMargin, y);
context.SetSourceColor (headerColor);
Pango.CairoHelper.ShowLayout (context, headerLayout);
layout.Width = Pango.Units.FromPixels (Allocation.Width - adjustedMarginSize - 35);
for (int i = 0; i < maxItems && i < dataSrc.ItemCount; i++) {
if (topItem != null && topItem.Category == category && topItem.Item == i)
continue;
double x = alloc.X + xMargin + headerMarginSize;
context.SetSourceRGB (0, 0, 0);
layout.SetMarkup (GetRowMarkup (dataSrc, i));
layout.GetPixelSize (out w, out h);
if (y + h + itemSeparatorHeight > Allocation.Height)
break;
if (selectedItem != null && selectedItem.Category == category && selectedItem.Item == i) {
context.SetSourceColor (selectionBackgroundColor);
context.Rectangle (alloc.X + headerMarginSize, y, Allocation.Width - adjustedMarginSize, h);
context.Fill ();
context.SetSourceRGB (1, 1, 1);
}
var px = dataSrc.GetIcon (i);
if (px != null) {
//.........这里部分代码省略.........
示例6: DrawForeground
public override void DrawForeground (MonoTextEditor editor, Cairo.Context cr, MarginDrawMetrics metrics)
{
var tx = Math.Round (metrics.X + (metrics.Width - cache.errorPixbuf.Width) / 2) - 1;
var ty = Math.Floor (metrics.Y + (metrics.Height - cache.errorPixbuf.Height) / 2);
cr.Save ();
cr.Translate (tx, ty);
cr.DrawImage (editor, errors.Any (e => e.IsError) ? cache.errorPixbuf : cache.warningPixbuf, 0, 0);
cr.Restore ();
}
示例7: DrawForeground
public override void DrawForeground (Mono.TextEditor.MonoTextEditor editor, Cairo.Context cr, MarginDrawMetrics metrics)
{
isFailed = false;
bool searchCases = false;
Xwt.Drawing.Image icon = host.GetStatusIcon (unitTest.UnitTestIdentifier);
if (icon != null) {
if (host.HasResult (unitTest.UnitTestIdentifier)) {
searchCases = true;
} else if (host.IsFailure (unitTest.UnitTestIdentifier)) {
failMessage = host.GetMessage (unitTest.UnitTestIdentifier);
isFailed = true;
}
} else {
searchCases = true;
}
if (searchCases) {
foreach (var caseId in unitTest.TestCases) {
icon = host.GetStatusIcon (unitTest.UnitTestIdentifier, caseId);
if (host.IsFailure (unitTest.UnitTestIdentifier, caseId)) {
failMessage = host.GetMessage (unitTest.UnitTestIdentifier, caseId);
isFailed = true;
break;
}
}
}
if (icon != null) {
if (icon.Width > metrics.Width || icon.Height > metrics.Height)
icon = icon.WithBoxSize (metrics.Width, metrics.Height);
cr.DrawImage (editor, icon, Math.Truncate (metrics.X + metrics.Width / 2 - icon.Width / 2), Math.Truncate (metrics.Y + metrics.Height / 2 - icon.Height / 2));
}
}
示例8: DrawIcon
protected virtual void DrawIcon(Cairo.Context ctx)
{
int x = Allocation.X + InternalPadding;
int y = Allocation.Y + (Allocation.Height - (int)icon.Height) / 2;
ctx.DrawImage (this, icon, x, y);
if (AllowPinning && (mouseOver || pinned)) {
Xwt.Drawing.Image star;
if (pinned) {
if (mouseOverStar)
star = starPinnedHover;
else
star = starPinned;
}
else {
if (mouseOverStar)
star = starNormalHover;
else
star = starNormal;
}
x = x + (int)icon.Width - (int)star.Width + 3;
y = y + (int)icon.Height - (int)star.Height + 3;
ctx.DrawImage (this, star, x, y);
starRect = new Gdk.Rectangle (x, y, (int)star.Width, (int)star.Height);
}
}
示例9: Draw
void Draw(Cairo.Context ctx, List<TableRow> rowList, int dividerX, int x, ref int y)
{
if (!heightMeasured)
return;
Pango.Layout layout = new Pango.Layout (PangoContext);
TableRow lastCategory = null;
foreach (var r in rowList) {
int w,h;
layout.SetText (r.Label);
layout.GetPixelSize (out w, out h);
int indent = 0;
if (r.IsCategory) {
var rh = h + CategoryTopBottomPadding*2;
ctx.Rectangle (0, y, Allocation.Width, rh);
using (var gr = new LinearGradient (0, y, 0, rh)) {
gr.AddColorStop (0, new Cairo.Color (248d/255d, 248d/255d, 248d/255d));
gr.AddColorStop (1, new Cairo.Color (240d/255d, 240d/255d, 240d/255d));
ctx.SetSource (gr);
ctx.Fill ();
}
if (lastCategory == null || lastCategory.Expanded || lastCategory.AnimatingExpand) {
ctx.MoveTo (0, y + 0.5);
ctx.LineTo (Allocation.Width, y + 0.5);
}
ctx.MoveTo (0, y + rh - 0.5);
ctx.LineTo (Allocation.Width, y + rh - 0.5);
ctx.SetSourceColor (DividerColor);
ctx.Stroke ();
ctx.MoveTo (x, y + CategoryTopBottomPadding);
ctx.SetSourceColor (CategoryLabelColor);
Pango.CairoHelper.ShowLayout (ctx, layout);
var img = r.Expanded ? discloseUp : discloseDown;
ctx.DrawImage (this, img, Allocation.Width - img.Width - CategoryTopBottomPadding, y + Math.Round ((rh - img.Height) / 2));
y += rh;
lastCategory = r;
}
else {
var cell = GetCell (r);
r.Enabled = !r.Property.IsReadOnly || cell.EditsReadOnlyObject;
var state = r.Enabled ? State : Gtk.StateType.Insensitive;
ctx.Save ();
ctx.Rectangle (0, y, dividerX, h + PropertyTopBottomPadding*2);
ctx.Clip ();
ctx.MoveTo (x, y + PropertyTopBottomPadding);
ctx.SetSourceColor (Style.Text (state).ToCairoColor ());
Pango.CairoHelper.ShowLayout (ctx, layout);
ctx.Restore ();
if (r != currentEditorRow)
cell.Render (GdkWindow, ctx, r.EditorBounds, state);
y += r.EditorBounds.Height;
indent = PropertyIndent;
}
if (r.ChildRows != null && r.ChildRows.Count > 0 && (r.Expanded || r.AnimatingExpand)) {
int py = y;
ctx.Save ();
if (r.AnimatingExpand)
ctx.Rectangle (0, y, Allocation.Width, r.AnimationHeight);
else
ctx.Rectangle (0, 0, Allocation.Width, Allocation.Height);
ctx.Clip ();
Draw (ctx, r.ChildRows, dividerX, x + indent, ref y);
ctx.Restore ();
if (r.AnimatingExpand) {
y = py + r.AnimationHeight;
// Repaing the background because the cairo clip doesn't work for gdk primitives
int dx = (int)((double)Allocation.Width * dividerPosition);
ctx.Rectangle (0, y, dx, Allocation.Height - y);
ctx.SetSourceColor (LabelBackgroundColor);
ctx.Fill ();
ctx.Rectangle (dx + 1, y, Allocation.Width - dx - 1, Allocation.Height - y);
ctx.SetSourceRGB (1, 1, 1);
ctx.Fill ();
}
}
}
}
示例10: DrawIndicator
void DrawIndicator (Cairo.Context cr, Xwt.Drawing.Image img)
{
cr.DrawImage (this, img, Math.Round ((Allocation.Width - img.Width) / 2), -1);
}
示例11: RenderPreview
void RenderPreview (Cairo.Context context, Gdk.Point position, double opacity)
{
if (brandedIcon != null) {
/* if (previewSurface == null) {
previewSurface = new SurfaceWrapper (context, brandedIcon);
}
double scale = PreviewSize / previewSurface.Width;
context.Save ();
context.Translate (position.X, position.Y);
context.Scale (scale * IconScale, scale * IconScale);
context.SetSourceSurface (previewSurface.Surface, -previewSurface.Width / 2, -previewSurface.Height / 2);
context.PaintWithAlpha (opacity);
context.Restore ();
*/
double scale = PreviewSize / brandedIcon.Width;
context.Save ();
context.Translate (position.X, position.Y);
context.Scale (scale * IconScale, scale * IconScale);
context.DrawImage (this, brandedIcon.WithAlpha (opacity), -brandedIcon.Width / 2, -brandedIcon.Height / 2);
context.Restore ();
}
}
示例12: Render
public void Render (Cairo.Context context, StatusArea.RenderArg arg, Gtk.Widget widget)
{
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.SetSource (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 - (int)arg.CurrentPixbuf.Size.Height) / 2;
context.DrawImage (widget, arg.CurrentPixbuf, arg.ChildAllocation.X, y);
progress_bar_x += (int)arg.CurrentPixbuf.Width + Styles.ProgressBarOuterPadding;
progress_bar_width -= (int)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 ();
}
示例13: DrawBackground
void DrawBackground (Cairo.Context context, Gdk.Rectangle region, int radius, StateType state)
{
int x = region.X + region.Width / 2;
int y = region.Y + region.Height / 2;
var img = btnNormal;
switch (state) {
case StateType.Insensitive:
img = btnInactive; break;
case StateType.Prelight:
img = btnHover; break;
case StateType.Selected:
img = btnPressed; break;
}
x -= (int) img.Width / 2;
y -= (int) img.Height / 2;
context.DrawImage (this, img, x, y);
}
示例14: DrawForeground
public override void DrawForeground (TextEditor editor, Cairo.Context cr, MarginDrawMetrics metrics)
{
isFailed = false;
var test = NUnitService.Instance.SearchTestById (unitTest.UnitTestIdentifier);
bool searchCases = false;
Xwt.Drawing.Image icon = null;
if (test != null) {
icon = test.StatusIcon;
var result = test.GetLastResult ();
if (result == null) {
searchCases = true;
} else if (result.IsFailure) {
failMessage = result.Message;
isFailed = true;
}
} else {
searchCases = true;
}
if (searchCases) {
foreach (var caseId in unitTest.TestCases) {
test = NUnitService.Instance.SearchTestById (unitTest.UnitTestIdentifier + caseId);
if (test != null) {
icon = test.StatusIcon;
var result = test.GetLastResult ();
if (result != null && result.IsFailure) {
failMessage = result.Message;
isFailed = true;
break;
}
}
}
}
if (icon != null) {
if (icon.Width > metrics.Width || icon.Height > metrics.Height)
icon = icon.WithBoxSize (metrics.Width, metrics.Height);
cr.DrawImage (editor, icon, Math.Truncate (metrics.X + metrics.Width / 2 - icon.Width / 2), Math.Truncate (metrics.Y + metrics.Height / 2 - icon.Height / 2));
}
}
示例15: DrawImage
protected void DrawImage (Cairo.Context cr, Image image, double x, double y, double size)
{
var deltaX = size / 2 - image.Width / 2 + 0.5f;
var deltaY = size / 2 - image.Height / 2 + 0.5f;
cr.DrawImage (Editor, image, Math.Round (x + deltaX), Math.Round (y + deltaY));
}