--- nono/lib/monitor.h 2026/04/29 17:05:44 1.1.1.9 +++ nono/lib/monitor.h 2026/04/29 17:05:56 1.1.1.12 @@ -12,7 +12,6 @@ #include "geometric.h" #include "mainapp.h" -#include "object.h" #include "textscreen.h" #include @@ -25,49 +24,36 @@ enum { }; // 識別子 (n番目で指定) -static constexpr uint ID_MONITOR_ATC(uint n) { - return ID_MONITOR_ATC0 + n; -} -static constexpr uint ID_MONITOR_CMMU(uint n) { - return ID_MONITOR_CMMU0 + n; -} -static constexpr uint ID_MONITOR_HOSTCOM(uint n) { - return ID_MONITOR_HOSTCOM0 + n; -} -static constexpr uint ID_MONITOR_HOSTNET(uint n) { - return ID_MONITOR_HOSTNET0 + n; -} -static constexpr uint ID_SUBWIN_CACHE(uint n) { - return ID_SUBWIN_CACHE0 + n; -} -static constexpr uint ID_MONITOR_MEMDUMP(uint n) { - return ID_MONITOR_MEMDUMP0 + n; -} -static constexpr uint ID_MONITOR_RTL8019AS(uint n) { +constexpr uint ID_MONITOR_ATC(uint n) { return ID_MONITOR_ATC0 + n; } +constexpr uint ID_MONITOR_CMMU(uint n) { return ID_MONITOR_CMMU0 + n; } +constexpr uint ID_MONITOR_HOSTCOM(uint n) { return ID_MONITOR_HOSTCOM0 + n; } +constexpr uint ID_MONITOR_HOSTNET(uint n) { return ID_MONITOR_HOSTNET0 + n; } +constexpr uint ID_SUBWIN_CACHE(uint n) { return ID_SUBWIN_CACHE0 + n; } +constexpr uint ID_MONITOR_MEMDUMP(uint n) { return ID_MONITOR_MEMDUMP0 + n; } +constexpr uint ID_MONITOR_RTL8019AS(uint n) { return ID_MONITOR_RTL8019AS0 + n; } -static constexpr uint ID_MONITOR_VIRTIO_BLOCK(uint n) { +constexpr uint ID_MONITOR_VIRTIO_BLOCK(uint n) { return ID_MONITOR_VIRTIO_BLOCK0 + n; } -static constexpr uint ID_MONITOR_XPMEMDUMP(uint n) { +constexpr uint ID_MONITOR_XPMEMDUMP(uint n) { return ID_MONITOR_XPMEMDUMP0 + n; } // 判定 -static constexpr bool IS_MONITOR_MEMDUMP(uint id) { +constexpr bool IS_MONITOR_MEMDUMP(uint id) { return (ID_MONITOR_MEMDUMP0 <= id && id < ID_MONITOR_MEMDUMP(MAX_MEMDUMP_MONITOR)); } -static constexpr bool IS_MONITOR_XPMEMDUMP(uint id) { +constexpr bool IS_MONITOR_XPMEMDUMP(uint id) { return (ID_MONITOR_XPMEMDUMP0 <= id && id < ID_MONITOR_XPMEMDUMP(MAX_XPMEMDUMP_MONITOR)); } +class BitmapRGBX; class Monitor; -using MonitorCallback_t = void (Object::*)(Monitor *, TextScreen&); -#define ToMonitorCallback(f) static_cast(f) - -// モニタ更新を呼び出すマクロ -#define MONITOR_UPDATE(m, scr) ((((m)->obj)->*((m)->func))((m), (scr))) +class Object; +using MonitorScreenCallback_t = void (Object::*)(Monitor *, TextScreen&); +using MonitorBitmapCallback_t = void (Object::*)(Monitor *, BitmapRGBX&); // モニタ class Monitor @@ -75,7 +61,7 @@ class Monitor public: Monitor(); Monitor(uint id_, Object *obj_); - ~Monitor(); + virtual ~Monitor(); uint GetId() const { return id; } @@ -99,13 +85,58 @@ class Monitor // このモニターの ID を表示用文字列にして返す。 const char *GetIdText() const { return GetIdText(id); } - Object *obj {}; // オブジェクト + // コールバック関数(テキストのみ)をセットする。 + template + void SetCallback(void (T::*func_)(Monitor *, TextScreen&)) { + screen_func = static_cast(func_); + } + // コールバック関数(テキスト、ビットマップ両方)をセットする。 + template + void SetCallback(void (T::*screen_func_)(Monitor *, TextScreen&), + void (T::*bitmap_func_)(Monitor *, BitmapRGBX&)) { + SetCallback(screen_func_); + bitmap_func = static_cast(bitmap_func_); + } - MonitorCallback_t func {}; // コールバック関数 + // ビットマップオーバーレイ用にパディング情報をセットする。 + void SetPadding(uint padding_) { + padding = padding_; + } + // ビットマップオーバーレイ用にフォントサイズをセットする。 + void SetFontSize(uint width, uint height) { + font_width = width; + font_height = height; + } + + uint GetFontWidth() const noexcept { return font_width; } + uint GetFontHeight() const noexcept { return font_height; } + // テキスト座標をビットマップ座標に変換する便利関数。 + uint BX(uint col) const noexcept { return padding + col * font_width; } + uint BY(uint row) const noexcept { return padding + row * font_height; } + + // モニタを更新する。 + void UpdateScreen(TextScreen& screen) { + (obj->*(screen_func))(this, screen); + } + // (あれば)ビットマップでモニタ更新する。 + bool UpdateBitmap(BitmapRGBX& bitmap) { + if (__predict_false(bitmap_func != NULL)) { + (obj->*(bitmap_func))(this, bitmap); + return true; + } else { + return false; + } + } + + Object *obj {}; // オブジェクト private: + // コールバック関数 + MonitorScreenCallback_t screen_func {}; + MonitorBitmapCallback_t bitmap_func {}; + // モニター識別子 - uint id; + uint id {}; // モニターサイズ nnSize size {}; @@ -113,6 +144,11 @@ class Monitor // 縦に可変長の場合の最大表示行数 (固定長なら 0) int maxh {}; + // ビットマップ描画用。 + uint font_width {}; + uint font_height {}; + uint padding {}; + // ID を表示用のテキストにしたものとの対応表。 static const std::vector> idtext; }; @@ -138,6 +174,7 @@ class MonitorManager // Create() の後、Init() より前に -M オプションの処理があるため。 // see wx/wxapp.cpp Monitor *Regist(uint id_, Object *parent_); + Monitor *Regist(Monitor *monitor_); // 削除 void Unregist(Monitor *mon_); @@ -157,24 +194,27 @@ class MonitorManager // 指定された id に対応する機種ケーパビリティを返す。 VMCap GetVMCap(uint id) const { - assert(id < info.size()); + assertmsg(id < info.size(), "id=%u < %zu", id, info.size()); return info[id].vmcap; } // 指定された id に対応する名前のリストを返す。 // id が範囲外だと assert する。 const std::vector& GetAliases(uint id) const { - assert(id < info.size()); + assertmsg(id < info.size(), "id=%u < %zu", id, info.size()); return info[id].aliases; } - // id リストから一覧表示用の文字列を生成して返す - static std::string MakeListString(std::vector list); + // id リストから一覧表示用の文字列リストを生成して返す + std::vector MakeListString(std::vector list) const; // 以降の追加を禁止する (プログラムミスを避けるため) void Fix(); private: + // Regist() の実体。 + Monitor *RegistCommon(uint id_, Object *parent_, Monitor *monitor_); + // モニターインスタンスの配列。添字はモニター ID なので歯抜け。 std::array, ID_SUBWIN_MAX> monitors /*{}*/;