void mr_focus_mouse (void) { struct mouse_coord m; get_mouse_coord (&m); mr_focus_cell (m.x, m.y); }
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; }
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; }
struct pos * get_mouse_pos (struct pos *p) { struct mouse_coord m; get_mouse_coord (&m); if (! is_valid_coord (&m.c)) { invalid_pos (p); return p; } int ry = (m.c.y - 3) % PLACE_HEIGHT; pos_gen (&m.c, p, 0, 3); if (edit == EDIT_NONE) { invalid_pos (p); return p; } struct pos p0; switch (fake (p)) { case MIRROR: case CHOPPER: case WALL: case PILLAR: case BIG_PILLAR_TOP: case BIG_PILLAR_BOTTOM: case ARCH_BOTTOM: case ARCH_TOP_MID: case ARCH_TOP_SMALL: case ARCH_TOP_LEFT: case ARCH_TOP_RIGHT: break; default: if (is_arch_top (prel (p, &p0, +0, -1))) break; if (ry >= 60) pos_gen (&m.c, p, 0, 3); else if (ry >= 50) pos_gen (&m.c, p, 23 - 2.5 * (ry - 50), 3); else pos_gen (&m.c, p, 23, 3); break; } struct pos np; npos (p, &np); if (! np.room) { invalid_pos (p); return p; } return p; }