openMSX
ImGuiBitmapViewer.hh
Go to the documentation of this file.
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#include "static_vector.hh"
9
10#include <cstdint>
11#include <optional>
12#include <span>
13#include <string>
14
15namespace openmsx {
16
17class ImGuiBitmapViewer final : public ImGuiPart
18{
19public:
20 enum ScrnMode : int { SCR5, SCR6, SCR7, SCR8, SCR11, SCR12, OTHER };
21
22public:
23 ImGuiBitmapViewer(ImGuiManager& manager_, size_t index);
24
25 [[nodiscard]] zstring_view iniName() const override { return title; }
26 void save(ImGuiTextBuffer& buf) override;
27 void loadLine(std::string_view name, zstring_view value) override;
28 void paint(MSXMotherBoard* motherBoard) override;
29
30private:
31 void renderBitmap(std::span<const uint8_t> vram, std::span<const uint32_t, 16> palette16,
32 int mode, int lines, int page, uint32_t* output) const;
33
34public:
35 bool show = true;
36
37private:
38 std::string title;
39
40 int bitmapScrnMode = 0;
41 int bitmapPage = 0; // 0-3 or 0-1 depending on screen mode, -1 for all pages TODO extended VRAM
42 int bitmapLines = 1; // 0->192, 1->212, 2->256
43 int bitmapColor0 = 16; // 0..15, 16->no replacement
44 int bitmapZoom = 0; // 0->1x, 1->2x, ..., 7->8x
45 gl::vec4 bitmapGridColor{0.0f, 0.0f, 0.0f, 0.5f}; // RGBA
46 gl::vec4 rasterBeamColor{1.0f, 0.0f, 0.0f, 0.8f}; // RGBA
47 bool overrideAll = false;
48 bool overrideMode = false;
49 bool overridePage = false;
50 bool overrideLines = false;
51 bool overrideColor0 = false;
52 bool bitmapGrid = true;
53 bool rasterBeam = false;
54
55 std::optional<gl::Texture> bitmapTex; // TODO also deallocate when needed
56 std::optional<gl::Texture> bitmapGridTex;
57
58 int showCmdOverlay = 0; // 0->none, 1->in-progress, 2->also finished
59 gl::vec4 colorSrcDone{0.0f, 1.0f, 0.0f, 0.66f};
60 gl::vec4 colorSrcTodo{0.0f, 1.0f, 0.0f, 0.33f};
61 gl::vec4 colorDstDone{1.0f, 0.0f, 0.0f, 0.66f};
62 gl::vec4 colorDstTodo{1.0f, 0.0f, 0.0f, 0.33f};
63
64 static constexpr auto persistentElements = std::tuple{
66 PersistentElement {"overrideAll", &ImGuiBitmapViewer::overrideAll},
67 PersistentElement {"overrideMode", &ImGuiBitmapViewer::overrideMode},
68 PersistentElement {"overridePage", &ImGuiBitmapViewer::overridePage},
69 PersistentElement {"overrideLines", &ImGuiBitmapViewer::overrideLines},
70 PersistentElement {"overrideColor0", &ImGuiBitmapViewer::overrideColor0},
71 PersistentElementMax{"scrnMode", &ImGuiBitmapViewer::bitmapScrnMode, OTHER}, // SCR5..SCR12
72 PersistentElement {"page", &ImGuiBitmapViewer::bitmapPage},
73 PersistentElementMax{"lines", &ImGuiBitmapViewer::bitmapLines, 3},
74 PersistentElementMax{"color0", &ImGuiBitmapViewer::bitmapColor0, 16 + 1},
75 PersistentElementMax{"zoom", &ImGuiBitmapViewer::bitmapZoom, 8},
76 PersistentElement {"showGrid", &ImGuiBitmapViewer::bitmapGrid},
77 PersistentElement {"gridColor", &ImGuiBitmapViewer::bitmapGridColor},
78 PersistentElement {"showRasterBeam", &ImGuiBitmapViewer::rasterBeam},
79 PersistentElement {"rasterBeamColor",&ImGuiBitmapViewer::rasterBeamColor},
80 PersistentElementMax{"showCmdOverlay", &ImGuiBitmapViewer::showCmdOverlay, 3},
81 PersistentElement {"colorSrcDone", &ImGuiBitmapViewer::colorSrcDone},
82 PersistentElement {"colorSrcTodo", &ImGuiBitmapViewer::colorSrcTodo},
83 PersistentElement {"colorDstDone", &ImGuiBitmapViewer::colorDstDone},
84 PersistentElement {"colorDstTodo", &ImGuiBitmapViewer::colorDstTodo}
85 };
86};
87
89struct Rect {
90 Rect() = default; // workaround
91 Rect(const Point& p1_, const Point& p2_) : p1(p1_), p2(p2_) {} // workaround apple-clang-16(?) limitation
93};
97
98// TODO write a unittest for these 2 functions.
100 int x, int y, int nx, int ny,
101 bool dix, bool diy, ImGuiBitmapViewer::ScrnMode screenMode, bool byteMode);
102DoneTodo splitRect(const Rect& r, int x, int y);
103
104} // namespace openmsx
105
106#endif
void loadLine(std::string_view name, zstring_view value) override
void paint(MSXMotherBoard *motherBoard) override
void save(ImGuiTextBuffer &buf) override
zstring_view iniName() const override
Like std::string_view, but with the extra guarantee that it refers to a zero-terminated string.
vecN< 2, int > ivec2
Definition gl_vec.hh:385
This file implemented 3 utility functions:
Definition Autofire.cc:11
PersistentElement(zstring_view, T C::*) -> PersistentElement< C, T >
DoneTodo splitRect(const Rect &r, int x, int y)
static_vector< Rect, 2 > rectFromVdpCmd(int x, int y, int nx, int ny, bool dix, bool diy, ImGuiBitmapViewer::ScrnMode screenMode, bool byteMode)
static_vector< Rect, 2 > done
static_vector< Rect, 2 > todo
Rect(const Point &p1_, const Point &p2_)
Rect()=default