void paintCar( QPainter *p ) // paint a car { QPointArray a; QBrush brush( Qt::yellow, Qt::SolidPattern ); p->setBrush( brush ); // use solid, yellow brush a.setPoints( 5, 50,50, 350,50, 450,120, 450,250, 50,250 ); p->drawPolygon( a ); // draw car body QFont f( "courier", 12, QFont::Bold ); p->setFont( f ); QColor windowColor( 120, 120, 255 ); // a light blue color brush.setColor( windowColor ); // set this brush color p->setBrush( brush ); // set brush p->drawRect( 80, 80, 250, 70 ); // car window p->drawText( 180, 80, 150, 70, Qt::AlignCenter, "-- Qt --\nTrolltech AS" ); QPixmap pixmap; if ( pixmap.load("flag.bmp") ) // load and draw image p->drawPixmap( 100, 85, pixmap ); p->setBackgroundMode( Qt::OpaqueMode ); // set opaque mode p->setBrush( Qt::DiagCrossPattern ); // black diagonal cross pattern p->drawEllipse( 90, 210, 80, 80 ); // back wheel p->setBrush( Qt::CrossPattern ); // black cross fill pattern p->drawEllipse( 310, 210, 80, 80 ); // front wheel }
void ProgressBar::paintEvent(QPaintEvent * /*event*/) { QPainter painter(this); QColor bufferColor(0, 0, 255); QColor windowColor(0, 255, 0); #ifdef SUPERIMPOSE_PROGRESS_ON_WAVEFORM bufferColor.setAlphaF(0.5); windowColor.setAlphaF(0.5); #else painter.fillRect(rect(), Qt::black); #endif if (m_bufferLength) { QRect bar = rect(); const qreal play = qreal(m_playPosition) / m_bufferLength; bar.setLeft(rect().left() + play * rect().width()); const qreal record = qreal(m_recordPosition) / m_bufferLength; bar.setRight(rect().left() + record * rect().width()); painter.fillRect(bar, bufferColor); QRect window = rect(); const qreal windowLeft = qreal(m_windowPosition) / m_bufferLength; window.setLeft(rect().left() + windowLeft * rect().width()); const qreal windowWidth = qreal(m_windowLength) / m_bufferLength; window.setWidth(windowWidth * rect().width()); painter.fillRect(window, windowColor); } }
void ProgressBarWidget::paintEvent(QPaintEvent *pEvent) { // Draw ourselves and accept the event QPainter painter(this); if (isEnabled()) { int value = int(mValue*width()); if (value != 0) { painter.fillRect(0, 0, value, height(), highlightColor()); } if (value != width()) { painter.fillRect(value, 0, width()-value, height(), windowColor()); } } else { painter.fillRect(0, 0, width(), height(), windowColor()); } pEvent->accept(); }
//--------------------------------------------------------------------------- void DeveloperConsole::RenderConsole( const unsigned int shaderProgramID ) { float inputBoxOffset = 5.f; Vertex3D vertices[ 8 ]; Vec2f inputWindowMins( 0.f, 0.f ); Vec2f inputWindowMaxes( GAME_WINDOW_X, m_fontCellHeight + inputBoxOffset ); Vec2f logWindowMins( 0.f, m_fontCellHeight + inputBoxOffset * 2.f ); Vec2f logWindowMaxes( GAME_WINDOW_X, GAME_WINDOW_Y ); Rgba windowColor( 0, 0, 0, 125 ); Rgba commandTextColor( Colors::WHITE ); // g_theRenderer->VennLoadIdentity(); // g_theRenderer->VennOrtho( 0.f, GAME_WINDOW_X, 0.f, GAME_WINDOW_Y, 0.f, 1.f ); // g_theRenderer->ApplyOrthoProjection( 0.f, GAME_WINDOW_X, 0.f, GAME_WINDOW_Y, 0.f, 1.f ); // the input window vertices[ 0 ].m_position = Vec3f( inputWindowMins.x, inputWindowMins.y, 0.f ); vertices[ 0 ].m_color = windowColor; vertices[ 1 ].m_position = Vec3f( inputWindowMins.x, inputWindowMaxes.y, 0.f ); vertices[ 1 ].m_color = windowColor; vertices[ 2 ].m_position = Vec3f( inputWindowMaxes.x, inputWindowMaxes.y, 0.f ); vertices[ 2 ].m_color = windowColor; vertices[ 3 ].m_position = Vec3f( inputWindowMaxes.x, inputWindowMins.y, 0.f ); vertices[ 3 ].m_color = windowColor; // render the log window vertices[ 4 ].m_position = Vec3f( logWindowMins.x, logWindowMins.y, 0.f ); vertices[ 4 ].m_color = windowColor; vertices[ 5 ].m_position = Vec3f( logWindowMins.x, logWindowMaxes.y, 0.f ); vertices[ 5 ].m_color = windowColor; vertices[ 6 ].m_position = Vec3f( logWindowMaxes.x, logWindowMaxes.y, 0.f ); vertices[ 6 ].m_color = windowColor; vertices[ 7 ].m_position = Vec3f( logWindowMaxes.x, logWindowMins.y, 0.f ); vertices[ 7 ].m_color = windowColor; // g_theRenderer->VennEnableClientState( V_VERTEX_ARRAY ); // g_theRenderer->VennEnableClientState( V_COLOR_ARRAY ); // // g_theRenderer->VennVertexPointer( 3, V_FLOAT, sizeof( Vertex3D ), &vertices[0].m_position ); // g_theRenderer->VennColorPointer( 4, V_FLOAT, sizeof( Vertex3D ), &vertices[0].m_color ); // // g_theRenderer->VennDrawArrays( V_QUADS, 0, 8 ); // // g_theRenderer->VennDisableClientState( V_VERTEX_ARRAY ); // g_theRenderer->VennDisableClientState( V_COLOR_ARRAY ); RenderVertexArrayWithShader( vertices, 8, shaderProgramID, V_QUADS ); // render current command string m_textRenderer->RenderText2D( m_currentConsoleCommandString.c_str(), m_fontCellHeight, Vec2f( inputWindowMins.x, inputWindowMins.y ), commandTextColor, shaderProgramID ); // render log lines for ( unsigned int index = m_logLines.size(); index > 0; --index ) { if ( logWindowMins.y >= GAME_WINDOW_Y ) break; CommandLogLine& currentLine = m_logLines[ index - 1 ]; m_textRenderer->RenderText2D( currentLine.m_text.c_str(), m_fontCellHeight, logWindowMins, currentLine.m_color, shaderProgramID ); logWindowMins.y += m_fontCellHeight + inputBoxOffset; } }