diff options
author | pixel <pixel> | 2003-04-04 08:04:38 +0000 |
---|---|---|
committer | pixel <pixel> | 2003-04-04 08:04:38 +0000 |
commit | 986a589d45841832e3655892f65b773193e277af (patch) | |
tree | 9d9945bcf86283f6cf392a09f634e00a6facb43e /lib | |
parent | 100da29601f0ed1923ca3d6a1db3142929321f38 (diff) |
Toying with shapes
Diffstat (limited to 'lib')
-rw-r--r-- | lib/glshape.cc | 30 | ||||
-rw-r--r-- | lib/shape.cc | 31 |
2 files changed, 60 insertions, 1 deletions
diff --git a/lib/glshape.cc b/lib/glshape.cc index 0fdaef0..5572e4d 100644 --- a/lib/glshape.cc +++ b/lib/glshape.cc @@ -154,3 +154,33 @@ void mogltk::glshape::Leave(bool was2D) { if (!was2D) mogltk::engine::glbase_o->Leave2DMode(); } + +class filldrawer : public mogltk::fillwalker { + public: + filldrawer(mogltk::shape * _s, mogltk::ColorP _c = DOS_WHITE) : s(_s), c(_c), oldx(-1), oldy(-1) { } + virtual ~filldrawer() { } + virtual void step(int x, int y) { + if (oldy != y) + oldx = -1; + if (oldx == -1) { + oldx = x; + } else { + s->hline(oldx, x, y, c); + oldx = -1; + } + oldy = y; + } + private: + mogltk::shape * s; + mogltk::ColorP c; + int oldx, oldy; +}; + +void mogltk::glshape::fdraw(fill * f, ColorP c) { + ENTER; + filldrawer * w = new filldrawer(this, c); + f->walk(w); + delete w; + LEAVE; +} +
\ No newline at end of file diff --git a/lib/shape.cc b/lib/shape.cc index 9ba4f0c..54e552b 100644 --- a/lib/shape.cc +++ b/lib/shape.cc @@ -1,4 +1,5 @@ #include <math.h> +#include <limits.h> #include <SDL.h> #include "engine.h" #include "base.h" @@ -18,7 +19,7 @@ mogltk::fillwalker::~fillwalker() { void mogltk::fillwalker::step(int x, int y) { } -mogltk::fill::fill() : header(0) { +mogltk::fill::fill() : minX(INT_MAX), minY(INT_MAX), maxX(INT_MIN), maxY(INT_MIN), header(0) { } mogltk::fill::~fill() { @@ -35,6 +36,34 @@ void mogltk::fill::insert(int x, int y) { new sline(y, this); } header->insert(x, y); + + if (x > maxX) + maxX = x; + + if (x < minX) + minX = x; + + if (y > maxY) + maxY = y; + + if (y < minY) + minY = y; +} + +int mogltk::fill::GetMaxX() { + return maxX; +} + +int mogltk::fill::GetMaxY() { + return maxY; +} + +int mogltk::fill::GetMinX() { + return minX; +} + +int mogltk::fill::GetMinY() { + return minY; } mogltk::fill::sline::sline(int _y, fill * _header) : y(_y), header(_header), pheader(0) { |