summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/shape.h2
-rw-r--r--lib/shape.cc88
-rw-r--r--src/test.cc1
3 files changed, 25 insertions, 66 deletions
diff --git a/include/shape.h b/include/shape.h
index fef6bb1..f107a00 100644
--- a/include/shape.h
+++ b/include/shape.h
@@ -92,8 +92,6 @@ namespace mogltk {
virtual fill * fcircle(int x, int y, int r);
virtual void fdraw(fill *, ColorP = WHITE, int sx = 0, int sy = 0);
virtual void sdraw(fill *, ColorP = WHITE, int sx = 0, int sy = 0);
- virtual void arc(int x, int y, int r, double a1, double a2, ColorP = DOS_WHITE);
- virtual void arc(int x, int y, int r, int x1, int y1, int x2, int y2, ColorP = DOS_WHITE);
virtual void box(int x1, int y1, int x2, int y2, ColorP = DOS_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/lib/shape.cc b/lib/shape.cc
index 908d6d1..a626155 100644
--- a/lib/shape.cc
+++ b/lib/shape.cc
@@ -91,7 +91,7 @@ void mogltk::fill::insert(int x1, int y1, int x2, int y2) {
struct segment s;
s.x1 = x1;
- s.y1 = y2;
+ s.y1 = y1;
s.x2 = x2;
s.y2 = y2;
segments.push_back(s);
@@ -311,7 +311,9 @@ void mogltk::shape::box(int x1, int y1, int x2, int y2, ColorP c) {
}
void mogltk::shape::hline(int x1, int x2, int y, ColorP c) {
- box(x1, y, x2, y, c);
+ for (; x1 <= x2; x1++) {
+ pixel(x1, y, c);
+ }
}
void mogltk::shape::hline3d(int x1, int x2, int y, ColorP shade1, ColorP shade2, bool bevel) {
@@ -329,7 +331,9 @@ void mogltk::shape::hline3d(int x1, int x2, int y, ColorP shade1, ColorP shade2,
}
void mogltk::shape::vline(int x, int y1, int y2, ColorP c) {
- box(x, y1, x, y2, c);
+ for (; y1 <= y2; y1++) {
+ pixel(x, y1, c);
+ }
}
void mogltk::shape::vline3d(int x, int y1, int y2, ColorP shade1, ColorP shade2, bool bevel) {
@@ -451,6 +455,21 @@ void mogltk::shape::bsubline_4(int x1, int y1, int x2, int y2, ColorP c) {
}
void mogltk::shape::line(int x1, int y1, int x2, int y2, ColorP c) {
+ if ((x1 == x2) && (y1 == y2)) {
+ pixel(x1, y1, c);
+ return;
+ }
+
+ if (x1 == x2) {
+ vline(x1, MIN(y1, y2), MAX(y1, y2), c);
+ return;
+ }
+
+ if (y1 == y2) {
+ hline(MIN(x1, x2), MAX(x1, x2), y1, c);
+ return;
+ }
+
float k = float(y2 - y1) / float(x2 - x1);
if ((k >= 0) && (k <= 1)) {
@@ -458,9 +477,9 @@ void mogltk::shape::line(int x1, int y1, int x2, int y2, ColorP 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);
+ } else {
+ bsubline_3(x1, y1, x2, y2, c);
}
}
@@ -653,28 +672,6 @@ mogltk::segdrawer::~segdrawer() {
void mogltk::segdrawer::step(int x1, int y1, int x2, int y2) {
sh->line(x1 - f->GetMinX(), y1 - f->GetMinY(), x2 - f->GetMinX(), y2 - f->GetMinY(), c);
-#if 0
- if (oldy != y) {
- oldx = -1;
- }
- if (oldx == -1) {
- oldx = x;
- } else {
-// s->hline(oldx, x, y, c);
- Uint32 * p = t->GetPixels();
- int i,
- first = t->GetWidth() * (y - f->GetMinY()) + oldx - f->GetMinX(),
- last = first - oldx + x;
- SDL_PixelFormat * format = t->GetFormat();
-
- for (i = first; i <= last; i++) {
- p[i] = c.toSDL(format);
- }
-
- oldx = -1;
- }
- oldy = y;
-#endif
}
void mogltk::shape::sdraw(fill * f, ColorP c, int sx, int sy) {
@@ -703,43 +700,6 @@ void mogltk::shape::sdraw(fill * f, ColorP c, int sx, int sy) {
LEAVE;
}
-void mogltk::shape::arc(int x0, int y0, int r, double a1, double a2, ColorP c) {
- ENTER;
-
- int x = 0;
- int y = r - 1;
- int d = 3 - 2 * r;
- int dI = 10 - 4 * r;
- int rI = 6;
-
- while (x <= y) {
- pixel(x0 + y, y0 - x, c); // 1
- pixel(x0 + x, y0 - y, c); // 2
- pixel(x0 - x, y0 - y, c); // 3
- pixel(x0 - y, y0 - x, c); // 4
- pixel(x0 - y, y0 + x, c); // 5
- pixel(x0 - x, y0 + y, c); // 6
- pixel(x0 + x, y0 + y, c); // 7
- pixel(x0 + y, y0 + x, c); // 8
-
- if (d >= 0) {
- d += dI;
- dI += 8;
- y -= 1;
- } else {
- d += rI;
- dI += 4;
- }
- rI += 4;
- x += 1;
- }
-
- LEAVE;
-}
-
-void mogltk::shape::arc(int x0, int y0, int r, int x1, int y1, int x2, int y2, ColorP c) {
-}
-
void mogltk::shape::obox(int x1, int y1, int x2, int y2, ColorP c) {
ENTER;
diff --git a/src/test.cc b/src/test.cc
index 7ab476a..aafdbf8 100644
--- a/src/test.cc
+++ b/src/test.cc
@@ -90,6 +90,7 @@ virtual int startup() throw (GeneralException) {
font->printf("t: %.2fs\n", (double) SDL_GetTicks() / 1000);
s->draw(mogltk::engine::mouseX() - 8, mogltk::engine::mouseY() - 6);
+ sh->line(320, 240, mogltk::engine::mouseX(), mogltk::engine::mouseY());
gl->Leave2DMode();