| 1 | #ifndef VRAMBITMAPPEDVIEW |
| 2 | #define VRAMBITMAPPEDVIEW |
| 3 | |
| 4 | #include <QString> |
| 5 | #include <QWidget> |
| 6 | #include <QImage> |
| 7 | #include <QPixmap> |
| 8 | #include <QMouseEvent> |
| 9 | #include <QColor> |
| 10 | #include <cstdint> |
| 11 | #include <optional> |
| 12 | |
| 13 | class VramTiledView : public QWidget |
| 14 | { |
| 15 | Q_OBJECT |
| 16 | public: |
| 17 | VramTiledView(QWidget* parent = nullptr); |
| 18 | |
| 19 | void setZoom(float zoom); |
| 20 | void setScreenMode(int mode); |
| 21 | void setLines(int nrLines); |
| 22 | void setVramSource(const uint8_t* adr); |
| 23 | void setNameTableAddress(int adr); |
| 24 | void setPatternTableAddress(int adr); |
| 25 | void setColorTableAddress(int adr); |
| 26 | void setPaletteSource(const uint8_t *adr); |
| 27 | void setBorderColor(int value); |
| 28 | void setDrawGrid(bool value); |
| 29 | void setTpBit(bool value); |
| 30 | void setTabletoShow(int value); |
| 31 | void setUseBlink(bool value); |
| 32 | void setForcedScreenRows(float value); |
| 33 | void setHighlightChar(int value); |
| 34 | |
| 35 | [[nodiscard]] unsigned getNameTableAddress() const; |
| 36 | [[nodiscard]] unsigned getPatternTableAddress() const; |
| 37 | [[nodiscard]] unsigned getColorTableAddress() const; |
| 38 | [[nodiscard]] int getScreenMode() const; |
| 39 | |
| 40 | void mousePressEvent(QMouseEvent* e) override; |
| 41 | void mouseMoveEvent (QMouseEvent* e) override; |
| 42 | |
| 43 | void warningImage(); |
| 44 | |
| 45 | // Used to draw a character on the external image used when clicked on the VramTiledView widget |
| 46 | void drawCharAtImage(int character, int x, int y, QImage& image); // Draw 8x8 character on reference image at topleft |
| 47 | QString textInfo(int x, int y, int character); |
| 48 | |
| 49 | [[nodiscard]] const uint8_t* getPaletteSource() const; |
| 50 | |
| 51 | void refresh(); |
| 52 | |
| 53 | signals: |
| 54 | void imageHovered(int screenX, int screenY, int character); |
| 55 | void imageClicked(int screenX, int screenY, int character, QString textinfo); |
| 56 | void highlightCount(uint8_t character, int count); |
| 57 | |
| 58 | private: |
| 59 | void paintEvent(QPaintEvent* e) override; |
| 60 | |
| 61 | void decode(); |
| 62 | void decodePalette(); |
| 63 | void decodePatternTable(); |
| 64 | void decodeNameTable(); |
| 65 | void overLayNameTable(); |
| 66 | void setPixel1x2(int x, int y, QRgb c); |
| 67 | void setPixel2x2(int x, int y, QRgb c); |
| 68 | QRgb getColor(int c); |
| 69 | |
| 70 | void decodePatternTableRegularChars(); |
| 71 | void decodePatternTableMultiColor(); |
| 72 | void decodeNameTableRegularChars(); |
| 73 | void decodeNameTableMultiColor(); |
| 74 | uint8_t getCharColorByte(int character, int x, int y, int row); |
| 75 | void drawCharAt(int character, int x, int y); // Draw 8x8 character on given location in image |
| 76 | |
| 77 | struct MouseEventInfo { |
| 78 | int x, y; |
| 79 | int character; |
| 80 | }; |
| 81 | std::optional<MouseEventInfo> infoFromMouseEvent(QMouseEvent* e); |
| 82 | |
| 83 | QString byteAsPattern(uint8_t byte); |
| 84 | |
| 85 | private: |
| 86 | QRgb msxPalette[16]; |
| 87 | QImage image; |
| 88 | QPixmap pixImage; |
| 89 | const uint8_t* palette = nullptr; |
| 90 | const uint8_t* vramBase = nullptr; |
| 91 | float zoomFactor; |
| 92 | bool drawGrid = true; |
| 93 | |
| 94 | int patternTableAddress = 0; |
| 95 | int nameTableAddress = 0; |
| 96 | int colorTableAddress = 0; |
| 97 | |
| 98 | int screenWidth = 32; |
| 99 | int screenHeight = 24; |
| 100 | int charWidth = 8; |
| 101 | int horiStep = 16; |
| 102 | |
| 103 | int lines = 212; |
| 104 | int screenMode = 0; |
| 105 | int tableToShow = 0; |
| 106 | int borderColor = 0; |
| 107 | float forcedScreenRows = 0; |
| 108 | int highlightChar = -1; // anything outside 0-255 will do |
| 109 | bool useBlink = false; |
| 110 | bool tpBit = false; |
| 111 | }; |
| 112 | |
| 113 | #endif // VRAMBITMAPPEDVIEW |