//位图转换到区域 (需要重写) HRGN AFCBmpToRgn(HBITMAP hBmp, COLORREF cTransparentColor, COLORREF cTolerance) { if (hBmp==NULL) return NULL; HRGN hRgn=NULL; HDC hMemDC=::CreateCompatibleDC(NULL); if (hMemDC!=NULL) { BITMAP bm; GetObject(hBmp, sizeof(bm), &bm); VOID * pbits32=NULL; BITMAPINFOHEADER RGB32BITSBITMAPINFO = {sizeof(BITMAPINFOHEADER),bm.bmWidth,bm.bmHeight,1,32,BI_RGB,0,0,0,0,0}; HBITMAP hbm32 = CreateDIBSection(hMemDC, (BITMAPINFO *)&RGB32BITSBITMAPINFO, DIB_RGB_COLORS, &pbits32, NULL, 0); if (hbm32) { HBITMAP holdBmp = (HBITMAP)SelectObject(hMemDC, hbm32); HDC hDC = CreateCompatibleDC(hMemDC); if (hDC) { BITMAP bm32; GetObject(hbm32,sizeof(bm32),&bm32); while (bm32.bmWidthBytes%4) bm32.bmWidthBytes++; HBITMAP holdBmp=(HBITMAP)SelectObject(hDC,hBmp); BitBlt(hMemDC,0,0,bm.bmWidth,bm.bmHeight,hDC,0,0,SRCCOPY); #define ALLOC_UNIT 100 DWORD maxRects=ALLOC_UNIT; HANDLE hData=GlobalAlloc(GMEM_MOVEABLE, sizeof(RGNDATAHEADER) + (sizeof(RECT) * maxRects)); RGNDATA *pData=(RGNDATA *)GlobalLock(hData); pData->rdh.dwSize=sizeof(RGNDATAHEADER); pData->rdh.iType=RDH_RECTANGLES; pData->rdh.nCount=pData->rdh.nRgnSize=0; SetRect(&pData->rdh.rcBound, MAXLONG, MAXLONG, 0, 0); // Keep on hand highest and lowest values for the "transparent" pixels BYTE lr = GetRValue(cTransparentColor); BYTE lg = GetGValue(cTransparentColor); BYTE lb = GetBValue(cTransparentColor); BYTE hr = min(0xff, lr + GetRValue(cTolerance)); BYTE hg = min(0xff, lg + GetGValue(cTolerance)); BYTE hb = min(0xff, lb + GetBValue(cTolerance)); // Scan each bitmap row from bottom to top (the bitmap is inverted vertically) BYTE *p32=(BYTE *)bm32.bmBits + (bm32.bmHeight - 1) * bm32.bmWidthBytes; for (int y=0;y<bm.bmHeight;y++) { // Scan each bitmap pixel from left to right for (int x=0;x<bm.bmWidth;x++) { // Search for a continuous range of "non transparent pixels" int x0=x; LONG *p=(LONG *)p32+x; while (x<bm.bmWidth) { BYTE b=GetRValue(*p); if (b>=lr&&b<=hr) { b=GetGValue(*p); if (b>=lg&&b<=hg) { b = GetBValue(*p); if (b >= lb && b <= hb) break; } } p++; x++; } if (x>x0) { // Add the pixels (x0, y) to (x, y+1) as a new rectangle in the region if (pData->rdh.nCount >= maxRects) { GlobalUnlock(hData); maxRects += 100; hData = GlobalReAlloc(hData, sizeof(RGNDATAHEADER) + (sizeof(RECT) * maxRects), GMEM_MOVEABLE); pData = (RGNDATA *)GlobalLock(hData); } RECT *pr = (RECT *)&pData->Buffer; SetRect(&pr[pData->rdh.nCount], x0, y, x, y+1); if (x0 < pData->rdh.rcBound.left) pData->rdh.rcBound.left = x0; if (y < pData->rdh.rcBound.top) pData->rdh.rcBound.top = y; if (x > pData->rdh.rcBound.right) pData->rdh.rcBound.right = x; if (y+1 > pData->rdh.rcBound.bottom) pData->rdh.rcBound.bottom = y+1; pData->rdh.nCount++; // On Windows98, ExtCreateRegion() may fail if the number of rectangles is too // large (ie: > 4000). Therefore, we have to create the region by multiple steps. if (pData->rdh.nCount == 2000) { HRGN h = ExtCreateRegion(NULL, sizeof(RGNDATAHEADER) + (sizeof(RECT) * maxRects), pData); if (hRgn) { CombineRgn(hRgn, hRgn, h, RGN_OR); DeleteObject(h); } else hRgn = h; pData->rdh.nCount = 0; SetRect(&pData->rdh.rcBound, MAXLONG, MAXLONG, 0, 0); } } } p32 -= bm32.bmWidthBytes; } HRGN h = ExtCreateRegion(NULL, sizeof(RGNDATAHEADER) + (sizeof(RECT) * maxRects), pData); if (hRgn) { CombineRgn(hRgn, hRgn, h, RGN_OR); DeleteObject(h); } else hRgn = h; // Clean up GlobalFree(hData); SelectObject(hDC, holdBmp); DeleteDC(hDC); } DeleteObject(SelectObject(hMemDC, holdBmp)); } DeleteDC(hMemDC); } return hRgn; }
/** * Returns the red part of the color * @return The red part of the color (0-255) */ constexpr uint8_t Red() const { return GetRValue(value); }
BOOL CImageDialog::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here m_btnMask.EnableOtherButton(_T("Other")); m_btnMask.SetColor((COLORREF)0); m_btnMask.SetColumnsNumber(10); m_ctlFade.SetRange(0,255); m_ctlFade.SetPos(255); m_pManager=g_pMainFrame->GetActiveUIView()->GetPaintManager(); m_ImagePreview.SetManager(m_pManager); g_HookAPI.EnableAddImage(false); m_strImagePathName=m_strImageProperty; LPCTSTR pStrImage=m_strImageProperty; CStdString sItem; CStdString sValue; LPTSTR pstr = NULL; while( *pStrImage != _T('\0') ) { sItem.Empty(); sValue.Empty(); while( *pStrImage != _T('\0') && *pStrImage != _T('=') ) { LPTSTR pstrTemp = ::CharNext(pStrImage); while( pStrImage < pstrTemp) { sItem += *pStrImage++; } } if( *pStrImage++ != _T('=') ) break; if( *pStrImage++ != _T('\'') ) break; while( *pStrImage != _T('\0') && *pStrImage != _T('\'') ) { LPTSTR pstrTemp = ::CharNext(pStrImage); while( pStrImage < pstrTemp) { sValue += *pStrImage++; } } if( *pStrImage++ != _T('\'') ) break; if( !sValue.IsEmpty() ) { if( sItem == _T("file")) m_strImagePathName = sValue; else if( sItem == _T("dest") ) m_strDest = sValue; else if( sItem == _T("source") ) m_strSource = sValue; else if( sItem == _T("corner") ) m_strCorner = sValue; else if( sItem == _T("mask") ) { DWORD dwMask; if( sValue[0] == _T('#')) dwMask = _tcstoul(sValue.GetData() + 1, &pstr, 16); else dwMask = _tcstoul(sValue.GetData(), &pstr, 16); dwMask&=0x00FFFFFF; m_btnMask.SetColor(RGB(GetBValue(dwMask),GetGValue(dwMask),GetRValue(dwMask))); } else if( sItem == _T("fade") ) { m_nFade = (BYTE)_tcstoul(sValue.GetData(), &pstr, 10); } else if( sItem == _T("hole") ) { m_bHole = (_tcscmp(sValue.GetData(), _T("true")) == 0); } } if( *pStrImage++ != _T(' ') ) break; } m_ctlFade.SetPos(m_nFade); int nIndex=m_lstImages.AddString(_T("(无)")); m_lstImages.SetItemDataPtr(nIndex,(void*)(LPCTSTR)m_strNullImage); const CStringArray* parrImage=g_pResourceView->GetAllImage(); LPCTSTR pstrImage=NULL; LPTSTR pszFileName=NULL; for(int i=0; i<parrImage->GetSize(); i++) { pstrImage=parrImage->GetAt(i); pszFileName=_tcsrchr((LPTSTR)pstrImage,_T('\\'))+1; nIndex=m_lstImages.AddString(pszFileName); m_lstImages.SetItemDataPtr(nIndex,(void*)pstrImage); } pstrImage=m_strImagePathName; pszFileName=_tcsrchr((LPTSTR)pstrImage,_T('\\'))+1; m_strImagePathName.IsEmpty()?m_lstImages.SelectString(-1,_T("(无)")):m_lstImages.SelectString(-1,pszFileName); UpdateData(FALSE); SetImageProperty(m_strImagePathName); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
void MaterialPreviewPropView::OnPropertyChangeNotification( NMHDR *nmhdr, LRESULT *lresult ) { idVec3 testColor; int lightId = 0; COLORREF color; NMPROPTREE *nmProp; CPropTreeItem *item; CPropTreeItem *parent; nmProp = (NMPROPTREE *)nmhdr; item = nmProp->pItem; // Determine which light this item modifies parent = item->GetParent(); if ( parent ) { lightId = parent->GetCtrlID(); } idStr itemLabel = item->GetLabelText(); if ( itemLabel == "Model Type" ) { materialPreview->OnModelChange( item->GetItemValue() ); } else if ( itemLabel == "Custom Model" ) { materialPreview->OnCustomModelChange( (const char *)item->GetItemValue() ); } else if ( itemLabel == "Show Lights" ) { materialPreview->OnShowLightsChange( item->GetItemValue() ? true : false ); } else if ( itemLabel == "Shader" ) { CPropTreeItemCombo *combo = (CPropTreeItemCombo *)item; CString materialName; combo->GetLBText( combo->GetCurSel(), materialName ); materialPreview->OnLightShaderChange( lightId, materialName.GetBuffer() ); } else if ( itemLabel == "Radius" ) { materialPreview->OnLightRadiusChange( lightId, atof( (char *)item->GetItemValue() ) ); } else if ( itemLabel == "Color" ) { color = item->GetItemValue(); testColor.x = (float)GetRValue( color ) * (float)( 1.f/255.f ); testColor.y = (float)GetGValue( color ) * (float)( 1.f/255.f ); testColor.z = (float)GetBValue( color ) * (float)( 1.f/255.f ); materialPreview->OnLightColorChange( lightId, testColor ); } else if ( itemLabel == "Move light" ) { materialPreview->OnLightAllowMoveChange( lightId, item->GetItemValue() ? true : false ); } else if ( itemLabel.Left(4) == "parm" ) { int index; itemLabel.Strip( "parm" ); index = atoi( itemLabel.c_str() ); materialPreview->OnLocalParmChange( index, atof( (char *)item->GetItemValue() ) ); } else if ( itemLabel.Left(6) == "global" ) { int index; itemLabel.Strip( "global" ); index = atoi( itemLabel.c_str() ); materialPreview->OnGlobalParmChange( index, atof( (char *)item->GetItemValue() ) ); } }
long CMUSHclientDoc::FilterPixel(long Pixel, short Operation, double Options) { long r = GetRValue (Pixel), g = GetGValue (Pixel), b = GetBValue (Pixel); switch (Operation) { case 1: // Noise { double threshold = Options / 100.0; r += (128 - genrand () * 256) * threshold; g += (128 - genrand () * 256) * threshold; b += (128 - genrand () * 256) * threshold; break; } case 2: // MonoNoise { double threshold = Options / 100.0; long j = (128 - genrand () * 256) * threshold; r += j; g += j; b += j; break; } case 7: // Brightness { r += Options; g += Options; b += Options; break; } case 8: // Contrast { double c; c = r - 128; // center on zero c *= Options; // multiply by contrast r = c + 128; // put back c = g - 128; // center on zero c *= Options; // multiply by contrast g = c + 128; // put back c = b - 128; // center on zero c *= Options; // multiply by contrast b = c + 128; // put back break; } case 9: // Gamma { double c; if (Options < 0.0) Options = 0.0; c = ( (double) r) / 255.0; // normalize it c = pow (c, Options); r = c * 255.0; c = ( (double) g) / 255.0; // normalize it c = pow (c, Options); g = c * 255.0; c = ( (double) b) / 255.0; // normalize it c = pow (c, Options); b = c * 255.0; break; } case 10: // ColourBrightness - red { r += Options; break; } case 11: // ColourContrast - red { double c; c = r - 128; // center on zero c *= Options; // multiply by contrast r = c + 128; // put back break; } case 12: // ColourGamma - red { double c; if (Options < 0.0) Options = 0.0; c = ( (double) r) / 255.0; // normalize it c = pow (c, Options); r = c * 255.0; break; } case 13: // ColourBrightness - green { g += Options; break; } case 14: // ColourContrast - green { double c; c = g - 128; // center on zero c *= Options; // multiply by contrast g = c + 128; // put back break; } case 15: // ColourGamma - green { double c; if (Options < 0.0) Options = 0.0; c = ( (double) g) / 255.0; // normalize it c = pow (c, Options); g = c * 255.0; break; } case 16: // ColourBrightness - blue { b += Options; break; } case 17: // ColourContrast - blue { double c; c = b - 128; // center on zero c *= Options; // multiply by contrast b = c + 128; // put back break; } case 18: // ColourGamma - blue { double c; if (Options < 0.0) Options = 0.0; c = ( (double) b) / 255.0; // normalize it c = pow (c, Options); b = c * 255.0; break; } case 19: // MakeGreyscale - linear { double c; c = r + g + b; c /= 3; r = c; g = c; b = c; break; } case 20: // MakeGreyscale - perceptual { double c; c = b * 0.11 + // blue (perceptual) g * 0.59 + // green r * 0.30; // red c /= 3; r = c; g = c; b = c; break; } case 21: // Brightness - multiplicative { r *= Options; g *= Options; b *= Options; break; } case 22: // Brightness - multiplicative - red { r *= Options; break; } case 23: // Brightness - multiplicative - green { g *= Options; break; } case 24: // Brightness - multiplicative - blue { b *= Options; break; } case 27: // Average (of 1 pixel is itself) break; default: return -1; } // end of switch return RGB (CLAMP (r), CLAMP (g), CLAMP (b)); } // end of CMUSHclientDoc::FilterPixel
void Site::Draw(CDC* pDC) { //设置TextOut的属性 CFont font; LOGFONT lf; memset(&lf, 0, sizeof(LOGFONT)); lf.lfHeight = 15; //字体的高 lf.lfWidth = 8; //字体宽 font.CreateFontIndirect(&lf); pDC->SelectObject(&font); HDC hdc=pDC->GetSafeHdc (); ::SetBkMode(hdc,TRANSPARENT); ::SetTextColor (hdc, RGB(255,255,0)); if(ID>0)//只绘制动态点,静态点副本不绘制! { COLORREF c=RGB(255-GetRValue(Color) ,255-GetGValue(Color) ,255-GetBValue(Color)); App_Veriable::DefaultSiteSeletedModeColor=c; CPen pen; if(ID==App_Veriable::SelectedSiteID)//选中的路径 { pen.CreatePen (PS_SOLID,1,App_Veriable::DefaultSiteSeletedModeColor); } else pen.CreatePen (PS_SOLID,1,Color); pDC->SelectObject(pen); if(Style=='C') pDC->Ellipse(Position.x-Size/2,Position.y-Size/2,Position.x+Size/2,Position.y+Size/2); if(Style=='T') { pDC->MoveTo(Position.x,Position.y-sqrt(3.0)*Size/3); pDC->LineTo(Position.x-Size/2,Position.y+sqrt(3.0)*Size/6); pDC->MoveTo(Position.x-Size/2,Position.y+sqrt(3.0)*Size/6); pDC->LineTo(Position.x+Size/2,Position.y+sqrt(3.0)*Size/6); pDC->MoveTo(Position.x+Size/2,Position.y+sqrt(3.0)*Size/6); pDC->LineTo(Position.x,Position.y-sqrt(3.0)*Size/3); } if(Style=='R') pDC->Rectangle(Position.x-Size/2,Position.y-Size/2,Position.x+Size/2,Position.y+Size/2); pen.DeleteObject(); CBrush brush; if(ID==App_Veriable::SelectedSiteID)//选中的路径 brush.CreateSolidBrush (App_Veriable::DefaultSiteSeletedModeColor); else brush.CreateSolidBrush (Color); pDC->SelectObject(brush); if(Style=='C') { /*CRgn c; c.CreateEllipticRgn(Position.x-Size/2,Position.y-Size/2,Position.x+Size/2,Position.x+Size/2); pDC->FillRgn (&c,&brush); c.DeleteObject();*/ pDC->Ellipse(Position.x-Size/2,Position.y-Size/2,Position.x+Size/2,Position.y+Size/2);//效果更好??? } if(Style=='T') { CPoint points[3]; points[0].x=Position.x; points[0].y=Position.y-sqrt(3.0)*Size/3; points[1].x=Position.x-Size/2; points[1].y=Position.y+sqrt(3.0)*Size/6; points[2].x=Position.x+Size/2; points[2].y=Position.y+sqrt(3.0)*Size/6; CRgn c; c.CreatePolygonRgn (points,3,WINDING); pDC->FillRgn (&c,&brush); c.DeleteObject(); } if(Style=='R') { CRgn c; c.CreateRectRgn (Position.x-Size/2,Position.y-Size/2,Position.x+Size/2,Position.y+Size/2); pDC->FillRgn (&c,&brush); c.DeleteObject(); /*pDC->Rectangle(Position.x-Size/2,Position.y-Size/2,Position.x+Size/2,Position.x+Size/2);*///不能用,好奇怪??? } if(this->SiteInfo!=App_Veriable::DefaultSiteInfo&&App_Veriable::ShowSiteInfo) pDC->TextOutW(this->Position.x,this->Position.y,this->SiteInfo); brush.DeleteObject(); } }
// This is what does the work in the background thread UINT CHexEditDoc::RunAerialThread() { // Keep looping until we are told to die for (;;) { // Signal that we are waiting then wait for start_aerial_event_ to be pulsed { CSingleLock sl(&docdata_, TRUE); aerial_state_ = WAITING; } TRACE1("+++ BGAerial: waiting for %p\n", this); DWORD wait_status = ::WaitForSingleObject(HANDLE(start_aerial_event_), INFINITE); docdata_.Lock(); aerial_state_ = SCANNING; docdata_.Unlock(); start_aerial_event_.ResetEvent(); ASSERT(wait_status == WAIT_OBJECT_0); TRACE1("+++ BGAerial: got event for %p\n", this); if (AerialProcessStop()) continue; // Reset for new scan docdata_.Lock(); aerial_fin_ = false; aerial_addr_ = 0; FILE_ADDRESS file_len = length_; int file_bpe = bpe_; unsigned char *file_dib = FreeImage_GetBits(dib_); unsigned dib_size = FreeImage_GetDIBSize(dib_); docdata_.Unlock(); TRACE("+++ BGAerial: using bitmap at %p\n", file_dib); // Get the file buffer size_t buf_len = (size_t)min(file_len, 65536); ASSERT(aerial_buf_ == NULL); aerial_buf_ = new unsigned char[buf_len]; for (;;) { // First check if we need to stop if (AerialProcessStop()) break; // stop processing and go back to WAITING state // Check if we have finished scanning the file if (aerial_addr_ >= file_len) { TRACE2("+++ BGAerial: finished scan for %p at address %p\n", this, file_dib + 3*size_t(aerial_addr_/file_bpe)); CSingleLock sl(&docdata_, TRUE); // Protect shared data access aerial_fin_ = true; break; // falls out to end_scan } // Get the next buffer full from the file and scan it size_t got = GetData(aerial_buf_, buf_len, aerial_addr_, 3); ASSERT(got <= buf_len); unsigned char *pbm = file_dib + 3*size_t(aerial_addr_/file_bpe); // where we write to bitmap unsigned char *pbuf; // where we read from the file buffer for (pbuf = aerial_buf_; pbuf < aerial_buf_ + got; pbuf += file_bpe, pbm += 3) { int r, g, b; r = g = b = 0; for (unsigned char *pp = pbuf; pp < pbuf + file_bpe; ++pp) { r += GetRValue(kala_[*pp]); g += GetGValue(kala_[*pp]); b += GetBValue(kala_[*pp]); } *pbm = unsigned char(b/file_bpe); *(pbm+1) = unsigned char(g/file_bpe); *(pbm+2) = unsigned char(r/file_bpe); } aerial_addr_ += got; } delete[] aerial_buf_; aerial_buf_ = NULL; } return 0; // never reached }
Color RenderThemeWinCE::platformActiveSelectionForegroundColor() const { COLORREF color = GetSysColor(COLOR_HIGHLIGHTTEXT); return Color(GetRValue(color), GetGValue(color), GetBValue(color), 255); }
//***************************************************************************************** void CBCGPColorMenuButton::OnDraw (CDC* pDC, const CRect& rect, CBCGPToolBarImages* pImages, BOOL bHorz, BOOL bCustomizeMode, BOOL bHighlight, BOOL bDrawBorder, BOOL bGrayDisabledButtons) { ASSERT_VALID (this); ASSERT_VALID (pDC); CBCGPToolbarMenuButton::OnDraw (pDC, rect, pImages, bHorz, bCustomizeMode, bHighlight, bDrawBorder, bGrayDisabledButtons); if (!IsDrawImage () || pImages == NULL) { return; } CPalette* pOldPalette = NULL; if (globalData.m_nBitsPerPixel == 8) // 256 colors { if (m_Palette.GetSafeHandle () == NULL) { //---------------------------------------- // Palette not created yet; create it now //---------------------------------------- CBCGPColorBar::CreatePalette (m_Colors, m_Palette); } ASSERT (m_Palette.GetSafeHandle () != NULL); pOldPalette = pDC->SelectPalette (&m_Palette, FALSE); pDC->RealizePalette (); } else if (m_Palette.GetSafeHandle () != NULL) { ::DeleteObject (m_Palette.Detach ()); ASSERT (m_Palette.GetSafeHandle () == NULL); } ASSERT (pImages != NULL); CRect rectColor = pImages->GetLastImageRect (); const int nColorBoxSize = CBCGPToolBar::IsLargeIcons () && !m_bMenuMode ? 10 : 5; rectColor.top = rectColor.bottom - nColorBoxSize; rectColor.OffsetRect (0, 1); //---------------- // Draw color bar: //---------------- BOOL bDrawImageShadow = bHighlight && !bCustomizeMode && CBCGPVisualManager::GetInstance ()->IsShadowHighlightedImage () && !globalData.IsHighContastMode () && ((m_nStyle & TBBS_PRESSED) == 0) && ((m_nStyle & TBBS_CHECKED) == 0) && ((m_nStyle & TBBS_DISABLED) == 0); if (bDrawImageShadow) { CBrush brShadow (globalData.clrBarShadow); pDC->FillRect (rectColor, &brShadow); rectColor.OffsetRect (-1, -1); } COLORREF color = (m_nStyle & TBBS_DISABLED) ? globalData.clrBarShadow : (m_Color == (COLORREF)-1 ? m_colorAutomatic : m_Color); CBrush br (PALETTERGB( GetRValue (color), GetGValue (color), GetBValue (color))); CBrush* pOldBrush = pDC->SelectObject (&br); CPen* pOldPen = (CPen*) pDC->SelectStockObject (NULL_PEN); pDC->Rectangle (&rectColor); pDC->SelectObject (pOldPen); pDC->SelectObject (pOldBrush); if (CBCGPVisualManager::GetInstance ()->IsMenuFlatLook ()) { if (color == globalData.clrBarFace) { pDC->Draw3dRect (rectColor, globalData.clrBarDkShadow, globalData.clrBarDkShadow); } } else { pDC->Draw3dRect (rectColor, globalData.clrBarShadow, globalData.clrBarLight); } if (pOldPalette != NULL) { pDC->SelectPalette (pOldPalette, FALSE); } }
void CAtmoGdiDisplayCaptureInput::CalcColors() { tRGBColor pixelColor; #ifdef UseGdiGetPixel COLORREF pixel; #ifdef UseGdiDesktopGetPixel HDC hdcScreen; #endif #endif int xx,yy; int capture_area_width = (m_ScreenSourceRect.right-m_ScreenSourceRect.left); int capture_area_height = (m_ScreenSourceRect.bottom-m_ScreenSourceRect.top); #ifndef UseGdiDesktopGetPixel HBITMAP hTempBitmap = CreateCompatibleBitmap(m_hdcScreen, capture_area_width, capture_area_height); HGDIOBJ hOldBmp = SelectObject(m_hTempBitmapDC, hTempBitmap); #endif #ifndef UseGdiGetPixel BITMAPINFO bmpInfo; ZeroMemory(&bmpInfo, sizeof(BITMAPINFO)); bmpInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER); GetDIBits(m_hTempBitmapDC,hTempBitmap,0,1,NULL,&bmpInfo,DIB_RGB_COLORS); // bmpInfo.bmiHeader.biWidth = capture_area_width; // bmpInfo.bmiHeader.biHeight = -capture_area_height; if(bmpInfo.bmiHeader.biSizeImage<=0) bmpInfo.bmiHeader.biSizeImage=bmpInfo.bmiHeader.biWidth * abs(bmpInfo.bmiHeader.biHeight)*(bmpInfo.bmiHeader.biBitCount+7)/8; bmpInfo.bmiHeader.biCompression=BI_RGB; #endif // have a look into VncDesktop.cpp :-) **g vncDesktop::CaptureScreen // vncDesktop::EnableOptimisedBlits() vncDesktop::CopyToBuffer( // http://cboard.cprogramming.com/archive/index.php/t-89037.html // http://cboard.cprogramming.com/showthread.php?t=76907 das schaut gut aus!!!!!! // damit spart man die GetDIBits(...) aufrufe... und bekommt mittelsBitBlit gleich alles // ins eigene Ram Kopiert... Full Access to display ram... :-))) // #ifndef UseGdiDesktopGetPixel BitBlt(m_hTempBitmapDC, 0, 0, capture_area_width, capture_area_height, m_hdcScreen, m_ScreenSourceRect.left, m_ScreenSourceRect.top, SRCCOPY); #endif int index = (m_CurrentFrame * CAP_WIDTH); int indexSkip = ((m_rowsPerFrame-1) * CAP_WIDTH); unsigned int col = 0; #ifdef UseGdiGetPixel #ifdef UseGdiDesktopGetPixel hdcScreen = GetDC(NULL); #endif for(int y=m_CurrentFrame; y<CAP_HEIGHT; y+=m_rowsPerFrame ) { // yy = (y * capture_area_height) / CAP_HEIGHT; // yy = yy + m_ScreenSourceRect.top + m_tShift; yy = m_iSrcRows[y]; for(int x=0;x<CAP_WIDTH;x++) { // xx = (x * capture_area_width) / CAP_WIDTH; // xx = xx + m_ScreenSourceRect.left + m_lShift; #ifndef UseGdiDesktopGetPixel pixel = GetPixel(m_hTempBitmapDC, m_iSrcCols[x], yy); #else pixel = GetPixel(hdcScreen, m_iSrcCols[x], yy); #endif pixelColor.r = GetRValue(pixel); pixelColor.g = GetGValue(pixel); pixelColor.b = GetBValue(pixel); HSV_Img[index++] = RGB2HSV(pixelColor); } index += indexSkip; } #ifdef UseGdiDesktopGetPixel ReleaseDC(NULL, hdcScreen); #endif #else switch(bmpInfo.bmiHeader.biBitCount) { case 8: { // [TF] 8bit support added by Tobias Fleischer/Tobybear - still untested and experimental, might not work! int nColors = bmpInfo.bmiHeader.biClrUsed ? bmpInfo.bmiHeader.biClrUsed : 1 << bmpInfo.bmiHeader.biBitCount; for( int y=m_CurrentFrame; y<CAP_HEIGHT; y+=m_rowsPerFrame ) { // yy = (y * capture_area_height) / CAP_HEIGHT; // yy = yy + m_ScreenSourceRect.top + m_tShift; if(bmpInfo.bmiHeader.biHeight>0) yy = bmpInfo.bmiHeader.biHeight - m_iSrcRows[y] - 1; else yy = m_iSrcRows[y]; // eine Bildzeile in meinen Arbeitsbuffer kopieren! // geht vielfach schneller als GetPixel aufrufen... wenn man dein Speicher dann direkt // zugreift... :-) GetDIBits(m_hTempBitmapDC,hTempBitmap,yy,1,m_PixelBuffer,&bmpInfo,DIB_RGB_COLORS); for(int x=0; x<CAP_WIDTH; x++) { xx = m_iSrcCols[x]; col = m_PixelBuffer[xx] % nColors; pixelColor.b = bmpInfo.bmiColors[col].rgbBlue; pixelColor.g = bmpInfo.bmiColors[col].rgbGreen; pixelColor.r = bmpInfo.bmiColors[col].rgbRed; HSV_Img[index++] = RGB2HSV(pixelColor); } index += indexSkip; } break; } case 16: { // [TF] 16bit support added by Tobias Fleischer/Tobybear - tested for(int y=m_CurrentFrame; y<CAP_HEIGHT; y+=m_rowsPerFrame ) { // yy = (y * capture_area_height) / CAP_HEIGHT; // yy = yy + m_ScreenSourceRect.top + m_tShift; if(bmpInfo.bmiHeader.biHeight>0) yy = bmpInfo.bmiHeader.biHeight - m_iSrcRows[y] - 1; else yy = m_iSrcRows[y]; // eine Bildzeile in meinen Arbeitsbuffer kopieren! // geht vielfach schneller als GetPixel aufrufen... wenn man dein Speicher dann direkt // zugreift... :-) GetDIBits(m_hTempBitmapDC,hTempBitmap,yy,1,m_PixelBuffer,&bmpInfo,DIB_RGB_COLORS); for(int x=0;x<CAP_WIDTH;x++) { xx = m_iSrcCols[x] * 2; col = m_PixelBuffer[xx] + (m_PixelBuffer[xx+1]<<8); pixelColor.b = (col & 0x1F)<<3; pixelColor.g = (col & 0x3E0)>>2; pixelColor.r = (col & 0x7C00)>>7; HSV_Img[index++] = RGB2HSV(pixelColor); } index += indexSkip; } break; } case 24: { for(int y=m_CurrentFrame; y<CAP_HEIGHT; y+=m_rowsPerFrame ) { // yy = (y * capture_area_height) / CAP_HEIGHT; // yy = yy + m_ScreenSourceRect.top + m_tShift; if(bmpInfo.bmiHeader.biHeight>0) yy = bmpInfo.bmiHeader.biHeight - m_iSrcRows[y] - 1; else yy = m_iSrcRows[y]; // eine Bildzeile in meinen Arbeitsbuffer kopieren! // geht vielfach schneller als GetPixel aufrufen... wenn man dein Speicher dann direkt // zugreift... :-) GetDIBits(m_hTempBitmapDC,hTempBitmap,yy,1,m_PixelBuffer,&bmpInfo,DIB_RGB_COLORS); for(int x=0;x<CAP_WIDTH;x++) { xx = m_iSrcCols[x] * 3; pixelColor.b = m_PixelBuffer[xx++]; pixelColor.g = m_PixelBuffer[xx++]; pixelColor.r = m_PixelBuffer[xx++]; HSV_Img[index++] = RGB2HSV(pixelColor); } index += indexSkip; } break; } case 32: { for(int y=m_CurrentFrame; y<CAP_HEIGHT; y+=m_rowsPerFrame ) { if(bmpInfo.bmiHeader.biHeight>0) yy = bmpInfo.bmiHeader.biHeight - m_iSrcRows[y] - 1; else yy = m_iSrcRows[y]; // eine Bildzeile in meinen Arbeitsbuffer kopieren! // geht vielfach schneller als GetPixel aufrufen... wenn man dein Speicher dann direkt // zugreift... :-) GetDIBits(m_hTempBitmapDC,hTempBitmap,yy,1,m_PixelBuffer,&bmpInfo,DIB_RGB_COLORS); for(int x=0;x<CAP_WIDTH;x++) { // xx = (x * capture_area_width) / CAP_WIDTH; // xx = xx + m_ScreenSourceRect.left + m_lShift; xx = m_iSrcCols[x] * 4; pixelColor.b = m_PixelBuffer[xx++]; pixelColor.g = m_PixelBuffer[xx++]; pixelColor.r = m_PixelBuffer[xx++]; HSV_Img[index++] = RGB2HSV(pixelColor); } index += indexSkip; } break; } } #endif #ifndef UseGdiDesktopGetPixel SelectObject(m_hTempBitmapDC, hOldBmp); DeleteObject(hTempBitmap); #endif m_CurrentFrame++; if(m_CurrentFrame >= m_rowsPerFrame) m_CurrentFrame = 0; m_pAtmoDynData->getLivePacketQueue()->AddPacket( m_pAtmoColorCalculator->AnalyzeHSV( HSV_Img ) ); }
Color RenderThemeWinCE::platformInactiveSelectionBackgroundColor() const { COLORREF color = GetSysColor(COLOR_GRAYTEXT); return Color(GetRValue(color), GetGValue(color), GetBValue(color), 255); }
void vxPaintDC::_FillGradient(const LPRECT lpRect, COLORREF colorStart, COLORREF colorFinish, bool bHorz /* = TRUE */, int nStartFlatPercentage /* = 0 */, int nEndFlatPercentage /* = 0 */) { if (NULL == lpRect) return; if (colorStart == colorFinish) { HBRUSH hbr = ::CreateSolidBrush(colorStart); assert(NULL != hbr); ::FillRect(m_hDC, lpRect, hbr); ::DeleteObject((HGDIOBJ)hbr); return; } if (nStartFlatPercentage > 0) { assert(nStartFlatPercentage <= 100); if (bHorz) { RECT rectTop; memcpy(&rectTop, lpRect, sizeof(RECT)); rectTop.bottom = rectTop.top + (rectTop.bottom - rectTop.top) * nStartFlatPercentage / 100; lpRect->top = rectTop.bottom; HBRUSH hbr = ::CreateSolidBrush(colorFinish); assert(NULL != hbr); ::FillRect(m_hDC, &rectTop, hbr); ::DeleteObject((HGDIOBJ)hbr); } else { RECT rectLeft; memcpy(&rectLeft, lpRect, sizeof(RECT)); rectLeft.right = rectLeft.left + (rectLeft.right - rectLeft.left) * nStartFlatPercentage / 100; lpRect->left = rectLeft.right; HBRUSH hbr = ::CreateSolidBrush(colorStart); assert(NULL != hbr); ::FillRect(m_hDC, &rectLeft, hbr); ::DeleteObject((HGDIOBJ)hbr); } } if (nEndFlatPercentage > 0) { assert(nEndFlatPercentage <= 100); if (bHorz) { RECT rectBottom; memcpy(&rectBottom, lpRect, sizeof(RECT)); rectBottom.top = rectBottom.bottom - (rectBottom.bottom - rectBottom.top) * nEndFlatPercentage / 100; lpRect->bottom = rectBottom.top; HBRUSH hbr = ::CreateSolidBrush(colorStart); assert(NULL != hbr); ::FillRect(m_hDC, &rectBottom, hbr); ::DeleteObject((HGDIOBJ)hbr); } else { RECT rectRight; memcpy(&rectRight, lpRect, sizeof(RECT)); rectRight.left = rectRight.right - (rectRight.right - rectRight.left) * nEndFlatPercentage / 100; lpRect->right = rectRight.left; HBRUSH hbr = ::CreateSolidBrush(colorFinish); assert(NULL != hbr); ::FillRect(m_hDC, &rectRight, hbr); ::DeleteObject((HGDIOBJ)hbr); } } if (nEndFlatPercentage + nStartFlatPercentage > 100) { assert(FALSE); return; } // this will make 2^6 = 64 fountain steps int nShift = 6; int nSteps = 1 << nShift; for (int i = 0; i < nSteps; i++) { // do a little alpha blending BYTE bR = (BYTE)((GetRValue(colorStart) * (nSteps - i) + GetRValue(colorFinish) * i) >> nShift); BYTE bG = (BYTE)((GetGValue(colorStart) * (nSteps - i) + GetGValue(colorFinish) * i) >> nShift); BYTE bB = (BYTE)((GetBValue(colorStart) * (nSteps - i) + GetBValue(colorFinish) * i) >> nShift); HBRUSH hbr = ::CreateSolidBrush(RGB(bR, bG, bB)); // then paint with the resulting color RECT r2; memcpy(&r2, lpRect, sizeof(RECT)); if (bHorz) { r2.bottom = lpRect->bottom - ((i * (lpRect->bottom - lpRect->top)) >> nShift); r2.top = lpRect->bottom - (((i + 1) * (lpRect->bottom - lpRect->top)) >> nShift); if ((r2.bottom - r2.top) > 0) { ::FillRect(m_hDC, &r2, hbr); } } else { r2.left = lpRect->left + ((i * (lpRect->right - lpRect->left)) >> nShift); r2.right = lpRect->left + (((i + 1) * (lpRect->right - lpRect->left)) >> nShift); if ((r2.right - r2.left) > 0) { ::FillRect(m_hDC, &r2, hbr); } } ::DeleteObject((HGDIOBJ)hbr); }
void CDigistring::OnPaint() { CRect rect; CDoubleRect CharRect; GetClientRect(&rect); CPaintDC dc(this); // device context for painting dc.SetBkColor(m_BackColor); CMyMemDC memDC(&dc, &rect); CBrush hBrushOff, hBrushOn; hBrushOff.CreateSolidBrush(m_OffColor); hBrushOn.CreateSolidBrush(m_OnColor); CBrush *pOldBrush = memDC.SelectObject(&hBrushOn); int r = int(GetRValue(m_OffColor) * 0.75 + GetRValue(m_BackColor) * 0.25); int g = int(GetGValue(m_OffColor) * 0.75 + GetGValue(m_BackColor) * 0.25); int b = int(GetBValue(m_OffColor) * 0.75 + GetBValue(m_BackColor) * 0.25); CPen OffPen(PS_SOLID | PS_ENDCAP_ROUND, 1, RGB(r,g,b)); r = int(GetRValue(m_OnColor) * 0.75 + GetRValue(m_BackColor) * 0.25); g = int(GetGValue(m_OnColor) * 0.75 + GetGValue(m_BackColor) * 0.25); b = int(GetBValue(m_OnColor) * 0.75 + GetBValue(m_BackColor) * 0.25); CPen OnPen(PS_SOLID | PS_ENDCAP_ROUND, 1, RGB(r,g,b)); CPen *pOldPen = memDC.SelectObject(&OffPen); int iTotWidth = 0; double dRelWidth, dRelHeight; // TODO: Add your message handler code here DigiCharVector::iterator CharIterator; // Calculate resizing factors... BuildString(); for (CharIterator = m_CharVector.begin(); CharIterator != m_CharVector.end(); CharIterator++) { iTotWidth += CharIterator->GetNormWidth(); } dRelWidth = double(rect.Width()) / iTotWidth; dRelHeight = double(rect.Height()) / NORM_DIGIHEIGHT; // If proportional make offset for centered text if (m_DispStyle & DS_SZ_PROP) { if (dRelWidth < dRelHeight) dRelHeight = dRelWidth; else dRelWidth = dRelHeight; CharRect.left = (rect.Width() - dRelWidth * iTotWidth) / 2; CharRect.top = (rect.Height() - dRelHeight * NORM_DIGIHEIGHT) / 2; } else CharRect.SetRectEmpty(); // Draw all characters... for (CharIterator = m_CharVector.begin(); CharIterator != m_CharVector.end(); CharIterator++) { CharRect.SetRect(CharRect.left, CharRect.top, CharRect.left + dRelWidth * CharIterator->GetNormWidth(), CharRect.top + dRelHeight * NORM_DIGIHEIGHT); CharIterator->Draw(&memDC, CharRect, &OffPen, &OnPen, &hBrushOff, &hBrushOn); CharRect.left += dRelWidth * CharIterator->GetNormWidth(); } // Mama says: Clean up your mess! memDC.SelectObject(pOldPen); memDC.SelectObject(pOldBrush); OffPen.DeleteObject(); OnPen.DeleteObject(); hBrushOff.DeleteObject(); hBrushOn.DeleteObject(); }
/* ===================== paint_Pathcast ===================== */ void paint_Pathcast( place_t place ) { int xi, yi; int xf, yf; int i,j; COLORREF cr; int tmp; game_t *game = NULL; figure_t *fig = NULL; int blocksize = BLOCKSIZE; switch( place ) { case LEFTGAME: game = k_system.pLeftGame; break; case RIGHTGAME: game = k_system.pRightGame; break; default: return; } if( game == NULL ) { return; } //validate figure // if( game->pFig == NULL ) { return; } fig = game->pFig; if( fig->desintegrated ) { return; } //sometimes the figure has an invalid position //and seqProc has not been called yet to fix the problem // if( (fig->pos.y >= CYSPACE) ) { return; } cr = kcfTable[VAR_EFF_PATHCAST_COLOR].v.dw; glColor3f( GetRValue(cr)/255.0f, GetGValue(cr)/255.0f, GetBValue(cr)/255.0f ); //draw pathcast effect // glBegin( GL_QUADS ); for( j=0; j<CXFIG; j++ ) { i = 0; tmp = -1; while( i<CYFIG ) { if( kFigRes[fig->type][i][fig->state*CSTATE + j] == 1 ) { tmp=i; } i++; } //cast "shadow" // if( (tmp < 4) && (tmp > -1) ) { xi = ( j + fig->pos.x ); yi = ( tmp + fig->pos.y + 1 ); yf = yi; xf = xi; while( (yf < CYSPACE) && (SPACE_CELL( game->AS, yf, xf ) != MAPCELL_BLOCK) ) { yf++; } if( yf > yi ) { NGL_polygon( (GLfloat)( xi*blocksize ), (GLfloat)( yf*blocksize - blocksize/3 ), (GLfloat)( (xi+1)*blocksize ), (GLfloat)( yf*blocksize ) ); } } } glEnd(); }
////////////////////////////////////////////////////////////////////////// //函数名:BitmapToRegion //功能:输入图像句柄,得到抠除了蒙板色的区域 //原作者:Jean-Edouard Lachand Robert, August 5, 1998 //修改人:C瓜哥(www.cguage.com) HRGN CAnimateButton::BitmapToRegion(HBITMAP hBmp, int nSplit, int n, COLORREF cTransparentColor = RGB(255, 0, 255), COLORREF cTolerance = RGB(255, 0, 255)) { HRGN hRgn = NULL; if (hBmp) { // Create a memory DC inside which we will scan the bitmap content HDC hMemDC = CreateCompatibleDC(NULL); if (hMemDC) { // Get bitmap size BITMAP bm; GetObject(hBmp, sizeof(bm), &bm); // Create a 32 bits depth bitmap and select it into the memory DC BITMAPINFOHEADER RGB32BITSBITMAPINFO = { sizeof(BITMAPINFOHEADER), // biSize bm.bmWidth, // biWidth; bm.bmHeight, // biHeight; 1, // biPlanes; 32, // biBitCount BI_RGB, // biCompression; 0, // biSizeImage; 0, // biXPelsPerMeter; 0, // biYPelsPerMeter; 0, // biClrUsed; 0 // biClrImportant; }; //每种状态图的宽度 int nBlockWidth = bm.bmWidth / nSplit; VOID * pbits32; HBITMAP hbm32 = CreateDIBSection(hMemDC, (BITMAPINFO *)&RGB32BITSBITMAPINFO, DIB_RGB_COLORS, &pbits32, NULL, 0); if (hbm32) { HBITMAP holdBmp = (HBITMAP)SelectObject(hMemDC, hbm32); // Create a DC just to copy the bitmap into the memory DC HDC hDC = CreateCompatibleDC(hMemDC); if (hDC) { // Get how many bytes per row we have for the bitmap bits (rounded up to 32 bits) BITMAP bm32; GetObject(hbm32, sizeof(bm32), &bm32); while (bm32.bmWidthBytes % 4) bm32.bmWidthBytes++; // Copy the bitmap into the memory DC HBITMAP holdBmp = (HBITMAP)SelectObject(hDC, hBmp); BitBlt(hMemDC, 0, 0, nBlockWidth, bm.bmHeight, hDC, nBlockWidth * n, 0, SRCCOPY); // For better performances, we will use the ExtCreateRegion() function to create the // region. This function take a RGNDATA structure on entry. We will add rectangles by // amount of ALLOC_UNIT number in this structure. #define ALLOC_UNIT 100 DWORD maxRects = ALLOC_UNIT; HANDLE hData = GlobalAlloc(GMEM_MOVEABLE, sizeof(RGNDATAHEADER) + (sizeof(RECT) * maxRects)); RGNDATA *pData = (RGNDATA *)GlobalLock(hData); pData->rdh.dwSize = sizeof(RGNDATAHEADER); pData->rdh.iType = RDH_RECTANGLES; pData->rdh.nCount = pData->rdh.nRgnSize = 0; SetRect(&pData->rdh.rcBound, MAXLONG, MAXLONG, 0, 0); // Keep on hand highest and lowest values for the "transparent" pixels BYTE lr = GetRValue(cTransparentColor); BYTE lg = GetGValue(cTransparentColor); BYTE lb = GetBValue(cTransparentColor); BYTE hr = min(0xff, lr + GetRValue(cTolerance)); BYTE hg = min(0xff, lg + GetGValue(cTolerance)); BYTE hb = min(0xff, lb + GetBValue(cTolerance)); // Scan each bitmap row from bottom to top (the bitmap is inverted vertically) BYTE *p32 = (BYTE *)bm32.bmBits + (bm32.bmHeight - 1) * bm32.bmWidthBytes; for (int y = 0; y < bm.bmHeight; y++) { // Scan each bitmap pixel from left to right for (int x = 0; x < nBlockWidth; x++) { // Search for a continuous range of "non transparent pixels" int x0 = x; LONG *p = (LONG *)p32 + x; while (x < nBlockWidth) { BYTE b = GetRValue(*p); if (b >= lr && b <= hr) { b = GetGValue(*p); if (b >= lg && b <= hg) { b = GetBValue(*p); if (b >= lb && b <= hb) // This pixel is "transparent" break; } } p++; x++; } if (x > x0) { // Add the pixels (x0, y) to (x, y+1) as a new rectangle in the region if (pData->rdh.nCount >= maxRects) { GlobalUnlock(hData); maxRects += ALLOC_UNIT; hData = GlobalReAlloc(hData, sizeof(RGNDATAHEADER) + (sizeof(RECT) * maxRects), GMEM_MOVEABLE); pData = (RGNDATA *)GlobalLock(hData); } RECT *pr = (RECT *)&pData->Buffer; SetRect(&pr[pData->rdh.nCount], x0, y, x, y+1); if (x0 < pData->rdh.rcBound.left) pData->rdh.rcBound.left = x0; if (y < pData->rdh.rcBound.top) pData->rdh.rcBound.top = y; if (x > pData->rdh.rcBound.right) pData->rdh.rcBound.right = x; if (y+1 > pData->rdh.rcBound.bottom) pData->rdh.rcBound.bottom = y+1; pData->rdh.nCount++; // On Windows98, ExtCreateRegion() may fail if the number of rectangles is too // large (ie: > 4000). Therefore, we have to create the region by multiple steps. if (pData->rdh.nCount == 2000) { HRGN h = ExtCreateRegion(NULL, sizeof(RGNDATAHEADER) + (sizeof(RECT) * maxRects), pData); if (hRgn) { CombineRgn(hRgn, hRgn, h, RGN_OR); DeleteObject(h); } else hRgn = h; pData->rdh.nCount = 0; SetRect(&pData->rdh.rcBound, MAXLONG, MAXLONG, 0, 0); } } } // Go to next row (remember, the bitmap is inverted vertically) p32 -= bm32.bmWidthBytes; } // Create or extend the region with the remaining rectangles HRGN h = ExtCreateRegion(NULL, sizeof(RGNDATAHEADER) + (sizeof(RECT) * maxRects), pData); if (hRgn) { CombineRgn(hRgn, hRgn, h, RGN_OR); DeleteObject(h); } else hRgn = h; // Clean up SelectObject(hDC, holdBmp); DeleteDC(hDC); } DeleteObject(SelectObject(hMemDC, holdBmp)); } DeleteDC(hMemDC); } }// if hBmp return hRgn; }
/** * colorize an image item (both standalone items with their own bitmap and glyph items). * * @param item image item to colorize * @param clr color to use (note: BGRA format required, although, alpha is ignored) * @param hue hue adjustment (in degrees, -180 .. +180 * @param saturation scalar value (0.0 ... 1.0) * @param value scalar value (0.0 ... 1.0) * * note: this isn't performance critical as it only runs at skin loading time or when * the user changes colorization options, never during rendering. * * if clr == 0, hsv transformation will be applied, otherwise it's rgb colorization. */ void Gfx::colorizeGlyph(TImageItem *item, const COLORREF clr, float hue, float saturation, float value) { LONG stride = 0, line, pixel; HBITMAP hBitmap = 0; LONG x, y, x1, y1; BITMAP bmp = {0}; DWORD dwLen; BYTE* pOrig, *pLine, alpha; float v_s_u = 0, v_s_w = 0, r = 0, g = 0, b = 0; if(0 == clr) { // do hsv transformation v_s_u = value * saturation * cos(hue * M_PI/180); v_s_w = value * saturation * sin(hue * M_PI/180); } else { // rgb colorization BYTE rValue = GetRValue(clr); BYTE gValue = GetGValue(clr); BYTE bValue = GetBValue(clr); r = (float)rValue / 2.55; g = (float)gValue / 2.55; b = (float)bValue / 2.55; } if(item) { /* * colorize a rectangular glyph */ if(item->dwFlags & IMAGE_GLYPH) { hBitmap = Skin::glyphItem->hbm; x = item->glyphMetrics[0]; y = item->glyphMetrics[1]; x1 = x + item->glyphMetrics[2] - 1; y1 = y + item->glyphMetrics[3] - 1; GetObject(hBitmap, sizeof(bmp), &bmp); if (bmp.bmBitsPixel != 32) return; dwLen = bmp.bmWidth * bmp.bmHeight * 4; if (dwLen > m_sAllocated) { m_p = (BYTE *)realloc(m_p, dwLen); dwLen = (DWORD)m_sAllocated; } memset(m_p, 0, dwLen); pOrig = m_p; GetBitmapBits(hBitmap, dwLen, m_p); stride = bmp.bmWidthBytes; m_p += ((y * stride) + (4 * x)); for(line = y; line <= y1; line++) { pLine = m_p; for(pixel = x; pixel <= x1; pixel++) { alpha = m_p[3]; if(alpha > 0) { if(0 == clr) hsvTransformPixel(m_p, value, v_s_u, v_s_w, alpha); else rgbTransformPixel(m_p, r, g, b, alpha); } m_p += 4; } m_p = pLine + stride; } SetBitmapBits(hBitmap, dwLen, pOrig); } else if (item->hbm) { GetObject(item->hbm, sizeof(bmp), &bmp); if (bmp.bmBitsPixel != 32) return; dwLen = bmp.bmWidth * bmp.bmHeight * 4; if (dwLen > m_sAllocated) { m_p = (BYTE *)realloc(m_p, dwLen); m_sAllocated = dwLen; } memset(m_p, 0, dwLen); pOrig = m_p; GetBitmapBits(item->hbm, dwLen, m_p); for(pixel = 0; pixel < (bmp.bmWidth * bmp.bmHeight); pixel++) { alpha = m_p[3]; if(alpha > 0) { if(0 == clr) hsvTransformPixel(m_p, value, v_s_u, v_s_w, alpha); else rgbTransformPixel(m_p, r, g, b, alpha); } m_p += 4; } SetBitmapBits(item->hbm, dwLen, pOrig); } } }
/************************************************** void CImg::SetPixel(int x, int y, COLORREF color) 功能: 设定指定坐标位置像素的颜色值 限制: 无 参数: int x, int y 指定的像素横、纵坐标值 COLORREF 欲设定的指定位置的颜色值,RGB形式给出 返回值: 无 ***************************************************/ void CImg::SetPixel(int x, int y, COLORREF color) { if(m_pBMIH->biBitCount == 8) // 256色图 { m_lpData[m_pBMIH->biHeight - y - 1][x] = GetRValue(color); } else if(m_pBMIH->biBitCount == 1) // 单色图 { BYTE Color = GetRValue(color); // 令0代表黑 RGBQUAD *p = (RGBQUAD*)m_lpvColorTable; if(p[0].rgbBlue != 0) Color = !Color; y = m_pBMIH->biHeight - y - 1; // 黑色点 if (Color == 0) // 设置对应位为0 { if(x % 8==0) { m_lpData[y][x/8] &= 0x7F; } else if(x % 8==1) { m_lpData[y][x/8] &= 0xBF; } else if(x % 8==2) { m_lpData[y][x/8] &= 0xDF; } else if(x % 8==3) { m_lpData[y][x/8] &= 0xEF; } else if(x % 8==4) { m_lpData[y][x/8] &= 0xF7; } else if(x % 8==5) { m_lpData[y][x/8] &= 0xFB; } else if(x % 8==6) { m_lpData[y][x/8] &= 0xFD; } else if(x % 8==7) { m_lpData[y][x/8] &= 0xFE; } } else // 白色点 { if(x % 8==0) { m_lpData[y][x/8] |= 0x80; } else if(x % 8==1) { m_lpData[y][x/8] |= 0x40; } else if(x % 8==2) { m_lpData[y][x/8] |= 0x20; } else if(x % 8==3) { m_lpData[y][x/8] |= 0x10; } else if(x % 8==4) { m_lpData[y][x/8] |= 0x08; } else if(x % 8==5) { m_lpData[y][x/8] |= 0x04; } else if(x % 8==6) { m_lpData[y][x/8] |= 0x02; } else if(x % 8==7) { m_lpData[y][x/8] |= 0x01; } } } else if(m_pBMIH->biBitCount == 24) { m_lpData[m_pBMIH->biHeight - y - 1][x*3] = GetBValue(color); m_lpData[m_pBMIH->biHeight - y - 1][x*3 + 1] = GetGValue(color); m_lpData[m_pBMIH->biHeight - y - 1][x*3 + 2] = GetRValue(color); } }
VOID CZUIRender::DrawRect(HDC hDC, RECT& rc, DWORD dwBorderSize, DWORD dwBorderColor, SIZE* pxyBorderRound /* = NULL */) { HPEN hPen = ::CreatePen(PS_SOLID | PS_INSIDEFRAME, dwBorderSize, RGB(GetBValue(dwBorderColor), GetGValue(dwBorderColor), GetRValue(dwBorderColor))); if(hPen != NULL) { HPEN hOldPen = (HPEN)::SelectObject(hDC, hPen); ::SelectObject(hDC, ::GetStockObject(NULL_BRUSH)); // »Ë¢Ñ¡Óÿջˢ, ¼´²»ÊµÐÄ if(pxyBorderRound != NULL) { // Ô²½Ç¾ØÐÎ ::RoundRect(hDC, rc.left, rc.top, rc.right, rc.bottom, pxyBorderRound->cx, pxyBorderRound->cy); } else { ::Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom); } ::SelectObject(hDC, hOldPen); ::DeleteObject(hPen); } }
bool wxTabCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name) { m_imageList = NULL; m_backgroundColour = wxColour(GetRValue(GetSysColor(COLOR_BTNFACE)), GetGValue(GetSysColor(COLOR_BTNFACE)), GetBValue(GetSysColor(COLOR_BTNFACE))); m_foregroundColour = *wxBLACK ; SetName(name); int x = pos.x; int y = pos.y; int width = size.x; int height = size.y; m_windowStyle = style; SetParent(parent); if (width <= 0) width = 100; if (height <= 0) height = 30; if (x < 0) x = 0; if (y < 0) y = 0; m_windowId = (id < 0 ? NewControlId() : id); long tabStyle = WS_CHILD | WS_VISIBLE; if (m_windowStyle & wxTC_MULTILINE) tabStyle |= TCS_MULTILINE; if (m_windowStyle & wxTC_RIGHTJUSTIFY) tabStyle |= TCS_RIGHTJUSTIFY; if (m_windowStyle & wxTC_FIXEDWIDTH) tabStyle |= TCS_FIXEDWIDTH; if (m_windowStyle & wxTC_OWNERDRAW) tabStyle |= TCS_OWNERDRAWFIXED; if (m_windowStyle & wxBORDER) tabStyle |= WS_BORDER; #ifndef __WXWINCE__ tabStyle |= TCS_TOOLTIPS; #endif // Create the toolbar control. HWND hWndTabCtrl = CreateWindowEx(0L, // No extended styles. WC_TABCONTROL, // Class name for the tab control wxEmptyString, // No default text. tabStyle, // Styles and defaults. x, y, width, height, // Standard size and position. (HWND) parent->GetHWND(), // Parent window (HMENU)m_windowId, // ID. wxGetInstance(), // Current instance. NULL ); // No class data. m_hWnd = (WXHWND) hWndTabCtrl; if (parent) parent->AddChild(this); SubclassWin((WXHWND) hWndTabCtrl); SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); return true; }
static inline QRgb colorref2qrgb(COLORREF col) { return qRgb(GetRValue(col),GetGValue(col),GetBValue(col)); }
void CGradientProgressCtrl::DrawGradient(CPaintDC *pDC, const RECT &rectClient, const int &nMaxWidth, const BOOL &bVertical) { RECT rectFill; // Rectangle for filling band float fStep; // How wide is each band? CBrush brush; // Brush to fill in the bar CMemDC memDC(pDC); // First find out the largest color distance between the start and end colors. This distance // will determine how many steps we use to carve up the client region and the size of each // gradient rect. int r, g, b; // First distance, then starting value float rStep, gStep, bStep; // Step size for each color BOOL bSameColor = FALSE; // Handle case if start color == end color // Get the color differences r = (GetRValue(m_clrEnd) - GetRValue(m_clrStart)); g = (GetGValue(m_clrEnd) - GetGValue(m_clrStart)); b = (GetBValue(m_clrEnd) - GetBValue(m_clrStart)); // Check to see if colors are same if((r == 0) && (g == 0) && (b == 0)) { bSameColor = TRUE; //Added the three lines below to fix the drawing //problem which used to occur when both the start //and end colors are same. r = GetRValue(m_clrStart); g = GetGValue(m_clrStart); b = GetBValue(m_clrStart); } int nSteps; //Select max. possible value for nSteps if the colors are equal if(bSameColor && m_clrStart == 0) nSteps = 255; else // Make the number of steps equal to the greatest distance nSteps = max(abs(r), max(abs(g), abs(b))); // Determine how large each band should be in order to cover the // client with nSteps bands (one for every color intensity level) if (bVertical) fStep = (float)rectClient.bottom / (float)nSteps; else fStep = (float)rectClient.right / (float)nSteps; // Calculate the step size for each color rStep = r/(float)nSteps; gStep = g/(float)nSteps; bStep = b/(float)nSteps; // Reset the colors to the starting position r = GetRValue(m_clrStart); g = GetGValue(m_clrStart); b = GetBValue(m_clrStart); // Start filling bands for (int iOnBand = 0; iOnBand < nSteps; iOnBand++) { // Fill the vertical control if (bVertical) { ::SetRect(&rectFill, 0, // Upper left X (int)(iOnBand * fStep), // Upper left Y rectClient.right+1, // Lower right X (int)((iOnBand+1) * fStep));// Lower right Y // CDC::FillSolidRect is faster, but it does not handle 8-bit color depth VERIFY(brush.CreateSolidBrush(RGB(r+rStep*iOnBand, g + gStep*iOnBand, b + bStep *iOnBand))); memDC.FillRect(&rectFill,&brush); VERIFY(brush.DeleteObject()); // If we are past the maximum for the current position we need to get out of the loop. // Before we leave, we repaint the remainder of the client area with the background color. if (rectFill.bottom > nMaxWidth) { ::SetRect(&rectFill, 0, rectFill.bottom, rectClient.right, rectClient.bottom); VERIFY(brush.CreateSolidBrush(m_clrBkGround)); memDC.FillRect(&rectFill, &brush); VERIFY(brush.DeleteObject()); return; } } else // Fill the horizontal control { ::SetRect(&rectFill, (int)(iOnBand * fStep), // Upper left X 0, // Upper left Y (int)((iOnBand+1) * fStep), // Lower right X rectClient.bottom+1); // Lower right Y // CDC::FillSolidRect is faster, but it does not handle 8-bit color depth VERIFY(brush.CreateSolidBrush(RGB(r+rStep*iOnBand, g + gStep*iOnBand, b + bStep *iOnBand))); memDC.FillRect(&rectFill,&brush); VERIFY(brush.DeleteObject()); // If we are past the maximum for the current position we need to get out of the loop. // Before we leave, we repaint the remainder of the client area with the background color. if (rectFill.right > nMaxWidth) { ::SetRect(&rectFill, rectFill.right, 0, rectClient.right, rectClient.bottom); VERIFY(brush.CreateSolidBrush(m_clrBkGround)); memDC.FillRect(&rectFill, &brush); VERIFY(brush.DeleteObject()); return; } } } }
/****************************************************************************** * OleTranslateColor [OLEAUT32.421] * * Convert an OLE_COLOR to a COLORREF. * * PARAMS * clr [I] Color to convert * hpal [I] Handle to a palette for the conversion * pColorRef [O] Destination for converted color, or NULL to test if the conversion is ok * * RETURNS * Success: S_OK. The conversion is ok, and pColorRef contains the converted color if non-NULL. * Failure: E_INVALIDARG, if any argument is invalid. * * FIXME * Document the conversion rules. */ HRESULT WINAPI OleTranslateColor( OLE_COLOR clr, HPALETTE hpal, COLORREF* pColorRef) { COLORREF colorref; BYTE b = HIBYTE(HIWORD(clr)); TRACE("(%08x, %p, %p)\n", clr, hpal, pColorRef); /* * In case pColorRef is NULL, provide our own to simplify the code. */ if (pColorRef == NULL) pColorRef = &colorref; switch (b) { case 0x00: { if (hpal != 0) *pColorRef = PALETTERGB(GetRValue(clr), GetGValue(clr), GetBValue(clr)); else *pColorRef = clr; break; } case 0x01: { if (hpal != 0) { PALETTEENTRY pe; /* * Validate the palette index. */ if (GetPaletteEntries(hpal, LOWORD(clr), 1, &pe) == 0) return E_INVALIDARG; } *pColorRef = clr; break; } case 0x02: *pColorRef = clr; break; case 0x80: { int index = LOBYTE(LOWORD(clr)); /* * Validate GetSysColor index. */ if ((index < COLOR_SCROLLBAR) || (index > COLOR_MENUBAR)) return E_INVALIDARG; *pColorRef = GetSysColor(index); break; } default: return E_INVALIDARG; } return S_OK; }
long CMUSHclientDoc::BlendPixel(long Blend, long Base, short Mode, double Opacity) { long rA = GetRValue (Blend), gA = GetGValue (Blend), bA = GetBValue (Blend); long rB = GetRValue (Base), gB = GetGValue (Base), bB = GetBValue (Base); long r, g, b; if (Opacity < 0.0 || Opacity > 1.0) return -2; // precompute cos table static unsigned char cos_table [256]; static bool bTableComputed = false; if (!bTableComputed) { double pi_div255 = 3.1415926535898 / 255.0; long i; for (i = 0; i < 256; i++) { double a = 64.0 - cos ((double) i * pi_div255) * 64.0; cos_table [i] = (uint8) (a + 0.5); // round } bTableComputed = true; } // table needs computing switch (Mode) { // normal modes case 1: Blend_It (Blend_Normal); break; case 2: Blend_It (Blend_Average); break; case 3: Blend_It (Blend_Interpolate); break; case 4: // dissolve - randomly choose pixels based on opacity { double rnd = genrand (); r = (rnd < Opacity) ? rA : rB; g = (rnd < Opacity) ? gA : gB; b = (rnd < Opacity) ? bA : bB; } break; // darkening modes case 5: Blend_It (Blend_Darken); break; case 6: Blend_It (Blend_Multiply); break; case 7: Blend_It (Blend_ColorBurn); break; case 8: Blend_It (Blend_LinearBurn); break; case 9: Blend_It (Blend_InverseColorBurn); break; case 10: Blend_It (Blend_Subtract); break; // lightening modes case 11: Blend_It (Blend_Lighten); break; case 12: Blend_It (Blend_Screen); break; case 13: Blend_It (Blend_ColorDodge); break; case 14: Blend_It (Blend_LinearDodge);break; case 15: Blend_It (Blend_InverseColorDodge); break; case 16: Blend_It (Blend_Add); break; // soft/hard light etc. case 17: Blend_It (Blend_Overlay); break; case 18: Blend_It (Blend_SoftLight); break; case 19: Blend_It (Blend_HardLight); break; case 20: Blend_It (Blend_VividLight); break; case 21: Blend_It (Blend_LinearLight);break; case 22: Blend_It (Blend_PinLight); break; case 23: Blend_It (Blend_HardMix); break; // difference modes case 24: Blend_It (Blend_Difference); break; case 25: Blend_It (Blend_Exclusion); break; // glow modes case 26: Blend_It (Blend_Reflect); break; case 27: Blend_It (Blend_Glow); break; case 28: Blend_It (Blend_Freeze); break; case 29: Blend_It (Blend_Heat); break; case 30: Blend_It (Blend_Negation); break; case 31: Blend_It (Blend_Phoenix); break; case 32: Blend_It (Blend_Stamp); break; // logical modes case 33: Blend_It (Blend_Xor); break; case 34: Blend_It (Blend_And); break; case 35: Blend_It (Blend_Or); break; // the follow modes take one colour from the blend and retain 2 from the base case 36: Colour_Op (rA, gB, bB); break; // red case 37: Colour_Op (rB, gA, bB); break; // green case 38: Colour_Op (rB, gB, bA); break; // blue // the follow modes take two colours from the blend and retain 1 from the base case 39: Colour_Op (rA, gA, bB); break; // yellow case 40: Colour_Op (rB, gA, bA); break; // cyan case 41: Colour_Op (rA, gB, bA); break; // magenta // limit green case 42: Colour_Op (rA, (gA > rA) ? rA : gA, bA); break; // green limited by red case 43: Colour_Op (rA, (gA > bA) ? bA : gA, bA); break; // green limited by blue case 44: Colour_Op (rA, (gA > ((rA + bA) / 2)) ? ((rA + bA) / 2) : gA, bA); break; // green limited by average of red and blue // limit blue case 45: Colour_Op (rA, gA, (bA > rA) ? rA : bA); break; // blue limited by red case 46: Colour_Op (rA, gA, (bA > gA) ? gA : bA); break; // blue limited by green case 47: Colour_Op (rA, gA, (bA > ((rA + gA) / 2)) ? ((rA + gA) / 2) : bA); break; // blue limited by average of red and green // limit red case 48: Colour_Op ((rA > gA) ? gA : rA, gA, bA); break; // red limited by green case 49: Colour_Op ((rA > bA) ? bA : rA, gA, bA); break; // red limited by blue case 50: Colour_Op ((rA > ((gA + bA) / 2)) ? ((gA + bA) / 2) : rA, gA, bA); break; // red limited by average of green and blue // select single colour case 51: Colour_Op (rA, 0, 0); break; // red only (looks red) case 52: Colour_Op (0, gA, 0); break; // green only (looks green) case 53: Colour_Op (0, 0, bA); break; // blue only (looks blue) // discard single colour case 54: Colour_Op (0, gA, bA); break; // discard red (looks cyan) case 55: Colour_Op (rA, 0, bA); break; // discard green (looks magenta) case 56: Colour_Op (rA, gA, 0); break; // discard blue (looks yellow) // one colour to all channels (ie. it looks grey) case 57: Colour_Op (rA, rA, rA); break; // all red case 58: Colour_Op (gA, gA, gA); break; // all green case 59: Colour_Op (bA, bA, bA); break; // all blue case 60: // Hue mode { CColor cA, cB; // A = blend, B = base cA.SetRGB (rA, gA, bA); cB.SetRGB (rB, gB, bB); cB.SetHue (cA.GetHue ()); // hue of blend image, others from base image r = Simple_Opacity (rB, cB.GetRed (), Opacity); g = Simple_Opacity (gB, cB.GetGreen (), Opacity); b = Simple_Opacity (bB, cB.GetBlue (), Opacity); } break; case 61: // Saturation mode { CColor cA, cB; // A = blend, B = base cA.SetRGB (rA, gA, bA); cB.SetRGB (rB, gB, bB); cB.SetSaturation (cA.GetSaturation ()); // saturation of blend image, others from base image r = Simple_Opacity (rB, cB.GetRed (), Opacity); g = Simple_Opacity (gB, cB.GetGreen (), Opacity); b = Simple_Opacity (bB, cB.GetBlue (), Opacity); } break; case 62: // Colour mode { CColor cA, cB; // A = blend, B = base cA.SetRGB (rA, gA, bA); cB.SetRGB (rB, gB, bB); cB.SetHue (cA.GetHue ()); // hue of blend image, cB.SetSaturation (cA.GetSaturation ()); // saturation of blend image, luminance from base image r = Simple_Opacity (rB, cB.GetRed (), Opacity); g = Simple_Opacity (gB, cB.GetGreen (), Opacity); b = Simple_Opacity (bB, cB.GetBlue (), Opacity); } break; case 63: // Luminance mode { CColor cA, cB; // A = blend, B = base cA.SetRGB (rA, gA, bA); cB.SetRGB (rB, gB, bB); cB.SetLuminance (cA.GetLuminance ()); // luminance from blend image, others from base image r = Simple_Opacity (rB, cB.GetRed (), Opacity); g = Simple_Opacity (gB, cB.GetGreen (), Opacity); b = Simple_Opacity (bB, cB.GetBlue (), Opacity); } break; case 64: // HSL (hue to red, saturation to green, luminance to blue) { CColor cA, cB; // A = blend, B = base cA.SetRGB (rA, gA, bA); r = Simple_Opacity (rB, cB.GetRed (), Opacity); g = Simple_Opacity (gB, cB.GetGreen (), Opacity); b = Simple_Opacity (bB, cB.GetBlue (), Opacity); } break; default: return -1; } // end of switch return RGB (CLAMP (r), CLAMP (g), CLAMP (b)); } // end of CMUSHclientDoc::BlendPixel
void CColourPopup::DrawCell(CDC* pDC, int nIndex) { // For the Custom Text area if (m_strCustomText.GetLength() && nIndex == CUSTOM_BOX_VALUE) { // The extent of the actual text button CRect TextButtonRect = m_CustomTextRect; TextButtonRect.top += 2*m_nMargin; // Fill background pDC->FillSolidRect(TextButtonRect, ::GetSysColor(COLOR_3DFACE)); // Draw horizontal line pDC->FillSolidRect(m_CustomTextRect.left+2*m_nMargin, m_CustomTextRect.top, m_CustomTextRect.Width()-4*m_nMargin, 1, ::GetSysColor(COLOR_3DSHADOW)); pDC->FillSolidRect(m_CustomTextRect.left+2*m_nMargin, m_CustomTextRect.top+1, m_CustomTextRect.Width()-4*m_nMargin, 1, ::GetSysColor(COLOR_3DHILIGHT)); TextButtonRect.DeflateRect(1,1); // fill background if (m_nChosenColourSel == nIndex && m_nCurrentSel != nIndex) pDC->FillSolidRect(TextButtonRect, ::GetSysColor(COLOR_3DLIGHT)); else pDC->FillSolidRect(TextButtonRect, ::GetSysColor(COLOR_3DFACE)); // Draw button if (m_nCurrentSel == nIndex) pDC->DrawEdge(TextButtonRect, BDR_RAISEDINNER, BF_RECT); else if (m_nChosenColourSel == nIndex) pDC->DrawEdge(TextButtonRect, BDR_SUNKENOUTER, BF_RECT); // Draw custom text CFont *pOldFont = (CFont*) pDC->SelectObject(&m_Font); pDC->SetBkMode(TRANSPARENT); pDC->DrawText(m_strCustomText, TextButtonRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE); pDC->SelectObject(pOldFont); return; } // For the Default Text area if (m_strDefaultText.GetLength() && nIndex == DEFAULT_BOX_VALUE) { // Fill background pDC->FillSolidRect(m_DefaultTextRect, ::GetSysColor(COLOR_3DFACE)); // The extent of the actual text button CRect TextButtonRect = m_DefaultTextRect; TextButtonRect.DeflateRect(1,1); // fill background if (m_nChosenColourSel == nIndex && m_nCurrentSel != nIndex) pDC->FillSolidRect(TextButtonRect, ::GetSysColor(COLOR_3DLIGHT)); else pDC->FillSolidRect(TextButtonRect, ::GetSysColor(COLOR_3DFACE)); // Draw thin line around text CRect LineRect = TextButtonRect; LineRect.DeflateRect(2*m_nMargin,2*m_nMargin); CPen pen(PS_SOLID, 1, ::GetSysColor(COLOR_3DSHADOW)); CPen* pOldPen = pDC->SelectObject(&pen); pDC->SelectStockObject(NULL_BRUSH); pDC->Rectangle(LineRect); pDC->SelectObject(pOldPen); // Draw button if (m_nCurrentSel == nIndex) pDC->DrawEdge(TextButtonRect, BDR_RAISEDINNER, BF_RECT); else if (m_nChosenColourSel == nIndex) pDC->DrawEdge(TextButtonRect, BDR_SUNKENOUTER, BF_RECT); // Draw custom text CFont *pOldFont = (CFont*) pDC->SelectObject(&m_Font); pDC->SetBkMode(TRANSPARENT); pDC->DrawText(m_strDefaultText, TextButtonRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE); pDC->SelectObject(pOldFont); return; } CRect rect; if (!GetCellRect(nIndex, rect)) return; // Select and realize the palette CPalette* pOldPalette = NULL; if (pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE) { pOldPalette = pDC->SelectPalette(&m_Palette, FALSE); pDC->RealizePalette(); } // fill background if (m_nChosenColourSel == nIndex && m_nCurrentSel != nIndex) pDC->FillSolidRect(rect, ::GetSysColor(COLOR_3DHILIGHT)); else pDC->FillSolidRect(rect, ::GetSysColor(COLOR_3DFACE)); // Draw button if (m_nCurrentSel == nIndex) pDC->DrawEdge(rect, BDR_RAISEDINNER, BF_RECT); else if (m_nChosenColourSel == nIndex) pDC->DrawEdge(rect, BDR_SUNKENOUTER, BF_RECT); CBrush brush(PALETTERGB(GetRValue(GetColour(nIndex)), GetGValue(GetColour(nIndex)), GetBValue(GetColour(nIndex)) )); CPen pen; pen.CreatePen(PS_SOLID, 1, ::GetSysColor(COLOR_3DSHADOW)); CBrush* pOldBrush = (CBrush*) pDC->SelectObject(&brush); CPen* pOldPen = (CPen*) pDC->SelectObject(&pen); // Draw the cell colour rect.DeflateRect(m_nMargin+1, m_nMargin+1); pDC->Rectangle(rect); // restore DC and cleanup pDC->SelectObject(pOldBrush); pDC->SelectObject(pOldPen); brush.DeleteObject(); pen.DeleteObject(); if (pOldPalette && pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE) pDC->SelectPalette(pOldPalette, FALSE); }
void MeterM1::DrawMeterBackground(CDC *pDC, CRect &rect) { int nInnerRadius = m_nRadiusFrame*8/10; // 内圆弧半径 m_nCenterRadius = m_nRadiusFrame/20; // 中心园半径大小 int nFrame = m_nRadiusFrame/18; // 边框厚度 double dstepTickDeg = (360.0+m_nStartAngleDeg-m_nEndAngleDeg)/(m_nTicks*m_nSubTicks); // 刻度步进角度 int nSubTickR = nInnerRadius+(m_nRadiusFrame-2*nFrame-nInnerRadius)/2; double dDeg = (m_nStartAngleDeg+360.0-m_nEndAngleDeg)/(TABNUM*PT_NUM); CRect rectPanel,rectInnerPanel; CPen penDraw, *pPenOld; CFont *pFontOld; CBrush brushFill, *pBrushOld; POINT ptStart, ptEnd, ptInnerStart, ptInnerEnd; CPoint pointInner[BOUNDARY_POINTS], ptGroup1[PT_NUM*TABNUM+1], ptGroup2[PT_NUM*TABNUM+1]; CPoint ptRgn[PT_NUM*2+2]; CPoint pttemp; CString strtemp; double dRadPerDeg; double dTickAngleRad; double dTemp; int nRef = 0; int nTickAngle; int nHeight; // 字体大小 double dtempangle; // 计算起始角终止角弧度 dRadPerDeg = 4.0*atan(1.0)/180.0; m_dLeftAngleRad = (m_nStartAngleDeg-180.0)*dRadPerDeg; m_dRightAngleRad = (m_nEndAngleDeg-360.0)*dRadPerDeg; // 计算圆弧起始终止点及区域 ptStart.x = m_ptMeterCenter.x-(int)(m_nRadiusFrame*cos(m_dLeftAngleRad)); ptStart.y = m_ptMeterCenter.y+(int)(m_nRadiusFrame*sin(m_dLeftAngleRad)); ptEnd.x = m_ptMeterCenter.x+(int)(m_nRadiusFrame*cos(-m_dRightAngleRad)); ptEnd.y = m_ptMeterCenter.y+(int)(m_nRadiusFrame*sin(-m_dRightAngleRad)); rectPanel.SetRect(m_ptMeterCenter.x-m_nRadiusFrame, m_ptMeterCenter.y-m_nRadiusFrame, m_ptMeterCenter.x+m_nRadiusFrame, m_ptMeterCenter.y+m_nRadiusFrame); // 获取点的位置 for(int i=0; i<=PT_NUM*TABNUM; i++) { ptGroup1[i].x = m_ptMeterCenter.x + (int)((m_nRadiusFrame-nFrame)*cos((m_nStartAngleDeg-i*dDeg)*dRadPerDeg)); ptGroup1[i].y = m_ptMeterCenter.y - (int)((m_nRadiusFrame-nFrame)*sin((m_nStartAngleDeg-i*dDeg)*dRadPerDeg)); ptGroup2[i].x = m_ptMeterCenter.x + (int)(m_nRadiusFrame*8*cos((m_nStartAngleDeg-i*dDeg)*dRadPerDeg)/10); ptGroup2[i].y = m_ptMeterCenter.y - (int)(m_nRadiusFrame*8*sin((m_nStartAngleDeg-i*dDeg)*dRadPerDeg)/10); } // 获取系统颜色; m_colorWindow = GetSysColor(COLOR_WINDOW); m_colorButton = GetSysColor(COLOR_BTNFACE); m_colorShadow = GetSysColor(COLOR_BTNSHADOW); m_colorHighlight = GetSysColor(COLOR_BTNHIGHLIGHT); m_colorText = GetSysColor(COLOR_BTNTEXT); // 临时使用的颜色 COLORREF colorCaption, cEdge, cMiddle; cMiddle = RGB(255, 255, 255); cEdge = RGB(96, 96, 255); // 用按钮色绘制背景 brushFill.DeleteObject(); brushFill.CreateSolidBrush(m_colorButton); pBrushOld = pDC->SelectObject(&brushFill); pDC->Rectangle(rect); pDC->SelectObject(pBrushOld); // 绘制圆盘边框 for(int iOnBand=nFrame; iOnBand>0; iOnBand--) { penDraw.DeleteObject(); colorCaption = RGB((GetRValue(cEdge)-GetRValue(cMiddle))*((float)iOnBand)/nFrame+GetRValue(cMiddle), (GetGValue(cEdge)-GetGValue(cMiddle))*((float)iOnBand)/nFrame+GetGValue(cMiddle), (GetBValue(cEdge)-GetBValue(cMiddle))*((float)iOnBand)/nFrame+GetBValue(cMiddle)); penDraw.CreatePen(PS_SOLID, iOnBand*2, colorCaption); pPenOld = pDC->SelectObject(&penDraw); pDC->Arc(&rectPanel, ptEnd, ptStart); pDC->SelectObject(pPenOld); } // 绘制内圈 ptInnerStart.x = m_ptMeterCenter.x-(int)(nInnerRadius*cos(m_dLeftAngleRad)); ptInnerStart.y = m_ptMeterCenter.y+(int)(nInnerRadius*sin(m_dLeftAngleRad)); ptInnerEnd.x = m_ptMeterCenter.x+(int)(nInnerRadius*cos(-m_dRightAngleRad)); ptInnerEnd.y = m_ptMeterCenter.y+(int)(nInnerRadius*sin(-m_dRightAngleRad)); rectInnerPanel.SetRect(m_ptMeterCenter.x-nInnerRadius, m_ptMeterCenter.y-nInnerRadius, m_ptMeterCenter.x+nInnerRadius ,m_ptMeterCenter.y+nInnerRadius); penDraw.DeleteObject(); penDraw.CreatePen(PS_SOLID, 1, RGB(255,255,0)); pPenOld = pDC->SelectObject(&penDraw); pDC->Arc(&rectInnerPanel, ptInnerEnd, ptInnerStart); pDC->SelectObject(pPenOld); if(m_bColorTick) { // 绘制色彩刻度 for(int i=0; i<TABNUM; i++) { //确定区域 for(int j=0; j<=PT_NUM; j++) { ptRgn[j] = ptGroup1[i*PT_NUM+j]; ptRgn[2*PT_NUM+1-j] = ptGroup2[i*PT_NUM+j]; } brushFill.DeleteObject(); brushFill.CreateSolidBrush(m_colorTable[i]); pBrushOld = pDC->SelectObject(&brushFill); penDraw.DeleteObject(); penDraw.CreatePen(PS_SOLID, 1, m_colorTable[i]); pPenOld = pDC->SelectObject(&penDraw); pDC->Polygon(ptRgn, 2*PT_NUM+2); pDC->SelectObject(pBrushOld); pDC->SelectObject(pPenOld); } } // 计算刻度点,避免不能整除引起较大误差*100 for(nTickAngle=m_nStartAngleDeg*100; nTickAngle>=(m_nEndAngleDeg-360)*100; nTickAngle-=(int)(dstepTickDeg*100)) { // 转换成弧度 dTickAngleRad = (double)nTickAngle/100*dRadPerDeg; // 确定外圈坐标 // 确定x坐标 dTemp = m_ptMeterCenter.x + (m_nRadiusFrame-2*nFrame)*cos(dTickAngleRad); m_pointBoundary[nRef].x = ROUND(dTemp); // 确定y坐标 dTemp = m_ptMeterCenter.y - (m_nRadiusFrame-2*nFrame)*sin(dTickAngleRad); m_pointBoundary[nRef].y = ROUND(dTemp); // 确定刻度点(主刻度和子刻度) //主刻度及文本标注点 if(nRef%m_nSubTicks == 0) { dTemp = m_ptMeterCenter.x + nInnerRadius*cos(dTickAngleRad); pointInner[nRef].x = ROUND(dTemp); dTemp = m_ptMeterCenter.y - nInnerRadius*sin(dTickAngleRad); pointInner[nRef].y = ROUND(dTemp); } // 子刻度 else { dTemp = m_ptMeterCenter.x + nSubTickR*cos(dTickAngleRad); pointInner[nRef].x = ROUND(dTemp); dTemp = m_ptMeterCenter.y - nSubTickR*sin(dTickAngleRad); pointInner[nRef].y = ROUND(dTemp); } nRef++ ; } // 多边形区域 m_rgnBoundary.DeleteObject() ; m_rgnBoundary.CreatePolygonRgn(m_pointBoundary, nRef, ALTERNATE); m_rectValue.top = m_ptMeterCenter.y + m_nRadiusFrame/5; m_rectValue.bottom = m_ptMeterCenter.y + m_nRadiusFrame/2; m_rectValue.left = m_ptMeterCenter.x - m_nRadiusFrame/2; m_rectValue.right = m_ptMeterCenter.x + m_nRadiusFrame/2; // 绘制刻度 penDraw.DeleteObject(); penDraw.CreatePen(PS_SOLID, 1, RGB(0,0,0)); pPenOld = pDC->SelectObject(&penDraw); for(int i=0; i<nRef; i++) { pDC->MoveTo(m_pointBoundary[i]); pDC->LineTo(pointInner[i]); } pDC->SelectObject(pPenOld); // 刻度标号 // 确定字体大小 nHeight = m_nRadiusFrame/6; m_font.CreateFont(nHeight, 0, 0, 0, 400, FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_SWISS, _T("Arial"));/////////////////////////////yingmou pFontOld = pDC->SelectObject(&m_font); pDC->SetBkMode(TRANSPARENT); for(int i=0; i<=m_nTicks; i++) { dtempangle = m_nStartAngleDeg-i*m_nSubTicks*dstepTickDeg; strtemp.Format(_T("%.*lf"), m_nScaleDecimals, (m_dMinValue+(m_dMaxValue-m_dMinValue)*i/m_nTicks));;////////////////////////////////////////////////yingmou if(dtempangle>190) { pDC->SetTextAlign(TA_BOTTOM|TA_LEFT); pDC->TextOut(pointInner[m_nSubTicks*i].x, pointInner[m_nSubTicks*i].y+nHeight/2, strtemp); } else if(dtempangle>170) { pDC->SetTextAlign(TA_BASELINE|TA_LEFT); pDC->TextOut(pointInner[m_nSubTicks*i].x, pointInner[m_nSubTicks*i].y+nHeight/3, strtemp); } else if(dtempangle>135) { pDC->SetTextAlign(TA_BASELINE|TA_LEFT); pDC->TextOut(pointInner[m_nSubTicks*i].x, pointInner[m_nSubTicks*i].y+nHeight/2, strtemp); } else if(dtempangle>100) { pDC->SetTextAlign(TA_TOP|TA_LEFT); pDC->TextOut(pointInner[m_nSubTicks*i].x-nHeight/4, pointInner[m_nSubTicks*i].y-nHeight/8, strtemp); } else if(dtempangle>80) { pDC->SetTextAlign(TA_TOP|TA_CENTER); pDC->TextOut(pointInner[m_nSubTicks*i].x, pointInner[m_nSubTicks*i].y, strtemp); } else if(dtempangle>45) { pDC->SetTextAlign(TA_BOTTOM|TA_RIGHT); pDC->TextOut(pointInner[m_nSubTicks*i].x+nHeight/3, pointInner[m_nSubTicks*i].y+nHeight, strtemp); } else if(dtempangle>10) { pDC->SetTextAlign(TA_RIGHT|TA_BASELINE); pDC->TextOut(pointInner[m_nSubTicks*i].x, pointInner[m_nSubTicks*i].y+nHeight/2, strtemp); } else if(dtempangle>-10) { pDC->SetTextAlign(TA_RIGHT|TA_BASELINE); pDC->TextOut(pointInner[m_nSubTicks*i].x, pointInner[m_nSubTicks*i].y+nHeight/3, strtemp); } else { pDC->SetTextAlign(TA_RIGHT|TA_BOTTOM); pDC->TextOut(pointInner[m_nSubTicks*i].x, pointInner[m_nSubTicks*i].y+nHeight/2, strtemp); } } pDC->SelectObject(pFontOld); }
void GraphicsInterface::DisplayStatus(wstring wstrText, int display_time) { GraphicsEngineOptions geo; RECT rcScreen; CMonitors cm; POINT pt = { 0, 0 }; Color cNull = Color(0, 0, 0, 0); Color cTemp; Color cOutline; Color cDropShadow; REAL rTemp; if (!m_ssSettings.bVisualFeedback) return; if (m_ssSettings.bNoDisplayWhenActive && m_ITCom->IsActiveWindow()) return; EnterCriticalSection(&_csCreateDisplay); _nDisplayType = 1; // Configure geo.nDisplayAlpha = m_ssSettings.nOSDAlpha; geo.bDisplayTopMost = m_ssSettings.bOSDTopMost; geo.nMaxWidth = m_ssSettings.nOSDMaxWidth; geo.nArtScaleMode = m_ssSettings.nArtMode == 3 ? ART_SCALEMODEHEIGHT : ART_SCALEMODESIZE; geo.saAlign = (Gdiplus::StringAlignment)m_ssSettings.nOSDTextJustify; geo.bForceToWidth = m_ssSettings.bOSDForceWidth; for (const auto& ge : _ges) { ge->SetOptions(geo); // Begin render process ge->BeginRender(5); } // Set background and borders rTemp = (REAL)m_ssSettings.nOSDBorderSize; cOutline = Color(GetRValue(m_ssSettings.lOSDBorderColor), GetGValue(m_ssSettings.lOSDBorderColor), GetBValue(m_ssSettings.lOSDBorderColor)); cTemp = Color(GetRValue(m_ssSettings.lOSDBkColorRef), GetGValue(m_ssSettings.lOSDBkColorRef), GetBValue(m_ssSettings.lOSDBkColorRef)); cDropShadow = Color(GetRValue(m_ssSettings.lDropShadowColor), GetGValue(m_ssSettings.lDropShadowColor), GetBValue(m_ssSettings.lDropShadowColor)); for (const auto& ge : _ges) { ge->SetDisplayBorder(m_ssSettings.bOSDOutlineMode ? cNull : cOutline, rTemp); ge->SetDisplayBackground(m_ssSettings.bOSDOutlineMode ? cNull : cTemp); } // Cache text height for shapes REAL text_height = _ges.at(0)->GetTextHeight(m_ssSettings.wcFontFace, (float)m_ssSettings.nOSDFontPoint, m_ssSettings.nOSDFontStyle); // Break string into lines, add to display wchar_t *lpToken = NULL; wchar_t *lpContext = NULL; wchar_t *lpRating = NULL; wchar_t *lpVolume = NULL; wchar_t *lpBeforeRating = NULL; cTemp = Color(GetRValue(m_ssSettings.lOSDColorRef), GetGValue(m_ssSettings.lOSDColorRef), GetBValue(m_ssSettings.lOSDColorRef)); Color cShapeFill = Color(GetRValue(m_ssSettings.lRatingShapeFill), GetGValue(m_ssSettings.lRatingShapeFill), GetBValue(m_ssSettings.lRatingShapeFill)); Color cShapeOutline = Color(GetRValue(m_ssSettings.lRatingShapeOutline), GetGValue(m_ssSettings.lRatingShapeOutline), GetBValue(m_ssSettings.lRatingShapeOutline)); lpToken = wcstok_s(const_cast<wchar_t*>(wstrText.c_str()), L"\n", &lpContext); while (NULL != lpToken && m_ssSettings.nDisplayLayout != 4) { for (const auto& ge : _ges) { ge->BeginLine(); } // check for %rating% in string, replace with img rating lpRating = wcsstr(lpToken, L"%rating%"); lpVolume = wcsstr(lpToken, L"%volume%"); if (NULL != lpVolume) { // Break up line lpBeforeRating = new wchar_t[lpVolume - lpToken + 1]; wcsncpy_s(lpBeforeRating, lpVolume - lpToken + 1, lpToken, lpVolume - lpToken); // Add text before rating for (const auto& ge : _ges) { ge->AddString(lpBeforeRating, false, m_ssSettings.nOSDFontStyle, (float)m_ssSettings.nOSDFontPoint, cTemp, m_ssSettings.wcFontFace, m_ssSettings.bOSDOutlineMode ? cOutline : cNull, 1.5f, m_ssSettings.bUseDropShadow ? m_ssSettings.fDropShadowOffset : 0.0f, cDropShadow); } // Add rating unsigned int lVolume = m_ITCom->GetVolumeLevel(); RectF rfShape = RectF(0, 0, text_height*10.0f, text_height*1.5f); for (const auto& ge : _ges) { ge->AddShape(ShapeVolume, FillCustom, rfShape, false, cShapeOutline, 3.0, cShapeFill, lVolume); // Add text after rating ge->AddString(lpVolume + 8, false, m_ssSettings.nOSDFontStyle, (float)m_ssSettings.nOSDFontPoint, cTemp, m_ssSettings.wcFontFace, m_ssSettings.bOSDOutlineMode ? cOutline : cNull, 1.5f, m_ssSettings.bUseDropShadow ? m_ssSettings.fDropShadowOffset : 0.0f, cDropShadow); } delete[] lpBeforeRating; } else if (NULL != lpRating) { // Break up line lpBeforeRating = new wchar_t[lpRating - lpToken + 1]; wcsncpy_s(lpBeforeRating, lpRating - lpToken + 1, lpToken, lpRating - lpToken); // Add text before rating for (const auto& ge : _ges) { ge->AddString(lpBeforeRating, false, m_ssSettings.nOSDFontStyle, (float)m_ssSettings.nOSDFontPoint, cTemp, m_ssSettings.wcFontFace, m_ssSettings.bOSDOutlineMode ? cOutline : cNull, 1.5f, m_ssSettings.bUseDropShadow ? m_ssSettings.fDropShadowOffset : 0.0f, cDropShadow); } // Add rating long lRating = m_ITCom->GetTrackRating(); long lWhole = (lRating - (lRating % 20)) / 20; lRating = lRating - lWhole * 20; long lHalf = (lRating - (lRating % 10)) / 10; long lEmpty = 5 - lWhole - lHalf; RectF rfShape = RectF(0, 0, text_height, text_height); for (int i = 0; i < lWhole; i++) { for (const auto& ge : _ges) { if (m_ssSettings.nRatingType == 1) ge->AddImage(m_ssSettings.wcRatingFullPath); else ge->AddShape((ShapeType)m_ssSettings.nRatingShapeType, FillAll, rfShape, false, cShapeOutline, 3.0, cShapeFill); } } for (int i = 0; i < lHalf; i++) { for (const auto& ge : _ges) { if (m_ssSettings.nRatingType == 1) ge->AddImage(m_ssSettings.wcRatingHalfPath); else ge->AddShape((ShapeType)m_ssSettings.nRatingShapeType, (ShapeStyle)(m_ssSettings.nRatingShapeStyle + 2), rfShape, false, cShapeOutline, 3.0, cShapeFill); } } for (int i = 0; i < lEmpty; i++) { for (const auto& ge : _ges) { if (m_ssSettings.nRatingType == 1) ge->AddImage(m_ssSettings.wcRatingEmptyPath); else ge->AddShape((ShapeType)m_ssSettings.nRatingShapeType, FillNone, rfShape, false, cShapeOutline, 3.0, cShapeFill); } } // Add text after rating for (const auto& ge : _ges) { ge->AddString(lpRating + 8, false, m_ssSettings.nOSDFontStyle, (float)m_ssSettings.nOSDFontPoint, cTemp, m_ssSettings.wcFontFace, m_ssSettings.bOSDOutlineMode ? cOutline : cNull, 1.5f, m_ssSettings.bUseDropShadow ? m_ssSettings.fDropShadowOffset : 0.0f, cDropShadow); } delete[] lpBeforeRating; } else { for (const auto& ge : _ges) { ge->AddString(lpToken, false, m_ssSettings.nOSDFontStyle, (float)m_ssSettings.nOSDFontPoint, cTemp, m_ssSettings.wcFontFace, m_ssSettings.bOSDOutlineMode ? cOutline : cNull, 1.5f, m_ssSettings.bUseDropShadow ? m_ssSettings.fDropShadowOffset : 0.0f, cDropShadow); } } for (const auto& ge : _ges) { ge->EndLine(); } lpToken = wcstok_s(NULL, L"\n", &lpContext); } // Position display if (!cm.GetMonitorRect(m_ssSettings.nOSDMonitor, rcScreen)) SystemParametersInfo(SPI_GETWORKAREA, 0, &rcScreen, 0); pt.x = rcScreen.left + (LONG)ceilf((m_ssSettings.nOSDHoriz / 100.0f) * (rcScreen.right - rcScreen.left)); pt.y = rcScreen.top + (LONG)ceilf((m_ssSettings.nOSDVert / 100.0f) * (rcScreen.bottom - rcScreen.top)); // Show display, start timer if (m_ssSettings.bOSDAllMonitors) { int monitor = 1; for (const auto& ge : _ges) { // Position display cm.GetMonitorRect(monitor, rcScreen); pt.x = rcScreen.left + (LONG)ceilf((m_ssSettings.nOSDHoriz / 100.0f) * (rcScreen.right - rcScreen.left)); pt.y = rcScreen.top + (LONG)ceilf((m_ssSettings.nOSDVert / 100.0f) * (rcScreen.bottom - rcScreen.top)); ge->EndRender(pt, rcScreen); ++monitor; } } else { for (const auto& ge : _ges) { ge->EndRender(pt, rcScreen); } } // Display should be shown for xx seconds, then hidden if (NULL != _hDisplayTimer) DeleteTimerQueueTimer(_hTimerQueue, _hDisplayTimer, INVALID_HANDLE_VALUE); _hDisplayTimer = NULL; CreateTimerQueueTimer(&_hDisplayTimer, _hTimerQueue, DisplayTimerCallback, (PVOID)this, display_time, 0, WT_EXECUTEDEFAULT | WT_EXECUTEONLYONCE); DisplayShow(); LeaveCriticalSection(&_csCreateDisplay); return; }
HIMAGELIST SdkCreateGrayImageList( IN HIMAGELIST himlNormal ) { int Count, i; int Width, Height; HIMAGELIST himlGray; HDC hdcDesktop; HDC hdcMem; RECT rc; COLORREF crMask; HPALETTE hpal; UINT index; HGDIOBJ hbm; HGDIOBJ hbmOld; COLORREF rgb; BYTE gray; HWND hWnd; int x, y; Count = ImageList_GetImageCount(himlNormal); if (Count == 0) { return NULL; } ImageList_GetIconSize(himlNormal, &Width, &Height); himlGray = ImageList_Create(Width, Height, ILC_COLOR24 | ILC_MASK, Count, 0); hdcDesktop = GetDC(NULL); hdcMem = CreateCompatibleDC(NULL); rc.top = rc.left = 0; rc.bottom = Height; rc.right = Width; crMask = RGB(200, 199, 200); if (GetDeviceCaps(hdcDesktop, BITSPIXEL) < 24) { hpal = (HPALETTE)GetCurrentObject(hdcDesktop, OBJ_PAL); index = GetNearestPaletteIndex(hpal, crMask); if (index != CLR_INVALID) { crMask = PALETTEINDEX(index); } } for (i = 0 ; i < Count; ++i) { hbm = CreateCompatibleBitmap(hdcDesktop, Width, Height); hbmOld = SelectObject(hdcMem, hbm); SdkFillSolidRect(hdcMem, crMask, &rc); ImageList_SetBkColor(himlNormal, crMask); ImageList_Draw(himlNormal, i, hdcMem, 0, 0, ILD_NORMAL); for (x = 0 ; x < Width; ++x) { for (y = 0; y < Height; ++y) { rgb = GetPixel(hdcMem, x, y); if (rgb != crMask) { gray = (BYTE) (95 + (GetRValue(rgb) * 3 + GetGValue(rgb) * 6 + GetBValue(rgb)) / 20); SetPixel(hdcMem, x, y, RGB(gray, gray, gray)); } } } hbm = SelectObject(hdcMem, hbmOld); ImageList_AddMasked(himlGray, (HBITMAP)hbm, crMask); DeleteObject(hbm); } DeleteDC(hdcMem); hWnd = WindowFromDC(hdcDesktop); ReleaseDC(hWnd, hdcDesktop); return himlGray; }
void GraphicsInterface::DisplayInfo(wstring wstrText, bool bArtwork, wchar_t *wcArt, int display_time, bool bUpdateOnly) { GraphicsEngineOptions geo; RECT rcScreen; CMonitors cm; POINT pt = { 0, 0 }; Color cNull = Color(0, 0, 0, 0); Color cTemp; Color cOutline; Color cArtOutline; Color cDropShadow; REAL rTemp; if (!m_ssSettings.bVisualFeedback) return; if (m_ssSettings.bNoDisplayWhenActive && m_ITCom->IsActiveWindow()) return; if (bUpdateOnly && (_nDisplayType == 1 || !IsDisplayVisible())) return; EnterCriticalSection(&_csCreateDisplay); _nDisplayType = 0; // Configure geo.nDisplayAlpha = m_ssSettings.nOSDAlpha; geo.bDisplayTopMost = m_ssSettings.bOSDTopMost; geo.nMaxWidth = m_ssSettings.nOSDMaxWidth; geo.nArtScaleMode = m_ssSettings.nArtMode == 3 ? ART_SCALEMODEHEIGHT : ART_SCALEMODESIZE; geo.saAlign = (Gdiplus::StringAlignment)m_ssSettings.nOSDTextJustify; geo.bForceToWidth = m_ssSettings.bOSDForceWidth; if (!bArtwork || NULL == wcArt || 0 == wcscmp(wcArt, L"")) { for (const auto& ge : _ges) { ge->SetOptions(geo); ge->BeginRender(5); } } else { for (const auto& ge : _ges) { ge->SetOptions(geo); ge->BeginRender(m_ssSettings.nDisplayLayout); } } // Set background and borders rTemp = (REAL)m_ssSettings.nOSDBorderSize; cOutline = Color(GetRValue(m_ssSettings.lOSDBorderColor), GetGValue(m_ssSettings.lOSDBorderColor), GetBValue(m_ssSettings.lOSDBorderColor)); cTemp = Color(GetRValue(m_ssSettings.lOSDBkColorRef), GetGValue(m_ssSettings.lOSDBkColorRef), GetBValue(m_ssSettings.lOSDBkColorRef)); cDropShadow = Color(GetRValue(m_ssSettings.lDropShadowColor), GetGValue(m_ssSettings.lDropShadowColor), GetBValue(m_ssSettings.lDropShadowColor)); cArtOutline = Color(GetRValue(m_ssSettings.lArtBorderColor), GetGValue(m_ssSettings.lArtBorderColor), GetBValue(m_ssSettings.lArtBorderColor)); for (const auto& ge : _ges) { ge->SetDisplayBorder(m_ssSettings.bOSDOutlineMode ? cNull : cOutline, rTemp); ge->SetDisplayBackground(m_ssSettings.bOSDOutlineMode ? cNull : cTemp); } // Add album art if needed if (bArtwork && m_ssSettings.bShowArtwork) { for (const auto& ge : _ges) { ge->AddArt(wcArt, false, cArtOutline, 1.5f, (float)m_ssSettings.nArtConstSize, m_ssSettings.nArtMode == 3 ? IMG_SCALENONE : IMG_SCALEALL); } } // Cache text height for shapes static REAL text_height; if (!bUpdateOnly) text_height = _ges.at(0)->GetTextHeight(m_ssSettings.wcFontFace, (float)m_ssSettings.nOSDFontPoint, m_ssSettings.nOSDFontStyle); // Break string into lines, add to display wchar_t *lpToken = NULL; wchar_t *lpContext = NULL; std::wstring line; size_t current_position = 0; size_t next_rating = 0; size_t next_format = 0; int old_font_style = m_ssSettings.nOSDFontStyle; cTemp = Color(GetRValue(m_ssSettings.lOSDColorRef), GetGValue(m_ssSettings.lOSDColorRef), GetBValue(m_ssSettings.lOSDColorRef)); Color cShapeFill = Color(GetRValue(m_ssSettings.lRatingShapeFill), GetGValue(m_ssSettings.lRatingShapeFill), GetBValue(m_ssSettings.lRatingShapeFill)); Color cShapeOutline = Color(GetRValue(m_ssSettings.lRatingShapeOutline), GetGValue(m_ssSettings.lRatingShapeOutline), GetBValue(m_ssSettings.lRatingShapeOutline)); lpToken = wcstok_s(const_cast<wchar_t*>(wstrText.c_str()), L"\n", &lpContext); while (NULL != lpToken && m_ssSettings.nDisplayLayout != 4) { for (const auto& ge : _ges) { ge->BeginLine(); } line = lpToken; current_position = 0; do { next_rating = line.find(L"%rating%", current_position); next_format = line.find(L"<", current_position); if ((next_rating == std::wstring::npos && next_format != std::wstring::npos) || (next_format != std::wstring::npos && next_rating != std::wstring::npos && next_format < next_rating)) { // format if ((next_format - current_position) > 0) { for (const auto& ge : _ges) { ge->AddString(line.substr(current_position, next_format - current_position).c_str(), false, m_ssSettings.nOSDFontStyle, (float)m_ssSettings.nOSDFontPoint, cTemp, m_ssSettings.wcFontFace, m_ssSettings.bOSDOutlineMode ? cOutline : cNull, 1.5f, m_ssSettings.bUseDropShadow ? m_ssSettings.fDropShadowOffset : 0.0f, cDropShadow); } } if (line.compare(next_format, 3, L"<b>") == 0) { m_ssSettings.nOSDFontStyle |= FontStyleBold; current_position = next_format + 3; } else if (line.compare(next_format, 3, L"<i>") == 0) { m_ssSettings.nOSDFontStyle |= FontStyleItalic; current_position = next_format + 3; } else if (line.compare(next_format, 4, L"</b>") == 0) { m_ssSettings.nOSDFontStyle &= ~FontStyleBold; current_position = next_format + 4; } else if (line.compare(next_format, 4, L"</i>") == 0) { m_ssSettings.nOSDFontStyle &= ~FontStyleItalic; current_position = next_format + 4; } else { for (const auto& ge : _ges) { ge->AddString(line.substr(next_format, 1).c_str(), false, m_ssSettings.nOSDFontStyle, (float)m_ssSettings.nOSDFontPoint, cTemp, m_ssSettings.wcFontFace, m_ssSettings.bOSDOutlineMode ? cOutline : cNull, 1.5f, m_ssSettings.bUseDropShadow ? m_ssSettings.fDropShadowOffset : 0.0f, cDropShadow); } current_position = next_format + 1; } } else if ((next_format == std::wstring::npos && next_rating != std::wstring::npos) || (next_format != std::wstring::npos && next_rating != std::wstring::npos && next_rating < next_format)) { // rating if ((next_rating - current_position) > 0) { for (const auto& ge : _ges) { ge->AddString(line.substr(current_position, next_rating - current_position).c_str(), false, m_ssSettings.nOSDFontStyle, (float)m_ssSettings.nOSDFontPoint, cTemp, m_ssSettings.wcFontFace, m_ssSettings.bOSDOutlineMode ? cOutline : cNull, 1.5f, m_ssSettings.bUseDropShadow ? m_ssSettings.fDropShadowOffset : 0.0f, cDropShadow); } } // Add rating long lRating = m_ITCom->GetTrackRating(); long lWhole = (lRating - (lRating % 20)) / 20; lRating = lRating - lWhole * 20; long lHalf = (lRating - (lRating % 10)) / 10; long lEmpty = 5 - lWhole - lHalf; RectF rfShape = RectF(0, 0, text_height, text_height); for (int i = 0; i < lWhole; i++) { for (const auto& ge : _ges) { if (m_ssSettings.nRatingType == 1) ge->AddImage(m_ssSettings.wcRatingFullPath); else ge->AddShape((ShapeType)m_ssSettings.nRatingShapeType, FillAll, rfShape, false, cShapeOutline, 3.0, cShapeFill); } } for (int i = 0; i < lHalf; i++) { for (const auto& ge : _ges) { if (m_ssSettings.nRatingType == 1) ge->AddImage(m_ssSettings.wcRatingHalfPath); else ge->AddShape((ShapeType)m_ssSettings.nRatingShapeType, (ShapeStyle)(m_ssSettings.nRatingShapeStyle + 2), rfShape, false, cShapeOutline, 3.0, cShapeFill); } } for (int i = 0; i < lEmpty; i++) { for (const auto& ge : _ges) { if (m_ssSettings.nRatingType == 1) ge->AddImage(m_ssSettings.wcRatingEmptyPath); else ge->AddShape((ShapeType)m_ssSettings.nRatingShapeType, FillNone, rfShape, false, cShapeOutline, 3.0, cShapeFill); } } current_position = next_rating + 8; } else { // no special processing needed if (line.substr(current_position, std::wstring::npos).length() > 0) { for (const auto& ge : _ges) { ge->AddString(line.substr(current_position, std::wstring::npos).c_str(), false, m_ssSettings.nOSDFontStyle, (float)m_ssSettings.nOSDFontPoint, cTemp, m_ssSettings.wcFontFace, m_ssSettings.bOSDOutlineMode ? cOutline : cNull, 1.5f, m_ssSettings.bUseDropShadow ? m_ssSettings.fDropShadowOffset : 0.0f, cDropShadow); } } } } while (next_format != std::wstring::npos || next_rating != std::wstring::npos); for (const auto& ge : _ges) { ge->EndLine(); } lpToken = wcstok_s(NULL, L"\n", &lpContext); } // Restore font style m_ssSettings.nOSDFontStyle = old_font_style; // Show display, start timer if (_bmInfo) { delete _bmInfo; _bmInfo = NULL; } if (m_ssSettings.bOSDAllMonitors) { bool has_track_pos = (NULL != wcsstr(m_ssSettings.wcOSDFormat, L"%track_position%")); int monitor = 1; for (const auto& ge : _ges) { // Position display cm.GetMonitorRect(monitor, rcScreen); pt.x = rcScreen.left + (LONG)ceilf((m_ssSettings.nOSDHoriz / 100.0f) * (rcScreen.right - rcScreen.left)); pt.y = rcScreen.top + (LONG)ceilf((m_ssSettings.nOSDVert / 100.0f) * (rcScreen.bottom - rcScreen.top)); if (has_track_pos) ge->EndRender(pt, rcScreen); else ge->EndRender(pt, rcScreen, m_ssSettings.bOSDAlwaysUp, &_bmInfo); ++monitor; } } else { // Position display if (!cm.GetMonitorRect(m_ssSettings.nOSDMonitor, rcScreen)) SystemParametersInfo(SPI_GETWORKAREA, 0, &rcScreen, 0); pt.x = rcScreen.left + (LONG)ceilf((m_ssSettings.nOSDHoriz / 100.0f) * (rcScreen.right - rcScreen.left)); pt.y = rcScreen.top + (LONG)ceilf((m_ssSettings.nOSDVert / 100.0f) * (rcScreen.bottom - rcScreen.top)); if (NULL != wcsstr(m_ssSettings.wcOSDFormat, L"%track_position%")) { for (const auto& ge : _ges) { ge->EndRender(pt, rcScreen); } } else { for (const auto& ge : _ges) { ge->EndRender(pt, rcScreen, m_ssSettings.bOSDAlwaysUp, &_bmInfo); } } } // Display should be shown for xx seconds, then hidden if (!bUpdateOnly) { if (!m_ssSettings.bOSDAlwaysUp) { if (NULL != _hDisplayTimer) DeleteTimerQueueTimer(_hTimerQueue, _hDisplayTimer, INVALID_HANDLE_VALUE); _hDisplayTimer = NULL; CreateTimerQueueTimer(&_hDisplayTimer, _hTimerQueue, DisplayTimerCallback, (PVOID)this, display_time, 0, WT_EXECUTEDEFAULT | WT_EXECUTEONLYONCE); } DisplayShow(); } LeaveCriticalSection(&_csCreateDisplay); return; }
void CChartGradient::DrawGradient(CDC* pDC, const CRect& GradientRect, COLORREF Color1, COLORREF Color2, EGradientType GradientType) { #if _MFC_VER > 0x0600 if ( (GradientType == gtHorizontal) || (GradientType == gtVertical) ) { TRIVERTEX vertex[2] ; vertex[0].x = GradientRect.left; vertex[0].y = GradientRect.top; vertex[0].Red = ((COLOR16)GetRValue(Color1))<<8; vertex[0].Green = ((COLOR16)GetGValue(Color1))<<8; vertex[0].Blue = ((COLOR16)GetBValue(Color1))<<8; vertex[0].Alpha = 0x0000; vertex[1].x = GradientRect.right; vertex[1].y = GradientRect.bottom; vertex[1].Red = ((COLOR16)GetRValue(Color2))<<8; vertex[1].Green = ((COLOR16)GetGValue(Color2))<<8; vertex[1].Blue = ((COLOR16)GetBValue(Color2))<<8; vertex[1].Alpha = 0x0000; GRADIENT_RECT gRect; gRect.UpperLeft = 0; gRect.LowerRight = 1; if (GradientType == gtHorizontal) pDC->GradientFill(vertex,2,&gRect,1,GRADIENT_FILL_RECT_H); else pDC->GradientFill(vertex,2,&gRect,1,GRADIENT_FILL_RECT_V); } else { for (int i=0;i<2; i++) { TRIVERTEX vertex[2] ; if (GradientType == gtHorizontalDouble) { vertex[0].x = GradientRect.left + (GradientRect.Width()/2) * i; vertex[0].y = GradientRect.top; } else { vertex[0].x = GradientRect.left; vertex[0].y = GradientRect.top + (GradientRect.Height()/2) * i; } if (i==0) { vertex[0].Red = ((COLOR16)GetRValue(Color1))<<8; vertex[0].Green = ((COLOR16)GetGValue(Color1))<<8; vertex[0].Blue = ((COLOR16)GetBValue(Color1))<<8; } else { vertex[0].Red = ((COLOR16)GetRValue(Color2))<<8; vertex[0].Green = ((COLOR16)GetGValue(Color2))<<8; vertex[0].Blue = ((COLOR16)GetBValue(Color2))<<8; } vertex[0].Alpha = 0x0000; if (GradientType == gtHorizontalDouble) { vertex[1].x = GradientRect.left + (GradientRect.Width()/2) * (i+1); vertex[1].y = GradientRect.bottom; } else { vertex[1].x = GradientRect.right; vertex[1].y = GradientRect.top + (GradientRect.Height()/2) * (i+1); } if (i==0) { vertex[1].Red = ((COLOR16)GetRValue(Color2))<<8; vertex[1].Green = ((COLOR16)GetGValue(Color2))<<8; vertex[1].Blue = ((COLOR16)GetBValue(Color2))<<8; } else { vertex[1].Red = ((COLOR16)GetRValue(Color1))<<8; vertex[1].Green = ((COLOR16)GetGValue(Color1))<<8; vertex[1].Blue = ((COLOR16)GetBValue(Color1))<<8; } vertex[1].Alpha = 0x0000; GRADIENT_RECT gRect; gRect.UpperLeft = 0; gRect.LowerRight = 1; if (GradientType == gtHorizontalDouble) pDC->GradientFill(vertex,2,&gRect,1,GRADIENT_FILL_RECT_H); else pDC->GradientFill(vertex,2,&gRect,1,GRADIENT_FILL_RECT_V); } } #else CBrush NewBrush(Color1); pDC->FillRect(GradientRect,&NewBrush); DeleteObject(NewBrush); #endif }
OP_STATUS SVGColor::GetStringRepresentation(TempBuffer* buffer) const { if(m_color_type == SVGCOLOR_RGBCOLOR) { if (m_color & CSS_COLOR_KEYWORD_TYPE_named && !(m_color & ~(CSS_COLOR_KEYWORD_TYPE_named | CSS_COLOR_KEYWORD_TYPE_index))) { const uni_char* colorstr = NULL; if((m_color & CSS_COLOR_KEYWORD_TYPE_ui_color) == CSS_COLOR_KEYWORD_TYPE_ui_color) { colorstr = CSS_GetKeywordString((short)(m_color & CSS_COLOR_KEYWORD_TYPE_index)); } else if(m_color & CSS_COLOR_KEYWORD_TYPE_x_color) { colorstr = HTM_Lex::GetColNameByIndex(m_color & CSS_COLOR_KEYWORD_TYPE_index); } #ifdef _DEBUG else { OP_ASSERT(!"Unknown color type"); } #endif if(colorstr) { return buffer->Append(colorstr); } } else { OpString8 a; if(OP_GET_A_VALUE(m_color) != 255) { RETURN_IF_ERROR(a.AppendFormat("rgba(%d,%d,%d,%d)", OP_GET_R_VALUE(m_color), OP_GET_G_VALUE(m_color), OP_GET_B_VALUE(m_color), OP_GET_A_VALUE(m_color))); } else { RETURN_IF_ERROR(a.AppendFormat("#%02x%02x%02x", GetRValue(m_color), GetGValue(m_color), GetBValue(m_color))); } return buffer->Append(a.CStr(), a.Length()); } } else if(m_color_type == SVGCOLOR_CURRENT_COLOR) { return buffer->Append("currentColor"); } else if(m_color_type == SVGCOLOR_RGBCOLOR_ICCCOLOR) { // FIXME: Generate this string } else if(m_color_type == SVGCOLOR_NONE) { return buffer->Append("none"); } OP_ASSERT(!"Unknown or unsupported color type"); return OpStatus::ERR; }