コード例 #1
0
        private void ChangeColorFromColorPicker(Control colorPicker, EventArgs e)
        {
            if (colorPicker is SolidColorPicker)
            {
                SolidColorPicker solidColorPicker = (SolidColorPicker)colorPicker;
                Color            newColor         = solidColorPicker.SelectedColor;
                GeoColor         newGeoColor      = GeoColor2MediaColorConverter.ConvertBack(newColor);

                hatchColorPicker.SyncBaseColor(DrawingColorToMediaColorConverter.ConvertBack(newColor));
                gradientPicker.SyncBaseColor(DrawingColorToMediaColorConverter.ConvertBack(newColor));

                SelectedBrush = new GeoSolidBrush(newGeoColor);
            }
            else if (colorPicker is HatchPicker)
            {
                HatchPicker hatchPicker = (HatchPicker)colorPicker;
                System.Drawing.Drawing2D.HatchStyle drawingHatchStyle = hatchPicker.SelectedHatchStyle;
                GeoHatchStyle geoHatchStyle = GeoHatchStyle2DrawingHatchStyle.ConvertBack(drawingHatchStyle);

                //solidColorPicker.SyncBaseColor(hatchPicker.ForegroundColor);
                gradientPicker.SyncBaseColor(hatchPicker.ForegroundColor);

                SelectedBrush = new GeoHatchBrush(geoHatchStyle, GeoColor2DrawingColorConverter.ConvertBack(hatchPicker.ForegroundColor)
                                                  , GeoColor2DrawingColorConverter.ConvertBack(hatchColorPicker.BackgroundColor));
            }
            else if (colorPicker is TexturePicker)
            {
                PropertyChangedEventArgs args          = (PropertyChangedEventArgs)e;
                TexturePicker            texturePicker = (TexturePicker)colorPicker;
                if (args.PropertyName == "SelectedBrush")
                {
                    ImageBrush mediaBrush = texturePicker.SelectedBrush as ImageBrush;
                    if (mediaBrush != null)
                    {
                        BitmapImage imageSource = (BitmapImage)mediaBrush.ImageSource;
                        if (imageSource != null)
                        {
                            SelectedBrush = new GeoTextureBrush(new GeoImage(imageSource.UriSource.LocalPath));
                        }
                    }
                }
            }
            else if (colorPicker is DrawingLinearGradientBrushPicker)
            {
                DrawingLinearGradientBrushPicker linearPicker = (DrawingLinearGradientBrushPicker)colorPicker;
                LinearGradientBrushEntity        brushEntity  = linearPicker.SelectedBrush;

                solidColorPicker.SyncBaseColor(brushEntity.StartColor);
                hatchColorPicker.SyncBaseColor(brushEntity.StartColor);

                SelectedBrush = new GeoLinearGradientBrush(GeoColor2DrawingColorConverter.ConvertBack(brushEntity.StartColor),
                                                           GeoColor2DrawingColorConverter.ConvertBack(brushEntity.EndColor),
                                                           brushEntity.Angle);
            }
        }
コード例 #2
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            solidColorBrushTabItem = GetTemplateChild("SolidColorBrushTabItem") as TabItem;
            hatchBrushTabItem      = GetTemplateChild("HatchBrushTabItem") as TabItem;
            textureTabItem         = GetTemplateChild("TextureTabItem") as TabItem;
            gradientTabItem        = GetTemplateChild("GradientColorBrushTabItem") as TabItem;
            solidColorPicker       = GetTemplateChild("SolidColorPicker") as SolidColorPicker;
            textureColorPicker     = GetTemplateChild("TextureColorPicker") as TexturePicker;
            hatchColorPicker       = GetTemplateChild("HatchColorPicker") as HatchPicker;
            gradientPicker         = GetTemplateChild("GradientPicker") as DrawingLinearGradientBrushPicker;
            pickTextureButton      = GetTemplateChild("PickTextureButton") as Button;
            colorTabControl        = GetTemplateChild("ColorTabControl") as TabControl;
            customColorList        = GetTemplateChild("CustomColorList") as ListBox;
            helpContainer          = GetTemplateChild("HelpContainer") as ContentPresenter;
            addcutomColorButton    = GetTemplateChild("AddCustomColorButton") as Button;

            if (!isTemplateApplied)
            {
                solidColorPicker.IsEnabled   = IsSolidColorBrushTabEnabled;
                textureColorPicker.IsEnabled = IsTextureBrushTabEnabled;
                hatchColorPicker.IsEnabled   = IsHatchBrushTabEnabled;
                gradientPicker.IsEnabled     = IsGradientColorBrushTabEnabled;

                solidColorPicker.SelectionChanged   += new EventHandler(SolidColorPicker_SelectionChanged);
                hatchColorPicker.SelectionChanged   += new EventHandler(HatchColorPicker_SelectionChanged);
                textureColorPicker.PropertyChanged  += new PropertyChangedEventHandler(TextureColorPicker_PropertyChanged);
                gradientPicker.SelectedBrushChanged += new EventHandler(GradientPicker_SelectedBrushChanged);
                pickTextureButton.Click             += new RoutedEventHandler(PickTextureButton_Click);

                solidColorPicker.SelectedItemDoubleClick   += OnSelectedItemDoubleClick;
                hatchColorPicker.SelectedItemDoubleClick   += OnSelectedItemDoubleClick;
                textureColorPicker.SelectedItemDoubleClick += OnSelectedItemDoubleClick;

                solidColorPicker.ColorPanelMouseDoubleClick += new MouseButtonEventHandler(SolidColorPicker_ColorPanelMouseDoubleClick);
                customColorList.SelectionChanged            += new SelectionChangedEventHandler(CustomColorList_SelectionChanged);
                colorTabControl.SelectionChanged            += new SelectionChangedEventHandler(ColorTabControl_SelectionChanged);
                addcutomColorButton.Click += new RoutedEventHandler(AddcutomColorButton_Click);
                helpContainer.Content      = HelpResourceHelper.GetHelpButton("ColorPickerHelp", HelpButtonMode.IconWithLabel);

                defaultColors = CreateDefaultPalette();
                customColorList.ItemsSource = defaultColors;
                isTemplateApplied           = true;

                Loaded -= TabColorPicker_Loaded;
                Loaded += TabColorPicker_Loaded;
            }
        }
コード例 #3
0
        private static void SelectedBrushChangedHandler(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            DrawingLinearGradientBrushPicker currentInstance = (DrawingLinearGradientBrushPicker)sender;

            currentInstance.RewirePropertyChangedEvent();
            double newAngle = currentInstance.SelectedBrush.Angle;
            double x2       = radius + radius * Math.Cos(newAngle * Math.PI / 180d);
            double y2       = radius - radius * Math.Sin(newAngle * Math.PI / 180d);

            if (currentInstance.stopAngleArrow != null)
            {
                currentInstance.stopAngleArrow.X2 = x2;
                currentInstance.stopAngleArrow.Y2 = y2;
            }

            currentInstance.SetStopColor(currentInstance.stopType == StopType.End ? currentInstance.SelectedBrush.EndColor : currentInstance.SelectedBrush.StartColor);
            currentInstance.SetPreviewImage();
        }