From 1bfaeb1dbca74a80bebba87cebdd2e3e9cc40526 Mon Sep 17 00:00:00 2001 From: TechGeekNZ Date: Mon, 8 Jun 2020 10:38:06 +1200 Subject: [PATCH 1/2] Cleanup: Give `SetDirtyBlocks` a more descriptive name. --- src/gfx.cpp | 27 ++++++++++++++++++--------- src/gfx_func.h | 2 +- src/news_gui.cpp | 2 +- src/viewport.cpp | 2 +- src/widget.cpp | 2 +- src/window.cpp | 4 ++-- 6 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/gfx.cpp b/src/gfx.cpp index a5e577205086..6039946fc640 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -1416,6 +1416,16 @@ void DrawMouseCursor() _cursor.dirty = false; } +/** + * Repaints a specific rectangle of the screen. + * + * @param left,top,right,bottom The area of the screen that needs repainting + * @pre The rectangle should have been previously marked dirty with \c AddDirtyBlock. + * @see AddDirtyBlock + * @see DrawDirtyBlocks + * @ingroup dirty + * + */ void RedrawScreenRect(int left, int top, int right, int bottom) { assert(right <= _screen.width && bottom <= _screen.height); @@ -1438,7 +1448,9 @@ void RedrawScreenRect(int left, int top, int right, int bottom) /** * Repaints the rectangle blocks which are marked as 'dirty'. * - * @see SetDirtyBlocks + * @see AddDirtyBlock + * + * @ingroup dirty */ void DrawDirtyBlocks() { @@ -1541,21 +1553,18 @@ void DrawDirtyBlocks() } /** - * This function extends the internal _invalid_rect rectangle as it - * now contains the rectangle defined by the given parameters. Note - * the point (0,0) is top left. + * Extend the internal _invalid_rect rectangle to contain the rectangle + * defined by the given parameters. Note the point (0,0) is top left. * * @param left The left edge of the rectangle * @param top The top edge of the rectangle * @param right The right edge of the rectangle * @param bottom The bottom edge of the rectangle * @see DrawDirtyBlocks + * @ingroup dirty * - * @todo The name of the function should be called like @c AddDirtyBlock as - * it neither set a dirty rect nor add several dirty rects although - * the function name is in plural. (Progman) */ -void SetDirtyBlocks(int left, int top, int right, int bottom) +void AddDirtyBlock(int left, int top, int right, int bottom) { byte *b; int width; @@ -1600,7 +1609,7 @@ void SetDirtyBlocks(int left, int top, int right, int bottom) */ void MarkWholeScreenDirty() { - SetDirtyBlocks(0, 0, _screen.width, _screen.height); + AddDirtyBlock(0, 0, _screen.width, _screen.height); } /** diff --git a/src/gfx_func.h b/src/gfx_func.h index 0ccdabac3d51..0edbf722a1fe 100644 --- a/src/gfx_func.h +++ b/src/gfx_func.h @@ -131,7 +131,7 @@ Point GetCharPosInString(const char *str, const char *ch, FontSize start_fontsiz const char *GetCharAtPosition(const char *str, int x, FontSize start_fontsize = FS_NORMAL); void DrawDirtyBlocks(); -void SetDirtyBlocks(int left, int top, int right, int bottom); +void AddDirtyBlock(int left, int top, int right, int bottom); void MarkWholeScreenDirty(); void GfxInitPalettes(); diff --git a/src/news_gui.cpp b/src/news_gui.cpp index 01b69677e32f..9993645c43a3 100644 --- a/src/news_gui.cpp +++ b/src/news_gui.cpp @@ -571,7 +571,7 @@ struct NewsWindow : Window { if (this->viewport != nullptr) this->viewport->top += newtop - this->top; this->top = newtop; - SetDirtyBlocks(this->left, mintop, this->left + this->width, maxtop + this->height); + AddDirtyBlock(this->left, mintop, this->left + this->width, maxtop + this->height); } StringID GetCompanyMessageString() const diff --git a/src/viewport.cpp b/src/viewport.cpp index 1c9dca1ef6ba..28345db60706 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -1886,7 +1886,7 @@ static void MarkViewportDirty(const ViewPort *vp, int left, int top, int right, if (top >= vp->virtual_height) return; - SetDirtyBlocks( + AddDirtyBlock( UnScaleByZoomLower(left, vp->zoom) + vp->left, UnScaleByZoomLower(top, vp->zoom) + vp->top, UnScaleByZoom(right, vp->zoom) + vp->left + 1, diff --git a/src/widget.cpp b/src/widget.cpp index eb683c4128e4..579b7efb6432 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -774,7 +774,7 @@ void NWidgetBase::SetDirty(const Window *w) const { int abs_left = w->left + this->pos_x; int abs_top = w->top + this->pos_y; - SetDirtyBlocks(abs_left, abs_top, abs_left + this->current_x, abs_top + this->current_y); + AddDirtyBlock(abs_left, abs_top, abs_left + this->current_x, abs_top + this->current_y); } /** diff --git a/src/window.cpp b/src/window.cpp index 30fa4d3d1245..e7bc6d2c4bb3 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -983,7 +983,7 @@ void DrawOverlappedWindowForAll(int left, int top, int right, int bottom) */ void Window::SetDirty() const { - SetDirtyBlocks(this->left, this->top, this->left + this->width, this->top + this->height); + AddDirtyBlock(this->left, this->top, this->left + this->width, this->top + this->height); } /** @@ -3493,7 +3493,7 @@ static int PositionWindow(Window *w, WindowClass clss, int setting) default: w->left = 0; break; } if (w->viewport != nullptr) w->viewport->left += w->left - old_left; - SetDirtyBlocks(0, w->top, _screen.width, w->top + w->height); // invalidate the whole row + AddDirtyBlock(0, w->top, _screen.width, w->top + w->height); // invalidate the whole row return w->left; } From dc22eb4651c5295f6477ddd4f7c9434392521ea3 Mon Sep 17 00:00:00 2001 From: TechGeekNZ Date: Tue, 9 Jun 2020 10:18:23 +1200 Subject: [PATCH 2/2] Cleanup: Fix typos in code comments. --- src/window.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/window.cpp b/src/window.cpp index e7bc6d2c4bb3..9fea6d1026c3 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -655,7 +655,7 @@ static void DispatchLeftClickEvent(Window *w, int x, int y, int click_count) WidgetType widget_type = (nw != nullptr) ? nw->type : WWT_EMPTY; bool focused_widget_changed = false; - /* If clicked on a window that previously did dot have focus */ + /* If clicked on a window that previously did not have focus */ if (_focused_window != w && // We already have focus, right? (w->window_desc->flags & WDF_NO_FOCUS) == 0 && // Don't lose focus to toolbars widget_type != WWT_CLOSEBOX) { // Don't change focused window if 'X' (close button) was clicked