示例#1
0
 static function loop()
 {
     self::$instance->desktop->draw();
     while (true) {
         switch (ncurses_getch()) {
             case NCURSES_KEY_MOUSE:
                 if (ncurses_getmouse($mevent)) {
                     $mask = $mevent['mmask'];
                     // Get click position and do hittesting
                     $evtx = $mevent['x'];
                     $evty = $mevent['y'];
                     // Figure out what event we are dealing with
                     if ($mask & NCURSES_BUTTON1_CLICKED) {
                         $evtb = 1;
                         $evtn = 'onClick';
                     } elseif ($mask & NCURSES_BUTTON1_DOUBLE_CLICKED) {
                         $evtb = 1;
                         $evtn = 'onDoubleClick';
                     } elseif ($mask & NCURSES_BUTTON1_PRESSED) {
                         $evtb = 1;
                         $evtn = 'onOnMouseDown';
                     } elseif ($mask & NCURSES_BUTTON1_RELEASED) {
                         $evtb = 1;
                         $evtn = 'onMouseUp';
                     }
                     // Resolve modifiers
                     $evtm = 0;
                     // Call event handler for $evtn with x, y, button and mod
                     self::$handlers[0]->call($evtx, $evty, $evtb, $evtm);
                 }
                 break;
             case " ":
                 return;
             default:
                 /* .... */
         }
         usleep(10000);
     }
 }
示例#2
0
文件: Mouse.php 项目: ck99/kurses
 private function getMouseEvent()
 {
     ncurses_getmouse($mevent);
     return new MouseEvent($mevent);
 }
示例#3
0
 /**
  *
  */
 function refresh()
 {
     ncurses_refresh();
     // paint both windows
     foreach ((array) $this->children as $child) {
         $child->draw($this->workspace);
     }
     ncurses_move(-1, 1);
     $kp = ncurses_getch();
     // wait for a user keypress
     if ($kp == NCURSES_KEY_MOUSE) {
         if (!ncurses_getmouse($mevent)) {
             if ($mevent["mmask"] & NCURSES_MOUSE_BUTTON1_PRESSED) {
                 $mouse_x = $mevent["x"];
                 // Save mouse position
                 $mouse_y = $mevent["y"];
             }
         }
     }
     if (count($this->children) > 0) {
         // Pass it on to topmost window
         @$this->children[count($this->children) - 1]->keypress($kp);
     }
     return $kp;
 }
示例#4
0
文件: cwt.php 项目: noccy80/cherryphp
 function handleinput()
 {
     static $lastchars = array();
     do {
         $ch = ncurses_getch();
         if ($ch == NCURSES_KEY_MOUSE) {
             if (ncurses_getmouse($mevent)) {
                 $mx = $mevent["x"];
                 // Save mouse position
                 $my = $mevent["y"];
                 $ctl =& $this->desktop->hitTest($mx, $my);
                 $mtd = null;
                 if ($ctl) {
                     if ($mevent["mmask"] & NCURSES_BUTTON1_PRESSED) {
                         $mtd = 'onMouseDown';
                         $arg = array(1, $mx, $my);
                     } elseif ($mevent["mmask"] & NCURSES_BUTTON2_PRESSED) {
                         $mtd = 'onMouseDown';
                         $arg = array(2, $mx, $my);
                     } elseif ($mevent["mmask"] & NCURSES_BUTTON3_PRESSED) {
                         $mtd = 'onMouseDown';
                         $arg = array(3, $mx, $my);
                     } elseif ($mevent["mmask"] & NCURSES_BUTTON4_PRESSED) {
                         $mtd = 'onMouseDown';
                         $arg = array(4, $mx, $my);
                     } elseif ($mevent["mmask"] & NCURSES_BUTTON1_RELEASED) {
                         $mtd = 'onMouseUp';
                         $arg = array(1, $mx, $my);
                     } elseif ($mevent["mmask"] & NCURSES_BUTTON2_RELEASED) {
                         $mtd = 'onMouseUp';
                         $arg = array(2, $mx, $my);
                     } elseif ($mevent["mmask"] & NCURSES_BUTTON3_RELEASED) {
                         $mtd = 'onMouseUp';
                         $arg = array(3, $mx, $my);
                     } elseif ($mevent["mmask"] & NCURSES_BUTTON4_RELEASED) {
                         $mtd = 'onMouseUp';
                         $arg = array(4, $mx, $my);
                     } elseif ($mevent["mmask"] & NCURSES_BUTTON1_CLICKED) {
                         $mtd = 'onClick';
                         $arg = array(1, $mx, $my);
                     } elseif ($mevent["mmask"] & NCURSES_BUTTON2_CLICKED) {
                         $mtd = 'onClick';
                         $arg = array(2, $mx, $my);
                     } elseif ($mevent["mmask"] & NCURSES_BUTTON3_CLICKED) {
                         $mtd = 'onClick';
                         $arg = array(3, $mx, $my);
                     } elseif ($mevent["mmask"] & NCURSES_BUTTON4_CLICKED) {
                         $mtd = 'onClick';
                         $arg = array(4, $mx, $my);
                     }
                     if ($mtd && is_callable(array(&$ctl, $mtd))) {
                         call_user_func_array(array(&$ctl, $mtd), $arg);
                     }
                     //Cwt::cwt()->debug('Event at %3dx%3d. Hittest: %5s. Mtd:%-25s', $mx, $my, !empty($ctl)?'Yes':'No',$mtd);
                 }
             }
         }
         /*
         ncurses_mvaddstr(5,5,"Char: ".sprintf('%02x',$ch)."             ");
         if ($ch>=0) {
             array_unshift($lastchars, sprintf('%02x',$ch));
             ncurses_mvaddstr(6,5,"Last: ".join(', ',$lastchars)."             ");
             $lastchars = array_slice($lastchars,0,6);
         }
         */
     } while ($ch != -1);
     ncurses_refresh();
     if ($ch == ' ') {
         $this->quit();
     }
 }