@@ -625,6 +625,9 @@ public double SecondHandDiameter
625
625
private PathGeometry SelectedSecondArcBounds { get ; set ; }
626
626
private bool IsUpdatingSelectedTimeComponent { get ; set ; }
627
627
private bool IsUpdatingSelectedTime { get ; set ; }
628
+ private bool IsHourDragPickingEnabled { get ; set ; }
629
+ private bool IsMinuteDragPickingEnabled { get ; set ; }
630
+ private bool IsSecondsDragPickingEnabled { get ; set ; }
628
631
629
632
static AnalogClockFace ( )
630
633
{
@@ -742,6 +745,7 @@ protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
742
745
{
743
746
return ;
744
747
}
748
+
745
749
Point screenPoint = e . GetPosition ( this . ClockFaceCanvas ) ;
746
750
var clockAngle = GetAngleFromCartesianPoint ( screenPoint ) ;
747
751
this . IsUpdatingSelectedTimeComponent = true ;
@@ -750,17 +754,20 @@ protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
750
754
switch ( screenPoint )
751
755
{
752
756
case { } when this . SelectedHourArcBounds . FillContains ( screenPoint ) :
757
+ this . IsHourDragPickingEnabled = true ;
753
758
double steps = this . Is24HModeEnabled ? 24 : 12 ;
754
759
degreeOfStep = 360 / steps ;
755
760
double hourValue = Math . Round ( clockAngle / degreeOfStep , MidpointRounding . AwayFromZero ) % steps ;
756
761
this . SelectedHour = hourValue ;
757
762
break ;
758
763
case { } when this . SelectedMinuteArcBounds . FillContains ( screenPoint ) :
764
+ this . IsMinuteDragPickingEnabled = true ;
759
765
degreeOfStep = 360 / 60.0 ;
760
766
double minuteValue = Math . Round ( clockAngle / degreeOfStep , MidpointRounding . AwayFromZero ) % 60 ;
761
767
this . SelectedMinute = minuteValue ;
762
768
break ;
763
769
case { } when this . SelectedSecondArcBounds . FillContains ( screenPoint ) :
770
+ this . IsSecondsDragPickingEnabled = true ;
764
771
degreeOfStep = 360 / 60.0 ;
765
772
double secondValue = Math . Round ( clockAngle / degreeOfStep , MidpointRounding . AwayFromZero ) % 60 ;
766
773
this . SelectedSecond = secondValue ;
@@ -769,6 +776,50 @@ protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
769
776
this . IsUpdatingSelectedTimeComponent = false ;
770
777
}
771
778
779
+ /// <inheritdoc />
780
+ protected override void OnPreviewMouseMove ( MouseEventArgs e )
781
+ {
782
+ base . OnPreviewMouseMove ( e ) ;
783
+ if ( ! this . IsHourDragPickingEnabled && ! IsMinuteDragPickingEnabled && ! IsSecondsDragPickingEnabled )
784
+ {
785
+ return ;
786
+ }
787
+ Point screenPoint = e . GetPosition ( this . ClockFaceCanvas ) ;
788
+ var clockAngle = GetAngleFromCartesianPoint ( screenPoint ) ;
789
+ this . IsUpdatingSelectedTimeComponent = true ;
790
+ double degreeOfStep ;
791
+
792
+ switch ( screenPoint )
793
+ {
794
+ case { } when this . IsHourDragPickingEnabled && this . SelectedHourArcBounds . FillContains ( screenPoint ) :
795
+ double steps = this . Is24HModeEnabled ? 24 : 12 ;
796
+ degreeOfStep = 360 / steps ;
797
+ double hourValue = Math . Round ( clockAngle / degreeOfStep , MidpointRounding . AwayFromZero ) % steps ;
798
+ this . SelectedHour = hourValue ;
799
+ break ;
800
+ case { } when this . IsMinuteDragPickingEnabled && this . SelectedMinuteArcBounds . FillContains ( screenPoint ) :
801
+ degreeOfStep = 360 / 60.0 ;
802
+ double minuteValue = Math . Round ( clockAngle / degreeOfStep , MidpointRounding . AwayFromZero ) % 60 ;
803
+ this . SelectedMinute = minuteValue ;
804
+ break ;
805
+ case { } when this . IsSecondsDragPickingEnabled && this . SelectedSecondArcBounds . FillContains ( screenPoint ) :
806
+ degreeOfStep = 360 / 60.0 ;
807
+ double secondValue = Math . Round ( clockAngle / degreeOfStep , MidpointRounding . AwayFromZero ) % 60 ;
808
+ this . SelectedSecond = secondValue ;
809
+ break ;
810
+ }
811
+ this . IsUpdatingSelectedTimeComponent = false ;
812
+ }
813
+
814
+ /// <inheritdoc />
815
+ protected override void OnPreviewMouseLeftButtonUp ( MouseButtonEventArgs e )
816
+ {
817
+ base . OnPreviewMouseLeftButtonUp ( e ) ;
818
+ this . IsHourDragPickingEnabled = false ;
819
+ this . IsMinuteDragPickingEnabled = false ;
820
+ this . IsSecondsDragPickingEnabled = false ;
821
+ }
822
+
772
823
/// <inheritdoc />
773
824
protected override void OnPreviewMouseWheel ( MouseWheelEventArgs e )
774
825
{
@@ -926,10 +977,18 @@ private static object CoerceHours(DependencyObject d, object basevalue)
926
977
: Math . Truncate ( hourValue ) % 12 ;
927
978
double decimalPart = hourValue - Math . Truncate ( hourValue ) ;
928
979
var decimalMinutes = decimalPart * 60 ;
929
- this_ . SelectedMinute = Math . Truncate ( decimalMinutes ) ;
980
+ bool isOverflow = decimalMinutes >= 1.0 ;
981
+ if ( isOverflow )
982
+ {
983
+ this_ . SelectedMinute = Math . Truncate ( decimalMinutes ) ;
984
+ }
930
985
decimalPart = decimalMinutes - Math . Truncate ( decimalMinutes ) ;
931
- var decimalSeconds = decimalPart * 60 ;
932
- this_ . SelectedSecond = Math . Round ( decimalSeconds , MidpointRounding . AwayFromZero ) ;
986
+ var decimalSeconds = Math . Round ( decimalPart * 60 , MidpointRounding . AwayFromZero ) ;
987
+ isOverflow = decimalSeconds >= 1.0 ;
988
+ if ( isOverflow )
989
+ {
990
+ this_ . SelectedSecond = decimalSeconds ;
991
+ }
933
992
934
993
this_ . IsUpdatingSelectedTimeComponent = false ;
935
994
return hours ;
@@ -946,17 +1005,26 @@ private static object CoerceMinutes(DependencyObject d, object basevalue)
946
1005
this_ . IsUpdatingSelectedTimeComponent = true ;
947
1006
var minuteValue = ( double ) basevalue ;
948
1007
double decimalHours = minuteValue / 60 ;
949
- this_ . SelectedHour = this_ . Is24HModeEnabled
950
- ? Math . Truncate ( decimalHours ) % 24
951
- : Math . Truncate ( decimalHours ) % 12 == 0
952
- ? 12
953
- : Math . Truncate ( decimalHours ) % 12 ;
954
- double decimalPart = decimalHours - Math . Truncate ( decimalHours ) ;
955
- var decimalMinutes = decimalPart * 60 ;
1008
+ bool isOverflow = decimalHours >= 1.0 ;
1009
+ if ( isOverflow )
1010
+ {
1011
+ this_ . SelectedHour = this_ . Is24HModeEnabled
1012
+ ? Math . Truncate ( decimalHours ) % 24
1013
+ : Math . Truncate ( decimalHours ) % 12 == 0
1014
+ ? 12
1015
+ : Math . Truncate ( decimalHours ) % 12 ;
1016
+ }
1017
+
1018
+ var decimalMinutes = minuteValue % 60 ;
956
1019
var minutes = Math . Truncate ( decimalMinutes ) ;
957
- decimalPart = decimalMinutes - Math . Truncate ( decimalMinutes ) ;
958
- double decimalSeconds = decimalPart * 60 ;
959
- this_ . SelectedSecond = Math . Round ( decimalSeconds , MidpointRounding . AwayFromZero ) ;
1020
+
1021
+ var decimalPart = decimalMinutes - Math . Truncate ( decimalMinutes ) ;
1022
+ double decimalSeconds = Math . Round ( decimalPart * 60 , MidpointRounding . AwayFromZero ) ;
1023
+ isOverflow = decimalSeconds >= 1.0 ;
1024
+ if ( isOverflow )
1025
+ {
1026
+ this_ . SelectedSecond = decimalSeconds ;
1027
+ }
960
1028
961
1029
this_ . IsUpdatingSelectedTimeComponent = false ;
962
1030
return minutes ;
@@ -973,16 +1041,25 @@ private static object CoerceSeconds(DependencyObject d, object basevalue)
973
1041
this_ . IsUpdatingSelectedTimeComponent = true ;
974
1042
var secondsValue = ( double ) basevalue ;
975
1043
double decimalHours = secondsValue / 3600 ;
976
- this_ . SelectedHour = this_ . Is24HModeEnabled
977
- ? Math . Truncate ( decimalHours ) % 24
978
- : Math . Truncate ( decimalHours ) % 12 == 0
979
- ? 12
980
- : Math . Truncate ( decimalHours ) % 12 ;
981
- var decimalPart = decimalHours - Math . Truncate ( decimalHours ) ;
982
- double decimalMinutes = decimalPart * 60 ;
983
- this_ . SelectedMinute = Math . Truncate ( decimalMinutes ) ;
984
- decimalPart = decimalMinutes - Math . Truncate ( decimalMinutes ) ;
985
- double decimalSeconds = decimalPart * 60 ;
1044
+ bool isOverflow = decimalHours >= 1.0 ;
1045
+ if ( isOverflow )
1046
+ {
1047
+ this_ . SelectedHour = this_ . Is24HModeEnabled
1048
+ ? Math . Truncate ( decimalHours ) % 24
1049
+ : Math . Truncate ( decimalHours ) % 12 == 0
1050
+ ? 12
1051
+ : Math . Truncate ( decimalHours ) % 12 ;
1052
+ }
1053
+
1054
+ var minutePart = secondsValue % 3600 ;
1055
+ double decimalMinutes = minutePart / 60 ;
1056
+ isOverflow = decimalMinutes >= 1.0 ;
1057
+ if ( isOverflow )
1058
+ {
1059
+ this_ . SelectedMinute = Math . Truncate ( decimalMinutes ) ;
1060
+ }
1061
+
1062
+ double decimalSeconds = minutePart % 60 ;
986
1063
var seconds = Math . Round ( decimalSeconds , MidpointRounding . AwayFromZero ) ;
987
1064
988
1065
this_ . IsUpdatingSelectedTimeComponent = false ;
0 commit comments