Beispiel #1
0
        LetterWheelLetter LtrFromArgs(MouseEventArgs args)
        {
            var pt = args.GetPosition(this);
            LetterWheelLetter ltrUnderMouse = null;
            var x = this.InputHitTest(pt);

            if (x != null)
            {
                if (x is TextBlock)
                {
                    ltrUnderMouse = VisualTreeHelper.GetParent(x as TextBlock) as LetterWheelLetter;
                }
                else if (x is LetterWheelLetter)
                {
                    ltrUnderMouse = x as LetterWheelLetter;
                }
                else if (x is Ellipse)
                {
                    if (!_mouseIsDown) // for the 1st mousedown, we'll allow a larger area
                    {
                        // calc x,y with circCtr as origin
                        var ptInCirc = new Point(pt.X - _ptCircleCtr.X, _ptCircleCtr.Y - pt.Y);

                        //var radsPerLetter = (2 * Math.PI / NumLtrs);
                        //var theta = Math.Atan2(ptInCirc.Y, ptInCirc.X);
                        //if (theta < 0)
                        //{
                        //    theta += 2 * Math.PI;
                        //}
                        //var ltrWheelNdx = (theta / (radsPerLetter));
                        //ltrUnderMouse = Children.OfType<LetterWheelLetter>().Skip((int)(ltrWheelNdx)).First();

                        LetterWheelLetter closestLetterWheelLetter = null;
                        var minDist = double.MaxValue;
                        foreach (var ltrWheelLtr in Children.OfType <LetterWheelLetter>())
                        {
                            var pttry = new Point(Canvas.GetLeft(ltrWheelLtr) + ltrWheelLtr.Width / 2 - _ptCircleCtr.X, _ptCircleCtr.Y - Canvas.GetTop(ltrWheelLtr) - ltrWheelLtr.Height / 2); // center of letter
                            var dist  = Math.Sqrt(Math.Pow((pttry.X - ptInCirc.X), 2) + Math.Pow((pttry.Y - ptInCirc.Y), 2));
                            if (dist < minDist)
                            {
                                closestLetterWheelLetter = ltrWheelLtr;
                                minDist = dist;
                            }
                        }
                        if (minDist <= closestLetterWheelLetter.Height)
                        {
                            ltrUnderMouse = closestLetterWheelLetter;
                        }
                    }
                }
            }
            return(ltrUnderMouse);
        }
Beispiel #2
0
        private void CreateCircle()
        {
            this.Children.Clear();
            //            this.Background = Brushes.AliceBlue;
            var circRadius = 110;
            var circ       = new Ellipse()
            {
                Width           = 2 * circRadius,
                Height          = 2 * circRadius,
                Fill            = Brushes.White,
                StrokeThickness = 3,
                Stroke          = Brushes.Black
            };

            _ptCirclePos = new Point(this.ActualWidth / 2 - circ.Width / 2, 0); //new Point(60, 10);
            Canvas.SetLeft(circ, _ptCirclePos.X);
            Canvas.SetTop(circ, _ptCirclePos.Y);

            _ptCircleCtr = new Point(_ptCirclePos.X + circ.Width / 2, _ptCirclePos.Y + circ.Height / 2);
            this.Children.Add(circ);

            int ndx           = 0;
            var radsPerLetter = (2 * Math.PI / NumLtrs);

            foreach (var ltr in _wordCont.InitialWord.ToUpper().OrderBy(p => gridgen._random.NextDouble())) // shuffle
            //                foreach (var ltr in wordCont.InitialWord.ToUpper().OrderBy(p => Guid.NewGuid()))
            {
                var lett = new LetterWheelLetter(ltr);
                _lstLetters.Add(lett);

                var x     = _ptCircleCtr.X + _pctRadiusLettersInCircle * circRadius * Math.Cos(radsPerLetter * ndx) - lett.Width / 2;
                var y     = _ptCircleCtr.Y - _pctRadiusLettersInCircle * circRadius * Math.Sin(radsPerLetter * ndx) - lett.Height / 2;
                var letpt = new Point(x, y);
                Canvas.SetLeft(lett, letpt.X);
                Canvas.SetTop(lett, letpt.Y);
                this.Children.Add(lett);
                ndx++;
            }

            this.Children.Add(polyLine);
        }