Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f576c59
Fumbling toward a transformation on CoronaTotalTime, so far the comma…
ggcrunchy Feb 7, 2019
6626191
Moved some of the time transform stuff into ShaderResource with link …
ggcrunchy Feb 8, 2019
e59f04a
Better argument checking for time transforms
ggcrunchy Feb 9, 2019
e05f972
Whoops, wasn't always linking Program back to ShaderResource
ggcrunchy Feb 10, 2019
c7af750
Removed notes to self about changes
ggcrunchy Feb 11, 2019
9058c1f
timeTransform ignored if no time dependency
ggcrunchy Feb 11, 2019
c01d916
Minor changes
ggcrunchy May 29, 2020
08dc3b6
Maintenance Revert Test
scottrules44 Sep 20, 2021
05b91fb
Simulator: Adding Samsung Galaxy 21 as a skin
scottrules44 Sep 22, 2021
f44be24
Maintenance
scottrules44 Sep 22, 2021
581d844
Android: adding rest of media intents for Android 11
scottrules44 Sep 22, 2021
265be3c
Merge
ggcrunchy Sep 23, 2021
e217c80
Merge
ggcrunchy Oct 4, 2021
ca300c1
Merge branch 'master' of https://github.com/coronalabs/corona
ggcrunchy Oct 19, 2021
0b5e1e9
First go at graphics.undefineEffect()
ggcrunchy Nov 9, 2021
b41e624
Revert "First go at graphics.undefineEffect()"
ggcrunchy Nov 10, 2021
5be6193
Merging upstream
ggcrunchy Aug 18, 2022
f38ecec
Merge branch 'master' of https://github.com/ggcrunchy/corona
ggcrunchy Aug 18, 2022
bb395b8
Merge branch 'master' of https://github.com/coronalabs/corona
ggcrunchy Dec 16, 2022
dfe75aa
Merge branch 'master' of https://github.com/coronalabs/corona
ggcrunchy Jan 25, 2023
5a3c9e5
Merge branch 'master' of https://github.com/coronalabs/corona
ggcrunchy Mar 24, 2023
0a67355
Merge branch 'master' of https://github.com/coronalabs/corona
ggcrunchy Apr 1, 2023
bb34246
More or less functional bitmap-based masking
ggcrunchy Apr 1, 2023
e8b2d71
Merge branch 'master' of https://github.com/coronalabs/corona
ggcrunchy Apr 14, 2023
5c006cd
Merge branch 'master' of https://github.com/coronalabs/corona
ggcrunchy Apr 14, 2023
ecf8ee0
Merge branch 'master' into MaskFromBitmap2
ggcrunchy Apr 18, 2023
ed674ef
Using weak table instead of encoding the filename to indicate hit-tes…
ggcrunchy Apr 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions librtt/Display/Rtt_BitmapMask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,41 +23,50 @@ namespace Rtt
// ----------------------------------------------------------------------------

BitmapMask*
BitmapMask::Create( Runtime& runtime, const FilePath& maskData )
BitmapMask::Create( Runtime& runtime, const FilePath& maskData, bool onlyForHitTests )
{
BitmapPaint *paint = BitmapPaint::NewBitmap( runtime, maskData, PlatformBitmap::kIsBitsFullResolution, true );
BitmapPaint *paint = BitmapPaint::NewBitmap( runtime, maskData, PlatformBitmap::kIsBitsFullResolution, true, onlyForHitTests );
BitmapMask *result = NULL;

if ( Rtt_VERIFY( paint ) )
if ( Rtt_VERIFY( paint || onlyForHitTests ) )
{
result = Rtt_NEW( runtime.GetAllocator(), BitmapMask( paint ) );
result = Rtt_NEW( runtime.GetAllocator(), BitmapMask( paint, onlyForHitTests ) );
}

return result;
}

BitmapMask::BitmapMask( BitmapPaint *paint )
BitmapMask::BitmapMask( BitmapPaint *paint, bool onlyForHitTests, bool isTemporary )
: fPaint( paint ),
fTransform(),
fContentWidth( Rtt_REAL_NEG_1 ),
fContentHeight( Rtt_REAL_NEG_1 )
fContentHeight( Rtt_REAL_NEG_1 ),
fOnlyForHitTests( onlyForHitTests ),
fIsTemporary( isTemporary )
{
Rtt_ASSERT( paint );
Rtt_ASSERT( paint || onlyForHitTests );
}

BitmapMask::BitmapMask( BitmapPaint *paint, Real contentW, Real contentH )
: fPaint( paint ),
fTransform(),
fContentWidth( contentW > Rtt_REAL_0 ? contentW : Rtt_REAL_NEG_1 ),
fContentHeight( contentH > Rtt_REAL_0 ? contentH : Rtt_REAL_NEG_1 )
fContentHeight( contentH > Rtt_REAL_0 ? contentH : Rtt_REAL_NEG_1 ),
fOnlyForHitTests( false ),
fIsTemporary( false )
{
}

BitmapMask::~BitmapMask()
{
Rtt_DELETE( fPaint );
if ( !fIsTemporary )
{
Rtt_DELETE( fPaint );
}
}

const char BitmapMask::kHitTestOnlyTable[] = "hitTestOnlyTableKey";

void
BitmapMask::GetSelfBounds( Rect& rect ) const
{
Expand Down
12 changes: 10 additions & 2 deletions librtt/Display/Rtt_BitmapMask.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,24 @@ class UserdataWrapper;
class BitmapMask
{
public:
static BitmapMask* Create( Runtime& runtime, const FilePath& maskData );
static BitmapMask* Create( Runtime& runtime, const FilePath& maskData, bool onlyForHitTests );

public:
BitmapMask( BitmapPaint *paint );
BitmapMask( BitmapPaint *paint, bool onlyForHitTests, bool isTemporary = false );
BitmapMask( BitmapPaint *paint, Real contentW, Real contentH );

public:
~BitmapMask();

public:
static const char kHitTestOnlyTable[];

public:
const BitmapPaint* GetPaint() const { return fPaint; }
BitmapPaint* GetPaint() { return fPaint; }

public:
bool GetOnlyForHitTests() const { return fOnlyForHitTests; }

public:
const Transform& GetTransform() const { return fTransform; }
Expand All @@ -58,6 +64,8 @@ class BitmapMask
Transform fTransform;
Real fContentWidth;
Real fContentHeight;
bool fOnlyForHitTests;
bool fIsTemporary;
};

// ----------------------------------------------------------------------------
Expand Down
9 changes: 7 additions & 2 deletions librtt/Display/Rtt_BitmapPaint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,21 @@ BitmapPaint::NewBitmap( Runtime& runtime, const char* filename, MPlatform::Direc
}

BitmapPaint*
BitmapPaint::NewBitmap( Runtime& runtime, const FilePath& data, U32 flags, bool isMask )
BitmapPaint::NewBitmap( Runtime& runtime, const FilePath& data, U32 flags, bool isMask, bool onlyForHitTests )
{
BitmapPaint *result = NULL;

const char *filename = data.GetFilename();
MPlatform::Directory baseDir = data.GetBaseDir();

if ( onlyForHitTests && '\0' == *filename )
{
return NULL;
}

TextureFactory& factory = runtime.GetDisplay().GetTextureFactory();
SharedPtr< TextureResource > pTexture =
factory.FindOrCreate( filename, baseDir, flags, isMask );
factory.FindOrCreate( filename, baseDir, flags, isMask, onlyForHitTests );

if ( pTexture.NotNull() )
{
Expand Down
2 changes: 1 addition & 1 deletion librtt/Display/Rtt_BitmapPaint.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class BitmapPaint : public Paint
static BitmapPaint* NewBitmap( Runtime& runtime, const char* filename, MPlatform::Directory baseDir, U32 flags );

// Load bitmap mask from file or reuse bitmap from image cache
static BitmapPaint* NewBitmap( Runtime& runtime, const FilePath& data, U32 flags, bool isMask );
static BitmapPaint* NewBitmap( Runtime& runtime, const FilePath& data, U32 flags, bool isMask, bool onlyForHitTests = false );

// Wrap platform bitmap in Paint-compatible interface. Typically used
// in conjunction with PlatformImageProvider
Expand Down
32 changes: 29 additions & 3 deletions librtt/Display/Rtt_DisplayObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "Display/Rtt_BitmapPaint.h"
#include "Display/Rtt_Scene.h"
#include "Display/Rtt_StageObject.h"
#include "Display/Rtt_ShapeObject.h"
#include "Rtt_Event.h"
#include "Rtt_LuaContext.h"
#include "Rtt_LuaProxy.h"
Expand Down Expand Up @@ -318,7 +319,32 @@ DisplayObject::UpdateSelfBounds( Rect& rRect ) const
if ( IsHitTestMasked() )
{
Rect maskBounds;
fMask->GetSelfBounds( maskBounds );

if ( fMask->GetOnlyForHitTests() && !fMask->GetPaint() )
{
if ( !ShapeObject::IsShapeObject( *this ) )
{
return;
}

const ShapeObject &o = static_cast<const ShapeObject&>( *this );
const BitmapPaint* tempPaint = o.GetBitmapPaint();

if ( !tempPaint )
{
return;
}

BitmapMask temp( const_cast<BitmapPaint*>( tempPaint ), true, true );

temp.GetSelfBounds( maskBounds );
}

else
{
fMask->GetSelfBounds( maskBounds );
}

rRect.Intersect( maskBounds );
}
}
Expand Down Expand Up @@ -1302,7 +1328,7 @@ DisplayObject::UpdateMask()
{
Rtt_ASSERT( ! IsValid( kMaskFlag ) );

if ( fMask )
if ( fMask && !fMask->GetOnlyForHitTests() )
{
/*
Matrix xform = GetSrcToDstMatrix();
Expand Down Expand Up @@ -1333,7 +1359,7 @@ DisplayObject::SetMask( Rtt_Allocator *allocator, BitmapMask *mask )

if ( mask )
{
if( ! fMaskUniform )
if( ! fMaskUniform && !fMask->GetOnlyForHitTests() )
{
fMaskUniform = Rtt_NEW( allocator, Uniform( allocator, Uniform::kMat3 ) );
}
Expand Down
4 changes: 2 additions & 2 deletions librtt/Display/Rtt_GroupObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ GroupObject::Draw( Renderer& renderer ) const

const BitmapMask *mask = GetMask();

if ( mask )
if ( mask && !fMask->GetOnlyForHitTests() )
{
Texture *texture = const_cast< BitmapPaint * >( mask->GetPaint() )->GetTexture();
Uniform *uniform = const_cast< Self * >( this )->GetMaskUniform();
Expand All @@ -221,7 +221,7 @@ GroupObject::Draw( Renderer& renderer ) const
}
}

if ( mask )
if ( mask && !fMask->GetOnlyForHitTests() )
{
renderer.PopMask();
}
Expand Down
48 changes: 48 additions & 0 deletions librtt/Display/Rtt_LuaLibGraphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class GraphicsLibrary

public:
static int newMask( lua_State *L );
static int newHitTestOnlyMask( lua_State *L );
static int newHitTestOnlyMaskFromPaint( lua_State *L );
static int newGradient( lua_State *L );
static int newImageSheet( lua_State *L );
static int defineEffect( lua_State *L );
Expand Down Expand Up @@ -113,6 +115,8 @@ GraphicsLibrary::Open( lua_State *L )
const luaL_Reg kVTable[] =
{
{ "newMask", newMask },
{ "newHitTestOnlyMask", newHitTestOnlyMask },
{ "newHitTestOnlyMaskFromPaint", newHitTestOnlyMaskFromPaint },
// { "newVertexArray", newVertexArray },
{ "newGradient", newGradient },
{ "newImageSheet", newImageSheet },
Expand Down Expand Up @@ -202,6 +206,43 @@ GraphicsLibrary::newMask( lua_State *L )
return result;
}

// graphics.newHitTestOnlyMask( filename [, baseDir] )
int
GraphicsLibrary::newHitTestOnlyMask( lua_State *L )
{
int result = GraphicsLibrary::newMask( L );

if ( result )
{
lua_getfield( L, LUA_REGISTRYINDEX, BitmapMask::kHitTestOnlyTable );

if ( lua_istable( L, -1 ) )
{
lua_pushvalue( L, -2 );
lua_pushboolean( L, 1 );
lua_rawset( L, -3 );
lua_pop( L, 1 );
}

else
{
result = 0;
}
}

return result;
}

// graphics.newHitTestOnlyMaskFromPaint( [opts] )
int
GraphicsLibrary::newHitTestOnlyMaskFromPaint( lua_State *L )
{
lua_settop( L, 0 ); // TODO: any options?
lua_pushliteral( L, "" );

return newHitTestOnlyMask( L );
}

// graphics.newVertexArray( x1, y1 [,x2, y2, ... ] )
/*
static int
Expand Down Expand Up @@ -901,6 +942,13 @@ LuaLibGraphics::Initialize( lua_State *L, Display& display )

CoronaLuaPushModule( L, GraphicsLibrary::kName );
lua_setglobal( L, GraphicsLibrary::kName ); // graphics = library

lua_newtable( L );
lua_createtable( L, 0, 1 );
lua_pushliteral( L, "k" );
lua_setfield( L, -2, "__mode" );
lua_setmetatable( L, -2 );
lua_setfield( L, LUA_REGISTRYINDEX, BitmapMask::kHitTestOnlyTable );
}

// ----------------------------------------------------------------------------
Expand Down
13 changes: 11 additions & 2 deletions librtt/Display/Rtt_PlatformBitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,17 @@ PlatformBitmap::HitTest( Rtt_Allocator *context, int i, int j, U8 threshold ) co
break;

default:
// TODO: Use GetColorByteIndexesFor()
Rtt_ASSERT_NOT_IMPLEMENTED();
{
int alphaIndex, redIndex, greenIndex, blueIndex;
GetColorByteIndexesFor( format, &alphaIndex, &redIndex, &greenIndex, &blueIndex );
#ifdef Rtt_ANDROID_ENV // cf. GraphicsLibrary::newOutline et al.
alphaIndex = 3;
#endif
const U8 *pixels = ((const U8*)data);
U8 alpha = pixels[index + alphaIndex];
/* TODO? use r,g,b...*/
result = alpha > threshold;
}
break;
}
}
Expand Down
61 changes: 60 additions & 1 deletion librtt/Display/Rtt_ShapeObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,37 @@ ShapeObject::~ShapeObject()
Rtt_DELETE( fPath );
}

bool
ShapeObject::IsShapeObject( const DisplayObject &object )
{
const LuaProxyVTable* t = &object.ProxyVTable(), * shapeVTable = &LuaShapeObjectProxyVTable::Constant();

while ( shapeVTable != t )
{
const LuaProxyVTable* parent = &t->Parent();

if ( parent == t )
{
return false;
}

else
{
t = parent;
}
}

return true;
}

const BitmapPaint*
ShapeObject::GetBitmapPaint() const
{
Rtt_ASSERT( fPath );

return (BitmapPaint*)fPath->GetFill()->AsPaint( Paint::kBitmap );
}

bool
ShapeObject::UpdateTransform( const Matrix& parentToDstSpace )
{
Expand Down Expand Up @@ -271,12 +302,25 @@ ShapeObject::SetSelfBounds( Real width, Real height )
void
ShapeObject::DidSetMask( BitmapMask *mask, Uniform *uniform )
{
Texture *maskTexture = ( mask ? mask->GetPaint()->GetTexture() : NULL );
Rtt_ASSERT( !mask || mask->GetPaint() || mask->GetOnlyForHitTests() );

Texture *maskTexture = ( mask && !mask->GetOnlyForHitTests() ? mask->GetPaint()->GetTexture() : NULL );

fFillData.fMaskTexture = maskTexture;
fFillData.fMaskUniform = uniform;
fStrokeData.fMaskTexture = maskTexture;
fStrokeData.fMaskUniform = uniform;

if ( mask && !mask->GetPaint() )
{
const BitmapPaint *bitmapPaint = GetBitmapPaint();

if ( bitmapPaint )
{
SetMaskGeometricProperty( kScaleX, GetGeometricProperty( kWidth ) / bitmapPaint->GetBitmap()->Width() );
SetMaskGeometricProperty( kScaleY, GetGeometricProperty( kHeight ) / bitmapPaint->GetBitmap()->Height() );
}
}
}

void
Expand Down Expand Up @@ -315,6 +359,21 @@ ShapeObject::SetFill( Paint* newValue )
fPath->SetFill( newValue );

DidChangePaint( fFillData );

BitmapMask *mask = GetMask();

if ( mask && !mask->GetPaint() )
{
Rtt_ASSERT( mask->GetOnlyForHitTests() );

const BitmapPaint *paint = GetBitmapPaint();

if ( paint )
{
SetMaskGeometricProperty( kScaleX, GetGeometricProperty( kWidth ) / paint->GetBitmap()->Width() );
SetMaskGeometricProperty( kScaleY, GetGeometricProperty( kHeight ) / paint->GetBitmap()->Height() );
}
}
}

void
Expand Down
Loading