1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-29 18:40:36 +02:00

Declare Surface methods that don't change the surface as "const"

This allows source surfaces (such as icons) to be passed around as
const references.
This commit is contained in:
Maarten ter Huurne 2013-08-09 17:47:34 +02:00
parent 46626030b2
commit b0d1d9e55f
2 changed files with 16 additions and 16 deletions

View File

@ -112,7 +112,7 @@ void Surface::flip() {
SDL_Flip(raw); SDL_Flip(raw);
} }
bool Surface::blit(SDL_Surface *destination, int x, int y, int w, int h, int a) { bool Surface::blit(SDL_Surface *destination, int x, int y, int w, int h, int a) const {
if (destination == NULL || a==0) return false; if (destination == NULL || a==0) return false;
SDL_Rect src = { 0, 0, static_cast<Uint16>(w), static_cast<Uint16>(h) }; SDL_Rect src = { 0, 0, static_cast<Uint16>(w), static_cast<Uint16>(h) };
@ -123,25 +123,25 @@ bool Surface::blit(SDL_Surface *destination, int x, int y, int w, int h, int a)
SDL_SetAlpha(raw, SDL_SRCALPHA|SDL_RLEACCEL, a); SDL_SetAlpha(raw, SDL_SRCALPHA|SDL_RLEACCEL, a);
return SDL_BlitSurface(raw, (w==0 || h==0) ? NULL : &src, destination, &dest); return SDL_BlitSurface(raw, (w==0 || h==0) ? NULL : &src, destination, &dest);
} }
bool Surface::blit(Surface *destination, int x, int y, int w, int h, int a) { bool Surface::blit(Surface *destination, int x, int y, int w, int h, int a) const {
return blit(destination->raw,x,y,w,h,a); return blit(destination->raw,x,y,w,h,a);
} }
bool Surface::blitCenter(SDL_Surface *destination, int x, int y, int w, int h, int a) { bool Surface::blitCenter(SDL_Surface *destination, int x, int y, int w, int h, int a) const {
int oh, ow; int oh, ow;
if (w==0) ow = halfW; else ow = min(halfW,w/2); if (w==0) ow = halfW; else ow = min(halfW,w/2);
if (h==0) oh = halfH; else oh = min(halfH,h/2); if (h==0) oh = halfH; else oh = min(halfH,h/2);
return blit(destination,x-ow,y-oh,w,h,a); return blit(destination,x-ow,y-oh,w,h,a);
} }
bool Surface::blitCenter(Surface *destination, int x, int y, int w, int h, int a) { bool Surface::blitCenter(Surface *destination, int x, int y, int w, int h, int a) const {
return blitCenter(destination->raw,x,y,w,h,a); return blitCenter(destination->raw,x,y,w,h,a);
} }
bool Surface::blitRight(SDL_Surface *destination, int x, int y, int w, int h, int a) { bool Surface::blitRight(SDL_Surface *destination, int x, int y, int w, int h, int a) const {
if (!w) w = raw->w; if (!w) w = raw->w;
return blit(destination,x-min(raw->w,w),y,w,h,a); return blit(destination,x-min(raw->w,w),y,w,h,a);
} }
bool Surface::blitRight(Surface *destination, int x, int y, int w, int h, int a) { bool Surface::blitRight(Surface *destination, int x, int y, int w, int h, int a) const {
if (!w) w = raw->w; if (!w) w = raw->w;
return blitRight(destination->raw,x,y,w,h,a); return blitRight(destination->raw,x,y,w,h,a);
} }
@ -192,7 +192,7 @@ void Surface::setClipRect(SDL_Rect rect) {
SDL_SetClipRect(raw,&rect); SDL_SetClipRect(raw,&rect);
} }
bool Surface::blit(Surface *destination, SDL_Rect container, Font::HAlign halign, Font::VAlign valign) { bool Surface::blit(Surface *destination, SDL_Rect container, Font::HAlign halign, Font::VAlign valign) const {
switch (halign) { switch (halign) {
case Font::HAlignLeft: case Font::HAlignLeft:
break; break;

View File

@ -52,8 +52,8 @@ public:
*/ */
void convertToDisplayFormat(); void convertToDisplayFormat();
int width() { return raw->w; } int width() const { return raw->w; }
int height() { return raw->h; } int height() const { return raw->h; }
void flip(); void flip();
@ -61,10 +61,10 @@ public:
void setClipRect(int x, int y, int w, int h); void setClipRect(int x, int y, int w, int h);
void setClipRect(SDL_Rect rect); void setClipRect(SDL_Rect rect);
bool blit(Surface *destination, int x, int y, int w=0, int h=0, int a=-1); bool blit(Surface *destination, int x, int y, int w=0, int h=0, int a=-1) const;
bool blit(Surface *destination, SDL_Rect container, Font::HAlign halign = Font::HAlignLeft, Font::VAlign valign = Font::VAlignTop); bool blit(Surface *destination, SDL_Rect container, Font::HAlign halign = Font::HAlignLeft, Font::VAlign valign = Font::VAlignTop) const;
bool blitCenter(Surface *destination, int x, int y, int w=0, int h=0, int a=-1); bool blitCenter(Surface *destination, int x, int y, int w=0, int h=0, int a=-1) const;
bool blitRight(Surface *destination, int x, int y, int w=0, int h=0, int a=-1); bool blitRight(Surface *destination, int x, int y, int w=0, int h=0, int a=-1) const;
void write(Font *font, const std::string &text, int x, int y, void write(Font *font, const std::string &text, int x, int y,
Font::HAlign halign = Font::HAlignLeft, Font::HAlign halign = Font::HAlignLeft,
@ -83,9 +83,9 @@ public:
private: private:
Surface(SDL_Surface *raw, bool freeWhenDone); Surface(SDL_Surface *raw, bool freeWhenDone);
bool blit(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1); bool blit(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1) const;
bool blitCenter(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1); bool blitCenter(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1) const;
bool blitRight(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1); bool blitRight(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1) const;
SDL_Surface *raw; SDL_Surface *raw;
bool freeWhenDone; bool freeWhenDone;