⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xneko.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 3 页
字号:
 * *--------------------------------------------------------------*/voidDisplayCharacters(){    int		Index;    int		x, y;    for ( Index = 0, x = 0, y = 0;	  BitmapGCDataTable[ Index ].GCCreatePtr != NULL; Index++ ) {	DrawNeko( x, y, *(BitmapGCDataTable[ Index ].GCCreatePtr) );	XFlush( theDisplay );	x += BITMAP_WIDTH;	if ( x > WindowWidth - BITMAP_WIDTH ) {	    x = 0;	    y += BITMAP_HEIGHT;	    if ( y > WindowHeight - BITMAP_HEIGHT) {		break;	    }	}    }}#endif	/* DEBUG *//*-------------------------------------------------------------- * *	%-!<%$s%H=hM} * *--------------------------------------------------------------*/BoolProcessKeyPress( theKeyEvent )    XKeyEvent	*theKeyEvent;{    int			Length;    int			theKeyBufferMaxLen = AVAIL_KEYBUF;    char		theKeyBuffer[ AVAIL_KEYBUF + 1 ];    KeySym		theKeySym;    XComposeStatus	theComposeStatus;    Bool		ReturnState;    ReturnState = True;    Length = XLookupString( theKeyEvent,			    theKeyBuffer, theKeyBufferMaxLen,			    &theKeySym, &theComposeStatus );    if ( Length > 0 ) {	switch ( theKeyBuffer[ 0 ] ) {	case 'q':	case 'Q':	    if ( theKeyEvent->state & Mod1Mask ) {	/* META (Alt) %-!< */		ReturnState = False;	    }	    break;	default:	    break;	}    }#ifdef	DEBUG    if ( EventState == DEBUG_MOVE ) {	switch ( theKeySym ) {	case XK_KP_1:	    NekoMoveDx = -(int)( NekoSpeed / sqrt( (double)2 ) );	    NekoMoveDy = -NekoMoveDx;	    break;	case XK_KP_2:	    NekoMoveDx = 0;	    NekoMoveDy = (int)NekoSpeed;	    break;	case XK_KP_3:	    NekoMoveDx = (int)( NekoSpeed / sqrt( (double)2 ) );	    NekoMoveDy = NekoMoveDx;	    break;	case XK_KP_4:	    NekoMoveDx = -(int)NekoSpeed;	    NekoMoveDy = 0;	    break;	case XK_KP_5:	    NekoMoveDx = 0;	    NekoMoveDy = 0;	    break;	case XK_KP_6:	    NekoMoveDx = (int)NekoSpeed;	    NekoMoveDy = 0;	    break;	case XK_KP_7:	    NekoMoveDx = -(int)( NekoSpeed / sqrt( (double)2 ) );	    NekoMoveDy = NekoMoveDx;	    break;	case XK_KP_8:	    NekoMoveDx = 0;	    NekoMoveDy = -(int)NekoSpeed;	    break;	case XK_KP_9:	    NekoMoveDx = (int)( NekoSpeed / sqrt( (double)2 ) );	    NekoMoveDy = -NekoMoveDx;	    break;	}    }#endif    return( ReturnState );}/*-------------------------------------------------------------- * *	G-0LCVD4@0 * *--------------------------------------------------------------*/voidNekoAdjust(){    if ( NekoX < 0 ) {	NekoX = 0;    } else if ( NekoX > WindowWidth - BITMAP_WIDTH ) {	NekoX = WindowWidth - BITMAP_WIDTH;    }    if ( NekoY < 0 ) {	NekoY = 0;    } else if ( NekoY > WindowHeight - BITMAP_HEIGHT ) {	NekoY = WindowHeight - BITMAP_HEIGHT;    }}/*-------------------------------------------------------------- * *	%$s%H=hM} * *--------------------------------------------------------------*/BoolProcessEvent(){    XEvent	theEvent;    Bool	ContinueState = True;    switch ( EventState ) {    case NORMAL_STATE:	while ( XCheckMaskEvent( theDisplay, EVENT_MASK1, &theEvent ) ) {	    switch ( theEvent.type ) {	    case ConfigureNotify:		WindowWidth = theEvent.xconfigure.width;		WindowHeight = theEvent.xconfigure.height;		WindowPointX = theEvent.xconfigure.x;		WindowPointY = theEvent.xconfigure.y;		BorderWidth = theEvent.xconfigure.border_width;		NekoAdjust();		break;	    case Expose:		if ( theEvent.xexpose.count == 0 ) {		    RedrawNeko();		}		break;	    case MapNotify:		RedrawNeko();		break;	    case KeyPress:		ContinueState = ProcessKeyPress( &theEvent.xkey );		if ( !ContinueState ) {		    return( ContinueState );		}		break;	    default:		/* Unknown Event */		break;	    }	}	break;#ifdef	DEBUG    case DEBUG_LIST:	XNextEvent( theDisplay, &theEvent );	switch ( theEvent.type ) {	case ConfigureNotify:	    WindowWidth = theEvent.xconfigure.width;	    WindowHeight = theEvent.xconfigure.height;	    WindowPointX = theEvent.xconfigure.x;	    WindowPointY = theEvent.xconfigure.y;	    BorderWidth = theEvent.xconfigure.border_width;	    break;	case Expose:	    if ( theEvent.xexpose.count == 0 ) {		DisplayCharacters();	    }	    break;	case MapNotify:	    DisplayCharacters();	    break;	case KeyPress:	    ContinueState = ProcessKeyPress( &theEvent );	    break;	default:	    /* Unknown Event */	    break;	}	break;    case DEBUG_MOVE:	while ( XCheckMaskEvent( theDisplay, EVENT_MASK1, &theEvent ) ) {	    switch ( theEvent.type ) {	    case ConfigureNotify:		WindowWidth = theEvent.xconfigure.width;		WindowHeight = theEvent.xconfigure.height;		WindowPointX = theEvent.xconfigure.x;		WindowPointY = theEvent.xconfigure.y;		BorderWidth = theEvent.xconfigure.border_width;		NekoAdjust();		break;	    case Expose:		if ( theEvent.xexpose.count == 0 ) {		    RedrawNeko();		}		break;	    case MapNotify:		RedrawNeko();		break;	    case KeyPress:		ContinueState = ProcessKeyPress( &theEvent );		if ( !ContinueState ) {		    return( ContinueState );		}		break;	    default:		/* Unknown Event */		break;	    }	}	break;#endif    default:	/* Internal Error */	break;    }    return( ContinueState );}/*-------------------------------------------------------------- * *	G-=hM} * *--------------------------------------------------------------*/voidProcessNeko(){    struct itimerval	Value;    /* 4D6-$N=i4|2= */    EventState = NORMAL_STATE;    /* G-$N=i4|2= */    NekoX = ( WindowWidth - BITMAP_WIDTH / 2 ) / 2;    NekoY = ( WindowHeight - BITMAP_HEIGHT / 2 ) / 2;    NekoLastX = NekoX;    NekoLastY = NekoY;    SetNekoState( NEKO_STOP );    /* %?%$%^!<@_Dj */    timerclear( &Value.it_interval );    timerclear( &Value.it_value );    Value.it_interval.tv_usec = IntervalTime;    Value.it_value.tv_usec = IntervalTime;    setitimer( ITIMER_REAL, &Value, 0 );    /* %a%$%s=hM} */    do {	NekoThinkDraw();    } while ( ProcessEvent() );}#ifdef	DEBUG/*-------------------------------------------------------------- * *	G-0lMw!J5/31/93P14460MQ!K * *--------------------------------------------------------------*/voidNekoList(){    EventState = DEBUG_LIST;    fprintf( stderr, "\n" );    fprintf( stderr, "G-0lMw$rI=<($7$^$9!#(Quit !D Alt-Q)\n" );    fprintf( stderr, "\n" );    XSelectInput( theDisplay, theWindow, EVENT_MASK2 );    while ( ProcessEvent() );}/*-------------------------------------------------------------- * *	G-0\F0SCCS/s.xneko.c9%H!J5/31/93P14670MQ!K * *--------------------------------------------------------------*/voidNekoMoveTest(){    struct itimerval	Value;    /* 4D6-$N=i4|2= */    EventState = DEBUG_MOVE;    /* G-$N=i4|2= */    NekoX = ( WindowWidth - BITMAP_WIDTH / 2 ) / 2;    NekoY = ( WindowHeight - BITMAP_HEIGHT / 2 ) / 2;    NekoLastX = NekoX;    NekoLastY = NekoY;    SetNekoState( NEKO_STOP );    /* %?%$%^!<@_Dj */    timerclear( &Value.it_interval );    timerclear( &Value.it_value );    Value.it_interval.tv_usec = IntervalTime;    Value.it_value.tv_usec = IntervalTime;    setitimer( ITIMER_REAL, &Value, 0 );    /* %a%$%s=hM} */    fprintf( stderr, "\n" );    fprintf( stderr, "G-$N0\F0SCCS/s.xneko.c9%H$r9T$$$^$9!#(Quit !D Alt-Q)\n" );    fprintf( stderr, "\n" );    fprintf( stderr, "\t%-!<May 31, 1993C%I>e$NSCCS/s.xneko.cs%-!<$GG-$r0\F0$5$;$F2<$5$$!#\n" );    fprintf( stderr, "\t(M-8z$J%-!<$O#1!A#9$G$9!#)\n" );    fprintf( stderr, "\n" );    do {	NekoThinkDraw();    } while ( ProcessEvent() );}/*-------------------------------------------------------------- * *	%a%K%e!<=hM}!J5/31/93P15170MQ!K * *--------------------------------------------------------------*/voidProcessDebugMenu(){    int		UserSelectNo = 0;    char	UserAnswer[ BUFSIZ ];    fprintf( stderr, "\n" );    fprintf( stderr, "!Zxneko 5/31/93P15280%a%K%e!<![\n" );    while ( !( UserSelectNo >= 1 && UserSelectNo <= 2 ) ) {	fprintf( stderr, "\n" );	fprintf( stderr, "\t1)!!G-%-%c%i%/%?!<0lMwI=<(\n" );	fprintf( stderr, "\t2)!!G-0\F0SCCS/s.xneko.c9%H\n" );	fprintf( stderr, "\n" );	fprintf( stderr, "Select: " );	fgets( UserAnswer, sizeof( UserAnswer ), stdin );	UserSelectNo = atoi( UserAnswer );	if ( !( UserSelectNo >= 1 && UserSelectNo <= 2 ) ) {	    fprintf( stderr, "\n" );	    fprintf( stderr, "@5$7$$HV9f$rA*Br$7$F2<$5$$!#\n" );	}    }    switch ( UserSelectNo ) {    case 1:	/* G-%-%c%i%/%?!<0lMwI=<( */	NekoList();	break;    case 2:	/* G-0\F0SCCS/s.xneko.c9%H */	NekoMoveTest();	break;    default:	/* Internal Error */	break;    }    fprintf( stderr, "SCCS/s.xneko.c9%H=*N;!#\n" );    fprintf( stderr, "\n" );}#endif	/* DEBUG *//*-------------------------------------------------------------- * *	SIGALRM %7%0%J%k=hM} * *--------------------------------------------------------------*/voidNullFunction(){    /* No Operation */}/*-------------------------------------------------------------- * *	Usage * *--------------------------------------------------------------*/voidUsage(){    fprintf( stderr,	     "Usage: %s [-display <display>] [-geometry <geometry>] \\\n",	     ProgramName );    fprintf( stderr, "  [-title <title>] [-name <title>] [-iconic] \\\n" );    fprintf( stderr, "  [-speed <speed>] [-time <time>] [-help]\n" );}/*-------------------------------------------------------------- * *	#XMay 31, 1993i%a!<%?I>2A * *--------------------------------------------------------------*/BoolGetArguments( argc, argv, theDisplayName, theGeometry, theTitle,	      NekoSpeed, IntervalTime )    int		argc;    char	*argv[];    char	*theDisplayName;    char	*theGeometry;    char	*theTitle;    double	*NekoSpeed;    long	*IntervalTime;{    int		ArgCounter;    Bool	iconicState;    theDisplayName[ 0 ] = '\0';    theGeometry[ 0 ] = '\0';    theTitle[ 0 ] = '\0';    iconicState = False;    for ( ArgCounter = 0; ArgCounter < argc; ArgCounter++ ) {	if ( strncmp( argv[ ArgCounter ], "-h", 2 ) == 0 ) {	    Usage();	    exit( 0 );	} else if ( strcmp( argv[ ArgCounter ], "-display" ) == 0 ) {	    ArgCounter++;	    if ( ArgCounter < argc ) {		strcpy( theDisplayName, argv[ ArgCounter ] );	    } else {		fprintf( stderr, "%s: -display option error.\n", ProgramName );		exit( 1 );	    }	} else if ( strncmp( argv[ ArgCounter ], "-geom", 5 ) == 0 ) {	    ArgCounter++;	    if ( ArgCounter < argc ) {		strcpy( theGeometry, argv[ ArgCounter ] );	    } else {		fprintf( stderr,			 "%s: -geometry option error.\n", ProgramName );		exit( 1 );	    }	} else if ( ( strcmp( argv[ ArgCounter ], "-title" ) == 0 )	     || ( strcmp( argv[ ArgCounter ], "-name" ) == 0 ) ) {	    ArgCounter++;	    if ( ArgCounter < argc ) {		strcpy( theTitle, argv[ ArgCounter ] );	    } else {		fprintf( stderr, "%s: -title option error.\n", ProgramName );		exit( 1 );	    }	} else if ( strcmp( argv[ ArgCounter ], "-iconic" ) == 0 ) {	    iconicState = True;	} else if ( strcmp( argv[ ArgCounter ], "-speed" ) == 0 ) {	    ArgCounter++;	    if ( ArgCounter < argc ) {		*NekoSpeed = atof( argv[ ArgCounter ] );	    } else {		fprintf( stderr, "%s: -speed option error.\n", ProgramName );		exit( 1 );	    }	} else if ( strcmp( argv[ ArgCounter ], "-time" ) == 0 ) {	    ArgCounter++;	    if ( ArgCounter < argc ) {		*IntervalTime = atol( argv[ ArgCounter ] );	    } else {		fprintf( stderr, "%s: -time option error.\n", ProgramName );		exit( 1 );	    }	} else {	    fprintf( stderr,		     "%s: Unknown option \"%s\".\n", ProgramName,						     argv[ ArgCounter ] );	    Usage();	    exit( 1 );	}    }    if ( strlen( theDisplayName ) < 1 ) {	theDisplayName = NULL;    }    if ( strlen( theGeometry ) < 1 ) {	theGeometry = NULL;    }    return( iconicState );}/*-------------------------------------------------------------- * *	%a%$%s4X?t * *--------------------------------------------------------------*/intmain( argc, argv )    int		argc;    char	*argv[];{    Bool	iconicState;    char	theDisplayName[ DIRNAMELEN ];    char	theGeometry[ DIRNAMELEN ];    char	theTitle[ DIRNAMELEN ];    ProgramName = argv[ 0 ];    argc--;    argv++;    iconicState = GetArguments( argc, argv,				theDisplayName,				theGeometry,				theTitle,				&NekoSpeed,				&IntervalTime );    InitScreen( theDisplayName, theGeometry, theTitle, iconicState );    signal( SIGALRM, NullFunction );    SinPiPer8Times3 = sin( PI_PER8 * (double)3 );    SinPiPer8 = sin( PI_PER8 );#ifndef	DEBUG    ProcessNeko();#else    ProcessDebugMenu();#endif    exit( 0 );}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -