From e318be8501559a9e53aa9990bf7e07b00c00ee51 Mon Sep 17 00:00:00 2001 From: pixel Date: Mon, 14 Apr 2003 15:51:42 +0000 Subject: Shapes fixed --- lib/shape.cc | 51 +++++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 24 deletions(-) (limited to 'lib/shape.cc') diff --git a/lib/shape.cc b/lib/shape.cc index de2a498..908d6d1 100644 --- a/lib/shape.cc +++ b/lib/shape.cc @@ -27,7 +27,7 @@ mogltk::segwalker::segwalker() { mogltk::segwalker::~segwalker() { } -mogltk::segwalker::setup(int x1, int y1, int x2, int y2) { +void mogltk::segwalker::step(int x1, int y1, int x2, int y2) { } mogltk::fill::fill() : minX(INT_MAX), minY(INT_MAX), maxX(INT_MIN), maxY(INT_MIN), cached(0), scached(0), header(0) { @@ -52,7 +52,7 @@ void mogltk::fill::swalk(segwalker * s) { std::vector::iterator i; for (i = segments.begin(); i != segments.end(); i++) { - s->setup(i->x1, i->y1, i->x2, i->y2); + s->step(i->x1, i->y1, i->x2, i->y2); } } @@ -290,13 +290,13 @@ mogltk::fill::sline * mogltk::fill::sline::look(int _y) { return next->look(_y); } -mogltk::shape(SDL_Surface * _surf) : surf(_surf) { - if (!tex) - tex = mogltk::engine::base_o->GetSurface(); +mogltk::shape::shape(SDL_Surface * _surf) : surf(_surf) { + if (!surf) + surf = mogltk::engine::base_o->getsurface(); } -SDL_Surface * mogltk::GetSurf() { - return Surf; +SDL_Surface * mogltk::shape::GetSurf() { + return surf; } void mogltk::shape::box(int x1, int y1, int x2, int y2, ColorP c) { @@ -305,7 +305,7 @@ void mogltk::shape::box(int x1, int y1, int x2, int y2, ColorP c) { SDL_Rect rect; rect.x = x1; rect.y = y1; rect.w = x2 - x1 + 1; rect.h = y2 - y1 + 1; - SDL_FillRect(Surf, &rect, c.toSDL(Surf)); + SDL_FillRect(surf, &rect, c.toSDL(surf->format)); LEAVE; } @@ -453,23 +453,23 @@ 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) { float k = float(y2 - y1) / float(x2 - x1); - if ((k >= 0) && (k <= 1)) + if ((k >= 0) && (k <= 1)) { bsubline_1(x1, y1, x2, y2, c); - else if (k > 1) + } else if (k > 1) { bsubline_2(x1, y1, x2, y2, c); - else if ((k < 0) && (k >= -1)) + } else if ((k < 0) && (k >= -1)) { bsubline_3(x1, y1, x2, y2, c); - else + } else { bsubline_4(x1, y1, x2, y2, c); - + } } void mogltk::shape::pixel(int x, int y, ColorP c) { ENTER; - int bpp = surface->format->BytesPerPixel; - Uint8 *p = (Uint8 *)Surf->pixels + y * Surf->pitch + x * bpp; - Uint32 pixel = c.toSDL(Surf); + int bpp = surf->format->BytesPerPixel; + Uint8 *p = (Uint8 *)surf->pixels + y * surf->pitch + x * bpp; + Uint32 pixel = c.toSDL(surf->format); switch(bpp) { case 1: @@ -496,7 +496,7 @@ void mogltk::shape::pixel(int x, int y, ColorP c) { *(Uint32 *)p = pixel; break; } - + LEAVE; } @@ -556,7 +556,6 @@ mogltk::fill * mogltk::shape::fcircle(int x0, int y0, int r) { 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); @@ -639,19 +638,22 @@ void mogltk::shape::fdraw(fill * f, ColorP c, int sx, int sy) { SDL_Rect r; r.x = f->GetMinX() + sx; r.y = f->GetMinY() + sy; - SDL_BlitSurface(f->GetTexture()->GetSurface(), 0, Surf, &r); + SDL_BlitSurface(f->GetTexture()->GetSurface(), 0, surf, &r); f->last = c.c; LEAVE; } -mogltk::segdrawer::segdrawer(fill * _f, texture * _t, ColorP _c) : f(_f), t(_t), c(_c) { +mogltk::segdrawer::segdrawer(fill * _f, texture * _t, ColorP _c) : f(_f), t(_t), c(_c), sh(new shape(_t->GetSurface())) { } mogltk::segdrawer::~segdrawer() { + delete sh; } 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; } @@ -672,6 +674,7 @@ void mogltk::segdrawer::step(int x1, int y1, int x2, int y2) { oldx = -1; } oldy = y; +#endif } void mogltk::shape::sdraw(fill * f, ColorP c, int sx, int sy) { @@ -694,7 +697,7 @@ void mogltk::shape::sdraw(fill * f, ColorP c, int sx, int sy) { SDL_Rect r; r.x = f->GetMinX() + sx; r.y = f->GetMinY() + sy; - SDL_BlitSurface(f->GetSTexture()->GetSurface(), 0, Surf, &r); + SDL_BlitSurface(f->GetSTexture()->GetSurface(), 0, surf, &r); f->last = c.c; LEAVE; @@ -854,8 +857,8 @@ void mogltk::shape::button(int x1, int y1, int x2, int y2, } bool mogltk::shape::Enter() { - if (SDL_MUSTLOCK(Surf)) { - SDL_LockSurface(Surf); + if (SDL_MUSTLOCK(surf)) { + SDL_LockSurface(surf); return true; } else { return false; @@ -864,7 +867,7 @@ bool mogltk::shape::Enter() { void mogltk::shape::Leave(bool locked) { if (locked) - SDL_UnlockSurface(Surf); + SDL_UnlockSurface(surf); } void mogltk::shape::tbox(texture *, int x1, int y1, int x2, int y2, int tx, int ty, double f, ColorP c) { -- cgit v1.2.3