]> git.localhorst.tv Git - l2e.git/blobdiff - src/graphics/Gauge.cpp
added type description of Gauge
[l2e.git] / src / graphics / Gauge.cpp
index 027d6b1313d541cc0afc7c44ccada3abe967b224..7407ba77c2f087f57b69a8af84f51a0f1cde4d9c 100644 (file)
@@ -7,16 +7,32 @@
 
 #include "Gauge.h"
 
-using geometry::Point;
+#include "../loader/TypeDescription.h"
+
+using geometry::Vector;
+using loader::FieldDescription;
+using loader::TypeDescription;
 
 namespace graphics {
 
-void Gauge::Draw(SDL_Surface *dest, const Point<int> &position, int width, Uint8 fill) const {
+void Gauge::Draw(SDL_Surface *dest, const Vector<int> &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 +40,28 @@ void Gauge::Draw(SDL_Surface *dest, const Point<int> &position, int width, Uint8
        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,15 +71,35 @@ void Gauge::Draw(SDL_Surface *dest, const Point<int> &position, int width, Uint8
        // 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);
        }
 
 }
 
+
+void Gauge::CreateTypeDescription() {
+       Gauge g;
+       TypeDescription &td(TypeDescription::CreateOrGet("Gauge"));
+
+       td.SetSize(sizeof(Gauge));
+
+       int imageId(TypeDescription::GetTypeId("Image"));
+       int numberId(TypeDescription::GetTypeId("Number"));
+       int vectorId(TypeDescription::GetTypeId("Vector"));
+
+       td.AddField("image", FieldDescription(((char *)&g.surface) - ((char *)&g), imageId, true));
+       td.AddField("full", FieldDescription(((char *)&g.fullOffset) - ((char *)&g), vectorId, false));
+       td.AddField("empty", FieldDescription(((char *)&g.emptyOffset) - ((char *)&g), vectorId, false));
+       td.AddField("height", FieldDescription(((char *)&g.height) - ((char *)&g), numberId, false));
+       td.AddField("start", FieldDescription(((char *)&g.startWidth) - ((char *)&g), numberId, false));
+       td.AddField("repeat", FieldDescription(((char *)&g.repeatWidth) - ((char *)&g), numberId, false));
+       td.AddField("end", FieldDescription(((char *)&g.endWidth) - ((char *)&g), numberId, false));
+}
+
 }