Date:2014-07-17 22:15:50 (3 months 3 days ago)
Author:Maarten ter Huurne
Commit:9df565b73cf3947f37fd25fe5a4e043ed7bc53bc
Message: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.
Files: src/surface.cpp (1 diff)
src/surface.h (2 diffs)

Change Details

src/surface.cpp
150150    blitRight(destination->raw,x,y,w,h,a);
151151}
152152
153void Surface::box(Sint16 x, Sint16 y, Uint16 w, Uint16 h, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
154    boxRGBA(raw, x, y, x + w - 1, y + h - 1, r, g, b, a);
155}
156void Surface::box(Sint16 x, Sint16 y, Uint16 w, Uint16 h, Uint8 r, Uint8 g, Uint8 b) {
157    SDL_Rect re = { x, y, w, h };
158    SDL_FillRect(raw, &re, SDL_MapRGBA(raw->format, r, g, b, 255));
159}
160void Surface::box(Sint16 x, Sint16 y, Uint16 w, Uint16 h, RGBAColor c) {
161    box(x, y, w, h, c.r, c.g, c.b, c.a);
162}
163153void Surface::box(SDL_Rect re, RGBAColor c) {
164    boxRGBA(raw, re.x, re.y, re.x + re.w - 1, re.y + re.h - 1, c.r, c.g, c.b, c.a);
154    if (c.a == 255) {
155        SDL_FillRect(raw, &re, c.pixelValue(raw->format));
156    } else if (c.a != 0) {
157        boxRGBA(raw, re.x, re.y, re.x + re.w - 1, re.y + re.h - 1, c.r, c.g, c.b, c.a);
158    }
165159}
166160
167void Surface::rectangle(Sint16 x, Sint16 y, Uint16 w, Uint16 h, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
168    rectangleRGBA(raw, x, y, x + w - 1, y + h - 1, r, g, b, a);
169}
170void Surface::rectangle(Sint16 x, Sint16 y, Uint16 w, Uint16 h, RGBAColor c) {
171    rectangle(x, y, w, h, c.r, c.g, c.b, c.a);
172}
173161void Surface::rectangle(SDL_Rect re, RGBAColor c) {
174    rectangle(re.x, re.y, re.w, re.h, c.r, c.g, c.b, c.a);
162    rectangleRGBA(raw, re.x, re.y, re.x + re.w - 1, re.y + re.h - 1, c.r, c.g, c.b, c.a);
175163}
176164
177165void Surface::clearClipRect() {
src/surface.h
3333    RGBAColor() : r(0), g(0), b(0), a(0) {}
3434    RGBAColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255)
3535        : r(r), g(g), b(b), a(a) {}
36    Uint32 pixelValue(SDL_PixelFormat *fmt) {
37        return SDL_MapRGBA(fmt, r, g, b, a);
38    }
3639};
3740
3841/**
...... 
7578        font->write(this, text, x, y, halign, valign);
7679    }
7780
78    void box(Sint16 x, Sint16 y, Uint16 w, Uint16 h, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
79    void box(Sint16 x, Sint16 y, Uint16 w, Uint16 h, Uint8 r, Uint8 g, Uint8 b);
80    void box(Sint16 x, Sint16 y, Uint16 w, Uint16 h, RGBAColor);
81    void box(SDL_Rect, RGBAColor);
82    void rectangle(Sint16, Sint16, Uint16, Uint16, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
83    void rectangle(Sint16, Sint16, Uint16, Uint16, RGBAColor);
84    void rectangle(SDL_Rect, RGBAColor);
81    void box(SDL_Rect re, RGBAColor c);
82    void box(Sint16 x, Sint16 y, Uint16 w, Uint16 h, RGBAColor c) {
83        box((SDL_Rect){ x, y, w, h }, c);
84    }
85    void box(Sint16 x, Sint16 y, Uint16 w, Uint16 h, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
86        box((SDL_Rect){ x, y, w, h }, RGBAColor(r, g, b, a));
87    }
88    void rectangle(SDL_Rect re, RGBAColor c);
89    void rectangle(Sint16 x, Sint16 y, Uint16 w, Uint16 h, RGBAColor c) {
90        rectangle((SDL_Rect){ x, y, w, h }, c);
91    }
92    void rectangle(Sint16 x, Sint16 y, Uint16 w, Uint16 h, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
93        rectangle((SDL_Rect){ x, y, w, h }, RGBAColor(r, g, b, a));
94    }
8595
8696private:
8797    Surface(SDL_Surface *raw, bool freeWhenDone);

Archive Download the corresponding diff file



interactive