Ejemplo n.º 1
0
        public void AaToggled()
        {
            if (parentForm == null)
            {
                if (selectedXIndex != -1 && selectedYIndex != -1)
                {
                    selectedImageIndex = 1;
                    // imageOverlay = Sgml.surface_create((int)parentForm.darkNumericUpDown1.Value, (int)parentForm.darkNumericUpDown2.Value);

                    Sgml.surface_set_target(imageOverlay);
                    Sgml.draw_clear_transparent();
                    Sgml.surface_reset_target();
                }
                return;
            }

            if (parentForm.drawModeOn)
            {
                if (selectedXIndex != -1 && selectedYIndex != -1)
                {
                    selectedImageIndex = 1;
                    // imageOverlay = Sgml.surface_create((int)parentForm.darkNumericUpDown1.Value, (int)parentForm.darkNumericUpDown2.Value);

                    Sgml.surface_set_target(imageOverlay);
                    Sgml.draw_clear_transparent();
                    Sgml.surface_reset_target();
                }
            }
        }
Ejemplo n.º 2
0
        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            cam.UpdatePosition();

            var originalPos  = cam.Camera.Position;
            var originalZoom = cam.Camera.Zoom;

            Matrix view = cam.Camera.GetViewMatrix();

            cam.Camera.Position = new Vector2(0, 0);
            cam.Camera.Zoom     = 1;

            Matrix normalizedMatrix = cam.Camera.GetViewMatrix();

            cam.Camera.Position = originalPos;
            cam.Camera.Zoom     = originalZoom;

            Sgml.world            = world;
            Sgml.view             = view;
            Sgml.normalizedMatrix = normalizedMatrix;

            if (selectedFrame != null)
            {
                if (ms.LeftButton == ButtonState.Pressed ^ ms.RightButton == ButtonState.Pressed)
                {
                    if (activeTool == Tools.Pixel || activeTool == Tools.Rubber || activeTool == Tools.Fill)
                    {
                        ToolDraw(ms.LeftButton == ButtonState.Pressed ? penColor : penColorRight);
                    }
                }

                if ((ms.LeftButton == ButtonState.Released && msPrev.LeftButton == ButtonState.Pressed && toolPreview) ^ (ms.RightButton == ButtonState.Released && msPrev.RightButton == ButtonState.Pressed && toolPreview))
                {
                    if (activeTool == Tools.Ellipse || activeTool == Tools.Rectangle || activeTool == Tools.Line || activeTool == Tools.RoundedRectangle)
                    {
                        ToolDraw(msPrev.LeftButton == ButtonState.Pressed ? penColor : penColorRight);
                        over = true;
                    }

                    toolPreview = false;
                }

                Sgml.draw_set_color(ms.LeftButton == ButtonState.Pressed ? penColor : penColorRight);

                // render preview
                toolOriginSubpixel.X = toolOrigin.X; //(float)Math.Floor(toolOrigin.X >= Sgml.mouse.X ? toolOrigin.X + .5f : toolOrigin.X - .5f);
                toolOriginSubpixel.Y = toolOrigin.Y; //(float)Math.Floor(toolOrigin.Y >= Sgml.mouse.Y ? toolOrigin.Y + .5f : toolOrigin.Y - .5f);

                mouseSubpixel.X = (float)Math.Floor(Sgml.mouse.X);
                mouseSubpixel.Y = (float)Math.Floor(Sgml.mouse.Y);

                mouseSubpixel.X += mouseSubpixel.X > toolOriginSubpixel.X ? 1 : 0;
                mouseSubpixel.Y += mouseSubpixel.Y > toolOriginSubpixel.Y ? 1 : 0;


                Sgml.surface_set_target(selectedFrame.previewLayer.texture);
                Sgml.draw_clear_transparent();
                Sgml.draw_set_color(ms.LeftButton == ButtonState.Pressed ? penColor : penColorRight);


                if (activeTool == Tools.Pixel)
                {
                    Sgml.draw_rectangle(new Vector2((float)Sgml.round(Sgml.mouse.X - .5f), (float)Sgml.round(Sgml.mouse.Y - .5f)), new Vector2((float)Sgml.round(Sgml.mouse.X + .5f), (float)Sgml.round(Sgml.mouse.Y + .5f)), false);
                }

                if (toolPreview)
                {
                    if (activeTool == Tools.Ellipse)
                    {
                        Sgml.draw_ellipse(new Vector2(Sgml.mouse.X - toolOrigin.X, Sgml.mouse.Y - toolOrigin.Y), toolOrigin, 1);
                    }

                    else if (activeTool == Tools.Rectangle)
                    {
                        float my = Sgml.mouse.Y;
                        my = (float)Sgml.floor(my) + .5f;

                        Sgml.draw_rectangle(toolOrigin, new Vector2(Sgml.mouse.X, my), true);
                    }

                    else if (activeTool == Tools.Line)
                    {
                        Sgml.draw_rectangle(new Vector2((float)Sgml.round(toolOriginINP.X - .5f), (float)Sgml.round(toolOriginINP.Y - .5f)), new Vector2((float)Sgml.round(toolOriginINP.X + .5f), (float)Sgml.round(toolOriginINP.Y + .5f)), false);
                        Sgml.draw_line(mouseSubpixel, toolOriginSubpixel);
                    }
                    else if (activeTool == Tools.RoundedRectangle)
                    {
                        Sgml.draw_roundrect(toolOrigin, new Vector2(Sgml.mouse.X, Sgml.mouse.Y), true, 1);
                    }
                }

                Sgml.surface_reset_target();

                if ((ms.LeftButton == ButtonState.Pressed && !toolPreview) ^ (ms.RightButton == ButtonState.Pressed && !toolPreview))
                {
                    if (!over)
                    {
                        toolOriginINP = new Vector2(Sgml.mouse.X, Sgml.mouse.Y);
                        toolOrigin.X  = (float)Sgml.round(Sgml.mouse.X - 0.5f) + .5f;
                        toolOrigin.Y  = (float)Sgml.round(Sgml.mouse.Y - 0.5f) + .5f;

                        toolPreview = true;
                    }
                    else
                    {
                        over = false;
                    }
                }
            }


            // Update frame if user pushed autoplay btn
            if (parentForm.darkButton33.Pushed)
            {
                animateIn--;

                if (animateIn <= 0)
                {
                    animateIn = (int)parentForm.darkNumericUpDown5.Value;

                    selectedImageIndex++;

                    if (selectedImageIndex >= Frames.Count)
                    {
                        selectedImageIndex = 0;
                    }

                    selectedFrame = Frames[selectedImageIndex];
                    parentForm.darkImageIndex1.SelectedFrame = selectedImageIndex;
                    parentForm.darkImageIndex1.Invalidate();
                }
            }

            msPrev = ms;
        }