1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-11 15:49:38 +00:00
CLK/OSBindings/Qt/scantargetwidget.h

77 lines
2.3 KiB
C
Raw Normal View History

#ifndef SCANTARGETWIDGET_H
#define SCANTARGETWIDGET_H
#include <QOpenGLWidget>
#include "../../Outputs/OpenGL/ScanTarget.hpp"
#include "../../Machines/ScanProducer.hpp"
#include "../../ClockReceiver/VSyncPredictor.hpp"
2020-07-04 04:29:37 +00:00
class ScanTargetWidget : public QOpenGLWidget {
public:
ScanTargetWidget(QWidget *parent = nullptr);
~ScanTargetWidget();
2020-07-04 04:29:37 +00:00
/// Sets the current scan producer; this scan producer will be
/// handed a suitable scan target as soon as one exists.
void setScanProducer(MachineTypes::ScanProducer *);
2020-07-04 04:29:37 +00:00
/// Destructs the current scan target
void stop();
2020-07-04 04:29:37 +00:00
struct MouseDelegate {
virtual void setMouseIsCaptured(bool) = 0;
virtual void moveMouse(QPoint) = 0;
virtual void setButtonPressed(int index, bool isPressed) = 0;
};
/// If a delegate is assigned then this widget will respond to clicks by capturing
/// the mouse, unless and until either ::stop() is called or ctrl+escape is pressed.
/// Mouse events can be tracked by the main window while the mouse is captured.
void setMouseDelegate(MouseDelegate *);
/// @returns @c true if the mouse is currently captured; @c false otherwise.
bool isMouseCaptured();
protected:
void initializeGL() override;
void resizeGL(int w, int h) override;
void paintGL() override;
2020-07-04 04:29:37 +00:00
void mousePressEvent(QMouseEvent *) override;
void mouseReleaseEvent(QMouseEvent *) override;
void mouseMoveEvent(QMouseEvent *) override;
void keyPressEvent(QKeyEvent *) override;
void keyReleaseEvent(QKeyEvent *) override;
2020-07-04 04:29:37 +00:00
void releaseMouse();
void setMouseButtonPressed(Qt::MouseButton, bool);
private:
// This should be created only once there's an OpenGL context. So it
// can't be done at creation time.
std::unique_ptr<Outputs::Display::OpenGL::ScanTarget> scanTarget;
2020-06-21 21:16:11 +00:00
Time::VSyncPredictor vsyncPredictor;
bool isConnected = false;
GLuint framebuffer = 0;
MachineTypes::ScanProducer *producer = nullptr;
2020-07-04 04:29:37 +00:00
Time::Nanos requestedRedrawTime = 0;
void setDefaultClearColour();
2020-07-04 04:29:37 +00:00
int rawWidth = 0, rawHeight = 0;
int scaledWidth = 0, scaledHeight = 0;
float outputScale = 1.0f;
void resize();
2020-07-04 04:29:37 +00:00
MouseDelegate *mouseDelegate = nullptr;
bool mouseIsCaptured = false;
bool f8State = false, f12State = false; // To support F8+F12 as a mouse release combination.
2020-07-04 04:29:37 +00:00
private slots:
void vsync();
};
#endif // SCANTARGETWIDGET_H