From f267c27feb300319136e09234fd404df91bf8985 Mon Sep 17 00:00:00 2001 From: John Date: Sun, 3 Aug 2014 11:16:34 +0200 Subject: Update gui.js --- gui.js | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'gui.js') diff --git a/gui.js b/gui.js index 6af9137..1fe6047 100644 --- a/gui.js +++ b/gui.js @@ -212,6 +212,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; @@ -455,6 +456,7 @@ IDE_Morph.prototype.createControlBar = function () { stopButton, pauseButton, startButton, + muteSoundsButton, projectButton, settingsButton, stageSizeButton, @@ -544,6 +546,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, @@ -706,7 +740,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()); @@ -3369,6 +3403,17 @@ IDE_Morph.prototype.toggleStageSize = function (isSmall) { } }; +IDE_Morph.prototype.toggleMuteSounds = function (isMuted) { + this.isMuted = isNil(isMuted) ? !this.isMuted : isMuted; + this.controlBar.muteSoundsButton.refresh(); + + this.sprites.asArray().forEach(function (sprt) { + sprt.refreshVolumeOfAllActiveSounds(); + }); + this.stage.refreshVolumeOfAllActiveSounds(); + +}; + IDE_Morph.prototype.createNewProject = function () { var myself = this; this.confirm( -- cgit v1.3.1 From 51387ddfbc536c5ecc88658682f1894411f60631 Mon Sep 17 00:00:00 2001 From: Gubolin Date: Sun, 3 Aug 2014 12:15:15 +0200 Subject: adjust indentation --- blocks.js | 6 +++--- gui.js | 15 +++++++-------- 2 files changed, 10 insertions(+), 11 deletions(-) (limited to 'gui.js') diff --git a/blocks.js b/blocks.js index 9f9e505..bb1c898 100644 --- a/blocks.js +++ b/blocks.js @@ -7714,7 +7714,7 @@ SymbolMorph.prototype.names = [ 'pointRight', 'gears', 'file', - 'mutedSounds', + 'mutedSounds', 'unmutedSounds', 'fullScreen', 'normalScreen', @@ -7840,9 +7840,9 @@ SymbolMorph.prototype.symbolCanvasColored = function (aColor) { return this.drawSymbolGears(canvas, aColor); case 'file': return this.drawSymbolFile(canvas, aColor); - case 'mutedSounds': + case 'mutedSounds': return this.drawSymbolMutedSounds(canvas, aColor); - case 'unmutedSounds': + case 'unmutedSounds': return this.drawSymbolUnmutedSounds(canvas, aColor); case 'fullScreen': return this.drawSymbolFullScreen(canvas, aColor); diff --git a/gui.js b/gui.js index 1fe6047..38e70ac 100644 --- a/gui.js +++ b/gui.js @@ -212,7 +212,7 @@ IDE_Morph.prototype.init = function (isAutoFill) { this.corral = null; this.isAutoFill = isAutoFill || true; - this.isMuted = false; + this.isMuted = false; this.isAppMode = false; this.isSmallStage = false; this.filePicker = null; @@ -456,7 +456,7 @@ IDE_Morph.prototype.createControlBar = function () { stopButton, pauseButton, startButton, - muteSoundsButton, + muteSoundsButton, projectButton, settingsButton, stageSizeButton, @@ -546,7 +546,7 @@ IDE_Morph.prototype.createControlBar = function () { this.controlBar.add(appModeButton); this.controlBar.appModeButton = appModeButton; // for refreshing - //muteSoundsButton + //muteSoundsButton button = new ToggleButtonMorph( null, //colors, myself, // the IDE is the target @@ -3404,14 +3404,13 @@ IDE_Morph.prototype.toggleStageSize = function (isSmall) { }; IDE_Morph.prototype.toggleMuteSounds = function (isMuted) { - this.isMuted = isNil(isMuted) ? !this.isMuted : isMuted; - this.controlBar.muteSoundsButton.refresh(); + this.isMuted = isNil(isMuted) ? !this.isMuted : isMuted; + this.controlBar.muteSoundsButton.refresh(); this.sprites.asArray().forEach(function (sprt) { - sprt.refreshVolumeOfAllActiveSounds(); + sprt.refreshVolumeOfAllActiveSounds(); }); - this.stage.refreshVolumeOfAllActiveSounds(); - + this.stage.refreshVolumeOfAllActiveSounds(); }; IDE_Morph.prototype.createNewProject = function () { -- cgit v1.3.1 From b700eaa3f35b931445df06ba1ff952a709f82cc5 Mon Sep 17 00:00:00 2001 From: Gubolin Date: Sun, 3 Aug 2014 12:41:23 +0200 Subject: add mute functions --- gui.js | 19 +++++++++++++++---- objects.js | 23 +++++++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) (limited to 'gui.js') diff --git a/gui.js b/gui.js index 38e70ac..28549df 100644 --- a/gui.js +++ b/gui.js @@ -3407,10 +3407,21 @@ IDE_Morph.prototype.toggleMuteSounds = function (isMuted) { this.isMuted = isNil(isMuted) ? !this.isMuted : isMuted; this.controlBar.muteSoundsButton.refresh(); - this.sprites.asArray().forEach(function (sprt) { - sprt.refreshVolumeOfAllActiveSounds(); - }); - this.stage.refreshVolumeOfAllActiveSounds(); + /* 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.createNewProject = function () { diff --git a/objects.js b/objects.js index fda06f6..c8147d9 100644 --- a/objects.js +++ b/objects.js @@ -2619,6 +2619,10 @@ SpriteMorph.prototype.playSound = function (name) { sound.volume = this.volume; active = sound.play(); + if (stage.muted === true) { + active.volume = 0; + } + this.activeSounds.push(active); this.activeSounds = this.activeSounds.filter(function (aud) { return !aud.ended && !aud.terminated; @@ -2651,6 +2655,13 @@ SpriteMorph.prototype.reportVolume = function () { return this.volume; } +SpriteMorph.prototype.unmuteAllSounds = function () { + var stage = this.parentThatIsA(StageMorph); + stage.muted = false; + + this.doSetVolume(this.volume); +}; + SpriteMorph.prototype.reportSounds = function () { return this.sounds; }; @@ -4293,6 +4304,7 @@ StageMorph.prototype.init = function (globals) { this.isFastTracked = false; this.cloneCount = 0; this.volume = 100; + this.muted = false; this.timerStart = Date.now(); this.tempo = 60; // bpm @@ -5507,6 +5519,17 @@ StageMorph.prototype.resumeAllActiveSounds = function () { }); }; +StageMorph.prototype.muteAllSounds = function () { + this.muted = true; + + this.activeSounds.forEach(function (audio) { + audio.volume = 0; + }); +}; + +StageMorph.prototype.unmuteAllSounds + = SpriteMorph.prototype.unmuteAllSounds; + StageMorph.prototype.reportSounds = SpriteMorph.prototype.reportSounds; -- cgit v1.3.1