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