コード例 #1
0
ファイル: canvas.cpp プロジェクト: andy-c-huang/Hitchin
void Canvas::paintEvent(QPaintEvent *event)
{
    //clock_t t0 = clock();
    
    delegate->redraw(delegate->enableRedrawBufferBack, delegate->enableRedrawBufferTop);
    delegate->enableRedrawBuffer(false, false);
    
    
    
    //Tests
    int imageSize = delegate->getImageBack()->width();
    if (imageSize != imageMaxSize())
    {
        qDebug() << "Error in Canvas::paintEvent: image size doesn't fit canvas size";
    }
    
    QPainter canvasPainter(this);
    canvasPainter.setClipRegion(event->region());
    canvasPainter.drawImage(imageFirstCornerX(), imageFirstCornerY(), *(delegate->getImageBack()));
    canvasPainter.drawImage(imageFirstCornerX(), imageFirstCornerY(), *(delegate->getImageTop()));
    
    if (delegate->getSendEndRepaint())
    {
        delegate->handler->processMessage(ActionHandlerMessage::END_CANVAS_REPAINT);
    }
    
    //qDebug() << "Time spent painting canvas: " << (clock() -t0)*1.0/CLOCKS_PER_SEC;
}
コード例 #2
0
void LayerTextureUpdaterBitmap::prepareToUpdate(const IntRect& contentRect, const IntSize& tileSize, int borderTexels)
{
    m_texSubImage.setSubImageSize(tileSize);

    m_canvas.resize(contentRect.size());
    // Assumption: if a tiler is using border texels, then it is because the
    // layer is likely to be filtered or transformed. Because of it might be
    // transformed, draw the text in grayscale instead of subpixel antialiasing.
    PlatformCanvas::Painter::TextOption textOption =
        borderTexels ? PlatformCanvas::Painter::GrayscaleText : PlatformCanvas::Painter::SubpixelText;
    PlatformCanvas::Painter canvasPainter(&m_canvas, textOption);
    paintContents(*canvasPainter.context(), contentRect);
}
コード例 #3
0
void BitmapCanvasLayerTextureUpdater::prepareToUpdate(const IntRect& contentRect, const IntSize& tileSize, int borderTexels, float contentsScale, IntRect* resultingOpaqueRect)
{
    m_texSubImage.setSubImageSize(tileSize);

    bool layerIsOpaque = m_canvas.opaque();

    m_canvas.resize(contentRect.size());
    // Assumption: if a tiler is using border texels, then it is because the
    // layer is likely to be filtered or transformed. Because of it might be
    // transformed, draw the text in grayscale instead of subpixel antialiasing.
    PlatformCanvas::Painter::TextOption textOption =
        borderTexels ? PlatformCanvas::Painter::GrayscaleText : PlatformCanvas::Painter::SubpixelText;
    PlatformCanvas::Painter canvasPainter(&m_canvas, textOption);
    canvasPainter.skiaContext()->setTrackOpaqueRegion(!layerIsOpaque);
    paintContents(*canvasPainter.context(), *canvasPainter.skiaContext(), contentRect, contentsScale);

    if (!layerIsOpaque)
        *resultingOpaqueRect = canvasPainter.skiaContext()->opaqueRegion().asRect();
}
コード例 #4
0
ファイル: encoder.cpp プロジェクト: cubemoon/game-editor
KrCanvasResource* KrEncoder::Load32Canvas(	const char* filename,
											const KrRGBA* transparent,
											int nTrans,
											gedString* error )
{
	if ( !filename )
	{
		if ( error ) *error = "No filename for a surface specified";
		return 0;
	}

	// Try to load the file.
	SDL_Surface* surface = ImageLoader( filename );
	if ( !surface )
	{
		char buf[256];
		sprintf( buf, "Failed to load surface '%s'.", filename );

		if ( error ) *error = buf;
		return 0;
	}

	// The image can be 32 bits or less. A NON-32 bit image has
	// color(s) that are marked transparent. A 32 bit image
	// simply uses the alpha channel. Canvas's are always 32 bit,
	// and we always use a canvas that supports alpha.

	KrCanvasResource* canvas = new KrCanvasResource(	"encoder", 
														surface->w,
														surface->h,
														true );

	if ( !canvas )
	{
		if ( error ) *error = "Failed to create canvas.";
		return 0;
	}

	// Copy from the surface to the canvas.
	int x, y;
	int i;
	
	KrPaintInfo canvasPaintInfo( canvas->Pixels(), canvas->Width(), canvas->Height() );
	KrPainter	canvasPainter( &canvasPaintInfo );
	KrPainter	surfacePainter( surface );

	for( x=0; x<surface->w; x++ )
	{
		for( y=0; y<surface->h; y++ )
		{
			KrRGBA rgba;
			surfacePainter.BreakPixel( x, y, &rgba );	

			for ( i=0; i<nTrans; i++ )
			{
				if (	rgba.c.red   == transparent[i].c.red
					 && rgba.c.green == transparent[i].c.green
					 && rgba.c.blue  == transparent[i].c.blue )
				{
					// Set the surface alpha to transparent.
					rgba.c.alpha = KrRGBA::KR_TRANSPARENT;
					break;
				}
			}
			canvasPainter.SetPixel( x, y, rgba );
		}
	}
	return canvas;
}