Example #1
0
void
set_mouse_pos (struct pos *p)
{
  struct mouse_coord m;

  struct pos np; npos (p, &np);

  m.mr.w = mr.w;
  m.mr.h = mr.h;
  m.mr.room = mr.room = np.room;

  con_m (&np, &m.c);

  int x, y;
  if (! mr_coord (np.room, -1, &x, &y)) {
    mr_center_room (np.room);
    x = mr.x;
    y = mr.y;
  }

  m.mr.x = mr.x = x;
  m.mr.y = mr.y = y;

  set_mouse_coord (&m);
}
Example #2
0
bool
ui_set_multi_room (int dw, int dh)
{
  char *text;

  if (mr.w + dw < 1 || mr.h + dh < 1) {
    xasprintf (&text, "MULTI-ROOM %ix%i", mr.w, mr.h);
    draw_bottom_text (NULL, text, 0);
    al_free (text);
    return false;
  }

  struct mouse_coord m;
  get_mouse_coord (&m);

  if (mr.w + dw != mr.w || mr.h + dh != mr.h)
    set_multi_room (mr.w + dw, mr.h + dh);

  mr_center_room (mr.room);

  if (mr_coord (m.c.room, -1, NULL, NULL))
    set_mouse_coord (&m);

  xasprintf (&text, "MULTI-ROOM %ix%i", mr.w, mr.h);
  draw_bottom_text (NULL, text, 0);
  al_free (text);
  return true;
}
Example #3
0
void
set_mouse_coord (struct mouse_coord *m)
{
  if (m->c.x < 0 || m->c.x >= ORIGINAL_WIDTH
      || m->c.y < 0 || m->c.y >= ORIGINAL_HEIGHT)
    return;

  int x, y;

  mr_restore_origin (&m->mr);

  if (! m->c.room) {
    al_set_mouse_xy (display, m->sx, m->sy);
    return;
  }

  if (! mr_coord (m->c.room, -1, &x, &y)) {
    mr_center_room (m->c.room);
    x = mr.x;
    y = mr.y;
  }

  struct mouse_coord m0;
  get_mouse_coord (&m0);
  if (m0.x >= 0 && m0.y >= 0 &&
      mr.cell[m0.x][m0.y].room == m->c.room) {
    x = m0.x;
    y = m0.y;
  }

  int tw, th;
  mr_get_resolution (&tw, &th);

  int w = al_get_display_width (display);
  int h = al_get_display_height (display);

  int mx = ((ORIGINAL_WIDTH * x + m->c.x + 1) * w) / tw;
  int my = ((ROOM_HEIGHT * y + m->c.y + 1) * h) / th;

  mx = min_int (mx, w - 1);
  my = min_int (my, h - 1);

  int flags = screen_flags | potion_flags;

  if (flags & ALLEGRO_FLIP_HORIZONTAL)
    mx = (w - 1) - mx;

  if (flags & ALLEGRO_FLIP_VERTICAL)
    my = (h - 1) - my;

  if (! al_set_mouse_xy (display, mx, my))
    error (0, 0, "%s (%p): cannot set mouse xy coordinates (%i,%i)",
           __func__, m, mx, my);

  do {
    al_get_mouse_state (&mouse_state);
  } while (mouse_state.x != mx || mouse_state.y != my);

  mr.select_cycles = SELECT_CYCLES;
}
Example #4
0
void
mr_focus_room (int room)
{
  int x, y;
  if (mr_coord (room, -1, &x, &y))
    mr_set_origin (room, x, y);
  else mr_center_room (room);
  mr.select_cycles = SELECT_CYCLES;
}
Example #5
0
void
set_mouse_room (int room)
{
  struct mouse_coord m;

  int x, y;
  if (mr_coord (room, -1, &x, &y))
    mr_set_origin (room, x, y);

  mr_save_origin (&m.mr);
  new_coord (&m.c, &global_level, room, ORIGINAL_WIDTH / 2, ORIGINAL_HEIGHT / 2);
  set_mouse_coord (&m);

  if (! room) {
    mr_center_room (0);
    mr.select_cycles = 0;
    int w = al_get_display_width (display);
    int h = al_get_display_height (display);
    al_set_mouse_xy (display, w / 2, h / 2);
  }
}
Example #6
0
void
generate_stars_for_pos (struct pos *p)
{
  struct pos np; npos (p, &np);
  int x, y;
  if (! mr_coord (np.room, -1, &x, &y)) return;

  struct stars *stars = &mr.cell[x][y].stars[np.floor][np.place];
  destroy_bitmap (stars->b);
  stars->b = NULL;
  if (stars->s) al_free (stars->s);
  stars->s = NULL;
  stars->count = 0;

  if (con (&np)->bg != BALCONY) return;

  stars->count = 3 + prandom_pos (&np, 5);
  stars->s = xcalloc (stars->count, sizeof (* stars->s));

  int i, min_x = INT_MAX, min_y = INT_MAX,
    max_x = INT_MIN, max_y = INT_MIN;

  for (i = 0; i < stars->count; i++) {
    struct star *s = &stars->s[i];
    star_coord (&np, i, s);
    min_x = min_int (min_x, s->x);
    min_y = min_int (min_y, s->y);
    max_x = max_int (max_x, s->x);
    max_y = max_int (max_y, s->y);
    s->color = next_color (s->color);
  }

  stars->b = create_bitmap (max_x - min_x + 1, max_y - min_y + 1);
  clear_bitmap (stars->b, TRANSPARENT_COLOR);
  new_coord (&stars->c, np.l, np.room, min_x, min_y);

  redraw_stars_bitmap (stars, vm);
}
Example #7
0
void
draw_multi_rooms (void)
{
  int x, y;

  mr_set_origin (mr.room, mr.x, mr.y);

  bool mr_view_changed = has_mr_view_changed ();

  if (mr_view_changed) force_full_redraw = true;

  if (anim_cycle == 0) {
    generate_wall_colors_for_room (0, room0_wall_color);
  }

  if (em == PALACE && vm == VGA
      && (mr_view_changed
          || em != mr.last.em
          || vm != mr.last.vm))
    generate_wall_colors ();

  if (mr_view_changed)
    generate_stars ();

  if (mouse_pos.room != mr.last.mouse_pos.room
      || mouse_pos.floor != mr.last.mouse_pos.floor
      || mouse_pos.place != mr.last.mouse_pos.place) {
    if (is_valid_pos (&mouse_pos))
      update_cache_pos (&mouse_pos, CHPOS_MOUSE_SELECT, em, vm);
    if (is_valid_pos (&mr.last.mouse_pos))
      update_cache_pos (&mr.last.mouse_pos, CHPOS_MOUSE_DESELECT, em, vm);
  }

  if (anim_cycle == 0
      || em != mr.last.em
      || vm != mr.last.vm
      || hgc != mr.last.hgc
      || hue != mr.last.hue) {
    update_room0_cache (em, vm);
    force_full_redraw = true;
  }

  if (anim_cycle == 0
      || mr_view_changed
      || em != mr.last.em
      || vm != mr.last.vm
      || hgc != mr.last.hgc
      || hue != mr.last.hue
      || global_level.number != mr.last.level) {
    update_cache (em, vm);
  }

  size_t i;
  for (i = 0; i < changed_pos_nmemb; i++)
    update_cache_pos (&changed_pos[i].p, changed_pos[i].reason, em, vm);
  destroy_array ((void **) &changed_pos, &changed_pos_nmemb);

  for (i = 0; i < changed_room_nmemb; i++)
    update_cache_room (changed_room[i], em, vm);
  destroy_array ((void **) &changed_room, &changed_room_nmemb);

  for (y = mr.h - 1; y >= 0; y--)
    for (x = 0; x < mr.w; x++) {
      clear_bitmap (mr.cell[x][y].screen, (mr.flicker > 0 && mr.flicker % 2)
                    ? mr.color : BLACK);

      if (! mr.cell[x][y].room) continue;
      mr.dx = x;
      mr.dy = y;
      draw_animated_background (mr.cell[x][y].screen,
                                mr.cell[x][y].room);
    }

  if (mr.flicker > 0) mr.flicker--;

  struct mr_room_list l;
  mr_get_room_list (&l);

  int xm, ym;
  if (! no_room_drawing)
    for (i = 0; i < l.nmemb; i++) {
      mr_coord (l.room[i], -1, &xm, &ym);
      for (y = mr.h - 1; y >= 0; y--)
        for (x = 0; x < mr.w; x++)
          if (mr.cell[x][y].room == l.room[i])
            draw_bitmap (mr.cell[xm][ym].cache,
                         mr.cell[x][y].screen, 0, 0, 0);
    }

  mr_destroy_room_list (&l);

  /* if (! no_room_drawing) */
  /*   for (y = mr.h - 1; y >= 0; y--) */
  /*     for (x = 0; x < mr.w; x++) */
  /*       if (mr.cell[x][y].room) */
  /*         draw_bitmap (mr.cell[x][y].cache, mr.cell[x][y].screen, 0, 0, 0); */

  for (y = mr.h - 1; y >= 0; y--)
    for (x = 0; x < mr.w; x++) {
      if (! mr.cell[x][y].room) continue;
      mr.dx = x;
      mr.dy = y;
      draw_animated_foreground (mr.cell[x][y].screen, mr.cell[x][y].room);
    }

  /* if (mr.select_cycles > 0) { */
  /*   int t = max_int (mr.w, mr.h); */
  /*   draw_rectangle (mr.cell[mr.x][mr.y].screen, 0, 3, */
  /*                   ORIGINAL_WIDTH - t, */
  /*                   3 + ROOM_HEIGHT - t, RED, t); */
  /*   mr.select_cycles--; */
  /* } */

  mr_update_last_settings ();
}
Example #8
0
bool
is_room_visible (int room)
{
  int x, y;
  return mr_coord (room, -1, &x, &y);
}
Example #9
0
void
draw_multi_rooms (void)
{
  int x, y;

  mr_set_origin (mr.room, mr.x, mr.y);

  bool mr_full_update = has_mr_view_changed ()
    || mr.full_update;

  if (mr_full_update) {
    mr_busy ();
    force_full_redraw = true;
  }

  if (anim_cycle == 0) {
    generate_wall_colors_for_room (0, room0_wall_color);
  }

  if (em == PALACE && vm == VGA
      && (mr_full_update
          || em != mr.last.em
          || vm != mr.last.vm))
    generate_wall_colors ();

  if (mouse_pos.room != mr.last.mouse_pos.room
      || mouse_pos.floor != mr.last.mouse_pos.floor
      || mouse_pos.place != mr.last.mouse_pos.place) {
    if (is_valid_pos (&mouse_pos))
      register_changed_pos (&mouse_pos);

    if (is_valid_pos (&mr.last.mouse_pos))
      register_changed_pos (&mr.last.mouse_pos);
  }

  if (anim_cycle == 0
      || em != mr.last.em
      || vm != mr.last.vm
      || hgc != mr.last.hgc
      || hue != mr.last.hue) {
    update_room0_cache (em, vm);
    force_full_redraw = true;
  }

  size_t i;

  if (anim_cycle == 0
      || mr_full_update
      || em != mr.last.em
      || vm != mr.last.vm
      || hgc != mr.last.hgc
      || hue != mr.last.hue
      || global_level.n != mr.last.level) {
    update_cache (em, vm);
  } else {
    bool depedv =
      ((em == DUNGEON && vm == VGA)
       || (em == DUNGEON && vm == EGA)
       || (em == PALACE && vm == EGA));

    /* optmize changed pos list */
    optimize_changed_pos ();

    /* update cache pos */
    for (i = 0; i < changed_pos_nmemb; i++) {
      update_cache_pos (&changed_pos[i], em, vm);
      struct pos pl; prel (&changed_pos[i], &pl, +0, -1);
      if (depedv && fake (&pl) == WALL)
        update_cache_pos (&pl, em, vm);
    }

    /* update cache room */
    for (i = 0; i < changed_room_nmemb; i++)
      update_cache_room (changed_room[i], em, vm);

    /* kept together so update_cache_pos and update_cache_room can
       access each other's arrays */
    destroy_array ((void **) &changed_pos, &changed_pos_nmemb);
    destroy_array ((void **) &changed_room, &changed_room_nmemb);
  }

  for (y = mr.h - 1; y >= 0; y--)
    for (x = 0; x < mr.w; x++) {
      clear_bitmap (mr.cell[x][y].screen, (mr.flicker > 0 && mr.flicker % 2)
                    ? mr.color : BLACK);

      if (! mr.cell[x][y].room) continue;
      mr.dx = x;
      mr.dy = y;
      draw_animated_background (mr.cell[x][y].screen,
                                mr.cell[x][y].room);
    }

  if (mr.flicker > 0) mr.flicker--;

  struct mr_room_list l;
  mr_get_room_list (&l);

  int xm, ym;
  if (! no_room_drawing)
    for (i = 0; i < l.nmemb; i++) {
      mr_coord (l.room[i], -1, &xm, &ym);
      for (y = mr.h - 1; y >= 0; y--)
        for (x = 0; x < mr.w; x++)
          if (mr.cell[x][y].room == l.room[i])
            draw_bitmap (mr.cell[xm][ym].cache,
                         mr.cell[x][y].screen, 0, 0, 0);
    }

  mr_destroy_room_list (&l);

  for (y = mr.h - 1; y >= 0; y--)
    for (x = 0; x < mr.w; x++) {
      if (! mr.cell[x][y].room) continue;
      mr.dx = x;
      mr.dy = y;
      draw_animated_foreground (mr.cell[x][y].screen, mr.cell[x][y].room);
    }

  mr_update_last_settings ();
}