make drawshape work better

This commit is contained in:
Tim Young 2024-06-06 14:16:01 -07:00
parent 726bafe580
commit 9aa26b82c6

View File

@ -732,43 +732,52 @@ function printHighlights(countof="mouseover") {
return countof; //the count of the item we were supposed to count return countof; //the count of the item we were supposed to count
} }
function drawhighlight(highlight) { function drawhighlight(highlight, canvas = null) {
MainCanvas_ctx.fillStyle = highlight.shapeColor; if (canvas == null)
MainCanvas_ctx.globalAlpha = highlight.opaciticy; //mostly transparent canvas = MainCanvas_ctx;
canvas.fillStyle = highlight.shapeColor;
canvas.globalAlpha = highlight.opaciticy; //mostly transparent
var oldWidth; var oldWidth;
if (highlight.shapeText == "square") if (highlight.shapeText == "square")
MainCanvas_ctx.fillRect(highlight.shapePoints.sx, highlight.shapePoints.sy, highlight.shapePoints.deltax, highlight.shapePoints.deltay); canvas.fillRect(highlight.shapePoints.sx, highlight.shapePoints.sy, highlight.shapePoints.deltax, highlight.shapePoints.deltay);
else if (highlight.shapeText == "line") { else if (highlight.shapeText == "line") {
oldWidth = MainCanvas_ctx.lineWidth; oldWidth = canvas.lineWidth;
MainCanvas_ctx.lineWidth += 6; canvas.lineWidth += 6;
MainCanvas_ctx.strokeStyle = highlight.shapeColor; canvas.strokeStyle = highlight.shapeColor;
MainCanvas_ctx.beginPath(); canvas.beginPath();
MainCanvas_ctx.moveTo(highlight.shapePoints.sx, highlight.shapePoints.sy); canvas.moveTo(highlight.shapePoints.sx, highlight.shapePoints.sy);
MainCanvas_ctx.lineTo(highlight.shapePoints.dx, highlight.shapePoints.dy); canvas.lineTo(highlight.shapePoints.dx, highlight.shapePoints.dy);
MainCanvas_ctx.stroke(); canvas.stroke();
MainCanvas_ctx.lineWidth = oldWidth; canvas.lineWidth = oldWidth;
MainCanvas_ctx.strokeStyle = "black"; canvas.strokeStyle = "black";
} }
else if (highlight.shapeText == "selectbox") { else if (highlight.shapeText == "selectbox") {
//console.log("Printing a selectbox"); //console.log("Printing a selectbox");
MainCanvas_ctx.fillStyle = "green"; canvas.fillStyle = "green";
oldWidth = MainCanvas_ctx.lineWidth; oldWidth = canvas.lineWidth;
MainCanvas_ctx.lineWidth += 2; canvas.lineWidth += 2;
MainCanvas_ctx.strokeStyle = "green"; canvas.strokeStyle = "green";
MainCanvas_ctx.beginPath(); canvas.beginPath();
MainCanvas_ctx.moveTo(highlight.shapePoints.sx, highlight.shapePoints.sy); canvas.moveTo(highlight.shapePoints.sx, highlight.shapePoints.sy);
MainCanvas_ctx.lineTo(highlight.shapePoints.dx, highlight.shapePoints.sy); canvas.lineTo(highlight.shapePoints.dx, highlight.shapePoints.sy);
MainCanvas_ctx.lineTo(highlight.shapePoints.dx, highlight.shapePoints.dy); canvas.lineTo(highlight.shapePoints.dx, highlight.shapePoints.dy);
MainCanvas_ctx.lineTo(highlight.shapePoints.sx, highlight.shapePoints.dy); canvas.lineTo(highlight.shapePoints.sx, highlight.shapePoints.dy);
MainCanvas_ctx.lineTo(highlight.shapePoints.sx, highlight.shapePoints.sy); canvas.lineTo(highlight.shapePoints.sx, highlight.shapePoints.sy);
MainCanvas_ctx.stroke(); canvas.stroke();
MainCanvas_ctx.lineWidth = oldWidth; canvas.lineWidth = oldWidth;
MainCanvas_ctx.strokeStyle = "black"; canvas.strokeStyle = "black";
} }
MainCanvas_ctx.globalAlpha = 1.0; //reset canvas.globalAlpha = 1.0; //reset
MainCanvas_ctx.fillStyle = "black"; //reset canvas.fillStyle = "black"; //reset
} }
//We use drawhighlight to draw one-off shapes
function drawshape( shape, rect, color, opaciticy = 0.4, canvas = null) {
if (canvas == null)
canvas = MainCanvas_ctx;
var tmp_queryhighlight = returnHighlightShape(shape, rect, color, "none", opaciticy);
drawhighlight(tmp_queryhighlight, canvas);
}
function countHighlightsNamed(countof = "mouseover") { function countHighlightsNamed(countof = "mouseover") {
var count = 0; var count = 0;