Skip to content

Commit

Permalink
Merge pull request #10 from rooklift/tree_drawer
Browse files Browse the repository at this point in the history
Tree drawer
  • Loading branch information
rooklift committed May 18, 2021
2 parents 20744f0 + ab99206 commit 2f8dd1a
Show file tree
Hide file tree
Showing 9 changed files with 507 additions and 47 deletions.
197 changes: 197 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,203 @@ function menu_build() {
},
]
},
{
label: "Graph width",
submenu: [
{
label: "512",
type: "checkbox",
checked: config.graph_width === 512,
click: () => {
win.webContents.send("set", {
key: "graph_width",
value: 512
});
set_checks("Display", "Graph width", "512");
}
},
{
label: "480",
type: "checkbox",
checked: config.graph_width === 480,
click: () => {
win.webContents.send("set", {
key: "graph_width",
value: 480
});
set_checks("Display", "Graph width", "480");
}
},
{
label: "448",
type: "checkbox",
checked: config.graph_width === 448,
click: () => {
win.webContents.send("set", {
key: "graph_width",
value: 448
});
set_checks("Display", "Graph width", "448");
}
},
{
label: "416",
type: "checkbox",
checked: config.graph_width === 416,
click: () => {
win.webContents.send("set", {
key: "graph_width",
value: 416
});
set_checks("Display", "Graph width", "416");
}
},
{
label: "384",
type: "checkbox",
checked: config.graph_width === 384,
click: () => {
win.webContents.send("set", {
key: "graph_width",
value: 384
});
set_checks("Display", "Graph width", "384");
}
},
{
label: "352",
type: "checkbox",
checked: config.graph_width === 352,
click: () => {
win.webContents.send("set", {
key: "graph_width",
value: 352
});
set_checks("Display", "Graph width", "352");
}
},
{
label: "320",
type: "checkbox",
checked: config.graph_width === 320,
click: () => {
win.webContents.send("set", {
key: "graph_width",
value: 320
});
set_checks("Display", "Graph width", "320");
}
},
{
label: "288",
type: "checkbox",
checked: config.graph_width === 288,
click: () => {
win.webContents.send("set", {
key: "graph_width",
value: 288
});
set_checks("Display", "Graph width", "288");
}
},
{
label: "256",
type: "checkbox",
checked: config.graph_width === 256,
click: () => {
win.webContents.send("set", {
key: "graph_width",
value: 256
});
set_checks("Display", "Graph width", "256");
}
},
{
label: "224",
type: "checkbox",
checked: config.graph_width === 224,
click: () => {
win.webContents.send("set", {
key: "graph_width",
value: 224
});
set_checks("Display", "Graph width", "224");
}
},
{
label: "192",
type: "checkbox",
checked: config.graph_width === 192,
click: () => {
win.webContents.send("set", {
key: "graph_width",
value: 192
});
set_checks("Display", "Graph width", "192");
}
},
{
label: "160",
type: "checkbox",
checked: config.graph_width === 160,
click: () => {
win.webContents.send("set", {
key: "graph_width",
value: 160
});
set_checks("Display", "Graph width", "160");
}
},
{
label: "128",
type: "checkbox",
checked: config.graph_width === 128,
click: () => {
win.webContents.send("set", {
key: "graph_width",
value: 128
});
set_checks("Display", "Graph width", "128");
}
},
{
label: "96",
type: "checkbox",
checked: config.graph_width === 96,
click: () => {
win.webContents.send("set", {
key: "graph_width",
value: 96
});
set_checks("Display", "Graph width", "96");
}
},
{
label: "64",
type: "checkbox",
checked: config.graph_width === 64,
click: () => {
win.webContents.send("set", {
key: "graph_width",
value: 64
});
set_checks("Display", "Graph width", "64");
}
},
{
label: "0",
type: "checkbox",
checked: config.graph_width === 0,
click: () => {
win.webContents.send("set", {
key: "graph_width",
value: 0
});
set_checks("Display", "Graph width", "0");
}
}
]
},
{
type: "separator",
},
Expand Down
5 changes: 5 additions & 0 deletions src/modules/__start_handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ document.getElementById("graphpositioncanvas").addEventListener("mousedown", (ev
hub.set_node(node);
});

document.getElementById("treecanvas").addEventListener("mousedown", (event) => {
let node = hub.tree_drawer.node_from_click(hub.node, event);
hub.set_node(node);
});

// Pressing arrows or Home or End should NOT affect the tabs list, but rather move about in the current game...

window.addEventListener("keydown", function(event) {
Expand Down
9 changes: 7 additions & 2 deletions src/modules/config_io.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ exports.defaults_classified = {
"major_graph_colour": "#4ba28bff",
"major_graph_var_colour": "#4b8ba2ff",
"midline_graph_colour": "#222222ff",
"graph_width": 224,
},

tree_redrawers: {
"tree_spacing": 24,
},

search_changers: {
Expand All @@ -73,7 +78,7 @@ exports.defaults_classified = {
},

no_immediate_effect: {
"width": 900,
"width": 1200,
"height": 740,
"stderr_to_console": true,
"autoanalysis_visits": 500,
Expand All @@ -93,7 +98,7 @@ for (let cl of Object.keys(exports.defaults_classified)) {

exports.size_keys = [
"minor_graph_linewidth", "major_graph_linewidth", "square_size", "thumbnail_square_size",
"board_line_width", "board_font_size", "info_font_size"
"board_line_width", "board_font_size", "info_font_size", "graph_width", "tree_spacing"
];

exports.colour_keys = Object.keys(exports.defaults).filter(key => typeof exports.defaults[key] === "string" && exports.defaults[key][0] === "#");
Expand Down
23 changes: 14 additions & 9 deletions src/modules/grapher.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,19 @@ let graph_drawer_prototype = {
throw "draw_graph() needs a node argument";
}

this.canvas.width = Math.max(64, window.innerWidth - this.canvas.getBoundingClientRect().left);
this.canvas.width = Math.max(0, Math.min(config.graph_width, window.innerWidth - this.canvas.getBoundingClientRect().left));
this.canvas.height = this.boardcanvas.height + 128;

this.draw_x_offset = 16;
this.draw_y_offset = this.boardcanvas.getBoundingClientRect().top - this.canvas.getBoundingClientRect().top + (config.square_size / 4);

this.drawable_width = this.canvas.width - (this.draw_x_offset * 2);
this.drawable_height = this.boardcanvas.height - (config.square_size / 2);
this.drawable_width = Math.max(0, this.canvas.width - (this.draw_x_offset * 2));
this.drawable_height = Math.max(0, this.boardcanvas.height - (config.square_size / 2));

if (this.drawable_width <= 0 || this.drawable_height <= 0) {
this.draw_position(node); // Will set its own canvas to zero size.
return;
}

let ctx = this.canvas.getContext("2d");

Expand Down Expand Up @@ -125,17 +130,17 @@ let graph_drawer_prototype = {

draw_position: function(node) {

if (!this.drawable_height) {
return;
}

let ctx = this.positioncanvas.getContext("2d");

// Clear the position canvas, while also making sure it's the right size...

this.positioncanvas.width = this.canvas.width;
this.positioncanvas.height = this.canvas.height;

if (this.drawable_width <= 0 || this.drawable_height <= 0) {
return;
}

let ctx = this.positioncanvas.getContext("2d");

// Position marker...

ctx.lineWidth = config.major_graph_linewidth;
Expand Down
Loading

0 comments on commit 2f8dd1a

Please sign in to comment.