📄 sdl_romvideo.c
字号:
tempRgn = NewRgn(); if ( ! tempRgn || ! drawRgn || ! gSaveGrayRgn ) { goto CLEANUP; } grayRgn = GetGrayRgn(); /* No need to check for this */ GetPort(&savePort); GetWMgrPort(&wMgrPort); /* Set the height properly */ LMSetMBarHeight(gSaveMenuBar); /* Restore the old GrayRgn: rounded corners, etc, but not the menubar -- subtract that out first! */ if (gSaveGrayRgn) { menuRect = (*GetMainDevice())->gdRect; menuRect.bottom = menuRect.top + gSaveMenuBar; RectRgn(menuRgn, &menuRect); DiffRgn(grayRgn, gSaveGrayRgn, drawRgn); /* What do we inval? */ DiffRgn(drawRgn, menuRgn, drawRgn); /* Clip out the menu */ /* Now redraw the corners and other bits black */ SetPort(wMgrPort); GetClip(tempRgn); SetClip(drawRgn); GetForeColor(&saveRGB); RGBForeColor(&blackRGB); PaintRgn(drawRgn); RGBForeColor(&saveRGB); SetClip(tempRgn); SetPort(savePort); UnionRgn(drawRgn, menuRgn, drawRgn); /* Put back the menu */ /* Now actually restore the GrayRgn */ CopyRgn(gSaveGrayRgn, grayRgn); DisposeRgn(gSaveGrayRgn); gSaveGrayRgn = nil; } /* Modify the vis regions of exposed windows and draw menubar */ window = (FrontWindow()) ? FrontWindow() : (WindowPtr) -1L; PaintBehind(window, drawRgn); CalcVisBehind(window, drawRgn); DrawMenuBar(); SetPort(savePort); gSaveMenuBar = 0; /* Now show the control strip if it's present */ if (!Gestalt(gestaltControlStripAttr, &response) && (response & (1L << gestaltControlStripExists))) { if (gSaveCSVis && !SBIsControlStripVisible()) SBShowHideControlStrip(true); gSaveCSVis = true; } /* Yield time so that floaters can catch up */ EventAvail(0, &theEvent); EventAvail(0, &theEvent); EventAvail(0, &theEvent); EventAvail(0, &theEvent); }CLEANUP: if (drawRgn) DisposeRgn(drawRgn); if (menuRgn) DisposeRgn(menuRgn); if (tempRgn) DisposeRgn(tempRgn);#endif /* !TARGET_API_MAC_CARBON */}/* Various screen update functions available */static void ROM_DirectUpdate(_THIS, int numrects, SDL_Rect *rects);static void ROM_WindowUpdate(_THIS, int numrects, SDL_Rect *rects);static void ROM_UnsetVideoMode(_THIS, SDL_Surface *current){ /* Free the current window, if any */ if ( SDL_Window != nil ) { GWorldPtr memworld; /* Handle OpenGL support */ Mac_GL_Quit(this); memworld = (GWorldPtr)GetWRefCon(SDL_Window); if ( memworld != nil ) { UnlockPixels(GetGWorldPixMap(memworld)); DisposeGWorld(memworld); } if ( (current->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {#if USE_QUICKTIME EndFullScreen(fullscreen_ctx, nil); SDL_Window = nil;#else ROM_ShowMenuBar(this);#endif } } current->pixels = NULL; current->flags &= ~(SDL_HWSURFACE|SDL_FULLSCREEN);}static SDL_Surface *ROM_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags){ Rect wrect, orect;#if TARGET_API_MAC_CARBON Rect tmprect;#endif /* Free any previous video mode */ ROM_UnsetVideoMode(this, current); /* Create the ROM window and SDL video surface */ current->flags = 0; /* Clear flags */ current->w = width; current->h = height; SetRect(&wrect, 0, 0, width, height); if ( SDL_Window ) { /* If we recreate the window, don't move it around */#if TARGET_API_MAC_CARBON orect = *GetWindowPortBounds(SDL_Window, &tmprect);#else orect = SDL_Window->portRect;#endif OffsetRect(&wrect, orect.left, orect.top); } else { /* Center the window the first time we show it */ OffsetRect(&wrect, (SDL_modelist[0]->w-width)/2, (SDL_modelist[0]->h-height)/2); }#if MACOSX && !USE_QUICKTIME /* Hum.. fullscreen mode is broken */ flags &= ~SDL_FULLSCREEN;#endif if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { /* Create the fullscreen window and use screen bits */ current->flags |= SDL_HWSURFACE|SDL_FULLSCREEN; if ( SDL_Window ) { DisposeWindow(SDL_Window); }#if USE_QUICKTIME BeginFullScreen(&fullscreen_ctx, nil, 0,0, &SDL_Window, nil, 0);#else SDL_Window = NewCWindow(nil, &wrect, "\p", true, plainDBox, (WindowPtr)-1, false, 0); ROM_HideMenuBar(this);#endif current->pitch = (**(**SDL_Display).gdPMap).rowBytes & 0x3FFF; current->pixels = (**(**SDL_Display).gdPMap).baseAddr; this->UpdateRects = ROM_DirectUpdate; } else { GWorldPtr memworld; PixMapHandle pixmap; int style; style = noGrowDocProc; if ( flags & SDL_NOFRAME ) { style = plainDBox; current->flags |= SDL_NOFRAME; } else if ( flags & SDL_RESIZABLE ) { style = zoomDocProc; current->flags |= SDL_RESIZABLE; } if ( SDL_Window && (style == current_style) ) { /* Resize existing window, if necessary */ if ( ((orect.right-orect.left) != width) || ((orect.bottom-orect.top) != height) ) { SizeWindow(SDL_Window, width, height, false); } } else { /* Recreate the window in the new style */ if ( SDL_Window ) { DisposeWindow(SDL_Window); } SDL_Window = NewCWindow(nil, &wrect, "\p", true, style, (WindowPtr)-1, true, 0); /* Set the window title, if any */ { char *title; SDL_WM_GetCaption(&title, NULL); if ( title ) { Mac_SetCaption(this, title, NULL); } } } current_style = style; SetPalette(SDL_Window, SDL_CPal, false); ActivatePalette(SDL_Window); if ( NewGWorld(&memworld, 0,#if TARGET_API_MAC_CARBON GetWindowPortBounds(SDL_Window, &tmprect),#else &SDL_Window->portRect,#endif SDL_CTab, nil, 0) != noErr ) { SDL_SetError("NewGWorld() failed"); return(NULL); } SetWRefCon(SDL_Window, (long)memworld); pixmap = GetGWorldPixMap(memworld); LockPixels(pixmap); current->pitch = (**pixmap).rowBytes & 0x3FFF; current->pixels = GetPixBaseAddr(pixmap); this->UpdateRects = ROM_WindowUpdate; } SetPortWindowPort(SDL_Window); SelectWindow(SDL_Window); /* Handle OpenGL support */ if ( flags & SDL_OPENGL ) { if ( Mac_GL_Init(this) == 0 ) { current->flags |= SDL_OPENGL; } else { current = NULL; } } if ( (flags & SDL_HWPALETTE) && (flags & SDL_FULLSCREEN) ) current->flags |= SDL_HWPALETTE; /* We're live! */ return(current);}/* We don't actually allow hardware surfaces other than the main one */static int ROM_AllocHWSurface(_THIS, SDL_Surface *surface){ return(-1);}static void ROM_FreeHWSurface(_THIS, SDL_Surface *surface){ return;}static int ROM_LockHWSurface(_THIS, SDL_Surface *surface){ return(0);}static void ROM_UnlockHWSurface(_THIS, SDL_Surface *surface){ return;}static void ROM_DirectUpdate(_THIS, int numrects, SDL_Rect *rects){ /* The application is already updating the visible video memory */ return;}static void ROM_WindowUpdate(_THIS, int numrects, SDL_Rect *rects){ GWorldPtr memworld; GrafPtr saveport; CGrafPtr thePort; const BitMap *memBits; const BitMap *winBits; int i; Rect update; /* Copy from the offscreen GWorld to the window port */ GetPort(&saveport); SetPortWindowPort(SDL_Window); thePort = GetWindowPort(SDL_Window); memworld = (GWorldPtr)GetWRefCon(SDL_Window);#if TARGET_API_MAC_CARBON memBits = GetPortBitMapForCopyBits((CGrafPtr) memworld);#else memBits = &((GrafPtr)memworld)->portBits;#endif#if TARGET_API_MAC_CARBON winBits = GetPortBitMapForCopyBits(thePort);#else winBits = &SDL_Window->portBits;#endif for ( i=0; i<numrects; ++i ) { update.left = rects[i].x; update.right = rects[i].x+rects[i].w; update.top = rects[i].y; update.bottom = rects[i].y+rects[i].h; CopyBits(memBits, winBits, &update, &update, srcCopy, nil); }#if TARGET_API_MAC_CARBON if ( QDIsPortBuffered(thePort) ) { QDFlushPortBuffer(thePort, NULL); }#endif SetPort(saveport);}static int ROM_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors){ CTabHandle cTab; int i; /* Get the colortable from the either the display or window */ if ( (this->screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { cTab = (**(**SDL_Display).gdPMap).pmTable; } else { cTab = SDL_CTab; } /* Verify the range of colors */ if ( (firstcolor+ncolors) > ((**cTab).ctSize+1) ) { return(0); } /* Set the screen palette and update the display */ for ( i=0; i< ncolors; ++i ) { int j = firstcolor + i; (**cTab).ctTable[j].value = j; (**cTab).ctTable[j].rgb.red = colors[i].r << 8 | colors[i].r; (**cTab).ctTable[j].rgb.green = colors[i].g << 8 | colors[i].g; (**cTab).ctTable[j].rgb.blue = colors[i].b << 8 | colors[i].b; }// if ( (this->screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { GDevice **odisplay; odisplay = GetGDevice(); SetGDevice(SDL_Display); SetEntries(0, (**cTab).ctSize, (ColorSpec *)&(**cTab).ctTable); SetGDevice(odisplay); } return(1);}void ROM_VideoQuit(_THIS){ int i; /* Free current video mode */ ROM_UnsetVideoMode(this, this->screen); if ( SDL_Window ) { DisposeWindow(SDL_Window); SDL_Window = nil; } /* Free palette and restore original one */ if ( SDL_CTab != nil ) { DisposeHandle((Handle)SDL_CTab); SDL_CTab = nil; } if ( SDL_CPal != nil ) { DisposePalette(SDL_CPal); SDL_CPal = nil; } RestoreDeviceClut(GetMainDevice()); /* Free list of video modes */ if ( SDL_modelist != NULL ) { for ( i=0; SDL_modelist[i]; ++i ) { free(SDL_modelist[i]); } free(SDL_modelist); SDL_modelist = NULL; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -