Exemplo n.º 1
0
void AscentApp::togglefullscreen() {
	if (toggledfullscreen == 0) {
		setfullscreen(!fullscreen);
		toggledfullscreen = 2; //Needs to be greater than 1 to avoid toggling too fast
	}
	
}
Exemplo n.º 2
0
void setfullscreen(bool enable, bool force)
{
    if(!screen) return;
    fullscreen = enable ? 1 : 0;
#if defined(WIN32) || defined(__APPLE__)
    initwarning(enable ? "fullscreen" : "windowed", INIT_RESET, CHANGE_GFX, force);
#else
    if(enable == !(screen->flags&SDL_FULLSCREEN))
    {
        SDL_WM_ToggleFullScreen(screen);
        inputgrab(grabinput!=0);
    }
#endif
}

VARF(0, fullscreen, 0, 1, 1, setfullscreen(fullscreen!=0));

void screenres(int *w, int *h)
{
#if !defined(WIN32) && !defined(__APPLE__)
    if(initing >= INIT_RESET)
    {
#endif
        scr_w = clamp(*w, SCR_MINW, SCR_MAXW);
        scr_h = clamp(*h, SCR_MINH, SCR_MAXH);
#if defined(WIN32) || defined(__APPLE__)
        initwarning("screen resolution");
#else
        return;
    }
    SDL_Surface *surf = SDL_SetVideoMode(clamp(*w, SCR_MINW, SCR_MAXW), clamp(*h, SCR_MINH, SCR_MAXH), 0, SDL_OPENGL|(screen->flags&SDL_FULLSCREEN ? SDL_FULLSCREEN : SDL_RESIZABLE));
void setfullscreen(bool enable)
{
    if(!screen) return;
#if defined(WIN32) || defined(__APPLE__)
    initwarning(enable ? "fullscreen" : "windowed");
#else
    if(enable == !(screen->flags&SDL_FULLSCREEN))
    {
        SDL_WM_ToggleFullScreen(screen);
        inputgrab(grabinput);
    }
#endif
}

#ifdef _DEBUG
VARF(fullscreen, 0, 0, 1, setfullscreen(fullscreen!=0));
#else
VARF(fullscreen, 0, 1, 1, setfullscreen(fullscreen!=0));
#endif

void screenres(int *w, int *h)
{
#if !defined(WIN32) && !defined(__APPLE__)
    if(initing >= INIT_RESET)
    {
#endif
        scr_w = clamp(*w, SCR_MINW, SCR_MAXW);
        scr_h = clamp(*h, SCR_MINH, SCR_MAXH);
#if defined(WIN32) || defined(__APPLE__)
        initwarning("screen resolution");
#else
Exemplo n.º 4
0
void AscentApp::onKeyDown_Standard(SDL_KeyboardEvent * keyEvent) {
	switch (keyEvent->keysym.sym) {
		case SDLK_F11:
			togglefullscreen();
			break;
		case SDLK_ESCAPE:
			setfullscreen(false);
			break;
		case SDLK_LEFT:
		case SDLK_h:
		case SDLK_KP_4:
			plan.push({ActionType::Move, Direction::Left, '\0'});
			break;
		case SDLK_RIGHT:
		case SDLK_l:
		case SDLK_KP_6:
			plan.push({ActionType::Move, Direction::Right, '\0'});
			break;
		case SDLK_UP:
		case SDLK_k:
		case SDLK_KP_8:
			plan.push({ActionType::Move, Direction::Up, '\0'});
			break;
		case SDLK_DOWN:
		case SDLK_j:
		case SDLK_KP_2:
			plan.push({ActionType::Move, Direction::Down, '\0'});
			break;
		case SDLK_y:
		case SDLK_KP_7:
			plan.push({ActionType::Move, Direction::UpLeft, '\0'});
			break;
		case SDLK_u:
		case SDLK_KP_9:
			plan.push({ActionType::Move, Direction::UpRight, '\0'});
			break;
		case SDLK_b:
		case SDLK_KP_1:
			plan.push({ActionType::Move, Direction::DownLeft, '\0'});
			break;
		case SDLK_n:
		case SDLK_KP_3:
			plan.push({ActionType::Move, Direction::DownRight, '\0'});
			break;
		case SDLK_KP_5:
		case SDLK_PERIOD:
			plan.push({ActionType::NONE, Direction::NONE, '\0'});
			break;
		case SDLK_g:
			plan.push({ActionType::Pickup, Direction::NONE, '\0'});
			break;
		case SDLK_d:
//			plan.push({ActionType::Drop, Direction::NONE, 'a'}); //Temporary implementation
			currentlyDisplaying = windowType::Inventory;
			userInputRequested = InputType::InventoryItemToDrop;
			break;
		case SDLK_i: // Viewing inventory only partially inplemented
			currentlyDisplaying = windowType::Inventory;
			userInputRequested = InputType::InventoryItemToView;
			break;
		default:
			break;
	}
}
Exemplo n.º 5
0
int
run() {
    int result = EXIT_FAILURE;

    loadatlas(&texmap, "../atlas/target.atlas", "../atlas/target.png");
    Texture *tex = gettex(&texmap, "ball.png");
    Texture *streettex = gettex(&texmap, "street.png");

    if(!tex || !streettex)
        goto out_texmap;

    Object mouse = {
        tformidentity,
        { 12, 12 }
    };

    Object street = {
        tformidentity,
        { 400, 250 }
    };

    Tform offset = tformidentity;
    offset.pos.x = -100;
    real scale = 1.0;
    Tform zoom = tformidentity;
    Tform camera = tformidentity;

    Vec2 worldabs = vec2zero;

    Tform angle = tformidentity;
    Vec2 pos = vec2zero;
    Tform player = tformidentity;

    while(running) {
        beginframe();
        if(input.keyboard.pressed[SDLK_ESCAPE])
            running = false;
        if(PRESSING_KEY(SDLK_f))
            setfullscreen(Diagonal);
        if(input.keyboard.pressed[SDLK_LSHIFT] && PRESSING_KEY(SDLK_f))
            setwindowed(Diagonal);
        if(input.keyboard.pressed[SDLK_d] || input.keyboard.pressed[SDLK_RIGHT])
            pos.x++;
        if(input.keyboard.pressed[SDLK_a] || input.keyboard.pressed[SDLK_LEFT])
            pos.x--;
        if(input.keyboard.pressed[SDLK_w] || input.keyboard.pressed[SDLK_UP])
            pos.y++;
        if(input.keyboard.pressed[SDLK_s] || input.keyboard.pressed[SDLK_DOWN])
            pos.y--;

        player = tformidentity;
        player.pos = pos;
        tformsetangle(&angle, LIMIT(input.mouse.screenabs.y * 0.02f, -M_PI_2, M_PI_2));
        player = TFORMMUL(player, angle);

        tformsetscale(&zoom, (Vec2) {
            scale, scale
        });
        camera = TFORMMUL( offset, TFORMMUL(zoom, TFORMT(tforminv(player))) );
        worldabs = TFORMVEC2(TFORMT(tforminv(camera)), input.mouse.screenabs);

        beginscene();

        batch_bind_texture(streettex->handle);
        batch.texcoords = streettex->coords;
        batch.tform = TFORMMUL(camera, street.t);
        batch_draw_rect(&street.s, 0);

        batch_bind_texture(tex->handle);
        batch.texcoords = tex->coords;
        mouse.t.pos = input.mouse.screenabs;
        batch.tform = mouse.t;
        batch_draw_rect(&mouse.s, 0);

        endscene();
        endframe();
    }

    result = EXIT_SUCCESS;
out_texmap:
    freetexmap(&texmap);
    return result;
}