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

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.6 ! root        9: #include "wxbmp.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 OnSize(wxSizeEvent& event);
                     79:        void OnPaint(wxPaintEvent& event);
1.1.1.6 ! root       80:        void OnTimer(wxTimerEvent& event);
1.1.1.2   root       81: 
1.1       root       82:        void Draw(wxDC& dc);
                     83:        void DrawKey(wxDC& dc, const keydata_t& key);
                     84:        void DrawEnterKey(wxDC& dc);
                     85:        void DrawEnterMark(wxDC& dc, const wxPoint& basep);
1.1.1.2   root       86:        virtual int DrawLED(wxDC& dc, const keydata_t& key) = 0;
1.1       root       87:        const keydata_t& FindKeydata(uint) const;
                     88: 
                     89:        void OnLeftDown(wxMouseEvent& event);
1.1.1.2   root       90:        void DoLeftDown(const keydata_t *key);
1.1       root       91:        void OnLeftUp(wxMouseEvent& event);
1.1.1.2   root       92:        void DoLeftUp(const keydata_t *key);
1.1       root       93:        void OnLeftDClick(wxMouseEvent& event);
                     94:        void OnRightDown(wxMouseEvent& event);
1.1.1.6 ! root       95:        bool IsModifier(uint code) const;
        !            96:        void UpdateModifier();
        !            97:        void KeyDown(const keydata_t& key);
        !            98:        void KeyUp(const keydata_t& key);
1.1.1.2   root       99: 
                    100:        const keydata_t *GetKeydataFromPoint(const wxPoint& pt) const;
1.1       root      101: 
1.1.1.2   root      102:        // 左クリック押下時のキー
1.1.1.4   root      103:        const keydata_t *leftdown_key {};
1.1       root      104: 
                    105:        // 修飾キーの状態 (刻印を変更するため)
1.1.1.6 ! root      106:        Modifier modifier {};
        !           107: 
        !           108:        // 前回の状態
        !           109:        std::vector<bool> last_pressed {};
        !           110:        Modifier last_modifier {};
1.1       root      111: 
                    112:        // フォントサイズに相対的な描画単位
1.1.1.4   root      113:        int unit {};
1.1       root      114: 
1.1.1.2   root      115:        // コントロールのサイズ [基準単位]
1.1.1.4   root      116:        int u_width {};
                    117:        int u_height {};
1.1.1.2   root      118: 
1.1.1.6 ! root      119:        // コントロール全域のビットマップ
        !           120:        WXBitmap bitmap {};
1.1       root      121: 
                    122:        // エンター記号の周囲の点集合
1.1.1.4   root      123:        std::vector<wxPoint> enter_points {};
                    124:        wxRegion enter_region {};
1.1       root      125: 
1.1.1.2   root      126:        // 色
                    127:        ColorPalette color {};
                    128: 
1.1       root      129:        // UTF-8 -> CP932 変換
                    130:        // Unicode の "\\" は Shift_JIS に対応する文字がないため、これを
                    131:        // Unicode から Shift_JIS に変換すると "" になり、これではキートップが
                    132:        // 刻印できなくて困る。
                    133:        // CP932 なら "\\" を変換しても "\\" ('\x5c') になってくれるので、
                    134:        // これを使う。この \x5c をバックスラッシュだと思うか円記号だと思うかは
                    135:        // こちらで決める。
                    136:        wxCSConv conv { "CP932" };
                    137: 
1.1.1.6 ! root      138:        // キー描画データ (派生クラス側から渡される)
        !           139:        const std::vector<keydata_t>& keydata;
        !           140: 
        !           141:        // タイマー
        !           142:        wxTimer timer {};
1.1.1.2   root      143: 
1.1       root      144:        // イベントテーブル
                    145:        wxDECLARE_EVENT_TABLE();
1.1.1.2   root      146: };
                    147: 
                    148: // LUNA ソフトウェアキーボード (パネル)
                    149: class WXLunaSoftKeyPanel : public WXSoftKeyPanel
                    150: {
                    151:        using inherited = WXSoftKeyPanel;
                    152:  public:
                    153:        WXLunaSoftKeyPanel(wxWindow *parent);
1.1.1.5   root      154:        virtual ~WXLunaSoftKeyPanel() override;
1.1.1.2   root      155: 
                    156:  private:
1.1.1.5   root      157:        int DrawLED(wxDC& dc, const keydata_t& key) override;
1.1       root      158: 
                    159:        // キー描画データ
1.1.1.2   root      160:        static std::vector<keydata_t> keydata;
                    161: };
                    162: 
                    163: // X68k ソフトウェアキーボード (パネル)
                    164: class WXX68kSoftKeyPanel : public WXSoftKeyPanel
                    165: {
                    166:        using inherited = WXSoftKeyPanel;
                    167:  public:
                    168:        WXX68kSoftKeyPanel(wxWindow *parent);
1.1.1.5   root      169:        virtual ~WXX68kSoftKeyPanel() override;
1.1.1.2   root      170: 
                    171:  private:
1.1.1.5   root      172:        int DrawLED(wxDC& dc, const keydata_t& key) override;
1.1.1.2   root      173: 
                    174:        // キー描画データ
1.1       root      175:        static std::vector<keydata_t> keydata;
                    176: };
                    177: 
1.1.1.6 ! root      178: // ソフトウェアキーボード (ウィンドウ)
        !           179: class WXSoftKeyWindow : public WXSubWindow
1.1.1.2   root      180: {
                    181:        using inherited = WXSubWindow;
                    182:  public:
1.1.1.6 ! root      183:        WXSoftKeyWindow(wxWindow *parent, wxWindowID id, vmtype_t vmtype);
        !           184:        virtual ~WXSoftKeyWindow() override;
1.1.1.2   root      185: 
                    186:  private:
                    187:        // キーボードパネル
1.1.1.6 ! root      188:        WXSoftKeyPanel *panel {};
1.1.1.2   root      189: };

unix.superglobalmegacorp.com

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