X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fgraphics%2FGauge.cpp;h=027d6b1313d541cc0afc7c44ccada3abe967b224;hb=1162be37102b24df11f469495c0184f3f9a26ba0;hp=042dc2704b4705e7c152926582ce85924f3ce0ee;hpb=2e0bbc9fcc1cce3e1faeff85cc63de7f676e8077;p=l2e.git diff --git a/src/graphics/Gauge.cpp b/src/graphics/Gauge.cpp index 042dc27..027d6b1 100644 --- a/src/graphics/Gauge.cpp +++ b/src/graphics/Gauge.cpp @@ -11,110 +11,56 @@ using geometry::Point; namespace graphics { -// TODO: add start and end "ignore" offsets -void Gauge::Draw(SDL_Surface *dest, Point position, int width, Uint8 level) const { - int fullWidth(width * level / 255); +void Gauge::Draw(SDL_Surface *dest, const Point &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; + // start + srcRect.w = startWidth; srcRect.h = height; destRect.x = position.X(); destRect.y = position.Y(); // full part - if (fullWidth >= startWidth) { // completely filled - srcRect.x = fullX; - srcRect.y = fullY; - srcRect.w = startWidth; - SDL_BlitSurface(surface, &srcRect, dest, &destRect); - } else if (fullWidth > 0) { // partially filled - srcRect.x = fullX; - srcRect.y = fullY; - srcRect.w = fullWidth; - SDL_BlitSurface(surface, &srcRect, dest, &destRect); - } - // empty part - if (fullWidth == 0) { // completely empty + if (fill == 0) { srcRect.x = emptyX; srcRect.y = emptyY; - srcRect.w = startWidth; SDL_BlitSurface(surface, &srcRect, dest, &destRect); - } else if (fullWidth < startWidth) { // partially empty - srcRect.x = emptyX + fullWidth; - srcRect.y = emptyY; - srcRect.w = startWidth - fullWidth; - destRect.x = position.X() + fullWidth; + } else { + srcRect.x = fullX; + srcRect.y = fullY; SDL_BlitSurface(surface, &srcRect, dest, &destRect); } destRect.x = position.X() + startWidth; // fill - if (fullWidth >= width - endWidth) { // completely filled - srcRect.x = fullX + startWidth; - srcRect.y = fullY; - srcRect.w = repeatWidth; - int fillWidth(width - startWidth - endWidth); - int fillCursor(0); - while (fillCursor < fillWidth) { - SDL_BlitSurface(surface, &srcRect, dest, &destRect); - destRect.x += repeatWidth; - fillCursor += repeatWidth; - } - } else if (fullWidth <= startWidth) { // completely empty - srcRect.x = emptyX + startWidth; - srcRect.y = emptyY; - srcRect.w = repeatWidth; - int fillWidth(width - startWidth - endWidth); - int fillCursor(0); - while (fillCursor < fillWidth) { - SDL_BlitSurface(surface, &srcRect, dest, &destRect); - destRect.x += repeatWidth; - fillCursor += repeatWidth; - } - } else { // partially filled/empty - srcRect.x = fullX + startWidth; - srcRect.y = fullY; - srcRect.w = repeatWidth; - int fillCursor(0); - while (fillCursor < fullWidth) { - SDL_BlitSurface(surface, &srcRect, dest, &destRect); - destRect.x += repeatWidth; - fillCursor += repeatWidth; - } - srcRect.x = emptyX + startWidth; - srcRect.y = emptyY; - int remaining(width - startWidth - endWidth); - while (fillCursor < remaining) { - SDL_BlitSurface(surface, &srcRect, dest, &destRect); - destRect.x += repeatWidth; - fillCursor += repeatWidth; - } + srcRect.x = fullX + startWidth; + srcRect.y = fullY; + srcRect.w = repeatWidth; + while (filledWidth > repeatWidth) { + SDL_BlitSurface(surface, &srcRect, dest, &destRect); + destRect.x += repeatWidth; + filledWidth -= repeatWidth; + } + srcRect.x = emptyX + startWidth; + srcRect.y = emptyY; + while (emptyWidth > repeatWidth) { + SDL_BlitSurface(surface, &srcRect, dest, &destRect); + destRect.x += repeatWidth; + emptyWidth -= repeatWidth; } // end - // full part - if (fullWidth >= width) { // completely filled + srcRect.w = endWidth; + if (fill == 255) { srcRect.x = fullX + startWidth + repeatWidth; srcRect.y = fullY; - srcRect.w = endWidth; SDL_BlitSurface(surface, &srcRect, dest, &destRect); - } else if (fullWidth > (width - endWidth)) { // partially filled - srcRect.x = fullX + startWidth + repeatWidth; - srcRect.y = fullY; - srcRect.w = endWidth - width + fullWidth; - SDL_BlitSurface(surface, &srcRect, dest, &destRect); - } - // empty part - if (fullWidth <= width - endWidth) { // completely empty + } else { srcRect.x = emptyX + startWidth + repeatWidth; srcRect.y = emptyY; - srcRect.w = startWidth; - SDL_BlitSurface(surface, &srcRect, dest, &destRect); - } else if (fullWidth > (width - endWidth) && fullWidth < width) { // partially empty - srcRect.x = emptyX + startWidth + repeatWidth + fullWidth - width + endWidth; - srcRect.y = emptyY; - srcRect.w = width - fullWidth; - destRect.x = position.X() + fullWidth; SDL_BlitSurface(surface, &srcRect, dest, &destRect); }