Clip widget draw calls which are outside _cur_dpi
This commit is contained in:
@@ -1048,6 +1048,7 @@ void NWidgetStacked::FillNestedArray(NWidgetBase **array, uint length)
|
||||
|
||||
void NWidgetStacked::Draw(const Window *w)
|
||||
{
|
||||
if (this->IsOutsideDrawArea()) return;
|
||||
if (this->shown_plane >= SZSP_BEGIN) return;
|
||||
|
||||
int plane = 0;
|
||||
@@ -1107,6 +1108,7 @@ void NWidgetPIPContainer::SetPIP(uint8 pip_pre, uint8 pip_inter, uint8 pip_post)
|
||||
|
||||
void NWidgetPIPContainer::Draw(const Window *w)
|
||||
{
|
||||
if (this->IsOutsideDrawArea()) return;
|
||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
||||
child_wid->Draw(w);
|
||||
}
|
||||
@@ -1623,6 +1625,8 @@ NWidgetCore *NWidgetMatrix::GetWidgetFromPos(int x, int y)
|
||||
|
||||
/* virtual */ void NWidgetMatrix::Draw(const Window *w)
|
||||
{
|
||||
if (this->IsOutsideDrawArea()) return;
|
||||
|
||||
/* Fill the background. */
|
||||
GfxFillRect(this->pos_x, this->pos_y, this->pos_x + this->current_x - 1, this->pos_y + this->current_y - 1, _colour_gradient[this->colour & 0xF][5]);
|
||||
|
||||
@@ -1826,6 +1830,7 @@ void NWidgetBackground::FillNestedArray(NWidgetBase **array, uint length)
|
||||
|
||||
void NWidgetBackground::Draw(const Window *w)
|
||||
{
|
||||
if (this->IsOutsideDrawArea()) return;
|
||||
if (this->current_x == 0 || this->current_y == 0) return;
|
||||
|
||||
Rect r;
|
||||
@@ -1900,6 +1905,7 @@ void NWidgetViewport::SetupSmallestSize(Window *w, bool init_array)
|
||||
|
||||
void NWidgetViewport::Draw(const Window *w)
|
||||
{
|
||||
if (this->IsOutsideDrawArea()) return;
|
||||
if (this->disp_flags & ND_NO_TRANSPARENCY) {
|
||||
TransparencyOptionBits to_backup = _transparency_opt;
|
||||
_transparency_opt &= (1 << TO_SIGNS) | (1 << TO_LOADING); // Disable all transparency, except textual stuff
|
||||
@@ -2023,6 +2029,7 @@ void NWidgetScrollbar::SetupSmallestSize(Window *w, bool init_array)
|
||||
|
||||
void NWidgetScrollbar::Draw(const Window *w)
|
||||
{
|
||||
if (this->IsOutsideDrawArea()) return;
|
||||
if (this->current_x == 0 || this->current_y == 0) return;
|
||||
|
||||
Rect r;
|
||||
@@ -2390,6 +2397,7 @@ void NWidgetLeaf::SetupSmallestSize(Window *w, bool init_array)
|
||||
|
||||
void NWidgetLeaf::Draw(const Window *w)
|
||||
{
|
||||
if (this->IsOutsideDrawArea()) return;
|
||||
if (this->current_x == 0 || this->current_y == 0) return;
|
||||
|
||||
/* Setup a clipping rectangle... */
|
||||
|
@@ -14,6 +14,7 @@
|
||||
#include "core/bitmath_func.hpp"
|
||||
#include "core/math_func.hpp"
|
||||
#include "strings_type.h"
|
||||
#include "gfx_func.h"
|
||||
#include "gfx_type.h"
|
||||
#include "window_type.h"
|
||||
|
||||
@@ -183,6 +184,13 @@ public:
|
||||
uint8 padding_bottom; ///< Paddings added to the bottom of the widget. Managed by parent container widget.
|
||||
uint8 padding_left; ///< Paddings added to the left of the widget. Managed by parent container widget. (parent container may swap this with padding_right for RTL)
|
||||
|
||||
inline bool IsOutsideDrawArea() const
|
||||
{
|
||||
if ((int)(this->pos_x + this->current_x) <= _cur_dpi->left || (int)(this->pos_x) >= _cur_dpi->left + _cur_dpi->width) return true;
|
||||
if ((int)(this->pos_y + this->current_y) <= _cur_dpi->top || (int)(this->pos_y) >= _cur_dpi->top + _cur_dpi->height) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
protected:
|
||||
inline void StoreSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height);
|
||||
};
|
||||
|
Reference in New Issue
Block a user