1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-16 17:17:32 +02:00

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.
This commit is contained in:
Maarten ter Huurne 2014-07-19 00:30:22 +02:00
parent 0dd027fcf4
commit 08ffbc76de

View File

@ -25,8 +25,6 @@
#include "surfacecollection.h" #include "surfacecollection.h"
#include "utilities.h" #include "utilities.h"
#include <SDL_gfxPrimitives.h>
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
#include <iostream> #include <iostream>
@ -161,7 +159,27 @@ void Surface::box(SDL_Rect re, RGBAColor c) {
} }
void Surface::rectangle(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() { void Surface::clearClipRect() {