Annotation of nono/wx/wxsoftkey.h, revision 1.1.1.16

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: 
1.1.1.11  root        7: //
                      8: // ソフトウェアキーボード
                      9: //
                     10: 
1.1       root       11: #pragma once
                     12: 
                     13: #include "wxsubwindow.h"
                     14: #include "wxtextpanel.h"
                     15: #include "keyboard.h"
1.1.1.12  root       16: #include "mainapp.h"
1.1       root       17: #include <array>
1.1.1.10  root       18: #include <map>
1.1       root       19: #include <vector>
                     20: 
1.1.1.13  root       21: class Keyboard;
                     22: 
1.1       root       23: // キー描画用のデータ構造体
                     24: struct keydata_t
                     25: {
                     26:        // フォントサイズの切り替えに対応するため、座標系の単位はピクセルでは
                     27:        // ない点に注意。フォントサイズ(高さ)の 1/4 を 1 と表現する。つまり
                     28:        // どのフォントサイズでも半角1文字は 2 x 4。
                     29:        int x;  // このキー枠の左上点
                     30:        int y;  // このキー枠の左上点
                     31:        int w;  // このキー枠の幅
                     32:        int h;  // このキー枠の高さ
1.1.1.2   root       33: 
                     34:        // 色種別
                     35:        // LUNA の場合はキートップ色の区別に使う。1=濃い, 0=通常。
                     36:        // X68k では使用しない。
                     37:        int coltype;
                     38: 
                     39:        int led;                        // -1ならLEDなし、0以上なら LED 番号
1.1       root       40:        uint keycode;           // キーコード (keyboard.h の KC_*)
1.1.1.2   root       41: 
1.1       root       42:        // 刻印
                     43:        // [0]: 通常
                     44:        // [1]: SHIFT時 (NULL なら通常のまま)
                     45:        const char *disp[2];
                     46: 
                     47:        int right() const { return x + w; }             // このキー枠の右
                     48:        int bottom() const { return y + h; }    // このキー枠の下
                     49: };
                     50: 
1.1.1.2   root       51: // ソフトウェアキーボード (パネル) 共通部分
                     52: class WXSoftKeyPanel : public WXTextPanel
1.1       root       53: {
1.1.1.2   root       54:        using inherited = WXTextPanel;
                     55:  protected:
                     56:        // 色の集合(パレット)
                     57:        struct ColorPalette {
1.1.1.11  root       58:                Color Background;               // 背景というかガワの部分の色
                     59:                Color Text;                             // 文字色
                     60:                Color Keytop[2][10];    // キートップ色。
                     61:                                                                // [2]=0:通常色、1:(あれば)濃色
                     62:                                                                // [10]=押され具合。0は押されていないとき
                     63:                Color Border;                   // LED 点灯時の枠の色
                     64:                Color LED[2];                   // LED。色は各機種定義 (今のところ0:赤 1:緑)
1.1.1.2   root       65:        };
                     66: 
1.1.1.6   root       67:        // 修飾キーの状態
                     68:        enum Modifier {
                     69:                ModNormal = 0,
                     70:                ModShift,
                     71:        };
                     72: 
                     73:  protected:
                     74:        WXSoftKeyPanel(wxWindow *parent, const std::vector<keydata_t>& keydata_,
                     75:                int u_width_, int u_height_);
1.1       root       76:  public:
1.1.1.14  root       77:        ~WXSoftKeyPanel() override;
1.1       root       78: 
                     79:        // フォントサイズ変更
1.1.1.11  root       80:        void FontChanged() override;
1.1       root       81: 
1.1.1.2   root       82:  protected:
1.1.1.11  root       83:        void UpdateTitle();
                     84: 
1.1.1.9   root       85:        void InitColorKeytop(int num);
1.1.1.13  root       86:        void InitIcon();
1.1.1.16! root       87: 
        !            88:        // LUNA-I、LUNA-88K の共通初期化
        !            89:        void InitLunaCommon();
        !            90: 
1.1.1.8   root       91:        void OnKeyChanged(wxCommandEvent& event);
1.1.1.9   root       92:        void OnTimer(wxTimerEvent& event);
1.1.1.2   root       93: 
1.1.1.11  root       94:        void Draw() override;
                     95:        void DrawKey(const keydata_t& key);
1.1.1.16! root       96:        void DrawKeyBox(const keydata_t&, Color bg, Color bd);
1.1.1.11  root       97:        void DrawEnterKey();
1.1.1.13  root       98:        void DrawBuzzer(const keydata_t& key);
1.1.1.11  root       99:        virtual int DrawLED(const keydata_t& key) = 0;
1.1       root      100:        const keydata_t& FindKeydata(uint) const;
                    101: 
                    102:        void OnLeftDown(wxMouseEvent& event);
1.1.1.10  root      103:        void DoLeftDown(uint code);
1.1       root      104:        void OnLeftUp(wxMouseEvent& event);
                    105:        void OnLeftDClick(wxMouseEvent& event);
                    106:        void OnRightDown(wxMouseEvent& event);
1.1.1.10  root      107:        void KeyDown(uint code);
                    108:        void KeyUp(uint code);
1.1.1.2   root      109: 
                    110:        const keydata_t *GetKeydataFromPoint(const wxPoint& pt) const;
1.1       root      111: 
1.1.1.2   root      112:        // 左クリック押下時のキー
1.1.1.10  root      113:        uint leftdown_key {};
1.1       root      114: 
1.1.1.10  root      115:        // トグル動作にするキーの集合。
                    116:        // first はキーコード、
                    117:        // second は押下ならキーコード、開放なら 0。
                    118:        std::map<uint, uint> toggle {};
1.1.1.9   root      119: 
1.1       root      120:        // 修飾キーの状態 (刻印を変更するため)
1.1.1.6   root      121:        Modifier modifier {};
                    122: 
1.1       root      123:        // フォントサイズに相対的な描画単位
1.1.1.4   root      124:        int unit {};
1.1       root      125: 
1.1.1.2   root      126:        // コントロールのサイズ [基準単位]
1.1.1.4   root      127:        int u_width {};
                    128:        int u_height {};
1.1.1.2   root      129: 
1.1.1.11  root      130:        // 初期タイトル
                    131:        wxString title {};
                    132: 
                    133:        // キーボードの接続状態
                    134:        bool connected {};
1.1       root      135: 
1.1.1.11  root      136:        // エンターキーの矩形
                    137:        Rect enter_top {};
                    138:        Rect enter_btm {};
1.1       root      139: 
1.1.1.13  root      140:        // アイコン
                    141:        std::unique_ptr<BitmapI1> enter_icon /*{}*/;
                    142: 
1.1.1.2   root      143:        // 色
                    144:        ColorPalette color {};
                    145: 
1.1.1.9   root      146:        // 残光処理
                    147:        // 10   : 減光しない点灯を示す (ただし色コードは 9)
                    148:        // 9..1 : 減光中 (9 がもっとも明るい)
                    149:        // 0    : 消灯中
                    150:        std::vector<uint8> persistence {};
                    151: 
                    152:        wxTimer timer {};
                    153: 
1.1       root      154:        // UTF-8 -> CP932 変換
                    155:        // Unicode の "\\" は Shift_JIS に対応する文字がないため、これを
                    156:        // Unicode から Shift_JIS に変換すると "" になり、これではキートップが
                    157:        // 刻印できなくて困る。
                    158:        // CP932 なら "\\" を変換しても "\\" ('\x5c') になってくれるので、
                    159:        // これを使う。この \x5c をバックスラッシュだと思うか円記号だと思うかは
                    160:        // こちらで決める。
                    161:        wxCSConv conv { "CP932" };
                    162: 
1.1.1.6   root      163:        // キー描画データ (派生クラス側から渡される)
                    164:        const std::vector<keydata_t>& keydata;
                    165: 
1.1.1.13  root      166:        Keyboard *keyboard {};
                    167: 
1.1       root      168:        // イベントテーブル
                    169:        wxDECLARE_EVENT_TABLE();
1.1.1.2   root      170: };
                    171: 
1.1.1.16! root      172: // LUNA-I ソフトウェアキーボード (パネル)
        !           173: class WXLuna1SoftKeyPanel : public WXSoftKeyPanel
        !           174: {
        !           175:        using inherited = WXSoftKeyPanel;
        !           176:  public:
        !           177:        explicit WXLuna1SoftKeyPanel(wxWindow *parent);
        !           178:        ~WXLuna1SoftKeyPanel() override;
        !           179: 
        !           180:  private:
        !           181:        int DrawLED(const keydata_t& key) override;
        !           182: 
        !           183:        // キー描画データ
        !           184:        static std::vector<keydata_t> keydata;
        !           185: };
        !           186: 
        !           187: // LUNA-88K ソフトウェアキーボード (パネル)
        !           188: class WXLuna88kSoftKeyPanel : public WXSoftKeyPanel
1.1.1.2   root      189: {
                    190:        using inherited = WXSoftKeyPanel;
                    191:  public:
1.1.1.16! root      192:        explicit WXLuna88kSoftKeyPanel(wxWindow *parent);
        !           193:        ~WXLuna88kSoftKeyPanel() override;
1.1.1.2   root      194: 
                    195:  private:
1.1.1.11  root      196:        int DrawLED(const keydata_t& key) override;
1.1       root      197: 
                    198:        // キー描画データ
1.1.1.2   root      199:        static std::vector<keydata_t> keydata;
                    200: };
                    201: 
                    202: // X68k ソフトウェアキーボード (パネル)
                    203: class WXX68kSoftKeyPanel : public WXSoftKeyPanel
                    204: {
                    205:        using inherited = WXSoftKeyPanel;
                    206:  public:
1.1.1.14  root      207:        explicit WXX68kSoftKeyPanel(wxWindow *parent);
                    208:        ~WXX68kSoftKeyPanel() override;
1.1.1.2   root      209: 
                    210:  private:
1.1.1.11  root      211:        int DrawLED(const keydata_t& key) override;
1.1.1.2   root      212: 
                    213:        // キー描画データ
1.1       root      214:        static std::vector<keydata_t> keydata;
                    215: };
                    216: 
1.1.1.6   root      217: // ソフトウェアキーボード (ウィンドウ)
                    218: class WXSoftKeyWindow : public WXSubWindow
1.1.1.2   root      219: {
                    220:        using inherited = WXSubWindow;
                    221:  public:
1.1.1.12  root      222:        WXSoftKeyWindow(wxWindow *parent, VMType vmtype);
1.1.1.14  root      223:        ~WXSoftKeyWindow() override;
1.1.1.2   root      224: };

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.