soundtest.cc

Go to the documentation of this file.
00001 /*
00002  *  This program is free software; you can redistribute it and/or modify
00003  *  it under the terms of the GNU General Public License as published by
00004  *  the Free Software Foundation; either version 2 of the License, or
00005  *  (at your option) any later version.
00006  *
00007  *  This program is distributed in the hope that it will be useful,
00008  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00009  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010  *  GNU General Public License for more details.
00011  *
00012  *  You should have received a copy of the GNU General Public License
00013  *  along with this program; if not, write to the Free Software
00014  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00015  */
00016  
00017 #ifdef HAVE_CONFIG_H
00018 #  include <config.h>
00019 #endif
00020 
00021 #include "SDL_events.h"
00022 #include "gamewin.h"
00023 #include "Audio.h"
00024 #include "soundtest.h"
00025 #include "Scroll_gump.h"
00026 #include "mouse.h"
00027 #include "exult.h"
00028 #include "font.h"
00029 #include "tqueue.h"
00030 
00031 SoundTester::SoundTester() : song(0), sfx(0), voice(0), active(0), repeat(true)
00032   {
00033   }
00034 
00035 SoundTester::~SoundTester()
00036   {
00037   }
00038 
00039 void SoundTester::test_sound()
00040 {
00041     
00042   Game_window *gwin = Game_window::get_instance();
00043   Image_buffer8 *ibuf = gwin->get_win()->get_ib8();
00044   Font *font = Shape_manager::get_instance()->get_font(4);
00045 
00046   Audio *audio = Audio::get_ptr();
00047   Scroll_gump *scroll = NULL;
00048 
00049   char buf[256];
00050   bool looping = true;
00051   bool redraw = true;
00052   SDL_Event event;
00053 
00054   int centerx = gwin->get_width()/2;
00055   int centery = gwin->get_height()/2;
00056   int left = centerx - 65;
00057   int first_line = centery-53;
00058   int line;
00059   int height = 6;
00060   int width = 6;
00061   
00062   Mouse::mouse->hide();
00063 
00064   gwin->get_tqueue()->pause(SDL_GetTicks());
00065 
00066   do
00067   {
00068     if (redraw)
00069     {
00070          
00071       scroll = new Scroll_gump();
00072       scroll->add_text(" ~");
00073       scroll->paint();
00074 
00075       line = first_line;
00076       font->paint_text_fixedwidth(ibuf, "Sound Tester", left, line, width);
00077       line += height;
00078       font->paint_text_fixedwidth(ibuf, "------------", left, line, width);
00079 
00080       line += height*2;
00081       font->paint_text_fixedwidth(ibuf, "   Up - Previous Type", left, line, width);
00082       
00083       line += height;
00084       font->paint_text_fixedwidth(ibuf, " Down - Next Type", left, line, width);
00085       
00086       line += height;
00087       font->paint_text_fixedwidth(ibuf, " Left - Previous Number", left, line, width);
00088       
00089       line += height;
00090       font->paint_text_fixedwidth(ibuf, "Right - Next Number", left, line, width);
00091 
00092       line += height;
00093       font->paint_text_fixedwidth(ibuf, "Enter - Play it", left, line, width);
00094 
00095       line += height;
00096       font->paint_text_fixedwidth(ibuf, "  ESC - Leave", left, line, width);
00097 
00098       line += height;
00099       font->paint_text_fixedwidth(ibuf, "    R - Repeat Music", left, line, width);
00100 
00101       line += height;
00102       font->paint_text_fixedwidth(ibuf, "    S - Stop Music", left, line, width);
00103 
00104 
00105       snprintf (buf, 256, "%2s Music %c %3i %c %s",
00106           active==0?"->":"",
00107           active==0?'<':' ',
00108           song,
00109           active==0?'>':' ',
00110           repeat?"- Repeat":"");
00111       line += height*2;
00112       font->paint_text_fixedwidth(ibuf, buf, left, line, width);
00113       
00114       
00115       snprintf (buf, 256, "%2s SFX   %c %3i %c",
00116           active==1?"->":"",
00117             active==1?'<':' ',
00118           sfx,
00119           active==1?'>':' ');
00120 
00121       line += height*2;
00122       font->paint_text_fixedwidth(ibuf, buf, left, line, width);
00123 
00124 
00125       snprintf (buf, 256, "%2s Voice %c %3i %c",
00126           active==2?"->":"",
00127           active==2?'<':' ',
00128           voice,
00129           active==2?'>':' ');
00130 
00131       line += height*2;
00132       font->paint_text_fixedwidth(ibuf, buf, left, line, width);
00133 
00134       gwin->show();
00135       delete scroll;
00136       redraw = false;
00137     }
00138       SDL_WaitEvent(&event);
00139     if(event.type==SDL_KEYDOWN)
00140     {
00141             redraw = true;
00142       switch(event.key.keysym.sym)
00143       {
00144 
00145       case SDLK_ESCAPE:
00146         looping = false;
00147         break;
00148 
00149       case SDLK_RETURN:
00150         if (active == 0)
00151         {
00152           audio->stop_music();
00153           audio->start_music (song, repeat, 0);
00154         }
00155         else if (active == 1)
00156         {
00157           audio->play_sound_effect (sfx);
00158         }
00159         else if (active == 2)
00160         {
00161           audio->cancel_streams();
00162           audio->start_speech (voice, false);
00163         }
00164         break;
00165         
00166       case SDLK_r:
00167         repeat = repeat?false:true;
00168         break;
00169       case SDLK_s:
00170         if ((event.key.keysym.mod & KMOD_ALT) && (event.key.keysym.mod & KMOD_CTRL)) 
00171           make_screenshot(true);
00172         else
00173           audio->stop_music();
00174         break;
00175       case SDLK_UP:
00176         active = (active + 2) % 3;
00177         break;
00178       case SDLK_DOWN:
00179         active = (active + 1) % 3;
00180         break;
00181       case SDLK_LEFT:
00182         if (active == 0)
00183         {
00184           song--;
00185           if (song < 0) song = 255;
00186         }
00187         else if (active == 1)
00188         {
00189           sfx--;
00190           if (sfx < 0) sfx = 255;
00191         }
00192         else if (active == 2)
00193         {
00194           voice--;
00195           if (voice < 0) voice = 255;
00196         }
00197         break;
00198       case SDLK_RIGHT:
00199         if (active == 0)
00200         {
00201           song++;
00202           if (song > 255) song = 0;
00203         }
00204         else if (active == 1)
00205         {
00206           sfx++;
00207           if (sfx > 255) sfx = 0;
00208         }
00209         else if (active == 2)
00210         {
00211           voice++;
00212           if (voice > 255) voice = 0;
00213         }
00214         break;
00215       default:
00216         break;
00217       }
00218     }
00219   } while(looping);
00220 
00221   gwin->get_tqueue()->resume(SDL_GetTicks());
00222   
00223   gwin->paint();
00224   Mouse::mouse->show();
00225   gwin->show();
00226 }

Generated on Mon Jul 9 14:42:42 2007 for ExultEngine by  doxygen 1.5.1