Skip to content

Commit

Permalink
Working on blur and a preview window. WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlamhauge committed Jul 19, 2023
1 parent 06705d0 commit cf17d94
Show file tree
Hide file tree
Showing 23 changed files with 465 additions and 48 deletions.
2 changes: 2 additions & 0 deletions app/data/app.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
<file>icons/new/svg/camera-move.svg</file>
<file>icons/new/svg/camera-rotate.svg</file>
<file>icons/new/svg/camera-scale.svg</file>
<file>icons/controls/preview_off-32.png</file>
<file>icons/controls/preview_on-32.png</file>
</qresource>
<qresource prefix="/app">
<file>icons/onion-blue.png</file>
Expand Down
Binary file added app/data/icons/controls/preview_off-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/data/icons/controls/preview_on-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions core_lib/core_lib.pro
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ HEADERS += \
src/interface/editor.h \
src/interface/flowlayout.h \
src/interface/layerpropertiesdialog.h \
src/interface/previewwindow.h \
src/interface/recentfilemenu.h \
src/interface/scribblearea.h \
src/interface/timecontrols.h \
Expand Down Expand Up @@ -120,7 +121,7 @@ HEADERS += \
src/qminiz.h \
src/activeframepool.h \
src/external/platformhandler.h \
src/selectionpainter.h
src/selectionpainter.h \

SOURCES += src/graphics/bitmap/bitmapimage.cpp \
src/graphics/bitmap/bitmapbucket.cpp \
Expand All @@ -136,6 +137,7 @@ SOURCES += src/graphics/bitmap/bitmapimage.cpp \
src/interface/editor.cpp \
src/interface/flowlayout.cpp \
src/interface/layerpropertiesdialog.cpp \
src/interface/previewwindow.cpp \
src/interface/recentfilemenu.cpp \
src/interface/scribblearea.cpp \
src/interface/timecontrols.cpp \
Expand Down Expand Up @@ -199,11 +201,12 @@ SOURCES += src/graphics/bitmap/bitmapimage.cpp \
src/miniz.cpp \
src/qminiz.cpp \
src/activeframepool.cpp \
src/selectionpainter.cpp
src/selectionpainter.cpp \

FORMS += \
ui/camerapropertiesdialog.ui \
ui/layerpropertiesdialog.ui
ui/layerpropertiesdialog.ui \
ui/previewwindow.ui

win32 {
INCLUDEPATH += src/external/win32
Expand Down
9 changes: 7 additions & 2 deletions core_lib/src/canvaspainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ GNU General Public License for more details.

#include "log.h"
#include "object.h"

#include "layerbitmap.h"
#include "layervector.h"
#include "bitmapimage.h"
Expand Down Expand Up @@ -138,7 +139,8 @@ void CanvasPainter::renderPreLayers(QPainter& painter)
paintCurrentFrame(painter, 0, mCurrentLayerIndex - 1);
}

paintOnionSkin(painter);
if (!mOnionSkinPainterOptions.mNoPlaybackMode)
paintOnionSkin(painter);
painter.setOpacity(1.0);
}

Expand Down Expand Up @@ -455,7 +457,10 @@ void CanvasPainter::paintCurrentFrame(QPainter& painter, int startLayer, int end
CANVASPAINTER_LOG(" Render Layer[%d] %s", i, layer->name());
switch (layer->type())
{
case Layer::BITMAP: { paintBitmapFrame(painter, layer, mFrameNumber, false, true, i == mCurrentLayerIndex); break; }
case Layer::BITMAP:
{
paintBitmapFrame(painter, layer, mFrameNumber, false, true, i == mCurrentLayerIndex); break;
}
case Layer::VECTOR: { paintVectorFrame(painter, layer, mFrameNumber, false, true, i == mCurrentLayerIndex); break; }
default: break;
}
Expand Down
2 changes: 2 additions & 0 deletions core_lib/src/canvaspainter.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ class CanvasPainter
int mCurrentLayerIndex = 0;
int mFrameNumber = 0;
BitmapImage* mBuffer = nullptr;
BitmapImage* mCloneBuffer = nullptr; // to clone original, so original is preserved
BitmapImage* mBlurBuffer = nullptr; // the blurred image buffer

QImage mScaledBitmap;

Expand Down
57 changes: 57 additions & 0 deletions core_lib/src/interface/previewwindow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include "previewwindow.h"
#include "ui_previewwindow.h"

#include "layermanager.h"

PreviewWindow::PreviewWindow(QWidget *parent) :
QWidget(parent),
ui(new Ui::PreviewWindow)
{
ui->setupUi(this);

connect(ui->btn5back, &QPushButton::clicked, this, &PreviewWindow::fiveBackwards);
connect(ui->btn1back, &QPushButton::clicked, this, &PreviewWindow::oneBackwards);
connect(ui->btn1fwd, &QPushButton::clicked, this, &PreviewWindow::oneForwards);
connect(ui->btn5fwd, &QPushButton::clicked, this, &PreviewWindow::fiveForwards);
connect(ui->btnClose, &QPushButton::clicked, this, &PreviewWindow::exitWindow);
}

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

void PreviewWindow::setCore(Editor *editor)
{
mEditor = editor;
}

void PreviewWindow::fiveBackwards()
{
if (mEditor->currentFrame() > 5)
mEditor->scrubTo(mEditor->currentFrame() - 5);
else
mEditor->scrubTo(1);
}

void PreviewWindow::oneBackwards()
{
if (mEditor->currentFrame() > 1)
mEditor->scrubBackward();
}

void PreviewWindow::oneForwards()
{
mEditor->scrubForward();
}

void PreviewWindow::fiveForwards()
{
mEditor->scrubTo(mEditor->currentFrame() + 5);
}

void PreviewWindow::exitWindow()
{
mEditor->layers()->setIsPreview(false);
close();
}
35 changes: 35 additions & 0 deletions core_lib/src/interface/previewwindow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifndef PREVIEWWINDOW_H
#define PREVIEWWINDOW_H

#include <QWidget>
#include <editor.h>

class Editor;

namespace Ui {
class PreviewWindow;
}

class PreviewWindow : public QWidget
{
Q_OBJECT

public:
explicit PreviewWindow(QWidget *parent = nullptr);
~PreviewWindow();

void setCore(Editor* editor);

private:
Ui::PreviewWindow *ui;

void fiveBackwards();
void oneBackwards();
void oneForwards();
void fiveForwards();
void exitWindow();

Editor* mEditor = nullptr;
};

#endif // PREVIEWWINDOW_H
11 changes: 9 additions & 2 deletions core_lib/src/interface/scribblearea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ ScribbleArea::~ScribbleArea()
bool ScribbleArea::init()
{
mPrefs = mEditor->preference();
mPlayback = mEditor->playback();
mDoubleClickTimer = new QTimer(this);
mMouseFilterTimer = new QTimer(this);

Expand Down Expand Up @@ -188,13 +189,19 @@ void ScribbleArea::setEffect(SETTING e, bool isOn)

void ScribbleArea::updateCurrentFrame()
{
updateFrame(mEditor->currentFrame());
if (mEditor->layers()->getIsPreview())
mEditor->layers()->blurCurrentFrame(mEditor->currentFrame());
else
updateFrame(mEditor->currentFrame());
}

void ScribbleArea::updateFrame(int frame)
{
Q_ASSERT(frame >= 0);
update();
if (mEditor->layers()->getIsPreview())
mEditor->layers()->blurCurrentFrame(mEditor->currentFrame());
else
update();
}

void ScribbleArea::invalidateCacheForDirtyFrames()
Expand Down
2 changes: 2 additions & 0 deletions core_lib/src/interface/scribblearea.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class BaseTool;
class PointerEvent;
class BitmapImage;
class VectorImage;
class PlaybackManager;


class ScribbleArea : public QWidget
Expand Down Expand Up @@ -294,6 +295,7 @@ public slots:
QPointF mTransformedCursorPos;

PreferenceManager* mPrefs = nullptr;
PlaybackManager* mPlayback = nullptr;

QPixmap mCanvas;
CanvasPainter mCanvasPainter;
Expand Down
27 changes: 26 additions & 1 deletion core_lib/src/interface/timecontrols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ GNU General Public License for more details.
#include "preferencemanager.h"
#include "timeline.h"
#include "pencildef.h"
#include "previewwindow.h"

TimeControls::TimeControls(TimeLine* parent) : QToolBar(parent)
{
Expand Down Expand Up @@ -103,6 +104,7 @@ void TimeControls::initUI()
mLoopButton = new QPushButton(this);
mSoundButton = new QPushButton(this);
mSoundScrubButton = new QPushButton(this);
mPreviewButton = new QPushButton(this);
mJumpToEndButton = new QPushButton(this);
mJumpToStartButton = new QPushButton(this);

Expand All @@ -113,6 +115,8 @@ void TimeControls::initUI()
mSoundScrubIcon = QIcon();
mSoundScrubIcon.addFile(":icons/controls/soundscrub.png", QSize(), QIcon::Normal, QIcon::On);
mSoundScrubIcon.addFile(":icons/controls/soundscrub-disabled.png", QSize(), QIcon::Normal, QIcon::Off);
mPreviewIcon = QIcon();
mPreviewIcon.addFile(":icons/controls/preview_on-32.png");
mJumpToEndIcon = QIcon(":icons/controls/endplay.png");
mJumpToStartIcon = QIcon(":icons/controls/startplay.png");
mStartIcon = QIcon(":icons/controls/play.png");
Expand All @@ -121,13 +125,15 @@ void TimeControls::initUI()
mLoopButton->setIcon(mLoopIcon);
mSoundButton->setIcon(mSoundIcon);
mSoundScrubButton->setIcon(mSoundScrubIcon);
mPreviewButton->setIcon(mPreviewIcon);
mJumpToEndButton->setIcon(mJumpToEndIcon);
mJumpToStartButton->setIcon(mJumpToStartIcon);

mPlayButton->setToolTip(tr("Play"));
mLoopButton->setToolTip(tr("Loop"));
mSoundButton->setToolTip(tr("Sound on/off"));
mSoundScrubButton->setToolTip(tr("Sound scrub on/off"));
mPreviewButton->setToolTip(tr("Preview window"));
mJumpToEndButton->setToolTip(tr("Jump to the End", "Tooltip of the jump to end button"));
mJumpToStartButton->setToolTip(tr("Jump to the Start", "Tooltip of the jump to start button"));

Expand All @@ -137,7 +143,6 @@ void TimeControls::initUI()
mSoundScrubButton->setCheckable(true);
mSoundScrubButton->setChecked(mEditor->preference()->isOn(SETTING::SOUND_SCRUB_ACTIVE));


addWidget(mJumpToStartButton);
addWidget(mPlayButton);
addWidget(mJumpToEndButton);
Expand All @@ -148,6 +153,7 @@ void TimeControls::initUI()
addWidget(mLoopEndSpinBox);
addWidget(mSoundButton);
addWidget(mSoundScrubButton);
addWidget(mPreviewButton);
addWidget(mTimecodeSelect);
mTimecodeLabelAction = addWidget(mTimecodeLabel);

Expand Down Expand Up @@ -222,6 +228,8 @@ void TimeControls::makeConnections()
connect(mSoundScrubButton, &QPushButton::clicked, this, &TimeControls::soundScrubToggled);
connect(mSoundScrubButton, &QPushButton::clicked, this, &TimeControls::updateSoundScrubIcon);

connect(mPreviewButton, &QPushButton::clicked, this, &TimeControls::gotoPreviewMode);

connect(mFpsBox, spinBoxValueChanged, this, &TimeControls::fpsChanged);
connect(mFpsBox, &QSpinBox::editingFinished, this, &TimeControls::onFpsEditingFinished);

Expand Down Expand Up @@ -320,6 +328,23 @@ void TimeControls::updateSoundScrubIcon(bool soundScrubEnabled)
}
}

void TimeControls::gotoPreviewMode()
{
if (mEditor->layers()->getIsPreview())
return;

mEditor->layers()->setIsPreview(true);
mPreviewWindow = new PreviewWindow();
mPreviewWindow->setAttribute(Qt::WA_DeleteOnClose);
mPreviewWindow->setCore(mEditor);
mPreviewWindow->setWindowFlags(mPreviewWindow->windowFlags() | Qt::WindowStaysOnTopHint);
mPreviewWindow->show();
}

void TimeControls::previewMode()
{
}

void TimeControls::noTimecodeText()
{
QSettings settings(PENCIL2D, PENCIL2D);
Expand Down
7 changes: 7 additions & 0 deletions core_lib/src/interface/timecontrols.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ GNU General Public License for more details.
class Editor;
class PreferenceManager;
class TimeLine;
class PreviewWindow;

class TimeControls : public QToolBar
{
Expand Down Expand Up @@ -70,6 +71,8 @@ public slots:
void loopStartValueChanged(int);
void loopEndValueChanged(int);
void updateSoundScrubIcon(bool soundScrubEnabled);
void gotoPreviewMode();
void previewMode();

void noTimecodeText();
void onlyFramesText();
Expand All @@ -83,6 +86,7 @@ public slots:
QPushButton* mLoopButton = nullptr;
QPushButton* mSoundButton = nullptr;
QPushButton* mSoundScrubButton = nullptr;
QPushButton* mPreviewButton = nullptr;
QSpinBox* mFpsBox = nullptr;
QCheckBox* mPlaybackRangeCheckBox = nullptr;
QSpinBox* mLoopStartSpinBox = nullptr;
Expand All @@ -100,9 +104,12 @@ public slots:
QIcon mLoopIcon;
QIcon mSoundIcon;
QIcon mSoundScrubIcon;
QIcon mPreviewIcon;
QIcon mJumpToEndIcon;
QIcon mJumpToStartIcon;

PreviewWindow* mPreviewWindow = nullptr;
bool mPreviewOpen = false;
TimeLine* mTimeline = nullptr;
Editor* mEditor = nullptr;
int mFps = 12;
Expand Down
2 changes: 1 addition & 1 deletion core_lib/src/interface/timelinecells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ void TimeLineCells::mouseMoveEvent(QMouseEvent* event)
if (current->type() == Layer::BITMAP
|| current->type() == Layer::VECTOR)
{
tip += ("'" + current->name() +"' Distance: " + QString::number(current->getDistance()/1000.0) + " m.\n");
tip += tr("%1: Distance: %2 m.\n").arg(current->name(), QString::number(current->getDistance()/1000.0));
}
}
tip.chop(2); // remove new line chars
Expand Down
Loading

0 comments on commit cf17d94

Please sign in to comment.