コード例 #1
0
        public void SaveChanges()
        {
            // Save physical images
            RenderTarget2D finalSurface = null;
            int            index        = 0;

            foreach (AnimationFrame af in Frames)
            {
                finalSurface = Sgml.surface_create(selectedFrame.previewLayer.texture.Width, selectedFrame.previewLayer.texture.Height);
                Sgml.surface_set_target(finalSurface);
                Sgml.draw_surface(Vector2.Zero, af.layers[0].texture);
                Sgml.surface_reset_target();
                Sgml.surface_save(finalSurface, parentForm.owner.currentProject.RootPath + "/Content/Sprites/texture" + "_frame" + index);

                index++;
            }

            finalSurface?.Dispose();
        }
コード例 #2
0
        protected override void Draw()
        {
            if (parentForm != null)
            {
                ms = Mouse.GetState();

                if (ttl < 10)
                {
                    if (ttl == 9)
                    {
                        ScaleToFit(90);
                    }

                    ttl++;
                }

                base.Draw();
                double framerate       = Editor.GetFrameRate;
                Matrix transformMatrix = cam.Camera.GetViewMatrix();
                MousePositionTranslated = cam.Camera.ScreenToWorld(new Vector2(ms.X, ms.Y));

                BackgroundColor = Color.Black;
                Editor.graphics.Clear(BackgroundColor);
                Input.MousePosition = MousePositionTranslated;
                MousePosition       = new Vector2(ms.X, ms.Y);

                Sgml.sb            = Editor.spriteBatch;
                Sgml.vb            = vertexBuffer;
                Sgml.be            = basicEffect;
                Sgml.m             = transformMatrix;
                Sgml.currentObject = representativeGameObject;

                Matrix view       = cam.Camera.GetViewMatrix();
                Matrix projection = m;

                basicEffect.World              = world;
                basicEffect.View               = view;
                basicEffect.Projection         = projection;
                basicEffect.VertexColorEnabled = true;

                Sgml.mouse = MousePositionTranslated;

                // Actual logic
                int cellSize = 16;
                int x        = 0;
                int y        = 0;

                RectangleF rect = RectangleF.Empty;

                Color c1 = Color.FromNonPremultiplied(68, 68, 68, 255);
                Color c2 = Color.FromNonPremultiplied(77, 77, 77, 255);

                bool flag     = true;
                bool lastFlag = flag;

                cam.Camera.Origin = new Vector2(Width / 2f, Height / 2f);


                basicEffect.View = Matrix.Identity;
                Sgml.m           = Matrix.Identity;
                Vector2 origin = Vector2.Zero;

                Sgml.draw_surface(origin, gridSurface);

                basicEffect.View = view;
                Sgml.m           = transformMatrix;

                if (selectedFrame != null)
                {
                    Sgml.draw_set_aa(!parentForm.drawModeOn);

                    if (selectedFrame.layers[0].texture != null)
                    {
                        Sgml.draw_surface(origin, selectedFrame.layers[selectedLayer].texture);
                        Sgml.draw_surface(origin, selectedFrame.previewLayer.texture);
                    }

                    Sgml.draw_set_aa(true);

                    // draw cells
                    int        xx     = 0;
                    int        yy     = 0;
                    int        xIndex = 0;
                    int        yIndex = 0;
                    RectangleF temp   = RectangleF.Empty;

                    float x1 = origin.X;
                    float y1 = origin.Y;
                    float x2 = x1 + (int)parentForm.darkNumericUpDown1.Value;
                    float y2 = y1 + (int)parentForm.darkNumericUpDown2.Value;

                    Sgml.draw_set_alpha(0.8);
                    Sgml.draw_set_color(Color.Black);
                    for (var i = 0; i < parentForm.darkNumericUpDown1.Value + 1; i++)
                    {
                        Sgml.draw_line(x1, y1 + i, x2, y1 + i);
                    }

                    for (var i = 0; i < parentForm.darkNumericUpDown2.Value + 1; i++)
                    {
                        Sgml.draw_line(x1 + i, y1, x1 + i, y2);
                    }

                    Sgml.draw_set_alpha(1);
                    Sgml.draw_set_color(Color.White);

                    Sgml.draw_set_aa(false);


                    if (selectedFrame.layers.Count > 0)
                    {
                        if (selectedFrame.layers[0].texture != null)
                        {
                            Sgml.draw_rectangle(origin, new Vector2(selectedFrame.layers[0].texture.Width, selectedFrame.layers[0].texture.Height), true);
                        }
                    }
                }

                basicEffect.View = Matrix.Identity;
                Sgml.m           = Matrix.Identity;

                Sgml.draw_set_color(Color.White);
                Sgml.draw_text(new Vector2(10, 10), framerate.ToString());
                Sgml.draw_text(new Vector2(10, 30), "[X: " + Sgml.round(Sgml.mouse.X - 0.5f) + " Y: " + Sgml.round(Sgml.mouse.Y - 0.5f) + "]");
                // Sgml.draw_text(new Vector2(10, 50), parentForm.darkNumericUpDown1.Value.ToString());
                Sgml.draw_text(new Vector2(10, 70), cam.Zoom.ToString());
                Sgml.draw_text(new Vector2(10, 90), "DIR: " + Sgml.point_direction(toolOriginSubpixel, mouseSubpixel));
                Sgml.draw_text(new Vector2(10, 110), "CLICK: " + toolOriginSubpixel.X + "x " + toolOriginSubpixel.Y + "y");
            }
        }