diff --git a/changelog.txt b/changelog.txt
index c0df03d..cf259f7 100644
--- a/changelog.txt
+++ b/changelog.txt
@@ -1,6 +1,9 @@
ZEngine Version Log for Version 0.7.7
-$Id: changelog.txt,v 1.3 2002/12/01 07:56:17 cozman Exp $
+$Id: changelog.txt,v 1.4 2002/12/01 08:36:39 cozman Exp $
+0.7.8
+ -Added ZRect::Draw using OpenGL.
+ -Fixed ZRectTest to use new ZRect.
0.7.7
-Changed behavior of core ZEngine class methods to reflect new OpenGL behavior.
diff --git a/include/ZE_ZRect.h b/include/ZE_ZRect.h
index ebce462..8d01cc6 100644
--- a/include/ZE_ZRect.h
+++ b/include/ZE_ZRect.h
@@ -13,7 +13,7 @@
File: ZE_ZRect.h
Description: Header file for core ZEngine Rectangle Object.
Author(s): James Turk
-$Id: ZE_ZRect.h,v 1.1 2002/11/21 05:41:11 cozman Exp $
+$Id: ZE_ZRect.h,v 1.2 2002/12/01 08:36:39 cozman Exp $
\file ZE_ZRect.h
\brief Definition file for ZRect.
@@ -36,15 +36,15 @@ namespace ZE
**/
class ZRect
{
- private:
+ protected:
//! X Position of top left corner of rectangle.
- int mX;
+ int rX;
//! Y Position of top left corner of rectangle.
- int mY;
+ int rY;
//! Width of Rectangle.
- int mWidth;
+ int rWidth;
//! Height of Rectangle.
- int mHeight;
+ int rHeight;
public:
@@ -93,6 +93,17 @@ class ZRect
**/
bool operator<(const ZRect &rhs) const;
+ /*!
+ \brief Draw rectangle. (filled)
+
+ Draw the ZRect, this function is mainly provided for testing purposes.
+ \param red Red component of color (0-255).
+ \param green Green component of color (0-255).
+ \param blue Blue component of color (0-255).
+ \param alpha Alpha component of color (0-255).
+ **/
+ void Draw(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha=255);
+
/*!
\brief Changes the location of the rectangle.
diff --git a/src/ZE_ZRect.cpp b/src/ZE_ZRect.cpp
index 1771062..e0755f2 100644
--- a/src/ZE_ZRect.cpp
+++ b/src/ZE_ZRect.cpp
@@ -13,7 +13,7 @@
File: ZE_ZRect.cpp
Description: Implementation source file for core ZEngine Rectangle Object.
Author(s): James Turk
-$Id: ZE_ZRect.cpp,v 1.1 2002/11/21 05:41:13 cozman Exp $
+$Id: ZE_ZRect.cpp,v 1.2 2002/12/01 08:36:39 cozman Exp $
\file ZE_ZRect.cpp
\brief Source file for ZRect.
@@ -27,17 +27,17 @@ namespace ZE
{
ZRect::ZRect() :
- mX(0),mY(0),mWidth(0),mHeight(0)
+ rX(0),rY(0),rWidth(0),rHeight(0)
{
}
ZRect::ZRect(int x, int y, int width, int height) :
- mX(x),mY(y),mWidth(width),mHeight(height)
+ rX(x),rY(y),rWidth(width),rHeight(height)
{
}
ZRect::ZRect(const ZRect &rhs) :
- mX(rhs.X()),mY(rhs.Y()),mWidth(rhs.Width()),mHeight(rhs.Height())
+ rX(rhs.X()),rY(rhs.Y()),rWidth(rhs.Width()),rHeight(rhs.Height())
{
}
@@ -45,10 +45,10 @@ const ZRect& ZRect::operator=(const ZRect &rhs)
{
if(this != &rhs)
{
- mX = rhs.X();
- mY = rhs.Y();
- mWidth = rhs.Width();
- mHeight = rhs.Height();
+ rX = rhs.X();
+ rY = rhs.Y();
+ rWidth = rhs.Width();
+ rHeight = rhs.Height();
}
return *this;
}
@@ -57,27 +57,27 @@ bool ZRect::operator<(const ZRect &rhs) const
{
//< is the one that is closer to top corner (as a whole)//
- if(mY < rhs.Y()) //check Ys
+ if(rY < rhs.Y()) //check Ys
return true;
- else if(mY > rhs.Y())
+ else if(rY > rhs.Y())
return false;
else
{
- if(mX < rhs.X()) //check Xs
+ if(rX < rhs.X()) //check Xs
return true;
- else if(mX > rhs.X())
+ else if(rX > rhs.X())
return false;
else
{
- if(mHeight < rhs.Height()) //check heights
+ if(rHeight < rhs.Height()) //check heights
return true;
- else if(mHeight > rhs.Height())
+ else if(rHeight > rhs.Height())
return false;
else
{
- if(mWidth < rhs.Width()) //check widths
+ if(rWidth < rhs.Width()) //check widths
return true;
- else if(mWidth > rhs.Width())
+ else if(rWidth > rhs.Width())
return false;
else
return false; //nothing left to check they are ==
@@ -86,39 +86,50 @@ bool ZRect::operator<(const ZRect &rhs) const
}
}
+void ZRect::Draw(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha)
+{
+ glColor4ub(red,green,blue,alpha);
+ glBegin(GL_QUADS);
+ glVertex2i(rX, rY);
+ glVertex2i(rX+rWidth, rY);
+ glVertex2i(rX+rWidth, rY+rHeight);
+ glVertex2i(rX, rY+rHeight);
+ glEnd();
+}
+
void ZRect::Move(int x, int y)
{
- mX = x;
- mY = y;
+ rX = x;
+ rY = y;
}
void ZRect::MoveRel(int xMove, int yMove)
{
- mX += xMove;
- mY += yMove;
+ rX += xMove;
+ rY += yMove;
}
void ZRect::Resize(int width, int height)
{
- mWidth = width;
- mHeight = height;
+ rWidth = width;
+ rHeight = height;
}
void ZRect::ResizeRel(int widthChange, int heightChange)
{
- mWidth += widthChange;
- mHeight += heightChange;
+ rWidth += widthChange;
+ rHeight += heightChange;
}
bool ZRect::Intersects(const ZRect &rect) const
{
- return !(mX > rect.Right() || rect.Left() > mX+mWidth ||
- mY > rect.Bottom() || rect.Top() > mY+mHeight);
+ return !(rX > rect.Right() || rect.Left() > rX+rWidth ||
+ rY > rect.Bottom() || rect.Top() > rY+rHeight);
}
bool ZRect::Contains(int x, int y) const
{
- return x > mX && x < mX+mWidth && y > mY && y < mY+mHeight;
+ return x > rX && x < rX+rWidth && y > rY && y < rY+rHeight;
}
bool ZRect::Contains(const ZRect &rect) const
@@ -134,10 +145,10 @@ ZRect ZRect::Intersection(const ZRect &rect) const
if(Intersects(rect))
{
- tempX = mX > rect.X() ? mX : rect.X();
- tempY = mY > rect.Y() ? mY : rect.Y();
- tempW = mX+mWidth < rect.Right() ? mX+mWidth : rect.Right();
- tempH = mY+mHeight < rect.Bottom() ? mY+mHeight : rect.Bottom();
+ tempX = rX > rect.X() ? rX : rect.X();
+ tempY = rY > rect.Y() ? rY : rect.Y();
+ tempW = rX+rWidth < rect.Right() ? rX+rWidth : rect.Right();
+ tempH = rY+rHeight < rect.Bottom() ? rY+rHeight : rect.Bottom();
tempW -= tempX; //adjust width and height
tempH -= tempY;
@@ -150,52 +161,52 @@ SDL_Rect ZRect::SDLrect() const
{
SDL_Rect ret;
- ret.x = static_cast(mX);
- ret.y = static_cast(mY);
- ret.w = static_cast(mWidth);
- ret.h = static_cast(mHeight);
+ ret.x = static_cast(rX);
+ ret.y = static_cast(rY);
+ ret.w = static_cast(rWidth);
+ ret.h = static_cast(rHeight);
return ret;
}
int ZRect::X() const
{
- return mX;
+ return rX;
}
int ZRect::Y() const
{
- return mY;
+ return rY;
}
int ZRect::Left() const
{
- return mX;
+ return rX;
}
int ZRect::Right() const
{
- return mX+mWidth;
+ return rX+rWidth;
}
int ZRect::Top() const
{
- return mY;
+ return rY;
}
int ZRect::Bottom() const
{
- return mY+mHeight;
+ return rY+rHeight;
}
int ZRect::Width() const
{
- return mWidth;
+ return rWidth;
}
int ZRect::Height() const
{
- return mHeight;
+ return rHeight;
}
} //namespace ZE
diff --git a/test/ZRectTest.cpp b/test/ZRectTest.cpp
index 872679f..eff8d96 100644
--- a/test/ZRectTest.cpp
+++ b/test/ZRectTest.cpp
@@ -69,9 +69,9 @@ void Test()
}
engine->Clear();
- engine->Clear(engine->MapColor(255,0,0,128),&moveRect.SDLrect());
- engine->Clear(engine->MapColor(0,0,255),&stillRect.SDLrect());
- engine->Clear(engine->MapColor(0,255,0),&moveRect.Intersection(stillRect).SDLrect());
+ moveRect.Draw(255,0,0,128);
+ stillRect.Draw(0,0,255,128);
+ moveRect.Intersection(stillRect).Draw(0,255,0);
engine->UpdateScreen();
} while(!engine->QuitRequested());
diff --git a/todo.txt b/todo.txt
index a1d3d08..0e84356 100644
--- a/todo.txt
+++ b/todo.txt
@@ -1,5 +1,6 @@
ZEngine Todo List
+
-Add rotation-zooming support (using OpenGL)
-Proofread, update, clarify documentation.
-Add Support for PhysicsFS with SDL_ttf and SDL_mixer music. (Waiting on other libraries.)