本文整理汇总了C#中Shape类的典型用法代码示例。如果您正苦于以下问题:C# Shape类的具体用法?C# Shape怎么用?C# Shape使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Shape类属于命名空间,在下文中一共展示了Shape类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyFrom
/// <override></override>
public override void CopyFrom(Shape source)
{
base.CopyFrom(source);
// Copy size if the source is a DiameterShape
if (source is DiameterShapeBase)
internalDiameter = ((DiameterShapeBase) source).DiameterInternal;
else {
// If not, try to calculate the size a good as possible
Rectangle srcBounds = Geometry.InvalidRectangle;
if (source is PathBasedPlanarShape) {
PathBasedPlanarShape src = (PathBasedPlanarShape) source;
// Calculate the bounds of the (unrotated) resize handles because with
// GetBoundingRectangle(), we receive the bounds including the children's bounds
List<Point> pointBuffer = new List<Point>();
int centerX = src.X;
int centerY = src.Y;
float angleDeg = Geometry.TenthsOfDegreeToDegrees(-src.Angle);
foreach (ControlPointId id in source.GetControlPointIds(ControlPointCapabilities.Resize))
pointBuffer.Add(Geometry.RotatePoint(centerX, centerY, angleDeg, source.GetControlPointPosition(id)));
Geometry.CalcBoundingRectangle(pointBuffer, out srcBounds);
}
else {
// Generic approach: try to fit into the bounding rectangle
srcBounds = source.GetBoundingRectangle(true);
}
//
// Calculate new size
if (Geometry.IsValid(srcBounds)) {
float scale = Geometry.CalcScaleFactor(DiameterInternal, DiameterInternal, srcBounds.Width, srcBounds.Height);
DiameterInternal = (int) Math.Round(DiameterInternal*scale);
}
}
}
示例2: DropConnection
public static Shape DropConnection(
Shape source,
Shape target,
string masterNameU)
{
return DropConnection(source, target, masterNameU, ClassConnections.Right, ClassConnections.Top);
}
示例3: CreateIndexableFields
//---------------------------------
// Indexing
//---------------------------------
public override Field[] CreateIndexableFields(Shape shape)
{
var rect = shape as Rectangle;
if (rect != null)
return CreateIndexableFields(rect);
throw new InvalidOperationException("Can only index Rectangle, not " + shape);
}
示例4: CreateIndexableFields
public override AbstractField[] CreateIndexableFields(Shape shape)
{
var point = shape as Point;
if (point != null)
{
var f = new AbstractField[2];
var f0 = new NumericField(fieldNameX, precisionStep, Field.Store.NO, true)
{OmitNorms = true, OmitTermFreqAndPositions = true};
f0.SetDoubleValue(point.GetX());
f[0] = f0;
var f1 = new NumericField(fieldNameY, precisionStep, Field.Store.NO, true)
{OmitNorms = true, OmitTermFreqAndPositions = true};
f1.SetDoubleValue(point.GetY());
f[1] = f1;
return f;
}
if (!ignoreIncompatibleGeometry)
{
throw new ArgumentException("TwoDoublesStrategy can not index: " + shape);
}
return new AbstractField[0]; // nothing (solr does not support null)
}
示例5: CollisionMovingRight
public bool CollisionMovingRight(Shape fallingShape, Dictionary<int, Tile> fallenTiles)
{
if (HitRightSideOfGrid(fallingShape) || HitFallenShapesMovingRight(fallingShape, fallenTiles))
return true;
return false;
}
示例6: RenderShapeToStream
public static void RenderShapeToStream(string dataDir, Shape shape)
{
//ExStart
//ExFor:ShapeRenderer
//ExFor:ShapeRenderer.#ctor(ShapeBase)
//ExFor:ImageSaveOptions.ImageColorMode
//ExFor:ImageSaveOptions.ImageBrightness
//ExFor:ShapeRenderer.Save(Stream, ImageSaveOptions)
//ExId:RenderShapeToStream
//ExSummary:Shows how to render a shape independent of the document to a JPEG image and save it to a stream.
// We can also retrieve the renderer for a shape by using the ShapeRenderer constructor.
ShapeRenderer r = new ShapeRenderer(shape);
// Define custom options which control how the image is rendered. Render the shape to the vector format EMF.
ImageSaveOptions imageOptions = new ImageSaveOptions(SaveFormat.Jpeg)
{
// Output the image in gray scale
ImageColorMode = ImageColorMode.Grayscale,
// Reduce the brightness a bit (default is 0.5f).
ImageBrightness = 0.45f
};
FileStream stream = new FileStream(dataDir + "TestFile.RenderToStream Out.jpg", FileMode.CreateNew);
// Save the rendered image to the stream using different options.
r.Save(stream, imageOptions);
//ExEnd
}
示例7: FixConnectorTextControl
public static void FixConnectorTextControl(Shape shape)
{
if (Common.GetShapeType(shape) == ShapeTypes.Connector) {
string pinX = Common.GetCellFormula(shape, "TxtPinX");
// if the current TxtPinX already is updating another cell via setatref, we don't need to
// do anything
if (!pinX.Contains("SETATREF")) {
shape.AddNamedRow((short)VisSectionIndices.visSectionControls, "TextPosition", 0);
// get old values and reuse them if we already have text
string pinY = Common.GetCellFormula(shape, "TxtPinY");
if (shape.Text.Length > 0) {
shape.get_CellsU("Controls.TextPosition.X").Formula = pinX;
shape.get_CellsU("Controls.TextPosition.Y").Formula = pinY;
}
else {
shape.get_CellsU("Controls.TextPosition.Y").FormulaU = "Height*0.5";
shape.get_CellsU("Controls.TextPosition.X").FormulaU = "Width*0.5";
}
shape.get_CellsU("Controls.TextPosition.XDyn").FormulaU = "Controls.TextPosition.X";
shape.get_CellsU("Controls.TextPosition.YDyn").FormulaU = "Controls.TextPosition.Y";
shape.get_CellsU("Controls.TextPosition.XCon").FormulaU = "IF(OR(STRSAME(SHAPETEXT(TheText),\"\"),HideText),5,0)";
shape.get_CellsU("Controls.TextPosition.CanGlue").FormulaU = "FALSE";
shape.get_CellsU("Controls.TextPosition.Prompt").FormulaU = "\"Reposition Text\"";
shape.get_CellsU("TxtPinX").FormulaU = "SETATREF(Controls.TextPosition)";
shape.get_CellsU("TxtPinY").FormulaU = "SETATREF(Controls.TextPosition.Y)";
}
}
}
示例8: DistanceGrid
public DistanceGrid(Shape shape, Scalar spacing)
{
if (shape == null) { throw new ArgumentNullException("shape"); }
if (spacing <= 0) { throw new ArgumentOutOfRangeException("spacing"); }
//prepare the shape.
Matrix2D old = shape.Matrix;
Matrix2D ident = Matrix2D.Identity;
shape.ApplyMatrix(ref ident);
shape.CalcBoundingBox2D();
this.box = shape.BoundingBox2D;
this.gridSpacing = spacing;
this.gridSpacingInv = 1 / spacing;
int xSize = (int)Math.Ceiling((box.Upper.X - box.Lower.X) * gridSpacingInv) + 2;
int ySize = (int)Math.Ceiling((box.Upper.Y - box.Lower.Y) * gridSpacingInv) + 2;
this.nodes = new Scalar[xSize, ySize];
Vector2D vector;
vector.X = box.Lower.X;
for (int x = 0; x < xSize; ++x, vector.X += spacing)
{
vector.Y = box.Lower.Y;
for (int y = 0; y < ySize; ++y, vector.Y += spacing)
{
nodes[x, y] = shape.GetDistance(vector);
}
}
//restore the shape
shape.ApplyMatrix(ref old);
shape.CalcBoundingBox2D();
}
示例9: IsSameType
/// <summary>
/// Checks if the current shape is of the same type as the parameter
/// </summary>
/// <param name="otherShape"></param>
/// <returns></returns>
public bool IsSameType(Shape otherShape)
{
if (otherShape == null || !(otherShape is Shape))
throw new ArgumentException("otherShape");
return string.Compare(this.Type, (otherShape as Shape).Type) == 0;
}
示例10: CopyFrom
/// <override></override>
public override void CopyFrom(Shape source) {
base.CopyFrom(source);
if (source is CircularArcBase) {
// Vertices and CapStyles will be copied by the base class
// so there's nothing left to do here...
}
}
示例11: CreatePrimitive
/**
* \brief If passed a valid ProBuilder::Shape, create it! Non-valid shape is Shape.Custom.
* \code{.cs}
* // Example usage:
* pb_Object myNewPrism = ProBuilder.CreatePrimitive(ProBuilder.Shape.Prism);
* \endcode
* @param shape The primitive type to create. Always creates the shape with default parameters (if applicable).
* \returns The new pb_Object.
*/
public static pb_Object CreatePrimitive(Shape shape)
{
pb_Object pb;
switch(shape)
{
case Shape.Cube:
pb = pb_Shape_Generator.CubeGenerator(Vector3.one);
break;
case Shape.Prism:
pb = pb_Shape_Generator.PrismGenerator(Vector3.one);
break;
case Shape.Stair:
// steps, width, height, depth, extend sides to floor, generate back, platforms only
pb = pb_Shape_Generator.StairGenerator(5, 2f, 5f, 7f, true, true, false);
break;
case Shape.Cylinder:
pb = pb_Shape_Generator.CylinderGenerator(6, 1.5f, 4f, 2);
break;
case Shape.Plane:
pb = pb_Shape_Generator.PlaneGenerator(2f, 2f, 3, 3, Axis.Up, false);
break;
default:
return null;
}
// pb.Refresh();
return pb;
}
示例12: cardToString
public static string cardToString(int val, Shape shape)
{
string str = System.String.Empty;
if (val <= 0 || val >= 14)
return str;
str = val.ToString();
switch (shape)
{
case Shape.Club:
str += "c";
break;
case Shape.Diamond:
str += "d";
break;
case Shape.Heart:
str += "h";
break;
case Shape.Spade:
str += "s";
break;
}
return str;
}
示例13: Main
static void Main()
{
var shapes = new Shape[numberOfShapes];
for (int i = 0; i < shapes.Length; i++)
{
switch (vladoRandoma.Next() % 3)
{
case 0:
shapes[i] = new Triangle(widths[vladoRandoma.Next(0, widths.Length)],
heights[vladoRandoma.Next(0, heights.Length)]);
break;
case 1: shapes[i] = new Rectangle(widths[vladoRandoma.Next(0, widths.Length)],
heights[vladoRandoma.Next(0, heights.Length)]);
break;
case 2: shapes[i] = new Circle(heights[vladoRandoma.Next(0, heights.Length)]);
break;
default:
break;
}
}
foreach (var item in shapes)
{
Console.WriteLine(item.ToString().Replace(',', '.'));
}
}
示例14: RenderShapeToGraphics
public static void RenderShapeToGraphics(string dataDir, Shape shape)
{
ShapeRenderer r = shape.GetShapeRenderer();
// Find the size that the shape will be rendered to at the specified scale and resolution.
Size shapeSizeInPixels = r.GetSizeInPixels(1.0f, 96.0f);
// Rotating the shape may result in clipping as the image canvas is too small. Find the longest side
// and make sure that the graphics canvas is large enough to compensate for this.
int maxSide = Math.Max(shapeSizeInPixels.Width, shapeSizeInPixels.Height);
using (Bitmap image = new Bitmap((int)(maxSide * 1.25), (int)(maxSide * 1.25)))
{
// Rendering to a graphics object means we can specify settings and transformations to be applied to
// the shape that is rendered. In our case we will rotate the rendered shape.
using (Graphics gr = Graphics.FromImage(image))
{
// Clear the shape with the background color of the document.
gr.Clear(shape.Document.PageColor);
// Center the rotation using translation method below
gr.TranslateTransform((float)image.Width / 8, (float)image.Height / 2);
// Rotate the image by 45 degrees.
gr.RotateTransform(45);
// Undo the translation.
gr.TranslateTransform(-(float)image.Width / 8, -(float)image.Height / 2);
// Render the shape onto the graphics object.
r.RenderToSize(gr, 0, 0, shapeSizeInPixels.Width, shapeSizeInPixels.Height);
}
dataDir = dataDir + "TestFile.RenderToGraphics_out_.png";
image.Save(dataDir, ImageFormat.Png);
Console.WriteLine("\nShape rendered to graphics successfully.\nFile saved at " + dataDir);
}
}
示例15: Execute
public IList<Shape> Execute(StyleOption option, EffectsDesigner designer, ImageItem source,
Shape imageShape)
{
designer.ApplyPseudoTextWhenNoTextShapes();
if ((option.IsUseBannerStyle
|| option.IsUseFrostedGlassBannerStyle)
&& (option.GetTextBoxPosition() == Position.Left
|| option.GetTextBoxPosition() == Position.Centre
|| option.GetTextBoxPosition() == Position.Right))
{
designer.ApplyTextWrapping();
}
else if (option.IsUseCircleStyle
|| option.IsUseOutlineStyle)
{
designer.ApplyTextWrapping();
}
else
{
designer.RecoverTextWrapping();
}
ApplyTextEffect(option, designer);
designer.ApplyTextGlowEffect(option.IsUseTextGlow, option.TextGlowColor);
return new List<Shape>();
}