|
|
1.1 root 1: //
2: // nono
1.1.1.2 root 3: // Copyright (C) 2020 nono project
4: // Licensed under nono-license.txt
1.1 root 5: //
6:
7: //
1.1.1.7 root 8: // モニター
1.1 root 9: //
10:
1.1.1.6 root 11: #include "wxmonitor.h"
1.1.1.7 root 12: #include "wxmainframe.h"
13:
14: //
15: // モニターパネル
16: //
17:
18: // イベントテーブル
19: wxBEGIN_EVENT_TABLE(WXMonitorPanel, inherited)
20: EVT_TIMER(wxID_ANY, WXMonitorPanel::OnTimer)
21: wxEND_EVENT_TABLE()
22:
23: // コンストラクタ
24: WXMonitorPanel::WXMonitorPanel(wxWindow *parent, Monitor& monitor_)
25: : inherited(parent, monitor_.GetSize())
26: , monitor(monitor_)
27: {
28: timer.SetOwner(this);
29:
30: // 現在の設定値を適用
1.1.1.8 ! root 31: auto mainframe = dynamic_cast<WXMainFrame*>(GetParent()->GetParent());
! 32: SetRate(mainframe->GetMonitorRate());
1.1.1.7 root 33:
34: // 最初に一回描画を起こす
35: wxTimerEvent dummy(timer);
36: AddPendingEvent(dummy);
37: }
38:
39: // デストラクタ
40: WXMonitorPanel::~WXMonitorPanel()
41: {
42: }
43:
44: // タイマーイベント
45: void
46: WXMonitorPanel::OnTimer(wxTimerEvent& event)
47: {
48: DoRefresh();
49: }
50:
51: // 画面を更新して再描画する。
52: //
53: // 通常はタイマーイベントにより更新間隔ごとに呼ばれるが、
54: // ユーザ操作により画面の更新が必要ならその都度直接これを呼ぶ。
55: void
56: WXMonitorPanel::DoRefresh()
57: {
58: // モニタースクリーンを更新して
59: MONITOR_UPDATE(monitor, screen);
60:
61: // 必要なら再描画
62: if (screen.GetBuf() != prevbuf) {
63: Refresh();
64: }
65: }
66:
67: // 画面更新頻度を Hz で設定する。
68: void
69: WXMonitorPanel::SetRate(int hz)
70: {
71: timer.Start(1000 / hz);
72: }
73:
74:
75: //
76: // モニターウィンドウ
77: //
1.1.1.6 root 78:
1.1 root 79: // コンストラクタ
1.1.1.5 root 80: WXMonitorWindow::WXMonitorWindow(wxWindow *parent, const wxString& name,
81: Monitor& monitor_)
82: : inherited(parent, wxID_ANY, name)
1.1 root 83: {
1.1.1.7 root 84: // モニタパネル
85: monpanel = new WXMonitorPanel(this, monitor_);
1.1.1.6 root 86: DoSize();
1.1 root 87: }
88:
89: // デストラクタ
90: WXMonitorWindow::~WXMonitorWindow()
91: {
92: }
1.1.1.7 root 93:
94:
95: //
96: // 縦スクロールバー付きモニタウィンドウ
97: //
98:
99: // イベントテーブル
100: wxBEGIN_EVENT_TABLE(WXScrollMonitorWindow, inherited)
101: EVT_SIZE(WXScrollMonitorWindow::OnSize)
102: wxEND_EVENT_TABLE()
103:
104: // コンストラクタ
105: WXScrollMonitorWindow::WXScrollMonitorWindow(wxWindow *parent,
106: const wxString& name, Monitor& monitor_)
107: : inherited(parent, wxID_ANY, name, DEFAULT_STYLE | wxRESIZE_BORDER)
108: {
109: // →
110: // +--------------+---------+
111: // | MonitorPanel | VScroll |
112: // +--------------+---------+
113:
114: wxBoxSizer *topsizer = new wxBoxSizer(wxHORIZONTAL);
115:
116: // モニタパネル
117: monpanel = new WXMonitorPanel(this, monitor_);
118: topsizer->Add(monpanel, 1, wxEXPAND);
119:
120: // スクロールバー
121: vscroll = new WXScrollBar(this, wxID_ANY, wxSB_VERTICAL);
122: topsizer->Add(vscroll, 0, wxEXPAND);
123:
124: SetSizer(topsizer);
125:
126: // ウィンドウサイズを確定させる
127: DoSize();
128:
129: // スクロールのために (パネル領域での) MouseWheel イベントもここで
130: // 受け取りたい。スクロールバー上のマウスホイール操作はスクロールバーが
131: // 処理しているので問題ないが、パネル領域でのマウスホイール操作はここ
132: // (wxFrame)ではなくパネルに対して飛んでくる。
133: // ここで一緒に処理したほうが楽なので、こちらに回す。
134: monpanel->Connect(wxEVT_MOUSEWHEEL,
135: wxMouseEventHandler(WXScrollMonitorWindow::OnMouseWheel), NULL, this);
136:
137: // スクロールバーからの位置変更通知
138: vscroll->Connect(NONO_EVT_SCROLL,
139: wxScrollEventHandler(WXScrollMonitorWindow::OnScroll), NULL, this);
140: }
141:
142: // デストラクタ
143: WXScrollMonitorWindow::~WXScrollMonitorWindow()
144: {
145: }
146:
147: bool
148: WXScrollMonitorWindow::Layout()
149: {
150: // 縦リサイズ可能レイアウト
151: return LayoutTextVResize(monpanel);
152: }
153:
154: // サイズ変更イベント
155: void
156: WXScrollMonitorWindow::OnSize(wxSizeEvent& event)
157: {
158: inherited::OnSize(event);
159:
160: // 今の所ヘッダが常に1行ある
161: static int HEADLINES = 1;
162:
163: // スクロールバーを再設定
164: int pos = (int)monpanel->GetUserData();
165: int thumbsize = monpanel->GetRow() - HEADLINES;
166: int range = monpanel->GetMonitor().GetMaxHeight() - HEADLINES;
167: int pagesize = thumbsize - 1;
168: if (pos > range - thumbsize) {
169: pos = range - thumbsize;
170: DoScroll(pos);
171: }
172: vscroll->SetScrollParam(pos, thumbsize, range, pagesize);
173: }
174:
175: // マウスホイールイベント (WXTextScreen 上で起きたやつをこっちに回してある)
176: void
177: WXScrollMonitorWindow::OnMouseWheel(wxMouseEvent& event)
178: {
179: // GetWheelRotation() は上(奥)向きに回すと +120、下(手前)に回すと -120。
180: // どこの決まりか知らんけど、スクロールバーのほうはホイール1段階で3行
181: // スクロールするのでそれに合わせる。
182: int pos = (int)monpanel->GetUserData();
183: pos = pos - event.GetWheelRotation() / 40;
184:
185: int maxpos = vscroll->GetRange() - vscroll->GetThumbSize();
186: if (pos < 0)
187: pos = 0;
188: if (pos > maxpos)
189: pos = maxpos;
190:
191: DoScroll(pos);
192: // スクロールバーの位置を追従
193: vscroll->SetThumbPosition(pos);
194: }
195:
196: // スクロールバーからの通知イベント
197: void
198: WXScrollMonitorWindow::OnScroll(wxScrollEvent& event)
199: {
200: DoScroll(event.GetPosition());
201: }
202:
203: // スクロール処理 (OnScroll() と OnMouseWheel() から呼ばれる)
204: void
205: WXScrollMonitorWindow::DoScroll(int pos)
206: {
207: // userdata が表示開始位置になっている
208: monpanel->SetUserData(pos);
209: monpanel->DoRefresh();
210: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.