From 08ffbc76deed48fef6cf42bb27bf5e913667cd89 Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Sat, 19 Jul 2014 00:30:22 +0200 Subject: [PATCH] Use our own alpha blended rectangle outline instead of SDL_gfx I implemented it as four 1-pixel-wide filled rectangles. While this is not the fastest way to do it, I doubt this will have a significant impact on overall performance. Note that the proper way to clip a rectangle outline is to clip the outline's four lines individually, not clip the rectangle and then draw a smaller rectangle outline. This means that an optimized drawing routine would have to be aware of whether clipping occurs, complicating the code. --- src/surface.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/surface.cpp b/src/surface.cpp index 8ecb197..48bb976 100644 --- a/src/surface.cpp +++ b/src/surface.cpp @@ -25,8 +25,6 @@ #include "surfacecollection.h" #include "utilities.h" -#include - #include #include #include @@ -161,7 +159,27 @@ void Surface::box(SDL_Rect re, RGBAColor c) { } void Surface::rectangle(SDL_Rect re, RGBAColor c) { - rectangleRGBA(raw, re.x, re.y, re.x + re.w - 1, re.y + re.h - 1, c.r, c.g, c.b, c.a); + if (re.h >= 1) { + // Top. + box(SDL_Rect { re.x, re.y, re.w, 1 }, c); + } + if (re.h >= 2) { + Sint16 ey = re.y + re.h - 1; + // Bottom. + box(SDL_Rect { re.x, ey, re.w, 1 }, c); + + Sint16 ex = re.x + re.w - 1; + Sint16 sy = re.y + 1; + Uint16 sh = re.h - 2; + // Left. + if (re.w >= 1) { + box(SDL_Rect { re.x, sy, 1, sh }, c); + } + // Right. + if (re.w >= 2) { + box(SDL_Rect { ex, sy, 1, sh }, c); + } + } } void Surface::clearClipRect() {