From 42051194d8b93c9a5b05c99ee249b1badb09fecf Mon Sep 17 00:00:00 2001 From: hut Date: Wed, 15 Jul 2009 12:55:15 +0200 Subject: mouse support in cli.rb --- code/cli.rb | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) diff --git a/code/cli.rb b/code/cli.rb index 3ef38237..ba315603 100644 --- a/code/cli.rb +++ b/code/cli.rb @@ -1,6 +1,9 @@ require 'ncurses' module CLI + @@mev = nil + extend self + def self.keytable(key) case key when 12 @@ -27,11 +30,24 @@ module CLI "" when 32..127 key.chr + when Ncurses::KEY_MOUSE + fetch_mouse_data + '' else - '' + key +# '' end end + def fetch_mouse_data + @@mev = MouseEvent.new + Ncurses::getmouse(@@mev) + end + + def mouse + @@mev + end + def self.included(this) @@window = Ncurses.initscr starti @@ -51,6 +67,14 @@ module CLI @@colortable = [] end + def init_mouse + Ncurses.mousemask(Ncurses::ALL_MOUSE_EVENTS | Ncurses::REPORT_MOUSE_POSITION, []) + end + + def stop_mouse + Ncurses.mousemask(0, []) + end + def self.refresh Ncurses.refresh end @@ -133,4 +157,61 @@ module CLI end return color end + + class MouseEvent # {{{ + attr_accessor :id, :x,:y,:z, :bstate + def press1?() 0 != @bstate & Ncurses::BUTTON1_PRESSED end + def press2?() 0 != @bstate & Ncurses::BUTTON2_PRESSED end + def press3?() 0 != @bstate & Ncurses::BUTTON3_PRESSED end + def press4?() 0 != @bstate & Ncurses::BUTTON4_PRESSED end + def press5?() 0 != @bstate & Ncurses::BUTTON5_PRESSED end + def press6?() 0 != @bstate & Ncurses::BUTTON6_PRESSED end + def press7?() 0 != @bstate & Ncurses::BUTTON7_PRESSED end + def press8?() 0 != @bstate & Ncurses::BUTTON8_PRESSED end + def press9?() 0 != @bstate & Ncurses::BUTTON9_PRESSED end + + def release1?() 0 != @bstate & Ncurses::BUTTON1_RELEASED end + def release2?() 0 != @bstate & Ncurses::BUTTON2_RELEASED end + def release3?() 0 != @bstate & Ncurses::BUTTON3_RELEASED end + def release4?() 0 != @bstate & Ncurses::BUTTON4_RELEASED end + def release5?() 0 != @bstate & Ncurses::BUTTON5_RELEASED end + def release6?() 0 != @bstate & Ncurses::BUTTON6_RELEASED end + def release7?() 0 != @bstate & Ncurses::BUTTON7_RELEASED end + def release8?() 0 != @bstate & Ncurses::BUTTON8_RELEASED end + def release9?() 0 != @bstate & Ncurses::BUTTON9_RELEASED end + + def click1?() 0 != @bstate & Ncurses::BUTTON1_CLICKED end + def click2?() 0 != @bstate & Ncurses::BUTTON2_CLICKED end + def click3?() 0 != @bstate & Ncurses::BUTTON3_CLICKED end + def click4?() 0 != @bstate & Ncurses::BUTTON4_CLICKED end + def click5?() 0 != @bstate & Ncurses::BUTTON5_CLICKED end + def click6?() 0 != @bstate & Ncurses::BUTTON6_CLICKED end + def click7?() 0 != @bstate & Ncurses::BUTTON7_CLICKED end + def click8?() 0 != @bstate & Ncurses::BUTTON8_CLICKED end + def click9?() 0 != @bstate & Ncurses::BUTTON9_CLICKED end + + def doubleclick1?() 0 != @bstate & Ncurses::BUTTON1_DOUBLE_CLICKED end + def doubleclick2?() 0 != @bstate & Ncurses::BUTTON2_DOUBLE_CLICKED end + def doubleclick3?() 0 != @bstate & Ncurses::BUTTON3_DOUBLE_CLICKED end + def doubleclick4?() 0 != @bstate & Ncurses::BUTTON4_DOUBLE_CLICKED end + def doubleclick5?() 0 != @bstate & Ncurses::BUTTON5_DOUBLE_CLICKED end + def doubleclick6?() 0 != @bstate & Ncurses::BUTTON6_DOUBLE_CLICKED end + def doubleclick7?() 0 != @bstate & Ncurses::BUTTON7_DOUBLE_CLICKED end + def doubleclick8?() 0 != @bstate & Ncurses::BUTTON8_DOUBLE_CLICKED end + def doubleclick9?() 0 != @bstate & Ncurses::BUTTON9_DOUBLE_CLICKED end + + def tripleclick1?() 0 != @bstate & Ncurses::BUTTON1_TRIPLE_CLICKED end + def tripleclick2?() 0 != @bstate & Ncurses::BUTTON2_TRIPLE_CLICKED end + def tripleclick3?() 0 != @bstate & Ncurses::BUTTON3_TRIPLE_CLICKED end + def tripleclick4?() 0 != @bstate & Ncurses::BUTTON4_TRIPLE_CLICKED end + def tripleclick5?() 0 != @bstate & Ncurses::BUTTON5_TRIPLE_CLICKED end + def tripleclick6?() 0 != @bstate & Ncurses::BUTTON6_TRIPLE_CLICKED end + def tripleclick7?() 0 != @bstate & Ncurses::BUTTON7_TRIPLE_CLICKED end + def tripleclick8?() 0 != @bstate & Ncurses::BUTTON8_TRIPLE_CLICKED end + def tripleclick9?() 0 != @bstate & Ncurses::BUTTON9_TRIPLE_CLICKED end + + def alt?() 0 != @bstate & Ncurses::BUTTON_ALT end + def shift?() 0 != @bstate & Ncurses::BUTTON_SHIFT end + def ctrl?() 0 != @bstate & Ncurses::BUTTON_CTRL end + end # }}} end -- cgit 1.4.1-2-gfad0