void KGUISkin::InitialSkin() { ReleaseAll(); HDC hDC = ::GetDC(NULL); if (GetDeviceCaps (hDC, BITSPIXEL) <= 8) { assert(false); return ; } m_BaseBrush = ::CreateSolidBrush(m_Color.ToColor()); m_IncBrush = ::CreateSolidBrush(m_IncColor.ToColor()); m_DecBrush = ::CreateSolidBrush(m_DecColor.ToColor()); m_BmpTitle = CreateTitleGradient(hDC); m_BmpHor = CreateBitmap(hDC, 0.4f); m_BmpHorHover = CreateBitmap(hDC, 0.2f); m_BmpVer = CreateBitmap(hDC, 0.4f, true); m_BmpVerHover = CreateBitmap(hDC, 0.2f, true); // Create the system command button highlight color. m_BmpHighlight = CreateGradient(hDC, RGB(0xf7, 0x1b, 0x10), RGB(0xd8, 0x54, 0x2d), RGB(0xd8, 0x54, 0x2d), true); // Create general button bitmap m_BmpBtnNormal = CreateGradient(hDC, RGB(0xe0, 0xe0, 0xe0), RGB(0xe0, 0xe0, 0xe0), RGB(0xc6, 0xc6, 0xc6), true); m_BmpBtnHover = CreateGradient(hDC, RGB(0xef, 0xef, 0xef), RGB(0xff, 0xff, 0xff), RGB(0xe0, 0xe0, 0xe0), true); m_BmpBtnNormalV = CreateGradient(hDC, RGB(0xe0, 0xe0, 0xe0), RGB(0xe0, 0xe0, 0xe0), RGB(0xc6, 0xc6, 0xc6), false); m_BmpBtnHoverV = CreateGradient(hDC, RGB(0xef, 0xef, 0xef), RGB(0xff, 0xff, 0xff), RGB(0xe0, 0xe0, 0xe0), false); ReleaseDC (NULL, hDC); }
HBITMAP KGUISkin::CreateBitmap(HDC hDC, FInt32 fFactor, bool bHor) { FInt32 fLight = L + (1.f - L) * fFactor; RGBQUAD rgb = KColor::HSL2RGB(H, S, fLight); COLORREF clr = KColor(rgb.rgbRed, rgb.rgbGreen, rgb.rgbBlue).ToColor(); return CreateGradient(hDC, m_Color.ToColor(), clr, clr, bHor); }
void CPlasmaRoutine::InitPallette() { // Create a gradient between all the colors we have for our plasma CreateGradient(m_PlasmaColors[0],m_PlasmaColors[1],32,&m_pPalletteBuffer[0]); // From black to Blue CreateGradient(m_PlasmaColors[2],m_PlasmaColors[3],32,&m_pPalletteBuffer[32]); // From Green to Blue CreateGradient(m_PlasmaColors[4],m_PlasmaColors[5],32,&m_pPalletteBuffer[64]); // From Green to White CreateGradient(m_PlasmaColors[6],m_PlasmaColors[6],32,&m_pPalletteBuffer[96]);// From Cyan to Cyan CreateGradient(m_PlasmaColors[8],m_PlasmaColors[9],32,&m_pPalletteBuffer[128]);// Cyan To Cyan CreateGradient(m_PlasmaColors[10],m_PlasmaColors[11],32,&m_pPalletteBuffer[160]);// While to dark Green CreateGradient(m_PlasmaColors[12],m_PlasmaColors[13],32,&m_pPalletteBuffer[192]);// Dark Blue to dark green CreateGradient(m_PlasmaColors[14],m_PlasmaColors[15],32,&m_pPalletteBuffer[224]);// Dark Blue to black }
void CSVGGradientEditCtl::PrepareRange() { if (m_colorSpread) { GlobalFree(m_colorSpread); m_colorSpread = NULL; } if (m_gradient != NULL) { m_colorSpread = CreateGradient(m_gradient, m_totalColors); } }
void CGradientStatic::OnPaint() { CPaintDC dc(this); // device context for painting CRect rClient; GetClientRect(rClient); if(m_bInit) { CreateGradient(&dc, &rClient); m_bInit = false; } dc.BitBlt(0,0,m_Mem.cx, m_Mem.cy, &m_Mem.dc, 0,0, SRCCOPY); }
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; static RECT rect,oldRect,invalidationRect; //The oldRect is used for window resizing handling , the invalidationRect for invalidating only the drawing area static BOOL drawing_circle=FALSE,drawing_square=TRUE,drawing_bezier=FALSE,//Checks what is being drawn at the moment first_point=TRUE, //Checks if the first point of the bezier is being drawn button_pressed_in_area=FALSE, //Checks if the button was pressed and if it happened inside the drawing area mouse_moving=FALSE; //Checks if the mouse is moving in order to paint the tracing of the object static HDC hdc, hdcMem; static HBITMAP hBitmap; BITMAP bitmap; static int figureCount=0; //Counts the number of figures in the drawing area static POINT arrayPoints[100][5]; //The array that holds the data of the figures static float xDisp,yDisp,slope,displacement; //Used to move and resize the pictures drawn . The last two variables are used to calculate the function //that the points will move on when resizing (the resize is a convergence towards the center) static int xFin=0,yFin=0,xFinSecond=0,yFinSecond=0; //Used to draw the tracing of elemens with the last two needed for Bezier only static int resizeCount; //Used to limit the resize to a certain number of times switch (message) /* handle the messages */ { case WM_CREATE: GetClientRect(hwnd,&rect); //oldRect gets the same value as current rect as to avoid division by 0 and unintended resizing at the beginning oldRect=rect; //Creates the needed switches CreateButtons(hwnd,rect); // Loads the bitmap from resources hBitmap = LoadBitmap(hInst,MAKEINTRESOURCE(LOGO)); GetObject(hBitmap,sizeof(BITMAP),&bitmap); break; case WM_SIZE: GetClientRect(hwnd,&rect); //Resizes all buttons based on the window size MoveWindow(hwndSquareButton,rect.right*3/4,rect.bottom/32,rect.right/8,30,TRUE); MoveWindow(hwndCircleButton,rect.right*7/8,rect.bottom/32,rect.right/8,30,TRUE); MoveWindow(hwndBezierButton,rect.right*3/4,rect.bottom/8,rect.right/8,30,TRUE); //Set the displacement of the drawings inside the window to new , moved coordinates xDisp=(float)rect.right/oldRect.right; yDisp=(float)rect.bottom/oldRect.bottom; oldRect.bottom=rect.bottom; oldRect.right=rect.right; for(int i=0; i<figureCount; i++) { for(int j=0; j<4; j++) { arrayPoints[i][j].x*=xDisp; arrayPoints[i][j].y*=yDisp; } } InvalidateRect(hwnd,NULL,TRUE); break; case WM_COMMAND: //Sets the buttons to active and puts the flags in the needed positions switch(wParam) { case ID_SWITCH_CIRCLE: SendMessage(hwndCircleButton,BM_SETCHECK,1,0); SendMessage(hwndBezierButton,BM_SETCHECK,0,0); SendMessage(hwndSquareButton,BM_SETCHECK,0,0); drawing_bezier=drawing_square=FALSE; drawing_circle=TRUE; break; case ID_SWITCH_SQUARE: SendMessage(hwndCircleButton,BM_SETCHECK,0,0); SendMessage(hwndBezierButton,BM_SETCHECK,0,0); SendMessage(hwndSquareButton,BM_SETCHECK,1,0); drawing_bezier=drawing_circle=FALSE; drawing_square=TRUE; break; case ID_SWITCH_BEZIER: SendMessage(hwndCircleButton,BM_SETCHECK,0,0); SendMessage(hwndBezierButton,BM_SETCHECK,1,0); SendMessage(hwndSquareButton,BM_SETCHECK,0,0); drawing_square=drawing_circle=FALSE; drawing_bezier=TRUE; break; } break; case WM_RBUTTONDOWN: //The setting up of invalidation region GetClientRect(hwnd,&rect); invalidationRect.right=rect.right*3/4-16; invalidationRect.top=rect.top+130; invalidationRect.bottom=rect.bottom-5; invalidationRect.left=rect.right*1/4+16; //The deletion a figure and refreshing the picture figureCount--; if(figureCount<0) figureCount=0; InvalidateRect(hwnd,&invalidationRect,TRUE); break; case WM_MOUSEMOVE: //Exits case in case the mouse is out of the needed area if(!button_pressed_in_area) break; mouse_moving=TRUE; //invalidation GetClientRect(hwnd,&rect); invalidationRect.right=rect.right*3/4-16; invalidationRect.top=rect.top+130; invalidationRect.bottom=rect.bottom-5; invalidationRect.left=rect.right*1/4+16; //Checks if the moving is being done in the drawing area and ends drawing in case it isn't if ((LOWORD(lParam)<rect.right/4+20) || (LOWORD(lParam)>rect.right*3/4-20) || (HIWORD(lParam)<135) || (HIWORD(lParam)>rect.bottom-6)) { SendMessage(hwnd,WM_LBUTTONUP,NULL,lParam) ; break; } hdc=GetDC(hwnd); //Depending on the selected drawing sets the points for the tracing of figures if (drawing_circle) { xFin=LOWORD(lParam); yFin=HIWORD(lParam); } if (drawing_square) { xFin=LOWORD(lParam); yFin=HIWORD(lParam); } if (drawing_bezier && !first_point) { xFin=LOWORD(lParam); yFin=HIWORD(lParam); } else if (drawing_bezier) { xFinSecond=LOWORD(lParam); yFinSecond=HIWORD(lParam); } //Send message to repaint drawing area InvalidateRect(hwnd,&invalidationRect,TRUE); ReleaseDC(hwnd,hdc); break; case WM_LBUTTONDOWN: //Checks if the button clicking is being done in the drawing area and sets focus to main window SetFocus(hwnd); GetClientRect(hwnd,&rect); if ((LOWORD(lParam)<rect.right/4+14) || (LOWORD(lParam)>rect.right*3/4-14) || (HIWORD(lParam)<125) || (HIWORD(lParam)>rect.bottom-6)) break; button_pressed_in_area=TRUE; hdc=GetDC(hwnd); //Gets initial points for the figure being drawn and sets a information value in order to read the right thing from the array afterwards if (drawing_square) { arrayPoints[figureCount][4].x=ID_SWITCH_SQUARE; arrayPoints[figureCount][0].x=LOWORD(lParam); arrayPoints[figureCount][0].y=HIWORD(lParam); } if (drawing_bezier && first_point) { arrayPoints[figureCount][4].x=ID_SWITCH_BEZIER; arrayPoints[figureCount][0].x=LOWORD(lParam); arrayPoints[figureCount][0].y=HIWORD(lParam); first_point=FALSE; } else if (drawing_bezier) { first_point=TRUE; figureCount--; arrayPoints[figureCount][2].x=LOWORD(lParam); arrayPoints[figureCount][2].y=HIWORD(lParam); } if (drawing_circle) { arrayPoints[figureCount][4].x=ID_SWITCH_CIRCLE; arrayPoints[figureCount][0].x=LOWORD(lParam); arrayPoints[figureCount][0].y=HIWORD(lParam); } ReleaseDC(hwnd,hdc); break; case WM_LBUTTONUP: //Makes sure the drawing started inside the canvas if(!button_pressed_in_area) break; mouse_moving=FALSE; //invalidation GetClientRect(hwnd,&rect); invalidationRect.right=rect.right*3/4-16; invalidationRect.top=rect.top+130; invalidationRect.bottom=rect.bottom-5; invalidationRect.left=rect.right*1/4+16; hdc=GetDC(hwnd); //Gets the end points of the figures if (drawing_square) { arrayPoints[figureCount][1].x=LOWORD(lParam); arrayPoints[figureCount][1].y=HIWORD(lParam); } if (drawing_bezier && !first_point) { arrayPoints[figureCount][1].x=LOWORD(lParam); arrayPoints[figureCount][1].y=HIWORD(lParam); } else if (drawing_bezier) { arrayPoints[figureCount][3].x=LOWORD(lParam); arrayPoints[figureCount][3].y=HIWORD(lParam); InvalidateRect(hwnd,&invalidationRect,TRUE); } if (drawing_circle) { arrayPoints[figureCount][1].x=LOWORD(lParam); arrayPoints[figureCount][1].y=HIWORD(lParam); } //Increments nr of figures figureCount++; button_pressed_in_area=FALSE; //The bezier uses 4 points instead of 2 like the others so different actions when invalidating if (!drawing_bezier) { InvalidateRect(hwnd,&invalidationRect,TRUE); } ReleaseDC(hwnd,hdc); break; case WM_KEYDOWN: //invalidation GetClientRect(hwnd,&rect); invalidationRect.right=rect.right*3/4-16; invalidationRect.top=rect.top+130; invalidationRect.bottom=rect.bottom-5; invalidationRect.left=rect.right*1/4+16; //Resizes canvas based on convergence on the line formed by the center point of the canvas and a point of the figure switch(wParam) { case VK_UP: if (resizeCount<0) break; for(int i=0; i<figureCount; i++) { for(int j=0; j<4; j++) { slope=(arrayPoints[i][j].y-(rect.bottom-126)/2)/(float)(arrayPoints[i][j].x-rect.right/2); displacement=arrayPoints[i][j].y-slope*arrayPoints[i][j].x; arrayPoints[i][j].x=(rect.right/2)-(rect.right/2-arrayPoints[i][j].x)*1.1; arrayPoints[i][j].y=roundf(arrayPoints[i][j].x*slope+displacement); } } resizeCount--; break; case VK_DOWN: if(resizeCount>10) break; for(int i=0; i<figureCount; i++) { for(int j=0; j<4; j++) { slope=(arrayPoints[i][j].y-(rect.bottom-126)/2)/(float)(arrayPoints[i][j].x-rect.right/2); displacement=arrayPoints[i][j].y-slope*arrayPoints[i][j].x; arrayPoints[i][j].x=(rect.right/2)-(rect.right/2-arrayPoints[i][j].x)*0.9; arrayPoints[i][j].y=roundf(arrayPoints[i][j].x*slope+displacement); } } resizeCount++; break; } InvalidateRect(hwnd,&invalidationRect,TRUE); break; case WM_PAINT: hdc=BeginPaint(hwnd,&ps); GetClientRect(hwnd,&rect); //Create figures SelectObject(hdc,GetStockObject(NULL_BRUSH)); for (int i=0; i<figureCount; i++) { switch(arrayPoints[i][4].x) { case ID_SWITCH_SQUARE: Rectangle(hdc,arrayPoints[i][0].x,arrayPoints[i][0].y,arrayPoints[i][1].x,arrayPoints[i][1].y); break; case ID_SWITCH_CIRCLE: Ellipse(hdc,arrayPoints[i][0].x,arrayPoints[i][0].y,arrayPoints[i][1].x,arrayPoints[i][1].y); break; case ID_SWITCH_BEZIER: PolyBezier(hdc,arrayPoints[i],4); break; } } //Create traces if (mouse_moving) { if (drawing_circle) { Ellipse(hdc,arrayPoints[figureCount][0].x,arrayPoints[figureCount][0].y,xFin,yFin); } if (drawing_bezier && !first_point) { MoveToEx(hdc,arrayPoints[figureCount][0].x,arrayPoints[figureCount][0].y,NULL); LineTo(hdc,xFin,yFin); } else if (drawing_bezier) { MoveToEx(hdc,arrayPoints[figureCount][0].x,arrayPoints[figureCount][0].y,NULL); LineTo(hdc,xFin,yFin); MoveToEx(hdc,arrayPoints[figureCount][2].x,arrayPoints[figureCount][2].y,NULL); LineTo(hdc,xFinSecond,yFinSecond); } if (drawing_square) { Rectangle(hdc,arrayPoints[figureCount][0].x,arrayPoints[figureCount][0].y,xFin,yFin); } } SelectObject(hdc,GetStockObject(WHITE_BRUSH)); //Create the gradients CreateGradient(hdc,0,0,rect.right/4+10,rect.bottom+1); CreateGradient(hdc,rect.right*3/4-10,0,rect.right+1,rect.bottom+1); //Creates the background for drawing DrawTheWorkingArea(hdc,rect); //Adds the lines to the drawing DrawTheLines(hdc,rect); //Adds figures to the mix DrawGeometry(hdc,rect); //Make bmp hdcMem = CreateCompatibleDC(hdc); SelectObject(hdcMem,hBitmap); BitBlt(hdc,rect.right/4+16,6,185,120,hdcMem,0,0,SRCCOPY); DeleteDC(hdcMem); EndPaint(hwnd,&ps); break; case WM_CTLCOLORSTATIC: SetBkMode((HDC)wParam,TRANSPARENT); return (LRESULT)GetStockObject(NULL_BRUSH); case WM_GETMINMAXINFO: //Setting the minimal size for the window MINMAXINFO *ptMinMax; ptMinMax=(MINMAXINFO*)lParam; ptMinMax->ptMinTrackSize.x=450; ptMinMax->ptMinTrackSize.y=300; break; case WM_DESTROY: PostQuitMessage (0); /* send a WM_QUIT to the message queue */ break; default: /* for messages that we don't deal with */ return DefWindowProc (hwnd, message, wParam, lParam); } return 0; }
HBITMAP KGUISkin::CreateTitleGradient(HDC hDC) { return CreateGradient(hDC, m_Color.ToColor(), m_IncColor.ToColor(), m_DecColor.ToColor(), true); }
PRBool nsSVGGradientFrame::SetupPaintServer(gfxContext *aContext, nsSVGGeometryFrame *aSource, float aGraphicOpacity) { // Get the transform list (if there is one) gfxMatrix patternMatrix = GetGradientTransform(aSource); if (patternMatrix.IsSingular()) return PR_FALSE; PRUint32 nStops = GetStopCount(); // SVG specification says that no stops should be treated like // the corresponding fill or stroke had "none" specified. if (nStops == 0) { aContext->SetColor(gfxRGBA(0, 0, 0, 0)); return PR_TRUE; } patternMatrix.Invert(); nsRefPtr<gfxPattern> gradient = CreateGradient(); if (!gradient || gradient->CairoStatus()) return PR_FALSE; PRUint16 aSpread = GetSpreadMethod(); if (aSpread == nsIDOMSVGGradientElement::SVG_SPREADMETHOD_PAD) gradient->SetExtend(gfxPattern::EXTEND_PAD); else if (aSpread == nsIDOMSVGGradientElement::SVG_SPREADMETHOD_REFLECT) gradient->SetExtend(gfxPattern::EXTEND_REFLECT); else if (aSpread == nsIDOMSVGGradientElement::SVG_SPREADMETHOD_REPEAT) gradient->SetExtend(gfxPattern::EXTEND_REPEAT); gradient->SetMatrix(patternMatrix); // setup stops float lastOffset = 0.0f; for (PRUint32 i = 0; i < nStops; i++) { float offset, stopOpacity; nscolor stopColor; GetStopInformation(i, &offset, &stopColor, &stopOpacity); if (offset < lastOffset) offset = lastOffset; else lastOffset = offset; gradient->AddColorStop(offset, gfxRGBA(NS_GET_R(stopColor)/255.0, NS_GET_G(stopColor)/255.0, NS_GET_B(stopColor)/255.0, NS_GET_A(stopColor)/255.0 * stopOpacity * aGraphicOpacity)); } aContext->SetPattern(gradient); return PR_TRUE; }
HRESULT CSwatchesList::OnDraw(ATL_DRAWINFO& di) { RECT& rc = *(RECT*)di.prcBounds; HDC hDC = di.hdcDraw; if (m_swatches) { Draw3DRect(hDC, m_areaRect.left-1, m_areaRect.top-1, m_areaRect.Width()+2, m_areaRect.Height()+2, RGB(0,0,0), RGB(0,0,0)); long scrollposY; m_vert->get_pos(&scrollposY); if (IntersectClipRect(hDC, m_areaRect.left, m_areaRect.top, m_areaRect.right, m_areaRect.bottom)) { POINT oldOrg; SetViewportOrgEx(hDC, m_areaRect.left, m_areaRect.top - scrollposY, &oldOrg); // For CMYK conversion /* TCHAR colorDirectory[MAX_PATH]; DWORD cbSize = sizeof(colorDirectory); GetColorDirectory(NULL, colorDirectory, &cbSize); HPROFILE hDestProfile = NULL; { TCHAR profilePath[MAX_PATH]; _makepath(profilePath, NULL, colorDirectory, "sRGB Color Space Profile.ICM", NULL); PROFILE profile = {0}; profile.dwType = PROFILE_FILENAME; profile.pProfileData = profilePath; profile.cbDataSize = (_tcslen(profilePath)+1)*sizeof(TCHAR); hDestProfile = OpenColorProfile(&profile, PROFILE_READ, FILE_SHARE_READ, OPEN_EXISTING); ATLASSERT(hDestProfile); } HPROFILE hTargetProfile = NULL; { TCHAR profilePath[MAX_PATH]; _makepath(profilePath, NULL, colorDirectory, targetProfile, NULL); PROFILE profile = {0}; profile.dwType = PROFILE_FILENAME; profile.pProfileData = profilePath; profile.cbDataSize = (_tcslen(profilePath)+1)*sizeof(TCHAR); hTargetProfile = OpenColorProfile(&profile, PROFILE_READ, FILE_SHARE_READ, OPEN_EXISTING); ATLASSERT(hTargetProfile); } LOGCOLORSPACE lcp = {0}; lcp.lcsSignature = LCS_SIGNATURE; lcp.lcsVersion = 0x400; lcp.lcsSize = sizeof(lcp); lcp.lcsCSType = LCS_sRGB; lcp.lcsFilename;// = NULL; // ?? HTRANSFORM hTransform = CreateColorTransform(&lcp, hDestProfile, hTargetProfile, BEST_MODE); ATLASSERT(hTransform); */ // Pattern for drawing ColorType symbols WORD bmdata[8] = { 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, }; HBITMAP hPatBitmap = CreateBitmap(8, 8, 1, 1, bmdata); ATLASSERT(hPatBitmap); HBRUSH hPatBrush = CreatePatternBrush(hPatBitmap); ATLASSERT(hPatBrush); DeleteObject(hPatBitmap); // HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT); LOGFONT lf; GetObject(hFont, sizeof(lf), &lf); lf.lfWeight = FW_BOLD; HFONT hFontSelected = CreateFontIndirect(&lf); HFONT hOldFont = (HFONT)GetCurrentObject(hDC, OBJ_FONT); long nswatches; m_swatches->get_length(&nswatches); int y = 0; for (int i = 0; i < nswatches; i++) { CComPtr<IPDSwatch> swatch; m_swatches->item(i, &swatch); //Rectangle(hDC, itemrect.left, itemrect.top, itemrect.right+1, itemrect.bottom+1); MoveToEx(hDC, 0, y+m_itemHeight, NULL); LineTo(hDC, m_areaRect.Width()+1, y+m_itemHeight); CRect itemrect(0, y+1, m_areaRect.Width(), y+m_itemHeight-1); // itemrect.top += 1; // itemrect.bottom -= 1; bool bSelected = IsSwatchSelected(swatch); if (bSelected) FillSolidRect(hDC, itemrect.left, itemrect.top+1, itemrect.Width(), itemrect.Height()-1, (bSelected)? GetSysColor(COLOR_HIGHLIGHT): GetSysColor(COLOR_WINDOW)); int swatchSize = m_itemHeight-4; int swatchTop = (m_itemHeight-swatchSize)/2; // CRect swatchRect(itemrect.left + 4, itemrect.top+itemrect.Height()/2-8, itemrect.left + 4 + 16, itemrect.top+itemrect.Height()/2-8+16); CRect swatchRect(itemrect.left + 4, itemrect.top+swatchTop, itemrect.left + 4 + swatchSize, itemrect.top+swatchTop+swatchSize); if (bSelected) { SelectObject(hDC, hFontSelected); SetTextColor(hDC, GetSysColor(COLOR_HIGHLIGHTTEXT)); } else { SelectObject(hDC, hFont); SetTextColor(hDC, GetSysColor(COLOR_WINDOWTEXT)); } SetBkMode(hDC, TRANSPARENT); BSTR bname; swatch->get_name(&bname); _bstr_t name = _bstr_t(bname, false); PDSwatchType swatchType; swatch->get_swatchType(&swatchType); CRect trect = itemrect; trect.left = swatchRect.right + 4; trect.right -= 30; if (swatchType == SWATCH_NONE) { FillSolidRect(hDC, &swatchRect, RGB(255, 255, 255)); HPEN hPen = CreatePen(PS_SOLID, 2, RGB(255, 0, 0)); HPEN hOldPen = (HPEN)SelectObject(hDC, hPen); MoveToEx(hDC, swatchRect.left+1, swatchRect.bottom-1, NULL); LineTo(hDC, swatchRect.right-1, swatchRect.top+1); SelectObject(hDC, hOldPen); DeleteObject(hPen); HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, GetStockObject(NULL_BRUSH)); Rectangle(hDC, swatchRect.left, swatchRect.top, swatchRect.right, swatchRect.bottom); SelectObject(hDC, hOldBrush); } else if (swatchType == SWATCH_COLOR || swatchType == SWATCH_TINT) { CComPtr<IPDColor> color; CComQIPtr<IPDSwatchColor> swatchColor; if (swatchType == SWATCH_COLOR) { swatchColor = swatch; swatchColor->get_color(&color); } else { CComQIPtr<IPDSwatchTint> swatchTint = swatch; swatchTint->get_swatchColor(&swatchColor); swatchTint->get_finalColor(&color); CRect trect2 = trect; trect.right -= 28; trect2.left = trect.right; double tint; swatchTint->get_tint(&tint); CUString str; str.Format("%d %%", (int)(tint*100)); DrawText(hDC, str, str.GetLength(), &trect2, DT_SINGLELINE | DT_VCENTER); } PDColorMode colorMode; color->get_colorMode(&colorMode); COLORREF clr; if (colorMode == COLORMODE_RGB) { double red; color->getChannel(0, &red); double green; color->getChannel(1, &green); double blue; color->getChannel(2, &blue); clr = RGB(red, green, blue); } else if (colorMode == COLORMODE_CMYK) { /* if (hTransform) { double cyan; color->getChannel(0, &cyan); double magenta; color->getChannel(1, &magenta); double yellow; color->getChannel(2, &yellow); double black; color->getChannel(3, &black); COLOR incolor; incolor.cmyk.cyan = cyan*65535/255; incolor.cmyk.magenta = magenta*65535/255; incolor.cmyk.yellow = yellow*65535/255; incolor.cmyk.black = black*65535/255; COLOR outcolor; BOOL bSuccess = TranslateColors(hTransform, &incolor, 1, COLOR_CMYK, &outcolor, COLOR_RGB); ATLASSERT(bSuccess); clr = RGB( outcolor.rgb.red*255.0/65535, outcolor.rgb.green*255.0/65535, outcolor.rgb.blue*255.0/65535); } else */ clr = -1; } if (clr != -1) { HBRUSH hBrush = CreateSolidBrush(clr); HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, hBrush); Rectangle(hDC, swatchRect.left, swatchRect.top, swatchRect.right, swatchRect.bottom); SelectObject(hDC, hOldBrush); DeleteObject(hBrush); } { CRect rc(itemrect.right-15, itemrect.top+4, itemrect.right-15+10, itemrect.top+4+10); if (colorMode == COLORMODE_RGB) { Rectangle(hDC, rc.left, rc.top-1, rc.right+1, rc.bottom+1); FillSolidRect(hDC, rc.left+1, rc.top, 3, rc.Height(), RGB(255, 0, 0)); FillSolidRect(hDC, rc.left+4, rc.top, 3, rc.Height(), RGB(0, 255, 0)); FillSolidRect(hDC, rc.left+7, rc.top, 3, rc.Height(), RGB(0, 0, 255)); } else if (colorMode == COLORMODE_CMYK) { // { HBRUSH hBrush = CreateSolidBrush(RGB(255, 0, 255)); HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, hBrush); POINT pts[3] = { rc.left, rc.top, rc.left+rc.Width(), rc.top, rc.left+rc.Width()/2, rc.top+rc.Height()/2, }; Polygon(hDC, pts, 3); SelectObject(hDC, hOldBrush); DeleteObject(hBrush); } // { HBRUSH hBrush = CreateSolidBrush(RGB(255, 255, 0)); HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, hBrush); POINT pts[3] = { rc.right, rc.top, rc.right, rc.top+rc.Height(), rc.right-rc.Width()/2, rc.top+rc.Height()/2, }; Polygon(hDC, pts, 3); SelectObject(hDC, hOldBrush); DeleteObject(hBrush); } // { HBRUSH hBrush = CreateSolidBrush(RGB(0, 0, 0)); HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, hBrush); POINT pts[3] = { rc.left, rc.bottom, rc.left+rc.Width(), rc.bottom, rc.left+rc.Width()/2, rc.bottom-rc.Height()/2, }; Polygon(hDC, pts, 3); SelectObject(hDC, hOldBrush); DeleteObject(hBrush); } // { HBRUSH hBrush = CreateSolidBrush(RGB(0, 255, 255)); HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, hBrush); POINT pts[3] = { rc.left, rc.top, rc.left, rc.top+rc.Height(), rc.left+rc.Width()/2, rc.top+rc.Height()/2, }; Polygon(hDC, pts, 3); SelectObject(hDC, hOldBrush); DeleteObject(hBrush); } } } { CRect rc(m_areaRect.right-28, y+4, m_areaRect.right-28+10, y+4+10); PDColorType colorType; swatchColor->get_colorType(&colorType); int oldBkMode = SetBkMode(hDC, OPAQUE); COLORREF oldTextClr = SetTextColor(hDC, RGB(100,100,100)); COLORREF oldBkClr = SetBkColor(hDC, RGB(255,255,255)); if (colorType == COLORTYPE_PROCESS) { HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, hPatBrush); Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom); SelectObject(hDC, hOldBrush); } else if (colorType == COLORTYPE_SPOT) { Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom); HPEN hPen = CreatePen(PS_SOLID, 1, RGB(120, 120, 120)); HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, hPatBrush); HPEN hOldPen = (HPEN)SelectObject(hDC, hPen); Ellipse(hDC, rc.left+2, rc.top+2, rc.right-2, rc.bottom-2); SelectObject(hDC, hOldBrush); SelectObject(hDC, hOldPen); DeleteObject(hPen); } else ATLASSERT(0); SetBkMode(hDC, oldBkMode); SetTextColor(hDC, oldTextClr); SetBkColor(hDC, oldBkClr); } } else if (swatchType == SWATCH_GRADIENT) { Gdiplus::Graphics graphics(hDC); CComQIPtr<IPDSwatchGradient> swatchGradient = swatch; CComPtr<IPDGradient> gradient; swatchGradient->get_gradient(&gradient); PDGradientType gradientType; gradient->get_type(&gradientType); Gdiplus::Rect rc(swatchRect.left, swatchRect.top, swatchRect.Width(), swatchRect.Height()); CArray<Gdiplus::REAL, Gdiplus::REAL> offsets; CArray<Gdiplus::Color,Gdiplus::Color&> colors; CreateGradient(offsets, colors, gradient); if (gradientType == GRADIENT_LINEAR) { Gdiplus::LinearGradientBrush brush(rc, Gdiplus::Color(0,0,0), Gdiplus::Color(0,0,0), Gdiplus::LinearGradientModeHorizontal); brush.SetInterpolationColors(colors.GetData(), offsets.GetData(), colors.GetSize()); graphics.FillRectangle(&brush, rc); } else if (gradientType == GRADIENT_RADIAL) { Gdiplus::GraphicsPath path; path.AddEllipse(rc); Gdiplus::PathGradientBrush brush(&path); brush.SetInterpolationColors(colors.GetData(), offsets.GetData(), colors.GetSize()); graphics.FillRectangle(&brush, rc); } else ATLASSERT(0); } else if (swatchType == SWATCH_PATTERN) { Gdiplus::Graphics graphics(hDC); CComQIPtr<IPDSwatchPattern> swatchPattern = swatch; CComPtr<IPDObjectGroup> objectGroup; swatchPattern->get_objectGroup(&objectGroup); RectD bbox; objectGroup->getExpandedBBox(&bbox); int width = swatchRect.Width(); int height = (bbox.Height * width/bbox.Width);//+0.5; if (height > swatchRect.Height()) { height = swatchRect.Height(); width = (bbox.Width * height/bbox.Height);//+0.5; } ATLASSERT(width <= bbox.Width); double magnify = width/bbox.Width; int left = (swatchRect.Width()-width)/2; int top = (swatchRect.Height()-height)/2; CComPtr<IPDRenderer> renderer; renderer.CoCreateInstance(CLSID_PDRenderer); if (renderer) { Gdiplus::Bitmap bitmap(width, height); { Gdiplus::Graphics bmgraphics(&bitmap); bmgraphics.FillRectangle(&Gdiplus::SolidBrush(Gdiplus::Color(255, 255, 255)), 0, 0, width, height); // Gdiplus::Graphics& bmgraphics = graphics; // CComQIPtr<IPDObjectTransformable> transformable = objectGroup; // RectD bounds; // transformable->get_bounds(&bounds); // bmgraphics.TranslateTransform(swatchRect.left+left, swatchRect.top+top); bmgraphics.ScaleTransform(magnify, magnify); bmgraphics.TranslateTransform(-bbox.X, -bbox.Y); // bmgraphics.TranslateTransform(-bounds.X, -bounds.Y); renderer->put_magnify(magnify); renderer->put_targetHDC((HDC)&bmgraphics); renderer->RenderObject(objectGroup); } graphics.DrawImage(&bitmap, swatchRect.left+left, swatchRect.top+top); } } DrawText(hDC, name, name.length(), &trect, DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS); y += m_itemHeight; } SelectObject(hDC, hOldFont); DeleteObject(hFontSelected); DeleteObject(hPatBrush); /* if (hTransform) DeleteColorTransform(hTransform); if (hDestProfile) CloseColorProfile(hDestProfile); */ SetViewportOrgEx(hDC, oldOrg.x, oldOrg.y, NULL); } } return S_OK; }
Gdiplus::Brush* GetGdiBrush(IPDBrush* brush, PDBrushType brushType = BRUSH_NONE) { Gdiplus::Brush* pBrush = NULL; if (brushType == BRUSH_NONE) { if (brush) brush->get_brushType(&brushType); } if (brushType == (PDBrushType)tomUndefined) { } else if (brushType == BRUSH_COLOR) { CComPtr<IPDColor> color; brush->get_tintedRGBColor(&color); if (color) { double red; color->getChannel(0, &red); double green; color->getChannel(1, &green); double blue; color->getChannel(2, &blue); pBrush = new Gdiplus::SolidBrush(Gdiplus::Color(255, red, green, blue)); } } else if (brushType == BRUSH_GRADIENT) { CComPtr<IPDGradient> gradient; brush->get_gradient(&gradient); if (gradient) { PDGradientType gradientType; gradient->get_type(&gradientType); double x1; brush->get_x1(&x1); double y1; brush->get_y1(&y1); double x2; brush->get_x2(&x2); double y2; brush->get_y2(&y2); CArray<Gdiplus::REAL, Gdiplus::REAL> offsets; CArray<Gdiplus::Color,Gdiplus::Color&> colors; CreateGradient(offsets, colors, gradient); if (gradientType == GRADIENT_LINEAR) { Gdiplus::LinearGradientBrush* pGradBrush = new Gdiplus::LinearGradientBrush( Gdiplus::Point(x1, y1), Gdiplus::Point(x2, y2), Gdiplus::Color(0,0,0,0), Gdiplus::Color(0,0,0,0)); pGradBrush->SetInterpolationColors(colors.GetData(), offsets.GetData(), colors.GetSize()); pBrush = pGradBrush; } else if (gradientType == GRADIENT_RADIAL) { double dx = x2-x1; double dy = y2-y1; double radius = sqrt(dx*dx+dy*dy); Gdiplus::GraphicsPath path; path.AddEllipse((float)(x1-radius), (float)(y1-radius), (float)(x1+radius), (float)(y1+radius)); Gdiplus::PathGradientBrush* pGradBrush = new Gdiplus::PathGradientBrush(&path); pGradBrush->SetInterpolationColors(colors.GetData(), offsets.GetData(), colors.GetSize()); pBrush = pGradBrush; } else ATLASSERT(0); } } else if (brushType == BRUSH_PATTERN) { CComPtr<IPDSwatch> swatch; brush->get_swatch(&swatch); CComQIPtr<IPDSwatchPattern> swatchPattern = swatch; CComPtr<IPDObjectGroup> objectGroup; swatchPattern->get_objectGroup(&objectGroup); if (objectGroup) { CPDObjectGroup* pGroup = static_cast<CPDObjectGroup*>(objectGroup.p); RectD bounds; pGroup->get_bounds(&bounds); Gdiplus::Bitmap bitmap(bounds.Width, bounds.Height); { Gdiplus::Graphics graphics(&bitmap); //graphics.ScaleTransform(swatchRect.Width()/bounds.Width, swatchRect.Height()/bounds.Height); graphics.TranslateTransform(-bounds.X, -bounds.Y); pGroup->Render(NULL, &graphics, 1, 1/*TODO*/); } Gdiplus::TextureBrush* pTexBrush = new Gdiplus::TextureBrush(&bitmap); pBrush = pTexBrush; } } return pBrush; }