void CTeris_1View::DrawXX(CDC *pDC) { CRect rect; GetClientRect(&rect); CDC dcMem; //用于缓冲作图的内存DC dcMem.CreateCompatibleDC(pDC); //依附窗口DC创建兼容内存DC CBitmap bmp; //内存中承载临时图象的位图 bmp.CreateCompatibleBitmap(pDC, rect.Width() , rect.Height() ); //创建兼容位图 dcMem.SelectObject(&bmp); //将位图选择进内存DC dcMem.FillSolidRect(rect, pDC->GetBkColor()); // CTeris_1Doc* pDoc = GetDocument(); CBox *tmp=NULL; tmp=(CBox *)pDoc->box.GetAt(0); tmp->Draw(&dcMem); CString score; score.Format("得分:%d",pDoc->score); dcMem.SelectStockObject(NULL_BRUSH); CPen pen2(PS_SOLID,2,DARKGREEN); dcMem.SelectObject(&pen2); CString s; s.Format("最高记录:%s %d分",TopName,topNum); dcMem.TextOut(465,280,s); dcMem.TextOut(500,300,score); if(xmxxscore>0){ s.Format("%d个 %d分",xmxxscore,xmxxscore*xmxxscore*5); dcMem.TextOut(150,100,s); }else if(xmxxscore<0){ xmxxscore=-xmxxscore; s.Format("剩余%d个 ,额外奖励%d分",xmxxscore,GetXXOverScore(xmxxscore) ); dcMem.TextOut(150,100,s); } dcMem.TextOut(500,500,"By yaolong."); dcMem.TextOut(500,520,"2013/12/28."); //dcMem.TextOut(465,400,"开始、暂停请按ENTER"); s.Format(" 本关要求:%d",(this->XMXXSCORE())); dcMem.TextOut(465,250,s); dcMem.Rectangle(450,0,620,200); dcMem.Rectangle(450,0,620,569); pDC->BitBlt(0,0,rect.Width(),rect.Height(), &dcMem ,0,0,SRCCOPY); dcMem.DeleteDC(); //删除DC bmp.DeleteObject(); //删除位图 }
void CTeris_1View::DrawBox(CDC *pDC) { CRect rect; GetClientRect(&rect); CDC dcMem; //用于缓冲作图的内存DC dcMem.CreateCompatibleDC(pDC); //依附窗口DC创建兼容内存DC CBitmap bmp; //内存中承载临时图象的位图 bmp.CreateCompatibleBitmap(pDC, rect.Width() , rect.Height() ); //创建兼容位图 dcMem.SelectObject(&bmp); //将位图选择进内存DC dcMem.FillSolidRect(rect, pDC->GetBkColor()); // CTeris_1Doc* pDoc = GetDocument(); CBox *tmp=NULL; for(int i=0;i<pDoc->box.GetSize();i++){ tmp=(CBox *)pDoc->box.GetAt(i); tmp->Draw(&dcMem); } CString score; score.Format("得分:%d",pDoc->score); dcMem.SelectStockObject(NULL_BRUSH); CPen pen2(PS_SOLID,2,DARKGREEN); dcMem.SelectObject(&pen2); CString s; s.Format("最高记录:%s %d分",TopName,topNum); dcMem.TextOut(465,280,s); // dcMem.TextOut(500,290,topNum); dcMem.TextOut(500,300,score); dcMem.TextOut(500,500,"By yaolong."); dcMem.TextOut(500,520,"2013/12/21."); dcMem.TextOut(465,400,"开始、暂停请按ENTER"); s.Format(" 用时:%d",(GetDocument()->tick)); dcMem.TextOut(465,250,s); dcMem.Rectangle(450,0,620,200); dcMem.Rectangle(450,0,620,569); if(GetDocument()->mode==CXY) dcMem.Rectangle(0,12*( (CBox *)pDoc->box.GetAt(0) )->LOCAL[0][0].halfSize,WNUMBER*2*( (CBox *)pDoc->box.GetAt(0) )->LOCAL[0][0].halfSize,12*( (CBox *)pDoc->box.GetAt(0) )->LOCAL[0][0].halfSize+1) ; pDC->BitBlt(0,0,rect.Width(),rect.Height(), &dcMem ,0,0,SRCCOPY); dcMem.DeleteDC(); //删除DC bmp.DeleteObject(); //删除位图 }
void ChartWidget::paintEvent(QPaintEvent*) { QPainter painter(this); painter.setWindow(0,0,width(),height()); painter.eraseRect(0,0,width(),height()); QPen pen0(Qt::SolidLine); pen0.setColor(palette().color(QPalette::Window)); painter.setPen(pen0); painter.drawRect(0,0,width(),height()); QPen pen1(Qt::DashDotLine); pen1.setColor(palette().color(QPalette::Mid)); painter.setPen(pen1); painter.drawLine(0,height()/2,width(),height()/2); for (int i=10;i<m_polygon.count();i+=10) { painter.drawLine(m_polygon[i].x(),0,m_polygon[i].x(),height()); } QPen pen2(Qt::SolidLine); pen2.setColor(palette().color(QPalette::Dark)); painter.setPen(pen2); painter.drawEllipse(m_plyIndicator,height()/2-2,3,3); painter.setRenderHints(QPainter::Antialiasing); painter.drawPolyline(m_polygon); }
void Na2DViewer::paintCrosshair(QPainter& painter) { float scale = defaultScale * cameraModel.scale(); QBrush brush1(Qt::black); QBrush brush2(QColor(255, 255, 180)); QPen pen1(brush1, 2.0/scale); QPen pen2(brush2, 1.0/scale); // qDebug() << "paint crosshair"; // Q: Why all this complicated math instead of just [width()/2, height()/2]? // A: This helps debug/document placement of image focus qreal w2 = (pixmap.width() - 1.0) / 2.0; // origin at pixel center, not corner qreal h2 = (pixmap.height() - 1.0) / 2.0; // origin at pixel center, not corner qreal cx = w2 + flip_X * (cameraModel.focus().x() - w2) + 0.5; qreal cy = h2 + flip_Y * (cameraModel.focus().y() - h2) + 0.5; QPointF f(cx, cy); QPointF dx1(4.0 / scale, 0); QPointF dy1(0, 4.0 / scale); QPointF dx2(10.0 / scale, 0); // crosshair size is ten pixels QPointF dy2(0, 10.0 / scale); painter.setPen(pen1); painter.drawLine(f + dx1, f + dx2); painter.drawLine(f - dx1, f - dx2); painter.drawLine(f + dy1, f + dy2); painter.drawLine(f - dy1, f - dy2); painter.setPen(pen2); painter.drawLine(f + dx1, f + dx2); painter.drawLine(f - dx1, f - dx2); painter.drawLine(f + dy1, f + dy2); painter.drawLine(f - dy1, f - dy2); }
void ParupaintColorWheel::paintEvent(QPaintEvent * event) { // QSS won't do much stuff. const qreal max_ratio = (qreal)(this->rect().width() > this->rect().height() ? this->rect().height() : this->rect().width())/2.0; QPoint rp = QPoint(max_ratio - wheel_width/2, max_ratio - wheel_width/2); QRect rr = QRect(this->rect().center() - rp, this->rect().center() + rp); QPainter paint(this); QConicalGradient gradient; gradient.setCenter(this->rect().center()); gradient.setAngle(-90); for(qreal i = 0; i <= 1; i += 0.1){ gradient.setColorAt(i, QColor::fromHslF(1.0 - i, 1, 0.5)); } QPen pen(QBrush(gradient), wheel_width); paint.setPen(pen); paint.drawArc(rr, 0, 360 * 16); qreal ttf = ((qreal(this->value()) / qreal(this->maximum()))*(M_PI*2) + M_PI/2); QPoint pp = this->rect().center() + QPoint(qCos(ttf) * (max_ratio), qSin(ttf) * (max_ratio)); QPen pen2(Qt::black); pen2.setWidth(2); paint.setPen(pen2); paint.drawLine(this->rect().center(), pp); // this->QDial::paintEvent(event); }
void SpinScanPolarPlot::configChanged(qint32) { setCanvasBackground(GColor(CTRAINPLOTBACKGROUND)); QColor col = GColor(CSPINSCANRIGHT); col.setAlpha(120); QBrush brush = QBrush(col); QPen pen(col); pen.setWidth(4); // thicker pen rightCurve->setBrush(Qt::NoBrush); rightCurve->setPen(pen); rightCurve->setStyle(QwtPlotCurve::Lines); rightCurve->setData(rightSpinScanPolarData); QColor col2 = GColor(CSPINSCANLEFT); col2.setAlpha(120); QBrush brush2 = QBrush(col2); QPen pen2(col2); pen2.setWidth(4); // thicker pen leftCurve->setBrush(Qt::NoBrush); leftCurve->setPen(pen2); leftCurve->setStyle(QwtPlotCurve::Lines); leftCurve->setData(leftSpinScanPolarData); }
void GEllipse::draw(CDC* dc) { CPen pen(this->getPattern(), this->getThick(), this->getLineColor()); dc->SelectObject(&pen); CBrush brush; brush.CreateHatchBrush(this->getFillPattern(), this->getFillColor()); dc->SelectObject(&brush); // 처음에 색이 NULL 이면 투명으로 if (this->getFillColor() == NULL) dc->SelectStockObject(NULL_BRUSH); // 원 그리기는 여기서부터 dc->MoveTo(getStartX(), getStartY()); dc->Ellipse(this->getStartX(), this->getStartY(), GetEnd().x, GetEnd().y); if (this->getSelected() == TRUE){ CPen pen2(PS_SOLID, 0, RGB(0, 0, 0)); dc->SelectObject(&pen2); CBrush brush2(RGB(255, 255, 255)); dc->SelectObject(&brush2); m_selectedRect[0] = new CRect(this->getStartX() - 5, this->getStartY() - 5, this->getStartX() + 5, this->getStartY() + 5); m_selectedRect[1] = new CRect(this->getEndX() - 5, this->getStartY() - 5, this->getEndX() + 5, this->getStartY() + 5); m_selectedRect[2] = new CRect(this->getStartX() - 5, this->getEndY() - 5, this->getStartX() + 5, this->getEndY() + 5); m_selectedRect[3] = new CRect(this->getEndX() - 5, this->getEndY() - 5, this->getEndX() + 5, this->getEndY() + 5); // 메모리 누수의 위험 있음. 수정바람! dc->Rectangle(m_selectedRect[0]); dc->Rectangle(m_selectedRect[1]); dc->Rectangle(m_selectedRect[2]); dc->Rectangle(m_selectedRect[3]); } }
void IndicatorItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { painter->setRenderHint(QPainter::Antialiasing); QPen pen(color); pen.setWidthF(width); int baseX = qMin(start.x(), finish.x()); int baseY = qMin(start.y(), finish.y()); QLinearGradient linearGrad(start - QPoint(baseX, baseY), finish - QPoint(baseX, baseY)); QColor start_color(255, 255, 255, 0); linearGrad.setColorAt(0, start_color); linearGrad.setColorAt(1, color.lighter()); QBrush brush(linearGrad); pen.setBrush(brush); painter->setPen(pen); painter->drawLine(mapFromScene(start), mapFromScene(finish)); QPen pen2(QColor(200, 200, 200, 30)); pen2.setWidth(6); painter->setPen(pen2); painter->drawLine(mapFromScene(start), mapFromScene(finish)); }
void CPropertyGridCheckProperty::OnDrawValue(CDC* pDC, CRect rect) { CPen pen(PS_SOLID,1,RGB(28,81,128)); CPen *pOldPen=(CPen*)pDC->SelectObject(&pen); CRect rc=rect; rc.left+=3; rc.right=rc.left+rc.Height()-4; rc.bottom-=2; rc.top+=3; pDC->Rectangle(rc); if(m_bChecked) { CPen pen2(PS_SOLID,2,RGB(33,161,33)); pDC->SelectObject(&pen2); CPoint pt1,pt2,pt3; pt1.x=rc.left+2; pt1.y=rc.top+rc.Height()*3/8; pt2.x=rc.left+rc.Width()*5/12; pt2.y=rc.top+rc.Height()*4/5-1; pt3.x=rc.right-2; pt3.y=rc.top+rc.Height()/4-1; pDC->MoveTo(pt1); pDC->LineTo(pt2); pDC->LineTo(pt3); } pDC->SelectObject(pOldPen); }
void MainWindow::paintEvent(QPaintEvent *) { int nelem = applist.count(); int cols = nelem / ROWS + 1; QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); QSize sz = sizeHint(); painter.fillRect(QRect(0, 0, sz.width(), sz.height()), QBrush(QColor(255, 20, 20))); int i = 0; int j = 0; for (; i < nelem; i++, j++) { if (j >= ROWS) j = 0; QIcon icon = applist[i].app_icon_; int sz = 64 ; if (active_index_ == i) sz -= animation_id_ * 3; QPixmap pixmap = icon.pixmap(QSize(sz, sz), QIcon::Normal, QIcon::On); painter.drawPixmap(QPoint(MARGIN * 2 + (64 - sz) / 2 + (i / ROWS) * 64, MARGIN *2 + j * 64 + TOP + (64 - sz) / 2), pixmap); } // vertical bars QPen pen1(Qt::black); painter.setPen(pen1); for (i = 0; i < cols; i++) { painter.drawLine(MARGIN * 2 + i * 64 + 21, MARGIN * 2 + TOP, MARGIN * 2 + i * 64 + 21, MARGIN * 2 + ROWS * 64 + TOP); painter.drawLine(MARGIN * 2 + i * 64 + 43, MARGIN * 2 + TOP, MARGIN * 2 + i * 64 + 43, MARGIN * 2 + ROWS * 64 + TOP); painter.drawLine(MARGIN * 2 + i * 64 + 64, MARGIN * 2 + TOP, MARGIN * 2 + i * 64 + 64, MARGIN * 2 + ROWS * 64 + TOP); } // horizontal bars for (i = 0; i < ROWS - 1; i++) { painter.drawLine(MARGIN * 2, MARGIN * 2 + 64 * (i + 1) - 1 + TOP, MARGIN * 2 + 64 * cols, MARGIN * 2 + 64 * (i + 1) - 1 + TOP); } // close button painter.fillRect(QRect(MARGIN * 2 + cols * 64 - 8, 8, 12, 3), QBrush(Qt::white)); painter.setFont(QFont("Sans", TOP, QFont::Normal)); QPen pen2(Qt::white); painter.setPen(pen2); painter.drawText(MARGIN * 2, TOP + MARGIN / 2, "Firetools"); if (animation_id_ > 0) { animation_id_--; QTimer::singleShot(ADELAY, this, SLOT(update())); } }
void CFileDlg::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: 在此处添加消息处理程序代码 // 不为绘图消息调用 CDialog::OnPaint() CRect rect; GetClientRect(rect); // dc.FillSolidRect(rect,RGB(255,255,255)); CClientDC aDC(this); //CClientDC的构造函数需要一个参数,这个参数是指向绘图窗口的指针,我们用this指针就可以了 CPoint startPoint; CPoint endPoint; startPoint.x = -1; startPoint.y = 38; endPoint.x = rect.Width()+1; endPoint.y = 38; COLORREF m_Color(RGB(160,160,255)); CPen pen(PS_SOLID,1,m_Color); ////建立一个画笔类对象,构造时设置画笔属性 aDC.SelectObject(&pen); aDC.MoveTo(startPoint); aDC.LineTo(endPoint); startPoint.x = -1; startPoint.y = 40; endPoint.x = rect.Width()+1; endPoint.y = 40; COLORREF m_Color3(RGB(255,255,255)); CPen pen3(PS_SOLID,2,m_Color3); ////建立一个画笔类对象,构造时设置画笔属性 aDC.SelectObject(&pen3); aDC.MoveTo(startPoint); aDC.LineTo(endPoint); startPoint.x = 218; startPoint.y = 38; endPoint.x = 218; endPoint.y = rect.Height()+2; COLORREF m_Color2(RGB(190,190,190)); CPen pen2(PS_SOLID,1,m_Color2); aDC.SelectObject(&pen2); aDC.MoveTo(startPoint); aDC.LineTo(endPoint); }
void CttView::LineCai(const CPoint &x, const CPoint &y){ int c[2][4]; int cnum[2]; CDC* pDC = GetWindowDC(); CPen pen1(0, 0, RGB(255, 0, 0)); CPen pen2(0, 3, RGB(0, 0, 0)); CPen pen3(0, 2, RGB(0, 0, 0)); GetC(c[0],cnum[0],x); GetC(c[1],cnum[1],y); if (cnum[0] & cnum[1]){ pDC->SelectObject(&pen1); pDC->MoveTo(x); pDC->LineTo(y); return; } if ((cnum[0] | cnum[1])==0){ pDC->SelectObject(&pen2); pDC->MoveTo(x); pDC->LineTo(y); return; } pDC->SelectObject(&pen1); pDC->MoveTo(x); pDC->LineTo(y); CPoint a[2]; int an = 0; if (c[0][0] != c[1][0])//与下边有交 { int jx = x.x + (1.0*m_d - x.y) / (y.y - x.y) *(y.x - x.x); if (jx > m_l && jx < m_r) a[an++] = CPoint(jx, m_d); } if (c[0][1] != c[1][1])//与上边有交 { int jx = x.x + (1.0*m_u - x.y) / (y.y - x.y) *(y.x - x.x); if (jx > m_l && jx < m_r) a[an++] = CPoint(jx, m_u); } if (c[0][2] != c[1][2])//与右边有交 { int jy = x.y + (1.0*m_r - x.x) / (y.x - x.x) *(y.y - x.y); if (jy < m_d && jy > m_u) a[an++] = CPoint(m_r, jy); } if (c[0][3] != c[1][3])//与左边有交 { int jy = x.y + (1.0*m_l - x.x) / (y.x - x.x) *(y.y - x.y); if (jy < m_d && jy > m_u) a[an++] = CPoint(m_l, jy); } if (an == 1){ if (cnum[0] == 0)a[an++] = x; else a[an++] = y; } pDC->SelectObject(&pen2); pDC->MoveTo(a[0]); pDC->LineTo(a[1]); }
void CFreqDial::drawDial() { wxMemoryDC dc; dc.SelectObject(*m_bitmap); #if defined(__WXMSW__) int major, minor; ::wxGetOsVersion(&major, &minor); wxColour bgColour; if (major >= 6) bgColour = wxColour(0xF0, 0xF0, 0xF0); // Windows Vista and newer else if (major == 5 && minor >= 1) bgColour = wxColour(0xEC, 0xE9, 0xD8); // Windows XP else bgColour = wxColour(0xD4, 0xD0, 0xC8); // Windows 2000 and earlier #elif defined(__WXGTK__) wxColour bgColour(0xF0, 0xF1, 0xF2); // wxColour bgColour(0xED, 0xE9, 0xE3); #elif defined(__WXMAC__) wxColour bgColour(0xF0, 0xF0, 0xF0); #else #error "Unknown platform" #endif wxBrush brush0(bgColour); wxPen pen0(bgColour); dc.SetPen(pen0); dc.SetBrush(brush0); dc.DrawRectangle(0, 0, m_width, m_height); int middleX = m_width / 2; int middleY = m_height / 2; dc.SetBrush(*wxLIGHT_GREY_BRUSH); wxPen pen1(*wxBLACK, 2, wxSOLID); dc.SetPen(pen1); dc.DrawCircle(middleX, middleY, (m_width - 2) / 2); int x = m_width / 2 - int(double(m_width / 2 - 25) * ::sin(m_angle * (M_PI / 180.0)) + 0.5); int y = m_height / 2 + int(double(m_height / 2 - 25) * ::cos(m_angle * (M_PI / 180.0)) + 0.5); dc.SetBrush(*wxBLACK_BRUSH); wxPen pen2(*wxWHITE, 2, wxSOLID); dc.SetPen(pen2); dc.DrawCircle(x, y, 20); dc.SelectObject(wxNullBitmap); wxClientDC clientDC(this); show(clientDC); }
void CLrcMask::DrawBkMask() { HDC hTempDc = GetDC(m_hWnd); HDC hMenDc = CreateCompatibleDC(hTempDc); DuiLib::CDuiRect rc; GetClientRect(&rc); HBITMAP hbmp; BITMAPINFO bitmapinfo; bitmapinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bitmapinfo.bmiHeader.biBitCount = 32; bitmapinfo.bmiHeader.biHeight = rc.GetHeight(); bitmapinfo.bmiHeader.biWidth = rc.GetWidth(); bitmapinfo.bmiHeader.biPlanes = 1; bitmapinfo.bmiHeader.biCompression=BI_RGB; bitmapinfo.bmiHeader.biXPelsPerMeter=0; bitmapinfo.bmiHeader.biYPelsPerMeter=0; bitmapinfo.bmiHeader.biClrUsed=0; bitmapinfo.bmiHeader.biClrImportant=0; bitmapinfo.bmiHeader.biSizeImage = bitmapinfo.bmiHeader.biWidth * bitmapinfo.bmiHeader.biHeight * bitmapinfo.bmiHeader.biBitCount / 8; hbmp = CreateDIBSection(hMenDc,&bitmapinfo,0,NULL,0,0); SelectBitmap(hMenDc,hbmp); Graphics graphics(hMenDc); graphics.SetSmoothingMode(SmoothingModeAntiAlias); graphics.SetInterpolationMode(InterpolationModeHighQualityBicubic); SolidBrush brush(Color(50,200,200,200)); Pen pen1(Color(155,223,223,223)); Pen pen2(Color(55,223,223,223)); LPRECT lpRect = &rc; RectF rect((Gdiplus::REAL)lpRect->left,(Gdiplus::REAL)lpRect->top,(Gdiplus::REAL)(lpRect->right-lpRect->left),(Gdiplus::REAL)(lpRect->bottom-lpRect->top)); graphics.FillRectangle(&brush,rect); graphics.DrawRectangle(&pen1,rect.GetLeft()+2,rect.GetTop()+2,rect.Width - 4,rect.Height -4); graphics.DrawRectangle(&pen2,rect.GetLeft()+1,rect.GetTop()+1,rect.Width - 2,rect.Height -2); DuiLib::CDuiRect rtWnd; GetWindowRect(&rtWnd); DuiLib::CPoint dstPt(0,0); DuiLib::CPoint winPt(rtWnd.left,rtWnd.top); DuiLib::CSize size(rc.GetWidth(),rc.GetHeight()); BLENDFUNCTION blend = {AC_SRC_OVER,0,255,AC_SRC_ALPHA}; BOOL bret = ::UpdateLayeredWindow(m_hWnd,hTempDc,&winPt,&size,hMenDc,&dstPt,0,&blend,ULW_ALPHA); DeleteDC(hMenDc); ReleaseDC(m_hWnd,hTempDc); // assert(bret); }
void GameWidget::paintEvent(QPaintEvent *e) { QPainter p(this); if (m_bShowSoser) { p.drawPixmap(m_soserX, 0, m_soser); } for(TShips::const_iterator sit = m_ships.constBegin(); sit != m_ships.constEnd(); ++sit) { p.drawPixmap(sit->x, sit->y, *sit->pix); } QRadialGradient grad1(0, 0, 7); grad1.setColorAt(1, QColor(0,0,0)); grad1.setColorAt(0, QColor(255,255,255)); QPen pen1(QColor(0,0,0)); QRadialGradient grad2(0, 0, 7); grad2.setColorAt(1, QColor(255,0,0)); grad2.setColorAt(0, QColor(255,200,200)); QPen pen2(QColor(255,0,0)); p.setPen(pen1); p.setBrush(QBrush(grad1)); int lastL = 1; for(TShots::const_iterator it = m_shots.constBegin(); it != m_shots.constEnd(); ++it) { int x = it->x, y = it->y, l = it->level; if (l != lastL) { p.setPen((l==1)?pen1:pen2); p.setBrush((l==1)?grad1:grad2); lastL = l; } p.setBrushOrigin(x, y); p.drawEllipse(x - 7, y - 7, 14, 14); } p.drawPixmap(m_gunX-32, m_gunY, PicBucket::instance().getPic(1, 2).pixmap); m_shotspreg = QRegion(); if (m_lives == 0) { p.setPen(QPen(Qt::NoPen)); p.setBrush(QBrush(QColor(255,255,255,188))); p.drawRect(0, 0, sizeX, sizeY); QLabel::paintEvent(e); return; } }
//绘制K线图 void CHistoryView::DrawLineOfK(CDC *pDC) { CHistoryDoc* pHistoryDoc = (CHistoryDoc*)GetDocument(); int nSel = ( (CHistoryFrame*)GetParentFrame() )->GetSliderCtrlPos(); int nCount = pHistoryDoc->m_arrayHistoryInfo.GetSize(); double dbLeft = m_rectMid.left;//X起始位置 double dbBottom = m_rectMid.bottom + m_nPenWidth;//Y起始位置 CPen pen1( PS_SOLID,m_nPenWidth / 2,RGB(255,0,0) ); CPen pen2( PS_SOLID,m_nPenWidth / 2,RGB(0,255,0) ); CPen* pOldPen; for(int nI = 0;nI < m_nStockNumPerPage;nI++) { double dbHiPrice = pHistoryDoc->m_arrayHistoryInfo[nI + nSel]->m_dbHiPrice;//当日最高价 double dbLowPrice = pHistoryDoc->m_arrayHistoryInfo[nI + nSel]->m_dbLowPrice;//当日最低价 double dbOpenPrice = pHistoryDoc->m_arrayHistoryInfo[nI + nSel]->m_dbOpenPrice;//当日开盘价 double dbClosePrice = pHistoryDoc->m_arrayHistoryInfo[nI + nSel]->m_dbClosePrice;//当日收盘价 double dbLowestPrice = pHistoryDoc->m_dbLowPrice;//历史最低价 //绘制矩形 dbLeft += m_dbXStep; CRect rect; rect.left = (int)dbLeft; rect.right = rect.left + int(m_dbXStep / 2); if(dbClosePrice >= dbOpenPrice)//收盘价高于开盘价 { rect.top = int( (dbClosePrice - dbLowestPrice) * m_dbYPriceUnit + dbBottom ); rect.bottom = int( (dbOpenPrice - dbLowestPrice) * m_dbYPriceUnit + dbBottom ); CPen pen( PS_SOLID,m_nPenWidth / 2,RGB(255,0,0) ); pOldPen = pDC->SelectObject(&pen1); pDC->Rectangle(&rect); } else//收盘价低于开盘价 { rect.top = int( (dbOpenPrice - dbLowestPrice) * m_dbYPriceUnit + dbBottom ); rect.bottom = int( (dbClosePrice - dbLowestPrice) * m_dbYPriceUnit + dbBottom ); CBrush brush( RGB(0,255,0) ); pDC->FillRect(&rect,&brush); pOldPen = pDC->SelectObject(&pen2); } //绘制直线 pDC->MoveTo( int(dbLeft + m_dbXStep / 4),rect.top); pDC->LineTo( int(dbLeft + m_dbXStep / 4),int( (dbHiPrice - dbLowestPrice) * m_dbYPriceUnit + dbBottom ) ); pDC->MoveTo( int(dbLeft + m_dbXStep / 4),rect.bottom); pDC->LineTo( int(dbLeft + m_dbXStep / 4),int( (dbLowPrice - dbLowestPrice) * m_dbYPriceUnit + dbBottom ) ); pDC->SelectObject(pOldPen); } }
void Viewport::drawOverlay(QPainter *painter) { painter->save(); QPolygonF poly = modelview.map(overlayPoints); QPen pen(QColor(0, 0, 0, 127)); pen.setWidth(5); painter->setPen(pen); painter->drawPolyline(poly); QPen pen2(Qt::yellow); pen2.setWidth(2); painter->setPen(pen2); painter->drawPolyline(poly); painter->restore(); }
void GraphicsScene::setupScene() { ballCollection.append(ball); ballCollection.append(ballRouge); ballCollection.append(ballJaune); ballCollection.append(ballVerte); ballCollection.append(ballDefault); ballDefault->setStop(false); QPen pen2(Qt::white,1,Qt::SolidLine); QRectF rect(0,10,976,652); addRect(rect,pen2); prisme->setPos( width()/2-prisme->getPixmap()->width()/2, height()/2-prisme->getPixmap()->height()/2); addItem(prisme); //prismeForme->setPen(QPen(QBrush(QColor("red")),2,Qt::SolidLine)); QPolygonF polygon; polygon << QPointF( width()/2, height()/2-prisme->getPixmap()->height()/2) << QPointF( width()/2-prisme->getPixmap()->width()/2, this->height()/2+prisme->getPixmap()->height()/2)<<QPointF(this->width()/2+prisme->getPixmap()->width()/2,this->height()/2+prisme->getPixmap()->height()/2); prismeForme->setPolygon(polygon); addItem(prismeForme); barPlayer->setPos(-barPlayer->getPixmap()->width()/2,( height()/2)-(barPlayer->getPixmap()->height()/2)); addItem(barPlayer); barIA->setPos( width()-barIA->getPixmap()->width()/2,( height()/2)-(barIA->getPixmap()->height()/2)); addItem(barIA); scoreManager->getScoreView2()->setPos(670,560); addItem(scoreManager->getScoreView2()); scoreManager->getScoreView1()->setPos(210,560); addItem(scoreManager->getScoreView1()); initBallBlanche(); timer = new QTimer( this ); timer->setInterval( 20 ); timer->start(); connect( timer, SIGNAL(timeout()), this, SLOT(actualiserScene()) ); timer2 = new QTimer(this); timer2->setInterval(1000); timer2->start(); connect( timer2, SIGNAL(timeout()), this, SLOT(refreshLine()) ); connect( barPlayer, SIGNAL(inactivite()), this, SLOT(stopScene()) ); connect( this, SIGNAL(finPartie()), this, SLOT(stopScene()) ); }
MapEditor::MapEditor(QGraphicsScene* scene) : scene_(scene) { copypaste_items_.clear(); selection_stage_ = 0; first_selection_x_ = 0; first_selection_y_ = 0; second_selection_x_ = 0; second_selection_y_ = 0; QPolygonF p; p.push_back(QPointF(0.0, 0.0)); p.push_back(QPointF(0.0, 32.0)); p.push_back(QPointF(32.0, 32.0)); p.push_back(QPointF(32.0, 0.0)); QPen pen(QColor(200, 0, 0)); QBrush brush(QColor(100, 0, 100, 100)); pointer_.image = scene->addPolygon(p, pen, brush); pointer_.image->setZValue(100); QPolygonF p2; p2.push_back(QPointF(0.0, 0.0)); p2.push_back(QPointF(0.0, 10 * 32.0)); p2.push_back(QPointF(10 * 32.0, 10 * 32.0)); p2.push_back(QPointF(10 * 32.0, 0.0)); QPen pen2(QColor(0, 100, 200)); pen2.setWidth(2); border_image_ = scene->addPolygon(p2, pen2); border_image_->setZValue(99); }
void CTimeAxis::drawTimePoint(CDC* pDC, int idxYY, int idxLrc/*, COLORREF clr*/) { if (pDC == NULL) return; if (m_pSyr == NULL) return; int num = m_pSyr->getYYerCount(); if (num < 1) return; if (idxYY < 0 || idxYY >= num) return; int numLrc = m_pSyr->getYYerLrcsCount(idxYY); if (numLrc < 1) return; if (idxLrc < 0 || idxLrc >= numLrc) return; int time = m_pSyr->getYYerLrcTime(idxYY, idxLrc); if (time < m_minTime || time > m_maxTime) return; CRect rect; this->GetWindowRect(&rect); ScreenToClient(&rect); rect.top += TIME_BREV_H; // int dy = rect.Height() / (num + 1); int x = rect.Width() * (time - m_minTime) / (m_maxTime - m_minTime) + rect.left; int y = rect.Height() * (idxYY + 1) / (num + 1) + rect.top; CPen *pOldPen = NULL; CPen pen1(PS_SOLID, 1, RGB(0, 255, 255)); CPen pen2(PS_SOLID, 1, RGB(255, 0, 255)); int state = m_pSyr->getYYerLrcState(idxYY, idxLrc); if (state == 0) { pOldPen = pDC->SelectObject(&pen1); } else if (state == 1) { pOldPen = pDC->SelectObject(&pen2); } int l = x - 2; int r = x + 2; int t = y - 5; int b = y + 5; if (l < rect.left) l = rect.left; if (r > rect.right-1) r = rect.right-1; if (t < rect.top+1) t = rect.top+1; if (b > rect.bottom-1) b = rect.bottom-1; pDC->MoveTo(l, t); pDC->LineTo(r, t); pDC->LineTo(r, b); pDC->LineTo(l, b); pDC->LineTo(l, t-1); t = rect.top - TIME_BREV_H + 3; b = t + 8; pDC->MoveTo(x, t); pDC->LineTo(x, b); pDC->SelectObject(pOldPen); }
void CMFCView::OnDraw(CDC* pDC) { CMFCDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); CRect r; GetClientRect(&r); // array of font name CString font[4]={"Arial","Tahoma","Times New Roman", "Consolas"}; CBrush brush; // init brush.CreateSolidBrush(RGB(255,0,0)); // red brush CBrush *pTempBrush = NULL; CBrush origBrush; pTempBrush = (CBrush*) pDC->SelectObject(&brush); // save original brush origBrush.FromHandle((HBRUSH)pTempBrush); // paint upper left corner with red brush pDC->Rectangle(0,0,r.Width()/2, r.Height()/2); try { CBrush brush2(RGB(rand()%255,rand()%255,rand()%255)); CBrush brush3(RGB(rand()%255,rand()%255,rand()%255)); CBrush brush4(RGB(rand()%255,rand()%255,rand()%255)); pTempBrush = (CBrush*)pDC->SelectObject(&brush2); // Paint upper right corner with red brush. pDC->Rectangle(r.Width() / 2, 0, r.Width(), r.Height() / 2); pTempBrush = (CBrush*)pDC->SelectObject(&brush3); // Paint lower left corner with green hatched brush. pDC->Rectangle(0, r.Height() / 2, r.Width() / 2, r.Height()); pTempBrush = (CBrush*)pDC->SelectObject(&brush4); // Paint lower right corner with resource brush. pDC->Rectangle(r.Width() / 2, r.Height() / 2, r.Width(), r.Height()); } catch(CResourceException* e) { e->ReportError(); e->Delete(); } pDC->SelectObject(&origBrush); // set font for every times we create new single view CFont *oldf, f; // select a random font in font array. f.CreateFont(rand()%80, rand()%30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, font[rand()%4]); oldf= pDC->SelectObject(&f); pDC->SetTextAlign(TA_CENTER); // align text to the center of the screen pDC->SetTextColor(RGB(rand()%255,rand()%255,rand()%255)); pDC->TextOut(r.CenterPoint().x, r.CenterPoint().y, "hello world"); // draw new rectangle CPen pen(PS_SOLID, 10, RGB(rand()%255,rand()%255,rand()%255)); CPen *pOldPen = pDC->SelectObject(&pen); pDC->Rectangle(50, 50, 250, 250); pDC->SelectObject(pOldPen); // draw new ellipse CPen pen2(PS_SOLID, 10, RGB(rand()%255,rand()%255,rand()%255)); CPen *pOldPen2 = pDC->SelectObject(&pen2); pDC->Ellipse(50, 50, 250, 250); pDC->SelectObject(pOldPen2); // duong cheo chinh CPen pen3(PS_SOLID, 10, RGB(rand()%255,rand()%255,rand()%255)); CPen *pOldPen3 = pDC->SelectObject(&pen3); pDC->MoveTo(50, 50); pDC->LineTo(250, 250); pDC->SelectObject(pOldPen3); // duong cheo phu CPen pen4(PS_SOLID, 10, RGB(rand()%255,rand()%255,rand()%255)); CPen *pOldPen4 = pDC->SelectObject(&pen4); pDC->MoveTo(250, 50); pDC->LineTo(50, 250); pDC->SelectObject(pOldPen4); // release object when it is no longer in use f.DeleteObject(); pen.DeleteObject(); pen2.DeleteObject(); pen3.DeleteObject(); pen4.DeleteObject(); }
void Plot::paintEvent(QPaintEvent *event) { QWidget::paintEvent(event); if (softMinimum == softMaximum) return; for (const auto l : legend) if (l->pen() != Qt::transparent) goto draw; return; draw: QPainter painter(this); // set coordinate system QSize s; s.setHeight(height() - padding_top - padding_bottom); // TODO bug - wykres nie działa, jeśli wartości brzegowe nie są całkowite - problem z setWindow double minval = 0;//double minval = qFloor(minimax.minimum(softMinimum, softMaximum)); double maxval = 0;//qCeil(minimax.maximum(softMinimum, softMaximum)); for (auto i : session->chart->series()) if (legend[i]->pen() != Qt::transparent) for (int j = softMinimum; j <= softMaximum && j < reinterpret_cast<QtCharts::QLineSeries*>(i)->count(); j++) maxval = qMax(maxval, reinterpret_cast<QtCharts::QLineSeries*>(i)->at(j).y()); if (minval == maxval) minval--; double delta = tickSpan(minval, maxval, s.height(), 24); /* TODO do pewnej wysokości nie powinno się rozrzedzać podziałki, tylko ją zwyczajnie skalować */ double ut = maxval = qCeil(maxval / delta) * delta;//double ut = qFloor(maxval / delta) * delta; double lt = qCeil(minval / delta) * delta; int scale = 1; while (delta * scale < 1) scale *= 10; s.setWidth(width() - 50 - 20); painter.setViewport(50 + 10, height() - padding_bottom, s.width(), -s.height()); painter.setWindow(softMinimum, minval, softMaximum - softMinimum, (maxval - minval) * scale); auto transform = painter.combinedTransform(); // draw axis painter.setRenderHint(QPainter::Antialiasing); QPen pen1(QBrush("#808080"), 1.); pen1.setCosmetic(true); painter.setPen(pen1); painter.drawLine(softMinimum, minval * scale, softMaximum, minval * scale); int gap = tickSpan(painter.fontMetrics().width(QString::number(softMaximum)) + 20, width() - 50); painter.setViewTransformEnabled(false); for (int i = softMinimum + (gap - (softMinimum % gap)) % gap; i <= softMaximum; i += gap) { auto tick = transform.map(QPointF(i, minval)).toPoint(); painter.drawLine(tick, tick + QPoint(0, 5)); painter.drawText(QRect(tick + QPoint(0, 9), QSize()), Qt::AlignHCenter | Qt::AlignTop | Qt::TextDontClip, QString::number(i)); } for (qreal i = lt; i <= ut; i += delta) painter.drawText(QRect(transform.map(QPointF(softMinimum, i * scale)).toPoint() - QPoint(9, 0), QSize()), Qt::AlignRight | Qt::AlignVCenter | Qt::TextDontClip, QString::number(i)); painter.setViewTransformEnabled(true); pen1.setStyle(Qt::DashLine); pen1.setColor("#333333"); painter.setPen(pen1); for (qreal i = (lt != minval ? lt : lt + delta); i <= ut; i += delta) painter.drawLine(softMinimum, i * scale, softMaximum, i * scale); painter.save(); painter.scale(1, scale); // plot data for (auto i : session->chart->series()) { auto interval = reinterpret_cast<QtCharts::QLineSeries*>(i)->pointsVector().mid(softMinimum, softMaximum - softMinimum + 1); if (interval.isEmpty()) continue; interval.prepend({interval.first().x(), 0}); interval.append({interval.last().x(), 0}); QLinearGradient gradient(0, minval, 0, maxval); gradient.setColorAt(0, Qt::transparent); gradient.setColorAt(1, legend[i]->brush()); painter.setPen(Qt::NoPen); painter.setBrush(gradient); painter.drawPolygon(interval); QPen pen2(legend[i]->pen(), 2.); pen2.setCosmetic(true); painter.setPen(pen2); painter.drawPolyline(&interval[1], interval.size() - 2); } painter.restore(); if (softMinimum <= value() && value() <= softMaximum) { painter.setViewTransformEnabled(false); int crs = transform.map(QPointF(value(), 0)).x(); QPen pen3(Qt::white, 2.); pen3.setJoinStyle(Qt::MiterJoin); painter.setPen(pen3); painter.setBrush(QBrush(Qt::white)); painter.drawLine(crs, padding_top - 5, crs, height() - padding_bottom); painter.drawConvexPolygon(QPolygon({{crs, padding_top - 2}, {crs - 3, padding_top - 5}, {crs + 3, padding_top - 5}})); } }
void GraphView::DrawPoint(int index, wxRegion *region, bool maybe_repaint_cursor) { bool repaint_cursor = false; int current_index = 0; if (index < 0) return; if (!m_draw->GetValuesTable().at(index).IsData()) return; wxDC* dc = m_dc; if (!dc->Ok()) return; int x, y; GetPointPosition(dc, index, &x , &y); bool wide = m_draw->GetSelected() && m_draw->GetDoubleCursor(); int line_width = wide ? 3 : 1; m_sdc.SetLineWidth(wide ? 3 : 1); m_sdc.SetWhiteForeground(); wxPen pen1(m_draw->GetDrawInfo()->GetDrawColor(), line_width, wxSOLID); wxPen pen2(alt_color, line_width, wxSOLID); dc->SetPen(pen1); dc->SetBrush(wxBrush(wxColour(0,0,0), wxTRANSPARENT)); int i = index; const Draw::VT& vt = m_draw->GetValuesTable(); bool is_alternate = AlternateColor(index); if (i - 1 >= 0 && vt.at(i-1).IsData()) { int x1, y1; GetPointPosition(dc, i - 1, &x1, &y1); bool ac = AlternateColor(i - 1); if (ac && is_alternate) { dc->SetPen(pen2); } else { dc->SetPen(pen1); } dc->DrawLine(x1, y1, x, y); m_sdc.DrawLine(x1, y1, x, y); if (ac) dc->SetPen(pen2); else dc->SetPen(pen1); DrawDot(x1, y1, dc, &m_sdc, region); if (region) region->Union(x1 , std::min(y, y1) - line_width, abs(x - x1) + 2 * line_width, abs(y - y1) + 2 * line_width); if (maybe_repaint_cursor && m_draw->GetCurrentIndex() != -1 && m_draw->GetCurrentIndex() == i) { repaint_cursor = true; current_index = i - 1; } } if ((i + 1) < (int)vt.size() && vt.at(i + 1).IsData()) { int x2, y2; bool ac = AlternateColor(i + 1); if (ac && is_alternate) { dc->SetPen(pen2); } else { dc->SetPen(pen1); } GetPointPosition(dc, i + 1, &x2 , &y2); dc->DrawLine(x, y, x2, y2); m_sdc.DrawLine(x, y, x2, y2); if (ac) dc->SetPen(pen2); else dc->SetPen(pen1); DrawDot(x2, y2, dc, &m_sdc, region); if (region) region->Union(x, std::min(y, y2) - line_width, abs(x - x2) + 2 * line_width, abs(y - y2) + 2 * line_width); if (maybe_repaint_cursor && m_draw->GetCurrentIndex() != -1 && m_draw->GetCurrentIndex() == i) { repaint_cursor = true; current_index = i + 1; } } if (is_alternate) dc->SetPen(pen2); else dc->SetPen(pen1); DrawDot(x, y, dc, &m_sdc, region); m_sdc.SetLineWidth(1); pen1.SetWidth(1); pen2.SetWidth(1); if (repaint_cursor) DrawCursor(current_index, region); dc->SetPen(wxNullPen); dc->SetBrush(wxNullBrush); }
void CElcStatic::OnPaint() { CPaintDC dc(this); DWORD dwStyle = GetStyle(); DWORD dwStaticType = (dwStyle & SS_TYPEMASK); CRect rect; GetClientRect(rect); CElcMemDC dcMem(&dc, rect); if (m_bUseBackgndColor) { dcMem.FillSolidRect(rect, m_crBackgnd); } else if (GetParent()) { HBRUSH hBrush = (HBRUSH)GetParent()->SendMessage(WM_CTLCOLORSTATIC, (WPARAM)dcMem.GetSafeHdc(), (LPARAM)m_hWnd); if (hBrush) ::FillRect(dcMem.GetSafeHdc(), rect, hBrush); } if (m_bUseTextColor) { dcMem.SetTextColor(m_crText); } if (m_pImage) { Graphics g(dcMem.GetSafeHdc()); Rect rcImage(0, 0, m_pImage->GetWidth(), m_pImage->GetHeight()); Rect rcDest; if (dwStyle & SS_CENTERIMAGE) { rcDest.X = rect.left + (rect.Width() - rcImage.Width) / 2; rcDest.Y = rect.top + (rect.Height() - rcImage.Height) / 2; rcDest.Width = rcImage.Width; rcDest.Height = rcImage.Height; } else { rcDest.X = rect.left; rcDest.Y = rect.top; rcDest.Width = rect.Width(); rcDest.Height = rect.Height(); } thePainter.DrawStretchImage(&g, m_pImage, &rcDest, &rcImage, 0); } else if (dwStaticType == SS_ICON || dwStaticType == SS_BITMAP || dwStaticType == SS_OWNERDRAW || dwStaticType == SS_USERITEM || dwStaticType == SS_ENHMETAFILE) { // not support type // pls use SetImage() to replace ASSERT(0); return; } else if (dwStaticType == SS_BLACKRECT || dwStaticType == SS_GRAYRECT || dwStaticType == SS_WHITERECT || dwStaticType == SS_BLACKFRAME || dwStaticType == SS_GRAYFRAME || dwStaticType == SS_WHITEFRAME) { // not support // pls use Standard MFC class : CStatic ASSERT(0); return; } else { if (dwStaticType == SS_ETCHEDHORZ) { CPen pen1(PS_SOLID, 1, m_crEtched1); CPen * pOld = dcMem.SelectObject(&pen1); dcMem.MoveTo(rect.left, rect.top); dcMem.LineTo(rect.right - 2, rect.top); CPen pen2(PS_SOLID, 1, m_crEtched2); dcMem.SelectObject(&pen2); dcMem.MoveTo(rect.left + 2, rect.top+1); dcMem.LineTo(rect.right, rect.top+1); dcMem.SelectObject(&pOld); } else if (dwStaticType == SS_ETCHEDVERT) { CPen pen1(PS_SOLID, 1, m_crEtched1); CPen * pOld = dcMem.SelectObject(&pen1); dcMem.MoveTo(rect.left, rect.top); dcMem.LineTo(rect.left, rect.bottom - 2); CPen pen2(PS_SOLID, 1, m_crEtched2); dcMem.SelectObject(&pen2); dcMem.MoveTo(rect.left + 1, rect.top + 2); dcMem.LineTo(rect.left + 1, rect.bottom); dcMem.SelectObject(&pOld); } else if (dwStaticType == SS_ETCHEDFRAME) { // not implement // support later... ASSERT(0); } else { CFont* pOldFont = dcMem.SelectObject(GetFont()); UINT nFormat = 0; if (dwStaticType == SS_LEFT) { nFormat = DT_LEFT | DT_NOFULLWIDTHCHARBREAK | DT_WORDBREAK; } else if (dwStaticType == SS_CENTER) { nFormat = DT_CENTER | DT_NOFULLWIDTHCHARBREAK | DT_WORDBREAK; } else if (dwStaticType == SS_RIGHT) { nFormat = DT_RIGHT | DT_NOFULLWIDTHCHARBREAK | DT_WORDBREAK; } else if (dwStaticType == SS_SIMPLE) { nFormat = DT_SINGLELINE | DT_VCENTER; } else if (dwStaticType == SS_LEFTNOWORDWRAP) { nFormat = DT_SINGLELINE; } /* // these codes are been commented because something errors are not been fiexd yet if (dwStyle & SS_ENDELLIPSIS) { nFormat |= DT_MODIFYSTRING | DT_END_ELLIPSIS | DT_WORD_ELLIPSIS; } if (dwStyle & SS_PATHELLIPSIS) { nFormat |= DT_MODIFYSTRING | DT_PATH_ELLIPSIS | DT_WORD_ELLIPSIS; }*/ if (dwStyle & SS_NOPREFIX) { nFormat |= DT_NOPREFIX; } if (dwStyle & SS_EDITCONTROL) { nFormat |= DT_EDITCONTROL; } CString strText; GetWindowText(strText); dcMem.DrawText(strText, rect, nFormat); dcMem.SelectObject(pOldFont); } } dcMem.DrawMe(); }
void QtGradientWidget::paintEvent(QPaintEvent *e) { Q_UNUSED(e) QPainter p(this); if (d_ptr->m_backgroundCheckered) { int pixSize = 40; QPixmap pm(2 * pixSize, 2 * pixSize); QPainter pmp(&pm); pmp.fillRect(0, 0, pixSize, pixSize, Qt::white); pmp.fillRect(pixSize, pixSize, pixSize, pixSize, Qt::white); pmp.fillRect(0, pixSize, pixSize, pixSize, Qt::black); pmp.fillRect(pixSize, 0, pixSize, pixSize, Qt::black); p.setBrushOrigin((size().width() % pixSize + pixSize) / 2, (size().height() % pixSize + pixSize) / 2); p.fillRect(rect(), pm); p.setBrushOrigin(0, 0); } QGradient *gradient = 0; switch (d_ptr->m_gradientType) { case QGradient::LinearGradient: gradient = new QLinearGradient(d_ptr->m_startLinear, d_ptr->m_endLinear); break; case QGradient::RadialGradient: gradient = new QRadialGradient(d_ptr->m_centralRadial, d_ptr->m_radiusRadial, d_ptr->m_focalRadial); break; case QGradient::ConicalGradient: gradient = new QConicalGradient(d_ptr->m_centralConical, d_ptr->m_angleConical); break; default: break; } if (!gradient) return; gradient->setStops(d_ptr->m_gradientStops); gradient->setSpread(d_ptr->m_gradientSpread); p.save(); p.scale(size().width(), size().height()); p.fillRect(QRect(0, 0, 1, 1), *gradient); p.restore(); p.setRenderHint(QPainter::Antialiasing); QColor c = QColor::fromRgbF(0.5, 0.5, 0.5, 0.5); QBrush br(c); p.setBrush(br); QPen pen(Qt::white); pen.setWidthF(1); p.setPen(pen); QPen dragPen = pen; dragPen.setWidthF(2); if (d_ptr->m_gradientType == QGradient::LinearGradient) { p.save(); if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::StartLinearHandle) p.setPen(dragPen); d_ptr->paintPoint(&p, d_ptr->m_startLinear, d_ptr->m_handleSize); p.restore(); p.save(); if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::EndLinearHandle) p.setPen(dragPen); d_ptr->paintPoint(&p, d_ptr->m_endLinear, d_ptr->m_handleSize); p.restore(); } else if (d_ptr->m_gradientType == QGradient::RadialGradient) { QPointF central = d_ptr->toViewport(d_ptr->m_centralRadial); p.save(); QRectF r = d_ptr->pointRect(central, 2 * d_ptr->m_handleSize / 3); QRectF r1(0, r.y(), size().width(), r.height()); QRectF r2(r.x(), 0, r.width(), r.y()); QRectF r3(r.x(), r.y() + r.height(), r.width(), size().height() - r.y() - r.height()); p.fillRect(r1, c); p.fillRect(r2, c); p.fillRect(r3, c); p.setBrush(Qt::NoBrush); p.save(); if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::CentralRadialHandle) p.setPen(dragPen); d_ptr->paintPoint(&p, d_ptr->m_centralRadial, d_ptr->m_handleSize); p.restore(); QRectF rect = QRectF(central.x() - d_ptr->m_radiusRadial * size().width(), central.y() - d_ptr->m_radiusRadial * size().height(), 2 * d_ptr->m_radiusRadial * size().width(), 2 * d_ptr->m_radiusRadial * size().height()); p.setClipRect(r1); p.setClipRect(r2, Qt::UniteClip); p.setClipRect(r3, Qt::UniteClip); p.drawEllipse(rect); if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::RadiusRadialHandle) { p.save(); p.setPen(dragPen); QRectF rect = QRectF(central.x() - d_ptr->m_radiusRadial / d_ptr->m_radiusFactor * size().width(), central.y() - d_ptr->m_radiusRadial / d_ptr->m_radiusFactor * size().height(), 2 * d_ptr->m_radiusRadial / d_ptr->m_radiusFactor * size().width(), 2 * d_ptr->m_radiusRadial / d_ptr->m_radiusFactor * size().height()); p.drawEllipse(rect); p.restore(); } p.restore(); p.save(); if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::FocalRadialHandle) p.setPen(dragPen); d_ptr->paintPoint(&p, d_ptr->m_focalRadial, 2 * d_ptr->m_handleSize / 3); p.restore(); } else if (d_ptr->m_gradientType == QGradient::ConicalGradient) { double radius = size().width(); if (size().height() < radius) radius = size().height(); radius /= 2; double corr = d_ptr->m_handleSize / 3; radius -= corr; QPointF central = d_ptr->toViewport(d_ptr->m_centralConical); p.save(); p.setBrush(Qt::NoBrush); QPen pen2(c); pen2.setWidthF(2 * d_ptr->m_handleSize / 3); p.setPen(pen2); p.drawEllipse(d_ptr->pointRect(central, 2 * radius)); p.restore(); p.save(); p.setBrush(Qt::NoBrush); int pointCount = 2; for (int i = 0; i < pointCount; i++) { QPointF ang(cos(M_PI * (i * 180.0 / pointCount + d_ptr->m_angleConical) / 180) * size().width() / 2, -sin(M_PI * (i * 180.0 / pointCount + d_ptr->m_angleConical) / 180) * size().height() / 2); double mod = sqrt(ang.x() * ang.x() + ang.y() * ang.y()); p.drawLine(QPointF(central.x() + ang.x() * (radius - corr) / mod, central.y() + ang.y() * (radius - corr) / mod), QPointF(central.x() + ang.x() * (radius + corr) / mod, central.y() + ang.y() * (radius + corr) / mod)); p.drawLine(QPointF(central.x() - ang.x() * (radius - corr) / mod, central.y() - ang.y() * (radius - corr) / mod), QPointF(central.x() - ang.x() * (radius + corr) / mod, central.y() - ang.y() * (radius + corr) / mod)); } if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::AngleConicalHandle) { p.save(); p.setPen(dragPen); QPointF ang(cos(M_PI * (d_ptr->m_angleConical - d_ptr->m_angleOffset) / 180) * size().width() / 2, -sin(M_PI * (d_ptr->m_angleConical - d_ptr->m_angleOffset) / 180) * size().height() / 2); double mod = sqrt(ang.x() * ang.x() + ang.y() * ang.y()); p.drawLine(QPointF(central.x() + ang.x() * (radius - corr) / mod, central.y() + ang.y() * (radius - corr) / mod), QPointF(central.x() + ang.x() * (radius + corr) / mod, central.y() + ang.y() * (radius + corr) / mod)); p.restore(); } p.restore(); p.save(); if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::CentralConicalHandle) p.setPen(dragPen); d_ptr->paintPoint(&p, d_ptr->m_centralConical, d_ptr->m_handleSize); p.restore(); } delete gradient; }
void SceneImageExporter::PageGraphicsSceneToPrinter(QGraphicsScene *scene, QPrinter &printer, QList<SectorRectHolder>& pageRegions, QString fileName, QString documentName __attribute__((unused))) { PrintingPreferences &pref __attribute__ ((unused)) = PrintingPreferences::prefs(); //qDebug() << pref.yDivisions(); //qDebug() << pref.selectedMeasure(); //qDebug() << pref.measures(); if (!fileName.isEmpty() && fileName != "" && fileName.endsWith(".pdf",Qt::CaseInsensitive)) { printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFileName(fileName); } // When printing, use full page mode, IE ignore hardware margins. It's up // to users to set them as they desire. printer.setFullPage(true); printer.setPaperSize(QSizeF(PrintingPreferences::prefs().selectedMeasure().width(), PrintingPreferences::prefs().selectedMeasure().height()), QPrinter::Millimeter); printer.setPageMargins(PrintingPreferences::prefs().leftMargin(), PrintingPreferences::prefs().topMargin(), PrintingPreferences::prefs().rightMargin(), PrintingPreferences::prefs().bottomMargin(), QPrinter::Millimeter); //here, I print using selected sheets and divisions. QPainter painter(&printer); qreal left,top,right,bottom; printer.getPageMargins(&left,&top,&right,&bottom,QPrinter::DevicePixel); // get the FULL PAGE RECTANGLE and adjust margins. QRectF pageRect = printer.paperRect(); pageRect.adjust(left,top,-right, -bottom); QColor transparent(0,0,0,0); QColor transBorder (0,0,0,128); QPen pen (transBorder); pen.setStyle(Qt::DotLine); QBrush brush; QGraphicsScene sceneFirst; QPen pen2 (QColor(0,0,0)); pen2.setStyle(Qt::DotLine); pen2.setWidthF(2.0); QBrush brush2; for (int h = 0; h < pageRegions.count(); h++) { QRectF rect = pageRegions[h].rectInner(); sceneFirst.addRect (rect.left(), rect.top(), rect.width(),rect.height(),pen2, brush2); rect = pageRegions[h].rectOuter(); sceneFirst.addRect (rect.left(), rect.top(), rect.width(),rect.height(),pen2, brush2); } scene->render(&painter, pageRect, scene->itemsBoundingRect(),Qt::KeepAspectRatio); sceneFirst.render(&painter,pageRect, sceneFirst.sceneRect(),Qt::KeepAspectRatio); for (int h = 0; h < pageRegions.count(); h++) { QRectF rect = pageRegions[h].rectOuter(); double ratio = rect.width()/rect.height(); QRectF rectTarget = QRectF(pageRect.left(), pageRect.top(), pageRect.width(), pageRect.width()/ratio); printer.newPage(); scene->render(&painter,rectTarget, rect); painter.setPen(pen2); painter.setBrush(brush); painter.drawRect(rectTarget); QRectF rect2 = pageRegions[h].rectInner(); double ratioX = rectTarget.width()/rect.width(); double ratioY = rectTarget.height()/rect.height(); double dy = rect2.top()-rect.top(); double dx = rect2.left() - rect.left(); //qDebug() << "rect outer: " << rect // << "\nrect inner: " << rect2 // << "\nrect target: " << rectTarget // << "\nx: " << dx << ",y:" << dy; QRectF rectTarget2 (rectTarget.top()+ dx*ratioX, rectTarget.left()+dy*ratioY, rect2.width()*ratioX, rect2.height()*ratioY); painter.drawRect(rectTarget2); } painter.end(); }
void Hokuyo::paintEvent(QPaintEvent *event) // display the data on the winder { flag = 0; int center_h = (int) (this->parentWidget()->height() /2); int center_w = (int) (this->parentWidget()->width() /2); QPainter painter(this); //*************************************************************** QPen pen2(Qt::black, 2, Qt::SolidLine); painter.setPen(pen2); painter.setBrush(Qt::red); QRectF rectangle(center_w - 2, center_h-2, 4, 4); painter.drawEllipse(rectangle); //******************************************************* if(showLRF) // if show laser range finder { QPen pen(Qt::black, 2, Qt::DashDotDotLine); painter.setPen(pen); painter.drawLine(20, 40, 120, 40); } else if(showIR) // if show small infrared sensor { QPen pen(Qt::black, 2, Qt::SolidLine); painter.setPen(pen); painter.drawLine(20, 40, 20 + center_h, 40); } //************************************************************** if(showIR) { painter.setBrush(Qt::cyan); QPen pen1(Qt::black, 2, Qt::SolidLine); QPointF points_front[3]; QPointF points_back[3]; points_front[0] = QPointF(center_w,center_h); points_front[1] = QPointF(center_w - 50, center_h + (float)this->IR01_update * center_h); points_front[2] = QPointF(center_w + 50, center_h + (float)this->IR01_update * center_h); painter.setPen(pen1); painter.drawPolygon(points_front,3); painter.setBrush(Qt::darkCyan); points_back[0] = QPointF(center_w, center_h); points_back[1] = QPointF(center_w - 50, center_h - (float)this->IR02_update * center_h); points_back[2] = QPointF(center_w + 50, center_h - (float)this->IR02_update * center_h); painter.drawPolygon(points_back,3); } else if(showLRF) { QPen pen3(Qt::black, 2, Qt::DashDotDotLine); painter.setPen(pen3); int count = 0; if(hokuyo_points!=NULL) { for(int it=0;it<683;it++) { painter.drawPoint(hokuyo_points[it].x * 100 + 300, -(hokuyo_points[it].y * 100) + 300); if(showlines) painter.drawLine(300,300,hokuyo_points[it].x * 100 + 300, -(hokuyo_points[it].y * 100) + 300); count ++; } } flag = 1; } }
void MyZKbMain::paintEvent(QPaintEvent * pe) { ZConfig Num(QString("numeros.cfg"), true); ZConfig ini(QString("skin.ini"), false); /*************/ int X1 = ini.readNumEntry(QString("UBICACION"), QString("1_X"), 2); int X2 = ini.readNumEntry(QString("UBICACION"), QString("2_X"), 2); int X3 = ini.readNumEntry(QString("UBICACION"), QString("3_X"), 2); int X4 = ini.readNumEntry(QString("UBICACION"), QString("4_X"), 2); int X5 = ini.readNumEntry(QString("UBICACION"), QString("5_X"), 2); int X6 = ini.readNumEntry(QString("UBICACION"), QString("6_X"), 2); int X7 = ini.readNumEntry(QString("UBICACION"), QString("7_X"), 2); int X8 = ini.readNumEntry(QString("UBICACION"), QString("8_X"), 2); int X9 = ini.readNumEntry(QString("UBICACION"), QString("9_X"), 2); int X10 = ini.readNumEntry(QString("UBICACION"), QString("10_X"), 2); int X11 = ini.readNumEntry(QString("UBICACION"), QString("11_X"), 2); int X12 = ini.readNumEntry(QString("UBICACION"), QString("12_X"), 2); int X13 = ini.readNumEntry(QString("UBICACION"), QString("13_X"), 2); int X14 = ini.readNumEntry(QString("UBICACION"), QString("14_X"), 2); int X15 = ini.readNumEntry(QString("UBICACION"), QString("15_X"), 2); int X16 = ini.readNumEntry(QString("UBICACION"), QString("16_X"), 2); int X17 = ini.readNumEntry(QString("UBICACION"), QString("17_X"), 2); int X18 = ini.readNumEntry(QString("UBICACION"), QString("18_X"), 2); int X19 = ini.readNumEntry(QString("UBICACION"), QString("19_X"), 2); int X20 = ini.readNumEntry(QString("UBICACION"), QString("20_X"), 2); int X21 = ini.readNumEntry(QString("UBICACION"), QString("21_X"), 2); int X22 = ini.readNumEntry(QString("UBICACION"), QString("22_X"), 2); int X23 = ini.readNumEntry(QString("UBICACION"), QString("23_X"), 2); int X24 = ini.readNumEntry(QString("UBICACION"), QString("24_X"), 2); int X25 = ini.readNumEntry(QString("UBICACION"), QString("25_X"), 2); int X26 = ini.readNumEntry(QString("UBICACION"), QString("26_X"), 2); int X27 = ini.readNumEntry(QString("UBICACION"), QString("27_X"), 2); int X28 = ini.readNumEntry(QString("UBICACION"), QString("28_X"), 2); int X29 = ini.readNumEntry(QString("UBICACION"), QString("29_X"), 2); int X30 = ini.readNumEntry(QString("UBICACION"), QString("30_X"), 2); int X31 = ini.readNumEntry(QString("UBICACION"), QString("31_X"), 2); int X32 = ini.readNumEntry(QString("UBICACION"), QString("32_X"), 2); int X33 = ini.readNumEntry(QString("UBICACION"), QString("33_X"), 2); int X34 = ini.readNumEntry(QString("UBICACION"), QString("34_X"), 2); int X35 = ini.readNumEntry(QString("UBICACION"), QString("35_X"), 2); int X36 = ini.readNumEntry(QString("UBICACION"), QString("36_X"), 2); /*************/ int Y1 = ini.readNumEntry(QString("UBICACION"), QString("1_Y"), 2); int Y2 = ini.readNumEntry(QString("UBICACION"), QString("2_Y"), 2); int Y3 = ini.readNumEntry(QString("UBICACION"), QString("3_Y"), 2); int Y4 = ini.readNumEntry(QString("UBICACION"), QString("4_Y"), 2); int Y5 = ini.readNumEntry(QString("UBICACION"), QString("5_Y"), 2); int Y6 = ini.readNumEntry(QString("UBICACION"), QString("6_Y"), 2); int Y7 = ini.readNumEntry(QString("UBICACION"), QString("7_Y"), 2); int Y8 = ini.readNumEntry(QString("UBICACION"), QString("8_Y"), 2); int Y9 = ini.readNumEntry(QString("UBICACION"), QString("9_Y"), 2); int Y10 = ini.readNumEntry(QString("UBICACION"), QString("10_Y"), 2); int Y11 = ini.readNumEntry(QString("UBICACION"), QString("11_Y"), 2); int Y12 = ini.readNumEntry(QString("UBICACION"), QString("12_Y"), 2); int Y13 = ini.readNumEntry(QString("UBICACION"), QString("13_Y"), 2); int Y14 = ini.readNumEntry(QString("UBICACION"), QString("14_Y"), 2); int Y15 = ini.readNumEntry(QString("UBICACION"), QString("15_Y"), 2); int Y16 = ini.readNumEntry(QString("UBICACION"), QString("16_Y"), 2); int Y17 = ini.readNumEntry(QString("UBICACION"), QString("17_Y"), 2); int Y18 = ini.readNumEntry(QString("UBICACION"), QString("18_Y"), 2); int Y19 = ini.readNumEntry(QString("UBICACION"), QString("19_Y"), 2); int Y20 = ini.readNumEntry(QString("UBICACION"), QString("20_Y"), 2); int Y21 = ini.readNumEntry(QString("UBICACION"), QString("21_Y"), 2); int Y22 = ini.readNumEntry(QString("UBICACION"), QString("22_Y"), 2); int Y23 = ini.readNumEntry(QString("UBICACION"), QString("23_Y"), 2); int Y24 = ini.readNumEntry(QString("UBICACION"), QString("24_Y"), 2); int Y25 = ini.readNumEntry(QString("UBICACION"), QString("25_Y"), 2); int Y26 = ini.readNumEntry(QString("UBICACION"), QString("26_Y"), 2); int Y27 = ini.readNumEntry(QString("UBICACION"), QString("27_Y"), 2); int Y28 = ini.readNumEntry(QString("UBICACION"), QString("28_Y"), 2); int Y29 = ini.readNumEntry(QString("UBICACION"), QString("29_Y"), 2); int Y30 = ini.readNumEntry(QString("UBICACION"), QString("30_Y"), 2); int Y31 = ini.readNumEntry(QString("UBICACION"), QString("31_Y"), 2); int Y32 = ini.readNumEntry(QString("UBICACION"), QString("32_Y"), 2); int Y33 = ini.readNumEntry(QString("UBICACION"), QString("33_Y"), 2); int Y34 = ini.readNumEntry(QString("UBICACION"), QString("34_Y"), 2); int Y35 = ini.readNumEntry(QString("UBICACION"), QString("35_Y"), 2); int Y36 = ini.readNumEntry(QString("UBICACION"), QString("36_Y"), 2); /*************/ if(!flag_loading) { QPixmap pix; pix=myimg; QRect ur(0,0,240,320); ur=pe->rect(); QPainter p(&pix); p.begin(&pix); QPainter p2(&pix); p2.begin(&pix); QPen pen(QColor(255,0,0) ); p.setPen(pen); QPen pen2(QColor(255,255,255) ); p2.setPen(pen2); if ( current == 1 ) { p.drawRect(X1, Y1, 40, 27); } if ( current == 2 ) { p.drawRect(X2, Y2, 40, 27); } if ( current == 3 ) { p.drawRect(X3, Y3, 40, 27); } if ( current == 4 ) { p.drawRect(X4, Y4, 40, 27); } if ( current == 5 ) { p.drawRect(X5, Y5, 40, 27); } if ( current == 6 ) { p.drawRect(X6, Y6, 40, 27); } if ( current == 7 ) { p.drawRect(X7, Y7, 40, 27); } if ( current == 8 ) { p.drawRect(X8, Y8, 40, 27); } if ( current == 9 ) { p.drawRect(X9, Y9, 40, 27); } if ( current == 10 ) { p.drawRect(X10, Y10, 40, 27); } if ( current == 11 ) { p.drawRect(X11, Y11, 40, 27); } if ( current == 12 ) { p.drawRect(X12, Y12, 40, 27); } if ( current == 13 ) { p.drawRect(X13, Y13, 40, 27); } if ( current == 14 ) { p.drawRect(X14, Y14, 40, 27); } if ( current == 15 ) { p.drawRect(X15, Y15, 40, 27); } if ( current == 16 ) { p.drawRect(X16, Y16, 40, 27); } if ( current == 17 ) { p.drawRect(X17, Y17, 40, 27); } if ( current == 18 ) { p.drawRect(X18, Y18, 40, 27); } if ( current == 19 ) { p.drawRect(X19, Y19, 40, 27); } if ( current == 20 ) { p.drawRect(X20, Y20, 40, 27); } if ( current == 21 ) { p.drawRect(X21, Y21, 40, 27); } if ( current == 22 ) { p.drawRect(X22, Y22, 40, 27); } if ( current == 23 ) { p.drawRect(X23, Y23, 40, 27); } if ( current == 24 ) { p.drawRect(X24, Y24, 40, 27); } if ( current == 25 ) { p.drawRect(X25, Y25, 40, 27); } if ( current == 26 ) { p.drawRect(X26, Y26, 40, 27); } if ( current == 27 ) { p.drawRect(X27, Y27, 40, 27); } if ( current == 28 ) { p.drawRect(X28, Y28, 40, 27); } if ( current == 29 ) { p.drawRect(X29, Y29, 40, 27); } if ( current == 30 ) { p.drawRect(X30, Y30, 40, 27); } if ( current == 31 ) { p.drawRect(X31, Y31, 40, 27); } if ( current == 32 ) { p.drawRect(X32, Y32, 40, 27); } if ( current == 33 ) { p.drawRect(X33, Y33, 40, 27); } if ( current == 34 ) { p.drawRect(X34, Y34, 40, 27); } if ( current == 35 ) { p.drawRect(X35, Y35, 40, 27); } if ( current == 36 ) { p.drawRect(X36, Y36, 40, 27); } if ( calcular==1 ) { int valx; lista.clear(); valx=1; Probabilidad(valx); valx=2; Probabilidad(valx); valx=4; Probabilidad(valx); valx=5; Probabilidad(valx); valx=7; Probabilidad(valx); valx=8; Probabilidad(valx); valx=10; Probabilidad(valx); valx=11; Probabilidad(valx); valx=13; Probabilidad(valx); valx=14; Probabilidad(valx); valx=16; Probabilidad(valx); valx=17; Probabilidad(valx); valx=19; Probabilidad(valx); valx=20; Probabilidad(valx); valx=22; Probabilidad(valx); valx=23; Probabilidad(valx); valx=25; Probabilidad(valx); valx=26; Probabilidad(valx); valx=28; Probabilidad(valx); valx=29; Probabilidad(valx); valx=31; Probabilidad(valx); valx=32; Probabilidad(valx); calcular=0; } int i=1; int j=1; QString stop="NO"; QString numero; while ( j<36 ) { update(); int number = Num.readNumEntry(QString("NUMEROS"), QString("%1").arg(j), 0 ); numero=""; for(int k=0;k<number;++k) { numero+=QString("."); } if ( number != 0 ) { p2.drawText(22, (25*i)+i*2/3+3, QString("%1").arg(numero), 50, QPainter::NONE); } j++; number = Num.readNumEntry(QString("NUMEROS"), QString("%1").arg(j), 0 ); numero=""; for(int k=0;k<number;++k) { numero+=QString("."); } if ( number != 0 ) { p2.drawText(61, (25*i)+i*2/3+3, QString("%1").arg(numero), 50, QPainter::NONE); } j++; number = Num.readNumEntry(QString("NUMEROS"), QString("%1").arg(j), 0 ); numero=""; for(int k=0;k<number;++k) { numero+=QString("."); } if ( number != 0 ) { p2.drawText(99, (25*i)+i*2/3+3, QString("%1").arg(numero), 50, QPainter::NONE); } i++; j++; if ( j==36 ) { stop="YES"; } } QString pr1,pr2,pr3,pr4; int cp=1; for ( int j=0 ; j < lista.count(); ++j ) { if ( cp <= 4 ) { pr1 += QString("%1 ").arg(lista[j]); } else if ( (cp>=5) && (cp<=8) ) { pr2 += QString("%1 ").arg(lista[j]); } else if ( (cp>=9) && (cp<=12) ) { pr3 += QString("%1 ").arg(lista[j]); } else if ( (cp>=13) && (cp<=16) ) { pr4 += QString("%1 ").arg(lista[j]); } ++cp; } p2.drawText(136, 240, QString("%1").arg(pr1), 50, QPainter::NONE); p2.drawText(136, 265, QString("%1").arg(pr2), 50, QPainter::NONE); p2.drawText(136, 290, QString("%1").arg(pr3), 50, QPainter::NONE); p2.drawText(136, 315, QString("%1").arg(pr4), 50, QPainter::NONE); jugadas=0; for ( int k=1 ; k < 37; ++k ) { int number = Num.readNumEntry(QString("NUMEROS"), QString("%1").arg(k), 0 ); jugadas +=number; } p2.drawText(136, 165, QString("%1").arg(jugadas), 50, QPainter::NONE); p.end(); p2.end(); setWFlags(getWFlags() | Qt::WRepaintNoErase); bitBlt( this, start_x , start_y , &pix, 0, 0, -1, -1 ); } QWidget::paintEvent( pe); }
void CSkinButton2::DrawFrame(Gdiplus::Graphics& gdi,CRect& rect) { if( m_enmuDrawType == NO_FRAME ) { Gdiplus::Pen pen1( m_colFrame1 ); gdi.DrawLine( &pen1, rect.left+1, rect.top, rect.right-2, rect.top ); gdi.DrawLine( &pen1, rect.left+1, rect.bottom-1, rect.right-2, rect.bottom-1 ); gdi.DrawLine( &pen1, rect.left, rect.top+1, rect.left, rect.bottom-2 ); gdi.DrawLine( &pen1, rect.right-1, rect.top+1, rect.right-1, rect.bottom-2 ); Gdiplus::Color colpix; pen1.GetColor( &colpix ); colpix.SetValue( Gdiplus::Color::MakeARGB(colpix.GetA()/2,colpix.GetR(),colpix.GetG(),colpix.GetB() ) ); Gdiplus::Pen penPix1( colpix ); gdi.DrawLine( &penPix1, rect.left, rect.top, rect.left+1, rect.top ); gdi.DrawLine( &penPix1, rect.right-1, rect.top, rect.right-1, rect.top+1 ); gdi.DrawLine( &penPix1, rect.right-1, rect.bottom-1, rect.right-2, rect.bottom-1 ); gdi.DrawLine( &penPix1, rect.left, rect.bottom-1, rect.left+1, rect.bottom-1 ); CRect rect2 = rect; ::InflateRect( &rect2, -1,-1 ); if( !m_bMouseDown ) { Gdiplus::Pen pen2(m_colFrame2); if( m_bMouseDown ) pen2.SetColor(m_colFrame1); else pen2.SetColor(m_colFrame2); gdi.DrawLine( &pen2, rect2.left+1, rect2.top, rect2.right-2, rect2.top ); gdi.DrawLine( &pen2, rect2.left+1, rect2.bottom-1, rect2.right-2, rect2.bottom-1 ); gdi.DrawLine( &pen2, rect2.left, rect2.top+1, rect2.left, rect2.bottom-2 ); gdi.DrawLine( &pen2, rect2.right-1, rect2.top+1, rect2.right-1, rect2.bottom-2 ); Gdiplus::Color colpix2; pen2.GetColor( &colpix2 ); colpix2.SetValue( Gdiplus::Color::MakeARGB(colpix2.GetA()/2,colpix2.GetR(),colpix2.GetG(),colpix2.GetB() ) ); Gdiplus::Pen penPix2( colpix2 ); gdi.DrawLine( &penPix2, rect2.left, rect2.top, rect2.left+1, rect2.top ); gdi.DrawLine( &penPix2, rect2.right-1, rect2.top, rect2.right-1, rect2.top+1 ); gdi.DrawLine( &penPix2, rect2.right-1, rect2.bottom-1, rect2.right-2, rect2.bottom-1 ); gdi.DrawLine( &penPix2, rect2.left, rect2.bottom-1, rect2.left+1, rect2.bottom-1 ); } if( m_bMouseDown ) { Gdiplus::RectF rc( rect2.left, rect2.top, rect2.Width(), rect2.Height()/3 ); Gdiplus::Color colBrush1,colBrush2; colBrush1.SetValue( Gdiplus::Color::MakeARGB(15,1,1,1) ); colBrush2.SetValue( Gdiplus::Color::MakeARGB(0,1,1,1) ); LinearGradientBrush brush( rc, colBrush1, colBrush2,LinearGradientModeVertical ); gdi.FillRectangle( &brush, rc ); } else { Gdiplus::RectF rc( rect2.left, rect2.top, rect2.Width(), rect2.Height()/2 ); rc.Inflate(-1,-1); LinearGradientBrush brush( rc, m_colBrush1, m_colBrush2,LinearGradientModeVertical ); gdi.FillRectangle( &brush, rc ); } return; } else if( m_enmuDrawType == NO_FRAME_SELECT ) { Gdiplus::Pen pen1( m_colFrame1 ); gdi.DrawLine( &pen1, rect.left+1, rect.top, rect.right-2, rect.top ); gdi.DrawLine( &pen1, rect.left+1, rect.bottom-1, rect.right-2, rect.bottom-1 ); gdi.DrawLine( &pen1, rect.left, rect.top+1, rect.left, rect.bottom-2 ); gdi.DrawLine( &pen1, rect.right-1, rect.top+1, rect.right-1, rect.bottom-2 ); Gdiplus::Color colpix; pen1.GetColor( &colpix ); colpix.SetValue( Gdiplus::Color::MakeARGB(colpix.GetA()/2,colpix.GetR(),colpix.GetG(),colpix.GetB() ) ); Gdiplus::Pen penPix1( colpix ); gdi.DrawLine( &penPix1, rect.left, rect.top, rect.left+1, rect.top ); gdi.DrawLine( &penPix1, rect.right-1, rect.top, rect.right-1, rect.top+1 ); gdi.DrawLine( &penPix1, rect.right-1, rect.bottom-1, rect.right-2, rect.bottom-1 ); gdi.DrawLine( &penPix1, rect.left, rect.bottom-1, rect.left+1, rect.bottom-1 ); CRect rect2 = rect; ::InflateRect( &rect2, -1,-1 ); if( !m_bMouseDown ) { Gdiplus::Pen pen2(m_colFrame2); if( m_bMouseDown ) pen2.SetColor(m_colFrame1); else pen2.SetColor(m_colFrame2); gdi.DrawLine( &pen2, rect2.left+1, rect2.top, rect2.right-2, rect2.top ); gdi.DrawLine( &pen2, rect2.left+1, rect2.bottom-1, rect2.right-2, rect2.bottom-1 ); gdi.DrawLine( &pen2, rect2.left, rect2.top+1, rect2.left, rect2.bottom-2 ); gdi.DrawLine( &pen2, rect2.right-1, rect2.top+1, rect2.right-1, rect2.bottom-2 ); Gdiplus::Color colpix2; pen2.GetColor( &colpix2 ); colpix2.SetValue( Gdiplus::Color::MakeARGB(colpix2.GetA()/2,colpix2.GetR(),colpix2.GetG(),colpix2.GetB() ) ); Gdiplus::Pen penPix2( colpix2 ); gdi.DrawLine( &penPix2, rect2.left, rect2.top, rect2.left+1, rect2.top ); gdi.DrawLine( &penPix2, rect2.right-1, rect2.top, rect2.right-1, rect2.top+1 ); gdi.DrawLine( &penPix2, rect2.right-1, rect2.bottom-1, rect2.right-2, rect2.bottom-1 ); gdi.DrawLine( &penPix2, rect2.left, rect2.bottom-1, rect2.left+1, rect2.bottom-1 ); } /* if( m_bMouseDown ) { Gdiplus::RectF rc( rect2.left, rect2.top, rect2.Width(), rect2.Height()/3 ); Gdiplus::Color colBrush1,colBrush2; colBrush1.SetValue( Gdiplus::Color::MakeARGB(15,1,1,1) ); colBrush2.SetValue( Gdiplus::Color::MakeARGB(0,1,1,1) ); LinearGradientBrush brush( rc, colBrush1, colBrush2,LinearGradientModeVertical ); gdi.FillRectangle( &brush, rc ); } else { Gdiplus::RectF rc( rect2.left, rect2.top, rect2.Width(), rect2.Height()/2 ); rc.Inflate(-1,-1); LinearGradientBrush brush( rc, m_colBrush1, m_colBrush2,LinearGradientModeVertical ); gdi.FillRectangle( &brush, rc ); }*/ CRect rect3 = rect2; ::InflateRect( &rect3, -1,-1 ); Gdiplus::RectF rc( rect3.left, rect3.top, rect3.Width(), rect3.Height() ); LinearGradientBrush brush( rc, m_colBK, m_colBK,LinearGradientModeVertical ); gdi.FillRectangle( &brush, rc ); Gdiplus::Color colBlack1 = Gdiplus::Color::MakeARGB(30,50,50,50); Gdiplus::Color colBlack2 = Gdiplus::Color::MakeARGB(15,50,50,50); Gdiplus::RectF rc1( rect3.left, rect3.top+rect3.Height()/2, rect3.Width(), rect3.Height()/2 ); LinearGradientBrush brush2( rc1, colBlack1, colBlack2,LinearGradientModeVertical ); gdi.FillRectangle( &brush2, rc1 ); return; } if( m_enmuDrawType == TOP_ARC ) { Gdiplus::Pen pen1( m_colFrame1 ); gdi.DrawLine( &pen1, rect.left+5, rect.top, rect.right-7, rect.top ); gdi.DrawLine( &pen1, rect.left, rect.bottom-1, rect.right, rect.bottom-1 ); gdi.DrawLine( &pen1, rect.left, rect.top+5, rect.left, rect.bottom-2 ); gdi.DrawLine( &pen1, rect.right-1, rect.top+5, rect.right-1, rect.bottom-2 ); CRect rect2 = rect; ::InflateRect( &rect2, -1,-1 ); if( !m_bMouseDown ) { Gdiplus::Pen pen2(m_colFrame2); gdi.DrawLine( &pen2, rect2.left+4, rect2.top, rect2.right-5, rect2.top ); gdi.DrawLine( &pen2, rect2.left, rect2.bottom-1, rect2.right-1, rect2.bottom-1 ); gdi.DrawLine( &pen2, rect2.left, rect2.top+4, rect2.left, rect2.bottom-2 ); gdi.DrawLine( &pen2, rect2.right-1, rect2.top+4, rect2.right-1, rect2.bottom-2 ); Gdiplus::RectF rectLeftTop2; rectLeftTop2.X = rect2.left; rectLeftTop2.Y = rect2.top; rectLeftTop2.Width = 6; rectLeftTop2.Height = 6; gdi.DrawArc( &pen2, rectLeftTop2,180,90 ); Gdiplus::RectF rectRightTop2; rectRightTop2.X = rect2.right-7; rectRightTop2.Y = rect2.top; rectRightTop2.Width = 6; rectRightTop2.Height = 6; gdi.DrawArc( &pen2, rectRightTop2,270,90 ); } Gdiplus::RectF rectLeftTop; rectLeftTop.X = rect.left; rectLeftTop.Y = rect.top; rectLeftTop.Width = 9; rectLeftTop.Height = 9; gdi.DrawArc( &pen1, rectLeftTop,180,90 ); Gdiplus::RectF rectRightTop; rectRightTop.X = rect.right-10; rectRightTop.Y = rect.top; rectRightTop.Width = 9; rectRightTop.Height = 9; gdi.DrawArc( &pen1, rectRightTop,270,90 ); /*Gdiplus::SolidBrush sb( m_colBrush ); Gdiplus::Brush *pbrush = sb.Clone();*/ if( m_bMouseDown ) { Gdiplus::RectF rc( rect2.left, rect2.top, rect2.Width(), rect2.Height()/3 ); Gdiplus::Color colBrush1,colBrush2; colBrush1.SetValue( Gdiplus::Color::MakeARGB(15,1,1,1) ); colBrush2.SetValue( Gdiplus::Color::MakeARGB(0,1,1,1) ); LinearGradientBrush brush( rc, colBrush1, colBrush2,LinearGradientModeVertical ); gdi.FillRectangle( &brush, rc ); } else { Gdiplus::RectF rc( rect2.left, rect2.top, rect2.Width(), rect2.Height()/2 ); rc.Inflate(-1,-1); LinearGradientBrush brush( rc, m_colBrush1, m_colBrush2,LinearGradientModeVertical ); gdi.FillRectangle( &brush, rc ); } } else if( m_enmuDrawType == BOTTON_ARC ) { } else if( m_enmuDrawType == RIGHT_ARC ) { } else if( m_enmuDrawType == LEFT_ARC ) { } else if( m_enmuDrawType & (TOP_ARC|BOTTON_ARC) || m_enmuDrawType & (RIGHT_ARC|LEFT_ARC) ) { // 四角都有弧线 } //gdi.DrawString( }
void CTextToolView::OnDraw(CDC* pDC) { CTextToolDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here if (iLogicalPixelsY == -1) { iLogicalPixelsY = pDC->GetDeviceCaps(LOGPIXELSY); LOGFONT rLogFont; m_pFont->GetLogFont(&rLogFont); m_iFontPointSize = -((rLogFont.lfHeight*72)/iLogicalPixelsY); } CBrush brush(RGB(0,0,0)); pDC->SetBkMode(OPAQUE); RECT rect; GetWindowRect(&rect); //pDC->GetBoundsRect(&rect,0); pDC->FillRect(&rect,&brush); // just in case rect.top = 0; rect.bottom = 1024; rect.left = 0; rect.right = 1024; pDC->FillRect(&rect,&brush); pDC->SetBkMode(TRANSPARENT ); pDC->SetTextColor(RGB(255,255,255)); pDC->SetBkColor(RGB(0,0,0)); pDC->SelectObject(m_pFont); CPen pen(PS_SOLID,1,RGB(128,128,128)); CPen pen2(PS_SOLID,1,RGB(64,64,255)); pDC->SelectObject(pen); CString szString = " !\"#$%'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ{\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; pDC->GetCharABCWidths(' ','~',m_aWidths); LOGFONT rLogFont; m_pFont->GetLogFont(&rLogFont); CSize size = pDC->GetTextExtent(szString); m_iCharacterHeight = abs(rLogFont.lfHeight); m_iTextureZStep = size.cy; //-rLogFont.lfHeight+2; int iXPos = 0; int iYPos = 0; int iXCount = 0; for (int iChar = ' '; iChar <= '~'; iChar++) { int iThisItem = iChar - ' '; int iThisPos = iXPos - m_aWidths[iThisItem].abcA; int iEndPos = iXCount + m_iTextureZStep; //m_aWidths[iChar-' '].abcB; if (iEndPos >= m_iMaxTextureWidth) { iXPos = 0; iXCount = 0; iThisPos = iXPos - m_aWidths[iThisItem].abcA; iEndPos = iXCount + m_iTextureZStep; //m_aWidths[iChar-' '].abcB; iYPos += m_iTextureZStep; } CString string = (char)iChar; pDC->TextOut(iThisPos, iYPos, string); m_arGlyphExtents[iThisItem].iStartX = iXCount; m_arGlyphExtents[iThisItem].iEndX = iXCount + m_aWidths[iThisItem].abcB; m_arGlyphExtents[iThisItem].iStartY = iYPos; m_arGlyphExtents[iThisItem].iEndY = iYPos + m_iTextureZStep; pDC->SelectObject(pen); iXPos = iEndPos; iXCount += m_iTextureZStep; } m_iMaxY = iYPos +m_iTextureZStep; pDC->SelectStockObject(SYSTEM_FONT); pDC->SelectStockObject(WHITE_PEN); }