Add non-working menu buttons
This commit is contained in:
parent
435b24cb6a
commit
6223b35536
6 changed files with 43 additions and 9 deletions
|
@ -1,9 +1,11 @@
|
|||
import * as gui from './index.mjs';
|
||||
import GuiElement from './element.mjs';
|
||||
|
||||
export class GuiButton extends gui.GuiElement {
|
||||
constructor(x, y, text, onclick) {
|
||||
let textSize = gui.measureText(text, 'Arial 14pt');
|
||||
super(x, y, ...textSize);
|
||||
export default class GuiButton extends GuiElement {
|
||||
constructor(text, onclick, x, y, w = 100, h = 30) {
|
||||
super(x, y, w, h);
|
||||
this.type = 'button';
|
||||
this.text = text;
|
||||
this.onclick = onclick;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,10 @@ export default class GuiElement {
|
|||
return [this.x, this.y, this.w, this.h];
|
||||
}
|
||||
|
||||
get center() {
|
||||
return [this.x + this.w / 2, this.y + this.h / 2];
|
||||
}
|
||||
|
||||
posRelative({x = null, xc = 0, y = null, yc = 0, w = null, h = null}) {
|
||||
if (x !== null) {
|
||||
this.x = (this.parent.w * x) - (this.w * xc);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import * as gui from './index.mjs';
|
||||
import GuiElement from './element.mjs';
|
||||
|
||||
export class GuiImage extends GuiElement {
|
||||
export default class GuiImage extends GuiElement {
|
||||
constructor(src, x, y, w, h) {
|
||||
w = w || src.width;
|
||||
h = h || src.height;
|
||||
|
|
|
@ -2,7 +2,8 @@ import * as gui from './index.mjs';
|
|||
import {images as assets} from '../assets.mjs';
|
||||
import {canvas} from '../graphics/index.mjs';
|
||||
import GuiFrame from './frame.mjs';
|
||||
import {GuiImage} from './image.mjs';
|
||||
import GuiImage from './image.mjs';
|
||||
import GuiButton from './button.mjs';
|
||||
|
||||
export function root() {
|
||||
return new GuiFrame(0, 0, canvas.width, canvas.height, {
|
||||
|
@ -16,7 +17,18 @@ export function title() {
|
|||
shadow.append(logo);
|
||||
logo.scaleImage({ w: shadow.w * 0.7 });
|
||||
logo.posRelative({ x: 0.5, xc: 0.5, y: 0.2 });
|
||||
console.log(logo);
|
||||
|
||||
// TODO: Implement call to change view to game.
|
||||
let startFunction = () => {};
|
||||
let start = new GuiButton('Start game', startFunction, 0, 0, 200);
|
||||
shadow.append(start);
|
||||
start.posRelative({ x: 0.5, xc: 0.5, y: 0.7 });
|
||||
|
||||
let secondFunction = () => {};
|
||||
let second = new GuiButton('Don\'t start game', secondFunction, 0, 0, 200);
|
||||
shadow.append(second);
|
||||
second.posRelative({ x: 0.5, xc: 0.5, y: 0.7 });
|
||||
second.y += 60;
|
||||
|
||||
return shadow;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue