void nodeWidget::paint( QPainter *painter, const QStyleOptionGraphicsItem *, QWidget * ) { QString title( "Hello" ); QList <QString> properties; properties << "Thing" << "lalala" << "bouind" << "hahaha"; QRectF originalRect( titlebarRect( painter->font() ) ); _titlePath = QPainterPath(); _titlePath.addRect( originalRect ); QRectF titleRect( originalRect ); titleRect.setHeight( titleRect.height() + ( ROUNDRADIUS * 2 + 1 ) ); QRectF contentsRect( titleRect ); contentsRect.setY( originalRect.height() ); contentsRect.setHeight( originalRect.height() + NODEPROPERTYHEIGHT*( properties.size() - 1 ) - 2*ROUNDRADIUS - 4 ); QPainterPath titleBar( makeRoundedPath( titleRect ) ); QPainterPath contents( makeRoundedPath( contentsRect ) ); QPen outlinePen( Qt::black, 3 ); if( isSelected() ) { outlinePen.setColor( SELECTED_COLOUR ); } QPainterPath globalLine( makeRoundedPath( titleRect.unite( contentsRect ) ) ); painter->setPen( outlinePen ); painter->drawPath( globalLine ); painter->fillPath( titleBar, titleGradient( titleRect ) ); painter->fillPath( contents, contentsBrush( contentsRect ) ); QColor separatingLineColor( Qt::black ); if( isSelected() ) { separatingLineColor = SELECTED_COLOUR; } separatingLineColor.setAlpha( 128 ); QPen separatingLinePen( separatingLineColor ); QPen whitePen( Qt::white ); painter->setPen( whitePen ); painter->drawText( originalRect, Qt::AlignCenter, title ); QRectF textRect( titleRect ); textRect.moveTop( textRect.top() + originalRect.height() - 2*ROUNDRADIUS - 2 ); FOREACH( properties, prop ) { painter->setPen( whitePen ); painter->drawText( textRect, Qt::AlignCenter, *prop ); if( &(*prop) != &(properties.back()) ) { painter->setPen( separatingLinePen ); painter->drawLine( titleRect.x(), textRect.y()+NODEPROPERTYHEIGHT+4, titleRect.x()+titleRect.width(), textRect.y()+NODEPROPERTYHEIGHT+4 ); } textRect.moveTop( textRect.top() + NODEPROPERTYHEIGHT ); }
void CPlayerSeekBar::CreateThumb(bool bEnabled, CDC& parentDC) { auto& pThumb = bEnabled ? m_pEnabledThumb : m_pDisabledThumb; pThumb = std::unique_ptr<CDC>(new CDC()); if (pThumb->CreateCompatibleDC(&parentDC)) { COLORREF white = GetSysColor(COLOR_WINDOW), shadow = GetSysColor(COLOR_3DSHADOW), light = GetSysColor(COLOR_3DHILIGHT), bkg = GetSysColor(COLOR_BTNFACE); CRect r(GetThumbRect()); r.MoveToXY(0, 0); CRect ri(GetInnerThumbRect(bEnabled, r)); CBitmap bmp; VERIFY(bmp.CreateCompatibleBitmap(&parentDC, r.Width(), r.Height())); VERIFY(pThumb->SelectObject(bmp)); pThumb->Draw3dRect(&r, light, 0); r.DeflateRect(0, 0, 1, 1); pThumb->Draw3dRect(&r, light, shadow); r.DeflateRect(1, 1, 1, 1); CBrush b(bkg); pThumb->FrameRect(&r, &b); r.DeflateRect(0, 1, 0, 1); pThumb->FrameRect(&r, &b); r.DeflateRect(1, 1, 0, 0); pThumb->Draw3dRect(&r, shadow, bkg); if (bEnabled) { r.DeflateRect(1, 1, 1, 2); CPen whitePen(PS_INSIDEFRAME, 1, white); CPen* old = pThumb->SelectObject(&whitePen); pThumb->MoveTo(r.left, r.top); pThumb->LineTo(r.right, r.top); pThumb->MoveTo(r.left, r.bottom); pThumb->LineTo(r.right, r.bottom); pThumb->SelectObject(old); pThumb->SetPixel(r.CenterPoint().x, r.top, 0); pThumb->SetPixel(r.CenterPoint().x, r.bottom, 0); } } else { ASSERT(FALSE); } }
void qAttitudeIndicator::paintEvent(QPaintEvent *) { QPainter painter(this); QPoint center(0,0); QPen whitePen(Qt::white); QPen blackPen(Qt::black); QBrush bgSky(QColor(48,172,220)); QBrush bgGround(QColor(247,168,21)); whitePen.setWidth(2); blackPen.setWidth(1); painter.setRenderHint(QPainter::Antialiasing); painter.translate(width() / 2, height() / 2); int side = qMin(width(), height()); painter.scale(side / (qreal)(size), side / (qreal)(size)); painter.setPen(blackPen); painter.rotate(roll); painter.setBrush(bgSky); int y = 0.25*size*pitch/20.; int x = sqrt(size*size/4 - y*y); qreal gr = atan((double)(y)/x); gr = gr * 180./3.1415926; painter.drawChord(-side/2,-side/2,side,side,gr*16,(180-2*gr)*16); painter.setBrush(bgGround); painter.drawChord(-side/2,-side/2,side,side,gr*16,-(180+2*gr)*16); painter.setPen(whitePen); painter.drawLine(-x,-y,x,-y); painter.setPen(blackPen); painter.rotate(-180.); for(int i=0;i<numbRollLine;i++) { painter.rotate(rollRotate[i]); painter.drawLine(rollPoint[i][0],rollPoint[i][1]); } whitePen.setWidth(1); painter.setPen(whitePen); painter.rotate(-90.); for(int i=0;i<numbPitchLine;i++) { painter.drawLine(pitchPoint[i][0],pitchPoint[i][1]); } painter.rotate(-roll); blackPen.setWidth(3); painter.setPen(blackPen); painter.drawLines(target); painter.drawLines(rollPointer); }
//----------------------------------------------------------------------------- //! Draws tick markers on the rudder bar. //----------------------------------------------------------------------------- void tRudderBarMedusa::DrawTickMarks( const QRect rect, QPainter* pPainter ) { pPainter->save(); // Translate painter to center of bar pPainter->translate( rect.width() / 2, rect.top() + (rect.height() / 2) ); QPen whitePen( pPainter->pen() ); whitePen.setColor( Qt::lightGray ); whitePen.setWidth( m_TickWidth ); whitePen.setCapStyle( Qt::RoundCap ); pPainter->setPen( whitePen ); int halfTickHeight = m_TickHeight / 2; // middle mark if ( !m_ValueVisible ) { pPainter->drawLine( 0, -halfTickHeight, 0, halfTickHeight ); } int x = m_BarWidth/2; pPainter->drawLine( x, -halfTickHeight, x, halfTickHeight ); // 100 % starboard pPainter->drawLine( -x, -halfTickHeight, -x, halfTickHeight ); // 100 % port int gainedWidth = ( m_BarWidth * m_cQuarterPosInPercentage ) / 100; int restWidth = m_BarWidth - gainedWidth; x = ( 3 * gainedWidth + restWidth ) / 6; pPainter->drawLine( x, -halfTickHeight, x, halfTickHeight ); // 50 % starboard pPainter->drawLine( -x, -halfTickHeight, -x, halfTickHeight ); // 50 % port // Quartermarks x = gainedWidth / 2; pPainter->drawLine( x, 0, x, 0 ); // 25 % starboard pPainter->drawLine( -x, 0, -x, 0 ); // 25 % port x = ( 3 * gainedWidth + 2 * restWidth ) / 6; pPainter->drawLine( x, 0, x, 0 ); // 75 % starboard pPainter->drawLine( -x, -0, -x, 0 ); // 75 % port pPainter->restore(); }
void Location::CutsceneView::CameraManipulatable::DrawCore(QGraphicsScene * pScene, QList<QGraphicsItem *> & addedItems) { QBrush blackBrush(qRgba(0, 0, 0, 255)); QPen blackPen(blackBrush, 4); QPen whitePen(QBrush(qRgba(255, 255, 255, 255)), 2); pOutsideCameraPathItem = new QGraphicsPathItem(); pOutsideCameraPathItem->setBrush(blackBrush); QGraphicsOpacityEffect *pOutsideCameraOpacityEffect = new QGraphicsOpacityEffect(); pOutsideCameraOpacityEffect->setOpacity(0.5); pOutsideCameraPathItem->setGraphicsEffect(pOutsideCameraOpacityEffect); pScene->addItem(pOutsideCameraPathItem); addedItems.append(pOutsideCameraPathItem); pCameraCenterHorizontalOuterLineItem = new QGraphicsLineItem(); pCameraCenterVerticalOuterLineItem = new QGraphicsLineItem(); pCameraCenterHorizontalInnerLineItem = new QGraphicsLineItem(); pCameraCenterVerticalInnerLineItem = new QGraphicsLineItem(); pCameraCenterHorizontalOuterLineItem->setPen(blackPen); pCameraCenterVerticalOuterLineItem->setPen(blackPen); pCameraCenterHorizontalInnerLineItem->setPen(whitePen); pCameraCenterVerticalInnerLineItem->setPen(whitePen); pCameraCenterGraphicsItemGroup = new QGraphicsItemGroup(); pCameraCenterGraphicsItemGroup->addToGroup(pCameraCenterHorizontalOuterLineItem); pCameraCenterGraphicsItemGroup->addToGroup(pCameraCenterVerticalOuterLineItem); pCameraCenterGraphicsItemGroup->addToGroup(pCameraCenterHorizontalInnerLineItem); pCameraCenterGraphicsItemGroup->addToGroup(pCameraCenterVerticalInnerLineItem); pCameraCenterOpacityEffect = new QGraphicsOpacityEffect(); pCameraCenterOpacityEffect->setOpacity(1.0); pCameraCenterGraphicsItemGroup->setGraphicsEffect(pCameraCenterOpacityEffect); pScene->addItem(pCameraCenterGraphicsItemGroup); addedItems.append(pCameraCenterGraphicsItemGroup); }
// Draw the sash void wxSashWindow::DrawSash(wxSashEdgePosition edge, wxDC& dc) { int w, h; GetClientSize(&w, &h); wxPen facePen(m_faceColour, 1, wxSOLID); wxBrush faceBrush(m_faceColour, wxSOLID); wxPen mediumShadowPen(m_mediumShadowColour, 1, wxSOLID); wxPen darkShadowPen(m_darkShadowColour, 1, wxSOLID); wxPen lightShadowPen(m_lightShadowColour, 1, wxSOLID); wxPen hilightPen(m_hilightColour, 1, wxSOLID); wxColour blackClr(0, 0, 0); wxColour whiteClr(255, 255, 255); wxPen blackPen(blackClr, 1, wxSOLID); wxPen whitePen(whiteClr, 1, wxSOLID); if ( edge == wxSASH_LEFT || edge == wxSASH_RIGHT ) { int sashPosition = (edge == wxSASH_LEFT) ? 0 : ( w - GetEdgeMargin(edge) ); dc.SetPen(facePen); dc.SetBrush(faceBrush); dc.DrawRectangle(sashPosition, 0, GetEdgeMargin(edge), h); if (GetWindowStyleFlag() & wxSW_3DSASH) { if (edge == wxSASH_LEFT) { // Draw a dark grey line on the left to indicate that the // sash is raised dc.SetPen(mediumShadowPen); dc.DrawLine(GetEdgeMargin(edge), 0, GetEdgeMargin(edge), h); } else { // Draw a highlight line on the right to indicate that the // sash is raised dc.SetPen(hilightPen); dc.DrawLine(w - GetEdgeMargin(edge), 0, w - GetEdgeMargin(edge), h); } } } else // top or bottom { int sashPosition = (edge == wxSASH_TOP) ? 0 : ( h - GetEdgeMargin(edge) ); dc.SetPen(facePen); dc.SetBrush(faceBrush); dc.DrawRectangle(0, sashPosition, w, GetEdgeMargin(edge)); if (GetWindowStyleFlag() & wxSW_3DSASH) { if (edge == wxSASH_BOTTOM) { // Draw a highlight line on the bottom to indicate that the // sash is raised dc.SetPen(hilightPen); dc.DrawLine(0, h - GetEdgeMargin(edge), w, h - GetEdgeMargin(edge)); } else { // Draw a drak grey line on the top to indicate that the // sash is raised dc.SetPen(mediumShadowPen); dc.DrawLine(1, GetEdgeMargin(edge), w-1, GetEdgeMargin(edge)); } } } dc.SetPen(wxNullPen); dc.SetBrush(wxNullBrush); }
void CAudioLevelIndicator::OnPaint() { CPaintDC dc(this); CRect rcClient; GetClientRect(&rcClient); UINT nPosition = 0; if (m_dAudioLevel >= 0 && m_dAudioLevel <= 1.0) nPosition = (int)(m_dAudioLevel*39); Gdiplus::Graphics graphics(dc); Gdiplus::REAL dScaleX = (Gdiplus::REAL)rcClient.Width() / 13.0; Gdiplus::REAL dScaleY = (Gdiplus::REAL)rcClient.Height() / 40.0; graphics.ScaleTransform(dScaleX, dScaleY); // Border Gdiplus::Pen greyPen(Gdiplus::Color(255, 109, 109, 109), 1); graphics.DrawLine(&greyPen, 0, 0, 0, rcClient.Height()-1); greyPen.SetColor(Gdiplus::Color(255, 168, 168, 168)); graphics.DrawLine(&greyPen, 1, 0, rcClient.Width()-1, 0); greyPen.SetColor(Gdiplus::Color(255, 225, 225, 225)); graphics.DrawLine(&greyPen, rcClient.Width()-1, 1, rcClient.Width()-1, rcClient.Height()); greyPen.SetColor(Gdiplus::Color(255, 215, 215, 215)); graphics.DrawLine(&greyPen, 1, rcClient.Height()-1, rcClient.Width()-2, rcClient.Height()-1); // Background Gdiplus::LinearGradientBrush linGrBrushRY( Gdiplus::Point(0, 1), Gdiplus::Point(0, 16), Gdiplus::Color(255, 124, 47, 47), Gdiplus::Color(255, 174, 165, 65)); Gdiplus::REAL relativeIntensities[] = {0.0f, 0.5f, 1.0f}; Gdiplus::REAL relativePositions[] = {0.0f, 0.25f, 1.0f}; linGrBrushRY.SetBlend(relativeIntensities, relativePositions, 3); Gdiplus::LinearGradientBrush linGrBrushYG( Gdiplus::Point(0, 16), Gdiplus::Point(0, 39), Gdiplus::Color(255, 174, 165, 65), Gdiplus::Color(255, 127, 188, 77)); graphics.FillRectangle(&linGrBrushRY, 1, 1, 11, 16); graphics.FillRectangle(&linGrBrushYG, 1, 17, 11, 22); // highlighting if (nPosition > 0) { Gdiplus::LinearGradientBrush linGrBrushRYBright( Gdiplus::Point(0, 1), Gdiplus::Point(0, 16), Gdiplus::Color(255, 153, 0, 0), Gdiplus::Color(255, 219, 216, 0)); linGrBrushRYBright.SetBlend(relativeIntensities, relativePositions, 3); Gdiplus::LinearGradientBrush linGrBrushYGBright( Gdiplus::Point(0, 16), Gdiplus::Point(0, 39), Gdiplus::Color(255, 219, 216, 0), Gdiplus::Color(255, 107, 233, 0)); int nLowerPosition = nPosition >= 22 ? 0 : 22 - nPosition; graphics.FillRectangle(&linGrBrushYGBright, 1, 17+nLowerPosition, 11, 22-nLowerPosition); if (nPosition > 22) { int nUpperPosition = nPosition >= 39 ? 0 : 38 - nPosition; graphics.FillRectangle(&linGrBrushRYBright, 1, 1+nUpperPosition, 11, 16-nUpperPosition); } Gdiplus::REAL relativeIntensities2[] = {0.0f, 0.1f, 0.0f}; Gdiplus::REAL relativePositions2[] = {0.0f, 0.5f, 1.0f}; Gdiplus::LinearGradientBrush linGrBrushWhiteL( Gdiplus::Point(1, 0), Gdiplus::Point(6, 0), Gdiplus::Color(0, 255, 255, 255), Gdiplus::Color(148, 255, 255, 255)); Gdiplus::LinearGradientBrush linGrBrushWhiteR( Gdiplus::Point(6, 0), Gdiplus::Point(13, 0), Gdiplus::Color(148, 255, 255, 255), Gdiplus::Color(0, 255, 255, 255)); int nUpperPosition = nPosition >= 39 ? 0 : 38 - nPosition; graphics.FillRectangle(&linGrBrushWhiteL, 1, 1+nUpperPosition, 6, 38-nUpperPosition); graphics.FillRectangle(&linGrBrushWhiteR, 7, 1+nUpperPosition, 6, 38-nUpperPosition); Gdiplus::Pen whitePen(Gdiplus::Color(255, 255, 255, 255), 1); graphics.DrawLine(&whitePen, 1, 1+nUpperPosition, 12, 1+nUpperPosition); } }
void CCalendarCtrl::DrawCells(CDC* pDC) { CRect rc; GetClientRect(&rc); int ncHeight = (rc.Height()-CALENDAR_HEADER_HEIGHT)/CALENDAR_ROWS; int ncWidth = rc.Width()/CALENDAR_COLUMNS; CPen whitePen(PS_SOLID, 1, RGB(255,255,255)); CPen blackPen(PS_SOLID, 1, RGB(0,0,0)); CFont* pOldFont = pDC->SelectObject(&m_DefaultFont); CPen* pOldPen = pDC->SelectObject(&blackPen); for(int i=0; i<CALENDAR_ROWS ; i++) { for(int u=0; u<CALENDAR_COLUMNS ; u++) { CRect rect; if(GetRectFromCell(i, u, rect)) { if(u == CALENDAR_COLUMNS-1) rect.right = rc.right; if(i == CALENDAR_ROWS-1) rect.bottom = rc.bottom; if((m_bMonthIsOdd && !(m_dayCells[i][u].date.GetMonth()%2)) || (!m_bMonthIsOdd && (m_dayCells[i][u].date.GetMonth()%2))) { CBrush br; br.CreateSolidBrush(CALENDAR_LIGHTGREY); pDC->FillRect(&rect ,&br); } COleDateTime today(time(NULL)); bool btoday = false; if(today.GetDay() == m_dayCells[i][u].date.GetDay() && today.GetMonth() == m_dayCells[i][u].date.GetMonth() && today.GetYear() == m_dayCells[i][u].date.GetYear()) { // Draw the frame CRect rcLine(rect); rcLine.bottom = rcLine.top+15; rcLine.top = rcLine.bottom-1; for(int c=0; c<15; c++) { pDC->FillSolidRect(rcLine, GetFadedBlue(c*6)); rcLine.bottom--; rcLine.top = rcLine.bottom-1; } btoday = true; } // Draw the selection bool bSelected = false; time_t tmax = max(m_SelectionRange[0], m_SelectionRange[1]); time_t tmin = min(m_SelectionRange[0], m_SelectionRange[1]); time_t tcur = DateToSeconds(m_dayCells[i][u].date); if(m_RandomSelection.GetCount()) { POSITION pos = m_RandomSelection.GetStartPosition(); while (pos){ void* p; DWORD date; m_RandomSelection.GetNextAssoc(pos, (void*&)date, p); if(date == (DWORD)tcur) { CBrush br; br.CreateSolidBrush(GetFadedBlue(70)); CRect selRect(rect); if(btoday) selRect.top += 15; pDC->FillRect(&selRect, &br); bSelected = true; } } if(m_SelectionRange[2] == tcur) { rect.left+=2; rect.right -=1; rect.top+=2; rect.bottom -=1; pDC->DrawFocusRect(rect); } } else if((tmax >= tcur) && (tcur >= tmin)) { CRect selRect(rect); CBrush br; br.CreateSolidBrush(GetFadedBlue(70)); if(btoday) selRect.top += 15; pDC->FillRect(&selRect, &br); bSelected = true; } // Out of range if( (m_dayCells[i][u].date >= m_BoundUp) || (m_dayCells[i][u].date <= m_BoundDown) ) { CRect selRect(rect); CBrush br; br.CreateSolidBrush(RGB(255,225,225)); pDC->FillRect(&selRect, &br); } if(m_dayCells[i][u].bMark) { CBrush br; br.CreateSolidBrush(RGB(255,104,4)); CRect rcMark(rect); rcMark.DeflateRect(3,3); rcMark.right = rcMark.left +6; rcMark.bottom = rcMark.top +6; pDC->FillRect(&rcMark, &br); } // draw inside... rect.DeflateRect(1,1); CString csDay; int nDay = m_dayCells[i][u].date.GetDay(); if(nDay == 1 || (i==0 && u==0)) { csDay.Format(_T("%s %d"), m_dayCells[i][u].date.Format(_T("%B")), nDay); CSize dtSize(pDC->GetTextExtent(csDay)); if(dtSize.cx>rect.Width()) csDay.Format(_T("%s %d"), m_dayCells[i][u].date.Format(_T("%b")), nDay); } else csDay.Format(_T("%d"), nDay); unsigned long nColor; if(bSelected && !btoday) nColor = pDC->SetTextColor(RGB(255,104,4)); else nColor = pDC->SetTextColor(RGB(0,0,0)); pDC->DrawText(csDay, rect, DT_RIGHT|DT_TOP); pDC->SetTextColor(nColor); // Draw the cell content if possible if(rect.Width() >= 15) { for (int j=0; j<m_dayCells[i][u].csaLines.GetSize(); j++) { CRect txtRect(rect); CRect dotRect(rect); txtRect.left += 9; //CALENDAR_LINE_HEIGHT; txtRect.right-= 2; txtRect.top += (j+1)*CALENDAR_LINE_HEIGHT; dotRect.top += (j+1)*CALENDAR_LINE_HEIGHT+(CALENDAR_LINE_HEIGHT/2-1); dotRect.bottom = dotRect.top + 3; dotRect.left += 3; dotRect.right = dotRect.left +3; m_dayCells[i][u].bPartial = false; if(!m_dayCells[i][u].csaLines[j].IsEmpty() && txtRect.Height() > CALENDAR_LINE_HEIGHT) { pDC->SetTextColor(RGB(0,0,0)); pDC->DrawText(m_dayCells[i][u].csaLines[j], txtRect, DT_LEFT|DT_TOP); CBrush br; br.CreateSolidBrush(RGB(125,175,255)); pDC->FillRect(&dotRect, &br); } else if(!m_dayCells[i][u].csaLines[j].IsEmpty()) { CPen dotPen(PS_SOLID, 1, RGB(170,170,170)); pDC->SelectObject(&dotPen); // Draw a little arrow static int t[2][7] = {5,5,8,8,8,5,5,4,3,2,1,2,3,4}; int n = 0; for(int r=7; r>0; r--){ pDC->MoveTo(rect.right-9+r, rect.bottom-t[0][n]); pDC->LineTo(rect.right-9+r, rect.bottom-t[1][n]); n++; } m_dayCells[i][u].bPartial = true; break; } } } } } } pDC->SelectObject(pOldFont); pDC->SelectObject(pOldPen); }
void QADI::paintEvent(QPaintEvent *) { QPainter painter(this); QBrush bgSky(QColor(48,172,220)); QBrush bgGround(QColor(247,168,21)); QPen whitePen(Qt::white); QPen blackPen(Qt::black); QPen pitchPen(Qt::white); QPen pitchZero(Qt::green); whitePen.setWidth(2); blackPen.setWidth(2); pitchZero.setWidth(3); painter.setRenderHint(QPainter::Antialiasing); painter.translate(width() / 2, height() / 2); painter.rotate(m_roll); // FIXME: AHRS output left-hand values double pitch_tem = -m_pitch; // draw background { int y_min, y_max; y_min = m_size/2*-40.0/45.0; y_max = m_size/2* 40.0/45.0; int y = m_size/2*pitch_tem/45.; if( y < y_min ) y = y_min; if( y > y_max ) y = y_max; int x = sqrt(m_size*m_size/4 - y*y); qreal gr = atan((double)(y)/x); gr = gr * 180./3.1415926; painter.setPen(blackPen); painter.setBrush(bgSky); painter.drawChord(-m_size/2, -m_size/2, m_size, m_size, gr*16, (180-2*gr)*16); painter.setBrush(bgGround); painter.drawChord(-m_size/2, -m_size/2, m_size, m_size, gr*16, -(180+2*gr)*16); } // set mask QRegion maskRegion(-m_size/2, -m_size/2, m_size, m_size, QRegion::Ellipse); painter.setClipRegion(maskRegion); // draw pitch lines & marker { int x, y, x1, y1; int textWidth; double p, r; int ll = m_size/8, l; int fontSize = 8; QString s; pitchPen.setWidth(2); painter.setFont(QFont("", fontSize)); // draw lines for(int i=-9; i<=9; i++) { p = i*10; s = QString("%1").arg(-p); if( i % 3 == 0 ) l = ll; else l = ll/2; if( i == 0 ) { painter.setPen(pitchZero); l = l * 1.8; } else { painter.setPen(pitchPen); } y = m_size/2*p/45.0 - m_size/2*pitch_tem/45.; x = l; r = sqrt(x*x + y*y); if( r > m_size/2 ) continue; painter.drawLine(QPointF(-l, 1.0*y), QPointF(l, 1.0*y)); textWidth = 100; if( i % 3 == 0 && i != 0 ) { painter.setPen(QPen(Qt::white)); x1 = -x-2-textWidth; y1 = y - fontSize/2 - 1; painter.drawText(QRectF(x1, y1, textWidth, fontSize+2), Qt::AlignRight|Qt::AlignVCenter, s); } } // draw marker int markerSize = m_size/20; float fx1, fy1, fx2, fy2, fx3, fy3; painter.setBrush(QBrush(Qt::red)); painter.setPen(Qt::NoPen); fx1 = markerSize; fy1 = 0; fx2 = fx1 + markerSize; fy2 = -markerSize/2; fx3 = fx1 + markerSize; fy3 = markerSize/2; QPointF points[3] = { QPointF(fx1, fy1), QPointF(fx2, fy2), QPointF(fx3, fy3) }; painter.drawPolygon(points, 3); QPointF points2[3] = { QPointF(-fx1, fy1), QPointF(-fx2, fy2), QPointF(-fx3, fy3) }; painter.drawPolygon(points2, 3); } // draw roll degree lines { int nRollLines = 36; float rotAng = 360.0 / nRollLines; int rollLineLeng = m_size/25; double fx1, fy1, fx2, fy2; int fontSize = 8; QString s; blackPen.setWidth(1); painter.setPen(blackPen); painter.setFont(QFont("", fontSize)); for(int i=0; i<nRollLines; i++) { if( i < nRollLines/2 ) s = QString("%1").arg(-i*rotAng); else s = QString("%1").arg(360-i*rotAng); fx1 = 0; fy1 = -m_size/2 + m_offset; fx2 = 0; if( i % 3 == 0 ) { fy2 = fy1 + rollLineLeng; painter.drawLine(QPointF(fx1, fy1), QPointF(fx2, fy2)); fy2 = fy1 + rollLineLeng+2; painter.drawText(QRectF(-50, fy2, 100, fontSize+2), Qt::AlignCenter, s); } else { fy2 = fy1 + rollLineLeng/2; painter.drawLine(QPointF(fx1, fy1), QPointF(fx2, fy2)); } painter.rotate(rotAng); } } // draw roll marker { int rollMarkerSize = m_size/25; double fx1, fy1, fx2, fy2, fx3, fy3; painter.rotate(-m_roll); painter.setBrush(QBrush(Qt::black)); fx1 = 0; fy1 = -m_size/2 + m_offset; fx2 = fx1 - rollMarkerSize/2; fy2 = fy1 + rollMarkerSize; fx3 = fx1 + rollMarkerSize/2; fy3 = fy1 + rollMarkerSize; QPointF points[3] = { QPointF(fx1, fy1), QPointF(fx2, fy2), QPointF(fx3, fy3) }; painter.drawPolygon(points, 3); } }
void QCompass::paintEvent(QPaintEvent *) { QPainter painter(this); QBrush bgGround(QColor(48,172,220)); QPen whitePen(Qt::white); QPen blackPen(Qt::black); QPen redPen(Qt::red); QPen bluePen(Qt::blue); QPen greenPen(Qt::green); whitePen.setWidth(1); blackPen.setWidth(2); redPen.setWidth(2); bluePen.setWidth(2); greenPen.setWidth(2); painter.setRenderHint(QPainter::Antialiasing); painter.translate(width() / 2, height() / 2); // draw background { painter.setPen(blackPen); painter.setBrush(bgGround); painter.drawEllipse(-m_size/2, -m_size/2, m_size, m_size); } // draw yaw lines { int nyawLines = 36; float rotAng = 360.0 / nyawLines; int yawLineLeng = m_size/25; double fx1, fy1, fx2, fy2; int fontSize = 8; QString s; blackPen.setWidth(1); painter.setPen(blackPen); for(int i=0; i<nyawLines; i++) { if( i == 0 ) { s = "N"; painter.setPen(bluePen); painter.setFont(QFont("", fontSize*1.3)); } else if ( i == 9 ) { s = "W"; painter.setPen(blackPen); painter.setFont(QFont("", fontSize*1.3)); } else if ( i == 18 ) { s = "S"; painter.setPen(redPen); painter.setFont(QFont("", fontSize*1.3)); } else if ( i == 27 ) { s = "E"; painter.setPen(blackPen); painter.setFont(QFont("", fontSize*1.3)); } else { s = QString("%1").arg(i*rotAng); painter.setPen(blackPen); painter.setFont(QFont("", fontSize)); } fx1 = 0; fy1 = -m_size/2 + m_offset; fx2 = 0; if( i % 3 == 0 ) { fy2 = fy1 + yawLineLeng; painter.drawLine(QPointF(fx1, fy1), QPointF(fx2, fy2)); fy2 = fy1 + yawLineLeng+4; painter.drawText(QRectF(-50, fy2, 100, fontSize+2), Qt::AlignCenter, s); } else { fy2 = fy1 + yawLineLeng/2; painter.drawLine(QPointF(fx1, fy1), QPointF(fx2, fy2)); } painter.rotate(-rotAng); } } // draw S/N arrow { int arrowWidth = m_size/5; double fx1, fy1, fx2, fy2, fx3, fy3; fx1 = 0; fy1 = -m_size/2 + m_offset + m_size/25 + 15; fx2 = -arrowWidth/2; fy2 = 0; fx3 = arrowWidth/2; fy3 = 0; painter.setPen(Qt::NoPen); painter.setBrush(QBrush(Qt::blue)); QPointF pointsN[3] = { QPointF(fx1, fy1), QPointF(fx2, fy2), QPointF(fx3, fy3) }; painter.drawPolygon(pointsN, 3); fx1 = 0; fy1 = m_size/2 - m_offset - m_size/25 - 15; fx2 = -arrowWidth/2; fy2 = 0; fx3 = arrowWidth/2; fy3 = 0; painter.setBrush(QBrush(Qt::red)); QPointF pointsS[3] = { QPointF(fx1, fy1), QPointF(fx2, fy2), QPointF(fx3, fy3) }; painter.drawPolygon(pointsS, 3); } // draw yaw marker { int yawMarkerSize = m_size/12; double fx1, fy1, fx2, fy2, fx3, fy3; painter.rotate(-m_yaw); painter.setBrush(QBrush(QColor(0xFF, 0x00, 0x00, 0xE0))); fx1 = 0; fy1 = -m_size/2 + m_offset; fx2 = fx1 - yawMarkerSize/2; fy2 = fy1 + yawMarkerSize; fx3 = fx1 + yawMarkerSize/2; fy3 = fy1 + yawMarkerSize; QPointF points[3] = { QPointF(fx1, fy1), QPointF(fx2, fy2), QPointF(fx3, fy3) }; painter.drawPolygon(points, 3); painter.rotate(m_yaw); } // draw altitude { int altFontSize = 13; int fx, fy, w, h; QString s; char buf[200]; w = 130; h = 2*(altFontSize + 8); fx = -w/2; fy = -h/2; blackPen.setWidth(2); painter.setPen(blackPen); painter.setBrush(QBrush(Qt::white)); painter.setFont(QFont("", altFontSize)); painter.drawRoundedRect(fx, fy, w, h, 6, 6); painter.setPen(bluePen); sprintf(buf, "ALT: %6.1f m", m_alt); s = buf; painter.drawText(QRectF(fx, fy+2, w, h/2), Qt::AlignCenter, s); sprintf(buf, "H: %6.1f m", m_h); s = buf; painter.drawText(QRectF(fx, fy+h/2, w, h/2), Qt::AlignCenter, s); } }
// WaveformViewDialog message handlers void WaveformViewDialog::OnPaint() { BufferredPaintDC dc(this); CRect rectTitle; GetDlgItem(IDC_PLACE_CAPTION)->GetWindowRect(&rectTitle); ScreenToClient(&rectTitle); dc.FillSolidRect(rectTitle, RGB(54, 133, 214)); CRect waveformRect; GetDlgItem(IDC_PLACE_WAVEFORM)->GetWindowRect(&waveformRect); ScreenToClient(&waveformRect); dc.FillSolidRect(waveformRect, RGB(0, 0, 0)); CFont *oldFont = dc.SelectObject(GuiResources::GetInstance()->GetFont(GuiResources::FONT_NORMAL)); dc.SetTextColor(RGB(255, 255, 255)); dc.SetBkMode(TRANSPARENT); CSize textSize = dc.GetTextExtent(_T("88888")); waveformRect.left += textSize.cx + 8; if (monitor_ != NULL && cashIndex_ != -1) { int cashCount = monitor_->Freeze(); if (cashIndex_ < cashCount) { Cash *cash = monitor_->GetCash(cashIndex_); CPen penYellow(PS_SOLID, 1, RGB(255, 255, 0)); CPen penGreen(PS_SOLID, 1, RGB(0, 255, 0)); int count = cash->GetADCSampleCount(g_ADCChannels[channel_].id); if (count > 0) { CString title; title.Format(_T("%s - %s"), (LPCTSTR)CA2T(cash->GetSN()), g_ADCChannels[channel_].name); labelTitle_.SetWindowText(title); const short *codes = cash->GetADCSampleCodes(g_ADCChannels[channel_].id); const short *values = cash->GetADCSampleValues(g_ADCChannels[channel_].id); // draw scaler __int64 sum = 0; short minValue = SHORT_MAX, maxValue = SHORT_MIN; for (int i = 0; i < count; i++) { if (values[i] < minValue) { minValue = values[i]; } if (values[i] > maxValue) { maxValue = values[i]; } sum += values[i]; } CPen whitePen(PS_SOLID, 1, RGB(255, 255, 255)); CPen *oldPen = dc.SelectObject(&whitePen); dc.MoveTo(waveformRect.left, waveformRect.top); dc.LineTo(waveformRect.left, waveformRect.bottom); int height = waveformRect.Height(); int range = g_ADCChannels[channel_].maxValue - g_ADCChannels[channel_].minValue; // min CString label; int x = waveformRect.left - textSize.cx - 8; int y = waveformRect.bottom - (minValue - g_ADCChannels[channel_].minValue) * height / range; dc.MoveTo(waveformRect.left - 4, y); dc.LineTo(waveformRect.right, y); label.Format(_T("%d"), minValue); dc.TextOut(x, y - textSize.cy / 2, label); // center short median = (short)(sum / count); y = waveformRect.bottom - (median - g_ADCChannels[channel_].minValue) * height / range; dc.MoveTo(waveformRect.left - 4, y); dc.LineTo(waveformRect.right, y); label.Format(_T("%d"), median); dc.TextOut(x, y - textSize.cy / 2, label); // max y = waveformRect.bottom - (maxValue - g_ADCChannels[channel_].minValue) * height / range; dc.MoveTo(waveformRect.left - 4, y); dc.LineTo(waveformRect.right, y); label.Format(_T("%d"), maxValue); dc.TextOut(x, y - textSize.cy / 2, label); dc.SelectObject(oldPen); ::DrawWaveform(&dc, waveformRect, codes, codes[0], codes[count - 1], count, &penYellow); ::DrawWaveform(&dc, waveformRect, values, g_ADCChannels[channel_].minValue, g_ADCChannels[channel_].maxValue, count, &penGreen); } } monitor_->Unfreeze(); } dc.SelectObject(oldFont); }
void BehavePlusApp::drawSplashPage( void ) { // If unable to load the picture, make a plain cyan backdrop instead if ( m_pixmap.isNull() ) // This code block should never be executed! { m_pixmap.resize( 700, 500 ); QPainter paint( &m_pixmap ); paint.fillRect( 0, 0, 700, 500, QBrush( "cyan", SolidPattern ) ); paint.end(); } // Painter attributes int align = Qt::AlignHCenter | Qt::AlignTop ; //static QString fontName( "Times New Roman" ); static QString fontName( "Arial" ); QFont fnt1( fontName, 48, QFont::Bold, false ); QFont fnt2( fontName, 24, QFont::Bold, false ); QFont fnt3( fontName, 16, QFont::Bold, false ); QFontMetrics fm1( fnt1 ); QFontMetrics fm2( fnt2 ); QFontMetrics fm3( fnt3 ); QPen blackPen( black ); QPen grayPen( gray ); QPen redPen( red ); QPen whitePen( white ); // Draw shadowed name QPainter paint( &m_pixmap ); int wd = m_pixmap.width(); int ht = m_pixmap.height() + 3 * fm3.lineSpacing(); paint.setFont( fnt1 ); paint.setPen( grayPen ); int y0 = fm1.lineSpacing()/8; paint.drawText( 4, y0+4, wd, ht, align, m_program ); paint.setPen( blackPen ); paint.drawText( 2, y0+2, wd, ht, align, m_program ); paint.setPen( whitePen ); paint.drawText( 0, y0, wd, ht, align, m_program ); // Draw sub name and version y0 += 3*fm1.lineSpacing()/4; paint.setFont( fnt2 ); paint.drawText( 0, y0, wd, ht-y0, align, "fire modeling system" ); y0 += 3*fm2.lineSpacing()/4; paint.drawText( 0, y0, wd, ht-y0, align, "Version " + m_version ); // Warning if ( ShowWarning ) { y0 += 3 * fm2.lineSpacing(); paint.setFont( fnt2 ); paint.setPen( redPen ); paint.drawText( 0, y0, wd, ht-y0, align, "This is pre-release software" ); y0 += fm2.lineSpacing(); paint.drawText( 0, y0, wd, ht-y0, align, "for testing purposes only!" ); y0 += fm2.lineSpacing(); paint.drawText( 0, y0, wd, ht-y0, align, "Use at Your Own Risk!" ); } // Authors y0 = ht - 6 * fm3.lineSpacing(); paint.setFont( fnt3 ); paint.setPen( whitePen ); paint.drawText( 0, y0, wd, ht-y0, align, "US Forest Service, Rocky Mountain Research Station" ); y0 += fm3.lineSpacing(); paint.drawText( 0, y0, wd, ht-y0, align, "& Systems for Environmental Management" ); paint.end(); // Status message display area m_statusLine = ht - 2 * fm3.lineSpacing(); return; }
void GLCanvas::drawUserInterface(wxDC &dc) const { wxSize size = GetSize(); wxPoint pos(0, 0); pos.x = size.x - _buttonSize; wxSize buttonSize(_buttonSize, _buttonSize); wxPen whitePen(wxColour(255, 255, 255)); whitePen.SetWidth(1); wxPen blackPen(wxColour(0, 0, 0)); blackPen.SetWidth(1); wxPen greenPen(wxColour(0, 255, 0)); wxBrush brush; dc.SetPen(blackPen); brush.SetColour(wxColour(0, 0, 0)); dc.SetBrush(brush); // draw black background behind all buttons dc.DrawRectangle(pos.x - 1, pos.y, _buttonSize + 1, _numButtons * _buttonSize + 1); // draw grit if (_style & DRAW_GRID) { dc.SetPen(greenPen); } else { dc.SetPen(whitePen); } dc.DrawRectangle(pos.x + 1, pos.y + 1, _buttonSize - 2, _buttonSize - 2); dc.DrawLine(pos.x + _buttonSizeHalf, pos.y + 1, pos.x + _buttonSizeHalf, pos.y + _buttonSize - 1); dc.DrawLine(pos.x + 1, pos.y + _buttonSizeHalf, size.x - 1, pos.y + _buttonSizeHalf); pos.y += _buttonSize; // draw a cube for showing AABB if (_style & DRAW_AABB) { dc.SetPen(greenPen); } else { dc.SetPen(whitePen); } dc.DrawRectangle(pos.x + _buttonSizeHalf - 3, pos.y + 3, _buttonSizeHalf, _buttonSizeHalf); dc.DrawRectangle(pos.x + 2, pos.y + _buttonSizeHalf - 2, _buttonSizeHalf, _buttonSizeHalf); dc.DrawLine(pos.x + 2, pos.y + _buttonSizeHalf - 2, pos.x + _buttonSizeHalf - 3, pos.y + 3); dc.DrawLine(pos.x + 2 + _buttonSizeHalf, pos.y + _buttonSizeHalf - 2, pos.x + _buttonSize - 3, pos.y + 3); dc.DrawLine(pos.x + 2 + _buttonSizeHalf, pos.y + _buttonSize - 3, pos.x + _buttonSize - 3, pos.y + _buttonSizeHalf + 2); pos.y += _buttonSize; // draw coordinate system if (_style & DRAW_LOCAL_COORDINATE_SYSTEM) { dc.SetPen(greenPen); } else { dc.SetPen(whitePen); } dc.DrawLine(pos.x + 2, pos.y + 3, pos.x + 2, pos.y + _buttonSize - 2); dc.DrawLine(pos.x + 2, pos.y + _buttonSize - 2, size.x - 3, pos.y + _buttonSize - 2); dc.DrawLine(pos.x + 2, pos.y + _buttonSize - 2, pos.x + _buttonSize - 6, pos.y + _buttonSizeHalf + 2); pos.y += _buttonSize; // draw joint constraints if (_style & DRAW_JOINT_CONSTRAINTS) { dc.SetPen(greenPen); } else { dc.SetPen(whitePen); } //dc.DrawCircle(pos.x + _buttonSizeHalf, pos.y + _buttonSizeHalf, _buttonSizeHalf - 3); //dc.DrawArc(pos.x + 4, pos.y + 5, pos.x + 4, pos.y + _buttonSize - 5, pos.x + _buttonSizeHalf + 2, pos.y + _buttonSizeHalf); //dc.DrawCircle(pos.x + 6, pos.y + _buttonSizeHalf, 3); dc.DrawEllipse(pos.x + 4, pos.y + 3, _buttonSizeHalf - 5, _buttonSizeHalf + 4); dc.DrawLine(pos.x + 8, pos.y + 3, pos.x + _buttonSizeHalf + 5, pos.y + _buttonSizeHalf); dc.DrawLine(pos.x + 8, pos.y + _buttonSizeHalf + 7, pos.x + _buttonSizeHalf + 5, pos.y + _buttonSizeHalf); pos.y += _buttonSize; // draw rotation axis if (_style & DRAW_ROTATION_AXIS) { dc.SetPen(greenPen); } else { dc.SetPen(whitePen); } dc.DrawArc(pos.x + _buttonSizeHalf + 2, pos.y + _buttonSize - 2, pos.x + _buttonSizeHalf, pos.y + _buttonSizeHalf + 1, pos.x + 2, pos.y + _buttonSize - 2); //dc.DrawEllipse(pos.x + 6, pos.y + 5, _buttonSize - 12, _buttonSize - 10); //dc.DrawCircle(pos.x + _buttonSizeHalf + 2, pos.y + _buttonSizeHalf - 2, 3); dc.DrawLine(pos.x + 2, pos.y + _buttonSize - 2, pos.x + _buttonSize - 2, pos.y + 2); dc.DrawLine(pos.x + 2, pos.y + _buttonSize - 2, pos.x + _buttonSize - 2, pos.y + _buttonSize - 2); pos.y += _buttonSize; // draw label if (_style & DRAW_LABEL) { dc.SetPen(greenPen); } else { dc.SetPen(whitePen); } dc.DrawRoundedRectangle(pos.x + 4, pos.y + 3, _buttonSize - 5, _buttonSizeHalf, 3.0); dc.DrawSpline(pos.x + 4, pos.y + _buttonSizeHalf - 3, pos.x + 1, pos.y + _buttonSizeHalf + 4, pos.x + _buttonSizeHalf + 4, pos.y + _buttonSizeHalf + 6); pos.y += _buttonSize; // draw locate skeleton button dc.SetPen(whitePen); dc.DrawLine(pos.x + _buttonSizeHalf, pos.y + 2, pos.x + _buttonSizeHalf, pos.y + _buttonSize - 1); dc.DrawLine(pos.x + 2, pos.y + _buttonSizeHalf, size.x - 1, pos.y + _buttonSizeHalf); dc.DrawCircle(pos.x + _buttonSizeHalf, pos.y + _buttonSizeHalf, _buttonSizeHalf - 4); brush.SetColour(wxColour(255, 255, 255)); dc.SetBrush(brush); dc.DrawCircle(pos.x + _buttonSizeHalf, pos.y + _buttonSizeHalf, _buttonSizeHalf - 8); pos.y += _buttonSize; // draw settings button dc.DrawCircle(pos.x + _buttonSizeHalf, pos.y + _buttonSizeHalf, _buttonSizeHalf - 3); dc.SetPen(blackPen); brush.SetColour(wxColour(0, 0, 0)); dc.SetBrush(brush); dc.DrawCircle(pos.x + _buttonSizeHalf + 6, pos.y + _buttonSizeHalf, 2); dc.DrawCircle(pos.x + _buttonSizeHalf - 6, pos.y + _buttonSizeHalf, 2); dc.DrawCircle(pos.x + _buttonSizeHalf, pos.y + _buttonSizeHalf + 6, 2); dc.DrawCircle(pos.x + _buttonSizeHalf, pos.y + _buttonSizeHalf - 6, 2); dc.SetPen(whitePen); dc.DrawCircle(pos.x + _buttonSizeHalf, pos.y + _buttonSizeHalf, _buttonSizeHalf - 7); }