|
|
1.1 ! root 1: // ! 2: // nono ! 3: // Copyright (C) 2021 nono project ! 4: // Licensed under nono-license.txt ! 5: // ! 6: ! 7: #pragma once ! 8: ! 9: #include "geometric.h" ! 10: #include "object.h" ! 11: #include "textscreen.h" ! 12: #include "vm.h" ! 13: ! 14: // モニタ識別子 ! 15: // ! 16: // テキストモニタの識別子だがメニューID (とウィンドウの識別ID) としても使う ! 17: // ので wxmainframe あたりも参照。 ! 18: enum { ! 19: #include "monitor_id.h" ! 20: }; ! 21: ! 22: // 識別子 (n番目で指定) ! 23: static constexpr int ID_MONITOR_ATC(int n) { ! 24: return ID_MONITOR_ATC0 + n; ! 25: } ! 26: static constexpr int ID_MONITOR_CMMU(int n) { ! 27: return ID_MONITOR_CMMU0 + n; ! 28: } ! 29: static constexpr int ID_SUBWIN_CACHE(int n) { ! 30: return ID_SUBWIN_CACHE0 + n; ! 31: } ! 32: static constexpr int ID_MONITOR_MEMDUMP(int n) { ! 33: return ID_MONITOR_MEMDUMP0 + n; ! 34: } ! 35: // 判定 ! 36: static constexpr bool IS_MONITOR_MEMDUMP(int id) { ! 37: return (ID_MONITOR_MEMDUMP0 <= id && ! 38: id < (ID_MONITOR_MEMDUMP0 + MAX_MEMDUMP_MONITOR)); ! 39: } ! 40: ! 41: class Monitor; ! 42: using MonitorCallback_t = void (Object::*)(Monitor *, TextScreen&); ! 43: // モニタコールバックを宣言するマクロ。 ! 44: // 強制力はないけどヘッダで宣言するところで使うこと。 ! 45: // コールバック関数の型が変わった時にコンパイルエラーで検出させるため。 ! 46: #define DECLARE_MONITOR_CALLBACK(name) void name (Monitor *, TextScreen&) ! 47: // モニタ更新を呼び出すマクロ ! 48: #define MONITOR_UPDATE(m, scr) ((((m).obj)->*((m).func))(&(m), (scr))) ! 49: ! 50: // モニタ ! 51: class Monitor ! 52: { ! 53: public: ! 54: Monitor(); ! 55: Monitor(Object *obj_); ! 56: virtual ~Monitor(); ! 57: ! 58: Object *obj {}; // オブジェクト ! 59: MonitorCallback_t func {}; // コールバック関数 ! 60: ! 61: int GetId() const { return id; } ! 62: ! 63: void SetSize(nnSize size_) { size = size_; } ! 64: void SetSize(int col_, int row_) { SetSize(nnSize(col_, row_)); } ! 65: virtual nnSize GetSize() const { return size; } ! 66: ! 67: // 登録。 ! 68: // モニタの登録はコンストラクタおよび Create フェーズまでに行うこと。 ! 69: // Create() の後、Init() より前に -M オプションの処理があるため。 ! 70: // see wx/wxapp.cpp ! 71: void Regist(int id); ! 72: ! 73: // 削除。 ! 74: void Unregist(); ! 75: ! 76: private: ! 77: // モニター識別子 ! 78: int id; ! 79: ! 80: // モニターサイズ ! 81: nnSize size {}; ! 82: }; ! 83: ! 84: // ! 85: // モニターマネージャ ! 86: // ! 87: class MonitorManager ! 88: { ! 89: friend class Monitor; ! 90: ! 91: // モニター情報 (事前定義) ! 92: struct MonitorInfo { ! 93: int id; ! 94: vmf_t feature; ! 95: std::vector<std::string> aliases; ! 96: }; ! 97: ! 98: public: ! 99: // 現在登録されているモニターのリストを返す。 ! 100: const std::vector<Monitor *>& GetList() const { return list; } ! 101: ! 102: // 指定された id を持つモニターを返す。 ! 103: // こっちは、なければ assert する。 ! 104: Monitor& Get(int id) const { ! 105: for (auto mon : list) { ! 106: if (mon->GetId() == id) { ! 107: return *mon; ! 108: } ! 109: } ! 110: assertmsg(false, "id=%d not found", id); ! 111: } ! 112: ! 113: // 指定された id を持つモニターを返す。 ! 114: // こっちは、なければ NULL を返す。 ! 115: Monitor *Find(int id) const { ! 116: for (auto mon : list) { ! 117: if (mon->GetId() == id) { ! 118: return mon; ! 119: } ! 120: } ! 121: return NULL; ! 122: } ! 123: ! 124: // 指定された id に対応する機種フラグを返す。 ! 125: vmf_t GetFeature(int id) const { ! 126: assert(0 <= id && id < info.size()); ! 127: return info[id].feature; ! 128: } ! 129: ! 130: // 指定された id に対応する名前のリストを返す。 ! 131: // id が範囲外だと assert する。 ! 132: const std::vector<std::string>& GetAliases(int id) const { ! 133: assert(0 <= id && id < info.size()); ! 134: return info[id].aliases; ! 135: } ! 136: ! 137: // id リストから一覧表示用の文字列を生成して返す ! 138: static std::string MakeListString(std::vector<int> list); ! 139: ! 140: // 以降の追加を禁止する (プログラムミスを避けるため) ! 141: void Fix(); ! 142: ! 143: private: ! 144: // 登録 (friend の Monitor からのみ呼べる) ! 145: void Regist(Monitor *mon); ! 146: ! 147: // 削除 (friend の Monitor からのみ呼べる) ! 148: void Unregist(Monitor *mon); ! 149: ! 150: // 現在登録されているモニターのリスト ! 151: std::vector<Monitor *> list {}; ! 152: ! 153: // 事前に設定されているモニター情報 ! 154: static const std::vector<MonitorInfo> info; ! 155: ! 156: // モニタの登録は -M オプションの処理が始まるまでに終えないといけない。 ! 157: bool fixed {}; ! 158: }; ! 159: ! 160: extern MonitorManager gMonitorManager;
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.