示例#1
0
void SdlApplication::onRender()
{
	// Lock surface pixels.
	SDL_LockSurface(_screen);
	
	// Create Fog::Painter instance mapped to the SDL surface data.
	Fog::Painter p;
	
	// Setup image buffer for painter.
	Fog::ImageBits buf;
	
	buf.setData(Fog::SizeI(_screen->w, _screen->h), Fog::IMAGE_FORMAT_XRGB32, _screen->pitch, (reinterpret_cast<uint8_t*>(_screen->pixels)));
	
	// Call our paint handler.
	if (p.begin(buf) == Fog::ERR_OK) onPaint(p);
	
	// Never forget to call p.end(). Painting can be asynchronous and
	// SDL_UnlockSurface() can invalidate the surface->pixels pointer.
	p.end();
	
	// Unlock surface pixels.
	SDL_UnlockSurface(_screen);
	
	// Flip buffer.
	//SDL_Flip(_screen);
	SDL_UpdateWindowSurface(win);
}
示例#2
0
void SdlApplication::onPaint(Fog::Painter& p)
{
	// Just use the Fog-Framework ;-)
	
	// Create some variable we will work with.
	float w = float(_screen->w);
	float h = float(_screen->h);
	
	float roundw = 100.0f;
	float roundh = 100.0f;
	
	Fog::PointF cp(w / 2.0f, h / 2.0f);
	
	// Clear the entire screen.
	p.setSource(Fog::Argb32(0xFF000000));
	p.fillAll();
	
	p.save();
	
	// Rotate across the screen center point.
	p.transform(createRotationMatrix(cp, _rotate));
	
	// And draw something...
	Fog::LinearGradientF gradient;
	
	//gradient
	gradient.setStart(cp.x - roundw / 2.0f, cp.y - roundh / 2.0f);
	gradient.setEnd(cp.x + roundw / 2.0f, cp.y + roundh / 2.0f);
	gradient.addStop(0.0f, Fog::Argb32(0xFFFFFFFF));
	gradient.addStop(0.5f, Fog::Argb32(0xFFFFFF00));
	gradient.addStop(1.0f, Fog::Argb32(0xFFFF0000));
	p.setSource(gradient);
	
	//p.setSource(Fog::Argb32(0xFFFF0000));

	
	
	p.fillRound(Fog::RoundF(
							Fog::RectF(cp.x - roundw / 2.0f, cp.y - roundh / 2.0f, roundw, roundh),
							Fog::PointF(20.0f, 20.0f)));
	
	p.restore();
}
示例#3
0
bool loadSvgFile(Image &img, const char *path) {
	Fog::Logger::getGlobal()->setSeverity(100);
	Fog::Logger::getLocal()->setSeverity(100);
	
	size_t width = 400, height = 400;
	Fog::SvgDocument svg;
	unsigned err;
	if ((err=svg.readFromFile(StringW::fromAscii8(path)))) {
		fprintf(stderr, "Failed to load SVG %s error %05X ERR_XML_SAX_NO_DOCUMENT=%05X\n", path, err, Fog::ERR_XML_SAX_NO_DOCUMENT);
		return false;
	}
	Fog::SizeF size = svg.getDocumentSize();
	if (size.w >= 2 && size.w <= 2048) width = size.w;
	if (size.h >= 2 && size.h <= 2048) height = size.h;
	svg.getResourceManager()->loadQueuedResources();
	Fog::SizeI si;
	void *imgdata=malloc(width*height*4);
	if (!imgdata) return false;
	si.w = width; si.h = height;
	Fog::ImageBits imgbits(si, Fog::IMAGE_FORMAT_PRGB32, width*4, (unsigned char*)imgdata);
	Fog::Painter painter;
	if ((err=painter.begin(imgbits))) {
		fprintf(stderr, "Failed to select surface to SVG rendering %s error %05X\n", path, err);
	}
	
	painter.setSource(Fog::Argb32(0xFFFFFFFF));
	painter.fillAll();
	if ((err=svg.render(&painter))) {
		fprintf(stderr, "Failed to render SVG %s error %05X\n", path, err);
	}
	painter.flush(Fog::PAINTER_FLUSH_SYNC);
	painter.end();
	load_from_pixels(img, imgdata, width, height, 4, true);
	free(imgdata);
	return true;
}