// front-end. Create pens, device context and buffer bitmap for global use, copy result to display // The back-end part n the middle has been taken out and moed to PainEvalGraph() static VOID DisplayEvalGraph( HWND hWnd, HDC hDC ) { RECT rcClient; int width; int height; /* Get client area */ GetClientRect( hWnd, &rcClient ); width = rcClient.right - rcClient.left; height = rcClient.bottom - rcClient.top; /* Create or recreate paint box if needed */ if( hbmPB == NULL || width != nWidthPB || height != nHeightPB ) { if( pens[PEN_DOTTED] == NULL ) { pens[PEN_BLACK] = GetStockObject(BLACK_PEN); pens[PEN_DOTTED] = CreatePen( PS_DOT, 0, RGB(0xA0,0xA0,0xA0) ); pens[PEN_BLUEDOTTED] = CreatePen( PS_DOT, 0, RGB(0x00,0x00,0xFF) ); pens[PEN_BOLDWHITE] = CreatePen( PS_SOLID, 2, crWhite ); pens[PEN_BOLDBLACK] = CreatePen( PS_SOLID, 2, crBlack ); hbrHist[0] = CreateBrush( BS_SOLID, crWhite ); hbrHist[1] = CreateBrush( BS_SOLID, crBlack ); hbrHist[2] = CreateBrush( BS_SOLID, GetSysColor( COLOR_3DFACE ) ); // background } if( hdcPB != NULL ) { DeleteDC( hdcPB ); hdcPB = NULL; } if( hbmPB != NULL ) { DeleteObject( hbmPB ); hbmPB = NULL; } hdcPB = CreateCompatibleDC( hDC ); nWidthPB = width; nHeightPB = height; hbmPB = CreateCompatibleBitmap( hDC, nWidthPB, nHeightPB ); SelectObject( hdcPB, hbmPB ); } // back-end painting; calls back front-end primitives for lines, rectangles and text PaintEvalGraph(); SetWindowText(hWnd, MakeEvalTitle(T_("Evaluation Graph"))); /* Copy bitmap into destination DC */ BitBlt( hDC, 0, 0, nWidthPB, nHeightPB, hdcPB, 0, 0, SRCCOPY ); }
void wxGraphicsContext::SetBrush( const wxBrush& brush ) { if ( !brush.Ok() || brush.GetStyle() == wxTRANSPARENT ) SetBrush( wxNullGraphicsBrush ); else SetBrush( CreateBrush( brush ) ); }
// **************************************************************************** // // Function Name: RGpDrawingSurface::SolidPolygon( ) // // Description: Fills and frames a solid polygon // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // void RGpDrawingSurface::SolidPolygon( const RIntPoint* pPoints, YPointCount numPoints ) { PolyHandle hPoly; TpsAssert( ( numPoints < kMaxPoints ), "Too many points." ); if ( numPoints == 2 ) Polyline( pPoints, numPoints ); else { hPoly = CreatePolygon( pPoints, numPoints ); CreateBrush( ); ::FillPoly( hPoly, &qd.black ); CreatePen( ); // offset polygon to simulate windows center pixel stroke if ( m_PenWidthOffset != 0 ) ::OffsetPoly( hPoly, -m_PenWidthOffset, -m_PenWidthOffset ); ::FramePoly( hPoly ); ::DisposeHandle( (Handle)hPoly ); } }
//Draw clock face. static void DrawClockFace(HANDLE hWnd) { HANDLE hDC = NULL; __RECT rect; //Window client area's rect. HANDLE hPen = NULL; HANDLE hBrush = NULL; HANDLE hOldBrush = NULL; HANDLE hOldPen = NULL; int cx,cy,r; hDC = GetClientDC(hWnd); if(!GetWindowRect(hWnd,&rect,GWR_INDICATOR_CLIENT)) { goto __TERMINAL; } //Calculate the circle's center coordinate and radius. cx = (rect.right - rect.left) / 2; cy = (rect.bottom - rect.top) / 2; r = cx > cy ? cy : cx; r -= 10; //Keep 10 pixel space between circle and window frame. //Create the pen and brush object used to draw circle. hPen = CreatePen(0,1,CLK_SCALE_COLOR); if(NULL == hPen) { goto __TERMINAL; } hBrush = CreateBrush(FALSE,CLK_FACE_COLOR); if(NULL == hBrush) { goto __TERMINAL; } hOldPen = SelectPen(hDC,hPen); hOldBrush = SelectBrush(hDC,hBrush); //Draw the clock face circle now. DrawCircle(hDC,cx,cy,r,FALSE); DrawCircle(hDC,cx,cy,r - 1,FALSE); DrawCircle(hDC,cx,cy,r - 2,FALSE); DrawCircle(hDC,cx,cy,r - 3,TRUE); DrawClockScale(hDC,cx,cy,r); //Draw clock's scale. //Restore original pen and brush for this window's DC. SelectPen(hDC,hOldPen); SelectBrush(hDC,hOldBrush); __TERMINAL: if(hPen) { DestroyPen(hPen); } if(hBrush) { DestroyBrush(hBrush); } return; }
//A local helper routine,to draw weeks title. static VOID DrawWeekTitle(HANDLE hWnd) { static TCHAR* Weeks[7] = { "SUN", "MON", "TUES", "WED", "THUR", "FRI", "SAT" }; HANDLE hDC = GetClientDC(hWnd); __RECT rect; HANDLE hBrush,hOldBrush; HANDLE hPen,hOldPen; int txtx,txty; //Text start position. hBrush = CreateBrush(FALSE,COLOR_CYAN); if(NULL == hBrush) { return; } hPen = CreatePen(0,1,COLOR_WHITE); if(NULL == hPen) { DestroyBrush(hBrush); return; } hOldBrush = SelectBrush(hDC,hBrush); hOldPen = SelectPen(hDC,hPen); for(int i = 0; i < 7; i ++) { rect.left = i * DAY_RECT_WIDTH; rect.right = rect.left + DAY_RECT_WIDTH; rect.top = DAY_RECT_HEIGHT; //Reserve the space for year/month/time window. rect.bottom = rect.top + DAY_RECT_HEIGHT; DrawRectangle(hDC,rect); txtx = rect.left + 8; txty = rect.top + 9; TextOut(hDC,txtx,txty,Weeks[i]); } SelectBrush(hDC,hOldBrush); SelectPen(hDC,hOldPen); DestroyPen(hPen); DestroyBrush(hBrush); return; }
// **************************************************************************** // // Function Name: RGpDrawingSurface::SolidFillPolygon( ) // // Description: Fills a solid polygon // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // void RGpDrawingSurface::SolidFillPolygon( const RIntPoint* pPoints, YPointCount numPoints ) { PolyHandle hPoly; TpsAssert( ( numPoints < kMaxPoints ), "Too many points." ); if ( numPoints == 2 ) { Polyline( pPoints, numPoints ); // REVEIW RAH should use fill color } else { hPoly = CreatePolygon( pPoints, numPoints ); CreateBrush( ); ::FillPoly( hPoly, &qd.black ); ::DisposeHandle( (Handle)hPoly ); } }
//Local helper routine to draw all clendar days. static VOID DrawDays(HANDLE hWnd,__CLENDAR_MONTH* pMonth) { __DAY_RECT* pDay = NULL; HANDLE hBrush = NULL,hOldBrush; HANDLE hPen = NULL,hOldPen; HANDLE hTodayBrush; HANDLE hDC = GetClientDC(hWnd); TCHAR daystr[10]; int txtx,txty; int i,j; __RECT rect; if(NULL == pMonth) { return; } hBrush = CreateBrush(FALSE,COLOR_LIGHTORANGE); if(NULL == hBrush) { goto __TERMINAL; } hTodayBrush = CreateBrush(FALSE,COLOR_VIOLET); if(NULL == hTodayBrush) { goto __TERMINAL; } hPen = CreatePen(0,1,COLOR_WHITE); if(NULL == hPen) { goto __TERMINAL; } hOldBrush = SelectBrush(hDC,hBrush); hOldPen = SelectPen(hDC,hPen); //Draw the days now. rect.top = DAY_RECT_HEIGHT * 2; //Reserve space for week title and year/month/time window. rect.left = 0; rect.right = DAY_RECT_WIDTH; rect.bottom = rect.top + DAY_RECT_HEIGHT; txtx = 8; txty = 9; for(i = 0; i < 5; i ++) { for(j = 0; j < 7; j ++) { pDay = &pMonth->DayArray[i * 7 + j]; if(pDay->day >= 32) //Invalid value. { rect.left += DAY_RECT_WIDTH; rect.right += DAY_RECT_WIDTH; continue; } if(pDay->bIsToday) //Draw today. { SelectBrush(hDC,hTodayBrush); DrawRectangle(hDC,rect); txtx = rect.left + 8; txty = rect.top + 9; sprintf(daystr,"%d",pDay->day); TextOut(hDC,txtx,txty,daystr); rect.left += DAY_RECT_WIDTH; rect.right += DAY_RECT_WIDTH; SelectBrush(hDC,hBrush); } else //Draw normal days. { DrawRectangle(hDC,rect); txtx = rect.left + 8; txty = rect.top + 9; sprintf(daystr,"%d",pDay->day); TextOut(hDC,txtx,txty,daystr); rect.left += DAY_RECT_WIDTH; rect.right += DAY_RECT_WIDTH; } } rect.left = 0; rect.right = DAY_RECT_WIDTH; rect.top += DAY_RECT_HEIGHT; rect.bottom += DAY_RECT_HEIGHT; } SelectBrush(hDC,hOldBrush); SelectPen(hDC,hOldPen); __TERMINAL: if(hBrush) { DestroyBrush(hBrush); } if(hPen) { DestroyPen(hPen); } if(hTodayBrush) { DestroyBrush(hTodayBrush); } return; }
//Create a DC object. HANDLE CreateDeviceContext(DWORD dwDCType,HANDLE hDevice,HANDLE hWnd,__REGION* pRegion) { __DC* pDC = NULL; HANDLE hPen = NULL; HANDLE hBrush = NULL; HANDLE hFont = NULL; BOOL bResult = FALSE; __WINDOW* pWnd = (__WINDOW*)hWnd; if(NULL == hDevice) { return NULL; } pDC = (__DC*)KMemAlloc(sizeof(__DC),KMEM_SIZE_TYPE_ANY); if(NULL == pDC) //Can not allocate memory. { goto __TERMINAL; } //Now create pen,font,brush objects. hPen = CreatePen(0,1,COLOR_BLACK); if(NULL == hPen) { goto __TERMINAL; } hFont = CreateFont(DEFAULT_FONT_WIDTH,DEFAULT_FONT_HEIGHT, DEFAULT_FONT_CHSPACE,DEFAULT_FONT_LNSPACE); if(NULL == hFont) { goto __TERMINAL; } hBrush = CreateBrush(FALSE,pWnd->clrBackground); if(NULL == hBrush) { goto __TERMINAL; } //Initialize DC object. pDC->dwDCType = dwDCType; pDC->pBrush = (__BRUSH*)hBrush; pDC->pFont = (__FONT*)hFont; pDC->hWindow = hWnd; pDC->pPen = (__PEN*)hPen; pDC->pRegion = pRegion; if(dwDCType | DC_TYPE_SCREEN) { pDC->pVideo = (__VIDEO*)hDevice; } else { pDC->hOther = hDevice; } bResult = TRUE; __TERMINAL: if(!bResult) { if(pDC) { KMemFree(pDC,KMEM_SIZE_TYPE_ANY,0); } if(hPen) { DestroyPen(hPen); } if(hBrush) { DestroyBrush(hBrush); } if(hFont) { DestroyFont(hFont); } pDC = NULL; } return (HANDLE)pDC; }
//Local helper routine,to draw a bitmap button in a given window or screen. static VOID DrawButtonNormal(HANDLE hDC,__BITMAP_BUTTON* pButton) { HANDLE hOldPen = NULL; HANDLE hOldBrush = NULL; HANDLE hTxtPen = NULL; HANDLE hTxtBkPen = NULL; HANDLE hTxtBrush = NULL; HANDLE hFacePen = NULL; HANDLE hFaceBrush = NULL; __RECT rect; if((NULL == hDC) || (NULL == pButton)) { goto __TERMINAL; } //Create the pen used to draw bitmap button. hTxtPen = CreatePen(0,1,pButton->TxtColor); if(NULL == hTxtPen) { goto __TERMINAL; } hTxtBkPen = CreatePen(0,1,pButton->TxtBackground); if(NULL == hTxtBkPen) { goto __TERMINAL; } hTxtBrush = CreateBrush(FALSE,pButton->TxtBackground); if(NULL == hTxtBrush) { goto __TERMINAL; } hFacePen = CreatePen(0,1,pButton->FaceClr); if(NULL == hFacePen) { goto __TERMINAL; } hFaceBrush = CreateBrush(FALSE,pButton->FaceClr); if(NULL == hFaceBrush) { goto __TERMINAL; } //Draw the button's face. hOldPen = SelectPen(hDC,hFacePen); hOldBrush = SelectBrush(hDC,hFaceBrush); rect.left = 0; rect.right = pButton->cx; rect.top = 0; rect.bottom = pButton->cy - pButton->txtheight; DrawRectangle(hDC,rect); //Draw bitmap here. if(pButton->pBmpData) //Bitmap has been specified. { DrawBitmap(hDC,pButton); } //Draw text background rectangle. SelectPen(hDC,hTxtBkPen); SelectBrush(hDC,hTxtBrush); rect.left = 0; rect.right = pButton->cx; rect.top = pButton->cy - pButton->txtheight; rect.bottom = pButton->cy; DrawRectangle(hDC,rect); //Write button's text.The text's coordinate and length is set and verified //in CreateBitmapButton routine. SelectPen(hDC,hTxtPen); TextOut(hDC,pButton->xtxt,pButton->ytxt,pButton->ButtonText); //Restore the DC's old pen and brush. SelectPen(hDC,hOldPen); SelectBrush(hDC,hOldBrush); __TERMINAL: if(hTxtPen) { DestroyPen(hTxtPen); } if(hTxtBkPen) { DestroyPen(hTxtBkPen); } if(hTxtBrush) { DestroyBrush(hTxtBrush); } if(hFacePen) { DestroyPen(hFacePen); } if(hFaceBrush) { DestroyBrush(hFaceBrush); } return; }
// Make painting tools once when the program starts void PaintCreate() { // Make color brushes Handle.white = CreateBrush(RGB(255, 255, 255)); Handle.black = CreateBrush(RGB( 0, 0, 0)); Handle.blue = CreateBrush(RGB( 0, 102, 204)); Handle.lightblue = CreateBrush(RGB( 51, 153, 255)); Handle.yellow = CreateBrush(RGB(255, 204, 0)); Handle.lightyellow = CreateBrush(RGB(255, 255, 102)); Handle.green = CreateBrush(RGB(102, 204, 51)); Handle.lightgreen = CreateBrush(RGB(153, 255, 102)); Handle.red = CreateBrush(RGB(255, 102, 51)); Handle.lightred = CreateBrush(RGB(255, 153, 102)); Handle.middle = CreateBrush(ColorMix(GetSysColor(COLOR_3DFACE), 1, GetSysColor(COLOR_3DSHADOW), 1)); // Make fonts Handle.arial = CreateFont(L"Arial", 299); // Biggest size that will still have font smoothing // Make a font based on what the system uses in message boxes NONCLIENTMETRICS info; ZeroMemory(&info, sizeof(info)); info.cbSize = sizeof(info); // Must define _WIN32_WINNT=0x0501 for sizeof(info) to return the size SPI_GETNONCLIENTMETRICS expects SystemParametersInfo( SPI_GETNONCLIENTMETRICS, // System parameter to retrieve sizeof(info), // Size of the structure &info, // Structure to fill with information 0); // Not setting a system parameter Handle.font = CreateFontIndirect(&info.lfMenuFont); if (!Handle.font) Report(L"error createfontindirect"); }