// Set shades for fonts BOOLEAN SetFontShade( UINT32 uiFontID, INT8 bColorID ) { HVOBJECT pFont; CHECKF( bColorID > 0 ); CHECKF( bColorID < 16 ); pFont = GetFontObject( uiFontID ); pFont->pShadeCurrent = pFont->pShades[ bColorID ]; return( TRUE ); }
CSize CGridBtnCellBase::GetCellExtent(CDC* pDC) { CSize sizeBase = CGridCellBase::GetCellExtent(pDC); // any button images? int iCtlNbr = GetDrawCtlNbr(); if( iCtlNbr > 0) { int iDefaultWidth = sizeBase.cy; int iWidthTotal = 0; int iWidth; CSize SizeText; CFont* pOldFont = pDC->SelectObject(GetFontObject()); CRect rectText; for( int i1=0; i1 < iCtlNbr; i1++) { iWidth = GetDrawCtlWidth( i1); if( iWidth <= 0) { const char* pszBtnText = GetDrawCtlBtnText( i1); if( pszBtnText == NULL) { iWidth = iDefaultWidth; } else { // use width of text in button as a gauge rectText.SetRectEmpty(); pDC->DrawText( pszBtnText, strlen( pszBtnText), &rectText, GetFormat() | DT_CALCRECT); iWidth = rectText.Width(); } } iWidthTotal += iWidth; } pDC->SelectObject(pOldFont); sizeBase += CSize( iWidthTotal + 4*GetMargin(), 0); } return sizeBase; }
BOOL CGridBtnCellBase::DrawBtnCell(CDC* pDC, int /* nRow */, int /* nCol */, CRect* prect, BOOL /* bEraseBkgnd */) { CGridCtrl* pGrid = GetGrid(); if (!pGrid || !pDC) return FALSE; if( prect->Width() <= 0 || prect->Height() <= 0) // prevents imagelist item from drawing even return FALSE; // though cell is hidden int nSavedDC = pDC->SaveDC(); // draw any button images ASSERT( MAX_NBR_CTLS_INCELL > GetDrawCtlNbrMax() ); // whoa! const int iCtlNbr = GetDrawCtlNbr(); CRect RectAry[ MAX_NBR_CTLS_INCELL]; if( iCtlNbr > 0) { if( GetState() & GVIS_SELECTED || GetState() & GVIS_DROPHILITED ) { // draw the rectangle around the grid -- // we may be filling cells with controls pDC->SelectStockObject(BLACK_PEN); pDC->SelectStockObject(NULL_BRUSH); pDC->Rectangle(*prect); } pDC->SetBkMode(TRANSPARENT); prect->DeflateRect( GetMargin(), 0); CFont* pOldFont = pDC->SelectObject(GetFontObject()); if( CalcDrawCtlRects( RectAry, // returns: CRects with coordinates // last entry has optional leftover rect // available for text, etc. MAX_NBR_CTLS_INCELL,// nbr of Rects in above array *prect) ) // cell rectangle to work with { for( int i1=0; i1 < iCtlNbr; i1++) { UINT uiType = GetDrawCtlType( i1); UINT uiState = GetDrawCtlState( i1); pDC->DrawFrameControl( RectAry[ i1], uiType, uiState); // if button has text, draw it, too const char* pszBtnText = GetDrawCtlBtnText( i1); if( pszBtnText != NULL) { COLORREF ColorCurrent = pDC->GetTextColor(); if( uiState & DFCS_INACTIVE) { // button is grayed-out // draw the text so that it matches MS's look RectAry[ i1].OffsetRect( 1, 1); pDC->SetTextColor( RGB( 255,255,255) ); pDC->DrawText( pszBtnText, -1, RectAry[ i1], DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS); RectAry[ i1].OffsetRect( -1, -1); pDC->SetTextColor( ::GetSysColor(COLOR_GRAYTEXT)); } else { pDC->SetTextColor( ::GetSysColor(COLOR_BTNTEXT)); } pDC->DrawText( pszBtnText, -1, RectAry[ i1], DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS); pDC->SetTextColor( ColorCurrent); } } // allowable text area has shrunk up *prect = RectAry[ iCtlNbr]; } pDC->SelectObject(pOldFont); // maybe there's nothing left to draw if( prect->Width() <= 0) { pDC->RestoreDC(nSavedDC); return TRUE; } } pDC->RestoreDC(nSavedDC); return TRUE; }
// This hack allows you to determine the height that a cell should be in order to display // stuff properly in the given width. CSize CGridCellMultiLine::GetTextExtentEx(int width, LPCTSTR szText, CDC* pDC /*= NULL*/) { CGridCtrl* pGrid = GetGrid(); ASSERT(pGrid); BOOL bReleaseDC = FALSE; if (pDC == NULL) { pDC = pGrid->GetDC(); if (!pDC) { CGridDefaultCell* pDefCell = (CGridDefaultCell*) GetDefaultCell(); ASSERT(pDefCell); return CSize(pDefCell->GetWidth(), pDefCell->GetHeight()); } bReleaseDC = TRUE; } CFont *pOldFont = NULL, *pFont = GetFontObject(); if (pFont) pOldFont = pDC->SelectObject(pFont); CSize size; int nFormat = GetFormat(); TEXTMETRIC tm; pDC->GetTextMetrics(&tm); int textWidth = width - (4*GetMargin ()); // corrects the bug if resizing column gives a text width smaller than (4*Getmargin()) if (textWidth <= 0) { textWidth = 1; } // If the cell is a multiline cell, then use the width of the cell // to get the height if ((nFormat & DT_WORDBREAK) && !(nFormat & DT_SINGLELINE)) { CRect rect; rect.SetRect(0, 0, textWidth, 0); pDC->DrawText(szText, -1, rect, nFormat | DT_CALCRECT); size.cx = rect.Width (); size.cy = rect.Height (); } else size = pDC->GetTextExtent(szText, _tcslen(szText)); size.cx += (tm.tmOverhang); if (pOldFont) pDC->SelectObject(pOldFont); size += CSize(4*GetMargin(), 2*GetMargin()); // Kludge for vertical text LOGFONT *pLF = GetFont(); if (pLF->lfEscapement == 900 || pLF->lfEscapement == -900) { int nTemp = size.cx; size.cx = size.cy; size.cy = nTemp; size += CSize(0, 4*GetMargin()); } if (bReleaseDC) pGrid->ReleaseDC(pDC); return size; }
BOOLEAN WrapString( INT16 *pStr, INT16 *pStr2, UINT16 usWidth, INT32 uiFont ) { UINT32 Cur, uiLet, uiNewLet, uiHyphenLet; UINT16 *curletter,transletter; BOOLEAN fLineSplit = FALSE; HVOBJECT hFont; // CHECK FOR WRAP Cur=0; uiLet = 0; curletter=pStr; // GET FONT hFont = GetFontObject( uiFont ); // LOOP FORWARDS AND COUNT while((*curletter)!=0) { transletter=GetIndex(*curletter); Cur+=GetWidth( hFont, transletter ); if ( Cur > usWidth ) { // We are here, loop backwards to find a space // Generate second string, and exit upon completion. uiHyphenLet = uiLet; //Save the hyphen location as it won't change. uiNewLet = uiLet; while((*curletter)!=0) { if ( (*curletter) == 32 ) { // Split Line! fLineSplit = TRUE; pStr[ uiNewLet ] = (INT16)'\0'; wcscpy( pStr2, &(pStr[ uiNewLet + 1 ]) ); } if ( fLineSplit ) break; uiNewLet--; curletter--; } if( !fLineSplit) { //We completed the check for a space, but failed, so use the hyphen method. swprintf( pStr2, L"-%s", &(pStr[uiHyphenLet]) ); pStr[uiHyphenLet] = (INT16)'/0'; fLineSplit = TRUE; //hyphen method break; } } // if ( fLineSplit ) // break; uiLet++; curletter++; } return( fLineSplit ); }
BOOLEAN InitializeFonts( ) { //INT16 zWinFontName[128]; // unused (jonathanl) //COLORVAL Color; // usused (jonathanl) // Initialize fonts // gpLargeFontType1 = LoadFontFile( "FONTS\\lfont1.sti" ); gpLargeFontType1 = LoadFontFile( "FONTS\\LARGEFONT1.sti" ); gvoLargeFontType1 = GetFontObject( gpLargeFontType1 ); CHECKF( CreateFontPaletteTables( gvoLargeFontType1 ) ); // gpSmallFontType1 = LoadFontFile( "FONTS\\6b-font.sti" ); gpSmallFontType1 = LoadFontFile( "FONTS\\SMALLFONT1.sti" ); gvoSmallFontType1 = GetFontObject( gpSmallFontType1 ); CHECKF( CreateFontPaletteTables( gvoSmallFontType1 ) ); // gpTinyFontType1 = LoadFontFile( "FONTS\\tfont1.sti" ); gpTinyFontType1 = LoadFontFile( "FONTS\\TINYFONT1.sti" ); gvoTinyFontType1 = GetFontObject( gpTinyFontType1 ); CHECKF( CreateFontPaletteTables( gvoTinyFontType1 ) ); // gp12PointFont1 = LoadFontFile( "FONTS\\font-12.sti" ); gp12PointFont1 = LoadFontFile( "FONTS\\FONT12POINT1.sti" ); gvo12PointFont1 = GetFontObject( gp12PointFont1 ); CHECKF( CreateFontPaletteTables( gvo12PointFont1 ) ); // gpClockFont = LoadFontFile( "FONTS\\DIGI.sti" ); gpClockFont = LoadFontFile( "FONTS\\CLOCKFONT.sti" ); gvoClockFont = GetFontObject( gpClockFont ); CHECKF( CreateFontPaletteTables( gvoClockFont ) ); // gpCompFont = LoadFontFile( "FONTS\\compfont.sti" ); gpCompFont = LoadFontFile( "FONTS\\COMPFONT.sti" ); gvoCompFont = GetFontObject( gpCompFont ); CHECKF( CreateFontPaletteTables( gvoCompFont ) ); // gpSmallCompFont = LoadFontFile( "FONTS\\scfont.sti" ); gpSmallCompFont = LoadFontFile( "FONTS\\SMALLCOMPFONT.sti" ); gvoSmallCompFont = GetFontObject( gpSmallCompFont ); CHECKF( CreateFontPaletteTables( gvoSmallCompFont ) ); // gp10PointRoman = LoadFontFile( "FONTS\\Roman10.sti" ); gp10PointRoman = LoadFontFile( "FONTS\\FONT10ROMAN.sti" ); gvo10PointRoman = GetFontObject( gp10PointRoman ); CHECKF( CreateFontPaletteTables( gvo10PointRoman ) ); // gp12PointRoman = LoadFontFile( "FONTS\\Roman12.sti" ); gp12PointRoman = LoadFontFile( "FONTS\\FONT12ROMAN.sti" ); gvo12PointRoman = GetFontObject( gp12PointRoman ); CHECKF( CreateFontPaletteTables( gvo12PointRoman ) ); // gp14PointSansSerif = LoadFontFile( "FONTS\\SansSerif14.sti" ); gp14PointSansSerif = LoadFontFile( "FONTS\\FONT14SANSERIF.sti" ); gvo14PointSansSerif = GetFontObject( gp14PointSansSerif); CHECKF( CreateFontPaletteTables( gvo14PointSansSerif) ); // DEF: Removed. Replaced with BLOCKFONT // gpMilitaryFont1 = LoadFontFile( "FONTS\\milfont.sti" ); // gvoMilitaryFont1 = GetFontObject( gpMilitaryFont1); // CHECKF( CreateFontPaletteTables( gvoMilitaryFont1) ); // gp10PointArial = LoadFontFile( "FONTS\\Arial10.sti" ); gp10PointArial = LoadFontFile( "FONTS\\FONT10ARIAL.sti" ); gvo10PointArial = GetFontObject( gp10PointArial); CHECKF( CreateFontPaletteTables( gvo10PointArial) ); // gp14PointArial = LoadFontFile( "FONTS\\Arial14.sti" ); gp14PointArial = LoadFontFile( "FONTS\\FONT14ARIAL.sti" ); gvo14PointArial = GetFontObject( gp14PointArial); CHECKF( CreateFontPaletteTables( gvo14PointArial) ); // gp10PointArialBold = LoadFontFile( "FONTS\\Arial10Bold2.sti" ); gp10PointArialBold = LoadFontFile( "FONTS\\FONT10ARIALBOLD.sti" ); gvo10PointArialBold = GetFontObject( gp10PointArialBold); CHECKF( CreateFontPaletteTables( gvo10PointArialBold) ); // gp12PointArial = LoadFontFile( "FONTS\\Arial12.sti" ); gp12PointArial = LoadFontFile( "FONTS\\FONT12ARIAL.sti" ); gvo12PointArial = GetFontObject( gp12PointArial); CHECKF( CreateFontPaletteTables( gvo12PointArial) ); // gpBlockyFont = LoadFontFile( "FONTS\\FONT2.sti" ); gpBlockyFont = LoadFontFile( "FONTS\\BLOCKFONT.sti" ); gvoBlockyFont = GetFontObject( gpBlockyFont); CHECKF( CreateFontPaletteTables( gvoBlockyFont) ); // gpBlockyFont2 = LoadFontFile( "FONTS\\interface_font.sti" ); gpBlockyFont2 = LoadFontFile( "FONTS\\BLOCKFONT2.sti" ); gvoBlockyFont2 = GetFontObject( gpBlockyFont2); CHECKF( CreateFontPaletteTables( gvoBlockyFont2) ); gpBlockyFont3 = LoadFontFile( "FONTS\\BLOCKFONT2.sti" ); gvoBlockyFont3 = GetFontObject( gpBlockyFont3); CHECKF( CreateFontPaletteTables( gvoBlockyFont3) ); // gp12PointArialFixedFont = LoadFontFile( "FONTS\\Arial12FixedWidth.sti" ); gp12PointArialFixedFont = LoadFontFile( "FONTS\\FONT12ARIALFIXEDWIDTH.sti" ); gvo12PointArialFixedFont = GetFontObject( gp12PointArialFixedFont ); CHECKF( CreateFontPaletteTables( gvo12PointArialFixedFont ) ); gp16PointArial = LoadFontFile( "FONTS\\FONT16ARIAL.sti" ); gvo16PointArial = GetFontObject( gp16PointArial ); CHECKF( CreateFontPaletteTables( gvo16PointArial ) ); gpBlockFontNarrow = LoadFontFile( "FONTS\\BLOCKFONTNARROW.sti" ); gvoBlockFontNarrow = GetFontObject( gpBlockFontNarrow ); CHECKF( CreateFontPaletteTables( gvoBlockFontNarrow ) ); gp14PointHumanist = LoadFontFile( "FONTS\\FONT14HUMANIST.sti" ); gvo14PointHumanist = GetFontObject( gp14PointHumanist ); CHECKF( CreateFontPaletteTables( gvo14PointHumanist ) ); #if defined( JA2EDITOR ) && defined( ENGLISH ) gpHugeFont = LoadFontFile( "FONTS\\HUGEFONT.sti" ); gvoHugeFont = GetFontObject( gpHugeFont ); CHECKF( CreateFontPaletteTables( gvoHugeFont ) ); #endif // Set default for font system SetFontDestBuffer( FRAME_BUFFER, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, FALSE ); gfFontsInit = TRUE; // ATE: Init WinFont System and any winfonts we wish... if ( iUseWinFonts ) { InitWinFonts( ); } return( TRUE ); }