Esempio n. 1
0
void change_disk(void) {
  path_t path;

  if (swaplist.fs == NULL) {
    /* No swaplist active, try using AUTOSWAP.LST */
    /* change_disk is called from the IEC idle loop, so ops_scratch is free */
    ustrcpy_P(ops_scratch, autoswap_lst_name);
    path.dir  = partition[current_part].current_dir;
    path.part = current_part;
    if (key_pressed(KEY_PREV))
      set_changelist_internal(&path, ops_scratch, 1);
    else
      set_changelist_internal(&path, ops_scratch, 0);

    if (swaplist.fs == NULL) {
      /* No swap list found, create one if key was "home" */
      if (key_pressed(KEY_HOME)) {
        uint8_t swapname[16]; // FIXME: magic constant

        ustrcpy_P(swapname, autoswap_gen_name);

        if (create_changelist(&path, swapname)) {
          set_changelist_internal(&path, swapname, 0);
          globalflags |= AUTOSWAP_ACTIVE;
        }
      }

      /* reset error and exit */
      set_error(ERROR_OK);
      reset_key(0xff); // <- lazy
      return;
    } else {
      /* Autoswaplist found, mark it as active                */
      /* and exit because the first image is already mounted. */
      globalflags |= AUTOSWAP_ACTIVE;
      reset_key(0xff); // <- lazy
      return;
    }
  }

  /* Mount the next image in the list */
  if (key_pressed(KEY_NEXT)) {
    linenum++;
    reset_key(KEY_NEXT);
    if (mount_line())
      confirm_blink(BLINK_FORWARD);
  } else if (key_pressed(KEY_PREV)) {
    linenum--;
    reset_key(KEY_PREV);
    if (mount_line())
      confirm_blink(BLINK_BACKWARD);
  } else if (key_pressed(KEY_HOME)) {
    linenum = 0;
    reset_key(KEY_HOME);
    if (mount_line())
      confirm_blink(BLINK_HOME);
  }
}
Esempio n. 2
0
static int check_keys(void)
{
	int keys = 0;

	if (key_pressed(KEY_POWER))
		keys += KEY_POWER;
	if (key_pressed(KEY_VOLUMEUP))
		keys += KEY_VOLUMEUP;
	if (key_pressed(KEY_VOLUMEDOWN))
		keys += KEY_VOLUMEDOWN;

	return keys;
}
Esempio n. 3
0
static int update(void)
{
   progress += 1.0f / logic_framerate;

   if (progress >= duration) {
      return DEMO_STATE_MAIN_MENU;
   }

   if (key_pressed(ALLEGRO_KEY_ESCAPE)) return DEMO_STATE_MAIN_MENU;
   if (key_pressed(ALLEGRO_KEY_SPACE)) return DEMO_STATE_MAIN_MENU;
   if (key_pressed(ALLEGRO_KEY_ENTER)) return DEMO_STATE_MAIN_MENU;
   if (mouse_button_pressed(1)) return DEMO_STATE_MAIN_MENU;

   return id();
}
Esempio n. 4
0
void HaiQTextEdit::keyPressEvent ( QKeyEvent * event ) {
	if (isReadOnly()) return;
	last_keypress.start();
	if (emit_key_only_mode) {
		emit key_pressed(*event);
		event->accept();
		return;
	}
	else {
		process_key(*event);
		emit key_pressed(*event);
		event->accept();
		return;
	}
}
Esempio n. 5
0
// Handle input and events. Return 0 to quit the program, or 1 to keep running.
inline int handle_events(SDL_Event* event, vector* cursor_pos, int* cursor_interaction)
{
	while(SDL_PollEvent(event))
	{
		int x, y;

		switch(event->type)
		{
			case SDL_KEYDOWN:
				if(key_pressed(event, SDLK_ESCAPE)) return 0;
				break;
			case SDL_MOUSEBUTTONDOWN:
				if(event->button.button == 1) *cursor_interaction = 1;
				else if(event->button.button == 3) *cursor_interaction = 2;
				break;
			case SDL_MOUSEBUTTONUP:
				*cursor_interaction = 0;
				break;
			case SDL_MOUSEMOTION:
				SDL_GetMouseState(&x, &y);
				cursor_pos->x = x, cursor_pos->y = y;
				break;
			case SDL_QUIT:
				return 0;
				break;
		}
	}

	return 1;
}
Esempio n. 6
0
void check_boot_mode(void)
{
	int pwr_key;

	pwr_key = power_key_pressed(KEY_PWR_STATUS_REG);
	if (!pwr_key)
		return;

	/* Clear PWR button Rising edge interrupt status flag */
	power_key_pressed(KEY_PWR_INTERRUPT_REG);

	if (key_pressed(KEY_VOLUMEUP))
		download_menu();
	else if (key_pressed(KEY_VOLUMEDOWN))
		mode_leave_menu(BOOT_MODE_THOR);
}
Esempio n. 7
0
void	click_re_match(t_data *data, t_window *w)
{
  w->continuer = 1;
  while (w->continuer)
    {
      SDL_WaitEvent(&w->event);
      switch(w->event.type)
	{
	case SDL_QUIT:
	  quit_game(w);
	case SDL_KEYDOWN:
	  key_pressed(data, w);
	case SDL_MOUSEBUTTONUP:
	  w->x = w->event.button.x;
	  w->continuer = 0;
	case SDL_MOUSEMOTION:
	  SDL_BlitSurface(w->background_r, NULL, w->ecran, &w->pos_background_c);
	  w->pos_cursor.x = w->event.motion.x - 128;
	  w->pos_cursor.y = w->event.motion.y - 64;
	  SDL_BlitSurface(w->cursor, NULL, w->ecran, &w->pos_cursor);
	  SDL_Flip(w->ecran);
	  break;
	}
    }
  if_click_re_match(data, w);
}
Esempio n. 8
0
File: dawm.c Progetto: dstenb/dawm
void
handler_keypress(XEvent *ev)
{
	XKeyEvent *kev = &ev->xkey;
	struct key *key;

	dbg_print(__func__);

	/* Handle launcher keys */
	if (kev->window == launcher_window() && launcher_keypress(kev)) {
		draw_bars();
		return;
	}

	for (key = keys; key; key = key->next) {
		if (key_pressed(key, kev->keycode, kev->state)) {
			if (key->action >= 0 && key->action < LASTAction &&
					key_handler[key->action]) {
				key_handler[key->action](key);
				break; /* Skip further bindings */
			} else {
				die("unhandled key action (%d), fix this!\n",
						key->action);
			}
		}
	}
}
Esempio n. 9
0
TEST(guards_test, is_key_false) {
    //given
    is_key<42> guard;
    SDL_Event key = { };

    //when && then
    EXPECT_FALSE(guard(key_pressed()));
}
Esempio n. 10
0
bool InputHandler::key_pressed(std::vector<sf::Keyboard::Key> keys)
{
	for(int i = 0; i < keys.size(); ++i)
	{
		if(key_pressed(keys[i]))
			return true;
	}
	return false;
}
Esempio n. 11
0
/* **update\_level()** is called by the Cage game loop for every frame
 * and has to update the game state ( animations, positions, etc..)
 * as well as redraw the frame using **draw\_level()**.
 */
static void update_level(void* data, float elapsed_ms)
{
    struct level_data* ldata = data;
    animate_wizard(ldata->wizard, elapsed_ms);
    animate_sprite(ldata->tree.sprite, elapsed_ms);
    draw_level(data, elapsed_ms);
    update_timeline(ldata->timeline, data, elapsed_ms);
    if (key_pressed(KB_ESC)) exit(0);
}
Esempio n. 12
0
File: op.c Progetto: theanine/chip8
// EXA1: Skips the next instruction if the key stored in VX isn't pressed
static int op_EXA1(word_t op)
{
    int x  = (op >> 8) & 0xF;

    if (!key_pressed(chip8.V[x]))
        system_incPC();

    return SUCCESS;
}
Esempio n. 13
0
TEST(guards_test, is_key_true) {
    //given
    is_key<42> guard;
    SDL_Event key = { };
    key.key.keysym.sym = 42;

    //when && then
    EXPECT_FALSE(guard(key_pressed()));
}
Esempio n. 14
0
// Engine ----------------------------------------------------------------------
// -----------------------------------------------------------------------------
int engine_create(const int width, const int height, const int scale, const int fps) {
    engine = (struct Engine*)malloc(sizeof(struct Engine));
    
    if (!engine_init(width, height, scale, fps)) {
        free(engine);
        return 1;
    }
    game_init();
    
    // Main Loop, o'rly?
    int render_start = 0, render_diff = 0, render_wait = 0;
    int fps_count = 0, fps_time = 0;
    while (engine->running) {
        render_start = SDL_GetTicks();
        
        engine_events();
        if (key_pressed(SDLK_p)) {
            engine_pause(!engine->paused);
        }
        if (!engine->paused) {
            game_update();
        }
        engine_clear_keys();
        engine_clear_mouse();
        game_render(engine->screen);
        SDL_Flip(engine->screen->bg);
        
        // Limit FPS
        render_diff = SDL_GetTicks() - render_start;
        if (render_diff > 0) {
            render_wait = engine->fps_wait - render_diff;
            if (render_wait > 0) {
                SDL_Delay(render_wait);
            }
            if (!engine->paused) {
                engine->time += SDL_GetTicks() - render_start;
            }
        }
        
        // Count FPS
        if (!engine->paused) {
            fps_count++;
            if (fps_count >= 10) {
                engine->fps_current = 1000 / ((engine->time - fps_time) / fps_count);
                fps_count = 0;
                fps_time = engine->time;
            }
        }
    }
    
    // Cleanup
    game_quit();
    engine_cleanup();
    return 0;
}
Esempio n. 15
0
unsigned char get_key(void) {
	unsigned char r, c;
	for (r = 0; r < 4; ++r) {
		for (c = 0; c < 4; ++c) {
			if (key_pressed(r, c)) {
				return (r * 4) + c + 1;
			}
		}
	}
	return 0;
}
Esempio n. 16
0
void joystick_calibrate(struct axis_calibration *calibration)
{
    printf("Joystick calibration not implemented\n");
    return;

    int key;
    int min[CONTROLS_NUMBER], max[CONTROLS_NUMBER];

    // TODO allow to change mapping
    printf("Joystick calibration\n");
    printf("--------------------\n");

    printf("Leave the joystick controls in the neutral position and press Enter.\n");
    do {
        printf("update\n");
    } while(!key_pressed(&key));

    for(int i = 0; i < CONTROLS_NUMBER; ++i)
        calibration[i].device_offset = joystick_get_control_raw(i);

    printf("Move joystick controls in circles a few times and press Enter.\n");
    do {
        for(int i = 0; i < CONTROLS_NUMBER; ++i) {
            int val = joystick_get_control_raw(i);

            if(val < min[i])
                min[i] = val;

            if(val > max[i])
                max[i] = val;
        }
    } while(!key_pressed(&key));

    for(int i = 0; i < CONTROLS_NUMBER; ++i) {
        // TODO
        calibration[i].scale_neg = 0;
        calibration[i].scale_pos = 0;
    }

    printf("Calibration finished.\n");
}
Esempio n. 17
0
void update_parameters()
{
	char key;
	float inc = 0.01;

	key = key_pressed();
	switch (key) {
	case 'a':
		gain_dry = inc;
		break;
	case 'z':
		gain_dry -= inc;
		break;
	case 's':
		gain_wet += inc;
		break;
	case 'x':
		gain_wet -= inc;
		break;
	case 'd':
		c += inc;
		DIST += inc;
		break;
	case 'c':
		c -= inc;
		DIST -= inc;
		break;
	case 'f':
		d += inc;
		break;
	case 'v':
		d -= inc;
		break;
	case '1':
		type_func = 1;
		break;
	case '2':
		type_func = 2;
		break;
	case '3':
		type_func = 3;
		break;
	case 'm':
		gain_dry = 0;
		break;
	case '0':
		gain_wet = 0;
		break;

	default:
		break;
	}
}
Esempio n. 18
0
bool
launcher_keypress(XKeyEvent *kev)
{
	bool handled = false;

	if (key_pressed(&keys.escape, kev->keycode, kev->state)) {
		launcher_ungrab();
		launcher_clear();
		handled = true;
	} else if (key_pressed(&keys.enter, kev->keycode, kev->state)) {
		launcher_spawn();
		launcher_autocomplete_clear();
		handled = true;
	} else if (key_pressed(&keys.left, kev->keycode, kev->state)) {
		launcher_move_left();
		handled = true;
	} else if (key_pressed(&keys.right, kev->keycode, kev->state)) {
		launcher_move_right();
		handled = true;
	} else if (key_pressed(&keys.backspace, kev->keycode, kev->state)) {
		launcher_char_del();
		launcher_autocomplete_clear();
		handled = true;
	} else if (key_pressed(&keys.tab, kev->keycode, kev->state)) {
		launcher_autocomplete();
		handled = true;
	} else {
		handled = launcher_handle_char(kev);
	}

	return handled;
}
Esempio n. 19
0
  void specialFunc(int k, int, int)
  {
    key_pressed(k);

    switch (k) {
    case GLUT_KEY_LEFT      : g_camera.rotate(-0.02f,0.0f); break;
    case GLUT_KEY_RIGHT     : g_camera.rotate(+0.02f,0.0f); break;
    case GLUT_KEY_UP        : g_camera.move(0.0f,0.0f,+g_speed); break;
    case GLUT_KEY_DOWN      : g_camera.move(0.0f,0.0f,-g_speed); break;
    case GLUT_KEY_PAGE_UP   : g_speed *= 1.2f; break;
    case GLUT_KEY_PAGE_DOWN : g_speed /= 1.2f; break;
    }
  }
Esempio n. 20
0
void
step()
{
    canvas_clear(1);

    if (key_down(KEY_ESCAPE)) {
        CORE->running = 0;
    }

    if (key_pressed(KEY_RETURN)) {
        window_fullscreen_toggle();
    }

    player_step(&GAME->player,
                key_down(KEY_LEFT), key_down(KEY_RIGHT), key_pressed(KEY_UP));

    tilemap_draw(GAME->scene.tilemap);

    char buf[256];
    sprintf(buf, "%.3fms %.3f", CORE->perf_step * 1e3, CORE->time_delta);
    text_draw(buf, 0, 0, 2);
}
Esempio n. 21
0
int main(int argc, char **argv){
    /* Initialize glut */
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE);
    glutInitWindowSize(640, 480);
    glutInitWindowPosition(100, 100);

    int win = glutCreateWindow("NeHe Lesson 2");

    /* Create a forward closure to avoid keeping global window state */
    void keypress_handler(unsigned char key, int x, int y){
        key_pressed(key, x, y, win);
    }
Esempio n. 22
0
void simulation_process_input(simulation_t* sim)
{
	if(key_pressed(KEY_MINUS))sim->camera.scale*=0.5;
	else if(key_pressed(KEY_PLUS))sim->camera.scale*=2;
	if(key_pressed(KEY_LEFT_BRACKET)&&sim->speedup>1)sim->speedup/=10;
	else if(key_pressed(KEY_RIGHT_BRACKET))sim->speedup*=10;

sim->current_spacecraft->firing=key_down(KEY_UP)&&sim->current_spacecraft->fuel>0;

    if(key_down(KEY_LEFT))sim->current_spacecraft->base.delta_rot+=0.1/sim->speedup;
    else if(key_down(KEY_RIGHT))sim->current_spacecraft->base.delta_rot-=0.1/sim->speedup;

    //Temporary, for testing docking
    if(key_pressed(KEY_DOWN))
    {
    spacecraft_t* craft=sim->current_spacecraft->docks[0].docked_spacecraft;
    printf("%d\n",craft->parent);
    spacecraft_undock(sim->current_spacecraft,0);
    //sim->current_spacecraft=craft;
    int i;
        for(i=0;i<sim->num_spacecraft;i++)sim->spacecraft[i].parent=NULL;
    }
}
Esempio n. 23
0
void
run (void) {
  while (1) {
    message("Turn : %6d ; <Press any key to interrupt>", turn);
    display();
		
    if(key_pressed())
      break;
		
    generation();
		
    turn++;
    sleep(1);
  }
}
Esempio n. 24
0
void key_callback(GLFWwindow *wnd, int key, int scan, int action, int mod) {
    switch(action) {
        case GLFW_PRESS:
            key_pressed(key, scan, mod);
            break;

        case GLFW_REPEAT:
            key_repeated(key, scan, mod);
            break;

        case GLFW_RELEASE:
            key_released(key, scan, mod);
            break;
    }
}
Esempio n. 25
0
unsigned char get_key(void) {
	for (int r=0; r < 4; r++) {
		CLR_BIT(DDRC, r);
		SET_BIT(PORTC, r);
		for (int c=4; c < 8; c++) {
			SET_BIT(DDRC, c);
			CLR_BIT(PORTC, c);
			set_to_NC(c);
			if (key_pressed(r,c)) {
				return (r*4) + c - 3;
			}
		}
	}
	return 0;
}
Esempio n. 26
0
static void kkbrd(void *arg)
{
	kbrd_instance_t *instance = (kbrd_instance_t *) arg;
	
	while (true) {
		wchar_t sc = indev_pop_character(&instance->raw);
		
		if (sc == IGNORE_CODE)
			continue;
		
		if (sc & KEY_RELEASE)
			key_released(instance, (sc ^ KEY_RELEASE) & 0x7f);
		else
			key_pressed(instance, sc & 0x7f);
	}
}
Esempio n. 27
0
void	read_button(t_list **list, t_list **current)
{
	char	buf[7];

	buf[0] = 0;
	buf[1] = 0;
	buf[2] = 0;
	buf[3] = 0;
	buf[4] = 0;
	buf[5] = 0;
	buf[6] = 0;
	read(0, buf, 6);
	key_pressed(list, current, buf);
	ft_putchar('\n');
	print_list(*list, *current);
}
Esempio n. 28
0
  void keyboardFunc(unsigned char key, int x, int y)
  {

    if (keyBindings.find(key) != keyBindings.end()) { keyBindings[key](key, x, y);  return; }

    key_pressed(key);

    switch (key)
    {
    case 'f' : 
      if (g_fullscreen) {
        g_fullscreen = false;
        glutReshapeWindow(g_window_width,g_window_height);
      } else {
        g_fullscreen = true;
        g_window_width = g_width;
        g_window_height = g_height;
        glutFullScreen(); 
      }
      break;
    case 'c' : {
      std::cout.precision(10);
      std::cout << "-vp " << g_camera.from.x    << " " << g_camera.from.y    << " " << g_camera.from.z    << " " 
                << "-vi " << g_camera.to.x << " " << g_camera.to.y << " " << g_camera.to.z << " " 
        //<< "-vd " << g_camera.to.x-g_camera.from.x << " " << g_camera.to.y-g_camera.from.y << " " << g_camera.to.z-g_camera.from.z << " " << std::endl
                << "-vu " << g_camera.up.x     << " " << g_camera.up.y     << " " << g_camera.up.z     << " " 
                << "-fov " << g_camera.fov << std::endl;
      break;
    }
      //case 'a' : g_camera.rotate(-0.02f,0.0f); break;
      //case 'd' : g_camera.rotate(+0.02f,0.0f); break;
      //case 'w' : g_camera.move(0.0f,0.0f,+g_speed); break;
      //case 's' : g_camera.move(0.0f,0.0f,-g_speed); break;
      //case ' ' : g_display = !g_display; break;

    case '+' : g_debug=clamp(g_debug+0.01f); PRINT(g_debug); break;
    case '-' : g_debug=clamp(g_debug-0.01f); PRINT(g_debug); break;

    case '\033': case 'q': case 'Q':
      cleanup();
      glutDestroyWindow(g_window);
#if defined(__MACOSX__)
      exit(1);
#endif
      break;
    }
  }
    void CameraController::update(float delta_time)
    {
        const Matrix3 rot = get_object()->get_rotation_matrix();

        Vector3 right, up, forward;
        rot.get_basis(right, up, forward);

        const float move_speed = 2.5f * (key_down(Key::Left_Shift) ? 4.0f : 1.0f); // meters/second
        const float rotate_speed = 0.002f; // rad/pixel

        Vector3 delta = Vector3::zero;

        if (key_down(Key::W))
            delta += forward;
        if (key_down(Key::S))
            delta -= forward;
        if (key_down(Key::D))
            delta += right;
        if (key_down(Key::A))
            delta -= right;
        if (key_down(Key::Space))
            delta += up;
        if (key_down(Key::Left_Control))
            delta -= up;

        get_object()->move(delta * move_speed * m_speed_up * delta_time);

        if (key_pressed(Key::Left_Alt))
            toggle_mouse_captured();

        if (is_mouse_captured())
        {
            const Vector2 mouse_delta = get_mouse_delta() * rotate_speed;
            m_rot_x += mouse_delta.y;
            m_rot_y += mouse_delta.x;

            m_speed_up += get_delta_scroll() * 0.5f;
            m_speed_up = std::max(m_speed_up, 0.0f);
        }

        Quaternion rot_x, rot_y;
        rot_x.rotation_x(m_rot_x);
        rot_y.rotation_y(m_rot_y);
        get_object()->set_rotation(rot_y * rot_x);
    }
Esempio n. 30
0
void particle_simple_action(particle_t* self) {
  int speed = 300;
  if(key_pressed('a')) {
    self->v.x = -speed;
  }
  if(key_pressed('d')) {
    self->v.x = speed;
  }
  if(!key_pressed('a') && !key_pressed('d')) {
    self->v.x = 0;
  }
  if(key_pressed('s')) {
    self->v.y = -speed;
  }
  if(key_pressed('w')) {
    self->v.y = speed;
  }
  if(!key_pressed('s') && !key_pressed('w')) {
    self->v.y = 0;
  }
}