+ // the area we're about to blit is transparent, so it doesn't
+ // matter whether we use 'straight' or 'straight onto' here
+ if (blend_method == Color::BLEND_ALPHA_BRIGHTEN)
+ apen.set_blend_method(blend_method);
+ else
+ apen.set_blend_method(Color::BLEND_STRAIGHT);
+
+ /* This represents the area we're pasting into the tile,
+ * within the tile as a whole. Areas (A), (B), (C) and (D)
+ * need blending with the underlying context if they're not
+ * zero-sized:
+ *
+ * 0 x x+w tw
+ * 0 +------------------------+
+ * | |
+ * | (A) |
+ * | |
+ * y | - - +----------+ - - - |
+ * | | | |
+ * | (C) | w by h | (D) |
+ * | | | |
+ * y+h | - - +----------+ - - - |
+ * | |
+ * | (B) |
+ * | |
+ * tw +------------------------+
+ */
+
+ if (y > 0) // draw the full-width strip above the rectangle (A)
+ { apen.move_to(0,0); clearsurface.set_wh(tw,y); clearsurface.clear(); clearsurface.blit_to(apen); }
+ if (y+h < th) // draw the full-width strip below the rectangle (B)
+ { apen.move_to(0,y+h); clearsurface.set_wh(tw,th-(y+h)); clearsurface.clear(); clearsurface.blit_to(apen); }
+ if (x > 0) // draw the box directly left of the rectangle (C)
+ { apen.move_to(0,y); clearsurface.set_wh(x,h); clearsurface.clear(); clearsurface.blit_to(apen); }
+ if (x+w < tw) // draw the box directly right of the rectangle (D)
+ { apen.move_to(x+w,y); clearsurface.set_wh(tw-(x+w),h); clearsurface.clear(); clearsurface.blit_to(apen); }