Example #1
0
void QwtPlotAbstractCanvas::drawStyled( QPainter *painter, bool hackStyledBackground )
{
    fillBackground( painter );

    if ( hackStyledBackground )
    {
        // Antialiasing rounded borders is done by
        // inserting pixels with colors between the 
        // border color and the color on the canvas,
        // When the border is painted before the plot items
        // these colors are interpolated for the canvas
        // and the plot items need to be clipped excluding
        // the anialiased pixels. In situations, where
        // the plot items fill the area at the rounded
        // borders this is noticeable.
        // The only way to avoid these annoying "artefacts"
        // is to paint the border on top of the plot items.

        if ( !d_data->styleSheet.hasBorder ||
            d_data->styleSheet.borderPath.isEmpty() )
        {
            // We have no border with at least one rounded corner
            hackStyledBackground = false;
        }
    }
    
    QWidget *w = canvasWidget();

    if ( hackStyledBackground )
    {
        painter->save();
        
        // paint background without border
        painter->setPen( Qt::NoPen );
        painter->setBrush( d_data->styleSheet.background.brush );
        painter->setBrushOrigin( d_data->styleSheet.background.origin );
        painter->setClipPath( d_data->styleSheet.borderPath );
        painter->drawRect( w->contentsRect() );

        painter->restore();

        drawCanvas( painter );

        // Now paint the border on top
        QStyleOptionFrame opt;
        opt.initFrom( w );
        w->style()->drawPrimitive( QStyle::PE_Frame, &opt, painter, w);
    }   
    else
    {
        QStyleOption opt;
        opt.initFrom( w );
        w->style()->drawPrimitive( QStyle::PE_Widget, &opt, painter, w );
    
        drawCanvas( painter );
    }   
}   
int main(){
	system("setterm -cursor on");

	//coba bikin huruf terus print

	//bikin huruf A kebalik
	polygon p;
	p.push_back(0,0);
	p.push_back(4,12);
	p.push_back(8,0);
	p.push_back(7,0);
	p.push_back(6,3);
	p.push_back(2,3);
	p.push_back(1,0);

	std::vector<polygon> bidangs;
	bidangs.push_back(p);

	polygon p2;
	p2.push_back(3,5);
	p2.push_back(4,10);
	p2.push_back(5,5);

	std::vector<polygon>lubangs;
	lubangs.push_back(p2);

// Ini mau implementasi teks
	letter letterAKebalik(bidangs,lubangs,9,13);
	initializePrinter();
	pixelBoolMatrix pbm1 = letterAKebalik.toPixelBoolMatrix(1);

	drawCanvas(0,0,0,255);
	pbm1.draw(10,10,255,255,255,255);
	printToScreen();
	sleep(1);
// Akhir


	for (int i=0;i<100;i++){
		pixelBoolMatrix pbm = letterAKebalik.toPixelBoolMatrix(1+(float)i/10);
		drawCanvas(0,0,0,255);
		pbm.draw(10,10,255,255,255,255);
		printToScreen();
		usleep(1000);

	}
	finishPrinter();
	system("setterm -cursor on");
	
}
int main(){

	initializePrinter();
	
	polygon p;
	p.push_back(4,4);
	p.push_back(30,100);
	p.push_back(100,4);
	p.push_back(30,400);

	//test print
	std::cout<<"hasil putar: "<<std::endl;
	polygon pPutar = p.hasilRotasi(180);
	for (int i=0;i<pPutar.size();i++){
		std::cout<<pPutar[i].getX()<<"\t"<<pPutar[i].getY()<<std::endl;
	}
	std::cout<<"\n"<<std::endl;

	polygon pGeser = p.hasilGeser(100,100);
	for (int i=0;i<pPutar.size();i++){
		std::cout<<pGeser[i].getX()<<"\t"<<pGeser[i].getY()<<std::endl;
	}
	std::cout<<"\n"<<std::endl;

	drawCanvas(0,0,0,255);
	p.draw(10,10,255,255,255,255,true);
	printToScreen();
	sleep(3);
	p.draw(10,10,255,255,255,255,true);	
	printToScreen();
	sleep(3);

	for (float f = 0; f < 360; f+=1){
		drawCanvas(0,0,0,255);
		p.hasilRotasi(f).draw(10,10,255,255,255,255,true);
		printToScreen();
		usleep(100);
	}
	point poros(50,50);
	for (float f = 0; f < 360; f+=1){
		
		drawCanvas(0,0,0,255);
		p.hasilRotasi(f,poros).draw(10,10,255,255,255,255,true);
		printToScreen();
		usleep(100);
	}

	finishPrinter();
}
int main() {
	if (initializePrinter()!=0) return 1;

	system("setterm -cursor off");

	drawCanvas(255,255,255,255);
	printToScreen();

	//drawPixSquare(5, 5, 5, 22, 22, 22, 255);

	circle C = circle(100,100,100,2);
	C.drawCircle(55,22,11,255, true, true);
	printToScreen();



	usleep(1000000);
	system("setterm -cursor on");
	finishPrinter();



	
	return 0;
}
Example #5
0
void game::drawScreen(){
	drawCanvas(0,0,0,255);
	for (int i=screenObjects.size()-1;i>=0;i--){
		screenObjects[i]->draw();
	}
	printToScreen();
}
Example #6
0
void game::run(){
	//TODO nanti harus diganti
	init();
	drawCanvas(0,0,0,255);
	drawTextCentered("GRAPHICAT",9,50,3,255,0,0,255);
	drawTextCentered("PLANE SHOOTER",13,150,3,255,0,0,255);
	drawTextCentered("Press A or D to move ship left or right",39,250,1,255,0,0,255);
	drawTextCentered("Press J or L to rotate the ship turret",38,300,1,255,0,0,255);
	drawTextCentered("Press Space to shoot",20,350,1,255,0,0,255);
	drawTextCentered("Press Q to change weapon",24,400,1,255,0,0,255);
	printToScreen();
	sleep(5);
	while (!gameOver()){
		updateControls();
		updateLogic();
		drawScreen();

		usleep(200);
	}
	usleep(500);
	drawTextCentered("YOU WIN",7,300,5,255,0,0,255);
	printToScreen();
	usleep(500);

	finishPrinter();
	resetTermios();
	sleep(2);
}
//! Redraw the canvas, and focus rect
void QwtPlotCanvas::drawContents(QPainter *painter)
{
    if ( cacheMode() && d_cache 
        && d_cache->size() == contentsRect().size() )
    {
        painter->drawPixmap(contentsRect().topLeft(), *d_cache);
    }
    else
        drawCanvas(painter);

#ifndef QWT_NO_COMPAT
    if ( d_outlineActive )
        drawOutline(*painter); // redraw outline
#endif

    if ( hasFocus() && focusIndicator() == CanvasFocusIndicator )
    {
        const int margin = 1;
        QRect focusRect = contentsRect();
        focusRect.setRect(focusRect.x() + margin, focusRect.y() + margin,
            focusRect.width() - 2 * margin, focusRect.height() - 2 * margin);

        drawFocusIndicator(painter, focusRect);
    }
}
Example #8
0
void Canvas::draw(QPainter& p, const QRect& rect)/*{{{*/
{
	//      printf("draw canvas %x virt %d\n", this, virt());

	int x = rect.x();
	int y = rect.y();
	int w = rect.width();
	int h = rect.height();
	int x2 = x + w;

	if (virt())
	{
		//printf("If virt() code running\n");
		drawCanvas(p, rect);

		//---------------------------------------------------
		// draw Canvas Items
		//---------------------------------------------------

		iCItem to(_items.lower_bound(x2));

		// Draw items from other parts behind all others.
		// Only for items with events (not Composer parts).
		QList<CItem*> sortedByZValue;

		// Draw items from other parts behind all others.
		// Only for items with events (not Composer parts).
		for (iCItem i = _items.begin(); i != to; ++i)
		{
			sortedByZValue.append(i->second);
		}
		PartZIndex = m_PartZIndex;

		qSort(sortedByZValue.begin(), sortedByZValue.end(), Canvas::smallerZValue);

		foreach(CItem* ci, sortedByZValue)
		{
			if (!ci->event().empty() && ci->part() != _curPart)
			{
				drawItem(p, ci, rect);
			}
			else if (!ci->isMoving() && (ci->event().empty() || ci->part() == _curPart))
			{
				drawItem(p, ci, rect);
			}
		}
		to = _moving.lower_bound(x2);
		for (iCItem i = _moving.begin(); i != to; ++i)
		{
			drawItem(p, i->second, rect);
		}

		drawTopItem(p,rect);
	}
	else
	{
Example #9
0
/*!
  \brief Redraw the plot
  If the autoReplot option is not set (which is the default)
  or if any curves are attached to raw data, the plot has to
  be refreshed explicitly in order to make changes visible.
  \sa setAutoReplot()
*/
void QwtPlot::replot()
{
    bool doAutoReplot = autoReplot();
    setAutoReplot(FALSE);

    updateAxes();
    drawCanvas(d_canvas->contentsRect());

    setAutoReplot(doAutoReplot);
}
int main(){
	initializePrinter();
	drawCanvas(0,0,0,255);
	int x,y;
	y = getYRes()/2;
	x = getXRes()/2;
	circle C = makeCircle(0,0,0,255,20,x,y);
	for (i=0;i<=360;i++) {
		rotateCircle(C,i,x,y);
		drawCircle(C);
	}
	printToScreen();
	finishPrinter();
}
Example #11
0
//! Setup a QPixmap for double-buffering
// and call drawCanvas(QPainter*)
//  \param ur update rect
void QwtPlot::drawCanvas(const QRect &ur)
{
    if ( ur.isValid() )
    {
        // Use double-buffering
        QPixmap pix( ur.size() );
        pix.fill( d_canvas, ur.topLeft() );
        QPainter p( &pix, d_canvas );
        p.translate( -ur.x(), -ur.y() );
        drawCanvas(&p);
        p.end();

        bitBlt( d_canvas, ur.topLeft(), &pix );
    }
}
Example #12
0
//! Redraw the canvas
void QwtPolarCanvas::drawContents( QPainter *painter )
{
  if ( d_data->paintAttributes & PaintCached && d_data->cache
       && d_data->cache->size() == contentsRect().size() )
  {
    painter->drawPixmap( contentsRect().topLeft(), *d_data->cache );
  }
  else
  {
    QwtPolarPlot *plt = plot();
    if ( plt )
    {
      const bool doAutoReplot = plt->autoReplot();
      plt->setAutoReplot( false );
      drawCanvas( painter, QwtDoubleRect( contentsRect() ) );
      plt->setAutoReplot( doAutoReplot );
    }
  }
}
Example #13
0
/*!
   \brief Render the plot to a given rectangle ( f.e on a QPrinter, QSvgRenderer )

   \param painter Painter
   \param plotRect Bounding rectangle for the plot
*/
void QwtPolarPlot::renderTo( QPainter *painter, const QRect &plotRect ) const
{
  if ( painter == 0 || !painter->isActive() ||
       !plotRect.isValid() || size().isNull() )
  {
    return;
  }

  // All paint operations need to be scaled according to
  // the paint device metrics.

  QwtPainter::setMetricsMap( this, painter->device() );
  const QwtMetricsMap &metricsMap = QwtPainter::metricsMap();

  int layoutOptions = QwtPolarLayout::IgnoreScrollbars
                      | QwtPolarLayout::IgnoreFrames;

  (( QwtPolarPlot * )this )->plotLayout()->activate( this,
      QwtPainter::metricsMap().deviceToLayout( plotRect ),
      layoutOptions );

  painter->save();
  renderTitle( painter, plotLayout()->titleRect() );
  painter->restore();

  painter->save();
  renderLegend( painter, plotLayout()->legendRect() );
  painter->restore();

  QRect canvasRect = plotLayout()->canvasRect();
  canvasRect = metricsMap.layoutToDevice( canvasRect );

  QwtPainter::setMetricsMap( painter->device(), painter->device() );

  painter->save();
  painter->setClipRect( canvasRect );
  drawCanvas( painter, canvasRect );
  painter->restore();

  QwtPainter::resetMetricsMap();

  (( QwtPolarPlot * )this )->plotLayout()->invalidate();
}
Example #14
0
void phaseDiagram(){

  //set-up stuff
  gROOT->Macro("init.C");
  setStyle();  
 
  //draw stuff
  drawCanvas();
  drawTransition();   //also draws critical point
  drawAxis();
  drawLabels();       //draws labels and arrows for phases
  drawExperiments();  //draws where RCIC, LHC etc. lie on curve
  drawNormal();       //draws normal matter

  //save stuff
  if(iSave){
    cPhase->Update();
    cPhase->SaveAs("phaseDiagram5.eps");
  }
}
/*!
  Redraw the canvas, and focus rect
  \param painter Painter
*/
void QwtPlotCanvas::drawContents( QPainter *painter )
{
    if ( d_data->paintAttributes & PaintCached && d_data->cache
        && d_data->cache->size() == contentsRect().size() )
    {
        painter->drawPixmap( contentsRect().topLeft(), *d_data->cache );
    }
    else
    {
        QwtPlot *plot = ( ( QwtPlot * )parent() );
        const bool doAutoReplot = plot->autoReplot();
        plot->setAutoReplot( false );

        drawCanvas( painter );

        plot->setAutoReplot( doAutoReplot );
    }

    if ( hasFocus() && focusIndicator() == CanvasFocusIndicator )
        drawFocusIndicator( painter );
}
Example #16
0
void QwtPlotAbstractCanvas::drawUnstyled( QPainter *painter )
{
    fillBackground( painter );

    QWidget *w = canvasWidget();

    if ( w->autoFillBackground() )
    {
        const QRect canvasRect = w->rect();

        painter->save();

        painter->setPen( Qt::NoPen );
        painter->setBrush( w->palette().brush( w->backgroundRole() ) );

        const QRect frameRect = w->property( "frameRect" ).toRect();
        if ( borderRadius() > 0.0 && ( canvasRect == frameRect ) )
        {
            const int frameWidth = w->property( "frameWidth" ).toInt();
            if ( frameWidth > 0 )
            {
                painter->setClipPath( borderPath2( canvasRect ) );
                painter->drawRect( canvasRect );
            }
            else
            {
                painter->setRenderHint( QPainter::Antialiasing, true );
                painter->drawPath( borderPath2( canvasRect ) );
            }
        }
        else
        {
            painter->drawRect( canvasRect );
        }

        painter->restore();
    }

    drawCanvas( painter );
}
/*!
  Paint event
  \param event Paint event
*/
void QwtPlotCanvas::paintEvent( QPaintEvent *event )
{
    QPainter painter( this );
    painter.setClipRegion( event->region() );

    if ( testPaintAttribute( QwtPlotCanvas::BackingStore ) &&
        d_data->backingStore != NULL )
    {
        QPixmap &bs = *d_data->backingStore;
        if ( bs.size() != size() )
        {
            bs = QPixmap( size() );

#ifdef Q_WS_X11
            if ( bs.x11Info().screen() != x11Info().screen() )
                bs.x11SetScreen( x11Info().screen() );
#endif

            if ( testAttribute(Qt::WA_StyledBackground) )
            {
                QPainter p( &bs );
                qwtFillBackground( &p, this );
                drawCanvas( &p, true );
            }
            else
            {
                QPainter p;
                if ( d_data->borderRadius <= 0.0 )
                {
                    qwtFillPixmap( this, bs );
                    p.begin( &bs );
                    drawCanvas( &p, false );
                }
                else
                {
                    p.begin( &bs );
                    qwtFillBackground( &p, this );
                    drawCanvas( &p, true );
                }

                if ( frameWidth() > 0 )
                    drawBorder( &p );
            }
        }

        painter.drawPixmap( 0, 0, *d_data->backingStore );
    }
    else
    {
        if ( testAttribute(Qt::WA_StyledBackground ) )
        {
            if ( testAttribute( Qt::WA_OpaquePaintEvent ) )
            {
                qwtFillBackground( &painter, this );
                drawCanvas( &painter, true );
            }
            else
            {
                drawCanvas( &painter, false );
            }
        }
        else
        {
            if ( testAttribute( Qt::WA_OpaquePaintEvent ) )
            {
                if ( autoFillBackground() )
                {
                    qwtFillBackground( &painter, this );
                    qwtDrawBackground( &painter, this );
                }
            }
            else
            {
                if ( borderRadius() > 0.0 )
                {
                    QPainterPath clipPath;
                    clipPath.addRect( rect() );
                    clipPath = clipPath.subtracted( borderPath( rect() ) );

                    painter.save();

                    painter.setClipPath( clipPath, Qt::IntersectClip );
                    qwtFillBackground( &painter, this );
                    qwtDrawBackground( &painter, this );

                    painter.restore();
                }
            }

            drawCanvas( &painter, false );

            if ( frameWidth() > 0 ) 
                drawBorder( &painter );
        }
    }

    if ( hasFocus() && focusIndicator() == CanvasFocusIndicator )
        drawFocusIndicator( &painter );
}
Example #18
0
/*!
  Paint event
  \param event Paint event
*/
void QwtPlotCanvas::paintEvent( QPaintEvent *event )
{
    QPainter painter( this );
    painter.setClipRegion( event->region() );

    if ( testPaintAttribute( QwtPlotCanvas::BackingStore ) &&
        d_data->backingStore != NULL )
    {
        QPixmap &bs = *d_data->backingStore;
        if ( bs.size() != size() )
        {
            bs = QPixmap( size() );

#ifdef Q_WS_X11
            if ( bs.x11Info().screen() != x11Info().screen() )
                bs.x11SetScreen( x11Info().screen() );
#endif

            if ( testAttribute(Qt::WA_StyledBackground) )
            {
                QPainter p( &bs );
                qwtFillBackground( &p, this );
                drawCanvas( &p, true );
            }
            else
            {
                QPainter p;
                if ( d_data->borderRadius <= 0.0 )
                {
#if QT_VERSION >= 0x050000
                    QwtPainter::fillPixmap( this, bs );
#else
                    bs.fill( this, 0, 0 );
#endif
                    p.begin( &bs );
                    drawCanvas( &p, false );
                }
                else
                {
                    p.begin( &bs );
                    qwtFillBackground( &p, this );
                    drawCanvas( &p, true );
                }

                if ( frameWidth() > 0 )
                    drawBorder( &p );
            }
        }

        painter.drawPixmap( 0, 0, *d_data->backingStore );
    }
    else
    {
        if ( testAttribute(Qt::WA_StyledBackground ) )
        {
            if ( testAttribute( Qt::WA_OpaquePaintEvent ) )
            {
                qwtFillBackground( &painter, this );
                drawCanvas( &painter, true );
            }
            else
            {
                drawCanvas( &painter, false );
            }
        }
        else
        {
            if ( testAttribute( Qt::WA_OpaquePaintEvent ) )
            {
                if ( autoFillBackground() )
                    qwtDrawBackground( &painter, this );
            }

            drawCanvas( &painter, false );

            if ( frameWidth() > 0 ) 
                drawBorder( &painter );
        }
    }

    if ( hasFocus() && focusIndicator() == CanvasFocusIndicator )
        drawFocusIndicator( &painter );
}