P5-1418. Remove 3D and Flat buttons when no frame is selected for canvas editor.
This commit is contained in:
@@ -69,6 +69,28 @@ function ButtonMenu(canvas, settings) {
|
|||||||
return _width;
|
return _width;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the button with id=buttonId to active/not active mode
|
||||||
|
*/
|
||||||
|
this.setButtonActive = function(buttonId, isActive) {
|
||||||
|
_textButtons.forEach(function (button) {
|
||||||
|
if (button.getId() === buttonId) {
|
||||||
|
button.setActive(isActive);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the button with id=buttonId to disabled/enabled mode
|
||||||
|
*/
|
||||||
|
this.setButtonDisabled = function(buttonId, isDisabled) {
|
||||||
|
_textButtons.forEach(function (button) {
|
||||||
|
if (button.getId() === buttonId) {
|
||||||
|
button.setDisabled(isDisabled);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hides the buttons
|
* Hides the buttons
|
||||||
*/
|
*/
|
||||||
@@ -76,7 +98,7 @@ function ButtonMenu(canvas, settings) {
|
|||||||
_textButtons.forEach(function(textButton) {
|
_textButtons.forEach(function(textButton) {
|
||||||
textButton.set({
|
textButton.set({
|
||||||
opacity: 0,
|
opacity: 0,
|
||||||
selectable: false
|
disabled: true
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -88,7 +110,7 @@ function ButtonMenu(canvas, settings) {
|
|||||||
_textButtons.forEach(function(textButton) {
|
_textButtons.forEach(function(textButton) {
|
||||||
textButton.set({
|
textButton.set({
|
||||||
opacity: 1,
|
opacity: 1,
|
||||||
selectable: true
|
disabled: false
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -216,12 +216,8 @@ var Canvas = fabric.util.createClass(fabric.Canvas, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
toggle3D: function (showAs3d) {
|
toggle3D: function (showAs3d) {
|
||||||
if (this.__type === 'canvas') {
|
|
||||||
this.getButtonMenu().getItems().forEach(function (button) {
|
this.getButtonMenu().setButtonActive('toggle3d', showAs3d);
|
||||||
var buttonState = button.getId() === '3d' ? showAs3d : !showAs3d;
|
|
||||||
button.setActive(buttonState);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!showAs3d) {
|
if (!showAs3d) {
|
||||||
return this.get3dHandler().disable();
|
return this.get3dHandler().disable();
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ var config = require('./config');
|
|||||||
|
|
||||||
function FrameHandler(viewport) {
|
function FrameHandler(viewport) {
|
||||||
var _frames;
|
var _frames;
|
||||||
var _frameType;
|
var _frameType = 'image';
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
initFrames();
|
initFrames();
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ function ImageEditor(canvasId, args) {
|
|||||||
type: 'wallpaper',
|
type: 'wallpaper',
|
||||||
// Default texts on the buttons
|
// Default texts on the buttons
|
||||||
buttons: {
|
buttons: {
|
||||||
flat: 'Flat',
|
showThreeD: '3d',
|
||||||
threeD: '3d',
|
hideThreeD: 'Flat',
|
||||||
showMurals: 'Show Murals Panel',
|
showMurals: 'Show Murals Panel',
|
||||||
hideMurals: 'Hide Murals Panel',
|
hideMurals: 'Hide Murals Panel',
|
||||||
showRulers: 'Show Ruler',
|
showRulers: 'Show Ruler',
|
||||||
@@ -36,13 +36,9 @@ function ImageEditor(canvasId, args) {
|
|||||||
// during the initialization of the image editor.
|
// during the initialization of the image editor.
|
||||||
if (_canvas.__type === 'canvas') {
|
if (_canvas.__type === 'canvas') {
|
||||||
_canvas.getButtonMenu()
|
_canvas.getButtonMenu()
|
||||||
.addItem('flat', _settings.buttons.flat, function () {
|
.addItem('toggle3d', [_settings.buttons.showThreeD, _settings.buttons.hideThreeD], function () {
|
||||||
_canvas.toggle3D(false);
|
_canvas.toggle3D(this.isActive());
|
||||||
}, true)
|
});
|
||||||
.addItem('3d', _settings.buttons.threeD, function () {
|
|
||||||
_canvas.toggle3D(true);
|
|
||||||
})
|
|
||||||
.render();
|
|
||||||
} else {
|
} else {
|
||||||
_canvas.getButtonMenu()
|
_canvas.getButtonMenu()
|
||||||
.addItem('toggleMurals', [_settings.buttons.showMurals, _settings.buttons.hideMurals], function () {
|
.addItem('toggleMurals', [_settings.buttons.showMurals, _settings.buttons.hideMurals], function () {
|
||||||
@@ -51,17 +47,17 @@ function ImageEditor(canvasId, args) {
|
|||||||
.addItem('toggleRulers', [_settings.buttons.showRulers, _settings.buttons.hideRulers], function () {
|
.addItem('toggleRulers', [_settings.buttons.showRulers, _settings.buttons.hideRulers], function () {
|
||||||
_canvas.getViewport().getRulers().enable(this.isActive());
|
_canvas.getViewport().getRulers().enable(this.isActive());
|
||||||
});
|
});
|
||||||
|
|
||||||
if (util.supportsFullscreen()) {
|
|
||||||
_canvas.getButtonMenu()
|
|
||||||
.addItem('toggleFullscreen', [_settings.buttons.showFullscreen, _settings.buttons.exitFullscreen], function () {
|
|
||||||
util.toggleFullscreen(_canvas.getSelectionElement().parentNode);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
_canvas.getButtonMenu().render();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (util.supportsFullscreen()) {
|
||||||
|
_canvas.getButtonMenu()
|
||||||
|
.addItem('toggleFullscreen', [_settings.buttons.showFullscreen, _settings.buttons.exitFullscreen], function () {
|
||||||
|
util.toggleFullscreen(_canvas.getSelectionElement().parentNode);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
_canvas.getButtonMenu().render();
|
||||||
|
|
||||||
// Binding fullscreen change event to the image-editor wrapper. This way we can set the correct button active.
|
// Binding fullscreen change event to the image-editor wrapper. This way we can set the correct button active.
|
||||||
$(_canvas.getSelectionElement().parentNode).bind('webkitfullscreenchange mozfullscreenchange fullscreenchange', function(e) {
|
$(_canvas.getSelectionElement().parentNode).bind('webkitfullscreenchange mozfullscreenchange fullscreenchange', function(e) {
|
||||||
var isFullscreen = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen;
|
var isFullscreen = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen;
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ function TextButton(id, text, settings, isActive) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Make sure we're interactive
|
// Make sure we're interactive
|
||||||
this.selectable = true;
|
this.disabled = false;
|
||||||
this.hoverCursor = config.textButton.cursor;
|
this.hoverCursor = config.textButton.cursor;
|
||||||
|
|
||||||
// Initialize text and rectangle
|
// Initialize text and rectangle
|
||||||
@@ -81,9 +81,9 @@ function TextButton(id, text, settings, isActive) {
|
|||||||
this.onClick = function(callback) {
|
this.onClick = function(callback) {
|
||||||
_callback = callback || function() {};
|
_callback = callback || function() {};
|
||||||
this.on('mousedown', function (e) {
|
this.on('mousedown', function (e) {
|
||||||
// As inactive buttons are still clickable, we first check if the button is 'selectable'.
|
// As inactive buttons are still clickable, we first check if the button is disabled.
|
||||||
// Only then we should do stuff.
|
// Only then we should do stuff.
|
||||||
if (this.selectable) {
|
if (!this.disabled) {
|
||||||
this.__active = !this.__active;
|
this.__active = !this.__active;
|
||||||
handleMouseDown.call(this, e);
|
handleMouseDown.call(this, e);
|
||||||
}
|
}
|
||||||
@@ -96,6 +96,14 @@ function TextButton(id, text, settings, isActive) {
|
|||||||
toggleActiveStyle.call(this);
|
toggleActiveStyle.call(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.setDisabled = function (isDisabled)
|
||||||
|
{
|
||||||
|
this.disabled = isDisabled;
|
||||||
|
|
||||||
|
_rect.setFill(_rectSettings[this.disabled ? 'disabledFill' : 'fill']);
|
||||||
|
_text.setFill(_textSettings[this.disabled ? 'disabledFill' : 'fill']);
|
||||||
|
};
|
||||||
|
|
||||||
if (_textSettings.text) {
|
if (_textSettings.text) {
|
||||||
this.setText(_textSettings.text);
|
this.setText(_textSettings.text);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ function Viewport(canvas) {
|
|||||||
if (canvas.__type !== 'canvas') {
|
if (canvas.__type !== 'canvas') {
|
||||||
drawBeams();
|
drawBeams();
|
||||||
} else {
|
} else {
|
||||||
self.setFrame();
|
self.setFrame(self.getFrameHandler().getFrameType());
|
||||||
}
|
}
|
||||||
|
|
||||||
canvas.getDragbars().apply();
|
canvas.getDragbars().apply();
|
||||||
@@ -162,6 +162,16 @@ function Viewport(canvas) {
|
|||||||
*/
|
*/
|
||||||
this.setFrame = function (frameType) {
|
this.setFrame = function (frameType) {
|
||||||
this.getFrameHandler().setFrames(frameType);
|
this.getFrameHandler().setFrames(frameType);
|
||||||
|
|
||||||
|
var buttons = canvas.getButtonMenu().getItems();
|
||||||
|
if (frameType === 'none') {
|
||||||
|
buttons[0].setDisabled(true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
buttons[0].setDisabled(false);
|
||||||
|
}
|
||||||
|
canvas.getButtonMenu().bringToFront();
|
||||||
|
|
||||||
canvas.refresh3dView();
|
canvas.refresh3dView();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -7,11 +7,12 @@ module.exports = {
|
|||||||
text: {
|
text: {
|
||||||
fill: '#ffffff',
|
fill: '#ffffff',
|
||||||
activeFill: '#ffffff',
|
activeFill: '#ffffff',
|
||||||
|
disabledFill: '#ffffff'
|
||||||
},
|
},
|
||||||
rect: {
|
rect: {
|
||||||
fill: '#343434',
|
fill: '#343434',
|
||||||
activeFill: '#494949',
|
activeFill: '#494949',
|
||||||
width: 100,
|
disabledFill: '#999999'
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -20,10 +21,12 @@ module.exports = {
|
|||||||
text: {
|
text: {
|
||||||
fill: '#ffffff',
|
fill: '#ffffff',
|
||||||
activeFill: '#ffffff',
|
activeFill: '#ffffff',
|
||||||
|
disabledFill: '#ffffff'
|
||||||
},
|
},
|
||||||
rect: {
|
rect: {
|
||||||
fill: '#343434',
|
fill: '#343434',
|
||||||
activeFill: '#494949',
|
activeFill: '#494949',
|
||||||
|
disabledFill: '#999999'
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ module.exports = {
|
|||||||
return {
|
return {
|
||||||
fill: '#343434',
|
fill: '#343434',
|
||||||
activeFill: '#494949',
|
activeFill: '#494949',
|
||||||
|
disabledFill: '#999999',
|
||||||
originX: 'center',
|
originX: 'center',
|
||||||
originY: 'center',
|
originY: 'center',
|
||||||
width: width || 1,
|
width: width || 1,
|
||||||
|
|||||||
+3
-3
@@ -104,9 +104,9 @@ var util = require('./includes/util');
|
|||||||
editor = new ImageEditor('canvas-editor', {
|
editor = new ImageEditor('canvas-editor', {
|
||||||
type: 'canvas',
|
type: 'canvas',
|
||||||
buttons: {
|
buttons: {
|
||||||
flat: 'Flat',
|
showThreeD: '3d',
|
||||||
threeD: '3D',
|
hideThreeD: 'Flat',
|
||||||
showMurals: 'Show Murals Panel',
|
showMurals: 'show-murals',
|
||||||
hideMurals: 'hide-murals',
|
hideMurals: 'hide-murals',
|
||||||
showRulers: 'show-rulers',
|
showRulers: 'show-rulers',
|
||||||
hideRulers: 'hide-rulers',
|
hideRulers: 'hide-rulers',
|
||||||
|
|||||||
Reference in New Issue
Block a user