--- nono/lib/monitor.h 2026/04/29 17:05:26 1.1.1.7 +++ nono/lib/monitor.h 2026/04/29 17:05:30 1.1.1.8 @@ -14,6 +14,7 @@ #include "mainapp.h" #include "object.h" #include "textscreen.h" +#include // モニタ識別子 // @@ -62,24 +63,17 @@ class Monitor; using MonitorCallback_t = void (Object::*)(Monitor *, TextScreen&); #define ToMonitorCallback(f) static_cast(f) -// モニタコールバックを宣言するマクロ。 -// 強制力はないけどヘッダで宣言するところで使うこと。 -// コールバック関数の型が変わった時にコンパイルエラーで検出させるため。 -#define DECLARE_MONITOR_CALLBACK(name) void name (Monitor *, TextScreen&) // モニタ更新を呼び出すマクロ -#define MONITOR_UPDATE(m, scr) ((((m).obj)->*((m).func))(&(m), (scr))) +#define MONITOR_UPDATE(m, scr) ((((m)->obj)->*((m)->func))((m), (scr))) // モニタ class Monitor { public: Monitor(); - explicit Monitor(Object *obj_); + Monitor(uint id_, Object *obj_); ~Monitor(); - Object *obj {}; // オブジェクト - MonitorCallback_t func {}; // コールバック関数 - uint GetId() const { return id; } // モニターの表示サイズを設定・取得。 @@ -91,21 +85,16 @@ class Monitor void SetMaxHeight(int maxh_) { maxh = maxh_; } int GetMaxHeight() const { return maxh; } - // 登録。 - // モニタの登録はコンストラクタおよび Create フェーズまでに行うこと。 - // Create() の後、Init() より前に -M オプションの処理があるため。 - // see wx/wxapp.cpp - void Regist(uint id); - - // 削除。 - void Unregist(); - // ID を表示用文字列にして返す。 static const char *GetIdText(uint id); // このモニターの ID を表示用文字列にして返す。 const char *GetIdText() const { return GetIdText(id); } + Object *obj {}; // オブジェクト + + MonitorCallback_t func {}; // コールバック関数 + private: // モニター識別子 uint id; @@ -125,8 +114,6 @@ class Monitor // class MonitorManager { - friend class Monitor; - // モニター情報 (事前定義) struct MonitorInfo { uint id; @@ -138,29 +125,26 @@ class MonitorManager MonitorManager(); ~MonitorManager(); - // 現在登録されているモニターのリストを返す。 - const std::vector& GetList() const { return list; } + // 登録。 + // モニタの登録はコンストラクタおよび Create フェーズまでに行うこと。 + // Create() の後、Init() より前に -M オプションの処理があるため。 + // see wx/wxapp.cpp + Monitor *Regist(uint id_, Object *parent_); + + // 削除 + void Unregist(Monitor *mon_); + + // 現在登録されているモニターの(穴空きでない)リストを返す。 + const std::vector GetList() const; // 指定された id を持つモニターを返す。 // こっちは、なければ assert する。 - Monitor& Get(uint id) const { - for (auto mon : list) { - if (mon->GetId() == id) { - return *mon; - } - } - PANIC("id=%d not found", id); - } + Monitor *Get(uint id) const; // 指定された id を持つモニターを返す。 // こっちは、なければ NULL を返す。 Monitor *Find(uint id) const { - for (auto mon : list) { - if (mon->GetId() == id) { - return mon; - } - } - return NULL; + return monitors[id].get(); } // 指定された id に対応する機種ケーパビリティを返す。 @@ -183,14 +167,8 @@ class MonitorManager void Fix(); private: - // 登録 (friend の Monitor からのみ呼べる) - void Regist(Monitor *mon); - - // 削除 (friend の Monitor からのみ呼べる) - void Unregist(Monitor *mon); - - // 現在登録されているモニターのリスト - std::vector list {}; + // モニターインスタンスの配列。添字はモニター ID なので歯抜け。 + std::array, ID_SUBWIN_MAX> monitors /*{}*/; // モニタの登録は -M オプションの処理が始まるまでに終えないといけない。 bool fixed {};