/*!
   \brief Render the plot to a given rectangle ( f.e QPrinter, QSvgRenderer )

   \param plot Plot widget to be rendered
   \param painter Painter
   \param plotRect Bounding rectangle for the plot
*/
void QwtPolarRenderer::render( QwtPolarPlot *plot,
    QPainter *painter, const QRectF &plotRect ) const
{
    if ( plot == NULL || painter == NULL || !painter->isActive() ||
        !plotRect.isValid() || plot->size().isNull() )
    {
        return;
    }

    d_data->plot = plot;

    /*
      The layout engine uses the same methods as they are used
      by the Qt layout system. Therefore we need to calculate the
      layout in screen coordinates and paint with a scaled painter.
     */
    QTransform transform;
    transform.scale(
        double( painter->device()->logicalDpiX() ) / plot->logicalDpiX(),
        double( painter->device()->logicalDpiY() ) / plot->logicalDpiY() );

    const QRectF layoutRect = transform.inverted().mapRect( plotRect );

    QwtPolarLayout *layout = plot->plotLayout();

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

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

    layout->activate( plot, layoutRect, layoutOptions );

    painter->save();
    painter->setWorldTransform( transform, true );

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

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

    const QRectF &canvasRect = layout->canvasRect();

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

    painter->restore();

    layout->invalidate();

    d_data->plot = NULL;
}
Exemple #2
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();
}
Exemple #3
0
bool PlayerLyricsText::render(KaraokePainter &p, qint64 timems)
{
    // Title time?
    if ( m_showTitleTime > 0 && timems < m_showTitleTime )
    {
        renderTitle( p, timems );
        return true;
    }

    if ( p.textRect() != m_usedImageSize )
    {
        m_usedImageSize = p.textRect();
        calculateFontSize();
    }

    int current;

    // Current lyric lookup:
    for ( current = 0; current < m_lines.size(); current++ )
    {
        // For empty lines we look up for the next time
        if ( m_lines[current].isEmpty() )
            continue;

        // Line ended already
        if ( m_lines[current].endTime() < timems )
            continue;

        // We found it
        break;
    }

    // Do we need to draw the notification?
    qint64 notification_duration = 0;

    // We show preamble if:
    if ( current < m_lines.size()   // this is not the last lyric
         && timems < m_lines[current].startTime() // it hasn't started yet;
         && m_lines[current].startTime() - timems <= MAX_NOTIFICATION_DURATION // time to start is less than 5s
         && ( current == 0 || m_lines[current].startTime() - m_lines[current-1].endTime() > MIN_TIME_DIFF_FOR_PREAMBLE ) ) // it is first lyric, or there is more than 5s between end and start
    {
        notification_duration = m_lines[current].startTime() - timems;
    }

    // Draw until we have screen space
    QFontMetrics fm( m_renderFont );
    p.setFont( m_renderFont );

    // Draw current line(s)
    int yoffset = p.textRect().y();
    int ybottom = p.textRect().height() - yoffset;
    yoffset += + fm.height();

    int scroll_passed = 0, scroll_total = 0;

    // If we're playing after the first line, start scrolling it so for the moment the next line it is due
    // it would be at the position of the second line.
    if ( current > 0 && current < m_lines.size() )
    {
        // Should we scroll?
        if ( timems > m_lines[current].startTime() )
        {
            scroll_total = m_lines[current].endTime() - m_lines[current].startTime();
            scroll_passed = timems - m_lines[current].startTime();
            yoffset -= scroll_passed * fm.height() / scroll_total;
        }

        // Draw one more line in front (so our line is always the second one)
        current--;
    }

    if ( current == m_lines.size() )
        return true;

    // Draw notification/preamble
    if ( notification_duration != 0 )
        drawNotification( p, notification_duration );

    // If a current line is empty, track down once
    if ( m_lines[current].isEmpty() && current > 0 )
        current--;

    while ( yoffset < ybottom && current < m_lines.size() )
    {
        if ( !m_lines[current].isEmpty() )
        {
            if ( scroll_total > 0 )
            {
                // Animate out the first line
                int percentage = (100 * scroll_passed) / scroll_total;
                m_lines[current].drawDisappear( p, percentage, yoffset );
                scroll_total = 0;
            }
            else
            {
                m_lines[current].draw( p, timems, yoffset );
            }
        }

        current++;
        yoffset += fm.height();
    }

    return true;
}
/*!
  Paint the contents of a QwtPlot instance into a given rectangle.

  \param plot Plot to be rendered
  \param painter Painter
  \param plotRect Bounding rectangle

  \sa renderDocument(), renderTo(), QwtPainter::setRoundingAlignment()
*/
void QwtPlotRenderer::render( QwtPlot *plot,
    QPainter *painter, const QRectF &plotRect ) const
{
    int axisId;

    if ( painter == 0 || !painter->isActive() ||
            !plotRect.isValid() || plot->size().isNull() )
        return;

    if ( !( d_data->discardFlags & DiscardBackground ) )
        qwtRenderBackground( painter, plotRect, plot );

    /*
      The layout engine uses the same methods as they are used
      by the Qt layout system. Therefore we need to calculate the
      layout in screen coordinates and paint with a scaled painter.
     */
    QTransform transform;
    transform.scale(
        double( painter->device()->logicalDpiX() ) / plot->logicalDpiX(),
        double( painter->device()->logicalDpiY() ) / plot->logicalDpiY() );


    QRectF layoutRect = transform.inverted().mapRect( plotRect );

    if ( !( d_data->discardFlags & DiscardBackground ) )
    {
        // subtract the contents margins

        int left, top, right, bottom;
        plot->getContentsMargins( &left, &top, &right, &bottom );
        layoutRect.adjust( left, top, -right, -bottom );
    }

    int baseLineDists[QwtPlot::axisCnt];
    if ( d_data->layoutFlags & FrameWithScales )
    {
        for ( axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
        {
            QwtScaleWidget *scaleWidget = plot->axisWidget( axisId );
            if ( scaleWidget )
            {
                baseLineDists[axisId] = scaleWidget->margin();
                scaleWidget->setMargin( 0 );
            }

            if ( !plot->axisEnabled( axisId ) )
            {
                int left = 0;
                int right = 0;
                int top = 0;
                int bottom = 0;

                // When we have a scale the frame is painted on
                // the position of the backbone - otherwise we
                // need to introduce a margin around the canvas

                switch( axisId )
                {
                    case QwtPlot::yLeft:
                        layoutRect.adjust( 1, 0, 0, 0 );
                        break;
                    case QwtPlot::yRight:
                        layoutRect.adjust( 0, 0, -1, 0 );
                        break;
                    case QwtPlot::xTop:
                        layoutRect.adjust( 0, 1, 0, 0 );
                        break;
                    case QwtPlot::xBottom:
                        layoutRect.adjust( 0, 0, 0, -1 );
                        break;
                    default:
                        break;
                }
                layoutRect.adjust( left, top, right, bottom );
            }
        }
    }

    // Calculate the layout for the document.

    QwtPlotLayout::Options layoutOptions = 
        QwtPlotLayout::IgnoreScrollbars | QwtPlotLayout::IgnoreFrames;

    if ( d_data->discardFlags & DiscardLegend )
        layoutOptions |= QwtPlotLayout::IgnoreLegend;

    plot->plotLayout()->activate( plot, layoutRect, layoutOptions );

    // now start painting

    painter->save();
    painter->setWorldTransform( transform, true );

    // canvas

    QwtScaleMap maps[QwtPlot::axisCnt];
    buildCanvasMaps( plot, plot->plotLayout()->canvasRect(), maps );
    renderCanvas( plot, painter, plot->plotLayout()->canvasRect(), maps );

    if ( !( d_data->discardFlags & DiscardTitle )
        && ( !plot->titleLabel()->text().isEmpty() ) )
    {
        renderTitle( plot, painter, plot->plotLayout()->titleRect() );
    }

    if ( !( d_data->discardFlags & DiscardLegend )
        && plot->legend() && !plot->legend()->isEmpty() )
    {
        renderLegend( plot, painter, plot->plotLayout()->legendRect() );
    }

    for ( axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
    {
        QwtScaleWidget *scaleWidget = plot->axisWidget( axisId );
        if ( scaleWidget )
        {
            int baseDist = scaleWidget->margin();

            int startDist, endDist;
            scaleWidget->getBorderDistHint( startDist, endDist );

            renderScale( plot, painter, axisId, startDist, endDist,
                baseDist, plot->plotLayout()->scaleRect( axisId ) );
        }
    }


    plot->plotLayout()->invalidate();

    // reset all widgets with their original attributes.
    if ( d_data->layoutFlags & FrameWithScales )
    {
        // restore the previous base line dists

        for ( axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
        {
            QwtScaleWidget *scaleWidget = plot->axisWidget( axisId );
            if ( scaleWidget  )
                scaleWidget->setMargin( baseLineDists[axisId] );
        }
    }

    painter->restore();
}
/*!
  Paint the contents of a QwtPlot instance into a given rectangle.

  \param plot Plot to be rendered
  \param painter Painter
  \param plotRect Bounding rectangle

  \sa renderDocument(), renderTo(), QwtPainter::setRoundingAlignment()
*/
void QwtPlotRenderer::render( QwtPlot *plot,
    QPainter *painter, const QRectF &plotRect ) const
{
    int axisId;

    if ( painter == 0 || !painter->isActive() ||
            !plotRect.isValid() || plot->size().isNull() )
        return;

    if ( !( d_data->discardFlags & DiscardBackground ) )
        qwtRenderBackground( painter, plotRect, plot );

    /*
      The layout engine uses the same methods as they are used
      by the Qt layout system. Therefore we need to calculate the
      layout in screen coordinates and paint with a scaled painter.
     */
    QTransform transform;
    transform.scale(
        double( painter->device()->logicalDpiX() ) / plot->logicalDpiX(),
        double( painter->device()->logicalDpiY() ) / plot->logicalDpiY() );

    painter->save();

    int baseLineDists[QwtPlot::axisCnt];
    if ( d_data->layoutFlags & FrameWithScales )
    {
        for ( axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
        {
            QwtScaleWidget *scaleWidget = plot->axisWidget( axisId );
            if ( scaleWidget )
            {
                baseLineDists[axisId] = scaleWidget->margin();
                scaleWidget->setMargin( 0 );
            }
        }
    }
    // Calculate the layout for the print.

    QwtPlotLayout::Options layoutOptions = 
        QwtPlotLayout::IgnoreScrollbars | QwtPlotLayout::IgnoreFrames;
    if ( d_data->discardFlags & DiscardLegend )
        layoutOptions |= QwtPlotLayout::IgnoreLegend;

    const QRectF layoutRect = transform.inverted().mapRect( plotRect );
    plot->plotLayout()->activate( plot, layoutRect, layoutOptions );

    painter->setWorldTransform( transform, true );

    // canvas

    QwtScaleMap maps[QwtPlot::axisCnt];
    buildCanvasMaps( plot, plot->plotLayout()->canvasRect(), maps );
    renderCanvas( plot, painter, plot->plotLayout()->canvasRect(), maps );

    if ( !( d_data->discardFlags & DiscardTitle )
        && ( !plot->titleLabel()->text().isEmpty() ) )
    {
        renderTitle( plot, painter, plot->plotLayout()->titleRect() );
    }

    if ( !( d_data->discardFlags & DiscardLegend )
        && plot->legend() && !plot->legend()->isEmpty() )
    {
        renderLegend( plot, painter, plot->plotLayout()->legendRect() );
    }

    for ( axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
    {
        QwtScaleWidget *scaleWidget = plot->axisWidget( axisId );
        if ( scaleWidget )
        {
            int baseDist = scaleWidget->margin();

            int startDist, endDist;
            scaleWidget->getBorderDistHint( startDist, endDist );

            renderScale( plot, painter, axisId, startDist, endDist,
                baseDist, plot->plotLayout()->scaleRect( axisId ) );
        }
    }


    plot->plotLayout()->invalidate();

    // reset all widgets with their original attributes.
    if ( d_data->layoutFlags & FrameWithScales )
    {
        // restore the previous base line dists

        for ( axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
        {
            QwtScaleWidget *scaleWidget = plot->axisWidget( axisId );
            if ( scaleWidget  )
                scaleWidget->setMargin( baseLineDists[axisId] );
        }
    }

    painter->restore();
}
Exemple #6
0
void renderMenu(int menu,int xscr,int yscr){
    int i = 0;
    switch(menu){
        case MENU_LOADGAME:
		sf2d_start_frame(GFX_TOP, GFX_LEFT);
        if(!enteringName){ // World select
            offsetX = 0;offsetY = (currentSelection * 32) - 48;
            drawText("Select a file",122,-16);
            for(i = 0; i < worldFileCount + 1; ++i){
                int color = 0x201092FF;
                char * text = fileNames[i];
                if(i == worldFileCount){
                    text = "Generate New World";
                    color = 0x109220FF;
                }
                if(i != currentSelection) color &= 0x7F7F7FFF; // Darken color.
                else {
                    if(areYouSure)color = 0xDF1010FF;
                }
                
                char scoreText[24];
                sprintf(scoreText,"Score: %d",fileScore[i]);
                
                renderFrame(1,i*4,24,(i*4)+4,color);
                if(i != worldFileCount){
                    drawText(text,(400-(strlen(text)*12))/2,i*64+12);
                    drawText(scoreText,(400-(strlen(scoreText)*12))/2,i*64+32);
                } else {
                    drawText(text,(400-(strlen(text)*12))/2,i*64+24);
                }
                if(fileWin[i] && i != worldFileCount) render16(18,i*32+8,24,208,0); // Render crown
            }
            offsetX = 0;offsetY = 0;
        } else { // Enter new world name.
            drawText("Enter a name",128,16);
            drawText(fileNames[worldFileCount],(400-(strlen(fileNames[worldFileCount])*12))/2, 48);
            
            if(errorFileName > 0){
                switch(errorFileName){// Error: Filename cannot already exist.
                    case 1: drawTextColor("ERROR: Length cannot be 0!",(400-26*12)/2,200,0xAF1010FF); break;    
                    case 2: drawTextColor("ERROR: You need Letters/Numbers!",(400-32*12)/2,200,0xAF1010FF); break;    
                    case 3: drawTextColor("ERROR: Filename already exists!",(400-31*12)/2,200,0xAF1010FF); break;    
                }    
            }
        }
		sf2d_end_frame();
		sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);
        if(!enteringName){ // World select
            if(!areYouSure){
                drawTextColor("Load World",100,12,0xFFFF3FFF);
                drawText("Press   or   to scroll", 28, 50);
                renderButtonIcon(k_up.input & -k_up.input, 98, 48, 1);
                renderButtonIcon(k_down.input & -k_down.input, 160, 48, 1);
                drawText("Press   to load world", (320-21*12)/2, 100);
                renderButtonIcon(k_accept.input & -k_accept.input, 104, 98, 1);
                drawText("Press   to return", 58, 150);
                renderButtonIcon(k_decline.input & -k_decline.input, 128, 148, 1);
                if(currentSelection != worldFileCount){
                    drawText("Press   to delete",(320-17*12)/2, 200);
                    renderButtonIcon(k_delete.input & -k_delete.input, 128, 198, 1);
                }
            } else {
                drawTextColor("Delete File?",88,12,0xFF3F3FFF);
                drawText("Press   to confirm", (320-18*12)/2, 100);
                renderButtonIcon(k_accept.input & -k_accept.input, 122, 98, 1);
                drawText("Press   to return", 58, 150);
                renderButtonIcon(k_decline.input & -k_decline.input, 128, 148, 1);
            }
            
        } else { // Draw the "keyboard"
            drawTextColor("Touch the keypad below",(320-22*12)/2,12,0xFFFF33FF);
            
            sf2d_draw_rectangle(0, 50, 320, 110, 0xBF7F7FFF);
            drawSizedText(guiText0,4, 60, 2);
            drawSizedText(guiText1,4, 80, 2);
            drawSizedText(guiText2,12, 100, 2);
            drawSizedText(guiText3,28, 120, 2);
            drawSizedText(guiText4,12, 140, 2);
            
            if(touchDelay > 0){
                sf2d_draw_rectangle(touchX, touchY, touchW, touchH, 0xAF);
            }
            
            drawText("Press   to confirm", (320-18*12)/2, 180);
            renderButtonIcon(k_accept.input & -k_accept.input, 122, 178, 1);
            drawText("Press   to return", 58, 210);
            renderButtonIcon(k_decline.input & -k_decline.input, 128, 208, 1);
        }
            
		sf2d_end_frame();
        break;
        case MENU_SETTINGS:
		    sf2d_start_frame(GFX_TOP, GFX_LEFT);
		        drawTextColor("Rebind Buttons",116,12,0xAFAF00FF);
                drawText("Button",16,32);
                drawText("Game",140,32);
                drawText("Menus",280,32);
		    
                char gameButText[34];
                char menuButText[34];
                    
                for(i = 0; i < 5; ++i){
                    if((currentSelection-2) + i > 21 || (currentSelection-2) + i < 0) continue;
                    renderButtonIcon(keys[(currentSelection-2) + i], 16, (i * 18) + 30, 2);
                    int ccol = 0x7F7F7FFF;
                    
                    sprintf(gameButText,"%s",getButtonFunctionGame(keys[(currentSelection-2) + i]));
                    sprintf(menuButText,"%s",getButtonFunctionMenu(keys[(currentSelection-2) + i]));
                    
                    if(i == 2){ 
                        if(!selBut)ccol = 0xFFFFFFFF;
                        else{ 
                            ccol = 0x00FF00FF;
                            if(left)sprintf(gameButText,"<%s>",getButtonFunctionGame(keys[(currentSelection-2) + i]));
                            else sprintf(menuButText,"<%s>",getButtonFunctionMenu(keys[(currentSelection-2) + i]));
                        }
                    }
                    if(left){
                        drawTextColor(gameButText, 112, (i * 33) + 80, ccol);
                        drawTextColor(menuButText, 280, (i * 33) + 80, 0x7F7F7FFF);
                    } else {
                        drawTextColor(gameButText, 112, (i * 33) + 80, 0x7F7F7FFF);
                        drawTextColor(menuButText, 280, (i * 33) + 80, ccol);
                    }
                }
                if(bindOpt){
                    renderFrame(1,1,24,14,0x1010BFFF);
                    drawTextColor("Save changes?",122,32,0xAFAF00FF);
                    for(i = 2; i >= 0; --i){
                        char* msg = keybOptions[i];
                        u32 color = 0x4F4F4FFF;
                        if(i == curSaveSel) color = 0xFFFFFFFF;
                        drawTextColor(msg,(400 - (strlen(msg) * 12))/2, (i * 24) + 92, color);    
                    }
                    drawText("Press   to return", 98, 190);
                    renderButtonIcon(k_decline.input & -k_decline.input, 168, 188, 1);
                    
                    if(errorBut >= 0 && errorBut < 9){
                        char errorText[30];
                        switch(errorBut){
                            case 0: sprintf(errorText, "Error: Missing 'Move up'"); break;
                            case 1: sprintf(errorText, "Error: Missing 'Move down'"); break;
                            case 2: sprintf(errorText, "Error: Missing 'Move right'"); break;
                            case 3: sprintf(errorText, "Error: Missing 'Move left'"); break;
                            case 4: sprintf(errorText, "Error: Missing 'Attack'"); break;
                            case 5: sprintf(errorText, "Error: Missing 'Toggle Menu'"); break;
                            case 6: sprintf(errorText, "Error: Missing 'Pause'"); break;
                            case 7: sprintf(errorText, "Error: Missing 'Accept'"); break;
                            case 8: sprintf(errorText, "Error: Missing 'Decline'"); break;
                            case 9: sprintf(errorText, "Error: Missing 'Delete'"); break;
                        }
                        drawTextColor(errorText,(400 - (strlen(errorText) * 12))/2,50,0xFF0000FF);
                    }
                    
                }
		    sf2d_end_frame();
		    sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);	
		    if(!selBut){
                drawText("Press   to select", 58, 80);
                renderButtonIcon(k_accept.input & -k_accept.input, 128, 78, 1);
                drawText("Press   to return", 58, 130);
                renderButtonIcon(k_decline.input & -k_decline.input, 128, 128, 1);
            } else {
                drawText("Press   or   to scroll", 28, 50);
                renderButtonIcon(k_left.input & -k_left.input, 98, 48, 1);
                renderButtonIcon(k_right.input & -k_right.input, 160, 48, 1);
                drawText("Press   to unselect", 46, 100);
                renderButtonIcon(k_accept.input & -k_accept.input, 118, 98, 1);
                drawText("Press   to return", 58, 150);
                renderButtonIcon(k_decline.input & -k_decline.input, 128, 148, 1);
            }
		    sf2d_end_frame();
        break;
        
        case MENU_PAUSED:
		    sf2d_start_frame(GFX_TOP, GFX_LEFT);
                if(currentLevel == 0){ 
                    sf2d_draw_texture_part_scale(minimap[1],(-xscr/3)-256,(-yscr/3)-32,0,0,128,128,12.5,7.5);
                    sf2d_draw_rectangle(0,0,400,240, 0xDFDFDFAF);
                }
	            offsetX = xscr;offsetY = yscr;
		            renderMenuBackground(xscr,yscr);
	            offsetX = 0;offsetY = 0;
                renderFrame(1,1,24,14,0xAF1010FF);
                drawText("Paused",164,32);
                for(i = 2; i >= 0; --i){
                    char* msg = pOptions[i];
                    u32 color = 0x7F7F7FFF;
                    if(i == currentSelection) color = 0xFFFFFFFF;
                    drawTextColor(msg,(400 - (strlen(msg) * 12))/2, (i * 24) + 100, color);    
                }
                
                if(pauseSaveDisplayTimer > 0) drawTextColor("Game Saved!", (400-(11*12))/2, 64,0x20FF20FF);
                
                if(areYouSure || areYouSureSave){
                    if(areYouSure)renderFrame(6,5,19,10,0x8F1010FF);
                    else renderFrame(6,5,19,10,0x108F10FF);
                    
                    drawText("Are you sure?",122,96);
                    drawText("   Yes", 164, 117);
                    renderButtonIcon(k_accept.input & -k_accept.input, 166, 114, 1);
                    drawText("   No", 170, 133);
                    renderButtonIcon(k_decline.input & -k_decline.input, 166, 130, 1);
                }
                
		    sf2d_end_frame();
        break;  
        case MENU_WIN:
		    sf2d_start_frame(GFX_TOP, GFX_LEFT);
                if(currentLevel == 0){ 
                    sf2d_draw_texture_part_scale(minimap[1],(-xscr/3)-256,(-yscr/3)-32,0,0,128,128,12.5,7.5);
                    sf2d_draw_rectangle(0,0,400,240, 0xDFDFDFAF);
                }
	            offsetX = xscr;offsetY = yscr;
		            renderMenuBackground(xscr,yscr);
	            offsetX = 0;offsetY = 0;
                renderFrame(5,3,21,12,0x1010FFFF);
                if(!rev){ opacity+=5; if(opacity == 255) rev = true; }
                else { opacity-=5; if(opacity == 100) rev = false; }
                sprintf(scoreText,"Score: %d", player.p.score);
                drawTextColor("You Win!",158,76,0xAFAF0000 + opacity);
                drawText(scoreText, 200-((strlen(scoreText)-1)*6), 100);
                drawText("Press   to continue", 96, 150);
                renderButtonIcon(k_attack.input & -k_attack.input, 166, 148, 1);
                
                //printf("0x%08X",k_attack.input & -k_attack.input);
		    sf2d_end_frame();
        break;  
        case MENU_LOSE:
		    sf2d_start_frame(GFX_TOP, GFX_LEFT);
                if(currentLevel == 0){ 
                    sf2d_draw_texture_part_scale(minimap[1],(-xscr/3)-256,(-yscr/3)-32,0,0,128,128,12.5,7.5);
                    sf2d_draw_rectangle(0,0,400,240, 0xDFDFDFAF);
                }
	            offsetX = xscr;offsetY = yscr;
		            renderMenuBackground(xscr,yscr);
	            offsetX = 0;offsetY = 0;
                renderFrame(5,3,21,12,0x1010FFFF);
                if(!rev){ opacity+=5; if(opacity == 255) rev = true; }
                else { opacity-=5; if(opacity == 100) rev = false; }
                sprintf(scoreText,"Score: %d", player.p.score);
                drawTextColor("You DIED!",158,76,0xAF000000 + opacity);
                drawText(scoreText, 200-((strlen(scoreText)-1)*6), 100);
                drawText("Press   to continue", 96, 150);
                renderButtonIcon(k_attack.input & -k_attack.input, 166, 148, 1);
                //printf("0x%08X",k_attack.input & -k_attack.input);
		    sf2d_end_frame();
        break;  
        case MENU_INVENTORY:
		    sf2d_start_frame(GFX_TOP, GFX_LEFT);
                if(currentLevel == 0){ 
                    sf2d_draw_texture_part_scale(minimap[1],(-xscr/3)-256,(-yscr/3)-32,0,0,128,128,12.5,7.5);
                    sf2d_draw_rectangle(0,0,400,240, 0xDFDFDFAF);
                }
	            offsetX = xscr;offsetY = yscr;
		            renderMenuBackground(xscr,yscr);
	            offsetX = 0;offsetY = 0;
                renderFrame(1,1,24,14,0x1010FFFF);
                renderItemList(player.p.inv, 1,1,24,14, curInvSel);
		    sf2d_end_frame();
        break;  
        case MENU_CRAFTING:
		    sf2d_start_frame(GFX_TOP, GFX_LEFT);
                if(currentLevel == 0){ 
                    sf2d_draw_texture_part_scale(minimap[1],(-xscr/3)-256,(-yscr/3)-32,0,0,128,128,12.5,7.5);
                    sf2d_draw_rectangle(0,0,400,240, 0xDFDFDFAF);
                }
	            offsetX = xscr;offsetY = yscr;
		            renderMenuBackground(xscr,yscr);
	            offsetX = 0;offsetY = 0;
	            
                renderFrame(15,1,24,4,0x1010FFFF);
                renderFrame(15,5,24,14,0x1010FFFF);
                renderFrame(1,1,14,14,0x1010FFFF);
                renderRecipes(currentRecipes, 1, 1, 14, 14, curInvSel);
                
                Recipe* rec = &currentRecipes->recipes[curInvSel];
                renderItemIcon(rec->itemResult,rec->itemAmountLevel,128,16);
                char craftText[12];
                sprintf(craftText,"%d",countItemInv(rec->itemResult,rec->itemAmountLevel, player.p.inv));
                drawText(craftText,274,34);
                
                if(rec->numOfCosts > 0){
                    int i;
                    for(i = 0; i < rec->numOfCosts; i++){
                        int amnt = countItemInv(rec->costs[i].costItem,0, player.p.inv);
                        int ttlCst = rec->costs[i].costAmount;
                        int col = 0xFFFFFFFF; if(amnt<ttlCst) col = 0x7F7F7FFF;
                        renderItemIcon(rec->costs[i].costItem,1,128,48+(i*8));
                        sprintf(craftText,"%d/%d",amnt,ttlCst);
                        drawTextColor(craftText,274,96+(i*18),col);
                    }
                }
                
		    sf2d_end_frame();
        break;  
        
        case MENU_CONTAINER:
		    sf2d_start_frame(GFX_TOP, GFX_LEFT);
                if(currentLevel == 0){ 
                    sf2d_draw_texture_part_scale(minimap[1],(-xscr/3)-256,(-yscr/3)-32,0,0,128,128,12.5,7.5);
                    sf2d_draw_rectangle(0,0,400,240, 0xDFDFDFAF);
                }
	            offsetX = xscr;offsetY = yscr;
		            renderMenuBackground(xscr,yscr);
		        if (curChestEntity->entityFurniture.r == 1){ offsetX = 48;offsetY = 0;}
		        else {offsetX = 0;offsetY = 0;}
		        
		        renderFrame(1,1,14,14,0x1010FFFF);
		        renderItemList(curChestEntity->entityFurniture.inv,1,1,14,14,
                curChestEntity->entityFurniture.r == 0 ? curInvSel : -curChestEntity->entityFurniture.oSel - 1);
		        renderFrame(15,1,28,14,0x1010FFFF);
		        renderItemList(player.p.inv,15,1,28,14,
                curChestEntity->entityFurniture.r == 1 ? curInvSel : -curChestEntity->entityFurniture.oSel - 1);
		        offsetX = 0;offsetY = 0;
		    sf2d_end_frame();
        break;
        case MENU_ABOUT:
		    sf2d_start_frame(GFX_TOP, GFX_LEFT);
		        drawText("About Minicraft",110,12);
		        drawSizedText("Minicraft was made by Markus Persson for the",24,36,1.0);
		        drawSizedText("22'nd ludum dare competition in december 2011.",16,48,1.0);
		        drawSizedText("it is dedicated to my father. <3",72,60,1.0);
		        drawSizedText("- Markus \"Notch\" Persson",104,76,1.0);
		        
		        drawTextColor("3DS Homebrew Edition",74,120,0x00FF00FF);
		        drawSizedTextColor("This port was made by David Benepe (Davideesk)",16,144,1.0,0x00FF00FF);
		        drawSizedTextColor("just for fun in September/October 2015.",44,156,1.0,0x00FF00FF);
		        drawSizedTextColor("TY Notch for creating a fun game to remake!",28,180,1.0,0x00FF00FF);
		    sf2d_end_frame();
		    sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);
		        drawTextColor("Special Thanks to:",52,12,0xFF7F7FFF);
		        drawTextColor("Smea",136,60,0xFF2020FF);
		        drawSizedTextColor("for ctrulib",116,80,1.0,0xFF2020FF);
		        drawTextColor("Xerpi",130,120,0x2020FFFF);
		        drawSizedTextColor("for sf2dlib",116,140,1.0,0x2020FFFF);
                drawText("Press   to return", 58, 220);
                renderButtonIcon(k_decline.input & -k_decline.input, 128, 218, 1);
		    sf2d_end_frame();
        break;
        case MENU_TITLE:
            /* Top Screen */
		    sf2d_start_frame(GFX_TOP, GFX_LEFT);
		        renderTitle(76,16);
		    
		        for(i = 4; i >= 0; --i){
                    char* msg = options[i];
                    u32 color = 0x7F7F7FFF;
                    if(i == currentSelection) color = 0xFFFFFFFF;
                    drawSizedTextColor(msg,(200 - (strlen(msg) * 8))/2, ((8 + i) * 20 - 50) >> 1,2.0, color);    
                }
		    
		        drawText(versionText,2,225);
		    sf2d_end_frame();
		    
            /* Bottom Screen */
		    sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);	
		      int startX = 0, startY = 0;// relative coordinates ftw
		        switch(currentSelection){
                    case 0: // "Start Game"
                        startX = 20;startY = 50;
                        render16(startX,startY+12,0,128,0);//Player(Carrying)
                        render16(startX,startY,128,128,0);//Workbench
                        startX = 120;startY = 20;
                        render16b(startX,startY,16,96,0,0x001DC1FF);// water pit
                        render16b(startX+16,startY,32,96,0,0x001DC1FF);
                        render16b(startX,startY+16,48,96,0,0x001DC1FF);
                        render16b(startX+16,startY+16,64,96,0,0x001DC1FF);
                        renderc  (startX+8,startY+12,48,160,16,8,0);//Waves
                        renderc  (startX+8,startY+8,0,112,16,8,0);//Player (Top-Half)
                        startX = 110;startY = 76;
                        render16 (startX,startY,48,112,0);//Player
                        renderc  (startX+12,startY,40,160,8,16,0);//Slash
                        render   (startX+14,startY+4,152,144,0);//Pickaxe
                        render16b(startX+18,startY,80,0,0,0xDCC6AEFF);//Iron ore
                        startX = 40;startY = 90;
                        render16b (startX,startY,128,112,0,0xADFFADFF);//Slime
                        render16 (startX+18,startY,48,112,1);//Player (Mirrored)
                        renderc  (startX+14,startY,32,160,8,16,0);//Slash
                        render   (startX+12,startY+4,104,144,1);//Sword
                        startX = 64;startY = 40;
                        render16b(startX,startY,16,80,0,0x69B569FF);// grass pit
                        render16b(startX+16,startY,32,80,0,0x69B569FF);
                        render16b(startX,startY+16,48,80,0,0x69B569FF);
                        render16b(startX+16,startY+16,64,80,0,0x69B569FF);
                        render16 (startX+8,startY+4,0,16,0);//Tree
                        render   (startX+1,startY+14,80,152,0);// Apple
                        render16 (startX+9,startY+18,16,112,0);//Player
                        renderc  (startX+9,startY+14,16,160,16,8,0);//Slash
                        drawTextColor("Play minicraft",24,24,0xFFFF7FFF);
                    break;
                    case 1: // "How To Play"
                        startX = 72;startY = 54;
                        render16(startX,startY,96,208,0);//C-PAD
                        startX = 72;startY = 37;
                        render16(startX,startY-16,16,112,0);//Player
                        render16(startX,startY,112,208,0);//C-PAD up
                        startX = 72;startY = 71;
                        render16(startX,startY+16,0,112,0);//Player
                        render16(startX,startY,144,208,0);//C-PAD down
                        startX = 39;startY = 54;
                        render16(startX,startY,48,112,1);//Player
                        render16(startX+16,startY,128,208,0);//C-PAD left
                        startX = 89;startY = 54;
                        render16(startX+16,startY,48,112,0);//Player
                        render16(startX,startY,160,208,0);//C-PAD right
                        
                        drawTextColor("Learn the basics",64,24,0xFFFF7FFF);
                    break;
                    case 2: // "Settings"
                    break;
                    case 3: // "About"
                    break;
                }
		    sf2d_end_frame();
            break;
        
        
    }
    
}
Exemple #7
0
void Main()
{
	ResourceLoader resources;

	auto sampler = SamplerState(SamplerState::Default2D);
	sampler.filter = TextureFilter::MinMagMipPoint;
	Graphics2D::SetSamplerState(sampler);

	Window::Resize(320 * 2, 240 * 2);
	Window::SetTitle(L"まちへかえろう(仮)");

	Array<HurdleObject> hurdles;
	Array<BuildingLayer> buildingLayers;
	Array<BuildingLayer2> buildingLayers2;

	Map::instance().init(40, 15);

	for (int i = 0; i < 40; i++)
	{
		Map::instance().set(i, 14, 5);
		Map::instance().set(i, 13, 5);
		Map::instance().set(i, 12, 4);
		Map::instance().set(i, 11, 3);
		Map::instance().set(i, 10, 3);
		Map::instance().set(i, 9, 2);
		Map::instance().set(i, 8, 1);
	}
	auto viewLeft = 0.0;
	auto mycharDead = false;
	ScreenState currentState = ScreenState::InTitle, prevState = currentState;
	bool prevSpacePressed = false;

	auto TitleTimer = TimerMillisec();

	ScriptEngine asEngine;
	asEngine.RegisterMethod(L"int getAt(double x, double y)", &Map::getAt, Map::instance());
	asEngine.RegisterProperty(L"double _viewX", &viewLeft);
	asEngine.RegisterProperty(L"bool _isGameOvered", &mycharDead);
	asEngine.RegisterFunction(L"void playJumpSound()", PlayJumpSound);
	auto context_mychar = asEngine.CreateContextFromScript(L"res/scripts/Mychar.as");

	Record::instance().init();

	int fc = 0;
	while (System::Update())
	{
		bool spacePressedInFrame = !prevSpacePressed && Input::KeySpace.pressed;
		prevSpacePressed = Input::KeySpace.pressed;

		asEngine.setFrameCount(fc);

		switch (currentState)
		{
		case ScreenState::InTitle:
			if (!TitleTimer.isActive) TitleTimer.start();
			renderBackgrounds(viewLeft, resources);
			renderBuildingLayers(buildingLayers, buildingLayers2, resources);
			renderMap(viewLeft, resources);
			renderTitle(TitleTimer.elapsed(), resources);
			renderCurrentMax();

			if (spacePressedInFrame)
			{
				// GameInit
				SoundAsset(SoundResourceLoader::decide).play();
				viewLeft = 0.0;
				mycharDead = false;
				context_mychar.Reenter();
				buildingLayers.clear();
				buildingLayers2.clear();
				hurdles.clear();
				currentState = ScreenState::Gaming;
			}
			break;
		case ScreenState::Gaming:
			// appear hurdles at random
			if (RandomBool(0.02))
			{
				if (hurdles.empty() || hurdles.back().getPos().x - (viewLeft + 320.0f) < -48.0f)
				{
					// allocate space least 48 logical-pixels
					hurdles.emplace_back(HurdleObject(Vec2(viewLeft + 320.0f, 8.0f * 16.0f + 8.0f)));
				}
			}
			// appear building at random
			if (RandomBool(0.02 / 30.0))
			{
				if (buildingLayers.empty() || buildingLayers.back().getPos().x < 0.0f)
				{
					buildingLayers.emplace_back(BuildingLayer(Vec2(320.0f, -60.0f)));
				}
			}
			if (RandomBool(0.01 / 30.0))
			{
				if (buildingLayers2.empty() || buildingLayers2.back().getPos().x < 0.0f)
				{
					buildingLayers2.emplace_back(BuildingLayer2(Vec2(320.0f, -60.0f)));
				}
			}

			asEngine.setFrameCount(fc);
			context_mychar.Execute();

			renderBackgrounds(viewLeft, resources);
			renderBuildingLayers(buildingLayers, buildingLayers2, resources);
			renderMap(viewLeft, resources);
			if (renderHurdlesAndHitTest(viewLeft, context_mychar.GetGlobalDoubleVec2(L"x", L"y"), hurdles, resources))
			{
				if (!mycharDead) SoundAsset(SoundResourceLoader::died).play();
				mycharDead = true;
			}
			renderPlayer(viewLeft, context_mychar.GetGlobalDouble(L"angle"), context_mychar.GetGlobalDoubleVec2(L"x", L"y"), resources);
			renderInfo(toScore(context_mychar.GetGlobalDouble(L"x")));

			// Host Processes
			if (mycharDead && context_mychar.GetGlobalDouble(L"x") < viewLeft - 120.0f)
			{
				// update record
				Record::instance().recordScore(toScore(context_mychar.GetGlobalDouble(L"x")));
				currentState = ScreenState::Result;
			}
			break;
		case ScreenState::Result:
			renderBackgrounds(viewLeft, resources);
			renderBuildingLayers(buildingLayers, buildingLayers2, resources);
			renderMap(viewLeft, resources);
			renderHurdlesAndHitTest(viewLeft, context_mychar.GetGlobalDoubleVec2(L"x", L"y"), hurdles, resources);
			renderResult(toScore(context_mychar.GetGlobalDouble(L"x")), Record::instance().isUpdated(), fc);

			if (spacePressedInFrame)
			{
				// GameInit
				SoundAsset(SoundResourceLoader::decide).play();
				TitleTimer.reset();
				currentState = ScreenState::InTitle;
			}
			break;
		}
		if (prevState != currentState)
		{
			fc = 0;
		}
		prevState = currentState;

		// Common Postprocesses
		fc++;
		viewLeft += 2.5f;
	}

	Map::instance().clean();
}
/*!
  Paint the contents of a QwtPlot instance into a given rectangle.

  \param plot Plot to be rendered
  \param painter Painter
  \param plotRect Bounding rectangle

  \sa renderDocument(), renderTo(), QwtPainter::setRoundingAlignment()
*/
void QwtPlotRenderer::render( QwtPlot *plot,
    QPainter *painter, const QRectF &plotRect ) const
{
    if ( painter == 0 || !painter->isActive() ||
            !plotRect.isValid() || plot->size().isNull() )
    {
        return;
    }

    if ( !( d_data->discardFlags & DiscardBackground ) )
        QwtPainter::drawBackgound( painter, plotRect, plot );

    /*
      The layout engine uses the same methods as they are used
      by the Qt layout system. Therefore we need to calculate the
      layout in screen coordinates and paint with a scaled painter.
     */
    QTransform transform;
    transform.scale(
        double( painter->device()->logicalDpiX() ) / plot->logicalDpiX(),
        double( painter->device()->logicalDpiY() ) / plot->logicalDpiY() );

    QRectF layoutRect = transform.inverted().mapRect( plotRect );

    if ( !( d_data->discardFlags & DiscardBackground ) )
    {
        // subtract the contents margins

        int left, top, right, bottom;
        plot->getContentsMargins( &left, &top, &right, &bottom );
        layoutRect.adjust( left, top, -right, -bottom );
    }

    QwtPlotLayout *layout = plot->plotLayout();

    int baseLineDists[QwtAxis::PosCount];
    int canvasMargins[QwtAxis::PosCount];

    for ( int axisPos = 0; axisPos < QwtAxis::PosCount; axisPos++ )
    {
        canvasMargins[ axisPos ] = layout->canvasMargin( axisPos );

        if ( d_data->layoutFlags & FrameWithScales )
        {
            const QwtAxisId axisId( axisPos, QWT_DUMMY_ID );

            QwtScaleWidget *scaleWidget = plot->axisWidget( axisId );
            if ( scaleWidget )
            {
                baseLineDists[ axisPos ] = scaleWidget->margin();
                scaleWidget->setMargin( 0 );
            }

            if ( !plot->isAxisVisible( axisId ) )
            {
                int left = 0;
                int right = 0;
                int top = 0;
                int bottom = 0;

                // When we have a scale the frame is painted on
                // the position of the backbone - otherwise we
                // need to introduce a margin around the canvas

                switch( axisPos )
                {
                    case QwtAxis::yLeft:
                        layoutRect.adjust( 1, 0, 0, 0 );
                        break;
                    case QwtAxis::yRight:
                        layoutRect.adjust( 0, 0, -1, 0 );
                        break;
                    case QwtAxis::xTop:
                        layoutRect.adjust( 0, 1, 0, 0 );
                        break;
                    case QwtAxis::xBottom:
                        layoutRect.adjust( 0, 0, 0, -1 );
                        break;
                }
                layoutRect.adjust( left, top, right, bottom );
            }
        }
    }

    // Calculate the layout for the document.

    QwtPlotLayout::Options layoutOptions = QwtPlotLayout::IgnoreScrollbars;

    if ( ( d_data->layoutFlags & FrameWithScales ) ||
        ( d_data->discardFlags & DiscardCanvasFrame ) )
    {
        layoutOptions |= QwtPlotLayout::IgnoreFrames;
    } 


    if ( d_data->discardFlags & DiscardLegend )
        layoutOptions |= QwtPlotLayout::IgnoreLegend;

    if ( d_data->discardFlags & DiscardTitle )
        layoutOptions |= QwtPlotLayout::IgnoreTitle;

    if ( d_data->discardFlags & DiscardFooter )
        layoutOptions |= QwtPlotLayout::IgnoreFooter;

    layout->update( plot, layoutRect, layoutOptions );

    // canvas

    QwtScaleMapTable mapTable = buildCanvasMaps( plot, layout->canvasRect() );
    if ( updateCanvasMargins( plot, layout->canvasRect(), mapTable ) )
    {
        // recalculate maps and layout, when the margins
        // have been changed

        layout->update( plot, layoutRect, layoutOptions );
        mapTable = buildCanvasMaps( plot, layout->canvasRect() );
    }

    // now start painting

    painter->save();
    painter->setWorldTransform( transform, true );

    renderCanvas( plot, painter, layout->canvasRect(), mapTable );

    if ( !( d_data->discardFlags & DiscardTitle )
        && ( !plot->titleLabel()->text().isEmpty() ) )
    {
        renderTitle( plot, painter, layout->titleRect() );
    }

    if ( !( d_data->discardFlags & DiscardFooter )
        && ( !plot->footerLabel()->text().isEmpty() ) )
    {
        renderFooter( plot, painter, layout->footerRect() );
    }

    if ( !( d_data->discardFlags & DiscardLegend )
        && plot->legend() && !plot->legend()->isEmpty() )
    {
        renderLegend( plot, painter, layout->legendRect() );
    }

    for ( int axisPos = 0; axisPos < QwtAxis::PosCount; axisPos++ )
    {
        for ( int i = 0; i < plot->axesCount( i ); i++ )
        {
            const QwtAxisId axisId( axisPos, i );

            QwtScaleWidget *scaleWidget = plot->axisWidget( axisId );
            if ( scaleWidget )
            {
                int baseDist = scaleWidget->margin();

                int startDist, endDist;
                scaleWidget->getBorderDistHint( startDist, endDist );

                renderScale( plot, painter, axisId, startDist, endDist,
                    baseDist, layout->scaleRect( axisId ) );
            }
        }
    }

    painter->restore();

    // restore all setting to their original attributes.
    for ( int axisPos = 0; axisPos < QwtAxis::PosCount; axisPos++ )
    {
        if ( d_data->layoutFlags & FrameWithScales )
        {
            const QwtAxisId axisId( axisPos, QWT_DUMMY_ID );

            QwtScaleWidget *scaleWidget = plot->axisWidget( axisId );
            if ( scaleWidget  )
                scaleWidget->setMargin( baseLineDists[axisPos] );
        }

        layout->setCanvasMargin( canvasMargins[axisPos] );
    }

    layout->invalidate();

}