Esempio n. 1
0
/**
 * Prints the provided strings centered in the middle of the screen.
 */
Code print_centered_vertically(const int string_count, char **strings, const ColorPair color_pair, Renderer *renderer) {
  const int text_line_height = global_monospaced_font_height;
  const int padding = 2 * get_padding() * global_monospaced_font_height;
  const int available_window_height = get_window_height() - padding;
  const int text_lines_limit = available_window_height / text_line_height;
  int printed_count = string_count;
  int y;
  int i;
  if (string_count > text_lines_limit) {
    printed_count = text_lines_limit;
  }
  y = (get_window_height() - string_count * text_line_height) / 2;
  for (i = 0; i < printed_count; i++) {
    print_centered_horizontally(y, 1, strings + i, color_pair, renderer);
    y += text_line_height;
  }
  return CODE_OK;
}
Esempio n. 2
0
/**
 * Creates a new fullscreen window.
 *
 * Updates the pointers with the window width, window height, and bar height.
 */
static Window *create_window(int *width, int *height) {
  const char *title = GAME_NAME;
  const int x = SDL_WINDOWPOS_CENTERED;
  const int y = SDL_WINDOWPOS_CENTERED;
  const int w = get_window_width();
  const int h = get_window_height();
  const Uint32 flags = SDL_WINDOW_INPUT_FOCUS;
  Window *window;
  window = SDL_CreateWindow(title, x, y, w, h, flags);
  SDL_GetWindowSize(window, width, height);
  return window;
}
Esempio n. 3
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);
}
Esempio n. 4
0
static void fix_start_row(struct multilist *list)
{
	int height;

	/* adjust start_row so that the cursor appears on the screen */

	height = get_window_height(list);
	if (list->cursor_row < list->start_row) {
		list->start_row = list->cursor_row;
	} else if (list->cursor_row >= list->start_row + height) {
		list->start_row = list->cursor_row - height + 1;
	}
	if (list->nrows > height && list->nrows - list->start_row < height) {
		list->start_row = list->nrows - height;
	}
}
Esempio n. 5
0
void GameOfLife::on_init()
{
    rect.set_color(glm::vec3(0.15f, 1.0f, 0.2f));
    rect.set_size(glm::vec2(cell_size));
    srand(static_cast<unsigned>(time(NULL)));

    width = std::ceil(get_window_width() / cell_size);
    height = std::ceil(get_window_height() / cell_size);

    map = new bool*[width];
    prev_map = new bool*[width];
    for(unsigned i = 0; i < width; ++i)
    {
        map[i] = new bool[height];
        prev_map[i] = new bool[height];
        for(unsigned j = 0; j < height; ++j)
        {
            map[i][j] = prev_map[i][j] = false;//!static_cast<bool>(rand()%3);
        }
    }

    cout << get_cell_neighbors(0, 0) << endl;
}
Esempio n. 6
0
void multilist_driver(struct multilist *list, int c)
{
	unsigned page;
	const void *tmp = NULL;

	if (list->nrows == 0) {
		return;
	}

	switch (c) {
	case ML_CURSOR_UP:
		if (list->cursor_row == 0) {
			return;
		}
		unhighlight_current_row(list);
		list->cursor_row--;
		tmp = data_get_prev_row(list, list->current_row);
		break;
	case ML_CURSOR_DOWN:
		if (list->cursor_row == list->nrows - 1) {
			return;
		}
		unhighlight_current_row(list);
		list->cursor_row++;
		tmp = data_get_next_row(list, list->current_row);
		break;
	case ML_CURSOR_PGUP:
		if (list->cursor_row == 0) {
			return;
		}
		unhighlight_current_row(list);
		page = get_window_height(list);
		if (page > list->cursor_row) {
			list->cursor_row = 0;
		} else {
			list->cursor_row -= page;
			list->start_row -= page;
		}
		tmp = data_get_row_n(list, list->cursor_row);
		break;
	case ML_CURSOR_PGDN:
		if (list->cursor_row == list->nrows - 1) {
			return;
		}
		unhighlight_current_row(list);
		page = get_window_height(list);
		if (page > list->nrows - list->cursor_row - 1) {
			list->cursor_row = list->nrows - 1;
		} else {
			list->cursor_row += page;
			list->start_row += page;
		}
		tmp = data_get_row_n(list, list->cursor_row);
		break;
	case ML_CURSOR_HOME:
		if (list->cursor_row == 0) {
			return;
		}
		unhighlight_current_row(list);
		list->cursor_row = 0;
		tmp = data_get_row_n(list, list->cursor_row);
		break;
	case ML_CURSOR_END:
		if (list->cursor_row == list->nrows - 1) {
			return;
		}
		unhighlight_current_row(list);
		list->cursor_row = list->nrows - 1;
		tmp = data_get_row_n(list, list->cursor_row);
		break;
	}

	SMB_ASSERT(tmp);
	list->current_row = tmp;
	highlight_current_row(list);
	fix_start_row(list);
}
Esempio n. 7
0
void
mouse_moved( int x, int y)
{
  usleep(100);

  camera_pose_t * camera_pose = get_camera_pose();
  int window_width = get_window_width();
  int window_height = get_window_height();

  switch (mouse_rotation.button)
  {
  case GLUT_LEFT_BUTTON: // rotate
  {
    camera_pose->phi   -= ((float)( mouse_rotation.x0 - x ))/((float)(window_width))*2.0*3.14;
    camera_pose->theta -= ((float)( mouse_rotation.y0 - y ))/((float)(window_height))*2.0*3.14;
    if (camera_pose->theta > 0.5*3.14)
      camera_pose->theta = 0.5*3.14;
    if (camera_pose->theta < -0.5*3.14f)
      camera_pose->theta = -0.5*3.14f;
    mouse_rotation.x0 = x;
    mouse_rotation.y0 = y;
    set_camera();
    break;
  }
  case GLUT_RIGHT_BUTTON: // pan
  {
    camera_pose->focus_x += 500.0f*cos(camera_pose->phi)*((float)(y - mouse_rotation.y0))/((float)(window_height));
    camera_pose->focus_y += 500.0f*sin(camera_pose->phi)*((float)(y - mouse_rotation.y0))/((float)(window_height));;

    camera_pose->focus_x += 500.0f*sin(camera_pose->phi)*((float)(x - mouse_rotation.x0))/((float)(window_width));
    camera_pose->focus_y -= 500.0f*cos(camera_pose->phi)*((float)(x - mouse_rotation.x0))/((float)(window_width));;

    mouse_rotation.x0 = x;
    mouse_rotation.y0 = y;

    set_camera();
    break;
  }
/*
  case GLUT_MIDDLE_BUTTON: // zoom
  {
    camera_pose->rho += 1000.0f*((float)(y - mouse_rotation.y0))/((float)(window_height));
    if (camera_pose->rho < 1.0f)
      camera_pose->rho = 1.0f;
    if (camera_pose->rho > 2000.0f)
      camera_pose->rho = 2000.0f;
    mouse_rotation.x0 = x;
    mouse_rotation.y0 = y;
    set_camera();
    break;
  }
*/
  case GLUT_MIDDLE_BUTTON: // move camera focus
  {
    camera_pose->focus_z += 500.0f*((float)(y - mouse_rotation.y0))/((float)(window_height));
    if (camera_pose->focus_z > 0.0f)
      camera_pose->focus_z = 0.0f;
    mouse_rotation.x0 = x;
    mouse_rotation.y0 = y;
    set_camera();
    break;
  }
  default:
    break;
  }// switch (mouse_rotation.button)
}