OXYGENHUB
◆ main openmsx / src / imgui / ImGuiBitmapViewer.hh
3.5 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#ifndef IMGUI_BITMAP_VIEWER_HH
2
#define IMGUI_BITMAP_VIEWER_HH
3
4
#include "ImGuiPart.hh"
5
6
#include "GLUtil.hh"
7
#include "gl_vec.hh"
8
9
#include <cstdint>
10
#include <optional>
11
#include <span>
12
#include <string>
13
14
namespace openmsx {
15
16
class ImGuiBitmapViewer final : public ImGuiPart
17
{
18
public:
19
	enum ScrnMode : int { SCR5, SCR6, SCR7, SCR8, SCR11, SCR12, OTHER }; // must be in sync with VDPCmdEngine 'scrnMode'
20
21
public:
22
	ImGuiBitmapViewer(ImGuiManager& manager_, size_t index);
23
24
	[[nodiscard]] zstring_view iniName() const override { return title; }
25
	void save(ImGuiTextBuffer& buf) override;
26
	void loadLine(std::string_view name, zstring_view value) override;
27
	void paint(MSXMotherBoard* motherBoard) override;
28
29
private:
30
	void renderBitmap(std::span<const uint8_t> vram, std::span<const uint32_t, 16> palette16,
31
	                  int mode, int lines, int page, uint32_t* output) const;
32
33
public:
34
	bool show = true;
35
36
private:
37
	std::string title;
38
39
	int bitmapScrnMode = 0;
40
	int bitmapPage = 0; // 0-3 or 0-1 depending on screen mode, -1 for all pages   TODO extended VRAM
41
	int bitmapLines = 1; // 0->192, 1->212, 2->256
42
	int bitmapColor0 = 16; // 0..15, 16->no replacement
43
	int bitmapZoom = 0; // 0->1x, 1->2x, ..., 7->8x
44
	gl::vec4 bitmapGridColor{0.0f, 0.0f, 0.0f, 0.5f}; // RGBA
45
	gl::vec4 rasterBeamColor{1.0f, 0.0f, 0.0f, 0.8f}; // RGBA
46
	bool overrideAll    = false;
47
	bool overrideMode   = false;
48
	bool overridePage   = false;
49
	bool overrideLines  = false;
50
	bool overrideColor0 = false;
51
	bool bitmapGrid = true;
52
	bool rasterBeam = false;
53
54
	std::optional<gl::Texture> bitmapTex; // TODO also deallocate when needed
55
	std::optional<gl::Texture> bitmapGridTex;
56
57
	int showCmdOverlay = 0; // 0->none, 1->in-progress, 2->also finished
58
	gl::vec4 colorSrcDone{0.0f, 1.0f, 0.0f, 0.66f};
59
	gl::vec4 colorSrcTodo{0.0f, 1.0f, 0.0f, 0.33f};
60
	gl::vec4 colorDstDone{1.0f, 0.0f, 0.0f, 0.66f};
61
	gl::vec4 colorDstTodo{1.0f, 0.0f, 0.0f, 0.33f};
62
63
	static constexpr auto persistentElements = std::tuple{
64
		PersistentElement   {"show",           &ImGuiBitmapViewer::show},
65
		PersistentElement   {"overrideAll",    &ImGuiBitmapViewer::overrideAll},
66
		PersistentElement   {"overrideMode",   &ImGuiBitmapViewer::overrideMode},
67
		PersistentElement   {"overridePage",   &ImGuiBitmapViewer::overridePage},
68
		PersistentElement   {"overrideLines",  &ImGuiBitmapViewer::overrideLines},
69
		PersistentElement   {"overrideColor0", &ImGuiBitmapViewer::overrideColor0},
70
		PersistentElementMax{"scrnMode",       &ImGuiBitmapViewer::bitmapScrnMode, OTHER}, // SCR5..SCR12
71
		PersistentElement   {"page",           &ImGuiBitmapViewer::bitmapPage},
72
		PersistentElementMax{"lines",          &ImGuiBitmapViewer::bitmapLines, 3},
73
		PersistentElementMax{"color0",         &ImGuiBitmapViewer::bitmapColor0, 16 + 1},
74
		PersistentElementMax{"zoom",           &ImGuiBitmapViewer::bitmapZoom, 8},
75
		PersistentElement   {"showGrid",       &ImGuiBitmapViewer::bitmapGrid},
76
		PersistentElement   {"gridColor",      &ImGuiBitmapViewer::bitmapGridColor},
77
		PersistentElement   {"showRasterBeam", &ImGuiBitmapViewer::rasterBeam},
78
		PersistentElement   {"rasterBeamColor",&ImGuiBitmapViewer::rasterBeamColor},
79
		PersistentElementMax{"showCmdOverlay", &ImGuiBitmapViewer::showCmdOverlay, 3},
80
		PersistentElement   {"colorSrcDone",   &ImGuiBitmapViewer::colorSrcDone},
81
		PersistentElement   {"colorSrcTodo",   &ImGuiBitmapViewer::colorSrcTodo},
82
		PersistentElement   {"colorDstDone",   &ImGuiBitmapViewer::colorDstDone},
83
		PersistentElement   {"colorDstTodo",   &ImGuiBitmapViewer::colorDstTodo}
84
	};
85
};
86
87
} // namespace openmsx
88
89
#endif