swap() private static method

private static swap ( float &f1, float &f2 ) : void
f1 float
f2 float
return void
Ejemplo n.º 1
0
        private Vector2 Slider2D(Rect rect, Vector2 value, Vector2 maxvalue, Vector2 minvalue, GUIStyle backStyle, GUIStyle thumbStyle)
        {
            if (backStyle == null)
            {
                return(value);
            }
            if (thumbStyle == null)
            {
                return(value);
            }
            int controlID = GUIUtility.GetControlID(ColorPicker.s_Slider2Dhash, FocusType.Native);

            if (maxvalue.x < minvalue.x)
            {
                ColorPicker.swap(ref maxvalue.x, ref minvalue.x);
            }
            if (maxvalue.y < minvalue.y)
            {
                ColorPicker.swap(ref maxvalue.y, ref minvalue.y);
            }
            float   num      = (thumbStyle.fixedHeight != 0f) ? thumbStyle.fixedHeight : ((float)thumbStyle.padding.vertical);
            float   num2     = (thumbStyle.fixedWidth != 0f) ? thumbStyle.fixedWidth : ((float)thumbStyle.padding.horizontal);
            Vector2 vector   = new Vector2((rect.width - (float)(backStyle.padding.right + backStyle.padding.left) - num2 * 2f) / (maxvalue.x - minvalue.x), (rect.height - (float)(backStyle.padding.top + backStyle.padding.bottom) - num * 2f) / (maxvalue.y - minvalue.y));
            Rect    position = new Rect(rect.x + value.x * vector.x + num2 / 2f + (float)backStyle.padding.left - minvalue.x * vector.x, rect.y + value.y * vector.y + num / 2f + (float)backStyle.padding.top - minvalue.y * vector.y, num2, num);
            Event   current  = Event.current;

            switch (current.GetTypeForControl(controlID))
            {
            case EventType.MouseDown:
                if (rect.Contains(current.mousePosition))
                {
                    GUIUtility.hotControl = controlID;
                    value.x     = (current.mousePosition.x - rect.x - num2 - (float)backStyle.padding.left) / vector.x + minvalue.x;
                    value.y     = (current.mousePosition.y - rect.y - num - (float)backStyle.padding.top) / vector.y + minvalue.y;
                    GUI.changed = true;
                    Event.current.Use();
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == controlID)
                {
                    GUIUtility.hotControl = 0;
                    current.Use();
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == controlID)
                {
                    value.x     = (current.mousePosition.x - rect.x - num2 - (float)backStyle.padding.left) / vector.x + minvalue.x;
                    value.y     = (current.mousePosition.y - rect.y - num - (float)backStyle.padding.top) / vector.y + minvalue.y;
                    value.x     = Mathf.Clamp(value.x, minvalue.x, maxvalue.x);
                    value.y     = Mathf.Clamp(value.y, minvalue.y, maxvalue.y);
                    GUI.changed = true;
                    Event.current.Use();
                }
                break;

            case EventType.Repaint:
                backStyle.Draw(rect, GUIContent.none, controlID);
                thumbStyle.Draw(position, GUIContent.none, controlID);
                break;
            }
            return(value);
        }