- BlitBitmap(gi->deco.design.bitmap, drawto,
- gi->deco.design.x, gi->deco.design.y,
- gi->deco.width, gi->deco.height,
- gi->x + gi->deco.x + (pressed ? gi->deco.xshift : 0),
- gi->y + gi->deco.y + (pressed ? gi->deco.yshift : 0));
+ {
+ // make sure that decoration does not overlap gadget border
+ int deco_x = gi->deco.x + (pressed ? gi->deco.xshift : 0);
+ int deco_y = gi->deco.y + (pressed ? gi->deco.yshift : 0);
+ int deco_width = MIN(gi->deco.width, gi->width - deco_x);
+ int deco_height = MIN(gi->deco.height, gi->height - deco_y);
+
+ if (gi->deco.masked)
+ BlitBitmapMasked(gi->deco.design.bitmap, drawto,
+ gi->deco.design.x, gi->deco.design.y,
+ deco_width, deco_height,
+ gi->x + deco_x, gi->y + deco_y);
+ else
+ BlitBitmap(gi->deco.design.bitmap, drawto,
+ gi->deco.design.x, gi->deco.design.y,
+ deco_width, deco_height,
+ gi->x + deco_x, gi->y + deco_y);
+ }
+