static void sdl_process_key(SDL_KeyboardEvent *ev)
{
    int keycode, v;

    if (ev->keysym.sym == SDLK_PAUSE) {
        /* specific case */
        v = 0;
        if (ev->type == SDL_KEYUP)
            v |= SCANCODE_UP;
        kbd_put_keycode(0xe1);
        kbd_put_keycode(0x1d | v);
        kbd_put_keycode(0x45 | v);
        return;
    }

    if (kbd_layout) {
//    	LOGV("Found kbd layout using generic for %d\n",ev->keysym.sym);
        keycode = sdl_keyevent_to_keycode_generic(ev);
    } else {
//    	LOGV("Found no kbd layout for %d\n",ev->keysym.sym);
        keycode = sdl_keyevent_to_keycode(ev);
    }

    switch(keycode) {
    case 0x00:
        /* sent when leaving window: reset the modifiers state */
        reset_keys();
        return;
    case 0x2a:                          /* Left Shift */
    case 0x36:                          /* Right Shift */
    case 0x1d:                          /* Left CTRL */
    case 0x9d:                          /* Right CTRL */
    case 0x38:                          /* Left ALT */
    case 0xb8:                         /* Right ALT */
        if (ev->type == SDL_KEYUP)
            modifiers_state[keycode] = 0;
        else
            modifiers_state[keycode] = 1;
        break;
#define QEMU_SDL_VERSION ((SDL_MAJOR_VERSION << 8) + SDL_MINOR_VERSION)
#if QEMU_SDL_VERSION < 0x102 || QEMU_SDL_VERSION == 0x102 && SDL_PATCHLEVEL < 14
        /* SDL versions before 1.2.14 don't support key up for caps/num lock. */
    case 0x45: /* num lock */
    case 0x3a: /* caps lock */
        /* SDL does not send the key up event, so we generate it */
        kbd_put_keycode(keycode);
        kbd_put_keycode(keycode | SCANCODE_UP);
        return;
#endif
    }

    /* now send the key code */
    if (keycode & SCANCODE_GREY)
        kbd_put_keycode(SCANCODE_EMUL0);
    if (ev->type == SDL_KEYUP)
        kbd_put_keycode(keycode | SCANCODE_UP);
    else
        kbd_put_keycode(keycode & SCANCODE_KEYCODEMASK);
}
Beispiel #2
0
/* ***************************************************************************
 *  Function apply_action
 *  Applies the actions recieved from the controller for player A and B
 * ***************************************************************************/
void ALEState::apply_action(Action player_a_action, Action player_b_action) {
  // Set keys
  reset_keys(m_osystem->event());

  if (uses_paddles)
    apply_action_paddles(m_osystem->event(), player_a_action, player_b_action);
  else
    apply_action_joysticks(m_osystem->event(), player_a_action, player_b_action);
}
Beispiel #3
0
static void sdl_process_key(SDL_KeyboardEvent *ev)
{
    int keycode, v;

    if (ev->keysym.sym == SDLK_PAUSE) {
        /* specific case */
        v = 0;
        if (ev->type == SDL_KEYUP)
            v |= 0x80;
        kbd_put_keycode(0xe1);
        kbd_put_keycode(0x1d | v);
        kbd_put_keycode(0x45 | v);
        return;
    }

    if (kbd_layout) {
        keycode = sdl_keyevent_to_keycode_generic(ev);
    } else {
        keycode = sdl_keyevent_to_keycode(ev);
    }

    switch(keycode) {
    case 0x00:
        /* sent when leaving window: reset the modifiers state */
        reset_keys();
        return;
    case 0x2a:                          /* Left Shift */
    case 0x36:                          /* Right Shift */
    case 0x1d:                          /* Left CTRL */
    case 0x9d:                          /* Right CTRL */
    case 0x38:                          /* Left ALT */
    case 0xb8:                         /* Right ALT */
        if (ev->type == SDL_KEYUP)
            modifiers_state[keycode] = 0;
        else
            modifiers_state[keycode] = 1;
        break;
    case 0x45: /* num lock */
    case 0x3a: /* caps lock */
        /* SDL does not send the key up event, so we generate it */
        kbd_put_keycode(keycode);
        kbd_put_keycode(keycode | 0x80);
        return;
    }

    /* now send the key code */
    if (keycode & 0x80)
        kbd_put_keycode(0xe0);
    if (ev->type == SDL_KEYUP)
        kbd_put_keycode(keycode | 0x80);
    else
        kbd_put_keycode(keycode & 0x7f);
}
Beispiel #4
0
MainMenu::MainMenu(KeyState *keystate, Graphics *g, GameState *s, GameData *d)
{
	ks = keystate;
	gm = g;
	gs = s;
	gd = d;

	options[0] = "Play";
	options[1] = "Exit";

	option = 0;

	reset_keys();
}
Beispiel #5
0
static void sdl_process_key(SDL_KeyboardEvent *ev)
{
    int keycode;

    if (ev->keysym.sym == SDLK_PAUSE) {
        /* specific case */
        qemu_input_event_send_key_qcode(dcl->con, Q_KEY_CODE_PAUSE,
                                        ev->type == SDL_KEYDOWN);
        return;
    }

    if (kbd_layout) {
        keycode = sdl_keyevent_to_keycode_generic(ev);
    } else {
        keycode = sdl_keyevent_to_keycode(ev);
    }

    switch(keycode) {
    case 0x00:
        /* sent when leaving window: reset the modifiers state */
        reset_keys();
        return;
    case 0x2a:                          /* Left Shift */
    case 0x36:                          /* Right Shift */
    case 0x1d:                          /* Left CTRL */
    case 0x9d:                          /* Right CTRL */
    case 0x38:                          /* Left ALT */
    case 0xb8:                         /* Right ALT */
        if (ev->type == SDL_KEYUP)
            modifiers_state[keycode] = 0;
        else
            modifiers_state[keycode] = 1;
        break;
#define QEMU_SDL_VERSION ((SDL_MAJOR_VERSION << 8) + SDL_MINOR_VERSION)
#if QEMU_SDL_VERSION < 0x102 || QEMU_SDL_VERSION == 0x102 && SDL_PATCHLEVEL < 14
        /* SDL versions before 1.2.14 don't support key up for caps/num lock. */
    case 0x45: /* num lock */
    case 0x3a: /* caps lock */
        /* SDL does not send the key up event, so we generate it */
        qemu_input_event_send_key_number(dcl->con, keycode, true);
        qemu_input_event_send_key_number(dcl->con, keycode, false);
        return;
#endif
    }

    /* now send the key code */
    qemu_input_event_send_key_number(dcl->con, keycode,
                                     ev->type == SDL_KEYDOWN);
}
/* ***************************************************************************
 *  Function apply_action
 *  Applies the actions recieved from the controller for player A and B
 * ***************************************************************************/
void ALEState::apply_action(Action player_a_action, Action player_b_action) {
  // Convert illegal actions into NOOPs; actions such as reset are always legal
  if (player_a_action < (Action)PLAYER_B_NOOP && !m_settings->isLegal(player_a_action))
    player_a_action = (Action)PLAYER_A_NOOP;
  if (player_b_action < (Action)RESET && !m_settings->isLegal((Action)((int)player_b_action - PLAYER_B_NOOP)))
    player_b_action = (Action)PLAYER_B_NOOP;

  // Set keys
  reset_keys(m_osystem->event());

  if (uses_paddles)
    apply_action_paddles(m_osystem->event(), player_a_action, player_b_action);
  else
    apply_action_joysticks(m_osystem->event(), player_a_action, player_b_action);
}
Beispiel #7
0
PauseMenu::PauseMenu(KeyState *keystate, Graphics *g, GameState *s, GameData *d)
{
	gm = g;
	ks = keystate;
	gs = s;
	gd = d;

	options[0] = "Resume";
	options[1] = "Restart";
	options[2] = "Main Menu";
	options[3] = "Exit";

	option = 0;

	reset_keys();
}
Beispiel #8
0
void PauseMenu::update()
{
	if (ks->key_up)
		option --;
	if (ks->key_down)
		option ++;
	if (ks->key_space)
		execute_option(option);
	if (ks->key_pause)
	{
		option = 0;
		execute_option(option);
	}

	reset_keys();

	while (option >= MAX_OPTIONS)
		option -= MAX_OPTIONS;
	while (option < 0)
		option += MAX_OPTIONS;
}
Beispiel #9
0
Ship* get_ship(int x, int y)
{
    SDL_Surface *fb = SDL_GetVideoSurface();
    int bpp = fb->pitch / fb->w;
    Ship* ship = malloc(sizeof(Ship));
    ship->pos = malloc(sizeof(Vector));
    set_vector(ship->pos, x, y);
    ship->v = malloc(sizeof(Vector));
    set_vector(ship->v, 0, 0);
    ship->dv = 2;
    ship->rot = 0;
    ship->vrot = 0;
    ship->arot = 0.5;
    ship->bullets = new_array(sizeof (Bullet));
    ship->particles = new_array(sizeof(Particle));

    if (!ship_sprite){
        bmp_file *bmp = read_bmp("Sprites/ship.bmp");
        ship_sprite = malloc(sizeof(Sprite));
        ship_sprite->pixels = convert_bmp_to_pixels(bmp, 4);
        ship_sprite->w = get_bmp_width(bmp);
        ship_sprite->h = get_bmp_height(bmp);
        ship_sprite->bpp = 4;//get_bmp_bits_per_pixel(bmp);
        free_bmp(bmp);
    }

    ship->sprite = *ship_sprite;

    int rrad = ship->sprite.w/sin(45); //rotation buffer width and height
    Sprite rotBuffer = {malloc(sizeof(int) * rrad * rrad), rrad, rrad, bpp};
    memset(rotBuffer.pixels, 0, sizeof(int) * rrad * rrad);
    rotate_sprite(ship->sprite, rotBuffer, 0);
    ship->rot_buffer = rotBuffer;
    ship->rainbow = SDL_CreateRGBSurface(SDL_SWSURFACE, fb->w, fb->h, 8*fb->pitch/fb->w, 0, 0, 0, 0);
    int bytes = fb->h * fb->pitch;
    memset(ship->rainbow->pixels, 0, bytes);
    reset_keys();
    return ship;
}
Beispiel #10
0
int init(const char *appTitle, int flags) {
	flags |= SDL_WINDOW_SHOWN;

	rlog("Creating Window.");

	win = SDL_CreateWindow(appTitle, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screenWidth, screenHeight, flags);
	if(!win) {
		rerror("SDL_CreateWindow: %s", SDL_GetError());
		return 0;
	}

	ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
	if(!ren) {
		rerror("SDL_CreateRenderer: %s", SDL_GetError());
		return 0;
	}

    SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, filter);

	rlog("Window Created.");

    if(SDL_ShowCursor(show_cursor) < 0) {
        rerror("SDL_ShowCursor: %s", SDL_GetError());
    }

	bmp = bm_create(virt_width, virt_height);

	tex = SDL_CreateTexture(ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, bmp->w, bmp->h);
	if(!tex) {
		rerror("SDL_CreateTexture: %s", SDL_GetError());
		return 0;
	}
	rlog("Texture Created.");

	reset_keys();

	return 1;
}
Beispiel #11
0
Datei: main.c Projekt: jcnix/c8
int main(int argc, char** argv)
{
	srand(time(NULL));
	struct chip8 cpu;

	initialize(&cpu);
	load_game(&cpu, argv[1]);

	//setup graphics
	SDL_Window *window = NULL;
	SDL_Surface *screen = NULL;
	if(SDL_Init(SDL_INIT_VIDEO) < 0)
	{
		printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
	}
	else
	{
		window = SDL_CreateWindow( "Chip8", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
		if(!window)
		{
			printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() );
		}
		else
		{
			//Get window surface
			screen = SDL_GetWindowSurface(window);

			//Fill the surface white
			SDL_FillRect( screen, NULL, SDL_MapRGB(screen->format, 0xFF, 0xFF, 0xFF ) );
			
			//Update the surface
			SDL_UpdateWindowSurface(window);
		}
	}

	SDL_Surface *s;
	s = SDL_CreateRGBSurface(0, 640, 320, 32, 0,0,0,0);
	SDL_FillRect(s, NULL, SDL_MapRGB(s->format, 0, 0, 0));
	SDL_Surface *pixel = NULL;
	pixel = SDL_LoadBMP("pixel.bmp");
	if(!pixel)
	{
			printf( "Unable to load image! SDL Error: %s\n", SDL_GetError() );
	}
	SDL_BlitSurface(s, NULL, screen, NULL);
	SDL_BlitSurface(pixel, NULL, screen, NULL);
	SDL_UpdateWindowSurface(window);
	
	//init keys
	reset_keys(&cpu);

	int quit = 0;
	while(!quit)
	{
		usleep(1000);
		emulate_cycle(&cpu);
		if(cpu.drawFlag)
		{
			//draw graphics
			SDL_BlitSurface(s, NULL, screen, NULL);
			for(int i = 0; i < DISP_T; i++)
			{
				if(cpu.gfx[i])
				{
					int x = (i % 64) * 10;
					int y = (i / 64) *10;
					SDL_Rect r;
					r.x = x;
					r.y = y;
					r.w = 10;
					r.h = 10;
					SDL_BlitSurface(pixel, NULL, screen, &r);
				}
			}
			SDL_UpdateWindowSurface(window);
			cpu.drawFlag = 0;
		}

		//set keys
		reset_keys(&cpu);
		SDL_Event e;
		SDL_PollEvent(&e);
		if(e.type == SDL_QUIT) {
			quit = 1;
		} else if(e.type == SDL_KEYDOWN) {
			long k = e.key.keysym.sym;
			switch(k) {
				case SDLK_1:
					cpu.keys[0] = 1;
					break;
				case SDLK_2:
					cpu.keys[1] = 1;
					break;
				case SDLK_3:
					cpu.keys[2] = 1;
					break;
				case SDLK_4:
					cpu.keys[3] = 1;
					break;
				case SDLK_q:
					cpu.keys[4] = 1;
					break;
				case SDLK_w:
					cpu.keys[5] = 1;
					break;
				case SDLK_e:
					cpu.keys[6] = 1;
					break;
				case SDLK_r:
					cpu.keys[7] = 1;
					break;
				case SDLK_a:
					cpu.keys[8] = 1;
					break;
				case SDLK_s:
					cpu.keys[9] = 1;
					break;	
				case SDLK_d:
					cpu.keys[10] = 1;
					break;
				case SDLK_f:
					cpu.keys[11] = 1;
					break;
				case SDLK_z:
					cpu.keys[12] = 1;
					break;
				case SDLK_x:
					cpu.keys[13] = 1;
					break;
				case SDLK_c:
					cpu.keys[14] = 1;
					break;
				case SDLK_v:
					cpu.keys[15] = 1;
					break;
			}
		}
	}

	SDL_FreeSurface(s);
	SDL_FreeSurface(pixel);
	pixel = NULL;

	SDL_DestroyWindow(window);
	SDL_DestroyWindow(screen);
	SDL_Quit();

	return 0;
}
Beispiel #12
0
static void sdl_refresh(DisplayState *ds)
{
    SDL_Event ev1, *ev = &ev1;
    int mod_state;

    if (last_vm_running != vm_running) {
        last_vm_running = vm_running;
        sdl_update_caption();
    }

    vga_hw_update();

    while (SDL_PollEvent(ev)) {
        switch (ev->type) {
        case SDL_VIDEOEXPOSE:
            sdl_update(ds, 0, 0, screen->w, screen->h);
            break;
        case SDL_KEYDOWN:
        case SDL_KEYUP:
            if (ev->type == SDL_KEYDOWN) {
                mod_state = (SDL_GetModState() & gui_grab_code) ==
                            gui_grab_code;
                gui_key_modifier_pressed = mod_state;
                if (gui_key_modifier_pressed) {
                    int keycode;
                    keycode = sdl_keyevent_to_keycode(&ev->key);
                    switch(keycode) {
                    case 0x21: /* 'f' key on US keyboard */
                        toggle_full_screen(ds);
                        gui_keysym = 1;
                        break;
                    case 0x02 ... 0x0a: /* '1' to '9' keys */
                        /* Reset the modifiers sent to the current console */
                        reset_keys();
                        console_select(keycode - 0x02);
                        if (!is_graphic_console()) {
                            /* display grab if going to a text console */
                            if (gui_grab)
                                sdl_grab_end();
                        }
                        gui_keysym = 1;
                        break;
                    default:
                        break;
                    }
                } else if (!is_graphic_console()) {
                    int keysym;
                    keysym = 0;
                    if (ev->key.keysym.mod & (KMOD_LCTRL | KMOD_RCTRL)) {
                        switch(ev->key.keysym.sym) {
                        case SDLK_UP:
                            keysym = QEMU_KEY_CTRL_UP;
                            break;
                        case SDLK_DOWN:
                            keysym = QEMU_KEY_CTRL_DOWN;
                            break;
                        case SDLK_LEFT:
                            keysym = QEMU_KEY_CTRL_LEFT;
                            break;
                        case SDLK_RIGHT:
                            keysym = QEMU_KEY_CTRL_RIGHT;
                            break;
                        case SDLK_HOME:
                            keysym = QEMU_KEY_CTRL_HOME;
                            break;
                        case SDLK_END:
                            keysym = QEMU_KEY_CTRL_END;
                            break;
                        case SDLK_PAGEUP:
                            keysym = QEMU_KEY_CTRL_PAGEUP;
                            break;
                        case SDLK_PAGEDOWN:
                            keysym = QEMU_KEY_CTRL_PAGEDOWN;
                            break;
                        default:
                            break;
                        }
                    } else {
                        switch(ev->key.keysym.sym) {
                        case SDLK_UP:
                            keysym = QEMU_KEY_UP;
                            break;
                        case SDLK_DOWN:
                            keysym = QEMU_KEY_DOWN;
                            break;
                        case SDLK_LEFT:
                            keysym = QEMU_KEY_LEFT;
                            break;
                        case SDLK_RIGHT:
                            keysym = QEMU_KEY_RIGHT;
                            break;
                        case SDLK_HOME:
                            keysym = QEMU_KEY_HOME;
                            break;
                        case SDLK_END:
                            keysym = QEMU_KEY_END;
                            break;
                        case SDLK_PAGEUP:
                            keysym = QEMU_KEY_PAGEUP;
                            break;
                        case SDLK_PAGEDOWN:
                            keysym = QEMU_KEY_PAGEDOWN;
                            break;
                        case SDLK_BACKSPACE:
                            keysym = QEMU_KEY_BACKSPACE;
                            break;
                        case SDLK_DELETE:
                            keysym = QEMU_KEY_DELETE;
                            break;
                        default:
                            break;
                        }
                    }
                    if (keysym) {
                        kbd_put_keysym(keysym);
                    } else if (ev->key.keysym.unicode != 0) {
                        kbd_put_keysym(ev->key.keysym.unicode);
                    }
                }
            } else if (ev->type == SDL_KEYUP) {
Beispiel #13
0
static void handle_keydown(DisplayState *ds, SDL_Event *ev)
{
    int mod_state;
    int keycode;

    if (alt_grab) {
        mod_state = (SDL_GetModState() & (gui_grab_code | KMOD_LSHIFT)) ==
                    (gui_grab_code | KMOD_LSHIFT);
    } else if (ctrl_grab) {
        mod_state = (SDL_GetModState() & KMOD_RCTRL) == KMOD_RCTRL;
    } else {
        mod_state = (SDL_GetModState() & gui_grab_code) == gui_grab_code;
    }
    gui_key_modifier_pressed = mod_state;

    if (gui_key_modifier_pressed) {
        keycode = sdl_keyevent_to_keycode(&ev->key);
        switch (keycode) {
        case 0x21: /* 'f' key on US keyboard */
            toggle_full_screen(ds);
            gui_keysym = 1;
            break;
        case 0x16: /* 'u' key on US keyboard */
            if (scaling_active) {
                scaling_active = 0;
                sdl_resize(ds);
                vga_hw_invalidate();
                vga_hw_update();
            }
            gui_keysym = 1;
            break;
        case 0x02 ... 0x0a: /* '1' to '9' keys */
            /* Reset the modifiers sent to the current console */
            reset_keys();
            console_select(keycode - 0x02);
            gui_keysym = 1;
            if (gui_fullscreen) {
                break;
            }
            if (!is_graphic_console()) {
                /* release grab if going to a text console */
                if (gui_grab) {
                    sdl_grab_end();
                } else if (absolute_enabled) {
                    sdl_show_cursor();
                }
            } else if (absolute_enabled) {
                sdl_hide_cursor();
                absolute_mouse_grab();
            }
            break;
        case 0x1b: /* '+' */
        case 0x35: /* '-' */
            if (!gui_fullscreen) {
                int width = MAX(real_screen->w + (keycode == 0x1b ? 50 : -50),
                                160);
                int height = (ds_get_height(ds) * width) / ds_get_width(ds);

                sdl_scale(ds, width, height);
                vga_hw_invalidate();
                vga_hw_update();
                gui_keysym = 1;
            }
        default:
            break;
        }
    } else if (!is_graphic_console()) {
Beispiel #14
0
static void sdl_refresh(DisplayState *ds)
{
    SDL_Event ev1, *ev = &ev1;
    int mod_state;

    if (last_vm_running != vm_running) {
        last_vm_running = vm_running;
        sdl_update_caption();
    }

    vga_hw_update();

    while (SDL_PollEvent(ev)) {
        switch (ev->type) {
        case SDL_VIDEOEXPOSE:
            sdl_update(ds, 0, 0, screen->w, screen->h);
            break;
        case SDL_KEYDOWN:
        case SDL_KEYUP:
            if (ev->type == SDL_KEYDOWN) {
                if (!alt_grab) {
                    mod_state = (SDL_GetModState() & gui_grab_code) ==
                                gui_grab_code;
                } else {
                    mod_state = (SDL_GetModState() & (gui_grab_code | KMOD_LSHIFT)) ==
                                (gui_grab_code | KMOD_LSHIFT);
                }
                gui_key_modifier_pressed = mod_state;
                if (gui_key_modifier_pressed) {
                    int keycode;
                    keycode = sdl_keyevent_to_keycode(&ev->key);
                    switch(keycode) {
                    case 0x21: /* 'f' key on US keyboard */
                        toggle_full_screen(ds);
                        gui_keysym = 1;
                        break;
                    case 0x02 ... 0x0a: /* '1' to '9' keys */
                        /* Reset the modifiers sent to the current console */
                        reset_keys();
                        console_select(keycode - 0x02);
                        if (!is_graphic_console()) {
                            /* display grab if going to a text console */
                            if (gui_grab)
                                sdl_grab_end();
                        }
                        gui_keysym = 1;
                        break;
                    default:
                        break;
                    }
                } else if (!is_graphic_console()) {
                    int keysym;
                    keysym = 0;
                    if (ev->key.keysym.mod & (KMOD_LCTRL | KMOD_RCTRL)) {
                        switch(ev->key.keysym.sym) {
                        case SDLK_UP: keysym = QEMU_KEY_CTRL_UP; break;
                        case SDLK_DOWN: keysym = QEMU_KEY_CTRL_DOWN; break;
                        case SDLK_LEFT: keysym = QEMU_KEY_CTRL_LEFT; break;
                        case SDLK_RIGHT: keysym = QEMU_KEY_CTRL_RIGHT; break;
                        case SDLK_HOME: keysym = QEMU_KEY_CTRL_HOME; break;
                        case SDLK_END: keysym = QEMU_KEY_CTRL_END; break;
                        case SDLK_PAGEUP: keysym = QEMU_KEY_CTRL_PAGEUP; break;
                        case SDLK_PAGEDOWN: keysym = QEMU_KEY_CTRL_PAGEDOWN; break;
                        default: break;
                        }
                    } else {
                        switch(ev->key.keysym.sym) {
                        case SDLK_UP: keysym = QEMU_KEY_UP; break;
                        case SDLK_DOWN: keysym = QEMU_KEY_DOWN; break;
                        case SDLK_LEFT: keysym = QEMU_KEY_LEFT; break;
                        case SDLK_RIGHT: keysym = QEMU_KEY_RIGHT; break;
                        case SDLK_HOME: keysym = QEMU_KEY_HOME; break;
                        case SDLK_END: keysym = QEMU_KEY_END; break;
                        case SDLK_PAGEUP: keysym = QEMU_KEY_PAGEUP; break;
                        case SDLK_PAGEDOWN: keysym = QEMU_KEY_PAGEDOWN; break;
                        case SDLK_BACKSPACE: keysym = QEMU_KEY_BACKSPACE; break;
                        case SDLK_DELETE: keysym = QEMU_KEY_DELETE; break;
                        default: break;
                        }
                    }
                    if (keysym) {
                        kbd_put_keysym(keysym);
                    } else if (ev->key.keysym.unicode != 0) {
                        kbd_put_keysym(ev->key.keysym.unicode);
                    }
                }
            } else if (ev->type == SDL_KEYUP) {
                if (!alt_grab) {
                    mod_state = (ev->key.keysym.mod & gui_grab_code);
                } else {
                    mod_state = (ev->key.keysym.mod &
                                 (gui_grab_code | KMOD_LSHIFT));
                }
                if (!mod_state) {
                    if (gui_key_modifier_pressed) {
                        gui_key_modifier_pressed = 0;
                        if (gui_keysym == 0) {
                            /* exit/enter grab if pressing Ctrl-Alt */
                            if (!gui_grab) {
                                /* if the application is not active,
                                   do not try to enter grab state. It
                                   prevents
                                   'SDL_WM_GrabInput(SDL_GRAB_ON)'
                                   from blocking all the application
                                   (SDL bug). */
                                if (SDL_GetAppState() & SDL_APPACTIVE)
                                    sdl_grab_start();
                            } else {
                                sdl_grab_end();
                            }
                            /* SDL does not send back all the
                               modifiers key, so we must correct it */
                            reset_keys();
                            break;
                        }
                        gui_keysym = 0;
                    }
                }
            }
            if (is_graphic_console() && !gui_keysym)
                sdl_process_key(&ev->key);
            break;
        case SDL_QUIT:
            if (!no_quit) {
                qemu_system_shutdown_request();
                vm_start();	/* In case we're paused */
            }
            break;
        case SDL_MOUSEMOTION:
            if (gui_grab || kbd_mouse_is_absolute() ||
                absolute_enabled) {
                sdl_send_mouse_event(0);
            }
            break;
        case SDL_MOUSEBUTTONDOWN:
        case SDL_MOUSEBUTTONUP:
            {
                SDL_MouseButtonEvent *bev = &ev->button;
                if (!gui_grab && !kbd_mouse_is_absolute()) {
                    if (ev->type == SDL_MOUSEBUTTONDOWN &&
                        (bev->state & SDL_BUTTON_LMASK)) {
                        /* start grabbing all events */
                        sdl_grab_start();
                    }
                } else {
                    int dz;
                    dz = 0;
#ifdef SDL_BUTTON_WHEELUP
                    if (bev->button == SDL_BUTTON_WHEELUP && ev->type == SDL_MOUSEBUTTONDOWN) {
                        dz = -1;
                    } else if (bev->button == SDL_BUTTON_WHEELDOWN && ev->type == SDL_MOUSEBUTTONDOWN) {
                        dz = 1;
                    }
#endif
                    sdl_send_mouse_event(dz);
                }
            }
            break;
        case SDL_ACTIVEEVENT:
            if (gui_grab && ev->active.state == SDL_APPINPUTFOCUS &&
                !ev->active.gain && !gui_fullscreen_initial_grab) {
                sdl_grab_end();
            }
            break;
        default:
            break;
        }
Beispiel #15
0
void MainMenu::reset()
{
	option = 0;
	reset_keys();
}
Beispiel #16
0
void PauseMenu::reset()
{
	option = 0;
	reset_keys();
}
static void sdl_gui_process_events(void)
{
    SDL_Event ev1, *ev = &ev1;
    int mod_state;
    int buttonstate = SDL_GetMouseState(NULL, NULL);

    gui_refresh_caption();

    /*vga_hw_update();*/
    SDL_EnableUNICODE(kbd_in_terminal_mode);

    while (SDL_PollEvent(ev)) {
        switch (ev->type) {
        case SDL_VIDEOEXPOSE:
            gui_notify_repaint_screen();
            break;
        case SDL_KEYDOWN:
        case SDL_KEYUP:
            if (ev->type == SDL_KEYDOWN) {
                if (!alt_grab) {
                    mod_state = (SDL_GetModState() & gui_grab_code) ==
                                gui_grab_code;
                } else {
                    mod_state = (SDL_GetModState() & (gui_grab_code | KMOD_LSHIFT)) ==
                                (gui_grab_code | KMOD_LSHIFT);
                }
                gui_key_modifier_pressed = mod_state;
                if (gui_key_modifier_pressed) {
                    int keycode;
                    keycode = sdl_keyevent_to_keycode(&ev->key);
                    switch(keycode) {
                    case 0x21: /* 'f' key on US keyboard */
                        if (gui_allows_fullscreen()) {
                            gui_notify_toggle_fullscreen();
                            special_key_combination = 1;
                        }
                        break;
                    case 0x02 ... 0x0a: /* '1' to '9' keys */
                        /* Reset the modifiers sent to the current console */
                        reset_keys();
                        gui_notify_console_select(keycode - 0x02);
                        special_key_combination = 1;
                        break;
                    default:
                        break;
                    }
                } else if (kbd_in_terminal_mode) {
                    int keysym;
                    keysym = 0;
                    if (ev->key.keysym.mod & (KMOD_LCTRL | KMOD_RCTRL)) {
                        switch(ev->key.keysym.sym) {
                        case SDLK_UP: keysym = QEMU_KEY_CTRL_UP; break;
                        case SDLK_DOWN: keysym = QEMU_KEY_CTRL_DOWN; break;
                        case SDLK_LEFT: keysym = QEMU_KEY_CTRL_LEFT; break;
                        case SDLK_RIGHT: keysym = QEMU_KEY_CTRL_RIGHT; break;
                        case SDLK_HOME: keysym = QEMU_KEY_CTRL_HOME; break;
                        case SDLK_END: keysym = QEMU_KEY_CTRL_END; break;
                        case SDLK_PAGEUP: keysym = QEMU_KEY_CTRL_PAGEUP; break;
                        case SDLK_PAGEDOWN: keysym = QEMU_KEY_CTRL_PAGEDOWN; break;
                        default: break;
                        }
                    } else {
                        switch(ev->key.keysym.sym) {
                        case SDLK_UP: keysym = QEMU_KEY_UP; break;
                        case SDLK_DOWN: keysym = QEMU_KEY_DOWN; break;
                        case SDLK_LEFT: keysym = QEMU_KEY_LEFT; break;
                        case SDLK_RIGHT: keysym = QEMU_KEY_RIGHT; break;
                        case SDLK_HOME: keysym = QEMU_KEY_HOME; break;
                        case SDLK_END: keysym = QEMU_KEY_END; break;
                        case SDLK_PAGEUP: keysym = QEMU_KEY_PAGEUP; break;
                        case SDLK_PAGEDOWN: keysym = QEMU_KEY_PAGEDOWN; break;
                        case SDLK_BACKSPACE: keysym = QEMU_KEY_BACKSPACE; break;
                        case SDLK_DELETE: keysym = QEMU_KEY_DELETE; break;
                        default: break;
                        }
                    }
                    if (keysym) {
                        gui_notify_term_key(keysym);
                    } else if (ev->key.keysym.unicode != 0) {
                        gui_notify_term_key(ev->key.keysym.unicode);
                    }
                }
            } else if (ev->type == SDL_KEYUP) {
                if (!alt_grab) {
                    mod_state = (ev->key.keysym.mod & gui_grab_code);
                } else {
                    mod_state = (ev->key.keysym.mod &
                                 (gui_grab_code | KMOD_LSHIFT));
                }
                if (!mod_state) {
                    if (gui_key_modifier_pressed) {
                        gui_key_modifier_pressed = 0;
                        if (!special_key_combination) {
                            /* exit/enter grab if pressing Ctrl-Alt */
                            gui_notify_toggle_grabmode();
                            /* SDL does not send back all the
                               modifiers key, so we must correct it */
                            reset_keys();
                            break;
                        }
                        special_key_combination = 0;
                    }
                }
            }
            if (!kbd_in_terminal_mode && !special_key_combination)
                sdl_process_key(&ev->key);
            break;
        case SDL_QUIT:
            if (!no_quit)
                qemu_system_shutdown_request();
            break;
        case SDL_MOUSEMOTION:
            gui_notify_mouse_motion(ev->motion.xrel, ev->motion.yrel, 0,
                                    ev->motion.x, ev->motion.y, 
                                    sdl_state_to_qemu(ev->motion.state));
            break;
        case SDL_MOUSEBUTTONDOWN:
        case SDL_MOUSEBUTTONUP:
            {
                SDL_MouseButtonEvent *bev = &ev->button;
                int dz = 0;

                if (ev->type == SDL_MOUSEBUTTONDOWN) {
                    buttonstate |= SDL_BUTTON(bev->button);
                } else {
                    buttonstate &= ~SDL_BUTTON(bev->button);
                }
#ifdef SDL_BUTTON_WHEELUP
                if (bev->button == SDL_BUTTON_WHEELUP && ev->type == SDL_MOUSEBUTTONDOWN) {
                    dz = -1;
                } else if (bev->button == SDL_BUTTON_WHEELDOWN && ev->type == SDL_MOUSEBUTTONDOWN) {
                    dz = 1;
                }
#endif
                gui_notify_mouse_button(dz, bev->x, bev->y, sdl_state_to_qemu(buttonstate));
            }
            break;
        case SDL_ACTIVEEVENT:
            if (ev->active.state == SDL_APPINPUTFOCUS && !ev->active.gain) {
                gui_notify_input_focus_lost();
            } else if (ev->active.state & SDL_APPACTIVE) {
                gui_notify_app_focus(ev->active.gain);
            }
            break;
        default:
            break;
        }
Beispiel #18
0
static void sdl_refresh(DisplayState *ds)
{
    SDL_Event ev1, *ev = &ev1;
    int mod_state;
    int buttonstate = SDL_GetMouseState(NULL, NULL);

    if (last_vm_running != vm_running) {
        last_vm_running = vm_running;
        sdl_update_caption();
    }

    vga_hw_update();
    SDL_EnableUNICODE(!is_graphic_console());

    while (SDL_PollEvent(ev)) {
        switch (ev->type) {
        case SDL_VIDEOEXPOSE:
            sdl_update(ds, 0, 0, real_screen->w, real_screen->h);
            break;
        case SDL_KEYDOWN:
        case SDL_KEYUP:
            if (ev->type == SDL_KEYDOWN) {
                if (alt_grab) {
                    mod_state = (SDL_GetModState() & (gui_grab_code | KMOD_LSHIFT)) ==
                                (gui_grab_code | KMOD_LSHIFT);
                } else if (ctrl_grab) {
                    mod_state = (SDL_GetModState() & KMOD_RCTRL) == KMOD_RCTRL;
                } else {
                    mod_state = (SDL_GetModState() & gui_grab_code) ==
                                gui_grab_code;
                }
                gui_key_modifier_pressed = mod_state;
                if (gui_key_modifier_pressed) {
                    int keycode;
                    keycode = sdl_keyevent_to_keycode(&ev->key);
                    switch(keycode) {
                    case 0x21: /* 'f' key on US keyboard */
                        toggle_full_screen(ds);
                        gui_keysym = 1;
                        break;
                    case 0x16: /* 'u' key on US keyboard */
                        scaling_active = 0;
                        sdl_resize(ds);
                        vga_hw_invalidate();
                        vga_hw_update();
                        break;
                    case 0x02 ... 0x0a: /* '1' to '9' keys */
                        /* Reset the modifiers sent to the current console */
                        reset_keys();
                        console_select(keycode - 0x02);
                        if (!is_graphic_console()) {
                            /* display grab if going to a text console */
                            if (gui_grab)
                                sdl_grab_end();
                        }
                        gui_keysym = 1;
                        break;
                    default:
                        break;
                    }
                } else if (!is_graphic_console()) {
                    int keysym;
                    keysym = 0;
                    if (ev->key.keysym.mod & (KMOD_LCTRL | KMOD_RCTRL)) {
                        switch(ev->key.keysym.sym) {
                        case SDLK_UP: keysym = QEMU_KEY_CTRL_UP; break;
                        case SDLK_DOWN: keysym = QEMU_KEY_CTRL_DOWN; break;
                        case SDLK_LEFT: keysym = QEMU_KEY_CTRL_LEFT; break;
                        case SDLK_RIGHT: keysym = QEMU_KEY_CTRL_RIGHT; break;
                        case SDLK_HOME: keysym = QEMU_KEY_CTRL_HOME; break;
                        case SDLK_END: keysym = QEMU_KEY_CTRL_END; break;
                        case SDLK_PAGEUP: keysym = QEMU_KEY_CTRL_PAGEUP; break;
                        case SDLK_PAGEDOWN: keysym = QEMU_KEY_CTRL_PAGEDOWN; break;
                        default: break;
                        }
                    } else {
                        switch(ev->key.keysym.sym) {
                        case SDLK_UP: keysym = QEMU_KEY_UP; break;
                        case SDLK_DOWN: keysym = QEMU_KEY_DOWN; break;
                        case SDLK_LEFT: keysym = QEMU_KEY_LEFT; break;
                        case SDLK_RIGHT: keysym = QEMU_KEY_RIGHT; break;
                        case SDLK_HOME: keysym = QEMU_KEY_HOME; break;
                        case SDLK_END: keysym = QEMU_KEY_END; break;
                        case SDLK_PAGEUP: keysym = QEMU_KEY_PAGEUP; break;
                        case SDLK_PAGEDOWN: keysym = QEMU_KEY_PAGEDOWN; break;
                        case SDLK_BACKSPACE: keysym = QEMU_KEY_BACKSPACE; break;
                        case SDLK_DELETE: keysym = QEMU_KEY_DELETE; break;
                        default: break;
                        }
                    }
                    if (keysym) {
                        kbd_put_keysym(keysym);
                    } else if (ev->key.keysym.unicode != 0) {
                        kbd_put_keysym(ev->key.keysym.unicode);
                    }
                }
            } else if (ev->type == SDL_KEYUP) {
                if (!alt_grab) {
                    mod_state = (ev->key.keysym.mod & gui_grab_code);
                } else {
                    mod_state = (ev->key.keysym.mod &
                                 (gui_grab_code | KMOD_LSHIFT));
                }
                if (!mod_state) {
                    if (gui_key_modifier_pressed) {
                        gui_key_modifier_pressed = 0;
                        if (gui_keysym == 0) {
                            /* exit/enter grab if pressing Ctrl-Alt */
                            if (!gui_grab) {
                                /* if the application is not active,
                                   do not try to enter grab state. It
                                   prevents
                                   'SDL_WM_GrabInput(SDL_GRAB_ON)'
                                   from blocking all the application
                                   (SDL bug). */
                                if (SDL_GetAppState() & SDL_APPACTIVE)
                                    sdl_grab_start();
                            } else {
                                sdl_grab_end();
                            }
                            /* SDL does not send back all the
                               modifiers key, so we must correct it */
                            reset_keys();
                            break;
                        }
                        gui_keysym = 0;
                    }
                }
            }
            if (is_graphic_console() && !gui_keysym)
                sdl_process_key(&ev->key);
            break;
        case SDL_QUIT:
            if (!no_quit)
                qemu_system_shutdown_request();
            break;
        case SDL_MOUSEMOTION:
            if (gui_grab || kbd_mouse_is_absolute() ||
                absolute_enabled) {
                sdl_send_mouse_event(ev->motion.xrel, ev->motion.yrel, 0,
                       ev->motion.x, ev->motion.y, ev->motion.state);
            }
            break;
        case SDL_MOUSEBUTTONDOWN:
        case SDL_MOUSEBUTTONUP:
            {
                SDL_MouseButtonEvent *bev = &ev->button;
                if (!gui_grab && !kbd_mouse_is_absolute()) {
                    if (ev->type == SDL_MOUSEBUTTONDOWN &&
                        (bev->button == SDL_BUTTON_LEFT)) {
                        /* start grabbing all events */
                        sdl_grab_start();
                    }
                } else {
                    int dz;
                    dz = 0;
                    if (ev->type == SDL_MOUSEBUTTONDOWN) {
                        buttonstate |= SDL_BUTTON(bev->button);
                    } else {
                        buttonstate &= ~SDL_BUTTON(bev->button);
                    }
#ifdef SDL_BUTTON_WHEELUP
                    if (bev->button == SDL_BUTTON_WHEELUP && ev->type == SDL_MOUSEBUTTONDOWN) {
                        dz = -1;
                    } else if (bev->button == SDL_BUTTON_WHEELDOWN && ev->type == SDL_MOUSEBUTTONDOWN) {
                        dz = 1;
                    }
#endif
                    sdl_send_mouse_event(0, 0, dz, bev->x, bev->y, buttonstate);
                }
            }
            break;
        case SDL_ACTIVEEVENT:
            if (gui_grab && ev->active.state == SDL_APPINPUTFOCUS &&
                !ev->active.gain && !gui_fullscreen_initial_grab) {
                sdl_grab_end();
            }
            if (ev->active.state & SDL_APPACTIVE) {
                if (ev->active.gain) {
                    /* Back to default interval */
                    dcl->gui_timer_interval = 0;
                    dcl->idle = 0;
                } else {
                    /* Sleeping interval */
                    dcl->gui_timer_interval = 500;
                    dcl->idle = 1;
                }
            }
            break;
	case SDL_VIDEORESIZE:
        {
	    SDL_ResizeEvent *rev = &ev->resize;
            int bpp = real_screen->format->BitsPerPixel;
            if (bpp != 16 && bpp != 32)
                bpp = 32;
            do_sdl_resize(rev->w, rev->h, bpp);
            scaling_active = 1;
            if (!is_buffer_shared(ds->surface)) {
                ds->surface = qemu_resize_displaysurface(ds, ds_get_width(ds), ds_get_height(ds));
                dpy_resize(ds);
            }
            vga_hw_invalidate();
            vga_hw_update();
            break;
        }
        default:
            break;
        }
Beispiel #19
0
int main()
{
	// set for 16 MHz clock
	CPU_PRESCALE(0);

	// Configure all port B and port D pins as inputs with pullup resistors.
	DDRD = 0x00;
	DDRB = 0x00;
	PORTB = 0xFF;
	PORTD = 0xFF;

    // Turn the LED on during the configuration
    LED_CONFIG;
    LED_ON;

	// Initialize the USB, and then wait for the host to set configuration.
	usb_init();
	while (!usb_configured());

    // Initialize the gamepad interface
    gamepad_init();

	// Wait an extra second for the PC's operating system to load drivers
	// and do whatever it does to actually be ready for input
	_delay_ms(1000);

    // Timer 0 configuration (~60Hz)
	TCCR0A = 0x00;  // Normal mode
	TCCR0B = 0x05;  // Clock/1024
	TIMSK0 = (1<<TOIE0);

    LED_OFF;

	while (1) {
        while (!ready);  // Block until the next cycle (~60Hz)
        cli();
        ready = 0;
        sei();

        // Read pressed buttons from gamepad interface
        gamepad_read();

        // Reset key array
        reset_keys();

        // Special functions
        // - Software reboot
        if (PRESSED_REBOOT) {
            reboot();
        }

        // 6 keys can be sent at a time, with any number of modifiers.
        //
        // - Buttons A, B, X and Y have their own position in the key array.
        // - Up/down and left/right pairs share one position, as they are
        //     mutually exclusive (you cannot pres up AND down).
        // - L and R use the left and right Shift modifiers.
        // - Select and Start use the left and right Ctrl modifiers.

        if (PRESSED_A) press_key(KEY_Z, 0);
        if (PRESSED_B) press_key(KEY_X, 1);
        if (PRESSED_X) press_key(KEY_A, 2);
        if (PRESSED_Y) press_key(KEY_S, 3);

        if (PRESSED_UP) {
            press_key(KEY_UP, 4);
        } else if (PRESSED_DOWN){
            press_key(KEY_DOWN, 4);
        }

        if (PRESSED_LEFT) {
            press_key(KEY_LEFT, 5);
        } else if (PRESSED_RIGHT){
            press_key(KEY_RIGHT, 5);
        }

        if (PRESSED_L) press_modifier(KEY_LEFT_SHIFT);
        if (PRESSED_R) press_modifier(KEY_RIGHT_SHIFT);
        if (PRESSED_SELECT) press_modifier(KEY_LEFT_CTRL);
        if (PRESSED_START) press_modifier(KEY_RIGHT_CTRL);

        usb_keyboard_send();
	}
}
static void handle_keydown(DisplayState *ds, SDL_Event *ev)
{
    int mod_state;
    int keycode;

    if (alt_grab) {
//    	LOGV("Found alt grab\n");
        mod_state = (SDL_GetModState() & (gui_grab_code | KMOD_LSHIFT)) ==
                    (gui_grab_code | KMOD_LSHIFT);
    } else if (ctrl_grab) {
//    	LOGV("Found ctrl grab\n");
        mod_state = (SDL_GetModState() & KMOD_RCTRL) == KMOD_RCTRL;
    } else {
//    	LOGV("Default grab\n");
        mod_state = (SDL_GetModState() & gui_grab_code) == gui_grab_code;
    }
    gui_key_modifier_pressed = mod_state;

    if (gui_key_modifier_pressed) {
        keycode = sdl_keyevent_to_keycode(&ev->key);
//        LOGV("Found modifier pressed for key/keycode = %d/%d\n", ev->key.keysym.sym, keycode);
        switch (keycode) {
        case 1: /* 'f' key on US keyboard */
        	LOGV("Keycode Pressed 'f' Fullscreen\n");
            toggle_full_screen(ds);
            gui_keysym = 1;
            break;
        case 16: /* 'u' key on US keyboard */
        	LOGV("Keycode Pressed 'u' unset Scale\n");
            if (scaling_active) {
            	LOGV("Found scaling active Unsetting...\n");
                scaling_active = 0;
                sdl_resize(ds);
                vga_hw_invalidate();
                vga_hw_update();
                reset_keys();
            }
            gui_keysym = 1;
            break;

        case 22 ... 23: /* '1' to '9' keys */ //MK hack
            /* Reset the modifiers sent to the current console */
        	LOGV("Keycode Pressed '1-9' console\n");
            reset_keys();
            console_select(keycode - 22);
            gui_keysym = 1;
//            if (gui_fullscreen) {
//            	LOGV("Found fullscreen breaking...\n");
//                break;
//            }
            if (!is_graphic_console()) {
                /* release grab if going to a text console */
            	LOGV("Found text console releasing grab...\n");
                if (gui_grab) {
                	LOGV("Found grab, grab ending...\n");
                    sdl_grab_end();
                } else if (absolute_enabled) {
                	LOGV("Found absolute_enabled, show cursor...\n");
                    sdl_show_cursor();
                }
            } else if (absolute_enabled) {
            	LOGV("Found absolute_enabled, hiding cursor and grabing mouse...\n");
                sdl_hide_cursor();
                absolute_mouse_grab();
            }
            break;
        case 24: /* '4' Zoom In */
        case 25: /* '3' Zoom Out*/
        	LOGV("Keycode Pressed '3/4' Zoom\n");
//            if (!gui_fullscreen) {
        	{

                int width = MAX(real_screen->w + (keycode == 25 ? 50 : -50),
                                160);
                int height = (ds_get_height(ds) * width) / ds_get_width(ds);
                LOGV("Found no fullscreen, scaling to: %dx%d \n", width, height);
                sdl_scale(ds, width, height);
                vga_hw_invalidate();
                vga_hw_update();
                reset_keys();
                gui_keysym = 1;
        	}
//            }
            break;
        case 26: /* Fit to Screen */
        	LOGV("Keycode Pressed '5' Fit to Screen\n");
//            if (!gui_fullscreen) {
        	{
            	int width;
            	int height;
            	AndroidGetWindowSize(&width, &height);
            	LOGV("Got Android window size=%dx%d", width, height);
            	LOGV("Got VM  resolution=%dx%d", ds_get_width(ds), ds_get_height(ds));
            	float aspectRatio = (float) ds_get_height(ds) / (float) ds_get_width(ds);
            	LOGV("Got aspectRatio=%f", aspectRatio);
            	int new_width = (int) (height / aspectRatio);
            	if(new_width > width){
            		LOGV("Width is overrun, modifying height");
            		new_width = width;
            		height = width * aspectRatio;
            	}
                LOGV("Found no fullscreen, Fit To Screen: %dx%d \n", new_width, height);
                sdl_scale(ds, new_width, height);
                vga_hw_invalidate();
                vga_hw_update();
                reset_keys();
                gui_keysym = 1;
        	}
//            }
            break;
        case 27: /* Stretch to Screen */
        	LOGV("Keycode Pressed '6' Fit to Screen\n");
//        	            if (!gui_fullscreen) {
        	            	{
        	            	int width;
        	            	int height;
        	            	AndroidGetWindowSize(&width, &height);
        	                LOGV("Found no fullscreen, Fit To Screen: %dx%d \n", width, height);
        	                sdl_scale(ds, width, height);
        	                vga_hw_invalidate();
        	                vga_hw_update();
        	                reset_keys();
        	                gui_keysym = 1;
        	            	}
//        	            }
        	            break;
        default:
        	LOGV("Default\n");
            break;
        }
    } else if (!is_graphic_console()) {
Beispiel #21
0
/**
 * Analyze /cmd type commands the player has typed in the console or bound to a key.
 * Sort out the "client intern" commands and expand or pre process them for the server.
 * @param cmd Command to check
 * @return 0 to send command to server, 1 to not send it */
int client_command_check(char *cmd)
{
	if (!strncasecmp(cmd, "/ready_spell", 12))
	{
		cmd = strchr(cmd, ' ');

		if (!cmd || *++cmd == 0)
		{
			draw_info("Usage: /ready_spell <spell name>", COLOR_GREEN);
		}
		else
		{
			int i, ii;

			for (i = 0; i < SPELL_LIST_MAX; i++)
			{
				for (ii = 0; ii < DIALOG_LIST_ENTRY; ii++)
				{
					if (spell_list[i].entry[0][ii].flag >= LIST_ENTRY_USED)
					{
						if (!strcmp(spell_list[i].entry[0][ii].name, cmd))
						{
							if (spell_list[i].entry[0][ii].flag == LIST_ENTRY_KNOWN)
							{
								fire_mode_tab[FIRE_MODE_SPELL].spell = &spell_list[i].entry[0][ii];
								RangeFireMode = FIRE_MODE_SPELL;
								sound_play_effect("scroll.ogg", MENU_SOUND_VOL);
								draw_info("Spell ready.", COLOR_GREEN);
								return 1;
							}
						}
					}

					if (spell_list[i].entry[1][ii].flag >= LIST_ENTRY_USED)
					{
						if (!strcmp(spell_list[i].entry[1][ii].name, cmd))
						{
							if (spell_list[i].entry[1][ii].flag==LIST_ENTRY_KNOWN)
							{
								fire_mode_tab[FIRE_MODE_SPELL].spell = &spell_list[i].entry[1][ii];
								RangeFireMode = FIRE_MODE_SPELL;
								sound_play_effect("scroll.ogg", MENU_SOUND_VOL);
								draw_info("Spell ready.", COLOR_GREEN);
								return 1;
							}
						}
					}
				}
			}
		}

		draw_info("Unknown spell.", COLOR_GREEN);
		return 1;
	}
	else if (!strncasecmp(cmd, "/pray", 5))
	{
		/* Give out "You are at full grace." when needed -
		 * server will not send us anything when this happens */
		if (cpl.stats.grace == cpl.stats.maxgrace)
			draw_info("You are at full grace. You stop praying.", COLOR_WHITE);
	}
	else if (!strncasecmp(cmd, "/keybind", 8))
	{
		map_udate_flag = 2;

		if (cpl.menustatus != MENU_KEYBIND)
		{
			keybind_status = KEYBIND_STATUS_NO;
			cpl.menustatus = MENU_KEYBIND;
		}
		else
		{
			save_keybind_file(KEYBIND_FILE);
			cpl.menustatus = MENU_NO;
		}

		sound_play_effect("scroll.ogg", 100);
		reset_keys();
		return 1;
	}
	else if (!strncmp(cmd, "/target", 7))
	{
		/* Logic is: if first parameter char is a digit, is enemy, friend or self.
		 * If first char a character - then it's a name of a living object. */
		if (!strncmp(cmd, "/target friend", 14))
			strcpy(cmd, "/target 1");
		else if (!strncmp(cmd,"/target enemy", 13))
			strcpy(cmd, "/target 0");
		else if (!strncmp(cmd, "/target self", 12))
			strcpy(cmd, "/target 2");
	}
	else if (!strncmp(cmd, "/help", 5))
	{
		cmd += 5;

		if (cmd == NULL || strcmp(cmd, "") == 0)
			show_help("main");
		else
			show_help(cmd + 1);

		return 1;
	}
	else if (!strncmp(cmd, "/script ", 8))
	{
		cmd += 8;

		if (!strncmp(cmd, "load ", 5))
		{
			cmd += 5;

			script_load(cmd);
		}
		if (!strncmp(cmd, "unload ", 7))
		{
			cmd += 7;

			script_unload(cmd);
		}
		else if (!strncmp(cmd, "list", 4))
		{
			script_list();
		}
		else if (!strncmp(cmd, "send ", 5))
		{
			cmd += 5;

			script_send(cmd);
		}

		return 1;
	}
	else if (!strncmp(cmd, "/shop", 5))
	{
		if (!shop_gui)
		{
			initialize_shop(SHOP_STATE_NONE);
		}
		else
		{
			draw_info("You must close the shop window before trying to set up another shop.", COLOR_RED);
		}

		return 1;
	}
	else if (!strncmp(cmd, "/ignore", 7))
	{
		ignore_command(cmd + 7);
		return 1;
	}
	else if (!strncmp(cmd, "/reply", 6))
	{
		cmd = strchr(cmd, ' ');

		if (!cmd || *++cmd == '\0')
		{
			draw_info("Usage: /reply <message>", COLOR_RED);
		}
		else
		{
			if (!cpl.player_reply[0])
			{
				draw_info("There is no one you can /reply.", COLOR_RED);
			}
			else
			{
				char buf[2048];

				snprintf(buf, sizeof(buf), "/tell %s %s", cpl.player_reply, cmd);
				send_command(buf);
			}
		}

		return 1;
	}
	else if (!strncmp(cmd, "/resetwidgets", 13))
	{
		reset_widget(NULL);
		return 1;
	}
	else if (!strncmp(cmd, "/resetwidget", 12))
	{
		cmd = strchr(cmd, ' ');

		if (!cmd || *++cmd == '\0')
		{
			draw_info("Usage: /resetwidget <name>", COLOR_RED);
		}
		else
		{
			reset_widget(cmd);
		}

		return 1;
	}

	return 0;
}