From 1944203a4162cef88f1790c4e6a41a86c36de911 Mon Sep 17 00:00:00 2001 From: Hiraoka Date: Fri, 5 Feb 2021 23:20:02 +0900 Subject: [PATCH] Fix #862 (insufficient x-shift in variation tree) --- .../featurecat/lizzie/gui/VariationTree.java | 49 ++++++------------- 1 file changed, 14 insertions(+), 35 deletions(-) diff --git a/src/main/java/featurecat/lizzie/gui/VariationTree.java b/src/main/java/featurecat/lizzie/gui/VariationTree.java index 3a6789017..ad4721463 100644 --- a/src/main/java/featurecat/lizzie/gui/VariationTree.java +++ b/src/main/java/featurecat/lizzie/gui/VariationTree.java @@ -26,6 +26,7 @@ public class VariationTree { private BoardHistoryNode curMove; private Rectangle area; private Point clickPoint; + private int curMoveLane = 0; public VariationTree() { laneUsageList = new ArrayList(); @@ -69,6 +70,8 @@ public Optional drawTree( // At this point, lane contains the lane we should use (the main branch is in lane 0) + if (startNode == curMove) curMoveLane = lane; + BoardHistoryNode cur = startNode; int curposx = posx + lane * XSPACING; int dotoffset = DOT_DIAM / 2; @@ -156,6 +159,7 @@ public Optional drawTree( if (cur.isEndDummay()) { continue; } + if (cur == curMove) curMoveLane = lane; if (calc) { if (inNode(curposx + dotoffset, posy + dotoffset)) { return Optional.of(cur); @@ -233,6 +237,16 @@ public Optional draw( if (width <= 0 || height <= 0) { return Optional.empty(); // we don't have enough space } + area.setBounds(posx, posy, width, height); + + // Get the lane of the current node by a dummy drawing. + if (!calc) { + int DUMMY = Integer.MIN_VALUE / 2; + clickPoint.setLocation(DUMMY, DUMMY); + curMoveLane = 0; + draw(g, posx, posy, width, height, true); // set curMoveLane as a side effect + } + int lane = curMoveLane; // Use dense tree for saving space if large-subboard YSPACING = (Lizzie.config.showLargeSubBoard() ? 20 : 30); @@ -241,7 +255,6 @@ public Optional draw( int strokeRadius = Lizzie.config.showBorder ? 2 : 0; if (!calc) { // Draw background - area.setBounds(posx, posy, width, height); g.setColor(new Color(0, 0, 0, 60)); g.fillRect(posx, posy, width, height); @@ -272,7 +285,6 @@ public Optional draw( node = node.previous().get(); curposy -= YSPACING; } - int lane = getCurLane(node, curMove, curposy, posy + height, 0, true); int startx = posx + xoffset; if (((lane + 1) * XSPACING + xoffset + DOT_DIAM + strokeRadius - width) > 0) { startx = startx - ((lane + 1) * XSPACING + xoffset + DOT_DIAM + strokeRadius - width); @@ -306,37 +318,4 @@ public void onClicked(int x, int y) { node.ifPresent(n -> Lizzie.board.moveToAnyPosition(n)); } } - - private int getCurLane( - BoardHistoryNode start, - BoardHistoryNode curMove, - int curposy, - int maxy, - int laneCount, - boolean isMain) { - BoardHistoryNode next = start; - int nexty = curposy; - while (next.next().isPresent() && nexty + YSPACING < maxy) { - nexty += YSPACING; - next = next.next().get(); - } - while (next.previous().isPresent() && (isMain || next != start)) { - next = next.previous().get(); - for (int i = 1; i < next.numberOfChildren(); i++) { - laneCount++; - if (next.findIndexOfNode(curMove, true) == i) { - return laneCount; - } - Optional variation = next.getVariation(i); - if (variation.isPresent()) { - int subLane = getCurLane(variation.get(), curMove, nexty, maxy, laneCount, false); - if (subLane > 0) { - return subLane; - } - } - } - nexty -= YSPACING; - } - return 0; - } }