a working example with mouse, 3 windows (need to be completed, but it works) ...
<?php
error_reporting(E_ALL);
function win($w, $h, $x, $y, $txt){
// now lets create a small window
$win = ncurses_newwin($w, $h, $x, $y);
// border our small window.
ncurses_wborder($win,0,0, 0,0, 0,0, 0,0);
# ncurses_wrefresh($win);// paint both windows
ncurses_refresh();// paint both windows
// move into the small window and write a string
ncurses_mvwaddstr($win, 0, 1, " $txt ");
ncurses_mvwaddstr($win, 1, 1, "($w, $h, $x, $y)");
// show our handiwork and refresh our small window
ncurses_wrefresh($win);
return $win;
}
// Initialie ncurses
$ncurse = ncurses_init();
// A full screen window
$win0 = win(0, 0, 0, 0, 'win0');
$win1 = win(10, 30, 7, 25, 'win1');
$win2 = win(10, 30, 20, 25, 'win2');
$info = win(15, 20, 2, 2, 'info');
// Draw everything so far
// ncurses_refresh();
$newmask = NCURSES_BUTTON1_CLICKED + NCURSES_BUTTON1_RELEASED;
# $newmask = NCURSES_ALL_MOUSE_EVENTS;
$mask = ncurses_mousemask($newmask, &$oldmask);
$events = array();
while(1){
ncurses_wmove($info, 1,1);
$ch = ncurses_getch();
ncurses_wclear($info);
ncurses_refresh();// paint both windows
ncurses_wborder($info,0,0, 0,0, 0,0, 0,0);
ncurses_refresh();// paint both windows
ncurses_mvwaddstr($win, 0, 1, " info ");
ncurses_refresh();// paint both windows
switch($ch){
case NCURSES_KEY_MOUSE:
if(ncurses_getmouse($mevent)){
$events[] = $mevent;
ncurses_mvwaddstr($info, 2, 1, " mouse event ");
ncurses_mvwaddstr($info, 3, 1, " ({$mevent['x']}/{$mevent['y']}) ");
ncurses_mvwaddstr($info, 4, 1, " ({$mevent['mmask']}) ");
ncurses_wrefresh($info);
}
break;
case chr('q'):
break 2;
default:
if($ch > 0x40)
$txt = chr($ch) . " $ch ";
else
$txt = '.' . " $ch";
ncurses_mvwaddstr($info, 1, 1, " $txt ");
ncurses_wrefresh($info);
}
if(chr($ch) == 'q')
break;
}
ncurses_end();// clean up our screen
print_r($events);
?>
ncurses_getmouse
(PHP 4 >= 4.2.0, PHP 5 < 5.3.0, PECL ncurses >= 1.0.0)
ncurses_getmouse — マウスイベントを読みこむ
説明
bool ncurses_getmouse
( array
&$mevent
)警告
この関数は、 実験的 なものです。この関数の動作・ 名前・その他ドキュメントに書かれている事項は、予告なく、将来的な PHP のリリースにおいて変更される可能性があります。 この関数は自己責任で使用してください。
ncurses_getmouse() は、 キューからマウスイベントを読み込みます。
パラメータ
-
mevent -
イベントのオプションを指定します。 これは配列への参照として渡されます(以下の例を参照ください)。
成功した場合、以下のキーを持つ連想配列が返されます。
-
"id" : 複数デバイスを識別する ID。
-
"x" : 画面上の相対的な x 位置(文字単位)。
-
"y" : 画面上の相対的な y 位置(文字単位)。
-
"z" : 現在はサポートされていません。
-
"mmask" : マウスアクション。
-
返り値
指定したウィンドウでマウスイベントが実際に見える場合に
FALSE、そうでない場合に TRUE を返します。
例
例1 ncurses_getmouse() の例
<?php
switch (ncurses_getch()){
case NCURSES_KEY_MOUSE:
if (!ncurses_getmouse($mevent)){
if ($mevent["mmask"] & NCURSES_MOUSE_BUTTON1_PRESSED){
$mouse_x = $mevent["x"]; // マウスの位置を保存します
$mouse_y = $mevent["y"];
}
}
break;
default:
/* .... */
}
?>
m dot quinton at gmail dot com
26-Sep-2005 04:05
