gui: refactor FPGAViewWidget even more slightly
This commit is contained in:
parent
25bf147d1a
commit
ba5395d89f
@ -242,9 +242,11 @@ void LineShader::draw(const LineShaderData &line, const QColor &color, float thi
|
||||
vao_.release();
|
||||
}
|
||||
|
||||
FPGAViewWidget::FPGAViewWidget(QWidget *parent)
|
||||
: QOpenGLWidget(parent), lineShader_(this), zoom_(500.f), ctx_(nullptr), paintTimer_(this),
|
||||
rendererData_(new FPGAViewWidget::RendererData), rendererArgs_(new FPGAViewWidget::RendererArgs)
|
||||
FPGAViewWidget::FPGAViewWidget(QWidget *parent) :
|
||||
QOpenGLWidget(parent), ctx_(nullptr), paintTimer_(this),
|
||||
lineShader_(this), zoom_(500.0f),
|
||||
rendererData_(new FPGAViewWidget::RendererData),
|
||||
rendererArgs_(new FPGAViewWidget::RendererArgs)
|
||||
{
|
||||
colors_.background = QColor("#000000");
|
||||
colors_.grid = QColor("#333");
|
||||
@ -562,7 +564,7 @@ void FPGAViewWidget::onHighlightGroupChanged(std::vector<DecalXY> decals, int gr
|
||||
|
||||
void FPGAViewWidget::resizeGL(int width, int height) {}
|
||||
|
||||
void FPGAViewWidget::mousePressEvent(QMouseEvent *event) { lastPos_ = event->pos(); }
|
||||
void FPGAViewWidget::mousePressEvent(QMouseEvent *event) { lastDragPos_ = event->pos(); }
|
||||
|
||||
// Invert the projection matrix to calculate screen/mouse to world/grid
|
||||
// coordinates.
|
||||
@ -578,9 +580,9 @@ QVector4D FPGAViewWidget::mouseToWorldCoordinates(int x, int y)
|
||||
|
||||
void FPGAViewWidget::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
const int dx = event->x() - lastPos_.x();
|
||||
const int dy = event->y() - lastPos_.y();
|
||||
lastPos_ = event->pos();
|
||||
const int dx = event->x() - lastDragPos_.x();
|
||||
const int dy = event->y() - lastDragPos_.y();
|
||||
lastDragPos_ = event->pos();
|
||||
|
||||
auto world = mouseToWorldCoordinates(dx, dy);
|
||||
viewMove_.translate(world.x(), -world.y());
|
||||
|
@ -267,16 +267,17 @@ class FPGAViewWidget : public QOpenGLWidget, protected QOpenGLFunctions
|
||||
FPGAViewWidget(QWidget *parent = 0);
|
||||
~FPGAViewWidget();
|
||||
|
||||
QSize minimumSizeHint() const override;
|
||||
QSize sizeHint() const override;
|
||||
|
||||
protected:
|
||||
// Qt callbacks.
|
||||
void initializeGL() Q_DECL_OVERRIDE;
|
||||
void paintGL() Q_DECL_OVERRIDE;
|
||||
void resizeGL(int width, int height) Q_DECL_OVERRIDE;
|
||||
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
||||
void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
||||
void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE;
|
||||
QSize minimumSizeHint() const override;
|
||||
QSize sizeHint() const override;
|
||||
|
||||
|
||||
public Q_SLOTS:
|
||||
void newContext(Context *ctx);
|
||||
@ -289,30 +290,20 @@ class FPGAViewWidget : public QOpenGLWidget, protected QOpenGLFunctions
|
||||
void zoomOutbound();
|
||||
|
||||
private:
|
||||
void drawGraphicElement(LineShaderData &out, const GraphicElement &el, float x, float y);
|
||||
void drawArchDecal(LineShaderData out[GraphicElement::STYLE_MAX], const DecalXY &decal);
|
||||
void drawDecal(LineShaderData &out, const DecalXY &decal);
|
||||
void renderLines(void);
|
||||
void zoom(int level);
|
||||
|
||||
QPoint lastPos_;
|
||||
LineShader lineShader_;
|
||||
QMatrix4x4 viewMove_;
|
||||
float zoom_;
|
||||
QMatrix4x4 getProjection(void);
|
||||
QVector4D mouseToWorldCoordinates(int x, int y);
|
||||
|
||||
const float zoomNear_ = 1.0f; // do not zoom closer than this
|
||||
const float zoomFar_ = 10000.0f; // do not zoom further than this
|
||||
|
||||
const float zoomLvl1_ = 100.0f;
|
||||
const float zoomLvl2_ = 50.0f;
|
||||
|
||||
Context *ctx_;
|
||||
QTimer paintTimer_;
|
||||
|
||||
std::unique_ptr<PeriodicRunner> renderRunner_;
|
||||
|
||||
QPoint lastDragPos_;
|
||||
LineShader lineShader_;
|
||||
QMatrix4x4 viewMove_;
|
||||
float zoom_;
|
||||
|
||||
struct
|
||||
{
|
||||
QColor background;
|
||||
@ -331,6 +322,8 @@ class FPGAViewWidget : public QOpenGLWidget, protected QOpenGLFunctions
|
||||
LineShaderData gfxSelected;
|
||||
LineShaderData gfxHighlighted[8];
|
||||
};
|
||||
std::unique_ptr<RendererData> rendererData_;
|
||||
QMutex rendererDataLock_;
|
||||
|
||||
struct RendererArgs
|
||||
{
|
||||
@ -338,11 +331,16 @@ class FPGAViewWidget : public QOpenGLWidget, protected QOpenGLFunctions
|
||||
std::vector<DecalXY> highlightedDecals[8];
|
||||
bool highlightedOrSelectedChanged;
|
||||
};
|
||||
|
||||
std::unique_ptr<RendererData> rendererData_;
|
||||
QMutex rendererDataLock_;
|
||||
std::unique_ptr<RendererArgs> rendererArgs_;
|
||||
QMutex rendererArgsLock_;
|
||||
|
||||
void zoom(int level);
|
||||
void renderLines(void);
|
||||
void drawGraphicElement(LineShaderData &out, const GraphicElement &el, float x, float y);
|
||||
void drawDecal(LineShaderData &out, const DecalXY &decal);
|
||||
void drawArchDecal(LineShaderData out[GraphicElement::STYLE_MAX], const DecalXY &decal);
|
||||
QVector4D mouseToWorldCoordinates(int x, int y);
|
||||
QMatrix4x4 getProjection(void);
|
||||
};
|
||||
|
||||
NEXTPNR_NAMESPACE_END
|
||||
|
Loading…
Reference in New Issue
Block a user