game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
frame_metrics_widget.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// frame_metrics_widget.h
4// ==============================================================================
5// Custom Qt widget for displaying real-time frame metrics with a frametime graph
6// Similar to MangoHud's visual style
7// ==============================================================================
8
9#pragma once
10
12
13#include <QPainter>
14#include <QTimer>
15#include <QWidget>
16#include <vector>
17
18class ThemeManager;
19
20class FrameMetricsWidget : public QWidget
21{
22 Q_OBJECT
23
24 public:
25 explicit FrameMetricsWidget(QWidget* parent = nullptr, ThemeManager* themeManager = nullptr);
26 ~FrameMetricsWidget() override = default;
27
28 /// Update the displayed metrics
29 void setMetrics(const FrameMetrics& metrics);
30
31 /// Clear the display (no game running)
32 void clear();
33
34 /// Set the target FPS for color coding (e.g., 60, 144)
35 void setTargetFps(double fps);
36
37 /// Set whether to show the frametime graph
38 void setShowGraph(bool show);
39
40 /// Set compact mode (less detailed, smaller)
41 void setCompactMode(bool compact);
42
43 /// Get the preferred size based on current mode
44 QSize sizeHint() const override;
45 QSize minimumSizeHint() const override;
46
47 public slots:
48 /// Apply current theme colors
49 void applyTheme();
50
51 protected:
52 void paintEvent(QPaintEvent* event) override;
53
54 private:
55 // Helper methods
56 QColor getFpsColor(double fps) const;
57 void drawFrametimeGraph(QPainter& painter, const QRect& rect, bool isStale, bool isVeryStale);
58 void drawStatsText(QPainter& painter, const QRect& rect);
59
60 // Current metrics
61 FrameMetrics metrics_;
62 bool hasMetrics_ = false;
63
64 // Display settings
65 double targetFps_ = 60.0;
66 bool showGraph_ = true;
67 bool compactMode_ = false;
68
69 // Colors — initialized from theme via applyTheme()
70 QColor bgColor_;
71 QColor graphBgColor_;
72 QColor graphLineColor_;
73 QColor graphFillColor_;
74 QColor textColor_;
75 QColor labelColor_;
76 QColor goodColor_;
77 QColor warnColor_;
78 QColor badColor_;
79 QColor staleColor_;
80
81 // Graph settings
82 static constexpr int GRAPH_HEIGHT = 40;
83 static constexpr int GRAPH_PADDING = 4;
84 static constexpr double FRAMETIME_SCALE_MAX = 50.0; // ms (for 20 FPS baseline)
85
86 ThemeManager* themeManager_;
87};
QSize sizeHint() const override
Get the preferred size based on current mode.
void setMetrics(const FrameMetrics &metrics)
Update the displayed metrics.
FrameMetricsWidget(QWidget *parent=nullptr, ThemeManager *themeManager=nullptr)
void clear()
Clear the display (no game running).
void setTargetFps(double fps)
Set the target FPS for color coding (e.g., 60, 144).
void setShowGraph(bool show)
Set whether to show the frametime graph.
void setCompactMode(bool compact)
Set compact mode (less detailed, smaller).
void applyTheme()
Apply current theme colors.
void paintEvent(QPaintEvent *event) override
~FrameMetricsWidget() override=default
QSize minimumSizeHint() const override
Real-time frame timing and performance metrics.