コード例 #1
0
ファイル: PolygonZShape.cs プロジェクト: qjw2bqn/czml-writer
        public PolygonZShape(
            int recordNumber,
            StringDictionary metadata,
            CartographicExtent extent,
            int[] parts,
            Rectangular[] positions,
            double minimumZ,
            double maximumZ,
            double[] zValues,
            double minimumMeasure,
            double maximumMeasure,
            double[] measures,
            ShapeType shapeType = ShapeType.PolygonZ
            )
            : base(recordNumber, metadata, extent, parts, positions, minimumMeasure, maximumMeasure, measures, shapeType)
        {
            _minimumZ = minimumZ;
            _maximumZ = maximumZ;

            for (int i = 0; i < parts.Length; ++i)
            {
                int count = ((i == parts.Length - 1) ?
                    positions.Length : parts[i + 1]) - parts[i];

                _parts[i] = new ShapePart(positions, zValues, measures, parts[i], count);
            }
        }
コード例 #2
0
ファイル: LineStyle2.cs プロジェクト: Hamsand/Swf2XNA
        public LineStyle2(SwfReader r, ShapeType shapeType)
        {
            this.Width = r.GetUI16();
            this.StartCapStyle = (CapStyle)r.GetBits(2);
            this.JoinStyle = (JoinStyle)r.GetBits(2);
            this.HasFillFlag = r.GetBit();
            this.NoHScaleFlag = r.GetBit();
            this.NoVScaleFlag = r.GetBit();
            this.PixelHintingFlag = r.GetBit();
            r.GetBits(5); // skip
            this.NoClose = r.GetBit();
            this.EndCapStyle = (CapStyle)r.GetBits(2);

            if (this.JoinStyle == JoinStyle.MiterJoin)
            {
                this.MiterLimitFactor = (float)((r.GetByte() / 0x100) + r.GetByte());
            }

            if (this.HasFillFlag)
            {
                this.FillStyle = FillStyleArray.ParseFillStyle2(r, shapeType);
            }
            else
            {
                this.Color = new RGBA(r.GetByte(), r.GetByte(), r.GetByte(), r.GetByte());
            }
        }
コード例 #3
0
        //Metoden CreateShape skriver ut en header som talar om vilken
        //typ av form vi har valt att skapa och läser in bredd och längd.
        //När värdena är inmatade skapas ett nytt objekt.
        private static Shape CreateShape(ShapeType shapeType)
        {
            double width;
            double length;

            Console.WriteLine();
            Console.BackgroundColor = ConsoleColor.DarkGreen;
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("===========================");
            Console.WriteLine("=                         =");
            Console.WriteLine("= {0,15}         =", shapeType);
            Console.WriteLine("=                         =");
            Console.WriteLine("===========================");
            Console.WriteLine();
            Console.ResetColor();

            width = ReadDoubleGreaterThanZero("Ange bredd: ");
            length = ReadDoubleGreaterThanZero("Ange längd: ");

            switch (shapeType)
            {
                case ShapeType.Ellipse:
                    return new Ellipse(width, length);

                case ShapeType.Rectangle:
                    return new Rectangle(width, length);

                default:
                    throw new ApplicationException();
            }
        }
コード例 #4
0
 //Current
 public FoundationCatalogResource(int APIversion,
     uint version,
     FoundationType foundation,
     MaterialList materials,
     Common common,
     uint wallCatalogIndex,
     uint floorCatalogIndex,
     uint vpxyIndex,
     uint index3,
     uint index4,
     uint unknown5,
     uint unknown6,
     ShapeType shape,
     TGIBlockList ltgib)
     : this(APIversion,
     version,
     foundation,
     common,
     wallCatalogIndex,
     floorCatalogIndex,
     index3,
     index4,
     unknown5,
     unknown6,
     shape,
     ltgib)
 {
     if (checking) if (version < 0x00000004)
             throw new InvalidOperationException(String.Format("Version {0} invalid with these arguments", version));
     this.materials = new MaterialList(OnResourceChanged, materials);
     this.vpxyIndex = vpxyIndex;
 }
コード例 #5
0
ファイル: Shape.cs プロジェクト: TNOCS/csTouch
 /// <summary>
 /// Base Shapefile shape - contains only the shape type and metadata plus helper methods.
 /// An instance of Shape is the Null ShapeType. If the Type field is not ShapeType.Null then
 /// cast to the more specific shape (i.e. ShapePolygon).
 /// </summary>
 /// <param name="shapeType">The ShapeType of the shape</param>
 /// <param name="recordNumber">The record number in the Shapefile</param>
 /// <param name="metadata">Metadata about the shape (optional)</param>
 /// <param name="dataRecord">IDataRecord associated with the shape</param>
 protected internal Shape(ShapeType shapeType, int recordNumber, StringDictionary metadata, IDataRecord dataRecord)
 {
     _type = shapeType;
     _metadata = metadata;
     _recordNumber = recordNumber;
     _dataRecord = dataRecord;
 }
コード例 #6
0
ファイル: Program.cs プロジェクト: re222dv/1DV402-C-sharp
        /// <summary>
        /// Creates a shape of the specified Shape Type
        /// </summary>
        public static Shape CreateShape(ShapeType shapeType)
        {
            Console.Clear();
            ViewHeader(shapeType.AsText());

            double[] dimensions = ReadDimensions(shapeType);

            Console.WriteLine();

            switch (shapeType) {
                case ShapeType.Circle:
                    return new Ellipse(dimensions[0]);
                case ShapeType.Sphere:
                    return new Sphere(dimensions[0] / 2);
                case ShapeType.Ellipse:
                    return new Ellipse(dimensions[0], dimensions[1]);
                case ShapeType.Rectangle:
                    return new Rectangle(dimensions[0], dimensions[1]);
                case ShapeType.Cuboid:
                    return new Cuboid(dimensions[0], dimensions[1], dimensions[2]);
                case ShapeType.Cylinder:
                    return new Cylinder(dimensions[0] / 2, dimensions[1] / 2, dimensions[2]);
            }
            return null;
        }
コード例 #7
0
 public void UpdateChildren(ShapeType s, GameObject target)
 {
     for (int i = 0; i < ChildCount(); i++)
     {
         this.transform.GetChild(i).GetComponent<ShapeBehavior>().UpdateShape(s, this);
     }
 }
コード例 #8
0
ファイル: Ragdoll.cs プロジェクト: Type1J/AtomicExamples
        void CreateRagdollBone(string boneName, ShapeType type, Vector3 size, Vector3 position, Quaternion rotation)
        {
            // Find the correct child scene node recursively
            Node boneNode = Node.GetChild(boneName, true);
            if (boneNode == null)
            {
                Log.Warn($"Could not find bone {boneName} for creating ragdoll physics components");
                return;
            }

            RigidBody body = boneNode.CreateComponent<RigidBody>();
            // Set mass to make movable
            body.Mass = 1.0f;
            // Set damping parameters to smooth out the motion
            body.LinearDamping = 0.05f;
            body.AngularDamping = 0.85f;
            // Set rest thresholds to ensure the ragdoll rigid bodies come to rest to not consume CPU endlessly
            body.LinearRestThreshold = 1.5f;
            body.AngularRestThreshold = 2.5f;

            CollisionShape shape = boneNode.CreateComponent<CollisionShape>();
            // We use either a box or a capsule shape for all of the bones
            if (type == ShapeType.SHAPE_BOX)
                shape.SetBox(size, position, rotation);
            else
                shape.SetCapsule(size.X, size.Y, position, rotation);
        }
コード例 #9
0
ファイル: SuperImage.cs プロジェクト: madeso/ImBatch
 public void InsertShape(ShapeType shapeType, int xPosition, int yPosition, int width, int height, Color colorName)
 {
     Bitmap temp = this.currentBitmap;
     Bitmap bmap = (Bitmap)temp.Clone();
     Graphics gr = Graphics.FromImage(bmap);
     Pen pen = new Pen(colorName);
     switch (shapeType)
     {
         case ShapeType.FilledEllipse:
             gr.FillEllipse(pen.Brush, xPosition, yPosition, width, height);
             break;
         case ShapeType.FilledRectangle:
             gr.FillRectangle(pen.Brush, xPosition, yPosition, width, height);
             break;
         case ShapeType.Ellipse:
             gr.DrawEllipse(pen, xPosition, yPosition, width, height);
             break;
         case ShapeType.Rectangle:
             gr.DrawRectangle(pen, xPosition, yPosition, width, height);
             break;
         default:
             throw new Exception("unhandled shapetype: " + shapeType);
     }
     this.currentBitmap = (Bitmap)bmap.Clone();
 }
コード例 #10
0
ファイル: PolygonDrawable.cs プロジェクト: homoluden/fukami
        public ColoredPolygonDrawable(ColoredPolygon polygon, ShapeType shapeType = ShapeType.Mesh)
        {
            if (polygon == null) { throw new ArgumentNullException("polygon"); }

            Polygon = polygon;
            BaseShape = shapeType;
        }
コード例 #11
0
ファイル: Program.cs プロジェクト: rn222cx/WP14
        private static Shape CreateShape(ShapeType shapeType)
        {
            Console.BackgroundColor = ConsoleColor.DarkGreen;
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("========================================");
            Console.WriteLine("={0,25}             =", shapeType);
            Console.WriteLine("========================================\n");
            Console.ResetColor();

            // Deklarera samt skriver in de olikas värden
            double length = ReadDoubleGreaterThanZero("Ange längden: ");
            double width = ReadDoubleGreaterThanZero("Ange Bredden: ");

            Console.WriteLine();

            // Val av form
            switch (shapeType)
            {
                case ShapeType.Ellipse:
                    return new Ellipse(length, width);
                case ShapeType.Rectangle:
                    return new Rectangle(length, width);
                default:
                    throw new ApplicationException();
            }
        }
コード例 #12
0
        public static List<IShapeFlyweight> Create(ShapeType type, int count)
        {
            IShapeFlyweight shape = null;

            switch (type)
            {
                case ShapeType.Square:
                    shape = new Square();
                    break;
                case ShapeType.Circle:
                    shape = new Circle();
                    break;
                case ShapeType.Triangle:
                    shape = new Triangle();
                    break;
                default:
                    throw new InvalidOperationException();
            }

            var shapes = new List<IShapeFlyweight>();
            shapes.Add(shape);

            for (int i = 1; i < count; i++)
            {
                shapes.Add(shape.Clone() as IShapeFlyweight);
            }

            return shapes;
        }
コード例 #13
0
ファイル: QuarterCircle.cs プロジェクト: hl222ih/2DV610.1
        public QuarterCircle(int cx, int cy, int radius, ShapeType shapeType) : base(shapeType)
        {
            if (radius < 0) throw new ArgumentOutOfRangeException("Radius not allowed to be negative.");

            CX = cx;
            CY = cy;
            Radius = radius;
        }
コード例 #14
0
ファイル: ShapeInfo.cs プロジェクト: 5665tm/GeometryApp
 /// <summary>
 ///     Конструктор
 /// </summary>
 /// <param name="guid">GUID</param>
 /// <param name="type">Тип фигуры</param>
 /// <param name="info">Информация о фигуре</param>
 /// <param name="coordinates">Координаты</param>
 /// <param name="color">Цвет</param>
 public ShapeInfo(Guid guid, ShapeType type, string info, string coordinates, string color)
 {
     Guid = guid;
     Type = type;
     Info = info;
     Coordinates = coordinates;
     Color = color;
 }
コード例 #15
0
ファイル: ShapeGroup.cs プロジェクト: kjburns31/vixen-modules
 /// <override></override>
 protected internal ShapeGroup(ShapeType shapeType, Template template)
     : base()
 {
     if (shapeType == null) throw new ArgumentNullException("shapeType");
     this.shapeType = shapeType;
     this.template = template;
     children = new GroupShapeAggregation(this);
 }
コード例 #16
0
 public override void Reset()
 {
     gameObject = null;
     shape = ShapeType.Sphere;
     color = Color.grey;
     radius = 1f;
     size = new Vector3(1f, 1f, 1f);
 }
コード例 #17
0
        public void SetDefaultShapes(ShapeType tableShape, ShapeType relationshipShape, ShapeType lblShape)
        {
            TableShape = tableShape;
            RelationshipShape = relationshipShape;
            LblShape = lblShape;

            var charStyle = ((EntitySymbol) tableShape.CreateInstance()).ColumnCharacterStyle;
            baseEntityFont = new Font(charStyle.FontFamily, charStyle.SizeInPoints, FontStyle.Bold);
        }
コード例 #18
0
ファイル: Shape.cs プロジェクト: madeso/ImBatch
 public Shape(XmlElement element)
 {
     this.xPosition = Parsing.ParseInt(element, "x");
     this.yPosition = Parsing.ParseInt(element, "y");
     this.width = Parsing.ParseInt(element, "width");
     this.height = Parsing.ParseInt(element, "height");
     this.shapeType = Parsing.ParseEnum<ShapeType>(element, "shape");
     this.color = Parsing.ParseColor(element, "color");
 }
コード例 #19
0
ファイル: DrawUtil.cs プロジェクト: kunukn/single-detect
        public static void DrawDots(DrawingContext dc, ICollection<IP> dots, Rectangle rect, ShapeType t = ShapeType.Default)
        {
            if (!IsDrawEnabled) return;

            foreach (var p in dots.Where(p => p != null))
            {
                dc.DrawRectangle(GetColor(p, t), null, GetShape(p, rect, t));
            }
        }
コード例 #20
0
ファイル: Form1.cs プロジェクト: rcreddy06/PaintApplication
 public void reset()
 {
     //reset the form roperties
     penColor = Color.FromArgb(255, 255, 0, 0);
     penWidth = 10;
     shapeList.Clear();
     currentShapeType = ShapeType.Line;
     dataModified = false;
 }
コード例 #21
0
ファイル: PointZShape.cs プロジェクト: qjw2bqn/czml-writer
 public PointZShape(
     int recordNumber, 
     StringDictionary metadata,
     Cartographic position,
     double measure, 
     ShapeType shapeType = ShapeType.PointZ)
     : base(recordNumber, metadata, position, measure, shapeType)
 {
 }
コード例 #22
0
ファイル: VectorFeature.cs プロジェクト: jarollz/Harlow
        public VectorFeature(int numOfParts, ShapeType shapeType)
        {
            if (shapeType != ShapeType.Point)
            {
                Bbox = new double[4];
            }

            Properties = new Dictionary<string, string>();
        }
コード例 #23
0
ファイル: Sp.cs プロジェクト: advdig/advgp2_administracion
 /**
  * Constructor - used when writing
  *
  * @param st the shape type
  * @param sid the shape id
  * @param p persistence flags
  */
 public Sp(ShapeType st,int sid,int p)
     : base(EscherRecordType.SP)
 {
     setVersion(2);
     shapeType = st.getValue();
     shapeId = sid;
     persistenceFlags = p;
     setInstance(shapeType);
 }
コード例 #24
0
 public static Shape CreateShape(ShapeType shapeType)
 {
     // Warning: Possible missed enum case(s) 'Square' int the switch statemet
     switch(shapeType)
     {
         case ShapeType.Circle: return new Circle();
         case ShapeType.Rectangle:return new Rectangle();
         default: throw new InvalidOperationException($"Unknown shape type '{shapeType}'");
     }
 }
コード例 #25
0
ファイル: Cloud.cs プロジェクト: henrikno/CloudWars
 protected Cloud(World world, float vapor, IGraphicManager graphicsHandler, ShapeType shapeType)
 {
     this.world = world;
     this.vapor = vapor;
     this.graphicsHandler = graphicsHandler;
     velocity = new Vector();
     position = new Vector();
     shape = graphicsHandler.InsertShape(shapeType);
     random = new Random(DateTime.UtcNow.Millisecond);
 }
コード例 #26
0
ファイル: Region.cs プロジェクト: naegelyd/therawii
 public Region(Region r)
 {
     regionEnabled = r.regionEnabled;
     rParams = new SerializableDictionary<regPT, RegionParameter>();
     foreach (regPT rPT in r.rParams.Keys)
     {
         rParams.Add(rPT, new RegionParameter(r.rParams[rPT]));
     }
     Shape = r.Shape;
 }
コード例 #27
0
ファイル: VectorShape.cs プロジェクト: jarollz/Harlow
        public VectorShape(int numOfParts, ShapeType shapeType)
            : base(numOfParts, shapeType)
        {
            if (shapeType != ShapeType.Point)
            {
                Bbox = new double[4];
            }

            this.Coordinates = new List<PointA[]>(numOfParts);
            this.Properties = new Dictionary<string, string>();
        }
コード例 #28
0
ファイル: Scene.cs プロジェクト: AtanasK/VP
 public void AddShape(Point position, ShapeType type)
 {
     Shape shape = null;
     if (type == ShapeType.CIRCLE)
         shape = new Circle(position, CurrentColor);
     else if (type == ShapeType.TRIANGLE)
         shape = new Triangle(position, CurrentColor,
             new Point(position.X + 30, position.Y),
             new Point(position.X, position.Y + 20));
     shapes.Add(shape);
 }
コード例 #29
0
ファイル: FixtureDef.cs プロジェクト: CloneDeath/Box2DX
 /// <summary>
 /// The constructor sets the default fixture definition values.
 /// </summary>	
 public FixtureDef()
 {
     Type = ShapeType.UnknownShape;
     UserData = null;
     Friction = 0.2f;
     Restitution = 0.0f;
     Density = 0.0f;
     Filter.CategoryBits = 0x0001;
     Filter.MaskBits = 0xFFFF;
     Filter.GroupIndex = 0;
     IsSensor = false;
 }
コード例 #30
0
 public static Shape Create(ShapeType type, double width)
 {
     switch (type)
     {
         case ShapeType.Circle:
             return new Circle(width);;
         case ShapeType.EquilateralTriangle:
             return new EquilateralTriangle(width);;
         default:
              return new Square(width);;
     }
 }
コード例 #31
0
        /// <summary>
        /// Create new document with textbox shape and some query
        /// </summary>
        internal static Document CreateTemplateDocumentWithDrawObjects(string templateText, ShapeType shapeType)
        {
            Document doc = new Document();

            // Create textbox shape.
            Shape shape = new Shape(doc, shapeType);

            shape.Width  = 431.5;
            shape.Height = 346.35;

            Paragraph paragraph = new Paragraph(doc);

            paragraph.AppendChild(new Run(doc, templateText));

            // Insert paragraph into the textbox.
            shape.AppendChild(paragraph);

            // Insert textbox into the document.
            doc.FirstSection.Body.FirstParagraph.AppendChild(shape);

            return(doc);
        }
コード例 #32
0
ファイル: DragHitShape.cs プロジェクト: wwwK/AsteroidMiner
 public void SetShape_Sphere(Point3D center, double radius)
 {
     _shape  = ShapeType.Sphere;
     _point  = center;
     _radius = radius;
 }
コード例 #33
0
        /// <summary>
        /// Populates the given streams for the shp and shx file when not in IndexMode.
        /// </summary>
        /// <param name="shpStream">Stream that is used to write the shp file.</param>
        /// <param name="shxStream">Stream that is used to write the shx file.</param>
        /// <param name="shapefile">The shapefile that contains the features that are written.</param>
        /// <param name="addPoints">Function that is used to add the points from the features to the parts and points lists.</param>
        /// <param name="expectedZType">Indicates which Z-ShapeType the header must have for the z values to be written.</param>
        /// <param name="expectedMType">Indicates which M-ShapeType the header must have for the m values to be written.</param>
        /// <param name="withParts">Indicates whether the parts should be written.</param>
        /// <returns>The lengths of the streams in bytes.</returns>
        internal static StreamLengthPair PopulateStreamsNotIndexed(Stream shpStream, Stream shxStream, Shapefile shapefile, Action <List <int>, List <Coordinate>, IFeature> addPoints, ShapeType expectedZType, ShapeType expectedMType, bool withParts)
        {
            var progressMeter = new ProgressMeter(shapefile.ProgressHandler, "Saving (Not Indexed)...", shapefile.Features.Count);

            int fid    = 0;
            int offset = 50; // the shapefile header starts at 100 bytes, so the initial offset is 50 words

            foreach (IFeature f in shapefile.Features)
            {
                List <int>        parts  = new List <int>();
                List <Coordinate> points = new List <Coordinate>();

                addPoints(parts, points, f);

                bool isNullShape = false;
                int  contentLength;

                // null shapes have a contentLength of 2, all other shapes must have the same shape type
                if (f.Geometry.IsEmpty)
                {
                    contentLength = 2;
                    isNullShape   = true;
                }
                else
                {
                    contentLength = GetContentLength(parts.Count, points.Count, shapefile.Header.ShapeType);
                }

                ////                                                      Index File
                //                                                       ---------------------------------------------------------
                //                                                       Position     Value          Type       Number  Byte Order
                //                                                       ---------------------------------------------------------
                shxStream.WriteBe(offset);                               // Byte 0     Offset         Integer     1      Big
                shxStream.WriteBe(contentLength);                        // Byte 4     Content Length Integer     1      Big

                ////                                                     X Y Poly Lines
                //                                                       ---------------------------------------------------------
                //                                                       Position     Value         Type        Number      Byte Order
                //                                                       -------------------------------------------------------
                shpStream.WriteBe(fid + 1);                              // Byte 0   Record Number  Integer     1           Big
                shpStream.WriteBe(contentLength);                        // Byte 4   Content Length Integer     1           Big

                if (isNullShape)
                {
                    shpStream.WriteLe((int)ShapeType.NullShape);         // Byte 8   Shape Type 0   Integer     1           Little
                }
                else
                {
                    shpStream.WriteLe((int)shapefile.Header.ShapeType);  // Byte 8   Shape Type     Integer     1           Little

                    shpStream.WriteLe(f.Geometry.EnvelopeInternal.MinX); // Byte 12   Xmin          Double      1           Little
                    shpStream.WriteLe(f.Geometry.EnvelopeInternal.MinY); // Byte 20   Ymin          Double      1           Little
                    shpStream.WriteLe(f.Geometry.EnvelopeInternal.MaxX); // Byte 28   Xmax          Double      1           Little
                    shpStream.WriteLe(f.Geometry.EnvelopeInternal.MaxY); // Byte 36   Ymax          Double      1           Little
                    if (withParts)
                    {
                        shpStream.WriteLe(parts.Count); // Byte 44   NumParts      Integer     1           Little
                    }
                    shpStream.WriteLe(points.Count);    // Byte 48   NumPoints     Integer     1           Little

                    if (withParts)                      ////                                     Byte 52   Parts         Integer     NumParts    Little
                    {
                        foreach (int part in parts)
                        {
                            shpStream.WriteLe(part);
                        }
                    }

                    double[] xyVals = new double[points.Count * 2];      // Byte X     Points              Point       NumPoints   Little
                    for (int i = 0; i < points.Count; i++)
                    {
                        xyVals[i * 2]       = points[i].X;
                        xyVals[(i * 2) + 1] = points[i].Y;
                    }

                    shpStream.WriteLe(xyVals);

                    if (shapefile.Header.ShapeType == expectedZType)
                    {
                        shpStream.WriteLe(f.Geometry.EnvelopeInternal.Minimum.Z);
                        shpStream.WriteLe(f.Geometry.EnvelopeInternal.Maximum.Z);
                        double[] zVals = new double[points.Count];
                        for (int i = 0; i < points.Count; i++)
                        {
                            zVals[i] = points[i].Z;
                        }

                        shpStream.WriteLe(zVals);
                    }

                    if (shapefile.Header.ShapeType == expectedMType || shapefile.Header.ShapeType == expectedZType)
                    {
                        shpStream.WriteLe(f.Geometry.EnvelopeInternal.Minimum.M);
                        shpStream.WriteLe(f.Geometry.EnvelopeInternal.Maximum.M);

                        double[] mVals = new double[points.Count];
                        for (int i = 0; i < points.Count; i++)
                        {
                            mVals[i] = points[i].M;
                        }

                        shpStream.WriteLe(mVals);
                    }
                }

                progressMeter.CurrentValue = fid;
                fid++;
                offset += 4;             // header bytes
                offset += contentLength; // adding the content length from each loop calculates the word offset
            }

            progressMeter.Reset();

            return(new StreamLengthPair {
                ShpLength = offset, ShxLength = 50 + (fid * 4)
            });
        }
コード例 #34
0
        private static void Deserialize(World world, Stream stream)
        {
            List <Body>    bodies   = new List <Body>();
            List <Fixture> fixtures = new List <Fixture>();
            List <Joint>   joints   = new List <Joint>();
            List <Shape>   shapes   = new List <Shape>();

            XMLFragmentElement root = XMLFragmentParser.LoadFromStream(stream);

            if (root.Name.ToLower() != "world")
            {
                throw new Exception();
            }

            //Read gravity
            foreach (XMLFragmentElement element in root.Elements)
            {
                if (element.Name.ToLower() == "gravity")
                {
                    world.Gravity = ReadVector(element);
                    break;
                }
            }

            //Read shapes
            foreach (XMLFragmentElement shapeElement in root.Elements)
            {
                if (shapeElement.Name.ToLower() == "shapes")
                {
                    foreach (XMLFragmentElement element in shapeElement.Elements)
                    {
                        if (element.Name.ToLower() != "shape")
                        {
                            throw new Exception();
                        }

                        ShapeType type    = (ShapeType)Enum.Parse(typeof(ShapeType), element.Attributes[0].Value, true);
                        float     density = float.Parse(element.Attributes[1].Value);

                        switch (type)
                        {
                        case ShapeType.Circle:
                        {
                            CircleShape shape = new CircleShape();
                            shape._density = density;

                            foreach (XMLFragmentElement sn in element.Elements)
                            {
                                switch (sn.Name.ToLower())
                                {
                                case "radius":
                                    shape.Radius = float.Parse(sn.Value);
                                    break;

                                case "position":
                                    shape.Position = ReadVector(sn);
                                    break;

                                default:
                                    throw new Exception();
                                }
                            }

                            shapes.Add(shape);
                        }
                        break;

                        case ShapeType.Polygon:
                        {
                            PolygonShape shape = new PolygonShape();
                            shape._density = density;

                            foreach (XMLFragmentElement sn in element.Elements)
                            {
                                switch (sn.Name.ToLower())
                                {
                                case "vertices":
                                {
                                    List <Vector2> verts = new List <Vector2>(sn.Elements.Count);

                                    foreach (XMLFragmentElement vert in sn.Elements)
                                    {
                                        verts.Add(ReadVector(vert));
                                    }

                                    shape.Vertices = new Vertices(verts);
                                }
                                break;

                                case "centroid":
                                    shape.MassData.Centroid = ReadVector(sn);
                                    break;
                                }
                            }

                            shapes.Add(shape);
                        }
                        break;

                        case ShapeType.Edge:
                        {
                            EdgeShape shape = new EdgeShape();
                            shape._density = density;

                            foreach (XMLFragmentElement sn in element.Elements)
                            {
                                switch (sn.Name.ToLower())
                                {
                                case "hasvertex0":
                                    shape.HasVertex0 = bool.Parse(sn.Value);
                                    break;

                                case "hasvertex3":
                                    shape.HasVertex0 = bool.Parse(sn.Value);
                                    break;

                                case "vertex0":
                                    shape.Vertex0 = ReadVector(sn);
                                    break;

                                case "vertex1":
                                    shape.Vertex1 = ReadVector(sn);
                                    break;

                                case "vertex2":
                                    shape.Vertex2 = ReadVector(sn);
                                    break;

                                case "vertex3":
                                    shape.Vertex3 = ReadVector(sn);
                                    break;

                                default:
                                    throw new Exception();
                                }
                            }
                            shapes.Add(shape);
                        }
                        break;

                        case ShapeType.Chain:
                        {
                            ChainShape shape = new ChainShape();
                            shape._density = density;

                            foreach (XMLFragmentElement sn in element.Elements)
                            {
                                switch (sn.Name.ToLower())
                                {
                                case "vertices":
                                {
                                    List <Vector2> verts = new List <Vector2>(sn.Elements.Count);

                                    foreach (XMLFragmentElement vert in sn.Elements)
                                    {
                                        verts.Add(ReadVector(vert));
                                    }

                                    shape.Vertices = new Vertices(verts);
                                }
                                break;

                                case "nextvertex":
                                    shape.NextVertex = ReadVector(sn);
                                    break;

                                case "prevvertex":
                                    shape.PrevVertex = ReadVector(sn);
                                    break;

                                default:
                                    throw new Exception();
                                }
                            }
                            shapes.Add(shape);
                        }
                        break;
                        }
                    }
                }
            }

            //Read fixtures
            foreach (XMLFragmentElement fixtureElement in root.Elements)
            {
                if (fixtureElement.Name.ToLower() == "fixtures")
                {
                    foreach (XMLFragmentElement element in fixtureElement.Elements)
                    {
                        Fixture fixture = new Fixture();

                        if (element.Name.ToLower() != "fixture")
                        {
                            throw new Exception();
                        }

                        fixture.FixtureId = int.Parse(element.Attributes[0].Value);

                        foreach (XMLFragmentElement sn in element.Elements)
                        {
                            switch (sn.Name.ToLower())
                            {
                            case "filterdata":
                                foreach (XMLFragmentElement ssn in sn.Elements)
                                {
                                    switch (ssn.Name.ToLower())
                                    {
                                    case "categorybits":
                                        fixture._collisionCategories = (Category)int.Parse(ssn.Value);
                                        break;

                                    case "maskbits":
                                        fixture._collidesWith = (Category)int.Parse(ssn.Value);
                                        break;

                                    case "groupindex":
                                        fixture._collisionGroup = short.Parse(ssn.Value);
                                        break;

                                    case "CollisionIgnores":
                                        string[] split = ssn.Value.Split('|');
                                        foreach (string s in split)
                                        {
                                            fixture._collisionIgnores.Add(int.Parse(s));
                                        }
                                        break;
                                    }
                                }

                                break;

                            case "friction":
                                fixture.Friction = float.Parse(sn.Value);
                                break;

                            case "issensor":
                                fixture.IsSensor = bool.Parse(sn.Value);
                                break;

                            case "restitution":
                                fixture.Restitution = float.Parse(sn.Value);
                                break;

                            case "userdata":
                                fixture.UserData = ReadSimpleType(sn, null, false);
                                break;
                            }
                        }

                        fixtures.Add(fixture);
                    }
                }
            }

            //Read bodies
            foreach (XMLFragmentElement bodyElement in root.Elements)
            {
                if (bodyElement.Name.ToLower() == "bodies")
                {
                    foreach (XMLFragmentElement element in bodyElement.Elements)
                    {
                        Body body = new Body(world);

                        if (element.Name.ToLower() != "body")
                        {
                            throw new Exception();
                        }

                        body.BodyType = (BodyType)Enum.Parse(typeof(BodyType), element.Attributes[0].Value, true);

                        foreach (XMLFragmentElement sn in element.Elements)
                        {
                            switch (sn.Name.ToLower())
                            {
                            case "active":
                                bool enabled = bool.Parse(sn.Value);
                                if (enabled)
                                {
                                    body._flags |= BodyFlags.Enabled;
                                }
                                else
                                {
                                    body._flags &= ~BodyFlags.Enabled;
                                }
                                break;

                            case "allowsleep":
                                body.SleepingAllowed = bool.Parse(sn.Value);
                                break;

                            case "angle":
                            {
                                Vector2 position = body.Position;
                                body.SetTransformIgnoreContacts(ref position, float.Parse(sn.Value));
                            }
                            break;

                            case "angulardamping":
                                body.AngularDamping = float.Parse(sn.Value);
                                break;

                            case "angularvelocity":
                                body.AngularVelocity = float.Parse(sn.Value);
                                break;

                            case "awake":
                                body.Awake = bool.Parse(sn.Value);
                                break;

                            case "bullet":
                                body.IsBullet = bool.Parse(sn.Value);
                                break;

                            case "fixedrotation":
                                body.FixedRotation = bool.Parse(sn.Value);
                                break;

                            case "lineardamping":
                                body.LinearDamping = float.Parse(sn.Value);
                                break;

                            case "linearvelocity":
                                body.LinearVelocity = ReadVector(sn);
                                break;

                            case "position":
                            {
                                float   rotation = body.Rotation;
                                Vector2 position = ReadVector(sn);
                                body.SetTransformIgnoreContacts(ref position, rotation);
                            }
                            break;

                            case "userdata":
                                body.UserData = ReadSimpleType(sn, null, false);
                                break;

                            case "bindings":
                            {
                                foreach (XMLFragmentElement pair in sn.Elements)
                                {
                                    Fixture fix = fixtures[int.Parse(pair.Attributes[0].Value)];
                                    fix.Shape = shapes[int.Parse(pair.Attributes[1].Value)].Clone();
                                    fix.CloneOnto(body);
                                }
                                break;
                            }
                            }
                        }

                        bodies.Add(body);
                    }
                }
            }

            //Read joints
            foreach (XMLFragmentElement jointElement in root.Elements)
            {
                if (jointElement.Name.ToLower() == "joints")
                {
                    foreach (XMLFragmentElement n in jointElement.Elements)
                    {
                        Joint joint;

                        if (n.Name.ToLower() != "joint")
                        {
                            throw new Exception();
                        }

                        JointType type = (JointType)Enum.Parse(typeof(JointType), n.Attributes[0].Value, true);

                        int    bodyAIndex = -1, bodyBIndex = -1;
                        bool   collideConnected = false;
                        object userData         = null;

                        foreach (XMLFragmentElement sn in n.Elements)
                        {
                            switch (sn.Name.ToLower())
                            {
                            case "bodya":
                                bodyAIndex = int.Parse(sn.Value);
                                break;

                            case "bodyb":
                                bodyBIndex = int.Parse(sn.Value);
                                break;

                            case "collideconnected":
                                collideConnected = bool.Parse(sn.Value);
                                break;

                            case "userdata":
                                userData = ReadSimpleType(sn, null, false);
                                break;
                            }
                        }

                        Body bodyA = bodies[bodyAIndex];
                        Body bodyB = bodies[bodyBIndex];

                        switch (type)
                        {
                        //case JointType.FixedMouse:
                        //    joint = new FixedMouseJoint();
                        //    break;
                        //case JointType.FixedRevolute:
                        //    break;
                        //case JointType.FixedDistance:
                        //    break;
                        //case JointType.FixedLine:
                        //    break;
                        //case JointType.FixedPrismatic:
                        //    break;
                        //case JointType.FixedAngle:
                        //    break;
                        //case JointType.FixedFriction:
                        //    break;
                        case JointType.Distance:
                            joint = new DistanceJoint();
                            break;

                        case JointType.Friction:
                            joint = new FrictionJoint();
                            break;

                        case JointType.Wheel:
                            joint = new WheelJoint();
                            break;

                        case JointType.Prismatic:
                            joint = new PrismaticJoint();
                            break;

                        case JointType.Pulley:
                            joint = new PulleyJoint();
                            break;

                        case JointType.Revolute:
                            joint = new RevoluteJoint();
                            break;

                        case JointType.Weld:
                            joint = new WeldJoint();
                            break;

                        case JointType.Rope:
                            joint = new RopeJoint();
                            break;

                        case JointType.Angle:
                            joint = new AngleJoint();
                            break;

                        case JointType.Motor:
                            joint = new MotorJoint();
                            break;

                        case JointType.Gear:
                            throw new Exception("GearJoint is not supported.");

                        default:
                            throw new Exception("Invalid or unsupported joint.");
                        }

                        joint.CollideConnected = collideConnected;
                        joint.UserData         = userData;
                        joint.BodyA            = bodyA;
                        joint.BodyB            = bodyB;
                        joints.Add(joint);
                        world.AddJoint(joint);

                        foreach (XMLFragmentElement sn in n.Elements)
                        {
                            // check for specific nodes
                            switch (type)
                            {
                            case JointType.Distance:
                            {
                                switch (sn.Name.ToLower())
                                {
                                case "dampingratio":
                                    ((DistanceJoint)joint).DampingRatio = float.Parse(sn.Value);
                                    break;

                                case "frequencyhz":
                                    ((DistanceJoint)joint).Frequency = float.Parse(sn.Value);
                                    break;

                                case "length":
                                    ((DistanceJoint)joint).Length = float.Parse(sn.Value);
                                    break;

                                case "localanchora":
                                    ((DistanceJoint)joint).LocalAnchorA = ReadVector(sn);
                                    break;

                                case "localanchorb":
                                    ((DistanceJoint)joint).LocalAnchorB = ReadVector(sn);
                                    break;
                                }
                            }
                            break;

                            case JointType.Friction:
                            {
                                switch (sn.Name.ToLower())
                                {
                                case "localanchora":
                                    ((FrictionJoint)joint).LocalAnchorA = ReadVector(sn);
                                    break;

                                case "localanchorb":
                                    ((FrictionJoint)joint).LocalAnchorB = ReadVector(sn);
                                    break;

                                case "maxforce":
                                    ((FrictionJoint)joint).MaxForce = float.Parse(sn.Value);
                                    break;

                                case "maxtorque":
                                    ((FrictionJoint)joint).MaxTorque = float.Parse(sn.Value);
                                    break;
                                }
                            }
                            break;

                            case JointType.Wheel:
                            {
                                switch (sn.Name.ToLower())
                                {
                                case "enablemotor":
                                    ((WheelJoint)joint).MotorEnabled = bool.Parse(sn.Value);
                                    break;

                                case "localanchora":
                                    ((WheelJoint)joint).LocalAnchorA = ReadVector(sn);
                                    break;

                                case "localanchorb":
                                    ((WheelJoint)joint).LocalAnchorB = ReadVector(sn);
                                    break;

                                case "motorspeed":
                                    ((WheelJoint)joint).MotorSpeed = float.Parse(sn.Value);
                                    break;

                                case "dampingratio":
                                    ((WheelJoint)joint).DampingRatio = float.Parse(sn.Value);
                                    break;

                                case "maxmotortorque":
                                    ((WheelJoint)joint).MaxMotorTorque = float.Parse(sn.Value);
                                    break;

                                case "frequencyhz":
                                    ((WheelJoint)joint).Frequency = float.Parse(sn.Value);
                                    break;

                                case "axis":
                                    ((WheelJoint)joint).Axis = ReadVector(sn);
                                    break;
                                }
                            }
                            break;

                            case JointType.Prismatic:
                            {
                                switch (sn.Name.ToLower())
                                {
                                case "enablelimit":
                                    ((PrismaticJoint)joint).LimitEnabled = bool.Parse(sn.Value);
                                    break;

                                case "enablemotor":
                                    ((PrismaticJoint)joint).MotorEnabled = bool.Parse(sn.Value);
                                    break;

                                case "localanchora":
                                    ((PrismaticJoint)joint).LocalAnchorA = ReadVector(sn);
                                    break;

                                case "localanchorb":
                                    ((PrismaticJoint)joint).LocalAnchorB = ReadVector(sn);
                                    break;

                                case "axis":
                                    ((PrismaticJoint)joint).Axis = ReadVector(sn);
                                    break;

                                case "maxmotorforce":
                                    ((PrismaticJoint)joint).MaxMotorForce = float.Parse(sn.Value);
                                    break;

                                case "motorspeed":
                                    ((PrismaticJoint)joint).MotorSpeed = float.Parse(sn.Value);
                                    break;

                                case "lowertranslation":
                                    ((PrismaticJoint)joint).LowerLimit = float.Parse(sn.Value);
                                    break;

                                case "uppertranslation":
                                    ((PrismaticJoint)joint).UpperLimit = float.Parse(sn.Value);
                                    break;

                                case "referenceangle":
                                    ((PrismaticJoint)joint).ReferenceAngle = float.Parse(sn.Value);
                                    break;
                                }
                            }
                            break;

                            case JointType.Pulley:
                            {
                                switch (sn.Name.ToLower())
                                {
                                case "worldanchora":
                                    ((PulleyJoint)joint).WorldAnchorA = ReadVector(sn);
                                    break;

                                case "worldanchorb":
                                    ((PulleyJoint)joint).WorldAnchorB = ReadVector(sn);
                                    break;

                                case "lengtha":
                                    ((PulleyJoint)joint).LengthA = float.Parse(sn.Value);
                                    break;

                                case "lengthb":
                                    ((PulleyJoint)joint).LengthB = float.Parse(sn.Value);
                                    break;

                                case "localanchora":
                                    ((PulleyJoint)joint).LocalAnchorA = ReadVector(sn);
                                    break;

                                case "localanchorb":
                                    ((PulleyJoint)joint).LocalAnchorB = ReadVector(sn);
                                    break;

                                case "ratio":
                                    ((PulleyJoint)joint).Ratio = float.Parse(sn.Value);
                                    break;

                                case "constant":
                                    ((PulleyJoint)joint).Constant = float.Parse(sn.Value);
                                    break;
                                }
                            }
                            break;

                            case JointType.Revolute:
                            {
                                switch (sn.Name.ToLower())
                                {
                                case "enablelimit":
                                    ((RevoluteJoint)joint).LimitEnabled = bool.Parse(sn.Value);
                                    break;

                                case "enablemotor":
                                    ((RevoluteJoint)joint).MotorEnabled = bool.Parse(sn.Value);
                                    break;

                                case "localanchora":
                                    ((RevoluteJoint)joint).LocalAnchorA = ReadVector(sn);
                                    break;

                                case "localanchorb":
                                    ((RevoluteJoint)joint).LocalAnchorB = ReadVector(sn);
                                    break;

                                case "maxmotortorque":
                                    ((RevoluteJoint)joint).MaxMotorTorque = float.Parse(sn.Value);
                                    break;

                                case "motorspeed":
                                    ((RevoluteJoint)joint).MotorSpeed = float.Parse(sn.Value);
                                    break;

                                case "lowerangle":
                                    ((RevoluteJoint)joint).LowerLimit = float.Parse(sn.Value);
                                    break;

                                case "upperangle":
                                    ((RevoluteJoint)joint).UpperLimit = float.Parse(sn.Value);
                                    break;

                                case "referenceangle":
                                    ((RevoluteJoint)joint).ReferenceAngle = float.Parse(sn.Value);
                                    break;
                                }
                            }
                            break;

                            case JointType.Weld:
                            {
                                switch (sn.Name.ToLower())
                                {
                                case "localanchora":
                                    ((WeldJoint)joint).LocalAnchorA = ReadVector(sn);
                                    break;

                                case "localanchorb":
                                    ((WeldJoint)joint).LocalAnchorB = ReadVector(sn);
                                    break;
                                }
                            }
                            break;

                            case JointType.Rope:
                            {
                                switch (sn.Name.ToLower())
                                {
                                case "localanchora":
                                    ((RopeJoint)joint).LocalAnchorA = ReadVector(sn);
                                    break;

                                case "localanchorb":
                                    ((RopeJoint)joint).LocalAnchorB = ReadVector(sn);
                                    break;

                                case "maxlength":
                                    ((RopeJoint)joint).MaxLength = float.Parse(sn.Value);
                                    break;
                                }
                            }
                            break;

                            case JointType.Gear:
                                throw new Exception("Gear joint is unsupported");

                            case JointType.Angle:
                            {
                                switch (sn.Name.ToLower())
                                {
                                case "biasfactor":
                                    ((AngleJoint)joint).BiasFactor = float.Parse(sn.Value);
                                    break;

                                case "maximpulse":
                                    ((AngleJoint)joint).MaxImpulse = float.Parse(sn.Value);
                                    break;

                                case "softness":
                                    ((AngleJoint)joint).Softness = float.Parse(sn.Value);
                                    break;

                                case "targetangle":
                                    ((AngleJoint)joint).TargetAngle = float.Parse(sn.Value);
                                    break;
                                }
                            }
                            break;

                            case JointType.Motor:
                                switch (sn.Name.ToLower())
                                {
                                case "angularoffset":
                                    ((MotorJoint)joint).AngularOffset = float.Parse(sn.Value);
                                    break;

                                case "linearoffset":
                                    ((MotorJoint)joint).LinearOffset = ReadVector(sn);
                                    break;

                                case "maxforce":
                                    ((MotorJoint)joint).MaxForce = float.Parse(sn.Value);
                                    break;

                                case "maxtorque":
                                    ((MotorJoint)joint).MaxTorque = float.Parse(sn.Value);
                                    break;

                                case "correctionfactor":
                                    ((MotorJoint)joint).CorrectionFactor = float.Parse(sn.Value);
                                    break;
                                }
                                break;
                            }
                        }
                    }
                }
            }

            world.ProcessChanges();
        }
コード例 #35
0
 private Rectangle GetShapeImageRectangle(ShapeType shapeType)
 {
     return(new Rectangle((int)shapeType * BlockSize, 0, BlockSize, BlockSize));
 }
コード例 #36
0
        /// <summary>
        /// Execute the SymbolStage
        /// </summary>
        /// <param name="sketch">A mutable sketch</param>
        /// <param name="filename">the name of the file being loaded</param>
        public override void run(Sketch.Sketch sketch, string filename)
        {
            Sketch.Sketch handLabeled = sketch.Clone();
            if (!_isPure)
            {
                sketch.RemoveLabels();
                sketch.resetShapes();
            }


            // Run!
            _pipeline.process(sketch);

            // Assessment
            int numShapes        = handLabeled.Shapes.Length;
            int numCorrect       = 0;
            int numMisgrouped    = 0;
            int numMisrecognized = 0;

            foreach (Sketch.Shape correctShape in handLabeled.Shapes)
            {
                if (!_recognizer.canRecognize(correctShape.Classification))
                {
                    // Decrement the number of shapes so this one doesn't count
                    // against us.
                    numShapes--;
                    continue;
                }

                ShapeType originalType = correctShape.Type;

                Sketch.Shape resultShape = sketch.ShapesL.Find(delegate(Sketch.Shape s) { return(s.GeometricEquals(correctShape)); });

                if (resultShape == null)
                {
                    numMisgrouped++;
                    continue;
                }

                ShapeType resultType = resultShape.Type;

                _typesSeen.Add(originalType);
                _typesSeen.Add(resultType);

                ensureKeyExists2D(_confusionMatrix, originalType, resultType);

                // Record stats
                _confusionMatrix[originalType][resultType]++;
                if (originalType == resultType)
                {
                    numCorrect++;
                }
                else
                {
                    numMisrecognized++;
                    if (_useLearning)
                    {
                        resultShape.Type = correctShape.Type; // not using originalType means we preserve case
                        _recognizer.learnFromExample(resultShape);
                    }
                }
            }
            _results.Add(new int[] {
                _results.Count + 1,
                numShapes,
                numCorrect,
                numMisgrouped,
                numMisrecognized
            });

            Console.WriteLine("   --> Correct recognitions: " + numCorrect + "/" + numShapes);
            Console.WriteLine("   --> Misgrouped: " + numMisgrouped);
            Console.WriteLine("   --> Misrecognized: " + numMisrecognized);
        }
コード例 #37
0
            internal Region(BinaryReaderEx br)
            {
                long start      = br.Position;
                long nameOffset = br.ReadInt64();

                Unk08 = br.ReadInt16();
                br.AssertByte((byte)Type);
                ShapeType shapeType = br.ReadEnum8 <ShapeType>();

                br.ReadInt16(); // Index
                Unk0E    = br.ReadInt16();
                Position = br.ReadVector3();
                Rotation = br.ReadVector3();
                long unkOffsetA = br.ReadInt64();
                long unkOffsetB = br.ReadInt64();

                br.AssertInt32(-1);
                br.AssertPattern(0x24, 0x00);
                long shapeDataOffset = br.ReadInt64();
                long typeDataOffset  = br.ReadInt64();

                br.AssertInt64(0);
                br.AssertInt64(0);

                Name = br.GetUTF16(start + nameOffset);

                br.Position = start + unkOffsetA;
                br.AssertInt32(0);

                br.Position = start + unkOffsetB;
                br.AssertInt32(0);

                br.Position = start + shapeDataOffset;
                switch (shapeType)
                {
                case ShapeType.Point:
                    Shape = new Shape.Point();
                    break;

                case ShapeType.Circle:
                    Shape = new Shape.Circle(br);
                    break;

                case ShapeType.Sphere:
                    Shape = new Shape.Sphere(br);
                    break;

                case ShapeType.Cylinder:
                    Shape = new Shape.Cylinder(br);
                    break;

                case ShapeType.Rect:
                    Shape = new Shape.Rect(br);
                    break;

                case ShapeType.Box:
                    Shape = new Shape.Box(br);
                    break;

                default:
                    throw new NotImplementedException($"Unimplemented shape type: {shapeType}");
                }

                if (HasTypeData)
                {
                    br.Position = start + typeDataOffset;
                    ReadTypeData(br);
                }
            }
コード例 #38
0
ファイル: ShapeManager.cs プロジェクト: dasilva94/ShareX
        private void CreateContextMenu()
        {
            cmsContextMenu = new ContextMenuStrip(form.components);

            #region Main

            ToolStripMenuItem tsmiCancelCapture = new ToolStripMenuItem("Cancel capture");
            tsmiCancelCapture.Image  = Resources.prohibition;
            tsmiCancelCapture.Click += (sender, e) => form.Close(RegionResult.Close);
            cmsContextMenu.Items.Add(tsmiCancelCapture);

            ToolStripMenuItem tsmiCloseMenu = new ToolStripMenuItem("Close menu");
            tsmiCloseMenu.Image  = Resources.cross;
            tsmiCloseMenu.Click += (sender, e) => cmsContextMenu.Close();
            cmsContextMenu.Items.Add(tsmiCloseMenu);

            #endregion Main

            #region Selected object

            tssObjectOptions = new ToolStripSeparator();
            cmsContextMenu.Items.Add(tssObjectOptions);

            tsmiDeleteSelected        = new ToolStripMenuItem("Delete selected object");
            tsmiDeleteSelected.Image  = Resources.layer__minus;
            tsmiDeleteSelected.Click += (sender, e) => DeleteSelectedShape();
            cmsContextMenu.Items.Add(tsmiDeleteSelected);

            tsmiDeleteAll        = new ToolStripMenuItem("Delete all objects");
            tsmiDeleteAll.Image  = Resources.minus;
            tsmiDeleteAll.Click += (sender, e) => ClearAll();
            cmsContextMenu.Items.Add(tsmiDeleteAll);

            #endregion Selected object

            #region Tools

            cmsContextMenu.Items.Add(new ToolStripSeparator());

            foreach (ShapeType shapeType in Helpers.GetEnums <ShapeType>())
            {
                ToolStripMenuItem tsmiShapeType = new ToolStripMenuItem(shapeType.GetLocalizedDescription());

                Image img = null;

                switch (shapeType)
                {
                case ShapeType.RegionRectangle:
                    img = Resources.layer_shape_region;
                    break;

                case ShapeType.RegionRoundedRectangle:
                    img = Resources.layer_shape_round_region;
                    break;

                case ShapeType.RegionEllipse:
                    img = Resources.layer_shape_ellipse_region;
                    break;

                case ShapeType.DrawingRectangle:
                    img = Resources.layer_shape;
                    break;

                case ShapeType.DrawingRoundedRectangle:
                    img = Resources.layer_shape_round;
                    break;

                case ShapeType.DrawingEllipse:
                    img = Resources.layer_shape_ellipse;
                    break;

                case ShapeType.DrawingLine:
                    img = Resources.layer_shape_line;
                    break;

                case ShapeType.DrawingArrow:
                    img = Resources.layer_shape_arrow;
                    break;

                case ShapeType.DrawingText:
                    img = Resources.layer_shape_text;
                    break;

                case ShapeType.DrawingBlur:
                    img = Resources.layer_shade;
                    break;

                case ShapeType.DrawingPixelate:
                    img = Resources.grid;
                    break;

                case ShapeType.DrawingHighlight:
                    img = Resources.highlighter_text;
                    break;
                }

                tsmiShapeType.Image = img;

                tsmiShapeType.Checked = shapeType == CurrentShapeType;
                tsmiShapeType.Tag     = shapeType;
                tsmiShapeType.Click  += (sender, e) =>
                {
                    tsmiShapeType.RadioCheck();
                    CurrentShapeType = shapeType;
                };
                cmsContextMenu.Items.Add(tsmiShapeType);
            }

            #endregion Tools

            #region Shape options

            tssShapeOptions = new ToolStripSeparator();
            cmsContextMenu.Items.Add(tssShapeOptions);

            tsmiBorderColor        = new ToolStripMenuItem("Border color...");
            tsmiBorderColor.Click += (sender, e) =>
            {
                PauseForm();

                ShapeType shapeType = CurrentShapeType;

                Color borderColor;

                if (shapeType == ShapeType.DrawingText)
                {
                    borderColor = AnnotationOptions.TextBorderColor;
                }
                else
                {
                    borderColor = AnnotationOptions.BorderColor;
                }

                using (ColorPickerForm dialogColor = new ColorPickerForm(borderColor))
                {
                    if (dialogColor.ShowDialog() == DialogResult.OK)
                    {
                        if (shapeType == ShapeType.DrawingText)
                        {
                            AnnotationOptions.TextBorderColor = dialogColor.NewColor;
                        }
                        else
                        {
                            AnnotationOptions.BorderColor = dialogColor.NewColor;
                        }

                        UpdateContextMenu();
                        UpdateCurrentShape();
                    }
                }

                ResumeForm();
            };
            cmsContextMenu.Items.Add(tsmiBorderColor);

            tslnudBorderSize = new ToolStripLabeledNumericUpDown();
            tslnudBorderSize.LabeledNumericUpDownControl.Text         = "Border size:";
            tslnudBorderSize.LabeledNumericUpDownControl.Minimum      = 0;
            tslnudBorderSize.LabeledNumericUpDownControl.Maximum      = 20;
            tslnudBorderSize.LabeledNumericUpDownControl.ValueChanged = (sender, e) =>
            {
                ShapeType shapeType = CurrentShapeType;

                int borderSize = (int)tslnudBorderSize.LabeledNumericUpDownControl.Value;

                if (shapeType == ShapeType.DrawingText)
                {
                    AnnotationOptions.TextBorderSize = borderSize;
                }
                else
                {
                    AnnotationOptions.BorderSize = borderSize;
                }

                UpdateCurrentShape();
            };
            cmsContextMenu.Items.Add(tslnudBorderSize);

            tsmiFillColor        = new ToolStripMenuItem("Fill color...");
            tsmiFillColor.Click += (sender, e) =>
            {
                PauseForm();

                ShapeType shapeType = CurrentShapeType;

                Color fillColor;

                if (shapeType == ShapeType.DrawingText)
                {
                    fillColor = AnnotationOptions.TextFillColor;
                }
                else
                {
                    fillColor = AnnotationOptions.FillColor;
                }

                using (ColorPickerForm dialogColor = new ColorPickerForm(fillColor))
                {
                    if (dialogColor.ShowDialog() == DialogResult.OK)
                    {
                        if (shapeType == ShapeType.DrawingText)
                        {
                            AnnotationOptions.TextFillColor = dialogColor.NewColor;
                        }
                        else
                        {
                            AnnotationOptions.FillColor = dialogColor.NewColor;
                        }

                        UpdateContextMenu();
                        UpdateCurrentShape();
                    }
                }

                ResumeForm();
            };
            cmsContextMenu.Items.Add(tsmiFillColor);

            tslnudRoundedRectangleRadius = new ToolStripLabeledNumericUpDown();
            tslnudRoundedRectangleRadius.LabeledNumericUpDownControl.Text         = "Corner radius:";
            tslnudRoundedRectangleRadius.LabeledNumericUpDownControl.Minimum      = 0;
            tslnudRoundedRectangleRadius.LabeledNumericUpDownControl.Maximum      = 150;
            tslnudRoundedRectangleRadius.LabeledNumericUpDownControl.Increment    = 3;
            tslnudRoundedRectangleRadius.LabeledNumericUpDownControl.ValueChanged = (sender, e) =>
            {
                AnnotationOptions.RoundedRectangleRadius = (int)tslnudRoundedRectangleRadius.LabeledNumericUpDownControl.Value;
                UpdateCurrentShape();
            };
            cmsContextMenu.Items.Add(tslnudRoundedRectangleRadius);

            tslnudBlurRadius = new ToolStripLabeledNumericUpDown();
            tslnudBlurRadius.LabeledNumericUpDownControl.Text         = "Blur radius:";
            tslnudBlurRadius.LabeledNumericUpDownControl.Minimum      = 2;
            tslnudBlurRadius.LabeledNumericUpDownControl.Maximum      = 100;
            tslnudBlurRadius.LabeledNumericUpDownControl.ValueChanged = (sender, e) =>
            {
                AnnotationOptions.BlurRadius = (int)tslnudBlurRadius.LabeledNumericUpDownControl.Value;
                UpdateCurrentShape();
            };
            cmsContextMenu.Items.Add(tslnudBlurRadius);

            tslnudPixelateSize = new ToolStripLabeledNumericUpDown();
            tslnudPixelateSize.LabeledNumericUpDownControl.Text         = "Pixel size:";
            tslnudPixelateSize.LabeledNumericUpDownControl.Minimum      = 2;
            tslnudPixelateSize.LabeledNumericUpDownControl.Maximum      = 100;
            tslnudPixelateSize.LabeledNumericUpDownControl.ValueChanged = (sender, e) =>
            {
                AnnotationOptions.PixelateSize = (int)tslnudPixelateSize.LabeledNumericUpDownControl.Value;
                UpdateCurrentShape();
            };
            cmsContextMenu.Items.Add(tslnudPixelateSize);

            tsmiHighlightColor        = new ToolStripMenuItem("Highlight color...");
            tsmiHighlightColor.Click += (sender, e) =>
            {
                PauseForm();

                using (ColorPickerForm dialogColor = new ColorPickerForm(AnnotationOptions.HighlightColor))
                {
                    if (dialogColor.ShowDialog() == DialogResult.OK)
                    {
                        AnnotationOptions.HighlightColor = dialogColor.NewColor;
                        UpdateContextMenu();
                        UpdateCurrentShape();
                    }
                }

                ResumeForm();
            };
            cmsContextMenu.Items.Add(tsmiHighlightColor);

            #endregion Shape options

            #region Capture

            cmsContextMenu.Items.Add(new ToolStripSeparator());

            ToolStripMenuItem tsmiFullscreenCapture = new ToolStripMenuItem("Capture fullscreen");
            tsmiFullscreenCapture.Image  = Resources.layer_fullscreen;
            tsmiFullscreenCapture.Click += (sender, e) => form.Close(RegionResult.Fullscreen);
            cmsContextMenu.Items.Add(tsmiFullscreenCapture);

            ToolStripMenuItem tsmiActiveMonitorCapture = new ToolStripMenuItem("Capture active monitor");
            tsmiActiveMonitorCapture.Image  = Resources.monitor;
            tsmiActiveMonitorCapture.Click += (sender, e) => form.Close(RegionResult.ActiveMonitor);
            cmsContextMenu.Items.Add(tsmiActiveMonitorCapture);

            ToolStripMenuItem tsmiMonitorCapture = new ToolStripMenuItem("Capture monitor");
            tsmiMonitorCapture.HideImageMargin();
            tsmiMonitorCapture.Image = Resources.monitor_window;
            cmsContextMenu.Items.Add(tsmiMonitorCapture);

            tsmiMonitorCapture.DropDownItems.Clear();

            Screen[] screens = Screen.AllScreens;

            for (int i = 0; i < screens.Length; i++)
            {
                Screen            screen = screens[i];
                ToolStripMenuItem tsmi   = new ToolStripMenuItem(string.Format("{0}. {1}x{2}", i + 1, screen.Bounds.Width, screen.Bounds.Height));
                int index = i;
                tsmi.Click += (sender, e) =>
                {
                    form.MonitorIndex = index;
                    form.Close(RegionResult.Monitor);
                };
                tsmiMonitorCapture.DropDownItems.Add(tsmi);
            }

            #endregion Capture

            #region Options

            cmsContextMenu.Items.Add(new ToolStripSeparator());

            ToolStripMenuItem tsmiOptions = new ToolStripMenuItem("Options");
            tsmiOptions.Image = Resources.gear;
            cmsContextMenu.Items.Add(tsmiOptions);

            ToolStripMenuItem tsmiQuickCrop = new ToolStripMenuItem("Multi region mode");
            tsmiQuickCrop.Checked      = !Config.QuickCrop;
            tsmiQuickCrop.CheckOnClick = true;
            tsmiQuickCrop.Click       += (sender, e) => Config.QuickCrop = !tsmiQuickCrop.Checked;
            tsmiOptions.DropDownItems.Add(tsmiQuickCrop);

            ToolStripMenuItem tsmiShowInfo = new ToolStripMenuItem("Show position and size info");
            tsmiShowInfo.Checked      = Config.ShowInfo;
            tsmiShowInfo.CheckOnClick = true;
            tsmiShowInfo.Click       += (sender, e) => Config.ShowInfo = tsmiShowInfo.Checked;
            tsmiOptions.DropDownItems.Add(tsmiShowInfo);

            ToolStripMenuItem tsmiShowMagnifier = new ToolStripMenuItem("Show magnifier");
            tsmiShowMagnifier.Checked      = Config.ShowMagnifier;
            tsmiShowMagnifier.CheckOnClick = true;
            tsmiShowMagnifier.Click       += (sender, e) => Config.ShowMagnifier = tsmiShowMagnifier.Checked;
            tsmiOptions.DropDownItems.Add(tsmiShowMagnifier);

            ToolStripMenuItem tsmiUseSquareMagnifier = new ToolStripMenuItem("Square shape magnifier");
            tsmiUseSquareMagnifier.Checked      = Config.UseSquareMagnifier;
            tsmiUseSquareMagnifier.CheckOnClick = true;
            tsmiUseSquareMagnifier.Click       += (sender, e) => Config.UseSquareMagnifier = tsmiUseSquareMagnifier.Checked;
            tsmiOptions.DropDownItems.Add(tsmiUseSquareMagnifier);

            ToolStripLabeledNumericUpDown tslnudMagnifierPixelCount = new ToolStripLabeledNumericUpDown();
            tslnudMagnifierPixelCount.LabeledNumericUpDownControl.Text         = "Magnifier pixel count:";
            tslnudMagnifierPixelCount.LabeledNumericUpDownControl.Minimum      = 1;
            tslnudMagnifierPixelCount.LabeledNumericUpDownControl.Maximum      = 35;
            tslnudMagnifierPixelCount.LabeledNumericUpDownControl.Increment    = 2;
            tslnudMagnifierPixelCount.LabeledNumericUpDownControl.Value        = Config.MagnifierPixelCount;
            tslnudMagnifierPixelCount.LabeledNumericUpDownControl.ValueChanged = (sender, e) => Config.MagnifierPixelCount = (int)tslnudMagnifierPixelCount.LabeledNumericUpDownControl.Value;
            tsmiOptions.DropDownItems.Add(tslnudMagnifierPixelCount);

            ToolStripLabeledNumericUpDown tslnudMagnifierPixelSize = new ToolStripLabeledNumericUpDown();
            tslnudMagnifierPixelSize.LabeledNumericUpDownControl.Text         = "Magnifier pixel size:";
            tslnudMagnifierPixelSize.LabeledNumericUpDownControl.Minimum      = 2;
            tslnudMagnifierPixelSize.LabeledNumericUpDownControl.Maximum      = 30;
            tslnudMagnifierPixelSize.LabeledNumericUpDownControl.Value        = Config.MagnifierPixelSize;
            tslnudMagnifierPixelSize.LabeledNumericUpDownControl.ValueChanged = (sender, e) => Config.MagnifierPixelSize = (int)tslnudMagnifierPixelSize.LabeledNumericUpDownControl.Value;
            tsmiOptions.DropDownItems.Add(tslnudMagnifierPixelSize);

            ToolStripMenuItem tsmiShowCrosshair = new ToolStripMenuItem("Show screen wide crosshair");
            tsmiShowCrosshair.Checked      = Config.ShowCrosshair;
            tsmiShowCrosshair.CheckOnClick = true;
            tsmiShowCrosshair.Click       += (sender, e) => Config.ShowCrosshair = tsmiShowCrosshair.Checked;
            tsmiOptions.DropDownItems.Add(tsmiShowCrosshair);

            ToolStripMenuItem tsmiShowFPS = new ToolStripMenuItem("Show FPS");
            tsmiShowFPS.Checked      = Config.ShowFPS;
            tsmiShowFPS.CheckOnClick = true;
            tsmiShowFPS.Click       += (sender, e) => Config.ShowFPS = tsmiShowFPS.Checked;
            tsmiOptions.DropDownItems.Add(tsmiShowFPS);

            #endregion Options

            CurrentShapeTypeChanged += shapeType => UpdateContextMenu();

            CurrentShapeChanged += shape => UpdateContextMenu();
        }
コード例 #39
0
        /**
         * @param circle
         * @return
         */

        public List <Shape> GetShapesByType(ShapeType circle)
        {
            // TODO: Implement
            return(shapes.Where(shape => shape.GetTypeOfShape() == circle).ToList());
        }
コード例 #40
0
 /// <summary>Initializes a new instance of the <see cref="Shape" /> class.</summary>
 /// <param name="shapeType">The shape type.</param>
 /// <param name="color">The color.</param>
 /// <param name="rounding">The rounding.</param>
 /// <param name="thickness">The thickness.</param>
 /// <param name="visible">The visibility.</param>
 public Shape(ShapeType shapeType, Color color, int rounding, int thickness, bool visible)
 {
     ConstructShape(shapeType, color, rounding, thickness, visible);
 }
コード例 #41
0
        protected virtual bool WriteShapeByTypeIfSupported(BinaryWriter dataOutput, IShape s, ShapeType type)
        {
            switch (type)
            {
            case ShapeType.TYPE_POINT: WritePoint(dataOutput, (IPoint)s); break;

            case ShapeType.TYPE_RECT: WriteRect(dataOutput, (IRectangle)s); break;

            case ShapeType.TYPE_CIRCLE: WriteCircle(dataOutput, (ICircle)s); break;

            case ShapeType.TYPE_COLL: WriteCollection(dataOutput, (ShapeCollection)s); break;

            default:
                return(false);
            }
            return(true);
        }
コード例 #42
0
ファイル: Program.cs プロジェクト: IvanRyzhankov/TestRepo
        static void ShowSizesHypotheticalCalculations(GeometricPatameter hypotheticalResultParam, TypeOfOperation typeOfOperation, ShapeType typeOfShape)
        {
            switch (typeOfShape)
            {
            case ShapeType.Triangle:

                Console.WriteLine($"Hypothetical radius of {ShapeType.Circle} is {hypotheticalResultParam.Radius}");
                Console.WriteLine($"the side of this {ShapeType.Quadrangle} is {hypotheticalResultParam.SideOfQuadrangle}");
                break;

            case ShapeType.Quadrangle:

                Console.WriteLine($"Hypothetical radius of {ShapeType.Circle} is {hypotheticalResultParam.Radius}");
                Console.WriteLine($"Hypothetical side of {ShapeType.Triangle} is {hypotheticalResultParam.SideOfTriangle}");
                break;

            case ShapeType.Circle:

                Console.WriteLine($"Hypothetical side of {ShapeType.Quadrangle} is {hypotheticalResultParam.SideOfQuadrangle}");
                Console.WriteLine($"Hypothetical side of {ShapeType.Triangle} is {hypotheticalResultParam.SideOfTriangle}");
                break;
            }
        }
コード例 #43
0
ファイル: DragHitShape.cs プロジェクト: wwwK/AsteroidMiner
 public void SetShape_Mesh(IEnumerable <ITriangle> triangles)
 {
     _shape     = ShapeType.Mesh;
     _triangles = triangles.ToArray();
 }
コード例 #44
0
ファイル: Program.cs プロジェクト: IvanRyzhankov/TestRepo
        static void ShowSizesCalculations(double result, TypeOfOperation typeOfOperation, ShapeType typeOfShape)
        {
            Console.Clear();

            switch (typeOfOperation)
            {
            case TypeOfOperation.Perimeter:
                Console.WriteLine($"the perimeter of this {typeOfShape} is {result}\n" + "");
                break;

            case TypeOfOperation.Square:
                Console.WriteLine($"the area of this {typeOfShape} is {result}\n" + "");
                break;
            }
        }
コード例 #45
0
ファイル: DragHitShape.cs プロジェクト: wwwK/AsteroidMiner
 public void SetShape_Plane(ITriangle plane)
 {
     _shape = ShapeType.Plane;
     _plane = plane;
 }
コード例 #46
0
        private void GetInput(float elapsed, KeyboardState keyboardState)
        {
            if (_currentGameState == GameState.GameOver || _currentGameState == GameState.GameComplete)
            {
                if (keyboardState.IsKeyDown(Keys.Enter))
                {
                    _currentGameState = GameState.AboutToStart;
                    _currentLevel     = 1;
                    _autoFallInterval = InitialAutoFallInterval;
                    _currentScore     = 0;

                    NewGame(_currentLevel);
                }
            }
            else if (_currentGameState != GameState.AboutToStart)
            {
                if (keyboardState.IsKeyDown(Keys.Right))
                {
                    _keyboardLeftRightTimer += elapsed;
                    if (_keyboardLeftRightTimer > 0.15F)
                    {
                        _currentShape.X++;
                        if (_board.IsSidesCollision(_currentShape))
                        {
                            _currentShape.X--;
                        }

                        _keyboardLeftRightTimer = 0;
                    }
                }
                else if (keyboardState.IsKeyDown(Keys.Left))
                {
                    _keyboardLeftRightTimer += elapsed;
                    if (_keyboardLeftRightTimer > 0.15F)
                    {
                        _currentShape.X--;
                        if (_board.IsSidesCollision(_currentShape))
                        {
                            _currentShape.X++;
                        }

                        _keyboardLeftRightTimer = 0;
                    }
                }
                else if (keyboardState.IsKeyDown(Keys.Down) && !_removingLines)
                {
                    _keyboardDownTimer += elapsed;
                    if (_keyboardDownTimer > 0.04F)
                    {
                        MoveShapeDown();

                        _keyboardDownTimer = 0;
                    }
                }
                else if (keyboardState.IsKeyDown(Keys.Up))
                {
                    _keyboardLeftRightTimer += elapsed;
                    if (_keyboardLeftRightTimer > 0.15F)
                    {
                        if (_board.CanRotateShape(_currentShape))
                        {
                            _currentShape.Rotate();
                        }

                        _keyboardLeftRightTimer = 0;
                    }
                }
                else if (keyboardState.IsKeyDown(Keys.Space))
                {
                    _keyboardLeftRightTimer += elapsed;
                    if (_keyboardLeftRightTimer > 0.15F)
                    {
                        ShapeType currentShape = _currentShape.ShapeType;
                        currentShape += 1;
                        currentShape  = (ShapeType)((int)currentShape % 7);

                        _currentShape.ChangeActualShape(currentShape);

                        _keyboardLeftRightTimer = 0;
                    }
                }
                else
                {
                    _keyboardLeftRightTimer = 0.9F;
                    _keyboardDownTimer      = 0.9F;
                }
            }
        }
コード例 #47
0
ファイル: DragHitShape.cs プロジェクト: wwwK/AsteroidMiner
 public void SetShape_Lines(IEnumerable <RayHitTestParameters> lines)
 {
     _shape = ShapeType.Lines;
     _lines = lines.ToArray();
 }
コード例 #48
0
 protected Shape3D(ShapeType shapeType, Shape2D baseShape, double height)
     : base(shapeType)
 {
     _baseShape = baseShape;
     _height    = height;
 }
コード例 #49
0
ファイル: ShapeManagerMenu.cs プロジェクト: selmen2004/ShareX
        private void UpdateMenu()
        {
            if (menuForm == null)
            {
                return;
            }

            ShapeType shapeType = CurrentShapeType;

            foreach (ToolStripButton tsb in tsMain.Items.OfType <ToolStripButton>().Where(x => x.Tag is ShapeType))
            {
                if ((ShapeType)tsb.Tag == shapeType)
                {
                    tsb.RadioCheck();
                    break;
                }
            }

            Color borderColor;

            if (shapeType == ShapeType.DrawingTextBackground || shapeType == ShapeType.DrawingSpeechBalloon)
            {
                borderColor = AnnotationOptions.TextBorderColor;
            }
            else if (shapeType == ShapeType.DrawingTextOutline)
            {
                borderColor = AnnotationOptions.TextOutlineBorderColor;
            }
            else if (shapeType == ShapeType.DrawingStep)
            {
                borderColor = AnnotationOptions.StepBorderColor;
            }
            else
            {
                borderColor = AnnotationOptions.BorderColor;
            }

            if (tsbBorderColor.Image != null)
            {
                tsbBorderColor.Image.Dispose();
            }
            tsbBorderColor.Image = ImageHelpers.CreateColorPickerIcon(borderColor, new Rectangle(0, 0, 16, 16), 8);

            int borderSize;

            if (shapeType == ShapeType.DrawingTextBackground || shapeType == ShapeType.DrawingSpeechBalloon)
            {
                borderSize = AnnotationOptions.TextBorderSize;
            }
            else if (shapeType == ShapeType.DrawingTextOutline)
            {
                borderSize = AnnotationOptions.TextOutlineBorderSize;
            }
            else if (shapeType == ShapeType.DrawingStep)
            {
                borderSize = AnnotationOptions.StepBorderSize;
            }
            else
            {
                borderSize = AnnotationOptions.BorderSize;
            }

            tslnudBorderSize.Content.Value = borderSize;

            Color fillColor;

            if (shapeType == ShapeType.DrawingTextBackground || shapeType == ShapeType.DrawingSpeechBalloon)
            {
                fillColor = AnnotationOptions.TextFillColor;
            }
            else if (shapeType == ShapeType.DrawingStep)
            {
                fillColor = AnnotationOptions.StepFillColor;
            }
            else
            {
                fillColor = AnnotationOptions.FillColor;
            }

            if (tsbFillColor.Image != null)
            {
                tsbFillColor.Image.Dispose();
            }
            tsbFillColor.Image = ImageHelpers.CreateColorPickerIcon(fillColor, new Rectangle(0, 0, 16, 16));

            int cornerRadius = 0;

            if (shapeType == ShapeType.RegionRectangle)
            {
                cornerRadius = AnnotationOptions.RegionCornerRadius;
            }
            else if (shapeType == ShapeType.DrawingRectangle || shapeType == ShapeType.DrawingTextBackground)
            {
                cornerRadius = AnnotationOptions.DrawingCornerRadius;
            }

            tslnudCornerRadius.Content.Value = cornerRadius;

            tslnudBlurRadius.Content.Value = AnnotationOptions.BlurRadius;

            tslnudPixelateSize.Content.Value = AnnotationOptions.PixelateSize;

            if (tsbHighlightColor.Image != null)
            {
                tsbHighlightColor.Image.Dispose();
            }
            tsbHighlightColor.Image = ImageHelpers.CreateColorPickerIcon(AnnotationOptions.HighlightColor, new Rectangle(0, 0, 16, 16));

            tsmiShadow.Checked = AnnotationOptions.Shadow;

            switch (shapeType)
            {
            default:
                tsddbShapeOptions.Visible = false;
                break;

            case ShapeType.RegionRectangle:
            case ShapeType.DrawingRectangle:
            case ShapeType.DrawingEllipse:
            case ShapeType.DrawingFreehand:
            case ShapeType.DrawingLine:
            case ShapeType.DrawingArrow:
            case ShapeType.DrawingTextOutline:
            case ShapeType.DrawingTextBackground:
            case ShapeType.DrawingSpeechBalloon:
            case ShapeType.DrawingStep:
            case ShapeType.EffectBlur:
            case ShapeType.EffectPixelate:
                tsddbShapeOptions.Visible = true;
                break;
            }

            tsmiUndo.Enabled   = tsmiDeleteAll.Enabled = Shapes.Count > 0;
            tsmiDelete.Enabled = tsmiMoveTop.Enabled = tsmiMoveUp.Enabled = tsmiMoveDown.Enabled = tsmiMoveBottom.Enabled = CurrentShape != null;

            switch (shapeType)
            {
            default:
                tsbBorderColor.Visible   = false;
                tslnudBorderSize.Visible = false;
                tsmiShadow.Visible       = false;
                break;

            case ShapeType.DrawingRectangle:
            case ShapeType.DrawingEllipse:
            case ShapeType.DrawingFreehand:
            case ShapeType.DrawingLine:
            case ShapeType.DrawingArrow:
            case ShapeType.DrawingTextOutline:
            case ShapeType.DrawingTextBackground:
            case ShapeType.DrawingSpeechBalloon:
            case ShapeType.DrawingStep:
                tsbBorderColor.Visible   = true;
                tslnudBorderSize.Visible = true;
                tsmiShadow.Visible       = true;
                break;
            }

            switch (shapeType)
            {
            default:
                tsbFillColor.Visible = false;
                break;

            case ShapeType.DrawingRectangle:
            case ShapeType.DrawingEllipse:
            case ShapeType.DrawingTextBackground:
            case ShapeType.DrawingSpeechBalloon:
            case ShapeType.DrawingStep:
                tsbFillColor.Visible = true;
                break;
            }

            switch (shapeType)
            {
            default:
                tslnudCornerRadius.Visible = false;
                break;

            case ShapeType.RegionRectangle:
            case ShapeType.DrawingRectangle:
            case ShapeType.DrawingTextBackground:
                tslnudCornerRadius.Visible = true;
                break;
            }

            tslnudBlurRadius.Visible   = shapeType == ShapeType.EffectBlur;
            tslnudPixelateSize.Visible = shapeType == ShapeType.EffectPixelate;
            tsbHighlightColor.Visible  = shapeType == ShapeType.EffectHighlight;

            if (tsmiRegionCapture != null)
            {
                tsmiRegionCapture.Visible = !Config.QuickCrop && ValidRegions.Length > 0;
            }
        }
コード例 #50
0
//
//	void OnDisable()
//	{
//
//	}
//
//	void OnDestroy()
//	{
//
//	}

    #endregion

    #region Public Methods
    public void updateMesh(ShapeType shape, float degree, float radius, float innerOff = 2)
    {
        if (shape == ShapeType.sector)
        {
            if (mesh == null)
            {
                mesh = new Mesh();
            }
            meshFilter = GetComponent <MeshFilter>();
            meshRender = GetComponent <MeshRenderer>();

            int     i;
            float   beginDegree;
            float   endDegree;
            float   beginRadian;
            float   endRadian;
            float   uvRadius = 0.5f;
            Vector2 uvCenter = new Vector2(0.5f, 0.5f);
            float   currentIntervalDegree = 0;
            float   limitDegree;
            int     count;

            float beginCos;
            float beginSin;
            float endCos;
            float endSin;

            int beginNumber;
            int endNumber;
            int triangleNumber;

            currentIntervalDegree = Mathf.Abs(m_intervalDegree);

            count = (int)(Mathf.Abs(degree) / currentIntervalDegree);
            if (degree % m_intervalDegree != 0)
            {
                ++count;
            }
            if (degree < 0)
            {
                currentIntervalDegree = -currentIntervalDegree;
            }

            if (lastCount != count || shape != m_type)
            {
                mesh.Clear();
                vertices    = new Vector3[count * 2 + 1];
                triangles   = new int[count * 3];
                uvs         = new Vector2[count * 2 + 1];
                vertices[0] = Vector3.zero;
                uvs[0]      = uvCenter;
                lastCount   = count;
            }

            i = 0;
            //		beginDegree = beginOffsetDegree;
            //		limitDegree = degree + beginOffsetDegree;
            beginDegree = 90 - degree / 2;
            limitDegree = degree + beginDegree;

            while (i < count)
            {
                endDegree = beginDegree + currentIntervalDegree;

                if (degree > 0)
                {
                    if (endDegree > limitDegree)
                    {
                        endDegree = limitDegree;
                    }
                }
                else
                {
                    if (endDegree < limitDegree)
                    {
                        endDegree = limitDegree;
                    }
                }

                beginRadian = Mathf.Deg2Rad * beginDegree;
                endRadian   = Mathf.Deg2Rad * endDegree;

                beginCos = Mathf.Cos(beginRadian);
                beginSin = Mathf.Sin(beginRadian);
                endCos   = Mathf.Cos(endRadian);
                endSin   = Mathf.Sin(endRadian);

                beginNumber    = i * 2 + 1;
                endNumber      = i * 2 + 2;
                triangleNumber = i * 3;

                vertices[beginNumber].x = beginCos * radius;
                vertices[beginNumber].y = 0;
                vertices[beginNumber].z = beginSin * radius;
                vertices[endNumber].x   = endCos * radius;
                vertices[endNumber].y   = 0;
                vertices[endNumber].z   = endSin * radius;

                triangles[triangleNumber] = 0;
                if (degree > 0)
                {
                    triangles[triangleNumber + 1] = endNumber;
                    triangles[triangleNumber + 2] = beginNumber;
                }
                else
                {
                    triangles[triangleNumber + 1] = beginNumber;
                    triangles[triangleNumber + 2] = endNumber;
                }

                if (radius > 0)
                {
                    uvs[beginNumber].x = beginCos * uvRadius + uvCenter.x;
                    uvs[beginNumber].y = beginSin * uvRadius + uvCenter.y;
                    uvs[endNumber].x   = endCos * uvRadius + uvCenter.x;
                    uvs[endNumber].y   = endSin * uvRadius + uvCenter.y;
                }
                else
                {
                    uvs[beginNumber].x = -beginCos * uvRadius + uvCenter.x;
                    uvs[beginNumber].y = -beginSin * uvRadius + uvCenter.y;
                    uvs[endNumber].x   = -endCos * uvRadius + uvCenter.x;
                    uvs[endNumber].y   = -endSin * uvRadius + uvCenter.y;
                }

                beginDegree += currentIntervalDegree;
                ++i;
            }

            mesh.vertices  = vertices;
            mesh.triangles = triangles;
            mesh.uv        = uvs;

            mesh.RecalculateNormals();
            mesh.RecalculateBounds();

            meshFilter.sharedMesh      = mesh;
            meshFilter.sharedMesh.name = "CircularSectorMesh";

            m_degree = degree;
            m_radius = radius;

            meshRender.sharedMaterial = m_circleIndicator;
        }
        else if (shape == ShapeType.obb)
        {
            if (mesh == null)
            {
                mesh = new Mesh();
            }
            meshFilter = GetComponent <MeshFilter>();
            meshRender = GetComponent <MeshRenderer>();

            Vector2 uvCenter = new Vector2(0.5f, 0.5f);
            mesh.Clear();
            vertices    = new Vector3[4];
            triangles   = new int[6];
            uvs         = new Vector2[4];
            vertices[0] = Vector3.zero;
            uvs[0]      = uvCenter;

            vertices[0] = new Vector3(degree, 0, 0);       //1,0
            vertices[1] = new Vector3(degree, 0, radius);  //1,1
            vertices[2] = new Vector3(-degree, 0, radius); //-1,-1
            vertices[3] = new Vector3(-degree, 0, 0);      //-1,0

            triangles[0] = 3;
            triangles[1] = 2;
            triangles[2] = 0;
            triangles[3] = 0;
            triangles[4] = 2;
            triangles[5] = 1;

            uvs[0] = new Vector2(0, 1);
            uvs[1] = new Vector2(0, 0);
            uvs[2] = new Vector2(1, 0);
            uvs[3] = new Vector2(1, 1);

            mesh.vertices              = vertices;
            mesh.triangles             = triangles;
            mesh.uv                    = uvs;
            meshFilter.sharedMesh      = mesh;
            meshFilter.sharedMesh.name = "CircularSectorMesh";;
            meshRender.sharedMaterial  = m_RectIndicator;

            m_degree = degree;
            m_radius = radius;
        }
        else if (shape == ShapeType.ring)
        {
            if (mesh == null)
            {
                mesh = new Mesh();
            }
            meshFilter = GetComponent <MeshFilter>();
            meshRender = GetComponent <MeshRenderer>();

            int     i;
            float   beginDegree;
            float   endDegree;
            float   beginRadian;
            float   endRadian;
            float   uvRadius = 0.5f;
            Vector2 uvCenter = new Vector2(0.5f, 0.5f);
            float   currentIntervalDegree = 0;
            float   limitDegree;
            int     count;

            float beginCos;
            float beginSin;
            float endCos;
            float endSin;

            int beginNumber;
            int beginMiddleNumber;
            int endNumber;
            int endMiddleNumber;
            int triangleNumber;
            int triangleAddition;

            currentIntervalDegree = Mathf.Abs(m_intervalDegree);

            count = (int)(Mathf.Abs(degree) / currentIntervalDegree);
            if (degree % m_intervalDegree != 0)
            {
                ++count;
            }
            if (degree < 0)
            {
                currentIntervalDegree = -currentIntervalDegree;
            }

            if (lastCount != count || m_type != shape)
            {
                mesh.Clear();
                vertices    = new Vector3[count * 2 * 2 + 1];
                triangles   = new int[count * 3 * 2];
                uvs         = new Vector2[count * 2 * 2 + 1];
                vertices[0] = Vector3.zero;
                uvs[0]      = uvCenter;
                lastCount   = count;
            }

            i = 0;
            //		beginDegree = beginOffsetDegree;
            //		limitDegree = degree + beginOffsetDegree;
            beginDegree = 90 - degree / 2;
            limitDegree = degree + beginDegree;

            while (i < count)
            {
                endDegree = beginDegree + currentIntervalDegree;

                if (degree > 0)
                {
                    if (endDegree > limitDegree)
                    {
                        endDegree = limitDegree;
                    }
                }
                else
                {
                    if (endDegree < limitDegree)
                    {
                        endDegree = limitDegree;
                    }
                }

                beginRadian = Mathf.Deg2Rad * beginDegree;
                endRadian   = Mathf.Deg2Rad * endDegree;

                beginCos = Mathf.Cos(beginRadian);
                beginSin = Mathf.Sin(beginRadian);
                endCos   = Mathf.Cos(endRadian);
                endSin   = Mathf.Sin(endRadian);

                beginMiddleNumber = i * 2 * 2 + 1;
                beginNumber       = i * 2 * 2 + 1 + 1;
                endNumber         = i * 2 * 2 + 2 + 1;
                endMiddleNumber   = i * 2 * 2 + 3 + 1;
                triangleNumber    = i * 3 * 2;
                triangleAddition  = i * 3 * 2 + 3;

                vertices[beginMiddleNumber].x = beginCos * innerOff;
                vertices[beginMiddleNumber].y = 0;
                vertices[beginMiddleNumber].z = beginSin * innerOff;

                vertices[beginNumber].x = beginCos * radius;
                vertices[beginNumber].y = 0;
                vertices[beginNumber].z = beginSin * radius;

                vertices[endNumber].x = endCos * radius;
                vertices[endNumber].y = 0;
                vertices[endNumber].z = endSin * radius;

                vertices[endMiddleNumber].x = endCos * innerOff;
                vertices[endMiddleNumber].y = 0;
                vertices[endMiddleNumber].z = endSin * innerOff;

                triangles[triangleNumber] = beginMiddleNumber;
                if (degree > 0)
                {
                    triangles[triangleNumber + 1] = endNumber;
                    triangles[triangleNumber + 2] = beginNumber;
                }
                else
                {
                    triangles[triangleNumber + 1] = beginNumber;
                    triangles[triangleNumber + 2] = endNumber;
                }

                triangles[triangleAddition] = endMiddleNumber;
                if (degree > 0)
                {
                    triangles[triangleAddition + 1] = endNumber;
                    triangles[triangleAddition + 2] = beginMiddleNumber;
                }
                else
                {
                    triangles[triangleAddition + 1] = beginMiddleNumber;
                    triangles[triangleAddition + 2] = endNumber;
                }

                if (radius > 0)
                {
                    uvs[beginNumber].x = beginCos * uvRadius + uvCenter.x;
                    uvs[beginNumber].y = beginSin * uvRadius + uvCenter.y;

                    uvs[beginMiddleNumber].x = beginCos * uvRadius * innerOff / radius + uvCenter.x;
                    uvs[beginMiddleNumber].y = beginSin * uvRadius * innerOff / radius + uvCenter.y;

                    uvs[endNumber].x = endCos * uvRadius + uvCenter.x;
                    uvs[endNumber].y = endSin * uvRadius + uvCenter.y;

                    uvs[endMiddleNumber].x = endCos * uvRadius * innerOff / radius + uvCenter.x;
                    uvs[endMiddleNumber].y = endSin * uvRadius * innerOff / radius + uvCenter.y;
                }
                else
                {
                    uvs[beginNumber].x = -beginCos * uvRadius + uvCenter.x;
                    uvs[beginNumber].y = -beginSin * uvRadius + uvCenter.y;

                    uvs[beginMiddleNumber].x = -beginCos * uvRadius * innerOff / radius + uvCenter.x;
                    uvs[beginMiddleNumber].y = -beginSin * uvRadius * innerOff / radius + uvCenter.y;

                    uvs[endNumber].x = -endCos * uvRadius + uvCenter.x;
                    uvs[endNumber].y = -endSin * uvRadius + uvCenter.y;

                    uvs[endMiddleNumber].x = -endCos * uvRadius * innerOff / radius + uvCenter.x;
                    uvs[endMiddleNumber].y = -endSin * uvRadius * innerOff / radius + uvCenter.y;
                }

                beginDegree += currentIntervalDegree;
                ++i;
            }
            mesh.vertices  = vertices;
            mesh.triangles = triangles;
            mesh.uv        = uvs;

            //			mesh.RecalculateNormals();
            //			mesh.RecalculateBounds();

            meshFilter.sharedMesh      = mesh;
            meshFilter.sharedMesh.name = "CircularSectorMesh";

            m_degree = degree;
            m_radius = radius;

            meshRender.sharedMaterial = m_circleIndicator;
        }
        m_type = shape;
    }
コード例 #51
0
ファイル: ShapeManagerMenu.cs プロジェクト: selmen2004/ShareX
        private void CreateToolbar()
        {
            menuForm = new Form()
            {
                AutoScaleDimensions = new SizeF(6F, 13F),
                AutoScaleMode       = AutoScaleMode.Font,
                AutoSize            = true,
                AutoSizeMode        = AutoSizeMode.GrowAndShrink,
                ClientSize          = new Size(759, 509),
                FormBorderStyle     = FormBorderStyle.None,
                Location            = new Point(200, 200),
                ShowInTaskbar       = false,
                StartPosition       = FormStartPosition.Manual,
                Text    = "ShareX - Region capture menu",
                TopMost = true
            };

            menuForm.KeyDown         += MenuForm_KeyDown;
            menuForm.KeyUp           += MenuForm_KeyUp;
            menuForm.LocationChanged += MenuForm_LocationChanged;

            menuForm.SuspendLayout();

            tsMain = new ToolStripEx()
            {
                AutoSize         = true,
                CanOverflow      = false,
                ClickThrough     = true,
                Dock             = DockStyle.None,
                GripStyle        = ToolStripGripStyle.Hidden,
                Location         = new Point(0, 0),
                MinimumSize      = new Size(10, 30),
                Padding          = new Padding(0, 0, 0, 0),
                Renderer         = new CustomToolStripProfessionalRenderer(),
                TabIndex         = 0,
                ShowItemToolTips = false
            };

            tsMain.MouseLeave += TsMain_MouseLeave;

            tsMain.SuspendLayout();

            // https://www.medo64.com/2014/01/scaling-toolstrip-with-dpi/
            using (Graphics g = menuForm.CreateGraphics())
            {
                double scale    = Math.Max(g.DpiX, g.DpiY) / 96.0;
                double newScale = ((int)Math.Floor(scale * 100) / 25 * 25) / 100.0;
                if (newScale > 1)
                {
                    int newWidth  = (int)(tsMain.ImageScalingSize.Width * newScale);
                    int newHeight = (int)(tsMain.ImageScalingSize.Height * newScale);
                    tsMain.ImageScalingSize = new Size(newWidth, newHeight);
                }
            }

            menuForm.Controls.Add(tsMain);

            tslDragLeft = new ToolStripLabel()
            {
                DisplayStyle = ToolStripItemDisplayStyle.Image,
                Image        = Resources.ui_radio_button_uncheck,
                Margin       = new Padding(2, 0, 2, 0),
                Padding      = new Padding(2)
            };

            tsMain.Items.Add(tslDragLeft);

            if (form.IsEditorMode)
            {
                #region Editor mode

                ToolStripButton tsbCompleteEdit = new ToolStripButton();

                if (form.Mode == RegionCaptureMode.Editor)
                {
                    tsbCompleteEdit.Text = "Run after capture tasks";
                }
                else
                {
                    tsbCompleteEdit.Text = "Apply changes & continue task (Enter)";
                }

                tsbCompleteEdit.DisplayStyle = ToolStripItemDisplayStyle.Image;
                tsbCompleteEdit.Image        = Resources.tick;
                tsbCompleteEdit.MouseDown   += (sender, e) => form.Close(RegionResult.AnnotateRunAfterCaptureTasks);
                tsMain.Items.Add(tsbCompleteEdit);

                if (form.Mode == RegionCaptureMode.TaskEditor)
                {
                    ToolStripButton tsbClose = new ToolStripButton("Continue task (Space or right click)");
                    tsbClose.DisplayStyle = ToolStripItemDisplayStyle.Image;
                    tsbClose.Image        = Resources.control;
                    tsbClose.MouseDown   += (sender, e) => form.Close(RegionResult.AnnotateContinueTask);
                    tsMain.Items.Add(tsbClose);

                    ToolStripButton tsbCloseCancel = new ToolStripButton("Cancel task (Esc)");
                    tsbCloseCancel.DisplayStyle = ToolStripItemDisplayStyle.Image;
                    tsbCloseCancel.Image        = Resources.cross;
                    tsbCloseCancel.MouseDown   += (sender, e) => form.Close(RegionResult.AnnotateCancelTask);
                    tsMain.Items.Add(tsbCloseCancel);
                }

                if (form.Mode == RegionCaptureMode.TaskEditor)
                {
                    tsMain.Items.Add(new ToolStripSeparator());
                }

                ToolStripButton tsbSaveImage = new ToolStripButton("Save image");
                tsbSaveImage.DisplayStyle = ToolStripItemDisplayStyle.Image;
                tsbSaveImage.Enabled      = File.Exists(form.ImageFilePath);
                tsbSaveImage.Image        = Resources.disk_black;
                tsbSaveImage.MouseDown   += (sender, e) => form.Close(RegionResult.AnnotateSaveImage);
                tsMain.Items.Add(tsbSaveImage);

                ToolStripButton tsbSaveImageAs = new ToolStripButton("Save image as...");
                tsbSaveImageAs.DisplayStyle = ToolStripItemDisplayStyle.Image;
                tsbSaveImageAs.Image        = Resources.disks_black;
                tsbSaveImageAs.MouseDown   += (sender, e) => form.Close(RegionResult.AnnotateSaveImageAs);
                tsMain.Items.Add(tsbSaveImageAs);

                ToolStripButton tsbCopyImage = new ToolStripButton("Copy image to clipboard");
                tsbCopyImage.DisplayStyle = ToolStripItemDisplayStyle.Image;
                tsbCopyImage.Image        = Resources.clipboard;
                tsbCopyImage.MouseDown   += (sender, e) => form.Close(RegionResult.AnnotateCopyImage);
                tsMain.Items.Add(tsbCopyImage);

                ToolStripButton tsbUploadImage = new ToolStripButton("Upload image");
                tsbUploadImage.DisplayStyle = ToolStripItemDisplayStyle.Image;
                tsbUploadImage.Image        = Resources.drive_globe;
                tsbUploadImage.MouseDown   += (sender, e) => form.Close(RegionResult.AnnotateUploadImage);
                tsMain.Items.Add(tsbUploadImage);

                ToolStripButton tsbPrintImage = new ToolStripButton("Print image...");
                tsbPrintImage.DisplayStyle = ToolStripItemDisplayStyle.Image;
                tsbPrintImage.Image        = Resources.printer;
                tsbPrintImage.MouseDown   += (sender, e) => form.Close(RegionResult.AnnotatePrintImage);
                tsMain.Items.Add(tsbPrintImage);

                tsMain.Items.Add(new ToolStripSeparator());

                #endregion Editor mode
            }

            #region Tools

            foreach (ShapeType shapeType in Helpers.GetEnums <ShapeType>())
            {
                if (form.IsEditorMode)
                {
                    if (IsShapeTypeRegion(shapeType))
                    {
                        continue;
                    }
                }
                else if (shapeType == ShapeType.DrawingRectangle)
                {
                    tsMain.Items.Add(new ToolStripSeparator());
                }

                ToolStripButton tsbShapeType = new ToolStripButton(shapeType.GetLocalizedDescription());
                tsbShapeType.DisplayStyle = ToolStripItemDisplayStyle.Image;

                Image img = null;

                switch (shapeType)
                {
                case ShapeType.RegionRectangle:
                    img = Resources.layer_shape_region;
                    break;

                case ShapeType.RegionEllipse:
                    img = Resources.layer_shape_ellipse_region;
                    break;

                case ShapeType.RegionFreehand:
                    img = Resources.layer_shape_polygon;
                    break;

                case ShapeType.DrawingRectangle:
                    img = Resources.layer_shape;
                    break;

                case ShapeType.DrawingEllipse:
                    img = Resources.layer_shape_ellipse;
                    break;

                case ShapeType.DrawingFreehand:
                    img = Resources.pencil;
                    break;

                case ShapeType.DrawingLine:
                    img = Resources.layer_shape_line;
                    break;

                case ShapeType.DrawingArrow:
                    img = Resources.layer_shape_arrow;
                    break;

                case ShapeType.DrawingTextOutline:
                    img = Resources.edit_outline;
                    break;

                case ShapeType.DrawingTextBackground:
                    img = Resources.edit_shade;
                    break;

                case ShapeType.DrawingSpeechBalloon:
                    img = Resources.balloon_box_left;
                    break;

                case ShapeType.DrawingStep:
                    img = Resources.counter_reset;
                    break;

                case ShapeType.DrawingImage:
                    img = Resources.image;
                    break;

                case ShapeType.EffectBlur:
                    img = Resources.layer_shade;
                    break;

                case ShapeType.EffectPixelate:
                    img = Resources.grid;
                    break;

                case ShapeType.EffectHighlight:
                    img = Resources.highlighter_text;
                    break;
                }

                tsbShapeType.Image   = img;
                tsbShapeType.Checked = shapeType == CurrentShapeType;
                tsbShapeType.Tag     = shapeType;

                tsbShapeType.MouseDown += (sender, e) =>
                {
                    tsbShapeType.RadioCheck();
                    CurrentShapeType = shapeType;
                };

                tsMain.Items.Add(tsbShapeType);
            }

            #endregion Tools

            #region Shape options

            tsMain.Items.Add(new ToolStripSeparator());

            tsbBorderColor = new ToolStripButton(Resources.ShapeManager_CreateContextMenu_Border_color___);
            tsbBorderColor.DisplayStyle = ToolStripItemDisplayStyle.Image;
            tsbBorderColor.Click       += (sender, e) =>
            {
                PauseForm();

                ShapeType shapeType = CurrentShapeType;

                Color borderColor;

                if (shapeType == ShapeType.DrawingTextBackground || shapeType == ShapeType.DrawingSpeechBalloon)
                {
                    borderColor = AnnotationOptions.TextBorderColor;
                }
                else if (shapeType == ShapeType.DrawingTextOutline)
                {
                    borderColor = AnnotationOptions.TextOutlineBorderColor;
                }
                else if (shapeType == ShapeType.DrawingStep)
                {
                    borderColor = AnnotationOptions.StepBorderColor;
                }
                else
                {
                    borderColor = AnnotationOptions.BorderColor;
                }

                using (ColorPickerForm dialogColor = new ColorPickerForm(borderColor))
                {
                    if (dialogColor.ShowDialog() == DialogResult.OK)
                    {
                        if (shapeType == ShapeType.DrawingTextBackground || shapeType == ShapeType.DrawingSpeechBalloon)
                        {
                            AnnotationOptions.TextBorderColor = dialogColor.NewColor;
                        }
                        else if (shapeType == ShapeType.DrawingTextOutline)
                        {
                            AnnotationOptions.TextOutlineBorderColor = dialogColor.NewColor;
                        }
                        else if (shapeType == ShapeType.DrawingStep)
                        {
                            AnnotationOptions.StepBorderColor = dialogColor.NewColor;
                        }
                        else
                        {
                            AnnotationOptions.BorderColor = dialogColor.NewColor;
                        }

                        UpdateMenu();
                        UpdateCurrentShape();
                    }
                }

                ResumeForm();
            };
            tsMain.Items.Add(tsbBorderColor);

            tsbFillColor = new ToolStripButton(Resources.ShapeManager_CreateContextMenu_Fill_color___);
            tsbFillColor.DisplayStyle = ToolStripItemDisplayStyle.Image;
            tsbFillColor.Click       += (sender, e) =>
            {
                PauseForm();

                ShapeType shapeType = CurrentShapeType;

                Color fillColor;

                if (shapeType == ShapeType.DrawingTextBackground || shapeType == ShapeType.DrawingSpeechBalloon)
                {
                    fillColor = AnnotationOptions.TextFillColor;
                }
                else if (shapeType == ShapeType.DrawingStep)
                {
                    fillColor = AnnotationOptions.StepFillColor;
                }
                else
                {
                    fillColor = AnnotationOptions.FillColor;
                }

                using (ColorPickerForm dialogColor = new ColorPickerForm(fillColor))
                {
                    if (dialogColor.ShowDialog() == DialogResult.OK)
                    {
                        if (shapeType == ShapeType.DrawingTextBackground || shapeType == ShapeType.DrawingSpeechBalloon)
                        {
                            AnnotationOptions.TextFillColor = dialogColor.NewColor;
                        }
                        else if (shapeType == ShapeType.DrawingStep)
                        {
                            AnnotationOptions.StepFillColor = dialogColor.NewColor;
                        }
                        else
                        {
                            AnnotationOptions.FillColor = dialogColor.NewColor;
                        }

                        UpdateMenu();
                        UpdateCurrentShape();
                    }
                }

                ResumeForm();
            };
            tsMain.Items.Add(tsbFillColor);

            tsbHighlightColor = new ToolStripButton(Resources.ShapeManager_CreateContextMenu_Highlight_color___);
            tsbHighlightColor.DisplayStyle = ToolStripItemDisplayStyle.Image;
            tsbHighlightColor.Click       += (sender, e) =>
            {
                PauseForm();

                using (ColorPickerForm dialogColor = new ColorPickerForm(AnnotationOptions.HighlightColor))
                {
                    if (dialogColor.ShowDialog() == DialogResult.OK)
                    {
                        AnnotationOptions.HighlightColor = dialogColor.NewColor;
                        UpdateMenu();
                        UpdateCurrentShape();
                    }
                }

                ResumeForm();
            };
            tsMain.Items.Add(tsbHighlightColor);

            tsddbShapeOptions = new ToolStripDropDownButton("Shape options");
            tsddbShapeOptions.DisplayStyle = ToolStripItemDisplayStyle.Image;
            tsddbShapeOptions.Image        = Resources.layer__pencil;
            tsMain.Items.Add(tsddbShapeOptions);

            tslnudBorderSize = new ToolStripLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Border_size_);
            tslnudBorderSize.Content.Minimum      = 0;
            tslnudBorderSize.Content.Maximum      = 20;
            tslnudBorderSize.Content.ValueChanged = (sender, e) =>
            {
                ShapeType shapeType = CurrentShapeType;

                int borderSize = (int)tslnudBorderSize.Content.Value;

                if (shapeType == ShapeType.DrawingTextBackground || shapeType == ShapeType.DrawingSpeechBalloon)
                {
                    AnnotationOptions.TextBorderSize = borderSize;
                }
                else if (shapeType == ShapeType.DrawingTextOutline)
                {
                    AnnotationOptions.TextOutlineBorderSize = borderSize;
                }
                else if (shapeType == ShapeType.DrawingStep)
                {
                    AnnotationOptions.StepBorderSize = borderSize;
                }
                else
                {
                    AnnotationOptions.BorderSize = borderSize;
                }

                UpdateCurrentShape();
            };
            tsddbShapeOptions.DropDownItems.Add(tslnudBorderSize);

            tslnudCornerRadius = new ToolStripLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Corner_radius_);
            tslnudCornerRadius.Content.Minimum      = 0;
            tslnudCornerRadius.Content.Maximum      = 150;
            tslnudCornerRadius.Content.ValueChanged = (sender, e) =>
            {
                ShapeType shapeType = CurrentShapeType;

                if (shapeType == ShapeType.RegionRectangle)
                {
                    AnnotationOptions.RegionCornerRadius = (int)tslnudCornerRadius.Content.Value;
                }
                else if (shapeType == ShapeType.DrawingRectangle || shapeType == ShapeType.DrawingTextBackground)
                {
                    AnnotationOptions.DrawingCornerRadius = (int)tslnudCornerRadius.Content.Value;
                }

                UpdateCurrentShape();
            };
            tsddbShapeOptions.DropDownItems.Add(tslnudCornerRadius);

            tslnudBlurRadius = new ToolStripLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Blur_radius_);
            tslnudBlurRadius.Content.Minimum      = 3;
            tslnudBlurRadius.Content.Maximum      = 199;
            tslnudBlurRadius.Content.Increment    = 2;
            tslnudBlurRadius.Content.ValueChanged = (sender, e) =>
            {
                AnnotationOptions.BlurRadius = (int)tslnudBlurRadius.Content.Value;
                UpdateCurrentShape();
            };
            tsddbShapeOptions.DropDownItems.Add(tslnudBlurRadius);

            tslnudPixelateSize = new ToolStripLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Pixel_size_);
            tslnudPixelateSize.Content.Minimum      = 2;
            tslnudPixelateSize.Content.Maximum      = 10000;
            tslnudPixelateSize.Content.ValueChanged = (sender, e) =>
            {
                AnnotationOptions.PixelateSize = (int)tslnudPixelateSize.Content.Value;
                UpdateCurrentShape();
            };
            tsddbShapeOptions.DropDownItems.Add(tslnudPixelateSize);

            tsmiShadow              = new ToolStripMenuItem("Drop shadow");
            tsmiShadow.Checked      = true;
            tsmiShadow.CheckOnClick = true;
            tsmiShadow.Click       += (sender, e) =>
            {
                AnnotationOptions.Shadow = tsmiShadow.Checked;
                UpdateCurrentShape();
            };
            tsddbShapeOptions.DropDownItems.Add(tsmiShadow);

            // In dropdown menu if only last item is visible then menu opens at 0, 0 position on first open, so need to add dummy item to solve this weird bug...
            tsddbShapeOptions.DropDownItems.Add(new ToolStripSeparator()
            {
                Visible = false
            });

            #endregion Shape options

            #region Edit

            ToolStripDropDownButton tsddbEdit = new ToolStripDropDownButton("Edit");
            tsddbEdit.DisplayStyle = ToolStripItemDisplayStyle.Image;
            tsddbEdit.Image        = Resources.wrench_screwdriver;
            tsMain.Items.Add(tsddbEdit);

            tsmiUndo       = new ToolStripMenuItem("Undo");
            tsmiUndo.Image = Resources.arrow_circle_225_left;
            tsmiUndo.ShortcutKeyDisplayString = "Ctrl+Z";
            tsmiUndo.MouseDown += (sender, e) => UndoShape();
            tsddbEdit.DropDownItems.Add(tsmiUndo);

            tsddbEdit.DropDownItems.Add(new ToolStripSeparator());

            tsmiDelete       = new ToolStripMenuItem("Delete");
            tsmiDelete.Image = Resources.layer__minus;
            tsmiDelete.ShortcutKeyDisplayString = "Del";
            tsmiDelete.MouseDown += (sender, e) => DeleteCurrentShape();
            tsddbEdit.DropDownItems.Add(tsmiDelete);

            tsmiDeleteAll       = new ToolStripMenuItem("Delete all");
            tsmiDeleteAll.Image = Resources.eraser;
            tsmiDeleteAll.ShortcutKeyDisplayString = "Shift+Del";
            tsmiDeleteAll.MouseDown += (sender, e) => DeleteAllShapes();
            tsddbEdit.DropDownItems.Add(tsmiDeleteAll);

            tsddbEdit.DropDownItems.Add(new ToolStripSeparator());

            tsmiMoveTop       = new ToolStripMenuItem("Bring to front");
            tsmiMoveTop.Image = Resources.layers_stack_arrange;
            tsmiMoveTop.ShortcutKeyDisplayString = "Home";
            tsmiMoveTop.MouseDown += (sender, e) => MoveCurrentShapeTop();
            tsddbEdit.DropDownItems.Add(tsmiMoveTop);

            tsmiMoveUp       = new ToolStripMenuItem("Bring forward");
            tsmiMoveUp.Image = Resources.layers_arrange;
            tsmiMoveUp.ShortcutKeyDisplayString = "Page up";
            tsmiMoveUp.MouseDown += (sender, e) => MoveCurrentShapeUp();
            tsddbEdit.DropDownItems.Add(tsmiMoveUp);

            tsmiMoveDown       = new ToolStripMenuItem("Send backward");
            tsmiMoveDown.Image = Resources.layers_arrange_back;
            tsmiMoveDown.ShortcutKeyDisplayString = "Page down";
            tsmiMoveDown.MouseDown += (sender, e) => MoveCurrentShapeDown();
            tsddbEdit.DropDownItems.Add(tsmiMoveDown);

            tsmiMoveBottom       = new ToolStripMenuItem("Send to back");
            tsmiMoveBottom.Image = Resources.layers_stack_arrange_back;
            tsmiMoveBottom.ShortcutKeyDisplayString = "End";
            tsmiMoveBottom.MouseDown += (sender, e) => MoveCurrentShapeBottom();
            tsddbEdit.DropDownItems.Add(tsmiMoveBottom);

            #endregion Edit

            if (!form.IsEditorMode)
            {
                tsMain.Items.Add(new ToolStripSeparator());

                #region Capture

                ToolStripDropDownButton tsddbCapture = new ToolStripDropDownButton("Capture");
                tsddbCapture.DisplayStyle = ToolStripItemDisplayStyle.Image;
                tsddbCapture.Image        = Resources.camera;
                tsMain.Items.Add(tsddbCapture);

                tsmiRegionCapture       = new ToolStripMenuItem("Capture regions");
                tsmiRegionCapture.Image = Resources.layer;
                tsmiRegionCapture.ShortcutKeyDisplayString = "Enter";
                tsmiRegionCapture.MouseDown += (sender, e) =>
                {
                    form.UpdateRegionPath();
                    form.Close(RegionResult.Region);
                };
                tsddbCapture.DropDownItems.Add(tsmiRegionCapture);

                if (RegionCaptureForm.LastRegionFillPath != null)
                {
                    ToolStripMenuItem tsmiLastRegionCapture = new ToolStripMenuItem("Capture last region");
                    tsmiLastRegionCapture.Image      = Resources.layers;
                    tsmiLastRegionCapture.MouseDown += (sender, e) => form.Close(RegionResult.LastRegion);
                    tsddbCapture.DropDownItems.Add(tsmiLastRegionCapture);
                }

                ToolStripMenuItem tsmiFullscreenCapture = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Capture_fullscreen);
                tsmiFullscreenCapture.Image = Resources.layer_fullscreen;
                tsmiFullscreenCapture.ShortcutKeyDisplayString = "Space";
                tsmiFullscreenCapture.MouseDown += (sender, e) => form.Close(RegionResult.Fullscreen);
                tsddbCapture.DropDownItems.Add(tsmiFullscreenCapture);

                ToolStripMenuItem tsmiActiveMonitorCapture = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Capture_active_monitor);
                tsmiActiveMonitorCapture.Image = Resources.monitor;
                tsmiActiveMonitorCapture.ShortcutKeyDisplayString = "~";
                tsmiActiveMonitorCapture.MouseDown += (sender, e) => form.Close(RegionResult.ActiveMonitor);
                tsddbCapture.DropDownItems.Add(tsmiActiveMonitorCapture);

                ToolStripMenuItem tsmiMonitorCapture = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Capture_monitor);
                tsmiMonitorCapture.HideImageMargin();
                tsmiMonitorCapture.Image = Resources.monitor_window;
                tsddbCapture.DropDownItems.Add(tsmiMonitorCapture);

                Screen[] screens = Screen.AllScreens;

                for (int i = 0; i < screens.Length; i++)
                {
                    Screen            screen = screens[i];
                    ToolStripMenuItem tsmi   = new ToolStripMenuItem($"{screen.Bounds.Width}x{screen.Bounds.Height}");
                    tsmi.ShortcutKeyDisplayString = (i + 1).ToString();
                    int index = i;
                    tsmi.MouseDown += (sender, e) =>
                    {
                        form.MonitorIndex = index;
                        form.Close(RegionResult.Monitor);
                    };
                    tsmiMonitorCapture.DropDownItems.Add(tsmi);
                }

                #endregion Capture

                #region Options

                ToolStripDropDownButton tsddbOptions = new ToolStripDropDownButton(Resources.ShapeManager_CreateContextMenu_Options);
                tsddbOptions.DisplayStyle = ToolStripItemDisplayStyle.Image;
                tsddbOptions.Image        = Resources.gear;
                tsMain.Items.Add(tsddbOptions);

                tsmiQuickCrop                          = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Multi_region_mode);
                tsmiQuickCrop.Checked                  = !Config.QuickCrop;
                tsmiQuickCrop.CheckOnClick             = true;
                tsmiQuickCrop.ShortcutKeyDisplayString = "Q";
                tsmiQuickCrop.Click                   += (sender, e) => Config.QuickCrop = !tsmiQuickCrop.Checked;
                tsddbOptions.DropDownItems.Add(tsmiQuickCrop);

                tsmiTips                          = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Show_tips);
                tsmiTips.Checked                  = Config.ShowHotkeys;
                tsmiTips.CheckOnClick             = true;
                tsmiTips.ShortcutKeyDisplayString = "F1";
                tsmiTips.Click                   += (sender, e) => Config.ShowHotkeys = tsmiTips.Checked;
                tsddbOptions.DropDownItems.Add(tsmiTips);

                ToolStripMenuItem tsmiShowInfo = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Show_position_and_size_info);
                tsmiShowInfo.Checked      = Config.ShowInfo;
                tsmiShowInfo.CheckOnClick = true;
                tsmiShowInfo.Click       += (sender, e) => Config.ShowInfo = tsmiShowInfo.Checked;
                tsddbOptions.DropDownItems.Add(tsmiShowInfo);

                ToolStripMenuItem tsmiShowMagnifier = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Show_magnifier);
                tsmiShowMagnifier.Checked      = Config.ShowMagnifier;
                tsmiShowMagnifier.CheckOnClick = true;
                tsmiShowMagnifier.Click       += (sender, e) => Config.ShowMagnifier = tsmiShowMagnifier.Checked;
                tsddbOptions.DropDownItems.Add(tsmiShowMagnifier);

                ToolStripMenuItem tsmiUseSquareMagnifier = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Square_shape_magnifier);
                tsmiUseSquareMagnifier.Checked      = Config.UseSquareMagnifier;
                tsmiUseSquareMagnifier.CheckOnClick = true;
                tsmiUseSquareMagnifier.Click       += (sender, e) => Config.UseSquareMagnifier = tsmiUseSquareMagnifier.Checked;
                tsddbOptions.DropDownItems.Add(tsmiUseSquareMagnifier);

                ToolStripLabeledNumericUpDown tslnudMagnifierPixelCount = new ToolStripLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Magnifier_pixel_count_);
                tslnudMagnifierPixelCount.Content.Minimum      = RegionCaptureOptions.MagnifierPixelCountMinimum;
                tslnudMagnifierPixelCount.Content.Maximum      = RegionCaptureOptions.MagnifierPixelCountMaximum;
                tslnudMagnifierPixelCount.Content.Increment    = 2;
                tslnudMagnifierPixelCount.Content.Value        = Config.MagnifierPixelCount;
                tslnudMagnifierPixelCount.Content.ValueChanged = (sender, e) => Config.MagnifierPixelCount = (int)tslnudMagnifierPixelCount.Content.Value;
                tsddbOptions.DropDownItems.Add(tslnudMagnifierPixelCount);

                ToolStripLabeledNumericUpDown tslnudMagnifierPixelSize = new ToolStripLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Magnifier_pixel_size_);
                tslnudMagnifierPixelSize.Content.Minimum      = RegionCaptureOptions.MagnifierPixelSizeMinimum;
                tslnudMagnifierPixelSize.Content.Maximum      = RegionCaptureOptions.MagnifierPixelSizeMaximum;
                tslnudMagnifierPixelSize.Content.Value        = Config.MagnifierPixelSize;
                tslnudMagnifierPixelSize.Content.ValueChanged = (sender, e) => Config.MagnifierPixelSize = (int)tslnudMagnifierPixelSize.Content.Value;
                tsddbOptions.DropDownItems.Add(tslnudMagnifierPixelSize);

                ToolStripMenuItem tsmiShowCrosshair = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Show_screen_wide_crosshair);
                tsmiShowCrosshair.Checked      = Config.ShowCrosshair;
                tsmiShowCrosshair.CheckOnClick = true;
                tsmiShowCrosshair.Click       += (sender, e) => Config.ShowCrosshair = tsmiShowCrosshair.Checked;
                tsddbOptions.DropDownItems.Add(tsmiShowCrosshair);

                ToolStripMenuItem tsmiFixedSize = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Fixed_size_region_mode);
                tsmiFixedSize.Checked      = Config.IsFixedSize;
                tsmiFixedSize.CheckOnClick = true;
                tsmiFixedSize.Click       += (sender, e) => Config.IsFixedSize = tsmiFixedSize.Checked;
                tsddbOptions.DropDownItems.Add(tsmiFixedSize);

                ToolStripDoubleLabeledNumericUpDown tslnudFixedSize = new ToolStripDoubleLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Width_,
                                                                                                              Resources.ShapeManager_CreateContextMenu_Height_);
                tslnudFixedSize.Content.Minimum      = 10;
                tslnudFixedSize.Content.Maximum      = 10000;
                tslnudFixedSize.Content.Increment    = 10;
                tslnudFixedSize.Content.Value        = Config.FixedSize.Width;
                tslnudFixedSize.Content.Value2       = Config.FixedSize.Height;
                tslnudFixedSize.Content.ValueChanged = (sender, e) => Config.FixedSize = new Size((int)tslnudFixedSize.Content.Value, (int)tslnudFixedSize.Content.Value2);
                tsddbOptions.DropDownItems.Add(tslnudFixedSize);

                ToolStripMenuItem tsmiShowFPS = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Show_FPS);
                tsmiShowFPS.Checked      = Config.ShowFPS;
                tsmiShowFPS.CheckOnClick = true;
                tsmiShowFPS.Click       += (sender, e) => Config.ShowFPS = tsmiShowFPS.Checked;
                tsddbOptions.DropDownItems.Add(tsmiShowFPS);

                ToolStripMenuItem tsmiRememberMenuState = new ToolStripMenuItem("Remember menu state");
                tsmiRememberMenuState.Checked      = Config.RememberMenuState;
                tsmiRememberMenuState.CheckOnClick = true;
                tsmiRememberMenuState.Click       += (sender, e) => Config.RememberMenuState = tsmiRememberMenuState.Checked;
                tsddbOptions.DropDownItems.Add(tsmiRememberMenuState);

                #endregion Options
            }

            ToolStripLabel tslDragRight = new ToolStripLabel()
            {
                Alignment    = ToolStripItemAlignment.Right,
                DisplayStyle = ToolStripItemDisplayStyle.Image,
                Image        = Resources.ui_radio_button_uncheck,
                Margin       = new Padding(0, 0, 2, 0),
                Padding      = new Padding(2)
            };

            tsMain.Items.Add(tslDragRight);

            tslDragLeft.MouseDown   += TslDrag_MouseDown;
            tslDragRight.MouseDown  += TslDrag_MouseDown;
            tslDragLeft.MouseEnter  += TslDrag_MouseEnter;
            tslDragRight.MouseEnter += TslDrag_MouseEnter;
            tslDragLeft.MouseLeave  += TslDrag_MouseLeave;
            tslDragRight.MouseLeave += TslDrag_MouseLeave;

            tsMain.ResumeLayout(false);
            tsMain.PerformLayout();
            menuForm.ResumeLayout(false);

            menuForm.Show(form);

            foreach (ToolStripItem tsi in tsMain.Items.OfType <ToolStripItem>())
            {
                if (!string.IsNullOrEmpty(tsi.Text))
                {
                    tsi.MouseEnter += (sender, e) =>
                    {
                        Point pos = CaptureHelpers.ScreenToClient(menuForm.PointToScreen(tsi.Bounds.Location));
                        pos.Y += tsi.Height + 8;
                        MenuTextAnimation.Position = pos;
                        MenuTextAnimation.Start(tsi.Text);
                    };

                    tsi.MouseLeave += TsMain_MouseLeave;
                }
            }

            UpdateMenu();

            CurrentShapeChanged     += shape => UpdateMenu();
            CurrentShapeTypeChanged += shapeType => UpdateMenu();
            ShapeCreated            += shape => UpdateMenu();

            ConfigureMenuState();

            form.Activate();
        }
コード例 #52
0
ファイル: DragHitShape.cs プロジェクト: wwwK/AsteroidMiner
 public void SetShape_LinesCircles(IEnumerable <RayHitTestParameters> lines, IEnumerable <CircleDefinition> circles)
 {
     _shape   = ShapeType.LinesCircles;
     _lines   = lines.ToArray();
     _circles = circles.ToArray();
 }
コード例 #53
0
        /// <summary>
        /// Populates the given streams for the shp and shx file when in IndexMode.
        /// </summary>
        /// <param name="shpStream">Stream that is used to write the shp file.</param>
        /// <param name="shxStream">Stream that is used to write the shx file.</param>
        /// <param name="shapefile">The shapefile that contains the features that are written.</param>
        /// <param name="expectedZType">Indicates which Z-ShapeType the header must have for the z values to be written.</param>
        /// <param name="expectedMType">Indicates which M-ShapeType the header must have for the m values to be written.</param>
        /// <param name="withParts">Indicates whether the parts should be written.</param>
        /// <returns>The lengths of the streams in bytes.</returns>
        internal static StreamLengthPair PopulateStreamsIndexed(Stream shpStream, Stream shxStream, Shapefile shapefile, ShapeType expectedZType, ShapeType expectedMType, bool withParts)
        {
            int fid    = 0;
            int offset = 50; // the shapefile header starts at 100 bytes, so the initial offset is 50 words

            foreach (ShapeRange shape in shapefile.ShapeIndices)
            {
                // null shapes have a contentLength of 2, all other shapes must have the same shape type
                int contentLength = shape.ShapeType == ShapeType.NullShape ? 2 : GetContentLength(shape.NumParts, shape.NumPoints, shapefile.Header.ShapeType);

                ////                                                           Index File
                //                                                             ---------------------------------------------------------
                //                                                             Position      Value              Type        Number      Byte Order
                //                                                             ---------------------------------------------------------
                shxStream.WriteBe(offset);                                     // Byte 0     Offset             Integer     1           Big
                shxStream.WriteBe(contentLength);                              // Byte 4     Content Length     Integer     1           Big

                ////                                                           X Y Poly Lines
                //                                                             ---------------------------------------------------------
                //                                                             Position        Value               Type        Number      Byte Order
                //                                                             ---------------------------------------------------------
                shpStream.WriteBe(fid + 1);                                    // Byte 0       Record Number       Integer     1           Big
                shpStream.WriteBe(contentLength);                              // Byte 4       Content Length      Integer     1           Big

                if (shape.ShapeType == ShapeType.NullShape)
                {
                    shpStream.WriteLe((int)ShapeType.NullShape);               // Byte 8       Shape Type 3        Integer     1           Little
                }
                else
                {
                    shpStream.WriteLe((int)shapefile.Header.ShapeType);        // Byte 8       Shape Type 3        Integer     1           Little
                    shpStream.WriteLe(shape.Extent.MinX);                      // Byte 12      Xmin                Double      1           Little
                    shpStream.WriteLe(shape.Extent.MinY);                      // Byte 20      Ymin                Double      1           Little
                    shpStream.WriteLe(shape.Extent.MaxX);                      // Byte 28      Xmax                Double      1           Little
                    shpStream.WriteLe(shape.Extent.MaxY);                      // Byte 36      Ymax                Double      1           Little
                    if (withParts)
                    {
                        shpStream.WriteLe(shape.NumParts); // Byte 44      NumParts            Integer     1           Little
                    }
                    shpStream.WriteLe(shape.NumPoints);    // Byte 48      NumPoints           Integer     1           Little

                    if (withParts)                         ////                                           Byte 52      Parts               Integer     NumParts    Little
                    {
                        foreach (PartRange part in shape.Parts)
                        {
                            shpStream.WriteLe(part.PartOffset);
                        }
                    }

                    int start = shape.StartIndex;
                    int count = shape.NumPoints;
                    shpStream.WriteLe(shapefile.Vertex, start * 2, count * 2); // Byte X       Points              Point       NumPoints   Little

                    if (shapefile.Header.ShapeType == expectedZType)
                    {
                        WriteValues(shapefile.Z, start, count, shpStream);
                    }

                    if (shapefile.Header.ShapeType == expectedMType || shapefile.Header.ShapeType == expectedZType)
                    {
                        WriteValues(shapefile.M, start, count, shpStream);
                    }
                }

                fid++;
                offset += 4;             // header bytes
                offset += contentLength; // adding the content length from each loop calculates the word offset
            }

            return(new StreamLengthPair {
                ShpLength = offset, ShxLength = 50 + (fid * 4)
            });
        }
コード例 #54
0
 /// <summary>
 /// Ensures that dictionary[s1][s2] exists. Sets it to 0 if it does not.
 /// </summary>
 /// <param name="dictionary">the dictionary to work with</param>
 /// <param name="s1">shape type 1</param>
 /// <param name="s2">shape type 2</param>
 private static void ensureKeyExists2D(Dictionary <ShapeType, Dictionary <ShapeType, int> > dictionary, ShapeType s1, ShapeType s2)
 {
     if (!dictionary.ContainsKey(s1))
     {
         dictionary.Add(s1, new Dictionary <ShapeType, int>());
     }
     if (!dictionary[s1].ContainsKey(s2))
     {
         dictionary[s1].Add(s2, 0);
     }
 }
コード例 #55
0
ファイル: DragHitShape.cs プロジェクト: wwwK/AsteroidMiner
 public void SetShape_Line(RayHitTestParameters line)
 {
     _shape     = ShapeType.Line;
     _point     = line.Origin;
     _direction = line.Direction;
 }
コード例 #56
0
 /// <summary>
 /// Constructor. Creates a new shape.
 /// </summary>
 /// <param name="shapeType">The type of shape to be created.</param>
 protected Shape(ShapeType shapeType)
 {
     ShapeType = shapeType;
 }
コード例 #57
0
 public static extern IntPtr CreateShape(ShapeType shapeType);
コード例 #58
0
ファイル: DragHitShape.cs プロジェクト: wwwK/AsteroidMiner
 public void SetShape_None()
 {
     _shape = ShapeType.None;
 }
コード例 #59
0
 public UnimplementedShapeException(ShapeType shapeType)
     : base($"Unknown shape type {shapeType} requires explicit implementation")
 {
 }
コード例 #60
0
ファイル: DragHitShape.cs プロジェクト: wwwK/AsteroidMiner
 public void SetShape_Circles(IEnumerable <CircleDefinition> circles)
 {
     _shape   = ShapeType.Circles;
     _circles = circles.ToArray();
 }