Skip to content

Commit 3f400f7

Browse files
committed
Offsets now being computed from the generic layout.
1 parent 99faaa2 commit 3f400f7

6 files changed

Lines changed: 12 additions & 49 deletions

File tree

src/gui/dlefglayout.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ LayoutNodesPanel::LayoutNodesPanel(wxWindow *p_parent, const TreeRenderConfig &p
115115
constexpr int Y_SPACING_MAX = 60;
116116

117117
m_terminalSpacing = new wxSpinCtrl(
118-
this, wxID_ANY, wxString::Format(_T("%d"), p_settings.TerminalSpacing()), wxDefaultPosition,
119-
wxDefaultSize, wxSP_ARROW_KEYS, Y_SPACING_MIN, Y_SPACING_MAX);
118+
this, wxID_ANY, wxString::Format(_T("%d"), p_settings.GetTerminalSpacing()),
119+
wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, Y_SPACING_MIN, Y_SPACING_MAX);
120120
gridSizer->Add(m_terminalSpacing, 1, wxEXPAND | wxALL, 5);
121121

122122
sizeSizer->Add(gridSizer, 1, wxALL | wxEXPAND, 5);

src/gui/efglayout.cc

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -560,41 +560,6 @@ GameNode TreeLayout::NextSameLevel(const GameNode &p_node) const
560560
return nullptr;
561561
}
562562

563-
void TreeLayout::ComputeOffsets(const GameNode &p_node, const BehaviorSupportProfile &p_support,
564-
int &p_ycoord)
565-
{
566-
const auto &settings = m_doc->GetStyle();
567-
568-
const auto entry = GetNodeEntry(p_node);
569-
if (m_doc->GetStyle().RootReachable() && p_node->GetInfoset() &&
570-
!p_node->GetInfoset()->GetPlayer()->IsChance()) {
571-
const auto actions = p_support.GetActions(p_node->GetInfoset());
572-
for (const auto &action : actions) {
573-
ComputeOffsets(p_node->GetChild(action), p_support, p_ycoord);
574-
}
575-
entry->m_y = (GetNodeEntry(p_node->GetChild(actions.front()))->m_y +
576-
GetNodeEntry(p_node->GetChild(actions.back()))->m_y) /
577-
2;
578-
}
579-
else if (!p_node->IsTerminal()) {
580-
const auto actions = p_node->GetInfoset()->GetActions();
581-
for (const auto &action : actions) {
582-
const auto child = p_node->GetChild(action);
583-
ComputeOffsets(child, p_support, p_ycoord);
584-
if (!p_node->GetPlayer()->IsChance() && !p_support.Contains(action)) {
585-
GetNodeEntry(child)->m_inSupport = false;
586-
}
587-
}
588-
entry->m_y = (GetNodeEntry(p_node->GetChild(actions.front()))->m_y +
589-
GetNodeEntry(p_node->GetChild(actions.back()))->m_y) /
590-
2;
591-
}
592-
else {
593-
entry->m_y = p_ycoord;
594-
p_ycoord += settings.TerminalSpacing();
595-
}
596-
}
597-
598563
std::shared_ptr<NodeEntry>
599564
TreeLayout::ComputeNextInInfoset(const std::shared_ptr<NodeEntry> &p_entry) const
600565
{
@@ -691,17 +656,17 @@ void TreeLayout::Layout(const BehaviorSupportProfile &p_support)
691656
BuildNodeList(p_support);
692657
}
693658

694-
int maxy = c_topMargin;
695-
ComputeOffsets(m_doc->GetGame()->GetRoot(), p_support, maxy);
696-
m_maxY = maxy + c_bottomMargin;
697-
698659
auto layout = Gambit::Layout(m_doc->GetGame());
699660
layout.LayoutTree(p_support);
700661

662+
const auto spacing = m_doc->GetStyle().GetTerminalSpacing();
701663
for (auto [node, entry] : layout.GetNodeMap()) {
702664
m_nodeMap[node]->m_level = entry->m_level;
703665
m_nodeMap[node]->m_sublevel = entry->m_sublevel;
666+
m_nodeMap[node]->m_y = entry->m_offset * spacing + c_topMargin;
704667
}
668+
m_maxY =
669+
c_topMargin + c_bottomMargin + spacing * (layout.GetMaxOffset() - layout.GetMinOffset());
705670
ComputeNodeDepths(layout);
706671

707672
ComputeRenderedParents();

src/gui/efglayout.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@ class TreeLayout final : public GameView {
116116

117117
void BuildNodeList(const GameNode &, const BehaviorSupportProfile &);
118118

119-
/// (Recursively) compute the y-offsets of all nodes
120-
void ComputeOffsets(const GameNode &, const BehaviorSupportProfile &, int &);
121119
/// Based on node levels and information set sublevels, compute the depth
122120
/// (X coordinate) of all nodes
123121
void ComputeNodeDepths(const Gambit::Layout &) const;

src/gui/layout.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ void Layout::LayoutTree(const BehaviorSupportProfile &p_support)
7575
m_numSublevels.clear();
7676
m_infosetSublevels.clear();
7777

78-
double ycoord = 0;
79-
LayoutSubtree(m_game->GetRoot(), p_support, 0, ycoord);
78+
m_maxOffset = 0;
79+
LayoutSubtree(m_game->GetRoot(), p_support, 0, m_maxOffset);
8080
}
8181

8282
} // namespace Gambit

src/gui/layout.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Layout {
4343
std::vector<int> m_numSublevels;
4444
std::map<std::pair<int, GameInfoset>, int> m_infosetSublevels;
4545

46-
float m_maxOffset{0};
46+
double m_maxOffset{0};
4747

4848
void LayoutSubtree(const GameNode &, const BehaviorSupportProfile &, int, double &);
4949

@@ -55,8 +55,8 @@ class Layout {
5555

5656
const std::map<GameNode, std::shared_ptr<LayoutEntry>> &GetNodeMap() const { return m_nodeMap; }
5757
const std::vector<int> &GetNumSublevels() const { return m_numSublevels; }
58-
float GetMinOffset() const { return 0; }
59-
float GetMaxOffset() const { return m_maxOffset; }
58+
double GetMinOffset() const { return 0; }
59+
double GetMaxOffset() const { return m_maxOffset; }
6060
};
6161
} // namespace Gambit
6262
#endif // GAMBIT_LAYOUT_H

src/gui/style.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class TreeRenderConfig {
109109
int GetNodeSize() const { return m_nodeSize; }
110110
void SetNodeSize(int p_nodeSize) { m_nodeSize = p_nodeSize; }
111111

112-
int TerminalSpacing() const { return m_terminalSpacing; }
112+
int GetTerminalSpacing() const { return m_terminalSpacing; }
113113
void SetTerminalSpacing(int p_spacing) { m_terminalSpacing = p_spacing; }
114114

115115
NodeTokenStyle GetChanceToken() const { return m_chanceToken; }

0 commit comments

Comments
 (0)