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