#import #import #import #include "../ref_soft/r_local.h" @interface QuakeView : NSView @end NSWindow *vid_window_i; QuakeView *vid_view_i; NSDirectScreen *vid_screen; byte *vid_buffer; // real framebuffer int vid_rowbytes; // framebuffer rowbytes unsigned *buffernative; // 24 bit off-screen back buffer for window unsigned swimp_palette[256]; typedef enum { rhap_shutdown, rhap_windowed, rhap_fullscreen } rhapMode_t; rhapMode_t rhap_mode; /* ======================================================================= FULLSCREEN ======================================================================= */ /* ** InitFullscreen */ rserr_t InitFullscreen (int width, int height) { NSDictionary *mode, *bestMode; int modeWidth, bestWidth; int modeHeight, bestHeight; NSArray *modes; int i; NSString *string; vid_screen = [[NSDirectScreen alloc] initWithScreen:[NSScreen mainScreen]]; // search for an apropriate mode modes = [vid_screen availableDisplayModes]; bestMode = NULL; bestWidth = 99999; bestHeight = 99999; for (i=0 ; i<[modes count] ; i++) { mode = [modes objectAtIndex: i]; string = [mode objectForKey: @"NSDirectScreenPixelEncoding"]; if ( ![string isEqualToString: @"PPPPPPPP"] ) continue; // only look at paletted modes modeWidth = [[mode objectForKey: @"NSDirectScreenWidth"] intValue]; modeHeight = [[mode objectForKey: @"NSDirectScreenHeight"] intValue]; if (modeWidth < width || modeHeight < height) continue; if (modeWidth < bestWidth) { bestWidth = modeWidth; bestHeight = modeHeight; bestMode = mode; } } // if there wasn't any paletted mode of that res or greater, fail if (!bestMode) return rserr_invalid_fullscreen; ri.Con_Printf (PRINT_ALL, "SheildDisplay\n"); [vid_screen shieldDisplay]; // hide the cursor in all fullscreen modes [NSCursor hide]; vid_window_i = [vid_screen shieldingWindow]; ri.Con_Printf (PRINT_ALL, "switchToDisplayMode\n"); [vid_screen switchToDisplayMode:bestMode]; // [vid_screen fadeDisplayOutToColor:[NSColor blackColor]]; // [vid_screen fadeDisplayInFromColor:[NSColor blackColor]]; vid_buffer = [vid_screen data]; vid_rowbytes = [vid_screen bytesPerRow]; return rserr_ok; } void ShutdownFullscreen (void) { [vid_screen dealloc]; [NSCursor unhide]; } void SetPaletteFullscreen (const unsigned char *palette) { #if 0 byte *p; int i; NSDirectPalette *pal; pal = [NSDirectPalette init]; for (i=0 ; i<256 ; i++) [pal setRed: palette[0]*(1.0/255) green: palette[1]*(1.0/255) blue: palette[2]*(1.0/255) atIndex: i]; [vid_screen setPalette: pal]; [pal release]; #endif } void BlitFullscreen (void) { int i, j; int w; int *dest, *source; w = vid.width>>2; source = (int *)vid.buffer; // off-screen buffer dest = (int *)vid_buffer; // directly on screen for (j=0 ; j>2), dest += (vid_rowbytes>>2) ) { for (i=0 ; ivalue,vid_ypos->value, width, height); vid_window_i = [[NSWindow alloc] initWithContentRect: content styleMask: NSTitledWindowMask backing: NSBackingStoreRetained defer: NO ]; // [vid_window_i addToEventMask: NS_FLAGSCHANGEDMASK]; [vid_window_i setTitle: @"Quake2"]; buffernative = malloc(width * height * 4); return retval; } void ShutdownWindowed (void) { if (vid_window_i) { [vid_window_i release]; vid_window_i = NULL; } if (buffernative) { free (buffernative); buffernative = NULL; } } void SetPaletteWindowed (const unsigned char *palette) { byte *p; int i; p = (byte *)swimp_palette; for (i=0 ; i<256 ; i++, p+=4, palette+=4) { p[0] = palette[0]; p[1] = palette[1]; p[2] = palette[2]; p[3] = 0xff; } } void BlitWindowed (void) { int i, c; int bps, spp, bpp, bpr; unsigned char *planes[5]; NSRect bounds; if (!vid_view_i) return; // translate to 24 bit color c = vid.width*vid.height; for (i=0 ; isource!=-1;km++) if (ch == km->source) { Key_Event (km->dest, true, 0); return; } if (ch >= 'A' && ch <= 'Z') ch += 'a' - 'A'; if (ch>=256) return; Key_Event (ch, true, 0); } - (void)flagsChanged:(NSEvent *)theEvent { static int oldflags; int newflags; int delta; keymap_t *km; int i; // PSobscurecursor (); newflags = [theEvent modifierFlags]; delta = newflags ^ oldflags; for (i=0 ; i<32 ; i++) { if ( !(delta & (1<source!=-1;km++) if ( (1<source) { if (newflags & (1<dest, true, 0); else Key_Event (km->dest, false, 0); } } oldflags = newflags; } - (void)keyUp:(NSEvent *)theEvent { int ch; keymap_t *km; ch = [[theEvent charactersIgnoringModifiers] characterAtIndex:0]; // check for non-ascii first for (km=keymaps;km->source!=-1;km++) if (ch == km->source) { Key_Event (km->dest, false, 0); return; } if (ch >= 'A' && ch <= 'Z') ch += 'a' - 'A'; if (ch>=256) return; Key_Event (ch, false, 0); } @end