* Fix azimuth position
* App crashes caused by Apple Pencil touches
* Missed code from ReticleView class
This commit is contained in:
olegoid 2016-01-07 19:57:03 -03:00
Родитель 76ccd514df
Коммит bed745dea5
5 изменённых файлов: 42 добавлений и 35 удалений

Просмотреть файл

@ -86,7 +86,7 @@ namespace TouchCanvas {
if (needsFullRedraw) {
SetFrozenImageNeedsUpdate ();
FrozenContext.ClearRect (Bounds);
foreach (var line in finishedLines) {
foreach (var line in finishedLines.Union (lines)) {
line.DrawCommitedPointsInContext (context, IsDebuggingEnabled, UsePreciseLocations);
}
@ -122,7 +122,7 @@ namespace TouchCanvas {
line = AddActiveLineForTouch (touch);
updateRect = updateRect.UnionWith (line.RemovePointsWithType (PointType.Predicted));
var coalescedTouches = evt.GetCoalescedTouches (touch);
var coalescedTouches = evt.GetCoalescedTouches (touch) ?? new UITouch[0];
var coalescedRect = AddPointsOfType (PointType.Coalesced, coalescedTouches, line, updateRect);
updateRect = updateRect.UnionWith (coalescedRect);
@ -132,8 +132,8 @@ namespace TouchCanvas {
updateRect = updateRect.UnionWith (predictedRect);
}
}
SetNeedsDisplayInRect (updateRect);
SetNeedsDisplay ();
// SetNeedsDisplayInRect (updateRect);
}
Line AddActiveLineForTouch (UITouch touch)
@ -166,7 +166,7 @@ namespace TouchCanvas {
}
var touchRect = line.AddPointOfType (type, touch);
accumulatedRect.UnionWith (touchRect);
accumulatedRect = accumulatedRect.UnionWith (touchRect);
CommitLine (line);
}
@ -191,7 +191,7 @@ namespace TouchCanvas {
if (cancel)
updateRect = updateRect.UnionWith (line.Cancel ());
if (line.IsComplete || !isTouchUpdatingEnabled) {
if (line.IsComplete) {
FinishLine (line);
} else {
pendingLines.Add (touch, line);
@ -216,7 +216,8 @@ namespace TouchCanvas {
return;
var updateResult = possibleLine.UpdateWithTouch (touch);
SetNeedsDisplayInRect (updateResult.Value);
if (updateResult.Key)
SetNeedsDisplayInRect (updateResult.Value);
// If this update updated the last point requiring an update, move the line to the `frozenImage`.
if (isPending && possibleLine.IsComplete) {

Просмотреть файл

@ -35,7 +35,7 @@ namespace TouchCanvas {
try {
return (T)(object)(((int)(object)type & ~(int)(object)value));
} catch (Exception ex) {
throw new ArgumentException ( string.Format ("Could not remove value from enumerated type '{0}'.", typeof(T).Name), ex);
return value;
}
}
}

Просмотреть файл

@ -22,25 +22,22 @@ namespace TouchCanvas {
public KeyValuePair<bool, CGRect> UpdateWithTouch (UITouch touch)
{
var emptyResult = new KeyValuePair<bool, CGRect> (false, CGRect.Empty);
LinePoint point;
if (!pointsWaitingForUpdatesByEstimationIndex.TryGetValue (touch.EstimationUpdateIndex, out point))
return emptyResult;
var estimationUpdateIndex = touch.EstimationUpdateIndex;
var point = pointsWaitingForUpdatesByEstimationIndex[estimationUpdateIndex];
if (point != null) {
var rect = UpdateRectForExistingPoint (point);
var didUpdate = point.UpdateWithTouch (touch);
if (didUpdate)
rect = rect.UnionWith (UpdateRectForExistingPoint (point));
if (point.EstimatedPropertiesExpectingUpdates == 0)
pointsWaitingForUpdatesByEstimationIndex.Remove (touch.EstimationUpdateIndex);
if (point.EstimatedPropertiesExpectingUpdates == 0) {
pointsWaitingForUpdatesByEstimationIndex.Remove (estimationUpdateIndex);
}
return new KeyValuePair<bool, CGRect> (didUpdate, rect);
}
return emptyResult;
return new KeyValuePair<bool, CGRect> (false, CGRect.Empty);
}
public CGRect AddPointOfType (PointType pointType, UITouch touch)
@ -70,10 +67,11 @@ namespace TouchCanvas {
if (priorPoint != null)
rect = rect.UnionWith (UpdateRectForLinePoint (priorPoint));
updateRect = updateRect.UnionWith (rect);
} else {
keepPoints.Add (point);
}
priorPoint = point;
keepPoints.Add (point);
}
Points = keepPoints;
@ -119,7 +117,7 @@ namespace TouchCanvas {
color = UIColor.Blue;
} else {
if (pointType.Has (PointType.Cancelled))
color = UIColor.Clear;
color = UIColor.Red;
else if (pointType.Has (PointType.Finger))
color = UIColor.Purple;
@ -240,10 +238,10 @@ namespace TouchCanvas {
var rect = UpdateRectForLinePoint (point);
var arrayIndex = point.SequenceNumber - Points.First ().SequenceNumber;
if (arrayIndex > 0)
if (arrayIndex > 0 && arrayIndex + 1 < Points.Count)
rect = rect.UnionWith (UpdateRectForLinePoint (point, Points[arrayIndex - 1]));
if (arrayIndex + 1 < Points.Count)
if (arrayIndex + 1 < Points.Count && arrayIndex + 1 > 0)
rect = rect.UnionWith (UpdateRectForLinePoint (point, Points[arrayIndex + 1]));
return rect;

Просмотреть файл

@ -108,7 +108,7 @@ namespace TouchCanvas {
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations ()
{
return UIInterfaceOrientationMask.LandscapeRight | UIInterfaceOrientationMask.LandscapeRight;
return UIInterfaceOrientationMask.LandscapeRight | UIInterfaceOrientationMask.LandscapeLeft;
}
partial void ClearView (UIBarButtonItem sender)
@ -136,26 +136,26 @@ namespace TouchCanvas {
void UpdateReticleView (UITouch touch, bool predicated = false)
{
if (touch.Type != UITouchType.Stylus)
if (touch == null || touch.Type != UITouchType.Stylus)
return;
ReticleView.PredictedDotLayer.Hidden = !predicated;
ReticleView.PredictedLineLayer.Hidden = !predicated;
var azimuthAngle = touch.GetAzimuthAngle (touch.View);
var azimuthUnitVector = touch.GetAzimuthUnitVector (touch.View);
var azimuthAngle = touch.GetAzimuthAngle (View);
var azimuthUnitVector = touch.GetAzimuthUnitVector (View);
var altitudeAngle = touch.AltitudeAngle;
if (predicated) {
ReticleView.PredictedAzimuthAngle = azimuthAngle;
ReticleView.PredictedAzimuthUnitVector = azimuthUnitVector;
ReticleView.PredictedAzimuthAngle = altitudeAngle;
ReticleView.PredictedAltitudeAngle = altitudeAngle;
} else {
var location = touch.PreviousLocationInView (View);
ReticleView.Center = location;
ReticleView.ActualAzimuthAngle = azimuthAngle;
ReticleView.ActualAzimuthUnitVector = azimuthUnitVector;
ReticleView.ActualAzimuthAngle = altitudeAngle;
ReticleView.ActualAltitudeAngle = altitudeAngle;
}
}
}

Просмотреть файл

@ -20,6 +20,12 @@ namespace TouchCanvas {
CALayer lineLayer = new CALayer ();
UIColor indicatorColor = UIColor.Red;
public override CGSize IntrinsicContentSize {
get {
return reticleImage.Size;
}
}
readonly CALayer predictedDotLayer = new CALayer ();
public CALayer PredictedDotLayer {
get {
@ -102,6 +108,8 @@ namespace TouchCanvas {
public ReticleView (CGRect frame) : base (frame)
{
ContentScaleFactor = UIScreen.MainScreen.Scale;
reticleLayer.ContentsGravity = CALayer.GravityCenter;
reticleLayer.Position = Layer.Position;
Layer.AddSublayer (reticleLayer);
@ -151,7 +159,7 @@ namespace TouchCanvas {
var transform = CGAffineTransform.MakeIdentity ();
for (int i = 0; i < 4; i++) {
path.MoveToPoint (transform, radius * 0.5f, 0f);
path.MoveToPoint (transform, radius * .5f, 0f);
path.AddLineToPoint (transform, radius * 1.15f, 0);
transform.Rotate (NMath.PI / 2f);
}
@ -176,7 +184,7 @@ namespace TouchCanvas {
LayoutIndicatorForAzimuthAngle (actualAzimuthAngle, actualAzimuthUnitVector, actualAltitudeAngle, lineLayer, dotLayer);
}
void LayoutIndicatorForAzimuthAngle (nfloat azimuthAngle, CGVector azimuthUnitVector, nfloat altitudeAngle, CALayer lineLayer, CALayer dotLayer)
void LayoutIndicatorForAzimuthAngle (nfloat azimuthAngle, CGVector azimuthUnitVector, nfloat altitudeAngle, CALayer targetLineLayer, CALayer targetDotLayer)
{
var reticleBounds = reticleLayer.Bounds;
var centeringTransform = CGAffineTransform.MakeTranslation (reticleBounds.Width / 2f, reticleBounds.Height / 2f);
@ -185,16 +193,16 @@ namespace TouchCanvas {
// Draw the indicator opposite the azimuth by rotating pi radians, for easy visualization.
rotationTransform = CGAffineTransform.Rotate (rotationTransform, NMath.PI);
var altitudeRadius = (1f - altitudeAngle / (NMath.PI / 2f) * radius);
var altitudeRadius = (1f - altitudeAngle / NMath.PI / 2f) * radius;
var lineTransform = CGAffineTransform.MakeScale (altitudeRadius, 1);
lineTransform.Multiply (rotationTransform);
lineTransform.Multiply (centeringTransform);
lineLayer.AffineTransform = lineTransform;
lineTransform = CGAffineTransform.Multiply (lineTransform, rotationTransform);
lineTransform = CGAffineTransform.Multiply (lineTransform, centeringTransform);
targetLineLayer.AffineTransform = lineTransform;
var dotTransform = CGAffineTransform.MakeTranslation (-azimuthUnitVector.dx * altitudeRadius, -azimuthUnitVector.dy * altitudeRadius);
dotTransform.Multiply (centeringTransform);
dotLayer.AffineTransform = dotTransform;
dotTransform = CGAffineTransform.Multiply (dotTransform, centeringTransform);
targetDotLayer.AffineTransform = dotTransform;
}
static void ConfigureDotLayer (CALayer targetLayer, UIColor color)