Skip to content

Commit

Permalink
Merge pull request #898 from jaredkhan/hover
Browse files Browse the repository at this point in the history
Hover
  • Loading branch information
hyanwong authored Dec 9, 2024
2 parents 0570bf4 + 1d7754b commit 35d92a7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
3 changes: 0 additions & 3 deletions OZprivate/rawJS/OZTreeModule/src/interactor/touch.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ class TouchInteractor {
} else if (event.targetTouches.length == 1) {
this.clicking = true;
}
// Jog the tree slightly to ensure that node hover-over states update
// NB: Obviously a hack, ideally we'd force this update without - see #155
this.controller.pan(1, 0);
}

touch_move(event) {
Expand Down
23 changes: 21 additions & 2 deletions OZprivate/rawJS/OZTreeModule/src/render/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ let last_yp = null;
let last_ws = null;
let last_btn_data = null;
let last_btn_action = null;
let last_button_x = null;
let last_button_y = null;

//Do not skip refresh when render_id = 60, 120, 180... because we want to refresh page when node details or images get fetched.
let render_id = 0;
Expand Down Expand Up @@ -58,8 +60,20 @@ function refresh(root) {
let start = new Date().getTime();
let shapes = [];

if (need_refresh()) {
const cursor_moved = tree_state.button_x != last_button_x || tree_state.button_y != last_button_y;

if (cursor_moved) {
last_button_x = tree_state.button_x;
last_button_y = tree_state.button_y;
// get the shapes early so we see global_button_action changes in need_refresh
controller.projection.get_shapes(root, shapes);
}

if (need_refresh()) {
if (!cursor_moved) {
controller.projection.get_shapes(root, shapes);
}
update_cursor();
refresh_by_redraw(shapes, context);
let end = new Date().getTime();
adjust_threshold(end-start);
Expand All @@ -68,6 +82,11 @@ function refresh(root) {
}
}

function update_cursor() {
// If cursor wasn't set here (e.g. was set by mouse interactor), leave it as it is.
if (canvas.style.cursor && !["move", "pointer", "default"].includes(canvas.style.cursor)) return;
canvas.style.cursor = tree_state.mouse_hold ? "move" : (global_button_action.action ? "pointer" : "default");
}

/**
* This function would first dynamically develop undeveloped parts.
Expand Down Expand Up @@ -105,7 +124,7 @@ function need_refresh() {

if (render_id % 60 === 0) return true;
if (tree_state.xp != last_xp || tree_state.yp != last_yp || tree_state.ws != last_ws) return true;
if (!areEqual(global_button_action.action,last_btn_action)) return true
if (!areEqual(global_button_action.action,last_btn_action)) return true;
if (!areEqual(global_button_action.data,last_btn_data)) return true;
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions OZprivate/rawJS/OZTreeModule/src/tree_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class TreeState {
this.url_parsed = false;
this.last_active_at = new Date();
this.last_render_at = new Date();
this.button_x = null;
this.button_y = null;
let self = this;
setTimeout(function() {
self.url_parsed = true;
Expand Down

0 comments on commit 35d92a7

Please sign in to comment.