示例#1
0
        public override void DoWindowContents(Rect inRect)
        {
            // set up rects
            // pickers & sliders
            Rect pickerRect = new Rect(inRect.xMin, inRect.yMin, pickerSize, pickerSize);
            Rect hueRect    = new Rect(pickerRect.xMax + _margin, inRect.yMin, sliderWidth, pickerSize);
            Rect alphaRect  = new Rect(hueRect.xMax + _margin, inRect.yMin, sliderWidth, pickerSize);

            // previews
            Rect previewRect    = new Rect(alphaRect.xMax + _margin, inRect.yMin, previewSize, previewSize);
            Rect previewOldRect = new Rect(previewRect.xMax, inRect.yMin, previewSize, previewSize);

            // buttons and textfields
            Rect okRect     = new Rect(alphaRect.xMax + _margin, inRect.yMax - _fieldHeight, previewSize * 2, _fieldHeight);
            Rect applyRect  = new Rect(alphaRect.xMax + _margin, inRect.yMax - 2 * _fieldHeight - _margin, previewSize - _margin / 2, _fieldHeight);
            Rect cancelRect = new Rect(applyRect.xMax + _margin, applyRect.yMin, previewSize - _margin / 2, _fieldHeight);
            Rect hexRect    = new Rect(alphaRect.xMax + _margin, inRect.yMax - 3 * _fieldHeight - 2 * _margin, previewSize * 2, _fieldHeight);

            // move ok/cancel buttons for the simple view with buttons
            if (!_preview && !_autoApply)
            {
                cancelRect = new Rect(inRect.xMin, pickerRect.yMax + _margin, (pickerSize - _margin) / 2, _fieldHeight);
                okRect     = cancelRect;
                okRect.x  += (pickerSize + _margin) / 2;
            }

            // draw transparency backgrounds
            GUI.DrawTexture(pickerRect, PickerAlphaBG);
            GUI.DrawTexture(alphaRect, SliderAlphaBG);
            if (_preview)
            {
                GUI.DrawTexture(previewRect, PreviewAlphaBG);
                GUI.DrawTexture(previewOldRect, PreviewAlphaBG);
            }

            // draw picker foregrounds
            GUI.DrawTexture(pickerRect, ColorPickerBG);
            GUI.DrawTexture(hueRect, HuePickerBG);
            GUI.DrawTexture(alphaRect, AlphaPickerBG);
            if (_preview)
            {
                GUI.DrawTexture(previewRect, TempPreviewBG);
                GUI.DrawTexture(previewOldRect, PreviewBG);
            }

            // draw slider handles
            Rect hueHandleRect    = new Rect(hueRect.xMin - 3f, hueRect.yMin + _huePosition - handleSize / 2, sliderWidth + 6f, handleSize);
            Rect pickerHandleRect = new Rect(pickerRect.xMin + _pickerPosition.x - handleSize / 2, pickerRect.yMin + _pickerPosition.y - handleSize / 2, handleSize, handleSize);
            Rect alphaHandleRect  = new Rect(alphaRect.xMin - 3f, alphaRect.yMin + _alphaPosition - handleSize / 2, sliderWidth + 6f, handleSize);

            GUI.DrawTexture(hueHandleRect, TempPreviewBG);
            GUI.DrawTexture(pickerHandleRect, TempPreviewBG);
            GUI.DrawTexture(alphaHandleRect, TempPreviewBG);

            // border on slider handles
            GUI.color = Color.gray;
            Widgets.DrawBox(hueHandleRect);
            Widgets.DrawBox(pickerHandleRect);
            Widgets.DrawBox(alphaHandleRect);
            GUI.color = Color.white;

            // reset active control on mouseup
            if (Input.GetMouseButtonUp(0))
            {
                _activeControl = controls.none;
            }

            // colorpicker interaction
            if (Mouse.IsOver(pickerRect))
            {
                if (Input.GetMouseButtonDown(0))
                {
                    _activeControl = controls.colorPicker;
                }

                if (_activeControl == controls.colorPicker)
                {
                    Vector2 MousePosition  = Event.current.mousePosition;
                    Vector2 PositionInRect = MousePosition - new Vector2(pickerRect.xMin, pickerRect.yMin);

                    PickerAction(PositionInRect);
                }
            }

            // hue picker interaction
            if (Mouse.IsOver(hueRect))
            {
                if (Input.GetMouseButtonDown(0))
                {
                    _activeControl = controls.huePicker;
                }

                if (Event.current.type == EventType.ScrollWheel)
                {
                    H           -= Event.current.delta.y * UnitsPerPixel;
                    _huePosition = Mathf.Clamp(_huePosition + Event.current.delta.y, 0f, pickerSize);
                    Event.current.Use();
                }

                if (_activeControl == controls.huePicker)
                {
                    float MousePosition  = Event.current.mousePosition.y;
                    float PositionInRect = MousePosition - hueRect.yMin;

                    HueAction(PositionInRect);
                }
            }

            // alpha picker interaction
            if (Mouse.IsOver(alphaRect))
            {
                if (Input.GetMouseButtonDown(0))
                {
                    _activeControl = controls.alphaPicker;
                }

                if (Event.current.type == EventType.ScrollWheel)
                {
                    A -= Event.current.delta.y * UnitsPerPixel;
                    _alphaPosition = Mathf.Clamp(_alphaPosition + Event.current.delta.y, 0f, pickerSize);
                    Event.current.Use();
                }

                if (_activeControl == controls.alphaPicker)
                {
                    float MousePosition  = Event.current.mousePosition.y;
                    float PositionInRect = MousePosition - alphaRect.yMin;

                    AlphaAction(PositionInRect);
                }
            }

            if (!_autoApply)
            {
                // buttons and text field
                // for some reason scrolling sometimes changes text size
                Text.Font = GameFont.Small;
                if (Widgets.ButtonText(okRect, "OK"))
                {
                    Apply();
                    Close();
                }

                if (Widgets.ButtonText(applyRect, "Apply"))
                {
                    Apply();
                    SetColor();
                }

                if (Widgets.ButtonText(cancelRect, "Cancel"))
                {
                    Close();
                }
            }

            if (_preview)
            {
                if (_hexIn != _hexOut)
                {
                    if (ColorHelper.TryHexToRGB(_hexIn, ref tempColor))
                    {
                        Notify_RGBUpdated();
                    }
                    else
                    {
                        GUI.color = Color.red;
                    }
                }

                _hexIn = Widgets.TextField(hexRect, _hexIn);
            }

            GUI.color = Color.white;
        }