Example #1
0
        /// <summary>
        /// 跟随模式时,更新当前窗口的位置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void carettimer_Tick(object sender, EventArgs e)
        {
            if (currentDisplayMode != DisplayMode.Follow)
            {
                return;
            }

            // 如果光标位置不变,颜色也不变,就不绘制了
            if (MousePosition.Equals(lastPosition))
            {
                return;
            }

            FollowCaret();
        }
Example #2
0
        /// <summary>
        /// 更新当前获取的颜色
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void colortimer_Tick(object sender, EventArgs e)
        {
            if (!stopDrawPreview && previewForm.MouseOnMe)
            {
                // 如果没有停止预览,并且鼠标在预览窗口上
                // 就不取色,这是为了防止因循环取色导致过高的资源占用
                return;
            }
            if (!settingLoaded)
            {
                // 不晓得为啥,在启动时加载Visible会被覆盖,所在放到这里来了
                SwitchDisplayMode(Settings.Main.Display);

                settingLoaded = true;
            }

            var color = ColorUtil.GetColor(MousePosition);

            // 如果光标位置不变,颜色也不变,就不绘制了
            if (MousePosition.Equals(lastPosition) && color.Equals(lastColor))
            {
                return;
            }

            lastPosition = MousePosition;
            lastColor    = color;

            colorBuffer.Clear();
            var val = colorBuffer.AppendFormat("{0:X2}{1:X2}{2:X2}", color.R, color.G, color.B).ToString();

            lbHex.Tag = val;
            colorBuffer.Clear();

            lbHex.Text = colorBuffer.AppendFormat("#{0}", lbHex.Tag).ToString();
            colorBuffer.Clear();

            val       = colorBuffer.AppendFormat("{0},{1},{2}", color.R, color.G, color.B).ToString();
            lbRgb.Tag = val;
            colorBuffer.Clear();

            lbRgb.Text = colorBuffer.AppendFormat("RGB({0})", lbRgb.Tag).ToString();
            colorBuffer.Clear();

            if (trayMenuShowPreview.Checked && !stopDrawPreview)
            {
                DrawPreview(MousePosition);
            }

            if (FormatMode.Mini == currentFormatMode)
            {
                if (!lbColorPreview.Visible)
                {
                    lbColorPreview.Show();
                }
                lbColorPreview.BackColor = color;
                return;
            }

            if (lbColorPreview.Visible)
            {
                lbColorPreview.Hide();
            }

            var contrastColor = ColorUtil.GetContrastColor(color);

            if (FormatMode.Standard == currentFormatMode)
            {
                lbRgb.BackColor = color;
                lbRgb.ForeColor = contrastColor;
                return;
            }

            if (lbRgb.BackColor != BackColor)
            {
                lbRgb.BackColor = BackColor;
                lbRgb.ForeColor = ForeColor;
            }

            // var hsl = HSL.Parse(color);
            var hsl = new HSL(color.GetHue(), color.GetSaturation(), color.GetBrightness());

            lbHsl.Text = colorBuffer.AppendFormat("HSL({0},{1},{2})",
                                                  Math.Round(hsl.H),
                                                  Util.Round(hsl.S * 100),
                                                  Util.Round(hsl.L * 100)).ToString();
            colorBuffer.Clear();

            var hsb = HSB.Parse(color);

            lbHsb.Text = colorBuffer.AppendFormat("HSB({0},{1},{2})",
                                                  Math.Round(hsb.H),
                                                  Util.Round(hsb.S * 100),
                                                  Util.Round(hsb.B * 100)).ToString();
            colorBuffer.Clear();

            var hsi = HSI.Parse(color, currentHsiAlgorithm);

            lbHsi.Text = colorBuffer.AppendFormat("HSI({0},{1},{2})",
                                                  Math.Round(hsi.H),
                                                  Util.Round(hsi.S * 100),
                                                  Util.Round(hsi.I * 100)).ToString();
            colorBuffer.Clear();

            pnExt.BackColor = color;
            pnExt.ForeColor = contrastColor;
        }
Example #3
0
        private void onRepeatedlyExecute()
        {
            if (Interlocked.CompareExchange(ref _inUpdate, 1, 0) != 0)
            {
                return;
            }
            try
            {
                MousePosition position = _input.MousePosition;

                var  obj            = _hitTest.ObjectAtMousePosition;
                bool leftMouseDown  = _input.LeftMouseButtonDown;
                bool rightMouseDown = _input.RightMouseButtonDown;
                bool anyButtonDown  = leftMouseDown || rightMouseDown;
                var  subscribers    = _subscribers;

                Subscriber subscriberToAdd;
                while (_subscribersToAdd.TryDequeue(out subscriberToAdd))
                {
                    subscribers.Add(subscriberToAdd);
                }

                string entityToRemove;
                while (_subscribersToRemove.TryDequeue(out entityToRemove))
                {
                    int index = subscribers.FindIndex(sub => sub.Entity.ID == entityToRemove);
                    if (index >= 0)
                    {
                        subscribers.RemoveAt(index);
                    }
                }

                foreach (var subscriber in subscribers)
                {
                    if (!subscriber.Enabled.Enabled || !subscriber.Visible.Visible || subscriber.Enabled.ClickThrough)
                    {
                        continue;
                    }
                    bool mouseIn = obj == subscriber.Entity;

                    subscriber.FireMouseMove  = mouseIn && !_mousePosition.Equals(position);
                    subscriber.FireMouseEnter = mouseIn && !subscriber.Events.IsMouseIn;
                    subscriber.FireMouseLeave = !mouseIn && subscriber.Events.IsMouseIn;
                    subscriber.SetMouseIn(mouseIn);
                    if (anyButtonDown)
                    {
                        subscriber.WasClickedIn = mouseIn && anyButtonDown;
                    }
                }

                _mousePosition = position;

                bool wasLeftMouseDown  = _leftMouseDown;
                bool wasRightMouseDown = _rightMouseDown;
                _leftMouseDown  = leftMouseDown;
                _rightMouseDown = rightMouseDown;

                foreach (var subscriber in subscribers)
                {
                    if (!subscriber.Enabled.Enabled || !subscriber.Visible.Visible || subscriber.Enabled.ClickThrough)
                    {
                        continue;
                    }
                    fireAndForgetEvents(subscriber, position, wasLeftMouseDown, wasRightMouseDown, leftMouseDown, rightMouseDown);
                }
            }
            finally
            {
                _inUpdate = 0;
            }
        }