添付ファイルの情報



[添付ファイル一覧] [全ページの添付ファイル一覧]

filemousegesture.cpp
格納ファイル名:attach/446576656C6F702F34_6D6F757365676573747572652E637070
ページ:Develop/4
格納ファイル名:attach/446576656C6F702F34_6D6F757365676573747572652E637070
MD5ハッシュ値:6369028fa109d4b5cca3181cac045d7b
サイズ:4.8KB (4937 bytes)
Content-type:application/octet-stream
登録日時:2006/12/18 21:26:50
アクセス数:293
MD5ハッシュ値:6369028fa109d4b5cca3181cac045d7b
filemousegesture.cpp
  0
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
 
/* マウスジェスチャーサンプルソース */
/* 2006/12/13 watam */
 
 
//======================================================================
//定数
//======================================================================
 
#define MG_BUFFER_SIZE 16 /* マウスジェスチャー用のバッファサイズ */
#define MG_CMD_MAX     32 /* マウスジェスチャーコマンドの総数 */
#define MG_RANGE       32 /* ジェスチャー一回ごとの判定距離 */
 
#define MG_RIGHT        1 /* →に動いた */
#define MG_DOWN         2 /* ↓に動いた */
#define MG_LEFT         3 /* ←に動いた */
#define MG_UP           4 /* ↑に動いた */
 
//======================================================================
//構造体
//======================================================================
 
/* マウスジェスチャーコマンド設定用構造体 */
typedef struct{
 
    int   FuncCode;               /* 発行するコマンド */
    int   BufferLength;           /* ジェスチャー情報の長さ */
    short Buffer[MG_BUFFER_SIZE]; /* ジェスチャー情報 */
 
}MG_CMD;
 
//======================================================================
//変数
//======================================================================
POINT MG_pos;                    /* 開始座標 */
int   MG_IsGesture;              /* ジェスチャー記録中かどうか */
int   MG_BufferLength;           /* 記録中のジェスチャーの長さ */
short MG_Buffer[MG_BUFFER_SIZE]; /* 記録用バッファ */
MG_CMD MG_CMD_LIST[MG_CMD_MAX];  /* マウスジェスチャーコマンド割り当てリスト(共通設定辺りで設定) */
 
//======================================================================
//プロトタイプ宣言
//======================================================================
void MouseGesture_Start( int xPos, int yPos );
void MouseGesture_Execute( int xPos, int yPos );
bool MouseGesture_Finish();
int  MouseGesture_Check( MG_CMD *MG_Command );
bool MouseGesture_IsGesture();
 
//----------------------------------------------------------------------
//マウスジェスチャー開始
//----------------------------------------------------------------------
void MouseGesture_Start( int xPos, int yPos )
{
    
    MG_pos.x = xPos;
    MG_pos.y = yPos;
    MG_IsGesture = true;
    MG_BufferLength = 0;
    memset( MG_Buffer, 0, sizeof(short)*MG_BUFFER_SIZE );
    
}
//----------------------------------------------------------------------
//マウスジェスチャー記録中
//----------------------------------------------------------------------
void MouseGesture_Execute( int xPos, int yPos )
{
    
    int xlen = xPos - MG_pos.x;
    int ylen = yPos - MG_pos.y;
    
    int arrow = 0;
    
    if( xlen > MG_RANGE ){
        arrow = MG_RIGHT;
    }else
    if( ylen > MG_RANGE ){
        arrow = MG_DOWN;
    }else
    if( xlen < -MG_RANGE ){
        arrow = MG_LEFT;
    }else
    if( ylen < -MG_RANGE ){
        arrow = MG_UP;
    }
    
    if( arrow ){
        /* 座標を更新 */
        MG_pos.x = xPos;
        MG_pos.y = yPos;
        /* 直前の記録と同じ方向の場合は受け付けない */
        if( !(MG_BufferLength && MG_Buffer[ MG_BufferLength-1 ] == arrow) ){
            if( MG_BufferLength < MG_BUFFER_SIZE ){
                MG_Buffer[ MG_BufferLength++ ] = arrow;
 
                /* 現在の状態と該当するコマンドがあるかどうか */
                MG_CMD *MG_Command = NULL;
                MouseGesture_Check( MG_Command );
                
                /* MG_Bufferの中身を文字列でステータスバーに表示 */
                
                if( MG_Command ){
                    /* ジェスチャーに割り当てられているコマンドをステータスバーに表示 */
                    /* 「↓→:(閉じる)」、など */
                    
                }
 
            }
        }
    }
 
}
//----------------------------------------------------------------------
//マウスジェスチャー終了
//----------------------------------------------------------------------
bool MouseGesture_Finish()
{
    
    /* ジェスチャー中 */
    if( MG_IsGesture ){
        
        MG_IsGesture = false;
        
        /* ジェスチャーの結果に該当するものがあれば、コマンドを発行 */
        MG_CMD *MG_Command = NULL;
        if( MouseGesture_Check( MG_Command ) ){
            /* コマンドを発行した場合は、trueを返して右クリックメニューなどを抑制する */
            return true;
        }
        
    }
    
    return false;
    
}
//----------------------------------------------------------------------
//マウスジェスチャー記録中かどうか
//----------------------------------------------------------------------
bool MouseGesture_IsGesture()
{
    return MG_IsGesture;
}
//----------------------------------------------------------------------
//コマンド判定
//----------------------------------------------------------------------
int  MouseGesture_Check( MG_CMD *MG_Command )
{
    
    int i;
    int ret = false;
    
    for( i = 0; i < MG_CMD_MAX; i++ ){
        if( !MG_CMD_LIST[i].BufferLength ){
            break;
        }
        /* 長さの同じものだけを判定する */
        if( MG_BufferLength == MG_CMD_LIST[i].BufferLength ){
            if( !memcmp( MG_Buffer, MG_CMD_LIST[i].Buffer, sizeof(short)*MG_BufferLength ) ){
                if( MG_Command ){
                    /* 該当するコマンドを返す */
                    MG_Command = &MG_CMD_LIST[i];
                }
                ret = true;
                break;
            }
        }
    }
 
    return ret;
 
}




    


    ホーム 一覧 単語検索 最終更新 バックアップ リンク元   ヘルプ   最終更新のRSS