From 75e6c179124e407805e7271773e09daf6c8a830c Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Sun, 28 Sep 2014 22:07:15 +0100 Subject: [PATCH 1/6] -Codechange: Change the FillSurface VideoSystem function to be more consistent with DrawRectangle --- src/dropdown.cpp | 2 +- src/gui_graphics.cpp | 4 ++-- src/video.cpp | 54 ++++++++++++++++++++++++++-------------------------- src/video.h | 2 +- src/viewport.cpp | 4 ++-- src/window.cpp | 2 +- 6 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/dropdown.cpp b/src/dropdown.cpp index 8298f2d..1cd99fe 100644 --- a/src/dropdown.cpp +++ b/src/dropdown.cpp @@ -108,7 +108,7 @@ void DropdownMenuWindow::DrawWidget(WidgetNumber wid_num, const BaseWidget *wid) for (auto const &item : this->items) { if (it == this->selected_index) { Rectangle32 r = {this->rect.base.x, y, static_cast(wid->pos.width - 1), static_cast(GetTextHeight())}; - _video.FillSurface(_palette[GetColourRangeBase(COL_RANGE_GREY) + 7], r); + _video.FillRectangle(r, _palette[GetColourRangeBase(COL_RANGE_GREY) + 7]); } _video.BlitText(item.str, MakeRGBA(255, 255, 255, OPAQUE), this->rect.base.x, y, wid->pos.width); diff --git a/src/gui_graphics.cpp b/src/gui_graphics.cpp index 9cd5a4f..86b29f1 100644 --- a/src/gui_graphics.cpp +++ b/src/gui_graphics.cpp @@ -18,7 +18,7 @@ /** * Draw the same sprite repeatedly over a (potentially) large area. The function recognizes a single-pixel - * sprite as a special case, and converts it to a VideoSystem::FillSurface call. + * sprite as a special case, and converts it to a VideoSystem::FillRectangle call. * @param x_base Left edge coordinate to start drawing. * @param y_base Top edge coordinate to start drawing. * @param spr Sprite to draw. @@ -34,7 +34,7 @@ static void DrawRepeatedSprites(int32 x_base, int32 y_base, const ImageData *spr return; } uint32 colour = spr->GetPixel(0, 0, &recolour); - _video.FillSurface(colour, {x_base, y_base, numx, numy}); + _video.FillRectangle({x_base, y_base, numx, numy}, colour); } /** diff --git a/src/video.cpp b/src/video.cpp index 300caa6..7943266 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -479,33 +479,6 @@ void VideoSystem::FinishRepaint() } /** - * Fill the rectangle with a single colour. - * @param colour Colour to fill with. - * @param rect %Rectangle to fill. - */ -void VideoSystem::FillSurface(uint32 colour, const Rectangle32 &rect) -{ - ClippedRectangle cr = this->GetClippedRectangle(); - - int x = Clamp((int)rect.base.x, 0, (int)cr.width); - int w = Clamp((int)(rect.base.x + rect.width), 0, (int)cr.width); - int y = Clamp((int)rect.base.y, 0, (int)cr.height); - int h = Clamp((int)(rect.base.y + rect.height), 0, (int)cr.height); - - w -= x; - h -= y; - if (w == 0 || h == 0) return; - - uint32 *pixels_base = cr.address + x + y * cr.pitch; - while (h > 0) { - uint32 *pixels = pixels_base; - for (int i = 0; i < w; i++) *pixels++ = colour; - pixels_base += cr.pitch; - h--; - } -} - -/** * Blit pixels from the \a spr relative to #blit_rect into the area. * @param img_base Coordinate of the sprite data. * @param spr The sprite to blit. @@ -938,3 +911,30 @@ void VideoSystem::DrawRectangle(const Rectangle32 &rect, uint32 colour) this->DrawLine(top_right, bottom_right, colour); this->DrawLine(bottom_left, bottom_right, colour); } + +/** + * Fill the rectangle with a single colour. + * @param rect %Rectangle to fill. + * @param colour Colour to fill with. + */ +void VideoSystem::FillRectangle(const Rectangle32 &rect, uint32 colour) +{ + ClippedRectangle cr = this->GetClippedRectangle(); + + int x = Clamp((int)rect.base.x, 0, (int)cr.width); + int w = Clamp((int)(rect.base.x + rect.width), 0, (int)cr.width); + int y = Clamp((int)rect.base.y, 0, (int)cr.height); + int h = Clamp((int)(rect.base.y + rect.height), 0, (int)cr.height); + + w -= x; + h -= y; + if (w == 0 || h == 0) return; + + uint32 *pixels_base = cr.address + x + y * cr.pitch; + while (h > 0) { + uint32 *pixels = pixels_base; + for (int i = 0; i < w; i++) *pixels++ = colour; + pixels_base += cr.pitch; + h--; + } +} diff --git a/src/video.h b/src/video.h index 6f435a9..06d8fcd 100644 --- a/src/video.h +++ b/src/video.h @@ -101,7 +101,6 @@ public: void SetClippedRectangle(const ClippedRectangle &cr); ClippedRectangle GetClippedRectangle(); - void FillSurface(uint32 colour, const Rectangle32 &rect); 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); @@ -149,6 +148,7 @@ public: void BlitText(const uint8 *text, uint32 colour, int xpos, int ypos, int width = 0x7FFF, Alignment align = ALG_LEFT); void DrawLine(const Point16 &start, const Point16 &end, uint32 colour); void DrawRectangle(const Rectangle32 &rect, uint32 colour); + void FillRectangle(const Rectangle32 &rect, uint32 colour); bool missing_sprites; ///< Indicates that some sprites cannot be drawn. std::set resolutions; ///< Set (for automatic sorting) of available resolutions. diff --git a/src/viewport.cpp b/src/viewport.cpp index eae8aa3..418b901 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -1022,7 +1022,7 @@ void SpriteCollector::CollectVoxel(const Voxel *voxel, int xpos, int ypos, int z gslope = voxel->GetGroundSlope(); } - + /* Fences */ for (TileEdge edge = EDGE_BEGIN; edge < EDGE_COUNT; edge++) { FenceType fence_type = voxel->GetFenceType(edge); @@ -1404,7 +1404,7 @@ void Viewport::OnDraw() collector.Collect(this->additions_enabled && this->additions_displayed); static const Recolouring recolour; - _video.FillSurface(MakeRGBA(0, 0, 0, OPAQUE), this->rect); // Black background. + _video.FillRectangle(this->rect, MakeRGBA(0, 0, 0, OPAQUE)); // Black background. ClippedRectangle cr = _video.GetClippedRectangle(); assert(this->rect.base.x >= 0 && this->rect.base.y >= 0); diff --git a/src/window.cpp b/src/window.cpp index 5fc0127..641e9a4 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -990,7 +990,7 @@ void UpdateWindows() * windows truly disappear (even if there is no other window behind it). */ Rectangle32 rect(0, 0, _video.GetXSize(), _video.GetYSize()); - _video.FillSurface(MakeRGBA(0, 0, 0, OPAQUE), rect); + _video.FillRectangle(rect, MakeRGBA(0, 0, 0, OPAQUE)); Window *w = _manager.bottom; while (w != nullptr) { -- 2.1.3