Esempio n. 1
0
GameWindow* PlatformWin::createWindow( char const* title , Vec2i const& size , int colorBit , bool bFullScreen )
{
	GameWindow* win = new GameWindow;
	if ( !win->create( title , size , colorBit , bFullScreen ) )
	{
		delete win;
		return NULL;
	}
	return win;
}
Esempio n. 2
0
    MainWindow() : audio_window(settings, mute_item), video_window(settings, *this), input_window(settings, input, [&]{ run(); }),
                   circuit(nullptr), prev_ui_state{false, false, false, false}
    {
        // Load config file
        nall::string config_path = configpath();
        config_path.append("dice/");
        directory::create(config_path);

        settings.filename = {config_path, "settings.cfg"};
        settings.load();
        
        onClose = &Application::quit;

        // Game menu
        game_menu.setText("Game");

        new_game_item.setText("New Game...");
        new_game_item.onActivate = [&] { game_window.create(geometry().position()); };
        game_window.cancel_button.onActivate = [&] { game_window.setModal(false); game_window.setVisible(false); };
        
        game_window.start_button.onActivate = [&]
        {
            GameDesc& g = game_list[game_window.game_view.selection()];
            if(circuit) delete circuit; 
            circuit = new Circuit(settings, *input, *video, g.desc, g.command_line);
            game_window.setModal(false);
            game_window.setVisible(false);
            onSize();
        };

        game_menu.append(new_game_item);

        end_game_item.setText("End Game");
        end_game_item.onActivate = [&] 
        { 
            if(circuit) 
            {
                delete circuit; 
                circuit = nullptr;
            }
            onSize();
        };
        game_menu.append(end_game_item);

        game_menu.append(game_sep[0]);
        pause_item.setText("Pause");
        pause_item.onToggle = [&] { settings.pause = pause_item.checked(); };
        throttle_item.setText("Throttle");
        throttle_item.setChecked(true);
        throttle_item.onToggle = [&]
        { 
            settings.throttle = throttle_item.checked();
            if(settings.throttle && circuit) // Adjust rtc
            {
                uint64_t emu_time = circuit->global_time * 1000000.0 * Circuit::timescale;
                circuit->rtc += int64_t(circuit->rtc.get_usecs()) - emu_time;
            }
        };
        game_menu.append(pause_item, throttle_item);

        game_menu.append(game_sep[1]);
        exit_item.setText("Exit");
        exit_item.onActivate = onClose;
        game_menu.append(exit_item);

        append(game_menu);

        // Settings menu
        settings_menu.setText("Settings");

        audio_item.setText("Audio Settings...");
        settings_menu.append(audio_item);
        audio_item.onActivate = [&] { audio_window.create(geometry().position()); };
        audio_window.onClose = audio_window.exit_button.onActivate = [&] 
        {
            mute_item.setChecked(settings.audio.mute);
            audio_window.setModal(false);
            audio_window.setVisible(false);
            if(circuit) circuit->audio.toggle_mute();
        };
        mute_item.setText("Mute Audio");
        mute_item.setChecked(settings.audio.mute);
        mute_item.onToggle = [&] 
        { 
            settings.audio.mute = mute_item.checked(); 
            if(circuit) circuit->audio.toggle_mute(); 
        };

        settings_menu.append(mute_item);
        settings_menu.append(settings_sep[0]);

        video_item.setText("Video Settings...");
        video_item.onActivate = [&] { video_window.create(geometry().position()); };
        status_visible_item.setText("Status Bar Visible");
        status_visible_item.setChecked(settings.video.status_visible);
        status_visible_item.onToggle = [&] 
        { 
            settings.video.status_visible = status_visible_item.checked();
            setStatusVisible(settings.video.status_visible);
        };
        fullscreen_item.setText("Fullscreen");
        fullscreen_item.onToggle = [&] { toggleFullscreen(fullscreen_item.checked()); };
        settings_menu.append(video_item, status_visible_item, fullscreen_item);

        settings_menu.append(settings_sep[1]);
        input_item.setText("Configure Inputs...");
        input_item.onActivate = [&] { input_window.create(geometry().position()); };
        input_window.onClose = [&] 
        {
            if(input_window.active_selector) input_window.active_selector->assign(KeyAssignment::None);
            input_window.setModal(false);
            input_window.setVisible(false);
        };
        input_window.exit_button.onActivate = [&]
        {
            if(input_window.active_selector) 
                input_window.active_selector->assign(KeyAssignment::None);
            else
            {
                input_window.setModal(false);
                input_window.setVisible(false);
            }
        };

        settings_menu.append(input_item);

        dipswitch_item.setText("Configure DIP Switches...");
        dipswitch_item.onActivate = [&] 
        { 
            int selection = 0;
            if(circuit) for(int i = 0; i < dipswitch_window.game_configs.size(); i++)
            {            
                if(circuit->game_config == dipswitch_window.game_configs[i])
                {
                    selection = i;
                    break;
                }
            }
            dipswitch_window.create(geometry().position(), selection); 
        };
        dipswitch_window.onClose = dipswitch_window.exit_button.onActivate = [&] 
        {
            dipswitch_window.game_configs[dipswitch_window.current_config].save();
            dipswitch_window.setModal(false);
            dipswitch_window.setVisible(false);
        };
        settings_menu.append(settings_sep[2]);
        settings_menu.append(dipswitch_item);

        append(settings_menu);

        setStatusVisible(settings.video.status_visible);

        setBackgroundColor({0, 0, 0});
        layout.setMargin(0);
        viewport = new Viewport();
        layout.append(*viewport, {~0, ~0});
        append(layout);

        // Initialize SDL, input, etc.
        settings.num_mice = ManyMouse_Init();

        if(SDL_Init(SDL_INIT_AUDIO|SDL_INIT_JOYSTICK) < 0)
	    {
	        printf("Unable to init SDL:\n%s\n", SDL_GetError());
		    exit(1);
	    }

        input = new Input();
        video = Video::createDefault(layout, viewport);

        onSize = [&] {

            if((signed)geometry().height < 0 || (signed)geometry().width < 0)
                return;
            
            video->video_init(geometry().width, geometry().height, settings.video);

            if(circuit == nullptr)
            {
                drawLogo();
            }

            viewport->setFocused();
        };

        setTitle(VERSION_STRING);
        setFrameGeometry({(Desktop::workspace().width - 640) / 2, (Desktop::workspace().height - 480) / 2, 640, 480});
        setMenuVisible();
        setVisible();

        onSize();
    }