Date: | 2014-07-17 22:15:50 (9 years 8 months 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 | ||
---|---|---|
150 | 150 | blitRight(destination->raw,x,y,w,h,a); |
151 | 151 | } |
152 | 152 | |
153 | void 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 | } | |
156 | void 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 | } | |
160 | void 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 | } | |
163 | 153 | void 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 | } | |
165 | 159 | } |
166 | 160 | |
167 | void 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 | } | |
170 | void 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 | } | |
173 | 161 | void 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); | |
175 | 163 | } |
176 | 164 | |
177 | 165 | void Surface::clearClipRect() { |
src/surface.h | ||
---|---|---|
33 | 33 | RGBAColor() : r(0), g(0), b(0), a(0) {} |
34 | 34 | RGBAColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) |
35 | 35 | : r(r), g(g), b(b), a(a) {} |
36 | Uint32 pixelValue(SDL_PixelFormat *fmt) { | |
37 | return SDL_MapRGBA(fmt, r, g, b, a); | |
38 | } | |
36 | 39 | }; |
37 | 40 | |
38 | 41 | /** |
... | ... | |
75 | 78 | font->write(this, text, x, y, halign, valign); |
76 | 79 | } |
77 | 80 | |
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 | } | |
85 | 95 | |
86 | 96 | private: |
87 | 97 | Surface(SDL_Surface *raw, bool freeWhenDone); |
Branches:
install_locations
master
opkrun
packages