# HG changeset patch # User koda # Date 1333901497 -7200 # Node ID 87e060b69926a85483bd9799c88b24cf2718d9fb # Parent 7a571b8caaee6aa683a8f5538b5f0dc633f87891 when focus is lost lower the volume to a minimum diff -r 7a571b8caaee -r 87e060b69926 hedgewars/uSound.pas --- a/hedgewars/uSound.pas Sat Apr 07 22:13:15 2012 +0200 +++ b/hedgewars/uSound.pas Sun Apr 08 18:11:37 2012 +0200 @@ -36,6 +36,7 @@ uses SDLh, uConsts, uTypes, sysutils; var MusicFN: shortstring; // music file name + previousVolume: LongInt; // cached volume value procedure initModule; procedure freeModule; @@ -90,6 +91,9 @@ // Returns a pointer to the voicepack with the given name. function AskForVoicepack(name: shortstring): Pointer; +// Drastically lower the volume when we lose focus (and restore the previous value) +procedure DampenAudio; +procedure UndampenAudio; implementation uses uVariables, uConsole, uUtils, uCommands, uDebug; @@ -477,6 +481,17 @@ ChangeVolume:= Volume * 100 div MIX_MAX_VOLUME end; +procedure DampenAudio; +begin +previousVolume:= Volume; +ChangeVolume(-Volume * 7 div 9); +end; + +procedure UndampenAudio; +begin +ChangeVolume(previousVolume - Volume); +end; + procedure PauseMusic; begin if (MusicFN = '') or (not isMusicEnabled) then diff -r 7a571b8caaee -r 87e060b69926 hedgewars/uWorld.pas --- a/hedgewars/uWorld.pas Sat Apr 07 22:13:15 2012 +0200 +++ b/hedgewars/uWorld.pas Sun Apr 08 18:11:37 2012 +0200 @@ -1712,6 +1712,9 @@ begin if (not cHasFocus) and (GameState <> gsConfirm) then ParseCommand('quit', true); + +if not cHasFocus then DampenAudio() +else UndampenAudio(); end; procedure animateWidget(widget: POnScreenWidget; fade, showWidget: boolean);