void multi_room_fit_stretch (void) { int w = 1; int h = 1; int lc, c = 1; repeat: do { lc = c; redim_multi_room (++w, h); mr_center_room (mr.room); c = mr_count_uniq_rooms (); /* printf ("W: room: %i, width: %i, height: %i, count: %i\n", */ /* mr.room, mr.w, mr.h, c); */ } while (c > lc); redim_multi_room (--w, h); mr_center_room (mr.room); int wc = c; do { lc = c; redim_multi_room (w, ++h); mr_center_room (mr.room); c = mr_count_uniq_rooms (); /* printf ("H: room: %i, width: %i, height: %i, count: %i\n", */ /* mr.room, mr.w, mr.h, c); */ } while (c > lc); redim_multi_room (w, --h); mr_center_room (mr.room); if (c > wc) goto repeat; }
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; } if (! set_multi_room (mr.w + dw, mr.h + dh)) { draw_bottom_text (NULL, "VIDEO CARD LIMIT REACHED", 0); return false; } mr_w = mr.w; mr_h = mr.h; mr_center_room (mr.room); xasprintf (&text, "MULTI-ROOM %ix%i", mr_w, mr_h); draw_bottom_text (NULL, text, 0); al_free (text); return true; }
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); }
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; }
void mr_restore_origin (struct mr_origin *o) { if (o->w == mr.w && o->h == mr.h) mr_set_origin (o->room, o->x, o->y); else mr_center_room (o->room); }
void apply_mr_fit_mode (void) { int w, h; switch (mr.fit_mode) { case MR_FIT_NONE: w = mr.fit_w; h = mr.fit_h; break; case MR_FIT_STRETCH: multi_room_fit_stretch (); w = mr.w; h = mr.h; break; case MR_FIT_RATIO: multi_room_fit_ratio (); w = mr.w; h = mr.h; break; } set_multi_room (w, h); mr_center_room (mr.room); }
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; }
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; }
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); } }