|
|
1.1 root 1: //
2: // nono
1.1.1.4 root 3: // Copyright (C) 2020 nono project
4: // Licensed under nono-license.txt
1.1 root 5: //
6:
7: #include "wxsoftkey.h"
1.1.1.4 root 8: #include "wxcolor.h"
1.1.1.6 ! root 9: #include "wxmainview.h"
1.1 root 10: #include "wxtextscreen.h"
1.1.1.4 root 11: #include "sram.h"
1.1 root 12:
13: //
1.1.1.4 root 14: // ソフトウェアキーボード (パネル) 共通部分
1.1 root 15: //
16:
1.1.1.4 root 17: // エンター記号。
18: // 描画の際にキー刻印文字列の半角文字数から描画幅を決定しており、
19: // エンター記号は半角2文字幅で描いているので実際の文字列も2文字にしておく。
20: // そうすると "\\n" が意味的にもちょうどいい。
21: // これは幅を算出するのに使うだけで表示はされない。
22: #define EnterMark "\\n"
23:
1.1 root 24: // イベントテーブル
1.1.1.4 root 25: wxBEGIN_EVENT_TABLE(WXSoftKeyPanel, inherited)
26: EVT_LEFT_DOWN(WXSoftKeyPanel::OnLeftDown)
27: EVT_LEFT_UP(WXSoftKeyPanel::OnLeftUp)
28: EVT_LEFT_DCLICK(WXSoftKeyPanel::OnLeftDClick)
29: EVT_RIGHT_DOWN(WXSoftKeyPanel::OnRightDown)
30: EVT_PAINT(WXSoftKeyPanel::OnPaint)
31: EVT_SIZE(WXSoftKeyPanel::OnSize)
1.1.1.6 ! root 32: EVT_TIMER(wxID_ANY, WXSoftKeyPanel::OnTimer)
1.1 root 33: wxEND_EVENT_TABLE()
34:
35: // コンストラクタ
1.1.1.4 root 36: WXSoftKeyPanel::WXSoftKeyPanel(wxWindow *parent,
1.1.1.6 ! root 37: const std::vector<keydata_t>& keydata_, int u_width_, int u_height_)
1.1 root 38: : inherited(parent)
1.1.1.6 ! root 39: , keydata(keydata_)
1.1 root 40: {
1.1.1.4 root 41: u_width = u_width_;
42: u_height = u_height_;
1.1.1.6 ! root 43:
! 44: // 比較用のバッファ (初回更新させるため true で埋めておく)
! 45: const std::vector<bool>& pressed = gKeyboard->GetPressed();
! 46: last_pressed.resize(pressed.size());
! 47: std::fill(last_pressed.begin(), last_pressed.end(), true);
! 48: last_modifier = (Modifier)-1;
! 49:
! 50: // このパネルへのキー入力はメインビューへのキー入力と同じ。
! 51: Connect(wxEVT_KEY_UP, wxKeyEventHandler(WXMainView::OnKeyUp), NULL,
! 52: gMainView);
! 53: Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(WXMainView::OnKeyDown), NULL,
! 54: gMainView);
! 55:
! 56: // 更新間隔は適当
! 57: timer.SetOwner(this);
! 58: timer.Start(100);
1.1 root 59: }
60:
61: // デストラクタ
1.1.1.4 root 62: WXSoftKeyPanel::~WXSoftKeyPanel()
1.1 root 63: {
64: }
65:
66: // フォントサイズ変更 (外部インタフェース)
67: void
1.1.1.5 root 68: WXSoftKeyPanel::SetFontSize(FontId new_fontid)
1.1 root 69: {
70: // 同じなら何もしない
1.1.1.5 root 71: if (fontid == new_fontid) {
1.1 root 72: return;
73: }
74:
75: // フォントを更新
1.1.1.5 root 76: UpdateFont(new_fontid);
1.1 root 77:
78: // サイズ変更処理
79: DoSize();
80: }
81:
82: // サイズ変更処理
83: // サイズを変更したい時に呼ぶ (サイズが変更されたらではない)。
84: // ここではサイズは fontsize にのみ依存しているので、フォントサイズが
85: // 変化/確定した時に呼び出すこと。
86: void
1.1.1.4 root 87: WXSoftKeyPanel::DoSize()
1.1 root 88: {
1.1.1.5 root 89: assert(fontid != FontId::None);
1.1 root 90:
91: // このパネル内の描画の基本単位
92: unit = font_height / 4;
93:
94: // エンターキーだけ矩形でないのでここでリージョンを計算。
95: // unit が確定したところで一回行う。
1.1.1.6 ! root 96: // ただし SHIFT_R のキーコードはちょっと使いづらいので、ここでは SHIFT_R
! 97: // を使わず [_] キーで代用する。
! 98: //
! 99: // | ^ | \ | BS |
! 100: // | | | |
! 101: // --+---+---+--(A)--+------(B)
! 102: // | | |
! 103: // | [ | |
! 104: // | | Enter |
! 105: // --+---+---+--(F)-(E) |
! 106: // | | | |
! 107: // | : | ] | |
! 108: // | | | |
! 109: // --+---+---+------(D)-----(C)
! 110: // | |
! 111: // _ | SHIFT |
1.1 root 112: //
113: const keydata_t& keybs = FindKeydata(KC_BS);
114: const keydata_t& keyleft = FindKeydata(KC_bracketleft);
115: const keydata_t& keyright = FindKeydata(KC_bracketright);
1.1.1.6 ! root 116: const keydata_t& keyscore = FindKeydata(KC_underscore);
1.1 root 117: // 各点のピクセル座標
118: enter_points = {
119: { keyleft.right() * unit, keyleft.y * unit }, // A
120: { keybs.right() * unit, keyleft.y * unit }, // B
1.1.1.6 ! root 121: { keybs.right() * unit, keyscore.y * unit }, // C
! 122: { keyright.right() * unit, keyscore.y * unit }, // D
1.1 root 123: { keyright.right() * unit, keyright.y * unit }, // E
124: { keyleft.right() * unit, keyright.y * unit }, // F
125: };
126: // 当たり判定用のリージョン
127: enter_region = wxRegion(enter_points.size(), enter_points.data());
128:
129: // コントロールの大きさを変更
1.1.1.4 root 130: wxSize size(u_width * unit, u_height * unit);
1.1 root 131: SetClientSize(size);
1.1.1.6 ! root 132: SetMinClientSize(size);
1.1 root 133: }
134:
135: // サイズ変更イベント
136: void
1.1.1.4 root 137: WXSoftKeyPanel::OnSize(wxSizeEvent& event)
1.1 root 138: {
139: // Mac ではウィンドウ作成時に 0 以下の値が来ることがある
140: // GTK では 1 で来ることがある
1.1.1.5 root 141: const wxSize& size = event.GetSize();
1.1 root 142: if (size.x <= 1 || size.y <= 1) {
143: return;
144: }
145:
146: // ビットマップ作成
1.1.1.6 ! root 147: bitmap.Create(size.x, size.y);
1.1 root 148:
149: // 再描画を指示
150: Refresh();
151: }
152:
1.1.1.6 ! root 153: // タイマーイベント
! 154: void
! 155: WXSoftKeyPanel::OnTimer(wxTimerEvent& event)
! 156: {
! 157: // 更新があれば再描画を指示
! 158: const std::vector<bool>& pressed = gKeyboard->GetPressed();
! 159: UpdateModifier();
! 160: if (pressed != last_pressed || modifier != last_modifier) {
! 161: Refresh();
! 162: }
! 163: }
! 164:
1.1 root 165: // 描画イベント (UI スレッドから呼ばれる)
166: void
1.1.1.4 root 167: WXSoftKeyPanel::OnPaint(wxPaintEvent& event)
1.1 root 168: {
169: // メモリ DC に描画
170: wxMemoryDC memDC;
1.1.1.6 ! root 171: memDC.SelectObject(bitmap);
1.1 root 172: Draw(memDC);
173:
174: // 実画面 DC にコピー
175: wxPaintDC dstDC(this);
1.1.1.6 ! root 176: wxSize size = bitmap.GetSize();
! 177: dstDC.Blit(0, 0, size.x, size.y, &memDC, 0, 0);
1.1 root 178: }
179:
180: // 描画本体
181: void
1.1.1.4 root 182: WXSoftKeyPanel::Draw(wxDC& dc)
1.1 root 183: {
1.1.1.4 root 184: dc.SetPen(wxPen(color.Background));
185: dc.SetBrush(wxBrush(color.Background));
1.1 root 186: dc.DrawRectangle(wxPoint(0, 0), GetSize());
187:
1.1.1.4 root 188: dc.SetPen(color.Text);
189: SetTextForeColor(color.Text);
1.1.1.6 ! root 190: for (const auto& key : keydata) {
! 191: bool is_pressed = gKeyboard->IsPressed(key.keycode);
! 192: if (is_pressed) {
1.1 root 193: // 押されている
1.1.1.4 root 194: SetTextBackColor(color.KeyPressed);
195: dc.SetBrush(color.KeyPressed);
1.1 root 196: } else {
197: // 押されていない
1.1.1.4 root 198: SetTextBackColor(color.Keytop[key.coltype]);
199: dc.SetBrush(wxBrush(color.Keytop[key.coltype]));
1.1 root 200: }
201:
202: // エンターキーだけ枠の描き方が違うので別処理
203: if (__predict_false(key.x < 0)) {
204: DrawEnterKey(dc);
205: } else {
206: DrawKey(dc, key);
207: }
1.1.1.6 ! root 208:
! 209: // 次回更新チェック用に現状を保存
! 210: last_pressed[key.keycode] = is_pressed;
1.1 root 211: }
212:
1.1.1.6 ! root 213: // 次回更新チェック用に現状を保存
! 214: last_modifier = modifier;
! 215:
1.1.1.4 root 216: #if 0
217: // X68k キーボードだとどこに表示するか
218: SetTextBackColor(color.Background);
1.1.1.2 root 219: wxString utfstr(wxT("右クリックで長押し"));
1.1 root 220: const char *sjis = (const char *)utfstr.mb_str(conv);
221: DrawStringSJIS(dc, 190 * unit, 2 * unit, sjis, TA::Disable);
1.1.1.4 root 222: #endif
1.1 root 223: }
224:
225: // 指定のキーを一つ (枠から刻印まで) 描画する。
226: void
1.1.1.4 root 227: WXSoftKeyPanel::DrawKey(wxDC& dc, const keydata_t& key)
1.1 root 228: {
229: // 枠
230: wxPoint pt(key.x * unit, key.y * unit);
231: wxSize sz(key.w * unit + 1, key.h * unit + 1);
232: dc.DrawRectangle(pt, sz);
233:
234: // 刻印を選択
235: const char *disp = key.disp[modifier];
236: if (disp == NULL) {
237: disp = key.disp[0];
238: }
239:
240: // Shift_JIS に変換
241: wxString utfstr(disp, wxConvUTF8);
242: const char *sjis = (const char *)utfstr.mb_str(conv);
1.1.1.4 root 243: // 改行があれば2行に分割
244: char sjis1[8] {};
245: char sjis2[8] {};
246: int sjislen;
247: int row;
248: const char *lf = strchr(sjis, '\n');
249: if (lf == NULL) {
250: // 1行なら、Shift_JIS での文字数は半角換算の文字数と一致する。
251: sjislen = strlen(sjis);
252: row = 1;
253: } else {
254: // 2行に分割。センタリングは1行目の長さだけで調べる。
255: strncpy(sjis1, sjis, lf - sjis);
256: strcpy(sjis2, lf + 1);
257: sjislen = strlen(sjis1);
258: row = 2;
259: }
1.1 root 260:
261: // センタリング
262: int x = key.x + (key.w - sjislen * 2) / 2;
1.1.1.4 root 263: int y = key.y + (key.h - row * 4) / 2;
1.1 root 264:
1.1.1.4 root 265: // LED を描画 (機種によって色々違うので個別クラス側で処理)
266: if (key.led >= 0) {
1.1 root 267: const wxPen oldpen = dc.GetPen();
268: const wxBrush oldbrush = dc.GetBrush();
1.1.1.4 root 269:
270: y += DrawLED(dc, key);
271:
1.1 root 272: dc.SetPen(oldpen);
273: dc.SetBrush(oldbrush);
274: }
275:
276: // 文字を描画
277: pt = wxPoint(x * unit + 1, y * unit + 1);
1.1.1.4 root 278: if (strcmp(disp, EnterMark) == 0) {
1.1 root 279: DrawEnterMark(dc, pt);
280: } else {
1.1.1.4 root 281: if (lf == NULL) {
282: // 1行の場合
283: DrawStringSJIS(dc, pt.x, pt.y, sjis);
284: } else {
285: // 2行の場合
286: DrawStringSJIS(dc, pt.x, pt.y, sjis1);
287: pt.y += 4 * unit;
288: DrawStringSJIS(dc, pt.x, pt.y, sjis2);
289: }
1.1 root 290: }
291: }
292:
293: // エンターキー
294: void
1.1.1.4 root 295: WXSoftKeyPanel::DrawEnterKey(wxDC& dc)
1.1 root 296: {
297: // エンターキーを描画
298: dc.DrawPolygon(enter_points.size(), enter_points.data());
299:
300: // エンター記号を描画
301: DrawEnterMark(dc, wxPoint(
302: (enter_points[0].x + enter_points[1].x) / 2 - (4 / 2),
303: (enter_points[1].y + enter_points[2].y) / 2 - (4 / 2)));
304: }
305:
306: // 指定の位置にエンター記号を描画する (エンターキー全体の描画ではない)。
307: // メインキーとテンキーの両方で同じ図柄を使う。
308: // 大きさは (3unit, 4unit) なので実質全角1文字分くらい。
309: void
1.1.1.4 root 310: WXSoftKeyPanel::DrawEnterMark(wxDC& dc, const wxPoint& basep)
1.1 root 311: {
312: // エンター記号は幅 3 unit、高さ 4 unit。
313: // +0 +1 +2 +3
314: // +0 .. .. .. 1.
315: // .. .. .. 1.
316: // +1 .. .. .. 1.
317: // .. .. .. 1.
318: // +2 .. 1. .. 1.
319: // .1 .. .. 1.
320: // +3 11 11 11 1.
321: // .1 .. .. ..
322: // +4 .. 1. .. ..
323: // .. .. .. ..
324: static const std::vector<std::pair<int,int>> entermark {
325: { 3, 0 },
326: { 3, 3 }, // │
327: { 0, 3 }, // ─
328: { 1, 2 }, // /
329: { 0, 3 }, // (一筆書きなので戻る)
330: { 1, 4 }, // \
331: };
332: for (int i = 1; i < entermark.size(); i++) {
333: auto start = entermark[i - 1];
334: auto end = entermark[i];
335: wxPoint startp(start.first * unit, start.second * unit);
336: wxPoint endp(end.first * unit, end.second * unit);
337: dc.DrawLine(basep + startp, basep + endp);
338: }
339: }
340:
341: // keycode に対応する keydata を返す
342: const keydata_t&
1.1.1.4 root 343: WXSoftKeyPanel::FindKeydata(uint keycode) const
1.1 root 344: {
1.1.1.6 ! root 345: for (const auto& key : keydata) {
1.1 root 346: if (key.keycode == keycode) {
347: return key;
348: }
349: }
350: // 見付からないはずはない
1.1.1.3 root 351: assertmsg(0, "keycode %d not found", keycode);
1.1 root 352: }
353:
354: // マウス左クリック (Down) イベント
355: void
1.1.1.4 root 356: WXSoftKeyPanel::OnLeftDown(wxMouseEvent& event)
1.1 root 357: {
1.1.1.5 root 358: const wxPoint& pt = event.GetPosition();
1.1.1.4 root 359: const keydata_t *key = GetKeydataFromPoint(pt);
1.1 root 360:
1.1.1.4 root 361: DoLeftDown(key);
1.1 root 362: }
363:
364: // マウス左クリック (Down) 処理
365: void
1.1.1.4 root 366: WXSoftKeyPanel::DoLeftDown(const keydata_t *key)
1.1 root 367: {
1.1.1.4 root 368: if (key != NULL) {
1.1.1.6 ! root 369: // 押下
! 370: KeyDown(*key);
! 371: // LeftUp のために覚えておく
! 372: leftdown_key = key;
1.1 root 373: }
374: }
375:
376: // マウス左クリック (Up) イベント
377: void
1.1.1.4 root 378: WXSoftKeyPanel::OnLeftUp(wxMouseEvent& event)
1.1 root 379: {
380: // Up 時は、これが起きた地点のキーコードではなく
381: // 直近に LeftDown したキーコードをターゲットにする。
1.1.1.4 root 382: const keydata_t *key = leftdown_key;
1.1 root 383:
1.1.1.4 root 384: DoLeftUp(key);
1.1 root 385: }
386:
387: // マウス左クリック (Up) 処理
388: void
1.1.1.4 root 389: WXSoftKeyPanel::DoLeftUp(const keydata_t *key)
1.1 root 390: {
1.1.1.4 root 391: if (key != NULL) {
1.1.1.6 ! root 392: // 開放
! 393: KeyUp(*key);
1.1 root 394: }
1.1.1.4 root 395: leftdown_key = NULL;
1.1 root 396: }
397:
398: // マウス左ダブルクリックイベント
399: // ダブルクリックという操作に特別何かを割り当ててはいないが、
400: // キーを連打するとその間隔によってはダブルクリックと扱われるため、
401: // 受け取ってここで処理する。
402: //
403: // DClick イベントは LeftDown、LeftUp、LeftDClick、LeftUp の順で
404: // 飛んでくるので、ここでは2回目の押下だけ処理すればよい。というか
405: // 処理自体は LeftDown とまったく同じになるので、イベントテーブルで
406: // 直接 EVT_LEFT_DCLICK => OnLeftDown に割り付けることも出来そうだが
407: // デバッグが紛らわしくなりそうなので独立したイベントとしておく。
408: void
1.1.1.4 root 409: WXSoftKeyPanel::OnLeftDClick(wxMouseEvent& event)
1.1 root 410: {
1.1.1.5 root 411: const wxPoint& pt = event.GetPosition();
1.1.1.4 root 412: const keydata_t *key = GetKeydataFromPoint(pt);
1.1 root 413:
1.1.1.4 root 414: DoLeftDown(key);
1.1 root 415: }
416:
417: // マウス右クリック (Down) イベント
418: // 長押し開始/解除。
419: // 右クリックのほうは Down だけで Up は使わない。
420: void
1.1.1.4 root 421: WXSoftKeyPanel::OnRightDown(wxMouseEvent& event)
1.1 root 422: {
1.1.1.5 root 423: const wxPoint& pt = event.GetPosition();
1.1.1.4 root 424: const keydata_t *key = GetKeydataFromPoint(pt);
1.1 root 425:
1.1.1.4 root 426: if (key != NULL) {
427: uint code = key->keycode;
1.1.1.6 ! root 428: if (gKeyboard->IsPressed(code)) {
1.1 root 429: // 押されていたら開放
1.1.1.4 root 430: KeyUp(*key);
1.1 root 431: } else {
432: // 押されてなければ長押し開始
1.1.1.4 root 433: KeyDown(*key);
1.1 root 434: }
435: }
436: }
437:
1.1.1.4 root 438: // 座標からキーデータを返す。
439: // キーに当たっていなければ NULL を返す。
440: const keydata_t *
441: WXSoftKeyPanel::GetKeydataFromPoint(const wxPoint& pt) const
1.1 root 442: {
1.1.1.4 root 443: // エンターキーだけ先に別判定
444: if (enter_region.Contains(pt) == wxInRegion) {
445: return &FindKeydata(KC_enter);
446: }
1.1 root 447:
1.1.1.6 ! root 448: for (const auto& key : keydata) {
1.1.1.4 root 449: if (key.x < 0) {
450: continue;
1.1 root 451: }
1.1.1.4 root 452: // 始点と幅の +1/-1 は罫線の分
453: wxRect rect(
454: (key.x * unit) + 1,
455: (key.y * unit) + 1,
456: (key.w * unit) - 1,
457: (key.h * unit) - 1);
458: if (rect.Contains(pt)) {
459: return &key;
1.1 root 460: }
1.1.1.4 root 461: }
462: return NULL;
463: }
464:
1.1.1.6 ! root 465: // 修飾キーなら true を返す
! 466: // (今は SHIFT しかないから修飾キーならなのか SHIFT ならなのか曖昧)
! 467: bool
! 468: WXSoftKeyPanel::IsModifier(uint code) const
! 469: {
! 470: if (code == KC_SHIFT_L || code == KC_SHIFT_R || code == KC_SHIFT) {
! 471: return true;
! 472: } else {
! 473: return false;
! 474: }
! 475: }
! 476:
! 477: // 修飾キーの状態を更新。今は SHIFT かどうかしかない
! 478: void
! 479: WXSoftKeyPanel::UpdateModifier()
! 480: {
! 481: if (gKeyboard->IsShift()) {
! 482: modifier = ModShift;
! 483: } else {
! 484: modifier = ModNormal;
! 485: }
! 486: }
! 487:
! 488: // このキーが押された処理
! 489: void
! 490: WXSoftKeyPanel::KeyDown(const keydata_t& key)
! 491: {
! 492: uint code = key.keycode;
! 493:
! 494: // VM に通知 (Keyboard がそれをホストに通知するかはまた別)
! 495: gKeyboard->MakeKey(code);
! 496:
! 497: // 修飾キー
! 498: if (IsModifier(code)) {
! 499: UpdateModifier();
! 500: }
! 501:
! 502: // キー状態が変わった(かも知れない)ので再描画
! 503: // 押した時にはタイマーを待たずに再描画したほうがよかろう
! 504: Refresh();
! 505: }
! 506:
! 507: // このキーが放された処理
! 508: void
! 509: WXSoftKeyPanel::KeyUp(const keydata_t& key)
! 510: {
! 511: uint code = key.keycode;
! 512:
! 513: // VM に通知 (Keyboard がそれをホストに通知するかはまた別)
! 514: gKeyboard->BreakKey(code);
! 515:
! 516: // 修飾キー
! 517: if (IsModifier(code)) {
! 518: UpdateModifier();
! 519: }
! 520:
! 521: // キー状態が変わった(かも知れない)が、
! 522: // 解放時はタイマーに任せた再描画でよかろう
! 523: //Refresh();
! 524: }
! 525:
! 526:
1.1.1.4 root 527: //
528: // LUNA ソフトウェアキーボード (パネル)
529: //
530:
531: // コンストラクタ
532: WXLunaSoftKeyPanel::WXLunaSoftKeyPanel(wxWindow *parent)
1.1.1.6 ! root 533: : inherited(parent, keydata, 226, 54)
1.1.1.4 root 534: {
535: // LUNA では
536: // BS キーの左隣 (0x5c) は円記号ではなくバックスラッシュ。
537: // それを SHIFT したやつ(0x7c) は破線でないパイプ。
538: // そのもう一つ左隣 (0x7e) はオーバーラインではなくチルダ。
539: SetGlyph5C(true);
540: SetGlyph7E(true);
541:
542: // キートップの濃淡はユニバーサルデザインの推奨色ではないけど
543: // ここは見分けを付けるためではなくただのデザインなので。
544: if (1) {
545: // 白モデル
546: color = {
547: .Background = UD_LIGHT_GREY, // 現物新品は何色だったんだろう
548: .Text = *wxBLACK,
549: .Keytop = { *wxWHITE, wxColour(200, 200, 203) },
550: // 白黒共通
551: .KeyPressed = UD_BLUE,
552: .Border = *wxBLACK,
553: .LED = { UD_RED },
554: };
555: } else {
556: // 黒モデル
557: color = {
558: .Background = *wxBLACK,
559: .Text = *wxWHITE,
560: .Keytop = { wxColour(50, 50, 53), *wxBLACK },
561: // 白黒共通
562: .KeyPressed = UD_BLUE,
563: .Border = *wxBLACK,
564: .LED = { UD_RED },
565: };
566: }
567:
568: DoSize();
569: }
570:
571: // デストラクタ
572: WXLunaSoftKeyPanel::~WXLunaSoftKeyPanel()
573: {
574: }
575:
576: // LED を描画して刻印描画のための y offset を返す。
577: int
578: WXLunaSoftKeyPanel::DrawLED(wxDC& dc, const keydata_t& key)
579: {
580: const std::vector<bool>& led = gKeyboard->GetLED();
581:
582: if (led[key.led]) {
583: // 点灯時は赤、枠は黒
584: dc.SetPen(color.Border);
585: dc.SetBrush(color.LED[0]);
1.1 root 586: } else {
1.1.1.4 root 587: // 消灯時は元のキートップの色で、枠は薄めにしたい
1.1.1.6 ! root 588: // (枠の色は今の所全モデル共通なので ColorPalette に含めていない)
! 589: dc.SetPen(UD_GREY);
1.1.1.4 root 590: dc.SetBrush(color.Keytop[key.coltype]);
1.1 root 591: }
592:
1.1.1.4 root 593: // LED を左肩に描く
594: wxPoint pt = wxPoint(key.x * unit + 2, key.y * unit + 2);
595: wxSize sz = wxSize(4 * unit - 2, 3 * unit - 2);
596: dc.DrawRectangle(pt, sz);
597:
598: // そのため文字は少し下げる
599: return +1;
600: }
601:
1.1 root 602: // キーデータ
603: #define H (8) // キーの高さ
604: #define L0 (2) // ファンクションキーの行
605: #define L1 (12) // ESC の行
606: #define L2 (20) // TAB の行
607: #define L3 (28) // CTRL の行
608: #define L4 (36) // SHIFT の行
609: #define L5 (44) // space の行
610: /*static*/ std::vector<keydata_t>
611: WXLunaSoftKeyPanel::keydata {
1.1.1.4 root 612: // +---- キートップの色(1:濃)
613: // | +- 0 以上なら LED 番号
614: // X Y W H C L KeyCode 通常 SHIFT
615: { 2, L0, 15, H, 1,-1, KC_F1, { "PF1" } },
616: { 17, L0, 15, H, 1,-1, KC_F2, { "PF2" } },
617: { 32, L0, 15, H, 1,-1, KC_F3, { "PF3" } },
618: { 47, L0, 15, H, 1,-1, KC_F4, { "PF4" } },
619: { 62, L0, 15, H, 1,-1, KC_F5, { "PF5" } },
620: { 81, L0, 15, H, 1,-1, KC_F6, { "PF6" } },
621: { 96, L0, 15, H, 1,-1, KC_F7, { "PF7" } },
622: { 111, L0, 15, H, 1,-1, KC_F8, { "PF8" } },
623: { 126, L0, 15, H, 1,-1, KC_F9, { "PF9" } },
624: { 141, L0, 15, H, 1,-1, KC_F10, { "PF10" } },
625:
626: { 2, L1, 12, H, 1,-1, KC_ESC, { "ESC" } },
627: { 14, L1, 10, H, 0,-1, KC_1, { "1", "!" } },
628: { 24, L1, 10, H, 0,-1, KC_2, { "2", "\"" } },
629: { 34, L1, 10, H, 0,-1, KC_3, { "3", "#" } },
630: { 44, L1, 10, H, 0,-1, KC_4, { "4", "$" } },
631: { 54, L1, 10, H, 0,-1, KC_5, { "5", "%" } },
632: { 64, L1, 10, H, 0,-1, KC_6, { "6", "&" } },
633: { 74, L1, 10, H, 0,-1, KC_7, { "7", "'" } },
634: { 84, L1, 10, H, 0,-1, KC_8, { "8", "(" } },
635: { 94, L1, 10, H, 0,-1, KC_9, { "9", ")" } },
636: { 104, L1, 10, H, 0,-1, KC_0, { "0", " " } },
637: { 114, L1, 10, H, 0,-1, KC_minus, { "-", "=" } },
638: { 124, L1, 10, H, 0,-1, KC_circum, { "^", "~" } },
639: { 134, L1, 10, H, 0,-1, KC_backslash, { "\\", "|" } },
640: { 144, L1, 12, H, 1,-1, KC_BS, { "BS" } },
641:
642: { 2, L2, 17, H, 1,-1, KC_TAB, { "TAB" } },
643: { 19, L2, 10, H, 0,-1, KC_Q, { "q", "Q" } },
644: { 29, L2, 10, H, 0,-1, KC_W, { "w", "W" } },
645: { 39, L2, 10, H, 0,-1, KC_E, { "e", "E" } },
646: { 49, L2, 10, H, 0,-1, KC_R, { "r", "R" } },
647: { 59, L2, 10, H, 0,-1, KC_T, { "t", "T" } },
648: { 69, L2, 10, H, 0,-1, KC_Y, { "y", "Y" } },
649: { 79, L2, 10, H, 0,-1, KC_U, { "u", "U" } },
650: { 89, L2, 10, H, 0,-1, KC_I, { "i", "I" } },
651: { 99, L2, 10, H, 0,-1, KC_O, { "o", "O" } },
652: { 109, L2, 10, H, 0,-1, KC_P, { "p", "P" } },
653: { 119, L2, 10, H, 0,-1, KC_at, { "@", "`" } },
654: { 129, L2, 10, H, 0,-1, KC_bracketleft, { "[", "{" } },
655:
656: { 2, L3, 20, H, 1,-1, KC_CTRL, { "CTRL" } },
657: { 22, L3, 10, H, 0,-1, KC_A, { "a", "A" } },
658: { 32, L3, 10, H, 0,-1, KC_S, { "s", "S" } },
659: { 42, L3, 10, H, 0,-1, KC_D, { "d", "D" } },
660: { 52, L3, 10, H, 0,-1, KC_F, { "f", "F" } },
661: { 62, L3, 10, H, 0,-1, KC_G, { "g", "G" } },
662: { 72, L3, 10, H, 0,-1, KC_H, { "h", "H" } },
663: { 82, L3, 10, H, 0,-1, KC_J, { "j", "J" } },
664: { 92, L3, 10, H, 0,-1, KC_K, { "k", "K" } },
665: { 102, L3, 10, H, 0,-1, KC_L, { "l", "L" } },
666: { 112, L3, 10, H, 0,-1, KC_semicolon, { ";", "+" } },
667: { 122, L3, 10, H, 0,-1, KC_colon, { ":", "*" } },
668: { 132, L3, 10, H, 0,-1, KC_bracketright, { "]", "}" } },
669:
670: { 2, L4, 25, H, 1,-1, KC_SHIFT_L, { "SHIFT" } },
671: { 27, L4, 10, H, 0,-1, KC_Z, { "z", "Z" } },
672: { 37, L4, 10, H, 0,-1, KC_X, { "x", "X" } },
673: { 47, L4, 10, H, 0,-1, KC_C, { "c", "C" } },
674: { 57, L4, 10, H, 0,-1, KC_V, { "v", "V" } },
675: { 67, L4, 10, H, 0,-1, KC_B, { "b", "B" } },
676: { 77, L4, 10, H, 0,-1, KC_N, { "n", "N" } },
677: { 87, L4, 10, H, 0,-1, KC_M, { "m", "M" } },
678: { 97, L4, 10, H, 0,-1, KC_comma, { ",", "<" } },
679: { 107, L4, 10, H, 0,-1, KC_period, { ".", ">" } },
680: { 117, L4, 10, H, 0,-1, KC_slash, { "/", "?" } },
681: { 127, L4, 10, H, 0,-1, KC_underscore, { " ", "_" } },
682: { 137, L4, 19, H, 1,-1, KC_SHIFT_R, { "SHIFT" } },
683:
684: { 2, L5, 20, H, 1,-1, KC_VALID, { "確定" } },
685: { 22, L5, 10, H, 1,-1, KC_SF, { "前面" } },
686: { 32, L5, 10, H, 1, 1, KC_CAPS, { "CAP" } },
687: { 42, L5, 80, H, 0,-1, KC_space, { " " } },
688: { 122, L5, 10, H, 1, 0, KC_kana, { "かな" } },
689: { 132, L5, 24, H, 1,-1, KC_XFER, { "変換" } },
1.1 root 690:
691: // カーソルキー島
1.1.1.4 root 692: { 160, L1, 10, H, 1,-1, KC_PF11, { "消去" } },
693: { 170, L1, 10, H, 1,-1, KC_PF12, { "呼出" } },
694: { 160, L2, 10, H, 1,-1, KC_PF13, { "文節\n←" } },
695: { 170, L2, 10, H, 1,-1, KC_PF14, { "文節\n→" } },
696: { 160, L3, 20, H, 1,-1, KC_up, { "↑" } },
697: { 160, L4, 10, H, 1,-1, KC_left, { "←" } },
698: { 170, L4, 10, H, 1,-1, KC_right, { "→" } },
699: { 160, L5, 20, H, 1,-1, KC_down, { "↓" } },
1.1 root 700:
701: // テンキー島
1.1.1.4 root 702: { 184, L1, 10, H, 1,-1, KC_DEL, { "DEL" } },
703: { 194, L1, 10, H, 1,-1, KC_PAD_plus, { "+" } },
704: { 204, L1, 10, H, 1,-1, KC_PAD_minus, { "-" } },
705: { 214, L1, 10, H, 1,-1, KC_PAD_multiply, { "*" } },
706:
707: { 184, L2, 10, H, 0,-1, KC_PAD_7, { "7" } },
708: { 194, L2, 10, H, 0,-1, KC_PAD_8, { "8" } },
709: { 204, L2, 10, H, 0,-1, KC_PAD_9, { "9" } },
710: { 214, L2, 10, H, 1,-1, KC_PAD_divide, { "/" } },
711:
712: { 184, L3, 10, H, 0,-1, KC_PAD_4, { "4" } },
713: { 194, L3, 10, H, 0,-1, KC_PAD_5, { "5" } },
714: { 204, L3, 10, H, 0,-1, KC_PAD_6, { "6" } },
715: { 214, L3, 10, H, 1,-1, KC_PAD_equal, { "=" } },
716:
717: { 184, L4, 10, H, 0,-1, KC_PAD_1, { "1" } },
718: { 194, L4, 10, H, 0,-1, KC_PAD_2, { "2" } },
719: { 204, L4, 10, H, 0,-1, KC_PAD_3, { "3" } },
720: { 214, L4, 10, H, 1,-1, KC_PAD_comma, { "," } },
721:
722: { 184, L5, 10, H, 0,-1, KC_PAD_0, { "0" } },
723: { 194, L5, 10, H, 0,-1, KC_PAD_decimal, { "." } },
724: { 204, L5, 20, H, 1,-1, KC_PAD_enter, { EnterMark } },
1.1 root 725:
726: // Enter だけ矩形でないので別処理するが
727: // この構造体には全部のキー情報が統一的に並んでいるほうがよかろう。
1.1.1.4 root 728: { -1, -1, -1, -1, 1,-1, KC_enter, { EnterMark } },
1.1 root 729: };
730:
731:
732: //
1.1.1.4 root 733: // X68k ソフトウェアキーボード (パネル)
734: //
735:
736: // コンストラクタ
737: WXX68kSoftKeyPanel::WXX68kSoftKeyPanel(wxWindow *parent)
1.1.1.6 ! root 738: : inherited(parent, keydata, 235, 54)
1.1.1.4 root 739: {
740: // X68k では SRAM 設定に同期させる。
741: uint8 sw = gSRAM->Peek8(0xed0059);
742: SetGlyph5C((sw & 0x01));
743: SetGlyph7E((sw & 0x02));
744: SetGlyph7C((sw & 0x04));
745:
746: // とりあえず黒のみ
747: color = {
748: .Background = wxColour(50, 50, 53),
749: .Text = *wxWHITE,
750: .Keytop = { *wxBLACK },
751: .KeyPressed = UD_BLUE,
752: .Border = *wxBLACK,
753: .LED = { UD_RED, UD_YELLOW_GREEN },
754: };
755:
756: DoSize();
757: }
758:
759: // デストラクタ
760: WXX68kSoftKeyPanel::~WXX68kSoftKeyPanel()
761: {
762: }
763:
764: // LED を描画して刻印描画のための y offset を返す。
765: int
766: WXX68kSoftKeyPanel::DrawLED(wxDC& dc, const keydata_t& key)
767: {
768: const std::vector<bool>& led = gKeyboard->GetLED();
769:
770: // 色を選択
771: // idx 刻印 色
772: // ----------------
773: // 0 かな 赤
774: // 1 ローマ 赤
775: // 2 コード 赤
776: // 3 CAPS 赤
777: // 4 INS 赤
778: // 5 ひら 緑
779: // 6 全角 緑
780: if (led[key.led]) {
781: int n = (key.led < 5) ? 0 : 1;
782: dc.SetPen(color.LED[n]);
783: dc.SetBrush(color.LED[n]);
784: } else {
785: // 消灯時は元のキートップの色で、枠は薄めにしたい
1.1.1.6 ! root 786: // (枠の色は今の所全モデル共通なので ColorPalette に含めていない)
! 787: dc.SetPen(UD_GREY);
1.1.1.4 root 788: dc.SetBrush(color.Keytop[key.coltype]);
789: }
790:
791: // LED は中央前方(画面でいうと下)
792: wxPoint pt = wxPoint((key.x + 3) * unit, (key.y + key.h - 2) * unit);
793: wxSize sz = wxSize(4 * unit, 2 * unit);
794: dc.DrawRectangle(pt, sz);
795:
796: // そのため文字は少し上げる
797: return -1;
798: }
799:
800: #define LF (L0 + 2) // ファンクションキーは少し低い(横長い)
801: #define HT (H * 2) // 縦2倍角のキー
802: /*static*/ std::vector<keydata_t>
803: WXX68kSoftKeyPanel::keydata {
804: // +- 0以上なら LED 番号
805: // X Y W H C L KeyCode 通常 SHIFT
806: { 2, L0, 10, H, 0,-1, KC_BREAK, { "BRK" } },
807: { 15, L0, 10, H, 0,-1, KC_COPY, { "COPY" } },
808: { 29, LF, 12, 6, 0,-1, KC_F1, { "F1" } },
809: { 41, LF, 12, 6, 0,-1, KC_F2, { "F2" } },
810: { 53, LF, 12, 6, 0,-1, KC_F3, { "F3" } },
811: { 65, LF, 12, 6, 0,-1, KC_F4, { "F4" } },
812: { 77, LF, 13, 6, 0,-1, KC_F5, { "F5" } },
813: { 94, LF, 13, 6, 0,-1, KC_F6, { "F6" } },
814: { 106, LF, 12, 6, 0,-1, KC_F7, { "F7" } },
815: { 118, LF, 12, 6, 0,-1, KC_F8, { "F8" } },
816: { 130, LF, 12, 6, 0,-1, KC_F9, { "F9" } },
817: { 142, LF, 13, 6, 0,-1, KC_F10, { "F10" } },
818:
819: { 2, L1, 10, H, 0,-1, KC_ESC, { "ESC" } },
820: { 12, L1, 10, H, 0,-1, KC_1, { "1", "!" } },
821: { 22, L1, 10, H, 0,-1, KC_2, { "2", "\"" } },
822: { 32, L1, 10, H, 0,-1, KC_3, { "3", "#" } },
823: { 42, L1, 10, H, 0,-1, KC_4, { "4", "$" } },
824: { 52, L1, 10, H, 0,-1, KC_5, { "5", "%" } },
825: { 62, L1, 10, H, 0,-1, KC_6, { "6", "&" } },
826: { 72, L1, 10, H, 0,-1, KC_7, { "7", "'" } },
827: { 82, L1, 10, H, 0,-1, KC_8, { "8", "(" } },
828: { 92, L1, 10, H, 0,-1, KC_9, { "9", ")" } },
829: { 102, L1, 10, H, 0,-1, KC_0, { "0", " " } },
830: { 112, L1, 10, H, 0,-1, KC_minus, { "-", "=" } },
831: { 122, L1, 10, H, 0,-1, KC_circum, { "^", "~" } },
832: { 132, L1, 10, H, 0,-1, KC_backslash, { "\\", "|" } },
833: { 142, L1, 13, H, 0,-1, KC_BS, { "BS" } },
834:
835: { 2, L2, 16, H, 0,-1, KC_TAB, { "TAB" } },
836: { 18, L2, 10, H, 0,-1, KC_Q, { "q", "Q" } },
837: { 28, L2, 10, H, 0,-1, KC_W, { "w", "W" } },
838: { 38, L2, 10, H, 0,-1, KC_E, { "e", "E" } },
839: { 48, L2, 10, H, 0,-1, KC_R, { "r", "R" } },
840: { 58, L2, 10, H, 0,-1, KC_T, { "t", "T" } },
841: { 68, L2, 10, H, 0,-1, KC_Y, { "y", "Y" } },
842: { 78, L2, 10, H, 0,-1, KC_U, { "u", "U" } },
843: { 88, L2, 10, H, 0,-1, KC_I, { "i", "I" } },
844: { 98, L2, 10, H, 0,-1, KC_O, { "o", "O" } },
845: { 108, L2, 10, H, 0,-1, KC_P, { "p", "P" } },
846: { 118, L2, 10, H, 0,-1, KC_at, { "@", "`" } },
847: { 128, L2, 10, H, 0,-1, KC_bracketleft, { "[", "{" } },
848:
849: { 2, L3, 19, H, 0,-1, KC_CTRL, { "CTRL" } },
850: { 21, L3, 10, H, 0,-1, KC_A, { "a", "A" } },
851: { 31, L3, 10, H, 0,-1, KC_S, { "s", "S" } },
852: { 41, L3, 10, H, 0,-1, KC_D, { "d", "D" } },
853: { 51, L3, 10, H, 0,-1, KC_F, { "f", "F" } },
854: { 61, L3, 10, H, 0,-1, KC_G, { "g", "G" } },
855: { 71, L3, 10, H, 0,-1, KC_H, { "h", "H" } },
856: { 81, L3, 10, H, 0,-1, KC_J, { "j", "J" } },
857: { 91, L3, 10, H, 0,-1, KC_K, { "k", "K" } },
858: { 101, L3, 10, H, 0,-1, KC_L, { "l", "L" } },
859: { 111, L3, 10, H, 0,-1, KC_semicolon, { ";", "+" } },
860: { 121, L3, 10, H, 0,-1, KC_colon, { ":", "*" } },
861: { 131, L3, 10, H, 0,-1, KC_bracketright, { "]", "}" } },
862:
1.1.1.6 ! root 863: { 2, L4, 24, H, 0,-1, KC_SHIFT, { "SHIFT" } },
1.1.1.4 root 864: { 26, L4, 10, H, 0,-1, KC_Z, { "z", "Z" } },
865: { 36, L4, 10, H, 0,-1, KC_X, { "x", "X" } },
866: { 46, L4, 10, H, 0,-1, KC_C, { "c", "C" } },
867: { 56, L4, 10, H, 0,-1, KC_V, { "v", "V" } },
868: { 66, L4, 10, H, 0,-1, KC_B, { "b", "B" } },
869: { 76, L4, 10, H, 0,-1, KC_N, { "n", "N" } },
870: { 86, L4, 10, H, 0,-1, KC_M, { "m", "M" } },
871: { 96, L4, 10, H, 0,-1, KC_comma, { ",", "<" } },
872: { 106, L4, 10, H, 0,-1, KC_period, { ".", ">" } },
873: { 116, L4, 10, H, 0,-1, KC_slash, { "/", "?" } },
874: { 126, L4, 10, H, 0,-1, KC_underscore, { " ", "_" } },
1.1.1.6 ! root 875: { 136, L4, 19, H, 0,-1, KC_SHIFT, { "SHIFT" } },
1.1.1.4 root 876:
877: { 21, L5, 10, H, 0, 5, KC_hira, { "ひら" } },
878: { 31, L5, 12, H, 0,-1, KC_XF1, { "XF1" } },
879: { 43, L5, 13, H, 0,-1, KC_XF2, { "XF2" } },
880: { 56, L5, 36, H, 0,-1, KC_space, { " " } },
881: { 92, L5, 12, H, 0,-1, KC_XF3, { "XF3" } },
882: { 104, L5, 12, H, 0,-1, KC_XF4, { "XF4" } },
883: { 116, L5, 12, H, 0,-1, KC_XF5, { "XF5" } },
884: { 128, L5, 10, H, 0, 6, KC_zenkaku, { "全角" } },
885:
886: // カーソルキー島
887: { 159, L0, 10, H, 0, 0, KC_kana, { "かな" } },
888: { 169, L0, 10, H, 0, 1, KC_romaji, { "ローマ" } },
889: { 179, L0, 10, H, 0, 2, KC_code, { "コード" } },
890: { 159, L1, 10, H, 0,-1, KC_HOME, { "HOME" } },
891: { 169, L1, 10, H, 0, 4, KC_INS, { "INS" } },
892: { 179, L1, 10, H, 0,-1, KC_DEL, { "DEL" } },
893: { 159, L2, 10, H, 0,-1, KC_ROLLUP, { "ROLL\n UP" } },
894: { 169, L2, 10, H, 0,-1, KC_ROLLDOWN, { "ROLL\nDOWN" } },
895: { 179, L2, 10, H, 0,-1, KC_UNDO, { "UNDO" } },
896: { 169, L3, 10, H, 0,-1, KC_up, { "↑" } },
897: { 159, L3, 10, HT,0,-1, KC_left, { "←" } },
898: { 179, L3, 10, HT,0,-1, KC_right, { "→" } },
899: { 169, L4, 10, H, 0,-1, KC_down, { "↓" } },
900: { 159, L5, 15, H, 0,-1, KC_OPT1, { "OPT.1" } },
901: { 174, L5, 15, H, 0,-1, KC_OPT2, { "OPT.2" } },
902:
903: // テンキー島
904: { 193, L0, 10, H, 0, 3, KC_CAPS, { "CAPS" } },
905: { 203, L0, 10, H, 0,-1, KC_kigou, { "記号" } },
906: { 213, L0, 10, H, 0,-1, KC_touroku, { "登録" } },
907: { 223, L0, 10, H, 0,-1, KC_HELP, { "HELP" } },
908: { 193, L1, 10, H, 0,-1, KC_PAD_CLR, { "CLR" } },
909: { 203, L1, 10, H, 0,-1, KC_PAD_divide, { "/" } },
910: { 213, L1, 10, H, 0,-1, KC_PAD_multiply, { "*" } },
911: { 223, L1, 10, H, 0,-1, KC_PAD_minus, { "-" } },
912: { 193, L2, 10, H, 0,-1, KC_PAD_7, { "7" } },
913: { 203, L2, 10, H, 0,-1, KC_PAD_8, { "8" } },
914: { 213, L2, 10, H, 0,-1, KC_PAD_9, { "9" } },
915: { 223, L2, 10, H, 0,-1, KC_PAD_plus, { "+" } },
916: { 193, L3, 10, H, 0,-1, KC_PAD_4, { "4" } },
917: { 203, L3, 10, H, 0,-1, KC_PAD_5, { "5" } },
918: { 213, L3, 10, H, 0,-1, KC_PAD_6, { "6" } },
919: { 223, L3, 10, H, 0,-1, KC_PAD_equal, { "=" } },
920: { 193, L4, 10, H, 0,-1, KC_PAD_1, { "1" } },
921: { 203, L4, 10, H, 0,-1, KC_PAD_2, { "2" } },
922: { 213, L4, 10, H, 0,-1, KC_PAD_3, { "3" } },
923: { 223, L4, 10, HT,0,-1, KC_PAD_enter, { "ENT" } },
924: { 193, L5, 10, H, 0,-1, KC_PAD_0, { "0" } },
925: { 203, L5, 10, H, 0,-1, KC_PAD_comma, { "," } },
926: { 213, L5, 10, H, 0,-1, KC_PAD_decimal, { "." } },
927:
928: // Enter だけ矩形でないので別処理するが
929: // この構造体には全部のキー情報が統一的に並んでいるほうがよかろう。
930: { -1, -1, -1, -1, 0,-1, KC_enter, { EnterMark } },
931: };
932:
933: //
1.1.1.6 ! root 934: // ソフトウェアキーボード (ウィンドウ)
1.1.1.4 root 935: //
936:
937: // コンストラクタ
1.1.1.6 ! root 938: WXSoftKeyWindow::WXSoftKeyWindow(wxWindow *parent, wxWindowID id,
! 939: vmtype_t vmtype)
1.1.1.4 root 940: : inherited(parent, id, _("Software Keyboard"))
941: {
1.1.1.6 ! root 942: if (vmtype == VMTYPE_X68030) {
! 943: panel = new WXX68kSoftKeyPanel(this);
! 944: } else {
! 945: panel = new WXLunaSoftKeyPanel(this);
! 946: }
1.1.1.4 root 947:
948: // 大きさをそれに固定
949: Fit();
950: }
951:
952: // デストラクタ
1.1.1.6 ! root 953: WXSoftKeyWindow::~WXSoftKeyWindow()
1.1.1.4 root 954: {
955: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.