示例#1
0
        public static void OnColorChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            // Force a re-render of the object if a visual-related property changes
            WheelSelector ctl = (obj as WheelSelector);

            ctl.InvalidateVisual();

            //TODO: Figure out how to handle circular dependencies properly.
            // Currently I'm using propUpdateFlag to prevent infinite loops here.
            // Ideally there should be a way to update the local values without calling
            // this callback again (but still notifying other users)

            if (!propUpdateFlag)
            {
                propUpdateFlag = true;

                if (args.Property == WheelSelector.ThetaProperty || args.Property == WheelSelector.RadProperty)
                {
                    ctl.RGBValue = ctl.wheel.ColourMapping(ctl.Rad, CircularMath.Mod(ctl.Theta), 1.0);
                }

                if (args.Property == WheelSelector.RGBValueProperty)
                {
                    var rgb = (RGBColor)args.NewValue;
                    var pt  = ctl.wheel.InverseColourMapping(rgb);
                    ctl.SetCurrentValue(ThetaProperty, pt.X);
                    ctl.SetCurrentValue(RadProperty, pt.Y);
                }

                propUpdateFlag = false;
            }
        }
示例#2
0
        private static void OnHSPropertyAnimated(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            WheelSelector ctl = (obj as WheelSelector);

            ctl.Theta = (args.NewValue as Point?).Value.X;
            ctl.Rad   = (args.NewValue as Point?).Value.Y;

            ctl.InvalidateVisual();
        }
示例#3
0
        public static void OnThumbSizeChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            // Force a re-render of the object if the thumb size changes
            WheelSelector ctl = (obj as WheelSelector);

            ctl.UpdateThumbSize();
            ctl.InvalidateMeasure();    // Updating the thumbsize changes the dial radius
            ctl.UpdateSelector();       // Also need to re-calculate the thumb position
            ctl.InvalidateVisual();     // And then re-paint everything
        }
示例#4
0
        public static void RenderToPng(int w, int h, string filename, double thumb_size = 0.5)
        {
            var ctl = new WheelSelector();

            ctl.ThumbSize = w * thumb_size;
            ctl.Rad = 0.0;

            ctl.Measure(new Size(w, h));
            ctl.Arrange(new Rect(new Size(w, h)));
            ctl.UpdateLayout();

            RenderTargetBitmap bitmap = new RenderTargetBitmap(w, h, 96, 96, PixelFormats.Pbgra32);
            bitmap.Render(ctl);

            PngBitmapEncoder png = new PngBitmapEncoder();
            png.Frames.Add(BitmapFrame.Create(bitmap));
            using (Stream s = File.Create(filename))
            {
                png.Save(s);
            }
        }