Skip to content

Commit ad8993e

Browse files
committed
Fixed entity rendering crash (#968)
1 parent a95bdb7 commit ad8993e

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/electron.renderer/misc/JsTools.hx

+15-13
Original file line numberDiff line numberDiff line change
@@ -287,42 +287,44 @@ class JsTools {
287287
else {
288288
// Shape
289289
var superScale = 3;
290-
var wid = ed.width*superScale;
291-
var hei = ed.height*superScale;
290+
var scaledSizePx = sizePx * superScale;
291+
var padPct = 0.05;
292+
var pad = M.round( scaledSizePx*padPct );
293+
var shapeWid = scaledSizePx * (1-padPct*2) * ( ed.width>ed.height ? 1 : ed.width/ed.height );
294+
var shapeHei = scaledSizePx * (1-padPct*2) * ( ed.height>ed.width ? 1 : ed.height/ed.width );
292295
var jCanvas = new J('<canvas></canvas>');
293296
jCanvas.appendTo(jWrapper);
294-
jCanvas.attr("width", wid);
295-
jCanvas.attr("height", hei);
297+
jCanvas.attr("width", scaledSizePx);
298+
jCanvas.attr("height", scaledSizePx);
296299

297300
var cnv = Std.downcast( jCanvas.get(0), js.html.CanvasElement );
298301
var ctx = cnv.getContext2d();
299-
var pad = M.round( sizePx*0.1*superScale );
300302

301303
ctx.fillStyle = new dn.Col(ed.color).toCssRgba(ed.fillOpacity);
302304
ctx.strokeStyle = new dn.Col(ed.color).toCssRgba(ed.lineOpacity);
303305
ctx.lineWidth = 2/superScale;
304306

305307
switch ed.renderMode {
306308
case Rectangle:
307-
ctx.fillRect(pad, pad, wid-pad*2, hei-pad*2);
308-
ctx.strokeRect(pad, pad, wid-pad*2, hei-pad*2);
309+
ctx.fillRect(scaledSizePx*0.5-shapeWid*0.5, scaledSizePx*0.5-shapeHei*0.5, shapeWid, shapeHei);
310+
ctx.strokeRect(scaledSizePx*0.5-shapeWid*0.5, scaledSizePx*0.5-shapeHei*0.5, shapeWid, shapeHei);
309311

310312
case Ellipse:
311313
ctx.beginPath();
312314
ctx.ellipse(
313-
wid*0.5, hei*0.5,
314-
wid*0.5-pad, hei*0.5-pad,
315+
scaledSizePx*0.5, scaledSizePx*0.5,
316+
shapeWid*0.5, shapeHei*0.5,
315317
0, 0, M.PI*2
316318
);
317319
ctx.fill();
318320
ctx.stroke();
319321

320322
case Cross:
321323
ctx.lineWidth = 3;
322-
ctx.moveTo(0,0);
323-
ctx.lineTo(wid, hei);
324-
ctx.moveTo(0,hei);
325-
ctx.lineTo(wid, 0);
324+
ctx.moveTo(scaledSizePx*0.5-shapeWid*0.5, scaledSizePx*0.5-shapeHei*0.5);
325+
ctx.lineTo(scaledSizePx*0.5+shapeWid*0.5, scaledSizePx*0.5+shapeHei*0.5);
326+
ctx.moveTo(scaledSizePx*0.5+shapeWid*0.5, scaledSizePx*0.5-shapeHei*0.5);
327+
ctx.lineTo(scaledSizePx*0.5-shapeWid*0.5, scaledSizePx*0.5+shapeHei*0.5);
326328
ctx.stroke();
327329

328330
case Tile: // N/A

0 commit comments

Comments
 (0)