From 8a5f6ed1f9667e1b25894fbf20cecb26cee8c5c7 Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Sun, 28 Sep 2014 22:20:03 +0100 Subject: [PATCH 2/6] -Codechange: Standardise the use of Points somewhat. --- src/fence_gui.cpp | 2 +- src/gui_graphics.cpp | 4 ++-- src/path_gui.cpp | 6 ++++-- src/ride_gui.cpp | 5 ++--- src/toolbar_gui.cpp | 4 ++-- src/video.cpp | 25 ++++++------------------- src/video.h | 10 ++++------ src/widget.cpp | 8 ++++---- 8 files changed, 25 insertions(+), 39 deletions(-) diff --git a/src/fence_gui.cpp b/src/fence_gui.cpp index 7532717..1e9d178 100644 --- a/src/fence_gui.cpp +++ b/src/fence_gui.cpp @@ -115,7 +115,7 @@ void FenceGui::DrawWidget(WidgetNumber wid_num, const BaseWidget *wid) const lines--; Recolouring recolouring; - _video.BlitImage(rect.x, rect.y - sprite->yoffset, sprite, recolouring, GS_NORMAL); + _video.BlitImage({rect.x, rect.y - sprite->yoffset}, sprite, recolouring, GS_NORMAL); rect.y += sprite->height; } break; diff --git a/src/gui_graphics.cpp b/src/gui_graphics.cpp index 86b29f1..dfa6910 100644 --- a/src/gui_graphics.cpp +++ b/src/gui_graphics.cpp @@ -30,7 +30,7 @@ static void DrawRepeatedSprites(int32 x_base, int32 y_base, const ImageData *spr { if (numx == 0 || numy == 0) return; if (!spr->IsSinglePixel()) { - _video.BlitImages(x_base, y_base, spr, numx, numy, recolour); + _video.BlitImages({x_base, y_base}, spr, numx, numy, recolour); return; } uint32 colour = spr->GetPixel(0, 0, &recolour); @@ -129,7 +129,7 @@ void OverlayShaded(const Rectangle32 &rect) uint16 numy = (r.height + img->height - 1) / img->height; static const Recolouring recolour; // Fixed recolouring mapping. - _video.BlitImages(base_x, base_y, img, numx, numy, recolour); + _video.BlitImages({base_x, base_y}, img, numx, numy, recolour); _video.SetClippedRectangle(cr); // Restore clipped area. } diff --git a/src/path_gui.cpp b/src/path_gui.cpp index cd808b0..4a0e0ef 100644 --- a/src/path_gui.cpp +++ b/src/path_gui.cpp @@ -225,7 +225,8 @@ void PathBuildGui::DrawWidget(WidgetNumber wid_num, const BaseWidget *wid) const if (img != nullptr) { int dx = (wid->pos.width - path_type_button_size.width) / 2; int dy = (wid->pos.height - path_type_button_size.height) / 2; - _video.BlitImage(GetWidgetScreenX(wid) + dx - path_type_button_size.base.x, GetWidgetScreenY(wid) + dy - path_type_button_size.base.y, img, recolour, GS_NORMAL); + Point32 pt(GetWidgetScreenX(wid) + dx - path_type_button_size.base.x, GetWidgetScreenY(wid) + dy - path_type_button_size.base.y); + _video.BlitImage(pt, img, recolour, GS_NORMAL); } } break; @@ -239,7 +240,8 @@ void PathBuildGui::DrawWidget(WidgetNumber wid_num, const BaseWidget *wid) const if (img != nullptr) { int dx = (wid->pos.width - path_type_button_size.width) / 2; int dy = (wid->pos.height - path_type_button_size.height) / 2; - _video.BlitImage(GetWidgetScreenX(wid) + dx - path_type_button_size.base.x, GetWidgetScreenY(wid) + dy - path_type_button_size.base.y, img, recolour, GS_NORMAL); + Point32 pt(GetWidgetScreenX(wid) + dx - path_type_button_size.base.x, GetWidgetScreenY(wid) + dy - path_type_button_size.base.y); + _video.BlitImage(pt, img, recolour, GS_NORMAL); } } break; diff --git a/src/ride_gui.cpp b/src/ride_gui.cpp index 6851688..f72631d 100644 --- a/src/ride_gui.cpp +++ b/src/ride_gui.cpp @@ -221,9 +221,8 @@ void RideSelectGui::DrawWidget(WidgetNumber wid_num, const BaseWidget *wid) cons /* Display the selected shop in the ride select window. */ if (ride_type != nullptr && ride_type->kind == RTK_SHOP) { static const Recolouring recolour; // Never modified, display 'original' image in the GUI. - _video.BlitImage(this->GetWidgetScreenX(wid) + wid->pos.width / 2, - this->GetWidgetScreenY(wid) + 40, ride_type->GetView(_shop_placer.orientation), - recolour, GS_NORMAL); + Point32 pt(this->GetWidgetScreenX(wid) + wid->pos.width / 2, this->GetWidgetScreenY(wid) + 40); + _video.BlitImage(pt, ride_type->GetView(_shop_placer.orientation), recolour, GS_NORMAL); } } break; diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index 590e9f8..57ba0ae 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -368,14 +368,14 @@ void BottomToolbarWindow::DrawWidget(WidgetNumber wid_num, const BaseWidget *wid Viewport *vp = GetViewport(); int dir = (vp == nullptr) ? 0 : vp->orientation; const ImageData *img = _sprite_manager.GetTableSprite(SPR_GUI_COMPASS_START + dir); - if (img != nullptr) _video.BlitImage(GetWidgetScreenX(wid), GetWidgetScreenY(wid), img, recolour, GS_NORMAL); + if (img != nullptr) _video.BlitImage({GetWidgetScreenX(wid), GetWidgetScreenY(wid)}, img, recolour, GS_NORMAL); break; } case BTB_WEATHER: { int spr = SPR_GUI_WEATHER_START + _weather.GetWeatherType(); const ImageData *img = _sprite_manager.GetTableSprite(spr); - if (img != nullptr) _video.BlitImage(GetWidgetScreenX(wid), GetWidgetScreenY(wid), img, recolour, GS_NORMAL); + if (img != nullptr) _video.BlitImage({GetWidgetScreenX(wid), GetWidgetScreenY(wid)}, img, recolour, GS_NORMAL); break; } } diff --git a/src/video.cpp b/src/video.cpp index 7943266..f277946 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -439,6 +439,7 @@ void VideoSystem::MainLoop() if (_finish) break; uint32 now = SDL_GetTicks(); + if (now - start != 0) printf("%ims\n", now - start); if (now >= start) { // No wrap around. now -= start; if (now < FRAME_DELAY) SDL_Delay(FRAME_DELAY - now); // Too early, wait until next frame. @@ -487,20 +488,7 @@ void VideoSystem::FinishRepaint() */ void VideoSystem::BlitImage(const Point32 &img_base, const ImageData *spr, const Recolouring &recolour, GradientShift shift) { - this->BlitImage(img_base.x, img_base.y, spr, recolour, shift); -} - -/** - * Blit an image at the specified position (top-left position) relative to #blit_rect. - * @param x Horizontal position. - * @param y Vertical position. - * @param img The sprite image data to blit. - * @param recolour Sprite recolouring definition. - * @param shift Gradient shift. - */ -void VideoSystem::BlitImage(int x, int y, const ImageData *img, const Recolouring &recolour, GradientShift shift) -{ - this->BlitImages(x, y, img, 1, 1, recolour, shift); + this->BlitImages(img_base, spr, 1, 1, recolour, shift); } /** @@ -673,20 +661,19 @@ static void Blit32bppImages(const ClippedRectangle &cr, int32 x_base, int32 y_ba /** * Blit pixels from the \a spr relative to \a img_base into the area. - * @param x_base Base X coordinate of the sprite data. - * @param y_base Base Y coordinate of the sprite data. + * @param pt Base coordinates of the sprite data. * @param spr The sprite to blit. * @param numx Number of sprites to draw in horizontal direction. * @param numy Number of sprites to draw in vertical direction. * @param recolour Sprite recolouring definition. * @param shift Gradient shift. */ -void VideoSystem::BlitImages(int32 x_base, int32 y_base, const ImageData *spr, uint16 numx, uint16 numy, const Recolouring &recolour, GradientShift shift) +void VideoSystem::BlitImages(const Point32 &pt, const ImageData *spr, uint16 numx, uint16 numy, const Recolouring &recolour, GradientShift shift) { this->blit_rect.ValidateAddress(); - x_base += spr->xoffset; - y_base += spr->yoffset; + int x_base = pt.x + spr->xoffset; + int y_base = pt.y + spr->yoffset; /* Don't draw wildly outside the screen. */ while (numx > 0 && x_base + spr->width < 0) { diff --git a/src/video.h b/src/video.h index 06d8fcd..9c9c7ba 100644 --- a/src/video.h +++ b/src/video.h @@ -101,9 +101,6 @@ public: void SetClippedRectangle(const ClippedRectangle &cr); ClippedRectangle GetClippedRectangle(); - void BlitImage(const Point32 &img_base, const ImageData *spr, const Recolouring &recolour, GradientShift shift); - void BlitImage(int x, int y, const ImageData *img, const Recolouring &recolour, GradientShift shift); - /** * Blit a row of sprites. * @param xmin Start X position. @@ -114,7 +111,7 @@ public: */ inline void BlitHorizontal(int32 xmin, uint16 numx, int32 y, const ImageData *spr, const Recolouring &recolour) { - this->BlitImages(xmin, y, spr, numx, 1, recolour); + this->BlitImages({xmin, y}, spr, numx, 1, recolour); } /** @@ -127,10 +124,11 @@ public: */ inline void BlitVertical(int32 ymin, uint16 numy, int32 x, const ImageData *spr, const Recolouring &recolour) { - this->BlitImages(x, ymin, spr, 1, numy, recolour); + this->BlitImages({x, ymin}, spr, 1, numy, recolour); } - void BlitImages(int32 x_base, int32 y_base, const ImageData *spr, uint16 numx, uint16 numy, const Recolouring &recolour, GradientShift shift = GS_NORMAL); + void BlitImage(const Point32 &img_base, const ImageData *spr, const Recolouring &recolour, GradientShift shift); + void BlitImages(const Point32 &pt, const ImageData *spr, uint16 numx, uint16 numy, const Recolouring &recolour, GradientShift shift = GS_NORMAL); void FinishRepaint(); diff --git a/src/widget.cpp b/src/widget.cpp index 4c34058..376677e 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -292,7 +292,7 @@ void LeafWidget::Draw(const GuiWindow *w) } else if ((this->flags & LWF_PRESSED) != 0) { spr_num += WCS_EMPTY_PRESSED; } - _video.BlitImage(left, top, _gui_sprites.radio_button.sprites[spr_num], rc, GS_NORMAL); + _video.BlitImage({left, top}, _gui_sprites.radio_button.sprites[spr_num], rc, GS_NORMAL); return; } @@ -319,7 +319,7 @@ void LeafWidget::Draw(const GuiWindow *w) int yoffset = top + (bottom - 1 - top - _gui_sprites.close_sprite->height) / 2; const ImageData *imgdata = _gui_sprites.close_sprite; - if (imgdata != nullptr) _video.BlitImage(xoffset + 1, yoffset + 1, imgdata, rc, GS_NORMAL); + if (imgdata != nullptr) _video.BlitImage({xoffset + 1, yoffset + 1}, imgdata, rc, GS_NORMAL); /* Closebox is never shaded. */ } } @@ -500,7 +500,7 @@ void DataWidget::Draw(const GuiWindow *w) int xoffset = left + (right + 1 - left - this->value_width) / 2 - rect.base.x; yoffset -= rect.base.y; const ImageData *imgdata = _sprite_manager.GetTableSprite(this->value); - if (imgdata != nullptr) _video.BlitImage(xoffset + pressed, yoffset + pressed, imgdata, rc, GS_NORMAL); + if (imgdata != nullptr) _video.BlitImage({xoffset + pressed, yoffset + pressed}, imgdata, rc, GS_NORMAL); break; } @@ -513,7 +513,7 @@ void DataWidget::Draw(const GuiWindow *w) if (imgdata != nullptr) { int triangle_yoff = top + (bottom + 1 - top - imgrect.height) / 2 + pressed; - _video.BlitImage(right - imgrect.width + pressed, triangle_yoff, imgdata, rc, GS_NORMAL); + _video.BlitImage({right - imgrect.width + pressed, triangle_yoff}, imgdata, rc, GS_NORMAL); } /* Note: Reusing the same string parameters from above */ if (this->value != STR_NULL) DrawString(w->TranslateStringNumber(this->value), TEXT_WHITE, left + pressed, yoffset + pressed, right - left - imgrect.width, align); -- 2.1.3