ZRect::Draw
This commit is contained in:
parent
0e65cbda2d
commit
a123fd50c9
@ -1,6 +1,9 @@
|
|||||||
ZEngine Version Log for Version 0.7.7
|
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
|
0.7.7
|
||||||
-Changed behavior of core ZEngine class methods to reflect new OpenGL behavior.
|
-Changed behavior of core ZEngine class methods to reflect new OpenGL behavior.
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
File: ZE_ZRect.h <br>
|
File: ZE_ZRect.h <br>
|
||||||
Description: Header file for core ZEngine Rectangle Object. <br>
|
Description: Header file for core ZEngine Rectangle Object. <br>
|
||||||
Author(s): James Turk <br>
|
Author(s): James Turk <br>
|
||||||
$Id: ZE_ZRect.h,v 1.1 2002/11/21 05:41:11 cozman Exp $<br>
|
$Id: ZE_ZRect.h,v 1.2 2002/12/01 08:36:39 cozman Exp $<br>
|
||||||
|
|
||||||
\file ZE_ZRect.h
|
\file ZE_ZRect.h
|
||||||
\brief Definition file for ZRect.
|
\brief Definition file for ZRect.
|
||||||
@ -36,15 +36,15 @@ namespace ZE
|
|||||||
**/
|
**/
|
||||||
class ZRect
|
class ZRect
|
||||||
{
|
{
|
||||||
private:
|
protected:
|
||||||
//! X Position of top left corner of rectangle.
|
//! X Position of top left corner of rectangle.
|
||||||
int mX;
|
int rX;
|
||||||
//! Y Position of top left corner of rectangle.
|
//! Y Position of top left corner of rectangle.
|
||||||
int mY;
|
int rY;
|
||||||
//! Width of Rectangle.
|
//! Width of Rectangle.
|
||||||
int mWidth;
|
int rWidth;
|
||||||
//! Height of Rectangle.
|
//! Height of Rectangle.
|
||||||
int mHeight;
|
int rHeight;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -93,6 +93,17 @@ class ZRect
|
|||||||
**/
|
**/
|
||||||
bool operator<(const ZRect &rhs) const;
|
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.
|
\brief Changes the location of the rectangle.
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
File: ZE_ZRect.cpp <br>
|
File: ZE_ZRect.cpp <br>
|
||||||
Description: Implementation source file for core ZEngine Rectangle Object. <br>
|
Description: Implementation source file for core ZEngine Rectangle Object. <br>
|
||||||
Author(s): James Turk <br>
|
Author(s): James Turk <br>
|
||||||
$Id: ZE_ZRect.cpp,v 1.1 2002/11/21 05:41:13 cozman Exp $<br>
|
$Id: ZE_ZRect.cpp,v 1.2 2002/12/01 08:36:39 cozman Exp $<br>
|
||||||
|
|
||||||
\file ZE_ZRect.cpp
|
\file ZE_ZRect.cpp
|
||||||
\brief Source file for ZRect.
|
\brief Source file for ZRect.
|
||||||
@ -27,17 +27,17 @@ namespace ZE
|
|||||||
{
|
{
|
||||||
|
|
||||||
ZRect::ZRect() :
|
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) :
|
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) :
|
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)
|
if(this != &rhs)
|
||||||
{
|
{
|
||||||
mX = rhs.X();
|
rX = rhs.X();
|
||||||
mY = rhs.Y();
|
rY = rhs.Y();
|
||||||
mWidth = rhs.Width();
|
rWidth = rhs.Width();
|
||||||
mHeight = rhs.Height();
|
rHeight = rhs.Height();
|
||||||
}
|
}
|
||||||
return *this;
|
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)//
|
//< 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;
|
return true;
|
||||||
else if(mY > rhs.Y())
|
else if(rY > rhs.Y())
|
||||||
return false;
|
return false;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(mX < rhs.X()) //check Xs
|
if(rX < rhs.X()) //check Xs
|
||||||
return true;
|
return true;
|
||||||
else if(mX > rhs.X())
|
else if(rX > rhs.X())
|
||||||
return false;
|
return false;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(mHeight < rhs.Height()) //check heights
|
if(rHeight < rhs.Height()) //check heights
|
||||||
return true;
|
return true;
|
||||||
else if(mHeight > rhs.Height())
|
else if(rHeight > rhs.Height())
|
||||||
return false;
|
return false;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(mWidth < rhs.Width()) //check widths
|
if(rWidth < rhs.Width()) //check widths
|
||||||
return true;
|
return true;
|
||||||
else if(mWidth > rhs.Width())
|
else if(rWidth > rhs.Width())
|
||||||
return false;
|
return false;
|
||||||
else
|
else
|
||||||
return false; //nothing left to check they are ==
|
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)
|
void ZRect::Move(int x, int y)
|
||||||
{
|
{
|
||||||
mX = x;
|
rX = x;
|
||||||
mY = y;
|
rY = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZRect::MoveRel(int xMove, int yMove)
|
void ZRect::MoveRel(int xMove, int yMove)
|
||||||
{
|
{
|
||||||
mX += xMove;
|
rX += xMove;
|
||||||
mY += yMove;
|
rY += yMove;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZRect::Resize(int width, int height)
|
void ZRect::Resize(int width, int height)
|
||||||
{
|
{
|
||||||
mWidth = width;
|
rWidth = width;
|
||||||
mHeight = height;
|
rHeight = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZRect::ResizeRel(int widthChange, int heightChange)
|
void ZRect::ResizeRel(int widthChange, int heightChange)
|
||||||
{
|
{
|
||||||
mWidth += widthChange;
|
rWidth += widthChange;
|
||||||
mHeight += heightChange;
|
rHeight += heightChange;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZRect::Intersects(const ZRect &rect) const
|
bool ZRect::Intersects(const ZRect &rect) const
|
||||||
{
|
{
|
||||||
return !(mX > rect.Right() || rect.Left() > mX+mWidth ||
|
return !(rX > rect.Right() || rect.Left() > rX+rWidth ||
|
||||||
mY > rect.Bottom() || rect.Top() > mY+mHeight);
|
rY > rect.Bottom() || rect.Top() > rY+rHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZRect::Contains(int x, int y) const
|
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
|
bool ZRect::Contains(const ZRect &rect) const
|
||||||
@ -134,10 +145,10 @@ ZRect ZRect::Intersection(const ZRect &rect) const
|
|||||||
|
|
||||||
if(Intersects(rect))
|
if(Intersects(rect))
|
||||||
{
|
{
|
||||||
tempX = mX > rect.X() ? mX : rect.X();
|
tempX = rX > rect.X() ? rX : rect.X();
|
||||||
tempY = mY > rect.Y() ? mY : rect.Y();
|
tempY = rY > rect.Y() ? rY : rect.Y();
|
||||||
tempW = mX+mWidth < rect.Right() ? mX+mWidth : rect.Right();
|
tempW = rX+rWidth < rect.Right() ? rX+rWidth : rect.Right();
|
||||||
tempH = mY+mHeight < rect.Bottom() ? mY+mHeight : rect.Bottom();
|
tempH = rY+rHeight < rect.Bottom() ? rY+rHeight : rect.Bottom();
|
||||||
|
|
||||||
tempW -= tempX; //adjust width and height
|
tempW -= tempX; //adjust width and height
|
||||||
tempH -= tempY;
|
tempH -= tempY;
|
||||||
@ -150,52 +161,52 @@ SDL_Rect ZRect::SDLrect() const
|
|||||||
{
|
{
|
||||||
SDL_Rect ret;
|
SDL_Rect ret;
|
||||||
|
|
||||||
ret.x = static_cast<Sint16>(mX);
|
ret.x = static_cast<Sint16>(rX);
|
||||||
ret.y = static_cast<Sint16>(mY);
|
ret.y = static_cast<Sint16>(rY);
|
||||||
ret.w = static_cast<Sint16>(mWidth);
|
ret.w = static_cast<Sint16>(rWidth);
|
||||||
ret.h = static_cast<Sint16>(mHeight);
|
ret.h = static_cast<Sint16>(rHeight);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ZRect::X() const
|
int ZRect::X() const
|
||||||
{
|
{
|
||||||
return mX;
|
return rX;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ZRect::Y() const
|
int ZRect::Y() const
|
||||||
{
|
{
|
||||||
return mY;
|
return rY;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ZRect::Left() const
|
int ZRect::Left() const
|
||||||
{
|
{
|
||||||
return mX;
|
return rX;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ZRect::Right() const
|
int ZRect::Right() const
|
||||||
{
|
{
|
||||||
return mX+mWidth;
|
return rX+rWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ZRect::Top() const
|
int ZRect::Top() const
|
||||||
{
|
{
|
||||||
return mY;
|
return rY;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ZRect::Bottom() const
|
int ZRect::Bottom() const
|
||||||
{
|
{
|
||||||
return mY+mHeight;
|
return rY+rHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ZRect::Width() const
|
int ZRect::Width() const
|
||||||
{
|
{
|
||||||
return mWidth;
|
return rWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ZRect::Height() const
|
int ZRect::Height() const
|
||||||
{
|
{
|
||||||
return mHeight;
|
return rHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
} //namespace ZE
|
} //namespace ZE
|
||||||
|
@ -69,9 +69,9 @@ void Test()
|
|||||||
}
|
}
|
||||||
|
|
||||||
engine->Clear();
|
engine->Clear();
|
||||||
engine->Clear(engine->MapColor(255,0,0,128),&moveRect.SDLrect());
|
moveRect.Draw(255,0,0,128);
|
||||||
engine->Clear(engine->MapColor(0,0,255),&stillRect.SDLrect());
|
stillRect.Draw(0,0,255,128);
|
||||||
engine->Clear(engine->MapColor(0,255,0),&moveRect.Intersection(stillRect).SDLrect());
|
moveRect.Intersection(stillRect).Draw(0,255,0);
|
||||||
engine->UpdateScreen();
|
engine->UpdateScreen();
|
||||||
|
|
||||||
} while(!engine->QuitRequested());
|
} while(!engine->QuitRequested());
|
||||||
|
1
todo.txt
1
todo.txt
@ -1,5 +1,6 @@
|
|||||||
ZEngine Todo List
|
ZEngine Todo List
|
||||||
|
|
||||||
|
|
||||||
-Add rotation-zooming support (using OpenGL)
|
-Add rotation-zooming support (using OpenGL)
|
||||||
-Proofread, update, clarify documentation.
|
-Proofread, update, clarify documentation.
|
||||||
-Add Support for PhysicsFS with SDL_ttf and SDL_mixer music. (Waiting on other libraries.)
|
-Add Support for PhysicsFS with SDL_ttf and SDL_mixer music. (Waiting on other libraries.)
|
||||||
|
Loading…
Reference in New Issue
Block a user