diff --git a/include/eepp/graphics.hpp b/include/eepp/graphics.hpp index cd322bc58..07ad2ed3f 100644 --- a/include/eepp/graphics.hpp +++ b/include/eepp/graphics.hpp @@ -39,5 +39,6 @@ #include #include #include +#include #endif diff --git a/include/eepp/graphics/arcdrawable.hpp b/include/eepp/graphics/arcdrawable.hpp new file mode 100644 index 000000000..a988fcd52 --- /dev/null +++ b/include/eepp/graphics/arcdrawable.hpp @@ -0,0 +1,26 @@ +#ifndef EE_GRAPHICS_ARCDRAWABLE +#define EE_GRAPHICS_ARCDRAWABLE + +#include + +namespace EE { namespace Graphics { + +class ArcDrawable : public PrimitiveDrawable { + public: + ArcDrawable( const Float& radius, Uint32 segmentsCount = 0, const Float& arcAngle = 360.f , const Float& arcStartAngle = 0.f ); + + virtual Sizef getSize(); + + virtual void draw( const Vector2f& position ); + + virtual void draw( const Vector2f& position, const Sizef& size ); + protected: + Float mRadius; + Uint32 mSegmentsCount; + Float mArcAngle; + Float mArcStartAngle; +}; + +}} + +#endif diff --git a/include/eepp/graphics/primitivedrawable.hpp b/include/eepp/graphics/primitivedrawable.hpp new file mode 100644 index 000000000..cd742b048 --- /dev/null +++ b/include/eepp/graphics/primitivedrawable.hpp @@ -0,0 +1,37 @@ +#ifndef EE_GRAPHICS_PRIMITIVEDRAWABLE +#define EE_GRAPHICS_PRIMITIVEDRAWABLE + +#include + +namespace EE { namespace Graphics { + +class PrimitiveDrawable : public Drawable { + public: + PrimitiveDrawable( EE_DRAWABLE_TYPE drawableType ); + + /** Set the fill mode used to draw primitives */ + void setFillMode( const EE_FILL_MODE& Mode ); + + /** @return The fill mode used to draw primitives */ + const EE_FILL_MODE& getFillMode() const; + + /** Set the blend mode used to draw primitives */ + void setBlendMode( const EE_BLEND_MODE& Mode ); + + /** @return The blend mode used to draw primitives */ + const EE_BLEND_MODE& getBlendMode() const; + + /** Set the line width to draw primitives */ + void setLineWidth( const Float& width ); + + /** @return The line with to draw primitives */ + const Float& getLineWidth() const; + protected: + EE_FILL_MODE mFillMode; + EE_BLEND_MODE mBlendMode; + Float mLineWidth; +}; + +}} + +#endif diff --git a/projects/linux/ee.files b/projects/linux/ee.files index 3ea205dfa..2cd13ec18 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -1,3 +1,4 @@ +../../include/eepp/graphics/arcdrawable.hpp ../../include/eepp/graphics/drawable.hpp ../../include/eepp/graphics/drawablesearcher.hpp ../../include/eepp/graphics/font.hpp @@ -5,6 +6,7 @@ ../../include/eepp/graphics/fonttruetype.hpp ../../include/eepp/graphics/fonttruetypeloader.hpp ../../include/eepp/graphics/graphicshelper.hpp +../../include/eepp/graphics/primitivedrawable.hpp ../../include/eepp/graphics/renderer/base.hpp ../../include/eepp/graphics/renderer/opengl.hpp ../../include/eepp/graphics/renderer/renderer.hpp @@ -33,6 +35,7 @@ ../../include/eepp/ui/uithemedefault.hpp ../../include/eepp/ui/uiwidget.hpp ../../src/eepp/gaming/mapobjectlayer.cpp +../../src/eepp/graphics/arcdrawable.cpp ../../src/eepp/graphics/drawable.cpp ../../src/eepp/graphics/drawablesearcher.cpp ../../src/eepp/graphics/fonttruetype.cpp @@ -40,6 +43,7 @@ ../../src/eepp/graphics/globalbatchrenderer.cpp ../../src/eepp/graphics/pixeldensity.cpp ../../src/eepp/graphics/pixelperfect.cpp +../../src/eepp/graphics/primitivedrawable.cpp ../../src/eepp/graphics/renderer/openglext.hpp ../../src/eepp/graphics/renderer/renderer.cpp ../../src/eepp/graphics/renderer/renderer.cpp diff --git a/src/eepp/graphics/arcdrawable.cpp b/src/eepp/graphics/arcdrawable.cpp new file mode 100644 index 000000000..85fa33fd3 --- /dev/null +++ b/src/eepp/graphics/arcdrawable.cpp @@ -0,0 +1,89 @@ +#include +#include + +namespace EE { namespace Graphics { + +ArcDrawable::ArcDrawable( const Float & radius, Uint32 segmentsCount, const Float & arcAngle, const Float & arcStartAngle ) : + PrimitiveDrawable( DRAWABLE_CUSTOM ), + mRadius( radius ), + mSegmentsCount( segmentsCount ), + mArcAngle( arcAngle ), + mArcStartAngle( arcStartAngle ) +{ +} + +Sizef ArcDrawable::getSize() { + return Sizef( mRadius * 2, mRadius * 2 ); +} + +void ArcDrawable::draw( const Vector2f& position ) { + draw( position, getSize() ); +} + +void ArcDrawable::draw( const Vector2f& position, const Sizef& size ) { + BatchRenderer * sBR = GlobalBatchRenderer::instance(); + + if ( size.getWidth() * 0.5f != mRadius ) { + mRadius = size.getWidth() * 0.5f; + } + + if(mSegmentsCount < 6) mSegmentsCount = 6; + mSegmentsCount = mSegmentsCount > 360 ? 360 : mSegmentsCount; + + Float angleShift = 360 / static_cast(mSegmentsCount); + Float arcAngleA = mArcAngle > 360 ? mArcAngle - 360 * std::floor( mArcAngle / 360 ) : mArcAngle; + + sBR->setTexture( NULL ); + + switch( mFillMode ) { + case DRAW_LINE: + { + sBR->setLineWidth( mLineWidth ); + + mSegmentsCount = Uint32( (Float)mSegmentsCount * (Float)eeabs( arcAngleA ) / 360 ); + Float startAngle = Math::radians(mArcStartAngle); + Float theta = Math::radians(arcAngleA) / Float(mSegmentsCount - 1); + Float tangetialFactor = eetan(theta); + Float radialFactor = eecos(theta); + Float x = mRadius * eecos(startAngle); + Float y = mRadius * eesin(startAngle); + + sBR->lineStripBegin(); + sBR->lineStripSetColor( mColor ); + + for( Uint32 ii = 0; ii < mSegmentsCount; ii++ ) { + sBR->batchLineStrip(x + position.x, y + position.y); + + Float tx = -y; + Float ty = x; + + x += tx * tangetialFactor; + y += ty * tangetialFactor; + + x *= radialFactor; + y *= radialFactor; + } + + break; + } + case DRAW_FILL: + { + sBR->triangleFanBegin(); + sBR->triangleFanSetColor( mColor ); + + for( Float i = 0; i < arcAngleA; i+= angleShift ) { + Float startAngle = mArcStartAngle + i; + + sBR->batchTriangleFan( position.x , position.y, + position.x + mRadius * Math::sinAng( startAngle ), position.y + mRadius * Math::cosAng( startAngle ), + position.x + mRadius * Math::sinAng( startAngle + angleShift ), position.y + mRadius * Math::cosAng( startAngle + angleShift ) ); + } + + break; + } + } + + sBR->draw(); +} + +}} diff --git a/src/eepp/graphics/primitivedrawable.cpp b/src/eepp/graphics/primitivedrawable.cpp new file mode 100644 index 000000000..12ccdfcb3 --- /dev/null +++ b/src/eepp/graphics/primitivedrawable.cpp @@ -0,0 +1,34 @@ +#include + +namespace EE { namespace Graphics { + +PrimitiveDrawable::PrimitiveDrawable(EE_DRAWABLE_TYPE drawableType) : + Drawable( drawableType ) +{ +} + +void PrimitiveDrawable::setFillMode( const EE_FILL_MODE& Mode ) { + mFillMode = Mode; +} + +const EE_FILL_MODE& PrimitiveDrawable::getFillMode() const { + return mFillMode; +} + +void PrimitiveDrawable::setBlendMode( const EE_BLEND_MODE& Mode ) { + mBlendMode = Mode; +} + +const EE_BLEND_MODE& PrimitiveDrawable::getBlendMode() const { + return mBlendMode; +} + +void PrimitiveDrawable::setLineWidth( const Float& width ) { + mLineWidth = width; +} + +const Float& PrimitiveDrawable::getLineWidth() const { + return mLineWidth; +} + +}} diff --git a/src/eepp/graphics/text.cpp b/src/eepp/graphics/text.cpp index 89f2074d7..146c34594 100644 --- a/src/eepp/graphics/text.cpp +++ b/src/eepp/graphics/text.cpp @@ -81,6 +81,7 @@ void Text::create(Font * font, const String & text, ColorA FontColor, ColorA Fon mGeometryNeedUpdate = true; mCachedWidthNeedUpdate = true; mColorsNeedUpdate = true; + ensureColorUpdate(); ensureGeometryUpdate(); } @@ -492,6 +493,7 @@ Float Text::getTextHeight() { void Text::draw(const Float & X, const Float & Y, const Vector2f & Scale, const Float & Angle, EE_BLEND_MODE Effect) { if ( NULL != mFont ) { + ensureColorUpdate(); ensureGeometryUpdate(); unsigned int numvert = mVertices.size(); @@ -580,7 +582,6 @@ void Text::draw(const Float & X, const Float & Y, const Vector2f & Scale, const } void Text::ensureGeometryUpdate() { - ensureColorUpdate(); cacheWidth(); Sizei textureSize = mFont->getTexture(mRealCharacterSize)->getPixelSize(); @@ -1020,7 +1021,6 @@ void Text::addGlyphQuad(std::vector& vertices, Vector2f position, VertexCoords vc; if ( GLi->quadsSupported() ) { - vc.texCoords.x = u1; vc.texCoords.y = v1; vc.position.x = centerDiffX + position.x + left - italic * top - outlineThickness; diff --git a/src/eepp/ui/uicontrolanim.cpp b/src/eepp/ui/uicontrolanim.cpp index 477ea03fb..a638dd675 100644 --- a/src/eepp/ui/uicontrolanim.cpp +++ b/src/eepp/ui/uicontrolanim.cpp @@ -398,7 +398,6 @@ void UIControlAnim::drawBorder() { P.setLineWidth( PixelDensity::dpToPx( mBorder->getWidth() ) ); P.setColor( getColor( mBorder->getColor() ) ); - //! @TODO: Check why was this +0.1f -0.1f? if ( mFlags & UI_CLIP_ENABLE ) { Rectf R( Vector2f( mScreenPosf.x + 0.1f, mScreenPosf.y + 0.1f ), Sizef( (Float)mRealSize.getWidth() - 0.1f, (Float)mRealSize.getHeight() - 0.1f ) ); diff --git a/src/examples/empty_window/empty_window.cpp b/src/examples/empty_window/empty_window.cpp index e08d9956f..4771b8bb8 100644 --- a/src/examples/empty_window/empty_window.cpp +++ b/src/examples/empty_window/empty_window.cpp @@ -44,21 +44,21 @@ void mainLoop() Vector2f winCenter( win->getWidth() * 0.5f, win->getHeight() * 0.5f ); - +/* GLi->enable(GL_STENCIL_TEST); GLi->stencilMask(0xFF); GLi->stencilFunc(GL_NEVER, 1, 0xFF); GLi->stencilOp(GL_REPLACE, GL_KEEP, GL_KEEP); - p.drawCircle( winCenter, 150, 40 ); + p.drawCircle( winCenter, 150, 64 ); GLi->stencilFunc(GL_EQUAL, 0, 0xFF); // Draw a circle - p.drawArc( winCenter, 200, 40, circ, circ2 ); + p.drawArc( winCenter, 200, 64, circ, circ2 ); GLi->disable(GL_STENCIL_TEST); - +*/ /* GLi->Enable(GL_STENCIL_TEST); @@ -79,6 +79,11 @@ void mainLoop() GLi->Disable(GL_STENCIL_TEST); */ + ArcDrawable arcDrawable( 100, 64 ); + arcDrawable.setColorFilter( ColorA( 220, 0, 0, 200 ) ); + arcDrawable.setFillMode( DRAW_FILL ); + arcDrawable.draw( winCenter ); + // Draw frame win->display();