예제 #1
0
void Histogram::paintCannon ( QPainter * p)
{
  QRect cr = contentsRect();

  int w = cr.width();
  int h = cr.height();
  QPixmap pix( cr.size() );
  QPainter tmp( &pix );
  tmp.setPen( Qt::NoPen );
  tmp.setFont(p->font());
  int hlevel = 0;
  if (orientation == 0) {
    if ( _sourcer )
      hlevel = (int) ((1.0 - _sourcer->valuePerc() ) * h);
    tmp.setBrush( cBack );
    tmp.drawRect( QRect( 0, 0, w, hlevel) );
    tmp.setBrush( barColor() );
    tmp.drawRect( QRect( QPoint( 0, hlevel), QPoint( w, h ) ) );
  } 
  else {
    if ( _sourcer ) {
      hlevel = (int) ( _sourcer->valuePerc()  * w);
    }

    tmp.setBrush( cBack );
    tmp.drawRect( QRect( hlevel,0, w, h) );
    tmp.setBrush( barColor() );
    tmp.drawRect( QRect( 0,0, hlevel,h));
  };

  tmp.end();
  p->drawPixmap( cr.topLeft(), pix );
}
예제 #2
0
//绘制频谱
void Spectrograph::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event)

    QPainter painter(this);
	//QPixmap backgroundImage;
	//backgroundImage.load(":/images/screen.png");
	////先通过pix的方法获得图片的过滤掉透明的部分得到的图片,作为loginPanel的不规则边框
	//this ->setMask(backgroundImage.mask());
	//painter.drawPixmap(0, 0, 190, 78, backgroundImage);

    const int numBars = m_bars.count();

	QColor barColor(5, 184, 204);		//频谱bar颜色
	QColor clipColor(255, 0, 0);		//频谱被截断后的颜色

    barColor = barColor.lighter();
    barColor.setAlphaF(0.75);		//设置alpha通道
    clipColor.setAlphaF(0.75);

    //绘制频谱
    if (numBars)
	{
        //计算宽度的条和空白
        const int widgetWidth = rect().width();										//频谱widget宽度
        const int barPlusGapWidth = widgetWidth / numBars;							//每一个频谱加空白间隙的宽度
        const int barWidth = 0.8 * barPlusGapWidth;									//每一个频谱bar的宽度
        const int gapWidth = barPlusGapWidth - barWidth;							//每一个空白间隙宽度
        const int paddingWidth = widgetWidth - numBars * (barWidth + gapWidth);		//边缘宽度
        const int leftPaddingWidth = (paddingWidth + gapWidth) / 2;					//左边缘宽度
        const int barHeight = rect().height() - 2 * gapWidth;						//每一个频谱bar的高度

		//绘制每一个频谱bar
        for (int i = 0; i < numBars; ++i)
		{
            const double value = m_bars[i].value;
            Q_ASSERT(value >= 0.0 && value <= 1.0);
            QRect bar = rect();

			//设置频谱bar的位置和大小
            bar.setLeft(rect().left() + leftPaddingWidth + (i * (gapWidth + barWidth)));
            bar.setWidth(barWidth);
            bar.setTop(rect().top() + gapWidth + (1.0 - value) * barHeight);
            bar.setBottom(rect().bottom() - gapWidth);

            QColor color = barColor;
            if (m_bars[i].clipped)
			{
                color = clipColor;
			}
            painter.fillRect(bar, color);
        }
    }
	event ->accept();
}
예제 #3
0
void ButtonUnit::onRender( RenderContext & context, const RectInt & window )
{
	WindowButton::onRender( context, window );

	if ( enabled() && m_Unit.valid() )
	{
		GameDocument * pDoc = (GameDocument *)document();
		ASSERT( pDoc );
		NounShip * pShip = pDoc->ship();
		if (! pShip )
			return;
		DisplayDevice * pDisplay = context.display();
		ASSERT( pDisplay );

		// draw the gadget icon
		if ( m_Icon.valid() )
		{
			RectInt iconBox( PointInt( window.left, window.top ), SizeInt( 32, 16 ) );
			RectFloat iconUV(0,0,1,1);

			Material::push( context, m_Icon );
			PrimitiveWindow::push( pDisplay, iconBox, iconUV, 
				pShip->isFriend( m_Unit ) ? GREEN : pShip->isEnemy( m_Unit ) ? RED : YELLOW );
		}

		// draw the unit health on the button
		Font * pFont = windowStyle()->font();
		ASSERT( pFont );

		WideString sHealth;
		sHealth.format( STR("%d%%"), 100 - ((m_Unit->damage() * 100) / m_Unit->maxDamage()) );

		SizeInt szHealth( pFont->size( sHealth ) );
		PointInt ptHealth( window.right - szHealth.width, window.bottom - szHealth.height );
		Font::push( context.display(), pFont, ptHealth, sHealth, WHITE );

		// display damage bar
		if ( m_Unit->damage() > 0 )
		{
			float damage = 1.0f - (m_Unit->damage() / m_Unit->maxDamage());
			RectInt bar( window.m_Left, window.m_Bottom + 1, 
				window.m_Right - (window.width() * (1.0f - damage)), window.m_Bottom + 3 );
			RectFloat barUV(0,0,1,1);

			Color barColor( 255 * (1.0f - damage), 255 * damage,0,255 );
			PrimitiveMaterial::push( pDisplay, PrimitiveMaterial::NONE );
			PrimitiveWindow::push( pDisplay, bar, barUV, barColor );
		}

		// display blinking border if this unit is the current target
		if ( pDoc->target() == m_Unit && (pDoc->tick() % 10) < 6)
			renderGlow( context );
	}
}
예제 #4
0
void KateTabButton::paintEvent(QPaintEvent *ev)
{
    Q_UNUSED(ev)

    QColor barColor(palette().color(QPalette::Highlight));

    // read from the parent widget (=KateTabBar) the isActiveViewSpace property
    if (isActiveViewSpace()) {
        // if inactive, convert color to gray value
        const int g = qGray(barColor.rgb());
        barColor = QColor(g, g, g);
    }

    // compute sane margins
    const int margin = style()->pixelMetric(QStyle::PM_ButtonMargin, 0, this);
    const int barMargin = margin / 2;
    const int barHeight = ceil(height() / 10.0);

    QPainter p(this);

    // paint bar if inactive but hovered
    if (!isChecked() && underMouse()) {
        barColor.setAlpha(80);
        p.fillRect(QRect(barMargin, height() - barHeight, width() - 2 * barMargin, barHeight), barColor);
    }

    // paint bar
    if (isChecked()) {
        barColor.setAlpha(255);
        p.fillRect(QRect(barMargin, height() - barHeight, width() - 2 * barMargin, barHeight), barColor);
    }

    // icon, if applicable
    int leftMargin = margin;
    if (! icon().isNull()) {
        const int y = (height() - 16) / 2;
        icon().paint(&p, margin, y, 16, 16);
        leftMargin += 16;
        leftMargin += margin;
    }

    // the width of the text is reduced by the close button + 2 * margin
    const int w = width() // width of widget
                - m_closeButton->width() - 2 * margin // close button
                - leftMargin; // modified button

    // draw text, we need to elide to xxx...xxx is too long
    const QString elidedText = QFontMetrics(font()).elidedText (text(), Qt::ElideMiddle, w);
    const QRect textRect(leftMargin, 0, w, height());
    const QPalette pal = QApplication::palette();
    style()->drawItemText(&p, textRect, Qt::AlignHCenter | Qt::AlignVCenter, pal, true, elidedText);
}
예제 #5
0
void FramesWeightFrame::drawWeights()
{
  if(!offscreen) return;

  QPainter p(offscreen);
  QColor boxColor = QColor("#5c4179");

  p.fillRect(0, 0, frames_count*FrameBarWidth, TrackHeight, boxColor);

  //emphasize the first frame if it's T-pose
  if(_anim->isFirstFrameTPose())
    p.fillRect(0, 0, FrameBarWidth, TrackHeight, QColor("#84365D"));

  double hFactor = ((double)TrackHeight) / 100.0;
  QColor barColor("#999999");

  for(int i=0; i<frames_count; i++)
  {
    int barHeight = (int)(frameWeights[i] * hFactor);
    if(i==weightedFrame)
      p.fillRect(i*FrameBarWidth +1, TrackHeight-barHeight, FrameBarWidth-2, barHeight, QColor("#0080ff"));
    else
      p.fillRect(i*FrameBarWidth +1, TrackHeight-barHeight, FrameBarWidth-2, barHeight, barColor);

    if(weightedFrame!=-1)
    {
      int w = frameWeights[weightedFrame];
      QPen textPen(QColor("#f8f8f8"));
      QFont f ("Arial", 11, QFont::Normal);
      p.setPen(textPen);
      p.setFont(f);

     //for some galactic reason the center alignment doesn't work as expected, so must be done manually
      if(w==100)
        p.drawText(weightedFrame*FrameBarWidth-FrameBarWidth, TrackHeight-TextSize,
                   FrameBarWidth*3, TextSize, Qt::AlignJustify, QString::number(w));
      else if(w<10)
        p.drawText(weightedFrame*FrameBarWidth, TrackHeight-TextSize,
                   FrameBarWidth, TextSize, Qt::AlignJustify, QString::number(w));
      else    //10-99
        p.drawText(weightedFrame*FrameBarWidth-(FrameBarWidth/2), TrackHeight-TextSize,
                   FrameBarWidth*2, TextSize, Qt::AlignJustify, QString::number(w));
    }
  }
}
예제 #6
0
//-----------------------------------------------------------------------------
//! Draws the value bar inside the rudder bar rectangle.
//-----------------------------------------------------------------------------
void tRudderBarMedusa::DrawValueBar( const QRect rect, QPainter* pPainter )
{
    pPainter->save();
    pPainter->translate( rect.width() / 2, rect.top() );

    bool positive = (m_Value >= 0);
    int valueP = 0;

    if( positive )
    {
        valueP = m_Value*100 / (int)m_MaxStarboard;
    }
    else
    {
        valueP = m_Value*100 / (int)m_MaxPort;
    }

    valueP = qMin( 100, valueP );   // Never exceed 100 %

    int valueBarWidth = 0;

    if( qAbs( valueP ) <= 25 )
    {
        valueBarWidth = ( m_BarWidth * m_cQuarterPosInPercentage * valueP ) / 5000;
    }
    else
    {
        int diff = qAbs(valueP) - 25;
        int remaining = 100 - m_cQuarterPosInPercentage;
        valueBarWidth = (m_BarWidth * ( 75 * m_cQuarterPosInPercentage + diff * remaining )) / 15000;
        if( !positive ) valueBarWidth = -valueBarWidth;
    }

    // Draw bar in full height
    QColor barColor( positive ? Qt::green : Qt::red );
    barColor.setAlpha( 200 );

    pPainter->fillRect( QRect( 0, 0, valueBarWidth, rect.height() ), QBrush( barColor ) );
    
    pPainter->restore();
}
예제 #7
0
void ViewEngineering::ButtonGadget::onRender( RenderContext & context, const RectInt & window )
{
	WindowButton::onRender( context, window );

	if ( enabled() )
	{
		DisplayDevice * pDisplay = context.display();
		ASSERT( pDisplay );
		Font * pFont = windowStyle()->font();
		ASSERT( pFont );

		// display damage percentage
		String status;
		status.format( "%d%%", int( m_rGadget->damageRatioInv() * 100) );

		SizeInt stringSize( pFont->size( status ) );
		PointInt stringPos( window.m_Right - stringSize.width, window.top );
		Font::push( pDisplay, pFont, stringPos, status, YELLOW );

		// display the damage bar
		if ( m_rGadget->damage() > 0 )
		{
			if ( fmod( activeTime(), 1.0f ) < 0.5f )		// make the bar blink
			{
				float damage = m_rGadget->damageRatioInv();
				RectInt bar( window.m_Left, window.m_Bottom + 1, 
					window.m_Right - (window.width() * (1.0f - damage)), window.m_Bottom + 3 );

				Color barColor( 255 * (1.0f - damage), 255 * damage,0,255 );
				PrimitiveMaterial::push( pDisplay, PrimitiveMaterial::NONE );
				PrimitiveWindow::push( pDisplay, bar, DAMAGE_BAR_UV, barColor );
			}
		}

		// display white blinking box around gadget currently at the top of the queue
		NounShip * pShip = WidgetCast<NounShip>( m_rGadget->parentBody() );
		if ( pShip != NULL && pShip->repairCount() > 0 && pShip->repair( 0 ) == m_rGadget && fmod( activeTime(), 1.0f ) < 0.5f )
			renderGlow( context );
	}
}
예제 #8
0
void SpectrumHistoryView::paintEvent(QPaintEvent *)
{
  QColor barColor(255, 0, 0);

  QPainter painter(this);
  painter.setBrush(QColor(0, 255, 0));

  for (int line=0; line < getHistorySize(); ++line)
  {
    for (unsigned int column=0; column < history[line].size(); ++column)
    {
      painter.setBrush(QColor(history[line][column]));
      painter.setPen(QColor(history[line][column]));
      painter.drawLine
        (
          column * width() / history[line].size(),//x1
          line,//y1
          (column + 1) * width() / history[line].size(),//x2
          line//y2
        );
    }
  }
}
예제 #9
0
void
HistogramDialog::recalculateHistogramRaw ()
{
    if(! m_visibleOnClient) return;

    ScopedDebug sd( "Recalculating histogram (slow)", 1);

    // drawable area width/height
    int daWidth = m_imageWidth - m_marginLeft - m_marginRight;
    int daHeight = m_imageHeight - m_marginTop - m_marginBottom;

    m_histInfo.min = zMin_;
    m_histInfo.max = zMax_;
    m_histInfo.nNans = 0;
    m_histInfo.maxBin = 0;
    int nBins;
    if( m_smoothGraph)
        nBins = std::max( daWidth , 10);
    else
        nBins = std::max( daWidth / 10, 10);

    m_histInfo.bins.resize ( nBins);
    for( int i = 0 ; i < nBins ; i ++ )
        m_histInfo.bins[i] = 0;

    quint64 trueCount = 0; // number of pixels in the clip range
    quint64 totalPixels = 0; // number of pixels that are not nans
    if( m_cir) {

        FitsParser & p = m_cir-> parser (); // alias

        FitsParser::HeaderInfo header = p.getHeaderInfo ();
//        totalPixels = header.naxis1 * header.naxis2;
        for( int y = 0 ; y < header.naxis2 ; y ++ ) {
            for( int x = 0 ; x < header.naxis1 ; x ++ ) {
                double v = p.src ( x, y, m_frameInfoNumber);
                if( isnan (v)) {
                    m_histInfo.nNans ++;
//                    totalPixels --;
                } else {
                    // TODO: centering in bins...?
                    int i = floor (nBins * (v - m_histInfo.min)/(m_histInfo.max - m_histInfo.min));
                    if( i >= 0 && i < nBins) {
                        m_histInfo.bins[i] ++;
                    }
                    if( v >= min() && v <= max()){
                        trueCount ++;
                    }
                }
            }
        }
        totalPixels = header.naxis1 * header.naxis2 - m_histInfo.nNans;

        // compute the highest count (so that we can scale this when drawing)
        for( int i = 0 ; i < m_histInfo.bins.size () ; i ++ ) {
            m_histInfo.maxBin = std::max( m_histInfo.maxBin, m_histInfo.bins[i]);
        }
    }

    // render the histogram
    QColor barColor( "#0071FD");
//    QColor backgroundColor( "#F3F3DA");
    QColor backgroundColor( "#ffffff");
    QColor highlightColor( "#FF0000");
    m_buffer = QImage( QSize(m_imageWidth, m_imageHeight), m_buffer.format());
    int ih = m_imageHeight;
    QPainter painter( & m_buffer);
    painter.setRenderHint( QPainter::Antialiasing, true);
    painter.setRenderHint( QPainter::HighQualityAntialiasing, true);
    painter.fillRect ( m_buffer.rect (), backgroundColor);

    // over which bin is the cursor?
    int cursorBin = m_cursorX - m_marginLeft;
    if( ! m_smoothGraph)
        cursorBin = floor( (m_cursorX - m_marginLeft) / double(daWidth) * nBins);
    cursorBin = clamp( cursorBin, 0, nBins - 1);

    double maxY = m_histInfo.maxBin;
    if( m_logScale) maxY = log( maxY + 1);
    double dx = double(daWidth) / nBins;
    for( int i = 0 ; i < m_histInfo.bins.size () ; i ++ ) {
        double y = m_histInfo.bins[i];
        if(y == 0) continue;
        if( m_logScale) y = log(y + 1);
        y = (daHeight-2) * y / double( maxY) + 2;
        //        painter.fillRect( QRectF( dx * i, ih, dx, -y ), barColor);
        QPoint p1( round( dx  * i) + m_marginLeft, ih - m_marginBottom);
        QPoint p2( round( dx  * (i+1)) - 1 + m_marginLeft, ih - m_marginBottom - y);

        if( i == cursorBin)
            painter.fillRect( QRect( p1, p2 ), highlightColor);
        else
            painter.fillRect( QRect( p1, p2 ), barColor);
    }

    // draw faint rectangles around bars (only if in bar mode)
    if( ! m_smoothGraph) {
        for( int i = 0 ; i < m_histInfo.bins.size () ; i ++ ) {
            double y = m_histInfo.bins[i];
            if( m_logScale) y = log(y + 1);
            y = daHeight * y / double( maxY);
            //        painter.fillRect( QRectF( dx * i, ih, dx, -y ), barColor);
            QPoint p1( round( dx  * i) + m_marginLeft, ih - m_marginBottom);
            QPoint p2( round( dx  * (i+1)) - 1 + m_marginLeft, ih - m_marginBottom - y);
            painter.setPen( QPen( QColor("black"), 0.1));
            painter.drawRect( QRect( p1, p2 ));
        }
    }

    // draw labels for horizontal
    {
        double yy = m_imageHeight - m_marginBottom + 1;
        Plot2dLabelers::BasicLabeler::SharedPtr horizLabeler = std::make_shared< Plot2dLabelers::BasicLabeler >();

        QFont m_fontHorizontalLabels( "Arial", 8);
        QFontMetrics m_fmHorizontalLabels( m_fontHorizontalLabels);
        int labelFontHeight = m_fmHorizontalLabels.height();
        auto measureTxt = [&m_fmHorizontalLabels]( const QString & str) -> double {
            return m_fmHorizontalLabels.width( str);
        };

        horizLabeler-> setZoom( zMin_, zMax_);
        horizLabeler-> setPixels( daWidth);
        horizLabeler-> setDual( false);
        auto labels = horizLabeler-> compute( measureTxt);

        painter.setFont( m_fontHorizontalLabels);
        painter.setPen( "black");
        QVector<QPointF> ticks;
        ticks.append( QPointF( m_marginLeft - 5, yy));
        ticks.append( QPointF( m_imageWidth - m_marginRight + 5, yy));
        for( auto & label : labels) {
            double xx = label.centerPix + m_marginLeft;
            painter.drawText( QRectF( xx, yy + labelFontHeight / 2.0 + 5, 1, 1),
                              Qt::AlignCenter | Qt::TextDontClip,
                              label.txt1
                              );
            ticks.append( QPointF( xx, m_imageHeight - m_marginBottom + 1));
            ticks.append( QPointF( xx, m_imageHeight - m_marginBottom + 5));
        }
        // tick marks
        painter.setPen( QPen( QBrush("blue"), 1));
        painter.drawLines( ticks);
    }

    // draw the markers
    double x1 = (min() - zMin_) / (zMax_ - zMin_) * daWidth + m_marginLeft;
    double x2 = (max() - zMin_) / (zMax_ - zMin_) * daWidth + m_marginLeft;
    painter.fillRect( QRectF( x1, 5, x2-x1, 5 ), QColor("#008800"));

    // draw the current cursor position
    double binCenter = (cursorBin + 0.5) / nBins * (zMax_ - zMin_) + zMin_;
    double cursorBinVal = m_histInfo.bins[ cursorBin];

    GetStateManager().ViewManager().RenderViewDeferred("HistogramView");

    // tell clients where the markers are
    pwset( "/Histogram/marker1", x1 / m_imageWidth);
    pwset( "/Histogram/marker2", x2 / m_imageWidth);

    // tell clients other stats
//    pwset("/Histogram/LowerClip", m_fvs.formatValue( min_));
//    pwset("/Histogram/UpperClip", m_fvs.formatValue( max_));
    m_vars.lowerClip-> set( min_);
    m_vars.upperClip-> set( max_);
    pwset("/Histogram/GlobalMin", m_fvs.formatValue( frameInfo_.min));
    pwset("/Histogram/GlobalMax", m_fvs.formatValue( frameInfo_.max));
    pwset( "/Histogram/nNaNs", m_histInfo.nNans);
    pwset( "/Histogram/binValue", m_fvs.formatValue( binCenter));
    pwset( "/Histogram/nValuesInBin", cursorBinVal);
    pwset( "/Histogram/trueCount", QString::number( 100 * double(trueCount) / totalPixels, 'g', 6) + "%");
}
예제 #10
0
void ButtonCargo::onRender( RenderContext & context, const RectInt & window )
{
	WindowButton::onRender( context, window );

	if ( enabled() )
	{
		Noun * pCargo = m_Cargo;
		ASSERT( pCargo );

		// display white box around cargo if current target
		GameDocument * pDoc = (GameDocument *)document();
		ASSERT( pDoc );

		if ( pDoc->target() == pCargo && (pDoc->tick() % 10) < 6 )
			renderGlow( context );

		if ( WidgetCast<CargoEnhancement>( pCargo ) )
		{
			// show the durability if an enhancement..
			CargoEnhancement * pCargoEnh = (CargoEnhancement *)pCargo;

			Font * pFont = windowStyle()->font();
			ASSERT( pFont );

			NounEnhancement * pEnhancement = pCargoEnh->enhancement();
			if ( pEnhancement != NULL )
			{
				int nMaxDamage = pEnhancement->maxDamage();
				if ( nMaxDamage > 0 )
				{
					WideString sQuantity;
					sQuantity.format( "%d/%d", nMaxDamage - pCargoEnh->damage(), nMaxDamage );

					SizeInt stringSize( pFont->size( sQuantity ) );
					PointInt stringPos( window.m_Right - stringSize.width, window.top );
					Font::push( context.display(), pFont, stringPos, sQuantity, WHITE );
				}
			}

			if ( ((CargoEnhancement *)pCargo)->quantity() <= 0 )
				destroy();
		}
		else if ( WidgetCast<NounCargo>( pCargo ) )
		{
			// draw the quantity if cargo
			Font * pFont = windowStyle()->font();
			ASSERT( pFont );

			WideString sQuantity;
			sQuantity.format( "%d", ((NounCargo *)pCargo)->quantity() );

			SizeInt stringSize( pFont->size( sQuantity ) );
			PointInt stringPos( window.m_Right - stringSize.width, window.top );
			Font::push( context.display(), pFont, stringPos, sQuantity, WHITE );

			if ( ((NounCargo *)pCargo)->quantity() <= 0 )
				destroy();
		}
		else if ( WidgetCast<NounUnit>( pCargo ) )
		{
			NounUnit * pUnit = (NounUnit *)pCargo;

			// draw the unit health on the button
			Font * pFont = windowStyle()->font();
			ASSERT( pFont );

			WideString sHealth;
			sHealth.format( "%d%%", 100 - ((pUnit->damage() * 100) / pUnit->maxDamage()) );

			PointInt ptHealth( window.right - pFont->size( sHealth ).width, window.top );
			Font::push( context.display(), pFont, ptHealth, sHealth, WHITE );

			// display damage bar
			if ( pUnit->damage() > 0 )
			{
				float damage = 1.0f - (pUnit->damage() / pUnit->maxDamage());
				RectInt bar( window.m_Left, window.m_Bottom + 1, 
					window.m_Right - (window.width() * (1.0f - damage)), window.m_Bottom + 3 );
				RectFloat barUV(0,0,1,1);

				Color barColor( 255 * (1.0f - damage), 255 * damage,0,255 );
				PrimitiveMaterial::push( context.display(), PrimitiveMaterial::NONE );
				PrimitiveWindow::push( context.display(), bar, barUV, barColor );
			}
		}
	}
}
예제 #11
0
void Spectrograph::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event)

    QPainter painter(this);
    painter.fillRect(rect(), Qt::black);

    const int numBars = m_bars.count();

    // Highlight region of selected bar
    if (m_barSelected != NullIndex && numBars) {
        QRect regionRect = rect();
        regionRect.setLeft(m_barSelected * rect().width() / numBars);
        regionRect.setWidth(rect().width() / numBars);
        QColor regionColor(0, 0, 64);
        painter.setBrush(Qt::DiagCrossPattern);
        painter.fillRect(regionRect, regionColor);
        painter.setBrush(Qt::NoBrush);
    }

    QColor barColor(0, 0, 255);
    QColor clipColor(255, 0, 0);

    // Draw the outline
    const QColor gridColor = barColor.darker();
    QPen gridPen(gridColor);
    painter.setPen(gridPen);
    painter.drawLine(rect().topLeft(), rect().topRight());
    painter.drawLine(rect().topRight(), rect().bottomRight());
    painter.drawLine(rect().bottomRight(), rect().bottomLeft());
    painter.drawLine(rect().bottomLeft(), rect().topLeft());

    QVector<qreal> dashes;
    dashes << 2 << 2;
    gridPen.setDashPattern(dashes);
    painter.setPen(gridPen);

    // Draw vertical lines between bars
    if (numBars) {
        const int numHorizontalSections = numBars;
        QLine line(rect().topLeft(), rect().bottomLeft());
        for (int i=1; i<numHorizontalSections; ++i) {
            line.translate(rect().width()/numHorizontalSections, 0);
            painter.drawLine(line);
        }
    }

    // Draw horizontal lines
    const int numVerticalSections = 10;
    QLine line(rect().topLeft(), rect().topRight());
    for (int i=1; i<numVerticalSections; ++i) {
        line.translate(0, rect().height()/numVerticalSections);
        painter.drawLine(line);
    }

    barColor = barColor.lighter();
    barColor.setAlphaF(0.75);
    clipColor.setAlphaF(0.75);

    // Draw the bars
    if (numBars) {
        // Calculate width of bars and gaps
        const int widgetWidth = rect().width();
        const int barPlusGapWidth = widgetWidth / numBars;
        const int barWidth = 0.8 * barPlusGapWidth;
        const int gapWidth = barPlusGapWidth - barWidth;
        const int paddingWidth = widgetWidth - numBars * (barWidth + gapWidth);
        const int leftPaddingWidth = (paddingWidth + gapWidth) / 2;
        const int barHeight = rect().height() - 2 * gapWidth;

        for (int i=0; i<numBars; ++i) {
            const qreal value = m_bars[i].value;
            Q_ASSERT(value >= 0.0 && value <= 1.0);
            QRect bar = rect();
            bar.setLeft(rect().left() + leftPaddingWidth + (i * (gapWidth + barWidth)));
            bar.setWidth(barWidth);
            bar.setTop(rect().top() + gapWidth + (1.0 - value) * barHeight);
            bar.setBottom(rect().bottom() - gapWidth);

            QColor color = barColor;
            if (m_bars[i].clipped)
                color = clipColor;

            painter.fillRect(bar, color);
        }
    }
}
예제 #12
0
void ButtonContact::onRender( RenderContext & context, const RectInt & window )
{
	WindowButton::onRender( context, window );

	DisplayDevice * pDisplay = context.display();
	ASSERT( pDisplay );
	GameDocument * pDoc = (GameDocument *)document();
	ASSERT( pDoc );
	NounShip * pShip = pDoc->ship();
	if (! pShip )
		return;
	WindowStyle * pStyle = windowStyle();
	ASSERT( pStyle );
	Font * pFont = pStyle->font();
	ASSERT( pFont );

	// get a pointer to our gadget
	Noun * pContact = m_Noun;
	if (! pContact )
		return;

	RectInt iconBox( PointInt( window.left, window.top ), SizeInt( 16, 16 ) );

	Color iconColor( YELLOW );
	if ( pShip->isFriend( pContact ) )
		iconColor = GREEN;
	else if ( pShip->isEnemy( pContact ) )
		iconColor = RED;

	// draw the gadget icon
	Material::push( context, m_Icon );
	PrimitiveWindow::push( pDisplay, iconBox, WINDOW_UV, iconColor );

	if ( WidgetCast<NounShip>( pContact ) 
		&& ((NounShip *)pContact)->canOrder( pShip ) )
	{
		Material::push( context, WidgetCast<Material>( resource("team") ) );
		iconBox += PointInt( 16, 0 );
		PrimitiveWindow::push( pDisplay, iconBox, WINDOW_UV, WHITE );
	}
	else if ( m_IsObjective )
	{
		Material::push( context, WidgetCast<Material>( resource("objective") ) );
		iconBox += PointInt( 16, 0 );
		PrimitiveWindow::push( pDisplay, iconBox, WINDOW_UV, WHITE );
	}

	// display status text
	CharString sStatus = pContact->displayName( false );
	if ( m_HotKey != 0 )
		sStatus = CharString().format("%c:%s", m_HotKey, sStatus );
	if ( sStatus.length() > 0 )
	{
		SizeInt stringSize( pFont->size( sStatus ) );
		// make sure the text fits on the label
		while( stringSize.width > (BUTTON_WIDTH - 5 ) )
		{
			// remove the right most character and check the width again
			sStatus.left( sStatus.length() - 1 );
			stringSize = pFont->size( sStatus );
		}

		PointInt stringPos( window.m_Right - stringSize.width, window.m_Bottom - stringSize.height );
		Font::push( pDisplay, pFont, stringPos, sStatus, m_bGroupLeader ? YELLOW : (m_bGroupPending ? GREY : WHITE) );
	}

	// display the damage bar
	if ( WidgetCast<NounShip>( pContact ) )
	{
		if ( ((NounShip *)pContact)->damage() > 0 )
		{
			float damage = ((NounShip *)pContact)->damageRatioInv();
			RectInt bar( window.m_Left, window.m_Bottom + 1, 
				window.m_Right - (window.width() * (1.0f - damage)), window.m_Bottom + 3 );

			Color barColor( 255 * (1.0f - damage), 255 * damage,0,255 );
			PrimitiveMaterial::push( pDisplay, PrimitiveMaterial::NONE );
			PrimitiveWindow::push( pDisplay, bar, WINDOW_UV, barColor );
		}
	}

	// render additional border if this contact is our current target
	if ( pDoc->rootTarget() == m_Noun && (pDoc->tick() % 10) < 6 )
		renderGlow( context );
}
예제 #13
0
void ButtonGadget::onRender( RenderContext & context, const RectInt & window )
{
	WindowButton::onRender( context, window );

	// get a pointer to our gadget
	NounGadget * pGadget = m_Gadget;
	if ( pGadget != NULL )
	{
		DisplayDevice * pDisplay = context.display();
		ASSERT( pDisplay );
		GameDocument * pDoc = (GameDocument *)document();
		ASSERT( pDoc );
		WindowStyle * pStyle = windowStyle();
		ASSERT( pStyle );
		Font * pFont = pStyle->font();
		ASSERT( pFont );

		// display bar if gadget has delay before usabled
		int delay = pGadget->usableWhen();
		if ( delay > 0 )
		{
			if ( (pDoc->tick() % 10) < 6 )		// make the bar blink
			{
				RectInt bar( window.left, window.top, 
					window.right - ((window.width() * delay) / 100), window.top + 16 );

				PrimitiveMaterial::push( pDisplay, PrimitiveMaterial::ADDITIVE );
				PrimitiveWindow::push( pDisplay, bar, WINDOW_UV, Color(0,0,255,255) );
			}			
		}

		// draw the gadget icon
		Material * pIcon = pGadget->icon();
		if ( pIcon != NULL )
		{
			RectInt iconBox( PointInt( window.left, window.top ), SizeInt( 32, 16 ) );

			Material::push( context, pIcon );
			PrimitiveWindow::push( pDisplay, iconBox, WINDOW_UV, m_IconColor );
		}

		// display any gadget status text
		WideString sStatus( pGadget->status() );
		if ( sStatus.length() > 0 )
		{
			SizeInt stringSize( pFont->size( sStatus ) );
			Font::push( pDisplay, pFont, PointInt( window.m_Right - stringSize.width, window.top ), sStatus, YELLOW );
		}

		// display hotkey in lower-left corner of button
		CharString sHotKey;
		if ( pGadget->hotkey() != 0 && pGadget->hotkey() != HK_SPACE )
			sHotKey += keyText( Keyboard::unmap( pGadget->hotkey() ) );

		if ( m_Gadget->group() != 0 )
			sHotKey += CharString().format(" %c", m_Gadget->group() );

		if ( WidgetCast<GadgetBeamWeapon>( pGadget ) && ((GadgetBeamWeapon *)pGadget)->pointDefense() )
			sHotKey += " PD";

		if ( sHotKey.length() > 0 )
		{
			WideString sWide = sHotKey;
			SizeInt stringSize( pFont->size( sWide ) );

			Font::push( pDisplay, pFont, PointInt( window.m_Right - stringSize.width, window.m_Bottom - stringSize.height ), 
				sWide, YELLOW );
		}

		// display the damage bar
		if ( pGadget->damage() > 0 )
		{
			if ( (pDoc->tick() % 10) < 6 )		// make the bar blink
			{
				float damage = pGadget->damageRatioInv();
				RectInt bar( window.m_Left, window.m_Bottom + 1, 
					window.m_Right - (window.width() * (1.0f - damage)), window.m_Bottom + 3 );

				Color barColor( 255 * (1.0f - damage), 255 * damage,0,255 );
				PrimitiveMaterial::push( pDisplay, PrimitiveMaterial::NONE );
				PrimitiveWindow::push( pDisplay, bar, WINDOW_UV, barColor );
			}
		}

		// blink a white border if this is the current target
		if ( pDoc->target() == m_Gadget && (pDoc->tick() % 10) < 6 )
			renderGlow( context );
	}
}