1 /*
2 ** Theres not many "about" dialogs that get their own C file ;-)
3 */
4
5 #include <stdio.h>
6 #include <string.h>
7 #include <stdlib.h>
8 #include <math.h>
9
10 #include <system_includes.h>
11
12
13 #include "replay.h"
14 #include "gui.h"
15
16 #define NUMSTARS 100
17
18 struct star
19 {
20 int16 x, y;
21 int16 sp;
22 };
23
24 struct star stars[NUMSTARS];
25
26 #ifndef __SDL_WRAPPER__
27 extern struct Screen *scr;
28 struct Window *aboutwin = NULL;
29 extern struct Window *mainwin;
30
31 uint32 about_winsig = 0;
32 uint32 about_sigs = 0;
33 uint32 about_timesig;
34
35 struct MsgPort *ab_tioport = NULL;
36 struct TimeRequest *ab_tioreq = NULL;
37 BOOL ab_tiopen = FALSE;
38 BOOL ab_tiopending = FALSE;
39 #else
40 BOOL aboutwin_open;
41 extern struct rawbm mainbm;
42 extern SDL_Event event;
43 extern struct ahx_tune *curtune;
44 extern int32 wm_count;
45 extern struct ahx_tune *rp_curtune;
46 SDL_TimerID thetimer = 0;
47 #endif
48
49 int16 ab_x = -1, ab_y = -1;
50
51 struct rawbm about_bm;
52 struct rawbm afont_bm;
53 struct rawbm stuff_bm;
54
55 int16 slice[320/2];
56 float64 sinpos = 0, cospos = 0;
57
58 const TEXT *scrtxt = " hivelytracker version 1.8 :: code by xeron of iris "
59 ":: gui design and skins created by spot of up rough "
60 ":: example tunes by xeron of iris, varthall of up rough, oxide of sonik and syphus "
61 ":: hivelytracker is based on ahx by dexter and pink of abyss "
62 ":: many thanks to pieknyman for helping me find and fix bugs in the replayer. you rule! "
63 ":: large parts of ahxplay.library by ilkka lehtoranta and per johansson were referenced for the replayer "
64 ":: thanks to passing by and kode54 for replayer improvements "
65 ":: thanks to spot, varthall and the rest of up rough for their ideas, tunes and betatesting "
66 ":: thanks to buzz for the aros and morphos ports, deltafire for the os x port, and pulkomandy for the haiku port "
67 ":: thanks to the betatesters of the sdl port as well! "
68 ":: greets... rno, tbl, tulou, scarab, nature, triad, dcs, fairlight, and yes, even loonies. "
69 ":: remember kids, say no to blancmange! "
70 ":: extra thanks to spot for his nagging and complaining, without "
71 " whom hively would not be as cool as it now is! "
72 ":: so... why did i write an ahx based tracker for os4? for one simple "
73 "reason: i wanted to create ahx tunes on my amigaone without having to "
74 "resort to uae. unfortunately ahx used the cia timers and paula directly "
75 "and so it didnt work properly at all under os4. so, i sat down and made "
76 "my own os4 ahx tracker, and i started adding new features as i did so. "
77 "i hope you enjoy it and the tunes made in it! "
78 "messages from buzz:�i�would�like�to�thank�xeron�for�this�great�tracker,�and�being�patient�with�me "
79 "while�i�port�it.�also thanks�to�all�the�betatesters�on�irc ... hi�syphus. "
80 "i would�also�like�to�thank�stingray�for�his�useless�tips�and�code�advice.�just�kidding!�"
81 "he�is�right�about�one�thing though,�my�code�does�suck! finally hi to yaz: "
82 "thanks for sending me that new tune ! ";
83
84 const TEXT *scrtab = "abcdefghijklmnopqrstuvwxyz!,.:?1234567890";
85
86 int32 scro=0, scrs=30, scrc=0;
87 int32 bx1=0, bx2=320;
88
89 #ifdef __SDL_WRAPPER__
about_timing(Uint32 interval,void * userdata)90 Uint32 about_timing( Uint32 interval, void *userdata )
91 {
92 if( aboutwin_open )
93 {
94 SDL_Event tmpevent;
95 SDL_UserEvent userevent;
96
97 userevent.type = SDL_USEREVENT;
98 userevent.code = 88;
99 userevent.data1 = NULL;
100 userevent.data2 = NULL;
101
102 tmpevent.type = SDL_USEREVENT;
103 tmpevent.user = userevent;
104
105 SDL_PushEvent( &tmpevent );
106 }
107
108 return 16;
109 }
110 #endif
111
112
about_pre_init(void)113 void about_pre_init( void )
114 {
115 int32 i;
116
117 #ifndef __SDL_WRAPPER__
118 about_bm.bm = NULL;
119 afont_bm.bm = NULL;
120 stuff_bm.bm = NULL;
121 #else
122 about_bm.srf = NULL;
123 afont_bm.srf = NULL;
124 stuff_bm.srf = NULL;
125 #endif
126
127 for( i=0; i<160; i++ ) slice[i] = -1;
128 }
129
about_init(void)130 BOOL about_init( void )
131 {
132 int32 r, g, b, i;
133
134 #ifndef __SDL_WRAPPER__
135 ab_tioport = IExec->AllocSysObjectTags(ASOT_PORT, TAG_DONE);
136 if( !ab_tioport )
137 {
138 printf( "Unable to create message port\n" );
139 return FALSE;
140 }
141
142 about_timesig = 1L<<ab_tioport->mp_SigBit;
143
144 ab_tioreq = (struct TimeRequest *)IExec->AllocSysObjectTags(ASOT_IOREQUEST,
145 ASOIOR_ReplyPort, ab_tioport,
146 ASOIOR_Size, sizeof( struct TimeRequest ),
147 TAG_DONE);
148 if( !ab_tioreq )
149 {
150 printf( "Unable to create io request!\n" );
151 return FALSE;
152 }
153
154 // Get timer.device
155 ab_tiopen = !IExec->OpenDevice( "timer.device", UNIT_MICROHZ, (struct IORequest *)ab_tioreq, 0 );
156 if( !ab_tiopen )
157 {
158 printf( "Unable to open timer.device\n" );
159 return FALSE;
160 }
161
162 about_sigs = about_timesig;
163
164 if( !make_image( &about_bm, 320, 240 ) ) return FALSE;
165 #else
166 SDL_Rect cliprect = { .x = 4, .y = 4, .w = 320, .h = 240 };
167 if( !make_image( &about_bm, 328, 248 ) ) return FALSE;
168 about_bm.offx = 4;
169 about_bm.offy = 4;
170 SDL_SetClipRect(about_bm.srf, &cliprect);
171 #endif
172
173 if( !make_image( &stuff_bm, 640, 2 ) ) return FALSE;
174 if( !open_image( "aboutfont", &afont_bm ) ) return FALSE;
175
176 set_fcol(&stuff_bm, 0x000000);
177 fillrect_xy(&stuff_bm, 0, 0, 639, 1);
178
179 r = 255<<8;
180 g = 0;
181 b = 0;
182
183 for( i=0; i<106; i++ )
184 {
185 set_fcol(&stuff_bm, ((r&0xff00)<<8)|(g&0xff00)|((b&0xff00)>>8));
186 #ifndef __SDL_WRAPPER__
187 IGraphics->WritePixel( &stuff_bm.rp, i, 0 );
188 #else
189 fillrect_xy(&stuff_bm, i, 0, i, 0);
190 #endif
191 r -= ((255*256)/106);
192 g += ((255*256)/106);
193 }
194
195 r = 0;
196 g = 255<<8;
197 b = 0;
198
199 for( i=106; i<213; i++ )
200 {
201 set_fcol(&stuff_bm, ((r&0xff00)<<8)|(g&0xff00)|((b&0xff00)>>8));
202 #ifndef __SDL_WRAPPER__
203 IGraphics->WritePixel( &stuff_bm.rp, i, 0 );
204 #else
205 fillrect_xy(&stuff_bm, i, 0, i, 0);
206 #endif
207 g -= ((255*256)/107);
208 b += ((255*256)/107);
209 }
210
211 r = 0;
212 g = 0;
213 b = 255<<8;
214
215 for( i=213; i<320; i++ )
216 {
217 set_fcol(&stuff_bm, ((r&0xff00)<<8)|(g&0xff00)|((b&0xff00)>>8));
218 #ifndef __SDL_WRAPPER__
219 IGraphics->WritePixel( &stuff_bm.rp, i, 0 );
220 #else
221 fillrect_xy(&stuff_bm, i, 0, i, 0);
222 #endif
223 b -= ((255*256)/107);
224 r += ((255*256)/107);
225 }
226
227 set_fcol(&stuff_bm, 0xffffff);
228 fillrect_xy(&stuff_bm, 0, 1, 0, 1);
229 set_fcol(&stuff_bm, 0xaaaaaa);
230 fillrect_xy(&stuff_bm, 1, 1, 1, 1);
231 set_fcol(&stuff_bm, 0x888888);
232 fillrect_xy(&stuff_bm, 2, 1, 2, 1);
233 set_fcol(&stuff_bm, 0x444444);
234 fillrect_xy(&stuff_bm, 3, 1, 3, 1);
235
236 for( i=0; i<NUMSTARS; i++ )
237 {
238 stars[i].x = rand()%320;
239 stars[i].y = (rand()%208)+16;
240 stars[i].sp = (rand()%6)+1;
241 }
242
243 bm_to_bm(&stuff_bm, 0, 0, &stuff_bm, 320, 0, 320, 1);
244
245 return TRUE;
246 }
247
about_close(void)248 void about_close( void )
249 {
250 #ifndef __SDL_WRAPPER__
251 if( aboutwin == NULL ) return;
252
253 ab_x = aboutwin->LeftEdge;
254 ab_y = aboutwin->TopEdge;
255 IIntuition->CloseWindow( aboutwin );
256 aboutwin = NULL;
257
258 about_sigs &= ~about_winsig;
259 about_winsig = 0;
260
261 if( ab_tiopending )
262 {
263 IExec->AbortIO( (struct IORequest *)ab_tioreq );
264 IExec->WaitIO( (struct IORequest *)ab_tioreq );
265 ab_tiopending = FALSE;
266 }
267 #else
268 aboutwin_open = FALSE;
269 if (thetimer) SDL_RemoveTimer(thetimer);
270 thetimer = 0;
271 gui_render_everything();
272 #endif
273 }
274
about_shutdown(void)275 void about_shutdown( void )
276 {
277 about_close();
278
279 #ifndef __SDL_WRAPPER__
280 if( about_bm.bm ) IGraphics->FreeBitMap( about_bm.bm );
281 if( afont_bm.bm ) IGraphics->FreeBitMap( afont_bm.bm );
282 if( stuff_bm.bm ) IGraphics->FreeBitMap( stuff_bm.bm );
283
284 if( ab_tiopen )
285 {
286 if( ab_tiopending )
287 {
288 IExec->AbortIO( (struct IORequest *)ab_tioreq );
289 IExec->WaitIO( (struct IORequest *)ab_tioreq );
290 ab_tiopending = FALSE;
291 }
292 IExec->CloseDevice( (struct IORequest *)ab_tioreq );
293 }
294 if( ab_tioreq ) IExec->FreeSysObject( ASOT_IOREQUEST, ab_tioreq );
295 if( ab_tioport ) IExec->FreeSysObject( ASOT_PORT, ab_tioport );
296
297 about_bm.bm = NULL;
298 afont_bm.bm = NULL;
299 stuff_bm.bm = NULL;
300 #else
301 if (about_bm.srf) SDL_FreeSurface(about_bm.srf);
302 if (afont_bm.srf) SDL_FreeSurface(afont_bm.srf);
303 if (stuff_bm.srf) SDL_FreeSurface(stuff_bm.srf);
304 about_bm.srf = NULL;
305 afont_bm.srf = NULL;
306 stuff_bm.srf = NULL;
307 #endif
308 }
309
about_open(void)310 void about_open( void )
311 {
312 #ifndef __SDL_WRAPPER__
313 if( aboutwin ) return;
314
315 if( ab_x == -1 )
316 {
317 ab_x = mainwin->LeftEdge + 40;
318 ab_y = mainwin->TopEdge + 40;
319 }
320
321 aboutwin = IIntuition->OpenWindowTags( NULL,
322 WA_Left, ab_x,
323 WA_Top, ab_y,
324 WA_InnerWidth, 320,
325 WA_InnerHeight, 240,
326 WA_Title, "HivelyTracker v1.8",
327 WA_ScreenTitle, "HivelyTracker (c)2013 IRIS & Up Rough! - http://www.uprough.net - http://www.hivelytracker.co.uk",
328 WA_RMBTrap, TRUE,
329 WA_IDCMP, IDCMP_CLOSEWINDOW, //|IDCMP_MOUSEBUTTONS,
330 WA_Activate, TRUE,
331 WA_DragBar, TRUE,
332 WA_CloseGadget, TRUE,
333 WA_DepthGadget, TRUE,
334 scr ? WA_CustomScreen : TAG_IGNORE, scr,
335 TAG_DONE );
336
337 if( !aboutwin ) return;
338
339 about_winsig = (1L<<aboutwin->UserPort->mp_SigBit);
340 about_sigs |= about_winsig;
341
342 if( ab_tiopending )
343 {
344 IExec->AbortIO( (struct IORequest *)ab_tioreq );
345 IExec->WaitIO( (struct IORequest *)ab_tioreq );
346 ab_tiopending = FALSE;
347 }
348
349 ab_tioreq->Request.io_Command = TR_ADDREQUEST;
350 ab_tioreq->Time.Seconds = 0;
351 ab_tioreq->Time.Microseconds = 20000;
352 IExec->SendIO( (struct IORequest *)ab_tioreq );
353 ab_tiopending = TRUE;
354 #else
355 thetimer = SDL_AddTimer( 20, (SDL_NewTimerCallback)about_timing, NULL );
356 aboutwin_open = TRUE;
357 #endif
358 }
359
about_toggle(void)360 void about_toggle( void )
361 {
362 #ifndef __SDL_WRAPPER__
363 if( aboutwin )
364 #else
365 if( aboutwin_open )
366 #endif
367 about_close();
368 else
369 about_open();
370 }
371
about_frame(void)372 void about_frame( void )
373 {
374 int32 i;
375 float64 stmp, ctmp;
376
377 #ifndef __SDL_WRAPPER__
378 if( aboutwin == NULL ) return;
379 #else
380 if( !aboutwin_open ) return;
381 #endif
382
383 set_fcol(&about_bm, 0x000000);
384 fillrect_xy(&about_bm, 0, 0, 319, 239);
385
386 for( i=0; i<158; i++ )
387 slice[i] = slice[i+2];
388
389 scrs+=4;
390 if( scrs > 31 )
391 {
392 scrs = 0;
393 scro++;
394 if( scrtxt[scro] == 0 ) scro = 0;
395 for( scrc=0; scrc<strlen( scrtab ); scrc++ )
396 if( scrtab[scrc] == scrtxt[scro] ) break;
397 if( scrc == strlen( scrtab ) ) scrc = -1;
398 }
399
400 if( scrc > -1 )
401 {
402 slice[158] = (scrc<<5)+scrs;
403 slice[159] = (scrc<<5)+scrs+2;
404 } else {
405 slice[158] = slice[159] = -1;
406 }
407
408 for( i=0; i<NUMSTARS; i++ )
409 {
410 stars[i].x -= stars[i].sp;
411 if( stars[i].x < -3 )
412 {
413 stars[i].x = 320;
414 stars[i].y = (rand()%208)+16;
415 stars[i].sp = (rand()%6)+1;
416 }
417
418 bm_to_bm(&stuff_bm, 0, 1, &about_bm, stars[i].x, stars[i].y, 4, 1);
419 }
420
421 for( i=0, stmp=sinpos, ctmp=cospos; i<160; i++, stmp+=0.015f, ctmp -= 0.021f )
422 if( slice[i] != -1 )
423 bm_to_bm(&afont_bm, slice[i], 0, &about_bm, i<<1, ((int32)(sin(stmp)*cos(ctmp)*85))+101, 2, 38);
424
425 sinpos += 0.1f;
426 cospos -= 0.0712f;
427
428 bm_to_bm(&stuff_bm, bx1, 0, &about_bm, 0, 8, 320, 1);
429 bm_to_bm(&stuff_bm, bx2, 0, &about_bm, 0, 232, 320, 1);
430
431 bx1 = (bx1+ 4)%320;
432 bx2 = (bx2+316)%320;
433
434 #ifndef __SDL_WRAPPER__
435 IGraphics->BltBitMapRastPort( about_bm.bm, 0, 0, aboutwin->RPort, aboutwin->BorderLeft, aboutwin->BorderTop, 320, 240, 0x0C0 );
436 #else
437 bm_to_bm(&about_bm, -4, -4, &mainbm, 236, 176, 328, 248);
438 #endif
439 }
440
441 //BOOL pause = FALSE;
442
about_handler(uint32 gotsigs)443 void about_handler( uint32 gotsigs )
444 {
445 #ifndef __SDL_WRAPPER__
446 struct IntuiMessage *msg;
447 BOOL closeme;
448
449 closeme = FALSE;
450
451 if( gotsigs & about_timesig )
452 {
453 if( ab_tiopending )
454 {
455 IExec->WaitIO( (struct IORequest *)ab_tioreq );
456 ab_tiopending = FALSE;
457 }
458
459 if( aboutwin != NULL )
460 {
461 // if( !pause )
462 about_frame();
463
464 ab_tioreq->Request.io_Command = TR_ADDREQUEST;
465 ab_tioreq->Time.Seconds = 0;
466 ab_tioreq->Time.Microseconds = 28571; // 35 FPS
467 IExec->SendIO( (struct IORequest *)ab_tioreq );
468 ab_tiopending = TRUE;
469 }
470 }
471
472 if( gotsigs & about_winsig )
473 {
474 while( ( msg = (struct IntuiMessage *)IExec->GetMsg( aboutwin->UserPort ) ) )
475 {
476 switch( msg->Class )
477 {
478 /*
479 case IDCMP_MOUSEBUTTONS:
480 if( msg->Code == SELECTUP ) pause ^= 1;
481 break;
482 */
483 case IDCMP_CLOSEWINDOW:
484 closeme = TRUE;
485 break;
486 }
487 IExec->ReplyMsg( (struct Message *)msg );
488 }
489 }
490
491 if( closeme ) about_close();
492 #else
493 switch (event.type)
494 {
495 case SDL_USEREVENT:
496 switch (event.user.code)
497 {
498 case 0:
499 if( curtune == rp_curtune )
500 {
501 gui_render_tunepanel( FALSE );
502 gui_render_vumeters();
503 }
504 if( (wm_count++)&1 )
505 gui_render_wavemeter();
506 bm_to_bm(&about_bm, -4, -4, &mainbm, 236, 176, 328, 248);
507 break;
508
509 case 88:
510 about_frame();
511 break;
512 }
513 break;
514
515 case SDL_MOUSEBUTTONUP:
516 if (event.button.button == SDL_BUTTON_LEFT)
517 about_close();
518 break;
519
520 case SDL_KEYUP:
521 if (event.key.keysym.sym == SDLK_ESCAPE)
522 about_close();
523 break;
524 }
525 #endif
526 }
527
528