Skip to content

Commit

Permalink
Make horizontal scrolling using the scrollwheel work again (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
wlhlm authored Jun 23, 2023
1 parent 7d99f5e commit b81e7cd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public void drawTooltip(GuiRecipe<?> gui, int recipe) {
}

protected Optional<Interactable> findHoveredInteractable(int recipe) {
if (!mouseInBounds()) {
if (!mouseInDiagramBounds()) {
return Optional.empty();
}

Expand All @@ -212,8 +212,8 @@ protected Optional<Interactable> findHoveredInteractable(int recipe) {
return Optional.empty();
}

public boolean mouseInBounds() {
return scrollManager.mouseInBounds();
public boolean mouseInDiagramBounds() {
return scrollManager.mouseInDiagramBounds();
}

public boolean interact(int recipe, Interactable.RecipeType recipeType) {
Expand Down Expand Up @@ -283,17 +283,16 @@ public boolean mouseClicked(GuiRecipe<?> gui, int button, int recipe) {
public boolean mouseScrolled(GuiRecipe<?> gui, int scroll, int recipe) {
ScrollDirection direction = scroll > 0 ? ScrollDirection.UP : ScrollDirection.DOWN;

if (mouseInBounds()) {
if (NEIClientUtils.shiftKey()) {
diagramState.scroll(direction);
return true;
}
if (!ConfigOptions.DISABLE_PAGE_SCROLL.get()) {
return scrollManager.mouseScroll(direction);
}
if (mouseInDiagramBounds() && NEIClientUtils.shiftKey()) {
diagramState.scroll(direction);
return true;
}

return false;
if (scrollManager.mouseScroll(direction)) {
return true;
} else {
return mouseInDiagramBounds() && ConfigOptions.DISABLE_PAGE_SCROLL.get();
}
}

public Optional<ItemStack> getStackUnderMouse(int recipe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public boolean keyboardScroll(Dimension diagramDimension, ScrollDirection direct

public boolean mouseScroll(ScrollDirection direction) {
// Horizontal scrolling is more rarely done, so we will scroll horizontally only if the
// mouse is directly over the horizontal scrollbar. Otherwise, we will default to vertical.
// mouse is directly over the horizontal scrollbar. Vertical scrolling is done either when
// the cursor is over the scrollbar or over the diagram itself.
if (horizontalScrollbar.mouseInScrollBounds()) {
ScrollDirection horizontalDirection;
switch (direction) {
Expand All @@ -61,8 +62,10 @@ public boolean mouseScroll(ScrollDirection direction) {
break;
}
return horizontalScrollbar.scroll(horizontalDirection, ConfigOptions.MOUSE_SCROLL_SPEED.get());
} else {
} else if (verticalScrollbar.mouseInScrollBounds() || mouseInDiagramBounds()) {
return verticalScrollbar.scroll(direction, ConfigOptions.MOUSE_SCROLL_SPEED.get());
} else {
return false;
}
}

Expand All @@ -75,7 +78,7 @@ public boolean mouseClickScrollbar(MouseButton button) {
return handled;
}

public boolean mouseInBounds() {
public boolean mouseInDiagramBounds() {
Point mousePos = getAbsoluteMousePosition();
Point viewportPos = getViewportPosition();
int xDiff = mousePos.x() - viewportPos.x();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public boolean objectUnderMouse(GuiContainer guiContainer, int mousex, int mouse

@Override
public boolean shouldShowTooltip(GuiContainer guiContainer) {
return getDiagramGroup(guiContainer).map(diagramGroup -> !diagramGroup.mouseInBounds()).orElse(true);
return getDiagramGroup(guiContainer).map(diagramGroup -> !diagramGroup.mouseInDiagramBounds()).orElse(true);
}
}

Expand Down

0 comments on commit b81e7cd

Please sign in to comment.