// manages changes in size VOID WndResize( const HWND hwnd ) { wcprintf("WndResize"); RECTL rWindow; LONG cyHeight, cxWidth; BITMAPINFOHEADER bmp; if( (hbmGlob = GpiSetBitmap( hpsBufferGlob, NULLHANDLE )) != NULLHANDLE ){ wcprintf("wndresize: there was an old bitmap"); GpiDeleteBitmap( hbmGlob ); // delete old stuff } else wcprintf("wndresize: there was no old bitmap"); // build the bitmap: WinQueryWindowRect( hwnd, &rWindow ); cxWidth = rWindow.xRight - rWindow.xLeft;// - 2; cyHeight = rWindow.yTop - rWindow.yBottom; // - 2; wcprintf("wndResize: Breite: %d, H”he: %d", rWindow.xRight, rWindow.yTop ); memset(&bmp, 0, sizeof(BITMAPINFOHEADER)); bmp.cbFix = sizeof(BITMAPINFOHEADER); bmp.cx = (SHORT)cxWidth; bmp.cy = (SHORT)cyHeight; bmp.cPlanes = (SHORT)cColorPlanes; bmp.cBitCount = (SHORT)cColorBitCount; hbmGlob = GpiCreateBitmap(hpsBufferGlob, (PBITMAPINFOHEADER2)&bmp, 0L, NULL, NULL); if( hbmGlob == GPI_ERROR ) DosBeep( 100, 500); GpiSetBitmap( hpsBufferGlob, hbmGlob); // calculate the size // if( !GpiSetPageViewport(hpsGlob, &rWindow) ) // wcprintf("error 1"); return; if( !GpiSetPageViewport(hpsBufferGlob, &rWindow) ) wcprintf("error 2"); }
/****************************************************************\ * *-------------------------------------------------------------- * * Name: ClkSize() * * Purpose:When the window has been sized, we calculate a page * rectangle which: (a) fills the window rectangle in either * the x or y dimension, (b) appears square, and (c) is centered * in the window rectangle * Usage: * * Method: * - * * - * - * * - * - * * Returns: * * \****************************************************************/ VOID ClkSize (HWND hwnd) { RECTL rclWindow; SIZEF sizef; LONG cxSquare, cySquare, cxEdge, cyEdge; LONG cyHeight; LONG cxWidth; HBITMAP hbm; BITMAPINFOHEADER bmp; /* * First get rid of any buffer bitmap already there. */ hbm = GpiSetBitmap (hpsBuffer, NULLHANDLE); if (hbm != NULLHANDLE) GpiDeleteBitmap (hbm); /* * Get the width and height of the window rectangle. */ WinQueryWindowRect (hwnd, &rclWindow); cxWidth = rclWindow.xRight - rclWindow.xLeft - 2; cyHeight = rclWindow.yTop - rclWindow.yBottom - 2; /* * Now create a bitmap the size of the window. */ bmp.cbFix = sizeof(BITMAPINFOHEADER); bmp.cx = (SHORT)cxWidth; bmp.cy = (SHORT)cyHeight; bmp.cPlanes = (SHORT)cColorPlanes; bmp.cBitCount = (SHORT)cColorBitcount; hbm = GpiCreateBitmap(hpsBuffer, (PBITMAPINFOHEADER2)&bmp, 0x0000, (PBYTE)NULL, (PBITMAPINFO2)NULL); GpiSetBitmap (hpsBuffer, hbm); /* * Assume the size of the page rectangle is constrained in the y * dimension,compute the x size which would make the rectangle appear * square, then check the assumption and do the reverse calculation * if necessary. */ cySquare = cyHeight - 2; cxSquare = ( cyHeight * cxRes ) / cyRes; if (cxWidth < cxSquare) { cxSquare = cxWidth - 2; cySquare = (cxWidth * cyRes) / cxRes; } /* * Fill in the page rectangle and set the page viewport. */ cxEdge = (cxWidth - cxSquare ) / 2; cyEdge = (cyHeight - cySquare ) / 2; rclPage.xLeft = cxEdge; rclPage.xRight = cxWidth - cxEdge; rclPage.yBottom = cyEdge; rclPage.yTop = cyHeight - cyEdge; /* * Determine where to put the date. If we have room under the clock, we * put it there. If we have more room on the left we put it there. If we * have more room in the midlle, it goes there. */ if (cp.usDispMode & DM_DATE) { vclrDate[SURFACE] = vclrBG[SHADE]; vclrDate[LIGHT] = vclrBG[LIGHT]; vclrDate[SHADE] = vclrBG[SHADE]; vclrDate[BACKGROUND] = vclrBG[SURFACE]; if (cyHeight > (cySquare*6/5)) { /*Goes under*/ vmatlfDateTrans.lM31 = (LONG)15; /*Horizontal*/ vmatlfDateTrans.lM32 = -(LONG)17; /*vertical*/ vmatlfDateScale.fxM11 = MAKEFIXED(2,0x8000); vmatlfDateScale.fxM22 = MAKEFIXED(2,0x8000); rclPage. yTop += cyEdge; rclPage. yBottom += cyEdge; vusDatePos = DP_UNDER; } else { if (cxWidth > (cxSquare * 31/10 )) { vmatlfDateTrans.lM31 = -(LONG)53 ; /*Horizontal*/ vmatlfDateTrans.lM32 = (LONG)04; /*vertical*/ vmatlfDateScale.fxM11 = MAKEFIXED(7,0xe000); vmatlfDateScale.fxM22 = MAKEFIXED(7,0xe000); rclPage.xRight += cxEdge; rclPage.xLeft += cxEdge; vusDatePos = DP_LEFTMIDDLE; } else { if (cxWidth > (cxSquare * 2)) { /*Goes on the left*/ vmatlfDateTrans.lM31 = -(LONG)52 ; /*Horizontal*/ vmatlfDateTrans.lM32 = (LONG)2; /*vertical*/ vmatlfDateScale.fxM11 = MAKEFIXED(3,0xd000); vmatlfDateScale.fxM22 = MAKEFIXED(3,0xd000); rclPage.xRight += cxEdge; rclPage.xLeft += cxEdge; vusDatePos = DP_LEFTDOWN ; } else { /*Goes inside*/ vmatlfDateTrans.lM31 = (LONG)24 ; /*Horizontal*/ vmatlfDateTrans.lM32 = (LONG)23; /*vertical*/ vmatlfDateScale.fxM11 = MAKEFIXED(2,0); vmatlfDateScale.fxM22 = MAKEFIXED(2,0); vclrDate[SURFACE] = vclrFace[SHADE] ; vclrDate[LIGHT] = vclrFace[LIGHT] ; vclrDate[SHADE] = vclrFace[SHADE]; vclrDate[BACKGROUND] = vclrFace[SURFACE]; vusDatePos = DP_INSIDE; } } } } f = GpiSetPageViewport (hps, &rclPage); f = GpiSetPageViewport (hpsBuffer, &rclPage); /* * Are we iconic? */ f = WinQueryWindowPos (hwndFrame, &swp); fIconic = (BOOL)(swp.fl & SWP_MINIMIZE ); fShowSecondHand = (BOOL) !(fIconic); GpiQueryCharBox(hpsBuffer, &sizef); GpiSetCharBox(hpsBuffer, &sizef); fBufferDirty = TRUE; }
/****************************************************************\ * Name: ClkSize() * * Purpose:When the window has been sized, we calculate a page * rectangle which: (a) fills the window rectangle in either * the x or y dimension, (b) appears square, and (c) is centered * in the window rectangle \****************************************************************/ VOID ClkSize (HWND hwnd) { RECTL rclWindow; SIZEF sizef; LONG cxSquare, cySquare, cxEdge, cyEdge; LONG cyHeight; LONG cxWidth; HBITMAP hbm; BITMAPINFOHEADER bmp; /* * First get rid of any buffer bitmap already there. */ hbm = GpiSetBitmap (hpsBuffer, NULLHANDLE); if (hbm != NULLHANDLE) GpiDeleteBitmap (hbm); /* * Get the width and height of the window rectangle. */ WinQueryWindowRect (hwnd, &rclWindow); cxWidth = rclWindow.xRight - rclWindow.xLeft - 2; cyHeight = rclWindow.yTop - rclWindow.yBottom - 2; /* * Now create a bitmap the size of the window. */ bmp.cbFix = sizeof(BITMAPINFOHEADER); bmp.cx = (SHORT)cxWidth; bmp.cy = (SHORT)cyHeight; bmp.cPlanes = (SHORT)cColorPlanes; bmp.cBitCount = (SHORT)cColorBitcount; hbm = GpiCreateBitmap(hpsBuffer, (PBITMAPINFOHEADER2)&bmp, 0x0000, (PBYTE)NULL, (PBITMAPINFO2)NULL); GpiSetBitmap (hpsBuffer, hbm); /* * Assume the size of the page rectangle is constrained in the y * dimension,compute the x size which would make the rectangle appear * square, then check the assumption and do the reverse calculation * if necessary. */ cySquare = cyHeight - 2; cxSquare = ( cyHeight * cxRes ) / cyRes; if (cxWidth < cxSquare) { cxSquare = cxWidth - 2; cySquare = (cxWidth * cyRes) / cxRes; } /* * Fill in the page rectangle and set the page viewport. */ RECTL rclPage; // clkdata.c war global!! aber warum? cxEdge = (cxWidth - cxSquare ) / 2; cyEdge = (cyHeight - cySquare ) / 2; rclPage.xLeft = cxEdge; rclPage.xRight = cxWidth - cxEdge; rclPage.yBottom = cyEdge; rclPage.yTop = cyHeight - cyEdge; f = GpiSetPageViewport (hps, &rclPage); f = GpiSetPageViewport (hpsBuffer, &rclPage); fBufferDirty = TRUE; }
// exported extern windows callback routine (doet alle belangrijke stuff) MRESULT EXPENTRY ClientWndProc(HWND hwnd,ULONG messg,MPARAM mp1,MPARAM mp2) { HPS hps; static HWND hMenu; RECTL rc; static INT xView, yView; int count,zoom,tel; float tmpangle; BOOL stat; SIZEL sizel; POINTL ptl; switch (messg) { case DM_CHECKSCORE: count = check_hiscores(mp1); if (count != 10) { WinDlgBox(HWND_DESKTOP,hwnd,EnterHiScore,NULLHANDLE,DRIFT_HISCORE,NULL); if (glb_name[0] == 0) strcpy(HiTable[count].name,"Cthulhu"); else strcpy(HiTable[count].name,glb_name); } break; case WM_SIZE: xView = SHORT1FROMMP(mp2); yView = SHORT2FROMMP(mp2); break; case WM_CREATE: init_logo(); load_hiscores(); // initialize the settings //hMenu=WinQueryWindow(hwnd,QW_PARENT); hMenu=WinWindowFromID(WinQueryWindow(hwnd,QW_PARENT),FID_MENU); // uncheck detaillevel stat = WinCheckMenuItem(hMenu,detaillevel,FALSE); // uncheck save on exit stat = WinCheckMenuItem(hMenu,IDM_SAVEONEXIT,FALSE); load_settings(); // check to correct menu item detaillevel stat = WinCheckMenuItem(hMenu,detaillevel,TRUE); if (saveonexit) stat = WinCheckMenuItem(hMenu,IDM_SAVEONEXIT,TRUE); switch (detaillevel) { case IDM_HIGHDET: game_bigex = 36; game_mediumex = 18; game_smallex = 9; maxthrustpixels = 9; break; case IDM_MEDIUMDET: game_bigex = 18; game_mediumex = 18; game_smallex = 9; maxthrustpixels = 5; break; case IDM_LOWDET: game_bigex = 9; game_mediumex = 9; game_smallex = 9; maxthrustpixels = 3; break; } if (saveonexit == TRUE) stat = WinCheckMenuItem(hMenu,IDM_SAVEONEXIT,TRUE); else stat = WinCheckMenuItem(hMenu,IDM_SAVEONEXIT,FALSE); break; case WM_TIMER: hps = WinGetPS(hwnd) ; sizel.cx = 2000 ; sizel.cy = 2000 ; GpiSetPS (hps, &sizel, PU_PELS) ; GpiQueryPageViewport(hps,&rc); rc.xLeft = 0;//xView / 2 ; rc.xRight = xView ; rc.yBottom = 0;//yView / 2 ; rc.yTop = yView; GpiSetPageViewport (hps, &rc) ; switch (game_status) { case GAME_INTRO : stat = WinEnableMenuItem(hMenu,IDM_PLAY,TRUE); stat = WinEnableMenuItem(hMenu,IDM_QUIT,FALSE); stat = WinEnableMenuItem(hMenu,IDM_PAUZE,FALSE); zoom = (game_duration - 100)/3; if (zoom < 5) zoom = 5; D->angle += 10; D->zoom = zoom; R->angle += 10; R->zoom = zoom; I->angle += 10; I->zoom = zoom; F->angle += 10; F->zoom = zoom; T->angle += 10; T->zoom = zoom; game_duration --; if (game_duration == 0) { game_status = GAME_HISCORE; game_duration = 200; if (random(2) == 0) { // insert the hiscore table insert_message(1800,0,"D R I F T F O R O S / 2 H I S C O R E S"); insert_message(1600,0,"Rank Name Score Level"); for (tel = 0; tel < 10; tel++) insert_message(1460-(tel*100),0,"%2d %-12s %5d %2d",tel+1,HiTable[tel].name,HiTable[tel].score,HiTable[tel].level); } else { // insert help message insert_message(1800,0,"DRIFT WARPSPEED FOR OS/2 WARP"); insert_message(1600,0,"By Dirk Vandenheuvel /c/ 1995"); insert_message(1400,0,"Keys"); insert_message(1200,0,"UP Thrust"); insert_message(1100,0,"LEFT Turn left"); insert_message(1000,0,"RIGHT Turn right"); insert_message(900,0, "SPACE Fire missile"); } WinInvalidateRect(hwnd,NULL,TRUE); } else intro(hps); break; case GAME_HISCORE: game_duration --; if (game_duration == 0) { // free the effekts list free_all(); game_status = GAME_INTRO; game_duration = 200; WinInvalidateRect(hwnd,NULL,TRUE); } break; case GAME_PLAYING: // play check_keys(); if (game_shooting) game_shooting--; game(hps); break; } WinReleasePS(hps); break; case WM_SYSCOMMAND: /*switch(mp1) { case SC_MINIMIZE: if (!game_pauze) SendMessage(hwnd,WM_COMMAND,IDM_PAUZE,0); break; } return(DefWindowProc(hwnd,messg,mp1,mp2));*/ break; case WM_COMMAND: switch (COMMANDMSG(&messg)->cmd) { case IDM_SAVEONEXIT: if (saveonexit == TRUE) // already checked { stat = WinCheckMenuItem(hMenu,IDM_SAVEONEXIT,FALSE); saveonexit = FALSE; save_settings(); // save the "do not save on exit" setting } else { stat = WinCheckMenuItem(hMenu,IDM_SAVEONEXIT,TRUE); saveonexit = TRUE; } break; case IDM_HIGHDET : // set to high game_bigex = 36; game_mediumex = 18; game_smallex = 9; maxthrustpixels = 9; stat = WinCheckMenuItem(hMenu,detaillevel,FALSE); detaillevel=SHORT1FROMMP(mp1); stat = WinCheckMenuItem(hMenu,detaillevel,TRUE); break; case IDM_MEDIUMDET: game_bigex = 18; game_mediumex = 18; game_smallex = 9; maxthrustpixels = 5; stat = WinCheckMenuItem(hMenu,detaillevel,FALSE); detaillevel=SHORT1FROMMP(mp1); stat = WinCheckMenuItem(hMenu,detaillevel,TRUE); break; case IDM_LOWDET: game_bigex = 9; game_mediumex = 9; game_smallex = 9; maxthrustpixels = 3; stat = WinCheckMenuItem(hMenu,detaillevel,FALSE); detaillevel=SHORT1FROMMP(mp1); stat = WinCheckMenuItem(hMenu,detaillevel,TRUE); break; case IDM_ABOUT: WinDlgBox(HWND_DESKTOP,hwnd,AboutDiaProc,NULLHANDLE,IDD_ABOUT,NULL); break; case IDM_HELP : //WinHelp (hwnd,"drift.hlp",HELP_INDEX,0); break; case IDVK_ESCAPE: // escape key pressed //SendMessage (hwnd, WM_SYSCOMMAND,SC_MINIMIZE,0); break; case IDM_PAUZE: if (game_status != GAME_PLAYING) break; if (game_pauze != TRUE) { WinStopTimer(hab,hwndClient,idTimer); stat = WinCheckMenuItem(hMenu,IDM_PAUZE,TRUE); game_pauze = TRUE; } else { game_pauze = FALSE; // gets a timer idTimer = WinStartTimer(hab,hwndClient,ID_TIMER,30); stat = WinCheckMenuItem(hMenu,IDM_PAUZE,FALSE); WinInvalidateRect(hwnd, NULL, TRUE); } break; case IDM_QUIT: stat = WinEnableMenuItem(hMenu,IDM_PLAY,TRUE); stat = WinEnableMenuItem(hMenu,IDM_QUIT,FALSE); stat = WinEnableMenuItem(hMenu,IDM_PAUZE,FALSE); free_all(); game_status = GAME_INTRO; if (game_pauze) { game_pauze = FALSE; //while (!SetTimer(hwnd,ID_TIMER,10,NULL)) //if (IDCANCEL == MessageBox (hwnd, "Cannot get timer handle!", szProgName,MB_ICONEXCLAMATION | MB_RETRYCANCEL)) //exit(0); // add a better shutdown here //CheckMenuItem(hmenu,IDM_PAUZE,MF_UNCHECKED); } game_duration = 200; WinInvalidateRect(hwnd, NULL, TRUE); break; case IDM_PLAY: free_all(); stat = WinEnableMenuItem(hMenu,IDM_PLAY,FALSE); stat = WinEnableMenuItem(hMenu,IDM_QUIT,TRUE); stat = WinEnableMenuItem(hMenu,IDM_PAUZE,TRUE); init_objekts(); game_level = 1; // init powerups to default game_pauze = FALSE; game_maxshots = MAXSHOT; game_shots = 1; game_turning = 10; game_shotlife = 20; game_rearshot = FALSE; game_shieldduration = 0; init_game(); game_status = GAME_PLAYING; game_score = 0; game_duration = 25; game_life = 3; WinInvalidateRect(hwnd, NULL, TRUE); break; default: break; } break; case WM_PAINT: hps = WinBeginPaint(hwnd,NULLHANDLE,&rc); WinQueryWindowRect(hps,&rc); WinFillRect(hps,&rc,CLR_BLACK); sizel.cx = 2000 ; sizel.cy = 2000 ; GpiSetPS (hps, &sizel, PU_PELS) ; GpiQueryPageViewport(hps,&rc); rc.xLeft = 0;//xView / 2 ; rc.xRight = xView ; rc.yBottom = 0;//yView / 2 ; rc.yTop = yView; GpiSetPageViewport (hps, &rc) ; if (game_status == GAME_HISCORE) hiscore(hps); if (game_status == GAME_PLAYING && game_pauze) game(hps); WinEndPaint(hps); break; default: return(WinDefWindowProc(hwnd,messg,mp1,mp2)); } return(MRESULT)0L; }