Skip to content

Commit

Permalink
Add keyframe editor ;
Browse files Browse the repository at this point in the history
  • Loading branch information
hoshiryu committed Apr 24, 2020
1 parent 1b99766 commit 6437fd3
Show file tree
Hide file tree
Showing 17 changed files with 3,536 additions and 6 deletions.
13 changes: 13 additions & 0 deletions cmake/filelistGuiBase.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
set( guibase_sources
BaseApplication.cpp
KeyFrameEditor/KeyFrameEditor.cpp
KeyFrameEditor/KeyFrameEditorFrame.cpp
KeyFrameEditor/KeyFrameEditorFrameScale.cpp
KeyFrameEditor/KeyFrameEditorScrollArea.cpp
KeyFrameEditor/KeyFrameEditorTimeScale.cpp
KeyFrameEditor/KeyFrameEditorValueScale.cpp
SelectionManager/SelectionManager.cpp
Timeline/HelpDialog.cpp
Timeline/TimelineFrameSelector.cpp
Expand Down Expand Up @@ -30,6 +36,12 @@ set( guibase_headers
BaseApplication.hpp
MainWindowInterface.hpp
RaGuiBase.hpp
KeyFrameEditor/KeyFrameEditor.h
KeyFrameEditor/KeyFrameEditorFrame.h
KeyFrameEditor/KeyFrameEditorFrameScale.h
KeyFrameEditor/KeyFrameEditorScrollArea.h
KeyFrameEditor/KeyFrameEditorTimeScale.h
KeyFrameEditor/KeyFrameEditorValueScale.h
SelectionManager/SelectionManager.hpp
Timeline/HelpDialog.hpp
Timeline/Configurations.h
Expand Down Expand Up @@ -63,6 +75,7 @@ set( guibase_inlines
)

set( guibase_uis
KeyFrameEditor/KeyFrameEditor.ui
Timeline/HelpDialog.ui
Timeline/Timeline.ui
)
Expand Down
94 changes: 94 additions & 0 deletions src/GuiBase/KeyFrameEditor/KeyFrameEditor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#include "ui_KeyFrameEditor.h"
#include <GuiBase/KeyFrameEditor/KeyFrameEditor.h>
#include <GuiBase/KeyFrameEditor/KeyFrameEditorFrame.h>

#include <Core/Animation/KeyFramedValue.hpp>

#include <fstream>
#include <iostream>

#include <QFileDialog>
#include <QResizeEvent>

namespace Ra::GuiBase {

KeyFrameEditor::KeyFrameEditor( Scalar maxTime, QWidget* parent ) :
QDialog( parent ),
ui( new Ui::KeyFrameEditor ) {
ui->setupUi( this );

// set sizePolicy to allow zoom in scrollArea
ui->scrollAreaWidgetContents->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Preferred );
// first draw of ruler with current width (default in Timeline.ui) of dialog
ui->scrollArea->onDrawRuler( width() - 2,
height() - 2 ); // left/right border width = 2 *1 pixel

// --- SET INTERNAL REFERENCES ---
ui->m_editorFrame->setEditorUi( ui );
ui->m_timeScale->setScrollArea( ui->scrollArea );
ui->m_valueScale->setScrollArea( ui->scrollArea );
ui->m_frameScale->setScrollArea( ui->scrollArea );
ui->m_frameScale->setEditorFrame( ui->m_editorFrame );

// set duration
ui->m_editorFrame->setDuration( maxTime );

// --- CREATE INTERNAL CONNECTIONS ---
connect( ui->m_editorFrame, &KeyFrameEditorFrame::updated, [=]() { update(); } );

// --- CONNECT INTERNAL SIGNALS TO EXTERNAL SIGNALS ---
connect( ui->m_editorFrame,
&KeyFrameEditorFrame::cursorChanged,
this,
&KeyFrameEditor::cursorChanged );
connect( ui->m_editorFrame,
&KeyFrameEditorFrame::keyFrameChanged,
this,
&KeyFrameEditor::keyFrameChanged );
connect( ui->m_editorFrame,
&KeyFrameEditorFrame::keyFrameAdded,
this,
&KeyFrameEditor::keyFrameAdded );
connect( ui->m_editorFrame,
&KeyFrameEditorFrame::keyFrameDeleted,
this,
&KeyFrameEditor::keyFrameDeleted );
connect( ui->m_editorFrame,
&KeyFrameEditorFrame::keyFrameMoved,
this,
&KeyFrameEditor::keyFrameMoved );
connect( ui->m_editorFrame,
&KeyFrameEditorFrame::keyFramesMoved,
this,
&KeyFrameEditor::keyFramesMoved );
}

KeyFrameEditor::~KeyFrameEditor() {
delete ui;
}

void KeyFrameEditor::onChangeCursor( Scalar time ) {
ui->m_editorFrame->onChangeCursor( time, false );
update();
}

void KeyFrameEditor::onChangeDuration( Scalar duration ) {
ui->m_editorFrame->setDuration( duration );
update();
}

void KeyFrameEditor::onUpdateKeyFrames( Scalar currentTime ) {
ui->m_editorFrame->onUpdateKeyFrames( currentTime );
}

void KeyFrameEditor::resizeEvent( QResizeEvent* event ) {

ui->scrollArea->onDrawRuler( event->size().width() - 2, event->size().height() - 2 );
}

void KeyFrameEditor::setKeyFramedValue( const std::string& name, KeyFrame* frame ) {
ui->m_valueName->setText( QString::fromStdString( name ) );
ui->m_editorFrame->setKeyFramedValue( frame );
}

} // namespace Ra::GuiBase
75 changes: 75 additions & 0 deletions src/GuiBase/KeyFrameEditor/KeyFrameEditor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#ifndef RADIUMENGINE_KEYFRAME_EDITOR_H
#define RADIUMENGINE_KEYFRAME_EDITOR_H

#include <GuiBase/RaGuiBase.hpp>

#include <map>
#include <vector>

#include <QDialog>
#include <QGraphicsEllipseItem>
#include <QGraphicsLineItem>
#include <QGraphicsScene>

#include <Core/CoreMacros.hpp>

namespace Ra::Core::Animation {
class KeyFramedValueBase;
}

namespace Ui {
class KeyFrameEditor;
} // namespace Ui

namespace Ra::GuiBase {

class RA_GUIBASE_API KeyFrameEditor : public QDialog
{
Q_OBJECT
public:
using KeyFrame = Ra::Core::Animation::KeyFramedValueBase;
explicit KeyFrameEditor( Scalar maxTime = 0, QWidget* parent = nullptr );
~KeyFrameEditor() override;

/// Set the KeyFramedValue to edit.
void setKeyFramedValue( const std::string& name, KeyFrame* frame );

signals:
/// Emitted when the user changes the current time in the editor frame.
void cursorChanged( Scalar time );

/// Emitted when the user changes a keyframe's value in the editor frame.
void keyFrameChanged( Scalar time );

/// Emitted when the user adds a keyframe to the KeyFramedValue in the editor frame.
void keyFrameAdded( Scalar time );

/// Emitted when the user removes a keyframe from the KeyFramedValue in the editor frame.
void keyFrameDeleted( Scalar time );

/// Emitted when the user changes a keyframe's time in the editor frame.
void keyFrameMoved( Scalar time0, Scalar time1 );

/// Emitted when the user offsets keyframes time in the editor frame.
void keyFramesMoved( Scalar time, Scalar offset );

public slots:
/// Update the editor frame to match the given time.
void onChangeCursor( Scalar time );

/// Update the editor frame to match the given duration.
void onChangeDuration( Scalar duration );

/// Update the editor frame to match the updated KeyFramedValue.
void onUpdateKeyFrames( Scalar currentTime );

protected:
void resizeEvent( QResizeEvent* ev ) override;

private:
Ui::KeyFrameEditor* ui;
};

} // namespace Ra::GuiBase

#endif // RADIUMENGINE_KEYFRAME_EDITOR_H
Loading

0 comments on commit 6437fd3

Please sign in to comment.