本文整理汇总了C#中IGraphics.GetClip方法的典型用法代码示例。如果您正苦于以下问题:C# IGraphics.GetClip方法的具体用法?C# IGraphics.GetClip怎么用?C# IGraphics.GetClip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IGraphics
的用法示例。
在下文中一共展示了IGraphics.GetClip方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ClipGraphicsByOverflow
/// <summary>
/// Clip the region the graphics will draw on by the overflow style of the containing block.<br/>
/// Recursively travel up the tree to find containing block that has overflow style set to hidden. if not
/// block found there will be no clipping and null will be returned.
/// </summary>
/// <param name="g">the graphics to clip</param>
/// <param name="box">the box that is rendered to get containing blocks</param>
/// <returns>the prev region if clipped, otherwise null</returns>
public static RectangleF ClipGraphicsByOverflow(IGraphics g, CssBox box)
{
var containingBlock = box.ContainingBlock;
while (true)
{
if (containingBlock.Overflow == CssConstants.Hidden)
{
var prevClip = g.GetClip();
var rect = box.ContainingBlock.ClientRectangle;
rect.X -= 2; // atodo: find better way to fix it
rect.Width += 2;
rect.Offset(box.HtmlContainer.ScrollOffset);
rect.Intersect(prevClip);
g.SetClip(rect);
return prevClip;
}
else
{
var cBlock = containingBlock.ContainingBlock;
if (cBlock == containingBlock)
return RectangleF.Empty;
containingBlock = cBlock;
}
}
}
示例2: DrawBackgroundImage
/// <summary>
/// Draw the background image of the given box in the given rectangle.<br/>
/// Handle background-repeat and background-position values.
/// </summary>
/// <param name="g">the device to draw into</param>
/// <param name="box">the box to draw its background image</param>
/// <param name="imageLoadHandler">the handler that loads image to draw</param>
/// <param name="rectangle">the rectangle to draw image in</param>
public static void DrawBackgroundImage(IGraphics g, CssBox box, ImageLoadHandler imageLoadHandler, RectangleF rectangle)
{
// image size depends if specific rectangle given in image loader
var imgSize = new Size(imageLoadHandler.Rectangle == Rectangle.Empty ? imageLoadHandler.Image.Width : imageLoadHandler.Rectangle.Width,
imageLoadHandler.Rectangle == Rectangle.Empty ? imageLoadHandler.Image.Height : imageLoadHandler.Rectangle.Height);
// get the location by BackgroundPosition value
var location = GetLocation(box.BackgroundPosition, rectangle, imgSize);
var srcRect = imageLoadHandler.Rectangle == Rectangle.Empty
? new Rectangle(0, 0, imgSize.Width, imgSize.Height)
: new Rectangle(imageLoadHandler.Rectangle.Left, imageLoadHandler.Rectangle.Top, imgSize.Width, imgSize.Height);
// initial image destination rectangle
var destRect = new Rectangle(location, imgSize);
// need to clip so repeated image will be cut on rectangle
var prevClip = g.GetClip();
var lRectangle = rectangle;
lRectangle.Intersect(prevClip);
g.SetClip(lRectangle);
switch( box.BackgroundRepeat )
{
case "no-repeat":
g.DrawImage(imageLoadHandler.Image, destRect, srcRect);
break;
case "repeat-x":
DrawRepeatX(g, imageLoadHandler, rectangle, srcRect, destRect, imgSize);
break;
case "repeat-y":
DrawRepeatY(g, imageLoadHandler, rectangle, srcRect, destRect, imgSize);
break;
default:
DrawRepeat(g, imageLoadHandler, rectangle, srcRect, destRect, imgSize);
break;
}
g.SetClip(prevClip);
}
示例3: Paint
/// <summary>
/// Paints the fragment
/// </summary>
/// <param name="g">Device context to use</param>
public void Paint(IGraphics g)
{
try
{
if (Display != CssConstants.None && Visibility == CssConstants.Visible)
{
// don't call paint if the rectangle of the box is not in visible rectangle
bool visible = Rectangles.Count == 0;
if (!visible)
{
var clip = g.GetClip();
var rect = ContainingBlock.ClientRectangle;
rect.X -= 2;
rect.Width += 2;
rect.Offset(HtmlContainer.ScrollOffset);
clip.Intersect(rect);
if (clip != RectangleF.Empty)
visible = true;
}
if (visible)
PaintImp(g);
}
}
catch (Exception ex)
{
HtmlContainer.ReportError(HtmlRenderErrorType.Paint, "Exception in box paint", ex);
}
}
示例4: PaintWords
/// <summary>
/// Paint all the words in the box.
/// </summary>
/// <param name="g">the device to draw into</param>
/// <param name="offset">the current scroll offset to offset the words</param>
private void PaintWords(IGraphics g, PointF offset)
{
foreach (var word in Words)
{
var wordPoint = new PointF(word.Left + offset.X, word.Top + offset.Y);
if (word.Selected)
{
// handle paint selected word background and with partial word selection
var wordLine = DomUtils.GetCssLineBoxByWord(word);
var left = word.SelectedStartOffset > -1 ? word.SelectedStartOffset : (wordLine.Words[0] != word && word.HasSpaceBefore ? -ActualWordSpacing : 0);
var padWordRight = word.HasSpaceAfter && !wordLine.IsLastSelectedWord(word);
var width = word.SelectedEndOffset > -1 ? word.SelectedEndOffset : word.Width + (padWordRight ? ActualWordSpacing : 0);
var rect = new RectangleF(word.Left + offset.X + left, word.Top + offset.Y, width - left, wordLine.LineHeight);
g.FillRectangle(GetSelectionBackBrush(false), rect.X, rect.Y, rect.Width, rect.Height);
if (HtmlContainer.SelectionForeColor != System.Drawing.Color.Empty && (word.SelectedStartOffset > 0 || word.SelectedEndIndexOffset > -1))
{
var orgClip = g.GetClip();
g.SetClip(rect, CombineMode.Exclude);
g.DrawString(word.Text, ActualFont, ActualColor, wordPoint, new SizeF(word.Width, word.Height));
g.SetClip(rect);
g.DrawString(word.Text, ActualFont, GetSelectionForeBrush(), wordPoint, new SizeF(word.Width, word.Height));
g.SetClip(orgClip);
}
else
{
g.DrawString(word.Text, ActualFont, GetSelectionForeBrush(), wordPoint, new SizeF(word.Width, word.Height));
}
}
else
{
//g.DrawRectangle(Pens.Red, wordPoint.X, wordPoint.Y, word.Width - 1, word.Height - 1);
g.DrawString(word.Text, ActualFont, ActualColor, wordPoint, new SizeF(word.Width, word.Height));
}
}
}