void ESChildSeatStatus::OnPaintClient(_DC *pDC, _Rect* pRectDC, _Rect* pRectClient){ _Rect rcClient = GetClientRect(); _Rect rcControlDC = ClientRectToDCRect(pRectDC, pRectClient, &rcClient); _Rect rcInvalid = *pRectDC&rcControlDC; _Size szClient(rcClient.Width(), rcClient.Height()); Image* pImageStatus = m_pBgImage; Image* pImageStatusActive = m_pBgActiveImage; Image* pImageStatusCurrent = m_bActive ? pImageStatusActive : pImageStatus; ESChildControlTable* pTable = (ESChildControlTable*)GetParent(); bool bAllowCaching = m_pOwner->IsDesignerMode() ? false : true; if( bAllowCaching ){ HBITMAP hImageCached = pTable->GetCachedSeatStatusImage(m_bActive); BITMAP bmInfo; memset(&bmInfo, 0, sizeof(BITMAP)); if( hImageCached ) GetObject(hImageCached, sizeof(BITMAP), &bmInfo); if( bmInfo.bmWidth != szClient.cx || bmInfo.bmHeight != szClient.cy ){ // Update cached image. pTable->FreeCachedSeatStatusImage(m_bActive); hImageCached = NULL; if( pImageStatusCurrent->ScaleBitmap(ScaleMode::ScaleMode_Bilinier, szClient.cx, szClient.cy, _Rect(0, 0, szClient.cx, szClient.cy), hImageCached, (pImageStatusCurrent->GetBPP() == 32)) ) pTable->UpdateCachedSeatStatusImage(m_bActive, hImageCached); } if( hImageCached ){ // Use cached image. Image imgTemp; imgTemp.Attach(hImageCached); m_pOwner->DrawBackground(pDC, pRectDC, pRectClient, rcClient, FillMode::FillMode_CentredImage, RGB(0, 0, 0), &imgTemp, _Rect(0, 0, 0, 0), false, (int)ScaleMode::ScaleMode_Bilinier); imgTemp.Detach(); } else{ if( pImageStatusCurrent && !pImageStatusCurrent->IsNull() ) m_pOwner->DrawBackground(pDC, pRectDC, pRectClient, rcClient, FillMode::FillMode_StretchImage, RGB(0, 0, 0), pImageStatusCurrent, m_rcOmitBorder, false, ScaleMode::ScaleMode_Bilinier); } } else{ if( pImageStatusCurrent && !pImageStatusCurrent->IsNull() ) m_pOwner->DrawBackground(pDC, pRectDC, pRectClient, rcClient, FillMode::FillMode_StretchImage, RGB(0, 0, 0), pImageStatusCurrent, m_rcOmitBorder, false, ScaleMode::ScaleMode_Bilinier); } ESChildControl::OnPaintClient(pDC, pRectDC, pRectClient); }
BOOL _DC::GetDibImageFromDC(int nBPP, Image& bmImage, UINT xSrc, UINT ySrc, UINT nWidth, UINT nHeight, _DC** pDCBitmap /*= NULL*/){ if( !context_ ){ ASSERT(FALSE); return FALSE; } HDC memDC = ::CreateCompatibleDC(NULL); BITMAPINFOHEADER bmpInfo32; memset(&bmpInfo32, 0, sizeof(BITMAPINFOHEADER)); bmpInfo32.biBitCount = nBPP; bmpInfo32.biCompression = BI_RGB; bmpInfo32.biPlanes = 1; bmpInfo32.biHeight = nHeight; bmpInfo32.biSize = sizeof(BITMAPINFOHEADER); bmpInfo32.biWidth = nWidth; void* lpMap = NULL; HBITMAP hDib = ::CreateDIBSection(memDC, (BITMAPINFO*)&bmpInfo32, DIB_RGB_COLORS, &lpMap, NULL, 0); if( !hDib ){ ::DeleteDC(memDC); return FALSE; } ::SelectObject (memDC, hDib); ::BitBlt (memDC, 0, 0, nWidth, nHeight, context_, xSrc, ySrc, SRCCOPY); if( pDCBitmap ){ *pDCBitmap = new _DC(); (*pDCBitmap)->Attach(memDC); } else{ ::DeleteDC(memDC); memDC = NULL; } bmImage.Attach(hDib); return TRUE; }
bool ESChildAvatar::SetAvatarImage(Image* pImage, bool bRedraw){ if( !pImage || pImage->IsNull() ) return false; if( !m_pImageAvatarBg || m_pImageAvatarBg->IsNull() ) return false; _Size szAvatar(m_pImageAvatarBg->GetWidth(), m_pImageAvatarBg->GetHeight()); Image bmAvatar; if( !bmAvatar.CreateDIBBitmap(32, RGB(0, 0, 0), szAvatar.cx, szAvatar.cy) ) return false; ImageDef hDest = bmAvatar; if( !pImage->ScaleBitmap_Bilinier(szAvatar.cx, szAvatar.cy, _Rect(0, 0, szAvatar.cx, szAvatar.cy), hDest, (pImage->GetBPP() == 32), 255) ){ bmAvatar.Destroy(); return false; } Image imgBg; imgBg.Attach(bmAvatar.Detach()); Image* pImgAvatar = Image::CombineImages(&imgBg, m_pImageAvatarBg, true); if( !pImgAvatar ){ imgBg.Destroy(); return false; } m_imageAvatar.Destroy(); m_imageAvatar.Attach(pImgAvatar->Detach()); m_pImageAvatar = &m_imageAvatar; imgBg.Destroy(); delete pImgAvatar; if( bRedraw ) Redraw(); return true; }
BOOL _DC::GetSelectedDibImageFromDC(Image& imageDib){ if( !context_ ){ ASSERT(FALSE); return FALSE; } Image* pTemp = GetTempImage(); ImageDef hDibImage = (HBITMAP)::SelectObject(context_, *pTemp); if( hDibImage != NULL ){ BITMAP bmInfo; if( GetObject(hDibImage, sizeof(BITMAP), &bmInfo) == sizeof(BITMAP) && bmInfo.bmBits != NULL ){ ::SelectObject(context_, hDibImage); imageDib.Attach(hDibImage); return true; } else{ ::SelectObject(context_, hDibImage); hDibImage = NULL; } } return false; }
bool EmbedeedFontMan::AddFont(const std::string sFontFolder, const std::string sFontName){ std::string sDir = sFontFolder; if( sDir[sDir.length() - 1] != '\\' ) sDir += _T("\\"); EmbedeedFont* pFont = new EmbedeedFont(); // Load characters code map. {{ BYTE* lpContent = NULL; int nSize = 0; if( Path::ReadFileContent(sDir + _T("codes.txt"), lpContent, nSize) && nSize > 0 ){ std::string sContent; sContent.resize(nSize); memcpy((void*)sContent.c_str(), lpContent, nSize); //memcpy(sContent.GetBufferSetLength(nSize), lpContent, nSize); CStringArray arrStrings; StringHelper::Split(&sContent, _T(";"), arrStrings); std::string sCharCode; for(int i=0; i<arrStrings.size(); i++){ sCharCode = arrStrings[i]; int nCharCode = 0; // Hex value if( sCharCode[0] == '#' ) nCharCode = StringHelper::HexStringIntoInt(&((TCHAR*)sCharCode.c_str())[1], sCharCode.length() - 1); else nCharCode = _ttoi(sCharCode.c_str()); pFont->m_arrCharacters.Add((void*)nCharCode, (void*)i); } } else{ #ifdef _DEBUG std::string sMsg; stringEx::Format(sMsg, _T("Couldn't find %s"), (sDir + _T("codes.txt")).c_str()); ::MessageBox(NULL, sMsg.c_str(), _T("Error"), MB_OK); #endif if( lpContent ) delete [] lpContent; delete pFont; return false; } // }} if( lpContent ){ delete [] lpContent; lpContent = NULL; } CStringArray arrFileNames; if( Path::GetFilesByExtention(sDir, _T("*.bmp"), arrFileNames, true) == 0 ){ delete pFont; return false; } for(int i=0; i<arrFileNames.size(); i++){ std::string sName = arrFileNames[i]; std::string sName2 = sName; std::string sFile = sDir + sName; if( sName.substr(0, sFontName.length()) != sFontName ) continue; // Skip wrong file name. sName.erase(0, sFontName.length()); stringEx::MakeLower(sName); int nIndex = 0; EmbedeedFontItemInfo* pInfo = new EmbedeedFontItemInfo(); pInfo->ZeroInit(); // Bold if( sName[nIndex] == 'b' ){ pInfo->m_nCharFlags |= EmbedeedFontItemInfo::EMBEDEED_FONT_FLAG_BOLD; nIndex ++; } // Underline if( sName[nIndex] == 'u' ){ pInfo->m_nCharFlags |= EmbedeedFontItemInfo::EMBEDEED_FONT_FLAG_UNDERLINE; nIndex ++; } // Italic if( sName[nIndex] == 'i' ){ pInfo->m_nCharFlags |= EmbedeedFontItemInfo::EMBEDEED_FONT_FLAG_ITALIC; nIndex ++; } // Load characters map image and detect characters left offset and width (in pixels). {{ Image* pImage = Image::LoadImage(sFile, -1, -1, false); if( pImage ){ int nWidthLimit = pImage->GetWidth(); int nWidth = pImage->GetWidth(); int nHeight = pImage->GetHeight(); int nWidthBytes = pImage->GetWidthBytes(); int nSymbolCt = 0; BYTE* pBits = (BYTE*)pImage->GetBits(); int nXOffset = 0; int nBPP = pImage->GetBPP()/8; int nSymbolMostLeftOffset = -1; int nSymbolMostRightOffset = -1; CDWordArray arrSymbolLeftOffsetAndWidth; std::string sSymbolStartPointAndWidth; int nMaxXOffset = nWidth; for(int x=nXOffset; x<nMaxXOffset; x++){ bool bClearLine = true; for(int y=0; y<nHeight; y++){ BYTE* pLineStartingBits = &pBits[((nHeight - y - 1)*nWidthBytes)]; BYTE* pPixel = &pLineStartingBits[x*nBPP]; // Is pixel visible. if( pPixel[0] > 10 ){ bClearLine = false; if( nSymbolMostLeftOffset > -1 ) nSymbolMostRightOffset = x; else nSymbolMostLeftOffset = x; continue; } pPixel = &pPixel[nBPP]; } if( bClearLine && nSymbolMostLeftOffset > -1 ){ if( nSymbolMostRightOffset == -1 ) nSymbolMostRightOffset = nSymbolMostLeftOffset; DWORD dwCombineVal = (nSymbolMostLeftOffset << 16) | ((nSymbolMostRightOffset - nSymbolMostLeftOffset + 1)&0xFFFF); arrSymbolLeftOffsetAndWidth.push_back(dwCombineVal); #ifdef _DEBUG std::string sFormat; stringEx::Format(sFormat, _T("%d:%d;"), nSymbolMostLeftOffset, nSymbolMostRightOffset - nSymbolMostLeftOffset + 1); sSymbolStartPointAndWidth += sFormat; #endif nSymbolMostLeftOffset = -1; nSymbolMostRightOffset = -1; } } pInfo->m_imageCharacters.Attach(pImage->Detach()); delete pImage; if( (arrSymbolLeftOffsetAndWidth.size() == pFont->m_arrCharacters.GetCount()) ){ pInfo->m_pCharPoints = new Point[arrSymbolLeftOffsetAndWidth.size()]; for(int j=0; j<arrSymbolLeftOffsetAndWidth.size(); j++){ DWORD dwCombineVal = arrSymbolLeftOffsetAndWidth.at(j); pInfo->m_pCharPoints[j].x = (int)(dwCombineVal>>16); pInfo->m_pCharPoints[j].y = (int)(dwCombineVal&0xFFFF); } } else{ #ifdef _DEBUG Image bmImg; bmImg.CreateDIBBitmap(pInfo->m_imageCharacters.GetBPP(), RGB(0, 0, 0), pInfo->m_imageCharacters.GetWidth(), pInfo->m_imageCharacters.GetHeight()*2, 0); _DC memDC; memDC.CreateCompatibleDC(NULL); memDC.SelectObject(bmImg); _DC srcDC; srcDC.CreateCompatibleDC(NULL); srcDC.SelectObject(pInfo->m_imageCharacters); memDC.BitBlt(0, 0, pInfo->m_imageCharacters.GetWidth(), pInfo->m_imageCharacters.GetHeight(), srcDC, 0, 0, SRCCOPY); int nHeight = pInfo->m_imageCharacters.GetHeight(); for(int j=0; j<arrSymbolLeftOffsetAndWidth.size(); j++){ DWORD dwCombineVal = arrSymbolLeftOffsetAndWidth.at(j); int nLeft = (int)(dwCombineVal>>16); int nWidth = (int)(dwCombineVal&0xFFFF); memDC.FillSolidRect(Rect(nLeft, nHeight, nLeft+nWidth, nHeight+nHeight), RGB(255, 255, 0)); } DeleteFile((sDir + _T("__") + sName2).c_str()); Image img; img.Attach((HBITMAP)bmImg.Detach()); // img.Save(sDir + _T("__") + sName2); img.Destroy(); std::string sMsg; stringEx::Format(sMsg, _T("Characters count is not the same for font '%s' item '%s'"), sFontName.c_str(), sName.c_str()); MessageBox(NULL, sMsg.c_str(), _T("Error"), MB_OK); #endif delete pInfo; continue; } pInfo->m_nCharCount = arrSymbolLeftOffsetAndWidth.size(); }