Example #1
0
        public Step3Sort()
        {
            var indexInfo = new TextBlock {
                Text = "0/" + Beard.KeysCount, FontSize = .3, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center
            };
            var indexBox = ShadowBox.SquareButton(indexInfo);

            indexBox.Height = indexBox.Width = r * 2;
            Content.Children.Add(indexBox);
            Moveable(indexBox);
            var points = Elements.Visual <Ellipse>(Beard.RawPoints, r);

            Elements.AddClick(indexBox, delegate {
                indexInfo.Text = "0/" + points.Count();
                orderedPoints.Clear();
                foreach (var item in points)
                {
                    item.Fill = Brushes.pending;
                }
                for (int i = Content.Children.Count - 1; i >= 0; i--)
                {
                    var c = Content.Children[i];
                    if (c is Grid && c != indexBox)
                    {
                        Content.Children.RemoveAt(i);
                    }
                    if (c is Ellipse)
                    {
                        (c as Ellipse).Fill = Brushes.pending;
                    }
                }
            }, null);
            Action moveIndexInfo = () => {
                Content.Children.Remove(indexBox);
                Content.Children.Add(indexBox);
            };
            EventHandler <TouchEventArgs> addTextTag = (s, e) => {
                var ell = s as Ellipse;
                var p   = (Point)ell.Tag;
                if (orderedPoints.Contains(p))
                {
                    return;
                }
                orderedPoints.Add(p);
                ell.Fill = Brushes.picked;
                var index = orderedPoints.Count + string.Empty;
                indexInfo.Text = index + '/' + points.Count();
                var g = Elements.Visual <Grid>(p, r);
                g.Children.Add(new TextBlock {
                    Text                = index,
                    FontSize            = Beard.Radius,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center
                });
                Content.Children.Add(g);
                moveIndexInfo();
            };

            foreach (var item in points)
            {
                Content.Children.Add(item);
                item.Fill       = Brushes.pending;
                item.TouchDown += addTextTag;
            }
            moveIndexInfo();
        }
Example #2
0
        public Step4PickKeys()
        {
            var pickedKeys = new WrapPanel();
            var previewer  = new TextBlock {
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
                Foreground          = new SolidColorBrush(Colors.Black),
                FontSize            = h / 3
            };

            Content.HorizontalAlignment = HorizontalAlignment.Left;
            Content.VerticalAlignment   = VerticalAlignment.Top;
            Content.Background          = new SolidColorBrush(Colors.White);
            for (var i = 0; i < cols; i++)
            {
                Content.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(1, GridUnitType.Star)
                });
            }
            for (var i = 0; i < rows; i++)
            {
                Content.RowDefinitions.Add(new RowDefinition {
                    Height = new GridLength(1, GridUnitType.Star)
                });
            }
            Content.Children.Add(pickedKeys);
            Grid.SetColumn(pickedKeys, 7);
            Grid.SetRow(pickedKeys, 6);
            Grid.SetColumnSpan(pickedKeys, 6);
            Grid.SetRowSpan(pickedKeys, 5);
            var infoBox = new Grid {
                Background = new LinearGradientBrush(new GradientStopCollection(new[] { new GradientStop(), new GradientStop(Colors.Black, .5), new GradientStop {
                                                                                            Offset = 1
                                                                                        } }))
            };

            Content.Children.Add(infoBox);
            Grid.SetColumn(infoBox, 7);
            Grid.SetRow(infoBox, 5);
            Grid.SetColumnSpan(infoBox, 6);
            infoBox.Children.Add(previewer);
            infoBox.TouchDown += (s, e) => {
                if (previewer.Tag != null || pickedKeys.Children.Count == 0)
                {
                    return;
                }
                Content.Children.Clear();
                var touchBoard = new TouchBoard {
                    Background = new SolidColorBrush(new Color {
                        A = 213
                    })
                };
                previewer.Tag        = touchBoard;
                touchBoard.Finished += (ss, ee) => {
                    touchBoard.Close();
                    previewer.Tag = null;
                };
                touchBoard.ShowDialog();
                touchBoard.WithEffect = true;
                touchBoard.Layout(Beard.Radius, Beard.OrderedPoints);
            };
            Action <Grid> preview = k => {
                k.TouchEnter += (s, e) => { previewer.Text = ((s as Grid).Children[0] as TextBlock).Text; };
                k.TouchLeave += (s, e) => { previewer.Text = string.Empty; };
            };
            Action <object> addKey = tag => {
                if (pickedKeys.Children.Count > 6 * 4 - 1)
                {
                    return;
                }
                var k = ShadowBox.Create(new GradientStop(Colors.White, 0), new GradientStop(Colors.Black, 1));
                preview(k);
                k.Tag    = tag;
                k.Width  = w;
                k.Height = h;
                k.Children.Add(new TextBlock {
                    Text                = tag.ToString(),
                    FontSize            = h / 3,
                    VerticalAlignment   = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Center
                });
                pickedKeys.Children.Add(k);
                Action <bool> changeArrow = d => {
                    ShadowBox.ShowCorner(k, d ? 3 : 1, b =>
                                         b.Viewbox = new Rect {
                        Y = d ? .25 : -.25, Width = 1, Height = 1
                    });
                };
                changeArrow(false);
                InputDevice temp = null;
                k.TouchDown += (s, e) => {
                    if (temp == null)
                    {
                        temp = e.Device;
                    }
                };
                Content.TouchLeave += (s, e) => {
                    if (temp != e.Device)
                    {
                        return;
                    }
                    temp = null;
                    var y = e.GetTouchPoint(k).Position.Y;
                    if (Math.Abs(y - h / 2) < h / 6)
                    {
                        pickedKeys.Children.Remove(k);
                    }
                    else
                    {
                        changeArrow(y > h / 2);
                    }
                };
            };
            var j = 1;

            for (var i = 0; i < rows * cols; i++)
            {
                var ci = i % cols;
                var ri = i / cols;
                if (ri > 4 && ci > 5 && ci < 14)
                {
                    continue;
                }
                var k = ShadowBox.Create(new GradientStop {
                    Color = Colors.Black
                }, new GradientStop {
                    Offset = 1
                });
                k.Tag    = (Key)j;
                k.Height = h;
                k.Width  = w;
                k.Children.Add(new TextBlock {
                    Text                = k.Tag.ToString(),
                    FontSize            = h / 3,
                    TextAlignment       = TextAlignment.Left,
                    VerticalAlignment   = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Center
                });
                Elements.AddClick(k, addKey, k.Tag);
                preview(k);
                Content.Children.Add(k);
                Grid.SetColumn(k, ci);
                Grid.SetRow(k, ri);
                j++;
            }
        }
Example #3
0
        public Step1SetRadiusAndCount()
        {
            Content.Children.Add(effectPanel);
            Content.Children.Add(addPanel);
            Content.Children.Add(countPanel);
            countPanel.Children.Add(countGrid);
            for (var i = 0; i < Beard.KeysMax; i++)
            {
                countGrid.Children.Add(ShadowBox.SquareButton());
            }
            setColor();
            var fs      = new List <finger>();
            var d       = default(InputDevice);
            var maxLeft = Width - countGrid.Width;

            countPanel.TouchLeave += (s, e) => {
                if (e.Device != d)
                {
                    return;
                }
                d = null;
            };
            countPanel.TouchMove += (s, e) => {
                e.Handled = true;
                if (d != null && d != e.Device)
                {
                    return;
                }
                d = e.Device;
                var left = Inside(e, countGrid).X;
                countGrid.Margin = new Thickness {
                    Left = left
                };
                c = Beard.KeysMin + (int)(left / maxLeft * Beard.KeysRange);
                setColor();
            };
            addPanel.TouchMove += (s, e) => {
                var f0 = fs.FirstOrDefault(p => p.d == e.Device);
                if (f0 == null)
                {
                    return;
                }
                f0.p = Inside(e, f0.e);
                if (fs.Count == 2)
                {
                    var f1 = fs.First(f => f != f0);
                    var _r = Min(MaxRadius, (f0.p - f1.p).Length / 2);
                    if (_r > 0)
                    {
                        r = _r;
                    }
                    f0.e.Width = f1.e.Width = f0.e.Height = f1.e.Height = r * 2;
                    setColor();
                }
                f0.e.Margin = new Thickness {
                    Left = f0.p.X, Top = f0.p.Y
                };
            };
            addPanel.TouchLeave += (s, e) => {
                var f = fs.FirstOrDefault(p => p.d == e.Device);
                if (f == null)
                {
                    return;
                }
                fs.Remove(f);
                effectPanel.Children.Remove(f.e);
            };
            addPanel.TouchDown += (s, e) => {
                if (fs.Count == 2)
                {
                    return;
                }
                var p   = e.GetTouchPoint(addPanel).Position;
                var ell = new Ellipse {
                    VerticalAlignment   = VerticalAlignment.Top,
                    HorizontalAlignment = HorizontalAlignment.Left,
                    Margin = new Thickness {
                        Left = p.X - r, Top = p.Y - r
                    },
                    Width  = r * 2,
                    Height = r * 2,
                    Fill   = new SolidColorBrush(Colors.Black)
                };
                fs.Add(new finger {
                    d = e.Device, e = ell, p = p
                });
                effectPanel.Children.Add(ell);
            };
        }