X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fgraphics%2FGauge.cpp;h=0d72ac0676eb11233a5d67df37e795f596e1d70a;hb=679b9e39c7680fd46482589f37f0a225032103b7;hp=09405a2069ca15da6b560df6a9328d95e0ceec71;hpb=2d10e898ccd404a69be02f5e93cf97398de99984;p=l2e.git diff --git a/src/graphics/Gauge.cpp b/src/graphics/Gauge.cpp index 09405a2..0d72ac0 100644 --- a/src/graphics/Gauge.cpp +++ b/src/graphics/Gauge.cpp @@ -7,16 +7,28 @@ #include "Gauge.h" -using geometry::Point; +using geometry::Vector; namespace graphics { -void Gauge::Draw(SDL_Surface *dest, Point position, int width, Uint8 fill) const { +void Gauge::Draw(SDL_Surface *dest, const Vector &position, int width, Uint8 fill) const { SDL_Rect srcRect, destRect; int filledWidth = fill * (width - startWidth - endWidth) / 255; int emptyWidth = (255 - fill) * (width - startWidth - endWidth) / 255; + if (!surface) { + destRect.x = position.X(); + destRect.y = position.Y(); + destRect.w = filledWidth + startWidth; + destRect.h = height; + SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0x00, 0xFF, 0x00)); + destRect.x += destRect.w; + destRect.w = emptyWidth + endWidth; + SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00)); + return; + } + // start srcRect.w = startWidth; srcRect.h = height; @@ -24,28 +36,28 @@ void Gauge::Draw(SDL_Surface *dest, Point position, int width, Uint8 fill) destRect.y = position.Y(); // full part if (fill == 0) { - srcRect.x = emptyX; - srcRect.y = emptyY; + srcRect.x = emptyOffset.X(); + srcRect.y = emptyOffset.Y(); SDL_BlitSurface(surface, &srcRect, dest, &destRect); } else { - srcRect.x = fullX; - srcRect.y = fullY; + srcRect.x = fullOffset.X(); + srcRect.y = fullOffset.Y(); SDL_BlitSurface(surface, &srcRect, dest, &destRect); } destRect.x = position.X() + startWidth; // fill - srcRect.x = fullX + startWidth; - srcRect.y = fullY; + srcRect.x = fullOffset.X() + startWidth; + srcRect.y = fullOffset.Y(); srcRect.w = repeatWidth; while (filledWidth > repeatWidth) { SDL_BlitSurface(surface, &srcRect, dest, &destRect); destRect.x += repeatWidth; filledWidth -= repeatWidth; } - srcRect.x = emptyX + startWidth; - srcRect.y = emptyY; + srcRect.x = emptyOffset.X() + startWidth; + srcRect.y = emptyOffset.Y(); while (emptyWidth > repeatWidth) { SDL_BlitSurface(surface, &srcRect, dest, &destRect); destRect.x += repeatWidth; @@ -55,12 +67,12 @@ void Gauge::Draw(SDL_Surface *dest, Point position, int width, Uint8 fill) // end srcRect.w = endWidth; if (fill == 255) { - srcRect.x = fullX + startWidth + repeatWidth; - srcRect.y = fullY; + srcRect.x = fullOffset.X() + startWidth + repeatWidth; + srcRect.y = fullOffset.Y(); SDL_BlitSurface(surface, &srcRect, dest, &destRect); } else { - srcRect.x = emptyX + startWidth + repeatWidth; - srcRect.y = emptyY; + srcRect.x = emptyOffset.X() + startWidth + repeatWidth; + srcRect.y = emptyOffset.Y(); SDL_BlitSurface(surface, &srcRect, dest, &destRect); }