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, std::string_view text,
50  int cx, int cy, byte alpha, uint32_t rgb);
51  gl::ivec2 getTextPos(int cursorX, int cursorY) const;
52  void drawConsoleText(OutputSurface& output, byte visibility);
53 
54  bool getFromCache(std::string_view text, uint32_t rgb,
55  BaseImage*& image, unsigned& width);
56  void insertInCache(std::string text, uint32_t rgb,
57  std::unique_ptr<BaseImage> image, unsigned width);
58  void clearCache();
59 
60  enum Placement {
61  CP_TOPLEFT, CP_TOP, CP_TOPRIGHT,
62  CP_LEFT, CP_CENTER, CP_RIGHT,
63  CP_BOTTOMLEFT, CP_BOTTOM, CP_BOTTOMRIGHT
64  };
65 
66  struct TextCacheElement {
67  TextCacheElement(std::string text_, uint32_t rgb_,
68  std::unique_ptr<BaseImage> image_, unsigned width_)
69  : text(std::move(text_)), image(std::move(image_))
70  , rgb(rgb_), width(width_) {}
71 
72  std::string text;
73  std::unique_ptr<BaseImage> image;
74  uint32_t rgb;
75  unsigned width;
76  };
77  using TextCache = std::list<TextCacheElement>;
78 
79  Reactor& reactor;
80  Display& display;
81  CommandConsole& console;
82  BooleanSetting& consoleSetting;
83  const unsigned screenW;
84  const unsigned screenH;
85  const bool openGL;
86 
87  TTFFont font;
88  TextCache textCache;
89  TextCache::iterator cacheHint;
90 
91  EnumSetting<Placement> consolePlacementSetting;
92  IntegerSetting fontSizeSetting;
93  FilenameSetting fontSetting;
94  IntegerSetting consoleColumnsSetting;
95  IntegerSetting consoleRowsSetting;
96  FilenameSetting backgroundSetting;
97  std::unique_ptr<BaseImage> backgroundImage;
98 
99  uint64_t lastBlinkTime;
100  uint64_t activeTime;
101  gl::ivec2 bgPos;
102  gl::ivec2 bgSize;
103  unsigned lastCursorX;
104  unsigned lastCursorY;
105  bool blink;
106  bool active;
107 };
108 
109 } // namespace openmsx
110 
111 #endif
openmsx::EnumSetting< Placement >
openmsx.hh
IntegerSetting.hh
gl_vec.hh
openmsx::FilenameSetting
Definition: FilenameSetting.hh:9
BaseImage.hh
openmsx::OSDConsoleRenderer
Definition: OSDConsoleRenderer.hh:26
Layer.hh
openmsx::Setting
Definition: Setting.hh:120
gl::vecN
Definition: gl_vec.hh:36
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::BaseImage
Definition: BaseImage.hh:12
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:12
openmsx::Observer
Generic Gang-of-Four Observer class, templatized edition.
Definition: Observer.hh:10
openmsx::CommandConsole
Definition: CommandConsole.hh:59