mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-25 15:56:15 +02:00
Removed halfW/H caching in Surface
This is a very cheap computation, no need to cache it.
This commit is contained in:
parent
7c4fa5d77a
commit
614f74a63d
@ -92,8 +92,6 @@ Surface::Surface(SDL_Surface *raw_, bool freeWhenDone_)
|
|||||||
: raw(raw_)
|
: raw(raw_)
|
||||||
, freeWhenDone(freeWhenDone_)
|
, freeWhenDone(freeWhenDone_)
|
||||||
{
|
{
|
||||||
halfW = raw->w/2;
|
|
||||||
halfH = raw->h/2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Surface::Surface(Surface *s) {
|
Surface::Surface(Surface *s) {
|
||||||
@ -104,8 +102,6 @@ Surface::Surface(Surface *s) {
|
|||||||
// an alpha channel, such as the display format.
|
// an alpha channel, such as the display format.
|
||||||
raw->format->alpha = s->raw->format->alpha;
|
raw->format->alpha = s->raw->format->alpha;
|
||||||
freeWhenDone = true;
|
freeWhenDone = true;
|
||||||
halfW = raw->w/2;
|
|
||||||
halfH = raw->h/2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Surface::~Surface() {
|
Surface::~Surface() {
|
||||||
@ -145,10 +141,9 @@ void Surface::blit(Surface *destination, int x, int y, int w, int h, int a) cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Surface::blitCenter(SDL_Surface *destination, int x, int y, int w, int h, int a) const {
|
void Surface::blitCenter(SDL_Surface *destination, int x, int y, int w, int h, int a) const {
|
||||||
int oh, ow;
|
int ow = raw->w / 2; if (w != 0) ow = min(ow, w / 2);
|
||||||
if (w==0) ow = halfW; else ow = min(halfW,w/2);
|
int oh = raw->h / 2; if (h != 0) oh = min(oh, h / 2);
|
||||||
if (h==0) oh = halfH; else oh = min(halfH,h/2);
|
blit(destination, x - ow, y - oh, w, h, a);
|
||||||
blit(destination,x-ow,y-oh,w,h,a);
|
|
||||||
}
|
}
|
||||||
void Surface::blitCenter(Surface *destination, int x, int y, int w, int h, int a) const {
|
void Surface::blitCenter(Surface *destination, int x, int y, int w, int h, int a) const {
|
||||||
blitCenter(destination->raw,x,y,w,h,a);
|
blitCenter(destination->raw,x,y,w,h,a);
|
||||||
@ -239,7 +234,7 @@ void Surface::blit(Surface *destination, SDL_Rect container, Font::HAlign halign
|
|||||||
case Font::HAlignLeft:
|
case Font::HAlignLeft:
|
||||||
break;
|
break;
|
||||||
case Font::HAlignCenter:
|
case Font::HAlignCenter:
|
||||||
container.x += container.w/2-halfW;
|
container.x += container.w / 2 - raw->w / 2;
|
||||||
break;
|
break;
|
||||||
case Font::HAlignRight:
|
case Font::HAlignRight:
|
||||||
container.x += container.w-raw->w;
|
container.x += container.w-raw->w;
|
||||||
@ -250,7 +245,7 @@ void Surface::blit(Surface *destination, SDL_Rect container, Font::HAlign halign
|
|||||||
case Font::VAlignTop:
|
case Font::VAlignTop:
|
||||||
break;
|
break;
|
||||||
case Font::VAlignMiddle:
|
case Font::VAlignMiddle:
|
||||||
container.y += container.h/2-halfH;
|
container.y += container.h / 2 - raw->h / 2;
|
||||||
break;
|
break;
|
||||||
case Font::VAlignBottom:
|
case Font::VAlignBottom:
|
||||||
container.y += container.h-raw->h;
|
container.y += container.h-raw->h;
|
||||||
|
@ -108,7 +108,6 @@ private:
|
|||||||
|
|
||||||
SDL_Surface *raw;
|
SDL_Surface *raw;
|
||||||
bool freeWhenDone;
|
bool freeWhenDone;
|
||||||
int halfW, halfH;
|
|
||||||
|
|
||||||
// For direct access to "raw".
|
// For direct access to "raw".
|
||||||
friend class Font;
|
friend class Font;
|
||||||
|
Loading…
Reference in New Issue
Block a user