Exemple #1
0
        public void EnterColor(Color c, bool animation)
        {
            if (c.A == 0) // The recent color has no color
            {
                c.R = c.G = c.B = 0;
            }                        // Black

            CurrentColor = c;
            HSVColor hsv = Math2.RGBToHSV(c);

            Hue        = hsv.H;
            Saturation = hsv.S;
            Value      = hsv.V;
            CompositeTransform ct = SeletcedColorEllipseCompositeTransform;

            // Compute SeletcedColorEllipse position
            Point targetPoint = Math2.SVToPoint(Saturation, Value, triangleSide);

            targetPoint.X  = trianglePoint1.X + targetPoint.X;
            targetPoint.Y  = trianglePoint1.Y - targetPoint.Y;
            targetPoint    = Math2.RotatePoint(targetPoint, triangleCenter, -Hue);
            targetPoint.X -= seletcedColorEllipse_r;
            targetPoint.Y -= seletcedColorEllipse_r;

            if (animation)
            {
                ColorPickerStoryboardStart(Hue, targetPoint);
            }
            else
            {
                TriangleImgRotation.Angle      = Hue;
                SelesctedRingImgRotation.Angle = Hue;
                _preAngle = Hue;
                PolygonTransform.Angle = Hue;

                ct.TranslateX   = targetPoint.X;
                ct.TranslateY   = targetPoint.Y;
                _preCirclePoint = new Point(ct.TranslateX, ct.TranslateY);
            }
        }
Exemple #2
0
        private unsafe void ChangeTriangleColorPixel(double hue)
        {
            HSVColor hsv = new HSVColor(hue, 1.0, 1.0);

            using (BitmapBuffer buffer = triangleSoftwareBitmap.LockBuffer(BitmapBufferAccessMode.Write))
            {
                using (var reference = buffer.CreateReference())
                {
                    byte *dataInBytes;
                    uint  capacity;
                    ((IMemoryBufferByteAccess)reference).GetBuffer(out dataInBytes, out capacity);

                    // Fill-in the BGRA plane
                    BitmapPlaneDescription bufferLayout = buffer.GetPlaneDescription(0);
                    double imgWidth  = bufferLayout.Width;
                    double imgHeight = bufferLayout.Height;

                    for (int row = 0; row < imgHeight; row++)
                    {
                        for (int col = 0; col < imgWidth; col++)
                        {
                            Point pt = new Point(col, bufferLayout.Height - row);

                            Math2.ComputeSV(pt, imgWidth, out hsv.S, out hsv.V);
                            Color color = hsv.GetRGB();

                            int pixelIndex = bufferLayout.Stride * row + 4 * col;
                            if (dataInBytes[pixelIndex + 3] != 0)
                            {
                                dataInBytes[pixelIndex + 0] = (byte)color.B;
                                dataInBytes[pixelIndex + 1] = (byte)color.G;
                                dataInBytes[pixelIndex + 2] = (byte)color.R;
                            }
                        }
                    }
                }
            }
        }
Exemple #3
0
        private void Polygon_PointerMoved(object sender, PointerRoutedEventArgs e)
        {
            if (_trianglePressing && !_textboxFocusing)
            {
                Point currentPoint = e.GetCurrentPoint(this.ImageGrid).Position;

                // Rotation current position "Hue" degrees
                Point rotatedPoint = Math2.RotatePoint(currentPoint, triangleCenter, Hue);

                // Let trianglePoint1 become origin
                Point newPoint = new Point(
                    Math.Abs(rotatedPoint.X - trianglePoint1.X),
                    Math.Abs(rotatedPoint.Y - trianglePoint1.Y)
                    );

                Math2.ComputeSV(newPoint, triangleSide, out Saturation, out Value);
                CurrentColor = Math2.HSVToRGB(Hue, Saturation, Value);

                // Compute SeletcedColorEllipse
                if (_pointerMovedStory)
                {
                    Point targetPoint = new Point(
                        currentPoint.X - seletcedColorEllipse_r,
                        currentPoint.Y - seletcedColorEllipse_r
                        );

                    ColorPickerStoryboardStart(_preAngle, targetPoint);
                }
                else
                {
                    CompositeTransform ct = SeletcedColorEllipseCompositeTransform;
                    ct.TranslateX   = currentPoint.X - seletcedColorEllipse_r;
                    ct.TranslateY   = currentPoint.Y - seletcedColorEllipse_r;
                    _preCirclePoint = new Point(ct.TranslateX, ct.TranslateY);
                }
            }
        }
Exemple #4
0
        public void EnterHSV(double h, double s, double v, Point targetPoint, bool animation)
        {
            Hue          = h;
            Saturation   = s;
            Value        = v;
            CurrentColor = Math2.HSVToRGB(Hue, Saturation, Value);
            CompositeTransform ct = SeletcedColorEllipseCompositeTransform;

            if (animation)
            {
                ColorPickerStoryboardStart(_preAngle, targetPoint);
            }
            else
            {
                TriangleImgRotation.Angle      = Hue;
                SelesctedRingImgRotation.Angle = Hue;
                _preAngle = Hue;
                PolygonTransform.Angle = Hue;

                ct.TranslateX   = targetPoint.X;
                ct.TranslateY   = targetPoint.Y;
                _preCirclePoint = new Point(ct.TranslateX, ct.TranslateY);
            }
        }
Exemple #5
0
 internal Color GetRGB()
 {
     return(Math2.HSVToRGB(H, S, V));
 }