openMSX
OSDConsoleRenderer.hh
Go to the documentation of this file.
1#ifndef OSDCONSOLERENDERER_HH
2#define OSDCONSOLERENDERER_HH
3
4#include "BaseImage.hh"
5#include "Layer.hh"
6#include "TTFFont.hh"
7#include "EnumSetting.hh"
8#include "IntegerSetting.hh"
9#include "FilenameSetting.hh"
10#include "Observer.hh"
11#include "gl_vec.hh"
12#include "openmsx.hh"
13#include <list>
14#include <memory>
15#include <string_view>
16#include <tuple>
17
18namespace openmsx {
19
20class BooleanSetting;
21class CommandConsole;
22class Display;
23class Reactor;
24
25class OSDConsoleRenderer final : public Layer, private Observer<Setting>
26{
27public:
28 OSDConsoleRenderer(Reactor& reactor, CommandConsole& console,
29 int screenW, int screenH, bool openGL);
30 ~OSDConsoleRenderer() override;
31
32private:
33 [[nodiscard]] int initFontAndGetColumns();
34 [[nodiscard]] int getRows();
35
36 // Layer
37 void paint(OutputSurface& output) override;
38
39 // Observer
40 void update(const Setting& setting) noexcept override;
41
42 void adjustColRow();
43 void setActive(bool active);
44
45 bool updateConsoleRect();
46 void loadFont (std::string_view value);
47 void loadBackground(std::string_view value);
48 byte getVisibility() const;
49 void drawText(OutputSurface& output, std::string_view text,
50 int cx, int cy, byte alpha, uint32_t rgb);
51 [[nodiscard]] gl::ivec2 getTextPos(int cursorX, int cursorY) const;
52 void drawConsoleText(OutputSurface& output, byte visibility);
53
54 [[nodiscard]] std::tuple<bool, BaseImage*, unsigned> getFromCache(
55 std::string_view text, uint32_t rgb);
56 void insertInCache(std::string text, uint32_t rgb,
57 std::unique_ptr<BaseImage> image, unsigned width);
58 void clearCache();
59
60private:
61 enum Placement {
62 CP_TOP_LEFT, CP_TOP, CP_TOP_RIGHT,
63 CP_LEFT, CP_CENTER, CP_RIGHT,
64 CP_BOTTOM_LEFT, CP_BOTTOM, CP_BOTTOM_RIGHT
65 };
66
67 struct TextCacheElement {
68 TextCacheElement(std::string text_, uint32_t rgb_,
69 std::unique_ptr<BaseImage> image_, unsigned width_)
70 : text(std::move(text_)), image(std::move(image_))
71 , rgb(rgb_), width(width_) {}
72
73 std::string text;
74 std::unique_ptr<BaseImage> image;
75 uint32_t rgb;
76 unsigned width; // in case of trailing whitespace width != image->getWidth()
77 };
78 using TextCache = std::list<TextCacheElement>;
79
80 Reactor& reactor;
81 Display& display;
82 CommandConsole& console;
83 BooleanSetting& consoleSetting;
84 const int screenW;
85 const int screenH;
86 const bool openGL;
87
88 TTFFont font;
89 TextCache textCache;
90 TextCache::iterator cacheHint;
91
92 EnumSetting<Placement> consolePlacementSetting;
93 IntegerSetting fontSizeSetting;
94 FilenameSetting fontSetting;
95 IntegerSetting consoleColumnsSetting;
96 IntegerSetting consoleRowsSetting;
97 FilenameSetting backgroundSetting;
98 std::unique_ptr<BaseImage> backgroundImage;
99
100 uint64_t lastBlinkTime;
101 uint64_t activeTime{0};
102 gl::ivec2 bgPos{}; // recalculate on first paint()
103 gl::ivec2 bgSize{};
104 unsigned lastCursorX{0};
105 unsigned lastCursorY{0};
106 bool blink{false};
107 bool active{false};
108};
109
110} // namespace openmsx
111
112#endif
std::string image
Definition: HDImageCLI.cc:13
BaseSetting * setting
Definition: Interpreter.cc:28
Represents the output window/screen of openMSX.
Definition: Display.hh:33
A Setting with an integer value.
Interface for display layers.
Definition: Layer.hh:12
OSDConsoleRenderer(Reactor &reactor, CommandConsole &console, int screenW, int screenH, bool openGL)
Generic Gang-of-Four Observer class, templatized edition.
Definition: Observer.hh:10
A frame buffer where pixels can be written to.
Contains the main loop of openMSX.
Definition: Reactor.hh:68
This file implemented 3 utility functions:
Definition: Autofire.cc:9