MCPcopy Create free account
hub / github.com/carbonengine/trinity / SampleMask

Method SampleMask

trinity/Sprite2d/Tr2Sprite2dPickingMask.cpp:33–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31}
32
33bool Tr2Sprite2dPickingMask::SampleMask( const Vector2& point, const Vector2& topLeft, float width, float height ) const
34{
35 if( !m_mask || !m_mask->IsGood() )
36 {
37 return false;
38 }
39 auto& bitmap = m_mask->GetBitmap();
40 auto mwidth = bitmap.GetWidth();
41 auto mheight = bitmap.GetHeight();
42
43 if( mwidth < m_leftEdge + m_rightEdge )
44 {
45 return false;
46 }
47 if( mheight < m_topEdge + m_bottomEdge )
48 {
49 return false;
50 }
51
52 float x = std::max( 0.f, std::min( width, point.x - 0.5f - topLeft.x ) );
53 float y = std::max( 0.f, std::min( height, point.y - 0.5f - topLeft.y ) );
54
55 uint32_t px, py;
56
57 if( x < m_leftEdge )
58 {
59 px = uint32_t( x );
60 }
61 else if( x >= width - m_rightEdge )
62 {
63 px = std::min( mwidth - uint32_t( width - x ), mwidth - 1 );
64 }
65 else
66 {
67 if( mwidth == m_leftEdge + m_rightEdge )
68 {
69 px = m_leftEdge;
70 }
71 else
72 {
73 px = std::min( uint32_t( ( x - m_leftEdge ) / ( width - m_leftEdge - m_rightEdge ) * ( mwidth - m_leftEdge - m_rightEdge ) + m_leftEdge ), mwidth - 1 );
74 }
75 }
76
77 if( y < m_topEdge )
78 {
79 py = uint32_t( y );
80 }
81 else if( y >= height - m_bottomEdge )
82 {
83 py = std::min( mheight - uint32_t( height - y ), mheight - 1 );
84 }
85 else
86 {
87 if( mheight == m_topEdge + m_bottomEdge )
88 {
89 py = m_topEdge;
90 }

Callers 9

PickPointMethod · 0.80
PickPointMethod · 0.80
PickPointMethod · 0.80
PickPointMethod · 0.80
PickPointMethod · 0.80
PickPointMethod · 0.80
PickPointMethod · 0.80
PickPointMethod · 0.80
PickPointMethod · 0.80

Calls 5

GetPixelMethod · 0.80
IsGoodMethod · 0.45
GetWidthMethod · 0.45
GetHeightMethod · 0.45
GetFormatMethod · 0.45

Tested by

no test coverage detected