/*================================= SetPort Sets the current port, invalidates PowerPlant's LPane cache, sets the origin to 0,0, the GDevice to the main device, and the clip rect to the port rect. ==================================*/ void SUMiscUtils::SetPort( GrafPtr inPort ) { if ( inPort ) { if ( UQDGlobals::GetCurrentPort() != inPort ) ::SetPort( inPort ); // set the gdevice to the main device (if it isn't already) // the Window Mgr requires this when opening windows, etc GDHandle mainDevice = ::GetMainDevice(); if ( GetGDevice() != mainDevice ) ::SetGDevice( mainDevice ); ::SetOrigin( 0, 0 ); // since PP changes this all the time Rect theRect; #if PP_Target_Carbon ::GetPortBounds(inPort, &theRect); #else theRect = inPort->portRect; #endif ::ClipRect( &theRect ); // since PP changes this all the time // tell PP the port has changed since it caches it LView::OutOfFocus( nil ); } }
void gr_palette_step_up( int r, int g, int b ) { int i; ubyte *p; int temp; ColorSpec colors[256]; GDHandle old_device; // PaletteHandle palette; // RGBColor color; // CTabHandle ctab; if (gr_palette_faded_out) return; if ( (r==last_r) && (g==last_g) && (b==last_b) ) return; last_r = r; last_g = g; last_b = b; p=gr_palette; // palette = GetPalette(GameWindow); for (i=0; i<256; i++ ) { colors[i].value = i; // temp = (int)(*p++) + r + gr_palette_gamma; temp = (int)(*p++) + r; if (temp<0) temp=0; else if (temp>63) temp=63; colors[i].rgb.red = gr_mac_gamma[temp]; // temp = (int)(*p++) + g + gr_palette_gamma; temp = (int)(*p++) + g; if (temp<0) temp=0; else if (temp>63) temp=63; colors[i].rgb.green = gr_mac_gamma[temp]; // temp = (int)(*p++) + b + gr_palette_gamma; temp = (int)(*p++) + b; if (temp<0) temp=0; else if (temp>63) temp=63; colors[i].rgb.blue = gr_mac_gamma[temp]; // SetEntryColor(palette, i, &color); } old_device = GetGDevice(); SetGDevice(GameMonitor); SetEntries(0, 255, colors); SetGDevice(old_device); #if 0 ctab = (CTabHandle)NewHandle(sizeof(ColorTable)); Palette2CTab(palette, ctab); AnimatePalette(GameWindow, ctab, 0, 0, 256); ActivatePalette(GameWindow); DisposeHandle((Handle)ctab); if (GameGWorld != NULL) { ctab = (**GetGWorldPixMap(GameGWorld)).pmTable; // get the color table for the gWorld. CTabChanged(ctab); (**ctab).ctSeed = (**(**(*(CGrafPtr)GameWindow).portPixMap).pmTable).ctSeed; } #endif }
void gr_palette_load( ubyte *pal ) { int i, j; GDHandle old_device; ColorSpec colors[256]; // PaletteHandle palette; // RGBColor color; // CTabHandle ctable; for (i=0; i<768; i++ ) { // gr_current_pal[i] = pal[i] + gr_palette_gamma; gr_current_pal[i] = pal[i]; if (gr_current_pal[i] > 63) gr_current_pal[i] = 63; } for (i = 0, j = 0; j < 256; j++) { colors[j].value = j; colors[j].rgb.red = gr_mac_gamma[gr_current_pal[i++]]; colors[j].rgb.green = gr_mac_gamma[gr_current_pal[i++]]; colors[j].rgb.blue = gr_mac_gamma[gr_current_pal[i++]]; } old_device = GetGDevice(); SetGDevice(GameMonitor); SetEntries(0, 255, colors); SetGDevice(old_device); #if 0 palette = GetPalette(GameWindow); for (i = 0; i < 768; i += 3) { color.red = gr_current_pal[i] << 9; color.green = gr_current_pal[i+1] << 9; color.blue = gr_current_pal[i+2] << 9; SetEntryColor(palette, i / 3, &color); } ctable = (CTabHandle)NewHandle(sizeof(ColorTable)); Palette2CTab(palette, ctable); AnimatePalette(GameWindow, ctable, 0, 0, 256); ActivatePalette(GameWindow); DisposeHandle((Handle)ctable); if (GameGWorld != NULL) { ctable = (**GetGWorldPixMap(GameGWorld)).pmTable; // get the color table for the gWorld. CTabChanged(ctable); (**ctable).ctSeed = (**(**(*(CGrafPtr)GameWindow).portPixMap).pmTable).ctSeed; } #endif gr_palette_faded_out = 0; init_computed_colors(); }
void gr_palette_clear() { int i; ColorSpec colors[256]; GDHandle old_device; // PaletteHandle palette; // RGBColor color; // CTabHandle ctable; for (i = 0; i < 256; i++) { colors[i].value = i; colors[i].rgb.red = 0; colors[i].rgb.green = 0; colors[i].rgb.blue = 0; } old_device = GetGDevice(); SetGDevice(GameMonitor); SetEntries(0, 255, colors); SetGDevice(old_device); #if 0 palette = GetPalette(GameWindow); for (i=0; i<256; i++) { color.red = 0x0; color.green = 0x0; color.blue = 0x0; SetEntryColor(palette, i, &color); } ctable = (CTabHandle)NewHandle(sizeof(ColorTable)); Palette2CTab(palette, ctable); AnimatePalette(GameWindow, ctable, 0, 0, 256); ActivatePalette(GameWindow); DisposeHandle((Handle)ctable); // make the seeds match for the gworld clut and the window palette. I don't know if // this is necessary, but it doesn't hurt. if (GameGWorld != NULL) { ctable = (**GetGWorldPixMap(GameGWorld)).pmTable; CTabChanged(ctable); (**ctable).ctSeed = (**(**(*(CGrafPtr)GameWindow).portPixMap).pmTable).ctSeed; } #endif gr_palette_faded_out = 1; }
void reset_debug_video_mode() { ColorSpec color[2]; GDHandle old_device; color[0].value = 255; color[0].rgb.red = 0xffff; color[0].rgb.blue = 0xffff; color[0].rgb.green = 0xffff; color[1].value = 0; color[1].rgb.red = 0x0; color[1].rgb.blue = 0x0; color[1].rgb.green = 0x0; SetGDevice(GameMonitor); old_device = GetGDevice(); SetEntries(-1, 1, color); SetGDevice(old_device); gr_debug_mode = 0; }
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 0 if ( (this->screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) #endif { GDevice **odisplay; odisplay = GetGDevice(); SetGDevice(SDL_Display); SetEntries(0, (**cTab).ctSize, (ColorSpec *)&(**cTab).ctTable); SetGDevice(odisplay); } return(1); }
/* ---------------------------------------------------------------------------- tbitStartup Initialize TPS off-screen bitmap subsystem at startup. Returns error code indicating success. ---------------------------------------------------------------------------- */ TPSAPI_DECLP( BOOLEAN ) tbitStartup (uWORD NrPorts, uWORD depth, HNATIVE hColor) { sWORD i; Rect Bounds; OSErr osError = noErr; SignedByte saveState; PixMapHandle hPixMap = nil; // handle to new off-screen PixMap short bytesPerRow; // bytes per row in PixMap fHasColorQuickdraw = tsysMacHasCQD(true); /** validations/initializations **/ TpsAssert((_TPorts == nil), "Bitmap subsystem was already been started up!"); TpsAssert((hColor != nil), "Bitmap subsystem color table must be provided!"); TpsAssert(tsysMacHasSys7(), "System 7 or greater required!"); TpsAssert(fHasColorQuickdraw, "32Bit Color QuickDraw required!"); TpsAssert(tsysMacHasGWorlds(), "QuickDraw Color GWorlds required!"); GetPort(&_pStartupPort); _hStartupDevice = GetGDevice(); /** clone the clut (to be used throughout) **/ saveState = HGetState((Handle)hColor); // save color tableÕs current state HNoPurge((Handle)hColor); // make sure it isnÕt purgeable _hColorTable = (CTabHandle)hColor; osError = HandToHand((Handle *)&_hColorTable); HSetState((Handle)hColor, saveState); // restore color tableÕs state if (osError != noErr) { // terrSetErrorCode(TERR_TMEMSECTION, TMEM_ERRALLOC); return FALSE; } /** create device (to be used throughout) **/ //SetRect(&Bounds, 0, 0, 1, 1); Bounds.left = 0; Bounds.top = 0; Bounds.right = 1; Bounds.bottom = 1; bytesPerRow = 16; // 16 byte align rowbytes if ((hPixMap = (PixMapHandle)NewHandleClear(sizeof(PixMap))) == nil) goto Failure; if (_SetUpPixMap(depth, &Bounds, _hColorTable, bytesPerRow, hPixMap) != noErr) goto Failure; if ((_hTBitDevice = (GDHandle)NewHandleClear(sizeof(GDevice))) == nil) goto Failure; if (_CreateGDevice(hPixMap, _hTBitDevice) != noErr) goto Failure; /** create internal port list **/ if ((_TPorts = (TBitPort *)NewPtrClear(sizeof(TBitPort) * (NrPorts + 1))) == nil) goto Failure; /** create pool of off-screen ports **/ //SetRect(&Bounds, 0, 0, 1, 1); Bounds.left = 0; Bounds.top = 0; Bounds.right = 1; Bounds.bottom = 1; for (i = 0; i < NrPorts; i++) { if ((_TPorts[i].pPort = (CGrafPtr)NewPtrClear(sizeof(CGrafPort))) == nil) goto Failure; OpenCPort(_TPorts[i].pPort); _TPorts[i].hOldPixMap = (_TPorts[i].pPort)->portPixMap; SetPortPix(nil); } /** clean up and out **/ SetPort(_pStartupPort); SetGDevice(_hStartupDevice); _NrTPorts = NrPorts; return TRUE; Failure: if (hPixMap != nil) { if ((**hPixMap).pmTable != nil) DisposCTable((**hPixMap).pmTable); if ((**hPixMap).baseAddr != nil) DisposHandle((Handle)(**hPixMap).baseAddr); DisposHandle((Handle)hPixMap); } if (_hTBitDevice != nil) { if ((**_hTBitDevice).gdITable != nil) DisposHandle((Handle)(**_hTBitDevice).gdITable); DisposHandle((Handle)_hTBitDevice); _hTBitDevice = nil; } if (_TPorts != nil) { for (i = 0; i < NrPorts; i++) { if (_TPorts[i].pPort != nil) { SetPort((GrafPtr)_TPorts[i].pPort); SetPortPix(_TPorts[i].hOldPixMap); CloseCPort(_TPorts[i].pPort); } } tmemFreeNativePtr(_TPorts); _TPorts = nil; } if (_hColorTable != nil) DisposCTable(_hColorTable); SetGDevice(_hStartupDevice); SetPort(_pStartupPort); // terrSetErrorCode(TERR_TMEMSECTION, TMEM_ERRALLOC); return FALSE; }
int gr_palette_fade_in(ubyte *pal, int nsteps, int allow_keys) { int i,j, k; ubyte c; fix fade_palette[768]; fix fade_palette_delta[768]; ColorSpec colors[256]; GDHandle old_device; // PaletteHandle palette; // RGBColor color; // CTabHandle ctable; allow_keys = allow_keys; if (!gr_palette_faded_out) return 0; // palette = GetPalette(GameWindow); for (i=0; i<768; i++ ) { gr_current_pal[i] = pal[i]; fade_palette[i] = 0; fade_palette_delta[i] = i2f(pal[i]) / nsteps; } for (j=0; j<nsteps; j++ ) { for (i=0, k = 0; k<256; k++ ) { colors[k].value = k; fade_palette[i] += fade_palette_delta[i]; if (fade_palette[i] > i2f(pal[i]) ) fade_palette[i] = i2f(pal[i]); // c = f2i(fade_palette[i])+gr_palette_gamma; c = f2i(fade_palette[i]); if (c > 63) c = 63; colors[k].rgb.red = gr_mac_gamma[c]; i++; fade_palette[i] += fade_palette_delta[i]; if (fade_palette[i] > i2f(pal[i]) ) fade_palette[i] = i2f(pal[i]); // c = f2i(fade_palette[i])+gr_palette_gamma; c = f2i(fade_palette[i]); if (c > 63) c = 63; colors[k].rgb.green = gr_mac_gamma[c]; i++; fade_palette[i] += fade_palette_delta[i]; if (fade_palette[i] > i2f(pal[i]) ) fade_palette[i] = i2f(pal[i]); // c = f2i(fade_palette[i])+gr_palette_gamma; c = f2i(fade_palette[i]); if (c > 63) c = 63; colors[k].rgb.blue = gr_mac_gamma[c]; i++; } old_device = GetGDevice(); SetGDevice(GameMonitor); SetEntries(0, 255, colors); SetGDevice(old_device); } #if 0 for (i=0; i<768; i++ ) { gr_current_pal[i] = pal[i]; fade_palette[i] = 0; fade_palette_delta[i] = i2f(pal[i]) / nsteps; } for (j=0; j<nsteps; j++ ) { for (i=0; i<768; ) { fade_palette[i] += fade_palette_delta[i]; if (fade_palette[i] > i2f(pal[i]) ) fade_palette[i] = i2f(pal[i]); c = f2i(fade_palette[i])+gr_palette_gamma; if (c > 63) c = 63; color.red = c << 9; i++; fade_palette[i] += fade_palette_delta[i]; if (fade_palette[i] > i2f(pal[i]) ) fade_palette[i] = i2f(pal[i]); c = f2i(fade_palette[i])+gr_palette_gamma; if (c > 63) c = 63; color.green = c << 9; i++; fade_palette[i] += fade_palette_delta[i]; if (fade_palette[i] > i2f(pal[i]) ) fade_palette[i] = i2f(pal[i]); c = f2i(fade_palette[i])+gr_palette_gamma; if (c > 63) c = 63; color.blue = c << 9; i++; SetEntryColor(palette, (i / 3) - 1, &color); } ctable = (CTabHandle)NewHandle(sizeof(ColorTable)); Palette2CTab(palette, ctable); AnimatePalette(GameWindow, ctable, 0, 0, 256); ActivatePalette(GameWindow); DisposeHandle((Handle)ctable); } #endif gr_palette_faded_out = 0; return 0; }
static void SaveToHDF (char *name) { CGrafPtr theCGrafPort; WindowPtr theWindow; PixMapPtr thePixMap; char buffer[80]; GDHandle gd; GDPtr theGDevice; unsigned char *theImage,*srcPtr,*dstPtr,*baseAddr; Rect screen,window; unsigned long size; int rowBytes,row,col,i,j; PaletteHandle thePalette; unsigned char transTable[256],hdfPalette[768]; RGBColor theColor; theWindow = myWindow.theWindow; theCGrafPort = (CGrafPtr) theWindow; gd = (GDHandle) GetGDevice(); theGDevice = *gd; /* check frontwindow */ if (theWindow!=FrontWindow()) { OneButtonBox("window to save must be the front window","OK"); return; } /* check screen depth and mode */ thePixMap = *(theGDevice->gdPMap); rowBytes = thePixMap->rowBytes&0x1FFF; baseAddr = (unsigned char *) thePixMap->baseAddr; if ((thePixMap->pixelType!=0)||(thePixMap->pixelSize!=8)) { OneButtonBox("Sorry, 8 bits/pixel and chunky mode required","OK"); return; } /* compute window contents coordinates */ thePixMap = *(theGDevice->gdPMap); SetRect(&screen,thePixMap->bounds.left,thePixMap->bounds.top,thePixMap->bounds.right,thePixMap->bounds.bottom); thePixMap = *(theCGrafPort->portPixMap); SetRect(&window,-thePixMap->bounds.left,-thePixMap->bounds.top,theCGrafPort->portRect.right-16-thePixMap->bounds.left,theCGrafPort->portRect.bottom-16-thePixMap->bounds.top); SectRect(&window,&screen,&window); /* allocate image buffer */ size = ((unsigned long)(window.right-window.left))*((unsigned long)(window.bottom-window.top)); theImage = (unsigned char *) malloc(size); if (theImage==NULL) { OneButtonBox("Sorry, not enough memory for image buffer","OK"); return; } /* create translation table and palette */ thePalette = GetPalette(theWindow); for (i=0; i<256; i++) { GetEntryColor(thePalette,i,&theColor); hdfPalette[i*3] = (theColor.red)>>8; hdfPalette[i*3+1] = (theColor.green)>>8; hdfPalette[i*3+2] = (theColor.blue)>>8; j = Color2Index(&theColor); transTable[j] = (unsigned char) i; } /* copy image */ dstPtr = theImage; for (row=window.top; row<window.bottom; row++) { srcPtr = baseAddr+row*rowBytes+window.left; for (col=window.left; col<window.right; col++) *(dstPtr++) = transTable[*(srcPtr++)]; } /* set palette for subsequent image */ if (DFR8setpalette(hdfPalette)) OneButtonBox("setpalette failed","OK"); /* write image to disk */ if(DFR8putimage(name,theImage,window.right-window.left,window.bottom-window.top,DFTAG_RLE)) { free(theImage); OneButtonBox("Image not written correctly","OK"); return; } /* free memory */ free(theImage); return; }
bool MCImageBitmapToPICT(MCImageBitmap *p_bitmap, MCMacSysPictHandle &r_pict) { #ifdef LIBGRAPHICS_BROKEN bool t_success = true; Pixmap drawdata = nil, drawmask = nil; MCBitmap *maskimagealpha = nil; t_success = MCImageSplitPixmaps(p_bitmap, drawdata, drawmask, maskimagealpha); if (!t_success) return false; Rect t_rect; SetRect(&t_rect, 0, 0, p_bitmap->width, p_bitmap->height); GWorldPtr t_old_gworld; GDHandle t_old_gdevice; GetGWorld(&t_old_gworld, &t_old_gdevice); PixMapHandle t_draw_pixmap; t_draw_pixmap = GetGWorldPixMap((CGrafPtr)drawdata -> handle . pixmap); GWorldPtr t_img_gworld; t_img_gworld = NULL; if (t_success) { QDErr t_err; t_err = NewGWorld(&t_img_gworld, 32, &t_rect, NULL, NULL, 0); if (t_err != noErr) t_success = false; } if (t_success) { SetGWorld(t_img_gworld, GetGDevice()); PenMode(srcCopy); ForeColor(blackColor); BackColor(whiteColor); if (maskimagealpha != NULL) { GWorldPtr t_alpha_gworld; if (NewGWorldFromPtr(&t_alpha_gworld, 8, &t_rect, GetCTable(40), NULL, 0, maskimagealpha -> data, maskimagealpha -> bytes_per_line) == noErr) { const BitMap *t_dst_bits; t_dst_bits = GetPortBitMapForCopyBits(t_img_gworld); const BitMap *t_src_bits; t_src_bits = GetPortBitMapForCopyBits((CGrafPtr)drawdata -> handle . pixmap); const BitMap *t_mask_bits; t_mask_bits = GetPortBitMapForCopyBits(t_alpha_gworld); EraseRect(&t_rect); CopyDeepMask(t_src_bits, t_mask_bits, t_dst_bits, &t_rect, &t_rect, &t_rect, srcCopy, NULL); } } else if (drawmask != NULL) { PixMapHandle t_mask_pixmap; t_mask_pixmap = GetGWorldPixMap((CGrafPtr)drawmask -> handle . pixmap); EraseRect(&t_rect); const BitMap *t_dst_bits; t_dst_bits = GetPortBitMapForCopyBits(t_img_gworld); const BitMap *t_src_bits; LockPixels(t_draw_pixmap); t_src_bits = (BitMap *)*t_draw_pixmap; const BitMap *t_mask_bits; LockPixels(t_mask_pixmap); t_mask_bits = (BitMap *)*t_mask_pixmap; CopyMask(t_src_bits, t_mask_bits, t_dst_bits, &t_rect, &t_rect, &t_rect); UnlockPixels(t_mask_pixmap); UnlockPixels(t_draw_pixmap); } else { const BitMap *t_dst_bits; t_dst_bits = GetPortBitMapForCopyBits(t_img_gworld); const BitMap *t_src_bits; LockPixels(t_draw_pixmap); t_src_bits = (BitMap *)*t_draw_pixmap; CopyBits(t_src_bits, t_dst_bits, &t_rect, &t_rect, srcCopy, NULL); UnlockPixels(t_draw_pixmap); } } PicHandle t_handle; t_handle = NULL; if (t_success) { OpenCPicParams t_params; t_params . srcRect = t_rect; t_params . hRes = 72 << 16; t_params . vRes = 72 << 16; t_params . version = -2; t_params . reserved1 = 0; t_params . reserved2 = 0; t_handle = OpenCPicture(&t_params); if (t_handle == NULL) t_success = false; } if (t_success) { GWorldPtr t_pict_gworld; GDHandle t_pict_gdevice; GetGWorld(&t_pict_gworld, &t_pict_gdevice); PenMode(srcCopy); ForeColor(blackColor); BackColor(whiteColor); const BitMap *t_dst_bits; t_dst_bits = GetPortBitMapForCopyBits(t_pict_gworld); const BitMap *t_src_bits; t_src_bits = GetPortBitMapForCopyBits(t_img_gworld); CopyBits(t_src_bits, t_dst_bits, &t_rect, &t_rect, srcCopy, NULL); ClosePicture(); } if (t_img_gworld != NULL) DisposeGWorld(t_img_gworld); SetGWorld(t_old_gworld, t_old_gdevice); MCscreen->freepixmap(drawdata); MCscreen->freepixmap(drawmask); if (maskimagealpha != nil) MCscreen->destroyimage(maskimagealpha); if (t_success) r_pict = (MCMacSysPictHandle)t_handle; return t_success; #else return false; #endif }
int #ifdef ACTIVEGS macmain #else main #endif (int argc, char* argv[]) { ProcessSerialNumber my_psn; IBNibRef nibRef; EventHandlerUPP handlerUPP; EventTypeSpec cmd_event[3]; GDHandle g_gdhandle; Rect win_rect; OSStatus err; char *argptr; int slash_cnt; int i; #ifndef ACTIVEGS /* Prepare argv0 */ slash_cnt = 0; argptr = argv[0]; for(i = strlen(argptr); i >= 0; i--) { if(argptr[i] == '/') { slash_cnt++; if(slash_cnt == 3) { strncpy(&(g_argv0_path[0]), argptr, i); g_argv0_path[i] = 0; } } } printf("g_argv0_path is %s\n", g_argv0_path); g_mac_argv[0] = argv[0]; g_mac_argc = 1; i = 1; while((i < argc) && (g_mac_argc < MAX_MAC_ARGS)) { if(!strncmp(argv[i], "-psn", 4)) { /* skip this argument */ } else { g_mac_argv[g_mac_argc++] = argv[i]; } i++; } #endif InitCursor(); g_event_rgnhandle = NewRgn(); g_status_font_family = FMGetFontFamilyFromName("\pCourier"); SetRect(&win_rect, 0, 0, X_A2_WINDOW_WIDTH, X_A2_WINDOW_HEIGHT // OG Remove status line from ActiveGS window #ifndef ACTIVEGS + MAX_STATUS_LINES*16 + 8 #endif ); OffsetRect(&win_rect, 64, 50); // Create a Nib reference passing the name of the nib file // CreateNibReference only searches into the application bundle. err = CreateNibReference(CFSTR("main"), &nibRef); require_noerr( err, CantGetNibRef ); // Once the nib reference is created, set the menu bar. err = SetMenuBarFromNib(nibRef, CFSTR("MenuBar")); require_noerr( err, CantSetMenuBar ); #ifndef ACTIVEGS err = CreateNewWindow(kDocumentWindowClass, kWindowStandardDocumentAttributes | kWindowStandardHandlerAttribute, &win_rect, &g_main_window); err = SetWindowTitleWithCFString(g_main_window, CFSTR("GSport")); #else err = CreateNewWindow(kDocumentWindowClass, (kWindowCloseBoxAttribute /*| kWindowFullZoomAttribute */| kWindowCollapseBoxAttribute /*| kWindowResizableAttribute*/) /*kWindowStandardDocumentAttributes*/ | kWindowStandardHandlerAttribute, &win_rect, &g_main_window); extern CFStringRef activeGSversionSTR; err = SetWindowTitleWithCFString(g_main_window, activeGSversionSTR); #endif //printf("CreateNewWindow ret: %d, g_main_window: %p\n", (int)err, g_main_window); // We don't need the nib reference anymore. DisposeNibReference(nibRef); SysBeep(120); handlerUPP = NewEventHandlerUPP( my_cmd_handler ); cmd_event[0].eventClass = kEventClassCommand; cmd_event[0].eventKind = kEventProcessCommand; InstallWindowEventHandler(g_main_window, handlerUPP, 1, &cmd_event[0], (void *)g_main_window, NULL); handlerUPP = NewEventHandlerUPP(my_win_handler); cmd_event[0].eventClass = kEventClassWindow; cmd_event[0].eventKind = kEventWindowDrawContent; cmd_event[1].eventClass = kEventClassWindow; cmd_event[1].eventKind = kEventWindowUpdate; cmd_event[2].eventClass = kEventClassWindow; cmd_event[2].eventKind = kEventWindowClose; err = InstallWindowEventHandler(g_main_window, handlerUPP, 3, &cmd_event[0], (void *)g_main_window, NULL); require_noerr(err, CantCreateWindow); // Get screen depth g_gdhandle = GetGDevice(); g_screen_mdepth = (**((**g_gdhandle).gdPMap)).pixelSize; g_screen_depth = g_screen_mdepth; if(g_screen_depth > 16) { /* 32-bit display */ g_red_mask = 0xff; g_green_mask = 0xff; g_blue_mask = 0xff; /* if (macUsingCoreGraphics) { g_red_left_shift = 0; g_green_left_shift = 8; g_blue_left_shift = 16; } else */ { g_red_left_shift = 16; g_green_left_shift = 8; g_blue_left_shift = 0; } g_red_right_shift = 0; g_green_right_shift = 0; g_blue_right_shift = 0; } else if(g_screen_depth > 8) { /* 16-bit display */ g_red_mask = 0x1f; g_green_mask = 0x1f; g_blue_mask = 0x1f; g_red_left_shift = 10; g_green_left_shift = 5; g_blue_left_shift = 0; g_red_right_shift = 3; g_green_right_shift = 3; g_blue_right_shift = 3; } // show_alert("About to show window", (int)g_main_window); update_main_window_size(); update_window(); // The window was created hidden so show it. ShowWindow( g_main_window ); BringToFront( g_main_window ); update_window(); // Make us pop to the front a different way err = GetCurrentProcess(&my_psn); if(err == noErr) { (void)SetFrontProcess(&my_psn); } // Call the event loop temp_run_application_event_loop(); CantCreateWindow: CantSetMenuBar: CantGetNibRef: show_simple_alert("ending", "", "error code", err); return err; }