--- nono/wx/wxsoftkey.h 2026/04/29 17:04:28 1.1 +++ nono/wx/wxsoftkey.h 2026/04/29 17:04:56 1.1.1.7 @@ -1,13 +1,16 @@ // // nono -// Copyright (C) 2019 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt // #pragma once +#include "wxbitmapbuf.h" #include "wxsubwindow.h" #include "wxtextpanel.h" #include "keyboard.h" +#include "vm.h" #include #include @@ -21,8 +24,15 @@ struct keydata_t int y; // このキー枠の左上点 int w; // このキー枠の幅 int h; // このキー枠の高さ - int coltype; // キートップの色(1:濃, 0:薄) + + // 色種別 + // LUNA の場合はキートップ色の区別に使う。1=濃い, 0=通常。 + // X68k では使用しない。 + int coltype; + + int led; // -1ならLEDなし、0以上なら LED 番号 uint keycode; // キーコード (keyboard.h の KC_*) + // 刻印 // [0]: 通常 // [1]: SHIFT時 (NULL なら通常のまま) @@ -32,76 +42,88 @@ struct keydata_t int bottom() const { return y + h; } // このキー枠の下 }; -class WXLunaSoftKeyPanel : public WXTextPanel +// ソフトウェアキーボード (パネル) 共通部分 +class WXSoftKeyPanel : public WXTextPanel { - typedef WXTextPanel inherited; + using inherited = WXTextPanel; + protected: + // 色の集合(パレット) + struct ColorPalette { + wxColour Background; // 背景というかガワの部分の色 + wxColour Text; // 文字色 + wxColour Keytop[2]; // キートップ色。0:通常色、1:(あれば)濃色 + wxColour KeyPressed; // キーが押された時のキートップ色 + wxColour Border; // LED 点灯時の枠の色 + wxColour LED[2]; // LED。色は各機種定義 (今のところ0:赤 1:緑) + }; + + // 修飾キーの状態 + enum Modifier { + ModNormal = 0, + ModShift, + }; + + protected: + WXSoftKeyPanel(wxWindow *parent, const std::vector& keydata_, + int u_width_, int u_height_); public: - WXLunaSoftKeyPanel(wxWindow *parent); - ~WXLunaSoftKeyPanel(); + virtual ~WXSoftKeyPanel() override; // フォントサイズ変更 - void SetFontSize(fontsize_t fontsize); + void SetFontSize(FontId fontid) override; - private: + protected: + void InitLED(); void DoSize(); - void OnSize(wxSizeEvent& event); void OnPaint(wxPaintEvent& event); + void OnTimer(wxTimerEvent& event); + void Draw(wxDC& dc); void DrawKey(wxDC& dc, const keydata_t& key); void DrawEnterKey(wxDC& dc); void DrawEnterMark(wxDC& dc, const wxPoint& basep); - const wxColour GetTopColor(const keydata_t& key) const; + virtual int DrawLED(wxDC& dc, const keydata_t& key) = 0; const keydata_t& FindKeydata(uint) const; void OnLeftDown(wxMouseEvent& event); - void DoLeftDown(uint code); + void DoLeftDown(const keydata_t *key); void OnLeftUp(wxMouseEvent& event); - void DoLeftUp(uint code); + void DoLeftUp(const keydata_t *key); void OnLeftDClick(wxMouseEvent& event); void OnRightDown(wxMouseEvent& event); - void KeyDown(uint code); - void KeyUp(uint code); - uint GetKeycodeFromPoint(const wxPoint& pt) const; - - // XXX どうするかね - bool black_keyboard = false; - - // LED キーなら true を返す - bool IsLEDKey(uint code) const { - return (code == KC_CAPS || code == KC_kana); - } - - // 押されていれば true (左クリック、右クリック区別なく両方)。 - // 共通キーコードによる配列。 - std::array hit {}; - - // 左クリック押下時の keycode - uint leftdown_keycode = 0; - - // LED - bool led_cap = false; - bool led_kana = false; + bool IsModifier(uint code) const; + void UpdateModifier(); + void KeyDown(const keydata_t& key); + void KeyUp(const keydata_t& key); + + const keydata_t *GetKeydataFromPoint(const wxPoint& pt) const; + + // 左クリック押下時のキー + const keydata_t *leftdown_key {}; // 修飾キーの状態 (刻印を変更するため) - enum { - ModNormal = 0, - ModShift, - } modifier {}; + Modifier modifier {}; + + // 前回の状態 + std::vector last_pressed {}; + Modifier last_modifier {}; // フォントサイズに相対的な描画単位 - int unit = 0; + int unit {}; - // コントロールのサイズ - int view_width = 0; - int view_height = 0; - - uint8 *bmpbuf = NULL; - wxImage *image = NULL; - wxBitmap *bitmap = NULL; + // コントロールのサイズ [基準単位] + int u_width {}; + int u_height {}; + + // コントロール全域のビットマップ + WXBitmapBuf bitmap {}; // エンター記号の周囲の点集合 - std::vector enter_points; - wxRegion enter_region; + std::vector enter_points {}; + wxRegion enter_region {}; + + // 色 + ColorPalette color {}; // UTF-8 -> CP932 変換 // Unicode の "\\" は Shift_JIS に対応する文字がないため、これを @@ -112,25 +134,55 @@ class WXLunaSoftKeyPanel : public WXText // こちらで決める。 wxCSConv conv { "CP932" }; + // キー描画データ (派生クラス側から渡される) + const std::vector& keydata; + + // タイマー + wxTimer timer {}; + // イベントテーブル wxDECLARE_EVENT_TABLE(); +}; + +// LUNA ソフトウェアキーボード (パネル) +class WXLunaSoftKeyPanel : public WXSoftKeyPanel +{ + using inherited = WXSoftKeyPanel; + public: + WXLunaSoftKeyPanel(wxWindow *parent); + virtual ~WXLunaSoftKeyPanel() override; + + private: + int DrawLED(wxDC& dc, const keydata_t& key) override; // キー描画データ static std::vector keydata; }; -// -// LUNA ソフトウェアキーボード (ウィンドウ) -// -class WXLunaSoftKeyWindow : public WXSubWindow +// X68k ソフトウェアキーボード (パネル) +class WXX68kSoftKeyPanel : public WXSoftKeyPanel +{ + using inherited = WXSoftKeyPanel; + public: + WXX68kSoftKeyPanel(wxWindow *parent); + virtual ~WXX68kSoftKeyPanel() override; + + private: + int DrawLED(wxDC& dc, const keydata_t& key) override; + + // キー描画データ + static std::vector keydata; +}; + +// ソフトウェアキーボード (ウィンドウ) +class WXSoftKeyWindow : public WXSubWindow { - typedef WXSubWindow inherited; + using inherited = WXSubWindow; public: - WXLunaSoftKeyWindow(wxWindow *parent, wxWindowID id); - virtual ~WXLunaSoftKeyWindow(); + WXSoftKeyWindow(wxWindow *parent, vmtype_t vmtype); + virtual ~WXSoftKeyWindow() override; - virtual void SetFontSize(fontsize_t fontsize); private: // キーボードパネル - WXLunaSoftKeyPanel *panel = NULL; + WXSoftKeyPanel *panel {}; };