void CDataView::Render2D(CPaintDC& dc) { CRect updateRect = dc.m_ps.rcPaint; int w = updateRect.Width(); int h = updateRect.Height(); int tx = updateRect.left; int ty = updateRect.top; int sx = std::max(0, GetScrollPos(SB_HORZ)) + tx; int sy = std::max(0, GetScrollPos(SB_VERT)) + ty; #if 1 dc.StretchBlt( tx, ty, w, h, m_memDC, sx/m_scale, sy/m_scale, w/m_scale, h/m_scale, SRCCOPY ); #else dc.BitBlt( tx, ty, w, h, m_memDC, sx, sy, SRCCOPY ); #endif }
void CUsbtestDlg::ShowWave(CPaintDC& dc, RECT& rc) { if (!m_buffer) return; CDC memDC; //定义内存DC CBitmap memBitmap; CBitmap* pOldBmp = NULL; memDC.CreateCompatibleDC(&dc); memBitmap.CreateCompatibleBitmap(&dc, rc.right, rc.bottom); pOldBmp = memDC.SelectObject(&memBitmap); memDC.BitBlt(rc.left, rc.top, rc.right, rc.bottom, &dc, 0, 0, SRCCOPY); RECT rect; rect.top = rc.top + 30; rect.bottom = rc.bottom - 30; rect.left = rc.left + 2; rect.right = rc.right - 2; unsigned char* waveData = m_buffer; int len = waveSize; double step = (double)(rect.right - rect.left) / len; double scale = (double)(rect.bottom - rect.top) / (double)255; memDC.MoveTo(rect.left, rect.bottom - waveData[0] * scale); for (int i = 1; i < len; i++) { memDC.LineTo(rect.left + i*step, rect.bottom - waveData[i] * scale); } char str[10]; sprintf_s(str, 10, "%d", curNo); memDC.TextOut(0, 0, CString(str)); dc.BitBlt(rc.left, rc.top, rc.right, rc.bottom, &memDC, 0, 0, SRCCOPY); memDC.SelectObject(pOldBmp); memDC.DeleteDC(); memBitmap.DeleteObject(); }
void CChildView::OnPaint() { CPaintDC *dc; CDC *pdc; CRgn ur; ur.CreateRectRgn(0, 0, 0, 0); GetUpdateRgn(&ur); CRect cr; GetClientRect(&cr); if (theApp.m_bStarted && !theApp.m_map.IsEmpty()) { // pdc = &dc; m_MemDC.SelectClipRgn(&ur); pdc = &m_MemDC; theApp.m_map.DrawMap(*pdc, &cr, &ur); CRect r; // r = cr; ur.GetRgnBox(r); // r.InflateRect(1, 1); if (r.left < 0) r.left = 0; if (r.top < 0) r.top = 0; dc = new CPaintDC(this); // device context for painting dc->BitBlt(r.left, r.top, r.Width(), r.Height(), &m_MemDC, r.left, r.top, SRCCOPY); } else { dc = new CPaintDC(this); // device context for painting if (theApp.m_bStarted) { dc->SetTextAlign(TA_CENTER); CPoint cp = cr.CenterPoint(); CString s; s.Format("There are no maps in '%s'", theApp.m_map.m_sMapsPath); dc->ExtTextOut(cp.x, cp.y - dc->GetOutputTextExtent("W").cy/2, ETO_OPAQUE, &cr, s, NULL); } else { dc->FillSolidRect(cr, 0); } } delete dc; }
void CGraphStatic::DrawData(CPaintDC& dc) { CRect rect; CDC memdc; CBitmap bmp; CBitmap *pOldBMP; CPen DataPen,*pOldPen; if(m_TotalPoint ==0) return; this->GetClientRect(&rect); bmp.CreateCompatibleBitmap(&dc, rect.Width(),rect.Height()); DataPen.CreatePen(PS_SOLID,2, RGB(15, 255, 235)); //Create compatibledc if(!memdc.CreateCompatibleDC(&dc)) { TRACE("Can't create compatibaleDC\n"); ::PostQuitMessage(0); } pOldPen=memdc.SelectObject(&DataPen); pOldBMP = memdc.SelectObject(&bmp); memdc.BitBlt(0, 0, rect.Width(), rect.Height(), &dc, 0, 0, SRCCOPY); int xorg = m_LeftOffset; int yorg = rect.Height()-m_BottomOffset; TRACE("xorg = %d,yorg = %d\n",xorg,yorg); memdc.SetViewportOrg(xorg,yorg); for(int i = 0;i<m_TotalPoint;i++) { this->DrawPixcel(memdc,i,m_pData[i]); } //Draw the average line double x0,y0; x0 = 0; y0 = m_Average; GetPoint(x0,y0); memdc.MoveTo(round(x0),round(y0)); // int old_mode = memdc.SetBkMode(TRANSPARENT); COLORREF old_bkcolor = memdc.SetBkColor(RGB(255,255,0)); COLORREF old_color = memdc.SetTextColor(RGB(255,0,255)); memdc.TextOut(round(x0 - (m_LeftOffset - 10)) ,round(y0 - 12),"Avg.Temp"); // memdc.SetBkMode(old_mode); memdc.SetTextColor(old_color); memdc.SetBkColor(old_bkcolor); // x0 = m_TotalPoint; x0 = m_MaxPoint - 1; y0 = m_Average; GetPoint(x0,y0); memdc.LineTo(round(x0),round(y0)); dc.BitBlt(0,0, rect.Width(), rect.Height(), &memdc, -xorg, -yorg, SRCCOPY); memdc.SelectObject(pOldBMP); memdc.SelectObject(pOldPen); memdc.DeleteDC(); }
void CGraphStatic::DrawGridAndText(CPaintDC& dc) { CDC memdc; //Double buffer bitmap CBitmap bmp; CPen GridPen,*pOldPen; CRect rect; this->GetClientRect(&rect); bmp.CreateCompatibleBitmap(&dc, rect.Width(),rect.Height()); //Create compatibledc if(!memdc.CreateCompatibleDC(&dc)) { TRACE("Can't create compatibaleDC\n"); ::PostQuitMessage(0); } CBitmap *pOldBMP = memdc.SelectObject(&bmp); memdc.FillSolidRect(&rect, RGB(255,255,255)); TRACE(" DataLoggerGraph l=%d,t=%d,r=%d,b=%d\n",rect.left,rect.top,rect.right,rect.bottom); //adjust the offset m_RightOffset += (rect.Width() - m_LeftOffset- m_RightOffset)%m_XGrid; m_BottomOffset += (rect.Height()-m_TopOffset - m_BottomOffset)%m_YGrid; m_xpixel = rect.Width()-m_LeftOffset- m_RightOffset; TRACE("There are %d pixel x size\n",m_xpixel); m_ypixel = rect.Height()-m_TopOffset - m_BottomOffset; TRACE("There are %d pixel y size\n",m_ypixel); GridPen.CreatePen(PS_DASHDOTDOT, 1, RGB(255, 25, 5)); pOldPen=memdc.SelectObject(&GridPen); memdc.Rectangle(&rect); //Draw the horizontal line int x_start = m_LeftOffset; int y_start = m_TopOffset; int x_end = rect.Width() - m_RightOffset; int y_end = y_start; CString str1; CRect rect1; CString csText; int degree ; for( int i = 0;i<m_YGrid + 1;i++) { rect1.left = x_start - 30; rect1.top = y_start - 10; rect1.right = x_start; rect1.bottom = y_start + 30; degree = int(m_Min + ((m_YGrid - i) * 1.0 * (m_Max - m_Min))/m_YGrid); csText.Format("%d",degree); // memdc.DrawText(pFDegree[i],&rect1,DT_LEFT); memdc.DrawText(csText,&rect1,DT_LEFT); memdc.MoveTo(x_start,y_start); memdc.LineTo(x_end,y_end); rect1.left = x_end + 5; rect1.top = y_end - 10; rect1.right = rect1.left + 30; rect1.bottom = rect1.top + 30; // memdc.DrawText(pCDegree[i],&rect1,DT_LEFT); degree = int((degree - 32.0) * 5.0/9.0); csText.Format("%d",degree); memdc.DrawText(csText,&rect1,DT_LEFT); y_start += (rect.Height() - m_TopOffset - m_BottomOffset)/m_YGrid; y_end = y_start; } //Draw the vertical line x_start = m_LeftOffset; y_start = m_TopOffset; x_end = x_start; y_end = rect.Height() - m_BottomOffset; int xaxis_index; for(i = 0;i<m_XGrid + 1;i++) { memdc.MoveTo(x_start,y_start); memdc.LineTo(x_end,y_end); rect1.left = x_end - 5; rect1.top = y_end ; rect1.right = rect1.left + 30; rect1.bottom = rect1.top + 30; xaxis_index = GetXAxisCharsIndex(); memdc.DrawText(XAXIS[xaxis_index][i],&rect1,DT_LEFT); x_start +=(rect.Width() - m_LeftOffset - m_RightOffset)/m_XGrid; x_end = x_start; } // //Biblt the bitmap to orignal dc dc.BitBlt(0, 0, rect.Width(), rect.Height(), &memdc, 0, 0, SRCCOPY); memdc.SelectObject(pOldPen); memdc.SelectObject(pOldBMP); memdc.DeleteDC(); }
void CLeftPanelDlgBar::OnPaint() { CPaintDC dc (this); // device context for painting CDC dcMem; dcMem.CreateCompatibleDC (&dc); CBrush brush (::GetSysColor (COLOR_3DFACE)); CMDIChildWnd* pChild = ((CMDIFrameWnd*) AfxGetMainWnd ())->MDIGetActive (); CRect r; GetClientRect (&r); if (pChild == NULL) { dc.FillRect (&r, &brush); goto __end; } CCdCoverCreator2Doc* pDoc = (CCdCoverCreator2Doc*) pChild->GetActiveDocument (); if (pDoc == NULL) { // look whether the last doc is still valid POSITION pos = AfxGetApp ()->GetFirstDocTemplatePosition (); CDocTemplate* pDocTmpl = AfxGetApp ()->GetNextDocTemplate (pos); bool bIsValid = false; for (pos = pDocTmpl->GetFirstDocPosition (); pos; ) if (pDocTmpl->GetNextDoc (pos) == m_pLastDoc) { bIsValid = true; break; } if (bIsValid) pDoc = m_pLastDoc; else m_pLastDoc = NULL; } else m_pLastDoc = pDoc; if (pDoc == NULL) { dc.FillRect (&r, &brush); goto __end; } CRect rect; GetClientRect (rect); rect.DeflateRect (5, 5, 5, 5); if (pDoc->m_pStyle != NULL) { CCdCoverCreator2View* pView = (CCdCoverCreator2View*) pChild->GetActiveView (); if (pView == NULL) goto __end; int nHeight = (rect.Width () / 5) * 4; CRenderDC rdc (&dc, nHeight, pView->GetDocument ()->m_pStyle); m_y[Cover] = 5; m_y[Back] = m_y[Cover] + rdc.GetHeight (Cover) + 10; m_y[Inlay] = m_y[Back] + rdc.GetHeight (Back) + 10; m_y[Label] = m_y[Inlay] + rdc.GetHeight (Inlay) + 10; m_y[Booklet] = m_y[Label] + rdc.GetHeight (Label) + 10; if (m_bRedraw) { CLabelRenderer renderer (pDoc->m_pTracks, pDoc->m_pDataCDInfo, reinterpret_cast<CBackgroundInfo**> (&(pDoc->m_pBackground)), pDoc->m_listFloatingObjects, *(pDoc->m_pStyle)); for (int i = 0; i < NUM_RENDER_TYPES - 1; i++) { if ((RenderType) i == Booklet) continue; CRect rectBmp (0, 0, rdc.GetWidth ((RenderType) i) + 5, /*nHeight*/(m_y[i + 1] - m_y[i]) + 5); m_Bitmap[i].DeleteObject (); m_Bitmap[i].CreateCompatibleBitmap (&dc, rectBmp.right, rectBmp.bottom); // render dcMem.SelectObject (&m_Bitmap[i]); dcMem.FillRect (rectBmp, &brush); renderer.Render (CRenderDC (&dcMem, nHeight, pDoc->m_pStyle), (RenderType) i, true); } m_bRedraw = false; } // draw the bitmaps int x[] = { (rect.Width () - rdc.GetWidth (Cover)) / 2 + 5, (rect.Width () - rdc.GetWidth (Back)) / 2 + 5, (rect.Width () - rdc.GetWidth (Inlay)) / 2 + 5, (rect.Width () - rdc.GetWidth (Label)) / 2 + 5, (rect.Width () - rdc.GetWidth (Cover)) / 2 + 5 }; dc.SetViewportOrg (x[Booklet], m_y[Booklet]); DrawBooklet (&dc, rdc.GetWidth (Cover), rdc.GetWidth (Cover) / 2, pDoc, pView->GetRenderType ()); dc.SetViewportOrg (0, 0); CBrush* pOldBrush = dc.GetCurrentBrush (); for (int i = 0; i < NUM_RENDER_TYPES; i++) { CRect rectArea (rect.left, m_y[i], rect.right, m_y[i] + ((RenderType) i == Booklet ? rdc.GetWidth (Cover) / 2 : rdc.GetHeight ((RenderType) i))); if ((RenderType) i != Booklet) { dcMem.SelectObject (m_Bitmap[i]); if (pDoc->m_pStyle->m_bHasRenderType[i]) dc.SelectStockObject (WHITE_BRUSH); else { dc.SetTextColor (RGB (0xff, 0xff, 0xff)); dc.SetBkColor (RGB (0x7f, 0x7f, 0x7f)); dc.SelectObject (dc.GetHalftoneBrush ()); } //dc.BitBlt (x[i], m_y[i], rdc.GetWidth ((RenderType) i) + 5, /*nHeight*/(m_y[i + 1] - m_y[i]) + 5, &dcMem, 0, 0, MERGECOPY); dc.BitBlt (x[i], m_y[i], rectArea.Width (), rectArea.Height () + 4, &dcMem, 0, 0, MERGECOPY); } // marker Mark (&dc, rectArea, pView->GetRenderType () != (RenderType) i); } dc.SelectObject (pOldBrush); } __end: #ifdef PEROUTKA_FEDORISIN CBitmap* pOldBmp = (CBitmap*) dcMem.SelectObject (m_bmpLogo); dc.FillSolidRect (0, r.bottom - 32, 148, 32, RGB (0xff, 0xff, 0xff)); dc.BitBlt ((148 - 80) / 2, r.bottom - 32, 80, 32, &dcMem, 0, 0, SRCCOPY); // dcMem.SelectObject (pOldBmp); #endif dcMem.DeleteDC (); brush.DeleteObject (); }
void CDataView::Render1D(CPaintDC& dc) { if (m_values.size() == 0) { return; } const std::vector<double>& values = m_values; const DataSetting1D& dataSetting = dynamic_cast<const DataSetting1D&>(*m_pDataSetting); size_t dataCount = dataSetting.GetTotalBytes() / dataSetting.GetElementSize(); double min = 0; double max = 0; if (dataSetting.viewAuto) { min = *std::min_element(values.begin(), values.begin()+dataCount); max = *std::max_element(values.begin(), values.begin()+dataCount); }else { min = EvalFormula(dataSetting.viewMinFormula); max = EvalFormula(dataSetting.viewMaxFormula); } CRect rect; GetClientRect(rect); rect.DeflateRect(60, 20, 20, 60); if (rect.bottom < 2 || rect.left < 2) return; double xa, xb, ya, yb; SolveSimultaneousLinearEquations<double>( 0, rect.left, dataCount, rect.right, xa, xb ); SolveSimultaneousLinearEquations<double>( min, rect.bottom, max, rect.top, ya, yb ); typedef gl::fixed<8, unsigned char> ComponentT; typedef gl::Color4< gl::ColorBGRA<ComponentT> > ColorT; typedef gl::AdditiveColorBlender<ColorT, NumericT> ColorBlenderT; typedef gl::LineDrawer_Nelson<NumericT, ColorT, ColorBlenderT, SLOPE_CORR_TABLE_SIZE, FILTER_TABLE_SIZE> LineDrawerT; CRect updateRect = dc.m_ps.rcPaint; CRect unionRect; ::UnionRect(unionRect, rect, updateRect); gl::Clipper<NumericT> clipper; clipper.SetClipRegion(unionRect.left, unionRect.top, unionRect.right, unionRect.bottom); gl::Buffer2D<ColorT>* pBuffer = (gl::Buffer2D<ColorT>*) gl::BuildBuffer2DFromBMP(m_bmi.bmiHeader, m_pBits); std::auto_ptr<gl::Buffer2D<ColorT> > autoDeleter(pBuffer); gl::Buffer2D_Fill(*pBuffer, ColorT(0)); LineDrawerT ld(pBuffer); ld.SetFilterTable(g_filterTable); ld.SetSlopeCorrectionTable(g_slopeCorrTable); ColorT col(0.9,0.9,0.9); // frame ld.DrawLine(col, rect.left, rect.top, rect.right, rect.top); ld.DrawLine(col, rect.left, rect.bottom, rect.right, rect.bottom); ld.DrawLine(col, rect.left, rect.top, rect.left, rect.bottom); ld.DrawLine(col, rect.right, rect.top, rect.right, rect.bottom); // axis if (rect.bottom <= yb && yb <= rect.top) { ld.DrawLine(col, xb, yb, xa*dataCount+xb, yb); } // grid // lines double x1 = xb; double y1 = ya*values[0]+yb; for (size_t i=1; i<dataCount; ++i) { double x = xa*i+xb; double y = ya*values[i]+yb; double tx1 = x1; double ty1 = y1; double tx = x; double ty = y; int clipped = clipper.ClipLinePoint(&tx1, &ty1, &tx, &ty); if (clipped != -1) ld.DrawLine(col, tx1, ty1, tx, ty); x1 = x; y1 = y; } dc.BitBlt( updateRect.left, updateRect.top, updateRect.Width(), updateRect.Height(), m_memDC, updateRect.left, updateRect.top, SRCCOPY ); // ruler }
//////////////////////////////////////////////////////////////////////////////// //#include "../../../code/image_proc/image/hsi.hpp" bool CColorAdjustDialog::DrawPreview(CPaintDC& dc, RECT* rect) { if (!m_blit_tile || m_blit_tile->GetPixels() == NULL || rect == NULL) { return false; } ///////////////////////////////////////////////////////// const int width = m_blit_tile->GetWidth(); const int height = m_blit_tile->GetHeight(); int current_width = m_Width; if (current_width > width) current_width = width; int current_height = m_Height; if (current_height > height) current_height = height; BGRA* pixels = (BGRA*) m_blit_tile->GetPixels(); for (int iy = 0; iy < current_height; iy++) { for (int ix = 0; ix < current_width; ix++) { pixels[iy * width + ix].red = m_Pixels[iy * m_Width + ix].red; pixels[iy * width + ix].green = m_Pixels[iy * m_Width + ix].green; pixels[iy * width + ix].blue = m_Pixels[iy * m_Width + ix].blue; pixels[iy * width + ix].alpha = m_Pixels[iy * m_Width + ix].alpha; } } ///////////////////////////////////////////////////////// int red_value = GetRedValue(); int green_value = GetGreenValue(); int blue_value = GetBlueValue(); int alpha_value = GetAlphaValue(); int use_red = ShouldUseRedChannel(); int use_green = ShouldUseGreenChannel(); int use_blue = ShouldUseBlueChannel(); int use_alpha = ShouldUseAlphaChannel(); int method = 0; if (method == 0) { for (int iy = 0; iy < current_height; iy++) { for (int ix = 0; ix < current_width; ix++) { if (use_red) pixels[iy * width + ix].red += red_value; if (use_green) pixels[iy * width + ix].green += green_value; if (use_blue) pixels[iy * width + ix].blue += blue_value; if (use_alpha) pixels[iy * width + ix].alpha += alpha_value; } } } /* else { double h_value = ((double)red_value / (double)255.0) * ((double)2.0 * 3.14); double s_value = ((double)green_value / (double)255.0); double i_value = ((double)blue_value / (double)255.0); for (int iy = 0; iy < current_height; iy++) { for (int ix = 0; ix < current_width; ix++) { double r = pixels[iy * width + ix].red / 255.0; double g = pixels[iy * width + ix].green / 255.0; double b = pixels[iy * width + ix].blue / 255.0; double h, s, i; RGBtoHSI(r, g, b, &h, &s, &i); if (use_red) h += h_value; if (use_green) s += s_value; if (use_blue) i += i_value; if (use_alpha) pixels[iy * width + ix].alpha += alpha_value; HSItoRGB(h, s, i, &r, &g, &b); pixels[iy * width + ix].red = r * 255; pixels[iy * width + ix].green = g * 255; pixels[iy * width + ix].blue = b * 255; } } } */ ///////////////////////////////////////////////////////// dc.BitBlt(rect->left, rect->top, current_width, current_height, CDC::FromHandle(m_blit_tile->GetDC()), 0, 0, SRCCOPY); if (1) { rect->left += current_width; dc.FillRect(rect, CBrush::FromHandle((HBRUSH)GetStockObject(BLACK_BRUSH))); rect->left -= current_width; rect->top += current_height; dc.FillRect(rect, CBrush::FromHandle((HBRUSH)GetStockObject(BLACK_BRUSH))); rect->top -= current_height; } return true; }