internal static void DoMinMaxSlider(Rect position, int id, ref float value, ref float size, float visualStart, float visualEnd, float startLimit, float endLimit, GUIStyle slider, GUIStyle thumb, bool horiz) { Event current = Event.current; bool flag = size == 0f; float min = Mathf.Min(visualStart, visualEnd); float max = Mathf.Max(visualStart, visualEnd); float dragStartLimit = Mathf.Min(startLimit, endLimit); float dragEndLimit = Mathf.Max(startLimit, endLimit); MinMaxSliderState state = s_MinMaxSliderState; if ((GUIUtility.hotControl == id) && (state != null)) { min = state.dragStartLimit; dragStartLimit = state.dragStartLimit; max = state.dragEndLimit; dragEndLimit = state.dragEndLimit; } float num5 = 0f; float num6 = Mathf.Clamp(value, min, max); float num7 = Mathf.Clamp(value + size, min, max) - num6; float num8 = (visualStart <= visualEnd) ? ((float)1) : ((float)(-1)); if ((slider != null) && (thumb != null)) { float num9; float num10; Rect rect; Rect rect2; Rect rect3; float num13; float num14; if (horiz) { float num11 = (thumb.fixedWidth == 0f) ? ((float)thumb.padding.horizontal) : thumb.fixedWidth; num9 = ((position.width - slider.padding.horizontal) - num11) / (max - min); rect = new Rect((((num6 - min) * num9) + position.x) + slider.padding.left, position.y + slider.padding.top, (num7 * num9) + num11, position.height - slider.padding.vertical); rect2 = new Rect(rect.x, rect.y, (float)thumb.padding.left, rect.height); rect3 = new Rect(rect.xMax - thumb.padding.right, rect.y, (float)thumb.padding.right, rect.height); num10 = current.mousePosition.x - position.x; } else { float num12 = (thumb.fixedHeight == 0f) ? ((float)thumb.padding.vertical) : thumb.fixedHeight; num9 = ((position.height - slider.padding.vertical) - num12) / (max - min); rect = new Rect(position.x + slider.padding.left, (((num6 - min) * num9) + position.y) + slider.padding.top, position.width - slider.padding.horizontal, (num7 * num9) + num12); rect2 = new Rect(rect.x, rect.y, rect.width, (float)thumb.padding.top); rect3 = new Rect(rect.x, rect.yMax - thumb.padding.bottom, rect.width, (float)thumb.padding.bottom); num10 = current.mousePosition.y - position.y; } switch (current.GetTypeForControl(id)) { case EventType.MouseDown: if (position.Contains(current.mousePosition) && ((min - max) != 0f)) { if (state == null) { state = s_MinMaxSliderState = new MinMaxSliderState(); } state.dragStartLimit = startLimit; state.dragEndLimit = endLimit; if (rect.Contains(current.mousePosition)) { state.dragStartPos = num10; state.dragStartValue = value; state.dragStartSize = size; state.dragStartValuesPerPixel = num9; if (rect2.Contains(current.mousePosition)) { state.whereWeDrag = 1; } else if (rect3.Contains(current.mousePosition)) { state.whereWeDrag = 2; } else { state.whereWeDrag = 0; } GUIUtility.hotControl = id; current.Use(); } else if (slider != GUIStyle.none) { if ((size != 0f) && flag) { if (horiz) { if (num10 > (rect.xMax - position.x)) { value += (size * num8) * 0.9f; } else { value -= (size * num8) * 0.9f; } } else if (num10 > (rect.yMax - position.y)) { value += (size * num8) * 0.9f; } else { value -= (size * num8) * 0.9f; } state.whereWeDrag = 0; GUI.changed = true; s_NextScrollStepTime = DateTime.Now.AddMilliseconds((double)kFirstScrollWait); num13 = !horiz ? current.mousePosition.y : current.mousePosition.x; num14 = !horiz ? rect.y : rect.x; state.whereWeDrag = (num13 <= num14) ? 3 : 4; } else { if (horiz) { value = (((num10 - (rect.width * 0.5f)) / num9) + min) - (size * 0.5f); } else { value = (((num10 - (rect.height * 0.5f)) / num9) + min) - (size * 0.5f); } state.dragStartPos = num10; state.dragStartValue = value; state.dragStartSize = size; state.dragStartValuesPerPixel = num9; state.whereWeDrag = 0; GUI.changed = true; } GUIUtility.hotControl = id; value = Mathf.Clamp(value, dragStartLimit, dragEndLimit - size); current.Use(); } break; } break; case EventType.MouseUp: if (GUIUtility.hotControl == id) { current.Use(); GUIUtility.hotControl = 0; } break; case EventType.MouseDrag: if (GUIUtility.hotControl == id) { float num15 = (num10 - state.dragStartPos) / state.dragStartValuesPerPixel; switch (state.whereWeDrag) { case 0: value = Mathf.Clamp(state.dragStartValue + num15, dragStartLimit, dragEndLimit - size); break; case 1: value = state.dragStartValue + num15; size = state.dragStartSize - num15; if (value < dragStartLimit) { size -= dragStartLimit - value; value = dragStartLimit; } if (size < num5) { value -= num5 - size; size = num5; } break; case 2: size = state.dragStartSize + num15; if ((value + size) > dragEndLimit) { size = dragEndLimit - value; } if (size < num5) { size = num5; } break; } GUI.changed = true; current.Use(); return; } break; case EventType.Repaint: slider.Draw(position, GUIContent.none, id); thumb.Draw(rect, GUIContent.none, id); if (((GUIUtility.hotControl == id) && position.Contains(current.mousePosition)) && ((min - max) != 0f)) { if (rect.Contains(current.mousePosition)) { if ((state != null) && ((state.whereWeDrag == 3) || (state.whereWeDrag == 4))) { GUIUtility.hotControl = 0; } } else if (DateTime.Now >= s_NextScrollStepTime) { num13 = !horiz ? current.mousePosition.y : current.mousePosition.x; num14 = !horiz ? rect.y : rect.x; int num17 = (num13 <= num14) ? 3 : 4; if (num17 == state.whereWeDrag) { if ((size != 0f) && flag) { if (horiz) { if (num10 > (rect.xMax - position.x)) { value += (size * num8) * 0.9f; } else { value -= (size * num8) * 0.9f; } } else if (num10 > (rect.yMax - position.y)) { value += (size * num8) * 0.9f; } else { value -= (size * num8) * 0.9f; } state.whereWeDrag = -1; GUI.changed = true; } value = Mathf.Clamp(value, dragStartLimit, dragEndLimit - size); s_NextScrollStepTime = DateTime.Now.AddMilliseconds((double)kScrollWait); } } break; } break; } } }
internal static void DoMinMaxSlider(Rect position, int id, ref float value, ref float size, float visualStart, float visualEnd, float startLimit, float endLimit, GUIStyle slider, GUIStyle thumb, bool horiz) { Event evt = Event.current; bool usePageScrollbars = size == 0; float minVisual = Mathf.Min(visualStart, visualEnd); float maxVisual = Mathf.Max(visualStart, visualEnd); float minLimit = Mathf.Min(startLimit, endLimit); float maxLimit = Mathf.Max(startLimit, endLimit); MinMaxSliderState state = s_MinMaxSliderState; if (GUIUtility.hotControl == id && state != null) { minVisual = state.dragStartLimit; minLimit = state.dragStartLimit; maxVisual = state.dragEndLimit; maxLimit = state.dragEndLimit; } float minSize = 0; float displayValue = Mathf.Clamp(value, minVisual, maxVisual); float displaySize = Mathf.Clamp(value + size, minVisual, maxVisual) - displayValue; float sign = visualStart > visualEnd ? -1 : 1; if (slider == null || thumb == null) { return; } // Figure out the rects float pixelsPerValue; float mousePosition; Rect thumbRect; Rect thumbMinRect, thumbMaxRect; if (horiz) { float thumbSize = thumb.fixedWidth != 0 ? thumb.fixedWidth : thumb.padding.horizontal; pixelsPerValue = (position.width - slider.padding.horizontal - thumbSize) / (maxVisual - minVisual); thumbRect = new Rect( (displayValue - minVisual) * pixelsPerValue + position.x + slider.padding.left, position.y + slider.padding.top, displaySize * pixelsPerValue + thumbSize, position.height - slider.padding.vertical); thumbMinRect = new Rect(thumbRect.x, thumbRect.y, thumb.padding.left, thumbRect.height); thumbMaxRect = new Rect(thumbRect.xMax - thumb.padding.right, thumbRect.y, thumb.padding.right, thumbRect.height); mousePosition = evt.mousePosition.x - position.x; } else { float thumbSize = thumb.fixedHeight != 0 ? thumb.fixedHeight : thumb.padding.vertical; pixelsPerValue = (position.height - slider.padding.vertical - thumbSize) / (maxVisual - minVisual); thumbRect = new Rect( position.x + slider.padding.left, (displayValue - minVisual) * pixelsPerValue + position.y + slider.padding.top, position.width - slider.padding.horizontal, displaySize * pixelsPerValue + thumbSize); thumbMinRect = new Rect(thumbRect.x, thumbRect.y, thumbRect.width, thumb.padding.top); thumbMaxRect = new Rect(thumbRect.x, thumbRect.yMax - thumb.padding.bottom, thumbRect.width, thumb.padding.bottom); mousePosition = evt.mousePosition.y - position.y; } float mousePos; float thumbPos; switch (evt.GetTypeForControl(id)) { case EventType.MouseDown: // if the click is outside this control, just bail out... if (!position.Contains(evt.mousePosition) || minVisual - maxVisual == 0) { return; } if (state == null) { state = s_MinMaxSliderState = new MinMaxSliderState(); } // These are required to be set whenever we grab hotcontrol, regardless of if we actually drag or not. (case 585577) state.dragStartLimit = startLimit; state.dragEndLimit = endLimit; if (thumbRect.Contains(evt.mousePosition)) { // We have a mousedown on the thumb // Record where we're draging from, so the user can get back. state.dragStartPos = mousePosition; state.dragStartValue = value; state.dragStartSize = size; state.dragStartValuesPerPixel = pixelsPerValue; if (thumbMinRect.Contains(evt.mousePosition)) { state.whereWeDrag = 1; } else if (thumbMaxRect.Contains(evt.mousePosition)) { state.whereWeDrag = 2; } else { state.whereWeDrag = 0; } GUIUtility.hotControl = id; evt.Use(); return; } else { // We're outside the thumb, but inside the trough. // If we have no background, we just bail out. if (slider == GUIStyle.none) { return; } // If we have a scrollSize, we do pgup/pgdn style movements // if not, we just snap to the current position and begin tracking if (size != 0 && usePageScrollbars) { if (horiz) { if (mousePosition > thumbRect.xMax - position.x) { value += size * sign * .9f; } else { value -= size * sign * .9f; } } else { if (mousePosition > thumbRect.yMax - position.y) { value += size * sign * .9f; } else { value -= size * sign * .9f; } } state.whereWeDrag = 0; GUI.changed = true; s_NextScrollStepTime = System.DateTime.Now.AddMilliseconds(kFirstScrollWait); mousePos = horiz ? evt.mousePosition.x : evt.mousePosition.y; thumbPos = horiz ? thumbRect.x : thumbRect.y; state.whereWeDrag = mousePos > thumbPos ? 4 : 3; } else { if (horiz) { value = ((float)mousePosition - thumbRect.width * .5f) / pixelsPerValue + minVisual - size * .5f; } else { value = ((float)mousePosition - thumbRect.height * .5f) / pixelsPerValue + minVisual - size * .5f; } state.dragStartPos = mousePosition; state.dragStartValue = value; state.dragStartSize = size; state.dragStartValuesPerPixel = pixelsPerValue; state.whereWeDrag = 0; GUI.changed = true; } GUIUtility.hotControl = id; value = Mathf.Clamp(value, minLimit, maxLimit - size); evt.Use(); return; } case EventType.MouseDrag: if (GUIUtility.hotControl != id) { return; } // Recalculate the value from the mouse position. this has the side effect that values are relative to the // click point - no matter where inside the trough the original value was. Also means user can get back original value // if he drags back to start position. float deltaVal = (mousePosition - state.dragStartPos) / state.dragStartValuesPerPixel; switch (state.whereWeDrag) { case 0: // normal drag value = Mathf.Clamp(state.dragStartValue + deltaVal, minLimit, maxLimit - size); break; case 1: // min size drag value = state.dragStartValue + deltaVal; size = state.dragStartSize - deltaVal; if (value < minLimit) { size -= minLimit - value; value = minLimit; } if (size < minSize) { value -= minSize - size; size = minSize; } break; case 2: // max size drag size = state.dragStartSize + deltaVal; if (value + size > maxLimit) { size = maxLimit - value; } if (size < minSize) { size = minSize; } break; } GUI.changed = true; evt.Use(); break; case EventType.MouseUp: if (GUIUtility.hotControl == id) { evt.Use(); GUIUtility.hotControl = 0; } break; case EventType.Repaint: slider.Draw(position, GUIContent.none, id); thumb.Draw(thumbRect, GUIContent.none, id); // if the mouse is outside this control, just bail out... if (GUIUtility.hotControl != id || !position.Contains(evt.mousePosition) || minVisual - maxVisual == 0) { return; } if (thumbRect.Contains(evt.mousePosition)) { if (state != null && (state.whereWeDrag == 3 || state.whereWeDrag == 4)) // if was scrolling with "through" and the thumb reached mouse - sliding action over { GUIUtility.hotControl = 0; } return; } if (System.DateTime.Now < s_NextScrollStepTime) { return; } mousePos = horiz ? evt.mousePosition.x : evt.mousePosition.y; thumbPos = horiz ? thumbRect.x : thumbRect.y; int currentSide = mousePos > thumbPos ? 4 : 3; if (currentSide != state.whereWeDrag) { return; } // If we have a scrollSize, we do pgup/pgdn style movements if (size != 0 && usePageScrollbars) { if (horiz) { if (mousePosition > thumbRect.xMax - position.x) { value += size * sign * .9f; } else { value -= size * sign * .9f; } } else { if (mousePosition > thumbRect.yMax - position.y) { value += size * sign * .9f; } else { value -= size * sign * .9f; } } state.whereWeDrag = -1; GUI.changed = true; } value = Mathf.Clamp(value, minLimit, maxLimit - size); s_NextScrollStepTime = System.DateTime.Now.AddMilliseconds(kScrollWait); break; } }
internal static void DoMinMaxSlider(Rect position, int id, ref float value, ref float size, float visualStart, float visualEnd, float startLimit, float endLimit, GUIStyle slider, GUIStyle thumb, bool horiz) { Event event2 = Event.current; bool flag = size == 0f; float dragStartLimit = Mathf.Min(visualStart, visualEnd); float dragEndLimit = Mathf.Max(visualStart, visualEnd); float num7 = Mathf.Min(startLimit, endLimit); float num8 = Mathf.Max(startLimit, endLimit); MinMaxSliderState state = s_MinMaxSliderState; if ((GUIUtility.hotControl == id) && (state != null)) { dragStartLimit = state.dragStartLimit; num7 = state.dragStartLimit; dragEndLimit = state.dragEndLimit; num8 = state.dragEndLimit; } float num9 = 0f; float num10 = Mathf.Clamp(value, dragStartLimit, dragEndLimit); float num11 = Mathf.Clamp(value + size, dragStartLimit, dragEndLimit) - num10; float num12 = (visualStart <= visualEnd) ? 1f : -1f; if ((slider != null) && (thumb != null)) { float num; float num2; Rect rect; Rect rect2; Rect rect3; float num3; float num4; if (horiz) { float num13 = (thumb.fixedWidth == 0f) ? ((float)thumb.padding.horizontal) : thumb.fixedWidth; num = ((position.width - slider.padding.horizontal) - num13) / (dragEndLimit - dragStartLimit); rect = new Rect((((num10 - dragStartLimit) * num) + position.x) + slider.padding.left, position.y + slider.padding.top, (num11 * num) + num13, position.height - slider.padding.vertical); float introduced24 = rect.x; rect2 = new Rect(introduced24, rect.y, (float)thumb.padding.left, rect.height); rect3 = new Rect(rect.xMax - thumb.padding.right, rect.y, (float)thumb.padding.right, rect.height); num2 = event2.mousePosition.x - position.x; } else { float num14 = (thumb.fixedHeight == 0f) ? ((float)thumb.padding.vertical) : thumb.fixedHeight; num = ((position.height - slider.padding.vertical) - num14) / (dragEndLimit - dragStartLimit); rect = new Rect(position.x + slider.padding.left, (((num10 - dragStartLimit) * num) + position.y) + slider.padding.top, position.width - slider.padding.horizontal, (num11 * num) + num14); float introduced25 = rect.x; float introduced26 = rect.y; rect2 = new Rect(introduced25, introduced26, rect.width, (float)thumb.padding.top); float introduced27 = rect.x; rect3 = new Rect(introduced27, rect.yMax - thumb.padding.bottom, rect.width, (float)thumb.padding.bottom); num2 = event2.mousePosition.y - position.y; } switch (event2.GetTypeForControl(id)) { case 0: if (position.Contains(event2.mousePosition) && ((dragStartLimit - dragEndLimit) != 0f)) { if (state == null) { state = s_MinMaxSliderState = new MinMaxSliderState(); } if (!rect.Contains(event2.mousePosition)) { if (slider != GUIStyle.none) { if ((size != 0f) & flag) { if (horiz) { if (num2 > (rect.xMax - position.x)) { value += (size * num12) * 0.9f; } else { value -= (size * num12) * 0.9f; } } else if (num2 > (rect.yMax - position.y)) { value += (size * num12) * 0.9f; } else { value -= (size * num12) * 0.9f; } state.whereWeDrag = 0; GUI.changed = (true); s_NextScrollStepTime = DateTime.Now.AddMilliseconds((double)kFirstScrollWait); num3 = !horiz ? event2.mousePosition.y : event2.mousePosition.x; num4 = !horiz ? rect.y : rect.x; state.whereWeDrag = (num3 <= num4) ? 3 : 4; } else { if (horiz) { value = (((num2 - (rect.width * 0.5f)) / num) + dragStartLimit) - (size * 0.5f); } else { value = (((num2 - (rect.height * 0.5f)) / num) + dragStartLimit) - (size * 0.5f); } state.dragStartPos = num2; state.dragStartValue = value; state.dragStartSize = size; state.whereWeDrag = 0; GUI.changed = (true); } GUIUtility.hotControl = (id); value = Mathf.Clamp(value, num7, num8 - size); event2.Use(); } return; } state.dragStartPos = num2; state.dragStartValue = value; state.dragStartSize = size; state.dragStartValuesPerPixel = num; state.dragStartLimit = startLimit; state.dragEndLimit = endLimit; if (rect2.Contains(event2.mousePosition)) { state.whereWeDrag = 1; } else if (rect3.Contains(event2.mousePosition)) { state.whereWeDrag = 2; } else { state.whereWeDrag = 0; } GUIUtility.hotControl = (id); event2.Use(); } return; case (EventType)1: if (GUIUtility.hotControl == id) { event2.Use(); GUIUtility.hotControl = (0); } return; case (EventType)2: case (EventType)4: case (EventType)5: case (EventType)6: return; case (EventType)3: if (GUIUtility.hotControl == id) { float num15 = (num2 - state.dragStartPos) / state.dragStartValuesPerPixel; switch (state.whereWeDrag) { case 0: value = Mathf.Clamp(state.dragStartValue + num15, num7, num8 - size); break; case 1: value = state.dragStartValue + num15; size = state.dragStartSize - num15; if (value < num7) { size -= num7 - value; value = num7; } if (size < num9) { value -= num9 - size; size = num9; } break; case 2: size = state.dragStartSize + num15; if ((value + size) > num8) { size = num8 - value; } if (size < num9) { size = num9; } break; } GUI.changed = (true); event2.Use(); } return; case (EventType)7: slider.Draw(position, GUIContent.none, id); thumb.Draw(rect, GUIContent.none, id); if (((GUIUtility.hotControl == id) && position.Contains(event2.mousePosition)) && ((dragStartLimit - dragEndLimit) != 0f)) { if (!rect.Contains(event2.mousePosition)) { if (DateTime.Now >= s_NextScrollStepTime) { num3 = !horiz ? event2.mousePosition.y : event2.mousePosition.x; num4 = !horiz ? rect.y : rect.x; if (((num3 <= num4) ? 3 : 4) != state.whereWeDrag) { return; } if ((size != 0f) & flag) { if (horiz) { if (num2 > (rect.xMax - position.x)) { value += (size * num12) * 0.9f; } else { value -= (size * num12) * 0.9f; } } else if (num2 > (rect.yMax - position.y)) { value += (size * num12) * 0.9f; } else { value -= (size * num12) * 0.9f; } state.whereWeDrag = -1; GUI.changed = (true); } value = Mathf.Clamp(value, num7, num8 - size); s_NextScrollStepTime = DateTime.Now.AddMilliseconds((double)kScrollWait); } return; } if ((state != null) && ((state.whereWeDrag == 3) || (state.whereWeDrag == 4))) { GUIUtility.hotControl = (0); } } return; } } }
internal static void DoMinMaxSlider(Rect position, int id, ref float value, ref float size, float visualStart, float visualEnd, float startLimit, float endLimit, GUIStyle slider, GUIStyle thumb, bool horiz) { float num9; float num10; Rect rect; Rect rect2; Rect rect3; float num13; float num14; Event current = Event.current; bool flag = size == 0f; float min = Mathf.Min(visualStart, visualEnd); float max = Mathf.Max(visualStart, visualEnd); float dragStartLimit = Mathf.Min(startLimit, endLimit); float dragEndLimit = Mathf.Max(startLimit, endLimit); MinMaxSliderState state = s_MinMaxSliderState; if ((GUIUtility.hotControl == id) && (state != null)) { min = state.dragStartLimit; dragStartLimit = state.dragStartLimit; max = state.dragEndLimit; dragEndLimit = state.dragEndLimit; } float num5 = 0f; float num6 = Mathf.Clamp(value, min, max); float num7 = Mathf.Clamp(value + size, min, max) - num6; float num8 = (visualStart <= visualEnd) ? ((float) 1) : ((float) (-1)); if ((slider == null) || (thumb == null)) { return; } if (horiz) { float num11 = (thumb.fixedWidth == 0f) ? ((float) thumb.padding.horizontal) : thumb.fixedWidth; num9 = ((position.width - slider.padding.horizontal) - num11) / (max - min); rect = new Rect((((num6 - min) * num9) + position.x) + slider.padding.left, position.y + slider.padding.top, (num7 * num9) + num11, position.height - slider.padding.vertical); rect2 = new Rect(rect.x, rect.y, (float) thumb.padding.left, rect.height); rect3 = new Rect(rect.xMax - thumb.padding.right, rect.y, (float) thumb.padding.right, rect.height); num10 = current.mousePosition.x - position.x; } else { float num12 = (thumb.fixedHeight == 0f) ? ((float) thumb.padding.vertical) : thumb.fixedHeight; num9 = ((position.height - slider.padding.vertical) - num12) / (max - min); rect = new Rect(position.x + slider.padding.left, (((num6 - min) * num9) + position.y) + slider.padding.top, position.width - slider.padding.horizontal, (num7 * num9) + num12); rect2 = new Rect(rect.x, rect.y, rect.width, (float) thumb.padding.top); rect3 = new Rect(rect.x, rect.yMax - thumb.padding.bottom, rect.width, (float) thumb.padding.bottom); num10 = current.mousePosition.y - position.y; } switch (current.GetTypeForControl(id)) { case EventType.MouseDown: if (position.Contains(current.mousePosition) && ((min - max) != 0f)) { if (state == null) { state = s_MinMaxSliderState = new MinMaxSliderState(); } state.dragStartLimit = startLimit; state.dragEndLimit = endLimit; if (rect.Contains(current.mousePosition)) { state.dragStartPos = num10; state.dragStartValue = value; state.dragStartSize = size; state.dragStartValuesPerPixel = num9; if (rect2.Contains(current.mousePosition)) { state.whereWeDrag = 1; } else if (rect3.Contains(current.mousePosition)) { state.whereWeDrag = 2; } else { state.whereWeDrag = 0; } GUIUtility.hotControl = id; current.Use(); return; } if (slider != GUIStyle.none) { if ((size != 0f) && flag) { if (horiz) { if (num10 > (rect.xMax - position.x)) { value += (size * num8) * 0.9f; } else { value -= (size * num8) * 0.9f; } } else if (num10 > (rect.yMax - position.y)) { value += (size * num8) * 0.9f; } else { value -= (size * num8) * 0.9f; } state.whereWeDrag = 0; GUI.changed = true; s_NextScrollStepTime = DateTime.Now.AddMilliseconds((double) kFirstScrollWait); num13 = !horiz ? current.mousePosition.y : current.mousePosition.x; num14 = !horiz ? rect.y : rect.x; state.whereWeDrag = (num13 <= num14) ? 3 : 4; } else { if (horiz) { value = (((num10 - (rect.width * 0.5f)) / num9) + min) - (size * 0.5f); } else { value = (((num10 - (rect.height * 0.5f)) / num9) + min) - (size * 0.5f); } state.dragStartPos = num10; state.dragStartValue = value; state.dragStartSize = size; state.dragStartValuesPerPixel = num9; state.whereWeDrag = 0; GUI.changed = true; } GUIUtility.hotControl = id; value = Mathf.Clamp(value, dragStartLimit, dragEndLimit - size); current.Use(); } return; } return; case EventType.MouseUp: if (GUIUtility.hotControl == id) { current.Use(); GUIUtility.hotControl = 0; } return; case EventType.MouseMove: case EventType.KeyDown: case EventType.KeyUp: case EventType.ScrollWheel: return; case EventType.MouseDrag: if (GUIUtility.hotControl == id) { float num15 = (num10 - state.dragStartPos) / state.dragStartValuesPerPixel; switch (state.whereWeDrag) { case 0: value = Mathf.Clamp(state.dragStartValue + num15, dragStartLimit, dragEndLimit - size); goto Label_069F; case 1: value = state.dragStartValue + num15; size = state.dragStartSize - num15; if (value < dragStartLimit) { size -= dragStartLimit - value; value = dragStartLimit; } if (size < num5) { value -= num5 - size; size = num5; } goto Label_069F; case 2: size = state.dragStartSize + num15; if ((value + size) > dragEndLimit) { size = dragEndLimit - value; } if (size < num5) { size = num5; } goto Label_069F; } break; } return; case EventType.Repaint: slider.Draw(position, GUIContent.none, id); thumb.Draw(rect, GUIContent.none, id); if (((GUIUtility.hotControl == id) && position.Contains(current.mousePosition)) && ((min - max) != 0f)) { if (rect.Contains(current.mousePosition)) { if ((state != null) && ((state.whereWeDrag == 3) || (state.whereWeDrag == 4))) { GUIUtility.hotControl = 0; } return; } if (DateTime.Now >= s_NextScrollStepTime) { num13 = !horiz ? current.mousePosition.y : current.mousePosition.x; num14 = !horiz ? rect.y : rect.x; int num16 = (num13 <= num14) ? 3 : 4; if (num16 != state.whereWeDrag) { return; } if ((size != 0f) && flag) { if (horiz) { if (num10 > (rect.xMax - position.x)) { value += (size * num8) * 0.9f; } else { value -= (size * num8) * 0.9f; } } else if (num10 > (rect.yMax - position.y)) { value += (size * num8) * 0.9f; } else { value -= (size * num8) * 0.9f; } state.whereWeDrag = -1; GUI.changed = true; } value = Mathf.Clamp(value, dragStartLimit, dragEndLimit - size); s_NextScrollStepTime = DateTime.Now.AddMilliseconds((double) kScrollWait); } return; } return; default: return; } Label_069F: GUI.changed = true; current.Use(); }
private static void DoMinMaxSlider(Rect position, int id, ref float value, ref float size, float visualStart, float visualEnd, float startLimit, float endLimit, GUIStyle slider, GUIStyle thumb, bool horiz) { var current = Event.current; var flag = size == 0f; var num = Mathf.Min(visualStart, visualEnd); var num2 = Mathf.Max(visualStart, visualEnd); var num3 = Mathf.Min(startLimit, endLimit); var num4 = Mathf.Max(startLimit, endLimit); var minMaxSliderState = s_MinMaxSliderState; if (GUIUtility.hotControl == id && minMaxSliderState != null) { num = minMaxSliderState.dragStartLimit; num3 = minMaxSliderState.dragStartLimit; num2 = minMaxSliderState.dragEndLimit; num4 = minMaxSliderState.dragEndLimit; } const float num5 = 0f; var num6 = Mathf.Clamp(value, num, num2); var num7 = Mathf.Clamp(value + size, num, num2) - num6; var num8 = visualStart <= visualEnd ? 1f : -1f; if (slider == null || thumb == null) { return; } float num10; Rect position2; Rect rect; Rect rect2; float num11; if (horiz) { var num9 = thumb.fixedWidth == 0f ? thumb.padding.horizontal : thumb.fixedWidth; num10 = (position.width - slider.padding.horizontal - num9) / (num2 - num); position2 = new Rect((num6 - num) * num10 + position.x + slider.padding.left, position.y + slider.padding.top, num7 * num10 + num9, position.height - slider.padding.vertical); rect = new Rect(position2.x, position2.y, thumb.padding.left, position2.height); rect2 = new Rect(position2.xMax - thumb.padding.right, position2.y, thumb.padding.right, position2.height); num11 = current.mousePosition.x - position.x; } else { var num12 = thumb.fixedHeight == 0f ? thumb.padding.vertical : thumb.fixedHeight; num10 = (position.height - slider.padding.vertical - num12) / (num2 - num); position2 = new Rect(position.x + slider.padding.left, (num6 - num) * num10 + position.y + slider.padding.top, position.width - slider.padding.horizontal, num7 * num10 + num12); rect = new Rect(position2.x, position2.y, position2.width, thumb.padding.top); rect2 = new Rect(position2.x, position2.yMax - thumb.padding.bottom, position2.width, thumb.padding.bottom); num11 = current.mousePosition.y - position.y; } switch (current.GetTypeForControl(id)) { case EventType.MouseDown: if (!position.Contains(current.mousePosition) || num - num2 == 0f) { return; } if (minMaxSliderState == null) { minMaxSliderState = s_MinMaxSliderState = new MinMaxSliderState(); } if (position2.Contains(current.mousePosition)) { minMaxSliderState.dragStartPos = num11; minMaxSliderState.dragStartValue = value; minMaxSliderState.dragStartSize = size; minMaxSliderState.dragStartValuesPerPixel = num10; minMaxSliderState.dragStartLimit = startLimit; minMaxSliderState.dragEndLimit = endLimit; if (rect.Contains(current.mousePosition)) { minMaxSliderState.whereWeDrag = 1; } else if (rect2.Contains(current.mousePosition)) { minMaxSliderState.whereWeDrag = 2; } else { minMaxSliderState.whereWeDrag = 0; } GUIUtility.hotControl = id; current.Use(); return; } if (slider == GUIStyle.none) { return; } if (size != 0f && flag) { if (horiz) { if (num11 > position2.xMax - position.x) { value += size * num8 * 0.9f; } else { value -= size * num8 * 0.9f; } } else if (num11 > position2.yMax - position.y) { value += size * num8 * 0.9f; } else { value -= size * num8 * 0.9f; } minMaxSliderState.whereWeDrag = 0; GUI.changed = true; s_NextScrollStepTime = DateTime.Now.AddMilliseconds(kFirstScrollWait); var num13 = !horiz ? current.mousePosition.y : current.mousePosition.x; var num14 = !horiz ? position2.y : position2.x; minMaxSliderState.whereWeDrag = num13 <= num14 ? 3 : 4; } else { if (horiz) { value = (num11 - position2.width * 0.5f) / num10 + num - size * 0.5f; } else { value = (num11 - position2.height * 0.5f) / num10 + num - size * 0.5f; } minMaxSliderState.dragStartPos = num11; minMaxSliderState.dragStartValue = value; minMaxSliderState.dragStartSize = size; minMaxSliderState.whereWeDrag = 0; GUI.changed = true; } GUIUtility.hotControl = id; value = Mathf.Clamp(value, num3, num4 - size); current.Use(); return; case EventType.MouseUp: if (GUIUtility.hotControl != id) { return; } current.Use(); GUIUtility.hotControl = 0; return; case EventType.MouseMove: case EventType.KeyDown: case EventType.KeyUp: case EventType.ScrollWheel: return; case EventType.MouseDrag: if (GUIUtility.hotControl != id) { return; } var num15 = (num11 - minMaxSliderState.dragStartPos) / minMaxSliderState.dragStartValuesPerPixel; switch (minMaxSliderState.whereWeDrag) { case 0: value = Mathf.Clamp(minMaxSliderState.dragStartValue + num15, num3, num4 - size); break; case 1: value = minMaxSliderState.dragStartValue + num15; size = minMaxSliderState.dragStartSize - num15; if (value < num3) { size -= num3 - value; value = num3; } if (size < num5) { value -= num5 - size; size = num5; } break; case 2: size = minMaxSliderState.dragStartSize + num15; if (value + size > num4) { size = num4 - value; } if (size < num5) { size = num5; } break; } GUI.changed = true; current.Use(); return; case EventType.Repaint: slider.Draw(position, GUIContent.none, id); thumb.Draw(position2, GUIContent.none, id); if (GUIUtility.hotControl != id || !position.Contains(current.mousePosition) || num - num2 == 0f) { return; } if (position2.Contains(current.mousePosition)) { if (minMaxSliderState != null && (minMaxSliderState.whereWeDrag == 3 || minMaxSliderState.whereWeDrag == 4)) { GUIUtility.hotControl = 0; } return; } if (DateTime.Now >= s_NextScrollStepTime) { var num13 = !horiz ? current.mousePosition.y : current.mousePosition.x; var num14 = !horiz ? position2.y : position2.x; if (minMaxSliderState != null && (num13 <= num14 ? 3 : 4) != minMaxSliderState.whereWeDrag) { return; } if (size != 0f && flag) { if (horiz) { if (num11 > position2.xMax - position.x) { value += size * num8 * 0.9f; } else { value -= size * num8 * 0.9f; } } else if (num11 > position2.yMax - position.y) { value += size * num8 * 0.9f; } else { value -= size * num8 * 0.9f; } if (minMaxSliderState != null) { minMaxSliderState.whereWeDrag = -1; } GUI.changed = true; } value = Mathf.Clamp(value, num3, num4 - size); s_NextScrollStepTime = DateTime.Now.AddMilliseconds(kScrollWait); } return; default: return; } }