]> gitweb.factorcode.org Git - factor.git/commitdiff
curses: simplification, implement coordinate queries
authorPhilipp Brüschweiler <blei42@gmail.com>
Thu, 25 Feb 2010 21:02:47 +0000 (22:02 +0100)
committerPhilipp Brüschweiler <blei42@gmail.com>
Sun, 3 Oct 2010 11:17:43 +0000 (13:17 +0200)
extra/curses/curses.factor

index 7d3e4401d5e30d9e24be40e2c6edf673d5dd4f82..b269d34697f82fb1ac7a470be56ca05d169ba57a 100644 (file)
@@ -317,18 +317,24 @@ PRIVATE>
 : wcrefresh ( window -- ) ptr>> (wcrefresh) ;
 : crefresh ( -- ) current-window get wcrefresh ;
 
-: wcnl ( window -- ) [ "\n" ] dip ptr>> (wcwrite) ;
+: wgetch ( window -- key ) ptr>> (wgetch) ;
+: getch ( -- key ) current-window get wgetch ;
+
+: waddch ( ch window -- ) ptr>> (waddch) ;
+: addch ( ch -- ) current-window get waddch ;
+
+: wcnl ( window -- ) [ CHAR: \n ] dip waddch ;
 : cnl ( -- ) current-window get wcnl ;
 
 : wcwrite ( string window -- ) ptr>> (wcwrite) ;
 : cwrite ( string -- ) current-window get wcwrite ;
 
 : wcprint ( string window -- )
-    ptr>> [ (wcwrite) ] [ "\n" swap (wcwrite) ] bi ;
+    ptr>> [ (wcwrite) ] [ CHAR: \n swap (waddch) ] bi ;
 : cprint ( string -- ) current-window get wcprint ;
 
 : wcprintf ( string window -- )
-    ptr>> [ (wcwrite) ] [ "\n" swap (wcwrite) ]
+    ptr>> [ (wcwrite) ] [ CHAR: \n swap (waddch) ]
     [ (wcrefresh) ] tri ;
 : cprintf ( string -- ) current-window get wcprintf ;
 
@@ -340,12 +346,6 @@ PRIVATE>
     [ encoding>> ] [ ptr>> ] bi (wcread) ;
 : cread ( n -- string ) current-window get wcread ;
 
-: wgetch ( window -- key ) ptr>> (wgetch) ;
-: getch ( -- key ) current-window get wgetch ;
-
-: waddch ( ch window -- ) ptr>> (waddch) ;
-: addch ( ch -- ) current-window get waddch ;
-
 : werase ( window -- ) ptr>> ffi:werase curses-error ;
 : erase ( -- ) current-window get werase ;
 
@@ -449,3 +449,32 @@ PRIVATE>
 
 : mousemask ( mask -- newmask oldmask )
     0 <ulong> [ ffi:mousemask ] keep *ulong ;
+
+: wget-yx ( window -- y x )
+    ptr>> ffi:c-window memory>struct [ _cury>> ] [ _curx>> ] bi ;
+: get-yx ( -- y x )
+    current-window get wget-yx ;
+
+: wget-y ( window -- y )
+    ptr>> ffi:c-window memory>struct _cury>> ;
+: get-y ( -- y )
+    current-window get wget-y ;
+: wget-x ( window -- x )
+    ptr>> ffi:c-window memory>struct _curx>> ;
+: get-x ( -- x )
+    current-window get wget-x ;
+
+: wget-max-yx ( window -- y x )
+    ptr>> ffi:c-window memory>struct
+    [ _maxy>> 1 + ] [ _maxx>> 1 + ] bi ;
+: get-max-yx ( -- y x )
+    current-window get wget-max-yx ;
+
+: wget-max-y ( window -- y )
+    ptr>> ffi:c-window memory>struct _maxy>> 1 + ;
+: get-max-y ( -- y )
+    current-window get wget-max-y ;
+: wget-max-x ( window -- x )
+    ptr>> ffi:c-window memory>struct _maxx>> 1 + ;
+: get-max-x ( -- x )
+    current-window get wget-max-x ;