@Override
public boolean mouseMove(Component component, int x, int y) {
boolean consumed = super.mouseMove(component, x, y);
if (Mouse.getCapturer() == component) {
Slider slider = (Slider)TerraSliderSkin.this.getComponent();
if (slider.getOrientation() == Orientation.HORIZONTAL) {
int sliderWidth = slider.getWidth();
int thumbWidthLocal = thumb.getWidth();
Point sliderLocation = thumb.mapPointToAncestor(slider, x, y);
int sliderX = sliderLocation.x;
int minX = dragOffset.x;
if (sliderX < minX) {
sliderX = minX;
}
int maxX = (sliderWidth - thumbWidthLocal) + dragOffset.x;
if (sliderX > maxX) {
sliderX = maxX;
}
float ratio = (float)(sliderX - dragOffset.x) / (sliderWidth - thumbWidthLocal);
int start = slider.getStart();
int end = slider.getEnd();
int value = (int)(start + (end - start) * ratio);
slider.setValue(value);
} else {
int sliderHeight = slider.getHeight();
int thumbHeightLocal = thumb.getHeight();
Point sliderLocation = thumb.mapPointToAncestor(slider, x, y);
int sliderY = sliderLocation.y;
int minY = dragOffset.y;
if (sliderY < minY) {
sliderY = minY;
}
int maxY = (sliderHeight - thumbHeightLocal) + dragOffset.y;
if (sliderY > maxY) {
sliderY = maxY;
}
float ratio = (float)(sliderY - dragOffset.y) / (sliderHeight - thumbHeightLocal);
int start = slider.getStart();
int end = slider.getEnd();
int value = (int)(start + (end - start) * ratio);
slider.setValue(value);
}
}
return consumed;
}