|
|
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: #pragma once
8:
1.1.1.7 root 9: #include "wxbitmapbuf.h"
1.1 root 10: #include "wxsubwindow.h"
11: #include "wxtextpanel.h"
12: #include "keyboard.h"
1.1.1.6 root 13: #include "vm.h"
1.1 root 14: #include <array>
15: #include <vector>
16:
17: // キー描画用のデータ構造体
18: struct keydata_t
19: {
20: // フォントサイズの切り替えに対応するため、座標系の単位はピクセルでは
21: // ない点に注意。フォントサイズ(高さ)の 1/4 を 1 と表現する。つまり
22: // どのフォントサイズでも半角1文字は 2 x 4。
23: int x; // このキー枠の左上点
24: int y; // このキー枠の左上点
25: int w; // このキー枠の幅
26: int h; // このキー枠の高さ
1.1.1.2 root 27:
28: // 色種別
29: // LUNA の場合はキートップ色の区別に使う。1=濃い, 0=通常。
30: // X68k では使用しない。
31: int coltype;
32:
33: int led; // -1ならLEDなし、0以上なら LED 番号
1.1 root 34: uint keycode; // キーコード (keyboard.h の KC_*)
1.1.1.2 root 35:
1.1 root 36: // 刻印
37: // [0]: 通常
38: // [1]: SHIFT時 (NULL なら通常のまま)
39: const char *disp[2];
40:
41: int right() const { return x + w; } // このキー枠の右
42: int bottom() const { return y + h; } // このキー枠の下
43: };
44:
1.1.1.2 root 45: // ソフトウェアキーボード (パネル) 共通部分
46: class WXSoftKeyPanel : public WXTextPanel
1.1 root 47: {
1.1.1.2 root 48: using inherited = WXTextPanel;
49: protected:
50: // 色の集合(パレット)
51: struct ColorPalette {
52: wxColour Background; // 背景というかガワの部分の色
53: wxColour Text; // 文字色
54: wxColour Keytop[2]; // キートップ色。0:通常色、1:(あれば)濃色
55: wxColour KeyPressed; // キーが押された時のキートップ色
1.1.1.6 root 56: wxColour Border; // LED 点灯時の枠の色
1.1.1.2 root 57: wxColour LED[2]; // LED。色は各機種定義 (今のところ0:赤 1:緑)
58: };
59:
1.1.1.6 root 60: // 修飾キーの状態
61: enum Modifier {
62: ModNormal = 0,
63: ModShift,
64: };
65:
66: protected:
67: WXSoftKeyPanel(wxWindow *parent, const std::vector<keydata_t>& keydata_,
68: int u_width_, int u_height_);
1.1 root 69: public:
1.1.1.3 root 70: virtual ~WXSoftKeyPanel() override;
1.1 root 71:
72: // フォントサイズ変更
1.1.1.3 root 73: void SetFontSize(FontId fontid) override;
1.1 root 74:
1.1.1.2 root 75: protected:
76: void InitLED();
1.1 root 77: void DoSize();
78: void OnPaint(wxPaintEvent& event);
1.1.1.8 ! root 79: void OnKeyChanged(wxCommandEvent& event);
1.1.1.2 root 80:
1.1 root 81: void Draw(wxDC& dc);
82: void DrawKey(wxDC& dc, const keydata_t& key);
83: void DrawEnterKey(wxDC& dc);
84: void DrawEnterMark(wxDC& dc, const wxPoint& basep);
1.1.1.2 root 85: virtual int DrawLED(wxDC& dc, const keydata_t& key) = 0;
1.1 root 86: const keydata_t& FindKeydata(uint) const;
87:
88: void OnLeftDown(wxMouseEvent& event);
1.1.1.2 root 89: void DoLeftDown(const keydata_t *key);
1.1 root 90: void OnLeftUp(wxMouseEvent& event);
1.1.1.2 root 91: void DoLeftUp(const keydata_t *key);
1.1 root 92: void OnLeftDClick(wxMouseEvent& event);
93: void OnRightDown(wxMouseEvent& event);
1.1.1.6 root 94: bool IsModifier(uint code) const;
95: void UpdateModifier();
96: void KeyDown(const keydata_t& key);
97: void KeyUp(const keydata_t& key);
1.1.1.2 root 98:
99: const keydata_t *GetKeydataFromPoint(const wxPoint& pt) const;
1.1 root 100:
1.1.1.2 root 101: // 左クリック押下時のキー
1.1.1.4 root 102: const keydata_t *leftdown_key {};
1.1 root 103:
104: // 修飾キーの状態 (刻印を変更するため)
1.1.1.6 root 105: Modifier modifier {};
106:
107: // 前回の状態
108: std::vector<bool> last_pressed {};
109: Modifier last_modifier {};
1.1 root 110:
111: // フォントサイズに相対的な描画単位
1.1.1.4 root 112: int unit {};
1.1 root 113:
1.1.1.2 root 114: // コントロールのサイズ [基準単位]
1.1.1.4 root 115: int u_width {};
116: int u_height {};
1.1.1.2 root 117:
1.1.1.6 root 118: // コントロール全域のビットマップ
1.1.1.7 root 119: WXBitmapBuf bitmap {};
1.1 root 120:
121: // エンター記号の周囲の点集合
1.1.1.4 root 122: std::vector<wxPoint> enter_points {};
123: wxRegion enter_region {};
1.1 root 124:
1.1.1.2 root 125: // 色
126: ColorPalette color {};
127:
1.1 root 128: // UTF-8 -> CP932 変換
129: // Unicode の "\\" は Shift_JIS に対応する文字がないため、これを
130: // Unicode から Shift_JIS に変換すると "" になり、これではキートップが
131: // 刻印できなくて困る。
132: // CP932 なら "\\" を変換しても "\\" ('\x5c') になってくれるので、
133: // これを使う。この \x5c をバックスラッシュだと思うか円記号だと思うかは
134: // こちらで決める。
135: wxCSConv conv { "CP932" };
136:
1.1.1.6 root 137: // キー描画データ (派生クラス側から渡される)
138: const std::vector<keydata_t>& keydata;
139:
1.1 root 140: // イベントテーブル
141: wxDECLARE_EVENT_TABLE();
1.1.1.2 root 142: };
143:
144: // LUNA ソフトウェアキーボード (パネル)
145: class WXLunaSoftKeyPanel : public WXSoftKeyPanel
146: {
147: using inherited = WXSoftKeyPanel;
148: public:
149: WXLunaSoftKeyPanel(wxWindow *parent);
1.1.1.5 root 150: virtual ~WXLunaSoftKeyPanel() override;
1.1.1.2 root 151:
152: private:
1.1.1.5 root 153: int DrawLED(wxDC& dc, const keydata_t& key) override;
1.1 root 154:
155: // キー描画データ
1.1.1.2 root 156: static std::vector<keydata_t> keydata;
157: };
158:
159: // X68k ソフトウェアキーボード (パネル)
160: class WXX68kSoftKeyPanel : public WXSoftKeyPanel
161: {
162: using inherited = WXSoftKeyPanel;
163: public:
164: WXX68kSoftKeyPanel(wxWindow *parent);
1.1.1.5 root 165: virtual ~WXX68kSoftKeyPanel() override;
1.1.1.2 root 166:
167: private:
1.1.1.5 root 168: int DrawLED(wxDC& dc, const keydata_t& key) override;
1.1.1.2 root 169:
170: // キー描画データ
1.1 root 171: static std::vector<keydata_t> keydata;
172: };
173:
1.1.1.6 root 174: // ソフトウェアキーボード (ウィンドウ)
175: class WXSoftKeyWindow : public WXSubWindow
1.1.1.2 root 176: {
177: using inherited = WXSubWindow;
178: public:
1.1.1.7 root 179: WXSoftKeyWindow(wxWindow *parent, vmtype_t vmtype);
1.1.1.6 root 180: virtual ~WXSoftKeyWindow() override;
1.1.1.2 root 181:
182: private:
183: // キーボードパネル
1.1.1.6 root 184: WXSoftKeyPanel *panel {};
1.1.1.2 root 185: };
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.