diff options
-rw-r--r-- | include/shape.h | 8 | ||||
-rw-r--r-- | lib/font.cc | 2 | ||||
-rw-r--r-- | lib/shape.cc | 166 | ||||
-rw-r--r-- | src/test.cc | 2 |
4 files changed, 171 insertions, 7 deletions
diff --git a/include/shape.h b/include/shape.h index 8152f5a..b2e218d 100644 --- a/include/shape.h +++ b/include/shape.h @@ -23,7 +23,7 @@ namespace mogltk { fill(); virtual ~fill(); void walk(fillwalker *); - void insert(int, int); + void insert(int, int, int, int); int GetMinX() const; int GetMinY() const; int GetMaxX() const; @@ -32,6 +32,7 @@ namespace mogltk { texture * Talloc(); Color last; private: + void insert(int, int); class sline : public Base { public: sline(int, fill *); @@ -88,6 +89,7 @@ namespace mogltk { virtual void vline(int x, int y1, int y2, ColorP = DOS_WHITE); virtual void vline3d(int x, int y1, int y2, ColorP = DOS_HIGH_WHITE, ColorP = DOS_GRAY, bool = false); virtual void vline(int x, int y1, int y2, ColorP, ColorP); + virtual void line(int x1, int y1, int x2, int y2, ColorP = WHITE); virtual void tbox(texture *, int x1, int y1, int x2, int y2, int tx = 0, int ty = 0, double = 1.0, ColorP = WHITE); virtual void tbox(texture *, int x1, int y1, int x2, int y2, int tx1, int ty1, int tx2, int ty2, ColorP = WHITE); virtual void tbox(texture *, int x1, int y1, int x2, int y2, ColorP, ColorP, ColorP, ColorP, int tx = 0, int ty = 0, double = 1.0); @@ -118,6 +120,10 @@ namespace mogltk { ColorP tshade1 = DOS_HIGH_WHITE, ColorP tshade2 = DOS_GRAY); private: + void bsubline_1(int x1, int y1, int x2, int y2, ColorP = WHITE); + void bsubline_2(int x1, int y1, int x2, int y2, ColorP = WHITE); + void bsubline_3(int x1, int y1, int x2, int y2, ColorP = WHITE); + void bsubline_4(int x1, int y1, int x2, int y2, ColorP = WHITE); virtual bool Enter(); virtual void Leave(bool); }; diff --git a/lib/font.cc b/lib/font.cc index 72d7de9..efdd9bd 100644 --- a/lib/font.cc +++ b/lib/font.cc @@ -142,7 +142,6 @@ mogltk::font::font(Handle * ffont) : textcolor(255, 255, 255, 255), shadow(0), w Uint8 * curtex = (Uint8 *) fonttex[0]->GetSurface()->pixels; Uint32 curU = 0, curV = 0, curT = 0; for (i = 0; i < nbentries; i++) { - printm(M_INFO, "Reading entry %i at offset 0x%x\n", i, ffont->tell()); sizes[i] = ffont->readU8(); for (int v = 0; v < maxY; v++) { for (int u = 0; u < maxX; u++) { @@ -179,7 +178,6 @@ mogltk::font::font(Handle * ffont) : textcolor(255, 255, 255, 255), shadow(0), w corresp = (Uint16 *) malloc(nbentries * 2 * sizeof(Uint16)); for (i = 0; i < 2 * nbentries; i++) { - printm(M_INFO, "Reading translation entry number %i at offset 0x%x\n", i, ffont->tell()); corresp[i] = ffont->readU16(); } } diff --git a/lib/shape.cc b/lib/shape.cc index 5120a3c..84e89fd 100644 --- a/lib/shape.cc +++ b/lib/shape.cc @@ -1,6 +1,8 @@ #include <math.h> #include <limits.h> #include <SDL.h> +#include <sys/types.h> +#include <generic.h> #include "engine.h" #include "base.h" #include "shape.h" @@ -35,6 +37,7 @@ void mogltk::fill::walk(fillwalker * w) { } void mogltk::fill::insert(int x, int y) { + printm(M_INFO, "Inserting %i %i\n", x, y); if (cached) { delete cached; cached = 0; @@ -58,6 +61,30 @@ void mogltk::fill::insert(int x, int y) { minY = y; } +void mogltk::fill::insert(int x1, int y1, int x2, int y2) { + int dx, dy, y; + double x, i, i2; + + printm(M_INFO, "Adding line (%i, %i)-(%i, %i)\n", x1, y1, x2, y2); + + if (y1 == y2) + return; + + if (y2 < y1) { + SWAP(x1, x2); + SWAP(y1, y2); + } + + dx = x1 - x2; + dy = y1 - y2; + + x = x1; + i = ((double) dx) / ((double) dy); + i2 = i / 2; + for (y = y1; y < y2; y++, x += i) + insert(x + i2, y); +} + int mogltk::fill::GetMaxX() const { return maxX; } @@ -264,6 +291,124 @@ void mogltk::shape::vline3d(int x, int y1, int y2, ColorP shade1, ColorP shade2, LEAVE; } +void mogltk::shape::bsubline_1(int x1, int y1, int x2, int y2, ColorP c) { + int x, y, ddx, ddy, e; + ddx = abs(x2 - x1); + ddy = abs(y2 - y1) << 1; + e = ddx - ddy; + ddx <<= 1; + + if (x1 > x2) { + SWAP(x1, x2); + SWAP(y1, y2); + } + + ENTER; + + for (x = x1, y = y1; x <= x2; x++) { + pixel(x, y, c); + if (e < 0) { + y++; + e += ddx - ddy; + } else { + e -= ddy; + } + } + + LEAVE; +} + +void mogltk::shape::bsubline_2(int x1, int y1, int x2, int y2, ColorP c) { + int x, y, ddx, ddy, e; + ddx = abs(x2 - x1) << 1; + ddy = abs(y2 - y1); + e = ddy - ddx; + ddy <<= 1; + + if (y1 > y2) { + SWAP(x1, x2); + SWAP(y1, y2); + } + + ENTER; + + for (y = y1, x = x1; y <= y2; y++) { + pixel(x, y, c); + if (e < 0) { + x++; + e += ddy - ddx; + } else { + e -= ddx; + } + } + + LEAVE; +} + +void mogltk::shape::bsubline_3(int x1, int y1, int x2, int y2, ColorP c) { + int x, y, ddx, ddy, e; + ddx = abs(x1 - x2) << 1; + ddy = abs(y2 - y1); + e = ddy - ddx; + ddy <<= 1; + + if (y1 > y2) { + SWAP(x1, x2); + SWAP(y1, y2); + } + + ENTER; + + for (y = y1, x = x1; y <= y2; y++) { + pixel(x, y, c); + if (e < 0) { + x--; + e += ddy - ddx; + } else { + e -= ddx; + } + } + + LEAVE; +} + +void mogltk::shape::bsubline_4(int x1, int y1, int x2, int y2, ColorP c) { + int x, y, ddx, ddy, e; + ddy = abs(y2 - y1) << 1; + ddx = abs(x1 - x2); + e = ddx - ddy; + ddx <<= 1; + + if (x1 > x2) { + SWAP(x1, x2); + SWAP(y1, y2); + } + + for (x = x1, y = y1; x <= x2; x++) { + pixel(x, y, c); + if (e < 0) { + y--; + e += ddx - ddy; + } else { + e -= ddy; + } + } +} + +void mogltk::shape::line(int x1, int y1, int x2, int y2, ColorP c) { + float k = float(y2 - y1) / float(x2 - x1); + + if ((k >= 0) && (k <= 1)) + bsubline_1(x1, y1, x2, y2, c); + else if (k > 1) + bsubline_2(x1, y1, x2, y2, c); + else if ((k < 0) && (k >= -1)) + bsubline_3(x1, y1, x2, y2, c); + else + bsubline_4(x1, y1, x2, y2, c); + +} + void mogltk::shape::pixel(int x, int y, ColorP c) { ENTER; @@ -341,9 +486,11 @@ mogltk::fill * mogltk::shape::fcircle(int x0, int y0, int r) { int dI = 10 - 4 * r; int rI = 6; mogltk::fill * f = new fill(); - bool t = true; + bool t = false; + int ox, oy; while (x <= y) { +/* if (t) { f->insert(x0 - x, y0 - y); f->insert(x0 + x, y0 - y); @@ -354,15 +501,28 @@ mogltk::fill * mogltk::shape::fcircle(int x0, int y0, int r) { f->insert(x0 + y, y0 - x); f->insert(x0 - y, y0 + x); f->insert(x0 + y, y0 + x); +*/ + printm(M_INFO, "fcircle: processing point %i %i\n", x, y); + if (t) { + f->insert(x0 - ox, y0 - oy, x0 - x, y0 - y); + f->insert(x0 + ox, y0 - oy, x0 + x, y0 - y); + f->insert(x0 - ox, y0 + oy, x0 - x, y0 + y); + f->insert(x0 + ox, y0 + oy, x0 + x, y0 + y); + f->insert(x0 - oy, y0 - ox, x0 - y, y0 - x); + f->insert(x0 + oy, y0 - ox, x0 + y, y0 - x); + f->insert(x0 - oy, y0 + ox, x0 - y, y0 + x); + f->insert(x0 + oy, y0 + ox, x0 + y, y0 + x); + } + ox = x; + oy = y; + t = true; if (d >= 0) { d += dI; dI += 8; y -= 1; - t = true; } else { d += rI; dI += 4; - t = false; } rI += 4; x += 1; diff --git a/src/test.cc b/src/test.cc index 8dc4c12..53c72e9 100644 --- a/src/test.cc +++ b/src/test.cc @@ -28,7 +28,7 @@ virtual int startup() throw (GeneralException) { new Archive("datas.paq"); -#if 1 +#if 0 mogltk::base * gl = new mogltk::glbase(); mogltk::shape * sh = new mogltk::glshape(); mogltk::font * font = new mogltk::glfont(&Input("font-2.bin")); |