diff --git a/src/app/commands/cmd_goto_frame.cpp b/src/app/commands/cmd_goto_frame.cpp index c7a4ca614..9f21079d4 100644 --- a/src/app/commands/cmd_goto_frame.cpp +++ b/src/app/commands/cmd_goto_frame.cpp @@ -53,7 +53,7 @@ public: protected: frame_t onGetFrame(Editor* editor) override { - return frame_t(0); + return 0; } }; @@ -67,11 +67,9 @@ public: protected: frame_t onGetFrame(Editor* editor) override { frame_t frame = editor->frame(); + frame_t last = editor->sprite()->lastFrame(); - if (frame > frame_t(0)) - return frame-1; - else - return editor->sprite()->lastFrame(); + return (frame > 0 ? frame-1: last); } }; @@ -84,10 +82,9 @@ public: protected: frame_t onGetFrame(Editor* editor) override { frame_t frame = editor->frame(); - if (frame < editor->sprite()->lastFrame()) - return frame+1; - else - return frame_t(0); + frame_t last = editor->sprite()->lastFrame(); + + return (frame < last ? frame+1: 0); } }; @@ -99,15 +96,12 @@ public: protected: frame_t onGetFrame(Editor* editor) override { - Sprite* sprite = editor->sprite(); - frame_t currentFrame = editor->frame(); - FrameTag* tag = get_animation_tag(sprite, currentFrame); - frame_t frameToGo = currentFrame + frame_t(1); + frame_t frame = editor->frame(); + FrameTag* tag = get_animation_tag(editor->sprite(), frame); + frame_t first = (tag ? tag->fromFrame(): 0); + frame_t last = (tag ? tag->toFrame(): editor->sprite()->lastFrame()); - if (frameToGo > tag->toFrame()) - frameToGo = tag->fromFrame(); - - return frameToGo; + return (frame < last ? frame+1: first); } }; @@ -119,15 +113,12 @@ public: protected: frame_t onGetFrame(Editor* editor) override { - Sprite* sprite = editor->sprite(); - frame_t currentFrame = editor->frame(); - FrameTag* tag = get_animation_tag(sprite, currentFrame); - frame_t frameToGo = currentFrame - frame_t(1); + frame_t frame = editor->frame(); + FrameTag* tag = get_animation_tag(editor->sprite(), frame); + frame_t first = (tag ? tag->fromFrame(): 0); + frame_t last = (tag ? tag->toFrame(): editor->sprite()->lastFrame()); - if (frameToGo < tag->fromFrame()) - frameToGo = tag->toFrame(); - - return frameToGo; + return (frame > first ? frame-1: last); } }; @@ -151,8 +142,7 @@ public: Command* clone() const override { return new GotoFrameCommand(*this); } protected: - void onLoadParams(const Params& params) override - { + void onLoadParams(const Params& params) override { std::string frame = params.get("frame"); if (!frame.empty()) m_frame = strtol(frame.c_str(), NULL, 10); else m_frame = 0;