mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-01-20 04:34:48 +00:00
blatantly ganked from T2D; adds rotation as an option for drawbitmap
demonstrates a bit of usage in guibitmapctrl. (do note, gui elements may need followup via altering thier clip rect depending on how folks want to end up using this)
This commit is contained in:
parent
14ebeaf3eb
commit
d07d113246
|
|
@ -303,54 +303,54 @@ U32 GFXDrawUtil::drawTextN( GFont *font, const Point2F &ptDraw, const UTF16 *in_
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 fSpin)
|
||||
{
|
||||
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, fSpin);
|
||||
}
|
||||
|
||||
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 fSpin)
|
||||
{
|
||||
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, fSpin);
|
||||
}
|
||||
|
||||
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 fSpin)
|
||||
{
|
||||
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, fSpin);
|
||||
}
|
||||
|
||||
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 fSpin)
|
||||
{
|
||||
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);
|
||||
drawBitmapStretchSR(texture,dstRectF,srcRectF,in_flip,filter,in_wrap);
|
||||
drawBitmapStretchSR(texture,dstRectF,srcRectF,in_flip,filter,in_wrap, fSpin);
|
||||
}
|
||||
|
||||
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 fSpin)
|
||||
{
|
||||
AssertFatal( texture != 0, "No texture specified for drawBitmap()" );
|
||||
|
||||
RectI subRegion( 0, 0, 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, fSpin);
|
||||
}
|
||||
|
||||
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 fSpin)
|
||||
{
|
||||
AssertFatal( texture != 0, "No texture specified for drawBitmapStretch()" );
|
||||
|
||||
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, fSpin);
|
||||
}
|
||||
|
||||
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 fSpin)
|
||||
{
|
||||
AssertFatal( texture != 0, "No texture specified for drawBitmapSR()" );
|
||||
|
||||
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, fSpin);
|
||||
}
|
||||
|
||||
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 fSpin)
|
||||
{
|
||||
// Sanity if no texture is specified.
|
||||
if(!texture)
|
||||
|
|
@ -395,6 +395,30 @@ void GFXDrawUtil::drawBitmapStretchSR( GFXTextureObject* texture, const RectF &d
|
|||
verts[2].texCoord.set( texLeft, texBottom );
|
||||
verts[3].texCoord.set( texRight, texBottom );
|
||||
|
||||
if (fSpin != 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(fSpin)));
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
rotMatrix.mulP(points[i]);
|
||||
points[i] += offset;
|
||||
verts[i].point = points[i];
|
||||
}
|
||||
}
|
||||
|
||||
verts.unlock();
|
||||
|
||||
mDevice->setVertexBuffer( verts );
|
||||
|
|
@ -1641,4 +1665,4 @@ void GFXDrawUtil::drawTransform( const GFXStateBlockDesc &desc, const MatrixF &m
|
|||
mDevice->setVertexBuffer( verts );
|
||||
mDevice->setupGenericShaders();
|
||||
mDevice->drawPrimitive( GFXLineList, 0, 3 );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,15 +93,15 @@ public:
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 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 drawBitmapStretch( GFXTextureObject*texture, const RectF &dstRect, 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 );
|
||||
void drawBitmap( GFXTextureObject*texture, const Point2F &in_rAt, const GFXBitmapFlip in_flip = GFXBitmapFlip_None, const GFXTextureFilterType filter = GFXTextureFilterPoint , bool in_wrap = true, F32 fSpin = 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, F32 fSpin = 0.0f);
|
||||
void drawBitmapStretch( GFXTextureObject*texture, const RectF &dstRect, const GFXBitmapFlip in_flip = GFXBitmapFlip_None, const GFXTextureFilterType filter = GFXTextureFilterPoint , bool in_wrap = true, F32 fSpin = 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, F32 fSpin = 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 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 drawBitmapStretch( GFXTextureObject*texture, const RectI &dstRect, 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 );
|
||||
void drawBitmap( GFXTextureObject*texture, const Point2I &in_rAt, const GFXBitmapFlip in_flip = GFXBitmapFlip_None, const GFXTextureFilterType filter = GFXTextureFilterPoint , bool in_wrap = true, F32 fSpin = 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, F32 fSpin = 0.0f);
|
||||
void drawBitmapStretch( GFXTextureObject*texture, const RectI &dstRect, const GFXBitmapFlip in_flip = GFXBitmapFlip_None, const GFXTextureFilterType filter = GFXTextureFilterPoint , bool in_wrap = true, F32 fSpin = 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, F32 fSpin = 0.0f);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Draw 3D Shapes
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ ConsoleDocClass( GuiBitmapCtrl,
|
|||
GuiBitmapCtrl::GuiBitmapCtrl(void)
|
||||
: mStartPoint( 0, 0 ),
|
||||
mColor(ColorI::WHITE),
|
||||
mRotation(0),
|
||||
mWrap( false )
|
||||
{
|
||||
INIT_ASSET(Bitmap);
|
||||
|
|
@ -83,6 +84,8 @@ void GuiBitmapCtrl::initPersistFields()
|
|||
addField("color", TypeColorI, Offset(mColor, GuiBitmapCtrl),"color mul");
|
||||
addField( "wrap", TypeBool, Offset( mWrap, GuiBitmapCtrl ),
|
||||
"If true, the bitmap is tiled inside the control rather than stretched to fit." );
|
||||
|
||||
addField("rotation", TypeF32, Offset(mRotation, GuiBitmapCtrl), "rotation");
|
||||
|
||||
endGroup( "Bitmap" );
|
||||
|
||||
|
|
@ -187,14 +190,14 @@ void GuiBitmapCtrl::onRender(Point2I offset, const RectI &updateRect)
|
|||
((texture->mBitmapSize.y*y)+offset.y)-yshift,
|
||||
texture->mBitmapSize.x,
|
||||
texture->mBitmapSize.y);
|
||||
GFX->getDrawUtil()->drawBitmapStretchSR(texture,dstRegion, srcRegion, GFXBitmapFlip_None, GFXTextureFilterLinear);
|
||||
GFX->getDrawUtil()->drawBitmapStretchSR(texture, dstRegion, srcRegion, GFXBitmapFlip_None, GFXTextureFilterLinear, mRotation);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
RectI rect(offset, getExtent());
|
||||
GFX->getDrawUtil()->drawBitmapStretch(mBitmap, rect, GFXBitmapFlip_None, GFXTextureFilterLinear, false);
|
||||
GFX->getDrawUtil()->drawBitmapStretch(mBitmap, rect, GFXBitmapFlip_None, GFXTextureFilterLinear, false, mRotation);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,8 @@ class GuiBitmapCtrl : public GuiControl
|
|||
|
||||
Point2I mStartPoint;
|
||||
ColorI mColor;
|
||||
|
||||
F32 mRotation;
|
||||
|
||||
/// If true, bitmap tiles inside control. Otherwise stretches.
|
||||
bool mWrap;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue