mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Move interpolation settings to ComponentSettings
This commit is contained in:
@@ -37,6 +37,12 @@ public class ComponentSettings {
|
||||
private static final RegistryValue PRECISION_TOUCHPAD_INTERPOLATION = Registry.get("idea.true.smooth.scrolling.interpolation.precision.touchpad");
|
||||
private static final RegistryValue OTHER_SOURCES_INTERPOLATION = Registry.get("idea.true.smooth.scrolling.interpolation.other");
|
||||
|
||||
private static final RegistryValue SCROLLBAR_DELAY = Registry.get("idea.true.smooth.scrolling.interpolation.scrollbar.delay");
|
||||
private static final RegistryValue MOUSE_WHEEL_MIN_DELAY = Registry.get("idea.true.smooth.scrolling.interpolation.mouse.wheel.delay.min");
|
||||
private static final RegistryValue MOUSE_WHEEL_MAX_DELAY = Registry.get("idea.true.smooth.scrolling.interpolation.mouse.wheel.delay.max");
|
||||
private static final RegistryValue PRECISION_TOUCHPAD_DELAY = Registry.get("idea.true.smooth.scrolling.interpolation.precision.touchpad.delay");
|
||||
private static final RegistryValue OTHER_SOURCES_DELAY = Registry.get("idea.true.smooth.scrolling.interpolation.other.delay");
|
||||
|
||||
private static final RegistryValue DYNAMIC_SCROLLBARS = Registry.get("idea.true.smooth.scrolling.dynamic.scrollbars");
|
||||
|
||||
private boolean mySmoothScrollingEnabled = true;
|
||||
@@ -72,6 +78,9 @@ public class ComponentSettings {
|
||||
|
||||
// Returns whether scrolling interpolation is enabled for particular input source
|
||||
public boolean isInterpolationEnabledFor(InputSource source) {
|
||||
if (!SystemProperties.isTrueSmoothScrollingEnabled()) {
|
||||
return false;
|
||||
}
|
||||
if (!SCROLLING_INTERPOLATION.asBoolean()) {
|
||||
return false;
|
||||
}
|
||||
@@ -88,6 +97,21 @@ public class ComponentSettings {
|
||||
}
|
||||
}
|
||||
|
||||
public int getInterpolationDelay(InputSource source, double rotation) {
|
||||
switch (source) {
|
||||
case SCROLLBAR:
|
||||
return SCROLLBAR_DELAY.asInteger();
|
||||
case MOUSE_WHEEL:
|
||||
int min = MOUSE_WHEEL_MIN_DELAY.asInteger();
|
||||
int max = MOUSE_WHEEL_MAX_DELAY.asInteger();
|
||||
return Math.max(min, Math.min(max, (int)Math.round(max * Math.abs(rotation))));
|
||||
case PRECISION_TOUCHPAD:
|
||||
return PRECISION_TOUCHPAD_DELAY.asInteger();
|
||||
default:
|
||||
return OTHER_SOURCES_DELAY.asInteger();
|
||||
}
|
||||
}
|
||||
|
||||
// Returns whether dymaics scrollbars are enabled (currently applies only to editor's horizontal scrollbar)
|
||||
public boolean areDynamicScrollbarsEnabled() {
|
||||
return DYNAMIC_SCROLLBARS.asBoolean();
|
||||
|
||||
@@ -162,6 +162,7 @@ public class JBScrollBar extends JScrollBar implements TopComponent, Interpolabl
|
||||
|
||||
@Override
|
||||
public void setValue(int value) {
|
||||
int delay = 0;
|
||||
Component parent = getParent();
|
||||
if (parent instanceof JBScrollPane) {
|
||||
JBScrollPane pane = (JBScrollPane)parent;
|
||||
@@ -169,15 +170,16 @@ public class JBScrollBar extends JScrollBar implements TopComponent, Interpolabl
|
||||
if (viewport != null) {
|
||||
ComponentSettings settings = ComponentSettings.getInstance();
|
||||
if (settings.isTrueSmoothScrollingEligibleFor(viewport.getView()) && settings.isInterpolationEligibleFor(this)) {
|
||||
InputSource source = pane.getInputSource(getValueIsAdjusting());
|
||||
if (settings.isInterpolationEnabledFor(source)) {
|
||||
myInterpolator.setTarget(value, pane.getInitialDelay(source));
|
||||
return;
|
||||
}
|
||||
delay = pane.getInitialDelay(getValueIsAdjusting());
|
||||
}
|
||||
}
|
||||
}
|
||||
super.setValue(value);
|
||||
if (delay > 0) {
|
||||
myInterpolator.setTarget(value, delay);
|
||||
}
|
||||
else {
|
||||
super.setValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -279,7 +281,7 @@ public class JBScrollBar extends JScrollBar implements TopComponent, Interpolabl
|
||||
// so we use 10 to restore amount of pixels to scroll.
|
||||
return 10 * rotation;
|
||||
}
|
||||
else if (SystemInfo.isWindows && Registry.is("ide.scroll.precise.rotation.windows")) {
|
||||
if (SystemInfo.isWindows && Registry.is("ide.scroll.precise.rotation.windows")) {
|
||||
JViewport viewport = getViewport();
|
||||
Font font = viewport == null ? null : getViewFont(viewport);
|
||||
int size = font == null ? JBUI.scale(10) : font.getSize(); // assume an unit size
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
package com.intellij.ui.components;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.util.registry.RegistryValue;
|
||||
import com.intellij.ui.ComponentSettings;
|
||||
import com.intellij.ui.InputSource;
|
||||
import com.intellij.util.SystemProperties;
|
||||
@@ -40,12 +38,6 @@ public class SmoothScrollPane extends JScrollPane {
|
||||
private static final Logger LOG = Logger.getInstance(SmoothScrollPane.class);
|
||||
private static final double EPSILON = 1E-5D;
|
||||
|
||||
private static final RegistryValue SCROLLBAR_DELAY = Registry.get("idea.true.smooth.scrolling.interpolation.scrollbar.delay");
|
||||
private static final RegistryValue PRECISION_TOUCHPAD_DELAY = Registry.get("idea.true.smooth.scrolling.interpolation.precision.touchpad.delay");
|
||||
private static final RegistryValue MOUSE_WHEEL_MIN_DELAY = Registry.get("idea.true.smooth.scrolling.interpolation.mouse.wheel.delay.min");
|
||||
private static final RegistryValue MOUSE_WHEEL_MAX_DELAY = Registry.get("idea.true.smooth.scrolling.interpolation.mouse.wheel.delay.max");
|
||||
private static final RegistryValue DEFAULT_DELAY = Registry.get("idea.true.smooth.scrolling.interpolation.other.delay");
|
||||
|
||||
private InputSource myInputSource = InputSource.UNKNOWN;
|
||||
private double myWheelRotation;
|
||||
|
||||
@@ -195,23 +187,10 @@ public class SmoothScrollPane extends JScrollPane {
|
||||
return viewport != null && (viewport.getView() instanceof Scrollable) ? (Scrollable)(viewport.getView()) : null;
|
||||
}
|
||||
|
||||
public InputSource getInputSource(boolean valueIsAdjusting) {
|
||||
return valueIsAdjusting ? InputSource.SCROLLBAR : myInputSource;
|
||||
}
|
||||
|
||||
public int getInitialDelay(InputSource source) {
|
||||
switch (source) {
|
||||
case SCROLLBAR:
|
||||
return SCROLLBAR_DELAY.asInteger();
|
||||
case PRECISION_TOUCHPAD:
|
||||
return PRECISION_TOUCHPAD_DELAY.asInteger();
|
||||
case MOUSE_WHEEL:
|
||||
return max(MOUSE_WHEEL_MIN_DELAY.asInteger(),
|
||||
min((int)round(abs(myWheelRotation) * MOUSE_WHEEL_MAX_DELAY.asInteger()),
|
||||
MOUSE_WHEEL_MAX_DELAY.asInteger()));
|
||||
default:
|
||||
return DEFAULT_DELAY.asInteger();
|
||||
}
|
||||
int getInitialDelay(boolean valueIsAdjusting) {
|
||||
InputSource source = valueIsAdjusting ? InputSource.SCROLLBAR : myInputSource;
|
||||
ComponentSettings settings = ComponentSettings.getInstance();
|
||||
return !settings.isInterpolationEnabledFor(source) ? 0 : settings.getInterpolationDelay(source, myWheelRotation);
|
||||
}
|
||||
|
||||
protected class SmoothScrollBar extends ScrollBar implements Interpolable, FinelyAdjustable {
|
||||
@@ -227,15 +206,14 @@ public class SmoothScrollPane extends JScrollPane {
|
||||
|
||||
@Override
|
||||
public void setValue(int value) {
|
||||
int delay = 0;
|
||||
ComponentSettings settings = ComponentSettings.getInstance();
|
||||
|
||||
InputSource source = getInputSource(getValueIsAdjusting());
|
||||
|
||||
if (settings.isTrueSmoothScrollingEligibleFor(getViewport().getView()) &&
|
||||
settings.isInterpolationEligibleFor(this) &&
|
||||
settings.isInterpolationEnabledFor(source)) {
|
||||
|
||||
myInterpolator.setTarget(value, getInitialDelay(source));
|
||||
if (settings.isTrueSmoothScrollingEligibleFor(getViewport().getView()) && settings.isInterpolationEligibleFor(this)) {
|
||||
delay = getInitialDelay(getValueIsAdjusting());
|
||||
}
|
||||
if (delay > 0) {
|
||||
myInterpolator.setTarget(value, delay);
|
||||
}
|
||||
else {
|
||||
super.setValue(value);
|
||||
|
||||
Reference in New Issue
Block a user