Ejemplo n.º 1
0
void Surface::EffectsBlit(int x, int y, Bitmap* src, Rect src_rect,
						   int top_opacity, int bottom_opacity, int opacity_split,
						   const Tone& tone,
						   double zoom_x, double zoom_y, double angle,
						   int waver_depth, double waver_phase) {
	bool rotate = angle != 0.0;
	bool scale = zoom_x != 1.0 || zoom_y != 1.0;
	bool waver = waver_depth != 0;
	bool tone_change = tone != Tone();
	bool opacity =
		(opacity_split <= 0) ? (top_opacity < 255) :
		(opacity_split >= src_rect.height) ? (bottom_opacity < 255) :
		(top_opacity < 255 || bottom_opacity < 255);
	opacity = top_opacity < 255 || bottom_opacity < 255;

	Surface* draw = (Surface*) NULL;

	if (tone_change) {
		if (!rotate && !scale && !opacity && !waver) {
			ToneBlit(x, y, src, src_rect, tone);
			return;
		}

		bool transparent = src->GetTransparent();
		draw = CreateSurface(src_rect.width, src_rect.height, transparent);
		if (transparent)
			draw->Clear();
		draw->ToneBlit(0, 0, src, src_rect, tone);
		src = draw;
		src_rect.x = 0;
		src_rect.y = 0;
	}

	if (rotate) {
		Matrix fwd = Matrix::Setup(angle, zoom_x, zoom_y, src_rect.x, src_rect.y, x, y);
		EffectsBlit(fwd, src, src_rect, top_opacity, bottom_opacity, opacity_split);
	}
	else if (scale)
		EffectsBlit(x, y, src, src_rect,
					top_opacity, bottom_opacity, opacity_split,
					zoom_x, zoom_y,
					waver_depth, waver_phase);
	else
		EffectsBlit(x, y, src, src_rect,
					top_opacity, bottom_opacity, opacity_split,
					waver_depth, waver_phase);

	if (draw != NULL)
		delete draw;
}