home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
d
/
dir_nm20.zip
/
Dir_NM_2.0
/
NM-Tool.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-07-16
|
10KB
|
438 lines
/* === IM-Tool.c ===
*
* int Rand_Num(Scaler)
* int KeyPressed()
* char GetKey()
* char getkey()
* char getch()
* char *Sub_Str(string,head,length)
* void Str_Append(Str_head,Str_tail,Length)
* void SetColor(color)
* void Line(x1,y1,x2,y2)
* void DrawRectangle(x_start,y_start,width,height)
* void FillRectangle(x_start,y_start,width,height)
* void Rub(x1,y1,width,height,color)
* void OutTextXY(x,y,string)
* void DrawEllipse(x,y,width,height,angle1,angle2)
* void FillEllipse(x,y,width,height,angle1,angle2)
* void Use_Font(font_name)
* void Out_I_XY(x,y,I)
* void Out_D_XY(x,y,D)
* void Dis(lock)
* void highlight(x_st,y_st,width,height)
* void readat(x,y,n,k)
* void Addline(x,y,z,At_high)
* void Underline(x,z,n)
* void Draw_Dot(x,y)
* void Point(x,y)
* void Dot(x,y)
* void Sharp(x,y)
* void Flat(x,y)
* void Normal(x,y)
* void HI_mark(i)
* void LO_mark(i)
* void Underline_(x,y,n)
* void L_Arrow(x,y)
* void R_Arrow(x,y)
* void U_Arrow(x,y)
* void D_Arrow(x,y)
* void Notice(x,y,dx,dy,on,On_Color,Off_Color)
*
*/
#include "NM.h"
int Rand_Num(Scaler)
int Scaler;
{
struct timeval tp;
struct timezone tzp;
if (gettimeofday(&tp,&tzp)==0) srand(tp.tv_sec % 60);else srand(6);
return rand()%Scaler;
}
int KeyPressed()
{
XEvent report;
XNextEvent(display,&report);
if (report.type==KeyPress) return (1);else return (0);
}
char GetKey()
{
XEvent report;
KeySym ks;
while(1)
{
XNextEvent(display,&report);
if (report.type==KeyPress)
{
ks=XLookupKeysym(report,0);
switch(ks)
{
case XK_F1:return '*';
case XK_F2:return '/';
case XK_F3:return '+';
case XK_F4:return '=';
case XK_F5:return '[';
case XK_F6:return ']';
case XK_Return:return '!';
case XK_Escape:return '&';
case XK_Left:return '<';
case XK_Right:return '>';
case XK_Up:return '?';
case XK_Down:return '@';
case 65496:return '#'; /* Home */
case 65502:return '%'; /* End */
case 65498:return '$'; /* PgUp */
case 65504:return '^'; /* PgDn */
case XK_Num_Lock:return '|';
case XK_Insert:return '{';
case XK_Delete:return '}';
default:XLookupString(report,tmpstr,128,&ks,0);
if (isalpha(tmpstr[0])) return (toupper(tmpstr[0]));
else return (tmpstr[0]);
}
}
}
}
char getkey()
{
XEvent report;
KeySym ks;
while(1)
{
XNextEvent(display,&report);
if (report.type==KeyPress)
{
ks=XLookupKeysym(report,0);
switch(ks)
{
case XK_F1:return '*';
case XK_F2:return '/';
case XK_F3:return '+';
case XK_F4:return '=';
case XK_F5:return '[';
case XK_F6:return ']';
case XK_Return:return '!';
case XK_Escape:return '&';
case XK_Left:return '<';
case XK_Right:return '>';
case XK_Up:return '?';
case XK_Down:return '@';
case 65496:return '#'; /* Home */
case 65502:return '%'; /* End */
case 65498:return '$'; /* PgUp */
case 65504:return '^'; /* PgDn */
case XK_Num_Lock:return '|';
case XK_Insert:return '{';
case XK_Delete:return '}';
default:XLookupString(report,tmpstr,128,&ks,0);return (tmpstr[0]);
}
}
}
}
char getch()
{
XEvent report;
KeySym ks;
while(1)
{
XNextEvent(display,&report);
if (report.type==KeyPress)
{ XLookupString(report,tmpstr,1,&ks,0);return (tmpstr[0]); }
}
}
char *Sub_Str(string,head,length)
char *string;
int head,length;
{
char *sub;
int i;
sub=(char *)malloc(5000);*sub='\0';i=-1;
if (strlen(string)>head && string[head]!='\n')
{
do
{
i++;sprintf(sub+strlen(sub),"%c",string[head+i]);
} while (i<length-1 && string[head+i]!='\n');
}
return sub;
}
void Str_Append(Str_head,Str_tail,Length)
char Str_head[256],Str_tail[256];
int Length;
{
if (Length<2) sprintf(Str_head+strlen(Str_head),"%c",Str_tail);
else sprintf(Str_head+strlen(Str_head),"%s",Str_tail);
}
void SetColor(color)
char *color;
{
XAllocNamedColor(display,theCmap,color,&exactcolor,&mycolor);
XSetForeground(display,gc,mycolor.pixel);
}
void Line(x1,y1,x2,y2)
int x1,y1,x2,y2;
{
XDrawLine(display,win,gc,x1,y1,x2,y2);
}
void DrawRectangle(x_start,y_start,width,height)
int x_start,y_start,width,height;
{
XDrawRectangle(display,win,gc,x_start,y_start,width,height);
}
void FillRectangle(x_start,y_start,width,height)
int x_start,y_start,width,height;
{
XFillRectangle(display,win,gc,x_start,y_start,width,height);
}
void Rub(x1,y1,width,height,color)
int x1,y1,width,height;
char *color;
{
SetColor(color);XFillRectangle(display,win,gc,x1,y1,width,height);
}
void OutTextXY(x,y,string)
int x,y;
char *string;
{
if (string[strlen(string)-1]=='\n')
XDrawString(display,win,gc,x,y,string,strlen(string)-1);
else XDrawString(display,win,gc,x,y,string,strlen(string));
}
void DrawEllipse(x,y,width,height,angle1,angle2)
int x,y,width,height,angle1,angle2;
{
XDrawArc(display,win,gc,x,y,width,height,angle1*64,angle2*64);
}
void FillEllipse(x,y,width,height,angle1,angle2)
int x,y,width,height,angle1,angle2;
{
XFillArc(display,win,gc,x,y,width,height,angle1*64,angle2*64);
}
void Use_Font(font_name)
char *font_name;
{
Font font;
font=XLoadFont(display,font_name);XSetFont(display,gc,font);
}
void Out_I_XY(x,y,I)
int x,y,I;
{
static char MsgText[12];
(void) sprintf(MsgText,"%i",I);
XDrawString(display,win,gc,x,y,MsgText,strlen(MsgText));
}
void Out_D_XY(x,y,D)
int x,y;
double D;
{
static char MsgText[12];
(void) sprintf(MsgText,"%d.2",D);
XDrawString(display,win,gc,x,y,MsgText,strlen(MsgText));
}
void dis(lock)
int *lock;
{
*lock=1-*lock;
}
void highlight(x_st,y_st,width,height)
int x_st,y_st,width,height;
{
SetColor("LimeGreen");XSetFunction(display,gc,GXxor);
FillRectangle(x_st,y_st,width,height);
SetColor("blue");DrawRectangle(x_st,y_st,width-1,height-1);
XSetFunction(display,gc,GXcopy);
}
void readat(x,y,n,k)
int x,y,n,*k;
{
char ch,st[7],STR1[256];
int i;
*st='\0';i=0;if (n>5) n=5;
do {
highlight(x+i*15,y-21,16,22);
do { } while (!(ch=GetKey()));
if (ch=='-' || isdigit(ch))
{
if (ch=='-') n++;sprintf(st+strlen(st),"%c",ch);
sprintf(STR1,"%c",ch);highlight(x+i*15,y-21,16,22);
SetColor("magenta");OutTextXY(x+i*15,y,STR1);i++;
}
} while (ch!='!' && i!=n);
if (i!=n) highlight(x+i*15,y-21,16,22);
if (*st=='\0') strcpy(st,"0");*k=atoi(st);
}
void Addline(x,Y,z,At_high)
int x,Y,z,At_high;
{
int i,k,y;
k=0;if (At_high<2) y=Y-V_Ht/4;else y=Y;
if (At_high==2)
{
SetColor("white");if (y<11) k=(12-y)/2;else if (y>21) k=(20-y)/2;
if (k>0) for (i=0;i<k;i++) Line(x+5,z-i*8+76,x+30,z-i*8+76);
else if (k<0) for (i=0;i<abs(k);i++) Line(x+5,z+i*8+124,x+30,z+i*8+124);
}
else if (At_high==1)
{
SetColor("white");if (y<11) k=(12-y)/2;else if (y>21) k=(20-y)/2;
if (k>0)
for (i=0;i<k;i++) Line(x+5,z-i*8+76+V_Ht,x+30,z-i*8+76+V_Ht);
else if (k<0)
for (i=0;i<abs(k);i++)
Line(x+5,z+i*8+124+V_Ht,x+30,z+i*8+124+V_Ht);
}
else if (At_high==0)
{
SetColor("grey");if (y<31) k=(32-y)/2;else if (y>41) k=(40-y)/2;
if (k>0)
for (i=0;i<k;i++)
Line(x+5,z-i*8+156+V_Ht,x+30,z-i*8+156+V_Ht);
else if (k<0)
for (i=0;i<abs(k);i++)
Line(x+5,z+i*8+204+V_Ht,x+30,z+i*8+204+V_Ht);
}
}
void Underline(x,z,n)
int x,z,n;
{
int k;
if (n<0) { n=-n;SetColor("MediumBlue"); } else SetColor("gold");
for (k=0;k<n;k++) Line(x*20+3,z+k*2+44,x*20+15,z+k*2+44);
}
void Draw_Dot(x,y)
int x,y;
{
FillEllipse(x,y,2,2,0,360*64);
}
void Point(x,y)
int x,y;
{
FillEllipse(x,y,6,6,0,360*64);
}
void Dot(x,y)
int x,y;
{
SetColor("ivory");XSetFunction(display,gc,GXxor);
FillEllipse(x,y,7,8,0,360*64);XSetFunction(display,gc,GXcopy);
}
void Sharp(x,y)
int x,y;
{
Line(x,y,x+7,y);Line(x,y+6,x+7,y+6);Line(x+2,y-3,x+2,y+9);
Line(x+5,y-3,x+5,y+9);
}
void Flat(x,y)
int x,y;
{
Line(x,y,x,y+12);Line(x+1,y+7,x+5,y+7);Line(x+5,y+7,x+5,y+10);
Line(x,y+12,x+5,y+10);
}
void Normal(x,y)
int x,y;
{
Line(x,y,x,y+14);Line(x,y+9,x+4,y+6);Line(x,y+12,x+4,y+9);
Line(x+4,y+4,x+4,y+18);
}
void HI_mark(i)
int i;
{
DrawEllipse(19,i-7,12,11,0,240);DrawEllipse(14,i-12,18,20,0,-270);
DrawEllipse(6,i-40,22,30,60,-120);DrawEllipse(6,i-41,22,30,60,-120);
DrawEllipse(19,i-40,16,30,-123,-127);DrawEllipse(19,i-39,16,30,-123,-127);
Line(21,i-16,25,i+14);Line(20,i-16,26,i+14);DrawEllipse(17,i+11,8,9,30,-180);
DrawEllipse(18,i+11,8,9,30,-180);Point(15,i+13);
}
void LO_mark(i)
int i;
{
Point(15,i+1);DrawEllipse(16,i-2,12,16,0,180);DrawEllipse(8,i-10,20,32,0,-90);
DrawEllipse(16,i-1,12,16,0,180);DrawEllipse(8,i-9,20,32,0,-90);
FillEllipse(32,i-3,5,5,0,360*64);FillEllipse(32,i+5,5,5,0,360*64);
}
void Underline_(x,y,n)
int x,y,n;
{
int k;
for (k=0;k<n;k++) Line(x-2,y+k*4,x+15,y+k*4);
}
void L_Arrow(x,y)
int x,y;
{
Line(x,y,x+5,y-3);Line(x,y,x+5,y+3);Line(x-1,y,x+13,y);
}
void R_Arrow(x,y)
int x,y;
{
Line(x,y,x-5,y-3);Line(x,y,x-5,y+3);Line(x+1,y,x-13,y);
}
void U_Arrow(x,y)
int x,y;
{
Line(x,y,x-3,y+5);Line(x,y,x+3,y+5);Line(x,y-1,x,y+13);
}
void D_Arrow(x,y)
int x,y;
{
Line(x,y,x-2,y-5);Line(x,y,x+2,y-5);Line(x,y+1,x,y-13);
}
void Notice(x,y,dx,dy,on,On_Color,Off_Color)
int x,y,dx,dy,on;
char *On_Color,*Off_Color;
{
XSetFunction(display,gc,GXcopy);
if (on==1) SetColor(On_Color);else SetColor(Off_Color);
FillRectangle(x,y,dx,dy);
}