From 63892518cd380cc7cb0a9af0b35ecd0d07c8de4d Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sun, 12 Jan 2025 18:42:58 +0100 Subject: [PATCH] more fixes and improvements to anim editor; eliminate OutlineRect --- Aquaria/AnimationEditor.cpp | 99 ++++++++++++++++++++++++------------- Aquaria/AnimationEditor.h | 2 + BBGE/CMakeLists.txt | 1 - BBGE/Quad.h | 14 ------ BBGE/RenderRect.cpp | 61 ----------------------- BBGE/SkeletalSprite.cpp | 2 +- 6 files changed, 68 insertions(+), 111 deletions(-) delete mode 100644 BBGE/RenderRect.cpp diff --git a/Aquaria/AnimationEditor.cpp b/Aquaria/AnimationEditor.cpp index 2178695..08f78fd 100644 --- a/Aquaria/AnimationEditor.cpp +++ b/Aquaria/AnimationEditor.cpp @@ -76,7 +76,11 @@ class TimelineTickRender : public RenderObject { public: TimelineTickRender() + : bg("black", Vector(400, 0)) { + addChild(&bg, PM_STATIC, RBP_ON); + bg.setWidthHeight(800, TIMELINE_HEIGHT); + bg.alphaMod = 0.2f; } virtual ~TimelineTickRender() @@ -84,6 +88,7 @@ public: } private: + Quad bg; void onRender(const RenderState& rs) const OVERRIDE { glLineWidth(1); @@ -247,15 +252,32 @@ struct AnimationEditorPage } }; +bool AnimationEditor::isMouseInRect() const +{ + Vector mp=core->mouse.position; + const float w2 = rect->width * 0.5f; + const float h2 = rect->height * 0.5f; + const float left = rect->position.x - w2; + const float right = rect->position.x + w2; + const float top = rect->position.y - h2; + const float btm = rect->position.y + h2; + return mp.x >= left && mp.x <= right && mp.y >= top && mp.y <= btm; +} void AnimationEditor::constrainMouse() { Vector mp=core->mouse.position; + const float w2 = rect->width * 0.5f; + const float h2 = rect->height * 0.5f; + const float left = rect->position.x - w2; + const float right = rect->position.x + w2; + const float top = rect->position.y - h2; + const float btm = rect->position.y + h2; bool doit = false; - if (mp.x < 200) { mp.x = 200; doit = true; } // FIXME: actually check box coords - if (mp.x > 600) { mp.x = 600; doit = true; } - if (mp.y < 100) { mp.y = 100; doit = true; } - if (mp.y > 500) { mp.y = 500; doit = true; } + if (mp.x < left ) { mp.x = left; doit = true; } + if (mp.x > right) { mp.x = right; doit = true; } + if (mp.y < top ) { mp.y = top; doit = true; } + if (mp.y > btm ) { mp.y = btm; doit = true; } if(doit) core->setMousePosition(mp); @@ -685,10 +707,13 @@ void AnimationEditor::applyState() addRenderObject(bAssist, LR_MENU); bSplineAssist = bAssist; - - OutlineRect *rect = new OutlineRect; + rect = new Quad("black", Vector(400,300+yoffs)); + rect->alphaMod = 0.2f; + rect->renderBorder = true; + rect->renderCenter = false; + rect->borderAlpha = 5; // HACK to compensate alphaMod + rect->renderBorderColor = Vector(1,1,1); rect->setWidthHeight(400,400); - rect->position = Vector(400,300+yoffs); addRenderObject(rect, LR_MENU); text = new DebugFont(); @@ -831,7 +856,8 @@ void AnimationEditor::reorderKeys() void AnimationEditor::rebuildKeyframeWidgets() { - size_t n = getCurrentPageAnimation()->getNumKeyframes(); + Animation *a = getCurrentPageAnimation(); + size_t n = a ? a->getNumKeyframes() : 0; pages[curPage].timeline->resizeKeyframes(n); } @@ -1074,6 +1100,8 @@ void AnimationEditor::update(float dt) constrainMouse(); } } + + bool doUpdateBones = false; if (editMode == AE_SELECT) { float t = 0; @@ -1106,11 +1134,13 @@ void AnimationEditor::update(float dt) if(Animation *a = spr->getCurrentAnimationOrNull()) { float len = a->getAnimationLength(); + float tt = t; if(len && mod) - t = fmodf(t, len); - spr->setTime(t); + tt = fmodf(tt, len); + spr->setTime(tt); } } + doUpdateBones = true; } } @@ -1120,8 +1150,16 @@ void AnimationEditor::update(float dt) splinegrid->wasModified = false; } - for(size_t i = 0; i < NumPages; ++i) - getPageSprite(i)->updateBones(); + if(doUpdateBones) + { + for(size_t i = 0; i < NumPages; ++i) + { + SkeletalSprite *spr = getPageSprite(i); + if(spr->isLoaded() && !spr->isAnimating()) + spr->updateBones(); + } + } + } void AnimationEditor::_copyKey() @@ -1179,10 +1217,10 @@ void AnimationEditor::nextKey() keyframeWidgets[i]->shiftLeft(); } } - else + else if(Animation *a = editSprite->getCurrentAnimation()) { currentKey++; - SkeletalKeyframe *k = editSprite->getCurrentAnimation()->getKeyframe(currentKey); + SkeletalKeyframe *k = a->getKeyframe(currentKey); if (k) editSprite->setTime(k->t); else @@ -1214,12 +1252,12 @@ void AnimationEditor::prevKey() keyframeWidgets[i]->shiftRight(); } } - else + else if(Animation *a = editSprite->getCurrentAnimation()) { if (currentKey > 0) { currentKey --; - SkeletalKeyframe *k = editSprite->getCurrentAnimation()->getKeyframe(currentKey); + SkeletalKeyframe *k = a->getKeyframe(currentKey); if (k) editSprite->setTime(k->t); @@ -1375,11 +1413,7 @@ void AnimationEditor::lmbd() { pushUndo(); updateEditingBone(); - if (editingBone - - && core->mouse.position.x > 400-200 && core->mouse.position.x < 400+200 - && core->mouse.position.y > 300-200 && core->mouse.position.y < 300+200 - ) + if (editingBone && isMouseInRect() && !editingBoneSprite->isAnimating()) { cursorOffset = editingBone->getWorldPosition() - core->mouse.position; editMode = AE_EDITING_MOVE; @@ -1425,12 +1459,11 @@ void AnimationEditor::applyTranslation() else { // all bones in all anims mode - SkeletalSprite *editSprite = getCurrentPageSprite(); - for (size_t a = 0; a < editSprite->animations.size(); ++a) + for (size_t a = 0; a < editingBoneSprite->animations.size(); ++a) { - for (size_t i = 0; i < editSprite->animations[a].getNumKeyframes(); ++i) + for (size_t i = 0; i < editingBoneSprite->animations[a].getNumKeyframes(); ++i) { - BoneKeyframe *b = editSprite->animations[a].getKeyframe(i)->getBoneKeyframe(editingBone->boneIdx); + BoneKeyframe *b = editingBoneSprite->animations[a].getKeyframe(i)->getBoneKeyframe(editingBone->boneIdx); if (b) { b->x += xdiff; @@ -1470,7 +1503,7 @@ void AnimationEditor::rmbd() if(editMode == AE_SELECT) { updateEditingBone(); - if (editingBone) + if (editingBone && !editingBoneSprite->isAnimating()) { pushUndo(); cursorOffset = core->mouse.position; @@ -1531,12 +1564,11 @@ void AnimationEditor::flipRot() else { // all bones in all anims mode - SkeletalSprite *editSprite = getCurrentPageSprite(); - for (size_t a = 0; a < editSprite->animations.size(); ++a) + for (size_t a = 0; a < editingBoneSprite->animations.size(); ++a) { - for (size_t i = 0; i < editSprite->animations[a].getNumKeyframes(); ++i) + for (size_t i = 0; i < editingBoneSprite->animations[a].getNumKeyframes(); ++i) { - BoneKeyframe *b = editSprite->animations[a].getKeyframe(i)->getBoneKeyframe(editingBone->boneIdx); + BoneKeyframe *b = editingBoneSprite->animations[a].getKeyframe(i)->getBoneKeyframe(editingBone->boneIdx); if (b) { b->rot = -b->rot; @@ -1615,12 +1647,11 @@ void AnimationEditor::rmbu() else { // all bones in all anims mode - SkeletalSprite *editSprite = getCurrentPageSprite(); - for (size_t a = 0; a < editSprite->animations.size(); ++a) + for (size_t a = 0; a < editingBoneSprite->animations.size(); ++a) { - for (size_t i = 0; i < editSprite->animations[a].getNumKeyframes(); ++i) + for (size_t i = 0; i < editingBoneSprite->animations[a].getNumKeyframes(); ++i) { - BoneKeyframe *b = editSprite->animations[a].getKeyframe(i)->getBoneKeyframe(editingBone->boneIdx); + BoneKeyframe *b = editingBoneSprite->animations[a].getKeyframe(i)->getBoneKeyframe(editingBone->boneIdx); if (b) { b->rot += rotdiff; diff --git a/Aquaria/AnimationEditor.h b/Aquaria/AnimationEditor.h index 067abe4..9fbdd9c 100644 --- a/Aquaria/AnimationEditor.h +++ b/Aquaria/AnimationEditor.h @@ -158,8 +158,10 @@ public: void updateButtonLabels(); void toggleGradient(); float getMouseTimelineTime() const; // <0 when not in timeline area + bool isMouseInRect() const; Gradient *bgGrad; + Quad *rect; Animation *getPageAnimation(size_t page) const; Animation *getCurrentPageAnimation() const; diff --git a/BBGE/CMakeLists.txt b/BBGE/CMakeLists.txt index c832cb2..8b62c91 100644 --- a/BBGE/CMakeLists.txt +++ b/BBGE/CMakeLists.txt @@ -77,7 +77,6 @@ set(BBGE_SRCS RenderObject.h RenderObject_inline.h RenderObjectLayer.cpp - RenderRect.cpp RenderState.cpp RenderState.h RoundedRect.cpp diff --git a/BBGE/Quad.h b/BBGE/Quad.h index 0258716..df7316b 100644 --- a/BBGE/Quad.h +++ b/BBGE/Quad.h @@ -24,20 +24,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "RenderObject.h" #include "DataStructures.h" -class OutlineRect : public RenderObject -{ -public: - OutlineRect(); - void setWidthHeight(int w, int h); - void setLineSize(int ls); - -protected: - - int w, h, w2, h2; - int lineSize; - - void onRender(const RenderState& rs) const OVERRIDE; -}; class DynamicRenderGrid; diff --git a/BBGE/RenderRect.cpp b/BBGE/RenderRect.cpp deleted file mode 100644 index 21ddb7b..0000000 --- a/BBGE/RenderRect.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* -Copyright (C) 2007, 2010 - Bit-Blot - -This file is part of Aquaria. - -Aquaria is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#include "Quad.h" -#include "RenderBase.h" - -OutlineRect::OutlineRect() : RenderObject() -{ - lineSize = 1; -} - -void OutlineRect::setWidthHeight(int w, int h) -{ - this->w = w; - this->h = h; - w2 = w/2; - h2 = h/2; -} - -void OutlineRect::setLineSize(int ls) -{ - lineSize = ls; -} - -void OutlineRect::onRender(const RenderState& rs) const -{ - glLineWidth(lineSize); - glBegin(GL_LINES); - // l - glVertex2f(-w2,-h2); - glVertex2f(-w2,h2); - // r - glVertex2f(w2,-h2); - glVertex2f(w2,h2); - // u - glVertex2f(-w2,-h2); - glVertex2f(w2,-h2); - // d - glVertex2f(-w2,h2); - glVertex2f(w2,h2); - glEnd(); -} - - diff --git a/BBGE/SkeletalSprite.cpp b/BBGE/SkeletalSprite.cpp index 746c62c..07d7bb3 100644 --- a/BBGE/SkeletalSprite.cpp +++ b/BBGE/SkeletalSprite.cpp @@ -2092,7 +2092,7 @@ void SkeletalSprite::setFreeze(bool f) void SkeletalSprite::updateBones() { - if (!frozen && isLoaded()) + if (!frozen) { for (size_t i = 0; i < animLayers.size(); i++) {