DrawClipped
This commit is contained in:
parent
429ed5c43d
commit
a9c641bc9d
@ -13,7 +13,7 @@
|
||||
\brief Definition file for ZImage.
|
||||
|
||||
Definition file for ZImage, the OpenGL version of the ZImage class for ZEngine.
|
||||
<br>$Id: ZE_ZImage.h,v 1.22 2003/08/07 05:54:45 cozman Exp $<br>
|
||||
<br>$Id: ZE_ZImage.h,v 1.23 2003/09/01 00:22:27 cozman Exp $<br>
|
||||
\author James Turk
|
||||
**/
|
||||
|
||||
@ -21,6 +21,7 @@
|
||||
#define __ze_zimage_h__
|
||||
|
||||
#include "ZE_ZEngine.h"
|
||||
#include "ZE_ZRect.h"
|
||||
|
||||
namespace ZE
|
||||
{
|
||||
@ -246,6 +247,17 @@ class ZImage
|
||||
**/
|
||||
void DrawRotated(float x, float y, float angle) const;
|
||||
|
||||
/*!
|
||||
\brief Draw Clipped Image to screen.
|
||||
|
||||
Image is drawn such that only portions of image which fall within a certain area appear.
|
||||
\since 0.8.5
|
||||
\param x X coord to draw Image to.
|
||||
\param y Y coord to draw Image to.
|
||||
\param clipRect Rectangle to clip within.
|
||||
**/
|
||||
void DrawClipped(float x, float y, ZRect clipRect) const;
|
||||
|
||||
/*!
|
||||
\brief Flip image over one or both axes.
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
\brief Source file for ZImage.
|
||||
|
||||
Implementation of ZImage, the Image class for ZEngine.
|
||||
<br>$Id: ZE_ZImage.cpp,v 1.41 2003/08/08 03:52:25 cozman Exp $<br>
|
||||
<br>$Id: ZE_ZImage.cpp,v 1.42 2003/09/01 00:22:35 cozman Exp $<br>
|
||||
\author James Turk
|
||||
**/
|
||||
|
||||
@ -237,6 +237,42 @@ void ZImage::DrawRotated(float x, float y, float angle) const
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void ZImage::DrawClipped(float x, float y, ZRect clipRect) const
|
||||
{
|
||||
ZRect imgRect(x,y,rWidth,rHeight),inRect;
|
||||
float xDiff,yDiff,nx,ny,nw,nh;
|
||||
xDiff = rTexMaxX - rTexMinX;
|
||||
yDiff = rTexMaxY - rTexMinY;
|
||||
|
||||
if(clipRect.Contains(imgRect))
|
||||
{
|
||||
Draw(x,y);
|
||||
}
|
||||
else if(clipRect.Intersects(imgRect))
|
||||
{
|
||||
inRect = clipRect.Intersection(imgRect);
|
||||
|
||||
nx = rTexMinX + (inRect.X()-imgRect.X())/imgRect.Width()*xDiff;
|
||||
ny = rTexMinY + (inRect.Y()-imgRect.Y())/imgRect.Height()*yDiff;
|
||||
nw = nx + (inRect.Width()/imgRect.Width())*xDiff;
|
||||
nh = ny + (inRect.Height()/imgRect.Height())*yDiff;
|
||||
|
||||
glColor4ub(255,255,255,rAlpha); //sets the color correctly
|
||||
Bind();
|
||||
glBegin(GL_TRIANGLE_STRIP);
|
||||
glTexCoord2f(nx,ny); glVertex2f(inRect.Left(),inRect.Top());
|
||||
glTexCoord2f(nw,ny); glVertex2f(inRect.Right(),inRect.Top());
|
||||
glTexCoord2f(nx,nh); glVertex2f(inRect.Left(),inRect.Bottom());
|
||||
glTexCoord2f(nw,nh); glVertex2f(inRect.Right(),inRect.Bottom());
|
||||
glEnd();
|
||||
glColor4ub(255,255,255,255); //be responsible, return to standard color state
|
||||
}
|
||||
else //doesn't contain nor intersect
|
||||
{
|
||||
//draw nothing
|
||||
}
|
||||
}
|
||||
|
||||
void ZImage::Flip(bool horizontal, bool vertical)
|
||||
{
|
||||
GLfloat temp;
|
||||
|
Loading…
Reference in New Issue
Block a user