void apply_unseen_mask() { Rect base_rect = {9,9,53,45},to_rect,big_to = {13,13,337,265}; GrafPtr old_port; short i,j,k,l; ConstPatternParam c; bool need_bother = false; if (PSD[SDF_NO_FRILLS] > 0) return; if ((is_combat()) && (which_combat_type == 0)) return; if (!(is_out()) && (univ.town->lighting_type > 0)) return; for (i = 0; i < 11; i++) for (j = 0; j < 11; j++) if (unexplored_area[i + 1][j + 1] == 1) need_bother = true; if (need_bother == false) return; GetPort(&old_port); SetPort(terrain_screen_gworld); //p = *bw_pats[3]; //c = p; c = *bw_pats[3]; PenPat(c); PenMode(notPatOr); for (i = 0; i < 11; i++) for (j = 0; j < 11; j++) if (unexplored_area[i + 1][j + 1] == 1) { to_rect = base_rect; OffsetRect(&to_rect,-28 + i * 28,-36 + 36 * j); SectRect(&to_rect,&big_to,&to_rect); PaintRect(&to_rect); //PaintRoundRect(&to_rect,4,4); for (k = i - 2; k < i + 1; k++) for (l = j - 2; l < j + 1; l++) if ((k >= 0) && (l >= 0) && (k < 9) && (l < 9) && ((k != i - 1) || (l != j - 1))) terrain_there[k][l] = -1; } //p = *bw_pats[6]; //c = p; c = *bw_pats[6]; PenPat(c); PenMode(patCopy); SetPort(old_port); }
// New doMyDeviceLoop, now works with multiple monitors void doMyDeviceLoop() { int depth; Rect gDeviceRect; Rect intersectingRect; GDHandle gDevice; //WindowRecord *windowRec = (WindowRecord *)gWindow; WindowPtr windowRec = gWindow; Rect windowRect; //= (**windowRec->contRgn).rgnBBox; RgnHandle rgnHandle = NewRgn(); GetWindowRegion(windowRec, kWindowContentRgn, rgnHandle); GetRegionBounds(rgnHandle, &windowRect); // Get the handle to the first device in the list. gDevice = GetDeviceList(); // Loop through all the devices in the list. while (gDevice != nil) { // Get the device's gdRect */ gDeviceRect = (**gDevice).gdRect; depth = (**(**gDevice).gdPMap).pixelSize; // Check if the app's window rect intersects the device's, and if it // does, set the clip region's rect to the intersection, then DRAW! if (SectRect( &windowRect, &gDeviceRect, &intersectingRect )) { // The intersectingRect is in global coords. Convert to local GlobalToLocal((Point *)&intersectingRect.top); GlobalToLocal((Point *)&intersectingRect.bottom); ClipRect( &intersectingRect ); doDraw( depth, &intersectingRect ); } // Get the next device in the list. gDevice = GetNextDevice( gDevice ); } DisposeRgn(rgnHandle); }
BOOL AFXAPI AfxCheckMonochrome(const RECT* pRect) { long versionQD; if (Gestalt(gestaltQuickdrawVersion, &versionQD) != noErr || versionQD < gestalt8BitQD) return TRUE; // We draw all toolbars in monochrome if the main monitor is monochrome // because the main monitor is what determines the button face color // and button shadow color, and if those aren't grays, we won't get // reasonable output no matter how deep a monitor we're drawing on. if (GetSysColor(COLOR_BTNFACE) == RGB(255, 255, 255)) return TRUE; Rect rectMacClient; rectMacClient.top = (short)pRect->top; rectMacClient.left = (short)pRect->left; rectMacClient.bottom = (short)pRect->bottom; rectMacClient.right = (short)pRect->right; for (GDHandle hgd = GetDeviceList(); hgd != NULL; hgd = GetNextDevice(hgd)) { if (!TestDeviceAttribute(hgd, screenDevice) || !TestDeviceAttribute(hgd, screenActive)) continue; // ignore devices that the toolbar isn't drawn on Rect rect; if (!SectRect(&rectMacClient, &(*hgd)->gdRect, &rect)) continue; // we require 2-bit grayscale or 4-bit color to draw in color int pixelSize = (*(*hgd)->gdPMap)->pixelSize; if (pixelSize == 1 || (pixelSize == 2 && TestDeviceAttribute(hgd, gdDevType))) return TRUE; } return FALSE; }
/*
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; }
void do_explosion_anim(short sound_num,short special_draw) // sound_num currently ignored // special_draw - 0 normal 1 - first half 2 - second half { Rect temp_rect,active_area_rect,to_rect,from_rect; Rect base_rect = {0,0,36,28},text_rect; char str[60]; short i,temp_val,temp_val2; location screen_ul; short t,cur_boom_type = 0; Point current_terrain_ul; GWorldPtr temp_gworld; GrafPtr old_port; short boom_type_sound[3] = {5,10,53}; if ((have_boom == false) || (boom_anim_active == false)) { boom_anim_active = false; return; } for (i = 0; i < 30; i++) if (store_booms[i].boom_type >= 0) i = 50; if (i == 30) return; // initialize general data if (in_startup_mode) { current_terrain_ul.h = 306; current_terrain_ul.v = 5; } else current_terrain_ul.h = current_terrain_ul.v = 5; // make terrain_template contain current terrain all nicely draw_terrain(1); if (special_draw != 2) { GetPortBounds(terrain_screen_gworld,&to_rect); Rect oldRect = to_rect; OffsetRect(&to_rect,current_terrain_ul.h, current_terrain_ul.v); rect_draw_some_item(terrain_screen_gworld,oldRect,to_rect,ul); } GetPort(&old_port); // create and clip temporary anim template GetPortBounds(terrain_screen_gworld,&temp_rect); NewGWorld(&temp_gworld, 0 /*8*/,&temp_rect, NULL, NULL, kNativeEndianPixMap); SetPort(temp_gworld); TextFont(geneva_font_num); TextFace(bold); TextSize(10); active_area_rect = temp_rect; InsetRect(&active_area_rect,13,13); ClipRect(&active_area_rect); SetPort(GetWindowPort(mainPtr)); // init missile paths screen_ul.x = center.x - 4; screen_ul.y = center.y - 4; for (i = 0; i < 30; i++) if ((store_booms[i].boom_type >= 0) && (special_draw < 2)) { cur_boom_type = store_booms[i].boom_type; explode_place_rect[i] = base_rect; OffsetRect(&explode_place_rect[i],13 + 28 * (store_booms[i].dest.x - screen_ul.x) + store_booms[i].x_adj, 13 + 36 * (store_booms[i].dest.y - screen_ul.y) + store_booms[i].y_adj); if ((store_booms[i].place_type == 1) && (special_draw < 2)) { temp_val = get_ran(1,0,50) - 25; temp_val2 = get_ran(1,0,50) - 25; OffsetRect(&explode_place_rect[i],temp_val,temp_val2); } // eliminate stuff that's too gone. Rect tempRect2; GetPortBounds(terrain_screen_gworld,&tempRect2); SectRect(&explode_place_rect[i],&tempRect2,&temp_rect); if (EqualRect(&temp_rect,&explode_place_rect[i]) == false) { store_booms[i].boom_type = -1; } } else if (special_draw < 2) explode_place_rect[i].top =explode_place_rect[i].left =explode_place_rect[i].bottom =explode_place_rect[i].right = 0; //play_sound(-1 * sound_num); if (special_draw < 2) play_sound(-1 * boom_type_sound[cur_boom_type]); // Now, at last, do explosion for (t = (special_draw == 2) ? 6 : 0; t < ((special_draw == 1) ? 6 : 11); t++) { // t goes up to 10 to make sure screen gets cleaned up // First, lay terrain in temporary graphic area; for (i = 0; i < 30; i++) if (store_booms[i].boom_type >= 0) rect_draw_some_item(terrain_screen_gworld,explode_place_rect[i], temp_gworld,explode_place_rect[i]); // Now put in explosions for (i = 0; i < 30; i++) if (store_booms[i].boom_type >= 0) { if ((t + store_booms[i].offset >= 0) && (t + store_booms[i].offset <= 7)) { from_rect = base_rect; OffsetRect(&from_rect,28 * (t + store_booms[i].offset),36 * (1 + store_booms[i].boom_type)); rect_draw_some_item(boom_gworld,from_rect, temp_gworld,explode_place_rect[i],transparent); if (store_booms[i].val_to_place > 0) { text_rect = explode_place_rect[i]; text_rect.top += 4; text_rect.left -= 10; if (store_booms[i].val_to_place < 10) text_rect.left += 8; sprintf(str,"%d",store_booms[i].val_to_place); SetPort(temp_gworld); ForeColor(whiteColor); char_port_draw_string(temp_gworld,text_rect,str,1,12); ForeColor(blackColor); SetPort(GetWindowPort(mainPtr)); } } } // Now draw all missiles to screen for (i = 0; i < 30; i++) if (store_booms[i].boom_type >= 0) { to_rect = explode_place_rect[i]; OffsetRect(&to_rect,current_terrain_ul.h,current_terrain_ul.v); rect_draw_some_item(temp_gworld,explode_place_rect[i],to_rect,ul); } //if (((PSD[SDF_GAME_SPEED] == 1) && (t % 3 == 0)) || ((PSD[SDF_GAME_SPEED] == 2) && (t % 2 == 0))) FlushAndPause(2 * (1 + PSD[SDF_GAME_SPEED])); } // Exit gracefully, and clean up screen for (i = 0; i < 30; i++) if (special_draw != 1) store_booms[i].boom_type = -1; DisposeGWorld(temp_gworld); SetPort(old_port); //to_rect = terrain_screen_gworld->portRect; //OffsetRect(&to_rect,current_terrain_ul.h,current_terrain_ul.v); //rect_draw_some_item(terrain_screen_gworld,terrain_screen_gworld->portRect, // terrain_screen_gworld,to_rect,0,1); }
void do_missile_anim(short num_steps,location missile_origin,short sound_num) { Rect temp_rect,missile_origin_base = {1,1,17,17},active_area_rect,to_rect,from_rect; short i,store_missile_dir; Point start_point,finish_point[30]; location screen_ul; short x1[30],x2[30],y1[30],y2[30],t; // for path paramaterization Rect missile_place_rect[30],missile_origin_rect[30],store_erase_rect[30]; Point current_terrain_ul; GWorldPtr temp_gworld; GrafPtr old_port; if ((have_missile == false) || (boom_anim_active == false)) { boom_anim_active = false; return; } for (i = 0; i < 30; i++) if (store_missiles[i].missile_type >= 0) i = 50; if (i == 30) return; // initialize general data if (in_startup_mode) { current_terrain_ul.h = 306; current_terrain_ul.v = 5; } else current_terrain_ul.h = current_terrain_ul.v = 5; // make terrain_template contain current terrain all nicely draw_terrain(1); GetPortBounds(terrain_screen_gworld,&to_rect); Rect oldBounds = to_rect; OffsetRect(&to_rect,current_terrain_ul.h, current_terrain_ul.v); rect_draw_some_item(terrain_screen_gworld,oldBounds,to_rect,ul); GetPort(&old_port); // create and clip temporary anim template GetPortBounds(terrain_screen_gworld,&temp_rect); NewGWorld(&temp_gworld, 0 /*8*/,&temp_rect, NULL, NULL, kNativeEndianPixMap); SetPort(temp_gworld); active_area_rect = temp_rect; InsetRect(&active_area_rect,13,13); ClipRect(&active_area_rect); SetPort(GetWindowPort(mainPtr)); // init missile paths for (i = 0; i < 30; i++) { SetRect(&store_erase_rect[i],0,0,0,0); if ((store_missiles[i].missile_type >= 0) && (missile_origin == store_missiles[i].dest)) store_missiles[i].missile_type = -1; } screen_ul.x = center.x - 4; screen_ul.y = center.y - 4; start_point.h = 13 + 14 + 28 * (short) (missile_origin.x - screen_ul.x); start_point.v = 13 + 18 + 36 * (short) (missile_origin.y - screen_ul.y); for (i = 0; i < 30; i++) if (store_missiles[i].missile_type >= 0) { finish_point[i].h = 1 + 13 + 14 + store_missiles[i].x_adj + 28 * (short) (store_missiles[i].dest.x - screen_ul.x); finish_point[i].v = 1 + 13 + 18 + store_missiles[i].y_adj + 36 * (short) (store_missiles[i].dest.y - screen_ul.y); // note ... +1 at beginning is put in to prevent infinite slope if (store_missiles[i].missile_type < 7) { store_missile_dir = get_missile_direction(start_point,finish_point[i]); missile_origin_rect[i] = missile_origin_base; OffsetRect(&missile_origin_rect[i],18 * store_missile_dir,18 * store_missiles[i].missile_type); } else { missile_origin_rect[i] = missile_origin_base; OffsetRect(&missile_origin_rect[i],0,18 * store_missiles[i].missile_type); } // x1 slope x2 start pt x1[i] = finish_point[i].h - start_point.h; x2[i] = start_point.h; y1[i] = finish_point[i].v - start_point.v; y2[i] = start_point.v; } else missile_place_rect[i].top =missile_place_rect[i].left =missile_place_rect[i].bottom =missile_place_rect[i].right = 0; play_sound(-1 * sound_num); // Now, at last, launch missile for (t = 0; t < num_steps; t++) { for (i = 0; i < 30; i++) if (store_missiles[i].missile_type >= 0) { // Where place? temp_rect = missile_origin_base; OffsetRect(&temp_rect,-8 + x2[i] + (x1[i] * t) / num_steps, -8 + y2[i] + (y1[i] * t) / num_steps); // now adjust for different paths if (store_missiles[i].path_type == 1) OffsetRect(&temp_rect,0, -1 * (t * (num_steps - t)) / 100); SectRect(&temp_rect,&active_area_rect,&missile_place_rect[i]); // Now put terrain in temporary; rect_draw_some_item(terrain_screen_gworld,missile_place_rect[i], temp_gworld,missile_place_rect[i]); // Now put in missile from_rect = missile_origin_rect[i]; if (store_missiles[i].missile_type >= 7) OffsetRect(&from_rect,18 * (t % 8),0); rect_draw_some_item(missiles_gworld,from_rect, temp_gworld,temp_rect,transparent); } // Now draw all missiles to screen for (i = 0; i < 30; i++) if (store_missiles[i].missile_type >= 0) { to_rect = store_erase_rect[i]; OffsetRect(&to_rect,current_terrain_ul.h,current_terrain_ul.v); rect_draw_some_item(terrain_screen_gworld,store_erase_rect[i],to_rect,ul); to_rect = missile_place_rect[i]; store_erase_rect[i] = to_rect; OffsetRect(&to_rect,current_terrain_ul.h,current_terrain_ul.v); rect_draw_some_item(temp_gworld,missile_place_rect[i],to_rect,ul); } if ((PSD[SDF_GAME_SPEED] == 3) || ((PSD[SDF_GAME_SPEED] == 1) && (t % 4 == 0)) || ((PSD[SDF_GAME_SPEED] == 2) && (t % 3 == 0))) FlushAndPause(1); } // Exit gracefully, and clean up screen for (i = 0; i < 30; i++) store_missiles[i].missile_type = -1; DisposeGWorld(temp_gworld); SetPort(old_port); GetPortBounds(terrain_screen_gworld,&to_rect); Rect oldRect = to_rect; OffsetRect(&to_rect,current_terrain_ul.h,current_terrain_ul.v); rect_draw_some_item(terrain_screen_gworld,oldRect,to_rect,ul); }