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 
17 namespace openmsx {
18 
19 class BooleanSetting;
20 class CommandConsole;
21 class ConsoleLine;
22 class Display;
23 class Reactor;
24 
25 class OSDConsoleRenderer final : public Layer, private Observer<Setting>
26 {
27 public:
28  OSDConsoleRenderer(Reactor& reactor, CommandConsole& console,
29  unsigned screenW, unsigned screenH, bool openGL);
30  ~OSDConsoleRenderer() override;
31 
32 private:
33  int initFontAndGetColumns();
34  int getRows();
35 
36  // Layer
37  void paint(OutputSurface& output) override;
38 
39  // Observer
40  void update(const Setting& setting) 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, const ConsoleLine& line,
50  gl::ivec2 pos, byte alpha);
51  void drawText2(OutputSurface& output, std::string_view text,
52  int& x, int y, byte alpha, unsigned rgb);
53  gl::ivec2 getTextPos(int cursorX, int cursorY);
54 
55  bool getFromCache(std::string_view text, unsigned rgb,
56  BaseImage*& image, unsigned& width);
57  void insertInCache(std::string text, unsigned rgb,
58  std::unique_ptr<BaseImage> image, unsigned width);
59  void clearCache();
60 
61  enum Placement {
62  CP_TOPLEFT, CP_TOP, CP_TOPRIGHT,
63  CP_LEFT, CP_CENTER, CP_RIGHT,
64  CP_BOTTOMLEFT, CP_BOTTOM, CP_BOTTOMRIGHT
65  };
66 
67  struct TextCacheElement {
68  TextCacheElement(std::string text_, unsigned 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  unsigned rgb;
76  unsigned width;
77  };
78  using TextCache = std::list<TextCacheElement>;
79 
80  Reactor& reactor;
81  Display& display;
82  CommandConsole& console;
83  BooleanSetting& consoleSetting;
84  const unsigned screenW;
85  const unsigned 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;
102  gl::ivec2 bgPos;
103  gl::ivec2 bgSize;
104  unsigned lastCursorX;
105  unsigned lastCursorY;
106  bool blink;
107  bool active;
108 };
109 
110 } // namespace openmsx
111 
112 #endif
openmsx::EnumSetting< Placement >
openmsx.hh
IntegerSetting.hh
gl_vec.hh
openmsx::FilenameSetting
Definition: FilenameSetting.hh:8
BaseImage.hh
openmsx::OSDConsoleRenderer
Definition: OSDConsoleRenderer.hh:25
Layer.hh
openmsx::Setting
Definition: Setting.hh:119
gl::vecN
Definition: gl_vec.hh:35
openmsx::Reactor
Contains the main loop of openMSX.
Definition: Reactor.hh:66
Observer.hh
openmsx::OSDConsoleRenderer::OSDConsoleRenderer
OSDConsoleRenderer(Reactor &reactor, CommandConsole &console, unsigned screenW, unsigned screenH, bool openGL)
Definition: OSDConsoleRenderer.cc:43
FilenameSetting.hh
TTFFont.hh
openmsx::Layer
Interface for display layers.
Definition: Layer.hh:11
openmsx::OSDConsoleRenderer::~OSDConsoleRenderer
~OSDConsoleRenderer() override
Definition: OSDConsoleRenderer.cc:141
EnumSetting.hh
openmsx::x
constexpr KeyMatrixPosition x
Keyboard bindings.
Definition: Keyboard.cc:1377
openmsx::ConsoleLine
This class represents a single text line in the console.
Definition: CommandConsole.hh:22
openmsx::Display
Represents the output window/screen of openMSX.
Definition: Display.hh:31
openmsx::BaseImage
Definition: BaseImage.hh:11
openmsx::BooleanSetting
Definition: BooleanSetting.hh:8
openmsx::IntegerSetting
A Setting with an integer value.
Definition: IntegerSetting.hh:10
openmsx::OutputSurface
A frame buffer where pixels can be written to.
Definition: OutputSurface.hh:19
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
openmsx::TTFFont
Definition: TTFFont.hh:11
openmsx::Observer
Generic Gang-of-Four Observer class, templatized edition.
Definition: Observer.hh:9
openmsx::CommandConsole
Definition: CommandConsole.hh:64