|
|
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:
1.1.1.10 root 15: //#define WINDOW_DEBUG 1
16:
17: #if defined(WINDOW_DEBUG)
18: #define DPRINTF(fmt...) printf(fmt)
19: #else
20: #define DPRINTF(fmt...) /**/
21: #endif
22:
1.1.1.7 root 23: //
24: // モニターパネル
25: //
26:
27: // イベントテーブル
28: wxBEGIN_EVENT_TABLE(WXMonitorPanel, inherited)
29: EVT_TIMER(wxID_ANY, WXMonitorPanel::OnTimer)
30: wxEND_EVENT_TABLE()
31:
32: // コンストラクタ
1.1.1.9 root 33: WXMonitorPanel::WXMonitorPanel(wxWindow *parent, Monitor *monitor_)
34: : inherited(parent, monitor_->GetSize())
1.1.1.7 root 35: , monitor(monitor_)
36: {
37: timer.SetOwner(this);
38:
39: // 現在の設定値を適用
1.1.1.8 root 40: auto mainframe = dynamic_cast<WXMainFrame*>(GetParent()->GetParent());
41: SetRate(mainframe->GetMonitorRate());
1.1.1.7 root 42:
43: // 最初に一回描画を起こす
44: wxTimerEvent dummy(timer);
45: AddPendingEvent(dummy);
46: }
47:
48: // デストラクタ
49: WXMonitorPanel::~WXMonitorPanel()
50: {
51: }
52:
53: // タイマーイベント
54: void
55: WXMonitorPanel::OnTimer(wxTimerEvent& event)
56: {
57: DoRefresh();
58: }
59:
60: // 画面を更新して再描画する。
61: //
62: // 通常はタイマーイベントにより更新間隔ごとに呼ばれるが、
63: // ユーザ操作により画面の更新が必要ならその都度直接これを呼ぶ。
64: void
65: WXMonitorPanel::DoRefresh()
66: {
67: // モニタースクリーンを更新して
68: MONITOR_UPDATE(monitor, screen);
69:
70: // 必要なら再描画
71: if (screen.GetBuf() != prevbuf) {
72: Refresh();
73: }
74: }
75:
76: // 画面更新頻度を Hz で設定する。
77: void
78: WXMonitorPanel::SetRate(int hz)
79: {
80: timer.Start(1000 / hz);
81: }
82:
83:
84: //
85: // モニターウィンドウ
86: //
1.1.1.6 root 87:
1.1 root 88: // コンストラクタ
1.1.1.5 root 89: WXMonitorWindow::WXMonitorWindow(wxWindow *parent, const wxString& name,
1.1.1.9 root 90: Monitor *monitor_)
1.1.1.5 root 91: : inherited(parent, wxID_ANY, name)
1.1 root 92: {
1.1.1.7 root 93: // モニタパネル
94: monpanel = new WXMonitorPanel(this, monitor_);
1.1.1.10 root 95: Fit();
1.1 root 96: }
97:
98: // デストラクタ
99: WXMonitorWindow::~WXMonitorWindow()
100: {
101: }
1.1.1.7 root 102:
103:
104: //
105: // 縦スクロールバー付きモニタウィンドウ
106: //
107:
108: // コンストラクタ
109: WXScrollMonitorWindow::WXScrollMonitorWindow(wxWindow *parent,
1.1.1.9 root 110: const wxString& name, Monitor *monitor_)
1.1.1.7 root 111: : inherited(parent, wxID_ANY, name, DEFAULT_STYLE | wxRESIZE_BORDER)
112: {
1.1.1.10 root 113: DPRINTF("%s begin\n", __method__);
114:
1.1.1.7 root 115: // +--------------+---------+
116: // | MonitorPanel | VScroll |
117: // +--------------+---------+
118:
119: // モニタパネル
120: monpanel = new WXMonitorPanel(this, monitor_);
121:
122: // スクロールバー
123: vscroll = new WXScrollBar(this, wxID_ANY, wxSB_VERTICAL);
124:
1.1.1.11! root 125: // 自前レイアウト。
! 126: SetMyLayout();
1.1.1.7 root 127:
128: // ウィンドウサイズを確定させる
1.1.1.10 root 129: FontChanged();
1.1.1.7 root 130:
131: // スクロールのために (パネル領域での) MouseWheel イベントもここで
132: // 受け取りたい。スクロールバー上のマウスホイール操作はスクロールバーが
133: // 処理しているので問題ないが、パネル領域でのマウスホイール操作はここ
134: // (wxFrame)ではなくパネルに対して飛んでくる。
135: // ここで一緒に処理したほうが楽なので、こちらに回す。
136: monpanel->Connect(wxEVT_MOUSEWHEEL,
137: wxMouseEventHandler(WXScrollMonitorWindow::OnMouseWheel), NULL, this);
138:
139: // スクロールバーからの位置変更通知
140: vscroll->Connect(NONO_EVT_SCROLL,
141: wxScrollEventHandler(WXScrollMonitorWindow::OnScroll), NULL, this);
1.1.1.10 root 142: DPRINTF("%s done\n", __method__);
1.1.1.7 root 143: }
144:
145: // デストラクタ
146: WXScrollMonitorWindow::~WXScrollMonitorWindow()
147: {
148: }
149:
1.1.1.10 root 150: void
151: WXScrollMonitorWindow::FontChanged()
1.1.1.7 root 152: {
1.1.1.10 root 153: monpanel->FontChanged();
154: vscroll->FontChanged();
155: DPRINTF("%s %d\n", __method__, monpanel->GetFontHeight());
156:
157: Fit();
1.1.1.7 root 158: }
159:
1.1.1.11! root 160: // 自前レイアウト方式のサイズに関する情報を返す。
! 161: bool
! 162: WXScrollMonitorWindow::GetMySizeHints(wxSize *newp, wxSize *minp, wxSize *maxp,
! 163: wxSize *incp)
1.1.1.7 root 164: {
1.1.1.11! root 165: auto psize = monpanel->GetSize();
! 166: auto vsize = vscroll->GetSize();
1.1.1.7 root 167:
1.1.1.11! root 168: // 幅は monpanel 幅 + スクロールバーの幅、高さは monpanel の高さで決まる。
! 169: // monpanel には四辺に Padding があることに注意。
! 170: int x = psize.x + vsize.x;
! 171: int min_y = std::max(vscroll->GetMinSize().y, monpanel->GetScreenHeight(1));
! 172: int new_y = std::max(psize.y, min_y);
! 173: wxSize newsize(x, new_y);
! 174: wxSize minsize(x, min_y);
! 175: wxSize maxsize(x, GetMaxClientSize().y);
! 176: wxSize incsize(0, monpanel->GetFontHeight());
! 177:
! 178: if (newp) *newp = newsize;
! 179: if (minp) *minp = minsize;
! 180: if (maxp) *maxp = maxsize;
! 181: if (incp) *incp = incsize;
! 182: return true;
1.1.1.10 root 183: }
1.1.1.7 root 184:
1.1.1.10 root 185: bool
186: WXScrollMonitorWindow::Layout()
187: {
1.1.1.11! root 188: if (MyLayout() == false) {
! 189: // コントロールを配置。
! 190: wxSize client = GetClientSize();
! 191: const wxSize vsize = vscroll->GetSize();
! 192:
! 193: int mon_width = client.x - vsize.x;
! 194: int mon_height = client.y;
! 195: // 最低でも 1px ないと GTK とかに怒られる。今は起きないはず?
! 196: if (__predict_false(mon_width < 1)) {
! 197: mon_width = 1;
! 198: }
! 199: if (__predict_false(mon_height < 1)) {
! 200: mon_height = 1;
! 201: }
1.1.1.10 root 202: #if defined(WINDOW_DEBUG)
1.1.1.11! root 203: const wxSize win = GetSize();
! 204: const wxSize minwin = GetMinSize();
! 205: printf("%s WinSize =(%d,%d) MinWin =(%d,%d) Shown=%u\n",
! 206: __method__, win.x, win.y, minwin.x, minwin.y, IsShown());
! 207: const wxSize min = GetMinClientSize();
! 208: printf("%s ClientSize=(%d,%d) MinClient=(%d,%d)\n",
! 209: __method__, client.x, client.y, min.x, min.y);
1.1.1.10 root 210: #endif
211:
1.1.1.11! root 212: monpanel->SetSize(0, 0, mon_width, mon_height);
! 213: vscroll->SetSize(mon_width, 0, vsize.x, mon_height);
1.1.1.10 root 214:
1.1.1.11! root 215: #if defined(WINDOW_DEBUG)
! 216: const wxSize monsize = monpanel->GetSize();
! 217: const wxSize vsize1 = vscroll->GetSize();
! 218: int py = monsize.y - monpanel->GetPaddingY();
! 219: int height = monpanel->GetFontHeight();
! 220: int row = (height != 0) ? (py / height) : 0;
! 221: int res = (height != 0) ? (py % height) : 0;
! 222: printf("%s mon=(%d,%d) vscroll=(%d,%d), row=%d%s\n", __method__,
! 223: monsize.x, monsize.y, vsize1.x, vsize1.y,
! 224: row, (res == 0 ? "" : "+"));
! 225: #endif
1.1.1.10 root 226:
1.1.1.11! root 227: // スクロールバーを再設定。
! 228: // 今の所ヘッダが常に1行ある。
! 229: static int HEADLINES = 1;
! 230: int pos = (int)monpanel->GetUserData();
! 231: int thumbsize = monpanel->GetRow() - HEADLINES;
! 232: int range = monpanel->GetMonitor()->GetMaxHeight() - HEADLINES;
! 233: int pagesize = thumbsize - 1;
! 234: if (pos > range - thumbsize) {
! 235: pos = range - thumbsize;
! 236: DoScroll(pos);
! 237: }
! 238: vscroll->SetScrollParam(pos, thumbsize, range, pagesize);
1.1.1.7 root 239: }
1.1.1.10 root 240: return true;
241: }
242:
1.1.1.7 root 243: // マウスホイールイベント (WXTextScreen 上で起きたやつをこっちに回してある)
244: void
245: WXScrollMonitorWindow::OnMouseWheel(wxMouseEvent& event)
246: {
247: // GetWheelRotation() は上(奥)向きに回すと +120、下(手前)に回すと -120。
248: // どこの決まりか知らんけど、スクロールバーのほうはホイール1段階で3行
249: // スクロールするのでそれに合わせる。
250: int pos = (int)monpanel->GetUserData();
251: pos = pos - event.GetWheelRotation() / 40;
252:
253: int maxpos = vscroll->GetRange() - vscroll->GetThumbSize();
254: if (pos < 0)
255: pos = 0;
256: if (pos > maxpos)
257: pos = maxpos;
258:
259: DoScroll(pos);
260: // スクロールバーの位置を追従
261: vscroll->SetThumbPosition(pos);
262: }
263:
264: // スクロールバーからの通知イベント
265: void
266: WXScrollMonitorWindow::OnScroll(wxScrollEvent& event)
267: {
268: DoScroll(event.GetPosition());
269: }
270:
271: // スクロール処理 (OnScroll() と OnMouseWheel() から呼ばれる)
272: void
273: WXScrollMonitorWindow::DoScroll(int pos)
274: {
275: // userdata が表示開始位置になっている
276: monpanel->SetUserData(pos);
277: monpanel->DoRefresh();
278: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.