Пример #1
0
        /// <summary>
        /// Gets colors, bold, but not font properties.
        /// </summary>
        public TStyles(AuScintilla sci)
        {
            BackgroundColor = ColorInt.SwapRB(sci.Call(SCI_STYLEGETBACK));

            TStyle _Get(EToken tok)
            {
                int  color = ColorInt.SwapRB(sci.Call(SCI_STYLEGETFORE, (int)tok));
                bool bold  = 0 != sci.Call(SCI_STYLEGETBOLD, (int)tok);

                return(new TStyle(color, bold));
            }

            Comment      = _Get(EToken.Comment);
            String       = _Get(EToken.String);
            StringEscape = _Get(EToken.StringEscape);
            Number       = _Get(EToken.Number);
            Punctuation  = _Get(EToken.Punctuation);
            Operator     = _Get(EToken.Operator);
            Keyword      = _Get(EToken.Keyword);
            Namespace    = _Get(EToken.Namespace);
            Type         = _Get(EToken.Type);
            Function     = _Get(EToken.Function);
            LocalVar     = _Get(EToken.LocalVar);
            Parameter    = _Get(EToken.Parameter);
            Field        = _Get(EToken.Field);
            Constant     = _Get(EToken.Constant);
            EnumMember   = _Get(EToken.EnumMember);
            Label        = _Get(EToken.Label);
            Preprocessor = _Get(EToken.Preprocessor);
            Excluded     = _Get(EToken.Excluded);
            XmlDocText   = _Get(EToken.XmlDocText);
            XmlDocTag    = _Get(EToken.XmlDocTag);

            LineNumber = _Get(EToken.LineNumber);
        }
Пример #2
0
    //rejected. Too simple, and nobody would find and use.
    ///// <summary>
    ///// Converts to int.
    ///// Can be used like <c>0xff123456.ToInt()</c> instead of <c>unchecked((int)0xff123456)</c>.
    ///// </summary>
    //public static int ToInt(this uint t) => unchecked((int)t);

    ///// <summary>
    ///// Converts to System.Drawing.Color.
    ///// Can be used like <c>0xff123456.ToColor_()</c> instead of <c>Color.FromArgb(unchecked((int)0xff123456))</c>.
    ///// </summary>
    ///// <param name="t"></param>
    ///// <param name="makeOpaque">Add 0xff000000.</param>
    //internal static System.Drawing.Color ToColor_(this uint t, bool makeOpaque = true)
    //	=> System.Drawing.Color.FromArgb(unchecked((int)(t | (makeOpaque ? 0xff000000 : 0))));

    /// <summary>
    /// Converts to System.Drawing.Color. Makes opaque (alpha 0xff).
    /// Can be used like <c>0x123456.ToColor_()</c> instead of <c>Color.FromArgb(unchecked((int)0xff123456))</c>.
    /// </summary>
    internal static System.Drawing.Color ToColor_(this int t, bool bgr = false)
    {
        if (bgr)
        {
            t = ColorInt.SwapRB(t);
        }
        return(System.Drawing.Color.FromArgb(unchecked (0xff << 24 | t)));
    }
Пример #3
0
        /// <summary>
        /// Gets color of a screen pixel.
        /// </summary>
        /// <param name="p">x y in screen.</param>
        /// <returns>Pixel color in 0xAARRGGBB format. Alpha 0xFF. Returns 0 if fails, eg if x y is not in screen.</returns>
        /// <remarks>
        /// Uses, API <msdn>GetPixel</msdn>. It is slow. If need faster, try <see cref="getPixels(wnd, RECT, bool)"/> (get 1 or more pixels from window client area).
        /// </remarks>
        /// <example>
        /// <code><![CDATA[
        /// //print.clear();
        /// //for (;;) {
        /// //	1.s();
        /// //	print.it(uiimage.getPixel(mouse.xy));
        /// //}
        /// ]]></code>
        /// </example>
        public static unsafe uint getPixel(POINT p)
        {
            using var dc = new ScreenDC_();
            //using var dc = new WindowDC_(wnd.getwnd.root); //same speed. Same with printwindow.
            uint R = Api.GetPixel(dc, p.x, p.y);

            if (R == 0xFFFFFFFF)
            {
                return(0);                             //it's better than exception
            }
            return(ColorInt.SwapRB(R) | 0xFF000000);
        }
Пример #4
0
        public KColorPicker()
        {
            StackPanel p1 = new();
            StackPanel p2 = new() { Orientation = Orientation.Horizontal, Margin = new Thickness(0, 0, 0, 3) };

            p1.Children.Add(p2);

            TextBox tH = null, tL = null, tS = null;

            var fColor = new TextBlock {
                Text = "Color", ToolTip = "Color RRGGBB", Foreground = Brushes.Black
            };

            p2.Children.Add(fColor);

            var bColor = new Rectangle {
                Width = 9, Height = 9, Fill = Brushes.Black, Margin = new Thickness(4, 2, 4, 0)
            };

            p2.Children.Add(bColor);

            _tColor              = new() { Width = 68, Text = "000000" };
            _tColor.TextChanged += (o, e) => {
                int col = _GetColor(bgr: true);
                if (!_hlsChanging)
                {
                    var(H, L, S) = ColorInt.ToHLS(col, bgr: true);
                    _hlsChanging = true;
                    if (S != 0)
                    {
                        tH.Text = H.ToString();
                    }
                    tL.Text      = L.ToString();
                    tS.Text      = S.ToString();
                    _hlsChanging = false;
                }

                if (!_palSelecting)
                {
                    _pal.SelectColor(col);
                }

                var brush = new SolidColorBrush(System.Windows.Media.Color.FromRgb((byte)col, (byte)(col >> 8), (byte)(col >> 16)));
                fColor.Foreground = brush;
                bColor.Fill       = brush;

                if (ColorChanged != null)
                {
                    if (!BGR)
                    {
                        col = ColorInt.SwapRB(col);
                    }
                    ColorChanged(col);
                }
            };
            p2.Children.Add(_tColor);

            //hls: 0 H, 1 L, 2 S.
            TextBox _AddHLS(int hls, string label, string tooltip)
            {
                p2.Children.Add(new TextBlock {
                    Text = label, Margin = new Thickness(hls == 0 ? 18 : 12, 0, 4, 0), ToolTip = tooltip
                });
                TextBox t = new() { Width = 34, Text = "0" };

                t.TextChanged += (o, e) => {
                    if (_hlsChanging)
                    {
                        return;
                    }
                    var tb = o as TextBox;
                    int i  = tb.Text.ToInt();
                    if (i < 0 || i > 240)
                    {
                        _hlsChanging = true;
                        tb.Text      = Math.Clamp(i, 0, 240).ToS();
                        _hlsChanging = false;
                    }

                    int H = tH.Text.ToInt(), L = tL.Text.ToInt(), S = tS.Text.ToInt();
                    int col = ColorInt.FromHLS(H, L, S, bgr: true);
                    _hlsChanging = true;
                    _SetColor(col, bgr: true);
                    _hlsChanging = false;
                };
                t.MouseWheel += (o, e) => {
                    int d = e.Delta / 15;                     //+-8
                    if (o == tH)
                    {
                        d /= 2;                              //hue is more sensitive; 8 would jump directly from box to box
                    }
                    int i = t.Text.ToInt() + d;
                    if (hls == 0)
                    {
                        if (i < 0)
                        {
                            i += 240;
                        }
                        else if (i > 240)
                        {
                            i -= 240;
                        }
                    }
                    int v = Math.Clamp(i, 0, 240);
                    t.Text = v.ToS();
                };
                p2.Children.Add(t);
                return(t);
            }

            tH = _AddHLS(0, "H", "Hue 0-240. Change with mouse wheel.");
            tL = _AddHLS(1, "L", "Luminance 0-240. Change with mouse wheel.");
            tS = _AddHLS(2, "S", "Saturation 0-240. Change with mouse wheel.");

            _pal = new _Palette(this);
            p1.Children.Add(_pal);

            base.Content = p1;
        }

        class _Palette : HwndHost
        {
            KColorPicker _cp;
            wnd _w;
            int _dpi;
            int _cellSize;
            const int c_nHue = 30;            //number of hue columns. Must be 240-divisible.
            const int c_nLum = 7;             //number of luminance rows. Must be 240-divisible minus 1.