summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorpixel <pixel>2003-05-19 14:59:03 +0000
committerpixel <pixel>2003-05-19 14:59:03 +0000
commit3dfc16e096855b5e713fb1223511302de218f45a (patch)
tree5b702286a29691e542f338609a61814ab2bd3183 /lib
parent0d0f1d5576a9fd1cb978323463abcf43dd7a2120 (diff)
Line bugfix
Diffstat (limited to 'lib')
-rw-r--r--lib/shape.cc88
1 files changed, 24 insertions, 64 deletions
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;