Example #1
0
bool init_scaler( unsigned int new_scaler, bool fullscreen )
{
	int w = scalers[new_scaler].width,
	    h = scalers[new_scaler].height;
	int bpp = can_init_scaler(new_scaler, fullscreen);
	/*int flags = SDL_SWSURFACE | SDL_HWPALETTE | (fullscreen ? SDL_FULLSCREEN : 0);
	
	if (bpp == 0)
		return false;
	
	SDL_Surface *const surface = SDL_SetVideoMode(w, h, bpp, flags);*/

	SDL_Surface *const surface = SDLSingleton::GetInstance()->GetSurface();
	
	if (surface == NULL)
	{
		fprintf(stderr, "error: failed to initialize video mode %dx%dx%d: %s\n", w, h, bpp, SDL_GetError());
		return false;
	}
	
	w = surface->w;
	h = surface->h;
	bpp = surface->format->BitsPerPixel;
	
	printf("initialized video: %dx%dx%d\n", w, h, bpp);
	
	scaler = new_scaler;
	fullscreen_enabled = fullscreen;
	
	switch (bpp)
	{
	case 32:
		scaler_function = scalers[scaler].scaler32;
		break;
	case 16:
		scaler_function = scalers[scaler].scaler16;
		break;
	case 8:
		scaler_function = scalers[scaler].scaler8;
		break;
	default:
		scaler_function = NULL;
		break;
	}
	
	if (scaler_function == NULL)
	{
		assert(false);
		return false;
	}
	
	input_grab();
	
	JE_showVGA();
	
	return true;
}
Example #2
0
void opentyrian_menu( void )
{
	typedef enum
	{
		MENU_ABOUT = 0,
		MENU_FULLSCREEN,
		MENU_SCALER,
		// MENU_DESTRUCT,
		MENU_JUKEBOX,
		MENU_RETURN,
		MenuOptions_MAX
	} MenuOptions;

	static const char *menu_items[] =
	{
		"About OpenTyrian",
		"Toggle Fullscreen",
		"Scaler: None",
		// "Play Destruct",
		"Jukebox",
		"Return to Main Menu",
	};
	bool menu_items_disabled[] =
	{
		false,
		!can_init_any_scaler(false) || !can_init_any_scaler(true),
		false,
		// false,
		false,
		false,
	};
	
	assert(COUNTOF(menu_items) == MenuOptions_MAX);
	assert(COUNTOF(menu_items_disabled) == MenuOptions_MAX);

	fade_black(10);
	JE_loadPic(VGAScreen, 13, false);

	draw_font_hv(VGAScreen, VGAScreen->surf->w / 2, 5, opentyrian_str, large_font, centered, 15, -3);

	memcpy(VGAScreen2->surf->pixels, VGAScreen->surf->pixels, VGAScreen2->surf->pitch * VGAScreen2->surf->h);

	JE_showVGA();

	play_song(36); // A Field for Mag

	MenuOptions sel = 0;

	uint temp_scaler = scaler;

	bool fade_in = true, quit = false;
	do
	{
		memcpy(VGAScreen->surf->pixels, VGAScreen2->surf->pixels, VGAScreen->surf->pitch * VGAScreen->surf->h);

		for (MenuOptions i = 0; i < MenuOptions_MAX; i++)
		{
			const char *text = menu_items[i];
			char buffer[100];

			if (i == MENU_SCALER)
			{
				snprintf(buffer, sizeof(buffer), "Scaler: %s", scalers[temp_scaler].name);
				text = buffer;
			}

			int y = i != MENU_RETURN ? i * 16 + 32 : 118;
			draw_font_hv(VGAScreen, VGAScreen->surf->w / 2, y, text, normal_font, centered, 15, menu_items_disabled[i] ? -8 : i != sel ? -4 : -2);
		}

		JE_showVGA();

		if (fade_in)
		{
			fade_in = false;
			fade_palette(colors, 20, 0, 255);
			wait_noinput(true, false, false);
		}

		tempW = 0;
		JE_textMenuWait(&tempW, false);

		if (newkey)
		{
			switch (lastkey_sym)
			{
			case SDLK_UP:
				do
				{
					if (sel-- == 0)
						sel = MenuOptions_MAX - 1;
				}
				while (menu_items_disabled[sel]);
				
				JE_playSampleNum(S_CURSOR);
				break;
			case SDLK_DOWN:
				do
				{
					if (++sel >= MenuOptions_MAX)
						sel = 0;
				}
				while (menu_items_disabled[sel]);
				
				JE_playSampleNum(S_CURSOR);
				break;
				
			case SDLK_LEFT:
				if (sel == MENU_SCALER)
				{
					do
					{
						if (temp_scaler == 0)
							temp_scaler = scalers_count;
						temp_scaler--;
					}
					while (!can_init_scaler(temp_scaler, fullscreen_enabled));
					
					JE_playSampleNum(S_CURSOR);
				}
				break;
			case SDLK_RIGHT:
				if (sel == MENU_SCALER)
				{
					do
					{
						temp_scaler++;
						if (temp_scaler == scalers_count)
							temp_scaler = 0;
					}
					while (!can_init_scaler(temp_scaler, fullscreen_enabled));
					
					JE_playSampleNum(S_CURSOR);
				}
				break;
				
			case SDLK_RETURN:
				switch (sel)
				{
				case MENU_ABOUT:
					JE_playSampleNum(S_SELECT);

					scroller_sine(about_text);

					memcpy(VGAScreen->surf->pixels, VGAScreen2->surf->pixels, VGAScreen->surf->pitch * VGAScreen->surf->h);
					JE_showVGA();
					fade_in = true;
					break;
					
				case MENU_FULLSCREEN:
					JE_playSampleNum(S_SELECT);

					if (!init_scaler(scaler, !fullscreen_enabled) && // try new fullscreen state
						!init_any_scaler(!fullscreen_enabled) &&     // try any scaler in new fullscreen state
						!init_scaler(scaler, fullscreen_enabled))    // revert on fail
					{
						exit(EXIT_FAILURE);
					}
					break;
					
				case MENU_SCALER:
					JE_playSampleNum(S_SELECT);

					if (scaler != temp_scaler)
					{
						if (!init_scaler(temp_scaler, fullscreen_enabled) &&   // try new scaler
							!init_scaler(temp_scaler, !fullscreen_enabled) &&  // try other fullscreen state
							!init_scaler(scaler, fullscreen_enabled))          // revert on fail
						{
							exit(EXIT_FAILURE);
						}
					}
					break;
					
				case MENU_JUKEBOX:
					JE_playSampleNum(S_SELECT);

					fade_black(10);
					jukebox();

					memcpy(VGAScreen->surf->pixels, VGAScreen2->surf->pixels, VGAScreen->surf->pitch * VGAScreen->surf->h);
					JE_showVGA();
					fade_in = true;
					break;
					
				case MENU_RETURN:
					quit = true;
					JE_playSampleNum(S_SPRING);
					break;
					
				case MenuOptions_MAX:
					assert(false);
					break;
				}
				break;
				
			case SDLK_ESCAPE:
				quit = true;
				JE_playSampleNum(S_SPRING);
				break;
				
			default:
				break;
			}
		}
	} while (!quit);
}
Example #3
0
void opentyrian_menu( void )
{
	static const char *menu_items[] =
	{
		"About OpenTyrian",
		"Toggle Fullscreen",
		"Scaler: None",
		// "Play Destruct",
		"Jukebox",
		"Return to Main Menu",
	};
	bool menu_items_disabled[] =
	{
		false,
		!can_init_any_scaler(false) || !can_init_any_scaler(true),
		false,
		// false,
		false,
		false,
	};
	
	fade_black(10);
	JE_loadPic(VGAScreen, 13, false);

	draw_font_hv(VGAScreen, VGAScreen->w / 2, 5, opentyrian_str, large_font, centered, 15, -3);

	memcpy(VGAScreen2->pixels, VGAScreen->pixels, VGAScreen2->pitch * VGAScreen2->h);

	JE_showVGA();

	play_song(36); // A Field for Mag

	int sel = 0;
	const int maxSel = COUNTOF(menu_items) - 1;

	uint32_t temp_scaler = scaler;

	bool fade_in = true, quit = false;
	do
	{
		memcpy(VGAScreen->pixels, VGAScreen2->pixels, VGAScreen->pitch * VGAScreen->h);

		for (int i = 0; i <= maxSel; i++)
		{
			const char *text = menu_items[i];
			char buffer[100];

			if (i == 2) /* Scaler */
			{
				snprintf(buffer, sizeof(buffer), "Scaler: %s", scalers[temp_scaler].name);
				text = buffer;
			}

			int y = i != maxSel ? i * 16 + 32 : 118;
			draw_font_hv(VGAScreen, VGAScreen->w / 2, y, text, normal_font, centered, 15, menu_items_disabled[i] ? -8 : i != sel ? -4 : -2);
		}

		JE_showVGA();

		if (fade_in)
		{
			fade_in = false;
			fade_palette(colors, 20, 0, 255);
			wait_noinput(true, false, false);
		}

		tempW = 0;
		JE_textMenuWait(&tempW, false);

		if (newkey)
		{
			switch (lastkey_sym)
			{
			case SDLK_UP:
				do
				{
					if (--sel < 0)
						sel = maxSel;
				}
				while (menu_items_disabled[sel]);
				
				JE_playSampleNum(S_CURSOR);
				break;
			case SDLK_DOWN:
				do
				{
					if (++sel > maxSel)
						sel = 0;
				}
				while (menu_items_disabled[sel]);
				
				JE_playSampleNum(S_CURSOR);
				break;
				
			case SDLK_LEFT:
				if (sel == 2)
				{
					do
					{
						if (temp_scaler == 0)
							temp_scaler = scalers_count;
						temp_scaler--;
					}
					while (!can_init_scaler(temp_scaler, fullscreen_enabled));
					
					JE_playSampleNum(S_CURSOR);
				}
				break;
			case SDLK_RIGHT:
				if (sel == 2)
				{
					do
					{
						temp_scaler++;
						if (temp_scaler == scalers_count)
							temp_scaler = 0;
					}
					while (!can_init_scaler(temp_scaler, fullscreen_enabled));
					
					JE_playSampleNum(S_CURSOR);
				}
				break;
				
			case SDLK_RETURN:
				switch (sel)
				{
				case 0: /* About */
					JE_playSampleNum(S_SELECT);

					scroller_sine(about_text);

					memcpy(VGAScreen->pixels, VGAScreen2->pixels, VGAScreen->pitch * VGAScreen->h);
					JE_showVGA();
					fade_in = true;
					break;
					
				case 1: /* Fullscreen */
					JE_playSampleNum(S_SELECT);

					if (!init_scaler(scaler, !fullscreen_enabled) && // try new fullscreen state
						!init_any_scaler(!fullscreen_enabled) &&     // try any scaler in new fullscreen state
						!init_scaler(scaler, fullscreen_enabled))    // revert on fail
					{
						exit(EXIT_FAILURE);
					}
					set_palette(colors, 0, 255); // for switching between 8 bpp scalers
					break;
					
				case 2: /* Scaler */
					JE_playSampleNum(S_SELECT);

					if (scaler != temp_scaler)
					{
						if (!init_scaler(temp_scaler, fullscreen_enabled) &&   // try new scaler
							!init_scaler(temp_scaler, !fullscreen_enabled) &&  // try other fullscreen state
							!init_scaler(scaler, fullscreen_enabled))          // revert on fail
						{
							exit(EXIT_FAILURE);
						}
						set_palette(colors, 0, 255); // for switching between 8 bpp scalers
					}
					break;
					
				case 3: /* Jukebox */
					JE_playSampleNum(S_SELECT);

					fade_black(10);
					jukebox();

					memcpy(VGAScreen->pixels, VGAScreen2->pixels, VGAScreen->pitch * VGAScreen->h);
					JE_showVGA();
					fade_in = true;
					break;
					
				case 4: /* Return to main menu */
					quit = true;
					JE_playSampleNum(S_SPRING);
					break;
				}
				break;
				
			case SDLK_ESCAPE:
				quit = true;
				JE_playSampleNum(S_SPRING);
				break;
				
			default:
				break;
			}
		}
	} while (!quit);
}
Example #4
0
bool init_scaler( unsigned int new_scaler, bool fullscreen )
#endif
{
	const SDL_VideoInfo *info = SDL_GetVideoInfo();
	const int screen_w = info->current_w; // Z10: 1280
	const int screen_h = info->current_h; // Z10: 768
#ifdef __BLACKBERRY__
	bool fullscreen = true;
	unsigned int new_scaler = 0;
	while (new_scaler < scalers_count &&
	       (scalers[new_scaler].width != screen_w ||
	        scalers[new_scaler].height != screen_h)) {
		new_scaler++;
	}
	if (scalers_count == new_scaler) {
		new_scaler = scalers_count - 1;
	}
	int bpp = 32;
	int w = scalers[new_scaler].width;
	int h = scalers[new_scaler].height;

#else
	int bpp = can_init_scaler(new_scaler, fullscreen);
#endif
	int flags = SDL_SWSURFACE | SDL_HWPALETTE | (fullscreen ? SDL_FULLSCREEN : 0);

	if (bpp == 0)
		return false;

	SDL_Surface * const surface = SDL_SetVideoMode(w, h, bpp, flags);

	if (surface == NULL) {
		fprintf(stderr, "error: failed to initialize video mode %dx%dx%d: %s\n",
		        w, h, bpp, SDL_GetError());
		return false;
	}

	w = surface->w;
	h = surface->h;
	bpp = surface->format->BitsPerPixel;

	fprintf(stderr, "initialized video: %dx%dx%d\n", w, h, bpp);

	scaler = new_scaler;
	fullscreen_enabled = fullscreen;

	switch (bpp) {
	case 32:
		scaler_function = scalers[scaler].scaler32;
		break;
	case 16:
		scaler_function = scalers[scaler].scaler16;
		break;
	case 8:
		scaler_function = scalers[scaler].scaler8;
		break;
	default:
		scaler_function = NULL;
		break;
	}

	if (scaler_function == NULL) {
		assert(false);
		return false;
	}

	input_grab();

	JE_showVGA();

	return true;
}