int main(int argc, char** argv) { std::cout<<"* ___ ____ _ _ _ _ "<<std::endl; std::cout<<"* |__] | |\\ | \\/ "<<std::endl; std::cout<<"* | |___ | \\| _/\\_ "<<std::endl; std::cout<<"-----------------------------"<<std::endl; std::cout<<"leetlights v0.1"<<std::endl; CROCCAT_Talk roccat; roccat.RestoreLEDRGB(); const int bins = 15; int nScreenWidth = GetSystemMetrics(SM_CXSCREEN); int nScreenHeight = GetSystemMetrics(SM_CYSCREEN); const int miniScreenY = nScreenHeight/10; const int miniScreenX = nScreenWidth/10; HWND hDesktopWnd = GetDesktopWindow(); HDC hDesktopDC = GetDC(hDesktopWnd); HDC hCaptureDC = CreateCompatibleDC(hDesktopDC); HBITMAP hCaptureBitmap =CreateCompatibleBitmap(hDesktopDC, miniScreenX, miniScreenY); SelectObject(hCaptureDC,hCaptureBitmap); SetStretchBltMode(hCaptureDC,HALFTONE); int histogram[bins+1][bins+1][bins+1]; COLORREF* pixel = new COLORREF [ miniScreenX * miniScreenY ]; int lR=0; int lG=0; int lB=0; DWORD start = GetTickCount(); DWORD diff; DWORD lastTime = start+1; DWORD time; while(true) { time = GetTickCount(); diff= start-time ; lastTime = time ; if(!StretchBlt(hCaptureDC,0,0,miniScreenX,miniScreenY,hDesktopDC,0,0,nScreenWidth,nScreenHeight,SRCCOPY)) { std::cout<<"Capturing failed, skipping iteration"<<std::endl; Sleep(100); continue; } BITMAPINFO MyBMInfo = {0}; BITMAPINFO bmpInfo; bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmpInfo.bmiHeader.biWidth = miniScreenX; bmpInfo.bmiHeader.biHeight = miniScreenY; bmpInfo.bmiHeader.biPlanes = 1; bmpInfo.bmiHeader.biBitCount = 32; bmpInfo.bmiHeader.biCompression = BI_RGB; bmpInfo.bmiHeader.biSizeImage = 0; bmpInfo.bmiHeader.biClrUsed = 0; bmpInfo.bmiHeader.biClrImportant = 0; if(0 == GetDIBits(hCaptureDC, hCaptureBitmap, 0,(UINT)miniScreenY, pixel, (BITMAPINFO *)&bmpInfo, DIB_RGB_COLORS)) { std::cout<<"Receiving Data failed, skipping interation"<<std::endl; Sleep(100); continue; } int r,g,b; int rB,gB,bB; int max1 =0; int maxR1=0; int maxG1=0; int maxB1=0; int max2 =0; int maxR2=0; int maxG2=0; int maxB2=0; int max3 =0; int maxR3=0; int maxG3=0; int maxB3=0; int max4 =0; int maxR4=0; int maxG4=0; int maxB4=0; int lastColorIntensity =0; memset(histogram,0,sizeof(histogram[0][0][0])*bins*bins*bins); for (int i=0; i<miniScreenX*miniScreenY; i++) { r =GetBValue(pixel[i]); g =GetGValue(pixel[i]); b =GetRValue(pixel[i]); rB = (int)(r/255.f*(bins)); gB = (int)(g/255.f*(bins)); bB = (int)(b/255.f*(bins)); histogram[rB][gB][bB] ++; if(histogram[rB][gB][bB] >=max4) { int nr = histogram[rB][gB][bB]; if(rB ==0 &&gB ==0 &&bB ==0 )continue; if(nr <max3) { max4 = nr; maxR4 =rB; maxG4 =gB; maxB4 =bB; } else if(nr <max2) { max3 = nr; maxR3 =rB; maxG3 =gB; maxB3 =bB; } else if(nr <max1) { max2 = nr; maxR2 =rB; maxG2 =gB; maxB2 =bB; } else { max1 = nr; maxR1 =rB; maxG1 =gB; maxB1 =bB; } } } float i1 = (max(maxR1,max(maxG1,maxB1))+min(max(min(maxG1,maxB1),maxR1),max(maxG1,maxB1)))/(float)(maxR1+maxG1+maxB1+1)+0*(maxR1+maxG1+maxB1)/(3*255.f)-((maxR1-maxG1)-(maxR1-maxB1)-(maxG1-maxB1)); float i2 = (max(maxR2,max(maxG2,maxB2))+min(max(min(maxG2,maxB2),maxR2),max(maxG2,maxB2)))/(float)(maxR2+maxG2+maxB2+1)+0*(maxR2+maxG2+maxB2)/(3*255.f)-((maxR1-maxG1)-(maxR1-maxB1)-(maxG1-maxB1)); float i3 = (max(maxR3,max(maxG3,maxB3))+min(max(min(maxG3,maxB3),maxR3),max(maxG3,maxB3)))/(float)(maxR3+maxG3+maxB3+1)+0*(maxR3+maxG3+maxB3)/(3*255.f)-((maxR1-maxG1)-(maxR1-maxB1)-(maxG1-maxB1)); float i4 = (max(maxR4,max(maxG4,maxB4))+min(max(min(maxG4,maxB4),maxR4),max(maxG4,maxB4)))/(float)(maxR4+maxG4+maxB4+1)+0*(maxR4+maxG4+maxB4)/(3*255.f)-((maxR1-maxG1)-(maxR1-maxB1)-(maxG1-maxB1)); float c = max(max(i1,i2),max(i3,i4)); BYTE r2; BYTE g2; BYTE b2; if(c==i1) { r2 = maxR1/(float)(bins+1)*255; g2 = maxG1/(float)(bins+1)*255; b2 = maxB1/(float)(bins+1)*255; } else if(c==i2) { r2 = maxR2/(float)(bins+1)*255; g2 = maxG2/(float)(bins+1)*255; b2 = maxB2/(float)(bins+1)*255; } else if(c ==i3) { r2 = maxR3/(float)(bins+1)*255; g2 = maxG3/(float)(bins+1)*255; b2 = maxB3/(float)(bins+1)*255; }else if(c==i4) { r2 = maxR4/(float)(bins+1)*255; g2 = maxG4/(float)(bins+1)*255; b2 = maxB4/(float)(bins+1)*255; } int r1,g1,b1; r1 = lR+(-lR+r2)/12; g1 = lG+(-lG+g2)/12; b1 = lB+(-lB+b2)/12; lR = r1; lG= g1; lB = b1; roccat.Set_LED_RGB(0x01,0x01,0x00,r1,g1,b1); } ReleaseDC(hDesktopWnd,hDesktopDC); DeleteDC(hCaptureDC); DeleteObject(hCaptureBitmap); }
//上传图片 void CDlgCustomFace::OnBnClickedUpload() { if ( m_Image.IsNull() ) { ShowMessage(TEXT("请选择图片!")); return ; } //设置状态 m_enOperateStatus = enOperateStatus_Upload; //链接网络 if ( ConnectServer() == false ) { //设置状态 m_enOperateStatus = enOperateStatus_NULL; return; } //获取DC CDC *pDC = GetDC(); LONG lBmpSize = LARGE_FACE_HEIGHT * (LARGE_FACE_WIDTH*3+LARGE_FACE_WIDTH%4) ; BYTE *pByteBmpData = (BYTE *)VirtualAlloc(NULL,lBmpSize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); //构造位图 BITMAPFILEHEADER bfh; BITMAPINFOHEADER bih; bfh.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER); bfh.bfReserved1=0; bfh.bfReserved2=0; bfh.bfType = 0x4D42; bfh.bfSize=lBmpSize+sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER) ; bih.biBitCount=24; bih.biClrImportant=0; bih.biClrUsed=0; bih.biCompression=BI_RGB; bih.biHeight=LARGE_FACE_HEIGHT; bih.biPlanes=1; bih.biSize=sizeof(bih); bih.biSizeImage=0; bih.biWidth=LARGE_FACE_WIDTH; bih.biXPelsPerMeter=0; bih.biYPelsPerMeter=0; //设置像素 WORD wWidth = (LARGE_FACE_WIDTH*3+LARGE_FACE_WIDTH%4); for ( int nCol = 0, nRealCol = LARGE_FACE_HEIGHT-1; nCol < LARGE_FACE_HEIGHT; ++nCol, --nRealCol ) for ( WORD wRow = 0, wByteIdex = 0; wRow < LARGE_FACE_WIDTH; wRow++, wByteIdex+=3) { COLORREF clr = pDC->GetPixel(LARGE_FRAME_LEFT+wRow, LARGE_FRAME_TOP+nCol); pByteBmpData[nRealCol*wWidth+wByteIdex] = GetBValue(clr); pByteBmpData[nRealCol*wWidth+wByteIdex+1] = GetGValue(clr); pByteBmpData[nRealCol*wWidth+wByteIdex+2] = GetRValue(clr); } //创建目录 CString strDirName = CString(g_GlobalUnits.GetWorkDirectory()) + TEXT("\\CustomFace"); CreateDirectory(strDirName, NULL) ; CString strFileName; strFileName = TEXT("\\MyFace.bmp"); //写入文件 CFile fileMyFace; try { if ( fileMyFace.Open(strDirName + strFileName, CFile::modeCreate|CFile::modeWrite|CFile::typeBinary) ) { //写入位图 fileMyFace.Write(&bfh, sizeof(bfh)); fileMyFace.Write(&bih, sizeof(bih)); fileMyFace.Write(pByteBmpData, lBmpSize); //关闭文件 fileMyFace.Close(); } //压缩文件 CZip oZip( strDirName + strFileName ); oZip.SwapSize( strDirName+TEXT("\\MyFace.zip") ); } catch(...){} //释放资源 ReleaseDC(pDC); VirtualFree(pByteBmpData, lBmpSize , MEM_DECOMMIT) ; //更新控件 UpdateControls(); }
char* Log_CreateRtfHeader(MODULEINFO *mi) { int i; // guesstimate amount of memory for the RTF header size_t bufferEnd = 0, bufferAlloced = 4096; char *buffer = (char *)mir_realloc(mi->pszHeader, bufferAlloced); buffer[0] = '\0'; // get the number of pixels per logical inch HDC hdc = GetDC(NULL); chatApi.logPixelSY = GetDeviceCaps(hdc, LOGPIXELSY); chatApi.logPixelSX = GetDeviceCaps(hdc, LOGPIXELSX); ReleaseDC(NULL, hdc); // ### RTF HEADER // font table Log_Append(buffer, bufferEnd, bufferAlloced, "{\\rtf1\\ansi\\deff0{\\fonttbl"); for (i = 0; i < OPTIONS_FONTCOUNT; i++) Log_Append(buffer, bufferEnd, bufferAlloced, "{\\f%u\\fnil\\fcharset%u%S;}", i, chatApi.aFonts[i].lf.lfCharSet, chatApi.aFonts[i].lf.lfFaceName); // colour table Log_Append(buffer, bufferEnd, bufferAlloced, "}{\\colortbl ;"); for (i = 0; i < OPTIONS_FONTCOUNT; i++) Log_Append(buffer, bufferEnd, bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(chatApi.aFonts[i].color), GetGValue(chatApi.aFonts[i].color), GetBValue(chatApi.aFonts[i].color)); for (i = 0; i < mi->nColorCount; i++) Log_Append(buffer, bufferEnd, bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(mi->crColors[i]), GetGValue(mi->crColors[i]), GetBValue(mi->crColors[i])); // new paragraph Log_Append(buffer, bufferEnd, bufferAlloced, "}\\pard"); // set tabs and indents int iIndent = 0; if (g_Settings->dwIconFlags) { iIndent += (14 * 1440) / chatApi.logPixelSX; Log_Append(buffer, bufferEnd, bufferAlloced, "\\tx%u", iIndent); } if (g_Settings->bShowTime) { int iSize = (g_Settings->LogTextIndent * 1440) / chatApi.logPixelSX; Log_Append(buffer, bufferEnd, bufferAlloced, "\\tx%u", iIndent + iSize); if (g_Settings->bLogIndentEnabled) iIndent += iSize; } Log_Append(buffer, bufferEnd, bufferAlloced, "\\fi-%u\\li%u", iIndent, iIndent); return buffer; }
//----------------------------------------------------------------------------- // Purpose: // Input : *pDC - // bounds - //----------------------------------------------------------------------------- void Box3D::RenderTool2D(CRender2D *pRender) { Vector mins = bmins; Vector maxs = bmaxs; CMapView2D *pView = (CMapView2D*)pRender->GetView(); Assert( pRender ); if ( IsTranslating() ) { TranslateBox( mins, maxs ); } else if ( IsEmpty() ) { return; } if ( m_dwDrawFlags & boundstext) { DrawBoundsText(pRender, mins, maxs, DBT_TOP | DBT_LEFT); } if ( IsTranslating() ) { pRender->PushRenderMode( RENDER_MODE_DOTTED ); pRender->SetDrawColor( GetRValue(Options.colors.clrToolDrag), GetGValue(Options.colors.clrToolDrag), GetBValue(Options.colors.clrToolDrag) ); } else if (!(m_dwDrawFlags & thicklines)) { pRender->PushRenderMode( RENDER_MODE_DOTTED ); pRender->SetDrawColor( GetRValue(m_clrBox), GetGValue(m_clrBox), GetBValue(m_clrBox) ); } else { pRender->PushRenderMode( RENDER_MODE_FLAT_NOZ ); pRender->SetDrawColor( GetRValue(m_clrBox), GetGValue(m_clrBox), GetBValue(m_clrBox) ); } // render bounds if ( !IsTranslating() || m_TranslateMode == modeScale || m_TranslateMode == modeMove ) { // draw simple rectangle pRender->DrawRectangle( mins, maxs, false, 0 ); } else { // during rotation or shearing, draw transformed bounding box Vector v[4]; // init all points to center v[0] = v[1] = v[2] = v[3] = (bmins+bmaxs) / 2; int axis = pView->axHorz; v[0][axis] = v[1][axis] = bmins[axis]; v[2][axis] = v[3][axis] = bmaxs[axis]; axis = pView->axVert; v[1][axis] = v[2][axis] = bmins[axis]; v[0][axis] = v[3][axis] = bmaxs[axis]; for ( int i=0; i<4; i++) { TranslatePoint( v[i] ); } pRender->DrawLine( v[0], v[1] ); pRender->DrawLine( v[1], v[2] ); pRender->DrawLine( v[2], v[3] ); pRender->DrawLine( v[3], v[0] ); } pRender->PopRenderMode(); // draw a cross for translation origin in move or rotation mode if ( IsTranslating() ) { if ( m_TranslateMode == modeMove || m_TranslateMode == modeRotate ) { Vector vec = m_vTranslationFixPoint; if ( m_TranslateMode == modeMove ) { TranslatePoint( vec ); } // draw 'X' pRender->SetHandleStyle( 7, CRender::HANDLE_CROSS ); pRender->SetHandleColor( GetRValue(Options.colors.clrToolDrag), GetGValue(Options.colors.clrToolDrag), GetBValue(Options.colors.clrToolDrag) ); pRender->DrawHandle( vec ); } } else if ( m_bEnableHandles ) { RenderHandles2D( pRender, mins, maxs ); } }
void CPolyDlg::OnEnterKey( UINT ctlID ) { CString csMsg, csEditstr, csItemNum, newitmstr ; int itemnum ; CComboBox& combo = m_Combo_Corner ; //convenience //Get editbox string CWnd* pWnd = (combo.GetWindow(GW_CHILD)) ; CWnd* pEditWnd = (pWnd->GetNextWindow()); //pointer to editbox window pEditWnd->GetWindowText( csEditstr ); csEditstr.TrimLeft() ; csEditstr.TrimRight() ; int numtokens = GetNumTokens( csEditstr ) ; int numitems = combo.GetCount() ; //check for too few or too many tokens in the entry string if( numtokens < 2 ) { csMsg = "Each entry must have at least X & Y positions " ; AfxMessageBox( csMsg + "\n" + csEditstr ) ; return ; } else if( numtokens > 7 ) { csMsg = "Each line can have no more than seven items" ; AfxMessageBox( csMsg + "\n" + csEditstr ) ; return ; } //OK, 2 or 3 tokens: get valid X/Y pos Vector3D vcrnr = GetCnrVector( csEditstr ) ; //3 tokens are considered to be [X Position] [Y Position] [Z Position] if( numtokens == 3 ) { //prepend item num & add to end itemnum = numitems + 1 ; FormatNumStr( csItemNum, itemnum ) ; newitmstr.Format( m_csCoordFmtStr, vcrnr.x, vcrnr.y, vcrnr.z, 0, 0, 0 ) ; csEditstr = csItemNum + newitmstr ; combo.AddString( csEditstr ) ; itemnum = GetItemNum( csEditstr ) ; } // 6 tokens are assumed to be [X Position] [Y Position] [Z Position] [R] [G] [B] else if( numtokens == 6 ) { COLORREF col = GetCnrColor( csEditstr ) ; int R = GetRValue( col ) ; int G = GetGValue( col ) ; int B = GetBValue( col ) ; //prepend item num & add to end itemnum = numitems + 1 ; FormatNumStr( csItemNum, itemnum ) ; newitmstr.Format( m_csCoordFmtStr, vcrnr.x, vcrnr.y, vcrnr.z, R, G, B ) ; csEditstr = csItemNum + newitmstr ; combo.AddString( csEditstr ) ; itemnum = GetItemNum( csEditstr ) ; } //otherwise we assume [Item #] [X Position] [Y Position] [Z Position] [R] [G] [B] else { itemnum = GetItemNum( csEditstr ) ; COLORREF col = GetCnrColor( csEditstr ) ; int R = GetRValue( col ) ; int G = GetGValue( col ) ; int B = GetBValue( col ) ; //insert at item number or add to end if( itemnum > numitems ) { //prepend correct item num & add to end itemnum = numitems + 1 ; FormatNumStr( csItemNum, itemnum ) ; newitmstr.Format( m_csCoordFmtStr, vcrnr.x, vcrnr.y, vcrnr.z, R, G, B ) ; csEditstr = csItemNum + newitmstr ; combo.AddString( csEditstr ) ; } else if( itemnum < numitems ) { combo.DeleteString( itemnum - 1 ) ; FormatNumStr( csItemNum, itemnum ) ; newitmstr.Format( m_csCoordFmtStr, vcrnr.x, vcrnr.y, vcrnr.z, R, G, B ) ; csEditstr = csItemNum + newitmstr ; combo.InsertString( itemnum - 1, csEditstr ) ; } else //itemnum points to last string { combo.DeleteString( itemnum - 1 ) ; FormatNumStr( csItemNum, itemnum ) ; newitmstr.Format( m_csCoordFmtStr, vcrnr.x, vcrnr.y, vcrnr.z, R, G, B ) ; csEditstr = csItemNum + newitmstr ; combo.AddString( csEditstr ) ; } } //leave this item selected combo.SetCurSel( itemnum - 1 ) ; UpdateControls() ; //added 07/10/03 }
// This function extracts the hue, saturation, and luminance from "color" // and places these values in h, s, and l respectively. void RGBtoHSL(unsigned int color,unsigned int& h, unsigned int& s, unsigned int& l) { unsigned int r = (unsigned int)GetRValue(color); unsigned int g = (unsigned int)GetGValue(color); unsigned int b = (unsigned int)GetBValue(color); float r_percent = ((float)r)/255; float g_percent = ((float)g)/255; float b_percent = ((float)b)/255; float max_color = 0; if((r_percent >= g_percent) && (r_percent >= b_percent)) { max_color = r_percent; } if((g_percent >= r_percent) && (g_percent >= b_percent)) max_color = g_percent; if((b_percent >= r_percent) && (b_percent >= g_percent)) max_color = b_percent; float min_color = 0; if((r_percent <= g_percent) && (r_percent <= b_percent)) min_color = r_percent; if((g_percent <= r_percent) && (g_percent <= b_percent)) min_color = g_percent; if((b_percent <= r_percent) && (b_percent <= g_percent)) min_color = b_percent; float L = 0; float S = 0; float H = 0; L = (max_color + min_color)/2; if(max_color == min_color) { S = 0; H = 0; } else { if(L < .50) { S = (max_color - min_color)/(max_color + min_color); } else { S = (max_color - min_color)/(2 - max_color - min_color); } if(max_color == r_percent) { H = (g_percent - b_percent)/(max_color - min_color); } if(max_color == g_percent) { H = 2 + (b_percent - r_percent)/(max_color - min_color); } if(max_color == b_percent) { H = 4 + (r_percent - g_percent)/(max_color - min_color); } } s = (unsigned int)(S*100); l = (unsigned int)(L*100); H = H*60; if(H < 0) H += 360; h = (unsigned int)H; }
void CChangeBackgroudWnd::Notify(TNotifyUI& msg) { if (msg.sType == _T("click")) { if (msg.pSender == m_pOptSwitch) { if ( m_pOptSwitch->IsSelected()) { m_pSlider->SetVisible(false); } else { m_pSlider->SetVisible(true); } } if (msg.pSender == m_PaintManager.FindControl(_T("bnt_bgimage"))) { m_pTab->SelectItem(0); } else if (msg.pSender == m_PaintManager.FindControl(_T("btn_color"))) { m_pTab->SelectItem(1); } else if (_tcsstr(msg.pSender->GetName(), _T("colour_")) != 0) { CSliderUI* AdjustColorSliderR = static_cast<CSliderUI*>(m_PaintManager.FindControl(kAdjustColorSliderRControlName)); CSliderUI* AdjustColorSliderG = static_cast<CSliderUI*>(m_PaintManager.FindControl(kAdjustColorSliderGControlName)); CSliderUI* AdjustColorSliderB = static_cast<CSliderUI*>(m_PaintManager.FindControl(kAdjustColorSliderBControlName)); if ((AdjustColorSliderR != NULL) && (AdjustColorSliderG != NULL) && (AdjustColorSliderB != NULL)) { DWORD dwColor = msg.pSender->GetBkColor(); AdjustColorSliderR->SetValue(static_cast<BYTE>(GetRValue(dwColor))); AdjustColorSliderG->SetValue(static_cast<BYTE>(GetGValue(dwColor))); AdjustColorSliderB->SetValue(static_cast<BYTE>(GetBValue(dwColor))); static_cast<CPlayerWnd*>(m_pParent)->SetBkColor(dwColor); } } } else if (msg.sType == _T("valuechanged")) { CSliderUI* AdjustColorSliderR = static_cast<CSliderUI*>(m_PaintManager.FindControl(kAdjustColorSliderRControlName)); CSliderUI* AdjustColorSliderG = static_cast<CSliderUI*>(m_PaintManager.FindControl(kAdjustColorSliderGControlName)); CSliderUI* AdjustColorSliderB = static_cast<CSliderUI*>(m_PaintManager.FindControl(kAdjustColorSliderBControlName)); if ((AdjustColorSliderR != NULL) && (AdjustColorSliderG != NULL) && (AdjustColorSliderB != NULL)) { BYTE red = AdjustColorSliderR->GetValue(); BYTE green = AdjustColorSliderG->GetValue(); BYTE blue = AdjustColorSliderB->GetValue(); COLORREF crColor = RGB(red, green, blue); TCHAR szBuf[MAX_PATH] = {0}; #if defined(UNDER_CE) _stprintf(szBuf, _T("FF%02X%02X%02X"), GetRValue(crColor), GetGValue(crColor), GetBValue(crColor)); #else _stprintf_s(szBuf, MAX_PATH - 1, _T("FF%02X%02X%02X"), GetRValue(crColor), GetGValue(crColor), GetBValue(crColor)); #endif LPTSTR pstr = NULL; DWORD dwColor = _tcstoul(szBuf, &pstr, 16); m_pParent->SetBkColor(dwColor); } } }
void CSliderCtrlEx::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult) { int loopMax = colorList.GetSize(); // number of color ranges to process LPNMCUSTOMDRAW lpCustDraw = (LPNMCUSTOMDRAW)pNMHDR; //////////////////////////////////////////////////////////////////////////////// // OnCustomDraw() is called at many different stages during the painting process // of the control. We only care about the PREPAINT state or the ITEMPREPAINT // state and not always then. // // If we want to be notified about subcontrol painting, we have to say so when // we get the initial PREPAINT message. //////////////////////////////////////////////////////////////////////////////// if(lpCustDraw->dwDrawStage == CDDS_PREPAINT) { // should we report slider's position? int curVal = GetPos(); if((m_Callback != NULL) && (curVal != m_oldPosition)) { m_oldPosition = curVal; m_Callback(m_p2Object, m_data1, curVal, m_IsDragging); } // If we don't have any special coloring to do, skip all the silliness... if(loopMax <= 0) { *pResult = CDRF_DODEFAULT; } else { // We want to be informed when each part of the control is being // processed so we can intercept the channel drawing. *pResult = CDRF_NOTIFYITEMDRAW; // send messages for each piece-part } return; } /////////////////////////////////////////////////////////////////////////////// // A slider (track control) is drawn in several steps: // 1. Erase // 2. Tics // 3. Channel // 4. Thumb // // It would be nice to capture when the background has been painted and // before the other sub-pieces have been painted. Then we could just // substitute our own painting routine. But this doesn't seem to be // available. // // So this routine captures the tics by inserting operations before // painting the thumb. // // Look at the help on NMCUSTOMDRAW for complete details, but the pNMHDR // pointer looks at a structure like: // // typedef struct tagNMCUSTOMDRAWINFO { // NMHDR hdr; // DWORD dwDrawStage; // This indicates what stage of the drawing process is involved // HDC hdc; // graphics context of the control (or sub-component) // RECT rc; // DWORD dwItemSpec; // This is the particular piece-part of the slider involved // UINT uItemState; // LPARAM lItemlParam; // } NMCUSTOMDRAW // // The stages include CDDS_PREPAINT, which is just before painting of the entire // control. However, unless the *pResult parameter is set to CDRF_NOTIFYITEMDRAW, // we will get notification for the control as a whole, not for each piece-part. // So the first thing to do is set *pResult. Thereafter, we must intercept // the sub-parts. // // We don't care about painting the background (we will re-paint later on). We // don't care about PREPAINT on the CHANNEL or the TICS since we will overwrite // everything when we get to the THUMB. ///////////////////////////////////////////////////////////////////////////////// if((lpCustDraw->dwDrawStage == CDDS_ITEMPREPAINT) && (lpCustDraw->dwItemSpec != TBCD_THUMB)) { *pResult = CDRF_DODEFAULT; return; } // get channel orientation BOOL IsVertical = (TBS_VERT & GetStyle()) ? TRUE : FALSE; // Get the coordinates of the control's window CRect crect; GetClientRect(crect); // client coordinates (top = left = 0, bottom = height, right = width) // Much of this is "paraphrased" from Nic Wilson's work -- see the header file ////////////////////////////////////////////////////////////////////////////////// // This bit does the tics marks transparently. // Create a memory dc to hold a copy of the oldbitmap data that includes the tics, // because when we add the background in we will lose the tic marks. /////////////////////////////////////////////////////////////////////////////////// CDC *pDC = CDC::FromHandle(lpCustDraw->hdc); CDC SaveCDC; CBitmap SaveCBmp; //set the colours for the monochrome mask bitmap COLORREF crOldBack = pDC->SetBkColor(RGB(0,0,0)); // set to Black COLORREF crOldText = pDC->SetTextColor(RGB(255,255,255)); // set to White int iWidth = crect.Width(); // channel width int iHeight = crect.Height(); // channel height //////////////////////////////////////////////////////////////////////////// // Create an in-memory copy of displayed bitmap, including the tics. // This is a monochrome bitmap since it was created from a memory DC. // If it had been created from pDC (an actual device DC, not a memory // DC) then this would be something with 8, 16, 24, or 32 bits per pixel. // // This will have a black background, with the tic marks in white. // // For reasons I don't yet understand, this saves only the tic marks and // the channel's centerline (both originally in black), and not the other // colors (such as drawn AROUND the channel's centerline). I am not sure // what would have happened if the tic marks were not black... //////////////////////////////////////////////////////////////////////////// SaveCDC.CreateCompatibleDC(pDC); SaveCBmp.CreateCompatibleBitmap(&SaveCDC, iWidth, iHeight); CBitmap* SaveCBmpOld = (CBitmap *)SaveCDC.SelectObject(SaveCBmp); SaveCDC.BitBlt(0, 0, iWidth, iHeight, pDC, crect.left, crect.top, SRCCOPY); if(m_dumpBitmaps) // debugging stuff { SaveBitmap("MonoTicsMask.bmp",SaveCBmp); } // Do as much of this stuff in memory as possible, then blit it to the screen CDC memDC; memDC.CreateCompatibleDC(pDC); CBitmap memBM; memBM.CreateCompatibleBitmap(pDC,iWidth,iHeight); // create from pDC, not memDC CBitmap *oldbm = memDC.SelectObject(&memBM); //////////////////////////////////////////////////////////////////////////////// // copy screen bitmap to memory bitmap for manipulation. If this is the very // first time the control has been updated, the screen bitmap will show only // the tic marks (in black) and the default background color (RGB(214,207,189)). // If the control has been updated before, remnants of the previously drawn // background color ranges will also show up. //////////////////////////////////////////////////////////////////////////////// memDC.BitBlt(0,0,iWidth,iHeight,pDC,0,0,SRCCOPY); if(m_dumpBitmaps) // debugging { SaveBitmap("ScrnStart.bmp",memBM); } ///////////////////////////////////////////////////////////////////////////// // Color parts of the channel if necessary. It SHOULD be necessary since we // don't get notifications unless there are colors to print, but we may have // a race condition and it is best to check. ///////////////////////////////////////////////////////////////////////////// if(loopMax) { ///////////////////////////////////////////////////////////////////////////////// // We need to draw colors over the subrange of the channel that the center of the // thumb traverses, rather than the entire client window. Later on, extend these // colors outwards to the ends of the client window (for nicer appearance). This // allows for more precise correlation with color and thumb position. ///////////////////////////////////////////////////////////////////////////////// CRect chanRect; GetChannelRect(&chanRect); CRect thmbRect; GetThumbRect(&thmbRect); // For unknown reasons, GetChannelRect() returns a rectangle // as though it were a horizonally oriented slider, even if it isn't! if(IsVertical) { CRect n; // could probably just change chanRect directly n.left = chanRect.top; n.right = chanRect.bottom; n.top = chanRect.left; n.bottom = chanRect.right; n.NormalizeRect(); chanRect.CopyRect(&n); } // Offset into client rectangle for beginning of coloring range int Offset = chanRect.left + thmbRect.Width()/2; if(IsVertical) { Offset = chanRect.top + thmbRect.Height()/2; } // Range for center of thumb on the channel int ht = chanRect.Height() - thmbRect.Height(); int wd = chanRect.Width() - thmbRect.Width(); // scaling between control range and bitmap int min,max; GetRange(min,max); // range of values for the slider double scale = (double(max) - double(min))/double(IsVertical ? ht : wd); BOOL gotStartColor = FALSE; BOOL gotEndColor = FALSE; COLORREF startColor = 0, endColor = 0; int loop; // Loop through the array of color ranges for(loop = 0; loop < loopMax; loop++) { clrRange clr; clr = colorList[loop]; // Get the good values. If not set, then entire range is good int lval = clr.lval; int hval = clr.hval; if((lval < min) || (lval > max)) lval = min; if((hval > max) || (hval < min)) hval = max; if(lval == min) { gotStartColor = TRUE; startColor = clr.strColor; } if(hval == max) { gotEndColor = TRUE; endColor = clr.endColor; } int minVal = lval - min; // offset into bitmap for this color minVal = int(double(minVal)/scale); // width (or height for vertical slider) inside bitmap for this color int widthVal = hval - lval; widthVal = int((double(widthVal)/scale) + 1.0); // For drawing a gradient, we need to know the individual RGB values int sR,eR,sG,eG,sB,eB; // start and end R, G, and B values sR = GetRValue(clr.strColor); eR = GetRValue(clr.endColor); sG = GetGValue(clr.strColor); eG = GetGValue(clr.endColor); sB = GetBValue(clr.strColor); eB = GetBValue(clr.endColor); if(GradientFill != NULL) { TRIVERTEX vert[2]; // for specifying range to gradient fill GRADIENT_RECT gRect; // Warning C4244: conversion from 'int' to 'unsigned short', possible loss of data #pragma warning (push) #pragma warning (disable : 4244) vert[0].Red = sR<<8; // expects 16-bit color values! vert[0].Green = sG<<8; vert[0].Blue = sB<<8; vert[0].Alpha = 0; // no fading/transparency vert[1].Red = eR<<8; vert[1].Green = eG<<8; vert[1].Blue = eB<<8; vert[1].Alpha = 0; #pragma warning (pop) gRect.UpperLeft = 0; gRect.LowerRight = 1; BOOL retval; if(IsVertical) // vertically oriented? { vert[0].x = 0; vert[0].y = Offset + minVal; vert[1].x = iWidth; vert[1].y = Offset + minVal + widthVal; retval = GradientFill(memDC,vert,2,&gRect,1,GRADIENT_FILL_RECT_V); } else { vert[0].x = Offset + minVal; vert[0].y = 0; vert[1].x = Offset + minVal + widthVal; vert[1].y = iHeight; retval = GradientFill(memDC,vert,2,&gRect,1,GRADIENT_FILL_RECT_H); } } else { // Homebrew version of GradientFill for rectangles -- works pretty well, sort of. int i; for(i = 0; i < widthVal; i++) // for each pixel column in bitmap color range { int R = sR; int G = sG; int B = sB; if(widthVal) { R += ::MulDiv(eR - sR, i, widthVal); G += ::MulDiv(eG - sG, i, widthVal); B += ::MulDiv(eB - sB, i, widthVal); } if(IsVertical) { // widthVal really refers to height //memDC.FillSolidRect(0,minVal+i,iWidth,widthVal-i,GetNearestColor(memDC,RGB(R,G,B))); memDC.FillSolidRect( 0, // starting X value Offset + minVal + i, // starting Y value iWidth, // full width 1, // one pixel height GetNearestColor(memDC,RGB(R,G,B))); } else { //memDC.FillSolidRect(minVal+i,0,widthVal-i,iHeight,GetNearestColor(memDC,RGB(R,G,B))); memDC.FillSolidRect( Offset + minVal + i, // Starting X value 0, // Starting Y value 1, // 1 pixel wide iHeight, // full height GetNearestColor(memDC,RGB(R,G,B))); } } } } if(m_extendColors) { // If we have put in colors at the slider ends, then extend those same // colors to the rest of the background. We could try to determine the // colors by examining the bitmap, but this is awkward and it is just // as easy to grab them on-the-fly in the coloring loop above. // // If you want to see why this is done, just set m_extendColors to FALSE // and take a look at the control. Ugly. But there might be a legitimate // reason for it so leave the option to suppress. if(IsVertical) { if(gotStartColor) { memDC.FillSolidRect(0, 0, iWidth, Offset, startColor); } if(gotEndColor) { memDC.FillSolidRect(0, iHeight - Offset - 1, iWidth, Offset, endColor); } } else { if(gotStartColor) { memDC.FillSolidRect(0, 0, Offset, iHeight, startColor); } if(gotEndColor) { memDC.FillSolidRect(iWidth - Offset - 1, 0, Offset, iHeight, endColor); } } } } // The screen bitmap should now have only the color ranges filled in, no tic // marks should be visible. if(m_dumpBitmaps) // debugging { SaveBitmap("ScrnColors.bmp",memBM); } ////////////////////////////////////////////////////////////// // More "paraphrasing" from Nic Wilson's work... ////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// // At this point, memDC's bitmap contains just the color ranges drawn above. // No tic marks are visible. Doing SRCINVERT with the mask will draw in the // tic marks, but all the colors will be backwards. Also, the tics will be // whatever color was drawn in the color range stuff, rather than solid, // normal tic marks. SRCINVERT means the RGB values are changed by subtracting // from 255: // // RGB(255,0,0) --> RGB(0,255,255) // RGB(247,8,0) --> RGB(8,247,255) // RGB(214,40,255) --> RGB(41,215,0) // ///////////////////////////////////////////////////////////////////////////// memDC.SetBkColor(pDC->GetBkColor()); memDC.SetTextColor(pDC->GetTextColor()); memDC.BitBlt(0, 0, iWidth, iHeight, &SaveCDC, 0, 0, SRCINVERT); if(m_dumpBitmaps) // debugging { SaveBitmap("ScrnInvert.bmp",memBM); } // Change the tic marks from the color range to the background color. This // changes only the tic marks (and the channel centerline) and leaves the // rest alone. The tic marks wind up black. memDC.BitBlt(0, 0, iWidth, iHeight, &SaveCDC, 0, 0, SRCAND); if(m_dumpBitmaps) // debugging { SaveBitmap("ScrnAnd.bmp",memBM); } // Finally, invert the color ranges to their normal values. Since the tic // marks in the SaveCDC bitmap are white, they get inverted to black. memDC.BitBlt(0, 0, iWidth, iHeight, &SaveCDC, 0, 0, SRCINVERT); if(m_dumpBitmaps) // debugging { SaveBitmap("ScrnFinal.bmp",memBM); } // Now copy out to screen pDC->BitBlt(0,0,iWidth,iHeight,&memDC,0,0,SRCCOPY); // restore and clean up pDC->SetBkColor(crOldBack); pDC->SetTextColor(crOldText); DeleteObject(SelectObject(SaveCDC, SaveCBmpOld)); DeleteDC(SaveCDC); DeleteObject(SelectObject(memDC,oldbm)); DeleteDC(memDC); *pResult = CDRF_DODEFAULT; m_dumpBitmaps = FALSE; // only do this once! }
// draw the item bool wxOwnerDrawn::OnDrawItem( wxDC& rDC , const wxRect& rRect , wxODAction eAction , wxODStatus eStatus ) { // // We do nothing on focus change // if (eAction == wxODFocusChanged ) return TRUE; // // Select the font and draw the text // --------------------------------- // CHARBUNDLE vCbnd; HPS hPS= rDC.GetHPS(); wxColour vColBack; wxColour vColText; COLORREF vRef; RECTL vRect = {rRect.x + 4, rRect.y + 1, rRect.x + (rRect.width - 2), rRect.y + rRect.height}; memset(&vCbnd, 0, sizeof(CHARBUNDLE)); // // Use default font if no font set // if (m_font.Ok()) { m_font.RealizeResource(); } else { ::GpiSetCharSet(hPS, LCID_DEFAULT); } // // Based on the status of the menu item, pick the right colors // if (eStatus & wxODSelected) { wxColour vCol2(wxT("WHITE")); vColBack.Set( (unsigned char)0 ,(unsigned char)0 ,(unsigned char)160 ); // no dark blue in color table vColText = vCol2; } else if (eStatus & wxODDisabled) { vRef = (ULONG)::WinQuerySysColor( HWND_DESKTOP ,SYSCLR_MENU // Light gray ,0L ); vColBack.Set( GetRValue(vRef) ,GetGValue(vRef) ,GetBValue(vRef) ); vRef = (ULONG)::WinQuerySysColor( HWND_DESKTOP ,SYSCLR_MENUDISABLEDTEXT // dark gray ,0L ); vColText.Set( GetRValue(vRef) ,GetGValue(vRef) ,GetBValue(vRef) ); } else { // // Fall back to default colors if none explicitly specified // vRef = ::WinQuerySysColor( HWND_DESKTOP ,SYSCLR_MENU // we are using gray for all our window backgrounds in wxWidgets ,0L ); vColBack.Set( GetRValue(vRef) ,GetGValue(vRef) ,GetBValue(vRef) ); vRef = ::WinQuerySysColor( HWND_DESKTOP ,SYSCLR_WINDOWTEXT // Black ,0L ); vColText.Set( GetRValue(vRef) ,GetGValue(vRef) ,GetBValue(vRef) ); } rDC.SetTextBackground(vColBack); rDC.SetTextForeground(vColText); rDC.SetBackgroundMode(wxTRANSPARENT); vCbnd.lColor = vColText.GetPixel(); vCbnd.lBackColor = vColBack.GetPixel(); ::GpiSetAttrs( hPS ,PRIM_CHAR ,CBB_BACK_COLOR | CBB_COLOR ,0 ,&vCbnd ); ::GpiSetBackMix( hPS ,BM_LEAVEALONE ); // // Paint the background // ::WinFillRect(hPS, &vRect, vColBack.GetPixel()); // // Determine where to draw and leave space for a check-mark. // int nX = rRect.x + GetMarginWidth(); // // Unfortunately, unlike Win32, PM has no owner drawn specific text // drawing methods like ::DrawState that can cleanly handle accel // mnemonics and deal, automatically, with various states, so we have // to handle them ourselves. Notice Win32 can't handle \t in ownerdrawn // strings either. We cannot handle mnemonics either. We display // them, though, in the hope we can figure them out some day. // // // Display main text and accel text separately to align better // wxString sTgt = wxT("\t"); wxString sFullString = m_strName; // need to save the original text wxString sAccel; int nIndex; size_t nWidth; size_t nCharWidth; size_t nHeight; bool bFoundMnemonic = FALSE; bool bFoundAccel = FALSE; // // Deal with the tab, extracting the Accel text // nIndex = sFullString.Find(sTgt.c_str()); if (nIndex != -1) { bFoundAccel = TRUE; sAccel = sFullString.Mid(nIndex + 1); sFullString.Remove(nIndex); } // // Deal with the mnemonic character // sTgt = wxT("~"); nIndex = sFullString.Find(sTgt.c_str()); if (nIndex != -1) { wxString sTmp = sFullString; bFoundMnemonic = TRUE; sTmp.Remove(nIndex); rDC.GetTextExtent( sTmp ,(long *)&nWidth ,(long *)&nHeight ); sTmp = sFullString[(size_t)(nIndex + 1)]; rDC.GetTextExtent( sTmp ,(long *)&nCharWidth ,(long *)&nHeight ); sFullString.Replace(sTgt.c_str(), wxEmptyString, TRUE); } // // Draw the main item text sans the accel text // POINTL vPntStart = {nX, rRect.y + 4}; ::GpiCharStringAt( rDC.GetHPS() ,&vPntStart ,sFullString.length() ,(PCH)sFullString.c_str() ); if (bFoundMnemonic) { // // Underline the mnemonic -- still won't work, but at least it "looks" right // wxPen vPen; POINTL vPntEnd = {nX + nWidth + nCharWidth - 3, rRect.y + 2}; //CharWidth is bit wide vPntStart.x = nX + nWidth - 1; vPntStart.y = rRect.y + 2; // Make it look pretty! vPen = wxPen(vColText, 1, wxSOLID); // Assuming we are always black rDC.SetPen(vPen); ::GpiMove(hPS, &vPntStart); ::GpiLine(hPS, &vPntEnd); } // // Now draw the accel text // if (bFoundAccel) { size_t nWidth; size_t nHeight; rDC.GetTextExtent( sAccel ,(long *)&nWidth ,(long *)&nHeight ); // // Back off the starting position from the right edge // vPntStart.x = rRect.width - (nWidth + 7); vPntStart.y = rRect.y + 4; ::GpiCharStringAt( rDC.GetHPS() ,&vPntStart ,sAccel.length() ,(PCH)sAccel.c_str() ); } // // Draw the bitmap // --------------- // if (IsCheckable() && !m_bmpChecked.Ok()) { if (eStatus & wxODChecked) { RECTL vRect; HBITMAP hBmpCheck = ::WinGetSysBitmap(HWND_DESKTOP, SBMP_MENUCHECK); vRect.xLeft = rRect.x; vRect.xRight = rRect.x + GetMarginWidth(); vRect.yBottom = rRect.y; vRect.yTop = rRect.y + m_nHeight - 3; ::WinDrawBitmap( hPS // PS for this menuitem ,hBmpCheck // system checkmark ,NULL // draw the whole bitmap ,(PPOINTL)&vRect // destination -- bottom left corner of the menuitem area ,0L // ignored ,0L // draw a bitmap ,DBM_NORMAL // draw normal size ); } } else { // // For uncheckable item we use only the 'checked' bitmap // wxBitmap vBmp(GetBitmap(IsCheckable() ? ((eStatus & wxODChecked) != 0) : TRUE)); if (vBmp.Ok()) { wxMemoryDC vDCMem(&rDC); wxMemoryDC* pOldDC = (wxMemoryDC*)vBmp.GetSelectedInto(); if(pOldDC != NULL) { vBmp.SetSelectedInto(NULL); } vDCMem.SelectObject(vBmp); // // Center bitmap // int nBmpWidth = vBmp.GetWidth(); int nBmpHeight = vBmp.GetHeight(); // // There should be enough space! // wxASSERT((nBmpWidth <= rRect.width) && (nBmpHeight <= rRect.height)); int nHeightDiff = m_nHeight - nBmpHeight; rDC.Blit( rRect.x + (GetMarginWidth() - nBmpWidth) / 2 ,rRect.y + nHeightDiff / 2 ,nBmpWidth ,nBmpHeight ,&vDCMem ,0 ,0 ,wxCOPY ,TRUE ); if (eStatus & wxODSelected) { POINTL vPnt1 = {rRect.x + 1, rRect.y + 3}; // Leave a little background border POINTL vPnt2 = {rRect.x + GetMarginWidth(), rRect.y + m_nHeight - 3}; LINEBUNDLE vLine; vLine.lColor = vColBack.GetPixel(); ::GpiSetAttrs( hPS ,PRIM_LINE ,LBB_COLOR ,0 ,&vLine ); ::GpiMove(hPS, &vPnt1); ::GpiBox( hPS ,DRO_OUTLINE ,&vPnt2 ,0L ,0L ); } vBmp.SetSelectedInto(NULL); } } return TRUE; } // end of wxOwnerDrawn::OnDrawItem
Color RenderThemeWinCE::platformInactiveSelectionBackgroundColor() const { COLORREF color = GetSysColor(COLOR_GRAYTEXT); return Color(GetRValue(color), GetGValue(color), GetBValue(color), 255); }
Color RenderThemeWinCE::platformActiveSelectionForegroundColor() const { COLORREF color = GetSysColor(COLOR_HIGHLIGHTTEXT); return Color(GetRValue(color), GetGValue(color), GetBValue(color), 255); }
// Draw the tiles // void CTileCastleFlag::Draw( CDC* pDC, int x, int y, int x2, int x3, int y2, int y3, int y4, int DrawingLevel) { // Compute polyline around tiles POINT Points1[4]; int NbPoint1 = 4; int TilePos = 0; double LowColor = GetLowColor( DrawingLevel ); Points1[0].x=x+x2; Points1[0].y=y-y2; Points1[1].x=x+x3; Points1[1].y=y; Points1[2].x=(int) (x+x3-x2/4.0); Points1[2].y=(int) (y+y2/4.0); Points1[3].x=x+x2; Points1[3].y=(int) (y-y2/2.0); double cosa; double sina; switch( m_CurrentRotation ) { case 0: break; case 1: cosa = cos(60/180.0*PI); sina = sin(60/180.0*PI); break; case 2: cosa = cos(120/180.0*PI); sina = sin(120/180.0*PI); break; case 3: cosa = cos(180/180.0*PI); sina = sin(180/180.0*PI); break; case 4: cosa = cos(240/180.0*PI); sina = sin(240/180.0*PI); break; case 5: cosa = cos(300/180.0*PI); sina = sin(300/180.0*PI); break; } if( m_CurrentRotation!=0 ) { for( int i=0; i<NbPoint1; i++ ) { double x1,y1; x1 = cosa*(Points1[i].x-x-x2)-sina*(Points1[i].y-y-(y3-y2)/2.0); y1 = sina*(Points1[i].x-x-x2)+cosa*(Points1[i].y-y-(y3-y2)/2.0); Points1[i].x = (int) (x+x2+x1); Points1[i].y = (int) (y+(y3-y2)/2.0+y1); } } CPen Pen; Pen.CreatePen(PS_NULL,0,RGB(0,0,0)); CPen* pOldPen = pDC->SelectObject( &Pen ); CBrush Brush; if( m_IsSelected ) Brush.CreateSolidBrush( RGB(255,255*LowColor,255*LowColor) ); else Brush.CreateSolidBrush( RGB(min(255,GetRValue(m_TileColor)+(255-GetRValue(m_TileColor))*LowColor),min(255,GetGValue(m_TileColor)+(255-GetGValue(m_TileColor))*LowColor),min(255,GetBValue(m_TileColor)+(255-GetBValue(m_TileColor))*LowColor)) ); CBrush* pOldBrush = pDC->SelectObject( &Brush ); pDC->Polygon( Points1, NbPoint1 ); // Draw points CBrush BlackBrush; BlackBrush.CreateSolidBrush( RGB(min(255,255*LowColor),min(255,255*LowColor),min(255,255*LowColor)) ); pDC->SelectObject( &BlackBrush ); double xe1 = (Points1[3].x+Points1[0].x)*.5; double ye1 = (Points1[3].y+Points1[0].y)*.5; double xe2 = (Points1[2].x+Points1[1].x)*.5; double ye2 = (Points1[2].y+Points1[1].y)*.5; int xe3 = (int) ((xe1+xe2)*.5); int ye3 = (int) ((ye1+ye2)*.5); int diameter = (int) (x2/10.0); pDC->Ellipse( xe3-diameter, ye3-diameter, xe3+diameter, ye3+diameter ); pDC->SelectObject( pOldBrush ); pDC->SelectObject( pOldPen ); DrawExtend( pDC, x, y, x2, x3, y2, y3, y4, DrawingLevel); }
void Renderer::drawCovers(bool showTarget){ #ifdef COVER_ALPHA glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER,0.1f); #endif if (cfgHighlightWidth == 0) showTarget = false; if (appInstance->albumCollection->getCount() == 0) return; float centerOffset = displayPos->getCenteredOffset(); CollectionPos centerCover = displayPos->getCenteredPos(); CollectionPos firstCover = displayPos->getOffsetPos(coverPos.getFirstCover() + 1); CollectionPos lastCover = displayPos->getOffsetPos(coverPos.getLastCover()); lastCover++; // getOffsetPos does not return the end() element CollectionPos targetCover = appInstance->albumCollection->getTargetPos(); int offset = appInstance->albumCollection->rank(firstCover) - appInstance->albumCollection->rank(centerCover); for (CollectionPos p = firstCover; p != lastCover; ++p, ++offset){ float co = -centerOffset + offset; shared_ptr<ImgTexture> tex = texLoader->getLoadedImgTexture(p); tex->glBind(); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // calculate darkening float g = 1-(min(1.0f,(abs(co)-2)/5))*0.5f; if (abs(co) < 2) g = 1; /*float g = 1 - (abs(co)-2)*0.2f; g = 1 - abs(co)*0.1f; g = 1 - abs(zRot)/80; g= 1; if (g < 0) g = 0;*/ glColor3f( g, g, g); glVectord origin(0, 0.5, 0); glQuad coverQuad = coverPos.getCoverQuad(co, tex->getAspect()); glPushName(SELECTION_CENTER + offset); glBegin(GL_QUADS); if (glFogCoordf) glFogCoordf((GLfloat)coverPos.distanceToMirror(coverQuad.topLeft)); glTexCoord2f(0.0f, 1.0f); // top left glVertex3fv((GLfloat*)&(coverQuad.topLeft.x)); if (glFogCoordf) glFogCoordf((GLfloat)coverPos.distanceToMirror(coverQuad.topRight)); glTexCoord2f(1.0f, 1.0f); // top right glVertex3fv((GLfloat*)&(coverQuad.topRight.x)); if (glFogCoordf) glFogCoordf((GLfloat)coverPos.distanceToMirror(coverQuad.bottomRight)); glTexCoord2f(1.0f, 0.0f); // bottom right glVertex3fv((GLfloat*)&(coverQuad.bottomRight.x)); if (glFogCoordf) glFogCoordf((GLfloat)coverPos.distanceToMirror(coverQuad.bottomLeft)); glTexCoord2f(0.0f, 0.0f); // bottom left glVertex3fv((GLfloat*)&(coverQuad.bottomLeft.x)); glEnd(); glPopName(); if (showTarget){ if (p == targetCover){ bool clipPlane = false; if (glIsEnabled(GL_CLIP_PLANE0)){ glDisable(GL_CLIP_PLANE0); clipPlane = true; } showTarget = false; glColor3f(GetRValue(cfgTitleColor) / 255.0f, GetGValue(cfgTitleColor) / 255.0f, GetBValue(cfgTitleColor) / 255.0f); glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); glDisable(GL_TEXTURE_2D); glLineWidth((GLfloat)cfgHighlightWidth); glPolygonOffset(-1.0f, -1.0f); glEnable(GL_POLYGON_OFFSET_LINE); glEnable(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, 0, (void*) &coverQuad); glDrawArrays(GL_QUADS, 0, 4); glDisable(GL_POLYGON_OFFSET_LINE); glEnable(GL_TEXTURE_2D); if (clipPlane) glEnable(GL_CLIP_PLANE0); } } } #ifdef COVER_ALPHA glDisable(GL_BLEND); glDisable(GL_ALPHA_TEST); #endif }
void Renderer::drawBg(){ glClearColor(GetRValue(cfgPanelBg)/255.0f, GetGValue(cfgPanelBg)/255.0f, GetBValue(cfgPanelBg)/255.0f, 0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); }
//*************************************************************** void CMyColorList::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { if (!lpDrawItemStruct) return; CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC); int m=GetHeaderCtrl()->GetItemCount(); for(int i=0;i<m;i++) { CString str; CRect rcItem; GetSubItemRect(lpDrawItemStruct->itemID,i,LVIR_LABEL,rcItem); str=GetItemText(lpDrawItemStruct->itemID,i); CMyColor *col=(CMyColor *)m_ArrayCol.GetAt(lpDrawItemStruct->itemID); pDC->SetBkMode(TRANSPARENT); CBrush brush; brush.CreateSolidBrush(col->colBack); pDC->FillRect(rcItem,&brush); pDC->SetTextColor(col->colText); LV_ITEM lvi; lvi.mask = LVIF_IMAGE | LVIF_STATE; lvi.iItem = lpDrawItemStruct->itemID; lvi.iSubItem = 0; lvi.stateMask = 0xFFFF; // get all state flags GetItem(&lvi); if((lvi.state & LVIS_SELECTED)||(lvi.state & LVIS_FOCUSED)) { if(m_blnSelect) { int r1=GetRValue(col->colSelect); int g1=GetGValue(col->colSelect); int b1=GetBValue(col->colSelect); for(int i=rcItem.Height()/2;i>0;i--) { r1=(r1+5)>255?255:(r1+5); g1=(g1+5)>255?255:(g1+5); b1=(b1+5)>255?255:(b1+5); CPen pen(PS_SOLID, 1, RGB(r1, g1, b1)); CPen *old = pDC->SelectObject(&pen); pDC->MoveTo(rcItem.left,rcItem.top+i); pDC->LineTo(rcItem.right,rcItem.top+i); pDC->MoveTo(rcItem.left,rcItem.bottom-i); pDC->LineTo(rcItem.right,rcItem.bottom-i); pDC->SelectObject(old); } } } int nAlign=atoi(m_ArrayHeaderAlign.GetAt(i)); if(i==0&&GetImageList(LVSIL_SMALL)!=NULL) { CPoint ptImage; ptImage.x=rcItem.left; ptImage.y=rcItem.top; GetImageList(LVSIL_SMALL)->Draw(pDC,lvi.iImage,ptImage,ILD_TRANSPARENT); pDC->SetBkMode(TRANSPARENT); rcItem.left=rcItem.left+16; if(nAlign==LVCFMT_LEFT) rcItem.left=rcItem.left+8; } switch(nAlign) { case LVCFMT_LEFT: pDC->DrawText(str,rcItem,DT_LEFT); break; case LVCFMT_CENTER: pDC->DrawText(str,rcItem,DT_CENTER); break; case LVCFMT_RIGHT: pDC->DrawText(str,rcItem,DT_RIGHT); break; default: pDC->DrawText(str,rcItem,DT_CENTER); break; } } }
RBitmapImage& RWinColorPalette::GetPaletteBitmapImage( ) { static BOOLEAN m_fPaletteInitialized = FALSE; static RBitmapImage m_biPalette; if ( !m_fPaletteInitialized ) { // find the resource in the resource file HRSRC hRsrc = FindResource( AfxGetResourceHandle(), MAKEINTRESOURCE( m_uPaletteBitmapID ), RT_BITMAP ); if ( hRsrc != NULL ) { // get a handle to the resource data HGLOBAL hTemp = LoadResource( AfxGetResourceHandle(), hRsrc ); if ( hTemp != NULL ) { // Initlize the palette bitmap with the resource data m_biPalette.Initialize( LockResource( hTemp ) ); // unlock and free the resource UnlockResource( hTemp ); FreeResource( hTemp ); } else AfxThrowResourceException( ); } else AfxThrowResourceException( ); m_fPaletteInitialized = TRUE; COLORMAP crColorMap[] = { { RGB( 255, 255, 255 ), GetSysColor( COLOR_BTNHIGHLIGHT ) }, { RGB( 192, 192, 192 ), GetSysColor( COLOR_BTNFACE ) }, { RGB( 128, 128, 128 ), GetSysColor( COLOR_BTNSHADOW ) } }; RIntPoint ptCells[] = { FindColor( crColorMap[0].from ), FindColor( crColorMap[1].from ), FindColor( crColorMap[2].from ) }; void* pRawData = m_biPalette.GetRawData(); RGBQUAD* pColorData = (RGBQUAD *) RBitmapImage::GetColorData( pRawData ); LPBYTE pImageData = (LPBYTE) RBitmapImage::GetImageData( pRawData ); for (int j = 0; (LPVOID) pColorData < (LPVOID) pImageData; j++, pColorData++) { for (int i = 0; i < NumElements( crColorMap ); i++) { if (crColorMap[i].from == RGB( pColorData->rgbRed, pColorData->rgbGreen, pColorData->rgbBlue )) { pColorData->rgbBlue = GetBValue( crColorMap[i].to ); pColorData->rgbRed = GetRValue( crColorMap[i].to ); pColorData->rgbGreen = GetGValue( crColorMap[i].to ); pColorData->rgbReserved = 0; } } if (j == 9) { // We only need to look at the system colors, so // jump to the last 10 entries in the palette. pColorData += 235; } } m_biPalette.UpdatePalette(); // // Relace the cells that got remapped // ROffscreenDrawingSurface dsMem; dsMem.SetImage( &m_biPalette ); RSolidColor rSolid; for (int i = 0; i < NumElements( ptCells ); i++) { if (ptCells[i].m_x >= 0 && ptCells[i].m_y >= 0) { RIntRect rcCell( RIntSize( kCellSize.m_dx - 2, kCellSize.m_dy - 2 ) ); rcCell.Offset( RIntSize( ptCells[i].m_x + 1, ptCells[i].m_y + 1 ) ); rSolid = crColorMap[i].from; RColor rColor( rSolid ); dsMem.SetFillColor( rColor ); dsMem.FillRectangle( rcCell ); } } dsMem.ReleaseImage(); } return m_biPalette; }
/****************************************************************************** * 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("(%08lx, %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; }
void COptionTreeItemColor::DrawControl(CDC *pDC, const RECT &rcRect) { // Declare variables HGDIOBJ hOld; HGDIOBJ hOldBrush; COLORREF crOld; int nOldBack; CRect rcText, rcColor, rcClient; CString strText; CBrush bBrush; COLORREF crOldBack; // Get window rect GetClientRect(rcClient); // Select font hOld = pDC->SelectObject(m_otOption->GetNormalFont()); // Create bush bBrush.CreateSolidBrush(m_crColor); // Set text color if (IsReadOnly() == TRUE || m_otOption->IsWindowEnabled() == FALSE) { crOld = pDC->SetTextColor(GetSysColor(COLOR_GRAYTEXT)); } else { crOld = pDC->SetTextColor(GetTextColor()); } // Set background color crOldBack = pDC->SetBkColor(GetBackgroundColor()); // Set background mode nOldBack = pDC->SetBkMode(TRANSPARENT); // Select brush hOldBrush = pDC->SelectObject(GetSysColorBrush(COLOR_BTNSHADOW)); // Get color rectangle rcColor.left = rcRect.left + 1; rcColor.right = rcColor.left + (long) OT_COLOR_SIZE; rcColor.top = rcRect.top + OT_SPACE - 2; rcColor.bottom = rcColor.top + (long) OT_COLOR_SIZE; // Draw color border rcColor.InflateRect(1, 1, 1, 1); pDC->PatBlt(rcColor.left, rcColor.top, rcColor.Width(), rcColor.Height(), PATCOPY); // Draw color rcColor.DeflateRect(1, 1, 1, 1); pDC->FillRect(rcColor, &bBrush); // Get text rectangle rcText.left = rcColor.right + OT_SPACE; rcText.right = rcRect.right; rcText.top = rcRect.top; rcText.bottom = rcRect.bottom; // Get text if (GetOption(OT_COLOR_SHOWHEX) == TRUE) { strText.Format(_T("#%.6X"), m_crColor); } else { strText.Format(_T("RGB (%d, %d, %d)"), GetRValue(m_crColor), GetGValue(m_crColor), GetBValue(m_crColor)); } // Draw text pDC->DrawText(strText, rcText, DT_SINGLELINE | DT_VCENTER); pDC->DrawText(strText, rcText, DT_SINGLELINE | DT_VCENTER | DT_CALCRECT); // Delete brush if (bBrush.GetSafeHandle() != NULL) { bBrush.DeleteObject(); } // Restore GDI ojects pDC->SelectObject(hOldBrush); pDC->SelectObject(hOld); pDC->SetTextColor(crOld); pDC->SetBkMode(nOldBack); pDC->SetBkColor(crOldBack); }
static char* winToggleGetBgColorAttrib(Ihandle* ih) { /* the most important use of this is to provide the correct background for images */ if (iupwin_comctl32ver6 && ih->data->type==IUP_TOGGLE_IMAGE) { COLORREF cr; if (iupwinDrawGetThemeButtonBgColor(ih->handle, &cr)) return iupStrReturnStrf("%d %d %d", (int)GetRValue(cr), (int)GetGValue(cr), (int)GetBValue(cr)); } if (ih->data->type == IUP_TOGGLE_TEXT) return iupBaseNativeParentGetBgColorAttrib(ih); else return IupGetGlobal("DLGBGCOLOR"); }
//-------------------------------------------------------------------------- // void wxPLDevDC::PutPixel( short x, short y, PLINT color ) // // Draw a pixel in color color @ (x,y). //-------------------------------------------------------------------------- void wxPLDevDC::PutPixel( short x, short y, PLINT color ) { const wxPen oldpen = m_dc->GetPen(); m_dc->SetPen( *( wxThePenList->FindOrCreatePen( wxColour( GetRValue( color ), GetGValue( color ), GetBValue( color ) ), 1, wxSOLID ) ) ); m_dc->DrawPoint( x, y ); AddtoClipRegion( x, y, x, y ); m_dc->SetPen( oldpen ); }
void CProgressCtrlX::DrawGradient(const CDrawInfo& info, const CRect &rcGrad, const CRect &rcClip, COLORREF clrStart, COLORREF clrEnd) { // Split colors to RGB chanels, find chanel with maximum difference // between the start and end colors. This distance will determine // number of steps of gradient int r = (GetRValue(clrEnd) - GetRValue(clrStart)); int g = (GetGValue(clrEnd) - GetGValue(clrStart)); int b = (GetBValue(clrEnd) - GetBValue(clrStart)); int nSteps = max(abs(r), max(abs(g), abs(b))); // if number of pixels in gradient less than number of steps - // use it as numberof steps int nPixels = rcGrad.Width(); nSteps = min(nPixels, nSteps); if(nSteps == 0) nSteps = 1; float rStep = (float)r/nSteps; float gStep = (float)g/nSteps; float bStep = (float)b/nSteps; r = GetRValue(clrStart); g = GetGValue(clrStart); b = GetBValue(clrStart); BOOL fLowColor = info.pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE; if(!fLowColor && nSteps > 1) if(info.pDC->GetDeviceCaps(BITSPIXEL)*info.pDC->GetDeviceCaps(PLANES) < 8) nSteps = 1; // for 16 colors no gradient float nWidthPerStep = (float)rcGrad.Width() / nSteps; CRect rcFill(rcGrad); CBrush br; // Start filling for (int i = 0; i < nSteps; i++) { rcFill.left = rcGrad.left + (int)(nWidthPerStep * i); rcFill.right = rcGrad.left + (int)(nWidthPerStep * (i+1)); if(i == nSteps-1) //last step (because of problems with float) rcFill.right = rcGrad.right; if(rcFill.right < rcClip.left) continue; // skip - band before cliping rect // clip it if(rcFill.left < rcClip.left) rcFill.left = rcClip.left; if(rcFill.right > rcClip.right) rcFill.right = rcClip.right; COLORREF clrFill = RGB(r + (int)(i * rStep), g + (int)(i * gStep), b + (int)(i * bStep)); if(fLowColor) { br.CreateSolidBrush(clrFill); // CDC::FillSolidRect is faster, but it does not handle 8-bit color depth info.pDC->FillRect(&ConvertToReal(info, rcFill), &br); br.DeleteObject(); } else info.pDC->FillSolidRect(&ConvertToReal(info, rcFill), clrFill); if(rcFill.right >= rcClip.right) break; // stop filling if we reach current position } }
void MeterM5::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 CPolyDlg::OnSelchangeContour() { POSITION pos ; int numcnrs, cnridx ; CContour* pCtr ; int selidx = m_ContourList.GetCurSel() ; if( m_LastContourSelIdx != selidx ) { //save current corner points back into parent contour object if( m_LastContourSelIdx >= 0 && m_LastContourSelIdx < m_ContourList.GetCount() ) { pos = m_ContourPtrList.FindIndex( m_LastContourSelIdx ) ; numcnrs = m_Combo_Corner.GetCount() ; if( pos && numcnrs > 0 ) { pCtr = (CContour*)m_ContourPtrList.GetAt( pos ) ; //don't delete pCtr, but do delete vertix arrays and m_ppVertexArray int numcnrs = pCtr->m_NumVertex ; for( cnridx = 0; cnridx < numcnrs; cnridx++ ) { GLdouble* pcnr = pCtr->m_ppVertexArray[ cnridx ] ; //pcnr pts to a GLdouble[6] array delete[] pcnr ; pcnr = NULL ; } delete[] pCtr->m_ppVertexArray ; pCtr->m_ppVertexArray = NULL ; //now create new arrays & load them from combobox pCtr->m_ppVertexArray = new GLdouble*[ numcnrs ] ; pCtr->m_NumVertex = numcnrs ; for( cnridx = 0; cnridx < numcnrs; cnridx++ ) { GLdouble* pcnr = new GLdouble[6] ; //pcnr pts to a GLdouble[6] array CString cnrstr ; m_Combo_Corner.GetLBText( cnridx, cnrstr ) ; Vector3D vcnr = GetCnrVector( cnrstr ) ; COLORREF col = GetCnrColor( cnrstr ) ; int R = GetRValue( col ) ; int G = GetGValue( col ) ; int B = GetBValue( col ) ; pcnr[0] = (GLdouble)vcnr.x ; pcnr[1] = (GLdouble)vcnr.y ; pcnr[2] = (GLdouble)vcnr.z ; //need to convert integer color value to normalized GLdouble pcnr[3] = (GLdouble)R/255. ; pcnr[4] = (GLdouble)G/255. ; pcnr[5] = (GLdouble)B/255. ; pCtr->m_ppVertexArray[ cnridx ] = pcnr ; } m_Combo_Corner.ResetContent() ; //dont do this if last selidx was invalid } } //load selected countour's corner pts into the combo list pos = m_ContourPtrList.FindIndex( selidx ) ; if( pos ) { CContour* pCtr = (CContour*)m_ContourPtrList.GetAt( pos ) ; int numcnrs = pCtr->m_NumVertex ; for( int cnridx = 0; cnridx < numcnrs; cnridx++ ) { GLdouble* pcnr = pCtr->m_ppVertexArray[ cnridx ] ; //pcnr pts to a GLdouble[6] array CString numstr, cnrstr ; FormatNumStr( numstr, cnridx + 1 ) ; cnrstr.Format( m_csCoordFmtStr, pcnr[0], pcnr[1], pcnr[2], int(pcnr[3]*255), int(pcnr[4]*255), int(pcnr[5]*255) ) ; m_Combo_Corner.AddString( numstr + cnrstr ) ; } } //now its safe to overwrite last idx & combo list contents m_LastContourSelIdx = selidx ; } UpdateControls() ; }
void CxShadeButton::SetShade(UINT shadeID,BYTE granularity,BYTE highlight,BYTE coloring,COLORREF color) { long sXSize,sYSize,bytes,j,i,k,h; BYTE *iDst ,*posDst; RECT rect; GetWindowRect(&rect); sYSize=rect.bottom-rect.top; sXSize=rect.right-rect.left ; m_dh.Create(max(1,sXSize-2*m_FocusRectMargin),1,8); //create the horizontal focus bitmap m_dv.Create(1,max(1,sYSize-2*m_FocusRectMargin),8); //create the vertical focus bitmap m_dNormal.Create(sXSize,sYSize,8); //create the default bitmap COLORREF hicr=GetSysColor(COLOR_BTNHIGHLIGHT); //get the button base colors COLORREF midcr=GetSysColor(COLOR_BTNFACE); COLORREF locr=GetSysColor(COLOR_BTNSHADOW); long r,g,b; //build the shaded palette for(i=0;i<129;i++){ r=((128-i)*GetRValue(locr)+i*GetRValue(midcr))/128; g=((128-i)*GetGValue(locr)+i*GetGValue(midcr))/128; b=((128-i)*GetBValue(locr)+i*GetBValue(midcr))/128; m_dNormal.SetPaletteIndex((BYTE)i,(BYTE)r,(BYTE)g,(BYTE)b); m_dh.SetPaletteIndex((BYTE)i,(BYTE)r,(BYTE)g,(BYTE)b); m_dv.SetPaletteIndex((BYTE)i,(BYTE)r,(BYTE)g,(BYTE)b); } for(i=1;i<129;i++){ r=((128-i)*GetRValue(midcr)+i*GetRValue(hicr))/128; g=((128-i)*GetGValue(midcr)+i*GetGValue(hicr))/128; b=((128-i)*GetBValue(midcr)+i*GetBValue(hicr))/128; m_dNormal.SetPaletteIndex((BYTE)(i+127),(BYTE)r,(BYTE)g,(BYTE)b); m_dh.SetPaletteIndex((BYTE)(i+127),(BYTE)r,(BYTE)g,(BYTE)b); m_dv.SetPaletteIndex((BYTE)(i+127),(BYTE)r,(BYTE)g,(BYTE)b); } m_dNormal.BlendPalette(color,coloring); //color the palette iDst=m_dh.GetBits(); //build the horiz. dotted focus bitmap j=(long)m_dh.GetWidth(); for(i=0;i<j;i++){ // iDst[i]=64+127*(i%2); //soft iDst[i]=255*(i%2); //hard } iDst=m_dv.GetBits(); //build the vert. dotted focus bitmap j=(long)m_dv.GetHeight(); for(i=0;i<j;i++){ // *iDst=64+127*(i%2); //soft *iDst=255*(i%2); //hard iDst+=4; } bytes = m_dNormal.GetLineWidth(); iDst = m_dNormal.GetBits(); posDst =iDst; long a,x,y,d,xs,idxmax,idxmin; int grainx2=RAND_MAX/(max(1,2*granularity)); idxmax=255-granularity; idxmin=granularity; switch(shadeID){ //---------------------------------------------------- case 8: //SHS_METAL m_dNormal.Clear(); // create the strokes k=40; //stroke granularity for(a=0;a<200;a++){ x=rand()/(RAND_MAX/sXSize); //stroke postion y=rand()/(RAND_MAX/sYSize); //stroke position xs=rand()/(RAND_MAX/min(sXSize,sYSize))/2; //stroke lenght d=rand()/(RAND_MAX/k); //stroke color for(i=0;i<xs;i++){ if (((x-i)>0)&&((y+i)<sYSize)) m_dNormal.SetPixelIndex(x-i,y+i,(BYTE)d); if (((x+i)<sXSize)&&((y-i)>0)) m_dNormal.SetPixelIndex(sXSize-x+i,y-i,(BYTE)d); } } //blend strokes with SHS_DIAGONAL posDst =iDst; a=(idxmax-idxmin-k)/2; for(i = 0; i < sYSize; i++) { for(j = 0; j < sXSize; j++) { d=posDst[j]+((a*i)/sYSize+(a*(sXSize-j))/sXSize); posDst[j]=(BYTE)d; posDst[j]+=rand()/grainx2; } posDst+=bytes; } break; //---------------------------------------------------- case 7: // SHS_HARDBUMP //set horizontal bump for(i = 0; i < sYSize; i++) { k=(255*i/sYSize)-127; k=(k*(k*k)/128)/128; k=(k*(128-granularity))/128+128; for(j = 0; j < sXSize; j++) { posDst[j]=(BYTE)k; posDst[j]+=rand()/grainx2-granularity; } posDst+=bytes; } //set vertical bump d=min(16,sXSize/6); //max edge=16 a=sYSize*sYSize/4; posDst =iDst; for(i = 0; i < sYSize; i++) { y=i-sYSize/2; for(j = 0; j < sXSize; j++) { x=j-sXSize/2; xs=sXSize/2-d+(y*y*d)/a; if (x>xs) posDst[j]=idxmin+(BYTE)(((sXSize-j)*128)/d); if ((x+xs)<0) posDst[j]=idxmax-(BYTE)((j*128)/d); posDst[j]+=rand()/grainx2-granularity; } posDst+=bytes; } break; //---------------------------------------------------- case 6: //SHS_SOFTBUMP for(i = 0; i < sYSize; i++) { h=(255*i/sYSize)-127; for(j = 0; j < sXSize; j++) { k=(255*(sXSize-j)/sXSize)-127; k=(h*(h*h)/128)/128+(k*(k*k)/128)/128; k=k*(128-granularity)/128+128; if (k<idxmin) k=idxmin; if (k>idxmax) k=idxmax; posDst[j]=(BYTE)k; posDst[j]+=rand()/grainx2-granularity; } posDst+=bytes; } break; //---------------------------------------------------- case 5: // SHS_VBUMP for(j = 0; j < sXSize; j++) { k=(255*(sXSize-j)/sXSize)-127; k=(k*(k*k)/128)/128; k=(k*(128-granularity))/128+128; for(i = 0; i < sYSize; i++) { posDst[j+i*bytes]=(BYTE)k; posDst[j+i*bytes]+=rand()/grainx2-granularity; } } break; //---------------------------------------------------- case 4: //SHS_HBUMP for(i = 0; i < sYSize; i++) { k=(255*i/sYSize)-127; k=(k*(k*k)/128)/128; k=(k*(128-granularity))/128+128; for(j = 0; j < sXSize; j++) { posDst[j]=(BYTE)k; posDst[j]+=rand()/grainx2-granularity; } posDst+=bytes; } break; //---------------------------------------------------- case 1: //SHS_DIAGSHADE a=(idxmax-idxmin)/2; for(i = 0; i < sYSize; i++) { for(j = 0; j < sXSize; j++) { posDst[j]=(BYTE)(idxmin+a*i/sYSize+a*(sXSize-j)/sXSize); posDst[j]+=rand()/grainx2-granularity; } posDst+=bytes; } break; //---------------------------------------------------- case 2: //SHS_HSHADE a=idxmax-idxmin; for(i = 0; i < sYSize; i++) { k=a*i/sYSize+idxmin; for(j = 0; j < sXSize; j++) { posDst[j]=(BYTE)k; posDst[j]+=rand()/grainx2-granularity; } posDst+=bytes; } break; //---------------------------------------------------- case 3: //SHS_VSHADE: a=idxmax-idxmin; for(j = 0; j < sXSize; j++) { k=a*(sXSize-j)/sXSize+idxmin; for(i = 0; i < sYSize; i++) { posDst[j+i*bytes]=(BYTE)k; posDst[j+i*bytes]+=rand()/grainx2-granularity; } } break; //---------------------------------------------------- default: //SHS_NOISE for(i = 0; i < sYSize; i++) { for(j = 0; j < sXSize; j++) { posDst[j]=128+rand()/grainx2-granularity; } posDst+=bytes; } } //---------------------------------------------------- m_dDisabled.Clone(&m_dNormal); //build the other bitmaps m_dOver.Clone(&m_dNormal); m_dOver.BlendPalette(GetSysColor(COLOR_BTNHIGHLIGHT),highlight); m_dDown.Clone(&m_dOver); }
BYTE colorToByte(COLORREF* ref) { return (GetRValue(*ref) * 30 + GetGValue(*ref) * 59 + GetBValue(*ref) * 11) / 100; }
void COptionTreeColorPopUp::DrawCell(CDC* pDC, int nIndex) { // For the Custom Text area if (m_strCustomText.GetLength() && nIndex == OT_COLOR_CUSTOMBOXVALUE) { // -- The extent of the actual text button CRect rcTextButton = m_rcCustomTextRect; rcTextButton.top += 2 * m_nMargin; // -- Fill background pDC->FillSolidRect(rcTextButton, ::GetSysColor(COLOR_3DFACE)); // -- Draw horizontal line pDC->FillSolidRect(m_rcCustomTextRect.left + 2 * m_nMargin, m_rcCustomTextRect.top, m_rcCustomTextRect.Width()-4*m_nMargin, 1, ::GetSysColor(COLOR_3DSHADOW)); pDC->FillSolidRect(m_rcCustomTextRect.left + 2 * m_nMargin, m_rcCustomTextRect.top + 1, m_rcCustomTextRect.Width()-4*m_nMargin, 1, ::GetSysColor(COLOR_3DHILIGHT)); rcTextButton.DeflateRect(1,1); // -- Fill background if (m_nChosenColorSel == nIndex && m_nCurrentSel != nIndex) { pDC->FillSolidRect(rcTextButton, ::GetSysColor(COLOR_3DLIGHT)); } else { pDC->FillSolidRect(rcTextButton, ::GetSysColor(COLOR_3DFACE)); } // -- Draw button if (m_nCurrentSel == nIndex) { pDC->DrawEdge(rcTextButton, BDR_RAISEDINNER, BF_RECT); } // -- Draw custom text CFont *pOldFont = (CFont*) pDC->SelectObject(&m_fFont); int nOldBack = pDC->SetBkMode(TRANSPARENT); pDC->DrawText(m_strCustomText, rcTextButton, DT_CENTER | DT_VCENTER | DT_SINGLELINE); // -- Restore pDC->SelectObject(pOldFont); pDC->SetBkMode(nOldBack); return; } // For the Default Text area if (m_strDefaultText.GetLength() && nIndex == OT_COLOR_DEFAULTBOXVALUE) { // -- Fill background pDC->FillSolidRect(m_rcDefaultTextRect, ::GetSysColor(COLOR_3DFACE)); // -- The extent of the actual text button CRect rcTextButton = m_rcDefaultTextRect; rcTextButton.DeflateRect(1,1); // -- Fill background if (m_nChosenColorSel == nIndex && m_nCurrentSel != nIndex) { for (long i = rcTextButton.top; i < rcTextButton.bottom; i++) { _DrawSelectRect(pDC->GetSafeHdc(), rcTextButton.left, i, rcTextButton.Width()); } } else { pDC->FillSolidRect(rcTextButton, ::GetSysColor(COLOR_3DFACE)); } // -- Draw thin line around text CRect rcLineRect = rcTextButton; CPen pen(PS_SOLID, 1, ::GetSysColor(COLOR_3DSHADOW)); CPen* pOldPen = pDC->SelectObject(&pen); // -- Calculate the rectangle rcLineRect.left += 3; rcLineRect.right -= 3; rcLineRect.top += 2; rcLineRect.bottom -= 3; // -- Restore pDC->SelectStockObject(NULL_BRUSH); pDC->Rectangle(rcLineRect); pDC->SelectObject(pOldPen); if (pen.GetSafeHandle() != NULL) { pen.DeleteObject(); } // -- Draw button if (m_nCurrentSel == nIndex) { pDC->DrawEdge(rcTextButton, BDR_RAISEDINNER, BF_RECT); } else if (m_nChosenColorSel == nIndex) { pDC->DrawEdge(rcTextButton, BDR_SUNKENOUTER, BF_RECT); } // -- Draw custom text CFont *pOldFont = (CFont*) pDC->SelectObject(&m_fFont); int nOldBack = pDC->SetBkMode(TRANSPARENT); pDC->DrawText(m_strDefaultText, rcTextButton, DT_CENTER | DT_VCENTER | DT_SINGLELINE); // -- Restore pDC->SelectObject(pOldFont); pDC->SetBkMode(nOldBack); // -- Select and realize the palette CPalette* pOldPalette = NULL; if (pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE) { pOldPalette = pDC->SelectPalette(&m_plPalette, FALSE); pDC->RealizePalette(); } // -- Draw sample cell of default color CRect rcSample; rcSample.left = rcLineRect.left; rcSample.right = rcSample.left + m_nBoxSize; rcSample.top = rcLineRect.top; rcSample.bottom = rcLineRect.top + m_nBoxSize; rcSample.DeflateRect(m_nMargin + 1, m_nMargin + 1); // -- Create objects CBrush brush(PALETTERGB(GetRValue(m_crDefault), GetGValue(m_crDefault), GetBValue(m_crDefault))); CPen penSample; penSample.CreatePen(PS_SOLID, 1, ::GetSysColor(COLOR_3DSHADOW)); CBrush* pOldBrush = (CBrush*) pDC->SelectObject(&brush); CPen* pOldSamplePen = (CPen*) pDC->SelectObject(&penSample); // Draw the cell color pDC->Rectangle(rcSample); // Restore pDC->SelectObject(pOldBrush); pDC->SelectObject(pOldSamplePen); if (brush.GetSafeHandle() != NULL) { brush.DeleteObject(); } if (penSample.GetSafeHandle() != NULL) { penSample.DeleteObject(); } if (pOldPalette && pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE) { pDC->SelectPalette(pOldPalette, FALSE); } return; } // Declare variables CRect rcCell; if (!GetCellRect(nIndex, rcCell)) { return; } // -- Select and realize the palette CPalette* pOldPalette = NULL; if (pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE) { pOldPalette = pDC->SelectPalette(&m_plPalette, FALSE); pDC->RealizePalette(); } // -- Fill background if (m_nChosenColorSel == nIndex && m_nCurrentSel != nIndex) { for (long i = rcCell.top; i < rcCell.bottom; i++) { _DrawSelectRect(pDC->GetSafeHdc(), rcCell.left, i, rcCell.Width()); } } else { pDC->FillSolidRect(rcCell, ::GetSysColor(COLOR_3DFACE)); } // Draw button if (m_nCurrentSel == nIndex) { pDC->DrawEdge(rcCell, BDR_RAISEDINNER, BF_RECT); } else if (m_nChosenColorSel == nIndex) { pDC->DrawEdge(rcCell, BDR_SUNKENOUTER, BF_RECT); } // Create objects CBrush brush(PALETTERGB(GetRValue(GetColor(nIndex)), GetGValue(GetColor(nIndex)), GetBValue(GetColor(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 color rcCell.DeflateRect(m_nMargin + 1, m_nMargin + 1); pDC->Rectangle(rcCell); // Restore pDC->SelectObject(pOldBrush); pDC->SelectObject(pOldPen); if (brush.GetSafeHandle() != NULL) { brush.DeleteObject(); } if (pen.GetSafeHandle() != NULL) { pen.DeleteObject(); } if (pOldPalette && pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE) { pDC->SelectPalette(pOldPalette, FALSE); } }
void PaintClc(HWND hwnd, struct ClcData *dat, HDC hdc, RECT * rcPaint) { RECT clRect; int y, indent, index, fontHeight; struct ClcGroup *group; HFONT hOldFont; LONG_PTR style = GetWindowLongPtr(hwnd, GWL_STYLE); int status = GetGeneralisedStatus(); int grey = 0, groupCountsFontTopShift; HBRUSH hBrushAlternateGrey = NULL; // yes I know about GetSysColorBrush() COLORREF tmpbkcolour = style & CLS_CONTACTLIST ? (dat->useWindowsColours ? GetSysColor(COLOR_3DFACE) : dat->bkColour) : dat->bkColour; if (dat->greyoutFlags & pcli->pfnClcStatusToPf2(status) || style & WS_DISABLED) grey = 1; else if (GetFocus() != hwnd && dat->greyoutFlags & GREYF_UNFOCUS) grey = 1; GetClientRect(hwnd, &clRect); if (rcPaint == NULL) rcPaint = &clRect; if (IsRectEmpty(rcPaint)) return; y = -dat->yScroll; HDC hdcMem = CreateCompatibleDC(hdc); HBITMAP hBmpOsb = CreateBitmap(clRect.right, clRect.bottom, 1, GetDeviceCaps(hdc, BITSPIXEL), NULL); HBITMAP hOldBitmap = (HBITMAP)SelectObject(hdcMem, hBmpOsb); { TEXTMETRIC tm; hOldFont = (HFONT)SelectObject(hdcMem, dat->fontInfo[FONTID_GROUPS].hFont); GetTextMetrics(hdcMem, &tm); groupCountsFontTopShift = tm.tmAscent; SelectObject(hdcMem, dat->fontInfo[FONTID_GROUPCOUNTS].hFont); GetTextMetrics(hdcMem, &tm); groupCountsFontTopShift -= tm.tmAscent; } if (style & CLS_GREYALTERNATE) hBrushAlternateGrey = CreateSolidBrush(GetNearestColor(hdcMem, RGB(GetRValue(tmpbkcolour) - 10, GetGValue(tmpbkcolour) - 10, GetBValue(tmpbkcolour) - 10))); ChangeToFont(hdcMem, dat, FONTID_CONTACTS, &fontHeight); SetBkMode(hdcMem, TRANSPARENT); { HBRUSH hBrush = CreateSolidBrush(tmpbkcolour); FillRect(hdcMem, rcPaint, hBrush); DeleteObject(hBrush); if (dat->hBmpBackground) { int x, y; int destw, desth; // XXX: Halftone isnt supported on 9x, however the scretch problems dont happen on 98. SetStretchBltMode(hdcMem, HALFTONE); BITMAP bmp; GetObject(dat->hBmpBackground, sizeof(bmp), &bmp); HDC hdcBmp = CreateCompatibleDC(hdcMem); SelectObject(hdcBmp, dat->hBmpBackground); y = dat->backgroundBmpUse & CLBF_SCROLL ? -dat->yScroll : 0; int maxx = dat->backgroundBmpUse & CLBF_TILEH ? clRect.right : 1; int maxy = dat->backgroundBmpUse & CLBF_TILEV ? maxy = rcPaint->bottom : y + 1; switch (dat->backgroundBmpUse & CLBM_TYPE) { case CLB_STRETCH: if (dat->backgroundBmpUse & CLBF_PROPORTIONAL) { if (clRect.right * bmp.bmHeight < clRect.bottom * bmp.bmWidth) { desth = clRect.bottom; destw = desth * bmp.bmWidth / bmp.bmHeight; } else { destw = clRect.right; desth = destw * bmp.bmHeight / bmp.bmWidth; } } else { destw = clRect.right; desth = clRect.bottom; } break; case CLB_STRETCHH: if (dat->backgroundBmpUse & CLBF_PROPORTIONAL) { destw = clRect.right; desth = destw * bmp.bmHeight / bmp.bmWidth; } else { destw = clRect.right; desth = bmp.bmHeight; } break; case CLB_STRETCHV: if (dat->backgroundBmpUse & CLBF_PROPORTIONAL) { desth = clRect.bottom; destw = desth * bmp.bmWidth / bmp.bmHeight; } else { destw = bmp.bmWidth; desth = clRect.bottom; } break; default: //clb_topleft destw = bmp.bmWidth; desth = bmp.bmHeight; break; } for (; y < maxy; y += desth) { if (y < rcPaint->top - desth) continue; for (x = 0; x < maxx; x += destw) StretchBlt(hdcMem, x, y, destw, desth, hdcBmp, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY); } DeleteDC(hdcBmp); } } group = &dat->list; group->scanIndex = 0; indent = 0; for (index = 0; y < rcPaint->bottom;) { if (group->scanIndex == group->cl.count) { group = group->parent; indent--; if (group == NULL) break; group->scanIndex++; continue; } if (y > rcPaint->top - dat->rowHeight) { int iImage = -1; int selected = index == dat->selection && (dat->showSelAlways || dat->exStyle & CLS_EX_SHOWSELALWAYS || GetFocus() == hwnd) && group->cl.items[group->scanIndex]->type != CLCIT_DIVIDER; int hottrack = dat->exStyle & CLS_EX_TRACKSELECT && group->cl.items[group->scanIndex]->type != CLCIT_DIVIDER && dat->iHotTrack == index; SIZE textSize, countsSize, spaceSize; int width, checkboxWidth; char *szCounts; //alternating grey if (style & CLS_GREYALTERNATE && index & 1) { RECT rc; rc.top = y; rc.bottom = rc.top + dat->rowHeight; rc.left = 0; rc.right = clRect.right; FillRect(hdcMem, &rc, hBrushAlternateGrey); } //setup if (group->cl.items[group->scanIndex]->type == CLCIT_GROUP) ChangeToFont(hdcMem, dat, FONTID_GROUPS, &fontHeight); else if (group->cl.items[group->scanIndex]->type == CLCIT_INFO) { if (group->cl.items[group->scanIndex]->flags & CLCIIF_GROUPFONT) ChangeToFont(hdcMem, dat, FONTID_GROUPS, &fontHeight); else ChangeToFont(hdcMem, dat, FONTID_CONTACTS, &fontHeight); } else if (group->cl.items[group->scanIndex]->type == CLCIT_DIVIDER) ChangeToFont(hdcMem, dat, FONTID_DIVIDERS, &fontHeight); else if (group->cl.items[group->scanIndex]->type == CLCIT_CONTACT && group->cl.items[group->scanIndex]->flags & CONTACTF_NOTONLIST) ChangeToFont(hdcMem, dat, FONTID_NOTONLIST, &fontHeight); else if (group->cl.items[group->scanIndex]->type == CLCIT_CONTACT && ((group->cl.items[group->scanIndex]->flags & CONTACTF_INVISTO && GetRealStatus(group->cl.items[group->scanIndex], status) != ID_STATUS_INVISIBLE) || (group->cl.items[group->scanIndex]->flags & CONTACTF_VISTO && GetRealStatus(group->cl.items[group->scanIndex], status) == ID_STATUS_INVISIBLE) ) ) { // the contact is in the always visible list and the proto is invisible // the contact is in the always invisible and the proto is in any other mode ChangeToFont(hdcMem, dat, group->cl.items[group->scanIndex]->flags & CONTACTF_ONLINE ? FONTID_INVIS : FONTID_OFFINVIS, &fontHeight); } else if (group->cl.items[group->scanIndex]->type == CLCIT_CONTACT && !(group->cl.items[group->scanIndex]->flags & CONTACTF_ONLINE)) ChangeToFont(hdcMem, dat, FONTID_OFFLINE, &fontHeight); else ChangeToFont(hdcMem, dat, FONTID_CONTACTS, &fontHeight); GetTextExtentPoint32(hdcMem, group->cl.items[group->scanIndex]->szText, (int)mir_tstrlen(group->cl.items[group->scanIndex]->szText), &textSize); width = textSize.cx; if (group->cl.items[group->scanIndex]->type == CLCIT_GROUP) { szCounts = pcli->pfnGetGroupCountsText(dat, group->cl.items[group->scanIndex]); if (szCounts[0]) { GetTextExtentPoint32A(hdcMem, " ", 1, &spaceSize); ChangeToFont(hdcMem, dat, FONTID_GROUPCOUNTS, &fontHeight); GetTextExtentPoint32A(hdcMem, szCounts, (int)mir_strlen(szCounts), &countsSize); width += spaceSize.cx + countsSize.cx; } } if ((style & CLS_CHECKBOXES && group->cl.items[group->scanIndex]->type == CLCIT_CONTACT) || (style & CLS_GROUPCHECKBOXES && group->cl.items[group->scanIndex]->type == CLCIT_GROUP) || (group->cl.items[group->scanIndex]->type == CLCIT_INFO && group->cl.items[group->scanIndex]->flags & CLCIIF_CHECKBOX)) checkboxWidth = dat->checkboxSize + 2; else checkboxWidth = 0; //background if (selected) { int x = dat->leftMargin + indent * dat->groupIndent + checkboxWidth + dat->iconXSpace - 2; ImageList_DrawEx(dat->himlHighlight, 0, hdcMem, x, y, min(width + 5, clRect.right - x), dat->rowHeight, CLR_NONE, CLR_NONE, dat->exStyle & CLS_EX_NOTRANSLUCENTSEL ? ILD_NORMAL : ILD_BLEND25); SetTextColor(hdcMem, dat->selTextColour); } else if (hottrack) SetHotTrackColour(hdcMem, dat); //checkboxes if (checkboxWidth) { RECT rc; HANDLE hTheme = OpenThemeData(hwnd, L"BUTTON"); rc.left = dat->leftMargin + indent * dat->groupIndent; rc.right = rc.left + dat->checkboxSize; rc.top = y + ((dat->rowHeight - dat->checkboxSize) >> 1); rc.bottom = rc.top + dat->checkboxSize; DrawThemeBackground(hTheme, hdcMem, BP_CHECKBOX, group->cl.items[group->scanIndex]->flags & CONTACTF_CHECKED ? (hottrack ? CBS_CHECKEDHOT : CBS_CHECKEDNORMAL) : (hottrack ? CBS_UNCHECKEDHOT : CBS_UNCHECKEDNORMAL), &rc, &rc); CloseThemeData(hTheme); } //icon if (group->cl.items[group->scanIndex]->type == CLCIT_GROUP) iImage = group->cl.items[group->scanIndex]->group->expanded ? IMAGE_GROUPOPEN : IMAGE_GROUPSHUT; else if (group->cl.items[group->scanIndex]->type == CLCIT_CONTACT) iImage = group->cl.items[group->scanIndex]->iImage; if (iImage != -1) { /*COLORREF colourFg=dat->selBkColour; int mode=ILD_NORMAL; if(selected) mode=ILD_SELECTED; else if(hottrack) {mode=ILD_FOCUS; colourFg=dat->hotTextColour;} else if(group->cl.items[group->scanIndex]->type==CLCIT_CONTACT && group->cl.items[group->scanIndex]->flags&CONTACTF_NOTONLIST) {colourFg=dat->fontInfo[FONTID_NOTONLIST].colour; mode=ILD_BLEND50;} ImageList_DrawEx(himlCListClc,iImage,hdcMem,dat->leftMargin+indent*dat->groupIndent+checkboxWidth,y+((dat->rowHeight-16)>>1),0,0,CLR_NONE,colourFg,mode); */ // this doesnt use CLS_CONTACTLIST since the colour prolly wont match anyway COLORREF colourFg = dat->selBkColour; int mode = ILD_NORMAL; if (hottrack) { colourFg = dat->hotTextColour; } else if (group->cl.items[group->scanIndex]->type == CLCIT_CONTACT && group->cl.items[group->scanIndex]->flags & CONTACTF_NOTONLIST) { colourFg = dat->fontInfo[FONTID_NOTONLIST].colour; mode = ILD_BLEND50; } if (group->cl.items[group->scanIndex]->type == CLCIT_CONTACT && dat->showIdle && (group->cl.items[group->scanIndex]->flags & CONTACTF_IDLE) && GetRealStatus(group->cl.items[group->scanIndex], ID_STATUS_OFFLINE) != ID_STATUS_OFFLINE) mode = ILD_SELECTED; ImageList_DrawEx(himlCListClc, iImage, hdcMem, dat->leftMargin + indent * dat->groupIndent + checkboxWidth, y + ((dat->rowHeight - 16) >> 1), 0, 0, CLR_NONE, colourFg, mode); } //text if (group->cl.items[group->scanIndex]->type == CLCIT_DIVIDER) { RECT rc; rc.top = y + (dat->rowHeight >> 1); rc.bottom = rc.top + 2; rc.left = dat->leftMargin + indent * dat->groupIndent; rc.right = rc.left + ((clRect.right - rc.left - textSize.cx) >> 1) - 3; DrawEdge(hdcMem, &rc, BDR_SUNKENOUTER, BF_RECT); TextOut(hdcMem, rc.right + 3, y + ((dat->rowHeight - fontHeight) >> 1), group->cl.items[group->scanIndex]->szText, (int)mir_tstrlen(group->cl.items[group->scanIndex]->szText)); rc.left = rc.right + 6 + textSize.cx; rc.right = clRect.right; DrawEdge(hdcMem, &rc, BDR_SUNKENOUTER, BF_RECT); }
HRESULT InitPaletteColors(COLOR_REF *pColor, PULONG pColorCount, IMG_BITMAP_HEADER *pBmp, PVOID pvRaw) { LONG Stride, ColorCount; PULONG pRaw, pRawBase; COLOR_REF *p; ColorCount = 0; Stride = (pBmp->Info.dwWidth * pBmp->Info.wBit / 8 + 3) & ~3; pRawBase = (PULONG)pvRaw; for (ULONG Height = pBmp->Info.dwHeight; Height; --Height) { pRaw = pRawBase; for (ULONG Width = pBmp->Info.dwWidth; Width; --Width) { LONG Index; ULONG Color; Color = *pRaw++; Index = 0; for (p = pColor; Index != ColorCount; ++Index) if (Color == p->Color) break; else ++p; if (Index == ColorCount) { p->Color = Color; p->RefCount = 1; ++ColorCount; } else { ++p->RefCount; } } *(PULONG)&pRawBase += Stride; } qsort(pColor, ColorCount, sizeof(*pColor), (int (__cdecl *)(const void*,const void*))compare); p = pColor; for (ULONG Index = 0, Count = MY_MIN(ColorCount, 256); Count; --Count) p++->Index = Index++; if (ColorCount > 256) { p = pColor + 256; for (ULONG Count = ColorCount - 256; Count; ++p, --Count) { LONG Diff, NearestIndex; ULONG Color = p->Color; COLOR_REF *p2 = pColor; NearestIndex = 0; Diff = 0x7FFFFFFF; for (ULONG Count = 256; Count; ++p2, --Count) { LONG diff2, r, g, b, a; diff2 = Color - p2->Color; r = GetRValue(diff2); g = GetGValue(diff2); b = GetBValue(diff2); a = diff2 >> 24; if (r < 0) r = -r; if (g < 0) g = -g; if (b < 0) b = -b; if (a < 0) a = -a; diff2 = r + g + b + a; if (diff2 < Diff) { Diff = diff2; NearestIndex = p2->Index; } } p->Index = NearestIndex; } }
VOID DrawSphere( HDC hDC, INT Xc, INT Yc ) { INT i, j, x, y; DOUBLE theta, phi, phase = clock() / 100; static VEC G[N][M]; for (i = 0; i < N; i++) { theta = i * PI / (N - 1); for (j = 0; j < M; j++) { phi = j * 2 * PI / (M - 1) + phase; G[i][j].X = R * sin(theta) * cos(phi); G[i][j].Y = R * sin(theta) * sin(phi); G[i][j].Z = R * cos(theta); G[i][j] = Rotate(G[i][j], VecSet(1, 1, 1), 45); } } for (i = 0; i < N; i++) for (j = 0; j < M; j++) { Ps[i][j].x = Xc + G[i][j].X; Ps[i][j].y = Yc - G[i][j].Z; } SelectObject(hDC, GetStockObject(DC_PEN)); SelectObject(hDC, GetStockObject(DC_BRUSH)); SetDCPenColor(hDC, RGB(255, 0, 255)); SetDCBrushColor(hDC, RGB(255, 255, 255)); for (i = 0; i < N - 1; i++) for (j = 0; j < M - 1; j++) { INT img_x, img_y; COLORREF c, r, g, b; img_x = j * (Globe.W - 1) / (M - 1); img_y = i * (Globe.H - 1) / (N - 1); c = Globe.Bits[img_x + img_y * Globe.W]; r = GetRValue(c); g = GetGValue(c); b = GetBValue(c); c = RGB(b, g, r); SetDCPenColor(hDC, c); SetDCBrushColor(hDC, c); p0 = Ps[i][j]; p1 = Ps[i][j + 1]; p2 = Ps[i + 1][j + 1]; p3 = Ps[i + 1][j]; DrawQuad(hDC, p0, p1, p2, p3, c); } /* for (i = 0; i < N; i++) { x = Xc + G[i][0].X; y = Yc - G[i][0].Z; MoveToEx(hDC, x , y, NULL); for (j = 1; j < M; j++) { x = Xc + G[i][j].X; y = Yc - G[i][j].Z; LineTo(hDC, x, y); } } for (j = 0; j < M; j++) { x = Xc + G[0][j].X; y = Yc - G[0][j].Z; MoveToEx(hDC, x , y, NULL); for (i = 1; i < N; i++) { x = Xc + G[i][j].X; y = Yc - G[i][j].Z; LineTo(hDC, x, y); } } */ }
void ColorSkinWindow::Notify(TNotifyUI& msg) { if (_tcsicmp(msg.sType, _T("click")) == 0) { CTabLayoutUI* pTabControl = static_cast<CTabLayoutUI*>(paint_manager_.FindControl(kTabControlName)); if (pTabControl != NULL) { if (pTabControl->GetCurSel() == 0) { if (_tcsstr(msg.pSender->GetName(), _T("colour_")) != 0) { CSliderUI* AdjustColorSliderR = static_cast<CSliderUI*>(paint_manager_.FindControl(kAdjustColorSliderRControlName)); CSliderUI* AdjustColorSliderG = static_cast<CSliderUI*>(paint_manager_.FindControl(kAdjustColorSliderGControlName)); CSliderUI* AdjustColorSliderB = static_cast<CSliderUI*>(paint_manager_.FindControl(kAdjustColorSliderBControlName)); if ((AdjustColorSliderR != NULL) && (AdjustColorSliderG != NULL) && (AdjustColorSliderB != NULL)) { DWORD dwColor = msg.pSender->GetBkColor(); AdjustColorSliderR->SetValue(static_cast<BYTE>(GetRValue(dwColor))); AdjustColorSliderG->SetValue(static_cast<BYTE>(GetGValue(dwColor))); AdjustColorSliderB->SetValue(static_cast<BYTE>(GetBValue(dwColor))); main_frame_->SetBkColor(dwColor); } } } else if (pTabControl->GetCurSel() == 1) {} } } else if (_tcsicmp(msg.sType, _T("valuechanged")) == 0) { CTabLayoutUI* pTabControl = static_cast<CTabLayoutUI*>(paint_manager_.FindControl(kTabControlName)); if (pTabControl != NULL) { if (pTabControl->GetCurSel() == 0) { CSliderUI* AdjustColorSliderR = static_cast<CSliderUI*>(paint_manager_.FindControl(kAdjustColorSliderRControlName)); CSliderUI* AdjustColorSliderG = static_cast<CSliderUI*>(paint_manager_.FindControl(kAdjustColorSliderGControlName)); CSliderUI* AdjustColorSliderB = static_cast<CSliderUI*>(paint_manager_.FindControl(kAdjustColorSliderBControlName)); if ((AdjustColorSliderR != NULL) && (AdjustColorSliderG != NULL) && (AdjustColorSliderB != NULL)) { if ((_tcsicmp(msg.pSender->GetName(), kAdjustColorSliderRControlName) == 0) || (_tcsicmp(msg.pSender->GetName(), kAdjustColorSliderGControlName) == 0) || (_tcsicmp(msg.pSender->GetName(), kAdjustColorSliderBControlName) == 0)) { BYTE red = AdjustColorSliderR->GetValue(); BYTE green = AdjustColorSliderG->GetValue(); BYTE blue = AdjustColorSliderB->GetValue(); COLORREF crColor = RGB(red, green, blue); TCHAR szBuf[MAX_PATH] = {0}; #if defined(UNDER_CE) _stprintf(szBuf, _T("FF%02X%02X%02X"), GetRValue(crColor), GetGValue(crColor), GetBValue(crColor)); #else _stprintf_s(szBuf, MAX_PATH - 1, _T("FF%02X%02X%02X"), GetRValue(crColor), GetGValue(crColor), GetBValue(crColor)); #endif LPTSTR pstr = NULL; DWORD dwColor = _tcstoul(szBuf, &pstr, 16); main_frame_->SetBkColor(dwColor); } } } else if (pTabControl->GetCurSel() == 1) {} } } else if (_tcsicmp(msg.sType, _T("selectchanged")) == 0) { CTabLayoutUI* pTabControl = static_cast<CTabLayoutUI*>(paint_manager_.FindControl(kTabControlName)); if (_tcsicmp(msg.pSender->GetName(), kAdjustColorControlName) == 0) { if (pTabControl && pTabControl->GetCurSel() != 0) { pTabControl->SelectItem(0); } } else if (_tcsicmp(msg.pSender->GetName(), kAdjustBkControlName) == 0) { if (pTabControl && pTabControl->GetCurSel() != 1) { pTabControl->SelectItem(1); } } } }