@@ -92,7 +92,7 @@ _isInterceptTouch(false),
92
92
_loopFocus (false ),
93
93
_passFocusToChild (true ),
94
94
_isFocusPassing (false ),
95
- _stencilRadius (0 .0f )
95
+ _stencilRadius (0 .0f )
96
96
{
97
97
// no-op
98
98
}
@@ -235,7 +235,11 @@ void Layout::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t par
235
235
{
236
236
return ;
237
237
}
238
-
238
+
239
+ // STEVE: https://github.com/cocos2d/cocos2d-x/pull/18651/files
240
+ if (FLAGS_TRANSFORM_DIRTY & parentFlags || _transformUpdated || _contentSizeDirty)
241
+ _clippingRectDirty = true ;
242
+
239
243
adaptRenderers ();
240
244
doLayout ();
241
245
@@ -255,7 +259,11 @@ void Layout::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t par
255
259
}
256
260
else
257
261
{
258
- Widget::visit (renderer, parentTransform, parentFlags);
262
+ // Widget::visit(renderer, parentTransform, parentFlags);
263
+
264
+ // STEVE: https://github.com/cocos2d/cocos2d-x/pull/18651/files
265
+ // no need to adapt render again
266
+ ProtectedNode::visit (renderer, parentTransform, parentFlags);
259
267
}
260
268
}
261
269
@@ -460,10 +468,21 @@ const Rect& Layout::getClippingRect()
460
468
{
461
469
if (_clippingRectDirty)
462
470
{
463
- Vec2 worldPos = convertToWorldSpace (Vec2::ZERO);
464
- AffineTransform t = getNodeToWorldAffineTransform ();
465
- float scissorWidth = _contentSize.width *t.a ;
466
- float scissorHeight = _contentSize.height *t.d ;
471
+ // STEVE: https://github.com/cocos2d/cocos2d-x/pull/18651/files
472
+ // Vec2 worldPos = convertToWorldSpace(Vec2::ZERO);
473
+ // AffineTransform t = getNodeToWorldAffineTransform();
474
+
475
+ Vec2 worldPos1 = convertToWorldSpace (Vec2::ZERO);
476
+ Vec2 worldPos2 = convertToWorldSpace (Vec2 (_contentSize.width , _contentSize.height ));
477
+ // Node can be flipped
478
+ Vec2 worldPos = Vec2 (std::min (worldPos1.x , worldPos2.x ), std::min (worldPos1.y , worldPos2.y ));
479
+
480
+ // STEVE: https://github.com/cocos2d/cocos2d-x/pull/18651/files
481
+ // float scissorWidth = _contentSize.width*t.a;
482
+ // float scissorHeight = _contentSize.height*t.d;
483
+ float scissorWidth = fabs (worldPos2.x - worldPos1.x );
484
+ float scissorHeight = fabs (worldPos2.y - worldPos1.y );
485
+
467
486
Rect parentClippingRect;
468
487
Layout* parent = this ;
469
488
@@ -479,54 +498,80 @@ const Rect& Layout::getClippingRect()
479
498
}
480
499
}
481
500
}
482
-
501
+
502
+ // STEVE: https://github.com/cocos2d/cocos2d-x/pull/18651/files
503
+ // if (_clippingParent)
504
+ // {
505
+ // parentClippingRect = _clippingParent->getClippingRect();
506
+ // float finalX = worldPos.x - (scissorWidth * _anchorPoint.x);
507
+ // float finalY = worldPos.y - (scissorHeight * _anchorPoint.y);
508
+ // float finalWidth = scissorWidth;
509
+ // float finalHeight = scissorHeight;
510
+ //
511
+ // float leftOffset = worldPos.x - parentClippingRect.origin.x;
512
+ // if (leftOffset < 0.0f)
513
+ // {
514
+ // finalX = parentClippingRect.origin.x;
515
+ // finalWidth += leftOffset;
516
+ // }
517
+ // float rightOffset = (worldPos.x + scissorWidth) - (parentClippingRect.origin.x + parentClippingRect.size.width);
518
+ // if (rightOffset > 0.0f)
519
+ // {
520
+ // finalWidth -= rightOffset;
521
+ // }
522
+ // float topOffset = (worldPos.y + scissorHeight) - (parentClippingRect.origin.y + parentClippingRect.size.height);
523
+ // if (topOffset > 0.0f)
524
+ // {
525
+ // finalHeight -= topOffset;
526
+ // }
527
+ // float bottomOffset = worldPos.y - parentClippingRect.origin.y;
528
+ // if (bottomOffset < 0.0f)
529
+ // {
530
+ // finalY = parentClippingRect.origin.y;
531
+ // finalHeight += bottomOffset;
532
+ // }
533
+ // if (finalWidth < 0.0f)
534
+ // {
535
+ // finalWidth = 0.0f;
536
+ // }
537
+ // if (finalHeight < 0.0f)
538
+ // {
539
+ // finalHeight = 0.0f;
540
+ // }
541
+ // _clippingRect.origin.x = finalX;
542
+ // _clippingRect.origin.y = finalY;
543
+ // _clippingRect.size.width = finalWidth;
544
+ // _clippingRect.size.height = finalHeight;
545
+ // }
546
+ // else
547
+ // {
548
+ // _clippingRect.origin.x = worldPos.x - (scissorWidth * _anchorPoint.x);
549
+ // _clippingRect.origin.y = worldPos.y - (scissorHeight * _anchorPoint.y);
550
+ // _clippingRect.size.width = scissorWidth;
551
+ // _clippingRect.size.height = scissorHeight;
552
+ // }
553
+ // _clippingRectDirty = false;
554
+
483
555
if (_clippingParent)
484
556
{
485
557
parentClippingRect = _clippingParent->getClippingRect ();
486
- float finalX = worldPos.x - (scissorWidth * _anchorPoint.x );
487
- float finalY = worldPos.y - (scissorHeight * _anchorPoint.y );
488
- float finalWidth = scissorWidth;
489
- float finalHeight = scissorHeight;
490
-
491
- float leftOffset = worldPos.x - parentClippingRect.origin .x ;
492
- if (leftOffset < 0 .0f )
493
- {
494
- finalX = parentClippingRect.origin .x ;
495
- finalWidth += leftOffset;
496
- }
497
- float rightOffset = (worldPos.x + scissorWidth) - (parentClippingRect.origin .x + parentClippingRect.size .width );
498
- if (rightOffset > 0 .0f )
499
- {
500
- finalWidth -= rightOffset;
501
- }
502
- float topOffset = (worldPos.y + scissorHeight) - (parentClippingRect.origin .y + parentClippingRect.size .height );
503
- if (topOffset > 0 .0f )
504
- {
505
- finalHeight -= topOffset;
506
- }
507
- float bottomOffset = worldPos.y - parentClippingRect.origin .y ;
508
- if (bottomOffset < 0 .0f )
509
- {
510
- finalY = parentClippingRect.origin .y ;
511
- finalHeight += bottomOffset;
512
- }
513
- if (finalWidth < 0 .0f )
514
- {
515
- finalWidth = 0 .0f ;
516
- }
517
- if (finalHeight < 0 .0f )
518
- {
519
- finalHeight = 0 .0f ;
520
- }
521
- _clippingRect.origin .x = finalX;
522
- _clippingRect.origin .y = finalY;
523
- _clippingRect.size .width = finalWidth;
524
- _clippingRect.size .height = finalHeight;
558
+
559
+ // STEVE: https://github.com/cocos2d/cocos2d-x/pull/18651/files
560
+ _clippingRect.origin .x = std::max (parentClippingRect.origin .x , worldPos.x );
561
+ _clippingRect.origin .y = std::max (parentClippingRect.origin .y , worldPos.y );
562
+
563
+ float right = std::min (parentClippingRect.origin .x + parentClippingRect.size .width , worldPos.x + scissorWidth);
564
+ float top = std::min (parentClippingRect.origin .y + parentClippingRect.size .height , worldPos.y + scissorHeight);
565
+
566
+ _clippingRect.size .width = std::max (0 .0f , right - _clippingRect.origin .x );
567
+ _clippingRect.size .height = std::max (0 .0f , top - _clippingRect.origin .y );
525
568
}
526
569
else
527
570
{
528
- _clippingRect.origin .x = worldPos.x - (scissorWidth * _anchorPoint.x );
529
- _clippingRect.origin .y = worldPos.y - (scissorHeight * _anchorPoint.y );
571
+ // STEVE: https://github.com/cocos2d/cocos2d-x/pull/18651/files
572
+ _clippingRect.origin .x = worldPos.x ;
573
+ _clippingRect.origin .y = worldPos.y ;
574
+
530
575
_clippingRect.size .width = scissorWidth;
531
576
_clippingRect.size .height = scissorHeight;
532
577
}
0 commit comments