////////////////////////////////////////////////////////////////////// // XLogical - A puzzle game // // Copyright (C) 2000 Neil Brown, Tom Warkentin // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // or at the website: http://www.gnu.org // //////////////////////////////////////////////////////////////////////// #include #include "audio.h" #include "graph.h" #include "exception.h" #include "gamelogic.h" #include "globals.h" #include "menuslider.h" #include "properties.h" #include "sound_files.h" #include "text.h" const float CMenuSlider::kSliderIncrement = 0.05; const int CMenuSlider::kSliderWidth = 128; const int CMenuSlider::kSliderHeight = 32; const int CMenuSlider::kThumbWidth = 8; const int CMenuSlider::kThumbHeight = 16; CMenuSlider::CMenuSlider( float aVal, const string &aString, const float aMax ) : fMax( aMax ), fValue( aVal ) { #if DEBUG & 1 cout << ">CMenuSlider::CMenuSlider()" << endl; #endif fMenuText.SetText( aString ); #if DEBUG & 1 cout << "CMenuSlider::~CMenuSlider()" << endl; #endif #if DEBUG & 1 cout << "CMenuSlider::Click()" << endl; cout << "aX=" << aX << " aY=" << aY << " aButton=" << aButton << endl; #endif float minX, maxX; // erase the old thumb graphDriver->graph_clear_rect( (int)(fX + fMenuText.Width() + graphDriver->graph_hi_font()->get_width() + ((fValue)/fMax * kSliderWidth) - kThumbWidth/2), fY + (Height() - kThumbHeight)/2, kThumbWidth, kThumbHeight ); minX = fX + fMenuText.Width() + graphDriver->graph_hi_font()->get_width(); maxX = minX + kSliderWidth; if ((aX >= minX) && (aX <= maxX)) { fValue = (aX - minX)/(maxX - minX) * fMax; Selected(); audioDriver->play_sound( soundFiles[SOUND_MENU_CLICK] ); } #if DEBUG & 1 cout << "CMenuSlider::Draw()" << endl; #endif int sliderXPM; int thumbXPM; // draw the text part fMenuText.Draw(); if (fHilighted) { sliderXPM = BMP_SLIDER; thumbXPM = BMP_SLIDER_THUMB; } else { sliderXPM = BMP_SLIDER; thumbXPM = BMP_SLIDER_THUMB; } // draw the slider and thumb parts graphDriver->graph_draw_pixmap( sliderXPM, 0, // srcX 0, // srcY fX + fMenuText.Width() + graphDriver->graph_hi_font()->get_width(), fY, kSliderWidth, kSliderHeight, USE_MASK ); graphDriver->graph_draw_pixmap( thumbXPM, 0, // srcX 0, // srcY (int)(fX + fMenuText.Width() + graphDriver->graph_hi_font()->get_width() + ((fValue)/fMax * kSliderWidth) - kThumbWidth/2), fY + (Height() - kThumbHeight)/2, kThumbWidth, kThumbHeight, USE_MASK ); #if DEBUG & 1 cout << "CMenuSlider::Keypress()" << endl; #endif // erase the old thumb graphDriver->graph_clear_rect( (int)(fX + fMenuText.Width() + graphDriver->graph_hi_font()->get_width() + ((fValue)/fMax * kSliderWidth) - kThumbWidth/2), fY + (Height() - kThumbHeight)/2, kThumbWidth, kThumbHeight ); switch( aKeyval ) { case eLeft: fValue -= kSliderIncrement * fMax; if (fValue < 0) { fValue = 0; } Selected(); audioDriver->play_sound( soundFiles[SOUND_MENU_CLICK] ); break; case eRight: fValue += kSliderIncrement * fMax; if (fValue > fMax) { fValue = fMax; } Selected(); audioDriver->play_sound( soundFiles[SOUND_MENU_CLICK] ); break; default: break; } #if DEBUG & 1 cout << "CMenuSlider::Manage()" << endl; #endif fMenuText.SetPos( fX, fY ); #if DEBUG & 1 cout << "CMenuSlider::Realize()" << endl; #endif // calculate dimensions of text part fMenuText.Realize(); // calculate size of slider and text part fHeight = fMenuText.Height(); fWidth = fMenuText.Width() + graphDriver->graph_hi_font()->get_width() + kSliderWidth; #if DEBUG & 1 cout << "CMenuSlider::Selected()" << endl; #endif #if DEBUG & 1 cout << "CMenuSlider::SetHiglighted()" << endl; #endif fMenuText.SetHilighted( aHilighted ); CMenuBase::SetHilighted( aHilighted ); #if DEBUG & 1 cout << "