|
|
1.1 root 1: //
2: // nono
3: // Copyright (C) 2022 nono project
4: // Licensed under nono-license.txt
5: //
6:
7: //
8: // ベクタテーブルモニタ
9: //
10:
11: #include "wxvectormonitor.h"
12: #include "wxtextscreen.h"
13: #include "vectortable.h"
14:
15: // イベントテーブル
16: wxBEGIN_EVENT_TABLE(WXVectorMonitor, inherited)
17: EVT_SIZE(WXVectorMonitor::OnSize)
18: wxEND_EVENT_TABLE()
19:
20: // コンストラクタ
21: WXVectorMonitor::WXVectorMonitor(wxWindow *parent)
22: : inherited(parent, wxID_ANY, _("Vector Table"))
23: {
24: // →
25: // +------------+---------+
26: // | TextScreen | VScroll |
27: // +------------+---------+
28:
29: wxBoxSizer *topsizer = new wxBoxSizer(wxHORIZONTAL);
30:
31: // テキストスクリーン
32: screen = new WXTextScreen(this, gMonitorManager->Get(ID_SUBWIN_VECTOR));
33: topsizer->Add(screen, 1, wxEXPAND);
34:
35: // スクロールバー
36: vscroll = new WXScrollBar(this, wxID_ANY, wxSB_VERTICAL);
37: topsizer->Add(vscroll, 0, wxEXPAND);
38:
39: SetSizer(topsizer);
40:
41: // ウィンドウサイズを確定させる
42: DoSize();
43:
44: // スクロールのために (パネル領域での) MouseWheel イベントもここで
45: // 受け取りたい。スクロールバー上のマウスホイール操作はスクロールバーが
46: // 処理しているので問題ないが、パネル領域でのマウスホイール操作はここ
47: // (wxFrame)ではなくパネルに対して飛んでくる。
48: // ここで一緒に処理したほうが楽なので、こちらに回す。
49: screen->Connect(wxEVT_MOUSEWHEEL,
50: wxMouseEventHandler(WXVectorMonitor::OnMouseWheel), NULL, this);
51:
52: // スクロールバーからの位置変更通知
53: vscroll->Connect(NONO_EVT_SCROLL,
54: wxScrollEventHandler(WXVectorMonitor::OnScroll), NULL, this);
55: }
56:
57: // デストラクタ
58: WXVectorMonitor::~WXVectorMonitor()
59: {
60: }
61:
62: // サイズ変更イベント
63: void
64: WXVectorMonitor::OnSize(wxSizeEvent& event)
65: {
66: inherited::OnSize(event);
67:
68: // スクロールバーを再設定
69: int pos = (int)screen->GetUserData();
70: int thumbsize = screen->GetRow() - 1; // 常にヘッダ1行表示している
71: int range = gVectorTable->Size();
72: int pagesize = thumbsize - 1;
73: if (pos > range - thumbsize) {
74: pos = range - thumbsize;
75: }
76: vscroll->SetScrollParam(pos, thumbsize, range, pagesize);
77: }
78:
79: // マウスホイールイベント (WXTextScreen 上で起きたやつをこっちに回してある)
80: void
81: WXVectorMonitor::OnMouseWheel(wxMouseEvent& event)
82: {
83: // GetWheelRotation() は上(奥)向きに回すと +120、下(手前)に回すと -120。
84: // どこの決まりか知らんけど、スクロールバーのほうはホイール1段階で3行
85: // スクロールするのでそれに合わせる。
86: int pos = (int)screen->GetUserData();
87: pos = pos - event.GetWheelRotation() / 40;
88:
89: int maxpos = vscroll->GetRange() - vscroll->GetThumbSize();
90: if (pos < 0)
91: pos = 0;
92: if (pos > maxpos)
93: pos = maxpos;
94:
95: DoScroll(pos);
96: // スクロールバーの位置を追従
97: vscroll->SetThumbPosition(pos);
98: }
99:
100: // スクロールバーからの通知イベント
101: void
102: WXVectorMonitor::OnScroll(wxScrollEvent& event)
103: {
104: DoScroll(event.GetPosition());
105: }
106:
107: // スクロール処理 (OnScroll() と OnMouseWheel() から呼ばれる)
108: void
109: WXVectorMonitor::DoScroll(int pos)
110: {
111: // Vector モニタは userdata が表示開始位置になっている
112: screen->SetUserData(pos);
113: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.