1 /*
2  * Schism Tracker - a cross-platform Impulse Tracker clone
3  * copyright (c) 2003-2005 Storlek <storlek@rigelseven.com>
4  * copyright (c) 2005-2008 Mrs. Brisby <mrs.brisby@nimh.org>
5  * copyright (c) 2009 Storlek & Mrs. Brisby
6  * copyright (c) 2010-2012 Storlek
7  * URL: http://schismtracker.org/
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
main(void)22  */
23 
24 #include "headers.h"
25 #include "it.h"
26 #include "page.h"
27 #include "video.h"
28 #include "song.h"
29 #include "version.h"
30 
31 /* Eventual TODO: draw the pattern data in the Schism logo in a different color than the words */
32 #include "auto/logoit.h"
33 #include "auto/logoschism.h"
34 
35 #define LOGO_WIDTH 292
36 #define LOGO_PITCH 292
37 #define LOGO_HEIGHT 50
38 
39 static int fake_driver = 0;
40 static SDL_Surface *it_logo = NULL;
41 static SDL_Surface *schism_logo = NULL;
42 
43 static struct widget widgets_about[1];
44 
45 static struct vgamem_overlay logo_image = {
46 	23, 17,
47 	58, 24,
48 	NULL, 0, 0, 0,
49 };
50 
51 
52 static int _fixup_ignore_globals(struct key_event *k)
53 {
54 	if (k->mouse && k->y > 20) return 0;
55 	switch (k->sym) {
56 	case SDLK_LEFT:
57 	case SDLK_RIGHT:
58 	case SDLK_DOWN:
59 	case SDLK_UP:
60 	case SDLK_TAB:
61 	case SDLK_RETURN:
62 	case SDLK_ESCAPE:
63 		/* use default handler */
64 		return 0;
65 	case SDLK_F2: case SDLK_F5: case SDLK_F9: case SDLK_F10:
66 		// Ctrl + these keys does not lead to a new screen
67 		if (k->mod & KMOD_CTRL)
68 			break;
69 		// Fall through.
70 	case SDLK_F1: case SDLK_F3: case SDLK_F4:
71 	case SDLK_F11: case SDLK_F12:
72 		// Ignore Alt and so on.
73 		if (k->mod & (KMOD_ALT | KMOD_SHIFT))
74 			break;
75 		dialog_destroy();
76 		return 0;
77 	default:
78 		break;
79 	}
80 	/* this way, we can't pull up help here */
81 	return 1;
82 }
83 
84 static void _draw_full(void)
85 {
86 	draw_fill_chars(0,0,79,49,0);
87 }
88 
89 void about_load_page(struct page *page)
90 {
91 	page->title = "";
92 	page->total_widgets = 0;
93 	page->widgets = NULL;
94 	page->pre_handle_key = _fixup_ignore_globals;
95 	page->help_index = HELP_COPYRIGHT;
96 	page->draw_full = _draw_full;
97 	page->set_page = show_about;
98 }
99 
100 static void about_close(UNUSED void *data)
101 {
102 	if (status.current_page == PAGE_ABOUT) set_page(PAGE_LOAD_MODULE);
103 	status.flags |= NEED_UPDATE;
104 }
105 
106 static void about_draw_const(void)
107 {
108 	char buf[81];
109 
110 	if (status.current_page == PAGE_ABOUT) {
111 		/* redraw outer part */
112 		draw_box(11,16, 68, 34, BOX_THIN | BOX_OUTER | BOX_FLAT_DARK);
113 	}
114 
115 	if (status.flags & CLASSIC_MODE) {
116 		draw_box(25,25, 56, 30, BOX_THIN | BOX_OUTER | BOX_FLAT_DARK);
117 
118 		draw_text("Sound Card Setup", 32, 26, 0, 2);
119 
120 		if (strcasecmp(song_audio_driver(), "dummy") == 0) {
121 			draw_text("No sound card detected", 29, 28, 0, 2);
122 		} else {
123 			switch (fake_driver) {
124 			case 0:
125 				draw_text("Sound Blaster 16 detected", 26, 28, 0, 2);
126 				draw_text("Port 220h, IRQ 7, DMA 5", 26, 29, 0, 2);
127 				break;
128 			case 1:
129 				/* FIXME: The GUS driver displays the memory settings a bit
130 				differently from the SB. If we're "supporting" it, we should
131 				probably keep the rest of the UI consistent with our choice.
132 				(Also: no love for the AWE cards?)
133 
134 				Alternately, it would be totally awesome to probe the system
135 				for the actual name and parameters of the card in use :) */
136 				draw_text("Gravis UltraSound detected", 26, 28, 0, 2);
137 				draw_text("Port 240h, IRQ 5, 1024k RAM", 26, 29, 0, 2);
138 				break;
139 			};
140 		}
141 	} else {
142 		snprintf(buf, 80, "Using %s on %s", song_audio_driver(), video_driver_name());
143 		buf[80] = 0;
144 		draw_text(buf, (80 - strlen(buf)) / 2, 25, 0, 2);
145 		/* build date? */
146 		draw_text(ver_short_copyright, 15, 27, 1, 2);
147 		draw_text(ver_short_based_on, 15, 28, 1, 2);
148 		/* XXX if we allow key remapping, need to reflect the *real* help key here */
149 		draw_text("Press F1 for copyright and full credits", 15, 29, 1, 2);
150 	}
151 	vgamem_ovl_apply(&logo_image);
152 }
153 
154 void show_about(void)
155 {
156 	static int didit = 0;
157 	struct dialog *d;
158 	unsigned char *p;
159 	int x, y;
160 
161 	fake_driver = (rand() & 3) ? 0 : 1;
162 
163 	if (!didit) {
164 		vgamem_ovl_alloc(&logo_image);
165 		it_logo = xpmdata(_logo_it_xpm);
166 		schism_logo = xpmdata(_logo_schism_xpm);
167 		didit=1;
168 	}
169 
170 	if (status.flags & CLASSIC_MODE) {
171 		p = it_logo ? it_logo->pixels : NULL;
172 	} else {
173 		p = schism_logo ? schism_logo->pixels : NULL;
174 	}
175 
176 	/* this is currently pretty gross */
177 	vgamem_ovl_clear(&logo_image, 2);
178 	if (p) {
179 		int c = (status.flags & CLASSIC_MODE) ? 11 : 0;
180 		for (y = 0; y < LOGO_HEIGHT; y++) {
181 			for (x = 0; x < LOGO_WIDTH; x++) {
182 				if (p[x]) {
183 					vgamem_ovl_drawpixel(&logo_image, x+2, y+6, c);
184 				}
185 			}
186 			vgamem_ovl_drawpixel(&logo_image, x, y+6, 2);
187 			vgamem_ovl_drawpixel(&logo_image, x+1, y+6, 2);
188 			p += LOGO_PITCH;
189 		}
190 	}
191 
192 	create_button(widgets_about + 0,
193 			33,32,
194 			12,
195 			0,0,0,0,0,
196 			dialog_yes_NULL, "Continue", 3);
197 	d = dialog_create_custom(11,16,
198 			58, 19,
199 			widgets_about, 1, 0,
200 			about_draw_const, NULL);
201 	d->action_yes = about_close;
202 	d->action_no = about_close;
203 	d->action_cancel = about_close;
204 
205 	/* okay, in just a moment, we're going to the module page.
206 	 * if your modules dir is large enough, this causes an annoying pause.
207 	 * to defeat this, we start scanning *NOW*. this makes startup "feel"
208 	 * faster.
209 	 */
210 	status.flags |= DIR_MODULES_CHANGED;
211 	pages[PAGE_LOAD_MODULE].set_page();
212 }
213 
214