Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add volume block. #23

Merged
merged 2 commits into from
Sep 30, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -7592,6 +7592,8 @@ SymbolMorph.prototype.names = [
'pointRight',
'gears',
'file',
'mutedSounds',
'unmutedSounds',
'fullScreen',
'normalScreen',
'smallStage',
Expand Down Expand Up @@ -7716,6 +7718,10 @@ SymbolMorph.prototype.symbolCanvasColored = function (aColor) {
return this.drawSymbolGears(canvas, aColor);
case 'file':
return this.drawSymbolFile(canvas, aColor);
case 'mutedSounds':
return this.drawSymbolMutedSounds(canvas, aColor);
case 'unmutedSounds':
return this.drawSymbolUnmutedSounds(canvas, aColor);
case 'fullScreen':
return this.drawSymbolFullScreen(canvas, aColor);
case 'normalScreen':
Expand Down Expand Up @@ -7918,6 +7924,34 @@ SymbolMorph.prototype.drawSymbolFile = function (canvas, color) {
return canvas;
};

SymbolMorph.prototype.drawSymbolMutedSounds = function (canvas, color) {
// answer a canvas showing a muted sounds toggling symbol
var ctx = canvas.getContext('2d'),
w = canvas.width,
h = canvas.height,
w2 = w / 2,
h2 = h / 2;

ctx.fillStyle = color.darker(40).toString();
ctx.fillRect(0, 0, w, h);

return canvas;
};

SymbolMorph.prototype.drawSymbolUnmutedSounds = function (canvas, color) {
// answer a canvas showing a UNmuted sounds toggling symbol
var ctx = canvas.getContext('2d'),
w = canvas.width,
h = canvas.height,
w2 = w / 2,
h2 = h / 2;

ctx.fillStyle = color.darker(60).toString();
ctx.fillRect(0, 0, w, h);

return canvas;
};

SymbolMorph.prototype.drawSymbolFullScreen = function (canvas, color) {
// answer a canvas showing two arrows pointing diagonally outwards
var ctx = canvas.getContext('2d'),
Expand Down
57 changes: 56 additions & 1 deletion gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ IDE_Morph.prototype.init = function (isAutoFill) {
this.corral = null;

this.isAutoFill = isAutoFill || true;
this.isMuted = false;
this.isAppMode = false;
this.isSmallStage = false;
this.filePicker = null;
Expand Down Expand Up @@ -526,6 +527,7 @@ IDE_Morph.prototype.createControlBar = function () {
stopButton,
pauseButton,
startButton,
muteSoundsButton,
projectButton,
settingsButton,
goalImagesButton,
Expand Down Expand Up @@ -617,6 +619,38 @@ IDE_Morph.prototype.createControlBar = function () {
{ this.controlBar.add(appModeButton); }
this.controlBar.appModeButton = appModeButton; // for refreshing

//muteSoundsButton
button = new ToggleButtonMorph(
null, //colors,
myself, // the IDE is the target
'toggleMuteSounds',
[
new SymbolMorph('mutedSounds', 14),
new SymbolMorph('unmutedSounds', 14)
],
function () { // query
return myself.isMuted;
}
);

button.corner = 12;
button.color = colors[0];
button.highlightColor = colors[1];
button.pressColor = colors[2];
button.labelMinExtent = new Point(36, 18);
button.padding = 0;
button.labelShadowOffset = new Point(-1, -1);
button.labelShadowColor = colors[1];
button.labelColor = this.buttonLabelColor;
button.contrast = this.buttonContrast;
button.drawNew();
// button.hint = 'sounds\nmuted & unmuted';
button.fixLayout();
button.refresh();
muteSoundsButton = button;
this.controlBar.add(muteSoundsButton);
this.controlBar.muteSoundsButton = button; // for refreshing

// stopButton
button = new PushButtonMorph(
this,
Expand Down Expand Up @@ -800,7 +834,7 @@ IDE_Morph.prototype.createControlBar = function () {
x = myself.right() - (StageMorph.prototype.dimensions.x
* (myself.isSmallStage ? myself.stageRatio : 1));

[stageSizeButton, appModeButton].forEach(
[stageSizeButton, appModeButton, muteSoundsButton].forEach(
function (button) {
x += padding;
button.setCenter(myself.controlBar.center());
Expand Down Expand Up @@ -3481,6 +3515,27 @@ IDE_Morph.prototype.toggleStageSize = function (isSmall) {
}
};

IDE_Morph.prototype.toggleMuteSounds = function (isMuted) {
this.isMuted = isNil(isMuted) ? !this.isMuted : isMuted;
this.controlBar.muteSoundsButton.refresh();

/* stage.activeSounds holds all active sounds
* a sprite's .activeSounds holds just its own
* so you have to use the stage to mute
* and the sprite to unmute, because the stage's volume
* overrides the sprite's one.
*/

if (this.isMuted === false) {
this.stage.unmuteAllSounds();
this.sprites.asArray().forEach(function (sprt) {
sprt.unmuteAllSounds();
});
} else {
this.stage.muteAllSounds();
}
};

IDE_Morph.prototype.openProjectsBrowser = function () {
new ProjectDialogMorph(this, 'open').popUp();
};
Expand Down
Loading