Skip to content

Commit e357b03

Browse files
committed
Implement menu.
1 parent 241ccd9 commit e357b03

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

src/UI/Pointer.js

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,13 @@ var Pointer = function (ui, x, y, key, frame) {
5656

5757
this.lbl = this.ui.add.label(x + 20, y + 20, "").setFontStyle(PathBuilder.UI.fonts["Label"]);
5858

59-
//TODO: implement container
60-
this.linebutton = this.ui.add.text(x, y, "Line",null,null,null,this.switchdrawmode,["Line"],this).setFontStyle(PathBuilder.UI.fonts["Button"]);
61-
this.quadbutton = this.ui.add.text(x, y, "Quadratic",null,null,null,this.switchdrawmode,["QuadraticBezier"],this).setFontStyle(PathBuilder.UI.fonts["Button"]);
62-
this.cubicbutton = this.ui.add.text(x, y, "Cubic",null,null,null,this.switchdrawmode,["CubicBezier"],this).setFontStyle(PathBuilder.UI.fonts["Button"]);
63-
this.splinebutton = this.ui.add.text(x, y, "Spline",null,null,null,this.switchdrawmode,["Spline"],this).setFontStyle(PathBuilder.UI.fonts["Button"]);
64-
this.ellipsebutton = this.ui.add.text(x, y, "Ellipse",null,null,null,this.switchdrawmode,["Ellipse"],this).setFontStyle(PathBuilder.UI.fonts["Button"]);
59+
this.menu = this.ui.add.menu(x, y);
6560

66-
this.menu = [this.linebutton, this.quadbutton, this.cubicbutton, this.splinebutton, this.ellipsebutton ];
67-
68-
this.menu.forEach(function(element){ element.setVisible(false)});
61+
this.menu.add(-50, -50, "Line", this.switchdrawmode,["Line"],this);
62+
this.menu.add(0, -50, "Quadratic", this.switchdrawmode,["Quadratic"],this);
63+
this.menu.add(50, -50, "Cubic", this.switchdrawmode,["Cubic"],this);
64+
this.menu.add(-50, 50, "Spline", this.switchdrawmode,["Spline"],this);
65+
this.menu.add(0, 50, "Ellipse", this.switchdrawmode,["Ellipse"],this);
6966

7067
this.scene.events.on('switchmode', this.switchmode, this);
7168

@@ -85,22 +82,21 @@ Pointer.prototype.switchmode = function (mode) {
8582

8683
this.setVisible(true);
8784
this.lbl.setVisible(true);
88-
this.menu.forEach(function(element){ element.setVisible(false)});
85+
this.menu.hide();
86+
8987
}
9088
if (mode == "normal") {
9189

9290
this.setVisible(false);
93-
this.menu.forEach(function(element){ element.setVisible(false)});
91+
this.menu.hide();
92+
9493
}
9594
if (mode == "select"){
9695
this.setVisible(false);
97-
this.menu.forEach(function(element){ element.setVisible(true)});
98-
99-
this.linebutton.setPosition(this.x - 50, this.y - 50);
100-
this.quadbutton.setPosition(this.x , this.y - 50);
101-
this.cubicbutton.setPosition(this.x +50, this.y - 50);
102-
this.splinebutton.setPosition(this.x -50, this.y + 50);
103-
this.ellipsebutton.setPosition(this.x , this.y + 50);
96+
97+
this.menu.setPosition(this.x , this.y);
98+
this.menu.show();
99+
104100
}
105101
if(mode == "hand"){
106102
game.canvas.style.cursor = "grab";
@@ -117,7 +113,7 @@ Pointer.prototype.switchCursor = function(){
117113
Pointer.prototype.switchdrawmode = function (mode) {
118114
this.scene.drawmode = mode;
119115
this.scene.drawmodelabel.setText("curve: " + mode);
120-
this.menu.forEach(function(element){ element.setVisible(false)});
116+
this.menu.hide();
121117
this.scene.switchmode("draw");
122118
}
123119

src/UI/UI.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
var Menu = require("./Menu");
22
var Button = require("./Button");
33
var Point = require("./Point/Point");
44
var EndPoint = require("./Point/EndPoint");
@@ -11,6 +11,11 @@ var UI = function (scene) {
1111
this.elements = [];
1212

1313
this.add = {
14+
menu: function (x, y) {
15+
var m = new Menu(this.ui, x, y);
16+
this.ui.scene.add.existing(m);
17+
return m;
18+
},
1419
text: function (x, y, text, key, frame, target, callback, args, context) {
1520
var tb = new Button(this.ui, x, y, text, key, frame, target, callback, args, context);
1621
this.ui.scene.add.existing(tb);

0 commit comments

Comments
 (0)