1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-22 13:48:06 +02:00

Made rect+color the preferred argument style for (filled) rectangle drawing

This is the opposite of the old situation, when the structs were
unraveled.

The definitions for the alternative styles were moved to the header,
so the compiler has more opportunities for optimizing the conversions.
This commit is contained in:
Maarten ter Huurne 2014-07-17 22:15:50 +02:00
parent dd27cb2e07
commit 9df565b73c
2 changed files with 23 additions and 25 deletions

View File

@ -150,28 +150,16 @@ void Surface::blitRight(Surface *destination, int x, int y, int w, int h, int a)
blitRight(destination->raw,x,y,w,h,a);
}
void Surface::box(Sint16 x, Sint16 y, Uint16 w, Uint16 h, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
boxRGBA(raw, x, y, x + w - 1, y + h - 1, r, g, b, a);
}
void Surface::box(Sint16 x, Sint16 y, Uint16 w, Uint16 h, Uint8 r, Uint8 g, Uint8 b) {
SDL_Rect re = { x, y, w, h };
SDL_FillRect(raw, &re, SDL_MapRGBA(raw->format, r, g, b, 255));
}
void Surface::box(Sint16 x, Sint16 y, Uint16 w, Uint16 h, RGBAColor c) {
box(x, y, w, h, c.r, c.g, c.b, c.a);
}
void Surface::box(SDL_Rect re, RGBAColor c) {
if (c.a == 255) {
SDL_FillRect(raw, &re, c.pixelValue(raw->format));
} else if (c.a != 0) {
boxRGBA(raw, re.x, re.y, re.x + re.w - 1, re.y + re.h - 1, c.r, c.g, c.b, c.a);
}
}
void Surface::rectangle(Sint16 x, Sint16 y, Uint16 w, Uint16 h, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
rectangleRGBA(raw, x, y, x + w - 1, y + h - 1, r, g, b, a);
}
void Surface::rectangle(Sint16 x, Sint16 y, Uint16 w, Uint16 h, RGBAColor c) {
rectangle(x, y, w, h, c.r, c.g, c.b, c.a);
}
void Surface::rectangle(SDL_Rect re, RGBAColor c) {
rectangle(re.x, re.y, re.w, re.h, c.r, c.g, c.b, c.a);
rectangleRGBA(raw, re.x, re.y, re.x + re.w - 1, re.y + re.h - 1, c.r, c.g, c.b, c.a);
}
void Surface::clearClipRect() {

View File

@ -33,6 +33,9 @@ struct RGBAColor {
RGBAColor() : r(0), g(0), b(0), a(0) {}
RGBAColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255)
: r(r), g(g), b(b), a(a) {}
Uint32 pixelValue(SDL_PixelFormat *fmt) {
return SDL_MapRGBA(fmt, r, g, b, a);
}
};
/**
@ -75,13 +78,20 @@ public:
font->write(this, text, x, y, halign, valign);
}
void box(Sint16 x, Sint16 y, Uint16 w, Uint16 h, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
void box(Sint16 x, Sint16 y, Uint16 w, Uint16 h, Uint8 r, Uint8 g, Uint8 b);
void box(Sint16 x, Sint16 y, Uint16 w, Uint16 h, RGBAColor);
void box(SDL_Rect, RGBAColor);
void rectangle(Sint16, Sint16, Uint16, Uint16, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
void rectangle(Sint16, Sint16, Uint16, Uint16, RGBAColor);
void rectangle(SDL_Rect, RGBAColor);
void box(SDL_Rect re, RGBAColor c);
void box(Sint16 x, Sint16 y, Uint16 w, Uint16 h, RGBAColor c) {
box((SDL_Rect){ x, y, w, h }, c);
}
void box(Sint16 x, Sint16 y, Uint16 w, Uint16 h, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
box((SDL_Rect){ x, y, w, h }, RGBAColor(r, g, b, a));
}
void rectangle(SDL_Rect re, RGBAColor c);
void rectangle(Sint16 x, Sint16 y, Uint16 w, Uint16 h, RGBAColor c) {
rectangle((SDL_Rect){ x, y, w, h }, c);
}
void rectangle(Sint16 x, Sint16 y, Uint16 w, Uint16 h, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
rectangle((SDL_Rect){ x, y, w, h }, RGBAColor(r, g, b, a));
}
private:
Surface(SDL_Surface *raw, bool freeWhenDone);