home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / VPR_DATA / DOGA / SOURCES / POLYEDIT.LZH / MODEL / INPUTX.C < prev    next >
C/C++ Source or Header  |  1996-06-05  |  5KB  |  298 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <iocslib.h>
  4. #include <doslib.h>
  5. #include <ctype.h>
  6.  
  7. #include "input.h"
  8. #include "graph.h"
  9. #include "view.h"
  10.  
  11. #define    TRUE    1
  12. #define    FALSE    0
  13.  
  14. struct    fkeytable {
  15.     char    funckey[20][32] ;
  16.     char    spckey[12][6] ;
  17. } ;
  18.  
  19. static    struct    fkeytable    default_fkey ;
  20. static    struct    fkeytable    set_fkey = {
  21.     {
  22.             "\xFEMenu1  \x7F\x01",    "\xFEMenu2  \x7F\x02",    "\xFEMenu3  \x7F\x03",
  23.             "\xFESearch \x7F\x04",    "\xFERepeat \x7F\x05",    "\xFESelect \x7F\x06",
  24.             "\xFE Cut   \x7F\x07",    "\xFE Copy  \x7F\x08",    "\xFEPaste  \x7F\x09",
  25.             "\xFETagJump\x7F\x0A",
  26.             "\x7F\x0B",    "\x7F\x0C",    "\x7F\x0D", "\x7F\x0E", "\x7F\x0F",
  27.             "\x7F\x10",    "\x7F\x11",    "\x7F\x12", "\x7F\x13", "\x7F\x14",
  28.     },
  29.     {
  30.         /*    ROLLUP        ROLLDN        INS            DEL            UP            LEFT        */
  31.             "\x7F\x15",    "\x7F\x16",    "\x7F\x17",    "\x7F\x18",    "\x7F\x19",    "\x7F\x1A",
  32.         /*    RIGHT        DOWN        CLR            HELP        HOME        UNDO        */
  33.             "\x7F\x1B",    "\x7F\x1C",    "\x7F\x1D",    "\x7F\x1E",    "\x7F\x1F", "\x7F\x20",
  34.     }
  35. };
  36.  
  37. typedef struct    {
  38.     unsigned short    scancode;
  39.     unsigned short    keycode;
  40. }    ConvTable;
  41.  
  42. #define SC(g,b)    ((g)*8+(b))
  43.  
  44. static ConvTable convtable[] = {
  45.     {0x63, KEY_F1},
  46.     {0x64, KEY_F2},
  47.     {0x65, KEY_F3},
  48.     {0x66, KEY_F4},
  49.     {0x67, KEY_F5},
  50.     {0x68, KEY_F6},
  51.     {0x69, KEY_F7},
  52.     {0x6a, KEY_F8},
  53.     {0x6b, KEY_F9},
  54.     {0x6c, KEY_F10},
  55.     {0x38, KEY_ROLLUP},
  56.     {0x39, KEY_ROLLDOWN},
  57.     {0x5e, KEY_INS},
  58.     {0x37, KEY_DEL},
  59.     {0x3c, KEY_UP},
  60.     {0x3b, KEY_LEFT},
  61.     {0x3d, KEY_RIGHT},
  62.     {0x3e, KEY_DOWN},
  63.     {0x3f, KEY_CLR},
  64.     {0x54, KEY_HELP},
  65.     {0x36, KEY_HOME},
  66.     {0x3a, KEY_UNDO},
  67.     {0x4f, KEY_NUMPAD_0},
  68.     {0x4b, KEY_NUMPAD_1},
  69.     {0x4c, KEY_NUMPAD_2},
  70.     {0x4d, KEY_NUMPAD_3},
  71.     {0x47, KEY_NUMPAD_4},
  72.     {0x48, KEY_NUMPAD_5},
  73.     {0x49, KEY_NUMPAD_6},
  74.     {0x43, KEY_NUMPAD_7},
  75.     {0x44, KEY_NUMPAD_8},
  76.     {0x45, KEY_NUMPAD_9},
  77.     {0x40, KEY_NUMPAD_SLASH},
  78.     {0x41, KEY_NUMPAD_ASTERISK},
  79.     {0x42, KEY_NUMPAD_MINUS},
  80.     {0x46, KEY_NUMPAD_PLUS},
  81.     {0x4a, KEY_NUMPAD_EQUAL},
  82.     {0x4e, KEY_NUMPAD_ENTER},
  83.     {0x50, KEY_NUMPAD_COMMA},
  84.     {0x51, KEY_NUMPAD_PERIOD},
  85. };
  86. int        MouseX = 0, MouseY = 0 ;
  87. int        MouseLeft = 0, MouseRight = 0 ;
  88. int        MouseMove = FALSE ;
  89. int        KeyCode = 0 ;
  90. int        ShiftStat = 0 ;
  91.  
  92. static    int        Cx, Cy ;
  93. static    int        Cursor ;
  94.  
  95. static    int        ShiftSense( void );
  96. static    int        KeySense( void );
  97. static    int        KeyIn( void );
  98. static    void    MouseON( void );
  99. static    void    MouseOFF( void );
  100.  
  101. extern    int        QuitFlag ;
  102.  
  103. void    InitInput()
  104. {
  105.     FNCKEYGT( 0, (UBYTE*)&default_fkey );
  106.     FNCKEYST( 0, (UBYTE*)&set_fkey );
  107.  
  108.     Cx = Cy = 0 ;
  109.     fputs("\x1b[>1h", stderr);
  110.     CursorOFF();
  111.  
  112.     /*    mouse    */
  113.     MS_INIT();
  114.     SKEY_MOD( 0, 0, 0 );
  115.     MouseON();
  116. }
  117.  
  118. void    ExitInput()
  119. {
  120.     MouseOFF();
  121.     SKEY_MOD( -1, 0, 0 );
  122.  
  123.     FNCKEYST( 0, (UBYTE*)&default_fkey );
  124.     CursorON();
  125.     fputs("\x1b[>1l", stderr);
  126.  
  127.     B_CLR_AL();
  128.     C_WIDTH( 0 );
  129. }
  130.  
  131. void    WaitInput()
  132. {
  133.     int        col, key ;
  134.     int        n, x, y, sw, llsw ;
  135.     static    int        selectcol ;
  136.     static    int        lsw ;
  137.     sw = -1;
  138.     do
  139.     {
  140.         /* key */
  141.         key = KeySense();
  142.  
  143.         /* mouse */
  144.         n = MS_CURGT();
  145.         x = ( n >> 16 ) & 0xffff ;
  146.         y = n & 0xffff ;
  147.         n = MS_GETDT();
  148.         llsw = sw;
  149.         sw = ( ( ( n & 0xff00 ) != 0 ) << 1 ) | ( ( n & 0x00ff ) != 0 );
  150.         if (llsw == -1) {
  151.             llsw = sw;
  152.         }
  153.  
  154.         /* select color */
  155.         selectcol = ( selectcol + 1 ) & 0xFFFF ;
  156.         col = ( selectcol >> 5 ) & 255 ;
  157.         if ( col >= 128 )
  158.             col = 255 - col ;
  159.         graph_palet( SELECT_COLOR, 255-col, 0, 255-col );
  160.     }
  161.     while (lsw == sw && key == 0 && (sw == 0 || (x == MouseX && y == MouseY)) && !QuitFlag);
  162.  
  163.     MouseMove = ( x != MouseX ) || ( y != MouseY );
  164.     MouseX = x ;
  165.     MouseY = y ;
  166.     if ( key )
  167.         KeyCode = KeyIn();
  168.     else
  169.         KeyCode = 0 ;
  170.     ShiftStat = ShiftSense();
  171.     lsw = sw ;
  172.     MouseLeft = sw >> 1 ;
  173.     MouseRight = sw & 1 ;
  174. }
  175.  
  176. void    PeekInput( void )
  177. {
  178.     int        n;
  179.  
  180.     n = MS_CURGT();
  181.     MouseX = ( n >> 16 ) & 0xffff ;
  182.     MouseY = n & 0xffff ;
  183.     n = MS_GETDT();
  184.     MouseLeft = (n & 0xff00) != 0;
  185.     MouseRight = (n & 0x00ff) != 0;
  186.  
  187.     ShiftStat = ShiftSense();
  188.     if (KeySense()) {
  189.         KeyCode = KeySense();
  190.     }
  191. }
  192.  
  193. void    FlushKey()
  194. {
  195.     while( KeySense() )
  196.         KeyIn();
  197. }
  198.  
  199. static    int        ShiftSense()
  200. {
  201.     return B_SFTSNS();
  202. }
  203.  
  204. static    int    ScanToCode(int code)
  205. {
  206.     int i;
  207.     int ch, sc;
  208.     sc = (code >> 8) & 0xff;
  209.     ch = code & 0xff;
  210.     for (i = 0; i < sizeof(convtable)/sizeof(convtable[0]); ++i) {
  211.         if (convtable[i].scancode == sc) {
  212.             return convtable[i].keycode;
  213.         }
  214.     }
  215.     if (isalpha(ch)) {
  216.         if (B_SFTSNS() & 1) {
  217.             return toupper(ch);
  218.         } else {
  219.             return tolower(ch);
  220.         }
  221.     }
  222.     return ch;
  223. }
  224.  
  225.  
  226. static    int        KeySense()
  227. {
  228. /*
  229.     return INPOUT( 0xFE );
  230. */
  231.     int code;
  232.     code = B_KEYSNS();
  233.     if (code == 0) {
  234.         return FALSE;
  235.     } else {
  236.         int c;
  237.         c = ScanToCode(code - 0x10000);
  238.         if ((code & 0x10000) && c == 0) {
  239.             B_KEYINP();
  240.         }
  241.         return c;
  242.     }
  243.  
  244. }
  245.  
  246. static    int        KeyIn()
  247. {
  248.     int        code ;
  249.     int c;
  250.     code = ScanToCode( c = B_KEYINP());
  251.     return code;
  252. }
  253.  
  254.  
  255. static    void    MouseON()
  256. {
  257.     MS_CURON();
  258. }
  259.  
  260. static    void    MouseOFF()
  261. {
  262.     MS_CUROF();
  263. }
  264.  
  265. void    Locate( x, y )
  266. int        x, y ;
  267. {
  268.     Cx = x ;
  269.     Cy = y ;
  270.     if ( Cursor )
  271.         B_LOCATE( Cx, Cy );
  272. }
  273.  
  274. void    CursorON()
  275. {
  276.     Cursor = TRUE ;
  277.     B_LOCATE( Cx, Cy );
  278.     C_CURON();
  279. }
  280.  
  281. void    CursorOFF()
  282. {
  283.     Cursor = FALSE ;
  284.     C_CUROFF();
  285. }
  286.  
  287. void    Bell()
  288. {
  289.     B_PUTC( 7 );
  290. }
  291.  
  292. void    GetCursorPosition( xp, yp )
  293. int        *xp, *yp ;
  294. {
  295.     *xp = Cx ;
  296.     *yp = Cy ;
  297. }
  298.