Beispiel #1
0
        //private void OnOpacityChanged(object sender, double e)
        //{
        //    double opacity = e;

        //    if (null != _layoutRoot)
        //    {
        //        // correct opacity range
        //        opacity = Math.Max(0.0, opacity);
        //        opacity = Math.Min(1.0, opacity);

        //        // set opacity
        //        _layoutRoot.Opacity = opacity;
        //    }
        //}


        private void AppSelector_OnSelectionChanged(object sender, EventArgs e)
        {
            if (sender is AppSelector selector)
            {
                AppSelector appSelector = (AppSelector)sender;
                this.UpdateUI(appSelector.SelectedID);
            }
        }
 private void _AppSelector_ClearClickedChanged(object sender, EventArgs e)
 {
     // need to change the mouse page too
     if (null != _AppSelector)
     {
         AppSelector appSelector = (AppSelector)sender;
         _inkCanvas.InkPresenter.StrokeContainer.Clear();
     }
 }
        private void _AppSelector_SelectedIDChanged(object sender, EventArgs e)
        {
            // need to change the mouse page too
            if ((null != _AppSelector) && (null != _AppSelector) && (null != _AppSelector))
            {
                AppSelector appSelector = (AppSelector)sender;
                this._SelectedColor = this.Colors[appSelector.SelectedID].Color;

                SetupBrush();
            }
        }
Beispiel #4
0
        private static void OnAppSelectorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (d is AppSelectorImage AppSelectorImage)
            {
                // clean up event handler from previous colorselector
                if (null != AppSelectorImage._previousAppSelector)
                {
                    AppSelectorImage._previousAppSelector.SelectedIDChanged -= AppSelectorImage.AppSelector_OnSelectionChanged;
                }

                // save this as the previous
                AppSelectorImage._previousAppSelector = AppSelectorImage.AppSelector;

                // add new event handler
                if (null != AppSelectorImage.AppSelector)
                {
                    AppSelectorImage.AppSelector.SelectedIDChanged += AppSelectorImage.AppSelector_OnSelectionChanged;
                }
            }
        }
 private void RaiseClearClickedEvent(AppSelector Selector)
 {
     this.RaiseClearClickedEvent(Selector, new EventArgs());
 }
 private void RaiseClearClickedEvent(AppSelector Selector, EventArgs e)
 {
     OnClearClicked?.Invoke(Selector, e);
 }
 private void RaiseSelectedIDChangedEvent(AppSelector Selector)
 {
     this.RaiseSelectedIDChangedEvent(Selector, new EventArgs());
 }
 private void RaiseSelectedIDChangedEvent(AppSelector Selector, EventArgs e)
 {
     SelectedIDChanged?.Invoke(Selector, e);
 }
        private void RenderUI()
        {
            // get the layoutroot
            _layoutRoot = (Grid)this.GetTemplateChild("LayoutRoot");

            //_layoutRoot.Opacity = 0;
            double AppSelectorMarginRight = StyleHelper.GetApplicationDouble("AppSelectorMarginRight");

            if (null == _layoutRoot)
            {
                return;
            }

            _layoutRoot.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(.95, GridUnitType.Star)
            });
            _layoutRoot.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(.05, GridUnitType.Star)
            });

            // create touch here canvas
            _touchHereCanvas = new Canvas()
            {
                Name             = "ColoringBookCanvasControls",
                Margin           = new Thickness(0),
                ManipulationMode = ManipulationModes.None
            };
            Grid.SetRow(_touchHereCanvas, 0);
            Grid.SetColumn(_touchHereCanvas, 0);
            _layoutRoot.Children.Add(_touchHereCanvas);

            // create the button grid
            _penTouchPointGrid = new Grid()
            {
                Name    = "AccessoriesPenButtonGrid",
                Margin  = new Thickness(0),
                Padding = new Thickness(0),
                Opacity = 0.0
            };
            _penTouchPointGrid.ColumnDefinitions.Add(new ColumnDefinition());
            _penTouchPointGrid.RowDefinitions.Add(new RowDefinition()
            {
                Height = new GridLength(1.0, GridUnitType.Auto)
            });
            _penTouchPointGrid.RowDefinitions.Add(new RowDefinition()
            {
                Height = new GridLength(GRID_ROWSPACING)
            });
            _penTouchPointGrid.RowDefinitions.Add(new RowDefinition()
            {
                Height = new GridLength(1.0, GridUnitType.Auto)
            });
            Canvas.SetLeft(_penTouchPointGrid, GRID_X);
            Canvas.SetTop(_penTouchPointGrid, GRID_Y);
            Canvas.SetZIndex(_penTouchPointGrid, Z_ORDER_CONTROLS);
            _touchHereCanvas.Children.Add(_penTouchPointGrid);

            // create the ink canvas
            _inkCanvas = new InkCanvas()
            {
                Name   = "InkCanvas",
                Margin = new Thickness(0),
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment   = VerticalAlignment.Stretch
            };

            // add events to inkpresenter
            _inkCanvas.InkPresenter.StrokeInput.StrokeStarted   += InkPresenter_StrokeStarted;
            _inkCanvas.InkPresenter.StrokeInput.StrokeContinued += InkPresenter_StrokeContinued;
            _inkCanvas.InkPresenter.StrokeInput.StrokeEnded     += InkPresenter_StrokeEnded;

            Grid.SetRow(_inkCanvas, 0);
            Grid.SetColumnSpan(_inkCanvas, this.ImageColumnSpan);
            Grid.SetColumn(_inkCanvas, 0);
            _layoutRoot.Children.Add(_inkCanvas);

            // please dont not have a URI or an SVGURI or the image below will error
            _ColoringImage = new ImageEx()
            {
                Name                = "ColoringImage",
                BitmapImage         = BMIMAGE_COLORING_BOOK,
                ImageWidth          = DOUBLE_COLORING_BOOK_IMAGE_WIDTH,
                Width               = DOUBLE_COLORING_BOOK_IMAGE_WIDTH,
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment   = VerticalAlignment.Center,

                Opacity          = .1,
                IsHitTestVisible = false
            };

            Canvas.SetZIndex(_ColoringImage, 101);
            Grid.SetColumnSpan(_ColoringImage, this.ImageColumnSpan);
            Grid.SetRow(_ColoringImage, 0);
            Grid.SetColumn(_ColoringImage, 0);
            _layoutRoot.Children.Add(_ColoringImage);

            this.Colors.Add(COLOR_COLORING_BOOK_RED);
            this.Colors.Add(COLOR_COLORING_BOOK_BLUE);
            this.Colors.Add(COLOR_COLORING_BOOK_TEAL);
            this.Colors.Add(COLOR_COLORING_BOOK_ORANGE);
            this.Colors.Add(COLOR_COLORING_BOOK_PURPLE);

            this._ImagePairs.Add(0, new ImagePair()
            {
                NotSelected = new Image()
                {
                    Source = BMIMAGE_COLOR_RED,
                    Width  = DOUBLE_COLORING_BOOK_BUTTON_WIDTH,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center,
                    Opacity             = 1.0
                },
                Selected = new Image()
                {
                    Source = BMIMAGE_COLOR_RED_SELECTED,
                    Width  = DOUBLE_COLORING_BOOK_BUTTON_WIDTH,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center,
                    Opacity             = 1.0
                }
            });

            this._ImagePairs.Add(1, new ImagePair()
            {
                NotSelected = new Image()
                {
                    Source = BMIMAGE_COLOR_BLUE,
                    Width  = DOUBLE_COLORING_BOOK_BUTTON_WIDTH,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center,
                    Opacity             = 1.0
                },
                Selected = new Image()
                {
                    Source = BMIMAGE_COLOR_BLUE_SELECTED,
                    Width  = DOUBLE_COLORING_BOOK_BUTTON_WIDTH,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center,
                    Opacity             = 1.0
                }
            });

            this._ImagePairs.Add(2, new ImagePair()
            {
                NotSelected = new Image()
                {
                    Source = BMIMAGE_COLOR_TEAL,
                    Width  = DOUBLE_COLORING_BOOK_BUTTON_WIDTH,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center,
                    Opacity             = 1.0
                },
                Selected = new Image()
                {
                    Source = BMIMAGE_COLOR_TEAL_SELECTED,
                    Width  = DOUBLE_COLORING_BOOK_BUTTON_WIDTH,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center,
                    Opacity             = 1.0
                }
            });

            this._ImagePairs.Add(3, new ImagePair()
            {
                NotSelected = new Image()
                {
                    Source = BMIMAGE_COLOR_ORANGE,
                    Width  = DOUBLE_COLORING_BOOK_BUTTON_WIDTH,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center,
                    Opacity             = 1.0
                },
                Selected = new Image()
                {
                    Source = BMIMAGE_COLOR_ORANGE_SELECTED,
                    Width  = DOUBLE_COLORING_BOOK_BUTTON_WIDTH,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center,
                    Opacity             = 1.0
                }
            });

            this._ImagePairs.Add(4, new ImagePair()
            {
                NotSelected = new Image()
                {
                    Source = BMIMAGE_COLOR_PURPLE,
                    Width  = DOUBLE_COLORING_BOOK_BUTTON_WIDTH,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center,
                    Opacity             = 1.0
                },
                Selected = new Image()
                {
                    Source = BMIMAGE_COLOR_PURPLE_SELECTED,
                    Width  = DOUBLE_COLORING_BOOK_BUTTON_WIDTH,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center,
                    Opacity             = 1.0
                }
            });

            this._AppSelector = new AppSelector()
            {
                //TelemetryId = TelemetryService.TELEMETRY_KEYBOARDVIEWCOLOR,
                IsPenOnly           = true,
                AppSelectorMode     = SelectorMode.Color,
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment   = VerticalAlignment.Center,
                Margin               = new Thickness(0, 0, AppSelectorMarginRight, 0),
                MainOrientation      = Orientation.Vertical,
                ButtonHeight         = DOUBLE_COLORING_BOOK_BUTTON_HEIGHT,
                ButtonWidth          = DOUBLE_COLORING_BOOK_BUTTON_WIDTH,
                Opacity              = 1,
                ImagePairs           = this._ImagePairs,
                ClearButtonImagePair = new ImagePair()
                {
                    NotSelected = new Image()
                    {
                        Source = BMIMAGE_CLEARBUTTON,
                        Width  = DOUBLE_COLORING_BOOK_BUTTON_WIDTH,
                        HorizontalAlignment = HorizontalAlignment.Center,
                        VerticalAlignment   = VerticalAlignment.Center,
                        Opacity             = 1.0
                    },
                    IsClearButton = true
                },
                SelectedID = 0
            };
            _AppSelector.SelectedIDChanged += _AppSelector_SelectedIDChanged;
            _AppSelector.OnClearClicked    += _AppSelector_ClearClickedChanged;
            Canvas.SetZIndex(_AppSelector, 101);
            Grid.SetRow(_AppSelector, 0);
            Grid.SetColumn(_AppSelector, 1);
            this._layoutRoot.Children.Add(_AppSelector);
            this._SelectedColor = this.Colors[0];
            SetupBrush();
        }
        private void RenderUI()
        {
            // get the layoutroot
            _layoutRoot = (Grid)this.GetTemplateChild("LayoutRoot");

            if (null == _layoutRoot)
            {
                return;
            }

            // create touch here canvas
            _touchHereCanvas = new Canvas()
            {
                Name             = "ColoringBookCanvasControls",
                Margin           = new Thickness(0),
                ManipulationMode = ManipulationModes.None
            };
            Grid.SetRow(_touchHereCanvas, 0);
            Grid.SetColumn(_touchHereCanvas, 0);
            _layoutRoot.Children.Add(_touchHereCanvas);

            // create the button grid
            _penTouchPointGrid = new Grid()
            {
                Name    = "AccessoriesPenButtonGrid",
                Margin  = new Thickness(0),
                Padding = new Thickness(0),
                Opacity = 0.0
            };
            _penTouchPointGrid.ColumnDefinitions.Add(new ColumnDefinition());
            _penTouchPointGrid.RowDefinitions.Add(new RowDefinition()
            {
                Height = new GridLength(1.0, GridUnitType.Auto)
            });
            _penTouchPointGrid.RowDefinitions.Add(new RowDefinition()
            {
                Height = new GridLength(GRID_ROWSPACING)
            });
            _penTouchPointGrid.RowDefinitions.Add(new RowDefinition()
            {
                Height = new GridLength(1.0, GridUnitType.Auto)
            });
            Canvas.SetLeft(_penTouchPointGrid, GRID_X);
            Canvas.SetTop(_penTouchPointGrid, GRID_Y);
            Canvas.SetZIndex(_penTouchPointGrid, Z_ORDER_CONTROLS);
            _touchHereCanvas.Children.Add(_penTouchPointGrid);

            // create touch here image
            _touchHereImage = new Image()
            {
                Source = new BitmapImage()
                {
                    UriSource = new Uri(URI_PENICON), DecodePixelWidth = (int)WIDTH_PENICON
                },
                Width = WIDTH_PENICON,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Center
            };
            Grid.SetRow(_touchHereImage, 0);
            Grid.SetColumn(_touchHereImage, 0);
            _penTouchPointGrid.Children.Add(_touchHereImage);

            // create the caption
            _caption = new StyledText()
            {
                Name                = "ColoringBookCaption",
                Text                = this.Caption,
                ControlStyle        = this.ControlStyle,
                TextAlignment       = TextAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Center
            };
            Grid.SetRow(_caption, 2);
            Grid.SetColumn(_caption, 0);
            _penTouchPointGrid.Children.Add(_caption);

            // create the ink canvas
            _inkCanvas = new InkCanvas()
            {
                Name   = "InkCanvas",
                Margin = new Thickness(0),
            };

            Grid.SetRow(_inkCanvas, 0);
            Grid.SetColumn(_inkCanvas, 0);
            _layoutRoot.Children.Add(_inkCanvas);

            // set the default drawing attribs
            SetupBrush();
            //InkDrawingAttributes inkDrawingAttributes = new InkDrawingAttributes()
            //{
            //    Color = GetNextColor(),
            //    //FitToCurve = true,
            //    PenTip = PenTipShape.Circle,
            //    Size = new Size(WINDOW_BOUNDS.Width * 0.02, WINDOW_BOUNDS.Height * 0.02)
            //};
            //_inkCanvas.InkPresenter.UpdateDefaultDrawingAttributes(inkDrawingAttributes);


            // add a nohitvisible png onto this page
            Image ColoringImage = new Image()
            {
                Source = new BitmapImage()
                {
                    UriSource = new Uri(ImageURI), DecodePixelWidth = this.ImageWidth
                },
                Width  = this.ImageWidth,
                Height = this.ImageHeight,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Center,
                Opacity             = 1.0,
                IsHitTestVisible    = false
            };

            Canvas.SetZIndex(ColoringImage, 100);
            Grid.SetRow(ColoringImage, 0);
            Grid.SetRowSpan(ColoringImage, 4);
            Grid.SetColumn(ColoringImage, 0);
            Grid.SetColumnSpan(ColoringImage, 3);
            _layoutRoot.Children.Add(ColoringImage);

            for (int i = 0; i < this.Colors.Count; i++)
            {
                this._URIs.Add(new AppSelectorData
                {
                    URI_NotSelectedImage = this.Colors[i].URI_NotSelectedImage,
                    URI_SelectedImage    = this.Colors[i].URI_SelectedImage
                });
            }
            AppSelector _AppSelector = new AppSelector()
            {//
                //TelemetryId = TelemetryService.TELEMETRY_KEYBOARDVIEWCOLOR,
                AppSelectorMode            = SelectorMode.Color,
                HorizontalAlignment        = HorizontalAlignment.Right,
                VerticalAlignment          = VerticalAlignment.Center,
                DurationInMilliseconds     = 200d,
                StaggerDelayInMilliseconds = 200d,
                AutoStart    = false,
                Orientation  = Orientation.Vertical,
                ButtonHeight = 74,
                URIs         = this._URIs
            };// bind event to catch and change color from this.colors

            // add the test selector here so it's after the color selector image
            _AppSelector.SelectedIDChanged += _AppSelector_SelectedIDChanged;
            Canvas.SetZIndex(_AppSelector, 101);
            Grid.SetRow(_AppSelector, 5);
            Grid.SetColumn(_AppSelector, 1);
            this._layoutRoot.Children.Add(_AppSelector);
            this._SelectedColor = this.Colors[0].Color;
            SetupBrush();
            // set up events
        }