1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-01-24 17:26:41 +00:00

more fixes and improvements to anim editor; eliminate OutlineRect

This commit is contained in:
fgenesis 2025-01-12 18:42:58 +01:00
parent db2b71c3d8
commit 63892518cd
6 changed files with 68 additions and 111 deletions

View file

@ -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;
}
if(doUpdateBones)
{
for(size_t i = 0; i < NumPages; ++i)
getPageSprite(i)->updateBones();
{
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;

View file

@ -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;

View file

@ -77,7 +77,6 @@ set(BBGE_SRCS
RenderObject.h
RenderObject_inline.h
RenderObjectLayer.cpp
RenderRect.cpp
RenderState.cpp
RenderState.h
RoundedRect.cpp

View file

@ -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;

View file

@ -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();
}

View file

@ -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++)
{