|
|
1.1 root 1: //
2: // nono
3: // Copyright (C) 2019 [email protected]
4: //
5:
6: #pragma once
7:
8: #include "wxsubwindow.h"
9: #include "wxtextpanel.h"
10: #include "keyboard.h"
11: #include <array>
12: #include <vector>
13:
14: // キー描画用のデータ構造体
15: struct keydata_t
16: {
17: // フォントサイズの切り替えに対応するため、座標系の単位はピクセルでは
18: // ない点に注意。フォントサイズ(高さ)の 1/4 を 1 と表現する。つまり
19: // どのフォントサイズでも半角1文字は 2 x 4。
20: int x; // このキー枠の左上点
21: int y; // このキー枠の左上点
22: int w; // このキー枠の幅
23: int h; // このキー枠の高さ
24: int coltype; // キートップの色(1:濃, 0:薄)
25: uint keycode; // キーコード (keyboard.h の KC_*)
26: // 刻印
27: // [0]: 通常
28: // [1]: SHIFT時 (NULL なら通常のまま)
29: const char *disp[2];
30:
31: int right() const { return x + w; } // このキー枠の右
32: int bottom() const { return y + h; } // このキー枠の下
33: };
34:
35: class WXLunaSoftKeyPanel : public WXTextPanel
36: {
37: typedef WXTextPanel inherited;
38: public:
39: WXLunaSoftKeyPanel(wxWindow *parent);
40: ~WXLunaSoftKeyPanel();
41:
42: // フォントサイズ変更
43: void SetFontSize(fontsize_t fontsize);
44:
45: private:
46: void DoSize();
47: void OnSize(wxSizeEvent& event);
48: void OnPaint(wxPaintEvent& event);
49: void Draw(wxDC& dc);
50: void DrawKey(wxDC& dc, const keydata_t& key);
51: void DrawEnterKey(wxDC& dc);
52: void DrawEnterMark(wxDC& dc, const wxPoint& basep);
53: const wxColour GetTopColor(const keydata_t& key) const;
54: const keydata_t& FindKeydata(uint) const;
55:
56: void OnLeftDown(wxMouseEvent& event);
57: void DoLeftDown(uint code);
58: void OnLeftUp(wxMouseEvent& event);
59: void DoLeftUp(uint code);
60: void OnLeftDClick(wxMouseEvent& event);
61: void OnRightDown(wxMouseEvent& event);
62: void KeyDown(uint code);
63: void KeyUp(uint code);
64: uint GetKeycodeFromPoint(const wxPoint& pt) const;
65:
66: // XXX どうするかね
67: bool black_keyboard = false;
68:
69: // LED キーなら true を返す
70: bool IsLEDKey(uint code) const {
71: return (code == KC_CAPS || code == KC_kana);
72: }
73:
74: // 押されていれば true (左クリック、右クリック区別なく両方)。
75: // 共通キーコードによる配列。
76: std::array<bool, KC_max> hit {};
77:
78: // 左クリック押下時の keycode
79: uint leftdown_keycode = 0;
80:
81: // LED
82: bool led_cap = false;
83: bool led_kana = false;
84:
85: // 修飾キーの状態 (刻印を変更するため)
86: enum {
87: ModNormal = 0,
88: ModShift,
89: } modifier {};
90:
91: // フォントサイズに相対的な描画単位
92: int unit = 0;
93:
94: // コントロールのサイズ
95: int view_width = 0;
96: int view_height = 0;
97:
98: uint8 *bmpbuf = NULL;
99: wxImage *image = NULL;
100: wxBitmap *bitmap = NULL;
101:
102: // エンター記号の周囲の点集合
103: std::vector<wxPoint> enter_points;
104: wxRegion enter_region;
105:
106: // UTF-8 -> CP932 変換
107: // Unicode の "\\" は Shift_JIS に対応する文字がないため、これを
108: // Unicode から Shift_JIS に変換すると "" になり、これではキートップが
109: // 刻印できなくて困る。
110: // CP932 なら "\\" を変換しても "\\" ('\x5c') になってくれるので、
111: // これを使う。この \x5c をバックスラッシュだと思うか円記号だと思うかは
112: // こちらで決める。
113: wxCSConv conv { "CP932" };
114:
115: // イベントテーブル
116: wxDECLARE_EVENT_TABLE();
117:
118: // キー描画データ
119: static std::vector<keydata_t> keydata;
120: };
121:
122: //
123: // LUNA ソフトウェアキーボード (ウィンドウ)
124: //
125: class WXLunaSoftKeyWindow : public WXSubWindow
126: {
127: typedef WXSubWindow inherited;
128: public:
129: WXLunaSoftKeyWindow(wxWindow *parent, wxWindowID id);
130: virtual ~WXLunaSoftKeyWindow();
131:
132: virtual void SetFontSize(fontsize_t fontsize);
133: private:
134: // キーボードパネル
135: WXLunaSoftKeyPanel *panel = NULL;
136: };
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.