Skip to content

Commit ebad47e

Browse files
Fix follow camera import image option
There were two issues with this feature. First was that it was importing with the camera view transform, but the camera rect is actually transformed by the inverse of that transformation. The second issue was an occasional off-by-one error in the position caused by using the more accurate qtransform over the rounded qrect that the camera rect is based off of.
1 parent d9078b1 commit ebad47e

File tree

7 files changed

+11
-11
lines changed

7 files changed

+11
-11
lines changed

app/src/importpositiondialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void ImportPositionDialog::changeImportView()
7676
}
7777
else if (mImportOption == ImportPosition::Type::CenterOfCamera)
7878
{
79-
QRectF cameraRect = mEditor->getScribbleArea()->getCameraRect();
79+
QRectF cameraRect = mEditor->getScribbleArea()->getCameraRect(); // Must be QRectF for the precision of cameraRect.center()
8080
transform = transform.fromTranslate(cameraRect.center().x(), cameraRect.center().y());
8181
mEditor->view()->setImportView(transform);
8282
QSettings settings(PENCIL2D, PENCIL2D);

core_lib/src/graphics/bitmap/bitmapbucket.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ BitmapBucket::BitmapBucket()
3030

3131
BitmapBucket::BitmapBucket(Editor* editor,
3232
QColor color,
33-
QRectF maxFillRegion,
33+
QRect maxFillRegion,
3434
QPointF fillPoint,
3535
Properties properties):
3636
mEditor(editor),
@@ -125,7 +125,7 @@ void BitmapBucket::paint(const QPointF updatedPoint, std::function<void(BucketSt
125125
QRgb fillColor = mBucketColor;
126126

127127
const QPoint point = QPoint(qFloor(updatedPoint.x()), qFloor(updatedPoint.y()));
128-
const QRect cameraRect = mMaxFillRegion.toRect();
128+
const QRect cameraRect = mMaxFillRegion;
129129
const int tolerance = mProperties.toleranceEnabled ? static_cast<int>(mProperties.tolerance) : 0;
130130
const int currentFrameIndex = mEditor->currentFrame();
131131
const QRgb origColor = fillColor;

core_lib/src/graphics/bitmap/bitmapbucket.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class BitmapBucket
3535
{
3636
public:
3737
explicit BitmapBucket();
38-
explicit BitmapBucket(Editor* editor, QColor color, QRectF maxFillRegion, QPointF fillPoint, Properties properties);
38+
explicit BitmapBucket(Editor* editor, QColor color, QRect maxFillRegion, QPointF fillPoint, Properties properties);
3939

4040
/** Will paint at the given point, given that it makes sense.. canUse is always called prior to painting
4141
*
@@ -71,7 +71,7 @@ class BitmapBucket
7171
QRgb mAppliedColor = 0;
7272

7373
QPointF mBucketStartPoint;
74-
QRectF mMaxFillRegion;
74+
QRect mMaxFillRegion;
7575

7676
int mTargetFillToLayerIndex = -1;
7777

core_lib/src/interface/editor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -918,8 +918,8 @@ bool Editor::importImage(const QString& filePath)
918918

919919
if (view()->getImportFollowsCamera())
920920
{
921-
LayerCamera* camera = static_cast<LayerCamera*>(layers()->getLastCameraLayer());
922-
QTransform transform = camera->getViewAtFrame(currentFrame());
921+
QRectF cameraRect = mScribbleArea->getCameraRect(); // Must be QRectF for the precision of cameraRect.center()
922+
QTransform transform = QTransform::fromTranslate(cameraRect.center().x(), cameraRect.center().y());
923923
view()->setImportView(transform);
924924
}
925925
switch (layer->type())

core_lib/src/interface/scribblearea.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,7 +1327,7 @@ void ScribbleArea::prepOverlays()
13271327
o.bTitleSafe = mPrefs->isOn(SETTING::TITLE_SAFE_ON);
13281328
o.nTitleSafe = mPrefs->getInt(SETTING::TITLE_SAFE);
13291329

1330-
o.mRect = getCameraRect().toRect(); // camera rect!
1330+
o.mRect = getCameraRect(); // camera rect!
13311331
o.mSinglePerspPoint = mEditor->overlays()->getSinglePerspPoint();
13321332
o.mLeftPerspPoint = mEditor->overlays()->getLeftPerspPoint();
13331333
o.mRightPerspPoint = mEditor->overlays()->getRightPerspPoint();
@@ -1423,7 +1423,7 @@ void ScribbleArea::drawPolyline(QPainterPath path, QPen pen, bool useAA)
14231423
/************************************************************************************/
14241424
// view handling
14251425

1426-
QRectF ScribbleArea::getCameraRect()
1426+
QRect ScribbleArea::getCameraRect()
14271427
{
14281428
return mCanvasPainter.getCameraRect();
14291429
}

core_lib/src/interface/scribblearea.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class ScribbleArea : public QWidget
8484
bool usePressure() const { return mUsePressure; }
8585
bool makeInvisible() const { return mMakeInvisible; }
8686

87-
QRectF getCameraRect();
87+
QRect getCameraRect();
8888
QPointF getCentralPoint();
8989

9090
/** Update current frame.

tests/src/test_bitmapbucket.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
#include "basetool.h"
1717

18-
void dragAndFill(QPointF movePoint, Editor* editor, QColor color, QRectF bounds, Properties properties) {
18+
void dragAndFill(QPointF movePoint, Editor* editor, QColor color, QRect bounds, Properties properties) {
1919
int moveX = 0;
2020

2121
BitmapBucket bucket = BitmapBucket(editor, color, bounds, movePoint, properties);

0 commit comments

Comments
 (0)