Skip to content

Commit 997bad1

Browse files
committed
Add separators to DigitalClockFace. Implement minor improvemnts
1 parent 1f66be0 commit 997bad1

File tree

1,600 files changed

+794
-50209
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,600 files changed

+794
-50209
lines changed

BionicCode.Net/BionicCode.Controls.Net.Wpf/AnalogClockFace.cs

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ public double SecondHandDiameter
516516
private bool IsHourDragPickingEnabled { get; set; }
517517
private bool IsMinuteDragPickingEnabled { get; set; }
518518
private bool IsSecondsDragPickingEnabled { get; set; }
519+
private bool IsClockFaceInitialized { get; set; }
519520

520521
static AnalogClockFace()
521522
{
@@ -575,16 +576,6 @@ private void InitializeClockRotateTransforms()
575576

576577
#region Overrides of FrameworkElement
577578

578-
/// <inheritdoc />
579-
protected override void OnInitialized(EventArgs e)
580-
{
581-
base.OnInitialized(e);
582-
}
583-
584-
#endregion
585-
586-
#region Overrides of FrameworkElement
587-
588579
/// <inheritdoc />
589580
protected override Size MeasureOverride(Size constraint)
590581
{
@@ -599,15 +590,19 @@ protected override Size MeasureOverride(Size constraint)
599590
/// <inheritdoc />
600591
protected override Size ArrangeOverride(Size arrangeBounds)
601592
{
602-
if (this.Is24HModeEnabled || this.IsTimePickerModeEnabled)
593+
if (!this.IsClockFaceInitialized)
603594
{
604-
DrawAnalog24Clock();
605-
}
606-
else
607-
{
608-
DrawAnalogClock();
595+
if (this.Is24HModeEnabled || this.IsTimePickerModeEnabled)
596+
{
597+
DrawAnalog24Clock();
598+
}
599+
else
600+
{
601+
DrawAnalogClock();
602+
}
603+
Draw24HTimePickerSelectionBounds();
604+
this.IsClockFaceInitialized = true;
609605
}
610-
Draw24HTimePickerSelectionBounds();
611606
arrangeBounds = base.ArrangeOverride(arrangeBounds);
612607
return arrangeBounds;
613608
}
@@ -738,6 +733,7 @@ private static void OnDiameterChanged(DependencyObject d, DependencyPropertyChan
738733
var this_ = d as AnalogClockFace;
739734
this_.Radius = (double)e.NewValue / 2;
740735
this_.Center = new Point(this_.Radius, this_.Radius);
736+
this_.IsClockFaceInitialized = false;
741737
}
742738

743739
protected override void OnDateElementChanged(FrameworkElement oldDateElement, FrameworkElement newDateElement)
@@ -770,6 +766,7 @@ protected override void OnDateElementChanged(FrameworkElement oldDateElement, Fr
770766
newDateElement.RenderTransform = this.DateElementTransform;
771767
}
772768

769+
this.IsClockFaceInitialized = false;
773770
base.OnDateElementChanged(oldDateElement, newDateElement);
774771
}
775772

@@ -793,18 +790,21 @@ private static void OnHourHandRadiusChanged(DependencyObject d, DependencyProper
793790
{
794791
var this_ = d as AnalogClockFace;
795792
this_.HourHandDiameter = (double) e.NewValue * 2;
793+
this_.IsClockFaceInitialized = false;
796794
}
797795

798796
private static void OnMinuteHandRadiusChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
799797
{
800798
var this_ = d as AnalogClockFace;
801799
this_.MinuteHandDiameter = (double)e.NewValue * 2;
800+
this_.IsClockFaceInitialized = false;
802801
}
803802

804803
private static void OnSecondHandRadiusChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
805804
{
806805
var this_ = d as AnalogClockFace;
807806
this_.SecondHandDiameter = (double)e.NewValue * 2;
807+
this_.IsClockFaceInitialized = false;
808808
}
809809

810810
private static void OnIsTimePickerModeEnabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
@@ -822,6 +822,7 @@ protected virtual void OnIsTimePickerModeEnabledChanged(bool oldValue, bool newV
822822
{
823823
this.Style = FindResource(AnalogClockFace.DefaultAnalogClockFaceStyleKey) as Style;
824824
}
825+
this.IsClockFaceInitialized = false;
825826
}
826827

827828
protected override void OnSelectedHourChanged(double oldValue, double newValue)
@@ -907,6 +908,7 @@ protected virtual void OnHourHandElementChanged(FrameworkElement oldClockHand, F
907908
{
908909
newClockHand.RenderTransform = this.HourHandTransform;
909910
}
911+
this.IsClockFaceInitialized = false;
910912
AddElementToClockFace(newClockHand, new Point(Canvas.GetLeft(newClockHand), Canvas.GetTop(newClockHand)));
911913
}
912914

@@ -939,6 +941,7 @@ protected virtual void OnMinuteHandElementChanged(FrameworkElement oldClockHand,
939941
{
940942
newClockHand.RenderTransform = this.MinuteHandTransform;
941943
}
944+
this.IsClockFaceInitialized = false;
942945
AddElementToClockFace(newClockHand, new Point(Canvas.GetLeft(newClockHand), Canvas.GetTop(newClockHand)));
943946
}
944947

@@ -971,6 +974,7 @@ protected virtual void OnSecondHandElementChanged(FrameworkElement oldClockHand,
971974
{
972975
newClockHand.RenderTransform = this.SecondHandTransform;
973976
}
977+
this.IsClockFaceInitialized = false;
974978
AddElementToClockFace(newClockHand, new Point(Canvas.GetLeft(newClockHand), Canvas.GetTop(newClockHand)));
975979
}
976980

@@ -1283,7 +1287,9 @@ private void DrawClockFaceBackground()
12831287
clockFaceBackgroundPosition.Offset(deltaToMiddleRadius / 2, deltaToMiddleRadius / 2);
12841288
var ellipse = new Ellipse()
12851289
{
1286-
Height = this.Diameter - deltaToMiddleRadius, Width = this.Diameter - deltaToMiddleRadius, Fill = this.Background
1290+
Height = this.Diameter - deltaToMiddleRadius,
1291+
Width = this.Diameter - deltaToMiddleRadius,
1292+
Fill = this.Background
12871293
};
12881294
AddElementToClockFace(ellipse, clockFaceBackgroundPosition, 0);
12891295
}

BionicCode.Net/BionicCode.Controls.Net.Wpf/ClockFace.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ protected ClockFace()
199199
{
200200
RenderTransform = this.ClockFaceScaleTransform,
201201
Background = Brushes.Transparent,
202-
Width = this.Width,
203-
Height = this.Height,
202+
Width = 0,
203+
Height = 0,
204204
HorizontalAlignment = HorizontalAlignment.Left,
205205
VerticalAlignment = VerticalAlignment.Top
206206
};
@@ -209,7 +209,7 @@ protected ClockFace()
209209
protected virtual Point ScaleClockFaceOverride(Size arrangeBounds)
210210
{
211211
Size requiredSize = GetNaturalSize();
212-
if (requiredSize.Equals(new Size()))
212+
if (requiredSize.Equals(new Size()) || requiredSize.Equals(arrangeBounds) || !IsValidArrangeSize(arrangeBounds) ||!IsValidArrangeSize(requiredSize))
213213
{
214214
return new Point(1, 1);
215215
}
@@ -253,6 +253,8 @@ protected virtual Point ScaleClockFaceOverride(Size arrangeBounds)
253253
return new Point(horizontalScaleFactor, verticalScaleFactor);
254254
}
255255

256+
protected bool IsValidArrangeSize(Size arrangeBounds) => !arrangeBounds.IsEmpty && double.IsNormal(arrangeBounds.Width) && double.IsNormal(arrangeBounds.Height);
257+
256258
protected virtual Size GetNaturalSize() => new Size(this.ClockFaceCanvas.DesiredSize.Width, this.ClockFaceCanvas.DesiredSize.Height);
257259

258260
private static object CoerceHours(DependencyObject d, object basevalue)
@@ -485,8 +487,12 @@ public void AddElementToClockFace(FrameworkElement clockElement, Point screenPoi
485487
public override void OnApplyTemplate()
486488
{
487489
base.OnApplyTemplate();
488-
var panelHost = GetTemplateChild("PART_HostPanel") as Panel;
489-
panelHost.Children.Add(this.ClockFaceCanvas);
490+
var hostPanel = GetTemplateChild("PART_HostPanel") as Panel;
491+
if (hostPanel == null)
492+
{
493+
throw new InvalidOperationException("Template part 'PART_HostPanel' of type 'Panel' not found");
494+
}
495+
hostPanel.Children.Add(this.ClockFaceCanvas);
490496
}
491497

492498
#endregion
@@ -496,8 +502,11 @@ public override void OnApplyTemplate()
496502
/// <inheritdoc />
497503
protected override Size MeasureOverride(Size constraint)
498504
{
499-
this.ClockFaceCanvas.Width = constraint.Width;
500-
this.ClockFaceCanvas.Height = constraint.Height;
505+
if (!IsValidArrangeSize(constraint))
506+
{
507+
constraint = GetNaturalSize();
508+
}
509+
501510
return constraint;
502511
}
503512

BionicCode.Net/BionicCode.Controls.Net.Wpf/DigitSegment.cs

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
using System.Windows;
99
using System.Windows.Media;
10+
using System.Windows.Media.Converters;
1011
using System.Windows.Shapes;
1112

1213
namespace BionicCode.Controls.Net.Wpf
@@ -31,7 +32,7 @@ public abstract class DigitSegment : Shape
3132
"IsOn",
3233
typeof(bool),
3334
typeof(DigitSegment),
34-
new PropertyMetadata(default(bool)));
35+
new PropertyMetadata(default(bool), DigitSegment.OnIsOnChanged));
3536

3637
public bool IsOn { get => (bool)GetValue(DigitSegment.IsOnProperty); set => SetValue(DigitSegment.IsOnProperty, value); }
3738

@@ -43,7 +44,7 @@ public abstract class DigitSegment : Shape
4344
"OnColor",
4445
typeof(Brush),
4546
typeof(DigitSegment),
46-
new PropertyMetadata(default(Brush)));
47+
new PropertyMetadata(default, DigitSegment.OnOnColorChanged));
4748

4849
public Brush OnColor { get => (Brush)GetValue(DigitSegment.OnColorProperty); set => SetValue(DigitSegment.OnColorProperty, value); }
4950

@@ -55,7 +56,7 @@ public abstract class DigitSegment : Shape
5556
"OffColor",
5657
typeof(Brush),
5758
typeof(DigitSegment),
58-
new PropertyMetadata(default(Brush)));
59+
new PropertyMetadata(default, DigitSegment.OnOffColorChanged));
5960

6061
public Brush OffColor { get => (Brush)GetValue(DigitSegment.OffColorProperty); set => SetValue(DigitSegment.OffColorProperty, value); }
6162

@@ -76,12 +77,13 @@ public abstract class DigitSegment : Shape
7677

7778
#endregion TiltAngle dependency property
7879

80+
protected Rect Bounds { get; set; }
81+
7982
protected DigitSegment()
8083
{
8184
}
8285

8386
protected abstract Geometry CreateGeometry();
84-
protected Rect Bounds { get; set; }
8587

8688
#region Overrides of Shape
8789

@@ -95,6 +97,59 @@ protected override Size MeasureOverride(Size constraint)
9597
return base.MeasureOverride(constraint);
9698
}
9799

100+
/// <inheritdoc />
101+
protected override Size ArrangeOverride(Size finalSize)
102+
{
103+
LightSegment(this.IsOn);
104+
return base.ArrangeOverride(finalSize);
105+
}
106+
98107
#endregion
108+
109+
#region OnIsOnChanged dependency property changed handler
110+
111+
private static void OnIsOnChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) =>
112+
(d as DigitSegment).OnIsOnChanged((bool) e.OldValue, (bool) e.NewValue);
113+
114+
protected virtual void OnIsOnChanged(bool oldValue, bool newValue) => LightSegment(newValue);
115+
116+
#endregion OnIsOnChanged dependency property changed handler
117+
118+
#region OnOnColorChanged dependency property changed handler
119+
120+
private static void OnOnColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) =>
121+
(d as DigitSegment).OnOnColorChanged((Brush) e.OldValue, (Brush) e.NewValue);
122+
123+
protected virtual void OnOnColorChanged(Brush oldValue, Brush newValue)
124+
{
125+
if (this.IsOn)
126+
{
127+
LightSegment(true);
128+
}
129+
}
130+
131+
#endregion OnOnColorChanged dependency property changed handler
132+
133+
#region OnOffColorChanged dependency property changed handler
134+
135+
private static void OnOffColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) =>
136+
(d as DigitSegment).OnOffColorChanged((Brush) e.OldValue, (Brush) e.NewValue);
137+
138+
protected virtual void OnOffColorChanged(Brush oldValue, Brush newValue)
139+
{
140+
if (!this.IsOn)
141+
{
142+
LightSegment(false);
143+
}
144+
}
145+
146+
#endregion OnOffColorChanged dependency property changed handler
147+
148+
protected Brush LightSegment(bool newValue)
149+
{
150+
return this.Fill = newValue
151+
? this.OnColor
152+
: this.OffColor;
153+
}
99154
}
100155
}

0 commit comments

Comments
 (0)