mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-29 16:25:42 +00:00
Merge pull request #637 from Azaezel/alpha40/guiRotation
blatantly ganked from T2D; adds rotation as an option for drawbitmap
This commit is contained in:
commit
e0e3ebc69d
4 changed files with 55 additions and 27 deletions
|
|
@ -303,54 +303,54 @@ U32 GFXDrawUtil::drawTextN( GFont *font, const Point2F &ptDraw, const UTF16 *in_
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Draw Bitmaps
|
// Draw Bitmaps
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void GFXDrawUtil::drawBitmap( GFXTextureObject* texture, const Point2I &in_rAt, const GFXBitmapFlip in_flip, const GFXTextureFilterType filter , bool in_wrap /*= true*/ )
|
void GFXDrawUtil::drawBitmap( GFXTextureObject* texture, const Point2I &in_rAt, const GFXBitmapFlip in_flip, const GFXTextureFilterType filter , bool in_wrap /*= true*/, F32 angle)
|
||||||
{
|
{
|
||||||
drawBitmap(texture,Point2F((F32)in_rAt.x,(F32)in_rAt.y),in_flip,filter,in_wrap);
|
drawBitmap(texture,Point2F((F32)in_rAt.x,(F32)in_rAt.y),in_flip,filter,in_wrap, angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GFXDrawUtil::drawBitmapStretch( GFXTextureObject* texture, const RectI &dstRect, const GFXBitmapFlip in_flip, const GFXTextureFilterType filter , bool in_wrap /*= true*/ )
|
void GFXDrawUtil::drawBitmapStretch( GFXTextureObject* texture, const RectI &dstRect, const GFXBitmapFlip in_flip, const GFXTextureFilterType filter , bool in_wrap /*= true*/, F32 angle)
|
||||||
{
|
{
|
||||||
drawBitmapStretch(texture,RectF((F32)dstRect.point.x,(F32)dstRect.point.y,(F32)dstRect.extent.x,(F32)dstRect.extent.y),in_flip,filter,in_wrap);
|
drawBitmapStretch(texture,RectF((F32)dstRect.point.x,(F32)dstRect.point.y,(F32)dstRect.extent.x,(F32)dstRect.extent.y),in_flip,filter,in_wrap, angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GFXDrawUtil::drawBitmapSR( GFXTextureObject* texture, const Point2I &in_rAt, const RectI &srcRect, const GFXBitmapFlip in_flip, const GFXTextureFilterType filter , bool in_wrap /*= true*/ )
|
void GFXDrawUtil::drawBitmapSR( GFXTextureObject* texture, const Point2I &in_rAt, const RectI &srcRect, const GFXBitmapFlip in_flip, const GFXTextureFilterType filter , bool in_wrap /*= true*/, F32 angle)
|
||||||
{
|
{
|
||||||
drawBitmapSR(texture,Point2F((F32)in_rAt.x,(F32)in_rAt.y),RectF((F32)srcRect.point.x,(F32)srcRect.point.y,(F32)srcRect.extent.x,(F32)srcRect.extent.y),in_flip,filter,in_wrap);
|
drawBitmapSR(texture,Point2F((F32)in_rAt.x,(F32)in_rAt.y),RectF((F32)srcRect.point.x,(F32)srcRect.point.y,(F32)srcRect.extent.x,(F32)srcRect.extent.y),in_flip,filter,in_wrap, angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GFXDrawUtil::drawBitmapStretchSR( GFXTextureObject *texture, const RectI &dstRect, const RectI &srcRect, const GFXBitmapFlip in_flip, const GFXTextureFilterType filter , bool in_wrap /*= true*/ )
|
void GFXDrawUtil::drawBitmapStretchSR( GFXTextureObject *texture, const RectI &dstRect, const RectI &srcRect, const GFXBitmapFlip in_flip, const GFXTextureFilterType filter , bool in_wrap /*= true*/, F32 angle)
|
||||||
{
|
{
|
||||||
RectF dstRectF = RectF((F32)dstRect.point.x,(F32)dstRect.point.y,(F32)dstRect.extent.x,(F32)dstRect.extent.y);
|
RectF dstRectF = RectF((F32)dstRect.point.x,(F32)dstRect.point.y,(F32)dstRect.extent.x,(F32)dstRect.extent.y);
|
||||||
RectF srcRectF = RectF((F32)srcRect.point.x,(F32)srcRect.point.y,(F32)srcRect.extent.x,(F32)srcRect.extent.y);
|
RectF srcRectF = RectF((F32)srcRect.point.x,(F32)srcRect.point.y,(F32)srcRect.extent.x,(F32)srcRect.extent.y);
|
||||||
drawBitmapStretchSR(texture,dstRectF,srcRectF,in_flip,filter,in_wrap);
|
drawBitmapStretchSR(texture,dstRectF,srcRectF,in_flip,filter,in_wrap, angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GFXDrawUtil::drawBitmap( GFXTextureObject*texture, const Point2F &in_rAt, const GFXBitmapFlip in_flip /*= GFXBitmapFlip_None*/, const GFXTextureFilterType filter /*= GFXTextureFilterPoint */ , bool in_wrap /*= true*/ )
|
void GFXDrawUtil::drawBitmap( GFXTextureObject*texture, const Point2F &in_rAt, const GFXBitmapFlip in_flip /*= GFXBitmapFlip_None*/, const GFXTextureFilterType filter /*= GFXTextureFilterPoint */ , bool in_wrap /*= true*/, F32 angle)
|
||||||
{
|
{
|
||||||
AssertFatal( texture != 0, "No texture specified for drawBitmap()" );
|
AssertFatal( texture != 0, "No texture specified for drawBitmap()" );
|
||||||
|
|
||||||
RectI subRegion( 0, 0, texture->mBitmapSize.x, texture->mBitmapSize.y );
|
RectI subRegion( 0, 0, texture->mBitmapSize.x, texture->mBitmapSize.y );
|
||||||
RectI stretch( in_rAt.x, in_rAt.y, texture->mBitmapSize.x, texture->mBitmapSize.y );
|
RectI stretch( in_rAt.x, in_rAt.y, texture->mBitmapSize.x, texture->mBitmapSize.y );
|
||||||
drawBitmapStretchSR( texture, stretch, subRegion, in_flip, filter, in_wrap );
|
drawBitmapStretchSR( texture, stretch, subRegion, in_flip, filter, in_wrap, angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GFXDrawUtil::drawBitmapStretch( GFXTextureObject*texture, const RectF &dstRect, const GFXBitmapFlip in_flip /*= GFXBitmapFlip_None*/, const GFXTextureFilterType filter /*= GFXTextureFilterPoint */ , bool in_wrap /*= true*/ )
|
void GFXDrawUtil::drawBitmapStretch( GFXTextureObject*texture, const RectF &dstRect, const GFXBitmapFlip in_flip /*= GFXBitmapFlip_None*/, const GFXTextureFilterType filter /*= GFXTextureFilterPoint */ , bool in_wrap /*= true*/, F32 angle)
|
||||||
{
|
{
|
||||||
AssertFatal( texture != 0, "No texture specified for drawBitmapStretch()" );
|
AssertFatal( texture != 0, "No texture specified for drawBitmapStretch()" );
|
||||||
|
|
||||||
RectF subRegion( 0.f, 0.f, (F32)texture->mBitmapSize.x, (F32)texture->mBitmapSize.y );
|
RectF subRegion( 0.f, 0.f, (F32)texture->mBitmapSize.x, (F32)texture->mBitmapSize.y );
|
||||||
drawBitmapStretchSR( texture, dstRect, subRegion, in_flip, filter, in_wrap );
|
drawBitmapStretchSR( texture, dstRect, subRegion, in_flip, filter, in_wrap, angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GFXDrawUtil::drawBitmapSR( GFXTextureObject*texture, const Point2F &in_rAt, const RectF &srcRect, const GFXBitmapFlip in_flip /*= GFXBitmapFlip_None*/, const GFXTextureFilterType filter /*= GFXTextureFilterPoint */ , bool in_wrap /*= true*/ )
|
void GFXDrawUtil::drawBitmapSR( GFXTextureObject*texture, const Point2F &in_rAt, const RectF &srcRect, const GFXBitmapFlip in_flip /*= GFXBitmapFlip_None*/, const GFXTextureFilterType filter /*= GFXTextureFilterPoint */ , bool in_wrap /*= true*/, F32 angle)
|
||||||
{
|
{
|
||||||
AssertFatal( texture != 0, "No texture specified for drawBitmapSR()" );
|
AssertFatal( texture != 0, "No texture specified for drawBitmapSR()" );
|
||||||
|
|
||||||
RectF stretch( in_rAt.x, in_rAt.y, srcRect.len_x(), srcRect.len_y() );
|
RectF stretch( in_rAt.x, in_rAt.y, srcRect.len_x(), srcRect.len_y() );
|
||||||
drawBitmapStretchSR( texture, stretch, srcRect, in_flip, filter, in_wrap );
|
drawBitmapStretchSR( texture, stretch, srcRect, in_flip, filter, in_wrap, angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GFXDrawUtil::drawBitmapStretchSR( GFXTextureObject* texture, const RectF &dstRect, const RectF &srcRect, const GFXBitmapFlip in_flip /*= GFXBitmapFlip_None*/, const GFXTextureFilterType filter /*= GFXTextureFilterPoint */ , bool in_wrap /*= true*/ )
|
void GFXDrawUtil::drawBitmapStretchSR( GFXTextureObject* texture, const RectF &dstRect, const RectF &srcRect, const GFXBitmapFlip in_flip /*= GFXBitmapFlip_None*/, const GFXTextureFilterType filter /*= GFXTextureFilterPoint */ , bool in_wrap /*= true*/, F32 angle)
|
||||||
{
|
{
|
||||||
// Sanity if no texture is specified.
|
// Sanity if no texture is specified.
|
||||||
if(!texture)
|
if(!texture)
|
||||||
|
|
@ -395,6 +395,30 @@ void GFXDrawUtil::drawBitmapStretchSR( GFXTextureObject* texture, const RectF &d
|
||||||
verts[2].texCoord.set( texLeft, texBottom );
|
verts[2].texCoord.set( texLeft, texBottom );
|
||||||
verts[3].texCoord.set( texRight, texBottom );
|
verts[3].texCoord.set( texRight, texBottom );
|
||||||
|
|
||||||
|
if (angle != 0.0f)
|
||||||
|
{
|
||||||
|
U32 i = 0;
|
||||||
|
Point3F points[4];
|
||||||
|
|
||||||
|
points[0] = Point3F(-dstRect.extent.x / 2.0f, -dstRect.extent.y / 2.0f, 0.0);
|
||||||
|
points[1] = Point3F(dstRect.extent.x / 2.0f, -dstRect.extent.y / 2.0f, 0.0);
|
||||||
|
points[2] = Point3F(-dstRect.extent.x / 2.0f, dstRect.extent.y / 2.0f, 0.0);
|
||||||
|
points[3] = Point3F(dstRect.extent.x / 2.0f, dstRect.extent.y / 2.0f, 0.0);
|
||||||
|
|
||||||
|
//calc center by taking position+extent/2
|
||||||
|
Point3F offset(dstRect.point.x + dstRect.extent.x / 2.0f,
|
||||||
|
dstRect.point.y + dstRect.extent.y / 2.0f, 0.0);
|
||||||
|
|
||||||
|
//rotate points by mulitplying by a rotation matrix
|
||||||
|
MatrixF rotMatrix(EulerF(0.0, 0.0, mDegToRad(angle)));
|
||||||
|
for (i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
rotMatrix.mulP(points[i]);
|
||||||
|
points[i] += offset;
|
||||||
|
verts[i].point = points[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
verts.unlock();
|
verts.unlock();
|
||||||
|
|
||||||
mDevice->setVertexBuffer( verts );
|
mDevice->setVertexBuffer( verts );
|
||||||
|
|
@ -1641,4 +1665,4 @@ void GFXDrawUtil::drawTransform( const GFXStateBlockDesc &desc, const MatrixF &m
|
||||||
mDevice->setVertexBuffer( verts );
|
mDevice->setVertexBuffer( verts );
|
||||||
mDevice->setupGenericShaders();
|
mDevice->setupGenericShaders();
|
||||||
mDevice->drawPrimitive( GFXLineList, 0, 3 );
|
mDevice->drawPrimitive( GFXLineList, 0, 3 );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -93,15 +93,15 @@ public:
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Draw Bitmaps
|
// Draw Bitmaps
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void drawBitmap( GFXTextureObject*texture, const Point2F &in_rAt, const GFXBitmapFlip in_flip = GFXBitmapFlip_None, const GFXTextureFilterType filter = GFXTextureFilterPoint , bool in_wrap = true );
|
void drawBitmap( GFXTextureObject*texture, const Point2F &in_rAt, const GFXBitmapFlip in_flip = GFXBitmapFlip_None, const GFXTextureFilterType filter = GFXTextureFilterPoint , bool in_wrap = true, F32 angle = 0.0f);
|
||||||
void drawBitmapSR( GFXTextureObject*texture, const Point2F &in_rAt, const RectF &srcRect, const GFXBitmapFlip in_flip = GFXBitmapFlip_None, const GFXTextureFilterType filter = GFXTextureFilterPoint , bool in_wrap = true );
|
void drawBitmapSR( GFXTextureObject*texture, const Point2F &in_rAt, const RectF &srcRect, const GFXBitmapFlip in_flip = GFXBitmapFlip_None, const GFXTextureFilterType filter = GFXTextureFilterPoint , bool in_wrap = true, F32 angle = 0.0f);
|
||||||
void drawBitmapStretch( GFXTextureObject*texture, const RectF &dstRect, const GFXBitmapFlip in_flip = GFXBitmapFlip_None, const GFXTextureFilterType filter = GFXTextureFilterPoint , bool in_wrap = true );
|
void drawBitmapStretch( GFXTextureObject*texture, const RectF &dstRect, const GFXBitmapFlip in_flip = GFXBitmapFlip_None, const GFXTextureFilterType filter = GFXTextureFilterPoint , bool in_wrap = true, F32 angle = 0.0f);
|
||||||
void drawBitmapStretchSR( GFXTextureObject*texture, const RectF &dstRect, const RectF &srcRect, const GFXBitmapFlip in_flip = GFXBitmapFlip_None, const GFXTextureFilterType filter = GFXTextureFilterPoint , bool in_wrap = true );
|
void drawBitmapStretchSR( GFXTextureObject*texture, const RectF &dstRect, const RectF &srcRect, const GFXBitmapFlip in_flip = GFXBitmapFlip_None, const GFXTextureFilterType filter = GFXTextureFilterPoint , bool in_wrap = true, F32 angle = 0.0f);
|
||||||
|
|
||||||
void drawBitmap( GFXTextureObject*texture, const Point2I &in_rAt, const GFXBitmapFlip in_flip = GFXBitmapFlip_None, const GFXTextureFilterType filter = GFXTextureFilterPoint , bool in_wrap = true );
|
void drawBitmap( GFXTextureObject*texture, const Point2I &in_rAt, const GFXBitmapFlip in_flip = GFXBitmapFlip_None, const GFXTextureFilterType filter = GFXTextureFilterPoint , bool in_wrap = true, F32 angle = 0.0f);
|
||||||
void drawBitmapSR( GFXTextureObject*texture, const Point2I &in_rAt, const RectI &srcRect, const GFXBitmapFlip in_flip = GFXBitmapFlip_None, const GFXTextureFilterType filter = GFXTextureFilterPoint , bool in_wrap = true );
|
void drawBitmapSR( GFXTextureObject*texture, const Point2I &in_rAt, const RectI &srcRect, const GFXBitmapFlip in_flip = GFXBitmapFlip_None, const GFXTextureFilterType filter = GFXTextureFilterPoint , bool in_wrap = true, F32 angle = 0.0f);
|
||||||
void drawBitmapStretch( GFXTextureObject*texture, const RectI &dstRect, const GFXBitmapFlip in_flip = GFXBitmapFlip_None, const GFXTextureFilterType filter = GFXTextureFilterPoint , bool in_wrap = true );
|
void drawBitmapStretch( GFXTextureObject*texture, const RectI &dstRect, const GFXBitmapFlip in_flip = GFXBitmapFlip_None, const GFXTextureFilterType filter = GFXTextureFilterPoint , bool in_wrap = true, F32 angle = 0.0f);
|
||||||
void drawBitmapStretchSR( GFXTextureObject*texture, const RectI &dstRect, const RectI &srcRect, const GFXBitmapFlip in_flip = GFXBitmapFlip_None, const GFXTextureFilterType filter = GFXTextureFilterPoint , bool in_wrap = true );
|
void drawBitmapStretchSR( GFXTextureObject*texture, const RectI &dstRect, const RectI &srcRect, const GFXBitmapFlip in_flip = GFXBitmapFlip_None, const GFXTextureFilterType filter = GFXTextureFilterPoint , bool in_wrap = true, F32 angle = 0.0f);
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Draw 3D Shapes
|
// Draw 3D Shapes
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@ ConsoleDocClass( GuiBitmapCtrl,
|
||||||
GuiBitmapCtrl::GuiBitmapCtrl(void)
|
GuiBitmapCtrl::GuiBitmapCtrl(void)
|
||||||
: mStartPoint( 0, 0 ),
|
: mStartPoint( 0, 0 ),
|
||||||
mColor(ColorI::WHITE),
|
mColor(ColorI::WHITE),
|
||||||
|
mAngle(0),
|
||||||
mWrap( false )
|
mWrap( false )
|
||||||
{
|
{
|
||||||
INIT_ASSET(Bitmap);
|
INIT_ASSET(Bitmap);
|
||||||
|
|
@ -83,6 +84,8 @@ void GuiBitmapCtrl::initPersistFields()
|
||||||
addField("color", TypeColorI, Offset(mColor, GuiBitmapCtrl),"color mul");
|
addField("color", TypeColorI, Offset(mColor, GuiBitmapCtrl),"color mul");
|
||||||
addField( "wrap", TypeBool, Offset( mWrap, GuiBitmapCtrl ),
|
addField( "wrap", TypeBool, Offset( mWrap, GuiBitmapCtrl ),
|
||||||
"If true, the bitmap is tiled inside the control rather than stretched to fit." );
|
"If true, the bitmap is tiled inside the control rather than stretched to fit." );
|
||||||
|
|
||||||
|
addField("angle", TypeF32, Offset(mAngle, GuiBitmapCtrl), "rotation");
|
||||||
|
|
||||||
endGroup( "Bitmap" );
|
endGroup( "Bitmap" );
|
||||||
|
|
||||||
|
|
@ -187,14 +190,14 @@ void GuiBitmapCtrl::onRender(Point2I offset, const RectI &updateRect)
|
||||||
((texture->mBitmapSize.y*y)+offset.y)-yshift,
|
((texture->mBitmapSize.y*y)+offset.y)-yshift,
|
||||||
texture->mBitmapSize.x,
|
texture->mBitmapSize.x,
|
||||||
texture->mBitmapSize.y);
|
texture->mBitmapSize.y);
|
||||||
GFX->getDrawUtil()->drawBitmapStretchSR(texture,dstRegion, srcRegion, GFXBitmapFlip_None, GFXTextureFilterLinear);
|
GFX->getDrawUtil()->drawBitmapStretchSR(texture, dstRegion, srcRegion, GFXBitmapFlip_None, GFXTextureFilterLinear, mAngle);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
RectI rect(offset, getExtent());
|
RectI rect(offset, getExtent());
|
||||||
GFX->getDrawUtil()->drawBitmapStretch(mBitmap, rect, GFXBitmapFlip_None, GFXTextureFilterLinear, false);
|
GFX->getDrawUtil()->drawBitmapStretch(mBitmap, rect, GFXBitmapFlip_None, GFXTextureFilterLinear, false, mAngle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,8 @@ class GuiBitmapCtrl : public GuiControl
|
||||||
|
|
||||||
Point2I mStartPoint;
|
Point2I mStartPoint;
|
||||||
ColorI mColor;
|
ColorI mColor;
|
||||||
|
F32 mAngle;
|
||||||
|
|
||||||
/// If true, bitmap tiles inside control. Otherwise stretches.
|
/// If true, bitmap tiles inside control. Otherwise stretches.
|
||||||
bool mWrap;
|
bool mWrap;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue