예제 #1
0
 internal void UpdateRGB(RGBStruct @struct)
 {
     this.R_.Text = @struct.r.ToString();
     this.G_.Text = @struct.g.ToString();
     this.B_.Text = @struct.b.ToString();
     this.A_.Text = @struct.a.ToString();
 }
예제 #2
0
        private void SuperColorPicker_PropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)
        {
            var    _old       = color_W.SelectedColor;
            byte   a_         = (byte)(AlphaSL.Value * 255);
            double lightness_ = DarknessSL.Value;

            var rgb_S  = RGBStruct.ApplyLightnessToRGB(new RGBStruct(_old), lightness_);
            var color_ = new Color(a_, rgb_S.r, rgb_S.g, rgb_S.b);

            SelectedColor            = color_;
            hSL.ColorToShow          = color_;
            rGB.ColorToShow          = color_;
            hextext.Text             = color_.ToString();
            PreviewBorder.Background = new SolidColorBrush(color_);
        }
예제 #3
0
        protected void DrawHsvDial(DrawingContext drawingContext)
        {
            float cx = (float)(Bounds.Width) / 2.0f;
            float cy = (float)(Bounds.Height) / 2.0f;

            float outer_radius = (float)Math.Min(cx, cy);

            ActualOuterRadius = outer_radius;

            int bmp_width  = (int)Bounds.Width;
            int bmp_height = (int)Bounds.Height;

            if (bmp_width <= 0 || bmp_height <= 0)
            {
                return;
            }


            var stopwatch = new Stopwatch();

            stopwatch.Start();

            //This probably wants to move somewhere else....
            if (border == null)
            {
                border                  = new Ellipse();
                border.Fill             = new SolidColorBrush(Colors.Transparent);
                border.Stroke           = new SolidColorBrush(Colors.Black);
                border.StrokeThickness  = 3;
                border.IsHitTestVisible = false;
                border.Opacity          = 50;
                this.Children.Add(border);
                border.HorizontalAlignment = HA.Center;
                border.VerticalAlignment   = VA.Center;
            }

            border.Width  = Math.Min(bmp_width, bmp_height) + (border.StrokeThickness / 2);
            border.Height = Math.Min(bmp_width, bmp_height) + (border.StrokeThickness / 2);

            var writeableBitmap = new WriteableBitmap(new PixelSize(bmp_width, bmp_height), new Vector(96, 96), PixelFormat.Bgra8888);

            using (var lockedFrameBuffer = writeableBitmap.Lock())
            {
                unsafe
                {
                    IntPtr bufferPtr = new IntPtr(lockedFrameBuffer.Address.ToInt64());

                    for (int y = 0; y < bmp_height; y++)
                    {
                        for (int x = 0; x < bmp_width; x++)
                        {
                            int color_data = 0;

                            // Convert xy to normalized polar co-ordinates
                            double dx = x - cx;
                            double dy = y - cy;
                            double pr = Math.Sqrt(dx * dx + dy * dy);

                            // Only draw stuff within the circle
                            if (pr <= outer_radius)
                            {
                                // Compute the color for the given pixel using polar co-ordinates
                                double    pa = Math.Atan2(dx, dy);
                                RGBStruct c  = ColorFunction(pr / outer_radius, ((pa + Math.PI) * 180.0 / Math.PI));

                                // Anti-aliasing
                                // This works by adjusting the alpha to the alias error between the outer radius (which is integer)
                                // and the computed radius, pr (which is float).
                                double aadelta = pr - (outer_radius - 1.0);
                                if (aadelta >= 0.0)
                                {
                                    c.a = (byte)(255 - aadelta * 255);
                                }

                                color_data = c.ToARGB32();
                            }

                            *((int *)bufferPtr) = color_data;
                            bufferPtr          += 4;
                        }
                    }
                }
            }

            drawingContext.DrawImage(writeableBitmap, Bounds);

            stopwatch.Stop();
            Debug.WriteLine($"YO! This puppy took {stopwatch.ElapsedMilliseconds} MS to complete");
        }
예제 #4
0
        protected void DrawHsvDial(DrawingContext drawingContext)
        {
            float cx = (float)this.ActualWidth / 2.0f;
            float cy = (float)this.ActualHeight / 2.0f;

            float outer_radius = (float)Math.Min(cx, cy);

            ActualOuterRadius = outer_radius;

            //double outer_circumference = 2.0 * Math.PI * outer_radius;

            int bmp_width  = (int)this.ActualWidth;
            int bmp_height = (int)this.ActualHeight;

            if (bmp_width <= 0 || bmp_height <= 0)
            {
                return;
            }

            bitmap = new WriteableBitmap(bmp_width, bmp_height, 96.0, 96.0, PixelFormats.Bgra32, null);

            bitmap.Lock();
            unsafe
            {
                int pBackBuffer = (int)bitmap.BackBuffer;

                for (int y = 0; y < bmp_height; y++)
                {
                    for (int x = 0; x < bmp_width; x++)
                    {
                        int color_data = 0;
                        //double inner_radius = radius * InnerRadius;

                        // Convert xy to normalized polar co-ordinates
                        double dx = x - cx;
                        double dy = y - cy;
                        double pr = Math.Sqrt(dx * dx + dy * dy);

                        // Only draw stuff within the circle
                        if (pr <= outer_radius)
                        {
                            // Compute the colour for the given pixel using polar co-ordinates
                            double    pa = Math.Atan2(dx, dy);
                            RGBStruct c  = ColourFunction(pr / outer_radius, ((pa + Math.PI) * 180.0 / Math.PI));

                            // Anti-aliasing
                            // This works by adjusting the alpha to the alias error between the outer radius (which is integer)
                            // and the computed radius, pr (which is float).
                            double aadelta = pr - (outer_radius - 1.0);
                            if (aadelta >= 0.0)
                            {
                                c.a = (byte)(255 - aadelta * 255);
                            }

                            color_data = c.ToARGB32();
                        }

                        *((int *)pBackBuffer) = color_data;
                        pBackBuffer          += 4;
                    }
                }
            }
            bitmap.AddDirtyRect(new Int32Rect(0, 0, bmp_width, bmp_height)); // I like to get dirty
            bitmap.Unlock();


            drawingContext.DrawImage(bitmap, new Rect(this.RenderSize));
        }