using namespace Sexy;
OptionsDialog::OptionsDialog() : Dialog(IMAGE_OPTIONS_DIALOG,
IMAGE_OPTIONS_DIALOG_BUTTON,
OptionsDialog::DialogId,
true,
"Options",
"",
"Close",
Dialog::BUTTONS_FOOTER)
{
unsigned int X, Y, W, H;
SetHeaderFont(FONT_MONO14);
SetLinesFont(FONT_MONO12);
SetButtonFont(FONT_MONO12);
mMusicVolume = new Slider(IMAGE_SLIDER, IMAGE_SLIDER_THUMB, OptionsDialog::MusicSliderId, this);
mSoundVolume = new Slider(IMAGE_SLIDER, IMAGE_SLIDER_THUMB, OptionsDialog::SoundSliderId, this);
mHardware = new Checkbox(IMAGE_CHECKBOX, IMAGE_CHECKBOX, OptionsDialog::HardwareCheckboxId, this);
mFullscreen = new Checkbox(IMAGE_CHECKBOX, IMAGE_CHECKBOX, OptionsDialog::HardwareCheckboxId, this);
mWidth = OptionsDialog::Width;
mHeight = OptionsDialog::Height;
X = (mWidth - (mWidth * .8)) / 2;
Y = TitleBarHeight + FONT_MONO12->GetHeight() + 5;
W = mWidth * .8;
H = TitleBarHeight;
mMusicVolume->Resize(X, Y, W, H);
Y += IMAGE_SLIDER->GetHeight() + FONT_MONO12->GetHeight() * 2;
mSoundVolume->Resize(X, Y, W, H);
X = mWidth * .7;
Y += IMAGE_SLIDER->GetHeight() + FONT_MONO12->GetHeight() * 2 - IMAGE_CHECKBOX->GetHeight() / 2;
W = IMAGE_CHECKBOX->GetWidth() / 2;
H = IMAGE_CHECKBOX->GetHeight();
mFullscreen->mUncheckedRect = Rect(0, 0, W, H);
mFullscreen->mCheckedRect = Rect(W, 0, W, H);
mFullscreen->Resize(X, Y, W, H);
Y += IMAGE_CHECKBOX->GetHeight() * 2;
mHardware->mUncheckedRect = Rect(0, 0, W, H);
mHardware->mCheckedRect = Rect(W, 0, W, H);
mHardware->Resize(X, Y, W, H);
mMusicVolume->SetValue(gSexyAppBase->GetMusicVolume());
mSoundVolume->SetValue(gSexyAppBase->GetSfxVolume());
mHardware->mChecked = gSexyAppBase->Is3DAccelerated();
mFullscreen->mChecked = !gSexyAppBase->mIsWindowed;
AddWidget(mMusicVolume);
AddWidget(mSoundVolume);
AddWidget(mHardware);
AddWidget(mFullscreen);
}
OptionsDialog::~OptionsDialog()
{
RemoveAllWidgets();
delete mMusicVolume;
delete mSoundVolume;
delete mHardware;
delete mFullscreen;
}
void OptionsDialog::Draw(Sexy::Graphics* g)
{
unsigned int X = 0, Y = 0;
Dialog::Draw(g);
g->SetColor(Color(255, 255, 255, 255));
g->SetFont(FONT_MONO12);
X = 0;
Y = TitleBarHeight + FONT_MONO12->GetHeight() + 5;
WriteString(g, "Music volume", X, Y, mWidth, 0);
Y += IMAGE_SLIDER->GetHeight() + FONT_MONO12->GetHeight() * 2;
WriteString(g, "Sound volume", X, Y, mWidth, 0);
X = mWidth * .2;
Y += IMAGE_SLIDER->GetHeight() + FONT_MONO12->GetHeight() * 2 + IMAGE_CHECKBOX->GetHeight() / 2;
WriteString(g, "Fullscreen:", X, Y, mWidth);
Y += IMAGE_CHECKBOX->GetHeight() * 2;
WriteString(g, "HW Accel:", X, Y, mWidth);
}
void OptionsDialog::SliderVal(int theId, double theVal)
{
switch (theId)
{
case MusicSliderId:
gSexyAppBase->SetMusicVolume(theVal);
break;
case SoundSliderId:
gSexyAppBase->SetSfxVolume(theVal);
break;
}
}
void OptionsDialog::ButtonDepress(int theId)
{
Dialog::ButtonDepress(theId);
if (theId == ID_YES)
{
gSexyAppBase->SwitchScreenMode(!mFullscreen->mChecked, mHardware->mChecked);
mResult = 0;
//gSexyAppBase->KillDialog(this);
}
}
void OptionsDialog::CheckboxChecked(int theId, bool Checked)
{
switch (theId)
{
case HardwareCheckboxId:
if (Checked)
{
if (!gSexyAppBase->Is3DAccelerationSupported())
{
mHardware->SetChecked(false);
}
}
break;
case FullScreenCheckboxId:
if (gSexyAppBase->mForceFullscreen && !Checked)
{
mFullscreen->mChecked = true;
}
break;
}
}