Skip to content

Commit

Permalink
Fixed entity rendering crash (#968)
Browse files Browse the repository at this point in the history
  • Loading branch information
deepnight committed Sep 25, 2023
1 parent a95bdb7 commit ad8993e
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/electron.renderer/misc/JsTools.hx
Original file line number Diff line number Diff line change
Expand Up @@ -287,42 +287,44 @@ class JsTools {
else {
// Shape
var superScale = 3;
var wid = ed.width*superScale;
var hei = ed.height*superScale;
var scaledSizePx = sizePx * superScale;
var padPct = 0.05;
var pad = M.round( scaledSizePx*padPct );
var shapeWid = scaledSizePx * (1-padPct*2) * ( ed.width>ed.height ? 1 : ed.width/ed.height );
var shapeHei = scaledSizePx * (1-padPct*2) * ( ed.height>ed.width ? 1 : ed.height/ed.width );
var jCanvas = new J('<canvas></canvas>');
jCanvas.appendTo(jWrapper);
jCanvas.attr("width", wid);
jCanvas.attr("height", hei);
jCanvas.attr("width", scaledSizePx);
jCanvas.attr("height", scaledSizePx);

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

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

switch ed.renderMode {
case Rectangle:
ctx.fillRect(pad, pad, wid-pad*2, hei-pad*2);
ctx.strokeRect(pad, pad, wid-pad*2, hei-pad*2);
ctx.fillRect(scaledSizePx*0.5-shapeWid*0.5, scaledSizePx*0.5-shapeHei*0.5, shapeWid, shapeHei);
ctx.strokeRect(scaledSizePx*0.5-shapeWid*0.5, scaledSizePx*0.5-shapeHei*0.5, shapeWid, shapeHei);

case Ellipse:
ctx.beginPath();
ctx.ellipse(
wid*0.5, hei*0.5,
wid*0.5-pad, hei*0.5-pad,
scaledSizePx*0.5, scaledSizePx*0.5,
shapeWid*0.5, shapeHei*0.5,
0, 0, M.PI*2
);
ctx.fill();
ctx.stroke();

case Cross:
ctx.lineWidth = 3;
ctx.moveTo(0,0);
ctx.lineTo(wid, hei);
ctx.moveTo(0,hei);
ctx.lineTo(wid, 0);
ctx.moveTo(scaledSizePx*0.5-shapeWid*0.5, scaledSizePx*0.5-shapeHei*0.5);
ctx.lineTo(scaledSizePx*0.5+shapeWid*0.5, scaledSizePx*0.5+shapeHei*0.5);
ctx.moveTo(scaledSizePx*0.5+shapeWid*0.5, scaledSizePx*0.5-shapeHei*0.5);
ctx.lineTo(scaledSizePx*0.5-shapeWid*0.5, scaledSizePx*0.5+shapeHei*0.5);
ctx.stroke();

case Tile: // N/A
Expand Down

0 comments on commit ad8993e

Please sign in to comment.