]> git.localhorst.tv Git - space.git/blobdiff - src/graphics/primitive.cpp
simple zoom
[space.git] / src / graphics / primitive.cpp
index c97345a63ac0380f79f0879b8fbeda23a2bc4ffb..1a68d45a9a8a16acfcd5843af60fce1242f35119 100644 (file)
@@ -128,4 +128,40 @@ void Grid(
        }
 }
 
+void Grid(
+               SDL_Surface *dst,
+               Vector<int> first,
+               Vector<int> second,
+               Vector<float> size,
+               Color color) {
+       Uint32 c = color.MapRGBA(dst);
+
+       Vector<int> from = min(first, second);
+       Vector<int> to = max(first, second);
+
+       if (size.x <= 1 || size.y <= 1) {
+               FillRect(dst, from, to - from, c);
+               return;
+       }
+
+       if (from.x > dst->w || from.y > dst->h || to.x < 0 || to.y < 0) {
+               return;
+       }
+
+       while (from.x < -size.x) from.x += size.x;
+       while (from.y < -size.y) from.y += size.y;
+       while (to.x > dst->w + size.x) to.x -= size.x;
+       while (to.y > dst->h + size.y) to.y -= size.y;
+
+       float width = to.x - from.x;
+       float height = to.y - from.y;
+
+       for (Vector<float> pos(from); pos.x <= to.x; pos.x += size.x) {
+               VLine(dst, pos, height, c);
+       }
+       for (Vector<float> pos(from); pos.y <= to.y; pos.y += size.y) {
+               HLine(dst, pos, width, c);
+       }
+}
+
 }