-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimulationViewWidget.h
82 lines (57 loc) · 2.15 KB
/
SimulationViewWidget.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef SIMULATIONVIEWWIDGET_H
#define SIMULATIONVIEWWIDGET_H
#include "Simulation.h"
#include "SimulationInfoTableModel.h"
#include <QWidget>
#include <QTimer>
#include <QAbstractScrollArea>
#include <memory>
class SimulationViewWidget : public QAbstractScrollArea {
Q_OBJECT
public:
enum class MouseButtonAction {
SelectPlant,
AddPlantSeed,
RemovePlants,
};
explicit SimulationViewWidget(QWidget *parent = nullptr);
void SetSimulation(std::shared_ptr<Simulation> sim);
void UpdateScrollBars();
void SetShowLight(bool showLight);
void SetPaused(bool paused);
void SetTargetFramesPerSecond(unsigned targetFps);
void SetTargetTicksPerSecond(unsigned targetTps);
void SetUnlimitedTicksPerSecond();
void SetLeftMouseButtonAction(MouseButtonAction action);
void SetRightMouseButtonAction(MouseButtonAction action);
SimulationInfoTableModel& GetSimulationInfoModel();
std::shared_ptr<Plant> GetSelectedPlant() const;
signals:
void onPlacePlantSeedRequested(double x);
protected:
virtual void mousePressEvent(QMouseEvent* event) override;
virtual void mouseMoveEvent(QMouseEvent* event) override;
virtual void wheelEvent(QWheelEvent* event) override;
virtual void paintEvent(QPaintEvent* event) override;
virtual void showEvent(QShowEvent* /*event*/) override;
virtual void resizeEvent(QResizeEvent* event) override;
private:
static inline constexpr int groundHeight = 5;
QTimer simulationDriver;
QTimer repaintDriver;
QTimer infoUpdateDriver;
std::shared_ptr<Simulation> sim;
SimulationInfoTableModel infoModel;
bool viewLight;
MouseButtonAction leftMouseButtonAction;
MouseButtonAction rightMouseButtonAction;
std::shared_ptr<Plant> selectedPlant;
static QString ElapsedTimeString(qint64 elapsedMsecs);
void Tick();
void Reset();
void PaintPlant(QPainter& paint, const Plant& plant, bool selected);
void UpdateInfoModel();
void PerformMouseButtonAction(MouseButtonAction action, const QPointF& location);
QPointF LocalToSimulation(const QPointF& localPoint) const;
};
#endif // SIMULATIONVIEWWIDGET_H