Example #1
0
        public void DrawShape(ShapeKind shapeKind)
        {
            switch (shapeKind)
            {
            case ShapeKind.Line:
                DrawLine();
                break;

            case ShapeKind.Triangle:
                DrawTriangle(Colors.Red);
                break;

            case ShapeKind.Square:
                DrawSquare(Colors.Green);
                break;

            case ShapeKind.X:
                DrawX(Colors.Blue);
                break;

            case ShapeKind.None:
                Reset(Colors.Red);
                break;
            }
        }
        public Mesh createQuad(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, bool isClockwise = true)
        {
            shapeKind  = ShapeKind.RECT;
            vertexType = VertexType.MESH;

            clearMesh();
            mesh.name = "Quad";

            mesh.vertices = new Vector3[] {
                new Vector3(x1, y1, 0.0f),
                new Vector3(x2, y2, 0.0f),
                new Vector3(x3, y3, 0.0f),
                new Vector3(x4, y4, 0.0f),
            };

            var uv = new Vector2[] {
                new Vector2(0.0f, 0.0f),
                new Vector2(1.0f, 0.0f),
                new Vector2(1.0f, 1.0f),
                new Vector2(0.0f, 1.0f),
            };

            int[] triangles   = new int[] { 2, 1, 0, 0, 3, 2 };
            int[] wireIndices = new int[] { 2, 1, 0, 3, 2 };

            mesh.subMeshCount = 2;
            setMeshTriangles(triangles, uv, 0);
            recalc(mesh);
            //setWireframeMeshTriangles(triangles, 1);
            setWireframeMeshIndices(wireIndices, 1, MeshTopology.LineStrip);

            return(mesh);
        }
Example #3
0
            public static BeginMode ToBeginMode(ShapeKind shapeKind, bool filled)
            {
                switch (shapeKind)
                {
                case ShapeKind.Lines:
                    return(BeginMode.Lines);

                case ShapeKind.Points:
                    return(BeginMode.Points);

                case ShapeKind.Polygon:
                    return(filled ? BeginMode.Polygon : BeginMode.LineStrip);

                case ShapeKind.Quads:
                    return(filled ? BeginMode.Quads : BeginMode.QuadStrip);

                case ShapeKind.QuadStrip:
                    return(BeginMode.QuadStrip);

                case ShapeKind.TriangleFan:
                    return(BeginMode.TriangleFan);

                case ShapeKind.Triangles:
                    return(BeginMode.Triangles);

                case ShapeKind.TriangleStrip:
                    return(BeginMode.TriangleString);

                default:
                    return(BeginMode.Polygon);
                }
            }
Example #4
0
 /// <summary>
 /// Вывести массив точек на игровом поле
 /// </summary>
 /// <param name="points">Массив точек для отрисовки</param>
 /// <param name="kind">Тип фигуры. Нужен для определения цвета точек</param>
 /// <param name="view">Свойства пользовательского интерфейса</param>
 public static void DrawPoints(Point2D[] points, ShapeKind kind, GameView view)
 {
     for (int i = 0; i < points.Length; i++)
     {
         DrawPoint(view.GameFieldLeft + points[i].Left * POINT_WIDTH, view.GameFieldTop + points[i].Top * POINT_HEIGHT, view.ShapeColors[(int)kind]);
     }
 }
Example #5
0
        public Mesh createQuad(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)
        {
            shapeKind = ShapeKind.RECT;
            shapeType = ShapeType.MESH;

            mesh      = new Mesh();
            mesh.name = "Quad";

            mesh.vertices = new Vector3[] {
                new Vector3(x1, y1, 0.0f),
                new Vector3(x2, y2, 0.0f),
                new Vector3(x3, y3, 0.0f),
                new Vector3(x4, y4, 0.0f),
            };

            mesh.triangles = new int[] {
                0, 1, 2,
                2, 3, 0
            };

            mesh.uv = new Vector2[] {
                new Vector2(0.0f, 0.0f),
                new Vector2(1.0f, 0.0f),
                new Vector2(1.0f, 1.0f),
                new Vector2(0.0f, 1.0f),
            };

            recalc(mesh);
            return(mesh);
        }
Example #6
0
 public void FromPmxSoftBody(PmxSoftBody sbody, bool nonStr = false)
 {
     if (!nonStr)
     {
         Name  = sbody.Name;
         NameE = sbody.NameE;
     }
     Shape     = sbody.Shape;
     Material  = sbody.Material;
     Group     = sbody.Group;
     PassGroup = sbody.PassGroup.Clone();
     IsGenerateBendingLinks = sbody.IsGenerateBendingLinks;
     IsGenerateClusters     = sbody.IsGenerateClusters;
     IsRandomizeConstraints = sbody.IsRandomizeConstraints;
     BendingLinkDistance    = sbody.BendingLinkDistance;
     ClusterCount           = sbody.ClusterCount;
     TotalMass      = sbody.TotalMass;
     Margin         = sbody.Margin;
     Config         = sbody.Config;
     MaterialConfig = sbody.MaterialConfig;
     BodyAnchorList = CP.CloneList(sbody.BodyAnchorList);
     VertexPinList  = CP.CloneList(sbody.VertexPinList);
     VertexIndices  = CP.CloneArray_ValueType(sbody.VertexIndices);
     FromID(sbody);
 }
Example #7
0
        public IAsyncOperation <SenseHatLedArrayDrawShapeResult> DrawShapeAsync(
            AllJoynMessageInfo info, int interfaceMemberShapeKind)
        {
            Task <SenseHatLedArrayDrawShapeResult> task =
                new Task <SenseHatLedArrayDrawShapeResult>(() =>
            {
                if (ledArray != null)
                {
                    currentShape = GetShapeKind(interfaceMemberShapeKind);

                    ledArray.DrawShape(currentShape);

                    return(SenseHatLedArrayDrawShapeResult.CreateSuccessResult());
                }
                else
                {
                    return(SenseHatLedArrayDrawShapeResult.CreateFailureResult(
                               (int)ErrorCodes.LedInitializationError));
                }
            });

            task.Start();

            return(task.AsAsyncOperation());
        }
Example #8
0
 public void BeginShape(ShapeKind kind)
 {
     _jsRuntime.InvokeVoid(
         _p5InvokeFunction,
         "beginShape",
         (uint)kind
         );
 }
 public UShape(UGraphics g)
 {
     this.g      = g;
     style       = new UGraphics.UStyle(g);
     vertexType  = VertexType.NONE;
     shapeKind   = ShapeKind.NONE;
     isClockwise = !g.isP5;
 }
Example #10
0
        private void btnTriangle_Click(object sender, EventArgs e)
        {
            shapeKind = ShapeKind.Triangle;
            string button = "triangle";

            ChangeButtonColor(button);
            selectionMode = true;
            btnSelection_Click(sender, e);
        }
Example #11
0
        public Mesh createRect(float x, float y, float w, float h)
        {
            shapeKind = ShapeKind.RECT;
            shapeType = ShapeType.MESH;

            mesh      = createQuad(x, y, x + w, y, x + w, y + h, x, y + h);
            mesh.name = "Rect";
            return(mesh);
        }
Example #12
0
        public Mesh createRect(float x, float y, float w, float h)
        {
            shapeKind  = ShapeKind.RECT;
            vertexType = VertexType.MESH;

            mesh = createQuad(x, y, x + w, y, x + w, y + h, x, y + h); // �����
            //mesh = createQuad(x, y - h, x + w, y - h, x + w, y, x, y); // �����
            mesh.name = "Rect";
            return(mesh);
        }
 public void beginShape(VertexType type = VertexType.LINE_STRIP)
 {
     shapeKind  = ShapeKind.NONE;
     vertexType = type;
     vertices.Clear();
     uv.Clear();
     triangles.Clear();
     colors.Clear();
     //mesh = null;
     clearMesh();
     wireframeSubmeshIndex = -1;
 }
Example #14
0
        private static void DrawShape(GameView view, int fieldLeft, int fieldTop, Shape shape, bool clear = false)
        {
            ShapeKind    kind  = clear ? ShapeKind.Empty : shape.Kind;
            ConsoleColor color = view.ShapeColors[(int)kind];

            for (int i = 0; i < shape.Points.Length; i++)
            {
                int left = fieldLeft + (shape.Position.Left + shape.Points[i].Left) * POINT_WIDTH;
                int top  = fieldTop + (shape.Position.Top + shape.Points[i].Top) * POINT_HEIGHT;
                DrawPoint(left, top, color);
            }
        }
Example #15
0
 public void beginShape(ShapeType type, bool isClockwise = true)
 {
     if (shapeKind != ShapeKind.NONE)
     {
         Debug.LogWarning("beginShape kind warning:" + shapeKind);
     }
     shapeKind = ShapeKind.CUSTOM;
     shapeType = type;
     vertices.Clear();
     uv.Clear();
     triangles.Clear();
     this.isClockwise = isClockwise;
 }
Example #16
0
 public PmxSoftBody()
 {
     Name      = "";
     NameE     = "";
     Shape     = ShapeKind.TriMesh;
     Material  = -1;
     Group     = 0;
     PassGroup = new PmxBodyPassGroup();
     InitializeParameter();
     BodyAnchorList = new List <BodyAnchor>();
     VertexPinList  = new List <VertexPin>();
     VertexIndices  = new int[0];
 }
Example #17
0
        public Mesh createEllipse(float x, float y, float w, float h)
        {
            shapeKind  = ShapeKind.ELLIPSE;
            vertexType = VertexType.MESH;

            w *= 0.5f; h *= 0.5f;
            //x += w; y += h;

            clearMesh();
            mesh.name = "Ellipse";

            const int div = 32;

            Vector3[] vertices    = new Vector3[div + 2];
            Vector2[] uv          = new Vector2[div + 2];
            int[]     triangles   = new int[(div + 1) * 3];
            int[]     wireIndices = new int[div + 1];
            float     d           = 0.0f;
            float     dstep       = (Mathf.PI * 2.0f) / (float)div;

            vertices[0].Set(x, y, 0);
            uv[0].Set(0.5f, 0.5f);
            for (int i = 1; i <= div + 1; i++)
            {
                float rx = Mathf.Cos(d);
                float ry = Mathf.Sin(d);
                vertices[i].Set(x + rx * w, y + ry * h, 0);
                uv[i].Set(0.5f + rx * 0.5f, 0.5f + ry * 0.5f);
                d += dstep;
                if (i < div + 1)
                {
                    int ti = (i - 1) * 3;
                    triangles[ti]     = 0;
                    triangles[ti + 1] = i + 1;
                    triangles[ti + 2] = i;
                }
                wireIndices[i - 1] = i;
            }
            mesh.vertices     = vertices;
            mesh.subMeshCount = 2;
            setMeshTriangles(triangles, uv, 0);
            recalc(mesh);
            //setWireframeMeshTriangles(triangles, 1);
            setWireframeMeshIndices(wireIndices, 1, MeshTopology.LineStrip);

            return(mesh);
        }
        public Mesh createPoint(float x, float y, float z)
        {
            shapeKind  = ShapeKind.LINE;
            vertexType = VertexType.LINES;

            clearMesh();
            mesh.name = "Point";

            mesh.vertices = new Vector3[] {
                new Vector3(x, y, z),
            };

            int[] indices = { 0 };
            mesh.SetIndices(indices, MeshTopology.Points, 0);

            //recalc(mesh);
            return(mesh);
        }
        public Mesh createLine(float x1, float y1, float z1, float x2, float y2, float z2)
        {
            shapeKind  = ShapeKind.LINE;
            vertexType = VertexType.LINES;

            clearMesh();
            mesh.name = "Line";

            mesh.vertices = new Vector3[] {
                new Vector3(x1, y1, z1),
                new Vector3(x2, y2, z2),
            };

            int[] indices = { 0, 1 };
            mesh.SetIndices(indices, MeshTopology.Lines, 0);

            //recalc(mesh);
            return(mesh);
        }
Example #20
0
        public void Subscribe(ShapeKind shapeKind)
        {
            if (!_disposed)
            {
                switch (shapeKind)
                {
                case ShapeKind.Circle:
                    _shapeWaitSets.Add(CreateCircleReader());
                    break;

                case ShapeKind.Square:
                    _shapeWaitSets.Add(CreateSquareReader());
                    break;

                case ShapeKind.Triangle:
                    _shapeWaitSets.Add(CreateTriangleReader());
                    break;
                }
            }
        }
Example #21
0
        public Mesh createEllipse(float x, float y, float w, float h)
        {
            shapeKind = ShapeKind.ELLIPSE;
            shapeType = ShapeType.MESH;

            mesh      = new Mesh(); //mesh.Clear();
            mesh.name = "Ellipse";

            const int div = 32;

            Vector3[] vertices  = new Vector3[div + 2];
            Vector2[] UV        = new Vector2[div + 2];
            int[]     triangles = new int[(div + 1) * 3];
            float     d         = 0.0f;
            float     dstep     = (Mathf.PI * 2.0f) / (float)div;

            vertices[0].Set(0, 0, 0);
            UV[0].Set(0, 0);
            for (int i = 1; i <= div + 1; i++)
            {
                float rx = Mathf.Cos(d);
                float ry = Mathf.Sin(d);
                vertices[i].Set(x + rx * w, y + ry * h, 0);
                UV[i].Set(0.5f + rx * 0.5f, 0.5f + ry * 0.5f);
                d += dstep;
                if (i > 0 && i < div + 1)
                {
                    int ti = (i - 1) * 3;
                    triangles[ti]     = i;
                    triangles[ti + 1] = i + 1;
                    triangles[ti + 2] = 0;
                }
            }
            mesh.vertices  = vertices;
            mesh.uv        = UV;
            mesh.triangles = triangles;

            recalc(mesh);
            return(mesh);
        }
Example #22
0
        public Mesh createRect(float x, float y, float w, float h)
        {
            shapeKind = ShapeKind.RECT;
            shapeType = ShapeType.MESH;

            mesh = createQuad(x, y, x + w, y, x + w, y + h, x, y + h);
            mesh.name = "Rect";
            return mesh;
        }
Example #23
0
        public Mesh createQuad(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)
        {
            shapeKind = ShapeKind.RECT;
            shapeType = ShapeType.MESH;

            mesh = new Mesh();
            mesh.name = "Quad";

            mesh.vertices = new Vector3[]{
            new Vector3 (x1, y1, 0.0f),
            new Vector3 (x2, y2, 0.0f),
            new Vector3 (x3, y3, 0.0f),
            new Vector3 (x4, y4, 0.0f),
            };

            mesh.triangles = new int[]{
            0, 1, 2,
            2, 3, 0
            };

            mesh.uv = new Vector2[]{
            new Vector2 (0.0f, 0.0f),
            new Vector2 (1.0f, 0.0f),
            new Vector2 (1.0f, 1.0f),
            new Vector2 (0.0f, 1.0f),
            };

            recalc(mesh);
            return mesh;
        }
Example #24
0
        public Mesh createEllipse(float x, float y, float w, float h)
        {
            shapeKind = ShapeKind.ELLIPSE;
            shapeType = ShapeType.MESH;

            mesh = new Mesh(); //mesh.Clear();
            mesh.name = "Ellipse";

            const int div = 32;
            Vector3[] vertices = new Vector3[div + 2];
            Vector2[] UV = new Vector2[div + 2];
            int[] triangles = new int[(div + 1) * 3];
            float d = 0.0f;
            float dstep = (Mathf.PI * 2.0f) / (float)div;

            vertices[0].Set(0, 0, 0);
            UV[0].Set(0, 0);
            for (int i = 1; i <= div + 1; i++)
            {
                float rx = Mathf.Cos(d);
                float ry = Mathf.Sin(d);
                vertices[i].Set(x + rx * w, y + ry * h, 0);
                UV[i].Set(0.5f + rx * 0.5f, 0.5f + ry * 0.5f);
                d += dstep;
                if (i > 0 && i < div + 1)
                {
                    int ti = (i - 1) * 3;
                    triangles[ti] = i;
                    triangles[ti + 1] = i + 1;
                    triangles[ti + 2] = 0;
                }
            }
            mesh.vertices = vertices;
            mesh.uv = UV;
            mesh.triangles = triangles;

            recalc(mesh);
            return mesh;
        }
Example #25
0
 public void beginShape(ShapeType type, bool isClockwise = true)
 {
     if (shapeKind != ShapeKind.NONE)
     {
         Debug.LogWarning("beginShape kind warning:" + shapeKind);
     }
     shapeKind = ShapeKind.CUSTOM;
     shapeType = type;
     vertices.Clear();
     uv.Clear();
     triangles.Clear();
     this.isClockwise = isClockwise;
 }
Example #26
0
        public static void Main()
        {
            Drawing   myDrawing = new Drawing();
            ShapeKind KindToAdd = ShapeKind.Circle;

            //Open the game window
            SwinGame.OpenGraphicsWindow("GameMain", 800, 600);
            SwinGame.ShowSwinGameSplashScreen();

            //Run the game loop
            while (SwinGame.WindowCloseRequested() == false)
            {
                //Fetch the next batch of UI interaction
                SwinGame.ProcessEvents();

                //Clear the screen and myDrawing the framerate
                SwinGame.ClearScreen(Color.White);

                if (SwinGame.KeyTyped(KeyCode.vk_r))
                {
                    KindToAdd = ShapeKind.Rectangle;
                }
                else if (SwinGame.KeyTyped(KeyCode.vk_c))
                {
                    KindToAdd = ShapeKind.Circle;
                }
                else if (SwinGame.KeyTyped(KeyCode.vk_l))
                {
                    KindToAdd = ShapeKind.Line;
                }

                if (SwinGame.MouseClicked(MouseButton.LeftButton))
                {
                    Shape newShape;

                    switch (KindToAdd)
                    {
                    case ShapeKind.Circle:
                        newShape = new Circle();
                        break;

                    case ShapeKind.Rectangle:
                        newShape = new Rectangle();
                        break;

                    case ShapeKind.Line:
                        newShape = new Line();
                        break;

                    default:
                        newShape = new Rectangle();
                        break;
                    }

                    newShape.X = SwinGame.MouseX();
                    newShape.Y = SwinGame.MouseY();
                    myDrawing.AddShape(newShape);
                }
                if (SwinGame.MouseClicked(MouseButton.RightButton))
                {
                    myDrawing.SelectShapesAt(SwinGame.MousePosition());
                }
                if (SwinGame.KeyTyped(KeyCode.vk_DELETE) || SwinGame.KeyTyped(KeyCode.vk_BACKSPACE))
                {
                    foreach (Shape shape in myDrawing.SelectedShapes)
                    {
                        myDrawing.RemoveShape(shape);
                    }
                }
                if (SwinGame.KeyTyped(KeyCode.vk_SPACE))
                {
                    myDrawing.Background = SwinGame.RandomRGBColor(255);
                }
                myDrawing.Draw();
                SwinGame.DrawFramerate(0, 0);

                //myDrawing onto the screen
                SwinGame.RefreshScreen(60);
            }
        }
Example #27
0
        public static void Main()
        {
            //Register shapes
            Shape.RegisterShape("Retangle", typeof(Rectangle));
            Shape.RegisterShape("Circle", typeof(Circle));
            Shape.RegisterShape("Line", typeof(Line));

            //Open the game window
            SwinGame.OpenGraphicsWindow("DrawingProgram", 1600, 900);
            SwinGame.ShowSwinGameSplashScreen();


            ShapeKind kindToAdd = ShapeKind.Circle;

            Drawing myDrawing = new Drawing();


            //Run the game loop
            while (false == SwinGame.WindowCloseRequested())
            {
                //Fetch the next batch of UI interaction
                SwinGame.ProcessEvents();

                if (SwinGame.MouseClicked(MouseButton.LeftButton))
                {
                    Shape newShape;
                    int   x = (int)SwinGame.MouseX();
                    int   y = (int)SwinGame.MouseY();

                    if (kindToAdd == ShapeKind.Circle)
                    {
                        Circle newCircle = new Circle();
                        newShape = newCircle;
                    }
                    else if (kindToAdd == ShapeKind.Line)
                    {
                        Line newLine = new Line();
                        newShape = newLine;
                    }
                    else
                    {
                        Rectangle newRect = new Rectangle();
                        newShape = newRect;
                    }
                    newShape.X = x;
                    newShape.Y = y;

                    myDrawing.AddShape(newShape);
                }


                if (SwinGame.KeyDown(KeyCode.SKey))
                {
                    myDrawing.Save("C:\\Users\\Mikan\\Desktop\\TestDrawing.txt");
                }

                if (SwinGame.KeyDown(KeyCode.OKey))
                {
                    myDrawing.Load("C:\\Users\\Mikan\\Desktop\\TestDrawing.txt");
                }

                if (SwinGame.KeyDown(KeyCode.LKey))
                {
                    kindToAdd = ShapeKind.Line;
                }

                if (SwinGame.KeyDown(KeyCode.RKey))
                {
                    kindToAdd = ShapeKind.Rectangle;
                }

                if (SwinGame.KeyDown(KeyCode.CKey))
                {
                    kindToAdd = ShapeKind.Circle;
                }

                if (SwinGame.KeyDown(KeyCode.SpaceKey))
                {
                    myDrawing.Background = SwinGame.RandomRGBColor(255);
                }

                if (SwinGame.KeyDown(KeyCode.DeleteKey) || SwinGame.KeyDown(KeyCode.BackspaceKey))
                {
                    myDrawing.DeleteSelectedShapes();
                }

                if (SwinGame.MouseClicked(MouseButton.RightButton))
                {
                    myDrawing.SelectShapesAt(SwinGame.MousePosition());
                }



                //Clear the screen and draw the framerate
                SwinGame.ClearScreen(Color.White);

                myDrawing.Draw();

                SwinGame.DrawFramerate(0, 0);

                //Draw onto the screen
                SwinGame.RefreshScreen(60);
            }
        }
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainWindowViewModel(IOpenDDSharpService dds, IViewService view, IConfigurationService config)
        {
            _dds = dds;
            _dds.SquareUpdated   += DdsSquareUpdated;
            _dds.CircleUpdated   += DdsCircleUpdated;
            _dds.TriangleUpdated += DdsTriangleUpdated;

            _view   = view;
            _config = config;

            _publishedSquares    = new ObservableCollection <SquareType>();
            _publishedCircles    = new ObservableCollection <CircleType>();
            _publishedTriangles  = new ObservableCollection <TriangleType>();
            _subscribedSquares   = new ObservableCollection <SquareType>();
            _subscribedCircles   = new ObservableCollection <CircleType>();
            _subscribedTriangles = new ObservableCollection <TriangleType>();

            Shapes = new CompositeCollection
            {
                new CollectionContainer()
                {
                    Collection = _publishedSquares
                },
                new CollectionContainer()
                {
                    Collection = _publishedCircles
                },
                new CollectionContainer()
                {
                    Collection = _publishedTriangles
                },
                new CollectionContainer()
                {
                    Collection = _subscribedSquares
                },
                new CollectionContainer()
                {
                    Collection = _subscribedCircles
                },
                new CollectionContainer()
                {
                    Collection = _subscribedTriangles
                }
            };

            PublishShapeCommand   = new RelayCommand(PublishShape, () => true);
            WriterQosCommand      = new RelayCommand(WriterQos, () => true);
            ReaderQosCommand      = new RelayCommand(ReaderQos, () => true);
            ReaderFilterCommand   = new RelayCommand(ReaderFilter, () => true);
            SubscribeShapeCommand = new RelayCommand(SubscribeShape, () => true);

            _rect   = new Rect(0, 0, 321, 361);
            _random = new Random();
            _selectedSubscriberShape = ShapeKind.Circle;
            _selectedPublisherShape  = ShapeKind.Circle;
            _selectedColor           = ShapeColor.Green;
            _selectedSize            = 45;
            _selectedSpeed           = 45;

            BindingOperations.EnableCollectionSynchronization(_publishedSquares, _lockPublishedSquares);
            BindingOperations.EnableCollectionSynchronization(_publishedCircles, _lockPublishedCircles);
            BindingOperations.EnableCollectionSynchronization(_publishedTriangles, _lockPublishedTriangles);
            BindingOperations.EnableCollectionSynchronization(_subscribedSquares, _lockSubscribedSquares);
            BindingOperations.EnableCollectionSynchronization(_subscribedCircles, _lockSubscribedCircles);
            BindingOperations.EnableCollectionSynchronization(_subscribedTriangles, _lockSubscribedTriangles);

            Messenger.Default.Register <FilterConfigMessage>(this, OnFilterConfigMessage);
        }
Example #29
0
        public static void Main()
        {
            Drawing   myDrawing = new Drawing();
            ShapeKind kindToAdd = ShapeKind.Circle;

            //Open the game window
            SwinGame.OpenGraphicsWindow("GameMain", 800, 600);

            //Run the game loop
            while (false == SwinGame.WindowCloseRequested())
            {
                //Fetch the next batch of UI interaction
                SwinGame.ProcessEvents();

                //Clear the screen and draw the framerate
                SwinGame.ClearScreen(Color.White);
                SwinGame.DrawFramerate(0, 0);

                if (SwinGame.KeyTyped(KeyCode.vk_r))
                {
                    kindToAdd = ShapeKind.Rectangle;
                }

                if (SwinGame.KeyTyped(KeyCode.vk_c))
                {
                    kindToAdd = ShapeKind.Circle;
                }

                if (SwinGame.KeyTyped(KeyCode.vk_l))
                {
                    kindToAdd = ShapeKind.Line;
                }

                if (SwinGame.MouseClicked(MouseButton.LeftButton))
                {
                    Shape newShape;
                    if (kindToAdd == ShapeKind.Rectangle)
                    {
                        newShape = new Rectangle();
                    }
                    else if (kindToAdd == ShapeKind.Circle)
                    {
                        newShape = new Circle();
                    }
                    else
                    {
                        newShape = new Line();
                    }

                    newShape.X = SwinGame.MouseX();
                    newShape.Y = SwinGame.MouseY();
                    myDrawing.AddShape(newShape);
                }

                if (SwinGame.KeyTyped(KeyCode.vk_SPACE))
                {
                    myDrawing.Background = SwinGame.RandomRGBColor(255);
                }

                if (SwinGame.MouseClicked(MouseButton.RightButton))
                {
                    myDrawing.SelectShapesAt(SwinGame.MousePosition());
                }

                if (SwinGame.KeyTyped(KeyCode.vk_DELETE))
                {
                    myDrawing.RemoveSelected();
                }

                if (SwinGame.KeyTyped(KeyCode.vk_s))
                {
                    myDrawing.Save("./ShapeDrawing.txt");
                }

                if (SwinGame.KeyTyped(KeyCode.vk_o))
                {
                    try
                    {
                        myDrawing.Load("./ShapeDrawing.txt");
                    }
                    catch (Exception e)
                    {
                        Console.Error.WriteLine("Error loading file: {0}", e.Message);
                    }
                }

                myDrawing.Draw();

                //Draw onto the screen
                SwinGame.RefreshScreen(60);
            }
        }
Example #30
0
 private static void SetShapeKind(ref Shape sh, ShapeKind kind)
 {
     sh.Kind   = kind;
     sh.Points = AllShapes[(int)kind];
 }
Example #31
0
 public PShape(ShapeType type = ShapeType.NONE)
 {
     style.init(null);
     shapeType = type;
     shapeKind = ShapeKind.NONE;
 }
        public static void Main()
        {
            //Register shapes
            Shape.RegisterShape("Rectangle", typeof(Rectangle));
            Shape.RegisterShape("Circle", typeof(Circle));
            Shape.RegisterShape("Line", typeof(Line));

            //Open the game window
            SwinGame.OpenGraphicsWindow("GameMain", 800, 600);
            SwinGame.ShowSwinGameSplashScreen();

            //Shape myShape = new Shape();
            Drawing   myDrawing = new Drawing();
            ShapeKind kindToAdd = ShapeKind.Circle;


            //Run the game loop
            while (false == SwinGame.WindowCloseRequested())
            {
                //Fetch the next batch of UI interaction
                SwinGame.ProcessEvents();

                string _path = @"C:\Users\Klim\Documents\Code\5.3D\TestDrawing.txt";

                if (SwinGame.KeyTyped(KeyCode.SKey))
                {
                    myDrawing.Save(_path);
                }

                if (SwinGame.KeyTyped(KeyCode.OKey))
                {
                    try
                    {
                        myDrawing.Load(_path);
                    }
                    catch (Exception e)
                    {
                        Console.Error.WriteLine("Error loadingfile: {0}", e.Message);
                    }
                }

                if (SwinGame.KeyTyped(KeyCode.RKey))
                {
                    kindToAdd = ShapeKind.Rectangle;
                }

                if (SwinGame.KeyTyped(KeyCode.CKey))
                {
                    kindToAdd = ShapeKind.Circle;
                }

                if (SwinGame.KeyTyped(KeyCode.LKey))
                {
                    kindToAdd = ShapeKind.Line;
                }

                // If the user clicks the LeftButton on their mouse, set the shapes x, y to be at the mouse's position
                if (SwinGame.MouseClicked(MouseButton.LeftButton))
                {
                    Shape newShape;
                    float x = SwinGame.MouseX();
                    float y = SwinGame.MouseY();

                    if (kindToAdd == ShapeKind.Circle)
                    {
                        Circle newCircle = new Circle();
                        newShape = newCircle;
                    }
                    else if (kindToAdd == ShapeKind.Rectangle)
                    {
                        Rectangle newRect = new Rectangle();
                        newShape = newRect;
                    }
                    else
                    {
                        Line newLine = new Line();
                        newShape = newLine;
                    }

                    newShape.X = x;
                    newShape.Y = y;
                    myDrawing.AddShape(newShape);
                }

                if (SwinGame.MouseClicked(MouseButton.RightButton))
                {
                    myDrawing.SelectShapeAt(SwinGame.MousePosition());
                }

                if (SwinGame.KeyTyped(KeyCode.SpaceKey))
                {
                    myDrawing.Background = SwinGame.RandomRGBColor(255);
                }

                if ((SwinGame.KeyTyped(KeyCode.DeleteKey)) | (SwinGame.KeyTyped(KeyCode.BackspaceKey)))
                {
                    myDrawing.DeleteShapes();
                }

                //Clear the screen and draw the framerate
                SwinGame.ClearScreen(Color.White);
                myDrawing.Draw();
                SwinGame.DrawFramerate(0, 0);

                //Draw onto the screen
                SwinGame.RefreshScreen(60);
            }
        }
Example #33
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ShapeObject"/> class with default settings.
 /// </summary>
 public ShapeObject()
 {
     shape            = ShapeKind.Rectangle;
     FlagSimpleBorder = true;
 }
Example #34
0
 public void BeginShape(ShapeKind kind)
 {
     ((IRenderer)Renderer).BeginShape(kind);
 }
Example #35
0
 /// <inheritdoc/>
 public override void OnBeforeInsert(int flags)
 {
     FShape = (ShapeKind)flags;
 }