Can now click on and highlight fractional lines

This commit is contained in:
bigguy345 committed 2025-12-19 02:09:18 +02:00
1 parent 9ef4b6ecdf
commit e79bf294f1
2 files changed
+14 -7

No files matched your search

@@ -355,17 +355,20 @@ public class GuiScriptTextArea extends GuiNpcTextField {
private int getSelectionPos(int xMouse, int yMouse) {
xMouse -= (this.x + LINE_NUMBER_GUTTER_WIDTH + 1);
yMouse -= this.y + 1;
// Adjust yMouse to account for fractional GL translation (negative offset applied in rendering)
// Adjust yMouse to account for fractional GL translation (negative offset applied in rendering).
// Use a double here (no integer rounding) so clicks that land on partially
// visible lines (fractional positions) correctly hit that line.
double fracPixels = scroll.getFractionalOffset() * container.lineHeight;
yMouse = (int) Math.round(yMouse + fracPixels);
double yMouseD = yMouse + fracPixels;
ArrayList list = new ArrayList(this.container.lines);
for (int i = 0; i < list.size(); ++i) {
LineData data = (LineData) list.get(i);
if (i >= scroll.getScrolledLine() && i <= scroll.getScrolledLine() + this.container.visibleLines) {
int yPos = (i - scroll.getScrolledLine()) * this.container.lineHeight;
if (yMouse >= yPos && yMouse < yPos + this.container.lineHeight) {
//+1 to account for the fractional line
if (i >= scroll.getScrolledLine() && i <= scroll.getScrolledLine() + this.container.visibleLines +1) {
double yPos = (i - scroll.getScrolledLine()) * this.container.lineHeight;
if (yMouseD >= yPos && yMouseD < yPos + this.container.lineHeight) {
int lineWidth = 0;
char[] chars = data.text.toCharArray();
@@ -15,7 +15,7 @@ public class ScrollState {
private double scrollVelocity = 0.0;
// Last timestamp for delta time calculation
private long lastScrollTime = 0L;
// Integer line index for compatibility with rendering
// First visible line
private int scrolledLine = 0;
// Scrollbar drag offset when dragging thumb
private int scrollbarDragOffset = 0;
@@ -136,7 +136,11 @@ public class ScrollState {
// Getters
public double getScrollPos() { return scrollPos; }
public double getTargetScroll() { return targetScroll; }
public int getScrolledLine() { return scrolledLine; }
/** @return First visible line **/
public int getScrolledLine() {
return scrolledLine;
}
public double getScrollVelocity() { return scrollVelocity; }
public boolean isClickScrolling() { return clickScrolling; }
public int getScrollbarDragOffset() { return scrollbarDragOffset; }