/*======================================== * sl.m: * Copyright 1993,1999 Toyoda Masashi * (toyoda@is.titech.ac.jp) * [Mac OS X version] Copyright 2003 KITADAI Yukinori * (Nyoho@hiroshima-u.ac.jp) * Last Modified: 2003/ 6/24 *======================================== */ /* sl version 3.03 : Mac OS X version 1.0.4 */ /* Drawing-speed is up(?) */ /* by KITADAI Yukinori 2003/ 6/24 */ /* sl version 3.03 : Mac OS X version 1.0.3 */ /* Changes font to Monaco */ /* by KITADAI Yukinori 2003/ 6/20 */ /* sl version 3.03 : Mac OS X version 1.0.2 */ /* from Yen symbol to backslash */ /* by KITADAI Yukinori 2003/ 6/18 */ /* sl version 3.03 : Mac OS X version 1.0.1 */ /* Only /dev/console owner meets slMacOSX.(Thanx T.Sumiya) */ /* Puts white under sl. */ /* by KITADAI Yukinori 2003/ 6/14 */ /* sl version 3.03 : Mac OS X version 1.0.0 */ /* by KITADAI Yukinori 2003/ 6/12 */ /* sl version 3.03 : add usleep(20000) */ /* by Toyoda Masashi 1998/ 7/22 */ /* sl version 3.02 : D51 flies! Change options. */ /* by Toyoda Masashi 1993/ 1/19 */ /* sl version 3.01 : Wheel turns smoother */ /* by Toyoda Masashi 1992/12/25 */ /* sl version 3.00 : Add d(D51) option */ /* by Toyoda Masashi 1992/12/24 */ /* sl version 2.02 : Bug fixed.(dust remains in screen) */ /* by Toyoda Masashi 1992/12/17 */ /* sl version 2.01 : Smoke run and disappear. */ /* Change '-a' to accident option. */ /* by Toyoda Masashi 1992/12/16 */ /* sl version 2.00 : Add a(all),l(long),F(Fly!) options. */ /* by Toyoda Masashi 1992/12/15 */ /* sl version 1.02 : Add turning wheel. */ /* by Toyoda Masashi 1992/12/14 */ /* sl version 1.01 : Add more complex smoke. */ /* by Toyoda Masashi 1992/12/14 */ /* sl version 1.00 : SL runs vomitting out smoke. */ /* by Toyoda Masashi 1992/12/11 */ #import #include #include #include #include #include #include #include #include "sl.h" int ACCIDENT = 0; int LOGO = 0; int FLY = 0; int NEXT = 1; char *buffer; int *usedlines; int lineMax,lineMin,colMax,colMin; int lineMax0, lineMin0; int lineDiff; float fontWidth, fontHeight; @interface SlView : NSView { NSTextStorage *textStorage; NSLayoutManager *layoutManager; NSTextContainer *textContainer; } - (id)initWithFrame:(NSRect)frame; - (void)dealloc; - (void)drawRect:(NSRect)rect; - (BOOL)isOpaque; - (BOOL)isFlipped; - (void)setColor:(NSColor *)color; - (void)setString:(NSString *)string; @end @implementation SlView - (id)initWithFrame:(NSRect)frame { [super initWithFrame:frame]; textStorage = [[NSTextStorage alloc] init]; layoutManager = [[NSLayoutManager alloc] init]; [textStorage addLayoutManager:layoutManager]; [textStorage replaceCharactersInRange:NSMakeRange(0, [textStorage length]) withString:@""]; [layoutManager release]; textContainer = [[NSTextContainer alloc] init]; //textContainer = [[NSTextContainer alloc] initWithContainerSize:frame.size]; /* [textContainer lineFragmentRectForProposedRect: frame sweepDirection: NSLineSweepRight movementDirection: NSLineMovesDown remainingRect: NULL ]; */ [layoutManager addTextContainer:textContainer]; [textContainer release]; [layoutManager setUsesScreenFonts:NO]; return self; } - (void)dealloc { [textStorage release]; [super dealloc]; } - (void)drawRect:(NSRect)rect { unsigned glyphIndex; NSRange glyphRange; NSRect usedRect; int i; NSFont *slFont = [NSFont fontWithName:@"Monaco" size:16]; NSDictionary *attr = [NSDictionary dictionaryWithObjectsAndKeys: slFont, NSFontAttributeName, [NSColor blackColor], NSForegroundColorAttributeName, nil ]; NSDictionary *attrW = [NSDictionary dictionaryWithObjectsAndKeys: slFont, NSFontAttributeName, [NSColor whiteColor], NSForegroundColorAttributeName, nil ]; [[NSColor clearColor] set]; //[[NSColor colorWithCalibratedRed:0.0 green:0.0 blue:0.4 alpha:0.5] set]; NSRectFill([self bounds]); glyphRange = [layoutManager glyphRangeForTextContainer:textContainer]; usedRect = [layoutManager usedRectForTextContainer:textContainer]; [textStorage setAttributes:attr range:NSMakeRange(0, [textStorage length])]; [textStorage addAttribute:NSForegroundColorAttributeName value:[NSColor whiteColor] range:NSMakeRange(0, [textStorage length])]; [layoutManager drawGlyphsForGlyphRange: glyphRange //atPoint:usedRect.origin]; atPoint:NSMakePoint(-5+1,1)]; [textStorage addAttribute:NSForegroundColorAttributeName value:[NSColor blackColor] range:NSMakeRange(0, [textStorage length])]; [layoutManager drawGlyphsForGlyphRange: glyphRange //atPoint:usedRect.origin]; atPoint:NSMakePoint(-5,0)]; } - (BOOL)isOpaque { return YES; } - (BOOL) isFlipped { return YES; } - (void)setString:(NSString *)string { [textStorage replaceCharactersInRange:NSMakeRange(0, [textStorage length]) withString:string]; [self setNeedsDisplay:YES]; } - (void)setColor:(NSColor *)color { [textStorage addAttribute:NSForegroundColorAttributeName value:color range:NSMakeRange(0, [textStorage length])]; [self setNeedsDisplay:YES]; } @end int check_console( int argc, char *argv[] ) { struct stat sb; uid_t uid = getuid(); stat ( "/dev/console", &sb ); if ( sb.st_uid != uid ){ NEXT=0; original_main ( argc, argv ); } return 0; } void checkUsedArea(void){ int i,j; lineMax = 0; lineMin = LINES-1; colMax = 0; colMin = COLS-1; for(i=0;ilineMax) lineMax = i; if(icolMax) colMax = j; if(j=COLS || y*COLS+x< 0 || y*COLS+x >= COLS*LINES) return ERR; else{ buffer[y*(COLS+1)+x]=*str; } } } return OK; } void option(char *str) { extern int ACCIDENT, FLY, LONG; while (*str != '\0') { switch (*str++) { case 'a': ACCIDENT = 1; break; case 'F': FLY = 1; break; case 'l': LOGO = 1; break; default: break; } } } int original_main(int argc, char *argv[]) { int x, i; for (i = 1; i < argc; ++i) { if (*argv[i] == '-') { option(argv[i] + 1); } } initscr(); signal(SIGINT, SIG_IGN); noecho(); leaveok(stdscr, TRUE); scrollok(stdscr, FALSE); for (x = COLS - 1; ; --x) { if (LOGO == 0) { if (add_D51(x) == ERR) break; } else { if (add_sl(x) == ERR) break; } refresh(); usleep(20000); } mvcur(0, COLS - 1, LINES - 1, 0); endwin(); exit(0); } int main(int argc, char *argv[]) { int dummy = check_console( argc, argv ); NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; id NSApp = [NSApplication new]; NSWindow *slWindow; NSString *string; SlView *slView; int x, i, j=0, k=0; NSRect rect; NSFont *slFont = [NSFont fontWithName:@"Monaco" size:16]; NSDictionary *attr = [NSDictionary dictionaryWithObjectsAndKeys: slFont, NSFontAttributeName, [NSColor blackColor], NSForegroundColorAttributeName, nil ]; NSDictionary *attrW = [NSDictionary dictionaryWithObjectsAndKeys: slFont, NSFontAttributeName, [NSColor whiteColor], NSForegroundColorAttributeName, nil ]; for (i = 1; i < argc; ++i) { if (*argv[i] == '-') { option(argv[i] + 1); } } initscr(); signal(SIGINT, SIG_IGN); noecho(); leaveok(stdscr, TRUE); scrollok(stdscr, FALSE); rect = [[NSScreen mainScreen] frame]; //rect.size.height*=0.2; fontWidth = [slFont widthOfString:@" "]; fontHeight = [slFont defaultLineHeightForFont]; COLS = (float)rect.size.width/fontWidth+1; LINES = (float)rect.size.height/fontHeight; buffer = (char *)malloc((COLS+1)*LINES*sizeof(char)); for(i=0;i<(COLS+1)*LINES;i++) buffer[i]=' '; for(i=0;i