1 /*
2  *  This program is free software; you can redistribute it and/or modify
3  *  it under the terms of the GNU General Public License as published by
4  *  the Free Software Foundation; either version 2 of the License, or
5  *  (at your option) any later version.
6  *
7  *  This program is distributed in the hope that it will be useful,
8  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *  GNU General Public License for more details.
11  *
12  *  You should have received a copy of the GNU General Public License
13  *  along with this program; if not, write to the Free Software
14  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  */
16 
17 #ifdef HAVE_CONFIG_H
18 #  include <config.h>
19 #endif
20 
21 #include "SDL_events.h"
22 #include "gamewin.h"
23 #include "Audio.h"
24 #include "soundtest.h"
25 #include "Scroll_gump.h"
26 #include "mouse.h"
27 #include "exult.h"
28 #include "font.h"
29 #include "tqueue.h"
30 
test_sound()31 void SoundTester::test_sound()
32 {
33 	Game_window *gwin = Game_window::get_instance();
34 	Image_buffer8 *ibuf = gwin->get_win()->get_ib8();
35 	Font *font = Shape_manager::get_instance()->get_font(4);
36 
37 	Audio *audio = Audio::get_ptr();
38 
39 	char buf[256];
40 	bool looping = true;
41 	bool redraw = true;
42 	SDL_Event event;
43 
44 	int centerx = gwin->get_width()/2;
45 	int centery = gwin->get_height()/2;
46 	int left = centerx - 65;
47 	int first_line = centery-53;
48 	int line;
49 	int height = 6;
50 	int width = 6;
51 
52 	Mouse::mouse->hide();
53 
54 	gwin->get_tqueue()->pause(SDL_GetTicks());
55 
56 	do
57 	{
58 		if (redraw)
59 		{
60 			Scroll_gump scroll;
61 			scroll.add_text(" ~");
62 			scroll.paint();
63 
64 			line = first_line;
65 			font->paint_text_fixedwidth(ibuf, "Sound Tester", left, line, width);
66 			line += height;
67 			font->paint_text_fixedwidth(ibuf, "------------", left, line, width);
68 
69 			line += height*2;
70 			font->paint_text_fixedwidth(ibuf, "   Up - Previous Type", left, line, width);
71 
72 			line += height;
73 			font->paint_text_fixedwidth(ibuf, " Down - Next Type", left, line, width);
74 
75 			line += height;
76 			font->paint_text_fixedwidth(ibuf, " Left - Previous Number", left, line, width);
77 
78 			line += height;
79 			font->paint_text_fixedwidth(ibuf, "Right - Next Number", left, line, width);
80 
81 			line += height;
82 			font->paint_text_fixedwidth(ibuf, "Enter - Play it", left, line, width);
83 
84 			line += height;
85 			font->paint_text_fixedwidth(ibuf, "  ESC - Leave", left, line, width);
86 
87 			line += height;
88 			font->paint_text_fixedwidth(ibuf, "    R - Repeat Music", left, line, width);
89 
90 			line += height;
91 			font->paint_text_fixedwidth(ibuf, "    S - Stop Music", left, line, width);
92 
93 
94 			snprintf (buf, 256, "%2s Music %c %3i %c %s",
95 					active==0?"->":"",
96 					active==0?'<':' ',
97 					song,
98 					active==0?'>':' ',
99 					repeat?"- Repeat":"");
100 			line += height*2;
101 			font->paint_text_fixedwidth(ibuf, buf, left, line, width);
102 
103 
104 			snprintf (buf, 256, "%2s SFX   %c %3i %c",
105 					active==1?"->":"",
106 						active==1?'<':' ',
107 					sfx,
108 					active==1?'>':' ');
109 
110 			line += height*2;
111 			font->paint_text_fixedwidth(ibuf, buf, left, line, width);
112 
113 
114 			snprintf (buf, 256, "%2s Voice %c %3i %c",
115 					active==2?"->":"",
116 					active==2?'<':' ',
117 					voice,
118 					active==2?'>':' ');
119 
120 			line += height*2;
121 			font->paint_text_fixedwidth(ibuf, buf, left, line, width);
122 
123 			gwin->show();
124 			redraw = false;
125 		}
126 		SDL_WaitEvent(&event);
127 		if(event.type==SDL_KEYDOWN)
128 		{
129 			redraw = true;
130 			switch(event.key.keysym.sym)
131 			{
132 
133 			case SDLK_ESCAPE:
134 				looping = false;
135 				break;
136 
137 			case SDLK_RETURN:
138 			case SDLK_KP_ENTER:
139 				if (active == 0)
140 				{
141 					audio->stop_music();
142 					audio->start_music (song, repeat);
143 				}
144 				else if (active == 1)
145 				{
146 					audio->play_sound_effect (sfx);
147 				}
148 				else if (active == 2)
149 				{
150 					audio->cancel_streams();
151 					audio->start_speech (voice, false);
152 				}
153 				break;
154 
155 			case SDLK_r:
156 				repeat = !repeat;
157 				break;
158 			case SDLK_s:
159 				if ((event.key.keysym.mod & KMOD_ALT) && (event.key.keysym.mod & KMOD_CTRL))
160 					make_screenshot(true);
161 				else
162 					audio->stop_music();
163 				break;
164 			case SDLK_UP:
165 				active = (active + 2) % 3;
166 				break;
167 			case SDLK_DOWN:
168 				active = (active + 1) % 3;
169 				break;
170 			case SDLK_LEFT:
171 				if (active == 0)
172 				{
173 					song--;
174 					if (song < 0) song = 255;
175 				}
176 				else if (active == 1)
177 				{
178 					sfx--;
179 					if (sfx < 0) sfx = 255;
180 				}
181 				else if (active == 2)
182 				{
183 					voice--;
184 					if (voice < 0) voice = 255;
185 				}
186 				break;
187 			case SDLK_RIGHT:
188 				if (active == 0)
189 				{
190 					song++;
191 					if (song > 255) song = 0;
192 				}
193 				else if (active == 1)
194 				{
195 					sfx++;
196 					if (sfx > 255) sfx = 0;
197 				}
198 				else if (active == 2)
199 				{
200 					voice++;
201 					if (voice > 255) voice = 0;
202 				}
203 				break;
204 			default:
205 				break;
206 			}
207 		}
208 	} while(looping);
209 
210 	gwin->get_tqueue()->resume(SDL_GetTicks());
211 
212 	gwin->paint();
213 	Mouse::mouse->show();
214 	gwin->show();
215 }
216