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;
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;
// 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);
}
class Gauge {
public:
- Gauge(SDL_Surface *s, int fullX, int fullY, int emptyX, int emptyY, int height, int startWidth, int repeatWidth, int endWidth)
- : surface(s), fullX(fullX), fullY(fullY), emptyX(emptyX), emptyY(emptyY), height(height), startWidth(startWidth), repeatWidth(repeatWidth), endWidth(endWidth) { }
+ explicit Gauge(SDL_Surface *s = 0, int fullX = 0, int fullY = 0, int emptyX = 0, int emptyY = 0, int height = 1, int startWidth = 0, int repeatWidth = 1, int endWidth = 0)
+ : surface(s), fullOffset(fullX, fullY), emptyOffset(emptyX, emptyY), height(height), startWidth(startWidth), repeatWidth(repeatWidth), endWidth(endWidth) { }
public:
int MinWidth() const { return startWidth + endWidth; }
int Height() const { return height; }
void Draw(SDL_Surface *dest, const geometry::Vector<int> &position, int width, Uint8 fill) const;
+public:
+ void SetSurface(SDL_Surface *s) { surface = s; }
+ void SetFullOffset(const geometry::Vector<int> &o) { fullOffset = o; }
+ void SetEmptyOffset(const geometry::Vector<int> &o) { emptyOffset = o; }
+ void SetHeight(int h) { height = h; }
+ void SetStartWidth(int w) { startWidth = w; }
+ void SetRepeatWidth(int w) { repeatWidth = w; }
+ void SetEndWidth(int w) { endWidth = w; }
+
private:
SDL_Surface *surface;
- int fullX;
- int fullY;
- int emptyX;
- int emptyY;
+ geometry::Vector<int> fullOffset;
+ geometry::Vector<int> emptyOffset;
int height;
int startWidth;
int repeatWidth;