コード例 #1
0
        private void AnimationPreviewTab()
        {
            _animatedPreviewAnchorMode = false;

            ImGui.InputInt("Zoom", ref _zoomLevel);
            ImGui.Text($"Frame {_controller.CurrentFrameIndex}/{_controller.CurrentAnimationData.FrameIndices.Length}");

            bool paused = !_playing;

            if (ImGui.Button("Play/Pause"))
            {
                _playing = !_playing;
            }
            if (paused)
            {
                ImGui.SameLine();
                if (ImGui.ArrowButton("Prev Frame", ImGuiDir.Left))
                {
                    _controller.ForceNextFrame();
                }
                ImGui.SameLine();
                if (ImGui.ArrowButton("Next Frame", ImGuiDir.Right))
                {
                    _controller.ForcePrevFrame();
                }
            }

            if (_animatedPreviewFb != null)
            {
                FrameBufferTexture texture = _animatedPreviewFb.ColorAttachment;
                (Vector2 uv1, Vector2 uv2) = texture.GetImGuiUV();
                ImGui.Image((IntPtr)texture.Pointer, texture.Size * _zoomLevel, uv1, uv2);
            }
        }
コード例 #2
0
        private void FrameAnchorTab()
        {
            if (_currentAsset == null)
            {
                return;
            }
            _animatedPreviewAnchorMode = true;

            SpriteAnimationFrameSource frameSource = _currentAsset.Content.FrameSource;
            int frameCount = frameSource.GetFrameCount();

            // Ensure data is of correct length. It's possible for it to be malformed if frames were re-detected or
            // user did something wacky.
            frameSource.FrameOrigins ??= new OriginPosition[frameCount];
            if (frameSource.FrameOrigins.Length != frameCount)
            {
                Array.Resize(ref frameSource.FrameOrigins, frameCount);
            }

            frameSource.FrameOffsets ??= new Vector2[frameCount];
            if (frameSource.FrameOffsets.Length != frameCount)
            {
                Array.Resize(ref frameSource.FrameOffsets, frameCount);
            }

            if (frameCount == 0)
            {
                return;
            }

            ImGui.InputInt("Zoom", ref _zoomLevel);

            ImGui.Text("Frame ");
            ImGui.SameLine();
            ImGui.SetNextItemWidth(130);
            ImGui.InputInt("", ref _frameAnchor);
            ImGui.SameLine();
            ImGui.Text($"/{frameCount}");

            if (_frameAnchor < 0)
            {
                _frameAnchor = 0;
            }
            if (_frameAnchor > frameCount - 1)
            {
                _frameAnchor = frameCount - 1;
            }

            var anchorType = (int)frameSource.FrameOrigins[_frameAnchor];

            if (ImGui.Combo("Anchor Type", ref anchorType, string.Join('\0', Enum.GetNames(typeof(OriginPosition)))))
            {
                frameSource.FrameOrigins[_frameAnchor] = (OriginPosition)anchorType;
                _controller.Reset();
                UnsavedChanges();
            }

            ImGui.SameLine();
            if (ImGui.Button("Apply To All"))
            {
                for (var i = 0; i < frameSource.FrameOrigins.Length; i++)
                {
                    frameSource.FrameOrigins[i] = (OriginPosition)anchorType;
                }

                UnsavedChanges();
            }

            if (ImGui.InputFloat2("Additional Offset", ref frameSource.FrameOffsets[_frameAnchor]))
            {
                UnsavedChanges();
            }

            if (_animatedPreviewFb != null)
            {
                FrameBufferTexture texture = _animatedPreviewFb.ColorAttachment;
                (Vector2 uv1, Vector2 uv2) = texture.GetImGuiUV();
                ImGui.Image((IntPtr)texture.Pointer, texture.Size * _zoomLevel, uv1, uv2);
            }
        }
コード例 #3
0
        private void FrameOrderTab()
        {
            AnimatedSprite             currentFileContext = _currentAsset !.Content !;
            SpriteAnimationFrameSource frameSource        = currentFileContext.FrameSource;

            var arraySource = frameSource as SpriteArrayFrameSource;
            var gridSource  = frameSource as SpriteGridFrameSource;

            if (frameSource != null)
            {
                ImGui.Text($"Frames: {currentFileContext.FrameSource.GetFrameCount()}");

                if (arraySource != null)
                {
                    ImGui.SameLine();
                    ImGui.Checkbox("Show Frame Indices", ref _showFrameIdx);
                    ImGui.SameLine();
                    if (ImGui.Button("Re-detect Frames"))
                    {
                        currentFileContext.FrameSource = new SpriteArrayFrameSource(_currentAssetTexture);
                        UnsavedChanges();
                    }
                }

                if (gridSource != null)
                {
                    if (ImGui.InputFloat2("FrameSize", ref gridSource.FrameSize))
                    {
                        _animatedPreviewInvalidated = true;
                        UnsavedChanges();
                    }

                    if (ImGui.InputFloat2("Frame Spacing", ref gridSource.Spacing))
                    {
                        _animatedPreviewInvalidated = true;
                        UnsavedChanges();
                    }
                }
            }

            ImGui.InputInt("Zoom", ref _zoomLevel);
            if (arraySource != null)
            {
                ImGui.Text("Right-click on a frame to select it, and then on another frame to swap their positions.");
            }

            ImGui.BeginChild("FramePreview", new Vector2(-1, -1), true, ImGuiWindowFlags.HorizontalScrollbar);

            // Array source being unordered allows for frames to be reordered.
            if (_textureFb != null && frameSource != null)
            {
                Vector2 winPos = ImGui.GetCursorScreenPos();

                FrameBufferTexture texture = _textureFb.ColorAttachment;
                (Vector2 uv1, Vector2 uv2) = texture.GetImGuiUV();
                ImGui.Image((IntPtr)texture.Pointer, texture.Size * _zoomLevel, uv1, uv2);

                if (arraySource != null && arraySource.Frames != null && ImGui.IsWindowFocused() && Engine.Host.IsKeyDown(Key.MouseKeyRight))
                {
                    Vector2 mPos = ImGui.GetMousePos();
                    mPos -= winPos;

                    int clickedOn = -1;
                    for (var i = 0; i < frameSource.GetFrameCount(); i++)
                    {
                        Rectangle uv = frameSource.GetFrameUV(i);
                        uv *= _zoomLevel;
                        if (!uv.Contains(mPos))
                        {
                            continue;
                        }
                        clickedOn = i;
                        break;
                    }

                    if (clickedOn != -1)
                    {
                        if (_selectedFrame == -1)
                        {
                            _selectedFrame = clickedOn;
                        }
                        else
                        {
                            Rectangle uvSelected = frameSource.GetFrameUV(_selectedFrame);
                            Rectangle uvNew      = frameSource.GetFrameUV(clickedOn);
                            arraySource.Frames[_selectedFrame] = uvNew;
                            arraySource.Frames[clickedOn]      = uvSelected;
                            _selectedFrame = -1;
                            UnsavedChanges();
                        }
                    }
                }
            }

            ImGui.EndChild();
        }