示例#1
0
 private Color DrawHVArea(float x, float y) => ToolBox.HSVToRGB(SelectedHue, x, 1.0f - y);
示例#2
0
 private Color DrawHueArea(float x, float y) => ToolBox.HSVToRGB(y * 360f, 1f, 1f);
示例#3
0
        protected override void Update(float deltaTime)
        {
            base.Update(deltaTime);

            if (!isInitialized)
            {
                Init();
                isInitialized = true;
            }

            if (!PlayerInput.PrimaryMouseButtonHeld())
            {
                mouseHeld = false;
            }

            if (GUI.MouseOn != this)
            {
                return;
            }

            Rectangle mainArea = MainArea,
                      hueArea  = HueArea;

            hueArea.Location  += Rect.Location;
            mainArea.Location += Rect.Location;

            if (PlayerInput.PrimaryMouseButtonDown())
            {
                mouseHeld = true;
                if (hueArea.Contains(PlayerInput.MousePosition))
                {
                    selectedRect = HueArea;
                }
                else if (mainArea.Contains(PlayerInput.MousePosition))
                {
                    selectedRect = MainArea;
                }
                else
                {
                    mouseHeld = false;
                }
            }

            if (!PlayerInput.PrimaryMouseButtonHeld())
            {
                mouseHeld = false;
            }

            if (mouseHeld && (PlayerInput.MouseSpeed != Vector2.Zero || PlayerInput.PrimaryMouseButtonDown()))
            {
                if (selectedRect == HueArea)
                {
                    Vector2 pos = PlayerInput.MousePosition - hueArea.Location.ToVector2();
                    SelectedHue = Math.Clamp(pos.Y / hueArea.Height * 360f, 0, 360);
                    RefreshHue();
                }
                else if (selectedRect == MainArea)
                {
                    var(x, y)          = PlayerInput.MousePosition - mainArea.Location.ToVector2();
                    SelectedSaturation = Math.Clamp(x / mainArea.Width, 0, 1);
                    SelectedValue      = Math.Clamp(1f - (y / mainArea.Height), 0, 1);
                }

                CurrentColor = ToolBox.HSVToRGB(SelectedHue, SelectedSaturation, SelectedValue);

                OnColorSelected?.Invoke(this, CurrentColor);
            }
        }