mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 18:10:37 +02:00
extended toolBars.js
This commit is contained in:
parent
21c7a7c8a7
commit
18fdb340c1
1 changed files with 63 additions and 15 deletions
|
@ -61,11 +61,10 @@ Overlay2D = function(properties, overlay) { // overlay is an optionnal variable
|
||||||
}
|
}
|
||||||
|
|
||||||
this.clicked = function(clickedOverlay) {
|
this.clicked = function(clickedOverlay) {
|
||||||
return (overlay == clickedOverlay ? true : false);
|
return overlay === clickedOverlay;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.cleanup = function() {
|
this.cleanup = function() {
|
||||||
print("Cleanup");
|
|
||||||
Overlays.deleteOverlay(overlay);
|
Overlays.deleteOverlay(overlay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,9 +111,9 @@ Tool = function(properties, selectable, selected) { // selectable and selected a
|
||||||
this.select(selected);
|
this.select(selected);
|
||||||
|
|
||||||
this.baseClicked = this.clicked;
|
this.baseClicked = this.clicked;
|
||||||
this.clicked = function(clickedOverlay) {
|
this.clicked = function(clickedOverlay, update) {
|
||||||
if (this.baseClicked(clickedOverlay)) {
|
if (this.baseClicked(clickedOverlay)) {
|
||||||
if (selectable) {
|
if (selectable && update) {
|
||||||
this.toggle();
|
this.toggle();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -141,6 +140,7 @@ ToolBar = function(x, y, direction) {
|
||||||
alpha: 1.0,
|
alpha: 1.0,
|
||||||
visible: false
|
visible: false
|
||||||
});
|
});
|
||||||
|
this.spacing = [];
|
||||||
|
|
||||||
this.addTool = function(properties, selectable, selected) {
|
this.addTool = function(properties, selectable, selected) {
|
||||||
if (direction == ToolBar.HORIZONTAL) {
|
if (direction == ToolBar.HORIZONTAL) {
|
||||||
|
@ -154,10 +154,13 @@ ToolBar = function(x, y, direction) {
|
||||||
this.width = Math.max(properties.width, this.width);
|
this.width = Math.max(properties.width, this.width);
|
||||||
this.height += properties.height + ToolBar.SPACING;
|
this.height += properties.height + ToolBar.SPACING;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.back != null) {
|
if (this.back != null) {
|
||||||
Overlays.editOverlay(this.back, {
|
Overlays.editOverlay(this.back, {
|
||||||
width: this.width + 2 * ToolBar.SPACING,
|
width: this.width +
|
||||||
height: this.height + 2 * ToolBar.SPACING
|
((direction == ToolBar.HORIZONTAL) ? 1 : 2) * ToolBar.SPACING,
|
||||||
|
height: this.height +
|
||||||
|
((direction == ToolBar.VERTICAL) ? 1 : 2) * ToolBar.SPACING,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,6 +168,43 @@ ToolBar = function(x, y, direction) {
|
||||||
return ((this.tools.length) - 1);
|
return ((this.tools.length) - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.addSpacing = function(size) {
|
||||||
|
if (direction == ToolBar.HORIZONTAL) {
|
||||||
|
this.width += size;
|
||||||
|
} else {
|
||||||
|
this.height += size;
|
||||||
|
}
|
||||||
|
this.spacing[this.tools.length] = size;
|
||||||
|
|
||||||
|
return (this.tools.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.changeSpacing = function(size, id) {
|
||||||
|
if (this.spacing[id] === null) {
|
||||||
|
this.spacing[id] = 0;
|
||||||
|
}
|
||||||
|
var diff = size - this.spacing[id];
|
||||||
|
this.spacing[id] = size;
|
||||||
|
|
||||||
|
var dx = (direction == ToolBar.HORIZONTAL) ? diff : 0;
|
||||||
|
var dy = (direction == ToolBar.VERTICAL) ? diff : 0;
|
||||||
|
this.width += dx;
|
||||||
|
this.height += dy;
|
||||||
|
|
||||||
|
for(i = id; i < this.tools.length; i++) {
|
||||||
|
this.tools[i].move(this.tools[i].x() + dx,
|
||||||
|
this.tools[i].y() + dy);
|
||||||
|
}
|
||||||
|
if (this.back != null) {
|
||||||
|
Overlays.editOverlay(this.back, {
|
||||||
|
width: this.width +
|
||||||
|
((direction == ToolBar.HORIZONTAL) ? 1 : 2) * ToolBar.SPACING,
|
||||||
|
height: this.height +
|
||||||
|
((direction == ToolBar.VERTICAL) ? 1 : 2) * ToolBar.SPACING,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.removeLastTool = function() {
|
this.removeLastTool = function() {
|
||||||
this.tools.pop().cleanup();
|
this.tools.pop().cleanup();
|
||||||
|
|
||||||
|
@ -217,10 +257,14 @@ ToolBar = function(x, y, direction) {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
Overlays.editOverlay(this.back, {
|
Overlays.editOverlay(this.back, {
|
||||||
|
width: this.width +
|
||||||
|
((direction == ToolBar.HORIZONTAL) ? 1 : 2) * ToolBar.SPACING,
|
||||||
|
height: this.height +
|
||||||
|
((direction == ToolBar.VERTICAL) ? 1 : 2) * ToolBar.SPACING,
|
||||||
visible: true,
|
visible: true,
|
||||||
backgroundColor: color,
|
backgroundColor: color,
|
||||||
alpha: alpha
|
alpha: alpha
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,9 +277,13 @@ ToolBar = function(x, y, direction) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.clicked = function(clickedOverlay) {
|
this.clicked = function(clickedOverlay, update) {
|
||||||
|
if(typeof(update) === 'undefined') {
|
||||||
|
update = true;
|
||||||
|
}
|
||||||
|
|
||||||
for(var tool in this.tools) {
|
for(var tool in this.tools) {
|
||||||
if (this.tools[tool].visible() && this.tools[tool].clicked(clickedOverlay)) {
|
if (this.tools[tool].visible() && this.tools[tool].clicked(clickedOverlay, update)) {
|
||||||
return parseInt(tool);
|
return parseInt(tool);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue