This commit is contained in:
Thomas Wilshaw
2020-06-16 11:53:35 +01:00
parent f4d56f79cb
commit 92eadc6854
2 changed files with 24 additions and 11 deletions
+6 -10
View File
@@ -163,10 +163,9 @@ void ViewerDisplayWidget::mousePressEvent(QMouseEvent *event)
SetMatrixTranslate(mat);
}
// get current position in preperation for move event
if (event->button() == Qt::MiddleButton) {
printf("Middle Button Clicked\n");
position_ = event->pos();
printf("x: %d, y:%d\n", position_.x(), position_.y());
return;
}
@@ -180,18 +179,18 @@ void ViewerDisplayWidget::mousePressEvent(QMouseEvent *event)
void ViewerDisplayWidget::mouseMoveEvent(QMouseEvent *event)
{
if (event->buttons() & Qt::MiddleButton) {
printf("Move\n");
QPointF delta = event->pos() - position_;
// scale delta to widget size
delta.setX(delta.x() / width());
delta.setY(delta.y() / height());
//this->move(this->pos()+new_position);
//QPoint new_pos = this->pos() + delta;
QMatrix4x4 mat;
//mat.translate(static_cast<float>(new_pos.x()) / width(), static_cast<float>(-1 * new_pos.y()) / height());
printf("x: %f, y:%f\n", delta.x(), delta.y());
mat = GetMatrixTranslate();
// Have to invert y axis, possibly because of something in the OpenGL code?
mat.translate(delta.x(), -1.0f * delta.y());
SetMatrixTranslate(mat);
// get new start position
position_ = event-> pos();
return;
}
@@ -278,9 +277,6 @@ void ViewerDisplayWidget::paintGL()
// Bind retrieved texture
f->glBindTexture(GL_TEXTURE_2D, texture_.texture());
//QMatrix4x4 mat;
//mat = scale_matrix_ * translate_matrix_ * mat;
// Blit using the color service
color_service()->ProcessOpenGL(true, GetCompleteMatrix());
+18 -1
View File
@@ -66,8 +66,15 @@ public:
virtual ~ViewerDisplayWidget() override;
/**
* @brief Return the translation only matrix.
*/
QMatrix4x4 GetMatrixTranslate();
/**
* @brief Return the complete translation and scale matrix
* This must be used if you want the entire transformation pipeline (scale and translate).
*/
QMatrix4x4 GetCompleteMatrix();
const ViewerSafeMarginInfo& GetSafeMargin() const;
@@ -86,6 +93,10 @@ public slots:
* Set this if you want the drawing to pass through some sort of transform (most of the time you won't want this).
*/
void SetMatrixTranslate(const QMatrix4x4& mat);
/**
* @brief Set the scale matrix.
*/
void SetMatrixZoom(const QMatrix4x4& mat);
/**
@@ -159,10 +170,13 @@ private:
OpenGLTexture texture_;
/**
* @brief Drawing matrix (defaults to identity)
* @brief Translation only matrix (defaults to identity).
*/
QMatrix4x4 translate_matrix_;
/**
* @breif Scale only matrix.
*/
QMatrix4x4 scale_matrix_;
#ifdef Q_OS_LINUX
@@ -183,6 +197,9 @@ private:
FramePtr last_loaded_buffer_;
/**
* @brief position of mouse to calculate delta from.
*/
QPoint position_;
private slots: