Enable Retina graphics for Turtle
This commit is contained in:
@ -3,10 +3,13 @@ var editor;
|
|||||||
var pipeurl;
|
var pipeurl;
|
||||||
var filename;
|
var filename;
|
||||||
var pendingChanges = -1;
|
var pendingChanges = -1;
|
||||||
|
var devicePixelRatio = window.devicePixelRatio || 1;
|
||||||
|
|
||||||
function Turtle(pipe, canvas) {
|
function Turtle(pipe, canvas) {
|
||||||
var dx, dy, xpos, ypos;
|
var dx, dy, xpos, ypos;
|
||||||
this.canvas = canvas; // jQuery object
|
this.canvas = canvas; // jQuery object
|
||||||
|
this.height;
|
||||||
|
this.width;
|
||||||
this.items = [];
|
this.items = [];
|
||||||
this.canvas.off('click');
|
this.canvas.off('click');
|
||||||
|
|
||||||
@ -48,9 +51,9 @@ function Turtle(pipe, canvas) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
dx = this.width / 2;
|
dx = this.width / (2 * devicePixelRatio);
|
||||||
dy = this.height / 2;
|
dy = this.height / (2 * devicePixelRatio);
|
||||||
if(e.offsetX==undefined)
|
if(e.offsetX===undefined)
|
||||||
{
|
{
|
||||||
var offset = canvas.offset();
|
var offset = canvas.offset();
|
||||||
xpos = e.pageX-offset.left;
|
xpos = e.pageX-offset.left;
|
||||||
@ -68,11 +71,16 @@ function Turtle(pipe, canvas) {
|
|||||||
Turtle.prototype.update = function () {
|
Turtle.prototype.update = function () {
|
||||||
var i, k, canvas, ctx, dx, dy, item, c, length;
|
var i, k, canvas, ctx, dx, dy, item, c, length;
|
||||||
canvas = this.canvas[0];
|
canvas = this.canvas[0];
|
||||||
|
canvas.width = this.get_width() * devicePixelRatio;
|
||||||
|
canvas.height = this.get_height() * devicePixelRatio;
|
||||||
|
canvas.style.width = `${this.get_width()}px`;
|
||||||
|
canvas.style.height = `${this.get_height()}px`;
|
||||||
ctx = canvas.getContext('2d');
|
ctx = canvas.getContext('2d');
|
||||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||||
|
ctx.scale(devicePixelRatio, devicePixelRatio);
|
||||||
length = this.items.length;
|
length = this.items.length;
|
||||||
dx = canvas.width / 2;
|
dx = canvas.width / (2 * devicePixelRatio);
|
||||||
dy = canvas.height / 2;
|
dy = canvas.height / (2 * devicePixelRatio);
|
||||||
for (i = 0; i < length; i += 1) {
|
for (i = 0; i < length; i += 1) {
|
||||||
item = this.items[i];
|
item = this.items[i];
|
||||||
c = item.coords;
|
c = item.coords;
|
||||||
@ -110,11 +118,17 @@ Turtle.prototype.update = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Turtle.prototype.get_width = function () {
|
Turtle.prototype.get_width = function () {
|
||||||
return this.canvas[0].width;
|
if (this.width === undefined) {
|
||||||
|
this.width = this.canvas[0].width;
|
||||||
|
}
|
||||||
|
return this.width;
|
||||||
}
|
}
|
||||||
|
|
||||||
Turtle.prototype.get_height = function () {
|
Turtle.prototype.get_height = function () {
|
||||||
return this.canvas[0].height;
|
if (this.height === undefined) {
|
||||||
|
this.height = this.canvas[0].height;
|
||||||
|
}
|
||||||
|
return this.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
Turtle.prototype.delete = function (item) {
|
Turtle.prototype.delete = function (item) {
|
||||||
|
Reference in New Issue
Block a user