Skip to content

Commit

Permalink
Merge pull request #923 from jaredkhan/fix-lost-context-scale
Browse files Browse the repository at this point in the history
Remember scale when context is lost
  • Loading branch information
hyanwong authored Dec 4, 2024
2 parents 30dad8c + 58fd425 commit f231464
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions OZprivate/rawJS/OZTreeModule/src/render/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ let controller = null;
let context = null;
let temp_context = null;
let canvas = null;
let scale_factor = 1;
let bg_canvas = null;
let bg_context = null;

Expand All @@ -28,15 +29,13 @@ function add_controller(_c) {
function setup_canvas(_c) {
canvas = _c;
context = canvas.getContext("2d");
context.scale(window.devicePixelRatio, window.devicePixelRatio);
scale_factor = window.devicePixelRatio;
if (!bg_canvas) {
bg_canvas = document.createElement('canvas');
bg_context = bg_canvas.getContext('2d');
}
bg_canvas.width = _c.width;
bg_canvas.width = _c.width; // setting width/height resets context
bg_canvas.height = _c.height;
bg_context.resetTransform();
bg_context.scale(window.devicePixelRatio, window.devicePixelRatio);
}

function set_temp_context(_c) {
Expand Down Expand Up @@ -112,6 +111,8 @@ function need_refresh() {
}

function refresh_by_redraw(shapes, _context) {
_context.resetTransform();
_context.scale(scale_factor, scale_factor);
_context.clearRect(0,0,tree_state.widthres,tree_state.heightres);
let length = shapes.length;
for (let i=0; i<length; i++) {
Expand Down

0 comments on commit f231464

Please sign in to comment.