[Spiderape-cvs] SF.net SVN: spiderape: [48] plugins/ncurses
Status: Beta
Brought to you by:
sgbeal
|
From: <sg...@us...> - 2007-09-29 06:17:15
|
Revision: 48
http://spiderape.svn.sourceforge.net/spiderape/?rev=48&view=rev
Author: sgbeal
Date: 2007-09-28 23:17:12 -0700 (Fri, 28 Sep 2007)
Log Message:
-----------
added more mouse support. Needs new macros from this morning's SpiderApe commit.
Modified Paths:
--------------
plugins/ncurses/SpiderApe-Plugin-ncurses.odt
plugins/ncurses/ncwrapper.cpp
plugins/ncurses/ncwrapper.hpp
plugins/ncurses/scripts/mouse.js
Modified: plugins/ncurses/SpiderApe-Plugin-ncurses.odt
===================================================================
(Binary files differ)
Modified: plugins/ncurses/ncwrapper.cpp
===================================================================
--- plugins/ncurses/ncwrapper.cpp 2007-09-28 14:39:50 UTC (rev 47)
+++ plugins/ncurses/ncwrapper.cpp 2007-09-29 06:17:12 UTC (rev 48)
@@ -66,14 +66,12 @@
// ASSERTNC asserts that stdscr is available.
#define ASSERTNC(FUNCNAME,CX) if( ! stdscr ) { \
- JS_ReportError(CX,"Function %s() requires that curses mode be running (try nc_initscr()).", FUNCNAME); \
- return JS_FALSE; \
+ return ape::set_pending_exception(CX,"Function %s() requires that curses mode be running (try nc_initscr()).", FUNCNAME); \
}
// ASSERTARGC asserts that the argv array meets some basic condition. It also calls ASSERTNC(FUNCNAME,CX).
#define ASSERTARGC(FUNCNAME,CX,ARGC_EXPR) if(!(ARGC_EXPR)) { \
- JS_ReportError( CX,"%s() argument check failed: %s",FUNCNAME,# ARGC_EXPR ); \
- return JS_FALSE; \
+ return ape::set_pending_exception( CX,"%s() argument check failed: %s",SPIDERAPE_CURRENT_FUNCTION,# ARGC_EXPR ); \
} \
ASSERTNC(FUNCNAME,CX)
@@ -466,6 +464,11 @@
<< "this['BUTTON4_DOUBLE_CLICKED']="<<NCURSES_MOUSE_MASK(4,NCURSES_DOUBLE_CLICKED)<<";"
<< "this['BUTTON4_TRIPLE_CLICKED']="<<NCURSES_MOUSE_MASK(4,NCURSES_TRIPLE_CLICKED)<<";"
+ << "this['BUTTON_CTRL']="<<BUTTON_CTRL<<';'
+ << "this['BUTTON_SHIFT']="<<BUTTON_SHIFT<<';'
+ << "this['BUTTON_ALT']="<<BUTTON_ALT<<';'
+ << "this['REPORT_MOUSE_POSITION']="<<REPORT_MOUSE_POSITION<<';'
+ << "this['ALL_MOUSE_EVENTS']="<<ALL_MOUSE_EVENTS<<';'
;
#endif
@@ -541,6 +544,8 @@
{"nc_keyok", nc_keyok, 0},
{"nc_keypad", nc_keypad, 0},
{"nc_meta", nc_meta, 0},
+ {"nc_mouseinterval",nc_mouseinterval,0},
+ {"nc_mousemask",nc_mousemask,0},
{"nc_move_panel", nc_move_panel, 0},
{"nc_movewin", nc_movewin, 0 },
{"nc_mvwaddch", nc_mvwaddch, 0},
@@ -615,6 +620,7 @@
{"nc_wdelch", nc_wdelch, 0},
{"nc_wdeleteln", nc_wdeleteln, 0},
{"nc_wechochar", nc_wechochar, 0},
+ {"nc_wenclose",nc_wenclose,0},
{"nc_werase", nc_werase, 0},
{"nc_wgeometry", nc_wgeometry, 0},
{"nc_wgetch", nc_wgetch, 0},
@@ -773,9 +779,9 @@
::keypad( stdscr, true );
::meta( stdscr, true );
::noecho();
-#if NCURSES_MOUSE_VERSION
- mousemask( ALL_MOUSE_EVENTS, NULL );
-#endif // NCURSES_MOUSE_VERSION
+// #if NCURSES_MOUSE_VERSION
+// mousemask( ALL_MOUSE_EVENTS, NULL );
+// #endif // NCURSES_MOUSE_VERSION
if( ! create_ncurses_objects(cx,globobj) )
{
@@ -2128,6 +2134,48 @@
return JS_TRUE;
}
+ JS_FUNC(nc_wenclose)
+ {
+ ASSERTARGC("nc_wenclose",cx,(3==argc));
+ *rval = bool_to_jsval( cx, ::ape::fwd_to_func3<bool,WINDOW const *,int,int>( wenclose, cx, obj, argc, argv ) );
+ return JS_TRUE;
+ }
+
+ JS_FUNC(nc_mouseinterval)
+ {
+ ASSERTARGC("nc_mouseinterval",cx,(1==argc));
+#if ! NCURSES_MOUSE_VERSION
+ *rval = JSVAL_NULL;
+#else
+ *rval = int_to_jsval( cx, ::ape::fwd_to_func1<int,int>( mouseinterval, cx, obj, argc, argv ) );
+#endif
+ return JS_TRUE;
+ }
+
+ JS_FUNC(nc_mousemask)
+ {
+ ASSERTARGC("nc_mousemask",cx,((0==argc) || (1==argc)));
+#if ! NCURSES_MOUSE_VERSION
+ *rval = JSVAL_NULL;
+#else
+ mmask_t mret;
+ if( 0 == argc )
+ {
+ // A weird workaround for the lack of a real getter:
+ mousemask( ALL_MOUSE_EVENTS, &mret );
+ mousemask( mret, NULL );
+ }
+ else
+ {
+ mmask_t arg = jsval_to_long( cx, argv[0] );
+ mret = mousemask( arg, NULL );
+ }
+ *rval = long_to_jsval( cx, mret );
+#endif
+ return JS_TRUE;
+ }
+
+
JS_FUNC(nc_getmouse)
{
#if ! NCURSES_MOUSE_VERSION
@@ -2142,14 +2190,24 @@
quasi.set( "z", int_to_jsval(evt.z) );
quasi.set( "id", int_to_jsval(evt.id) );
quasi.set( "bstate", int_to_jsval(evt.bstate) );
- //scriptable scr( cx, quasi.js_object() );
- //scr.eval( "print('scr=',this.toSource())");
*rval = quasi.js_value();
#endif // NCURSES_MOUSE_VERSION
return JS_TRUE;
+ }
+
+ JS_FUNC(nc_ungetmouse)
+ {
+#if ! NCURSES_MOUSE_VERSION
+ *rval = JSVAL_NULL;
+#else
+ return ape::set_pending_exception(cx,"nc_ungetmouse() not yet implemented.");
+#endif // NCURSES_MOUSE_VERSION
+ return JS_TRUE;
+
}
+
} } // namespace ape::nc
#undef ASSERTARGC
Modified: plugins/ncurses/ncwrapper.hpp
===================================================================
--- plugins/ncurses/ncwrapper.hpp 2007-09-28 14:39:50 UTC (rev 47)
+++ plugins/ncurses/ncwrapper.hpp 2007-09-29 06:17:12 UTC (rev 48)
@@ -624,8 +624,33 @@
*/
NC_WRAPPER_FUNC(getmouse);
+ /** Not yet implemented. */
+ NC_WRAPPER_FUNC(ungetmouse);
+ NC_WRAPPER_FUNC(wenclose);
+ NC_WRAPPER_FUNC(mouseinterval);
/**
+ Similar, but not identical, to the native function.
+
+ If passed no arguments then it acts like a getter, fetching
+ the current mousemask value. If passed 1 argument it is
+ used as a mouse mask and the mask which gets actually
+ implemented is returned (which may be different than the
+ requested mask).
+
+ JS Usage:
+
+ var mask = nc_mousemask(); // getter
+
+ var actualmask = nc_mousemask( ... requested mask ... ); // setter
+
+
+ */
+ NC_WRAPPER_FUNC(mousemask);
+
+
+
+ /**
This non-standard curses function returns the
geometry of it's first argument, which must be
a WINDOW.
Modified: plugins/ncurses/scripts/mouse.js
===================================================================
--- plugins/ncurses/scripts/mouse.js 2007-09-28 14:39:50 UTC (rev 47)
+++ plugins/ncurses/scripts/mouse.js 2007-09-29 06:17:12 UTC (rev 48)
@@ -1,35 +1,34 @@
assert(open_dll('../ncurses.so'));
nc_initscr();
+nc_capture_cout(stdscr);
+var mask = ncurses.BUTTON1_PRESSED | ncurses.BUTTON1_RELEASED;
+print( "requesting mousemask(",format_token('%08x',mask),") ==",
+ format_token('%08x',nc_mousemask(mask)) );
+print("actual mousemask() ==",format_token('%08x',nc_mousemask()) );;
nc_scrollok(stdscr,true);
nc_noecho();
-var sub = nc_subwin(stdscr,3,4,5,6);
-nc_wbkgd( sub, ncurses["-"] | nc_color("white","red"));
-nc_capture_cout(stdscr);
-nc_wmove(stdscr,12,0);
-print("nc_getparyx(sub) ==",nc_getparyx(sub).toSource());
-print("nc_getparyx(sub).y ==",nc_getparyx(sub).y);
-print("nc_getpary(sub) ==",nc_getpary(sub));
-print("nc_getparx(sub) ==",nc_getparx(sub));
-if( 0 ) {
- for( var i = 0; i < 4; ++i ) {
- print("nc_curs_set("+i+") ==",nc_curs_set(i));
- nc_getch();
- }
-}
-if( 1 ) {
- print( "mouse ?? ==",ncurses.MOUSE_VERSION );
+// This subwin is only to demonstrate nc_wenclose()
+var subwin = nc_subwin(stdscr,5,15,0,nc_screen_width()/2);
+nc_wbkgd( subwin, nc_color('white','red') | ncurses.A_BOLD );
+nc_waddstr(subwin, "Click here.");
+nc_wrefresh(subwin);
+nc_wmove(stdscr,10,0);
+
+
+if( ncurses.MOUSE_VERSION ) {
print("Play with the mouse. Tap 'q' to quit.");
var key = 0;
while( ascii('q') != (key = nc_wgetch(stdscr)) ) {
if( key == ncurses.KEY_MOUSE ) {
var evt = nc_getmouse();
print( "mouse :",key,evt.toSource() );
+ if( nc_wenclose(subwin,evt.y,evt.x) ) {
+ print("Event hit the subwindow.");
+ }
}
}
}
-print("Tap any key to exit.");
-nc_wgetch(stdscr);
nc_endwin();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|