summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2016-12-25 17:57:47 +0000
committerfrosch <frosch@openttd.org>2016-12-25 17:57:47 +0000
commitf882a5aa003849585140e2da10468639af1bc7e4 (patch)
tree4ec34e6777b676dda453f15ad96159c12430305d
parent3419bff4ed1e3cab9ed1e2374f6269e2d7321135 (diff)
downloadopenttd-f882a5aa003849585140e2da10468639af1bc7e4.tar.xz
(svn r27713) -Fix [FS#6527]: Setup clipping areas for individual widgets when drawing. (adf88)
-rw-r--r--src/widget.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/widget.cpp b/src/widget.cpp
index d59ca020e..2c06cfe29 100644
--- a/src/widget.cpp
+++ b/src/widget.cpp
@@ -2393,15 +2393,22 @@ void NWidgetLeaf::Draw(const Window *w)
{
if (this->current_x == 0 || this->current_y == 0) return;
+ /* Setup a clipping rectangle... */
+ DrawPixelInfo new_dpi;
+ if (!FillDrawPixelInfo(&new_dpi, this->pos_x, this->pos_y, this->current_x, this->current_y)) return;
+ /* ...but keep coordinates relative to the window. */
+ new_dpi.left += this->pos_x;
+ new_dpi.top += this->pos_y;
+
+ DrawPixelInfo *old_dpi = _cur_dpi;
+ _cur_dpi = &new_dpi;
+
Rect r;
r.left = this->pos_x;
r.right = this->pos_x + this->current_x - 1;
r.top = this->pos_y;
r.bottom = this->pos_y + this->current_y - 1;
- const DrawPixelInfo *dpi = _cur_dpi;
- if (dpi->left > r.right || dpi->left + dpi->width <= r.left || dpi->top > r.bottom || dpi->top + dpi->height <= r.top) return;
-
bool clicked = this->IsLowered();
switch (this->type) {
case WWT_EMPTY:
@@ -2512,6 +2519,8 @@ void NWidgetLeaf::Draw(const Window *w)
if (this->IsDisabled()) {
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, _colour_gradient[this->colour & 0xF][2], FILLRECT_CHECKER);
}
+
+ _cur_dpi = old_dpi;
}
/**