OXYGENHUB
◆ main openmsx / src / imgui / ImGuiRasterViewer.hh
3.9 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
e8555c89 Andy McCall 1
#ifndef IMGUI_RASTER_VIEWER_HH
2
#define IMGUI_RASTER_VIEWER_HH
3
4
#include "ImGuiPart.hh"
5
6
#include "VDP.hh"
7
8
#include "GLUtil.hh"
9
#include "MemBuffer.hh"
10
11
#include <span>
12
13
namespace openmsx {
14
15
class ImGuiTraceViewer;
16
17
class ImGuiRasterViewer final : public ImGuiPart
18
{
19
public:
20
	ImGuiRasterViewer(ImGuiManager& manager, ImGuiTraceViewer& traceViewer);
21
22
	[[nodiscard]] zstring_view iniName() const override { return "Raster Viewer"; }
23
	void save(ImGuiTextBuffer& buf) override;
24
	void loadLine(std::string_view name, zstring_view value) override;
25
	void paint(MSXMotherBoard* motherBoard) override;
26
27
private:
28
	void paintSettings();
29
	void paintDisplay(MSXMotherBoard& motherBoard);
30
	void paintConfigure(MSXMotherBoard& motherBoard);
31
	void initPixelBuffer(size_t lines);
32
	gl::vec2 drawCrosshair(
33
		gl::ivec2 vdpPos, gl::vec4 color, gl::vec2 scrnPos, int zoom,
34
		std::span<const unsigned, VDP::NUM_LINES_MAX> lineWidths);
35
	void drawMarker(
36
		gl::ivec2 vdpPos, gl::vec4 color, gl::vec2 scrnPos, int zoom,
37
		std::span<const unsigned, VDP::NUM_LINES_MAX> lineWidths);
38
	void drawRegion(
39
		gl::ivec2 from, gl::ivec2 to, gl::vec4 color, gl::vec2 scrnTopLeft, int zoom,
40
		std::span<const unsigned> lineWidths);
41
42
	struct TraceInfo {
43
		TraceInfo(std::string name_, gl::vec4 color_, bool enabled_)
44
			: name(std::move(name_)), color(color_), enabled(enabled_) {}
45
		std::string name;
46
		gl::vec4 color;
47
		bool enabled = true;
48
	};
49
	TraceInfo& getTraceInfoFor(std::string_view name);
50
51
public:
52
	bool show = false;
53
54
private:
55
	ImGuiTraceViewer& traceViewer;
56
	std::vector<TraceInfo> traceInfos; // sorted on name
57
58
	// settings
59
	gl::vec4 gridColor{0.0f, 0.0f, 0.0f, 0.5f}; // RGBA
60
	gl::vec4 fadeOutColor{0.0f, 0.0f, 0.0f, 0.75f}; // RGBA
61
	gl::vec4 beamColor{1.0f, 0.0f, 0.0f, 0.8f}; // RGBA
62
	gl::vec4 vblankIrqColor{1.0f, 1.0f, 0.0f, 0.8f}; // RGBA
63
	gl::vec4 lineIrqColor{0.0f, 1.0f, 1.0f, 0.8f}; // RGBA
64
	gl::vec4 markerColor1{0.0f, 1.0f, 0.0f, 0.8f}; // RGBA
65
	gl::vec4 markerColor2{1.0f, 0.0f, 0.0f, 0.8f}; // RGBA
66
	gl::vec4 shadeColor{1.0f, 1.0f, 0.0f, 0.3f}; // RGBA
67
	std::string shadeTrace;
68
	enum Shade : int { DISABLED, MARKERS, TRACE };
69
	int shadeType = Shade::MARKERS;
70
	int zoomSelect = 0; // +1 for actual zoom factor
71
	bool showGrid = true;
72
	bool showFadeOut = true;
73
	bool showBeam = true;
74
	bool showVblankIrq = false;
75
	bool showLineIrq = false;
76
	bool showTraces = false;
77
	bool showMarkers = true;
78
	bool showConfigure = false;
79
80
	MemBuffer<uint32_t> pixelBuffer;
81
	gl::Texture viewTex{gl::Null{}};
82
	gl::Texture gridTex320{gl::Null{}};
83
	gl::Texture gridTex640{gl::Null{}};
84
	gl::Texture checkerTex{gl::Null{}};
85
86
	static constexpr auto persistentElements = std::tuple{
87
		PersistentElement{"show",           &ImGuiRasterViewer::show},
88
		PersistentElement{"zoom",           &ImGuiRasterViewer::zoomSelect},
89
		PersistentElement{"grid",           &ImGuiRasterViewer::showGrid},
90
		PersistentElement{"fadeOut",        &ImGuiRasterViewer::showFadeOut},
91
		PersistentElement{"beam",           &ImGuiRasterViewer::showBeam},
92
		PersistentElement{"vblankIrq",      &ImGuiRasterViewer::showVblankIrq},
93
		PersistentElement{"lineIrq",        &ImGuiRasterViewer::showLineIrq},
94
		PersistentElement{"traces",         &ImGuiRasterViewer::showTraces},
95
		PersistentElement{"markers",        &ImGuiRasterViewer::showMarkers},
96
		PersistentElement{"shadeTrace",     &ImGuiRasterViewer::shadeTrace},
97
		PersistentElement{"shadeType",      &ImGuiRasterViewer::shadeType},
98
		PersistentElement{"gridColor",      &ImGuiRasterViewer::gridColor},
99
		PersistentElement{"fadeOutColor",   &ImGuiRasterViewer::fadeOutColor},
100
		PersistentElement{"beamColor",      &ImGuiRasterViewer::beamColor},
101
		PersistentElement{"vblankIrqColor", &ImGuiRasterViewer::vblankIrqColor},
102
		PersistentElement{"lineIrqColor",   &ImGuiRasterViewer::lineIrqColor},
103
		PersistentElement{"marker1Color",   &ImGuiRasterViewer::markerColor1},
104
		PersistentElement{"marker2Color",   &ImGuiRasterViewer::markerColor2},
105
		PersistentElement{"shadeColor",     &ImGuiRasterViewer::shadeColor},
106
	};
107
};
108
109
} // namespace openmsx
110
111
#endif