1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 04:40:03 -04:00
This commit is contained in:
Emil Ernerfeldt
2018-12-26 22:17:33 +01:00
parent 2e4d961676
commit 4bca549de1
7 changed files with 175 additions and 78 deletions

View File

@@ -2,18 +2,6 @@ function paintCommand(canvas, cmd) {
var ctx = canvas.getContext("2d");
// console.log(`cmd: ${JSON.stringify(cmd)}`);
switch (cmd.kind) {
case "clear":
ctx.fillStyle = cmd.fill_style;
ctx.clearRect(0, 0, canvas.width, canvas.height);
return;
case "line":
ctx.beginPath();
ctx.lineWidth = cmd.line_width;
ctx.strokeStyle = cmd.stroke_style;
ctx.moveTo(cmd.from.x, cmd.from.y);
ctx.lineTo(cmd.to.x, cmd.to.y);
ctx.stroke();
return;
case "circle":
ctx.beginPath();
ctx.arc(cmd.center.x, cmd.center.y, cmd.radius, 0, 2 * Math.PI, false);
@@ -27,6 +15,21 @@ function paintCommand(canvas, cmd) {
ctx.stroke();
}
return;
case "clear":
ctx.fillStyle = cmd.fill_style;
ctx.clearRect(0, 0, canvas.width, canvas.height);
return;
case "line":
ctx.beginPath();
ctx.moveTo(cmd.points[0].x, cmd.points[0].y);
for (var _i = 0, _a = cmd.points; _i < _a.length; _i++) {
var point = _a[_i];
ctx.lineTo(point.x, point.y);
}
ctx.lineWidth = cmd.width;
ctx.strokeStyle = cmd.style;
ctx.stroke();
return;
case "rect":
var x = cmd.pos.x;
var y = cmd.pos.y;

View File

@@ -13,10 +13,9 @@ interface Clear {
interface Line {
kind: "line";
from: Vec2;
line_width: number;
stroke_style: string;
to: Vec2;
points: Vec2[];
style: string;
width: number;
}
interface Outline {
@@ -59,20 +58,6 @@ function paintCommand(canvas, cmd: PaintCmd) {
// console.log(`cmd: ${JSON.stringify(cmd)}`);
switch (cmd.kind) {
case "clear":
ctx.fillStyle = cmd.fill_style;
ctx.clearRect(0, 0, canvas.width, canvas.height);
return;
case "line":
ctx.beginPath();
ctx.lineWidth = cmd.line_width;
ctx.strokeStyle = cmd.stroke_style;
ctx.moveTo(cmd.from.x, cmd.from.y);
ctx.lineTo(cmd.to.x, cmd.to.y);
ctx.stroke();
return;
case "circle":
ctx.beginPath();
ctx.arc(cmd.center.x, cmd.center.y, cmd.radius, 0, 2 * Math.PI, false);
@@ -87,6 +72,22 @@ function paintCommand(canvas, cmd: PaintCmd) {
}
return;
case "clear":
ctx.fillStyle = cmd.fill_style;
ctx.clearRect(0, 0, canvas.width, canvas.height);
return;
case "line":
ctx.beginPath();
ctx.moveTo(cmd.points[0].x, cmd.points[0].y);
for (const point of cmd.points) {
ctx.lineTo(point.x, point.y);
}
ctx.lineWidth = cmd.width;
ctx.strokeStyle = cmd.style;
ctx.stroke();
return;
case "rect":
const x = cmd.pos.x;
const y = cmd.pos.y;