Skip to content

Commit b86ef12

Browse files
committed
Replace audio backend in menu with audio device
We currently only have one backend (OpenAL) and that is unlikely to change soon.
1 parent 03fc8ee commit b86ef12

File tree

5 files changed

+61
-48
lines changed

5 files changed

+61
-48
lines changed

src/gui/MainMenu.cpp

+19-8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121

2222
#include <iomanip>
2323

24+
#include <boost/foreach.hpp>
25+
26+
#include "audio/Audio.h"
2427
#include "core/Application.h"
2528
#include "core/Config.h"
2629
#include "core/Core.h"
@@ -542,22 +545,30 @@ void MainMenuOptionAudioCreate(CWindowMenuConsole * console, Vec2i size)
542545
{
543546
// Audio backend selection
544547
{
548+
545549
HorizontalPanelWidget * pc = new HorizontalPanelWidget;
546-
std::string szMenuText = getLocalised("system_menus_options_audio_backend", "Backend");
550+
std::string szMenuText = getLocalised("system_menus_options_audio_device", "Device");
547551
szMenuText += " ";
548552
TextWidget * me = new TextWidget(-1, hFontMenu, szMenuText, Vec2i(RATIO_X(20), 0), NOP);
549553
me->SetCheckOff();
550554
pc->AddElement(me);
551-
CycleTextWidget * slider = new CycleTextWidget(BUTTON_MENUOPTIONSAUDIO_BACKEND);
555+
CycleTextWidget * slider = new CycleTextWidget(BUTTON_MENUOPTIONSAUDIO_DEVICE);
552556

553-
slider->AddText(new TextWidget(-1, hFontMenu, "Auto-Select", Vec2i(0, 0), OPTIONS_AUDIO_BACKEND_AUTOMATIC));
557+
int maxwidth = RATIO_X(size.x - 28) - me->rZone.width() - slider->rZone.width();
558+
559+
slider->AddText(new TextWidget(-1, hFontControls, "Default"));
554560
slider->selectLast();
555-
#if ARX_HAVE_OPENAL
556-
slider->AddText(new TextWidget(-1, hFontMenu, "OpenAL", Vec2i(0, 0), OPTIONS_AUDIO_BACKEND_OPENAL));
557-
if(config.audio.backend == "OpenAL") {
558-
slider->selectLast();
561+
562+
BOOST_FOREACH(const std::string & device, audio::getDevices()) {
563+
TextWidget * text = new TextWidget(-1, hFontControls, device);
564+
if(text->rZone.width() > maxwidth) {
565+
text->rZone.right = text->rZone.left + maxwidth;
566+
}
567+
slider->AddText(text);
568+
if(config.audio.device == device) {
569+
slider->selectLast();
570+
}
559571
}
560-
#endif
561572

562573
float fRatio = (RATIO_X(size.x-9) - slider->rZone.width());
563574
slider->Move(Vec2i(checked_range_cast<int>(fRatio), 0));

src/gui/MenuPublic.cpp

+13-3
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,20 @@ bool ARXMenu_Options_Audio_SetEAX(bool _bEnable) {
192192

193193
ARX_SOUND_SetReverb(config.audio.eax);
194194

195+
return config.audio.eax;
196+
}
197+
198+
199+
void ARXMenu_Options_Audio_SetDevice(std::string device) {
200+
201+
config.audio.device = device;
202+
195203
/*
204+
* TODO This is ugly and doesn't save all currently playing samples - only looping ones,
205+
* and those aren't restored at the same playback position. Ideally the audio subsystem
206+
* should be able to switch backends internally.
207+
*/
208+
196209
ARX_SOUND_PushAnimSamples();
197210
size_t ulSizeAmbiancePlayList;
198211
char * pAmbiancePlayList = ARX_SOUND_AmbianceSavePlayList(ulSizeAmbiancePlayList);
@@ -214,9 +227,6 @@ bool ARXMenu_Options_Audio_SetEAX(bool _bEnable) {
214227
}
215228

216229
ARX_SOUND_PopAnimSamples();
217-
*/
218-
219-
return config.audio.eax;
220230
}
221231

222232
void ARXMenu_Options_Control_SetInvertMouse(bool enable) {

src/gui/MenuPublic.h

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ void ARXMenu_Options_Video_SetDetailsQuality(int lod);
5454

5555
// Audio options
5656

57+
void ARXMenu_Options_Audio_SetDevice(std::string device);
5758
void ARXMenu_Options_Audio_SetMasterVolume(int volume);
5859
void ARXMenu_Options_Audio_SetSfxVolume(int volume);
5960
void ARXMenu_Options_Audio_SetSpeechVolume(int volume);

src/gui/MenuWidgets.cpp

+27-34
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,9 @@ bool MENU_NoActiveWindow() {
201201
return false;
202202
}
203203

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

@@ -1023,17 +1023,12 @@ void TextWidget::Render() {
10231023
if(bNoMenu)
10241024
return;
10251025

1026-
Vec3f ePos;
1027-
ePos.x = (float) rZone.left;
1028-
ePos.y = (float) rZone.top;
1029-
ePos.z = 1;
1030-
10311026
if(bSelected) {
1032-
FontRenderText(pFont, ePos, lpszText, lColorHighlight);
1027+
FontRenderText(pFont, rZone, lpszText, lColorHighlight);
10331028
} else if(enabled) {
1034-
FontRenderText(pFont, ePos, lpszText, lColor);
1029+
FontRenderText(pFont, rZone, lpszText, lColor);
10351030
} else {
1036-
FontRenderText(pFont, ePos, lpszText, Color::grayb(127));
1031+
FontRenderText(pFont, rZone, lpszText, Color::grayb(127));
10371032
}
10381033

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

1051-
Vec3f ePos = Vec3f(Vec2f(rZone.topLeft()), 1.f);
1052-
1053-
FontRenderText(pFont, ePos, lpszText, lColorHighlight);
1046+
FontRenderText(pFont, rZone, lpszText, lColorHighlight);
10541047

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

@@ -1083,10 +1076,6 @@ void TextWidget::RenderMouseOver() {
10831076
}
10841077
}
10851078

1086-
Vec2i TextWidget::GetTextSize() const {
1087-
return pFont->getTextSize(lpszText);
1088-
}
1089-
10901079
CMenuState::CMenuState()
10911080
: bReInitAll(false)
10921081
, eOldMenuState(NOP)
@@ -1370,9 +1359,9 @@ bool CheckboxWidget::OnMouseClick() {
13701359
break;
13711360
}
13721361
case BUTTON_MENUOPTIONSAUDIO_EAX: {
1373-
ARXMenu_Options_Audio_SetEAX((iState)?true:false);
1374-
}
1362+
ARXMenu_Options_Audio_SetEAX(iState != 0);
13751363
break;
1364+
}
13761365
case BUTTON_MENUOPTIONS_CONTROLS_INVERTMOUSE: {
13771366
ARXMenu_Options_Control_SetInvertMouse((iState)?true:false);
13781367
}
@@ -2455,25 +2444,27 @@ void CycleTextWidget::AddText(TextWidget *_pText) {
24552444
_pText->Move(Vec2i(rZone.left + pLeftButton->rZone.width(), rZone.top + 0));
24562445
vText.push_back(_pText);
24572446

2458-
Vec2i textSize = _pText->GetTextSize();
2447+
Vec2i textSize = _pText->rZone.size();
24592448

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

2463-
pLeftButton->SetPos(Vec2i(rZone.left, rZone.top+(textSize.y>>2)));
2464-
pRightButton->SetPos(Vec2i(rZone.right-pRightButton->rZone.width(), rZone.top+(textSize.y>>2)));
2452+
pLeftButton->SetPos(Vec2i(rZone.left,
2453+
rZone.top + rZone.height() / 2 - pLeftButton->rZone.height() / 2));
2454+
pRightButton->SetPos(Vec2i(rZone.right - pRightButton->rZone.width(),
2455+
rZone.top + rZone.height() / 2 - pRightButton->rZone.height() / 2));
24652456

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

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

2473-
textSize = pMenuElementText->GetTextSize();
2464+
textSize = pMenuElementText->rZone.size();
24742465

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

@@ -2542,6 +2533,16 @@ bool CycleTextWidget::OnMouseClick() {
25422533
}
25432534

25442535
switch(iID) {
2536+
2537+
case BUTTON_MENUOPTIONSAUDIO_DEVICE: {
2538+
if(iPos == 0) {
2539+
ARXMenu_Options_Audio_SetDevice("auto");
2540+
} else {
2541+
ARXMenu_Options_Audio_SetDevice(vText.at(iPos)->lpszText);
2542+
}
2543+
break;
2544+
}
2545+
25452546
case BUTTON_MENUOPTIONSVIDEO_RESOLUTION: {
25462547
std::string pcText = (vText.at(iPos))->lpszText;
25472548

@@ -2566,14 +2567,6 @@ bool CycleTextWidget::OnMouseClick() {
25662567
}
25672568
break;
25682569
}
2569-
case BUTTON_MENUOPTIONSAUDIO_BACKEND: {
2570-
switch((vText.at(iPos))->eMenuState) {
2571-
case OPTIONS_AUDIO_BACKEND_OPENAL: config.audio.backend = "OpenAL"; break;
2572-
case OPTIONS_AUDIO_BACKEND_AUTOMATIC: config.audio.backend = "auto"; break;
2573-
default: break;
2574-
}
2575-
break;
2576-
}
25772570
// MENUOPTIONS_VIDEO
25782571
case BUTTON_MENUOPTIONSVIDEO_OTHERSDETAILS: {
25792572
ARXMenu_Options_Video_SetDetailsQuality(iPos);

src/gui/MenuWidgets.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ enum MenuButton {
8686
BUTTON_MENUOPTIONSVIDEO_VSYNC,
8787
BUTTON_MENUOPTIONSVIDEO_OTHERSDETAILS,
8888

89-
BUTTON_MENUOPTIONSAUDIO_BACKEND,
89+
BUTTON_MENUOPTIONSAUDIO_DEVICE,
9090
BUTTON_MENUOPTIONSAUDIO_MASTER,
9191
BUTTON_MENUOPTIONSAUDIO_SFX,
9292
BUTTON_MENUOPTIONSAUDIO_SPEECH,
@@ -355,8 +355,6 @@ class TextWidget: public Widget {
355355
void SetText(const std::string & _pText);
356356
void RenderMouseOver();
357357

358-
Vec2i GetTextSize() const;
359-
360358
bool OnMouseDoubleClick();
361359
};
362360

0 commit comments

Comments
 (0)