Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fb4a96d81b | ||
|
|
bbf115f33c | ||
|
|
5d9c2cf590 | ||
|
|
b99231f6e2 | ||
|
|
2676907129 | ||
|
|
6f4c533ebb | ||
|
|
85dcaea979 | ||
|
|
8560b31657 | ||
|
|
b896588f45 | ||
|
|
0b4d4facfe | ||
|
|
52ad897ee3 | ||
|
|
72582f2a60 | ||
|
|
2b2048da7d | ||
|
|
e85fa990bd | ||
|
|
81a61538c3 | ||
|
|
cc8751bd09 |
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "microbit",
|
||||
"name": "BBC micro:bit",
|
||||
"title": "JavaScript for BBC micro:bit",
|
||||
"name": "code micro:bit",
|
||||
"title": "micro:bit",
|
||||
"corepkg": "microbit",
|
||||
"bundleddirs": [
|
||||
"libs/microbit",
|
||||
@@ -22,13 +22,13 @@
|
||||
"description": "",
|
||||
"files": [
|
||||
"main.blocks",
|
||||
"main.blocks.ts",
|
||||
"main.ts",
|
||||
"README.md"
|
||||
]
|
||||
},
|
||||
"files": {
|
||||
"main.blocks": "<xml xmlns=\"http://www.w3.org/1999/xhtml\"><block type=\"device_print_message\"><value name=\"text\"><shadow type=\"text\"><field name=\"TEXT\">Hello!</field></shadow></value></block></xml>",
|
||||
"main.blocks.ts": "\n",
|
||||
"main.ts": "\n",
|
||||
"README.md": "Describe your project here!"
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "kindscript-microbit",
|
||||
"version": "0.2.29",
|
||||
"version": "0.2.36",
|
||||
"description": "BBC micro:bit target for KindScript",
|
||||
"keywords": [
|
||||
"JavaScript",
|
||||
@@ -29,6 +29,6 @@
|
||||
"typescript": "^1.8.7"
|
||||
},
|
||||
"dependencies": {
|
||||
"kindscript": "0.2.30"
|
||||
"kindscript": "0.2.36"
|
||||
}
|
||||
}
|
||||
|
||||
114
sim/simsvg.ts
114
sim/simsvg.ts
@@ -1,4 +1,5 @@
|
||||
namespace ks.rt.micro_bit {
|
||||
const Svg = ks.rt.Svg;
|
||||
|
||||
export interface IBoardTheme {
|
||||
accent?: string;
|
||||
@@ -46,119 +47,6 @@ namespace ks.rt.micro_bit {
|
||||
disableTilt?:boolean;
|
||||
}
|
||||
|
||||
class Svg {
|
||||
static pt : SVGPoint;
|
||||
static cursorPoint(pt: SVGPoint, svg: SVGSVGElement, evt : MouseEvent) : SVGPoint {
|
||||
pt.x = evt.clientX;
|
||||
pt.y = evt.clientY;
|
||||
return pt.matrixTransform(svg.getScreenCTM().inverse());
|
||||
}
|
||||
|
||||
static rotateElement(el : SVGElement, originX : number ,originY : number,degrees:number){
|
||||
el.setAttribute(
|
||||
'transform',
|
||||
`translate(${originX},${originY}) rotate(${degrees+90}) translate(${-originX},${-originY})`
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
static elt(name:string) : SVGElement {
|
||||
return document.createElementNS("http://www.w3.org/2000/svg", name)
|
||||
}
|
||||
|
||||
static hydrate(el : SVGElement, props: any) {
|
||||
for(let k in props) {
|
||||
if (k == "title") {
|
||||
Svg.title(el, props[k])
|
||||
} else el.setAttributeNS(null, k, props[k])
|
||||
}
|
||||
}
|
||||
|
||||
static child(parent : Element, name: string, props: any) : SVGElement {
|
||||
var el = <SVGElement>Svg.elt(name);
|
||||
Svg.hydrate(el, props);
|
||||
parent.appendChild(el);
|
||||
return el;
|
||||
}
|
||||
|
||||
static path(parent: Element, cls: string, data:string, title?: string) : SVGElement {
|
||||
let p : any = {class:cls, d:data};
|
||||
if (title) p["title"] = title;
|
||||
return Svg.child(parent, "path", p);
|
||||
}
|
||||
|
||||
static fill(el: SVGElement, c : string) {
|
||||
(<SVGStylable><any>el).style.fill = c;
|
||||
}
|
||||
|
||||
static fills(els: SVGElement[], c : string) {
|
||||
els.forEach(el => (<SVGStylable><any>el).style.fill = c);
|
||||
}
|
||||
|
||||
static buttonEvents(el : Element,
|
||||
move: (ev: MouseEvent) => void,
|
||||
start?: (ev:MouseEvent) => void,
|
||||
stop?: (ev:MouseEvent) => void) {
|
||||
let captured = false;
|
||||
el.addEventListener('mousedown', (ev: MouseEvent) => {
|
||||
captured = true;
|
||||
if (start) start(ev)
|
||||
return true;
|
||||
});
|
||||
el.addEventListener('mousemove', (ev:MouseEvent) => {
|
||||
if (captured) {
|
||||
move(ev);
|
||||
ev.preventDefault();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
el.addEventListener('mouseup', (ev:MouseEvent) => {
|
||||
captured = false;
|
||||
if (stop) stop(ev);
|
||||
});
|
||||
el.addEventListener('mouseleave', (ev:MouseEvent) => {
|
||||
captured = false;
|
||||
if (stop) stop(ev);
|
||||
});
|
||||
}
|
||||
|
||||
static linearGradient(defs: SVGDefsElement, id : string) : SVGLinearGradientElement {
|
||||
let gradient = <SVGLinearGradientElement>Svg.child(defs, "linearGradient", { id: id, x1:"0%", y1:"0%", x2:"0%", y2:"100%" });
|
||||
let stop1 = Svg.child(gradient, "stop", {offset:"0%"})
|
||||
let stop2 = Svg.child(gradient, "stop", {offset:"100%"})
|
||||
let stop3 = Svg.child(gradient, "stop", {offset:"100%"})
|
||||
let stop4 = Svg.child(gradient, "stop", {offset:"100%"})
|
||||
return gradient;
|
||||
}
|
||||
|
||||
static setGradientColors(lg : SVGLinearGradientElement, start:string, end:string) {
|
||||
if (!lg) return;
|
||||
|
||||
(<SVGStopElement>lg.childNodes[0]).style.stopColor = start;
|
||||
(<SVGStopElement>lg.childNodes[1]).style.stopColor = start;
|
||||
(<SVGStopElement>lg.childNodes[2]).style.stopColor = end;
|
||||
(<SVGStopElement>lg.childNodes[3]).style.stopColor = end;
|
||||
}
|
||||
|
||||
static setGradientValue(lg : SVGLinearGradientElement, percent: string) {
|
||||
(<SVGStopElement>lg.childNodes[1]).setAttribute("offset", percent);
|
||||
(<SVGStopElement>lg.childNodes[2]).setAttribute("offset", percent);
|
||||
}
|
||||
|
||||
static animate(el: SVGElement, cls: string) {
|
||||
el.classList.add(cls);
|
||||
let p = el.parentElement;
|
||||
p.removeChild(el);
|
||||
p.appendChild(el)
|
||||
}
|
||||
|
||||
static title(el : SVGElement, txt:string) {
|
||||
let t = Svg.child(el, "title", {});
|
||||
t.textContent = txt;
|
||||
}
|
||||
}
|
||||
|
||||
export class MicrobitBoardSvg
|
||||
{
|
||||
public element : SVGSVGElement;
|
||||
|
||||
Reference in New Issue
Block a user