Example #1
0
/**
 * @brief This function is called by the main loop when there is an input event.
 * @param event the event to handle
 */
void LanguageScreen::notify_event(InputEvent &event) {

  static const InputEvent::KeyboardKey validation_keys[] = { InputEvent::KEY_SPACE, InputEvent::KEY_RETURN, InputEvent::KEY_NONE };

  if (transition == NULL) {

    if (event.is_direction_pressed()) {

      int direction = event.get_direction();
      if (direction == 2) {
	// up
	set_cursor_position((cursor_position - 1 + nb_languages) % nb_languages);
	Sound::play("cursor");
      }
      else if (direction == 6) {
	// down
	set_cursor_position((cursor_position + 1) % nb_languages);
	Sound::play("cursor");
      }
    }
    else if (event.is_keyboard_key_pressed(validation_keys)
	|| event.is_joypad_button_pressed()) {

	FileTools::set_language(language_codes[cursor_position]);
	transition = Transition::create(Transition::FADE, Transition::OUT);
	transition->start();
    }
  }
}
/**
 * @brief This function is called when a key is pressed on this submenu.
 * @param key the key pressed
 */
void PauseSubmenuInventory::key_pressed(GameControls::GameKey key) {

  KeysEffect &keys_effect = game.get_keys_effect();

  switch (key) {

  case GameControls::ACTION:
    if (keys_effect.get_action_key_effect() == KeysEffect::ACTION_KEY_INFO) {
      show_info_message();
    }
    break;

  case GameControls::ITEM_1:
    if (is_item_selected()) {
      assign_item(0);
    }
    break;

  case GameControls::ITEM_2:
    if (is_item_selected()) {
      assign_item(1);
    }
    break;

  case GameControls::LEFT:
    if (cursor_column == 0) {
      pause_menu.show_left_submenu();
    }
    else {
      play_cursor_sound();
      set_cursor_position(cursor_row, cursor_column - 1);
    }
    break;

  case GameControls::RIGHT:
    if (cursor_column == 6) {
      pause_menu.show_right_submenu();
    }
    else {
      play_cursor_sound();
      set_cursor_position(cursor_row, cursor_column + 1);
    }
    break;

  case GameControls::UP:
    play_cursor_sound();
    set_cursor_position((cursor_row + 3) % 4, cursor_column);
    break;

  case GameControls::DOWN:
    play_cursor_sound();
    set_cursor_position((cursor_row + 1) % 4, cursor_column);
    break;

  default:
    break;
  }
}
Example #3
0
void render_exit_menu(exit_menu_t *state, float cursor_x, float cursor_y)
{
    // Update center of cursor
    set_cursor_position(state->cursor_state, cursor_x, cursor_y);

    // Check if anything selected
    check_cursor_in_image(state->cursor_state, state->mandelbrot_state);
    check_cursor_in_image(state->cursor_state, state->sph_state);
    check_cursor_in_image(state->cursor_state, state->terminal_state);

    // Draw background rectangle
    float center[2] = {0.0f, 0.0f};
    float gl_dims[2] = {2.0f, 0.7f};
    float background_color[4] = {1.0f, 1.0f, 1.0f, 0.8f};
    render_rectangle(state->rectangle_state, center, gl_dims, background_color);

    // Draw mandelbrot image
    draw_image(state->mandelbrot_state);

    // Draw terminal image
    draw_image(state->terminal_state);

    // Draw SPH image
    draw_image(state->sph_state);

    // Draw cursor
    draw_cursor(state->cursor_state);
}
Example #4
0
/**
 * @brief Creates a selection menu phase where the player sets the global options.
 * @param menu the selection menu this phase will belong to
 */
SelectionMenuOptions::SelectionMenuOptions(SelectionMenu *menu):
  SelectionMenuPhase(menu, "selection_menu.phase.options"),
  cursor_position(0), modifying(false) {

  // option texts and values
  for (int i = 0; i < nb_options; i++) {

    // labels
    this->label_texts[i] = new TextSurface(64, 86 + i * 16, TextSurface::ALIGN_LEFT, TextSurface::ALIGN_MIDDLE);
    this->label_texts[i]->set_font("fixed");
    this->label_texts[i]->set_text(StringResource::get_string(label_keys[i]));

    // values
    this->value_texts[i] = new TextSurface(266, 86 + i * 16, TextSurface::ALIGN_RIGHT, TextSurface::ALIGN_MIDDLE);
    this->value_texts[i]->set_font("fixed");

    this->current_indices[i] = -1;
  }
  load_configuration();

  this->left_arrow_sprite = new Sprite("menus/arrow");
  this->left_arrow_sprite->set_current_animation("blink");
  this->left_arrow_sprite->set_current_direction(2);

  this->right_arrow_sprite = new Sprite("menus/arrow");
  this->right_arrow_sprite->set_current_animation("blink");
  this->right_arrow_sprite->set_current_direction(0);

  menu->set_bottom_options("selection_menu.back", "");
  set_cursor_position(0);
}
Example #5
0
void debug_view_disasm::set_selected_address(offs_t address)
{
	const debug_view_disasm_source &source = downcast<const debug_view_disasm_source &>(*m_source);
	offs_t byteaddress = source.m_space.address_to_byte(address) & source.m_space.logbytemask();
	for (int line = 0; line < m_total.y; line++)
		if (m_byteaddress[line] == byteaddress)
		{
			m_cursor.y = line;
			set_cursor_position(m_cursor);
			break;
		}
}
Example #6
0
void Edit::on_mousepress()
{
	if(Mouse::is_over(get_position(), get_size()))
	{
		if(Mouse::is_pressed(1))
		{
		    WINDOW * window = WINDOW::get_active();
		    if(window != nullptr)
		        set_cursor_position(Mouse::get_position(*window).x, cursor_y);
		}
	}
}
Example #7
0
/**
 * @brief Moves the options cursor downwards.
 */
void SelectionMenuOptions::move_cursor_down() {

  menu->play_cursor_sound();
  left_arrow_sprite->restart_animation();

  int cursor_position = this->cursor_position + 1;

  if (cursor_position > nb_options) {
    cursor_position = 0;
  }
  set_cursor_position(cursor_position);
}
Example #8
0
int		main(void)
{
	t_env	*env;
	char	buffer[20];

	init_signals();
	tgetent(0, getenv("TERM"));
	if (!(env = malloc(sizeof(*env))))
		quit("Failed to malloc env");
	if (!(env->caps = malloc(sizeof(*env->caps))))
		quit("Failed to malloc env caps");
	env->messages = NULL;
	if (!(env->input = ft_memalloc(1)))
		quit("Failed to malloc new input");
	init_caps(env->caps);
	terminal_catch_mode();
	ft_putstr(env->caps->fullscreen_start);
	ft_putstr(env->caps->clear);
	ft_putstr(env->caps->stand_start);
	ft_putstr(env->caps->bold_start);
	int i = 0;
	set_cursor_position(env, 0, get_window_height() - 2);
	int width = get_window_width();
	while (i < width)
	{
		ft_putchar('-');
		i++;
	}
	ft_putstr(env->caps->stand_end);
	fcntl(0, F_SETFL, fcntl(0, F_GETFL) | O_NONBLOCK);
	int t = 0;
	int rd;
	while (t < 50)
	{
		ft_bzero(buffer, 20);
		while ((rd = read(0, buffer, 20)) < 1)
		{
			if (errno != EAGAIN && errno != EWOULDBLOCK)
				quit("Error on stdin read");
			//check tcp
			//check resize
		}
		ft_putstr(buffer);
		t++;
	}
	fcntl(0, F_SETFL, fcntl(0, F_GETFL) & ~O_NONBLOCK);
	ft_putstr(env->caps->fullscreen_end);
	terminal_normal_mode();
	return (0);
}
Example #9
0
/* DDS3.2.12: Update Cursor Position */
static void update_ccp(struct cursor cursor, enum input_event next)
{
	struct cursor new_cursor;
	unsigned int number_of_groups, group_index, number_of_candidates;
	int candidate_index;

	group_index = cursor.group_index;
	candidate_index = cursor.screen_candidate_index;

	number_of_groups = get_num_gps_electorate();
	number_of_candidates = get_num_cands_in_gp(group_index);

	if (next == INPUT_UP) {
		candidate_index -= 1;
		if (candidate_index < 0) {
			candidate_index = number_of_candidates - 1;
		}
	}
	if (next == INPUT_DOWN) {
		candidate_index += 1;
		if (candidate_index == number_of_candidates) {
			candidate_index = 0;
		}
	}
	if (next == INPUT_NEXT) {
		group_index += 1;
		candidate_index = -1;
		if (group_index == number_of_groups) {
			group_index = 0;
		}
	}	
	if (next == INPUT_PREVIOUS) {
		if (group_index == 0) {
			group_index = number_of_groups;
		}
		group_index -= 1;
		candidate_index = -1;
	}
	
	new_cursor.group_index = group_index;
	new_cursor.screen_candidate_index = candidate_index;

	set_cursor_position(new_cursor);

	/* Interrupt any currently playing audio */
	draw_group_entry(new_cursor, YES, true);
}
Example #10
0
/**
 * @brief Creates a language screen.
 * @param solarus the Solarus object
 */
LanguageScreen::LanguageScreen(Solarus &solarus):
  Screen(solarus), transition(NULL), intermediate_surface(NULL), 
  language_codes(NULL), language_texts(NULL),
  cursor_position(0), nb_languages(0), finished(false) {

  if (FileTools::get_language().size() != 0) {
    // a language is already set: skip this screen
    finished = true;
  }
  else {
    intermediate_surface = new Surface(320, 240);

    std::map<std::string, std::string> language_map = FileTools::get_languages();
    nb_languages = language_map.size();
    first_visible_language = 0;
    nb_visible_languages = std::min(nb_languages, max_visible_languages);
    language_texts = new TextSurface*[nb_languages];
    language_codes = new std::string[nb_languages];
    int cursor_position = 0;
    int i = 0;

    std::map<std::string, std::string>::iterator it;
    for (it = language_map.begin(); it != language_map.end(); it++) {
      language_codes[i] = it->first;
      language_texts[i] = new TextSurface(160, 0, TextSurface::ALIGN_CENTER, TextSurface::ALIGN_MIDDLE);
      language_texts[i]->set_font("fixed");
      language_texts[i]->set_text(it->second);
      if (language_codes[i] == FileTools::get_default_language()) {
        cursor_position = i;
      }
      i++;
    }
    set_cursor_position(cursor_position);
  }

  if (nb_languages == 1) {
    // no choice: skip the language screen
    FileTools::set_language(language_codes[0]);
    finished = true;
  }
}
Example #11
0
void				go_right(t_usent *us)
{
	tputs(tgetstr("nd", NULL), 1, tputchar);
	set_cursor_position(us, 1);
}
Example #12
0
void				go_left(t_usent *us)
{
	tputs(tgetstr("le", NULL), 1, tputchar);
	set_cursor_position(us, -1);
}
Example #13
0
/**
 * @brief Constructor.
 * @param pause_menu the pause menu object
 * @param game the game
 */
PauseSubmenuInventory::PauseSubmenuInventory(PauseMenu &pause_menu, Game &game):
  PauseSubmenu(pause_menu, game) {

  cursor_sprite = new Sprite("menus/pause_cursor");

  IniFile ini = IniFile("hud/inventory.dat", IniFile::READ);
  ini.set_group("items");

  // set the sprites, counters and caption strings
  std::ostringstream oss;
  for (int k = 0; k < 28; k++) {

    // get the item, its counter property and the possession state
    oss.str("");
    oss << "item_" << k;
    item_names[k] = ini.get_string_value(oss.str());
    int variant = equipment.get_item_variant(item_names[k]);
    ItemProperties &item_properties = equipment.get_item_properties(item_names[k]);

    if (variant != 0 && item_properties.has_counter()) {

      // if the player has the item and this item has an amount, we show a counter

      int amount = equipment.get_item_amount(item_names[k]);
      int maximum = equipment.get_item_maximum(item_names[k]);
      int x = 60 + (k % 7) * 32;
      int y = 81 + (k / 7) * 32;

      counters[k] = new Counter(2, false, x, y);
      counters[k]->set_maximum(maximum);
      counters[k]->set_value(amount);
    }
    else {
      counters[k] = NULL;
    }

    // initialize the sprite and the caption string
    if (variant != 0) {

      std::ostringstream oss;

      // sprite
      sprites[k] = new Sprite("entities/items");
      sprites[k]->set_current_animation(item_names[k]);
      sprites[k]->set_current_direction(variant - 1);

      // caption string
      oss.str("");
      oss << "inventory.caption.item." << item_names[k] << "." << variant;
      caption_strings[k] = StringResource::get_string(oss.str());
    }
    else {
      sprites[k] = NULL;
    }
  }

  // initialize the cursor
  int index = savegame.get_integer(Savegame::INVENTORY_LAST_ITEM_INDEX);
  int row = index / 7;
  int column = index % 7;
  set_cursor_position(row, column);

  item_assigned_movement = NULL;
}
Example #14
0
void Edit::set_cursor_position(const Vector2& position)
{
	set_cursor_position(position.x, position.y);
}
Example #15
0
/*
 * Program entry point
 */
uint main(uint argc, uchar* argv[])
{
  uchar* title_info = "L:     F1:Save ESC:Exit"; /* const */
  uchar  line_ibcd[4]; /* To store line number digits */
  uint   ibcdt;

  uint i = 0;
  uint n = 0;
  uint result = 0;

  /* buff is fixed size and allocated in far memory so it
   * can be big enough.
   * buff_size is the size in bytes actually used in buff
   * buff_cursor_offset is the linear offset of current
   * cursor position inside buff
   */
  lp_t buff = 0;
  ul_t buff_size = 0;
  ul_t buff_cursor_offset = 0;

  /* First line number to display in the editor area */
  uint current_line = 0;

  /* Var to get key presses */
  uint k = 0;

  struct FS_ENTRY entry;

  /* Chck usage */
  if(argc != 2) {
    putstr("Usage: %s <file>\n\r\n\r", argv[0]);
    putstr("<file> can be:\n\r");
    putstr("-an existing file path: opens existing file to edit\n\r");
    putstr("-a new file path: opens empty editor. File will be created on save\n\r");
    putstr("\n\r");
    return 1;
  }

  /* Allocate fixed size text buffer */
  buff = lmalloc(0xFFFFL);
  if(buff == 0) {
    putstr("Error: can't allocate memory\n\r");
    return 1;
  }

  /* Find file */
  n = get_entry(&entry, argv[1], UNKNOWN_VALUE, UNKNOWN_VALUE);

  /* Load file or show error */
  if(n<ERROR_ANY && (entry.flags & FST_FILE)) {
    ul_t offset = 0;
    uchar cbuff[512];
    setlc(buff, entry.size, 0);
    buff_size = entry.size;
    while(result = read_file(cbuff, argv[1], (uint)offset, sizeof(cbuff))) {
      if(result >= ERROR_ANY) {
        lmfree(buff);
        putstr("Can't read file %s (error=%x)\n\r", argv[1], result);
        return 1;
      }
      lmemcpy(buff + offset, lp(cbuff), (ul_t)result);
      offset += result;
    }
    if(offset != entry.size) {
      lmfree(buff);
      putstr("Can't read file (readed %d bytes, expected %d)\n\r",
        (uint)offset, entry.size);
      return 1;
    }
    /* Buffer must finish with a 0 and */
    /* must fit at least this 0, so buff_size can't be 0 */
    if(buff_size == 0 || getlc(buff + buff_size-1L) != 0) {
      buff_size++;
    }
  }

  /* Create 1 byte buffer if this is a new file */
  /* This byte is for the final 0 */
  if(buff_size == 0) {
    buff_size = 1;
    lmemset(buff, 0, buff_size);
  }

  /* Get screen size */
  get_screen_size(SSM_CHARS, &SCREEN_WIDTH, &SCREEN_HEIGHT);

  /* Allocate screen buffer */
  screen_buff = lmalloc((ul_t)(SCREEN_WIDTH*(SCREEN_HEIGHT-1)));
  if(screen_buff == 0) {
    putstr("Error: can't allocate memory\n\r");
    lmfree(buff);
    return 1;
  }

  /* Clear screen buffer */
  lmemset(screen_buff, 0, (ul_t)(SCREEN_WIDTH*(SCREEN_HEIGHT-1)));

  /* Write title */
  for(i=0; i<strlen(argv[1]); i++) {
    putchar_attr(i, 0, argv[1][i], TITLE_ATTRIBUTES);
  }
  for(; i<SCREEN_WIDTH-strlen(title_info); i++) {
    putchar_attr(i, 0, ' ', TITLE_ATTRIBUTES);
  }
  for(; i<SCREEN_WIDTH; i++) {
    putchar_attr(i, 0,
      title_info[i+strlen(title_info)-SCREEN_WIDTH], TITLE_ATTRIBUTES);
  }

  /* Show buffer and set cursor at start */
  set_show_cursor(HIDE_CURSOR);
  show_buffer_at_line(buff, current_line);
  set_cursor_position(0, 1);
  set_show_cursor(SHOW_CURSOR);

  /* Main loop */
  while(k != KEY_ESC) {
    uint col, line;

    /* Getmouse state */
    get_mouse_state(SSM_CHARS, &mouse_x, &mouse_y, &mouse_buttons);

    /* Process buttons */
    if(mouse_buttons & MOUSE_LEFT_BUTTON) {
      buff_cursor_offset = linecol_to_buffer_offset(buff, mouse_x, mouse_y-1);
    }

    /* Get key press */
    k = getkey(KM_NO_WAIT);

    /* Process key actions */

    /* Keys to ignore */
    if((k>KEY_F1 && k<=KEY_F10) ||
      k==KEY_F11 || k==KEY_F12 ||
      k==KEY_PRT_SC || k==KEY_INS ||
      k==0) {
      continue;

    /* Key F1: Save */
    } else if(k == KEY_F1) {
      ul_t offset = 0;
      uchar cbuff[512];
      result = 0;
      while(offset<buff_size && result<ERROR_ANY) {
        ul_t to_copy = min(sizeof(cbuff), buff_size-offset);
        lmemcpy(lp(cbuff), buff + offset, to_copy);
        result = write_file(cbuff, argv[1], (uint)offset, (uint)to_copy, FWF_CREATE | FWF_TRUNCATE);
        offset += to_copy;
      }

      /* Update state indicator */
      if(result < ERROR_ANY) {
        putchar_attr(strlen(argv[1]), 0, ' ', TITLE_ATTRIBUTES);
      } else {
        putchar_attr(strlen(argv[1]), 0, '*', (TITLE_ATTRIBUTES&0xF0)|AT_T_RED);
      }
      /* This opperation takes some time, so clear keyboard buffer */
      getkey(KM_CLEAR_BUFFER);

    /* Cursor keys: Move cursor */
    } else if(k == KEY_UP) {
      buffer_offset_to_linecol(buff, buff_cursor_offset, &col, &line);
      if(line > 0) {
        line -= 1;
        buff_cursor_offset = linecol_to_buffer_offset(buff, col, line);
      }

    } else if(k == KEY_DOWN) {
      buffer_offset_to_linecol(buff, buff_cursor_offset, &col, &line);
      line += 1;
      buff_cursor_offset = linecol_to_buffer_offset(buff, col, line);

    } else if(k == KEY_LEFT) {
      if(buff_cursor_offset > 0) {
        buff_cursor_offset--;
      }

    } else if(k == KEY_RIGHT) {
      if(buff_cursor_offset < buff_size - 1) {
        buff_cursor_offset++;
      }

    /* HOME, END, PG_UP and PG_DN keys */
    } else if(k == KEY_HOME) {
      buffer_offset_to_linecol(buff, buff_cursor_offset, &col, &line);
      col = 0;
      buff_cursor_offset = linecol_to_buffer_offset(buff, col, line);

    } else if(k == KEY_END) {
      buffer_offset_to_linecol(buff, buff_cursor_offset, &col, &line);
      col = 0xFFFF;
      buff_cursor_offset = linecol_to_buffer_offset(buff, col, line);

    } else if(k == KEY_PG_DN) {
      buffer_offset_to_linecol(buff, buff_cursor_offset, &col, &line);
      line += SCREEN_HEIGHT-1;
      buff_cursor_offset = linecol_to_buffer_offset(buff, col, line);

    } else if(k == KEY_PG_UP) {
      buffer_offset_to_linecol(buff, buff_cursor_offset, &col, &line);
      line -= min(line, SCREEN_HEIGHT-1);
      buff_cursor_offset = linecol_to_buffer_offset(buff, col, line);


    /* Backspace key: delete char before cursor and move cursor there */
    } else if(k == KEY_BACKSPACE) {
      if(buff_cursor_offset > 0) {
        lmemcpy(buff+buff_cursor_offset-1L, buff+buff_cursor_offset, buff_size-buff_cursor_offset);
        buff_size--;
        putchar_attr(strlen(argv[1]), 0, '*', TITLE_ATTRIBUTES);
        buff_cursor_offset--;
      }

    /* Del key: delete char at cursor */
    } else if(k == KEY_DEL) {
      if(buff_cursor_offset < buff_size-1) {
        lmemcpy(buff+buff_cursor_offset, buff+buff_cursor_offset+1, buff_size-buff_cursor_offset-1);
        buff_size--;
        putchar_attr(strlen(argv[1]), 0, '*', TITLE_ATTRIBUTES);
      }

    /* Any other key but esc: insert char at cursor */
    } else if(k != KEY_ESC && k != 0) {

      if(k == KEY_RETURN) {
        k = '\n';
      }
      if(k == KEY_TAB) {
        k = '\t';
      }
      lmemcpy(buff+buff_cursor_offset+1, buff+buff_cursor_offset, buff_size-buff_cursor_offset);
      setlc(buff, buff_cursor_offset++, k);
      buff_size++;
      putchar_attr(strlen(argv[1]), 0, '*', TITLE_ATTRIBUTES);
    }

    /* Update cursor position and display */
    buffer_offset_to_linecol(buff, buff_cursor_offset, &col, &line);
    if(line < current_line) {
      current_line = line;
    } else if(line > current_line + SCREEN_HEIGHT - 2) {
      current_line = line - SCREEN_HEIGHT + 2;
    }

    /* Update line number in title */
    /* Compute bcd value (reversed) */
    ibcdt = min(9999, buffer_offset_to_fileline(buff, buff_cursor_offset)+1);
    n = SCREEN_WIDTH-strlen(title_info)+2;
    for(i=0; i<4; i++) {
      line_ibcd[i] = ibcdt%10;
      ibcdt /= 10;
      if(ibcdt==0) {
        ibcdt = i;
        break;
      }
    }
    /* Display it */
    for(i=0; i<4; i++) {
      uchar c = i<=ibcdt?line_ibcd[ibcdt-i]+'0':' ';
      putchar_attr(n+i, 0, c, TITLE_ATTRIBUTES);
    }

    set_show_cursor(HIDE_CURSOR);
    show_buffer_at_line(buff, current_line);
    line -= current_line;
    line += 1;
    set_cursor_position(col, line);
    set_show_cursor(SHOW_CURSOR);
  }

  /* Free screen buffer */
  lmfree(screen_buff);

  /* Free buffer */
  lmfree(buff);

  /* Reset screen */
  clear_screen();
  set_cursor_position(0, 0);

  return 0;
}