public override void OnReleased(UIElement uiElement, PointerRoutedEventArgs args)
        {
            if (mIsTranslating)
            {
                Matrix3x2 translation = Matrix3x2.Identity;

                var pt = args.GetCurrentPoint(uiElement).Position;
                if (!mStrokeHandler.TransformationMatrix.IsIdentity)
                {
                    bool res = Matrix3x2.Invert(mStrokeHandler.TransformationMatrix, out Matrix3x2 modelTransformationMatrix);

                    if (!res)
                    {
                        throw new InvalidOperationException("Transform matrix could not be inverted.");
                    }

                    Vector2 currentPointPos      = new Vector2((float)pt.X, (float)pt.Y);
                    Vector2 startPos             = new Vector2((float)mStartPosition.X, (float)mStartPosition.Y);
                    Vector2 modelCurrentPointPos = Vector2.Transform(currentPointPos, modelTransformationMatrix);
                    Vector2 modelStartPos        = Vector2.Transform(startPos, modelTransformationMatrix);

                    double dX = modelCurrentPointPos.X - modelStartPos.X;
                    double dY = modelCurrentPointPos.Y - modelStartPos.Y;
                    translation = Matrix3x2.CreateTranslation((float)dX, (float)dY);
                }
                else
                {
                    double dX = pt.X - mStartPosition.X;
                    double dY = pt.Y - mStartPosition.Y;
                    translation = Matrix3x2.CreateTranslation((float)dX, (float)dY);
                }

                TranslateFinished?.Invoke(this, translation);
            }
            else
            {
                base.OnReleased(uiElement, args);
            }

            mIsTranslating = false;
        }
Ejemplo n.º 2
0
 private void Worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     object[] arr = e.Result as object[];
     if (arr[0].ToString() == "done")
     {
         string json = arr[1].ToString();
         GoogleTranslateAPIResponse response = JsonConvert.DeserializeObject <GoogleTranslateAPIResponse>(json);
         if (response != null && response.sentences.Count > 0)
         {
             TranslateFinished?.Invoke(response.sentences[0].trans);
         }
         else
         {
             TranslateFinished?.Invoke("No Suggestion");
         }
     }
     else
     {
         TranslateFinished?.Invoke("No Suggestion");
     }
 }