Skip to content

Commit c0b158c

Browse files
committed
Refactoring and modernisation of tree layout
This implements a variety of modernisation, simplification, and refactoring on the algorithm that lays out extensive games for display. In particular, it clarifies the approach to layout and mostly separates "logical" layout from the details of how to map this onto specific coordinates for wxWidgets rendering.
1 parent e59b0b6 commit c0b158c

16 files changed

Lines changed: 616 additions & 681 deletions

src/gui/dlefglayout.cc

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,18 @@ class gbtLayoutNodesPanel : public wxPanel {
4242
int NodeSize() const { return m_nodeSize->GetValue(); }
4343
int TerminalSpacing() const { return m_terminalSpacing->GetValue(); }
4444

45-
int ChanceToken() const { return m_chanceToken->GetSelection(); }
46-
int PlayerToken() const { return m_playerToken->GetSelection(); }
47-
int TerminalToken() const { return m_terminalToken->GetSelection(); }
45+
NodeTokenStyle GetChanceToken() const
46+
{
47+
return static_cast<NodeTokenStyle>(m_chanceToken->GetSelection());
48+
}
49+
NodeTokenStyle GetPlayerToken() const
50+
{
51+
return static_cast<NodeTokenStyle>(m_playerToken->GetSelection());
52+
}
53+
NodeTokenStyle GetTerminalToken() const
54+
{
55+
return static_cast<NodeTokenStyle>(m_terminalToken->GetSelection());
56+
}
4857
};
4958

5059
gbtLayoutNodesPanel::gbtLayoutNodesPanel(wxWindow *p_parent, const gbtStyle &p_settings)
@@ -62,20 +71,20 @@ gbtLayoutNodesPanel::gbtLayoutNodesPanel(wxWindow *p_parent, const gbtStyle &p_s
6271
tokenSizer->Add(new wxStaticText(this, wxID_STATIC, _("Indicate chance nodes with")), 0,
6372
wxALL | wxALIGN_CENTER_VERTICAL, 5);
6473
m_chanceToken = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 5, tokenChoices);
65-
m_chanceToken->SetSelection(p_settings.ChanceToken());
74+
m_chanceToken->SetSelection(p_settings.GetChanceToken());
6675
tokenSizer->Add(m_chanceToken, 1, wxALL | wxEXPAND, 5);
6776

6877
tokenSizer->Add(new wxStaticText(this, wxID_STATIC, _("Indicate player nodes with")), 0,
6978
wxALL | wxALIGN_CENTER_VERTICAL, 5);
7079
m_playerToken = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 5, tokenChoices);
71-
m_playerToken->SetSelection(p_settings.PlayerToken());
80+
m_playerToken->SetSelection(p_settings.GetPlayerToken());
7281
tokenSizer->Add(m_playerToken, 1, wxALL | wxEXPAND, 5);
7382

7483
tokenSizer->Add(new wxStaticText(this, wxID_STATIC, _("Indicate terminal nodes with")), 0,
7584
wxALL | wxALIGN_CENTER_VERTICAL, 5);
7685
m_terminalToken =
7786
new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 5, tokenChoices);
78-
m_terminalToken->SetSelection(p_settings.TerminalToken());
87+
m_terminalToken->SetSelection(p_settings.GetTerminalToken());
7988
tokenSizer->Add(m_terminalToken, 1, wxALL | wxEXPAND, 5);
8089

8190
nodeSizer->Add(tokenSizer, 1, wxALL | wxEXPAND, 5);
@@ -92,7 +101,7 @@ gbtLayoutNodesPanel::gbtLayoutNodesPanel(wxWindow *p_parent, const gbtStyle &p_s
92101
const int NODE_LENGTH_MIN = 5;
93102
const int NODE_LENGTH_MAX = 100;
94103

95-
m_nodeSize = new wxSpinCtrl(this, wxID_ANY, wxString::Format(_T("%d"), p_settings.NodeSize()),
104+
m_nodeSize = new wxSpinCtrl(this, wxID_ANY, wxString::Format(_T("%d"), p_settings.GetNodeSize()),
96105
wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, NODE_LENGTH_MIN,
97106
NODE_LENGTH_MAX);
98107
gridSizer->Add(m_nodeSize, 1, wxEXPAND | wxALL, 5);
@@ -125,11 +134,17 @@ class gbtLayoutBranchesPanel : public wxPanel {
125134
public:
126135
gbtLayoutBranchesPanel(wxWindow *p_parent, const gbtStyle &);
127136

128-
int BranchLength() const { return m_branchLength->GetValue(); }
129-
int TineLength() const { return m_tineLength->GetValue(); }
137+
int GetBranchLength() const { return m_branchLength->GetValue(); }
138+
int GetTineLength() const { return m_tineLength->GetValue(); }
130139

131-
int BranchStyle() const { return m_branchStyle->GetSelection(); }
132-
int BranchLabels() const { return m_branchLabels->GetSelection(); }
140+
BranchLineStyle GetBranchStyle() const
141+
{
142+
return static_cast<BranchLineStyle>(m_branchStyle->GetSelection());
143+
}
144+
BranchLabelOrientationStyle GetBranchLabels() const
145+
{
146+
return static_cast<BranchLabelOrientationStyle>(m_branchLabels->GetSelection());
147+
}
133148
};
134149

135150
gbtLayoutBranchesPanel::gbtLayoutBranchesPanel(wxWindow *p_parent, const gbtStyle &p_settings)
@@ -152,14 +167,14 @@ gbtLayoutBranchesPanel::gbtLayoutBranchesPanel(wxWindow *p_parent, const gbtStyl
152167
wxString styleChoices[] = {_("using straight lines between nodes"),
153168
_("with a tine for branch labels")};
154169
m_branchStyle = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 2, styleChoices);
155-
m_branchStyle->SetSelection(p_settings.BranchStyle());
170+
m_branchStyle->SetSelection(p_settings.GetBranchStyle());
156171
styleSizer->Add(m_branchStyle, 1, wxALL | wxEXPAND, 5);
157172

158173
styleSizer->Add(new wxStaticText(this, wxID_STATIC, _("Draw labels")), 1,
159174
wxALL | wxALIGN_CENTER_VERTICAL, 5);
160175
wxString labelChoices[] = {_("horizontally"), _("rotated parallel to the branch")};
161176
m_branchLabels = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 2, labelChoices);
162-
m_branchLabels->SetSelection(p_settings.BranchLabels());
177+
m_branchLabels->SetSelection(p_settings.GetBranchLabels());
163178
styleSizer->Add(m_branchLabels, 1, wxALL | wxEXPAND, 5);
164179

165180
styleBoxSizer->Add(styleSizer, 1, wxALL | wxEXPAND, 5);
@@ -173,14 +188,14 @@ gbtLayoutBranchesPanel::gbtLayoutBranchesPanel(wxWindow *p_parent, const gbtStyl
173188
gridSizer->Add(new wxStaticText(this, wxID_ANY, _("size of branch fork")), 0,
174189
wxALIGN_CENTER_VERTICAL | wxALL, 5);
175190
m_branchLength = new wxSpinCtrl(
176-
this, wxID_ANY, wxString::Format(_T("%d"), p_settings.BranchLength()), wxDefaultPosition,
191+
this, wxID_ANY, wxString::Format(_T("%d"), p_settings.GetBranchLength()), wxDefaultPosition,
177192
wxDefaultSize, wxSP_ARROW_KEYS, BRANCH_LENGTH_MIN, BRANCH_LENGTH_MAX);
178193
gridSizer->Add(m_branchLength, 1, wxALL | wxEXPAND, 5);
179194

180195
gridSizer->Add(new wxStaticText(this, wxID_ANY, _("size of branch tine")), 1,
181196
wxALIGN_CENTER_VERTICAL | wxALL, 5);
182197
m_tineLength = new wxSpinCtrl(
183-
this, wxID_ANY, wxString::Format(_T("%d"), p_settings.TineLength()), wxDefaultPosition,
198+
this, wxID_ANY, wxString::Format(_T("%d"), p_settings.GetTineLength()), wxDefaultPosition,
184199
wxDefaultSize, wxSP_ARROW_KEYS, TINE_LENGTH_MIN, TINE_LENGTH_MAX);
185200
gridSizer->Add(m_tineLength, 1, wxALL | wxEXPAND, 5);
186201

@@ -200,8 +215,14 @@ class gbtLayoutInfosetsPanel : public wxPanel {
200215
public:
201216
gbtLayoutInfosetsPanel(wxWindow *p_parent, const gbtStyle &);
202217

203-
int InfosetConnect() const { return m_infosetConnect->GetSelection(); }
204-
int InfosetJoin() const { return m_infosetJoin->GetSelection(); }
218+
InfosetConnectStyle GetInfosetConnect() const
219+
{
220+
return static_cast<InfosetConnectStyle>(m_infosetConnect->GetSelection());
221+
}
222+
InfosetJoinStyle GetInfosetJoin() const
223+
{
224+
return static_cast<InfosetJoinStyle>(m_infosetJoin->GetSelection());
225+
}
205226
};
206227

207228
gbtLayoutInfosetsPanel::gbtLayoutInfosetsPanel(wxWindow *p_parent, const gbtStyle &p_settings)
@@ -219,14 +240,14 @@ gbtLayoutInfosetsPanel::gbtLayoutInfosetsPanel(wxWindow *p_parent, const gbtStyl
219240
_("only when on the same level"), _("regardless of level")};
220241
m_infosetConnect =
221242
new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 3, connectChoices);
222-
m_infosetConnect->SetSelection(p_settings.InfosetConnect());
243+
m_infosetConnect->SetSelection(p_settings.GetInfosetConnect());
223244
styleSizer->Add(m_infosetConnect, 0, wxALL, 5);
224245

225246
styleSizer->Add(new wxStaticText(this, wxID_STATIC, _("Draw information set connections")), 0,
226247
wxALL | wxALIGN_CENTER_VERTICAL, 5);
227248
wxString joinChoices[] = {_("using lines"), _("using bubbles")};
228249
m_infosetJoin = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 2, joinChoices);
229-
m_infosetJoin->SetSelection(p_settings.InfosetJoin());
250+
m_infosetJoin->SetSelection(p_settings.GetInfosetJoin());
230251
styleSizer->Add(m_infosetJoin, 0, wxALL | wxEXPAND, 5);
231252
infosetSizer->Add(styleSizer, 0, wxALL | wxALIGN_CENTER, 5);
232253
topSizer->Add(infosetSizer, 0, wxALL, 5);
@@ -277,19 +298,19 @@ void gbtLayoutDialog::GetSettings(gbtStyle &p_settings)
277298
auto *nodes = dynamic_cast<gbtLayoutNodesPanel *>(m_notebook->GetPage(0));
278299
p_settings.SetNodeSize(nodes->NodeSize());
279300
p_settings.SetTerminalSpacing(nodes->TerminalSpacing());
280-
p_settings.SetChanceToken(nodes->ChanceToken());
281-
p_settings.SetPlayerToken(nodes->PlayerToken());
282-
p_settings.SetTerminalToken(nodes->TerminalToken());
301+
p_settings.SetChanceToken(nodes->GetChanceToken());
302+
p_settings.SetPlayerToken(nodes->GetPlayerToken());
303+
p_settings.SetTerminalToken(nodes->GetTerminalToken());
283304

284305
auto *branches = dynamic_cast<gbtLayoutBranchesPanel *>(m_notebook->GetPage(1));
285-
p_settings.SetBranchLength(branches->BranchLength());
286-
p_settings.SetTineLength(branches->TineLength());
287-
p_settings.SetBranchStyle(branches->BranchStyle());
288-
p_settings.SetBranchLabels(branches->BranchLabels());
306+
p_settings.SetBranchLength(branches->GetBranchLength());
307+
p_settings.SetTineLength(branches->GetTineLength());
308+
p_settings.SetBranchStyle(branches->GetBranchStyle());
309+
p_settings.SetBranchLabels(branches->GetBranchLabels());
289310

290311
auto *infosets = dynamic_cast<gbtLayoutInfosetsPanel *>(m_notebook->GetPage(2));
291-
p_settings.SetInfosetConnect(infosets->InfosetConnect());
292-
p_settings.SetInfosetJoin(infosets->InfosetJoin());
312+
p_settings.SetInfosetConnect(infosets->GetInfosetConnect());
313+
p_settings.SetInfosetJoin(infosets->GetInfosetJoin());
293314
}
294315

295316
void gbtLayoutDialog::OnSetDefaults(wxCommandEvent &)

src/gui/dlefglegend.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ gbtLegendDialog::gbtLegendDialog(wxWindow *p_parent, const gbtStyle &p_options)
5050
nodeAboveSizer->Add(new wxStaticText(this, wxID_STATIC, _("Display")), 0, wxALL | wxALIGN_CENTER,
5151
5);
5252
m_nodeAbove = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 8, nodeLabelList);
53-
m_nodeAbove->SetSelection(p_options.NodeAboveLabel());
53+
m_nodeAbove->SetSelection(p_options.GetNodeAboveLabel());
5454
nodeAboveSizer->Add(m_nodeAbove, 1, wxALL | wxALIGN_CENTER, 5);
5555
nodeAboveSizer->Add(new wxStaticText(this, wxID_STATIC, _("above each node")), 0,
5656
wxALL | wxALIGN_CENTER, 5);
@@ -60,7 +60,7 @@ gbtLegendDialog::gbtLegendDialog(wxWindow *p_parent, const gbtStyle &p_options)
6060
nodeBelowSizer->Add(new wxStaticText(this, wxID_STATIC, _("Display")), 0, wxALL | wxALIGN_CENTER,
6161
5);
6262
m_nodeBelow = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 8, nodeLabelList);
63-
m_nodeBelow->SetSelection(p_options.NodeBelowLabel());
63+
m_nodeBelow->SetSelection(p_options.GetNodeBelowLabel());
6464
nodeBelowSizer->Add(m_nodeBelow, 1, wxALL | wxALIGN_CENTER, 5);
6565
nodeBelowSizer->Add(new wxStaticText(this, wxID_STATIC, _("below each node")), 0,
6666
wxALL | wxALIGN_CENTER, 5);
@@ -78,7 +78,7 @@ gbtLegendDialog::gbtLegendDialog(wxWindow *p_parent, const gbtStyle &p_options)
7878
wxALL | wxALIGN_CENTER, 5);
7979
m_actionAbove =
8080
new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 4, actionLabelList);
81-
m_actionAbove->SetSelection(p_options.BranchAboveLabel());
81+
m_actionAbove->SetSelection(p_options.GetBranchAboveLabel());
8282
actionAboveSizer->Add(m_actionAbove, 1, wxALL | wxALIGN_CENTER, 5);
8383
actionAboveSizer->Add(new wxStaticText(this, wxID_STATIC, _("above each action")), 0,
8484
wxALL | wxALIGN_CENTER, 5);
@@ -89,7 +89,7 @@ gbtLegendDialog::gbtLegendDialog(wxWindow *p_parent, const gbtStyle &p_options)
8989
wxALL | wxALIGN_CENTER, 5);
9090
m_actionBelow =
9191
new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 4, actionLabelList);
92-
m_actionBelow->SetSelection(p_options.BranchBelowLabel());
92+
m_actionBelow->SetSelection(p_options.GetBranchBelowLabel());
9393
actionBelowSizer->Add(m_actionBelow, 1, wxALL | wxALIGN_CENTER, 5);
9494
actionBelowSizer->Add(new wxStaticText(this, wxID_STATIC, _("below each action")), 0,
9595
wxALL | wxALIGN_CENTER, 5);

src/gui/dlefglegend.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,23 @@ class gbtLegendDialog : public wxDialog {
3434
gbtLegendDialog(wxWindow *, const gbtStyle &);
3535

3636
// Data access (only valid when ShowModal() returns with wxID_OK)
37-
int GetNodeAbove() const { return m_nodeAbove->GetSelection(); }
38-
int GetNodeBelow() const { return m_nodeBelow->GetSelection(); }
37+
NodeLabelStyle GetNodeAbove() const
38+
{
39+
return static_cast<NodeLabelStyle>(m_nodeAbove->GetSelection());
40+
}
41+
NodeLabelStyle GetNodeBelow() const
42+
{
43+
return static_cast<NodeLabelStyle>(m_nodeBelow->GetSelection());
44+
}
3945

40-
int GetBranchAbove() const { return m_actionAbove->GetSelection(); }
41-
int GetBranchBelow() const { return m_actionBelow->GetSelection(); }
46+
BranchLabelStyle GetBranchAbove() const
47+
{
48+
return static_cast<BranchLabelStyle>(m_actionAbove->GetSelection());
49+
}
50+
BranchLabelStyle GetBranchBelow() const
51+
{
52+
return static_cast<BranchLabelStyle>(m_actionBelow->GetSelection());
53+
}
4254
};
4355

4456
#endif // DLEFGLEGEND_H

src/gui/dlefglogit.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ static wxColour GetPlayerColor(gbtGameDocument *p_doc, int p_index)
114114
return *wxBLACK;
115115
}
116116

117-
const Gambit::GameAction action = p_doc->GetAction(p_index);
118-
return p_doc->GetStyle().GetPlayerColor(action->GetInfoset()->GetPlayer()->GetNumber());
117+
const GameAction action = p_doc->GetAction(p_index);
118+
return p_doc->GetStyle().GetPlayerColor(action->GetInfoset()->GetPlayer());
119119
}
120120

121121
wxSheetCellAttr gbtLogitBehavList::GetAttr(const wxSheetCoords &p_coords, wxSheetAttr_Type) const
@@ -147,8 +147,7 @@ wxSheetCellAttr gbtLogitBehavList::GetAttr(const wxSheetCoords &p_coords, wxShee
147147
attr.SetOrientation(wxHORIZONTAL);
148148
if (p_coords.GetCol() > 0) {
149149
const Gambit::GameAction action = m_doc->GetAction(p_coords.GetCol());
150-
attr.SetForegroundColour(
151-
m_doc->GetStyle().GetPlayerColor(action->GetInfoset()->GetPlayer()->GetNumber()));
150+
attr.SetForegroundColour(m_doc->GetStyle().GetPlayerColor(action->GetInfoset()->GetPlayer()));
152151
if (action->GetInfoset()->GetNumber() % 2 == 0) {
153152
attr.SetBackgroundColour(wxColour(250, 250, 250));
154153
}

src/gui/dlefgreveal.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ gbtRevealMoveDialog::gbtRevealMoveDialog(wxWindow *p_parent, gbtGameDocument *p_
5353
m_players.push_back(new wxCheckBox(this, wxID_ANY, wxString::Format(_T("Player %d"), pl)));
5454
}
5555
m_players[pl]->SetValue(true);
56-
m_players[pl]->SetForegroundColour(m_doc->GetStyle().GetPlayerColor(pl));
56+
m_players[pl]->SetForegroundColour(m_doc->GetStyle().GetPlayerColor(player));
5757
boxSizer->Add(m_players[pl], 1, wxALL | wxEXPAND, 0);
5858
}
5959
playerBox->Add(boxSizer, 1, wxALL | wxEXPAND, 5);

src/gui/dlnfglogit.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ static wxColour GetPlayerColor(gbtGameDocument *p_doc, int p_index)
179179
for (const auto &player : p_doc->GetGame()->GetPlayers()) {
180180
for (const auto &strategy : player->GetStrategies()) {
181181
if (index++ == p_index) {
182-
return p_doc->GetStyle().GetPlayerColor(player->GetNumber());
182+
return p_doc->GetStyle().GetPlayerColor(player);
183183
}
184184
}
185185
}
@@ -379,7 +379,7 @@ gbtLogitPlotStrategyList::gbtLogitPlotStrategyList(wxWindow *p_parent, gbtGameDo
379379
for (int st = 1; st <= m_doc->GetGame()->MixedProfileLength(); st++) {
380380
const GameStrategy strategy = m_doc->GetGame()->GetStrategy(st);
381381
const GamePlayer player = strategy->GetPlayer();
382-
const wxColour color = m_doc->GetStyle().GetPlayerColor(player->GetNumber());
382+
const wxColour color = m_doc->GetStyle().GetPlayerColor(player);
383383

384384
if (strategy->GetNumber() == 1) {
385385
SetCellSpan(wxSheetCoords(st - 1, 0), wxSheetCoords(player->GetStrategies().size(), 1));
@@ -501,8 +501,8 @@ void LogitPlotPanel::Plot()
501501
m_branch.GetProfile(i + 1)[st]);
502502
}
503503

504-
curve->SetPen(wxPLOTPEN_NORMAL, wxPen(m_doc->GetStyle().GetPlayerColor(player->GetNumber()), 1,
505-
wxPENSTYLE_SOLID));
504+
curve->SetPen(wxPLOTPEN_NORMAL,
505+
wxPen(m_doc->GetStyle().GetPlayerColor(player), 1, wxPENSTYLE_SOLID));
506506

507507
m_plotCtrl->AddCurve(curve, false);
508508
}

0 commit comments

Comments
 (0)