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