diff options
-rw-r--r-- | include/glshape.h | 1 | ||||
-rw-r--r-- | include/shape.h | 5 | ||||
-rw-r--r-- | lib/glshape.cc | 30 | ||||
-rw-r--r-- | lib/shape.cc | 31 | ||||
-rw-r--r-- | src/test.cc | 26 |
5 files changed, 80 insertions, 13 deletions
diff --git a/include/glshape.h b/include/glshape.h index e3654f5..bb0bdb3 100644 --- a/include/glshape.h +++ b/include/glshape.h @@ -11,6 +11,7 @@ namespace mogltk { class glshape : public shape { public: virtual void pixel(int x, int y, ColorP = WHITE); + virtual void fdraw(fill *, ColorP = WHITE); virtual void box(int x1, int y1, int x2, int y2, ColorP = WHITE); virtual void box3d(int x1, int y1, int x2, int y2, ColorP = DOS_WHITE, ColorP = DOS_HIGH_WHITE, ColorP = DOS_GRAY, int = 2, bool = false); virtual void box(int x1, int y1, int x2, int y2, ColorP, ColorP, ColorP, ColorP); diff --git a/include/shape.h b/include/shape.h index 07e88ed..e06115e 100644 --- a/include/shape.h +++ b/include/shape.h @@ -24,6 +24,10 @@ namespace mogltk { virtual ~fill(); void walk(fillwalker *); void insert(int, int); + int GetMinX(); + int GetMinY(); + int GetMaxX(); + int GetMaxY(); private: class sline : public Base { public: @@ -54,6 +58,7 @@ namespace mogltk { point * pheader; friend class point; }; + int minX, minY, maxX, maxY; protected: sline * header; friend class sline; 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) { diff --git a/src/test.cc b/src/test.cc index d93e50e..2d42107 100644 --- a/src/test.cc +++ b/src/test.cc @@ -20,12 +20,12 @@ virtual int startup() throw (GeneralException) { new Archive("datas.paq"); -// mogltk::glbase * gl = new mogltk::glbase(); -// mogltk::glshape * sh = new mogltk::glshape(); -// mogltk::glfont * font = new mogltk::glfont(&Input("font-2.bin")); - mogltk::base * gl = new mogltk::base(); - mogltk::shape * sh = new mogltk::shape(); - mogltk::font * font = new mogltk::font(&Input("font-2.bin")); + mogltk::glbase * gl = new mogltk::glbase(); + mogltk::glshape * sh = new mogltk::glshape(); + mogltk::glfont * font = new mogltk::glfont(&Input("font-2.bin")); +// mogltk::base * gl = new mogltk::base(); +// mogltk::shape * sh = new mogltk::shape(); +// mogltk::font * font = new mogltk::font(&Input("font-2.bin")); mogltk::Sprite * s = new mogltk::Sprite(&Input("cursor.rgba"), 25, 25); mogltk::engine::setcursorvisible(true); @@ -42,12 +42,12 @@ virtual int startup() throw (GeneralException) { sy1 = 240 + 240 * sin(0.692 * t + 8.21); sy2 = 240 + 240 * sin(1.029 * t + 2.42); -// gl->Enter2DMode(); + gl->Enter2DMode(); -// sh->tbox(mytex, 50, 50, 561, 561, BLACK, RED, LIME, BLUE); -// sh->box(400, 100, 450, 150, BLACK, RED, LIME, BLUE); + sh->tbox(mytex, 50, 50, 561, 561, BLACK, RED, LIME, BLUE); + sh->box(400, 100, 450, 150, BLACK, RED, LIME, BLUE); -// sh->box(5, 5, 150, 80, CORNFLOWERBLUE, DEEPSKYBLUE, MIDNIGHTBLUE, NAVY); + sh->box(5, 5, 150, 80, CORNFLOWERBLUE, DEEPSKYBLUE, MIDNIGHTBLUE, NAVY); font->setshadow(1); font->putcursor(10, 30); font->setcolor(WHITE); @@ -63,7 +63,9 @@ virtual int startup() throw (GeneralException) { sh->box3d(180, 130, 320, 220); sh->button(200, 150, 300, 200, "Bouton"); - sh->pcircle(320, 240, 50); +// for (int j = 0; j < 100; j++) { + sh->pcircle(320, 240, 50); +// } // sh->arc(320, 240, 50, 0, 0); sh->box(MIN(sx1, sx2), MIN(sy1, sy2), MAX(sx1, sx2), MAX(sy1, sy2), AlphaBlue); @@ -76,7 +78,7 @@ virtual int startup() throw (GeneralException) { s->draw(mogltk::engine::mouseX() - 8, mogltk::engine::mouseY() - 6); -// gl->Leave2DMode(); + gl->Leave2DMode(); gl->Flip(); |