示例#1
0
void DrawGame(GameRenderer* g, World* world)
{
	CheckResize(g, world);
	//Prepare to render to texture.
	SDL_SetRenderTarget(g->renderer, g->gameTexture);
	
	//Clear screen
	SDL_SetRenderDrawColor( g->renderer, 0xFF, 0xFF, 0xFF, 0xFF );
	SDL_RenderClear( g->renderer );
	
	//Draw our grid
	//Resizing the background grid looks terrible.
	if(g->zoom >= 0)
	{
		DrawBackgroundGrid( g->renderer, g->screenGame.w, g->screenGame.h, &g->gridProps );		
	}
	DrawCells(g->renderer, &g->gridProps, world);		
	SDL_RenderPresent( g->renderer );

	//Now draw the rest of the screen
	SDL_SetRenderTarget(g->renderer, NULL);
	SDL_SetRenderDrawColor( g->renderer, 180, 180, 180, 255 );
	SDL_RenderClear( g->renderer );

	SDL_RenderCopy(g->renderer, g->gameTexture, NULL, &(g->screenGame));
	//Draw the ring of greyed-out game areas around our game area, to represent world wrapping to the user.
	SDL_SetTextureColorMod(g->gameTexture, 240, 240, 240);
	int startX = g->screenGame.x - g->screenGame.w;
	int startY = g->screenGame.y - g->screenGame.h;
	SDL_Rect current;
	current.w = g->screenGame.w;
	current.h = g->screenGame.h;
	for(int iterX = 0; iterX < 3; ++iterX)
	{
		for(int iterY = 0; iterY < 3; ++iterY)
		{
			//Don't draw over primary game area.
			if( ! ((iterX == 1) && (iterY == 1)))
			{
				current.x = startX + (current.w	* iterX);
				current.y = startY + (current.h	* iterY);
				SDL_RenderCopy(g->renderer, g->gameTexture, NULL, &current);
			}
		}
	}

	SDL_SetTextureColorMod(g->gameTexture, 255, 255, 255);
	SDL_RenderPresent(g->renderer);
}
bool HistogramDrawingArea::on_expose_event( GdkEventExpose* event )
{    
    Glib::RefPtr<Gdk::Window> window = get_window();
    if( window == NULL)
    {
        return true;
    }

    Cairo::RefPtr<Cairo::Context> refCairo = window->create_cairo_context();

    // clip to the area indicated by the expose event so that we only redraw
    // the portion of the window that needs to be redrawn
    refCairo->rectangle(
        event->area.x, 
        event->area.y,
        event->area.width, 
        event->area.height);
    refCairo->clip();               

    // Clear the background
    refCairo->set_source_rgb( 255, 255, 255 );
    refCairo->paint();

    Glib::Mutex::Lock pixBufLock(statsMutex, Glib::NOT_LOCK );
    if ( pixBufLock.try_acquire() != true )
    {
        return true;
    }

    if ( m_drawMode == Histogram::MODE_HISTOGRAM )
    {
        for ( int i=0; i < ImageStatistics::NUM_STATISTICS_CHANNELS; i++ )
        {            
            DrawSingleHistogramLine( 
                refCairo, 
                static_cast<ImageStatistics::StatisticsChannel>(i) );
        }
        
        DrawHistogramGridLabels( refCairo );
    }
    else if ( m_drawMode == Histogram::MODE_ROWCOL )
    {
        double red, green, blue;

        if ( m_dispOptions.showGrey == true )
        {            
            GetLineColor( ImageStatistics::GREY, red, green, blue );

            DrawSingleRowColChannel( 
                refCairo, 
                m_rowColStats.grey, 
                m_rowColStats.numPixelValues,
                red, 
                green, 
                blue );
        }

        if ( m_dispOptions.showRed == true )
        {
            GetLineColor( ImageStatistics::RED, red, green, blue );

            DrawSingleRowColChannel( 
                refCairo, 
                m_rowColStats.red, 
                m_rowColStats.numPixelValues,
                red, 
                green, 
                blue );
        }

        if ( m_dispOptions.showGreen == true )
        {
            GetLineColor( ImageStatistics::GREEN, red, green, blue );

            DrawSingleRowColChannel( 
                refCairo, 
                m_rowColStats.green, 
                m_rowColStats.numPixelValues,
                red, 
                green, 
                blue );
        }

        if ( m_dispOptions.showBlue == true )
        {
            GetLineColor( ImageStatistics::BLUE, red, green, blue );

            DrawSingleRowColChannel( 
                refCairo, 
                m_rowColStats.blue, 
                m_rowColStats.numPixelValues,
                red, 
                green, 
                blue );
        }

        DrawRowColGridLabels( 
            refCairo, 
            m_rowColStats.numPixelValues, 
            m_rowColStats.imageDimension );
    }    

    DrawBackgroundGrid( refCairo );

    return true;
}