Fixed some bugs, added rounder rectangles.

This commit is contained in:
spartanj
2010-06-30 23:35:28 -03:00
parent c00a979022
commit 0048fa6dfb
22 changed files with 798 additions and 436 deletions

View File

@@ -24,6 +24,10 @@
// Utils
#include "utils/vector2.hpp"
#include "utils/vector3.hpp"
#include "utils/size.hpp"
#include "utils/line2.hpp"
#include "utils/triangle2.hpp"
#include "utils/quad2.hpp"
#include "utils/colors.hpp"
#include "utils/polygon2.hpp"
#include "utils/rect.hpp"

View File

@@ -37,7 +37,7 @@ void cBatchRenderer::Draw() {
void cBatchRenderer::SetTexture( const Uint32& TexId ) {
if ( mTexture != TexId )
Flush();
mTexture = TexId;
}
@@ -61,112 +61,112 @@ void cBatchRenderer::SetBlendMode( EE_BATCH_RENDER_METHOD Mode ) {
void cBatchRenderer::Flush() {
if ( mNumVertex == 0 )
return;
bool CreateMatrix = ( mRotation || mScale != 1.0f || mPosition.x || mPosition.y );
if ( mTexture > 0 )
cTextureFactory::instance()->Bind( mTexture );
else
glDisable( GL_TEXTURE_2D );
cTextureFactory::instance()->SetBlendFunc( mBlend );
if ( mCurrentMode == EE_GL_POINTS && mTexture > 0 ) {
glEnable( GL_POINT_SPRITE_ARB );
glTexEnvf( GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE );
glPointSize( cTextureFactory::instance()->GetTextureWidth( mTexture ) );
}
if ( CreateMatrix ) {
glLoadIdentity();
glPushMatrix();
glTranslatef( mPosition.x, mPosition.y, 0.0f);
glTranslatef( mCenter.x, mCenter.y, 0.0f);
glRotatef( mRotation, 0.0f, 0.0f, 1.0f );
glScalef( mScale, mScale, 1.0f );
glTranslatef( -mCenter.x, -mCenter.y, 0.0f);
}
glVertexPointer(2, GL_FLOAT, sizeof(eeVertex), reinterpret_cast<char*> ( &mVertex[0] ) );
glTexCoordPointer(2, GL_FLOAT, sizeof(eeVertex), reinterpret_cast<char*> ( &mVertex[0] ) + sizeof(eeVector2f) );
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(eeVertex), reinterpret_cast<char*> ( &mVertex[0] ) + sizeof(eeVector2f) + sizeof(eeTexCoord) );
glDrawArrays( mCurrentMode, 0, mNumVertex );
if ( CreateMatrix )
glPopMatrix();
if ( mCurrentMode == EE_GL_POINTS && mTexture > 0 ) {
glDisable( GL_POINT_SPRITE_ARB );
}
if ( mTexture == 0 )
glEnable( GL_TEXTURE_2D );
mNumVertex = 0;
}
void cBatchRenderer::BatchQuad( const eeFloat& x, const eeFloat& y, const eeFloat& width, const eeFloat& height, const eeFloat& angle ) {
eeVector2f center;
if ( mNumVertex + 3 >= mVertex.size() )
return;
SetBlendMode( EE_GL_QUADS );
if ( angle ) {
center.x = x + width * 0.5f;
center.y = y + height * 0.5f;
}
mTVertex = &mVertex[ mNumVertex ];
mTVertex->pos.x = x;
mTVertex->pos.y = y;
mTVertex->tex = mTexCoord[0];
mTVertex->color = mVerColor[0];
Rotate(center, &mTVertex->pos, angle);
mTVertex = &mVertex[ mNumVertex + 1];
mTVertex->pos.x = x;
mTVertex->pos.y = y + height;
mTVertex->tex = mTexCoord[1];
mTVertex->color = mVerColor[1];
Rotate(center, &mTVertex->pos, angle);
mTVertex = &mVertex[ mNumVertex + 2];
mTVertex->pos.x = x + width;
mTVertex->pos.y = y + height;
mTVertex->tex = mTexCoord[2];
mTVertex->color = mVerColor[2];
Rotate(center, &mTVertex->pos, angle);
mTVertex = &mVertex[ mNumVertex + 3];
mTVertex->pos.x = x + width;
mTVertex->pos.y = y;
mTVertex->tex = mTexCoord[3];
mTVertex->color = mVerColor[3];
Rotate(center, &mTVertex->pos, angle);
AddVertexs(4);
}
void cBatchRenderer::BatchQuadEx( const eeFloat& x, const eeFloat& y, const eeFloat& width, const eeFloat& height, const eeFloat& angle, const eeFloat& scale, const bool& scalefromcenter ) {
eeVector2f center;
eeFloat mx = x;
eeFloat my = y;
eeFloat mwidth = width;
eeFloat mheight = height;
if ( mNumVertex + 3 >= mVertex.size() )
return;
SetBlendMode( EE_GL_QUADS );
center.x = width * 0.5f;
center.y = height * 0.5f;
if ( scale != 1.0f ) {
if ( scalefromcenter ) {
mx = mx + center.x - center.x * scale;
@@ -175,38 +175,38 @@ void cBatchRenderer::BatchQuadEx( const eeFloat& x, const eeFloat& y, const eeFl
mwidth *= scale;
mheight *= scale;
}
center.x += x;
center.y += y;
mTVertex = &mVertex[ mNumVertex ];
mTVertex->pos.x = mx;
mTVertex->pos.y = my;
mTVertex->tex = mTexCoord[0];
mTVertex->color = mVerColor[0];
Rotate(center, &mTVertex->pos, angle);
mTVertex = &mVertex[ mNumVertex + 1 ];
mTVertex->pos.x = mx;
mTVertex->pos.y = my + mheight;
mTVertex->tex = mTexCoord[1];
mTVertex->color = mVerColor[1];
Rotate(center, &mTVertex->pos, angle);
mTVertex = &mVertex[ mNumVertex + 2 ];
mTVertex->pos.x = mx + mwidth;
mTVertex->pos.y = my + mheight;
mTVertex->tex = mTexCoord[2];
mTVertex->color = mVerColor[2];
Rotate(center, &mTVertex->pos, angle);
mTVertex = &mVertex[ mNumVertex + 3 ];
mTVertex->pos.x = mx + mwidth;
mTVertex->pos.y = my;
mTVertex->tex = mTexCoord[3];
mTVertex->color = mVerColor[3];
Rotate(center, &mTVertex->pos, angle);
AddVertexs(4);
}
@@ -214,33 +214,33 @@ void cBatchRenderer::BatchQuadFree( const eeFloat& x0, const eeFloat& y0, const
if ( mNumVertex + 3 >= mVertex.size() )
return;
SetBlendMode( EE_GL_QUADS );
mTVertex = &mVertex[ mNumVertex ];
mTVertex->pos.x = x0;
mTVertex->pos.y = y0;
mTVertex->tex = mTexCoord[0];
mTVertex->color = mVerColor[0];
mTVertex = &mVertex[ mNumVertex + 1 ];
mTVertex->pos.x = x1;
mTVertex->pos.y = y1;
mTVertex->tex = mTexCoord[1];
mTVertex->color = mVerColor[1];
mTVertex = &mVertex[ mNumVertex + 2 ];
mTVertex->pos.x = x2;
mTVertex->pos.y = y2;
mTVertex->tex = mTexCoord[2];
mTVertex->color = mVerColor[2];
mTVertex = &mVertex[ mNumVertex + 3 ];
mTVertex->pos.x = x3;
mTVertex->pos.y = y3;
mTVertex->tex = mTexCoord[3];
mTVertex->color = mVerColor[3];
AddVertexs(4);
}
@@ -250,10 +250,10 @@ void cBatchRenderer::BatchQuadFreeEx( const eeFloat& x0, const eeFloat& y0, cons
mQ.V[0].y = y0; mQ.V[1].y = y1; mQ.V[2].y = y2; mQ.V[3].y = y3;
eeFloat MinX = mQ.V[0].x, MaxX = mQ.V[0].x, MinY = mQ.V[0].y, MaxY = mQ.V[0].y;
eeVector2f QCenter;
if ( mNumVertex + 3 >= mVertex.size() )
return;
if ( Angle != 0 || Scale != 1.0f ) {
for (Uint8 i = 1; i < 4; i++ ) {
if ( MinX > mQ.V[i].x ) MinX = mQ.V[i].x;
@@ -261,54 +261,54 @@ void cBatchRenderer::BatchQuadFreeEx( const eeFloat& x0, const eeFloat& y0, cons
if ( MinY > mQ.V[i].y ) MinY = mQ.V[i].y;
if ( MaxY < mQ.V[i].y ) MaxY = mQ.V[i].y;
}
QCenter.x = MinX + ( MaxX - MinX ) * 0.5f;
QCenter.y = MinY + ( MaxY - MinY ) * 0.5f;
}
if ( Scale != 1.0f ) {
for (Uint8 i = 0; i < 4; i++ ) {
if ( mQ.V[i].x < QCenter.x )
mQ.V[i].x = QCenter.x - fabs(QCenter.x - mQ.V[i].x) * Scale;
else
mQ.V[i].x = QCenter.x + fabs(QCenter.x - mQ.V[i].x) * Scale;
if ( mQ.V[i].y < QCenter.y )
mQ.V[i].y = QCenter.y - fabs(QCenter.y - mQ.V[i].y) * Scale;
else
mQ.V[i].y = QCenter.y + fabs(QCenter.y - mQ.V[i].y) * Scale;
}
}
if ( Angle != 0 )
mQ = RotateQuadCentered( mQ, Angle, QCenter );
SetBlendMode( EE_GL_QUADS );
mTVertex = &mVertex[ mNumVertex ];
mTVertex->pos.x = mQ[0].x;
mTVertex->pos.y = mQ[0].y;
mTVertex->tex = mTexCoord[0];
mTVertex->color = mVerColor[0];
mTVertex = &mVertex[ mNumVertex + 1 ];
mTVertex->pos.x = mQ[1].x;
mTVertex->pos.y = mQ[1].y;
mTVertex->tex = mTexCoord[1];
mTVertex->color = mVerColor[1];
mTVertex = &mVertex[ mNumVertex + 2 ];
mTVertex->pos.x = mQ[2].x;
mTVertex->pos.y = mQ[2].y;
mTVertex->tex = mTexCoord[2];
mTVertex->color = mVerColor[2];
mTVertex = &mVertex[ mNumVertex + 3 ];
mTVertex->pos.x = mQ[3].x;
mTVertex->pos.y = mQ[3].y;
mTVertex->tex = mTexCoord[3];
mTVertex->color = mVerColor[3];
AddVertexs(4);
}
@@ -366,15 +366,15 @@ void cBatchRenderer::PointSetColor( const eeColorA Color ) {
void cBatchRenderer::BatchPoint( const eeFloat& x, const eeFloat& y ) {
if ( mNumVertex + 1 >= mVertex.size() )
return;
SetBlendMode( EE_GL_POINTS );
mTVertex = &mVertex[ mNumVertex ];
mTVertex->pos.x = x;
mTVertex->pos.y = y;
mTVertex->tex = mTexCoord[0];
mTVertex->color = mVerColor[0];
AddVertexs(1);
}
@@ -395,21 +395,21 @@ void cBatchRenderer::LinesSetColorFree( const eeColorA Color0, const eeColorA Co
void cBatchRenderer::BatchLine( const eeFloat& x0, const eeFloat& y0, const eeFloat& x1, const eeFloat& y1 ) {
if ( mNumVertex + 1 >= mVertex.size() )
return;
SetBlendMode( EE_GL_LINES );
mTVertex = &mVertex[ mNumVertex ];
mTVertex->pos.x = x0;
mTVertex->pos.y = y0;
mTVertex->tex = mTexCoord[0];
mTVertex->color = mVerColor[0];
mTVertex = &mVertex[ mNumVertex + 1 ];
mTVertex->pos.x = x1;
mTVertex->pos.y = y1;
mTVertex->tex = mTexCoord[1];
mTVertex->color = mVerColor[1];
AddVertexs(2);
}
@@ -430,24 +430,47 @@ void cBatchRenderer::LineLoopSetColorFree( const eeColorA Color0, const eeColorA
void cBatchRenderer::BatchLineLoop( const eeFloat& x0, const eeFloat& y0, const eeFloat& x1, const eeFloat& y1 ) {
if ( mNumVertex + 1 >= mVertex.size() )
return;
SetBlendMode( EE_GL_LINE_LOOP );
mTVertex = &mVertex[ mNumVertex ];
mTVertex->pos.x = x0;
mTVertex->pos.y = y0;
mTVertex->tex = mTexCoord[0];
mTVertex->color = mVerColor[0];
mTVertex = &mVertex[ mNumVertex + 1 ];
mTVertex->pos.x = x1;
mTVertex->pos.y = y1;
mTVertex->tex = mTexCoord[1];
mTVertex->color = mVerColor[1];
AddVertexs(2);
}
void cBatchRenderer::BatchLineLoop( const eeVector2f& vector1, const eeVector2f& vector2 ) {
BatchLineLoop( vector1.x, vector1.y, vector2.x, vector2.y );
}
void cBatchRenderer::BatchLineLoop( const eeFloat& x0, const eeFloat& y0 ) {
if ( mNumVertex + 1 >= mVertex.size() )
return;
SetBlendMode( EE_GL_LINE_LOOP );
mTVertex = &mVertex[ mNumVertex ];
mTVertex->pos.x = x0;
mTVertex->pos.y = y0;
mTVertex->tex = mTexCoord[0];
mTVertex->color = mVerColor[0];
AddVertexs(1);
}
void cBatchRenderer::BatchLineLoop( const eeVector2f& vector1 ) {
BatchLineLoop( vector1.x, vector1.y );
}
void cBatchRenderer::TriangleFanBegin() {
SetBlendMode( EE_GL_TRIANGLE_FAN );
TriangleFanSetSubset( 0, 0, 0, 1, 1, 1 );
@@ -472,21 +495,21 @@ void cBatchRenderer::BatchTriangleFan( const eeFloat& x0, const eeFloat& y0, con
if ( mNumVertex + 2 >= mVertex.size() )
return;
SetBlendMode( EE_GL_TRIANGLE_FAN );
mTVertex = &mVertex[ mNumVertex ];
mTVertex->pos.x = x0;
mTVertex->pos.y = y0;
mTVertex->tex = mTexCoord[0];
mTVertex->color = mVerColor[0];
mTVertex = &mVertex[ mNumVertex + 1 ];
mTVertex->pos.x = x1;
mTVertex->pos.y = y1;
mTVertex->tex = mTexCoord[1];
mTVertex->color = mVerColor[1];
mTVertex = &mVertex[ mNumVertex + 2 ];
mTVertex->pos.x = x2;
mTVertex->pos.y = y2;
@@ -520,21 +543,21 @@ void cBatchRenderer::BatchTriangle( const eeFloat& x0, const eeFloat& y0, const
if ( mNumVertex + 2 >= mVertex.size() )
return;
SetBlendMode( EE_GL_TRIANGLES );
mTVertex = &mVertex[ mNumVertex ];
mTVertex->pos.x = x0;
mTVertex->pos.y = y0;
mTVertex->tex = mTexCoord[0];
mTVertex->color = mVerColor[0];
mTVertex = &mVertex[ mNumVertex + 1 ];
mTVertex->pos.x = x1;
mTVertex->pos.y = y1;
mTVertex->tex = mTexCoord[1];
mTVertex->color = mVerColor[1];
mTVertex = &mVertex[ mNumVertex + 2 ];
mTVertex->pos.x = x2;
mTVertex->pos.y = y2;
@@ -551,21 +574,40 @@ void cBatchRenderer::PolygonSetColor( const eeColorA& Color ) {
void cBatchRenderer::BatchPolygon( const eePolygon2f& Polygon ) {
if ( Polygon.Size() > mVertex.size() )
return;
SetBlendMode( EE_GL_POLYGON );
for ( Uint32 i = 0; i < Polygon.Size(); i++ ) {
mTVertex = &mVertex[ mNumVertex ];
mTVertex->pos.x = Polygon.X() + Polygon[i].x;
mTVertex->pos.y = Polygon.Y() + Polygon[i].y;
mTVertex->tex = mTexCoord[0];
mTVertex->color = mVerColor[0];
AddVertexs(1);
}
}
void cBatchRenderer::BatchPolygonByPoint( const eeFloat& x, const eeFloat& y ) {
if ( mNumVertex + 1 >= mVertex.size() )
return;
SetBlendMode( EE_GL_POLYGON );
mTVertex = &mVertex[ mNumVertex ];
mTVertex->pos.x = x;
mTVertex->pos.y = y;
mTVertex->tex = mTexCoord[0];
mTVertex->color = mVerColor[0];
AddVertexs(1);
}
void cBatchRenderer::BatchPolygonByPoint( const eeVector2f& Vector ) {
BatchPolygonByPoint( Vector.x, Vector.y );
}
void cBatchRenderer::SetLineWidth( const eeFloat& lineWidth ) {
glLineWidth( lineWidth );
}

View File

@@ -5,7 +5,7 @@
namespace EE { namespace Graphics {
typedef struct {
typedef struct {
eeFloat u;
eeFloat v;
} eeTexCoord;
@@ -21,174 +21,184 @@ class cBatchRenderer {
public:
cBatchRenderer();
~cBatchRenderer();
/** Construct with a defined number of vertexs preallocated */
cBatchRenderer( const eeUint& Prealloc );
/** Allocate space for vertexs */
void AllocVertexs( const eeUint& size );
/** Set the current texture to render on the batch ( if you change the texture and you have batched something, this will be renderer immediately ) */
void SetTexture( const Uint32& TexId );
/** Set the blending functions to use on the batch */
void SetBlendFunc( const EE_RENDERALPHAS& Blend );
/** Set if every batch call have to be immediately rendered */
void BatchForceRendering( const bool& force ) { mForceRendering = force; }
/** Get if the rendering is force on every batch call */
bool BatchForceRendering() const { return mForceRendering; }
/** Force the batch rendering */
void Draw();
/** Force the batch rendering only if BatchForceRendering is enable */
void DrawOpt();
/** Set the rotation of the rendered vertex. */
void BatchRotation( const eeFloat& Rotation ) { mRotation = Rotation; }
/** Get the rotation of the rendered vertex. */
eeFloat BatchRotation() const { return mRotation; }
/** Set the scale of the rendered vertex. */
void BatchScale( const eeFloat& Scale ) { mScale = Scale; }
/** Get the scale of the rendered vertex. */
eeFloat BatchScale() const { return mScale; }
/** The batch position */
void BatchPosition( const eeVector2f Pos ) { mPosition = Pos; }
/** @return The batch position */
eeVector2f BatchPosition() const { return mPosition; }
/** This will set a center position for rotating and scaling the batched vertex. */
void BatchCenter( const eeVector2f Pos ) { mCenter = Pos; }
/** @return The batch center position */
eeVector2f BatchCenter() const { return mCenter; }
/** Add to the batch a quad ( this will change your batch rendering method to GL_QUADS, so if you were using another one will Draw all the batched vertexs first ) */
void BatchQuadEx( const eeFloat& x, const eeFloat& y, const eeFloat& width, const eeFloat& height, const eeFloat& angle = 0.0f, const eeFloat& scale = 1.0f, const bool& scalefromcenter = true );
/** Add to the batch a quad ( this will change your batch rendering method to GL_QUADS, so if you were using another one will Draw all the batched vertexs first ) */
void BatchQuad( const eeFloat& x, const eeFloat& y, const eeFloat& width, const eeFloat& height, const eeFloat& angle = 0.0f );
/** Add to the batch a quad with the vertex freely seted ( this will change your batch rendering method to GL_QUADS, so if you were using another one will Draw all the batched vertexs first ) */
void BatchQuadFree( const eeFloat& x0, const eeFloat& y0, const eeFloat& x1, const eeFloat& y1, const eeFloat& x2, const eeFloat& y2, const eeFloat& x3, const eeFloat& y3 );
/** Add to the batch a quad with the vertex freely seted ( this will change your batch rendering method to GL_QUADS, so if you were using another one will Draw all the batched vertexs first ) */
void BatchQuadFreeEx( const eeFloat& x0, const eeFloat& y0, const eeFloat& x1, const eeFloat& y1, const eeFloat& x2, const eeFloat& y2, const eeFloat& x3, const eeFloat& y3, const eeFloat& Angle = 0.0f, const eeFloat& Scale = 1.0f );
/** This will set as the default batch rendering to GL_QUADS. WIll reset the texture subset rendering to the whole texture. Will reset the default color rendering to eeColorA(255,255,255,255). */
void QuadsBegin();
/** Set the texture sector to be rendered */
void QuadsSetSubset( const eeFloat& tl_u, const eeFloat& tl_v, const eeFloat& br_u, const eeFloat& br_v );
/** Set the texture sector to be rendered but freely seted */
void QuadsSetSubsetFree( const eeFloat& x0, const eeFloat& y0, const eeFloat& x1, const eeFloat& y1, const eeFloat& x2, const eeFloat& y2, const eeFloat& x3, const eeFloat& y3 );
/** Set the quad color */
void QuadsSetColor( const eeColorA Color );
/** Set the quad color per vertex */
void QuadsSetColorFree( const eeColorA Color0, const eeColorA Color1, const eeColorA Color2, const eeColorA Color3 );
/** This will set as the default batch rendering to GL_POINTS. And will reset the point color to eeColorA(255,255,255,255). */
void PointsBegin();
/** Set the point color */
void PointSetColor( const eeColorA Color );
/** Add to the batch a point ( this will change your batch rendering method to GL_POINTS, so if you were using another one will Draw all the batched vertexs first ) */
void BatchPoint( const eeFloat& x, const eeFloat& y );
/** This will set as the default batch rendering to GL_LINES. And will reset the line color to eeColorA(255,255,255,255). */
void LinesBegin();
/** Set the line color */
void LinesSetColor( const eeColorA Color );
/** Set the line color, per vertex */
void LinesSetColorFree( const eeColorA Color0, const eeColorA Color1 );
/** Add to the batch a line ( this will change your batch rendering method to GL_LINES, so if you were using another one will Draw all the batched vertexs first ) */
void BatchLine( const eeFloat& x0, const eeFloat& y0, const eeFloat& x1, const eeFloat& y1 );
/** This will set as the default batch rendering to GL_LINE_LOOP. And will reset the line color to eeColorA(255,255,255,255). */
void LineLoopBegin();
/** Set the line color */
void LineLoopSetColor( const eeColorA Color );
/** Set the line color, per vertex */
void LineLoopSetColorFree( const eeColorA Color0, const eeColorA Color1 );
/** Add to the batch a line ( this will change your batch rendering method to GL_LINE_LOOP, so if you were using another one will Draw all the batched vertexs first ) */
void BatchLineLoop( const eeFloat& x0, const eeFloat& y0, const eeFloat& x1, const eeFloat& y1 );
void BatchLineLoop( const eeFloat& x0, const eeFloat& y0);
void BatchLineLoop( const eeVector2f& vector1, const eeVector2f& vector2 );
void BatchLineLoop( const eeVector2f& vector1 );
/** This will set as the default batch rendering to GL_TRIANGLE_FAN. And will reset the line color to eeColorA(255,255,255,255). */
void TriangleFanBegin();
/** Set the triangle fan color */
void TriangleFanSetColor( const eeColorA Color );
/** Set the triangle fan color, per vertex */
void TriangleFanSetColorFree( const eeColorA Color0, const eeColorA Color1, const eeColorA Color2 );
/** Set the texture sector to be rendered but freely seted */
void TriangleFanSetSubset( const eeFloat& x0, const eeFloat& y0, const eeFloat& x1, const eeFloat& y1, const eeFloat& x2, const eeFloat& y2 );
/** Add to the batch a triangle fan ( this will change your batch rendering method to GL_TRIANGLE_FAN, so if you were using another one will Draw all the batched vertexs first ) */
void BatchTriangleFan( const eeFloat& x0, const eeFloat& y0, const eeFloat& x1, const eeFloat& y1, const eeFloat& x2, const eeFloat& y2 );
/** This will set as the default batch rendering to GL_TRIANGLES. And will reset the line color to eeColorA(255,255,255,255). */
void TrianglesBegin();
/** Set the triangles color */
void TrianglesSetColor( const eeColorA Color );
/** Set the triangles color, per vertex */
void TrianglesSetColorFree( const eeColorA Color0, const eeColorA Color1, const eeColorA Color2 );
/** Set the texture sector to be rendered but freely seted */
void TrianglesSetSubset( const eeFloat& x0, const eeFloat& y0, const eeFloat& x1, const eeFloat& y1, const eeFloat& x2, const eeFloat& y2 );
/** Add to the batch a triangle ( this will change your batch rendering method to GL_TRIANGLES, so if you were using another one will Draw all the batched vertexs first ) */
void BatchTriangle( const eeFloat& x0, const eeFloat& y0, const eeFloat& x1, const eeFloat& y1, const eeFloat& x2, const eeFloat& y2 );
/** Set the polygon color */
void PolygonSetColor( const eeColorA& Color );
/** Add to the batch a polygon ( this will change your batch rendering method to GL_POLYGON, so if you were using another one will Draw all the batched vertexs first ) */
void BatchPolygon( const eePolygon2f& Polygon );
/** Set the line width */
void SetLineWidth( const eeFloat& lineWidth );
/** Set the point size */
void SetPointSize( const eeFloat& pointSize );
void BatchPolygonByPoint( const eeFloat& x, const eeFloat& y );
void BatchPolygonByPoint( const eeVector2f& Vector );
protected:
std::vector<eeVertex> mVertex;
eeVertex * mTVertex;
eeUint mNumVertex;
Uint32 mTexture;
EE_RENDERALPHAS mBlend;
eeTexCoord mTexCoord[4];
eeColorA mVerColor[4];
EE_BATCH_RENDER_METHOD mCurrentMode;
eeFloat mRotation, mScale;
eeVector2f mPosition, mCenter;
bool mForceRendering;
void Flush();
void Init();
void AddVertexs( const eeUint& num );

View File

@@ -1,4 +1,5 @@
#include "cprimitives.hpp"
#include "../utils/polygon2.hpp"
namespace EE { namespace Graphics {
@@ -10,16 +11,96 @@ cPrimitives::cPrimitives() {
cPrimitives::~cPrimitives() {}
void cPrimitives::DrawRectangle(const eeFloat& x, const eeFloat& y, const eeFloat& width, const eeFloat& height, const eeColorA& TopLeft, const eeColorA& BottomLeft, const eeColorA& BottomRight, const eeColorA& TopRight, const eeFloat& Angle, const eeFloat& Scale, const EE_FILLMODE& fillmode, const EE_RENDERALPHAS& blend, const eeFloat& lineWidth) {
void cPrimitives::DrawRoundedRectangle(const eeFloat& x, const eeFloat& y, const eeFloat& width, const eeFloat& height, const eeColorA& TopLeft, const eeColorA& BottomLeft, const eeColorA& BottomRight, const eeColorA& TopRight, const eeFloat& Angle, const eeFloat& Scale, const EE_FILLMODE& fillmode, const EE_RENDERALPHAS& blend, const eeFloat& lineWidth, const eeUint& Corners ) {
BR->SetTexture( 0 );
BR->SetBlendFunc( blend );
eeUint i;
eeFloat xscalediff = width * Scale - width;
eeFloat yscalediff = height * Scale - height;
eeVector2f poly;
eeVector2f Center( x + width * 0.5f + xscalediff, y + height * 0.5f + yscalediff );
eePolygon2f Poly = CreateRoundedPolygon( x - xscalediff, y - yscalediff, width + xscalediff, height + yscalediff, Corners );
Poly.Rotate( Angle, Center );
switch(fillmode) {
case DRAW_FILL: {
if ( TopLeft == BottomLeft && BottomLeft == BottomRight && BottomRight == TopRight ) {
BR->PolygonSetColor( TopLeft );
BR->BatchPolygon( Poly );
} else {
for ( i = 0; i < Poly.Size(); i++ ) {
poly = Poly[i];
if ( poly.x <= Center.x && poly.y <= Center.y )
BR->PolygonSetColor( TopLeft );
else if ( poly.x <= Center.x && poly.y >= Center.y )
BR->PolygonSetColor( BottomLeft );
else if ( poly.x > Center.x && poly.y > Center.y )
BR->PolygonSetColor( BottomRight );
else if ( poly.x > Center.x && poly.y < Center.y )
BR->PolygonSetColor( TopRight );
else
BR->PolygonSetColor( TopLeft );
BR->BatchPolygonByPoint( Poly[i] );
}
}
break;
}
case DRAW_LINE:
BR->SetLineWidth( lineWidth );
BR->LineLoopBegin();
BR->LineLoopSetColor( TopLeft );
if ( TopLeft == BottomLeft && BottomLeft == BottomRight && BottomRight == TopRight ) {
for ( i = 0; i < Poly.Size(); i+=2 )
BR->BatchLineLoop( Poly[i], Poly[i+1] );
} else {
for ( eeUint i = 0; i < Poly.Size(); i++ ) {
poly = Poly[i];
if ( poly.x <= Center.x && poly.y <= Center.y )
BR->LineLoopSetColor( TopLeft );
else if ( poly.x < Center.x && poly.y > Center.y )
BR->LineLoopSetColor( BottomLeft );
else if ( poly.x > Center.x && poly.y > Center.y )
BR->LineLoopSetColor( BottomRight );
else if ( poly.x > Center.x && poly.y < Center.y )
BR->LineLoopSetColor( TopRight );
else
BR->LineLoopSetColor( TopLeft );
BR->BatchLineLoop( Poly[i] );
}
}
break;
}
BR->Draw();
}
void cPrimitives::DrawRectangle(const eeFloat& x, const eeFloat& y, const eeFloat& width, const eeFloat& height, const eeColorA& TopLeft, const eeColorA& BottomLeft, const eeColorA& BottomRight, const eeColorA& TopRight, const eeFloat& Angle, const eeFloat& Scale, const EE_FILLMODE& fillmode, const EE_RENDERALPHAS& blend, const eeFloat& lineWidth, const eeUint& Corners) {
if ( 0 != Corners ) {
DrawRoundedRectangle( x, y, width, height, TopLeft, BottomLeft, BottomRight, TopRight, Angle, Scale, fillmode, blend, lineWidth, Corners );
return;
}
BR->SetTexture( 0 );
BR->SetBlendFunc( blend );
switch(fillmode) {
case DRAW_FILL:
case DRAW_FILL: {
BR->QuadsBegin();
BR->QuadsSetColorFree( TopLeft, BottomLeft, BottomRight, TopRight );
BR->BatchQuadEx( x, y, width, height, Angle, Scale );
break;
}
case DRAW_LINE:
BR->SetLineWidth( lineWidth );
@@ -32,7 +113,7 @@ void cPrimitives::DrawRectangle(const eeFloat& x, const eeFloat& y, const eeFloa
Q.V[1].x = x, Q.V[1].y = y + height;
Q.V[2].x = x + width; Q.V[2].y = y + height;
Q.V[3].x = x + width; Q.V[3].y = y;
Q.Scale( Scale );
Q.Rotate( Angle, eeVector2f( x + width * 0.5f, y + height * 0.5f ) );
@@ -179,16 +260,28 @@ void cPrimitives::DrawPolygon(const eePolygon2f& p, const EE_FILLMODE& fillmode,
BR->Draw();
}
void cPrimitives::DrawRectangle( const eeRectf& R, const eeColorA& TopLeft, const eeColorA& BottomLeft, const eeColorA& BottomRight, const eeColorA& TopRight, const eeFloat& Angle, const eeFloat& Scale, const EE_FILLMODE& fillmode, const EE_RENDERALPHAS& blend, const eeFloat& lineWidth) {
DrawRectangle( R.Left, R.Top, R.Right - R.Left, R.Bottom - R.Top, TopLeft, BottomLeft, BottomRight, TopRight, Angle, Scale, fillmode, blend, lineWidth);
void cPrimitives::DrawRectangle( const eeRectf& R, const eeColorA& TopLeft, const eeColorA& BottomLeft, const eeColorA& BottomRight, const eeColorA& TopRight, const eeFloat& Angle, const eeFloat& Scale, const EE_FILLMODE& fillmode, const EE_RENDERALPHAS& blend, const eeFloat& lineWidth, const eeUint& Corners) {
DrawRectangle( R.Left, R.Top, R.Right - R.Left, R.Bottom - R.Top, TopLeft, BottomLeft, BottomRight, TopRight, Angle, Scale, fillmode, blend, lineWidth, Corners);
}
void cPrimitives::DrawRectangle( const eeRectf& R, const eeFloat& Angle, const eeFloat& Scale, const EE_FILLMODE& fillmode, const EE_RENDERALPHAS& blend, const eeFloat& lineWidth) {
DrawRectangle( R.Left, R.Top, R.Right - R.Left, R.Bottom - R.Top, mColor, mColor, mColor, mColor, Angle, Scale, fillmode, blend, lineWidth);
void cPrimitives::DrawRectangle( const eeRectf& R, const eeFloat& Angle, const eeFloat& Scale, const EE_FILLMODE& fillmode, const EE_RENDERALPHAS& blend, const eeFloat& lineWidth, const eeUint& Corners) {
DrawRectangle( R.Left, R.Top, R.Right - R.Left, R.Bottom - R.Top, mColor, mColor, mColor, mColor, Angle, Scale, fillmode, blend, lineWidth, Corners);
}
void cPrimitives::DrawRectangle(const eeFloat& x, const eeFloat& y, const eeFloat& width, const eeFloat& height, const eeFloat& Angle, const eeFloat& Scale, const EE_FILLMODE& fillmode, const EE_RENDERALPHAS& blend, const eeFloat& lineWidth) {
DrawRectangle(x, y, width, height, mColor, mColor, mColor, mColor, Angle, Scale, fillmode, blend, lineWidth);
void cPrimitives::DrawRectangle(const eeFloat& x, const eeFloat& y, const eeFloat& width, const eeFloat& height, const eeFloat& Angle, const eeFloat& Scale, const EE_FILLMODE& fillmode, const EE_RENDERALPHAS& blend, const eeFloat& lineWidth, const eeUint& Corners) {
DrawRectangle(x, y, width, height, mColor, mColor, mColor, mColor, Angle, Scale, fillmode, blend, lineWidth, Corners);
}
void cPrimitives::DrawRoundedRectangle( const eeRectf& R, const eeColorA& TopLeft, const eeColorA& BottomLeft, const eeColorA& BottomRight, const eeColorA& TopRight, const eeFloat& Angle, const eeFloat& Scale, const EE_FILLMODE& fillmode, const EE_RENDERALPHAS& blend, const eeFloat& lineWidth, const eeUint& Corners ) {
DrawRoundedRectangle( R.Left, R.Top, R.Right - R.Left, R.Bottom - R.Top, TopLeft, BottomLeft, BottomRight, TopRight, Angle, Scale, fillmode, blend, lineWidth, Corners);
}
void cPrimitives::DrawRoundedRectangle( const eeRectf& R, const eeFloat& Angle, const eeFloat& Scale, const EE_FILLMODE& fillmode, const EE_RENDERALPHAS& blend, const eeFloat& lineWidth, const eeUint& Corners) {
DrawRoundedRectangle( R.Left, R.Top, R.Right - R.Left, R.Bottom - R.Top, mColor, mColor, mColor, mColor, Angle, Scale, fillmode, blend, lineWidth, Corners);
}
void cPrimitives::DrawRoundedRectangle(const eeFloat& x, const eeFloat& y, const eeFloat& width, const eeFloat& height, const eeFloat& Angle, const eeFloat& Scale, const EE_FILLMODE& fillmode, const EE_RENDERALPHAS& blend, const eeFloat& lineWidth, const eeUint& Corners ) {
DrawRoundedRectangle(x, y, width, height, mColor, mColor, mColor, mColor, Angle, Scale, fillmode, blend, lineWidth, Corners);
}
void cPrimitives::DrawLine(const eeVector2f& p1, const eeVector2f& p2, const eeFloat& lineWidth) {

View File

@@ -112,7 +112,7 @@ class EE_API cPrimitives {
* @param lineWidth The line width ( default 1.0f )
*/
void DrawTriangle(const eeVector2f& p1, const eeVector2f& p2, const eeVector2f& p3, const EE_FILLMODE& fillmode = DRAW_FILL, const EE_RENDERALPHAS& blend = ALPHA_NORMAL, const eeFloat& lineWidth = 1.0f);
/** Draw a triangle on the screen
* @param t The Triangle (eeTriangle2f)
* @param fillmode Draw filled or only lines
@@ -120,7 +120,7 @@ class EE_API cPrimitives {
* @param lineWidth The line width ( default 1.0f )
*/
void DrawTriangle(const eeTriangle2f& t, const EE_FILLMODE& fillmode = DRAW_FILL, const EE_RENDERALPHAS& blend = ALPHA_NORMAL, const eeFloat& lineWidth = 1.0f);
/** Draw a triangle on the screen
* @param t The Triangle (eeTriangle2f)
* @param Color1 First Point Color
@@ -131,7 +131,7 @@ class EE_API cPrimitives {
* @param lineWidth The line width ( default 1.0f )
*/
void DrawTriangle(const eeTriangle2f& t, const eeColorA& Color1, const eeColorA& Color2, const eeColorA& Color3, const EE_FILLMODE& fillmode = DRAW_FILL, const EE_RENDERALPHAS& blend = ALPHA_NORMAL, const eeFloat& lineWidth = 1.0f);
/** Draw a rectangle on the screen
* @param x Screen x axis
* @param y Screen y axis
@@ -143,7 +143,9 @@ class EE_API cPrimitives {
* @param blend The Blend Mode
* @param lineWidth The line width ( default 1.0f )
*/
void DrawRectangle(const eeFloat& x, const eeFloat& y, const eeFloat& width, const eeFloat& height, const eeFloat& Angle = 0, const eeFloat& Scale = 1, const EE_FILLMODE& fillmode = DRAW_FILL, const EE_RENDERALPHAS& blend = ALPHA_NORMAL, const eeFloat& lineWidth = 1.0f);
void DrawRectangle(const eeFloat& x, const eeFloat& y, const eeFloat& width, const eeFloat& height, const eeFloat& Angle = 0, const eeFloat& Scale = 1, const EE_FILLMODE& fillmode = DRAW_FILL, const EE_RENDERALPHAS& blend = ALPHA_NORMAL, const eeFloat& lineWidth = 1.0f, const eeUint& Corners = 0 );
void DrawRoundedRectangle(const eeFloat& x, const eeFloat& y, const eeFloat& width, const eeFloat& height, const eeFloat& Angle = 0, const eeFloat& Scale = 1, const EE_FILLMODE& fillmode = DRAW_FILL, const EE_RENDERALPHAS& blend = ALPHA_NORMAL, const eeFloat& lineWidth = 1.0f, const eeUint& Corners = 8 );
/** Draw a rectangle on the screen
* @param x Screen x axis
@@ -160,8 +162,10 @@ class EE_API cPrimitives {
* @param blend The Blend Mode
* @param lineWidth The line width ( default 1.0f )
*/
void DrawRectangle(const eeFloat& x, const eeFloat& y, const eeFloat& width, const eeFloat& height, const eeColorA& TopLeft, const eeColorA& BottomLeft, const eeColorA& BottomRight, const eeColorA& TopRight, const eeFloat& Angle = 0, const eeFloat& Scale = 1, const EE_FILLMODE& fillmode = DRAW_FILL, const EE_RENDERALPHAS& blend = ALPHA_NORMAL, const eeFloat& lineWidth = 1.0f);
void DrawRectangle(const eeFloat& x, const eeFloat& y, const eeFloat& width, const eeFloat& height, const eeColorA& TopLeft, const eeColorA& BottomLeft, const eeColorA& BottomRight, const eeColorA& TopRight, const eeFloat& Angle = 0, const eeFloat& Scale = 1, const EE_FILLMODE& fillmode = DRAW_FILL, const EE_RENDERALPHAS& blend = ALPHA_NORMAL, const eeFloat& lineWidth = 1.0f, const eeUint& Corners = 0 );
void DrawRoundedRectangle(const eeFloat& x, const eeFloat& y, const eeFloat& width, const eeFloat& height, const eeColorA& TopLeft, const eeColorA& BottomLeft, const eeColorA& BottomRight, const eeColorA& TopRight, const eeFloat& Angle = 0, const eeFloat& Scale = 1, const EE_FILLMODE& fillmode = DRAW_FILL, const EE_RENDERALPHAS& blend = ALPHA_NORMAL, const eeFloat& lineWidth = 1.0f, const eeUint& Corners = 8 );
/** Draw a rectangle on the screen
* @param R The Rectangle eeRectf
* @param Angle Rectangle Angle
@@ -170,8 +174,10 @@ class EE_API cPrimitives {
* @param blend The Blend Mode
* @param lineWidth The line width ( default 1.0f )
*/
void DrawRectangle( const eeRectf& R, const eeFloat& Angle = 0, const eeFloat& Scale = 1, const EE_FILLMODE& fillmode = DRAW_FILL, const EE_RENDERALPHAS& blend = ALPHA_NORMAL, const eeFloat& lineWidth = 1.0f);
void DrawRectangle( const eeRectf& R, const eeFloat& Angle = 0, const eeFloat& Scale = 1, const EE_FILLMODE& fillmode = DRAW_FILL, const EE_RENDERALPHAS& blend = ALPHA_NORMAL, const eeFloat& lineWidth = 1.0f, const eeUint& Corners = 0 );
void DrawRoundedRectangle( const eeRectf& R, const eeFloat& Angle = 0, const eeFloat& Scale = 1, const EE_FILLMODE& fillmode = DRAW_FILL, const EE_RENDERALPHAS& blend = ALPHA_NORMAL, const eeFloat& lineWidth = 1.0f, const eeUint& Corners = 8 );
/** Draw a rectangle on the screen
* @param R The Rectangle eeRectf
* @param TopLeft The Top Left Rectangle Color
@@ -184,8 +190,10 @@ class EE_API cPrimitives {
* @param blend The Blend Mode
* @param lineWidth The line width ( default 1.0f )
*/
void DrawRectangle( const eeRectf& R, const eeColorA& TopLeft, const eeColorA& BottomLeft, const eeColorA& BottomRight, const eeColorA& TopRight, const eeFloat& Angle = 0, const eeFloat& Scale = 1, const EE_FILLMODE& fillmode = DRAW_FILL, const EE_RENDERALPHAS& blend = ALPHA_NORMAL, const eeFloat& lineWidth = 1.0f);
void DrawRectangle( const eeRectf& R, const eeColorA& TopLeft, const eeColorA& BottomLeft, const eeColorA& BottomRight, const eeColorA& TopRight, const eeFloat& Angle = 0, const eeFloat& Scale = 1, const EE_FILLMODE& fillmode = DRAW_FILL, const EE_RENDERALPHAS& blend = ALPHA_NORMAL, const eeFloat& lineWidth = 1.0f, const eeUint& Corners = 0 );
void DrawRoundedRectangle( const eeRectf& R, const eeColorA& TopLeft, const eeColorA& BottomLeft, const eeColorA& BottomRight, const eeColorA& TopRight, const eeFloat& Angle = 0, const eeFloat& Scale = 1, const EE_FILLMODE& fillmode = DRAW_FILL, const EE_RENDERALPHAS& blend = ALPHA_NORMAL, const eeFloat& lineWidth = 1.0f, const eeUint& Corners = 8 );
/** Draw a four edges polygon on screen
* @param x1 First Point x axis
* @param y1 First Point y axis
@@ -245,7 +253,7 @@ class EE_API cPrimitives {
* @param lineWidth The line width ( default 1.0f )
*/
void DrawQuad(const eeVector2f& p1, const eeVector2f& p2, const eeVector2f& p3, const eeVector2f& p4, const EE_FILLMODE& fillmode = DRAW_FILL, const EE_RENDERALPHAS& blend = ALPHA_NORMAL, const eeFloat& lineWidth = 1.0f, const eeFloat& OffsetX = 0, const eeFloat& OffsetY = 0);
/** Draw a four edges polygon on screen
* @param q The Quad
* @param fillmode Draw filled or only lines
@@ -253,7 +261,7 @@ class EE_API cPrimitives {
* @param lineWidth The line width ( default 1.0f )
*/
void DrawQuad(const eeQuad2f& q, const EE_FILLMODE& fillmode = DRAW_FILL, const EE_RENDERALPHAS& blend = ALPHA_NORMAL, const eeFloat& lineWidth = 1.0f, const eeFloat& OffsetX = 0, const eeFloat& OffsetY = 0);
/** Draw a polygon on screen
* @param p The Polygon
* @param fillmode Draw filled or only lines
@@ -261,13 +269,13 @@ class EE_API cPrimitives {
* @param lineWidth The line width ( default 1.0f )
*/
void DrawPolygon(const eePolygon2f& p, const EE_FILLMODE& fillmode = DRAW_FILL, const EE_RENDERALPHAS& blend = ALPHA_NORMAL, const eeFloat& lineWidth = 1.0f);
/** Set the current color for drawing primitives */
void SetColor( const eeColorA& Color );
private:
cTextureFactory* TF;
eeColorA mColor;
cGlobalBatchRenderer* BR;
};

View File

@@ -48,18 +48,16 @@ cShaderProgram::~cShaderProgram() {
mUniformLocations.clear();
mAttributeLocations.clear();
RemoveFromManager();
}
void cShaderProgram::AddToManager( const std::string& name ) {
Name( name );
cShaderProgramManager::Instance()->Add( this );
cShaderProgramManager::instance()->Add( this );
}
void cShaderProgram::RemoveFromManager() {
cShaderProgramManager::Instance()->Remove( this );
cShaderProgramManager::instance()->Remove( this );
}
void cShaderProgram::Init() {

View File

@@ -11,7 +11,7 @@ cShaderProgramManager::~cShaderProgramManager()
std::map<std::string, cShaderProgram*>::iterator it;
for ( it = mShaders.begin(); it != mShaders.end(); it++ )
delete it->second;
Remove( it->second );
}
void cShaderProgramManager::Add( cShaderProgram * ShaderProgram ) {

View File

@@ -7,7 +7,11 @@
#include "../utils/polygon2.hpp"
#include "../utils/colors.hpp"
#include "../utils/utils.hpp"
#include "../utils/size.hpp"
#include "../utils/line2.hpp"
#include "../utils/triangle2.hpp"
#include "../utils/quad2.hpp"
using namespace EE::Utils;
#endif
#endif

View File

@@ -301,6 +301,59 @@ bool IntersectPolygon2( const Polygon2<T>& p0, const Polygon2<T>& p1 ) {
return true;
}
template<typename T>
Polygon2<T> CreateRoundedPolygon( const T& x, const T& y, const T& width, const T& height, const eeUint& Radius = 8 ) {
eeFloat PI05 = PI * 0.5f;
eeFloat PI15 = PI * 1.5f;
eeFloat PI20 = PI * 2.0f;
eeFloat sx, sy;
eeFloat t;
Polygon2<T> Poly;
Poly.PushBack( Vector2<T>( x, y + height - Radius) );
Poly.PushBack( Vector2<T>( x, y + Radius ) );
for( t = PI; t < PI15; t += 0.1f ) {
sx = x + Radius + (eeFloat)cosf(t) * Radius;
sy = y + Radius + (eeFloat)sinf(t) * Radius;
Poly.PushBack( Vector2<T> (sx, sy) );
}
Poly.PushBack( Vector2<T>( x + Radius, y ) );
Poly.PushBack( Vector2<T>( x + width - Radius, y ) );
for( t = PI15; t < PI20; t += 0.1f ) {
sx = x + width - Radius + (eeFloat)cosf(t) * Radius;
sy = y + Radius + (eeFloat)sinf(t) * Radius;
Poly.PushBack( Vector2<T> (sx, sy) );
}
Poly.PushBack( Vector2<T> ( x + width, y + Radius ) );
Poly.PushBack( Vector2<T> ( x + width, y + height - Radius ) );
for( t = 0; t < PI05; t += 0.1f ){
sx = x + width - Radius + (eeFloat)cosf(t) * Radius;
sy = y + height -Radius + (eeFloat)sinf(t) * Radius;
Poly.PushBack( Vector2<T> (sx, sy) );
}
Poly.PushBack( Vector2<T> ( x + width - Radius, y + height ) );
Poly.PushBack( Vector2<T> ( x + Radius, y + height ) );
for( t = PI05; t < PI; t += 0.1f ) {
sx = x + Radius + (eeFloat)cosf(t) * Radius;
sy = y + height - Radius + (eeFloat)sinf(t) * Radius;
Poly.PushBack( Vector2<T> (sx, sy) );
}
return Poly;
}
/* A very fast function to calculate the approximate inverse square root of a
* floating point value and a helper function that uses it for getting the
* normal squareroot. For an explanation of the inverse squareroot function

View File

@@ -11,10 +11,31 @@
class cUITest : public cUIControlAnim {
public:
cUITest( cUIControlAnim::CreateParams& Params ) : cUIControlAnim( Params ) { mOldColor = mBackground.Color(); }
cUITest( cUIControlAnim::CreateParams& Params ) : cUIControlAnim( Params ) { mOldColor = mBackground.Colors(); }
virtual Uint32 OnMouseEnter( const eeVector2i& Pos, const Uint32 Flags ) { mBackground.Color( eeColorA( mOldColor.R(), mOldColor.G(), mOldColor.B(), 200 ) ); return 1; }
virtual Uint32 OnMouseExit( const eeVector2i& Pos, const Uint32 Flags ) { mBackground.Color( mOldColor ); return 1; }
virtual Uint32 OnMouseEnter( const eeVector2i& Pos, const Uint32 Flags ) {
if ( 4 == mOldColor.size() ) {
mBackground.Colors( eeColorA( mOldColor[0].R(), mOldColor[0].G(), mOldColor[0].B(), 200 ),
eeColorA( mOldColor[1].R(), mOldColor[1].G(), mOldColor[1].B(), 200 ),
eeColorA( mOldColor[2].R(), mOldColor[2].G(), mOldColor[2].B(), 200 ),
eeColorA( mOldColor[3].R(), mOldColor[3].G(), mOldColor[3].B(), 200 )
);
} else {
mBackground.Color( eeColorA( mOldColor[0].R(), mOldColor[0].G(), mOldColor[0].B(), 200 ) );
}
return 1;
}
virtual Uint32 OnMouseExit( const eeVector2i& Pos, const Uint32 Flags ) {
if ( 4 == mOldColor.size() ) {
mBackground.Colors( mOldColor[0], mOldColor[1], mOldColor[2], mOldColor[3] );
} else {
mBackground.Color( mOldColor[0] );
}
return 1;
}
virtual Uint32 OnMouseUp( const eeVector2i& Pos, const Uint32 Flags ) {
cUIDragable::OnMouseUp( Pos, Flags );
@@ -27,11 +48,12 @@ class cUITest : public cUIControlAnim {
return 1;
}
const eeColorA& OldColor() { return mOldColor; }
const std::vector<eeColorA>& OldColor() { return mOldColor; }
protected:
eeColorA mOldColor;
std::vector<eeColorA> mOldColor;
};
class cEETest : private cThread {
public:
typedef boost::function0<void> SceneCb;
@@ -177,6 +199,7 @@ void cEETest::Init() {
mUseShaders = Ini.GetValueB( "EEPP", "UseShaders", false );
run = EE->Init(mWidth, mHeight, BitColor, Windowed, Resizeable, VSync);
PAK.Open( MyPath + "data/ee.pak" );
run = ( run && PAK.IsOpen() );
@@ -239,11 +262,12 @@ void cEETest::Init() {
cUIManager::instance()->Init();
cUIControl::CreateParams Params( cUIManager::instance()->MainControl(), eeVector2i(0,0), eeSize( 320, 240 ), UI_FILL_BACKGROUND );
cUIControl::CreateParams Params( cUIManager::instance()->MainControl(), eeVector2i(0,0), eeSize( 320, 240 ), UI_FILL_BACKGROUND | UI_CLIP_ENABLE | UI_BORDER );
Params.Flags |= UI_CLIP_ENABLE;
Params.Background.Color( eeColorA( 0x66CC0000 ) );
Params.Border.Width( 2.f );
Params.Border.Color( 0xFF979797 );
Params.Background.Corners(5);
Params.Background.Colors( eeColorA( 0x66FAFAFA ), eeColorA( 0xCCFAFAFA ), eeColorA( 0xCCFAFAFA ), eeColorA( 0x66FAFAFA ) );
cUIControlAnim * C = new cUITest( Params );
C->Visible( true );
C->Enabled( true );
@@ -252,7 +276,8 @@ void cEETest::Init() {
C->StartRotation( 0.f, 360.f, 2500.f );
Params.Flags &= ~UI_CLIP_ENABLE;
Params.Background.Color( eeColorA( 0x7700FF00 ) );
Params.Background.Corners(0);
Params.Background.Colors( eeColorA( 0x7700FF00 ), eeColorA( 0x7700CC00 ), eeColorA( 0x7700CC00 ), eeColorA( 0x7700FF00 ) );
Params.Parent( C );
Params.Size = eeSize( 50, 50 );
cUITest * Child = new cUITest( Params );
@@ -261,7 +286,7 @@ void cEETest::Init() {
Child->Enabled( true );
Child->StartRotation( 0.f, 360.f * 10.f, 5000.f * 10.f );
Params.Background.Color( eeColorA( 0x77FFFF00 ) );
Params.Background.Colors( eeColorA( 0x77FFFF00 ), eeColorA( 0x77CCCC00 ), eeColorA( 0x77CCCC00 ), eeColorA( 0x77FFFF00 ) );
Params.Parent( Child );
Params.Size = eeSize( 25, 25 );
cUITest * Child2 = new cUITest( Params );
@@ -270,17 +295,6 @@ void cEETest::Init() {
Child2->Enabled( true );
Child2->StartRotation( 0.f, 360.f * 10.f, 5000.f * 10.f );
cUIControl::CreateParams Params2;
Params2.Flags = UI_FILL_BACKGROUND | UI_BORDER;
Params2.Background.Color( eeColorA( 0x770000FF ) );
Params2.Border.Width( 4 );
Params2.Parent( C );
Params2.PosSet( 320 - 25, 240 - 45 );
Params2.Size = eeSize( 50, 50 );
cUITest * Ctrl = new cUITest( Params2 );
Ctrl->Visible( true );
Ctrl->Enabled( true );
cUIGfx::CreateParams GfxParams;
GfxParams.Parent( C );
GfxParams.PosSet( 160, 100 );
@@ -295,15 +309,6 @@ void cEETest::Init() {
Gfx->AlphaInterpolation()->Loop( true );
Gfx->AlphaInterpolation()->SetTotalTime( 1000.f );
Params2.Parent( Gfx );
Params2.PosSet( -25, -25 );
Params2.Size = eeSize( 50, 50 );
Params2.Background.Color( eeColorA( 0x7700F0FF ) );
Params2.Flags &= ~UI_BORDER;
Ctrl = new cUITest( Params2 );
Ctrl->Visible( true );
Ctrl->Enabled( true );
cUITextBox::CreateParams TextParams;
TextParams.Parent( C );
TextParams.PosSet( 0, 0 );
@@ -317,10 +322,12 @@ void cEETest::Init() {
cUITextInput::CreateParams InputParams;
InputParams.Parent( C );
InputParams.Background.Color( eeColorA( 0x7744FF00 ) );
InputParams.PosSet( 0, 220 );
InputParams.Size = eeSize( 320, 20 );
InputParams.Flags = UI_VALIGN_CENTER | UI_HALIGN_LEFT | UI_FILL_BACKGROUND | UI_CLIP_ENABLE;
InputParams.Background.Corners(6);
InputParams.Border.Color(0xFF979797);
InputParams.Background.Colors( eeColorA(0x99AAAAAA), eeColorA(0x99CCCCCC), eeColorA(0x99CCCCCC), eeColorA(0x99AAAAAA) );
InputParams.PosSet( 10, 220 );
InputParams.Size = eeSize( 300, 18 );
InputParams.Flags = UI_VALIGN_CENTER | UI_HALIGN_LEFT | UI_FILL_BACKGROUND | UI_CLIP_ENABLE | UI_BORDER;
InputParams.Font = &TTF;
InputParams.SupportNewLine = false;
cUITextInput * Input = new cUITextInput( InputParams );
@@ -658,11 +665,6 @@ void cEETest::Screen3() {
Batch.BatchLineLoop( HWidth + 350 * sinAng(j), HHeight + 350 * cosAng(j), HWidth + AnimVal * sinAng(j+1), HHeight + AnimVal * cosAng(j+1) );
}
Batch.Draw();
#ifdef EE_SHADERS
if ( mUseShaders )
mBlurFactor = ( ( scale - 1.0f ) * 0.5f );
#endif
}
void cEETest::Render() {
@@ -704,8 +706,19 @@ void cEETest::Render() {
TTF.SetText( L"Entropia Engine++\nEE++ Support TTF Fonts and they look beautifull. :)\nCTRL + 1 = Screen 1 - CTRL + 2 = Screen 2" );
eeColorA ColRR1( 150, 150, 150, 220 );
eeColorA ColRR4( 150, 150, 150, 220 );
eeColorA ColRR2( 100, 100, 100, 220 );
eeColorA ColRR3( 100, 100, 100, 220 );
PR.SetColor( eeColorA(150, 150, 150, 220) );
PR.DrawRectangle( 0.f, (eeFloat)EE->GetHeight() - (eeFloat)TTF.GetNumLines() * (eeFloat)TTF.GetFontSize(), (eeFloat)TTF.GetTextWidth(), (eeFloat)TTF.GetNumLines() * (eeFloat)TTF.GetFontSize() );
PR.DrawRectangle(
0.f,
(eeFloat)EE->GetHeight() - (eeFloat)TTF.GetNumLines() * (eeFloat)TTF.GetFontSize(),
(eeFloat)TTF.GetTextWidth(),
(eeFloat)TTF.GetNumLines() * (eeFloat)TTF.GetFontSize(),
ColRR1, ColRR2, ColRR3, ColRR4
);
TTF.Draw( 0.f, (eeFloat)EE->GetHeight() - TTF.GetTextHeight(), FONT_DRAW_CENTER, 1.f, Ang );
@@ -724,17 +737,17 @@ void cEETest::Render() {
FF2.Draw( L"_", 6.f + FF2.GetTextWidth(), 24.f + (eeFloat)LineNum * (eeFloat)FF2.GetFontSize() );
}
cUIManager::instance()->Update();
cUIManager::instance()->Draw();
TTF.SetText( mBuda );
TTF.Draw( 0.f, 50.f );
Con.Draw();
FF2.SetText( L"FPS: " + toWStr( EE->FPS() ) );
FF2.Draw( EE->GetWidth() - FF2.GetTextWidth() - 15, 0 );
cUIManager::instance()->Update();
cUIManager::instance()->Draw();
Con.Draw();
if ( Screen < 2 )
TF->Draw( Cursor[ Screen ], Mousef.x, Mousef.y );
}

View File

@@ -2,24 +2,72 @@
namespace EE { namespace UI {
cUIBackground::cUIBackground() :
mColor( 0xFF404040 ),
mBlendMode( ALPHA_NORMAL )
cUIBackground::cUIBackground() :
mBlendMode( ALPHA_NORMAL ),
mCorners(0)
{
mColor.push_back( eeColorA(0xFF404040) );
}
cUIBackground::cUIBackground( const cUIBackground& Back ) :
mColor( Back.Color() ),
mBlendMode( ALPHA_NORMAL )
cUIBackground::cUIBackground( const cUIBackground& Back ) :
mBlendMode( ALPHA_NORMAL ),
mCorners( Back.Corners() )
{
cUIBackground * b = const_cast<cUIBackground *> ( &Back ); // cheating
mColor = b->Colors();
}
const eeColorA& cUIBackground::Color() const {
cUIBackground::cUIBackground( const eeColorA& Color, const eeUint& Corners, const EE_RENDERALPHAS& BlendMode ) :
mBlendMode( BlendMode ),
mCorners( Corners )
{
mColor.push_back( Color );
}
cUIBackground::cUIBackground( const eeColorA& TopLeftColor, const eeColorA& BottomLeftColor, const eeColorA& BottomRightColor, const eeColorA& TopRightColor, const eeUint& Corners, const EE_RENDERALPHAS& BlendMode ) :
mBlendMode( BlendMode ),
mCorners( Corners )
{
Colors( TopLeftColor, BottomLeftColor, BottomRightColor, TopRightColor );
}
eeColorA& cUIBackground::Color( const eeUint& index ) {
if ( index < mColor.size() )
return mColor[ index ];
return mColor[ 0 ];
}
void cUIBackground::ColorsTo( const eeColorA& Color ) {
for ( eeUint i = 0; i < mColor.size(); i++ )
mColor[i] = Color;
}
void cUIBackground::Colors( const eeColorA& TopLeftColor, const eeColorA& BottomLeftColor, const eeColorA& BottomRightColor, const eeColorA& TopRightColor ) {
mColor[0] = TopLeftColor;
if ( mColor.size() < 2 )
mColor.push_back( BottomLeftColor );
else
mColor[1] = BottomLeftColor;
if ( mColor.size() < 3 )
mColor.push_back( BottomRightColor );
else
mColor[2] = BottomRightColor;
if ( mColor.size() < 4 )
mColor.push_back( TopRightColor );
else
mColor[3] = TopRightColor;
}
const std::vector<eeColorA>& cUIBackground::Colors() {
return mColor;
}
void cUIBackground::Color( const eeColorA& Col ) {
mColor = Col;
mColor[0] = Col;
}
const EE_RENDERALPHAS& cUIBackground::Blend() const {
@@ -30,4 +78,12 @@ void cUIBackground::Blend( const EE_RENDERALPHAS& blend ) {
mBlendMode = blend;
}
const eeUint& cUIBackground::Corners() const {
return mCorners;
}
void cUIBackground::Corners( const eeUint& corners ) {
mCorners = corners;
}
}}

View File

@@ -4,22 +4,36 @@
#include "base.hpp"
namespace EE { namespace UI {
class cUIBackground {
public:
cUIBackground();
cUIBackground( const eeColorA& Color, const eeUint& Corners = 0, const EE_RENDERALPHAS& BlendMode = ALPHA_NORMAL );
cUIBackground( const cUIBackground& Back );
cUIBackground( const eeColorA& TopLeftColor, const eeColorA& BottomLeftColor, const eeColorA& BottomRightColor, const eeColorA& TopRightColor, const eeUint& Corners, const EE_RENDERALPHAS& BlendMode );
eeColorA& Color( const eeUint& index = 0 );
const eeColorA& Color() const;
void Color( const eeColorA& Col );
const std::vector<eeColorA>& Colors();
void Colors( const eeColorA& TopLeftColor, const eeColorA& BottomLeftColor, const eeColorA& BottomRightColor, const eeColorA& TopRightColor );
void ColorsTo( const eeColorA& Color );
const EE_RENDERALPHAS& Blend() const;
void Blend( const EE_RENDERALPHAS& blend );
const eeUint& Corners() const;
void Corners( const eeUint& corners );
protected:
eeColorA mColor;
EE_RENDERALPHAS mBlendMode;
std::vector<eeColorA> mColor;
EE_RENDERALPHAS mBlendMode;
eeUint mCorners;
};
}}
#endif
#endif

View File

@@ -405,7 +405,12 @@ void cUIControl::BackgroundDraw() {
cPrimitives P;
P.SetColor( mBackground.Color() );
P.DrawRectangle( (eeFloat)Pos.x, (eeFloat)Pos.y, (eeFloat)mSize.Width(), (eeFloat)mSize.Height(), 0.f, 1.f, DRAW_FILL, mBackground.Blend() );
if ( 4 == mBackground.Colors().size() ) {
P.DrawRectangle( (eeFloat)Pos.x, (eeFloat)Pos.y, (eeFloat)mSize.Width(), (eeFloat)mSize.Height(), mBackground.Colors()[0], mBackground.Colors()[1], mBackground.Colors()[2], mBackground.Colors()[3], 0.f, 1.f, DRAW_FILL, mBackground.Blend(), 1.0f, mBackground.Corners() );
} else {
P.DrawRectangle( (eeFloat)Pos.x, (eeFloat)Pos.y, (eeFloat)mSize.Width(), (eeFloat)mSize.Height(), 0.f, 1.f, DRAW_FILL, mBackground.Blend(), 1.0f, mBackground.Corners() );
}
}
void cUIControl::BorderDraw() {
@@ -414,7 +419,7 @@ void cUIControl::BorderDraw() {
cPrimitives P;
P.SetColor( mBorder.Color() );
P.DrawRectangle( (eeFloat)Pos.x, (eeFloat)Pos.y, (eeFloat)mSize.Width(), (eeFloat)mSize.Height(), 0.f, 1.f, DRAW_LINE, mBlend, (eeFloat)mBorder.Width() );
P.DrawRectangle( (eeFloat)Pos.x, (eeFloat)Pos.y, (eeFloat)mSize.Width(), (eeFloat)mSize.Height(), 0.f, 1.f, DRAW_LINE, mBlend, (eeFloat)mBorder.Width(), mBackground.Corners() );
}
const Uint32& cUIControl::ControlFlags() const {

View File

@@ -25,14 +25,19 @@ class EE_API cUIControl {
const eeVector2i& pos = eeVector2i( 0, 0 ),
const eeSize& size = eeSize( -1, -1 ),
const Uint32& flags = UI_HALIGN_LEFT | UI_VALIGN_CENTER,
const EE_RENDERALPHAS& blend = ALPHA_NORMAL
const EE_RENDERALPHAS& blend = ALPHA_NORMAL,
const cUIBackground& Back = cUIBackground(),
const cUIBorder& Bord = cUIBorder()
) :
ParentCtrl( parentCtrl ),
Pos( pos ),
Size( size ),
Flags( flags ),
Blend( blend )
{}
{
Background = Back;
Border = Bord;
}
CreateParams() {
ParentCtrl = NULL;

View File

@@ -204,7 +204,12 @@ void cUIControlAnim::BackgroundDraw() {
cPrimitives P;
P.SetColor( GetColor( mBackground.Color() ) );
P.DrawRectangle( (eeFloat)Pos.x, (eeFloat)Pos.y, (eeFloat)mSize.Width(), (eeFloat)mSize.Height(), 0.f, 1.f, DRAW_FILL, mBackground.Blend() );
if ( 4 == mBackground.Colors().size() ) {
P.DrawRectangle( (eeFloat)Pos.x, (eeFloat)Pos.y, (eeFloat)mSize.Width(), (eeFloat)mSize.Height(), GetColor( mBackground.Colors()[0] ), GetColor( mBackground.Colors()[1] ), GetColor( mBackground.Colors()[2] ), GetColor( mBackground.Colors()[3] ), 0.f, 1.f, DRAW_FILL, mBackground.Blend(), 1.0f, mBackground.Corners() );
} else {
P.DrawRectangle( (eeFloat)Pos.x, (eeFloat)Pos.y, (eeFloat)mSize.Width(), (eeFloat)mSize.Height(), 0.f, 1.f, DRAW_FILL, mBackground.Blend(), 1.0f, mBackground.Corners() );
}
}
void cUIControlAnim::BorderDraw() {
@@ -213,7 +218,7 @@ void cUIControlAnim::BorderDraw() {
cPrimitives P;
P.SetColor( GetColor( mBorder.Color() ) );
P.DrawRectangle( (eeFloat)Pos.x, (eeFloat)Pos.y, (eeFloat)mSize.Width(), (eeFloat)mSize.Height(), 0.f, 1.f, DRAW_LINE, mBlend, (eeFloat)mBorder.Width() );
P.DrawRectangle( (eeFloat)Pos.x, (eeFloat)Pos.y, (eeFloat)mSize.Width(), (eeFloat)mSize.Height(), 0.f, 1.f, DRAW_LINE, mBlend, (eeFloat)mBorder.Width(), mBackground.Corners() );
}
eeColorA cUIControlAnim::GetColor( const eeColorA& Col ) {

39
src/utils/line2.hpp Normal file
View File

@@ -0,0 +1,39 @@
#ifndef EE_UTILSLINE2_HPP
#define EE_UTILSLINE2_HPP
namespace EE { namespace Utils {
template <typename T>
class Line2 {
public:
Line2();
Line2( const Vector2<T>& v1, const Vector2<T>& v2 );
Vector2<T> V[2];
Vector2<T> GetNormal();
};
template <typename T>
Line2<T>::Line2() {
V[0] = Vector2<T>();
V[1] = Vector2<T>();
}
template <typename T>
Line2<T>::Line2( const Vector2<T>& v1, const Vector2<T>& v2 ) {
V[0] = v1;
V[1] = v2;
}
template <typename T>
Vector2<T> Line2<T>::GetNormal() {
Vector2<T> tV = Vector2<T>( -(V[1].y - V[0].y) , V[1].x - V[0].x );
tV.Normalize();
return tV;
}
typedef Line2<eeFloat> eeLine2f;
}}
#endif

View File

@@ -1,6 +1,9 @@
#ifndef EE_UTILSPOLIGON2_H
#define EE_UTILSPOLIGON2_H
#include "triangle2.hpp"
#include "quad2.hpp"
namespace EE { namespace Utils {
template <typename T>
@@ -28,6 +31,8 @@ class Polygon2 {
void Position( const Vector2<T>& V ) { cOffsetX = V.x; cOffsetY = V.y; }
T X( const T& x ) { cOffsetX = x; }
T Y( const T& y ) { cOffsetY = y; }
void Rotate( const T& Angle, const Vector2<T>& Center );
private:
std::deque< Vector2<T> > Vector;
T cOffsetX, cOffsetY;
@@ -89,6 +94,15 @@ std::size_t Polygon2<T>::Size() const {
return Vector.size();
}
template <typename T>
void Polygon2<T>::Rotate( const T& Angle, const Vector2<T>& Center ) {
if ( Angle == 0.f )
return;
for ( eeUint i = 0; i < Vector.size(); i++ )
Vector[ i ].RotateVectorCentered( Angle, Center );
}
typedef Polygon2<eeFloat> eePolygon2f;
}}

108
src/utils/quad2.hpp Normal file
View File

@@ -0,0 +1,108 @@
#ifndef EE_UTILSQUAD2_HPP
#define EE_UTILSQUAD2_HPP
namespace EE { namespace Utils {
template <typename T>
class Quad2 {
public:
Quad2();
Quad2( const Vector2<T>& v1, const Vector2<T>& v2, const Vector2<T>& v3, const Vector2<T>& v4 );
const Vector2<T>& operator[] ( const Uint32& Pos ) const;
Vector2<T> V[4];
/**
Vector2<T> V[0]; //! Left - Top Vector
Vector2<T> V[1]; //! Left - Bottom Vector
Vector2<T> V[2]; //! Right - Bottom Vertex
Vector2<T> V[3]; //! Right - Top Vertex
*/
Vector2<T> GetCenter();
void Rotate( const T& Angle, const Vector2<T>& Center );
void Rotate( const T& Angle );
void Scale( const eeFloat& scale );
void Scale( const eeFloat& scale, const Vector2<T>& Center );
};
template <typename T>
void Quad2<T>::Rotate( const T& Angle ) {
Rotate( Angle, GetCenter() );
}
template <typename T>
void Quad2<T>::Rotate( const T& Angle, const Vector2<T>& Center ) {
if ( Angle == 0.f )
return;
V[0].RotateVectorCentered( Angle, Center );
V[1].RotateVectorCentered( Angle, Center );
V[2].RotateVectorCentered( Angle, Center );
V[3].RotateVectorCentered( Angle, Center );
}
template <typename T>
void Quad2<T>::Scale( const eeFloat& scale, const Vector2<T>& Center ) {
if ( scale == 1.0f )
return;
for ( Uint32 i = 0; i < 4; i++ ) {
if ( V[i].x < Center.x )
V[i].x = Center.x - fabs( Center.x - V[i].x ) * scale;
else
V[i].x = Center.x + fabs( Center.x - V[i].x ) * scale;
if ( V[i].y < Center.y )
V[i].y = Center.y - fabs( Center.y - V[i].y ) * scale;
else
V[i].y = Center.y + fabs( Center.y - V[i].y ) * scale;
}
}
template <typename T>
void Quad2<T>::Scale( const eeFloat& scale ) {
Scale( scale, GetCenter() );
}
template <typename T>
Vector2<T> Quad2<T>::GetCenter() {
eeFloat MinX = V[0].x, MaxX = V[0].x, MinY = V[0].y, MaxY = V[0].y;
for (Uint8 i = 1; i < 4; i++ ) {
if ( MinX > V[i].x ) MinX = V[i].x;
if ( MaxX < V[i].x ) MaxX = V[i].x;
if ( MinY > V[i].y ) MinY = V[i].y;
if ( MaxY < V[i].y ) MaxY = V[i].y;
}
return Vector2<T>( MinX + (MaxX - MinX) * 0.5f, MinY + (MaxY - MinX) * 0.5f );
}
template <typename T>
const Vector2<T>& Quad2<T>::operator[] ( const Uint32& Pos ) const {
if ( Pos <= 3 )
return V[Pos];
return V[0];
}
template <typename T>
Quad2<T>::Quad2() {
V[0] = Vector2<T>();
V[1] = Vector2<T>();
V[2] = Vector2<T>();
V[3] = Vector2<T>();
}
template <typename T>
Quad2<T>::Quad2( const Vector2<T>& v1, const Vector2<T>& v2, const Vector2<T>& v3, const Vector2<T>& v4 ) {
V[0] = v1;
V[1] = v2;
V[2] = v3;
V[3] = v4;
}
typedef Quad2<eeFloat> eeQuad2f;
}}
#endif

View File

@@ -2,6 +2,7 @@
#define EE_UTILSCRECT_H
#include "vector2.hpp"
#include "size.hpp"
namespace EE { namespace Utils {

69
src/utils/size.hpp Normal file
View File

@@ -0,0 +1,69 @@
#ifndef EE_UTILSSIZE_HPP
#define EE_UTILSSIZE_HPP
namespace EE { namespace Utils {
template<typename T>
class tSize : public Vector2<T>
{
public:
tSize();
tSize( const T& Width, const T& Height );
tSize( const tSize<T>& Size );
tSize( const Vector2<T>& Vec );
const T& Width() const;
const T& Height() const;
void Width( const T& width );
void Height( const T& height );
};
template <typename T>
tSize<T>::tSize() {
this->x = 0;
this->y = 0;
}
template <typename T>
tSize<T>::tSize( const T& Width, const T& Height ) {
this->x = Width;
this->y = Height;
}
template <typename T>
tSize<T>::tSize( const tSize<T>& Size ) {
this->x = Size.Width();
this->y = Size.Height();
}
template <typename T>
tSize<T>::tSize( const Vector2<T>& Vec ) {
this->x = Vec.x;
this->y = Vec.y;
}
template <typename T>
const T& tSize<T>::Width() const {
return this->x;
}
template <typename T>
const T& tSize<T>::Height() const {
return this->y;
}
template <typename T>
void tSize<T>::Width( const T& width ) {
this->x = width;
}
template <typename T>
void tSize<T>::Height( const T& height ) {
this->y = height;
}
typedef tSize<eeInt> eeSize;
}}
#endif

32
src/utils/triangle2.hpp Normal file
View File

@@ -0,0 +1,32 @@
#ifndef EE_UTILSTRIANGLE2_HPP
#define EE_UTILSTRIANGLE2_HPP
namespace EE { namespace Utils {
template <typename T>
class Triangle2 {
public:
Triangle2();
Triangle2( const Vector2<T>& v1, const Vector2<T>& v2, const Vector2<T>& v3 );
Vector2<T> V[3];
};
template <typename T>
Triangle2<T>::Triangle2() {
V[0] = Vector2<T>();
V[1] = Vector2<T>();
V[2] = Vector2<T>();
}
template <typename T>
Triangle2<T>::Triangle2( const Vector2<T>& v1, const Vector2<T>& v2, const Vector2<T>& v3 ) {
V[0] = v1;
V[1] = v2;
V[2] = v3;
}
typedef Triangle2<eeFloat> eeTriangle2f;
}}
#endif

View File

@@ -205,220 +205,9 @@ T Vector2<T>::Distance( const Vector2<T>& Vec ) {
return sqrt((x - Vec.x) * (x - Vec.x) + (y - Vec.y) * (y - Vec.y));
}
template<typename T>
class tSize : public Vector2<T>
{
public:
tSize();
tSize( const T& Width, const T& Height );
tSize( const tSize<T>& Size );
tSize( const Vector2<T>& Vec );
const T& Width() const;
const T& Height() const;
void Width( const T& width );
void Height( const T& height );
};
template <typename T>
tSize<T>::tSize() {
this->x = 0;
this->y = 0;
}
template <typename T>
tSize<T>::tSize( const T& Width, const T& Height ) {
this->x = Width;
this->y = Height;
}
template <typename T>
tSize<T>::tSize( const tSize<T>& Size ) {
this->x = Size.Width();
this->y = Size.Height();
}
template <typename T>
tSize<T>::tSize( const Vector2<T>& Vec ) {
this->x = Vec.x;
this->y = Vec.y;
}
template <typename T>
const T& tSize<T>::Width() const {
return this->x;
}
template <typename T>
const T& tSize<T>::Height() const {
return this->y;
}
template <typename T>
void tSize<T>::Width( const T& width ) {
this->x = width;
}
template <typename T>
void tSize<T>::Height( const T& height ) {
this->y = height;
}
template <typename T>
class Quad2 {
public:
Quad2();
Quad2( const Vector2<T>& v1, const Vector2<T>& v2, const Vector2<T>& v3, const Vector2<T>& v4 );
const Vector2<T>& operator[] ( const Uint32& Pos ) const;
Vector2<T> V[4];
/**
Vector2<T> V[0]; //! Left - Top Vector
Vector2<T> V[1]; //! Left - Bottom Vector
Vector2<T> V[2]; //! Right - Bottom Vertex
Vector2<T> V[3]; //! Right - Top Vertex
*/
Vector2<T> GetCenter();
void Rotate( const T& Angle, const Vector2<T>& Center );
void Rotate( const T& Angle );
void Scale( const eeFloat& scale );
void Scale( const eeFloat& scale, const Vector2<T>& Center );
};
template <typename T>
void Quad2<T>::Rotate( const T& Angle ) {
Rotate( Angle, GetCenter() );
}
template <typename T>
void Quad2<T>::Rotate( const T& Angle, const Vector2<T>& Center ) {
if ( Angle == 0.f )
return;
V[0].RotateVectorCentered( Angle, Center );
V[1].RotateVectorCentered( Angle, Center );
V[2].RotateVectorCentered( Angle, Center );
V[3].RotateVectorCentered( Angle, Center );
}
template <typename T>
void Quad2<T>::Scale( const eeFloat& scale, const Vector2<T>& Center ) {
if ( scale == 1.0f )
return;
for ( Uint32 i = 0; i < 4; i++ ) {
if ( V[i].x < Center.x )
V[i].x = Center.x - fabs( Center.x - V[i].x ) * scale;
else
V[i].x = Center.x + fabs( Center.x - V[i].x ) * scale;
if ( V[i].y < Center.y )
V[i].y = Center.y - fabs( Center.y - V[i].y ) * scale;
else
V[i].y = Center.y + fabs( Center.y - V[i].y ) * scale;
}
}
template <typename T>
void Quad2<T>::Scale( const eeFloat& scale ) {
Scale( scale, GetCenter() );
}
template <typename T>
Vector2<T> Quad2<T>::GetCenter() {
eeFloat MinX = V[0].x, MaxX = V[0].x, MinY = V[0].y, MaxY = V[0].y;
for (Uint8 i = 1; i < 4; i++ ) {
if ( MinX > V[i].x ) MinX = V[i].x;
if ( MaxX < V[i].x ) MaxX = V[i].x;
if ( MinY > V[i].y ) MinY = V[i].y;
if ( MaxY < V[i].y ) MaxY = V[i].y;
}
return Vector2<T>( MinX + (MaxX - MinX) * 0.5f, MinY + (MaxY - MinX) * 0.5f );
}
template <typename T>
const Vector2<T>& Quad2<T>::operator[] ( const Uint32& Pos ) const {
if ( Pos <= 3 )
return V[Pos];
return V[0];
}
template <typename T>
Quad2<T>::Quad2() {
V[0] = Vector2<T>();
V[1] = Vector2<T>();
V[2] = Vector2<T>();
V[3] = Vector2<T>();
}
template <typename T>
Quad2<T>::Quad2( const Vector2<T>& v1, const Vector2<T>& v2, const Vector2<T>& v3, const Vector2<T>& v4 ) {
V[0] = v1;
V[1] = v2;
V[2] = v3;
V[3] = v4;
}
template <typename T>
class Triangle2 {
public:
Triangle2();
Triangle2( const Vector2<T>& v1, const Vector2<T>& v2, const Vector2<T>& v3 );
Vector2<T> V[3];
};
template <typename T>
Triangle2<T>::Triangle2() {
V[0] = Vector2<T>();
V[1] = Vector2<T>();
V[2] = Vector2<T>();
}
template <typename T>
Triangle2<T>::Triangle2( const Vector2<T>& v1, const Vector2<T>& v2, const Vector2<T>& v3 ) {
V[0] = v1;
V[1] = v2;
V[2] = v3;
}
template <typename T>
class Line2 {
public:
Line2();
Line2( const Vector2<T>& v1, const Vector2<T>& v2 );
Vector2<T> V[2];
Vector2<T> GetNormal();
};
template <typename T>
Line2<T>::Line2() {
V[0] = Vector2<T>();
V[1] = Vector2<T>();
}
template <typename T>
Line2<T>::Line2( const Vector2<T>& v1, const Vector2<T>& v2 ) {
V[0] = v1;
V[1] = v2;
}
template <typename T>
Vector2<T> Line2<T>::GetNormal() {
Vector2<T> tV = Vector2<T>( -(V[1].y - V[0].y) , V[1].x - V[0].x );
tV.Normalize();
return tV;
}
typedef Vector2<Int32> eeVector2if;
typedef Vector2<eeInt> eeVector2i;
typedef Vector2<eeFloat> eeVector2f;
typedef Quad2<eeFloat> eeQuad2f;
typedef Triangle2<eeFloat> eeTriangle2f;
typedef tSize<eeInt> eeSize;
}}