Skip to content

Commit

Permalink
Replace audio backend in menu with audio device
Browse files Browse the repository at this point in the history
We currently only have one backend (OpenAL) and that is unlikely to
change soon.
  • Loading branch information
dscharrer committed Nov 6, 2014
1 parent 03fc8ee commit b86ef12
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 48 deletions.
27 changes: 19 additions & 8 deletions src/gui/MainMenu.cpp
Expand Up @@ -21,6 +21,9 @@

#include <iomanip>

#include <boost/foreach.hpp>

#include "audio/Audio.h"
#include "core/Application.h"
#include "core/Config.h"
#include "core/Core.h"
Expand Down Expand Up @@ -542,22 +545,30 @@ void MainMenuOptionAudioCreate(CWindowMenuConsole * console, Vec2i size)
{
// Audio backend selection
{

HorizontalPanelWidget * pc = new HorizontalPanelWidget;
std::string szMenuText = getLocalised("system_menus_options_audio_backend", "Backend");
std::string szMenuText = getLocalised("system_menus_options_audio_device", "Device");
szMenuText += " ";
TextWidget * me = new TextWidget(-1, hFontMenu, szMenuText, Vec2i(RATIO_X(20), 0), NOP);
me->SetCheckOff();
pc->AddElement(me);
CycleTextWidget * slider = new CycleTextWidget(BUTTON_MENUOPTIONSAUDIO_BACKEND);
CycleTextWidget * slider = new CycleTextWidget(BUTTON_MENUOPTIONSAUDIO_DEVICE);

slider->AddText(new TextWidget(-1, hFontMenu, "Auto-Select", Vec2i(0, 0), OPTIONS_AUDIO_BACKEND_AUTOMATIC));
int maxwidth = RATIO_X(size.x - 28) - me->rZone.width() - slider->rZone.width();

slider->AddText(new TextWidget(-1, hFontControls, "Default"));
slider->selectLast();
#if ARX_HAVE_OPENAL
slider->AddText(new TextWidget(-1, hFontMenu, "OpenAL", Vec2i(0, 0), OPTIONS_AUDIO_BACKEND_OPENAL));
if(config.audio.backend == "OpenAL") {
slider->selectLast();

BOOST_FOREACH(const std::string & device, audio::getDevices()) {
TextWidget * text = new TextWidget(-1, hFontControls, device);
if(text->rZone.width() > maxwidth) {
text->rZone.right = text->rZone.left + maxwidth;
}
slider->AddText(text);
if(config.audio.device == device) {
slider->selectLast();
}
}
#endif

float fRatio = (RATIO_X(size.x-9) - slider->rZone.width());
slider->Move(Vec2i(checked_range_cast<int>(fRatio), 0));
Expand Down
16 changes: 13 additions & 3 deletions src/gui/MenuPublic.cpp
Expand Up @@ -192,7 +192,20 @@ bool ARXMenu_Options_Audio_SetEAX(bool _bEnable) {

ARX_SOUND_SetReverb(config.audio.eax);

return config.audio.eax;
}


void ARXMenu_Options_Audio_SetDevice(std::string device) {

config.audio.device = device;

/*
* TODO This is ugly and doesn't save all currently playing samples - only looping ones,
* and those aren't restored at the same playback position. Ideally the audio subsystem
* should be able to switch backends internally.
*/

ARX_SOUND_PushAnimSamples();
size_t ulSizeAmbiancePlayList;
char * pAmbiancePlayList = ARX_SOUND_AmbianceSavePlayList(ulSizeAmbiancePlayList);
Expand All @@ -214,9 +227,6 @@ bool ARXMenu_Options_Audio_SetEAX(bool _bEnable) {
}

ARX_SOUND_PopAnimSamples();
*/

return config.audio.eax;
}

void ARXMenu_Options_Control_SetInvertMouse(bool enable) {
Expand Down
1 change: 1 addition & 0 deletions src/gui/MenuPublic.h
Expand Up @@ -54,6 +54,7 @@ void ARXMenu_Options_Video_SetDetailsQuality(int lod);

// Audio options

void ARXMenu_Options_Audio_SetDevice(std::string device);
void ARXMenu_Options_Audio_SetMasterVolume(int volume);
void ARXMenu_Options_Audio_SetSfxVolume(int volume);
void ARXMenu_Options_Audio_SetSpeechVolume(int volume);
Expand Down
61 changes: 27 additions & 34 deletions src/gui/MenuWidgets.cpp
Expand Up @@ -201,9 +201,9 @@ bool MENU_NoActiveWindow() {
return false;
}

void FontRenderText(Font* _pFont, Vec3f pos, const std::string& _pText, Color _c) {
if(pTextManage) {
pTextManage->AddText(_pFont, _pText, pos.x, pos.y, _c);
void FontRenderText(Font* _pFont, const Rect & rzone, const std::string& _pText, Color _c) {
if(pTextManage && !rzone.empty()) {
pTextManage->AddText(_pFont, _pText, rzone, _c);
}
}

Expand Down Expand Up @@ -1023,17 +1023,12 @@ void TextWidget::Render() {
if(bNoMenu)
return;

Vec3f ePos;
ePos.x = (float) rZone.left;
ePos.y = (float) rZone.top;
ePos.z = 1;

if(bSelected) {
FontRenderText(pFont, ePos, lpszText, lColorHighlight);
FontRenderText(pFont, rZone, lpszText, lColorHighlight);
} else if(enabled) {
FontRenderText(pFont, ePos, lpszText, lColor);
FontRenderText(pFont, rZone, lpszText, lColor);
} else {
FontRenderText(pFont, ePos, lpszText, Color::grayb(127));
FontRenderText(pFont, rZone, lpszText, Color::grayb(127));
}

}
Expand All @@ -1048,9 +1043,7 @@ void TextWidget::RenderMouseOver() {
GRenderer->SetRenderState(Renderer::AlphaBlending, true);
GRenderer->SetBlendFunc(Renderer::BlendOne, Renderer::BlendOne);

Vec3f ePos = Vec3f(Vec2f(rZone.topLeft()), 1.f);

FontRenderText(pFont, ePos, lpszText, lColorHighlight);
FontRenderText(pFont, rZone, lpszText, lColorHighlight);

GRenderer->SetRenderState(Renderer::AlphaBlending, false);

Expand Down Expand Up @@ -1083,10 +1076,6 @@ void TextWidget::RenderMouseOver() {
}
}

Vec2i TextWidget::GetTextSize() const {
return pFont->getTextSize(lpszText);
}

CMenuState::CMenuState()
: bReInitAll(false)
, eOldMenuState(NOP)
Expand Down Expand Up @@ -1370,9 +1359,9 @@ bool CheckboxWidget::OnMouseClick() {
break;
}
case BUTTON_MENUOPTIONSAUDIO_EAX: {
ARXMenu_Options_Audio_SetEAX((iState)?true:false);
}
ARXMenu_Options_Audio_SetEAX(iState != 0);
break;
}
case BUTTON_MENUOPTIONS_CONTROLS_INVERTMOUSE: {
ARXMenu_Options_Control_SetInvertMouse((iState)?true:false);
}
Expand Down Expand Up @@ -2455,25 +2444,27 @@ void CycleTextWidget::AddText(TextWidget *_pText) {
_pText->Move(Vec2i(rZone.left + pLeftButton->rZone.width(), rZone.top + 0));
vText.push_back(_pText);

Vec2i textSize = _pText->GetTextSize();
Vec2i textSize = _pText->rZone.size();

rZone.right = std::max(rZone.right, rZone.left + pLeftButton->rZone.width() + pRightButton->rZone.width() + textSize.x);
rZone.bottom = std::max(rZone.bottom, rZone.top + textSize.y);

pLeftButton->SetPos(Vec2i(rZone.left, rZone.top+(textSize.y>>2)));
pRightButton->SetPos(Vec2i(rZone.right-pRightButton->rZone.width(), rZone.top+(textSize.y>>2)));
pLeftButton->SetPos(Vec2i(rZone.left,
rZone.top + rZone.height() / 2 - pLeftButton->rZone.height() / 2));
pRightButton->SetPos(Vec2i(rZone.right - pRightButton->rZone.width(),
rZone.top + rZone.height() / 2 - pRightButton->rZone.height() / 2));

int dx=rZone.right-rZone.left-pLeftButton->rZone.width()-pRightButton->rZone.width();
int dx=rZone.width()-pLeftButton->rZone.width()-pRightButton->rZone.width();
//on recentre tout
std::vector<TextWidget*>::iterator it;

for(it = vText.begin(); it < vText.end(); ++it) {
TextWidget *pMenuElementText=*it;

textSize = pMenuElementText->GetTextSize();
textSize = pMenuElementText->rZone.size();

int dxx=(dx-textSize.x)>>1;
pMenuElementText->SetPos(Vec2i(pLeftButton->rZone.right + dxx, rZone.top));
pMenuElementText->SetPos(Vec2i(pLeftButton->rZone.right + dxx, rZone.top + rZone.height() / 2 - textSize.y/2));
}
}

Expand Down Expand Up @@ -2542,6 +2533,16 @@ bool CycleTextWidget::OnMouseClick() {
}

switch(iID) {

case BUTTON_MENUOPTIONSAUDIO_DEVICE: {
if(iPos == 0) {
ARXMenu_Options_Audio_SetDevice("auto");
} else {
ARXMenu_Options_Audio_SetDevice(vText.at(iPos)->lpszText);
}
break;
}

case BUTTON_MENUOPTIONSVIDEO_RESOLUTION: {
std::string pcText = (vText.at(iPos))->lpszText;

Expand All @@ -2566,14 +2567,6 @@ bool CycleTextWidget::OnMouseClick() {
}
break;
}
case BUTTON_MENUOPTIONSAUDIO_BACKEND: {
switch((vText.at(iPos))->eMenuState) {
case OPTIONS_AUDIO_BACKEND_OPENAL: config.audio.backend = "OpenAL"; break;
case OPTIONS_AUDIO_BACKEND_AUTOMATIC: config.audio.backend = "auto"; break;
default: break;
}
break;
}
// MENUOPTIONS_VIDEO
case BUTTON_MENUOPTIONSVIDEO_OTHERSDETAILS: {
ARXMenu_Options_Video_SetDetailsQuality(iPos);
Expand Down
4 changes: 1 addition & 3 deletions src/gui/MenuWidgets.h
Expand Up @@ -86,7 +86,7 @@ enum MenuButton {
BUTTON_MENUOPTIONSVIDEO_VSYNC,
BUTTON_MENUOPTIONSVIDEO_OTHERSDETAILS,

BUTTON_MENUOPTIONSAUDIO_BACKEND,
BUTTON_MENUOPTIONSAUDIO_DEVICE,
BUTTON_MENUOPTIONSAUDIO_MASTER,
BUTTON_MENUOPTIONSAUDIO_SFX,
BUTTON_MENUOPTIONSAUDIO_SPEECH,
Expand Down Expand Up @@ -355,8 +355,6 @@ class TextWidget: public Widget {
void SetText(const std::string & _pText);
void RenderMouseOver();

Vec2i GetTextSize() const;

bool OnMouseDoubleClick();
};

Expand Down

0 comments on commit b86ef12

Please sign in to comment.