-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c1d3c2
commit 03afbf2
Showing
10 changed files
with
213 additions
and
73 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { Graphics, BitmapText, Assets } from "../pixi.min.mjs"; | ||
import { getContainer, getElements } from "./app.js"; | ||
|
||
const TOP_MARGIN = 20; | ||
|
||
export function addBox(box) { | ||
const elements = getElements(); | ||
const container = getContainer(); | ||
container.addChild(box); | ||
elements.push(box); | ||
} | ||
|
||
export function buildBox(object) { | ||
const box = new Graphics(); | ||
box.roundRect(object.x, object.y, object.width, object.height, object.radius); | ||
box.fill(object.color); | ||
box.stroke({ width: 2, color: "#000000" }); | ||
return box; | ||
} | ||
|
||
export function addTitleToBox(title, box) { | ||
const boxTitle = new BitmapText({ | ||
text: title, | ||
style: { | ||
fontFamiliy: "sans-serif", | ||
fontSize: 16, | ||
align: "center", | ||
fill: "black", | ||
fontWeight: "bold", | ||
}, | ||
}); | ||
box.addChild(boxTitle); | ||
boxTitle.y = box.y + TOP_MARGIN; | ||
boxTitle.x = box.x + (box.width - boxTitle.width) / 2; | ||
return boxTitle.y; | ||
} | ||
|
||
export function addLinesToBox(lines, box, y) { | ||
let prevY = y; | ||
lines.forEach((line) => { | ||
const boxLine = new BitmapText({ | ||
text: line, | ||
style: { | ||
fontFamily: "sans-serif", | ||
fontSize: 14, | ||
align: "center", | ||
fill: "black", | ||
}, | ||
}); | ||
box.addChild(boxLine); | ||
boxLine.y = prevY + 10; | ||
boxLine.x = box.x + (box.width - boxLine.width) / 2; | ||
prevY = boxLine.y + boxLine.height; | ||
}); | ||
|
||
return prevY; | ||
} | ||
|
||
export async function svgElementToPixiSprite(src) { | ||
const sprite = await Assets.load({ | ||
src, | ||
data: { | ||
parseAsGraphicsContext: true, | ||
}, | ||
}); | ||
const graphics = new Graphics(sprite); | ||
return graphics; | ||
} | ||
|
||
export function addImageToBox(sprite, box, y) { | ||
box.addChild(sprite); | ||
sprite.y = y; | ||
sprite.x = box.x + (box.width - sprite.width) / 2; | ||
return sprite.y + sprite.height; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { getContainer, getApp } from "./app.js"; | ||
|
||
export const scrollTopLeft = () => { | ||
const container = getContainer(); | ||
container.x = 0; | ||
container.y = 0; | ||
}; | ||
|
||
export const scrollTopCenter = () => { | ||
const container = getContainer(); | ||
const app = getApp(); | ||
|
||
const screenWidth = app.renderer.width; | ||
const containerWidth = container.width; | ||
|
||
const x = (screenWidth - containerWidth) / 2; | ||
const y = 0; | ||
container.x = x; | ||
container.y = y; | ||
|
||
return { x, y }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,12 @@ | ||
export async function textToSVGElement(text) { | ||
const element = await MathJax.tex2svgPromise(text); | ||
return element.firstElementChild; | ||
export async function textToSVG(text) { | ||
const svg = await MathJax.tex2svg(text).firstElementChild; | ||
|
||
const src = | ||
"data:image/svg+xml;base64," + | ||
btoa( | ||
'<?xml version="1.0" encoding="UTF-8" standalone="no" ?>\n' + | ||
svg.outerHTML | ||
); | ||
|
||
return src; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.