@@ -335,31 +335,13 @@ - (void) setScrollPosition:(CGPoint)newPos
335
335
336
336
- (void ) setScrollPosition : (CGPoint)newPos animated : (BOOL )animated
337
337
{
338
+ // Check bounds
339
+ newPos.x = MAX (MIN (newPos.x , self.maxScrollX ), self.minScrollX );
340
+ newPos.y = MAX (MIN (newPos.y , self.maxScrollY ), self.minScrollY );
341
+
338
342
BOOL xMoved = (newPos.x != self.scrollPosition .x );
339
343
BOOL yMoved = (newPos.y != self.scrollPosition .y );
340
-
341
- // Check bounds
342
- if (newPos.x > self.maxScrollX )
343
- {
344
- newPos.x = self.maxScrollX ;
345
- xMoved = YES ;
346
- }
347
- if (newPos.x < self.minScrollX )
348
- {
349
- newPos.x = self.minScrollX ;
350
- xMoved = YES ;
351
- }
352
- if (newPos.y > self.maxScrollY )
353
- {
354
- newPos.y = self.maxScrollY ;
355
- yMoved = YES ;
356
- }
357
- if (newPos.y < self.minScrollY )
358
- {
359
- newPos.y = self.minScrollY ;
360
- yMoved = YES ;
361
- }
362
-
344
+
363
345
if (animated)
364
346
{
365
347
CGPoint oldPos = self.scrollPosition ;
@@ -749,11 +731,35 @@ - (void) onExitTransitionDidStart
749
731
750
732
- (void )scrollWheel : (NSEvent *)theEvent
751
733
{
752
- CCDirector* dir = [CCDirector sharedDirector ];
753
-
734
+ CCDirector* dir = [CCDirector sharedDirector ];
735
+
754
736
float deltaX = theEvent.deltaX ;
755
737
float deltaY = theEvent.deltaY ;
756
-
738
+
739
+ [self scrollViewDidScroll ];
740
+
741
+ switch (theEvent.phase ) {
742
+ case NSEventPhaseBegan:
743
+ [self scrollViewWillBeginDragging ];
744
+ break ;
745
+ case NSEventPhaseEnded:
746
+ // TODO: add logic to determine if it will decelerate
747
+ [self scrollViewDidEndDraggingAndWillDecelerate: YES ];
748
+ default :
749
+ break ;
750
+ }
751
+
752
+ switch (theEvent.momentumPhase ) {
753
+ case NSEventPhaseBegan:
754
+ [self scrollViewWillBeginDecelerating ];
755
+ break ;
756
+ case NSEventPhaseEnded:
757
+ [self scrollViewDidEndDecelerating ];
758
+ default :
759
+ break ;
760
+ }
761
+
762
+
757
763
// Calculate the delta in node space
758
764
CGPoint ref = [dir convertToGL: CGPointZero];
759
765
ref = [self convertToNodeSpace: ref];
@@ -824,4 +830,46 @@ - (void)scrollWheel:(NSEvent *)theEvent
824
830
825
831
#endif
826
832
833
+
834
+ #pragma mark - CCScrollViewDelegate Helpers
835
+
836
+ - (void )scrollViewDidScroll
837
+ {
838
+ if ( [self .delegate respondsToSelector: @selector (scrollViewDidScroll: )] )
839
+ {
840
+ [self .delegate scrollViewDidScroll: self ];
841
+ }
842
+ }
843
+
844
+ - (void )scrollViewWillBeginDragging
845
+ {
846
+ if ( [self .delegate respondsToSelector: @selector (scrollViewWillBeginDragging: )])
847
+ {
848
+ [self .delegate scrollViewWillBeginDragging: self ];
849
+ }
850
+ }
851
+ - (void )scrollViewDidEndDraggingAndWillDecelerate : (BOOL )decelerate
852
+ {
853
+ if ([self .delegate respondsToSelector: @selector (scrollViewDidEndDragging:willDecelerate: )])
854
+ {
855
+ [self .delegate scrollViewDidEndDragging: self
856
+ willDecelerate: decelerate];
857
+ }
858
+ }
859
+ - (void )scrollViewWillBeginDecelerating
860
+ {
861
+ if ( [self .delegate respondsToSelector: @selector (scrollViewWillBeginDecelerating: )])
862
+ {
863
+ [self .delegate scrollViewWillBeginDecelerating: self ];
864
+ }
865
+
866
+ }
867
+ - (void )scrollViewDidEndDecelerating
868
+ {
869
+ if ( [self .delegate respondsToSelector: @selector (scrollViewDidEndDecelerating: )])
870
+ {
871
+ [self .delegate scrollViewDidEndDecelerating: self ];
872
+ }
873
+ }
874
+
827
875
@end
0 commit comments