Skip to content

Commit

Permalink
iss: pencil2d#1877 - Fix import image using camera transform not working
Browse files Browse the repository at this point in the history
  • Loading branch information
MrStevns committed Sep 23, 2024
1 parent 7a0918f commit 6d6bb96
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 35 deletions.
32 changes: 9 additions & 23 deletions app/src/importpositiondialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,39 +64,25 @@ void ImportPositionDialog::didChangeComboBoxIndex(const int index)

void ImportPositionDialog::changeImportView()
{
mEditor->view()->setImportFollowsCamera(false);
QTransform transform;
if (mImportOption == ImportPosition::Type::CenterOfView)
{
QPointF centralPoint = mEditor->getScribbleArea()->getCentralPoint();
transform = transform.fromTranslate(centralPoint.x(), centralPoint.y());
mEditor->view()->setImportView(transform);
QSettings settings(PENCIL2D, PENCIL2D);
settings.setValue(IMPORT_REPOSITION_TYPE, ui->cbImagePosition->currentIndex());
return;
}
else if (mImportOption == ImportPosition::Type::CenterOfCanvas)
{
transform = transform.fromTranslate(0, 0);
mEditor->view()->setImportView(transform);
QSettings settings(PENCIL2D, PENCIL2D);
settings.setValue(IMPORT_REPOSITION_TYPE, ui->cbImagePosition->currentIndex());
return;
}
else if (mImportOption == ImportPosition::Type::CenterOfCamera)
else if (mImportOption == ImportPosition::Type::CenterOfCamera || mImportOption == ImportPosition::Type::CenterOfCameraFollowed)
{
LayerCamera* layerCam = static_cast<LayerCamera*>(mEditor->layers()->getCameraLayerBelow(mEditor->currentLayerIndex()));
Q_ASSERT(layerCam);
QRectF cameraRect = layerCam->getViewRect();
transform = transform.fromTranslate(cameraRect.center().x(), cameraRect.center().y());
mEditor->view()->setImportView(transform);
QSettings settings(PENCIL2D, PENCIL2D);
settings.setValue(IMPORT_REPOSITION_TYPE, ui->cbImagePosition->currentIndex());
return;
}

Q_ASSERT(mImportOption == ImportPosition::Type::CenterOfCameraFollowed);
mEditor->view()->setImportFollowsCamera(true);
if (mImportOption == ImportPosition::Type::CenterOfCamera) {
KeyFrame* camKey = layerCam->getKeyFrameAt(mEditor->currentFrame());
transform = layerCam->getViewAtFrame(camKey->pos()).inverted();
} else {
transform = layerCam->getViewAtFrame(mEditor->currentFrame()).inverted();
}
}
mEditor->view()->setImportView(transform);
QSettings settings(PENCIL2D, PENCIL2D);
settings.setValue(IMPORT_REPOSITION_TYPE, ui->cbImagePosition->currentIndex());
}
7 changes: 0 additions & 7 deletions core_lib/src/interface/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1015,13 +1015,6 @@ Status Editor::importImage(const QString& filePath)
DebugDetails dd;
dd << QString("Raw file path: %1").arg(filePath);

if (view()->getImportFollowsCamera())
{
LayerCamera* camera = static_cast<LayerCamera*>(layers()->getLastCameraLayer());
Q_ASSERT(camera);
QTransform transform = camera->getViewAtFrame(currentFrame());
view()->setImportView(transform);
}
switch (layer->type())
{
case Layer::BITMAP:
Expand Down
5 changes: 0 additions & 5 deletions core_lib/src/managers/viewmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ class ViewManager : public BaseManager
QTransform getImportView() { return mImportView; }
void setImportView(const QTransform& newView) { mImportView = newView; }

void setImportFollowsCamera(bool b) { mImportFollowsCamera = b; }
bool getImportFollowsCamera() { return mImportFollowsCamera; }

void forceUpdateViewTransform();

signals:
Expand Down Expand Up @@ -126,8 +123,6 @@ class ViewManager : public BaseManager
bool mOverlayThirds = false;
bool mOverlayGoldenRatio = false;
bool mOverlaySafeAreas = false;

bool mImportFollowsCamera = false;
};

#endif // VIEWMANAGER_H

0 comments on commit 6d6bb96

Please sign in to comment.