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 >
Wrap
C/C++ Source or Header
|
1996-06-05
|
5KB
|
298 lines
#include <stdio.h>
#include <string.h>
#include <iocslib.h>
#include <doslib.h>
#include <ctype.h>
#include "input.h"
#include "graph.h"
#include "view.h"
#define TRUE 1
#define FALSE 0
struct fkeytable {
char funckey[20][32] ;
char spckey[12][6] ;
} ;
static struct fkeytable default_fkey ;
static struct fkeytable set_fkey = {
{
"\xFEMenu1 \x7F\x01", "\xFEMenu2 \x7F\x02", "\xFEMenu3 \x7F\x03",
"\xFESearch \x7F\x04", "\xFERepeat \x7F\x05", "\xFESelect \x7F\x06",
"\xFE Cut \x7F\x07", "\xFE Copy \x7F\x08", "\xFEPaste \x7F\x09",
"\xFETagJump\x7F\x0A",
"\x7F\x0B", "\x7F\x0C", "\x7F\x0D", "\x7F\x0E", "\x7F\x0F",
"\x7F\x10", "\x7F\x11", "\x7F\x12", "\x7F\x13", "\x7F\x14",
},
{
/* ROLLUP ROLLDN INS DEL UP LEFT */
"\x7F\x15", "\x7F\x16", "\x7F\x17", "\x7F\x18", "\x7F\x19", "\x7F\x1A",
/* RIGHT DOWN CLR HELP HOME UNDO */
"\x7F\x1B", "\x7F\x1C", "\x7F\x1D", "\x7F\x1E", "\x7F\x1F", "\x7F\x20",
}
};
typedef struct {
unsigned short scancode;
unsigned short keycode;
} ConvTable;
#define SC(g,b) ((g)*8+(b))
static ConvTable convtable[] = {
{0x63, KEY_F1},
{0x64, KEY_F2},
{0x65, KEY_F3},
{0x66, KEY_F4},
{0x67, KEY_F5},
{0x68, KEY_F6},
{0x69, KEY_F7},
{0x6a, KEY_F8},
{0x6b, KEY_F9},
{0x6c, KEY_F10},
{0x38, KEY_ROLLUP},
{0x39, KEY_ROLLDOWN},
{0x5e, KEY_INS},
{0x37, KEY_DEL},
{0x3c, KEY_UP},
{0x3b, KEY_LEFT},
{0x3d, KEY_RIGHT},
{0x3e, KEY_DOWN},
{0x3f, KEY_CLR},
{0x54, KEY_HELP},
{0x36, KEY_HOME},
{0x3a, KEY_UNDO},
{0x4f, KEY_NUMPAD_0},
{0x4b, KEY_NUMPAD_1},
{0x4c, KEY_NUMPAD_2},
{0x4d, KEY_NUMPAD_3},
{0x47, KEY_NUMPAD_4},
{0x48, KEY_NUMPAD_5},
{0x49, KEY_NUMPAD_6},
{0x43, KEY_NUMPAD_7},
{0x44, KEY_NUMPAD_8},
{0x45, KEY_NUMPAD_9},
{0x40, KEY_NUMPAD_SLASH},
{0x41, KEY_NUMPAD_ASTERISK},
{0x42, KEY_NUMPAD_MINUS},
{0x46, KEY_NUMPAD_PLUS},
{0x4a, KEY_NUMPAD_EQUAL},
{0x4e, KEY_NUMPAD_ENTER},
{0x50, KEY_NUMPAD_COMMA},
{0x51, KEY_NUMPAD_PERIOD},
};
int MouseX = 0, MouseY = 0 ;
int MouseLeft = 0, MouseRight = 0 ;
int MouseMove = FALSE ;
int KeyCode = 0 ;
int ShiftStat = 0 ;
static int Cx, Cy ;
static int Cursor ;
static int ShiftSense( void );
static int KeySense( void );
static int KeyIn( void );
static void MouseON( void );
static void MouseOFF( void );
extern int QuitFlag ;
void InitInput()
{
FNCKEYGT( 0, (UBYTE*)&default_fkey );
FNCKEYST( 0, (UBYTE*)&set_fkey );
Cx = Cy = 0 ;
fputs("\x1b[>1h", stderr);
CursorOFF();
/* mouse */
MS_INIT();
SKEY_MOD( 0, 0, 0 );
MouseON();
}
void ExitInput()
{
MouseOFF();
SKEY_MOD( -1, 0, 0 );
FNCKEYST( 0, (UBYTE*)&default_fkey );
CursorON();
fputs("\x1b[>1l", stderr);
B_CLR_AL();
C_WIDTH( 0 );
}
void WaitInput()
{
int col, key ;
int n, x, y, sw, llsw ;
static int selectcol ;
static int lsw ;
sw = -1;
do
{
/* key */
key = KeySense();
/* mouse */
n = MS_CURGT();
x = ( n >> 16 ) & 0xffff ;
y = n & 0xffff ;
n = MS_GETDT();
llsw = sw;
sw = ( ( ( n & 0xff00 ) != 0 ) << 1 ) | ( ( n & 0x00ff ) != 0 );
if (llsw == -1) {
llsw = sw;
}
/* select color */
selectcol = ( selectcol + 1 ) & 0xFFFF ;
col = ( selectcol >> 5 ) & 255 ;
if ( col >= 128 )
col = 255 - col ;
graph_palet( SELECT_COLOR, 255-col, 0, 255-col );
}
while (lsw == sw && key == 0 && (sw == 0 || (x == MouseX && y == MouseY)) && !QuitFlag);
MouseMove = ( x != MouseX ) || ( y != MouseY );
MouseX = x ;
MouseY = y ;
if ( key )
KeyCode = KeyIn();
else
KeyCode = 0 ;
ShiftStat = ShiftSense();
lsw = sw ;
MouseLeft = sw >> 1 ;
MouseRight = sw & 1 ;
}
void PeekInput( void )
{
int n;
n = MS_CURGT();
MouseX = ( n >> 16 ) & 0xffff ;
MouseY = n & 0xffff ;
n = MS_GETDT();
MouseLeft = (n & 0xff00) != 0;
MouseRight = (n & 0x00ff) != 0;
ShiftStat = ShiftSense();
if (KeySense()) {
KeyCode = KeySense();
}
}
void FlushKey()
{
while( KeySense() )
KeyIn();
}
static int ShiftSense()
{
return B_SFTSNS();
}
static int ScanToCode(int code)
{
int i;
int ch, sc;
sc = (code >> 8) & 0xff;
ch = code & 0xff;
for (i = 0; i < sizeof(convtable)/sizeof(convtable[0]); ++i) {
if (convtable[i].scancode == sc) {
return convtable[i].keycode;
}
}
if (isalpha(ch)) {
if (B_SFTSNS() & 1) {
return toupper(ch);
} else {
return tolower(ch);
}
}
return ch;
}
static int KeySense()
{
/*
return INPOUT( 0xFE );
*/
int code;
code = B_KEYSNS();
if (code == 0) {
return FALSE;
} else {
int c;
c = ScanToCode(code - 0x10000);
if ((code & 0x10000) && c == 0) {
B_KEYINP();
}
return c;
}
}
static int KeyIn()
{
int code ;
int c;
code = ScanToCode( c = B_KEYINP());
return code;
}
static void MouseON()
{
MS_CURON();
}
static void MouseOFF()
{
MS_CUROF();
}
void Locate( x, y )
int x, y ;
{
Cx = x ;
Cy = y ;
if ( Cursor )
B_LOCATE( Cx, Cy );
}
void CursorON()
{
Cursor = TRUE ;
B_LOCATE( Cx, Cy );
C_CURON();
}
void CursorOFF()
{
Cursor = FALSE ;
C_CUROFF();
}
void Bell()
{
B_PUTC( 7 );
}
void GetCursorPosition( xp, yp )
int *xp, *yp ;
{
*xp = Cx ;
*yp = Cy ;
}