예제 #1
0
        /// <summary>Initializes the struct with default values.</summary>
        public static ColorGradientKey Default()
        {
            ColorGradientKey value = new ColorGradientKey();

            value.color = new Color();
            value.time  = 0f;

            return(value);
        }
            /// <summary>
            /// Handles input. Should be called by the owning window whenever a pointer is double-clicked.
            /// </summary>
            /// <param name="panelPos">Position of the pointer relative to the panel parent to this element.</param>
            /// <param name="button">Pointer button involved in the event.</param>
            internal void OnPointerDoubleClicked(Vector2I panelPos, PointerButton button)
            {
                Rect2I canvasBounds = canvas.Bounds;

                if (!canvasBounds.Contains(panelPos))
                {
                    return;
                }

                Vector2I canvasPos = panelPos - new Vector2I(canvasBounds.x, canvasBounds.y);

                int keyIdx;

                if (FindKey(canvasPos, out keyIdx))
                {
                    ColorPicker.Show(keys[keyIdx].color, false,
                                     (b, color) =>
                    {
                        if (b)
                        {
                            ColorGradientKey key = keys[keyIdx];
                            key.color            = color;
                            keys[keyIdx]         = key;

                            OnGradientModified?.Invoke(new ColorGradient(keys.ToArray()));
                            Rebuild();
                        }
                    });
                }
                else
                {
                    float time = PixelToTime(canvasPos.x);
                    if (time >= 0.0f && time <= 1.0f)
                    {
                        keys.Add(new ColorGradientKey(Color.Black, time));
                        keys.Sort((lhs, rhs) => lhs.time.CompareTo(rhs.time));

                        OnGradientModified?.Invoke(new ColorGradient(keys.ToArray()));
                    }

                    Rebuild();
                }
            }
            /// <summary>
            /// Handles input. Should be called by the owning window whenever a pointer is moved.
            /// </summary>
            /// <param name="panelPos">Position of the pointer relative to the panel parent to this element.</param>
            /// <param name="button">Pointer button involved in the event.</param>
            internal void OnPointerMoved(Vector2I panelPos, PointerButton button)
            {
                if (button != PointerButton.Left)
                {
                    return;
                }

                if (isMousePressedOverKey)
                {
                    Rect2I   canvasBounds = canvas.Bounds;
                    Vector2I canvasPos    = panelPos - new Vector2I(canvasBounds.x, canvasBounds.y);

                    if (!isDragInProgress)
                    {
                        int distance = Vector2I.Distance(canvasPos, dragStart);
                        if (distance >= DRAG_START_DISTANCE)
                        {
                            isDragInProgress = true;
                        }
                    }

                    if (isDragInProgress)
                    {
                        float time = PixelToTime(canvasPos.x);
                        if (time >= 0.0f && time <= 1.0f)
                        {
                            ColorGradientKey key = keys[selectedIdx];
                            key.time          = time;
                            keys[selectedIdx] = key;

                            OnGradientModified?.Invoke(new ColorGradient(keys.ToArray()));
                        }

                        Rebuild();
                    }
                }
            }
예제 #4
0
 private static extern void Internal_getKey(IntPtr thisPtr, uint idx, out ColorGradientKey __output);