VOID ClientPaint(HWND hwnd) { POINTL pt; HPS hps; RECTL rcl; LONG lLen; LONG lCenter; WinInvalidateRect(hwnd,(PRECTL)NULL,FALSE); hps = WinBeginPaint(hwnd,(HPS)NULL,&rcl ); // if (bShowingProgress) // rcl.yBottom = 60L; WinFillRect(hps,&rcl,CLR_WHITE); lCenter = (INITWIDTH / 2); if (bDebug) { GpiSetBackColor(hps,CLR_WHITE); GpiSetBackMix(hps,BM_OVERPAINT); GpiCreateLogFont(hps,NULL,3,&fattMsgFont); GpiSetColor(hps,CLR_BLACK); GpiSetCharSet(hps,3); pt.x = 10; if (szDebugLineOne[0] != 0) { pt.y = 82L; GpiCharStringAt(hps,&pt,strlen(szDebugLineOne),szDebugLineOne); } if (szDebugLineTwo[0] != 0) { pt.y = 62L; GpiCharStringAt(hps,&pt,strlen(szDebugLineTwo),szDebugLineTwo); } } else { GpiSetColor(hps,CLR_CYAN); GpiSetBackColor(hps,CLR_WHITE); GpiSetBackMix(hps,BM_OVERPAINT); GpiCreateLogFont(hps, NULL, 2, &fattBigFont); GpiSetCharSet(hps,2); pt.x = (lCenter - (10 * stBigCell.cx)); pt.y = 60L; GpiCharStringAt(hps,&pt,21,"OS/tools Installation"); } if (!bShowingProgress) PrintBanners(szBannerOne,szBannerTwo); WinEndPaint(hps); }
LONG ScaleFont(HPS hPS, CHAR *pszFacename, LONG lSize) { FATTRS fat; /* Font Attributes */ SIZEF sizfxBox; /* Character Size Holder */ /* Complete the font attributes structure to */ /* allow the selection of the font requested */ /* within the print file dialogue box */ memset(&fat, 0, sizeof(FATTRS)); fat.usRecordLength = (USHORT)sizeof(FATTRS); fat.lMatch = SelectScalableFont(hPS, strcpy(fat.szFacename, pszFacename)); fat.usCodePage = (USHORT)850; /* Create the required font and set the */ /* character size by changing the character box */ /* size. The sizing in TWIPS for a 12 pt font */ /* is 240, therefore a 10 pt font would be 200. */ GpiCreateLogFont(hPS, (PSTR8)NULL, 2L, &fat); GpiSetCharSet(hPS, 2L); sizfxBox.cx = sizfxBox.cy = MAKEFIXED(lSize * 2, 0); GpiSetCharBox(hPS, &sizfxBox); return(2L); }
void setTNGfont(HPS hps) { LONG cFonts; LONG lTemp = 0L; CHAR fontName[25]; FATTRS fattrs; SIZEF sizfCharBox; fattrs.usRecordLength = sizeof(FATTRS); fattrs.fsSelection = 0; fattrs.lMatch = 0L; fattrs.idRegistry = 0; fattrs.usCodePage = 850; fattrs.lMaxBaselineExt = 0L; fattrs.lAveCharWidth = 0L; fattrs.fsType = 0; fattrs.fsFontUse = FATTR_FONTUSE_OUTLINE; strcpy(fattrs.szFacename,TNG_FONT); cFonts = GpiQueryFonts(hps, QF_PUBLIC,fattrs.szFacename, &lTemp, (LONG) sizeof(FONTMETRICS), (PFONTMETRICS)NULL); if (cFonts==0) { strcpy(fattrs.szFacename,"Helvetica"); } GpiCreateLogFont(hps, (PSTR8)NULL, fontId, &fattrs); GpiSetCharSet(hps,fontId); sizfCharBox.cx=MAKEFIXED(14,0); sizfCharBox.cy=MAKEFIXED(20,0); GpiSetCharBox(hps,&sizfCharBox); GpiSetTextAlignment(hps,TA_CENTER,TA_TOP); }
static void LboxDrawLine(HWND hwnd, OWNERITEM *item, RECTL *rcl, image_contents_screencode_t *line) { const HPS hps = item->hps; const int name = WinDlgLboxSelectedItem(hwnd, DID_FONTNAME_LB); FATTRS font = { sizeof(FATTRS), 0, 0, "", 0, 0, 8, 8, 0, 0 }; strcpy(font.szFacename, fnames[name]); GpiCreateLogFont(hps, NULL, 1, &font); GpiSetCharSet(hps, 1); GpiSetBackColor(hps, item->fsState ? CLR_DARKGRAY : CLR_WHITE); GpiSetColor(hps, item->fsState ? CLR_WHITE : CLR_DEFAULT); GpiCharStringPosAt(hps, (POINTL*)rcl, rcl, CHS_OPAQUE, line->length, line->line, NULL); GpiSetCharSet(hps, 0); GpiDeleteSetId(hps, 1); }
void PaintClient (HPS hps, SHORT cxClient, SHORT cyClient) { static CHAR szText [] = "ZED" ; POINTL ptl, ptlShear ; // Create the logical font CreateOutlineFont (hps, LCID_FONT, "Times New Roman", 0, 0) ; GpiSetCharSet (hps, LCID_FONT) ; // Display the shadow GpiSetColor (hps, CLR_DARKBLUE) ; ScaleOutlineFont (hps, 2160, 720) ; ptlShear.x = 1 ; //was 2 ptlShear.y = 1 ; GpiSetCharShear (hps, &ptlShear) ; ptl.x = cxClient / 8 ; ptl.y = cyClient / 4 ; GpiCharStringAt (hps, &ptl, strlen (szText), szText) ; // Display the text GpiSetColor (hps, CLR_WHITE) ; ScaleOutlineFont (hps, 720, 720) ; ptlShear.x = 0 ; ptlShear.y = 1 ; GpiSetCharShear (hps, &ptlShear) ; GpiCharStringAt (hps, &ptl, strlen (szText), szText) ; // Select the default font; delete the logical font GpiSetCharSet (hps, LCID_DEFAULT) ; GpiDeleteSetId (hps, LCID_FONT) ; }
void PaintClient (HPS hps, SHORT cxClient, SHORT cyClient) { static CHAR szText [] = "Hello!" ; FONTMETRICS fm ; int iPtHt, iPtWd ; POINTL ptl, aptl[TXTBOX_COUNT] ; // Create the logical font, select it, and scale it CreateOutlineFont (hps, LCID_FONT, "Helvetica", 0, 0) ; GpiSetCharSet (hps, LCID_FONT) ; ScaleOutlineFont (hps, 120, 120) ; // Scale font to client window size GpiQueryTextBox (hps, strlen (szText), szText, TXTBOX_COUNT, aptl) ; iPtHt = (int) (120 * cyClient / (aptl[TXTBOX_TOPLEFT].y - aptl[TXTBOX_BOTTOMLEFT].y)) ; iPtWd = (int) (120 * cxClient / aptl[TXTBOX_CONCAT].x) ; ScaleOutlineFont (hps, iPtHt, iPtWd) ; // Display the text string GpiQueryFontMetrics (hps, sizeof (FONTMETRICS), &fm) ; ptl.x = 0 ; ptl.y = cyClient - fm.lMaxAscender ; GpiCharStringAt (hps, &ptl, strlen (szText), szText) ; // Select the default font; delete the logical font GpiSetCharSet (hps, LCID_DEFAULT) ; GpiDeleteSetId (hps, LCID_FONT) ; }
/**************************************************************** DefaultOutlineFont: Set an outline font which is sizeable. ****************************************************************/ void SetOutlineFont(HPS hps, short height) {FONTMETRICS fm[80]; static FATTRS fat; static LONG cFonts=0; LONG ltemp=0; SIZEF size; int i; if (height<=2) return; if (cFonts==0) { GpiLoadFonts(WinQueryAnchorBlock(HWND_DESKTOP),"helv"); cFonts= GpiQueryFonts(hps,QF_PUBLIC|QF_PRIVATE,"Helv",<emp, sizeof(FONTMETRICS),(PFONTMETRICS)0); if (cFonts>sizeof(fm)/sizeof(FONTMETRICS)) cFonts=sizeof(fm)/sizeof(FONTMETRICS); GpiQueryFonts(hps,QF_PUBLIC|QF_PRIVATE,"Helv",&cFonts, sizeof(FONTMETRICS),fm); for (i=0; (!(fm[i].fsDefn&FM_DEFN_OUTLINE)) && //find outline and (!(fm[i].fsType&FM_TYPE_KERNING)) && //kerned if can (i<cFonts); i++); if (i==cFonts) for (i=0; (!(fm[i].fsDefn&FM_DEFN_OUTLINE))&& // Find outline atleast (i<cFonts); i++); if (i==cFonts) i=0; fat.usRecordLength =sizeof(FATTRS); fat.lMatch =fm[i].lMatch; fat.lMatch =0; fat.fsFontUse = FATTR_FONTUSE_OUTLINE; strcpy(fat.szFacename,fm[i].szFacename); } GpiCreateLogFont(hps,(PSTR8)0,1,&fat); GpiSetBackMix(hps,(LONG)BM_LEAVEALONE); GpiSetCharSet(hps,1); size.cx = MAKEFIXED(height,0); size.cy = MAKEFIXED(height,0); GpiSetCharBox(hps,&size); GpiSetTextAlignment(hps,TA_NORMAL_HORIZ,TA_BOTTOM); }
/*@ XPrinterDevice::KillPrinterJob() @remarks Remove the printer job from the printer queue. */ void XPrinterDevice::KillPrinterJob() { DevEscape(hdc, DEVESC_ABORTDOC, 0, NULL, NULL, NULL); if (hps) { GpiSetCharSet(hps, 0); GpiAssociate(hps, (HDC) 0); GpiDestroyPS(hps); hps = (HPS) 0; } if (hdc) { DevCloseDC(hdc); hdc = (HDC) 0; } }
static MRESULT EXPENTRY LinkLabelProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) { linkData *ld = (linkData *)WinQueryWindowULong( hwnd, QWL_USER ); switch ( msg ) { case WM_PAINT: { FONTMETRICS fm; FATTRS fat; HPS hps; ULONG style; char *text = (char *)malloc( MAXTEXTLEN ); WinQueryWindowText( hwnd, MAXTEXTLEN, text); hps = WinBeginPaint( hwnd , 0L , 0L ); GpiQueryFontMetrics( hps , sizeof( FONTMETRICS ) , &fm ); memset( &fat , 0 , sizeof( fat ) ); fat.usRecordLength = sizeof( FATTRS ); fat.lMatch = fm.lMatch; fat.fsSelection = FATTR_SEL_UNDERSCORE; strcpy( fat.szFacename , fm.szFacename ); GpiDeleteSetId( hps , 1 ); GpiCreateLogFont( hps , 0 , 1 , &fat ); GpiSetCharSet( hps , 1 ); WinQueryWindowRect( hwnd , &ld->textRect ); style = WinQueryWindowULong( hwnd, QWL_STYLE ); style &= DT_LEFT|DT_CENTER|DT_RIGHT|DT_TOP|DT_VCENTER|DT_BOTTOM; WinDrawText( hps, -1, text, &ld->textRect, CLR_BLUE, SYSCLR_DIALOGBACKGROUND, style | DT_ERASERECT | DT_UNDERSCORE ); WinDrawText( hps, -1, text, &ld->textRect, CLR_BLUE, SYSCLR_DIALOGBACKGROUND, style | DT_QUERYEXTENT | DT_UNDERSCORE ); WinEndPaint( hps ); free( text ); } return (MRESULT)FALSE; case WM_MOUSEMOVE: { if ( handPtr != NULLHANDLE ) { POINTL ptl; ptl.x = SHORT1FROMMP( mp1 ); ptl.y = SHORT2FROMMP( mp1 ); if ( WinPtInRect( WinQueryAnchorBlock( hwnd ), &ld->textRect, &ptl) ) { WinSetPointer( HWND_DESKTOP, handPtr ); return (MRESULT)FALSE; } } } break; case WM_BUTTON1CLICK: { PROGDETAILS pd; char *text; POINTL ptl; if ( strcmp( browserExe, "" ) == 0 ) break; ptl.x = SHORT1FROMMP( mp1 ); ptl.y = SHORT2FROMMP( mp1 ); if ( !WinPtInRect( WinQueryAnchorBlock( hwnd ), &ld->textRect, &ptl) ) break; if ( ld->url == NULL ) { text = (char *)malloc( MAXTEXTLEN ); WinQueryWindowText( hwnd, MAXTEXTLEN, text); } else text = strdup( ld->url ); pd.Length = sizeof( PROGDETAILS ); pd.progt.progc = PROG_DEFAULT; pd.progt.fbVisible = SHE_VISIBLE; pd.pszTitle = NULL; pd.pszExecutable = browserExe; pd.pszParameters = NULL; pd.pszStartupDir = ( browserDir[0] == 0 ) ? NULL : browserDir; pd.pszIcon = NULL; pd.pszEnvironment = NULL; pd.swpInitial.fl = SWP_ACTIVATE; pd.swpInitial.cy = 0; pd.swpInitial.cx = 0; pd.swpInitial.y = 0; pd.swpInitial.x = 0; pd.swpInitial.hwndInsertBehind = HWND_TOP; pd.swpInitial.hwnd = NULLHANDLE; pd.swpInitial.ulReserved1 = 0; pd.swpInitial.ulReserved2 = 0; WinStartApp( NULLHANDLE , &pd , text , NULL , 0 ); free( text ); } break; case WM_DESTROY: ld->labelProc( hwnd, msg, mp1, mp2 ); if ( ld->url != NULL ) free( ld->url ); free( ld ); return (MRESULT)FALSE; } return ld->labelProc( hwnd, msg, mp1, mp2 ); }
/************************************************************************** * * Name : MyWindowProc * * Description: The window procedure associated with the client area in * the standard frame window. It processes all messages * either sent or posted to the client area, depending on * the message command and parameters. * * Concepts : * * API's : WinLoadString * WinInvalidateRegion * WinPostMsg * WinDefWindowProc * WinBeginPaint * GpiSetColor * GpiSetBackColor * GpiSetBackMix * GpiCharStringAt * WinEndPaint * * Parameters : hwnd = window handle * msg = message code * mp1 = first message parameter * mp2 = second message parameter * * Return : depends on message sent * *************************************************************************/ MRESULT EXPENTRY MyWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) { switch( msg ) { case WM_TIMER: { WinInvalidateRegion( hwnd, 0L, FALSE ); break; } case WM_CREATE: /* * Window initialization is performed here in WM_CREATE processing * WinLoadString loads strings from the resource file. */ WinLoadString( hab, (HMODULE)0L, IDS_HELLO, STRINGLENGTH, szHello ); WinLoadString( hab, (HMODULE)0L, IDS_1, STRINGLENGTH, sz1 ); WinLoadString( hab, (HMODULE)0L, IDS_2, STRINGLENGTH, sz2 ); WinLoadString( hab, (HMODULE)0L, IDS_3, STRINGLENGTH, sz3 ); strcpy( szString, szHello ); /* Copy text Hello into szString*/ break; case WM_COMMAND: /* * When the user chooses option 1, 2, or 3 from the Options pull- * down, the text string is set to 1, 2, or 3, and * WinInvalidateRegion sends a WM_PAINT message. * When Exit is chosen, the application posts itself a WM_CLOSE * message. */ { USHORT command; /* WM_COMMAND command value */ command = SHORT1FROMMP(mp1); /* Extract the command value */ switch (command) { case ID_EXITPROG: WinPostMsg( hwnd, WM_CLOSE, (MPARAM)0, (MPARAM)0 ); break; default: return WinDefWindowProc( hwnd, msg, mp1, mp2 ); } break; } case WM_ERASEBACKGROUND: /* * Return TRUE to request PM to paint the window background * in SYSCLR_WINDOW. */ return (MRESULT)( TRUE ); case WM_PAINT: /* * Window contents are drawn here in WM_PAINT processing. */ { HPS hps; /* Presentation Space handle */ RECTL rc; /* Rectangle coordinates */ POINTL pt; /* String screen coordinates */ POINTL pPos; LONG lColor,r,g,b; FATTRS fat; HPS shps = WinGetScreenPS(HWND_DESKTOP); fat.usRecordLength = sizeof(FATTRS); /* sets size of structure */ fat.fsSelection = 0; /* uses default selection */ fat.lMatch = 0L; /* does not force match */ fat.idRegistry = 0; /* uses default registry */ fat.usCodePage = 0; /* code-page 850 */ fat.lMaxBaselineExt = 14L; /* requested font height is 12 pels */ fat.lAveCharWidth = 14L; /* requested font width is 12 pels */ fat.fsType = 0; /* uses default type */ fat.fsFontUse = FATTR_FONTUSE_NOMIX;/* doesn't mix with graphics */ strcpy(fat.szFacename ,"Courier"); WinQueryPointerPos(HWND_DESKTOP, &pPos); hps = WinBeginPaint( hwnd, 0L, &rc ); GpiCreateLogColorTable(shps, 0, LCOLF_RGB, 0, 0, NULL); GpiCreateLogColorTable(hps, 0, LCOLF_RGB, 0, 0, NULL); pt.x = 10; pt.y = 27; /* Set the text coordinates, */ lColor=GpiQueryPel(shps, &pPos); GpiSetBackColor( hps, 16777215); /* its background and */ WinFillRect( hps, &rc, lColor); GpiSetBackMix( hps, BM_OVERPAINT ); /* how it mixes, */ b = lColor & 0x000000FF; lColor = lColor >> 8; g = lColor & 0x000000FF; lColor = lColor >> 8; r = lColor & 0x000000FF; WinReleasePS(shps); sprintf(szString,"Color: #%.2X%.2X%.2X",r,g,b); GpiCreateLogFont(hps, NULL, 1L, &fat); GpiSetCharSet(hps, 1L); GpiSetCharMode(hps, CM_MODE1); GpiCharStringAt( hps,&pt ,(LONG)strlen( szString ), szString ); WinEndPaint( hps ); /* Drawing is complete */ break; } case WM_CLOSE: WinPostMsg( hwnd, WM_QUIT, (MPARAM)0,(MPARAM)0 );/* Cause termination*/ break; default: /* * Everything else comes here. This call MUST exist * in your window procedure. */ return WinDefWindowProc( hwnd, msg, mp1, mp2 ); } return (MRESULT)FALSE; } /* End of MyWindowProc */
void _SelectFont( HPS ps ) { //============================ GpiCreateLogFont( ps, NULL, FIXED_FONT, &FontAttrs ); GpiSetCharSet( ps, FIXED_FONT ); }
/**************************************************************************** * ClientWndProc * * - Typical PM client window procedure. (see below) * * - Standard client window I/O * ****************************************************************************/ MRESULT EXPENTRY ClientWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { RECTL rcl; SWP swp; HPS hpsPaint; static HPS hps; /* Permanent HPS */ static INT cx, cy; /* Client window dimensions */ static BOOL bSlowUpdateNow = FALSE; /* Update toggle for asteroids * * and enemy which are slow. */ static POINTL ptlCenter; /* Center of client window */ switch (msg) { /* Recieved from WinCreateStdWindow */ case WM_CREATE: /* Get permanent PS for entire window */ hps = WinGetPS(hwnd); /* Load private Asteroid fonts from ASTEROID.DLL */ if (GpiLoadFonts(hab, "ASTEROID") != GPI_OK) { WinReleasePS(hps); WinAlarm(HWND_DESKTOP, WA_WARNING); WinMessageBox(HWND_DESKTOP,NULLHANDLE, "Please put ASTEROID.DLL in a directory in your LIBPATH.", "Error reading ASTEROID.DLL", 0,MB_ICONHAND|MB_OK|MB_APPLMODAL); WinPostMsg(hwnd,WM_QUIT,(MPARAM) 0L,(MPARAM) 0L); return (MRESULT) TRUE; } /* Register/create logical fonts for use */ InitFonts(hps); /* Display About dialoge box */ WinDlgBox(HWND_DESKTOP, hwnd, (PFNWP)AboutDlgProc, NULLHANDLE, IDD_ABOUT, NULL); return 0; /* Recieved during attract mode when user starts game */ case WM_STARTGAME: /* Determine the number of players */ cPlayers = (INT)LONGFROMMP(mp1); /* Initialize each player */ for (Player=0;Player<cPlayers;Player++) { Level[Player] = 1; Ships[Player] = prfProfile.iSHIPS; DeletePhotons(); InitAsteroids(); InitEnemy(); } /* Start with player 1 */ Player = 0; iGameMode = GAME_MODE_NEXT; iGameModeCnt = GAME_PAUSE_TIME-1; /* Hide the pointer if mouse controls are enabled */ ShowMouse(FALSE); /* Paint everything */ WinSendMsg(hwnd, WM_PAINT, MPVOID, MPVOID); return 0; /* Recieved at startup and at the completion of a game */ case WM_INITGAME: /* Make mouse visible if we hid it before */ ShowMouse(TRUE); /* Fix menu to reflect attract mode */ EnableMenuItem(hwndMenu, IDM_START, TRUE); EnableMenuItem(hwndMenu, IDM_STOP, FALSE); /* Initialize player and enemy data structures */ cPlayers = 0; Level[0] = 1; for (Player=0;Player<2;Player++) { Score[Player] = 0L; Ships[Player] = 0; DeletePhotons(); } Player = 0; /* Initialize asteroids (and enemy) for attract mode */ InitAsteroids(); InitEnemy(); /* Depending on whether ASTEROID was just started or a game just * * completed display the "High Score" or "Press 1 or 2" screen. */ if (SHORT1FROMMP(mp1) == 0) { iGameMode = GAME_MODE_INIT1; iGameModeCnt = GAME_INIT_TIME; } else { iGameMode = GAME_MODE_INIT2; iGameModeCnt = GAME_INIT_TIME; } /* Paint everything */ WinSendMsg(hwnd, WM_PAINT, MPVOID, MPVOID); return 0; /* Usually recieved from the system, sometime forced by the program to * * ensure the screen is not corrupt. */ case WM_PAINT: /* Clear entire window to insure no "droppings" */ WinQueryWindowRect(hwnd,&rcl); WinFillRect(hps, &rcl, CLR_BLACK); WinInvalidateRect(hwnd, &rcl, FALSE); /* Get the update region and paint it black */ hpsPaint = WinBeginPaint(hwnd, (HPS)NULL, &rcl); WinFillRect(hpsPaint, &rcl, CLR_BLACK); WinEndPaint(hpsPaint); /* Only in normal play mode should we draw the ship */ if ((iGameMode == GAME_MODE_PLAY) && (iShipMode[Player] != EXPLOSION) && (iShipMode[Player] != HYPERSPACE)) DrawShip(hps, cx, cy, DRAW_INIT); else if ((iGameMode == GAME_MODE_PLAY) && (iShipMode[Player] == EXPLOSION)) ExplodeShip(hps, cx, cy); /* Draw the enemy if it is on the screen */ if (iEnemyMode[Player] != NONE) if (iEnemyMode[Player] != EXPLOSION) DrawEnemy(hps, cx, cy,DRAW_INIT); else ExplodeEnemy(hps, cx, cy); /* Draw photons and asteroids in all modes but the "Enter your * * initials" mode, otherwise draw that screen. */ if (iGameMode != GAME_MODE_HIGH) { DrawPhotons(hps, cx, cy, DRAW_INIT); DrawAsteroids(hps, cx, cy, DRAW_INIT); } else DrawHighScore(hps, cx, cy, DRAW_INIT); /* Always draw the score */ DrawScore(hps, cx, cy, DRAW_INIT); return 0; /* Left mouse button down. This simulates the move/track function * * in the system menu. */ case WM_BUTTON1DOWN: if (prfProfile.bMOUSECONTROL && iGameMode != GAME_MODE_INIT1 && iGameMode != GAME_MODE_INIT2 && !TogglePause(CHECK)) { UPDATE_FIRE(iShipMode[Player], TRUE); return (MRESULT)TRUE; } return WinSendMsg(hwndFrame, WM_TRACKFRAME, (MPARAM) (SHORT1FROMMP(mp2) | TF_MOVE), MPVOID); case WM_BUTTON1UP: if (prfProfile.bMOUSECONTROL) { UPDATE_FIRE(iShipMode[Player], FALSE); return (MRESULT)TRUE; } return 0; /* Left mouse button double clicked. Toggle frame control display. */ case WM_BUTTON1DBLCLK: if (!prfProfile.bMOUSECONTROL || iGameMode == GAME_MODE_INIT1 || iGameMode == GAME_MODE_INIT2 || TogglePause(CHECK)) { if (prfProfile.bCONTROLS = !prfProfile.bCONTROLS) ShowFrameControls(); else HideFrameControls(); } return 0; case WM_BUTTON2DOWN: if (prfProfile.bMOUSECONTROL) { UPDATE_SHIELD(iShipMode[Player], iShipShieldCnt[Player]); return (MRESULT)TRUE; } return 0; case WM_BUTTON2CLICK: if (prfProfile.bMOUSECONTROL) { UPDATE_HYPERSPACE(iShipMode[Player], iShipModeCnt[Player]); return (MRESULT)TRUE; } return 0; /* Right mouse button double clicked. Display the about dialog box. */ case WM_BUTTON2DBLCLK: if (!prfProfile.bMOUSECONTROL || iGameMode == GAME_MODE_INIT1 || iGameMode == GAME_MODE_INIT2 || TogglePause(CHECK)) { WinDlgBox(HWND_DESKTOP, hwndClient, (PFNWP)AboutDlgProc, NULLHANDLE, IDD_ABOUT, NULL); } return 0; /* User typed a key. Most of this is self explanatory. */ case WM_CHAR: ProcessChar((CHAR) (CHARMSG(&msg)->vkey-1), CHARMSG(&msg)->fs & KC_VIRTUALKEY, (CHAR) (CHARMSG(&msg)->chr), (BOOL) !(CHARMSG(&msg)->fs & KC_KEYUP)); return 0; /* User entered a command via the menu bar. */ case WM_COMMAND: DoCommand(hwnd, msg, mp1, mp2); return 0; /* Suspend/un-suspend game depending on focus */ case WM_SETFOCUS: if ((BOOL) SHORT1FROMMP(mp2)) TogglePause(SUSPEND_OFF); else if (!prfProfile.bBACKGRND) TogglePause(SUSPEND_ON); return 0; /* Keep track of the client window size. Profile information is not * * updated here because there are better places (i.e. at exit) */ case WM_SIZE: cx = (INT)SHORT1FROMMP(mp2); cy = (INT)SHORT2FROMMP(mp2); /* Keep track of client window position. Also updates profile info. */ case WM_MOVE: WinQueryWindowPos(hwndFrame,&swp); if (!(swp.fl & SWP_MAXIMIZE) && !(swp.fl & SWP_MINIMIZE)) { prfProfile.x = swp.x;prfProfile.y = swp.y; prfProfile.cx = swp.cx;prfProfile.cy = swp.cy; } if (swp.fl & SWP_MINIMIZE) if (!prfProfile.bBACKGRND) { /* Set icon */ WinSendMsg(hwndFrame, WM_SETICON, (MPARAM) WinLoadPointer(HWND_DESKTOP, NULLHANDLE, ID_RESOURCE), MPVOID); TogglePause(SUSPEND_ON); } else WinSendMsg(hwndFrame, WM_SETICON, MPVOID, MPVOID); else TogglePause(SUSPEND_OFF); ptlCenter.x = swp.cx / 2; ptlCenter.y = swp.cy / 2; WinMapWindowPoints(hwndClient, HWND_DESKTOP, &ptlCenter, 1L); return 0; /* Recieved approximately 31 times a second. This is the longest and * * ugliest of the messages, partly because there are so many cases * * to keep track of, partly because it must be highly optimized. */ case WM_TIMER: if (prfProfile.bMOUSECONTROL && iGameMode != GAME_MODE_INIT1 && iGameMode != GAME_MODE_INIT2) { POINTL ptl; static BOOL bUp, bLeft, bRight; WinQueryPointerPos(HWND_DESKTOP, &ptl); if (bUp || (ptl.y - ptlCenter.y > 0)) UPDATE_THRUST(iShipMode[Player], bUp = (ptl.y - ptlCenter.y > 0)); if (bLeft || (ptlCenter.x - ptl.x > 0)) UPDATE_LEFT(iShipMode[Player], bLeft = (ptlCenter.x - ptl.x > 0)); if (bRight || (ptlCenter.x - ptl.x < 0)) UPDATE_RIGHT(iShipMode[Player], bRight = (ptlCenter.x - ptl.x < 0)); WinSetPointerPos(HWND_DESKTOP, ptlCenter.x, ptlCenter.y); } /* Determine the current game mode */ switch (iGameMode) { /* Either initialization/attract mode screen. */ case GAME_MODE_INIT1: case GAME_MODE_INIT2: /* Switch screens when count expires */ if (--iGameModeCnt == 0) { if (iGameMode == GAME_MODE_INIT1) iGameMode = GAME_MODE_INIT2; else iGameMode = GAME_MODE_INIT1; iGameModeCnt = GAME_INIT_TIME; /* Score must be redrawn because the attract mode screens * * draw the score differently. */ DrawScore(hps, cx, cy, DRAW_REINIT); } /* Update photons, asteroids, enemy, and score */ UpdatePhotons(hps, cx, cy); if (uiSpeed == SPEED_OS2 || (bSlowUpdateNow = !bSlowUpdateNow)) { UpdateAsteroids(hps, cx, cy); UpdateEnemy(hps, cx, cy); DrawScore(hps, cx, cy, DRAW_REFRESH); } break; /* Completion of one player's turn or new game */ case GAME_MODE_NEXT: /* Initially, erase and redraw everything for new player */ if (iGameModeCnt-- == GAME_PAUSE_TIME) { if ((cPlayers == MAXPLAYERS) && (Ships[(Player+1) % MAXPLAYERS])) { DrawAsteroids(hps, cx, cy, DRAW_ERASE); DrawPhotons(hps, cx, cy, DRAW_ERASE); Player = (Player+1) % MAXPLAYERS; } DrawScore(hps, cx, cy, DRAW_REINIT); DrawAsteroids(hps, cx, cy, DRAW_INIT); } /* During countdown update score and asteroids */ else if (iGameModeCnt > 0) { if (uiSpeed == SPEED_OS2 || (bSlowUpdateNow = !bSlowUpdateNow)) { DrawScore(hps, cx, cy, DRAW_REFRESH); UpdateAsteroids(hps, cx, cy); } } /* At end of countdown start the player */ else { InitShip(); InitEnemy(); iGameMode = GAME_MODE_PLAY; DrawScore(hps, cx, cy, DRAW_REINIT); } break; /* Normal play mode */ case GAME_MODE_PLAY: /* Update ship, photons, asteroids, enemy, and score */ UpdateShip(hps, cx, cy); UpdatePhotons(hps, cx, cy); if (uiSpeed == SPEED_OS2 || (bSlowUpdateNow = !bSlowUpdateNow)) { UpdateAsteroids(hps, cx, cy); UpdateEnemy(hps, cx, cy); /* Erase old and draw new scores if there is a change*/ if (bChangeScore) { bChangeScore = FALSE; DrawScore(hps, cx, cy, DRAW_REINIT); } /* Else just refresh the score */ else DrawScore(hps, cx, cy, DRAW_REFRESH); } break; /* Game over mode. This is the longest and ugliest case because * * conditions are highly dependent on the number of players, * * multiplayer game status, and the number and order of high * * scores. */ case GAME_MODE_OVER: /* Initially, just update the score and number of ships */ if (iGameModeCnt-- == GAME_PAUSE_TIME) DrawScore(hps, cx, cy, DRAW_REINIT); /* During countdown refresh the score and update the asteroids */ else if (iGameModeCnt > 0) { if (uiSpeed == SPEED_OS2 || (bSlowUpdateNow = !bSlowUpdateNow)) { DrawScore(hps, cx, cy, DRAW_REFRESH); UpdateAsteroids(hps, cx, cy); } } /* At the end of the countdown, if there are any other players, * * continue with them. */ else { /* Countinue on with any remaining players. */ if ((cPlayers == MAXPLAYERS) && (Ships[(Player+1) % MAXPLAYERS])) { /* Erase all of the old asteroids. */ DrawAsteroids(hps, cx, cy, DRAW_ERASE); /* Setup everything for the next player */ Player = (Player+1) % MAXPLAYERS; InitShip(); InitEnemy(); iGameMode = GAME_MODE_PLAY; DrawAsteroids(hps, cx, cy, DRAW_INIT); DrawScore(hps, cx, cy, DRAW_REINIT); } /* Check for new high scores and update table as necessary. */ else { /* Erase all of the old asteroids. */ DrawAsteroids(hps, cx, cy, DRAW_ERASE); /* The following if/else block is admittedly a kludge, it is * * simple and it does work, however. Ideally it should * * sort the high scores and update the high score table in * * descending order. */ /* If player 1 scored higher than player 2 then check * * player 1 first for a high score. */ if (Score[0] > Score[1]) for (Player=0;Player<cPlayers;Player++) /* If the player's score is > than the lowest, * * update the high score table. */ if (Score[Player] > prfProfile.lSCORES[9]) { UpdateHighScores(); iGameMode = GAME_MODE_HIGH; } /* Otherwise, make sure he is not asked for his * * initials. */ else Score[Player] = 0; /* Otherwise, check player 2 first */ else for (Player=cPlayers;Player>=0;Player--) /* If the player's score is > than the lowest, * * update the high score table. */ if (Score[Player] > prfProfile.lSCORES[9]) { UpdateHighScores(); iGameMode = GAME_MODE_HIGH; } /* Otherwise, make sure he is not asked for his * * initials. */ else Score[Player] = 0L; /* If there was no high score, go into attract mode */ if (iGameMode != GAME_MODE_HIGH) WinSendMsg(hwnd,WM_INITGAME,MPFROMSHORT(1),(MPARAM) 0L); /* Else, check for player 1's initials first then 2's * * This is not faithful, in the arcade game the player * * with the higher score always goes first. */ else { if (Score[0] > 0L) Player = 0; else Player = 1; DrawScore(hps, cx, cy, DRAW_REINIT); DrawHighScore(hps, cx, cy, DRAW_INIT); } } } break; /* Mode which prompts players to enter their initials */ case GAME_MODE_HIGH: /* If the player's position is > 0 then refresh the screen */ if (Score[Player] > 0L) DrawHighScore(hps, cx, cy, DRAW_REFRESH); /* Else, the current player is done go to the next */ else if ((cPlayers == MAXPLAYERS) && (Player == 0) && (Score[1] > 0L)) { Player++; DrawHighScore(hps, cx, cy, DRAW_REINIT); } /* If there are no more high scores then go into attract mode */ else WinSendMsg(hwnd, WM_INITGAME, MPFROMSHORT(1), MPVOID); break; } return 0; /* Used by help manager */ case HM_QUERY_KEYS_HELP: return((MRESULT)IDH_CLIENTKEYS); /* Recieved always from the system or in the case of an initialization* * error. Both messages will normally save the profile information.* * Ideally the profile section should be moved to a subroutine and the* * the following should be broken into two distinct cases. */ case WM_SAVEAPPLICATION: case WM_DESTROY: /* If the fonts were not found bApplicationOk will be false, in * * that case the window profile information should not be updated.*/ if (TRUE) { /* Copy window position and size info into profile structure */ WinQueryWindowPos(hwndFrame, &swp); if (swp.fl & SWP_MAXIMIZE) prfProfile.ulMINMAX = SWP_MAXIMIZE; else if (swp.fl & SWP_MINIMIZE) prfProfile.ulMINMAX = SWP_MINIMIZE; else { prfProfile.ulMINMAX = 0; prfProfile.x = swp.x;prfProfile.y = swp.y; prfProfile.cx = swp.cx;prfProfile.cy = swp.cy; } /* Write profile information */ PrfWriteProfileData(HINI_USERPROFILE, szClientClass, "Data", &prfProfile, sizeof(PROFILEREC)); } /* If the application is terminating release the fonts and the hps. */ if (msg == WM_DESTROY) { /* Make sure mouse is visible if we hid it before */ ShowMouse(TRUE); /* Release font identifiers and DLL resource module */ GpiSetCharSet(hps, LCID_DEFAULT); GpiDeleteSetId(hps, LCID_LARGE); GpiDeleteSetId(hps, LCID_SMALL); GpiUnloadFonts(hab, "ASTEROID"); /* Release the "permanent" presentation space */ WinReleasePS(hps); } return 0; } return WinDefWindowProc(hwnd, msg, mp1, mp2); }
MRESULT EXPENTRY ClientWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { static CHAR szErrorMsg [] = "File not found or could not be opened" ; static INT cxClient, cyClient, cxChar, cyChar, cyDesc ; CHAR *pcReadBuffer ; FILE *fileInput ; FONTMETRICS fm ; HPS hps ; INT iLength ; POINTL ptl ; switch (msg) { case WM_CREATE: hps = WinGetPS (hwnd) ; EzfQueryFonts (hps) ; if (!EzfCreateLogFont (hps, LCID_FIXEDFONT, FONTFACE_MONO, FONTSIZE_10, 0)) { WinReleasePS (hps) ; WinMessageBox (HWND_DESKTOP, HWND_DESKTOP, "Cannot find a fixed-pitch font. Load the Courier " "fonts from the Control Panel and try again.", szClientClass, 0, MB_OK | MB_WARNING) ; return MRFROMSHORT (1) ; } GpiQueryFontMetrics (hps, (LONG) sizeof fm, &fm) ; cxChar = fm.lAveCharWidth ; cyChar = fm.lMaxBaselineExt ; cyDesc = fm.lMaxDescender ; GpiSetCharSet (hps, LCID_DEFAULT) ; GpiDeleteSetId (hps, LCID_FIXEDFONT) ; WinReleasePS (hps) ; return 0 ; case WM_SIZE: cxClient = SHORT1FROMMP (mp2) ; cyClient = SHORT2FROMMP (mp2) ; return 0 ; case WM_COMMAND: switch (COMMANDMSG(&msg)->cmd) { case IDM_OPEN: if (WinDlgBox (HWND_DESKTOP, hwnd, OpenDlgProc, NULLHANDLE, IDD_OPEN, NULL)) WinInvalidateRect (hwnd, NULL, FALSE) ; return 0 ; case IDM_ABOUT: WinDlgBox (HWND_DESKTOP, hwnd, AboutDlgProc, NULLHANDLE, IDD_ABOUT, NULL) ; return 0 ; } break ; case WM_PAINT: hps = WinBeginPaint (hwnd, NULLHANDLE, NULL) ; GpiErase (hps) ; if (szFileName [0] != '\0') { EzfCreateLogFont (hps, LCID_FIXEDFONT, FONTFACE_MONO, FONTSIZE_10, 0) ; EzfCreateLogFont (hps, LCID_BOLDFONT, FONTFACE_MONO, FONTSIZE_10, FATTR_SEL_BOLD) ; GpiSetCharSet (hps, LCID_BOLDFONT) ; ptl.x = cxChar ; ptl.y = cyClient - cyChar + cyDesc ; GpiCharStringAt (hps, &ptl, strlen (szFileName), szFileName) ; ptl.y -= cyChar ; if ((fileInput = fopen (szFileName, "r")) != NULL) { GpiSetCharSet (hps, LCID_FIXEDFONT) ; pcReadBuffer = (PCHAR) malloc (cxClient / cxChar) ; while ((ptl.y -= cyChar) > 0 && fgets (pcReadBuffer, cxClient / cxChar - 2, fileInput) != NULL) { iLength = strlen (pcReadBuffer) ; if (pcReadBuffer [iLength - 1] == '\n') iLength-- ; if (iLength > 0) GpiCharStringAt (hps, &ptl, iLength, pcReadBuffer) ; } free (pcReadBuffer) ; fclose (fileInput) ; } else // file cannot be opened { ptl.y -= cyChar ; GpiCharStringAt (hps, &ptl, strlen (szErrorMsg), szErrorMsg) ; } GpiSetCharSet (hps, LCID_DEFAULT) ; GpiDeleteSetId (hps, LCID_FIXEDFONT) ; GpiDeleteSetId (hps, LCID_BOLDFONT) ; } WinEndPaint (hps) ; return 0 ; } return WinDefWindowProc (hwnd, msg, mp1, mp2) ; }
void ColumnPaint(SCREEN *pstScreen) { HPS hps; RECTL rclRect; WORD wChar; BOOL bLastWasNewLine = FALSE; WORD wDirection; LONG lReadIndex; WORD wFilterMask; BOOL bTestNewLine; WORD wNewLine; BOOL bWrap; BOOL bSkip; WORD wFunc; LONG lPacketCount; LONG lOldTop; DosRequestMutexSem(hmtxColGioBlockedSem,10000); WinInvalidateRect(pstScreen->hwndClient,(PRECTL)NULL,FALSE); hps = WinBeginPaint(pstScreen->hwndClient,(HPS)NULL,&rclRect); if (WinIsWindowShowing(pstScreen->hwndClient)) { rclRect.yBottom = 0; rclRect.yTop = (pstScreen->lHeight + stCell.cy); rclRect.xLeft = 0; rclRect.xRight = (pstScreen->lWidth + stCell.cx); WinFillRect(hps,&rclRect,pstScreen->lBackgrndColor); if (pstScreen->wDirection == CS_WRITE) { if ((stRead.lBackgrndColor == stWrite.lBackgrndColor) && (stWrite.hwndScroll == (HWND)NULL)) { rclRect.xRight = stWrite.rcl.xRight; rclRect.xLeft = stWrite.rcl.xRight - 1; rclRect.yBottom = 0; rclRect.yTop = stWrite.rcl.yTop; if (stWrite.lBackgrndColor == CLR_WHITE) WinFillRect(hps,&rclRect,CLR_BLACK); else WinFillRect(hps,&rclRect,(stWrite.lBackgrndColor ^ stWrite.lBackgrndColor)); stWrite.rclDisp.xRight = (stWrite.lWidth + stCell.cx - 1); } else stWrite.rclDisp.xRight = (stWrite.lWidth + stCell.cx); } if (stCFG.fDisplaying & (DISP_DATA | DISP_FILE)) { pstScreen->Pos.y = pstScreen->lHeight; pstScreen->Pos.x = 0; lReadIndex = pstScreen->lScrollIndex; pstScreen->rclDisp.xLeft = 0L; if (pstScreen->wDirection == CS_READ) GpiCreateLogFont(hps,(PSTR8)"HEXFONTS",2,&astFontAttributes[stCFG.wColReadFont]); else GpiCreateLogFont(hps,(PSTR8)"HEXFONTS",2,&astFontAttributes[stCFG.wColWriteFont]); GpiSetCharSet(hps,2); GpiSetColor(hps,pstScreen->lForegrndColor); if (pstScreen->bFilter) wFilterMask = (WORD)pstScreen->byDisplayMask; else wFilterMask = 0x00ff; wNewLine = (WORD)pstScreen->byNewLineChar; wDirection = pstScreen->wDirection; bTestNewLine = pstScreen->bTestNewLine; bSkip = pstScreen->bSkipBlankLines; bWrap = pstScreen->bWrap; lPacketCount = 0; while (lReadIndex < lScrollCount) { if (lPacketCount == 0) { wChar = pwScrollBuffer[lReadIndex]; wFunc = (pwScrollBuffer[lReadIndex++] & 0x0ff00); switch (wFunc) { case CS_PACKET_DATA: lPacketCount = (wChar & 0x00ff); break; case CS_WRITE_IMM: if (wFunc != CS_READ) wFunc = CS_WRITE; case CS_READ_IMM: if (wFunc != CS_WRITE) wFunc = CS_READ; case CS_WRITE: case CS_READ: if (wFunc != wDirection) continue; wChar &= wFilterMask; if (bTestNewLine && (wChar == wNewLine)) { if (bSkip && bLastWasNewLine) continue; if (CharPrintable((BYTE *)&wChar,pstScreen)) if (bWrap || (pstScreen->Pos.x <= pstScreen->lWidth)) GpiCharStringAt(hps,&pstScreen->Pos,1,(BYTE *)&wChar); if (pstScreen->Pos.y <= 0) break; pstScreen->Pos.y -= stCell.cy; bLastWasNewLine = TRUE; pstScreen->Pos.x = 0L; } else { if (CharPrintable((BYTE *)&wChar,pstScreen)) { bLastWasNewLine = FALSE; if (pstScreen->Pos.x <= pstScreen->lWidth) { GpiCharStringAt(hps,&pstScreen->Pos,1,(BYTE *)&wChar); pstScreen->Pos.x += stCell.cx; } else { if (pstScreen->bWrap) { pstScreen->Pos.x = 0; pstScreen->Pos.y -= stCell.cy; GpiCharStringAt(hps,&pstScreen->Pos,1,(BYTE *)&wChar); pstScreen->Pos.x += stCell.cx; } if (pstScreen->Pos.y < 0 ) break; } } } } } else { lPacketCount--; lReadIndex++; } } } else { // pstScreen->lLeadRow = pstScreen->lHeight; pstScreen->Pos.y = pstScreen->lHeight; pstScreen->Pos.x = 0L; } } WinEndPaint(hps); DosReleaseMutexSem(hmtxColGioBlockedSem); // WinInvalidateRect(hwndStatus,(PRECTL)NULL,FALSE); }